Skip to content

Commit 044573e

Browse files
authored
Merge 50a39d7 into f77f317
2 parents f77f317 + 50a39d7 commit 044573e

File tree

6 files changed

+132
-35
lines changed

6 files changed

+132
-35
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
open Bechamel
2+
3+
module D = Debug.Make (struct let name = __MODULE__ end)
4+
5+
(* tested configuration limits *)
6+
let max_hosts = 64
7+
8+
let max_vms = (*2400*) 240
9+
10+
let max_vbds = (* 255 *) 25
11+
12+
let () =
13+
(* a minimal harness init *)
14+
Suite_init.harness_init () ;
15+
(* don't spam the logs in [allocate] *)
16+
Debug.set_level Syslog.Info
17+
18+
let allocate () =
19+
let open Test_common in
20+
let __context = make_test_database () in
21+
let (_sm_ref : API.ref_SM) = make_sm ~__context () in
22+
let sr_ref = make_sr ~__context () in
23+
let (_ : API.ref_PBD array) =
24+
Array.init max_hosts (fun _ -> make_pbd ~__context ~sR:sr_ref ())
25+
in
26+
let vms =
27+
Array.init max_vms @@ fun _ ->
28+
let vm_ref = make_vm ~__context () in
29+
Array.init (max_vbds / 2) @@ fun _ ->
30+
let vdi_ref = make_vdi ~__context ~sR:sr_ref () in
31+
let vbd_ref =
32+
make_vbd ~__context ~vDI:vdi_ref ~vM:vm_ref ~currently_attached:true
33+
~mode:`RO ()
34+
in
35+
let vdi_ref' = make_vdi ~__context ~sR:sr_ref () in
36+
let vbd_ref' =
37+
make_vbd ~__context ~vDI:vdi_ref' ~vM:vm_ref ~currently_attached:true
38+
~mode:`RW ()
39+
in
40+
(vdi_ref, vbd_ref, vdi_ref', vbd_ref')
41+
in
42+
D.info "Created test database" ;
43+
(__context, vms)
44+
45+
let test_vdi_update_allowed_operations (__context, vm_disks) =
46+
let _, _, vdi_ref, vbd_ref = vm_disks.(0).(0) in
47+
Db.VBD.set_currently_attached ~__context ~self:vbd_ref ~value:true ;
48+
Xapi_vdi.update_allowed_operations ~__context ~self:vdi_ref ;
49+
Db.VBD.set_currently_attached ~__context ~self:vbd_ref ~value:false ;
50+
Xapi_vdi.update_allowed_operations ~__context ~self:vdi_ref
51+
52+
let benchmarks =
53+
Test.make_grouped ~name:"update_allowed_operations"
54+
[
55+
Test.make_with_resource ~name:"VDI" ~allocate ~free:ignore Test.uniq
56+
(Staged.stage test_vdi_update_allowed_operations)
57+
]
58+
59+
let () = Bechamel_simple_cli.cli benchmarks

ocaml/tests/bench/dune

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
11
(executables
2-
(names bench_tracing bench_uuid bench_throttle2 bench_cached_reads)
3-
(libraries tracing bechamel bechamel-notty notty.unix tracing_export threads.posix fmt notty uuid xapi_aux tests_common log xapi_internal)
4-
)
2+
(names
3+
bench_tracing
4+
bench_uuid
5+
bench_throttle2
6+
bench_cached_reads
7+
bench_vdi_allowed_operations)
8+
(libraries
9+
tracing
10+
bechamel
11+
bechamel-notty
12+
notty.unix
13+
tracing_export
14+
threads.posix
15+
fmt
16+
notty
17+
uuid
18+
xapi_aux
19+
tests_common
20+
log
21+
xapi_internal))

ocaml/xapi/cancel_tasks.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ let update_all_allowed_operations ~__context =
8383
in
8484
let vbd_records =
8585
List.map
86-
(fun vbd -> (vbd, Db.VBD.get_record_internal ~__context ~self:vbd))
86+
(fun vbd -> Db.VBD.get_record_internal ~__context ~self:vbd)
8787
all_vbds
8888
in
8989
List.iter
9090
(safe_wrapper "allowed_ops - VDIs" (fun self ->
9191
let relevant_vbds =
9292
List.filter
93-
(fun (_, vbd_record) -> vbd_record.Db_actions.vBD_VDI = self)
93+
(fun vbd_record -> vbd_record.Db_actions.vBD_VDI = self)
9494
vbd_records
9595
in
9696
Xapi_vdi.update_allowed_operations_internal ~__context ~self

ocaml/xapi/xapi_globs.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,16 @@ let rpu_allowed_vm_operations =
500500
; `update_allowed_operations
501501
]
502502

503+
module Vdi_operations = struct
504+
type t = API.vdi_operations
505+
506+
(* this is more efficient than just 'let compare = Stdlib.compare',
507+
because the compiler can specialize it to [t] without calling any runtime functions *)
508+
let compare (a : t) (b : t) = Stdlib.compare a b
509+
end
510+
511+
module Vdi_operations_set = Set.Make (Vdi_operations)
512+
503513
(* Until the Ely release, the vdi_operations enum had stayed unchanged
504514
* since 2009 or earlier, but then Ely and some subsequent releases
505515
* added new members to the enum. *)
@@ -517,6 +527,7 @@ let pre_ely_vdi_operations =
517527
; `generate_config
518528
; `blocked
519529
]
530+
|> Vdi_operations_set.of_list
520531

521532
(* We might consider restricting this further. *)
522533
let rpu_allowed_vdi_operations = pre_ely_vdi_operations

ocaml/xapi/xapi_vdi.ml

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ let check_operation_error ~__context ?sr_records:_ ?(pbd_records = [])
8686
let* () =
8787
if
8888
Helpers.rolling_upgrade_in_progress ~__context
89-
&& not (List.mem op Xapi_globs.rpu_allowed_vdi_operations)
89+
&& not
90+
(Xapi_globs.Vdi_operations_set.mem op
91+
Xapi_globs.rpu_allowed_vdi_operations
92+
)
9093
then
9194
Error (Api_errors.not_supported_during_upgrade, [])
9295
else
@@ -96,7 +99,7 @@ let check_operation_error ~__context ?sr_records:_ ?(pbd_records = [])
9699
(* Don't fail with other_operation_in_progress if VDI mirroring is in
97100
progress and destroy is called as part of VDI mirroring *)
98101
let is_vdi_mirroring_in_progress =
99-
List.exists (fun (_, op) -> op = `mirror) current_ops && op = `destroy
102+
op = `destroy && List.exists (fun (_, op) -> op = `mirror) current_ops
100103
in
101104
if
102105
List.exists (fun (_, op) -> op <> `copy) current_ops
@@ -130,7 +133,7 @@ let check_operation_error ~__context ?sr_records:_ ?(pbd_records = [])
130133
pbd_records
131134
in
132135
let* () =
133-
if pbds_attached = [] && List.mem op [`resize] then
136+
if pbds_attached = [] && op = `resize then
134137
Error (Api_errors.sr_no_pbds, [Ref.string_of sr])
135138
else
136139
Ok ()
@@ -155,16 +158,14 @@ let check_operation_error ~__context ?sr_records:_ ?(pbd_records = [])
155158
)
156159
)
157160
| Some records ->
158-
List.map snd
159-
(List.filter
160-
(fun (_, vbd_record) ->
161-
vbd_record.Db_actions.vBD_VDI = _ref'
162-
&& (vbd_record.Db_actions.vBD_currently_attached
163-
|| vbd_record.Db_actions.vBD_reserved
164-
)
165-
)
166-
records
161+
List.filter
162+
(fun vbd_record ->
163+
vbd_record.Db_actions.vBD_VDI = _ref'
164+
&& (vbd_record.Db_actions.vBD_currently_attached
165+
|| vbd_record.Db_actions.vBD_reserved
166+
)
167167
)
168+
records
168169
in
169170
let my_active_rw_vbd_records =
170171
List.filter (fun vbd -> vbd.Db_actions.vBD_mode = `RW) my_active_vbd_records
@@ -183,14 +184,12 @@ let check_operation_error ~__context ?sr_records:_ ?(pbd_records = [])
183184
)
184185
)
185186
| Some records ->
186-
List.map snd
187-
(List.filter
188-
(fun (_, vbd_record) ->
189-
vbd_record.Db_actions.vBD_VDI = _ref'
190-
&& vbd_record.Db_actions.vBD_current_operations <> []
191-
)
192-
records
187+
List.filter
188+
(fun vbd_record ->
189+
vbd_record.Db_actions.vBD_VDI = _ref'
190+
&& vbd_record.Db_actions.vBD_current_operations <> []
193191
)
192+
records
194193
in
195194
(* If the VBD is currently_attached then some operations can still be
196195
performed ie: VDI.clone (if the VM is suspended we have to have the
@@ -467,7 +466,7 @@ let update_allowed_operations_internal ~__context ~self ~sr_records ~pbd_records
467466
*)
468467
let all_ops =
469468
Xapi_globs.pre_ely_vdi_operations
470-
|> List.filter (function
469+
|> Xapi_globs.Vdi_operations_set.filter (function
471470
| `blocked ->
472471
false (* CA-260245 *)
473472
| `force_unlock ->
@@ -477,25 +476,36 @@ let update_allowed_operations_internal ~__context ~self ~sr_records ~pbd_records
477476
)
478477
in
479478
let all = Db.VDI.get_record_internal ~__context ~self in
479+
let vbd_records =
480+
match vbd_records with
481+
| None when Pool_role.is_master () ->
482+
all.Db_actions.vDI_VBDs
483+
|> List.rev_map (fun self -> Db.VBD.get_record_internal ~__context ~self)
484+
|> Option.some
485+
| v ->
486+
v
487+
in
480488
let allowed =
481489
let check x =
482490
match
483491
check_operation_error ~__context ~sr_records ~pbd_records ?vbd_records
484492
ha_enabled all self x
485493
with
486494
| Ok () ->
487-
[x]
495+
true
488496
| _ ->
489-
[]
497+
false
490498
in
491-
List.fold_left (fun accu op -> check op @ accu) [] all_ops
499+
all_ops |> Xapi_globs.Vdi_operations_set.filter check
492500
in
493501
let allowed =
494-
if Helpers.rolling_upgrade_in_progress ~__context then
495-
Xapi_stdext_std.Listext.List.intersect allowed
496-
Xapi_globs.rpu_allowed_vdi_operations
497-
else
498-
allowed
502+
( if Helpers.rolling_upgrade_in_progress ~__context then
503+
Xapi_globs.Vdi_operations_set.inter allowed
504+
Xapi_globs.rpu_allowed_vdi_operations
505+
else
506+
allowed
507+
)
508+
|> Xapi_globs.Vdi_operations_set.elements
499509
in
500510
Db.VDI.set_allowed_operations ~__context ~self ~value:allowed
501511

ocaml/xapi/xapi_vdi.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ val check_operation_error :
2323
__context:Context.t
2424
-> ?sr_records:'a list
2525
-> ?pbd_records:(API.ref_PBD * API.pBD_t) list
26-
-> ?vbd_records:(API.ref_VBD * Db_actions.vBD_t) list
26+
-> ?vbd_records:Db_actions.vBD_t list
2727
-> bool
2828
-> Db_actions.vDI_t
2929
-> API.ref_VDI
@@ -40,7 +40,7 @@ val update_allowed_operations_internal :
4040
-> self:[`VDI] API.Ref.t
4141
-> sr_records:'a list
4242
-> pbd_records:(API.ref_PBD * API.pBD_t) list
43-
-> ?vbd_records:(API.ref_VBD * Db_actions.vBD_t) list
43+
-> ?vbd_records:Db_actions.vBD_t list
4444
-> unit
4545
-> unit
4646

0 commit comments

Comments
 (0)