소스 검색

qemu-option: Move the implied first name into QemuOptsList

We sometimes permit omitting the first option name, for example
-device foo is short for -device driver=foo.  The name to use
("driver" in the example) is passed as argument to qemu_opts_parse().
For each QemuOptsList, we use at most one such name.

Move the name into QemuOptsList, and pass whether to permit the
abbreviation.  This ensures continued consistency, and simplifies the
commit after next in this series.
Markus Armbruster 15 년 전
부모
커밋
8212c64f0e
8개의 변경된 파일24개의 추가작업 그리고 13개의 파일을 삭제
  1. 1 1
      hw/pci-hotplug.c
  2. 1 1
      hw/qdev.c
  3. 1 1
      hw/usb-net.c
  4. 2 2
      net.c
  5. 5 0
      qemu-config.c
  6. 6 1
      qemu-option.c
  7. 2 1
      qemu-option.h
  8. 6 6
      vl.c

+ 1 - 1
hw/pci-hotplug.c

@@ -54,7 +54,7 @@ static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon,
         return NULL;
         return NULL;
     }
     }
 
 
-    opts = qemu_opts_parse(&qemu_net_opts, opts_str ? opts_str : "", NULL);
+    opts = qemu_opts_parse(&qemu_net_opts, opts_str ? opts_str : "", 0);
     if (!opts) {
     if (!opts) {
         monitor_printf(mon, "parsing network options '%s' failed\n",
         monitor_printf(mon, "parsing network options '%s' failed\n",
                        opts_str ? opts_str : "");
                        opts_str ? opts_str : "");

+ 1 - 1
hw/qdev.c

@@ -767,7 +767,7 @@ void do_device_add(Monitor *mon, const QDict *qdict)
     QemuOpts *opts;
     QemuOpts *opts;
 
 
     opts = qemu_opts_parse(&qemu_device_opts,
     opts = qemu_opts_parse(&qemu_device_opts,
-                           qdict_get_str(qdict, "config"), "driver");
+                           qdict_get_str(qdict, "config"), 1);
     if (opts) {
     if (opts) {
         if (qdev_device_help(opts) || qdev_device_add(opts) == NULL) {
         if (qdev_device_help(opts) || qdev_device_add(opts) == NULL) {
             qemu_opts_del(opts);
             qemu_opts_del(opts);

+ 1 - 1
hw/usb-net.c

@@ -1478,7 +1478,7 @@ static USBDevice *usb_net_init(const char *cmdline)
     QemuOpts *opts;
     QemuOpts *opts;
     int idx;
     int idx;
 
 
-    opts = qemu_opts_parse(&qemu_net_opts, cmdline, NULL);
+    opts = qemu_opts_parse(&qemu_net_opts, cmdline, 0);
     if (!opts) {
     if (!opts) {
         return NULL;
         return NULL;
     }
     }

+ 2 - 2
net.c

@@ -1159,7 +1159,7 @@ void net_host_device_add(Monitor *mon, const QDict *qdict)
         return;
         return;
     }
     }
 
 
-    opts = qemu_opts_parse(&qemu_net_opts, opts_str ? opts_str : "", NULL);
+    opts = qemu_opts_parse(&qemu_net_opts, opts_str ? opts_str : "", 0);
     if (!opts) {
     if (!opts) {
         monitor_printf(mon, "parsing network options '%s' failed\n",
         monitor_printf(mon, "parsing network options '%s' failed\n",
                        opts_str ? opts_str : "");
                        opts_str ? opts_str : "");
@@ -1364,7 +1364,7 @@ int net_client_parse(QemuOptsList *opts_list, const char *optarg)
     }
     }
 #endif
 #endif
 
 
-    if (!qemu_opts_parse(opts_list, optarg, "type")) {
+    if (!qemu_opts_parse(opts_list, optarg, 1)) {
         return -1;
         return -1;
     }
     }
 
 

+ 5 - 0
qemu-config.c

@@ -86,6 +86,7 @@ QemuOptsList qemu_drive_opts = {
 
 
 QemuOptsList qemu_chardev_opts = {
 QemuOptsList qemu_chardev_opts = {
     .name = "chardev",
     .name = "chardev",
+    .implied_opt_name = "backend",
     .head = QTAILQ_HEAD_INITIALIZER(qemu_chardev_opts.head),
     .head = QTAILQ_HEAD_INITIALIZER(qemu_chardev_opts.head),
     .desc = {
     .desc = {
         {
         {
@@ -152,6 +153,7 @@ QemuOptsList qemu_chardev_opts = {
 
 
 QemuOptsList qemu_device_opts = {
 QemuOptsList qemu_device_opts = {
     .name = "device",
     .name = "device",
+    .implied_opt_name = "driver",
     .head = QTAILQ_HEAD_INITIALIZER(qemu_device_opts.head),
     .head = QTAILQ_HEAD_INITIALIZER(qemu_device_opts.head),
     .desc = {
     .desc = {
         /*
         /*
@@ -165,6 +167,7 @@ QemuOptsList qemu_device_opts = {
 
 
 QemuOptsList qemu_netdev_opts = {
 QemuOptsList qemu_netdev_opts = {
     .name = "netdev",
     .name = "netdev",
+    .implied_opt_name = "type",
     .head = QTAILQ_HEAD_INITIALIZER(qemu_netdev_opts.head),
     .head = QTAILQ_HEAD_INITIALIZER(qemu_netdev_opts.head),
     .desc = {
     .desc = {
         /*
         /*
@@ -177,6 +180,7 @@ QemuOptsList qemu_netdev_opts = {
 
 
 QemuOptsList qemu_net_opts = {
 QemuOptsList qemu_net_opts = {
     .name = "net",
     .name = "net",
+    .implied_opt_name = "type",
     .head = QTAILQ_HEAD_INITIALIZER(qemu_net_opts.head),
     .head = QTAILQ_HEAD_INITIALIZER(qemu_net_opts.head),
     .desc = {
     .desc = {
         /*
         /*
@@ -227,6 +231,7 @@ QemuOptsList qemu_global_opts = {
 
 
 QemuOptsList qemu_mon_opts = {
 QemuOptsList qemu_mon_opts = {
     .name = "mon",
     .name = "mon",
+    .implied_opt_name = "chardev",
     .head = QTAILQ_HEAD_INITIALIZER(qemu_mon_opts.head),
     .head = QTAILQ_HEAD_INITIALIZER(qemu_mon_opts.head),
     .desc = {
     .desc = {
         {
         {

+ 6 - 1
qemu-option.c

@@ -753,12 +753,17 @@ int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname
     return 0;
     return 0;
 }
 }
 
 
-QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, const char *firstname)
+QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params,
+                          int permit_abbrev)
 {
 {
+    const char *firstname;
     char value[1024], *id = NULL;
     char value[1024], *id = NULL;
     const char *p;
     const char *p;
     QemuOpts *opts;
     QemuOpts *opts;
 
 
+    assert(!permit_abbrev || list->implied_opt_name);
+    firstname = permit_abbrev ? list->implied_opt_name : NULL;
+
     if (strncmp(params, "id=", 3) == 0) {
     if (strncmp(params, "id=", 3) == 0) {
         get_opt_value(value, sizeof(value), params+3);
         get_opt_value(value, sizeof(value), params+3);
         id = qemu_strdup(value);
         id = qemu_strdup(value);

+ 2 - 1
qemu-option.h

@@ -97,6 +97,7 @@ typedef struct QemuOptDesc {
 
 
 struct QemuOptsList {
 struct QemuOptsList {
     const char *name;
     const char *name;
+    const char *implied_opt_name;
     QTAILQ_HEAD(, QemuOpts) head;
     QTAILQ_HEAD(, QemuOpts) head;
     QemuOptDesc desc[];
     QemuOptDesc desc[];
 };
 };
@@ -118,7 +119,7 @@ const char *qemu_opts_id(QemuOpts *opts);
 void qemu_opts_del(QemuOpts *opts);
 void qemu_opts_del(QemuOpts *opts);
 int qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc);
 int qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc);
 int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname);
 int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname);
-QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, const char *firstname);
+QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, int permit_abbrev);
 QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict);
 QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict);
 QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict);
 QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict);
 
 

+ 6 - 6
vl.c

@@ -1813,7 +1813,7 @@ QemuOpts *drive_add(const char *file, const char *fmt, ...)
     vsnprintf(optstr, sizeof(optstr), fmt, ap);
     vsnprintf(optstr, sizeof(optstr), fmt, ap);
     va_end(ap);
     va_end(ap);
 
 
-    opts = qemu_opts_parse(&qemu_drive_opts, optstr, NULL);
+    opts = qemu_opts_parse(&qemu_drive_opts, optstr, 0);
     if (!opts) {
     if (!opts) {
         fprintf(stderr, "%s: huh? duplicate? (%s)\n",
         fprintf(stderr, "%s: huh? duplicate? (%s)\n",
                 __FUNCTION__, optstr);
                 __FUNCTION__, optstr);
@@ -4370,7 +4370,7 @@ static int balloon_parse(const char *arg)
     if (!strncmp(arg, "virtio", 6)) {
     if (!strncmp(arg, "virtio", 6)) {
         if (arg[6] == ',') {
         if (arg[6] == ',') {
             /* have params -> parse them */
             /* have params -> parse them */
-            opts = qemu_opts_parse(&qemu_device_opts, arg+7, NULL);
+            opts = qemu_opts_parse(&qemu_device_opts, arg+7, 0);
             if (!opts)
             if (!opts)
                 return  -1;
                 return  -1;
         } else {
         } else {
@@ -5365,7 +5365,7 @@ int main(int argc, char **argv, char **envp)
                 default_monitor = 0;
                 default_monitor = 0;
                 break;
                 break;
             case QEMU_OPTION_mon:
             case QEMU_OPTION_mon:
-                opts = qemu_opts_parse(&qemu_mon_opts, optarg, "chardev");
+                opts = qemu_opts_parse(&qemu_mon_opts, optarg, 1);
                 if (!opts) {
                 if (!opts) {
                     fprintf(stderr, "parse error: %s\n", optarg);
                     fprintf(stderr, "parse error: %s\n", optarg);
                     exit(1);
                     exit(1);
@@ -5373,7 +5373,7 @@ int main(int argc, char **argv, char **envp)
                 default_monitor = 0;
                 default_monitor = 0;
                 break;
                 break;
             case QEMU_OPTION_chardev:
             case QEMU_OPTION_chardev:
-                opts = qemu_opts_parse(&qemu_chardev_opts, optarg, "backend");
+                opts = qemu_opts_parse(&qemu_chardev_opts, optarg, 1);
                 if (!opts) {
                 if (!opts) {
                     fprintf(stderr, "parse error: %s\n", optarg);
                     fprintf(stderr, "parse error: %s\n", optarg);
                     exit(1);
                     exit(1);
@@ -5467,7 +5467,7 @@ int main(int argc, char **argv, char **envp)
                 add_device_config(DEV_USB, optarg);
                 add_device_config(DEV_USB, optarg);
                 break;
                 break;
             case QEMU_OPTION_device:
             case QEMU_OPTION_device:
-                if (!qemu_opts_parse(&qemu_device_opts, optarg, "driver")) {
+                if (!qemu_opts_parse(&qemu_device_opts, optarg, 1)) {
                     exit(1);
                     exit(1);
                 }
                 }
                 break;
                 break;
@@ -5576,7 +5576,7 @@ int main(int argc, char **argv, char **envp)
                 configure_rtc_date_offset(optarg, 1);
                 configure_rtc_date_offset(optarg, 1);
                 break;
                 break;
             case QEMU_OPTION_rtc:
             case QEMU_OPTION_rtc:
-                opts = qemu_opts_parse(&qemu_rtc_opts, optarg, NULL);
+                opts = qemu_opts_parse(&qemu_rtc_opts, optarg, 0);
                 if (!opts) {
                 if (!opts) {
                     fprintf(stderr, "parse error: %s\n", optarg);
                     fprintf(stderr, "parse error: %s\n", optarg);
                     exit(1);
                     exit(1);