From nobody Sat Feb 7 05:49:35 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498743670406981.1079642022701; Thu, 29 Jun 2017 06:41:10 -0700 (PDT) Received: from localhost ([::1]:39430 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZgw-00014V-1a for importer@patchew.org; Thu, 29 Jun 2017 09:41:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48919) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZUI-0005mE-3H for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:28:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQZUG-0001Op-SZ for qemu-devel@nongnu.org; Thu, 29 Jun 2017 09:28:02 -0400 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:35270) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQZUG-0001OK-Lh; Thu, 29 Jun 2017 09:28:00 -0400 Received: by mail-wr0-x242.google.com with SMTP id z45so36903914wrb.2; Thu, 29 Jun 2017 06:28:00 -0700 (PDT) Received: from localhost.localdomain (94-39-191-51.adsl-ull.clienti.tiscali.it. [94.39.191.51]) by smtp.gmail.com with ESMTPSA id i22sm4087691wrb.30.2017.06.29.06.27.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Jun 2017 06:27:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=TkrxAMVt1BjhdWLaJpV2BUGGLTWwMpPbhtzFoaLeSkQ=; b=cDyjAxCenl6W8uXri6/gAJvyEB9ORo79pGDAeXNmYzEDpf3lZ8ytoIa53Zdb1Y6Q/K RfPTK+SrO5SeF6uzbESUpOmU9yTAoH8vZHd+Vs8oGVp1Le7A9Vx9tr2PCLYo678pHR/I gT4qYJviQ/lzLoKxalDBIK9McA63Erawr3Q2vogpCEYHK370mfyhwWKBbCq09DtemYd+ gWLTWxRoPCrdmdGeM86OFU9gc0gYFL8Le4B6/x+UzesU1TBIzcx7JCvRBFQ+EYJJyOwv 0lzeyTErFM2KAgJ6kxTD2orA7mz9tv1d0JgEWRmM3HAFmY1/SQzgJ4p/5gAtw/RLKf+/ arUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=TkrxAMVt1BjhdWLaJpV2BUGGLTWwMpPbhtzFoaLeSkQ=; b=uBEhC8wm4EmAVrmghAKFRlkQVlRGRSuRWdfY6pEu7hoTkGGBNMp3DxLjkX5mzPSEnQ ghR3E0lJEjqOq5xw2xsUHhTMDS8CPDWk7k8+pFbB49kcxzx8t8eBi1rgYPBOFODi0HZX mnAW6ZhL/1agJSYOMKrtVFGWz77fVZb8X7eu3WbFZf10MQDSZt7ZzJ7stYpR5PQpU6n0 DM/iVWMYWIa/YRm0coPiQ0Hf5LsUNIK0VPi9/dfRQPNgLGbBGYxgUgI/z6f5IgToe3d5 he4xx8WkQnACP1q/erqv/2AlgfmgA3gv+H4FoRZbqLZybiVkNyoteIkqvFbSDKDhizpq 2xMw== X-Gm-Message-State: AKS2vOzhQZ2C25VvevsEQNSNVGUsZqrWyUNnon17xz1SEXNyA1KMELYA Z/zoFSLiQfFaxdOF110= X-Received: by 10.223.178.143 with SMTP id g15mr21081857wrd.144.1498742879388; Thu, 29 Jun 2017 06:27:59 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 15:27:44 +0200 Message-Id: <20170629132749.997-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170629132749.997-1-pbonzini@redhat.com> References: <20170629132749.997-1-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::242 Subject: [Qemu-devel] [PATCH 06/11] qed: move tail of qed_aio_write_main to qed_aio_write_{cow, alloc} 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, qemu-block@nongnu.org, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This part is never called for in-place writes, move it away to avoid the "backwards" coding style typical of callback-based code. Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini --- block/qed.c | 70 ++++++++++++++++++++++++++++-----------------------------= ---- 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/block/qed.c b/block/qed.c index 385381a78a..d593557522 100644 --- a/block/qed.c +++ b/block/qed.c @@ -982,40 +982,12 @@ static int coroutine_fn qed_aio_write_main(QEDAIOCB *= acb) BDRVQEDState *s =3D acb_to_s(acb); uint64_t offset =3D acb->cur_cluster + qed_offset_into_cluster(s, acb->cur_pos); - int ret; =20 trace_qed_aio_write_main(s, acb, 0, offset, acb->cur_qiov.size); =20 BLKDBG_EVENT(s->bs->file, BLKDBG_WRITE_AIO); - ret =3D bdrv_co_pwritev(s->bs->file, offset, acb->cur_qiov.size, - &acb->cur_qiov, 0); - if (ret < 0) { - return ret; - } - - if (acb->find_cluster_ret !=3D QED_CLUSTER_FOUND) { - if (s->bs->backing) { - /* - * Flush new data clusters before updating the L2 table - * - * This flush is necessary when a backing file is in use. A c= rash - * during an allocating write could result in empty clusters i= n the - * image. If the write only touched a subregion of the cluste= r, - * then backing image sectors have been lost in the untouched - * region. The solution is to flush after writing a new data - * cluster and before updating the L2 table. - */ - ret =3D bdrv_co_flush(s->bs->file->bs); - if (ret < 0) { - return ret; - } - } - ret =3D qed_aio_write_l2_update(acb, acb->cur_cluster); - if (ret < 0) { - return ret; - } - } - return 0; + return bdrv_co_pwritev(s->bs->file, offset, acb->cur_qiov.size, + &acb->cur_qiov, 0); } =20 /** @@ -1050,7 +1022,29 @@ static int coroutine_fn qed_aio_write_cow(QEDAIOCB *= acb) return ret; } =20 - return qed_aio_write_main(acb); + ret =3D qed_aio_write_main(acb); + if (ret < 0) { + return ret; + } + + if (s->bs->backing) { + /* + * Flush new data clusters before updating the L2 table + * + * This flush is necessary when a backing file is in use. A crash + * during an allocating write could result in empty clusters in the + * image. If the write only touched a subregion of the cluster, + * then backing image sectors have been lost in the untouched + * region. The solution is to flush after writing a new data + * cluster and before updating the L2 table. + */ + ret =3D bdrv_co_flush(s->bs->file->bs); + if (ret < 0) { + return ret; + } + } + + return 0; } =20 /** @@ -1103,6 +1097,7 @@ static int coroutine_fn qed_aio_write_alloc(QEDAIOCB = *acb, size_t len) if (acb->find_cluster_ret =3D=3D QED_CLUSTER_ZERO) { return 0; } + acb->cur_cluster =3D 1; } else { acb->cur_cluster =3D qed_alloc_clusters(s, acb->cur_nclusters); } @@ -1115,15 +1110,14 @@ static int coroutine_fn qed_aio_write_alloc(QEDAIOC= B *acb, size_t len) } } =20 - if (acb->flags & QED_AIOCB_ZERO) { - ret =3D qed_aio_write_l2_update(acb, 1); - } else { + if (!(acb->flags & QED_AIOCB_ZERO)) { ret =3D qed_aio_write_cow(acb); + if (ret < 0) { + return ret; + } } - if (ret < 0) { - return ret; - } - return 0; + + return qed_aio_write_l2_update(acb, acb->cur_cluster); } =20 /** --=20 2.13.0