(** This exception can be raised by any library function that detects
an error. To get a printable error message, call
{!Virterror.to_string} on the content of this exception.
+*)
- Note that functions may also raise
- [Invalid_argument "virFoo not supported"]
- (where virFoo is the libvirt function name) if a function is
- not supported at either compile or runtime. This applies to
+exception Not_supported of string
+(**
+ Functions may raise
+ [Not_supported "virFoo"]
+ (where [virFoo] is the libvirt function name) if a function is
+ not supported at either compile or run time. This applies to
any libvirt function added after version 0.2.1.
+
See also [http://libvirt.org/hvsupport.html]
*)
typedef value (*Val_ptr_t) (void *);
static value Val_opt (void *ptr, Val_ptr_t Val_ptr);
/*static value option_default (value option, value deflt);*/
-static value _raise_virterror (virConnectPtr conn, const char *fn);
+static void _raise_virterror (virConnectPtr conn, const char *fn);
+static void not_supported (const char *fn);
static value Val_virterror (virErrorPtr err);
/* Use this around synchronous libvirt API calls to release the OCaml
#define CHECK_ERROR(cond, conn, fn) \
do { if (cond) _raise_virterror (conn, fn); } while (0)
-#define NOT_SUPPORTED(fn) \
- caml_invalid_argument (fn " not supported")
-
/* For more about weak symbols, see:
* http://kolpackov.net/pipermail/notes/2004-March/000006.html
* We are using this to do runtime detection of library functions
#ifdef HAVE_WEAK_SYMBOLS
#define WEAK_SYMBOL_CHECK(sym) \
- do { if (!sym) NOT_SUPPORTED(#sym); } while (0)
+ do { if (!sym) not_supported(#sym); } while (0)
#else
#define WEAK_SYMBOL_CHECK(sym)
#endif /* HAVE_WEAK_SYMBOLS */
free (r);
CAMLreturn (rv);
#else
- NOT_SUPPORTED ("virConnectGetHostname");
+ not_supported ("virConnectGetHostname");
#endif
}
free (r);
CAMLreturn (rv);
#else
- NOT_SUPPORTED ("virConnectGetURI");
+ not_supported ("virConnectGetURI");
#endif
}
rv = caml_copy_int64 ((int64) r);
CAMLreturn (rv);
#else
- NOT_SUPPORTED ("virNodeGetFreeMemory");
+ not_supported ("virNodeGetFreeMemory");
#endif
}
CAMLreturn (rv);
#else
- NOT_SUPPORTED ("virNodeGetCellsFreeMemory");
+ not_supported ("virNodeGetCellsFreeMemory");
#endif
}
Store_field (rv, 1, nparams);
CAMLreturn (rv);
#else
- NOT_SUPPORTED ("virDomainGetSchedulerType");
+ not_supported ("virDomainGetSchedulerType");
#endif
}
}
CAMLreturn (rv);
#else
- NOT_SUPPORTED ("virDomainGetSchedulerParameters");
+ not_supported ("virDomainGetSchedulerParameters");
#endif
}
CAMLreturn (Val_unit);
#else
- NOT_SUPPORTED ("virDomainSetSchedulerParameters");
+ not_supported ("virDomainSetSchedulerParameters");
#endif
}
CAMLreturn (rv);
#else /* virDomainMigrate not supported */
- NOT_SUPPORTED ("virDomainMigrate");
+ not_supported ("virDomainMigrate");
#endif
}
CAMLreturn (rv);
#else
- NOT_SUPPORTED ("virDomainBlockStats");
+ not_supported ("virDomainBlockStats");
#endif
}
CAMLreturn (rv);
#else
- NOT_SUPPORTED ("virDomainInterfaceStats");
+ not_supported ("virDomainInterfaceStats");
#endif
}
}
#endif
-static value
+static void
_raise_virterror (virConnectPtr conn, const char *fn)
{
CAMLparam0 ();
caml_raise_with_arg (*caml_named_value ("ocaml_libvirt_virterror"), rv);
/*NOTREACHED*/
- CAMLreturn (Val_unit);
+ CAMLreturn0;
+}
+
+/* Raise an error if a function is not supported. */
+static void
+not_supported (const char *fn)
+{
+ CAMLparam0 ();
+ CAMLlocal1 (fnv);
+
+ fnv = caml_copy_string (fn);
+ caml_raise_with_arg (*caml_named_value ("ocaml_libvirt_not_supported"), fnv);
+
+ /*NOTREACHED*/
+ CAMLreturn0;
}
/* Convert the virErrorNumber, virErrorDomain and virErrorLevel enums
(* qemu:/// and other URIs didn't support virConnectGetHostname until
* libvirt 0.3.3. Before that they'd throw a virterror. *)
| Libvirt.Virterror _
- | Invalid_argument "virConnectGetHostname not supported" -> "unknown" in
+ | Libvirt.Not_supported "virConnectGetHostname" -> "unknown" in
let libvirt_version =
let v, _ = Libvirt.get_version () in
let block_stats =
try List.map (fun dev -> dev, D.block_stats dom dev) blkdevs
with
- | Invalid_argument "virDomainBlockStats not supported"
+ | Libvirt.Not_supported "virDomainBlockStats"
| Libvirt.Virterror _ -> [] in
let interface_stats =
try List.map (fun dev -> dev, D.interface_stats dom dev) netifs
with
- | Invalid_argument "virDomainInterfaceStats not supported"
+ | Libvirt.Not_supported "virDomainInterfaceStats"
| Libvirt.Virterror _ -> [] in
let prev_info, prev_block_stats, prev_interface_stats =