cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From santhosheduku...@apache.org
Subject git commit: updated refs/heads/master to 4470911
Date Thu, 31 Jul 2014 09:31:56 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master b919da8a5 -> 44709111a


Added Coverity Fixes


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/44709111
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/44709111
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/44709111

Branch: refs/heads/master
Commit: 44709111a3280e29865e82a081c5efbe0120cd85
Parents: b919da8
Author: Santhosh Edukulla <santhosh.edukulla@gmail.com>
Authored: Thu Jul 31 15:01:30 2014 +0530
Committer: Santhosh Edukulla <santhosh.edukulla@gmail.com>
Committed: Thu Jul 31 15:01:30 2014 +0530

----------------------------------------------------------------------
 .../kvm/resource/LibvirtComputingResource.java  | 58 ++++++++++----------
 1 file changed, 28 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/44709111/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
index 1be797c..f84af6b 100755
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
@@ -2465,24 +2465,25 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Serv
                     IoCTX io = r.ioCtxCreate(primaryPool.getSourceDir());
                     Rbd rbd = new Rbd(io);
                     RbdImage image = rbd.open(snapshotDisk.getName(), snapshotName);
-
                     File fh = new File(snapshotDestPath);
-                    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fh));
-                    int chunkSize = 4194304;
-                    long offset = 0;
-                    s_logger.debug("Backuping up RBD snapshot " + snapshotName + " to  "
+ snapshotDestPath);
-                    while (true) {
-                        byte[] buf = new byte[chunkSize];
-
-                        int bytes = image.read(offset, buf, chunkSize);
-                        if (bytes <= 0) {
-                            break;
+                    try(BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fh));)
{
+                        int chunkSize = 4194304;
+                        long offset = 0;
+                        s_logger.debug("Backuping up RBD snapshot " + snapshotName + " to
 " + snapshotDestPath);
+                        while (true) {
+                            byte[] buf = new byte[chunkSize];
+                            int bytes = image.read(offset, buf, chunkSize);
+                            if (bytes <= 0) {
+                                break;
+                            }
+                            bos.write(buf, 0, bytes);
+                            offset += bytes;
                         }
-                        bos.write(buf, 0, bytes);
-                        offset += bytes;
+                        s_logger.debug("Completed backing up RBD snapshot " + snapshotName
+ " to  " + snapshotDestPath + ". Bytes written: " + offset);
+                    }catch(IOException ex)
+                    {
+                        s_logger.error("BackupSnapshotAnswer:Exception:"+ ex.getMessage());
                     }
-                    s_logger.debug("Completed backing up RBD snapshot " + snapshotName +
" to  " + snapshotDestPath + ". Bytes written: " + offset);
-                    bos.close();
                     r.ioCtxDestroy(io);
                 } catch (RadosException e) {
                     s_logger.error("A RADOS operation failed. The error was: " + e.getMessage());
@@ -2490,12 +2491,6 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Serv
                 } catch (RbdException e) {
                     s_logger.error("A RBD operation on " + snapshotDisk.getName() + " failed.
The error was: " + e.getMessage());
                     return new BackupSnapshotAnswer(cmd, false, e.toString(), null, true);
-                } catch (FileNotFoundException e) {
-                    s_logger.error("Failed to open " + snapshotDestPath + ". The error was:
" + e.getMessage());
-                    return new BackupSnapshotAnswer(cmd, false, e.toString(), null, true);
-                } catch (IOException e) {
-                    s_logger.debug("An I/O error occured during a snapshot operation on "
+ snapshotDestPath);
-                    return new BackupSnapshotAnswer(cmd, false, e.toString(), null, true);
                 }
             } else {
                 Script command = new Script(_manageSnapshotPath, _cmdsTimeout, s_logger);
@@ -2721,10 +2716,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Serv
                 Date date = new Date();
                 templateContent += "snapshot.name=" + dateFormat.format(date) + System.getProperty("line.separator");
 
-                FileOutputStream templFo = new FileOutputStream(templateProp);
-                templFo.write(templateContent.getBytes());
-                templFo.flush();
-                templFo.close();
+                try(FileOutputStream templFo = new FileOutputStream(templateProp);) {
+                    templFo.write(templateContent.getBytes());
+                    templFo.flush();
+                }catch(IOException ex)
+                {
+                    s_logger.error("CreatePrivateTemplateAnswer:Exception:"+ex.getMessage());
+                }
+
             }
 
             Map<String, Object> params = new HashMap<String, Object>();
@@ -3546,10 +3545,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Serv
 
         if (prvKeyFile.exists()) {
             String prvKey = cmd.getPrvKey();
-            try {
-                FileOutputStream prvKStream = new FileOutputStream(prvKeyFile);
-                prvKStream.write(prvKey.getBytes());
-                prvKStream.close();
+            try (FileOutputStream prvKStream = new FileOutputStream(prvKeyFile);){
+                if ( prvKStream != null) {
+                    prvKStream.write(prvKey.getBytes());
+                }
             } catch (FileNotFoundException e) {
                 result = "File" + SSHPRVKEYPATH + "is not found:" + e.toString();
                 s_logger.debug(result);
@@ -3557,7 +3556,6 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Serv
                 result = "Write file " + SSHPRVKEYPATH + ":" + e.toString();
                 s_logger.debug(result);
             }
-
             Script script = new Script("chmod", _timeout, s_logger);
             script.add("600", SSHPRVKEYPATH);
             script.execute();


Mime
View raw message