Skip to contentSkip to conversation

CIFS: Consolidate error handling for cifs_invalidate_mapping

PATCH In review Pavel Shilovsky 3 participants 9 messages Mar 24, 2011 – Mar 25, 2011 6 messages not in the archive

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

PATCH 1/1 CIFS: Consolidate error handling for cifs_invalidate_mapping

Base of approach for splitting all calls that uses cifs_invalidate_mapping (or cifs_revalidate_dentry, cifs_revalidate_file) into two groups:
1) aware about -EBUSY error code and report it back (cifs_d_revalidate, cifs_strict_fsync, cifs_file_strict_mmap);
2) don't do it (cifs_getattrs, cifs_lseek).

---
 fs/cifs/cifsfs.c |    8 +++++++-
 fs/cifs/cifsfs.h |    2 +-
 fs/cifs/file.c   |   18 ++++++++++++++----
 fs/cifs/inode.c  |   30 ++++++++++++++++++------------
 4 files changed, 40 insertions(+), 18 deletions(-)
fs/cifs/cifsfs.c +7 -1
index de49fbb..b275d76 100644
@@ -634,7 +634,13 @@ static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
 		CIFS_I(file->f_path.dentry->d_inode)->time = 0;
 
 		retval = cifs_revalidate_file(file);
-		if (retval < 0)
+		/*
+		 * We only need to get right file length and don't need to
+		 * aware about busy pages (-EBUSY error code).
+		 */
+		if (retval == -EBUSY)
+			retval = 0;
+		else if (retval < 0)
 			return (loff_t)retval;
 	}
 	return generic_file_llseek_unlocked(file, offset, origin);
fs/cifs/cifsfs.h +1 -1
index bb64313..f4391ff 100644
@@ -61,7 +61,7 @@ extern int cifs_rename(struct inode *, struct dentry *, struct inode *,
 		       struct dentry *);
 extern int cifs_revalidate_file(struct file *filp);
 extern int cifs_revalidate_dentry(struct dentry *);
-extern void cifs_invalidate_mapping(struct inode *inode);
+extern int cifs_invalidate_mapping(struct inode *inode);
 extern int cifs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
 extern int cifs_setattr(struct dentry *, struct iattr *);
 
fs/cifs/file.c +14 -4
index b9731c9..d99cf48 100644
@@ -1448,8 +1448,13 @@ int cifs_strict_fsync(struct file *file, int datasync)
 	cFYI(1, "Sync file - name: %s datasync: 0x%x",
 		file->f_path.dentry->d_name.name, datasync);
 
-	if (!CIFS_I(inode)->clientCanCacheRead)
-		cifs_invalidate_mapping(inode);
+	if (!CIFS_I(inode)->clientCanCacheRead) {
+		rc = cifs_invalidate_mapping(inode);
+		if (rc) {
+			FreeXid(xid);
+			return rc;
+		}
+	}
 
 	tcon = tlink_tcon(smbfile->tlink);
 	if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC))
@@ -1916,8 +1921,13 @@ int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma)
 
 	xid = GetXid();
 
-	if (!CIFS_I(inode)->clientCanCacheRead)
-		cifs_invalidate_mapping(inode);
+	if (!CIFS_I(inode)->clientCanCacheRead) {
+		rc = cifs_invalidate_mapping(inode);
+		if (rc) {
+			FreeXid(xid);
+			return rc;
+		}
+	}
 
 	rc = generic_file_mmap(file, vma);
 	FreeXid(xid);
fs/cifs/inode.c +18 -12
index adb6324..d3abfc5 100644
@@ -1683,27 +1683,25 @@ cifs_inode_needs_reval(struct inode *inode)
 /*
  * Zap the cache. Called when invalid_mapping flag is set.
  */
-void
+int
 cifs_invalidate_mapping(struct inode *inode)
 {
-	int rc;
+	int rc = 0;
 	struct cifsInodeInfo *cifs_i = CIFS_I(inode);
 
-	cifs_i->invalid_mapping = false;
-
 	if (inode->i_mapping && inode->i_mapping->nrpages != 0) {
 		/* write back any cached data */
 		rc = filemap_write_and_wait(inode->i_mapping);
 		mapping_set_error(inode->i_mapping, rc);
 		rc = invalidate_inode_pages2(inode->i_mapping);
-		if (rc) {
-			cERROR(1, "%s: could not invalidate inode %p", __func__,
-			       inode);
-			cifs_i->invalid_mapping = true;
-		}
+		if (rc)
+			cFYI(1, "%s: could not invalidate inode %p", __func__,
+			     inode);
+		cifs_i->invalid_mapping = (rc != 0) ? true : false;
 	}
 
 	cifs_fscache_reset_inode_cookie(inode);
+	return rc;
 }
 
 int cifs_revalidate_file(struct file *filp)
@@ -1722,7 +1720,7 @@ int cifs_revalidate_file(struct file *filp)
 
 check_inval:
 	if (CIFS_I(inode)->invalid_mapping)
-		cifs_invalidate_mapping(inode);
+		rc = cifs_invalidate_mapping(inode);
 
 	return rc;
 }
@@ -1764,7 +1762,7 @@ int cifs_revalidate_dentry(struct dentry *dentry)
 
 check_inval:
 	if (CIFS_I(inode)->invalid_mapping)
-		cifs_invalidate_mapping(inode);
+		rc = cifs_invalidate_mapping(inode);
 
 	kfree(full_path);
 	FreeXid(xid);
@@ -1776,7 +1774,15 @@ int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
 {
 	struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb);
 	struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
-	int err = cifs_revalidate_dentry(dentry);
+	int err;
+
+	err = cifs_revalidate_dentry(dentry);
+	/*
+	 * We only need to get file attributes and don't need to
+	 * aware about busy pages (-EBUSY error code).
+	 */
+	if (err == -EBUSY)
+		err = 0;
 
 	if (!err) {
 		generic_fillattr(dentry->d_inode, stat);
Signature · 1 line
1.7.1
#2 lore raw
In reply to a message not in the archive
Quoted 29 lines · Pavel Shilovsky

Base of approach for splitting all calls that uses cifs_invalidate_mapping (or cifs_revalidate_dentry, cifs_revalidate_file) into two groups:
1) aware about -EBUSY error code and report it back (cifs_d_revalidate, cifs_strict_fsync, cifs_file_strict_mmap);
2) don't do it (cifs_getattrs, cifs_lseek).

