diff options
author | Eric Blake <eblake@redhat.com> | 2012-06-09 21:24:57 -0600 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2012-06-19 13:50:03 -0600 |
commit | dbb564f862bc2fca63a63acdc794727340b9d046 (patch) | |
tree | 767d7b8557d8a675c1d0f27cfe8bdc99f996536b /daemon | |
parent | list: provide python bindings for snapshots (diff) | |
download | libvirt-dbb564f862bc2fca63a63acdc794727340b9d046.tar.gz libvirt-dbb564f862bc2fca63a63acdc794727340b9d046.tar.bz2 libvirt-dbb564f862bc2fca63a63acdc794727340b9d046.zip |
list: provide RPC call for snapshots
The generator doesn't handle lists of virDomainSnapshotPtr, so
this commit requires a bit more work than some RPC additions.
* src/remote/remote_protocol.x
(REMOTE_PROC_DOMAIN_LIST_ALL_SNAPSHOTS)
(REMOTE_PROC_DOMAIN_SNAPSHOT_LIST_ALL_CHILDREN): New RPC calls,
with corresponding structs.
* daemon/remote.c (remoteDispatchDomainListAllSnapshots)
(remoteDispatchDomainSnapshotListAllChildren): New functions.
* src/remote/remote_driver.c (remoteDomainListAllSnapshots)
(remoteDomainSnapshotListAllChildren): Likewise.
* src/remote_protocol-structs: Regenerate.
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/remote.c | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/daemon/remote.c b/daemon/remote.c index ac0f06824..b8c2aab13 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -3797,6 +3797,132 @@ cleanup: return rv; } +static int +remoteDispatchDomainListAllSnapshots(virNetServerPtr server ATTRIBUTE_UNUSED, + virNetServerClientPtr client, + virNetMessagePtr msg ATTRIBUTE_UNUSED, + virNetMessageErrorPtr rerr, + remote_domain_list_all_snapshots_args *args, + remote_domain_list_all_snapshots_ret *ret) +{ + virDomainSnapshotPtr *snaps = NULL; + int nsnaps = 0; + int i; + int rv = -1; + struct daemonClientPrivate *priv = virNetServerClientGetPrivateData(client); + virDomainPtr dom = NULL; + + if (!priv->conn) { + virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open")); + goto cleanup; + } + + if (!(dom = get_nonnull_domain(priv->conn, args->dom))) + goto cleanup; + + if ((nsnaps = virDomainListAllSnapshots(dom, + args->need_results ? &snaps : NULL, + args->flags)) < 0) + goto cleanup; + + if (snaps && nsnaps) { + if (VIR_ALLOC_N(ret->snapshots.snapshots_val, nsnaps) < 0) { + virReportOOMError(); + goto cleanup; + } + + ret->snapshots.snapshots_len = nsnaps; + + for (i = 0; i < nsnaps; i++) + make_nonnull_domain_snapshot(ret->snapshots.snapshots_val + i, + snaps[i]); + } else { + ret->snapshots.snapshots_len = 0; + ret->snapshots.snapshots_val = NULL; + } + + ret->ret = nsnaps; + rv = 0; + +cleanup: + if (rv < 0) + virNetMessageSaveError(rerr); + if (dom) + virDomainFree(dom); + if (snaps) { + for (i = 0; i < nsnaps; i++) + virDomainSnapshotFree(snaps[i]); + VIR_FREE(snaps); + } + return rv; +} + +static int +remoteDispatchDomainSnapshotListAllChildren(virNetServerPtr server ATTRIBUTE_UNUSED, + virNetServerClientPtr client, + virNetMessagePtr msg ATTRIBUTE_UNUSED, + virNetMessageErrorPtr rerr, + remote_domain_snapshot_list_all_children_args *args, + remote_domain_snapshot_list_all_children_ret *ret) +{ + virDomainSnapshotPtr *snaps = NULL; + int nsnaps = 0; + int i; + int rv = -1; + struct daemonClientPrivate *priv = virNetServerClientGetPrivateData(client); + virDomainPtr dom = NULL; + virDomainSnapshotPtr snapshot = NULL; + + if (!priv->conn) { + virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open")); + goto cleanup; + } + + if (!(dom = get_nonnull_domain(priv->conn, args->snapshot.dom))) + goto cleanup; + + if (!(snapshot = get_nonnull_domain_snapshot(dom, args->snapshot))) + goto cleanup; + + if ((nsnaps = virDomainSnapshotListAllChildren(snapshot, + args->need_results ? &snaps : NULL, + args->flags)) < 0) + goto cleanup; + + if (snaps && nsnaps) { + if (VIR_ALLOC_N(ret->snapshots.snapshots_val, nsnaps) < 0) { + virReportOOMError(); + goto cleanup; + } + + ret->snapshots.snapshots_len = nsnaps; + + for (i = 0; i < nsnaps; i++) + make_nonnull_domain_snapshot(ret->snapshots.snapshots_val + i, + snaps[i]); + } else { + ret->snapshots.snapshots_len = 0; + ret->snapshots.snapshots_val = NULL; + } + + ret->ret = nsnaps; + rv = 0; + +cleanup: + if (rv < 0) + virNetMessageSaveError(rerr); + if (snapshot) + virDomainSnapshotFree(snapshot); + if (dom) + virDomainFree(dom); + if (snaps) { + for (i = 0; i < nsnaps; i++) + virDomainSnapshotFree(snaps[i]); + VIR_FREE(snaps); + } + return rv; +} + /*----- Helpers. -----*/ /* get_nonnull_domain and get_nonnull_network turn an on-wire |