Skip to contentSkip to conversation

: xfs - fixes found with sparse checking

PATCH In review Dave Chinner 3 participants 11 messages Dec 21, 2011 – Feb 1, 2012 XFS filesystem

lore
Share & tools
lore
#0 lore raw

cover : xfs - fixes found with sparse checking

There are a few minor issues. The first patch are all really just cleanups that don't change functionality. The second patch fixes a real bug that we need to consider backporting to stable releases.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#6 lore raw

PATCH 2/2 xfs: fix endian conversion issue in discard code

From: Dave Chinner <[email protected]>

When finding the longest extent in an AG, we read the value directly out of the AGF buffer without endian conversion. This will give an incorrect length, resulting in FITRIM operations potentially not trimming everything that it should.

---
 fs/xfs/xfs_discard.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
fs/xfs/xfs_discard.c +2 -2
index 8a24f0c..286a051 100644
@@ -68,7 +68,7 @@ xfs_trim_extents(
 	 * Look up the longest btree in the AGF and start with it.
 	 */
 	error = xfs_alloc_lookup_le(cur, 0,
-				    XFS_BUF_TO_AGF(agbp)->agf_longest, &i);
+			    be32_to_cpu(XFS_BUF_TO_AGF(agbp)->agf_longest), &i);
 	if (error)
 		goto out_del_cursor;
 
@@ -84,7 +84,7 @@ xfs_trim_extents(
 		if (error)
 			goto out_del_cursor;
 		XFS_WANT_CORRUPTED_GOTO(i == 1, out_del_cursor);
-		ASSERT(flen <= XFS_BUF_TO_AGF(agbp)->agf_longest);
+		ASSERT(flen <= be32_to_cpu(XFS_BUF_TO_AGF(agbp)->agf_longest));
 
 		/*
 		 * Too small?  Give up.
Signature · 6 lines
1.7.5.4

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#1 lore raw

PATCH 1/2 xfs: clean up minor sparse warnings

In reply to Dave Chinner

From: Dave Chinner <[email protected]>

---
 fs/xfs/xfs_dir2_block.c |    1 +
 fs/xfs/xfs_ioctl.c      |   10 ++++------
 fs/xfs/xfs_ioctl32.c    |    2 +-
 fs/xfs/xfs_iops.c       |   13 ++++++++-----
 4 files changed, 14 insertions(+), 12 deletions(-)
fs/xfs/xfs_dir2_block.c +1 -0
index 9245e02..d3b63ae 100644
@@ -29,6 +29,7 @@
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_inode_item.h"
+#include "xfs_dir2.h"
 #include "xfs_dir2_format.h"
 #include "xfs_dir2_priv.h"
 #include "xfs_error.h"
fs/xfs/xfs_ioctl.c +4 -6
index d99a905..2f3f56a 100644
@@ -230,24 +230,22 @@ xfs_open_by_handle(
 
 	/* Put open permission in namei format. */
 	permflag = hreq->oflags;
-	if ((permflag+1) & O_ACCMODE)
-		permflag++;
 	if (permflag & O_TRUNC)
-		permflag |= 2;
+		permflag |= O_RDWR;
 
 	if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) &&
-	    (permflag & FMODE_WRITE) && IS_APPEND(inode)) {
+	    (OPEN_FMODE(permflag) & FMODE_WRITE) && IS_APPEND(inode)) {
 		error = -XFS_ERROR(EPERM);
 		goto out_dput;
 	}
 
