From 4c713977ca6e6b2daf1b860f42d40e2ef1ef98b2 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 5 Mar 2012 16:19:14 +0000 Subject: [PATCH] Remove virConnectListAllDomains. This was never in a released libvirt. --- configure.ac | 1 - libvirt/libvirt.ml | 134 ++++++++++++++++---------------------------- libvirt/libvirt.mli | 22 -------- libvirt/libvirt_c_oneoffs.c | 85 ---------------------------- 4 files changed, 47 insertions(+), 195 deletions(-) diff --git a/configure.ac b/configure.ac index 31a99bb..e6ca675 100644 --- a/configure.ac +++ b/configure.ac @@ -125,7 +125,6 @@ AC_CHECK_FUNCS([virConnectGetHostname \ virStorageVolGetPath \ virDomainBlockPeek \ virDomainMemoryPeek \ - virConnectListAllDomains \ ]) dnl Check for optional types added since 0.2.1. diff --git a/libvirt/libvirt.ml b/libvirt/libvirt.ml index 2ffdac9..9b16650 100644 --- a/libvirt/libvirt.ml +++ b/libvirt/libvirt.ml @@ -375,8 +375,6 @@ struct *) let max_peek _ = 65536 - external list_all_domains : 'a Connect.t -> ?want_info:bool -> list_flag list -> 'a t array * info array = "ocaml_libvirt_connect_list_all_domains" - external create_linux : [>`W] Connect.t -> xml -> rw t = "ocaml_libvirt_domain_create_linux" external lookup_by_id : 'a Connect.t -> int -> 'a t = "ocaml_libvirt_domain_lookup_by_id" external lookup_by_uuid : 'a Connect.t -> uuid -> 'a t = "ocaml_libvirt_domain_lookup_by_uuid" @@ -423,94 +421,56 @@ struct external const : [>`R] t -> ro t = "%identity" - (* First time we are called, we will check if - * virConnectListAllDomains is supported. - *) - let have_list_all_domains = ref None - - let check_have_list_all_domains conn = - match !have_list_all_domains with - | Some v -> v - | None -> - (* Check if virConnectListAllDomains is supported - * by this version of libvirt. - *) - let v = - (* libvirt has a short-cut which makes this very quick ... *) - try ignore (list_all_domains conn []); true - with Not_supported "virConnectListAllDomains" -> false in - have_list_all_domains := Some v; - v - let get_domains conn flags = - let have_list_all_domains = check_have_list_all_domains conn in - - if have_list_all_domains then ( - (* Good, we can use the shiny new method. *) - let doms, _ = list_all_domains conn ~want_info:false flags in - Array.to_list doms - ) - else ( - (* Old/slow/inefficient method. *) - let get_active, get_inactive = - if List.mem ListAll flags then - (true, true) - else - (List.mem ListActive flags, List.mem ListInactive flags) in - let active_doms = - if get_active then ( - let n = Connect.num_of_domains conn in - let ids = Connect.list_domains conn n in - let ids = Array.to_list ids in - map_ignore_errors (lookup_by_id conn) ids - ) else [] in - - let inactive_doms = - if get_inactive then ( - let n = Connect.num_of_defined_domains conn in - let names = Connect.list_defined_domains conn n in - let names = Array.to_list names in - map_ignore_errors (lookup_by_name conn) names - ) else [] in - - active_doms @ inactive_doms - ) + (* Old/slow/inefficient method. *) + let get_active, get_inactive = + if List.mem ListAll flags then + (true, true) + else + (List.mem ListActive flags, List.mem ListInactive flags) in + let active_doms = + if get_active then ( + let n = Connect.num_of_domains conn in + let ids = Connect.list_domains conn n in + let ids = Array.to_list ids in + map_ignore_errors (lookup_by_id conn) ids + ) else [] in + + let inactive_doms = + if get_inactive then ( + let n = Connect.num_of_defined_domains conn in + let names = Connect.list_defined_domains conn n in + let names = Array.to_list names in + map_ignore_errors (lookup_by_name conn) names + ) else [] in + + active_doms @ inactive_doms let get_domains_and_infos conn flags = - let have_list_all_domains = check_have_list_all_domains conn in - - if have_list_all_domains then ( - (* Good, we can use the shiny new method. *) - let doms, infos = list_all_domains conn ~want_info:true flags in - let doms = Array.to_list doms and infos = Array.to_list infos in - List.combine doms infos - ) - else ( - (* Old/slow/inefficient method. *) - let get_active, get_inactive = - if List.mem ListAll flags then - (true, true) - else (List.mem ListActive flags, List.mem ListInactive flags) in - let active_doms = - if get_active then ( - let n = Connect.num_of_domains conn in - let ids = Connect.list_domains conn n in - let ids = Array.to_list ids in - map_ignore_errors (lookup_by_id conn) ids - ) else [] in - - let inactive_doms = - if get_inactive then ( - let n = Connect.num_of_defined_domains conn in - let names = Connect.list_defined_domains conn n in - let names = Array.to_list names in - map_ignore_errors (lookup_by_name conn) names - ) else [] in - - let doms = active_doms @ inactive_doms in - - map_ignore_errors (fun dom -> (dom, get_info dom)) doms - ) + (* Old/slow/inefficient method. *) + let get_active, get_inactive = + if List.mem ListAll flags then + (true, true) + else (List.mem ListActive flags, List.mem ListInactive flags) in + let active_doms = + if get_active then ( + let n = Connect.num_of_domains conn in + let ids = Connect.list_domains conn n in + let ids = Array.to_list ids in + map_ignore_errors (lookup_by_id conn) ids + ) else [] in + + let inactive_doms = + if get_inactive then ( + let n = Connect.num_of_defined_domains conn in + let names = Connect.list_defined_domains conn n in + let names = Array.to_list names in + map_ignore_errors (lookup_by_name conn) names + ) else [] in + + let doms = active_doms @ inactive_doms in + + map_ignore_errors (fun dom -> (dom, get_info dom)) doms end module Network = diff --git a/libvirt/libvirt.mli b/libvirt/libvirt.mli index 695414b..3d7d95f 100644 --- a/libvirt/libvirt.mli +++ b/libvirt/libvirt.mli @@ -468,26 +468,6 @@ sig functions. If you want to peek more than this then you must break your request into chunks. *) - val list_all_domains : 'a Connect.t -> ?want_info:bool -> list_flag list -> 'a t array * info array - (** [list_all_domains conn flags] returns all domains which - match [flags]. - - This can return both active and inactive domains. The - list of flags controls what domains are returned. See - {!list_flag}. - - The two arrays returned will have the same length, unless - [~want_info] is [false] in which case the info array - will be zero-length. The default for [~want_info] is [true]. - In most cases there is no extra penalty for getting the - info fields, or the penalty is insignificant. - - This call was introduced in libvirt 0.4.5. Because you - might dynamically link to an older version of libvirt which - doesn't have this call, you should use {!get_domains} - or {!get_domains_and_infos} which use the most efficient - way to get domains for the available version of libvirt. - *) val create_linux : [>`W] Connect.t -> xml -> rw t (** Create a new guest domain (not necessarily a Linux one) from the given XML. @@ -625,7 +605,6 @@ sig See also: {!get_domains_and_infos}, - {!list_all_domains}, {!Connect.list_domains}, {!Connect.list_defined_domains}. *) @@ -638,7 +617,6 @@ sig See also: {!get_domains}, - {!list_all_domains}, {!Connect.list_domains}, {!Connect.list_defined_domains}, {!get_info}. diff --git a/libvirt/libvirt_c_oneoffs.c b/libvirt/libvirt_c_oneoffs.c index f8fd79d..29a1c05 100644 --- a/libvirt/libvirt_c_oneoffs.c +++ b/libvirt/libvirt_c_oneoffs.c @@ -194,91 +194,6 @@ ocaml_libvirt_connect_node_get_cells_free_memory (value connv, #endif } -#ifdef HAVE_WEAK_SYMBOLS -#ifdef HAVE_VIRCONNECTLISTALLDOMAINS -extern int virConnectListAllDomains (virConnectPtr conn, - virDomainPtr **domains, - virDomainInfo **infos, - unsigned long stateflags, - unsigned long flags) - __attribute__((weak)); -#endif -#endif - -CAMLprim value -ocaml_libvirt_connect_list_all_domains (value connv, - value wantinfov, - value flagsv) -{ -#ifdef HAVE_VIRCONNECTLISTALLDOMAINS - CAMLparam3 (connv, wantinfov, flagsv); - CAMLlocal4 (flagv, rv, rv1, rv2); - CAMLlocal2 (v1, v2); - virConnectPtr conn = Connect_val (connv); - virDomainPtr *domains; - virDomainInfo *infos; - int want_info, i, r, flag; - unsigned long flags = 0; - - /* ?want_info */ - if (wantinfov == Val_int (0)) /* None == true */ - want_info = 1; - else - want_info = Bool_val (Field (wantinfov, 0)); - - /* Iterate over the list of flags. */ - for (; flagsv != Val_int (0); flagsv = Field (flagsv, 1)) { - flagv = Field (flagsv, 0); - flag = Int_val (flagv); - switch (flag) { - case 0: flags |= VIR_DOMAIN_LIST_ACTIVE; break; - case 1: flags |= VIR_DOMAIN_LIST_INACTIVE; break; - case 2: flags |= VIR_DOMAIN_LIST_ALL; break; - } - } - - WEAK_SYMBOL_CHECK (virConnectListAllDomains); - NONBLOCKING (r = virConnectListAllDomains (conn, &domains, - want_info ? &infos : NULL, - flags, 0)); - CHECK_ERROR (r == -1, conn, "virConnectListAllDomains"); - - /* Convert the result into a pair of arrays. */ - rv1 = caml_alloc (r, 0); - for (i = 0; i < r; ++i) { - v1 = Val_domain (domains[i], connv); - Store_field (rv1, i, v1); - } - free (domains); - - if (want_info) { - rv2 = caml_alloc (r, 0); - - for (i = 0; i < r; ++i) { - v1 = caml_alloc (5, 0); - Store_field (v1, 0, Val_int (infos[i].state)); - v2 = caml_copy_int64 (infos[i].maxMem); Store_field (v1, 1, v2); - v2 = caml_copy_int64 (infos[i].memory); Store_field (v1, 2, v2); - Store_field (v1, 3, Val_int (infos[i].nrVirtCpu)); - v2 = caml_copy_int64 (infos[i].cpuTime); Store_field (v1, 4, v2); - - Store_field (rv2, i, v1); - } - - free (infos); - } - else - rv2 = caml_alloc (0, 0); /* zero-length array */ - - rv = caml_alloc_tuple (2); - Store_field (rv, 0, rv1); - Store_field (rv, 1, rv2); - CAMLreturn (rv); -#else - not_supported ("virConnectListAllDomains"); -#endif -} - CAMLprim value ocaml_libvirt_domain_get_id (value domv) { -- 1.8.3.1