]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Allow creating volumes with a backing store but no capacity
authorJán Tomko <jtomko@redhat.com>
Tue, 17 Feb 2015 15:57:02 +0000 (16:57 +0100)
committerJán Tomko <jtomko@redhat.com>
Mon, 2 Mar 2015 07:07:11 +0000 (08:07 +0100)
The tool creating the image can get the capacity from the backing
storage. Just refresh the volume afterwards.

https://bugzilla.redhat.com/show_bug.cgi?id=958510

src/storage/storage_backend.c
src/storage/storage_backend_fs.c
src/storage/storage_backend_rbd.c
src/storage/storage_backend_sheepdog.c
src/storage/storage_driver.c
tests/storagevolxml2argvdata/qcow2-nocapacity.argv [new file with mode: 0644]
tests/storagevolxml2argvtest.c
tests/storagevolxml2xmlin/vol-qcow2-nocapacity-backing.xml [new file with mode: 0644]

index 7230ac7712bda748f30dc6339a093fa520244ff0..a4e75f5a5c8eb9a37b4cb3b610ba28fa9803b1b7 100644 (file)
@@ -487,6 +487,12 @@ virStorageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED,
         goto cleanup;
     }
 
+    if (vol->target.backingStore) {
+        virReportError(VIR_ERR_NO_SUPPORT, "%s",
+                       _("backing storage not supported for raw volumes"));
+        goto cleanup;
+    }
+
     if (flags & VIR_STORAGE_VOL_CREATE_REFLINK)
         reflink_copy = true;
 
@@ -1055,7 +1061,7 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
     if (convert)
         virCommandAddArg(cmd, inputPath);
     virCommandAddArg(cmd, vol->target.path);
-    if (!convert)
+    if (!convert && size_arg)
         virCommandAddArgFormat(cmd, "%lluK", size_arg);
 
     return cmd;
index 77d894c9a7c39f36612e40a5825627175d64b124..35385db84f431d3a4cf8d4ef737e1cb5668fcf2d 100644 (file)
@@ -1037,6 +1037,13 @@ static int createFileDir(virConnectPtr conn ATTRIBUTE_UNUSED,
         return -1;
     }
 
