Skip to content

Commit

Permalink
Merge pull request #98 from arnaldo2792/fix-udev-rule
Browse files Browse the repository at this point in the history
Fix udev rule for EBS mappings
  • Loading branch information
arnaldo2792 committed Aug 19, 2024
2 parents c74767f + 8472149 commit 6e0156d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/os/ebs-volumes.rules
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ ATTRS{model}!="Amazon Elastic Block Store", GOTO="ebs_volumes_end"
ENV{DEVTYPE}=="disk", ATTR{queue/io_timeout}="4294967295"

# Add symlink for disk
KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", IMPORT{program}="/usr/bin/ghostdog ebs-device-name $devnode", SYMLINK+="$env{XVD_DEVICE_NAME}"
KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", IMPORT{program}="/usr/bin/ghostdog ebs-device-name $devnode", SYMLINK+="disk/by-ebs-id/$env{XVD_DEVICE_NAME}"

# Add symlink for partition
KERNEL=="nvme[0-9]*n[0-9]*p[0-9]*", ENV{DEVTYPE}=="partition", IMPORT{parent}="XVD_DEVICE_NAME", SYMLINK+="$env{XVD_DEVICE_NAME}$number"
KERNEL=="nvme[0-9]*n[0-9]*p[0-9]*", ENV{DEVTYPE}=="partition", IMPORT{parent}="XVD_DEVICE_NAME", SYMLINK+="disk/by-ebs-id/$env{XVD_DEVICE_NAME}$number"

LABEL="ebs_volumes_end"
28 changes: 27 additions & 1 deletion sources/ghostdog/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ fn parse_device_name(device_info: &[u8], path: String) -> Result<String> {
let offset = NVME_IDENTIFY_DATA_SIZE - 1024;
let device_name = &device_info[offset..offset + 32];

Ok(String::from_utf8_lossy(device_name).trim_end().to_string())
// Remove `/dev` in case the returned device name includes it, the udev
// rule already includes that prefix
Ok(String::from_utf8_lossy(device_name)
.trim_start_matches("/dev/")
.trim_end()
.to_string())
}

/// Print the device type in the environment key format udev expects.
Expand Down Expand Up @@ -235,4 +240,25 @@ mod test {
let data = gpt_data(partition_type, partition_name);
assert_eq!(find_device_type(&mut Cursor::new(&data)).unwrap(), "system");
}

#[test]
fn test_valid_device_info() {
for device_name in ["xvdcz", "/dev/xvdcz"] {
let device_info = build_device_info(device_name);
assert_eq!(
parse_device_name(&device_info, "".to_string()).unwrap(),
"xvdcz".to_string()
);
}
}

fn build_device_info(device_name: &str) -> Vec<u8> {
let mut device_name = device_name.as_bytes().to_vec();
let mut device_info: Vec<u8> = vec![0; NVME_IDENTIFY_DATA_SIZE - 1024];
let mut padding = vec![32; NVME_IDENTIFY_DATA_SIZE - device_info.len() - device_name.len()];
device_info.append(&mut device_name);
device_info.append(&mut padding);

device_info
}
}

0 comments on commit 6e0156d

Please sign in to comment.