Refactor the types so we have distinct PV & LV types.
[virt-top.git] / virt-df / virt_df_lvm2.ml
1 (* 'df' command for virtual domains.
2
3    (C) Copyright 2007 Richard W.M. Jones, Red Hat Inc.
4    http://libvirt.org/
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20    Support for LVM2 PVs.
21 *)
22
23 open Printf
24 open Virt_df_gettext.Gettext
25 open Virt_df
26
27 let plugin_name = "LVM2"
28
29 let sector_size = 512
30 let sector_size64 = 512L
31
32 let pv_label_offset = sector_size64
33
34 (* Probe to see if it's an LVM2 PV.  Look for the "LABELONE" label. *)
35 let rec probe_pv lvm_plugin_id dev =
36   try
37     let uuid = read_pv_label dev in
38     { lvm_plugin_id = lvm_plugin_id; pv_uuid = uuid }
39   with _ -> raise Not_found
40
41 and read_pv_label dev =
42   (* Load the second sector. *)
43   let bits = dev#read_bitstring pv_label_offset sector_size in
44
45   (*Bitmatch.hexdump_bitstring stdout bits;*)
46
47   bitmatch bits with
48   | labelone : 8*8 : bitstring;         (* "LABELONE" *)
49     padding : 16*8 : bitstring;
50     lvm2_ver : 8*8 : bitstring;         (* "LVM2 001" *)
51     uuid : 32*8 : bitstring             (* UUID *)
52       when Bitmatch.string_of_bitstring labelone = "LABELONE" &&
53         Bitmatch.string_of_bitstring lvm2_ver = "LVM2 001" ->
54     Bitmatch.string_of_bitstring uuid
55   | _ ->
56     invalid_arg (sprintf "read_pv_label: %s: not an LVM2 physical volume"
57                    dev#name)
58
59 (* We are passed a list of devices which we previously identified
60  * as PVs belonging to us.  From these produce a list of all LVs
61  * (as devices) and return them.  Note that we don't try to detect
62  * what is on these LVs - that will be done in the main code.
63  *)
64 let list_lvs devs = []
65
66 (* Register with main code. *)
67 let () =
68   lvm_type_register plugin_name probe_pv list_lvs