Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,27 @@ let vgs_offline =
)
)

let lvchange_offline =
"lvchange vg/lv --offline: check that we can activate volumes offline" >::
fun () ->
with_temp_file (fun filename' ->
with_loop_device filename' (fun loop ->
xenvm [ "vgcreate"; vg; loop ] |> ignore_string;
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;
file_of_string "test.xenvmd.conf" ("( (listenPort ()) (listenPath (Some \"/tmp/xenvmd\")) (host_allocation_quantum 128) (host_low_water_mark 8) (vg "^vg^") (devices ("^loop^")))");
xenvmd [ "--config"; "./test.xenvmd.conf"; "--daemon" ] |> ignore_string;
Xenvm_client.Rpc.uri := "file://local/services/xenvmd/" ^ vg;
Xenvm_client.unix_domain_socket_path := "/tmp/xenvmd";
finally
(fun () ->
xenvm [ "lvcreate"; "-n"; "test"; "-L"; "3"; vg ] |> ignore_string;
) (fun () ->
xenvm [ "shutdown"; "/dev/"^vg ] |> ignore_string
);
xenvm [ "lvchange"; "-ay"; vg ^ "/test"; "--offline" ] |> ignore_string;
)
)

let pvremove =
"pvremove <device>: check that we can make a PV unrecognisable" >::
(fun () ->
Expand All @@ -69,6 +90,7 @@ let pvremove =
let no_xenvmd_suite = "Commands which should work without xenvmd" >::: [
vgcreate;
vgs_offline;
lvchange_offline;
pvremove;
]

Expand Down
34 changes: 24 additions & 10 deletions xenvm/lvchange.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,28 @@ let activate vg lv local_device =
Devmapper.mknod name path 0o0600;
return ()

let lvchange_activate copts vg_name lv_name physical_device =
let lvchange_activate copts vg_name lv_name physical_device (offline:bool) : unit =
let open Xenvm_common in
Lwt_main.run (
get_vg_info_t copts vg_name >>= fun info ->
set_uri copts info;
Client.get_lv ~name:lv_name >>= fun (vg, lv) ->
if vg.Lvm.Vg.name <> vg_name then failwith "Invalid URI";
let local_device = match (info,physical_device) with
let local_device : string = match (info,physical_device) with
| _, Some d -> d (* cmdline overrides default for the VG *)
| Some info, None -> info.local_device (* If we've got a default, use that *)
| None, None -> failwith "Need to know the local device!"
in
| None, None -> failwith "Need to know the local device!" in
( if offline then begin
with_block local_device
(fun x ->
let module Vg_IO = Lvm.Vg.Make(Log)(Block)(Time)(Clock) in
Vg_IO.connect [ x ] `RO >>|= fun vg ->
match Vg_IO.find vg lv_name with
| None -> failwith (Printf.sprintf "Failed to find LV %s" lv_name)
| Some vol ->
return (Vg_IO.metadata_of vg, Vg_IO.Volume.metadata_of vol)
)
end else Client.get_lv ~name:lv_name
) >>= fun (vg, lv) ->
if vg.Lvm.Vg.name <> vg_name then failwith "Invalid URI";
activate vg lv local_device
)

Expand Down Expand Up @@ -105,10 +115,10 @@ let lvchange_refresh copts vg_name lv_name physical_device =
reload vg lv local_device
)

let lvchange copts (vg_name,lv_name_opt) physical_device action perm refresh add_tag del_tag =
let lvchange copts (vg_name,lv_name_opt) physical_device action perm refresh add_tag del_tag offline =
let lv_name = match lv_name_opt with Some l -> l | None -> failwith "Need LV name" in
(match action with
| Some Activate -> lvchange_activate copts vg_name lv_name physical_device
| Some Activate -> lvchange_activate copts vg_name lv_name physical_device offline
| Some Deactivate -> lvchange_deactivate copts vg_name lv_name
| None -> ());
(if refresh then lvchange_refresh copts vg_name lv_name physical_device);
Expand Down Expand Up @@ -158,12 +168,16 @@ let add_tag_arg =
let del_tag_arg =
let doc = "Remove the given tag from the LV" in
Arg.(value & opt (some string) None & info ["deltag"] ~docv:"DELTAG" ~doc)


let offline_arg =
let doc = "Assume xenvmd is offline and read metadata from the disk" in
Arg.(value & flag & info [ "offline" ] ~docv:"OFFLINE" ~doc)

let lvchange_cmd =
let doc = "Change the attributes of a logical volume" in
let man = [
`S "DESCRIPTION";
`P "lvchange allows you to change the attributes of a logical volume including making them known to the kernel ready for use."
] in
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),
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),
Term.info "lvchange" ~sdocs:"COMMON OPTIONS" ~doc ~man
2 changes: 1 addition & 1 deletion xenvm/lvcreate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let lvcreate copts lv_name real_size percent_size tags vg_name =
| e -> fail e
) >>= fun () ->
return info) in
match info with | Some i -> Lvchange.lvchange_activate copts vg_name lv_name (Some i.local_device) | None -> ()
match info with | Some i -> Lvchange.lvchange_activate copts vg_name lv_name (Some i.local_device) false | None -> ()

let lv_name_arg =
let doc = "Gives the name of the LV to be created. This must be unique within the volume group. " in
Expand Down
2 changes: 1 addition & 1 deletion xenvm/vgchange.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let vgchange copts (vg_name,_) physical_device action =
let names = List.map (fun (_, lv) -> lv.Lvm.Lv.name) @@ Lvm.Vg.LVs.bindings vg.Lvm.Vg.lvs in
Lwt_list.iter_s (fun lv_name ->
(match action with
| Some Activate -> Lvchange.lvchange_activate copts vg_name lv_name physical_device
| Some Activate -> Lvchange.lvchange_activate copts vg_name lv_name physical_device false
| Some Deactivate -> Lvchange.lvchange_deactivate copts vg_name lv_name
| None -> ());
return ()
Expand Down
2 changes: 2 additions & 0 deletions xenvmd/xenvmd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ module VolumeManager = struct
(fun (host, _) ->
Host.disconnect host
) !from_LVMs
>>= fun () ->
sync ()
end

module FreePool = struct
Expand Down