From: Jeff Layton Subject: Re: [PATCH 1/6] CIFS: Make cifsFileInfo_put work with strict cache mode Date: Tue, 9 Nov 2010 13:00:58 -0500 Message-ID: <20101109130058.1ba3c435@corrin.poochiereds.net> References: <1288945777-9197-1-git-send-email-piastryyy@gmail.com> <1288945777-9197-2-git-send-email-piastryyy@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Pavel Shilovsky Return-path: In-Reply-To: <1288945777-9197-2-git-send-email-piastryyy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> Sender: linux-cifs-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: On Fri, 5 Nov 2010 11:29:32 +0300 Pavel Shilovsky wrote: > On strict cache mode when we close the last file handle of the inode we > should invalidate it to prevent data coherency problem when we open it > again but it has been modified by other clients. > > Signed-off-by: Pavel Shilovsky > --- > fs/cifs/cifs_fs_sb.h | 1 + > fs/cifs/file.c | 6 ++++++ > 2 files changed, 7 insertions(+), 0 deletions(-) > > diff --git a/fs/cifs/cifs_fs_sb.h b/fs/cifs/cifs_fs_sb.h > index e9a393c..be7b159 100644 > --- a/fs/cifs/cifs_fs_sb.h > +++ b/fs/cifs/cifs_fs_sb.h > @@ -40,6 +40,7 @@ > #define CIFS_MOUNT_FSCACHE 0x8000 /* local caching enabled */ > #define CIFS_MOUNT_MF_SYMLINKS 0x10000 /* Minshall+French Symlinks enabled */ > #define CIFS_MOUNT_MULTIUSER 0x20000 /* multiuser mount */ > +#define CIFS_MOUNT_STRICT_IO 0x40000 /* strict cache mode */ > > struct cifs_sb_info { > struct rb_root tlink_tree; > diff --git a/fs/cifs/file.c b/fs/cifs/file.c > index 777e7f4..b36de2e 100644 > --- a/fs/cifs/file.c > +++ b/fs/cifs/file.c > @@ -264,7 +264,9 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file) > struct inode *inode = cifs_file->dentry->d_inode; > struct cifsTconInfo *tcon = tlink_tcon(cifs_file->tlink); > struct cifsInodeInfo *cifsi = CIFS_I(inode); > + struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); > struct cifsLockInfo *li, *tmp; > + bool last_open_file = false; > > spin_lock(&cifs_file_list_lock); > if (--cifs_file->count > 0) { > @@ -279,10 +281,14 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file) > if (list_empty(&cifsi->openFileList)) { > cFYI(1, "closing last open instance for inode %p", > cifs_file->dentry->d_inode); > + last_open_file = true; > cifs_set_oplock_level(inode, 0); > } > spin_unlock(&cifs_file_list_lock); > > + if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) && last_open_file) > + invalidate_remote_inode(inode); > + Now that I think about it...this looks racy. Suppose someone races in after you set last_open_file, opens the file and does a write.... I think you'd be better served by setting the invalid_mapping flag on the cifs_i instead and letting the normal revalidation codepath handle this. The cache will then be invalidated the next time cifs_revalidate_file/dentry is run. > if (!tcon->need_reconnect && !cifs_file->invalidHandle) { > int xid, rc; >