Skip to contentSkip to conversation

Introducing new strict cache mode (try #4)

PATCH In review Pavel Shilovsky 3 participants 18 messages Nov 5, 2010 – Nov 10, 2010 10 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Introducing new strict cache mode (try #4)

I add new ones (fsync, mmap) and modified previous patches (read, write, close) and their descriptions. Here is the complete set of them.

Pavel Shilovsky (6):
CIFS: Make cifsFileInfo_put work with strict cache mode
CIFS: Make read call work with strict cache mode
CIFS: Make write call work with strict cache mode
CIFS: Make cifs_fsync work with strict cache mode
CIFS: Make cifs_file_map work with strict cache mode
CIFS: Add strictcache mount option

 fs/cifs/README       |    5 +++
 fs/cifs/cifs_fs_sb.h |    1 +
 fs/cifs/cifsfs.c     |   79 +++++++++++++++++++++++++++++++++++++++++++++----
 fs/cifs/connect.c    |    5 +++
 fs/cifs/file.c       |   54 +++++++++++++++++++++++++---------
 5 files changed, 123 insertions(+), 21 deletions(-)
Signature · 1 line
1.7.2.3

A message that is not in the archive (sent off-list or not yet received): 1288945777-9197-1-git-send-email-piastryyy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH 1/6 CIFS: Make cifsFileInfo_put work with strict cache mode

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.

---
 fs/cifs/cifs_fs_sb.h |    1 +
 fs/cifs/file.c       |    6 ++++++
 2 files changed, 7 insertions(+), 0 deletions(-)
fs/cifs/cifs_fs_sb.h +1 -0
index e9a393c..be7b159 100644
@@ -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;
fs/cifs/file.c +6 -0
index 777e7f4..b36de2e 100644
@@ -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);
+
 	if (!tcon->need_reconnect && !cifs_file->invalidHandle) {
 		int xid, rc;
 
Signature · 1 line
1.7.2.3

A message that is not in the archive (sent off-list or not yet received): 1288945777-9197-2-git-send-email-piastryyy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#4 lore raw

Re: [PATCH 1/6] CIFS: Make cifsFileInfo_put work with strict cache mode

Quoted 38 lines · On Fri, 5 Nov 2010 11:29:32 +0300 Pavel Shilovsky…

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.

---
 fs/cifs/cifs_fs_sb.h |    1 +
 fs/cifs/file.c       |    6 ++++++
 2 files changed, 7 insertions(+), 0 deletions(-)
fs/cifs/cifs_fs_sb.h +1 -0
index e9a393c..be7b159 100644
@@ -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;
fs/cifs/file.c +2 -0
index 777e7f4..b36de2e 100644
@@ -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)) {

fs/cifs/file.c void cifsFileInfo_put(struct cifsFileInfo *cifs_file) · line 291

Quoted 10 lines
fs/cifs/file.c +4 -0
 		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.

Quoted 3 lines
fs/cifs/file.c +0 -0
 	if (!tcon->need_reconnect && !cifs_file->invalidHandle) {
 		int xid, rc;
 

A message that is not in the archive (sent off-list or not yet received): 20101109130058.1ba3c435-4QP7MXygkU+dMjc06nkz3ljfA9RmPOcC@public.gmane.org

#6 lore raw

Re: [PATCH 1/6] CIFS: Make cifsFileInfo_put work with strict cache mode

2010/11/9 Jeff Layton <[email protected]>:

Quoted 48 lines
Quoted 45 lines · On Fri,  5 Nov 2010 11:29:32 +0300 Pavel Shilovsky…

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.

---
 fs/cifs/cifs_fs_sb.h |    1 +
 fs/cifs/file.c       |    6 ++++++

 2 files changed, 7 insertions(+), 0 deletions(-)
fs/cifs/cifs_fs_sb.h +1 -0
index e9a393c..be7b159 100644
@@ -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;
fs/cifs/file.c +3 -0
index 777e7f4..b36de2e 100644
@@ -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);
 
Quoted 6 lines

fs/cifs/file.c void cifsFileInfo_put(struct cifsFileInfo *cifs_file) · line 291

Quoted 3 lines
fs/cifs/file.c +3 -0
+     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....

Can you explain what bad happens in this case?

Quoted 10 lines

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.

Quoted 3 lines
fs/cifs/file.c +0 -0
       if (!tcon->need_reconnect && !cifs_file->invalidHandle) {
               int xid, rc;
 
Signature · 2 lines
Best regards,
Pavel Shilovsky.

A message that is not in the archive (sent off-list or not yet received): AANLkTi=BZ_ozRd01VEjDAZ4YWou-Ng6vPnOvAwRWGRxC-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#8 lore raw

Re: [PATCH 1/6] CIFS: Make cifsFileInfo_put work with strict cache mode

Quoted 49 lines · On Tue, 9 Nov 2010 21:02:19 +0300 Pavel Shilovsky…

2010/11/9 Jeff Layton <[email protected]>:

Quoted 48 lines
Quoted 45 lines · On Fri,  5 Nov 2010 11:29:32 +0300 Pavel Shilovsky…

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.

---
 fs/cifs/cifs_fs_sb.h |    1 +
 fs/cifs/file.c       |    6 ++++++

 2 files changed, 7 insertions(+), 0 deletions(-)
fs/cifs/cifs_fs_sb.h +1 -0
index e9a393c..be7b159 100644
@@ -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;
fs/cifs/file.c +3 -0
index 777e7f4..b36de2e 100644
@@ -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);
 
Quoted 9 lines
Quoted 6 lines

fs/cifs/file.c void cifsFileInfo_put(struct cifsFileInfo *cifs_file) · line 291

Quoted 3 lines
fs/cifs/file.c +3 -0
+     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....

Can you explain what bad happens in this case?

It looks like you'll be invalidating potentially up-to-date data. Either way...I've been steadily trying to move the code to a more well-defined codepath for invalidating dirty data. Zapping the cached pages here is unnecessary. It would be better to just mark the inode as having an invalid mapping and move on, unless you see some other reason why we must zap all of the pages here.

Quoted 13 lines
Quoted 10 lines

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.

Quoted 3 lines
fs/cifs/file.c +0 -0
       if (!tcon->need_reconnect && !cifs_file->invalidHandle) {
               int xid, rc;
 
Signature · 1 line
Jeff Layton <[email protected]>
#9 lore raw

PATCH 2/6 CIFS: Make read call work with strict cache mode

In reply to a message not in the archive

Add cifs_file_aio_read where we read from the cache if we have at least Level II oplock - otherwise read from the server.

---
 fs/cifs/cifsfs.c |   28 ++++++++++++++++++++++++++--
 1 files changed, 26 insertions(+), 2 deletions(-)
fs/cifs/cifsfs.c +26 -2
index 38526a6..bb7f36e 100644
@@ -569,6 +569,30 @@ cifs_do_mount(struct file_system_type *fs_type,
 	return dget(sb->s_root);
 }
 
+static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
+				   unsigned long nr_segs, loff_t pos)
+{
+	struct inode *inode;
+	struct cifs_sb_info *cifs_sb;
+	ssize_t read;
+
+	inode = iocb->ki_filp->f_path.dentry->d_inode;
+	cifs_sb = CIFS_SB(iocb->ki_filp->f_path.dentry->d_sb);
+
+	if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) == 0)
+		/* BB call cifs_revalidate_file before generic_file_aio_read */
+		return generic_file_aio_read(iocb, iov, nr_segs, pos);
+
+	if (!CIFS_I(inode)->clientCanCacheRead) {
+		read = cifs_user_read(iocb->ki_filp, iov->iov_base,
+				      iov->iov_len, &pos);
+		iocb->ki_pos = pos;
+	} else
+		read = generic_file_aio_read(iocb, iov, nr_segs, pos);
+
+	return read;
+}
+
 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
 				   unsigned long nr_segs, loff_t pos)
 {
@@ -691,7 +715,7 @@ const struct inode_operations cifs_symlink_inode_ops = {
 const struct file_operations cifs_file_ops = {
 	.read = do_sync_read,
 	.write = do_sync_write,
-	.aio_read = generic_file_aio_read,
+	.aio_read = cifs_file_aio_read,
 	.aio_write = cifs_file_aio_write,
 	.open = cifs_open,
 	.release = cifs_close,
@@ -728,7 +752,7 @@ const struct file_operations cifs_file_direct_ops = {
 const struct file_operations cifs_file_nobrl_ops = {
 	.read = do_sync_read,
 	.write = do_sync_write,
-	.aio_read = generic_file_aio_read,
+	.aio_read = cifs_file_aio_read,
 	.aio_write = cifs_file_aio_write,
 	.open = cifs_open,
 	.release = cifs_close,
Signature · 1 line
1.7.2.3

A message that is not in the archive (sent off-list or not yet received): 1288945777-9197-3-git-send-email-piastryyy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#11 lore raw

Re: [PATCH 2/6] CIFS: Make read call work with strict cache mode

Quoted 30 lines · On Fri, 5 Nov 2010 11:29:33 +0300 Pavel Shilovsky…

Add cifs_file_aio_read where we read from the cache if we have at least Level II oplock - otherwise read from the server.

---
 fs/cifs/cifsfs.c |   28 ++++++++++++++++++++++++++--
 1 files changed, 26 insertions(+), 2 deletions(-)
fs/cifs/cifsfs.c +14 -0
index 38526a6..bb7f36e 100644
@@ -569,6 +569,30 @@ cifs_do_mount(struct file_system_type *fs_type,
 	return dget(sb->s_root);
 }
 
+static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
+				   unsigned long nr_segs, loff_t pos)
+{
+	struct inode *inode;
+	struct cifs_sb_info *cifs_sb;
+	ssize_t read;
+
+	inode = iocb->ki_filp->f_path.dentry->d_inode;
+	cifs_sb = CIFS_SB(iocb->ki_filp->f_path.dentry->d_sb);
+
+	if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) == 0)
+		/* BB call cifs_revalidate_file before generic_file_aio_read */
+		return generic_file_aio_read(iocb, iov, nr_segs, pos);
+

fs/cifs/cifsfs.c cifs_do_mount(struct file_system_type *fs_type, · line 595

Quoted 10 lines
fs/cifs/cifsfs.c +10 -0
+	if (!CIFS_I(inode)->clientCanCacheRead) {
+		read = cifs_user_read(iocb->ki_filp, iov->iov_base,
+				      iov->iov_len, &pos);
+		iocb->ki_pos = pos;
+	} else
+		read = generic_file_aio_read(iocb, iov, nr_segs, pos);
+
+	return read;
+}
+

This looks more convoluted than it really ought to be. Something like this would be better:

if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) == 0 ||

    CIFS_I(inode)->clientCanCacheRead)
	return generic_file_aio_read(iocb, iov, nr_segs, pos);

read = cifs_user_read(iocb->ki_filp, iov->iov_base, ...

Quoted 21 lines
fs/cifs/cifsfs.c +2 -2
 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
 				   unsigned long nr_segs, loff_t pos)
 {
@@ -691,7 +715,7 @@ const struct inode_operations cifs_symlink_inode_ops = {
 const struct file_operations cifs_file_ops = {
 	.read = do_sync_read,
 	.write = do_sync_write,
-	.aio_read = generic_file_aio_read,
+	.aio_read = cifs_file_aio_read,
 	.aio_write = cifs_file_aio_write,
 	.open = cifs_open,
 	.release = cifs_close,
@@ -728,7 +752,7 @@ const struct file_operations cifs_file_direct_ops = {
 const struct file_operations cifs_file_nobrl_ops = {
 	.read = do_sync_read,
 	.write = do_sync_write,
-	.aio_read = generic_file_aio_read,
+	.aio_read = cifs_file_aio_read,
 	.aio_write = cifs_file_aio_write,
 	.open = cifs_open,
 	.release = cifs_close,
#12 lore raw

PATCH 3/6 CIFS: Make write call work with strict cache mode

In reply to a message not in the archive

On strict cache mode if we don't have Exclusive oplock we write a data to the server through cifs_user_write. Then if we Level II oplock store it in the cache, otherwise - invalidate inode pages affected by this writing.

---
 fs/cifs/cifsfs.c |   51 ++++++++++++++++++++++++++++++++++++++++++++++-----
 fs/cifs/file.c   |   14 ++++++++++++--
 2 files changed, 58 insertions(+), 7 deletions(-)
fs/cifs/cifsfs.c +46 -5
index bb7f36e..fbcd219 100644
@@ -596,12 +596,53 @@ static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
 				   unsigned long nr_segs, loff_t pos)
 {
-	struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
-	ssize_t written;
+	struct inode *inode;
+	struct cifs_sb_info *cifs_sb;
+	ssize_t written, cache_written;
+	loff_t saved_pos;
+
+	inode = iocb->ki_filp->f_path.dentry->d_inode;
+
+	if (CIFS_I(inode)->clientCanCacheAll)
+		return generic_file_aio_write(iocb, iov, nr_segs, pos);
+
+	cifs_sb = CIFS_SB(iocb->ki_filp->f_path.dentry->d_sb);
+
+	if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) == 0) {
+		int rc;
+
+		written = generic_file_aio_write(iocb, iov, nr_segs, pos);
+
+		rc = filemap_fdatawrite(inode->i_mapping);
+		if (rc)
+			cFYI(1, "cifs_file_aio_write: %d rc on %p inode",
+			     rc, inode);
+		return written;
+	}
+
+	saved_pos = pos;
+	written = cifs_user_write(iocb->ki_filp, iov->iov_base,
+				  iov->iov_len, &pos);
+
+	if (written > 0 && CIFS_I(inode)->clientCanCacheRead) {
+		/* we have data written to the server and at least oplock
+		   for reading - store the date in the cache */
+		cache_written = generic_file_aio_write(iocb, iov,
+						       nr_segs, saved_pos);
+		if (cache_written != written)
+			cERROR(1, "Cache written and server written data "
+			       "lengths are different");
+		return written;
+	}
+
+	if (written > 0)
+		invalidate_mapping_pages(inode->i_mapping,
+					      saved_pos >> PAGE_CACHE_SHIFT,
+					      (saved_pos+iov->iov_len-1)
+					      >> PAGE_CACHE_SHIFT);
+
+	iocb->ki_pos = pos;
 
-	written = generic_file_aio_write(iocb, iov, nr_segs, pos);
-	if (!CIFS_I(inode)->clientCanCacheAll)
-		filemap_fdatawrite(inode->i_mapping);
 	return written;
 }
 
fs/cifs/file.c +12 -2
index b36de2e..85824c0 100644
@@ -1537,7 +1537,11 @@ static int cifs_write_end(struct file *file, struct address_space *mapping,
 			struct page *page, void *fsdata)
 {
 	int rc;
-	struct inode *inode = mapping->host;
+	struct inode *inode;
+	struct cifs_sb_info *cifs_sb;
+
+	inode = mapping->host;
+	cifs_sb = CIFS_SB(inode->i_sb);
 
 	cFYI(1, "write_end for page %p from pos %lld with %d bytes",
 		 page, pos, copied);
@@ -1570,7 +1574,13 @@ static int cifs_write_end(struct file *file, struct address_space *mapping,
 	} else {
 		rc = copied;
 		pos += copied;
-		set_page_dirty(page);
+		/* if we have strict cache switched on and don't have Exclusive
+		   oplock for the inode, we don't have to set_page_dirty
+		   because we flushed the data to the server in
+		   cifs_file_aio_write before */
+		if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) == 0 ||
+		    CIFS_I(inode)->clientCanCacheAll)
+			set_page_dirty(page);
 	}
 
 	if (rc > 0) {
Signature · 1 line
1.7.2.3

A message that is not in the archive (sent off-list or not yet received): 1288945777-9197-4-git-send-email-piastryyy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#14 lore raw

PATCH 3/6 CIFS: Make write call work with strict cache mode

On strict cache mode if we don't have Exclusive oplock we write a data to the server through cifs_user_write. Then if we Level II oplock store it in the cache, otherwise - invalidate inode pages affected by this writing.

---
 fs/cifs/cifsfs.c |   51 ++++++++++++++++++++++++++++++++++++++++++++++-----
 fs/cifs/file.c   |   14 ++++++++++++--
 2 files changed, 58 insertions(+), 7 deletions(-)
fs/cifs/cifsfs.c +46 -5
index bb7f36e..fbcd219 100644
@@ -596,12 +596,53 @@ static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
 				   unsigned long nr_segs, loff_t pos)
 {
-	struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
-	ssize_t written;
+	struct inode *inode;
+	struct cifs_sb_info *cifs_sb;
+	ssize_t written, cache_written;
+	loff_t saved_pos;
+
+	inode = iocb->ki_filp->f_path.dentry->d_inode;
+
+	if (CIFS_I(inode)->clientCanCacheAll)
+		return generic_file_aio_write(iocb, iov, nr_segs, pos);
+
+	cifs_sb = CIFS_SB(iocb->ki_filp->f_path.dentry->d_sb);
+
+	if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) == 0) {
+		int rc;
+
+		written = generic_file_aio_write(iocb, iov, nr_segs, pos);
+
+		rc = filemap_fdatawrite(inode->i_mapping);
+		if (rc)
+			cFYI(1, "cifs_file_aio_write: %d rc on %p inode",
+			     rc, inode);
+		return written;
+	}
+
+	saved_pos = pos;
+	written = cifs_user_write(iocb->ki_filp, iov->iov_base,
+				  iov->iov_len, &pos);
+
+	if (written > 0 && CIFS_I(inode)->clientCanCacheRead) {
+		/* we have a data written to the server and at least oplock
+		   for reading - store the data in the cache */
+		cache_written = generic_file_aio_write(iocb, iov,
+						       nr_segs, saved_pos);
+		if (cache_written != written)
+			cERROR(1, "Cache written and server written data "
+			       "lengths are different");
+		return written;
+	}
+
+	if (written > 0)
+		invalidate_mapping_pages(inode->i_mapping,
+					      saved_pos >> PAGE_CACHE_SHIFT,
+					      (saved_pos+iov->iov_len-1)
+					      >> PAGE_CACHE_SHIFT);
+
+	iocb->ki_pos = pos;
 
-	written = generic_file_aio_write(iocb, iov, nr_segs, pos);
-	if (!CIFS_I(inode)->clientCanCacheAll)
-		filemap_fdatawrite(inode->i_mapping);
 	return written;
 }
 
