ocaml-libvirt/0001-remove-parameter-nr_pcpus-of-Libvirt.Domain.get_cpu_.patch

117 lines
4.4 KiB
Diff
Raw Normal View History

From 252568550f9bf28b07f4e6d116485205e58afe4a Mon Sep 17 00:00:00 2001
From: Hu Tao <hutao@cn.fujitsu.com>
Date: Wed, 9 May 2012 16:48:30 +0800
Subject: [PATCH 1/2] remove parameter nr_pcpus of
Libvirt.Domain.get_cpu_stats
remove the value because we can get it from the libvirt API
---
examples/.depend | 4 ++--
examples/get_cpu_stats.ml | 2 +-
libvirt/.depend | 6 +++---
libvirt/libvirt.ml | 2 +-
libvirt/libvirt.mli | 4 ++--
libvirt/libvirt_c_oneoffs.c | 10 +++++++---
6 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/examples/.depend b/examples/.depend
index 831adf6..f58db3d 100644
--- a/examples/.depend
+++ b/examples/.depend
@@ -1,6 +1,6 @@
-node_info.cmo: ../libvirt/libvirt.cmi
-node_info.cmx: ../libvirt/libvirt.cmx
get_cpu_stats.cmo: ../libvirt/libvirt.cmi
get_cpu_stats.cmx: ../libvirt/libvirt.cmx
list_domains.cmo: ../libvirt/libvirt.cmi
list_domains.cmx: ../libvirt/libvirt.cmx
+node_info.cmo: ../libvirt/libvirt.cmi
+node_info.cmx: ../libvirt/libvirt.cmx
diff --git a/examples/get_cpu_stats.ml b/examples/get_cpu_stats.ml
index 79d5c3c..d7a8d0c 100644
--- a/examples/get_cpu_stats.ml
+++ b/examples/get_cpu_stats.ml
@@ -25,7 +25,7 @@ let () =
let stats =
let dom = D.lookup_by_name conn domname in
- D.get_cpu_stats dom nr_pcpus in
+ D.get_cpu_stats dom in
Array.iteri (
fun n params ->
diff --git a/libvirt/.depend b/libvirt/.depend
index 43a2367..3f2297e 100644
--- a/libvirt/.depend
+++ b/libvirt/.depend
@@ -1,6 +1,6 @@
-libvirt_version.cmi:
libvirt.cmi:
-libvirt_version.cmo: libvirt_version.cmi
-libvirt_version.cmx: libvirt_version.cmi
+libvirt_version.cmi:
libvirt.cmo: libvirt.cmi
libvirt.cmx: libvirt.cmi
+libvirt_version.cmo: libvirt_version.cmi
+libvirt_version.cmx: libvirt_version.cmi
diff --git a/libvirt/libvirt.ml b/libvirt/libvirt.ml
index 53c5bb4..07542a9 100644
--- a/libvirt/libvirt.ml
+++ b/libvirt/libvirt.ml
@@ -417,7 +417,7 @@ struct
external set_vcpus : [>`W] t -> int -> unit = "ocaml_libvirt_domain_set_vcpus"
external pin_vcpu : [>`W] t -> int -> string -> unit = "ocaml_libvirt_domain_pin_vcpu"
external get_vcpus : [>`R] t -> int -> int -> int * vcpu_info array * string = "ocaml_libvirt_domain_get_vcpus"
- external get_cpu_stats : [>`R] t -> int -> typed_param list array = "ocaml_libvirt_domain_get_cpu_stats"
+ external get_cpu_stats : [>`R] t -> typed_param list array = "ocaml_libvirt_domain_get_cpu_stats"
external get_max_vcpus : [>`R] t -> int = "ocaml_libvirt_domain_get_max_vcpus"
external attach_device : [>`W] t -> xml -> unit = "ocaml_libvirt_domain_attach_device"
external detach_device : [>`W] t -> xml -> unit = "ocaml_libvirt_domain_detach_device"
diff --git a/libvirt/libvirt.mli b/libvirt/libvirt.mli
index 0913a63..5a288c0 100644
--- a/libvirt/libvirt.mli
+++ b/libvirt/libvirt.mli
@@ -559,8 +559,8 @@ sig
for a domain. See the libvirt documentation for details
of the array and bitmap returned from this function.
*)
- val get_cpu_stats : [>`R] t -> int -> typed_param list array
- (** [get_pcpu_stats dom nr_pcpu] returns the physical CPU stats
+ val get_cpu_stats : [>`R] t -> typed_param list array
+ (** [get_pcpu_stats dom] returns the physical CPU stats
for a domain. See the libvirt documentation for details.
*)
val get_max_vcpus : [>`R] t -> int
diff --git a/libvirt/libvirt_c_oneoffs.c b/libvirt/libvirt_c_oneoffs.c
index 3d42b73..70cf96f 100644
--- a/libvirt/libvirt_c_oneoffs.c
+++ b/libvirt/libvirt_c_oneoffs.c
@@ -532,17 +532,21 @@ extern int virDomainGetCPUStats (virDomainPtr domain,
#endif
CAMLprim value
-ocaml_libvirt_domain_get_cpu_stats (value domv, value nr_pcpusv)
+ocaml_libvirt_domain_get_cpu_stats (value domv)
{
#ifdef HAVE_VIRDOMAINGETCPUSTATS
- CAMLparam2 (domv, nr_pcpusv);
+ CAMLparam1 (domv);
CAMLlocal5 (cpustats, param_head, param_node, typed_param, typed_param_value);
CAMLlocal1 (v);
virDomainPtr dom = Domain_val (domv);
virConnectPtr conn = Connect_domv (domv);
- int nr_pcpus = Int_val (nr_pcpusv);
virTypedParameterPtr params;
int r, cpu, ncpus, nparams, i, j, pos;
+ int nr_pcpus;
+
+ /* get number of pcpus */
+ NONBLOCKING (nr_pcpus = virDomainGetCPUStats(dom, NULL, 0, 0, 0, 0));
+ CHECK_ERROR (nr_pcpus < 0, conn, "virDomainGetCPUStats");
/* get percpu information */
NONBLOCKING (nparams = virDomainGetCPUStats(dom, NULL, 0, 0, 1, 0));
--
1.7.11.4