Skip to contentSkip to conversation

Add strict cache mode (try #4)

PATCH In review Pavel Shilovsky 5 participants 33 messages Nov 28, 2010 – Dec 6, 2010 22 messages not in the archive

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

cover Add strict cache mode (try #4)

Re-posting the whole set of strict cache patches.

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

 fs/cifs/README       |    5 +++
 fs/cifs/cifs_fs_sb.h |    1 +
 fs/cifs/cifsfs.c     |   71 +++++++++++++++++++++++++++++++++++++++++++++----
 fs/cifs/connect.c    |    5 +++
 fs/cifs/file.c       |   42 +++++++++++++++++++++--------
 5 files changed, 106 insertions(+), 18 deletions(-)
Signature · 1 line
1.7.3.2

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

#2 lore raw

PATCH 1/6 CIFS: Make cifsFileInfo_put work with strict cache mode (try #4)

On strict cache mode when we close the last file handle of the inode we should set invalid_mapping flag on this inode 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       |    8 ++++++++
 2 files changed, 9 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 +8 -0
index b857ce5..f853bf0 100644
@@ -264,6 +264,7 @@ 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;
 
 	spin_lock(&cifs_file_list_lock);
@@ -279,6 +280,13 @@ 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);
+
+		/* in strict cache mode we need invalidate mapping on the last
+		   close  because it may cause a error when we open this file
+		   again and get at least level II oplock */
+		if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO)
+			CIFS_I(inode)->invalid_mapping = true;
+
 		cifs_set_oplock_level(cifsi, 0);
 	}
 	spin_unlock(&cifs_file_list_lock);
Signature · 1 line
1.7.3.2

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

Reviewed-by
#4 lore raw

Re: [PATCH 1/6] CIFS: Make cifsFileInfo_put work with strict cache mode (try #4)

Quoted 38 lines · On Sun, 28 Nov 2010 11:12:47 +0300 Pavel Shilovsky…

On strict cache mode when we close the last file handle of the inode we should set invalid_mapping flag on this inode 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       |    8 ++++++++
 2 files changed, 9 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 +1 -0
index b857ce5..f853bf0 100644
@@ -264,6 +264,7 @@ 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;
 
 	spin_lock(&cifs_file_list_lock);
@@ -279,6 +280,13 @@ 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);

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

Quoted 10 lines
fs/cifs/file.c +7 -0
+
+		/* in strict cache mode we need invalidate mapping on the last
+		   close  because it may cause a error when we open this file
+		   again and get at least level II oplock */
+		if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO)
+			CIFS_I(inode)->invalid_mapping = true;
+
 		cifs_set_oplock_level(cifsi, 0);
 	}
 	spin_unlock(&cifs_file_list_lock);

Looks reasonable.

#5 lore raw

PATCH 2/6 CIFS: Make read call work with strict cache mode (try #2)

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 |   31 +++++++++++++++++++++++++++++--
 1 files changed, 29 insertions(+), 2 deletions(-)
fs/cifs/cifsfs.c +29 -2
index 9c37897..bbb5294 100644
@@ -568,6 +568,33 @@ 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 ||
+	    CIFS_I(inode)->clientCanCacheRead)
+		return generic_file_aio_read(iocb, iov, nr_segs, pos);
+
+	/* in strict cache mode we need to read from the server all the time
+	   if we don't have level II oplock because the server can delay mtime
+	   change - so we can't make a decision about inode invalidating.
+	   And we can also fail with pagereading if there are mandatory locks
+	   on pages affected by this read but not on the region from pos to
+	   pos+len-1 */
+	read = cifs_user_read(iocb->ki_filp, iov->iov_base,
+			      iov->iov_len, &pos);
+	iocb->ki_pos = pos;
+
+	return read;
+}
+
 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
 				   unsigned long nr_segs, loff_t pos)
 {
@@ -690,7 +717,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,
@@ -727,7 +754,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.3.2

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

Reviewed-by
#7 lore raw

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

Quoted 26 lines · On Sun, 28 Nov 2010 11:12:48 +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 |   31 +++++++++++++++++++++++++++++--
 1 files changed, 29 insertions(+), 2 deletions(-)
fs/cifs/cifsfs.c +10 -0
index 9c37897..bbb5294 100644
@@ -568,6 +568,33 @@ 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);
+

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

Quoted 10 lines
fs/cifs/cifsfs.c +10 -0
+	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);
+
+	/* in strict cache mode we need to read from the server all the time
+	   if we don't have level II oplock because the server can delay mtime
+	   change - so we can't make a decision about inode invalidating.
+	   And we can also fail with pagereading if there are mandatory locks
+	   on pages affected by this read but not on the region from pos to
+	   pos+len-1 */

^^^^^^^^^^^
Nit: while much of the existing cifs code doesn't, it's best to follow kernel coding style when you're adding code. The above comment doesn't do this however. You may want to have a look at Documentation/CodingStyle in the kernel sources.

