Skip to contentSkip to conversation

ext2: Update also inode on disk when dir is IS_DIRSYNC

PATCH In review Jan Kara 3 participants 4 messages Jan 13, 2009 – Jan 14, 2009 ext2 file system

lore
Share & tools
lore

Jan Kara

author
#0 lore raw

PATCH 1/1 ext2: Update also inode on disk when dir is IS_DIRSYNC

We used to just write changed page for IS_DIRSYNC inodes. But we also have to update directory inode itself just for the case that we've allocated a new block and changed i_size.

CC Pavel Machek <[email protected]>
---
 fs/ext2/dir.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

Andrew, would you please merge the patch? Ext3 and ext4 don't have this
problem BTW.

fs/ext2/dir.c +2 -3
index 9a0fc40..7fba549 100644
@@ -94,11 +94,10 @@ static int ext2_commit_chunk(struct page *page, loff_t pos, unsigned len)
 		i_size_write(dir, pos+len);
 		mark_inode_dirty(dir);
 	}
+	unlock_page(page);
 
 	if (IS_DIRSYNC(dir))
-		err = write_one_page(page, 1);
-	else
-		unlock_page(page);
+		err = ext2_sync_inode(dir);
 
 	return err;
 }
Signature · 1 line
1.6.0.4
#1 lore raw
Quoted 6 lines

We used to just write changed page for IS_DIRSYNC inodes. But we also have to update directory inode itself just for the case that we've allocated a new block and changed i_size.

CC Pavel Machek <[email protected]>

Tested, and I can't break ext2 in simple tests now.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#2 lore raw
In reply to Jan Kara
Quoted 19 lines · On Tue, 13 Jan 2009 13:42:02 +0100 Jan Kara <[email protected]> wrote:

We used to just write changed page for IS_DIRSYNC inodes. But we also have to update directory inode itself just for the case that we've allocated a new block and changed i_size.

CC Pavel Machek <[email protected]>
---
 fs/ext2/dir.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

Andrew, would you please merge the patch? Ext3 and ext4 don't have this
problem BTW.

fs/ext2/dir.c +0 -0
index 9a0fc40..7fba549 100644
@@ -94,11 +94,10 @@ static int ext2_commit_chunk(struct page *page, loff_t pos, unsigned len)
 		i_size_write(dir, pos+len);

fs/ext2/dir.c static int ext2_commit_chunk(struct page *page, loff_t pos, unsigned len) · line 101

Quoted 10 lines
fs/ext2/dir.c +2 -3
 		mark_inode_dirty(dir);
 	}
+	unlock_page(page);
 
 	if (IS_DIRSYNC(dir))
-		err = write_one_page(page, 1);
-	else
-		unlock_page(page);
+		err = ext2_sync_inode(dir);
 

But with this change we no longer sync the data page? Don't we need something like this:

static int ext2_commit_chunk(struct page *page, loff_t pos, unsigned len)

{
	struct address_space *mapping = page->mapping;
	struct inode *dir = mapping->host;
	int err = 0;

	dir->i_version++;
	block_write_end(NULL, mapping, pos, len, len, page, NULL);

	if (pos+len > dir->i_size) {
		i_size_write(dir, pos+len);
		mark_inode_dirty(dir);
	}

	if (IS_DIRSYNC(dir)) {
		err = write_one_page(page, 1);
		if (err == 0)
			err = ext2_sync_inode(dir);
	} else {
		unlock_page(page);
	}

	return err;
}

?

author
#3 lore raw
Quoted 26 lines · Andrew Morton
Quoted 23 lines · On Tue, 13 Jan 2009 13:42:02 +0100 Jan Kara <[email protected]> wrote:

We used to just write changed page for IS_DIRSYNC inodes. But we also have to update directory inode itself just for the case that we've allocated a new block and changed i_size.

CC Pavel Machek <[email protected]>
---
 fs/ext2/dir.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

Andrew, would you please merge the patch? Ext3 and ext4 don't have this
problem BTW.

fs/ext2/dir.c +1 -0
index 9a0fc40..7fba549 100644
@@ -94,11 +94,10 @@ static int ext2_commit_chunk(struct page *page, loff_t pos, unsigned len)
 		i_size_write(dir, pos+len);
 		mark_inode_dirty(dir);
 	}
+	unlock_page(page);
 
Quoted 9 lines

fs/ext2/dir.c static int ext2_commit_chunk(struct page *page, loff_t pos, unsigned len) · line 101

Quoted 6 lines
fs/ext2/dir.c +1 -3
 	if (IS_DIRSYNC(dir))
-		err = write_one_page(page, 1);
-	else
-		unlock_page(page);
+		err = ext2_sync_inode(dir);
 

But with this change we no longer sync the data page? Don't we need something like this:

Oh, correct, we do. I was confused by sync_inode() calling fdatawrite()
but did not realize that the way ext2_sync_inode() calls it has start == end == 0. Thanks for spotting this.

Quoted 25 lines

static int ext2_commit_chunk(struct page *page, loff_t pos, unsigned len)

{
	struct address_space *mapping = page->mapping;
	struct inode *dir = mapping->host;
	int err = 0;

	dir->i_version++;
	block_write_end(NULL, mapping, pos, len, len, page, NULL);

	if (pos+len > dir->i_size) {
		i_size_write(dir, pos+len);
		mark_inode_dirty(dir);
	}

	if (IS_DIRSYNC(dir)) {
		err = write_one_page(page, 1);
		if (err == 0)
			err = ext2_sync_inode(dir);
	} else {
		unlock_page(page);
	}

	return err;
}
Quoted 1 line

?

Yes, I'll send you a new version of the patch and also send refreshed
second patch with blkdev_issue_flush() calls.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR