Skip to contentSkip to conversation

Update for patches in patch queue

DISCUSSION Applied Aneesh Kumar K.V 2 participants 5 messages Sep 12, 2008 – Sep 13, 2008 ext4 file system

lore
Share & tools
lore
#1 lore raw
In reply to Aneesh Kumar K.V

From: Aneesh Kumar K.V <[email protected]>

With delayed allocation we use i_data_sem to update i_disksize. We need to update i_disksize only if the new size specified is greater than the current value and we need to make sure we don't race with other i_disksize update. With delayed allocation we will switch to nondelalloc write_begin if we are low on free blocks. That means nondelalloc write_begin also need to use the same locking.

We also need to check and update i_disksize even if the new size is less that inode.i_size because of delayed allocation.

---
 fs/ext4/ext4.h    |   11 +++++++++++
 fs/ext4/extents.c |    9 +++++----
 fs/ext4/inode.c   |   54 +++++++++++++++++++++++++++++------------------------
 3 files changed, 46 insertions(+), 28 deletions(-)
fs/ext4/ext4.h +11 -0
index 79bdcd8..9fb7796 100644
@@ -1219,6 +1219,17 @@ do {								\
 #define EXT4_FREEBLOCKS_WATERMARK 0
 #endif
 
+static inline void ext4_update_i_disksize(struct inode *inode, loff_t newsize)
+{
+	/*
+	 * XXX: replace with spinlock if seen contended -bzzz
+	 */
+	down_write(&EXT4_I(inode)->i_data_sem);
+	if (newsize > EXT4_I(inode)->i_disksize)
+		EXT4_I(inode)->i_disksize = newsize;
+	up_write(&EXT4_I(inode)->i_data_sem);
+	return ;
+}
 
 /*
  * Inodes and files operations
fs/ext4/extents.c +5 -4
index b24d3c5..cbf388a 100644
@@ -2877,10 +2877,11 @@ static void ext4_falloc_update_inode(struct inode *inode,
 	 * Update only when preallocation was requested beyond
 	 * the file size.
 	 */
-	if (!(mode & FALLOC_FL_KEEP_SIZE) &&
-				new_size > i_size_read(inode)) {
-		i_size_write(inode, new_size);
-		EXT4_I(inode)->i_disksize = new_size;
+	if (!(mode & FALLOC_FL_KEEP_SIZE)) {
+		if (new_size > i_size_read(inode))
+			i_size_write(inode, new_size);
+		if (new_size > EXT4_I(inode)->i_disksize)
+			ext4_update_i_disksize(inode, new_size);
 	}
 
 }
fs/ext4/inode.c +22 -19

73 lines not on this page · raw message

#2 lore raw

From: Aneesh Kumar K.V <[email protected]>

For blocksize < pagesize we need to remove blocks that got allocte in block_wirte_begin if we fail with ENOSPC for later blocks. block_write_begin internally does this if it allocated page locally. This make sure we don't have blocks outisde inode.i_size during ENOSPC

---
 fs/ext4/inode.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
fs/ext4/inode.c +14 -0
index 48534be..e7c84e4 100644
@@ -1391,6 +1391,13 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping,
  		unlock_page(page);
 		ext4_journal_stop(handle);
  		page_cache_release(page);
+		/*
+		 * block_write_begin may have instantiated a few blocks
+		 * outside i_size.  Trim these off again. Don't need
+		 * i_size_read because we hold i_mutex.
+		 */
+		if (pos + len > inode->i_size)
+			vmtruncate(inode, inode->i_size);
 	}
 
 	if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
@@ -2560,6 +2567,13 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping,
 		unlock_page(page);
 		ext4_journal_stop(handle);
 		page_cache_release(page);
+		/*
+		 * block_write_begin may have instantiated a few blocks
+		 * outside i_size.  Trim these off again. Don't need
+		 * i_size_read because we hold i_mutex.
+		 */
+		if (pos + len > inode->i_size)
+			vmtruncate(inode, inode->i_size);
 	}
 
 	if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
#0 lore raw

The following patches update the below patches in the patch queue.

ext4_truncate_block_allocated_on_a_failed_ext4_write_begin.patch ext4_i_disksize_lock_race_fix.patch

The change is to move some parts of the patch from ext4_i_disksize_lock_race_fix.patch to ext4_truncate_block_allocated_on_a_failed_ext4_write_begin.patch

#3 lore raw
In reply to Aneesh Kumar K.V

Hi,

I guess git send-email did something wrong. I had these two patches as followup for the compose mail with this subject. Any how i am attaching the patches below. The patches update ext4_truncate_block_allocated_on_a_failed_ext4_write_begin.patch and ext4_i_disksize_lock_race_fix.patch by moving some changes from ext4_i_disksize_lock_race_fix.patch to the other.

-aneesh

ext4: truncate block allocated on a failed ext4_write_begin

From: Aneesh Kumar K.V <[email protected]>

For blocksize < pagesize we need to remove blocks that got allocte in block_wirte_begin if we fail with ENOSPC for later blocks. block_write_begin internally does this if it allocated page locally. This make sure we don't have blocks outisde inode.i_size during ENOSPC

---
 fs/ext4/inode.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
fs/ext4/inode.c +14 -0
index 48534be..e7c84e4 100644
@@ -1391,6 +1391,13 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping,
  		unlock_page(page);
 		ext4_journal_stop(handle);
  		page_cache_release(page);
+		/*
+		 * block_write_begin may have instantiated a few blocks
+		 * outside i_size.  Trim these off again. Don't need
+		 * i_size_read because we hold i_mutex.
+		 */
+		if (pos + len > inode->i_size)
+			vmtruncate(inode, inode->i_size);
 	}
 
 	if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
@@ -2560,6 +2567,13 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping,
 		unlock_page(page);
 		ext4_journal_stop(handle);
 		page_cache_release(page);
+		/*
+		 * block_write_begin may have instantiated a few blocks
+		 * outside i_size.  Trim these off again. Don't need
+		 * i_size_read because we hold i_mutex.
+		 */
+		if (pos + len > inode->i_size)
+			vmtruncate(inode, inode->i_size);
 	}
 
 	if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))

ext4: Properly update i_disksize.

From: Aneesh Kumar K.V <[email protected]>

With delayed allocation we use i_data_sem to update i_disksize. We need to update i_disksize only if the new size specified is greater than the current value and we need to make sure we don't race with other i_disksize update. With delayed allocation we will switch to nondelalloc write_begin if we are low on free blocks. That means nondelalloc write_begin also need to use the same locking.

We also need to check and update i_disksize even
if the new size is less that inode.i_size because
of delayed allocation.

---
 fs/ext4/ext4.h    |   11 +++++++++++
 fs/ext4/extents.c |    9 +++++----
 fs/ext4/inode.c   |   54 +++++++++++++++++++++++++++++------------------------
 3 files changed, 46 insertions(+), 28 deletions(-)
fs/ext4/ext4.h +11 -0
index 79bdcd8..9fb7796 100644
@@ -1219,6 +1219,17 @@ do {								\
 #define EXT4_FREEBLOCKS_WATERMARK 0
 #endif
 
+static inline void ext4_update_i_disksize(struct inode *inode, loff_t newsize)
+{
+	/*
+	 * XXX: replace with spinlock if seen contended -bzzz
+	 */
+	down_write(&EXT4_I(inode)->i_data_sem);
+	if (newsize > EXT4_I(inode)->i_disksize)
+		EXT4_I(inode)->i_disksize = newsize;
+	up_write(&EXT4_I(inode)->i_data_sem);
+	return ;
+}
 
 /*
  * Inodes and files operations
fs/ext4/extents.c +5 -4
index b24d3c5..cbf388a 100644
@@ -2877,10 +2877,11 @@ static void ext4_falloc_update_inode(struct inode *inode,
 	 * Update only when preallocation was requested beyond
 	 * the file size.
 	 */
-	if (!(mode & FALLOC_FL_KEEP_SIZE) &&
-				new_size > i_size_read(inode)) {
-		i_size_write(inode, new_size);
-		EXT4_I(inode)->i_disksize = new_size;
+	if (!(mode & FALLOC_FL_KEEP_SIZE)) {
+		if (new_size > i_size_read(inode))
+			i_size_write(inode, new_size);
+		if (new_size > EXT4_I(inode)->i_disksize)
+			ext4_update_i_disksize(inode, new_size);
 	}
 
 }
fs/ext4/inode.c +22 -19

73 lines not on this page · raw message

maintainer Applied
#4 lore raw
Quoted 7 lines · Aneesh Kumar K.V

I guess git send-email did something wrong. I had these two patches as followup for the compose mail with this subject. Any how i am attaching the patches below. The patches update ext4_truncate_block_allocated_on_a_failed_ext4_write_begin.patch and ext4_i_disksize_lock_race_fix.patch by moving some changes from ext4_i_disksize_lock_race_fix.patch to the other.

Thanks, applied. I merged back in the patch description improvements I had made, and made a few more to improve the English description of these two patches.

- Ted