diff --git a/packages/os/ebs-volumes.rules b/packages/os/ebs-volumes.rules index 64c644ac1..dacb992b0 100644 --- a/packages/os/ebs-volumes.rules +++ b/packages/os/ebs-volumes.rules @@ -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" diff --git a/sources/ghostdog/src/main.rs b/sources/ghostdog/src/main.rs index 1ed766a4d..e1f9c3402 100644 --- a/sources/ghostdog/src/main.rs +++ b/sources/ghostdog/src/main.rs @@ -117,7 +117,12 @@ fn parse_device_name(device_info: &[u8], path: String) -> Result { 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. @@ -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 { + let mut device_name = device_name.as_bytes().to_vec(); + let mut device_info: Vec = 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 + } }