Skip to contentSkip to conversation

: rename machine options to use dashes

PATCH Superseded Luiz Capitulino 2 participants 10 messages Jul 10, 2012 – Jul 11, 2012

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover : rename machine options to use dashes

Today, machine options use underscores to separate words (eg. kernel_irqchip), however upcoming QOM conversion wants to use dashes instead.

This series converts all machine type options to use dashes. Command-line backwards compatibility is maintained by adding an alias for each changed option.

 device_tree.c          |  2 +-
 hw/ppce500_mpc8544ds.c |  2 +-
 kvm-all.c              |  2 +-
 qemu-config.c          | 12 ++++++++----
 qemu-option.c          |  9 ++++++++-
 qemu-option.h          |  1 +
 qemu-options.hx        |  8 ++++----
 target-i386/kvm.c      |  2 +-
 8 files changed, 25 insertions(+), 13 deletions(-)
#1 lore raw

PATCH 1/5 qemu-option: add alias support

It allows for specifying an alias for each option name, see next commits examples.

---
 qemu-option.c | 9 ++++++++-
 qemu-option.h | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)
qemu-option.c +8 -1
index bb3886c..59a1f6e 100644
@@ -616,6 +616,7 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value,
                     bool prepend, Error **errp)
 {
     QemuOpt *opt;
+    const char *optname;
     const QemuOptDesc *desc = opts->list->desc;
     Error *local_err = NULL;
     int i;
@@ -624,18 +625,24 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value,
         if (strcmp(desc[i].name, name) == 0) {
             break;
         }
+        if (desc[i].alias && strcmp(desc[i].alias, name) == 0) {
+            break;
+        }
     }
     if (desc[i].name == NULL) {
         if (i == 0) {
             /* empty list -> allow any */;
+            optname = name;
         } else {
             error_set(errp, QERR_INVALID_PARAMETER, name);
             return;
         }
+    } else {
+        optname = desc[i].name;
     }
 
     opt = g_malloc0(sizeof(*opt));
