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));
132 #ifdef HAVE_WEAK_SYMBOLS
133 #ifdef HAVE_VIRNODEGETFREEMEMORY
134 extern unsigned long long virNodeGetFreeMemory (virConnectPtr conn)
135 __attribute__((weak));
140 ocaml_libvirt_connect_node_get_free_memory (value connv)
142 #ifdef HAVE_VIRNODEGETFREEMEMORY
145 virConnectPtr conn = Connect_val (connv);
146 unsigned long long r;
148 WEAK_SYMBOL_CHECK (virNodeGetFreeMemory);
149 NONBLOCKING (r = virNodeGetFreeMemory (conn));
150 CHECK_ERROR (r == 0, conn, "virNodeGetFreeMemory");
152 rv = caml_copy_int64 ((int64) r);
155 not_supported ("virNodeGetFreeMemory");
159 #ifdef HAVE_WEAK_SYMBOLS
160 #ifdef HAVE_VIRNODEGETCELLSFREEMEMORY
161 extern int virNodeGetCellsFreeMemory (virConnectPtr conn,
162 unsigned long long *freeMems,
163 int startCell, int maxCells)
164 __attribute__((weak));
169 ocaml_libvirt_connect_node_get_cells_free_memory (value connv,
170 value startv, value maxv)
172 #ifdef HAVE_VIRNODEGETCELLSFREEMEMORY
173 CAMLparam3 (connv, startv, maxv);
175 virConnectPtr conn = Connect_val (connv);
176 int start = Int_val (startv);
177 int max = Int_val (maxv);
179 unsigned long long freemems[max];
181 WEAK_SYMBOL_CHECK (virNodeGetCellsFreeMemory);
182 NONBLOCKING (r = virNodeGetCellsFreeMemory (conn, freemems, start, max));
183 CHECK_ERROR (r == -1, conn, "virNodeGetCellsFreeMemory");
185 rv = caml_alloc (r, 0);
186 for (i = 0; i < r; ++i) {
187 iv = caml_copy_int64 ((int64) freemems[i]);
188 Store_field (rv, i, iv);
193 not_supported ("virNodeGetCellsFreeMemory");
198 ocaml_libvirt_domain_get_id (value domv)
201 virDomainPtr dom = Domain_val (domv);
202 virConnectPtr conn = Connect_domv (domv);
205 NONBLOCKING (r = virDomainGetID (dom));
206 /* There's a bug in libvirt which means that if you try to get
207 * the ID of a defined-but-not-running domain, it returns -1,
208 * and there's no way to distinguish that from an error.
210 CHECK_ERROR (r == (unsigned int) -1, conn, "virDomainGetID");
212 CAMLreturn (Val_int ((int) r));
216 ocaml_libvirt_domain_get_max_memory (value domv)
220 virDomainPtr dom = Domain_val (domv);
221 virConnectPtr conn = Connect_domv (domv);
224 NONBLOCKING (r = virDomainGetMaxMemory (dom));
225 CHECK_ERROR (r == 0 /* [sic] */, conn, "virDomainGetMaxMemory");
227 rv = caml_copy_int64 (r);
232 ocaml_libvirt_domain_set_max_memory (value domv, value memv)
234 CAMLparam2 (domv, memv);
235 virDomainPtr dom = Domain_val (domv);
236 virConnectPtr conn = Connect_domv (domv);
237 unsigned long mem = Int64_val (memv);
240 NONBLOCKING (r = virDomainSetMaxMemory (dom, mem));
241 CHECK_ERROR (r == -1, conn, "virDomainSetMaxMemory");
243 CAMLreturn (Val_unit);
247 ocaml_libvirt_domain_set_memory (value domv, value memv)
249 CAMLparam2 (domv, memv);
250 virDomainPtr dom = Domain_val (domv);
251 virConnectPtr conn = Connect_domv (domv);
252 unsigned long mem = Int64_val (memv);
255 NONBLOCKING (r = virDomainSetMemory (dom, mem));
256 CHECK_ERROR (r == -1, conn, "virDomainSetMemory");
258 CAMLreturn (Val_unit);
262 ocaml_libvirt_domain_get_info (value domv)
266 virDomainPtr dom = Domain_val (domv);
267 virConnectPtr conn = Connect_domv (domv);
271 NONBLOCKING (r = virDomainGetInfo (dom, &info));
272 CHECK_ERROR (r == -1, conn, "virDomainGetInfo");
274 rv = caml_alloc (5, 0);
275 Store_field (rv, 0, Val_int (info.state)); // These flags are compatible.
276 v = caml_copy_int64 (info.maxMem); Store_field (rv, 1, v);
277 v = caml_copy_int64 (info.memory); Store_field (rv, 2, v);
278 Store_field (rv, 3, Val_int (info.nrVirtCpu));
279 v = caml_copy_int64 (info.cpuTime); Store_field (rv, 4, v);
284 #ifdef HAVE_WEAK_SYMBOLS
285 #ifdef HAVE_VIRDOMAINGETSCHEDULERTYPE
286 extern char *virDomainGetSchedulerType(virDomainPtr domain,
288 __attribute__((weak));
293 ocaml_libvirt_domain_get_scheduler_type (value domv)
295 #ifdef HAVE_VIRDOMAINGETSCHEDULERTYPE
297 CAMLlocal2 (rv, strv);
298 virDomainPtr dom = Domain_val (domv);
299 virConnectPtr conn = Connect_domv (domv);
303 WEAK_SYMBOL_CHECK (virDomainGetSchedulerType);
304 NONBLOCKING (r = virDomainGetSchedulerType (dom, &nparams));
305 CHECK_ERROR (!r, conn, "virDomainGetSchedulerType");
307 rv = caml_alloc_tuple (2);
308 strv = caml_copy_string (r); Store_field (rv, 0, strv);
310 Store_field (rv, 1, nparams);
313 not_supported ("virDomainGetSchedulerType");
317 #ifdef HAVE_WEAK_SYMBOLS
318 #ifdef HAVE_VIRDOMAINGETSCHEDULERPARAMETERS
319 extern int virDomainGetSchedulerParameters (virDomainPtr domain,
320 virSchedParameterPtr params,
322 __attribute__((weak));
327 ocaml_libvirt_domain_get_scheduler_parameters (value domv, value nparamsv)
329 #ifdef HAVE_VIRDOMAINGETSCHEDULERPARAMETERS
330 CAMLparam2 (domv, nparamsv);
331 CAMLlocal4 (rv, v, v2, v3);
332 virDomainPtr dom = Domain_val (domv);
333 virConnectPtr conn = Connect_domv (domv);
334 int nparams = Int_val (nparamsv);
335 virSchedParameter params[nparams];
338 WEAK_SYMBOL_CHECK (virDomainGetSchedulerParameters);
339 NONBLOCKING (r = virDomainGetSchedulerParameters (dom, params, &nparams));
340 CHECK_ERROR (r == -1, conn, "virDomainGetSchedulerParameters");
342 rv = caml_alloc (nparams, 0);
343 for (i = 0; i < nparams; ++i) {
344 v = caml_alloc_tuple (2); Store_field (rv, i, v);
345 v2 = caml_copy_string (params[i].field); Store_field (v, 0, v2);
346 switch (params[i].type) {
347 case VIR_DOMAIN_SCHED_FIELD_INT:
348 v2 = caml_alloc (1, 0);
349 v3 = caml_copy_int32 (params[i].value.i); Store_field (v2, 0, v3);
351 case VIR_DOMAIN_SCHED_FIELD_UINT:
352 v2 = caml_alloc (1, 1);
353 v3 = caml_copy_int32 (params[i].value.ui); Store_field (v2, 0, v3);
355 case VIR_DOMAIN_SCHED_FIELD_LLONG:
356 v2 = caml_alloc (1, 2);
357 v3 = caml_copy_int64 (params[i].value.l); Store_field (v2, 0, v3);
359 case VIR_DOMAIN_SCHED_FIELD_ULLONG:
360 v2 = caml_alloc (1, 3);
361 v3 = caml_copy_int64 (params[i].value.ul); Store_field (v2, 0, v3);
363 case VIR_DOMAIN_SCHED_FIELD_DOUBLE:
364 v2 = caml_alloc (1, 4);
365 v3 = caml_copy_double (params[i].value.d); Store_field (v2, 0, v3);
367 case VIR_DOMAIN_SCHED_FIELD_BOOLEAN:
368 v2 = caml_alloc (1, 5);
369 Store_field (v2, 0, Val_int (params[i].value.b));
372 caml_failwith ((char *)__FUNCTION__);
374 Store_field (v, 1, v2);
378 not_supported ("virDomainGetSchedulerParameters");
382 #ifdef HAVE_WEAK_SYMBOLS
383 #ifdef HAVE_VIRDOMAINSETSCHEDULERPARAMETERS
384 extern int virDomainSetSchedulerParameters (virDomainPtr domain,
385 virSchedParameterPtr params,
387 __attribute__((weak));
392 ocaml_libvirt_domain_set_scheduler_parameters (value domv, value paramsv)
394 #ifdef HAVE_VIRDOMAINSETSCHEDULERPARAMETERS
395 CAMLparam2 (domv, paramsv);
397 virDomainPtr dom = Domain_val (domv);
398 virConnectPtr conn = Connect_domv (domv);
399 int nparams = Wosize_val (paramsv);
400 virSchedParameter params[nparams];
404 for (i = 0; i < nparams; ++i) {
405 v = Field (paramsv, i); /* Points to the two-element tuple. */
406 name = String_val (Field (v, 0));
407 strncpy (params[i].field, name, VIR_DOMAIN_SCHED_FIELD_LENGTH);
408 params[i].field[VIR_DOMAIN_SCHED_FIELD_LENGTH-1] = '\0';
409 v = Field (v, 1); /* Points to the sched_param_value block. */
410 switch (Tag_val (v)) {
412 params[i].type = VIR_DOMAIN_SCHED_FIELD_INT;
413 params[i].value.i = Int32_val (Field (v, 0));
416 params[i].type = VIR_DOMAIN_SCHED_FIELD_UINT;
417 params[i].value.ui = Int32_val (Field (v, 0));
420 params[i].type = VIR_DOMAIN_SCHED_FIELD_LLONG;
421 params[i].value.l = Int64_val (Field (v, 0));
424 params[i].type = VIR_DOMAIN_SCHED_FIELD_ULLONG;
425 params[i].value.ul = Int64_val (Field (v, 0));
428 params[i].type = VIR_DOMAIN_SCHED_FIELD_DOUBLE;
429 params[i].value.d = Double_val (Field (v, 0));
432 params[i].type = VIR_DOMAIN_SCHED_FIELD_BOOLEAN;
433 params[i].value.b = Int_val (Field (v, 0));
436 caml_failwith ((char *)__FUNCTION__);
440 WEAK_SYMBOL_CHECK (virDomainSetSchedulerParameters);
441 NONBLOCKING (r = virDomainSetSchedulerParameters (dom, params, nparams));
442 CHECK_ERROR (r == -1, conn, "virDomainSetSchedulerParameters");
444 CAMLreturn (Val_unit);
446 not_supported ("virDomainSetSchedulerParameters");
451 ocaml_libvirt_domain_set_vcpus (value domv, value nvcpusv)
453 CAMLparam2 (domv, nvcpusv);
454 virDomainPtr dom = Domain_val (domv);
455 virConnectPtr conn = Connect_domv (domv);
456 int r, nvcpus = Int_val (nvcpusv);
458 NONBLOCKING (r = virDomainSetVcpus (dom, nvcpus));
459 CHECK_ERROR (r == -1, conn, "virDomainSetVcpus");
461 CAMLreturn (Val_unit);
465 ocaml_libvirt_domain_pin_vcpu (value domv, value vcpuv, value cpumapv)
467 CAMLparam3 (domv, vcpuv, cpumapv);
468 virDomainPtr dom = Domain_val (domv);
469 virConnectPtr conn = Connect_domv (domv);
470 int maplen = caml_string_length (cpumapv);
471 unsigned char *cpumap = (unsigned char *) String_val (cpumapv);
472 int vcpu = Int_val (vcpuv);
475 NONBLOCKING (r = virDomainPinVcpu (dom, vcpu, cpumap, maplen));
476 CHECK_ERROR (r == -1, conn, "virDomainPinVcpu");
478 CAMLreturn (Val_unit);
482 ocaml_libvirt_domain_get_vcpus (value domv, value maxinfov, value maplenv)
484 CAMLparam3 (domv, maxinfov, maplenv);
485 CAMLlocal5 (rv, infov, strv, v, v2);
486 virDomainPtr dom = Domain_val (domv);
487 virConnectPtr conn = Connect_domv (domv);
488 int maxinfo = Int_val (maxinfov);
489 int maplen = Int_val (maplenv);
490 virVcpuInfo info[maxinfo];
491 unsigned char cpumaps[maxinfo * maplen];
494 memset (info, 0, sizeof (virVcpuInfo) * maxinfo);
495 memset (cpumaps, 0, maxinfo * maplen);
497 NONBLOCKING (r = virDomainGetVcpus (dom, info, maxinfo, cpumaps, maplen));
498 CHECK_ERROR (r == -1, conn, "virDomainPinVcpu");
500 /* Copy the virVcpuInfo structures. */
501 infov = caml_alloc (maxinfo, 0);
502 for (i = 0; i < maxinfo; ++i) {
503 v2 = caml_alloc (4, 0); Store_field (infov, i, v2);
504 Store_field (v2, 0, Val_int (info[i].number));
505 Store_field (v2, 1, Val_int (info[i].state));
506 v = caml_copy_int64 (info[i].cpuTime); Store_field (v2, 2, v);
507 Store_field (v2, 3, Val_int (info[i].cpu));
510 /* Copy the bitmap. */
511 strv = caml_alloc_string (maxinfo * maplen);
512 memcpy (String_val (strv), cpumaps, maxinfo * maplen);
514 /* Allocate the tuple and return it. */
515 rv = caml_alloc_tuple (3);
516 Store_field (rv, 0, Val_int (r)); /* number of CPUs. */
517 Store_field (rv, 1, infov);
518 Store_field (rv, 2, strv);
523 #ifdef HAVE_WEAK_SYMBOLS
524 #ifdef HAVE_VIRDOMAINMIGRATE
525 extern virDomainPtr virDomainMigrate (virDomainPtr domain, virConnectPtr dconn,
526 unsigned long flags, const char *dname,
527 const char *uri, unsigned long bandwidth)
528 __attribute__((weak));
533 ocaml_libvirt_domain_migrate_native (value domv, value dconnv, value flagsv, value optdnamev, value opturiv, value optbandwidthv, value unitv)
535 #ifdef HAVE_VIRDOMAINMIGRATE
536 CAMLparam5 (domv, dconnv, flagsv, optdnamev, opturiv);
537 CAMLxparam2 (optbandwidthv, unitv);
538 CAMLlocal2 (flagv, rv);
539 virDomainPtr dom = Domain_val (domv);
540 virConnectPtr conn = Connect_domv (domv);
541 virConnectPtr dconn = Connect_val (dconnv);
543 const char *dname = Optstring_val (optdnamev);
544 const char *uri = Optstring_val (opturiv);
545 unsigned long bandwidth;
548 /* Iterate over the list of flags. */
549 for (; flagsv != Val_int (0); flagsv = Field (flagsv, 1))
551 flagv = Field (flagsv, 0);
552 if (flagv == Val_int (0))
553 flags |= VIR_MIGRATE_LIVE;
556 if (optbandwidthv == Val_int (0)) /* None */
558 else /* Some bandwidth */
559 bandwidth = Int_val (Field (optbandwidthv, 0));
561 WEAK_SYMBOL_CHECK (virDomainMigrate);
562 NONBLOCKING (r = virDomainMigrate (dom, dconn, flags, dname, uri, bandwidth));
563 CHECK_ERROR (!r, conn, "virDomainMigrate");
565 rv = Val_domain (r, dconnv);
569 #else /* virDomainMigrate not supported */
570 not_supported ("virDomainMigrate");
575 ocaml_libvirt_domain_migrate_bytecode (value *argv, int argn)
577 return ocaml_libvirt_domain_migrate_native (argv[0], argv[1], argv[2],
578 argv[3], argv[4], argv[5],
582 #ifdef HAVE_WEAK_SYMBOLS
583 #ifdef HAVE_VIRDOMAINBLOCKSTATS
584 extern int virDomainBlockStats (virDomainPtr dom,
586 virDomainBlockStatsPtr stats,
588 __attribute__((weak));
593 ocaml_libvirt_domain_block_stats (value domv, value pathv)
595 #if HAVE_VIRDOMAINBLOCKSTATS
596 CAMLparam2 (domv, pathv);
598 virDomainPtr dom = Domain_val (domv);
599 virConnectPtr conn = Connect_domv (domv);
600 char *path = String_val (pathv);
601 struct _virDomainBlockStats stats;
604 WEAK_SYMBOL_CHECK (virDomainBlockStats);
605 NONBLOCKING (r = virDomainBlockStats (dom, path, &stats, sizeof stats));
606 CHECK_ERROR (r == -1, conn, "virDomainBlockStats");
608 rv = caml_alloc (5, 0);
609 v = caml_copy_int64 (stats.rd_req); Store_field (rv, 0, v);
610 v = caml_copy_int64 (stats.rd_bytes); Store_field (rv, 1, v);
611 v = caml_copy_int64 (stats.wr_req); Store_field (rv, 2, v);
612 v = caml_copy_int64 (stats.wr_bytes); Store_field (rv, 3, v);
613 v = caml_copy_int64 (stats.errs); Store_field (rv, 4, v);
617 not_supported ("virDomainBlockStats");
621 #ifdef HAVE_WEAK_SYMBOLS
622 #ifdef HAVE_VIRDOMAININTERFACESTATS
623 extern int virDomainInterfaceStats (virDomainPtr dom,
625 virDomainInterfaceStatsPtr stats,
627 __attribute__((weak));
632 ocaml_libvirt_domain_interface_stats (value domv, value pathv)
634 #if HAVE_VIRDOMAININTERFACESTATS
635 CAMLparam2 (domv, pathv);
637 virDomainPtr dom = Domain_val (domv);
638 virConnectPtr conn = Connect_domv (domv);
639 char *path = String_val (pathv);
640 struct _virDomainInterfaceStats stats;
643 WEAK_SYMBOL_CHECK (virDomainInterfaceStats);
644 NONBLOCKING (r = virDomainInterfaceStats (dom, path, &stats, sizeof stats));
645 CHECK_ERROR (r == -1, conn, "virDomainInterfaceStats");
647 rv = caml_alloc (8, 0);
648 v = caml_copy_int64 (stats.rx_bytes); Store_field (rv, 0, v);
649 v = caml_copy_int64 (stats.rx_packets); Store_field (rv, 1, v);
650 v = caml_copy_int64 (stats.rx_errs); Store_field (rv, 2, v);
651 v = caml_copy_int64 (stats.rx_drop); Store_field (rv, 3, v);
652 v = caml_copy_int64 (stats.tx_bytes); Store_field (rv, 4, v);
653 v = caml_copy_int64 (stats.tx_packets); Store_field (rv, 5, v);
654 v = caml_copy_int64 (stats.tx_errs); Store_field (rv, 6, v);
655 v = caml_copy_int64 (stats.tx_drop); Store_field (rv, 7, v);
659 not_supported ("virDomainInterfaceStats");
663 #ifdef HAVE_WEAK_SYMBOLS
664 #ifdef HAVE_VIRDOMAINBLOCKPEEK
665 extern int virDomainBlockPeek (virDomainPtr domain,
667 unsigned long long offset,
671 __attribute__((weak));
676 ocaml_libvirt_domain_block_peek_native (value domv, value pathv, value offsetv, value sizev, value bufferv, value boffv)
678 #ifdef HAVE_VIRDOMAINBLOCKPEEK
679 CAMLparam5 (domv, pathv, offsetv, sizev, bufferv);
681 virDomainPtr dom = Domain_val (domv);
682 virConnectPtr conn = Connect_domv (domv);
683 const char *path = String_val (pathv);
684 unsigned long long offset = Int64_val (offsetv);
685 size_t size = Int_val (sizev);
686 char *buffer = String_val (bufferv);
687 int boff = Int_val (boffv);
690 /* Check that the return buffer is big enough. */
691 if (caml_string_length (bufferv) < boff + size)
692 caml_failwith ("virDomainBlockPeek: return buffer too short");
694 WEAK_SYMBOL_CHECK (virDomainBlockPeek);
695 /* NB. not NONBLOCKING because buffer might move (XXX) */
696 r = virDomainBlockPeek (dom, path, offset, size, buffer+boff, 0);
697 CHECK_ERROR (r == -1, conn, "virDomainBlockPeek");
699 CAMLreturn (Val_unit);
701 #else /* virDomainBlockPeek not supported */
702 not_supported ("virDomainBlockPeek");
707 ocaml_libvirt_domain_block_peek_bytecode (value *argv, int argn)
709 return ocaml_libvirt_domain_block_peek_native (argv[0], argv[1], argv[2],
710 argv[3], argv[4], argv[5]);
713 #ifdef HAVE_WEAK_SYMBOLS
714 #ifdef HAVE_VIRDOMAINMEMORYPEEK
715 extern int virDomainMemoryPeek (virDomainPtr domain,
716 unsigned long long start,
720 __attribute__((weak));
725 ocaml_libvirt_domain_memory_peek_native (value domv, value flagsv, value offsetv, value sizev, value bufferv, value boffv)
727 #ifdef HAVE_VIRDOMAINMEMORYPEEK
728 CAMLparam5 (domv, flagsv, offsetv, sizev, bufferv);
731 virDomainPtr dom = Domain_val (domv);
732 virConnectPtr conn = Connect_domv (domv);
734 unsigned long long offset = Int64_val (offsetv);
735 size_t size = Int_val (sizev);
736 char *buffer = String_val (bufferv);
737 int boff = Int_val (boffv);
740 /* Check that the return buffer is big enough. */
741 if (caml_string_length (bufferv) < boff + size)
742 caml_failwith ("virDomainMemoryPeek: return buffer too short");
745 for (; flagsv != Val_int (0); flagsv = Field (flagsv, 1))
747 flagv = Field (flagsv, 0);
748 if (flagv == Val_int (0))
749 flags |= VIR_MEMORY_VIRTUAL;
752 WEAK_SYMBOL_CHECK (virDomainMemoryPeek);
753 /* NB. not NONBLOCKING because buffer might move (XXX) */
754 r = virDomainMemoryPeek (dom, offset, size, buffer+boff, flags);
755 CHECK_ERROR (r == -1, conn, "virDomainMemoryPeek");
757 CAMLreturn (Val_unit);
759 #else /* virDomainMemoryPeek not supported */
760 not_supported ("virDomainMemoryPeek");
765 ocaml_libvirt_domain_memory_peek_bytecode (value *argv, int argn)
767 return ocaml_libvirt_domain_memory_peek_native (argv[0], argv[1], argv[2],
768 argv[3], argv[4], argv[5]);
771 #ifdef HAVE_WEAK_SYMBOLS
772 #ifdef HAVE_VIRSTORAGEPOOLGETINFO
773 extern int virStoragePoolGetInfo(virStoragePoolPtr pool, virStoragePoolInfoPtr info)
774 __attribute__((weak));
779 ocaml_libvirt_storage_pool_get_info (value poolv)
781 #if HAVE_VIRSTORAGEPOOLGETINFO
784 virStoragePoolPtr pool = Pool_val (poolv);
785 virConnectPtr conn = Connect_polv (poolv);
786 virStoragePoolInfo info;
789 WEAK_SYMBOL_CHECK (virStoragePoolGetInfo);
790 NONBLOCKING (r = virStoragePoolGetInfo (pool, &info));
791 CHECK_ERROR (r == -1, conn, "virStoragePoolGetInfo");
793 rv = caml_alloc (4, 0);
794 Store_field (rv, 0, Val_int (info.state));
795 v = caml_copy_int64 (info.capacity); Store_field (rv, 1, v);
796 v = caml_copy_int64 (info.allocation); Store_field (rv, 2, v);
797 v = caml_copy_int64 (info.available); Store_field (rv, 3, v);
801 not_supported ("virStoragePoolGetInfo");
805 #ifdef HAVE_WEAK_SYMBOLS
806 #ifdef HAVE_VIRSTORAGEVOLGETINFO
807 extern int virStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info)
808 __attribute__((weak));
813 ocaml_libvirt_storage_vol_get_info (value volv)
815 #if HAVE_VIRSTORAGEVOLGETINFO
818 virStorageVolPtr vol = Volume_val (volv);
819 virConnectPtr conn = Connect_volv (volv);
820 virStorageVolInfo info;
823 WEAK_SYMBOL_CHECK (virStorageVolGetInfo);
824 NONBLOCKING (r = virStorageVolGetInfo (vol, &info));
825 CHECK_ERROR (r == -1, conn, "virStorageVolGetInfo");
827 rv = caml_alloc (3, 0);
828 Store_field (rv, 0, Val_int (info.type));
829 v = caml_copy_int64 (info.capacity); Store_field (rv, 1, v);
830 v = caml_copy_int64 (info.allocation); Store_field (rv, 1, v);
834 not_supported ("virStorageVolGetInfo");
838 #ifdef HAVE_WEAK_SYMBOLS
839 #ifdef HAVE_VIRJOBGETINFO
840 extern int virJobGetInfo(virJobPtr job, virJobInfoPtr info)
841 __attribute__((weak));
846 ocaml_libvirt_job_get_info (value jobv)
848 #if HAVE_VIRJOBGETINFO
851 virJobPtr job = Job_val (jobv);
852 virConnectPtr conn = Connect_jobv (jobv);
856 WEAK_SYMBOL_CHECK (virJobGetInfo);
857 NONBLOCKING (r = virJobGetInfo (job, &info));
858 CHECK_ERROR (r == -1, conn, "virJobGetInfo");
860 rv = caml_alloc (5, 0);
861 Store_field (rv, 0, Val_int (info.type));
862 Store_field (rv, 1, Val_int (info.state));
863 Store_field (rv, 2, Val_int (info.runningTime));
864 Store_field (rv, 3, Val_int (info.remainingTime));
865 Store_field (rv, 4, Val_int (info.percentComplete));
869 not_supported ("virJobGetInfo");
873 /*----------------------------------------------------------------------*/
876 ocaml_libvirt_virterror_get_last_error (value unitv)
880 virErrorPtr err = virGetLastError ();
882 rv = Val_opt (err, (Val_ptr_t) Val_virterror);
888 ocaml_libvirt_virterror_get_last_conn_error (value connv)
892 virConnectPtr conn = Connect_val (connv);
894 rv = Val_opt (conn, (Val_ptr_t) Val_connect);
900 ocaml_libvirt_virterror_reset_last_error (value unitv)
903 virResetLastError ();
904 CAMLreturn (Val_unit);
908 ocaml_libvirt_virterror_reset_last_conn_error (value connv)
911 virConnectPtr conn = Connect_val (connv);
912 virConnResetLastError (conn);
913 CAMLreturn (Val_unit);
916 /*----------------------------------------------------------------------*/
918 /* Initialise the library. */
920 ocaml_libvirt_init (value unit)
926 r = virInitialize ();
927 CHECK_ERROR (r == -1, NULL, "virInitialize");
929 CAMLreturn (Val_unit);