Skip to contentSkip to conversation

misc xfsprogs cleanups after the 5.7 merge

PATCH In review Christoph Hellwig 3 participants 30 messages May 9, 2020 – May 11, 2020

lore
Share & tools
lore
#0 lore raw

Hi Eric,

this series contains the differences to my port that seem useful to keep.

#1 lore raw

PATCH 1/8 libxfs: use tabs instead of spaces in div_u64

---
 libxfs/libxfs_priv.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libxfs/libxfs_priv.h +2 -2
index 8d717d91..5688284d 100644
@@ -263,8 +263,8 @@ div_u64_rem(uint64_t dividend, uint32_t divisor, uint32_t *remainder)
  */
 static inline uint64_t div_u64(uint64_t dividend, uint32_t divisor)
 {
-        uint32_t remainder;
-        return div_u64_rem(dividend, divisor, &remainder);
+	uint32_t remainder;
+	return div_u64_rem(dividend, divisor, &remainder);
 }
 
 /**
Signature · 1 line
2.26.2
Reviewed-by on v1 1/8
#2 lore raw

Re: [PATCH 1/8] libxfs: use tabs instead of spaces in div_u64

Quoted 1 line · Christoph Hellwig

Looks ok,

--D

Quoted 22 lines
---
 libxfs/libxfs_priv.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libxfs/libxfs_priv.h +2 -2
index 8d717d91..5688284d 100644
@@ -263,8 +263,8 @@ div_u64_rem(uint64_t dividend, uint32_t divisor, uint32_t *remainder)
  */
 static inline uint64_t div_u64(uint64_t dividend, uint32_t divisor)
 {
-        uint32_t remainder;
-        return div_u64_rem(dividend, divisor, &remainder);
+	uint32_t remainder;
+	return div_u64_rem(dividend, divisor, &remainder);
 }
 
 /**
Signature · 1 line
2.26.2
#3 lore raw

Re: [PATCH 1/8] libxfs: use tabs instead of spaces in div_u64

In reply to Christoph Hellwig
Quoted 2 lines · Christoph Hellwig

---

oh that's embarrassing.... Thanks for this and the other fixes, I had meant to go through the differences but tough to keep up with you. ;)

-Eric

Quoted 19 lines
 libxfs/libxfs_priv.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libxfs/libxfs_priv.h +2 -2
index 8d717d91..5688284d 100644
@@ -263,8 +263,8 @@ div_u64_rem(uint64_t dividend, uint32_t divisor, uint32_t *remainder)
  */
 static inline uint64_t div_u64(uint64_t dividend, uint32_t divisor)
 {
-        uint32_t remainder;
-        return div_u64_rem(dividend, divisor, &remainder);
+	uint32_t remainder;
+	return div_u64_rem(dividend, divisor, &remainder);
 }
 
 /**
#4 lore raw

PATCH 2/8 db: fix a comment in scan_freelist

In reply to Christoph Hellwig

XFS_BUF_TO_AGFL_BNO has been renamed to open coded xfs_buf_to_agfl_bno.

---
 db/check.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
db/check.c +1 -1
index c9bafa8e..09f8f6c9 100644
@@ -4075,7 +4075,7 @@ scan_freelist(
 		return;
 	}
 
-	/* open coded XFS_BUF_TO_AGFL_BNO */
+	/* open coded xfs_buf_to_agfl_bno */
 	state.count = 0;
 	state.agno = seqno;
 	libxfs_agfl_walk(mp, agf, iocur_top->bp, scan_agfl, &state);
Signature · 1 line
2.26.2
Reviewed-by on v1 2/8
#5 lore raw

Re: [PATCH 2/8] db: fix a comment in scan_freelist

Quoted 3 lines · Christoph Hellwig

XFS_BUF_TO_AGFL_BNO has been renamed to open coded xfs_buf_to_agfl_bno.

LGTM

--D

Quoted 20 lines
---
 db/check.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
db/check.c +1 -1
index c9bafa8e..09f8f6c9 100644
@@ -4075,7 +4075,7 @@ scan_freelist(
 		return;
 	}
 
-	/* open coded XFS_BUF_TO_AGFL_BNO */
+	/* open coded xfs_buf_to_agfl_bno */
 	state.count = 0;
 	state.agno = seqno;
 	libxfs_agfl_walk(mp, agf, iocur_top->bp, scan_agfl, &state);
Signature · 1 line
2.26.2
#6 lore raw

PATCH 3/8 db: add a comment to agfl_crc_flds

In reply to Christoph Hellwig

Explain the bno field that is not actually part of the structure anymore.

---
 db/agfl.c | 1 +
 1 file changed, 1 insertion(+)
