qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] qdev: more patches for the -device switch
@ 2009-07-02 10:32 Gerd Hoffmann
  2009-07-02 10:32 ` [Qemu-devel] [PATCH 1/2] qdev: add user-specified identifier to devices Gerd Hoffmann
  2009-07-02 10:32 ` [Qemu-devel] [PATCH 2/2] switch balloon initialization to -device Gerd Hoffmann
  0 siblings, 2 replies; 3+ messages in thread
From: Gerd Hoffmann @ 2009-07-02 10:32 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

  Hi,

Two little patches showing what nice things we can do now with qdev and
the -device switch in place.  The patches obviously depend on the other
patches posted yesterday which add the -device switch in the first place.

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Qemu-devel] [PATCH 1/2] qdev: add user-specified identifier to devices.
  2009-07-02 10:32 [Qemu-devel] [PATCH 0/2] qdev: more patches for the -device switch Gerd Hoffmann
@ 2009-07-02 10:32 ` Gerd Hoffmann
  2009-07-02 10:32 ` [Qemu-devel] [PATCH 2/2] switch balloon initialization to -device Gerd Hoffmann
  1 sibling, 0 replies; 3+ messages in thread
From: Gerd Hoffmann @ 2009-07-02 10:32 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Add id field to DeviceState.  Make qdev_device_add() fill it if supplied
on the command line (i.e. -device foo,id=bar).  Make "info qtree" print it.

