From nobody Sun Apr 28 22:07:18 2024 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; 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 149021647887194.6217601675969; Wed, 22 Mar 2017 14:01:18 -0700 (PDT) Received: from localhost ([::1]:53283 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqnNd-0000Ft-4f for importer@patchew.org; Wed, 22 Mar 2017 17:01:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52338) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqnMp-0008Mo-Ru for qemu-devel@nongnu.org; Wed, 22 Mar 2017 17:00:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cqnMj-0003FL-9V for qemu-devel@nongnu.org; Wed, 22 Mar 2017 17:00:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39312) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cqnMe-0003Di-R4; Wed, 22 Mar 2017 17:00:16 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2BD8E437F78; Wed, 22 Mar 2017 21:00:15 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-141.ams2.redhat.com [10.36.116.141]) by smtp.corp.redhat.com (Postfix) with ESMTP id C77D51749C; Wed, 22 Mar 2017 21:00:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2BD8E437F78 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2BD8E437F78 From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 22 Mar 2017 22:00:05 +0100 Message-Id: <20170322210005.16533-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 22 Mar 2017 21:00: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] [PATCH for-2.9?] file-posix: Make bdrv_flush() failure permanent without O_DIRECT 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-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Success for bdrv_flush() means that all previously written data is safe on disk. For fdatasync(), the best semantics we can hope for on Linux (without O_DIRECT) is that all data that was written since the last call was successfully written back. Therefore, and because we can't redo all writes after a flush failure, we have to give up after a single fdatasync() failure. After this failure, we would never be able to make the promise that a successful bdrv_flush() makes. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi --- block/file-posix.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index 53febd3..beb7a4f 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -144,6 +144,7 @@ typedef struct BDRVRawState { bool has_write_zeroes:1; bool discard_zeroes:1; bool use_linux_aio:1; + bool page_cache_inconsistent:1; bool has_fallocate; bool needs_alignment; } BDRVRawState; @@ -824,10 +825,31 @@ static ssize_t handle_aiocb_ioctl(RawPosixAIOData *ai= ocb) =20 static ssize_t handle_aiocb_flush(RawPosixAIOData *aiocb) { + BDRVRawState *s =3D aiocb->bs->opaque; int ret; =20 + if (s->page_cache_inconsistent) { + return -EIO; + } + ret =3D qemu_fdatasync(aiocb->aio_fildes); if (ret =3D=3D -1) { + /* There is no clear definition of the semantics of a failing fsyn= c(), + * so we may have to assume the worst. The sad truth is that this + * assumption is correct for Linux. Some pages are now probably ma= rked + * clean in the page cache even though they are inconsistent with = the + * on-disk contents. The next fdatasync() call would succeed, but = no + * further writeback attempt will be made. We can't get back to a = state + * in which we know what is on disk (we would have to rewrite + * everything that was touched since the last fdatasync() at least= ), so + * make bdrv_flush() fail permanently. Given that the behaviour is= n't + * really defined, I have little hope that other OSes are doing be= tter. + * + * Obviously, this doesn't affect O_DIRECT, which bypasses the page + * cache. */ + if ((s->open_flags & O_DIRECT) =3D=3D 0) { + s->page_cache_inconsistent =3D true; + } return -errno; } return 0; --=20 2.9.3