Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions ocaml/idl/datamodel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5336,16 +5336,7 @@ module VDI = struct
~doc:"Resize the VDI." ~allowed_roles:_R_VM_ADMIN ()

let resize_online =
call ~name:"resize_online" ~in_oss_since:None
~lifecycle:
[
(Published, rel_rio, "")
; (Deprecated, rel_inverness, "Dummy transition")
; ( Removed
, rel_inverness
, "Online VDI resize is not supported by any of the storage backends."
)
]
call ~name:"resize_online" ~in_oss_since:None ~lifecycle:[]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will cause problems, we can't simply rewrite history. we have to think of a way to reintroduce this

~params:
[
(Ref _vdi, "vdi", "The VDI to resize")
Expand Down Expand Up @@ -6513,6 +6504,7 @@ module VBD = struct
; ("unplug_force", "Attempting to forcibly unplug this VBD")
; ("pause", "Attempting to pause a block device backend")
; ("unpause", "Attempting to unpause a block device backend")
; ("resize_online", "Attempting to online resize a block device backend")
]
)

Expand Down Expand Up @@ -6542,6 +6534,17 @@ module VBD = struct
~errs:[Api_errors.vbd_not_removable_media; Api_errors.vbd_not_empty]
~allowed_roles:_R_VM_OP ()

let resize_online =
call ~name:"resize_online"
~lifecycle:[(Published, rel_rio, "Resize a media online")]
~doc:"Resize a media online"
~params:
[
(Ref _vbd, "vbd", "The vbd representing the device")
; (Int, "size", "The new size of the media")
]
~allowed_roles:_R_VM_ADMIN ()

