Skip to content

Commit b56df25

Browse files
authored
Fix xe host-get-cpu-features command, add pool-get-cpu-features (#6513)
`Host.cpu_info` list no longer contains a value associated with a "features" key, but the CLI implementation was hardcoded to expect it. As a result, it would show an unhelpful error like: ``` The server failed to handle your request, due to an internal error. The given message may give details useful for debugging the problem. message: INTERNAL_ERROR: [ Not_found ] ``` Instead use the `cpu_info_features` keys from xapi-consts (after moving these keys from xapi-globs first). Add the pool version of the command. Additionally document their output format: ``` # xe help host-get-cpu-features command name : host-get-cpu-features reqd params : optional params : uuid description : Prints a hexadecimal representation of the host's physical-CPU features for PV and HVM VMs. features_{hvm,pv} are "maximum" featuresets the host will accept during migrations, and features_{hvm,pv}_host will be used to start new VMs. # xe help pool-get-cpu-features command name : pool-get-cpu-features reqd params : optional params : description : Prints a hexadecimal representation of the pool's physical-CPU features for PV and HVM VMs. These are combinations of all the hosts' policies and are used when starting new VMs in a pool. # xe host-get-cpu-features uuid=7f566729-0ee7-47c4-853d-2c5f3a195ad4 features_pv : 1fc9cbf5-f6f83203-2991cbf5-00000123-00000001-000c0b39-00000000-00000100-00001000-ac000c00-00000000-00000000-00000000-00000000-00000000-00000000-1c020004-00000000-00000000-00000000-00000000-00000000 features_hvm: 1fcbfbff-f7fa3223-2d93fbff-00000523-00000001-001c0fbb-00000000-00000100-00101000-bc000c00-00000000-00000000-00000000-00000000-00000000-00000000-1c020004-00000000-00000000-00000000-00000000-00000000 features_pv_host: 1fc9cbf5-f6d83203-28100800-00000121-00000001-000c0b29-00000000-00000000-00001000-ac000400-00000000-00000000-00000000-00000000-00000000-00000000-0c000000-00000000-00000000-00000000-00000000-00000000 features_hvm_host: 1fcbfbff-f7fa3203-2c100800-00000121-00000001-001c0fab-00000000-00000000-00101000-bc000400-00000000-00000000-00000000-00000000-00000000-00000000-0c000000-00000000-00000000-00000000-00000000-00000000 # xe pool-get-cpu-features features_pv_host : 1fc9cbf5-f6d83203-28100800-00000121-00000001-000c0b29-00000000-00000000-00001000-ac000400-00000000-00000000-00000000-00000000-00000000-00000000-0c000000-00000000-00000000-00000000-00000000-00000000 features_hvm_host: 1fcbfbff-f7fa3203-2c100800-00000121-00000001-001c0fab-00000000-00000000-00101000-bc000400-00000000-00000000-00000000-00000000-00000000-00000000-0c000000-00000000-00000000-00000000-00000000-00000000 ``` ==== Tested manually
2 parents c3186c4 + c23f1a3 commit b56df25

File tree

9 files changed

+88
-44
lines changed

9 files changed

+88
-44
lines changed

ocaml/tests/test_xapi_xenops.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ let test_xapi_restart_inner () =
6262
in
6363
let flags =
6464
[
65-
(Xapi_globs.cpu_info_vendor_key, "AuthenticAMD")
66-
; (Xapi_globs.cpu_info_features_key, "deadbeef-deadbeef")
65+
(Constants.cpu_info_vendor_key, "AuthenticAMD")
66+
; (Constants.cpu_info_features_key, "deadbeef-deadbeef")
6767
]
6868
in
6969
let add_flags vm =

ocaml/tests/test_xenopsd_metadata.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ let load_vm_config __context conf =
3838
in
3939
let flags =
4040
[
41-
(Xapi_globs.cpu_info_vendor_key, "AuthenticAMD")
42-
; (Xapi_globs.cpu_info_features_key, "deadbeef-deadbeef")
41+
(Constants.cpu_info_vendor_key, "AuthenticAMD")
42+
; (Constants.cpu_info_features_key, "deadbeef-deadbeef")
4343
]
4444
in
4545
Db.VM.set_last_boot_CPU_flags ~__context ~self ~value:flags ;

ocaml/xapi-cli-server/cli_frontend.ml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,18 @@ let rec cmdtable_data : (string * cmd_spec) list =
529529
; flags= []
530530
}
531531
)
532+
; ( "pool-get-cpu-features"
533+
, {
534+
reqd= []
535+
; optn= []
536+
; help=
537+
{|Prints a hexadecimal representation of the pool's physical-CPU
538+
features for PV and HVM VMs. These are combinations of all the
539+
hosts' policies and are used when starting new VMs in a pool.|}
540+
; implementation= No_fd Cli_operations.pool_get_cpu_features
541+
; flags= []
542+
}
543+
)
532544
; ( "host-is-in-emergency-mode"
533545
, {
534546
reqd= []
@@ -1012,8 +1024,10 @@ let rec cmdtable_data : (string * cmd_spec) list =
10121024
reqd= []
10131025
; optn= ["uuid"]
10141026
; help=
1015-
"Prints a hexadecimal representation of the host's physical-CPU \
1016-
features."
1027+
{|Prints a hexadecimal representation of the host's physical-CPU
1028+
features for PV and HVM VMs. features_{hvm,pv} are "maximum"
1029+
featuresets the host will accept during migrations, and
1030+
features_{hvm,pv}_host will be used to start new VMs.|}
10171031
; implementation= No_fd Cli_operations.host_get_cpu_features
10181032
; flags= []
10191033
}

ocaml/xapi-cli-server/cli_operations.ml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6819,6 +6819,28 @@ let pool_get_guest_secureboot_readiness printer rpc session_id params =
68196819
(Record_util.pool_guest_secureboot_readiness_to_string result)
68206820
)
68216821

6822+
let cpu_info_features_of feature_keys cpu_info =
6823+
let ( let* ) = Option.bind in
6824+
List.filter_map
6825+
(fun key ->
6826+
let* features = List.assoc_opt key cpu_info in
6827+
Some (key, features)
6828+
)
6829+
feature_keys
6830+
6831+
let pool_get_cpu_features printer rpc session_id params =
6832+
let pool = get_pool_with_default rpc session_id params "uuid" in
6833+
let cpu_info = Client.Pool.get_cpu_info ~rpc ~session_id ~self:pool in
6834+
6835+
let feature_keys =
6836+
[
6837+
Constants.cpu_info_features_pv_host_key
6838+
; Constants.cpu_info_features_hvm_host_key
6839+
]
6840+
in
6841+
let features = cpu_info_features_of feature_keys cpu_info in
6842+
printer (Cli_printer.PTable [features])
6843+
68226844
let pool_sync_bundle fd _printer rpc session_id params =
68236845
let filename_opt = List.assoc_opt "filename" params in
68246846
match filename_opt with
@@ -6988,8 +7010,17 @@ let host_get_cpu_features printer rpc session_id params =
69887010
get_host_from_session rpc session_id
69897011
in
69907012
let cpu_info = Client.Host.get_cpu_info ~rpc ~session_id ~self:host in
6991-
let features = List.assoc "features" cpu_info in
6992-
printer (Cli_printer.PMsg features)
7013+
7014+
let feature_keys =
7015+
[
7016+
Constants.cpu_info_features_pv_key
7017+
; Constants.cpu_info_features_hvm_key
7018+
; Constants.cpu_info_features_pv_host_key
7019+
; Constants.cpu_info_features_hvm_host_key
7020+
]
7021+
in
7022+
let features = cpu_info_features_of feature_keys cpu_info in
7023+
printer (Cli_printer.PTable [features])
69937024

69947025
let host_enable_display printer rpc session_id params =
69957026
let host =

ocaml/xapi-consts/constants.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,20 @@ let hvm_boot_params_order = "order"
177177

178178
let hvm_default_boot_order = "cd"
179179

180+
(** Keys for different CPUID policies in {Host,Pool}.cpu_info *)
181+
182+
let cpu_info_vendor_key = "vendor"
183+
184+
let cpu_info_features_key = "features"
185+
186+
let cpu_info_features_pv_key = "features_pv"
187+
188+
let cpu_info_features_hvm_key = "features_hvm"
189+
190+
let cpu_info_features_pv_host_key = "features_pv_host"
191+
192+
let cpu_info_features_hvm_host_key = "features_hvm_host"
193+
180194
(* Key we put in VM.other_config when we upgrade a VM from Zurich/Geneva to Rio *)
181195
let vm_upgrade_time = "upgraded at"
182196

ocaml/xapi/cpuid_helpers.ml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
* GNU Lesser General Public License for more details.
1313
*)
1414

