Skip to content

Commit df8c967

Browse files
committed
Merge pull request #111 from xapi-project/creation_time
Improve the output of lvdisplay
2 parents 21a49bc + 4cc5e88 commit df8c967

File tree

7 files changed

+59
-33
lines changed

7 files changed

+59
-33
lines changed

idl/xenvm_interface.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ external get_lv: name:string -> (Vg_wrapper.t * Lv_wrapper.t) = ""
1010
and metadata for the LV in question. *)
1111

1212
external get : unit -> Vg_wrapper.t = ""
13-
external create : name:string -> size:int64 -> tags:string list -> unit = ""
13+
external create : name:string -> size:int64 -> creation_host:string -> creation_time:int64 -> tags:string list -> unit = ""
1414
external rename : oldname:string -> newname:string -> unit = ""
1515
external remove : name:string -> unit = ""
1616
external resize : name:string -> size:int64 -> unit = ""

setup.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ mkdir -p /tmp/xenvm.d
3838
./xenvm.native lvcreate -n live -L 4 djstest --configdir /tmp/xenvm.d $MOCK_ARG
3939
./xenvm.native lvchange -ay /dev/djstest/live --configdir /tmp/xenvm.d $MOCK_ARG
4040

41+
./xenvm.native lvdisplay /dev/djstest --configdir /tmp/xenvm.d $MOCK_ARG
42+
./xenvm.native lvdisplay /dev/djstest -c --configdir /tmp/xenvm.d $MOCK_ARG
43+
4144
#./xenvm.native benchmark
4245
# create and connect to hosts
4346
./xenvm.native host-create /dev/djstest host1 --configdir /tmp/xenvm.d $MOCK_ARG

xenvm/lvcreate.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ let lvcreate copts lv_name real_size percent_size tags vg_name =
2323
bytes
2424
| _ -> failwith "Initial size must be absolute" in
2525
if vg.Lvm.Vg.name <> vg_name then failwith "Invalid VG name";
26-
Client.create lv_name size tags >>= fun () ->
26+
let creation_host = Unix.gethostname () in
27+
let creation_time = Unix.gettimeofday () |> Int64.of_float in
28+
Client.create lv_name size creation_host creation_time tags >>= fun () ->
2729
return info) in
2830
match info with | Some i -> Lvchange.lvchange_activate copts vg_name lv_name (Some i.local_device) | None -> ()
2931

xenvm/lvdisplay.ml

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,60 @@ let print_verbose vg lv =
1313
then [ "write" ] else []) in
1414
String.concat "/" all in
1515
let size = Int64.mul vg.Lvm.Vg.extent_size (Lvm.Lv.size_in_extents lv) in
16+
let creation_time =
17+
let open Unix in
18+
let tm = gmtime (Int64.to_float lv.Lvm.Lv.creation_time) in
19+
Printf.sprintf "%d-%02d-%02d %02d:%02d:%02d +0000"
20+
(tm.tm_year + 1900) (tm.tm_mon + 1) tm.tm_mday
21+
tm.tm_hour tm.tm_min tm.tm_sec in
22+
23+
let device =
24+
let module Devmapper = (val !dm: Devmapper.S.DEVMAPPER) in
25+
let name = Mapper.name_of vg lv in
26+
match Devmapper.stat name with
27+
| Some info ->
28+
Some (Printf.sprintf "%ld:%ld" info.Devmapper.major info.Devmapper.minor)
29+
| None ->
30+
None in
31+
1632
let lines = [
1733
"--- Logical volume ---";
1834
Printf.sprintf "LV Path /dev/%s/%s" vg.Lvm.Vg.name lv.Lvm.Lv.name;
1935
Printf.sprintf "LV Name %s" lv.Lvm.Lv.name;
2036
Printf.sprintf "VG Name %s" vg.Lvm.Vg.name;
2137
Printf.sprintf "LV UUID %s" (Lvm.Uuid.to_string lv.Lvm.Lv.id);
2238
Printf.sprintf "LV Write Access %s" read_write;
23-
Printf.sprintf "LV Creation host, time unknown, unknown";
39+
Printf.sprintf "LV Creation host, time %s, %s" lv.Lvm.Lv.creation_host creation_time;
2440
Printf.sprintf "LV Status %s" (if List.mem Lvm.Lv.Status.Visible lv.Lvm.Lv.status then "available" else "");
2541
Printf.sprintf "# open uknown";
2642
Printf.sprintf "LV Size %Lds" size;
2743
Printf.sprintf "Current LE %Ld" (Lvm.Lv.size_in_extents lv);
2844
Printf.sprintf "Segments %d" (List.length lv.Lvm.Lv.segments);
29-
Printf.sprintf "Allocation: inherit";
30-
Printf.sprintf "Read ahead sectors: auto";
45+
Printf.sprintf "Allocation inherit";
46+
Printf.sprintf "Read ahead sectors auto";
3147
(*
3248
- currently set to 256
33-
Block device 253:0
3449
*)
50+
] @ (match device with
51+
| Some device -> [ Printf.sprintf "Block device %s" device ]
52+
| None -> []) @ [
3553
"";
3654
] in
3755
Lwt_list.iter_s (fun line -> stdout " %s" line) lines
3856

