Commit f27dc1ac authored by Juergen Gross's avatar Juergen Gross

xen: make use of xenbus_read_unsigned() in xen-blkfront

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: default avatarJuergen Gross <jgross@suse.com>
Acked-by: default avatarDavid Vrabel <david.vrabel@citrix.com>
parent 8235777b
...@@ -1758,17 +1758,13 @@ static int talk_to_blkback(struct xenbus_device *dev, ...@@ -1758,17 +1758,13 @@ static int talk_to_blkback(struct xenbus_device *dev,
const char *message = NULL; const char *message = NULL;
struct xenbus_transaction xbt; struct xenbus_transaction xbt;
int err; int err;
unsigned int i, max_page_order = 0; unsigned int i, max_page_order;
unsigned int ring_page_order = 0; unsigned int ring_page_order;
err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, max_page_order = xenbus_read_unsigned(info->xbdev->otherend,
"max-ring-page-order", "%u", &max_page_order); "max-ring-page-order", 0);
if (err != 1) ring_page_order = min(xen_blkif_max_ring_order, max_page_order);
info->nr_ring_pages = 1; info->nr_ring_pages = 1 << ring_page_order;
else {
ring_page_order = min(xen_blkif_max_ring_order, max_page_order);
info->nr_ring_pages = 1 << ring_page_order;
}
for (i = 0; i < info->nr_rings; i++) { for (i = 0; i < info->nr_rings; i++) {
struct blkfront_ring_info *rinfo = &info->rinfo[i]; struct blkfront_ring_info *rinfo = &info->rinfo[i];
...@@ -1877,18 +1873,14 @@ static int talk_to_blkback(struct xenbus_device *dev, ...@@ -1877,18 +1873,14 @@ static int talk_to_blkback(struct xenbus_device *dev,
static int negotiate_mq(struct blkfront_info *info) static int negotiate_mq(struct blkfront_info *info)
{ {
unsigned int backend_max_queues = 0; unsigned int backend_max_queues;
int err;
unsigned int i; unsigned int i;
BUG_ON(info->nr_rings); BUG_ON(info->nr_rings);
/* Check if backend supports multiple queues. */ /* Check if backend supports multiple queues. */
err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, backend_max_queues = xenbus_read_unsigned(info->xbdev->otherend,
"multi-queue-max-queues", "%u", &backend_max_queues); "multi-queue-max-queues", 1);
if (err < 0)
backend_max_queues = 1;
info->nr_rings = min(backend_max_queues, xen_blkif_max_queues); info->nr_rings = min(backend_max_queues, xen_blkif_max_queues);
/* We need at least one ring. */ /* We need at least one ring. */
if (!info->nr_rings) if (!info->nr_rings)
...@@ -2195,7 +2187,6 @@ static void blkfront_setup_discard(struct blkfront_info *info) ...@@ -2195,7 +2187,6 @@ static void blkfront_setup_discard(struct blkfront_info *info)
int err; int err;
unsigned int discard_granularity; unsigned int discard_granularity;
unsigned int discard_alignment; unsigned int discard_alignment;
unsigned int discard_secure;
info->feature_discard = 1; info->feature_discard = 1;
err = xenbus_gather(XBT_NIL, info->xbdev->otherend, err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
...@@ -2206,10 +2197,9 @@ static void blkfront_setup_discard(struct blkfront_info *info) ...@@ -2206,10 +2197,9 @@ static void blkfront_setup_discard(struct blkfront_info *info)
info->discard_granularity = discard_granularity; info->discard_granularity = discard_granularity;
info->discard_alignment = discard_alignment; info->discard_alignment = discard_alignment;
} }
err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, info->feature_secdiscard =
"discard-secure", "%u", &discard_secure); !!xenbus_read_unsigned(info->xbdev->otherend, "discard-secure",
if (err > 0) 0);
info->feature_secdiscard = !!discard_secure;
} }
static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo) static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo)
...@@ -2301,16 +2291,11 @@ static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo) ...@@ -2301,16 +2291,11 @@ static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo)
*/ */
static void blkfront_gather_backend_features(struct blkfront_info *info) static void blkfront_gather_backend_features(struct blkfront_info *info)
{ {
int err;
int barrier, flush, discard, persistent;
unsigned int indirect_segments; unsigned int indirect_segments;
info->feature_flush = 0; info->feature_flush = 0;
info->feature_fua = 0; info->feature_fua = 0;
err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
"feature-barrier", "%d", &barrier);
/* /*
* If there's no "feature-barrier" defined, then it means * If there's no "feature-barrier" defined, then it means
* we're dealing with a very old backend which writes * we're dealing with a very old backend which writes
...@@ -2318,7 +2303,7 @@ static void blkfront_gather_backend_features(struct blkfront_info *info) ...@@ -2318,7 +2303,7 @@ static void blkfront_gather_backend_features(struct blkfront_info *info)
* *
* If there are barriers, then we use flush. * 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 = 1; info->feature_flush = 1;
info->feature_fua = 1; info->feature_fua = 1;
} }
...@@ -2327,35 +2312,23 @@ static void blkfront_gather_backend_features(struct blkfront_info *info) ...@@ -2327,35 +2312,23 @@ static void blkfront_gather_backend_features(struct blkfront_info *info)
* And if there is "feature-flush-cache" use that above * And if there is "feature-flush-cache" use that above
* barriers. * barriers.
*/ */
err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, if (xenbus_read_unsigned(info->xbdev->otherend, "feature-flush-cache",
"feature-flush-cache", "%d", &flush); 0)) {
if (err > 0 && flush) {
info->feature_flush = 1; info->feature_flush = 1;
info->feature_fua = 0; info->feature_fua = 0;
} }
err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, if (xenbus_read_unsigned(info->xbdev->otherend, "feature-discard", 0))
"feature-discard", "%d", &discard);
if (err > 0 && discard)
blkfront_setup_discard(info); blkfront_setup_discard(info);
err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, info->feature_persistent =
"feature-persistent", "%d", &persistent); xenbus_read_unsigned(info->xbdev->otherend,
if (err <= 0) "feature-persistent", 0);
info->feature_persistent = 0;
else
info->feature_persistent = persistent;
err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, indirect_segments = xenbus_read_unsigned(info->xbdev->otherend,
"feature-max-indirect-segments", "%u", "feature-max-indirect-segments", 0);
&indirect_segments); info->max_indirect_segments = min(indirect_segments,
if (err <= 0) xen_blkif_max_segments);
info->max_indirect_segments = 0;
else
info->max_indirect_segments = min(indirect_segments,
xen_blkif_max_segments);
} }
/* /*
...@@ -2420,11 +2393,9 @@ static void blkfront_connect(struct blkfront_info *info) ...@@ -2420,11 +2393,9 @@ static void blkfront_connect(struct blkfront_info *info)
* provide this. Assume physical sector size to be the same as * provide this. Assume physical sector size to be the same as
* sector_size in that case. * sector_size in that case.
*/ */
err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, physical_sector_size = xenbus_read_unsigned(info->xbdev->otherend,
"physical-sector-size", "%u", &physical_sector_size); "physical-sector-size",
if (err != 1) sector_size);
physical_sector_size = sector_size;
blkfront_gather_backend_features(info); blkfront_gather_backend_features(info);
for (i = 0; i < info->nr_rings; i++) { for (i = 0; i < info->nr_rings; i++) {
err = blkfront_setup_indirect(&info->rinfo[i]); err = blkfront_setup_indirect(&info->rinfo[i]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment