18772: address review feedback.
[arvados.git] / tools / compute-images / scripts / create-ebs-volume-nvme.patch
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: BSD-3-Clause
4
5 Make the create-ebs-volume script work with nvme devices.
6
7 diff --git a/bin/create-ebs-volume b/bin/create-ebs-volume
8 index 6857564..efeac35 100755
9 --- a/create-ebs-volume
10 +++ b/create-ebs-volume
11 @@ -149,10 +149,11 @@ function get_next_logical_device() {
12      for letter in ${alphabet[@]}; do
13          # use /dev/xvdb* device names to avoid contention for /dev/sd* and /dev/xvda names
14          # only supported by HVM instances
15 -        if [ ! -b "/dev/xvdb${letter}" ]; then
16 +        if [[ $created_volumes =~ .*/dev/xvdb${letter}.* ]]; then
17 +            continue
18 +        fi
19              echo "/dev/xvdb${letter}"
20              break
21 -        fi
22      done
23  }
24  
25 @@ -322,13 +323,21 @@ function create_and_attach_volume() {
26      set -e
27  
28      logthis "waiting for volume $volume_id on filesystem"
29 +    set +e
30      while true; do
31 -        if [ -e "$device" ]; then
32 -            logthis "volume $volume_id on filesystem as $device"
33 +        # AWS returns e.g. vol-00338247831716a7b4, the kernel changes that to vol00338247831716a7b
34 +        valid_volume_id=`echo $volume_id |sed -e 's/[^a-zA-Z0-9]//'`
35 +        # example lsblk output:
36 +        # nvme4n1                     259:7    0  150G  0 disk            vol00338247831716a7b
37 +        LSBLK=`lsblk -o +SERIAL |grep $valid_volume_id`
38 +        if [[ $? -eq 0 ]]; then
39 +            nvme_device=`echo $LSBLK|cut -f1 -d' '|xargs -I {} echo "/dev/{}"`
40 +            logthis "volume $volume_id on filesystem as $nvme_device (aws device $device)"
41              break
42          fi
43          sleep 1
44      done
45 +    set -e
46  
47      # set volume delete on termination
48      aws ec2 modify-instance-attribute \
49 @@ -338,7 +347,7 @@ function create_and_attach_volume() {
50      > /dev/null
51      logthis "volume $volume_id DeleteOnTermination ENABLED"
52  
53 -    echo $device
54 +    echo "$nvme_device"
55  }
56  
57  create_and_attach_volume