fs/cifs/file.c +12 -2
index b36de2e..85824c0 100644
@@ -1537,7 +1537,11 @@ static int cifs_write_end(struct file *file, struct address_space *mapping,
 			struct page *page, void *fsdata)
 {
 	int rc;
-	struct inode *inode = mapping->host;
+	struct inode *inode;
+	struct cifs_sb_info *cifs_sb;
+
+	inode = mapping->host;
+	cifs_sb = CIFS_SB(inode->i_sb);
 
 	cFYI(1, "write_end for page %p from pos %lld with %d bytes",
 		 page, pos, copied);
@@ -1570,7 +1574,13 @@ static int cifs_write_end(struct file *file, struct address_space *mapping,
 	} else {
 		rc = copied;
 		pos += copied;
-		set_page_dirty(page);
+		/* if we have strict cache switched on and don't have Exclusive
+		   oplock for the inode, we don't have to set_page_dirty
+		   because we flushed the data to the server in
+		   cifs_file_aio_write before */
+		if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) == 0 ||
+		    CIFS_I(inode)->clientCanCacheAll)
+			set_page_dirty(page);
 	}
 
 	if (rc > 0) {
Signature · 1 line
1.7.2.3
#15 lore raw

Re: [PATCH 3/6] CIFS: Make write call work with strict cache mode

In reply to a message not in the archive
Quoted 92 lines · On Fri, 5 Nov 2010 11:29:34 +0300 Pavel Shilovsky…

On strict cache mode if we don't have Exclusive oplock we write a data to the server through cifs_user_write. Then if we Level II oplock store it in the cache, otherwise - invalidate inode pages affected by this writing.

---
 fs/cifs/cifsfs.c |   51 ++++++++++++++++++++++++++++++++++++++++++++++-----
 fs/cifs/file.c   |   14 ++++++++++++--
 2 files changed, 58 insertions(+), 7 deletions(-)
fs/cifs/cifsfs.c +46 -5
index bb7f36e..fbcd219 100644
@@ -596,12 +596,53 @@ static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
 				   unsigned long nr_segs, loff_t pos)
 {
-	struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
-	ssize_t written;
+	struct inode *inode;
+	struct cifs_sb_info *cifs_sb;
+	ssize_t written, cache_written;
+	loff_t saved_pos;
+
+	inode = iocb->ki_filp->f_path.dentry->d_inode;
+
+	if (CIFS_I(inode)->clientCanCacheAll)
+		return generic_file_aio_write(iocb, iov, nr_segs, pos);
+
+	cifs_sb = CIFS_SB(iocb->ki_filp->f_path.dentry->d_sb);
+
+	if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) == 0) {
+		int rc;
+
+		written = generic_file_aio_write(iocb, iov, nr_segs, pos);
+
+		rc = filemap_fdatawrite(inode->i_mapping);
+		if (rc)
+			cFYI(1, "cifs_file_aio_write: %d rc on %p inode",
+			     rc, inode);
+		return written;
+	}
+
+	saved_pos = pos;
+	written = cifs_user_write(iocb->ki_filp, iov->iov_base,
+				  iov->iov_len, &pos);
+
+	if (written > 0 && CIFS_I(inode)->clientCanCacheRead) {
+		/* we have data written to the server and at least oplock
+		   for reading - store the date in the cache */
+		cache_written = generic_file_aio_write(iocb, iov,
+						       nr_segs, saved_pos);
+		if (cache_written != written)
+			cERROR(1, "Cache written and server written data "
+			       "lengths are different");
+		return written;
+	}
+
+	if (written > 0)
+		invalidate_mapping_pages(inode->i_mapping,
+					      saved_pos >> PAGE_CACHE_SHIFT,
+					      (saved_pos+iov->iov_len-1)
+					      >> PAGE_CACHE_SHIFT);
+
+	iocb->ki_pos = pos;
 
-	written = generic_file_aio_write(iocb, iov, nr_segs, pos);
-	if (!CIFS_I(inode)->clientCanCacheAll)
-		filemap_fdatawrite(inode->i_mapping);
 	return written;
 }
 
fs/cifs/file.c +5 -1
index b36de2e..85824c0 100644
@@ -1537,7 +1537,11 @@ static int cifs_write_end(struct file *file, struct address_space *mapping,
 			struct page *page, void *fsdata)
 {
 	int rc;
-	struct inode *inode = mapping->host;
+	struct inode *inode;
+	struct cifs_sb_info *cifs_sb;
+
+	inode = mapping->host;
+	cifs_sb = CIFS_SB(inode->i_sb);
 
 	cFYI(1, "write_end for page %p from pos %lld with %d bytes",
 		 page, pos, copied);
@@ -1570,7 +1574,13 @@ static int cifs_write_end(struct file *file, struct address_space *mapping,
 	} else {

fs/cifs/file.c static int cifs_write_end(struct file *file, struct address_space *mapping, · line 1583

Quoted 10 lines
fs/cifs/file.c +7 -1
 		rc = copied;
 		pos += copied;
-		set_page_dirty(page);
+		/* if we have strict cache switched on and don't have Exclusive
+		   oplock for the inode, we don't have to set_page_dirty
+		   because we flushed the data to the server in
+		   cifs_file_aio_write before */
+		if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) == 0 ||
+		    CIFS_I(inode)->clientCanCacheAll)
+			set_page_dirty(page);

Is there a potential for a race here? Suppose I have clientCanCacheAll set, I write to the cache, but before I get to cifs_write_end, an oplock break is processed and clientCanCacheAll is cleared. Now I have dirty data in cache but the dirty flag doesn't get set. Does anything prevent that?

Quoted 3 lines
fs/cifs/file.c +0 -0
 	}
 
 	if (rc > 0) {

A message that is not in the archive (sent off-list or not yet received): 20101109131001.56a40c86-4QP7MXygkU+dMjc06nkz3ljfA9RmPOcC@public.gmane.org

#17 lore raw

Re: [PATCH 3/6] CIFS: Make write call work with strict cache mode

2010/11/9 Jeff Layton <[email protected]>:

Quoted 103 lines
Quoted 100 lines · On Fri,  5 Nov 2010 11:29:34 +0300 Pavel Shilovsky…

On strict cache mode if we don't have Exclusive oplock we write a data to the server through cifs_user_write. Then if we Level II oplock store it in the cache, otherwise - invalidate inode pages affected by this writing.

---
 fs/cifs/cifsfs.c |   51 ++++++++++++++++++++++++++++++++++++++++++++++----- fs/cifs/file.c   |   14 ++++++++++++--

 2 files changed, 58 insertions(+), 7 deletions(-)
fs/cifs/cifsfs.c +46 -5
index bb7f36e..fbcd219 100644
@@ -596,12 +596,53 @@ static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
  static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
                                  unsigned long nr_segs, loff_t pos)
  {
-     struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
-     ssize_t written;
+     struct inode *inode;
+     struct cifs_sb_info *cifs_sb;
+     ssize_t written, cache_written;
+     loff_t saved_pos;
+
+     inode = iocb->ki_filp->f_path.dentry->d_inode;
+
+     if (CIFS_I(inode)->clientCanCacheAll)
+             return generic_file_aio_write(iocb, iov, nr_segs, pos);
+
+     cifs_sb = CIFS_SB(iocb->ki_filp->f_path.dentry->d_sb);
+
+     if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) == 0) {
+             int rc;
+
+             written = generic_file_aio_write(iocb, iov, nr_segs, pos);
+
+             rc = filemap_fdatawrite(inode->i_mapping);
+             if (rc)
+                     cFYI(1, "cifs_file_aio_write: %d rc on %p inode",
+                          rc, inode);
+             return written;
+     }
+
+     saved_pos = pos;
+     written = cifs_user_write(iocb->ki_filp, iov->iov_base,
+                               iov->iov_len, &pos);
+
+     if (written > 0 && CIFS_I(inode)->clientCanCacheRead) {
+             /* we have data written to the server and at least oplock
+                for reading - store the date in the cache */
+             cache_written = generic_file_aio_write(iocb, iov,
+                                                    nr_segs, saved_pos);
+             if (cache_written != written)
+                     cERROR(1, "Cache written and server written data "
+                            "lengths are different");
+             return written;
+     }
+
+     if (written > 0)
+             invalidate_mapping_pages(inode->i_mapping,
+                                           saved_pos >> PAGE_CACHE_SHIFT,
+                                           (saved_pos+iov->iov_len-1)
+                                           >> PAGE_CACHE_SHIFT);
+
+     iocb->ki_pos = pos;
 
