qemu-config.c 18.4 KB
Newer Older
G
Gerd Hoffmann 已提交
1
#include "qemu-common.h"
2
#include "qemu-error.h"
G
Gerd Hoffmann 已提交
3 4
#include "qemu-option.h"
#include "qemu-config.h"
5
#include "hw/qdev.h"
G
Gerd Hoffmann 已提交
6

7
static QemuOptsList qemu_drive_opts = {
G
Gerd Hoffmann 已提交
8
    .name = "drive",
B
Blue Swirl 已提交
9
    .head = QTAILQ_HEAD_INITIALIZER(qemu_drive_opts.head),
G
Gerd Hoffmann 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
    .desc = {
        {
            .name = "bus",
            .type = QEMU_OPT_NUMBER,
            .help = "bus number",
        },{
            .name = "unit",
            .type = QEMU_OPT_NUMBER,
            .help = "unit number (i.e. lun for scsi)",
        },{
            .name = "if",
            .type = QEMU_OPT_STRING,
            .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)",
        },{
            .name = "index",
            .type = QEMU_OPT_NUMBER,
26
            .help = "index number",
G
Gerd Hoffmann 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
        },{
            .name = "cyls",
            .type = QEMU_OPT_NUMBER,
            .help = "number of cylinders (ide disk geometry)",
        },{
            .name = "heads",
            .type = QEMU_OPT_NUMBER,
            .help = "number of heads (ide disk geometry)",
        },{
            .name = "secs",
            .type = QEMU_OPT_NUMBER,
            .help = "number of sectors (ide disk geometry)",
        },{
            .name = "trans",
            .type = QEMU_OPT_STRING,
            .help = "chs translation (auto, lba. none)",
        },{
            .name = "media",
            .type = QEMU_OPT_STRING,
            .help = "media type (disk, cdrom)",
        },{
            .name = "snapshot",
            .type = QEMU_OPT_BOOL,
50
            .help = "enable/disable snapshot mode",
G
Gerd Hoffmann 已提交
51 52 53 54 55 56 57
        },{
            .name = "file",
            .type = QEMU_OPT_STRING,
            .help = "disk image",
        },{
            .name = "cache",
            .type = QEMU_OPT_STRING,
58 59
            .help = "host cache usage (none, writeback, writethrough, "
                    "directsync, unsafe)",
60 61 62 63
        },{
            .name = "aio",
            .type = QEMU_OPT_STRING,
            .help = "host AIO implementation (threads, native)",
G
Gerd Hoffmann 已提交
64 65 66 67 68 69 70
        },{
            .name = "format",
            .type = QEMU_OPT_STRING,
            .help = "disk format (raw, qcow2, ...)",
        },{
            .name = "serial",
            .type = QEMU_OPT_STRING,
71
            .help = "disk serial number",
K
Kevin Wolf 已提交
72 73 74
        },{
            .name = "rerror",
            .type = QEMU_OPT_STRING,
75
            .help = "read error action",
G
Gerd Hoffmann 已提交
76 77 78
        },{
            .name = "werror",
            .type = QEMU_OPT_STRING,
79
            .help = "write error action",
G
Gerd Hoffmann 已提交
80 81 82 83
        },{
            .name = "addr",
            .type = QEMU_OPT_STRING,
            .help = "pci address (virtio only)",
84 85 86
        },{
            .name = "readonly",
            .type = QEMU_OPT_BOOL,
87
            .help = "open drive file as read-only",
G
Gerd Hoffmann 已提交
88
        },
89
        { /* end of list */ }
G
Gerd Hoffmann 已提交
90 91 92
    },
};

