qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: fred.konrad@greensocs.com
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, aliguori@us.ibm.com,
	e.voevodin@samsung.com, mark.burton@greensocs.com,
	stefanha@redhat.com, cornelia.huck@de.ibm.com, afaerber@suse.de,
	fred.konrad@greensocs.com
Subject: [Qemu-devel] [RFC PATCH V4 1/6] qdev : add a maximum device allowed field for the bus.
Date: Fri, 30 Nov 2012 18:12:05 +0100	[thread overview]
Message-ID: <1354295530-18644-2-git-send-email-fred.konrad@greensocs.com> (raw)
In-Reply-To: <1354295530-18644-1-git-send-email-fred.konrad@greensocs.com>

From: KONRAD Frederic <fred.konrad@greensocs.com>

Only one device can be connected to virtio-bus.
This patch add a field max_dev which is :
    * the maximum amount of devices connected on the bus ( when
    * max_dev!=0 ).
    * have no effect ( when max_dev=0 ).

The function qbus_find_recursive is modified :
    * to return a non full bus when the "bus=" option is not present.
    * to give an error when the "bus=" option is pointing a full bus.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/qdev-core.h    |    2 ++
 hw/qdev-monitor.c |   11 +++++++++++
 qerror.h          |    3 +++
 3 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/hw/qdev-core.h b/hw/qdev-core.h
index fff7f0f..f5019b1 100644
--- a/hw/qdev-core.h
+++ b/hw/qdev-core.h
@@ -113,6 +113,8 @@ struct BusState {
     const char *name;
     int allow_hotplug;
     int max_index;
+    /* maximum devices allowed on the bus. */
+    int max_dev;
     QTAILQ_HEAD(ChildrenHead, BusChild) children;
     QLIST_ENTRY(BusState) sibling;
 };
diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index a1b4d6a..4471b3a 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -292,6 +292,17 @@ static BusState *qbus_find_recursive(BusState *bus, const char *name,
     if (bus_typename && !object_dynamic_cast(OBJECT(bus), bus_typename)) {
         match = 0;
     }
+    /* Check if max_dev is reached */
+    if ((bus->max_dev != 0) && (bus->max_dev <= bus->max_index)) {
+        if (name != NULL) {
+            /* bus was explicitly specified : return an error. */
+            qerror_report(QERR_BUS_IS_FULL, bus->name);
+            return NULL;
+        } else {
+            /* bus was not specified : try to find another one. */
+            match = 0;
+        }
+    }
     if (match) {
         return bus;
     }
diff --git a/qerror.h b/qerror.h
index 8db4309..b159828 100644
--- a/qerror.h
+++ b/qerror.h
@@ -69,6 +69,9 @@ void assert_no_error(Error *err);
 #define QERR_BUS_NOT_FOUND \
     ERROR_CLASS_GENERIC_ERROR, "Bus '%s' not found"
 
+#define QERR_BUS_IS_FULL \
+    ERROR_CLASS_GENERIC_ERROR, "Bus '%s' is full"
+
 #define QERR_COMMAND_DISABLED \
     ERROR_CLASS_GENERIC_ERROR, "The command %s has been disabled for this instance"
 
-- 
1.7.1

  reply	other threads:[~2012-11-30 17:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-30 17:12 [Qemu-devel] [RFC PATCH V4 0/6] Virtio refactoring fred.konrad
2012-11-30 17:12 ` fred.konrad [this message]
2012-11-30 18:26   ` [Qemu-devel] [RFC PATCH V4 1/6] qdev : add a maximum device allowed field for the bus Peter Maydell
2012-11-30 17:12 ` [Qemu-devel] [RFC PATCH V4 2/6] virtio-bus : Introduce virtio-bus fred.konrad
2012-11-30 18:36   ` Peter Maydell
2012-11-30 17:12 ` [Qemu-devel] [RFC PATCH V4 3/6] virtio-pci-bus : Introduce virtio-pci-bus fred.konrad
2012-11-30 17:12 ` [Qemu-devel] [RFC PATCH V4 4/6] virtio-pci : Introduce virtio-pci device fred.konrad
2012-11-30 17:12 ` [Qemu-devel] [RFC PATCH V4 5/6] virtio-device : Introduce virtio-device fred.konrad
2012-11-30 18:40   ` Peter Maydell
2012-11-30 17:12 ` [Qemu-devel] [RFC PATCH V4 6/6] virtio-blk : Refactoring virtio-blk fred.konrad
2012-11-30 18:42   ` Peter Maydell
2012-11-30 18:43 ` [Qemu-devel] [RFC PATCH V4 0/6] Virtio refactoring Peter Maydell
2012-12-03  9:25   ` KONRAD Frédéric

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=1354295530-18644-2-git-send-email-fred.konrad@greensocs.com \
    --to=fred.konrad@greensocs.com \
    --cc=afaerber@suse.de \
    --cc=aliguori@us.ibm.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=e.voevodin@samsung.com \
    --cc=mark.burton@greensocs.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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).