rbd: Close the InputStream and use a long for the offset
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/a1c8a0f6 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/a1c8a0f6 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/a1c8a0f6 Branch: refs/heads/rbd-snap-clone Commit: a1c8a0f67c079df64b7418df08037e488b579542 Parents: aee68f7 Author: Wido den Hollander <[email protected]> Authored: Thu May 16 16:58:02 2013 +0200 Committer: Wido den Hollander <[email protected]> Committed: Thu May 16 16:58:02 2013 +0200 ---------------------------------------------------------------------- .../kvm/storage/LibvirtStorageAdaptor.java | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a1c8a0f6/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java index 4525ac2..179faf9 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java @@ -958,7 +958,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fh)); int chunkSize = 4194304; - int offset = 0; + long offset = 0; s_logger.debug("Reading temporary file " + tmpFile + " into RBD image " + name + " in chunks of " + chunkSize + " bytes"); while(true) { byte[] buf = new byte[chunkSize]; @@ -970,6 +970,9 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { image.write(buf, offset, bytes); offset += bytes; } + bis.close(); + s_logger.debug("Removing temporary file " + tmpFile); + fh.delete(); /* Snapshot the image and protect that snapshot so we can clone (layer) from it */ s_logger.debug("Creating RBD snapshot " + this.rbdTemplateSnapName + " on image " + name); @@ -979,9 +982,6 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { rbd.close(image); r.ioCtxDestroy(io); - s_logger.debug("Removing temporary file " + tmpFile); - fh.delete(); - } catch (QemuImgException e) { s_logger.error("Failed to do a temp convert from " + srcFile.getFileName() + " to " + destFile.getFileName() + " the error was: " + e.getMessage());
