Skip to content

Commit ef0eddd

Browse files
committed
CP-53554: Split plug xenopsd atomic into attach/activate
This consists of two parts, splitting the attach_and_activate into functionally equivalent attach and activate functions, and splitting the VBD_plug atomic itself's behaviour into two new atomics, VBD_attach and VBD_activate. If the new xenopsd_vbd_plug_unplug_legacy flag is true, the only difference will be that VBD_plug calls attach and activate sequentially instead of attach_and_activate. If xenopsd_vbd_plug_unplug_legacy is false, the VBD_attach and VBD_activate atomics will be used in place of VBD_plug in all places that it is used. This should still be functionally equivalent. The purpose of this change is to allow optimisations in this area as there are some situations where they do not need to be called at the same time. For example VBD_attach could be called outside of VM migrate downtime to reduce the overall downtime. Signed-off-by: Steven Woods <steven.woods@cloud.com>
1 parent 78382d5 commit ef0eddd

7 files changed

Lines changed: 344 additions & 216 deletions

File tree

ocaml/xenopsd/lib/storage.ml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,20 @@ let vm_of_domid vmdomid =
6262
"Invalid domid, could not be converted to int, passing empty string." ;
6363
Storage_interface.Vm.of_string ""
6464

65-
let attach_and_activate ~task ~_vm ~vmdomid ~dp ~sr ~vdi ~read_write =
65+
let attach ~task ~_vm ~vmdomid ~dp ~sr ~vdi ~read_write =
66+
let dbg = get_dbg task in
67+
Xenops_task.with_subtask task
68+
(Printf.sprintf "VDI.attach3 %s" dp)
69+
(transform_exception (fun () ->
70+
Client.VDI.attach3 dbg dp sr vdi vmdomid read_write
71+
)
72+
)
73+
74+
let activate ~task ~_vm ~vmdomid ~dp ~sr ~vdi =
6675
let dbg = get_dbg task in
67-
let result =
68-
Xenops_task.with_subtask task
69-
(Printf.sprintf "VDI.attach3 %s" dp)
70-
(transform_exception (fun () ->
71-
Client.VDI.attach3 dbg dp sr vdi vmdomid read_write
72-
)
73-
)
74-
in
7576
Xenops_task.with_subtask task
7677
(Printf.sprintf "VDI.activate3 %s" dp)
77-
(transform_exception (fun () -> Client.VDI.activate3 dbg dp sr vdi vmdomid)) ;
78-
result
78+
(transform_exception (fun () -> Client.VDI.activate3 dbg dp sr vdi vmdomid))
7979

8080
let deactivate task dp sr vdi vmdomid =
8181
debug "Deactivating disk %s %s" (Sr.string_of sr) (Vdi.string_of vdi) ;

ocaml/xenopsd/lib/xenops_server.ml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ let finally = Xapi_stdext_pervasives.Pervasiveext.finally
3737

3838
let domain_shutdown_ack_timeout = ref 60.
3939