93
static QemuOptsList qemu_chardev_opts = {
94
    .name = "chardev",
95
    .implied_opt_name = "backend",
B
Blue Swirl 已提交
96
    .head = QTAILQ_HEAD_INITIALIZER(qemu_chardev_opts.head),
97
    .desc = {
98 99 100 101 102 103
        {
            .name = "backend",
            .type = QEMU_OPT_STRING,
        },{
            .name = "path",
            .type = QEMU_OPT_STRING,
104 105 106 107 108 109
        },{
            .name = "host",
            .type = QEMU_OPT_STRING,
        },{
            .name = "port",
            .type = QEMU_OPT_STRING,
G
Gerd Hoffmann 已提交
110 111 112 113 114 115
        },{
            .name = "localaddr",
            .type = QEMU_OPT_STRING,
        },{
            .name = "localport",
            .type = QEMU_OPT_STRING,
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
        },{
            .name = "to",
            .type = QEMU_OPT_NUMBER,
        },{
            .name = "ipv4",
            .type = QEMU_OPT_BOOL,
        },{
            .name = "ipv6",
            .type = QEMU_OPT_BOOL,
        },{
            .name = "wait",
            .type = QEMU_OPT_BOOL,
        },{
            .name = "server",
            .type = QEMU_OPT_BOOL,
        },{
            .name = "delay",
            .type = QEMU_OPT_BOOL,
        },{
            .name = "telnet",
            .type = QEMU_OPT_BOOL,
G
Gerd Hoffmann 已提交
137 138 139 140 141 142 143 144 145 146 147 148
        },{
            .name = "width",
            .type = QEMU_OPT_NUMBER,
        },{
            .name = "height",
            .type = QEMU_OPT_NUMBER,
        },{
            .name = "cols",
            .type = QEMU_OPT_NUMBER,
        },{
            .name = "rows",
            .type = QEMU_OPT_NUMBER,
G
Gerd Hoffmann 已提交
149 150 151
        },{
            .name = "mux",
            .type = QEMU_OPT_BOOL,
152 153 154
        },{
            .name = "signal",
            .type = QEMU_OPT_BOOL,
A
Alon Levy 已提交
155 156 157 158 159 160
        },{
            .name = "name",
            .type = QEMU_OPT_STRING,
        },{
            .name = "debug",
            .type = QEMU_OPT_NUMBER,
161
        },
162
        { /* end of list */ }
163 164 165
    },
};

166 167 168 169 170 171 172 173 174 175 176
QemuOptsList qemu_fsdev_opts = {
    .name = "fsdev",
    .implied_opt_name = "fstype",
    .head = QTAILQ_HEAD_INITIALIZER(qemu_fsdev_opts.head),
    .desc = {
        {
            .name = "fstype",
            .type = QEMU_OPT_STRING,
        }, {
            .name = "path",
            .type = QEMU_OPT_STRING,
177 178 179
        }, {
            .name = "security_model",
            .type = QEMU_OPT_STRING,
180 181 182 183 184
        },
        { /*End of list */ }
    },
};

185 186 187 188 189 190 191 192 193 194 195 196 197 198
QemuOptsList qemu_virtfs_opts = {
    .name = "virtfs",
    .implied_opt_name = "fstype",
    .head = QTAILQ_HEAD_INITIALIZER(qemu_virtfs_opts.head),
    .desc = {
        {
            .name = "fstype",
            .type = QEMU_OPT_STRING,
        }, {
            .name = "path",
            .type = QEMU_OPT_STRING,
        }, {
            .name = "mount_tag",
            .type = QEMU_OPT_STRING,
199 200 201
        }, {
            .name = "security_model",
            .type = QEMU_OPT_STRING,
202 203 204 205 206 207
        },

        { /*End of list */ }
    },
};

208
static QemuOptsList qemu_device_opts = {
G
Gerd Hoffmann 已提交
209
    .name = "device",
210
    .implied_opt_name = "driver",
B
Blue Swirl 已提交
211
    .head = QTAILQ_HEAD_INITIALIZER(qemu_device_opts.head),
G
Gerd Hoffmann 已提交
212 213 214 215 216 217
    .desc = {
        /*
         * no elements => accept any
         * sanity checking will happen later
         * when setting device properties
         */
218
        { /* end of list */ }
G
Gerd Hoffmann 已提交
219 220 221
    },
};

222
static QemuOptsList qemu_netdev_opts = {
M
Mark McLoughlin 已提交
223
    .name = "netdev",
224
    .implied_opt_name = "type",
M
Mark McLoughlin 已提交
225 226 227 228 229 230 231 232 233 234
    .head = QTAILQ_HEAD_INITIALIZER(qemu_netdev_opts.head),
    .desc = {
        /*
         * no elements => accept any params
         * validation will happen later
         */
        { /* end of list */ }
    },
};

235
static QemuOptsList qemu_net_opts = {
M
Mark McLoughlin 已提交
236
    .name = "net",
237
    .implied_opt_name = "type",
M
Mark McLoughlin 已提交
238 239 240 241 242 243 244 245 246 247
    .head = QTAILQ_HEAD_INITIALIZER(qemu_net_opts.head),
    .desc = {
        /*
         * no elements => accept any params
         * validation will happen later
         */
        { /* end of list */ }
    },
};

248
static QemuOptsList qemu_rtc_opts = {
J
Jan Kiszka 已提交
249 250 251 252 253 254
    .name = "rtc",
    .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head),
    .desc = {
        {
            .name = "base",
            .type = QEMU_OPT_STRING,
J
Jan Kiszka 已提交
255 256 257
        },{
            .name = "clock",
            .type = QEMU_OPT_STRING,
J
Jan Kiszka 已提交
258 259 260 261
        },{
            .name = "driftfix",
            .type = QEMU_OPT_STRING,
        },
262
        { /* end of list */ }
J
Jan Kiszka 已提交
263 264 265
    },
};

266
static QemuOptsList qemu_global_opts = {
267 268 269 270 271 272 273 274 275 276 277 278 279
    .name = "global",
    .head = QTAILQ_HEAD_INITIALIZER(qemu_global_opts.head),
    .desc = {
        {
            .name = "driver",
            .type = QEMU_OPT_STRING,
        },{
            .name = "property",
            .type = QEMU_OPT_STRING,
        },{
            .name = "value",
            .type = QEMU_OPT_STRING,
        },
280
        { /* end of list */ }
281 282 283
    },
};

284
static QemuOptsList qemu_mon_opts = {
285
    .name = "mon",
286
    .implied_opt_name = "chardev",
287 288 289 290 291 292 293 294 295 296 297
    .head = QTAILQ_HEAD_INITIALIZER(qemu_mon_opts.head),
    .desc = {
        {
            .name = "mode",
            .type = QEMU_OPT_STRING,
        },{
            .name = "chardev",
            .type = QEMU_OPT_STRING,
        },{
            .name = "default",
            .type = QEMU_OPT_BOOL,
298 299 300
        },{
            .name = "pretty",
            .type = QEMU_OPT_BOOL,
301
        },
302
        { /* end of list */ }
303 304 305
    },
};

306 307 308 309 310 311
static QemuOptsList qemu_trace_opts = {
    .name = "trace",
    .implied_opt_name = "trace",
    .head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head),
    .desc = {
        {
312 313 314
            .name = "events",
            .type = QEMU_OPT_STRING,
        },{
315 316 317
            .name = "file",
            .type = QEMU_OPT_STRING,
        },
G
Gerd Hoffmann 已提交
318
        { /* end of list */ }
319 320 321
    },
};

322
static QemuOptsList qemu_cpudef_opts = {
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
    .name = "cpudef",
    .head = QTAILQ_HEAD_INITIALIZER(qemu_cpudef_opts.head),
    .desc = {
        {
            .name = "name",
            .type = QEMU_OPT_STRING,
        },{
            .name = "level",
            .type = QEMU_OPT_NUMBER,
        },{
            .name = "vendor",
            .type = QEMU_OPT_STRING,
        },{
            .name = "family",
            .type = QEMU_OPT_NUMBER,
        },{
            .name = "model",
            .type = QEMU_OPT_NUMBER,
        },{
            .name = "stepping",
            .type = QEMU_OPT_NUMBER,
        },{
            .name = "feature_edx",      /* cpuid 0000_0001.edx */
            .type = QEMU_OPT_STRING,
        },{
            .name = "feature_ecx",      /* cpuid 0000_0001.ecx */
            .type = QEMU_OPT_STRING,
        },{
            .name = "extfeature_edx",   /* cpuid 8000_0001.edx */
            .type = QEMU_OPT_STRING,
        },{
            .name = "extfeature_ecx",   /* cpuid 8000_0001.ecx */
            .type = QEMU_OPT_STRING,
        },{
            .name = "xlevel",
            .type = QEMU_OPT_NUMBER,
        },{
            .name = "model_id",
            .type = QEMU_OPT_STRING,
        },{
            .name = "vendor_override",
            .type = QEMU_OPT_NUMBER,
        },
        { /* end of list */ }
    },
};

