git.annexia.org
/
ocaml-libvirt.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add contrib directory, and non-upstream patch to add Domain.get_cpu_stats_total.
[ocaml-libvirt.git]
/
libvirt
/
libvirt_c_oneoffs.c
diff --git
a/libvirt/libvirt_c_oneoffs.c
b/libvirt/libvirt_c_oneoffs.c
index
f827707
..
70cf96f
100644
(file)
--- a/
libvirt/libvirt_c_oneoffs.c
+++ b/
libvirt/libvirt_c_oneoffs.c
@@
-532,20
+532,24
@@
extern int virDomainGetCPUStats (virDomainPtr domain,
#endif
CAMLprim value
#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
{
#ifdef HAVE_VIRDOMAINGETCPUSTATS
- CAMLparam
2 (domv, nr_pcpus
v);
+ CAMLparam
1 (dom
v);
CAMLlocal5 (cpustats, param_head, param_node, typed_param, typed_param_value);
CAMLlocal1 (v);
virDomainPtr dom = Domain_val (domv);
virConnectPtr conn = Connect_domv (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;
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 */
/* get percpu information */
- NONBLOCKING (nparams = virDomainGetCPUStats(dom, NULL, 0,
-1
, 1, 0));
+ NONBLOCKING (nparams = virDomainGetCPUStats(dom, NULL, 0,
0
, 1, 0));
CHECK_ERROR (nparams < 0, conn, "virDomainGetCPUStats");
if ((params = malloc(sizeof(*params) * nparams * 128)) == NULL)
CHECK_ERROR (nparams < 0, conn, "virDomainGetCPUStats");
if ((params = malloc(sizeof(*params) * nparams * 128)) == NULL)
@@
-568,7
+572,7
@@
ocaml_libvirt_domain_get_cpu_stats (value domv, value nr_pcpusv)
continue;
}
continue;
}
- for (j =
nparams
- 1; j >= 0; j--) {
+ for (j =
r
- 1; j >= 0; j--) {
pos = i * nparams + j;
if (params[pos].type == 0)
continue;
pos = i * nparams + j;
if (params[pos].type == 0)
continue;
@@
-613,6
+617,9
@@
ocaml_libvirt_domain_get_cpu_stats (value domv, value nr_pcpusv)
free (params[pos].value.s);
break;
default:
free (params[pos].value.s);
break;
default:
+ /* XXX Memory leak on this path, if there are more
+ * VIR_TYPED_PARAM_STRING past this point in the array.
+ */
free (params);
caml_failwith ("virDomainGetCPUStats: "
"unknown parameter type returned");
free (params);
caml_failwith ("virDomainGetCPUStats: "
"unknown parameter type returned");