]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/pve/0025-PVE-Allow-version-code-in-machine-type.patch
eb2730437c3fad6bde51ef7ff33cef80b3421526
[pve-qemu.git] / debian / patches / pve / 0025-PVE-Allow-version-code-in-machine-type.patch
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
5
6 E.g. pc-i440fx-4.0+pve3 would print 'pve3' as version code while
7 selecting pc-i440fx-4.0 as machine type.
8
9 Version is made available as 'pve-version' in query-machines (same as,
10 and only if 'is-current').
11
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>
16 ---
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(-)
22
23 diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
24 index 314351cdff..628a3537c5 100644
25 --- a/hw/core/machine-qmp-cmds.c
26 +++ b/hw/core/machine-qmp-cmds.c
27 @@ -94,6 +94,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;
31 +
32 + // PVE version string only exists for current machine
33 + if (mc->pve_version) {
34 + info->pve_version = g_strdup(mc->pve_version);
35 + }
36 }
37
38 if (mc->default_cpu_type) {
39 diff --git a/include/hw/boards.h b/include/hw/boards.h
40 index 8b8f6d5c00..dd6d0a1447 100644
41 --- a/include/hw/boards.h
42 +++ b/include/hw/boards.h
43 @@ -246,6 +246,8 @@ struct MachineClass {
44 const char *desc;
45 const char *deprecation_reason;
46
47 + const char *pve_version;
48 +
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 a024d5b05d..1d69bffaa0 100644
54 --- a/qapi/machine.json
55 +++ b/qapi/machine.json
56 @@ -168,6 +168,8 @@
57 #
58 # @acpi: machine type supports ACPI (since 8.0)
59 #
60 +# @pve-version: custom PVE version suffix specified as 'machine+pveN'
61 +#
62 # Since: 1.2
63 ##
64 { 'struct': 'MachineInfo',
65 @@ -175,7 +177,7 @@
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' } }
71
72 ##
73 # @query-machines:
74 diff --git a/system/vl.c b/system/vl.c
75 index 20ebf2c920..4d39e32097 100644
76 --- a/system/vl.c
77 +++ b/system/vl.c
78 @@ -1659,6 +1659,7 @@ static const QEMUOption *lookup_opt(int argc, char **argv,
79 static MachineClass *select_machine(QDict *qdict, Error **errp)
80 {
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 @@ -1676,6 +1677,11 @@ static MachineClass *select_machine(QDict *qdict, Error **errp)
87 }
88 }
89
90 + if (machine_class) {
91 + machine_class->pve_version = g_strdup(pvever);
92 + qdict_del(qdict, "pvever");
93 + }
94 +
95 g_slist_free(machines);
96 if (local_err) {
97 error_append_hint(&local_err, "Use -machine help to list supported machines\n");
98 @@ -3313,12 +3319,31 @@ void qemu_init(int argc, char **argv)
99 case QEMU_OPTION_machine:
100 {
101 bool help;
102 + size_t pvever_index, name_len;
103 + const gchar *name;
104 + gchar *name_clean, *pvever;
105
106 keyval_parse_into(machine_opts_dict, optarg, "type", &help, &error_fatal);
107 if (help) {
108 machine_help_func(machine_opts_dict);
109 exit(EXIT_SUCCESS);
110 }
111 +
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);
123 + g_free(pvever);
124 + }
125 + }
126 +
127 break;
128 }
129 case QEMU_OPTION_accel: