Damans227 commented on code in PR #14266:
URL: https://github.com/apache/cloudstack/pull/14266#discussion_r4258588233


##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java:
##########
@@ -431,14 +431,17 @@ private boolean attachRbdVolumeToVm(KVMStoragePoolManager 
storagePoolMgr, String
     }
 
     private String getDeviceToAttachDisk(String vmName) {
-        String[] domblkCmd = new String[] { 
Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName };
-        String[] tailCmd = new String[] { 
Script.getExecutableAbsolutePath("tail"), "-n", "3" };
-        String[] headCmd = new String[] { 
Script.getExecutableAbsolutePath("head"), "-n", "1" };
+        // --details adds a Device column (disk/cdrom) that the awk below 
filters on ($2=="disk")
+        // to exclude cdrom slots. cdrom entries (hdc, hdd) are listed after 
the virtio disks in
+        // domblklist's output, so without this filter, taking the last line 
would select a
+        // cdrom, not the actual disk.
+        String[] domblkCmd = new String[] { 
Script.getExecutableAbsolutePath("virsh"), "domblklist", "--domain", vmName, 
"--details" };
         // The commands are executed without a shell, so the awk program must 
be passed as a plain
         // argument. Keeping the quotes a shell would have stripped makes awk 
fail with
         // "invalid char" and produce no output.
-        String[] awkCmd = new String[] { 
Script.getExecutableAbsolutePath("awk"), "{print $1}" };
-        Pair<Integer, String> result = 
Script.executePipedCommands(Arrays.asList(domblkCmd, tailCmd, headCmd, awkCmd), 
0);
+        String[] awkCmd = new String[] { 
Script.getExecutableAbsolutePath("awk"), "$2==\"disk\"{print $3}" };

Review Comment:
   what happens on a vm whose disks use the ide bus? the last disk there can be 
hdb, so the next name is hdc which is already the cdrom



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to