-     written = generic_file_aio_write(iocb, iov, nr_segs, pos);
-     if (!CIFS_I(inode)->clientCanCacheAll)
-             filemap_fdatawrite(inode->i_mapping);
       return written;
  }
 
fs/cifs/file.c +10 -2
index b36de2e..85824c0 100644
@@ -1537,7 +1537,11 @@ static int cifs_write_end(struct file *file, struct address_space *mapping,
                       struct page *page, void *fsdata)
  {
       int rc;
-     struct inode *inode = mapping->host;
+     struct inode *inode;
+     struct cifs_sb_info *cifs_sb;
+
+     inode = mapping->host;
+     cifs_sb = CIFS_SB(inode->i_sb);
 
       cFYI(1, "write_end for page %p from pos %lld with %d bytes",
                page, pos, copied);
@@ -1570,7 +1574,13 @@ static int cifs_write_end(struct file *file, struct address_space *mapping,
       } else {
               rc = copied;
               pos += copied;
-             set_page_dirty(page);
+             /* if we have strict cache switched on and don't have Exclusive
+                oplock for the inode, we don't have to set_page_dirty
+                because we flushed the data to the server in
+                cifs_file_aio_write before */
+             if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) == 0 ||
Quoted 8 lines

fs/cifs/file.c static int cifs_write_end(struct file *file, struct address_space *mapping, · line 1583

Quoted 2 lines
fs/cifs/file.c +2 -0
+                 CIFS_I(inode)->clientCanCacheAll)
+                     set_page_dirty(page);

Is there a potential for a race here? Suppose I have clientCanCacheAll set, I write to the cache, but before I get to cifs_write_end, an oplock break is processed and clientCanCacheAll is cleared. Now I have dirty data in cache but the dirty flag doesn't get set. Does anything prevent that?

Yes, you are right. In the case of clientCanCacheAll and STRICT_IO set
- can we call set_page_dirty for every page affected by our write in cifs_file_aio_write? It should prevent races, I think.

Quoted 5 lines
Quoted 4 lines
fs/cifs/file.c +0 -0
       }
 
       if (rc > 0) {
Signature · 2 lines
Best regards,
Pavel Shilovsky.

A message that is not in the archive (sent off-list or not yet received): AANLkTik-0k-p_XeWjd79-Popa57g-BFcLtB-XY55mktw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#19 lore raw

Re: [PATCH 3/6] CIFS: Make write call work with strict cache mode

Quoted 113 lines · On Tue, 9 Nov 2010 21:16:44 +0300 Pavel Shilovsky…

2010/11/9 Jeff Layton <[email protected]>:

Quoted 103 lines
Quoted 100 lines · On Fri,  5 Nov 2010 11:29:34 +0300 Pavel Shilovsky…

On strict cache mode if we don't have Exclusive oplock we write a data to the server through cifs_user_write. Then if we Level II oplock store it in the cache, otherwise - invalidate inode pages affected by this writing.

---
 fs/cifs/cifsfs.c |   51 ++++++++++++++++++++++++++++++++++++++++++++++----- fs/cifs/file.c   |   14 ++++++++++++--

 2 files changed, 58 insertions(+), 7 deletions(-)
fs/cifs/cifsfs.c +46 -5
index bb7f36e..fbcd219 100644
@@ -596,12 +596,53 @@ static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
  static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
                                  unsigned long nr_segs, loff_t pos)
  {
-     struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
-     ssize_t written;
+     struct inode *inode;
+     struct cifs_sb_info *cifs_sb;
+     ssize_t written, cache_written;
+     loff_t saved_pos;
+
+     inode = iocb->ki_filp->f_path.dentry->d_inode;
+
+     if (CIFS_I(inode)->clientCanCacheAll)
+             return generic_file_aio_write(iocb, iov, nr_segs, pos);
+
+     cifs_sb = CIFS_SB(iocb->ki_filp->f_path.dentry->d_sb);
+
+     if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) == 0) {
+             int rc;
+
+             written = generic_file_aio_write(iocb, iov, nr_segs, pos);
+
+             rc = filemap_fdatawrite(inode->i_mapping);
+             if (rc)
+                     cFYI(1, "cifs_file_aio_write: %d rc on %p inode",
+                          rc, inode);
+             return written;
+     }
+
+     saved_pos = pos;
+     written = cifs_user_write(iocb->ki_filp, iov->iov_base,
+                               iov->iov_len, &pos);
+
+     if (written > 0 && CIFS_I(inode)->clientCanCacheRead) {
+             /* we have data written to the server and at least oplock
+                for reading - store the date in the cache */
+             cache_written = generic_file_aio_write(iocb, iov,
+                                                    nr_segs, saved_pos);
+             if (cache_written != written)
+                     cERROR(1, "Cache written and server written data "
+                            "lengths are different");
+             return written;
+     }
+
+     if (written > 0)
+             invalidate_mapping_pages(inode->i_mapping,
+                                           saved_pos >> PAGE_CACHE_SHIFT,
+                                           (saved_pos+iov->iov_len-1)
+                                           >> PAGE_CACHE_SHIFT);
+
+     iocb->ki_pos = pos;
 