+    if (vol->target.backingStore) {
+        virReportError(VIR_ERR_NO_SUPPORT, "%s",
+                       _("backing storage not supported for directories volumes"));
+        return -1;
+    }
+
+
     if ((err = virDirCreate(vol->target.path, vol->target.perms->mode,
                             vol->target.perms->uid,
                             vol->target.perms->gid,
index 57182de26a357d2678bcccc6f2493e085c528b79..ae4bcb38152e5b3d9d0aff669a6b48d2e6c42a13 100644 (file)
@@ -509,6 +509,12 @@ virStorageBackendRBDBuildVol(virConnectPtr conn,
 
     virCheckFlags(0, -1);
 
+    if (!vol->target.capacity) {
+        virReportError(VIR_ERR_NO_SUPPORT, "%s",
+                       _("volume capacity required for this storage pool"));
+        goto cleanup;
+    }
+
     if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, &pool->def->source) < 0)
         goto cleanup;
 
index 941985905dd2b65e1cec2874ec0d77a095fd0128..f389d9bc53c4c542efec6da4a6d634c83868671e 100644 (file)
@@ -266,6 +266,12 @@ virStorageBackendSheepdogBuildVol(virConnectPtr conn,
 
     virCheckFlags(0, -1);
 
+    if (!vol->target.capacity) {
+        virReportError(VIR_ERR_NO_SUPPORT, "%s",
+                       _("volume capacity required for this pool"));
+        goto cleanup;
+    }
+
     virCommandPtr cmd = virCommandNewArgList(COLLIE, "vdi", "create", vol->name, NULL);
     virCommandAddArgFormat(cmd, "%llu", vol->target.capacity);
     virStorageBackendSheepdogAddHostArg(cmd, pool);
index 6e51603d10656905ed68f62a7fd20591fd9ecb6c..b95506faf594afbd2db2d1bcdcc81041f20dcd70 100644 (file)
@@ -1649,10 +1649,18 @@ storageVolCreateXML(virStoragePoolPtr obj,
     if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
         goto cleanup;
 
-    voldef = virStorageVolDefParseString(pool->def, xmldesc, 0);
+    voldef = virStorageVolDefParseString(pool->def, xmldesc,
+                                         VIR_VOL_XML_PARSE_OPT_CAPACITY);
     if (voldef == NULL)
         goto cleanup;
 
+    if (!voldef->target.capacity && !backend->buildVol) {
+        virReportError(VIR_ERR_NO_SUPPORT,
+                       "%s", _("volume capacity required for this "
+                               "storage pool"));
+        goto cleanup;
+    }
+
     if (virStorageVolCreateXMLEnsureACL(obj->conn, pool->def, voldef) < 0)
         goto cleanup;
 
@@ -1725,6 +1733,10 @@ storageVolCreateXML(virStoragePoolPtr obj,
 
     }
 
+    if (backend->refreshVol &&
+        backend->refreshVol(obj->conn, pool, voldef) < 0)
+        goto cleanup;
+
     /* Update pool metadata */
     pool->def->allocation += buildvoldef->target.allocation;
     pool->def->available -= buildvoldef->target.allocation;
diff --git a/tests/storagevolxml2argvdata/qcow2-nocapacity.argv b/tests/storagevolxml2argvdata/qcow2-nocapacity.argv
new file mode 100644 (file)
index 0000000..1198cba
--- /dev/null
@@ -0,0 +1,5 @@
+qemu-img create \
+-f qcow2 \
+-b /dev/null \
+-o backing_fmt=raw,encryption=on \
+/var/lib/libvirt/images/OtherDemo.img
index 52bb85625dcae9b46d5199ae8fc11ae62ff7a028..696659cb32696cb2add87e4befa55de93a39b6ef 100644 (file)
@@ -40,7 +40,8 @@ testCompareXMLToArgvFiles(bool shouldFail,
                           const char *inputvolxml,
                           const char *cmdline,
                           unsigned int flags,
-                          int imgformat)
+                          int imgformat,
+                          unsigned long parse_flags)
 {
     char *volXmlData = NULL;
     char *poolXmlData = NULL;
@@ -49,7 +50,6 @@ testCompareXMLToArgvFiles(bool shouldFail,
     char *expectedCmdline = NULL;
     char *actualCmdline = NULL;
     int ret = -1;
-    unsigned long parse_flags = 0;
 
     int len;
 
@@ -149,6 +149,7 @@ struct testInfo {
     const char *cmdline;
     unsigned int flags;
     int imgformat;
+    unsigned long parseflags;
 };
 
 static int
@@ -183,7 +184,7 @@ testCompareXMLToArgvHelper(const void *data)
     result = testCompareXMLToArgvFiles(info->shouldFail, poolxml, volxml,
                                        inputpoolxml, inputvolxml,
                                        cmdline, info->flags,
-                                       info->imgformat);
+                                       info->imgformat, info->parseflags);
 
  cleanup:
     VIR_FREE(poolxml);
@@ -210,11 +211,11 @@ mymain(void)
     int ret = 0;
     unsigned int flags = VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA;
 
-#define DO_TEST_FULL(shouldFail, pool, vol, inputpool, inputvol, cmdline,    \
-                     flags, imgformat)                                       \
+#define DO_TEST_FULL(shouldFail, parseflags, pool, vol, inputpool, inputvol, \
+                     cmdline, flags, imgformat)                              \
     do {                                                                     \
         struct testInfo info = { shouldFail, pool, vol, inputpool, inputvol, \
-                                 cmdline, flags, imgformat };                \
+                                 cmdline, flags, imgformat, parseflags };    \
         if (virtTestRun("Storage Vol XML-2-argv " cmdline,                   \
                         testCompareXMLToArgvHelper, &info) < 0)              \
             ret = -1;                                                        \
@@ -222,10 +223,10 @@ mymain(void)
     while (0);
 
 #define DO_TEST(pool, ...)                                                 \
-    DO_TEST_FULL(false, pool, __VA_ARGS__)
+    DO_TEST_FULL(false, 0, pool, __VA_ARGS__)
 
 #define DO_TEST_FAIL(pool, ...)                                            \
-    DO_TEST_FULL(true, pool, __VA_ARGS__)
+    DO_TEST_FULL(true, 0, pool, __VA_ARGS__)
 
     DO_TEST("pool-dir", "vol-qcow2",
             NULL, NULL,
@@ -312,6 +313,9 @@ mymain(void)
     DO_TEST("pool-dir", "vol-qcow2-nocapacity",
             "pool-dir", "vol-file",
             "qcow2-nocapacity-convert-prealloc", flags, FMT_OPTIONS);
+    DO_TEST_FULL(false, VIR_VOL_XML_PARSE_OPT_CAPACITY,
+                 "pool-dir", "vol-qcow2-nocapacity-backing", NULL, NULL,
+                 "qcow2-nocapacity", 0, FMT_OPTIONS);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
diff --git a/tests/storagevolxml2xmlin/vol-qcow2-nocapacity-backing.xml b/tests/storagevolxml2xmlin/vol-qcow2-nocapacity-backing.xml
new file mode 100644 (file)
index 0000000..f8e439b
--- /dev/null
@@ -0,0 +1,23 @@
+<volume>
+  <name>OtherDemo.img</name>
+  <key>/var/lib/libvirt/images/OtherDemo.img</key>
+  <source>
+  </source>
+  <target>
+    <path>/var/lib/libvirt/images/OtherDemo.img</path>
+    <format type='qcow2'/>
+    <permissions>
+      <mode>0644</mode>
+      <owner>0</owner>
+      <group>0</group>
+      <label>unconfined_u:object_r:virt_image_t:s0</label>
+    </permissions>
+    <encryption format='qcow'>
+      <secret type='passphrase' uuid='e78d4b51-a2af-485f-b0f5-afca709a80f4'/>
+    </encryption>
+  </target>
+  <backingStore>
+    <path>/dev/null</path>
+    <format type='raw'/>
+  </backingStore>
+</volume>