|
1 | 1 | /*!
|
2 | 2 | ghostdog is a tool to manage ephemeral disks.
|
3 | 3 | It can be called as a udev helper program to identify ephemeral disks.
|
| 4 | +It can also be called for EFA device detection which can be used for ExecCondition in systemd units. |
4 | 5 | */
|
5 | 6 |
|
6 | 7 | use argh::FromArgs;
|
@@ -30,8 +31,14 @@ struct Args {
|
30 | 31 | enum SubCommand {
|
31 | 32 | Scan(ScanArgs),
|
32 | 33 | EbsDeviceName(EbsDeviceNameArgs),
|
| 34 | + EfaPresent(EfaPresentArgs), |
33 | 35 | }
|
34 | 36 |
|
| 37 | +#[derive(FromArgs, PartialEq, Debug)] |
| 38 | +#[argh(subcommand, name = "efa-present")] |
| 39 | +/// Detect if EFA devices are attached. |
| 40 | +struct EfaPresentArgs {} |
| 41 | + |
35 | 42 | #[derive(FromArgs, PartialEq, Debug)]
|
36 | 43 | #[argh(subcommand, name = "scan")]
|
37 | 44 | /// Scan a device to see if it is an ephemeral disk.
|
@@ -63,10 +70,21 @@ fn run() -> Result<()> {
|
63 | 70 | let device_name = find_device_name(format!("{}", path.display()))?;
|
64 | 71 | emit_device_name(&device_name);
|
65 | 72 | }
|
| 73 | + SubCommand::EfaPresent(_) => { |
| 74 | + is_efa_attached()?; |
| 75 | + } |
66 | 76 | }
|
67 | 77 | Ok(())
|
68 | 78 | }
|
69 | 79 |
|
| 80 | +fn is_efa_attached() -> Result<()> { |
| 81 | + if pciclient::is_efa_attached().context(error::CheckEfaFailureSnafu)? { |
| 82 | + Ok(()) |
| 83 | + } else { |
| 84 | + Err(error::Error::NoEfaPresent) |
| 85 | + } |
| 86 | +} |
| 87 | + |
70 | 88 | /// Find the device type by examining the partition table, if present.
|
71 | 89 | fn find_device_type<R>(reader: &mut R) -> Result<String>
|
72 | 90 | where
|
@@ -176,6 +194,10 @@ mod error {
|
176 | 194 | },
|
177 | 195 | #[snafu(display("Invalid device info for device '{}'", path.display()))]
|
178 | 196 | InvalidDeviceInfo { path: std::path::PathBuf },
|
| 197 | + #[snafu(display("Failed to check if EFA device is attached: {}", source))] |
| 198 | + CheckEfaFailure { source: pciclient::PciClientError }, |
| 199 | + #[snafu(display("Did not detect EFA"))] |
| 200 | + NoEfaPresent, |
179 | 201 | }
|
180 | 202 | }
|
181 | 203 |
|
|
0 commit comments