Skip to content

Commit 660dcd2

Browse files
committed
vdi: enable resize_online command
Signed-off-by: Anthoine Bourgeois <anthoine.bourgeois@vates.tech>
1 parent b463fd1 commit 660dcd2

15 files changed

Lines changed: 144 additions & 14 deletions

File tree

ocaml/idl/datamodel.ml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5336,16 +5336,7 @@ module VDI = struct
53365336
~doc:"Resize the VDI." ~allowed_roles:_R_VM_ADMIN ()
53375337

53385338
let resize_online =
5339-
call ~name:"resize_online" ~in_oss_since:None
5340-
~lifecycle:
5341-
[
5342-
(Published, rel_rio, "")
5343-
; (Deprecated, rel_inverness, "Dummy transition")
5344-
; ( Removed
5345-
, rel_inverness
5346-
, "Online VDI resize is not supported by any of the storage backends."
5347-
)
5348-
]
5339+
call ~name:"resize_online" ~in_oss_since:None ~lifecycle:[]
53495340
~params:
53505341
[
53515342
(Ref _vdi, "vdi", "The VDI to resize")

ocaml/tests/test_vdi_allowed_operations.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ let test_update_allowed_operations () =
549549
let allowed_operations =
550550
Db.VDI.get_allowed_operations ~__context ~self:vdi_ref
551551
in
552-
let ok_ops : API.vdi_operations_set = [`snapshot; `clone; `copy] in
552+
let ok_ops : API.vdi_operations_set = [`snapshot; `clone; `copy; `resize_online] in
553553
Alcotest.(check Alcotest_comparators.vdi_operations_set)
554554
"update_allowed_operations should be correct" ok_ops allowed_operations ;
555555
let vbd_ref = Db.VDI.get_VBDs ~__context ~self:vdi_ref |> List.hd in

ocaml/xapi-idl/storage/storage_interface.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,14 @@ module StorageAPI (R : RPC) = struct
813813
declare "VDI.resize" []
814814
(dbg_p @-> sr_p @-> vdi_p @-> new_size_p @-> returning new_size_p err)
815815

816+
(** [resize_online task sr vdi new_size] makes a VDI's virtual_size at least
817+
[new_size] bytes. The function returns the new virtual_size which may be
818+
bigger (but not less than) requested. *)
819+
let resize_online =
820+
let new_size_p = Param.mk ~name:"new_size" Types.int64 in
821+
declare "VDI.resize_online" []
822+
(dbg_p @-> sr_p @-> vdi_p @-> new_size_p @-> returning new_size_p err)
823+
816824
(** [destroy task sr vdi] removes [vdi] from [sr] *)
817825
let destroy =
818826
declare "VDI.destroy" []
@@ -1525,6 +1533,9 @@ module type Server_impl = sig
15251533
val resize :
15261534
context -> dbg:debug_info -> sr:sr -> vdi:vdi -> new_size:int64 -> int64
15271535

1536+
val resize_online :
1537+
context -> dbg:debug_info -> sr:sr -> vdi:vdi -> new_size:int64 -> int64
1538+
15281539
val destroy : context -> dbg:debug_info -> sr:sr -> vdi:vdi -> unit
15291540

15301541
val stat : context -> dbg:debug_info -> sr:sr -> vdi:vdi -> vdi_info
@@ -1780,6 +1791,9 @@ module Server (Impl : Server_impl) () = struct
17801791
S.VDI.resize (fun dbg sr vdi new_size ->
17811792
Impl.VDI.resize () ~dbg ~sr ~vdi ~new_size
17821793
) ;
1794+
S.VDI.resize_online (fun dbg sr vdi new_size ->
1795+
Impl.VDI.resize_online () ~dbg ~sr ~vdi ~new_size
1796+
) ;
17831797
S.VDI.destroy (fun dbg sr vdi -> Impl.VDI.destroy () ~dbg ~sr ~vdi) ;
17841798
S.VDI.stat (fun dbg sr vdi -> Impl.VDI.stat () ~dbg ~sr ~vdi) ;
17851799
S.VDI.introduce (fun dbg sr uuid sm_config location ->

ocaml/xapi-idl/storage/storage_skeleton.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ module VDI = struct
106106
let resize ctx ~dbg ~sr ~vdi ~new_size =
107107
Storage_interface.unimplemented __FUNCTION__
108108

109+
let resize_online ctx ~dbg ~sr ~vdi ~new_size =
110+
Storage_interface.unimplemented __FUNCTION__
111+
109112
let destroy ctx ~dbg ~sr ~vdi = Storage_interface.unimplemented __FUNCTION__
110113

111114
let stat ctx ~dbg ~sr ~vdi = Storage_interface.unimplemented __FUNCTION__

ocaml/xapi-storage-script/main.ml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,7 @@ module QueryImpl (M : META) = struct
898898
; ("Volume.clone", "VDI_CLONE")
899899
; ("Volume.snapshot", "VDI_SNAPSHOT")
900900
; ("Volume.resize", "VDI_RESIZE")
901+
; ("Volume.resize_online", "VDI_RESIZE_ONLINE")
901902
; ("Volume.destroy", "VDI_DELETE")
902903
; ("Volume.stat", "VDI_UPDATE")
903904
]
@@ -1504,6 +1505,19 @@ module VDIImpl (M : META) = struct
15041505
)
15051506
|> wrap
15061507

1508+
let vdi_resize_online_impl dbg sr vdi' new_size =
1509+
(let vdi = Storage_interface.Vdi.string_of vdi' in
1510+
Attached_SRs.find sr >>>= fun sr ->
1511+
return_volume_rpc (fun () ->
1512+
Volume_client.resize_online (volume_rpc ~dbg) dbg sr vdi new_size
1513+
)
1514+
>>>= fun () ->
1515+
(* Now call Volume.stat to discover the size *)
1516+
stat ~dbg ~sr ~vdi >>>= fun response ->
1517+
return response.Xapi_storage.Control.virtual_size
1518+
)
1519+
|> wrap
1520+
15071521
let vdi_stat_impl dbg sr vdi' =
15081522
(let vdi = Storage_interface.Vdi.string_of vdi' in
15091523
Attached_SRs.find sr >>>= fun sr ->
@@ -1934,6 +1948,7 @@ let bind ~volume_script_dir =
19341948
S.VDI.set_name_label VDI.vdi_set_name_label_impl ;
19351949
S.VDI.set_name_description VDI.vdi_set_name_description_impl ;
19361950
S.VDI.resize VDI.vdi_resize_impl ;
1951+
S.VDI.resize_online VDI.vdi_resize_online_impl ;
19371952
S.VDI.stat VDI.vdi_stat_impl ;
19381953
S.VDI.introduce VDI.vdi_introduce_impl ;
19391954
S.VDI.attach3 VDI.vdi_attach3_impl ;

ocaml/xapi-storage/generator/lib/control.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,17 @@ module Volume (R : RPC) = struct
330330
]
331331
(dbg @-> sr @-> key @-> new_size @-> returning unit errors)
332332

333+
let resize_online =
334+
let new_size =
335+
Param.mk ~name:"new_size" ~description:["New disk size"] Types.int64
336+
in
337+
R.declare "resize_online"
338+
[
339+
"[resize_online sr volume new_size] enlarges [volume] to be at least "
340+
; "[new_size]."
341+
]
342+
(dbg @-> sr @-> key @-> new_size @-> returning unit errors)
343+
333344
let stat =
334345
R.declare "stat"
335346
["[stat sr volume] returns metadata associated with [volume]."]

ocaml/xapi-storage/generator/test/storage_test.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ let volume_server () =
181181
Volume.set unimplemented ;
182182
Volume.unset unimplemented ;
183183
Volume.resize unimplemented ;
184+
Volume.resize_online unimplemented ;
184185
Volume.stat unimplemented ;
185186
Volume.compare unimplemented ;
186187
Volume.similar_content unimplemented ;

ocaml/xapi/message_forwarding.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5432,6 +5432,16 @@ functor
54325432
forward_vdi_op ~local_fn ~__context ~self:vdi ~remote_fn
54335433
)
54345434

5435+
let resize_online ~__context ~vdi ~size =
5436+
info "VDI.resize_online: VDI = '%s'; size = %Ld" (vdi_uuid ~__context vdi) size ;
5437+
let local_fn = Local.VDI.resize_online ~vdi ~size in
5438+
let remote_fn = Client.VDI.resize_online ~vdi ~size in
5439+
let sR = Db.VDI.get_SR ~__context ~self:vdi in
5440+
with_sr_andor_vdi ~__context ~sr:(sR, `vdi_resize) ~vdi:(vdi, `resize_online)
5441+
~doc:"VDI.resize_online" (fun () ->
5442+
forward_vdi_op ~local_fn ~__context ~self:vdi ~remote_fn
5443+
)
5444+
54355445
let generate_config ~__context ~host ~vdi =
54365446
info "VDI.generate_config: VDI = '%s'; host = '%s'"
54375447
(vdi_uuid ~__context vdi)

ocaml/xapi/sm.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,20 @@ let vdi_resize ~dbg dconf driver sr vdi newsize =
299299
in
300300
Sm_exec.parse_vdi_info (Sm_exec.exec_xmlrpc ~dbg (driver_filename driver) call)
301301

302+
let vdi_resize_online ~dbg dconf driver sr vdi newsize =
303+
with_dbg ~dbg ~name:"vdi_resize_online" @@ fun di ->
304+
let dbg = Debug_info.to_string di in
305+
debug "vdi_resize_online" driver
306+
(sprintf "sr=%s vdi=%s newsize=%Ld" (Ref.string_of sr) (Ref.string_of vdi)
307+
newsize
308+
) ;
309+
srmaster_only dconf ;
310+
let call =
311+
Sm_exec.make_call ~sr_ref:sr ~vdi_ref:vdi dconf "vdi_resize_online"
312+
[sprintf "%Lu" newsize]
313+
in
314+
Sm_exec.parse_vdi_info (Sm_exec.exec_xmlrpc ~dbg (driver_filename driver) call)
315+
302316
let vdi_generate_config ~dbg dconf driver sr vdi =
303317
with_dbg ~dbg ~name:"vdi_generate_config" @@ fun di ->
304318
let dbg = Debug_info.to_string di in

ocaml/xapi/storage_mux.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,15 @@ module Mux = struct
480480
end)) in
481481
C.VDI.resize (Debug_info.to_string di) sr vdi new_size
482482

483+
let resize_online () ~dbg ~sr ~vdi ~new_size =
484+
with_dbg ~name:"VDI.resize_online" ~dbg @@ fun di ->
485+
info "VDI.resize_online dbg:%s sr:%s vdi:%s new_size:%Ld" dbg (s_of_sr sr)
486+
(s_of_vdi vdi) new_size ;
487+
let module C = StorageAPI (Idl.Exn.GenClient (struct
488+
let rpc = of_sr sr
489+
end)) in
490+
C.VDI.resize_online (Debug_info.to_string di) sr vdi new_size
491+
483492
let destroy () ~dbg ~sr ~vdi =
484493
with_dbg ~name:"VDI.destroy" ~dbg @@ fun di ->
485494
info "VDI.destroy dbg:%s sr:%s vdi:%s" dbg (s_of_sr sr) (s_of_vdi vdi) ;

0 commit comments

Comments
 (0)