Skip to contentSkip to conversation

xfsprogs: merge the duplicated condition in xfs_mkfs.c/validate_ag_geometry

PATCH In review Wang Sheng-Hui 2 participants 3 messages May 28, 2015 – May 29, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfsprogs: merge the duplicated condition in xfs_mkfs.c/validate_ag_geometry

Some conditions are duplicated. Merge them.

---
 mkfs/xfs_mkfs.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)
mkfs/xfs_mkfs.c +8 -16
index e2a052d..7ec2556 100644
@@ -740,22 +740,6 @@ validate_ag_geometry(
 	__uint64_t	agsize,
 	__uint64_t	agcount)
 {
-	if (agsize < XFS_AG_MIN_BLOCKS(blocklog)) {
-		fprintf(stderr,
-	_("agsize (%lld blocks) too small, need at least %lld blocks\n"),
-			(long long)agsize,
-			(long long)XFS_AG_MIN_BLOCKS(blocklog));
-		usage();
-	}
-
-	if (agsize > XFS_AG_MAX_BLOCKS(blocklog)) {
-		fprintf(stderr,
-	_("agsize (%lld blocks) too big, maximum is %lld blocks\n"),
-			(long long)agsize,
-			(long long)XFS_AG_MAX_BLOCKS(blocklog));
-		usage();
-	}
-
 	if (agsize > dblocks) {
 		fprintf(stderr,
 	_("agsize (%lld blocks) too big, data area is %lld blocks\n"),
@@ -765,6 +749,10 @@ validate_ag_geometry(
 
 	if (agsize < XFS_AG_MIN_BLOCKS(blocklog)) {
 		fprintf(stderr,
+	_("agsize (%lld blocks) too small, need at least %lld blocks\n"),
+			(long long)agsize,
+			(long long)XFS_AG_MIN_BLOCKS(blocklog));
+		fprintf(stderr,
 	_("too many allocation groups for size = %lld\n"),
 				(long long)agsize);
 		fprintf(stderr, _("need at most %lld allocation groups\n"),
@@ -775,6 +763,10 @@ validate_ag_geometry(
 
 	if (agsize > XFS_AG_MAX_BLOCKS(blocklog)) {
 		fprintf(stderr,
+	_("agsize (%lld blocks) too big, maximum is %lld blocks\n"),
+			(long long)agsize,
+			(long long)XFS_AG_MAX_BLOCKS(blocklog));
+		fprintf(stderr,
 	_("too few allocation groups for size = %lld\n"), (long long)agsize);
 		fprintf(stderr,
 	_("need at least %lld allocation groups\n"),
Signature · 9 lines
1.8.3.2




_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#1 lore raw
Quoted 1 line · Wang Sheng-Hui

Some conditions are duplicated. Merge them.

While you are correct that they are duplicated, simply combining them doesn't mkae a lot of sense; now we'll get this sort of error message:

Quoted 3 lines

agsize (%lld blocks) too small, need at least %lld blocks too many allocation groups for size = %lld
need at most %lld allocation groups

and what should a user do with that information? It's somewhat nonsensical.

The code as it is today, and as it has been since commit 1f1b8be7926480046ead7b98c9850ace7bcd82a3, doesn't make much sense, because we can never hit the second conditional. But simply combining them doesn't look like the right answer to me.

If you look at the above commit, what it used to do was something like:

- /*

-                * If the specified agsize is too small, or too large,
-                * complain.
-                */

- if (agsize < XFS_AG_MIN_BLOCKS(blocklog)) {
- fprintf(stderr,
- _("agsize (%lldb) too small, need at least %lld blocks\n"),
- (long long)agsize,
- (long long)XFS_AG_MIN_BLOCKS(blocklog));
- usage();
- }

<snip>

- /*

-        * If the ag size is too small, complain if agcount/agsize was
-        * specified, and fix it otherwise.
-        */

- if (agsize < XFS_AG_MIN_BLOCKS(blocklog)) {
- if (daflag || dasize) {
- fprintf(stderr,
- _("too many allocation groups for size = %lld\n"),
- (long long)agsize);
- fprintf(stderr,

-                               _("need at most %lld allocation groups\n"),
-                               (long long)
-                               (dblocks / XFS_AG_MIN_BLOCKS(blocklog) +
-                               (dblocks % XFS_AG_MIN_BLOCKS(blocklog) != 0)));

...

I *think* the intent was to use different messages based on what was specified by the user; i.e. if agsize was specified, and is too small, then say:

Quoted 1 line

agsize (%lld blocks) too small, need at least %lld blocks

but if agcount was specified, and was too large, then say:

Quoted 2 lines

too many allocation groups for size = %lld
need at most %lld allocation groups

but combining those two messages doesn't make sense to me.

-Eric

Quoted 45 lines
---
 mkfs/xfs_mkfs.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)
mkfs/xfs_mkfs.c +4 -16
index e2a052d..7ec2556 100644
@@ -740,22 +740,6 @@ validate_ag_geometry(
 	__uint64_t	agsize,
 	__uint64_t	agcount)
 {
-	if (agsize < XFS_AG_MIN_BLOCKS(blocklog)) {
-		fprintf(stderr,
-	_("agsize (%lld blocks) too small, need at least %lld blocks\n"),
-			(long long)agsize,
-			(long long)XFS_AG_MIN_BLOCKS(blocklog));
-		usage();
-	}
-
-	if (agsize > XFS_AG_MAX_BLOCKS(blocklog)) {
-		fprintf(stderr,
-	_("agsize (%lld blocks) too big, maximum is %lld blocks\n"),
-			(long long)agsize,
-			(long long)XFS_AG_MAX_BLOCKS(blocklog));
-		usage();
-	}
-
 	if (agsize > dblocks) {
 		fprintf(stderr,
 	_("agsize (%lld blocks) too big, data area is %lld blocks\n"),
@@ -765,6 +749,10 @@ validate_ag_geometry(
 
 	if (agsize < XFS_AG_MIN_BLOCKS(blocklog)) {
 		fprintf(stderr,
+	_("agsize (%lld blocks) too small, need at least %lld blocks\n"),
+			(long long)agsize,
+			(long long)XFS_AG_MIN_BLOCKS(blocklog));
+		fprintf(stderr,
 	_("too many allocation groups for size = %lld\n"),
 				(long long)agsize);
 		fprintf(stderr, _("need at most %lld allocation groups\n"),

mkfs/xfs_mkfs.c validate_ag_geometry( · line 772

Quoted 10 lines
mkfs/xfs_mkfs.c +4 -0
@@ -775,6 +763,10 @@ validate_ag_geometry(
 
 	if (agsize > XFS_AG_MAX_BLOCKS(blocklog)) {
 		fprintf(stderr,
+	_("agsize (%lld blocks) too big, maximum is %lld blocks\n"),
+			(long long)agsize,
+			(long long)XFS_AG_MAX_BLOCKS(blocklog));
+		fprintf(stderr,
 	_("too few allocation groups for size = %lld\n"), (long long)agsize);
 		fprintf(stderr,
 	_("need at least %lld allocation groups\n"),

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

#2 lore raw
Quoted 57 lines · Eric Sandeen
Quoted 1 line · Wang Sheng-Hui

Some conditions are duplicated. Merge them.

While you are correct that they are duplicated, simply combining them doesn't mkae a lot of sense; now we'll get this sort of error message:

Quoted 3 lines

agsize (%lld blocks) too small, need at least %lld blocks too many allocation groups for size = %lld
need at most %lld allocation groups

and what should a user do with that information? It's somewhat nonsensical.

The code as it is today, and as it has been since commit 1f1b8be7926480046ead7b98c9850ace7bcd82a3, doesn't make much sense, because we can never hit the second conditional. But simply combining them doesn't look like the right answer to me.

If you look at the above commit, what it used to do was something like:

(quoted diff) +0 -25
-               /*
-                * If the specified agsize is too small, or too large,
-                * complain.
-                */
-               if (agsize < XFS_AG_MIN_BLOCKS(blocklog)) {
-                       fprintf(stderr,
-               _("agsize (%lldb) too small, need at least %lld blocks\n"),
-                               (long long)agsize,
-                               (long long)XFS_AG_MIN_BLOCKS(blocklog));
-                       usage();
-               }
 
<snip>
 
-       /*
-        * If the ag size is too small, complain if agcount/agsize was
-        * specified, and fix it otherwise.
-        */
-       if (agsize < XFS_AG_MIN_BLOCKS(blocklog)) {
-               if (daflag || dasize) {
-                       fprintf(stderr,
-                       _("too many allocation groups for size = %lld\n"),
-                               (long long)agsize);
-                       fprintf(stderr,
-                               _("need at most %lld allocation groups\n"),
-                               (long long)
-                               (dblocks / XFS_AG_MIN_BLOCKS(blocklog) +
-                               (dblocks % XFS_AG_MIN_BLOCKS(blocklog) != 0)));
 
...

I *think* the intent was to use different messages based on what was specified by the user; i.e. if agsize was specified, and is too small, then say:

Quoted 9 lines
Quoted 1 line

agsize (%lld blocks) too small, need at least %lld blocks

but if agcount was specified, and was too large, then say:

Quoted 2 lines

too many allocation groups for size = %lld
need at most %lld allocation groups

but combining those two messages doesn't make sense to me.

Got it, Eric.

Regards,
Sheng-Hui

Quoted 48 lines

-Eric

Quoted 45 lines
---
 mkfs/xfs_mkfs.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)
mkfs/xfs_mkfs.c +4 -16
index e2a052d..7ec2556 100644
@@ -740,22 +740,6 @@ validate_ag_geometry(
 	__uint64_t	agsize,
 	__uint64_t	agcount)
 {
-	if (agsize < XFS_AG_MIN_BLOCKS(blocklog)) {
-		fprintf(stderr,
-	_("agsize (%lld blocks) too small, need at least %lld blocks\n"),
-			(long long)agsize,
-			(long long)XFS_AG_MIN_BLOCKS(blocklog));
-		usage();
-	}
-
-	if (agsize > XFS_AG_MAX_BLOCKS(blocklog)) {
-		fprintf(stderr,
-	_("agsize (%lld blocks) too big, maximum is %lld blocks\n"),
-			(long long)agsize,
-			(long long)XFS_AG_MAX_BLOCKS(blocklog));
-		usage();
-	}
-
 	if (agsize > dblocks) {
 		fprintf(stderr,
 	_("agsize (%lld blocks) too big, data area is %lld blocks\n"),
@@ -765,6 +749,10 @@ validate_ag_geometry(
 
 	if (agsize < XFS_AG_MIN_BLOCKS(blocklog)) {
 		fprintf(stderr,
+	_("agsize (%lld blocks) too small, need at least %lld blocks\n"),
+			(long long)agsize,
+			(long long)XFS_AG_MIN_BLOCKS(blocklog));
+		fprintf(stderr,
 	_("too many allocation groups for size = %lld\n"),
 				(long long)agsize);
 		fprintf(stderr, _("need at most %lld allocation groups\n"),
@@ -775,6 +763,10 @@ validate_ag_geometry(
 
Quoted 13 lines

mkfs/xfs_mkfs.c validate_ag_geometry( · line 772

Quoted 10 lines
mkfs/xfs_mkfs.c +4 -0
 	if (agsize > XFS_AG_MAX_BLOCKS(blocklog)) {
 		fprintf(stderr,
+	_("agsize (%lld blocks) too big, maximum is %lld blocks\n"),
+			(long long)agsize,
+			(long long)XFS_AG_MAX_BLOCKS(blocklog));
+		fprintf(stderr,
 	_("too few allocation groups for size = %lld\n"), (long long)agsize);
 		fprintf(stderr,
 	_("need at least %lld allocation groups\n"),

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