Re: [Qemu-devel] [PATCH v3 for 2.0] update names in option tables to match with actual command-line spelling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Mar 27, 2014 at 10:16:44AM +0800, Amos Kong wrote:
> On Wed, Mar 26, 2014 at 05:12:08PM +0100, Markus Armbruster wrote:
> > Eric Blake <eblake@xxxxxxxxxx> writes:

...
> > > Reviewed-by: Eric Blake <eblake@xxxxxxxxxx>
> > 
> > I'm not thrilled about the ABI break, but avoiding it would probably
> > take too much code for too little gain.
 
Hi Markus, Eric

> We can add an 'alias_index' field to QemuOptsList, and init it to -1
> in qemu_add_opts().
> 
> And we only re-set 'alias_index' to 'popt->index' in vl.c(option parsing part)
> then we can find opts by qemu_options[i].index.
> 
> We also need to give a warning () if it's group name of added QemuOptsList
> doesn't match with defined option name.
> 
> If someone add a new QemuOpts and the group name doesn't match, he/she will
> get a warning, and call a help function to re-set 'alias_index'.
>  
> I can send a RFC patch for this.

* Option 1
Attached two RFC patches, it added a new field ('alias_index') to
QemuOptsList, and record QEMU_OPTION enum-index to it when group
name of option table doesn't match option name.

And try to find list by index before find list by option name in
qmp_query_command_line_options().