57+
(* Example output:
58+
/dev/packer-virtualbox-iso-vg/root:packer-virtualbox-iso-vg:3:1:-1:1:132661248:16194:-1:0:-1:252:0
59+
*)
3960
let print_colon vg lv =
4061
let sectors = Int64.mul vg.Lvm.Vg.extent_size (Lvm.Lv.size_in_extents lv) in
62+
let major, minor =
63+
let module Devmapper = (val !dm: Devmapper.S.DEVMAPPER) in
64+
let name = Mapper.name_of vg lv in
65+
match Devmapper.stat name with
66+
| Some info ->
67+
Int32.to_string info.Devmapper.major, Int32.to_string info.Devmapper.minor
68+
| None ->
69+
"-1", "-1" in
4170
let parts = [
4271
Printf.sprintf "/dev/%s/%s" vg.Lvm.Vg.name lv.Lvm.Lv.name;
4372
vg.Lvm.Vg.name;
@@ -50,8 +79,8 @@ let print_colon vg lv =
5079
"?"; (* allocated extents *)
5180
"?"; (* allocation policy *)
5281
"?"; (* read ahead sectors *)
53-
"?"; (* major *)
54-
"?"; (* minor *)
82+
major;
83+
minor;
5584
] in
5685
stdout " %s" (String.concat ":" parts)
5786

xenvm/vgcreate.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ let vgcreate _ vg_name devices =
2424
| `Error (`Msg x) -> failwith x in
2525
(name,block)
2626
) blocks in
27-
Vg_IO.format vg_name ~magic:`Journalled pvs >>|= fun () ->
27+
let creation_host = Unix.gethostname () in
28+
let creation_time = Unix.gettimeofday () |> Int64.of_float in
29+
Vg_IO.format vg_name ~creation_host ~creation_time ~magic:`Journalled pvs >>|= fun () ->
2830
Vg_IO.connect (List.map snd pvs) `RW
2931
>>|= fun vg ->
3032
(return (Vg.create (Vg_IO.metadata_of vg) _journal_name size))

xenvm/xenvm.ml

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,18 @@ let format config name filenames =
6767
| `Error (`Msg x) -> failwith x in
6868
(name,block)
6969
) blocks in
70-
Vg_IO.format name ~magic:`Journalled pvs >>|= fun () ->
70+
let creation_host = Unix.gethostname () in
71+
let creation_time = Unix.gettimeofday () |> Int64.of_float in
72+
Vg_IO.format name ~creation_host ~creation_time ~magic:`Journalled pvs >>|= fun () ->
7173
Vg_IO.connect (List.map snd pvs) `RW
7274
>>|= fun vg ->
73-
(return (Vg.create (Vg_IO.metadata_of vg) _journal_name size))
75+
(return (Vg.create (Vg_IO.metadata_of vg) _journal_name size ~creation_host ~creation_time))
7476
>>|= fun (_, op) ->
7577
Vg_IO.update vg [ op ]
7678
>>|= fun () ->
7779
return () in
7880
Lwt_main.run t
7981

80-
let create config name size =
81-
set_uri config None;
82-
Lwt_main.run
83-
(let size_in_bytes = Int64.mul 1048576L size in
84-
Client.create ~name ~size:size_in_bytes ~tags:[])
85-
8682
let host_create copts (vg_name,_) host =
8783
let t =
8884
get_vg_info_t copts vg_name >>= fun info ->
@@ -153,6 +149,7 @@ let shutdown copts (vg_name,_) =
153149

154150
let benchmark copts (vg_name,_) =
155151
let t =
152+
let creation_host = Unix.gethostname () in
156153
get_vg_info_t copts vg_name >>= fun info ->
157154
set_uri copts info;
158155
let mib = Int64.mul 1048576L 4L in
@@ -167,7 +164,7 @@ let benchmark copts (vg_name,_) =
167164
then stderr "%s %d %% complete\n%!" test_name (100 - (n * 100) / number)
168165
else return () ) >>= fun () ->
169166
fori test_name ((number - n, Unix.gettimeofday () -. start) :: acc) f (n - 1) in
170-
fori "Creating volumes" [] (fun i -> Client.create ~name:(Printf.sprintf "test-lv-%d" i) ~size:mib ~tags:[]) number
167+
fori "Creating volumes" [] (fun i -> Client.create ~name:(Printf.sprintf "test-lv-%d" i) ~size:mib ~creation_host ~creation_time:(Unix.gettimeofday () |> Int64.of_float) ~tags:[]) number
171168
>>= fun creates ->
172169
let time = Unix.gettimeofday () -. start in
173170
let oc = open_out "benchmark.dat" in
@@ -232,15 +229,6 @@ let format_cmd =
232229
Term.(pure format $ copts_t $ vgname $ filenames),
233230
Term.info "format" ~sdocs:copts_sect ~doc ~man
234231

