qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Marcel Apfelbaum <marcel.a@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, aliguori@us.ibm.com, afaerber@suse.de,
	sw@weilnetz.de
Subject: [Qemu-devel] [PATCH] qdev-monitor: Avoid exiting when hot-plugging two devices with the same bootindex value
Date: Wed, 11 Sep 2013 21:26:46 +0300	[thread overview]
Message-ID: <1378924006-14057-1-git-send-email-marcel.a@redhat.com> (raw)

Qemu is expected to quit if the same boot index value is used by two devices.
However, hot-plugging a device with a bootindex value already used should
fail with a friendly message rather than quitting a running VM.

Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
---
 qdev-monitor.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/qdev-monitor.c b/qdev-monitor.c
index 410cdcb..654d086 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -24,6 +24,7 @@
 #include "qmp-commands.h"
 #include "sysemu/arch_init.h"
 #include "qemu/config-file.h"
+#include "sysemu/sysemu.h"
 
 /*
  * Aliases were a bad idea from the start.  Let's keep them
@@ -442,6 +443,31 @@ static BusState *qbus_find(const char *path)
     }
 }
 
+#define OBJ_PROP_BOOTINDEX "bootindex"
+
+static bool bootindex_colision(Object *obj, QemuOpts *opts)
+{
+    int32_t bootindex;
+
+    if (!object_property_find(obj, OBJ_PROP_BOOTINDEX, NULL)) {
+        return false;
+    }
+
+    /* avoid parsing by setting the property and then getting it typed */
+    object_property_parse(obj, qemu_opt_get(opts, OBJ_PROP_BOOTINDEX),
+                          OBJ_PROP_BOOTINDEX, NULL);
+    bootindex = (int32_t)object_property_get_int(obj, OBJ_PROP_BOOTINDEX,
+                                                 NULL);
+
+    if (bootindex >= 0) {
+        if (get_boot_device(bootindex)) {
+            return true;
+        }
+    }
+
+    return false;
+}
+
 DeviceState *qdev_device_add(QemuOpts *opts)
 {
     ObjectClass *obj;
@@ -502,6 +528,13 @@ DeviceState *qdev_device_add(QemuOpts *opts)
     /* create device, set properties */
     qdev = DEVICE(object_new(driver));
 
+    if (qdev_hotplug && bootindex_colision(OBJECT(qdev), opts)) {
+        qerror_report(QERR_INVALID_PARAMETER_VALUE,
+                      "bootindex", "an unused boot index value");
+        qdev_free(qdev);
+        return NULL;
+    }
+
     if (bus) {
         qdev_set_parent_bus(qdev, bus);
     }
-- 
1.8.3.1

             reply	other threads:[~2013-09-11 18:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-11 18:26 Marcel Apfelbaum [this message]
2013-09-11 18:41 ` [Qemu-devel] [PATCH] qdev-monitor: Avoid exiting when hot-plugging two devices with the same bootindex value Marcel Apfelbaum
2013-09-12  7:49 ` Paolo Bonzini
2013-09-12  8:38   ` Marcel Apfelbaum
2013-09-12  9:43   ` Markus Armbruster
2013-09-12 10:33     ` Marcel Apfelbaum
2013-09-12 11:04       ` Markus Armbruster
2013-09-12 11:23         ` Marcel Apfelbaum
2013-09-16  9:54         ` Marcel Apfelbaum
2013-09-16 10:11           ` Paolo Bonzini
2013-09-16 15:14             ` Michael S. Tsirkin
2013-09-16 15:34               ` Paolo Bonzini
2013-09-16 15:59                 ` Michael S. Tsirkin
2013-09-16 11:03           ` Gleb Natapov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1378924006-14057-1-git-send-email-marcel.a@redhat.com \
    --to=marcel.a@redhat.com \
    --cc=afaerber@suse.de \
    --cc=aliguori@us.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sw@weilnetz.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).