Skip to contentSkip to conversation

nilfs2: add logic for the case of file growing (old size <= new size) in nilfs_truncate()

PATCH In review Vyacheslav Dubeyko 2 participants 4 messages Apr 24, 2013 – Apr 26, 2013

Subsystems (2)
lore
Share & tools
lore

Vyacheslav Dubeyko

author maintainer
#0 lore raw

PATCH 1/1 nilfs2: add logic for the case of file growing (old size <= new size) in nilfs_truncate()

From: Vyacheslav Dubeyko <[email protected]>
Subject: [PATCH] nilfs2: add logic for the case of file growing (old size <= new size) in nilfs_truncate()

There are situations when nilfs_truncate() is called with new value of i_size that is greater than old one. This patch adds logic for such case.

---
 fs/nilfs2/inode.c |   30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
fs/nilfs2/inode.c +30 -0
index 6b49f14..5ccaace 100644
@@ -698,6 +698,36 @@ void nilfs_truncate(struct inode *inode)
 
 	blocksize = sb->s_blocksize;
 	blkoff = (inode->i_size + blocksize - 1) >> sb->s_blocksize_bits;
+
+	if (blkoff > inode->i_blocks) {
+		int err;
+		struct address_space *mapping = inode->i_mapping;
+		struct page *page;
+		void *fsdata;
+		loff_t size = inode->i_size;
+
+		err = pagecache_write_begin(NULL, mapping, size, 0,
+						AOP_FLAG_UNINTERRUPTIBLE,
+						&page, &fsdata);
+		if (err) {
+			printk(KERN_ERR
+			    "NILFS: pagecache_write_begin() failed: err %d",
+			    err);
+			return;
+		}
+		err = pagecache_write_end(NULL, mapping, size,
+						0, 0, page, fsdata);
+		if (err < 0) {
+			printk(KERN_ERR
+			    "NILFS: pagecache_write_end() failed: err %d",
+			    err);
+			return;
+		}
+		mark_inode_dirty(inode);
+		return;
+	} else if (blkoff == inode->i_blocks)
+		return;
+
 	nilfs_transaction_begin(sb, &ti, 0); /* never fails */
 
 	block_truncate_page(inode->i_mapping, inode->i_size, nilfs_get_block);
Signature · 1 line
1.7.9.5
#1 lore raw

Hi Vyacheslav,

Quoted 7 lines · Vyacheslav Dubeyko

From: Vyacheslav Dubeyko <[email protected]>
Subject: [PATCH] nilfs2: add logic for the case of file growing (old size <= new size) in nilfs_truncate()

There are situations when nilfs_truncate() is called with new value of i_size that is greater than old one. This patch adds logic for such case.

Did you confirm that nilfs_truncate has real problem in such situtation?

I think hole blocks should be appended in that case.

Doesn't the current implementation work so?

With regards,
Ryusuke Konishi

Quoted 54 lines
---
 fs/nilfs2/inode.c |   30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
fs/nilfs2/inode.c +30 -0
index 6b49f14..5ccaace 100644
@@ -698,6 +698,36 @@ void nilfs_truncate(struct inode *inode)
 
 	blocksize = sb->s_blocksize;
 	blkoff = (inode->i_size + blocksize - 1) >> sb->s_blocksize_bits;
+
+	if (blkoff > inode->i_blocks) {
+		int err;
+		struct address_space *mapping = inode->i_mapping;
+		struct page *page;
+		void *fsdata;
+		loff_t size = inode->i_size;
+
+		err = pagecache_write_begin(NULL, mapping, size, 0,
+						AOP_FLAG_UNINTERRUPTIBLE,
+						&page, &fsdata);
+		if (err) {
+			printk(KERN_ERR
+			    "NILFS: pagecache_write_begin() failed: err %d",
+			    err);
+			return;
+		}
+		err = pagecache_write_end(NULL, mapping, size,
+						0, 0, page, fsdata);
+		if (err < 0) {
+			printk(KERN_ERR
+			    "NILFS: pagecache_write_end() failed: err %d",
+			    err);
+			return;
+		}
+		mark_inode_dirty(inode);
+		return;
+	} else if (blkoff == inode->i_blocks)
+		return;
+
 	nilfs_transaction_begin(sb, &ti, 0); /* never fails */
 
 	block_truncate_page(inode->i_mapping, inode->i_size, nilfs_get_block);
Signature · 8 lines
1.7.9.5



--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

author maintainer
#2 lore raw
Quoted 5 lines · Ryusuke Konishi

Hi Vyacheslav,

Quoted 3 lines · Vyacheslav Dubeyko

From: Vyacheslav Dubeyko <[email protected]>
Subject: [PATCH] nilfs2: add logic for the case of file growing (old size <= new size) in nilfs_truncate()

Quoted 7 lines
Quoted 4 lines

There are situations when nilfs_truncate() is called with new value of i_size that is greater than old one. This patch adds logic for such case.

Did you confirm that nilfs_truncate has real problem in such situtation?

I haven't any reproducing path that can reveal real problem for such situation. But I think that, as minimum, it makes sense to return from nilfs_truncate() without any activity for the case of blkoff == inode->i_blocks.

Quoted 4 lines

I think hole blocks should be appended in that case.

Doesn't the current implementation work so?

As I understand, in current NILFS2 implementation nilfs_truncate() results in calling nilfs_get_block() with create flag equals by zero. The nilfs_get_block() simply returns without any activity for the case of file growing:

135 } else if (ret == -ENOENT) {
136 /* not found is not error (e.g. hole); must return without
137 the mapped state flag. */
138 ;
139 }

Suggested implementation calls nilfs_get_block() with create flag equals by 1, in result. So, it will allocate the block really. If the real allocation is not desirable then I am wrong with suggested implementation for the case of blkoff > inode->i_blocks.

Could you share your vision about it?

With the best regards,
Vyacheslav Dubeyko.

Quoted 62 lines

With regards,
Ryusuke Konishi

Quoted 54 lines
---
 fs/nilfs2/inode.c |   30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
fs/nilfs2/inode.c +30 -0
index 6b49f14..5ccaace 100644
@@ -698,6 +698,36 @@ void nilfs_truncate(struct inode *inode)
 
 	blocksize = sb->s_blocksize;
 	blkoff = (inode->i_size + blocksize - 1) >> sb->s_blocksize_bits;
+
+	if (blkoff > inode->i_blocks) {
+		int err;
+		struct address_space *mapping = inode->i_mapping;
+		struct page *page;
+		void *fsdata;
+		loff_t size = inode->i_size;
+
+		err = pagecache_write_begin(NULL, mapping, size, 0,
+						AOP_FLAG_UNINTERRUPTIBLE,
+						&page, &fsdata);
+		if (err) {
+			printk(KERN_ERR
+			    "NILFS: pagecache_write_begin() failed: err %d",
+			    err);
+			return;
+		}
+		err = pagecache_write_end(NULL, mapping, size,
+						0, 0, page, fsdata);
+		if (err < 0) {
+			printk(KERN_ERR
+			    "NILFS: pagecache_write_end() failed: err %d",
+			    err);
+			return;
+		}
+		mark_inode_dirty(inode);
+		return;
+	} else if (blkoff == inode->i_blocks)
+		return;
+
 	nilfs_transaction_begin(sb, &ti, 0); /* never fails */
 
 	block_truncate_page(inode->i_mapping, inode->i_size, nilfs_get_block);
Signature · 8 lines
1.7.9.5



--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
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

#3 lore raw
Quoted 11 lines · Vyacheslav Dubeyko
Quoted 10 lines · Ryusuke Konishi

Hi Vyacheslav,

Quoted 7 lines · Vyacheslav Dubeyko

From: Vyacheslav Dubeyko <[email protected]>
Subject: [PATCH] nilfs2: add logic for the case of file growing (old size <= new size) in nilfs_truncate()

There are situations when nilfs_truncate() is called with new value of i_size that is greater than old one. This patch adds logic for such case.

Quoted 7 lines
Quoted 2 lines

Did you confirm that nilfs_truncate has real problem in such situtation?

I haven't any reproducing path that can reveal real problem for such situation. But I think that, as minimum, it makes sense to return from nilfs_truncate() without any activity for the case of blkoff == inode->i_blocks.

block_truncate_page() must be called even if blkoff == inode->i_blocks because it handles marginal block.

Quoted 10 lines
Quoted 4 lines

I think hole blocks should be appended in that case.

Doesn't the current implementation work so?

As I understand, in current NILFS2 implementation nilfs_truncate() results in calling nilfs_get_block() with create flag equals by zero. The nilfs_get_block() simply returns without any activity for the case of file growing:

Quoted 6 lines

135 } else if (ret == -ENOENT) {
136 /* not found is not error (e.g. hole); must return without
137 the mapped state flag. */
138 ;
139 }

That is the desired behavior.

Quoted 6 lines

Suggested implementation calls nilfs_get_block() with create flag equals by 1, in result. So, it will allocate the block really. If the real allocation is not desirable then I am wrong with suggested implementation for the case of blkoff > inode->i_blocks.

Could you share your vision about it?

As I commented on the previous mail, we don't have to do the real allocation for the case of blkoff > inode->i_blocks.

We just have to set up inode so that the extended part is regarded as hole blocks. Hole blocks are read as null bytes ('\0'), and this complies with the spec of truncate/ftruncate.

Regards,
Ryusuke Konishi

Quoted 67 lines

With the best regards,
Vyacheslav Dubeyko.

Quoted 54 lines

With regards,
Ryusuke Konishi

Quoted 50 lines
---
 fs/nilfs2/inode.c |   30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
fs/nilfs2/inode.c +30 -0
index 6b49f14..5ccaace 100644
@@ -698,6 +698,36 @@ void nilfs_truncate(struct inode *inode)
 
 	blocksize = sb->s_blocksize;
 	blkoff = (inode->i_size + blocksize - 1) >> sb->s_blocksize_bits;
+
+	if (blkoff > inode->i_blocks) {
+		int err;
+		struct address_space *mapping = inode->i_mapping;
+		struct page *page;
+		void *fsdata;
+		loff_t size = inode->i_size;
+
+		err = pagecache_write_begin(NULL, mapping, size, 0,
+						AOP_FLAG_UNINTERRUPTIBLE,
+						&page, &fsdata);
+		if (err) {
+			printk(KERN_ERR
+			    "NILFS: pagecache_write_begin() failed: err %d",
+			    err);
+			return;
+		}
+		err = pagecache_write_end(NULL, mapping, size,
+						0, 0, page, fsdata);
+		if (err < 0) {
+			printk(KERN_ERR
+			    "NILFS: pagecache_write_end() failed: err %d",
+			    err);
+			return;
+		}
+		mark_inode_dirty(inode);
+		return;
+	} else if (blkoff == inode->i_blocks)
+		return;
+
 	nilfs_transaction_begin(sb, &ti, 0); /* never fails */
 
 	block_truncate_page(inode->i_mapping, inode->i_size, nilfs_get_block);
Signature · 1 line
1.7.9.5
Quoted 8 lines
Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

--
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

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html