abh1sar commented on code in PR #11560:
URL: https://github.com/apache/cloudstack/pull/11560#discussion_r2320764918


##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRestoreBackupCommandWrapper.java:
##########
@@ -140,52 +146,59 @@ private void restoreVolume(String backupPath, String 
backupRepoType, String back
                     throw new CloudRuntimeException(String.format("Failed to 
attach volume to VM: %s", vmNameAndState.first()));
                 }
             }
-        } catch (Exception e) {
-            throw new CloudRuntimeException("Failed to restore volume", e);
         } finally {
             unmountBackupDirectory(mountDirectory);
             deleteTemporaryDirectory(mountDirectory);
         }
     }
 
 
-    private String mountBackupDirectory(String backupRepoAddress, String 
backupRepoType, String mountOptions) {
+    private String mountBackupDirectory(String backupRepoAddress, String 
backupRepoType, String mountOptions, Integer mountTimeout) {
         String randomChars = RandomStringUtils.random(5, true, false);
         String mountDirectory = String.format("%s.%s",BACKUP_TEMP_FILE_PREFIX 
, randomChars);
+
         try {
             mountDirectory = 
Files.createTempDirectory(mountDirectory).toString();
-            String mount = String.format(MOUNT_COMMAND, backupRepoType, 
backupRepoAddress, mountDirectory);
-            if ("cifs".equals(backupRepoType)) {
-                if (Objects.isNull(mountOptions) || 
mountOptions.trim().isEmpty()) {
-                    mountOptions = "nobrl";
-                } else {
-                    mountOptions += ",nobrl";
-                }
-            }
-            if (Objects.nonNull(mountOptions) && 
!mountOptions.trim().isEmpty()) {
-                mount += " -o " + mountOptions;
+        } catch (IOException e) {
+            logger.error(String.format("Failed to create the tmp mount 
directory {} for restore", mountDirectory), e);
+            throw new CloudRuntimeException("Failed to create the tmp mount 
directory for restore on the KVM host");
+        }
+
+        String mount = String.format(MOUNT_COMMAND, backupRepoType, 
backupRepoAddress, mountDirectory);
+        if ("cifs".equals(backupRepoType)) {
+            if (Objects.isNull(mountOptions) || mountOptions.trim().isEmpty()) 
{
+                mountOptions = "nobrl";
+            } else {
+                mountOptions += ",nobrl";
             }
-            Script.runSimpleBashScript(mount);
-        } catch (Exception e) {
-            throw new CloudRuntimeException(String.format("Failed to mount %s 
to %s", backupRepoType, backupRepoAddress), e);
+        }
+        if (Objects.nonNull(mountOptions) && !mountOptions.trim().isEmpty()) {
+            mount += " -o " + mountOptions;
+        }
+
+        int exitValue = Script.runSimpleBashScriptForExitValue(mount, 
mountTimeout, false);
+        if (exitValue != 0) {
+            logger.error(String.format("Failed to mount repository {} of type 
{} to the directory {}", backupRepoAddress, backupRepoType, mountDirectory));
+            throw new CloudRuntimeException("Failed to mount the backup 
repository on the KVM host");
         }
         return mountDirectory;
     }
 
     private void unmountBackupDirectory(String backupDirectory) {
-        try {
-            String umountCmd = String.format(UMOUNT_COMMAND, backupDirectory);
-            Script.runSimpleBashScript(umountCmd);
-        } catch (Exception e) {
-            throw new CloudRuntimeException(String.format("Failed to unmount 
backup directory: %s", backupDirectory), e);
+        String umountCmd = String.format(UMOUNT_COMMAND, backupDirectory);
+        int exitValue = Script.runSimpleBashScriptForExitValue(umountCmd);

Review Comment:
   fiy - same here. runSimpleBashScript doesn't throw any exception.



-- 
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