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