-	if ((permflag & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
+	if ((OPEN_FMODE(permflag) & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
 		error = -XFS_ERROR(EACCES);
 		goto out_dput;
 	}
 
 	/* Can't write directories. */
-	if (S_ISDIR(inode->i_mode) && (permflag & FMODE_WRITE)) {
+	if (S_ISDIR(inode->i_mode) && (OPEN_FMODE(permflag) & FMODE_WRITE)) {
 		error = -XFS_ERROR(EISDIR);
 		goto out_dput;
 	}
fs/xfs/xfs_ioctl32.c +1 -1
index 54e623b..ce332af 100644
@@ -293,7 +293,7 @@ xfs_compat_ioc_bulkstat(
 		int res;
 
 		error = xfs_bulkstat_one_compat(mp, inlast, bulkreq.ubuffer,
-				sizeof(compat_xfs_bstat_t), 0, &res);
+				sizeof(compat_xfs_bstat_t), NULL, &res);
 	} else if (cmd == XFS_IOC_FSBULKSTAT_32) {
 		error = xfs_bulkstat(mp, &inlast, &count,
 			xfs_bulkstat_one_compat, sizeof(compat_xfs_bstat_t),
fs/xfs/xfs_iops.c +8 -5
index 23ce927..a5a9772 100644
@@ -103,12 +103,15 @@ xfs_mark_inode_dirty(
 }
 
 
-int xfs_initxattrs(struct inode *inode, const struct xattr *xattr_array,
-		   void *fs_info)
+static int
+xfs_initxattrs(
+	struct inode		*inode,
+	const struct xattr	*xattr_array,
+	void			*fs_info)
 {
-	const struct xattr *xattr;
-	struct xfs_inode *ip = XFS_I(inode);
-	int error = 0;
+	const struct xattr	*xattr;
+	struct xfs_inode	*ip = XFS_I(inode);
+	int			error = 0;
 
 	for (xattr = xattr_array; xattr->name != NULL; xattr++) {
 		error = xfs_attr_set(ip, xattr->name, xattr->value,
Signature · 6 lines
1.7.5.4

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] xfs: fix endian conversion issue in discard code

In reply to Dave Chinner
Quoted 6 lines · Dave Chinner

From: Dave Chinner <[email protected]>

When finding the longest extent in an AG, we read the value directly out of the AGF buffer without endian conversion. This will give an incorrect length, resulting in FITRIM operations potentially not trimming everything that it should.

Looks good to me.

Quoted 1 line

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Reviewed-by on v1 2/2
#10 lore raw

Re: [PATCH 2/2] xfs: fix endian conversion issue in discard code

In reply to Dave Chinner
Quoted 8 lines · Dave Chinner

From: Dave Chinner <[email protected]>

When finding the longest extent in an AG, we read the value directly out of the AGF buffer without endian conversion. This will give an incorrect length, resulting in FITRIM operations potentially not trimming everything that it should.

Looks good,

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] xfs: clean up minor sparse warnings

In reply to Dave Chinner
Quoted 23 lines
fs/xfs/xfs_ioctl.c +3 -5
index d99a905..2f3f56a 100644
@@ -230,24 +230,22 @@ xfs_open_by_handle(
 
 	/* Put open permission in namei format. */
 	permflag = hreq->oflags;
-	if ((permflag+1) & O_ACCMODE)
-		permflag++;
 	if (permflag & O_TRUNC)
-		permflag |= 2;
+		permflag |= O_RDWR;
 
 	if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) &&
-	    (permflag & FMODE_WRITE) && IS_APPEND(inode)) {
+	    (OPEN_FMODE(permflag) & FMODE_WRITE) && IS_APPEND(inode)) {
 		error = -XFS_ERROR(EPERM);
 		goto out_dput;
 	}
 
-	if ((permflag & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
+	if ((OPEN_FMODE(permflag) & FMODE_WRITE) && IS_IMMUTABLE(inode)) {

fs/xfs/xfs_ioctl.c xfs_open_by_handle( · line 251

Quoted 10 lines
fs/xfs/xfs_ioctl.c +1 -1
 		error = -XFS_ERROR(EACCES);
 		goto out_dput;
 	}
 
 	/* Can't write directories. */
-	if (S_ISDIR(inode->i_mode) && (permflag & FMODE_WRITE)) {
+	if (S_ISDIR(inode->i_mode) && (OPEN_FMODE(permflag) & FMODE_WRITE)) {
 		error = -XFS_ERROR(EISDIR);
 		goto out_dput;
 	}

I think this one is complicated enough that is deserves a separate patch and a better description.

For the other small bits:

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#3 lore raw

Re: [PATCH 1/2] xfs: clean up minor sparse warnings

Quoted 27 lines · Christoph Hellwig
Quoted 27 lines
fs/xfs/xfs_ioctl.c +3 -5
index d99a905..2f3f56a 100644
@@ -230,24 +230,22 @@ xfs_open_by_handle(
 
 	/* Put open permission in namei format. */
 	permflag = hreq->oflags;
-	if ((permflag+1) & O_ACCMODE)
-		permflag++;
 	if (permflag & O_TRUNC)
-		permflag |= 2;
+		permflag |= O_RDWR;
 
 	if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) &&
-	    (permflag & FMODE_WRITE) && IS_APPEND(inode)) {
+	    (OPEN_FMODE(permflag) & FMODE_WRITE) && IS_APPEND(inode)) {
 		error = -XFS_ERROR(EPERM);
 		goto out_dput;
 	}
 
-	if ((permflag & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
+	if ((OPEN_FMODE(permflag) & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
 		error = -XFS_ERROR(EACCES);
 		goto out_dput;
 	}
 
Quoted 9 lines

fs/xfs/xfs_ioctl.c xfs_open_by_handle( · line 251

Quoted 6 lines
fs/xfs/xfs_ioctl.c +1 -1
 	/* Can't write directories. */
-	if (S_ISDIR(inode->i_mode) && (permflag & FMODE_WRITE)) {
+	if (S_ISDIR(inode->i_mode) && (OPEN_FMODE(permflag) & FMODE_WRITE)) {
 		error = -XFS_ERROR(EISDIR);
 		goto out_dput;
 	}

I think this one is complicated enough that is deserves a separate patch and a better description.

Ok, I've also just found a problem with it(*) so I'll separate it and resend when I've fixed it.

Cheers,

Dave.

(*) did you know we actually have a test (079) that verifies this logic? I didn't until a little while ago....

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by
#4 lore raw

Re: [PATCH 1/2] xfs: clean up minor sparse warnings

Hey Dave,

Quoted 38 lines · Dave Chinner
Quoted 27 lines · Christoph Hellwig
Quoted 27 lines
fs/xfs/xfs_ioctl.c +3 -5
index d99a905..2f3f56a 100644
@@ -230,24 +230,22 @@ xfs_open_by_handle(
 
 	/* Put open permission in namei format. */
 	permflag = hreq->oflags;
-	if ((permflag+1) & O_ACCMODE)
-		permflag++;
 	if (permflag & O_TRUNC)
-		permflag |= 2;
+		permflag |= O_RDWR;
 
 	if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) &&
-	    (permflag & FMODE_WRITE) && IS_APPEND(inode)) {
+	    (OPEN_FMODE(permflag) & FMODE_WRITE) && IS_APPEND(inode)) {
 		error = -XFS_ERROR(EPERM);
 		goto out_dput;
 	}
 
-	if ((permflag & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
+	if ((OPEN_FMODE(permflag) & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
 		error = -XFS_ERROR(EACCES);
 		goto out_dput;
 	}
 
Quoted 9 lines

fs/xfs/xfs_ioctl.c xfs_open_by_handle( · line 251

Quoted 6 lines
fs/xfs/xfs_ioctl.c +1 -1
 	/* Can't write directories. */
-	if (S_ISDIR(inode->i_mode) && (permflag & FMODE_WRITE)) {
+	if (S_ISDIR(inode->i_mode) && (OPEN_FMODE(permflag) & FMODE_WRITE)) {
 		error = -XFS_ERROR(EISDIR);
 		goto out_dput;
 	}

I think this one is complicated enough that is deserves a separate patch and a better description.

Quoted 2 lines

Ok, I've also just found a problem with it(*) so I'll separate it and resend when I've fixed it.

D'oh, I just reviewed this and didn't find the problem. Looking forward to your next rev to see what it is.

-Ben

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#8 lore raw

Re: [PATCH 2/2] xfs: fix endian conversion issue in discard code

In reply to Ben Myers
Quoted 8 lines · Ben Myers
Quoted 6 lines · Dave Chinner

From: Dave Chinner <[email protected]>

When finding the longest extent in an AG, we read the value directly out of the AGF buffer without endian conversion. This will give an incorrect length, resulting in FITRIM operations potentially not trimming everything that it should.

Quoted 5 lines

Looks good to me.

Quoted 1 line

This is a pretty serious thing, can you send it to Linus as soon as he takes the current pull request?

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#9 lore raw

Re: [PATCH 2/2] xfs: fix endian conversion issue in discard code

Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Ben Myers
Quoted 6 lines · Dave Chinner

From: Dave Chinner <[email protected]>

When finding the longest extent in an AG, we read the value directly out of the AGF buffer without endian conversion. This will give an incorrect length, resulting in FITRIM operations potentially not trimming everything that it should.

Quoted 8 lines
Quoted 5 lines

Looks good to me.

Quoted 1 line

This is a pretty serious thing, can you send it to Linus as soon as he takes the current pull request?

yep.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#5 lore raw

Re: [PATCH 1/2] xfs: clean up minor sparse warnings

In reply to Dave Chinner

Hey Dave,

Quoted 38 lines · Dave Chinner
Quoted 27 lines · Christoph Hellwig
Quoted 27 lines
fs/xfs/xfs_ioctl.c +3 -5
index d99a905..2f3f56a 100644
@@ -230,24 +230,22 @@ xfs_open_by_handle(
 
 	/* Put open permission in namei format. */
 	permflag = hreq->oflags;
-	if ((permflag+1) & O_ACCMODE)
-		permflag++;
 	if (permflag & O_TRUNC)
-		permflag |= 2;
+		permflag |= O_RDWR;
 
 	if ((!(permflag & O_APPEND) || (permflag & O_TRUNC)) &&
-	    (permflag & FMODE_WRITE) && IS_APPEND(inode)) {
+	    (OPEN_FMODE(permflag) & FMODE_WRITE) && IS_APPEND(inode)) {
 		error = -XFS_ERROR(EPERM);
 		goto out_dput;
 	}
 
-	if ((permflag & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
+	if ((OPEN_FMODE(permflag) & FMODE_WRITE) && IS_IMMUTABLE(inode)) {
 		error = -XFS_ERROR(EACCES);
 		goto out_dput;
 	}
 
Quoted 9 lines

fs/xfs/xfs_ioctl.c xfs_open_by_handle( · line 251

Quoted 6 lines
fs/xfs/xfs_ioctl.c +1 -1
 	/* Can't write directories. */
-	if (S_ISDIR(inode->i_mode) && (permflag & FMODE_WRITE)) {
+	if (S_ISDIR(inode->i_mode) && (OPEN_FMODE(permflag) & FMODE_WRITE)) {
 		error = -XFS_ERROR(EISDIR);
 		goto out_dput;
 	}

I think this one is complicated enough that is deserves a separate patch and a better description.

Quoted 2 lines

Ok, I've also just found a problem with it(*) so I'll separate it and resend when I've fixed it.

Did you resend this?

Thanks,
Ben

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs