All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] filefrag: fix minor issues with 29758d2
@ 2014-05-29 17:25 Eric Sandeen
  2014-05-29 17:29 ` Eric Sandeen
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Eric Sandeen @ 2014-05-29 17:25 UTC (permalink / raw)
  To: ext4 development; +Cc: Andreas Dilger

29758d2 filefrag: exit with error code if an error is hit

introduced a couple errors; in one case it missed returning
a value, and in the other used a test where it needed an
assignment.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

diff --git a/misc/filefrag.c b/misc/filefrag.c
index 37c4416..b2826ad 100644
--- a/misc/filefrag.c
+++ b/misc/filefrag.c
@@ -387,8 +387,9 @@ static int frag_report(const char *filename)
 	if (last_device != st.st_dev) {
 		if (fstatfs(fd, &fsinfo) < 0) {
 			close(fd);
+			rc = -errno;
 			perror("fstatfs");
-			return;
+			return rc;
 		}
 		if (verbose)
 			printf("Filesystem type is: %lx\n",
@@ -556,7 +557,7 @@ int main(int argc, char**argv)
 		int rc2 = frag_report(*cpp);
 
 		if (rc2 < 0 && rc == 0)
-			rc == rc2;
+			rc = rc2;
 	}
 
 	return rc;


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] filefrag: fix minor issues with 29758d2
  2014-05-29 17:25 [PATCH] filefrag: fix minor issues with 29758d2 Eric Sandeen
@ 2014-05-29 17:29 ` Eric Sandeen
  2014-05-29 17:34 ` Lukáš Czerner
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Eric Sandeen @ 2014-05-29 17:29 UTC (permalink / raw)
  To: ext4 development; +Cc: Andreas Dilger

On 5/29/14, 12:25 PM, Eric Sandeen wrote:
> 29758d2 filefrag: exit with error code if an error is hit
> 
> introduced a couple errors; in one case it missed returning
> a value, and in the other used a test where it needed an
> assignment.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
> 
> diff --git a/misc/filefrag.c b/misc/filefrag.c
> index 37c4416..b2826ad 100644
> --- a/misc/filefrag.c
> +++ b/misc/filefrag.c
> @@ -387,8 +387,9 @@ static int frag_report(const char *filename)
>  	if (last_device != st.st_dev) {
>  		if (fstatfs(fd, &fsinfo) < 0) {
>  			close(fd);
> +			rc = -errno;
>  			perror("fstatfs");
> -			return;
> +			return rc;
>  		}

And as an aside, here and other places where we do:

if (syscall() < 0) {
	close (fd);
	rc = -errno;
	perror("syscall");
	return rc;
}

we actually run the risk of close failing, and getting errno/perror from THAT,
but *shrug* for now...

-Eric

>  		if (verbose)
>  			printf("Filesystem type is: %lx\n",
> @@ -556,7 +557,7 @@ int main(int argc, char**argv)
>  		int rc2 = frag_report(*cpp);
>  
>  		if (rc2 < 0 && rc == 0)
> -			rc == rc2;
> +			rc = rc2;
>  	}
>  
>  	return rc;
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] filefrag: fix minor issues with 29758d2
  2014-05-29 17:25 [PATCH] filefrag: fix minor issues with 29758d2 Eric Sandeen
  2014-05-29 17:29 ` Eric Sandeen
@ 2014-05-29 17:34 ` Lukáš Czerner
  2014-05-29 17:42   ` Eric Sandeen
  2014-05-29 17:40 ` [PATCH V2] filefrag: fix " Eric Sandeen
  2014-05-30 18:10 ` [PATCH V3] filefrag: " Eric Sandeen
  3 siblings, 1 reply; 9+ messages in thread
From: Lukáš Czerner @ 2014-05-29 17:34 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: ext4 development, Andreas Dilger

On Thu, 29 May 2014, Eric Sandeen wrote:

> Date: Thu, 29 May 2014 12:25:17 -0500
> From: Eric Sandeen <sandeen@redhat.com>
> To: ext4 development <linux-ext4@vger.kernel.org>
> Cc: Andreas Dilger <adilger@dilger.ca>
> Subject: [PATCH] filefrag: fix minor issues with 29758d2
> 
> 29758d2 filefrag: exit with error code if an error is hit
> 
> introduced a couple errors; in one case it missed returning
> a value, and in the other used a test where it needed an
> assignment.

Looks good, although I wonder if we can just return -errno or goto
out_close ? (same with fstat failure).

Thanks!
-Lukas

> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
> 
> diff --git a/misc/filefrag.c b/misc/filefrag.c
> index 37c4416..b2826ad 100644
> --- a/misc/filefrag.c
> +++ b/misc/filefrag.c
> @@ -387,8 +387,9 @@ static int frag_report(const char *filename)
>  	if (last_device != st.st_dev) {
>  		if (fstatfs(fd, &fsinfo) < 0) {
>  			close(fd);
> +			rc = -errno;
>  			perror("fstatfs");
> -			return;
> +			return rc;
>  		}
>  		if (verbose)
>  			printf("Filesystem type is: %lx\n",
> @@ -556,7 +557,7 @@ int main(int argc, char**argv)
>  		int rc2 = frag_report(*cpp);
>  
>  		if (rc2 < 0 && rc == 0)
> -			rc == rc2;
> +			rc = rc2;
>  	}
>  
>  	return rc;
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH V2] filefrag: fix issues with 29758d2
  2014-05-29 17:25 [PATCH] filefrag: fix minor issues with 29758d2 Eric Sandeen
  2014-05-29 17:29 ` Eric Sandeen
  2014-05-29 17:34 ` Lukáš Czerner
@ 2014-05-29 17:40 ` Eric Sandeen
  2014-05-30  6:45   ` Andreas Dilger
  2014-05-30 18:10 ` [PATCH V3] filefrag: " Eric Sandeen
  3 siblings, 1 reply; 9+ messages in thread
From: Eric Sandeen @ 2014-05-29 17:40 UTC (permalink / raw)
  To: ext4 development; +Cc: Andreas Dilger

29758d2 filefrag: exit with error code if an error is hit

introduced a couple errors; in one case it missed returning
a value, and in the other used a test where it needed an
assignment.

Also fix a precedence problem with:

	if (fe_flags & mask == 0)

which is equivalent to:

	if (fe_flags & (mask == 0))

but we need:

	if ((fe_flags & mask) == 0)

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

diff --git a/misc/filefrag.c b/misc/filefrag.c
index 37c4416..1d05f47 100644
--- a/misc/filefrag.c
+++ b/misc/filefrag.c
@@ -175,7 +175,7 @@ static void print_extent_info(struct fiemap_extent *fm_extent, int cur_ex,
 	for (mask = 1; fe_flags != 0 && mask != 0; mask <<= 1) {
 		char hex[6];
 
-		if (fe_flags & mask == 0)
+		if ((fe_flags & mask) == 0)
 			continue;
 		sprintf(hex, "%#04x,", mask);
 		print_flag(&fe_flags, mask, flags, hex);
@@ -387,8 +387,9 @@ static int frag_report(const char *filename)
 	if (last_device != st.st_dev) {
 		if (fstatfs(fd, &fsinfo) < 0) {
 			close(fd);
+			rc = -errno;
 			perror("fstatfs");
-			return;
+			return rc;
 		}
 		if (verbose)
 			printf("Filesystem type is: %lx\n",
@@ -556,7 +557,7 @@ int main(int argc, char**argv)
 		int rc2 = frag_report(*cpp);
 
 		if (rc2 < 0 && rc == 0)
-			rc == rc2;
+			rc = rc2;
 	}
 
 	return rc;


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] filefrag: fix minor issues with 29758d2
  2014-05-29 17:34 ` Lukáš Czerner
@ 2014-05-29 17:42   ` Eric Sandeen
  0 siblings, 0 replies; 9+ messages in thread
From: Eric Sandeen @ 2014-05-29 17:42 UTC (permalink / raw)
  To: Lukáš Czerner; +Cc: ext4 development, Andreas Dilger

On 5/29/14, 12:34 PM, Lukáš Czerner wrote:
> On Thu, 29 May 2014, Eric Sandeen wrote:
> 
>> Date: Thu, 29 May 2014 12:25:17 -0500
>> From: Eric Sandeen <sandeen@redhat.com>
>> To: ext4 development <linux-ext4@vger.kernel.org>
>> Cc: Andreas Dilger <adilger@dilger.ca>
>> Subject: [PATCH] filefrag: fix minor issues with 29758d2
>>
>> 29758d2 filefrag: exit with error code if an error is hit
>>
>> introduced a couple errors; in one case it missed returning
>> a value, and in the other used a test where it needed an
>> assignment.
> 
> Looks good, although I wonder if we can just return -errno or goto
> out_close ? (same with fstat failure).

Perhaps; I was just following the style of the error handling block
before it, rather than refactoring w/ gotos and such.  :)

Going for the "small fix."

-Eric

> Thanks!
> -Lukas
> 
>>
>> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
>> ---
>>
>> diff --git a/misc/filefrag.c b/misc/filefrag.c
>> index 37c4416..b2826ad 100644
>> --- a/misc/filefrag.c
>> +++ b/misc/filefrag.c
>> @@ -387,8 +387,9 @@ static int frag_report(const char *filename)
>>  	if (last_device != st.st_dev) {
>>  		if (fstatfs(fd, &fsinfo) < 0) {
>>  			close(fd);
>> +			rc = -errno;
>>  			perror("fstatfs");
>> -			return;
>> +			return rc;
>>  		}
>>  		if (verbose)
>>  			printf("Filesystem type is: %lx\n",
>> @@ -556,7 +557,7 @@ int main(int argc, char**argv)
>>  		int rc2 = frag_report(*cpp);
>>  
>>  		if (rc2 < 0 && rc == 0)
>> -			rc == rc2;
>> +			rc = rc2;
>>  	}
>>  
>>  	return rc;
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH V2] filefrag: fix issues with 29758d2
  2014-05-29 17:40 ` [PATCH V2] filefrag: fix " Eric Sandeen
