Complete implementation of storage API.
authorRichard W.M. Jones <rjones@redhat.com>
Sat, 19 Jan 2008 17:26:09 +0000 (17:26 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Sat, 19 Jan 2008 17:26:09 +0000 (17:26 +0000)
libvirt/generator.pl
libvirt/libvirt.ml
libvirt/libvirt.mli
libvirt/libvirt_c.c
libvirt/libvirt_c_oneoffs.c

index 7beac84..63de30e 100755 (executable)
@@ -193,11 +193,8 @@ my @functions = (
 # written in 'libvirt_c_oneoffs.c'.
 
 my @unimplemented = (
 # 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_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",
     );
 
 #----------------------------------------------------------------------
     );
 
 #----------------------------------------------------------------------
index 0405d74..d01db2f 100644 (file)
@@ -230,6 +230,7 @@ struct
   type 'rw t
   type pool_state = Inactive | Active
   type pool_info = {
   type 'rw t
   type pool_state = Inactive | Active
   type pool_info = {
+    state : pool_state;
     capacity : int64;
     allocation : int64;
   }
     capacity : int64;
     allocation : int64;
   }
index e80cf91..72917ef 100644 (file)
@@ -645,6 +645,7 @@ sig
     (** State of the storage pool. *)
 
   type pool_info = {
     (** 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. *)
   }
     capacity : int64;                  (** Logical size in bytes. *)
     allocation : int64;                        (** Currently allocated in bytes. *)
   }
index 347cab7..d60052f 100644 (file)
@@ -2475,12 +2475,6 @@ ocaml_libvirt_job_get_domain (value jobv)
  */
 
 CAMLprim value
  */
 
 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");
 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");
 }
 
   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 */
 #include "libvirt_c_epilogue.c"
 
 /* EOF */
index b1331e0..a3a7e34 100644 (file)
 
 /* Please read libvirt/README file. */
 
 
 /* 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
 /*----------------------------------------------------------------------*/
 
 CAMLprim value
@@ -179,6 +129,13 @@ ocaml_libvirt_connect_get_node_info (value connv)
   CAMLreturn (rv);
 }
 
   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)
 {
 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
 }
 
 #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)
 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);
 }
 
   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)
 {
 CAMLprim value
 ocaml_libvirt_domain_get_scheduler_type (value domv)
 {
@@ -340,6 +314,15 @@ ocaml_libvirt_domain_get_scheduler_type (value domv)
 #endif
 }
 
 #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)
 {
 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
 }
 
 #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)
 {
 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);
 }
 
   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)
 {
 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]);
 }
 
                                              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)
 {
 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
 }
 
 #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)
 {
 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
 }
 
 #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
 /*----------------------------------------------------------------------*/
 
 CAMLprim value