Skip to content

Commit 4840c20

Browse files
committed
xenopsd: trigger online resize by writing xenstore
Signed-off-by: Anthoine Bourgeois <anthoine.bourgeois@vates.tech>
1 parent 660dcd2 commit 4840c20

13 files changed

Lines changed: 111 additions & 5 deletions

ocaml/idl/datamodel.ml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6504,6 +6504,7 @@ module VBD = struct
65046504
; ("unplug_force", "Attempting to forcibly unplug this VBD")
65056505
; ("pause", "Attempting to pause a block device backend")
65066506
; ("unpause", "Attempting to unpause a block device backend")
6507+
; ("resize_online", "Attempting to online resize a block device backend")
65076508
]
65086509
)
65096510

@@ -6533,6 +6534,17 @@ module VBD = struct
65336534
~errs:[Api_errors.vbd_not_removable_media; Api_errors.vbd_not_empty]
65346535
~allowed_roles:_R_VM_OP ()
65356536

6537+
let resize_online =
6538+
call ~name:"resize_online"
6539+
~lifecycle:[(Published, rel_rio, "Resize a media online")]
6540+
~doc:"Resize a media online"
6541+
~params:
6542+
[
6543+
(Ref _vbd, "vbd", "The vbd representing the device")
6544+
; (Int, "size", "The new size of the media")
6545+
]
6546+
~allowed_roles:_R_VM_ADMIN ()
6547+
65366548
let plug =
65376549
call ~name:"plug"
65386550
~lifecycle:
@@ -6714,6 +6726,7 @@ module VBD = struct
67146726
; pause
67156727
; unpause
67166728
; set_mode
6729+
; resize_online
67176730
]
67186731
~contents:
67196732
([

ocaml/idl/schematest.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ let hash x = Digest.string x |> Digest.to_hex
33
(* BEWARE: if this changes, check that schema has been bumped accordingly in
44
ocaml/idl/datamodel_common.ml, usually schema_minor_vsn *)
55

6-
let last_known_schema_hash = "3b20f4304cfaaa7b6213af91ae632e64"
6+
let last_known_schema_hash = "acf96a87d6dad370c7000e7d299c1f41"
77

88
let current_schema_hash : string =
99
let open Datamodel_types in

ocaml/xapi-cli-server/cli_operations.ml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,9 +2008,25 @@ let vdi_resize _printer rpc session_id params =
20082008
let online =
20092009
List.mem_assoc "online" params && List.assoc "online" params = "true"
20102010
in
2011-
if online then
2012-
Client.VDI.resize_online ~rpc ~session_id ~vdi ~size:new_size
2013-
else
2011+
if online then (
2012+
Client.VDI.resize_online ~rpc ~session_id ~vdi ~size:new_size;
2013+
let all_vbds = Client.VDI.get_VBDs ~rpc ~session_id ~self:vdi in
2014+
let all_vbd_records = List.map (vbd_record rpc session_id) all_vbds in
2015+
let active_records =
2016+
List.filter
2017+
(fun x -> (field_lookup x.fields "currently-attached").get () = "true")
2018+
all_vbd_records
2019+
in
2020+
List.iter
2021+
(fun vbd_record ->
2022+
let vbd_uuid = (field_lookup vbd_record.fields "uuid").get () in
2023+
let vbd =
2024+
Client.VBD.get_by_uuid ~rpc ~session_id ~uuid:vbd_uuid
2025+
in
2026+
Client.VBD.resize_online ~rpc ~session_id ~vbd ~size:new_size
2027+
)
2028+
active_records
2029+
) else
20142030
Client.VDI.resize ~rpc ~session_id ~vdi ~size:new_size
20152031

20162032
let vdi_generate_config printer rpc session_id params =

ocaml/xapi-idl/xen/xenops_interface.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,11 @@ module XenopsAPI (R : RPC) = struct
954954
let remove =
955955
declare "VBD.remove" []
956956
(debug_info_p @-> vbd_id_p @-> returning unit_p err)
957+
958+
let resize_online =
959+
let new_size_p = Param.mk ~name:"new_size" Types.int64 in
960+
declare "VBD.resize_online" []
961+
(debug_info_p @-> vbd_id_p @-> new_size_p @-> returning task_id_p err)
957962
end
958963

959964
module VUSB = struct

ocaml/xapi/message_forwarding.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5694,6 +5694,15 @@ functor
56945694
let assert_attachable ~__context ~self =
56955695
info "VBD.assert_attachable: VBD = '%s'" (vbd_uuid ~__context self) ;
56965696
Local.VBD.assert_attachable ~__context ~self
5697+
5698+
let resize_online ~__context ~vbd ~size =
5699+
info "VBD.resize_online: VBD = '%s'; size = %Ld" (vbd_uuid ~__context vbd) size ;
5700+
let local_fn = Local.VBD.resize_online ~vbd ~size in
5701+
let remote_fn = Client.VBD.resize_online ~vbd ~size in
5702+
with_vbd_marked ~__context ~vbd ~doc:"VBD.resize_online" ~op:`resize_online (fun () ->
5703+
forward_vbd_op ~local_fn ~__context ~self:vbd ~remote_fn
5704+
) ;
5705+
update_vbd_and_vdi_operations ~__context ~vbd
56975706
end
56985707

56995708
module VBD_metrics = struct end

ocaml/xapi/xapi_vbd.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ let insert ~__context ~vbd ~vdi =
342342
assert_ok_to_insert ~__context ~vbd ~vdi ;
343343
Xapi_xenops.vbd_insert ~__context ~self:vbd ~vdi
344344

345+
let resize_online ~__context ~vbd ~size =
346+
assert_not_empty ~__context ~vbd ;
347+
Xapi_xenops.vbd_resize_online ~__context ~self:vbd ~value:size
348+
345349
let assert_ok_to_eject ~__context ~vbd =
346350
let vm = Db.VBD.get_VM ~__context ~self:vbd in
347351
assert_removable ~__context ~vbd ;

ocaml/xapi/xapi_vbd_helpers.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ open D
2929
open Record_util
3030

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

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

ocaml/xapi/xapi_xenops.ml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4213,6 +4213,22 @@ let vbd_insert_hvm ~__context ~self ~vdi =
42134213
(Ref.string_of self) (Ref.string_of vdi) (Ref.string_of vdi)
42144214
)
42154215

4216+
let vbd_resize_online ~__context ~self ~value =
4217+
let@ __context = Context.with_tracing ~__context __FUNCTION__ in
4218+
let vm = Db.VBD.get_VM ~__context ~self in
4219+
let queue_name = queue_of_vm ~__context ~self:vm in
4220+
transform_xenops_exn ~__context ~vm queue_name (fun () ->
4221+
assert_resident_on ~__context ~self:vm ;
4222+
let vbd = md_of_vbd ~__context ~self in
4223+
info "xenops: VBD.resize_online %s.%s %Ld" (fst vbd.Vbd.id) (snd vbd.Vbd.id) value ;
4224+
let id = id_of_vm ~__context ~self:vm in
4225+
let dbg = Context.string_of_task_and_tracing __context in
4226+
let module Client = (val make_client queue_name : XENOPS) in
4227+
debug "xenops: VBD.resize_online %s" id ;
4228+
Client.VBD.resize_online dbg vbd.Vbd.id value |> sync_with_task __context queue_name ;
4229+
Events_from_xenopsd.wait queue_name dbg id ()
4230+
)
4231+
42164232
let has_qemu ~__context ~vm =
42174233
let@ __context = Context.with_tracing ~__context __FUNCTION__ in
42184234
let dbg = Context.string_of_task_and_tracing __context in

ocaml/xenopsd/lib/xenops_server.ml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ type atomic =
134134
| VBD_detach of Vbd.id
135135
| VBD_insert of Vbd.id * disk
136136
| VBD_set_active of Vbd.id * bool
137+
| VBD_resize_online of Vbd.id * int64
137138
| VM_remove of Vm.id
138139
| PCI_plug of Pci.id * bool (* use Qmp.add_device *)
139140
| PCI_unplug of Pci.id
@@ -223,6 +224,8 @@ let rec name_of_atomic = function
223224
"VBD_insert"
224225
| VBD_set_active _ ->
225226
"VBD_set_active"
227+
| VBD_resize_online _ ->
228+
"VBD_resize_online"
226229
| VM_remove _ ->
227230
"VM_remove"
228231
| PCI_plug _ ->
@@ -2138,6 +2141,17 @@ let rec perform_atomic ~progress_callback ?result (op : atomic)
21382141
| _ ->
21392142
raise (Xenopsd_error (Bad_power_state (power, Running)))
21402143
)
2144+
| VBD_resize_online (id, new_size) -> (
2145+
debug "VBD.resize_online %s" (VBD_DB.string_of_id id) ;
2146+
let vbd_t = VBD_DB.read_exn id in
2147+
let power = (B.VM.get_state (VM_DB.read_exn (fst id))).Vm.power_state in
2148+
match power with
2149+
| Running | Paused ->
2150+
B.VBD.resize_online t (VBD_DB.vm_of id) vbd_t new_size ;
2151+
VBD_DB.signal id
2152+
| _ ->
2153+
raise (Xenopsd_error (Bad_power_state (power, Running)))
2154+
)
21412155
| VM_remove id -> (
21422156
debug "VM.remove %s" id ;
21432157
let vm_t = VM_DB.read_exn id in
@@ -2624,6 +2638,7 @@ and trigger_cleanup_after_failure_atom op t =
26242638
| VBD_unplug (id, _)
26252639
| VBD_deactivate (id, _)
26262640
| VBD_detach id
2641+
| VBD_resize_online (id, _)
26272642
| VBD_insert (id, _) ->
26282643
immediate_operation dbg (fst id) (VBD_check_state id)
26292644
| VIF_plug id
@@ -3555,6 +3570,9 @@ module VBD = struct
35553570
Debug.with_thread_associated dbg
35563571
(fun () -> debug "VBD.list %s" vm ; DB.list vm)
35573572
()
3573+
3574+
let resize_online _ dbg id new_size =
3575+
queue_operation dbg (DB.vm_of id) (Atomic (VBD_resize_online (id, new_size)))
35583576
end
35593577

35603578
module VIF = struct
@@ -4421,6 +4439,7 @@ let _ =
44214439
Server.VBD.unplug (VBD.unplug ()) ;
44224440
Server.VBD.eject (VBD.eject ()) ;
44234441
Server.VBD.insert (VBD.insert ()) ;
4442+
Server.VBD.resize_online (VBD.resize_online ()) ;
44244443
Server.VUSB.add (VUSB.add ()) ;
44254444
Server.VUSB.remove (VUSB.remove ()) ;
44264445
Server.VUSB.stat (VUSB.stat ()) ;

ocaml/xenopsd/lib/xenops_server_plugin.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ module type S = sig
229229

230230
val get_device_action_request :
231231
Vm.id -> Vbd.t -> device_action_request option
232+
233+
val resize_online : Xenops_task.task_handle -> Vm.id -> Vbd.t -> int64 -> unit
232234
end
233235

234236
module VIF : sig

0 commit comments

Comments
 (0)