Skip to content

Commit 438c8f3

Browse files
committed
Merge remote-tracking branch 'origin' into pr/33
2 parents bf6b5eb + 37726e7 commit 438c8f3

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

amazon-ec2-utils.spec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ rm -rf $RPM_BUILD_ROOT
7777
%changelog
7878
* Thu Jan 18 2024 Keith Gable <gablk@amazon.com> - 2.2.0-1
7979
- Corrected issue where an ec2-metadata error was written to stdout
80+
- Change ec2nvme-nsid to use Bash string manipulation to improve
81+
performance and reliability
8082

81-
* Mon Jun 5 2023 Guillaume Delacour <delacoug@amazon.com> - 2.2.0-1
83+
* Mon Jun 5 2023 Guillaume Delacour <delacoug@amazon.com> - 2.2.0-1
8284
- Add `--quiet` option to `ec2-metadata --help` output
8385
- Add `-R`/`--region` option to `ec2-metadata` to discover the EC2 instance's region
8486

ec2nvme-nsid

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@
66
# for the specific language governing permissions and limitations under
77
# the License.
88

9-
#Expected input if partition's kernel name like nvme0n1p2
10-
if [ $# -eq 0 ] ; then
9+
# Expected input is partition's kernel name like nvme0n1p2 or nvme0n1, output would be 1
10+
11+
if [[ $# -ne 1 ]]; then
1112
exit 1
1213
else
13-
# extract ns id from partition's kernel name and export it
14-
NSID=$(echo -n "$@" | cut -f 3 -d 'n' | cut -f 1 -d 'p')
14+
kernel_name=$1
15+
16+
# Remove nvme prefix (also deals with any /dev that might accidentally get passed in)
17+
prefix_removed=${kernel_name#*nvme*n}
18+
19+
# Remove partition suffix
20+
NSID=${prefix_removed%p*}
21+
1522
echo "_NS_ID=${NSID}"
1623
fi

0 commit comments

Comments
 (0)