I still need a good solution for snapshot-create-as to list multiple disk options. But this patch is sufficient to test the creation of disk snapshots using only default <disks> for snapshot-create-as, and snapshot-create provides full access to the snapshot process. * tools/virsh.c (cmdSnapshotCreate, cmdSnapshotCreateAs): Add --disk-only. * tools/virsh.pod (snapshot-create, snapshot-create-as): Document it. --- I'm thinking that: virsh snapshot-create-as dom --disk-only --disk-omit vda --disk-internal vdb \ --disk-external vdc --disk-external vdd,type=qcow2,file=/path/to/blah might be a nice syntax for specifying: <disks> <disk name='vda' snapshot='no'/> <disk name='vdb' snapshot='internal'/> <disk name='vdc' snapshot='external'/> <disk name='vdd' snapshot='external'> <driver type='qcow2'/> <source file='/path/to/blah'/> </disk> </disks> but I'm not quite sure how do that without some surgery to virsh parsing functions, since all of the --disk-* options would be allowed more than once. Another thought is: virsh snapshot-create-as dom --disk-only --disk vda,snapshot=no \ --disk vdb,snapshot=internal --disk vdc,snapshot=external \ --disk vdd,snapshot=external,type=qcow2,file=/path/to/blah and having --disk be the only repeated option, at which point it is not too much of a stretch to write: virsh snapshot-create-as dom --disk-only vda,snapshot=no \ vdb,snapshot=internal vdc,snapshot=external \ vdd,snapshot=external,type=qcow2,file=/path/to/blah and from there it looks like existing argv handling. I'll have to play with it more, but I'll save that for a separate patch. tools/virsh.c | 12 ++++++++++-- tools/virsh.pod | 20 +++++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index b081c49..16e1bf0 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -12266,6 +12266,7 @@ static const vshCmdOptDef opts_snapshot_create[] = { {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")}, {"xmlfile", VSH_OT_DATA, 0, N_("domain snapshot XML")}, {"halt", VSH_OT_BOOL, 0, N_("halt domain after snapshot is created")}, + {"disk-only", VSH_OT_BOOL, 0, N_("capture disk state but not vm state")}, {NULL, 0, 0, NULL} }; @@ -12281,6 +12282,9 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "halt")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_HALT; + if (vshCommandOptBool(cmd, "disk-only")) + flags |= VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY; + if (!vshConnectionUsability(ctl, ctl->conn)) goto cleanup; @@ -12330,6 +12334,7 @@ static const vshCmdOptDef opts_snapshot_create_as[] = { {"description", VSH_OT_DATA, 0, N_("description of snapshot")}, {"print-xml", VSH_OT_BOOL, 0, N_("print XML document rather than create")}, {"halt", VSH_OT_BOOL, 0, N_("halt domain after snapshot is created")}, + {"disk-only", VSH_OT_BOOL, 0, N_("capture disk state but not vm state")}, {NULL, 0, 0, NULL} }; @@ -12347,6 +12352,9 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "halt")) flags |= VIR_DOMAIN_SNAPSHOT_CREATE_HALT; + if (vshCommandOptBool(cmd, "disk-only")) + flags |= VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY; + if (!vshConnectionUsability(ctl, ctl->conn)) goto cleanup; @@ -12374,9 +12382,9 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) } if (vshCommandOptBool(cmd, "print-xml")) { - if (vshCommandOptBool(cmd, "halt")) { + if (flags) { vshError(ctl, "%s", - _("--print-xml and --halt are mutually exclusive")); + _("--print-xml does not work with --halt or --disk-only")); goto cleanup; } vshPrint(ctl, "%s\n", buffer); diff --git a/tools/virsh.pod b/tools/virsh.pod index b357330..a702520 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1605,26 +1605,36 @@ used to represent properties of snapshots. =over 4 -=item B<snapshot-create> I<domain> [I<xmlfile>] [I<--halt>] +=item B<snapshot-create> I<domain> [I<xmlfile>] [I<--halt>] [I<--disk-only>] Create a snapshot for domain I<domain> with the properties specified in I<xmlfile>. The only properties settable for a domain snapshot are the -<name> and <description>; the rest of the fields are ignored, and +<name> and <description>, as well as <disks> if I<--disk-only> is given; +the rest of the fields are ignored, and automatically filled in by libvirt. If I<xmlfile> is completely omitted, then libvirt will choose a value for all fields. If I<--halt> is specified, the domain will be left in an inactive state after the snapshot is created. -=item B<snapshot-create-as> I<domain> [{I<--print-xml> | I<--halt>}] -[I<name>] [I<description>] +If I<--disk-only> is specified, the snapshot will only include disk +state rather than the usual system checkpoint with vm state. Disk +snapshots are faster than full system checkpoints, but reverting to a +disk snapshot may require fsck or journal replays, since it is like +the disk state at the point when the power cord is abruptly pulled; +and mixing I<--halt> and I<--disk-only> loses any data that was not +flushed to disk at the time. + +=item B<snapshot-create-as> I<domain> {[I<--print-xml>] | [I<--halt>] +[I<--disk-only>]} [I<name>] [I<description>] Create a snapshot for domain I<domain> with the given <name> and <description>; if either value is omitted, libvirt will choose a value. If I<--print-xml> is specified, then XML appropriate for I<snapshot-create> is output, rather than actually creating a snapshot. Otherwise, if I<--halt> is specified, the domain will be left in an -inactive state after the snapshot is created. +inactive state after the snapshot is created, and if I<--disk-only> +is specified, the snapshot will not include vm state. =item B<snapshot-current> I<domain> [I<--name>] [I<--security-info>] -- 1.7.4.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list