]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
xen: make use of xenbus_read_unsigned() in xen-blkfront
authorJuergen Gross <jgross@suse.com>
Mon, 31 Oct 2016 13:58:40 +0000 (14:58 +0100)
committerBoris Ostrovsky <boris.ostrovsky@oracle.com>
Fri, 3 Feb 2017 20:55:27 +0000 (15:55 -0500)
Use xenbus_read_unsigned() instead of xenbus_scanf() when possible.
This requires to change the type of some reads from int to unsigned,
but these cases have been wrong before: negative values are not allowed
for the modified cases.

Cc: konrad.wilk@oracle.com
Cc: roger.pau@citrix.com
Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: David Vrabel <david.vrabel@citrix.com>
OraBug: 25497392

(cherry picked from commit f27dc1ac56865c2cc43d0ec3110a2b4a95b04e1d)
Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Conflicts:
drivers/block/xen-blkfront.c

drivers/block/xen-blkfront.c

index e86b2ffd5a1e2529400aaa7a68caab7af3a8da9d..89a9dfaade94a9637fe510fa03d56e21e0de482d 100644 (file)
@@ -1793,21 +1793,17 @@ static int talk_to_blkback(struct xenbus_device *dev,
        const char *message = NULL;
        struct xenbus_transaction xbt;
        int err;
-       unsigned int i, max_page_order = 0;
-       unsigned int ring_page_order = 0;
+       unsigned int i, max_page_order;
+       unsigned int ring_page_order;
 
-       err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
-                          "max-ring-page-order", "%u", &max_page_order);
-       if (err != 1)
-               info->nr_ring_pages = 1;
-       else {
-               ring_page_order = min(xen_blkif_max_ring_order, max_page_order);
-               if (info->new_max_ring_page_order) {
-                       BUG_ON(info->new_max_ring_page_order > max_page_order);
-                       ring_page_order = info->new_max_ring_page_order;
-               }
-               info->nr_ring_pages = 1 << ring_page_order;
+       max_page_order = xenbus_read_unsigned(info->xbdev->otherend,
+                                             "max-ring-page-order", 0);
+       ring_page_order = min(xen_blkif_max_ring_order, max_page_order);
+       if (info->new_max_ring_page_order) {
+               BUG_ON(info->new_max_ring_page_order > max_page_order);
+               ring_page_order = info->new_max_ring_page_order;
        }
+       info->nr_ring_pages = 1 << ring_page_order;
 
        for (i = 0; i < info->nr_rings; i++) {
                struct blkfront_ring_info *rinfo = &info->rinfo[i];
@@ -1916,18 +1912,14 @@ again:
 
 static int negotiate_mq(struct blkfront_info *info)
 {
-       unsigned int backend_max_queues = 0;
-       int err;
+       unsigned int backend_max_queues;
        unsigned int i;
 
        BUG_ON(info->nr_rings);
 
        /* Check if backend supports multiple queues. */
-       err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
-                          "multi-queue-max-queues", "%u", &backend_max_queues);
-       if (err < 0)
-               backend_max_queues = 1;
-
+       backend_max_queues = xenbus_read_unsigned(info->xbdev->otherend,
+                                                 "multi-queue-max-queues", 1);
        info->nr_rings = min(backend_max_queues, xen_blkif_max_queues);
        if (info->new_max_queues) {
                BUG_ON(info->new_max_queues > backend_max_queues);
@@ -2235,7 +2227,6 @@ static void blkfront_setup_discard(struct blkfront_info *info)
        int err;
        unsigned int discard_granularity;
        unsigned int discard_alignment;
-       unsigned int discard_secure;
 
        info->feature_discard = 1;
        err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
@@ -2246,10 +2237,9 @@ static void blkfront_setup_discard(struct blkfront_info *info)
                info->discard_granularity = discard_granularity;
                info->discard_alignment = discard_alignment;
        }
-       err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
-                          "discard-secure", "%u", &discard_secure);
-       if (err > 0)
-               info->feature_secdiscard = !!discard_secure;
+       info->feature_secdiscard =
+               !!xenbus_read_unsigned(info->xbdev->otherend, "discard-secure",
+                                      0);
 }
 
 static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo)
@@ -2341,15 +2331,10 @@ out_of_memory:
  */
 static void blkfront_gather_backend_features(struct blkfront_info *info)
 {
-       int err;
-       int barrier, flush, discard, persistent;
        unsigned int indirect_segments;
 
        info->feature_flush = 0;
 
-       err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
-                          "feature-barrier", "%d", &barrier);
-
        /*
         * If there's no "feature-barrier" defined, then it means
         * we're dealing with a very old backend which writes
@@ -2357,43 +2342,30 @@ static void blkfront_gather_backend_features(struct blkfront_info *info)
         *
         * If there are barriers, then we use flush.
         */
-       if (err > 0 && barrier)
+       if (xenbus_read_unsigned(info->xbdev->otherend, "feature-barrier", 0))
                info->feature_flush = REQ_FLUSH | REQ_FUA;
+
        /*
         * And if there is "feature-flush-cache" use that above
         * barriers.
         */
-       err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
-                          "feature-flush-cache", "%d", &flush);
-
-       if (err > 0 && flush)
+       if (xenbus_read_unsigned(info->xbdev->otherend, "feature-flush-cache", 0))
                info->feature_flush = REQ_FLUSH;
 
-       err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
-                          "feature-discard", "%d", &discard);
-
-       if (err > 0 && discard)
+       if (xenbus_read_unsigned(info->xbdev->otherend, "feature-discard", 0))
                blkfront_setup_discard(info);
 
-       err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
-                          "feature-persistent", "%d", &persistent);
-       if (err <= 0)
-               info->feature_persistent = 0;
-       else
-               info->feature_persistent = persistent;
+       info->feature_persistent =
+               xenbus_read_unsigned(info->xbdev->otherend,
+                                    "feature-persistent", 0);
 
-       err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
-                          "feature-max-indirect-segments", "%u",
-                          &indirect_segments);
-       if (err <= 0)
-               info->max_indirect_segments = 0;
-       else {
-               info->max_indirect_segments = min(indirect_segments,
-                                                 xen_blkif_max_segments);
-               if (info->new_max_indirect_segments) {
-                       BUG_ON(info->new_max_indirect_segments > indirect_segments);
-                       info->max_indirect_segments = info->new_max_indirect_segments;
-               }
+       indirect_segments = xenbus_read_unsigned(info->xbdev->otherend,
+                                       "feature-max-indirect-segments", 0);
+       info->max_indirect_segments = min(indirect_segments,
+                                         xen_blkif_max_segments);
+       if (info->new_max_indirect_segments) {
+               BUG_ON(info->new_max_indirect_segments > indirect_segments);
+               info->max_indirect_segments = info->new_max_indirect_segments;
        }
 }
 
@@ -2670,11 +2642,9 @@ static void blkfront_connect(struct blkfront_info *info)
         * provide this. Assume physical sector size to be the same as
         * sector_size in that case.
         */
-       err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
-                          "physical-sector-size", "%u", &physical_sector_size);
-       if (err != 1)
-               physical_sector_size = sector_size;
-
+       physical_sector_size = xenbus_read_unsigned(info->xbdev->otherend,
+                                                   "physical-sector-size",
+                                                   sector_size);
        blkfront_gather_backend_features(info);
        for (i = 0; i < info->nr_rings; i++) {
                err = blkfront_setup_indirect(&info->rinfo[i]);