G
Gerd Hoffmann 已提交
370 371 372 373 374 375 376
QemuOptsList qemu_spice_opts = {
    .name = "spice",
    .head = QTAILQ_HEAD_INITIALIZER(qemu_spice_opts.head),
    .desc = {
        {
            .name = "port",
            .type = QEMU_OPT_NUMBER,
G
Gerd Hoffmann 已提交
377 378 379
        },{
            .name = "tls-port",
            .type = QEMU_OPT_NUMBER,
380 381 382 383 384 385 386 387 388
        },{
            .name = "addr",
            .type = QEMU_OPT_STRING,
        },{
            .name = "ipv4",
            .type = QEMU_OPT_BOOL,
        },{
            .name = "ipv6",
            .type = QEMU_OPT_BOOL,
G
Gerd Hoffmann 已提交
389 390 391 392 393 394
        },{
            .name = "password",
            .type = QEMU_OPT_STRING,
        },{
            .name = "disable-ticketing",
            .type = QEMU_OPT_BOOL,
395 396 397
        },{
            .name = "disable-copy-paste",
            .type = QEMU_OPT_BOOL,
M
Marc-André Lureau 已提交
398 399 400
        },{
            .name = "sasl",
            .type = QEMU_OPT_BOOL,
G
Gerd Hoffmann 已提交
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
        },{
            .name = "x509-dir",
            .type = QEMU_OPT_STRING,
        },{
            .name = "x509-key-file",
            .type = QEMU_OPT_STRING,
        },{
            .name = "x509-key-password",
            .type = QEMU_OPT_STRING,
        },{
            .name = "x509-cert-file",
            .type = QEMU_OPT_STRING,
        },{
            .name = "x509-cacert-file",
            .type = QEMU_OPT_STRING,
        },{
            .name = "x509-dh-key-file",
            .type = QEMU_OPT_STRING,
        },{
            .name = "tls-ciphers",
            .type = QEMU_OPT_STRING,
422 423 424 425 426 427
        },{
            .name = "tls-channel",
            .type = QEMU_OPT_STRING,
        },{
            .name = "plaintext-channel",
            .type = QEMU_OPT_STRING,
428 429 430 431 432 433 434 435 436
        },{
            .name = "image-compression",
            .type = QEMU_OPT_STRING,
        },{
            .name = "jpeg-wan-compression",
            .type = QEMU_OPT_STRING,
        },{
            .name = "zlib-glz-wan-compression",
            .type = QEMU_OPT_STRING,
G
Gerd Hoffmann 已提交
437 438 439 440 441 442 443 444 445
        },{
            .name = "streaming-video",
            .type = QEMU_OPT_STRING,
        },{
            .name = "agent-mouse",
            .type = QEMU_OPT_BOOL,
        },{
            .name = "playback-compression",
            .type = QEMU_OPT_BOOL,
G
Gerd Hoffmann 已提交
446
        },
G
Gerd Hoffmann 已提交
447
        { /* end of list */ }
G
Gerd Hoffmann 已提交
448 449 450
    },
};

G
Gleb Natapov 已提交
451 452 453 454 455 456 457 458 459 460 461 462
QemuOptsList qemu_option_rom_opts = {
    .name = "option-rom",
    .implied_opt_name = "romfile",
    .head = QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts.head),
    .desc = {
        {
            .name = "bootindex",
            .type = QEMU_OPT_NUMBER,
        }, {
            .name = "romfile",
            .type = QEMU_OPT_STRING,
        },
G
Gerd Hoffmann 已提交
463
        { /* end of list */ }
G
Gleb Natapov 已提交
464 465 466
    },
};

467 468
static QemuOptsList qemu_machine_opts = {
    .name = "machine",
469
    .implied_opt_name = "type",
470 471 472
    .head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head),
    .desc = {
        {
473 474 475 476
            .name = "type",
            .type = QEMU_OPT_STRING,
            .help = "emulated machine"
        }, {
477 478 479 480 481 482 483 484
            .name = "accel",
            .type = QEMU_OPT_STRING,
            .help = "accelerator list",
        },
        { /* End of list */ }
    },
};

