open Virt_df_gettext.Gettext
-let debug = true (* If true emit lots of debugging information. *)
-
let ( +* ) = Int32.add
let ( -* ) = Int32.sub
let ( ** ) = Int32.mul
let ( *^ ) = Int64.mul
let ( /^ ) = Int64.div
+let debug = ref false
let uri = ref None
let inodes = ref false
let human = ref false
(* Probe a device for partitions. Returns [Some parts] or [None]. *)
let probe_for_partitions dev =
- if debug then eprintf "probing for partitions on %s ...\n%!" dev#name;
+ if !debug then eprintf "probing for partitions on %s ...\n%!" dev#name;
let rec loop = function
| [] -> None
| (parts_name, probe_fn) :: rest ->
with Not_found -> loop rest
in
let r = loop !partition_types in
- if debug then (
+ if !debug then (
match r with
| None -> eprintf "no partitions found on %s\n%!" dev#name
| Some { parts_name = name; parts = parts } ->
(* Probe a device for a filesystem. Returns [Some fs] or [None]. *)
let probe_for_filesystem dev =
- if debug then eprintf "probing for a filesystem on %s ...\n%!" dev#name;
+ if !debug then eprintf "probing for a filesystem on %s ...\n%!" dev#name;
let rec loop = function
| [] -> None
| (fs_name, probe_fn) :: rest ->
with Not_found -> loop rest
in
let r = loop !filesystem_types in
- if debug then (
+ if !debug then (
match r with
| None -> eprintf "no filesystem found on %s\n%!" dev#name
| Some fs ->
(* Probe a device for a PV. Returns [Some lvm_name] or [None]. *)
let probe_for_pv dev =
- if debug then eprintf "probing if %s is a PV ...\n%!" dev#name;
+ if !debug then eprintf "probing if %s is a PV ...\n%!" dev#name;
let rec loop = function
| [] -> None
| (lvm_name, (probe_fn, _)) :: rest ->
with Not_found -> loop rest
in
let r = loop !lvm_types in
- if debug then (
+ if !debug then (
match r with
| None -> eprintf "no PV found on %s\n%!" dev#name
| Some { lvm_plugin_id = name } ->
used throughout the plug-ins and main code.
*)
-val debug : bool
-(** If true, emit logs of debugging information to stderr. *)
-
val ( +* ) : int32 -> int32 -> int32
val ( -* ) : int32 -> int32 -> int32
val ( ** ) : int32 -> int32 -> int32
val ( /^ ) : int64 -> int64 -> int64
(** int32 and int64 infix operators for convenience. *)
+val debug : bool ref (** If true, emit debug info to stderr*)
val uri : string option ref (** Hypervisor/libvirt URI. *)
val inodes : bool ref (** Display inodes. *)
val human : bool ref (** Display human-readable. *)
let rec probe_pv lvm_plugin_id dev =
try
let uuid, _ = read_pv_label dev in
- if debug then
+ if !debug then
eprintf "LVM2 detected PV UUID %s\n%!" uuid;
{ lvm_plugin_id = lvm_plugin_id; pv_uuid = uuid }
with exn ->
- if debug then prerr_endline (Printexc.to_string exn);
+ if !debug then prerr_endline (Printexc.to_string exn);
raise Not_found
and read_pv_label dev =
(sprintf "LVM2: read_pv_label: %s: not an LVM2 physical volume" dev#name)
and read_metadata dev offset32 len32 =
- if debug then
+ if !debug then
eprintf "metadata: offset 0x%lx len %ld bytes\n%!" offset32 len32;
(* Check the offset and length are sensible. *)
vgname, (pvuuids, vgmeta)) vgs in
(* Print the VGs. *)
- if debug then
+ if !debug then
List.iter (
fun (vgname, (pvuuids, vgmeta)) ->
eprintf "VG %s is on PVs: %s\n%!" vgname (String.concat "," pvuuids)
) vgs in
(* Print the LVs. *)
- if debug then
+ if !debug then
List.iter (
fun (vgname, (pvuuids, vgmeta, lvs)) ->
let lvnames = List.map fst lvs in
"uri " ^ s_ "Connect to URI (default: Xen)";
"--connect", Arg.String set_uri,
"uri " ^ s_ "Connect to URI (default: Xen)";
+ "--debug", Arg.Set debug,
+ " " ^ s_ "Debug mode (default: false)";
"-h", Arg.Set human,
" " ^ s_ "Print sizes in human-readable format";
"--human-readable", Arg.Set human,
and make_mbr_entry part_status dev partno part_type first_lba part_size =
let first_lba = uint64_of_int32 first_lba in
let part_size = uint64_of_int32 part_size in
- eprintf "first_lba = %Lx\n" first_lba;
- eprintf "part_size = %Lx\n" part_size;
+ if !debug then
+ eprintf "make_mbr_entry: first_lba = %Lx part_size = %Lx\n%!"
+ first_lba part_size;
{ part_status = part_status;
part_type = part_type;
part_dev = new partition_device dev partno first_lba part_size;