fs/cifs/inode.c +2 -4
index adb6324..d3abfc5 100644
@@ -1683,27 +1683,25 @@ cifs_inode_needs_reval(struct inode *inode)
  /*
  * Zap the cache. Called when invalid_mapping flag is set.
  */
-void
+int
  cifs_invalidate_mapping(struct inode *inode)
  {
-       int rc;
+       int rc = 0;
        struct cifsInodeInfo *cifs_i = CIFS_I(inode);
 
-       cifs_i->invalid_mapping = false;
-
        if (inode->i_mapping && inode->i_mapping->nrpages != 0) {
                /* write back any cached data */
                rc = filemap_write_and_wait(inode->i_mapping);
                mapping_set_error(inode->i_mapping, rc);
                rc = invalidate_inode_pages2(inode->i_mapping);

fs/cifs/inode.c cifs_inode_needs_reval(struct inode *inode) · line 1701

Quoted 10 lines
fs/cifs/inode.c +4 -5
-               if (rc) {
-                       cERROR(1, "%s: could not invalidate inode %p", __func__,
-                              inode);
-                       cifs_i->invalid_mapping = true;
-               }
+               if (rc)
+                       cFYI(1, "%s: could not invalidate inode %p", __func__,
+                            inode);
+               cifs_i->invalid_mapping = (rc != 0) ? true : false;
        }

aren't you setting invalid_mapping twice (the first one is redundant)?

Quoted 26 lines
fs/cifs/inode.c +0 -0
  int cifs_revalidate_file(struct file *filp)
@@ -1722,7 +1720,7 @@ int cifs_revalidate_file(struct file *filp)
 

 check_inval:
       if (CIFS_I(inode)->invalid_mapping)
-               cifs_invalidate_mapping(inode);
+               rc = cifs_invalidate_mapping(inode);

       return rc;
 }

fs/cifs/inode.c +0 -0
@@ -1764,7 +1762,7 @@ int cifs_revalidate_dentry(struct dentry *dentry)
 

 check_inval:
       if (CIFS_I(inode)->invalid_mapping)
-               cifs_invalidate_mapping(inode);
+               rc = cifs_invalidate_mapping(inode);

       kfree(full_path);
       FreeXid(xid);

fs/cifs/inode.c +2 -1
@@ -1776,7 +1774,15 @@ int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
  {
        struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb);
        struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
-       int err = cifs_revalidate_dentry(dentry);
+       int err;
+

fs/cifs/inode.c int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry, · line 1788

Quoted 10 lines
fs/cifs/inode.c +7 -0
+       err = cifs_revalidate_dentry(dentry);
+       /*
+        * We only need to get file attributes and don't need to
+        * aware about busy pages (-EBUSY error code).
+        */
+       if (err == -EBUSY)
+               err = 0;
 
        if (!err) {
                generic_fillattr(dentry->d_inode, stat);

With this change couldn't we accidently return a temporary write error (ENOSPC for example or EACCESS) when revalidating a file - which the caller is not expecting (getattr should only return errors if it can't get the attributes)

Signature · 3 lines
Thanks,

Steve
#5 lore raw
In reply to a message not in the archive
Quoted 54 lines · On Thu, 24 Mar 2011 17:39:47 +0300 Pavel Shilovsky…

Base of approach for splitting all calls that uses cifs_invalidate_mapping (or cifs_revalidate_dentry, cifs_revalidate_file) into two groups:
1) aware about -EBUSY error code and report it back (cifs_d_revalidate, cifs_strict_fsync, cifs_file_strict_mmap);
2) don't do it (cifs_getattrs, cifs_lseek).

---
 fs/cifs/cifsfs.c |    8 +++++++-
 fs/cifs/cifsfs.h |    2 +-
 fs/cifs/file.c   |   18 ++++++++++++++----
 fs/cifs/inode.c  |   30 ++++++++++++++++++------------
 4 files changed, 40 insertions(+), 18 deletions(-)
fs/cifs/cifsfs.c +7 -1
index de49fbb..b275d76 100644
@@ -634,7 +634,13 @@ static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
 		CIFS_I(file->f_path.dentry->d_inode)->time = 0;
 
 		retval = cifs_revalidate_file(file);
-		if (retval < 0)
+		/*
+		 * We only need to get right file length and don't need to
+		 * aware about busy pages (-EBUSY error code).
+		 */
+		if (retval == -EBUSY)
+			retval = 0;
+		else if (retval < 0)
 			return (loff_t)retval;
 	}
 	return generic_file_llseek_unlocked(file, offset, origin);
fs/cifs/cifsfs.h +1 -1
index bb64313..f4391ff 100644
@@ -61,7 +61,7 @@ extern int cifs_rename(struct inode *, struct dentry *, struct inode *,
 		       struct dentry *);
 extern int cifs_revalidate_file(struct file *filp);
 extern int cifs_revalidate_dentry(struct dentry *);
-extern void cifs_invalidate_mapping(struct inode *inode);
+extern int cifs_invalidate_mapping(struct inode *inode);
 extern int cifs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
 extern int cifs_setattr(struct dentry *, struct iattr *);
 
fs/cifs/file.c +0 -0
index b9731c9..d99cf48 100644
@@ -1448,8 +1448,13 @@ int cifs_strict_fsync(struct file *file, int datasync)
 	cFYI(1, "Sync file - name: %s datasync: 0x%x",
 		file->f_path.dentry->d_name.name, datasync);
 

fs/cifs/file.c int cifs_strict_fsync(struct file *file, int datasync) · line 1458

Quoted 10 lines
fs/cifs/file.c +7 -2
-	if (!CIFS_I(inode)->clientCanCacheRead)
-		cifs_invalidate_mapping(inode);
+	if (!CIFS_I(inode)->clientCanCacheRead) {
+		rc = cifs_invalidate_mapping(inode);
+		if (rc) {
+			FreeXid(xid);
+			return rc;
+		}
+	}
 

