diff mbox

rbd: drop dev reference on error in rbd_open()

Message ID 50255E0F.4070406@inktank.com (mailing list archive)
State New, archived
Headers show

Commit Message

Alex Elder Aug. 10, 2012, 7:16 p.m. UTC
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>
---
  drivers/block/rbd.c |    7 +++----
  1 file changed, 3 insertions(+), 4 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Yehuda Sadeh Aug. 10, 2012, 7:20 p.m. UTC | #1
Reviewed-by: Yehuda Sadeh <yehuda@inktank.com>

On Fri, Aug 10, 2012 at 12:16 PM, Alex Elder <elder@inktank.com> wrote:
> 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>
> ---
>  drivers/block/rbd.c |    7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> Index: b/drivers/block/rbd.c
> ===================================================================
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -246,13 +246,12 @@ static int rbd_open(struct block_device
>  {
>         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;
>  }
>
> --
> To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Josh Durgin Aug. 10, 2012, 7:36 p.m. UTC | #2
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>

On 08/10/2012 12:16 PM, Alex Elder wrote:
> 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>
> ---
>   drivers/block/rbd.c |    7 +++----
>   1 file changed, 3 insertions(+), 4 deletions(-)
>
> Index: b/drivers/block/rbd.c
> ===================================================================
> --- a/drivers/block/rbd.c
> +++ b/drivers/block/rbd.c
> @@ -246,13 +246,12 @@ static int rbd_open(struct block_device
>   {
>       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;
>   }

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

Index: b/drivers/block/rbd.c
===================================================================
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -246,13 +246,12 @@  static int rbd_open(struct block_device
  {
  	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;
  }