let plug =
call ~name:"plug"
~lifecycle:
Expand Down Expand Up @@ -6723,6 +6726,7 @@ module VBD = struct
; pause
; unpause
; set_mode
; resize_online
]
~contents:
([
Expand Down
2 changes: 1 addition & 1 deletion ocaml/idl/schematest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let hash x = Digest.string x |> Digest.to_hex
(* BEWARE: if this changes, check that schema has been bumped accordingly in
ocaml/idl/datamodel_common.ml, usually schema_minor_vsn *)

let last_known_schema_hash = "3b20f4304cfaaa7b6213af91ae632e64"
let last_known_schema_hash = "acf96a87d6dad370c7000e7d299c1f41"

let current_schema_hash : string =
let open Datamodel_types in
Expand Down
2 changes: 1 addition & 1 deletion ocaml/tests/test_vdi_allowed_operations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ let test_update_allowed_operations () =
let allowed_operations =
Db.VDI.get_allowed_operations ~__context ~self:vdi_ref
in
let ok_ops : API.vdi_operations_set = [`snapshot; `clone; `copy] in
let ok_ops : API.vdi_operations_set = [`snapshot; `clone; `copy; `resize_online] in
Alcotest.(check Alcotest_comparators.vdi_operations_set)
"update_allowed_operations should be correct" ok_ops allowed_operations ;
let vbd_ref = Db.VDI.get_VBDs ~__context ~self:vdi_ref |> List.hd in
Expand Down
22 changes: 19 additions & 3 deletions ocaml/xapi-cli-server/cli_operations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2008,9 +2008,25 @@ let vdi_resize _printer rpc session_id params =
let online =
List.mem_assoc "online" params && List.assoc "online" params = "true"
in
if online then
Client.VDI.resize_online ~rpc ~session_id ~vdi ~size:new_size
else
if online then (
Client.VDI.resize_online ~rpc ~session_id ~vdi ~size:new_size;
let all_vbds = Client.VDI.get_VBDs ~rpc ~session_id ~self:vdi in
let all_vbd_records = List.map (vbd_record rpc session_id) all_vbds in
let active_records =
List.filter
(fun x -> (field_lookup x.fields "currently-attached").get () = "true")
all_vbd_records
in
List.iter
(fun vbd_record ->
let vbd_uuid = (field_lookup vbd_record.fields "uuid").get () in
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is slightly unusual to use the UUID for lookup and it would be more paradigmatic to use the reference.

let vbd =
Client.VBD.get_by_uuid ~rpc ~session_id ~uuid:vbd_uuid
in
Client.VBD.resize_online ~rpc ~session_id ~vbd ~size:new_size
)
active_records
) else
Client.VDI.resize ~rpc ~session_id ~vdi ~size:new_size

let vdi_generate_config printer rpc session_id params =
Expand Down
14 changes: 14 additions & 0 deletions ocaml/xapi-idl/storage/storage_interface.ml
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,14 @@ module StorageAPI (R : RPC) = struct
declare "VDI.resize" []
(dbg_p @-> sr_p @-> vdi_p @-> new_size_p @-> returning new_size_p err)

(** [resize_online task sr vdi new_size] makes a VDI's virtual_size at least
[new_size] bytes. The function returns the new virtual_size which may be
bigger (but not less than) requested. *)
let resize_online =
let new_size_p = Param.mk ~name:"new_size" Types.int64 in
declare "VDI.resize_online" []
(dbg_p @-> sr_p @-> vdi_p @-> new_size_p @-> returning new_size_p err)

(** [destroy task sr vdi] removes [vdi] from [sr] *)
let destroy =
declare "VDI.destroy" []
Expand Down Expand Up @@ -1525,6 +1533,9 @@ module type Server_impl = sig
val resize :
context -> dbg:debug_info -> sr:sr -> vdi:vdi -> new_size:int64 -> int64

val resize_online :
context -> dbg:debug_info -> sr:sr -> vdi:vdi -> new_size:int64 -> int64

val destroy : context -> dbg:debug_info -> sr:sr -> vdi:vdi -> unit

val stat : context -> dbg:debug_info -> sr:sr -> vdi:vdi -> vdi_info
Expand Down Expand Up @@ -1780,6 +1791,9 @@ module Server (Impl : Server_impl) () = struct
S.VDI.resize (fun dbg sr vdi new_size ->
Impl.VDI.resize () ~dbg ~sr ~vdi ~new_size
) ;
S.VDI.resize_online (fun dbg sr vdi new_size ->
Impl.VDI.resize_online () ~dbg ~sr ~vdi ~new_size
) ;
S.VDI.destroy (fun dbg sr vdi -> Impl.VDI.destroy () ~dbg ~sr ~vdi) ;
S.VDI.stat (fun dbg sr vdi -> Impl.VDI.stat () ~dbg ~sr ~vdi) ;
S.VDI.introduce (fun dbg sr uuid sm_config location ->
Expand Down
3 changes: 3 additions & 0 deletions ocaml/xapi-idl/storage/storage_skeleton.ml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ module VDI = struct
let resize ctx ~dbg ~sr ~vdi ~new_size =
Storage_interface.unimplemented __FUNCTION__

let resize_online ctx ~dbg ~sr ~vdi ~new_size =
Storage_interface.unimplemented __FUNCTION__

let destroy ctx ~dbg ~sr ~vdi = Storage_interface.unimplemented __FUNCTION__

let stat ctx ~dbg ~sr ~vdi = Storage_interface.unimplemented __FUNCTION__
Expand Down
5 changes: 5 additions & 0 deletions ocaml/xapi-idl/xen/xenops_interface.ml
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,11 @@ module XenopsAPI (R : RPC) = struct
let remove =
declare "VBD.remove" []
(debug_info_p @-> vbd_id_p @-> returning unit_p err)

let resize_online =
let new_size_p = Param.mk ~name:"new_size" Types.int64 in
declare "VBD.resize_online" []
(debug_info_p @-> vbd_id_p @-> new_size_p @-> returning task_id_p err)
end

module VUSB = struct
Expand Down
15 changes: 15 additions & 0 deletions ocaml/xapi-storage-script/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,7 @@ module QueryImpl (M : META) = struct
; ("Volume.clone", "VDI_CLONE")
; ("Volume.snapshot", "VDI_SNAPSHOT")
; ("Volume.resize", "VDI_RESIZE")
; ("Volume.resize_online", "VDI_RESIZE_ONLINE")
; ("Volume.destroy", "VDI_DELETE")
; ("Volume.stat", "VDI_UPDATE")
]
Expand Down Expand Up @@ -1504,6 +1505,19 @@ module VDIImpl (M : META) = struct
)
|> wrap

let vdi_resize_online_impl dbg sr vdi' new_size =
(let vdi = Storage_interface.Vdi.string_of vdi' in
Attached_SRs.find sr >>>= fun sr ->
return_volume_rpc (fun () ->
Volume_client.resize_online (volume_rpc ~dbg) dbg sr vdi new_size
)
>>>= fun () ->
(* Now call Volume.stat to discover the size *)
stat ~dbg ~sr ~vdi >>>= fun response ->
return response.Xapi_storage.Control.virtual_size
)
|> wrap

let vdi_stat_impl dbg sr vdi' =
(let vdi = Storage_interface.Vdi.string_of vdi' in
Attached_SRs.find sr >>>= fun sr ->
Expand Down Expand Up @@ -1934,6 +1948,7 @@ let bind ~volume_script_dir =
S.VDI.set_name_label VDI.vdi_set_name_label_impl ;
S.VDI.set_name_description VDI.vdi_set_name_description_impl ;
S.VDI.resize VDI.vdi_resize_impl ;
S.VDI.resize_online VDI.vdi_resize_online_impl ;
S.VDI.stat VDI.vdi_stat_impl ;
S.VDI.introduce VDI.vdi_introduce_impl ;
S.VDI.attach3 VDI.vdi_attach3_impl ;
Expand Down
11 changes: 11 additions & 0 deletions ocaml/xapi-storage/generator/lib/control.ml
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,17 @@ module Volume (R : RPC) = struct
]
(dbg @-> sr @-> key @-> new_size @-> returning unit errors)

let resize_online =
let new_size =
Param.mk ~name:"new_size" ~description:["New disk size"] Types.int64
in
R.declare "resize_online"
[
"[resize_online sr volume new_size] enlarges [volume] to be at least "
; "[new_size]."
]
(dbg @-> sr @-> key @-> new_size @-> returning unit errors)

let stat =
R.declare "stat"
["[stat sr volume] returns metadata associated with [volume]."]
Expand Down
1 change: 1 addition & 0 deletions ocaml/xapi-storage/generator/test/storage_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ let volume_server () =
Volume.set unimplemented ;
Volume.unset unimplemented ;
Volume.resize unimplemented ;
Volume.resize_online unimplemented ;
Volume.stat unimplemented ;
Volume.compare unimplemented ;
Volume.similar_content unimplemented ;
Expand Down
19 changes: 19 additions & 0 deletions ocaml/xapi/message_forwarding.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5443,6 +5443,16 @@ functor
forward_vdi_op ~local_fn ~__context ~self:vdi ~remote_fn
)

let resize_online ~__context ~vdi ~size =
info "VDI.resize_online: VDI = '%s'; size = %Ld" (vdi_uuid ~__context vdi) size ;
let local_fn = Local.VDI.resize_online ~vdi ~size in
let remote_fn = Client.VDI.resize_online ~vdi ~size in
let sR = Db.VDI.get_SR ~__context ~self:vdi in
with_sr_andor_vdi ~__context ~sr:(sR, `vdi_resize) ~vdi:(vdi, `resize_online)
~doc:"VDI.resize_online" (fun () ->
forward_vdi_op ~local_fn ~__context ~self:vdi ~remote_fn
)

let generate_config ~__context ~host ~vdi =
info "VDI.generate_config: VDI = '%s'; host = '%s'"
(vdi_uuid ~__context vdi)
Expand Down Expand Up @@ -5695,6 +5705,15 @@ functor
let assert_attachable ~__context ~self =
info "VBD.assert_attachable: VBD = '%s'" (vbd_uuid ~__context self) ;
Local.VBD.assert_attachable ~__context ~self

let resize_online ~__context ~vbd ~size =
info "VBD.resize_online: VBD = '%s'; size = %Ld" (vbd_uuid ~__context vbd) size ;
let local_fn = Local.VBD.resize_online ~vbd ~size in
let remote_fn = Client.VBD.resize_online ~vbd ~size in
with_vbd_marked ~__context ~vbd ~doc:"VBD.resize_online" ~op:`resize_online (fun () ->
forward_vbd_op ~local_fn ~__context ~self:vbd ~remote_fn
) ;
update_vbd_and_vdi_operations ~__context ~vbd
end

module VBD_metrics = struct end
Expand Down
14 changes: 14 additions & 0 deletions ocaml/xapi/sm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,20 @@ let vdi_resize ~dbg dconf driver sr vdi newsize =
in
Sm_exec.parse_vdi_info (Sm_exec.exec_xmlrpc ~dbg (driver_filename driver) call)

let vdi_resize_online ~dbg dconf driver sr vdi newsize =
with_dbg ~dbg ~name:"vdi_resize_online" @@ fun di ->
let dbg = Debug_info.to_string di in
debug "vdi_resize_online" driver
(sprintf "sr=%s vdi=%s newsize=%Ld" (Ref.string_of sr) (Ref.string_of vdi)
newsize
) ;
srmaster_only dconf ;
let call =
Sm_exec.make_call ~sr_ref:sr ~vdi_ref:vdi dconf "vdi_resize_online"
[sprintf "%Lu" newsize]
in
Sm_exec.parse_vdi_info (Sm_exec.exec_xmlrpc ~dbg (driver_filename driver) call)

let vdi_generate_config ~dbg dconf driver sr vdi =
with_dbg ~dbg ~name:"vdi_generate_config" @@ fun di ->
let dbg = Debug_info.to_string di in
Expand Down
9 changes: 9 additions & 0 deletions ocaml/xapi/storage_mux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,15 @@ module Mux = struct
end)) in
C.VDI.resize (Debug_info.to_string di) sr vdi new_size

let resize_online () ~dbg ~sr ~vdi ~new_size =
with_dbg ~name:"VDI.resize_online" ~dbg @@ fun di ->
info "VDI.resize_online dbg:%s sr:%s vdi:%s new_size:%Ld" dbg (s_of_sr sr)
(s_of_vdi vdi) new_size ;
let module C = StorageAPI (Idl.Exn.GenClient (struct
let rpc = of_sr sr
end)) in
C.VDI.resize_online (Debug_info.to_string di) sr vdi new_size

let destroy () ~dbg ~sr ~vdi =
with_dbg ~name:"VDI.destroy" ~dbg @@ fun di ->
info "VDI.destroy dbg:%s sr:%s vdi:%s" dbg (s_of_sr sr) (s_of_vdi vdi) ;
Expand Down
25 changes: 25 additions & 0 deletions ocaml/xapi/storage_smapiv1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,31 @@ module SMAPIv1 : Server_impl = struct
| Sm.MasterOnly ->
redirect sr

let resize_online _context ~dbg ~sr ~vdi ~new_size =
with_dbg ~name:"VDI.resize_online" ~dbg @@ fun di ->
let dbg = Debug_info.to_string di in
try
let vi =
for_vdi ~dbg ~sr ~vdi "VDI.resize_online" (fun device_config _type sr self ->
Sm.vdi_resize_online ~dbg device_config _type sr self new_size
)
in
Server_helpers.exec_with_new_task "VDI.resize_online"
~subtask_of:(Ref.of_string dbg) (fun __context ->
let self, _ =
find_vdi ~__context sr
(Storage_interface.Vdi.of_string vi.Smint.vdi_info_location)
in
Db.VDI.get_virtual_size ~__context ~self
)
with
| Api_errors.Server_error (code, params) ->
raise (Storage_error (Backend_error (code, params)))
| Smint.Not_implemented_in_backend ->
raise (Storage_error (Unimplemented "VDI.resize_online"))
| Sm.MasterOnly ->
redirect sr

let destroy _context ~dbg ~sr ~vdi =
with_dbg ~name:"VDI.destroy" ~dbg @@ fun di ->
let dbg = Debug_info.to_string di in
Expand Down
9 changes: 9 additions & 0 deletions ocaml/xapi/storage_smapiv1_wrapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,15 @@ functor
Impl.VDI.resize context ~dbg ~sr ~vdi ~new_size
)

