You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by yn...@apache.org on 2014/07/13 08:33:47 UTC

git commit: updated refs/heads/master to e7392cd

Repository: cloudstack
Updated Branches:
  refs/heads/master 388210c8f -> e7392cdac


Remove "--output" option from qemu-img info command call

since the option is not supported by qemu-img in CentOS 6.3


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

Branch: refs/heads/master
Commit: e7392cdac63f1fb835599ef1545139bf6165a078
Parents: 388210c
Author: ynojima <ma...@ynojima.net>
Authored: Sat Jul 12 00:22:06 2014 -0600
Committer: ynojima <ma...@ynojima.net>
Committed: Sun Jul 13 00:33:16 2014 -0600

----------------------------------------------------------------------
 .../kvm/storage/LibvirtStorageAdaptor.java      | 14 ++++----
 .../apache/cloudstack/utils/qemu/QemuImg.java   | 36 +++++++++++++-------
 .../cloudstack/utils/qemu/QemuImgTest.java      | 16 ++++-----
 3 files changed, 38 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e7392cda/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 ecf3e08..e9c588e 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
@@ -674,8 +674,8 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
                                                     PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size) {
         String volPath = pool.getLocalPath() + "/" + name;
         String volName = name;
-        long volAllocation = 0;
-        long volCapacity = 0;
+        long virtualSize = 0;
+        long actualSize = 0;
 
         final int timeout = 0;
 
@@ -691,8 +691,8 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
         try{
             qemu.create(destFile, options);
             Map<String, String> info = qemu.info(destFile);
-            volAllocation = Long.parseLong(info.get(new String("virtual-size")));
-            volCapacity = Long.parseLong(info.get(new String("actual-size")));
+            virtualSize = Long.parseLong(info.get(new String("virtual_size")));
+            actualSize = new File(destFile.getFileName()).length();
         } catch (QemuImgException e) {
             s_logger.error("Failed to create " + volPath +
                     " due to a failed executing of qemu-img: " + e.getMessage());
@@ -700,8 +700,8 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
 
         KVMPhysicalDisk disk = new KVMPhysicalDisk(volPath, volName, pool);
         disk.setFormat(format);
-        disk.setSize(volAllocation);
-        disk.setVirtualSize(volCapacity);
+        disk.setSize(actualSize);
+        disk.setVirtualSize(virtualSize);
         return disk;
     }
 
@@ -1189,7 +1189,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
                 srcFile = new QemuImgFile(sourcePath, sourceFormat);
                 try {
                     Map<String, String> info = qemu.info(srcFile);
-                    String backingFile = info.get(new String("backing-file"));
+                    String backingFile = info.get(new String("backing_file"));
                     // qcow2 templates can just be copied into place
                     if (sourceFormat.equals(destFormat) && backingFile == null && sourcePath.endsWith(".qcow2")) {
                         String result = Script.runSimpleBashScript("cp -f " + sourcePath + " " + destPath, timeout);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e7392cda/plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/qemu/QemuImg.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/qemu/QemuImg.java b/plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/qemu/QemuImg.java
index 56ed607..389ac21 100644
--- a/plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/qemu/QemuImg.java
+++ b/plugins/hypervisors/kvm/src/org/apache/cloudstack/utils/qemu/QemuImg.java
@@ -16,16 +16,13 @@
 // under the License.
 package org.apache.cloudstack.utils.qemu;
 
+import java.util.HashMap;
 import java.util.Map;
 import com.cloud.storage.Storage;
 
 import com.cloud.utils.script.Script;
 import com.cloud.utils.script.OutputInterpreter;
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
-import org.apache.commons.lang.NotImplementedException;
-
-import java.lang.reflect.Type;
+import sun.reflect.generics.reflectiveObjects.NotImplementedException;
 
 public class QemuImg {
 
@@ -285,9 +282,9 @@ public class QemuImg {
      * Qemu-img returns human readable output, but this method does it's best
      * to turn that into machine readeable data.
      *
-     * Spaces in keys are replaced by hyphen-minus (-).
-     * Sizes (virtual-size and disk-size) are returned in bytes
-     * Paths (image and backing-file) are the absolute path to the file
+     * Spaces in keys are replaced by underscores (_).
+     * Sizes (virtual_size and disk_size) are returned in bytes
+     * Paths (image and backing_file) are the absolute path to the file
      *
      * @param file
      *            A QemuImgFile object containing the file to get the information from
@@ -296,8 +293,6 @@ public class QemuImg {
     public Map<String, String> info(QemuImgFile file) throws QemuImgException {
         Script s = new Script(_qemuImgPath);
         s.add("info");
-        s.add("--output");
-        s.add("json");
         s.add(file.getFileName());
         OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
         String result = s.execute(parser);
@@ -305,9 +300,24 @@ public class QemuImg {
             throw new QemuImgException(result);
         }
 
-        Type stringStringMap = new TypeToken<Map<String, String>>(){}.getType();
-        Gson gson = new Gson();
-        return gson.fromJson(parser.getLines(), stringStringMap);
+        HashMap<String, String> info = new HashMap<String, String>();
+        String[] outputBuffer = parser.getLines().trim().split("\n");
+        for (int i = 0; i < outputBuffer.length; i++) {
+            String[] lineBuffer = outputBuffer[i].split(":", 2);
+            if (lineBuffer.length == 2) {
+                String key = lineBuffer[0].trim().replace(" ", "_");
+                String value = null;
+
+                if (key.equals("virtual_size")) {
+                    value = lineBuffer[1].trim().replaceAll("^.*\\(([0-9]+).*$", "$1");
+                } else {
+                    value = lineBuffer[1].trim();
+                }
+
+                info.put(key, value);
+            }
+        }
+        return info;
     }
 
     /* List, apply, create or delete snapshots in image */

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e7392cda/plugins/hypervisors/kvm/test/org/apache/cloudstack/utils/qemu/QemuImgTest.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/test/org/apache/cloudstack/utils/qemu/QemuImgTest.java b/plugins/hypervisors/kvm/test/org/apache/cloudstack/utils/qemu/QemuImgTest.java
index 9059f8c..e81890a 100644
--- a/plugins/hypervisors/kvm/test/org/apache/cloudstack/utils/qemu/QemuImgTest.java
+++ b/plugins/hypervisors/kvm/test/org/apache/cloudstack/utils/qemu/QemuImgTest.java
@@ -51,7 +51,7 @@ public class QemuImgTest {
             fail("We didn't get any information back from qemu-img");
         }
 
-        Long infoSize = Long.parseLong(info.get(new String("virtual-size")));
+        Long infoSize = Long.parseLong(info.get(new String("virtual_size")));
         assertEquals(Long.valueOf(size), Long.valueOf(infoSize));
 
         String infoPath = info.get(new String("image"));
@@ -78,13 +78,13 @@ public class QemuImgTest {
         qemu.create(file, options);
         Map<String, String> info = qemu.info(file);
 
-        Long infoSize = Long.parseLong(info.get(new String("virtual-size")));
+        Long infoSize = Long.parseLong(info.get(new String("virtual_size")));
         assertEquals(Long.valueOf(size), Long.valueOf(infoSize));
 
         String infoPath = info.get(new String("image"));
         assertEquals(filename, infoPath);
 
-        String infoClusterSize = info.get(new String("cluster-size"));
+        String infoClusterSize = info.get(new String("cluster_size"));
         assertEquals(clusterSize, infoClusterSize);
 
         File f = new File(filename);
@@ -135,7 +135,7 @@ public class QemuImgTest {
                 fail("We didn't get any information back from qemu-img");
             }
 
-            Long infoSize = Long.parseLong(info.get(new String("virtual-size")));
+            Long infoSize = Long.parseLong(info.get(new String("virtual_size")));
             assertEquals(Long.valueOf(endSize), Long.valueOf(infoSize));
         } catch (QemuImgException e) {
             fail(e.getMessage());
@@ -164,7 +164,7 @@ public class QemuImgTest {
                 fail("We didn't get any information back from qemu-img");
             }
 
-            Long infoSize = Long.parseLong(info.get(new String("virtual-size")));
+            Long infoSize = Long.parseLong(info.get(new String("virtual_size")));
             assertEquals(Long.valueOf(startSize + increment), Long.valueOf(infoSize));
         } catch (QemuImgException e) {
             fail(e.getMessage());
@@ -192,7 +192,7 @@ public class QemuImgTest {
                 fail("We didn't get any information back from qemu-img");
             }
 
-            Long infoSize = Long.parseLong(info.get(new String("virtual-size")));
+            Long infoSize = Long.parseLong(info.get(new String("virtual_size")));
             assertEquals(Long.valueOf(startSize + increment), Long.valueOf(infoSize));
         } catch (QemuImgException e) {
             fail(e.getMessage());
@@ -255,7 +255,7 @@ public class QemuImgTest {
             fail("We didn't get any information back from qemu-img");
         }
 
-        String backingFile = info.get(new String("backing-file"));
+        String backingFile = info.get(new String("backing_file"));
         if (backingFile == null) {
             fail("The second file does not have a property backing_file! Create failed?");
         }
@@ -306,7 +306,7 @@ public class QemuImgTest {
         PhysicalDiskFormat infoFormat = PhysicalDiskFormat.valueOf(info.get(new String("format")).toUpperCase());
         assertEquals(destFormat, infoFormat);
 
-        Long infoSize = Long.parseLong(info.get(new String("virtual-size")));
+        Long infoSize = Long.parseLong(info.get(new String("virtual_size")));
         assertEquals(Long.valueOf(srcSize), Long.valueOf(infoSize));
 
         File sf = new File(srcFileName);