Hmm...this put us in danger of reporting writeback errors twice? Note that cifs_invalidate_mapping resets the error on the mapping if writeback fails. So imagine:

t1: do the regular filemap_write_and_wait in vfs_fsync
t2: another thread dirties pages on the inode
t1: call cifs_invalidate_mapping which does filemap_write_and_wait.
That fails, so fsync returns an error.
t2: now it does an fsync and the error is reported again

Quoted 40 lines
fs/cifs/file.c +7 -2
 	tcon = tlink_tcon(smbfile->tlink);
 	if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC))
@@ -1916,8 +1921,13 @@ int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma)
 
 	xid = GetXid();
 
-	if (!CIFS_I(inode)->clientCanCacheRead)
-		cifs_invalidate_mapping(inode);
+	if (!CIFS_I(inode)->clientCanCacheRead) {
+		rc = cifs_invalidate_mapping(inode);
+		if (rc) {
+			FreeXid(xid);
+			return rc;
+		}
+	}
 
 	rc = generic_file_mmap(file, vma);
 	FreeXid(xid);
fs/cifs/inode.c +2 -4
index adb6324..d3abfc5 100644
@@ -1683,27 +1683,25 @@ cifs_inode_needs_reval(struct inode *inode)
 /*
  * Zap the cache. Called when invalid_mapping flag is set.
  */
-void
+int
 cifs_invalidate_mapping(struct inode *inode)
 {
-	int rc;
+	int rc = 0;
 	struct cifsInodeInfo *cifs_i = CIFS_I(inode);
 
-	cifs_i->invalid_mapping = false;
-
 	if (inode->i_mapping && inode->i_mapping->nrpages != 0) {
 		/* write back any cached data */
 		rc = filemap_write_and_wait(inode->i_mapping);
 		mapping_set_error(inode->i_mapping, rc);

fs/cifs/inode.c cifs_inode_needs_reval(struct inode *inode) · line 1700

Quoted 10 lines
fs/cifs/inode.c +4 -5
 		rc = invalidate_inode_pages2(inode->i_mapping);
-		if (rc) {
-			cERROR(1, "%s: could not invalidate inode %p", __func__,
-			       inode);
-			cifs_i->invalid_mapping = true;
-		}
+		if (rc)
+			cFYI(1, "%s: could not invalidate inode %p", __func__,
+			     inode);
+		cifs_i->invalid_mapping = (rc != 0) ? true : false;

This is racy. You could end up writing back, invalidating pages, etc. successfully. Another thread could come along afterward and then set invalid_mapping = true. Then you go and set it to false, thinking that everything is OK.

I think what you really want to do is mapping to false first, then reset it to true if writeback or page invalidation fails.

Quoted 42 lines
fs/cifs/inode.c +12 -3
 	}
 
 	cifs_fscache_reset_inode_cookie(inode);
+	return rc;
 }
 
 int cifs_revalidate_file(struct file *filp)
@@ -1722,7 +1720,7 @@ int cifs_revalidate_file(struct file *filp)
 
 check_inval:
 	if (CIFS_I(inode)->invalid_mapping)
-		cifs_invalidate_mapping(inode);
+		rc = cifs_invalidate_mapping(inode);
 
 	return rc;
 }
@@ -1764,7 +1762,7 @@ int cifs_revalidate_dentry(struct dentry *dentry)
 
 check_inval:
 	if (CIFS_I(inode)->invalid_mapping)
-		cifs_invalidate_mapping(inode);
+		rc = cifs_invalidate_mapping(inode);
 
 	kfree(full_path);
 	FreeXid(xid);
@@ -1776,7 +1774,15 @@ int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
 {
 	struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb);
 	struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
-	int err = cifs_revalidate_dentry(dentry);
+	int err;
+
+	err = cifs_revalidate_dentry(dentry);
+	/*
+	 * We only need to get file attributes and don't need to
+	 * aware about busy pages (-EBUSY error code).
+	 */
+	if (err == -EBUSY)
+		err = 0;
 
 	if (!err) {
 		generic_fillattr(dentry->d_inode, stat);
Signature · 1 line
Jeff Layton <[email protected]>
#4 lore raw
In reply to a message not in the archive

2011/3/24 Steve French <[email protected]>:

Quoted 34 lines · Pavel Shilovsky
Quoted 33 lines

Base of approach for splitting all calls that uses cifs_invalidate_mapping (or cifs_revalidate_dentry, cifs_revalidate_file) into two groups:
1) aware about -EBUSY error code and report it back (cifs_d_revalidate, cifs_strict_fsync, cifs_file_strict_mmap);
2) don't do it (cifs_getattrs, cifs_lseek).

fs/cifs/inode.c +2 -8
index adb6324..d3abfc5 100644
@@ -1683,27 +1683,25 @@ cifs_inode_needs_reval(struct inode *inode)
  /*
  * Zap the cache. Called when invalid_mapping flag is set.
  */
-void
+int
  cifs_invalidate_mapping(struct inode *inode)
  {
-       int rc;
+       int rc = 0;
        struct cifsInodeInfo *cifs_i = CIFS_I(inode);
 
-       cifs_i->invalid_mapping = false;
-
        if (inode->i_mapping && inode->i_mapping->nrpages != 0) {
                /* write back any cached data */
                rc = filemap_write_and_wait(inode->i_mapping);
                mapping_set_error(inode->i_mapping, rc);
                rc = invalidate_inode_pages2(inode->i_mapping);
-               if (rc) {
-                       cERROR(1, "%s: could not invalidate inode %p", __func__,
-                              inode);
-                       cifs_i->invalid_mapping = true;
Quoted 8 lines

fs/cifs/inode.c cifs_inode_needs_reval(struct inode *inode) · line 1701

Quoted 6 lines
fs/cifs/inode.c +4 -1
-               }
+               if (rc)
+                       cFYI(1, "%s: could not invalidate inode %p", __func__,
+                            inode);
+               cifs_i->invalid_mapping = (rc != 0) ? true : false;
        }

aren't you setting invalid_mapping twice (the first one is redundant)?

I think I set it only here in cifs_invalidate_mapping - can you clarify what you mean?

Quoted 36 lines
Quoted 36 lines
fs/cifs/inode.c +0 -0
  int cifs_revalidate_file(struct file *filp)
@@ -1722,7 +1720,7 @@ int cifs_revalidate_file(struct file *filp)
 

 check_inval:
       if (CIFS_I(inode)->invalid_mapping)
-               cifs_invalidate_mapping(inode);
+               rc = cifs_invalidate_mapping(inode);

       return rc;
 }