let resize_online context ~dbg ~sr ~vdi ~new_size =
with_dbg ~name:"VDI.resize_online" ~dbg @@ fun di ->
info "VDI.resize_online dbg:%s sr:%s vdi:%s new_size:%Ld" di.log (s_of_sr sr)
(s_of_vdi vdi) new_size ;
let dbg = Debug_info.to_string di in
with_vdi sr vdi (fun () ->
Impl.VDI.resize_online context ~dbg ~sr ~vdi ~new_size
)

let destroy_and_data_destroy call_name call_f context ~dbg ~sr ~vdi =
with_dbg ~name:call_name ~dbg @@ fun di ->
info "%s dbg:%s sr:%s vdi:%s" call_name di.log (s_of_sr sr)
Expand Down
3 changes: 3 additions & 0 deletions ocaml/xapi/xapi_sr_operations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ let all_ops : API.storage_operations_set =
; `vdi_create
; `vdi_destroy
; `vdi_resize
; `vdi_resize_online
; `vdi_clone
; `vdi_snapshot
; `vdi_mirror
Expand All @@ -64,6 +65,7 @@ let all_rpu_ops : API.storage_operations_set =
; `vdi_create
; `vdi_destroy
; `vdi_resize
; `vdi_resize_online
; `vdi_clone
; `vdi_snapshot
; `vdi_introduce
Expand All @@ -81,6 +83,7 @@ let sm_cap_table : (API.storage_operations * _) list =
(`vdi_create, Vdi_create)
; (`vdi_destroy, Vdi_delete)
; (`vdi_resize, Vdi_resize)
; (`vdi_resize_online, Vdi_resize)
; (`vdi_introduce, Vdi_introduce)
; (`vdi_mirror, Vdi_mirror)
; (`vdi_enable_cbt, Vdi_configure_cbt)
Expand Down
4 changes: 4 additions & 0 deletions ocaml/xapi/xapi_vbd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ let insert ~__context ~vbd ~vdi =
assert_ok_to_insert ~__context ~vbd ~vdi ;
Xapi_xenops.vbd_insert ~__context ~self:vbd ~vdi

let resize_online ~__context ~vbd ~size =
assert_not_empty ~__context ~vbd ;
Xapi_xenops.vbd_resize_online ~__context ~self:vbd ~value:size

let assert_ok_to_eject ~__context ~vbd =
let vm = Db.VBD.get_VM ~__context ~self:vbd in
assert_removable ~__context ~vbd ;
Expand Down
2 changes: 1 addition & 1 deletion ocaml/xapi/xapi_vbd_helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ open D
open Record_util

let all_ops : API.vbd_operations_set =
[`attach; `eject; `unplug; `unplug_force; `insert; `plug; `pause; `unpause]
[`attach; `eject; `unplug; `unplug_force; `insert; `plug; `pause; `unpause; `resize_online]

type table = (API.vbd_operations, (string * string list) option) Hashtbl.t

Expand Down
Loading
Loading