Quoted 20 lines
fs/cifs/cifsfs.c +8 -1
+	read = cifs_user_read(iocb->ki_filp, iov->iov_base,
+			      iov->iov_len, &pos);
+	iocb->ki_pos = pos;
+
+	return read;
+}
+
 static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
 				   unsigned long nr_segs, loff_t pos)
 {
@@ -690,7 +717,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,

fs/cifs/cifsfs.c const struct file_operations cifs_file_direct_ops = { · line 760

Quoted 8 lines
fs/cifs/cifsfs.c +1 -1
@@ -727,7 +754,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,

Looks reasonable:

#8 lore raw

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

In reply to a message not in the archive

Your patch arbitrarily shortens the read to the first vector. While short reads for regular files are fine with Posix, it will break a lot of userspace applications.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#10 lore raw

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

2010/11/29 Christoph Hellwig <[email protected]>:

Quoted 5 lines

Your patch arbitrarily shortens the read to the first vector.  While short reads for regular files are fine with Posix, it will break a lot of userspace applications.

cifs_user_read returns the number of bytes we read from the server and it, of course, can be different with requested number. Could you explain carefully what do you mean, please? Where is a problem here?

Signature · 2 lines
Best regards,
Pavel Shilovsky.

A message that is not in the archive (sent off-list or not yet received): AANLkTimcVhP10LSn5+F+AY+ppnrhKmp_VCsjkKf04cQr-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#12 lore raw

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

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

Quoted 11 lines

2010/11/29 Christoph Hellwig <[email protected]>:

Quoted 5 lines

Your patch arbitrarily shortens the read to the first vector.  While short reads for regular files are fine with Posix, it will break a lot of userspace applications.

cifs_user_read returns the number of bytes we read from the server and it, of course, can be different with requested number. Could you explain carefully what do you mean, please? Where is a problem here?

It seems to me that I understand what you meant. Of course, it is a bug to process only one segment while nr_segs can be more than one here. Thanks!

Signature · 2 lines
Best regards,
Pavel Shilovsky.
#13 lore raw

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

In reply to a message not in the archive
Quoted 12 lines · On Mon, 29 Nov 2010 13:41:13 +0300 Pavel Shilovsky…

2010/11/29 Christoph Hellwig <[email protected]>:

Quoted 5 lines

Your patch arbitrarily shortens the read to the first vector.  While short reads for regular files are fine with Posix, it will break a lot of userspace applications.

cifs_user_read returns the number of bytes we read from the server and it, of course, can be different with requested number. Could you explain carefully what do you mean, please? Where is a problem here?

Gah...good catch, Christoph. I'll need to rescind my ack for this patch too.

Pavel, note that the aio_read prototype has a "nr_segs" argument. Your patch ignores that argument in the strictcache case. If someone passes in an array of iovecs, then you're ignoring all but the first.

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

PATCH 3/6 CIFS: Make write call work with strict cache mode (try #2)

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 |   40 ++++++++++++++++++++++++++++++++++++----
 1 files changed, 36 insertions(+), 4 deletions(-)
fs/cifs/cifsfs.c +36 -4
index bbb5294..901c82b 100644
@@ -598,12 +598,44 @@ 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;
+	struct inode *inode;
+	struct cifs_sb_info *cifs_sb;
 	ssize_t written;
 
-	written = generic_file_aio_write(iocb, iov, nr_segs, pos);
-	if (!CIFS_I(inode)->clientCanCacheAll)
-		filemap_fdatawrite(inode->i_mapping);
+	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;
+	}
+
+	/* in strict cache mode we need to write the data to the server exactly
+	   from the pos to pos+len-1 rather than flush all affected pages
+	   because it may cause a error with mandatory locks on these pages but
+	   not on the region from pos to ppos+len-1 */
+	written = cifs_user_write(iocb->ki_filp, iov->iov_base,
+				  iov->iov_len, &pos);
+
+	iocb->ki_pos = pos;
+
+	/* if we were successful - invalidate inode pages the write affected */
+	if (written > 0)
+		invalidate_mapping_pages(inode->i_mapping,
+					      (pos-written) >> PAGE_CACHE_SHIFT,
+					      (pos-1) >> PAGE_CACHE_SHIFT);
+
 	return written;
 }
 
Signature · 1 line
1.7.3.2

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

Reviewed-by
#16 lore raw

Re: [PATCH 3/6] CIFS: Make write call work with strict cache mode (try #2)

Quoted 38 lines · On Sun, 28 Nov 2010 11:12:49 +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 |   40 ++++++++++++++++++++++++++++++++++++----
 1 files changed, 36 insertions(+), 4 deletions(-)
fs/cifs/cifsfs.c +15 -4
index bbb5294..901c82b 100644
@@ -598,12 +598,44 @@ 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;
+	struct inode *inode;
+	struct cifs_sb_info *cifs_sb;
 	ssize_t written;
 
-	written = generic_file_aio_write(iocb, iov, nr_segs, pos);
-	if (!CIFS_I(inode)->clientCanCacheAll)
-		filemap_fdatawrite(inode->i_mapping);
+	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);

fs/cifs/cifsfs.c static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 627

Quoted 10 lines
fs/cifs/cifsfs.c +10 -0
+		if (rc)
+			cFYI(1, "cifs_file_aio_write: %d rc on %p inode",
+			     rc, inode);
+		return written;
+	}
+
+	/* in strict cache mode we need to write the data to the server exactly
+	   from the pos to pos+len-1 rather than flush all affected pages
+	   because it may cause a error with mandatory locks on these pages but
+	   not on the region from pos to ppos+len-1 */

Again, please fix the comment style. Here: ^^^^

Quoted 4 lines
fs/cifs/cifsfs.c +4 -0
+	written = cifs_user_write(iocb->ki_filp, iov->iov_base,
+				  iov->iov_len, &pos);
+
+	iocb->ki_pos = pos;

fs/cifs/cifsfs.c static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 641

Quoted 10 lines
fs/cifs/cifsfs.c +7 -0
+
+	/* if we were successful - invalidate inode pages the write affected */
+	if (written > 0)
+		invalidate_mapping_pages(inode->i_mapping,
+					      (pos-written) >> PAGE_CACHE_SHIFT,
+					      (pos-1) >> PAGE_CACHE_SHIFT);
+
 	return written;
 }
 

May god have mercy on anyone who tries to mix strictcache and mmap.

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

#18 lore raw

Re: [PATCH 3/6] CIFS: Make write call work with strict cache mode (try #2)

Quoted 71 lines · On Sun, 28 Nov 2010 06:36:04 -0500 Jeff Layton…
Quoted 38 lines · On Sun, 28 Nov 2010 11:12:49 +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 |   40 ++++++++++++++++++++++++++++++++++++----
 1 files changed, 36 insertions(+), 4 deletions(-)
fs/cifs/cifsfs.c +15 -4
index bbb5294..901c82b 100644
@@ -598,12 +598,44 @@ 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;
+	struct inode *inode;
+	struct cifs_sb_info *cifs_sb;
 	ssize_t written;
 
-	written = generic_file_aio_write(iocb, iov, nr_segs, pos);
-	if (!CIFS_I(inode)->clientCanCacheAll)
-		filemap_fdatawrite(inode->i_mapping);
+	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);

fs/cifs/cifsfs.c static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 627

Quoted 10 lines
fs/cifs/cifsfs.c +10 -0
+		if (rc)
+			cFYI(1, "cifs_file_aio_write: %d rc on %p inode",
+			     rc, inode);
+		return written;
+	}
+
+	/* in strict cache mode we need to write the data to the server exactly
+	   from the pos to pos+len-1 rather than flush all affected pages
+	   because it may cause a error with mandatory locks on these pages but
+	   not on the region from pos to ppos+len-1 */

Again, please fix the comment style. Here: ^^^^

Quoted 4 lines
fs/cifs/cifsfs.c +4 -0
+	written = cifs_user_write(iocb->ki_filp, iov->iov_base,
+				  iov->iov_len, &pos);
+
+	iocb->ki_pos = pos;

fs/cifs/cifsfs.c static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 641

Quoted 10 lines
fs/cifs/cifsfs.c +7 -0
+
+	/* if we were successful - invalidate inode pages the write affected */
+	if (written > 0)
+		invalidate_mapping_pages(inode->i_mapping,
+					      (pos-written) >> PAGE_CACHE_SHIFT,
+					      (pos-1) >> PAGE_CACHE_SHIFT);
+
 	return written;
 }
 

May god have mercy on anyone who tries to mix strictcache and mmap.

Quoted 1 line

(cc'ing Suresh so he can comment)

Actually...I'm going to withdraw my Reviewed-by tag here for now. This bare invalidate_mapping_pages doesn't deal with fscache.

I think I need to understand what's intended when someone specifies strictcache and fsc before I can ack this. The simple answer would be that they are mutually exclusive, but if that's the case then the patch that adds the mount option needs to deal with that appropriately.

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

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

#20 lore raw

Re: [PATCH 3/6] CIFS: Make write call work with strict cache mode (try #2)

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

Quoted 78 lines
Quoted 71 lines · On Sun, 28 Nov 2010 06:36:04 -0500 Jeff Layton…
Quoted 38 lines · On Sun, 28 Nov 2010 11:12:49 +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 |   40 ++++++++++++++++++++++++++++++++++++----

 1 files changed, 36 insertions(+), 4 deletions(-)
fs/cifs/cifsfs.c +15 -4
index bbb5294..901c82b 100644
@@ -598,12 +598,44 @@ 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;
+   struct inode *inode;
+   struct cifs_sb_info *cifs_sb;
     ssize_t written;
 
-   written = generic_file_aio_write(iocb, iov, nr_segs, pos);
-   if (!CIFS_I(inode)->clientCanCacheAll)
-           filemap_fdatawrite(inode->i_mapping);
+   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);

fs/cifs/cifsfs.c static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 627

Quoted 10 lines
fs/cifs/cifsfs.c +10 -0
+           if (rc)
+                   cFYI(1, "cifs_file_aio_write: %d rc on %p inode",
+                        rc, inode);
+           return written;
+   }
+
+   /* in strict cache mode we need to write the data to the server exactly
+      from the pos to pos+len-1 rather than flush all affected pages
+      because it may cause a error with mandatory locks on these pages but
+      not on the region from pos to ppos+len-1 */

      Again, please fix the comment style. Here: ^^^^

