1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Dietmar Maurer <dietmar@proxmox.com>
3 Date: Mon, 6 Apr 2020 12:16:55 +0200
4 Subject: [PATCH] PVE: Allow version code in machine type
6 E.g. pc-i440fx-4.0+pve3 would print 'pve3' as version code while
7 selecting pc-i440fx-4.0 as machine type.
9 Version is made available as 'pve-version' in query-machines (same as,
10 and only if 'is-current').
12 Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
13 Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
14 [FE: adapt to QAPI changes]
15 Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
17 hw/core/machine-qmp-cmds.c | 5 +++++
18 include/hw/boards.h | 2 ++
19 qapi/machine.json | 4 +++-
20 system/vl.c | 25 +++++++++++++++++++++++++
21 4 files changed, 35 insertions(+), 1 deletion(-)
23 diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
24 index 40821e2317..ee93ddd69a 100644
25 --- a/hw/core/machine-qmp-cmds.c
26 +++ b/hw/core/machine-qmp-cmds.c
27 @@ -95,6 +95,11 @@ MachineInfoList *qmp_query_machines(Error **errp)
28 if (strcmp(mc->name, MACHINE_GET_CLASS(current_machine)->name) == 0) {
29 info->has_is_current = true;
30 info->is_current = true;
32 + // PVE version string only exists for current machine
33 + if (mc->pve_version) {
34 + info->pve_version = g_strdup(mc->pve_version);
38 if (mc->default_cpu_type) {
39 diff --git a/include/hw/boards.h b/include/hw/boards.h
40 index da85f86efb..1aa0987020 100644
41 --- a/include/hw/boards.h
42 +++ b/include/hw/boards.h
43 @@ -240,6 +240,8 @@ struct MachineClass {
45 const char *deprecation_reason;
47 + const char *pve_version;
49 void (*init)(MachineState *state);
50 void (*reset)(MachineState *state, ShutdownCause reason);
51 void (*wakeup)(MachineState *state);
52 diff --git a/qapi/machine.json b/qapi/machine.json
53 index 297ad0e0e5..a9fd40d844 100644
54 --- a/qapi/machine.json
55 +++ b/qapi/machine.json
58 # @acpi: machine type supports ACPI (since 8.0)
60 +# @pve-version: custom PVE version suffix specified as 'machine+pveN'
64 { 'struct': 'MachineInfo',
66 '*is-default': 'bool', '*is-current': 'bool', 'cpu-max': 'int',
67 'hotpluggable-cpus': 'bool', 'numa-mem-supported': 'bool',
68 'deprecated': 'bool', '*default-cpu-type': 'str',
69 - '*default-ram-id': 'str', 'acpi': 'bool' } }
70 + '*default-ram-id': 'str', 'acpi': 'bool', '*pve-version': 'str' } }
74 diff --git a/system/vl.c b/system/vl.c
75 index 56d715c818..87f03e61a1 100644
78 @@ -1660,6 +1660,7 @@ static const QEMUOption *lookup_opt(int argc, char **argv,
79 static MachineClass *select_machine(QDict *qdict, Error **errp)
81 const char *machine_type = qdict_get_try_str(qdict, "type");
82 + const char *pvever = qdict_get_try_str(qdict, "pvever");
83 GSList *machines = object_class_get_list(TYPE_MACHINE, false);
84 MachineClass *machine_class;
85 Error *local_err = NULL;
86 @@ -1677,6 +1678,11 @@ static MachineClass *select_machine(QDict *qdict, Error **errp)
90 + if (machine_class) {
91 + machine_class->pve_version = g_strdup(pvever);
92 + qdict_del(qdict, "pvever");
95 g_slist_free(machines);
97 error_append_hint(&local_err, "Use -machine help to list supported machines\n");
98 @@ -3319,12 +3325,31 @@ void qemu_init(int argc, char **argv)
99 case QEMU_OPTION_machine:
102 + size_t pvever_index, name_len;
104 + gchar *name_clean, *pvever;
106 keyval_parse_into(machine_opts_dict, optarg, "type", &help, &error_fatal);
108 machine_help_func(machine_opts_dict);
112 + // PVE version is specified with '+' as seperator, e.g. pc-i440fx+pvever
113 + name = qdict_get_try_str(machine_opts_dict, "type");
114 + if (name != NULL) {
115 + name_len = strlen(name);
116 + pvever_index = strcspn(name, "+");
117 + if (pvever_index < name_len) {
118 + name_clean = g_strndup(name, pvever_index);
119 + pvever = g_strndup(name + pvever_index + 1, name_len - pvever_index - 1);
120 + qdict_put_str(machine_opts_dict, "pvever", pvever);
121 + qdict_put_str(machine_opts_dict, "type", name_clean);
122 + g_free(name_clean);
129 case QEMU_OPTION_accel: