Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 17D1611331 for ; Thu, 31 Jul 2014 09:31:57 +0000 (UTC) Received: (qmail 15879 invoked by uid 500); 31 Jul 2014 09:31:56 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 15847 invoked by uid 500); 31 Jul 2014 09:31:56 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 15838 invoked by uid 99); 31 Jul 2014 09:31:56 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 31 Jul 2014 09:31:56 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 9474F9BB4B0; Thu, 31 Jul 2014 09:31:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: santhoshedukulla@apache.org To: commits@cloudstack.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: git commit: updated refs/heads/master to 4470911 Date: Thu, 31 Jul 2014 09:31:56 +0000 (UTC) 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 Authored: Thu Jul 31 15:01:30 2014 +0530 Committer: Santhosh Edukulla 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 params = new HashMap(); @@ -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();