All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <famz@redhat.com>,
	qemu-block@nongnu.org
Subject: [Qemu-devel] [PATCH v6 01/11] block: add flag to indicate that no I/O will be performed
Date: Mon, 21 Mar 2016 14:11:42 +0000	[thread overview]
Message-ID: <1458569512-22970-2-git-send-email-berrange@redhat.com> (raw)
In-Reply-To: <1458569512-22970-1-git-send-email-berrange@redhat.com>

When opening an image it is useful to know whether the caller
intends to perform I/O on the image or not. In the case of
encrypted images this will allow the block driver to avoid
having to prompt for decryption keys when we merely want to
query header metadata about the image. eg qemu-img info

This flag is enforced at the top level only, since even if
we don't want todo I/O on the 'qcow2' file payload, the
underlying 'file' driver will still need todo I/O to read
the qcow2 header, for example.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 block.c               |  5 +++--
 block/io.c            |  2 ++
 include/block/block.h |  1 +
 qemu-img.c            | 44 ++++++++++++++++++++++----------------------
 4 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/block.c b/block.c
index b4107fc..97787b3 100644
--- a/block.c
+++ b/block.c
@@ -701,7 +701,8 @@ static void bdrv_inherited_options(int *child_flags, QDict *child_options,
     flags |= BDRV_O_UNMAP;
 
     /* Clear flags that only apply to the top layer */
-    flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING | BDRV_O_COPY_ON_READ);
+    flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING | BDRV_O_COPY_ON_READ |
+               BDRV_O_NO_IO);
 
     *child_flags = flags;
 }
@@ -721,7 +722,7 @@ static void bdrv_inherited_fmt_options(int *child_flags, QDict *child_options,
     child_file.inherit_options(child_flags, child_options,
                                parent_flags, parent_options);
 
-    *child_flags &= ~BDRV_O_PROTOCOL;
+    *child_flags &= ~(BDRV_O_PROTOCOL | BDRV_O_NO_IO);
 }
 
 const BdrvChildRole child_format = {
diff --git a/block/io.c b/block/io.c
index 41d954ca..bfc8592 100644
--- a/block/io.c
+++ b/block/io.c
@@ -842,6 +842,7 @@ static int coroutine_fn bdrv_aligned_preadv(BlockDriverState *bs,
     assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0);
     assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0);
     assert(!qiov || bytes == qiov->size);
+    assert((bs->open_flags & BDRV_O_NO_IO) == 0);
 
     /* Handle Copy on Read and associated serialisation */
     if (flags & BDRV_REQ_COPY_ON_READ) {
@@ -1128,6 +1129,7 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs,
     assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0);
     assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0);
     assert(!qiov || bytes == qiov->size);
+    assert((bs->open_flags & BDRV_O_NO_IO) == 0);
 
     waited = wait_serialising_requests(req);
     assert(!waited || !req->serialising);
