diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 7230ac7712..a4e75f5a5c 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -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; diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index 77d894c9a7..35385db84f 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -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, diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c index 57182de26a..ae4bcb3815 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -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; diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_backend_sheepdog.c index 941985905d..f389d9bc53 100644 --- a/src/storage/storage_backend_sheepdog.c +++ b/src/storage/storage_backend_sheepdog.c @@ -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); diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 6e51603d10..b95506faf5 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -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 index 0000000000..1198cbaf2e --- /dev/null +++ b/tests/storagevolxml2argvdata/qcow2-nocapacity.argv @@ -0,0 +1,5 @@ +qemu-img create \ +-f qcow2 \ +-b /dev/null \ +-o backing_fmt=raw,encryption=on \ +/var/lib/libvirt/images/OtherDemo.img diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c index 52bb85625d..696659cb32 100644 --- a/tests/storagevolxml2argvtest.c +++ b/tests/storagevolxml2argvtest.c @@ -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 index 0000000000..f8e439bc56 --- /dev/null +++ b/tests/storagevolxml2xmlin/vol-qcow2-nocapacity-backing.xml @@ -0,0 +1,23 @@ + + OtherDemo.img + /var/lib/libvirt/images/OtherDemo.img + + + + /var/lib/libvirt/images/OtherDemo.img + + + 0644 + 0 + 0 + + + + + + + + /dev/null + + +