Blame SOURCES/0005-Change-binding-of-virConnectGetAllDomainStats-to-ret.patch

4e3392
From 3169af3337938e18bf9ecc6ce936d644e14ff3de Mon Sep 17 00:00:00 2001
4e3392
From: "Richard W.M. Jones" <rjones@redhat.com>
4e3392
Date: Tue, 28 Mar 2017 13:52:51 +0100
4e3392
Subject: [PATCH 5/5] Change binding of virConnectGetAllDomainStats to return
4e3392
 dom UUID.
4e3392
4e3392
The virDomainPtr object returned by this binding isn't a reliable
4e3392
virDomainPtr object.  The only thing we can safely do with it is to
4e3392
get its UUID.  Modify the API correspondingly.
4e3392
4e3392
Updates commit 380f1e05b244ae4750ca5101b5b5a182dcd0d1fd.
4e3392
---
4e3392
 examples/get_all_domain_stats.ml |  7 ++++---
4e3392
 libvirt/libvirt.ml               |  6 +++---
4e3392
 libvirt/libvirt.mli              |  6 +++---
4e3392
 libvirt/libvirt_c_oneoffs.c      | 13 +++++++++++--
4e3392
 4 files changed, 21 insertions(+), 11 deletions(-)
4e3392
4e3392
diff --git a/examples/get_all_domain_stats.ml b/examples/get_all_domain_stats.ml
4e3392
index cc86da6..be91f77 100644
4e3392
--- a/examples/get_all_domain_stats.ml
4e3392
+++ b/examples/get_all_domain_stats.ml
4e3392
@@ -8,10 +8,11 @@ open Printf
4e3392
 module C = Libvirt.Connect
4e3392
 module D = Libvirt.Domain
4e3392
 
4e3392
-let print_stats stats =
4e3392
+let print_stats conn stats =
4e3392
   try
