From ba1949db0ac905e6e615af6d6abb7e3f7588d250 Mon Sep 17 00:00:00 2001 From: Ricardo Rosales Date: Thu, 3 Sep 2020 09:35:36 -0500 Subject: [PATCH 1/4] Keeping master version of ebs-nvme-mapping.sh --- 999-aws-ebs-nvme.rules | 1 + nextephemeraldevice.sh | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 nextephemeraldevice.sh diff --git a/999-aws-ebs-nvme.rules b/999-aws-ebs-nvme.rules index a514019..c6baed5 100644 --- a/999-aws-ebs-nvme.rules +++ b/999-aws-ebs-nvme.rules @@ -1 +1,2 @@ SUBSYSTEM=="block", KERNEL=="nvme[0-9]*n1", ATTRS{model}=="Amazon Elastic Block Store", PROGRAM+="/usr/local/sbin/ebs-nvme-mapping.sh /dev/%k" SYMLINK+="%c" +KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", ATTRS{model}=="Amazon EC2 NVMe Instance Storage", PROGRAM="/usr/local/bin/nextdevice %k", SYMLINK+="%c" diff --git a/nextephemeraldevice.sh b/nextephemeraldevice.sh new file mode 100644 index 0000000..9842bd3 --- /dev/null +++ b/nextephemeraldevice.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +kern_name=${1} +incr=0 +while [[ -e "/dev/ephemeral${incr}" ]] && [[ $(readlink "/dev/ephemeral${incr}") != "${kern_name}" ]]; do + incr=$[$i+1] +done +echo "ephemeral${incr}" From af010259d5650508f8aa200cd0316aae8d8ad730 Mon Sep 17 00:00:00 2001 From: Ricardo Rosales Date: Tue, 21 Apr 2020 23:05:36 -0500 Subject: [PATCH 2/4] Adding reference to udev rule to nextephemeraldevice script --- nextephemeraldevice.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/nextephemeraldevice.sh b/nextephemeraldevice.sh index 9842bd3..a32d305 100644 --- a/nextephemeraldevice.sh +++ b/nextephemeraldevice.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# To be used with the udev rule: /etc/udev/rules.d/999-aws-ebs-nvme.rules kern_name=${1} incr=0 From 6aca438b7a126e9872fd54d58cf39ccf64c60954 Mon Sep 17 00:00:00 2001 From: Ricardo Rosales Date: Thu, 3 Sep 2020 09:39:19 -0500 Subject: [PATCH 3/4] Keeping master version of ebs-nvme-mapping.sh --- 999-aws-ebs-nvme.rules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/999-aws-ebs-nvme.rules b/999-aws-ebs-nvme.rules index c6baed5..20617ba 100644 --- a/999-aws-ebs-nvme.rules +++ b/999-aws-ebs-nvme.rules @@ -1,2 +1,2 @@ SUBSYSTEM=="block", KERNEL=="nvme[0-9]*n1", ATTRS{model}=="Amazon Elastic Block Store", PROGRAM+="/usr/local/sbin/ebs-nvme-mapping.sh /dev/%k" SYMLINK+="%c" -KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", ATTRS{model}=="Amazon EC2 NVMe Instance Storage", PROGRAM="/usr/local/bin/nextdevice %k", SYMLINK+="%c" +KERNEL=="nvme[0-9]*n[0-9]*", ENV{DEVTYPE}=="disk", ATTRS{model}=="Amazon EC2 NVMe Instance Storage", PROGRAM="/usr/local/bin/nextephemeraldevice.sh %k", SYMLINK+="%c" From 1a8da64ff5005ae76724ca5cda1c1a098b543f43 Mon Sep 17 00:00:00 2001 From: Ricardo Rosales Date: Thu, 3 Sep 2020 17:24:30 -0500 Subject: [PATCH 4/4] adding lock file to ephemeral script --- nextephemeraldevice.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/nextephemeraldevice.sh b/nextephemeraldevice.sh index a32d305..14a4237 100644 --- a/nextephemeraldevice.sh +++ b/nextephemeraldevice.sh @@ -1,9 +1,27 @@ #!/usr/bin/env bash # To be used with the udev rule: /etc/udev/rules.d/999-aws-ebs-nvme.rules +# check if lock file exists +script_name="$(basename $0)" +pid_file="/tmp/${script_name}.lock" +counter=0 +until [ $counter -eq 5 ] || [[ ! -e "${pid_file}" ]] ; do + sleep $(( counter++ )) +done + +# create lock file if it does not exist +if [[ -e "${pid_file}" ]]; then + echo "Lock file ${pid_file} still exists after counter ended" >&2 + exit 1 +else + touch "${pid_file}" +fi + kern_name=${1} incr=0 while [[ -e "/dev/ephemeral${incr}" ]] && [[ $(readlink "/dev/ephemeral${incr}") != "${kern_name}" ]]; do incr=$[$i+1] done +# remove lock file +rm "${pid_file}" echo "ephemeral${incr}"