235-
let create_cmd =
236-
let doc = "Create a logical volume" in
237-
let man = [
238-
`S "DESCRIPTION";
239-
`P "Creates a logical volume";
240-
] in
241-
Term.(pure create $ copts_t $ lvname $ size),
242-
Term.info "create" ~sdocs:copts_sect ~doc ~man
243-
244232
let host_connect_cmd =
245233
let doc = "Connect to a host" in
246234
let man = [
@@ -310,7 +298,7 @@ let default_cmd =
310298
let cmds = [
311299
Lvresize.lvresize_cmd;
312300
Lvresize.lvextend_cmd;
313-
format_cmd; create_cmd;
301+
format_cmd;
314302
shutdown_cmd; host_create_cmd; host_destroy_cmd;
315303
host_list_cmd;
316304
host_connect_cmd; host_disconnect_cmd; benchmark_cmd;

xenvmd/xenvmd.ml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,13 @@ module VolumeManager = struct
196196
| None -> begin
197197
debug "No freeLVM volume";
198198
let size = Int64.(mul 4L (mul 1024L 1024L)) in
199+
let creation_host = Unix.gethostname () in
200+
let creation_time = Unix.gettimeofday () |> Int64.of_float in
199201
write (fun vg ->
200-
Lvm.Vg.create vg toLVM size
202+
Lvm.Vg.create vg toLVM size ~creation_host ~creation_time
201203
) >>= fun () ->
202204
write (fun vg ->
203-
Lvm.Vg.create vg fromLVM size
205+
Lvm.Vg.create vg fromLVM size ~creation_host ~creation_time
204206
) >>= fun () ->
205207
(* The local allocator needs to see the volumes now *)
206208
sync () >>= fun () ->
@@ -240,7 +242,7 @@ module VolumeManager = struct
240242
(* Create the freeLVM LV at the end - we can use the existence
241243
of this as a flag to show that we've finished host creation *)
242244
write (fun vg ->
243-
Lvm.Vg.create vg freeLVM size
245+
Lvm.Vg.create vg freeLVM size ~creation_host ~creation_time
244246
) >>= fun () ->
245247
sync ()
246248
end
@@ -573,9 +575,9 @@ module Impl = struct
573575
let get context () =
574576
fatal_error "get" (VolumeManager.read (fun x -> return (`Ok x)))
575577

576-
let create context ~name ~size ~tags =
578+
let create context ~name ~size ~creation_host ~creation_time ~tags =
577579
VolumeManager.write (fun vg ->
578-
Lvm.Vg.create vg name ~tags size
580+
Lvm.Vg.create vg name ~creation_host ~creation_time ~tags size
579581
)
580582

581583
let rename context ~oldname ~newname =

0 commit comments

Comments
 (0)