Skip to contentSkip to conversation

xfs: Check for delayed allocations before setting extsize

PATCH Superseded Ojaswin Mujoo 3 participants 13 messages Oct 11, 2024 – Oct 18, 2024 XFS filesystem

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 xfs: Check for delayed allocations before setting extsize

Extsize is allowed to be set on files with no data in it. For this, we were checking if the files have extents but missed to check if delayed extents were present. This patch adds that check.

While we are at it, also refactor this check into a helper since its used in some other places as well like xfs_inactive() or xfs_ioctl_setattr_xflags()

**Without the patch (SUCCEEDS)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)

**With the patch (FAILS as expected)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)
xfs_io: FS_IOC_FSSETXATTR testfile: Invalid argument

---
 fs/xfs/xfs_inode.c | 2 +-
 fs/xfs/xfs_inode.h | 5 +++++
 fs/xfs/xfs_ioctl.c | 4 ++--
 3 files changed, 8 insertions(+), 3 deletions(-)
fs/xfs/xfs_inode.c +1 -1
index bcc277fc0a83..19dcb569a3e7 100644
@@ -1409,7 +1409,7 @@ xfs_inactive(
 
 	if (S_ISREG(VFS_I(ip)->i_mode) &&
 	    (ip->i_disk_size != 0 || XFS_ISIZE(ip) != 0 ||
-	     ip->i_df.if_nextents > 0 || ip->i_delayed_blks > 0))
+	     xfs_inode_has_filedata(ip)))
 		truncate = 1;
 
 	if (xfs_iflags_test(ip, XFS_IQUOTAUNCHECKED)) {
fs/xfs/xfs_inode.h +5 -0
index 97ed912306fd..03944b6c5fba 100644
@@ -292,6 +292,11 @@ static inline bool xfs_is_cow_inode(struct xfs_inode *ip)
 	return xfs_is_reflink_inode(ip) || xfs_is_always_cow_inode(ip);
 }
 
+static inline bool xfs_inode_has_filedata(const struct xfs_inode *ip)
+{
+	return ip->i_df.if_nextents > 0 || ip->i_delayed_blks > 0;
+}
+
 /*
  * Check if an inode has any data in the COW fork.  This might be often false
  * even for inodes with the reflink flag when there is no pending COW operation.
fs/xfs/xfs_ioctl.c +2 -2
index a20d426ef021..2567fd2a0994 100644
@@ -481,7 +481,7 @@ xfs_ioctl_setattr_xflags(
 
 	if (rtflag != XFS_IS_REALTIME_INODE(ip)) {
 		/* Can't change realtime flag if any extents are allocated. */
-		if (ip->i_df.if_nextents || ip->i_delayed_blks)
+		if (xfs_inode_has_filedata(ip))
 			return -EINVAL;
 
 		/*
@@ -602,7 +602,7 @@ xfs_ioctl_setattr_check_extsize(
 	if (!fa->fsx_valid)
 		return 0;
 
-	if (S_ISREG(VFS_I(ip)->i_mode) && ip->i_df.if_nextents &&
+	if (S_ISREG(VFS_I(ip)->i_mode) && xfs_inode_has_filedata(ip) &&
 	    XFS_FSB_TO_B(mp, ip->i_extsize) != fa->fsx_extsize)
 		return -EINVAL;
 
Signature · 1 line
2.43.5
Reviewed-by on v3 1/1
#1 lore raw
Quoted 17 lines · Ojaswin Mujoo

Extsize is allowed to be set on files with no data in it. For this, we were checking if the files have extents but missed to check if delayed extents were present. This patch adds that check.

While we are at it, also refactor this check into a helper since its used in some other places as well like xfs_inactive() or xfs_ioctl_setattr_xflags()

**Without the patch (SUCCEEDS)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)

**With the patch (FAILS as expected)**

Quoted 8 lines
$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)
xfs_io: FS_IOC_FSSETXATTR testfile: Invalid argument

Looks good now,

--D

Quoted 61 lines
---
 fs/xfs/xfs_inode.c | 2 +-
 fs/xfs/xfs_inode.h | 5 +++++
 fs/xfs/xfs_ioctl.c | 4 ++--
 3 files changed, 8 insertions(+), 3 deletions(-)
fs/xfs/xfs_inode.c +1 -1
index bcc277fc0a83..19dcb569a3e7 100644
@@ -1409,7 +1409,7 @@ xfs_inactive(
 
 	if (S_ISREG(VFS_I(ip)->i_mode) &&
 	    (ip->i_disk_size != 0 || XFS_ISIZE(ip) != 0 ||
-	     ip->i_df.if_nextents > 0 || ip->i_delayed_blks > 0))
+	     xfs_inode_has_filedata(ip)))
 		truncate = 1;
 
 	if (xfs_iflags_test(ip, XFS_IQUOTAUNCHECKED)) {
fs/xfs/xfs_inode.h +5 -0
index 97ed912306fd..03944b6c5fba 100644
@@ -292,6 +292,11 @@ static inline bool xfs_is_cow_inode(struct xfs_inode *ip)
 	return xfs_is_reflink_inode(ip) || xfs_is_always_cow_inode(ip);
 }
 
+static inline bool xfs_inode_has_filedata(const struct xfs_inode *ip)
+{
+	return ip->i_df.if_nextents > 0 || ip->i_delayed_blks > 0;
+}
+
 /*
  * Check if an inode has any data in the COW fork.  This might be often false
  * even for inodes with the reflink flag when there is no pending COW operation.
fs/xfs/xfs_ioctl.c +2 -2
index a20d426ef021..2567fd2a0994 100644
@@ -481,7 +481,7 @@ xfs_ioctl_setattr_xflags(
 
 	if (rtflag != XFS_IS_REALTIME_INODE(ip)) {
 		/* Can't change realtime flag if any extents are allocated. */