W
wayne 已提交
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
QemuOptsList qemu_boot_opts = {
    .name = "boot-opts",
    .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head),
    .desc = {
        /* the three names below are not used now */
        {
            .name = "order",
            .type = QEMU_OPT_STRING,
        }, {
            .name = "once",
            .type = QEMU_OPT_STRING,
        }, {
            .name = "menu",
            .type = QEMU_OPT_STRING,
        /* following are really used */
        }, {
            .name = "splash",
            .type = QEMU_OPT_STRING,
        }, {
            .name = "splash-time",
            .type = QEMU_OPT_STRING,
        },
        { /*End of list */ }
    },
};

511
static QemuOptsList *vm_config_groups[32] = {
G
Gerd Hoffmann 已提交
512
    &qemu_drive_opts,
513
    &qemu_chardev_opts,
G
Gerd Hoffmann 已提交
514
    &qemu_device_opts,
M
Mark McLoughlin 已提交
515
    &qemu_netdev_opts,
M
Mark McLoughlin 已提交
516
    &qemu_net_opts,
J
Jan Kiszka 已提交
517
    &qemu_rtc_opts,
518
    &qemu_global_opts,
519
    &qemu_mon_opts,
520
    &qemu_cpudef_opts,
521
    &qemu_trace_opts,
G
Gleb Natapov 已提交
522
    &qemu_option_rom_opts,
523
    &qemu_machine_opts,
W
wayne 已提交
524
    &qemu_boot_opts,
G
Gerd Hoffmann 已提交
525 526 527
    NULL,
};

528
static QemuOptsList *find_list(QemuOptsList **lists, const char *group)
G
Gerd Hoffmann 已提交
529 530 531 532 533 534 535 536
{
    int i;

    for (i = 0; lists[i] != NULL; i++) {
        if (strcmp(lists[i]->name, group) == 0)
            break;
    }
    if (lists[i] == NULL) {
537
        error_report("there is no option group \"%s\"", group);
G
Gerd Hoffmann 已提交
538 539 540 541
    }
    return lists[i];
}

542 543 544 545 546
QemuOptsList *qemu_find_opts(const char *group)
{
    return find_list(vm_config_groups, group);
}

547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
void qemu_add_opts(QemuOptsList *list)
{
    int entries, i;

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

G
Gerd Hoffmann 已提交
563 564 565
int qemu_set_option(const char *str)
{
    char group[64], id[64], arg[64];
G
Gerd Hoffmann 已提交
566
    QemuOptsList *list;
G
Gerd Hoffmann 已提交
567
    QemuOpts *opts;
G
Gerd Hoffmann 已提交
568
    int rc, offset;
G
Gerd Hoffmann 已提交
569 570 571

    rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset);
    if (rc < 3 || str[offset] != '=') {
572
        error_report("can't parse: \"%s\"", str);
G
Gerd Hoffmann 已提交
573 574 575
        return -1;
    }

576
    list = qemu_find_opts(group);
G
Gerd Hoffmann 已提交
577
    if (list == NULL) {
G
Gerd Hoffmann 已提交
578 579 580
        return -1;
    }

G
Gerd Hoffmann 已提交
581
    opts = qemu_opts_find(list, id);
G
Gerd Hoffmann 已提交
582
    if (!opts) {
583 584
        error_report("there is no %s \"%s\" defined",
                     list->name, id);
G
Gerd Hoffmann 已提交
585 586 587
        return -1;
    }

M
Mark McLoughlin 已提交
588
    if (qemu_opt_set(opts, arg, str+offset+1) == -1) {
G
Gerd Hoffmann 已提交
589 590 591 592 593
        return -1;
    }
    return 0;
}

594 595 596 597 598 599 600 601
int qemu_global_option(const char *str)
{
    char driver[64], property[64];
    QemuOpts *opts;
    int rc, offset;

    rc = sscanf(str, "%63[^.].%63[^=]%n", driver, property, &offset);
    if (rc < 2 || str[offset] != '=') {
602
        error_report("can't parse: \"%s\"", str);
603 604 605 606 607 608 609 610 611 612
        return -1;
    }

    opts = qemu_opts_create(&qemu_global_opts, NULL, 0);
    qemu_opt_set(opts, "driver", driver);
    qemu_opt_set(opts, "property", property);
    qemu_opt_set(opts, "value", str+offset+1);
    return 0;
}