-     written = generic_file_aio_write(iocb, iov, nr_segs, pos);
-     if (!CIFS_I(inode)->clientCanCacheAll)
-             filemap_fdatawrite(inode->i_mapping);
       return written;
  }
 
fs/cifs/file.c +10 -2
index b36de2e..85824c0 100644
@@ -1537,7 +1537,11 @@ static int cifs_write_end(struct file *file, struct address_space *mapping,
                       struct page *page, void *fsdata)
  {
       int rc;
-     struct inode *inode = mapping->host;
+     struct inode *inode;
+     struct cifs_sb_info *cifs_sb;
+
+     inode = mapping->host;
+     cifs_sb = CIFS_SB(inode->i_sb);
 
       cFYI(1, "write_end for page %p from pos %lld with %d bytes",
                page, pos, copied);
@@ -1570,7 +1574,13 @@ static int cifs_write_end(struct file *file, struct address_space *mapping,
       } else {
               rc = copied;
               pos += copied;
-             set_page_dirty(page);
+             /* if we have strict cache switched on and don't have Exclusive
+                oplock for the inode, we don't have to set_page_dirty
+                because we flushed the data to the server in
+                cifs_file_aio_write before */
+             if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) == 0 ||
Quoted 8 lines

fs/cifs/file.c static int cifs_write_end(struct file *file, struct address_space *mapping, · line 1583

Quoted 2 lines
fs/cifs/file.c +2 -0
+                 CIFS_I(inode)->clientCanCacheAll)
+                     set_page_dirty(page);

Is there a potential for a race here? Suppose I have clientCanCacheAll set, I write to the cache, but before I get to cifs_write_end, an oplock break is processed and clientCanCacheAll is cleared. Now I have dirty data in cache but the dirty flag doesn't get set. Does anything prevent that?

Quoted 4 lines

Yes, you are right. In the case of clientCanCacheAll and STRICT_IO set
- can we call set_page_dirty for every page affected by our write in cifs_file_aio_write? It should prevent races, I think.

Hmm...setting the dirty bit before the data has actually been copied to the page? I'm not sure that's a good idea. If you want to do that you may want to run it by linux-fsdevel first.

Maybe you could do something instead with the fsdata pointer in write_begin and write_end?

Signature · 1 line
Jeff Layton <[email protected]>

A message that is not in the archive (sent off-list or not yet received): 20101110070420.74daca64-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org

#21 lore raw

Re: [PATCH 3/6] CIFS: Make write call work with strict cache mode

2010/11/10 Jeff Layton <[email protected]>:

Quoted 8 lines

Hmm...setting the dirty bit before the data has actually been copied to the page? I'm not sure that's a good idea. If you want to do that you may want to run it by linux-fsdevel first.

Maybe you could do something instead with the fsdata pointer in write_begin and write_end?

Jeff, what's about simply invalidating inode range if we don't have exlusive oplock after cifs_user_write? I don't think that there is a chance to write a data to the server and keep oplock level II in the same time - so no need for storing the data in the cache at all. And if we don't store it in the cache we don't need to modify cifs_write_end - no races.

so, I mean the following:

+ if (CIFS_I(inode)->clientCanCacheAll)
+ return generic_file_aio_write(iocb, iov, nr_segs, pos);
+
+ cifs_sb = CIFS_SB(iocb->ki_filp->f_path.dentry->d_sb);
+
+ if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) == 0) {
+ int rc;
+
+ written = generic_file_aio_write(iocb, iov, nr_segs, pos);
+
+ rc = filemap_fdatawrite(inode->i_mapping);
+ if (rc)
+ cFYI(1, "cifs_file_aio_write: %d rc on %p inode",
+ rc, inode);
+ return written;
+ }
+
+ written = cifs_user_write(iocb->ki_filp, iov->iov_base,
+ iov->iov_len, &pos);
+
+ if (written > 0)
+ invalidate_mapping_pages(inode->i_mapping,
+ (pos-written) >> PAGE_CACHE_SHIFT,
+ (pos-1) >> PAGE_CACHE_SHIFT);
+ iocb->ki_pos = pos;

Signature · 2 lines
Best regards,
Pavel Shilovsky.

A message that is not in the archive (sent off-list or not yet received): AANLkTikCh+UgGRwdXqTjrZXEonb+J-c=NpxQ-Ph16Emt-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#23 lore raw

Re: [PATCH 3/6] CIFS: Make write call work with strict cache mode

Quoted 35 lines · On Wed, 10 Nov 2010 16:15:33 +0300 Pavel Shilovsky…

2010/11/10 Jeff Layton <[email protected]>:

Quoted 8 lines

Hmm...setting the dirty bit before the data has actually been copied to the page? I'm not sure that's a good idea. If you want to do that you may want to run it by linux-fsdevel first.

Maybe you could do something instead with the fsdata pointer in write_begin and write_end?

Jeff, what's about simply invalidating inode range if we don't have exlusive oplock after cifs_user_write? I don't think that there is a chance to write a data to the server and keep oplock level II in the same time - so no need for storing the data in the cache at all. And if we don't store it in the cache we don't need to modify cifs_write_end - no races.

so, I mean the following:

(quoted diff) +15 -0
+       if (CIFS_I(inode)->clientCanCacheAll)
+               return generic_file_aio_write(iocb, iov, nr_segs, pos);
+
+       cifs_sb = CIFS_SB(iocb->ki_filp->f_path.dentry->d_sb);
+
+       if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) == 0) {
+               int rc;
+
+               written = generic_file_aio_write(iocb, iov, nr_segs, pos);
+
+               rc = filemap_fdatawrite(inode->i_mapping);
+               if (rc)
+                       cFYI(1, "cifs_file_aio_write: %d rc on %p inode",
+                            rc, inode);
+               return written;

Review

Quoted 10 lines
(quoted diff) +10 -0
+       }
+
+       written = cifs_user_write(iocb->ki_filp, iov->iov_base,
+                                 iov->iov_len, &pos);
+
+       if (written > 0)
+               invalidate_mapping_pages(inode->i_mapping,
+                                             (pos-written) >> PAGE_CACHE_SHIFT,
+                                             (pos-1) >> PAGE_CACHE_SHIFT);
+       iocb->ki_pos = pos;

