From e7c94d95feb1fb3d7249c2ead935fe2e56ec31a4 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] Implemented virStorageVolLookupByName & virStorageVolCreateXML. --- libvirt/generator.pl | 14 ++++---- libvirt/libvirt_c.c | 98 +++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 88 insertions(+), 24 deletions(-) diff --git a/libvirt/generator.pl b/libvirt/generator.pl index 0a73264..8b20adf 100755 --- a/libvirt/generator.pl +++ b/libvirt/generator.pl @@ -155,14 +155,14 @@ my @functions = ( { name => "virStorageVolFree", sig => "vol : free", weak => 1 }, { name => "virStorageVolDestroy", sig => "vol : free", weak => 1 }, -# { name => "virStorageVolLookupByName", XXX see libvir-list posting -# sig => "pool, string : vol", weak => 1 }, + { name => "virStorageVolLookupByName", + sig => "pool, string : vol from pool", weak => 1 }, { name => "virStorageVolLookupByKey", sig => "conn, string : vol", weak => 1 }, { name => "virStorageVolLookupByPath", sig => "conn, string : vol", weak => 1 }, -# { name => "virStorageVolCreateXML", -# sig => "pool, string : vol", weak => 1 }, XXX + { name => "virStorageVolCreateXML", + sig => "pool, string, 0 : vol from pool", weak => 1 }, { name => "virStorageVolGetXMLDesc", sig => "vol, 0 : string", weak => 1 }, { name => "virStorageVolGetPath", @@ -193,8 +193,6 @@ my @functions = ( # written in 'libvirt_c_oneoffs.c'. my @unimplemented = ( - "ocaml_libvirt_storage_vol_lookup_by_name", # XXX see above - "ocaml_libvirt_storage_vol_create_xml", # XXX see above ); #---------------------------------------------------------------------- @@ -957,9 +955,9 @@ END # Unimplemented functions. -printf "$0: warning: %d unimplemented functions\n", scalar (@unimplemented); - if (@unimplemented) { + printf "$0: warning: %d unimplemented functions\n", scalar (@unimplemented); + print F <<'END'; /* The following functions are unimplemented and always fail. * See generator.pl '@unimplemented' diff --git a/libvirt/libvirt_c.c b/libvirt/libvirt_c.c index e764311..0200b1c 100644 --- a/libvirt/libvirt_c.c +++ b/libvirt/libvirt_c.c @@ -2437,6 +2437,47 @@ ocaml_libvirt_storage_vol_destroy (value volv) #endif } +/* Automatically generated binding for virStorageVolLookupByName. + * In generator.pl this function has signature "pool, string : vol from pool". + */ + +#ifdef HAVE_WEAK_SYMBOLS +#ifdef HAVE_VIRSTORAGEVOLLOOKUPBYNAME +extern virStorageVolPtr virStorageVolLookupByName (virStoragePoolPtr pool, const char *str) __attribute__((weak)); +#endif +#endif + +CAMLprim value +ocaml_libvirt_storage_vol_lookup_by_name (value poolv, value strv) +{ + CAMLparam2 (poolv, strv); +#ifndef HAVE_VIRSTORAGEVOLLOOKUPBYNAME + /* Symbol virStorageVolLookupByName not found at compile time. */ + not_supported ("virStorageVolLookupByName"); + /* Suppresses a compiler warning. */ + (void) caml__frame; +#else + /* Check that the symbol virStorageVolLookupByName + * is in runtime version of libvirt. + */ + WEAK_SYMBOL_CHECK (virStorageVolLookupByName); + + CAMLlocal2 (rv, connv); + virStoragePoolPtr pool = Pool_val (poolv); + virConnectPtr conn = Connect_polv (poolv); + char *str = String_val (strv); + virStorageVolPtr r; + + NONBLOCKING (r = virStorageVolLookupByName (pool, str)); + CHECK_ERROR (!r, conn, "virStorageVolLookupByName"); + + connv = Field (poolv, 1); + rv = Val_volume (r, connv); + + CAMLreturn (rv); +#endif +} + /* Automatically generated binding for virStorageVolLookupByKey. * In generator.pl this function has signature "conn, string : vol". */ @@ -2515,6 +2556,47 @@ ocaml_libvirt_storage_vol_lookup_by_path (value connv, value strv) #endif } +/* Automatically generated binding for virStorageVolCreateXML. + * In generator.pl this function has signature "pool, string, 0 : vol from pool". + */ + +#ifdef HAVE_WEAK_SYMBOLS +#ifdef HAVE_VIRSTORAGEVOLCREATEXML +extern virStorageVolPtr virStorageVolCreateXML (virStoragePoolPtr pool, const char *str, int flags) __attribute__((weak)); +#endif +#endif + +CAMLprim value +ocaml_libvirt_storage_vol_create_xml (value poolv, value strv) +{ + CAMLparam2 (poolv, strv); +#ifndef HAVE_VIRSTORAGEVOLCREATEXML + /* Symbol virStorageVolCreateXML not found at compile time. */ + not_supported ("virStorageVolCreateXML"); + /* Suppresses a compiler warning. */ + (void) caml__frame; +#else + /* Check that the symbol virStorageVolCreateXML + * is in runtime version of libvirt. + */ + WEAK_SYMBOL_CHECK (virStorageVolCreateXML); + + CAMLlocal2 (rv, connv); + virStoragePoolPtr pool = Pool_val (poolv); + virConnectPtr conn = Connect_polv (poolv); + char *str = String_val (strv); + virStorageVolPtr r; + + NONBLOCKING (r = virStorageVolCreateXML (pool, str, 0)); + CHECK_ERROR (!r, conn, "virStorageVolCreateXML"); + + connv = Field (poolv, 1); + rv = Val_volume (r, connv); + + CAMLreturn (rv); +#endif +} + /* Automatically generated binding for virStorageVolGetXMLDesc. * In generator.pl this function has signature "vol, 0 : string". */ @@ -2864,22 +2946,6 @@ ocaml_libvirt_job_get_domain (value jobv) #endif } -/* The following functions are unimplemented and always fail. - * See generator.pl '@unimplemented' - */ - -CAMLprim value -ocaml_libvirt_storage_vol_lookup_by_name () -{ - failwith ("ocaml_libvirt_storage_vol_lookup_by_name is unimplemented"); -} - -CAMLprim value -ocaml_libvirt_storage_vol_create_xml () -{ - failwith ("ocaml_libvirt_storage_vol_create_xml is unimplemented"); -} - #include "libvirt_c_epilogue.c" /* EOF */ -- 1.8.3.1