Skip to content

Commit 8f64a29

Browse files
committed
Merge pull request #93 from xapi-project/more-tunnelling
Vgs: a more accurate lv_count
2 parents d17e977 + 8ba825c commit 8f64a29

File tree

2 files changed

+52
-12
lines changed

2 files changed

+52
-12
lines changed

test/test.ml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,20 @@ let vgcreate =
3636
Lwt_main.run t
3737
)
3838

39+
let vgs_offline =
40+
"vgs <device>: check that we can read metadata without xenvmd." >::
41+
(fun () ->
42+
with_temp_file (fun filename ->
43+
xenvm [ "vgcreate"; vg; filename ] |> ignore_string;
44+
mkdir_rec "/etc/xenvm.d" 0o0644;
45+
xenvm [ "set-vg-info"; "--pvpath"; filename; "-S"; "/tmp/xenvmd"; vg; "--local-allocator-path"; "/tmp/xenvm-local-allocator"; "--uri"; "file://local/services/xenvmd/"^vg ] |> ignore_string;
46+
xenvm [ "vgs"; vg ] |> ignore_string
47+
)
48+
)
49+
3950
let no_xenvmd_suite = "Commands which should work without xenvmd" >::: [
4051
vgcreate;
52+
vgs_offline;
4153
]
4254

4355
let assert_lv_exists ?expected_size_in_extents name =
@@ -115,11 +127,31 @@ let lvchange_n =
115127
assert_equal ~printer:string_of_bool false (dm_exists name);
116128
xenvm [ "lvremove"; vg ^ "/test" ] |> ignore_string
117129

130+
let parse_int x =
131+
int_of_string (String.trim x)
132+
133+
let vgs_online =
134+
"vgs <device>: check that we can read fresh metadata with xenvmd." >::
135+
(fun () ->
136+
let metadata = Lwt_main.run (Client.get ()) in
137+
let count = xenvm [ "vgs"; "/dev/" ^ vg; "--noheadings"; "-o"; "lv_count" ] |> parse_int in
138+
let expected = Lvm.Vg.LVs.cardinal metadata.Lvm.Vg.lvs in
139+
assert_equal ~printer:string_of_int expected count;
140+
(* The new LV will be cached: *)
141+
xenvm [ "lvcreate"; "-n"; "test"; "-L"; "3"; vg ] |> ignore_string;
142+
(* This should use the network, not the on-disk metadata: *)
143+
let count = xenvm [ "vgs"; "/dev/" ^ vg; "--noheadings"; "-o"; "lv_count" ] |> parse_int in
144+
(* Did we see the new volume? *)
145+
assert_equal ~printer:string_of_int (expected+1) count;
146+
xenvm [ "lvremove"; vg ^ "/test" ] |> ignore_string
147+
)
148+
118149
let xenvmd_suite = "Commands which require xenvmd" >::: [
119150
lvcreate_L;
120151
lvcreate_l;
121152
lvcreate_percent;
122153
lvchange_n;
154+
vgs_online;
123155
]
124156

125157
let _ =

xenvm/vgs.ml

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,28 @@ let vgs copts noheadings nosuffix units fields vg_names =
4141
let local_device = match info with
4242
| Some info -> info.local_device (* If we've got a default, use that *)
4343
| None -> failwith "Need to know the local device!" in
44-
Lwt.catch
45-
(fun () ->
46-
with_block local_device
47-
(fun x ->
48-
Vg_IO.connect [ x ] `RO >>|= fun vg ->
49-
return (Vg_IO.metadata_of vg)
44+
(* First try a network connection to get the most up to date information.
45+
We currently don't replay the redo log when opening the VG read/only--
46+
see [mirage/mirage-block-volume#68]. *)
47+
Lwt.catch Client.get
48+
(fun e ->
49+
stderr "WARNING: failed to contact xenvmd; falling back to reading the disk metadata"
50+
>>= fun () ->
51+
Lwt.catch
52+
(fun () ->
53+
with_block local_device
54+
(fun x ->
55+
Vg_IO.connect [ x ] `RO >>|= fun vg ->
56+
return (Vg_IO.metadata_of vg)
57+
)
5058
)
59+
(fun _ ->
60+
stderr " Volume group \"%s\" not found" vg_name
61+
>>= fun () ->
62+
stderr " Skipping volume group %s" vg_name
63+
>>= fun () ->
64+
exit 1)
5165
)
52-
(fun _ ->
53-
stderr " Volume group \"%s\" not found" vg_name
54-
>>= fun () ->
55-
stderr " Skipping volume group %s" vg_name
56-
>>= fun () ->
57-
exit 1)
5866
>>= fun vg ->
5967
Lwt.return (info,vg)) vg_names >>= fun vgs ->
6068
let rows = List.concat (List.map do_row vgs) in

0 commit comments

Comments
 (0)