That might work, and it gets around the ugly double write thing that the earlier patches did.

You're probably right that most servers won't allow you to keep a level II oplock and write to the file. If one does, then the pages will have to be refaulted in, of course which will suck for performance, but I'm not terribly concerned about that.

Also, please take some time and sprinkle some comments in there too. In a year or two we'll be struggling to recall this conversation to figure out why it was done this way...

Signature · 1 line
Jeff Layton <[email protected]>
#24 lore raw

PATCH 4/6 CIFS: Make cifs_fsync work with strict cache mode

In reply to a message not in the archive

Remove filemap_write_and_wait call because it is previously called from vfs_sync_range and invalidate inode if we don't have at least Level II oplock and strcit cache mode switched on.

---
 fs/cifs/file.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
fs/cifs/file.c +7 -7
index 85824c0..e8ca2d6 100644
@@ -1603,20 +1603,20 @@ int cifs_fsync(struct file *file, int datasync)
 	struct cifsTconInfo *tcon;
 	struct cifsFileInfo *smbfile = file->private_data;
 	struct inode *inode = file->f_path.dentry->d_inode;
+	struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
 
 	xid = GetXid();
 
 	cFYI(1, "Sync file - name: %s datasync: 0x%x",
 		file->f_path.dentry->d_name.name, datasync);
 
-	rc = filemap_write_and_wait(inode->i_mapping);
-	if (rc == 0) {
-		struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
+	if (!CIFS_I(inode)->clientCanCacheRead &&
+	    ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) == 0))
+		invalidate_remote_inode(inode);
 
