diff mbox

[for-2.10,8/9] block/rbd: do not blindly set bs->read_only

Message ID 613303fd54633f005eeea485e32f590994eb299f.1491416061.git.jcody@redhat.com
State New
Headers show

Commit Message

Jeff Cody April 5, 2017, 6:28 p.m. UTC
We do not want to just blindly set bs->read_only.  The only time
we need to set it with the current rbd driver, is if we are using an
rbd snapshot.  In that case, we must set it to read-only.

Signed-off-by: Jeff Cody <jcody@redhat.com>
---
 block/rbd.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

Comments

Stefan Hajnoczi April 7, 2017, 9:52 a.m. UTC | #1
On Wed, Apr 05, 2017 at 02:28:50PM -0400, Jeff Cody wrote:
> We do not want to just blindly set bs->read_only.  The only time
> we need to set it with the current rbd driver, is if we are using an
> rbd snapshot.  In that case, we must set it to read-only.
> 
> Signed-off-by: Jeff Cody <jcody@redhat.com>
> ---
>  block/rbd.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/block/rbd.c b/block/rbd.c
> index c5e1aeb..35853c9 100644
> --- a/block/rbd.c
> +++ b/block/rbd.c
> @@ -635,6 +635,7 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
>          goto failed_shutdown;
>      }
>  
> +    /* rbd_open is always r/w */
>      r = rbd_open(s->io_ctx, s->image_name, &s->image, s->snap);
>      if (r < 0) {
>          error_setg_errno(errp, -r, "error reading header from %s",
> @@ -642,10 +643,14 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
>          goto failed_open;
>      }
>  
> -    r = bdrv_set_read_only(bs, (s->snap != NULL), &local_err);
> -    if (r < 0) {
> -        error_propagate(errp, local_err);
> -        goto failed_open;
> +    /* If we are using an rbd snapshot, we must be r/o, otherwise
> +     * leave as-is */
> +    if (s->snap != NULL) {
> +        r = bdrv_set_read_only(bs, true, &local_err);
> +        if (r < 0) {
> +            error_propagate(errp, local_err);
> +            goto failed_open;
> +        }

This patch series breaks git-bisect(1) for -drive
file.driver=rbd,file.read-only=on since bdrv_set_read_only(bs, false,
&local_err) fails.

Please squash this patch where you added the bdrv_set_read_only() errp
argument.
diff mbox

Patch

diff --git a/block/rbd.c b/block/rbd.c
index c5e1aeb..35853c9 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -635,6 +635,7 @@  static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
         goto failed_shutdown;
     }
 
+    /* rbd_open is always r/w */
     r = rbd_open(s->io_ctx, s->image_name, &s->image, s->snap);
     if (r < 0) {
         error_setg_errno(errp, -r, "error reading header from %s",
@@ -642,10 +643,14 @@  static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
         goto failed_open;
     }
 
-    r = bdrv_set_read_only(bs, (s->snap != NULL), &local_err);
-    if (r < 0) {
-        error_propagate(errp, local_err);
-        goto failed_open;
+    /* If we are using an rbd snapshot, we must be r/o, otherwise
+     * leave as-is */
+    if (s->snap != NULL) {
+        r = bdrv_set_read_only(bs, true, &local_err);
+        if (r < 0) {
+            error_propagate(errp, local_err);
+            goto failed_open;
+        }
     }
 
     qemu_opts_del(opts);