@@ -3,6 +3,8 @@ open Cmdliner
33open Lwt
44open Errors
55
6+ let dm = ref (module Devmapper. Linux : Devmapper.S.DEVMAPPER )
7+
68let syslog = Lwt_log. syslog ~facility: `Daemon ()
79
810let stdout fmt = Printf. ksprintf (fun s ->
@@ -40,24 +42,28 @@ type field = { key: string; name: string; fn:fieldfn }
4042(* see https://git.fedorahosted.org/cgit/lvm2.git/tree/lib/metadata/lv.c?id=v2_02_117#n643
4143 for canonical description of this field. *)
4244
43- (* Since we're single-shot, cache the active devices here *)
44- let devmapper_ls =
45- let cache = ref None in
46- fun () ->
47- match ! cache with
48- | None ->
49- let ls = Devmapper. ls () in
50- cache := Some ls;
51- ls
52- | Some ls ->
53- ls
45+ let attr_of_lv vg lv =
46+ let module Devmapper = (val ! dm: Devmapper.S.DEVMAPPER ) in
47+
48+ (* Since we're single-shot, cache the active devices here *)
49+ let devmapper_ls =
50+ let cache = ref None in
51+ fun () ->
52+ match ! cache with
53+ | None ->
54+ let ls = Devmapper. ls () in
55+ cache := Some ls;
56+ ls
57+ | Some ls ->
58+ ls
59+ in
5460
55- let devmapper_stat name =
56- if List. mem name (devmapper_ls () )
57- then Devmapper. stat name
58- else None
61+ let devmapper_stat name =
62+ if List. mem name (devmapper_ls () )
63+ then Devmapper. stat name
64+ else None
65+ in
5966
60- let attr_of_lv vg lv =
6167 let name = Mapper. name_of vg lv in
6268 let info = devmapper_stat name in
6369 Printf. sprintf " %c%c%c%c%c%c%c%c%c%c"
@@ -208,7 +214,9 @@ type copts_t = {
208214 config : string ;
209215}
210216
211- let make_copts config uri_override sockpath_override = {uri_override; config; sockpath_override }
217+ let make_copts config uri_override sockpath_override mock_dm =
218+ dm := if mock_dm then (module Devmapper. Mock : Devmapper.S.DEVMAPPER ) else (module Devmapper. Linux : Devmapper.S.DEVMAPPER );
219+ { uri_override; config; sockpath_override }
212220
213221let config =
214222 let doc = " Path to the config directory" in
@@ -295,8 +303,12 @@ let output_arg default_fields =
295303 let a = Arg. (value & opt (some string ) None & info [" o" ;" options" ] ~doc ) in
296304 Term. (pure (parse_output default_fields) $ a)
297305
306+ let mock_dm_arg =
307+ let doc = " Enable mock interfaces on device mapper." in
308+ Arg. (value & flag & info [" mock-devmapper" ] ~doc )
309+
298310let copts_t =
299- Term. (pure make_copts $ config $ uri_arg $ sock_path_arg)
311+ Term. (pure make_copts $ config $ uri_arg $ sock_path_arg $ mock_dm_arg )
300312
301313let kib = 1024L
302314let sectors = 512L
@@ -382,8 +394,8 @@ let set_vg_info_t copts uri local_device local_allocator_path unix_domain_sock_p
382394 exit 1
383395 | e -> Lwt. fail e)
384396
385- let run_set_vg_info_t config uri local_allocator_path local_device unix_domain_sock_path vg_name =
386- let copts = make_copts config (Some uri) unix_domain_sock_path in
397+ let run_set_vg_info_t config uri local_allocator_path local_device unix_domain_sock_path vg_name mock_dm =
398+ let copts = make_copts config (Some uri) unix_domain_sock_path mock_dm in
387399 Lwt_main. run (set_vg_info_t copts uri local_device local_allocator_path unix_domain_sock_path vg_name)
388400
389401let get_vg_info_t copts vg_name =
@@ -405,7 +417,7 @@ let set_vg_info_cmd =
405417 `P " This command takes a physical device path and a URI, and will write these to the
406418filesystem. Subsequent xenvm commands will use these as defaults." ;
407419 ] in
408- Term. (pure run_set_vg_info_t $ config $ uri_arg_required $ local_allocator_path $ physical_device_arg_required $ sock_path_arg $ name_arg),
420+ Term. (pure run_set_vg_info_t $ config $ uri_arg_required $ local_allocator_path $ physical_device_arg_required $ sock_path_arg $ name_arg $ mock_dm_arg ),
409421 Term. info " set-vg-info" ~sdocs: copts_sect ~doc ~man
410422
411423
0 commit comments