fs/cifs/inode.c +0 -0
@@ -1764,7 +1762,7 @@ int cifs_revalidate_dentry(struct dentry *dentry)
 

 check_inval:
       if (CIFS_I(inode)->invalid_mapping)
-               cifs_invalidate_mapping(inode);
+               rc = cifs_invalidate_mapping(inode);

       kfree(full_path);
       FreeXid(xid);

fs/cifs/inode.c +9 -1
@@ -1776,7 +1774,15 @@ int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
  {
        struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb);
        struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
-       int err = cifs_revalidate_dentry(dentry);
+       int err;
+
+       err = cifs_revalidate_dentry(dentry);
+       /*
+        * We only need to get file attributes and don't need to
+        * aware about busy pages (-EBUSY error code).
+        */
+       if (err == -EBUSY)
+               err = 0;
 
Quoted 7 lines

fs/cifs/inode.c int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry, · line 1788

Quoted 2 lines
fs/cifs/inode.c +0 -0
        if (!err) {
                generic_fillattr(dentry->d_inode, stat);

With this change couldn't we accidently return a temporary write error (ENOSPC for example or EACCESS) when revalidating a file - which the caller is not expecting (getattr should only return errors if it can't get the attributes)

Now I don't return error from filemap_write_and_wait - so, there are no errors from write part of revalidation.

Signature · 2 lines
Best regards,
Pavel Shilovsky.
#7 lore raw
In reply to a message not in the archive

2011/3/25 Jeff Layton <[email protected]>:

Quoted 72 lines
Quoted 54 lines · On Thu, 24 Mar 2011 17:39:47 +0300 Pavel Shilovsky…

Base of approach for splitting all calls that uses cifs_invalidate_mapping (or cifs_revalidate_dentry, cifs_revalidate_file) into two groups:
1) aware about -EBUSY error code and report it back (cifs_d_revalidate, cifs_strict_fsync, cifs_file_strict_mmap);
2) don't do it (cifs_getattrs, cifs_lseek).

---
 fs/cifs/cifsfs.c |    8 +++++++- fs/cifs/cifsfs.h |    2 +-
 fs/cifs/file.c   |   18 ++++++++++++++---- fs/cifs/inode.c  |   30 ++++++++++++++++++------------

 4 files changed, 40 insertions(+), 18 deletions(-)
fs/cifs/cifsfs.c +7 -1
index de49fbb..b275d76 100644
@@ -634,7 +634,13 @@ static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
               CIFS_I(file->f_path.dentry->d_inode)->time = 0;
 
               retval = cifs_revalidate_file(file);
-             if (retval < 0)
+             /*
+              * We only need to get right file length and don't need to
+              * aware about busy pages (-EBUSY error code).
+              */
+             if (retval == -EBUSY)
+                     retval = 0;
+             else if (retval < 0)
                       return (loff_t)retval;
       }
       return generic_file_llseek_unlocked(file, offset, origin);
fs/cifs/cifsfs.h +1 -1
index bb64313..f4391ff 100644
@@ -61,7 +61,7 @@ extern int cifs_rename(struct inode *, struct dentry *, struct inode *,
                      struct dentry *);
  extern int cifs_revalidate_file(struct file *filp);
  extern int cifs_revalidate_dentry(struct dentry *);
-extern void cifs_invalidate_mapping(struct inode *inode);
+extern int cifs_invalidate_mapping(struct inode *inode);
  extern int cifs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  extern int cifs_setattr(struct dentry *, struct iattr *);
 
fs/cifs/file.c +0 -0
index b9731c9..d99cf48 100644
@@ -1448,8 +1448,13 @@ int cifs_strict_fsync(struct file *file, int datasync)
       cFYI(1, "Sync file - name: %s datasync: 0x%x",
               file->f_path.dentry->d_name.name, datasync);
 

fs/cifs/file.c int cifs_strict_fsync(struct file *file, int datasync) · line 1458

Quoted 10 lines
fs/cifs/file.c +7 -2
-     if (!CIFS_I(inode)->clientCanCacheRead)
-             cifs_invalidate_mapping(inode);
+     if (!CIFS_I(inode)->clientCanCacheRead) {
+             rc = cifs_invalidate_mapping(inode);
+             if (rc) {
+                     FreeXid(xid);
+                     return rc;
+             }
+     }
 

Hmm...this put us in danger of reporting writeback errors twice? Note that cifs_invalidate_mapping resets the error on the mapping if writeback fails. So imagine:

Quoted 5 lines

t1: do the regular filemap_write_and_wait in vfs_fsync
t2: another thread dirties pages on the inode
t1: call cifs_invalidate_mapping which does filemap_write_and_wait. That fails, so fsync returns an error.
t2: now it does an fsync and the error is reported again

why does the last line report the error again? what does it prevent to return OK?

Quoted 57 lines
Quoted 41 lines
fs/cifs/file.c +7 -2
       tcon = tlink_tcon(smbfile->tlink);
       if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC))
@@ -1916,8 +1921,13 @@ int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma)
 
       xid = GetXid();
 
-     if (!CIFS_I(inode)->clientCanCacheRead)
-             cifs_invalidate_mapping(inode);
+     if (!CIFS_I(inode)->clientCanCacheRead) {
+             rc = cifs_invalidate_mapping(inode);
+             if (rc) {
+                     FreeXid(xid);
+                     return rc;
+             }
+     }
 
       rc = generic_file_mmap(file, vma);
       FreeXid(xid);
