* [Qemu-devel] [PATCH 1/2] qdev: make compat stuff more generic @ 2009-11-24 11:06 Gerd Hoffmann 2009-11-24 11:06 ` [Qemu-devel] [PATCH 2/2] qdev: add command line option to set global defaults for properties Gerd Hoffmann 0 siblings, 1 reply; 6+ messages in thread From: Gerd Hoffmann @ 2009-11-24 11:06 UTC (permalink / raw) To: qemu-devel; +Cc: Gerd Hoffmann This patch renames the compat properties into global properties and makes them more generic. The compatibility stuff is only one of multiple possible users now. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- hw/boards.h | 2 +- hw/pc.c | 2 +- hw/qdev-properties.c | 22 ++++++++++++++-------- hw/qdev.c | 2 +- hw/qdev.h | 10 ++++++---- vl.c | 2 +- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/hw/boards.h b/hw/boards.h index d889341..7a0f20f 100644 --- a/hw/boards.h +++ b/hw/boards.h @@ -20,7 +20,7 @@ typedef struct QEMUMachine { int use_scsi; int max_cpus; int is_default; - CompatProperty *compat_props; + GlobalProperty *compat_props; struct QEMUMachine *next; } QEMUMachine; diff --git a/hw/pc.c b/hw/pc.c index 7c791c4..f8b270b 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -1292,7 +1292,7 @@ static QEMUMachine pc_machine_v0_10 = { .desc = "Standard PC, qemu 0.10", .init = pc_init_pci, .max_cpus = 255, - .compat_props = (CompatProperty[]) { + .compat_props = (GlobalProperty[]) { { .driver = "virtio-blk-pci", .property = "class", diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index bda6699..fe106bd 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -593,21 +593,27 @@ void qdev_prop_set_defaults(DeviceState *dev, Property *props) } } -static CompatProperty *compat_props; +static QTAILQ_HEAD(, GlobalProperty) global_props = QTAILQ_HEAD_INITIALIZER(global_props); -void qdev_prop_register_compat(CompatProperty *props) +void qdev_prop_register_global(GlobalProperty *prop) { - compat_props = props; + QTAILQ_INSERT_TAIL(&global_props, prop, next); } -void qdev_prop_set_compat(DeviceState *dev) +void qdev_prop_register_global_list(GlobalProperty *props) { - CompatProperty *prop; + int i; - if (!compat_props) { - return; + for (i = 0; props[i].driver != NULL; i++) { + qdev_prop_register_global(props+i); } - for (prop = compat_props; prop->driver != NULL; prop++) { +} + +void qdev_prop_set_globals(DeviceState *dev) +{ + GlobalProperty *prop; + + QTAILQ_FOREACH(prop, &global_props, next) { if (strcmp(dev->info->name, prop->driver) != 0) { continue; } diff --git a/hw/qdev.c b/hw/qdev.c index d19d531..d8fbc9a 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -102,7 +102,7 @@ DeviceState *qdev_create(BusState *bus, const char *name) dev->parent_bus = bus; qdev_prop_set_defaults(dev, dev->info->props); qdev_prop_set_defaults(dev, dev->parent_bus->info->props); - qdev_prop_set_compat(dev); + qdev_prop_set_globals(dev); QLIST_INSERT_HEAD(&bus->children, dev, sibling); if (qdev_hotplug) { assert(bus->allow_hotplug); diff --git a/hw/qdev.h b/hw/qdev.h index 41642ee..557b5e4 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -92,11 +92,12 @@ struct PropertyInfo { int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len); }; -struct CompatProperty { +typedef struct GlobalProperty { const char *driver; const char *property; const char *value; -}; + QTAILQ_ENTRY(GlobalProperty) next; +} GlobalProperty; /*** Board API. This should go away once we have a machine config file. ***/ @@ -266,8 +267,9 @@ void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value); void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); void qdev_prop_set_defaults(DeviceState *dev, Property *props); -void qdev_prop_register_compat(CompatProperty *props); -void qdev_prop_set_compat(DeviceState *dev); +void qdev_prop_register_global(GlobalProperty *prop); +void qdev_prop_register_global_list(GlobalProperty *props); +void qdev_prop_set_globals(DeviceState *dev); /* This is a nasty hack to allow passing a NULL bus to qdev_create. */ extern struct BusInfo system_bus_info; diff --git a/vl.c b/vl.c index ee43808..d52b1cc 100644 --- a/vl.c +++ b/vl.c @@ -5698,7 +5698,7 @@ int main(int argc, char **argv, char **envp) } if (machine->compat_props) { - qdev_prop_register_compat(machine->compat_props); + qdev_prop_register_global_list(machine->compat_props); } machine->init(ram_size, boot_devices, kernel_filename, kernel_cmdline, initrd_filename, cpu_model); -- 1.6.2.5 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 2/2] qdev: add command line option to set global defaults for properties. 2009-11-24 11:06 [Qemu-devel] [PATCH 1/2] qdev: make compat stuff more generic Gerd Hoffmann @ 2009-11-24 11:06 ` Gerd Hoffmann 2009-11-24 14:11 ` [Qemu-devel] " Michael S. Tsirkin 0 siblings, 1 reply; 6+ messages in thread From: Gerd Hoffmann @ 2009-11-24 11:06 UTC (permalink / raw) To: qemu-devel; +Cc: Gerd Hoffmann This patch adds infrastructure and command line option for setting global defaults for device properties, i.e. you can for example use -global virtio-blk-pci.vectors=0 to turn off msi by default for all virtio block devices. The config file syntax is: [global] driver = "virtio-blk-pci" property = "vectors" value = "0" This can also be used to set properties for devices which are not created via -device but implicitly via machine init, i.e. -global isa-fdc,driveA=<name> This patch uses the mechanism which configures properties for the compatibility machine types (pc-0.10 & friends). The command line takes precedence over the machine type values. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- qemu-config.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-config.h | 2 + qemu-options.hx | 3 ++ vl.c | 6 +++++ 4 files changed, 67 insertions(+), 0 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index 590fc05..e12b66c 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -2,6 +2,7 @@ #include "qemu-option.h" #include "qemu-config.h" #include "sysemu.h" +#include "hw/qdev.h" QemuOptsList qemu_drive_opts = { .name = "drive", @@ -202,6 +203,24 @@ QemuOptsList qemu_rtc_opts = { }, }; +QemuOptsList qemu_global_opts = { + .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, + }, + { /* end if list */ } + }, +}; + static QemuOptsList *lists[] = { &qemu_drive_opts, &qemu_chardev_opts, @@ -209,6 +228,7 @@ static QemuOptsList *lists[] = { &qemu_netdev_opts, &qemu_net_opts, &qemu_rtc_opts, + &qemu_global_opts, NULL, }; @@ -257,6 +277,42 @@ int qemu_set_option(const char *str) return 0; } +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] != '=') { + qemu_error("can't parse: \"%s\"\n", str); + 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; +} + +static int qemu_add_one_global(QemuOpts *opts, void *opaque) +{ + GlobalProperty *g; + + g = qemu_mallocz(sizeof(*g)); + g->driver = qemu_opt_get(opts, "driver"); + g->property = qemu_opt_get(opts, "property"); + g->value = qemu_opt_get(opts, "value"); + qdev_prop_register_global(g); + return 0; +} + +void qemu_add_globals(void) +{ + qemu_opts_foreach(&qemu_global_opts, qemu_add_one_global, NULL, 0); +} + struct ConfigWriteData { QemuOptsList *list; FILE *fp; diff --git a/qemu-config.h b/qemu-config.h index b564851..6246e76 100644 --- a/qemu-config.h +++ b/qemu-config.h @@ -9,6 +9,8 @@ extern QemuOptsList qemu_net_opts; extern QemuOptsList qemu_rtc_opts; int qemu_set_option(const char *str); +int qemu_global_option(const char *str); +void qemu_add_globals(void); void qemu_config_write(FILE *fp); int qemu_config_parse(FILE *fp); diff --git a/qemu-options.hx b/qemu-options.hx index b65fd74..420b7d8 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -109,6 +109,9 @@ DEF("set", HAS_ARG, QEMU_OPTION_set, "-set group.id.arg=value\n" " set <arg> parameter for item <id> of type <group>\n" " i.e. -set drive.$id.file=/path/to/image\n") +DEF("global", HAS_ARG, QEMU_OPTION_global, + "-global driver.property=value\n" + " set a global default for a driver property\n") STEXI @item -drive @var{option}[,@var{option}[,@var{option}[,...]]] diff --git a/vl.c b/vl.c index d52b1cc..4911fe5 100644 --- a/vl.c +++ b/vl.c @@ -4786,6 +4786,10 @@ int main(int argc, char **argv, char **envp) if (qemu_set_option(optarg) != 0) exit(1); break; + case QEMU_OPTION_global: + if (qemu_global_option(optarg) != 0) + exit(1); + break; case QEMU_OPTION_mtdblock: drive_add(optarg, MTD_ALIAS); break; @@ -5700,6 +5704,8 @@ int main(int argc, char **argv, char **envp) if (machine->compat_props) { qdev_prop_register_global_list(machine->compat_props); } + qemu_add_globals(); + machine->init(ram_size, boot_devices, kernel_filename, kernel_cmdline, initrd_filename, cpu_model); -- 1.6.2.5 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] Re: [PATCH 2/2] qdev: add command line option to set global defaults for properties. 2009-11-24 11:06 ` [Qemu-devel] [PATCH 2/2] qdev: add command line option to set global defaults for properties Gerd Hoffmann @ 2009-11-24 14:11 ` Michael S. Tsirkin 2009-11-25 12:55 ` Gerd Hoffmann 0 siblings, 1 reply; 6+ messages in thread From: Michael S. Tsirkin @ 2009-11-24 14:11 UTC (permalink / raw) To: Gerd Hoffmann; +Cc: qemu-devel On Tue, Nov 24, 2009 at 12:06:28PM +0100, Gerd Hoffmann wrote: > This patch adds infrastructure and command line option for setting > global defaults for device properties, i.e. you can for example use > > -global virtio-blk-pci.vectors=0 > > to turn off msi by default for all virtio block devices. The config > file syntax is: > > [global] > driver = "virtio-blk-pci" > property = "vectors" > value = "0" Where's this documented? > This can also be used to set properties for devices which are not > created via -device but implicitly via machine init, i.e. > > -global isa-fdc,driveA=<name> > ... > diff --git a/qemu-options.hx b/qemu-options.hx > index b65fd74..420b7d8 100644 > --- a/qemu-options.hx > +++ b/qemu-options.hx > @@ -109,6 +109,9 @@ DEF("set", HAS_ARG, QEMU_OPTION_set, > "-set group.id.arg=value\n" > " set <arg> parameter for item <id> of type <group>\n" > " i.e. -set drive.$id.file=/path/to/image\n") > +DEF("global", HAS_ARG, QEMU_OPTION_global, > + "-global driver.property=value\n" > + " set a global default for a driver property\n") > STEXI > @item -drive @var{option}[,@var{option}[,@var{option}[,...]]] Let's add a hint on how to get the list of drivers and properties? How would one figure out the command lines you give in the examples above? -- MST ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Qemu-devel] Re: [PATCH 2/2] qdev: add command line option to set global defaults for properties. 2009-11-24 14:11 ` [Qemu-devel] " Michael S. Tsirkin @ 2009-11-25 12:55 ` Gerd Hoffmann 2009-11-25 13:18 ` Michael S. Tsirkin 0 siblings, 1 reply; 6+ messages in thread From: Gerd Hoffmann @ 2009-11-25 12:55 UTC (permalink / raw) To: Michael S. Tsirkin; +Cc: qemu-devel [-- Attachment #1: Type: text/plain, Size: 1227 bytes --] On 11/24/09 15:11, Michael S. Tsirkin wrote: > On Tue, Nov 24, 2009 at 12:06:28PM +0100, Gerd Hoffmann wrote: >> This patch adds infrastructure and command line option for setting >> global defaults for device properties, i.e. you can for example use >> >> -global virtio-blk-pci.vectors=0 >> >> to turn off msi by default for all virtio block devices. The config >> file syntax is: >> >> [global] >> driver = "virtio-blk-pci" >> property = "vectors" >> value = "0" > > Where's this documented? config file syntax is git-style, the details are not (yet) documented. Easiest way to get one if you want to play with it is "qemu <all-your-vm-options-here> -writeconfig <filename>". Note that not all command line options are covered. I've attached a sample to this mail. Needs a few patches sent to the list yesterday and today to actually work though. > How would one figure out the command lines you give in > the examples above? "info qtree" in monitor prints the device names and properties for all devices used by the virtual machine. "info qdm" and '-device ?' list all devices known to qemu. The device properties are not listed there though (one of the items on my todo list). cheers, Gerd [-- Attachment #2: x86-gfx.cfg --] [-- Type: text/plain, Size: 1617 bytes --] # qemu config file # The config file doesn't yet cover all possible options. # # minimum command line: # qemu -nodefaults -vga cirrus -readconfig $thisfile # # you might want to add these switches: # -enable-kvm -m <mem> -smp <cpus> -vnc <display> -monitor <chardev> # # create a new config file for your guest, for the bits already covered: # qemu <tons-of-switches-here> -writeconfig <name>.cfg ##################################################### # host side configuration [drive "hda"] if = "none" file = "/vmdisk/arch-x86.img" [drive "hdc"] if = "none" media = "cdrom" [drive "sda"] if = "none" file = "/vmdisk/test-lsi-1.img" [drive "sdb"] if = "none" file = "/vmdisk/test-lsi-2.img" [drive "vda"] if = "none" file = "/vmdisk/test-vio-1.img" [chardev "ttyS0"] backend = "vc" cols = "100" rows = "50" [netdev "eth0"] type = "user" ##################################################### # guest devices [device] driver = "ide-drive" bus = "ide.0" drive = "hda" [device] driver = "ide-drive" bus = "ide.1" drive = "hdc" [device] driver = "isa-serial" chardev = "ttyS0" [device] driver = "e1000" netdev = "eth0" mac = "52:54:00:78:23:6f" addr = "06.0" [device] driver = "AC97" addr = "05.0" [device] driver = "virtio-balloon-pci" addr = "08.0" [device] driver = "virtio-blk-pci" addr = "0c.0" drive = "vda" [device "lsi"] driver = "lsi53c895a" addr = "0a.0" [device] driver = "scsi-disk" bus = "lsi.0" scsi-id = "0" drive = "sda" [device] driver = "scsi-disk" bus = "lsi.0" scsi-id = "2" drive = "sdb" ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Qemu-devel] Re: [PATCH 2/2] qdev: add command line option to set global defaults for properties. 2009-11-25 12:55 ` Gerd Hoffmann @ 2009-11-25 13:18 ` Michael S. Tsirkin 2009-11-25 14:03 ` Paul Brook 0 siblings, 1 reply; 6+ messages in thread From: Michael S. Tsirkin @ 2009-11-25 13:18 UTC (permalink / raw) To: Gerd Hoffmann; +Cc: qemu-devel On Wed, Nov 25, 2009 at 01:55:18PM +0100, Gerd Hoffmann wrote: > On 11/24/09 15:11, Michael S. Tsirkin wrote: >> On Tue, Nov 24, 2009 at 12:06:28PM +0100, Gerd Hoffmann wrote: >>> This patch adds infrastructure and command line option for setting >>> global defaults for device properties, i.e. you can for example use >>> >>> -global virtio-blk-pci.vectors=0 >>> >>> to turn off msi by default for all virtio block devices. The config >>> file syntax is: >>> >>> [global] >>> driver = "virtio-blk-pci" >>> property = "vectors" >>> value = "0" >> >> Where's this documented? > > config file syntax is git-style, the details are not (yet) documented. > > Easiest way to get one if you want to play with it is > "qemu <all-your-vm-options-here> -writeconfig <filename>". > > Note that not all command line options are covered. > > I've attached a sample to this mail. Needs a few patches sent to the > list yesterday and today to actually work though. > >> How would one figure out the command lines you give in >> the examples above? > > "info qtree" in monitor prints the device names and properties for all > devices used by the virtual machine. > > "info qdm" and '-device ?' list all devices known to qemu. So maybe add "use -device ? to get list of all devices" to help text? [mst@tuck qemu]$ ~/qemu-git/bin/qemu-system-x86_64 -device ? /home/mst/qemu-git/bin/qemu-system-x86_64: invalid option -- '-device' [mst@tuck qemu]$ ~/qemu-git/bin/qemu-system-x86_64 --device ? /home/mst/qemu-git/bin/qemu-system-x86_64: invalid option -- '-device' > The device > properties are not listed there though (one of the items on my todo > list). Yes, and in fact each option should supply a help text explaining what it is. This was not done this way upfront and each day makes it harder to document as new options are added without documentation. > cheers, > Gerd ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] Re: [PATCH 2/2] qdev: add command line option to set global defaults for properties. 2009-11-25 13:18 ` Michael S. Tsirkin @ 2009-11-25 14:03 ` Paul Brook 0 siblings, 0 replies; 6+ messages in thread From: Paul Brook @ 2009-11-25 14:03 UTC (permalink / raw) To: qemu-devel; +Cc: Gerd Hoffmann, Michael S. Tsirkin > So maybe add "use -device ? to get list of all devices" > to help text? > > [mst@tuck qemu]$ ~/qemu-git/bin/qemu-system-x86_64 -device ? > /home/mst/qemu-git/bin/qemu-system-x86_64: invalid option -- '-device' You need to stop your shell eating the ? Paul ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-11-25 14:03 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2009-11-24 11:06 [Qemu-devel] [PATCH 1/2] qdev: make compat stuff more generic Gerd Hoffmann 2009-11-24 11:06 ` [Qemu-devel] [PATCH 2/2] qdev: add command line option to set global defaults for properties Gerd Hoffmann 2009-11-24 14:11 ` [Qemu-devel] " Michael S. Tsirkin 2009-11-25 12:55 ` Gerd Hoffmann 2009-11-25 13:18 ` Michael S. Tsirkin 2009-11-25 14:03 ` Paul Brook
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).