From 219ea41d8dbad32137b4376ecb17fa958d5751b8 Mon Sep 17 00:00:00 2001 From: Chen Hanxiao Date: Tue, 3 Feb 2015 11:05:27 +0800 Subject: [PATCH] virsh-volume: add support for --reflink Add support for --reflink to the virsh 'vol-create-from' and 'vol-clone' commands to signify usage of the VIR_STORAGE_VOL_CREATE_REFLINK flag in the ensuing virStorageVolCreateXMLFrom API call. Updated the man page to describe the new flag. Signed-off-by: Chen Hanxiao --- tools/virsh-volume.c | 16 ++++++++++++++++ tools/virsh.pod | 9 ++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index d585ee272d..db94154a7f 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -204,6 +204,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "prealloc-metadata")) flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; + if (!(pool = vshCommandOptPool(ctl, cmd, "pool", NULL))) return false; @@ -378,6 +379,7 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "prealloc-metadata")) flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; + if (!(pool = vshCommandOptPool(ctl, cmd, "pool", NULL))) return false; @@ -441,6 +443,10 @@ static const vshCmdOptDef opts_vol_create_from[] = { .type = VSH_OT_BOOL, .help = N_("preallocate metadata (for qcow2 instead of full allocation)") }, + {.name = "reflink", + .type = VSH_OT_BOOL, + .help = N_("use btrfs COW lightweight copy") + }, {.name = NULL} }; @@ -460,6 +466,9 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "prealloc-metadata")) flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; + if (vshCommandOptBool(cmd, "reflink")) + flags |= VIR_STORAGE_VOL_CREATE_REFLINK; + if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) goto cleanup; @@ -554,6 +563,10 @@ static const vshCmdOptDef opts_vol_clone[] = { .type = VSH_OT_BOOL, .help = N_("preallocate metadata (for qcow2 instead of full allocation)") }, + {.name = "reflink", + .type = VSH_OT_BOOL, + .help = N_("use btrfs COW lightweight copy") + }, {.name = NULL} }; @@ -574,6 +587,9 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "prealloc-metadata")) flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; + if (vshCommandOptBool(cmd, "reflink")) + flags |= VIR_STORAGE_VOL_CREATE_REFLINK; + origpool = virStoragePoolLookupByVolume(origvol); if (!origpool) { vshError(ctl, "%s", _("failed to get parent pool")); diff --git a/tools/virsh.pod b/tools/virsh.pod index 804458e367..e367e04ccf 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -3160,6 +3160,7 @@ B =item B I I [I<--inputpool> I] I [I<--prealloc-metadata>] +[I<--reflink>] Create a volume, using another volume as input. I is the name or UUID of the storage pool to create the volume in. @@ -3171,6 +3172,9 @@ I is the name or key or path of the source volume. 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. +When I<--reflink> is specified, perform a COW lightweight copy, +where the data blocks are copied only when modified. +If this is not possible, the copy fails. =item B I I I [I<--allocation> I] [I<--format> I] [I<--backing-vol> @@ -3205,7 +3209,7 @@ 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<--prealloc-metadata>] +I [I<--prealloc-metadata>] [I<--reflink>] Clone an existing volume. Less powerful, but easier to type, version of B. @@ -3217,6 +3221,9 @@ I is the name of the new volume. 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. +When I<--reflink> is specified, perform a COW lightweight copy, +where the data blocks are copied only when modified. +If this is not possible, the copy fails. =item B [I<--pool> I] I -- 2.39.5