summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2008-04-15 11:44:41 +0100
committerRichard W.M. Jones <rjones@redhat.com>2008-04-15 11:44:41 +0100
commit40c683ea4c9d921a6fe23c2639125261b92da472 (patch)
treebd48665ca2251cb9d7b6e70408ec19aee0f7d69b
parent0019c13c600d34f12778e849246711bb20ba4ee2 (diff)
downloadvirt-top-40c683ea4c9d921a6fe23c2639125261b92da472.zip
virt-top-40c683ea4c9d921a6fe23c2639125261b92da472.tar.gz
virt-top-40c683ea4c9d921a6fe23c2639125261b92da472.tar.xz
Add PV detection framework.
-rw-r--r--virt-df/virt_df.ml31
-rw-r--r--virt-df/virt_df.mli26
-rw-r--r--virt-df/virt_df_main.ml25
3 files changed, 61 insertions, 21 deletions
diff --git a/virt-df/virt_df.ml b/virt-df/virt_df.ml
index c61f6df..b992e1b 100644
--- a/virt-df/virt_df.ml
+++ b/virt-df/virt_df.ml
@@ -97,7 +97,7 @@ and disk_content =
[ `Unknown (* Not probed or unknown. *)
| `Partitions of partitions (* Contains partitions. *)
| `Filesystem of filesystem (* Contains a filesystem directly. *)
- | `PhysicalVolume of unit (* Contains an LVM PV. *)
+ | `PhysicalVolume of string (* Contains an LVM PV. *)
]
(* Partitions. *)
@@ -116,7 +116,7 @@ and partition_status = Bootable | Nonbootable | Malformed | NullEntry
and partition_content =
[ `Unknown (* Not probed or unknown. *)
| `Filesystem of filesystem (* Filesystem. *)
- | `PhysicalVolume of unit (* Contains an LVM PV. *)
+ | `PhysicalVolume of string (* Contains an LVM PV. *)
]
(* Filesystems (also swap devices). *)
@@ -180,8 +180,8 @@ let filesystem_types = ref []
let filesystem_type_register (fs_name : string) probe_fn =
filesystem_types := (fs_name, probe_fn) :: !filesystem_types
-(* Probe a device for filesystems. Returns [Some fs] or [None]. *)
-let probe_for_filesystems dev =
+(* 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;
let rec loop = function
| [] -> None
@@ -200,8 +200,23 @@ let probe_for_filesystems dev =
r
(* Register a volume management type. *)
-(*
let lvm_types = ref []
-let lvm_type_register (lvm_name : string) probe_fn =
- lvm_types := (lvm_name, probe_fn) :: !lvm_types
-*)
+let lvm_type_register (lvm_name : string) probe_fn list_lvs_fn =
+ lvm_types := (lvm_name, (probe_fn, list_lvs_fn)) :: !lvm_types
+
+(* 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;
+ let rec loop = function
+ | [] -> None
+ | (lvm_name, (probe_fn, _)) :: rest ->
+ if probe_fn dev then Some lvm_name else loop rest
+ in
+ let r = loop !lvm_types in
+ if debug then (
+ match r with
+ | None -> eprintf "no PV found on %s\n%!" dev#name
+ | Some lvm_name ->
+ eprintf "%s contains a %s PV\n%!" dev#name lvm_name
+ );
+ r
diff --git a/virt-df/virt_df.mli b/virt-df/virt_df.mli
index 1b3f6ca..db98af2 100644
--- a/virt-df/virt_df.mli
+++ b/virt-df/virt_df.mli
@@ -17,9 +17,9 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*)
-(* This module (Virt_df) contains functions and values which are
- * used throughout the plug-ins and main code.
- *)
+(** This module (Virt_df) contains functions and values which are
+ used throughout the plug-ins and main code.
+*)
val debug : bool
(** If true, emit logs of debugging information to stderr. *)
@@ -71,7 +71,7 @@ v}
of the physical devices, partitions and filesystems potentially
available to the guest.
- Volume management schemes (eg. LVM) register themselves here
+ Volume management schemes (eg. LVM2) register themselves here
and are called later with "spare" physical devices and partitions
to see if they contain LVM data. If this results in additional
logical volumes then these are checked for filesystems.
@@ -131,7 +131,7 @@ and disk = {
and disk_content =
[ `Filesystem of filesystem (** Contains a direct filesystem. *)
| `Partitions of partitions (** Contains partitions. *)
- | `PhysicalVolume of unit (** Contains an LVM PV. *)
+ | `PhysicalVolume of string (** Contains an LVM PV. *)
| `Unknown (** Not probed or unknown. *)
]
and partitions = {
@@ -147,7 +147,7 @@ and partition = {
and partition_status = Bootable | Nonbootable | Malformed | NullEntry
and partition_content =
[ `Filesystem of filesystem (** Filesystem. *)
- | `PhysicalVolume of unit (** Contains an LVM PV. *)
+ | `PhysicalVolume of string (** Contains an LVM PV. *)
| `Unknown (** Not probed or unknown. *)
]
and filesystem = {
@@ -177,5 +177,17 @@ val probe_for_partitions : device -> partitions option
val filesystem_type_register : string -> (device -> filesystem) -> unit
(** Register a filesystem probing plugin. *)
-val probe_for_filesystems : device -> filesystem option
+val probe_for_filesystem : device -> filesystem option
(** Do a filesystem probe on a device. Returns [Some filesystem] or [None]. *)
+
+val lvm_type_register :
+ string -> (device -> bool) -> (device list -> device list) -> unit
+(** [lvm_type_register lvm_name probe_fn list_lvs_fn]
+ registers a new LVM type. [probe_fn] is a function which
+ should probe a device to find out if it contains a PV.
+ [list_lvs_fn] is a function which should take a list of
+ devices (PVs) and construct a list of LV devices.
+*)
+
+val probe_for_pv : device -> string option
+(** Do a PV probe on a device. Returns [Some lvm_name] or [None]. *)
diff --git a/virt-df/virt_df_main.ml b/virt-df/virt_df_main.ml
index 9504785..c989d76 100644
--- a/virt-df/virt_df_main.ml
+++ b/virt-df/virt_df_main.ml
@@ -268,13 +268,18 @@ OPTIONS" in
{ disk with d_content = `Partitions parts }
| None ->
(* Not partitioned. Does it contain a filesystem? *)
- let fs = probe_for_filesystems dev in
+ let fs = probe_for_filesystem dev in
match fs with
| Some fs ->
{ disk with d_content = `Filesystem fs }
| None ->
- (* Not partitioned, no filesystem, so it's spare. *)
- disk
+ (* Not partitioned, no filesystem, is it a PV? *)
+ let pv = probe_for_pv dev in
+ match pv with
+ | Some lvm_name ->
+ { disk with d_content = `PhysicalVolume lvm_name }
+ | None ->
+ disk (* Spare/unknown. *)
) in
(* Now we have either detected partitions or a filesystem on each
@@ -287,12 +292,18 @@ OPTIONS" in
let ps = List.map (
fun p ->
if p.part_status = Bootable || p.part_status = Nonbootable then (
- let fs = probe_for_filesystems p.part_dev in
+ let fs = probe_for_filesystem p.part_dev in
match fs with
| Some fs ->
{ p with part_content = `Filesystem fs }
| None ->
- p
+ (* Is it a PV? *)
+ let pv = probe_for_pv p.part_dev in
+ match pv with
+ | Some lvm_name ->
+ { p with part_content = `PhysicalVolume lvm_name }
+ | None ->
+ p (* Spare/unknown. *)
) else p
) parts.parts in
let parts = { parts with parts = ps } in
@@ -300,7 +311,9 @@ OPTIONS" in
| disk -> disk
) in
- (* XXX LVM stuff here. *)
+ (* XXX LVM filesystem detection ... *)
+
+