Skip to contentSkip to conversation

CIFS: Use invalidate_inode_pages2 instead of invalidate_remote_inode (try #2)

PATCH In review Pavel Shilovsky 3 participants 6 messages Feb 25, 2011 – Mar 15, 2011 2 messages not in the archive

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

PATCH 1/1 CIFS: Use invalidate_inode_pages2 instead of invalidate_remote_inode (try #2)

Use invalidate_inode_pages2 that don't leave pages even if shrink_page_list() has a temp ref on them. It prevents a data coherency problem on exclusive oplocks opens.

---
 fs/cifs/inode.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)
fs/cifs/inode.c +11 -5
index 589f3e3..0011e95 100644
@@ -1687,12 +1687,18 @@ cifs_invalidate_mapping(struct inode *inode)
 
 	cifs_i->invalid_mapping = false;
 
-	/* write back any cached data */
-	if (inode->i_mapping && inode->i_mapping->nrpages != 0) {
-		rc = filemap_write_and_wait(inode->i_mapping);
-		mapping_set_error(inode->i_mapping, rc);
+	if (inode->i_mapping) {
+		/* write back any cached data */
+		if (inode->i_mapping->nrpages != 0) {
+			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);
 	}
-	invalidate_remote_inode(inode);
+
 	cifs_fscache_reset_inode_cookie(inode);
 }
 
Signature · 1 line
1.7.1

A message that is not in the archive (sent off-list or not yet received): 1298629310-4618-1-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org

#2 lore raw

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

Quoted 38 lines

Use invalidate_inode_pages2 that don't leave pages even if shrink_page_list() has a temp ref on them. It prevents a data coherency problem on exclusive oplocks opens.

---
 fs/cifs/inode.c |   16 +++++++++++-----

 1 files changed, 11 insertions(+), 5 deletions(-)
fs/cifs/inode.c +11 -6
index 589f3e3..0011e95 100644
@@ -1687,12 +1687,18 @@ cifs_invalidate_mapping(struct inode *inode)
 
        cifs_i->invalid_mapping = false;
 
-       /* write back any cached data */
-       if (inode->i_mapping && inode->i_mapping->nrpages != 0) {
-               rc = filemap_write_and_wait(inode->i_mapping);
-               mapping_set_error(inode->i_mapping, rc);
+       if (inode->i_mapping) {
+               /* write back any cached data */
+               if (inode->i_mapping->nrpages != 0) {
+                       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);
        }
-       invalidate_remote_inode(inode);
+
        cifs_fscache_reset_inode_cookie(inode);
  }
 
--
Quoted 3 lines

1.7.1

What's about this?

Signature · 2 lines
Best regards,
Pavel Shilovsky.
Reviewed-by
#3 lore raw
In reply to a message not in the archive
Quoted 27 lines · On Fri, 25 Feb 2011 13:21:50 +0300 Pavel Shilovsky…

Use invalidate_inode_pages2 that don't leave pages even if shrink_page_list() has a temp ref on them. It prevents a data coherency problem on exclusive oplocks opens.

---
 fs/cifs/inode.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)
fs/cifs/inode.c +6 -4
index 589f3e3..0011e95 100644
@@ -1687,12 +1687,18 @@ cifs_invalidate_mapping(struct inode *inode)
 
 	cifs_i->invalid_mapping = false;
 
-	/* write back any cached data */
-	if (inode->i_mapping && inode->i_mapping->nrpages != 0) {
-		rc = filemap_write_and_wait(inode->i_mapping);
-		mapping_set_error(inode->i_mapping, rc);
+	if (inode->i_mapping) {
+		/* write back any cached data */
+		if (inode->i_mapping->nrpages != 0) {
+			rc = filemap_write_and_wait(inode->i_mapping);
+			mapping_set_error(inode->i_mapping, rc);
+		}

fs/cifs/inode.c cifs_invalidate_mapping(struct inode *inode) · line 1704

Quoted 10 lines
fs/cifs/inode.c +5 -1
+		rc = invalidate_inode_pages2(inode->i_mapping);
+		if (rc)
+			cERROR(1, "%s: could not invalidate inode %p", __func__,
+			       inode);
 	}
-	invalidate_remote_inode(inode);
+
 	cifs_fscache_reset_inode_cookie(inode);
 }
 

Looks like a correct change overall. I wonder too whether we need to make cifs_invalidate_mapping return the error from invalidate_inode_pages2 and have the callers deal with that appropriately.

For now, I think we should just keep an eye out for the printk that you're adding to pop. If we start to see those frequently under some workloads we can think about what the right approach is.

#4 lore raw
In reply to a message not in the archive
Quoted 27 lines · On Fri, 25 Feb 2011 13:21:50 +0300 Pavel Shilovsky…

Use invalidate_inode_pages2 that don't leave pages even if shrink_page_list() has a temp ref on them. It prevents a data coherency problem on exclusive oplocks opens.

---
 fs/cifs/inode.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)
fs/cifs/inode.c +6 -4
index 589f3e3..0011e95 100644
@@ -1687,12 +1687,18 @@ cifs_invalidate_mapping(struct inode *inode)
 
 	cifs_i->invalid_mapping = false;
 