@ 2014-05-30  6:45   ` Andreas Dilger
  0 siblings, 0 replies; 9+ messages in thread
From: Andreas Dilger @ 2014-05-30  6:45 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: ext4 development

[-- Attachment #1: Type: text/plain, Size: 1991 bytes --]

On May 29, 2014, at 11:40 AM, Eric Sandeen <sandeen@redhat.com> wrote:
> 29758d2 filefrag: exit with error code if an error is hit
> 
> introduced a couple errors; in one case it missed returning
> a value, and in the other used a test where it needed an
> assignment.
> 
> Also fix a precedence problem with:
> 
> 	if (fe_flags & mask == 0)
> 
> which is equivalent to:
> 
> 	if (fe_flags & (mask == 0))
> 
> but we need:
> 
> 	if ((fe_flags & mask) == 0)

Strange.  I'm pretty sure I fixed this, because it was causing every
flag to be printed, but I guess I sent the wrong version or something.
Thanks for fixing this.

> diff --git a/misc/filefrag.c b/misc/filefrag.c
> index 37c4416..1d05f47 100644
> --- a/misc/filefrag.c
> +++ b/misc/filefrag.c
> @@ -175,7 +175,7 @@ static void print_extent_info(struct fiemap_extent *fm_extent, int cur_ex,
> 	for (mask = 1; fe_flags != 0 && mask != 0; mask <<= 1) {
> 		char hex[6];
> 
> -		if (fe_flags & mask == 0)
> +		if ((fe_flags & mask) == 0)
> 			continue;
> 		sprintf(hex, "%#04x,", mask);
> 		print_flag(&fe_flags, mask, flags, hex);
> @@ -387,8 +387,9 @@ static int frag_report(const char *filename)
> 	if (last_device != st.st_dev) {
> 		if (fstatfs(fd, &fsinfo) < 0) {
> 			close(fd);
> +			rc = -errno;

Would be better to move this above close(), instead of introducing
another case of the potential error you mentioned.

Cheers, Andreas

> 			perror("fstatfs");
> -			return;
> +			return rc;
> 		}
> 		if (verbose)
> 			printf("Filesystem type is: %lx\n",
> @@ -556,7 +557,7 @@ int main(int argc, char**argv)
> 		int rc2 = frag_report(*cpp);
> 
> 		if (rc2 < 0 && rc == 0)
> -			rc == rc2;
> +			rc = rc2;
> 	}
> 
> 	return rc;
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH V3] filefrag: filefrag: fix issues with 29758d2
  2014-05-29 17:25 [PATCH] filefrag: fix minor issues with 29758d2 Eric Sandeen
                   ` (2 preceding siblings ...)
  2014-05-29 17:40 ` [PATCH V2] filefrag: fix " Eric Sandeen
@ 2014-05-30 18:10 ` Eric Sandeen
  2014-05-30 21:03   ` Andreas Dilger
  3 siblings, 1 reply; 9+ messages in thread
From: Eric Sandeen @ 2014-05-30 18:10 UTC (permalink / raw)
  To: ext4 development; +Cc: Andreas Dilger

29758d2 filefrag: exit with error code if an error is hit

introduced a couple errors; in one case it missed returning
a value, and possibly picked up errno from (unchecked) close(),
and in the other used a test where it needed an
assignment.  So capture the error, move perror() directly
after the failed call in both cases, and fix the assignment.

Also fix a precedence problem with:

	if (fe_flags & mask == 0)

which is equivalent to:

	if (fe_flags & (mask == 0))

but we need:

	if ((fe_flags & mask) == 0)

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

diff --git a/misc/filefrag.c b/misc/filefrag.c
index 37c4416..820821b 100644
--- a/misc/filefrag.c
+++ b/misc/filefrag.c
@@ -175,7 +175,7 @@ static void print_extent_info(struct fiemap_extent *fm_extent, int cur_ex,
 	for (mask = 1; fe_flags != 0 && mask != 0; mask <<= 1) {
 		char hex[6];
 
-		if (fe_flags & mask == 0)
+		if ((fe_flags & mask) == 0)
 			continue;
 		sprintf(hex, "%#04x,", mask);
 		print_flag(&fe_flags, mask, flags, hex);
@@ -378,17 +378,18 @@ static int frag_report(const char *filename)
 #else
 	if (fstat(fd, &st) < 0) {
 #endif
-		close(fd);
 		rc = -errno;
 		perror("stat");
+		close(fd);
 		return rc;
 	}
 
 	if (last_device != st.st_dev) {
 		if (fstatfs(fd, &fsinfo) < 0) {
-			close(fd);
+			rc = -errno;
 			perror("fstatfs");
-			return;
+			close(fd);
+			return rc;
 		}
 		if (verbose)
 			printf("Filesystem type is: %lx\n",
@@ -556,7 +557,7 @@ int main(int argc, char**argv)
 		int rc2 = frag_report(*cpp);
 
 		if (rc2 < 0 && rc == 0)
-			rc == rc2;
+			rc = rc2;
 	}
 
 	return rc;


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH V3] filefrag: filefrag: fix issues with 29758d2
  2014-05-30 18:10 ` [PATCH V3] filefrag: " Eric Sandeen
