提交 b28a068b 编写于 作者: J Justin Clift 提交者: Eric Blake

virsh: add snapshot backing store support to vol-create-as

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.
上级 3cf642a0
...@@ -5279,6 +5279,8 @@ static const vshCmdOptDef opts_vol_create_as[] = { ...@@ -5279,6 +5279,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")}, {"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")}, {"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")}, {"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} {NULL, 0, 0, NULL}
}; };
...@@ -5318,6 +5320,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) ...@@ -5318,6 +5320,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
int found; int found;
char *xml; char *xml;
char *name, *capacityStr, *allocationStr, *format; char *name, *capacityStr, *allocationStr, *format;
char *snapshotStrVol, *snapshotStrFormat;
unsigned long long capacity, allocation = 0; unsigned long long capacity, allocation = 0;
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
...@@ -5344,6 +5347,8 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) ...@@ -5344,6 +5347,8 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
vshError(ctl, _("Malformed size %s"), allocationStr); vshError(ctl, _("Malformed size %s"), allocationStr);
format = vshCommandOptString(cmd, "format", &found); format = vshCommandOptString(cmd, "format", &found);
snapshotStrVol = vshCommandOptString(cmd, "backing-vol", &found);
snapshotStrFormat = vshCommandOptString(cmd, "backing-vol-format", &found);
virBufferAddLit(&buf, "<volume>\n"); virBufferAddLit(&buf, "<volume>\n");
virBufferVSprintf(&buf, " <name>%s</name>\n", name); virBufferVSprintf(&buf, " <name>%s</name>\n", name);
...@@ -5356,8 +5361,62 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) ...@@ -5356,8 +5361,62 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
virBufferVSprintf(&buf, " <format type='%s'/>\n",format); virBufferVSprintf(&buf, " <format type='%s'/>\n",format);
virBufferAddLit(&buf, " </target>\n"); 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)) { if (virBufferError(&buf)) {
vshPrint(ctl, "%s", _("Failed to allocate XML buffer")); vshPrint(ctl, "%s", _("Failed to allocate XML buffer"));
......
...@@ -784,8 +784,8 @@ source volume is in. ...@@ -784,8 +784,8 @@ source volume is in.
I<vol-name-or-key-or-path> is the name or key or path of the source volume. 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 =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<--allocation> I<size> I<--format> I<string> I<--backing-vol>
I<vol-name-or-key-or-path> I<--snapshot-source-format> I<string> I<vol-name-or-key-or-path> I<--backing-vol-format> I<string>
Create a volume from a set of arguments. 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 I<pool-or-uuid> is the name or UUID of the storage pool to create the volume
...@@ -797,10 +797,10 @@ I<--allocation> I<size> is the initial size to be allocated in the volume, with ...@@ -797,10 +797,10 @@ I<--allocation> I<size> is the initial size to be allocated in the volume, with
optional k, M, G, or T suffix. optional k, M, G, or T suffix.
I<--format> I<string> is used in file based storage pools to specify the volume I<--format> I<string> is used in file based storage pools to specify the volume
file format to use; raw, bochs, qcow, qcow2, vmdk. 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. 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; I<--backing-vol-format> I<string> is the format of the snapshot backing volume;
raw, bochs, qcow, qcow2, vmdk. 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> =item B<vol-clone> [optional I<--pool> I<pool-or-uuid>] I<vol-name-or-key-or-path> I<name>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册