Can you try applying the attached patch? It has some debugging to check that the cifs file it's trying to close actually got opened. It turns out that some paths through were either managing to escape that or were going through when they shouldn't have been. David --- commit cd7390c5e356efe67d93e4d1ba548c9c0ede4224 Author: David Howells <dhowells@xxxxxxxxxx> Date: Tue Jan 11 19:44:42 2022 +0000 fixes diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c index 6186824b366e..bf3b4c9901b9 100644 --- a/fs/cifs/dir.c +++ b/fs/cifs/dir.c @@ -508,10 +508,12 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry, server->ops->close(xid, tcon, &fid); cifs_del_pending_open(&open); rc = -ENOMEM; + goto out; } fscache_use_cookie(cifs_inode_cookie(file_inode(file)), file->f_mode & FMODE_WRITE); + file->f_mode |= 0x80000000; out: cifs_put_tlink(tlink); diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 44da7646f789..47333730c963 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -568,7 +568,7 @@ int cifs_open(struct inode *inode, struct file *file) spin_lock(&CIFS_I(inode)->deferred_lock); cifs_del_deferred_close(cfile); spin_unlock(&CIFS_I(inode)->deferred_lock); - goto out; + goto use_cache; } else { _cifsFileInfo_put(cfile, true, false); } @@ -630,19 +630,6 @@ int cifs_open(struct inode *inode, struct file *file) goto out; } - - fscache_use_cookie(cifs_inode_cookie(file_inode(file)), - file->f_mode & FMODE_WRITE); - if (file->f_flags & O_DIRECT && - (!((file->f_flags & O_ACCMODE) != O_RDONLY) || - file->f_flags & O_APPEND)) { - struct cifs_fscache_inode_coherency_data cd; - cifs_fscache_fill_coherency(file_inode(file), &cd); - fscache_invalidate(cifs_inode_cookie(file_inode(file)), - &cd, i_size_read(file_inode(file)), - FSCACHE_INVAL_DIO_WRITE); - } - if ((oplock & CIFS_CREATE_ACTION) && !posix_open_ok && tcon->unix_ext) { /* * Time to set mode which we can not set earlier due to @@ -661,6 +648,20 @@ int cifs_open(struct inode *inode, struct file *file) cfile->pid); } +use_cache: + fscache_use_cookie(cifs_inode_cookie(file_inode(file)), + file->f_mode & FMODE_WRITE); + file->f_mode |= 0x80000000; + if (file->f_flags & O_DIRECT && + (!((file->f_flags & O_ACCMODE) != O_RDONLY) || + file->f_flags & O_APPEND)) { + struct cifs_fscache_inode_coherency_data cd; + cifs_fscache_fill_coherency(file_inode(file), &cd); + fscache_invalidate(cifs_inode_cookie(file_inode(file)), + &cd, i_size_read(file_inode(file)), + FSCACHE_INVAL_DIO_WRITE); + } + out: free_dentry_path(page); free_xid(xid); @@ -885,7 +886,10 @@ int cifs_close(struct inode *inode, struct file *file) struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); struct cifs_deferred_close *dclose; - cifs_fscache_unuse_inode_cookie(inode, file->f_mode & FMODE_WRITE); + if (!(file->f_mode & 0x80000000)) + printk("File not opened?\n"); + else + cifs_fscache_unuse_inode_cookie(inode, file->f_mode & FMODE_WRITE); if (file->private_data != NULL) { cfile = file->private_data; diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c index 9bb1ab5fe5ed..08c8def8342a 100644 --- a/fs/fscache/cookie.c +++ b/fs/fscache/cookie.c @@ -571,6 +571,7 @@ void __fscache_use_cookie(struct fscache_cookie *cookie, bool will_modify) n_active, atomic_read(&cookie->n_accesses), will_modify ? fscache_active_use_modify : fscache_active_use); + ASSERTCMP(n_active, >, 0); again: state = fscache_cookie_state(cookie); @@ -657,6 +658,7 @@ void __fscache_unuse_cookie(struct fscache_cookie *cookie, trace_fscache_active(debug_id, r, c - 1, a, fscache_active_unuse); return; } + ASSERTCMP(c, >, 0); spin_lock(&cookie->lock); r = refcount_read(&cookie->ref); -- Linux-cachefs mailing list Linux-cachefs@xxxxxxxxxx https://listman.redhat.com/mailman/listinfo/linux-cachefs