G
Gerd Hoffmann 已提交
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
struct ConfigWriteData {
    QemuOptsList *list;
    FILE *fp;
};

static int config_write_opt(const char *name, const char *value, void *opaque)
{
    struct ConfigWriteData *data = opaque;

    fprintf(data->fp, "  %s = \"%s\"\n", name, value);
    return 0;
}

static int config_write_opts(QemuOpts *opts, void *opaque)
{
    struct ConfigWriteData *data = opaque;
    const char *id = qemu_opts_id(opts);

    if (id) {
        fprintf(data->fp, "[%s \"%s\"]\n", data->list->name, id);
    } else {
        fprintf(data->fp, "[%s]\n", data->list->name);
    }
    qemu_opt_foreach(opts, config_write_opt, data, 0);
    fprintf(data->fp, "\n");
    return 0;
}

void qemu_config_write(FILE *fp)
{
    struct ConfigWriteData data = { .fp = fp };
644
    QemuOptsList **lists = vm_config_groups;
G
Gerd Hoffmann 已提交
645 646 647 648 649 650 651 652
    int i;

    fprintf(fp, "# qemu config file\n\n");
    for (i = 0; lists[i] != NULL; i++) {
        data.list = lists[i];
        qemu_opts_foreach(data.list, config_write_opts, &data, 0);
    }
}
G
Gerd Hoffmann 已提交
653

654
int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname)
G
Gerd Hoffmann 已提交
655 656
{
    char line[1024], group[64], id[64], arg[64], value[1024];
657
    Location loc;
G
Gerd Hoffmann 已提交
658 659
    QemuOptsList *list = NULL;
    QemuOpts *opts = NULL;
660
    int res = -1, lno = 0;
G
Gerd Hoffmann 已提交
661

662
    loc_push_none(&loc);
G
Gerd Hoffmann 已提交
663
    while (fgets(line, sizeof(line), fp) != NULL) {
664
        loc_set_file(fname, ++lno);
G
Gerd Hoffmann 已提交
665 666 667 668 669 670 671 672 673 674
        if (line[0] == '\n') {
            /* skip empty lines */
            continue;
        }
        if (line[0] == '#') {
            /* comment */
            continue;
        }
        if (sscanf(line, "[%63s \"%63[^\"]\"]", group, id) == 2) {
            /* group with id */
675
            list = find_list(lists, group);
G
Gerd Hoffmann 已提交
676
            if (list == NULL)
677
                goto out;
G
Gerd Hoffmann 已提交
678 679 680 681 682
            opts = qemu_opts_create(list, id, 1);
            continue;
        }
        if (sscanf(line, "[%63[^]]]", group) == 1) {
            /* group without id */
683
            list = find_list(lists, group);
G
Gerd Hoffmann 已提交
684
            if (list == NULL)
685
                goto out;
G
Gerd Hoffmann 已提交
686 687 688 689 690 691
            opts = qemu_opts_create(list, NULL, 0);
            continue;
        }
        if (sscanf(line, " %63s = \"%1023[^\"]\"", arg, value) == 2) {
            /* arg = value */
            if (opts == NULL) {
692 693
                error_report("no group defined");
                goto out;
G
Gerd Hoffmann 已提交
694 695
            }
            if (qemu_opt_set(opts, arg, value) != 0) {
696
                goto out;
G
Gerd Hoffmann 已提交
697 698 699
            }
            continue;
        }
700 701
        error_report("parse error");
        goto out;
G
Gerd Hoffmann 已提交
702
    }
703 704 705 706
    if (ferror(fp)) {
        error_report("error reading file");
        goto out;
    }
707 708 709 710
    res = 0;
out:
    loc_pop(&loc);
    return res;
G
Gerd Hoffmann 已提交
711
}
712 713 714 715

int qemu_read_config_file(const char *filename)
{
    FILE *f = fopen(filename, "r");
716 717
    int ret;

718 719 720 721
    if (f == NULL) {
        return -errno;
    }

722
    ret = qemu_config_parse(f, vm_config_groups, filename);
723 724
    fclose(f);

725 726 727 728 729
    if (ret == 0) {
        return 0;
    } else {
        return -EINVAL;
    }
730
}