Skip to content

Commit

Permalink
feat(udev): extend rules for compatibility in SCSI and older NVMe env…
Browse files Browse the repository at this point in the history
…ironments

There are multiple combinations of disks depending on instance vm size
and configuration:

- NVMe-only disks in v6+ families

- Mixed disk with SCSI OS & resource disks alongside NVMe local disks
  e.g. LSv2/3

- Mixed disk with SCSI resource disk alongside NVMe OS and data disks
  e.g. Ebdsv5 with NVMe controller configured

- SCSI-only disks with most instances prior to v6

For SCSI OS disk, export as /dev/disk/azure/os similar to NVMe OS disk.

For SCSI resource disk, export as /dev/disk/azure/resource as already
done in the existing udev rules implementations. Ideally we'd expose
SCSI local disks in the same manner as local NVMe disks, but since we
cannot be sure of what environment we're in, /dev/disk/azure/local
will be limited to local NVMe disks of any configuration.

For older NVMe local disk implementation such as LSv2/v3 which do not
expose identifiers for index, name, etc. export new links for
/dev/disk/azure/local/by-serial/<serial>.  Based on observation, it
is possible this serial contains the equivalent index identifier so
this may be revisited in the future if we determine it to be
guaranteed to be useful as such.

Signed-off-by: Chris Patterson <[email protected]>
  • Loading branch information
cjp256 committed Aug 1, 2024
1 parent 43e0392 commit 8d8e336
Showing 1 changed file with 41 additions and 24 deletions.
65 changes: 41 additions & 24 deletions udev/80-azure-nvme.rules
Original file line number Diff line number Diff line change
@@ -1,33 +1,50 @@
ACTION!="add|change", GOTO="azure_nvme_end"
SUBSYSTEM!="block", GOTO="azure_nvme_end"
KERNEL!="nvme*", GOTO="azure_nvme_end"
ATTRS{nsid}!="?*", GOTO="azure_nvme_end"
ACTION!="add|change", GOTO="azure_disk_end"
SUBSYSTEM!="block", GOTO="azure_disk_end"

ENV{ID_MODEL}=="Microsoft NVMe Direct Disk", GOTO="azure_nvme_direct_v1_start"
ENV{ID_MODEL}=="Microsoft NVMe Direct Disk v2", GOTO="azure_nvme_direct_v2_start"
ENV{ID_MODEL}=="MSFT NVMe Accelerator v1.0", GOTO="azure_nvme_remote_start"
GOTO="azure_nvme_end"
KERNEL=="nvme*", ATTRS{nsid}=="?*", ENV{ID_MODEL}=="Microsoft NVMe Direct Disk", GOTO="azure_disk_nvme_direct_v1"
KERNEL=="nvme*", ATTRS{nsid}=="?*", ENV{ID_MODEL}=="Microsoft NVMe Direct Disk v2", GOTO="azure_disk_nvme_direct_v2"
KERNEL=="nvme*", ATTRS{nsid}=="?*", ENV{ID_MODEL}=="MSFT NVMe Accelerator v1.0", GOTO="azure_disk_nvme_remote_v1"
ENV{ID_VENDOR}=="Msft", ENV{ID_MODEL}=="Virtual_Disk", GOTO="azure_disk_scsi"
GOTO="azure_disk_end"

