summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2007-11-14 12:08:49 +0000
committerRichard W.M. Jones <rjones@redhat.com>2007-11-14 12:08:49 +0000
commita09aae02dad075562f880fafaddd966f70342729 (patch)
tree2419d57165db80edd9d65f404d71360767bb17aa
parentbbbb071cc29af9bb70a7e5657c96ff4eb55662dd (diff)
downloadvirt-top-a09aae02dad075562f880fafaddd966f70342729.tar.gz
virt-top-a09aae02dad075562f880fafaddd966f70342729.tar.xz
virt-top-a09aae02dad075562f880fafaddd966f70342729.zip
Added support for new API calls:
- virNodeGetFreeMemory - virNodeGetCellsFreeMemory Release of 0.3.3.1.
-rw-r--r--config.h.in6
-rw-r--r--configure.ac2
-rw-r--r--libvirt/libvirt.ml2
-rw-r--r--libvirt/libvirt.mli16
-rw-r--r--libvirt/libvirt_c.c59
-rw-r--r--mlvirsh/mlvirsh.ml20
6 files changed, 104 insertions, 1 deletions
diff --git a/config.h.in b/config.h.in
index d8c604b..b28c478 100644
--- a/config.h.in
+++ b/config.h.in
@@ -57,6 +57,12 @@
/* 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
diff --git a/configure.ac b/configure.ac
index 4899523..d3d8973 100644
--- a/configure.ac
+++ b/configure.ac
@@ -52,7 +52,7 @@ AC_CHECK_FUNC(virConnectGetCapabilities,
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)
diff --git a/libvirt/libvirt.ml b/libvirt/libvirt.ml
index 2447f16..7b75eb8 100644
--- a/libvirt/libvirt.ml
+++ b/libvirt/libvirt.ml
@@ -63,6 +63,8 @@ struct
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;
diff --git a/libvirt/libvirt.mli b/libvirt/libvirt.mli
index ffe21fb..73bfcb5 100644
--- a/libvirt/libvirt.mli
+++ b/libvirt/libvirt.mli
@@ -105,6 +105,22 @@ sig
*)
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.
diff --git a/libvirt/libvirt_c.c b/libvirt/libvirt_c.c
index 0fdcbac..9e2182b 100644
--- a/libvirt/libvirt_c.c
+++ b/libvirt/libvirt_c.c
@@ -116,6 +116,16 @@ extern int virDomainSetSchedulerParameters (virDomainPtr domain,
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 */
/*----------------------------------------------------------------------*/
@@ -534,6 +544,55 @@ ocaml_libvirt_connect_get_node_info (value connv)
}
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);
diff --git a/mlvirsh/mlvirsh.ml b/mlvirsh/mlvirsh.ml
index ee8afe4..055f818 100644
--- a/mlvirsh/mlvirsh.ml
+++ b/mlvirsh/mlvirsh.ml
@@ -138,6 +138,12 @@ let do_command =
| [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
@@ -226,6 +232,7 @@ let do_command =
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
@@ -426,6 +433,19 @@ let do_command =
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),