Skip to content

Commit a8ef604

Browse files
author
David Scott
committed
Add xenvm lvchange --offline to attach a device without a running xenvmd
This will allow us to attach XenServer HA 'static' VDIs. Fixes #116 Signed-off-by: David Scott <[email protected]>
1 parent 2ac69bb commit a8ef604

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

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 ()

0 commit comments

Comments
 (0)