Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4483803ybx; Mon, 4 Nov 2019 14:11:15 -0800 (PST) X-Google-Smtp-Source: APXvYqzHDXBDA361rOkoQ/N1WYpvAYD5kUwwbk3HaITZehymosarodv3I37fEn/U6bY9Oxumfx/o X-Received: by 2002:a17:907:2061:: with SMTP id qp1mr9890948ejb.43.1572905475826; Mon, 04 Nov 2019 14:11:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572905475; cv=none; d=google.com; s=arc-20160816; b=M8s3hMU7yT4E5Y5TylqvCEBpMMZK1AHzaKXoNc44RHsqSkgS78XfEH6jCivlNjGhhc SSIZcAmZP3ZPqyo3iRUi0uGDZtXzLLFtYsBFO0vzGz9Zn+vy6tuX4T0PIEmukzLBQUn8 LvpbH+Xo50V7HYTJX5QYQWZKxEwkX4ym2c0qFA4ihuYJNsM7NJ2p4mpZK3y4XOn8LvWl wgIaFcf7e400VF5pYmrTHhoFPGO5/ejBiJloNSGg42eRbiZdnPjj4NRAoAxUxd+SyjGL mTBljPR/VYISee+oiDEb5gJOCoD9sjWLdpjqsrR2xzCRGwfJqxYJnpKj//4F+chEIW+e HHeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GhN6CRzS+LdGH1SbyL8q57tbrxXpYw97Il7izmEQyHo=; b=CpXxCWVflKXWD5hatGQj4tDLUymhfFMngpOEGYr6alj5YPyBHDL4EMqM4Lc466muHL fRFZDNfb4OKzC+RMwtQnP582UR97rczefZdxs3AHdEUSjAqh92+wK85DEe7rn212mvoJ wn2cZ8OpnfblUuHPG8E7RaDaOL574hHdD0COTfVf9ih2Lb4r5jmibLe4yOgTK1lLKp18 wQuvv1c71QfBGZnrMBLQ9xpyPIfpmyALQIaT6Z7Kxhr26fvL5dmMS8qxjsYonGkwxRlK pFc6CXEfih6cqgc8HZ7WYPP4L9IaRKcY4nQPaPcAG6NWClOBox83O4j7fgHuJwXm1W2H dt3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bSC2hclU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b18si7593177edc.390.2019.11.04.14.10.52; Mon, 04 Nov 2019 14:11:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bSC2hclU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389804AbfKDWKY (ORCPT + 99 others); Mon, 4 Nov 2019 17:10:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:43486 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390522AbfKDWKT (ORCPT ); Mon, 4 Nov 2019 17:10:19 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4B2EC20650; Mon, 4 Nov 2019 22:10:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572905418; bh=hnk8VfwAow7cYuRhDBroNSThsGc48+kAJd2FwB4YOvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bSC2hclUNBiW2j4jZfGVbIhKh4Dfhpcvo4/XtaZq3O+H2lO7mz5nk2GpzLtBRulz9 AcQ+73bHThcq8NpGpXQ8T1wfXXzH0tMa5tvfSvU5adnysaVHDLBVER1o9bOclAmj8q Gm5+f/bd2+w+WanRVJE5eqretXdUdSvsZa8Csol8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miklos Szeredi Subject: [PATCH 5.3 096/163] fuse: truncate pending writes on O_TRUNC Date: Mon, 4 Nov 2019 22:44:46 +0100 Message-Id: <20191104212147.071968528@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212140.046021995@linuxfoundation.org> References: <20191104212140.046021995@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miklos Szeredi commit e4648309b85a78f8c787457832269a8712a8673e upstream. Make sure cached writes are not reordered around open(..., O_TRUNC), with the obvious wrong results. Fixes: 4d99ff8f12eb ("fuse: Turn writeback cache on") Cc: # v3.15+ Signed-off-by: Miklos Szeredi Signed-off-by: Greg Kroah-Hartman --- fs/fuse/file.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -201,7 +201,7 @@ int fuse_open_common(struct inode *inode { struct fuse_conn *fc = get_fuse_conn(inode); int err; - bool lock_inode = (file->f_flags & O_TRUNC) && + bool is_wb_truncate = (file->f_flags & O_TRUNC) && fc->atomic_o_trunc && fc->writeback_cache; @@ -209,16 +209,20 @@ int fuse_open_common(struct inode *inode if (err) return err; - if (lock_inode) + if (is_wb_truncate) { inode_lock(inode); + fuse_set_nowrite(inode); + } err = fuse_do_open(fc, get_node_id(inode), file, isdir); if (!err) fuse_finish_open(inode, file); - if (lock_inode) + if (is_wb_truncate) { + fuse_release_nowrite(inode); inode_unlock(inode); + } return err; }