-		if (ip->i_df.if_nextents || ip->i_delayed_blks)
+		if (xfs_inode_has_filedata(ip))
 			return -EINVAL;
 
 		/*
@@ -602,7 +602,7 @@ xfs_ioctl_setattr_check_extsize(
 	if (!fa->fsx_valid)
 		return 0;
 
-	if (S_ISREG(VFS_I(ip)->i_mode) && ip->i_df.if_nextents &&
+	if (S_ISREG(VFS_I(ip)->i_mode) && xfs_inode_has_filedata(ip) &&
 	    XFS_FSB_TO_B(mp, ip->i_extsize) != fa->fsx_extsize)
 		return -EINVAL;
 
Signature · 1 line
2.43.5
#2 lore raw
Quoted 24 lines · Darrick J. Wong
Quoted 23 lines · Ojaswin Mujoo

Extsize is allowed to be set on files with no data in it. For this, we were checking if the files have extents but missed to check if delayed extents were present. This patch adds that check.

While we are at it, also refactor this check into a helper since its used in some other places as well like xfs_inactive() or xfs_ioctl_setattr_xflags()

**Without the patch (SUCCEEDS)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)

**With the patch (FAILS as expected)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)
xfs_io: FS_IOC_FSSETXATTR testfile: Invalid argument

Quoted 5 lines
Quoted 2 lines

Looks good now,

That said, could you add a fixes tag for the xfs_ioctl_setattr_* changes, please?

--D

Quoted 64 lines

--D

Quoted 61 lines
---
 fs/xfs/xfs_inode.c | 2 +-
 fs/xfs/xfs_inode.h | 5 +++++
 fs/xfs/xfs_ioctl.c | 4 ++--
 3 files changed, 8 insertions(+), 3 deletions(-)
fs/xfs/xfs_inode.c +1 -1
index bcc277fc0a83..19dcb569a3e7 100644
@@ -1409,7 +1409,7 @@ xfs_inactive(
 
 	if (S_ISREG(VFS_I(ip)->i_mode) &&
 	    (ip->i_disk_size != 0 || XFS_ISIZE(ip) != 0 ||
-	     ip->i_df.if_nextents > 0 || ip->i_delayed_blks > 0))
+	     xfs_inode_has_filedata(ip)))
 		truncate = 1;
 
 	if (xfs_iflags_test(ip, XFS_IQUOTAUNCHECKED)) {
fs/xfs/xfs_inode.h +5 -0
index 97ed912306fd..03944b6c5fba 100644
@@ -292,6 +292,11 @@ static inline bool xfs_is_cow_inode(struct xfs_inode *ip)
 	return xfs_is_reflink_inode(ip) || xfs_is_always_cow_inode(ip);
 }
 
+static inline bool xfs_inode_has_filedata(const struct xfs_inode *ip)
+{
+	return ip->i_df.if_nextents > 0 || ip->i_delayed_blks > 0;
+}
+
 /*
  * Check if an inode has any data in the COW fork.  This might be often false
  * even for inodes with the reflink flag when there is no pending COW operation.
fs/xfs/xfs_ioctl.c +2 -2
index a20d426ef021..2567fd2a0994 100644
@@ -481,7 +481,7 @@ xfs_ioctl_setattr_xflags(
 
 	if (rtflag != XFS_IS_REALTIME_INODE(ip)) {
 		/* Can't change realtime flag if any extents are allocated. */
-		if (ip->i_df.if_nextents || ip->i_delayed_blks)
+		if (xfs_inode_has_filedata(ip))
 			return -EINVAL;
 
 		/*
@@ -602,7 +602,7 @@ xfs_ioctl_setattr_check_extsize(
 	if (!fa->fsx_valid)
 		return 0;
 
-	if (S_ISREG(VFS_I(ip)->i_mode) && ip->i_df.if_nextents &&
+	if (S_ISREG(VFS_I(ip)->i_mode) && xfs_inode_has_filedata(ip) &&
 	    XFS_FSB_TO_B(mp, ip->i_extsize) != fa->fsx_extsize)
 		return -EINVAL;
 
Signature · 1 line
2.43.5
#3 lore raw
Quoted 25 lines · Darrick J. Wong
Quoted 24 lines · Darrick J. Wong
Quoted 23 lines · Ojaswin Mujoo

Extsize is allowed to be set on files with no data in it. For this, we were checking if the files have extents but missed to check if delayed extents were present. This patch adds that check.

While we are at it, also refactor this check into a helper since its used in some other places as well like xfs_inactive() or xfs_ioctl_setattr_xflags()

**Without the patch (SUCCEEDS)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)

**With the patch (FAILS as expected)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)
xfs_io: FS_IOC_FSSETXATTR testfile: Invalid argument

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Looks good now,

That said, could you add a fixes tag for the xfs_ioctl_setattr_* changes, please?

Hi Darrick,

Sure I'll send a new version. Thanks for the review!

Regards,
ojaswin

Reviewed-by
#4 lore raw
Quoted 4 lines · Ojaswin Mujoo
Quoted 3 lines · Darrick J. Wong
Quoted 2 lines · Darrick J. Wong
Quoted 1 line · Ojaswin Mujoo

Extsize is allowed to be set on files with no data in it.

Should this be "Extsize should only be allowed to be set on files with no data written."

Quoted 32 lines

For this,

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines

we were checking if the files have extents but missed to check if delayed extents were present. This patch adds that check.

While we are at it, also refactor this check into a helper since its used in some other places as well like xfs_inactive() or xfs_ioctl_setattr_xflags()

**Without the patch (SUCCEEDS)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)

**With the patch (FAILS as expected)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)
xfs_io: FS_IOC_FSSETXATTR testfile: Invalid argument

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Looks good now,

That said, could you add a fixes tag for the xfs_ioctl_setattr_* changes, please?

Quoted 7 lines

Hi Darrick,

Sure I'll send a new version. Thanks for the review!

Regards,
ojaswin

Feel free to add the following if you like:

#5 lore raw
Quoted 8 lines · John Garry
Quoted 4 lines · Ojaswin Mujoo
Quoted 3 lines · Darrick J. Wong
Quoted 2 lines · Darrick J. Wong
Quoted 1 line · Ojaswin Mujoo

Extsize is allowed to be set on files with no data in it.

Should this be "Extsize should only be allowed to be set on files with no data written."

Sure, I can make the change.

Quoted 35 lines
Quoted 35 lines

For this,

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines

we were checking if the files have extents but missed to check if delayed extents were present. This patch adds that check.

While we are at it, also refactor this check into a helper since its used in some other places as well like xfs_inactive() or xfs_ioctl_setattr_xflags()

**Without the patch (SUCCEEDS)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)

**With the patch (FAILS as expected)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)
xfs_io: FS_IOC_FSSETXATTR testfile: Invalid argument

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Looks good now,

That said, could you add a fixes tag for the xfs_ioctl_setattr_* changes, please?

Hi Darrick,

Quoted 8 lines
Quoted 5 lines

Sure I'll send a new version. Thanks for the review!

Regards,
ojaswin

Feel free to add the following if you like:

Thanks John!

Regards,
ojaswin

#6 lore raw
In reply to Darrick J. Wong
Quoted 25 lines · Darrick J. Wong
Quoted 24 lines · Darrick J. Wong
Quoted 23 lines · Ojaswin Mujoo

Extsize is allowed to be set on files with no data in it. For this, we were checking if the files have extents but missed to check if delayed extents were present. This patch adds that check.

While we are at it, also refactor this check into a helper since its used in some other places as well like xfs_inactive() or xfs_ioctl_setattr_xflags()

**Without the patch (SUCCEEDS)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)

**With the patch (FAILS as expected)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)
xfs_io: FS_IOC_FSSETXATTR testfile: Invalid argument

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Looks good now,

That said, could you add a fixes tag for the xfs_ioctl_setattr_* changes, please?

Actually a small doubt Darrick regarding the Fixes commit (asked inline below):

Quoted 52 lines

--D

Quoted 49 lines

--D

Quoted 47 lines
---
 fs/xfs/xfs_inode.c | 2 +-
 fs/xfs/xfs_inode.h | 5 +++++
 fs/xfs/xfs_ioctl.c | 4 ++--
 3 files changed, 8 insertions(+), 3 deletions(-)
fs/xfs/xfs_inode.c +1 -1
index bcc277fc0a83..19dcb569a3e7 100644
@@ -1409,7 +1409,7 @@ xfs_inactive(
 
 	if (S_ISREG(VFS_I(ip)->i_mode) &&
 	    (ip->i_disk_size != 0 || XFS_ISIZE(ip) != 0 ||
-	     ip->i_df.if_nextents > 0 || ip->i_delayed_blks > 0))
+	     xfs_inode_has_filedata(ip)))
 		truncate = 1;
 
 	if (xfs_iflags_test(ip, XFS_IQUOTAUNCHECKED)) {
fs/xfs/xfs_inode.h +5 -0
index 97ed912306fd..03944b6c5fba 100644
@@ -292,6 +292,11 @@ static inline bool xfs_is_cow_inode(struct xfs_inode *ip)
 	return xfs_is_reflink_inode(ip) || xfs_is_always_cow_inode(ip);
 }
 
+static inline bool xfs_inode_has_filedata(const struct xfs_inode *ip)
+{
+	return ip->i_df.if_nextents > 0 || ip->i_delayed_blks > 0;
+}
+
 /*
  * Check if an inode has any data in the COW fork.  This might be often false
  * even for inodes with the reflink flag when there is no pending COW operation.
fs/xfs/xfs_ioctl.c +1 -1
index a20d426ef021..2567fd2a0994 100644
@@ -481,7 +481,7 @@ xfs_ioctl_setattr_xflags(
 
 	if (rtflag != XFS_IS_REALTIME_INODE(ip)) {
 		/* Can't change realtime flag if any extents are allocated. */