fs/cifs/inode.c +2 -4
index adb6324..d3abfc5 100644
@@ -1683,27 +1683,25 @@ cifs_inode_needs_reval(struct inode *inode)
  /*
   * Zap the cache. Called when invalid_mapping flag is set.
   */
-void
+int
  cifs_invalidate_mapping(struct inode *inode)
  {
-     int rc;
+     int rc = 0;
       struct cifsInodeInfo *cifs_i = CIFS_I(inode);
 
-     cifs_i->invalid_mapping = false;
-
       if (inode->i_mapping && inode->i_mapping->nrpages != 0) {
               /* write back any cached data */
               rc = filemap_write_and_wait(inode->i_mapping);
               mapping_set_error(inode->i_mapping, rc);

fs/cifs/inode.c cifs_inode_needs_reval(struct inode *inode) · line 1700

Quoted 10 lines
fs/cifs/inode.c +4 -5
               rc = invalidate_inode_pages2(inode->i_mapping);
-             if (rc) {
-                     cERROR(1, "%s: could not invalidate inode %p", __func__,
-                            inode);
-                     cifs_i->invalid_mapping = true;
-             }
+             if (rc)
+                     cFYI(1, "%s: could not invalidate inode %p", __func__,
+                          inode);
+             cifs_i->invalid_mapping = (rc != 0) ? true : false;

This is racy. You could end up writing back, invalidating pages, etc. successfully. Another thread could come along afterward and then set invalid_mapping = true. Then you go and set it to false, thinking that everything is OK.

Quoted 3 lines

I think what you really want to do is mapping to false first, then reset it to true if writeback or page invalidation fails.

But in your case it's racy again:
1) t1 sets it to false
2) t2 sets it to false
3) t1 does filemap_write and invalidate - OK
4) t2 does filemap_write and invalidate - ERROR (!)
5) t2 marks invalid_mapping as true
6) t1 marks invalid_mapping as false - and we miss a ERROR from the 4rd line.

May be we should protect it through a special mapping lock?

Quoted 43 lines
Quoted 42 lines
fs/cifs/inode.c +1 -0
       }
 
       cifs_fscache_reset_inode_cookie(inode);
+     return rc;
  }
 
  int cifs_revalidate_file(struct file *filp)
@@ -1722,7 +1720,7 @@ int cifs_revalidate_file(struct file *filp)
 

 check_inval:
      if (CIFS_I(inode)->invalid_mapping)
-             cifs_invalidate_mapping(inode);
+             rc = cifs_invalidate_mapping(inode);

      return rc;
 }

fs/cifs/inode.c +0 -0
@@ -1764,7 +1762,7 @@ int cifs_revalidate_dentry(struct dentry *dentry)
 

 check_inval:
      if (CIFS_I(inode)->invalid_mapping)
-             cifs_invalidate_mapping(inode);
+             rc = cifs_invalidate_mapping(inode);

      kfree(full_path);
      FreeXid(xid);

fs/cifs/inode.c +9 -1
@@ -1776,7 +1774,15 @@ int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
  {
       struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb);
       struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
-     int err = cifs_revalidate_dentry(dentry);
+     int err;
+
+     err = cifs_revalidate_dentry(dentry);
+     /*
+      * We only need to get file attributes and don't need to
+      * aware about busy pages (-EBUSY error code).
+      */
+     if (err == -EBUSY)
+             err = 0;
 
       if (!err) {
               generic_fillattr(dentry->d_inode, stat);
Signature · 2 lines
Best regards,
Pavel Shilovsky.
#9 lore raw
In reply to a message not in the archive

2011/3/25 Pavel Shilovsky <[email protected]>:

Quoted 151 lines

2011/3/25 Jeff Layton <[email protected]>:

Quoted 72 lines
Quoted 54 lines · On Thu, 24 Mar 2011 17:39:47 +0300 Pavel Shilovsky…

Base of approach for splitting all calls that uses cifs_invalidate_mapping (or cifs_revalidate_dentry, cifs_revalidate_file) into two groups:
1) aware about -EBUSY error code and report it back (cifs_d_revalidate, cifs_strict_fsync, cifs_file_strict_mmap);
2) don't do it (cifs_getattrs, cifs_lseek).

---
 fs/cifs/cifsfs.c |    8 +++++++- fs/cifs/cifsfs.h |    2 +-
 fs/cifs/file.c   |   18 ++++++++++++++---- fs/cifs/inode.c  |   30 ++++++++++++++++++------------

 4 files changed, 40 insertions(+), 18 deletions(-)
fs/cifs/cifsfs.c +7 -1
index de49fbb..b275d76 100644
@@ -634,7 +634,13 @@ static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
               CIFS_I(file->f_path.dentry->d_inode)->time = 0;
 
               retval = cifs_revalidate_file(file);
-             if (retval < 0)
+             /*
+              * We only need to get right file length and don't need to
+              * aware about busy pages (-EBUSY error code).
+              */
+             if (retval == -EBUSY)
+                     retval = 0;
+             else if (retval < 0)
                       return (loff_t)retval;
       }
       return generic_file_llseek_unlocked(file, offset, origin);
fs/cifs/cifsfs.h +1 -1
index bb64313..f4391ff 100644
@@ -61,7 +61,7 @@ extern int cifs_rename(struct inode *, struct dentry *, struct inode *,
                      struct dentry *);
  extern int cifs_revalidate_file(struct file *filp);
  extern int cifs_revalidate_dentry(struct dentry *);
-extern void cifs_invalidate_mapping(struct inode *inode);
+extern int cifs_invalidate_mapping(struct inode *inode);
  extern int cifs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  extern int cifs_setattr(struct dentry *, struct iattr *);
 
fs/cifs/file.c +0 -0
index b9731c9..d99cf48 100644
@@ -1448,8 +1448,13 @@ int cifs_strict_fsync(struct file *file, int datasync)
       cFYI(1, "Sync file - name: %s datasync: 0x%x",
               file->f_path.dentry->d_name.name, datasync);
 

fs/cifs/file.c int cifs_strict_fsync(struct file *file, int datasync) · line 1458

Quoted 10 lines
fs/cifs/file.c +7 -2
-     if (!CIFS_I(inode)->clientCanCacheRead)
-             cifs_invalidate_mapping(inode);
+     if (!CIFS_I(inode)->clientCanCacheRead) {
+             rc = cifs_invalidate_mapping(inode);
+             if (rc) {
+                     FreeXid(xid);
+                     return rc;
+             }
+     }
 

Hmm...this put us in danger of reporting writeback errors twice? Note that cifs_invalidate_mapping resets the error on the mapping if writeback fails. So imagine:

Quoted 5 lines

t1: do the regular filemap_write_and_wait in vfs_fsync
t2: another thread dirties pages on the inode
t1: call cifs_invalidate_mapping which does filemap_write_and_wait. That fails, so fsync returns an error.
t2: now it does an fsync and the error is reported again

why does the last line report the error again? what does it prevent to return OK?

Quoted 57 lines
Quoted 41 lines
fs/cifs/file.c +7 -2
       tcon = tlink_tcon(smbfile->tlink);
       if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC))
@@ -1916,8 +1921,13 @@ int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma)
 
       xid = GetXid();
 
-     if (!CIFS_I(inode)->clientCanCacheRead)
-             cifs_invalidate_mapping(inode);
+     if (!CIFS_I(inode)->clientCanCacheRead) {
+             rc = cifs_invalidate_mapping(inode);
+             if (rc) {
+                     FreeXid(xid);
+                     return rc;
+             }
+     }
 
       rc = generic_file_mmap(file, vma);
       FreeXid(xid);
fs/cifs/inode.c +2 -4
index adb6324..d3abfc5 100644
@@ -1683,27 +1683,25 @@ cifs_inode_needs_reval(struct inode *inode)
  /*
   * Zap the cache. Called when invalid_mapping flag is set.
   */
-void
+int
  cifs_invalidate_mapping(struct inode *inode)
  {
-     int rc;
+     int rc = 0;
       struct cifsInodeInfo *cifs_i = CIFS_I(inode);
 
-     cifs_i->invalid_mapping = false;
-
       if (inode->i_mapping && inode->i_mapping->nrpages != 0) {
               /* write back any cached data */
               rc = filemap_write_and_wait(inode->i_mapping);
               mapping_set_error(inode->i_mapping, rc);

fs/cifs/inode.c cifs_inode_needs_reval(struct inode *inode) · line 1700

Quoted 10 lines
fs/cifs/inode.c +4 -5
               rc = invalidate_inode_pages2(inode->i_mapping);
-             if (rc) {
-                     cERROR(1, "%s: could not invalidate inode %p", __func__,
-                            inode);
-                     cifs_i->invalid_mapping = true;
-             }
+             if (rc)
+                     cFYI(1, "%s: could not invalidate inode %p", __func__,
+                          inode);
+             cifs_i->invalid_mapping = (rc != 0) ? true : false;

This is racy. You could end up writing back, invalidating pages, etc. successfully. Another thread could come along afterward and then set invalid_mapping = true. Then you go and set it to false, thinking that everything is OK.

Quoted 3 lines

I think what you really want to do is mapping to false first, then reset it to true if writeback or page invalidation fails.

But in your case it's racy again:
1) t1 sets it to false
2) t2 sets it to false
3) t1 does filemap_write and invalidate - OK
4) t2 does filemap_write and invalidate - ERROR (!)
5) t2 marks invalid_mapping as true
6) t1 marks invalid_mapping as false - and we miss a ERROR from the 4rd line.

Quoted 1 line

May be we should protect it through  a special mapping lock?

Sorry, you are right - there are no problems with it because on the line 6 we don't set anything as you suggest. So - this question is over.

Quoted 49 lines
Quoted 41 lines
Quoted 41 lines
fs/cifs/inode.c +1 -0
       }
 
       cifs_fscache_reset_inode_cookie(inode);
+     return rc;
  }
 
  int cifs_revalidate_file(struct file *filp)
@@ -1722,7 +1720,7 @@ int cifs_revalidate_file(struct file *filp)
 

 check_inval:
      if (CIFS_I(inode)->invalid_mapping)
-             cifs_invalidate_mapping(inode);
+             rc = cifs_invalidate_mapping(inode);

      return rc;
 }

fs/cifs/inode.c +0 -0
@@ -1764,7 +1762,7 @@ int cifs_revalidate_dentry(struct dentry *dentry)
 

 check_inval:
      if (CIFS_I(inode)->invalid_mapping)
-             cifs_invalidate_mapping(inode);
+             rc = cifs_invalidate_mapping(inode);

      kfree(full_path);
      FreeXid(xid);

fs/cifs/inode.c +9 -1
@@ -1776,7 +1774,15 @@ int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
  {
       struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb);
       struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
-     int err = cifs_revalidate_dentry(dentry);
+     int err;
+
+     err = cifs_revalidate_dentry(dentry);
+     /*
+      * We only need to get file attributes and don't need to
+      * aware about busy pages (-EBUSY error code).
+      */
+     if (err == -EBUSY)
+             err = 0;
 
Quoted 3 lines

fs/cifs/inode.c int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry, · line 1788

Quoted 2 lines
fs/cifs/inode.c +0 -0
       if (!err) {
               generic_fillattr(dentry->d_inode, stat);

--
Best regards,
Pavel Shilovsky.

Signature · 2 lines
Best regards,
Pavel Shilovsky.
#10 lore raw
In reply to a message not in the archive
Quoted 73 lines · On Fri, 25 Mar 2011 07:56:07 +0300 Pavel Shilovsky…

2011/3/25 Jeff Layton <[email protected]>:

Quoted 72 lines
Quoted 54 lines · On Thu, 24 Mar 2011 17:39:47 +0300 Pavel Shilovsky…

Base of approach for splitting all calls that uses cifs_invalidate_mapping (or cifs_revalidate_dentry, cifs_revalidate_file) into two groups:
1) aware about -EBUSY error code and report it back (cifs_d_revalidate, cifs_strict_fsync, cifs_file_strict_mmap);
2) don't do it (cifs_getattrs, cifs_lseek).

---
 fs/cifs/cifsfs.c |    8 +++++++- fs/cifs/cifsfs.h |    2 +-
 fs/cifs/file.c   |   18 ++++++++++++++---- fs/cifs/inode.c  |   30 ++++++++++++++++++------------

 4 files changed, 40 insertions(+), 18 deletions(-)
fs/cifs/cifsfs.c +7 -1
index de49fbb..b275d76 100644
@@ -634,7 +634,13 @@ static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
               CIFS_I(file->f_path.dentry->d_inode)->time = 0;
 
               retval = cifs_revalidate_file(file);
-             if (retval < 0)
+             /*
+              * We only need to get right file length and don't need to
+              * aware about busy pages (-EBUSY error code).
+              */
+             if (retval == -EBUSY)
+                     retval = 0;
+             else if (retval < 0)
                       return (loff_t)retval;
       }
       return generic_file_llseek_unlocked(file, offset, origin);
fs/cifs/cifsfs.h +1 -1
index bb64313..f4391ff 100644
@@ -61,7 +61,7 @@ extern int cifs_rename(struct inode *, struct dentry *, struct inode *,
                      struct dentry *);
  extern int cifs_revalidate_file(struct file *filp);
  extern int cifs_revalidate_dentry(struct dentry *);
-extern void cifs_invalidate_mapping(struct inode *inode);
+extern int cifs_invalidate_mapping(struct inode *inode);
  extern int cifs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  extern int cifs_setattr(struct dentry *, struct iattr *);
 
fs/cifs/file.c +0 -0
index b9731c9..d99cf48 100644
@@ -1448,8 +1448,13 @@ int cifs_strict_fsync(struct file *file, int datasync)
       cFYI(1, "Sync file - name: %s datasync: 0x%x",
               file->f_path.dentry->d_name.name, datasync);
 

fs/cifs/file.c int cifs_strict_fsync(struct file *file, int datasync) · line 1458

Quoted 10 lines
fs/cifs/file.c +7 -2
-     if (!CIFS_I(inode)->clientCanCacheRead)
-             cifs_invalidate_mapping(inode);
+     if (!CIFS_I(inode)->clientCanCacheRead) {
+             rc = cifs_invalidate_mapping(inode);
+             if (rc) {
+                     FreeXid(xid);
+                     return rc;
+             }
+     }
 

Hmm...this put us in danger of reporting writeback errors twice? Note that cifs_invalidate_mapping resets the error on the mapping if writeback fails. So imagine:

Quoted 9 lines
Quoted 5 lines

t1: do the regular filemap_write_and_wait in vfs_fsync
t2: another thread dirties pages on the inode
t1: call cifs_invalidate_mapping which does filemap_write_and_wait. That fails, so fsync returns an error.
t2: now it does an fsync and the error is reported again

why does the last line report the error again? what does it prevent to return OK?

cifs_invalidate_inode does this:

              rc = filemap_write_and_wait(inode->i_mapping);

               mapping_set_error(inode->i_mapping, rc);
               rc = invalidate_inode_pages2(inode->i_mapping);

...if there's an error on writeback, it'll reset that error on the mapping to make sure we can report it later. However, I was mistaken...this patch doesn't report any writeback errors here, just ones on invalidation, so it may be ok.

I wonder though...would it be less racy to set up a launder_page function for CIFS and just call invalidate_inode_pages2 here without the filemap_write_and_wait?

Signature · 1 line
Jeff Layton <[email protected]>
#12 lore raw
In reply to a message not in the archive

2011/3/25 Jeff Layton <[email protected]>:

Quoted 93 lines
Quoted 73 lines · On Fri, 25 Mar 2011 07:56:07 +0300 Pavel Shilovsky…

2011/3/25 Jeff Layton <[email protected]>:

Quoted 72 lines
Quoted 54 lines · On Thu, 24 Mar 2011 17:39:47 +0300 Pavel Shilovsky…

Base of approach for splitting all calls that uses cifs_invalidate_mapping (or cifs_revalidate_dentry, cifs_revalidate_file) into two groups:
1) aware about -EBUSY error code and report it back (cifs_d_revalidate, cifs_strict_fsync, cifs_file_strict_mmap);
2) don't do it (cifs_getattrs, cifs_lseek).

---
 fs/cifs/cifsfs.c |    8 +++++++- fs/cifs/cifsfs.h |    2 +-
 fs/cifs/file.c   |   18 ++++++++++++++---- fs/cifs/inode.c  |   30 ++++++++++++++++++------------

 4 files changed, 40 insertions(+), 18 deletions(-)
fs/cifs/cifsfs.c +7 -1
index de49fbb..b275d76 100644
@@ -634,7 +634,13 @@ static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
               CIFS_I(file->f_path.dentry->d_inode)->time = 0;
 
               retval = cifs_revalidate_file(file);
-             if (retval < 0)
+             /*
+              * We only need to get right file length and don't need to
+              * aware about busy pages (-EBUSY error code).
+              */
+             if (retval == -EBUSY)
+                     retval = 0;
+             else if (retval < 0)
                       return (loff_t)retval;
       }
       return generic_file_llseek_unlocked(file, offset, origin);
fs/cifs/cifsfs.h +1 -1
index bb64313..f4391ff 100644
@@ -61,7 +61,7 @@ extern int cifs_rename(struct inode *, struct dentry *, struct inode *,
                      struct dentry *);
  extern int cifs_revalidate_file(struct file *filp);
  extern int cifs_revalidate_dentry(struct dentry *);
-extern void cifs_invalidate_mapping(struct inode *inode);
+extern int cifs_invalidate_mapping(struct inode *inode);
  extern int cifs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  extern int cifs_setattr(struct dentry *, struct iattr *);
 
fs/cifs/file.c +0 -0
index b9731c9..d99cf48 100644
@@ -1448,8 +1448,13 @@ int cifs_strict_fsync(struct file *file, int datasync)
       cFYI(1, "Sync file - name: %s datasync: 0x%x",
               file->f_path.dentry->d_name.name, datasync);
 

fs/cifs/file.c int cifs_strict_fsync(struct file *file, int datasync) · line 1458

Quoted 10 lines
fs/cifs/file.c +7 -2
-     if (!CIFS_I(inode)->clientCanCacheRead)
-             cifs_invalidate_mapping(inode);
+     if (!CIFS_I(inode)->clientCanCacheRead) {
+             rc = cifs_invalidate_mapping(inode);
+             if (rc) {
+                     FreeXid(xid);
+                     return rc;
+             }
+     }
 

Hmm...this put us in danger of reporting writeback errors twice? Note that cifs_invalidate_mapping resets the error on the mapping if writeback fails. So imagine:

Quoted 9 lines
Quoted 5 lines

t1: do the regular filemap_write_and_wait in vfs_fsync
t2: another thread dirties pages on the inode
t1: call cifs_invalidate_mapping which does filemap_write_and_wait. That fails, so fsync returns an error.
t2: now it does an fsync and the error is reported again

why does the last line report the error again? what does it prevent to return OK?

cifs_invalidate_inode does this:

               rc = filemap_write_and_wait(inode->i_mapping); mapping_set_error(inode->i_mapping, rc); rc = invalidate_inode_pages2(inode->i_mapping);

Quoted 9 lines

...if there's an error on writeback, it'll reset that error on the mapping to make sure we can report it later. However, I was mistaken...this patch doesn't report any writeback errors here, just ones on invalidation, so it may be ok.

I wonder though...would it be less racy to set up a launder_page function for CIFS and just call invalidate_inode_pages2 here without the filemap_write_and_wait?

It can make sense but I think that it should be a separate patch. If everything is ok excepts things you commented I can provide the next version of the patch.

Signature · 2 lines
Best regards,
Pavel Shilovsky.
#14 lore raw
In reply to a message not in the archive
Quoted 99 lines · On Fri, 25 Mar 2011 22:47:23 +0300 Pavel Shilovsky…

2011/3/25 Jeff Layton <[email protected]>:

Quoted 98 lines
Quoted 73 lines · On Fri, 25 Mar 2011 07:56:07 +0300 Pavel Shilovsky…

2011/3/25 Jeff Layton <[email protected]>:

Quoted 72 lines
Quoted 54 lines · On Thu, 24 Mar 2011 17:39:47 +0300 Pavel Shilovsky…

Base of approach for splitting all calls that uses cifs_invalidate_mapping (or cifs_revalidate_dentry, cifs_revalidate_file) into two groups:
1) aware about -EBUSY error code and report it back (cifs_d_revalidate, cifs_strict_fsync, cifs_file_strict_mmap);
2) don't do it (cifs_getattrs, cifs_lseek).

---
 fs/cifs/cifsfs.c |    8 +++++++- fs/cifs/cifsfs.h |    2 +-
 fs/cifs/file.c   |   18 ++++++++++++++---- fs/cifs/inode.c  |   30 ++++++++++++++++++------------

 4 files changed, 40 insertions(+), 18 deletions(-)
fs/cifs/cifsfs.c +7 -1
index de49fbb..b275d76 100644
@@ -634,7 +634,13 @@ static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
               CIFS_I(file->f_path.dentry->d_inode)->time = 0;
 
               retval = cifs_revalidate_file(file);
-             if (retval < 0)
+             /*
+              * We only need to get right file length and don't need to
+              * aware about busy pages (-EBUSY error code).
+              */
+             if (retval == -EBUSY)
+                     retval = 0;
+             else if (retval < 0)
                       return (loff_t)retval;
       }
       return generic_file_llseek_unlocked(file, offset, origin);
fs/cifs/cifsfs.h +1 -1
index bb64313..f4391ff 100644
@@ -61,7 +61,7 @@ extern int cifs_rename(struct inode *, struct dentry *, struct inode *,
                      struct dentry *);
  extern int cifs_revalidate_file(struct file *filp);
  extern int cifs_revalidate_dentry(struct dentry *);
-extern void cifs_invalidate_mapping(struct inode *inode);
+extern int cifs_invalidate_mapping(struct inode *inode);
  extern int cifs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
  extern int cifs_setattr(struct dentry *, struct iattr *);
 
fs/cifs/file.c +0 -0
index b9731c9..d99cf48 100644
@@ -1448,8 +1448,13 @@ int cifs_strict_fsync(struct file *file, int datasync)
       cFYI(1, "Sync file - name: %s datasync: 0x%x",
               file->f_path.dentry->d_name.name, datasync);
 

fs/cifs/file.c int cifs_strict_fsync(struct file *file, int datasync) · line 1458

Quoted 10 lines
fs/cifs/file.c +7 -2
-     if (!CIFS_I(inode)->clientCanCacheRead)
-             cifs_invalidate_mapping(inode);
+     if (!CIFS_I(inode)->clientCanCacheRead) {
+             rc = cifs_invalidate_mapping(inode);
+             if (rc) {
+                     FreeXid(xid);
+                     return rc;
+             }
+     }
 

Hmm...this put us in danger of reporting writeback errors twice? Note that cifs_invalidate_mapping resets the error on the mapping if writeback fails. So imagine:

Quoted 9 lines
Quoted 5 lines

t1: do the regular filemap_write_and_wait in vfs_fsync
t2: another thread dirties pages on the inode
t1: call cifs_invalidate_mapping which does filemap_write_and_wait. That fails, so fsync returns an error.
t2: now it does an fsync and the error is reported again

why does the last line report the error again? what does it prevent to return OK?

cifs_invalidate_inode does this:

               rc = filemap_write_and_wait(inode->i_mapping); mapping_set_error(inode->i_mapping, rc); rc = invalidate_inode_pages2(inode->i_mapping);

...if there's an error on writeback, it'll reset that error on the mapping to make sure we can report it later. However, I was mistaken...this patch doesn't report any writeback errors here, just ones on invalidation, so it may be ok.

Quoted 9 lines
Quoted 4 lines

I wonder though...would it be less racy to set up a launder_page function for CIFS and just call invalidate_inode_pages2 here without the filemap_write_and_wait?

It can make sense but I think that it should be a separate patch. If everything is ok excepts things you commented I can provide the next version of the patch.

That's seems reasonable.

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