/* Define to 1 if you have the `virDomainSetSchedulerParameters' function. */
#undef HAVE_VIRDOMAINSETSCHEDULERPARAMETERS
+/* Define to 1 if you have the `virNodeGetCellsFreeMemory' function. */
+#undef HAVE_VIRNODEGETCELLSFREEMEMORY
+
+/* Define to 1 if you have the `virNodeGetFreeMemory' function. */
+#undef HAVE_VIRNODEGETFREEMEMORY
+
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
#undef NO_MINUS_C_MINUS_O
dnl Check for optional libvirt functions added since 0.2.1.
dnl See: http://libvirt.org/hvsupport.html
-AC_CHECK_FUNCS([virConnectGetHostname virConnectGetURI virDomainBlockStats virDomainGetSchedulerParameters virDomainGetSchedulerType virDomainInterfaceStats virDomainMigrate virDomainSetSchedulerParameters])
+AC_CHECK_FUNCS([virConnectGetHostname virConnectGetURI virDomainBlockStats virDomainGetSchedulerParameters virDomainGetSchedulerType virDomainInterfaceStats virDomainMigrate virDomainSetSchedulerParameters virNodeGetFreeMemory virNodeGetCellsFreeMemory])
dnl Check for optional ncurses.
AC_CHECK_LIB(ncurses,initscr)
external num_of_defined_networks : [>`R] t -> int = "ocaml_libvirt_connect_num_of_defined_networks"
external list_defined_networks : [>`R] t -> int -> string array = "ocaml_libvirt_connect_list_defined_networks"
external get_node_info : [>`R] t -> node_info = "ocaml_libvirt_connect_get_node_info"
+ external node_get_free_memory : [> `R] t -> int64 = "ocaml_libvirt_connect_node_get_free_memory"
+ external node_get_cells_free_memory : [> `R] t -> int -> int -> int64 array = "ocaml_libvirt_connect_node_get_cells_free_memory"
(* See VIR_NODEINFO_MAXCPUS macro defined in <libvirt.h>. *)
let maxcpus_of_node_info { nodes = nodes; sockets = sockets;
*)
val get_node_info : [>`R] t -> node_info
+ val node_get_free_memory : [> `R] t -> int64
+ (**
+ [node_get_free_memory conn]
+ returns the amount of free memory (not allocated to any guest)
+ in the machine.
+ *)
+
+ val node_get_cells_free_memory : [> `R] t -> int -> int -> int64 array
+ (**
+ [node_get_cells_free_memory conn start max]
+ returns the amount of free memory on each NUMA cell in kilobytes.
+ [start] is the first cell for which we return free memory.
+ [max] is the maximum number of cells for which we return free memory.
+ Returns an array of up to [max] entries in length.
+ *)
+
val maxcpus_of_node_info : node_info -> int
(** Calculate the total number of CPUs supported (but not necessarily
active) in the host.
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
+ocaml_libvirt_connect_node_get_free_memory (value connv)
+{
+#ifdef HAVE_VIRNODEGETFREEMEMORY
+ CAMLparam1 (connv);
+ CAMLlocal1 (rv);
+ virConnectPtr conn = Connect_val (connv);
+ unsigned long long r;
+
+ WEAK_SYMBOL_CHECK (virNodeGetFreeMemory);
+ r = virNodeGetFreeMemory (conn);
+ CHECK_ERROR (r == 0, conn, "virNodeGetFreeMemory");
+
+ rv = caml_copy_int64 ((int64) r);
+ CAMLreturn (rv);
+#else
+ NOT_SUPPORTED ("virNodeGetFreeMemory");
+#endif
+}
+
+CAMLprim value
+ocaml_libvirt_connect_node_get_cells_free_memory (value connv,
+ value startv, value maxv)
+{
+#ifdef HAVE_VIRNODEGETCELLSFREEMEMORY
+ CAMLparam3 (connv, startv, maxv);
+ CAMLlocal2 (rv, iv);
+ virConnectPtr conn = Connect_val (connv);
+ int start = Int_val (startv);
+ int max = Int_val (maxv);
+ int r, i;
+ unsigned long long freemems[max];
+
+ WEAK_SYMBOL_CHECK (virNodeGetCellsFreeMemory);
+ r = virNodeGetCellsFreeMemory (conn, freemems, start, max);
+ CHECK_ERROR (r == -1, conn, "virNodeGetCellsFreeMemory");
+
+ rv = caml_alloc (r, 0);
+ for (i = 0; i < r; ++i) {
+ iv = caml_copy_int64 ((int64) freemems[i]);
+ Store_field (rv, i, iv);
+ }
+
+ CAMLreturn (rv);
+#else
+ NOT_SUPPORTED ("virNodeGetCellsFreeMemory");
+#endif
+}
+
+CAMLprim value
ocaml_libvirt_domain_create_linux (value connv, value xmlv)
{
CAMLparam2 (connv, xmlv);
| [str1; str2] -> print (fn (arg1 str1) (Some (arg2 str2)))
| _ -> failwith "incorrect number of arguments for function"
in
+ let cmd012 print fn arg1 arg2 = function (* Command with 0, 1 or 2 args. *)
+ | [] -> print (fn None None)
+ | [str1] -> print (fn (Some (arg1 str1)) None)
+ | [str1; str2] -> print (fn (Some (arg1 str1)) (Some (arg2 str2)))
+ | _ -> failwith "incorrect number of arguments for function"
+ in
let cmdN print fn = (* Command with any number of args. *)
fun args -> print (fn args)
in
let no_return _ = () in
let print_int i = print_endline (string_of_int i) in
let print_int64 i = print_endline (Int64.to_string i) in
+ let print_int64_array a = Array.iter print_int64 a in
let print_bool b = print_endline (string_of_bool b) in
let print_version v =
let major = v / 1000000 in
cmd1 print_endline D.get_xml_desc
(arg_full_connection domain_of_string),
"Print the XML description of a domain.";
+ "freecell",
+ cmd012 print_int64_array (
+ fun start max ->
+ let conn = get_readonly_connection () in
+ match start, max with
+ | None, _ ->
+ [| C.node_get_free_memory conn |]
+ | Some start, None ->
+ C.node_get_cells_free_memory conn start 1
+ | Some start, Some max ->
+ C.node_get_cells_free_memory conn start max
+ ) int_of_string int_of_string,
+ "Display free memory for machine, NUMA cell or range of cells";
"get-autostart",
cmd1 print_bool D.get_autostart
(arg_readonly_connection domain_of_string),