From patchwork Thu Mar 17 17:51:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 8613661 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CAD979FC32 for ; Thu, 17 Mar 2016 17:54:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 71FBF202F0 for ; Thu, 17 Mar 2016 17:54:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6EE582026F for ; Thu, 17 Mar 2016 17:54:17 +0000 (UTC) Received: from localhost ([::1]:37170 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agc7k-0004oI-P3 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Mar 2016 13:54:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40588) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agc5b-0000ji-9K for qemu-devel@nongnu.org; Thu, 17 Mar 2016 13:52:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agc5Z-0006ro-Q9 for qemu-devel@nongnu.org; Thu, 17 Mar 2016 13:52:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38303) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agc5T-0006q4-At; Thu, 17 Mar 2016 13:51:55 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id BC229C00EB06; Thu, 17 Mar 2016 17:51:54 +0000 (UTC) Received: from t530wlan.home.berrange.com.com (vpn1-7-40.ams2.redhat.com [10.36.7.40]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2HHpol1009388; Thu, 17 Mar 2016 13:51:53 -0400 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Thu, 17 Mar 2016 17:51:36 +0000 Message-Id: <1458237102-16204-2-git-send-email-berrange@redhat.com> In-Reply-To: <1458237102-16204-1-git-send-email-berrange@redhat.com> References: <1458237102-16204-1-git-send-email-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org Subject: [Qemu-devel] [PATCH v5 1/7] block: add flag to indicate that no I/O will be performed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Daniel P. Berrange --- 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 59a18a3..4d1a9d3 100644 --- a/block.c +++ b/block.c @@ -706,7 +706,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; } @@ -726,7 +727,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 a69bfc4..010e25a 100644 --- a/block/io.c +++ b/block/io.c @@ -862,6 +862,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) { @@ -1148,6 +1149,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 eaa6426..bb8e97d 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 3103150..a03e501 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"); @@ -248,7 +248,7 @@ static int img_open_password(BlockBackend *blk, const char *filename, static BlockBackend *img_open_opts(const char *id, const char *optstr, QemuOpts *opts, int flags, - bool require_io, bool quiet) + bool quiet) { QDict *options; Error *local_err = NULL; @@ -260,7 +260,7 @@ static BlockBackend *img_open_opts(const char *id, 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; } @@ -269,7 +269,7 @@ static BlockBackend *img_open_opts(const char *id, static BlockBackend *img_open_file(const char *id, const char *filename, const char *fmt, int flags, - bool require_io, bool quiet) + bool quiet) { BlockBackend *blk; Error *local_err = NULL; @@ -286,7 +286,7 @@ static BlockBackend *img_open_file(const char *id, 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; } @@ -298,7 +298,7 @@ static BlockBackend *img_open(const char *id, bool image_opts, const char *filename, const char *fmt, int flags, - bool require_io, bool quiet) + bool quiet) { BlockBackend *blk; if (image_opts) { @@ -312,9 +312,9 @@ static BlockBackend *img_open(const char *id, if (!opts) { return NULL; } - blk = img_open_opts(id, filename, opts, flags, true, quiet); + blk = img_open_opts(id, filename, opts, flags, quiet); } else { - blk = img_open_file(id, filename, fmt, flags, true, quiet); + blk = img_open_file(id, filename, fmt, flags, quiet); } return blk; } @@ -686,7 +686,7 @@ static int img_check(int argc, char **argv) return 1; } - blk = img_open("image", image_opts, filename, fmt, flags, true, quiet); + blk = img_open("image", image_opts, filename, fmt, flags, quiet); if (!blk) { return 1; } @@ -878,7 +878,7 @@ static int img_commit(int argc, char **argv) return 1; } - blk = img_open("image", image_opts, filename, fmt, flags, true, quiet); + blk = img_open("image", image_opts, filename, fmt, flags, quiet); if (!blk) { return 1; } @@ -1212,13 +1212,13 @@ static int img_compare(int argc, char **argv) goto out3; } - blk1 = img_open("image_1", image_opts, filename1, fmt1, flags, true, quiet); + blk1 = img_open("image_1", image_opts, filename1, fmt1, flags, quiet); if (!blk1) { ret = 2; goto out3; } - blk2 = img_open("image_2", image_opts, filename2, fmt2, flags, true, quiet); + blk2 = img_open("image_2", image_opts, filename2, fmt2, flags, quiet); if (!blk2) { ret = 2; goto out2; @@ -1902,7 +1902,7 @@ static int img_convert(int argc, char **argv) char *id = bs_n > 1 ? g_strdup_printf("source_%d", bs_i) : g_strdup("source"); blk[bs_i] = img_open(id, image_opts, argv[optind + bs_i], - fmt, src_flags, true, quiet); + fmt, src_flags, quiet); g_free(id); if (!blk[bs_i]) { ret = -1; @@ -2049,7 +2049,7 @@ static int img_convert(int argc, char **argv) * Not critical right now, so fix can wait... */ out_blk = img_open_file("target", out_filename, - out_fmt, flags, true, quiet); + out_fmt, flags, quiet); if (!out_blk) { ret = -1; goto out; @@ -2241,8 +2241,8 @@ static ImageInfoList *collect_image_info_list(bool image_opts, g_hash_table_insert(filenames, (gpointer)filename, NULL); blk = img_open("image", 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; } @@ -2573,7 +2573,7 @@ static int img_map(int argc, char **argv) } blk = img_open("image", image_opts, filename, fmt, - BDRV_O_FLAGS, true, false); + BDRV_O_FLAGS, false); if (!blk) { return 1; } @@ -2719,7 +2719,7 @@ static int img_snapshot(int argc, char **argv) /* Open the image */ blk = img_open("image", image_opts, filename, NULL, - bdrv_oflags, true, quiet); + bdrv_oflags, quiet); if (!blk) { return 1; } @@ -2890,7 +2890,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", image_opts, filename, fmt, flags, true, quiet); + blk = img_open("image", image_opts, filename, fmt, flags, quiet); if (!blk) { ret = -1; goto out; @@ -3228,7 +3228,7 @@ static int img_resize(int argc, char **argv) qemu_opts_del(param); blk = img_open("image", 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; @@ -3387,7 +3387,7 @@ static int img_amend(int argc, char **argv) goto out; } - blk = img_open("image", image_opts, filename, fmt, flags, true, quiet); + blk = img_open("image", image_opts, filename, fmt, flags, quiet); if (!blk) { ret = -1; goto out;