Coverage Report

Created: 2026-11-20 08:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qemu/monitor/qemu-config-qmp.c
Line
Count
Source
1
/* SPDX-License-Identifier: GPL-2.0-or-later */
2
#include "qemu/osdep.h"
3
#include "qemu/target-info.h"
4
#include "qapi/error.h"
5
#include "qapi/qapi-commands-misc.h"
6
#include "qobject/qlist.h"
7
#include "qemu/option.h"
8
#include "qemu/config-file.h"
9
#include "hw/core/boards.h"
10
11
static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc)
12
0
{
13
0
    CommandLineParameterInfoList *param_list = NULL;
14
0
    CommandLineParameterInfo *info;
15
0
    int i;
16
17
0
    for (i = 0; desc[i].name != NULL; i++) {
18
0
        info = g_malloc0(sizeof(*info));
19
0
        info->name = g_strdup(desc[i].name);
20
21
0
        switch (desc[i].type) {
22
0
        case QEMU_OPT_STRING:
23
0
            info->type = COMMAND_LINE_PARAMETER_TYPE_STRING;
24
0
            break;
25
0
        case QEMU_OPT_BOOL:
26
0
            info->type = COMMAND_LINE_PARAMETER_TYPE_BOOLEAN;
27
0
            break;
28
0
        case QEMU_OPT_NUMBER:
29
0
            info->type = COMMAND_LINE_PARAMETER_TYPE_NUMBER;
30
0
            break;
31
0
        case QEMU_OPT_SIZE:
32
0
            info->type = COMMAND_LINE_PARAMETER_TYPE_SIZE;
33
0
            break;
34
0
        }
35
36
0
        info->help = g_strdup(desc[i].help);
37
0
        info->q_default = g_strdup(desc[i].def_value_str);
38
39
0
        QAPI_LIST_PREPEND(param_list, info);
40
0
    }
41
42
0
    return param_list;
43
0
}
44
45
/* remove repeated entry from the info list */
46
static void cleanup_infolist(CommandLineParameterInfoList *head)
47
0
{
48
0
    CommandLineParameterInfoList *pre_entry, *cur, *del_entry;
49
50
0
    cur = head;
51
0
    while (cur->next) {
52
0
        pre_entry = head;
53
0
        while (pre_entry != cur->next) {
54
0
            if (!strcmp(pre_entry->value->name, cur->next->value->name)) {
55
0
                del_entry = cur->next;
56
0
                cur->next = cur->next->next;
57
0
                del_entry->next = NULL;
58
0
                qapi_free_CommandLineParameterInfoList(del_entry);
59
0
                break;
60
0
            }
61
0
            pre_entry = pre_entry->next;
62
0
        }
63
0
        cur = cur->next;
64
0
    }
65
0
}
66
67
/* merge the description items of two parameter infolists */
68
static void connect_infolist(CommandLineParameterInfoList *head,
69
                             CommandLineParameterInfoList *new)
70
0
{
71
0
    CommandLineParameterInfoList *cur;
72
73
0
    cur = head;
74
0
    while (cur->next) {
75
0
        cur = cur->next;
76
0
    }
77
0
    cur->next = new;
78
0
}
79
80
/* access all the local QemuOptsLists for drive option */
81
static CommandLineParameterInfoList *get_drive_infolist(void)
82
0
{
83
0
    CommandLineParameterInfoList *head = NULL, *cur;
84
0
    int i;
85
86
0
    for (i = 0; drive_config_groups[i] != NULL; i++) {
87
0
        if (!head) {
88
0
            head = query_option_descs(drive_config_groups[i]->desc);
89
0
        } else {
90
0
            cur = query_option_descs(drive_config_groups[i]->desc);
91
0
            connect_infolist(head, cur);
92
0
        }
93
0
    }
94
0
    cleanup_infolist(head);
95
96
0
    return head;
97
0
}
98
99
static CommandLineParameterInfo *objprop_to_cmdline_prop(ObjectProperty *prop)
100
0
{
101
0
    CommandLineParameterInfo *info;
102
103
0
    info = g_malloc0(sizeof(*info));
104
0
    info->name = g_strdup(prop->name);
105
106
0
    if (g_str_equal(prop->type, "bool") || g_str_equal(prop->type, "OnOffAuto")) {
107
0
        info->type = COMMAND_LINE_PARAMETER_TYPE_BOOLEAN;
108
0
    } else if (g_str_equal(prop->type, "int")) {
109
0
        info->type = COMMAND_LINE_PARAMETER_TYPE_NUMBER;
110
0
    } else if (g_str_equal(prop->type, "size")) {
111
0
        info->type = COMMAND_LINE_PARAMETER_TYPE_SIZE;
112
0
    } else {
113
0
        info->type = COMMAND_LINE_PARAMETER_TYPE_STRING;
114
0
    }
115
116
0
    if (prop->description) {
117
0
        info->help = g_strdup(prop->description);
118
0
    }
119
120
0
    return info;
121
0
}
122
123
static CommandLineParameterInfoList *query_all_machine_properties(void)
124
0
{
125
0
    CommandLineParameterInfoList *params = NULL, *clpiter;
126
0
    CommandLineParameterInfo *info;
127
0
    GSList *machines, *curr_mach;
128
0
    ObjectPropertyIterator op_iter;
129
0
    ObjectProperty *prop;
130
0
    bool is_new;
131
132
0
    machines = object_class_get_list(TYPE_MACHINE, false);
133
0
    assert(machines);
134
135
    /* Loop over all machine classes */
136
0
    for (curr_mach = machines; curr_mach; curr_mach = curr_mach->next) {
137
0
        object_class_property_iter_init(&op_iter, curr_mach->data);
138
        /* ... and over the properties of each machine: */
139
0
        while ((prop = object_property_iter_next(&op_iter))) {
140
0
            if (!prop->set) {
141
0
                continue;
142
0
            }
143
            /*
144
             * Check whether the property has already been put into the list
145
             * (via another machine class)
146
             */
147
0
            is_new = true;
148
0
            for (clpiter = params; clpiter != NULL; clpiter = clpiter->next) {
149
0
                if (g_str_equal(clpiter->value->name, prop->name)) {
150
0
                    is_new = false;
151
0
                    break;
152
0
                }
153
0
            }
154
            /* If it hasn't been added before, add it now to the list */
155
0
            if (is_new) {
156
0
                info = objprop_to_cmdline_prop(prop);
157
0
                QAPI_LIST_PREPEND(params, info);
158
0
            }
159
0
        }
160
0
    }
161
162
0
    g_slist_free(machines);
163
164
    /* Add entry for the "type" parameter */
165
0
    info = g_malloc0(sizeof(*info));
166
0
    info->name = g_strdup("type");
167
0
    info->type = COMMAND_LINE_PARAMETER_TYPE_STRING;
168
0
    info->help = g_strdup("machine type");
169
0
    QAPI_LIST_PREPEND(params, info);
170
171
0
    return params;
172
0
}
173
174
CommandLineOptionInfoList *qmp_query_command_line_options(const char *option,
175
                                                          Error **errp)
176
0
{
177
0
    CommandLineOptionInfoList *conf_list = NULL;
178
0
    CommandLineOptionInfo *info;
179
0
    int i;
180
181
0
    for (i = 0; vm_config_groups[i] != NULL; i++) {
182
0
        if (!option || !strcmp(option, vm_config_groups[i]->name)) {
183
0
            info = g_malloc0(sizeof(*info));
184
0
            info->option = g_strdup(vm_config_groups[i]->name);
185
0
            if (!strcmp("drive", vm_config_groups[i]->name)) {
186
0
                info->parameters = get_drive_infolist();
187
0
            } else {
188
0
                info->parameters =
189
0
                    query_option_descs(vm_config_groups[i]->desc);
190
0
            }
191
0
            QAPI_LIST_PREPEND(conf_list, info);
192
0
        }
193
0
    }
194
195
0
    if (!option || !strcmp(option, "machine")) {
196
0
        info = g_malloc0(sizeof(*info));
197
0
        info->option = g_strdup("machine");
198
0
        info->parameters = query_all_machine_properties();
199
0
        QAPI_LIST_PREPEND(conf_list, info);
200
0
    }
201
202
0
    if (conf_list == NULL) {
203
0
        error_setg(errp, "invalid option name: %s", option);
204
0
    }
205
206
0
    return conf_list;
207
0
}