Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'zpool list -v' alignment #8147

Merged
merged 1 commit into from
Dec 4, 2018
Merged

Conversation

behlendorf
Copy link
Contributor

@behlendorf behlendorf commented Nov 21, 2018

Motivation and Context

Issue #7308. The current output of zpool list -v does a terrible
job properly aligning its output. We want to correct that so it's
easy to read at a glance. This change only tackles the major
cosmetic issues and intentionally avoids any extensive refactoring.
There's quite a bit more which could be improved.

Description

The verbose output of 'zpool list' was not correctly aligned due
to differences in the vdev name lengths. Minimally update the
code the correct the alignment using the same strategy employed
by 'zpool status'.

Missing dashes were added for the empty defaults columns, and
the vdev state is now printed for all vdevs.

The ALTROOT properly was removed from the default output to get
close to staying within an 80 character width. At least for
short vdev names.

How Has This Been Tested?

Manually inspected the output for a moderating interesting pool configuration.

BEFORE:

$ zpool list -v
NAME       SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP  HEALTH  ALTROOT
tank              7.50G   888K  7.50G        -         -     0%     0%  1.00x  DEGRADED  -
  mirror          7.50G   888K  7.50G        -         -     0%  0.01%
    vdb               -      -      -        -         -      -      -
    spare             -      -      -        -         -      -      -
      vdc             -      -      -        -         -      -      -
      vdd             -      -      -        -         -      -      -
cache                 -      -      -         -      -      -
  /var/tmp/cache  1020M  17.5K  1019M        -         -     0%  0.00%
spare                 -      -      -         -      -      -
  vdd   

AFTER:

$ zpool list -v
NAME               SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP    HEALTH  ALTROOT
tank              7.50G  1.63M  7.50G        -         -     0%     0%  1.00x  DEGRADED  -
  mirror          7.50G  1.63M  7.50G        -         -     0%  0.02%      -  DEGRADED
    vdb               -      -      -        -         -      -      -      -  ONLINE  
    spare             -      -      -        -         -      -      -      -  DEGRADED
      vdc             -      -      -        -         -      -      -      -  OFFLINE 
      vdd             -      -      -        -         -      -      -      -  ONLINE  
cache                 -      -      -        -         -      -      -      -  -
  /var/tmp/cache  1020M    34K  1019M        -         -     0%  0.00%      -  ONLINE  
spare                 -      -      -        -         -      -      -      -  -
  vdd                 -      -      -        -         -      -      -      -  INUSE 

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (a change to man pages or other documentation)

Checklist:

@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Nov 21, 2018
@codecov
Copy link

codecov bot commented Nov 22, 2018

Codecov Report

Merging #8147 into master will increase coverage by 0.16%.
The diff coverage is 96.15%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8147      +/-   ##
==========================================
+ Coverage   78.45%   78.61%   +0.16%     
==========================================
  Files         378      378              
  Lines      114765   114786      +21     
==========================================
+ Hits        90035    90244     +209     
+ Misses      24730    24542     -188
Flag Coverage Δ
#kernel 78.82% <ø> (+0.18%) ⬆️
#user 67.67% <96.15%> (+0.28%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c40a112...3fe2e50. Read the comment docs.

@behlendorf behlendorf added Status: Revision Needed Changes are required for the PR to be accepted and removed Status: Code Review Needed Ready for review and testing labels Nov 26, 2018
@tonyhutter
Copy link
Contributor

This may be outside the scope of this fixup, but you might want to consider fixing the -H indents as well:

$ sudo ./cmd/zpool/zpool list -v
NAME             SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP  HEALTH
mypool            80M   120K  79.9M        -         -     3%     0%  1.00x  ONLINE
  mirror          80M   120K  79.9M        -         -     3%  0.14%      -  ONLINE
    /tmp/file1      -      -      -        -         -      -      -      -  ONLINE
    /tmp/file2      -      -      -        -         -      -      -      -  ONLINE
logs                -      -      -        -         -      -      -      -  -
  /tmp/file3      80M      0    80M        -         -     0%  0.00%      -  ONLINE
cache               -      -      -        -         -      -      -      -  -
  /tmp/file4    95.5M     1K  95.5M        -         -     0%  0.00%      -  ONLINE

$ sudo ./cmd/zpool/zpool list -vH
mypool	80M	120K	79.9M	-	-	3%	0%	1.00x	ONLINE
	mirror	80M	120K	79.9M	-	-	3%	0.14%	-	ONLINE
	/tmp/file1	-	-	-	-	-	-	-	-	ONLINE
	/tmp/file2	-	-	-	-	-	-	-	-	ONLINE
logs                -      -      -        -         -      -      -      -  -
	/tmp/file3	80M	0	80M	-	-	0%	0.00%	-	ONLINE
cache               -      -      -        -         -      -      -      -  -
	/tmp/file4	95.5M	1K	95.5M	-	-	0%	0.00%	-	ONLINE

int
get_namewidth(zpool_handle_t *zhp, void *data)
static int
get_namewidth(zpool_handle_t *zhp, int *width, int flags, boolean_t verbose)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. What about having get_namewidth() return the width instead of having a separate *width?
  2. Can you add a quick comment above the function deceleration:
    /* Return the length of the pool/vdev name column. */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, after reworking things a little more I think that'll work.

@behlendorf
Copy link
Contributor Author

behlendorf commented Nov 27, 2018

Refreshed. and feedback addressed.

you might want to consider fixing the -H indents as well:

I'd rather leave this alone to make sure we don't break anything parsing this output. The documentation clearly states the output will print the columns separated by a single tab.

             -H      Scripted mode. Do not display headers, and separate
                     fields by a single tab instead of arbitrary space.

I've also re-added the ALTROOT line to the output. Several helper functions in the ZTS look for this column and its absence resulted in test failures. The zpool list output is already over 80 columns and I think if we want to shorten that up with can do so in a dedicated PR.

@behlendorf behlendorf added Status: Code Review Needed Ready for review and testing and removed Status: Revision Needed Changes are required for the PR to be accepted labels Nov 27, 2018
@behlendorf behlendorf requested a review from kpande November 29, 2018 04:50
Copy link
Contributor

@tcaputi tcaputi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't completely understand all of the formatting, but at a glance it looks good. The commit comment has a typo: Minimally update the code the correct the alignment using the same strategy employedby 'zpool status'.

The verbose output of 'zpool list' was not correctly aligned due
to differences in the vdev name lengths.  Minimally update the
code the correct the alignment using the same strategy employed
by 'zpool status'.

Missing dashes were added for the empty defaults columns, and
the vdev state is now printed for all vdevs.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Nov 30, 2018
@behlendorf behlendorf merged commit c5eea0a into openzfs:master Dec 4, 2018
GregorKopka pushed a commit to GregorKopka/zfs that referenced this pull request Jan 7, 2019
The verbose output of 'zpool list' was not correctly aligned due
to differences in the vdev name lengths.  Minimally update the
code the correct the alignment using the same strategy employed
by 'zpool status'.

Missing dashes were added for the empty defaults columns, and
the vdev state is now printed for all vdevs.

Reviewed-by: Tom Caputi <tcaputi@datto.com>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes openzfs#7308 
Closes openzfs#8147
@behlendorf behlendorf deleted the issue-7308 branch April 19, 2021 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants