]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/pve/0024-PVE-Allow-version-code-in-machine-type.patch
c54a5f8107f6bf5a417839a0b6d894014dad09de
[pve-qemu.git] / debian / patches / pve / 0024-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 ---
14 hw/core/machine-qmp-cmds.c | 6 ++++++
15 include/hw/boards.h | 2 ++
16 qapi/machine.json | 4 +++-
17 softmmu/vl.c | 23 +++++++++++++++++++++++
18 4 files changed, 34 insertions(+), 1 deletion(-)
19
20 diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c
21 index 8f8d5d5276..370e66d9cc 100644
22 --- a/hw/core/machine-qmp-cmds.c
23 +++ b/hw/core/machine-qmp-cmds.c
24 @@ -102,6 +102,12 @@ MachineInfoList *qmp_query_machines(Error **errp)
25 if (strcmp(mc->name, MACHINE_GET_CLASS(current_machine)->name) == 0) {
26 info->has_is_current = true;
27 info->is_current = true;
28 +
29 + // PVE version string only exists for current machine
30 + if (mc->pve_version) {
31 + info->has_pve_version = true;
32 + info->pve_version = g_strdup(mc->pve_version);
33 + }
34 }
35
36 if (mc->default_cpu_type) {
37 diff --git a/include/hw/boards.h b/include/hw/boards.h
38 index accd6eff35..1b16728389 100644
39 --- a/include/hw/boards.h
40 +++ b/include/hw/boards.h
41 @@ -205,6 +205,8 @@ struct MachineClass {
42 const char *desc;
43 const char *deprecation_reason;
44
45 + const char *pve_version;
46 +
47 void (*init)(MachineState *state);
48 void (*reset)(MachineState *state);
49 void (*wakeup)(MachineState *state);
50 diff --git a/qapi/machine.json b/qapi/machine.json
51 index cf120ac343..a6f483af4f 100644
52 --- a/qapi/machine.json
53 +++ b/qapi/machine.json
54 @@ -160,6 +160,8 @@
55 #
56 # @default-ram-id: the default ID of initial RAM memory backend (since 5.2)
57 #
58 +# @pve-version: custom PVE version suffix specified as 'machine+pveN'
59 +#
60 # Since: 1.2
61 ##
62 { 'struct': 'MachineInfo',
63 @@ -167,7 +169,7 @@
64 '*is-default': 'bool', '*is-current': 'bool', 'cpu-max': 'int',
65 'hotpluggable-cpus': 'bool', 'numa-mem-supported': 'bool',
66 'deprecated': 'bool', '*default-cpu-type': 'str',
67 - '*default-ram-id': 'str' } }
68 + '*default-ram-id': 'str', '*pve-version': 'str' } }
69
70 ##
71 # @query-machines:
72 diff --git a/softmmu/vl.c b/softmmu/vl.c
73 index d87cf6e103..e5010236f3 100644
74 --- a/softmmu/vl.c
75 +++ b/softmmu/vl.c
76 @@ -1621,6 +1621,7 @@ static const QEMUOption *lookup_opt(int argc, char **argv,
77 static MachineClass *select_machine(QDict *qdict, Error **errp)
78 {
79 const char *optarg = qdict_get_try_str(qdict, "type");
80 + const char *pvever = qdict_get_try_str(qdict, "pvever");
81 GSList *machines = object_class_get_list(TYPE_MACHINE, false);
82 MachineClass *machine_class;
83 Error *local_err = NULL;
84 @@ -1638,6 +1639,11 @@ static MachineClass *select_machine(QDict *qdict, Error **errp)
85 }
86 }
87
88 + if (machine_class) {
89 + machine_class->pve_version = g_strdup(pvever);
90 + qdict_del(qdict, "pvever");
91 + }
92 +
93 g_slist_free(machines);
94 if (local_err) {
95 error_append_hint(&local_err, "Use -machine help to list supported machines\n");
96 @@ -3312,12 +3318,29 @@ void qemu_init(int argc, char **argv, char **envp)
97 case QEMU_OPTION_machine:
98 {
99 bool help;
100 + size_t pvever_index, name_len;
101 + const gchar *name;
102 + gchar *name_clean, *pvever;
103
104 keyval_parse_into(machine_opts_dict, optarg, "type", &help, &error_fatal);
105 if (help) {
106 machine_help_func(machine_opts_dict);
107 exit(EXIT_SUCCESS);
108 }
109 +
110 + // PVE version is specified with '+' as seperator, e.g. pc-i440fx+pvever
111 + name = qdict_get_try_str(machine_opts_dict, "type");
112 + name_len = strlen(name);
113 + pvever_index = strcspn(name, "+");
114 + if (pvever_index < name_len) {
115 + name_clean = g_strndup(name, pvever_index);
116 + pvever = g_strndup(name + pvever_index + 1, name_len - pvever_index - 1);
117 + qdict_put_str(machine_opts_dict, "pvever", pvever);
118 + qdict_put_str(machine_opts_dict, "type", name_clean);
119 + g_free(name_clean);
120 + g_free(pvever);
121 + }
122 +
123 break;
124 }
125 case QEMU_OPTION_accel: