Skip to content

Commit 68be9f8

Browse files
thomassagaborigloi
authored andcommitted
CP-22009 Add CBT enable/disable operations to datamodel
And add checks for these VDI operations that determine whether whether they are allowed on a given VDI. Signed-off-by: Thomas Sanders <[email protected]>
1 parent 60e849f commit 68be9f8

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

ocaml/idl/datamodel.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5987,6 +5987,8 @@ let storage_operations =
59875987
"vdi_clone", "Cloneing a VDI";
59885988
"vdi_snapshot", "Snapshotting a VDI";
59895989
"vdi_mirror", "Mirroring a VDI";
5990+
"vdi_enable_cbt", "Enabling changed block tracking for a VDI";
5991+
"vdi_disable_cbt", "Disabling changed block tracking for a VDI";
59905992
"pbd_create", "Creating a PBD for this SR";
59915993
"pbd_destroy", "Destroying one of this SR's PBDs"; ])
59925994

@@ -6309,6 +6311,8 @@ let vdi_operations =
63096311
"update", "Refreshing the fields of the VDI";
63106312
"force_unlock", "Forcibly unlocking the VDI";
63116313
"generate_config", "Generating static configuration";
6314+
"enable_cbt", "Enabling changed block tracking for a VDI";
6315+
"disable_cbt", "Disabling changed block tracking for a VDI";
63126316
"blocked", "Operations on this VDI are temporarily blocked";
63136317
])
63146318

ocaml/xapi/record_util.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ let host_operation_to_string = function
9797
| `vm_resume -> "VM.resume"
9898
| `vm_migrate -> "VM.migrate"
9999

100-
let vdi_operation_to_string = function
100+
let vdi_operation_to_string: API.vdi_operations -> string = function
101101
| `scan -> "scan"
102102
| `clone -> "clone"
103103
| `copy -> "copy"
@@ -110,9 +110,11 @@ let vdi_operation_to_string = function
110110
| `forget -> "forget"
111111
| `update -> "update"
112112
| `generate_config -> "generate_config"
113+
| `enable_cbt -> "enable_cbt"
114+
| `disable_cbt -> "disable_cbt"
113115
| `blocked -> "blocked"
114116

115-
let sr_operation_to_string = function
117+
let sr_operation_to_string: API.storage_operations -> string = function
116118
| `scan -> "scan"
117119
| `destroy -> "destroy"
118120
| `forget -> "forget"
@@ -126,6 +128,8 @@ let sr_operation_to_string = function
126128
| `vdi_clone -> "VDI.clone"
127129
| `vdi_snapshot -> "VDI.snapshot"
128130
| `vdi_mirror -> "VDI.mirror"
131+
| `vdi_enable_cbt -> "VDI.enable_cbt"
132+
| `vdi_disable_cbt -> "VDI.disable_cbt"
129133
| `pbd_create -> "PBD.create"
130134
| `pbd_destroy -> "PBD.destroy"
131135

ocaml/xapi/xapi_sr_operations.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,16 @@ open Record_util
3737

3838
let all_ops : API.storage_operations_set =
3939
[ `scan; `destroy; `forget; `plug; `unplug; `vdi_create; `vdi_destroy; `vdi_resize; `vdi_clone; `vdi_snapshot; `vdi_mirror;
40-
`vdi_introduce; `update; `pbd_create; `pbd_destroy ]
40+
`vdi_enable_cbt; `vdi_disable_cbt; `vdi_introduce; `update; `pbd_create; `pbd_destroy ]
4141

4242
let sm_cap_table =
4343
[ `vdi_create, Smint.Vdi_create;
4444
`vdi_destroy, Smint.Vdi_delete;
4545
`vdi_resize, Smint.Vdi_resize;
4646
`vdi_introduce, Smint.Vdi_introduce;
4747
`vdi_mirror, Smint.Vdi_mirror;
48+
`vdi_enable_cbt, Smint.Vdi_configure_cbt;
49+
`vdi_disable_cbt, Smint.Vdi_configure_cbt;
4850
`update, Smint.Sr_update;
4951
(* We fake clone ourselves *)
5052
`vdi_snapshot, Smint.Vdi_snapshot ]

ocaml/xapi/xapi_vdi.ml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ let check_sm_feature_error (op:API.vdi_operations) sm_features sr =
4141
| `generate_config -> Some Vdi_generate_config
4242
| `clone -> Some Vdi_clone
4343
| `mirror -> Some Vdi_mirror
44+
| `enable_cbt | `disable_cbt -> Some Vdi_configure_cbt
4445
) in
4546
match required_sm_feature with
4647
| None -> None
@@ -125,7 +126,7 @@ let check_operation_error ~__context ?(sr_records=[]) ?(pbd_records=[]) ?(vbd_re
125126
VDI.clone (if the VM is suspended we have to have the 'allow_clone_suspended_vm'' flag)
126127
VDI.snapshot; VDI.resize_online; 'blocked' (CP-831) *)
127128
let operation_can_be_performed_live = match op with
128-
| `snapshot | `resize_online | `blocked | `clone | `mirror -> true
129+
| `snapshot | `resize_online | `blocked | `clone | `mirror | `enable_cbt | `disable_cbt -> true
129130
| _ -> false in
130131

131132
let operation_can_be_performed_with_ro_attach =
@@ -199,6 +200,14 @@ let check_operation_error ~__context ?(sr_records=[]) ?(pbd_records=[]) ?(vbd_re
199200
if List.mem record.Db_actions.vDI_type [ `ha_statefile; `redo_log ]
200201
then Some (Api_errors.operation_not_allowed, ["VDI containing HA statefile or redo log cannot be copied (check the VDI's allowed operations)."])
201202
else None
203+
| (`enable_cbt | `disable_cbt) ->
204+
if record.Db_actions.vDI_is_a_snapshot
205+
then Some (Api_errors.operation_not_allowed, ["VDI is a snapshot: " ^ _ref])
206+
else if record.Db_actions.vDI_type <> `user
207+
then Some (Api_errors.vdi_incompatible_type, [ _ref; Record_util.vdi_type_to_string record.Db_actions.vDI_type ])
208+
else if record.Db_actions.vDI_on_boot = `reset
209+
then Some (Api_errors.vdi_on_boot_mode_incompatible_with_operation, [])
210+
else None
202211
| `mirror | `clone | `generate_config | `scan | `force_unlock | `blocked | `update -> None
203212
)
204213

0 commit comments

Comments
 (0)