4e3392
     Array.iter (
4e3392
-      fun { D.dom = dom; D.params = params } ->
4e3392
+      fun { D.dom_uuid = uuid; D.params = params } ->
4e3392
+        let dom = D.lookup_by_uuid conn uuid in
4e3392
         printf "domain %s:\n" (D.get_name dom);
4e3392
         Array.iteri (
4e3392
           fun i (field, value) ->
4e3392
@@ -55,7 +56,7 @@ let () =
4e3392
   while not !quit do
4e3392
     let stats = D.get_all_domain_stats conn what who in
4e3392
 
4e3392
-    if stats <> [||] then print_stats stats
4e3392
+    if stats <> [||] then print_stats conn stats
4e3392
     else (
4e3392
       printf "no guests found\n";
4e3392
       quit := true
4e3392
diff --git a/libvirt/libvirt.ml b/libvirt/libvirt.ml
4e3392
index ce1878a..d03a127 100644
4e3392
--- a/libvirt/libvirt.ml
4e3392
+++ b/libvirt/libvirt.ml
4e3392
@@ -408,8 +408,8 @@ struct
4e3392
     | StatsState | StatsCpuTotal | StatsBalloon | StatsVcpu
4e3392
     | StatsInterface | StatsBlock | StatsPerf
4e3392
 
4e3392
-  type 'a domain_stats_record = {
4e3392
-    dom : 'a t;
4e3392
+  type domain_stats_record = {
4e3392
+    dom_uuid : uuid;
4e3392
     params : typed_param array;
4e3392
   }
4e3392
 
4e3392
@@ -467,7 +467,7 @@ struct
4e3392
   external block_peek : [>`W] t -> string -> int64 -> int -> string -> int -> unit = "ocaml_libvirt_domain_block_peek_bytecode" "ocaml_libvirt_domain_block_peek_native"
4e3392
   external memory_peek : [>`W] t -> memory_flag list -> int64 -> int -> string -> int -> unit = "ocaml_libvirt_domain_memory_peek_bytecode" "ocaml_libvirt_domain_memory_peek_native"
4e3392
 
4e3392
-  external get_all_domain_stats : 'a Connect.t -> stats_type list -> get_all_domain_stats_flag list -> 'a domain_stats_record array = "ocaml_libvirt_domain_get_all_domain_stats"
4e3392
+  external get_all_domain_stats : [>`R] Connect.t -> stats_type list -> get_all_domain_stats_flag list -> domain_stats_record array = "ocaml_libvirt_domain_get_all_domain_stats"
4e3392
 
4e3392
   external const : [>`R] t -> ro t = "%identity"
4e3392
 
4e3392
diff --git a/libvirt/libvirt.mli b/libvirt/libvirt.mli
4e3392
index d1b5992..dc0033b 100644
4e3392
--- a/libvirt/libvirt.mli
4e3392
+++ b/libvirt/libvirt.mli
4e3392
@@ -494,8 +494,8 @@ sig
4e3392
     | StatsState | StatsCpuTotal | StatsBalloon | StatsVcpu
4e3392
     | StatsInterface | StatsBlock | StatsPerf
4e3392
 
4e3392
-  type 'a domain_stats_record = {
4e3392
-    dom : 'a t;
4e3392
+  type domain_stats_record = {
4e3392
+    dom_uuid : uuid;
4e3392
     params : typed_param array;
4e3392
   }
4e3392
 
4e3392
@@ -636,7 +636,7 @@ sig
4e3392
 
4e3392
 	See also {!max_peek}. *)
4e3392
 
4e3392
-  external get_all_domain_stats : 'a Connect.t -> stats_type list -> get_all_domain_stats_flag list -> 'a domain_stats_record array = "ocaml_libvirt_domain_get_all_domain_stats"
4e3392
+  external get_all_domain_stats : [>`R] Connect.t -> stats_type list -> get_all_domain_stats_flag list -> domain_stats_record array = "ocaml_libvirt_domain_get_all_domain_stats"
4e3392
     (** [get_all_domain_stats conn stats flags] allows you to read
4e3392
         all stats across multiple/all domains in a single call.
4e3392
 
4e3392
diff --git a/libvirt/libvirt_c_oneoffs.c b/libvirt/libvirt_c_oneoffs.c
4e3392
index 17412f5..958ba69 100644
4e3392
--- a/libvirt/libvirt_c_oneoffs.c
4e3392
+++ b/libvirt/libvirt_c_oneoffs.c
4e3392
@@ -570,6 +570,7 @@ ocaml_libvirt_domain_get_all_domain_stats (value connv,
4e3392
   virDomainStatsRecordPtr *rstats;
4e3392
   unsigned int stats = 0, flags = 0;
4e3392
   int i, j, r;
4e3392
+  unsigned char uuid[VIR_UUID_BUFLEN];
4e3392
 
4e3392
   /* Get stats and flags. */
4e3392
   for (; statsv != Val_int (0); statsv = Field (statsv, 1)) {
4e3392
@@ -619,8 +620,16 @@ ocaml_libvirt_domain_get_all_domain_stats (value connv,
4e3392
   rv = caml_alloc (r, 0);       /* domain_stats_record array. */
4e3392
   for (i = 0; i < r; ++i) {
4e3392
     dsv = caml_alloc (2, 0);    /* domain_stats_record */
4e3392
-    virDomainRef (rstats[i]->dom);
4e3392
-    Store_field (dsv, 0, Val_domain (rstats[i]->dom, connv));
4e3392
+
4e3392
+    /* Libvirt returns something superficially resembling a
4e3392
+     * virDomainPtr, but it's not a real virDomainPtr object
4e3392
+     * (eg. dom->id == -1, and its refcount is wrong).  The only thing
4e3392
+     * we can safely get from it is the UUID.
4e3392
+     */
4e3392
+    v = caml_alloc_string (VIR_UUID_BUFLEN);
4e3392
+    virDomainGetUUID (rstats[i]->dom, uuid);
4e3392
+    memcpy (String_val (v), uuid, VIR_UUID_BUFLEN);
4e3392
+    Store_field (dsv, 0, v);
4e3392
 
4e3392
     tpv = caml_alloc (rstats[i]->nparams, 0); /* typed_param array */
4e3392
     for (j = 0; j < rstats[i]->nparams; ++j) {
4e3392
-- 
4e3392
2.9.3
4e3392