40+
let xenopsd_vbd_plug_unplug_legacy = ref true
41+
4042
type context = {
4143
transferred_fd: Unix.file_descr option
4244
(** some API calls take a file descriptor argument *)
@@ -122,6 +124,8 @@ type atomic =
122124
| VM_hook_script_stable of (Vm.id * Xenops_hooks.script * string * Vm.id)
123125
| VM_hook_script of (Vm.id * Xenops_hooks.script * string)
124126
| VBD_plug of Vbd.id
127+
| VBD_attach of Vbd.id
128+
| VBD_activate of Vbd.id
125129
| VBD_epoch_begin of (Vbd.id * disk * bool)
126130
| VBD_epoch_end of (Vbd.id * disk)
127131
| VBD_set_qos of Vbd.id
@@ -195,6 +199,10 @@ let rec name_of_atomic = function
195199
"VM_hook_script"
196200
| VBD_plug _ ->
197201
"VBD_plug"
202+
| VBD_attach _ ->
203+
"VBD_attach"
204+
| VBD_activate _ ->
205+
"VBD_activate"
198206
| VBD_epoch_begin _ ->
199207
"VBD_epoch_begin"
200208
| VBD_epoch_end _ ->
@@ -1580,6 +1588,18 @@ let parallel_map name ~id lst f = parallel name ~id (List.concat_map f lst)
15801588

15811589
let map_or_empty f x = Option.value ~default:[] (Option.map f x)
15821590

1591+
(* Creates a Serial of 2 or more Atomics. If the number of Atomics could be
1592+
less than this, use serial or serial_concat *)
1593+
let serial_of name ~id at1 at2 ats =
1594+
Serial (id, Printf.sprintf "%s VM=%s" name id, at1 :: at2 :: ats)
1595+
1596+
let vbd_plug vbd_id =
1597+
if !xenopsd_vbd_plug_unplug_legacy then
1598+
VBD_plug vbd_id
1599+
else
1600+
serial_of "VBD.attach_and_activate" ~id:(VBD_DB.vm_of vbd_id)
1601+
(VBD_attach vbd_id) (VBD_activate vbd_id) []
1602+
15831603
let rec atomics_of_operation = function
15841604
| VM_start (id, force) ->
15851605
let vbds_rw, vbds_ro = VBD_DB.vbds id |> vbd_plug_sets in
@@ -1604,7 +1624,7 @@ let rec atomics_of_operation = function
16041624
[VBD_epoch_begin (vbd.Vbd.id, x, vbd.Vbd.persistent)]
16051625
)
16061626
vbd.Vbd.backend
1607-
; [VBD_plug vbd.Vbd.id]
1627+
; [vbd_plug vbd.Vbd.id]
16081628
]
16091629
)
16101630
in
@@ -1692,7 +1712,7 @@ let rec atomics_of_operation = function
16921712
let name_one = pf "VBD.activate_and_plug %s" typ in
16931713
parallel_map name_multi ~id vbds (fun vbd ->
16941714
serial name_one ~id
1695-
[VBD_set_active (vbd.Vbd.id, true); VBD_plug vbd.Vbd.id]
1715+
[VBD_set_active (vbd.Vbd.id, true); vbd_plug vbd.Vbd.id]
16961716
)
16971717
in
16981718
[
@@ -1825,7 +1845,7 @@ let rec atomics_of_operation = function
18251845
]
18261846
|> List.concat
18271847
| VBD_hotplug id ->
1828-
[VBD_set_active (id, true); VBD_plug id]
1848+
[VBD_set_active (id, true); vbd_plug id]
18291849
| VBD_hotunplug (id, force) ->
18301850
[VBD_unplug (id, force); VBD_set_active (id, false)]
18311851
| VIF_hotplug id ->
@@ -2017,7 +2037,15 @@ let rec perform_atomic ~progress_callback ?result (op : atomic)
20172037
Xenops_hooks.vm ~script ~reason ~id ~extra_args
20182038
| VBD_plug id ->
20192039
debug "VBD.plug %s" (VBD_DB.string_of_id id) ;
2020-
B.VBD.plug t (VBD_DB.vm_of id) (VBD_DB.read_exn id) ;
2040+
B.VBD.attach t (VBD_DB.vm_of id) (VBD_DB.read_exn id) ;
2041+
B.VBD.activate t (VBD_DB.vm_of id) (VBD_DB.read_exn id) ;
2042+
VBD_DB.signal id
2043+
| VBD_attach id ->
2044+
debug "VBD.attach %s" (VBD_DB.string_of_id id) ;
2045+
B.VBD.attach t (VBD_DB.vm_of id) (VBD_DB.read_exn id)
2046+
| VBD_activate id ->
2047+
debug "VBD.activate %s" (VBD_DB.string_of_id id) ;
2048+
B.VBD.activate t (VBD_DB.vm_of id) (VBD_DB.read_exn id) ;
20212049
VBD_DB.signal id
20222050
| VBD_set_active (id, b) ->
20232051
debug "VBD.set_active %s %b" (VBD_DB.string_of_id id) b ;
@@ -2445,6 +2473,8 @@ and trigger_cleanup_after_failure_atom op t =
24452473
match op with
24462474
| VBD_eject id
24472475
| VBD_plug id
2476+
| VBD_attach id
2477+
| VBD_activate id
24482478
| VBD_set_active (id, _)
24492479
| VBD_epoch_begin (id, _, _)
24502480
| VBD_epoch_end (id, _)

ocaml/xenopsd/lib/xenops_server_plugin.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ module type S = sig
207207

208208
val epoch_end : Xenops_task.task_handle -> Vm.id -> disk -> unit
209209

210-
val plug : Xenops_task.task_handle -> Vm.id -> Vbd.t -> unit
210+
val attach : Xenops_task.task_handle -> Vm.id -> Vbd.t -> unit
211+
212+
val activate : Xenops_task.task_handle -> Vm.id -> Vbd.t -> unit
211213

212214
val unplug : Xenops_task.task_handle -> Vm.id -> Vbd.t -> bool -> unit
213215

ocaml/xenopsd/lib/xenops_server_simulator.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,9 @@ module VBD = struct
673673

674674
let epoch_end _ (_vm : Vm.id) (_disk : disk) = ()
675675

676-
let plug _ (vm : Vm.id) (vbd : Vbd.t) = with_lock m (add_vbd vm vbd)
676+
let attach _ (vm : Vm.id) (vbd : Vbd.t) = with_lock m (add_vbd vm vbd)
677+
678+
let activate _ (_vm : Vm.id) (_vbd : Vbd.t) = ()
677679

678680
let unplug _ vm vbd _ = with_lock m (remove_vbd vm vbd)
679681

ocaml/xenopsd/lib/xenops_server_skeleton.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ module VBD = struct
145145

146146
let epoch_end _ _ _ = ()
147147

148-
let plug _ _ _ = unimplemented "VBD.plug"
148+
let attach _ _ _ = unimplemented "VBD.attach"
149+
150+
let activate _ _ _ = unimplemented "VBD.activate"
149151

150152
let unplug _ _ _ _ = unimplemented "VBD.unplug"
151153

ocaml/xenopsd/lib/xenopsd.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ let options =
283283
, (fun () -> string_of_int !test_open)
284284
, "TESTING only: open N file descriptors"
285285
)
286+
; ( "xenopsd-vbd-plug-unplug-legacy"
287+
, Arg.Bool (fun x -> Xenops_server.xenopsd_vbd_plug_unplug_legacy := x)
288+
, (fun () -> string_of_bool !Xenops_server.xenopsd_vbd_plug_unplug_legacy)
289+
, "False if we want to split the plug atomic into attach/activate"
290+
)
286291
]
287292

288293
let path () = Filename.concat !sockets_path "xenopsd"

0 commit comments

Comments
 (0)