Skip to content

Commit a1f364e

Browse files
committed
CP-53554: Split plug atomic into attach/activate
Signed-off-by: Steven Woods <[email protected]>
1 parent 5e5c53b commit a1f364e

7 files changed

+339
-210
lines changed

ocaml/xenopsd/lib/storage.ml

+11-11
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

+35-4
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 split_plug_atomic id 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_attach vbd_id)
1601+
(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+
; [split_plug_atomic id vbd.Vbd.id]
16081628
]
16091629
)
16101630
in
@@ -1692,7 +1712,10 @@ 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+
[
1716+
VBD_set_active (vbd.Vbd.id, true)
1717+
; split_plug_atomic id vbd.Vbd.id
1718+
]
16961719
)
16971720
in
16981721
[
@@ -1825,7 +1848,7 @@ let rec atomics_of_operation = function
18251848
]
18261849
|> List.concat
18271850
| VBD_hotplug id ->
1828-
[VBD_set_active (id, true); VBD_plug id]
1851+
[VBD_set_active (id, true); split_plug_atomic "VBD_hotplug" id]
18291852
| VBD_hotunplug (id, force) ->
18301853
[VBD_unplug (id, force); VBD_set_active (id, false)]
18311854
| VIF_hotplug id ->
@@ -2017,7 +2040,13 @@ let rec perform_atomic ~progress_callback ?result (op : atomic)
20172040
Xenops_hooks.vm ~script ~reason ~id ~extra_args
20182041
| VBD_plug id ->
20192042
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) ;
2043+
B.VBD.attach t (VBD_DB.vm_of id) (VBD_DB.read_exn id) ;
2044+
B.VBD.activate t (VBD_DB.vm_of id) (VBD_DB.read_exn id) ;
2045+
VBD_DB.signal id
2046+
| VBD_attach id ->
2047+
B.VBD.attach t (VBD_DB.vm_of id) (VBD_DB.read_exn id)
2048+
| VBD_activate id ->
2049+
B.VBD.activate t (VBD_DB.vm_of id) (VBD_DB.read_exn id) ;
20212050
VBD_DB.signal id
20222051
| VBD_set_active (id, b) ->
20232052
debug "VBD.set_active %s %b" (VBD_DB.string_of_id id) b ;
@@ -2445,6 +2474,8 @@ and trigger_cleanup_after_failure_atom op t =
24452474
match op with
24462475
| VBD_eject id
24472476
| VBD_plug id
2477+
| VBD_attach id
2478+
| VBD_activate id
24482479
| VBD_set_active (id, _)
24492480
| VBD_epoch_begin (id, _, _)
24502481
| VBD_epoch_end (id, _)

ocaml/xenopsd/lib/xenops_server_plugin.ml

+3-1
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

+3-1
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

+3-1
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

+5
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)