Skip to content

Commit d17e977

Browse files
committed
Merge pull request #92 from xapi-project/more-tunnelling
lvcreate supports %age arguments
2 parents ec83343 + c6209de commit d17e977

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

test/test.ml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,36 @@ let assert_lv_exists ?expected_size_in_extents name =
5555
) in
5656
Lwt_main.run t
5757

58+
let free_extents () =
59+
let t =
60+
Client.get ()
61+
>>= fun vg ->
62+
return (Lvm.Pv.Allocator.size (vg.Lvm.Vg.free_space)) in
63+
Lwt_main.run t
64+
5865
let lvcreate_L =
5966
"lvcreate -n <name> -L <mib> <vg>: check that we can create an LV with a size in MiB" >::
6067
fun () ->
61-
xenvm [ "lvcreate"; "-n"; "test"; "-L"; "4"; vg ] |> ignore_string;
62-
assert_lv_exists ~expected_size_in_extents:1L "test";
68+
xenvm [ "lvcreate"; "-n"; "test"; "-L"; "16"; vg ] |> ignore_string;
69+
assert_lv_exists ~expected_size_in_extents:4L "test";
6370
xenvm [ "lvremove"; vg ^ "/test" ] |> ignore_string
6471

6572
let lvcreate_l =
6673
"lvcreate -n <name> -l <extents> <vg>: check that we can create an LV with a size in extents" >::
6774
fun () ->
68-
xenvm [ "lvcreate"; "-n"; "test"; "-l"; "1"; vg ] |> ignore_string;
69-
assert_lv_exists ~expected_size_in_extents:1L "test";
75+
xenvm [ "lvcreate"; "-n"; "test"; "-l"; "2"; vg ] |> ignore_string;
76+
assert_lv_exists ~expected_size_in_extents:2L "test";
7077
xenvm [ "lvremove"; vg ^ "/test" ] |> ignore_string
7178

79+
let lvcreate_percent =
80+
"lvcreate -n <name> -l 100%F <vg>: check that we can fill all free space in the VG" >::
81+
fun () ->
82+
xenvm [ "lvcreate"; "-n"; "test"; "-l"; "100%F"; vg ] |> ignore_string;
83+
let free = free_extents () in
84+
assert_equal ~printer:Int64.to_string 0L free;
85+
xenvm [ "lvremove"; vg ^ "/test" ] |> ignore_string
86+
87+
7288
let file_exists filename =
7389
try
7490
Unix.LargeFile.stat filename |> ignore;
@@ -102,6 +118,7 @@ let lvchange_n =
102118
let xenvmd_suite = "Commands which require xenvmd" >::: [
103119
lvcreate_L;
104120
lvcreate_l;
121+
lvcreate_percent;
105122
lvchange_n;
106123
]
107124

xenvm/lvcreate.ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ let lvcreate copts lv_name real_size percent_size tags vg_name =
1212
set_uri copts info;
1313
Client.get () >>= fun vg ->
1414

15-
let extent_size_mib = Int64.(div (mul 512L vg.Lvm.Vg.extent_size) (mul 1024L 1024L)) in
15+
let extent_size_bytes = Int64.(mul 512L vg.Lvm.Vg.extent_size) in
1616

1717
let size = match parse_size real_size percent_size with
1818
| `Absolute size -> size
19-
| `Extents extents -> Int64.mul extent_size_mib extents
19+
| `Extents extents -> Int64.mul extent_size_bytes extents
20+
| `Free percent ->
21+
let extents = Int64.(div (mul (Lvm.Pv.Allocator.size vg.Lvm.Vg.free_space) percent) 100L) in
22+
let bytes = Int64.mul extent_size_bytes extents in
23+
bytes
2024
| _ -> failwith "Initial size must be absolute" in
21-
2225
if vg.Lvm.Vg.name <> vg_name then failwith "Invalid VG name";
2326
Client.create lv_name size tags >>= fun () ->
2427
return info) in

xenvm/lvresize.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let lvresize copts live (vg_name,lv_opt) real_size percent_size =
99
let size = match parse_size real_size percent_size with
1010
| `IncreaseBy x -> `IncreaseBy x
1111
| `Absolute x -> `Absolute x
12+
| `Free _ -> failwith "Resizing to a percentage of free space not supported"
1213
| `DecreaseBy _ -> failwith "Shrinking volumes not supported"
1314
| `Extents _ -> failwith "Resizing in terms of extents not supported" in
1415

xenvm/xenvm_common.ml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,18 @@ let parse_size_string =
324324
| Not_found ->
325325
failwith "Expecting a size of the form [0-9]+[mMbBkKgGtTsS]?"
326326

327-
(* LogicalExtentsNumber[%{VG|PVS|FREE|ORIGIN}] *)
327+
(* LogicalExtentsNumber[%{VG|PVS|FREE|ORIGIN}] in the man page
328+
but the command will apparently also accept '100%F' *)
328329
let parse_percent_size_string s =
329330
try
330-
let _ = String.index s '%' in
331-
failwith "Creating an LV with a %age size is not implemented yet"
331+
let i = String.index s '%' in
332+
let percent = Int64.of_string (String.sub s 0 i) in
333+
match String.sub s (i + 1) (String.length s - i - 1) with
334+
| "F" | "FREE" -> `Free percent
335+
| "VG" -> failwith "Creating an LV with a %age of VG is not implemented yet"
336+
| "PVS" -> failwith "Creating an LV with a %age of PVS is not implemented yet"
337+
| "ORIGIN" -> failwith "Creating an LV with a %age of ORIGIN is not implemented yet"
338+
| x -> failwith (Printf.sprintf "I don't understand the %%age size string: %s; expected [VG|PVS|FREE|ORIGIN]" x)
332339
with Not_found ->
333340
`Extents (Int64.of_string s)
334341

0 commit comments

Comments
 (0)