Quoted 4 lines
fs/cifs/cifsfs.c +4 -0
+   written = cifs_user_write(iocb->ki_filp, iov->iov_base,
+                             iov->iov_len, &pos);
+
+   iocb->ki_pos = pos;

fs/cifs/cifsfs.c static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 641

Quoted 10 lines
fs/cifs/cifsfs.c +7 -0
+
+   /* if we were successful - invalidate inode pages the write affected */
+   if (written > 0)
+           invalidate_mapping_pages(inode->i_mapping,
+                                         (pos-written) >> PAGE_CACHE_SHIFT,
+                                         (pos-1) >> PAGE_CACHE_SHIFT);
+
     return written;
  }
 

May god have mercy on anyone who tries to mix strictcache and mmap.

Quoted 1 line

(cc'ing Suresh so he can comment)

Quoted 7 lines

Actually...I'm going to withdraw my Reviewed-by tag here for now. This bare invalidate_mapping_pages doesn't deal with fscache.

I think I need to understand what's intended when someone specifies strictcache and fsc before I can ack this. The simple answer would be that they are mutually exclusive, but if that's the case then the patch that adds the mount option needs to deal with that appropriately.

I don't think they can live together. I think we should do smth like a following in mount options parsing:

...
if (opt == fscache) {
vol->fscahe = 1;
vol->strictcache = 0;
}
...
if (opt == strictcache) {
vol->strictcache = 1;
vol->fscache = 0;
}

So, if user specify both only the last will affect the client behavior. Also we should add this information into cifs manpage. Thoughts?

Signature · 2 lines
Best regards,
Pavel Shilovsky.

A message that is not in the archive (sent off-list or not yet received): AANLkTimO9t_wXPZRWXx856-wkG-EwRWTizrCKSo4e2SY-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#22 lore raw

Re: [PATCH 3/6] CIFS: Make write call work with strict cache mode (try #2)

Quoted 102 lines · On Mon, 29 Nov 2010 13:58:05 +0300 Pavel Shilovsky…

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

Quoted 78 lines
Quoted 71 lines · On Sun, 28 Nov 2010 06:36:04 -0500 Jeff Layton…
Quoted 38 lines · On Sun, 28 Nov 2010 11:12:49 +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 |   40 ++++++++++++++++++++++++++++++++++++----

 1 files changed, 36 insertions(+), 4 deletions(-)
fs/cifs/cifsfs.c +15 -4
index bbb5294..901c82b 100644
@@ -598,12 +598,44 @@ 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;
+   struct inode *inode;
+   struct cifs_sb_info *cifs_sb;
     ssize_t written;
 
-   written = generic_file_aio_write(iocb, iov, nr_segs, pos);
-   if (!CIFS_I(inode)->clientCanCacheAll)
-           filemap_fdatawrite(inode->i_mapping);
+   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);

fs/cifs/cifsfs.c static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 627

Quoted 10 lines
fs/cifs/cifsfs.c +10 -0
+           if (rc)
+                   cFYI(1, "cifs_file_aio_write: %d rc on %p inode",
+                        rc, inode);
+           return written;
+   }
+
+   /* in strict cache mode we need to write the data to the server exactly
+      from the pos to pos+len-1 rather than flush all affected pages
+      because it may cause a error with mandatory locks on these pages but
+      not on the region from pos to ppos+len-1 */

      Again, please fix the comment style. Here: ^^^^

Quoted 4 lines
fs/cifs/cifsfs.c +4 -0
+   written = cifs_user_write(iocb->ki_filp, iov->iov_base,
+                             iov->iov_len, &pos);
+
+   iocb->ki_pos = pos;

fs/cifs/cifsfs.c static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 641

Quoted 10 lines
fs/cifs/cifsfs.c +7 -0
+
+   /* if we were successful - invalidate inode pages the write affected */
+   if (written > 0)
+           invalidate_mapping_pages(inode->i_mapping,
+                                         (pos-written) >> PAGE_CACHE_SHIFT,
+                                         (pos-1) >> PAGE_CACHE_SHIFT);
+
     return written;
  }
 

May god have mercy on anyone who tries to mix strictcache and mmap.

Quoted 1 line

(cc'ing Suresh so he can comment)

Quoted 7 lines

Actually...I'm going to withdraw my Reviewed-by tag here for now. This bare invalidate_mapping_pages doesn't deal with fscache.

I think I need to understand what's intended when someone specifies strictcache and fsc before I can ack this. The simple answer would be that they are mutually exclusive, but if that's the case then the patch that adds the mount option needs to deal with that appropriately.

I don't think they can live together. I think we should do smth like a following in mount options parsing:

...

if (opt == fscache) {
   vol->fscahe = 1;
   vol->strictcache = 0;
}

...
if (opt == strictcache) {
vol->strictcache = 1;
vol->fscache = 0;
}

Quoted 4 lines

So, if user specify both only the last will affect the client behavior. Also we should add this information into cifs manpage. Thoughts?

That would one way to deal with it.

On the other hand though...fscache allows you to keep more data cached than you have RAM. This could be useful in a strictcache situation as well. Consider the case of an application on a client that has a lot of large files open for read. The server may grant oplocks on all of them. fscache would allow for fewer round trips to the server in such a case.

So, another way to deal with it would be to simply invalidate the fscache whenever you'd invalidate the in-ram cache. I'm not sure what to do for the cifs_file_aio_write case where you're invalidating just a small range however.

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

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

#24 lore raw

Re: [PATCH 3/6] CIFS: Make write call work with strict cache mode (try #2)

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

Quoted 118 lines
Quoted 102 lines · On Mon, 29 Nov 2010 13:58:05 +0300 Pavel Shilovsky…

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

Quoted 78 lines
Quoted 71 lines · On Sun, 28 Nov 2010 06:36:04 -0500 Jeff Layton…
Quoted 38 lines · On Sun, 28 Nov 2010 11:12:49 +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 |   40 ++++++++++++++++++++++++++++++++++++----

 1 files changed, 36 insertions(+), 4 deletions(-)
fs/cifs/cifsfs.c +15 -4
index bbb5294..901c82b 100644
@@ -598,12 +598,44 @@ 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;
+   struct inode *inode;
+   struct cifs_sb_info *cifs_sb;
     ssize_t written;
 
-   written = generic_file_aio_write(iocb, iov, nr_segs, pos);
-   if (!CIFS_I(inode)->clientCanCacheAll)
-           filemap_fdatawrite(inode->i_mapping);
+   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);

fs/cifs/cifsfs.c static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 627

Quoted 10 lines
fs/cifs/cifsfs.c +10 -0
+           if (rc)
+                   cFYI(1, "cifs_file_aio_write: %d rc on %p inode",
+                        rc, inode);
+           return written;
+   }
+
+   /* in strict cache mode we need to write the data to the server exactly
+      from the pos to pos+len-1 rather than flush all affected pages
+      because it may cause a error with mandatory locks on these pages but
+      not on the region from pos to ppos+len-1 */

      Again, please fix the comment style. Here: ^^^^