LABEL="azure_nvme_direct_v1_start"
LABEL="azure_nvme_direct_v2_start"
ATTRS{nsid}=="?*", ENV{AZURE_NVME_TYPE}="local"
GOTO="azure_nvme_start"
LABEL="azure_disk_scsi"
ATTRS{device_id}=="?00000000-0000-*", ENV{AZURE_DISK_TYPE}="os", GOTO="azure_disk_symlink"
ENV{DEVTYPE}=="partition", PROGRAM="/bin/sh -c 'readlink /sys/class/block/%k/../device|cut -d: -f4'", ENV{AZURE_DISK_LUN}="$result"
ENV{DEVTYPE}=="disk", PROGRAM="/bin/sh -c 'readlink /sys/class/block/%k/device|cut -d: -f4'", ENV{AZURE_DISK_LUN}="$result"
ATTRS{device_id}=="{f8b3781a-1e82-4818-a1c3-63d806ec15bb}", ENV{AZURE_DISK_LUN}=="0", ENV{AZURE_DISK_TYPE}="os", ENV{AZURE_DISK_LUN}="", GOTO="azure_disk_symlink"
ATTRS{device_id}=="{f8b3781b-1e82-4818-a1c3-63d806ec15bb}", ENV{AZURE_DISK_TYPE}="data", GOTO="azure_disk_symlink"
ATTRS{device_id}=="{f8b3781c-1e82-4818-a1c3-63d806ec15bb}", ENV{AZURE_DISK_TYPE}="data", GOTO="azure_disk_symlink"
ATTRS{device_id}=="{f8b3781d-1e82-4818-a1c3-63d806ec15bb}", ENV{AZURE_DISK_TYPE}="data", GOTO="azure_disk_symlink"

LABEL="azure_nvme_remote_start"
# Use "resource" type for local SCSI because some VM skus offer NVMe local disks in addition to a SCSI resource disk, e.g. LSv3 family.
# This logic is already in walinuxagent rules but we duplicate it here to avoid an unnecessary dependency for anyone requiring it.
ATTRS{device_id}=="?00000000-0001-*", ENV{AZURE_DISK_TYPE}="resource", ENV{AZURE_DISK_LUN}="", GOTO="azure_disk_symlink"
ATTRS{device_id}=="{f8b3781a-1e82-4818-a1c3-63d806ec15bb}", ENV{AZURE_DISK_LUN}=="1", ENV{AZURE_DISK_TYPE}="resource", ENV{AZURE_DISK_LUN}="", GOTO="azure_disk_symlink"
GOTO="azure_disk_end"

LABEL="azure_disk_nvme_direct_v1"
LABEL="azure_disk_nvme_direct_v2"
ATTRS{nsid}=="?*", ENV{AZURE_DISK_TYPE}="local", ENV{AZURE_DISK_SERIAL}="$env{ID_SERIAL_SHORT}"
GOTO="azure_disk_nvme_id"

LABEL="azure_disk_nvme_remote_v1"
ATTRS{nsid}=="1", ENV{AZURE_NVME_TYPE}="os", GOTO="azure_nvme_start"
ATTRS{nsid}=="?*", ENV{AZURE_NVME_TYPE}="data", PROGRAM="/bin/sh -ec 'echo $$((%s{nsid}-2))'", ENV{AZURE_NVME_LUN}="$result"
GOTO="azure_nvme_start"

LABEL="azure_nvme_start"
LABEL="azure_disk_nvme_id"
ATTRS{nsid}=="?*", IMPORT{program}="/usr/sbin/azure-nvme-id --udev"

