Merge pull request #260 from giuseppe/invalidate-cache-readdir

main: invalidate directory cache on create/rename
This commit is contained in:
Daniel J Walsh 2020-11-11 16:34:50 -05:00 committed by GitHub
commit a9d8634e5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -50,6 +50,7 @@ struct ovl_node
Hash_table *inodes; Hash_table *inodes;
struct ovl_ino *ino; struct ovl_ino *ino;
struct ovl_node *next_link; struct ovl_node *next_link;
unsigned int in_readdir;
unsigned int do_unlink : 1; unsigned int do_unlink : 1;
unsigned int do_rmdir : 1; unsigned int do_rmdir : 1;

26
main.c
View File

@ -2183,6 +2183,7 @@ ovl_opendir (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
fi->cache_readdir = 1; fi->cache_readdir = 1;
#endif #endif
} }
node->in_readdir++;
fuse_reply_open (req, fi); fuse_reply_open (req, fi);
return; return;
@ -2395,6 +2396,7 @@ ovl_releasedir (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
size_t s; size_t s;
struct ovl_dirp *d = ovl_dirp (fi); struct ovl_dirp *d = ovl_dirp (fi);
struct ovl_data *lo = ovl_data (req); struct ovl_data *lo = ovl_data (req);
struct ovl_node *node = NULL;
if (UNLIKELY (ovl_debug (req))) if (UNLIKELY (ovl_debug (req)))
fprintf (stderr, "ovl_releasedir(ino=%" PRIu64 ")\n", ino); fprintf (stderr, "ovl_releasedir(ino=%" PRIu64 ")\n", ino);
@ -2409,6 +2411,10 @@ ovl_releasedir (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
} }
} }
node = do_lookup_file (lo, ino, NULL);
if (node)
node->in_readdir--;
free (d->tbl); free (d->tbl);
free (d); free (d);
fuse_reply_err (req, 0); fuse_reply_err (req, 0);
@ -3709,7 +3715,7 @@ ovl_create (fuse_req_t req, fuse_ino_t parent, const char *name,
cleanup_lock int l = enter_big_lock (); cleanup_lock int l = enter_big_lock ();
cleanup_close int fd = -1; cleanup_close int fd = -1;
struct fuse_entry_param e; struct fuse_entry_param e;
struct ovl_node *node = NULL; struct ovl_node *p, *node = NULL;
struct ovl_data *lo = ovl_data (req); struct ovl_data *lo = ovl_data (req);
struct stat st; struct stat st;
@ -3735,6 +3741,11 @@ ovl_create (fuse_req_t req, fuse_ino_t parent, const char *name,
return; return;
} }
p = do_lookup_file (lo, parent, NULL);
/* Make sure the cache is invalidated, if the parent is in the middle of a readdir. */
if (p && p->in_readdir)
fuse_lowlevel_notify_inval_inode (lo->se, parent, 0, 0);
if (node == NULL || do_getattr (req, &e, node, fd, NULL) < 0) if (node == NULL || do_getattr (req, &e, node, fd, NULL) < 0)
{ {
fuse_reply_err (req, errno); fuse_reply_err (req, errno);
@ -4551,6 +4562,7 @@ ovl_rename (fuse_req_t req, fuse_ino_t parent, const char *name,
fuse_ino_t newparent, const char *newname, fuse_ino_t newparent, const char *newname,
unsigned int flags) unsigned int flags)
{ {
struct ovl_node *p;
cleanup_lock int l = enter_big_lock (); cleanup_lock int l = enter_big_lock ();
struct ovl_data *lo = ovl_data (req); struct ovl_data *lo = ovl_data (req);
@ -4567,6 +4579,14 @@ ovl_rename (fuse_req_t req, fuse_ino_t parent, const char *name,
ovl_rename_exchange (req, parent, name, newparent, newname, flags); ovl_rename_exchange (req, parent, name, newparent, newname, flags);
else else
ovl_rename_direct (req, parent, name, newparent, newname, flags); ovl_rename_direct (req, parent, name, newparent, newname, flags);
/* Make sure the cache is invalidated, if the parent is in the middle of a readdir. */
p = do_lookup_file (lo, parent, NULL);
if (p && p->in_readdir)
fuse_lowlevel_notify_inval_inode (lo->se, parent, 0, 0);
p = do_lookup_file (lo, newparent, NULL);
if (p && p->in_readdir)
fuse_lowlevel_notify_inval_inode (lo->se, newparent, 0, 0);
} }
static void static void
@ -4785,6 +4805,10 @@ ovl_mknod (fuse_req_t req, fuse_ino_t parent, const char *name, mode_t mode, dev
return; return;
} }
/* Make sure the cache is invalidated, if the parent is in the middle of a readdir. */
if (pnode->in_readdir)
fuse_lowlevel_notify_inval_inode (lo->se, parent, 0, 0);
e.ino = node_to_inode (node); e.ino = node_to_inode (node);
e.attr_timeout = get_timeout (lo); e.attr_timeout = get_timeout (lo);
e.entry_timeout = get_timeout (lo); e.entry_timeout = get_timeout (lo);