diff options
author | Alex Elder <elder@inktank.com> | 2012-08-31 18:29:55 -0400 |
---|---|---|
committer | Alex Elder <elder@inktank.com> | 2012-10-10 10:43:39 -0400 |
commit | 117973fb4c91f3fd913127577e9f71b3aa6cb556 (patch) | |
tree | 30720002351972e6c227f8e9d2d6376021693d09 /drivers/block/rbd.c | |
parent | 9478554ae5d21d65e948a3eff4ee2a8ad30d70e9 (diff) |
rbd: define rbd_dev_v2_refresh()
Define a new function rbd_dev_v2_refresh() to update/refresh the
snapshot context for a format version 2 rbd image. This function
will update anything that is not fixed for the life of an rbd
image--at the moment this is mainly the snapshot context and (for
a base mapping) the size.
Update rbd_refresh_header() so it selects which function to use
based on the image format.
Rename __rbd_refresh_header() to be rbd_dev_v1_refresh()
to be consistent with the naming of its version 2 counterpart.
Similarly rename rbd_refresh_header() to be rbd_dev_refresh().
Unrelated--we use rbd_image_format_valid() here. Delete the other
use of it, which was primarily put in place to ensure that function
was referenced at the time it was defined.
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.c | 55 |
1 files changed, 47 insertions, 8 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index b64125d1d7bd..f11b839166ef 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c | |||
@@ -268,7 +268,8 @@ static void rbd_put_dev(struct rbd_device *rbd_dev) | |||
268 | put_device(&rbd_dev->dev); | 268 | put_device(&rbd_dev->dev); |
269 | } | 269 | } |
270 | 270 | ||
271 | static int rbd_refresh_header(struct rbd_device *rbd_dev, u64 *hver); | 271 | static int rbd_dev_refresh(struct rbd_device *rbd_dev, u64 *hver); |
272 | static int rbd_dev_v2_refresh(struct rbd_device *rbd_dev, u64 *hver); | ||
272 | 273 | ||
273 | static int rbd_open(struct block_device *bdev, fmode_t mode) | 274 | static int rbd_open(struct block_device *bdev, fmode_t mode) |
274 | { | 275 | { |
@@ -1304,7 +1305,7 @@ static void rbd_watch_cb(u64 ver, u64 notify_id, u8 opcode, void *data) | |||
1304 | dout("rbd_watch_cb %s notify_id=%llu opcode=%u\n", | 1305 | dout("rbd_watch_cb %s notify_id=%llu opcode=%u\n", |
1305 | rbd_dev->header_name, (unsigned long long) notify_id, | 1306 | rbd_dev->header_name, (unsigned long long) notify_id, |
1306 | (unsigned int) opcode); | 1307 | (unsigned int) opcode); |
1307 | rc = rbd_refresh_header(rbd_dev, &hver); | 1308 | rc = rbd_dev_refresh(rbd_dev, &hver); |
1308 | if (rc) | 1309 | if (rc) |
1309 | pr_warning(RBD_DRV_NAME "%d got notification but failed to " | 1310 | pr_warning(RBD_DRV_NAME "%d got notification but failed to " |
1310 | " update snaps: %d\n", rbd_dev->major, rc); | 1311 | " update snaps: %d\n", rbd_dev->major, rc); |
@@ -1732,7 +1733,7 @@ static void rbd_update_mapping_size(struct rbd_device *rbd_dev) | |||
1732 | /* | 1733 | /* |
1733 | * only read the first part of the ondisk header, without the snaps info | 1734 | * only read the first part of the ondisk header, without the snaps info |
1734 | */ | 1735 | */ |
1735 | static int __rbd_refresh_header(struct rbd_device *rbd_dev, u64 *hver) | 1736 | static int rbd_dev_v1_refresh(struct rbd_device *rbd_dev, u64 *hver) |
1736 | { | 1737 | { |
1737 | int ret; | 1738 | int ret; |
1738 | struct rbd_image_header h; | 1739 | struct rbd_image_header h; |
@@ -1773,12 +1774,16 @@ static int __rbd_refresh_header(struct rbd_device *rbd_dev, u64 *hver) | |||
1773 | return ret; | 1774 | return ret; |
1774 | } | 1775 | } |
1775 | 1776 | ||
1776 | static int rbd_refresh_header(struct rbd_device *rbd_dev, u64 *hver) | 1777 | static int rbd_dev_refresh(struct rbd_device *rbd_dev, u64 *hver) |
1777 | { | 1778 | { |
1778 | int ret; | 1779 | int ret; |
1779 | 1780 | ||
1781 | rbd_assert(rbd_image_format_valid(rbd_dev->image_format)); | ||
1780 | mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); | 1782 | mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); |
1781 | ret = __rbd_refresh_header(rbd_dev, hver); | 1783 | if (rbd_dev->image_format == 1) |
1784 | ret = rbd_dev_v1_refresh(rbd_dev, hver); | ||
1785 | else | ||
1786 | ret = rbd_dev_v2_refresh(rbd_dev, hver); | ||
1782 | mutex_unlock(&ctl_mutex); | 1787 | mutex_unlock(&ctl_mutex); |
1783 | 1788 | ||
1784 | return ret; | 1789 | return ret; |
@@ -1938,7 +1943,7 @@ static ssize_t rbd_image_refresh(struct device *dev, | |||
1938 | struct rbd_device *rbd_dev = dev_to_rbd_dev(dev); | 1943 | struct rbd_device *rbd_dev = dev_to_rbd_dev(dev); |
1939 | int ret; | 1944 | int ret; |
1940 | 1945 | ||
1941 | ret = rbd_refresh_header(rbd_dev, NULL); | 1946 | ret = rbd_dev_refresh(rbd_dev, NULL); |
1942 | 1947 | ||
1943 | return ret < 0 ? ret : size; | 1948 | return ret < 0 ? ret : size; |
1944 | } | 1949 | } |
@@ -2402,6 +2407,41 @@ static char *rbd_dev_snap_info(struct rbd_device *rbd_dev, u32 which, | |||
2402 | return ERR_PTR(-EINVAL); | 2407 | return ERR_PTR(-EINVAL); |
2403 | } | 2408 | } |
2404 | 2409 | ||
2410 | static int rbd_dev_v2_refresh(struct rbd_device *rbd_dev, u64 *hver) | ||
2411 | { | ||
2412 | int ret; | ||
2413 | __u8 obj_order; | ||
2414 | |||
2415 | down_write(&rbd_dev->header_rwsem); | ||
2416 | |||
2417 | /* Grab old order first, to see if it changes */ | ||
2418 | |||
2419 | obj_order = rbd_dev->header.obj_order, | ||
2420 | ret = rbd_dev_v2_image_size(rbd_dev); | ||
2421 | if (ret) | ||
2422 | goto out; | ||
2423 | if (rbd_dev->header.obj_order != obj_order) { | ||
2424 | ret = -EIO; | ||
2425 | goto out; | ||
2426 | } | ||
2427 | rbd_update_mapping_size(rbd_dev); | ||
2428 | |||
2429 | ret = rbd_dev_v2_snap_context(rbd_dev, hver); | ||
2430 | dout("rbd_dev_v2_snap_context returned %d\n", ret); | ||
2431 | if (ret) | ||
2432 | goto out; | ||
2433 | ret = rbd_dev_snaps_update(rbd_dev); | ||
2434 | dout("rbd_dev_snaps_update returned %d\n", ret); | ||
2435 | if (ret) | ||
2436 | goto out; | ||
2437 | ret = rbd_dev_snaps_register(rbd_dev); | ||
2438 | dout("rbd_dev_snaps_register returned %d\n", ret); | ||
2439 | out: | ||
2440 | up_write(&rbd_dev->header_rwsem); | ||
2441 | |||
2442 | return ret; | ||
2443 | } | ||
2444 | |||
2405 | /* | 2445 | /* |
2406 | * Scan the rbd device's current snapshot list and compare it to the | 2446 | * Scan the rbd device's current snapshot list and compare it to the |
2407 | * newly-received snapshot context. Remove any existing snapshots | 2447 | * newly-received snapshot context. Remove any existing snapshots |
@@ -2564,7 +2604,7 @@ static int rbd_init_watch_dev(struct rbd_device *rbd_dev) | |||
2564 | do { | 2604 | do { |
2565 | ret = rbd_req_sync_watch(rbd_dev); | 2605 | ret = rbd_req_sync_watch(rbd_dev); |
2566 | if (ret == -ERANGE) { | 2606 | if (ret == -ERANGE) { |
2567 | rc = rbd_refresh_header(rbd_dev, NULL); | 2607 | rc = rbd_dev_refresh(rbd_dev, NULL); |
2568 | if (rc < 0) | 2608 | if (rc < 0) |
2569 | return rc; | 2609 | return rc; |
2570 | } | 2610 | } |
@@ -3045,7 +3085,6 @@ static ssize_t rbd_add(struct bus_type *bus, | |||
3045 | rc = rbd_dev_probe(rbd_dev); | 3085 | rc = rbd_dev_probe(rbd_dev); |
3046 | if (rc < 0) | 3086 | if (rc < 0) |
3047 | goto err_out_client; | 3087 | goto err_out_client; |
3048 | rbd_assert(rbd_image_format_valid(rbd_dev->image_format)); | ||
3049 | 3088 | ||
3050 | /* no need to lock here, as rbd_dev is not registered yet */ | 3089 | /* no need to lock here, as rbd_dev is not registered yet */ |
3051 | rc = rbd_dev_snaps_update(rbd_dev); | 3090 | rc = rbd_dev_snaps_update(rbd_dev); |