-	/* write back any cached data */
-	if (inode->i_mapping && inode->i_mapping->nrpages != 0) {
-		rc = filemap_write_and_wait(inode->i_mapping);
-		mapping_set_error(inode->i_mapping, rc);
+	if (inode->i_mapping) {
+		/* write back any cached data */
+		if (inode->i_mapping->nrpages != 0) {
+			rc = filemap_write_and_wait(inode->i_mapping);
+			mapping_set_error(inode->i_mapping, rc);
+		}

fs/cifs/inode.c cifs_invalidate_mapping(struct inode *inode) · line 1704

Quoted 10 lines
fs/cifs/inode.c +5 -1
+		rc = invalidate_inode_pages2(inode->i_mapping);
+		if (rc)
+			cERROR(1, "%s: could not invalidate inode %p", __func__,
+			       inode);
 	}
-	invalidate_remote_inode(inode);
+
 	cifs_fscache_reset_inode_cookie(inode);
 }
 

I think using invalidate_inode_pages2 is the right thing to do. I'm not so keen however on simply popping a printk when that fails. The user is going to see that and say "huh?"

I think we need to consider allowing EBUSY bubble up to userspace appropriately. Otherwise we still risk data coherency problems, right? Perhaps cifs_invalidate_mapping should be changed to an int return and the callers could return errors from it?

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

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

#6 lore raw

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

Quoted 45 lines
Quoted 27 lines · On Fri, 25 Feb 2011 13:21:50 +0300 Pavel Shilovsky…

Use invalidate_inode_pages2 that don't leave pages even if shrink_page_list() has a temp ref on them. It prevents a data coherency problem on exclusive oplocks opens.

---
 fs/cifs/inode.c |   16 +++++++++++-----

 1 files changed, 11 insertions(+), 5 deletions(-)
fs/cifs/inode.c +6 -4
index 589f3e3..0011e95 100644
@@ -1687,12 +1687,18 @@ cifs_invalidate_mapping(struct inode *inode)
 
       cifs_i->invalid_mapping = false;
 
-     /* write back any cached data */
-     if (inode->i_mapping && inode->i_mapping->nrpages != 0) {
-             rc = filemap_write_and_wait(inode->i_mapping);
-             mapping_set_error(inode->i_mapping, rc);
+     if (inode->i_mapping) {
+             /* write back any cached data */
+             if (inode->i_mapping->nrpages != 0) {
+                     rc = filemap_write_and_wait(inode->i_mapping);
+                     mapping_set_error(inode->i_mapping, rc);
+             }

fs/cifs/inode.c cifs_invalidate_mapping(struct inode *inode) · line 1704

Quoted 10 lines
fs/cifs/inode.c +5 -1
+             rc = invalidate_inode_pages2(inode->i_mapping);
+             if (rc)
+                     cERROR(1, "%s: could not invalidate inode %p", __func__,
+                            inode);
       }
-     invalidate_remote_inode(inode);
+
       cifs_fscache_reset_inode_cookie(inode);
  }
 

I think using invalidate_inode_pages2 is the right thing to do. I'm not so keen however on simply popping a printk when that fails. The user is going to see that and say "huh?"

Quoted 5 lines

I think we need to consider allowing EBUSY bubble up to userspace appropriately. Otherwise we still risk data coherency problems, right? Perhaps cifs_invalidate_mapping should be changed to an int return and the callers could return errors from it?

I like this idea. I can recreate the patch if nobody objects.

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

PATCH 1/1 CIFS: Use invalidate_inode_pages2 instead of invalidate_remote_inode (try #2)

In reply to Pavel Shilovsky

Hi all!

I faced with a problem of data coherency in cifs and found out that invalidate_remote_inode doesn't invalidate all pages in the failed cases. I also find this comment
http://lxr.free-electrons.com/source/mm/truncate.c#L369 and decided that the reason of such a strage behavior can be buddy page allocator, that uses shrink_page_list(). So, what's why I decided to use invalidate_inode_pages2 that deal with such pages successfully.

Could you comment on this patch? Is it a possible scenario that invalidate_remote_inode can fail on pages if shrink_page_list() has a temp ref on them?

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

Quoted 41 lines

Use invalidate_inode_pages2 that don't leave pages even if shrink_page_list() has a temp ref on them. It prevents a data coherency problem on exclusive oplocks opens.

---
 fs/cifs/inode.c |   16 +++++++++++-----

 1 files changed, 11 insertions(+), 5 deletions(-)
fs/cifs/inode.c +11 -6
index 589f3e3..0011e95 100644
@@ -1687,12 +1687,18 @@ cifs_invalidate_mapping(struct inode *inode)
 
        cifs_i->invalid_mapping = false;
 
-       /* write back any cached data */
-       if (inode->i_mapping && inode->i_mapping->nrpages != 0) {
-               rc = filemap_write_and_wait(inode->i_mapping);
-               mapping_set_error(inode->i_mapping, rc);
+       if (inode->i_mapping) {
+               /* write back any cached data */
+               if (inode->i_mapping->nrpages != 0) {
+                       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);
        }
-       invalidate_remote_inode(inode);
+
        cifs_fscache_reset_inode_cookie(inode);
  }
 
--

1.7.1

Signature · 6 lines
Best regards,
Pavel Shilovsky.
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html