Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2981868pxj; Mon, 17 May 2021 14:49:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyC6EYfw6YK4HT0YtbNzVZWat4oDdOolLKdQZ/sOdua9miw01PpgGkL71z6pGzJaEqx52Q X-Received: by 2002:a5d:805a:: with SMTP id b26mr1682266ior.138.1621288155997; Mon, 17 May 2021 14:49:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621288155; cv=none; d=google.com; s=arc-20160816; b=LBvMcB/3J7gpj9pygGWeXwKa5LkwEGfVuQUIuI4HFzldTXwGa6ztq28hzHhEQvk3ZT 2xdWJHlpCoAwBUPpujnlEGeCO/aAQMmZ0Iee/TqyxbD9bdsxNjP/YXPQxzu4EEoTQbn5 22yRigdIuWR9AZgsILqTZiFpuOaK557QUirkJ5VACdANMQMEgf12WJrvzzSIxZbTOkcZ 1xdzqhmYpNLGgq96wsrkBDpzDWyTqlMTiJ4kFHjIT1YgWCdzMFf6V8hMANgk3S/lpn9Q NKv/H7fEyGW6qg6rv0o74ybq08lzmnME6kCF/MyApDrk861tfJsgJtlnA3Ie3gt5jMF4 LH9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=P3cIQHoZZZJNJKluckE7XFvR4tZ2DGrSVEPqHzeob2A=; b=VpMHXyr5LMrafUAzYDoaEC14kesasp3LfCRM0jQXmeca2Uq8A+TH+6wrbHnnuqVaLE iiceEHNhxNVyx7eMJc5ZlNz4BlZc47JwYKmI6rhIdq+gVY5/3wgS342+GMfTkj6OiC/f 2CXZk3ryxlGuPMpspE+8Fp4q0Fx0e2zNQlkhxWY1ykXxo50SAlthg26a8iuRHS0BFlop ypHKZI7vmb1ijRyq4Fdt+unzOeXLI+WRwUtkGgekAsSDnsYrId+sb74859+dU/7Vas8t ZdFHDNPcB4KvIj4SQrVtAmg2qFMgLm30qAtv9W1AcmV2xjXGdkIiH+iFrEbEGSG9Dw/J DBEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cWhuci3f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p14si20115350ils.62.2021.05.17.14.49.03; Mon, 17 May 2021 14:49:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cWhuci3f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238672AbhEQOLu (ORCPT + 99 others); Mon, 17 May 2021 10:11:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:59820 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233962AbhEQOJj (ORCPT ); Mon, 17 May 2021 10:09:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id ADD3961360; Mon, 17 May 2021 14:06:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260418; bh=61xpfLXqVEMo6Yjqybp3IC64fXwudK8TBjdPC8zIexw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cWhuci3fkSKliD6ia6JxztImDrW8OYTvtENCTg8pHKhqRHt/CobbtHwq0NCz4nZbu YdgLVJDc/hvfxNqjQBxWzrlkHY5m0ME1fL4hMzfREHK8vHnXSBTBPFJfwlvpsOJgIb 5BooeXX1qfB65om42EI8M52iz14Cj3ru/GKMjwxc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vivek Goyal , Miklos Szeredi , Sasha Levin Subject: [PATCH 5.12 073/363] fuse: invalidate attrs when page writeback completes Date: Mon, 17 May 2021 15:58:59 +0200 Message-Id: <20210517140305.058970098@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vivek Goyal [ Upstream commit 3466958beb31a8e9d3a1441a34228ed088b84f3e ] In fuse when a direct/write-through write happens we invalidate attrs because that might have updated mtime/ctime on server and cached mtime/ctime will be stale. What about page writeback path. Looks like we don't invalidate attrs there. To be consistent, invalidate attrs in writeback path as well. Only exception is when writeback_cache is enabled. In that case we strust local mtime/ctime and there is no need to invalidate attrs. Recently users started experiencing failure of xfstests generic/080, geneirc/215 and generic/614 on virtiofs. This happened only newer "stat" utility and not older one. This patch fixes the issue. So what's the root cause of the issue. Here is detailed explanation. generic/080 test does mmap write to a file, closes the file and then checks if mtime has been updated or not. When file is closed, it leads to flushing of dirty pages (and that should update mtime/ctime on server). But we did not explicitly invalidate attrs after writeback finished. Still generic/080 passed so far and reason being that we invalidated atime in fuse_readpages_end(). This is called in fuse_readahead() path and always seems to trigger before mmaped write. So after mmaped write when lstat() is called, it sees that atleast one of the fields being asked for is invalid (atime) and that results in generating GETATTR to server and mtime/ctime also get updated and test passes. But newer /usr/bin/stat seems to have moved to using statx() syscall now (instead of using lstat()). And statx() allows it to query only ctime or mtime (and not rest of the basic stat fields). That means when querying for mtime, fuse_update_get_attr() sees that mtime is not invalid (only atime is invalid). So it does not generate a new GETATTR and fill stat with cached mtime/ctime. And that means updated mtime is not seen by xfstest and tests start failing. Invalidating attrs after writeback completion should solve this problem in a generic manner. Signed-off-by: Vivek Goyal Signed-off-by: Miklos Szeredi Signed-off-by: Sasha Levin --- fs/fuse/file.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index eff4abaa87da..6e6d1e599869 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -1776,8 +1776,17 @@ static void fuse_writepage_end(struct fuse_mount *fm, struct fuse_args *args, container_of(args, typeof(*wpa), ia.ap.args); struct inode *inode = wpa->inode; struct fuse_inode *fi = get_fuse_inode(inode); + struct fuse_conn *fc = get_fuse_conn(inode); mapping_set_error(inode->i_mapping, error); + /* + * A writeback finished and this might have updated mtime/ctime on + * server making local mtime/ctime stale. Hence invalidate attrs. + * Do this only if writeback_cache is not enabled. If writeback_cache + * is enabled, we trust local ctime/mtime. + */ + if (!fc->writeback_cache) + fuse_invalidate_attr(inode); spin_lock(&fi->lock); rb_erase(&wpa->writepages_entry, &fi->writepages); while (wpa->next) { -- 2.30.2