{"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}
};
int found;
char *xml;
char *name, *capacityStr, *allocationStr, *format;
+ char *snapshotStrVol, *snapshotStrFormat;
unsigned long long capacity, allocation = 0;
virBuffer buf = VIR_BUFFER_INITIALIZER;
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);
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"));
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
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>