Skip to content

Commit 760ad59

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

File tree

7 files changed

+387
-3
lines changed

7 files changed

+387
-3
lines changed

ocaml/xenopsd/lib/storage.ml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,26 @@ let attach_and_activate ~task ~_vm ~vmdomid ~dp ~sr ~vdi ~read_write =
7777
(transform_exception (fun () -> Client.VDI.activate3 dbg dp sr vdi vmdomid)) ;
7878
result
7979

80+
(* CP-53554: The attach half of attach_and_activate to allow them to be done separately *)
81+
let attach ~task ~_vm ~vmdomid ~dp ~sr ~vdi ~read_write =
82+
let dbg = get_dbg task in
83+
let result =
84+
Xenops_task.with_subtask task
85+
(Printf.sprintf "VDI.attach3 %s" dp)
86+
(transform_exception (fun () ->
87+
Client.VDI.attach3 dbg dp sr vdi vmdomid read_write
88+
)
89+
)
90+
in
91+
result
92+
93+
(* CP-53554: The activate half of attach_and_activate to allow them to be done separately *)
94+
let activate ~task ~_vm ~vmdomid ~dp ~sr ~vdi =
95+
let dbg = get_dbg task in
96+
Xenops_task.with_subtask task
97+
(Printf.sprintf "VDI.activate3 %s" dp)
98+
(transform_exception (fun () -> Client.VDI.activate3 dbg dp sr vdi vmdomid))
99+
80100
let deactivate task dp sr vdi vmdomid =
81101
debug "Deactivating disk %s %s" (Sr.string_of sr) (Vdi.string_of vdi) ;
82102
let dbg = get_dbg task in

ocaml/xenopsd/lib/xenops_server.ml

Lines changed: 42 additions & 3 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,27 @@ 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+
(* Given a non-empty list, returns an Atomic rather than a single item list *)
1592+
let nonempty_serial_unpacked name ~id lst =
1593+
match serial name ~id lst with
1594+
| [x] ->
1595+
x
1596+
| [] | _ :: _ ->
1597+
(* this should never happen *)
1598+
raise
1599+
(Xenopsd_error
1600+
(Internal_error
1601+
"serial with non-empty list should always return a length 1 list"
1602+
)
1603+
)
1604+
1605+
let split_plug_atomic id vbd_id =
1606+
if !xenopsd_vbd_plug_unplug_legacy then
1607+
VBD_plug vbd_id
1608+
else
1609+
nonempty_serial_unpacked "VBD.attach_and_activate" ~id
1610+
[VBD_attach vbd_id; VBD_activate vbd_id]
1611+
15831612
let rec atomics_of_operation = function
15841613
| VM_start (id, force) ->
15851614
let vbds_rw, vbds_ro = VBD_DB.vbds id |> vbd_plug_sets in
@@ -1604,7 +1633,7 @@ let rec atomics_of_operation = function
16041633
[VBD_epoch_begin (vbd.Vbd.id, x, vbd.Vbd.persistent)]
16051634
)
16061635
vbd.Vbd.backend
1607-
; [VBD_plug vbd.Vbd.id]
1636+
; [split_plug_atomic id vbd.Vbd.id]
16081637
]
16091638
)
16101639
in
@@ -1692,7 +1721,10 @@ let rec atomics_of_operation = function
16921721
let name_one = pf "VBD.activate_and_plug %s" typ in
16931722
parallel_map name_multi ~id vbds (fun vbd ->
16941723
serial name_one ~id
1695-
[VBD_set_active (vbd.Vbd.id, true); VBD_plug vbd.Vbd.id]
1724+
[
1725+
VBD_set_active (vbd.Vbd.id, true)
1726+
; split_plug_atomic id vbd.Vbd.id
1727+
]
16961728
)
16971729
in
16981730
[
@@ -1825,7 +1857,7 @@ let rec atomics_of_operation = function
18251857
]
18261858
|> List.concat
18271859
| VBD_hotplug id ->
1828-
[VBD_set_active (id, true); VBD_plug id]
1860+
[VBD_set_active (id, true); split_plug_atomic "VBD_hotplug" id]
18291861
| VBD_hotunplug (id, force) ->
18301862
[VBD_unplug (id, force); VBD_set_active (id, false)]
18311863
| VIF_hotplug id ->
@@ -2019,6 +2051,11 @@ let rec perform_atomic ~progress_callback ?result (op : atomic)
20192051
debug "VBD.plug %s" (VBD_DB.string_of_id id) ;
20202052
B.VBD.plug t (VBD_DB.vm_of id) (VBD_DB.read_exn id) ;
20212053
VBD_DB.signal id
2054+
| VBD_attach id ->
2055+
B.VBD.attach t (VBD_DB.vm_of id) (VBD_DB.read_exn id)
2056+
| VBD_activate id ->
2057+
B.VBD.activate t (VBD_DB.vm_of id) (VBD_DB.read_exn id) ;
2058+
VBD_DB.signal id
20222059
| VBD_set_active (id, b) ->
20232060
debug "VBD.set_active %s %b" (VBD_DB.string_of_id id) b ;
20242061
B.VBD.set_active t (VBD_DB.vm_of id) (VBD_DB.read_exn id) b ;
@@ -2445,6 +2482,8 @@ and trigger_cleanup_after_failure_atom op t =
24452482
match op with
24462483
| VBD_eject id
24472484
| VBD_plug id
2485+
| VBD_attach id
2486+
| VBD_activate id
24482487
| VBD_set_active (id, _)
24492488
| VBD_epoch_begin (id, _, _)
24502489
| VBD_epoch_end (id, _)

ocaml/xenopsd/lib/xenops_server_plugin.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ module type S = sig
209209

210210
val plug : Xenops_task.task_handle -> Vm.id -> Vbd.t -> unit
211211

212+
val attach : Xenops_task.task_handle -> Vm.id -> Vbd.t -> unit
213+
214+
val activate : Xenops_task.task_handle -> Vm.id -> Vbd.t -> unit
215+
212216
val unplug : Xenops_task.task_handle -> Vm.id -> Vbd.t -> bool -> unit
213217

214218
val insert : Xenops_task.task_handle -> Vm.id -> Vbd.t -> disk -> unit

ocaml/xenopsd/lib/xenops_server_simulator.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,10 @@ module VBD = struct
675675

676676
let plug _ (vm : Vm.id) (vbd : Vbd.t) = with_lock m (add_vbd vm vbd)
677677

678+
let attach _ (vm : Vm.id) (vbd : Vbd.t) = with_lock m (add_vbd vm vbd)
679+
680+
let activate _ (_vm : Vm.id) (_vbd : Vbd.t) = ()
681+
678682
let unplug _ vm vbd _ = with_lock m (remove_vbd vm vbd)
679683

680684
let insert _ _vm _vbd _disk = ()

ocaml/xenopsd/lib/xenops_server_skeleton.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ module VBD = struct
147147

148148
let plug _ _ _ = unimplemented "VBD.plug"
149149

150+
let attach _ _ _ = unimplemented "VBD.attach"
151+
152+
let activate _ _ _ = unimplemented "VBD.activate"
153+
150154
let unplug _ _ _ _ = unimplemented "VBD.unplug"
151155

152156
let insert _ _ _ _ = unimplemented "VBD.insert"

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)