[libvirt] [PATCH 2/4] snapshot: add 'virsh snapshot-info'
Eric Blake
eblake at redhat.com
Mon Jun 11 18:03:01 UTC 2012
On 06/11/2012 12:49 AM, Osier Yang wrote:
> On 2012年05月25日 11:33, Eric Blake wrote:
>> Expose the recent API additions in virsh. Borrows ideas from 'dominfo'
>> for the general type of information to display. Output looks like:
>>
>> $ tools/virsh snapshot-info fedora-local tmp
>> Name: tmp
>> Domain: fedora-local
>> Current: no
>> State: disk-snapshot
>> Parent: -
>> Children: 1
>> Descendants: 2
>> Metadata: yes
>>
>> possibly with fewer lines when talking to older servers.
>>
>> + /* Metadata; the fallback here relies on the fact that metadata
>> + * used to have an all-or-nothing effect on snapshot count. */
>> + metadata = virDomainSnapshotHasMetadata(snapshot, 0);
>> + if (metadata< 0) {
>> + virResetLastError();
>> + count = virDomainSnapshotNum(dom,
>> + VIR_DOMAIN_SNAPSHOT_LIST_METADATA);
>> + metadata = count != 0;
>> + }
>> + vshPrint(ctl, "%-15s %s\n", _("Metadata:"),
>> + metadata> 0 ? _("yes") : _("no"));
I tweaked this part slightly (if virDomainSnapshotNum() fails due to the
LIST_METADATA flag being unsupported, then that should omit the
Metadata: line as we don't have an accurate answer).
>
> ACK
Thanks; pushed now, with this squashed in.
diff --git c/tools/virsh.c w/tools/virsh.c
index 5e6fe6d..744b629 100644
--- c/tools/virsh.c
+++ w/tools/virsh.c
@@ -16657,7 +16657,7 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd)
goto cleanup;
}
flags = 0;
- count = virDomainSnapshotNumChildren(snapshot, 0);
+ count = virDomainSnapshotNumChildren(snapshot, flags);
if (count < 0)
goto cleanup;
vshPrint(ctl, "%-15s %d\n", _("Children:"), count);
@@ -16671,13 +16671,13 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd
*cmd)
* used to have an all-or-nothing effect on snapshot count. */
metadata = virDomainSnapshotHasMetadata(snapshot, 0);
if (metadata < 0) {
+ metadata = virDomainSnapshotNum(dom,
+ VIR_DOMAIN_SNAPSHOT_LIST_METADATA);
virResetLastError();
- count = virDomainSnapshotNum(dom,
- VIR_DOMAIN_SNAPSHOT_LIST_METADATA);
- metadata = count != 0;
}
- vshPrint(ctl, "%-15s %s\n", _("Metadata:"),
- metadata > 0 ? _("yes") : _("no"));
+ if (metadata >= 0)
+ vshPrint(ctl, "%-15s %s\n", _("Metadata:"),
+ metadata ? _("yes") : _("no"));
ret = true;
--
Eric Blake eblake at redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120611/80e1cfd6/attachment-0001.sig>
More information about the libvir-list
mailing list