fuse: invalidate readdir cache on epoch bump
Subsystems (2)
PATCH 1/1 fuse: invalidate readdir cache on epoch bump
From: Jun Wu <[email protected]>
FUSE_NOTIFY_INC_EPOCH invalidates dentries, but does not invalidate cached readdir results. A process with cwd inside a FUSE mount can therefore observe stale readdir(".") output after an epoch bump.
Fix this by recording epoch in the readdir cache and checking it on reuse.
Add FUSE_EPOCH_READDIR init flag so userspace can detect this change.
Minimal reproducer:
- mount a tiny FUSE fs with an empty root directory
- on opendir, enable fi->cache_readdir and fi->keep_cache
- chdir into the mount and call readdir(".") to populate readdir cache
- make the FUSE server report one file in the root directory
- send only FUSE_NOTIFY_INC_EPOCH
- call readdir(".") again; before this change it stays stale, after this change it sees the new file
--- fs/fuse/dev.c | 6 +++--- fs/fuse/fuse_i.h | 3 +++ fs/fuse/inode.c | 2 +- fs/fuse/readdir.c | 5 ++++- include/uapi/linux/fuse.h | 3 +++ 5 files changed, 14 insertions(+), 5 deletions(-)
fs/fuse/dev.c +3 -3
@@ -2039,9 +2039,9 @@ static int fuse_notify_resend(struct fuse_conn *fc) }/* -* Increments the fuse connection epoch. This will result of dentries from -* previous epochs to be invalidated. Additionally, if inval_wq is set, a work -* queue is scheduled to trigger the invalidation. +* Increments the fuse connection epoch. This will cause dentries and +* readdir caches from previous epochs to be invalidated. Additionally, +* if inval_wq is set, a work queue is scheduled to trigger the invalidation. */ static int fuse_notify_inc_epoch (struct fuse_conn *fc) {
fs/fuse/fuse_i.h +3 -0
@@ -191,6 +191,9 @@ struct fuse_inode {/* iversion of directory when cache was started */ u64 iversion; +/* epoch of fc when cache was started */ +int epoch; +/* protects above fields */ spinlock_t lock; } rdc;
fs/fuse/inode.c +1 -1
@@ -1506,7 +1506,7 @@ static struct fuse_init_args *fuse_new_init(struct fuse_mount *fm)FUSE_SECURITY_CTX |FUSE_CREATE_SUPP_GROUP |FUSE_HAS_EXPIRE_ONLY |FUSE_DIRECT_IO_ALLOW_MMAP |FUSE_NO_EXPORT_SUPPORT |FUSE_HAS_RESEND |FUSE_ALLOW_IDMAP | -FUSE_REQUEST_TIMEOUT ; +FUSE_REQUEST_TIMEOUT |FUSE_EPOCH_READDIR ;#ifdef CONFIG_FUSE_DAX if (fm->fc->dax) flags |=FUSE_MAP_ALIGNMENT ;
fs/fuse/readdir.c +4 -1
@@ -438,6 +438,7 @@ static void fuse_rdc_reset(struct inode *inode) fi->rdc.version++; fi->rdc.size =0 ; fi->rdc.pos =0 ; + fi->rdc.epoch =0 ; }#define UNCACHED 1
@@ -479,6 +480,7 @@ static int fuse_readdir_cached(struct file *file, struct dir_context *ctx)if (!ctx->pos && !fi->rdc.size) { fi->rdc.mtime =inode_get_mtime (inode); fi->rdc.iversion =inode_query_iversion (inode); + fi->rdc.epoch =atomic_read (&fc->epoch); }spin_unlock (&fi->rdc.lock);return UNCACHED ;
@@ -492,7 +494,8 @@ static int fuse_readdir_cached(struct file *file, struct dir_context *ctx)struct timespec64 mtime =inode_get_mtime (inode);if (inode_peek_iversion (inode) != fi->rdc.iversion || - !timespec64_equal (&fi->rdc.mtime, &mtime)) { + !timespec64_equal (&fi->rdc.mtime, &mtime) || + fi->rdc.epoch !=atomic_read (&fc->epoch)) {fuse_rdc_reset (inode); goto retry_locked; }
include/uapi/linux/fuse.h +3 -0
@@ -240,6 +240,7 @@* - add FUSE_COPY_FILE_RANGE_64 * - add struct fuse_copy_file_range_out * - add FUSE_NOTIFY_PRUNE +* - add FUSE_EPOCH_READDIR */ #ifndef _LINUX_FUSE_H
@@ -448,6 +449,7 @@ struct fuse_file_lock {* FUSE_OVER_IO_URING: Indicate that client supports io-uring * FUSE_REQUEST_TIMEOUT: kernel supports timing out requests. * init_out.request_timeout contains the timeout (in secs) +* FUSE_EPOCH_READDIR: epoch bump also invalidates readdir caches */ #define FUSE_ASYNC_READ (1 << 0)#define FUSE_POSIX_LOCKS (1 << 1)
@@ -495,6 +497,7 @@ struct fuse_file_lock {#define FUSE_ALLOW_IDMAP (1ULL << 40)#define FUSE_OVER_IO_URING (1ULL << 41)#define FUSE_REQUEST_TIMEOUT (1ULL << 42) +#define FUSE_EPOCH_READDIR (1ULL << 43)/** * CUSE INIT request/reply flags
Signature · 1 line
2.53.0
Quoted 10 lines · Jun Wu
From: Jun Wu <[email protected]>
FUSE_NOTIFY_INC_EPOCHinvalidates dentries, but does not invalidate cached readdir results. A process with cwd inside a FUSE mount can therefore observe stalereaddir(".")output after an epoch bump.Fix this by recording epoch in the readdir cache and checking it on reuse.
Add
FUSE_EPOCH_READDIRinit flag so userspace can detect this change.
imo this is more of a fix than a new feature, so I don't think the changes for adding the FUSE_EPOCH_READDIR init flag is necessary. I think the Fixes: 2396356a945b ("fuse: add more control over cache invalidation behaviour") tag fits here.
Other than that, this change makes sense to me.
Thanks,
Joanne
Quoted 126 lines
Minimal reproducer:
- mount a tiny FUSE fs with an empty root directory
- on opendir, enablefi->cache_readdirandfi->keep_cache
- chdir into the mount and callreaddir(".")to populate readdir cache
- make the FUSE server report one file in the root directory
- send onlyFUSE_NOTIFY_INC_EPOCH
- callreaddir(".")again; before this change it stays stale, after this change it sees the new fileSigned-off-by Jun Wu <[email protected]>--- fs/fuse/dev.c | 6 +++--- fs/fuse/fuse_i.h | 3 +++ fs/fuse/inode.c | 2 +- fs/fuse/readdir.c | 5 ++++- include/uapi/linux/fuse.h | 3 +++ 5 files changed, 14 insertions(+), 5 deletions(-)fs/fuse/dev.c +3
-3@@ -2039,9 +2039,9 @@ static int fuse_notify_resend(struct fuse_conn *fc) }/* -* Increments the fuse connection epoch. This will result of dentries from -* previous epochs to be invalidated. Additionally, if inval_wq is set, a work -* queue is scheduled to trigger the invalidation. +* Increments the fuse connection epoch. This will cause dentries and +* readdir caches from previous epochs to be invalidated. Additionally, +* if inval_wq is set, a work queue is scheduled to trigger the invalidation. */ static int fuse_notify_inc_epoch (struct fuse_conn *fc) {fs/fuse/fuse_i.h +3
-0@@ -191,6 +191,9 @@ struct fuse_inode {/* iversion of directory when cache was started */ u64 iversion; +/* epoch of fc when cache was started */ +int epoch; +/* protects above fields */ spinlock_t lock; } rdc;fs/fuse/inode.c +1
-1@@ -1506,7 +1506,7 @@ static struct fuse_init_args *fuse_new_init(struct fuse_mount *fm)FUSE_SECURITY_CTX |FUSE_CREATE_SUPP_GROUP |FUSE_HAS_EXPIRE_ONLY |FUSE_DIRECT_IO_ALLOW_MMAP |FUSE_NO_EXPORT_SUPPORT |FUSE_HAS_RESEND |FUSE_ALLOW_IDMAP | -FUSE_REQUEST_TIMEOUT ; +FUSE_REQUEST_TIMEOUT |FUSE_EPOCH_READDIR ;#ifdef CONFIG_FUSE_DAX if (fm->fc->dax) flags |=FUSE_MAP_ALIGNMENT ;fs/fuse/readdir.c +4
-1@@ -438,6 +438,7 @@ static void fuse_rdc_reset(struct inode *inode) fi->rdc.version++; fi->rdc.size =0 ; fi->rdc.pos =0 ; + fi->rdc.epoch =0 ; }#define UNCACHED 1@@ -479,6 +480,7 @@ static int fuse_readdir_cached(struct file *file, struct dir_context *ctx)if (!ctx->pos && !fi->rdc.size) { fi->rdc.mtime =inode_get_mtime (inode); fi->rdc.iversion =inode_query_iversion (inode); + fi->rdc.epoch =atomic_read (&fc->epoch); }spin_unlock (&fi->rdc.lock);return UNCACHED ;@@ -492,7 +494,8 @@ static int fuse_readdir_cached(struct file *file, struct dir_context *ctx)struct timespec64 mtime =inode_get_mtime (inode);if (inode_peek_iversion (inode) != fi->rdc.iversion || - !timespec64_equal (&fi->rdc.mtime, &mtime)) { + !timespec64_equal (&fi->rdc.mtime, &mtime) || + fi->rdc.epoch !=atomic_read (&fc->epoch)) {fuse_rdc_reset (inode); goto retry_locked; }include/uapi/linux/fuse.h +3
-1@@ -240,6 +240,7 @@* - add FUSE_COPY_FILE_RANGE_64 * - add struct fuse_copy_file_range_out * - add FUSE_NOTIFY_PRUNE +* - add FUSE_EPOCH_READDIR */ #ifndef _LINUX_FUSE_H@@ -448,6 +449,7 @@ struct fuse_file_lock {* FUSE_OVER_IO_URING: Indicate that client supports io-uring * FUSE_REQUEST_TIMEOUT: kernel supports timing out requests. * init_out.request_timeout contains the timeout (in secs) +* FUSE_EPOCH_READDIR: epoch bump also invalidates readdir caches */ #define FUSE_ASYNC_READ (1 << 0)#define FUSE_POSIX_LOCKS (1 << 1)@@ -495,6 +497,7 @@ struct fuse_file_lock {#define FUSE_ALLOW_IDMAP (1ULL << 40)#define FUSE_OVER_IO_URING (1ULL << 41)#define FUSE_REQUEST_TIMEOUT (1ULL << 42) +#define FUSE_EPOCH_READDIR (1ULL << 43)/** * CUSE INIT request/reply flags -- 2.53.0
PATCH v2 1/1 fuse: invalidate readdir cache on epoch bump
In reply to Jun WuFrom: Jun Wu <[email protected]>
FUSE_NOTIFY_INC_EPOCH invalidates dentries, but does not invalidate cached readdir results. A process with cwd inside a FUSE mount can therefore observe stale readdir(".") output after an epoch bump.
Fix this by recording epoch in the readdir cache and checking it on reuse.
Minimal reproducer:
- mount a tiny FUSE fs with an empty root directory
- on opendir, enable fi->cache_readdir and fi->keep_cache
- chdir into the mount and call readdir(".") to populate readdir cache
- make the FUSE server report one file in the root directory
- send only FUSE_NOTIFY_INC_EPOCH
- call readdir(".") again; before this change it stays stale, after this change it sees the new file
---
Changes in v2:
- Addresses Joanne Koong's suggestions:
- Drop the FUSE_EPOCH_READDIR init flag.
- Add Fixes tag.
- Rebase onto current mainline.
--- fs/fuse/dev.c | 6 +++--- fs/fuse/fuse_i.h | 3 +++ fs/fuse/readdir.c | 5 ++++- 3 files changed, 10 insertions(+), 4 deletions(-)
fs/fuse/dev.c +3 -3
@@ -2038,9 +2038,9 @@ static int fuse_notify_resend(struct fuse_conn *fc) }/* -* Increments the fuse connection epoch. This will result of dentries from -* previous epochs to be invalidated. Additionally, if inval_wq is set, a work -* queue is scheduled to trigger the invalidation. +* Increments the fuse connection epoch. This will cause dentries and +* readdir caches from previous epochs to be invalidated. Additionally, +* if inval_wq is set, a work queue is scheduled to trigger the invalidation. */ static int fuse_notify_inc_epoch (struct fuse_conn *fc) {
fs/fuse/fuse_i.h +3 -0
@@ -191,6 +191,9 @@ struct fuse_inode {/* iversion of directory when cache was started */ u64 iversion; +/* epoch of fc when cache was started */ +int epoch; +/* protects above fields */ spinlock_t lock; } rdc;
fs/fuse/readdir.c +4 -1
@@ -442,6 +442,7 @@ static void fuse_rdc_reset(struct inode *inode) fi->rdc.version++; fi->rdc.size =0 ; fi->rdc.pos =0 ; + fi->rdc.epoch =0 ; }#define UNCACHED 1
@@ -483,6 +484,7 @@ static int fuse_readdir_cached(struct file *file, struct dir_context *ctx)if (!ctx->pos && !fi->rdc.size) { fi->rdc.mtime =inode_get_mtime (inode); fi->rdc.iversion =inode_query_iversion (inode); + fi->rdc.epoch =atomic_read (&fc->epoch); }spin_unlock (&fi->rdc.lock);return UNCACHED ;
@@ -496,7 +498,8 @@ static int fuse_readdir_cached(struct file *file, struct dir_context *ctx)struct timespec64 mtime =inode_get_mtime (inode);if (inode_peek_iversion (inode) != fi->rdc.iversion || - !timespec64_equal (&fi->rdc.mtime, &mtime)) { + !timespec64_equal (&fi->rdc.mtime, &mtime) || + fi->rdc.epoch !=atomic_read (&fc->epoch)) {fuse_rdc_reset (inode); goto retry_locked; }
Signature · 1 line
2.54.0
Quoted 18 lines · Jun Wu
From: Jun Wu <[email protected]>
FUSE_NOTIFY_INC_EPOCHinvalidates dentries, but does not invalidate cached readdir results. A process with cwd inside a FUSE mount can therefore observe stalereaddir(".")output after an epoch bump.Fix this by recording epoch in the readdir cache and checking it on reuse.
Minimal reproducer:
- mount a tiny FUSE fs with an empty root directory
- on opendir, enablefi->cache_readdirandfi->keep_cache
- chdir into the mount and callreaddir(".")to populate readdir cache
- make the FUSE server report one file in the root directory
- send onlyFUSE_NOTIFY_INC_EPOCH
- callreaddir(".")again; before this change it stays stale, after this change it sees the new file
Quoted 2 lines
Fixes 2396356a945b ("fuse: add more control over cache invalidation behaviour")Signed-off-by Jun Wu <[email protected]>
Nice catch! The fix looks good to me, so feel free to add my
Cheers,
Signature · 1 line
Luís
Quoted 76 lines
---
Changes in v2:
- Addresses Joanne Koong's suggestions:
- Drop theFUSE_EPOCH_READDIRinit flag.
- Add Fixes tag.
- Rebase onto current mainline.--- fs/fuse/dev.c | 6 +++--- fs/fuse/fuse_i.h | 3 +++ fs/fuse/readdir.c | 5 ++++- 3 files changed, 10 insertions(+), 4 deletions(-)fs/fuse/dev.c +3
-3@@ -2038,9 +2038,9 @@ static int fuse_notify_resend(struct fuse_conn *fc) }/* -* Increments the fuse connection epoch. This will result of dentries from -* previous epochs to be invalidated. Additionally, if inval_wq is set, a work -* queue is scheduled to trigger the invalidation. +* Increments the fuse connection epoch. This will cause dentries and +* readdir caches from previous epochs to be invalidated. Additionally, +* if inval_wq is set, a work queue is scheduled to trigger the invalidation. */ static int fuse_notify_inc_epoch (struct fuse_conn *fc) {fs/fuse/fuse_i.h +3
-0@@ -191,6 +191,9 @@ struct fuse_inode {/* iversion of directory when cache was started */ u64 iversion; +/* epoch of fc when cache was started */ +int epoch; +/* protects above fields */ spinlock_t lock; } rdc;fs/fuse/readdir.c +4
-1@@ -442,6 +442,7 @@ static void fuse_rdc_reset(struct inode *inode) fi->rdc.version++; fi->rdc.size =0 ; fi->rdc.pos =0 ; + fi->rdc.epoch =0 ; }#define UNCACHED 1@@ -483,6 +484,7 @@ static int fuse_readdir_cached(struct file *file, struct dir_context *ctx)if (!ctx->pos && !fi->rdc.size) { fi->rdc.mtime =inode_get_mtime (inode); fi->rdc.iversion =inode_query_iversion (inode); + fi->rdc.epoch =atomic_read (&fc->epoch); }spin_unlock (&fi->rdc.lock);return UNCACHED ;@@ -496,7 +498,8 @@ static int fuse_readdir_cached(struct file *file, struct dir_context *ctx)struct timespec64 mtime =inode_get_mtime (inode);if (inode_peek_iversion (inode) != fi->rdc.iversion || - !timespec64_equal (&fi->rdc.mtime, &mtime)) { + !timespec64_equal (&fi->rdc.mtime, &mtime) || + fi->rdc.epoch !=atomic_read (&fc->epoch)) {fuse_rdc_reset (inode); goto retry_locked; }Signature · 1 line
2.54.0
Joanne Koong
Reviewed-byQuoted 21 lines · Luis Henriques
Quoted 18 lines · Jun Wu
From: Jun Wu <[email protected]>
FUSE_NOTIFY_INC_EPOCHinvalidates dentries, but does not invalidate cached readdir results. A process with cwd inside a FUSE mount can therefore observe stalereaddir(".")output after an epoch bump.Fix this by recording epoch in the readdir cache and checking it on reuse.
Minimal reproducer:
- mount a tiny FUSE fs with an empty root directory
- on opendir, enablefi->cache_readdirandfi->keep_cache
- chdir into the mount and callreaddir(".")to populate readdir cache
- make the FUSE server report one file in the root directory
- send onlyFUSE_NOTIFY_INC_EPOCH
- callreaddir(".")again; before this change it stays stale, after this change it sees the new file
Quoted 2 lines
Quoted 2 lines
Fixes 2396356a945b ("fuse: add more control over cache invalidation behaviour")Signed-off-by Jun Wu <[email protected]>
(btw, I think your v2 email may have gotten corrupted when sending. I wasn't able to find it in my inbox and had to manually import Luis's. I'm not seeing it show up on lore [1] either)
Thanks,
Joanne
Quoted 22 lines · Joanne Koong
Quoted 21 lines · Luis Henriques
Quoted 18 lines · Jun Wu
From: Jun Wu <[email protected]>
FUSE_NOTIFY_INC_EPOCHinvalidates dentries, but does not invalidate cached readdir results. A process with cwd inside a FUSE mount can therefore observe stalereaddir(".")output after an epoch bump.Fix this by recording epoch in the readdir cache and checking it on reuse.
Minimal reproducer:
- mount a tiny FUSE fs with an empty root directory
- on opendir, enablefi->cache_readdirandfi->keep_cache
- chdir into the mount and callreaddir(".")to populate readdir cache
- make the FUSE server report one file in the root directory
- send onlyFUSE_NOTIFY_INC_EPOCH
- callreaddir(".")again; before this change it stays stale, after this change it sees the new file
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Fixes 2396356a945b ("fuse: add more control over cache invalidation behaviour")Signed-off-by Jun Wu <[email protected]>Reviewed-by Joanne Koong <[email protected]>(btw, I think your v2 email may have gotten corrupted when sending. I wasn't able to find it in my inbox and had to manually import Luis's. I'm not seeing it show up on lore [1] either)
Hmm... yeah, looks like there's something funny with his email. The mail server I use seems to be more tolerant than lore regarding incorrect email. So maybe lore blocked it because the domain and the smtp server address don't match...? Anyway, maybe it's worth resending so that everyone can see it.
Cheers,
Signature · 1 line
Luís
A message that is not in the archive (sent off-list or not yet received): CAFfKmRW_Dqtb_DwAgK5Oq5kTAnGY6bmRpYP-Gw2+PVBtU4YVtQ@mail.gmail.com
Quoted 3 lines · Jun Wu
Thanks for your review! I think my DNS records had expired when sending, and retrying after fixing the DNS didn't help. I will resend with a regular Gmail address.
Awesome, thanks. I can confirm v3 is now on the mailing-list, though this email I'm replying to seems to have been dropped again :-)
Cheers,
Signature · 1 line
Luís
Quoted 58 lines
Regards,
JunQuoted 47 lines · Luis Henriques
Quoted 7 lines · Joanne Koong
Quoted 6 lines · Luis Henriques
Quoted 3 lines · Jun Wu
From: Jun Wu <[email protected]>
FUSE_NOTIFY_INC_EPOCHinvalidates dentries, but does not invalidatecached
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
readdir results. A process with cwd inside a FUSE mount can therefore observe stale
readdir(".")output after an epoch bump.Fix this by recording epoch in the readdir cache and checking it on
reuse.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Minimal reproducer:
- mount a tiny FUSE fs with an empty root directory
- on opendir, enablefi->cache_readdirandfi->keep_cache
- chdir into the mount and callreaddir(".")to populate readdir cache
- make the FUSE server report one file in the root directory
- send onlyFUSE_NOTIFY_INC_EPOCH
- callreaddir(".")again; before this change it stays stale, afterthis
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
change it sees the new file
Fixes 2396356a945b ("fuse: add more control over cache invalidationbehaviour")
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Signed-off-by Jun Wu <[email protected]>Reviewed-by Joanne Koong <[email protected]>(btw, I think your v2 email may have gotten corrupted when sending. I wasn't able to find it in my inbox and had to manually import Luis's. I'm not seeing it show up on lore [1] either)
Hmm... yeah, looks like there's something funny with his email. The mail server I use seems to be more tolerant than lore regarding incorrect email. So maybe lore blocked it because the domain and the smtp server address don't match...? Anyway, maybe it's worth resending so that everyone can see it.
Cheers,
--
LuísSignature · 2 lines
WU Jun <[email protected]>
Quoted 19 lines · Jun Wu
From: Jun Wu <[email protected]>
FUSE_NOTIFY_INC_EPOCHinvalidates dentries, but does not invalidate cached readdir results. A process with cwd inside a FUSE mount can therefore observe stalereaddir(".")output after an epoch bump.Fix this by recording epoch in the readdir cache and checking it on reuse.
Minimal reproducer:
- mount a tiny FUSE fs with an empty root directory
- on opendir, enablefi->cache_readdirandfi->keep_cache
- chdir into the mount and callreaddir(".")to populate readdir cache
- make the FUSE server report one file in the root directory
- send onlyFUSE_NOTIFY_INC_EPOCH
- callreaddir(".")again; before this change it stays stale, after this change it sees the new file
Quoted 2 lines
Fixes 2396356a945b ("fuse: add more control over cache invalidation behaviour")Signed-off-by Jun Wu <[email protected]>
Applied, thanks.
Miklos
PATCH v2 1/1 fuse: invalidate readdir cache on epoch bump
In reply to Jun WuFrom: Jun Wu <[email protected]>
FUSE_NOTIFY_INC_EPOCH invalidates dentries, but does not invalidate cached readdir results. A process with cwd inside a FUSE mount can therefore observe stale readdir(".") output after an epoch bump.
Fix this by recording epoch in the readdir cache and checking it on reuse.
Minimal reproducer:
- mount a tiny FUSE fs with an empty root directory
- on opendir, enable fi->cache_readdir and fi->keep_cache
- chdir into the mount and call readdir(".") to populate readdir cache
- make the FUSE server report one file in the root directory
- send only FUSE_NOTIFY_INC_EPOCH
- call readdir(".") again; before this change it stays stale, after this change it sees the new file
---
Changes in v2:
- Addresses Joanne Koong's suggestions:
- Drop the FUSE_EPOCH_READDIR init flag.
- Add Fixes tag.
- Rebase onto current mainline.
--- fs/fuse/dev.c | 6 +++--- fs/fuse/fuse_i.h | 3 +++ fs/fuse/readdir.c | 5 ++++- 3 files changed, 10 insertions(+), 4 deletions(-)
fs/fuse/dev.c +3 -3
@@ -2038,9 +2038,9 @@ static int fuse_notify_resend(struct fuse_conn *fc) }/* -* Increments the fuse connection epoch. This will result of dentries from -* previous epochs to be invalidated. Additionally, if inval_wq is set, a work -* queue is scheduled to trigger the invalidation. +* Increments the fuse connection epoch. This will cause dentries and +* readdir caches from previous epochs to be invalidated. Additionally, +* if inval_wq is set, a work queue is scheduled to trigger the invalidation. */ static int fuse_notify_inc_epoch (struct fuse_conn *fc) {
fs/fuse/fuse_i.h +3 -0
@@ -191,6 +191,9 @@ struct fuse_inode {/* iversion of directory when cache was started */ u64 iversion; +/* epoch of fc when cache was started */ +int epoch; +/* protects above fields */ spinlock_t lock; } rdc;
fs/fuse/readdir.c +4 -1
@@ -442,6 +442,7 @@ static void fuse_rdc_reset(struct inode *inode) fi->rdc.version++; fi->rdc.size =0 ; fi->rdc.pos =0 ; + fi->rdc.epoch =0 ; }#define UNCACHED 1
@@ -483,6 +484,7 @@ static int fuse_readdir_cached(struct file *file, struct dir_context *ctx)if (!ctx->pos && !fi->rdc.size) { fi->rdc.mtime =inode_get_mtime (inode); fi->rdc.iversion =inode_query_iversion (inode); + fi->rdc.epoch =atomic_read (&fc->epoch); }spin_unlock (&fi->rdc.lock);return UNCACHED ;
@@ -496,7 +498,8 @@ static int fuse_readdir_cached(struct file *file, struct dir_context *ctx)struct timespec64 mtime =inode_get_mtime (inode);if (inode_peek_iversion (inode) != fi->rdc.iversion || - !timespec64_equal (&fi->rdc.mtime, &mtime)) { + !timespec64_equal (&fi->rdc.mtime, &mtime) || + fi->rdc.epoch !=atomic_read (&fc->epoch)) {fuse_rdc_reset (inode); goto retry_locked; }
Signature · 1 line
2.54.0