Skip to content

Commit 7505713

Browse files
committed
Merge pull request #119 from xapi-project/safety-label
Support `lvchange --offline`
2 parents 43c0075 + 9b92df3 commit 7505713

File tree

5 files changed

+50
-12
lines changed

5 files changed

+50
-12
lines changed

test/test.ml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,27 @@ let vgs_offline =
4747
)
4848
)
4949

50+
let lvchange_offline =
51+
"lvchange vg/lv --offline: check that we can activate volumes offline" >::
52+
fun () ->
53+
with_temp_file (fun filename' ->
54+
with_loop_device filename' (fun loop ->
55+
xenvm [ "vgcreate"; vg; loop ] |> ignore_string;
56+
xenvm [ "set-vg-info"; "--pvpath"; loop; "-S"; "/tmp/xenvmd"; vg; "--local-allocator-path"; "/tmp/xenvm-local-allocator"; "--uri"; "file://local/services/xenvmd/"^vg ] |> ignore_string;
57+
file_of_string "test.xenvmd.conf" ("( (listenPort ()) (listenPath (Some \"/tmp/xenvmd\")) (host_allocation_quantum 128) (host_low_water_mark 8) (vg "^vg^") (devices ("^loop^")))");
58+
xenvmd [ "--config"; "./test.xenvmd.conf"; "--daemon" ] |> ignore_string;
59+
Xenvm_client.Rpc.uri := "file://local/services/xenvmd/" ^ vg;
60+
Xenvm_client.unix_domain_socket_path := "/tmp/xenvmd";
61+
finally
62+
(fun () ->
63+
xenvm [ "lvcreate"; "-n"; "test"; "-L"; "3"; vg ] |> ignore_string;
64+
) (fun () ->
65+
xenvm [ "shutdown"; "/dev/"^vg ] |> ignore_string
66+
);
67+
xenvm [ "lvchange"; "-ay"; vg ^ "/test"; "--offline" ] |> ignore_string;
68+
)
69+
)
70+
5071
let pvremove =
5172
"pvremove <device>: check that we can make a PV unrecognisable" >::
5273
(fun () ->
@@ -69,6 +90,7 @@ let pvremove =
6990
let no_xenvmd_suite = "Commands which should work without xenvmd" >::: [
7091
vgcreate;
7192
vgs_offline;
93+
lvchange_offline;
7294
pvremove;
7395
]
7496

xenvm/lvchange.ml

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,28 @@ let activate vg lv local_device =
2626
Devmapper.mknod name path 0o0600;
2727
return ()
2828

29-
let lvchange_activate copts vg_name lv_name physical_device =
29+
let lvchange_activate copts vg_name lv_name physical_device (offline:bool) : unit =
3030
let open Xenvm_common in
3131
Lwt_main.run (
3232
get_vg_info_t copts vg_name >>= fun info ->
3333
set_uri copts info;
34-
Client.get_lv ~name:lv_name >>= fun (vg, lv) ->
35-
if vg.Lvm.Vg.name <> vg_name then failwith "Invalid URI";
36-
let local_device = match (info,physical_device) with
34+
let local_device : string = match (info,physical_device) with
3735
| _, Some d -> d (* cmdline overrides default for the VG *)
3836
| Some info, None -> info.local_device (* If we've got a default, use that *)
39-
| None, None -> failwith "Need to know the local device!"
40-
in
37+
| None, None -> failwith "Need to know the local device!" in
38+
( if offline then begin
39+
with_block local_device
40+
(fun x ->
41+
let module Vg_IO = Lvm.Vg.Make(Log)(Block)(Time)(Clock) in
42+
Vg_IO.connect [ x ] `RO >>|= fun vg ->
43+
match Vg_IO.find vg lv_name with
44+
| None -> failwith (Printf.sprintf "Failed to find LV %s" lv_name)
45+
| Some vol ->
46+
return (Vg_IO.metadata_of vg, Vg_IO.Volume.metadata_of vol)
47+
)
48+
end else Client.get_lv ~name:lv_name
49+
) >>= fun (vg, lv) ->
50+
if vg.Lvm.Vg.name <> vg_name then failwith "Invalid URI";
4151
activate vg lv local_device
4252
)
4353

@@ -105,10 +115,10 @@ let lvchange_refresh copts vg_name lv_name physical_device =
105115
reload vg lv local_device
106116
)
107117

108-
let lvchange copts (vg_name,lv_name_opt) physical_device action perm refresh add_tag del_tag =
118+
let lvchange copts (vg_name,lv_name_opt) physical_device action perm refresh add_tag del_tag offline =
109119
let lv_name = match lv_name_opt with Some l -> l | None -> failwith "Need LV name" in
110120
(match action with
111-
| Some Activate -> lvchange_activate copts vg_name lv_name physical_device
121+
| Some Activate -> lvchange_activate copts vg_name lv_name physical_device offline
112122
| Some Deactivate -> lvchange_deactivate copts vg_name lv_name
113123
| None -> ());
114124
(if refresh then lvchange_refresh copts vg_name lv_name physical_device);
@@ -158,12 +168,16 @@ let add_tag_arg =
158168
let del_tag_arg =
159169
let doc = "Remove the given tag from the LV" in
160170
Arg.(value & opt (some string) None & info ["deltag"] ~docv:"DELTAG" ~doc)
161-
171+
172+
let offline_arg =
173+
let doc = "Assume xenvmd is offline and read metadata from the disk" in
174+
Arg.(value & flag & info [ "offline" ] ~docv:"OFFLINE" ~doc)
175+
162176
let lvchange_cmd =
163177
let doc = "Change the attributes of a logical volume" in
164178
let man = [
165179
`S "DESCRIPTION";
166180
`P "lvchange allows you to change the attributes of a logical volume including making them known to the kernel ready for use."
167181
] in
168-
Term.(pure lvchange $ Xenvm_common.copts_t $ Xenvm_common.name_arg $ Xenvm_common.physical_device_arg $ action_arg $ perm_arg $ refresh_arg $ add_tag_arg $ del_tag_arg),
182+
Term.(pure lvchange $ Xenvm_common.copts_t $ Xenvm_common.name_arg $ Xenvm_common.physical_device_arg $ action_arg $ perm_arg $ refresh_arg $ add_tag_arg $ del_tag_arg $ offline_arg),
169183
Term.info "lvchange" ~sdocs:"COMMON OPTIONS" ~doc ~man

xenvm/lvcreate.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let lvcreate copts lv_name real_size percent_size tags vg_name =
3535
| e -> fail e
3636
) >>= fun () ->
3737
return info) in
38-
match info with | Some i -> Lvchange.lvchange_activate copts vg_name lv_name (Some i.local_device) | None -> ()
38+
match info with | Some i -> Lvchange.lvchange_activate copts vg_name lv_name (Some i.local_device) false | None -> ()
3939

4040
let lv_name_arg =
4141
let doc = "Gives the name of the LV to be created. This must be unique within the volume group. " in

xenvm/vgchange.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let vgchange copts (vg_name,_) physical_device action =
1313
let names = List.map (fun (_, lv) -> lv.Lvm.Lv.name) @@ Lvm.Vg.LVs.bindings vg.Lvm.Vg.lvs in
1414
Lwt_list.iter_s (fun lv_name ->
1515
(match action with
16-
| Some Activate -> Lvchange.lvchange_activate copts vg_name lv_name physical_device
16+
| Some Activate -> Lvchange.lvchange_activate copts vg_name lv_name physical_device false
1717
| Some Deactivate -> Lvchange.lvchange_deactivate copts vg_name lv_name
1818
| None -> ());
1919
return ()

xenvmd/xenvmd.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ module VolumeManager = struct
430430
(fun (host, _) ->
431431
Host.disconnect host
432432
) !from_LVMs
433+
>>= fun () ->
434+
sync ()
433435
end
434436

435437
module FreePool = struct

0 commit comments

Comments
 (0)