Job functions should be marked as weak.
[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 #ifdef HAVE_WEAK_SYMBOLS
479 #ifdef HAVE_VIRDOMAINCREATELINUXJOB
480 extern virJobPtr virDomainCreateLinuxJob (virConnectPtr conn, const char *str, unsigned  int flags) __attribute__((weak));
481 #endif
482 #endif
483
484 CAMLprim value
485 ocaml_libvirt_domain_create_linux_job (value connv, value strv)
486 {
487   CAMLparam2 (connv, strv);
488 #ifndef HAVE_VIRDOMAINCREATELINUXJOB
489   /* Symbol virDomainCreateLinuxJob not found at compile time. */
490   not_supported ("virDomainCreateLinuxJob");
491   /* Suppresses a compiler warning. */
492   (void) caml__frame;
493 #else
494   /* Check that the symbol virDomainCreateLinuxJob
495    * is in runtime version of libvirt.
496    */
497   WEAK_SYMBOL_CHECK (virDomainCreateLinuxJob);
498
499   CAMLlocal1 (rv);
500   virConnectPtr conn = Connect_val (connv);
501   char *str = String_val (strv);
502   virJobPtr r;
503
504   NONBLOCKING (r = virDomainCreateLinuxJob (conn, str, 0));
505   CHECK_ERROR (!r, conn, "virDomainCreateLinuxJob");
506
507   rv = Val_job (r, connv);
508
509   CAMLreturn (rv);
510 #endif
511 }
512
513 CAMLprim value
514 ocaml_libvirt_domain_free (value domv)
515 {
516   CAMLparam1 (domv);
517
518   virDomainPtr dom = Domain_val (domv);
519   virConnectPtr conn = Connect_domv (domv);
520   int r;
521
522   NONBLOCKING (r = virDomainFree (dom));
523   CHECK_ERROR (r == -1, conn, "virDomainFree");
524
525   /* So that we don't double-free in the finalizer: */
526   Domain_val (domv) = NULL;
527
528   CAMLreturn (Val_unit);
529 }
530
531 CAMLprim value
532 ocaml_libvirt_domain_destroy (value domv)
533 {
534   CAMLparam1 (domv);
535
536   virDomainPtr dom = Domain_val (domv);
537   virConnectPtr conn = Connect_domv (domv);
538   int r;
539
540   NONBLOCKING (r = virDomainDestroy (dom));
541   CHECK_ERROR (r == -1, conn, "virDomainDestroy");
542
543   /* So that we don't double-free in the finalizer: */
544   Domain_val (domv) = NULL;
545
546   CAMLreturn (Val_unit);
547 }
548
549 CAMLprim value
550 ocaml_libvirt_domain_lookup_by_name (value connv, value strv)
551 {
552   CAMLparam2 (connv, strv);
553
554   CAMLlocal1 (rv);
555   virConnectPtr conn = Connect_val (connv);
556   char *str = String_val (strv);
557   virDomainPtr r;
558
559   NONBLOCKING (r = virDomainLookupByName (conn, str));
560   CHECK_ERROR (!r, conn, "virDomainLookupByName");
561
562   rv = Val_domain (r, connv);
563
564   CAMLreturn (rv);
565 }
566
567 CAMLprim value
568 ocaml_libvirt_domain_lookup_by_id (value connv, value iv)
569 {
570   CAMLparam2 (connv, iv);
571
572   CAMLlocal1 (rv);
573   virConnectPtr conn = Connect_val (connv);
574   int i = Int_val (iv);
575   virDomainPtr r;
576
577   NONBLOCKING (r = virDomainLookupByID (conn, i));
578   CHECK_ERROR (!r, conn, "virDomainLookupByID");
579
580   rv = Val_domain (r, connv);
581
582   CAMLreturn (rv);
583 }
584
585 CAMLprim value
586 ocaml_libvirt_domain_lookup_by_uuid (value connv, value uuidv)
587 {
588   CAMLparam2 (connv, uuidv);
589
590   CAMLlocal1 (rv);
591   virConnectPtr conn = Connect_val (connv);
592   unsigned char *uuid = (unsigned char *) String_val (uuidv);
593   virDomainPtr r;
594
595   NONBLOCKING (r = virDomainLookupByUUID (conn, uuid));
596   CHECK_ERROR (!r, conn, "virDomainLookupByUUID");
597
598   rv = Val_domain (r, connv);
599
600   CAMLreturn (rv);
601 }
602
603 CAMLprim value
604 ocaml_libvirt_domain_lookup_by_uuid_string (value connv, value strv)
605 {
606   CAMLparam2 (connv, strv);
607
608   CAMLlocal1 (rv);
609   virConnectPtr conn = Connect_val (connv);
610   char *str = String_val (strv);
611   virDomainPtr r;
612
613   NONBLOCKING (r = virDomainLookupByUUIDString (conn, str));
614   CHECK_ERROR (!r, conn, "virDomainLookupByUUIDString");
615
616   rv = Val_domain (r, connv);
617
618   CAMLreturn (rv);
619 }
620
621 CAMLprim value
622 ocaml_libvirt_domain_get_name (value domv)
623 {
624   CAMLparam1 (domv);
625
626   CAMLlocal1 (rv);
627   virDomainPtr dom = Domain_val (domv);
628   virConnectPtr conn = Connect_domv (domv);
629   const char *r;
630
631   NONBLOCKING (r = virDomainGetName (dom));
632   CHECK_ERROR (!r, conn, "virDomainGetName");
633
634   rv = caml_copy_string (r);
635   CAMLreturn (rv);
636 }
637
638 CAMLprim value
639 ocaml_libvirt_domain_get_os_type (value domv)
640 {
641   CAMLparam1 (domv);
642
643   CAMLlocal1 (rv);
644   virDomainPtr dom = Domain_val (domv);
645   virConnectPtr conn = Connect_domv (domv);
646   char *r;
647
648   NONBLOCKING (r = virDomainGetOSType (dom));
649   CHECK_ERROR (!r, conn, "virDomainGetOSType");
650
651   rv = caml_copy_string (r);
652   free (r);
653   CAMLreturn (rv);
654 }
655
656 CAMLprim value
657 ocaml_libvirt_domain_get_xml_desc (value domv)
658 {
659   CAMLparam1 (domv);
660
661   CAMLlocal1 (rv);
662   virDomainPtr dom = Domain_val (domv);
663   virConnectPtr conn = Connect_domv (domv);
664   char *r;
665
666   NONBLOCKING (r = virDomainGetXMLDesc (dom, 0));
667   CHECK_ERROR (!r, conn, "virDomainGetXMLDesc");
668
669   rv = caml_copy_string (r);
670   free (r);
671   CAMLreturn (rv);
672 }
673
674 CAMLprim value
675 ocaml_libvirt_domain_get_uuid (value domv)
676 {
677   CAMLparam1 (domv);
678
679   CAMLlocal1 (rv);
680   virDomainPtr dom = Domain_val (domv);
681   virConnectPtr conn = Connect_domv (domv);
682   unsigned char uuid[VIR_UUID_BUFLEN];
683   int r;
684
685   NONBLOCKING (r = virDomainGetUUID (dom, uuid));
686   CHECK_ERROR (r == -1, conn, "virDomainGetUUID");
687
688   rv = caml_copy_string ((char *) uuid);
689   CAMLreturn (rv);
690 }
691
692 CAMLprim value
693 ocaml_libvirt_domain_get_uuid_string (value domv)
694 {
695   CAMLparam1 (domv);
696
697   CAMLlocal1 (rv);
698   virDomainPtr dom = Domain_val (domv);
699   virConnectPtr conn = Connect_domv (domv);
700   char uuid[VIR_UUID_STRING_BUFLEN];
701   int r;
702
703   NONBLOCKING (r = virDomainGetUUIDString (dom, uuid));
704   CHECK_ERROR (r == -1, conn, "virDomainGetUUIDString");
705
706   rv = caml_copy_string (uuid);
707   CAMLreturn (rv);
708 }
709
710 CAMLprim value
711 ocaml_libvirt_domain_get_max_vcpus (value domv)
712 {
713   CAMLparam1 (domv);
714
715   virDomainPtr dom = Domain_val (domv);
716   virConnectPtr conn = Connect_domv (domv);
717   int r;
718
719   NONBLOCKING (r = virDomainGetMaxVcpus (dom));
720   CHECK_ERROR (r == -1, conn, "virDomainGetMaxVcpus");
721
722   CAMLreturn (Val_int (r));
723 }
724
725 CAMLprim value
726 ocaml_libvirt_domain_save (value domv, value strv)
727 {
728   CAMLparam2 (domv, strv);
729
730   CAMLlocal1 (rv);
731   virDomainPtr dom = Domain_val (domv);
732   virConnectPtr conn = Connect_domv (domv);
733   char *str = String_val (strv);
734   int r;
735
736   NONBLOCKING (r = virDomainSave (dom, str));
737   CHECK_ERROR (r == -1, conn, "virDomainSave");
738
739   CAMLreturn (Val_unit);
740 }
741
742 #ifdef HAVE_WEAK_SYMBOLS
743 #ifdef HAVE_VIRDOMAINSAVEJOB
744 extern virJobPtr virDomainSaveJob (virDomainPtr dom, const char *str) __attribute__((weak));
745 #endif
746 #endif
747
748 CAMLprim value
749 ocaml_libvirt_domain_save_job (value domv, value strv)
750 {
751   CAMLparam2 (domv, strv);
752 #ifndef HAVE_VIRDOMAINSAVEJOB
753   /* Symbol virDomainSaveJob not found at compile time. */
754   not_supported ("virDomainSaveJob");
755   /* Suppresses a compiler warning. */
756   (void) caml__frame;
757 #else
758   /* Check that the symbol virDomainSaveJob
759    * is in runtime version of libvirt.
760    */
761   WEAK_SYMBOL_CHECK (virDomainSaveJob);
762
763   CAMLlocal2 (rv, connv);
764   virDomainPtr dom = Domain_val (domv);
765   virConnectPtr conn = Connect_domv (domv);
766   char *str = String_val (strv);
767   virJobPtr r;
768
769   NONBLOCKING (r = virDomainSaveJob (dom, str));
770   CHECK_ERROR (!r, conn, "virDomainSaveJob");
771
772   connv = Field (domv, 1);
773   rv = Val_job (r, connv);
774
775   CAMLreturn (rv);
776 #endif
777 }
778
779 CAMLprim value
780 ocaml_libvirt_domain_restore (value connv, value strv)
781 {
782   CAMLparam2 (connv, strv);
783
784   CAMLlocal1 (rv);
785   virConnectPtr conn = Connect_val (connv);
786   char *str = String_val (strv);
787   int r;
788
789   NONBLOCKING (r = virDomainRestore (conn, str));
790   CHECK_ERROR (r == -1, conn, "virDomainRestore");
791
792   CAMLreturn (Val_unit);
793 }
794
795 #ifdef HAVE_WEAK_SYMBOLS
796 #ifdef HAVE_VIRDOMAINRESTOREJOB
797 extern virJobPtr virDomainRestoreJob (virConnectPtr conn, const char *str) __attribute__((weak));
798 #endif
799 #endif
800
801 CAMLprim value
802 ocaml_libvirt_domain_restore_job (value connv, value strv)
803 {
804   CAMLparam2 (connv, strv);
805 #ifndef HAVE_VIRDOMAINRESTOREJOB
806   /* Symbol virDomainRestoreJob not found at compile time. */
807   not_supported ("virDomainRestoreJob");
808   /* Suppresses a compiler warning. */
809   (void) caml__frame;
810 #else
811   /* Check that the symbol virDomainRestoreJob
812    * is in runtime version of libvirt.
813    */
814   WEAK_SYMBOL_CHECK (virDomainRestoreJob);
815
816   CAMLlocal1 (rv);
817   virConnectPtr conn = Connect_val (connv);
818   char *str = String_val (strv);
819   virJobPtr r;
820
821   NONBLOCKING (r = virDomainRestoreJob (conn, str));
822   CHECK_ERROR (!r, conn, "virDomainRestoreJob");
823
824   rv = Val_job (r, connv);
825
826   CAMLreturn (rv);
827 #endif
828 }
829
830 CAMLprim value
831 ocaml_libvirt_domain_core_dump (value domv, value strv)
832 {
833   CAMLparam2 (domv, strv);
834
835   CAMLlocal1 (rv);
836   virDomainPtr dom = Domain_val (domv);
837   virConnectPtr conn = Connect_domv (domv);
838   char *str = String_val (strv);
839   int r;
840
841   NONBLOCKING (r = virDomainCoreDump (dom, str, 0));
842   CHECK_ERROR (!r, conn, "virDomainCoreDump");
843
844   CAMLreturn (Val_unit);
845 }
846
847 #ifdef HAVE_WEAK_SYMBOLS
848 #ifdef HAVE_VIRDOMAINCOREDUMPJOB
849 extern virJobPtr virDomainCoreDumpJob (virDomainPtr dom, const char *str,  int flags) __attribute__((weak));
850 #endif
851 #endif
852
853 CAMLprim value
854 ocaml_libvirt_domain_core_dump_job (value domv, value strv)
855 {
856   CAMLparam2 (domv, strv);
857 #ifndef HAVE_VIRDOMAINCOREDUMPJOB
858   /* Symbol virDomainCoreDumpJob not found at compile time. */
859   not_supported ("virDomainCoreDumpJob");
860   /* Suppresses a compiler warning. */
861   (void) caml__frame;
862 #else
863   /* Check that the symbol virDomainCoreDumpJob
864    * is in runtime version of libvirt.
865    */
866   WEAK_SYMBOL_CHECK (virDomainCoreDumpJob);
867
868   CAMLlocal2 (rv, connv);
869   virDomainPtr dom = Domain_val (domv);
870   virConnectPtr conn = Connect_domv (domv);
871   char *str = String_val (strv);
872   virJobPtr r;
873
874   NONBLOCKING (r = virDomainCoreDumpJob (dom, str, 0));
875   CHECK_ERROR (!r, conn, "virDomainCoreDumpJob");
876
877   connv = Field (domv, 1);
878   rv = Val_job (r, connv);
879
880   CAMLreturn (rv);
881 #endif
882 }
883
884 CAMLprim value
885 ocaml_libvirt_domain_suspend (value domv)
886 {
887   CAMLparam1 (domv);
888
889   virDomainPtr dom = Domain_val (domv);
890   virConnectPtr conn = Connect_domv (domv);
891   int r;
892
893   NONBLOCKING (r = virDomainSuspend (dom));
894   CHECK_ERROR (r == -1, conn, "virDomainSuspend");
895
896   CAMLreturn (Val_unit);
897 }
898
899 CAMLprim value
900 ocaml_libvirt_domain_resume (value domv)
901 {
902   CAMLparam1 (domv);
903
904   virDomainPtr dom = Domain_val (domv);
905   virConnectPtr conn = Connect_domv (domv);
906   int r;
907
908   NONBLOCKING (r = virDomainResume (dom));
909   CHECK_ERROR (r == -1, conn, "virDomainResume");
910
911   CAMLreturn (Val_unit);
912 }
913
914 CAMLprim value
915 ocaml_libvirt_domain_shutdown (value domv)
916 {
917   CAMLparam1 (domv);
918
919   virDomainPtr dom = Domain_val (domv);
920   virConnectPtr conn = Connect_domv (domv);
921   int r;
922
923   NONBLOCKING (r = virDomainShutdown (dom));
924   CHECK_ERROR (r == -1, conn, "virDomainShutdown");
925
926   CAMLreturn (Val_unit);
927 }
928
929 CAMLprim value
930 ocaml_libvirt_domain_reboot (value domv)
931 {
932   CAMLparam1 (domv);
933
934   virDomainPtr dom = Domain_val (domv);
935   virConnectPtr conn = Connect_domv (domv);
936   int r;
937
938   NONBLOCKING (r = virDomainReboot (dom, 0));
939   CHECK_ERROR (r == -1, conn, "virDomainReboot");
940
941   CAMLreturn (Val_unit);
942 }
943
944 CAMLprim value
945 ocaml_libvirt_domain_define_xml (value connv, value strv)
946 {
947   CAMLparam2 (connv, strv);
948
949   CAMLlocal1 (rv);
950   virConnectPtr conn = Connect_val (connv);
951   char *str = String_val (strv);
952   virDomainPtr r;
953
954   NONBLOCKING (r = virDomainDefineXML (conn, str));
955   CHECK_ERROR (!r, conn, "virDomainDefineXML");
956
957   rv = Val_domain (r, connv);
958
959   CAMLreturn (rv);
960 }
961
962 CAMLprim value
963 ocaml_libvirt_domain_undefine (value domv)
964 {
965   CAMLparam1 (domv);
966
967   virDomainPtr dom = Domain_val (domv);
968   virConnectPtr conn = Connect_domv (domv);
969   int r;
970
971   NONBLOCKING (r = virDomainUndefine (dom));
972   CHECK_ERROR (r == -1, conn, "virDomainUndefine");
973
974   CAMLreturn (Val_unit);
975 }
976
977 CAMLprim value
978 ocaml_libvirt_domain_create (value domv)
979 {
980   CAMLparam1 (domv);
981
982   virDomainPtr dom = Domain_val (domv);
983   virConnectPtr conn = Connect_domv (domv);
984   int r;
985
986   NONBLOCKING (r = virDomainCreate (dom));
987   CHECK_ERROR (r == -1, conn, "virDomainCreate");
988
989   CAMLreturn (Val_unit);
990 }
991
992 #ifdef HAVE_WEAK_SYMBOLS
993 #ifdef HAVE_VIRDOMAINCREATEJOB
994 extern virJobPtr virDomainCreateJob (virDomainPtr dom, unsigned  int flags) __attribute__((weak));
995 #endif
996 #endif
997
998 CAMLprim value
999 ocaml_libvirt_domain_create_job (value domv)
1000 {
1001   CAMLparam1 (domv);
1002 #ifndef HAVE_VIRDOMAINCREATEJOB
1003   /* Symbol virDomainCreateJob not found at compile time. */
1004   not_supported ("virDomainCreateJob");
1005   /* Suppresses a compiler warning. */
1006   (void) caml__frame;
1007 #else
1008   /* Check that the symbol virDomainCreateJob
1009    * is in runtime version of libvirt.
1010    */
1011   WEAK_SYMBOL_CHECK (virDomainCreateJob);
1012
1013   CAMLlocal2 (rv, connv);
1014   virDomainPtr dom = Domain_val (domv);
1015   virConnectPtr conn = Connect_domv (domv);
1016   virJobPtr r;
1017
1018   NONBLOCKING (r = virDomainCreateJob (dom, 0));
1019   CHECK_ERROR (!r, conn, "virDomainCreateJob");
1020
1021   connv = Field (domv, 1);
1022   rv = Val_job (r, connv);
1023
1024   CAMLreturn (rv);
1025 #endif
1026 }
1027
1028 CAMLprim value
1029 ocaml_libvirt_domain_attach_device (value domv, value strv)
1030 {
1031   CAMLparam2 (domv, strv);
1032
1033   CAMLlocal1 (rv);
1034   virDomainPtr dom = Domain_val (domv);
1035   virConnectPtr conn = Connect_domv (domv);
1036   char *str = String_val (strv);
1037   int r;
1038
1039   NONBLOCKING (r = virDomainAttachDevice (dom, str));
1040   CHECK_ERROR (r == -1, conn, "virDomainAttachDevice");
1041
1042   CAMLreturn (Val_unit);
1043 }
1044
1045 CAMLprim value
1046 ocaml_libvirt_domain_detach_device (value domv, value strv)
1047 {
1048   CAMLparam2 (domv, strv);
1049
1050   CAMLlocal1 (rv);
1051   virDomainPtr dom = Domain_val (domv);
1052   virConnectPtr conn = Connect_domv (domv);
1053   char *str = String_val (strv);
1054   int r;
1055
1056   NONBLOCKING (r = virDomainDetachDevice (dom, str));
1057   CHECK_ERROR (r == -1, conn, "virDomainDetachDevice");
1058
1059   CAMLreturn (Val_unit);
1060 }
1061
1062 CAMLprim value
1063 ocaml_libvirt_domain_get_autostart (value domv)
1064 {
1065   CAMLparam1 (domv);
1066
1067   virDomainPtr dom = Domain_val (domv);
1068   virConnectPtr conn = Connect_domv (domv);
1069   int r, b;
1070
1071   NONBLOCKING (r = virDomainGetAutostart (dom, &b));
1072   CHECK_ERROR (r == -1, conn, "virDomainGetAutostart");
1073
1074   CAMLreturn (b ? Val_true : Val_false);
1075 }
1076
1077 CAMLprim value
1078 ocaml_libvirt_domain_set_autostart (value domv, value bv)
1079 {
1080   CAMLparam2 (domv, bv);
1081
1082   virDomainPtr dom = Domain_val (domv);
1083   virConnectPtr conn = Connect_domv (domv);
1084   int r, b;
1085
1086   b = bv == Val_true ? 1 : 0;
1087
1088   NONBLOCKING (r = virDomainSetAutostart (dom, b));
1089   CHECK_ERROR (r == -1, conn, "virDomainSetAutostart");
1090
1091   CAMLreturn (Val_unit);
1092 }
1093
1094 CAMLprim value
1095 ocaml_libvirt_network_free (value netv)
1096 {
1097   CAMLparam1 (netv);
1098
1099   virNetworkPtr net = Network_val (netv);
1100   virConnectPtr conn = Connect_netv (netv);
1101   int r;
1102
1103   NONBLOCKING (r = virNetworkFree (net));
1104   CHECK_ERROR (r == -1, conn, "virNetworkFree");
1105
1106   /* So that we don't double-free in the finalizer: */
1107   Network_val (netv) = NULL;
1108
1109   CAMLreturn (Val_unit);
1110 }
1111
1112 CAMLprim value
1113 ocaml_libvirt_network_destroy (value netv)
1114 {
1115   CAMLparam1 (netv);
1116
1117   virNetworkPtr net = Network_val (netv);
1118   virConnectPtr conn = Connect_netv (netv);
1119   int r;
1120
1121   NONBLOCKING (r = virNetworkDestroy (net));
1122   CHECK_ERROR (r == -1, conn, "virNetworkDestroy");
1123
1124   /* So that we don't double-free in the finalizer: */
1125   Network_val (netv) = NULL;
1126
1127   CAMLreturn (Val_unit);
1128 }
1129
1130 CAMLprim value
1131 ocaml_libvirt_network_lookup_by_name (value connv, value strv)
1132 {
1133   CAMLparam2 (connv, strv);
1134
1135   CAMLlocal1 (rv);
1136   virConnectPtr conn = Connect_val (connv);
1137   char *str = String_val (strv);
1138   virNetworkPtr r;
1139
1140   NONBLOCKING (r = virNetworkLookupByName (conn, str));
1141   CHECK_ERROR (!r, conn, "virNetworkLookupByName");
1142
1143   rv = Val_network (r, connv);
1144
1145   CAMLreturn (rv);
1146 }
1147
1148 CAMLprim value
1149 ocaml_libvirt_network_lookup_by_uuid (value connv, value uuidv)
1150 {
1151   CAMLparam2 (connv, uuidv);
1152
1153   CAMLlocal1 (rv);
1154   virConnectPtr conn = Connect_val (connv);
1155   unsigned char *uuid = (unsigned char *) String_val (uuidv);
1156   virNetworkPtr r;
1157
1158   NONBLOCKING (r = virNetworkLookupByUUID (conn, uuid));
1159   CHECK_ERROR (!r, conn, "virNetworkLookupByUUID");
1160
1161   rv = Val_network (r, connv);
1162
1163   CAMLreturn (rv);
1164 }
1165
1166 CAMLprim value
1167 ocaml_libvirt_network_lookup_by_uuid_string (value connv, value strv)
1168 {
1169   CAMLparam2 (connv, strv);
1170
1171   CAMLlocal1 (rv);
1172   virConnectPtr conn = Connect_val (connv);
1173   char *str = String_val (strv);
1174   virNetworkPtr r;
1175
1176   NONBLOCKING (r = virNetworkLookupByUUIDString (conn, str));
1177   CHECK_ERROR (!r, conn, "virNetworkLookupByUUIDString");
1178
1179   rv = Val_network (r, connv);
1180
1181   CAMLreturn (rv);
1182 }
1183
1184 CAMLprim value
1185 ocaml_libvirt_network_get_name (value netv)
1186 {
1187   CAMLparam1 (netv);
1188
1189   CAMLlocal1 (rv);
1190   virNetworkPtr net = Network_val (netv);
1191   virConnectPtr conn = Connect_netv (netv);
1192   const char *r;
1193
1194   NONBLOCKING (r = virNetworkGetName (net));
1195   CHECK_ERROR (!r, conn, "virNetworkGetName");
1196
1197   rv = caml_copy_string (r);
1198   CAMLreturn (rv);
1199 }
1200
1201 CAMLprim value
1202 ocaml_libvirt_network_get_xml_desc (value netv)
1203 {
1204   CAMLparam1 (netv);
1205
1206   CAMLlocal1 (rv);
1207   virNetworkPtr net = Network_val (netv);
1208   virConnectPtr conn = Connect_netv (netv);
1209   char *r;
1210
1211   NONBLOCKING (r = virNetworkGetXMLDesc (net, 0));
1212   CHECK_ERROR (!r, conn, "virNetworkGetXMLDesc");
1213
1214   rv = caml_copy_string (r);
1215   free (r);
1216   CAMLreturn (rv);
1217 }
1218
1219 CAMLprim value
1220 ocaml_libvirt_network_get_bridge_name (value netv)
1221 {
1222   CAMLparam1 (netv);
1223
1224   CAMLlocal1 (rv);
1225   virNetworkPtr net = Network_val (netv);
1226   virConnectPtr conn = Connect_netv (netv);
1227   char *r;
1228
1229   NONBLOCKING (r = virNetworkGetBridgeName (net));
1230   CHECK_ERROR (!r, conn, "virNetworkGetBridgeName");
1231
1232   rv = caml_copy_string (r);
1233   free (r);
1234   CAMLreturn (rv);
1235 }
1236
1237 CAMLprim value
1238 ocaml_libvirt_network_get_uuid (value netv)
1239 {
1240   CAMLparam1 (netv);
1241
1242   CAMLlocal1 (rv);
1243   virNetworkPtr net = Network_val (netv);
1244   virConnectPtr conn = Connect_netv (netv);
1245   unsigned char uuid[VIR_UUID_BUFLEN];
1246   int r;
1247
1248   NONBLOCKING (r = virNetworkGetUUID (net, uuid));
1249   CHECK_ERROR (r == -1, conn, "virNetworkGetUUID");
1250
1251   rv = caml_copy_string ((char *) uuid);
1252   CAMLreturn (rv);
1253 }
1254
1255 CAMLprim value
1256 ocaml_libvirt_network_get_uuid_string (value netv)
1257 {
1258   CAMLparam1 (netv);
1259
1260   CAMLlocal1 (rv);
1261   virNetworkPtr net = Network_val (netv);
1262   virConnectPtr conn = Connect_netv (netv);
1263   char uuid[VIR_UUID_STRING_BUFLEN];
1264   int r;
1265
1266   NONBLOCKING (r = virNetworkGetUUIDString (net, uuid));
1267   CHECK_ERROR (r == -1, conn, "virNetworkGetUUIDString");
1268
1269   rv = caml_copy_string (uuid);
1270   CAMLreturn (rv);
1271 }
1272
1273 CAMLprim value
1274 ocaml_libvirt_network_undefine (value netv)
1275 {
1276   CAMLparam1 (netv);
1277
1278   virNetworkPtr net = Network_val (netv);
1279   virConnectPtr conn = Connect_netv (netv);
1280   int r;
1281
1282   NONBLOCKING (r = virNetworkUndefine (net));
1283   CHECK_ERROR (r == -1, conn, "virNetworkUndefine");
1284
1285   CAMLreturn (Val_unit);
1286 }
1287
1288 CAMLprim value
1289 ocaml_libvirt_network_create_xml (value connv, value strv)
1290 {
1291   CAMLparam2 (connv, strv);
1292
1293   CAMLlocal1 (rv);
1294   virConnectPtr conn = Connect_val (connv);
1295   char *str = String_val (strv);
1296   virNetworkPtr r;
1297
1298   NONBLOCKING (r = virNetworkCreateXML (conn, str));
1299   CHECK_ERROR (!r, conn, "virNetworkCreateXML");
1300
1301   rv = Val_network (r, connv);
1302
1303   CAMLreturn (rv);
1304 }
1305
1306 #ifdef HAVE_WEAK_SYMBOLS
1307 #ifdef HAVE_VIRNETWORKCREATEXMLJOB
1308 extern virJobPtr virNetworkCreateXMLJob (virConnectPtr conn, const char *str) __attribute__((weak));
1309 #endif
1310 #endif
1311
1312 CAMLprim value
1313 ocaml_libvirt_network_create_xml_job (value connv, value strv)
1314 {
1315   CAMLparam2 (connv, strv);
1316 #ifndef HAVE_VIRNETWORKCREATEXMLJOB
1317   /* Symbol virNetworkCreateXMLJob not found at compile time. */
1318   not_supported ("virNetworkCreateXMLJob");
1319   /* Suppresses a compiler warning. */
1320   (void) caml__frame;
1321 #else
1322   /* Check that the symbol virNetworkCreateXMLJob
1323    * is in runtime version of libvirt.
1324    */
1325   WEAK_SYMBOL_CHECK (virNetworkCreateXMLJob);
1326
1327   CAMLlocal1 (rv);
1328   virConnectPtr conn = Connect_val (connv);
1329   char *str = String_val (strv);
1330   virJobPtr r;
1331
1332   NONBLOCKING (r = virNetworkCreateXMLJob (conn, str));
1333   CHECK_ERROR (!r, conn, "virNetworkCreateXMLJob");
1334
1335   rv = Val_job (r, connv);
1336
1337   CAMLreturn (rv);
1338 #endif
1339 }
1340
1341 CAMLprim value
1342 ocaml_libvirt_network_define_xml (value connv, value strv)
1343 {
1344   CAMLparam2 (connv, strv);
1345
1346   CAMLlocal1 (rv);
1347   virConnectPtr conn = Connect_val (connv);
1348   char *str = String_val (strv);
1349   virNetworkPtr r;
1350
1351   NONBLOCKING (r = virNetworkDefineXML (conn, str));
1352   CHECK_ERROR (!r, conn, "virNetworkDefineXML");
1353
1354   rv = Val_network (r, connv);
1355
1356   CAMLreturn (rv);
1357 }
1358
1359 CAMLprim value
1360 ocaml_libvirt_network_create (value netv)
1361 {
1362   CAMLparam1 (netv);
1363
1364   virNetworkPtr net = Network_val (netv);
1365   virConnectPtr conn = Connect_netv (netv);
1366   int r;
1367
1368   NONBLOCKING (r = virNetworkCreate (net));
1369   CHECK_ERROR (r == -1, conn, "virNetworkCreate");
1370
1371   CAMLreturn (Val_unit);
1372 }
1373
1374 #ifdef HAVE_WEAK_SYMBOLS
1375 #ifdef HAVE_VIRNETWORKCREATEJOB
1376 extern virJobPtr virNetworkCreateJob (virNetworkPtr net) __attribute__((weak));
1377 #endif
1378 #endif
1379
1380 CAMLprim value
1381 ocaml_libvirt_network_create_job (value netv)
1382 {
1383   CAMLparam1 (netv);
1384 #ifndef HAVE_VIRNETWORKCREATEJOB
1385   /* Symbol virNetworkCreateJob not found at compile time. */
1386   not_supported ("virNetworkCreateJob");
1387   /* Suppresses a compiler warning. */
1388   (void) caml__frame;
1389 #else
1390   /* Check that the symbol virNetworkCreateJob
1391    * is in runtime version of libvirt.
1392    */
1393   WEAK_SYMBOL_CHECK (virNetworkCreateJob);
1394
1395   CAMLlocal2 (rv, connv);
1396   virNetworkPtr net = Network_val (netv);
1397   virConnectPtr conn = Connect_netv (netv);
1398   virJobPtr r;
1399
1400   NONBLOCKING (r = virNetworkCreateJob (net));
1401   CHECK_ERROR (!r, conn, "virNetworkCreateJob");
1402
1403   connv = Field (netv, 1);
1404   rv = Val_job (r, connv);
1405
1406   CAMLreturn (rv);
1407 #endif
1408 }
1409
1410 CAMLprim value
1411 ocaml_libvirt_network_get_autostart (value netv)
1412 {
1413   CAMLparam1 (netv);
1414
1415   virNetworkPtr net = Network_val (netv);
1416   virConnectPtr conn = Connect_netv (netv);
1417   int r, b;
1418
1419   NONBLOCKING (r = virNetworkGetAutostart (net, &b));
1420   CHECK_ERROR (r == -1, conn, "virNetworkGetAutostart");
1421
1422   CAMLreturn (b ? Val_true : Val_false);
1423 }
1424
1425 CAMLprim value
1426 ocaml_libvirt_network_set_autostart (value netv, value bv)
1427 {
1428   CAMLparam2 (netv, bv);
1429
1430   virNetworkPtr net = Network_val (netv);
1431   virConnectPtr conn = Connect_netv (netv);
1432   int r, b;
1433
1434   b = bv == Val_true ? 1 : 0;
1435
1436   NONBLOCKING (r = virNetworkSetAutostart (net, b));
1437   CHECK_ERROR (r == -1, conn, "virNetworkSetAutostart");
1438
1439   CAMLreturn (Val_unit);
1440 }
1441
1442 #ifdef HAVE_WEAK_SYMBOLS
1443 #ifdef HAVE_VIRSTORAGEPOOLFREE
1444 extern int virStoragePoolFree (virStoragePoolPtr pool) __attribute__((weak));
1445 #endif
1446 #endif
1447
1448 CAMLprim value
1449 ocaml_libvirt_storage_pool_free (value poolv)
1450 {
1451   CAMLparam1 (poolv);
1452 #ifndef HAVE_VIRSTORAGEPOOLFREE
1453   /* Symbol virStoragePoolFree not found at compile time. */
1454   not_supported ("virStoragePoolFree");
1455   /* Suppresses a compiler warning. */
1456   (void) caml__frame;
1457 #else
1458   /* Check that the symbol virStoragePoolFree
1459    * is in runtime version of libvirt.
1460    */
1461   WEAK_SYMBOL_CHECK (virStoragePoolFree);
1462
1463   virStoragePoolPtr pool = Pool_val (poolv);
1464   virConnectPtr conn = Connect_polv (poolv);
1465   int r;
1466
1467   NONBLOCKING (r = virStoragePoolFree (pool));
1468   CHECK_ERROR (r == -1, conn, "virStoragePoolFree");
1469
1470   /* So that we don't double-free in the finalizer: */
1471   Pool_val (poolv) = NULL;
1472
1473   CAMLreturn (Val_unit);
1474 #endif
1475 }
1476
1477 #ifdef HAVE_WEAK_SYMBOLS
1478 #ifdef HAVE_VIRSTORAGEPOOLDESTROY
1479 extern int virStoragePoolDestroy (virStoragePoolPtr pool) __attribute__((weak));
1480 #endif
1481 #endif
1482
1483 CAMLprim value
1484 ocaml_libvirt_storage_pool_destroy (value poolv)
1485 {
1486   CAMLparam1 (poolv);
1487 #ifndef HAVE_VIRSTORAGEPOOLDESTROY
1488   /* Symbol virStoragePoolDestroy not found at compile time. */
1489   not_supported ("virStoragePoolDestroy");
1490   /* Suppresses a compiler warning. */
1491   (void) caml__frame;
1492 #else
1493   /* Check that the symbol virStoragePoolDestroy
1494    * is in runtime version of libvirt.
1495    */
1496   WEAK_SYMBOL_CHECK (virStoragePoolDestroy);
1497
1498   virStoragePoolPtr pool = Pool_val (poolv);
1499   virConnectPtr conn = Connect_polv (poolv);
1500   int r;
1501
1502   NONBLOCKING (r = virStoragePoolDestroy (pool));
1503   CHECK_ERROR (r == -1, conn, "virStoragePoolDestroy");
1504
1505   /* So that we don't double-free in the finalizer: */
1506   Pool_val (poolv) = NULL;
1507
1508   CAMLreturn (Val_unit);
1509 #endif
1510 }
1511
1512 #ifdef HAVE_WEAK_SYMBOLS
1513 #ifdef HAVE_VIRSTORAGEPOOLLOOKUPBYNAME
1514 extern virStoragePoolPtr virStoragePoolLookupByName (virConnectPtr conn, const char *str) __attribute__((weak));
1515 #endif
1516 #endif
1517
1518 CAMLprim value
1519 ocaml_libvirt_storage_pool_lookup_by_name (value connv, value strv)
1520 {
1521   CAMLparam2 (connv, strv);
1522 #ifndef HAVE_VIRSTORAGEPOOLLOOKUPBYNAME
1523   /* Symbol virStoragePoolLookupByName not found at compile time. */
1524   not_supported ("virStoragePoolLookupByName");
1525   /* Suppresses a compiler warning. */
1526   (void) caml__frame;
1527 #else
1528   /* Check that the symbol virStoragePoolLookupByName
1529    * is in runtime version of libvirt.
1530    */
1531   WEAK_SYMBOL_CHECK (virStoragePoolLookupByName);
1532
1533   CAMLlocal1 (rv);
1534   virConnectPtr conn = Connect_val (connv);
1535   char *str = String_val (strv);
1536   virStoragePoolPtr r;
1537
1538   NONBLOCKING (r = virStoragePoolLookupByName (conn, str));
1539   CHECK_ERROR (!r, conn, "virStoragePoolLookupByName");
1540
1541   rv = Val_pool (r, connv);
1542
1543   CAMLreturn (rv);
1544 #endif
1545 }
1546
1547 #ifdef HAVE_WEAK_SYMBOLS
1548 #ifdef HAVE_VIRSTORAGEPOOLLOOKUPBYUUID
1549 extern virStoragePoolPtr virStoragePoolLookupByUUID (virConnectPtr conn, const unsigned char *str) __attribute__((weak));
1550 #endif
1551 #endif
1552
1553 CAMLprim value
1554 ocaml_libvirt_storage_pool_lookup_by_uuid (value connv, value uuidv)
1555 {
1556   CAMLparam2 (connv, uuidv);
1557 #ifndef HAVE_VIRSTORAGEPOOLLOOKUPBYUUID
1558   /* Symbol virStoragePoolLookupByUUID not found at compile time. */
1559   not_supported ("virStoragePoolLookupByUUID");
1560   /* Suppresses a compiler warning. */
1561   (void) caml__frame;
1562 #else
1563   /* Check that the symbol virStoragePoolLookupByUUID
1564    * is in runtime version of libvirt.
1565    */
1566   WEAK_SYMBOL_CHECK (virStoragePoolLookupByUUID);
1567
1568   CAMLlocal1 (rv);
1569   virConnectPtr conn = Connect_val (connv);
1570   unsigned char *uuid = (unsigned char *) String_val (uuidv);
1571   virStoragePoolPtr r;
1572
1573   NONBLOCKING (r = virStoragePoolLookupByUUID (conn, uuid));
1574   CHECK_ERROR (!r, conn, "virStoragePoolLookupByUUID");
1575
1576   rv = Val_pool (r, connv);
1577
1578   CAMLreturn (rv);
1579 #endif
1580 }
1581
1582 #ifdef HAVE_WEAK_SYMBOLS
1583 #ifdef HAVE_VIRSTORAGEPOOLLOOKUPBYUUIDSTRING
1584 extern virStoragePoolPtr virStoragePoolLookupByUUIDString (virConnectPtr conn, const char *str) __attribute__((weak));
1585 #endif
1586 #endif
1587
1588 CAMLprim value
1589 ocaml_libvirt_storage_pool_lookup_by_uuid_string (value connv, value strv)
1590 {
1591   CAMLparam2 (connv, strv);
1592 #ifndef HAVE_VIRSTORAGEPOOLLOOKUPBYUUIDSTRING
1593   /* Symbol virStoragePoolLookupByUUIDString not found at compile time. */
1594   not_supported ("virStoragePoolLookupByUUIDString");
1595   /* Suppresses a compiler warning. */
1596   (void) caml__frame;
1597 #else
1598   /* Check that the symbol virStoragePoolLookupByUUIDString
1599    * is in runtime version of libvirt.
1600    */
1601   WEAK_SYMBOL_CHECK (virStoragePoolLookupByUUIDString);
1602
1603   CAMLlocal1 (rv);
1604   virConnectPtr conn = Connect_val (connv);
1605   char *str = String_val (strv);
1606   virStoragePoolPtr r;
1607
1608   NONBLOCKING (r = virStoragePoolLookupByUUIDString (conn, str));
1609   CHECK_ERROR (!r, conn, "virStoragePoolLookupByUUIDString");
1610
1611   rv = Val_pool (r, connv);
1612
1613   CAMLreturn (rv);
1614 #endif
1615 }
1616
1617 #ifdef HAVE_WEAK_SYMBOLS
1618 #ifdef HAVE_VIRSTORAGEPOOLGETNAME
1619 extern const char *virStoragePoolGetName (virStoragePoolPtr pool) __attribute__((weak));
1620 #endif
1621 #endif
1622
1623 CAMLprim value
1624 ocaml_libvirt_storage_pool_get_name (value poolv)
1625 {
1626   CAMLparam1 (poolv);
1627 #ifndef HAVE_VIRSTORAGEPOOLGETNAME
1628   /* Symbol virStoragePoolGetName not found at compile time. */
1629   not_supported ("virStoragePoolGetName");
1630   /* Suppresses a compiler warning. */
1631   (void) caml__frame;
1632 #else
1633   /* Check that the symbol virStoragePoolGetName
1634    * is in runtime version of libvirt.
1635    */
1636   WEAK_SYMBOL_CHECK (virStoragePoolGetName);
1637
1638   CAMLlocal1 (rv);
1639   virStoragePoolPtr pool = Pool_val (poolv);
1640   virConnectPtr conn = Connect_polv (poolv);
1641   const char *r;
1642
1643   NONBLOCKING (r = virStoragePoolGetName (pool));
1644   CHECK_ERROR (!r, conn, "virStoragePoolGetName");
1645
1646   rv = caml_copy_string (r);
1647   CAMLreturn (rv);
1648 #endif
1649 }
1650
1651 #ifdef HAVE_WEAK_SYMBOLS
1652 #ifdef HAVE_VIRSTORAGEPOOLGETXMLDESC
1653 extern char *virStoragePoolGetXMLDesc (virStoragePoolPtr pool,  int flags) __attribute__((weak));
1654 #endif
1655 #endif
1656
1657 CAMLprim value
1658 ocaml_libvirt_storage_pool_get_xml_desc (value poolv)
1659 {
1660   CAMLparam1 (poolv);
1661 #ifndef HAVE_VIRSTORAGEPOOLGETXMLDESC
1662   /* Symbol virStoragePoolGetXMLDesc not found at compile time. */
1663   not_supported ("virStoragePoolGetXMLDesc");
1664   /* Suppresses a compiler warning. */
1665   (void) caml__frame;
1666 #else
1667   /* Check that the symbol virStoragePoolGetXMLDesc
1668    * is in runtime version of libvirt.
1669    */
1670   WEAK_SYMBOL_CHECK (virStoragePoolGetXMLDesc);
1671
1672   CAMLlocal1 (rv);
1673   virStoragePoolPtr pool = Pool_val (poolv);
1674   virConnectPtr conn = Connect_polv (poolv);
1675   char *r;
1676
1677   NONBLOCKING (r = virStoragePoolGetXMLDesc (pool, 0));
1678   CHECK_ERROR (!r, conn, "virStoragePoolGetXMLDesc");
1679
1680   rv = caml_copy_string (r);
1681   free (r);
1682   CAMLreturn (rv);
1683 #endif
1684 }
1685
1686 #ifdef HAVE_WEAK_SYMBOLS
1687 #ifdef HAVE_VIRSTORAGEPOOLGETUUID
1688 extern int virStoragePoolGetUUID (virStoragePoolPtr pool, unsigned char *) __attribute__((weak));
1689 #endif
1690 #endif
1691
1692 CAMLprim value
1693 ocaml_libvirt_storage_pool_get_uuid (value poolv)
1694 {
1695   CAMLparam1 (poolv);
1696 #ifndef HAVE_VIRSTORAGEPOOLGETUUID
1697   /* Symbol virStoragePoolGetUUID not found at compile time. */
1698   not_supported ("virStoragePoolGetUUID");
1699   /* Suppresses a compiler warning. */
1700   (void) caml__frame;
1701 #else
1702   /* Check that the symbol virStoragePoolGetUUID
1703    * is in runtime version of libvirt.
1704    */
1705   WEAK_SYMBOL_CHECK (virStoragePoolGetUUID);
1706
1707   CAMLlocal1 (rv);
1708   virStoragePoolPtr pool = Pool_val (poolv);
1709   virConnectPtr conn = Connect_polv (poolv);
1710   unsigned char uuid[VIR_UUID_BUFLEN];
1711   int r;
1712
1713   NONBLOCKING (r = virStoragePoolGetUUID (pool, uuid));
1714   CHECK_ERROR (r == -1, conn, "virStoragePoolGetUUID");
1715
1716   rv = caml_copy_string ((char *) uuid);
1717   CAMLreturn (rv);
1718 #endif
1719 }
1720
1721 #ifdef HAVE_WEAK_SYMBOLS
1722 #ifdef HAVE_VIRSTORAGEPOOLGETUUIDSTRING
1723 extern int virStoragePoolGetUUIDString (virStoragePoolPtr pool, char *) __attribute__((weak));
1724 #endif
1725 #endif
1726
1727 CAMLprim value
1728 ocaml_libvirt_storage_pool_get_uuid_string (value poolv)
1729 {
1730   CAMLparam1 (poolv);
1731 #ifndef HAVE_VIRSTORAGEPOOLGETUUIDSTRING
1732   /* Symbol virStoragePoolGetUUIDString not found at compile time. */
1733   not_supported ("virStoragePoolGetUUIDString");
1734   /* Suppresses a compiler warning. */
1735   (void) caml__frame;
1736 #else
1737   /* Check that the symbol virStoragePoolGetUUIDString
1738    * is in runtime version of libvirt.
1739    */
1740   WEAK_SYMBOL_CHECK (virStoragePoolGetUUIDString);
1741
1742   CAMLlocal1 (rv);
1743   virStoragePoolPtr pool = Pool_val (poolv);
1744   virConnectPtr conn = Connect_polv (poolv);
1745   char uuid[VIR_UUID_STRING_BUFLEN];
1746   int r;
1747
1748   NONBLOCKING (r = virStoragePoolGetUUIDString (pool, uuid));
1749   CHECK_ERROR (r == -1, conn, "virStoragePoolGetUUIDString");
1750
1751   rv = caml_copy_string (uuid);
1752   CAMLreturn (rv);
1753 #endif
1754 }
1755
1756 #ifdef HAVE_WEAK_SYMBOLS
1757 #ifdef HAVE_VIRSTORAGEPOOLCREATEXML
1758 extern virStoragePoolPtr virStoragePoolCreateXML (virConnectPtr conn, const char *str) __attribute__((weak));
1759 #endif
1760 #endif
1761
1762 CAMLprim value
1763 ocaml_libvirt_storage_pool_create_xml (value connv, value strv)
1764 {
1765   CAMLparam2 (connv, strv);
1766 #ifndef HAVE_VIRSTORAGEPOOLCREATEXML
1767   /* Symbol virStoragePoolCreateXML not found at compile time. */
1768   not_supported ("virStoragePoolCreateXML");
1769   /* Suppresses a compiler warning. */
1770   (void) caml__frame;
1771 #else
1772   /* Check that the symbol virStoragePoolCreateXML
1773    * is in runtime version of libvirt.
1774    */
1775   WEAK_SYMBOL_CHECK (virStoragePoolCreateXML);
1776
1777   CAMLlocal1 (rv);
1778   virConnectPtr conn = Connect_val (connv);
1779   char *str = String_val (strv);
1780   virStoragePoolPtr r;
1781
1782   NONBLOCKING (r = virStoragePoolCreateXML (conn, str));
1783   CHECK_ERROR (!r, conn, "virStoragePoolCreateXML");
1784
1785   rv = Val_pool (r, connv);
1786
1787   CAMLreturn (rv);
1788 #endif
1789 }
1790
1791 #ifdef HAVE_WEAK_SYMBOLS
1792 #ifdef HAVE_VIRSTORAGEPOOLDEFINEXML
1793 extern virStoragePoolPtr virStoragePoolDefineXML (virConnectPtr conn, const char *str) __attribute__((weak));
1794 #endif
1795 #endif
1796
1797 CAMLprim value
1798 ocaml_libvirt_storage_pool_define_xml (value connv, value strv)
1799 {
1800   CAMLparam2 (connv, strv);
1801 #ifndef HAVE_VIRSTORAGEPOOLDEFINEXML
1802   /* Symbol virStoragePoolDefineXML not found at compile time. */
1803   not_supported ("virStoragePoolDefineXML");
1804   /* Suppresses a compiler warning. */
1805   (void) caml__frame;
1806 #else
1807   /* Check that the symbol virStoragePoolDefineXML
1808    * is in runtime version of libvirt.
1809    */
1810   WEAK_SYMBOL_CHECK (virStoragePoolDefineXML);
1811
1812   CAMLlocal1 (rv);
1813   virConnectPtr conn = Connect_val (connv);
1814   char *str = String_val (strv);
1815   virStoragePoolPtr r;
1816
1817   NONBLOCKING (r = virStoragePoolDefineXML (conn, str));
1818   CHECK_ERROR (!r, conn, "virStoragePoolDefineXML");
1819
1820   rv = Val_pool (r, connv);
1821
1822   CAMLreturn (rv);
1823 #endif
1824 }
1825
1826 #ifdef HAVE_WEAK_SYMBOLS
1827 #ifdef HAVE_VIRSTORAGEPOOLUNDEFINE
1828 extern int virStoragePoolUndefine (virStoragePoolPtr pool) __attribute__((weak));
1829 #endif
1830 #endif
1831
1832 CAMLprim value
1833 ocaml_libvirt_storage_pool_undefine (value poolv)
1834 {
1835   CAMLparam1 (poolv);
1836 #ifndef HAVE_VIRSTORAGEPOOLUNDEFINE
1837   /* Symbol virStoragePoolUndefine not found at compile time. */
1838   not_supported ("virStoragePoolUndefine");
1839   /* Suppresses a compiler warning. */
1840   (void) caml__frame;
1841 #else
1842   /* Check that the symbol virStoragePoolUndefine
1843    * is in runtime version of libvirt.
1844    */
1845   WEAK_SYMBOL_CHECK (virStoragePoolUndefine);
1846
1847   virStoragePoolPtr pool = Pool_val (poolv);
1848   virConnectPtr conn = Connect_polv (poolv);
1849   int r;
1850
1851   NONBLOCKING (r = virStoragePoolUndefine (pool));
1852   CHECK_ERROR (r == -1, conn, "virStoragePoolUndefine");
1853
1854   CAMLreturn (Val_unit);
1855 #endif
1856 }
1857
1858 #ifdef HAVE_WEAK_SYMBOLS
1859 #ifdef HAVE_VIRSTORAGEPOOLCREATE
1860 extern int virStoragePoolCreate (virStoragePoolPtr pool) __attribute__((weak));
1861 #endif
1862 #endif
1863
1864 CAMLprim value
1865 ocaml_libvirt_storage_pool_create (value poolv)
1866 {
1867   CAMLparam1 (poolv);
1868 #ifndef HAVE_VIRSTORAGEPOOLCREATE
1869   /* Symbol virStoragePoolCreate not found at compile time. */
1870   not_supported ("virStoragePoolCreate");
1871   /* Suppresses a compiler warning. */
1872   (void) caml__frame;
1873 #else
1874   /* Check that the symbol virStoragePoolCreate
1875    * is in runtime version of libvirt.
1876    */
1877   WEAK_SYMBOL_CHECK (virStoragePoolCreate);
1878
1879   virStoragePoolPtr pool = Pool_val (poolv);
1880   virConnectPtr conn = Connect_polv (poolv);
1881   int r;
1882
1883   NONBLOCKING (r = virStoragePoolCreate (pool));
1884   CHECK_ERROR (r == -1, conn, "virStoragePoolCreate");
1885
1886   CAMLreturn (Val_unit);
1887 #endif
1888 }
1889
1890 #ifdef HAVE_WEAK_SYMBOLS
1891 #ifdef HAVE_VIRSTORAGEPOOLSHUTDOWN
1892 extern int virStoragePoolShutdown (virStoragePoolPtr pool) __attribute__((weak));
1893 #endif
1894 #endif
1895
1896 CAMLprim value
1897 ocaml_libvirt_storage_pool_shutdown (value poolv)
1898 {
1899   CAMLparam1 (poolv);
1900 #ifndef HAVE_VIRSTORAGEPOOLSHUTDOWN
1901   /* Symbol virStoragePoolShutdown not found at compile time. */
1902   not_supported ("virStoragePoolShutdown");
1903   /* Suppresses a compiler warning. */
1904   (void) caml__frame;
1905 #else
1906   /* Check that the symbol virStoragePoolShutdown
1907    * is in runtime version of libvirt.
1908    */
1909   WEAK_SYMBOL_CHECK (virStoragePoolShutdown);
1910
1911   virStoragePoolPtr pool = Pool_val (poolv);
1912   virConnectPtr conn = Connect_polv (poolv);
1913   int r;
1914
1915   NONBLOCKING (r = virStoragePoolShutdown (pool));
1916   CHECK_ERROR (r == -1, conn, "virStoragePoolShutdown");
1917
1918   CAMLreturn (Val_unit);
1919 #endif
1920 }
1921
1922 #ifdef HAVE_WEAK_SYMBOLS
1923 #ifdef HAVE_VIRSTORAGEPOOLREFRESH
1924 extern int virStoragePoolRefresh (virStoragePoolPtr pool, unsigned  int flags) __attribute__((weak));
1925 #endif
1926 #endif
1927
1928 CAMLprim value
1929 ocaml_libvirt_storage_pool_refresh (value poolv)
1930 {
1931   CAMLparam1 (poolv);
1932 #ifndef HAVE_VIRSTORAGEPOOLREFRESH
1933   /* Symbol virStoragePoolRefresh not found at compile time. */
1934   not_supported ("virStoragePoolRefresh");
1935   /* Suppresses a compiler warning. */
1936   (void) caml__frame;
1937 #else
1938   /* Check that the symbol virStoragePoolRefresh
1939    * is in runtime version of libvirt.
1940    */
1941   WEAK_SYMBOL_CHECK (virStoragePoolRefresh);
1942
1943   virStoragePoolPtr pool = Pool_val (poolv);
1944   virConnectPtr conn = Connect_polv (poolv);
1945   int r;
1946
1947   NONBLOCKING (r = virStoragePoolRefresh (pool, 0));
1948   CHECK_ERROR (r == -1, conn, "virStoragePoolRefresh");
1949
1950   CAMLreturn (Val_unit);
1951 #endif
1952 }
1953
1954 #ifdef HAVE_WEAK_SYMBOLS
1955 #ifdef HAVE_VIRSTORAGEPOOLGETAUTOSTART
1956 extern int virStoragePoolGetAutostart (virStoragePoolPtr pool, int *r) __attribute__((weak));
1957 #endif
1958 #endif
1959
1960 CAMLprim value
1961 ocaml_libvirt_storage_pool_get_autostart (value poolv)
1962 {
1963   CAMLparam1 (poolv);
1964 #ifndef HAVE_VIRSTORAGEPOOLGETAUTOSTART
1965   /* Symbol virStoragePoolGetAutostart not found at compile time. */
1966   not_supported ("virStoragePoolGetAutostart");
1967   /* Suppresses a compiler warning. */
1968   (void) caml__frame;
1969 #else
1970   /* Check that the symbol virStoragePoolGetAutostart
1971    * is in runtime version of libvirt.
1972    */
1973   WEAK_SYMBOL_CHECK (virStoragePoolGetAutostart);
1974
1975   virStoragePoolPtr pool = Pool_val (poolv);
1976   virConnectPtr conn = Connect_polv (poolv);
1977   int r, b;
1978
1979   NONBLOCKING (r = virStoragePoolGetAutostart (pool, &b));
1980   CHECK_ERROR (r == -1, conn, "virStoragePoolGetAutostart");
1981
1982   CAMLreturn (b ? Val_true : Val_false);
1983 #endif
1984 }
1985
1986 #ifdef HAVE_WEAK_SYMBOLS
1987 #ifdef HAVE_VIRSTORAGEPOOLSETAUTOSTART
1988 extern int virStoragePoolSetAutostart (virStoragePoolPtr pool, int b) __attribute__((weak));
1989 #endif
1990 #endif
1991
1992 CAMLprim value
1993 ocaml_libvirt_storage_pool_set_autostart (value poolv, value bv)
1994 {
1995   CAMLparam2 (poolv, bv);
1996 #ifndef HAVE_VIRSTORAGEPOOLSETAUTOSTART
1997   /* Symbol virStoragePoolSetAutostart not found at compile time. */
1998   not_supported ("virStoragePoolSetAutostart");
1999   /* Suppresses a compiler warning. */
2000   (void) caml__frame;
2001 #else
2002   /* Check that the symbol virStoragePoolSetAutostart
2003    * is in runtime version of libvirt.
2004    */
2005   WEAK_SYMBOL_CHECK (virStoragePoolSetAutostart);
2006
2007   virStoragePoolPtr pool = Pool_val (poolv);
2008   virConnectPtr conn = Connect_polv (poolv);
2009   int r, b;
2010
2011   b = bv == Val_true ? 1 : 0;
2012
2013   NONBLOCKING (r = virStoragePoolSetAutostart (pool, b));
2014   CHECK_ERROR (r == -1, conn, "virStoragePoolSetAutostart");
2015
2016   CAMLreturn (Val_unit);
2017 #endif
2018 }
2019
2020 #ifdef HAVE_WEAK_SYMBOLS
2021 #ifdef HAVE_VIRSTORAGEVOLFREE
2022 extern int virStorageVolFree (virStorageVolPtr vol) __attribute__((weak));
2023 #endif
2024 #endif
2025
2026 CAMLprim value
2027 ocaml_libvirt_storage_vol_free (value volv)
2028 {
2029   CAMLparam1 (volv);
2030 #ifndef HAVE_VIRSTORAGEVOLFREE
2031   /* Symbol virStorageVolFree not found at compile time. */
2032   not_supported ("virStorageVolFree");
2033   /* Suppresses a compiler warning. */
2034   (void) caml__frame;
2035 #else
2036   /* Check that the symbol virStorageVolFree
2037    * is in runtime version of libvirt.
2038    */
2039   WEAK_SYMBOL_CHECK (virStorageVolFree);
2040
2041   virStorageVolPtr vol = Volume_val (volv);
2042   virConnectPtr conn = Connect_volv (volv);
2043   int r;
2044
2045   NONBLOCKING (r = virStorageVolFree (vol));
2046   CHECK_ERROR (r == -1, conn, "virStorageVolFree");
2047
2048   /* So that we don't double-free in the finalizer: */
2049   Volume_val (volv) = NULL;
2050
2051   CAMLreturn (Val_unit);
2052 #endif
2053 }
2054
2055 #ifdef HAVE_WEAK_SYMBOLS
2056 #ifdef HAVE_VIRSTORAGEVOLDESTROY
2057 extern int virStorageVolDestroy (virStorageVolPtr vol) __attribute__((weak));
2058 #endif
2059 #endif
2060
2061 CAMLprim value
2062 ocaml_libvirt_storage_vol_destroy (value volv)
2063 {
2064   CAMLparam1 (volv);
2065 #ifndef HAVE_VIRSTORAGEVOLDESTROY
2066   /* Symbol virStorageVolDestroy not found at compile time. */
2067   not_supported ("virStorageVolDestroy");
2068   /* Suppresses a compiler warning. */
2069   (void) caml__frame;
2070 #else
2071   /* Check that the symbol virStorageVolDestroy
2072    * is in runtime version of libvirt.
2073    */
2074   WEAK_SYMBOL_CHECK (virStorageVolDestroy);
2075
2076   virStorageVolPtr vol = Volume_val (volv);
2077   virConnectPtr conn = Connect_volv (volv);
2078   int r;
2079
2080   NONBLOCKING (r = virStorageVolDestroy (vol));
2081   CHECK_ERROR (r == -1, conn, "virStorageVolDestroy");
2082
2083   /* So that we don't double-free in the finalizer: */
2084   Volume_val (volv) = NULL;
2085
2086   CAMLreturn (Val_unit);
2087 #endif
2088 }
2089
2090 #ifdef HAVE_WEAK_SYMBOLS
2091 #ifdef HAVE_VIRSTORAGEVOLLOOKUPBYKEY
2092 extern virStorageVolPtr virStorageVolLookupByKey (virConnectPtr conn, const char *str) __attribute__((weak));
2093 #endif
2094 #endif
2095
2096 CAMLprim value
2097 ocaml_libvirt_storage_vol_lookup_by_key (value connv, value strv)
2098 {
2099   CAMLparam2 (connv, strv);
2100 #ifndef HAVE_VIRSTORAGEVOLLOOKUPBYKEY
2101   /* Symbol virStorageVolLookupByKey not found at compile time. */
2102   not_supported ("virStorageVolLookupByKey");
2103   /* Suppresses a compiler warning. */
2104   (void) caml__frame;
2105 #else
2106   /* Check that the symbol virStorageVolLookupByKey
2107    * is in runtime version of libvirt.
2108    */
2109   WEAK_SYMBOL_CHECK (virStorageVolLookupByKey);
2110
2111   CAMLlocal1 (rv);
2112   virConnectPtr conn = Connect_val (connv);
2113   char *str = String_val (strv);
2114   virStorageVolPtr r;
2115
2116   NONBLOCKING (r = virStorageVolLookupByKey (conn, str));
2117   CHECK_ERROR (!r, conn, "virStorageVolLookupByKey");
2118
2119   rv = Val_volume (r, connv);
2120
2121   CAMLreturn (rv);
2122 #endif
2123 }
2124
2125 #ifdef HAVE_WEAK_SYMBOLS
2126 #ifdef HAVE_VIRSTORAGEVOLLOOKUPBYPATH
2127 extern virStorageVolPtr virStorageVolLookupByPath (virConnectPtr conn, const char *str) __attribute__((weak));
2128 #endif
2129 #endif
2130
2131 CAMLprim value
2132 ocaml_libvirt_storage_vol_lookup_by_path (value connv, value strv)
2133 {
2134   CAMLparam2 (connv, strv);
2135 #ifndef HAVE_VIRSTORAGEVOLLOOKUPBYPATH
2136   /* Symbol virStorageVolLookupByPath not found at compile time. */
2137   not_supported ("virStorageVolLookupByPath");
2138   /* Suppresses a compiler warning. */
2139   (void) caml__frame;
2140 #else
2141   /* Check that the symbol virStorageVolLookupByPath
2142    * is in runtime version of libvirt.
2143    */
2144   WEAK_SYMBOL_CHECK (virStorageVolLookupByPath);
2145
2146   CAMLlocal1 (rv);
2147   virConnectPtr conn = Connect_val (connv);
2148   char *str = String_val (strv);
2149   virStorageVolPtr r;
2150
2151   NONBLOCKING (r = virStorageVolLookupByPath (conn, str));
2152   CHECK_ERROR (!r, conn, "virStorageVolLookupByPath");
2153
2154   rv = Val_volume (r, connv);
2155
2156   CAMLreturn (rv);
2157 #endif
2158 }
2159
2160 #ifdef HAVE_WEAK_SYMBOLS
2161 #ifdef HAVE_VIRSTORAGEVOLGETXMLDESC
2162 extern char *virStorageVolGetXMLDesc (virStorageVolPtr vol,  int flags) __attribute__((weak));
2163 #endif
2164 #endif
2165
2166 CAMLprim value
2167 ocaml_libvirt_storage_vol_get_xml_desc (value volv)
2168 {
2169   CAMLparam1 (volv);
2170 #ifndef HAVE_VIRSTORAGEVOLGETXMLDESC
2171   /* Symbol virStorageVolGetXMLDesc not found at compile time. */
2172   not_supported ("virStorageVolGetXMLDesc");
2173   /* Suppresses a compiler warning. */
2174   (void) caml__frame;
2175 #else
2176   /* Check that the symbol virStorageVolGetXMLDesc
2177    * is in runtime version of libvirt.
2178    */
2179   WEAK_SYMBOL_CHECK (virStorageVolGetXMLDesc);
2180
2181   CAMLlocal1 (rv);
2182   virStorageVolPtr vol = Volume_val (volv);
2183   virConnectPtr conn = Connect_volv (volv);
2184   char *r;
2185
2186   NONBLOCKING (r = virStorageVolGetXMLDesc (vol, 0));
2187   CHECK_ERROR (!r, conn, "virStorageVolGetXMLDesc");
2188
2189   rv = caml_copy_string (r);
2190   free (r);
2191   CAMLreturn (rv);
2192 #endif
2193 }
2194
2195 #ifdef HAVE_WEAK_SYMBOLS
2196 #ifdef HAVE_VIRSTORAGEVOLGETPATH
2197 extern char *virStorageVolGetPath (virStorageVolPtr vol) __attribute__((weak));
2198 #endif
2199 #endif
2200
2201 CAMLprim value
2202 ocaml_libvirt_storage_vol_get_path (value volv)
2203 {
2204   CAMLparam1 (volv);
2205 #ifndef HAVE_VIRSTORAGEVOLGETPATH
2206   /* Symbol virStorageVolGetPath not found at compile time. */
2207   not_supported ("virStorageVolGetPath");
2208   /* Suppresses a compiler warning. */
2209   (void) caml__frame;
2210 #else
2211   /* Check that the symbol virStorageVolGetPath
2212    * is in runtime version of libvirt.
2213    */
2214   WEAK_SYMBOL_CHECK (virStorageVolGetPath);
2215
2216   CAMLlocal1 (rv);
2217   virStorageVolPtr vol = Volume_val (volv);
2218   virConnectPtr conn = Connect_volv (volv);
2219   char *r;
2220
2221   NONBLOCKING (r = virStorageVolGetPath (vol));
2222   CHECK_ERROR (!r, conn, "virStorageVolGetPath");
2223
2224   rv = caml_copy_string (r);
2225   free (r);
2226   CAMLreturn (rv);
2227 #endif
2228 }
2229
2230 #ifdef HAVE_WEAK_SYMBOLS
2231 #ifdef HAVE_VIRSTORAGEVOLGETKEY
2232 extern const char *virStorageVolGetKey (virStorageVolPtr vol) __attribute__((weak));
2233 #endif
2234 #endif
2235
2236 CAMLprim value
2237 ocaml_libvirt_storage_vol_get_key (value volv)
2238 {
2239   CAMLparam1 (volv);
2240 #ifndef HAVE_VIRSTORAGEVOLGETKEY
2241   /* Symbol virStorageVolGetKey not found at compile time. */
2242   not_supported ("virStorageVolGetKey");
2243   /* Suppresses a compiler warning. */
2244   (void) caml__frame;
2245 #else
2246   /* Check that the symbol virStorageVolGetKey
2247    * is in runtime version of libvirt.
2248    */
2249   WEAK_SYMBOL_CHECK (virStorageVolGetKey);
2250
2251   CAMLlocal1 (rv);
2252   virStorageVolPtr vol = Volume_val (volv);
2253   virConnectPtr conn = Connect_volv (volv);
2254   const char *r;
2255
2256   NONBLOCKING (r = virStorageVolGetKey (vol));
2257   CHECK_ERROR (!r, conn, "virStorageVolGetKey");
2258
2259   rv = caml_copy_string (r);
2260   CAMLreturn (rv);
2261 #endif
2262 }
2263
2264 #ifdef HAVE_WEAK_SYMBOLS
2265 #ifdef HAVE_VIRSTORAGEVOLGETNAME
2266 extern const char *virStorageVolGetName (virStorageVolPtr vol) __attribute__((weak));
2267 #endif
2268 #endif
2269
2270 CAMLprim value
2271 ocaml_libvirt_storage_vol_get_name (value volv)
2272 {
2273   CAMLparam1 (volv);
2274 #ifndef HAVE_VIRSTORAGEVOLGETNAME
2275   /* Symbol virStorageVolGetName not found at compile time. */
2276   not_supported ("virStorageVolGetName");
2277   /* Suppresses a compiler warning. */
2278   (void) caml__frame;
2279 #else
2280   /* Check that the symbol virStorageVolGetName
2281    * is in runtime version of libvirt.
2282    */
2283   WEAK_SYMBOL_CHECK (virStorageVolGetName);
2284
2285   CAMLlocal1 (rv);
2286   virStorageVolPtr vol = Volume_val (volv);
2287   virConnectPtr conn = Connect_volv (volv);
2288   const char *r;
2289
2290   NONBLOCKING (r = virStorageVolGetName (vol));
2291   CHECK_ERROR (!r, conn, "virStorageVolGetName");
2292
2293   rv = caml_copy_string (r);
2294   CAMLreturn (rv);
2295 #endif
2296 }
2297
2298 #ifdef HAVE_WEAK_SYMBOLS
2299 #ifdef HAVE_VIRSTORAGEPOOLLOOKUPBYVOLUME
2300 extern virStoragePoolPtr virStoragePoolLookupByVolume (virStorageVolPtr vol) __attribute__((weak));
2301 #endif
2302 #endif
2303
2304 CAMLprim value
2305 ocaml_libvirt_storage_pool_lookup_by_volume (value volv)
2306 {
2307   CAMLparam1 (volv);
2308 #ifndef HAVE_VIRSTORAGEPOOLLOOKUPBYVOLUME
2309   /* Symbol virStoragePoolLookupByVolume not found at compile time. */
2310   not_supported ("virStoragePoolLookupByVolume");
2311   /* Suppresses a compiler warning. */
2312   (void) caml__frame;
2313 #else
2314   /* Check that the symbol virStoragePoolLookupByVolume
2315    * is in runtime version of libvirt.
2316    */
2317   WEAK_SYMBOL_CHECK (virStoragePoolLookupByVolume);
2318
2319   CAMLlocal2 (rv, connv);
2320   virStorageVolPtr vol = Volume_val (volv);
2321   virConnectPtr conn = Connect_volv (volv);
2322   virStoragePoolPtr r;
2323
2324   NONBLOCKING (r = virStoragePoolLookupByVolume (vol));
2325   CHECK_ERROR (!r, conn, "virStoragePoolLookupByVolume");
2326
2327   connv = Field (volv, 1);
2328   rv = Val_pool (r, connv);
2329
2330   CAMLreturn (rv);
2331 #endif
2332 }
2333
2334 #ifdef HAVE_WEAK_SYMBOLS
2335 #ifdef HAVE_VIRJOBFREE
2336 extern int virJobFree (virJobPtr job) __attribute__((weak));
2337 #endif
2338 #endif
2339
2340 CAMLprim value
2341 ocaml_libvirt_job_free (value jobv)
2342 {
2343   CAMLparam1 (jobv);
2344 #ifndef HAVE_VIRJOBFREE
2345   /* Symbol virJobFree not found at compile time. */
2346   not_supported ("virJobFree");
2347   /* Suppresses a compiler warning. */
2348   (void) caml__frame;
2349 #else
2350   /* Check that the symbol virJobFree
2351    * is in runtime version of libvirt.
2352    */
2353   WEAK_SYMBOL_CHECK (virJobFree);
2354
2355   virJobPtr job = Job_val (jobv);
2356   virConnectPtr conn = Connect_jobv (jobv);
2357   int r;
2358
2359   NONBLOCKING (r = virJobFree (job));
2360   CHECK_ERROR (r == -1, conn, "virJobFree");
2361
2362   /* So that we don't double-free in the finalizer: */
2363   Job_val (jobv) = NULL;
2364
2365   CAMLreturn (Val_unit);
2366 #endif
2367 }
2368
2369 #ifdef HAVE_WEAK_SYMBOLS
2370 #ifdef HAVE_VIRJOBCANCEL
2371 extern int virJobCancel (virJobPtr job) __attribute__((weak));
2372 #endif
2373 #endif
2374
2375 CAMLprim value
2376 ocaml_libvirt_job_cancel (value jobv)
2377 {
2378   CAMLparam1 (jobv);
2379 #ifndef HAVE_VIRJOBCANCEL
2380   /* Symbol virJobCancel not found at compile time. */
2381   not_supported ("virJobCancel");
2382   /* Suppresses a compiler warning. */
2383   (void) caml__frame;
2384 #else
2385   /* Check that the symbol virJobCancel
2386    * is in runtime version of libvirt.
2387    */
2388   WEAK_SYMBOL_CHECK (virJobCancel);
2389
2390   virJobPtr job = Job_val (jobv);
2391   virConnectPtr conn = Connect_jobv (jobv);
2392   int r;
2393
2394   NONBLOCKING (r = virJobCancel (job));
2395   CHECK_ERROR (r == -1, conn, "virJobCancel");
2396
2397   CAMLreturn (Val_unit);
2398 #endif
2399 }
2400
2401 #ifdef HAVE_WEAK_SYMBOLS
2402 #ifdef HAVE_VIRJOBGETNETWORK
2403 extern virNetworkPtr virJobGetNetwork (virJobPtr job) __attribute__((weak));
2404 #endif
2405 #endif
2406
2407 CAMLprim value
2408 ocaml_libvirt_job_get_network (value jobv)
2409 {
2410   CAMLparam1 (jobv);
2411 #ifndef HAVE_VIRJOBGETNETWORK
2412   /* Symbol virJobGetNetwork not found at compile time. */
2413   not_supported ("virJobGetNetwork");
2414   /* Suppresses a compiler warning. */
2415   (void) caml__frame;
2416 #else
2417   /* Check that the symbol virJobGetNetwork
2418    * is in runtime version of libvirt.
2419    */
2420   WEAK_SYMBOL_CHECK (virJobGetNetwork);
2421
2422   CAMLlocal2 (rv, connv);
2423   virJobPtr job = Job_val (jobv);
2424   virConnectPtr conn = Connect_jobv (jobv);
2425   virNetworkPtr r;
2426
2427   NONBLOCKING (r = virJobGetNetwork (job));
2428   CHECK_ERROR (!r, conn, "virJobGetNetwork");
2429
2430   connv = Field (jobv, 1);
2431   rv = Val_network (r, connv);
2432
2433   CAMLreturn (rv);
2434 #endif
2435 }
2436
2437 #ifdef HAVE_WEAK_SYMBOLS
2438 #ifdef HAVE_VIRJOBGETDOMAIN
2439 extern virDomainPtr virJobGetDomain (virJobPtr job) __attribute__((weak));
2440 #endif
2441 #endif
2442
2443 CAMLprim value
2444 ocaml_libvirt_job_get_domain (value jobv)
2445 {
2446   CAMLparam1 (jobv);
2447 #ifndef HAVE_VIRJOBGETDOMAIN
2448   /* Symbol virJobGetDomain not found at compile time. */
2449   not_supported ("virJobGetDomain");
2450   /* Suppresses a compiler warning. */
2451   (void) caml__frame;
2452 #else
2453   /* Check that the symbol virJobGetDomain
2454    * is in runtime version of libvirt.
2455    */
2456   WEAK_SYMBOL_CHECK (virJobGetDomain);
2457
2458   CAMLlocal2 (rv, connv);
2459   virJobPtr job = Job_val (jobv);
2460   virConnectPtr conn = Connect_jobv (jobv);
2461   virDomainPtr r;
2462
2463   NONBLOCKING (r = virJobGetDomain (job));
2464   CHECK_ERROR (!r, conn, "virJobGetDomain");
2465
2466   connv = Field (jobv, 1);
2467   rv = Val_domain (r, connv);
2468
2469   CAMLreturn (rv);
2470 #endif
2471 }
2472
2473 /* The following functions are unimplemented and always fail.
2474  * See generator.pl '@unimplemented'
2475  */
2476
2477 CAMLprim value
2478 ocaml_libvirt_storage_pool_get_info ()
2479 {
2480   failwith ("ocaml_libvirt_storage_pool_get_info is unimplemented");
2481 }
2482
2483 CAMLprim value
2484 ocaml_libvirt_storage_vol_lookup_by_name ()
2485 {
2486   failwith ("ocaml_libvirt_storage_vol_lookup_by_name is unimplemented");
2487 }
2488
2489 CAMLprim value
2490 ocaml_libvirt_storage_vol_create_xml ()
2491 {
2492   failwith ("ocaml_libvirt_storage_vol_create_xml is unimplemented");
2493 }
2494
2495 CAMLprim value
2496 ocaml_libvirt_storage_vol_get_info ()
2497 {
2498   failwith ("ocaml_libvirt_storage_vol_get_info is unimplemented");
2499 }
2500
2501 CAMLprim value
2502 ocaml_libvirt_job_get_info ()
2503 {
2504   failwith ("ocaml_libvirt_job_get_info is unimplemented");
2505 }
2506
2507 #include "libvirt_c_epilogue.c"
2508
2509 /* EOF */