@ 2014-05-30 21:03   ` Andreas Dilger
  2014-06-02  1:28     ` Theodore Ts'o
  0 siblings, 1 reply; 9+ messages in thread
From: Andreas Dilger @ 2014-05-30 21:03 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: ext4 development

[-- Attachment #1: Type: text/plain, Size: 1947 bytes --]


On May 30, 2014, at 12:10 PM, Eric Sandeen <sandeen@redhat.com> wrote:

> 29758d2 filefrag: exit with error code if an error is hit
> 
> introduced a couple errors; in one case it missed returning
> a value, and possibly picked up errno from (unchecked) close(),
> and in the other used a test where it needed an
> assignment.  So capture the error, move perror() directly
> after the failed call in both cases, and fix the assignment.
> 
> Also fix a precedence problem with:
> 
> 	if (fe_flags & mask == 0)
> 
> which is equivalent to:
> 
> 	if (fe_flags & (mask == 0))
> 
> but we need:
> 
> 	if ((fe_flags & mask) == 0)
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>

Looks good:

Reviewed-by: Andreas Dilger <adilger@dilger.ca>

> ---
> 
> diff --git a/misc/filefrag.c b/misc/filefrag.c
> index 37c4416..820821b 100644
> --- a/misc/filefrag.c
> +++ b/misc/filefrag.c
> @@ -175,7 +175,7 @@ static void print_extent_info(struct fiemap_extent *fm_extent, int cur_ex,
> 	for (mask = 1; fe_flags != 0 && mask != 0; mask <<= 1) {
> 		char hex[6];
> 
> -		if (fe_flags & mask == 0)
> +		if ((fe_flags & mask) == 0)
> 			continue;
> 		sprintf(hex, "%#04x,", mask);
> 		print_flag(&fe_flags, mask, flags, hex);
> @@ -378,17 +378,18 @@ static int frag_report(const char *filename)
> #else
> 	if (fstat(fd, &st) < 0) {
> #endif
> -		close(fd);
> 		rc = -errno;
> 		perror("stat");
> +		close(fd);
> 		return rc;
> 	}
> 
> 	if (last_device != st.st_dev) {
> 		if (fstatfs(fd, &fsinfo) < 0) {
> -			close(fd);
> +			rc = -errno;
> 			perror("fstatfs");
> -			return;
> +			close(fd);
> +			return rc;
> 		}
> 		if (verbose)
> 			printf("Filesystem type is: %lx\n",
> @@ -556,7 +557,7 @@ int main(int argc, char**argv)
> 		int rc2 = frag_report(*cpp);
> 
> 		if (rc2 < 0 && rc == 0)
> -			rc == rc2;
> +			rc = rc2;
> 	}
> 
> 	return rc;
> 


Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH V3] filefrag: filefrag: fix issues with 29758d2
  2014-05-30 21:03   ` Andreas Dilger
@ 2014-06-02  1:28     ` Theodore Ts'o
  0 siblings, 0 replies; 9+ messages in thread
From: Theodore Ts'o @ 2014-06-02  1:28 UTC (permalink / raw)
  To: Andreas Dilger; +Cc: Eric Sandeen, ext4 development

Thanks, applied.

					- Ted

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-06-02  1:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-29 17:25 [PATCH] filefrag: fix minor issues with 29758d2 Eric Sandeen
2014-05-29 17:29 ` Eric Sandeen
2014-05-29 17:34 ` Lukáš Czerner
2014-05-29 17:42   ` Eric Sandeen
2014-05-29 17:40 ` [PATCH V2] filefrag: fix " Eric Sandeen
2014-05-30  6:45   ` Andreas Dilger
2014-05-30 18:10 ` [PATCH V3] filefrag: " Eric Sandeen
2014-05-30 21:03   ` Andreas Dilger
2014-06-02  1:28     ` Theodore Ts'o

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.