-		if (ip->i_df.if_nextents || ip->i_delayed_blks)
+		if (xfs_inode_has_filedata(ip))
 			return -EINVAL;
 
Quoted 7 lines
Quoted 7 lines

fs/xfs/xfs_ioctl.c xfs_ioctl_setattr_check_extsize( · line 605

Quoted 7 lines
fs/xfs/xfs_ioctl.c +1 -1
 		/*
@@ -602,7 +602,7 @@ xfs_ioctl_setattr_check_extsize(
 	if (!fa->fsx_valid)
 		return 0;
 
-	if (S_ISREG(VFS_I(ip)->i_mode) && ip->i_df.if_nextents &&
+	if (S_ISREG(VFS_I(ip)->i_mode) && xfs_inode_has_filedata(ip) &&

So seems like there have been lots of changes to this particular line mostly as a part of refactoring other areas but seems like the actual commit that introduced it was:

commit e94af02a9cd7b6590bec81df9d6ab857d6cf322f
Author: Eric Sandeen <[email protected]>
Date: Wed Nov 2 15:10:41 2005 +1100

[XFS] fix old xfs_setattr mis-merge from irix; mostly harmless esp if not using xfs rt

Before this we were actually checking ip->i_delayed_blks correctly. So just wanted to confirm that the fixes would have the above commit right?

If this looks okay I'll send a revision with this above tags:

Fixes e94af02a9cd7 ("[XFS] fix old xfs_setattr mis-merge from irix; mostly harmless esp if not using xfs rt")

Thanks,
Ojaswin

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
fs/xfs/xfs_ioctl.c +0 -0
 	    XFS_FSB_TO_B(mp, ip->i_extsize) != fa->fsx_extsize)
 		return -EINVAL;
 
Signature · 1 line
2.43.5
#7 lore raw
Quoted 109 lines · Ojaswin Mujoo
Quoted 25 lines · Darrick J. Wong
Quoted 24 lines · Darrick J. Wong
Quoted 23 lines · Ojaswin Mujoo

Extsize is allowed to be set on files with no data in it. For this, we were checking if the files have extents but missed to check if delayed extents were present. This patch adds that check.

While we are at it, also refactor this check into a helper since its used in some other places as well like xfs_inactive() or xfs_ioctl_setattr_xflags()

**Without the patch (SUCCEEDS)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)

**With the patch (FAILS as expected)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)
xfs_io: FS_IOC_FSSETXATTR testfile: Invalid argument

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Looks good now,

That said, could you add a fixes tag for the xfs_ioctl_setattr_* changes, please?

Actually a small doubt Darrick regarding the Fixes commit (asked inline below):

Quoted 52 lines

--D

Quoted 49 lines

--D

Quoted 47 lines
---
 fs/xfs/xfs_inode.c | 2 +-
 fs/xfs/xfs_inode.h | 5 +++++
 fs/xfs/xfs_ioctl.c | 4 ++--
 3 files changed, 8 insertions(+), 3 deletions(-)
fs/xfs/xfs_inode.c +1 -1
index bcc277fc0a83..19dcb569a3e7 100644
@@ -1409,7 +1409,7 @@ xfs_inactive(
 
 	if (S_ISREG(VFS_I(ip)->i_mode) &&
 	    (ip->i_disk_size != 0 || XFS_ISIZE(ip) != 0 ||
-	     ip->i_df.if_nextents > 0 || ip->i_delayed_blks > 0))
+	     xfs_inode_has_filedata(ip)))
 		truncate = 1;
 
 	if (xfs_iflags_test(ip, XFS_IQUOTAUNCHECKED)) {
fs/xfs/xfs_inode.h +5 -0
index 97ed912306fd..03944b6c5fba 100644
@@ -292,6 +292,11 @@ static inline bool xfs_is_cow_inode(struct xfs_inode *ip)
 	return xfs_is_reflink_inode(ip) || xfs_is_always_cow_inode(ip);
 }
 
+static inline bool xfs_inode_has_filedata(const struct xfs_inode *ip)
+{
+	return ip->i_df.if_nextents > 0 || ip->i_delayed_blks > 0;
+}
+
 /*
  * Check if an inode has any data in the COW fork.  This might be often false
  * even for inodes with the reflink flag when there is no pending COW operation.
fs/xfs/xfs_ioctl.c +1 -1
index a20d426ef021..2567fd2a0994 100644
@@ -481,7 +481,7 @@ xfs_ioctl_setattr_xflags(
 
 	if (rtflag != XFS_IS_REALTIME_INODE(ip)) {
 		/* Can't change realtime flag if any extents are allocated. */
-		if (ip->i_df.if_nextents || ip->i_delayed_blks)
+		if (xfs_inode_has_filedata(ip))
 			return -EINVAL;
 
Quoted 7 lines
Quoted 7 lines

fs/xfs/xfs_ioctl.c xfs_ioctl_setattr_check_extsize( · line 605

Quoted 7 lines
fs/xfs/xfs_ioctl.c +1 -1
 		/*
@@ -602,7 +602,7 @@ xfs_ioctl_setattr_check_extsize(
 	if (!fa->fsx_valid)
 		return 0;
 
-	if (S_ISREG(VFS_I(ip)->i_mode) && ip->i_df.if_nextents &&
+	if (S_ISREG(VFS_I(ip)->i_mode) && xfs_inode_has_filedata(ip) &&

So seems like there have been lots of changes to this particular line mostly as a part of refactoring other areas but seems like the actual commit that introduced it was:

commit e94af02a9cd7b6590bec81df9d6ab857d6cf322f
Author: Eric Sandeen <[email protected]>
Date: Wed Nov 2 15:10:41 2005 +1100

[XFS] fix old xfs_setattr mis-merge from irix; mostly harmless esp if not using xfs rt

Quoted 6 lines

Before this we were actually checking ip->i_delayed_blks correctly. So just wanted to confirm that the fixes would have the above commit right?

If this looks okay I'll send a revision with this above tags:

Fixes e94af02a9cd7 ("[XFS] fix old xfs_setattr mis-merge from irix; mostly harmless esp if not using xfs rt")

Yeah, that sounds fine. Want to write a quick fstest to bang on xfs_ioctl_setattr_check_extsize to force everyone to backport it? :)

--D

Quoted 12 lines

Thanks,
Ojaswin

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
fs/xfs/xfs_ioctl.c +0 -0
 	    XFS_FSB_TO_B(mp, ip->i_extsize) != fa->fsx_extsize)
 		return -EINVAL;
 
Signature · 1 line
2.43.5
#8 lore raw
Quoted 113 lines · Darrick J. Wong
Quoted 112 lines · Ojaswin Mujoo
Quoted 25 lines · Darrick J. Wong
Quoted 24 lines · Darrick J. Wong
Quoted 23 lines · Ojaswin Mujoo

Extsize is allowed to be set on files with no data in it. For this, we were checking if the files have extents but missed to check if delayed extents were present. This patch adds that check.

While we are at it, also refactor this check into a helper since its used in some other places as well like xfs_inactive() or xfs_ioctl_setattr_xflags()

**Without the patch (SUCCEEDS)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)

**With the patch (FAILS as expected)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)
xfs_io: FS_IOC_FSSETXATTR testfile: Invalid argument

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Looks good now,

That said, could you add a fixes tag for the xfs_ioctl_setattr_* changes, please?

Actually a small doubt Darrick regarding the Fixes commit (asked inline below):

Quoted 52 lines

--D

Quoted 49 lines

--D

Quoted 47 lines
---
 fs/xfs/xfs_inode.c | 2 +-
 fs/xfs/xfs_inode.h | 5 +++++
 fs/xfs/xfs_ioctl.c | 4 ++--
 3 files changed, 8 insertions(+), 3 deletions(-)
fs/xfs/xfs_inode.c +1 -1
index bcc277fc0a83..19dcb569a3e7 100644
@@ -1409,7 +1409,7 @@ xfs_inactive(
 
 	if (S_ISREG(VFS_I(ip)->i_mode) &&
 	    (ip->i_disk_size != 0 || XFS_ISIZE(ip) != 0 ||
-	     ip->i_df.if_nextents > 0 || ip->i_delayed_blks > 0))
+	     xfs_inode_has_filedata(ip)))
 		truncate = 1;
 
 	if (xfs_iflags_test(ip, XFS_IQUOTAUNCHECKED)) {
fs/xfs/xfs_inode.h +5 -0
index 97ed912306fd..03944b6c5fba 100644
@@ -292,6 +292,11 @@ static inline bool xfs_is_cow_inode(struct xfs_inode *ip)
 	return xfs_is_reflink_inode(ip) || xfs_is_always_cow_inode(ip);
 }
 
+static inline bool xfs_inode_has_filedata(const struct xfs_inode *ip)
+{
+	return ip->i_df.if_nextents > 0 || ip->i_delayed_blks > 0;
+}
+
 /*
  * Check if an inode has any data in the COW fork.  This might be often false
  * even for inodes with the reflink flag when there is no pending COW operation.
fs/xfs/xfs_ioctl.c +1 -1
index a20d426ef021..2567fd2a0994 100644
@@ -481,7 +481,7 @@ xfs_ioctl_setattr_xflags(
 
 	if (rtflag != XFS_IS_REALTIME_INODE(ip)) {
 		/* Can't change realtime flag if any extents are allocated. */
-		if (ip->i_df.if_nextents || ip->i_delayed_blks)
+		if (xfs_inode_has_filedata(ip))
 			return -EINVAL;
 
Quoted 7 lines
Quoted 7 lines

fs/xfs/xfs_ioctl.c xfs_ioctl_setattr_check_extsize( · line 605

Quoted 7 lines
fs/xfs/xfs_ioctl.c +1 -1
 		/*
@@ -602,7 +602,7 @@ xfs_ioctl_setattr_check_extsize(
 	if (!fa->fsx_valid)
 		return 0;
 
-	if (S_ISREG(VFS_I(ip)->i_mode) && ip->i_df.if_nextents &&
+	if (S_ISREG(VFS_I(ip)->i_mode) && xfs_inode_has_filedata(ip) &&

So seems like there have been lots of changes to this particular line mostly as a part of refactoring other areas but seems like the actual commit that introduced it was:

commit e94af02a9cd7b6590bec81df9d6ab857d6cf322f
Author: Eric Sandeen <[email protected]>
Date: Wed Nov 2 15:10:41 2005 +1100

[XFS] fix old xfs_setattr mis-merge from irix; mostly harmless esp if not using xfs rt

Before this we were actually checking ip->i_delayed_blks correctly. So just wanted to confirm that the fixes would have the above commit right?

Quoted 6 lines
Quoted 3 lines

If this looks okay I'll send a revision with this above tags:

Fixes e94af02a9cd7 ("[XFS] fix old xfs_setattr mis-merge from irix; mostly harmless esp if not using xfs rt")

Yeah, that sounds fine. Want to write a quick fstest to bang on xfs_ioctl_setattr_check_extsize to force everyone to backport it? :)

Got it, thanks, I'll send a v4.

Regarding the tests, we were thinking of adding more comprehensive generic tests for extsize now that ext4 is also implementing it. We have a new team member Nirjhar (cc'd) who is interested in writing the xfstest and is working on it as we speak.

Since the area is new to him, it might take a bit of time to get that out, hope that is okay?

Regards,
Ojaswin

Quoted 15 lines

--D

Quoted 12 lines

Thanks,
Ojaswin

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
fs/xfs/xfs_ioctl.c +0 -0
 	    XFS_FSB_TO_B(mp, ip->i_extsize) != fa->fsx_extsize)
 		return -EINVAL;
 
Signature · 1 line
2.43.5
#9 lore raw
Quoted 121 lines · Ojaswin Mujoo
Quoted 113 lines · Darrick J. Wong
Quoted 112 lines · Ojaswin Mujoo
Quoted 25 lines · Darrick J. Wong
Quoted 24 lines · Darrick J. Wong
Quoted 23 lines · Ojaswin Mujoo

Extsize is allowed to be set on files with no data in it. For this, we were checking if the files have extents but missed to check if delayed extents were present. This patch adds that check.

While we are at it, also refactor this check into a helper since its used in some other places as well like xfs_inactive() or xfs_ioctl_setattr_xflags()

**Without the patch (SUCCEEDS)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)

**With the patch (FAILS as expected)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)
xfs_io: FS_IOC_FSSETXATTR testfile: Invalid argument

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Looks good now,

That said, could you add a fixes tag for the xfs_ioctl_setattr_* changes, please?

Actually a small doubt Darrick regarding the Fixes commit (asked inline below):

Quoted 52 lines

--D

Quoted 49 lines

--D

Quoted 47 lines
---
 fs/xfs/xfs_inode.c | 2 +-
 fs/xfs/xfs_inode.h | 5 +++++
 fs/xfs/xfs_ioctl.c | 4 ++--
 3 files changed, 8 insertions(+), 3 deletions(-)
fs/xfs/xfs_inode.c +1 -1
index bcc277fc0a83..19dcb569a3e7 100644
@@ -1409,7 +1409,7 @@ xfs_inactive(
 
 	if (S_ISREG(VFS_I(ip)->i_mode) &&
 	    (ip->i_disk_size != 0 || XFS_ISIZE(ip) != 0 ||
-	     ip->i_df.if_nextents > 0 || ip->i_delayed_blks > 0))
+	     xfs_inode_has_filedata(ip)))
 		truncate = 1;
 
 	if (xfs_iflags_test(ip, XFS_IQUOTAUNCHECKED)) {
fs/xfs/xfs_inode.h +5 -0
index 97ed912306fd..03944b6c5fba 100644
@@ -292,6 +292,11 @@ static inline bool xfs_is_cow_inode(struct xfs_inode *ip)
 	return xfs_is_reflink_inode(ip) || xfs_is_always_cow_inode(ip);
 }
 
+static inline bool xfs_inode_has_filedata(const struct xfs_inode *ip)
+{
+	return ip->i_df.if_nextents > 0 || ip->i_delayed_blks > 0;
+}
+
 /*
  * Check if an inode has any data in the COW fork.  This might be often false
  * even for inodes with the reflink flag when there is no pending COW operation.
fs/xfs/xfs_ioctl.c +1 -1
index a20d426ef021..2567fd2a0994 100644
@@ -481,7 +481,7 @@ xfs_ioctl_setattr_xflags(
 
 	if (rtflag != XFS_IS_REALTIME_INODE(ip)) {
 		/* Can't change realtime flag if any extents are allocated. */
-		if (ip->i_df.if_nextents || ip->i_delayed_blks)
+		if (xfs_inode_has_filedata(ip))
 			return -EINVAL;
 
Quoted 7 lines
Quoted 7 lines

fs/xfs/xfs_ioctl.c xfs_ioctl_setattr_check_extsize( · line 605

Quoted 7 lines
fs/xfs/xfs_ioctl.c +1 -1
 		/*
@@ -602,7 +602,7 @@ xfs_ioctl_setattr_check_extsize(
 	if (!fa->fsx_valid)
 		return 0;
 
-	if (S_ISREG(VFS_I(ip)->i_mode) && ip->i_df.if_nextents &&
+	if (S_ISREG(VFS_I(ip)->i_mode) && xfs_inode_has_filedata(ip) &&

So seems like there have been lots of changes to this particular line mostly as a part of refactoring other areas but seems like the actual commit that introduced it was:

commit e94af02a9cd7b6590bec81df9d6ab857d6cf322f
Author: Eric Sandeen <[email protected]>
Date: Wed Nov 2 15:10:41 2005 +1100

[XFS] fix old xfs_setattr mis-merge from irix; mostly harmless esp if not using xfs rt

Before this we were actually checking ip->i_delayed_blks correctly. So just wanted to confirm that the fixes would have the above commit right?

Quoted 6 lines
Quoted 3 lines

If this looks okay I'll send a revision with this above tags:

Fixes e94af02a9cd7 ("[XFS] fix old xfs_setattr mis-merge from irix; mostly harmless esp if not using xfs rt")

Yeah, that sounds fine. Want to write a quick fstest to bang on xfs_ioctl_setattr_check_extsize to force everyone to backport it? :)

Quoted 6 lines

Got it, thanks, I'll send a v4.

Regarding the tests, we were thinking of adding more comprehensive generic tests for extsize now that ext4 is also implementing it. We have a new team member Nirjhar (cc'd) who is interested in writing the xfstest and is working on it as we speak.

Heh, welcome! :)

Quoted 2 lines

Since the area is new to him, it might take a bit of time to get that out, hope that is okay?

Sounds good to me. You might see how many of the tests/xfs/ stuff can be pulled up to tests/generic/ as a starting point.

--D

Quoted 19 lines

Regards,
Ojaswin

Quoted 15 lines

--D

Quoted 12 lines

Thanks,
Ojaswin

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
fs/xfs/xfs_ioctl.c +0 -0
 	    XFS_FSB_TO_B(mp, ip->i_extsize) != fa->fsx_extsize)
 		return -EINVAL;
 
Signature · 1 line
2.43.5
#10 lore raw
Quoted 129 lines · Darrick J. Wong
Quoted 121 lines · Ojaswin Mujoo
Quoted 113 lines · Darrick J. Wong
Quoted 112 lines · Ojaswin Mujoo
Quoted 25 lines · Darrick J. Wong
Quoted 24 lines · Darrick J. Wong
Quoted 23 lines · Ojaswin Mujoo

Extsize is allowed to be set on files with no data in it. For this, we were checking if the files have extents but missed to check if delayed extents were present. This patch adds that check.

While we are at it, also refactor this check into a helper since its used in some other places as well like xfs_inactive() or xfs_ioctl_setattr_xflags()

**Without the patch (SUCCEEDS)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)

**With the patch (FAILS as expected)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)
xfs_io: FS_IOC_FSSETXATTR testfile: Invalid argument

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Looks good now,

That said, could you add a fixes tag for the xfs_ioctl_setattr_* changes, please?

Actually a small doubt Darrick regarding the Fixes commit (asked inline below):

Quoted 52 lines

--D

Quoted 49 lines

--D

Quoted 47 lines
---
 fs/xfs/xfs_inode.c | 2 +-
 fs/xfs/xfs_inode.h | 5 +++++
 fs/xfs/xfs_ioctl.c | 4 ++--
 3 files changed, 8 insertions(+), 3 deletions(-)
fs/xfs/xfs_inode.c +1 -1
index bcc277fc0a83..19dcb569a3e7 100644
@@ -1409,7 +1409,7 @@ xfs_inactive(
 
 	if (S_ISREG(VFS_I(ip)->i_mode) &&
 	    (ip->i_disk_size != 0 || XFS_ISIZE(ip) != 0 ||
-	     ip->i_df.if_nextents > 0 || ip->i_delayed_blks > 0))
+	     xfs_inode_has_filedata(ip)))
 		truncate = 1;
 
 	if (xfs_iflags_test(ip, XFS_IQUOTAUNCHECKED)) {
fs/xfs/xfs_inode.h +5 -0
index 97ed912306fd..03944b6c5fba 100644
@@ -292,6 +292,11 @@ static inline bool xfs_is_cow_inode(struct xfs_inode *ip)
 	return xfs_is_reflink_inode(ip) || xfs_is_always_cow_inode(ip);
 }
 
+static inline bool xfs_inode_has_filedata(const struct xfs_inode *ip)
+{
+	return ip->i_df.if_nextents > 0 || ip->i_delayed_blks > 0;
+}
+
 /*
  * Check if an inode has any data in the COW fork.  This might be often false
  * even for inodes with the reflink flag when there is no pending COW operation.
fs/xfs/xfs_ioctl.c +1 -1
index a20d426ef021..2567fd2a0994 100644
@@ -481,7 +481,7 @@ xfs_ioctl_setattr_xflags(
 
 	if (rtflag != XFS_IS_REALTIME_INODE(ip)) {
 		/* Can't change realtime flag if any extents are allocated. */
-		if (ip->i_df.if_nextents || ip->i_delayed_blks)
+		if (xfs_inode_has_filedata(ip))
 			return -EINVAL;
 
Quoted 7 lines
Quoted 7 lines

fs/xfs/xfs_ioctl.c xfs_ioctl_setattr_check_extsize( · line 605

Quoted 7 lines
fs/xfs/xfs_ioctl.c +1 -1
 		/*
@@ -602,7 +602,7 @@ xfs_ioctl_setattr_check_extsize(
 	if (!fa->fsx_valid)
 		return 0;
 
-	if (S_ISREG(VFS_I(ip)->i_mode) && ip->i_df.if_nextents &&
+	if (S_ISREG(VFS_I(ip)->i_mode) && xfs_inode_has_filedata(ip) &&

So seems like there have been lots of changes to this particular line mostly as a part of refactoring other areas but seems like the actual commit that introduced it was:

commit e94af02a9cd7b6590bec81df9d6ab857d6cf322f
Author: Eric Sandeen <[email protected]>
Date: Wed Nov 2 15:10:41 2005 +1100

[XFS] fix old xfs_setattr mis-merge from irix; mostly harmless esp if not using xfs rt

Before this we were actually checking ip->i_delayed_blks correctly. So just wanted to confirm that the fixes would have the above commit right?

Quoted 6 lines
Quoted 3 lines

If this looks okay I'll send a revision with this above tags:

Fixes e94af02a9cd7 ("[XFS] fix old xfs_setattr mis-merge from irix; mostly harmless esp if not using xfs rt")

Yeah, that sounds fine. Want to write a quick fstest to bang on xfs_ioctl_setattr_check_extsize to force everyone to backport it? :)

Quoted 6 lines

Got it, thanks, I'll send a v4.

Regarding the tests, we were thinking of adding more comprehensive generic tests for extsize now that ext4 is also implementing it. We have a new team member Nirjhar (cc'd) who is interested in writing the xfstest and is working on it as we speak.

Quoted 7 lines

Heh, welcome! :)

Quoted 2 lines

Since the area is new to him, it might take a bit of time to get that out, hope that is okay?

Sounds good to me. You might see how many of the tests/xfs/ stuff can be pulled up to tests/generic/ as a starting point.

Sure Darrick, I believe you mean how many of the extsize related tests we can pull up right?

So I was checking this and I could find some relevant tests:

* Looking into existing tests around extsize:
* xfs/074
* Check some extent size hint boundary conditions that can result in MAXEXTLEN overflows.
* This looks specific to xfs however

* xfs/208
* Testing interactinon b/w cowextsize and extsize but again seems xfs specific

* xfs/207
* basic test on setting and getting (cow)extsize on file with data or empty
* This is a subset of the features we are testing with our test, but only for extsize not cowextsize.
* So we can probably remove the equivalent tests from here when we add the generic one.

* xfs/419
* These are related to extsize inherit feature but with rtinherit.
* The current patchset in ext4 doesn't implement this extszinherit but it might be something we might want to do in the future
* We can look into hoisting the extszinherit related tests at some point

* The other ones I looked into around extsize again seemed to be specific to xfx but maybe i missed something.

Are there any other tests you had in mind Darrick?

Regards,
ojaswin

Quoted 22 lines

--D

Quoted 19 lines

Regards,
Ojaswin

Quoted 15 lines

--D

Quoted 12 lines

Thanks,
Ojaswin

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
fs/xfs/xfs_ioctl.c +0 -0
 	    XFS_FSB_TO_B(mp, ip->i_extsize) != fa->fsx_extsize)
 		return -EINVAL;
 
Signature · 1 line
2.43.5
#11 lore raw
Quoted 165 lines · Ojaswin Mujoo
Quoted 129 lines · Darrick J. Wong
Quoted 121 lines · Ojaswin Mujoo
Quoted 113 lines · Darrick J. Wong
Quoted 112 lines · Ojaswin Mujoo
Quoted 25 lines · Darrick J. Wong
Quoted 24 lines · Darrick J. Wong
Quoted 23 lines · Ojaswin Mujoo

Extsize is allowed to be set on files with no data in it. For this, we were checking if the files have extents but missed to check if delayed extents were present. This patch adds that check.

While we are at it, also refactor this check into a helper since its used in some other places as well like xfs_inactive() or xfs_ioctl_setattr_xflags()

**Without the patch (SUCCEEDS)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)

**With the patch (FAILS as expected)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)
xfs_io: FS_IOC_FSSETXATTR testfile: Invalid argument

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Looks good now,

That said, could you add a fixes tag for the xfs_ioctl_setattr_* changes, please?

Actually a small doubt Darrick regarding the Fixes commit (asked inline below):

Quoted 52 lines

--D

Quoted 49 lines

--D

Quoted 47 lines
---
 fs/xfs/xfs_inode.c | 2 +-
 fs/xfs/xfs_inode.h | 5 +++++
 fs/xfs/xfs_ioctl.c | 4 ++--
 3 files changed, 8 insertions(+), 3 deletions(-)
fs/xfs/xfs_inode.c +1 -1
index bcc277fc0a83..19dcb569a3e7 100644
@@ -1409,7 +1409,7 @@ xfs_inactive(
 
 	if (S_ISREG(VFS_I(ip)->i_mode) &&
 	    (ip->i_disk_size != 0 || XFS_ISIZE(ip) != 0 ||
-	     ip->i_df.if_nextents > 0 || ip->i_delayed_blks > 0))
+	     xfs_inode_has_filedata(ip)))
 		truncate = 1;
 
 	if (xfs_iflags_test(ip, XFS_IQUOTAUNCHECKED)) {
fs/xfs/xfs_inode.h +5 -0
index 97ed912306fd..03944b6c5fba 100644
@@ -292,6 +292,11 @@ static inline bool xfs_is_cow_inode(struct xfs_inode *ip)
 	return xfs_is_reflink_inode(ip) || xfs_is_always_cow_inode(ip);
 }
 
+static inline bool xfs_inode_has_filedata(const struct xfs_inode *ip)
+{
+	return ip->i_df.if_nextents > 0 || ip->i_delayed_blks > 0;
+}
+
 /*
  * Check if an inode has any data in the COW fork.  This might be often false
  * even for inodes with the reflink flag when there is no pending COW operation.
fs/xfs/xfs_ioctl.c +1 -1
index a20d426ef021..2567fd2a0994 100644
@@ -481,7 +481,7 @@ xfs_ioctl_setattr_xflags(
 
 	if (rtflag != XFS_IS_REALTIME_INODE(ip)) {
 		/* Can't change realtime flag if any extents are allocated. */
-		if (ip->i_df.if_nextents || ip->i_delayed_blks)
+		if (xfs_inode_has_filedata(ip))
 			return -EINVAL;
 
Quoted 7 lines
Quoted 7 lines

fs/xfs/xfs_ioctl.c xfs_ioctl_setattr_check_extsize( · line 605

Quoted 7 lines
fs/xfs/xfs_ioctl.c +1 -1
 		/*
@@ -602,7 +602,7 @@ xfs_ioctl_setattr_check_extsize(
 	if (!fa->fsx_valid)
 		return 0;
 
-	if (S_ISREG(VFS_I(ip)->i_mode) && ip->i_df.if_nextents &&
+	if (S_ISREG(VFS_I(ip)->i_mode) && xfs_inode_has_filedata(ip) &&

So seems like there have been lots of changes to this particular line mostly as a part of refactoring other areas but seems like the actual commit that introduced it was:

commit e94af02a9cd7b6590bec81df9d6ab857d6cf322f
Author: Eric Sandeen <[email protected]>
Date: Wed Nov 2 15:10:41 2005 +1100

[XFS] fix old xfs_setattr mis-merge from irix; mostly harmless esp if not using xfs rt

Before this we were actually checking ip->i_delayed_blks correctly. So just wanted to confirm that the fixes would have the above commit right?

Quoted 6 lines
Quoted 3 lines

If this looks okay I'll send a revision with this above tags:

Fixes e94af02a9cd7 ("[XFS] fix old xfs_setattr mis-merge from irix; mostly harmless esp if not using xfs rt")

Yeah, that sounds fine. Want to write a quick fstest to bang on xfs_ioctl_setattr_check_extsize to force everyone to backport it? :)

Quoted 6 lines

Got it, thanks, I'll send a v4.

Regarding the tests, we were thinking of adding more comprehensive generic tests for extsize now that ext4 is also implementing it. We have a new team member Nirjhar (cc'd) who is interested in writing the xfstest and is working on it as we speak.

Quoted 7 lines

Heh, welcome! :)

Quoted 2 lines

Since the area is new to him, it might take a bit of time to get that out, hope that is okay?

Sounds good to me. You might see how many of the tests/xfs/ stuff can be pulled up to tests/generic/ as a starting point.

Sure Darrick, I believe you mean how many of the extsize related tests we can pull up right?

So I was checking this and I could find some relevant tests:

* Looking into existing tests around extsize:
* xfs/074
* Check some extent size hint boundary conditions that can result in MAXEXTLEN overflows.
* This looks specific to xfs however

* xfs/208
* Testing interactinon b/w cowextsize and extsize but again seems xfs specific

* xfs/207
* basic test on setting and getting (cow)extsize on file with data or empty
* This is a subset of the features we are testing with our test, but only for extsize not cowextsize.
* So we can probably remove the equivalent tests from here when we add the generic one.

* xfs/419
* These are related to extsize inherit feature but with rtinherit.
* The current patchset in ext4 doesn't implement this extszinherit but it might be something we might want to do in the future
* We can look into hoisting the extszinherit related tests at some point

Quoted 4 lines

* The other ones I looked into around extsize again seemed to be specific to xfx but maybe i missed something.

Are there any other tests you had in mind Darrick?

Not really. Most of my testing comes from setting up an entire vm config with extszinherit=X in the MKFS_OPTIONS. I wonder if we need a single generic test to kick the tires on the functionality just to make sure that everyone runs it even if they only do an all-defaults testrun?

--D

Quoted 26 lines

Regards,
ojaswin

Quoted 22 lines

--D

Quoted 19 lines

Regards,
Ojaswin

Quoted 15 lines

--D

Quoted 12 lines

Thanks,
Ojaswin

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
fs/xfs/xfs_ioctl.c +0 -0
 	    XFS_FSB_TO_B(mp, ip->i_extsize) != fa->fsx_extsize)
 		return -EINVAL;
 
Signature · 1 line
2.43.5
#12 lore raw
Quoted 169 lines · Darrick J. Wong
Quoted 168 lines · Ojaswin Mujoo
Quoted 129 lines · Darrick J. Wong
Quoted 121 lines · Ojaswin Mujoo
Quoted 113 lines · Darrick J. Wong
Quoted 112 lines · Ojaswin Mujoo
Quoted 25 lines · Darrick J. Wong
Quoted 24 lines · Darrick J. Wong
Quoted 23 lines · Ojaswin Mujoo

Extsize is allowed to be set on files with no data in it. For this, we were checking if the files have extents but missed to check if delayed extents were present. This patch adds that check.

While we are at it, also refactor this check into a helper since its used in some other places as well like xfs_inactive() or xfs_ioctl_setattr_xflags()

**Without the patch (SUCCEEDS)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)

**With the patch (FAILS as expected)**

$ xfs_io -c 'open -f testfile' -c 'pwrite 0 1024' -c 'extsize 65536'

wrote 1024/1024 bytes at offset 0
1 KiB, 1 ops; 0.0002 sec (4.628 MiB/sec and 4739.3365 ops/sec)
xfs_io: FS_IOC_FSSETXATTR testfile: Invalid argument

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Looks good now,

That said, could you add a fixes tag for the xfs_ioctl_setattr_* changes, please?

Actually a small doubt Darrick regarding the Fixes commit (asked inline below):

Quoted 52 lines

--D

Quoted 49 lines

--D

Quoted 47 lines
---
 fs/xfs/xfs_inode.c | 2 +-
 fs/xfs/xfs_inode.h | 5 +++++
 fs/xfs/xfs_ioctl.c | 4 ++--
 3 files changed, 8 insertions(+), 3 deletions(-)
fs/xfs/xfs_inode.c +1 -1
index bcc277fc0a83..19dcb569a3e7 100644
@@ -1409,7 +1409,7 @@ xfs_inactive(
 
 	if (S_ISREG(VFS_I(ip)->i_mode) &&
 	    (ip->i_disk_size != 0 || XFS_ISIZE(ip) != 0 ||
-	     ip->i_df.if_nextents > 0 || ip->i_delayed_blks > 0))
+	     xfs_inode_has_filedata(ip)))
 		truncate = 1;
 
 	if (xfs_iflags_test(ip, XFS_IQUOTAUNCHECKED)) {
fs/xfs/xfs_inode.h +5 -0
index 97ed912306fd..03944b6c5fba 100644
@@ -292,6 +292,11 @@ static inline bool xfs_is_cow_inode(struct xfs_inode *ip)
 	return xfs_is_reflink_inode(ip) || xfs_is_always_cow_inode(ip);
 }
 
+static inline bool xfs_inode_has_filedata(const struct xfs_inode *ip)
+{
+	return ip->i_df.if_nextents > 0 || ip->i_delayed_blks > 0;
+}
+
 /*
  * Check if an inode has any data in the COW fork.  This might be often false
  * even for inodes with the reflink flag when there is no pending COW operation.
fs/xfs/xfs_ioctl.c +1 -1
index a20d426ef021..2567fd2a0994 100644
@@ -481,7 +481,7 @@ xfs_ioctl_setattr_xflags(
 
 	if (rtflag != XFS_IS_REALTIME_INODE(ip)) {
 		/* Can't change realtime flag if any extents are allocated. */
-		if (ip->i_df.if_nextents || ip->i_delayed_blks)
+		if (xfs_inode_has_filedata(ip))
 			return -EINVAL;
 
Quoted 7 lines
Quoted 7 lines

fs/xfs/xfs_ioctl.c xfs_ioctl_setattr_check_extsize( · line 605

Quoted 7 lines
fs/xfs/xfs_ioctl.c +1 -1
 		/*
@@ -602,7 +602,7 @@ xfs_ioctl_setattr_check_extsize(
 	if (!fa->fsx_valid)
 		return 0;
 
-	if (S_ISREG(VFS_I(ip)->i_mode) && ip->i_df.if_nextents &&
+	if (S_ISREG(VFS_I(ip)->i_mode) && xfs_inode_has_filedata(ip) &&

So seems like there have been lots of changes to this particular line mostly as a part of refactoring other areas but seems like the actual commit that introduced it was:

commit e94af02a9cd7b6590bec81df9d6ab857d6cf322f
Author: Eric Sandeen <[email protected]>
Date: Wed Nov 2 15:10:41 2005 +1100

[XFS] fix old xfs_setattr mis-merge from irix; mostly harmless esp if not using xfs rt

Before this we were actually checking ip->i_delayed_blks correctly. So just wanted to confirm that the fixes would have the above commit right?

Quoted 6 lines
Quoted 3 lines

If this looks okay I'll send a revision with this above tags:

Fixes e94af02a9cd7 ("[XFS] fix old xfs_setattr mis-merge from irix; mostly harmless esp if not using xfs rt")

Yeah, that sounds fine. Want to write a quick fstest to bang on xfs_ioctl_setattr_check_extsize to force everyone to backport it? :)

Quoted 6 lines

Got it, thanks, I'll send a v4.

Regarding the tests, we were thinking of adding more comprehensive generic tests for extsize now that ext4 is also implementing it. We have a new team member Nirjhar (cc'd) who is interested in writing the xfstest and is working on it as we speak.

Quoted 7 lines

Heh, welcome! :)

Quoted 2 lines

Since the area is new to him, it might take a bit of time to get that out, hope that is okay?

Sounds good to me. You might see how many of the tests/xfs/ stuff can be pulled up to tests/generic/ as a starting point.

Sure Darrick, I believe you mean how many of the extsize related tests we can pull up right?

So I was checking this and I could find some relevant tests:

* Looking into existing tests around extsize:
* xfs/074
* Check some extent size hint boundary conditions that can result in MAXEXTLEN overflows.
* This looks specific to xfs however

* xfs/208
* Testing interactinon b/w cowextsize and extsize but again seems xfs specific

* xfs/207
* basic test on setting and getting (cow)extsize on file with data or empty
* This is a subset of the features we are testing with our test, but only for extsize not cowextsize.
* So we can probably remove the equivalent tests from here when we add the generic one.

* xfs/419
* These are related to extsize inherit feature but with rtinherit.
* The current patchset in ext4 doesn't implement this extszinherit but it might be something we might want to do in the future
* We can look into hoisting the extszinherit related tests at some point

* The other ones I looked into around extsize again seemed to be specific to xfx but maybe i missed something.

Quoted 6 lines
Quoted 1 line

Are there any other tests you had in mind Darrick?

Not really. Most of my testing comes from setting up an entire vm config with extszinherit=X in the MKFS_OPTIONS. I wonder if we need a single generic test to kick the tires on the functionality just to make sure that everyone runs it even if they only do an all-defaults testrun?

Got it Darrick, thanks for the inputs.

Sure we can look into adding/enhancing tests for extsizeinherit in mkfs as well as setting using xfs_io.

Regards,
ojaswin

Quoted 29 lines

--D

Quoted 26 lines

Regards,
ojaswin

Quoted 22 lines

--D

Quoted 19 lines

Regards,
Ojaswin

Quoted 15 lines

--D

Quoted 12 lines

Thanks,
Ojaswin

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
fs/xfs/xfs_ioctl.c +0 -0
 	    XFS_FSB_TO_B(mp, ip->i_extsize) != fa->fsx_extsize)
 		return -EINVAL;
 
Signature · 1 line
2.43.5