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

WIP: add AWS EBS NVMe udev rules #476

Closed
wants to merge 1 commit into from
Closed
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
47 changes: 47 additions & 0 deletions overlay.d/05core/usr/lib/udev/bin/aws-ebs-nvme-id
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

# Copyright (c) 2020 The CoreOS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

usage() {
echo "Usage: $0 [-d|-p|-h] <device>" 1>&2
}

# Get partition ID from device name, e.g. '/dev/nvme0n1p2' -> '1'
namespace_id() {
NSID=$(echo -n "$1" | cut -f 3 -d 'n' | cut -f 1 -d 'p')
echo "_NS_ID=${NSID}"
}

# Get device name from raw metadata,
devname() {
RAWVOL=$(nvme id-ctrl --raw-binary "$1" | cut -c3073-3104 | tr -s ' ' | sed 's/ $//g')
bh7cw marked this conversation as resolved.
Show resolved Hide resolved
VOL="${RAWVOL#/dev/}"
if [[ -n "$VOL" ]]; then
echo "${VOL}"
else
exit 1
fi
}

while getopts "hd:n:" o; do
Copy link
Member

Choose a reason for hiding this comment

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

These options are pretty cryptic. Can we use long opts instead?

case "${o}" in
d)
devname "${OPTARG}"
exit 0
;;
n)
namespace_id "${OPTARG}"
exit 0
;;
h)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
14 changes: 14 additions & 0 deletions overlay.d/05core/usr/lib/udev/rules.d/70-aws-ebs-nvme-id.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#AWS EBS NVMe
ACTION!="add|change", GOTO="aws_ebs_nvme_end"
SUBSYSTEM!="block", GOTO="aws_ebs_nvme_end"

# NVMe devices
KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", ATTRS{model}=="Amazon Elastic Block Store", ATTRS{serial}=="?*", SYMLINK+="disk/by-id/nvme-$attr{model}_$attr{serial}-ns-%n", OPTIONS+="string_escape=replace"
KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", ATTRS{model}=="Amazon Elastic Block Store", ATTRS{serial}=="?*", PROGRAM="/usr/lib/udev/bin/aws-ebs-nvme-id -d /dev/%k", SYMLINK+="%c"

# NVMe partitions
KERNEL=="nvme[0-9]*n[0-9]*p[0-9]*", ENV{DEVTYPE}=="partition", ATTRS{model}=="Amazon Elastic Block Store", ATTRS{serial}=="?*", IMPORT{program}="/usr/lib/udev/bin/aws-ebs-nvme-id -d /dev/%k"
KERNEL=="nvme[0-9]*n[0-9]*p[0-9]*", ENV{DEVTYPE}=="partition", ATTRS{model}=="Amazon Elastic Block Store", ATTRS{serial}=="?*", ENV{_NS_ID}=="?*", SYMLINK+="disk/by-id/nvme-$attr{model}_$attr{serial}-ns-$env{_NS_ID}-part%n", OPTIONS+="string_escape=replace"
KERNEL=="nvme[0-9]*n[0-9]*p[0-9]*", ENV{DEVTYPE}=="partition", ATTRS{model}=="Amazon Elastic Block Store", ATTRS{serial}=="?*", ENV{_NS_ID}=="?*", PROGRAM="/usr/lib/udev/bin/aws-ebs-nvme-id -d /dev/%k", SYMLINK+="%c%n"

LABEL="aws_ebs_nvme_end"