Skip to content

Commit

Permalink
zpool: flush output before sleeping
Browse files Browse the repository at this point in the history
Several zpool commands (status, list, iostat) have modes that present
some information, sleep a while, present the current state, sleep, etc.
Some of those had ways to invoke them that when piped would appear to do
nothing for a while, because non-terminals are block-buffered, not
line-buffered, by default.  Fix this by forcing a flush before sleeping.

In particular, all of these buffered:
- zpool status <pool> <interval>
- zpool iostat -y<m> <pool> <interval>
- zpool list <pool> <interval>

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <robn@despairlabs.com>
Closes openzfs#15593
  • Loading branch information
robn authored and lundman committed Dec 12, 2023
1 parent 7d97a6e commit cc33e0e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5950,6 +5950,7 @@ zpool_do_iostat(int argc, char **argv)
print_iostat_header(&cb);

if (skip) {
(void) fflush(stdout);
(void) fsleep(interval);
continue;
}
Expand Down Expand Up @@ -5980,18 +5981,13 @@ zpool_do_iostat(int argc, char **argv)

}

/*
* Flush the output so that redirection to a file isn't buffered
* indefinitely.
*/
(void) fflush(stdout);

if (interval == 0)
break;

if (count != 0 && --count == 0)
break;

(void) fflush(stdout);
(void) fsleep(interval);
}

Expand Down Expand Up @@ -6514,6 +6510,8 @@ zpool_do_list(int argc, char **argv)
break;

pool_list_free(list);

(void) fflush(stdout);
(void) fsleep(interval);
}

Expand Down Expand Up @@ -9094,6 +9092,7 @@ zpool_do_status(int argc, char **argv)
if (count != 0 && --count == 0)
break;

(void) fflush(stdout);
(void) fsleep(interval);
}

Expand Down

0 comments on commit cc33e0e

Please sign in to comment.