diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index f219de98b2a4491ab3669bb7fe9156f6d638787d..21a2df08d821326eaf7a26535808acbdbdd58ae8 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -124,6 +124,8 @@ static const vshCmdOptDef opts_vol_create_as[] = { N_("the backing volume if taking a snapshot")}, {"backing-vol-format", VSH_OT_STRING, 0, N_("format of backing volume if taking a snapshot")}, + {"prealloc-metadata", VSH_OT_BOOL, 0, N_("preallocate metadata (for qcow2 " + "instead of full allocation)")}, {NULL, 0, 0, NULL} }; @@ -146,7 +148,10 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) const char *snapshotStrVol = NULL, *snapshotStrFormat = NULL; unsigned long long capacity, allocation = 0; virBuffer buf = VIR_BUFFER_INITIALIZER; + unsigned long flags = 0; + if (vshCommandOptBool(cmd, "prealloc-metadata")) + flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; if (!(pool = vshCommandOptPoolBy(ctl, cmd, "pool", NULL, VSH_BYNAME))) return false; @@ -256,7 +261,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) goto cleanup; } xml = virBufferContentAndReset(&buf); - vol = virStorageVolCreateXML(pool, xml, 0); + vol = virStorageVolCreateXML(pool, xml, flags); VIR_FREE(xml); virStoragePoolFree(pool); @@ -287,6 +292,8 @@ static const vshCmdInfo info_vol_create[] = { static const vshCmdOptDef opts_vol_create[] = { {"pool", VSH_OT_DATA, VSH_OFLAG_REQ, N_("pool name")}, {"file", VSH_OT_DATA, VSH_OFLAG_REQ, N_("file containing an XML vol description")}, + {"prealloc-metadata", VSH_OT_BOOL, 0, N_("preallocate metadata (for qcow2 " + "instead of full allocation)")}, {NULL, 0, 0, NULL} }; @@ -297,8 +304,11 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd) virStorageVolPtr vol; const char *from = NULL; bool ret = true; + unsigned int flags = 0; char *buffer; + if (vshCommandOptBool(cmd, "prealloc-metadata")) + flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; if (!(pool = vshCommandOptPoolBy(ctl, cmd, "pool", NULL, VSH_BYNAME))) return false; @@ -314,7 +324,7 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd) return false; } - vol = virStorageVolCreateXML(pool, buffer, 0); + vol = virStorageVolCreateXML(pool, buffer, flags); VIR_FREE(buffer); virStoragePoolFree(pool); @@ -343,6 +353,8 @@ static const vshCmdOptDef opts_vol_create_from[] = { {"file", VSH_OT_DATA, VSH_OFLAG_REQ, N_("file containing an XML vol description")}, {"vol", VSH_OT_DATA, VSH_OFLAG_REQ, N_("input vol name or key")}, {"inputpool", VSH_OT_STRING, 0, N_("pool name or uuid of the input volume's pool")}, + {"prealloc-metadata", VSH_OT_BOOL, 0, N_("preallocate metadata (for qcow2 " + "instead of full allocation)")}, {NULL, 0, 0, NULL} }; @@ -354,10 +366,13 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) const char *from = NULL; bool ret = false; char *buffer = NULL; + unsigned int flags = 0; if (!(pool = vshCommandOptPool(ctl, cmd, "pool", NULL))) goto cleanup; + if (vshCommandOptBool(cmd, "prealloc-metadata")) + flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; if (vshCommandOptString(cmd, "file", &from) <= 0) { goto cleanup; } @@ -370,7 +385,7 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - newvol = virStorageVolCreateXMLFrom(pool, buffer, inputvol, 0); + newvol = virStorageVolCreateXMLFrom(pool, buffer, inputvol, flags); if (newvol != NULL) { vshPrint(ctl, _("Vol %s created from input vol %s\n"), @@ -434,6 +449,8 @@ static const vshCmdOptDef opts_vol_clone[] = { {"vol", VSH_OT_DATA, VSH_OFLAG_REQ, N_("orig vol name or key")}, {"newname", VSH_OT_DATA, VSH_OFLAG_REQ, N_("clone name")}, {"pool", VSH_OT_STRING, 0, N_("pool name or uuid")}, + {"prealloc-metadata", VSH_OT_BOOL, 0, N_("preallocate metadata (for qcow2 " + "instead of full allocation)")}, {NULL, 0, 0, NULL} }; @@ -446,10 +463,14 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd) char *origxml = NULL; xmlChar *newxml = NULL; bool ret = false; + unsigned int flags = 0; if (!(origvol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) goto cleanup; + if (vshCommandOptBool(cmd, "prealloc-metadata")) + flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; + origpool = virStoragePoolLookupByVolume(origvol); if (!origpool) { vshError(ctl, "%s", _("failed to get parent pool")); @@ -469,7 +490,7 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - newvol = virStorageVolCreateXMLFrom(origpool, (char *) newxml, origvol, 0); + newvol = virStorageVolCreateXMLFrom(origpool, (char *) newxml, origvol, flags); if (newvol != NULL) { vshPrint(ctl, _("Vol %s cloned from %s\n"), diff --git a/tools/virsh.pod b/tools/virsh.pod index 7dde3df2eceacf982b43ee9296622193edca3c7c..b0e7064bcf3688233fb9447249d2bfbd1a366d18 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -2405,13 +2405,17 @@ Returns the UUID of the named I. =over 4 -=item B I I +=item B I I [I<--prealloc-metadata>] Create a volume from an XML . I is the name or UUID of the storage pool to create the volume in. I is the XML with the volume definition. An easy way to create the XML is to use the B command to obtain the definition of a pre-existing volume. +[I<--prealloc-metadata>] preallocate metadata (for qcow2 images which don't +support full allocation). This option creates a sparse image file with metadata, +resulting in higher performance compared to images with no preallocation and +only slightly higher initial disk space usage. B @@ -2420,7 +2424,7 @@ B virsh vol-create differentstoragepool newvolume.xml =item B I I [I<--inputpool> -I] I +I] I [I<--prealloc-metadata>] Create a volume, using another volume as input. I is the name or UUID of the storage pool to create the volume in. @@ -2428,10 +2432,15 @@ I is the XML with the volume definition. I<--inputpool> I is the name or uuid of the storage pool the source volume is in. I is the name or key or path of the source volume. +[I<--prealloc-metadata>] preallocate metadata (for qcow2 images which don't +support full allocation). This option creates a sparse image file with metadata, +resulting in higher performance compared to images with no preallocation and +only slightly higher initial disk space usage. =item B I I I [I<--allocation> I] [I<--format> I] [I<--backing-vol> I] [I<--backing-vol-format> I] +[I<--prealloc-metadata>] Create a volume from a set of arguments. I is the name or UUID of the storage pool to create the volume @@ -2448,9 +2457,13 @@ volume to be used if taking a snapshot of an existing volume. I<--backing-vol-format> I is the format of the snapshot backing volume; raw, bochs, qcow, qcow2, qed, vmdk, host_device. These are, however, meant for file based storage pools. +[I<--prealloc-metadata>] preallocate metadata (for qcow2 images which don't +support full allocation). This option creates a sparse image file with metadata, +resulting in higher performance compared to images with no preallocation and +only slightly higher initial disk space usage. =item B [I<--pool> I] I -I +I [I<--prealloc-metadata>] Clone an existing volume. Less powerful, but easier to type, version of B. @@ -2458,6 +2471,10 @@ I<--pool> I is the name or UUID of the storage pool to create the volume in. I is the name or key or path of the source volume. I is the name of the new volume. +[I<--prealloc-metadata>] preallocate metadata (for qcow2 images which don't +support full allocation). This option creates a sparse image file with metadata, +resulting in higher performance compared to images with no preallocation and +only slightly higher initial disk space usage. =item B [I<--pool> I] I