-		tcon = tlink_tcon(smbfile->tlink);
-		if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC))
-			rc = CIFSSMBFlush(xid, tcon, smbfile->netfid);
-	}
+	tcon = tlink_tcon(smbfile->tlink);
+	if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC))
+		rc = CIFSSMBFlush(xid, tcon, smbfile->netfid);
 
 	FreeXid(xid);
 	return rc;
Signature · 1 line
1.7.2.3
#25 lore raw

PATCH 5/6 CIFS: Make cifs_file_map work with strict cache mode

In reply to a message not in the archive

Invalidate inode if we don't have at least Level II oplock and strict cache mode switched on.

---
 fs/cifs/file.c |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)
fs/cifs/file.c +15 -5
index e8ca2d6..81eb840 100644
@@ -1820,14 +1820,24 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
 int cifs_file_mmap(struct file *file, struct vm_area_struct *vma)
 {
 	int rc, xid;
+	struct inode *inode = file->f_path.dentry->d_inode;
+	struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
 
 	xid = GetXid();
-	rc = cifs_revalidate_file(file);
-	if (rc) {
-		cFYI(1, "Validation prior to mmap failed, error=%d", rc);
-		FreeXid(xid);
-		return rc;
+
+	if (!CIFS_I(inode)->clientCanCacheRead &&
+	    ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) == 0))
+		invalidate_remote_inode(inode);
+	else {
+		rc = cifs_revalidate_file(file);
+		if (rc) {
+			cFYI(1, "Validation prior to mmap failed, error=%d",
+			     rc);
+			FreeXid(xid);
+			return rc;
+		}
 	}
+
 	rc = generic_file_mmap(file, vma);
 	FreeXid(xid);
 	return rc;
Signature · 1 line
1.7.2.3
#26 lore raw

PATCH 6/6 CIFS: Add strictcache mount option

In reply to a message not in the archive

Use for switching on strict cache mode. In this mode the client read from the cache all the time it has Oplock Level II, otherwise - read from the server. All written data are stored in the cache, but if the client doesn't have Exclusive Oplock, it writes the data to the server.

---
 fs/cifs/README    |    5 +++++
 fs/cifs/connect.c |    5 +++++
 2 files changed, 10 insertions(+), 0 deletions(-)
fs/cifs/README +5 -0
index ee68d10..8fb6192 100644
@@ -443,6 +443,11 @@ A partial list of the supported mount options follows:
 		if oplock (caching token) is granted and held. Note that
 		direct allows write operations larger than page size
 		to be sent to the server.
+  strictcache   Use for switching on strict cache mode. In this mode the
+		client read from the cache all the time it has Oplock Level II,
+		otherwise - read from the server. All written data are stored
+		in the cache, but if the client doesn't have Exclusive Oplock,
+		it writes the data to the server.
   acl   	Allow setfacl and getfacl to manage posix ACLs if server
 		supports them.  (default)
   noacl 	Do not allow setfacl and getfacl calls on this mount
fs/cifs/connect.c +5 -0
index 251a17c..97286c7 100644
@@ -84,6 +84,7 @@ struct smb_vol {
 	bool no_xattr:1;   /* set if xattr (EA) support should be disabled*/
 	bool server_ino:1; /* use inode numbers from server ie UniqueId */
 	bool direct_io:1;
+	bool strict_io:1; /* strict cache behavior */
 	bool remap:1;      /* set to remap seven reserved chars in filenames */
 	bool posix_paths:1; /* unset to not ask for posix pathnames. */
 	bool no_linux_ext:1;
@@ -1347,6 +1348,8 @@ cifs_parse_mount_options(char *options, const char *devname,
 			vol->direct_io = 1;
 		} else if (strnicmp(data, "forcedirectio", 13) == 0) {
 			vol->direct_io = 1;
+		} else if (strnicmp(data, "strictcache", 11) == 0) {
+			vol->strict_io = 1;
 		} else if (strnicmp(data, "noac", 4) == 0) {
 			printk(KERN_WARNING "CIFS: Mount option noac not "
 				"supported. Instead set "
@@ -2597,6 +2600,8 @@ static void setup_cifs_sb(struct smb_vol *pvolume_info,
 	if (pvolume_info->multiuser)
 		cifs_sb->mnt_cifs_flags |= (CIFS_MOUNT_MULTIUSER |
 					    CIFS_MOUNT_NO_PERM);
+	if (pvolume_info->strict_io)
+		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_STRICT_IO;
 	if (pvolume_info->direct_io) {
 		cFYI(1, "mounting share using direct i/o");
 		cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DIRECT_IO;
Signature · 1 line
1.7.2.3
#27 lore raw
In reply to a message not in the archive

2010/11/5 Pavel Shilovsky <[email protected]>:

Quoted 15 lines

I add new ones (fsync, mmap) and modified previous patches (read, write, close) and their descriptions. Here is the complete set of them.

Pavel Shilovsky (6):
 CIFS: Make cifsFileInfo_put work with strict cache mode
 CIFS: Make read call work with strict cache mode
 CIFS: Make write call work with strict cache mode
 CIFS: Make cifs_fsync work with strict cache mode
 CIFS: Make cifs_file_map work with strict cache mode
 CIFS: Add strictcache mount option

 fs/cifs/README       |    5 +++
 fs/cifs/cifs_fs_sb.h |    1 +
 fs/cifs/cifsfs.c     |   79 +++++++++++++++++++++++++++++++++++++++++++++---- fs/cifs/connect.c    |    5 +++
 fs/cifs/file.c       |   54 +++++++++++++++++++++++++---------

Quoted 6 lines
 5 files changed, 123 insertions(+), 21 deletions(-)

--
1.7.2.3

What's about this set of patches?

Signature · 2 lines
Best regards,
Pavel Shilovsky.