From f1f314e84bd2daef18b983eb1c2e10a7614c57bb Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] 2007-09-18 Richard Jones * virt-df/virt_df.ml: Handle domains with partition-backed block devices. * virt-top/virt_top.ml: Don't fail on older libvirt which would give an error if list_domains or list_defined_domains was called with n = 0. * ChangeLog: Start tracking changes. --- ChangeLog | 11 +++++++++++ virt-df/virt_df.ml | 29 ++++++++++++++++++++++------- virt-top/virt_top.ml | 8 ++++++-- 3 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 ChangeLog diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..dc30cd4 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,11 @@ +2007-09-18 Richard Jones + + * virt-df/virt_df.ml: Handle domains with partition-backed + block devices. + + * virt-top/virt_top.ml: Don't fail on older libvirt which would + give an error if list_domains or list_defined_domains was called + with n = 0. + + * ChangeLog: Start tracking changes. + diff --git a/virt-df/virt_df.ml b/virt-df/virt_df.ml index 26c73c6..d651fa3 100644 --- a/virt-df/virt_df.ml +++ b/virt-df/virt_df.ml @@ -75,8 +75,8 @@ type domain = { and disk = { d_type : string option; (* The *) d_device : string option; (* The *) - d_file : string option; (* The *) - d_dev : string option; (* The *) + d_source : string option; (* The *) + d_target : string option; (* The *) } let doms : domain list = @@ -127,6 +127,14 @@ let doms : domain list = | _ :: rest -> source_file_of rest in + let rec source_dev_of = function + | [] -> None + | Xml.Element ("source", attrs, _) :: rest -> + (try Some (List.assoc "dev" attrs) + with Not_found -> source_dev_of rest) + | _ :: rest -> source_dev_of rest + in + let disks = List.filter_map ( function @@ -137,11 +145,15 @@ let doms : domain list = let device = try Some (List.assoc "device" attrs) with Not_found -> None in - let file = source_file_of children in - let dev = target_dev_of children in + let source = + match source_file_of children with + | (Some _) as source -> source + | None -> source_dev_of children in + let target = target_dev_of children in Some { - d_type = typ; d_device = device; d_file = file; d_dev = dev + d_type = typ; d_device = device; + d_source = source; d_target = target } | _ -> None ) devices in @@ -156,8 +168,11 @@ let () = printf "%s:\n" dom_name; List.iter ( function - | { d_file = Some file; d_dev = Some dev } -> - printf "\t%s -> %s\n" file dev + | { d_source = Some source; d_target = Some target } -> + printf "\t%s -> %s\n" source target + | { d_type = None; d_device = Some "cdrom"; + d_source = None; d_target = Some target } -> + printf "\t[CD] -> %s\n" target | _ -> printf "\t(device omitted, missing or in XML\n"; ) dom_disks diff --git a/virt-top/virt_top.ml b/virt-top/virt_top.ml index 7a041b2..e2a7435 100644 --- a/virt-top/virt_top.ml +++ b/virt-top/virt_top.ml @@ -439,7 +439,9 @@ let redraw, clear_pcpu_display_data = let doms = (* Active domains. *) let n = C.num_of_domains conn in - let ids = Array.to_list (C.list_domains conn n) in + let ids = + if n > 0 then Array.to_list (C.list_domains conn n) + else [] in let doms = List.filter_map ( fun id -> @@ -485,7 +487,9 @@ let redraw, clear_pcpu_display_data = (* Inactive domains. *) let n = C.num_of_defined_domains conn in - let names = Array.to_list (C.list_defined_domains conn n) in + let names = + if n > 0 then Array.to_list (C.list_defined_domains conn n) + else [] in let doms_inactive = List.map (fun name -> name, Inactive) names in doms @ doms_inactive in -- 1.8.3.1