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


##########
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);

Review Comment:
   fiy - runSimpleBashScript doesn't return any exception. just a return value. 
So no need to keep it inside try-catch. So, checking the return value instead.



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