[Pkg-libvirt-commits] [libguestfs] 47/65: v2v: domainxml: add vol_dumpxml

Hilko Bengen bengen at moszumanska.debian.org
Tue Apr 21 12:11:09 UTC 2015


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch experimental
in repository libguestfs.

commit 5da2ed95c11af6be6bee27f5b3dce8a6f3a29d74
Author: Pino Toscano <ptoscano at redhat.com>
Date:   Tue Apr 14 16:35:51 2015 +0200

    v2v: domainxml: add vol_dumpxml
    
    Add a new vol_dumpxml to get the XML dump of a pool's volume.
---
 v2v/domainxml-c.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 v2v/domainxml.ml  |  1 +
 v2v/domainxml.mli |  6 ++++++
 3 files changed, 68 insertions(+)

diff --git a/v2v/domainxml-c.c b/v2v/domainxml-c.c
index b5d2f81..fe9f6d2 100644
--- a/v2v/domainxml-c.c
+++ b/v2v/domainxml-c.c
@@ -305,6 +305,61 @@ v2v_pool_dumpxml (value connv, value poolnamev)
   CAMLreturn (retv);
 }
 
+value
+v2v_vol_dumpxml (value connv, value poolnamev, value volnamev)
+{
+  CAMLparam3 (connv, poolnamev, volnamev);
+  CAMLlocal1 (retv);
+  const char *volname;
+  /* We have to assemble the error on the stack because a dynamic
+   * string couldn't be freed.
+   */
+  char errmsg[256];
+  virErrorPtr err;
+  virConnectPtr conn;
+  virStoragePoolPtr pool;
+  virStorageVolPtr vol;
+  char *xml;
+
+  /* Look up the pool. */
+  pool = connect_and_load_pool (connv, poolnamev);
+  conn = virStoragePoolGetConnect (pool);
+
+  /* Look up the volume. */
+  volname = String_val (volnamev);
+
+  vol = virStorageVolLookupByName (pool, volname);
+
+  if (!vol) {
+    err = virGetLastError ();
+    snprintf (errmsg, sizeof errmsg,
+              _("cannot find libvirt volume '%s': %s"), volname, err->message);
+    virStoragePoolFree (pool);
+    virConnectClose (conn);
+    caml_invalid_argument (errmsg);
+  }
+
+  xml = virStorageVolGetXMLDesc (vol, 0);
+  if (xml == NULL) {
+    err = virGetLastError ();
+    snprintf (errmsg, sizeof errmsg,
+              _("cannot fetch XML description of volume '%s': %s"),
+              volname, err->message);
+    virStorageVolFree (vol);
+    virStoragePoolFree (pool);
+    virConnectClose (conn);
+    caml_invalid_argument (errmsg);
+  }
+  virStorageVolFree (vol);
+  virStoragePoolFree (pool);
+  virConnectClose (conn);
+
+  retv = caml_copy_string (xml);
+  free (xml);
+
+  CAMLreturn (retv);
+}
+
 #else /* !HAVE_LIBVIRT */
 
 value
@@ -319,4 +374,10 @@ v2v_pool_dumpxml (value connv, value poolv)
   caml_invalid_argument ("virt-v2v was compiled without libvirt support");
 }
 
+value
+v2v_vol_dumpxml (value connv, value poolnamev, value volnamev)
+{
+  caml_invalid_argument ("virt-v2v was compiled without libvirt support");
+}
+
 #endif /* !HAVE_LIBVIRT */
diff --git a/v2v/domainxml.ml b/v2v/domainxml.ml
index 8782ea1..7dbfcbd 100644
--- a/v2v/domainxml.ml
+++ b/v2v/domainxml.ml
@@ -20,3 +20,4 @@
 
 external dumpxml : ?password:string -> ?conn:string -> string -> string = "v2v_dumpxml"
 external pool_dumpxml : ?conn:string -> string -> string = "v2v_pool_dumpxml"
+external vol_dumpxml : ?conn:string -> string -> string -> string = "v2v_vol_dumpxml"
diff --git a/v2v/domainxml.mli b/v2v/domainxml.mli
index 47a91cf..7008769 100644
--- a/v2v/domainxml.mli
+++ b/v2v/domainxml.mli
@@ -32,3 +32,9 @@ val pool_dumpxml : ?conn:string -> string -> string
 (** [pool_dumpxml ?conn pool] returns the libvirt XML of pool [pool].
     The optional [?conn] parameter is the libvirt connection URI.
     [pool] may be a pool name or UUID. *)
+
+val vol_dumpxml : ?conn:string -> string -> string -> string
+(** [vol_dumpxml ?conn pool vol] returns the libvirt XML of volume [vol],
+    which is part of the pool [pool].
+    The optional [?conn] parameter is the libvirt connection URI.
+    [pool] may be a pool name or UUID. *)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list