Skip to contentSkip to conversation

xfs_repair: don't use do_warn for normal log message

PATCH Superseded Masatake YAMATO 2 participants 3 messages Sep 13, 2017 – Sep 14, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs_repair: don't use do_warn for normal log message

In some case, exit statuses of xfs_repair -n are different even for the same file system when -v is specified or not. This patch fixes this behavior.

If -v is specified, do_warn() is used in zero_log() for printing a normal message. That makes the exit status to 1 though there is no dirtiness in the file system.

The original zero_log():

	error = xlog_find_tail(log, &head_blk, &tail_blk);
	if (error) {...
	} else {
		if (verbose) {
			do_warn(
	_("zero_log: head block %" PRId64 " tail block %" PRId64 "\n"),
				head_blk, tail_blkn);
		}

do_warn() is used for the message, "zero_log:...". do_log should be used instead because this log message is for just reporting the values of head_blk, and tail_blk. do_log is for "just reporting".

Using do_warn unintentionally has an impact. It causes the exit status of the command. do_warn sets fs_is_dirty global variable.
That refers in main function to decide the exit status.

    void
    do_warn(char const *msg, ...)
    {
	    va_list args;

	    fs_is_dirty = 1;

    int
    main(int argc, char **argv)
    {
    ...

		    if (fs_is_dirty)
			    return(1);
---
 repair/phase2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
repair/phase2.c +1 -1
index c21778b8..f7ea655f 100644
@@ -75,7 +75,7 @@ zero_log(
 	 */
 	error = xlog_find_tail(log, &head_blk, &tail_blk);
 	if (error) {
-		do_warn(
+		do_log(
 		_("zero_log: cannot find log head/tail (xlog_find_tail=%d)\n"),
 			error);
 		if (!no_modify && !zap_log)
Signature · 1 line
2.13.5
#1 lore raw
Quoted 51 lines · Masatake YAMATO

In some case, exit statuses of xfs_repair -n are different even for the same file system when -v is specified or not. This patch fixes this behavior.

If -v is specified, do_warn() is used in zero_log() for printing a normal message. That makes the exit status to 1 though there is no dirtiness in the file system.

The original zero_log():

	error = xlog_find_tail(log, &head_blk, &tail_blk);
	if (error) {...
	} else {
		if (verbose) {
			do_warn(
	_("zero_log: head block %" PRId64 " tail block %" PRId64 "\n"),
				head_blk, tail_blkn);
		}

do_warn() is used for the message, "zero_log:...". do_log should be used instead because this log message is for just reporting the values of head_blk, and tail_blk. do_log is for "just reporting".

Using do_warn unintentionally has an impact. It causes the exit status of the command. do_warn sets fs_is_dirty global variable.
That refers in main function to decide the exit status.

    void
    do_warn(char const *msg, ...)
    {
	    va_list args;

	    fs_is_dirty = 1;

    int
    main(int argc, char **argv)
    {
    ...

		    if (fs_is_dirty)
			    return(1);
---
 repair/phase2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
repair/phase2.c +0 -0
index c21778b8..f7ea655f 100644

repair/phase2.c zero_log( · line 81

Quoted 8 lines
repair/phase2.c +1 -1
@@ -75,7 +75,7 @@ zero_log(
 	 */
 	error = xlog_find_tail(log, &head_blk, &tail_blk);
 	if (error) {
-		do_warn(
+		do_log(
 		_("zero_log: cannot find log head/tail (xlog_find_tail=%d)\n"),
 			error);
 		if (!no_modify && !zap_log)

The code change doesn't match the code in commit description. This warning looks like a warning that needs to be issued and change the exist status - it indicates that there is a problem with the log.

Indeed, the commit description does not even need the code in it; reviewers are familiar with the difference between do_warn/do_log. What the commit message needs to do is explain when the problem occurs, what it's impact is and why it needs fixing. The code fix should then be obvious and self explanitory....

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#2 lore raw
Quoted 65 lines · Dave Chinner
Quoted 51 lines · Masatake YAMATO

In some case, exit statuses of xfs_repair -n are different even for the same file system when -v is specified or not. This patch fixes this behavior.

If -v is specified, do_warn() is used in zero_log() for printing a normal message. That makes the exit status to 1 though there is no dirtiness in the file system.

The original zero_log():

	error = xlog_find_tail(log, &head_blk, &tail_blk);
	if (error) {...
	} else {
		if (verbose) {
			do_warn(
	_("zero_log: head block %" PRId64 " tail block %" PRId64 "\n"),
				head_blk, tail_blkn);
		}

do_warn() is used for the message, "zero_log:...". do_log should be used instead because this log message is for just reporting the values of head_blk, and tail_blk. do_log is for "just reporting".

Using do_warn unintentionally has an impact. It causes the exit status of the command. do_warn sets fs_is_dirty global variable.
That refers in main function to decide the exit status.

    void
    do_warn(char const *msg, ...)
    {
	    va_list args;

	    fs_is_dirty = 1;

    int
    main(int argc, char **argv)
    {
    ...

		    if (fs_is_dirty)
			    return(1);
---
 repair/phase2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
repair/phase2.c +0 -0
index c21778b8..f7ea655f 100644

repair/phase2.c zero_log( · line 81

Quoted 8 lines
repair/phase2.c +1 -1
@@ -75,7 +75,7 @@ zero_log(
 	 */
 	error = xlog_find_tail(log, &head_blk, &tail_blk);
 	if (error) {
-		do_warn(
+		do_log(
 		_("zero_log: cannot find log head/tail (xlog_find_tail=%d)\n"),
 			error);
 		if (!no_modify && !zap_log)

The code change doesn't match the code in commit description. This warning looks like a warning that needs to be issued and change the exist status - it indicates that there is a problem with the log.

Quoted 5 lines

Indeed, the commit description does not even need the code in it; reviewers are familiar with the difference between do_warn/do_log. What the commit message needs to do is explain when the problem occurs, what it's impact is and why it needs fixing. The code fix should then be obvious and self explanitory....

Thank you for comments.

How about [PATCH v2] I submited just after submitting this [PATCH]? I think the change in [PATCH v2] makes sense. If the commit log in [PATCH v2] is not clear enough, I will submit v3.

Regards,
Masatake YAMATO

Quoted 6 lines

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]