LABEL="azure_disk_symlink"
# systemd v254 ships an updated 60-persistent-storage.rules that would allow
# these to be deduplicated using $env{.PART_SUFFIX}
ENV{DEVTYPE}=="disk", ENV{AZURE_NVME_TYPE}=="os", SYMLINK+="disk/azure/os"
ENV{DEVTYPE}=="disk", ENV{AZURE_NVME_TYPE}=="?*", ENV{AZURE_NVME_INDEX}=="?*", SYMLINK+="disk/azure/$env{AZURE_NVME_TYPE}/by-index/$env{AZURE_NVME_INDEX}"
ENV{DEVTYPE}=="disk", ENV{AZURE_NVME_TYPE}=="?*", ENV{AZURE_NVME_LUN}=="?*", SYMLINK+="disk/azure/$env{AZURE_NVME_TYPE}/by-lun/$env{AZURE_NVME_LUN}"
ENV{DEVTYPE}=="disk", ENV{AZURE_NVME_TYPE}=="?*", ENV{AZURE_NVME_NAME}=="?*", SYMLINK+="disk/azure/$env{AZURE_NVME_TYPE}/by-name/$env{AZURE_NVME_NAME}"
ENV{DEVTYPE}=="partition", ENV{AZURE_NVME_TYPE}=="os", SYMLINK+="disk/azure/os-part%n"
ENV{DEVTYPE}=="partition", ENV{AZURE_NVME_TYPE}=="?*", ENV{AZURE_NVME_INDEX}=="?*", SYMLINK+="disk/azure/$env{AZURE_NVME_TYPE}/by-index/$env{AZURE_NVME_INDEX}-part%n"
ENV{DEVTYPE}=="partition", ENV{AZURE_NVME_TYPE}=="?*", ENV{AZURE_NVME_LUN}=="?*", SYMLINK+="disk/azure/$env{AZURE_NVME_TYPE}/by-lun/$env{AZURE_NVME_LUN}-part%n"
ENV{DEVTYPE}=="partition", ENV{AZURE_NVME_TYPE}=="?*", ENV{AZURE_NVME_NAME}=="?*", SYMLINK+="disk/azure/$env{AZURE_NVME_TYPE}/by-name/$env{AZURE_NVME_NAME}-part%n"
LABEL="azure_nvme_end"
ENV{DEVTYPE}=="disk", ENV{AZURE_DISK_TYPE}=="os|resource|root", SYMLINK+="disk/azure/$env{AZURE_DISK_TYPE}"
ENV{DEVTYPE}=="disk", ENV{AZURE_DISK_TYPE}=="?*", ENV{AZURE_DISK_INDEX}=="?*", SYMLINK+="disk/azure/$env{AZURE_DISK_TYPE}/by-index/$env{AZURE_DISK_INDEX}"
ENV{DEVTYPE}=="disk", ENV{AZURE_DISK_TYPE}=="?*", ENV{AZURE_DISK_LUN}=="?*", SYMLINK+="disk/azure/$env{AZURE_DISK_TYPE}/by-lun/$env{AZURE_DISK_LUN}"
ENV{DEVTYPE}=="disk", ENV{AZURE_DISK_TYPE}=="?*", ENV{AZURE_DISK_NAME}=="?*", SYMLINK+="disk/azure/$env{AZURE_DISK_TYPE}/by-name/$env{AZURE_DISK_NAME}"
ENV{DEVTYPE}=="disk", ENV{AZURE_DISK_TYPE}=="?*", ENV{AZURE_DISK_SERIAL}=="?*", SYMLINK+="disk/azure/$env{AZURE_DISK_TYPE}/by-serial/$env{AZURE_DISK_SERIAL}"
ENV{DEVTYPE}=="partition", ENV{AZURE_DISK_TYPE}=="os|resource|root", SYMLINK+="disk/azure/$env{AZURE_DISK_TYPE}-part%n"
ENV{DEVTYPE}=="partition", ENV{AZURE_DISK_TYPE}=="?*", ENV{AZURE_DISK_INDEX}=="?*", SYMLINK+="disk/azure/$env{AZURE_DISK_TYPE}/by-index/$env{AZURE_DISK_INDEX}-part%n"
ENV{DEVTYPE}=="partition", ENV{AZURE_DISK_TYPE}=="?*", ENV{AZURE_DISK_LUN}=="?*", SYMLINK+="disk/azure/$env{AZURE_DISK_TYPE}/by-lun/$env{AZURE_DISK_LUN}-part%n"
ENV{DEVTYPE}=="partition", ENV{AZURE_DISK_TYPE}=="?*", ENV{AZURE_DISK_NAME}=="?*", SYMLINK+="disk/azure/$env{AZURE_DISK_TYPE}/by-name/$env{AZURE_DISK_NAME}-part%n"
ENV{DEVTYPE}=="partition", ENV{AZURE_DISK_TYPE}=="?*", ENV{AZURE_DISK_SERIAL}=="?*", SYMLINK+="disk/azure/$env{AZURE_DISK_TYPE}/by-serial/$env{AZURE_DISK_SERIAL}-part%n"
LABEL="azure_disk_end"

0 comments on commit 8d8e336

Please sign in to comment.