This repository has been archived by the owner on Sep 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
udev: add support for AWS EBS NVMe friendly names
- Loading branch information
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright (c) 2018 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() { | ||
check_udev_aws | ||
NSID=$(echo -n "$1" | cut -f 3 -d 'n' | cut -f 1 -d 'p') | ||
echo "_NS_ID=${NSID}" | ||
} | ||
|
||
# Get device name from raw metadata, | ||
# see https://github.com/coreos/bugs/issues/2399. | ||
devname() { | ||
check_udev_aws | ||
RAWVOL=$(nvme id-ctrl --raw-binary "$1" | cut -c3073-3104 | tr -s ' ' | sed 's/ $//g') | ||
VOL="${RAWVOL#/dev/}" | ||
if [[ -n "$VOL" ]]; then | ||
echo "${VOL}" | ||
else | ||
exit 1 | ||
fi | ||
} | ||
|
||
# Ensure this is run with proper environment populated by udev, | ||
# and acting on an AWS EBS device. | ||
check_udev_aws() { | ||
if [ "${ID_MODEL}" != "Amazon Elastic Block Store" ]; then | ||
echo 'Stopping due to non-matching ID_MODEL env variable' | ||
exit 1 | ||
fi | ||
} | ||
|
||
while getopts "hd:n:" o; do | ||
case "${o}" in | ||
d) | ||
devname "${OPTARG}" | ||
exit 0 | ||
;; | ||
n) | ||
namespace_id "${OPTARG}" | ||
exit 0 | ||
;; | ||
h) | ||
usage | ||
exit 0 | ||
;; | ||
*) | ||
usage | ||
exit 1 | ||
;; | ||
esac | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters