Skip to contentSkip to conversation

writeback: Update dirty flags in two steps

PATCH In review Dmitry Monakhov 2 participants 2 messages May 7, 2010 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 writeback: Update dirty flags in two steps

Filesystems with delalloc support may dirty inode during writepages. As result inode will have dirty metadata flags even after write_inode. In fact we have two dedicated functions for proper data and metadata writeback. It is reasonable to separate flags updates in two stages.

https://bugzilla.kernel.org/show_bug.cgi?id=15906

---
 fs/fs-writeback.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)
fs/fs-writeback.c +11 -4
index fdc07e3..e73d8ff 100644
@@ -459,11 +459,9 @@ writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
 
 	BUG_ON(inode->i_state & I_SYNC);
 
-	/* Set I_SYNC, reset I_DIRTY */
-	dirty = inode->i_state & I_DIRTY;
+	/* Set I_SYNC, reset I_DIRTY_PAGES */
 	inode->i_state |= I_SYNC;
-	inode->i_state &= ~I_DIRTY;
-
+	inode->i_state &= ~I_DIRTY_PAGES;
 	spin_unlock(&inode_lock);
 
 	ret = do_writepages(mapping, wbc);
@@ -479,6 +477,15 @@ writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
 			ret = err;
 	}
 
+	/*
+	 * Some filesystems may redirty the inode during the writeback
+	 * due to delalloc, clear dirty metadata flags right before
+	 * write_inode()
+	 */
+	spin_lock(&inode_lock);
+	dirty = inode->i_state & I_DIRTY;
+	inode->i_state &= ~(I_DIRTY_SYNC | I_DIRTY_DATASYNC);
+	spin_unlock(&inode_lock);
 	/* Don't write the inode if only I_DIRTY_PAGES was set */
 	if (dirty & (I_DIRTY_SYNC | I_DIRTY_DATASYNC)) {
 		int err = write_inode(inode, wbc);
Signature · 1 line
1.6.6.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Dmitry Monakhov

Filesystems with delalloc support may dirty inode during writepages. As result inode will have dirty metadata flags even after write_inode. In fact we have two dedicated functions for proper data and metadata writeback. It is reasonable to separate flags updates in two stages.

https://bugzilla.kernel.org/show_bug.cgi?id=15906

Looks good and passes XFSQA for me.

fs/fs-writeback.c writeback_single_inode(struct inode *inode, struct writeback_control *wbc) · line 490

Quoted 6 lines
fs/fs-writeback.c +4 -0
+	spin_lock(&inode_lock);
+	dirty = inode->i_state & I_DIRTY;
+	inode->i_state &= ~(I_DIRTY_SYNC | I_DIRTY_DATASYNC);
+	spin_unlock(&inode_lock);
 	/* Don't write the inode if only I_DIRTY_PAGES was set */
 	if (dirty & (I_DIRTY_SYNC | I_DIRTY_DATASYNC)) {

No need for the double masking, the first line could be just

	dirty = inode->i_state;

or you could do:

	/* Don't write the inode if only I_DIRTY_PAGES was set */
	dirty = inode->i_state & (I_DIRTY_SYNC | I_DIRTY_DATASYNC);

and then just

	if (dirty) {