Quoted 4 lines
fs/cifs/cifsfs.c +4 -0
+   written = cifs_user_write(iocb->ki_filp, iov->iov_base,
+                             iov->iov_len, &pos);
+
+   iocb->ki_pos = pos;

fs/cifs/cifsfs.c static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 641

Quoted 10 lines
fs/cifs/cifsfs.c +7 -0
+
+   /* if we were successful - invalidate inode pages the write affected */
+   if (written > 0)
+           invalidate_mapping_pages(inode->i_mapping,
+                                         (pos-written) >> PAGE_CACHE_SHIFT,
+                                         (pos-1) >> PAGE_CACHE_SHIFT);
+
     return written;
  }
 

May god have mercy on anyone who tries to mix strictcache and mmap.

Quoted 1 line

(cc'ing Suresh so he can comment)

Quoted 7 lines

Actually...I'm going to withdraw my Reviewed-by tag here for now. This bare invalidate_mapping_pages doesn't deal with fscache.

I think I need to understand what's intended when someone specifies strictcache and fsc before I can ack this. The simple answer would be that they are mutually exclusive, but if that's the case then the patch that adds the mount option needs to deal with that appropriately.

I don't think they can live together. I think we should do smth like a following in mount options parsing:

...
if (opt == fscache) {
   vol->fscahe = 1;
   vol->strictcache = 0;
}
...
if (opt == strictcache) {
  vol->strictcache = 1;
  vol->fscache = 0;
}

Quoted 4 lines

So, if user specify both only the last will affect the client behavior. Also we should add this information into cifs manpage. Thoughts?

That would one way to deal with it.

On the other hand though...fscache allows you to keep more data cached than you have RAM. This could be useful in a strictcache situation as well. Consider the case of an application on a client that has a lot of large files open for read. The server may grant oplocks on all of them. fscache would allow for fewer round trips to the server in such a case.

Quoted 5 lines

So, another way to deal with it would be to simply invalidate the fscache whenever you'd invalidate the in-ram cache. I'm not sure what to do for the cifs_file_aio_write case where you're invalidating just a small range however.

According to the idea that we can't keep read oplock and writing to the server in the same time, I think we can simply call cifs_invalidate_mapping or even set invalidate_mapping flag on inode.

Signature · 2 lines
Best regards,
Pavel Shilovsky.
#25 lore raw

Re: [PATCH 3/6] CIFS: Make write call work with strict cache mode (try #2)

In reply to a message not in the archive
Quoted 118 lines · Jeff Layton
Quoted 102 lines · On Mon, 29 Nov 2010 13:58:05 +0300 Pavel Shilovsky…

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

Quoted 78 lines
Quoted 71 lines · On Sun, 28 Nov 2010 06:36:04 -0500 Jeff Layton…
Quoted 38 lines · On Sun, 28 Nov 2010 11:12:49 +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 | � 40 ++++++++++++++++++++++++++++++++++++---- �1 files changed, 36 insertions(+), 4 deletions(-)

fs/cifs/cifsfs.c +15 -4
index bbb5294..901c82b 100644
@@ -598,12 +598,44 @@ 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;
+ � struct inode *inode;
+ � struct cifs_sb_info *cifs_sb;
 � � ssize_t written;
 
- � written = generic_file_aio_write(iocb, iov, nr_segs, pos);
- � if (!CIFS_I(inode)->clientCanCacheAll)
- � � � � � filemap_fdatawrite(inode->i_mapping);
+ � 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);

fs/cifs/cifsfs.c static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 627

Quoted 10 lines
fs/cifs/cifsfs.c +10 -0
+ � � � � � if (rc)
+ � � � � � � � � � cFYI(1, "cifs_file_aio_write: %d rc on %p inode",
+ � � � � � � � � � � � �rc, inode);
+ � � � � � return written;
+ � }
+
+ � /* in strict cache mode we need to write the data to the server exactly
+ � � �from the pos to pos+len-1 rather than flush all affected pages
+ � � �because it may cause a error with mandatory locks on these pages but
+ � � �not on the region from pos to ppos+len-1 */

� � � Again, please fix the comment style. Here: ^^^^

Quoted 4 lines
fs/cifs/cifsfs.c +4 -0
+ � written = cifs_user_write(iocb->ki_filp, iov->iov_base,
+ � � � � � � � � � � � � � � iov->iov_len, &pos);
+
+ � iocb->ki_pos = pos;

fs/cifs/cifsfs.c static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 641

Quoted 10 lines
fs/cifs/cifsfs.c +7 -0
+
+ � /* if we were successful - invalidate inode pages the write affected */
+ � if (written > 0)
+ � � � � � invalidate_mapping_pages(inode->i_mapping,
+ � � � � � � � � � � � � � � � � � � � � (pos-written) >> PAGE_CACHE_SHIFT,
+ � � � � � � � � � � � � � � � � � � � � (pos-1) >> PAGE_CACHE_SHIFT);
+
 � � return written;
 �}
 

May god have mercy on anyone who tries to mix strictcache and mmap.

Quoted 1 line

(cc'ing Suresh so he can comment)

Quoted 7 lines

Actually...I'm going to withdraw my Reviewed-by tag here for now. This bare invalidate_mapping_pages doesn't deal with fscache.

I think I need to understand what's intended when someone specifies strictcache and fsc before I can ack this. The simple answer would be that they are mutually exclusive, but if that's the case then the patch that adds the mount option needs to deal with that appropriately.

I don't think they can live together. I think we should do smth like a following in mount options parsing:

...

if (opt == fscache) {
   vol->fscahe = 1;
   vol->strictcache = 0;
}

...
if (opt == strictcache) {
vol->strictcache = 1;
vol->fscache = 0;
}

Quoted 4 lines

So, if user specify both only the last will affect the client behavior. Also we should add this information into cifs manpage. Thoughts?

That would one way to deal with it.

On the other hand though...fscache allows you to keep more data cached than you have RAM. This could be useful in a strictcache situation as well. Consider the case of an application on a client that has a lot of large files open for read. The server may grant oplocks on all of them. fscache would allow for fewer round trips to the server in such a case.

Quoted 5 lines

So, another way to deal with it would be to simply invalidate the fscache whenever you'd invalidate the in-ram cache. I'm not sure what to do for the cifs_file_aio_write case where you're invalidating just a small range however.

Yes, we seem to have those two options while the later has the advantage that Jeff mentioned. I think we could do the later without much of a problme. We just need to retire the cookies and get new ones (relinquishing with retire set to 1) i.e. by calling cifs_fscache_reset_inode_cookie(). FS-Cache does not provide data invalidation by itself. For the cifs_file_aio_write case too we could set invalid_mapping and get fresh cookies.

Thanks,

Signature · 1 line
Suresh Jayaraman

A message that is not in the archive (sent off-list or not yet received): [email protected]

#27 lore raw

Re: [PATCH 3/6] CIFS: Make write call work with strict cache mode (try #2)

2010/11/29 Suresh Jayaraman <[email protected]>:

Quoted 125 lines · Jeff Layton
Quoted 118 lines
Quoted 102 lines · On Mon, 29 Nov 2010 13:58:05 +0300 Pavel Shilovsky…

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

Quoted 78 lines
Quoted 71 lines · On Sun, 28 Nov 2010 06:36:04 -0500 Jeff Layton…
Quoted 38 lines · On Sun, 28 Nov 2010 11:12:49 +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 | � 40 ++++++++++++++++++++++++++++++++++++---- �1 files changed, 36 insertions(+), 4 deletions(-)

fs/cifs/cifsfs.c +15 -4
index bbb5294..901c82b 100644
@@ -598,12 +598,44 @@ 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;
+ � struct inode *inode;
+ � struct cifs_sb_info *cifs_sb;
 � � ssize_t written;
 
- � written = generic_file_aio_write(iocb, iov, nr_segs, pos);
- � if (!CIFS_I(inode)->clientCanCacheAll)
- � � � � � filemap_fdatawrite(inode->i_mapping);
+ � 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);

fs/cifs/cifsfs.c static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 627

Quoted 10 lines
fs/cifs/cifsfs.c +10 -0
+ � � � � � if (rc)
+ � � � � � � � � � cFYI(1, "cifs_file_aio_write: %d rc on %p inode",
+ � � � � � � � � � � � �rc, inode);
+ � � � � � return written;
+ � }
+
+ � /* in strict cache mode we need to write the data to the server exactly
+ � � �from the pos to pos+len-1 rather than flush all affected pages
+ � � �because it may cause a error with mandatory locks on these pages but
+ � � �not on the region from pos to ppos+len-1 */

� � � Again, please fix the comment style. Here: ^^^^

Quoted 4 lines
fs/cifs/cifsfs.c +4 -0
+ � written = cifs_user_write(iocb->ki_filp, iov->iov_base,
+ � � � � � � � � � � � � � � iov->iov_len, &pos);
+
+ � iocb->ki_pos = pos;

fs/cifs/cifsfs.c static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 641

Quoted 10 lines
fs/cifs/cifsfs.c +7 -0
+
+ � /* if we were successful - invalidate inode pages the write affected */
+ � if (written > 0)
+ � � � � � invalidate_mapping_pages(inode->i_mapping,
+ � � � � � � � � � � � � � � � � � � � � (pos-written) >> PAGE_CACHE_SHIFT,
+ � � � � � � � � � � � � � � � � � � � � (pos-1) >> PAGE_CACHE_SHIFT);
+
 � � return written;
 �}
 

May god have mercy on anyone who tries to mix strictcache and mmap.

Quoted 1 line

(cc'ing Suresh so he can comment)

Quoted 7 lines

Actually...I'm going to withdraw my Reviewed-by tag here for now. This bare invalidate_mapping_pages doesn't deal with fscache.

I think I need to understand what's intended when someone specifies strictcache and fsc before I can ack this. The simple answer would be that they are mutually exclusive, but if that's the case then the patch that adds the mount option needs to deal with that appropriately.

I don't think they can live together. I think we should do smth like a following in mount options parsing:

...
if (opt == fscache) {
   vol->fscahe = 1;
   vol->strictcache = 0;
}
...
if (opt == strictcache) {
  vol->strictcache = 1;
  vol->fscache = 0;
}

Quoted 4 lines

So, if user specify both only the last will affect the client behavior. Also we should add this information into cifs manpage. Thoughts?

That would one way to deal with it.

On the other hand though...fscache allows you to keep more data cached than you have RAM. This could be useful in a strictcache situation as well. Consider the case of an application on a client that has a lot of large files open for read. The server may grant oplocks on all of them. fscache would allow for fewer round trips to the server in such a case.

Quoted 5 lines

So, another way to deal with it would be to simply invalidate the fscache whenever you'd invalidate the in-ram cache. I'm not sure what to do for the cifs_file_aio_write case where you're invalidating just a small range however.

Quoted 8 lines

Yes, we seem to have those two options while the later has the advantage that Jeff mentioned. I think we could do the later without much of a problme. We just need to retire the cookies and get new ones (relinquishing with retire set to 1) i.e. by calling cifs_fscache_reset_inode_cookie(). FS-Cache does not provide data invalidation by itself. For the cifs_file_aio_write case too we could set invalid_mapping and get fresh cookies.

Ok, I am going to provide these changes.

Signature · 2 lines
Best regards,
Pavel Shilovsky.
#28 lore raw

Re: [PATCH 3/6] CIFS: Make write call work with strict cache mode (try #2)

In reply to a message not in the archive

2010/11/29 Suresh Jayaraman <[email protected]>:

Quoted 125 lines · Jeff Layton
Quoted 118 lines
Quoted 102 lines · On Mon, 29 Nov 2010 13:58:05 +0300 Pavel Shilovsky…

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

Quoted 78 lines
Quoted 71 lines · On Sun, 28 Nov 2010 06:36:04 -0500 Jeff Layton…
Quoted 38 lines · On Sun, 28 Nov 2010 11:12:49 +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 | � 40 ++++++++++++++++++++++++++++++++++++---- �1 files changed, 36 insertions(+), 4 deletions(-)

fs/cifs/cifsfs.c +15 -4
index bbb5294..901c82b 100644
@@ -598,12 +598,44 @@ 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;
+ � struct inode *inode;
+ � struct cifs_sb_info *cifs_sb;
 � � ssize_t written;
 
- � written = generic_file_aio_write(iocb, iov, nr_segs, pos);
- � if (!CIFS_I(inode)->clientCanCacheAll)
- � � � � � filemap_fdatawrite(inode->i_mapping);
+ � 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);

fs/cifs/cifsfs.c static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 627

Quoted 10 lines
fs/cifs/cifsfs.c +10 -0
+ � � � � � if (rc)
+ � � � � � � � � � cFYI(1, "cifs_file_aio_write: %d rc on %p inode",
+ � � � � � � � � � � � �rc, inode);
+ � � � � � return written;
+ � }
+
+ � /* in strict cache mode we need to write the data to the server exactly
+ � � �from the pos to pos+len-1 rather than flush all affected pages
+ � � �because it may cause a error with mandatory locks on these pages but
+ � � �not on the region from pos to ppos+len-1 */

� � � Again, please fix the comment style. Here: ^^^^

Quoted 4 lines
fs/cifs/cifsfs.c +4 -0
+ � written = cifs_user_write(iocb->ki_filp, iov->iov_base,
+ � � � � � � � � � � � � � � iov->iov_len, &pos);
+
+ � iocb->ki_pos = pos;

fs/cifs/cifsfs.c static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 641

Quoted 10 lines
fs/cifs/cifsfs.c +7 -0
+
+ � /* if we were successful - invalidate inode pages the write affected */
+ � if (written > 0)
+ � � � � � invalidate_mapping_pages(inode->i_mapping,
+ � � � � � � � � � � � � � � � � � � � � (pos-written) >> PAGE_CACHE_SHIFT,
+ � � � � � � � � � � � � � � � � � � � � (pos-1) >> PAGE_CACHE_SHIFT);
+
 � � return written;
 �}
 

May god have mercy on anyone who tries to mix strictcache and mmap.

Quoted 1 line

(cc'ing Suresh so he can comment)

Quoted 7 lines

Actually...I'm going to withdraw my Reviewed-by tag here for now. This bare invalidate_mapping_pages doesn't deal with fscache.

I think I need to understand what's intended when someone specifies strictcache and fsc before I can ack this. The simple answer would be that they are mutually exclusive, but if that's the case then the patch that adds the mount option needs to deal with that appropriately.

I don't think they can live together. I think we should do smth like a following in mount options parsing:

...
if (opt == fscache) {
   vol->fscahe = 1;
   vol->strictcache = 0;
}
...
if (opt == strictcache) {
  vol->strictcache = 1;
  vol->fscache = 0;
}

Quoted 4 lines

So, if user specify both only the last will affect the client behavior. Also we should add this information into cifs manpage. Thoughts?

That would one way to deal with it.

On the other hand though...fscache allows you to keep more data cached than you have RAM. This could be useful in a strictcache situation as well. Consider the case of an application on a client that has a lot of large files open for read. The server may grant oplocks on all of them. fscache would allow for fewer round trips to the server in such a case.

Quoted 5 lines

So, another way to deal with it would be to simply invalidate the fscache whenever you'd invalidate the in-ram cache. I'm not sure what to do for the cifs_file_aio_write case where you're invalidating just a small range however.

Quoted 9 lines

Yes, we seem to have those two options while the later has the advantage that Jeff mentioned. I think we could do the later without much of a problme. We just need to retire the cookies and get new ones (relinquishing with retire set to 1) i.e. by calling cifs_fscache_reset_inode_cookie(). FS-Cache does not provide data invalidation by itself. For the cifs_file_aio_write case too we could set invalid_mapping and get fresh cookies.

What's about mmap and fsync patch? How do you think they mix with fscache?

Signature · 2 lines
Best regards,
Pavel Shilovsky.

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

#30 lore raw

Re: [PATCH 3/6] CIFS: Make write call work with strict cache mode (try #2)

Quoted 136 lines · Pavel Shilovsky

2010/11/29 Suresh Jayaraman <[email protected]>:

Quoted 125 lines · Jeff Layton
Quoted 118 lines
Quoted 102 lines · On Mon, 29 Nov 2010 13:58:05 +0300 Pavel Shilovsky…

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

Quoted 78 lines
Quoted 71 lines · On Sun, 28 Nov 2010 06:36:04 -0500 Jeff Layton…
Quoted 38 lines · On Sun, 28 Nov 2010 11:12:49 +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 | � 40 ++++++++++++++++++++++++++++++++++++---- �1 files changed, 36 insertions(+), 4 deletions(-)

fs/cifs/cifsfs.c +15 -4
index bbb5294..901c82b 100644
@@ -598,12 +598,44 @@ 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;
+ � struct inode *inode;
+ � struct cifs_sb_info *cifs_sb;
 � � ssize_t written;
 
- � written = generic_file_aio_write(iocb, iov, nr_segs, pos);
- � if (!CIFS_I(inode)->clientCanCacheAll)
- � � � � � filemap_fdatawrite(inode->i_mapping);
+ � 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);

fs/cifs/cifsfs.c static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 627

Quoted 10 lines
fs/cifs/cifsfs.c +10 -0
+ � � � � � if (rc)
+ � � � � � � � � � cFYI(1, "cifs_file_aio_write: %d rc on %p inode",
+ � � � � � � � � � � � �rc, inode);
+ � � � � � return written;
+ � }
+
+ � /* in strict cache mode we need to write the data to the server exactly
+ � � �from the pos to pos+len-1 rather than flush all affected pages
+ � � �because it may cause a error with mandatory locks on these pages but
+ � � �not on the region from pos to ppos+len-1 */

� � � Again, please fix the comment style. Here: ^^^^

Quoted 4 lines
fs/cifs/cifsfs.c +4 -0
+ � written = cifs_user_write(iocb->ki_filp, iov->iov_base,
+ � � � � � � � � � � � � � � iov->iov_len, &pos);
+
+ � iocb->ki_pos = pos;

fs/cifs/cifsfs.c static ssize_t cifs_file_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 641

Quoted 10 lines
fs/cifs/cifsfs.c +7 -0
+
+ � /* if we were successful - invalidate inode pages the write affected */
+ � if (written > 0)
+ � � � � � invalidate_mapping_pages(inode->i_mapping,
+ � � � � � � � � � � � � � � � � � � � � (pos-written) >> PAGE_CACHE_SHIFT,
+ � � � � � � � � � � � � � � � � � � � � (pos-1) >> PAGE_CACHE_SHIFT);
+
 � � return written;
 �}
 

May god have mercy on anyone who tries to mix strictcache and mmap.

Quoted 1 line

