[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 09/10] xen/blkback: get hardware queue number from blkfront



Backend advertise the max number it supported to "multi-queue-max-queues", and
read the negotiate value from "multi-queue-num-queues".

Signed-off-by: Bob Liu <bob.liu@xxxxxxxxxx>
---
 drivers/block/xen-blkback/blkback.c |  8 ++++++++
 drivers/block/xen-blkback/xenbus.c  | 36 ++++++++++++++++++++++++++++++------
 2 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/drivers/block/xen-blkback/blkback.c 
b/drivers/block/xen-blkback/blkback.c
index 0969e7e..34d72b0 100644
--- a/drivers/block/xen-blkback/blkback.c
+++ b/drivers/block/xen-blkback/blkback.c
@@ -80,6 +80,11 @@ module_param_named(max_persistent_grants, 
xen_blkif_max_pgrants, int, 0644);
 MODULE_PARM_DESC(max_persistent_grants,
                  "Maximum number of grants to map persistently");
 
+unsigned int xenblk_max_queues;
+module_param_named(max_queues, xenblk_max_queues, uint, 0644);
+MODULE_PARM_DESC(max_queues,
+                "Maximum number of hardware queues per virtual disk");
+
 /*
  * The LRU mechanism to clean the lists of persistent grants needs to
  * be executed periodically. The time interval between consecutive executions
@@ -1390,6 +1395,9 @@ static int __init xen_blkif_init(void)
        if (!xen_domain())
                return -ENODEV;
 
+       /* Allow as many queues as there are CPUs, by default */
+       xenblk_max_queues = num_online_cpus();
+
        rc = xen_blkif_interface_init();
        if (rc)
                goto failed_init;
diff --git a/drivers/block/xen-blkback/xenbus.c 
b/drivers/block/xen-blkback/xenbus.c
index 93e5f38..c33d8c9 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -21,6 +21,8 @@
 #include <xen/grant_table.h>
 #include "common.h"
 
+extern unsigned int xenblk_max_queues;
+
 struct backend_info {
        struct xenbus_device    *dev;
        struct xen_blkif        *blkif;
@@ -225,12 +227,6 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid)
        atomic_set(&blkif->drain, 0);
        INIT_WORK(&blkif->free_work, xen_blkif_deferred_free);
 
-       blkif->nr_rings = 1;
-       if (xen_blkif_alloc_rings(blkif)) {
-               kmem_cache_free(xen_blkif_cachep, blkif);
-               return ERR_PTR(-ENOMEM);
-       }
-
        return blkif;
 }
 
@@ -647,6 +643,14 @@ static int xen_blkbk_probe(struct xenbus_device *dev,
                goto fail;
        }
 
+       /* Multi-queue support: This is an optional feature. */
+       err = xenbus_printf(XBT_NIL, dev->nodename,
+                           "multi-queue-max-queues", "%u", xenblk_max_queues);
+       if (err) {
+               pr_debug("Error writing multi-queue-num-queues\n");
+               goto fail;
+       }
+
        /* setup back pointer */
        be->blkif->be = be;
 
@@ -927,6 +931,7 @@ static int connect_ring(struct backend_info *be)
        char *xspath;
        size_t xspathsize;
        const size_t xenstore_path_ext_size = 11; /* sufficient for 
"/queue-NNN" */
+       unsigned int requested_num_queues = 0;
 
        DPRINTK("%s", dev->otherend);
 
@@ -954,6 +959,25 @@ static int connect_ring(struct backend_info *be)
        be->blkif->vbd.feature_gnt_persistent = pers_grants;
        be->blkif->vbd.overflow_max_grants = 0;
 
+       /*
+        * Read the number of hardware queus from frontend.
+        */
+       err = xenbus_scanf(XBT_NIL, dev->otherend, "multi-queue-num-queues", 
"%u", &requested_num_queues);
+       if (err < 0) {
+               requested_num_queues = 1;
+       } else {
+               if (requested_num_queues > xenblk_max_queues) {
+                       /* buggy or malicious guest */
+                       xenbus_dev_fatal(dev, err,
+                                       "guest requested %u queues, exceeding 
the maximum of %u.",
+                                       requested_num_queues, 
xenblk_max_queues);
+                       return -1;
+               }
+       }
+       be->blkif->nr_rings = requested_num_queues;
+       if (xen_blkif_alloc_rings(be->blkif))
+               return -ENOMEM;
+
        if (be->blkif->nr_rings == 1) {
                err = xenbus_gather(XBT_NIL, dev->otherend, "ring-ref", "%lu",
                                &ring_ref, "event-channel", "%u", &evtchn, 
NULL);
-- 
1.8.3.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.