ef674c73ccc701410a4c5ff0190d7e8367482fe5
[virt-top.git] / libvirt / libvirt_c.c
1 /* !!! WARNING WARNING WARNING WARNING WARNING WARNING WARNING !!!
2  *
3  * THIS FILE IS AUTOMATICALLY GENERATED BY 'generator.pl'.
4  *
5  * Any changes you make to this file may be overwritten.
6  */
7
8 /* OCaml bindings for libvirt.
9  * (C) Copyright 2007-2008 Richard W.M. Jones, Red Hat Inc.
10  * http://libvirt.org/
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with this library; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
25  */
26
27 #include "config.h"
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include <libvirt/libvirt.h>
34 #include <libvirt/virterror.h>
35
36 #include <caml/config.h>
37 #include <caml/alloc.h>
38 #include <caml/callback.h>
39 #include <caml/custom.h>
40 #include <caml/fail.h>
41 #include <caml/memory.h>
42 #include <caml/misc.h>
43 #include <caml/mlvalues.h>
44 #include <caml/signals.h>
45
46 #include "libvirt_c_prologue.c"
47
48 #include "libvirt_c_oneoffs.c"
49
50 CAMLprim value
51 ocaml_libvirt_connect_close (value connv)
52 {
53   CAMLparam1 (connv);
54
55   virConnectPtr conn = Connect_val (connv);
56   int r;
57
58   NONBLOCKING (r = virConnectClose (conn));
59   CHECK_ERROR (r == -1, conn, "virConnectClose");
60
61   /* So that we don't double-free in the finalizer: */
62   Connect_val (connv) = NULL;
63
64   CAMLreturn (Val_unit);
65 }
66
67 #ifdef HAVE_WEAK_SYMBOLS
68 #ifdef HAVE_VIRCONNECTGETHOSTNAME
69 extern char *virConnectGetHostname (virConnectPtr conn) __attribute__((weak));
70 #endif
71 #endif
72
73 CAMLprim value
74 ocaml_libvirt_connect_get_hostname (value connv)
75 {
76   CAMLparam1 (connv);
77 #ifndef HAVE_VIRCONNECTGETHOSTNAME
78   /* Symbol virConnectGetHostname not found at compile time. */
79   not_supported ("virConnectGetHostname");
80   /* Suppresses a compiler warning. */
81   (void) caml__frame;
82 #else
83   /* Check that the symbol virConnectGetHostname
84    * is in runtime version of libvirt.
85    */
86   WEAK_SYMBOL_CHECK (virConnectGetHostname);
87
88   CAMLlocal1 (rv);
89   virConnectPtr conn = Connect_val (connv);
90   char *r;
91
92   NONBLOCKING (r = virConnectGetHostname (conn));
93   CHECK_ERROR (!r, conn, "virConnectGetHostname");
94
95   rv = caml_copy_string (r);
96   free (r);
97   CAMLreturn (rv);
98 #endif
99 }
100
101 #ifdef HAVE_WEAK_SYMBOLS
102 #ifdef HAVE_VIRCONNECTGETURI
103 extern char *virConnectGetURI (virConnectPtr conn) __attribute__((weak));
104 #endif
105 #endif
106
107 CAMLprim value
108 ocaml_libvirt_connect_get_uri (value connv)
109 {
110   CAMLparam1 (connv);
111 #ifndef HAVE_VIRCONNECTGETURI
112   /* Symbol virConnectGetURI not found at compile time. */
113   not_supported ("virConnectGetURI");
114   /* Suppresses a compiler warning. */
115   (void) caml__frame;
116 #else
117   /* Check that the symbol virConnectGetURI
118    * is in runtime version of libvirt.
119    */
120   WEAK_SYMBOL_CHECK (virConnectGetURI);
121
122   CAMLlocal1 (rv);
123   virConnectPtr conn = Connect_val (connv);
124   char *r;
125
126   NONBLOCKING (r = virConnectGetURI (conn));
127   CHECK_ERROR (!r, conn, "virConnectGetURI");
128
129   rv = caml_copy_string (r);
130   free (r);
131   CAMLreturn (rv);
132 #endif
133 }
134
135 CAMLprim value
136 ocaml_libvirt_connect_get_type (value connv)
137 {
138   CAMLparam1 (connv);
139
140   CAMLlocal1 (rv);
141   virConnectPtr conn = Connect_val (connv);
142   const char *r;
143
144   NONBLOCKING (r = virConnectGetType (conn));
145   CHECK_ERROR (!r, conn, "virConnectGetType");
146
147   rv = caml_copy_string (r);
148   CAMLreturn (rv);
149 }
150
151 CAMLprim value
152 ocaml_libvirt_connect_num_of_domains (value connv)
153 {
154   CAMLparam1 (connv);
155
156   virConnectPtr conn = Connect_val (connv);
157   int r;
158
159   NONBLOCKING (r = virConnectNumOfDomains (conn));
160   CHECK_ERROR (r == -1, conn, "virConnectNumOfDomains");
161
162   CAMLreturn (Val_int (r));
163 }
164
165 CAMLprim value
166 ocaml_libvirt_connect_list_domains (value connv, value iv)
167 {
168   CAMLparam2 (connv, iv);
169
170   CAMLlocal1 (rv);
171   virConnectPtr conn = Connect_val (connv);
172   int i = Int_val (iv);
173   int ids[i], r;
174
175   NONBLOCKING (r = virConnectListDomains (conn, ids, i));
176   CHECK_ERROR (r == -1, conn, "virConnectListDomains");
177
178   rv = caml_alloc (r, 0);
179   for (i = 0; i < r; ++i)
180     Store_field (rv, i, Val_int (ids[i]));
181
182   CAMLreturn (rv);
183 }
184
185 CAMLprim value
186 ocaml_libvirt_connect_num_of_defined_domains (value connv)
187 {
188   CAMLparam1 (connv);
189
190   virConnectPtr conn = Connect_val (connv);
191   int r;
192
193   NONBLOCKING (r = virConnectNumOfDefinedDomains (conn));
194   CHECK_ERROR (r == -1, conn, "virConnectNumOfDefinedDomains");
195
196   CAMLreturn (Val_int (r));
197 }
198
199 CAMLprim value
200 ocaml_libvirt_connect_list_defined_domains (value connv, value iv)
201 {
202   CAMLparam2 (connv, iv);
203
204   CAMLlocal2 (rv, strv);
205   virConnectPtr conn = Connect_val (connv);
206   int i = Int_val (iv);
207   char *names[i];
208   int r;
209
210   NONBLOCKING (r = virConnectListDefinedDomains (conn, names, i));
211   CHECK_ERROR (r == -1, conn, "virConnectListDefinedDomains");
212
213   rv = caml_alloc (r, 0);
214   for (i = 0; i < r; ++i) {
215     strv = caml_copy_string (names[i]);
216     Store_field (rv, i, strv);
217     free (names[i]);
218   }
219
220   CAMLreturn (rv);
221 }
222
223 CAMLprim value
224 ocaml_libvirt_connect_num_of_networks (value connv)
225 {
226   CAMLparam1 (connv);
227
228   virConnectPtr conn = Connect_val (connv);
229   int r;
230
231   NONBLOCKING (r = virConnectNumOfNetworks (conn));
232   CHECK_ERROR (r == -1, conn, "virConnectNumOfNetworks");
233
234   CAMLreturn (Val_int (r));
235 }
236
237 CAMLprim value
238 ocaml_libvirt_connect_list_networks (value connv, value iv)
239 {
240   CAMLparam2 (connv, iv);
241
242   CAMLlocal2 (rv, strv);
243   virConnectPtr conn = Connect_val (connv);
244   int i = Int_val (iv);
245   char *names[i];
246   int r;
247
248   NONBLOCKING (r = virConnectListNetworks (conn, names, i));
249   CHECK_ERROR (r == -1, conn, "virConnectListNetworks");
250
251   rv = caml_alloc (r, 0);
252   for (i = 0; i < r; ++i) {
253     strv = caml_copy_string (names[i]);
254     Store_field (rv, i, strv);
255     free (names[i]);
256   }
257
258   CAMLreturn (rv);
259 }
260
261 CAMLprim value
262 ocaml_libvirt_connect_num_of_defined_networks (value connv)
263 {
264   CAMLparam1 (connv);
265
266   virConnectPtr conn = Connect_val (connv);
267   int r;
268
269   NONBLOCKING (r = virConnectNumOfDefinedNetworks (conn));
270   CHECK_ERROR (r == -1, conn, "virConnectNumOfDefinedNetworks");
271
272   CAMLreturn (Val_int (r));
273 }
274
275 CAMLprim value
276 ocaml_libvirt_connect_list_defined_networks (value connv, value iv)
277 {
278   CAMLparam2 (connv, iv);
279
280   CAMLlocal2 (rv, strv);
281   virConnectPtr conn = Connect_val (connv);
282   int i = Int_val (iv);
283   char *names[i];
284   int r;
285
286   NONBLOCKING (r = virConnectListDefinedNetworks (conn, names, i));
287   CHECK_ERROR (r == -1, conn, "virConnectListDefinedNetworks");
288
289   rv = caml_alloc (r, 0);
290   for (i = 0; i < r; ++i) {
291     strv = caml_copy_string (names[i]);
292     Store_field (rv, i, strv);
293     free (names[i]);
294   }
295
296   CAMLreturn (rv);
297 }
298
299 #ifdef HAVE_WEAK_SYMBOLS
300 #ifdef HAVE_VIRCONNECTNUMOFSTORAGEPOOLS
301 extern int virConnectNumOfStoragePools (virConnectPtr conn) __attribute__((weak));
302 #endif
303 #endif
304
305 CAMLprim value
306 ocaml_libvirt_connect_num_of_storage_pools (value connv)
307 {
308   CAMLparam1 (connv);
309 #ifndef HAVE_VIRCONNECTNUMOFSTORAGEPOOLS
310   /* Symbol virConnectNumOfStoragePools not found at compile time. */
311   not_supported ("virConnectNumOfStoragePools");
312   /* Suppresses a compiler warning. */
313   (void) caml__frame;
314 #else
315   /* Check that the symbol virConnectNumOfStoragePools
316    * is in runtime version of libvirt.
317    */
318   WEAK_SYMBOL_CHECK (virConnectNumOfStoragePools);
319
320   virConnectPtr conn = Connect_val (connv);
321   int r;
322
323   NONBLOCKING (r = virConnectNumOfStoragePools (conn));
324   CHECK_ERROR (r == -1, conn, "virConnectNumOfStoragePools");
325
326   CAMLreturn (Val_int (r));
327 #endif
328 }
329
330 #ifdef HAVE_WEAK_SYMBOLS
331 #ifdef HAVE_VIRCONNECTLISTSTORAGEPOOLS
332 extern int virConnectListStoragePools (virConnectPtr conn, char **const names, int maxnames) __attribute__((weak));
333 #endif
334 #endif
335
336 CAMLprim value
337 ocaml_libvirt_connect_list_storage_pools (value connv, value iv)
338 {
339   CAMLparam2 (connv, iv);
340 #ifndef HAVE_VIRCONNECTLISTSTORAGEPOOLS
341   /* Symbol virConnectListStoragePools not found at compile time. */
342   not_supported ("virConnectListStoragePools");
343   /* Suppresses a compiler warning. */
344   (void) caml__frame;
345 #else
346   /* Check that the symbol virConnectListStoragePools
347    * is in runtime version of libvirt.
348    */
349   WEAK_SYMBOL_CHECK (virConnectListStoragePools);
350
351   CAMLlocal2 (rv, strv);
352   virConnectPtr conn = Connect_val (connv);
353   int i = Int_val (iv);
354   char *names[i];
355   int r;
356
357   NONBLOCKING (r = virConnectListStoragePools (conn, names, i));
358   CHECK_ERROR (r == -1, conn, "virConnectListStoragePools");
359
360   rv = caml_alloc (r, 0);
361   for (i = 0; i < r; ++i) {
362     strv = caml_copy_string (names[i]);
363     Store_field (rv, i, strv);
364     free (names[i]);
365   }
366
367   CAMLreturn (rv);
368 #endif
369 }
370
371 #ifdef HAVE_WEAK_SYMBOLS
372 #ifdef HAVE_VIRCONNECTNUMOFDEFINEDSTORAGEPOOLS
373 extern int virConnectNumOfDefinedStoragePools (virConnectPtr conn) __attribute__((weak));
374 #endif
375 #endif
376
377 CAMLprim value
378 ocaml_libvirt_connect_num_of_defined_storage_pools (value connv)
379 {
380   CAMLparam1 (connv);
381 #ifndef HAVE_VIRCONNECTNUMOFDEFINEDSTORAGEPOOLS
382   /* Symbol virConnectNumOfDefinedStoragePools not found at compile time. */
383   not_supported ("virConnectNumOfDefinedStoragePools");
384   /* Suppresses a compiler warning. */
385   (void) caml__frame;
386 #else
387   /* Check that the symbol virConnectNumOfDefinedStoragePools
388    * is in runtime version of libvirt.
389    */
390   WEAK_SYMBOL_CHECK (virConnectNumOfDefinedStoragePools);
391
392   virConnectPtr conn = Connect_val (connv);
393   int r;
394
395   NONBLOCKING (r = virConnectNumOfDefinedStoragePools (conn));
396   CHECK_ERROR (r == -1, conn, "virConnectNumOfDefinedStoragePools");
397
398   CAMLreturn (Val_int (r));
399 #endif
400 }
401
402 #ifdef HAVE_WEAK_SYMBOLS
403 #ifdef HAVE_VIRCONNECTLISTDEFINEDSTORAGEPOOLS
404 extern int virConnectListDefinedStoragePools (virConnectPtr conn, char **const names, int maxnames) __attribute__((weak));
405 #endif
406 #endif
407
408 CAMLprim value
409 ocaml_libvirt_connect_list_defined_storage_pools (value connv, value iv)
410 {
411   CAMLparam2 (connv, iv);
412 #ifndef HAVE_VIRCONNECTLISTDEFINEDSTORAGEPOOLS
413   /* Symbol virConnectListDefinedStoragePools not found at compile time. */
414   not_supported ("virConnectListDefinedStoragePools");
415   /* Suppresses a compiler warning. */
416   (void) caml__frame;
417 #else
418   /* Check that the symbol virConnectListDefinedStoragePools
419    * is in runtime version of libvirt.
420    */
421   WEAK_SYMBOL_CHECK (virConnectListDefinedStoragePools);
422
423   CAMLlocal2 (rv, strv);
424   virConnectPtr conn = Connect_val (connv);
425   int i = Int_val (iv);
426   char *names[i];
427   int r;
428
429   NONBLOCKING (r = virConnectListDefinedStoragePools (conn, names, i));
430   CHECK_ERROR (r == -1, conn, "virConnectListDefinedStoragePools");
431
432   rv = caml_alloc (r, 0);
433   for (i = 0; i < r; ++i) {
434     strv = caml_copy_string (names[i]);
435     Store_field (rv, i, strv);
436     free (names[i]);
437   }
438
439   CAMLreturn (rv);
440 #endif
441 }
442
443 CAMLprim value
444 ocaml_libvirt_connect_get_capabilities (value connv)
445 {
446   CAMLparam1 (connv);
447
448   CAMLlocal1 (rv);
449   virConnectPtr conn = Connect_val (connv);
450   char *r;
451
452   NONBLOCKING (r = virConnectGetCapabilities (conn));
453   CHECK_ERROR (!r, conn, "virConnectGetCapabilities");
454
455   rv = caml_copy_string (r);
456   free (r);
457   CAMLreturn (rv);
458 }
459
460 CAMLprim value
461 ocaml_libvirt_domain_create_linux (value connv, value strv)
462 {
463   CAMLparam2 (connv, strv);
464
465   CAMLlocal1 (rv);
466   virConnectPtr conn = Connect_val (connv);
467   char *str = String_val (strv);
468   virDomainPtr r;
469
470   NONBLOCKING (r = virDomainCreateLinux (conn, str, 0));
471   CHECK_ERROR (!r, conn, "virDomainCreateLinux");
472
473   rv = Val_domain (r, connv);
474
475   CAMLreturn (rv);
476 }
477
478 CAMLprim value
479 ocaml_libvirt_domain_create_linux_job (value connv, value strv)
480 {
481   CAMLparam2 (connv, strv);
482
483   CAMLlocal1 (rv);
484   virConnectPtr conn = Connect_val (connv);
485   char *str = String_val (strv);
486   virJobPtr r;
487
488   NONBLOCKING (r = virDomainCreateLinuxJob (conn, str, 0));
489   CHECK_ERROR (!r, conn, "virDomainCreateLinuxJob");
490
491   rv = Val_job (r, connv);
492
493   CAMLreturn (rv);
494 }
495
496 CAMLprim value
497 ocaml_libvirt_domain_free (value domv)
498 {
499   CAMLparam1 (domv);
500
501   virDomainPtr dom = Domain_val (domv);
502   virConnectPtr conn = Connect_domv (domv);
503   int r;
504
505   NONBLOCKING (r = virDomainFree (dom));
506   CHECK_ERROR (r == -1, conn, "virDomainFree");
507
508   /* So that we don't double-free in the finalizer: */
509   Domain_val (domv) = NULL;
510
511   CAMLreturn (Val_unit);
512 }
513
514 CAMLprim value
515 ocaml_libvirt_domain_destroy (value domv)
516 {
517   CAMLparam1 (domv);
518
519   virDomainPtr dom = Domain_val (domv);
520   virConnectPtr conn = Connect_domv (domv);
521   int r;
522
523   NONBLOCKING (r = virDomainDestroy (dom));
524   CHECK_ERROR (r == -1, conn, "virDomainDestroy");
525
526   /* So that we don't double-free in the finalizer: */
527   Domain_val (domv) = NULL;
528
529   CAMLreturn (Val_unit);
530 }
531
532 CAMLprim value
533 ocaml_libvirt_domain_lookup_by_name (value connv, value strv)
534 {
535   CAMLparam2 (connv, strv);
536
537   CAMLlocal1 (rv);
538   virConnectPtr conn = Connect_val (connv);
539   char *str = String_val (strv);
540   virDomainPtr r;
541
542   NONBLOCKING (r = virDomainLookupByName (conn, str));
543   CHECK_ERROR (!r, conn, "virDomainLookupByName");
544
545   rv = Val_domain (r, connv);
546
547   CAMLreturn (rv);
548 }
549
550 CAMLprim value
551 ocaml_libvirt_domain_lookup_by_id (value connv, value iv)
552 {
553   CAMLparam2 (connv, iv);
554
555   CAMLlocal1 (rv);
556   virConnectPtr conn = Connect_val (connv);
557   int i = Int_val (iv);
558   virDomainPtr r;
559
560   NONBLOCKING (r = virDomainLookupByID (conn, i));
561   CHECK_ERROR (!r, conn, "virDomainLookupByID");
562
563   rv = Val_domain (r, connv);
564
565   CAMLreturn (rv);
566 }
567
568 CAMLprim value
569 ocaml_libvirt_domain_lookup_by_uuid (value connv, value uuidv)
570 {
571   CAMLparam2 (connv, uuidv);
572
573   CAMLlocal1 (rv);
574   virConnectPtr conn = Connect_val (connv);
575   unsigned char *uuid = (unsigned char *) String_val (uuidv);
576   virDomainPtr r;
577
578   NONBLOCKING (r = virDomainLookupByUUID (conn, uuid));
579   CHECK_ERROR (!r, conn, "virDomainLookupByUUID");
580
581   rv = Val_domain (r, connv);
582
583   CAMLreturn (rv);
584 }
585
586 CAMLprim value
587 ocaml_libvirt_domain_lookup_by_uuid_string (value connv, value strv)
588 {
589   CAMLparam2 (connv, strv);
590
591   CAMLlocal1 (rv);
592   virConnectPtr conn = Connect_val (connv);
593   char *str = String_val (strv);
594   virDomainPtr r;
595
596   NONBLOCKING (r = virDomainLookupByUUIDString (conn, str));
597   CHECK_ERROR (!r, conn, "virDomainLookupByUUIDString");
598
599   rv = Val_domain (r, connv);
600
601   CAMLreturn (rv);
602 }
603
604 CAMLprim value
605 ocaml_libvirt_domain_get_name (value domv)
606 {
607   CAMLparam1 (domv);
608
609   CAMLlocal1 (rv);
610   virDomainPtr dom = Domain_val (domv);
611   virConnectPtr conn = Connect_domv (domv);
612   const char *r;
613
614   NONBLOCKING (r = virDomainGetName (dom));
615   CHECK_ERROR (!r, conn, "virDomainGetName");
616
617   rv = caml_copy_string (r);
618   CAMLreturn (rv);
619 }
620
621 CAMLprim value
622 ocaml_libvirt_domain_get_os_type (value domv)
623 {
624   CAMLparam1 (domv);
625
626   CAMLlocal1 (rv);
627   virDomainPtr dom = Domain_val (domv);
628   virConnectPtr conn = Connect_domv (domv);
629   char *r;
630
631   NONBLOCKING (r = virDomainGetOSType (dom));
632   CHECK_ERROR (!r, conn, "virDomainGetOSType");
633
634   rv = caml_copy_string (r);
635   free (r);
636   CAMLreturn (rv);
637 }
638
639 CAMLprim value
640 ocaml_libvirt_domain_get_xml_desc (value domv)
641 {
642   CAMLparam1 (domv);
643
644   CAMLlocal1 (rv);
645   virDomainPtr dom = Domain_val (domv);
646   virConnectPtr conn = Connect_domv (domv);
647   char *r;
648
649   NONBLOCKING (r = virDomainGetXMLDesc (dom, 0));
650   CHECK_ERROR (!r, conn, "virDomainGetXMLDesc");
651
652   rv = caml_copy_string (r);
653   free (r);
654   CAMLreturn (rv);
655 }
656
657 CAMLprim value
658 ocaml_libvirt_domain_get_uuid (value domv)
659 {
660   CAMLparam1 (domv);
661
662   CAMLlocal1 (rv);
663   virDomainPtr dom = Domain_val (domv);
664   virConnectPtr conn = Connect_domv (domv);
665   unsigned char uuid[VIR_UUID_BUFLEN];
666   int r;
667
668   NONBLOCKING (r = virDomainGetUUID (dom, uuid));
669   CHECK_ERROR (r == -1, conn, "virDomainGetUUID");
670
671   rv = caml_copy_string ((char *) uuid);
672   CAMLreturn (rv);
673 }
674
675 CAMLprim value
676 ocaml_libvirt_domain_get_uuid_string (value domv)
677 {
678   CAMLparam1 (domv);
679
680   CAMLlocal1 (rv);
681   virDomainPtr dom = Domain_val (domv);
682   virConnectPtr conn = Connect_domv (domv);
683   char uuid[VIR_UUID_STRING_BUFLEN];
684   int r;
685
686   NONBLOCKING (r = virDomainGetUUIDString (dom, uuid));
687   CHECK_ERROR (r == -1, conn, "virDomainGetUUIDString");
688
689   rv = caml_copy_string (uuid);
690   CAMLreturn (rv);
691 }
692
693 CAMLprim value
694 ocaml_libvirt_domain_get_max_vcpus (value domv)
695 {
696   CAMLparam1 (domv);
697
698   virDomainPtr dom = Domain_val (domv);
699   virConnectPtr conn = Connect_domv (domv);
700   int r;
701
702   NONBLOCKING (r = virDomainGetMaxVcpus (dom));
703   CHECK_ERROR (r == -1, conn, "virDomainGetMaxVcpus");
704
705   CAMLreturn (Val_int (r));
706 }
707
708 CAMLprim value
709 ocaml_libvirt_domain_save (value domv, value strv)
710 {
711   CAMLparam2 (domv, strv);
712
713   CAMLlocal1 (rv);
714   virDomainPtr dom = Domain_val (domv);
715   virConnectPtr conn = Connect_domv (domv);
716   char *str = String_val (strv);
717   int r;
718
719   NONBLOCKING (r = virDomainSave (dom, str));
720   CHECK_ERROR (r == -1, conn, "virDomainSave");
721
722   CAMLreturn (Val_unit);
723 }
724
725 CAMLprim value
726 ocaml_libvirt_domain_save_job (value domv, value strv)
727 {
728   CAMLparam2 (domv, strv);
729
730   CAMLlocal2 (rv, connv);
731   virDomainPtr dom = Domain_val (domv);
732   virConnectPtr conn = Connect_domv (domv);
733   char *str = String_val (strv);
734   virJobPtr r;
735
736   NONBLOCKING (r = virDomainSaveJob (dom, str));
737   CHECK_ERROR (!r, conn, "virDomainSaveJob");
738
739   connv = Field (domv, 1);
740   rv = Val_job (r, connv);
741
742   CAMLreturn (rv);
743 }
744
745 CAMLprim value
746 ocaml_libvirt_domain_restore (value connv, value strv)
747 {
748   CAMLparam2 (connv, strv);
749
750   CAMLlocal1 (rv);
751   virConnectPtr conn = Connect_val (connv);
752   char *str = String_val (strv);
753   int r;
754
755   NONBLOCKING (r = virDomainRestore (conn, str));
756   CHECK_ERROR (r == -1, conn, "virDomainRestore");
757
758   CAMLreturn (Val_unit);
759 }
760
761 CAMLprim value
762 ocaml_libvirt_domain_restore_job (value connv, value strv)
763 {
764   CAMLparam2 (connv, strv);
765
766   CAMLlocal1 (rv);
767   virConnectPtr conn = Connect_val (connv);
768   char *str = String_val (strv);
769   virJobPtr r;
770
771   NONBLOCKING (r = virDomainRestoreJob (conn, str));
772   CHECK_ERROR (!r, conn, "virDomainRestoreJob");
773
774   rv = Val_job (r, connv);
775
776   CAMLreturn (rv);
777 }
778
779 CAMLprim value
780 ocaml_libvirt_domain_core_dump (value domv, value strv)
781 {
782   CAMLparam2 (domv, strv);
783
784   CAMLlocal1 (rv);
785   virDomainPtr dom = Domain_val (domv);
786   virConnectPtr conn = Connect_domv (domv);
787   char *str = String_val (strv);
788   int r;
789
790   NONBLOCKING (r = virDomainCoreDump (dom, str, 0));
791   CHECK_ERROR (!r, conn, "virDomainCoreDump");
792
793   CAMLreturn (Val_unit);
794 }
795
796 CAMLprim value
797 ocaml_libvirt_domain_core_dump_job (value domv, value strv)
798 {
799   CAMLparam2 (domv, strv);
800
801   CAMLlocal2 (rv, connv);
802   virDomainPtr dom = Domain_val (domv);
803   virConnectPtr conn = Connect_domv (domv);
804   char *str = String_val (strv);
805   virJobPtr r;
806
807   NONBLOCKING (r = virDomainCoreDumpJob (dom, str, 0));
808   CHECK_ERROR (!r, conn, "virDomainCoreDumpJob");
809
810   connv = Field (domv, 1);
811   rv = Val_job (r, connv);
812
813   CAMLreturn (rv);
814 }
815
816 CAMLprim value
817 ocaml_libvirt_domain_suspend (value domv)
818 {
819   CAMLparam1 (domv);
820
821   virDomainPtr dom = Domain_val (domv);
822   virConnectPtr conn = Connect_domv (domv);
823   int r;
824
825   NONBLOCKING (r = virDomainSuspend (dom));
826   CHECK_ERROR (r == -1, conn, "virDomainSuspend");
827
828   CAMLreturn (Val_unit);
829 }
830
831 CAMLprim value
832 ocaml_libvirt_domain_resume (value domv)
833 {
834   CAMLparam1 (domv);
835
836   virDomainPtr dom = Domain_val (domv);
837   virConnectPtr conn = Connect_domv (domv);
838   int r;
839
840   NONBLOCKING (r = virDomainResume (dom));
841   CHECK_ERROR (r == -1, conn, "virDomainResume");
842
843   CAMLreturn (Val_unit);
844 }
845
846 CAMLprim value
847 ocaml_libvirt_domain_shutdown (value domv)
848 {
849   CAMLparam1 (domv);
850
851   virDomainPtr dom = Domain_val (domv);
852   virConnectPtr conn = Connect_domv (domv);
853   int r;
854
855   NONBLOCKING (r = virDomainShutdown (dom));
856   CHECK_ERROR (r == -1, conn, "virDomainShutdown");
857
858   CAMLreturn (Val_unit);
859 }
860
861 CAMLprim value
862 ocaml_libvirt_domain_reboot (value domv)
863 {
864   CAMLparam1 (domv);
865
866   virDomainPtr dom = Domain_val (domv);
867   virConnectPtr conn = Connect_domv (domv);
868   int r;
869
870   NONBLOCKING (r = virDomainReboot (dom, 0));
871   CHECK_ERROR (r == -1, conn, "virDomainReboot");
872
873   CAMLreturn (Val_unit);
874 }
875
876 CAMLprim value
877 ocaml_libvirt_domain_define_xml (value connv, value strv)
878 {
879   CAMLparam2 (connv, strv);
880
881   CAMLlocal1 (rv);
882   virConnectPtr conn = Connect_val (connv);
883   char *str = String_val (strv);
884   virDomainPtr r;
885
886   NONBLOCKING (r = virDomainDefineXML (conn, str));
887   CHECK_ERROR (!r, conn, "virDomainDefineXML");
888
889   rv = Val_domain (r, connv);
890
891   CAMLreturn (rv);
892 }
893
894 CAMLprim value
895 ocaml_libvirt_domain_undefine (value domv)
896 {
897   CAMLparam1 (domv);
898
899   virDomainPtr dom = Domain_val (domv);
900   virConnectPtr conn = Connect_domv (domv);
901   int r;
902
903   NONBLOCKING (r = virDomainUndefine (dom));
904   CHECK_ERROR (r == -1, conn, "virDomainUndefine");
905
906   CAMLreturn (Val_unit);
907 }
908
909 CAMLprim value
910 ocaml_libvirt_domain_create (value domv)
911 {
912   CAMLparam1 (domv);
913
914   virDomainPtr dom = Domain_val (domv);
915   virConnectPtr conn = Connect_domv (domv);
916   int r;
917
918   NONBLOCKING (r = virDomainCreate (dom));
919   CHECK_ERROR (r == -1, conn, "virDomainCreate");
920
921   CAMLreturn (Val_unit);
922 }
923
924 CAMLprim value
925 ocaml_libvirt_domain_create_job (value domv)
926 {
927   CAMLparam1 (domv);
928
929   CAMLlocal2 (rv, connv);
930   virDomainPtr dom = Domain_val (domv);
931   virConnectPtr conn = Connect_domv (domv);
932   virJobPtr r;
933
934   NONBLOCKING (r = virDomainCreateJob (dom, 0));
935   CHECK_ERROR (!r, conn, "virDomainCreateJob");
936
937   connv = Field (domv, 1);
938   rv = Val_job (r, connv);
939
940   CAMLreturn (rv);
941 }
942
943 CAMLprim value
944 ocaml_libvirt_domain_attach_device (value domv, value strv)
945 {
946   CAMLparam2 (domv, strv);
947
948   CAMLlocal1 (rv);
949   virDomainPtr dom = Domain_val (domv);
950   virConnectPtr conn = Connect_domv (domv);
951   char *str = String_val (strv);
952   int r;
953
954   NONBLOCKING (r = virDomainAttachDevice (dom, str));
955   CHECK_ERROR (r == -1, conn, "virDomainAttachDevice");
956
957   CAMLreturn (Val_unit);
958 }
959
960 CAMLprim value
961 ocaml_libvirt_domain_detach_device (value domv, value strv)
962 {
963   CAMLparam2 (domv, strv);
964
965   CAMLlocal1 (rv);
966   virDomainPtr dom = Domain_val (domv);
967   virConnectPtr conn = Connect_domv (domv);
968   char *str = String_val (strv);
969   int r;
970
971   NONBLOCKING (r = virDomainDetachDevice (dom, str));
972   CHECK_ERROR (r == -1, conn, "virDomainDetachDevice");
973
974   CAMLreturn (Val_unit);
975 }
976
977 CAMLprim value
978 ocaml_libvirt_domain_get_autostart (value domv)
979 {
980   CAMLparam1 (domv);
981
982   virDomainPtr dom = Domain_val (domv);
983   virConnectPtr conn = Connect_domv (domv);
984   int r, b;
985
986   NONBLOCKING (r = virDomainGetAutostart (dom, &b));
987   CHECK_ERROR (r == -1, conn, "virDomainGetAutostart");
988
989   CAMLreturn (b ? Val_true : Val_false);
990 }
991
992 CAMLprim value
993 ocaml_libvirt_domain_set_autostart (value domv, value bv)
994 {
995   CAMLparam2 (domv, bv);
996
997   virDomainPtr dom = Domain_val (domv);
998   virConnectPtr conn = Connect_domv (domv);
999   int r, b;
1000
1001   b = bv == Val_true ? 1 : 0;
1002
1003   NONBLOCKING (r = virDomainSetAutostart (dom, b));
1004   CHECK_ERROR (r == -1, conn, "virDomainSetAutostart");
1005
1006   CAMLreturn (Val_unit);
1007 }
1008
1009 CAMLprim value
1010 ocaml_libvirt_network_free (value netv)
1011 {
1012   CAMLparam1 (netv);
1013
1014   virNetworkPtr net = Network_val (netv);
1015   virConnectPtr conn = Connect_netv (netv);
1016   int r;
1017
1018   NONBLOCKING (r = virNetworkFree (net));
1019   CHECK_ERROR (r == -1, conn, "virNetworkFree");
1020
1021   /* So that we don't double-free in the finalizer: */
1022   Network_val (netv) = NULL;
1023
1024   CAMLreturn (Val_unit);
1025 }
1026
1027 CAMLprim value
1028 ocaml_libvirt_network_destroy (value netv)
1029 {
1030   CAMLparam1 (netv);
1031
1032   virNetworkPtr net = Network_val (netv);
1033   virConnectPtr conn = Connect_netv (netv);
1034   int r;
1035
1036   NONBLOCKING (r = virNetworkDestroy (net));
1037   CHECK_ERROR (r == -1, conn, "virNetworkDestroy");
1038
1039   /* So that we don't double-free in the finalizer: */
1040   Network_val (netv) = NULL;
1041
1042   CAMLreturn (Val_unit);
1043 }
1044
1045 CAMLprim value
1046 ocaml_libvirt_network_lookup_by_name (value connv, value strv)
1047 {
1048   CAMLparam2 (connv, strv);
1049
1050   CAMLlocal1 (rv);
1051   virConnectPtr conn = Connect_val (connv);
1052   char *str = String_val (strv);
1053   virNetworkPtr r;
1054
1055   NONBLOCKING (r = virNetworkLookupByName (conn, str));
1056   CHECK_ERROR (!r, conn, "virNetworkLookupByName");
1057
1058   rv = Val_network (r, connv);
1059
1060   CAMLreturn (rv);
1061 }
1062
1063 CAMLprim value
1064 ocaml_libvirt_network_lookup_by_uuid (value connv, value uuidv)
1065 {
1066   CAMLparam2 (connv, uuidv);
1067
1068   CAMLlocal1 (rv);
1069   virConnectPtr conn = Connect_val (connv);
1070   unsigned char *uuid = (unsigned char *) String_val (uuidv);
1071   virNetworkPtr r;
1072
1073   NONBLOCKING (r = virNetworkLookupByUUID (conn, uuid));
1074   CHECK_ERROR (!r, conn, "virNetworkLookupByUUID");
1075
1076   rv = Val_network (r, connv);
1077
1078   CAMLreturn (rv);
1079 }
1080
1081 CAMLprim value
1082 ocaml_libvirt_network_lookup_by_uuid_string (value connv, value strv)
1083 {
1084   CAMLparam2 (connv, strv);
1085
1086   CAMLlocal1 (rv);
1087   virConnectPtr conn = Connect_val (connv);
1088   char *str = String_val (strv);
1089   virNetworkPtr r;
1090
1091   NONBLOCKING (r = virNetworkLookupByUUIDString (conn, str));
1092   CHECK_ERROR (!r, conn, "virNetworkLookupByUUIDString");
1093
1094   rv = Val_network (r, connv);
1095
1096   CAMLreturn (rv);
1097 }
1098
1099 CAMLprim value
1100 ocaml_libvirt_network_get_name (value netv)
1101 {
1102   CAMLparam1 (netv);
1103
1104   CAMLlocal1 (rv);
1105   virNetworkPtr net = Network_val (netv);
1106   virConnectPtr conn = Connect_netv (netv);
1107   const char *r;
1108
1109   NONBLOCKING (r = virNetworkGetName (net));
1110   CHECK_ERROR (!r, conn, "virNetworkGetName");
1111
1112   rv = caml_copy_string (r);
1113   CAMLreturn (rv);
1114 }
1115
1116 CAMLprim value
1117 ocaml_libvirt_network_get_xml_desc (value netv)
1118 {
1119   CAMLparam1 (netv);
1120
1121   CAMLlocal1 (rv);
1122   virNetworkPtr net = Network_val (netv);
1123   virConnectPtr conn = Connect_netv (netv);
1124   char *r;
1125
1126   NONBLOCKING (r = virNetworkGetXMLDesc (net, 0));
1127   CHECK_ERROR (!r, conn, "virNetworkGetXMLDesc");
1128
1129   rv = caml_copy_string (r);
1130   free (r);
1131   CAMLreturn (rv);
1132 }
1133
1134 CAMLprim value
1135 ocaml_libvirt_network_get_bridge_name (value netv)
1136 {
1137   CAMLparam1 (netv);
1138
1139   CAMLlocal1 (rv);
1140   virNetworkPtr net = Network_val (netv);
1141   virConnectPtr conn = Connect_netv (netv);
1142   char *r;
1143
1144   NONBLOCKING (r = virNetworkGetBridgeName (net));
1145   CHECK_ERROR (!r, conn, "virNetworkGetBridgeName");
1146
1147   rv = caml_copy_string (r);
1148   free (r);
1149   CAMLreturn (rv);
1150 }
1151
1152 CAMLprim value
1153 ocaml_libvirt_network_get_uuid (value netv)
1154 {
1155   CAMLparam1 (netv);
1156
1157   CAMLlocal1 (rv);
1158   virNetworkPtr net = Network_val (netv);
1159   virConnectPtr conn = Connect_netv (netv);
1160   unsigned char uuid[VIR_UUID_BUFLEN];
1161   int r;
1162
1163   NONBLOCKING (r = virNetworkGetUUID (net, uuid));
1164   CHECK_ERROR (r == -1, conn, "virNetworkGetUUID");
1165
1166   rv = caml_copy_string ((char *) uuid);
1167   CAMLreturn (rv);
1168 }
1169
1170 CAMLprim value
1171 ocaml_libvirt_network_get_uuid_string (value netv)
1172 {
1173   CAMLparam1 (netv);
1174
1175   CAMLlocal1 (rv);
1176   virNetworkPtr net = Network_val (netv);
1177   virConnectPtr conn = Connect_netv (netv);
1178   char uuid[VIR_UUID_STRING_BUFLEN];
1179   int r;
1180
1181   NONBLOCKING (r = virNetworkGetUUIDString (net, uuid));
1182   CHECK_ERROR (r == -1, conn, "virNetworkGetUUIDString");
1183
1184   rv = caml_copy_string (uuid);
1185   CAMLreturn (rv);
1186 }
1187
1188 CAMLprim value
1189 ocaml_libvirt_network_undefine (value netv)
1190 {
1191   CAMLparam1 (netv);
1192
1193   virNetworkPtr net = Network_val (netv);
1194   virConnectPtr conn = Connect_netv (netv);
1195   int r;
1196
1197   NONBLOCKING (r = virNetworkUndefine (net));
1198   CHECK_ERROR (r == -1, conn, "virNetworkUndefine");
1199
1200   CAMLreturn (Val_unit);
1201 }
1202
1203 CAMLprim value
1204 ocaml_libvirt_network_create_xml (value connv, value strv)
1205 {
1206   CAMLparam2 (connv, strv);
1207
1208   CAMLlocal1 (rv);
1209   virConnectPtr conn = Connect_val (connv);
1210   char *str = String_val (strv);
1211   virNetworkPtr r;
1212
1213   NONBLOCKING (r = virNetworkCreateXML (conn, str));
1214   CHECK_ERROR (!r, conn, "virNetworkCreateXML");
1215
1216   rv = Val_network (r, connv);
1217
1218   CAMLreturn (rv);
1219 }
1220
1221 CAMLprim value
1222 ocaml_libvirt_network_create_xml_job (value connv, value strv)
1223 {
1224   CAMLparam2 (connv, strv);
1225
1226   CAMLlocal1 (rv);
1227   virConnectPtr conn = Connect_val (connv);
1228   char *str = String_val (strv);
1229   virJobPtr r;
1230
1231   NONBLOCKING (r = virNetworkCreateXMLJob (conn, str));
1232   CHECK_ERROR (!r, conn, "virNetworkCreateXMLJob");
1233
1234   rv = Val_job (r, connv);
1235
1236   CAMLreturn (rv);
1237 }
1238
1239 CAMLprim value
1240 ocaml_libvirt_network_define_xml (value connv, value strv)
1241 {
1242   CAMLparam2 (connv, strv);
1243
1244   CAMLlocal1 (rv);
1245   virConnectPtr conn = Connect_val (connv);
1246   char *str = String_val (strv);
1247   virNetworkPtr r;
1248
1249   NONBLOCKING (r = virNetworkDefineXML (conn, str));
1250   CHECK_ERROR (!r, conn, "virNetworkDefineXML");
1251
1252   rv = Val_network (r, connv);
1253
1254   CAMLreturn (rv);
1255 }
1256
1257 CAMLprim value
1258 ocaml_libvirt_network_create (value netv)
1259 {
1260   CAMLparam1 (netv);
1261
1262   virNetworkPtr net = Network_val (netv);
1263   virConnectPtr conn = Connect_netv (netv);
1264   int r;
1265
1266   NONBLOCKING (r = virNetworkCreate (net));
1267   CHECK_ERROR (r == -1, conn, "virNetworkCreate");
1268
1269   CAMLreturn (Val_unit);
1270 }
1271
1272 CAMLprim value
1273 ocaml_libvirt_network_create_job (value netv)
1274 {
1275   CAMLparam1 (netv);
1276
1277   CAMLlocal2 (rv, connv);
1278   virNetworkPtr net = Network_val (netv);
1279   virConnectPtr conn = Connect_netv (netv);
1280   virJobPtr r;
1281
1282   NONBLOCKING (r = virNetworkCreateJob (net));
1283   CHECK_ERROR (!r, conn, "virNetworkCreateJob");
1284
1285   connv = Field (netv, 1);
1286   rv = Val_job (r, connv);
1287
1288   CAMLreturn (rv);
1289 }
1290
1291 CAMLprim value
1292 ocaml_libvirt_network_get_autostart (value netv)
1293 {
1294   CAMLparam1 (netv);
1295
1296   virNetworkPtr net = Network_val (netv);
1297   virConnectPtr conn = Connect_netv (netv);
1298   int r, b;
1299
1300   NONBLOCKING (r = virNetworkGetAutostart (net, &b));
1301   CHECK_ERROR (r == -1, conn, "virNetworkGetAutostart");
1302
1303   CAMLreturn (b ? Val_true : Val_false);
1304 }
1305
1306 CAMLprim value
1307 ocaml_libvirt_network_set_autostart (value netv, value bv)
1308 {
1309   CAMLparam2 (netv, bv);
1310
1311   virNetworkPtr net = Network_val (netv);
1312   virConnectPtr conn = Connect_netv (netv);
1313   int r, b;
1314
1315   b = bv == Val_true ? 1 : 0;
1316
1317   NONBLOCKING (r = virNetworkSetAutostart (net, b));
1318   CHECK_ERROR (r == -1, conn, "virNetworkSetAutostart");
1319
1320   CAMLreturn (Val_unit);
1321 }
1322
1323 #ifdef HAVE_WEAK_SYMBOLS
1324 #ifdef HAVE_VIRSTORAGEPOOLFREE
1325 extern int virStoragePoolFree (virStoragePoolPtr pool) __attribute__((weak));
1326 #endif
1327 #endif
1328
1329 CAMLprim value
1330 ocaml_libvirt_storage_pool_free (value poolv)
1331 {
1332   CAMLparam1 (poolv);
1333 #ifndef HAVE_VIRSTORAGEPOOLFREE
1334   /* Symbol virStoragePoolFree not found at compile time. */
1335   not_supported ("virStoragePoolFree");
1336   /* Suppresses a compiler warning. */
1337   (void) caml__frame;
1338 #else
1339   /* Check that the symbol virStoragePoolFree
1340    * is in runtime version of libvirt.
1341    */
1342   WEAK_SYMBOL_CHECK (virStoragePoolFree);
1343
1344   virStoragePoolPtr pool = Pool_val (poolv);
1345   virConnectPtr conn = Connect_polv (poolv);
1346   int r;
1347
1348   NONBLOCKING (r = virStoragePoolFree (pool));
1349   CHECK_ERROR (r == -1, conn, "virStoragePoolFree");
1350
1351   /* So that we don't double-free in the finalizer: */
1352   Pool_val (poolv) = NULL;
1353
1354   CAMLreturn (Val_unit);
1355 #endif
1356 }
1357
1358 #ifdef HAVE_WEAK_SYMBOLS
1359 #ifdef HAVE_VIRSTORAGEPOOLDESTROY
1360 extern int virStoragePoolDestroy (virStoragePoolPtr pool) __attribute__((weak));
1361 #endif
1362 #endif
1363
1364 CAMLprim value
1365 ocaml_libvirt_storage_pool_destroy (value poolv)
1366 {
1367   CAMLparam1 (poolv);
1368 #ifndef HAVE_VIRSTORAGEPOOLDESTROY
1369   /* Symbol virStoragePoolDestroy not found at compile time. */
1370   not_supported ("virStoragePoolDestroy");
1371   /* Suppresses a compiler warning. */
1372   (void) caml__frame;
1373 #else
1374   /* Check that the symbol virStoragePoolDestroy
1375    * is in runtime version of libvirt.
1376    */
1377   WEAK_SYMBOL_CHECK (virStoragePoolDestroy);
1378
1379   virStoragePoolPtr pool = Pool_val (poolv);
1380   virConnectPtr conn = Connect_polv (poolv);
1381   int r;
1382
1383   NONBLOCKING (r = virStoragePoolDestroy (pool));
1384   CHECK_ERROR (r == -1, conn, "virStoragePoolDestroy");
1385
1386   /* So that we don't double-free in the finalizer: */
1387   Pool_val (poolv) = NULL;
1388
1389   CAMLreturn (Val_unit);
1390 #endif
1391 }
1392
1393 #ifdef HAVE_WEAK_SYMBOLS
1394 #ifdef HAVE_VIRSTORAGEPOOLLOOKUPBYNAME
1395 extern virStoragePoolPtr virStoragePoolLookupByName (virConnectPtr conn, const char *str) __attribute__((weak));
1396 #endif
1397 #endif
1398
1399 CAMLprim value
1400 ocaml_libvirt_storage_pool_lookup_by_name (value connv, value strv)
1401 {
1402   CAMLparam2 (connv, strv);
1403 #ifndef HAVE_VIRSTORAGEPOOLLOOKUPBYNAME
1404   /* Symbol virStoragePoolLookupByName not found at compile time. */
1405   not_supported ("virStoragePoolLookupByName");
1406   /* Suppresses a compiler warning. */
1407   (void) caml__frame;
1408 #else
1409   /* Check that the symbol virStoragePoolLookupByName
1410    * is in runtime version of libvirt.
1411    */
1412   WEAK_SYMBOL_CHECK (virStoragePoolLookupByName);
1413
1414   CAMLlocal1 (rv);
1415   virConnectPtr conn = Connect_val (connv);
1416   char *str = String_val (strv);
1417   virStoragePoolPtr r;
1418
1419   NONBLOCKING (r = virStoragePoolLookupByName (conn, str));
1420   CHECK_ERROR (!r, conn, "virStoragePoolLookupByName");
1421
1422   rv = Val_pool (r, connv);
1423
1424   CAMLreturn (rv);
1425 #endif
1426 }
1427
1428 #ifdef HAVE_WEAK_SYMBOLS
1429 #ifdef HAVE_VIRSTORAGEPOOLLOOKUPBYUUID
1430 extern virStoragePoolPtr virStoragePoolLookupByUUID (virConnectPtr conn, const unsigned char *str) __attribute__((weak));
1431 #endif
1432 #endif
1433
1434 CAMLprim value
1435 ocaml_libvirt_storage_pool_lookup_by_uuid (value connv, value uuidv)
1436 {
1437   CAMLparam2 (connv, uuidv);
1438 #ifndef HAVE_VIRSTORAGEPOOLLOOKUPBYUUID
1439   /* Symbol virStoragePoolLookupByUUID not found at compile time. */
1440   not_supported ("virStoragePoolLookupByUUID");
1441   /* Suppresses a compiler warning. */
1442   (void) caml__frame;
1443 #else
1444   /* Check that the symbol virStoragePoolLookupByUUID
1445    * is in runtime version of libvirt.
1446    */
1447   WEAK_SYMBOL_CHECK (virStoragePoolLookupByUUID);
1448
1449   CAMLlocal1 (rv);
1450   virConnectPtr conn = Connect_val (connv);
1451   unsigned char *uuid = (unsigned char *) String_val (uuidv);
1452   virStoragePoolPtr r;
1453
1454   NONBLOCKING (r = virStoragePoolLookupByUUID (conn, uuid));
1455   CHECK_ERROR (!r, conn, "virStoragePoolLookupByUUID");
1456
1457   rv = Val_pool (r, connv);
1458
1459   CAMLreturn (rv);
1460 #endif
1461 }
1462
1463 #ifdef HAVE_WEAK_SYMBOLS
1464 #ifdef HAVE_VIRSTORAGEPOOLLOOKUPBYUUIDSTRING
1465 extern virStoragePoolPtr virStoragePoolLookupByUUIDString (virConnectPtr conn, const char *str) __attribute__((weak));
1466 #endif
1467 #endif
1468
1469 CAMLprim value
1470 ocaml_libvirt_storage_pool_lookup_by_uuid_string (value connv, value strv)
1471 {
1472   CAMLparam2 (connv, strv);
1473 #ifndef HAVE_VIRSTORAGEPOOLLOOKUPBYUUIDSTRING
1474   /* Symbol virStoragePoolLookupByUUIDString not found at compile time. */
1475   not_supported ("virStoragePoolLookupByUUIDString");
1476   /* Suppresses a compiler warning. */
1477   (void) caml__frame;
1478 #else
1479   /* Check that the symbol virStoragePoolLookupByUUIDString
1480    * is in runtime version of libvirt.
1481    */
1482   WEAK_SYMBOL_CHECK (virStoragePoolLookupByUUIDString);
1483
1484   CAMLlocal1 (rv);
1485   virConnectPtr conn = Connect_val (connv);
1486   char *str = String_val (strv);
1487   virStoragePoolPtr r;
1488
1489   NONBLOCKING (r = virStoragePoolLookupByUUIDString (conn, str));
1490   CHECK_ERROR (!r, conn, "virStoragePoolLookupByUUIDString");
1491
1492   rv = Val_pool (r, connv);
1493
1494   CAMLreturn (rv);
1495 #endif
1496 }
1497
1498 #ifdef HAVE_WEAK_SYMBOLS
1499 #ifdef HAVE_VIRSTORAGEPOOLGETNAME
1500 extern const char *virStoragePoolGetName (virStoragePoolPtr pool) __attribute__((weak));
1501 #endif
1502 #endif
1503
1504 CAMLprim value
1505 ocaml_libvirt_storage_pool_get_name (value poolv)
1506 {
1507   CAMLparam1 (poolv);
1508 #ifndef HAVE_VIRSTORAGEPOOLGETNAME
1509   /* Symbol virStoragePoolGetName not found at compile time. */
1510   not_supported ("virStoragePoolGetName");
1511   /* Suppresses a compiler warning. */
1512   (void) caml__frame;
1513 #else
1514   /* Check that the symbol virStoragePoolGetName
1515    * is in runtime version of libvirt.
1516    */
1517   WEAK_SYMBOL_CHECK (virStoragePoolGetName);
1518
1519   CAMLlocal1 (rv);
1520   virStoragePoolPtr pool = Pool_val (poolv);
1521   virConnectPtr conn = Connect_polv (poolv);
1522   const char *r;
1523
1524   NONBLOCKING (r = virStoragePoolGetName (pool));
1525   CHECK_ERROR (!r, conn, "virStoragePoolGetName");
1526
1527   rv = caml_copy_string (r);
1528   CAMLreturn (rv);
1529 #endif
1530 }
1531
1532 #ifdef HAVE_WEAK_SYMBOLS
1533 #ifdef HAVE_VIRSTORAGEPOOLGETXMLDESC
1534 extern char *virStoragePoolGetXMLDesc (virStoragePoolPtr pool,  int flags) __attribute__((weak));
1535 #endif
1536 #endif
1537
1538 CAMLprim value
1539 ocaml_libvirt_storage_pool_get_xml_desc (value poolv)
1540 {
1541   CAMLparam1 (poolv);
1542 #ifndef HAVE_VIRSTORAGEPOOLGETXMLDESC
1543   /* Symbol virStoragePoolGetXMLDesc not found at compile time. */
1544   not_supported ("virStoragePoolGetXMLDesc");
1545   /* Suppresses a compiler warning. */
1546   (void) caml__frame;
1547 #else
1548   /* Check that the symbol virStoragePoolGetXMLDesc
1549    * is in runtime version of libvirt.
1550    */
1551   WEAK_SYMBOL_CHECK (virStoragePoolGetXMLDesc);
1552
1553   CAMLlocal1 (rv);
1554   virStoragePoolPtr pool = Pool_val (poolv);
1555   virConnectPtr conn = Connect_polv (poolv);
1556   char *r;
1557
1558   NONBLOCKING (r = virStoragePoolGetXMLDesc (pool, 0));
1559   CHECK_ERROR (!r, conn, "virStoragePoolGetXMLDesc");
1560
1561   rv = caml_copy_string (r);
1562   free (r);
1563   CAMLreturn (rv);
1564 #endif
1565 }
1566
1567 #ifdef HAVE_WEAK_SYMBOLS
1568 #ifdef HAVE_VIRSTORAGEPOOLGETUUID
1569 extern int virStoragePoolGetUUID (virStoragePoolPtr pool, unsigned char *) __attribute__((weak));
1570 #endif
1571 #endif
1572
1573 CAMLprim value
1574 ocaml_libvirt_storage_pool_get_uuid (value poolv)
1575 {
1576   CAMLparam1 (poolv);
1577 #ifndef HAVE_VIRSTORAGEPOOLGETUUID
1578   /* Symbol virStoragePoolGetUUID not found at compile time. */
1579   not_supported ("virStoragePoolGetUUID");
1580   /* Suppresses a compiler warning. */
1581   (void) caml__frame;
1582 #else
1583   /* Check that the symbol virStoragePoolGetUUID
1584    * is in runtime version of libvirt.
1585    */
1586   WEAK_SYMBOL_CHECK (virStoragePoolGetUUID);
1587
1588   CAMLlocal1 (rv);
1589   virStoragePoolPtr pool = Pool_val (poolv);
1590   virConnectPtr conn = Connect_polv (poolv);
1591   unsigned char uuid[VIR_UUID_BUFLEN];
1592   int r;
1593
1594   NONBLOCKING (r = virStoragePoolGetUUID (pool, uuid));
1595   CHECK_ERROR (r == -1, conn, "virStoragePoolGetUUID");
1596
1597   rv = caml_copy_string ((char *) uuid);
1598   CAMLreturn (rv);
1599 #endif
1600 }
1601
1602 #ifdef HAVE_WEAK_SYMBOLS
1603 #ifdef HAVE_VIRSTORAGEPOOLGETUUIDSTRING
1604 extern int virStoragePoolGetUUIDString (virStoragePoolPtr pool, char *) __attribute__((weak));
1605 #endif
1606 #endif
1607
1608 CAMLprim value
1609 ocaml_libvirt_storage_pool_get_uuid_string (value poolv)
1610 {
1611   CAMLparam1 (poolv);
1612 #ifndef HAVE_VIRSTORAGEPOOLGETUUIDSTRING
1613   /* Symbol virStoragePoolGetUUIDString not found at compile time. */
1614   not_supported ("virStoragePoolGetUUIDString");
1615   /* Suppresses a compiler warning. */
1616   (void) caml__frame;
1617 #else
1618   /* Check that the symbol virStoragePoolGetUUIDString
1619    * is in runtime version of libvirt.
1620    */
1621   WEAK_SYMBOL_CHECK (virStoragePoolGetUUIDString);
1622
1623   CAMLlocal1 (rv);
1624   virStoragePoolPtr pool = Pool_val (poolv);
1625   virConnectPtr conn = Connect_polv (poolv);
1626   char uuid[VIR_UUID_STRING_BUFLEN];
1627   int r;
1628
1629   NONBLOCKING (r = virStoragePoolGetUUIDString (pool, uuid));
1630   CHECK_ERROR (r == -1, conn, "virStoragePoolGetUUIDString");
1631
1632   rv = caml_copy_string (uuid);
1633   CAMLreturn (rv);
1634 #endif
1635 }
1636
1637 #ifdef HAVE_WEAK_SYMBOLS
1638 #ifdef HAVE_VIRSTORAGEPOOLCREATEXML
1639 extern virStoragePoolPtr virStoragePoolCreateXML (virConnectPtr conn, const char *str) __attribute__((weak));
1640 #endif
1641 #endif
1642
1643 CAMLprim value
1644 ocaml_libvirt_storage_pool_create_xml (value connv, value strv)
1645 {
1646   CAMLparam2 (connv, strv);
1647 #ifndef HAVE_VIRSTORAGEPOOLCREATEXML
1648   /* Symbol virStoragePoolCreateXML not found at compile time. */
1649   not_supported ("virStoragePoolCreateXML");
1650   /* Suppresses a compiler warning. */
1651   (void) caml__frame;
1652 #else
1653   /* Check that the symbol virStoragePoolCreateXML
1654    * is in runtime version of libvirt.
1655    */
1656   WEAK_SYMBOL_CHECK (virStoragePoolCreateXML);
1657
1658   CAMLlocal1 (rv);
1659   virConnectPtr conn = Connect_val (connv);
1660   char *str = String_val (strv);
1661   virStoragePoolPtr r;
1662
1663   NONBLOCKING (r = virStoragePoolCreateXML (conn, str));
1664   CHECK_ERROR (!r, conn, "virStoragePoolCreateXML");
1665
1666   rv = Val_pool (r, connv);
1667
1668   CAMLreturn (rv);
1669 #endif
1670 }
1671
1672 #ifdef HAVE_WEAK_SYMBOLS
1673 #ifdef HAVE_VIRSTORAGEPOOLDEFINEXML
1674 extern virStoragePoolPtr virStoragePoolDefineXML (virConnectPtr conn, const char *str) __attribute__((weak));
1675 #endif
1676 #endif
1677
1678 CAMLprim value
1679 ocaml_libvirt_storage_pool_define_xml (value connv, value strv)
1680 {
1681   CAMLparam2 (connv, strv);
1682 #ifndef HAVE_VIRSTORAGEPOOLDEFINEXML
1683   /* Symbol virStoragePoolDefineXML not found at compile time. */
1684   not_supported ("virStoragePoolDefineXML");
1685   /* Suppresses a compiler warning. */
1686   (void) caml__frame;
1687 #else
1688   /* Check that the symbol virStoragePoolDefineXML
1689    * is in runtime version of libvirt.
1690    */
1691   WEAK_SYMBOL_CHECK (virStoragePoolDefineXML);
1692
1693   CAMLlocal1 (rv);
1694   virConnectPtr conn = Connect_val (connv);
1695   char *str = String_val (strv);
1696   virStoragePoolPtr r;
1697
1698   NONBLOCKING (r = virStoragePoolDefineXML (conn, str));
1699   CHECK_ERROR (!r, conn, "virStoragePoolDefineXML");
1700
1701   rv = Val_pool (r, connv);
1702
1703   CAMLreturn (rv);
1704 #endif
1705 }
1706
1707 #ifdef HAVE_WEAK_SYMBOLS
1708 #ifdef HAVE_VIRSTORAGEPOOLUNDEFINE
1709 extern int virStoragePoolUndefine (virStoragePoolPtr pool) __attribute__((weak));
1710 #endif
1711 #endif
1712
1713 CAMLprim value
1714 ocaml_libvirt_storage_pool_undefine (value poolv)
1715 {
1716   CAMLparam1 (poolv);
1717 #ifndef HAVE_VIRSTORAGEPOOLUNDEFINE
1718   /* Symbol virStoragePoolUndefine not found at compile time. */
1719   not_supported ("virStoragePoolUndefine");
1720   /* Suppresses a compiler warning. */
1721   (void) caml__frame;
1722 #else
1723   /* Check that the symbol virStoragePoolUndefine
1724    * is in runtime version of libvirt.
1725    */
1726   WEAK_SYMBOL_CHECK (virStoragePoolUndefine);
1727
1728   virStoragePoolPtr pool = Pool_val (poolv);
1729   virConnectPtr conn = Connect_polv (poolv);
1730   int r;
1731
1732   NONBLOCKING (r = virStoragePoolUndefine (pool));
1733   CHECK_ERROR (r == -1, conn, "virStoragePoolUndefine");
1734
1735   CAMLreturn (Val_unit);
1736 #endif
1737 }
1738
1739 #ifdef HAVE_WEAK_SYMBOLS
1740 #ifdef HAVE_VIRSTORAGEPOOLCREATE
1741 extern int virStoragePoolCreate (virStoragePoolPtr pool) __attribute__((weak));
1742 #endif
1743 #endif
1744
1745 CAMLprim value
1746 ocaml_libvirt_storage_pool_create (value poolv)
1747 {
1748   CAMLparam1 (poolv);
1749 #ifndef HAVE_VIRSTORAGEPOOLCREATE
1750   /* Symbol virStoragePoolCreate not found at compile time. */
1751   not_supported ("virStoragePoolCreate");
1752   /* Suppresses a compiler warning. */
1753   (void) caml__frame;
1754 #else
1755   /* Check that the symbol virStoragePoolCreate
1756    * is in runtime version of libvirt.
1757    */
1758   WEAK_SYMBOL_CHECK (virStoragePoolCreate);
1759
1760   virStoragePoolPtr pool = Pool_val (poolv);
1761   virConnectPtr conn = Connect_polv (poolv);
1762   int r;
1763
1764   NONBLOCKING (r = virStoragePoolCreate (pool));
1765   CHECK_ERROR (r == -1, conn, "virStoragePoolCreate");
1766
1767   CAMLreturn (Val_unit);
1768 #endif
1769 }
1770
1771 #ifdef HAVE_WEAK_SYMBOLS
1772 #ifdef HAVE_VIRSTORAGEPOOLSHUTDOWN
1773 extern int virStoragePoolShutdown (virStoragePoolPtr pool) __attribute__((weak));
1774 #endif
1775 #endif
1776
1777 CAMLprim value
1778 ocaml_libvirt_storage_pool_shutdown (value poolv)
1779 {
1780   CAMLparam1 (poolv);
1781 #ifndef HAVE_VIRSTORAGEPOOLSHUTDOWN
1782   /* Symbol virStoragePoolShutdown not found at compile time. */
1783   not_supported ("virStoragePoolShutdown");
1784   /* Suppresses a compiler warning. */
1785   (void) caml__frame;
1786 #else
1787   /* Check that the symbol virStoragePoolShutdown
1788    * is in runtime version of libvirt.
1789    */
1790   WEAK_SYMBOL_CHECK (virStoragePoolShutdown);
1791
1792   virStoragePoolPtr pool = Pool_val (poolv);
1793   virConnectPtr conn = Connect_polv (poolv);
1794   int r;
1795
1796   NONBLOCKING (r = virStoragePoolShutdown (pool));
1797   CHECK_ERROR (r == -1, conn, "virStoragePoolShutdown");
1798
1799   CAMLreturn (Val_unit);
1800 #endif
1801 }
1802
1803 #ifdef HAVE_WEAK_SYMBOLS
1804 #ifdef HAVE_VIRSTORAGEPOOLREFRESH
1805 extern int virStoragePoolRefresh (virStoragePoolPtr pool, unsigned  int flags) __attribute__((weak));
1806 #endif
1807 #endif
1808
1809 CAMLprim value
1810 ocaml_libvirt_storage_pool_refresh (value poolv)
1811 {
1812   CAMLparam1 (poolv);
1813 #ifndef HAVE_VIRSTORAGEPOOLREFRESH
1814   /* Symbol virStoragePoolRefresh not found at compile time. */
1815   not_supported ("virStoragePoolRefresh");
1816   /* Suppresses a compiler warning. */
1817   (void) caml__frame;
1818 #else
1819   /* Check that the symbol virStoragePoolRefresh
1820    * is in runtime version of libvirt.
1821    */
1822   WEAK_SYMBOL_CHECK (virStoragePoolRefresh);
1823
1824   virStoragePoolPtr pool = Pool_val (poolv);
1825   virConnectPtr conn = Connect_polv (poolv);
1826   int r;
1827
1828   NONBLOCKING (r = virStoragePoolRefresh (pool, 0));
1829   CHECK_ERROR (r == -1, conn, "virStoragePoolRefresh");
1830
1831   CAMLreturn (Val_unit);
1832 #endif
1833 }
1834
1835 #ifdef HAVE_WEAK_SYMBOLS
1836 #ifdef HAVE_VIRSTORAGEPOOLGETAUTOSTART
1837 extern int virStoragePoolGetAutostart (virStoragePoolPtr pool, int *r) __attribute__((weak));
1838 #endif
1839 #endif
1840
1841 CAMLprim value
1842 ocaml_libvirt_storage_pool_get_autostart (value poolv)
1843 {
1844   CAMLparam1 (poolv);
1845 #ifndef HAVE_VIRSTORAGEPOOLGETAUTOSTART
1846   /* Symbol virStoragePoolGetAutostart not found at compile time. */
1847   not_supported ("virStoragePoolGetAutostart");
1848   /* Suppresses a compiler warning. */
1849   (void) caml__frame;
1850 #else
1851   /* Check that the symbol virStoragePoolGetAutostart
1852    * is in runtime version of libvirt.
1853    */
1854   WEAK_SYMBOL_CHECK (virStoragePoolGetAutostart);
1855
1856   virStoragePoolPtr pool = Pool_val (poolv);
1857   virConnectPtr conn = Connect_polv (poolv);
1858   int r, b;
1859
1860   NONBLOCKING (r = virStoragePoolGetAutostart (pool, &b));
1861   CHECK_ERROR (r == -1, conn, "virStoragePoolGetAutostart");
1862
1863   CAMLreturn (b ? Val_true : Val_false);
1864 #endif
1865 }
1866
1867 #ifdef HAVE_WEAK_SYMBOLS
1868 #ifdef HAVE_VIRSTORAGEPOOLSETAUTOSTART
1869 extern int virStoragePoolSetAutostart (virStoragePoolPtr pool, int b) __attribute__((weak));
1870 #endif
1871 #endif
1872
1873 CAMLprim value
1874 ocaml_libvirt_storage_pool_set_autostart (value poolv, value bv)
1875 {
1876   CAMLparam2 (poolv, bv);
1877 #ifndef HAVE_VIRSTORAGEPOOLSETAUTOSTART
1878   /* Symbol virStoragePoolSetAutostart not found at compile time. */
1879   not_supported ("virStoragePoolSetAutostart");
1880   /* Suppresses a compiler warning. */
1881   (void) caml__frame;
1882 #else
1883   /* Check that the symbol virStoragePoolSetAutostart
1884    * is in runtime version of libvirt.
1885    */
1886   WEAK_SYMBOL_CHECK (virStoragePoolSetAutostart);
1887
1888   virStoragePoolPtr pool = Pool_val (poolv);
1889   virConnectPtr conn = Connect_polv (poolv);
1890   int r, b;
1891
1892   b = bv == Val_true ? 1 : 0;
1893
1894   NONBLOCKING (r = virStoragePoolSetAutostart (pool, b));
1895   CHECK_ERROR (r == -1, conn, "virStoragePoolSetAutostart");
1896
1897   CAMLreturn (Val_unit);
1898 #endif
1899 }
1900
1901 #ifdef HAVE_WEAK_SYMBOLS
1902 #ifdef HAVE_VIRSTORAGEVOLFREE
1903 extern int virStorageVolFree (virStorageVolPtr vol) __attribute__((weak));
1904 #endif
1905 #endif
1906
1907 CAMLprim value
1908 ocaml_libvirt_storage_vol_free (value volv)
1909 {
1910   CAMLparam1 (volv);
1911 #ifndef HAVE_VIRSTORAGEVOLFREE
1912   /* Symbol virStorageVolFree not found at compile time. */
1913   not_supported ("virStorageVolFree");
1914   /* Suppresses a compiler warning. */
1915   (void) caml__frame;
1916 #else
1917   /* Check that the symbol virStorageVolFree
1918    * is in runtime version of libvirt.
1919    */
1920   WEAK_SYMBOL_CHECK (virStorageVolFree);
1921
1922   virStorageVolPtr vol = Volume_val (volv);
1923   virConnectPtr conn = Connect_volv (volv);
1924   int r;
1925
1926   NONBLOCKING (r = virStorageVolFree (vol));
1927   CHECK_ERROR (r == -1, conn, "virStorageVolFree");
1928
1929   /* So that we don't double-free in the finalizer: */
1930   Volume_val (volv) = NULL;
1931
1932   CAMLreturn (Val_unit);
1933 #endif
1934 }
1935
1936 #ifdef HAVE_WEAK_SYMBOLS
1937 #ifdef HAVE_VIRSTORAGEVOLDESTROY
1938 extern int virStorageVolDestroy (virStorageVolPtr vol) __attribute__((weak));
1939 #endif
1940 #endif
1941
1942 CAMLprim value
1943 ocaml_libvirt_storage_vol_destroy (value volv)
1944 {
1945   CAMLparam1 (volv);
1946 #ifndef HAVE_VIRSTORAGEVOLDESTROY
1947   /* Symbol virStorageVolDestroy not found at compile time. */
1948   not_supported ("virStorageVolDestroy");
1949   /* Suppresses a compiler warning. */
1950   (void) caml__frame;
1951 #else
1952   /* Check that the symbol virStorageVolDestroy
1953    * is in runtime version of libvirt.
1954    */
1955   WEAK_SYMBOL_CHECK (virStorageVolDestroy);
1956
1957   virStorageVolPtr vol = Volume_val (volv);
1958   virConnectPtr conn = Connect_volv (volv);
1959   int r;
1960
1961   NONBLOCKING (r = virStorageVolDestroy (vol));
1962   CHECK_ERROR (r == -1, conn, "virStorageVolDestroy");
1963
1964   /* So that we don't double-free in the finalizer: */
1965   Volume_val (volv) = NULL;
1966
1967   CAMLreturn (Val_unit);
1968 #endif
1969 }
1970
1971 #ifdef HAVE_WEAK_SYMBOLS
1972 #ifdef HAVE_VIRSTORAGEVOLLOOKUPBYKEY
1973 extern virStorageVolPtr virStorageVolLookupByKey (virConnectPtr conn, const char *str) __attribute__((weak));
1974 #endif
1975 #endif
1976
1977 CAMLprim value
1978 ocaml_libvirt_storage_vol_lookup_by_key (value connv, value strv)
1979 {
1980   CAMLparam2 (connv, strv);
1981 #ifndef HAVE_VIRSTORAGEVOLLOOKUPBYKEY
1982   /* Symbol virStorageVolLookupByKey not found at compile time. */
1983   not_supported ("virStorageVolLookupByKey");
1984   /* Suppresses a compiler warning. */
1985   (void) caml__frame;
1986 #else
1987   /* Check that the symbol virStorageVolLookupByKey
1988    * is in runtime version of libvirt.
1989    */
1990   WEAK_SYMBOL_CHECK (virStorageVolLookupByKey);
1991
1992   CAMLlocal1 (rv);
1993   virConnectPtr conn = Connect_val (connv);
1994   char *str = String_val (strv);
1995   virStorageVolPtr r;
1996
1997   NONBLOCKING (r = virStorageVolLookupByKey (conn, str));
1998   CHECK_ERROR (!r, conn, "virStorageVolLookupByKey");
1999
2000   rv = Val_volume (r, connv);
2001
2002   CAMLreturn (rv);
2003 #endif
2004 }
2005
2006 #ifdef HAVE_WEAK_SYMBOLS
2007 #ifdef HAVE_VIRSTORAGEVOLLOOKUPBYPATH
2008 extern virStorageVolPtr virStorageVolLookupByPath (virConnectPtr conn, const char *str) __attribute__((weak));
2009 #endif
2010 #endif
2011
2012 CAMLprim value
2013 ocaml_libvirt_storage_vol_lookup_by_path (value connv, value strv)
2014 {
2015   CAMLparam2 (connv, strv);
2016 #ifndef HAVE_VIRSTORAGEVOLLOOKUPBYPATH
2017   /* Symbol virStorageVolLookupByPath not found at compile time. */
2018   not_supported ("virStorageVolLookupByPath");
2019   /* Suppresses a compiler warning. */
2020   (void) caml__frame;
2021 #else
2022   /* Check that the symbol virStorageVolLookupByPath
2023    * is in runtime version of libvirt.
2024    */
2025   WEAK_SYMBOL_CHECK (virStorageVolLookupByPath);
2026
2027   CAMLlocal1 (rv);
2028   virConnectPtr conn = Connect_val (connv);
2029   char *str = String_val (strv);
2030   virStorageVolPtr r;
2031
2032   NONBLOCKING (r = virStorageVolLookupByPath (conn, str));
2033   CHECK_ERROR (!r, conn, "virStorageVolLookupByPath");
2034
2035   rv = Val_volume (r, connv);
2036
2037   CAMLreturn (rv);
2038 #endif
2039 }
2040
2041 #ifdef HAVE_WEAK_SYMBOLS
2042 #ifdef HAVE_VIRSTORAGEVOLGETXMLDESC
2043 extern char *virStorageVolGetXMLDesc (virStorageVolPtr vol,  int flags) __attribute__((weak));
2044 #endif
2045 #endif
2046
2047 CAMLprim value
2048 ocaml_libvirt_storage_vol_get_xml_desc (value volv)
2049 {
2050   CAMLparam1 (volv);
2051 #ifndef HAVE_VIRSTORAGEVOLGETXMLDESC
2052   /* Symbol virStorageVolGetXMLDesc not found at compile time. */
2053   not_supported ("virStorageVolGetXMLDesc");
2054   /* Suppresses a compiler warning. */
2055   (void) caml__frame;
2056 #else
2057   /* Check that the symbol virStorageVolGetXMLDesc
2058    * is in runtime version of libvirt.
2059    */
2060   WEAK_SYMBOL_CHECK (virStorageVolGetXMLDesc);
2061
2062   CAMLlocal1 (rv);
2063   virStorageVolPtr vol = Volume_val (volv);
2064   virConnectPtr conn = Connect_volv (volv);
2065   char *r;
2066
2067   NONBLOCKING (r = virStorageVolGetXMLDesc (vol, 0));
2068   CHECK_ERROR (!r, conn, "virStorageVolGetXMLDesc");
2069
2070   rv = caml_copy_string (r);
2071   free (r);
2072   CAMLreturn (rv);
2073 #endif
2074 }
2075
2076 #ifdef HAVE_WEAK_SYMBOLS
2077 #ifdef HAVE_VIRSTORAGEVOLGETPATH
2078 extern char *virStorageVolGetPath (virStorageVolPtr vol) __attribute__((weak));
2079 #endif
2080 #endif
2081
2082 CAMLprim value
2083 ocaml_libvirt_storage_vol_get_path (value volv)
2084 {
2085   CAMLparam1 (volv);
2086 #ifndef HAVE_VIRSTORAGEVOLGETPATH
2087   /* Symbol virStorageVolGetPath not found at compile time. */
2088   not_supported ("virStorageVolGetPath");
2089   /* Suppresses a compiler warning. */
2090   (void) caml__frame;
2091 #else
2092   /* Check that the symbol virStorageVolGetPath
2093    * is in runtime version of libvirt.
2094    */
2095   WEAK_SYMBOL_CHECK (virStorageVolGetPath);
2096
2097   CAMLlocal1 (rv);
2098   virStorageVolPtr vol = Volume_val (volv);
2099   virConnectPtr conn = Connect_volv (volv);
2100   char *r;
2101
2102   NONBLOCKING (r = virStorageVolGetPath (vol));
2103   CHECK_ERROR (!r, conn, "virStorageVolGetPath");
2104
2105   rv = caml_copy_string (r);
2106   free (r);
2107   CAMLreturn (rv);
2108 #endif
2109 }
2110
2111 #ifdef HAVE_WEAK_SYMBOLS
2112 #ifdef HAVE_VIRSTORAGEVOLGETKEY
2113 extern const char *virStorageVolGetKey (virStorageVolPtr vol) __attribute__((weak));
2114 #endif
2115 #endif
2116
2117 CAMLprim value
2118 ocaml_libvirt_storage_vol_get_key (value volv)
2119 {
2120   CAMLparam1 (volv);
2121 #ifndef HAVE_VIRSTORAGEVOLGETKEY
2122   /* Symbol virStorageVolGetKey not found at compile time. */
2123   not_supported ("virStorageVolGetKey");
2124   /* Suppresses a compiler warning. */
2125   (void) caml__frame;
2126 #else
2127   /* Check that the symbol virStorageVolGetKey
2128    * is in runtime version of libvirt.
2129    */
2130   WEAK_SYMBOL_CHECK (virStorageVolGetKey);
2131
2132   CAMLlocal1 (rv);
2133   virStorageVolPtr vol = Volume_val (volv);
2134   virConnectPtr conn = Connect_volv (volv);
2135   const char *r;
2136
2137   NONBLOCKING (r = virStorageVolGetKey (vol));
2138   CHECK_ERROR (!r, conn, "virStorageVolGetKey");
2139
2140   rv = caml_copy_string (r);
2141   CAMLreturn (rv);
2142 #endif
2143 }
2144
2145 #ifdef HAVE_WEAK_SYMBOLS
2146 #ifdef HAVE_VIRSTORAGEVOLGETNAME
2147 extern const char *virStorageVolGetName (virStorageVolPtr vol) __attribute__((weak));
2148 #endif
2149 #endif
2150
2151 CAMLprim value
2152 ocaml_libvirt_storage_vol_get_name (value volv)
2153 {
2154   CAMLparam1 (volv);
2155 #ifndef HAVE_VIRSTORAGEVOLGETNAME
2156   /* Symbol virStorageVolGetName not found at compile time. */
2157   not_supported ("virStorageVolGetName");
2158   /* Suppresses a compiler warning. */
2159   (void) caml__frame;
2160 #else
2161   /* Check that the symbol virStorageVolGetName
2162    * is in runtime version of libvirt.
2163    */
2164   WEAK_SYMBOL_CHECK (virStorageVolGetName);
2165
2166   CAMLlocal1 (rv);
2167   virStorageVolPtr vol = Volume_val (volv);
2168   virConnectPtr conn = Connect_volv (volv);
2169   const char *r;
2170
2171   NONBLOCKING (r = virStorageVolGetName (vol));
2172   CHECK_ERROR (!r, conn, "virStorageVolGetName");
2173
2174   rv = caml_copy_string (r);
2175   CAMLreturn (rv);
2176 #endif
2177 }
2178
2179 #ifdef HAVE_WEAK_SYMBOLS
2180 #ifdef HAVE_VIRSTORAGEPOOLLOOKUPBYVOLUME
2181 extern virStoragePoolPtr virStoragePoolLookupByVolume (virStorageVolPtr vol) __attribute__((weak));
2182 #endif
2183 #endif
2184
2185 CAMLprim value
2186 ocaml_libvirt_storage_pool_lookup_by_volume (value volv)
2187 {
2188   CAMLparam1 (volv);
2189 #ifndef HAVE_VIRSTORAGEPOOLLOOKUPBYVOLUME
2190   /* Symbol virStoragePoolLookupByVolume not found at compile time. */
2191   not_supported ("virStoragePoolLookupByVolume");
2192   /* Suppresses a compiler warning. */
2193   (void) caml__frame;
2194 #else
2195   /* Check that the symbol virStoragePoolLookupByVolume
2196    * is in runtime version of libvirt.
2197    */
2198   WEAK_SYMBOL_CHECK (virStoragePoolLookupByVolume);
2199
2200   CAMLlocal2 (rv, connv);
2201   virStorageVolPtr vol = Volume_val (volv);
2202   virConnectPtr conn = Connect_volv (volv);
2203   virStoragePoolPtr r;
2204
2205   NONBLOCKING (r = virStoragePoolLookupByVolume (vol));
2206   CHECK_ERROR (!r, conn, "virStoragePoolLookupByVolume");
2207
2208   connv = Field (volv, 1);
2209   rv = Val_pool (r, connv);
2210
2211   CAMLreturn (rv);
2212 #endif
2213 }
2214
2215 #ifdef HAVE_WEAK_SYMBOLS
2216 #ifdef HAVE_VIRJOBFREE
2217 extern int virJobFree (virJobPtr job) __attribute__((weak));
2218 #endif
2219 #endif
2220
2221 CAMLprim value
2222 ocaml_libvirt_job_free (value jobv)
2223 {
2224   CAMLparam1 (jobv);
2225 #ifndef HAVE_VIRJOBFREE
2226   /* Symbol virJobFree not found at compile time. */
2227   not_supported ("virJobFree");
2228   /* Suppresses a compiler warning. */
2229   (void) caml__frame;
2230 #else
2231   /* Check that the symbol virJobFree
2232    * is in runtime version of libvirt.
2233    */
2234   WEAK_SYMBOL_CHECK (virJobFree);
2235
2236   virJobPtr job = Job_val (jobv);
2237   virConnectPtr conn = Connect_jobv (jobv);
2238   int r;
2239
2240   NONBLOCKING (r = virJobFree (job));
2241   CHECK_ERROR (r == -1, conn, "virJobFree");
2242
2243   /* So that we don't double-free in the finalizer: */
2244   Job_val (jobv) = NULL;
2245
2246   CAMLreturn (Val_unit);
2247 #endif
2248 }
2249
2250 #ifdef HAVE_WEAK_SYMBOLS
2251 #ifdef HAVE_VIRJOBCANCEL
2252 extern int virJobCancel (virJobPtr job) __attribute__((weak));
2253 #endif
2254 #endif
2255
2256 CAMLprim value
2257 ocaml_libvirt_job_cancel (value jobv)
2258 {
2259   CAMLparam1 (jobv);
2260 #ifndef HAVE_VIRJOBCANCEL
2261   /* Symbol virJobCancel not found at compile time. */
2262   not_supported ("virJobCancel");
2263   /* Suppresses a compiler warning. */
2264   (void) caml__frame;
2265 #else
2266   /* Check that the symbol virJobCancel
2267    * is in runtime version of libvirt.
2268    */
2269   WEAK_SYMBOL_CHECK (virJobCancel);
2270
2271   virJobPtr job = Job_val (jobv);
2272   virConnectPtr conn = Connect_jobv (jobv);
2273   int r;
2274
2275   NONBLOCKING (r = virJobCancel (job));
2276   CHECK_ERROR (r == -1, conn, "virJobCancel");
2277
2278   CAMLreturn (Val_unit);
2279 #endif
2280 }
2281
2282 #ifdef HAVE_WEAK_SYMBOLS
2283 #ifdef HAVE_VIRJOBGETNETWORK
2284 extern virNetworkPtr virJobGetNetwork (virJobPtr job) __attribute__((weak));
2285 #endif
2286 #endif
2287
2288 CAMLprim value
2289 ocaml_libvirt_job_get_network (value jobv)
2290 {
2291   CAMLparam1 (jobv);
2292 #ifndef HAVE_VIRJOBGETNETWORK
2293   /* Symbol virJobGetNetwork not found at compile time. */
2294   not_supported ("virJobGetNetwork");
2295   /* Suppresses a compiler warning. */
2296   (void) caml__frame;
2297 #else
2298   /* Check that the symbol virJobGetNetwork
2299    * is in runtime version of libvirt.
2300    */
2301   WEAK_SYMBOL_CHECK (virJobGetNetwork);
2302
2303   CAMLlocal2 (rv, connv);
2304   virJobPtr job = Job_val (jobv);
2305   virConnectPtr conn = Connect_jobv (jobv);
2306   virNetworkPtr r;
2307
2308   NONBLOCKING (r = virJobGetNetwork (job));
2309   CHECK_ERROR (!r, conn, "virJobGetNetwork");
2310
2311   connv = Field (jobv, 1);
2312   rv = Val_network (r, connv);
2313
2314   CAMLreturn (rv);
2315 #endif
2316 }
2317
2318 #ifdef HAVE_WEAK_SYMBOLS
2319 #ifdef HAVE_VIRJOBGETDOMAIN
2320 extern virDomainPtr virJobGetDomain (virJobPtr job) __attribute__((weak));
2321 #endif
2322 #endif
2323
2324 CAMLprim value
2325 ocaml_libvirt_job_get_domain (value jobv)
2326 {
2327   CAMLparam1 (jobv);
2328 #ifndef HAVE_VIRJOBGETDOMAIN
2329   /* Symbol virJobGetDomain not found at compile time. */
2330   not_supported ("virJobGetDomain");
2331   /* Suppresses a compiler warning. */
2332   (void) caml__frame;
2333 #else
2334   /* Check that the symbol virJobGetDomain
2335    * is in runtime version of libvirt.
2336    */
2337   WEAK_SYMBOL_CHECK (virJobGetDomain);
2338
2339   CAMLlocal2 (rv, connv);
2340   virJobPtr job = Job_val (jobv);
2341   virConnectPtr conn = Connect_jobv (jobv);
2342   virDomainPtr r;
2343
2344   NONBLOCKING (r = virJobGetDomain (job));
2345   CHECK_ERROR (!r, conn, "virJobGetDomain");
2346
2347   connv = Field (jobv, 1);
2348   rv = Val_domain (r, connv);
2349
2350   CAMLreturn (rv);
2351 #endif
2352 }
2353
2354 /* The following functions are unimplemented and always fail.
2355  * See generator.pl '@unimplemented'
2356  */
2357
2358 CAMLprim value
2359 ocaml_libvirt_storage_pool_get_info ()
2360 {
2361   failwith ("ocaml_libvirt_storage_pool_get_info is unimplemented");
2362 }
2363
2364 CAMLprim value
2365 ocaml_libvirt_storage_vol_lookup_by_name ()
2366 {
2367   failwith ("ocaml_libvirt_storage_vol_lookup_by_name is unimplemented");
2368 }
2369
2370 CAMLprim value
2371 ocaml_libvirt_storage_vol_create_xml ()
2372 {
2373   failwith ("ocaml_libvirt_storage_vol_create_xml is unimplemented");
2374 }
2375
2376 CAMLprim value
2377 ocaml_libvirt_storage_vol_get_info ()
2378 {
2379   failwith ("ocaml_libvirt_storage_vol_get_info is unimplemented");
2380 }
2381
2382 CAMLprim value
2383 ocaml_libvirt_job_get_info ()
2384 {
2385   failwith ("ocaml_libvirt_job_get_info is unimplemented");
2386 }
2387
2388 #include "libvirt_c_epilogue.c"
2389
2390 /* EOF */