From patchwork Wed Dec 12 13:26:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726311 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 56F6D91E for ; Wed, 12 Dec 2018 13:29:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45A2A2B16A for ; Wed, 12 Dec 2018 13:29:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39ED42B176; Wed, 12 Dec 2018 13:29:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id BD2472B16A for ; Wed, 12 Dec 2018 13:29:32 +0000 (UTC) Received: from localhost ([::1]:44890 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Zu-0002IR-W3 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:29:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45935) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4YN-0002Gy-Oc for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:27:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4YM-0000oZ-Qr for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:27:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38658) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4YH-0000jX-9b; Wed, 12 Dec 2018 08:27:49 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9435088311; Wed, 12 Dec 2018 13:27:48 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 795A460C5C; Wed, 12 Dec 2018 13:27:47 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:26:55 +0100 Message-Id: <20181212132735.16080-2-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 12 Dec 2018 13:27:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 01/41] block: adding lzfse decompressing support as a module. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Julio Faracco QEMU dmg support includes zlib and bzip2, but it does not contains lzfse support. This commit adds the source file to extend compression support for new DMGs. Signed-off-by: Julio Faracco Signed-off-by: Kevin Wolf --- block/dmg-lzfse.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 block/dmg-lzfse.c diff --git a/block/dmg-lzfse.c b/block/dmg-lzfse.c new file mode 100644 index 0000000000..19d25bc646 --- /dev/null +++ b/block/dmg-lzfse.c @@ -0,0 +1,49 @@ +/* + * DMG lzfse uncompression + * + * Copyright (c) 2018 Julio Cesar Faracco + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "dmg.h" +#include + +static int dmg_uncompress_lzfse_do(char *next_in, unsigned int avail_in, + char *next_out, unsigned int avail_out) +{ + size_t out_size = lzfse_decode_buffer((uint8_t *) next_out, avail_out, + (uint8_t *) next_in, avail_in, + NULL); + + /* We need to decode the single chunk only. */ + /* So, out_size == avail_out is not an error here. */ + if (out_size > 0) { + return out_size; + } + return -1; +} + +__attribute__((constructor)) +static void dmg_lzfse_init(void) +{ + assert(!dmg_uncompress_lzfse); + dmg_uncompress_lzfse = dmg_uncompress_lzfse_do; +} From patchwork Wed Dec 12 13:26:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726319 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C40F86C5 for ; Wed, 12 Dec 2018 13:32:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF9482B404 for ; Wed, 12 Dec 2018 13:32:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2D042B425; Wed, 12 Dec 2018 13:32:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 4151D2B404 for ; Wed, 12 Dec 2018 13:32:56 +0000 (UTC) Received: from localhost ([::1]:44912 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4dD-0005NZ-GB for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:32:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45977) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4YR-0002L4-O0 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4YP-0000qa-MM for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:27:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50644) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4YI-0000kW-K2; Wed, 12 Dec 2018 08:27:50 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EC37636809; Wed, 12 Dec 2018 13:27:49 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB5C760C5C; Wed, 12 Dec 2018 13:27:48 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:26:56 +0100 Message-Id: <20181212132735.16080-3-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 12 Dec 2018 13:27:50 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 02/41] configure: adding support to lzfse library. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Julio Faracco This commit includes the support to lzfse opensource library. With this library dmg block driver can decompress images with this type of compression inside. Signed-off-by: Julio Faracco Signed-off-by: Kevin Wolf --- configure | 31 +++++++++++++++++++++++++++++++ block/Makefile.objs | 2 ++ 2 files changed, 33 insertions(+) diff --git a/configure b/configure index 0a3c6a72c3..f32d4fa925 100755 --- a/configure +++ b/configure @@ -434,6 +434,7 @@ capstone="" lzo="" snappy="" bzip2="" +lzfse="" guest_agent="" guest_agent_with_vss="no" guest_agent_ntddscsi="no" @@ -1310,6 +1311,10 @@ for opt do ;; --enable-bzip2) bzip2="yes" ;; + --enable-lzfse) lzfse="yes" + ;; + --disable-lzfse) lzfse="no" + ;; --enable-guest-agent) guest_agent="yes" ;; --disable-guest-agent) guest_agent="no" @@ -1745,6 +1750,8 @@ disabled with --disable-FEATURE, default is enabled if available: snappy support of snappy compression library bzip2 support of bzip2 compression library (for reading bzip2-compressed dmg images) + lzfse support of lzfse compression library + (for reading lzfse-compressed dmg images) seccomp seccomp support coroutine-pool coroutine freelist (better performance) glusterfs GlusterFS backend @@ -2263,6 +2270,24 @@ EOF fi fi +########################################## +# lzfse check + +if test "$lzfse" != "no" ; then + cat > $TMPC << EOF +#include +int main(void) { lzfse_decode_scratch_size(); return 0; } +EOF + if compile_prog "" "-llzfse" ; then + lzfse="yes" + else + if test "$lzfse" = "yes"; then + feature_not_found "lzfse" "Install lzfse devel" + fi + lzfse="no" + fi +fi + ########################################## # libseccomp check @@ -6090,6 +6115,7 @@ echo "Live block migration $live_block_migration" echo "lzo support $lzo" echo "snappy support $snappy" echo "bzip2 support $bzip2" +echo "lzfse support $lzfse" echo "NUMA host support $numa" echo "libxml2 $libxml2" echo "tcmalloc support $tcmalloc" @@ -6612,6 +6638,11 @@ if test "$bzip2" = "yes" ; then echo "BZIP2_LIBS=-lbz2" >> $config_host_mak fi +if test "$lzfse" = "yes" ; then + echo "CONFIG_LZFSE=y" >> $config_host_mak + echo "LZFSE_LIBS=-llzfse" >> $config_host_mak +fi + if test "$libiscsi" = "yes" ; then echo "CONFIG_LIBISCSI=m" >> $config_host_mak echo "LIBISCSI_CFLAGS=$libiscsi_cflags" >> $config_host_mak diff --git a/block/Makefile.objs b/block/Makefile.objs index 46d585cfd0..7a81892a52 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -57,6 +57,8 @@ ssh.o-libs := $(LIBSSH2_LIBS) block-obj-dmg-bz2-$(CONFIG_BZIP2) += dmg-bz2.o block-obj-$(if $(CONFIG_DMG),m,n) += $(block-obj-dmg-bz2-y) dmg-bz2.o-libs := $(BZIP2_LIBS) +block-obj-$(if $(CONFIG_LZFSE),m,n) += dmg-lzfse.o +dmg-lzfse.o-libs := $(LZFSE_LIBS) qcow.o-libs := -lz linux-aio.o-libs := -laio parallels.o-cflags := $(LIBXML2_CFLAGS) From patchwork Wed Dec 12 13:26:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726321 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 964C414E2 for ; Wed, 12 Dec 2018 13:33:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 855D22B408 for ; Wed, 12 Dec 2018 13:33:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 761462B42A; Wed, 12 Dec 2018 13:33:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 0EF232B408 for ; Wed, 12 Dec 2018 13:33:15 +0000 (UTC) Received: from localhost ([::1]:44922 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4dX-00073c-6C for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:33:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45979) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4YR-0002L5-O6 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4YP-0000qf-NM for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:27:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34042) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4YK-0000lr-0g; Wed, 12 Dec 2018 08:27:52 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5618AC034DC2; Wed, 12 Dec 2018 13:27:51 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4472E60C5C; Wed, 12 Dec 2018 13:27:50 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:26:57 +0100 Message-Id: <20181212132735.16080-4-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 12 Dec 2018 13:27:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 03/41] dmg: including dmg-lzfse module inside dmg block driver. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Julio Faracco This commit includes the support to new module dmg-lzfse into dmg block driver. It includes the support for block type ULFO (0x80000007). Signed-off-by: Julio Faracco Signed-off-by: Kevin Wolf --- block/dmg.h | 3 +++ block/dmg.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/block/dmg.h b/block/dmg.h index 2ecf239ba5..f28929998f 100644 --- a/block/dmg.h +++ b/block/dmg.h @@ -55,4 +55,7 @@ typedef struct BDRVDMGState { extern int (*dmg_uncompress_bz2)(char *next_in, unsigned int avail_in, char *next_out, unsigned int avail_out); +extern int (*dmg_uncompress_lzfse)(char *next_in, unsigned int avail_in, + char *next_out, unsigned int avail_out); + #endif diff --git a/block/dmg.c b/block/dmg.c index 1d9283ba2f..86bb2344ea 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -33,6 +33,9 @@ int (*dmg_uncompress_bz2)(char *next_in, unsigned int avail_in, char *next_out, unsigned int avail_out); +int (*dmg_uncompress_lzfse)(char *next_in, unsigned int avail_in, + char *next_out, unsigned int avail_out); + enum { /* Limit chunk sizes to prevent unreasonable amounts of memory being used * or truncating when converting to 32-bit types @@ -107,6 +110,7 @@ static void update_max_chunk_size(BDRVDMGState *s, uint32_t chunk, switch (s->types[chunk]) { case 0x80000005: /* zlib compressed */ case 0x80000006: /* bzip2 compressed */ + case 0x80000007: /* lzfse compressed */ compressed_size = s->lengths[chunk]; uncompressed_sectors = s->sectorcounts[chunk]; break; @@ -188,6 +192,8 @@ static bool dmg_is_known_block_type(uint32_t entry_type) return true; case 0x80000006: /* bzip2 */ return !!dmg_uncompress_bz2; + case 0x80000007: /* lzfse */ + return !!dmg_uncompress_lzfse; default: return false; } @@ -425,6 +431,7 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, } block_module_load_one("dmg-bz2"); + block_module_load_one("dmg-lzfse"); s->n_chunks = 0; s->offsets = s->lengths = s->sectors = s->sectorcounts = NULL; @@ -623,6 +630,27 @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num) return ret; } break; + case 0x80000007: + if (!dmg_uncompress_lzfse) { + break; + } + /* we need to buffer, because only the chunk as whole can be + * inflated. */ + ret = bdrv_pread(bs->file, s->offsets[chunk], + s->compressed_chunk, s->lengths[chunk]); + if (ret != s->lengths[chunk]) { + return -1; + } + + ret = dmg_uncompress_lzfse((char *)s->compressed_chunk, + (unsigned int) s->lengths[chunk], + (char *)s->uncompressed_chunk, + (unsigned int) + (512 * s->sectorcounts[chunk])); + if (ret < 0) { + return ret; + } + break; case 1: /* copy */ ret = bdrv_pread(bs->file, s->offsets[chunk], s->uncompressed_chunk, s->lengths[chunk]); From patchwork Wed Dec 12 13:26:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726327 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 963A56C5 for ; Wed, 12 Dec 2018 13:36:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8263D2836F for ; Wed, 12 Dec 2018 13:36:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7250329535; Wed, 12 Dec 2018 13:36:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 078AB2836F for ; Wed, 12 Dec 2018 13:36:22 +0000 (UTC) Received: from localhost ([::1]:44926 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4gX-00084W-Re for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:36:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4YT-0002My-Nw for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4YP-0000qi-Nf for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57140) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4YL-0000n9-Cb; Wed, 12 Dec 2018 08:27:53 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B4AC23097023; Wed, 12 Dec 2018 13:27:52 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id A037F60C5C; Wed, 12 Dec 2018 13:27:51 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:26:58 +0100 Message-Id: <20181212132735.16080-5-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 12 Dec 2018 13:27:52 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 04/41] dmg: exchanging hardcoded dmg UDIF block types to enum. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Julio Faracco This change is better to understand what kind of block type is being handled by the code. Using a syntax similar to the DMG documentation is easier than tracking all hex values assigned to a block type. Signed-off-by: Julio Faracco Signed-off-by: Kevin Wolf --- block/dmg.c | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/block/dmg.c b/block/dmg.c index 86bb2344ea..50e91aef6d 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -44,6 +44,19 @@ enum { DMG_SECTORCOUNTS_MAX = DMG_LENGTHS_MAX / 512, }; +enum { + /* DMG Block Type */ + UDZE = 0, /* Zeroes */ + UDRW, /* RAW type */ + UDIG, /* Ignore */ + UDCO = 0x80000004, + UDZO, + UDBZ, + ULFO, + UDCM = 0x7ffffffe, /* Comments */ + UDLE /* Last Entry */ +}; + static int dmg_probe(const uint8_t *buf, int buf_size, const char *filename) { int len; @@ -108,16 +121,16 @@ static void update_max_chunk_size(BDRVDMGState *s, uint32_t chunk, uint32_t uncompressed_sectors = 0; switch (s->types[chunk]) { - case 0x80000005: /* zlib compressed */ - case 0x80000006: /* bzip2 compressed */ - case 0x80000007: /* lzfse compressed */ + case UDZO: /* zlib compressed */ + case UDBZ: /* bzip2 compressed */ + case ULFO: /* lzfse compressed */ compressed_size = s->lengths[chunk]; uncompressed_sectors = s->sectorcounts[chunk]; break; - case 1: /* copy */ + case UDRW: /* copy */ uncompressed_sectors = DIV_ROUND_UP(s->lengths[chunk], 512); break; - case 2: /* zero */ + case UDIG: /* zero */ /* as the all-zeroes block may be large, it is treated specially: the * sector is not copied from a large buffer, a simple memset is used * instead. Therefore uncompressed_sectors does not need to be set. */ @@ -186,13 +199,13 @@ typedef struct DmgHeaderState { static bool dmg_is_known_block_type(uint32_t entry_type) { switch (entry_type) { - case 0x00000001: /* uncompressed */ - case 0x00000002: /* zeroes */ - case 0x80000005: /* zlib */ + case UDRW: /* uncompressed */ + case UDIG: /* zeroes */ + case UDZO: /* zlib */ return true; - case 0x80000006: /* bzip2 */ + case UDBZ: /* bzip2 */ return !!dmg_uncompress_bz2; - case 0x80000007: /* lzfse */ + case ULFO: /* lzfse */ return !!dmg_uncompress_lzfse; default: return false; @@ -586,7 +599,7 @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num) s->current_chunk = s->n_chunks; switch (s->types[chunk]) { /* block entry type */ - case 0x80000005: { /* zlib compressed */ + case UDZO: { /* zlib compressed */ /* we need to buffer, because only the chunk as whole can be * inflated. */ ret = bdrv_pread(bs->file, s->offsets[chunk], @@ -609,7 +622,7 @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num) return -1; } break; } - case 0x80000006: /* bzip2 compressed */ + case UDBZ: /* bzip2 compressed */ if (!dmg_uncompress_bz2) { break; } @@ -630,7 +643,7 @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num) return ret; } break; - case 0x80000007: + case ULFO: if (!dmg_uncompress_lzfse) { break; } @@ -651,14 +664,14 @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num) return ret; } break; - case 1: /* copy */ + case UDRW: /* copy */ ret = bdrv_pread(bs->file, s->offsets[chunk], s->uncompressed_chunk, s->lengths[chunk]); if (ret != s->lengths[chunk]) { return -1; } break; - case 2: /* zero */ + case UDIG: /* zero */ /* see dmg_read, it is treated specially. No buffer needs to be * pre-filled, the zeroes can be set directly. */ break; From patchwork Wed Dec 12 13:26:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726317 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E5FB14E2 for ; Wed, 12 Dec 2018 13:30:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D84F2B160 for ; Wed, 12 Dec 2018 13:30:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 719A82B38D; Wed, 12 Dec 2018 13:30:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 1AF252B160 for ; Wed, 12 Dec 2018 13:30:31 +0000 (UTC) Received: from localhost ([::1]:44910 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4as-0004tN-6o for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:30:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46048) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4YY-0002Oj-0Y for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4YV-0000yr-Px for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50334) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4YN-0000oH-1I; Wed, 12 Dec 2018 08:27:55 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 21141307D850; Wed, 12 Dec 2018 13:27:54 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0EBB360F94; Wed, 12 Dec 2018 13:27:52 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:26:59 +0100 Message-Id: <20181212132735.16080-6-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 12 Dec 2018 13:27:54 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 05/41] block/replication: drop extra synchronization X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Vladimir Sementsov-Ogievskiy After commit f8d59dfb40 "block/backup: fix fleecing scheme: use serialized writes" fleecing (specifically reading from backup target, when backup source is in backing chain of backup target) is safe, because all backup-job writes to target are serialized. Therefore we don't need additional synchronization for these reads. Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Kevin Wolf --- block/replication.c | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/block/replication.c b/block/replication.c index 6349d6958e..0c2989d2cb 100644 --- a/block/replication.c +++ b/block/replication.c @@ -218,9 +218,6 @@ static coroutine_fn int replication_co_readv(BlockDriverState *bs, QEMUIOVector *qiov) { BDRVReplicationState *s = bs->opaque; - BdrvChild *child = s->secondary_disk; - BlockJob *job = NULL; - CowRequest req; int ret; if (s->mode == REPLICATION_MODE_PRIMARY) { @@ -233,28 +230,9 @@ static coroutine_fn int replication_co_readv(BlockDriverState *bs, return ret; } - if (child && child->bs) { - job = child->bs->job; - } - - if (job) { - uint64_t remaining_bytes = remaining_sectors * BDRV_SECTOR_SIZE; - - backup_wait_for_overlapping_requests(child->bs->job, - sector_num * BDRV_SECTOR_SIZE, - remaining_bytes); - backup_cow_request_begin(&req, child->bs->job, - sector_num * BDRV_SECTOR_SIZE, - remaining_bytes); - ret = bdrv_co_preadv(bs->file, sector_num * BDRV_SECTOR_SIZE, - remaining_bytes, qiov, 0); - backup_cow_request_end(&req); - goto out; - } - ret = bdrv_co_preadv(bs->file, sector_num * BDRV_SECTOR_SIZE, remaining_sectors * BDRV_SECTOR_SIZE, qiov, 0); -out: + return replication_return_value(s, ret); } From patchwork Wed Dec 12 13:27:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726315 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 737F96C5 for ; Wed, 12 Dec 2018 13:30:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61B582B32B for ; Wed, 12 Dec 2018 13:30:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54B5F2B37A; Wed, 12 Dec 2018 13:30:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id D3DBA2B32B for ; Wed, 12 Dec 2018 13:30:21 +0000 (UTC) Received: from localhost ([::1]:44906 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4ai-0004ii-T6 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:30:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46113) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Yb-0002RD-Kk for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Ya-00013p-E7 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52648) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4YP-0000pP-Lw; Wed, 12 Dec 2018 08:27:59 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7E1EF30832CE; Wed, 12 Dec 2018 13:27:55 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E09B60C44; Wed, 12 Dec 2018 13:27:54 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:00 +0100 Message-Id: <20181212132735.16080-7-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 12 Dec 2018 13:27:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 06/41] block/backup: drop unused synchronization interface X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Vladimir Sementsov-Ogievskiy Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Kevin Wolf --- include/block/block_backup.h | 13 ------------ block/backup.c | 38 +++++++----------------------------- 2 files changed, 7 insertions(+), 44 deletions(-) diff --git a/include/block/block_backup.h b/include/block/block_backup.h index 994a3bd2ec..157596c296 100644 --- a/include/block/block_backup.h +++ b/include/block/block_backup.h @@ -20,19 +20,6 @@ #include "block/block_int.h" -typedef struct CowRequest { - int64_t start_byte; - int64_t end_byte; - QLIST_ENTRY(CowRequest) list; - CoQueue wait_queue; /* coroutines blocked on this request */ -} CowRequest; - -void backup_wait_for_overlapping_requests(BlockJob *job, int64_t offset, - uint64_t bytes); -void backup_cow_request_begin(CowRequest *req, BlockJob *job, - int64_t offset, uint64_t bytes); -void backup_cow_request_end(CowRequest *req); - void backup_do_checkpoint(BlockJob *job, Error **errp); #endif diff --git a/block/backup.c b/block/backup.c index 4d084f6ca6..b829b251eb 100644 --- a/block/backup.c +++ b/block/backup.c @@ -28,6 +28,13 @@ #define BACKUP_CLUSTER_SIZE_DEFAULT (1 << 16) +typedef struct CowRequest { + int64_t start_byte; + int64_t end_byte; + QLIST_ENTRY(CowRequest) list; + CoQueue wait_queue; /* coroutines blocked on this request */ +} CowRequest; + typedef struct BackupBlockJob { BlockJob common; BlockBackend *target; @@ -322,37 +329,6 @@ void backup_do_checkpoint(BlockJob *job, Error **errp) hbitmap_set(backup_job->copy_bitmap, 0, len); } -void backup_wait_for_overlapping_requests(BlockJob *job, int64_t offset, - uint64_t bytes) -{ - BackupBlockJob *backup_job = container_of(job, BackupBlockJob, common); - int64_t start, end; - - assert(block_job_driver(job) == &backup_job_driver); - - start = QEMU_ALIGN_DOWN(offset, backup_job->cluster_size); - end = QEMU_ALIGN_UP(offset + bytes, backup_job->cluster_size); - wait_for_overlapping_requests(backup_job, start, end); -} - -void backup_cow_request_begin(CowRequest *req, BlockJob *job, - int64_t offset, uint64_t bytes) -{ - BackupBlockJob *backup_job = container_of(job, BackupBlockJob, common); - int64_t start, end; - - assert(block_job_driver(job) == &backup_job_driver); - - start = QEMU_ALIGN_DOWN(offset, backup_job->cluster_size); - end = QEMU_ALIGN_UP(offset + bytes, backup_job->cluster_size); - cow_request_begin(req, backup_job, start, end); -} - -void backup_cow_request_end(CowRequest *req) -{ - cow_request_end(req); -} - static void backup_drain(BlockJob *job) { BackupBlockJob *s = container_of(job, BackupBlockJob, common); From patchwork Wed Dec 12 13:27:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726323 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A406A6C5 for ; Wed, 12 Dec 2018 13:34:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93E352844C for ; Wed, 12 Dec 2018 13:34:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 877352847B; Wed, 12 Dec 2018 13:34:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 17C0E2844C for ; Wed, 12 Dec 2018 13:34:04 +0000 (UTC) Received: from localhost ([::1]:44923 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4eJ-0007bY-6S for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:34:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46175) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Yf-0002YK-VX for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Ya-00013m-EA for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34006) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4YP-0000qG-O7; Wed, 12 Dec 2018 08:27:59 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D99A7A8F4; Wed, 12 Dec 2018 13:27:56 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7FE760C44; Wed, 12 Dec 2018 13:27:55 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:01 +0100 Message-Id: <20181212132735.16080-8-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 12 Dec 2018 13:27:56 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 07/41] qcow2: use Z_OK instead of 0 for deflateInit2 return code check X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Vladimir Sementsov-Ogievskiy Use appropriate macro, corresponding to deflateInit2 spec. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia Signed-off-by: Kevin Wolf --- block/qcow2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/qcow2.c b/block/qcow2.c index 991d6ac91b..225fcbde67 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3738,7 +3738,7 @@ static ssize_t qcow2_compress(void *dest, const void *src, size_t size) memset(&strm, 0, sizeof(strm)); ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -12, 9, Z_DEFAULT_STRATEGY); - if (ret != 0) { + if (ret != Z_OK) { return -2; } From patchwork Wed Dec 12 13:27:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726341 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8098413AF for ; Wed, 12 Dec 2018 13:39:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 701472A2F0 for ; Wed, 12 Dec 2018 13:39:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 638272A311; Wed, 12 Dec 2018 13:39:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 2D12D2A2F0 for ; Wed, 12 Dec 2018 13:39:46 +0000 (UTC) Received: from localhost ([::1]:44952 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4jp-0002NH-D8 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:39:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46114) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Yb-0002RE-Ka for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Ya-00013l-ED for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52676) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4YR-0000rW-MO; Wed, 12 Dec 2018 08:28:01 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8791E307EA84; Wed, 12 Dec 2018 13:27:58 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DB8560C44; Wed, 12 Dec 2018 13:27:57 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:02 +0100 Message-Id: <20181212132735.16080-9-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 12 Dec 2018 13:27:58 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 08/41] qcow2: make more generic interface for qcow2_compress X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Vladimir Sementsov-Ogievskiy Give explicit size both for source and destination buffers, to make it similar with decompression path and than cleanly reuse parameter structure for decompression threads. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia Signed-off-by: Kevin Wolf --- block/qcow2.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 225fcbde67..0c1569f715 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3722,14 +3722,15 @@ fail: /* * qcow2_compress() * - * @dest - destination buffer, at least of @size-1 bytes - * @src - source buffer, @size bytes + * @dest - destination buffer, @dest_size bytes + * @src - source buffer, @src_size bytes * * Returns: compressed size on success - * -1 if compression is inefficient + * -1 destination buffer is not enough to store compressed data * -2 on any other error */ -static ssize_t qcow2_compress(void *dest, const void *src, size_t size) +static ssize_t qcow2_compress(void *dest, size_t dest_size, + const void *src, size_t src_size) { ssize_t ret; z_stream strm; @@ -3744,14 +3745,14 @@ static ssize_t qcow2_compress(void *dest, const void *src, size_t size) /* strm.next_in is not const in old zlib versions, such as those used on * OpenBSD/NetBSD, so cast the const away */ - strm.avail_in = size; + strm.avail_in = src_size; strm.next_in = (void *) src; - strm.avail_out = size - 1; + strm.avail_out = dest_size; strm.next_out = dest; ret = deflate(&strm, Z_FINISH); if (ret == Z_STREAM_END) { - ret = size - 1 - strm.avail_out; + ret = dest_size - strm.avail_out; } else { ret = (ret == Z_OK ? -1 : -2); } @@ -3765,8 +3766,9 @@ static ssize_t qcow2_compress(void *dest, const void *src, size_t size) typedef struct Qcow2CompressData { void *dest; + size_t dest_size; const void *src; - size_t size; + size_t src_size; ssize_t ret; } Qcow2CompressData; @@ -3774,7 +3776,8 @@ static int qcow2_compress_pool_func(void *opaque) { Qcow2CompressData *data = opaque; - data->ret = qcow2_compress(data->dest, data->src, data->size); + data->ret = qcow2_compress(data->dest, data->dest_size, + data->src, data->src_size); return 0; } @@ -3786,15 +3789,17 @@ static void qcow2_compress_complete(void *opaque, int ret) /* See qcow2_compress definition for parameters description */ static ssize_t qcow2_co_compress(BlockDriverState *bs, - void *dest, const void *src, size_t size) + void *dest, size_t dest_size, + const void *src, size_t src_size) { BDRVQcow2State *s = bs->opaque; BlockAIOCB *acb; ThreadPool *pool = aio_get_thread_pool(bdrv_get_aio_context(bs)); Qcow2CompressData arg = { .dest = dest, + .dest_size = dest_size, .src = src, - .size = size, + .src_size = src_size, }; while (s->nb_compress_threads >= MAX_COMPRESS_THREADS) { @@ -3861,7 +3866,8 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset, out_buf = g_malloc(s->cluster_size); - out_len = qcow2_co_compress(bs, out_buf, buf, s->cluster_size); + out_len = qcow2_co_compress(bs, out_buf, s->cluster_size - 1, + buf, s->cluster_size); if (out_len == -2) { ret = -EINVAL; goto fail; From patchwork Wed Dec 12 13:27:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726387 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 12875174F for ; Wed, 12 Dec 2018 13:42:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0111A2B164 for ; Wed, 12 Dec 2018 13:42:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E969C2B1E4; Wed, 12 Dec 2018 13:42:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 576EE2B164 for ; Wed, 12 Dec 2018 13:42:41 +0000 (UTC) Received: from localhost ([::1]:44973 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4me-0004xX-5j for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:42:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46118) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Yb-0002RJ-MK for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Ya-00014E-FJ for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54316) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4YT-0000si-Lu; Wed, 12 Dec 2018 08:28:03 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E53BE89AC6; Wed, 12 Dec 2018 13:27:59 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id CFF7360C44; Wed, 12 Dec 2018 13:27:58 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:03 +0100 Message-Id: <20181212132735.16080-10-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 12 Dec 2018 13:27:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 09/41] qcow2: move decompression from qcow2-cluster.c to qcow2.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Vladimir Sementsov-Ogievskiy Compression is done in threads in qcow2.c. We want to do decompression in the same way, so, firstly, move it to the same file. The only change is braces around if-body in decompress_buffer, to satisfy checkpatch. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia Signed-off-by: Kevin Wolf --- block/qcow2-cluster.c | 70 ------------------------------------------ block/qcow2.c | 71 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 70 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index d37fe08b3d..e2737429f5 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1571,76 +1571,6 @@ again: return 0; } -static int decompress_buffer(uint8_t *out_buf, int out_buf_size, - const uint8_t *buf, int buf_size) -{ - z_stream strm1, *strm = &strm1; - int ret, out_len; - - memset(strm, 0, sizeof(*strm)); - - strm->next_in = (uint8_t *)buf; - strm->avail_in = buf_size; - strm->next_out = out_buf; - strm->avail_out = out_buf_size; - - ret = inflateInit2(strm, -12); - if (ret != Z_OK) - return -1; - ret = inflate(strm, Z_FINISH); - out_len = strm->next_out - out_buf; - if ((ret != Z_STREAM_END && ret != Z_BUF_ERROR) || - out_len != out_buf_size) { - inflateEnd(strm); - return -1; - } - inflateEnd(strm); - return 0; -} - -int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) -{ - BDRVQcow2State *s = bs->opaque; - int ret, csize, nb_csectors, sector_offset; - uint64_t coffset; - - coffset = cluster_offset & s->cluster_offset_mask; - if (s->cluster_cache_offset != coffset) { - nb_csectors = ((cluster_offset >> s->csize_shift) & s->csize_mask) + 1; - sector_offset = coffset & 511; - csize = nb_csectors * 512 - sector_offset; - - /* Allocate buffers on first decompress operation, most images are - * uncompressed and the memory overhead can be avoided. The buffers - * are freed in .bdrv_close(). - */ - if (!s->cluster_data) { - /* one more sector for decompressed data alignment */ - s->cluster_data = qemu_try_blockalign(bs->file->bs, - QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size + 512); - if (!s->cluster_data) { - return -ENOMEM; - } - } - if (!s->cluster_cache) { - s->cluster_cache = g_malloc(s->cluster_size); - } - - BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED); - ret = bdrv_read(bs->file, coffset >> 9, s->cluster_data, - nb_csectors); - if (ret < 0) { - return ret; - } - if (decompress_buffer(s->cluster_cache, s->cluster_size, - s->cluster_data + sector_offset, csize) < 0) { - return -EIO; - } - s->cluster_cache_offset = coffset; - } - return 0; -} - /* * This discards as many clusters of nb_clusters as possible at once (i.e. * all clusters in the same L2 slice) and returns the number of discarded diff --git a/block/qcow2.c b/block/qcow2.c index 0c1569f715..d4d141c495 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3762,6 +3762,34 @@ static ssize_t qcow2_compress(void *dest, size_t dest_size, return ret; } +static int decompress_buffer(uint8_t *out_buf, int out_buf_size, + const uint8_t *buf, int buf_size) +{ + z_stream strm1, *strm = &strm1; + int ret, out_len; + + memset(strm, 0, sizeof(*strm)); + + strm->next_in = (uint8_t *)buf; + strm->avail_in = buf_size; + strm->next_out = out_buf; + strm->avail_out = out_buf_size; + + ret = inflateInit2(strm, -12); + if (ret != Z_OK) { + return -1; + } + ret = inflate(strm, Z_FINISH); + out_len = strm->next_out - out_buf; + if ((ret != Z_STREAM_END && ret != Z_BUF_ERROR) || + out_len != out_buf_size) { + inflateEnd(strm); + return -1; + } + inflateEnd(strm); + return 0; +} + #define MAX_COMPRESS_THREADS 4 typedef struct Qcow2CompressData { @@ -3915,6 +3943,49 @@ fail: return ret; } +int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) +{ + BDRVQcow2State *s = bs->opaque; + int ret, csize, nb_csectors, sector_offset; + uint64_t coffset; + + coffset = cluster_offset & s->cluster_offset_mask; + if (s->cluster_cache_offset != coffset) { + nb_csectors = ((cluster_offset >> s->csize_shift) & s->csize_mask) + 1; + sector_offset = coffset & 511; + csize = nb_csectors * 512 - sector_offset; + + /* Allocate buffers on first decompress operation, most images are + * uncompressed and the memory overhead can be avoided. The buffers + * are freed in .bdrv_close(). + */ + if (!s->cluster_data) { + /* one more sector for decompressed data alignment */ + s->cluster_data = qemu_try_blockalign(bs->file->bs, + QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size + 512); + if (!s->cluster_data) { + return -ENOMEM; + } + } + if (!s->cluster_cache) { + s->cluster_cache = g_malloc(s->cluster_size); + } + + BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED); + ret = bdrv_read(bs->file, coffset >> 9, s->cluster_data, + nb_csectors); + if (ret < 0) { + return ret; + } + if (decompress_buffer(s->cluster_cache, s->cluster_size, + s->cluster_data + sector_offset, csize) < 0) { + return -EIO; + } + s->cluster_cache_offset = coffset; + } + return 0; +} + static int make_completely_empty(BlockDriverState *bs) { BDRVQcow2State *s = bs->opaque; From patchwork Wed Dec 12 13:27:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726397 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B4BC518A7 for ; Wed, 12 Dec 2018 13:45:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A35A02B20E for ; Wed, 12 Dec 2018 13:45:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97DFF2B32B; Wed, 12 Dec 2018 13:45:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 8B5542B20E for ; Wed, 12 Dec 2018 13:45:30 +0000 (UTC) Received: from localhost ([::1]:44995 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4pN-0000Jx-Mx for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:45:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46146) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Yc-0002Sh-PP for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Yb-00015t-K7 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38758) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4YV-0000wE-OO; Wed, 12 Dec 2018 08:28:03 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4FEFA88311; Wed, 12 Dec 2018 13:28:01 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DA7F60C44; Wed, 12 Dec 2018 13:28:00 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:04 +0100 Message-Id: <20181212132735.16080-11-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 12 Dec 2018 13:28:01 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 10/41] qcow2: refactor decompress_buffer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Vladimir Sementsov-Ogievskiy - make it look more like a pair of qcow2_compress - rename the function and its parameters - drop extra out_len variable, check filling of output buffer by strm structure itself - fix code style - add some documentation Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia Signed-off-by: Kevin Wolf --- block/qcow2.c | 56 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index d4d141c495..ac9bb3a225 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3762,32 +3762,46 @@ static ssize_t qcow2_compress(void *dest, size_t dest_size, return ret; } -static int decompress_buffer(uint8_t *out_buf, int out_buf_size, - const uint8_t *buf, int buf_size) +/* + * qcow2_decompress() + * + * Decompress some data (not more than @src_size bytes) to produce exactly + * @dest_size bytes. + * + * @dest - destination buffer, @dest_size bytes + * @src - source buffer, @src_size bytes + * + * Returns: 0 on success + * -1 on fail + */ +static ssize_t qcow2_decompress(void *dest, size_t dest_size, + const void *src, size_t src_size) { - z_stream strm1, *strm = &strm1; - int ret, out_len; - - memset(strm, 0, sizeof(*strm)); + int ret = 0; + z_stream strm; - strm->next_in = (uint8_t *)buf; - strm->avail_in = buf_size; - strm->next_out = out_buf; - strm->avail_out = out_buf_size; + memset(&strm, 0, sizeof(strm)); + strm.avail_in = src_size; + strm.next_in = (void *) src; + strm.avail_out = dest_size; + strm.next_out = dest; - ret = inflateInit2(strm, -12); + ret = inflateInit2(&strm, -12); if (ret != Z_OK) { return -1; } - ret = inflate(strm, Z_FINISH); - out_len = strm->next_out - out_buf; - if ((ret != Z_STREAM_END && ret != Z_BUF_ERROR) || - out_len != out_buf_size) { - inflateEnd(strm); - return -1; + + ret = inflate(&strm, Z_FINISH); + if ((ret != Z_STREAM_END && ret != Z_BUF_ERROR) || strm.avail_out != 0) { + /* We approve Z_BUF_ERROR because we need @dest buffer to be filled, but + * @src buffer may be processed partly (because in qcow2 we know size of + * compressed data with precision of one sector) */ + ret = -1; } - inflateEnd(strm); - return 0; + + inflateEnd(&strm); + + return ret; } #define MAX_COMPRESS_THREADS 4 @@ -3977,8 +3991,8 @@ int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) if (ret < 0) { return ret; } - if (decompress_buffer(s->cluster_cache, s->cluster_size, - s->cluster_data + sector_offset, csize) < 0) { + if (qcow2_decompress(s->cluster_cache, s->cluster_size, + s->cluster_data + sector_offset, csize) < 0) { return -EIO; } s->cluster_cache_offset = coffset; From patchwork Wed Dec 12 13:27:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726407 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 49B1714E2 for ; Wed, 12 Dec 2018 13:48:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38E8729F54 for ; Wed, 12 Dec 2018 13:48:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2AB4329F21; Wed, 12 Dec 2018 13:48:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id C594129F21 for ; Wed, 12 Dec 2018 13:48:49 +0000 (UTC) Received: from localhost ([::1]:45013 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4sa-00034y-Ar for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:48:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46110) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Yb-0002R7-I3 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Ya-00014M-Fr for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46522) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4YV-0000xp-Ma; Wed, 12 Dec 2018 08:28:03 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AB5B4C03D47F; Wed, 12 Dec 2018 13:28:02 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9783C60C44; Wed, 12 Dec 2018 13:28:01 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:05 +0100 Message-Id: <20181212132735.16080-12-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 12 Dec 2018 13:28:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 11/41] qcow2: use byte-based read in qcow2_decompress_cluster X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Vladimir Sementsov-Ogievskiy We are gradually moving away from sector-based interfaces, towards byte-based. Get rid of it here too. Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Kevin Wolf --- block/qcow2.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index ac9bb3a225..d4b25d88b5 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3957,17 +3957,19 @@ fail: return ret; } -int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) +int coroutine_fn +qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) { BDRVQcow2State *s = bs->opaque; - int ret, csize, nb_csectors, sector_offset; + int ret, csize, nb_csectors; uint64_t coffset; + struct iovec iov; + QEMUIOVector local_qiov; coffset = cluster_offset & s->cluster_offset_mask; if (s->cluster_cache_offset != coffset) { nb_csectors = ((cluster_offset >> s->csize_shift) & s->csize_mask) + 1; - sector_offset = coffset & 511; - csize = nb_csectors * 512 - sector_offset; + csize = nb_csectors * 512 - (coffset & 511); /* Allocate buffers on first decompress operation, most images are * uncompressed and the memory overhead can be avoided. The buffers @@ -3985,14 +3987,17 @@ int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) s->cluster_cache = g_malloc(s->cluster_size); } + iov.iov_base = s->cluster_data; + iov.iov_len = csize; + qemu_iovec_init_external(&local_qiov, &iov, 1); + BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED); - ret = bdrv_read(bs->file, coffset >> 9, s->cluster_data, - nb_csectors); + ret = bdrv_co_preadv(bs->file, coffset, csize, &local_qiov, 0); if (ret < 0) { return ret; } if (qcow2_decompress(s->cluster_cache, s->cluster_size, - s->cluster_data + sector_offset, csize) < 0) { + s->cluster_data, csize) < 0) { return -EIO; } s->cluster_cache_offset = coffset; From patchwork Wed Dec 12 13:27:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726331 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 903CA14E2 for ; Wed, 12 Dec 2018 13:37:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7EF5D29019 for ; Wed, 12 Dec 2018 13:37:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 728B4297AF; Wed, 12 Dec 2018 13:37:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id C845029019 for ; Wed, 12 Dec 2018 13:37:04 +0000 (UTC) Received: from localhost ([::1]:44948 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4hE-0001MV-1e for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:37:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46228) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Yj-0002mt-TL for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Yi-0001K1-JO for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50260) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4Ya-00013T-LR; Wed, 12 Dec 2018 08:28:08 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F2B55308624F; Wed, 12 Dec 2018 13:28:07 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 012F260C61; Wed, 12 Dec 2018 13:28:02 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:06 +0100 Message-Id: <20181212132735.16080-13-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 12 Dec 2018 13:28:08 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 12/41] qcow2: aio support for compressed cluster read X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Vladimir Sementsov-Ogievskiy Allocate buffers locally and release qcow2 lock. Than, reads inside qcow2_co_preadv_compressed may be done in parallel, however all decompression is still done synchronously. Let's improve it in the following commit. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia Signed-off-by: Kevin Wolf --- block/qcow2.h | 4 --- block/qcow2.c | 96 ++++++++++++++++++++++++++------------------------- 2 files changed, 49 insertions(+), 51 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 8662b68575..a98d24500b 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -278,9 +278,6 @@ typedef struct BDRVQcow2State { QEMUTimer *cache_clean_timer; unsigned cache_clean_interval; - uint8_t *cluster_cache; - uint8_t *cluster_data; - uint64_t cluster_cache_offset; QLIST_HEAD(QCowClusterAlloc, QCowL2Meta) cluster_allocs; uint64_t *refcount_table; @@ -616,7 +613,6 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size, bool exact_size); int qcow2_shrink_l1_table(BlockDriverState *bs, uint64_t max_size); int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index); -int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset); int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num, uint8_t *buf, int nb_sectors, bool enc, Error **errp); diff --git a/block/qcow2.c b/block/qcow2.c index d4b25d88b5..c1886c46e3 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -74,6 +74,13 @@ typedef struct { #define QCOW2_EXT_MAGIC_CRYPTO_HEADER 0x0537be77 #define QCOW2_EXT_MAGIC_BITMAPS 0x23852875 +static int coroutine_fn +qcow2_co_preadv_compressed(BlockDriverState *bs, + uint64_t file_cluster_offset, + uint64_t offset, + uint64_t bytes, + QEMUIOVector *qiov); + static int qcow2_probe(const uint8_t *buf, int buf_size, const char *filename) { const QCowHeader *cow_header = (const void *)buf; @@ -1414,7 +1421,6 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, goto fail; } - s->cluster_cache_offset = -1; s->flags = flags; ret = qcow2_refcount_init(bs); @@ -1914,15 +1920,15 @@ static coroutine_fn int qcow2_co_preadv(BlockDriverState *bs, uint64_t offset, break; case QCOW2_CLUSTER_COMPRESSED: - /* add AIO support for compressed blocks ? */ - ret = qcow2_decompress_cluster(bs, cluster_offset); + qemu_co_mutex_unlock(&s->lock); + ret = qcow2_co_preadv_compressed(bs, cluster_offset, + offset, cur_bytes, + &hd_qiov); + qemu_co_mutex_lock(&s->lock); if (ret < 0) { goto fail; } - qemu_iovec_from_buf(&hd_qiov, 0, - s->cluster_cache + offset_in_cluster, - cur_bytes); break; case QCOW2_CLUSTER_NORMAL: @@ -2058,8 +2064,6 @@ static coroutine_fn int qcow2_co_pwritev(BlockDriverState *bs, uint64_t offset, qemu_iovec_init(&hd_qiov, qiov->niov); - s->cluster_cache_offset = -1; /* disable compressed cache */ - qemu_co_mutex_lock(&s->lock); while (bytes != 0) { @@ -2223,8 +2227,6 @@ static void qcow2_close(BlockDriverState *bs) g_free(s->image_backing_file); g_free(s->image_backing_format); - g_free(s->cluster_cache); - qemu_vfree(s->cluster_data); qcow2_refcount_close(bs); qcow2_free_snapshots(bs); } @@ -3401,7 +3403,6 @@ qcow2_co_copy_range_to(BlockDriverState *bs, QCowL2Meta *l2meta = NULL; assert(!bs->encrypted); - s->cluster_cache_offset = -1; /* disable compressed cache */ qemu_co_mutex_lock(&s->lock); @@ -3957,52 +3958,53 @@ fail: return ret; } -int coroutine_fn -qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) +static int coroutine_fn +qcow2_co_preadv_compressed(BlockDriverState *bs, + uint64_t file_cluster_offset, + uint64_t offset, + uint64_t bytes, + QEMUIOVector *qiov) { BDRVQcow2State *s = bs->opaque; - int ret, csize, nb_csectors; + int ret = 0, csize, nb_csectors; uint64_t coffset; + uint8_t *buf, *out_buf; struct iovec iov; QEMUIOVector local_qiov; + int offset_in_cluster = offset_into_cluster(s, offset); - coffset = cluster_offset & s->cluster_offset_mask; - if (s->cluster_cache_offset != coffset) { - nb_csectors = ((cluster_offset >> s->csize_shift) & s->csize_mask) + 1; - csize = nb_csectors * 512 - (coffset & 511); + coffset = file_cluster_offset & s->cluster_offset_mask; + nb_csectors = ((file_cluster_offset >> s->csize_shift) & s->csize_mask) + 1; + csize = nb_csectors * 512 - (coffset & 511); - /* Allocate buffers on first decompress operation, most images are - * uncompressed and the memory overhead can be avoided. The buffers - * are freed in .bdrv_close(). - */ - if (!s->cluster_data) { - /* one more sector for decompressed data alignment */ - s->cluster_data = qemu_try_blockalign(bs->file->bs, - QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size + 512); - if (!s->cluster_data) { - return -ENOMEM; - } - } - if (!s->cluster_cache) { - s->cluster_cache = g_malloc(s->cluster_size); - } + buf = g_try_malloc(csize); + if (!buf) { + return -ENOMEM; + } + iov.iov_base = buf; + iov.iov_len = csize; + qemu_iovec_init_external(&local_qiov, &iov, 1); - iov.iov_base = s->cluster_data; - iov.iov_len = csize; - qemu_iovec_init_external(&local_qiov, &iov, 1); + out_buf = qemu_blockalign(bs, s->cluster_size); - BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED); - ret = bdrv_co_preadv(bs->file, coffset, csize, &local_qiov, 0); - if (ret < 0) { - return ret; - } - if (qcow2_decompress(s->cluster_cache, s->cluster_size, - s->cluster_data, csize) < 0) { - return -EIO; - } - s->cluster_cache_offset = coffset; + BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED); + ret = bdrv_co_preadv(bs->file, coffset, csize, &local_qiov, 0); + if (ret < 0) { + goto fail; } - return 0; + + if (qcow2_decompress(out_buf, s->cluster_size, buf, csize) < 0) { + ret = -EIO; + goto fail; + } + + qemu_iovec_from_buf(qiov, 0, out_buf + offset_in_cluster, bytes); + +fail: + qemu_vfree(out_buf); + g_free(buf); + + return ret; } static int make_completely_empty(BlockDriverState *bs) From patchwork Wed Dec 12 13:27:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726325 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0637C14E2 for ; Wed, 12 Dec 2018 13:34:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA65C2836F for ; Wed, 12 Dec 2018 13:34:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEF7B28718; Wed, 12 Dec 2018 13:34:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id C5BC32836F for ; Wed, 12 Dec 2018 13:34:23 +0000 (UTC) Received: from localhost ([::1]:44920 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4ed-0006Gi-22 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:34:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46200) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Yi-0002hk-Eu for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Yh-0001Fh-HL for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50270) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4Yc-00015m-1K; Wed, 12 Dec 2018 08:28:10 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5A81A308624F; Wed, 12 Dec 2018 13:28:09 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4AE9A60C44; Wed, 12 Dec 2018 13:28:08 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:07 +0100 Message-Id: <20181212132735.16080-14-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 12 Dec 2018 13:28:09 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 13/41] qcow2: do decompression in threads X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Vladimir Sementsov-Ogievskiy Do decompression in threads, like it is already done for compression. This improves asynchronous compressed reads performance. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia Signed-off-by: Kevin Wolf --- block/qcow2.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index c1886c46e3..0b5ad13006 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3807,20 +3807,24 @@ static ssize_t qcow2_decompress(void *dest, size_t dest_size, #define MAX_COMPRESS_THREADS 4 +typedef ssize_t (*Qcow2CompressFunc)(void *dest, size_t dest_size, + const void *src, size_t src_size); typedef struct Qcow2CompressData { void *dest; size_t dest_size; const void *src; size_t src_size; ssize_t ret; + + Qcow2CompressFunc func; } Qcow2CompressData; static int qcow2_compress_pool_func(void *opaque) { Qcow2CompressData *data = opaque; - data->ret = qcow2_compress(data->dest, data->dest_size, - data->src, data->src_size); + data->ret = data->func(data->dest, data->dest_size, + data->src, data->src_size); return 0; } @@ -3830,10 +3834,9 @@ static void qcow2_compress_complete(void *opaque, int ret) qemu_coroutine_enter(opaque); } -/* See qcow2_compress definition for parameters description */ -static ssize_t qcow2_co_compress(BlockDriverState *bs, - void *dest, size_t dest_size, - const void *src, size_t src_size) +static ssize_t coroutine_fn +qcow2_co_do_compress(BlockDriverState *bs, void *dest, size_t dest_size, + const void *src, size_t src_size, Qcow2CompressFunc func) { BDRVQcow2State *s = bs->opaque; BlockAIOCB *acb; @@ -3843,6 +3846,7 @@ static ssize_t qcow2_co_compress(BlockDriverState *bs, .dest_size = dest_size, .src = src, .src_size = src_size, + .func = func, }; while (s->nb_compress_threads >= MAX_COMPRESS_THREADS) { @@ -3865,6 +3869,22 @@ static ssize_t qcow2_co_compress(BlockDriverState *bs, return arg.ret; } +static ssize_t coroutine_fn +qcow2_co_compress(BlockDriverState *bs, void *dest, size_t dest_size, + const void *src, size_t src_size) +{ + return qcow2_co_do_compress(bs, dest, dest_size, src, src_size, + qcow2_compress); +} + +static ssize_t coroutine_fn +qcow2_co_decompress(BlockDriverState *bs, void *dest, size_t dest_size, + const void *src, size_t src_size) +{ + return qcow2_co_do_compress(bs, dest, dest_size, src, src_size, + qcow2_decompress); +} + /* XXX: put compressed sectors first, then all the cluster aligned tables to avoid losing bytes in alignment */ static coroutine_fn int @@ -3993,7 +4013,7 @@ qcow2_co_preadv_compressed(BlockDriverState *bs, goto fail; } - if (qcow2_decompress(out_buf, s->cluster_size, buf, csize) < 0) { + if (qcow2_co_decompress(bs, out_buf, s->cluster_size, buf, csize) < 0) { ret = -EIO; goto fail; } From patchwork Wed Dec 12 13:27:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726337 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 77F3614E2 for ; Wed, 12 Dec 2018 13:37:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6708C2836F for ; Wed, 12 Dec 2018 13:37:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B5BB29535; Wed, 12 Dec 2018 13:37:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 31EFE2836F for ; Wed, 12 Dec 2018 13:37:40 +0000 (UTC) Received: from localhost ([::1]:44940 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4hn-0000cO-Dh for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:37:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46236) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Yk-0002nU-8O for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Yi-0001KC-Ty for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34150) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4Yd-00017B-Gf; Wed, 12 Dec 2018 08:28:11 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B75BD13AA0; Wed, 12 Dec 2018 13:28:10 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5C7260C44; Wed, 12 Dec 2018 13:28:09 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:08 +0100 Message-Id: <20181212132735.16080-15-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 12 Dec 2018 13:28:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 14/41] file-posix: Reorganise RawPosixAIOData X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP RawPosixAIOData contains a lot of fields for several separate operations that are to be processed in a worker thread and that need different parameters. The struct is currently rather unorganised, with unions that cover some, but not all operations, and even one #define for field names instead of a union. Clean this up to have some common fields and a single union. As a side effect, on x86_64 the struct shrinks from 72 to 48 bytes. Signed-off-by: Kevin Wolf --- block/file-posix.c | 89 +++++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 07bbdab953..d0102a7ec0 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -182,25 +182,29 @@ static int64_t raw_getlength(BlockDriverState *bs); typedef struct RawPosixAIOData { BlockDriverState *bs; + int aio_type; int aio_fildes; - union { - struct iovec *aio_iov; - void *aio_ioctl_buf; - }; - int aio_niov; - uint64_t aio_nbytes; -#define aio_ioctl_cmd aio_nbytes /* for QEMU_AIO_IOCTL */ + off_t aio_offset; - int aio_type; + uint64_t aio_nbytes; + union { + struct { + struct iovec *iov; + int niov; + } io; + struct { + uint64_t cmd; + void *buf; + } ioctl; struct { int aio_fd2; off_t aio_offset2; - }; + } copy_range; struct { PreallocMode prealloc; Error **errp; - }; + } truncate; }; } RawPosixAIOData; @@ -1152,7 +1156,7 @@ static ssize_t handle_aiocb_ioctl(RawPosixAIOData *aiocb) { int ret; - ret = ioctl(aiocb->aio_fildes, aiocb->aio_ioctl_cmd, aiocb->aio_ioctl_buf); + ret = ioctl(aiocb->aio_fildes, aiocb->ioctl.cmd, aiocb->ioctl.buf); if (ret == -1) { return -errno; } @@ -1233,13 +1237,13 @@ static ssize_t handle_aiocb_rw_vector(RawPosixAIOData *aiocb) do { if (aiocb->aio_type & QEMU_AIO_WRITE) len = qemu_pwritev(aiocb->aio_fildes, - aiocb->aio_iov, - aiocb->aio_niov, + aiocb->io.iov, + aiocb->io.niov, aiocb->aio_offset); else len = qemu_preadv(aiocb->aio_fildes, - aiocb->aio_iov, - aiocb->aio_niov, + aiocb->io.iov, + aiocb->io.niov, aiocb->aio_offset); } while (len == -1 && errno == EINTR); @@ -1305,8 +1309,8 @@ static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb) * If there is just a single buffer, and it is properly aligned * we can just use plain pread/pwrite without any problems. */ - if (aiocb->aio_niov == 1) { - return handle_aiocb_rw_linear(aiocb, aiocb->aio_iov->iov_base); + if (aiocb->io.niov == 1) { + return handle_aiocb_rw_linear(aiocb, aiocb->io.iov->iov_base); } /* * We have more than one iovec, and all are properly aligned. @@ -1343,9 +1347,9 @@ static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb) char *p = buf; int i; - for (i = 0; i < aiocb->aio_niov; ++i) { - memcpy(p, aiocb->aio_iov[i].iov_base, aiocb->aio_iov[i].iov_len); - p += aiocb->aio_iov[i].iov_len; + for (i = 0; i < aiocb->io.niov; ++i) { + memcpy(p, aiocb->io.iov[i].iov_base, aiocb->io.iov[i].iov_len); + p += aiocb->io.iov[i].iov_len; } assert(p - buf == aiocb->aio_nbytes); } @@ -1356,12 +1360,12 @@ static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb) size_t count = aiocb->aio_nbytes, copy; int i; - for (i = 0; i < aiocb->aio_niov && count; ++i) { + for (i = 0; i < aiocb->io.niov && count; ++i) { copy = count; - if (copy > aiocb->aio_iov[i].iov_len) { - copy = aiocb->aio_iov[i].iov_len; + if (copy > aiocb->io.iov[i].iov_len) { + copy = aiocb->io.iov[i].iov_len; } - memcpy(aiocb->aio_iov[i].iov_base, p, copy); + memcpy(aiocb->io.iov[i].iov_base, p, copy); assert(count >= copy); p += copy; count -= copy; @@ -1572,14 +1576,15 @@ static ssize_t handle_aiocb_copy_range(RawPosixAIOData *aiocb) { uint64_t bytes = aiocb->aio_nbytes; off_t in_off = aiocb->aio_offset; - off_t out_off = aiocb->aio_offset2; + off_t out_off = aiocb->copy_range.aio_offset2; while (bytes) { ssize_t ret = copy_file_range(aiocb->aio_fildes, &in_off, - aiocb->aio_fd2, &out_off, + aiocb->copy_range.aio_fd2, &out_off, bytes, 0); trace_file_copy_file_range(aiocb->bs, aiocb->aio_fildes, in_off, - aiocb->aio_fd2, out_off, bytes, 0, ret); + aiocb->copy_range.aio_fd2, out_off, bytes, + 0, ret); if (ret == 0) { /* No progress (e.g. when beyond EOF), let the caller fall back to * buffer I/O. */ @@ -1648,7 +1653,8 @@ static int handle_aiocb_truncate(RawPosixAIOData *aiocb) struct stat st; int fd = aiocb->aio_fildes; int64_t offset = aiocb->aio_offset; - Error **errp = aiocb->errp; + PreallocMode prealloc = aiocb->truncate.prealloc; + Error **errp = aiocb->truncate.errp; if (fstat(fd, &st) < 0) { result = -errno; @@ -1657,12 +1663,12 @@ static int handle_aiocb_truncate(RawPosixAIOData *aiocb) } current_length = st.st_size; - if (current_length > offset && aiocb->prealloc != PREALLOC_MODE_OFF) { + if (current_length > offset && prealloc != PREALLOC_MODE_OFF) { error_setg(errp, "Cannot use preallocation for shrinking files"); return -ENOTSUP; } - switch (aiocb->prealloc) { + switch (prealloc) { #ifdef CONFIG_POSIX_FALLOCATE case PREALLOC_MODE_FALLOC: /* @@ -1743,7 +1749,7 @@ static int handle_aiocb_truncate(RawPosixAIOData *aiocb) default: result = -ENOTSUP; error_setg(errp, "Unsupported preallocation mode: %s", - PreallocMode_str(aiocb->prealloc)); + PreallocMode_str(prealloc)); return result; } @@ -1768,7 +1774,7 @@ static int aio_worker(void *arg) case QEMU_AIO_READ: ret = handle_aiocb_rw(aiocb); if (ret >= 0 && ret < aiocb->aio_nbytes) { - iov_memset(aiocb->aio_iov, aiocb->aio_niov, ret, + iov_memset(aiocb->io.iov, aiocb->io.niov, ret, 0, aiocb->aio_nbytes - ret); ret = aiocb->aio_nbytes; @@ -1829,16 +1835,17 @@ static int paio_submit_co_full(BlockDriverState *bs, int fd, acb->bs = bs; acb->aio_type = type; acb->aio_fildes = fd; - acb->aio_fd2 = fd2; - acb->aio_offset2 = offset2; acb->aio_nbytes = bytes; acb->aio_offset = offset; if (qiov) { - acb->aio_iov = qiov->iov; - acb->aio_niov = qiov->niov; + acb->io.iov = qiov->iov; + acb->io.niov = qiov->niov; assert(qiov->size == bytes); + } else { + acb->copy_range.aio_fd2 = fd2; + acb->copy_range.aio_offset2 = offset2; } trace_file_paio_submit_co(offset, bytes, type); @@ -1976,8 +1983,10 @@ raw_regular_truncate(BlockDriverState *bs, int fd, int64_t offset, .aio_fildes = fd, .aio_type = QEMU_AIO_TRUNCATE, .aio_offset = offset, - .prealloc = prealloc, - .errp = errp, + .truncate = { + .prealloc = prealloc, + .errp = errp, + }, }; /* @bs can be NULL, bdrv_get_aio_context() returns the main context then */ @@ -3089,8 +3098,8 @@ static BlockAIOCB *hdev_aio_ioctl(BlockDriverState *bs, acb->aio_type = QEMU_AIO_IOCTL; acb->aio_fildes = s->fd; acb->aio_offset = 0; - acb->aio_ioctl_buf = buf; - acb->aio_ioctl_cmd = req; + acb->ioctl.buf = buf; + acb->ioctl.cmd = req; pool = aio_get_thread_pool(bdrv_get_aio_context(bs)); return thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque); } From patchwork Wed Dec 12 13:27:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726347 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 384913E9D for ; Wed, 12 Dec 2018 13:40:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25DB72A2F0 for ; Wed, 12 Dec 2018 13:40:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A76C2AA93; Wed, 12 Dec 2018 13:40:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id B8CBD2A2F0 for ; Wed, 12 Dec 2018 13:40:23 +0000 (UTC) Received: from localhost ([::1]:44957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4kQ-00036N-Ue for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:40:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46252) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Yk-0002qR-VM for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Yk-0001LT-29 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38100) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4Yi-0001GI-3j; Wed, 12 Dec 2018 08:28:16 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 68DD03084218; Wed, 12 Dec 2018 13:28:15 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F80960C44; Wed, 12 Dec 2018 13:28:10 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:09 +0100 Message-Id: <20181212132735.16080-16-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 12 Dec 2018 13:28:15 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 15/41] file-posix: Factor out raw_thread_pool_submit() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Getting the thread pool of the AioContext of a block node and scheduling some work in it is an operation that is already done twice, and we'll get more instances. Factor it out into a separate function. Signed-off-by: Kevin Wolf --- block/file-posix.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index d0102a7ec0..27be94cfe5 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1824,13 +1824,20 @@ static int aio_worker(void *arg) return ret; } +static int coroutine_fn raw_thread_pool_submit(BlockDriverState *bs, + ThreadPoolFunc func, void *arg) +{ + /* @bs can be NULL, bdrv_get_aio_context() returns the main context then */ + ThreadPool *pool = aio_get_thread_pool(bdrv_get_aio_context(bs)); + return thread_pool_submit_co(pool, func, arg); +} + static int paio_submit_co_full(BlockDriverState *bs, int fd, int64_t offset, int fd2, int64_t offset2, QEMUIOVector *qiov, int bytes, int type) { RawPosixAIOData *acb = g_new(RawPosixAIOData, 1); - ThreadPool *pool; acb->bs = bs; acb->aio_type = type; @@ -1849,8 +1856,7 @@ static int paio_submit_co_full(BlockDriverState *bs, int fd, } trace_file_paio_submit_co(offset, bytes, type); - pool = aio_get_thread_pool(bdrv_get_aio_context(bs)); - return thread_pool_submit_co(pool, aio_worker, acb); + return raw_thread_pool_submit(bs, aio_worker, acb); } static inline int paio_submit_co(BlockDriverState *bs, int fd, @@ -1976,7 +1982,6 @@ raw_regular_truncate(BlockDriverState *bs, int fd, int64_t offset, PreallocMode prealloc, Error **errp) { RawPosixAIOData *acb = g_new(RawPosixAIOData, 1); - ThreadPool *pool; *acb = (RawPosixAIOData) { .bs = bs, @@ -1989,9 +1994,7 @@ raw_regular_truncate(BlockDriverState *bs, int fd, int64_t offset, }, }; - /* @bs can be NULL, bdrv_get_aio_context() returns the main context then */ - pool = aio_get_thread_pool(bdrv_get_aio_context(bs)); - return thread_pool_submit_co(pool, aio_worker, acb); + return raw_thread_pool_submit(bs, aio_worker, acb); } static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset, From patchwork Wed Dec 12 13:27:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726349 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6405115A6 for ; Wed, 12 Dec 2018 13:40:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5344F2A2F0 for ; Wed, 12 Dec 2018 13:40:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 47C872A56D; Wed, 12 Dec 2018 13:40:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id EA52F2A2F0 for ; Wed, 12 Dec 2018 13:40:40 +0000 (UTC) Received: from localhost ([::1]:44971 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4ki-0004Ut-5k for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:40:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46280) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Ym-0002vF-Ck for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Yl-0001Mi-HD for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44018) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4Yj-0001KO-GS; Wed, 12 Dec 2018 08:28:17 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C75973082A34; Wed, 12 Dec 2018 13:28:16 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id B47A060C44; Wed, 12 Dec 2018 13:28:15 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:10 +0100 Message-Id: <20181212132735.16080-17-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 12 Dec 2018 13:28:16 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 16/41] file-posix: Avoid aio_worker() for QEMU_AIO_TRUNCATE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP aio_worker() doesn't add anything interesting, it's only a useless indirection. Call the handler function directly instead. As we know that this handler function is only called from coroutine context and the coroutine stays around until the worker thread finishes, we can keep RawPosixAIOData on the stack. Signed-off-by: Kevin Wolf --- block/file-posix.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 27be94cfe5..7c5121efc9 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1645,8 +1645,9 @@ static ssize_t handle_aiocb_discard(RawPosixAIOData *aiocb) return ret; } -static int handle_aiocb_truncate(RawPosixAIOData *aiocb) +static int handle_aiocb_truncate(void *opaque) { + RawPosixAIOData *aiocb = opaque; int result = 0; int64_t current_length = 0; char *buf = NULL; @@ -1812,8 +1813,7 @@ static int aio_worker(void *arg) ret = handle_aiocb_copy_range(aiocb); break; case QEMU_AIO_TRUNCATE: - ret = handle_aiocb_truncate(aiocb); - break; + g_assert_not_reached(); default: error_report("invalid aio request (0x%x)", aiocb->aio_type); ret = -EINVAL; @@ -1981,9 +1981,9 @@ static int coroutine_fn raw_regular_truncate(BlockDriverState *bs, int fd, int64_t offset, PreallocMode prealloc, Error **errp) { - RawPosixAIOData *acb = g_new(RawPosixAIOData, 1); + RawPosixAIOData acb; - *acb = (RawPosixAIOData) { + acb = (RawPosixAIOData) { .bs = bs, .aio_fildes = fd, .aio_type = QEMU_AIO_TRUNCATE, @@ -1994,7 +1994,7 @@ raw_regular_truncate(BlockDriverState *bs, int fd, int64_t offset, }, }; - return raw_thread_pool_submit(bs, aio_worker, acb); + return raw_thread_pool_submit(bs, handle_aiocb_truncate, &acb); } static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset, From patchwork Wed Dec 12 13:27:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726389 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7E5A1174F for ; Wed, 12 Dec 2018 13:43:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D28A2AE00 for ; Wed, 12 Dec 2018 13:43:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5FCB32B1E4; Wed, 12 Dec 2018 13:43:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 0D9BE2AE00 for ; Wed, 12 Dec 2018 13:43:12 +0000 (UTC) Received: from localhost ([::1]:44984 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4nA-0006wP-5C for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:43:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46333) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Ys-00034s-5L for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Yr-0001Qc-7t for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:13918) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4Yk-0001Lj-Ra; Wed, 12 Dec 2018 08:28:18 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2FE403084258; Wed, 12 Dec 2018 13:28:18 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2030560C44; Wed, 12 Dec 2018 13:28:16 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:11 +0100 Message-Id: <20181212132735.16080-18-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 12 Dec 2018 13:28:18 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 17/41] file-posix: Avoid aio_worker() for QEMU_AIO_COPY_RANGE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP aio_worker() doesn't add anything interesting, it's only a useless indirection. Call the handler function directly instead. As we know that this handler function is only called from coroutine context and the coroutine stays around until the worker thread finishes, we can keep RawPosixAIOData on the stack. Signed-off-by: Kevin Wolf --- block/file-posix.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 7c5121efc9..e502ba7e15 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1572,8 +1572,9 @@ static off_t copy_file_range(int in_fd, off_t *in_off, int out_fd, } #endif -static ssize_t handle_aiocb_copy_range(RawPosixAIOData *aiocb) +static int handle_aiocb_copy_range(void *opaque) { + RawPosixAIOData *aiocb = opaque; uint64_t bytes = aiocb->aio_nbytes; off_t in_off = aiocb->aio_offset; off_t out_off = aiocb->copy_range.aio_offset2; @@ -1810,8 +1811,6 @@ static int aio_worker(void *arg) ret = handle_aiocb_write_zeroes_unmap(aiocb); break; case QEMU_AIO_COPY_RANGE: - ret = handle_aiocb_copy_range(aiocb); - break; case QEMU_AIO_TRUNCATE: g_assert_not_reached(); default: @@ -2714,6 +2713,7 @@ static int coroutine_fn raw_co_copy_range_to(BlockDriverState *bs, BdrvRequestFlags read_flags, BdrvRequestFlags write_flags) { + RawPosixAIOData acb; BDRVRawState *s = bs->opaque; BDRVRawState *src_s; @@ -2726,8 +2726,20 @@ static int coroutine_fn raw_co_copy_range_to(BlockDriverState *bs, if (fd_open(src->bs) < 0 || fd_open(dst->bs) < 0) { return -EIO; } - return paio_submit_co_full(bs, src_s->fd, src_offset, s->fd, dst_offset, - NULL, bytes, QEMU_AIO_COPY_RANGE); + + acb = (RawPosixAIOData) { + .bs = bs, + .aio_type = QEMU_AIO_COPY_RANGE, + .aio_fildes = src_s->fd, + .aio_offset = src_offset, + .aio_nbytes = bytes, + .copy_range = { + .aio_fd2 = s->fd, + .aio_offset2 = dst_offset, + }, + }; + + return raw_thread_pool_submit(bs, handle_aiocb_copy_range, &acb); } BlockDriver bdrv_file = { From patchwork Wed Dec 12 13:27:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726427 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 41E9491E for ; Wed, 12 Dec 2018 13:52:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 321262B27D for ; Wed, 12 Dec 2018 13:52:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 261AB2B340; Wed, 12 Dec 2018 13:52:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id B3A0F2B27D for ; Wed, 12 Dec 2018 13:52:05 +0000 (UTC) Received: from localhost ([::1]:45030 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4vk-0004Mp-UU for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:52:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46337) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Ys-00034u-Ah for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Yr-0001Qn-8p for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34402) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4Ym-0001Mw-DP; Wed, 12 Dec 2018 08:28:20 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 95E83811D9; Wed, 12 Dec 2018 13:28:19 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DED260C44; Wed, 12 Dec 2018 13:28:18 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:12 +0100 Message-Id: <20181212132735.16080-19-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 12 Dec 2018 13:28:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 18/41] file-posix: Avoid aio_worker() for QEMU_AIO_WRITE_ZEROES X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP aio_worker() doesn't add anything interesting, it's only a useless indirection. Call the handler function directly instead. As we know that this handler function is only called from coroutine context and the coroutine stays around until the worker thread finishes, we can keep RawPosixAIOData on the stack. Signed-off-by: Kevin Wolf --- block/file-posix.c | 53 +++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index e502ba7e15..16f2b202c6 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1464,8 +1464,9 @@ static ssize_t handle_aiocb_write_zeroes_block(RawPosixAIOData *aiocb) return ret; } -static ssize_t handle_aiocb_write_zeroes(RawPosixAIOData *aiocb) +static int handle_aiocb_write_zeroes(void *opaque) { + RawPosixAIOData *aiocb = opaque; #if defined(CONFIG_FALLOCATE) || defined(CONFIG_XFS) BDRVRawState *s = aiocb->bs->opaque; #endif @@ -1529,8 +1530,9 @@ static ssize_t handle_aiocb_write_zeroes(RawPosixAIOData *aiocb) return -ENOTSUP; } -static ssize_t handle_aiocb_write_zeroes_unmap(RawPosixAIOData *aiocb) +static int handle_aiocb_write_zeroes_unmap(void *opaque) { + RawPosixAIOData *aiocb = opaque; BDRVRawState *s G_GNUC_UNUSED = aiocb->bs->opaque; int ret; @@ -1805,11 +1807,7 @@ static int aio_worker(void *arg) ret = handle_aiocb_discard(aiocb); break; case QEMU_AIO_WRITE_ZEROES: - ret = handle_aiocb_write_zeroes(aiocb); - break; case QEMU_AIO_WRITE_ZEROES | QEMU_AIO_DISCARD: - ret = handle_aiocb_write_zeroes_unmap(aiocb); - break; case QEMU_AIO_COPY_RANGE: case QEMU_AIO_TRUNCATE: g_assert_not_reached(); @@ -2631,18 +2629,41 @@ raw_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) return paio_submit_co(bs, s->fd, offset, NULL, bytes, QEMU_AIO_DISCARD); } -static int coroutine_fn raw_co_pwrite_zeroes( - BlockDriverState *bs, int64_t offset, - int bytes, BdrvRequestFlags flags) +static int coroutine_fn +raw_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes, + BdrvRequestFlags flags, bool blkdev) { BDRVRawState *s = bs->opaque; - int operation = QEMU_AIO_WRITE_ZEROES; + RawPosixAIOData acb; + ThreadPoolFunc *handler; + + acb = (RawPosixAIOData) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type = QEMU_AIO_WRITE_ZEROES, + .aio_offset = offset, + .aio_nbytes = bytes, + }; + + if (blkdev) { + acb.aio_type |= QEMU_AIO_BLKDEV; + } if (flags & BDRV_REQ_MAY_UNMAP) { - operation |= QEMU_AIO_DISCARD; + acb.aio_type |= QEMU_AIO_DISCARD; + handler = handle_aiocb_write_zeroes_unmap; + } else { + handler = handle_aiocb_write_zeroes; } - return paio_submit_co(bs, s->fd, offset, NULL, bytes, operation); + return raw_thread_pool_submit(bs, handler, &acb); +} + +static int coroutine_fn raw_co_pwrite_zeroes( + BlockDriverState *bs, int64_t offset, + int bytes, BdrvRequestFlags flags) +{ + return raw_do_pwrite_zeroes(bs, offset, bytes, flags, false); } static int raw_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) @@ -3147,8 +3168,6 @@ hdev_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) static coroutine_fn int hdev_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes, BdrvRequestFlags flags) { - BDRVRawState *s = bs->opaque; - int operation = QEMU_AIO_WRITE_ZEROES | QEMU_AIO_BLKDEV; int rc; rc = fd_open(bs); @@ -3156,11 +3175,7 @@ static coroutine_fn int hdev_co_pwrite_zeroes(BlockDriverState *bs, return rc; } - if (flags & BDRV_REQ_MAY_UNMAP) { - operation |= QEMU_AIO_DISCARD; - } - - return paio_submit_co(bs, s->fd, offset, NULL, bytes, operation); + return raw_do_pwrite_zeroes(bs, offset, bytes, flags, true); } static int coroutine_fn hdev_co_create_opts(const char *filename, QemuOpts *opts, From patchwork Wed Dec 12 13:27:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726399 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F30EF14E2 for ; Wed, 12 Dec 2018 13:46:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF6A72B340 for ; Wed, 12 Dec 2018 13:46:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D379A2B354; Wed, 12 Dec 2018 13:46:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 74F9F2B340 for ; Wed, 12 Dec 2018 13:46:12 +0000 (UTC) Received: from localhost ([::1]:45005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4q3-0000tP-NA for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:46:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46411) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Yw-00037F-M9 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Yv-0001V9-KG for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39028) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4Yq-0001Q1-TM; Wed, 12 Dec 2018 08:28:25 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2EEC288302; Wed, 12 Dec 2018 13:28:24 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC8B460C44; Wed, 12 Dec 2018 13:28:19 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:13 +0100 Message-Id: <20181212132735.16080-20-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 12 Dec 2018 13:28:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 19/41] file-posix: Avoid aio_worker() for QEMU_AIO_DISCARD X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP aio_worker() doesn't add anything interesting, it's only a useless indirection. Call the handler function directly instead. As we know that this handler function is only called from coroutine context and the coroutine stays around until the worker thread finishes, we can keep RawPosixAIOData on the stack. Signed-off-by: Kevin Wolf --- block/file-posix.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 16f2b202c6..88887108a7 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1608,8 +1608,9 @@ static int handle_aiocb_copy_range(void *opaque) return 0; } -static ssize_t handle_aiocb_discard(RawPosixAIOData *aiocb) +static int handle_aiocb_discard(void *opaque) { + RawPosixAIOData *aiocb = opaque; int ret = -EOPNOTSUPP; BDRVRawState *s = aiocb->bs->opaque; @@ -1804,8 +1805,6 @@ static int aio_worker(void *arg) ret = handle_aiocb_ioctl(aiocb); break; case QEMU_AIO_DISCARD: - ret = handle_aiocb_discard(aiocb); - break; case QEMU_AIO_WRITE_ZEROES: case QEMU_AIO_WRITE_ZEROES | QEMU_AIO_DISCARD: case QEMU_AIO_COPY_RANGE: @@ -2622,11 +2621,30 @@ static void coroutine_fn raw_co_invalidate_cache(BlockDriverState *bs, } static coroutine_fn int -raw_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) +raw_do_pdiscard(BlockDriverState *bs, int64_t offset, int bytes, bool blkdev) { BDRVRawState *s = bs->opaque; + RawPosixAIOData acb; + + acb = (RawPosixAIOData) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type = QEMU_AIO_DISCARD, + .aio_offset = offset, + .aio_nbytes = bytes, + }; - return paio_submit_co(bs, s->fd, offset, NULL, bytes, QEMU_AIO_DISCARD); + if (blkdev) { + acb.aio_type |= QEMU_AIO_BLKDEV; + } + + return raw_thread_pool_submit(bs, handle_aiocb_discard, &acb); +} + +static coroutine_fn int +raw_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) +{ + return raw_do_pdiscard(bs, offset, bytes, false); } static int coroutine_fn @@ -3154,15 +3172,13 @@ static int fd_open(BlockDriverState *bs) static coroutine_fn int hdev_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) { - BDRVRawState *s = bs->opaque; int ret; ret = fd_open(bs); if (ret < 0) { return ret; } - return paio_submit_co(bs, s->fd, offset, NULL, bytes, - QEMU_AIO_DISCARD | QEMU_AIO_BLKDEV); + return raw_do_pdiscard(bs, offset, bytes, true); } static coroutine_fn int hdev_co_pwrite_zeroes(BlockDriverState *bs, From patchwork Wed Dec 12 13:27:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726405 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 87B5091E for ; Wed, 12 Dec 2018 13:47:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77A002B340 for ; Wed, 12 Dec 2018 13:47:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6BBE82B3C2; Wed, 12 Dec 2018 13:47:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 1BF032B34D for ; Wed, 12 Dec 2018 13:47:20 +0000 (UTC) Received: from localhost ([::1]:45009 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4r9-0001dz-7x for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:47:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46408) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Yw-00037C-L6 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Yv-0001V0-IA for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44078) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4Ys-0001R8-8j; Wed, 12 Dec 2018 08:28:26 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8D87E3082A26; Wed, 12 Dec 2018 13:28:25 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A9ED60C44; Wed, 12 Dec 2018 13:28:24 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:14 +0100 Message-Id: <20181212132735.16080-21-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 12 Dec 2018 13:28:25 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 20/41] file-posix: Avoid aio_worker() for QEMU_AIO_FLUSH X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP aio_worker() doesn't add anything interesting, it's only a useless indirection. Call the handler function directly instead. As we know that this handler function is only called from coroutine context and the coroutine stays around until the worker thread finishes, we can keep RawPosixAIOData on the stack. Signed-off-by: Kevin Wolf --- block/file-posix.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 88887108a7..4a94597b80 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1164,8 +1164,9 @@ static ssize_t handle_aiocb_ioctl(RawPosixAIOData *aiocb) return 0; } -static ssize_t handle_aiocb_flush(RawPosixAIOData *aiocb) +static int handle_aiocb_flush(void *opaque) { + RawPosixAIOData *aiocb = opaque; BDRVRawState *s = aiocb->bs->opaque; int ret; @@ -1798,12 +1799,10 @@ static int aio_worker(void *arg) ret = -EINVAL; } break; - case QEMU_AIO_FLUSH: - ret = handle_aiocb_flush(aiocb); - break; case QEMU_AIO_IOCTL: ret = handle_aiocb_ioctl(aiocb); break; + case QEMU_AIO_FLUSH: case QEMU_AIO_DISCARD: case QEMU_AIO_WRITE_ZEROES: case QEMU_AIO_WRITE_ZEROES | QEMU_AIO_DISCARD: @@ -1931,6 +1930,7 @@ static void raw_aio_unplug(BlockDriverState *bs) static int raw_co_flush_to_disk(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; + RawPosixAIOData acb; int ret; ret = fd_open(bs); @@ -1938,7 +1938,13 @@ static int raw_co_flush_to_disk(BlockDriverState *bs) return ret; } - return paio_submit_co(bs, s->fd, 0, NULL, 0, QEMU_AIO_FLUSH); + acb = (RawPosixAIOData) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type = QEMU_AIO_FLUSH, + }; + + return raw_thread_pool_submit(bs, handle_aiocb_flush, &acb); } static void raw_aio_attach_aio_context(BlockDriverState *bs, From patchwork Wed Dec 12 13:27:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726395 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 98B9514E2 for ; Wed, 12 Dec 2018 13:44:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 885DE28174 for ; Wed, 12 Dec 2018 13:44:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C7212B1FF; Wed, 12 Dec 2018 13:44:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 1DE6E2AE00 for ; Wed, 12 Dec 2018 13:44:11 +0000 (UTC) Received: from localhost ([::1]:44988 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4o6-0007eQ-Bl for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:44:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46410) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Yw-00037E-M7 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Yv-0001VE-Ks for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54039) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4Yt-0001S5-Ir; Wed, 12 Dec 2018 08:28:27 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E64013086259; Wed, 12 Dec 2018 13:28:26 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id D79C460C44; Wed, 12 Dec 2018 13:28:25 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:15 +0100 Message-Id: <20181212132735.16080-22-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 12 Dec 2018 13:28:26 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 21/41] file-posix: Move read/write operation logic out of aio_worker() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP aio_worker() for reads and writes isn't boring enough yet. It still does some postprocessing for handling short reads and turning the result into the right return value. However, there is no reason why handle_aiocb_rw() couldn't do the same, and even without duplicating code between the read and write path. So move the code there. Signed-off-by: Kevin Wolf --- block/file-posix.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 4a94597b80..877c0700e1 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1311,7 +1311,8 @@ static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb) * we can just use plain pread/pwrite without any problems. */ if (aiocb->io.niov == 1) { - return handle_aiocb_rw_linear(aiocb, aiocb->io.iov->iov_base); + nbytes = handle_aiocb_rw_linear(aiocb, aiocb->io.iov->iov_base); + goto out; } /* * We have more than one iovec, and all are properly aligned. @@ -1323,7 +1324,7 @@ static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb) nbytes = handle_aiocb_rw_vector(aiocb); if (nbytes == aiocb->aio_nbytes || (nbytes < 0 && nbytes != -ENOSYS)) { - return nbytes; + goto out; } preadv_present = false; } @@ -1341,7 +1342,8 @@ static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb) */ buf = qemu_try_blockalign(aiocb->bs, aiocb->aio_nbytes); if (buf == NULL) { - return -ENOMEM; + nbytes = -ENOMEM; + goto out; } if (aiocb->aio_type & QEMU_AIO_WRITE) { @@ -1375,7 +1377,21 @@ static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb) } qemu_vfree(buf); - return nbytes; +out: + if (nbytes == aiocb->aio_nbytes) { + return 0; + } else if (nbytes >= 0 && nbytes < aiocb->aio_nbytes) { + if (aiocb->aio_type & QEMU_AIO_WRITE) { + return -EINVAL; + } else { + iov_memset(aiocb->io.iov, aiocb->io.niov, nbytes, + 0, aiocb->aio_nbytes - nbytes); + return 0; + } + } else { + assert(nbytes < 0); + return nbytes; + } } #ifdef CONFIG_XFS @@ -1779,25 +1795,9 @@ static int aio_worker(void *arg) switch (aiocb->aio_type & QEMU_AIO_TYPE_MASK) { case QEMU_AIO_READ: ret = handle_aiocb_rw(aiocb); - if (ret >= 0 && ret < aiocb->aio_nbytes) { - iov_memset(aiocb->io.iov, aiocb->io.niov, ret, - 0, aiocb->aio_nbytes - ret); - - ret = aiocb->aio_nbytes; - } - if (ret == aiocb->aio_nbytes) { - ret = 0; - } else if (ret >= 0 && ret < aiocb->aio_nbytes) { - ret = -EINVAL; - } break; case QEMU_AIO_WRITE: ret = handle_aiocb_rw(aiocb); - if (ret == aiocb->aio_nbytes) { - ret = 0; - } else if (ret >= 0 && ret < aiocb->aio_nbytes) { - ret = -EINVAL; - } break; case QEMU_AIO_IOCTL: ret = handle_aiocb_ioctl(aiocb); From patchwork Wed Dec 12 13:27:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726435 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A4FDB14E2 for ; Wed, 12 Dec 2018 13:54:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93B692B3FA for ; Wed, 12 Dec 2018 13:54:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 880F52B400; Wed, 12 Dec 2018 13:54:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 3385E2B3FA for ; Wed, 12 Dec 2018 13:54:49 +0000 (UTC) Received: from localhost ([::1]:45061 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4yO-0007w9-EC for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:54:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46472) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Z1-0003C7-2Y for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Z0-0001Z3-4c for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44090) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4Yu-0001TD-VT; Wed, 12 Dec 2018 08:28:29 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4FDA43082A26; Wed, 12 Dec 2018 13:28:28 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E24A60C44; Wed, 12 Dec 2018 13:28:27 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:16 +0100 Message-Id: <20181212132735.16080-23-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 12 Dec 2018 13:28:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 22/41] file-posix: Avoid aio_worker() for QEMU_AIO_READ/WRITE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP aio_worker() doesn't add anything interesting, it's only a useless indirection. Call the handler function directly instead. As we know that this handler function is only called from coroutine context and the coroutine stays around until the worker thread finishes, we can keep RawPosixAIOData on the stack. Signed-off-by: Kevin Wolf --- block/file-posix.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 877c0700e1..0f64c83639 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1300,8 +1300,9 @@ static ssize_t handle_aiocb_rw_linear(RawPosixAIOData *aiocb, char *buf) return offset; } -static ssize_t handle_aiocb_rw(RawPosixAIOData *aiocb) +static int handle_aiocb_rw(void *opaque) { + RawPosixAIOData *aiocb = opaque; ssize_t nbytes; char *buf; @@ -1793,15 +1794,11 @@ static int aio_worker(void *arg) ssize_t ret = 0; switch (aiocb->aio_type & QEMU_AIO_TYPE_MASK) { - case QEMU_AIO_READ: - ret = handle_aiocb_rw(aiocb); - break; - case QEMU_AIO_WRITE: - ret = handle_aiocb_rw(aiocb); - break; case QEMU_AIO_IOCTL: ret = handle_aiocb_ioctl(aiocb); break; + case QEMU_AIO_READ: + case QEMU_AIO_WRITE: case QEMU_AIO_FLUSH: case QEMU_AIO_DISCARD: case QEMU_AIO_WRITE_ZEROES: @@ -1865,6 +1862,7 @@ static int coroutine_fn raw_co_prw(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int type) { BDRVRawState *s = bs->opaque; + RawPosixAIOData acb; if (fd_open(bs) < 0) return -EIO; @@ -1887,7 +1885,20 @@ static int coroutine_fn raw_co_prw(BlockDriverState *bs, uint64_t offset, } } - return paio_submit_co(bs, s->fd, offset, qiov, bytes, type); + acb = (RawPosixAIOData) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type = type, + .aio_offset = offset, + .aio_nbytes = bytes, + .io = { + .iov = qiov->iov, + .niov = qiov->niov, + }, + }; + + assert(qiov->size == bytes); + return raw_thread_pool_submit(bs, handle_aiocb_rw, &acb); } static int coroutine_fn raw_co_preadv(BlockDriverState *bs, uint64_t offset, From patchwork Wed Dec 12 13:27:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726441 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E7D15159A for ; Wed, 12 Dec 2018 13:57:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D857729436 for ; Wed, 12 Dec 2018 13:57:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC7362B32B; Wed, 12 Dec 2018 13:57:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 7734F29436 for ; Wed, 12 Dec 2018 13:57:00 +0000 (UTC) Received: from localhost ([::1]:45076 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX50V-0001KZ-CE for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:56:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46491) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Z1-0003DG-V0 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Z1-0001ZY-0R for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59196) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4Yw-0001VY-Jy; Wed, 12 Dec 2018 08:28:30 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA6FA394D4D; Wed, 12 Dec 2018 13:28:29 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id A800960C44; Wed, 12 Dec 2018 13:28:28 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:17 +0100 Message-Id: <20181212132735.16080-24-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 12 Dec 2018 13:28:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 23/41] file-posix: Remove paio_submit_co() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The function is not used any more, remove it. Signed-off-by: Kevin Wolf --- block/file-posix.c | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 0f64c83639..c8a085a911 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1824,40 +1824,6 @@ static int coroutine_fn raw_thread_pool_submit(BlockDriverState *bs, return thread_pool_submit_co(pool, func, arg); } -static int paio_submit_co_full(BlockDriverState *bs, int fd, - int64_t offset, int fd2, int64_t offset2, - QEMUIOVector *qiov, - int bytes, int type) -{ - RawPosixAIOData *acb = g_new(RawPosixAIOData, 1); - - acb->bs = bs; - acb->aio_type = type; - acb->aio_fildes = fd; - - acb->aio_nbytes = bytes; - acb->aio_offset = offset; - - if (qiov) { - acb->io.iov = qiov->iov; - acb->io.niov = qiov->niov; - assert(qiov->size == bytes); - } else { - acb->copy_range.aio_fd2 = fd2; - acb->copy_range.aio_offset2 = offset2; - } - - trace_file_paio_submit_co(offset, bytes, type); - return raw_thread_pool_submit(bs, aio_worker, acb); -} - -static inline int paio_submit_co(BlockDriverState *bs, int fd, - int64_t offset, QEMUIOVector *qiov, - int bytes, int type) -{ - return paio_submit_co_full(bs, fd, offset, -1, 0, qiov, bytes, type); -} - static int coroutine_fn raw_co_prw(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int type) { From patchwork Wed Dec 12 13:27:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726419 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D22AE14E2 for ; Wed, 12 Dec 2018 13:51:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA9142AF35 for ; Wed, 12 Dec 2018 13:51:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD9872B18A; Wed, 12 Dec 2018 13:51:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 2A4932AF35 for ; Wed, 12 Dec 2018 13:51:01 +0000 (UTC) Received: from localhost ([::1]:45021 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4ui-0003VD-Ag for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:51:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46504) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Z2-0003Dp-HO for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Z1-0001aC-CD for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53008) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4Yx-0001X8-Vx; Wed, 12 Dec 2018 08:28:32 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 28CCF30832D2; Wed, 12 Dec 2018 13:28:31 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0DA9B60C44; Wed, 12 Dec 2018 13:28:29 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:18 +0100 Message-Id: <20181212132735.16080-25-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 12 Dec 2018 13:28:31 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 24/41] file-posix: Switch to .bdrv_co_ioctl X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP No real reason to keep using the callback based mechanism here when the rest of the file-posix driver is coroutine based. Changing it brings ioctls more in line with how other request types work. Signed-off-by: Kevin Wolf --- include/scsi/pr-manager.h | 8 +++----- block/file-posix.c | 21 +++++++++++---------- scsi/pr-manager.c | 21 +++++++++------------ scsi/trace-events | 2 +- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/include/scsi/pr-manager.h b/include/scsi/pr-manager.h index 50a77b08fc..6ad5fd1ff7 100644 --- a/include/scsi/pr-manager.h +++ b/include/scsi/pr-manager.h @@ -5,6 +5,7 @@ #include "qapi/visitor.h" #include "qom/object_interfaces.h" #include "block/aio.h" +#include "qemu/coroutine.h" #define TYPE_PR_MANAGER "pr-manager" @@ -37,11 +38,8 @@ typedef struct PRManagerClass { } PRManagerClass; bool pr_manager_is_connected(PRManager *pr_mgr); -BlockAIOCB *pr_manager_execute(PRManager *pr_mgr, - AioContext *ctx, int fd, - struct sg_io_hdr *hdr, - BlockCompletionFunc *complete, - void *opaque); +int coroutine_fn pr_manager_execute(PRManager *pr_mgr, AioContext *ctx, int fd, + struct sg_io_hdr *hdr); PRManager *pr_manager_lookup(const char *id, Error **errp); diff --git a/block/file-posix.c b/block/file-posix.c index c8a085a911..9c15bbe429 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3109,24 +3109,25 @@ hdev_open_Mac_error: } #if defined(__linux__) - -static BlockAIOCB *hdev_aio_ioctl(BlockDriverState *bs, - unsigned long int req, void *buf, - BlockCompletionFunc *cb, void *opaque) +static int coroutine_fn +hdev_co_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) { BDRVRawState *s = bs->opaque; RawPosixAIOData *acb; ThreadPool *pool; + int ret; - if (fd_open(bs) < 0) - return NULL; + ret = fd_open(bs); + if (ret < 0) { + return ret; + } if (req == SG_IO && s->pr_mgr) { struct sg_io_hdr *io_hdr = buf; if (io_hdr->cmdp[0] == PERSISTENT_RESERVE_OUT || io_hdr->cmdp[0] == PERSISTENT_RESERVE_IN) { return pr_manager_execute(s->pr_mgr, bdrv_get_aio_context(bs), - s->fd, io_hdr, cb, opaque); + s->fd, io_hdr); } } @@ -3138,7 +3139,7 @@ static BlockAIOCB *hdev_aio_ioctl(BlockDriverState *bs, acb->ioctl.buf = buf; acb->ioctl.cmd = req; pool = aio_get_thread_pool(bdrv_get_aio_context(bs)); - return thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque); + return thread_pool_submit_co(pool, aio_worker, acb); } #endif /* linux */ @@ -3279,7 +3280,7 @@ static BlockDriver bdrv_host_device = { /* generic scsi device */ #ifdef __linux__ - .bdrv_aio_ioctl = hdev_aio_ioctl, + .bdrv_co_ioctl = hdev_co_ioctl, #endif }; @@ -3401,7 +3402,7 @@ static BlockDriver bdrv_host_cdrom = { .bdrv_lock_medium = cdrom_lock_medium, /* generic scsi device */ - .bdrv_aio_ioctl = hdev_aio_ioctl, + .bdrv_co_ioctl = hdev_co_ioctl, }; #endif /* __linux__ */ diff --git a/scsi/pr-manager.c b/scsi/pr-manager.c index 2a8f300dde..d9f4e8c3ad 100644 --- a/scsi/pr-manager.c +++ b/scsi/pr-manager.c @@ -48,24 +48,21 @@ static int pr_manager_worker(void *opaque) } -BlockAIOCB *pr_manager_execute(PRManager *pr_mgr, - AioContext *ctx, int fd, - struct sg_io_hdr *hdr, - BlockCompletionFunc *complete, - void *opaque) +int coroutine_fn pr_manager_execute(PRManager *pr_mgr, AioContext *ctx, int fd, + struct sg_io_hdr *hdr) { - PRManagerData *data = g_new(PRManagerData, 1); ThreadPool *pool = aio_get_thread_pool(ctx); + PRManagerData data = { + .pr_mgr = pr_mgr, + .fd = fd, + .hdr = hdr, + }; - trace_pr_manager_execute(fd, hdr->cmdp[0], hdr->cmdp[1], opaque); - data->pr_mgr = pr_mgr; - data->fd = fd; - data->hdr = hdr; + trace_pr_manager_execute(fd, hdr->cmdp[0], hdr->cmdp[1]); /* The matching object_unref is in pr_manager_worker. */ object_ref(OBJECT(pr_mgr)); - return thread_pool_submit_aio(pool, pr_manager_worker, - data, complete, opaque); + return thread_pool_submit_co(pool, pr_manager_worker, &data); } bool pr_manager_is_connected(PRManager *pr_mgr) diff --git a/scsi/trace-events b/scsi/trace-events index 45f5b6e49b..f8a68b11eb 100644 --- a/scsi/trace-events +++ b/scsi/trace-events @@ -1,3 +1,3 @@ # scsi/pr-manager.c -pr_manager_execute(int fd, int cmd, int sa, void *opaque) "fd=%d cmd=0x%02x service action=0x%02x opaque=%p" +pr_manager_execute(int fd, int cmd, int sa) "fd=%d cmd=0x%02x service action=0x%02x" pr_manager_run(int fd, int cmd, int sa) "fd=%d cmd=0x%02x service action=0x%02x" From patchwork Wed Dec 12 13:27:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726445 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 336CD14E2 for ; Wed, 12 Dec 2018 13:59:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 236E22A7C7 for ; Wed, 12 Dec 2018 13:59:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 17C9E2A7CC; Wed, 12 Dec 2018 13:59:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id B03092A7C7 for ; Wed, 12 Dec 2018 13:59:24 +0000 (UTC) Received: from localhost ([::1]:45091 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX52p-0002YN-IM for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:59:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46539) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Z4-0003FY-1X for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Z3-0001bW-0h for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47572) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4Yz-0001YE-Im; Wed, 12 Dec 2018 08:28:33 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E64FB30821FF; Wed, 12 Dec 2018 13:28:32 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id D35BF60C44; Wed, 12 Dec 2018 13:28:31 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:19 +0100 Message-Id: <20181212132735.16080-26-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 12 Dec 2018 13:28:32 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 25/41] file-posix: Avoid aio_worker() for QEMU_AIO_IOCTL X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP aio_worker() doesn't add anything interesting, it's only a useless indirection. Call the handler function directly instead. As we know that this handler function is only called from coroutine context and the coroutine stays around until the worker thread finishes, we can keep RawPosixAIOData on the stack. This was the last user of aio_worker(), so the function goes away now. Signed-off-by: Kevin Wolf --- block/file-posix.c | 55 +++++++++++++--------------------------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 9c15bbe429..a2ab2c19b8 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1152,8 +1152,9 @@ static int hdev_probe_geometry(BlockDriverState *bs, HDGeometry *geo) } #endif -static ssize_t handle_aiocb_ioctl(RawPosixAIOData *aiocb) +static int handle_aiocb_ioctl(void *opaque) { + RawPosixAIOData *aiocb = opaque; int ret; ret = ioctl(aiocb->aio_fildes, aiocb->ioctl.cmd, aiocb->ioctl.buf); @@ -1788,34 +1789,6 @@ out: return result; } -static int aio_worker(void *arg) -{ - RawPosixAIOData *aiocb = arg; - ssize_t ret = 0; - - switch (aiocb->aio_type & QEMU_AIO_TYPE_MASK) { - case QEMU_AIO_IOCTL: - ret = handle_aiocb_ioctl(aiocb); - break; - case QEMU_AIO_READ: - case QEMU_AIO_WRITE: - case QEMU_AIO_FLUSH: - case QEMU_AIO_DISCARD: - case QEMU_AIO_WRITE_ZEROES: - case QEMU_AIO_WRITE_ZEROES | QEMU_AIO_DISCARD: - case QEMU_AIO_COPY_RANGE: - case QEMU_AIO_TRUNCATE: - g_assert_not_reached(); - default: - error_report("invalid aio request (0x%x)", aiocb->aio_type); - ret = -EINVAL; - break; - } - - g_free(aiocb); - return ret; -} - static int coroutine_fn raw_thread_pool_submit(BlockDriverState *bs, ThreadPoolFunc func, void *arg) { @@ -3113,8 +3086,7 @@ static int coroutine_fn hdev_co_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) { BDRVRawState *s = bs->opaque; - RawPosixAIOData *acb; - ThreadPool *pool; + RawPosixAIOData acb; int ret; ret = fd_open(bs); @@ -3131,15 +3103,18 @@ hdev_co_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) } } - acb = g_new(RawPosixAIOData, 1); - acb->bs = bs; - acb->aio_type = QEMU_AIO_IOCTL; - acb->aio_fildes = s->fd; - acb->aio_offset = 0; - acb->ioctl.buf = buf; - acb->ioctl.cmd = req; - pool = aio_get_thread_pool(bdrv_get_aio_context(bs)); - return thread_pool_submit_co(pool, aio_worker, acb); + acb = (RawPosixAIOData) { + .bs = bs, + .aio_type = QEMU_AIO_IOCTL, + .aio_fildes = s->fd, + .aio_offset = 0, + .ioctl = { + .buf = buf, + .cmd = req, + }, + }; + + return raw_thread_pool_submit(bs, handle_aiocb_ioctl, &acb); } #endif /* linux */ From patchwork Wed Dec 12 13:27:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726447 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 70A6A159A for ; Wed, 12 Dec 2018 14:01:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BCC329E8C for ; Wed, 12 Dec 2018 14:01:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B9EB2A92A; Wed, 12 Dec 2018 14:01:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id D9ABD29E8C for ; Wed, 12 Dec 2018 14:01:56 +0000 (UTC) Received: from localhost ([::1]:45134 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX55I-0005ab-5D for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 09:01:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Z4-0003G1-6a for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Z3-0001bm-9t for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34572) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4Z1-0001ZJ-1G; Wed, 12 Dec 2018 08:28:35 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 51023811D7; Wed, 12 Dec 2018 13:28:34 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F54060C44; Wed, 12 Dec 2018 13:28:33 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:20 +0100 Message-Id: <20181212132735.16080-27-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 12 Dec 2018 13:28:34 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 26/41] block: Add bdrv_reopen_set_read_only() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alberto Garcia Most callers of bdrv_reopen() only use it to switch a BlockDriverState between read-only and read-write, so this patch adds a new function that does just that. We also want to get rid of the flags parameter in the bdrv_reopen() API, so this function sets the "read-only" option and passes the original flags (which will then be updated in bdrv_reopen_prepare()). Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- include/block/block.h | 2 ++ block.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/block/block.h b/include/block/block.h index 7f5453b45b..382e6643fc 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -303,6 +303,8 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, QDict *options, int flags); int bdrv_reopen_multiple(AioContext *ctx, BlockReopenQueue *bs_queue, Error **errp); int bdrv_reopen(BlockDriverState *bs, int bdrv_flags, Error **errp); +int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only, + Error **errp); int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, Error **errp); void bdrv_reopen_commit(BDRVReopenState *reopen_state); diff --git a/block.c b/block.c index 811239ca23..7178872560 100644 --- a/block.c +++ b/block.c @@ -3146,6 +3146,23 @@ int bdrv_reopen(BlockDriverState *bs, int bdrv_flags, Error **errp) return ret; } +int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only, + Error **errp) +{ + int ret; + BlockReopenQueue *queue; + QDict *opts = qdict_new(); + + qdict_put_bool(opts, BDRV_OPT_READ_ONLY, read_only); + + bdrv_subtree_drained_begin(bs); + queue = bdrv_reopen_queue(NULL, bs, opts, bdrv_get_flags(bs)); + ret = bdrv_reopen_multiple(bdrv_get_aio_context(bs), queue, errp); + bdrv_subtree_drained_end(bs); + + return ret; +} + static BlockReopenQueueEntry *find_parent_in_reopen_queue(BlockReopenQueue *q, BdrvChild *c) { From patchwork Wed Dec 12 13:27:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726417 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 070C291E for ; Wed, 12 Dec 2018 13:50:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAE782B075 for ; Wed, 12 Dec 2018 13:50:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF66A2B1A7; Wed, 12 Dec 2018 13:50:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 7D1B52B075 for ; Wed, 12 Dec 2018 13:50:51 +0000 (UTC) Received: from localhost ([::1]:45032 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4uY-0004a0-Kz for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:50:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46564) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4Z5-0003Hg-5l for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Z4-0001cv-C2 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34588) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4Z2-0001aP-Bm; Wed, 12 Dec 2018 08:28:36 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AC70981F0E; Wed, 12 Dec 2018 13:28:35 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BE0260C44; Wed, 12 Dec 2018 13:28:34 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:21 +0100 Message-Id: <20181212132735.16080-28-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 12 Dec 2018 13:28:35 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 27/41] block: Use bdrv_reopen_set_read_only() in bdrv_backing_update_filename() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alberto Garcia This patch replaces the bdrv_reopen() calls that set and remove the BDRV_O_RDWR flag with the new bdrv_reopen_set_read_only() function. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/block.c b/block.c index 7178872560..d7b94794f4 100644 --- a/block.c +++ b/block.c @@ -1079,11 +1079,11 @@ static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base, const char *filename, Error **errp) { BlockDriverState *parent = c->opaque; - int orig_flags = bdrv_get_flags(parent); + bool read_only = bdrv_is_read_only(parent); int ret; - if (!(orig_flags & BDRV_O_RDWR)) { - ret = bdrv_reopen(parent, orig_flags | BDRV_O_RDWR, errp); + if (read_only) { + ret = bdrv_reopen_set_read_only(parent, false, errp); if (ret < 0) { return ret; } @@ -1095,8 +1095,8 @@ static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base, error_setg_errno(errp, -ret, "Could not update backing file link"); } - if (!(orig_flags & BDRV_O_RDWR)) { - bdrv_reopen(parent, orig_flags, NULL); + if (read_only) { + bdrv_reopen_set_read_only(parent, true, NULL); } return ret; From patchwork Wed Dec 12 13:27:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726339 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1E31F13AF for ; Wed, 12 Dec 2018 13:38:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D7732836F for ; Wed, 12 Dec 2018 13:38:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA9E629535; Wed, 12 Dec 2018 13:38:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 911AE2836F for ; Wed, 12 Dec 2018 13:38:30 +0000 (UTC) Received: from localhost ([::1]:44947 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4ib-0001IW-EL for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:38:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46636) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4ZA-0003Ng-6I for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4Z9-0001gr-6k for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:44 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46822) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4Z3-0001bj-PG; Wed, 12 Dec 2018 08:28:37 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 17897C0495A1; Wed, 12 Dec 2018 13:28:37 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 05ACD60C44; Wed, 12 Dec 2018 13:28:35 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:22 +0100 Message-Id: <20181212132735.16080-29-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 12 Dec 2018 13:28:37 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 28/41] block: Use bdrv_reopen_set_read_only() in commit_start/complete() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alberto Garcia This patch replaces the bdrv_reopen() calls that set and remove the BDRV_O_RDWR flag with the new bdrv_reopen_set_read_only() function. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block/commit.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/block/commit.c b/block/commit.c index a2da5740b0..a53c2d04b0 100644 --- a/block/commit.c +++ b/block/commit.c @@ -38,7 +38,7 @@ typedef struct CommitBlockJob { BlockBackend *base; BlockDriverState *base_bs; BlockdevOnError on_error; - int base_flags; + bool base_read_only; char *backing_file_str; } CommitBlockJob; @@ -124,8 +124,8 @@ static void commit_clean(Job *job) /* restore base open flags here if appropriate (e.g., change the base back * to r/o). These reopens do not need to be atomic, since we won't abort * even on failure here */ - if (s->base_flags != bdrv_get_flags(s->base_bs)) { - bdrv_reopen(s->base_bs, s->base_flags, NULL); + if (s->base_read_only) { + bdrv_reopen_set_read_only(s->base_bs, true, NULL); } g_free(s->backing_file_str); @@ -264,7 +264,6 @@ void commit_start(const char *job_id, BlockDriverState *bs, const char *filter_node_name, Error **errp) { CommitBlockJob *s; - int orig_base_flags; BlockDriverState *iter; BlockDriverState *commit_top_bs = NULL; Error *local_err = NULL; @@ -283,11 +282,9 @@ void commit_start(const char *job_id, BlockDriverState *bs, } /* convert base to r/w, if necessary */ - orig_base_flags = bdrv_get_flags(base); - if (!(orig_base_flags & BDRV_O_RDWR)) { - bdrv_reopen(base, orig_base_flags | BDRV_O_RDWR, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); + s->base_read_only = bdrv_is_read_only(base); + if (s->base_read_only) { + if (bdrv_reopen_set_read_only(base, false, errp) != 0) { goto fail; } } @@ -363,7 +360,6 @@ void commit_start(const char *job_id, BlockDriverState *bs, goto fail; } - s->base_flags = orig_base_flags; s->backing_file_str = g_strdup(backing_file_str); s->on_error = on_error; From patchwork Wed Dec 12 13:27:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726451 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 035FA174F for ; Wed, 12 Dec 2018 14:05:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E52E62844C for ; Wed, 12 Dec 2018 14:05:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6D682B10F; Wed, 12 Dec 2018 14:05:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 6C8C92B0C3 for ; Wed, 12 Dec 2018 14:05:15 +0000 (UTC) Received: from localhost ([::1]:45180 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX58T-0007T0-J1 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 09:05:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46671) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4ZB-0003P9-D4 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4ZA-0001i5-Cv for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47618) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4Z5-0001dJ-3u; Wed, 12 Dec 2018 08:28:39 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 73A883082202; Wed, 12 Dec 2018 13:28:38 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6438960C44; Wed, 12 Dec 2018 13:28:37 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:23 +0100 Message-Id: <20181212132735.16080-30-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 12 Dec 2018 13:28:38 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 29/41] block: Use bdrv_reopen_set_read_only() in bdrv_commit() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alberto Garcia This patch replaces the bdrv_reopen() calls that set and remove the BDRV_O_RDWR flag with the new bdrv_reopen_set_read_only() function. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block/commit.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/block/commit.c b/block/commit.c index a53c2d04b0..53148e610b 100644 --- a/block/commit.c +++ b/block/commit.c @@ -391,7 +391,7 @@ int bdrv_commit(BlockDriverState *bs) BlockDriverState *commit_top_bs = NULL; BlockDriver *drv = bs->drv; int64_t offset, length, backing_length; - int ro, open_flags; + int ro; int64_t n; int ret = 0; uint8_t *buf = NULL; @@ -410,10 +410,9 @@ int bdrv_commit(BlockDriverState *bs) } ro = bs->backing->bs->read_only; - open_flags = bs->backing->bs->open_flags; if (ro) { - if (bdrv_reopen(bs->backing->bs, open_flags | BDRV_O_RDWR, NULL)) { + if (bdrv_reopen_set_read_only(bs->backing->bs, false, NULL)) { return -EACCES; } } @@ -523,7 +522,7 @@ ro_cleanup: if (ro) { /* ignoring error return here */ - bdrv_reopen(bs->backing->bs, open_flags & ~BDRV_O_RDWR, NULL); + bdrv_reopen_set_read_only(bs->backing->bs, true, NULL); } return ret; From patchwork Wed Dec 12 13:27:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726453 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E70BE159A for ; Wed, 12 Dec 2018 14:06:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6D432B10F for ; Wed, 12 Dec 2018 14:06:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C86572B138; Wed, 12 Dec 2018 14:06:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 669302B0C3 for ; Wed, 12 Dec 2018 14:06:28 +0000 (UTC) Received: from localhost ([::1]:45189 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX59f-0008RP-Im for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 09:06:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46675) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4ZB-0003PF-FG for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4ZA-0001iJ-Ed for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50828) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4Z6-0001eW-Hc; Wed, 12 Dec 2018 08:28:40 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D2653307D861; Wed, 12 Dec 2018 13:28:39 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id C090860C44; Wed, 12 Dec 2018 13:28:38 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:24 +0100 Message-Id: <20181212132735.16080-31-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 12 Dec 2018 13:28:39 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 30/41] block: Use bdrv_reopen_set_read_only() in stream_start/complete() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alberto Garcia This patch replaces the bdrv_reopen() calls that set and remove the BDRV_O_RDWR flag with the new bdrv_reopen_set_read_only() function. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block/stream.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/block/stream.c b/block/stream.c index 81a7ec8ece..7a49ac0992 100644 --- a/block/stream.c +++ b/block/stream.c @@ -34,7 +34,7 @@ typedef struct StreamBlockJob { BlockDriverState *base; BlockdevOnError on_error; char *backing_file_str; - int bs_flags; + bool bs_read_only; } StreamBlockJob; static int coroutine_fn stream_populate(BlockBackend *blk, @@ -89,10 +89,10 @@ static void stream_clean(Job *job) BlockDriverState *bs = blk_bs(bjob->blk); /* Reopen the image back in read-only mode if necessary */ - if (s->bs_flags != bdrv_get_flags(bs)) { + if (s->bs_read_only) { /* Give up write permissions before making it read-only */ blk_set_perm(bjob->blk, 0, BLK_PERM_ALL, &error_abort); - bdrv_reopen(bs, s->bs_flags, NULL); + bdrv_reopen_set_read_only(bs, true, NULL); } g_free(s->backing_file_str); @@ -226,12 +226,12 @@ void stream_start(const char *job_id, BlockDriverState *bs, { StreamBlockJob *s; BlockDriverState *iter; - int orig_bs_flags; + bool bs_read_only; /* Make sure that the image is opened in read-write mode */ - orig_bs_flags = bdrv_get_flags(bs); - if (!(orig_bs_flags & BDRV_O_RDWR)) { - if (bdrv_reopen(bs, orig_bs_flags | BDRV_O_RDWR, errp) != 0) { + bs_read_only = bdrv_is_read_only(bs); + if (bs_read_only) { + if (bdrv_reopen_set_read_only(bs, false, errp) != 0) { return; } } @@ -261,7 +261,7 @@ void stream_start(const char *job_id, BlockDriverState *bs, s->base = base; s->backing_file_str = g_strdup(backing_file_str); - s->bs_flags = orig_bs_flags; + s->bs_read_only = bs_read_only; s->on_error = on_error; trace_stream_start(bs, base, s); @@ -269,7 +269,7 @@ void stream_start(const char *job_id, BlockDriverState *bs, return; fail: - if (orig_bs_flags != bdrv_get_flags(bs)) { - bdrv_reopen(bs, orig_bs_flags, NULL); + if (bs_read_only) { + bdrv_reopen_set_read_only(bs, true, NULL); } } From patchwork Wed Dec 12 13:27:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726449 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 24AB1159A for ; Wed, 12 Dec 2018 14:04:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 137A52B09F for ; Wed, 12 Dec 2018 14:04:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 061C22B10F; Wed, 12 Dec 2018 14:04:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 8E0322B102 for ; Wed, 12 Dec 2018 14:04:01 +0000 (UTC) Received: from localhost ([::1]:45178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX57I-0007Al-AF for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 09:04:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46667) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4ZB-0003Ol-6V for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4ZA-0001iB-Dg for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47944) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4Z7-0001fI-Rm; Wed, 12 Dec 2018 08:28:41 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 39ECF3084294; Wed, 12 Dec 2018 13:28:41 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 29D8C60C44; Wed, 12 Dec 2018 13:28:39 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:25 +0100 Message-Id: <20181212132735.16080-32-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 12 Dec 2018 13:28:41 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 31/41] block: Use bdrv_reopen_set_read_only() in qmp_change_backing_file() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alberto Garcia This patch replaces the bdrv_reopen() calls that set and remove the BDRV_O_RDWR flag with the new bdrv_reopen_set_read_only() function. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- blockdev.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/blockdev.c b/blockdev.c index 81f95d920b..6fa6969cd0 100644 --- a/blockdev.c +++ b/blockdev.c @@ -4100,7 +4100,6 @@ void qmp_change_backing_file(const char *device, BlockDriverState *image_bs = NULL; Error *local_err = NULL; bool ro; - int open_flags; int ret; bs = qmp_get_root_bs(device, errp); @@ -4142,13 +4141,10 @@ void qmp_change_backing_file(const char *device, } /* if not r/w, reopen to make r/w */ - open_flags = image_bs->open_flags; ro = bdrv_is_read_only(image_bs); if (ro) { - bdrv_reopen(image_bs, open_flags | BDRV_O_RDWR, &local_err); - if (local_err) { - error_propagate(errp, local_err); + if (bdrv_reopen_set_read_only(image_bs, false, errp) != 0) { goto out; } } @@ -4164,7 +4160,7 @@ void qmp_change_backing_file(const char *device, } if (ro) { - bdrv_reopen(image_bs, open_flags, &local_err); + bdrv_reopen_set_read_only(image_bs, true, &local_err); error_propagate(errp, local_err); } From patchwork Wed Dec 12 13:27:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726455 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 33A14159A for ; Wed, 12 Dec 2018 14:07:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 226DE2844C for ; Wed, 12 Dec 2018 14:07:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 159002B10F; Wed, 12 Dec 2018 14:07:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 5EDE72844C for ; Wed, 12 Dec 2018 14:07:43 +0000 (UTC) Received: from localhost ([::1]:45193 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX5As-0000bO-1O for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 09:07:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4ZC-0003QQ-DT for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4ZB-0001jV-HV for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46215) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4Z9-0001gM-Cp; Wed, 12 Dec 2018 08:28:43 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A45A53DE04; Wed, 12 Dec 2018 13:28:42 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8880960C44; Wed, 12 Dec 2018 13:28:41 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:26 +0100 Message-Id: <20181212132735.16080-33-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 12 Dec 2018 13:28:42 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 32/41] block: Use bdrv_reopen_set_read_only() in external_snapshot_commit() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alberto Garcia This patch replaces the bdrv_reopen() call that set and remove the BDRV_O_RDWR flag with the new bdrv_reopen_set_read_only() function. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- blockdev.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/blockdev.c b/blockdev.c index 6fa6969cd0..e6c8349409 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1703,8 +1703,7 @@ static void external_snapshot_commit(BlkActionState *common) * bdrv_reopen_multiple() across all the entries at once, because we * don't want to abort all of them if one of them fails the reopen */ if (!atomic_read(&state->old_bs->copy_on_read)) { - bdrv_reopen(state->old_bs, state->old_bs->open_flags & ~BDRV_O_RDWR, - NULL); + bdrv_reopen_set_read_only(state->old_bs, true, NULL); } aio_context_release(aio_context); From patchwork Wed Dec 12 13:27:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726457 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5665B159A for ; Wed, 12 Dec 2018 14:09:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31A0C2A9CE for ; Wed, 12 Dec 2018 14:09:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 20C9A2A9D5; Wed, 12 Dec 2018 14:09:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 143ED2A0F0 for ; Wed, 12 Dec 2018 14:09:06 +0000 (UTC) Received: from localhost ([::1]:45197 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX5CD-0001XU-6m for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 09:09:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46784) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4ZI-0003X1-VX for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4ZE-0001mP-Sn for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58422) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4ZA-0001ho-NM; Wed, 12 Dec 2018 08:28:44 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0F7163082DDC; Wed, 12 Dec 2018 13:28:44 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF4D860C44; Wed, 12 Dec 2018 13:28:42 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:27 +0100 Message-Id: <20181212132735.16080-34-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 12 Dec 2018 13:28:44 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 33/41] block: Use bdrv_reopen_set_read_only() in the mirror driver X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alberto Garcia The 'block-commit' QMP command is implemented internally using two different drivers. If the source image is the active layer then the mirror driver is used (commit_active_start()), otherwise the commit driver is used (commit_start()). In both cases the destination image must be put temporarily in read-write mode. This is done correctly in the latter case, but what commit_active_start() does is copy all flags instead. This patch replaces the bdrv_reopen() calls in that function with bdrv_reopen_set_read_only() so that only the read-only status is changed. A similar change is made in mirror_exit(), which is also used by the 'drive-mirror' and 'blockdev-mirror' commands. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block/mirror.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 8f52c6215d..628f9e6a0b 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -669,9 +669,10 @@ static int mirror_exit_common(Job *job) if (s->should_complete && !abort) { BlockDriverState *to_replace = s->to_replace ?: src; + bool ro = bdrv_is_read_only(to_replace); - if (bdrv_get_flags(target_bs) != bdrv_get_flags(to_replace)) { - bdrv_reopen(target_bs, bdrv_get_flags(to_replace), NULL); + if (ro != bdrv_is_read_only(target_bs)) { + bdrv_reopen_set_read_only(target_bs, ro, NULL); } /* The mirror job has no requests in flight any more, but we need to @@ -1689,13 +1690,15 @@ void commit_active_start(const char *job_id, BlockDriverState *bs, BlockCompletionFunc *cb, void *opaque, bool auto_complete, Error **errp) { - int orig_base_flags; + bool base_read_only; Error *local_err = NULL; - orig_base_flags = bdrv_get_flags(base); + base_read_only = bdrv_is_read_only(base); - if (bdrv_reopen(base, bs->open_flags, errp)) { - return; + if (base_read_only) { + if (bdrv_reopen_set_read_only(base, false, errp) < 0) { + return; + } } mirror_start_job(job_id, bs, creation_flags, base, NULL, speed, 0, 0, @@ -1714,6 +1717,8 @@ void commit_active_start(const char *job_id, BlockDriverState *bs, error_restore_flags: /* ignore error and errp for bdrv_reopen, because we want to propagate * the original error */ - bdrv_reopen(base, orig_base_flags, NULL); + if (base_read_only) { + bdrv_reopen_set_read_only(base, true, NULL); + } return; } From patchwork Wed Dec 12 13:27:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726393 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C0D8414E2 for ; Wed, 12 Dec 2018 13:44:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEDB92B164 for ; Wed, 12 Dec 2018 13:44:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A272F2AE00; Wed, 12 Dec 2018 13:44:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 4C05C2AE00 for ; Wed, 12 Dec 2018 13:44:10 +0000 (UTC) Received: from localhost ([::1]:44986 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4o5-0007dn-Hj for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:44:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46782) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4ZI-0003Wz-VQ for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4ZE-0001ma-UA for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51282) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4ZC-0001jd-47; Wed, 12 Dec 2018 08:28:46 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6DCD2356E7; Wed, 12 Dec 2018 13:28:45 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 595C060C44; Wed, 12 Dec 2018 13:28:44 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:28 +0100 Message-Id: <20181212132735.16080-35-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 12 Dec 2018 13:28:45 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 34/41] block: Drop bdrv_reopen() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alberto Garcia No one is using this function anymore, so we can safely remove it. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- include/block/block.h | 1 - block.c | 21 --------------------- 2 files changed, 22 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 382e6643fc..de72c7a093 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -302,7 +302,6 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, BlockDriverState *bs, QDict *options, int flags); int bdrv_reopen_multiple(AioContext *ctx, BlockReopenQueue *bs_queue, Error **errp); -int bdrv_reopen(BlockDriverState *bs, int bdrv_flags, Error **errp); int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only, Error **errp); int bdrv_reopen_prepare(BDRVReopenState *reopen_state, diff --git a/block.c b/block.c index d7b94794f4..071465ee3a 100644 --- a/block.c +++ b/block.c @@ -3125,27 +3125,6 @@ cleanup: return ret; } - -/* Reopen a single BlockDriverState with the specified flags. */ -int bdrv_reopen(BlockDriverState *bs, int bdrv_flags, Error **errp) -{ - int ret = -1; - Error *local_err = NULL; - BlockReopenQueue *queue; - - bdrv_subtree_drained_begin(bs); - - queue = bdrv_reopen_queue(NULL, bs, NULL, bdrv_flags); - ret = bdrv_reopen_multiple(bdrv_get_aio_context(bs), queue, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); - } - - bdrv_subtree_drained_end(bs); - - return ret; -} - int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only, Error **errp) { From patchwork Wed Dec 12 13:27:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726415 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B0BDD14E2 for ; Wed, 12 Dec 2018 13:50:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FB502AAF6 for ; Wed, 12 Dec 2018 13:50:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 943902AC29; Wed, 12 Dec 2018 13:50:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 831A22AB3D for ; Wed, 12 Dec 2018 13:50:36 +0000 (UTC) Received: from localhost ([::1]:45031 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4uJ-0004Nz-Kv for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:50:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46834) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4ZK-0003ZI-E6 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:29:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4ZJ-0001qD-1N for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:23795) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4ZD-0001kw-F6; Wed, 12 Dec 2018 08:28:47 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CC8363082141; Wed, 12 Dec 2018 13:28:46 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id B818760C44; Wed, 12 Dec 2018 13:28:45 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:29 +0100 Message-Id: <20181212132735.16080-36-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 12 Dec 2018 13:28:46 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 35/41] qemu-io: Put flag changes in the options QDict in reopen_f() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alberto Garcia When reopen_f() puts a block device in the reopen queue, some of the new options are passed using a QDict, but others ("read-only" and the cache options) are passed as flags. This patch puts those flags in the QDict. This way the flags parameter becomes redundant and we'll be able to get rid of it in a subsequent patch. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- qemu-io-cmds.c | 27 ++++++++++++++++++++++++++- tests/qemu-iotests/133 | 9 +++++++++ tests/qemu-iotests/133.out | 8 ++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 5363482213..c9ae09d574 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -10,6 +10,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/qmp/qdict.h" #include "qemu-io.h" #include "sysemu/block-backend.h" #include "block/block.h" @@ -1978,6 +1979,7 @@ static int reopen_f(BlockBackend *blk, int argc, char **argv) int flags = bs->open_flags; bool writethrough = !blk_enable_write_cache(blk); bool has_rw_option = false; + bool has_cache_option = false; BlockReopenQueue *brq; Error *local_err = NULL; @@ -1989,6 +1991,7 @@ static int reopen_f(BlockBackend *blk, int argc, char **argv) error_report("Invalid cache option: %s", optarg); return -EINVAL; } + has_cache_option = true; break; case 'o': if (!qemu_opts_parse_noisily(&reopen_opts, optarg, 0)) { @@ -2046,9 +2049,31 @@ static int reopen_f(BlockBackend *blk, int argc, char **argv) } qopts = qemu_opts_find(&reopen_opts, NULL); - opts = qopts ? qemu_opts_to_qdict(qopts, NULL) : NULL; + opts = qopts ? qemu_opts_to_qdict(qopts, NULL) : qdict_new(); qemu_opts_reset(&reopen_opts); + if (qdict_haskey(opts, BDRV_OPT_READ_ONLY)) { + if (has_rw_option) { + error_report("Cannot set both -r/-w and '" BDRV_OPT_READ_ONLY "'"); + qobject_unref(opts); + return -EINVAL; + } + } else { + qdict_put_bool(opts, BDRV_OPT_READ_ONLY, !(flags & BDRV_O_RDWR)); + } + + if (qdict_haskey(opts, BDRV_OPT_CACHE_DIRECT) || + qdict_haskey(opts, BDRV_OPT_CACHE_NO_FLUSH)) { + if (has_cache_option) { + error_report("Cannot set both -c and the cache options"); + qobject_unref(opts); + return -EINVAL; + } + } else { + qdict_put_bool(opts, BDRV_OPT_CACHE_DIRECT, flags & BDRV_O_NOCACHE); + qdict_put_bool(opts, BDRV_OPT_CACHE_NO_FLUSH, flags & BDRV_O_NO_FLUSH); + } + bdrv_subtree_drained_begin(bs); brq = bdrv_reopen_queue(NULL, bs, opts, flags); bdrv_reopen_multiple(bdrv_get_aio_context(bs), brq, &local_err); diff --git a/tests/qemu-iotests/133 b/tests/qemu-iotests/133 index a9a47a3c36..63b25f394b 100755 --- a/tests/qemu-iotests/133 +++ b/tests/qemu-iotests/133 @@ -91,6 +91,15 @@ echo IMGOPTSSYNTAX=false $QEMU_IO -f null-co -c 'reopen' -c 'info' \ "json:{'driver': 'null-co', 'size': 65536}" +echo +echo "=== Check that mixing -c/-r/-w and their corresponding options is forbidden ===" +echo + +$QEMU_IO -c 'reopen -r -o read-only=on' $TEST_IMG +$QEMU_IO -c 'reopen -w -o read-only=on' $TEST_IMG +$QEMU_IO -c 'reopen -c none -o cache.direct=on' $TEST_IMG +$QEMU_IO -c 'reopen -c writeback -o cache.direct=on' $TEST_IMG +$QEMU_IO -c 'reopen -c directsync -o cache.no-flush=on' $TEST_IMG # success, all done echo "*** done" rm -f $seq.full diff --git a/tests/qemu-iotests/133.out b/tests/qemu-iotests/133.out index f4a85aeb63..48a9d087f0 100644 --- a/tests/qemu-iotests/133.out +++ b/tests/qemu-iotests/133.out @@ -24,4 +24,12 @@ Cannot change the option 'driver' format name: null-co format name: null-co + +=== Check that mixing -c/-r/-w and their corresponding options is forbidden === + +Cannot set both -r/-w and 'read-only' +Cannot set both -r/-w and 'read-only' +Cannot set both -c and the cache options +Cannot set both -c and the cache options +Cannot set both -c and the cache options *** done From patchwork Wed Dec 12 13:27:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726433 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0C6FF159A for ; Wed, 12 Dec 2018 13:54:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF19F29377 for ; Wed, 12 Dec 2018 13:54:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E31B62B3A6; Wed, 12 Dec 2018 13:54:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 7C50929377 for ; Wed, 12 Dec 2018 13:54:08 +0000 (UTC) Received: from localhost ([::1]:45052 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4xj-0006KP-Po for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:54:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46863) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4ZL-0003aY-E2 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4ZK-0001rj-C7 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34682) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4ZE-0001m6-VK; Wed, 12 Dec 2018 08:28:49 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 37C96811AC; Wed, 12 Dec 2018 13:28:48 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24F8960C44; Wed, 12 Dec 2018 13:28:46 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:30 +0100 Message-Id: <20181212132735.16080-37-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 12 Dec 2018 13:28:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 36/41] block: Clean up reopen_backing_file() in block/replication.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alberto Garcia This function is used to put the hidden and secondary disks in read-write mode before launching the backup job, and back in read-only mode afterwards. This patch does the following changes: - Use an options QDict with the "read-only" option instead of passing the changes as flags only. - Simplify the code (it was unnecessarily complicated and verbose). - Fix a bug due to which the secondary disk was not being put back in read-only mode when writable=false (because in this case orig_secondary_flags always had the BDRV_O_RDWR flag set). - Stop clearing the BDRV_O_INACTIVE flag. The flags parameter to bdrv_reopen_queue() becomes redundant and we'll be able to get rid of it in a subsequent patch. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block/replication.c | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/block/replication.c b/block/replication.c index 0c2989d2cb..af9dba8696 100644 --- a/block/replication.c +++ b/block/replication.c @@ -20,6 +20,7 @@ #include "block/block_backup.h" #include "sysemu/block-backend.h" #include "qapi/error.h" +#include "qapi/qmp/qdict.h" #include "replication.h" typedef enum { @@ -39,8 +40,8 @@ typedef struct BDRVReplicationState { char *top_id; ReplicationState *rs; Error *blocker; - int orig_hidden_flags; - int orig_secondary_flags; + bool orig_hidden_read_only; + bool orig_secondary_read_only; int error; } BDRVReplicationState; @@ -349,44 +350,40 @@ static void secondary_do_checkpoint(BDRVReplicationState *s, Error **errp) } } +/* This function is supposed to be called twice: + * first with writable = true, then with writable = false. + * The first call puts s->hidden_disk and s->secondary_disk in + * r/w mode, and the second puts them back in their original state. + */ static void reopen_backing_file(BlockDriverState *bs, bool writable, Error **errp) { BDRVReplicationState *s = bs->opaque; BlockReopenQueue *reopen_queue = NULL; - int orig_hidden_flags, orig_secondary_flags; - int new_hidden_flags, new_secondary_flags; Error *local_err = NULL; if (writable) { - orig_hidden_flags = s->orig_hidden_flags = - bdrv_get_flags(s->hidden_disk->bs); - new_hidden_flags = (orig_hidden_flags | BDRV_O_RDWR) & - ~BDRV_O_INACTIVE; - orig_secondary_flags = s->orig_secondary_flags = - bdrv_get_flags(s->secondary_disk->bs); - new_secondary_flags = (orig_secondary_flags | BDRV_O_RDWR) & - ~BDRV_O_INACTIVE; - } else { - orig_hidden_flags = (s->orig_hidden_flags | BDRV_O_RDWR) & - ~BDRV_O_INACTIVE; - new_hidden_flags = s->orig_hidden_flags; - orig_secondary_flags = (s->orig_secondary_flags | BDRV_O_RDWR) & - ~BDRV_O_INACTIVE; - new_secondary_flags = s->orig_secondary_flags; + s->orig_hidden_read_only = bdrv_is_read_only(s->hidden_disk->bs); + s->orig_secondary_read_only = bdrv_is_read_only(s->secondary_disk->bs); } bdrv_subtree_drained_begin(s->hidden_disk->bs); bdrv_subtree_drained_begin(s->secondary_disk->bs); - if (orig_hidden_flags != new_hidden_flags) { - reopen_queue = bdrv_reopen_queue(reopen_queue, s->hidden_disk->bs, NULL, - new_hidden_flags); + if (s->orig_hidden_read_only) { + int flags = bdrv_get_flags(s->hidden_disk->bs); + QDict *opts = qdict_new(); + qdict_put_bool(opts, BDRV_OPT_READ_ONLY, !writable); + reopen_queue = bdrv_reopen_queue(reopen_queue, s->hidden_disk->bs, + opts, flags); } - if (!(orig_secondary_flags & BDRV_O_RDWR)) { + if (s->orig_secondary_read_only) { + int flags = bdrv_get_flags(s->secondary_disk->bs); + QDict *opts = qdict_new(); + qdict_put_bool(opts, BDRV_OPT_READ_ONLY, !writable); reopen_queue = bdrv_reopen_queue(reopen_queue, s->secondary_disk->bs, - NULL, new_secondary_flags); + opts, flags); } if (reopen_queue) { From patchwork Wed Dec 12 13:27:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726439 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E61E314E2 for ; Wed, 12 Dec 2018 13:56:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D621329377 for ; Wed, 12 Dec 2018 13:56:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C9BC32AC5F; Wed, 12 Dec 2018 13:56:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 637C329377 for ; Wed, 12 Dec 2018 13:56:22 +0000 (UTC) Received: from localhost ([::1]:45067 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4zt-0008LN-Jh for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:56:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46896) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4ZM-0003bu-MV for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4ZK-0001ro-Dx for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47682) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4ZG-0001na-AM; Wed, 12 Dec 2018 08:28:50 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9F80A30820D8; Wed, 12 Dec 2018 13:28:49 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8554660C44; Wed, 12 Dec 2018 13:28:48 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:31 +0100 Message-Id: <20181212132735.16080-38-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 12 Dec 2018 13:28:49 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 37/41] block: Remove flags parameter from bdrv_reopen_queue() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alberto Garcia Now that all callers are passing all flag changes as QDict options, the flags parameter is no longer necessary, so we can get rid of it. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- include/block/block.h | 3 +-- block.c | 5 +++-- block/replication.c | 6 ++---- qemu-io-cmds.c | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index de72c7a093..f70a843b72 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -299,8 +299,7 @@ BlockDriverState *bdrv_open(const char *filename, const char *reference, BlockDriverState *bdrv_new_open_driver(BlockDriver *drv, const char *node_name, int flags, Error **errp); BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, - BlockDriverState *bs, - QDict *options, int flags); + BlockDriverState *bs, QDict *options); int bdrv_reopen_multiple(AioContext *ctx, BlockReopenQueue *bs_queue, Error **errp); int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only, Error **errp); diff --git a/block.c b/block.c index 071465ee3a..800c341244 100644 --- a/block.c +++ b/block.c @@ -3060,8 +3060,9 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, BlockDriverState *bs, - QDict *options, int flags) + QDict *options) { + int flags = bdrv_get_flags(bs); return bdrv_reopen_queue_child(bs_queue, bs, options, flags, NULL, NULL, 0); } @@ -3135,7 +3136,7 @@ int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only, qdict_put_bool(opts, BDRV_OPT_READ_ONLY, read_only); bdrv_subtree_drained_begin(bs); - queue = bdrv_reopen_queue(NULL, bs, opts, bdrv_get_flags(bs)); + queue = bdrv_reopen_queue(NULL, bs, opts); ret = bdrv_reopen_multiple(bdrv_get_aio_context(bs), queue, errp); bdrv_subtree_drained_end(bs); diff --git a/block/replication.c b/block/replication.c index af9dba8696..e70dd95001 100644 --- a/block/replication.c +++ b/block/replication.c @@ -371,19 +371,17 @@ static void reopen_backing_file(BlockDriverState *bs, bool writable, bdrv_subtree_drained_begin(s->secondary_disk->bs); if (s->orig_hidden_read_only) { - int flags = bdrv_get_flags(s->hidden_disk->bs); QDict *opts = qdict_new(); qdict_put_bool(opts, BDRV_OPT_READ_ONLY, !writable); reopen_queue = bdrv_reopen_queue(reopen_queue, s->hidden_disk->bs, - opts, flags); + opts); } if (s->orig_secondary_read_only) { - int flags = bdrv_get_flags(s->secondary_disk->bs); QDict *opts = qdict_new(); qdict_put_bool(opts, BDRV_OPT_READ_ONLY, !writable); reopen_queue = bdrv_reopen_queue(reopen_queue, s->secondary_disk->bs, - opts, flags); + opts); } if (reopen_queue) { diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index c9ae09d574..2c39124036 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -2075,7 +2075,7 @@ static int reopen_f(BlockBackend *blk, int argc, char **argv) } bdrv_subtree_drained_begin(bs); - brq = bdrv_reopen_queue(NULL, bs, opts, flags); + brq = bdrv_reopen_queue(NULL, bs, opts); bdrv_reopen_multiple(bdrv_get_aio_context(bs), brq, &local_err); bdrv_subtree_drained_end(bs); From patchwork Wed Dec 12 13:27:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726403 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 74B8914E2 for ; Wed, 12 Dec 2018 13:47:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60D8D2B354 for ; Wed, 12 Dec 2018 13:47:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 548B02B355; Wed, 12 Dec 2018 13:47:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id BB7A92B340 for ; Wed, 12 Dec 2018 13:47:19 +0000 (UTC) Received: from localhost ([::1]:45008 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4r8-0001cf-VG for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:47:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46879) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4ZM-0003bD-3z for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4ZK-0001sM-VE for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52125) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4ZH-0001oY-RS; Wed, 12 Dec 2018 08:28:52 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 11FF9811D9; Wed, 12 Dec 2018 13:28:51 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA81260C44; Wed, 12 Dec 2018 13:28:49 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:32 +0100 Message-Id: <20181212132735.16080-39-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 12 Dec 2018 13:28:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 38/41] block: Stop passing flags to bdrv_reopen_queue_child() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alberto Garcia Now that all callers are passing the new options using the QDict we no longer need the 'flags' parameter. This patch makes the following changes: 1) The update_options_from_flags() call is no longer necessary so it can be removed. 2) The update_flags_from_options() call is now used in all cases, and is moved down a few lines so it happens after the options QDict contains the final set of values. 3) The flags parameter is removed. Now the flags are initialized using the current value (for the top-level node) or the parent flags (after inherit_options()). In both cases the initial values are updated to reflect the new options in the QDict. This happens in bdrv_reopen_queue_child() (as explained above) and in bdrv_reopen_prepare(). Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block.c | 48 +++++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/block.c b/block.c index 800c341244..cb354438be 100644 --- a/block.c +++ b/block.c @@ -2931,7 +2931,6 @@ BlockDriverState *bdrv_open(const char *filename, const char *reference, static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, BlockDriverState *bs, QDict *options, - int flags, const BdrvChildRole *role, QDict *parent_options, int parent_flags) @@ -2940,7 +2939,9 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, BlockReopenQueueEntry *bs_entry; BdrvChild *child; - QDict *old_options, *explicit_options; + QDict *old_options, *explicit_options, *options_copy; + int flags; + QemuOpts *opts; /* Make sure that the caller remembered to use a drained section. This is * important to avoid graph changes between the recursive queuing here and @@ -2966,22 +2967,11 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, /* * Precedence of options: * 1. Explicitly passed in options (highest) - * 2. Set in flags (only for top level) - * 3. Retained from explicitly set options of bs - * 4. Inherited from parent node - * 5. Retained from effective options of bs + * 2. Retained from explicitly set options of bs + * 3. Inherited from parent node + * 4. Retained from effective options of bs */ - if (!parent_options) { - /* - * Any setting represented by flags is always updated. If the - * corresponding QDict option is set, it takes precedence. Otherwise - * the flag is translated into a QDict option. The old setting of bs is - * not considered. - */ - update_options_from_flags(options, flags); - } - /* Old explicitly set values (don't overwrite by inherited value) */ if (bs_entry) { old_options = qdict_clone_shallow(bs_entry->state.explicit_options); @@ -2995,16 +2985,10 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, /* Inherit from parent node */ if (parent_options) { - QemuOpts *opts; - QDict *options_copy; - assert(!flags); + flags = 0; role->inherit_options(&flags, options, parent_flags, parent_options); - options_copy = qdict_clone_shallow(options); - opts = qemu_opts_create(&bdrv_runtime_opts, NULL, 0, &error_abort); - qemu_opts_absorb_qdict(opts, options_copy, NULL); - update_flags_from_options(&flags, opts); - qemu_opts_del(opts); - qobject_unref(options_copy); + } else { + flags = bdrv_get_flags(bs); } /* Old values are used for options that aren't set yet */ @@ -3012,6 +2996,14 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, bdrv_join_options(bs, options, old_options); qobject_unref(old_options); + /* We have the final set of options so let's update the flags */ + options_copy = qdict_clone_shallow(options); + opts = qemu_opts_create(&bdrv_runtime_opts, NULL, 0, &error_abort); + qemu_opts_absorb_qdict(opts, options_copy, NULL); + update_flags_from_options(&flags, opts); + qemu_opts_del(opts); + qobject_unref(options_copy); + /* bdrv_open_inherit() sets and clears some additional flags internally */ flags &= ~BDRV_O_PROTOCOL; if (flags & BDRV_O_RDWR) { @@ -3051,7 +3043,7 @@ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, qdict_extract_subqdict(options, &new_child_options, child_key_dot); g_free(child_key_dot); - bdrv_reopen_queue_child(bs_queue, child->bs, new_child_options, 0, + bdrv_reopen_queue_child(bs_queue, child->bs, new_child_options, child->role, options, flags); } @@ -3062,9 +3054,7 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, BlockDriverState *bs, QDict *options) { - int flags = bdrv_get_flags(bs); - return bdrv_reopen_queue_child(bs_queue, bs, options, flags, - NULL, NULL, 0); + return bdrv_reopen_queue_child(bs_queue, bs, options, NULL, NULL, 0); } /* From patchwork Wed Dec 12 13:27:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726431 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1DD1214E2 for ; Wed, 12 Dec 2018 13:54:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A4C628EC6 for ; Wed, 12 Dec 2018 13:54:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F2FC429436; Wed, 12 Dec 2018 13:54:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 8815728EC6 for ; Wed, 12 Dec 2018 13:54:04 +0000 (UTC) Received: from localhost ([::1]:45058 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4xf-0007OH-Cv for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:54:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46903) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4ZN-0003cS-32 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4ZL-0001tA-W1 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48580) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4ZJ-0001pd-8q; Wed, 12 Dec 2018 08:28:53 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6EB9430917A1; Wed, 12 Dec 2018 13:28:52 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5AE5C60C44; Wed, 12 Dec 2018 13:28:51 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:33 +0100 Message-Id: <20181212132735.16080-40-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 12 Dec 2018 13:28:52 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 39/41] block: Remove assertions from update_flags_from_options() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alberto Garcia This function takes four options (cache.direct, cache.no-flush, read-only and auto-read-only) from a QemuOpts object and updates the flags accordingly. If any of those options is not set (because it was missing from the original QDict or because it had an invalid value) then the function aborts with a failed assertion: $ qemu-io -c 'reopen -o read-only=foo' hd.qcow2 block.c:1126: update_flags_from_options: Assertion `qemu_opt_find(opts, BDRV_OPT_CACHE_DIRECT)' failed. Aborted This assertion is unnecessary, and it forces any caller of bdrv_reopen() to pass all the aforementioned four options. This may have made sense in order to remove ambiguity when bdrv_reopen() was taking both flags and options, but that's not the case anymore. It's also unnecessary if we want to validate the option values, because bdrv_reopen_prepare() already takes care of that, as we can see if we remove the assertions: $ qemu-io -c 'reopen -o read-only=foo' hd.qcow2 Parameter 'read-only' expects 'on' or 'off' Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block.c | 4 ---- tests/qemu-iotests/133 | 9 +++++++++ tests/qemu-iotests/133.out | 7 +++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/block.c b/block.c index cb354438be..c6d4564bcf 100644 --- a/block.c +++ b/block.c @@ -1139,22 +1139,18 @@ static void update_flags_from_options(int *flags, QemuOpts *opts) { *flags &= ~(BDRV_O_CACHE_MASK | BDRV_O_RDWR | BDRV_O_AUTO_RDONLY); - assert(qemu_opt_find(opts, BDRV_OPT_CACHE_NO_FLUSH)); if (qemu_opt_get_bool_del(opts, BDRV_OPT_CACHE_NO_FLUSH, false)) { *flags |= BDRV_O_NO_FLUSH; } - assert(qemu_opt_find(opts, BDRV_OPT_CACHE_DIRECT)); if (qemu_opt_get_bool_del(opts, BDRV_OPT_CACHE_DIRECT, false)) { *flags |= BDRV_O_NOCACHE; } - assert(qemu_opt_find(opts, BDRV_OPT_READ_ONLY)); if (!qemu_opt_get_bool_del(opts, BDRV_OPT_READ_ONLY, false)) { *flags |= BDRV_O_RDWR; } - assert(qemu_opt_find(opts, BDRV_OPT_AUTO_READ_ONLY)); if (qemu_opt_get_bool_del(opts, BDRV_OPT_AUTO_READ_ONLY, false)) { *flags |= BDRV_O_AUTO_RDONLY; } diff --git a/tests/qemu-iotests/133 b/tests/qemu-iotests/133 index 63b25f394b..565e0b1b6e 100755 --- a/tests/qemu-iotests/133 +++ b/tests/qemu-iotests/133 @@ -100,6 +100,15 @@ $QEMU_IO -c 'reopen -w -o read-only=on' $TEST_IMG $QEMU_IO -c 'reopen -c none -o cache.direct=on' $TEST_IMG $QEMU_IO -c 'reopen -c writeback -o cache.direct=on' $TEST_IMG $QEMU_IO -c 'reopen -c directsync -o cache.no-flush=on' $TEST_IMG + +echo +echo "=== Check that invalid options are handled correctly ===" +echo + +$QEMU_IO -c 'reopen -o read-only=foo' $TEST_IMG +$QEMU_IO -c 'reopen -o cache.no-flush=bar' $TEST_IMG +$QEMU_IO -c 'reopen -o cache.direct=baz' $TEST_IMG +$QEMU_IO -c 'reopen -o auto-read-only=qux' $TEST_IMG # success, all done echo "*** done" rm -f $seq.full diff --git a/tests/qemu-iotests/133.out b/tests/qemu-iotests/133.out index 48a9d087f0..414c7fa27f 100644 --- a/tests/qemu-iotests/133.out +++ b/tests/qemu-iotests/133.out @@ -32,4 +32,11 @@ Cannot set both -r/-w and 'read-only' Cannot set both -c and the cache options Cannot set both -c and the cache options Cannot set both -c and the cache options + +=== Check that invalid options are handled correctly === + +Parameter 'read-only' expects 'on' or 'off' +Parameter 'cache.no-flush' expects 'on' or 'off' +Parameter 'cache.direct' expects 'on' or 'off' +Parameter 'auto-read-only' expects 'on' or 'off' *** done From patchwork Wed Dec 12 13:27:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726443 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B5530159A for ; Wed, 12 Dec 2018 13:58:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1E1229377 for ; Wed, 12 Dec 2018 13:58:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 95EB82AC5F; Wed, 12 Dec 2018 13:58:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 36F8829377 for ; Wed, 12 Dec 2018 13:58:31 +0000 (UTC) Received: from localhost ([::1]:45085 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX51y-0001i7-HU for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:58:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46960) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4ZW-0003kl-2X for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:29:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4ZU-0001zQ-7u for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:29:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47706) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4ZK-0001rS-H2; Wed, 12 Dec 2018 08:28:54 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D05DA30820D8; Wed, 12 Dec 2018 13:28:53 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA75860C44; Wed, 12 Dec 2018 13:28:52 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:34 +0100 Message-Id: <20181212132735.16080-41-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 12 Dec 2018 13:28:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 40/41] block: Assert that flags are up-to-date in bdrv_reopen_prepare() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alberto Garcia Towards the end of bdrv_reopen_queue_child(), before starting to process the children, the update_flags_from_options() function is called in order to have BDRVReopenState.flags in sync with the options from the QDict. This is necessary because during the reopen process flags must be updated for all nodes in the queue so bdrv_is_writable_after_reopen() and the permission checks work correctly. Because of that, calling update_flags_from_options() again in bdrv_reopen_prepare() doesn't really change the flags (they are already up-to-date). But we need to call it in order to remove those options from QemuOpts and that way indicate that they have been processed. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/block.c b/block.c index c6d4564bcf..4f5ff2cc12 100644 --- a/block.c +++ b/block.c @@ -3197,6 +3197,7 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, Error **errp) { int ret = -1; + int old_flags; Error *local_err = NULL; BlockDriver *drv; QemuOpts *opts; @@ -3223,7 +3224,12 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, goto error; } + /* This was already called in bdrv_reopen_queue_child() so the flags + * are up-to-date. This time we simply want to remove the options from + * QemuOpts in order to indicate that they have been processed. */ + old_flags = reopen_state->flags; update_flags_from_options(&reopen_state->flags, opts); + assert(old_flags == reopen_state->flags); discard = qemu_opt_get_del(opts, BDRV_OPT_DISCARD); if (discard != NULL) { From patchwork Wed Dec 12 13:27:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10726437 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C33FD14E2 for ; Wed, 12 Dec 2018 13:56:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFB9629377 for ; Wed, 12 Dec 2018 13:56:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0BD62AC5F; Wed, 12 Dec 2018 13:56:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 40E2429377 for ; Wed, 12 Dec 2018 13:56:19 +0000 (UTC) Received: from localhost ([::1]:45074 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4zq-0000mb-Fc for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 08:56:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46928) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX4ZO-0003fN-R7 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:29:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX4ZN-0001uu-Q1 for qemu-devel@nongnu.org; Wed, 12 Dec 2018 08:28:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48602) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gX4ZL-0001sY-Rm; Wed, 12 Dec 2018 08:28:55 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 39E2C3091791; Wed, 12 Dec 2018 13:28:55 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-245.ams2.redhat.com [10.36.117.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 220D460C5C; Wed, 12 Dec 2018 13:28:53 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 12 Dec 2018 14:27:35 +0100 Message-Id: <20181212132735.16080-42-kwolf@redhat.com> In-Reply-To: <20181212132735.16080-1-kwolf@redhat.com> References: <20181212132735.16080-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 12 Dec 2018 13:28:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 41/41] iotests: make 235 work on s390 (and others) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Christian Borntraeger "-machine pc" will not work all architectures. Lets fall back to the default machine by not specifying it. In addition we also need to specify -no-shutdown on s390 as qemu will exit otherwise. Cc: qemu-stable@nongnu.org Signed-off-by: Christian Borntraeger Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- tests/qemu-iotests/235 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/qemu-iotests/235 b/tests/qemu-iotests/235 index da044ed34e..d6edd97ab4 100755 --- a/tests/qemu-iotests/235 +++ b/tests/qemu-iotests/235 @@ -49,7 +49,9 @@ qemu_img_create('-f', iotests.imgfmt, '-o', 'preallocation=metadata', disk, str(size)) vm = QEMUMachine(iotests.qemu_prog) -vm.add_args('-machine', 'pc,accel=kvm') +vm.add_args('-machine', 'accel=kvm') +if iotests.qemu_default_machine == 's390-ccw-virtio': + vm.add_args('-no-shutdown') vm.add_args('-drive', 'id=src,file=' + disk) vm.launch()