Skip to content

Commit c987c32

Browse files
committed
Merge pull request #142 from djs55/xenvm-offline
Add an `--offline` mode for `xenvm lvs`
2 parents 64ea4ed + 40ea078 commit c987c32

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

xenvm/lvchange.ml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,11 @@ let del_tag_arg =
170170
let doc = "Remove the given tag from the LV" in
171171
Arg.(value & opt (some string) None & info ["deltag"] ~docv:"DELTAG" ~doc)
172172

173-
let offline_arg =
174-
let doc = "Assume xenvmd is offline and read metadata from the disk" in
175-
Arg.(value & flag & info [ "offline" ] ~docv:"OFFLINE" ~doc)
176-
177173
let lvchange_cmd =
178174
let doc = "Change the attributes of a logical volume" in
179175
let man = [
180176
`S "DESCRIPTION";
181177
`P "lvchange allows you to change the attributes of a logical volume including making them known to the kernel ready for use."
182178
] in
183-
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),
179+
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 $ Xenvm_common.offline_arg),
184180
Term.info "lvchange" ~sdocs:"COMMON OPTIONS" ~doc ~man

xenvm/lvs.ml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
open Cmdliner
44
open Xenvm_common
55
open Lwt
6+
open Errors
67

78
let default_fields = [
89
"lv_name";
@@ -18,7 +19,7 @@ let default_fields = [
1819
"convert_lv"]
1920

2021

21-
let lvs copts noheadings nosuffix units fields (vg_name,lv_name_opt) =
22+
let lvs copts noheadings nosuffix units fields offline physical_device (vg_name,lv_name_opt) =
2223
let open Xenvm_common in
2324
let segs = has_seg_field fields in
2425
let do_row dev vg lv =
@@ -36,10 +37,22 @@ let lvs copts noheadings nosuffix units fields (vg_name,lv_name_opt) =
3637
Lwt_main.run (
3738
get_vg_info_t copts vg_name >>= fun info ->
3839
set_uri copts info;
39-
let dev = match info with | Some i -> i.local_device | None -> "<unknown>" in
40+
let dev : string = match (info,physical_device) with
41+
| _, Some d -> d (* cmdline overrides default for the VG *)
42+
| Some info, None -> info.local_device (* If we've got a default, use that *)
43+
| None, None -> failwith "Need to know the local device!" in
44+
4045
Lwt.catch
41-
(Client.get)
42-
(fun _ ->
46+
(fun () ->
47+
if offline then begin
48+
with_block dev
49+
(fun x ->
50+
let module Vg_IO = Lvm.Vg.Make(Log)(Block)(Time)(Clock) in
51+
Vg_IO.connect [ x ] `RO >>|= fun vg ->
52+
return (Vg_IO.metadata_of vg)
53+
)
54+
end else Client.get ()
55+
) (fun _ ->
4356
stderr " Volume group \"%s\" not found" vg_name
4457
>>= fun () ->
4558
stderr " Skipping volume group %s" vg_name
@@ -66,5 +79,5 @@ let lvs_cmd =
6679
`S "DESCRIPTION";
6780
`P "lvs produces formatted output about logical volumes";
6881
] in
69-
Term.(pure lvs $ Xenvm_common.copts_t $ noheadings_arg $ nosuffix_arg $ units_arg $ output_arg default_fields $ Xenvm_common.name_arg),
82+
Term.(pure lvs $ Xenvm_common.copts_t $ noheadings_arg $ nosuffix_arg $ units_arg $ output_arg default_fields $ Xenvm_common.offline_arg $ Xenvm_common.physical_device_arg $ Xenvm_common.name_arg),
7083
Term.info "lvs" ~sdocs:"COMMON OPTIONS" ~doc ~man

xenvm/xenvm_common.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,3 +493,8 @@ let action_arg =
493493
Activation of a logical volume creates a symbolic link /dev/VolumeGroupName/LogicalVolumeName pointing to the device node. This link is removed on deactivation. All software and scripts should access the device through this symbolic link and present this as the name of the device. The location and name of the underlying device node may depend on the distribution and configuration (e.g. udev) and might change from release to release." in
494494
let a = Arg.(value & opt (some char) None & info ["a"] ~docv:"ACTIVATE" ~doc) in
495495
Term.(pure parse_action $ a)
496+
497+
let offline_arg =
498+
let doc = "Assume xenvmd is offline and read metadata from the disk"
499+
in
500+
Arg.(value & flag & info [ "offline" ] ~docv:"OFFLINE" ~doc)

0 commit comments

Comments
 (0)