Skip to content

Commit

Permalink
rbd: barriers are hard
Browse files Browse the repository at this point in the history
Let's go shopping!

I'm afraid this may not have gotten it right:
    0774130  rbd: add barriers near done flag operations

The smp_wmb() should have been done *before* setting the done flag,
to ensure all other data was valid before marking the object request
done.

Switch to use atomic_inc_return() here to set the done flag, which
allows us to verify we don't mark something done more than once.
Doing this also implies general barriers before and after the call.

And although a read memory barrier might have been sufficient before
reading the done flag, convert this to a full memory barrier just
to put this issue to bed.

This resolves:
    http://tracker.ceph.com/issues/4238

Signed-off-by: Alex Elder <elder@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
  • Loading branch information
Alex Elder committed Feb 25, 2013
1 parent 4dda41d commit 632b88c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions drivers/block/rbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1226,13 +1226,22 @@ static void obj_request_done_init(struct rbd_obj_request *obj_request)

static void obj_request_done_set(struct rbd_obj_request *obj_request)
{
atomic_set(&obj_request->done, 1);
smp_wmb();
int done;

done = atomic_inc_return(&obj_request->done);
if (done > 1) {
struct rbd_img_request *img_request = obj_request->img_request;
struct rbd_device *rbd_dev;

rbd_dev = img_request ? img_request->rbd_dev : NULL;
rbd_warn(rbd_dev, "obj_request %p was already done\n",
obj_request);
}
}

static bool obj_request_done_test(struct rbd_obj_request *obj_request)
{
smp_rmb();
smp_mb();
return atomic_read(&obj_request->done) != 0;
}

Expand Down

0 comments on commit 632b88c

Please sign in to comment.