Skip to content

Commit ae43e9d

Browse files
committed
rbd: fix rbd_dev_parent_get() when parent_overlap == 0
The comment for rbd_dev_parent_get() said * We must get the reference before checking for the overlap to * coordinate properly with zeroing the parent overlap in * rbd_dev_v2_parent_info() when an image gets flattened. We * drop it again if there is no overlap. but the "drop it again if there is no overlap" part was missing from the implementation. This lead to absurd parent_ref values for images with parent_overlap == 0, as parent_ref was incremented for each img_request and virtually never decremented. Fix this by leveraging the fact that refresh path calls rbd_dev_v2_parent_info() under header_rwsem and use it for read in rbd_dev_parent_get(), instead of messing around with atomics. Get rid of barriers in rbd_dev_v2_parent_info() while at it - I don't see what they'd pair with now and I suspect we are in a pretty miserable situation as far as proper locking goes regardless. Cc: stable@vger.kernel.org # 3.11+ Signed-off-by: Ilya Dryomov <idryomov@redhat.com> Reviewed-by: Josh Durgin <jdurgin@redhat.com> Reviewed-by: Alex Elder <elder@linaro.org>
1 parent 26bc420 commit ae43e9d

1 file changed

Lines changed: 6 additions & 14 deletions

File tree

‎drivers/block/rbd.c‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,32 +2098,26 @@ static void rbd_dev_parent_put(struct rbd_device *rbd_dev)
20982098
* If an image has a non-zero parent overlap, get a reference to its
20992099
* parent.
21002100
*
2101-
* We must get the reference before checking for the overlap to
2102-
* coordinate properly with zeroing the parent overlap in
2103-
* rbd_dev_v2_parent_info() when an image gets flattened. We
2104-
* drop it again if there is no overlap.
2105-
*
21062101
* Returns true if the rbd device has a parent with a non-zero
21072102
* overlap and a reference for it was successfully taken, or
21082103
* false otherwise.
21092104
*/
21102105
static bool rbd_dev_parent_get(struct rbd_device *rbd_dev)
21112106
{
2112-
int counter;
2107+
int counter = 0;
21132108

21142109
if (!rbd_dev->parent_spec)
21152110
return false;
21162111

2117-
counter = atomic_inc_return_safe(&rbd_dev->parent_ref);
2118-
if (counter > 0 && rbd_dev->parent_overlap)
2119-
return true;
2120-
2121-
/* Image was flattened, but parent is not yet torn down */
2112+
down_read(&rbd_dev->header_rwsem);
2113+
if (rbd_dev->parent_overlap)
2114+
counter = atomic_inc_return_safe(&rbd_dev->parent_ref);
2115+
up_read(&rbd_dev->header_rwsem);
21222116

21232117
if (counter < 0)
21242118
rbd_warn(rbd_dev, "parent reference overflow");
21252119

2126-
return false;
2120+
return counter > 0;
21272121
}
21282122

21292123
/*
@@ -4239,7 +4233,6 @@ static int rbd_dev_v2_parent_info(struct rbd_device *rbd_dev)
42394233
*/
42404234
if (rbd_dev->parent_overlap) {
42414235
rbd_dev->parent_overlap = 0;
4242-
smp_mb();
42434236
rbd_dev_parent_put(rbd_dev);
42444237
pr_info("%s: clone image has been flattened\n",
42454238
rbd_dev->disk->disk_name);
@@ -4285,7 +4278,6 @@ static int rbd_dev_v2_parent_info(struct rbd_device *rbd_dev)
42854278
* treat it specially.
42864279
*/
42874280
rbd_dev->parent_overlap = overlap;
4288-
smp_mb();
42894281
if (!overlap) {
42904282

42914283
/* A null parent_spec indicates it's the initial probe */

0 commit comments

Comments
 (0)