@@ -5,6 +5,39 @@ open Lwt
55open Xenvm_common
66open Errors
77
8+ module Vg_IO = Lvm.Vg. Make (Log )(Block )(Time )(Clock )
9+
10+ let to_file (vg_name , lv_name ) local_device oc =
11+ with_block local_device
12+ (fun x ->
13+ Vg_IO. connect [ x ] `RO >> |= fun vg ->
14+ match Vg_IO. find vg lv_name with
15+ | None -> failwith (Printf. sprintf " Failed to find LV %s" lv_name)
16+ | Some vol ->
17+ Vg_IO.Volume. connect vol
18+ >> = function
19+ | `Error _ -> fail (Failure (Printf. sprintf " Failed to open %s" lv_name))
20+ | `Ok disk ->
21+ Vg_IO.Volume. get_info disk
22+ >> = fun info ->
23+ let buffer = Io_page. (to_cstruct (get 1024 )) in
24+ let nsectors = Cstruct. len buffer / info.Vg_IO.Volume. sector_size in
25+ let rec loop = function
26+ | n when n = info.Vg_IO.Volume. size_sectors -> return ()
27+ | n ->
28+ let remaining = Int64. sub info.Vg_IO.Volume. size_sectors n in
29+ let toread = min (Int64. to_int remaining) nsectors in
30+ let buffer' = Cstruct. sub buffer 0 (toread * info.Vg_IO.Volume. sector_size) in
31+ Vg_IO.Volume. read disk n [ buffer' ]
32+ >> = function
33+ | `Ok () ->
34+ Lwt_io. write oc (Cstruct. to_string buffer')
35+ >> = fun () ->
36+ loop (Int64. (add n (of_int toread)))
37+ | _ -> failwith (Printf. sprintf " Failed to read sector %Ld" n) in
38+ loop 0L
39+ )
40+
841let lvdump copts (vg_name , lv_name_opt ) physical_device : unit =
942 let open Xenvm_common in
1043 let lv_name = match lv_name_opt with Some l -> l | None -> failwith " Need LV name" in
@@ -15,37 +48,8 @@ let lvdump copts (vg_name, lv_name_opt) physical_device : unit =
1548 | _ , Some d -> d (* cmdline overrides default for the VG *)
1649 | Some info , None -> info.local_device (* If we've got a default, use that *)
1750 | None , None -> failwith " Need to know the local device!" in
18- let module Vg_IO = Lvm.Vg. Make (Log )(Block )(Time )(Clock ) in
19- with_block local_device
20- (fun x ->
21- Vg_IO. connect [ x ] `RO >> |= fun vg ->
22- match Vg_IO. find vg lv_name with
23- | None -> failwith (Printf. sprintf " Failed to find LV %s" lv_name)
24- | Some vol ->
25- Vg_IO.Volume. connect vol
26- >> = function
27- | `Error _ -> fail (Failure (Printf. sprintf " Failed to open %s" lv_name))
28- | `Ok disk ->
29- Vg_IO.Volume. get_info disk
30- >> = fun info ->
31- let buffer = Io_page. (to_cstruct (get 1024 )) in
32- let nsectors = Cstruct. len buffer / info.Vg_IO.Volume. sector_size in
33- let rec loop = function
34- | n when n = info.Vg_IO.Volume. size_sectors -> return ()
35- | n ->
36- let remaining = Int64. sub info.Vg_IO.Volume. size_sectors n in
37- let toread = min (Int64. to_int remaining) nsectors in
38- let buffer' = Cstruct. sub buffer 0 (toread * info.Vg_IO.Volume. sector_size) in
39- Vg_IO.Volume. read disk n [ buffer' ]
40- >> = function
41- | `Ok () ->
42- Lwt_io. write Lwt_io. stdout (Cstruct. to_string buffer')
43- >> = fun () ->
44- loop (Int64. (add n (of_int toread)))
45- | _ -> failwith (Printf. sprintf " Failed to read sector %Ld" n) in
46- loop 0L
47- )
48- )
51+ to_file (vg_name, lv_name) local_device Lwt_io. stdout
52+ )
4953
5054let lvdump_cmd =
5155 let doc = " Dump the physical contents of a logical volume" in
0 commit comments