From patchwork Thu Jun 29 13:27:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 782279 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wz14l4Wvkz9s3s for ; Thu, 29 Jun 2017 23:40:23 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="cDyjAxCe"; dkim-atps=neutral Received: from localhost ([::1]:39423 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQZgD-00007A-D8 for incoming@patchwork.ozlabs.org; Thu, 29 Jun 2017 09:40:21 -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) 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) 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) 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 = acb_to_s(acb); uint64_t offset = acb->cur_cluster + qed_offset_into_cluster(s, acb->cur_pos); - int ret; trace_qed_aio_write_main(s, acb, 0, offset, acb->cur_qiov.size); BLKDBG_EVENT(s->bs->file, BLKDBG_WRITE_AIO); - ret = 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 != 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 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 = bdrv_co_flush(s->bs->file->bs); - if (ret < 0) { - return ret; - } - } - ret = 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); } /** @@ -1050,7 +1022,29 @@ static int coroutine_fn qed_aio_write_cow(QEDAIOCB *acb) return ret; } - return qed_aio_write_main(acb); + ret = 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 = bdrv_co_flush(s->bs->file->bs); + if (ret < 0) { + return ret; + } + } + + return 0; } /** @@ -1103,6 +1097,7 @@ static int coroutine_fn qed_aio_write_alloc(QEDAIOCB *acb, size_t len) if (acb->find_cluster_ret == QED_CLUSTER_ZERO) { return 0; } + acb->cur_cluster = 1; } else { acb->cur_cluster = qed_alloc_clusters(s, acb->cur_nclusters); } @@ -1115,15 +1110,14 @@ static int coroutine_fn qed_aio_write_alloc(QEDAIOCB *acb, size_t len) } } - if (acb->flags & QED_AIOCB_ZERO) { - ret = qed_aio_write_l2_update(acb, 1); - } else { + if (!(acb->flags & QED_AIOCB_ZERO)) { ret = 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); } /**