Skip to content

Commit

Permalink
rbd: drop dev reference on error in rbd_open()
Browse files Browse the repository at this point in the history
If a read-only rbd device is opened for writing in rbd_open(), it
returns without dropping the just-acquired device reference.

Fix this by moving the read-only check before getting the reference.

Signed-off-by: Alex Elder <elder@inktank.com>
Reviewed-by: Yehuda Sadeh <yehuda@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
  • Loading branch information
Alex Elder authored and Sage Weil committed Sep 22, 2012
1 parent 5698bd7 commit 340c7a2
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions drivers/block/rbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,12 @@ static int rbd_open(struct block_device *bdev, fmode_t mode)
{
struct rbd_device *rbd_dev = bdev->bd_disk->private_data;

rbd_get_dev(rbd_dev);

set_device_ro(bdev, rbd_dev->read_only);

if ((mode & FMODE_WRITE) && rbd_dev->read_only)
return -EROFS;

rbd_get_dev(rbd_dev);
set_device_ro(bdev, rbd_dev->read_only);

return 0;
}

Expand Down

0 comments on commit 340c7a2

Please sign in to comment.