Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix udev rule for EBS mappings #98

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}