This helps users and management apps identifying devices in monitor
output, which is especially useful with otherwise identical devices
such as two virtio disks.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/qdev.c |    5 ++++-
 hw/qdev.h |    1 +
 2 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index 2b8994a..735fe4e 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -145,6 +145,7 @@ DeviceState *qdev_device_add(const char *cmdline)
     qdev = info->bus_info->add(driver, strlen(addr) ? addr : NULL);
 
     if (params) {
+        get_param_value(qdev->id, sizeof(qdev->id), "id", params);
         while (params[0]) {
             if (2 != sscanf(params, "%31[^=]=%255[^,]%n", tag, value, &n)) {
                 fprintf(stderr, "parse error at \"%s\"\n", params);
@@ -153,6 +154,8 @@ DeviceState *qdev_device_add(const char *cmdline)
             params += n;
             if (strcmp(tag, "addr") == 0)
                 continue;
+            if (strcmp(tag, "id") == 0)
+                continue;
             if (-1 == qdev_prop_parse(qdev, tag, value)) {
                 fprintf(stderr, "can't set property \"%s\" to \"%s\" for \"%s\"\n",
                         tag, value, driver);
@@ -308,7 +311,7 @@ static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props,
 static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
 {
     BusState *child;
-    qdev_printf("dev: %s\n", dev->info->name);
+    qdev_printf("dev: %s, id \"%s\"\n", dev->info->name, dev->id);
     indent += 2;
     if (dev->num_gpio_in) {
         qdev_printf("gpio-in %d\n", dev->num_gpio_in);
diff --git a/hw/qdev.h b/hw/qdev.h
index 8531276..ad3f2a6 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -17,6 +17,7 @@ typedef struct BusInfo BusInfo;
 /* This structure should not be accessed directly.  We declare it here
    so that it can be embedded in individual device state structures.  */
 struct DeviceState {
+    char id[32];
     DeviceInfo *info;
     BusState *parent_bus;
     int num_gpio_out;
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Qemu-devel] [PATCH 2/2] switch balloon initialization to -device.
  2009-07-02 10:32 [Qemu-devel] [PATCH 0/2] qdev: more patches for the -device switch Gerd Hoffmann
  2009-07-02 10:32 ` [Qemu-devel] [PATCH 1/2] qdev: add user-specified identifier to devices Gerd Hoffmann
@ 2009-07-02 10:32 ` Gerd Hoffmann
  1 sibling, 0 replies; 3+ messages in thread
From: Gerd Hoffmann @ 2009-07-02 10:32 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

With that patch applied "-balloon virtio,args" becomes a shortcut for
"-device virtio-balloon-pci,args".

Side effects:
 - ballon device gains support for id=<tag>.
 - ballon device is off by default now.
 - initialization order changes, which may in different pci slot
   assignment depending on the VM configuration.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/pc.c  |    6 -----
 sysemu.h |    2 -
 vl.c     |   65 +++++++++++++++++++++++++++++++++++++------------------------
 3 files changed, 39 insertions(+), 34 deletions(-)

diff --git a/hw/pc.c b/hw/pc.c
index 2b89356..ccd2fed 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -1407,12 +1407,6 @@ static void pc_init1(ram_addr_t ram_size,
         }
     }
 
-    /* Add virtio balloon device */
-    if (pci_enabled && virtio_balloon) {
-        qdev = pci_create("virtio-balloon-pci", virtio_balloon_devaddr);
-        qdev_init(qdev);
-    }
-
     /* Add virtio console devices */
     if (pci_enabled) {
         for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
diff --git a/sysemu.h b/sysemu.h
index 06dc4c6..9a83bfe 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -116,8 +116,6 @@ extern int win2k_install_hack;
 extern int rtc_td_hack;
 extern int alt_grab;
 extern int usb_enabled;
-extern int virtio_balloon;
-extern const char *virtio_balloon_devaddr;
 extern int smp_cpus;
 extern int cursor_hide;
 extern int graphic_rotate;
diff --git a/vl.c b/vl.c
index f62a6b8..2d06cdf 100644
--- a/vl.c
+++ b/vl.c
@@ -236,8 +236,6 @@ int smp_cpus = 1;
 const char *vnc_display;
 int acpi_enabled = 1;
 int no_hpet = 0;
-int virtio_balloon = 1;
-const char *virtio_balloon_devaddr;
 int fd_bootchk = 1;
 int no_reboot = 0;
 int no_shutdown = 0;
@@ -4680,29 +4678,6 @@ static void select_vgahw (const char *p)
     }
 }
 
-#ifdef TARGET_I386
-static int balloon_parse(const char *arg)
-{
-    char buf[128];
-    const char *p;
-
-    if (!strcmp(arg, "none")) {
-        virtio_balloon = 0;
-    } else if (!strncmp(arg, "virtio", 6)) {
-        virtio_balloon = 1;
-        if (arg[6] == ',')  {
-            p = arg + 7;
-            if (get_param_value(buf, sizeof(buf), "addr", p)) {
-                virtio_balloon_devaddr = strdup(buf);
-            }
-        }
-    } else {
-        return -1;
-    }
-    return 0;
-}
-#endif
-
 #ifdef _WIN32
 static BOOL WINAPI qemu_ctrl_handler(DWORD type)
 {
@@ -4908,6 +4883,24 @@ static void add_device_config(int type, const char *cmdline)
     TAILQ_INSERT_TAIL(&device_configs, conf, next);
 }
 
+#ifdef TARGET_I386
+static void add_device_config_params(int type, const char *driver,
+                                     const char *params)
+{
+    char *buf;
+    size_t len,pos;
+
+    len = strlen(driver) + 1;
+    if (params)
+        len += strlen(params) + 1;
+    buf = qemu_mallocz(len);
+    pos = snprintf(buf, len, "%s", driver);
+    if (params)
+        pos += snprintf(buf+pos, len-pos, ",%s", params);
+    add_device_config(type, buf);
+}
+#endif
+
 static int foreach_device_config(int type, int (*func)(const char *cmdline))
 {
     struct device_config *conf;
@@ -4933,6 +4926,26 @@ static int generic_parse(const char *cmdline)
     return 0;
 }
 
+#ifdef TARGET_I386
+static int add_device_balloon(const char *arg)
+{
+    const char *name = NULL, *params = NULL;
+
+    if (!strcmp(arg, "none"))
+        return 0;
+    if (!strncmp(arg, "virtio", 6)) {
+        name = "virtio-balloon-pci";
+        if (arg[6] == ',')
+            params = arg+7;
+    }
+    if (!name)
+        return -1;
+
+    add_device_config_params(DEV_GENERIC, name, params);
+    return 0;
+}
+#endif
+
 int main(int argc, char **argv, char **envp)
 {
     const char *gdbstub_dev = NULL;
@@ -5553,7 +5566,7 @@ int main(int argc, char **argv, char **envp)
                 no_hpet = 1;
                 break;
             case QEMU_OPTION_balloon:
-                if (balloon_parse(optarg) < 0) {
+                if (add_device_balloon(optarg) < 0) {
                     fprintf(stderr, "Unknown -balloon argument %s\n", optarg);
                     exit(1);
                 }
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-07-02 10:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-02 10:32 [Qemu-devel] [PATCH 0/2] qdev: more patches for the -device switch Gerd Hoffmann
2009-07-02 10:32 ` [Qemu-devel] [PATCH 1/2] qdev: add user-specified identifier to devices Gerd Hoffmann
2009-07-02 10:32 ` [Qemu-devel] [PATCH 2/2] switch balloon initialization to -device Gerd Hoffmann

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).