(cc'ing Suresh so he can comment)

Quoted 7 lines

Actually...I'm going to withdraw my Reviewed-by tag here for now. This bare invalidate_mapping_pages doesn't deal with fscache.

I think I need to understand what's intended when someone specifies strictcache and fsc before I can ack this. The simple answer would be that they are mutually exclusive, but if that's the case then the patch that adds the mount option needs to deal with that appropriately.

I don't think they can live together. I think we should do smth like a following in mount options parsing:

...

if (opt == fscache) {
   vol->fscahe = 1;
   vol->strictcache = 0;
}

...
if (opt == strictcache) {
vol->strictcache = 1;
vol->fscache = 0;
}

Quoted 4 lines

So, if user specify both only the last will affect the client behavior. Also we should add this information into cifs manpage. Thoughts?

That would one way to deal with it.

On the other hand though...fscache allows you to keep more data cached than you have RAM. This could be useful in a strictcache situation as well. Consider the case of an application on a client that has a lot of large files open for read. The server may grant oplocks on all of them. fscache would allow for fewer round trips to the server in such a case.

Quoted 5 lines

So, another way to deal with it would be to simply invalidate the fscache whenever you'd invalidate the in-ram cache. I'm not sure what to do for the cifs_file_aio_write case where you're invalidating just a small range however.

Quoted 9 lines

Yes, we seem to have those two options while the later has the advantage that Jeff mentioned. I think we could do the later without much of a problme. We just need to retire the cookies and get new ones (relinquishing with retire set to 1) i.e. by calling cifs_fscache_reset_inode_cookie(). FS-Cache does not provide data invalidation by itself. For the cifs_file_aio_write case too we could set invalid_mapping and get fresh cookies.

Quoted 2 lines

What's about mmap and fsync patch? How do you think they mix with fscache?

Basically, relinquishing cookie when you are invalidating inode should make them work without issues I think. But, I would also test your patches (once you post the patchset that includes fscache handling as well) to be sure.

Thanks,

Signature · 1 line
Suresh Jayaraman

A message that is not in the archive (sent off-list or not yet received): [email protected]

#32 lore raw

Re: [PATCH 3/6] CIFS: Make write call work with strict cache mode (try #2)

2010/11/29 Suresh Jayaraman <[email protected]>:

Quoted 11 lines · Pavel Shilovsky
Quoted 3 lines

What's about mmap and fsync patch? How do you think they mix with fscache?

Basically, relinquishing cookie when you are invalidating inode should make them work without issues I think. But, I would also test your patches (once you post the patchset that includes fscache handling as well) to be sure.

I reposted patches from 2 to 5(included). So, uptodate set is

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

please, let me know about results when you finished testing them.

Signature · 2 lines
Best regards,
Pavel Shilovsky.

A message that is not in the archive (sent off-list or not yet received): AANLkTikB6_nwg+G+pYv9NNeohHPwymjUkv3r-mJkZBxW-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#34 lore raw

Re: [PATCH 3/6] CIFS: Make write call work with strict cache mode (try #2)

Quoted 15 lines · Pavel Shilovsky

2010/11/29 Suresh Jayaraman <[email protected]>:

Quoted 11 lines · Pavel Shilovsky
Quoted 3 lines

What's about mmap and fsync patch? How do you think they mix with fscache?

Basically, relinquishing cookie when you are invalidating inode should make them work without issues I think. But, I would also test your patches (once you post the patchset that includes fscache handling as well) to be sure.

I reposted patches from 2 to 5(included). So, uptodate set is

Quoted 8 lines

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

I just applied your patches on my test box, but I see that the fscache integration is not done, yet. Am I seeing older version of patches?

Signature · 1 line
Suresh Jayaraman

A message that is not in the archive (sent off-list or not yet received): [email protected]

#36 lore raw

Re: [PATCH 3/6] CIFS: Make write call work with strict cache mode (try #2)

2010/12/1 Suresh Jayaraman <[email protected]>:

Quoted 3 lines

I just applied your patches on my test box, but I see that the fscache integration is not done, yet. Am I seeing older version of patches?

What do you mean for "fscache integration"? I changed all invalidate_inode_* calls to cifs_invalidate_mapping or setting invalid_mapping flag - so, it seems to me that I don't miss places where I affect cache but don't aware of fscache (cifs_invalidate_mapping process fscache as well). Of course, it can be - so, could you point me to such places, please?

Signature · 2 lines
Best regards,
Pavel Shilovsky.

A message that is not in the archive (sent off-list or not yet received): AANLkTik1AC5YJV_CtihSobE1mgj1-7tuiBLf7_nDsiv2-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#38 lore raw

Re: [PATCH 3/6] CIFS: Make write call work with strict cache mode (try #2)

Quoted 5 lines · Pavel Shilovsky

2010/12/1 Suresh Jayaraman <[email protected]>:

Quoted 3 lines

I just applied your patches on my test box, but I see that the fscache integration is not done, yet. Am I seeing older version of patches?

Quoted 7 lines

What do you mean for "fscache integration"? I changed all invalidate_inode_* calls to cifs_invalidate_mapping or setting invalid_mapping flag - so, it seems to me that I don't miss places where I affect cache but don't aware of fscache (cifs_invalidate_mapping process fscache as well). Of course, it can be - so, could you point me to such places, please?

Sorry about the delay in getting back. You're right the patches are taking care of relinquishing the cookies wherever appropriate. I have done some testing with both 'strictcache' and 'fsc' enabled and so far they work as expected. The tests involve doing file operations with fsc enabled always but strict cache enabled/disabled and watching fscache statistics via /proc/fs/fscache/stats). I didn't encounter any unexpected results.

Thanks,

Signature · 1 line
Suresh Jayaraman

A message that is not in the archive (sent off-list or not yet received): [email protected]

#40 lore raw

Re: [PATCH 3/6] CIFS: Make write call work with strict cache mode (try #2)

2010/12/6 Suresh Jayaraman <[email protected]>:

Quoted 14 lines · Pavel Shilovsky
Quoted 5 lines

2010/12/1 Suresh Jayaraman <[email protected]>:

Quoted 3 lines

I just applied your patches on my test box, but I see that the fscache integration is not done, yet. Am I seeing older version of patches?

Quoted 7 lines

What do you mean for "fscache integration"? I changed all invalidate_inode_* calls to cifs_invalidate_mapping or setting invalid_mapping flag - so, it seems to me that I don't miss places where I affect cache but don't aware of fscache (cifs_invalidate_mapping process fscache as well). Of course, it can be - so, could you point me to such places, please?

Quoted 7 lines

Sorry about the delay in getting back. You're right the patches are taking care of relinquishing the cookies wherever appropriate. I have done some testing with both 'strictcache' and 'fsc' enabled and so far they work as expected. The tests involve doing file operations with fsc enabled always but strict cache enabled/disabled and watching fscache statistics via /proc/fs/fscache/stats). I didn't encounter any unexpected results.

Thank you very much for this testing!

Jeff, Suresh, as we have the good results on strict cache + fscache and reviewed patch number 1 (cifsFileInfo_put part), could you review other patches: 2) read (try #4), 3) write (try #4), 4) fsync (try #3),
5) mmap (try #3) and 6) mount option (try #2) please?

Signature · 2 lines
Best regards,
Pavel Shilovsky.
#41 lore raw

PATCH 4/6 CIFS: Make cifs_fsync work with strict cache mode (try #2)

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 f853bf0..22d0421 100644
@@ -1595,20 +1595,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))
+		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.3.2

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

Reviewed-by
#43 lore raw

Re: [PATCH 4/6] CIFS: Make cifs_fsync work with strict cache mode (try #2)

Quoted 4 lines · On Sun, 28 Nov 2010 11:12:50 +0300 Pavel Shilovsky…

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.

I think you mean vfs_fsync_range?

Quoted 27 lines
---
 fs/cifs/file.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
fs/cifs/file.c +4 -3
index f853bf0..22d0421 100644
@@ -1595,20 +1595,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))
+		invalidate_remote_inode(inode);
 

fs/cifs/file.c int cifs_fsync(struct file *file, int datasync) · line 1614

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

Looks reasonable. I like the fact that we're pulling out the unnecessary filemap_write_and_wait here.

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

#45 lore raw

Re: [PATCH 4/6] CIFS: Make cifs_fsync work with strict cache mode (try #2)

Quoted 45 lines · On Sun, 28 Nov 2010 06:42:19 -0500 Jeff Layton…
Quoted 4 lines · On Sun, 28 Nov 2010 11:12:50 +0300 Pavel Shilovsky…

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.

I think you mean vfs_fsync_range?

Quoted 35 lines
---
 fs/cifs/file.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
fs/cifs/file.c +7 -7
index f853bf0..22d0421 100644
@@ -1595,20 +1595,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))
+		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);
 
Quoted 8 lines

fs/cifs/file.c int cifs_fsync(struct file *file, int datasync) · line 1614

Quoted 2 lines
fs/cifs/file.c +0 -0
 	FreeXid(xid);
 	return rc;

Looks reasonable. I like the fact that we're pulling out the unnecessary filemap_write_and_wait here.

Actually...I must withdraw this Reviewed-by until I understand how this is expected to mesh with fscache.

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

PATCH 5/6 CIFS: Make cifs_file_map work with strict cache mode (try #2)

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 22d0421..d9dcc98 100644
@@ -1812,14 +1812,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))
+		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.3.2
#47 lore raw

PATCH 6/6 CIFS: Add strictcache mount option (try #2)

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.3.2
#48 lore raw
In reply to a message not in the archive
Quoted 1 line · Pavel Shilovsky

Re-posting the whole set of strict cache patches.

I try to explain here the "strict cache" semantics as I'm not sure whether I understand it clearly. Please correct me if I'm wrong.

Strict cache semantics

o provides stricter cache coherency among cifs clients that access the same files.
o The clients will read data from the Server always, except when they hold read oplock or Level II oplock on the file.
o The clients will write data to the Server always, except when they hold exclusive oplock on the file.
o When we close the last filehandle of the inode, file should be marked for revalidation as it is possible for the client to access stale data from the cache when we open it again with a read oplock.
o On fsync/mmap, invalidate inode if read oplock has not been set.

Is this the semantics being proposed? Did I miss anything?

Thanks,

Quoted 15 lines

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

 fs/cifs/README       |    5 +++
 fs/cifs/cifs_fs_sb.h |    1 +
 fs/cifs/cifsfs.c     |   71 +++++++++++++++++++++++++++++++++++++++++++++----
 fs/cifs/connect.c    |    5 +++
 fs/cifs/file.c       |   42 +++++++++++++++++++++--------
 5 files changed, 106 insertions(+), 18 deletions(-)
Signature · 1 line
Suresh Jayaraman

A message that is not in the archive (sent off-list or not yet received): [email protected]

#50 lore raw

2010/11/29 Suresh Jayaraman <[email protected]>:

Quoted 21 lines · Pavel Shilovsky
Quoted 1 line

Re-posting the whole set of strict cache patches.

I try to explain here the "strict cache" semantics as I'm not sure whether I understand it clearly. Please correct me if I'm wrong.

Strict cache semantics

 o provides stricter cache coherency among cifs clients that access the same files.
 o The clients will read data from the Server always, except when they hold read oplock or Level II oplock on the file.
 o The clients will write data to the Server always, except when they hold exclusive oplock on the file.
 o When we close the last filehandle of the inode, file should be marked for revalidation as it is possible for the client to access stale data from the cache when we open it again with a read oplock.
 o On fsync/mmap, invalidate inode if read oplock has not been set.

Quoted 1 line

Is this the semantics being proposed? Did I miss anything?

Yes, you are right - it is exactly what I mean.

Signature · 2 lines
Best regards,
Pavel Shilovsky.

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

#52 lore raw
Quoted 22 lines · Pavel Shilovsky

2010/11/29 Suresh Jayaraman <[email protected]>:

Quoted 21 lines · Pavel Shilovsky
Quoted 1 line

Re-posting the whole set of strict cache patches.

I try to explain here the "strict cache" semantics as I'm not sure whether I understand it clearly. Please correct me if I'm wrong.

Strict cache semantics

�o provides stricter cache coherency among cifs clients that access � �the same files.
�o The clients will read data from the Server always, except when they � �hold read oplock or Level II oplock on the file.
�o The clients will write data to the Server always, except when they � �hold exclusive oplock on the file.
�o When we close the last filehandle of the inode, file should be � �marked for revalidation as it is possible for the client to access � �stale data from the cache when we open it again with a read � �oplock.
�o On fsync/mmap, invalidate inode if read oplock has not been set.

Quoted 4 lines
Quoted 1 line

Is this the semantics being proposed? Did I miss anything?

Yes, you are right - it is exactly what I mean.

Also, would be good to know what level of testing these patches have undergone. Could you share the test results as well?

Thanks,

Signature · 1 line
Suresh Jayaraman

A message that is not in the archive (sent off-list or not yet received): [email protected]

#54 lore raw

2010/11/29 Suresh Jayaraman <[email protected]>:

Quoted 23 lines · Pavel Shilovsky
Quoted 22 lines

2010/11/29 Suresh Jayaraman <[email protected]>:

Quoted 21 lines · Pavel Shilovsky
Quoted 1 line

Re-posting the whole set of strict cache patches.

I try to explain here the "strict cache" semantics as I'm not sure whether I understand it clearly. Please correct me if I'm wrong.

Strict cache semantics

�o provides stricter cache coherency among cifs clients that access � �the same files.
�o The clients will read data from the Server always, except when they � �hold read oplock or Level II oplock on the file.
�o The clients will write data to the Server always, except when they � �hold exclusive oplock on the file.
�o When we close the last filehandle of the inode, file should be � �marked for revalidation as it is possible for the client to access � �stale data from the cache when we open it again with a read � �oplock.
�o On fsync/mmap, invalidate inode if read oplock has not been set.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Is this the semantics being proposed? Did I miss anything?

Yes, you are right - it is exactly what I mean.

Also, would be good to know what level of testing these patches have undergone. Could you share the test results as well?

I don't run big stress tests over it but I have tree small tests that shows the problem this mode is going to fix.

Signature · 2 lines
Best regards,
Pavel Shilovsky.

#!/bin/env python
#
# We have to mount the same share to test, test1, test2 directories that locate in the directory we

# execute this script from.

from os import open, close, O_RDWR, O_CREAT, write, read, O_RDONLY, O_WRONLY, O_TRUNC, lseek, SEEK_END, SEEK_SET

f = open('test/_test4321_', O_RDWR | O_CREAT | O_TRUNC) close(f)

f1 = open('test1/_test4321_', O_RDWR)
write(f1, 'a')
close(f1)

f2 = open('test2/_test4321_', O_WRONLY)
write(f2, 'x')
close(f2)

f3 = open('test1/_test4321_', O_RDONLY)
print 'must be x:', read(f3, 1)

close(f3)

#!/bin/env python
#
# We have to mount the same share to test, test1, test2 directories that locate in the directory we

# execute this script from.

from os import open, close, O_RDWR, O_CREAT, write, read, O_RDONLY, O_WRONLY, O_TRUNC, lseek, SEEK_END, SEEK_SET

f = open('test/_test4321_', O_RDWR | O_CREAT | O_TRUNC) close(f)

f1 = open('test1/_test4321_', O_RDWR)
write(f1, 'a')

f2 = open('test2/_test4321_', O_WRONLY)
write(f2, 'x')

f3 = open('test1/_test4321_', O_RDONLY)
print 'must be x:', read(f3, 1)

close(f1)
close(f2)
close(f3)

#!/bin/env python
#
# We have to mount the same share to test, test1, test2 directories that locate in the directory we

# execute this script from.

from os import open, close, O_RDWR, O_CREAT, write, read, O_RDONLY, O_WRONLY, O_TRUNC, lseek

f = open('test/_test4321_', O_RDWR | O_CREAT | O_TRUNC) write(f, ''.join('a' for _ in range(4096))) close(f)

f1 = open('test1/_test4321_', O_RDWR)
f2 = open('test2/_test4321_', O_RDWR)

write(f1, 'x')
print 'x is written through f1'
print '%c is read from f2' % read(f2, 1)

write(f1, 'y')
print 'y is written through f1'
print '%c is read from f2' % read(f2, 1)

write(f1, 'z')
print 'z is written through f1'
print '%c is read from f2' % read(f2, 1)

close(f1)
close(f2)