db/agfl.c +1 -0
index 45e4d6f9..ce7a2548 100644
@@ -47,6 +47,7 @@ const field_t	agfl_crc_flds[] = {
 	{ "uuid", FLDT_UUID, OI(OFF(uuid)), C1, 0, TYP_NONE },
 	{ "lsn", FLDT_UINT64X, OI(OFF(lsn)), C1, 0, TYP_NONE },
 	{ "crc", FLDT_CRC, OI(OFF(crc)), C1, 0, TYP_NONE },
+	/* the bno array really is behind the actual structure */
 	{ "bno", FLDT_AGBLOCKNZ, OI(bitize(sizeof(struct xfs_agfl))),
 	  agfl_bno_size, FLD_ARRAY|FLD_COUNT, TYP_DATA },
 	{ NULL }
Signature · 1 line
2.26.2
#7 lore raw

Re: [PATCH 3/8] db: add a comment to agfl_crc_flds

Quoted 13 lines · Christoph Hellwig

Explain the bno field that is not actually part of the structure anymore.

---
 db/agfl.c | 1 +
 1 file changed, 1 insertion(+)
db/agfl.c +0 -0
index 45e4d6f9..ce7a2548 100644

db/agfl.c const field_t agfl_crc_flds[] = { · line 50

Quoted 4 lines
db/agfl.c +1 -0
@@ -47,6 +47,7 @@ const field_t	agfl_crc_flds[] = {
 	{ "uuid", FLDT_UUID, OI(OFF(uuid)), C1, 0, TYP_NONE },
 	{ "lsn", FLDT_UINT64X, OI(OFF(lsn)), C1, 0, TYP_NONE },
 	{ "crc", FLDT_CRC, OI(OFF(crc)), C1, 0, TYP_NONE },
+	/* the bno array really is behind the actual structure */

Er... the bno array comes /after/ the actual structure, right?

--D

Quoted 6 lines
db/agfl.c +0 -0
 	{ "bno", FLDT_AGBLOCKNZ, OI(bitize(sizeof(struct xfs_agfl))),
 	  agfl_bno_size, FLD_ARRAY|FLD_COUNT, TYP_DATA },
 	{ NULL }
Signature · 1 line
2.26.2
#8 lore raw

Re: [PATCH 3/8] db: add a comment to agfl_crc_flds

Quoted 9 lines · Darrick J. Wong
Quoted 8 lines · Christoph Hellwig

Explain the bno field that is not actually part of the structure anymore.

---
 db/agfl.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 11 lines

db/agfl.c const field_t agfl_crc_flds[] = { · line 50

Quoted 9 lines
db/agfl.c +1 -0
index 45e4d6f9..ce7a2548 100644
@@ -47,6 +47,7 @@ const field_t	agfl_crc_flds[] = {
 	{ "uuid", FLDT_UUID, OI(OFF(uuid)), C1, 0, TYP_NONE },
 	{ "lsn", FLDT_UINT64X, OI(OFF(lsn)), C1, 0, TYP_NONE },
 	{ "crc", FLDT_CRC, OI(OFF(crc)), C1, 0, TYP_NONE },
+	/* the bno array really is behind the actual structure */

Er... the bno array comes /after/ the actual structure, right?

Yes. That's what I mean, but after seems to be less confusing.

#9 lore raw

Re: [PATCH 3/8] db: add a comment to agfl_crc_flds

Quoted 22 lines · Christoph Hellwig
Quoted 9 lines · Darrick J. Wong
Quoted 8 lines · Christoph Hellwig

Explain the bno field that is not actually part of the structure anymore.

---
 db/agfl.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 11 lines

db/agfl.c const field_t agfl_crc_flds[] = { · line 50

Quoted 9 lines
db/agfl.c +1 -0
index 45e4d6f9..ce7a2548 100644
@@ -47,6 +47,7 @@ const field_t	agfl_crc_flds[] = {
 	{ "uuid", FLDT_UUID, OI(OFF(uuid)), C1, 0, TYP_NONE },
 	{ "lsn", FLDT_UINT64X, OI(OFF(lsn)), C1, 0, TYP_NONE },
 	{ "crc", FLDT_CRC, OI(OFF(crc)), C1, 0, TYP_NONE },
+	/* the bno array really is behind the actual structure */

Er... the bno array comes /after/ the actual structure, right?

Quoted 1 line

Yes. That's what I mean, but after seems to be less confusing.

so:

/* the bno array is after the actual structure */

right? I can just do that on merge.

Reviewed-by
#10 lore raw

Re: [PATCH 3/8] db: add a comment to agfl_crc_flds

Quoted 23 lines · Eric Sandeen
Quoted 22 lines · Christoph Hellwig
Quoted 20 lines · Darrick J. Wong
Quoted 13 lines · Christoph Hellwig

Explain the bno field that is not actually part of the structure anymore.

---
 db/agfl.c | 1 +
 1 file changed, 1 insertion(+)
db/agfl.c +0 -0
index 45e4d6f9..ce7a2548 100644

db/agfl.c const field_t agfl_crc_flds[] = { · line 50

Quoted 4 lines
db/agfl.c +1 -0
@@ -47,6 +47,7 @@ const field_t	agfl_crc_flds[] = {
 	{ "uuid", FLDT_UUID, OI(OFF(uuid)), C1, 0, TYP_NONE },
 	{ "lsn", FLDT_UINT64X, OI(OFF(lsn)), C1, 0, TYP_NONE },
 	{ "crc", FLDT_CRC, OI(OFF(crc)), C1, 0, TYP_NONE },
+	/* the bno array really is behind the actual structure */

Er... the bno array comes /after/ the actual structure, right?

Quoted 7 lines
Quoted 1 line

Yes. That's what I mean, but after seems to be less confusing.

so:

/* the bno array is after the actual structure */

right? I can just do that on merge.

With that changed,

--D

#11 lore raw

Re: [PATCH 3/8] db: add a comment to agfl_crc_flds

In reply to Eric Sandeen
Quoted 6 lines · Eric Sandeen
Quoted 1 line

Yes. That's what I mean, but after seems to be less confusing.

so:

/* the bno array is after the actual structure */

right? I can just do that on merge.

Looks ok.

#12 lore raw

PATCH 4/8 db: cleanup attr_set_f and attr_remove_f

In reply to Christoph Hellwig

Don't use local variables for information that is set in the da_args structure.

---
 db/attrset.c | 67 ++++++++++++++++++++++------------------------------
 1 file changed, 28 insertions(+), 39 deletions(-)
db/attrset.c +28 -39
index 1ff2eb85..0a464983 100644
@@ -67,10 +67,9 @@ attr_set_f(
 	int			argc,
 	char			**argv)
 {
-	struct xfs_inode	*ip = NULL;
-	struct xfs_da_args	args = { NULL };
-	char			*name, *value, *sp;
-	int			c, valuelen = 0;
+	struct xfs_da_args	args = { };
+	char			*sp;
+	int			c;
 
 	if (cur_typ == NULL) {
 		dbprintf(_("no current type\n"));
@@ -111,8 +110,9 @@ attr_set_f(
 
 		/* value length */
 		case 'v':
-			valuelen = (int)strtol(optarg, &sp, 0);
-			if (*sp != '\0' || valuelen < 0 || valuelen > 64*1024) {
+			args.valuelen = strtol(optarg, &sp, 0);
+			if (*sp != '\0' ||
+			    args.valuelen < 0 || args.valuelen > 64 * 1024) {
 				dbprintf(_("bad attr_set valuelen %s\n"), optarg);
 				return 0;
 			}
@@ -129,35 +129,29 @@ attr_set_f(
 		return 0;
 	}
 
-	name = argv[optind];
+	args.name = (const unsigned char *)argv[optind];
+	args.namelen = strlen(argv[optind]);
 
-	if (valuelen) {
-		value = (char *)memalign(getpagesize(), valuelen);
-		if (!value) {
-			dbprintf(_("cannot allocate buffer (%d)\n"), valuelen);
+	if (args.valuelen) {
+		args.value = memalign(getpagesize(), args.valuelen);
+		if (!args.value) {
+			dbprintf(_("cannot allocate buffer (%d)\n"),
+				args.valuelen);
 			goto out;
 		}
-		memset(value, 'v', valuelen);
-	} else {
-		value = NULL;
+		memset(args.value, 'v', args.valuelen);
 	}
 
-	if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &ip,
+	if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &args.dp,
 			&xfs_default_ifork_ops)) {
 		dbprintf(_("failed to iget inode %llu\n"),
 			(unsigned long long)iocur_top->ino);
 		goto out;
 	}
 
-	args.dp = ip;
-	args.name = (unsigned char *)name;
-	args.namelen = strlen(name);
-	args.value = value;
-	args.valuelen = valuelen;
-
 	if (libxfs_attr_set(&args)) {
 		dbprintf(_("failed to set attr %s on inode %llu\n"),
-			name, (unsigned long long)iocur_top->ino);
+			args.name, (unsigned long long)iocur_top->ino);
 		goto out;
 	}
 
@@ -166,10 +160,10 @@ attr_set_f(
 
 out:
 	mp->m_flags &= ~LIBXFS_MOUNT_COMPAT_ATTR;
-	if (ip)
-		libxfs_irele(ip);
-	if (value)
-		free(value);
+	if (args.dp)
+		libxfs_irele(args.dp);
+	if (args.value)
+		free(args.value);
 	return 0;
 }
 
@@ -178,9 +172,7 @@ attr_remove_f(
 	int			argc,
 	char			**argv)
 {
-	struct xfs_inode	*ip = NULL;
-	struct xfs_da_args	args = { NULL };
-	char			*name;
+	struct xfs_da_args	args = { };
 	int			c;
 
 	if (cur_typ == NULL) {
@@ -223,23 +215,20 @@ attr_remove_f(
 		return 0;
 	}
 
-	name = argv[optind];
+	args.name = (const unsigned char *)argv[optind];
+	args.namelen = strlen(argv[optind]);
 
-	if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &ip,
+	if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &args.dp,
 			&xfs_default_ifork_ops)) {
 		dbprintf(_("failed to iget inode %llu\n"),
 			(unsigned long long)iocur_top->ino);
 		goto out;
 	}
 
-	args.dp = ip;
-	args.name = (unsigned char *)name;
-	args.namelen = strlen(name);
-	args.value = NULL;
-
 	if (libxfs_attr_set(&args)) {
 		dbprintf(_("failed to remove attr %s from inode %llu\n"),
-			name, (unsigned long long)iocur_top->ino);
+			(unsigned char *)args.name,
+			(unsigned long long)iocur_top->ino);
 		goto out;
 	}
 
@@ -248,7 +237,7 @@ attr_remove_f(
 
 out:
 	mp->m_flags &= ~LIBXFS_MOUNT_COMPAT_ATTR;
-	if (ip)
-		libxfs_irele(ip);
+	if (args.dp)
+		libxfs_irele(args.dp);
 	return 0;
 }
Signature · 1 line
2.26.2
Reviewed-by on v1 4/8
#13 lore raw

Re: [PATCH 4/8] db: cleanup attr_set_f and attr_remove_f

Quoted 4 lines · Christoph Hellwig

Don't use local variables for information that is set in the da_args structure.

Seems like a good cleanup,

--D

Quoted 148 lines
---
 db/attrset.c | 67 ++++++++++++++++++++++------------------------------
 1 file changed, 28 insertions(+), 39 deletions(-)
db/attrset.c +28 -39
index 1ff2eb85..0a464983 100644
@@ -67,10 +67,9 @@ attr_set_f(
 	int			argc,
 	char			**argv)
 {
-	struct xfs_inode	*ip = NULL;
-	struct xfs_da_args	args = { NULL };
-	char			*name, *value, *sp;
-	int			c, valuelen = 0;
+	struct xfs_da_args	args = { };
+	char			*sp;
+	int			c;
 
 	if (cur_typ == NULL) {
 		dbprintf(_("no current type\n"));
@@ -111,8 +110,9 @@ attr_set_f(
 
 		/* value length */
 		case 'v':
-			valuelen = (int)strtol(optarg, &sp, 0);
-			if (*sp != '\0' || valuelen < 0 || valuelen > 64*1024) {
+			args.valuelen = strtol(optarg, &sp, 0);
+			if (*sp != '\0' ||
+			    args.valuelen < 0 || args.valuelen > 64 * 1024) {
 				dbprintf(_("bad attr_set valuelen %s\n"), optarg);
 				return 0;
 			}
@@ -129,35 +129,29 @@ attr_set_f(
 		return 0;
 	}
 
-	name = argv[optind];
+	args.name = (const unsigned char *)argv[optind];
+	args.namelen = strlen(argv[optind]);
 
-	if (valuelen) {
-		value = (char *)memalign(getpagesize(), valuelen);
-		if (!value) {
-			dbprintf(_("cannot allocate buffer (%d)\n"), valuelen);
+	if (args.valuelen) {
+		args.value = memalign(getpagesize(), args.valuelen);
+		if (!args.value) {
+			dbprintf(_("cannot allocate buffer (%d)\n"),
+				args.valuelen);
 			goto out;
 		}
-		memset(value, 'v', valuelen);
-	} else {
-		value = NULL;
+		memset(args.value, 'v', args.valuelen);
 	}
 
-	if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &ip,
+	if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &args.dp,
 			&xfs_default_ifork_ops)) {
 		dbprintf(_("failed to iget inode %llu\n"),
 			(unsigned long long)iocur_top->ino);
 		goto out;
 	}
 
-	args.dp = ip;
-	args.name = (unsigned char *)name;
-	args.namelen = strlen(name);
-	args.value = value;
-	args.valuelen = valuelen;
-
 	if (libxfs_attr_set(&args)) {
 		dbprintf(_("failed to set attr %s on inode %llu\n"),
-			name, (unsigned long long)iocur_top->ino);
+			args.name, (unsigned long long)iocur_top->ino);
 		goto out;
 	}
 
@@ -166,10 +160,10 @@ attr_set_f(
 
 out:
 	mp->m_flags &= ~LIBXFS_MOUNT_COMPAT_ATTR;
-	if (ip)
-		libxfs_irele(ip);
-	if (value)
-		free(value);
+	if (args.dp)
+		libxfs_irele(args.dp);
+	if (args.value)
+		free(args.value);
 	return 0;
 }
 
@@ -178,9 +172,7 @@ attr_remove_f(
 	int			argc,
 	char			**argv)
 {
-	struct xfs_inode	*ip = NULL;
-	struct xfs_da_args	args = { NULL };
-	char			*name;
+	struct xfs_da_args	args = { };
 	int			c;
 
 	if (cur_typ == NULL) {
@@ -223,23 +215,20 @@ attr_remove_f(
 		return 0;
 	}
 
-	name = argv[optind];
+	args.name = (const unsigned char *)argv[optind];
+	args.namelen = strlen(argv[optind]);
 
-	if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &ip,
+	if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &args.dp,
 			&xfs_default_ifork_ops)) {
 		dbprintf(_("failed to iget inode %llu\n"),
 			(unsigned long long)iocur_top->ino);
 		goto out;
 	}
 
-	args.dp = ip;
-	args.name = (unsigned char *)name;
-	args.namelen = strlen(name);
-	args.value = NULL;
-
 	if (libxfs_attr_set(&args)) {
 		dbprintf(_("failed to remove attr %s from inode %llu\n"),
-			name, (unsigned long long)iocur_top->ino);
+			(unsigned char *)args.name,
+			(unsigned long long)iocur_top->ino);
 		goto out;
 	}
 
@@ -248,7 +237,7 @@ attr_remove_f(
 
 out:
 	mp->m_flags &= ~LIBXFS_MOUNT_COMPAT_ATTR;
-	if (ip)
-		libxfs_irele(ip);
+	if (args.dp)
+		libxfs_irele(args.dp);
 	return 0;
 }
Signature · 1 line
2.26.2
#14 lore raw

Re: [PATCH 4/8] db: cleanup attr_set_f and attr_remove_f

In reply to Christoph Hellwig
Quoted 2 lines · Christoph Hellwig

Don't use local variables for information that is set in the da_args structure.

I'm on the fence about this one; Darrick had missed setting a couple of necessary structure members, so I actually see some value in assigning them all right before we call into libxfs_attr_set .... it makes it very clear what's being sent in to libxfs_attr_set.

-Eric

Quoted 147 lines
---
 db/attrset.c | 67 ++++++++++++++++++++++------------------------------
 1 file changed, 28 insertions(+), 39 deletions(-)
db/attrset.c +28 -39
index 1ff2eb85..0a464983 100644
@@ -67,10 +67,9 @@ attr_set_f(
 	int			argc,
 	char			**argv)
 {
-	struct xfs_inode	*ip = NULL;
-	struct xfs_da_args	args = { NULL };
-	char			*name, *value, *sp;
-	int			c, valuelen = 0;
+	struct xfs_da_args	args = { };
+	char			*sp;
+	int			c;
 
 	if (cur_typ == NULL) {
 		dbprintf(_("no current type\n"));
@@ -111,8 +110,9 @@ attr_set_f(
 
 		/* value length */
 		case 'v':
-			valuelen = (int)strtol(optarg, &sp, 0);
-			if (*sp != '\0' || valuelen < 0 || valuelen > 64*1024) {
+			args.valuelen = strtol(optarg, &sp, 0);
+			if (*sp != '\0' ||
+			    args.valuelen < 0 || args.valuelen > 64 * 1024) {
 				dbprintf(_("bad attr_set valuelen %s\n"), optarg);
 				return 0;
 			}
@@ -129,35 +129,29 @@ attr_set_f(
 		return 0;
 	}
 
-	name = argv[optind];
+	args.name = (const unsigned char *)argv[optind];
+	args.namelen = strlen(argv[optind]);
 
-	if (valuelen) {
-		value = (char *)memalign(getpagesize(), valuelen);
-		if (!value) {
-			dbprintf(_("cannot allocate buffer (%d)\n"), valuelen);
+	if (args.valuelen) {
+		args.value = memalign(getpagesize(), args.valuelen);
+		if (!args.value) {
+			dbprintf(_("cannot allocate buffer (%d)\n"),
+				args.valuelen);
 			goto out;
 		}
-		memset(value, 'v', valuelen);
-	} else {
-		value = NULL;
+		memset(args.value, 'v', args.valuelen);
 	}
 
-	if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &ip,
+	if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &args.dp,
 			&xfs_default_ifork_ops)) {
 		dbprintf(_("failed to iget inode %llu\n"),
 			(unsigned long long)iocur_top->ino);
 		goto out;
 	}
 
-	args.dp = ip;
-	args.name = (unsigned char *)name;
-	args.namelen = strlen(name);
-	args.value = value;
-	args.valuelen = valuelen;
-
 	if (libxfs_attr_set(&args)) {
 		dbprintf(_("failed to set attr %s on inode %llu\n"),
-			name, (unsigned long long)iocur_top->ino);
+			args.name, (unsigned long long)iocur_top->ino);
 		goto out;
 	}
 
@@ -166,10 +160,10 @@ attr_set_f(
 
 out:
 	mp->m_flags &= ~LIBXFS_MOUNT_COMPAT_ATTR;
-	if (ip)
-		libxfs_irele(ip);
-	if (value)
-		free(value);
+	if (args.dp)
+		libxfs_irele(args.dp);
+	if (args.value)
+		free(args.value);
 	return 0;
 }
 
@@ -178,9 +172,7 @@ attr_remove_f(
 	int			argc,
 	char			**argv)
 {
-	struct xfs_inode	*ip = NULL;
-	struct xfs_da_args	args = { NULL };
-	char			*name;
+	struct xfs_da_args	args = { };
 	int			c;
 
 	if (cur_typ == NULL) {
@@ -223,23 +215,20 @@ attr_remove_f(
 		return 0;
 	}
 
-	name = argv[optind];
+	args.name = (const unsigned char *)argv[optind];
+	args.namelen = strlen(argv[optind]);
 
-	if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &ip,
+	if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &args.dp,
 			&xfs_default_ifork_ops)) {
 		dbprintf(_("failed to iget inode %llu\n"),
 			(unsigned long long)iocur_top->ino);
 		goto out;
 	}
 
-	args.dp = ip;
-	args.name = (unsigned char *)name;
-	args.namelen = strlen(name);
-	args.value = NULL;
-
 	if (libxfs_attr_set(&args)) {
 		dbprintf(_("failed to remove attr %s from inode %llu\n"),
-			name, (unsigned long long)iocur_top->ino);
+			(unsigned char *)args.name,
+			(unsigned long long)iocur_top->ino);
 		goto out;
 	}
 
@@ -248,7 +237,7 @@ attr_remove_f(
 
 out:
 	mp->m_flags &= ~LIBXFS_MOUNT_COMPAT_ATTR;
-	if (ip)
-		libxfs_irele(ip);
+	if (args.dp)
+		libxfs_irele(args.dp);
 	return 0;
 }
#15 lore raw

Re: [PATCH 4/8] db: cleanup attr_set_f and attr_remove_f

Quoted 8 lines · Eric Sandeen
Quoted 2 lines · Christoph Hellwig

Don't use local variables for information that is set in the da_args structure.

I'm on the fence about this one; Darrick had missed setting a couple of necessary structure members, so I actually see some value in assigning them all right before we call into libxfs_attr_set .... it makes it very clear what's being sent in to libxfs_attr_set.

But using additional local variables doesn't help with initialing the fields, it actually makes it easier to miss, which I guess is what happened. I find the code much easier to verify without the extra variables.

#16 lore raw

Re: [PATCH 4/8] db: cleanup attr_set_f and attr_remove_f

Quoted 10 lines · Christoph Hellwig
Quoted 8 lines · Eric Sandeen
Quoted 2 lines · Christoph Hellwig

Don't use local variables for information that is set in the da_args structure.

I'm on the fence about this one; Darrick had missed setting a couple of necessary structure members, so I actually see some value in assigning them all right before we call into libxfs_attr_set .... it makes it very clear what's being sent in to libxfs_attr_set.

Quoted 4 lines

But using additional local variables doesn't help with initialing the fields, it actually makes it easier to miss, which I guess is what happened. I find the code much easier to verify without the extra variables.

They seem a bit extraneous, but my problem is I can't keep track of how much of the args structure is actually filled out when it's spread out over dozens of lines ....

*shrug* I dunno. Maybe darrick can cast the tie-breaking vote. ;)

#17 lore raw

Re: [PATCH 4/8] db: cleanup attr_set_f and attr_remove_f

Quoted 16 lines · Eric Sandeen
Quoted 10 lines · Christoph Hellwig
Quoted 8 lines · Eric Sandeen
Quoted 2 lines · Christoph Hellwig

Don't use local variables for information that is set in the da_args structure.

I'm on the fence about this one; Darrick had missed setting a couple of necessary structure members, so I actually see some value in assigning them all right before we call into libxfs_attr_set .... it makes it very clear what's being sent in to libxfs_attr_set.

Quoted 4 lines

But using additional local variables doesn't help with initialing the fields, it actually makes it easier to miss, which I guess is what happened. I find the code much easier to verify without the extra variables.

Quoted 5 lines

They seem a bit extraneous, but my problem is I can't keep track of how much of the args structure is actually filled out when it's spread out over dozens of lines ....

*shrug* I dunno. Maybe darrick can cast the tie-breaking vote. ;)

I mean... I /did/ already RVB this one... :)

--D

#18 lore raw

Re: [PATCH 4/8] db: cleanup attr_set_f and attr_remove_f

Quoted 17 lines · Darrick J. Wong
Quoted 16 lines · Eric Sandeen
Quoted 14 lines · Christoph Hellwig
Quoted 8 lines · Eric Sandeen
Quoted 2 lines · Christoph Hellwig

Don't use local variables for information that is set in the da_args structure.

I'm on the fence about this one; Darrick had missed setting a couple of necessary structure members, so I actually see some value in assigning them all right before we call into libxfs_attr_set .... it makes it very clear what's being sent in to libxfs_attr_set.

But using additional local variables doesn't help with initialing the fields, it actually makes it easier to miss, which I guess is what happened. I find the code much easier to verify without the extra variables.

Quoted 7 lines
Quoted 5 lines

They seem a bit extraneous, but my problem is I can't keep track of how much of the args structure is actually filled out when it's spread out over dozens of lines ....

*shrug* I dunno. Maybe darrick can cast the tie-breaking vote. ;)

I mean... I /did/ already RVB this one... :)

Before I raised the question, but *shrug* ok, I guess nobody else sees it my way so I'll merge it as is, not worth haggling over any further.

thanks for all the cleanups, Christoph.

-Eric

#19 lore raw

PATCH 5/8 db: validate name and namelen in attr_set_f and attr_remove_f

In reply to Christoph Hellwig

libxfs has stopped validating these parameters internally, so do it in the xfs_db commands.

---
 db/attrset.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
db/attrset.c +18 -0
index 0a464983..e3575271 100644
@@ -130,7 +130,16 @@ attr_set_f(
 	}
 
 	args.name = (const unsigned char *)argv[optind];
+	if (!args.name) {
+		dbprintf(_("invalid name\n"));
+		return 0;
+	}
+
 	args.namelen = strlen(argv[optind]);
+	if (args.namelen >= MAXNAMELEN) {
+		dbprintf(_("name too long\n"));
+		return 0;
+	}
 
 	if (args.valuelen) {
 		args.value = memalign(getpagesize(), args.valuelen);
@@ -216,7 +225,16 @@ attr_remove_f(
 	}
 
 	args.name = (const unsigned char *)argv[optind];
+	if (!args.name) {
+		dbprintf(_("invalid name\n"));
+		return 0;
+	}
+
 	args.namelen = strlen(argv[optind]);
+	if (args.namelen >= MAXNAMELEN) {
+		dbprintf(_("name too long\n"));
+		return 0;
+	}
 
 	if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &args.dp,
 			&xfs_default_ifork_ops)) {
Signature · 1 line
2.26.2
Reviewed-by on v1 5/8
#20 lore raw

Re: [PATCH 5/8] db: validate name and namelen in attr_set_f and attr_remove_f

Quoted 4 lines · Christoph Hellwig

libxfs has stopped validating these parameters internally, so do it in the xfs_db commands.

IIRC the VFS checks these parameters so that libxfs doesn't have to, right?

If so,

--D

Quoted 45 lines
---
 db/attrset.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
db/attrset.c +18 -0
index 0a464983..e3575271 100644
@@ -130,7 +130,16 @@ attr_set_f(
 	}
 
 	args.name = (const unsigned char *)argv[optind];
+	if (!args.name) {
+		dbprintf(_("invalid name\n"));
+		return 0;
+	}
+
 	args.namelen = strlen(argv[optind]);
+	if (args.namelen >= MAXNAMELEN) {
+		dbprintf(_("name too long\n"));
+		return 0;
+	}
 
 	if (args.valuelen) {
 		args.value = memalign(getpagesize(), args.valuelen);
@@ -216,7 +225,16 @@ attr_remove_f(
 	}
 
 	args.name = (const unsigned char *)argv[optind];
+	if (!args.name) {
+		dbprintf(_("invalid name\n"));
+		return 0;
+	}
+
 	args.namelen = strlen(argv[optind]);
+	if (args.namelen >= MAXNAMELEN) {
+		dbprintf(_("name too long\n"));
+		return 0;
+	}
 
 	if (libxfs_iget(mp, NULL, iocur_top->ino, 0, &args.dp,
 			&xfs_default_ifork_ops)) {
Signature · 1 line
2.26.2
#21 lore raw

Re: [PATCH 5/8] db: validate name and namelen in attr_set_f and attr_remove_f

Quoted 8 lines · Darrick J. Wong
Quoted 4 lines · Christoph Hellwig

libxfs has stopped validating these parameters internally, so do it in the xfs_db commands.

IIRC the VFS checks these parameters so that libxfs doesn't have to, right?

Yes. But we don't have the VFS in xfsprogs :)

#22 lore raw

PATCH 6/8 db: ensure that create and replace are exclusive in attr_set_f

In reply to Christoph Hellwig

Clear the other flag when applying the create or replace option, as the low-level libxfs can't handle both at the same time.

---
 db/attrset.c | 2 ++
 1 file changed, 2 insertions(+)
db/attrset.c +2 -0
index e3575271..b86ecec7 100644
@@ -99,9 +99,11 @@ attr_set_f(
 		/* modifiers */
 		case 'C':
 			args.attr_flags |= XATTR_CREATE;
+			args.attr_flags &= ~XATTR_REPLACE;
 			break;
 		case 'R':
 			args.attr_flags |= XATTR_REPLACE;
+			args.attr_flags &= ~XATTR_CREATE;
 			break;
 
 		case 'n':
Signature · 1 line
2.26.2
Reviewed-by on v1 6/8
#23 lore raw

Re: [PATCH 6/8] db: ensure that create and replace are exclusive in attr_set_f

Quoted 4 lines · Christoph Hellwig

Clear the other flag when applying the create or replace option, as the low-level libxfs can't handle both at the same time.

--D

Quoted 23 lines
---
 db/attrset.c | 2 ++
 1 file changed, 2 insertions(+)
db/attrset.c +2 -0
index e3575271..b86ecec7 100644
@@ -99,9 +99,11 @@ attr_set_f(
 		/* modifiers */
 		case 'C':
 			args.attr_flags |= XATTR_CREATE;
+			args.attr_flags &= ~XATTR_REPLACE;
 			break;
 		case 'R':
 			args.attr_flags |= XATTR_REPLACE;
+			args.attr_flags &= ~XATTR_CREATE;
 			break;
 
 		case 'n':
Signature · 1 line
2.26.2
#24 lore raw

PATCH 7/8 repair: cleanup build_agf_agfl

In reply to Christoph Hellwig

No need to have two variables for the AGFL block number array.

---
 repair/phase5.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
repair/phase5.c +2 -5
index 17b57448..677297fe 100644
@@ -2149,18 +2149,15 @@ build_agf_agfl(
 
 	/* setting to 0xff results in initialisation to NULLAGBLOCK */
 	memset(agfl, 0xff, mp->m_sb.sb_sectsize);
+	freelist = xfs_buf_to_agfl_bno(agfl_buf);
 	if (xfs_sb_version_hascrc(&mp->m_sb)) {
-		__be32 *agfl_bno = xfs_buf_to_agfl_bno(agfl_buf);
-
 		agfl->agfl_magicnum = cpu_to_be32(XFS_AGFL_MAGIC);
 		agfl->agfl_seqno = cpu_to_be32(agno);
 		platform_uuid_copy(&agfl->agfl_uuid, &mp->m_sb.sb_meta_uuid);
 		for (i = 0; i < libxfs_agfl_size(mp); i++)
-			agfl_bno[i] = cpu_to_be32(NULLAGBLOCK);
+			freelist[i] = cpu_to_be32(NULLAGBLOCK);
 	}
 
-	freelist = xfs_buf_to_agfl_bno(agfl_buf);
-
 	/*
 	 * do we have left-over blocks in the btree cursors that should
 	 * be used to fill the AGFL?
Signature · 1 line
2.26.2
Reviewed-by on v1 7/8
#25 lore raw

Re: [PATCH 7/8] repair: cleanup build_agf_agfl

Quoted 12 lines · Christoph Hellwig

No need to have two variables for the AGFL block number array.

---
 repair/phase5.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
repair/phase5.c +0 -0
index 17b57448..677297fe 100644

repair/phase5.c build_agf_agfl( · line 2151

Quoted 3 lines
repair/phase5.c +0 -0
@@ -2149,18 +2149,15 @@ build_agf_agfl(
 
 	/* setting to 0xff results in initialisation to NULLAGBLOCK */
 	memset(agfl, 0xff, mp->m_sb.sb_sectsize);

/me wonders why this memset isn't sufficient to null out the freelist, but a better cleanup would be to rip all this out in favor of adapting the nearly identical functions in xfs_ag.c.

In the meantime we don't need duplicate variables, and:

--D

Quoted 20 lines
repair/phase5.c +2 -5
+	freelist = xfs_buf_to_agfl_bno(agfl_buf);
 	if (xfs_sb_version_hascrc(&mp->m_sb)) {
-		__be32 *agfl_bno = xfs_buf_to_agfl_bno(agfl_buf);
-
 		agfl->agfl_magicnum = cpu_to_be32(XFS_AGFL_MAGIC);
 		agfl->agfl_seqno = cpu_to_be32(agno);
 		platform_uuid_copy(&agfl->agfl_uuid, &mp->m_sb.sb_meta_uuid);
 		for (i = 0; i < libxfs_agfl_size(mp); i++)
-			agfl_bno[i] = cpu_to_be32(NULLAGBLOCK);
+			freelist[i] = cpu_to_be32(NULLAGBLOCK);
 	}
 
-	freelist = xfs_buf_to_agfl_bno(agfl_buf);
-
 	/*
 	 * do we have left-over blocks in the btree cursors that should
 	 * be used to fill the AGFL?
Signature · 1 line
2.26.2
#26 lore raw

Re: [PATCH 7/8] repair: cleanup build_agf_agfl

Quoted 14 lines · Darrick J. Wong
Quoted 13 lines · Christoph Hellwig

No need to have two variables for the AGFL block number array.

---
 repair/phase5.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
repair/phase5.c +0 -0
index 17b57448..677297fe 100644
@@ -2149,18 +2149,15 @@ build_agf_agfl(
 
Quoted 6 lines

repair/phase5.c build_agf_agfl( · line 2151

Quoted 2 lines
repair/phase5.c +0 -0
 	/* setting to 0xff results in initialisation to NULLAGBLOCK */
 	memset(agfl, 0xff, mp->m_sb.sb_sectsize);

/me wonders why this memset isn't sufficient to null out the freelist, but a better cleanup would be to rip all this out in favor of adapting the nearly identical functions in xfs_ag.c.

probably because xfs_agflblock_init is

a) static and
b) expects a aghdr_init_data *id arg which isn't too convenient here I guess

Might be nice to factor xfs_agflblock_init to call a helper that this and build_agf_agfl can both use though, I'll give that a whirl.

-Eric

Quoted 27 lines

In the meantime we don't need duplicate variables, and:

--D

Quoted 20 lines
repair/phase5.c +2 -5
+	freelist = xfs_buf_to_agfl_bno(agfl_buf);
 	if (xfs_sb_version_hascrc(&mp->m_sb)) {
-		__be32 *agfl_bno = xfs_buf_to_agfl_bno(agfl_buf);
-
 		agfl->agfl_magicnum = cpu_to_be32(XFS_AGFL_MAGIC);
 		agfl->agfl_seqno = cpu_to_be32(agno);
 		platform_uuid_copy(&agfl->agfl_uuid, &mp->m_sb.sb_meta_uuid);
 		for (i = 0; i < libxfs_agfl_size(mp); i++)
-			agfl_bno[i] = cpu_to_be32(NULLAGBLOCK);
+			freelist[i] = cpu_to_be32(NULLAGBLOCK);
 	}
 
-	freelist = xfs_buf_to_agfl_bno(agfl_buf);
-
 	/*
 	 * do we have left-over blocks in the btree cursors that should
 	 * be used to fill the AGFL?
Signature · 1 line
2.26.2
#27 lore raw

PATCH 8/8 metadump: small cleanup for process_inode

In reply to Christoph Hellwig

Shorten a conditional to a single line.

---
 db/metadump.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
db/metadump.c +1 -2
index 14e7eaa7..e5cb3aa5 100644
@@ -2415,8 +2415,7 @@ process_inode(
 	nametable_clear();
 
 	/* copy extended attributes if they exist and forkoff is valid */
-	if (success &&
-	    XFS_DFORK_DSIZE(dip, mp) < XFS_LITINO(mp)) {
+	if (success && XFS_DFORK_DSIZE(dip, mp) < XFS_LITINO(mp)) {
 		attr_data.remote_val_count = 0;
 		switch (dip->di_aformat) {
 			case XFS_DINODE_FMT_LOCAL:
Signature · 1 line
2.26.2
Reviewed-by on v1 8/8
#28 lore raw

Re: [PATCH 8/8] metadump: small cleanup for process_inode

Quoted 3 lines · Christoph Hellwig

Shorten a conditional to a single line.

Looks good,

--D

Quoted 21 lines
---
 db/metadump.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
db/metadump.c +1 -2
index 14e7eaa7..e5cb3aa5 100644
@@ -2415,8 +2415,7 @@ process_inode(
 	nametable_clear();
 
 	/* copy extended attributes if they exist and forkoff is valid */
-	if (success &&
-	    XFS_DFORK_DSIZE(dip, mp) < XFS_LITINO(mp)) {
+	if (success && XFS_DFORK_DSIZE(dip, mp) < XFS_LITINO(mp)) {
 		attr_data.remote_val_count = 0;
 		switch (dip->di_aformat) {
 			case XFS_DINODE_FMT_LOCAL:
Signature · 1 line
2.26.2
#29 lore raw
In reply to Christoph Hellwig
Quoted 4 lines · Christoph Hellwig

Hi Eric,

this series contains the differences to my port that seem useful to keep.

I staged all of these except:

11538453 New          [4/8] db: cleanup attr_set_f and attr_remove_f
11538455 New          [5/8] db: validate name and namelen in attr_set_f and attr_remove_f
11538457 New          [6/8] db: ensure that create and replace are exclusive in attr_set_f

because i'm not sure about patch 4/8; because the structure bits that need initialization differ a bit between set and remove, and because the initial backport missed a couple initializations, I feel like initializing the structure just before the libxfs call might be more obvious in terms of what's getting passed in.

(however, if we keep that I should make the attr_filter variable work the same way)

patches 5 and 6 just depend on the decision re: patch 4.

thanks,
-Eric