From cf1b8052e9bca746a90dc4380bf4d6b09399adf2 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] Complete implementation of storage API. --- libvirt/generator.pl | 3 - libvirt/libvirt.ml | 1 + libvirt/libvirt.mli | 1 + libvirt/libvirt_c.c | 18 ---- libvirt/libvirt_c_oneoffs.c | 222 ++++++++++++++++++++++++++++++++++---------- 5 files changed, 174 insertions(+), 71 deletions(-) diff --git a/libvirt/generator.pl b/libvirt/generator.pl index 7beac84..63de30e 100755 --- a/libvirt/generator.pl +++ b/libvirt/generator.pl @@ -193,11 +193,8 @@ my @functions = ( # written in 'libvirt_c_oneoffs.c'. my @unimplemented = ( - "ocaml_libvirt_storage_pool_get_info", "ocaml_libvirt_storage_vol_lookup_by_name", # XXX see above "ocaml_libvirt_storage_vol_create_xml", # XXX see above - "ocaml_libvirt_storage_vol_get_info", - "ocaml_libvirt_job_get_info", ); #---------------------------------------------------------------------- diff --git a/libvirt/libvirt.ml b/libvirt/libvirt.ml index 0405d74..d01db2f 100644 --- a/libvirt/libvirt.ml +++ b/libvirt/libvirt.ml @@ -230,6 +230,7 @@ struct type 'rw t type pool_state = Inactive | Active type pool_info = { + state : pool_state; capacity : int64; allocation : int64; } diff --git a/libvirt/libvirt.mli b/libvirt/libvirt.mli index e80cf91..72917ef 100644 --- a/libvirt/libvirt.mli +++ b/libvirt/libvirt.mli @@ -645,6 +645,7 @@ sig (** State of the storage pool. *) type pool_info = { + state : pool_state; (** Inactive | Active *) capacity : int64; (** Logical size in bytes. *) allocation : int64; (** Currently allocated in bytes. *) } diff --git a/libvirt/libvirt_c.c b/libvirt/libvirt_c.c index 347cab7..d60052f 100644 --- a/libvirt/libvirt_c.c +++ b/libvirt/libvirt_c.c @@ -2475,12 +2475,6 @@ ocaml_libvirt_job_get_domain (value jobv) */ CAMLprim value -ocaml_libvirt_storage_pool_get_info () -{ - failwith ("ocaml_libvirt_storage_pool_get_info is unimplemented"); -} - -CAMLprim value ocaml_libvirt_storage_vol_lookup_by_name () { failwith ("ocaml_libvirt_storage_vol_lookup_by_name is unimplemented"); @@ -2492,18 +2486,6 @@ ocaml_libvirt_storage_vol_create_xml () failwith ("ocaml_libvirt_storage_vol_create_xml is unimplemented"); } -CAMLprim value -ocaml_libvirt_storage_vol_get_info () -{ - failwith ("ocaml_libvirt_storage_vol_get_info is unimplemented"); -} - -CAMLprim value -ocaml_libvirt_job_get_info () -{ - failwith ("ocaml_libvirt_job_get_info is unimplemented"); -} - #include "libvirt_c_epilogue.c" /* EOF */ diff --git a/libvirt/libvirt_c_oneoffs.c b/libvirt/libvirt_c_oneoffs.c index b1331e0..a3a7e34 100644 --- a/libvirt/libvirt_c_oneoffs.c +++ b/libvirt/libvirt_c_oneoffs.c @@ -19,56 +19,6 @@ /* Please read libvirt/README file. */ -#ifdef HAVE_WEAK_SYMBOLS -#ifdef HAVE_VIRDOMAINBLOCKSTATS -extern int virDomainBlockStats (virDomainPtr dom, - const char *path, - virDomainBlockStatsPtr stats, - size_t size) - __attribute__((weak)); -#endif -#ifdef HAVE_VIRDOMAINGETSCHEDULERPARAMETERS -extern int virDomainGetSchedulerParameters (virDomainPtr domain, - virSchedParameterPtr params, - int *nparams) - __attribute__((weak)); -#endif -#ifdef HAVE_VIRDOMAINGETSCHEDULERTYPE -extern char *virDomainGetSchedulerType(virDomainPtr domain, - int *nparams) - __attribute__((weak)); -#endif -#ifdef HAVE_VIRDOMAININTERFACESTATS -extern int virDomainInterfaceStats (virDomainPtr dom, - const char *path, - virDomainInterfaceStatsPtr stats, - size_t size) - __attribute__((weak)); -#endif -#ifdef HAVE_VIRDOMAINMIGRATE -extern virDomainPtr virDomainMigrate (virDomainPtr domain, virConnectPtr dconn, - unsigned long flags, const char *dname, - const char *uri, unsigned long bandwidth) - __attribute__((weak)); -#endif -#ifdef HAVE_VIRDOMAINSETSCHEDULERPARAMETERS -extern int virDomainSetSchedulerParameters (virDomainPtr domain, - virSchedParameterPtr params, - int nparams) - __attribute__((weak)); -#endif -#ifdef HAVE_VIRNODEGETFREEMEMORY -extern unsigned long long virNodeGetFreeMemory (virConnectPtr conn) - __attribute__((weak)); -#endif -#ifdef HAVE_VIRNODEGETCELLSFREEMEMORY -extern int virNodeGetCellsFreeMemory (virConnectPtr conn, - unsigned long long *freeMems, - int startCell, int maxCells) - __attribute__((weak)); -#endif -#endif /* HAVE_WEAK_SYMBOLS */ - /*----------------------------------------------------------------------*/ CAMLprim value @@ -179,6 +129,13 @@ ocaml_libvirt_connect_get_node_info (value connv) CAMLreturn (rv); } +#ifdef HAVE_WEAK_SYMBOLS +#ifdef HAVE_VIRNODEGETFREEMEMORY +extern unsigned long long virNodeGetFreeMemory (virConnectPtr conn) + __attribute__((weak)); +#endif +#endif + CAMLprim value ocaml_libvirt_connect_node_get_free_memory (value connv) { @@ -199,6 +156,15 @@ ocaml_libvirt_connect_node_get_free_memory (value connv) #endif } +#ifdef HAVE_WEAK_SYMBOLS +#ifdef HAVE_VIRNODEGETCELLSFREEMEMORY +extern int virNodeGetCellsFreeMemory (virConnectPtr conn, + unsigned long long *freeMems, + int startCell, int maxCells) + __attribute__((weak)); +#endif +#endif + CAMLprim value ocaml_libvirt_connect_node_get_cells_free_memory (value connv, value startv, value maxv) @@ -315,6 +281,14 @@ ocaml_libvirt_domain_get_info (value domv) CAMLreturn (rv); } +#ifdef HAVE_WEAK_SYMBOLS +#ifdef HAVE_VIRDOMAINGETSCHEDULERTYPE +extern char *virDomainGetSchedulerType(virDomainPtr domain, + int *nparams) + __attribute__((weak)); +#endif +#endif + CAMLprim value ocaml_libvirt_domain_get_scheduler_type (value domv) { @@ -340,6 +314,15 @@ ocaml_libvirt_domain_get_scheduler_type (value domv) #endif } +#ifdef HAVE_WEAK_SYMBOLS +#ifdef HAVE_VIRDOMAINGETSCHEDULERPARAMETERS +extern int virDomainGetSchedulerParameters (virDomainPtr domain, + virSchedParameterPtr params, + int *nparams) + __attribute__((weak)); +#endif +#endif + CAMLprim value ocaml_libvirt_domain_get_scheduler_parameters (value domv, value nparamsv) { @@ -396,6 +379,15 @@ ocaml_libvirt_domain_get_scheduler_parameters (value domv, value nparamsv) #endif } +#ifdef HAVE_WEAK_SYMBOLS +#ifdef HAVE_VIRDOMAINSETSCHEDULERPARAMETERS +extern int virDomainSetSchedulerParameters (virDomainPtr domain, + virSchedParameterPtr params, + int nparams) + __attribute__((weak)); +#endif +#endif + CAMLprim value ocaml_libvirt_domain_set_scheduler_parameters (value domv, value paramsv) { @@ -528,6 +520,15 @@ ocaml_libvirt_domain_get_vcpus (value domv, value maxinfov, value maplenv) CAMLreturn (rv); } +#ifdef HAVE_WEAK_SYMBOLS +#ifdef HAVE_VIRDOMAINMIGRATE +extern virDomainPtr virDomainMigrate (virDomainPtr domain, virConnectPtr dconn, + unsigned long flags, const char *dname, + const char *uri, unsigned long bandwidth) + __attribute__((weak)); +#endif +#endif + CAMLprim value ocaml_libvirt_domain_migrate_native (value domv, value dconnv, value flagsv, value optdnamev, value opturiv, value optbandwidthv, value unitv) { @@ -578,6 +579,16 @@ ocaml_libvirt_domain_migrate_bytecode (value *argv, int argn) argv[6]); } +#ifdef HAVE_WEAK_SYMBOLS +#ifdef HAVE_VIRDOMAINBLOCKSTATS +extern int virDomainBlockStats (virDomainPtr dom, + const char *path, + virDomainBlockStatsPtr stats, + size_t size) + __attribute__((weak)); +#endif +#endif + CAMLprim value ocaml_libvirt_domain_block_stats (value domv, value pathv) { @@ -607,6 +618,16 @@ ocaml_libvirt_domain_block_stats (value domv, value pathv) #endif } +#ifdef HAVE_WEAK_SYMBOLS +#ifdef HAVE_VIRDOMAININTERFACESTATS +extern int virDomainInterfaceStats (virDomainPtr dom, + const char *path, + virDomainInterfaceStatsPtr stats, + size_t size) + __attribute__((weak)); +#endif +#endif + CAMLprim value ocaml_libvirt_domain_interface_stats (value domv, value pathv) { @@ -639,6 +660,107 @@ ocaml_libvirt_domain_interface_stats (value domv, value pathv) #endif } +#ifdef HAVE_WEAK_SYMBOLS +#ifdef HAVE_VIRSTORAGEPOOLGETINFO +extern int virStoragePoolGetInfo(virStoragePoolPtr pool, virStoragePoolInfoPtr info) + __attribute__((weak)); +#endif +#endif + +CAMLprim value +ocaml_libvirt_storage_pool_get_info (value poolv) +{ +#if HAVE_VIRSTORAGEPOOLGETINFO + CAMLparam1 (poolv); + CAMLlocal2 (rv, v); + virStoragePoolPtr pool = Pool_val (poolv); + virConnectPtr conn = Connect_polv (poolv); + virStoragePoolInfo info; + int r; + + WEAK_SYMBOL_CHECK (virStoragePoolGetInfo); + NONBLOCKING (r = virStoragePoolGetInfo (pool, &info)); + CHECK_ERROR (r == -1, conn, "virStoragePoolGetInfo"); + + rv = caml_alloc (3, 0); + Store_field (rv, 0, Val_int (info.state)); + v = caml_copy_int64 (info.capacity); Store_field (rv, 1, v); + v = caml_copy_int64 (info.allocation); Store_field (rv, 1, v); + + CAMLreturn (rv); +#else + not_supported ("virStoragePoolGetInfo"); +#endif +} + +#ifdef HAVE_WEAK_SYMBOLS +#ifdef HAVE_VIRSTORAGEVOLGETINFO +extern int virStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info) + __attribute__((weak)); +#endif +#endif + +CAMLprim value +ocaml_libvirt_storage_vol_get_info (value volv) +{ +#if HAVE_VIRSTORAGEVOLGETINFO + CAMLparam1 (volv); + CAMLlocal2 (rv, v); + virStorageVolPtr vol = Volume_val (volv); + virConnectPtr conn = Connect_volv (volv); + virStorageVolInfo info; + int r; + + WEAK_SYMBOL_CHECK (virStorageVolGetInfo); + NONBLOCKING (r = virStorageVolGetInfo (vol, &info)); + CHECK_ERROR (r == -1, conn, "virStorageVolGetInfo"); + + rv = caml_alloc (3, 0); + Store_field (rv, 0, Val_int (info.type)); + v = caml_copy_int64 (info.capacity); Store_field (rv, 1, v); + v = caml_copy_int64 (info.allocation); Store_field (rv, 1, v); + + CAMLreturn (rv); +#else + not_supported ("virStorageVolGetInfo"); +#endif +} + +#ifdef HAVE_WEAK_SYMBOLS +#ifdef HAVE_VIRJOBGETINFO +extern int virJobGetInfo(virJobPtr job, virJobInfoPtr info) + __attribute__((weak)); +#endif +#endif + +CAMLprim value +ocaml_libvirt_job_get_info (value jobv) +{ +#if HAVE_VIRJOBGETINFO + CAMLparam1 (jobv); + CAMLlocal1 (rv); + virJobPtr job = Job_val (jobv); + virConnectPtr conn = Connect_jobv (jobv); + virJobInfo info; + int r; + + WEAK_SYMBOL_CHECK (virJobGetInfo); + NONBLOCKING (r = virJobGetInfo (job, &info)); + CHECK_ERROR (r == -1, conn, "virJobGetInfo"); + + rv = caml_alloc (5, 0); + Store_field (rv, 0, Val_int (info.type)); + Store_field (rv, 1, Val_int (info.state)); + Store_field (rv, 2, Val_int (info.runningTime)); + Store_field (rv, 3, Val_int (info.remainingTime)); + Store_field (rv, 4, Val_int (info.percentComplete)); + + CAMLreturn (rv); +#else + not_supported ("virJobGetInfo"); +#endif +} + /*----------------------------------------------------------------------*/ CAMLprim value -- 1.8.3.1