[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH] virsh: add snapshot backing store support to vol-create-as



On Wed, Jun 09, 2010 at 02:38:32AM +1000, Justin Clift wrote:
> This patch adds two new parameters to the vol-create-as command:
> 
>  --backing-vol <volume-name-or-key-or-path>
>  --backing-vol-format <format-of-backing-vol>
> 
>   virsh # vol-create-as guest_images_lvm snapvol1 5G --backing-vol \
>               rhel6vm1lun1
>   Vol snapvol1 created
> 
>   virsh # vol-create-as image_dir qcow2snap2 5G --format qcow2 \
>               --backing-vol imagevol1.qcow2 \
>               --backing-vol-format qcow2
>   Vol qcow2snap2 created
> 
> Additionally, the virsh man page update fixes incorrect snapshot
> parameters that were included in my prior bulk volume command patch.
> ---
>  tools/virsh.c   |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  tools/virsh.pod |   10 ++++----
>  2 files changed, 65 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/virsh.c b/tools/virsh.c
> index 1e00114..f990ccd 100644
> --- a/tools/virsh.c
> +++ b/tools/virsh.c
> @@ -5274,6 +5274,8 @@ static const vshCmdOptDef opts_vol_create_as[] = {
>      {"capacity", VSH_OT_DATA, VSH_OFLAG_REQ, N_("size of the vol with optional k,M,G,T suffix")},
>      {"allocation", VSH_OT_STRING, 0, N_("initial allocation size with optional k,M,G,T suffix")},
>      {"format", VSH_OT_STRING, 0, N_("file format type raw,bochs,qcow,qcow2,vmdk")},
> +    {"backing-vol", VSH_OT_STRING, 0, N_("the backing volume if taking a snapshot")},
> +    {"backing-vol-format", VSH_OT_STRING, 0, N_("format of backing volume if taking a snapshot")},
>      {NULL, 0, 0, NULL}
>  };
>  
> @@ -5313,6 +5315,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
>      int found;
>      char *xml;
>      char *name, *capacityStr, *allocationStr, *format;
> +    char *snapshotStrVol, *snapshotStrFormat;
>      unsigned long long capacity, allocation = 0;
>      virBuffer buf = VIR_BUFFER_INITIALIZER;
>  
> @@ -5339,6 +5342,8 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
>          vshError(ctl, _("Malformed size %s"), allocationStr);
>  
>      format = vshCommandOptString(cmd, "format", &found);
> +    snapshotStrVol = vshCommandOptString(cmd, "backing-vol", &found);
> +    snapshotStrFormat = vshCommandOptString(cmd, "backing-vol-format", &found);
>  
>      virBufferAddLit(&buf, "<volume>\n");
>      virBufferVSprintf(&buf, "  <name>%s</name>\n", name);
> @@ -5351,8 +5356,62 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
>          virBufferVSprintf(&buf, "    <format type='%s'/>\n",format);
>          virBufferAddLit(&buf, "  </target>\n");
>      }
> -    virBufferAddLit(&buf, "</volume>\n");
>  
> +    /* Convert the snapshot parameters into backingStore XML */
> +    if (snapshotStrVol) {
> +        /* Lookup snapshot backing volume.  Try the backing-vol
> +         *  parameter as a name */
> +        vshDebug(ctl, 5, "%s: Look up backing store volume '%s' as name\n",
> +                 cmd->def->name, snapshotStrVol);
> +        virStorageVolPtr snapVol = virStorageVolLookupByName(pool, snapshotStrVol);
> +        if (snapVol)
> +                vshDebug(ctl, 5, "%s: Backing store volume found using '%s' as name\n",
> +                         cmd->def->name, snapshotStrVol);
> +
> +        if (snapVol == NULL) {
> +            /* Snapshot backing volume not found by name.  Try the
> +             *  backing-vol parameter as a key */
> +            vshDebug(ctl, 5, "%s: Look up backing store volume '%s' as key\n",
> +                     cmd->def->name, snapshotStrVol);
> +            snapVol = virStorageVolLookupByKey(ctl->conn, snapshotStrVol);
> +            if (snapVol)
> +                vshDebug(ctl, 5, "%s: Backing store volume found using '%s' as key\n",
> +                         cmd->def->name, snapshotStrVol);
> +        }
> +        if (snapVol == NULL) {
> +            /* Snapshot backing volume not found by key.  Try the
> +             *  backing-vol parameter as a path */
> +            vshDebug(ctl, 5, "%s: Look up backing store volume '%s' as path\n",
> +                     cmd->def->name, snapshotStrVol);
> +            snapVol = virStorageVolLookupByPath(ctl->conn, snapshotStrVol);
> +            if (snapVol)
> +                vshDebug(ctl, 5, "%s: Backing store volume found using '%s' as path\n",
> +                         cmd->def->name, snapshotStrVol);
> +        }
> +        if (snapVol == NULL) {
> +            vshError(ctl, _("failed to get vol '%s'"), snapshotStrVol);
> +            return FALSE;
> +        }
> +
> +        char *snapshotStrVolPath;
> +        if ((snapshotStrVolPath = virStorageVolGetPath(snapVol)) == NULL) {
> +            virStorageVolFree(snapVol);
> +            return FALSE;
> +        }
> +
> +        /* Create XML for the backing store */
> +        virBufferAddLit(&buf, "  <backingStore>\n");
> +        virBufferVSprintf(&buf, "    <path>%s</path>\n",snapshotStrVolPath);
> +        if (snapshotStrFormat)
> +            virBufferVSprintf(&buf, "    <format type='%s'/>\n",snapshotStrFormat);
> +        virBufferAddLit(&buf, "  </backingStore>\n");
> +
> +        /* Cleanup snapshot allocations */
> +        VIR_FREE(snapshotStrVolPath);
> +        virStorageVolFree(snapVol);
> +    }
> +
> +    virBufferAddLit(&buf, "</volume>\n");
>  
>      if (virBufferError(&buf)) {
>          vshPrint(ctl, "%s", _("Failed to allocate XML buffer"));
> diff --git a/tools/virsh.pod b/tools/virsh.pod
> index 3b0cf16..56afd52 100644
> --- a/tools/virsh.pod
> +++ b/tools/virsh.pod
> @@ -782,8 +782,8 @@ source volume is in.
>  I<vol-name-or-key-or-path> is the name or key or path of the source volume.
>  
>  =item B<vol-create-as> I<pool-or-uuid> I<name> I<capacity> optional
> -I<--allocation> I<size> I<--format> I<string> I<--snapshot-source-vol>
> -I<vol-name-or-key-or-path> I<--snapshot-source-format> I<string>
> +I<--allocation> I<size> I<--format> I<string> I<--backing-vol>
> +I<vol-name-or-key-or-path> I<--backing-vol-format> I<string>
>  
>  Create a volume from a set of arguments.
>  I<pool-or-uuid> is the name or UUID of the storage pool to create the volume
> @@ -795,10 +795,10 @@ I<--allocation> I<size> is the initial size to be allocated in the volume, with
>  optional k, M, G, or T suffix.
>  I<--format> I<string> is used in file based storage pools to specify the volume
>  file format to use; raw, bochs, qcow, qcow2, vmdk.
> -I<--snapshot-source-vol> I<vol-name-or-key-or-path> is the source backing
> +I<--backing-vol> I<vol-name-or-key-or-path> is the source backing
>  volume to be used if taking a snapshot of an existing volume.
> -I<--snapshot-source-format> I<string> is the format of the snapshot backing volume;
> -raw, bochs, qcow, qcow2, vmdk.
> +I<--backing-vol-format> I<string> is the format of the snapshot backing volume;
> +raw, bochs, qcow, qcow2, vmdk, host_device.
>  
>  =item B<vol-clone> [optional I<--pool> I<pool-or-uuid>] I<vol-name-or-key-or-path> I<name>
>  
> -- 

ACK, this looks fine to me


Daniel
-- 
|: Red Hat, Engineering, London    -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org        -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]