From nobody Thu May 16 19:07:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675802298; cv=none; d=zohomail.com; s=zohoarc; b=HWRIo6wq0qzZ2JSPX3kbr2RuqwD35NdWxpW8bkxn68JS0Aqz2/romuSJ78NrFU0srSaeDEoiQ1Z0UJx4FQAViFECL6Qk4S95Q79D0gmZk/02dYGzDqjSsrFAWa64qaCQBkVlWIQtvgRkJZYmhznAL8S/sDITsN1jeybAvdCd7Pw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675802298; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZHAcYrwLiKzwlv8ftTovcEzHuKiOJB+r7rwtfed0E/g=; b=RpancrPZPoTD84KLs/ewBzMKvclaNfwAUV6Tn1kESkOfLlnmH7n3OGIZbB5kqZBwJerxc9GDXPldnVZKZSkmtSAFNH8Jcews9rLrCcvwfrXmPj2aWzA+J9hWhIQ+5mlYbBl+1Tc7apweUOkjhpSl7Un/GcD0S+ffycx5f8ON164= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675802298549172.53369973105112; Tue, 7 Feb 2023 12:38:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pPUiv-0000Ly-UG; Tue, 07 Feb 2023 15:37:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPUiu-0000LC-No for qemu-devel@nongnu.org; Tue, 07 Feb 2023 15:37:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPUis-0004Jd-7u for qemu-devel@nongnu.org; Tue, 07 Feb 2023 15:37:52 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-594-5iDMDd9UMuGp3_kT_rIsbA-1; Tue, 07 Feb 2023 15:37:45 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 79B51811E6E; Tue, 7 Feb 2023 20:37:45 +0000 (UTC) Received: from localhost (unknown [10.39.192.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DE2A2166B29; Tue, 7 Feb 2023 20:37:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675802269; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZHAcYrwLiKzwlv8ftTovcEzHuKiOJB+r7rwtfed0E/g=; b=MHhDtUm5DtoAaOnvrMPKd817h4tuQ9xMVr0mgUSqaUv0YCJtPe4AzNFGicSxmSdr+OeJAR eI2bsAiwn2CmHWVi3gMtpVFhqNO8UUTsjCO3myaACbgOLF5tlxBpIEXxmfIra3ksIQ8vhD QyZymKO1d8hQvZfc3xtKYKOKAVoLDV4= X-MC-Unique: 5iDMDd9UMuGp3_kT_rIsbA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Kevin Wolf , Fiona Ebner , qemu-block@nongnu.org, Fam Zheng , Stefan Hajnoczi , Hanna Reitz , qemu-stable@nongnu.org, Eric Blake Subject: [PATCH v4 1/4] block: fix detect-zeroes= with BDRV_REQ_REGISTERED_BUF Date: Tue, 7 Feb 2023 15:37:16 -0500 Message-Id: <20230207203719.242926-2-stefanha@redhat.com> In-Reply-To: <20230207203719.242926-1-stefanha@redhat.com> References: <20230207203719.242926-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675802298938100001 Content-Type: text/plain; charset="utf-8" When a write request is converted into a write zeroes request by the detect-zeroes=3D feature, it is no longer associated with an I/O buffer. The BDRV_REQ_REGISTERED_BUF flag doesn't make sense without an I/O buffer and must be cleared because bdrv_co_do_pwrite_zeroes() fails with -EINVAL when it's set. Fiona Ebner bisected and diagnosed this QEMU 7.2 regression where writes containing zeroes to a blockdev with discard=3Dunmap,detect-zeroes=3Dunmap fail. Buglink: https://gitlab.com/qemu-project/qemu/-/issues/1404 Fixes: e8b6535533be ("block: add BDRV_REQ_REGISTERED_BUF request flag") Tested-by: Fiona Ebner Cc: qemu-stable@nongnu.org Reviewed-by: Eric Blake Reviewed-by: Hanna Czenczek Signed-off-by: Stefan Hajnoczi --- block/io.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/io.c b/block/io.c index 2dc0c13e41..d2be37b11e 100644 --- a/block/io.c +++ b/block/io.c @@ -1926,6 +1926,9 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChil= d *child, if (bs->detect_zeroes =3D=3D BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP)= { flags |=3D BDRV_REQ_MAY_UNMAP; } + + /* Can't use optimization hint with bufferless zero write */ + flags &=3D ~BDRV_REQ_REGISTERED_BUF; } =20 if (ret < 0) { --=20 2.39.1 From nobody Thu May 16 19:07:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675802313; cv=none; d=zohomail.com; s=zohoarc; b=Pb/yBpe8J2H6oLnmWz92wmiLXrO/5r6GvjpFDdC5lx1ACcDaj7YNOCCbj3f83mTTxo1vhTvumeRdZzBUFDEPQsTuLGFK5oVpp2DTa7O0JK8IHLXpclyN4H9vLXUf0+P/Bnx/9+DwDekCcq+AJ4GUS8cnPa2O65UAhXPjKvf/Cmc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675802313; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=z4PEFehov0XWa5Gg2xozxFuWrmHOWJCKqvg8po4LObQ=; b=JS8csWvj19QNP8xrf7k7IiThIfYWZpuaAC91sQwhamWs/YMRzadhOq26aPhzsZUUE6pz7LytnI9egsQWHyCx4xRW6I/1t9L6wPZ3LUTDjV+qvORRs4cB29wZtKRe2Pfzncl+DfqqZcNcV2Lsn467k6fV/gLFzDmZrBI3KxdHGDA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675802313537210.76946393662; Tue, 7 Feb 2023 12:38:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pPUj5-0000U7-2O; Tue, 07 Feb 2023 15:38:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPUj2-0000TD-Lm for qemu-devel@nongnu.org; Tue, 07 Feb 2023 15:38:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPUj1-0004Lb-68 for qemu-devel@nongnu.org; Tue, 07 Feb 2023 15:38:00 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-561-7_eLY9LiO76GY53cHuKejQ-1; Tue, 07 Feb 2023 15:37:55 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 01EC8101A55E; Tue, 7 Feb 2023 20:37:55 +0000 (UTC) Received: from localhost (unknown [10.39.192.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65BA9C15BA0; Tue, 7 Feb 2023 20:37:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675802278; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z4PEFehov0XWa5Gg2xozxFuWrmHOWJCKqvg8po4LObQ=; b=C4d/JJBzTVPbpKHUGPPjUmUG89zyL3rBGiiYs4P2OZ76/RniFLYTOpoFjoPAdeQLd8G0Bq MiNrx9RPM6Ted6Cd7Xl/N065Q5vm28PwRW1VoqxQQlZWH7Am3DKWL/DhfBWfI5UIgOFUyz lXQX4xWBKcUxRqqpwfscVGPnpgcIxMo= X-MC-Unique: 7_eLY9LiO76GY53cHuKejQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Kevin Wolf , Fiona Ebner , qemu-block@nongnu.org, Fam Zheng , Stefan Hajnoczi , Hanna Reitz , Eric Blake Subject: [PATCH v4 2/4] qemu-io: use BdrvRequestFlags instead of int Date: Tue, 7 Feb 2023 15:37:17 -0500 Message-Id: <20230207203719.242926-3-stefanha@redhat.com> In-Reply-To: <20230207203719.242926-1-stefanha@redhat.com> References: <20230207203719.242926-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675802314912100003 Content-Type: text/plain; charset="utf-8" The block layer APIs use BdrvRequestFlags while qemu-io code uses int. Although the code compiles and runs fine, BdrvRequestFlags is clearer because it differentiates between other types of flags like bdrv_open() flags. This is purely refactoring. Reviewed-by: Eric Blake Reviewed-by: Hanna Czenczek Signed-off-by: Stefan Hajnoczi --- qemu-io-cmds.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index a061031615..1f60c23ba4 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -556,7 +556,7 @@ static int do_pread(BlockBackend *blk, char *buf, int64= _t offset, } =20 static int do_pwrite(BlockBackend *blk, char *buf, int64_t offset, - int64_t bytes, int flags, int64_t *total) + int64_t bytes, BdrvRequestFlags flags, int64_t *total) { int ret; =20 @@ -573,7 +573,8 @@ static int do_pwrite(BlockBackend *blk, char *buf, int6= 4_t offset, } =20 static int do_pwrite_zeroes(BlockBackend *blk, int64_t offset, - int64_t bytes, int flags, int64_t *total) + int64_t bytes, BdrvRequestFlags flags, + int64_t *total) { int ret =3D blk_pwrite_zeroes(blk, offset, bytes, flags | BDRV_REQ_ZERO_WRITE); @@ -651,7 +652,7 @@ static int do_aio_readv(BlockBackend *blk, QEMUIOVector= *qiov, } =20 static int do_aio_writev(BlockBackend *blk, QEMUIOVector *qiov, - int64_t offset, int flags, int *total) + int64_t offset, BdrvRequestFlags flags, int *tota= l) { int async_ret =3D NOT_DONE; =20 @@ -1028,7 +1029,7 @@ static int write_f(BlockBackend *blk, int argc, char = **argv) struct timespec t1, t2; bool Cflag =3D false, qflag =3D false, bflag =3D false; bool Pflag =3D false, zflag =3D false, cflag =3D false, sflag =3D fals= e; - int flags =3D 0; + BdrvRequestFlags flags =3D 0; int c, cnt, ret; char *buf =3D NULL; int64_t offset; @@ -1229,7 +1230,7 @@ static int writev_f(BlockBackend *blk, int argc, char= **argv) { struct timespec t1, t2; bool Cflag =3D false, qflag =3D false; - int flags =3D 0; + BdrvRequestFlags flags =3D 0; int c, cnt, ret; char *buf; int64_t offset; @@ -1544,7 +1545,7 @@ static int aio_write_f(BlockBackend *blk, int argc, c= har **argv) int nr_iov, c; int pattern =3D 0xcd; struct aio_ctx *ctx =3D g_new0(struct aio_ctx, 1); - int flags =3D 0; + BdrvRequestFlags flags =3D 0; =20 ctx->blk =3D blk; while ((c =3D getopt(argc, argv, "CfiqP:uz")) !=3D -1) { --=20 2.39.1 From nobody Thu May 16 19:07:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675802297; cv=none; d=zohomail.com; s=zohoarc; b=JF5ddbalLnhNujyHvzeU8M0XQVIlHxOgoAa9qjcv/vCGovVVFt00Wl1q2eZZgHnG174zo1nhLYfUras3+wmwIUDu5X8R+ClHJSEM6Y7/LeinciQ2IvoMA3u+8wqvttz52QNTnAlR4JkYwzTmDt81K3Y08yLlAOQNePlFkf5BxcQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675802297; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4Or+YkJo8aXPTL4hlov0vrubJ2fL1oqmJg/f7BAzwY0=; b=mAxH9CG1W2B1xhdj7DZE4UGCAimCuKgJoZjdIVVBO1sPTMM5a6Zph8pRlCFKijtTazqL5E7WEHJNFqFdOLokoYry5yQJQeDoLvGlIZQSSV6+PHT2haVTzW6VHq8LwUEGXpUuCX+ZFhkF5olF035pe0UiEtPrrBVrofUdocZ86C8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675802297794231.4369727153437; Tue, 7 Feb 2023 12:38:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pPUj0-0000QH-CC; Tue, 07 Feb 2023 15:37:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPUiy-0000PW-Qm for qemu-devel@nongnu.org; Tue, 07 Feb 2023 15:37:56 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPUiw-0004Kq-Da for qemu-devel@nongnu.org; Tue, 07 Feb 2023 15:37:56 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-295-K7mhCcOQNcmsD8iax7f8mg-1; Tue, 07 Feb 2023 15:37:50 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F19FB1C0A58B; Tue, 7 Feb 2023 20:37:49 +0000 (UTC) Received: from localhost (unknown [10.39.192.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id EBC462166B29; Tue, 7 Feb 2023 20:37:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675802273; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4Or+YkJo8aXPTL4hlov0vrubJ2fL1oqmJg/f7BAzwY0=; b=VNKeXvTmyNKrTyMQVNOo3mpOIcX9Jtn3YZn8ci9LnJ9uG7Y/qzMeQCtnwiYtMPjNHvcfAW ZpieGes4ySpGsBXVrn7BA23IXREtD2/lSe/BRFXIS/uxc3vToyg4gNTi/BQxU9cJbXjQ4G geiWRR/QQ9Tdtuijs79SdYnbMayxTq0= X-MC-Unique: K7mhCcOQNcmsD8iax7f8mg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Kevin Wolf , Fiona Ebner , qemu-block@nongnu.org, Fam Zheng , Stefan Hajnoczi , Hanna Reitz , Eric Blake Subject: [PATCH v4 3/4] qemu-io: add -r option to register I/O buffer Date: Tue, 7 Feb 2023 15:37:18 -0500 Message-Id: <20230207203719.242926-4-stefanha@redhat.com> In-Reply-To: <20230207203719.242926-1-stefanha@redhat.com> References: <20230207203719.242926-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675802298983100006 Content-Type: text/plain; charset="utf-8" The blk_register_buf() API is an optimization hint that allows some block drivers to avoid I/O buffer housekeeping or bounce buffers. Add an -r option to register the I/O buffer so that qemu-io can be used to test the blk_register_buf() API. The next commit will add a test that uses the new option. Reviewed-by: Eric Blake Signed-off-by: Stefan Hajnoczi Reviewed-by: Hanna Czenczek --- qemu-io-cmds.c | 204 +++++++++++++++++++++++++++++++------------------ 1 file changed, 129 insertions(+), 75 deletions(-) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 1f60c23ba4..e7a02f5b99 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -338,7 +338,8 @@ static int parse_pattern(const char *arg) */ =20 #define MISALIGN_OFFSET 16 -static void *qemu_io_alloc(BlockBackend *blk, size_t len, int pattern) +static void *qemu_io_alloc(BlockBackend *blk, size_t len, int pattern, + bool register_buf) { void *buf; =20 @@ -347,16 +348,24 @@ static void *qemu_io_alloc(BlockBackend *blk, size_t = len, int pattern) } buf =3D blk_blockalign(blk, len); memset(buf, pattern, len); + if (register_buf) { + blk_register_buf(blk, buf, len, &error_abort); + } if (qemuio_misalign) { buf +=3D MISALIGN_OFFSET; } return buf; } =20 -static void qemu_io_free(void *p) +static void qemu_io_free(BlockBackend *blk, void *p, size_t len, + bool unregister_buf) { if (qemuio_misalign) { p -=3D MISALIGN_OFFSET; + len +=3D MISALIGN_OFFSET; + } + if (unregister_buf) { + blk_unregister_buf(blk, p, len); } qemu_vfree(p); } @@ -371,14 +380,16 @@ static void qemu_io_free(void *p) * @blk - the block backend where the buffer content is going to be writte= n to * @len - the buffer length * @file_name - the file to read the content from + * @register_buf - call blk_register_buf() * * Returns: the buffer pointer on success * NULL on error */ static void *qemu_io_alloc_from_file(BlockBackend *blk, size_t len, - const char *file_name) + const char *file_name, bool register_= buf) { - char *buf, *buf_origin; + size_t alloc_len =3D len + (qemuio_misalign ? MISALIGN_OFFSET : 0); + char *alloc_buf, *buf, *end; FILE *f =3D fopen(file_name, "r"); int pattern_len; =20 @@ -387,19 +398,13 @@ static void *qemu_io_alloc_from_file(BlockBackend *bl= k, size_t len, return NULL; } =20 - if (qemuio_misalign) { - len +=3D MISALIGN_OFFSET; - } - - buf_origin =3D buf =3D blk_blockalign(blk, len); + alloc_buf =3D buf =3D blk_blockalign(blk, alloc_len); =20 if (qemuio_misalign) { - buf_origin +=3D MISALIGN_OFFSET; buf +=3D MISALIGN_OFFSET; - len -=3D MISALIGN_OFFSET; } =20 - pattern_len =3D fread(buf_origin, 1, len, f); + pattern_len =3D fread(buf, 1, len, f); =20 if (ferror(f)) { perror(file_name); @@ -414,24 +419,23 @@ static void *qemu_io_alloc_from_file(BlockBackend *bl= k, size_t len, fclose(f); f =3D NULL; =20 - if (len > pattern_len) { - len -=3D pattern_len; - buf +=3D pattern_len; - - while (len > 0) { - size_t len_to_copy =3D MIN(pattern_len, len); - - memcpy(buf, buf_origin, len_to_copy); + if (register_buf) { + blk_register_buf(blk, alloc_buf, alloc_len, &error_abort); + } =20 - len -=3D len_to_copy; - buf +=3D len_to_copy; - } + end =3D buf + len; + for (char *p =3D buf + pattern_len; p < end; p +=3D pattern_len) { + memcpy(p, buf, MIN(pattern_len, end - p)); } =20 - return buf_origin; + return buf; =20 error: - qemu_io_free(buf_origin); + /* + * This code path is only taken before blk_register_buf() is called, so + * hardcode the qemu_io_free() unregister_buf argument to false. + */ + qemu_io_free(blk, alloc_buf, alloc_len, false); if (f) { fclose(f); } @@ -490,7 +494,7 @@ static void print_report(const char *op, struct timespe= c *t, int64_t offset, */ static void * create_iovec(BlockBackend *blk, QEMUIOVector *qiov, char **argv, int nr_io= v, - int pattern) + int pattern, bool register_buf) { size_t *sizes =3D g_new0(size_t, nr_iov); size_t count =3D 0; @@ -526,7 +530,7 @@ create_iovec(BlockBackend *blk, QEMUIOVector *qiov, cha= r **argv, int nr_iov, =20 qemu_iovec_init(qiov, nr_iov); =20 - buf =3D p =3D qemu_io_alloc(blk, count, pattern); + buf =3D p =3D qemu_io_alloc(blk, count, pattern, register_buf); =20 for (i =3D 0; i < nr_iov; i++) { qemu_iovec_add(qiov, p, sizes[i]); @@ -539,7 +543,7 @@ fail: } =20 static int do_pread(BlockBackend *blk, char *buf, int64_t offset, - int64_t bytes, int64_t *total) + int64_t bytes, BdrvRequestFlags flags, int64_t *total) { int ret; =20 @@ -547,7 +551,7 @@ static int do_pread(BlockBackend *blk, char *buf, int64= _t offset, return -ERANGE; } =20 - ret =3D blk_pread(blk, offset, bytes, (uint8_t *)buf, 0); + ret =3D blk_pread(blk, offset, bytes, (uint8_t *)buf, flags); if (ret < 0) { return ret; } @@ -638,11 +642,11 @@ static void aio_rw_done(void *opaque, int ret) } =20 static int do_aio_readv(BlockBackend *blk, QEMUIOVector *qiov, - int64_t offset, int *total) + int64_t offset, BdrvRequestFlags flags, int *total) { int async_ret =3D NOT_DONE; =20 - blk_aio_preadv(blk, offset, qiov, 0, aio_rw_done, &async_ret); + blk_aio_preadv(blk, offset, qiov, flags, aio_rw_done, &async_ret); while (async_ret =3D=3D NOT_DONE) { main_loop_wait(false); } @@ -682,6 +686,7 @@ static void read_help(void) " -p, -- ignored for backwards compatibility\n" " -P, -- use a pattern to verify read data\n" " -q, -- quiet mode, do not show I/O statistics\n" +" -r, -- register I/O buffer\n" " -s, -- start offset for pattern verification (only with -P)\n" " -v, -- dump buffer to standard output\n" "\n"); @@ -695,7 +700,7 @@ static const cmdinfo_t read_cmd =3D { .cfunc =3D read_f, .argmin =3D 2, .argmax =3D -1, - .args =3D "[-abCqv] [-P pattern [-s off] [-l len]] off len", + .args =3D "[-abCqrv] [-P pattern [-s off] [-l len]] off len", .oneline =3D "reads a number of bytes at a specified offset", .help =3D read_help, }; @@ -713,8 +718,9 @@ static int read_f(BlockBackend *blk, int argc, char **a= rgv) int64_t total =3D 0; int pattern =3D 0; int64_t pattern_offset =3D 0, pattern_count =3D 0; + BdrvRequestFlags flags =3D 0; =20 - while ((c =3D getopt(argc, argv, "bCl:pP:qs:v")) !=3D -1) { + while ((c =3D getopt(argc, argv, "bCl:pP:qrs:v")) !=3D -1) { switch (c) { case 'b': bflag =3D true; @@ -743,6 +749,9 @@ static int read_f(BlockBackend *blk, int argc, char **a= rgv) case 'q': qflag =3D true; break; + case 'r': + flags |=3D BDRV_REQ_REGISTERED_BUF; + break; case 's': sflag =3D true; pattern_offset =3D cvtnum(optarg); @@ -807,15 +816,20 @@ static int read_f(BlockBackend *blk, int argc, char *= *argv) count); return -EINVAL; } + if (flags & BDRV_REQ_REGISTERED_BUF) { + printf("I/O buffer registration is not supported when reading " + "from vmstate\n"); + return -EINVAL; + } } =20 - buf =3D qemu_io_alloc(blk, count, 0xab); + buf =3D qemu_io_alloc(blk, count, 0xab, flags & BDRV_REQ_REGISTERED_BU= F); =20 clock_gettime(CLOCK_MONOTONIC, &t1); if (bflag) { ret =3D do_load_vmstate(blk, buf, offset, count, &total); } else { - ret =3D do_pread(blk, buf, offset, count, &total); + ret =3D do_pread(blk, buf, offset, count, flags, &total); } clock_gettime(CLOCK_MONOTONIC, &t2); =20 @@ -852,7 +866,7 @@ static int read_f(BlockBackend *blk, int argc, char **a= rgv) print_report("read", &t2, offset, count, total, cnt, Cflag); =20 out: - qemu_io_free(buf); + qemu_io_free(blk, buf, count, flags & BDRV_REQ_REGISTERED_BUF); return ret; } =20 @@ -870,8 +884,9 @@ static void readv_help(void) " Uses multiple iovec buffers if more than one byte range is specified.\n" " -C, -- report statistics in a machine parsable format\n" " -P, -- use a pattern to verify read data\n" -" -v, -- dump buffer to standard output\n" " -q, -- quiet mode, do not show I/O statistics\n" +" -r, -- register I/O buffer\n" +" -v, -- dump buffer to standard output\n" "\n"); } =20 @@ -882,7 +897,7 @@ static const cmdinfo_t readv_cmd =3D { .cfunc =3D readv_f, .argmin =3D 2, .argmax =3D -1, - .args =3D "[-Cqv] [-P pattern] off len [len..]", + .args =3D "[-Cqrv] [-P pattern] off len [len..]", .oneline =3D "reads a number of bytes at a specified offset", .help =3D readv_help, }; @@ -900,8 +915,9 @@ static int readv_f(BlockBackend *blk, int argc, char **= argv) QEMUIOVector qiov; int pattern =3D 0; bool Pflag =3D false; + BdrvRequestFlags flags =3D 0; =20 - while ((c =3D getopt(argc, argv, "CP:qv")) !=3D -1) { + while ((c =3D getopt(argc, argv, "CP:qrv")) !=3D -1) { switch (c) { case 'C': Cflag =3D true; @@ -916,6 +932,9 @@ static int readv_f(BlockBackend *blk, int argc, char **= argv) case 'q': qflag =3D true; break; + case 'r': + flags |=3D BDRV_REQ_REGISTERED_BUF; + break; case 'v': vflag =3D true; break; @@ -939,13 +958,14 @@ static int readv_f(BlockBackend *blk, int argc, char = **argv) optind++; =20 nr_iov =3D argc - optind; - buf =3D create_iovec(blk, &qiov, &argv[optind], nr_iov, 0xab); + buf =3D create_iovec(blk, &qiov, &argv[optind], nr_iov, 0xab, + flags & BDRV_REQ_REGISTERED_BUF); if (buf =3D=3D NULL) { return -EINVAL; } =20 clock_gettime(CLOCK_MONOTONIC, &t1); - ret =3D do_aio_readv(blk, &qiov, offset, &total); + ret =3D do_aio_readv(blk, &qiov, offset, flags, &total); clock_gettime(CLOCK_MONOTONIC, &t2); =20 if (ret < 0) { @@ -980,8 +1000,8 @@ static int readv_f(BlockBackend *blk, int argc, char *= *argv) print_report("read", &t2, offset, qiov.size, total, cnt, Cflag); =20 out: + qemu_io_free(blk, buf, qiov.size, flags & BDRV_REQ_REGISTERED_BUF); qemu_iovec_destroy(&qiov); - qemu_io_free(buf); return ret; } =20 @@ -998,13 +1018,14 @@ static void write_help(void) " filled with a set pattern (0xcdcdcdcd).\n" " -b, -- write to the VM state rather than the virtual disk\n" " -c, -- write compressed data with blk_write_compressed\n" +" -C, -- report statistics in a machine parsable format\n" " -f, -- use Force Unit Access semantics\n" " -n, -- with -z, don't allow slow fallback\n" " -p, -- ignored for backwards compatibility\n" " -P, -- use different pattern to fill file\n" +" -q, -- quiet mode, do not show I/O statistics\n" +" -r, -- register I/O buffer\n" " -s, -- use a pattern file to fill the write buffer\n" -" -C, -- report statistics in a machine parsable format\n" -" -q, -- quiet mode, do not show I/O statistics\n" " -u, -- with -z, allow unmapping\n" " -z, -- write zeroes using blk_pwrite_zeroes\n" "\n"); @@ -1019,7 +1040,7 @@ static const cmdinfo_t write_cmd =3D { .perm =3D BLK_PERM_WRITE, .argmin =3D 2, .argmax =3D -1, - .args =3D "[-bcCfnquz] [-P pattern | -s source_file] off len", + .args =3D "[-bcCfnqruz] [-P pattern | -s source_file] off len", .oneline =3D "writes a number of bytes at a specified offset", .help =3D write_help, }; @@ -1039,7 +1060,7 @@ static int write_f(BlockBackend *blk, int argc, char = **argv) int pattern =3D 0xcd; const char *file_name =3D NULL; =20 - while ((c =3D getopt(argc, argv, "bcCfnpP:qs:uz")) !=3D -1) { + while ((c =3D getopt(argc, argv, "bcCfnpP:qrs:uz")) !=3D -1) { switch (c) { case 'b': bflag =3D true; @@ -1069,6 +1090,9 @@ static int write_f(BlockBackend *blk, int argc, char = **argv) case 'q': qflag =3D true; break; + case 'r': + flags |=3D BDRV_REQ_REGISTERED_BUF; + break; case 's': sflag =3D true; file_name =3D optarg; @@ -1148,14 +1172,21 @@ static int write_f(BlockBackend *blk, int argc, cha= r **argv) } } =20 - if (!zflag) { + if (zflag) { + if (flags & BDRV_REQ_REGISTERED_BUF) { + printf("cannot combine zero write with registered I/O buffer\n= "); + return -EINVAL; + } + } else { if (sflag) { - buf =3D qemu_io_alloc_from_file(blk, count, file_name); + buf =3D qemu_io_alloc_from_file(blk, count, file_name, + flags & BDRV_REQ_REGISTERED_BUF); if (!buf) { return -EINVAL; } } else { - buf =3D qemu_io_alloc(blk, count, pattern); + buf =3D qemu_io_alloc(blk, count, pattern, + flags & BDRV_REQ_REGISTERED_BUF); } } =20 @@ -1189,7 +1220,7 @@ static int write_f(BlockBackend *blk, int argc, char = **argv) =20 out: if (!zflag) { - qemu_io_free(buf); + qemu_io_free(blk, buf, count, flags & BDRV_REQ_REGISTERED_BUF); } return ret; } @@ -1206,10 +1237,11 @@ writev_help(void) "\n" " Writes into a segment of the currently open file, using a buffer\n" " filled with a set pattern (0xcdcdcdcd).\n" -" -P, -- use different pattern to fill file\n" " -C, -- report statistics in a machine parsable format\n" " -f, -- use Force Unit Access semantics\n" +" -P, -- use different pattern to fill file\n" " -q, -- quiet mode, do not show I/O statistics\n" +" -r, -- register I/O buffer\n" "\n"); } =20 @@ -1221,7 +1253,7 @@ static const cmdinfo_t writev_cmd =3D { .perm =3D BLK_PERM_WRITE, .argmin =3D 2, .argmax =3D -1, - .args =3D "[-Cfq] [-P pattern] off len [len..]", + .args =3D "[-Cfqr] [-P pattern] off len [len..]", .oneline =3D "writes a number of bytes at a specified offset", .help =3D writev_help, }; @@ -1240,7 +1272,7 @@ static int writev_f(BlockBackend *blk, int argc, char= **argv) int pattern =3D 0xcd; QEMUIOVector qiov; =20 - while ((c =3D getopt(argc, argv, "CfqP:")) !=3D -1) { + while ((c =3D getopt(argc, argv, "CfP:qr")) !=3D -1) { switch (c) { case 'C': Cflag =3D true; @@ -1251,6 +1283,9 @@ static int writev_f(BlockBackend *blk, int argc, char= **argv) case 'q': qflag =3D true; break; + case 'r': + flags |=3D BDRV_REQ_REGISTERED_BUF; + break; case 'P': pattern =3D parse_pattern(optarg); if (pattern < 0) { @@ -1276,7 +1311,8 @@ static int writev_f(BlockBackend *blk, int argc, char= **argv) optind++; =20 nr_iov =3D argc - optind; - buf =3D create_iovec(blk, &qiov, &argv[optind], nr_iov, pattern); + buf =3D create_iovec(blk, &qiov, &argv[optind], nr_iov, pattern, + flags & BDRV_REQ_REGISTERED_BUF); if (buf =3D=3D NULL) { return -EINVAL; } @@ -1301,8 +1337,8 @@ static int writev_f(BlockBackend *blk, int argc, char= **argv) t2 =3D tsub(t2, t1); print_report("wrote", &t2, offset, qiov.size, total, cnt, Cflag); out: + qemu_io_free(blk, buf, qiov.size, flags & BDRV_REQ_REGISTERED_BUF); qemu_iovec_destroy(&qiov); - qemu_io_free(buf); return ret; } =20 @@ -1318,6 +1354,7 @@ struct aio_ctx { bool zflag; BlockAcctCookie acct; int pattern; + BdrvRequestFlags flags; struct timespec t1; }; =20 @@ -1347,7 +1384,8 @@ static void aio_write_done(void *opaque, int ret) ctx->qiov.size, 1, ctx->Cflag); out: if (!ctx->zflag) { - qemu_io_free(ctx->buf); + qemu_io_free(ctx->blk, ctx->buf, ctx->qiov.size, + ctx->flags & BDRV_REQ_REGISTERED_BUF); qemu_iovec_destroy(&ctx->qiov); } g_free(ctx); @@ -1392,7 +1430,8 @@ static void aio_read_done(void *opaque, int ret) print_report("read", &t2, ctx->offset, ctx->qiov.size, ctx->qiov.size, 1, ctx->Cflag); out: - qemu_io_free(ctx->buf); + qemu_io_free(ctx->blk, ctx->buf, ctx->qiov.size, + ctx->flags & BDRV_REQ_REGISTERED_BUF); qemu_iovec_destroy(&ctx->qiov); g_free(ctx); } @@ -1414,10 +1453,11 @@ static void aio_read_help(void) " considered successful once the request is submitted, independently\n" " of potential I/O errors or pattern mismatches.\n" " -C, -- report statistics in a machine parsable format\n" -" -P, -- use a pattern to verify read data\n" " -i, -- treat request as invalid, for exercising stats\n" -" -v, -- dump buffer to standard output\n" +" -P, -- use a pattern to verify read data\n" " -q, -- quiet mode, do not show I/O statistics\n" +" -r, -- register I/O buffer\n" +" -v, -- dump buffer to standard output\n" "\n"); } =20 @@ -1428,7 +1468,7 @@ static const cmdinfo_t aio_read_cmd =3D { .cfunc =3D aio_read_f, .argmin =3D 2, .argmax =3D -1, - .args =3D "[-Ciqv] [-P pattern] off len [len..]", + .args =3D "[-Ciqrv] [-P pattern] off len [len..]", .oneline =3D "asynchronously reads a number of bytes", .help =3D aio_read_help, }; @@ -1439,7 +1479,7 @@ static int aio_read_f(BlockBackend *blk, int argc, ch= ar **argv) struct aio_ctx *ctx =3D g_new0(struct aio_ctx, 1); =20 ctx->blk =3D blk; - while ((c =3D getopt(argc, argv, "CP:iqv")) !=3D -1) { + while ((c =3D getopt(argc, argv, "CiP:qrv")) !=3D -1) { switch (c) { case 'C': ctx->Cflag =3D true; @@ -1460,6 +1500,9 @@ static int aio_read_f(BlockBackend *blk, int argc, ch= ar **argv) case 'q': ctx->qflag =3D true; break; + case 'r': + ctx->flags |=3D BDRV_REQ_REGISTERED_BUF; + break; case 'v': ctx->vflag =3D true; break; @@ -1486,7 +1529,8 @@ static int aio_read_f(BlockBackend *blk, int argc, ch= ar **argv) optind++; =20 nr_iov =3D argc - optind; - ctx->buf =3D create_iovec(blk, &ctx->qiov, &argv[optind], nr_iov, 0xab= ); + ctx->buf =3D create_iovec(blk, &ctx->qiov, &argv[optind], nr_iov, 0xab, + ctx->flags & BDRV_REQ_REGISTERED_BUF); if (ctx->buf =3D=3D NULL) { block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_READ); g_free(ctx); @@ -1496,7 +1540,8 @@ static int aio_read_f(BlockBackend *blk, int argc, ch= ar **argv) clock_gettime(CLOCK_MONOTONIC, &ctx->t1); block_acct_start(blk_get_stats(blk), &ctx->acct, ctx->qiov.size, BLOCK_ACCT_READ); - blk_aio_preadv(blk, ctx->offset, &ctx->qiov, 0, aio_read_done, ctx); + blk_aio_preadv(blk, ctx->offset, &ctx->qiov, ctx->flags, aio_read_done, + ctx); return 0; } =20 @@ -1517,11 +1562,12 @@ static void aio_write_help(void) " Note that due to its asynchronous nature, this command will be\n" " considered successful once the request is submitted, independently\n" " of potential I/O errors or pattern mismatches.\n" -" -P, -- use different pattern to fill file\n" " -C, -- report statistics in a machine parsable format\n" " -f, -- use Force Unit Access semantics\n" " -i, -- treat request as invalid, for exercising stats\n" +" -P, -- use different pattern to fill file\n" " -q, -- quiet mode, do not show I/O statistics\n" +" -r, -- register I/O buffer\n" " -u, -- with -z, allow unmapping\n" " -z, -- write zeroes using blk_aio_pwrite_zeroes\n" "\n"); @@ -1535,7 +1581,7 @@ static const cmdinfo_t aio_write_cmd =3D { .perm =3D BLK_PERM_WRITE, .argmin =3D 2, .argmax =3D -1, - .args =3D "[-Cfiquz] [-P pattern] off len [len..]", + .args =3D "[-Cfiqruz] [-P pattern] off len [len..]", .oneline =3D "asynchronously writes a number of bytes", .help =3D aio_write_help, }; @@ -1545,22 +1591,24 @@ static int aio_write_f(BlockBackend *blk, int argc,= char **argv) int nr_iov, c; int pattern =3D 0xcd; struct aio_ctx *ctx =3D g_new0(struct aio_ctx, 1); - BdrvRequestFlags flags =3D 0; =20 ctx->blk =3D blk; - while ((c =3D getopt(argc, argv, "CfiqP:uz")) !=3D -1) { + while ((c =3D getopt(argc, argv, "CfiP:qruz")) !=3D -1) { switch (c) { case 'C': ctx->Cflag =3D true; break; case 'f': - flags |=3D BDRV_REQ_FUA; + ctx->flags |=3D BDRV_REQ_FUA; break; case 'q': ctx->qflag =3D true; break; + case 'r': + ctx->flags |=3D BDRV_REQ_REGISTERED_BUF; + break; case 'u': - flags |=3D BDRV_REQ_MAY_UNMAP; + ctx->flags |=3D BDRV_REQ_MAY_UNMAP; break; case 'P': pattern =3D parse_pattern(optarg); @@ -1596,7 +1644,7 @@ static int aio_write_f(BlockBackend *blk, int argc, c= har **argv) return -EINVAL; } =20 - if ((flags & BDRV_REQ_MAY_UNMAP) && !ctx->zflag) { + if ((ctx->flags & BDRV_REQ_MAY_UNMAP) && !ctx->zflag) { printf("-u requires -z to be specified\n"); g_free(ctx); return -EINVAL; @@ -1608,6 +1656,12 @@ static int aio_write_f(BlockBackend *blk, int argc, = char **argv) return -EINVAL; } =20 + if (ctx->zflag && (ctx->flags & BDRV_REQ_REGISTERED_BUF)) { + printf("cannot combine zero write with registered I/O buffer\n"); + g_free(ctx); + return -EINVAL; + } + ctx->offset =3D cvtnum(argv[optind]); if (ctx->offset < 0) { int ret =3D ctx->offset; @@ -1626,12 +1680,12 @@ static int aio_write_f(BlockBackend *blk, int argc,= char **argv) } =20 ctx->qiov.size =3D count; - blk_aio_pwrite_zeroes(blk, ctx->offset, count, flags, aio_write_do= ne, - ctx); + blk_aio_pwrite_zeroes(blk, ctx->offset, count, ctx->flags, + aio_write_done, ctx); } else { nr_iov =3D argc - optind; ctx->buf =3D create_iovec(blk, &ctx->qiov, &argv[optind], nr_iov, - pattern); + pattern, ctx->flags & BDRV_REQ_REGISTERED_= BUF); if (ctx->buf =3D=3D NULL) { block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_WRITE); g_free(ctx); @@ -1642,8 +1696,8 @@ static int aio_write_f(BlockBackend *blk, int argc, c= har **argv) block_acct_start(blk_get_stats(blk), &ctx->acct, ctx->qiov.size, BLOCK_ACCT_WRITE); =20 - blk_aio_pwritev(blk, ctx->offset, &ctx->qiov, flags, aio_write_don= e, - ctx); + blk_aio_pwritev(blk, ctx->offset, &ctx->qiov, ctx->flags, + aio_write_done, ctx); } =20 return 0; --=20 2.39.1 From nobody Thu May 16 19:07:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675802345; cv=none; d=zohomail.com; s=zohoarc; b=U1QPrH+jvmno6TQq0LnRVpL6SQGVSaD+besq589+OY/3S1W3Wv0h4F2q+kasO2K+PRASbKmauSXCXeebP/n6Kp+zOvwBH5y+DRXZMng1SSzWnUq3r063xaPXNgx9Y5bD2vHcq1fuFP6BYrl5y+d7J9g7aXQ+rLouMeP9qSXn0hA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675802345; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qXLS+qlXUGLXaRdiRtwVgo1stC2nNPE+FtrNAVSPfoc=; b=UlCYMC6DSWwbezQuV539uvjFEGY2LeAoXlPbhrnRE1+SBKqu2QwDdoMhVkGs2fmor6yG9eF6qi73un/tWvJ4oKOfoDX3pnSLu2H/vsakcBvH0DYFpr613snaYvO8yFoZESvaKFQSIH8wYx6dV+tAMzVIyQ6zYFVH55l5xhsINbw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675802345291741.838496033972; Tue, 7 Feb 2023 12:39:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pPUj1-0000R2-4s; Tue, 07 Feb 2023 15:37:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPUj0-0000QF-8U for qemu-devel@nongnu.org; Tue, 07 Feb 2023 15:37:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPUiy-0004L7-Nn for qemu-devel@nongnu.org; Tue, 07 Feb 2023 15:37:58 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-513-slhc1KgiN52DBwcUu0Q4Bw-1; Tue, 07 Feb 2023 15:37:53 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A0197887400; Tue, 7 Feb 2023 20:37:52 +0000 (UTC) Received: from localhost (unknown [10.39.192.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D447140EBF4; Tue, 7 Feb 2023 20:37:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675802276; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qXLS+qlXUGLXaRdiRtwVgo1stC2nNPE+FtrNAVSPfoc=; b=VWPB3965mvj9dcoxA6mD0tjNJal10wUz91gzPyftoaja5uj2soGJsmM2zcwb9wAPEITM8L tpbw6icDYT75vXaw6fph8fSsJ5E34rUJQmlA5EbZkSu7Dw0hFPb8xPC4qQPbYcXYGoZCNg zvd/om6cyCkR8ajV6sCX5NC0EjnbwKc= X-MC-Unique: slhc1KgiN52DBwcUu0Q4Bw-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Kevin Wolf , Fiona Ebner , qemu-block@nongnu.org, Fam Zheng , Stefan Hajnoczi , Hanna Reitz , Eric Blake Subject: [PATCH v4 4/4] iotests/detect-zeroes-registered-buf: add new test Date: Tue, 7 Feb 2023 15:37:19 -0500 Message-Id: <20230207203719.242926-5-stefanha@redhat.com> In-Reply-To: <20230207203719.242926-1-stefanha@redhat.com> References: <20230207203719.242926-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675802347017100003 Content-Type: text/plain; charset="utf-8" This regression test demonstrates that detect-zeroes works with registered buffers. Bug details: https://gitlab.com/qemu-project/qemu/-/issues/1404 Reviewed-by: Eric Blake Reviewed-by: Hanna Czenczek Signed-off-by: Stefan Hajnoczi --- .../tests/detect-zeroes-registered-buf | 58 +++++++++++++++++++ .../tests/detect-zeroes-registered-buf.out | 7 +++ 2 files changed, 65 insertions(+) create mode 100755 tests/qemu-iotests/tests/detect-zeroes-registered-buf create mode 100644 tests/qemu-iotests/tests/detect-zeroes-registered-buf.o= ut diff --git a/tests/qemu-iotests/tests/detect-zeroes-registered-buf b/tests/= qemu-iotests/tests/detect-zeroes-registered-buf new file mode 100755 index 0000000000..edb5f2cee5 --- /dev/null +++ b/tests/qemu-iotests/tests/detect-zeroes-registered-buf @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +# group: rw auto quick +# +# Check that detect-zeroes=3Dunmap works on writes with registered I/O buf= fers. +# This is a regression test for +# https://gitlab.com/qemu-project/qemu/-/issues/1404 where I/O requests fa= iled +# unexpectedly. +# +# Copyright Red Hat +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=3Dstefanha@redhat.com + +seq=3D`basename $0` +echo "QA output created by $seq" + +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +cd .. +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto generic + +size=3D128M +_make_test_img $size +IMGSPEC=3D"driver=3D$IMGFMT,file.filename=3D$TEST_IMG,discard=3Dunmap,dete= ct-zeroes=3Dunmap" + +echo +echo "=3D=3D writing zero buffer to image =3D=3D" +QEMU_IO_OPTIONS=3D"$QEMU_IO_OPTIONS_NO_FMT" $QEMU_IO -c "write -r -P 0 0 4= k" --image-opts "$IMGSPEC" | _filter_qemu_io + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/tests/detect-zeroes-registered-buf.out b/te= sts/qemu-iotests/tests/detect-zeroes-registered-buf.out new file mode 100644 index 0000000000..42c56fcc8d --- /dev/null +++ b/tests/qemu-iotests/tests/detect-zeroes-registered-buf.out @@ -0,0 +1,7 @@ +QA output created by detect-zeroes-registered-buf +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D134217728 + +=3D=3D writing zero buffer to image =3D=3D +wrote 4096/4096 bytes at offset 0 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +*** done --=20 2.39.1