Skip to content

Commit

Permalink
ocaml/xapi: use generated enum list instead of hand-maintained ones
Browse files Browse the repository at this point in the history
The list in xapi_vm_lifecycle now contains ignored operations, this allows
users to easily see which operations are excluded from the database, decide
whether they're worth exposing them and change the code accordingly to
accomodate for them.

Signed-off-by: Pau Ruiz Safont <[email protected]>
  • Loading branch information
psafont committed Apr 18, 2024
1 parent c20b11e commit 723a498
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 94 deletions.
14 changes: 1 addition & 13 deletions ocaml/xapi/xapi_host_helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,7 @@ let with_lock = Xapi_stdext_threads.Threadext.Mutex.execute

let finally = Xapi_stdext_pervasives.Pervasiveext.finally

let all_operations =
[
`provision
; `evacuate
; `reboot
; `shutdown
; `vm_start
; `vm_resume
; `vm_migrate
; `power_on
; `apply_updates
; `enable
]
let all_operations = API.host_allowed_operations__all

(** Returns a table of operations -> API error options (None if the operation would be ok) *)
let valid_operations ~__context record _ref' =
Expand Down
24 changes: 1 addition & 23 deletions ocaml/xapi/xapi_sr_operations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,7 @@ open Client

open Record_util

let all_ops : API.storage_operations_set =
[
`scan
; `destroy
; `forget
; `plug
; `unplug
; `vdi_create
; `vdi_destroy
; `vdi_resize
; `vdi_clone
; `vdi_snapshot
; `vdi_mirror
; `vdi_enable_cbt
; `vdi_disable_cbt
; `vdi_data_destroy
; `vdi_list_changed_blocks
; `vdi_set_on_boot
; `vdi_introduce
; `update
; `pbd_create
; `pbd_destroy
]
let all_ops = API.storage_operations__all

(* This list comes from https://github.com/xenserver/xen-api/blob/tampa-bugfix/ocaml/xapi/xapi_sr_operations.ml#L36-L38 *)
let all_rpu_ops : API.storage_operations_set =
Expand Down
21 changes: 1 addition & 20 deletions ocaml/xapi/xapi_vdi_helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,7 @@ module D = Debug.Make (struct let name = "xapi_vdi_helpers" end)

open D

let all_ops : API.vdi_operations_set =
[
`blocked
; `clone
; `copy
; `data_destroy
; `destroy
; `disable_cbt
; `enable_cbt
; `force_unlock
; `forget
; `generate_config
; `list_changed_blocks
; `mirror
; `resize
; `resize_online
; `set_on_boot
; `snapshot
; `update
]
let all_ops = API.vdi_operations__all

(* CA-26514: Block operations on 'unmanaged' VDIs *)
let assert_managed ~__context ~vdi =
Expand Down
67 changes: 29 additions & 38 deletions ocaml/xapi/xapi_vm_lifecycle.ml
Original file line number Diff line number Diff line change
Expand Up @@ -749,50 +749,41 @@ let vtpm_update_allowed_operations ~__context ~self =
let allowed = match state with `Halted -> ops | _ -> [] in
Db.VTPM.set_allowed_operations ~__context ~self ~value:allowed

let ignored_ops =
[
`create_template
; `power_state_reset
; `csvm
; `get_boot_record
; `send_sysrq
; `send_trigger
; `query_services
; `shutdown
; `call_plugin
; `changing_memory_live
; `awaiting_memory_live
; `changing_memory_limits
; `changing_shadow_memory_live
; `changing_VCPUs
; `assert_operation_valid
; `data_source_op
; `update_allowed_operations
; `import
; `reverting
]

let allowable_ops =
List.filter (fun op -> not (List.mem op ignored_ops)) API.vm_operations__all

let update_allowed_operations ~__context ~self =
let check_operation_error = check_operation_error ~__context ~ref:self in
let check accu op =
match check_operation_error ~op ~strict:true with
match check_operation_error ~__context ~ref:self ~op ~strict:true with
| None ->
op :: accu
| _ ->
| Some _err ->
accu
in
let allowed =
List.fold_left check []
[
`snapshot
; `copy
; `clone
; `revert
; `checkpoint
; `snapshot_with_quiesce
; `start
; `start_on
; `pause
; `unpause
; `clean_shutdown
; `clean_reboot
; `hard_shutdown
; `hard_reboot
; `suspend
; `resume
; `resume_on
; `export
; `destroy
; `provision
; `changing_VCPUs_live
; `pool_migrate
; `migrate_send
; `make_into_template
; `changing_static_range
; `changing_shadow_memory
; `changing_dynamic_range
; `changing_NVRAM
; `create_vtpm
; `metadata_export
]
in
let allowed = List.fold_left check [] allowable_ops in
(* FIXME: need to be able to deal with rolling-upgrade for orlando as well *)
let allowed =
if Helpers.rolling_upgrade_in_progress ~__context then
Expand Down

0 comments on commit 723a498

Please sign in to comment.