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

Conversation

arnaldo2792
Copy link
Contributor

Issue number:
#97

Description of changes:

With this change, symlinks to the underlying EBS volumes will be created under /dev/by-ebs-id instead of the root of /dev. This will help prevent collisions with actual devices created by the kernel (as described in this amazonlinux/amazon-ec2-utils#37).

As part of this change, /dev/ will be removed from the device name if it is found after querying the device identifier, so that only the device id is returned to udev.

Testing done:

I ran my change in an EC2 instance, and confirmed that the devices are listed under /dev/by-ebs-id when the mapping is added:

ls -la /dev/disk/by-ebs-id
total 0
drwxr-xr-x.  2 root root 240 Aug 19 20:50 .
drwxr-xr-x. 10 root root 200 Aug 19 20:50 ..
lrwxrwxrwx.  1 root root  13 Aug 19 20:50 xvda -> ../../nvme0n1
lrwxrwxrwx.  1 root root  15 Aug 19 20:50 xvda1 -> ../../nvme0n1p1
lrwxrwxrwx.  1 root root  15 Aug 19 20:50 xvda2 -> ../../nvme0n1p2
lrwxrwxrwx.  1 root root  15 Aug 19 20:50 xvda3 -> ../../nvme0n1p3
lrwxrwxrwx.  1 root root  15 Aug 19 20:50 xvda4 -> ../../nvme0n1p4
lrwxrwxrwx.  1 root root  15 Aug 19 20:50 xvda5 -> ../../nvme0n1p5
lrwxrwxrwx.  1 root root  15 Aug 19 20:50 xvda6 -> ../../nvme0n1p6
lrwxrwxrwx.  1 root root  15 Aug 19 20:50 xvda7 -> ../../nvme0n1p7
lrwxrwxrwx.  1 root root  15 Aug 19 20:50 xvda8 -> ../../nvme0n1p8
lrwxrwxrwx.  1 root root  13 Aug 19 20:50 xvdcz -> ../../nvme1n1

I confirmed that in the workflow that prepends the device ID with /dev/, this prefix is removed and the symlink is created under /dev/by-ebs-id/

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

Comment on lines 122 to 125
Ok(String::from_utf8_lossy(device_name)
.replace("/dev/", "")
.trim_end()
.to_string())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it feels a bit loose not to anchor this to the start of the string:

Suggested change
Ok(String::from_utf8_lossy(device_name)
.replace("/dev/", "")
.trim_end()
.to_string())
Ok(String::from_utf8_lossy(device_name)
.trim_start_matches("/dev/")
.trim_end()
.to_string())

Comment on lines 247 to 250
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could factor this into a helper function now that it's repeated

In certain workflows, EC2 adds `/dev/` to the device name. Remove it,
otherwise the symlink created by `udev` will point to the wrong path.

Signed-off-by: Arnaldo Garcia Rincon <agarrcia@amazon.com>
Create the symlinks to the actual devices under `/dev/by-ebs-id` so that
the names don't collide with actual devices created by the kernel.

Signed-off-by: Arnaldo Garcia Rincon <agarrcia@amazon.com>
@arnaldo2792
Copy link
Contributor Author

(addressed nits on ghostdog)

@arnaldo2792 arnaldo2792 merged commit 6e0156d into bottlerocket-os:develop Aug 19, 2024
2 checks passed
@arnaldo2792 arnaldo2792 deleted the fix-udev-rule branch September 5, 2024 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants