From patchwork Fri Sep 28 15:42:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 10620127 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9BD0A15A6 for ; Fri, 28 Sep 2018 15:43:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 939F228BE0 for ; Fri, 28 Sep 2018 15:43:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87F5928CBE; Fri, 28 Sep 2018 15:43:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F17F128D23 for ; Fri, 28 Sep 2018 15:43:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729413AbeI1WHY (ORCPT ); Fri, 28 Sep 2018 18:07:24 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:39281 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729464AbeI1WHL (ORCPT ); Fri, 28 Sep 2018 18:07:11 -0400 Received: by mail-wr1-f67.google.com with SMTP id s14-v6so6889174wrw.6 for ; Fri, 28 Sep 2018 08:42:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=B2ZwOEo60CdExzSgD8bIEzDFyWtJeUcZ0M09C+yFE00=; b=qEES8Ylo00XpTWVdfLh4qlvOa24Iu7ocW6A0YqL46Hi8eO+Ekc1Kgf8oXRZtfRkZkg 3WQSWGRtNX9frJyAX1vvsXIWwM7xe1LxLmEn6zjDdU6bUzEfLGI7FjPFvmM3dwopUoQr qkaMKXgyQvNWS9HeTpH3M3oF5166rT2U7gt+vjrJ45q0F0jHGV7mbr6pWnrG4S/f4bXu +dR4nJ8iU0/ex28pPLElJFu3BpE1jwdiiUO2pdFubMUN/lLpYH8CA+X7bzHu1Jjztnpx 4U/6GFnWFJaG5Xj1BqPt8VkyNlwKcpWs5WuIXCrh9FU0mtmSb48tkr8VmaM2VVKhadpq kIzQ== X-Gm-Message-State: ABuFfogEzMZe70rFKtCrEhY9zLVc9splWwUaYXZ0zDSRURtlb5D8JReO b9wmn7Fs2fnHbhYfHaoOXI4YkWndtbA= X-Google-Smtp-Source: ACcGV624Ai74gf20ZHY6Qn04ZIp5HmytJWMSksJEoTRQtUyzQFNQX6E1b2Uw2uPqG5M5diyLintijA== X-Received: by 2002:adf:afdd:: with SMTP id y29-v6mr9268990wrd.176.1538149370293; Fri, 28 Sep 2018 08:42:50 -0700 (PDT) Received: from veci.piliscsaba.redhat.com (catv-212-96-48-140.catv.broadband.hu. [212.96.48.140]) by smtp.gmail.com with ESMTPSA id v2-v6sm2009877wme.36.2018.09.28.08.42.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Sep 2018 08:42:49 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 8/9] fuse: use iversion for readdir cache verification Date: Fri, 28 Sep 2018 17:42:33 +0200 Message-Id: <20180928154234.19270-9-mszeredi@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180928154234.19270-1-mszeredi@redhat.com> References: <20180928154234.19270-1-mszeredi@redhat.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use the internal iversion counter to make sure modifications of the directory through this filesystem are not missed by the mtime check (due to mtime granularity). Signed-off-by: Miklos Szeredi --- fs/fuse/dir.c | 21 ++++++++++++++------- fs/fuse/fuse_i.h | 3 +++ fs/fuse/readdir.c | 5 ++++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 3a333b0ea9ad..6800fdc3e730 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -14,6 +14,7 @@ #include #include #include +#include #include static void fuse_advise_use_readdirplus(struct inode *dir) @@ -89,6 +90,12 @@ void fuse_invalidate_attr(struct inode *inode) get_fuse_inode(inode)->i_time = 0; } +static void fuse_dir_changed(struct inode *dir) +{ + fuse_invalidate_attr(dir); + inode_maybe_inc_iversion(dir, false); +} + /** * Mark the attributes as stale due to an atime change. Avoid the invalidate if * atime is not used. @@ -447,7 +454,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, kfree(forget); d_instantiate(entry, inode); fuse_change_entry_timeout(entry, &outentry); - fuse_invalidate_attr(dir); + fuse_dir_changed(dir); err = finish_open(file, entry, generic_file_open); if (err) { fuse_sync_release(ff, flags); @@ -561,7 +568,7 @@ static int create_new_entry(struct fuse_conn *fc, struct fuse_args *args, } else { fuse_change_entry_timeout(entry, &outarg); } - fuse_invalidate_attr(dir); + fuse_dir_changed(dir); return 0; out_put_forget_req: @@ -671,7 +678,7 @@ static int fuse_unlink(struct inode *dir, struct dentry *entry) drop_nlink(inode); spin_unlock(&fc->lock); fuse_invalidate_attr(inode); - fuse_invalidate_attr(dir); + fuse_dir_changed(dir); fuse_invalidate_entry_cache(entry); fuse_update_ctime(inode); } else if (err == -EINTR) @@ -693,7 +700,7 @@ static int fuse_rmdir(struct inode *dir, struct dentry *entry) err = fuse_simple_request(fc, &args); if (!err) { clear_nlink(d_inode(entry)); - fuse_invalidate_attr(dir); + fuse_dir_changed(dir); fuse_invalidate_entry_cache(entry); } else if (err == -EINTR) fuse_invalidate_entry(entry); @@ -732,9 +739,9 @@ static int fuse_rename_common(struct inode *olddir, struct dentry *oldent, fuse_update_ctime(d_inode(newent)); } - fuse_invalidate_attr(olddir); + fuse_dir_changed(olddir); if (olddir != newdir) - fuse_invalidate_attr(newdir); + fuse_dir_changed(newdir); /* newent will end up negative */ if (!(flags & RENAME_EXCHANGE) && d_really_is_positive(newent)) { @@ -967,7 +974,7 @@ int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid, if (!entry) goto unlock; - fuse_invalidate_attr(parent); + fuse_dir_changed(parent); fuse_invalidate_entry(entry); if (child_nodeid != 0 && d_really_is_positive(entry)) { diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index e498f9edf01f..1e8d20e86760 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -120,6 +120,9 @@ struct fuse_inode { /** modification time of directory when cache was started */ struct timespec64 mtime; + /** iversion of directory when cache was started */ + u64 iversion; + /** protects above fields */ spinlock_t lock; } rdc; diff --git a/fs/fuse/readdir.c b/fs/fuse/readdir.c index f96525cef518..d91ae7449b73 100644 --- a/fs/fuse/readdir.c +++ b/fs/fuse/readdir.c @@ -8,6 +8,7 @@ #include "fuse_i.h" +#include #include static bool fuse_use_readdirplus(struct inode *dir, struct dir_context *ctx) @@ -445,6 +446,7 @@ static int fuse_readdir_cached(struct file *file, struct dir_context *ctx) /* Starting cache? Set cache mtime. */ if (!ctx->pos && !fi->rdc.size) { fi->rdc.mtime = inode->i_mtime; + fi->rdc.iversion = inode_query_iversion(inode); } spin_unlock(&fi->rdc.lock); return UNCACHED; @@ -455,7 +457,8 @@ static int fuse_readdir_cached(struct file *file, struct dir_context *ctx) * changed, and reset the cache if so. */ if (!ctx->pos) { - if (!timespec64_equal(&fi->rdc.mtime, &inode->i_mtime)) { + if (inode_peek_iversion(inode) != fi->rdc.iversion || + !timespec64_equal(&fi->rdc.mtime, &inode->i_mtime)) { fuse_rdc_reset(inode); goto retry_locked; }