summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2008-04-16 08:15:56 +0100
committerRichard W.M. Jones <rjones@redhat.com>2008-04-16 08:15:56 +0100
commit027b0d92ed236fa24f211e053e81189cddffe7d7 (patch)
treec4c421cc01b9b964bc0cd471e65633f2b8d6cd1d
parent291265b7171d332d2969e07ac189d876e3d7f26d (diff)
downloadvirt-top-027b0d92ed236fa24f211e053e81189cddffe7d7.tar.gz
virt-top-027b0d92ed236fa24f211e053e81189cddffe7d7.tar.xz
virt-top-027b0d92ed236fa24f211e053e81189cddffe7d7.zip
Make debug selectable at runtime.
-rw-r--r--virt-df/virt_df.ml15
-rw-r--r--virt-df/virt_df.mli4
-rw-r--r--virt-df/virt_df_lvm2.ml10
-rw-r--r--virt-df/virt_df_main.ml2
-rw-r--r--virt-df/virt_df_mbr.ml5
5 files changed, 18 insertions, 18 deletions
diff --git a/virt-df/virt_df.ml b/virt-df/virt_df.ml
index 63bb090..5fd4d80 100644
--- a/virt-df/virt_df.ml
+++ b/virt-df/virt_df.ml
@@ -23,8 +23,6 @@ open Unix
open Virt_df_gettext.Gettext
-let debug = true (* If true emit lots of debugging information. *)
-
let ( +* ) = Int32.add
let ( -* ) = Int32.sub
let ( ** ) = Int32.mul
@@ -35,6 +33,7 @@ let ( -^ ) = Int64.sub
let ( *^ ) = Int64.mul
let ( /^ ) = Int64.div
+let debug = ref false
let uri = ref None
let inodes = ref false
let human = ref false
@@ -171,7 +170,7 @@ let partition_type_register (parts_name : string) probe_fn =
(* 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 ->
@@ -179,7 +178,7 @@ let probe_for_partitions dev =
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 } ->
@@ -196,7 +195,7 @@ let filesystem_type_register (fs_name : string) probe_fn =
(* 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 ->
@@ -204,7 +203,7 @@ let probe_for_filesystem dev =
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 ->
@@ -220,7 +219,7 @@ let lvm_type_register (lvm_name : string) probe_fn list_lvs_fn =
(* 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 ->
@@ -228,7 +227,7 @@ let probe_for_pv dev =
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 } ->
diff --git a/virt-df/virt_df.mli b/virt-df/virt_df.mli
index d40c934..f3d20a7 100644
--- a/virt-df/virt_df.mli
+++ b/virt-df/virt_df.mli
@@ -21,9 +21,6 @@
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
@@ -34,6 +31,7 @@ val ( *^ ) : int64 -> int64 -> int64
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. *)
diff --git a/virt-df/virt_df_lvm2.ml b/virt-df/virt_df_lvm2.ml
index af58f97..314586e 100644
--- a/virt-df/virt_df_lvm2.ml
+++ b/virt-df/virt_df_lvm2.ml
@@ -37,11 +37,11 @@ let sector_size64 = 512L
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 =
@@ -87,7 +87,7 @@ 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. *)
@@ -166,7 +166,7 @@ let rec list_lvs devs =
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)
@@ -249,7 +249,7 @@ let rec list_lvs devs =
) 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
diff --git a/virt-df/virt_df_main.ml b/virt-df/virt_df_main.ml
index e6ae53e..1e1db45 100644
--- a/virt-df/virt_df_main.ml
+++ b/virt-df/virt_df_main.ml
@@ -54,6 +54,8 @@ let () =
"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,
diff --git a/virt-df/virt_df_mbr.ml b/virt-df/virt_df_mbr.ml
index b56189c..75e0661 100644
--- a/virt-df/virt_df_mbr.ml
+++ b/virt-df/virt_df_mbr.ml
@@ -133,8 +133,9 @@ and parse_mbr_entry dev i bits =
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;