[libvirt] Minor fixes to ocaml bindings for storage pools/volumes

These patches fix a couple of minor issues I encountered while trying to manipulate storage pools and volumes from an OCaml program. If you're interested, the OCaml client code is a simple adapter to allow an XCP host to use libvirt (for storage only atm, more later). The client code (so far) is here: https://github.com/djs55/xcp-libvirt-storage/blob/master/server.ml Cheers, Dave Scott http://dave.recoil.org/

A connection is either read/write (type rw = [`R|`W]) or read/only (type ro = [`R]). A function which requires the ability to write needs to take a parameter [> `W] rather than [`W] (which would correspond to a write-only connection). We can now use a read/write connection to call: Pool.set_autostart Volume.create_xml Volume.delete Signed-off-by: David Scott <dave.scott@eu.citrix.com> --- libvirt/libvirt.ml | 6 +++--- libvirt/libvirt.mli | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libvirt/libvirt.ml b/libvirt/libvirt.ml index 07542a9..443b22b 100644 --- a/libvirt/libvirt.ml +++ b/libvirt/libvirt.ml @@ -536,7 +536,7 @@ struct external get_info : [`R] t -> pool_info = "ocaml_libvirt_storage_pool_get_info" external get_xml_desc : [`R] t -> xml = "ocaml_libvirt_storage_pool_get_xml_desc" external get_autostart : [`R] t -> bool = "ocaml_libvirt_storage_pool_get_autostart" - external set_autostart : [`W] t -> bool -> unit = "ocaml_libvirt_storage_pool_set_autostart" + external set_autostart : [>`W] t -> bool -> unit = "ocaml_libvirt_storage_pool_set_autostart" external num_of_volumes : [`R] t -> int = "ocaml_libvirt_storage_pool_num_of_volumes" external list_volumes : [`R] t -> int -> string array = "ocaml_libvirt_storage_pool_list_volumes" external const : [>`R] t -> ro t = "%identity" @@ -562,8 +562,8 @@ struct external get_path : [`R] t -> string = "ocaml_libvirt_storage_vol_get_path" external get_info : [`R] t -> vol_info = "ocaml_libvirt_storage_vol_get_info" external get_xml_desc : [`R] t -> xml = "ocaml_libvirt_storage_vol_get_xml_desc" - external create_xml : [`W] Pool.t -> xml -> unit = "ocaml_libvirt_storage_vol_create_xml" - external delete : [`W] t -> unit = "ocaml_libvirt_storage_vol_delete" + external create_xml : [>`W] Pool.t -> xml -> unit = "ocaml_libvirt_storage_vol_create_xml" + external delete : [>`W] t -> unit = "ocaml_libvirt_storage_vol_delete" external free : [>`R] t -> unit = "ocaml_libvirt_storage_vol_free" external const : [>`R] t -> ro t = "%identity" end diff --git a/libvirt/libvirt.mli b/libvirt/libvirt.mli index 5a288c0..70cc2c7 100644 --- a/libvirt/libvirt.mli +++ b/libvirt/libvirt.mli @@ -757,7 +757,7 @@ sig (** Get the XML description. *) val get_autostart : [`R] t -> bool (** Get the autostart flag for the storage pool. *) - val set_autostart : [`W] t -> bool -> unit + val set_autostart : [>`W] t -> bool -> unit (** Set the autostart flag for the storage pool. *) val num_of_volumes : [`R] t -> int @@ -810,9 +810,9 @@ sig val get_xml_desc : [`R] t -> xml (** Get the XML description. *) - val create_xml : [`W] Pool.t -> xml -> unit + val create_xml : [>`W] Pool.t -> xml -> unit (** Create a storage volume. *) - val delete : [`W] t -> unit + val delete : [>`W] t -> unit (** Delete a storage volume. *) val free : [>`R] t -> unit (** Free a storage volume object in memory. -- 1.7.10.4

This corrects a mismatch between the generated C stubs and the .ml interface. Signed-off-by: David Scott <dave.scott@eu.citrix.com> --- libvirt/libvirt.ml | 2 +- libvirt/libvirt.mli | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libvirt/libvirt.ml b/libvirt/libvirt.ml index 443b22b..1fbb8ca 100644 --- a/libvirt/libvirt.ml +++ b/libvirt/libvirt.ml @@ -563,7 +563,7 @@ struct external get_info : [`R] t -> vol_info = "ocaml_libvirt_storage_vol_get_info" external get_xml_desc : [`R] t -> xml = "ocaml_libvirt_storage_vol_get_xml_desc" external create_xml : [>`W] Pool.t -> xml -> unit = "ocaml_libvirt_storage_vol_create_xml" - external delete : [>`W] t -> unit = "ocaml_libvirt_storage_vol_delete" + external delete : [>`W] t -> vol_delete_flags -> unit = "ocaml_libvirt_storage_vol_delete" external free : [>`R] t -> unit = "ocaml_libvirt_storage_vol_free" external const : [>`R] t -> ro t = "%identity" end diff --git a/libvirt/libvirt.mli b/libvirt/libvirt.mli index 70cc2c7..bf95fa2 100644 --- a/libvirt/libvirt.mli +++ b/libvirt/libvirt.mli @@ -812,7 +812,7 @@ sig val create_xml : [>`W] Pool.t -> xml -> unit (** Create a storage volume. *) - val delete : [>`W] t -> unit + val delete : [>`W] t -> vol_delete_flags -> unit (** Delete a storage volume. *) val free : [>`R] t -> unit (** Free a storage volume object in memory. -- 1.7.10.4

This affects the following functions: virStoragePoolBuild virStoragePoolDelete virStorageVolDelete Previously a call to virStorageVolDelete would succeed returning 0, which was interpreted as false, causing us to raise an exception with VIR_ERR_NONE. Signed-off-by: David Scott <dave.scott@eu.citrix.com> --- libvirt/generator.pl | 2 +- libvirt/libvirt_c.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libvirt/generator.pl b/libvirt/generator.pl index 8590ea7..abebfff 100755 --- a/libvirt/generator.pl +++ b/libvirt/generator.pl @@ -749,7 +749,7 @@ sub gen_c_code int r; NONBLOCKING (r = $c_name ($1, i)); - CHECK_ERROR (!r, conn, \"$c_name\"); + CHECK_ERROR (r == -1, conn, \"$c_name\"); CAMLreturn (Val_unit); " diff --git a/libvirt/libvirt_c.c b/libvirt/libvirt_c.c index b1f084b..d07a55e 100644 --- a/libvirt/libvirt_c.c +++ b/libvirt/libvirt_c.c @@ -1932,7 +1932,7 @@ ocaml_libvirt_storage_pool_build (value poolv, value iv) int r; NONBLOCKING (r = virStoragePoolBuild (pool, i)); - CHECK_ERROR (!r, conn, "virStoragePoolBuild"); + CHECK_ERROR (r == -1, conn, "virStoragePoolBuild"); CAMLreturn (Val_unit); #endif @@ -2038,7 +2038,7 @@ ocaml_libvirt_storage_pool_delete (value poolv, value iv) int r; NONBLOCKING (r = virStoragePoolDelete (pool, i)); - CHECK_ERROR (!r, conn, "virStoragePoolDelete"); + CHECK_ERROR (r == -1, conn, "virStoragePoolDelete"); CAMLreturn (Val_unit); #endif @@ -2309,7 +2309,7 @@ ocaml_libvirt_storage_vol_delete (value volv, value iv) int r; NONBLOCKING (r = virStorageVolDelete (vol, i)); - CHECK_ERROR (!r, conn, "virStorageVolDelete"); + CHECK_ERROR (r == -1, conn, "virStorageVolDelete"); CAMLreturn (Val_unit); #endif -- 1.7.10.4

On Wed, Mar 06, 2013 at 04:18:02PM +0000, David Scott wrote:
These patches fix a couple of minor issues I encountered while trying to manipulate storage pools and volumes from an OCaml program.
If you're interested, the OCaml client code is a simple adapter to allow an XCP host to use libvirt (for storage only atm, more later). The client code (so far) is here:
https://github.com/djs55/xcp-libvirt-storage/blob/master/server.ml
Thanks -- I just pushed all 3 patches. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW

On Wed, Mar 6, 2013 at 5:01 PM, Richard W.M. Jones <rjones@redhat.com>wrote:
On Wed, Mar 06, 2013 at 04:18:02PM +0000, David Scott wrote:
These patches fix a couple of minor issues I encountered while trying to manipulate storage pools and volumes from an OCaml program.
If you're interested, the OCaml client code is a simple adapter to allow an XCP host to use libvirt (for storage only atm, more later). The client code (so far) is here:
https://github.com/djs55/xcp-libvirt-storage/blob/master/server.ml
Thanks -- I just pushed all 3 patches.
Great :-) Generally I find the OCaml bindings very nice to use. IMHO they're a great way to explore the libvirt API, especially combined with a nice OCaml toplevel like "utop"-- so thanks for creating them! -- Dave Scott http://dave.recoil.org/
participants (2)
-
David Scott
-
Richard W.M. Jones