1 /* OCaml bindings for libvirt.
2 * (C) Copyright 2007 Richard W.M. Jones, Red Hat Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 /* Please read libvirt/README file. */
22 /*----------------------------------------------------------------------*/
25 ocaml_libvirt_get_version (value driverv, value unit)
27 CAMLparam2 (driverv, unit);
29 const char *driver = Optstring_val (driverv);
30 unsigned long libVer, typeVer = 0, *typeVer_ptr;
33 typeVer_ptr = driver ? &typeVer : NULL;
34 NONBLOCKING (r = virGetVersion (&libVer, driver, typeVer_ptr));
35 CHECK_ERROR (r == -1, NULL, "virGetVersion");
37 rv = caml_alloc_tuple (2);
38 Store_field (rv, 0, Val_int (libVer));
39 Store_field (rv, 1, Val_int (typeVer));
43 /*----------------------------------------------------------------------*/
45 /* Connection object. */
48 ocaml_libvirt_connect_open (value namev, value unit)
50 CAMLparam2 (namev, unit);
52 const char *name = Optstring_val (namev);
55 NONBLOCKING (conn = virConnectOpen (name));
56 CHECK_ERROR (!conn, NULL, "virConnectOpen");
58 rv = Val_connect (conn);
64 ocaml_libvirt_connect_open_readonly (value namev, value unit)
66 CAMLparam2 (namev, unit);
68 const char *name = Optstring_val (namev);
71 NONBLOCKING (conn = virConnectOpenReadOnly (name));
72 CHECK_ERROR (!conn, NULL, "virConnectOpen");
74 rv = Val_connect (conn);
80 ocaml_libvirt_connect_get_version (value connv)
83 virConnectPtr conn = Connect_val (connv);
87 NONBLOCKING (r = virConnectGetVersion (conn, &hvVer));
88 CHECK_ERROR (r == -1, conn, "virConnectGetVersion");
90 CAMLreturn (Val_int (hvVer));
94 ocaml_libvirt_connect_get_max_vcpus (value connv, value typev)
96 CAMLparam2 (connv, typev);
97 virConnectPtr conn = Connect_val (connv);
98 const char *type = Optstring_val (typev);
101 NONBLOCKING (r = virConnectGetMaxVcpus (conn, type));
102 CHECK_ERROR (r == -1, conn, "virConnectGetMaxVcpus");
104 CAMLreturn (Val_int (r));
108 ocaml_libvirt_connect_get_node_info (value connv)
112 virConnectPtr conn = Connect_val (connv);
116 NONBLOCKING (r = virNodeGetInfo (conn, &info));
117 CHECK_ERROR (r == -1, conn, "virNodeGetInfo");
119 rv = caml_alloc (8, 0);
120 v = caml_copy_string (info.model); Store_field (rv, 0, v);
121 v = caml_copy_int64 (info.memory); Store_field (rv, 1, v);
122 Store_field (rv, 2, Val_int (info.cpus));
123 Store_field (rv, 3, Val_int (info.mhz));
124 Store_field (rv, 4, Val_int (info.nodes));
125 Store_field (rv, 5, Val_int (info.sockets));
126 Store_field (rv, 6, Val_int (info.cores));
127 Store_field (rv, 7, Val_int (info.threads));
133 ocaml_libvirt_connect_node_get_free_memory (value connv)
137 virConnectPtr conn = Connect_val (connv);
138 unsigned long long r;
140 NONBLOCKING (r = virNodeGetFreeMemory (conn));
141 CHECK_ERROR (r == 0, conn, "virNodeGetFreeMemory");
143 rv = caml_copy_int64 ((int64) r);
148 ocaml_libvirt_connect_node_get_cells_free_memory (value connv,
149 value startv, value maxv)
151 CAMLparam3 (connv, startv, maxv);
153 virConnectPtr conn = Connect_val (connv);
154 int start = Int_val (startv);
155 int max = Int_val (maxv);
157 unsigned long long freemems[max];
159 NONBLOCKING (r = virNodeGetCellsFreeMemory (conn, freemems, start, max));
160 CHECK_ERROR (r == -1, conn, "virNodeGetCellsFreeMemory");
162 rv = caml_alloc (r, 0);
163 for (i = 0; i < r; ++i) {
164 iv = caml_copy_int64 ((int64) freemems[i]);
165 Store_field (rv, i, iv);
172 ocaml_libvirt_domain_get_id (value domv)
175 virDomainPtr dom = Domain_val (domv);
176 /*virConnectPtr conn = Connect_domv (domv);*/
179 NONBLOCKING (r = virDomainGetID (dom));
180 /* In theory this could return -1 on error, but in practice
181 * libvirt never does this unless you call it with a corrupted
182 * or NULL dom object. So ignore errors here.
185 CAMLreturn (Val_int ((int) r));
189 ocaml_libvirt_domain_get_max_memory (value domv)
193 virDomainPtr dom = Domain_val (domv);
194 virConnectPtr conn = Connect_domv (domv);
197 NONBLOCKING (r = virDomainGetMaxMemory (dom));
198 CHECK_ERROR (r == 0 /* [sic] */, conn, "virDomainGetMaxMemory");
200 rv = caml_copy_int64 (r);
205 ocaml_libvirt_domain_set_max_memory (value domv, value memv)
207 CAMLparam2 (domv, memv);
208 virDomainPtr dom = Domain_val (domv);
209 virConnectPtr conn = Connect_domv (domv);
210 unsigned long mem = Int64_val (memv);
213 NONBLOCKING (r = virDomainSetMaxMemory (dom, mem));
214 CHECK_ERROR (r == -1, conn, "virDomainSetMaxMemory");
216 CAMLreturn (Val_unit);
220 ocaml_libvirt_domain_set_memory (value domv, value memv)
222 CAMLparam2 (domv, memv);
223 virDomainPtr dom = Domain_val (domv);
224 virConnectPtr conn = Connect_domv (domv);
225 unsigned long mem = Int64_val (memv);
228 NONBLOCKING (r = virDomainSetMemory (dom, mem));
229 CHECK_ERROR (r == -1, conn, "virDomainSetMemory");
231 CAMLreturn (Val_unit);
235 ocaml_libvirt_domain_get_info (value domv)
239 virDomainPtr dom = Domain_val (domv);
240 virConnectPtr conn = Connect_domv (domv);
244 NONBLOCKING (r = virDomainGetInfo (dom, &info));
245 CHECK_ERROR (r == -1, conn, "virDomainGetInfo");
247 rv = caml_alloc (5, 0);
248 Store_field (rv, 0, Val_int (info.state)); // These flags are compatible.
249 v = caml_copy_int64 (info.maxMem); Store_field (rv, 1, v);
250 v = caml_copy_int64 (info.memory); Store_field (rv, 2, v);
251 Store_field (rv, 3, Val_int (info.nrVirtCpu));
252 v = caml_copy_int64 (info.cpuTime); Store_field (rv, 4, v);
258 ocaml_libvirt_domain_get_scheduler_type (value domv)
261 CAMLlocal2 (rv, strv);
262 virDomainPtr dom = Domain_val (domv);
263 virConnectPtr conn = Connect_domv (domv);
267 NONBLOCKING (r = virDomainGetSchedulerType (dom, &nparams));
268 CHECK_ERROR (!r, conn, "virDomainGetSchedulerType");
270 rv = caml_alloc_tuple (2);
271 strv = caml_copy_string (r); Store_field (rv, 0, strv);
273 Store_field (rv, 1, nparams);
278 ocaml_libvirt_domain_get_scheduler_parameters (value domv, value nparamsv)
280 CAMLparam2 (domv, nparamsv);
281 CAMLlocal4 (rv, v, v2, v3);
282 virDomainPtr dom = Domain_val (domv);
283 virConnectPtr conn = Connect_domv (domv);
284 int nparams = Int_val (nparamsv);
285 virSchedParameter params[nparams];
288 NONBLOCKING (r = virDomainGetSchedulerParameters (dom, params, &nparams));
289 CHECK_ERROR (r == -1, conn, "virDomainGetSchedulerParameters");
291 rv = caml_alloc (nparams, 0);
292 for (i = 0; i < nparams; ++i) {
293 v = caml_alloc_tuple (2); Store_field (rv, i, v);
294 v2 = caml_copy_string (params[i].field); Store_field (v, 0, v2);
295 switch (params[i].type) {
296 case VIR_DOMAIN_SCHED_FIELD_INT:
297 v2 = caml_alloc (1, 0);
298 v3 = caml_copy_int32 (params[i].value.i); Store_field (v2, 0, v3);
300 case VIR_DOMAIN_SCHED_FIELD_UINT:
301 v2 = caml_alloc (1, 1);
302 v3 = caml_copy_int32 (params[i].value.ui); Store_field (v2, 0, v3);
304 case VIR_DOMAIN_SCHED_FIELD_LLONG:
305 v2 = caml_alloc (1, 2);
306 v3 = caml_copy_int64 (params[i].value.l); Store_field (v2, 0, v3);
308 case VIR_DOMAIN_SCHED_FIELD_ULLONG:
309 v2 = caml_alloc (1, 3);
310 v3 = caml_copy_int64 (params[i].value.ul); Store_field (v2, 0, v3);
312 case VIR_DOMAIN_SCHED_FIELD_DOUBLE:
313 v2 = caml_alloc (1, 4);
314 v3 = caml_copy_double (params[i].value.d); Store_field (v2, 0, v3);
316 case VIR_DOMAIN_SCHED_FIELD_BOOLEAN:
317 v2 = caml_alloc (1, 5);
318 Store_field (v2, 0, Val_int (params[i].value.b));
321 caml_failwith ((char *)__FUNCTION__);
323 Store_field (v, 1, v2);
329 ocaml_libvirt_domain_set_scheduler_parameters (value domv, value paramsv)
331 CAMLparam2 (domv, paramsv);
333 virDomainPtr dom = Domain_val (domv);
334 virConnectPtr conn = Connect_domv (domv);
335 int nparams = Wosize_val (paramsv);
336 virSchedParameter params[nparams];
340 for (i = 0; i < nparams; ++i) {
341 v = Field (paramsv, i); /* Points to the two-element tuple. */
342 name = String_val (Field (v, 0));
343 strncpy (params[i].field, name, VIR_DOMAIN_SCHED_FIELD_LENGTH);
344 params[i].field[VIR_DOMAIN_SCHED_FIELD_LENGTH-1] = '\0';
345 v = Field (v, 1); /* Points to the sched_param_value block. */
346 switch (Tag_val (v)) {
348 params[i].type = VIR_DOMAIN_SCHED_FIELD_INT;
349 params[i].value.i = Int32_val (Field (v, 0));
352 params[i].type = VIR_DOMAIN_SCHED_FIELD_UINT;
353 params[i].value.ui = Int32_val (Field (v, 0));
356 params[i].type = VIR_DOMAIN_SCHED_FIELD_LLONG;
357 params[i].value.l = Int64_val (Field (v, 0));
360 params[i].type = VIR_DOMAIN_SCHED_FIELD_ULLONG;
361 params[i].value.ul = Int64_val (Field (v, 0));
364 params[i].type = VIR_DOMAIN_SCHED_FIELD_DOUBLE;
365 params[i].value.d = Double_val (Field (v, 0));
368 params[i].type = VIR_DOMAIN_SCHED_FIELD_BOOLEAN;
369 params[i].value.b = Int_val (Field (v, 0));
372 caml_failwith ((char *)__FUNCTION__);
376 NONBLOCKING (r = virDomainSetSchedulerParameters (dom, params, nparams));
377 CHECK_ERROR (r == -1, conn, "virDomainSetSchedulerParameters");
379 CAMLreturn (Val_unit);
383 ocaml_libvirt_domain_set_vcpus (value domv, value nvcpusv)
385 CAMLparam2 (domv, nvcpusv);
386 virDomainPtr dom = Domain_val (domv);
387 virConnectPtr conn = Connect_domv (domv);
388 int r, nvcpus = Int_val (nvcpusv);
390 NONBLOCKING (r = virDomainSetVcpus (dom, nvcpus));
391 CHECK_ERROR (r == -1, conn, "virDomainSetVcpus");
393 CAMLreturn (Val_unit);
397 ocaml_libvirt_domain_pin_vcpu (value domv, value vcpuv, value cpumapv)
399 CAMLparam3 (domv, vcpuv, cpumapv);
400 virDomainPtr dom = Domain_val (domv);
401 virConnectPtr conn = Connect_domv (domv);
402 int maplen = caml_string_length (cpumapv);
403 unsigned char *cpumap = (unsigned char *) String_val (cpumapv);
404 int vcpu = Int_val (vcpuv);
407 NONBLOCKING (r = virDomainPinVcpu (dom, vcpu, cpumap, maplen));
408 CHECK_ERROR (r == -1, conn, "virDomainPinVcpu");
410 CAMLreturn (Val_unit);
414 ocaml_libvirt_domain_get_vcpus (value domv, value maxinfov, value maplenv)
416 CAMLparam3 (domv, maxinfov, maplenv);
417 CAMLlocal5 (rv, infov, strv, v, v2);
418 virDomainPtr dom = Domain_val (domv);
419 virConnectPtr conn = Connect_domv (domv);
420 int maxinfo = Int_val (maxinfov);
421 int maplen = Int_val (maplenv);
422 virVcpuInfo info[maxinfo];
423 unsigned char cpumaps[maxinfo * maplen];
426 memset (info, 0, sizeof (virVcpuInfo) * maxinfo);
427 memset (cpumaps, 0, maxinfo * maplen);
429 NONBLOCKING (r = virDomainGetVcpus (dom, info, maxinfo, cpumaps, maplen));
430 CHECK_ERROR (r == -1, conn, "virDomainPinVcpu");
432 /* Copy the virVcpuInfo structures. */
433 infov = caml_alloc (maxinfo, 0);
434 for (i = 0; i < maxinfo; ++i) {
435 v2 = caml_alloc (4, 0); Store_field (infov, i, v2);
436 Store_field (v2, 0, Val_int (info[i].number));
437 Store_field (v2, 1, Val_int (info[i].state));
438 v = caml_copy_int64 (info[i].cpuTime); Store_field (v2, 2, v);
439 Store_field (v2, 3, Val_int (info[i].cpu));
442 /* Copy the bitmap. */
443 strv = caml_alloc_string (maxinfo * maplen);
444 memcpy (String_val (strv), cpumaps, maxinfo * maplen);
446 /* Allocate the tuple and return it. */
447 rv = caml_alloc_tuple (3);
448 Store_field (rv, 0, Val_int (r)); /* number of CPUs. */
449 Store_field (rv, 1, infov);
450 Store_field (rv, 2, strv);
456 ocaml_libvirt_domain_get_cpu_stats (value domv)
459 CAMLlocal5 (cpustats, param_head, param_node, typed_param, typed_param_value);
461 virDomainPtr dom = Domain_val (domv);
462 virConnectPtr conn = Connect_domv (domv);
463 virTypedParameterPtr params;
464 int r, cpu, ncpus, nparams, i, j, pos;
467 /* get number of pcpus */
468 NONBLOCKING (nr_pcpus = virDomainGetCPUStats(dom, NULL, 0, 0, 0, 0));
469 CHECK_ERROR (nr_pcpus < 0, conn, "virDomainGetCPUStats");
471 /* get percpu information */
472 NONBLOCKING (nparams = virDomainGetCPUStats(dom, NULL, 0, 0, 1, 0));
473 CHECK_ERROR (nparams < 0, conn, "virDomainGetCPUStats");
475 if ((params = malloc(sizeof(*params) * nparams * 128)) == NULL)
476 caml_failwith ("virDomainGetCPUStats: malloc");
478 cpustats = caml_alloc (nr_pcpus, 0); /* cpustats: array of params(list of typed_param) */
480 while (cpu < nr_pcpus) {
481 ncpus = nr_pcpus - cpu > 128 ? 128 : nr_pcpus - cpu;
483 NONBLOCKING (r = virDomainGetCPUStats(dom, params, nparams, cpu, ncpus, 0));
484 CHECK_ERROR (r < 0, conn, "virDomainGetCPUStats");
486 for (i = 0; i < ncpus; i++) {
487 /* list of typed_param: single linked list of param_nodes */
488 param_head = Val_emptylist; /* param_head: the head param_node of list of typed_param */
490 if (params[i * nparams].type == 0) {
491 Store_field(cpustats, cpu + i, param_head);
495 for (j = r - 1; j >= 0; j--) {
496 pos = i * nparams + j;
497 if (params[pos].type == 0)
500 param_node = caml_alloc(2, 0); /* param_node: typed_param, next param_node */
501 Store_field(param_node, 1, param_head);
502 param_head = param_node;
504 typed_param = caml_alloc(2, 0); /* typed_param: field name(string), typed_param_value */
505 Store_field(param_node, 0, typed_param);
506 Store_field(typed_param, 0, caml_copy_string(params[pos].field));
508 /* typed_param_value: value with the corresponding type tag */
509 switch(params[pos].type) {
510 case VIR_TYPED_PARAM_INT:
511 typed_param_value = caml_alloc (1, 0);
512 v = caml_copy_int32 (params[pos].value.i);
514 case VIR_TYPED_PARAM_UINT:
515 typed_param_value = caml_alloc (1, 1);
516 v = caml_copy_int32 (params[pos].value.ui);
518 case VIR_TYPED_PARAM_LLONG:
519 typed_param_value = caml_alloc (1, 2);
520 v = caml_copy_int64 (params[pos].value.l);
522 case VIR_TYPED_PARAM_ULLONG:
523 typed_param_value = caml_alloc (1, 3);
524 v = caml_copy_int64 (params[pos].value.ul);
526 case VIR_TYPED_PARAM_DOUBLE:
527 typed_param_value = caml_alloc (1, 4);
528 v = caml_copy_double (params[pos].value.d);
530 case VIR_TYPED_PARAM_BOOLEAN:
531 typed_param_value = caml_alloc (1, 5);
532 v = Val_bool (params[pos].value.b);
534 case VIR_TYPED_PARAM_STRING:
535 typed_param_value = caml_alloc (1, 6);
536 v = caml_copy_string (params[pos].value.s);
537 free (params[pos].value.s);
540 /* XXX Memory leak on this path, if there are more
541 * VIR_TYPED_PARAM_STRING past this point in the array.
544 caml_failwith ("virDomainGetCPUStats: "
545 "unknown parameter type returned");
547 Store_field (typed_param_value, 0, v);
548 Store_field (typed_param, 1, typed_param_value);
550 Store_field (cpustats, cpu + i, param_head);
555 CAMLreturn (cpustats);
559 ocaml_libvirt_domain_migrate_native (value domv, value dconnv, value flagsv, value optdnamev, value opturiv, value optbandwidthv, value unitv)
561 CAMLparam5 (domv, dconnv, flagsv, optdnamev, opturiv);
562 CAMLxparam2 (optbandwidthv, unitv);
563 CAMLlocal2 (flagv, rv);
564 virDomainPtr dom = Domain_val (domv);
565 virConnectPtr conn = Connect_domv (domv);
566 virConnectPtr dconn = Connect_val (dconnv);
568 const char *dname = Optstring_val (optdnamev);
569 const char *uri = Optstring_val (opturiv);
570 unsigned long bandwidth;
573 /* Iterate over the list of flags. */
574 for (; flagsv != Val_int (0); flagsv = Field (flagsv, 1))
576 flagv = Field (flagsv, 0);
577 if (flagv == Val_int (0))
578 flags |= VIR_MIGRATE_LIVE;
581 if (optbandwidthv == Val_int (0)) /* None */
583 else /* Some bandwidth */
584 bandwidth = Int_val (Field (optbandwidthv, 0));
586 NONBLOCKING (r = virDomainMigrate (dom, dconn, flags, dname, uri, bandwidth));
587 CHECK_ERROR (!r, conn, "virDomainMigrate");
589 rv = Val_domain (r, dconnv);
595 ocaml_libvirt_domain_migrate_bytecode (value *argv, int argn)
597 return ocaml_libvirt_domain_migrate_native (argv[0], argv[1], argv[2],
598 argv[3], argv[4], argv[5],
603 ocaml_libvirt_domain_block_stats (value domv, value pathv)
605 CAMLparam2 (domv, pathv);
607 virDomainPtr dom = Domain_val (domv);
608 virConnectPtr conn = Connect_domv (domv);
609 char *path = String_val (pathv);
610 struct _virDomainBlockStats stats;
613 NONBLOCKING (r = virDomainBlockStats (dom, path, &stats, sizeof stats));
614 CHECK_ERROR (r == -1, conn, "virDomainBlockStats");
616 rv = caml_alloc (5, 0);
617 v = caml_copy_int64 (stats.rd_req); Store_field (rv, 0, v);
618 v = caml_copy_int64 (stats.rd_bytes); Store_field (rv, 1, v);
619 v = caml_copy_int64 (stats.wr_req); Store_field (rv, 2, v);
620 v = caml_copy_int64 (stats.wr_bytes); Store_field (rv, 3, v);
621 v = caml_copy_int64 (stats.errs); Store_field (rv, 4, v);
627 ocaml_libvirt_domain_interface_stats (value domv, value pathv)
629 CAMLparam2 (domv, pathv);
631 virDomainPtr dom = Domain_val (domv);
632 virConnectPtr conn = Connect_domv (domv);
633 char *path = String_val (pathv);
634 struct _virDomainInterfaceStats stats;
637 NONBLOCKING (r = virDomainInterfaceStats (dom, path, &stats, sizeof stats));
638 CHECK_ERROR (r == -1, conn, "virDomainInterfaceStats");
640 rv = caml_alloc (8, 0);
641 v = caml_copy_int64 (stats.rx_bytes); Store_field (rv, 0, v);
642 v = caml_copy_int64 (stats.rx_packets); Store_field (rv, 1, v);
643 v = caml_copy_int64 (stats.rx_errs); Store_field (rv, 2, v);
644 v = caml_copy_int64 (stats.rx_drop); Store_field (rv, 3, v);
645 v = caml_copy_int64 (stats.tx_bytes); Store_field (rv, 4, v);
646 v = caml_copy_int64 (stats.tx_packets); Store_field (rv, 5, v);
647 v = caml_copy_int64 (stats.tx_errs); Store_field (rv, 6, v);
648 v = caml_copy_int64 (stats.tx_drop); Store_field (rv, 7, v);
654 ocaml_libvirt_domain_block_peek_native (value domv, value pathv, value offsetv, value sizev, value bufferv, value boffv)
656 CAMLparam5 (domv, pathv, offsetv, sizev, bufferv);
658 virDomainPtr dom = Domain_val (domv);
659 virConnectPtr conn = Connect_domv (domv);
660 const char *path = String_val (pathv);
661 unsigned long long offset = Int64_val (offsetv);
662 size_t size = Int_val (sizev);
663 char *buffer = String_val (bufferv);
664 int boff = Int_val (boffv);
667 /* Check that the return buffer is big enough. */
668 if (caml_string_length (bufferv) < boff + size)
669 caml_failwith ("virDomainBlockPeek: return buffer too short");
671 /* NB. not NONBLOCKING because buffer might move (XXX) */
672 r = virDomainBlockPeek (dom, path, offset, size, buffer+boff, 0);
673 CHECK_ERROR (r == -1, conn, "virDomainBlockPeek");
675 CAMLreturn (Val_unit);
679 ocaml_libvirt_domain_block_peek_bytecode (value *argv, int argn)
681 return ocaml_libvirt_domain_block_peek_native (argv[0], argv[1], argv[2],
682 argv[3], argv[4], argv[5]);
686 ocaml_libvirt_domain_memory_peek_native (value domv, value flagsv, value offsetv, value sizev, value bufferv, value boffv)
688 CAMLparam5 (domv, flagsv, offsetv, sizev, bufferv);
691 virDomainPtr dom = Domain_val (domv);
692 virConnectPtr conn = Connect_domv (domv);
694 unsigned long long offset = Int64_val (offsetv);
695 size_t size = Int_val (sizev);
696 char *buffer = String_val (bufferv);
697 int boff = Int_val (boffv);
700 /* Check that the return buffer is big enough. */
701 if (caml_string_length (bufferv) < boff + size)
702 caml_failwith ("virDomainMemoryPeek: return buffer too short");
705 for (; flagsv != Val_int (0); flagsv = Field (flagsv, 1))
707 flagv = Field (flagsv, 0);
708 if (flagv == Val_int (0))
709 flags |= VIR_MEMORY_VIRTUAL;
712 /* NB. not NONBLOCKING because buffer might move (XXX) */
713 r = virDomainMemoryPeek (dom, offset, size, buffer+boff, flags);
714 CHECK_ERROR (r == -1, conn, "virDomainMemoryPeek");
716 CAMLreturn (Val_unit);
720 ocaml_libvirt_domain_memory_peek_bytecode (value *argv, int argn)
722 return ocaml_libvirt_domain_memory_peek_native (argv[0], argv[1], argv[2],
723 argv[3], argv[4], argv[5]);
727 ocaml_libvirt_storage_pool_get_info (value poolv)
731 virStoragePoolPtr pool = Pool_val (poolv);
732 virConnectPtr conn = Connect_polv (poolv);
733 virStoragePoolInfo info;
736 NONBLOCKING (r = virStoragePoolGetInfo (pool, &info));
737 CHECK_ERROR (r == -1, conn, "virStoragePoolGetInfo");
739 rv = caml_alloc (4, 0);
740 Store_field (rv, 0, Val_int (info.state));
741 v = caml_copy_int64 (info.capacity); Store_field (rv, 1, v);
742 v = caml_copy_int64 (info.allocation); Store_field (rv, 2, v);
743 v = caml_copy_int64 (info.available); Store_field (rv, 3, v);
749 ocaml_libvirt_storage_vol_get_info (value volv)
753 virStorageVolPtr vol = Volume_val (volv);
754 virConnectPtr conn = Connect_volv (volv);
755 virStorageVolInfo info;
758 NONBLOCKING (r = virStorageVolGetInfo (vol, &info));
759 CHECK_ERROR (r == -1, conn, "virStorageVolGetInfo");
761 rv = caml_alloc (3, 0);
762 Store_field (rv, 0, Val_int (info.type));
763 v = caml_copy_int64 (info.capacity); Store_field (rv, 1, v);
764 v = caml_copy_int64 (info.allocation); Store_field (rv, 2, v);
769 /*----------------------------------------------------------------------*/
772 ocaml_libvirt_virterror_get_last_error (value unitv)
776 virErrorPtr err = virGetLastError ();
778 rv = Val_opt (err, (Val_ptr_t) Val_virterror);
784 ocaml_libvirt_virterror_get_last_conn_error (value connv)
788 virConnectPtr conn = Connect_val (connv);
790 rv = Val_opt (conn, (Val_ptr_t) Val_connect);
796 ocaml_libvirt_virterror_reset_last_error (value unitv)
799 virResetLastError ();
800 CAMLreturn (Val_unit);
804 ocaml_libvirt_virterror_reset_last_conn_error (value connv)
807 virConnectPtr conn = Connect_val (connv);
808 virConnResetLastError (conn);
809 CAMLreturn (Val_unit);
812 /*----------------------------------------------------------------------*/
814 /* Initialise the library. */
816 ocaml_libvirt_init (value unit)
822 r = virInitialize ();
823 CHECK_ERROR (r == -1, NULL, "virInitialize");
825 CAMLreturn (Val_unit);