aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/rbd.c
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2012-07-25 10:32:41 -0400
committerSage Weil <sage@inktank.com>2012-07-30 21:21:46 -0400
commitb813623ab95d0b4bbeb22e160bd5461965d0c571 (patch)
treea40f3cc64c62b7ab643167a72c2789b7561b06b8 /drivers/block/rbd.c
parentccece235d3737221e7a1118fdbd8474112adac84 (diff)
rbd: return obj version in __rbd_refresh_header()
Add a new parameter to __rbd_refresh_header() through which the version of the header object is passed back to the caller. In most cases this isn't needed. The main motivation is to normalize (almost) all calls to __rbd_refresh_header() so they are all wrapped immediately by mutex_lock()/mutex_unlock(). Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Diffstat (limited to 'drivers/block/rbd.c')
-rw-r--r--drivers/block/rbd.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 34676937d2d2..de981ac72362 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -240,7 +240,7 @@ static void rbd_put_dev(struct rbd_device *rbd_dev)
240 put_device(&rbd_dev->dev); 240 put_device(&rbd_dev->dev);
241} 241}
242 242
243static int __rbd_refresh_header(struct rbd_device *rbd_dev); 243static int __rbd_refresh_header(struct rbd_device *rbd_dev, u64 *hver);
244 244
245static int rbd_open(struct block_device *bdev, fmode_t mode) 245static int rbd_open(struct block_device *bdev, fmode_t mode)
246{ 246{
@@ -1226,8 +1226,7 @@ static void rbd_watch_cb(u64 ver, u64 notify_id, u8 opcode, void *data)
1226 rbd_dev->header_name, (unsigned long long) notify_id, 1226 rbd_dev->header_name, (unsigned long long) notify_id,
1227 (unsigned int) opcode); 1227 (unsigned int) opcode);
1228 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); 1228 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1229 rc = __rbd_refresh_header(rbd_dev); 1229 rc = __rbd_refresh_header(rbd_dev, &hver);
1230 hver = rbd_dev->header.obj_version;
1231 mutex_unlock(&ctl_mutex); 1230 mutex_unlock(&ctl_mutex);
1232 if (rc) 1231 if (rc)
1233 pr_warning(RBD_DRV_NAME "%d got notification but failed to " 1232 pr_warning(RBD_DRV_NAME "%d got notification but failed to "
@@ -1707,7 +1706,7 @@ static void __rbd_remove_all_snaps(struct rbd_device *rbd_dev)
1707/* 1706/*
1708 * only read the first part of the ondisk header, without the snaps info 1707 * only read the first part of the ondisk header, without the snaps info
1709 */ 1708 */
1710static int __rbd_refresh_header(struct rbd_device *rbd_dev) 1709static int __rbd_refresh_header(struct rbd_device *rbd_dev, u64 *hver)
1711{ 1710{
1712 int ret; 1711 int ret;
1713 struct rbd_image_header h; 1712 struct rbd_image_header h;
@@ -1732,6 +1731,8 @@ static int __rbd_refresh_header(struct rbd_device *rbd_dev)
1732 /* osd requests may still refer to snapc */ 1731 /* osd requests may still refer to snapc */
1733 ceph_put_snap_context(rbd_dev->header.snapc); 1732 ceph_put_snap_context(rbd_dev->header.snapc);
1734 1733
1734 if (hver)
1735 *hver = h.obj_version;
1735 rbd_dev->header.obj_version = h.obj_version; 1736 rbd_dev->header.obj_version = h.obj_version;
1736 rbd_dev->header.image_size = h.image_size; 1737 rbd_dev->header.image_size = h.image_size;
1737 rbd_dev->header.total_snaps = h.total_snaps; 1738 rbd_dev->header.total_snaps = h.total_snaps;
@@ -1901,17 +1902,13 @@ static ssize_t rbd_image_refresh(struct device *dev,
1901 size_t size) 1902 size_t size)
1902{ 1903{
1903 struct rbd_device *rbd_dev = dev_to_rbd_dev(dev); 1904 struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
1904 int rc; 1905 int ret;
1905 int ret = size;
1906 1906
1907 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); 1907 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1908 1908 ret = __rbd_refresh_header(rbd_dev, NULL);
1909 rc = __rbd_refresh_header(rbd_dev);
1910 if (rc < 0)
1911 ret = rc;
1912
1913 mutex_unlock(&ctl_mutex); 1909 mutex_unlock(&ctl_mutex);
1914 return ret; 1910
1911 return ret < 0 ? ret : size;
1915} 1912}
1916 1913
1917static DEVICE_ATTR(size, S_IRUGO, rbd_size_show, NULL); 1914static DEVICE_ATTR(size, S_IRUGO, rbd_size_show, NULL);
@@ -2200,7 +2197,7 @@ static int rbd_init_watch_dev(struct rbd_device *rbd_dev)
2200 ret = rbd_req_sync_watch(rbd_dev); 2197 ret = rbd_req_sync_watch(rbd_dev);
2201 if (ret == -ERANGE) { 2198 if (ret == -ERANGE) {
2202 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); 2199 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
2203 rc = __rbd_refresh_header(rbd_dev); 2200 rc = __rbd_refresh_header(rbd_dev, NULL);
2204 mutex_unlock(&ctl_mutex); 2201 mutex_unlock(&ctl_mutex);
2205 if (rc < 0) 2202 if (rc < 0)
2206 return rc; 2203 return rc;
@@ -2650,7 +2647,7 @@ static ssize_t rbd_snap_add(struct device *dev,
2650 if (ret < 0) 2647 if (ret < 0)
2651 goto err_unlock; 2648 goto err_unlock;
2652 2649
2653 ret = __rbd_refresh_header(rbd_dev); 2650 ret = __rbd_refresh_header(rbd_dev, NULL);
2654 if (ret < 0) 2651 if (ret < 0)
2655 goto err_unlock; 2652 goto err_unlock;
2656 2653