diff --git a/include/block/block.h b/include/block/block.h
index 01349ef..d8945ff 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -93,6 +93,7 @@ typedef struct HDGeometry {
 #define BDRV_O_PROTOCOL    0x8000  /* if no block driver is explicitly given:
                                       select an appropriate protocol driver,
                                       ignoring the format layer */
+#define BDRV_O_NO_IO       0x10000 /* don't initialize for I/O */
 
 #define BDRV_O_CACHE_MASK  (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH)
 
diff --git a/qemu-img.c b/qemu-img.c
index 29eae2a..7fa2a13 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -224,13 +224,13 @@ static int print_block_option_help(const char *filename, const char *fmt)
 
 
 static int img_open_password(BlockBackend *blk, const char *filename,
-                             bool require_io, bool quiet)
+                             int flags, bool quiet)
 {
     BlockDriverState *bs;
     char password[256];
 
     bs = blk_bs(blk);
-    if (bdrv_is_encrypted(bs) && require_io) {
+    if (bdrv_is_encrypted(bs) && !(flags & BDRV_O_NO_IO)) {
         qprintf(quiet, "Disk image '%s' is encrypted.\n", filename);
         if (qemu_read_password(password, sizeof(password)) < 0) {
             error_report("No password given");
@@ -247,7 +247,7 @@ static int img_open_password(BlockBackend *blk, const char *filename,
 
 static BlockBackend *img_open_opts(const char *optstr,
                                    QemuOpts *opts, int flags,
-                                   bool require_io, bool quiet)
+                                   bool quiet)
 {
     QDict *options;
     Error *local_err = NULL;
@@ -259,7 +259,7 @@ static BlockBackend *img_open_opts(const char *optstr,
         return NULL;
     }
 
-    if (img_open_password(blk, optstr, require_io, quiet) < 0) {
+    if (img_open_password(blk, optstr, flags, quiet) < 0) {
         blk_unref(blk);
         return NULL;
     }
@@ -268,7 +268,7 @@ static BlockBackend *img_open_opts(const char *optstr,
 
 static BlockBackend *img_open_file(const char *filename,
                                    const char *fmt, int flags,
-                                   bool require_io, bool quiet)
+                                   bool quiet)
 {
     BlockBackend *blk;
     Error *local_err = NULL;
@@ -285,7 +285,7 @@ static BlockBackend *img_open_file(const char *filename,
         return NULL;
     }
 
-    if (img_open_password(blk, filename, require_io, quiet) < 0) {
+    if (img_open_password(blk, filename, flags, quiet) < 0) {
         blk_unref(blk);
         return NULL;
     }
@@ -296,7 +296,7 @@ static BlockBackend *img_open_file(const char *filename,
 static BlockBackend *img_open(bool image_opts,
                               const char *filename,
                               const char *fmt, int flags,
-                              bool require_io, bool quiet)
+                              bool quiet)
 {
     BlockBackend *blk;
     if (image_opts) {
@@ -310,9 +310,9 @@ static BlockBackend *img_open(bool image_opts,
         if (!opts) {
             return NULL;
         }
-        blk = img_open_opts(filename, opts, flags, true, quiet);
+        blk = img_open_opts(filename, opts, flags, quiet);
     } else {
-        blk = img_open_file(filename, fmt, flags, true, quiet);
+        blk = img_open_file(filename, fmt, flags, quiet);
     }
     return blk;
 }
@@ -684,7 +684,7 @@ static int img_check(int argc, char **argv)
         return 1;
     }
 
-    blk = img_open(image_opts, filename, fmt, flags, true, quiet);
+    blk = img_open(image_opts, filename, fmt, flags, quiet);
     if (!blk) {
         return 1;
     }
@@ -876,7 +876,7 @@ static int img_commit(int argc, char **argv)
         return 1;
     }
 
-    blk = img_open(image_opts, filename, fmt, flags, true, quiet);
+    blk = img_open(image_opts, filename, fmt, flags, quiet);
     if (!blk) {
         return 1;
     }
@@ -1210,13 +1210,13 @@ static int img_compare(int argc, char **argv)
         goto out3;
     }
 
-    blk1 = img_open(image_opts, filename1, fmt1, flags, true, quiet);
+    blk1 = img_open(image_opts, filename1, fmt1, flags, quiet);
     if (!blk1) {
         ret = 2;
         goto out3;
     }
 
-    blk2 = img_open(image_opts, filename2, fmt2, flags, true, quiet);
+    blk2 = img_open(image_opts, filename2, fmt2, flags, quiet);
     if (!blk2) {
         ret = 2;
         goto out2;
@@ -1898,7 +1898,7 @@ static int img_convert(int argc, char **argv)
     total_sectors = 0;
     for (bs_i = 0; bs_i < bs_n; bs_i++) {
         blk[bs_i] = img_open(image_opts, argv[optind + bs_i],
-                             fmt, src_flags, true, quiet);
+                             fmt, src_flags, quiet);
         if (!blk[bs_i]) {
             ret = -1;
             goto out;
@@ -2043,7 +2043,7 @@ static int img_convert(int argc, char **argv)
      * the bdrv_create() call which takes different params.
      * Not critical right now, so fix can wait...
      */
-    out_blk = img_open_file(out_filename, out_fmt, flags, true, quiet);
+    out_blk = img_open_file(out_filename, out_fmt, flags, quiet);
     if (!out_blk) {
         ret = -1;
         goto out;
@@ -2235,8 +2235,8 @@ static ImageInfoList *collect_image_info_list(bool image_opts,
         g_hash_table_insert(filenames, (gpointer)filename, NULL);
 
         blk = img_open(image_opts, filename, fmt,
-                       BDRV_O_FLAGS | BDRV_O_NO_BACKING,
-                       false, false);
+                       BDRV_O_FLAGS | BDRV_O_NO_BACKING | BDRV_O_NO_IO,
+                       false);
         if (!blk) {
             goto err;
         }
@@ -2566,7 +2566,7 @@ static int img_map(int argc, char **argv)
         return 1;
     }
 
-    blk = img_open(image_opts, filename, fmt, BDRV_O_FLAGS, true, false);
+    blk = img_open(image_opts, filename, fmt, BDRV_O_FLAGS, false);
     if (!blk) {
         return 1;
     }
@@ -2711,7 +2711,7 @@ static int img_snapshot(int argc, char **argv)
     }
 
     /* Open the image */
-    blk = img_open(image_opts, filename, NULL, bdrv_oflags, true, quiet);
+    blk = img_open(image_opts, filename, NULL, bdrv_oflags, quiet);
     if (!blk) {
         return 1;
     }
@@ -2882,7 +2882,7 @@ static int img_rebase(int argc, char **argv)
      * Ignore the old backing file for unsafe rebase in case we want to correct
      * the reference to a renamed or moved backing file.
      */
-    blk = img_open(image_opts, filename, fmt, flags, true, quiet);
+    blk = img_open(image_opts, filename, fmt, flags, quiet);
     if (!blk) {
         ret = -1;
         goto out;
@@ -3220,7 +3220,7 @@ static int img_resize(int argc, char **argv)
     qemu_opts_del(param);
 
     blk = img_open(image_opts, filename, fmt,
-                   BDRV_O_FLAGS | BDRV_O_RDWR, true, quiet);
+                   BDRV_O_FLAGS | BDRV_O_RDWR, quiet);
     if (!blk) {
         ret = -1;
         goto out;
@@ -3379,7 +3379,7 @@ static int img_amend(int argc, char **argv)
         goto out;
     }
 
-    blk = img_open(image_opts, filename, fmt, flags, true, quiet);
+    blk = img_open(image_opts, filename, fmt, flags, quiet);
     if (!blk) {
         ret = -1;
         goto out;
-- 
2.5.0

  reply	other threads:[~2016-03-21 14:12 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-21 14:11 [Qemu-devel] [PATCH v6 00/11] Add new LUKS block driver (for 2.6) Daniel P. Berrange
2016-03-21 14:11 ` Daniel P. Berrange [this message]
2016-03-21 14:11 ` [Qemu-devel] [PATCH v6 02/11] qemu-img/qemu-io: don't prompt for passwords if not required Daniel P. Berrange
2016-03-21 14:11 ` [Qemu-devel] [PATCH v6 03/11] tests: redirect stderr to stdout for iotests Daniel P. Berrange
2016-03-21 14:11 ` [Qemu-devel] [PATCH v6 04/11] tests: refactor python I/O tests helper main method Daniel P. Berrange
2016-03-21 14:11 ` [Qemu-devel] [PATCH v6 05/11] tests: add output filter to python I/O tests helper Daniel P. Berrange
2016-03-21 14:11 ` [Qemu-devel] [PATCH v6 06/11] block: add generic full disk encryption driver Daniel P. Berrange
2016-03-21 14:11 ` [Qemu-devel] [PATCH v6 07/11] block: move encryption deprecation warning into qcow code Daniel P. Berrange
2016-03-21 20:04   ` Eric Blake
2016-03-21 14:11 ` [Qemu-devel] [PATCH v6 08/11] block: add support for --image-opts in block I/O tests Daniel P. Berrange
2016-03-21 20:08   ` Eric Blake
2016-03-22 10:36     ` Daniel P. Berrange
2016-03-24 21:59   ` [Qemu-devel] [Qemu-block] " Max Reitz
2016-03-21 14:11 ` [Qemu-devel] [PATCH v6 09/11] block: add support for encryption secrets " Daniel P. Berrange
2016-03-21 20:13   ` Eric Blake
2016-03-21 14:11 ` [Qemu-devel] [PATCH v6 10/11] block: enable testing of LUKS driver with " Daniel P. Berrange
2016-03-21 14:11 ` [Qemu-devel] [PATCH v6 11/11] block: an interoperability test for luks vs dm-crypt/cryptsetup Daniel P. Berrange
2016-03-21 16:50 ` [Qemu-devel] [PATCH v6 00/11] Add new LUKS block driver (for 2.6) Kevin Wolf
2016-03-21 16:53   ` Daniel P. Berrange
2016-03-23 13:53 ` Kevin Wolf
2016-03-29  9:13   ` [Qemu-devel] [Qemu-block] " Kevin Wolf
2016-03-29  9:15     ` Daniel P. Berrange

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=1458569512-22970-2-git-send-email-berrange@redhat.com \
    --to=berrange@redhat.com \
    --cc=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.