const char *name = NULL;
const char *snapshot = NULL;
const char *driver = NULL;
+ const char *stype = NULL;
const char *file = NULL;
char **array = NULL;
int narray;
size_t i;
+ bool isFile = true;
narray = vshStringToArray(str, &array);
if (narray <= 0)
snapshot = array[i] + strlen("snapshot=");
else if (!driver && STRPREFIX(array[i], "driver="))
driver = array[i] + strlen("driver=");
+ else if (!stype && STRPREFIX(array[i], "stype="))
+ stype = array[i] + strlen("stype=");
else if (!file && STRPREFIX(array[i], "file="))
file = array[i] + strlen("file=");
else
virBufferEscapeString(buf, "<disk name='%s'", name);
if (snapshot)
virBufferAsprintf(buf, " snapshot='%s'", snapshot);
+ if (stype) {
+ if (STREQ(stype, "block")) {
+ isFile = false;
+ } else if (STRNEQ(stype, "file")) {
+ vshError(ctl, _("Unknown storage type: '%s'"), stype);
+ goto cleanup;
+ }
+ virBufferAsprintf(buf, " type='%s'", stype);
+ }
if (driver || file) {
virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 2);
if (driver)
virBufferAsprintf(buf, "<driver type='%s'/>\n", driver);
- if (file)
- virBufferEscapeString(buf, "<source file='%s'/>\n", file);
+ if (file) {
+ if (isFile)
+ virBufferEscapeString(buf, "<source file='%s'/>\n", file);
+ else
+ virBufferEscapeString(buf, "<source dev='%s'/>\n", file);
+ }
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</disk>\n");
} else {
},
{.name = "diskspec",
.type = VSH_OT_ARGV,
- .help = N_("disk attributes: disk[,snapshot=type][,driver=type][,file=name]")
+ .help = N_("disk attributes: disk[,snapshot=type][,driver=type][,stype=type][,file=name]")
},
{.name = NULL}
};
external full system snapshots create external files. This option can occur
multiple times, according to the number of <disk> elements in the domain
xml. Each <diskspec> is in the
-form B<disk[,snapshot=type][,driver=type][,file=name]>. A I<diskspec>
-must be provided for disks backed by block devices as libvirt doesn't
-auto-generate file names for those. To include a
-literal comma in B<disk> or in B<file=name>, escape it with a second
-comma. A literal I<--diskspec> must precede each B<diskspec> unless
+form B<disk[,snapshot=type][,driver=type][,stype=type][,file=name]>.
+A I<diskspec> must be provided for disks backed by block devices as libvirt
+doesn't auto-generate file names for those. The optional B<stype> parameter
+allows to control the type of the source file. Supported values are 'file'
+(default) and 'block'.
+
+To include a literal comma in B<disk> or in B<file=name>, escape it with a
+second comma. A literal I<--diskspec> must precede each B<diskspec> unless
all three of I<domain>, I<name>, and I<description> are also present.
For example, a diskspec of "vda,snapshot=external,file=/path/to,,new"
results in the following XML: