Skip to content

Commit

Permalink
qmp: access the local QemuOptsLists for drive option
Browse files Browse the repository at this point in the history
Currently we have three QemuOptsList (qemu_common_drive_opts,
qemu_legacy_drive_opts, and qemu_drive_opts), only qemu_drive_opts
is added to vm_config_groups[].

This patch changes query-command-line-options to access three local
QemuOptsLists for drive option, and merge the description items
together.

Signed-off-by: Amos Kong <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
  • Loading branch information
amoskong authored and kevmw committed Nov 14, 2013
1 parent d48addd commit 968854c
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 2 deletions.
1 change: 0 additions & 1 deletion blockdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#include "sysemu/arch_init.h"

static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives);
extern QemuOptsList qemu_common_drive_opts;

static const char *const if_name[IF_COUNT] = {
[IF_NONE] = "none",
Expand Down
1 change: 1 addition & 0 deletions include/qemu/config-file.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
QemuOptsList *qemu_find_opts(const char *group);
QemuOptsList *qemu_find_opts_err(const char *group, Error **errp);
void qemu_add_opts(QemuOptsList *list);
void qemu_add_drive_opts(QemuOptsList *list);
int qemu_set_option(const char *str);
int qemu_global_option(const char *str);
void qemu_add_globals(void);
Expand Down
2 changes: 2 additions & 0 deletions include/sysemu/sysemu.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ QemuOpts *qemu_get_machine_opts(void);

bool usb_enabled(bool default_usb);

extern QemuOptsList qemu_legacy_drive_opts;
extern QemuOptsList qemu_common_drive_opts;
extern QemuOptsList qemu_drive_opts;
extern QemuOptsList qemu_chardev_opts;
extern QemuOptsList qemu_device_opts;
Expand Down
77 changes: 76 additions & 1 deletion util/qemu-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "qmp-commands.h"

static QemuOptsList *vm_config_groups[32];
static QemuOptsList *drive_config_groups[4];

static QemuOptsList *find_list(QemuOptsList **lists, const char *group,
Error **errp)
Expand Down Expand Up @@ -77,6 +78,59 @@ static CommandLineParameterInfoList *query_option_descs(const QemuOptDesc *desc)
return param_list;
}

/* remove repeated entry from the info list */
static void cleanup_infolist(CommandLineParameterInfoList *head)
{
CommandLineParameterInfoList *pre_entry, *cur, *del_entry;

cur = head;
while (cur->next) {
pre_entry = head;
while (pre_entry != cur->next) {
if (!strcmp(pre_entry->value->name, cur->next->value->name)) {
del_entry = cur->next;
cur->next = cur->next->next;
g_free(del_entry);
break;
}
pre_entry = pre_entry->next;
}
cur = cur->next;
}
}

/* merge the description items of two parameter infolists */
static void connect_infolist(CommandLineParameterInfoList *head,
CommandLineParameterInfoList *new)
{
CommandLineParameterInfoList *cur;

cur = head;
while (cur->next) {
cur = cur->next;
}
cur->next = new;
}

/* access all the local QemuOptsLists for drive option */
static CommandLineParameterInfoList *get_drive_infolist(void)
{
CommandLineParameterInfoList *head = NULL, *cur;
int i;

for (i = 0; drive_config_groups[i] != NULL; i++) {
if (!head) {
head = query_option_descs(drive_config_groups[i]->desc);
} else {
cur = query_option_descs(drive_config_groups[i]->desc);
connect_infolist(head, cur);
}
}
cleanup_infolist(head);

return head;
}

CommandLineOptionInfoList *qmp_query_command_line_options(bool has_option,
const char *option,
Error **errp)
Expand All @@ -89,7 +143,12 @@ CommandLineOptionInfoList *qmp_query_command_line_options(bool has_option,
if (!has_option || !strcmp(option, vm_config_groups[i]->name)) {
info = g_malloc0(sizeof(*info));
info->option = g_strdup(vm_config_groups[i]->name);
info->parameters = query_option_descs(vm_config_groups[i]->desc);
if (!strcmp("drive", vm_config_groups[i]->name)) {
info->parameters = get_drive_infolist();
} else {
info->parameters =
query_option_descs(vm_config_groups[i]->desc);
}
entry = g_malloc0(sizeof(*entry));
entry->value = info;
entry->next = conf_list;
Expand All @@ -109,6 +168,22 @@ QemuOptsList *qemu_find_opts_err(const char *group, Error **errp)
return find_list(vm_config_groups, group, errp);
}

void qemu_add_drive_opts(QemuOptsList *list)
{
int entries, i;

entries = ARRAY_SIZE(drive_config_groups);
entries--; /* keep list NULL terminated */
for (i = 0; i < entries; i++) {
if (drive_config_groups[i] == NULL) {
drive_config_groups[i] = list;
return;
}
}
fprintf(stderr, "ran out of space in drive_config_groups");
abort();
}

void qemu_add_opts(QemuOptsList *list)
{
int entries, i;
Expand Down
3 changes: 3 additions & 0 deletions vl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2867,6 +2867,9 @@ int main(int argc, char **argv, char **envp)
module_call_init(MODULE_INIT_QOM);

qemu_add_opts(&qemu_drive_opts);
qemu_add_drive_opts(&qemu_legacy_drive_opts);
qemu_add_drive_opts(&qemu_common_drive_opts);
qemu_add_drive_opts(&qemu_drive_opts);
qemu_add_opts(&qemu_chardev_opts);
qemu_add_opts(&qemu_device_opts);
qemu_add_opts(&qemu_netdev_opts);
Expand Down

0 comments on commit 968854c

Please sign in to comment.