-    opt->name = g_strdup(name);
+    opt->name = g_strdup(optname);
     opt->opts = opts;
     if (prepend) {
         QTAILQ_INSERT_HEAD(&opts->head, opt, next);
qemu-option.h +1 -0
index 951dec3..7106d2f 100644
@@ -94,6 +94,7 @@ enum QemuOptType {
 
 typedef struct QemuOptDesc {
     const char *name;
+    const char *alias;
     enum QemuOptType type;
     const char *help;
 } QemuOptDesc;
Signature · 1 line
1.7.11.1.116.g8228a23
#2 lore raw

Re: [Qemu-devel] [PATCH 1/5] qemu-option: add alias support

Quoted 37 lines · Luiz Capitulino

It allows for specifying an alias for each option name, see next commits examples.

---
 qemu-option.c | 9 ++++++++-
 qemu-option.h | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)
qemu-option.c +5 -0
index bb3886c..59a1f6e 100644
@@ -616,6 +616,7 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value,
                     bool prepend, Error **errp)
 {
     QemuOpt *opt;
+    const char *optname;
     const QemuOptDesc *desc = opts->list->desc;
     Error *local_err = NULL;
     int i;
@@ -624,18 +625,24 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value,
         if (strcmp(desc[i].name, name) == 0) {
             break;
         }
+        if (desc[i].alias && strcmp(desc[i].alias, name) == 0) {
+            break;
+        }
     }
     if (desc[i].name == NULL) {
         if (i == 0) {
             /* empty list -> allow any */;
+            optname = name;
         } else {
             error_set(errp, QERR_INVALID_PARAMETER, name);
             return;
         }

qemu-option.c static void opt_set(QemuOpts *opts, const char *name, const char *value, · line 648

Quoted 10 lines
qemu-option.c +3 -1
+    } else {
+        optname = desc[i].name;
     }
 
     opt = g_malloc0(sizeof(*opt));
-    opt->name = g_strdup(name);
+    opt->name = g_strdup(optname);
     opt->opts = opts;
     if (prepend) {
         QTAILQ_INSERT_HEAD(&opts->head, opt, next);

What about qemu_opt_set_bool() and qemu_opts_validate()? Don't they need alias support as well?

By the way, I really dislike qemu_opt_set_bool() duplicating qemu_opt_set(). Shame on commit f02b77c9.

Quoted 12 lines
qemu-option.h +1 -0
index 951dec3..7106d2f 100644
@@ -94,6 +94,7 @@ enum QemuOptType {
 
 typedef struct QemuOptDesc {
     const char *name;
+    const char *alias;
     enum QemuOptType type;
     const char *help;
 } QemuOptDesc;
#3 lore raw

Re: [Qemu-devel] [PATCH 1/5] qemu-option: add alias support

Quoted 43 lines · On Wed, 11 Jul 2012 09:00:59 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 41 lines · Luiz Capitulino

It allows for specifying an alias for each option name, see next commits examples.

---
 qemu-option.c | 9 ++++++++-
 qemu-option.h | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)
qemu-option.c +7 -0
index bb3886c..59a1f6e 100644
@@ -616,6 +616,7 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value,
                     bool prepend, Error **errp)
 {
     QemuOpt *opt;
+    const char *optname;
     const QemuOptDesc *desc = opts->list->desc;
     Error *local_err = NULL;
     int i;
@@ -624,18 +625,24 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value,
         if (strcmp(desc[i].name, name) == 0) {
             break;
         }
+        if (desc[i].alias && strcmp(desc[i].alias, name) == 0) {
+            break;
+        }
     }
     if (desc[i].name == NULL) {
         if (i == 0) {
             /* empty list -> allow any */;
+            optname = name;
         } else {
             error_set(errp, QERR_INVALID_PARAMETER, name);
             return;
         }
+    } else {
+        optname = desc[i].name;
     }
 
Quoted 9 lines

qemu-option.c static void opt_set(QemuOpts *opts, const char *name, const char *value, · line 648

Quoted 6 lines
qemu-option.c +1 -1
     opt = g_malloc0(sizeof(*opt));
-    opt->name = g_strdup(name);
+    opt->name = g_strdup(optname);
     opt->opts = opts;
     if (prepend) {
         QTAILQ_INSERT_HEAD(&opts->head, opt, next);

What about qemu_opt_set_bool() and qemu_opts_validate()? Don't they need alias support as well?

Oh, you're right, thanks for catching this.

Quoted 2 lines

By the way, I really dislike qemu_opt_set_bool() duplicating qemu_opt_set(). Shame on commit f02b77c9.

Yeah, I'll fix the duplication.

Quoted 14 lines
Quoted 13 lines
qemu-option.h +1 -0
index 951dec3..7106d2f 100644
@@ -94,6 +94,7 @@ enum QemuOptType {
 
 typedef struct QemuOptDesc {
     const char *name;
+    const char *alias;
     enum QemuOptType type;
     const char *help;
 } QemuOptDesc;
#4 lore raw

PATCH 2/5 machine: rename kernel_irqchip to kernel-irqchip

In reply to Luiz Capitulino

QOM conversion wants option names with dashes (instead of underscores), this commit does the change for the kernel_irqchip machine option.

The underscore is still supported through an option alias for backwards compatibility.

---
 kvm-all.c       | 2 +-
 qemu-config.c   | 3 ++-
 qemu-options.hx | 4 ++--
 3 files changed, 5 insertions(+), 4 deletions(-)
kvm-all.c +1 -1
index f8e4328..c988bb6 100644
@@ -1168,7 +1168,7 @@ static int kvm_irqchip_create(KVMState *s)
 
     if (QTAILQ_EMPTY(&list->head) ||
         !qemu_opt_get_bool(QTAILQ_FIRST(&list->head),
-                           "kernel_irqchip", true) ||
+                           "kernel-irqchip", true) ||
         !kvm_check_extension(s, KVM_CAP_IRQCHIP)) {
         return 0;
     }
qemu-config.c +2 -1
index 5c3296b..3fe91a8 100644
@@ -560,7 +560,8 @@ static QemuOptsList qemu_machine_opts = {
             .type = QEMU_OPT_STRING,
             .help = "accelerator list",
         }, {
-            .name = "kernel_irqchip",
+            .name = "kernel-irqchip",
+            .alias= "kernel_irqchip",
             .type = QEMU_OPT_BOOL,
             .help = "use KVM in-kernel irqchip",
         }, {
qemu-options.hx +2 -2
index ecf7ca1..b149852 100644
@@ -32,7 +32,7 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \
     "                selects emulated machine (-machine ? for list)\n"
     "                property accel=accel1[:accel2[:...]] selects accelerator\n"
     "                supported accelerators are kvm, xen, tcg (default: tcg)\n"
-    "                kernel_irqchip=on|off controls accelerated irqchip support\n"
+    "                kernel-irqchip=on|off controls accelerated irqchip support\n"
     "                kvm_shadow_mem=size of KVM shadow MMU\n",
     QEMU_ARCH_ALL)
 STEXI
@@ -46,7 +46,7 @@ This is used to enable an accelerator. Depending on the target architecture,
 kvm, xen, or tcg can be available. By default, tcg is used. If there is more
 than one accelerator specified, the next one is used if the previous one fails
 to initialize.
-@item kernel_irqchip=on|off
+@item kernel-irqchip=on|off
 Enables in-kernel irqchip support for the chosen accelerator when available.
 @item kvm_shadow_mem=size
 Defines the size of the KVM shadow MMU.
Signature · 1 line
1.7.11.1.116.g8228a23
#5 lore raw

PATCH 3/5 machine: rename kvm_shadow_mem to kvm-shadow-mem

In reply to Luiz Capitulino

QOM conversion wants option names with dashes (instead of underscores), this commit does the change for the kvm_shadow_mem machine option.

The underscore is still supported through an option alias for backwards compatibility.

---
 qemu-config.c     | 3 ++-
 qemu-options.hx   | 4 ++--
 target-i386/kvm.c | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)
qemu-config.c +2 -1
index 3fe91a8..909fae9 100644
@@ -565,7 +565,8 @@ static QemuOptsList qemu_machine_opts = {
             .type = QEMU_OPT_BOOL,
             .help = "use KVM in-kernel irqchip",
         }, {
-            .name = "kvm_shadow_mem",
+            .name = "kvm-shadow-mem",
+            .alias= "kvm_shadow_mem",
             .type = QEMU_OPT_SIZE,
             .help = "KVM shadow MMU size",
         }, {
qemu-options.hx +2 -2
index b149852..b95438f 100644
@@ -33,7 +33,7 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \
     "                property accel=accel1[:accel2[:...]] selects accelerator\n"
     "                supported accelerators are kvm, xen, tcg (default: tcg)\n"
     "                kernel-irqchip=on|off controls accelerated irqchip support\n"
-    "                kvm_shadow_mem=size of KVM shadow MMU\n",
+    "                kvm-shadow-mem=size of KVM shadow MMU\n",
     QEMU_ARCH_ALL)
 STEXI
 @item -machine [type=]@var{name}[,prop=@var{value}[,...]]
@@ -48,7 +48,7 @@ than one accelerator specified, the next one is used if the previous one fails
 to initialize.
 @item kernel-irqchip=on|off
 Enables in-kernel irqchip support for the chosen accelerator when available.
-@item kvm_shadow_mem=size
+@item kvm-shadow-mem=size
 Defines the size of the KVM shadow MMU.
 @end table
 ETEXI
target-i386/kvm.c +1 -1
index 0d0d8f6..90bf4d4 100644
@@ -698,7 +698,7 @@ int kvm_arch_init(KVMState *s)
 
     if (!QTAILQ_EMPTY(&list->head)) {
         shadow_mem = qemu_opt_get_size(QTAILQ_FIRST(&list->head),
-                                       "kvm_shadow_mem", -1);
+                                       "kvm-shadow-mem", -1);
         if (shadow_mem != -1) {
             shadow_mem /= 4096;
             ret = kvm_vm_ioctl(s, KVM_SET_NR_MMU_PAGES, shadow_mem);
Signature · 1 line
1.7.11.1.116.g8228a23
#6 lore raw

PATCH 4/5 machine: rename phandle_start to phandle-start

In reply to Luiz Capitulino

QOM conversion wants option names with dashes (instead of underscores), this commit does the change for the phandle_start machine option.

The underscore is still supported through an option alias for backwards compatibility.

---
 device_tree.c | 2 +-
 qemu-config.c | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
device_tree.c +1 -1
index b366fdd..fe59768 100644
@@ -213,7 +213,7 @@ uint32_t qemu_devtree_alloc_phandle(void *fdt)
         machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
         if (machine_opts) {
             const char *phandle_start;
-            phandle_start = qemu_opt_get(machine_opts, "phandle_start");
+            phandle_start = qemu_opt_get(machine_opts, "phandle-start");
             if (phandle_start) {
                 phandle = strtoul(phandle_start, NULL, 0);
             }
qemu-config.c +2 -1
index 909fae9..d888b5b 100644
@@ -590,7 +590,8 @@ static QemuOptsList qemu_machine_opts = {
             .type = QEMU_OPT_STRING,
             .help = "Dump current dtb to a file and quit",
         }, {
-            .name = "phandle_start",
+            .name = "phandle-start",
+            .alias= "phandle_start",
             .type = QEMU_OPT_STRING,
             .help = "The first phandle ID we may generate dynamically",
         }, {
Signature · 1 line
1.7.11.1.116.g8228a23
#7 lore raw

PATCH 5/5 machine: rename dt_compatible to dt-compatible

In reply to Luiz Capitulino

QOM conversion wants option names with dashes (instead of underscores), this commit does the change for the dt_compatible machine option.

The underscore is still supported through an option alias for backwards compatibility.

---
 hw/ppce500_mpc8544ds.c | 2 +-
 qemu-config.c          | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
hw/ppce500_mpc8544ds.c +1 -1
index 8b9fd83..7b98011 100644
@@ -148,7 +148,7 @@ static int mpc8544_load_device_tree(CPUPPCState *env,
         const char *tmp;
         dumpdtb = qemu_opt_get(machine_opts, "dumpdtb");
         dtb_file = qemu_opt_get(machine_opts, "dtb");
-        tmp = qemu_opt_get(machine_opts, "dt_compatible");
+        tmp = qemu_opt_get(machine_opts, "dt-compatible");
         if (tmp) {
             compatible = tmp;
             compatible_len = strlen(compatible) + 1;
qemu-config.c +2 -1
index d888b5b..9dac3be 100644
@@ -595,7 +595,8 @@ static QemuOptsList qemu_machine_opts = {
             .type = QEMU_OPT_STRING,
             .help = "The first phandle ID we may generate dynamically",
         }, {
-            .name = "dt_compatible",
+            .name = "dt-compatible",
+            .alias= "dt_compatible",
             .type = QEMU_OPT_STRING,
             .help = "Overrides the \"compatible\" property of the dt root node",
         },
Signature · 1 line
1.7.11.1.116.g8228a23
#8 lore raw
In reply to Luiz Capitulino
Quoted 2 lines · Luiz Capitulino

Today, machine options use underscores to separate words (eg. kernel_irqchip), however upcoming QOM conversion wants to use dashes instead.

Command line users will appreciate consistent use of '-', too.

Quoted 3 lines

This series converts all machine type options to use dashes. Command-line backwards compatibility is maintained by adding an alias for each changed option.

Looks good except for PATCH 1/5.

Many -machine options are not documented in -help. Not your fault.

#9 lore raw

A quick git-grep for more instances of '_' in option parameter names finds only vcard_emul_options(). Yet another ad hoc option argument parser. I'm not asking you to do anything about it.