qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Fam Zheng <famz@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-devel@nongnu.org, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH] block: Improve driver whitelist checks
Date: Thu, 10 Oct 2013 20:47:43 +0800	[thread overview]
Message-ID: <20131010124743.GA21583@T430s.nay.redhat.com> (raw)
In-Reply-To: <1381399079-17826-1-git-send-email-kwolf@redhat.com>

On Thu, 10/10 11:57, Kevin Wolf wrote:
> The main intent of this patch is to consolidate the whitelist checks to
> a single point in the code instead of spreading it everywhere. This adds
> a nicer error message for read-only whitelisting, too, in places where
> it was still missing.
> 
> The patch also contains a bonus bug fix: By finding the format first in
> bdrv_open() and then independently checking against the whitelist only
> later, we avoid the case that use of a non-whitelisted format results in
> probing rather than an error message. Previously, this could happen when
> using the driver=... option.
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  block.c    | 10 +++++++---
>  blockdev.c |  8 ++------
>  2 files changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/block.c b/block.c
> index beea027..84c0eac 100644
> --- a/block.c
> +++ b/block.c
> @@ -769,7 +769,11 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
>      bs->read_only = !(open_flags & BDRV_O_RDWR);
>  
>      if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, bs->read_only)) {
> -        error_setg(errp, "Driver '%s' is not whitelisted", drv->format_name);
> +        error_setg(errp,
> +                   !bs->read_only && bdrv_is_whitelisted(drv, true)
> +                        ? "Driver '%s' can only be used for read-only devices"
> +                        : "Driver '%s' is not whitelisted",
> +                   drv->format_name);
>          return -ENOTSUP;
>      }
>  
> @@ -881,7 +885,7 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename,
>      /* Find the right block driver */
>      drvname = qdict_get_try_str(options, "driver");
>      if (drvname) {
> -        drv = bdrv_find_whitelisted_format(drvname, !(flags & BDRV_O_RDWR));
> +        drv = bdrv_find_format(drvname);
>          if (!drv) {
>              error_setg(errp, "Unknown driver '%s'", drvname);
>          }
> @@ -1123,7 +1127,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
>      /* Find the right image format driver */
>      drvname = qdict_get_try_str(options, "driver");
>      if (drvname) {
> -        drv = bdrv_find_whitelisted_format(drvname, !(flags & BDRV_O_RDWR));
> +        drv = bdrv_find_format(drvname);
>          qdict_del(options, "driver");
>      }
>  
> diff --git a/blockdev.c b/blockdev.c
> index 92029d8..5f3cece 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -468,13 +468,9 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts,
>              return NULL;
>          }
>  
> -        drv = bdrv_find_whitelisted_format(buf, ro);
> +        drv = bdrv_find_format(buf);
>          if (!drv) {
> -            if (!ro && bdrv_find_whitelisted_format(buf, !ro)) {
> -                error_report("'%s' can be only used as read-only device.", buf);
> -            } else {
> -                error_report("'%s' invalid format", buf);
> -            }
> +            error_report("'%s' invalid format", buf);
>              return NULL;
>          }
>      }

This is much cleaner now. Thanks.

Reviewed-by: Fam Zheng <famz@redhat.com>

      reply	other threads:[~2013-10-10 12:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-10  9:57 [Qemu-devel] [PATCH] block: Improve driver whitelist checks Kevin Wolf
2013-10-10 12:47 ` Fam Zheng [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131010124743.GA21583@T430s.nay.redhat.com \
    --to=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).