15-
open Xapi_globs
16-
1715
module D = Debug.Make (struct let name = "cpuid_helpers" end)
1816

1917
open D
@@ -24,20 +22,19 @@ let features_t t =
2422
(Xenops_interface.CPU_policy.of_string t)
2523
Xenops_interface.CPU_policy.to_string
2624

27-
let features =
28-
Map_check.(field Xapi_globs.cpu_info_features_key (features_t `vm))
25+
let features = Map_check.(field Constants.cpu_info_features_key (features_t `vm))
2926

3027
let features_pv =
31-
Map_check.(field Xapi_globs.cpu_info_features_pv_key (features_t `host))
28+
Map_check.(field Constants.cpu_info_features_pv_key (features_t `host))
3229

3330
let features_hvm =
34-
Map_check.(field Xapi_globs.cpu_info_features_hvm_key (features_t `host))
31+
Map_check.(field Constants.cpu_info_features_hvm_key (features_t `host))
3532

3633
let features_pv_host =
37-
Map_check.(field Xapi_globs.cpu_info_features_pv_host_key (features_t `host))
34+
Map_check.(field Constants.cpu_info_features_pv_host_key (features_t `host))
3835

3936
let features_hvm_host =
40-
Map_check.(field Xapi_globs.cpu_info_features_hvm_host_key (features_t `host))
37+
Map_check.(field Constants.cpu_info_features_hvm_host_key (features_t `host))
4138

