aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/rbd.c
diff options
context:
space:
mode:
authorAlex Elder <elder@dreamhost.com>2012-02-07 13:03:37 -0500
committerAlex Elder <elder@dreamhost.com>2012-03-22 11:47:50 -0400
commit593a9e7b34fa62d703b473ae923a9681556cdf74 (patch)
tree966050a350368a6c622e45a3ddd7d4fe5f857d08 /drivers/block/rbd.c
parent00f1f36ffa29a6b8e0529770bce2a44585ab3af0 (diff)
rbd: small changes
Here is another set of small code tidy-ups: - Define SECTOR_SHIFT and SECTOR_SIZE, and use these symbolic names throughout. Tell the blk_queue system our physical block size, in the (unlikely) event we want to use something other than the default. - Delete the definition of struct rbd_info, which is never used. - Move the definition of dev_to_rbd() down in its source file, just above where it gets first used, and change its name to dev_to_rbd_dev(). - Replace an open-coded operation in rbd_dev_release() to use dev_to_rbd_dev() instead. - Calculate the segment size for a given rbd_device just once in rbd_init_disk(). - Use the '%zd' conversion specifier in rbd_snap_size_show(), since the value formatted is a size_t. - Switch to the '%llu' conversion specifier in rbd_snap_id_show(). since the value formatted is unsigned. Signed-off-by: Alex Elder <elder@dreamhost.com>
Diffstat (limited to 'drivers/block/rbd.c')
-rw-r--r--drivers/block/rbd.c85
1 files changed, 52 insertions, 33 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index a42b28e7f3fa..568fa5b1206b 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -41,6 +41,15 @@
41 41
42#include "rbd_types.h" 42#include "rbd_types.h"
43 43
44/*
45 * The basic unit of block I/O is a sector. It is interpreted in a
46 * number of contexts in Linux (blk, bio, genhd), but the default is
47 * universally 512 bytes. These symbols are just slightly more
48 * meaningful than the bare numbers they represent.
49 */
50#define SECTOR_SHIFT 9
51#define SECTOR_SIZE (1ULL << SECTOR_SHIFT)
52
44#define RBD_DRV_NAME "rbd" 53#define RBD_DRV_NAME "rbd"
45#define RBD_DRV_NAME_LONG "rbd (rados block device)" 54#define RBD_DRV_NAME_LONG "rbd (rados block device)"
46 55
@@ -221,11 +230,6 @@ static struct device rbd_root_dev = {
221}; 230};
222 231
223 232
224static struct rbd_device *dev_to_rbd(struct device *dev)
225{
226 return container_of(dev, struct rbd_device, dev);
227}
228
229static struct device *rbd_get_dev(struct rbd_device *rbd_dev) 233static struct device *rbd_get_dev(struct rbd_device *rbd_dev)
230{ 234{
231 return get_device(&rbd_dev->dev); 235 return get_device(&rbd_dev->dev);
@@ -743,7 +747,7 @@ static struct bio *bio_chain_clone(struct bio **old, struct bio **next,
743 747
744 /* split the bio. We'll release it either in the next 748 /* split the bio. We'll release it either in the next
745 call, or it will have to be released outside */ 749 call, or it will have to be released outside */
746 bp = bio_split(old_chain, (len - total) / 512ULL); 750 bp = bio_split(old_chain, (len - total) / SECTOR_SIZE);
747 if (!bp) 751 if (!bp)
748 goto err_out; 752 goto err_out;
749 753
@@ -1471,7 +1475,7 @@ static void rbd_rq_fn(struct request_queue *q)
1471 do_write = (rq_data_dir(rq) == WRITE); 1475 do_write = (rq_data_dir(rq) == WRITE);
1472 1476
1473 size = blk_rq_bytes(rq); 1477 size = blk_rq_bytes(rq);
1474 ofs = blk_rq_pos(rq) * 512ULL; 1478 ofs = blk_rq_pos(rq) * SECTOR_SIZE;
1475 rq_bio = rq->bio; 1479 rq_bio = rq->bio;
1476 if (do_write && rbd_dev->read_only) { 1480 if (do_write && rbd_dev->read_only) {
1477 __blk_end_request_all(rq, -EROFS); 1481 __blk_end_request_all(rq, -EROFS);
@@ -1482,7 +1486,7 @@ static void rbd_rq_fn(struct request_queue *q)
1482 1486
1483 dout("%s 0x%x bytes at 0x%llx\n", 1487 dout("%s 0x%x bytes at 0x%llx\n",
1484 do_write ? "write" : "read", 1488 do_write ? "write" : "read",
1485 size, blk_rq_pos(rq) * 512ULL); 1489 size, blk_rq_pos(rq) * SECTOR_SIZE);
1486 1490
1487 num_segs = rbd_get_num_segments(&rbd_dev->header, ofs, size); 1491 num_segs = rbd_get_num_segments(&rbd_dev->header, ofs, size);
1488 coll = rbd_alloc_coll(num_segs); 1492 coll = rbd_alloc_coll(num_segs);
@@ -1547,13 +1551,17 @@ static int rbd_merge_bvec(struct request_queue *q, struct bvec_merge_data *bmd,
1547 struct bio_vec *bvec) 1551 struct bio_vec *bvec)
1548{ 1552{
1549 struct rbd_device *rbd_dev = q->queuedata; 1553 struct rbd_device *rbd_dev = q->queuedata;
1550 unsigned int chunk_sectors = 1 << (rbd_dev->header.obj_order - 9); 1554 unsigned int chunk_sectors;
1551 sector_t sector = bmd->bi_sector + get_start_sect(bmd->bi_bdev); 1555 sector_t sector;
1552 unsigned int bio_sectors = bmd->bi_size >> 9; 1556 unsigned int bio_sectors;
1553 int max; 1557 int max;
1554 1558
1559 chunk_sectors = 1 << (rbd_dev->header.obj_order - SECTOR_SHIFT);
1560 sector = bmd->bi_sector + get_start_sect(bmd->bi_bdev);
1561 bio_sectors = bmd->bi_size >> SECTOR_SHIFT;
1562
1555 max = (chunk_sectors - ((sector & (chunk_sectors - 1)) 1563 max = (chunk_sectors - ((sector & (chunk_sectors - 1))
1556 + bio_sectors)) << 9; 1564 + bio_sectors)) << SECTOR_SHIFT;
1557 if (max < 0) 1565 if (max < 0)
1558 max = 0; /* bio_add cannot handle a negative return */ 1566 max = 0; /* bio_add cannot handle a negative return */
1559 if (max <= bvec->bv_len && bio_sectors == 0) 1567 if (max <= bvec->bv_len && bio_sectors == 0)
@@ -1708,7 +1716,7 @@ static int __rbd_update_snaps(struct rbd_device *rbd_dev)
1708 return ret; 1716 return ret;
1709 1717
1710 /* resized? */ 1718 /* resized? */
1711 set_capacity(rbd_dev->disk, h.image_size / 512ULL); 1719 set_capacity(rbd_dev->disk, h.image_size / SECTOR_SIZE);
1712 1720
1713 down_write(&rbd_dev->header.snap_rwsem); 1721 down_write(&rbd_dev->header.snap_rwsem);
1714 1722
@@ -1745,6 +1753,7 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
1745 struct gendisk *disk; 1753 struct gendisk *disk;
1746 struct request_queue *q; 1754 struct request_queue *q;
1747 int rc; 1755 int rc;
1756 u64 segment_size;
1748 u64 total_size = 0; 1757 u64 total_size = 0;
1749 1758
1750 /* contact OSD, request size info about the object being mapped */ 1759 /* contact OSD, request size info about the object being mapped */
@@ -1780,11 +1789,15 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
1780 if (!q) 1789 if (!q)
1781 goto out_disk; 1790 goto out_disk;
1782 1791
1792 /* We use the default size, but let's be explicit about it. */
1793 blk_queue_physical_block_size(q, SECTOR_SIZE);
1794
1783 /* set io sizes to object size */ 1795 /* set io sizes to object size */
1784 blk_queue_max_hw_sectors(q, rbd_obj_bytes(&rbd_dev->header) / 512ULL); 1796 segment_size = rbd_obj_bytes(&rbd_dev->header);
1785 blk_queue_max_segment_size(q, rbd_obj_bytes(&rbd_dev->header)); 1797 blk_queue_max_hw_sectors(q, segment_size / SECTOR_SIZE);
1786 blk_queue_io_min(q, rbd_obj_bytes(&rbd_dev->header)); 1798 blk_queue_max_segment_size(q, segment_size);
1787 blk_queue_io_opt(q, rbd_obj_bytes(&rbd_dev->header)); 1799 blk_queue_io_min(q, segment_size);
1800 blk_queue_io_opt(q, segment_size);
1788 1801
1789 blk_queue_merge_bvec(q, rbd_merge_bvec); 1802 blk_queue_merge_bvec(q, rbd_merge_bvec);
1790 disk->queue = q; 1803 disk->queue = q;
@@ -1795,7 +1808,7 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
1795 rbd_dev->q = q; 1808 rbd_dev->q = q;
1796 1809
1797 /* finally, announce the disk to the world */ 1810 /* finally, announce the disk to the world */
1798 set_capacity(disk, total_size / 512ULL); 1811 set_capacity(disk, total_size / SECTOR_SIZE);
1799 add_disk(disk); 1812 add_disk(disk);
1800 1813
1801 pr_info("%s: added with size 0x%llx\n", 1814 pr_info("%s: added with size 0x%llx\n",
@@ -1812,10 +1825,15 @@ out:
1812 sysfs 1825 sysfs
1813*/ 1826*/
1814 1827
1828static struct rbd_device *dev_to_rbd_dev(struct device *dev)
1829{
1830 return container_of(dev, struct rbd_device, dev);
1831}
1832
1815static ssize_t rbd_size_show(struct device *dev, 1833static ssize_t rbd_size_show(struct device *dev,
1816 struct device_attribute *attr, char *buf) 1834 struct device_attribute *attr, char *buf)
1817{ 1835{
1818 struct rbd_device *rbd_dev = dev_to_rbd(dev); 1836 struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
1819 1837
1820 return sprintf(buf, "%llu\n", (unsigned long long)rbd_dev->header.image_size); 1838 return sprintf(buf, "%llu\n", (unsigned long long)rbd_dev->header.image_size);
1821} 1839}
@@ -1823,7 +1841,7 @@ static ssize_t rbd_size_show(struct device *dev,
1823static ssize_t rbd_major_show(struct device *dev, 1841static ssize_t rbd_major_show(struct device *dev,
1824 struct device_attribute *attr, char *buf) 1842 struct device_attribute *attr, char *buf)
1825{ 1843{
1826 struct rbd_device *rbd_dev = dev_to_rbd(dev); 1844 struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
1827 1845
1828 return sprintf(buf, "%d\n", rbd_dev->major); 1846 return sprintf(buf, "%d\n", rbd_dev->major);
1829} 1847}
@@ -1831,7 +1849,7 @@ static ssize_t rbd_major_show(struct device *dev,
1831static ssize_t rbd_client_id_show(struct device *dev, 1849static ssize_t rbd_client_id_show(struct device *dev,
1832 struct device_attribute *attr, char *buf) 1850 struct device_attribute *attr, char *buf)
1833{ 1851{
1834 struct rbd_device *rbd_dev = dev_to_rbd(dev); 1852 struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
1835 1853
1836 return sprintf(buf, "client%lld\n", 1854 return sprintf(buf, "client%lld\n",
1837 ceph_client_id(rbd_dev->rbd_client->client)); 1855 ceph_client_id(rbd_dev->rbd_client->client));
@@ -1840,7 +1858,7 @@ static ssize_t rbd_client_id_show(struct device *dev,
1840static ssize_t rbd_pool_show(struct device *dev, 1858static ssize_t rbd_pool_show(struct device *dev,
1841 struct device_attribute *attr, char *buf) 1859 struct device_attribute *attr, char *buf)
1842{ 1860{
1843 struct rbd_device *rbd_dev = dev_to_rbd(dev); 1861 struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
1844 1862
1845 return sprintf(buf, "%s\n", rbd_dev->pool_name); 1863 return sprintf(buf, "%s\n", rbd_dev->pool_name);
1846} 1864}
@@ -1848,7 +1866,7 @@ static ssize_t rbd_pool_show(struct device *dev,
1848static ssize_t rbd_name_show(struct device *dev, 1866static ssize_t rbd_name_show(struct device *dev,
1849 struct device_attribute *attr, char *buf) 1867 struct device_attribute *attr, char *buf)
1850{ 1868{
1851 struct rbd_device *rbd_dev = dev_to_rbd(dev); 1869 struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
1852 1870
1853 return sprintf(buf, "%s\n", rbd_dev->obj); 1871 return sprintf(buf, "%s\n", rbd_dev->obj);
1854} 1872}
@@ -1857,7 +1875,7 @@ static ssize_t rbd_snap_show(struct device *dev,
1857 struct device_attribute *attr, 1875 struct device_attribute *attr,
1858 char *buf) 1876 char *buf)
1859{ 1877{
1860 struct rbd_device *rbd_dev = dev_to_rbd(dev); 1878 struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
1861 1879
1862 return sprintf(buf, "%s\n", rbd_dev->snap_name); 1880 return sprintf(buf, "%s\n", rbd_dev->snap_name);
1863} 1881}
@@ -1867,7 +1885,7 @@ static ssize_t rbd_image_refresh(struct device *dev,
1867 const char *buf, 1885 const char *buf,
1868 size_t size) 1886 size_t size)
1869{ 1887{
1870 struct rbd_device *rbd_dev = dev_to_rbd(dev); 1888 struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
1871 int rc; 1889 int rc;
1872 int ret = size; 1890 int ret = size;
1873 1891
@@ -1932,7 +1950,7 @@ static ssize_t rbd_snap_size_show(struct device *dev,
1932{ 1950{
1933 struct rbd_snap *snap = container_of(dev, struct rbd_snap, dev); 1951 struct rbd_snap *snap = container_of(dev, struct rbd_snap, dev);
1934 1952
1935 return sprintf(buf, "%lld\n", (long long)snap->size); 1953 return sprintf(buf, "%zd\n", snap->size);
1936} 1954}
1937 1955
1938static ssize_t rbd_snap_id_show(struct device *dev, 1956static ssize_t rbd_snap_id_show(struct device *dev,
@@ -1941,7 +1959,7 @@ static ssize_t rbd_snap_id_show(struct device *dev,
1941{ 1959{
1942 struct rbd_snap *snap = container_of(dev, struct rbd_snap, dev); 1960 struct rbd_snap *snap = container_of(dev, struct rbd_snap, dev);
1943 1961
1944 return sprintf(buf, "%lld\n", (long long)snap->id); 1962 return sprintf(buf, "%llu\n", (unsigned long long) snap->id);
1945} 1963}
1946 1964
1947static DEVICE_ATTR(snap_size, S_IRUGO, rbd_snap_size_show, NULL); 1965static DEVICE_ATTR(snap_size, S_IRUGO, rbd_snap_size_show, NULL);
@@ -2232,7 +2250,8 @@ static void rbd_id_put(struct rbd_device *rbd_dev)
2232/* 2250/*
2233 * Skips over white space at *buf, and updates *buf to point to the 2251 * Skips over white space at *buf, and updates *buf to point to the
2234 * first found non-space character (if any). Returns the length of 2252 * first found non-space character (if any). Returns the length of
2235 * the token (string of non-white space characters) found. 2253 * the token (string of non-white space characters) found. Note
2254 * that *buf must be terminated with '\0'.
2236 */ 2255 */
2237static inline size_t next_token(const char **buf) 2256static inline size_t next_token(const char **buf)
2238{ 2257{
@@ -2250,13 +2269,14 @@ static inline size_t next_token(const char **buf)
2250/* 2269/*
2251 * Finds the next token in *buf, and if the provided token buffer is 2270 * Finds the next token in *buf, and if the provided token buffer is
2252 * big enough, copies the found token into it. The result, if 2271 * big enough, copies the found token into it. The result, if
2253 * copied, is guaranteed to be terminated with '\0'. 2272 * copied, is guaranteed to be terminated with '\0'. Note that *buf
2273 * must be terminated with '\0' on entry.
2254 * 2274 *
2255 * Returns the length of the token found (not including the '\0'). 2275 * Returns the length of the token found (not including the '\0').
2256 * Return value will be 0 if no token is found, and it will be >= 2276 * Return value will be 0 if no token is found, and it will be >=
2257 * token_size if the token would not fit. 2277 * token_size if the token would not fit.
2258 * 2278 *
2259 * The *buf pointer will be updated point beyond the end of the 2279 * The *buf pointer will be updated to point beyond the end of the
2260 * found token. Note that this occurs even if the token buffer is 2280 * found token. Note that this occurs even if the token buffer is
2261 * too small to hold it. 2281 * too small to hold it.
2262 */ 2282 */
@@ -2456,8 +2476,7 @@ static struct rbd_device *__rbd_get_dev(unsigned long id)
2456 2476
2457static void rbd_dev_release(struct device *dev) 2477static void rbd_dev_release(struct device *dev)
2458{ 2478{
2459 struct rbd_device *rbd_dev = 2479 struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
2460 container_of(dev, struct rbd_device, dev);
2461 2480
2462 if (rbd_dev->watch_request) { 2481 if (rbd_dev->watch_request) {
2463 struct ceph_client *client = rbd_dev->rbd_client->client; 2482 struct ceph_client *client = rbd_dev->rbd_client->client;
@@ -2520,7 +2539,7 @@ static ssize_t rbd_snap_add(struct device *dev,
2520 const char *buf, 2539 const char *buf,
2521 size_t count) 2540 size_t count)
2522{ 2541{
2523 struct rbd_device *rbd_dev = dev_to_rbd(dev); 2542 struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
2524 int ret; 2543 int ret;
2525 char *name = kmalloc(count + 1, GFP_KERNEL); 2544 char *name = kmalloc(count + 1, GFP_KERNEL);
2526 if (!name) 2545 if (!name)