From nobody Wed Feb 11 02:07:19 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 1496224160827633.7995356539582; Wed, 31 May 2017 02:49:20 -0700 (PDT) Received: from localhost ([::1]:58158 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0Fj-00075z-9Q for importer@patchew.org; Wed, 31 May 2017 05:49:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG0AL-0002W6-1L for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dG0AJ-0001mD-WA for qemu-devel@nongnu.org; Wed, 31 May 2017 05:43:45 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:34758) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dG0AJ-0001lf-Po; Wed, 31 May 2017 05:43:43 -0400 Received: by mail-wm0-x241.google.com with SMTP id d127so2257069wmf.1; Wed, 31 May 2017 02:43:43 -0700 (PDT) Received: from localhost.localdomain (94-39-157-43.adsl-ull.clienti.tiscali.it. [94.39.157.43]) by smtp.gmail.com with ESMTPSA id b30sm18150162wra.6.2017.05.31.02.43.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 May 2017 02:43:41 -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=m3Ken3+7w57u7rzo1JRocuhLxUkHyGNAPlfq2VfTqgw=; b=vXJ2aKi7tCvF7V+NEOkfnFopSL9pl19dzzAYltXBgPtlvyk2pNNm8DxU09EKVNbQE3 Y+SMznF65Hr5m8SlUKkmpioudYc6vofn4LOb0vnLtLos4ZVYpCWgGdZzJdBpUPf87j8s hujmMjNZSlkEIRTnfd785XPqPvxxGPep/40q2SISlmCQSHDMgSwXVIUH9Z9PpwN9jLhj 47aMLrp2sAzFsItk40zk7Oa3UNwxZ/jlDsFCyAx5WVaKSfu7Eqs60CymulzfRiwecmad ADy5UYecVGuW4cPG5b2X4Pn7LeuruhDQ4FDzj4f8vVKclm01frlFUYI2AgfUX0xNAkmo xy1A== 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=m3Ken3+7w57u7rzo1JRocuhLxUkHyGNAPlfq2VfTqgw=; b=BKRQLzYw77WHuPO9OAsYhHJDVLwnXgszyWcCDkxQhUhYj63G56LtmVNoM3fQyG4Y1o vNUvrNnj2pFdXCYo9PDaqvDgEMpUwNgCSlvTLWyhVUYk1C8ZOt8GkQBXNIjAfh1H1nVW D3Uzr/3ZSQ1L2cfqTX+AMTlTfY9kqIHdqMNar0T2LWyEYiNVdaQ0BvTpuVs9zoPPmNBD Kg8KFUHnXxsdH6zWG9nZX9/T3xgYRIs2DRfzPxaJ1iryit+Wd/ZtTrU2CM3lOIop24M6 rue2jZYrS2cHOkEvEBfXud7zQ2x80htbJWsB4kffHN6FBiHL8z47UyIEn3qDNxLbpBbM DJRA== X-Gm-Message-State: AODbwcC6ATy8z/+17As1ngNoC2Tn7EzHBrMIyi5gfKvkLkwG+jMN9Cva 7GKiRuJ+ybxDF5ttQhg= X-Received: by 10.28.14.205 with SMTP id 196mr4977250wmo.13.1496223822570; Wed, 31 May 2017 02:43:42 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 31 May 2017 11:43:26 +0200 Message-Id: <20170531094330.1808-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170531094330.1808-1-pbonzini@redhat.com> References: <20170531094330.1808-1-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PATCH 07/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, famz@redhat.com, qemu-block@nongnu.org, mreitz@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. Signed-off-by: Paolo Bonzini --- block/qed.c | 68 ++++++++++++++++++++++++++++-----------------------------= ---- 1 file changed, 31 insertions(+), 37 deletions(-) diff --git a/block/qed.c b/block/qed.c index ab505faa84..83a0973cfb 100644 --- a/block/qed.c +++ b/block/qed.c @@ -981,39 +981,11 @@ static int 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_pwritev(s->bs->file, offset, &acb->cur_qiov); - 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_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_pwritev(s->bs->file, offset, &acb->cur_qiov); } =20 /** @@ -1048,7 +1020,29 @@ static int 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_flush(s->bs->file->bs); + if (ret < 0) { + return ret; + } + } + + return 0; } =20 /** @@ -1101,6 +1095,7 @@ static int 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); } @@ -1113,15 +1108,14 @@ static int qed_aio_write_alloc(QEDAIOCB *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