diff options
author | Juergen Gross <jgross@suse.com> | 2016-10-31 09:58:40 -0400 |
---|---|---|
committer | Juergen Gross <jgross@suse.com> | 2016-11-07 07:55:09 -0500 |
commit | f27dc1ac56865c2cc43d0ec3110a2b4a95b04e1d (patch) | |
tree | 2459ab90258257b0bc58d8263960ca7f53988774 /drivers/block | |
parent | 8235777b2068e3280b6fa1413f1940ade31f0adf (diff) |
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: Juergen Gross <jgross@suse.com>
Acked-by: David Vrabel <david.vrabel@citrix.com>
Diffstat (limited to 'drivers/block')
-rw-r--r-- | drivers/block/xen-blkfront.c | 81 |
1 files changed, 26 insertions, 55 deletions
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 9908597c5209..2ee9646d8a5f 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c | |||
@@ -1758,17 +1758,13 @@ static int talk_to_blkback(struct xenbus_device *dev, | |||
1758 | const char *message = NULL; | 1758 | const char *message = NULL; |
1759 | struct xenbus_transaction xbt; | 1759 | struct xenbus_transaction xbt; |
1760 | int err; | 1760 | int err; |
1761 | unsigned int i, max_page_order = 0; | 1761 | unsigned int i, max_page_order; |
1762 | unsigned int ring_page_order = 0; | 1762 | unsigned int ring_page_order; |
1763 | 1763 | ||
1764 | err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, | 1764 | max_page_order = xenbus_read_unsigned(info->xbdev->otherend, |
1765 | "max-ring-page-order", "%u", &max_page_order); | 1765 | "max-ring-page-order", 0); |
1766 | if (err != 1) | 1766 | ring_page_order = min(xen_blkif_max_ring_order, max_page_order); |
1767 | info->nr_ring_pages = 1; | 1767 | info->nr_ring_pages = 1 << ring_page_order; |
1768 | else { | ||
1769 | ring_page_order = min(xen_blkif_max_ring_order, max_page_order); | ||
1770 | info->nr_ring_pages = 1 << ring_page_order; | ||
1771 | } | ||
1772 | 1768 | ||
1773 | for (i = 0; i < info->nr_rings; i++) { | 1769 | for (i = 0; i < info->nr_rings; i++) { |
1774 | struct blkfront_ring_info *rinfo = &info->rinfo[i]; | 1770 | struct blkfront_ring_info *rinfo = &info->rinfo[i]; |
@@ -1877,18 +1873,14 @@ again: | |||
1877 | 1873 | ||
1878 | static int negotiate_mq(struct blkfront_info *info) | 1874 | static int negotiate_mq(struct blkfront_info *info) |
1879 | { | 1875 | { |
1880 | unsigned int backend_max_queues = 0; | 1876 | unsigned int backend_max_queues; |
1881 | int err; | ||
1882 | unsigned int i; | 1877 | unsigned int i; |
1883 | 1878 | ||
1884 | BUG_ON(info->nr_rings); | 1879 | BUG_ON(info->nr_rings); |
1885 | 1880 | ||
1886 | /* Check if backend supports multiple queues. */ | 1881 | /* Check if backend supports multiple queues. */ |
1887 | err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, | 1882 | backend_max_queues = xenbus_read_unsigned(info->xbdev->otherend, |
1888 | "multi-queue-max-queues", "%u", &backend_max_queues); | 1883 | "multi-queue-max-queues", 1); |
1889 | if (err < 0) | ||
1890 | backend_max_queues = 1; | ||
1891 | |||
1892 | info->nr_rings = min(backend_max_queues, xen_blkif_max_queues); | 1884 | info->nr_rings = min(backend_max_queues, xen_blkif_max_queues); |
1893 | /* We need at least one ring. */ | 1885 | /* We need at least one ring. */ |
1894 | if (!info->nr_rings) | 1886 | if (!info->nr_rings) |
@@ -2195,7 +2187,6 @@ static void blkfront_setup_discard(struct blkfront_info *info) | |||
2195 | int err; | 2187 | int err; |
2196 | unsigned int discard_granularity; | 2188 | unsigned int discard_granularity; |
2197 | unsigned int discard_alignment; | 2189 | unsigned int discard_alignment; |
2198 | unsigned int discard_secure; | ||
2199 | 2190 | ||
2200 | info->feature_discard = 1; | 2191 | info->feature_discard = 1; |
2201 | err = xenbus_gather(XBT_NIL, info->xbdev->otherend, | 2192 | err = xenbus_gather(XBT_NIL, info->xbdev->otherend, |
@@ -2206,10 +2197,9 @@ static void blkfront_setup_discard(struct blkfront_info *info) | |||
2206 | info->discard_granularity = discard_granularity; | 2197 | info->discard_granularity = discard_granularity; |
2207 | info->discard_alignment = discard_alignment; | 2198 | info->discard_alignment = discard_alignment; |
2208 | } | 2199 | } |
2209 | err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, | 2200 | info->feature_secdiscard = |
2210 | "discard-secure", "%u", &discard_secure); | 2201 | !!xenbus_read_unsigned(info->xbdev->otherend, "discard-secure", |
2211 | if (err > 0) | 2202 | 0); |
2212 | info->feature_secdiscard = !!discard_secure; | ||
2213 | } | 2203 | } |
2214 | 2204 | ||
2215 | static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo) | 2205 | static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo) |
@@ -2301,16 +2291,11 @@ out_of_memory: | |||
2301 | */ | 2291 | */ |
2302 | static void blkfront_gather_backend_features(struct blkfront_info *info) | 2292 | static void blkfront_gather_backend_features(struct blkfront_info *info) |
2303 | { | 2293 | { |
2304 | int err; | ||
2305 | int barrier, flush, discard, persistent; | ||
2306 | unsigned int indirect_segments; | 2294 | unsigned int indirect_segments; |
2307 | 2295 | ||
2308 | info->feature_flush = 0; | 2296 | info->feature_flush = 0; |
2309 | info->feature_fua = 0; | 2297 | info->feature_fua = 0; |
2310 | 2298 | ||
2311 | err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, | ||
2312 | "feature-barrier", "%d", &barrier); | ||
2313 | |||
2314 | /* | 2299 | /* |
2315 | * If there's no "feature-barrier" defined, then it means | 2300 | * If there's no "feature-barrier" defined, then it means |
2316 | * we're dealing with a very old backend which writes | 2301 | * 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 | * | 2303 | * |
2319 | * If there are barriers, then we use flush. | 2304 | * If there are barriers, then we use flush. |
2320 | */ | 2305 | */ |
2321 | if (err > 0 && barrier) { | 2306 | if (xenbus_read_unsigned(info->xbdev->otherend, "feature-barrier", 0)) { |
2322 | info->feature_flush = 1; | 2307 | info->feature_flush = 1; |
2323 | info->feature_fua = 1; | 2308 | info->feature_fua = 1; |
2324 | } | 2309 | } |
@@ -2327,35 +2312,23 @@ static void blkfront_gather_backend_features(struct blkfront_info *info) | |||
2327 | * And if there is "feature-flush-cache" use that above | 2312 | * And if there is "feature-flush-cache" use that above |
2328 | * barriers. | 2313 | * barriers. |
2329 | */ | 2314 | */ |
2330 | err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, | 2315 | if (xenbus_read_unsigned(info->xbdev->otherend, "feature-flush-cache", |
2331 | "feature-flush-cache", "%d", &flush); | 2316 | 0)) { |
2332 | |||
2333 | if (err > 0 && flush) { | ||
2334 | info->feature_flush = 1; | 2317 | info->feature_flush = 1; |
2335 | info->feature_fua = 0; | 2318 | info->feature_fua = 0; |
2336 | } | 2319 | } |
2337 | 2320 | ||
2338 | err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, | 2321 | if (xenbus_read_unsigned(info->xbdev->otherend, "feature-discard", 0)) |
2339 | "feature-discard", "%d", &discard); | ||
2340 | |||
2341 | if (err > 0 && discard) | ||
2342 | blkfront_setup_discard(info); | 2322 | blkfront_setup_discard(info); |
2343 | 2323 | ||
2344 | err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, | 2324 | info->feature_persistent = |
2345 | "feature-persistent", "%d", &persistent); | 2325 | xenbus_read_unsigned(info->xbdev->otherend, |
2346 | if (err <= 0) | 2326 | "feature-persistent", 0); |
2347 | info->feature_persistent = 0; | ||
2348 | else | ||
2349 | info->feature_persistent = persistent; | ||
2350 | 2327 | ||
2351 | err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, | 2328 | indirect_segments = xenbus_read_unsigned(info->xbdev->otherend, |
2352 | "feature-max-indirect-segments", "%u", | 2329 | "feature-max-indirect-segments", 0); |
2353 | &indirect_segments); | 2330 | info->max_indirect_segments = min(indirect_segments, |
2354 | if (err <= 0) | 2331 | xen_blkif_max_segments); |
2355 | info->max_indirect_segments = 0; | ||
2356 | else | ||
2357 | info->max_indirect_segments = min(indirect_segments, | ||
2358 | xen_blkif_max_segments); | ||
2359 | } | 2332 | } |
2360 | 2333 | ||
2361 | /* | 2334 | /* |
@@ -2420,11 +2393,9 @@ static void blkfront_connect(struct blkfront_info *info) | |||
2420 | * provide this. Assume physical sector size to be the same as | 2393 | * provide this. Assume physical sector size to be the same as |
2421 | * sector_size in that case. | 2394 | * sector_size in that case. |
2422 | */ | 2395 | */ |
2423 | err = xenbus_scanf(XBT_NIL, info->xbdev->otherend, | 2396 | physical_sector_size = xenbus_read_unsigned(info->xbdev->otherend, |
2424 | "physical-sector-size", "%u", &physical_sector_size); | 2397 | "physical-sector-size", |
2425 | if (err != 1) | 2398 | sector_size); |
2426 | physical_sector_size = sector_size; | ||
2427 | |||
2428 | blkfront_gather_backend_features(info); | 2399 | blkfront_gather_backend_features(info); |
2429 | for (i = 0; i < info->nr_rings; i++) { | 2400 | for (i = 0; i < info->nr_rings; i++) { |
2430 | err = blkfront_setup_indirect(&info->rinfo[i]); | 2401 | err = blkfront_setup_indirect(&info->rinfo[i]); |