This can avoid the ABI breaking, it also introduced some trouble.
We also need to check if alias_index of unmatched option is set
to a positive number, and report error (option name doesn't match, and
alias_index isn't set) in error state.

* Option 2
OR pass enum-index to qemu_add_opts(), and set enum-index for all the options.
   -void qemu_add_opts(QemuOptsList *list)
   +void qemu_add_opts(QemuOptsList *list, int index)

* Option 3 break ABI

Let's make a decision.

> > How can we prevent future violations of the convention "QemuOptsList
> > member name matches the name of the (primary) option using it for its
> > argument"?  Right now, all we have is /* option name */ tacked to the
> > member.  Which is at best a reminder for those who already know.
> 
> It's absolutely necessary!
>  
> > I'd ask for a test catching violations if I could think of an easy way
> > to code it.
> 
> Currently I prefer this option, so I will send a V3 with strict checking.


-- 
			Amos.
>From 7e5f08331fdcc074027de0767bcbbc4d3af9a546 Mon Sep 17 00:00:00 2001
From: Amos Kong <akong@xxxxxxxxxx>
Date: Thu, 27 Mar 2014 07:37:24 +0800
Subject: [PATCH RFC 1/2] add alias_index to QemuOptsList

If group name of option table doesn't match with option name,
we will save the index of QEMU_OPTION index to alias_index.
Then we can try to find QemuOptsList by index for unmatched
options.

alias_index of matched options will be set to -1.

Signed-off-by: Amos Kong <akong@xxxxxxxxxx>
---
 hw/acpi/core.c             |  2 ++
 include/qapi/qmp/qerror.h  |  3 +++
 include/qemu/config-file.h |  1 +
 include/qemu/option.h      |  1 +
 util/qemu-config.c         | 16 ++++++++++++++++
 vl.c                       |  2 ++
 6 files changed, 25 insertions(+)

diff --git a/hw/acpi/core.c b/hw/acpi/core.c
index 79414b4..1f459fc 100644
--- a/hw/acpi/core.c
+++ b/hw/acpi/core.c
@@ -27,6 +27,7 @@
 #include "qapi/opts-visitor.h"
 #include "qapi/dealloc-visitor.h"
 #include "qapi-visit.h"
+#include "qemu-options.h"
 
 struct acpi_table_header {
     uint16_t _length;         /* our length, not actual part of the hdr */
@@ -64,6 +65,7 @@ static QemuOptsList qemu_acpi_opts = {
 static void acpi_register_config(void)
 {
     qemu_add_opts(&qemu_acpi_opts);
+    qemu_set_opt_index(qemu_acpi_opts.name, QEMU_OPTION_acpitable, NULL);
 }
 
 machine_init(acpi_register_config);
diff --git a/include/qapi/qmp/qerror.h b/include/qapi/qmp/qerror.h
index da75abf..cfbd29d 100644
--- a/include/qapi/qmp/qerror.h
+++ b/include/qapi/qmp/qerror.h
@@ -134,6 +134,9 @@ void qerror_report_err(Error *err);
 #define QERR_INVALID_OPTION_GROUP \
     ERROR_CLASS_GENERIC_ERROR, "There is no option group '%s'"
 
+#define QERR_INVALID_OPTION_INDEX \
+    ERROR_CLASS_GENERIC_ERROR, "There is no option index '%d'"
+
 #define QERR_INVALID_PARAMETER \
     ERROR_CLASS_GENERIC_ERROR, "Invalid parameter '%s'"
 
diff --git a/include/qemu/config-file.h b/include/qemu/config-file.h
index dbd97c4..1884313 100644
--- a/include/qemu/config-file.h
+++ b/include/qemu/config-file.h
@@ -8,6 +8,7 @@
 
 QemuOptsList *qemu_find_opts(const char *group);
 QemuOptsList *qemu_find_opts_err(const char *group, Error **errp);
+void qemu_set_opt_index(const char *group, int index, Error **errp);
 void qemu_add_opts(QemuOptsList *list);
 void qemu_add_drive_opts(QemuOptsList *list);
 int qemu_set_option(const char *str);
diff --git a/include/qemu/option.h b/include/qemu/option.h
index 8c0ac34..0d63ec9 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -103,6 +103,7 @@ typedef struct QemuOptDesc {
 
 struct QemuOptsList {
     const char *name;
+    int alias_index;
     const char *implied_opt_name;
     bool merge_lists;  /* Merge multiple uses of option into a single list? */
     QTAILQ_HEAD(, QemuOpts) head;
diff --git a/util/qemu-config.c b/util/qemu-config.c
index 508adbc..877d0e9 100644
--- a/util/qemu-config.c
+++ b/util/qemu-config.c
@@ -184,6 +184,21 @@ void qemu_add_drive_opts(QemuOptsList *list)
     abort();
 }
 
+void qemu_set_opt_index(const char *group, int index, Error **errp)
+{
+    int i;
+
+    for (i = 0; vm_config_groups[i] != NULL; i++) {
+        if (strcmp(vm_config_groups[i]->name, group) == 0) {
+            vm_config_groups[i]->alias_index = index;
+            break;
+        }
+    }
+    if (vm_config_groups[i] == NULL) {
+        error_set(errp, QERR_INVALID_OPTION_GROUP, group);
+    }
+}
+
 void qemu_add_opts(QemuOptsList *list)
 {
     int entries, i;
@@ -193,6 +208,7 @@ void qemu_add_opts(QemuOptsList *list)
     for (i = 0; i < entries; i++) {
         if (vm_config_groups[i] == NULL) {
             vm_config_groups[i] = list;
+            list->alias_index = -1;
             return;
         }
     }
diff --git a/vl.c b/vl.c
index 2355227..6457d6d 100644
--- a/vl.c
+++ b/vl.c
@@ -2988,7 +2988,9 @@ int main(int argc, char **argv, char **envp)
     qemu_add_opts(&qemu_option_rom_opts);
     qemu_add_opts(&qemu_machine_opts);
     qemu_add_opts(&qemu_smp_opts);
+    qemu_set_opt_index(qemu_smp_opts.name, QEMU_OPTION_smp, NULL);
     qemu_add_opts(&qemu_boot_opts);
+    qemu_set_opt_index(qemu_boot_opts.name, QEMU_OPTION_boot, NULL);
     qemu_add_opts(&qemu_sandbox_opts);
     qemu_add_opts(&qemu_add_fd_opts);
     qemu_add_opts(&qemu_object_opts);
-- 
1.8.5.3

>From 5d0308014bbee9b5753a8f432b3a751033b98458 Mon Sep 17 00:00:00 2001
From: Amos Kong <akong@xxxxxxxxxx>
Date: Tue, 28 Jan 2014 11:17:09 +0800
Subject: [PATCH RFC 2/2] query-command-line-options: query all the options in
 qemu-options.hx

vm_config_groups[] only contains part of the options which have
parameters, and all options which have no parameter aren't added
to vm_config_groups[]. Current query-command-line-options only
checks options from vm_config_groups[], so some options will
be lost.

We have macro in qemu-options.hx to generate a table that
contains all the options. This patch tries to query options
from the table.

Then we won't lose the legacy options that weren't added to
vm_config_groups[] (eg: -vnc, -smbios). The options that have
no parameter will also be returned (eg: -enable-fips)

Some options that have parameters have a NULL desc list, some
options don't have parameters, and "parameters" is mandatory
in the past. So we add a new field "unspecified-parameters" to
present if the option takes unspecified parameters.

Some group names('smp-opts', 'boot-opts', 'acpi') of option
tables don't match their actual command-line spelling, we will
try to find the QemuOptsList by index.

Signed-off-by: Amos Kong <akong@xxxxxxxxxx>
---
 qapi-schema.json   | 10 ++++++++--
 qemu-options.h     | 12 ++++++++++++
 util/qemu-config.c | 49 +++++++++++++++++++++++++++++++++++++++++++------
 vl.c               | 19 ++-----------------
 4 files changed, 65 insertions(+), 25 deletions(-)

diff --git a/qapi-schema.json b/qapi-schema.json
index 391356f..20fe4f5 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4102,12 +4102,18 @@
 #
 # @option: option name
 #
-# @parameters: an array of @CommandLineParameterInfo
+# @parameters: array of @CommandLineParameterInfo, possibly empty
+#
+# @unspecified-parameters: @optional present if the @parameters array is empty.
+#                          If true, then the option takes unspecified
+#                          parameters, if false, then the option takes no
+#                          parameter (since 2.1)
 #
 # Since 1.5
 ##
 { 'type': 'CommandLineOptionInfo',
-  'data': { 'option': 'str', 'parameters': ['CommandLineParameterInfo'] } }
+  'data': { 'option': 'str', 'parameters': ['CommandLineParameterInfo'],
+            '*unspecified-parameters': 'bool' } }
 
 ##
 # @query-command-line-options:
diff --git a/qemu-options.h b/qemu-options.h
index 89a009e..4024487 100644
--- a/qemu-options.h
+++ b/qemu-options.h
@@ -28,9 +28,21 @@
 #ifndef _QEMU_OPTIONS_H_
 #define _QEMU_OPTIONS_H_
 
+#include "sysemu/arch_init.h"
+
 enum {
 #define QEMU_OPTIONS_GENERATE_ENUM
 #include "qemu-options-wrapper.h"
 };
 
+#define HAS_ARG 0x0001
+
+typedef struct QEMUOption {
+    const char *name;
+    int flags;
+    int index;
+    uint32_t arch_mask;
+} QEMUOption;
+
+extern const QEMUOption qemu_options[];
 #endif
diff --git a/util/qemu-config.c b/util/qemu-config.c
index 877d0e9..29a6419 100644
--- a/util/qemu-config.c
+++ b/util/qemu-config.c
@@ -6,6 +6,14 @@
 #include "hw/qdev.h"
 #include "qapi/error.h"
 #include "qmp-commands.h"
+#include "qemu-options.h"
+
+const QEMUOption qemu_options[] = {
+    { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
+#define QEMU_OPTIONS_GENERATE_OPTIONS
+#include "qemu-options-wrapper.h"
+    { NULL },
+};
 
 static QemuOptsList *vm_config_groups[32];
 static QemuOptsList *drive_config_groups[4];
@@ -25,6 +33,19 @@ static QemuOptsList *find_list(QemuOptsList **lists, const char *group,
     return lists[i];
 }
 
+static QemuOptsList *find_list_by_index(QemuOptsList **lists, int index)
+{
+    int i;
+
+    for (i = 0; lists[i] != NULL; i++) {
+        if (lists[i]->alias_index == index) {
+            break;
+        }
+    }
+
+    return lists[i];
+}
+
 QemuOptsList *qemu_find_opts(const char *group)
 {
     QemuOptsList *ret;
@@ -137,18 +158,32 @@ CommandLineOptionInfoList *qmp_query_command_line_options(bool has_option,
 {
     CommandLineOptionInfoList *conf_list = NULL, *entry;
     CommandLineOptionInfo *info;
+    QemuOptsList *list;
     int i;
 
-    for (i = 0; vm_config_groups[i] != NULL; i++) {
-        if (!has_option || !strcmp(option, vm_config_groups[i]->name)) {
+    for (i = 0; qemu_options[i].name; i++) {
+        if (!has_option || !strcmp(option, qemu_options[i].name)) {
             info = g_malloc0(sizeof(*info));
-            info->option = g_strdup(vm_config_groups[i]->name);
-            if (!strcmp("drive", vm_config_groups[i]->name)) {
+            info->option = g_strdup(qemu_options[i].name);
+
+            if (!strcmp("drive", qemu_options[i].name)) {
                 info->parameters = get_drive_infolist();
             } else {
-                info->parameters =
-                    get_param_info(vm_config_groups[i]->desc);
+                list = find_list_by_index(vm_config_groups,
+                                          qemu_options[i].index);
+                if (list == NULL) {
+                    list = find_list(vm_config_groups,
+                                     qemu_options[i].name,
+                                     NULL);
+                }
+                info->parameters = list ? get_param_info(list->desc) : NULL;
+            }
+
+            if (!info->parameters) {
+                info->has_unspecified_parameters = true;
+                info->unspecified_parameters = qemu_options[i].flags & HAS_ARG;
             }
+
             entry = g_malloc0(sizeof(*entry));
             entry->value = info;
             entry->next = conf_list;
@@ -163,6 +198,8 @@ CommandLineOptionInfoList *qmp_query_command_line_options(bool has_option,
     return conf_list;
 }
 
+#undef HAS_ARG
+
 QemuOptsList *qemu_find_opts_err(const char *group, Error **errp)
 {
     return find_list(vm_config_groups, group, errp);
diff --git a/vl.c b/vl.c
index 6457d6d..9fdba9e 100644
--- a/vl.c
+++ b/vl.c
@@ -111,7 +111,6 @@ int main(int argc, char **argv)
 #include "trace/control.h"
 #include "qemu/queue.h"
 #include "sysemu/cpus.h"
-#include "sysemu/arch_init.h"
 #include "qemu/osdep.h"
 
 #include "ui/qemu-spice.h"
@@ -2080,22 +2079,6 @@ static void help(int exitcode)
     exit(exitcode);
 }
 
-#define HAS_ARG 0x0001
-
-typedef struct QEMUOption {
-    const char *name;
-    int flags;
-    int index;
-    uint32_t arch_mask;
-} QEMUOption;
-
-static const QEMUOption qemu_options[] = {
-    { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
-#define QEMU_OPTIONS_GENERATE_OPTIONS
-#include "qemu-options-wrapper.h"
-    { NULL },
-};
-
 static bool vga_available(void)
 {
     return object_class_by_name("VGA") || object_class_by_name("isa-vga");
@@ -2840,6 +2823,8 @@ static const QEMUOption *lookup_opt(int argc, char **argv,
     return popt;
 }
 
+#undef HAS_ARG
+
 static gpointer malloc_and_trace(gsize n_bytes)
 {
     void *ptr = malloc(n_bytes);
-- 
1.8.5.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]