4239
let cpu_count = Map_check.(field "cpu_count" int)
4340

@@ -55,7 +52,7 @@ let get_flags_for_vm ~__context domain_type cpu_info =
5552
| `pv ->
5653
features_pv
5754
in
58-
let vendor = List.assoc cpu_info_vendor_key cpu_info in
55+
let vendor = List.assoc Constants.cpu_info_vendor_key cpu_info in
5956
let migration = Map_check.getf features_field cpu_info in
6057
(vendor, migration)
6158

@@ -124,16 +121,18 @@ let assert_vm_is_compatible ~__context ~vm ~host =
124121
get_host_compatibility_info ~__context ~domain_type ~host ()
125122
in
126123
let vm_cpu_info = vm_rec.API.vM_last_boot_CPU_flags in
127-
if List.mem_assoc cpu_info_vendor_key vm_cpu_info then (
124+
if List.mem_assoc Constants.cpu_info_vendor_key vm_cpu_info then (
128125
(* Check the VM was last booted on a CPU with the same vendor as this host's CPU. *)
129-
let vm_cpu_vendor = List.assoc cpu_info_vendor_key vm_cpu_info in
126+
let vm_cpu_vendor =
127+
List.assoc Constants.cpu_info_vendor_key vm_cpu_info
128+
in
130129
debug "VM last booted on CPU of vendor %s; host CPUs are of vendor %s"
131130
vm_cpu_vendor host_cpu_vendor ;
132131
if vm_cpu_vendor <> host_cpu_vendor then
133132
fail
134133
"VM last booted on a host which had a CPU from a different vendor."
135134
) ;
136-
if List.mem_assoc cpu_info_features_key vm_cpu_info then (
135+
if List.mem_assoc Constants.cpu_info_features_key vm_cpu_info then (
137136
(* Check the VM was last booted on a CPU whose features are a subset of the features of this host's CPU. *)
138137
let vm_cpu_features = Map_check.getf features vm_cpu_info in
139138
debug

ocaml/xapi/create_misc.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -579,16 +579,16 @@ let create_host_cpu ~__context host_info =
579579
; ("model", cpu_info.model)
580580
; ("stepping", cpu_info.stepping)
581581
; ("flags", cpu_info.flags)
582-
; ( Xapi_globs.cpu_info_features_pv_key
582+
; ( Constants.cpu_info_features_pv_key
583583
, CPU_policy.to_string cpu_info.features_pv
584584
)
585-
; ( Xapi_globs.cpu_info_features_hvm_key
585+
; ( Constants.cpu_info_features_hvm_key
586586
, CPU_policy.to_string cpu_info.features_hvm
587587
)
588-
; ( Xapi_globs.cpu_info_features_hvm_host_key
588+
; ( Constants.cpu_info_features_hvm_host_key
589589
, CPU_policy.to_string cpu_info.features_hvm_host
590590
)
591-
; ( Xapi_globs.cpu_info_features_pv_host_key
591+
; ( Constants.cpu_info_features_pv_host_key
592592
, CPU_policy.to_string cpu_info.features_pv_host
593593
)
594594
]
@@ -698,8 +698,8 @@ let create_pool_cpuinfo ~__context =
698698
("vendor", "")
699699
; ("socket_count", "0")
700700
; ("cpu_count", "0")
701-
; (Xapi_globs.cpu_info_features_pv_host_key, "")
702-
; (Xapi_globs.cpu_info_features_hvm_host_key, "")
701+
; (Constants.cpu_info_features_pv_host_key, "")
702+
; (Constants.cpu_info_features_hvm_host_key, "")
703703
]
704704
in
705705
let pool_cpuinfo = List.fold_left merge zero all_host_cpus in

ocaml/xapi/xapi_globs.ml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -631,20 +631,6 @@ let auth_type_PAM = "PAM"
631631

632632
let event_hook_auth_on_xapi_initialize_succeeded = ref false
633633

634-
(** {2 CPUID feature masking} *)
635-
636-
let cpu_info_vendor_key = "vendor"
637-
638-
let cpu_info_features_key = "features"
639-
640-
let cpu_info_features_pv_key = "features_pv"
641-
642-
let cpu_info_features_hvm_key = "features_hvm"
643-
644-
let cpu_info_features_pv_host_key = "features_pv_host"
645-
646-
let cpu_info_features_hvm_host_key = "features_hvm_host"
647-
648634
(** Metrics *)
649635

650636
let metrics_root = "/dev/shm/metrics"

ocaml/xapi/xapi_xenops.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ module MD = struct
12131213
if not (List.mem_assoc Vm_platform.featureset platformdata) then
12141214
let featureset =
12151215
match
1216-
List.assoc_opt Xapi_globs.cpu_info_features_key
1216+
List.assoc_opt Constants.cpu_info_features_key
12171217
vm.API.vM_last_boot_CPU_flags
12181218
with
12191219
| _ when vm.API.vM_power_state <> `Suspended ->
@@ -2418,12 +2418,12 @@ let update_vm ~__context id =
24182418
state.Vm.featureset ;
24192419
let vendor =
24202420
Db.Host.get_cpu_info ~__context ~self:localhost
2421-
|> List.assoc Xapi_globs.cpu_info_vendor_key
2421+
|> List.assoc Constants.cpu_info_vendor_key
24222422
in
24232423
let value =
24242424
[
2425-
(Xapi_globs.cpu_info_vendor_key, vendor)
2426-
; (Xapi_globs.cpu_info_features_key, state.Vm.featureset)
2425+
(Constants.cpu_info_vendor_key, vendor)
2426+
; (Constants.cpu_info_features_key, state.Vm.featureset)
24272427
]
24282428
in
24292429
Db.VM.set_last_boot_CPU_flags ~__context ~self ~value

0 commit comments

Comments
 (0)