-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Allow appending to default props for zfs and zpool list. #18069
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
base: master
Are you sure you want to change the base?
Conversation
It would be nice to support this case by removing such a column from the "default" part of the list and inserting it into the "user" part of the list at the specified position. E.g. I might want to keep the Additionally, perhaps some care is needed to support (or cleanly refuse) repeated |
It's a good point to bring up. Personally, I like the simplicity of |
|
Could you add a simple test case? |
af7ae67 to
c4e98b7
Compare
It looks to me like the normal and Given this, it doesn't feel to me like this PR is the right place to address this issue. It seems worthwhile to have a separate thread discussing how ZFS should handle multiple |
Added. |
I started reviewing your test cases yesterday and ended up tweaking them a little 😄 . The new version gets rid of the temporary files, adds stricter checks for column order, and verifies the JSON (diff below): diffdiff --git a/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_009_pos.ksh b/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_009_pos.ksh
index 5a499275f..6eae533cb 100755
--- a/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_009_pos.ksh
+++ b/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_009_pos.ksh
@@ -37,26 +37,23 @@
# Verify 'zfs list -o+' allows users to append a column to the defaults
#
# STRATEGY:
-# 1. Execute `zfs list -o+guid`.
-# 2. Confirm that the "name" and "guid" columns both appear in the output.
-#
-
-function cleanup
-{
- if [[ -f $tmpfile ]]; then
- rm -f $tmpfile
- fi
-}
+# 1. Add a user comment to dataset
+# 2. Execute `zfs list -o +comment:`.
+# 3. Verify the first column of the defaults gets printed.
+# 4. Verify the user comment appears as the last column.
+# 5. Verify we see both one of the default entries and the user comment in JSON.
verify_runnable "both"
-log_onexit cleanup
log_assert "Verify 'zfs list -o+<...>' appends columns to the defaults."
-tmpfile=$TEST_BASE_DIR/zfslist.out.$$
+log_must zfs set comment:=helloworld $TESTPOOL
-zfs list -o+guid > $tmpfile
-log_must grep -qi "name" $tmpfile
-log_must grep -qi "guid" $tmpfile
+log_must eval zfs list $TESTPOOL -o +comment: | grep -E '^NAME.+COMMENT:$'
+log_must eval zfs list $TESTPOOL -o +comment: | grep -E "^$TESTPOOL.+helloworld$"
+val=$(zfs list -j -o +comment: $TESTPOOL | jq -r '.datasets.'$TESTPOOL'.properties."comment:".value')
+log_must test $val == "helloworld"
+val=$(zfs list -j -o +comment: $TESTPOOL | jq -r ".datasets.$TESTPOOL.properties.mountpoint.value")
+log_must test $val == "/$TESTPOOL"
log_pass "'zfs list -o+<...>' successfully added columns to the defaults."
diff --git a/tests/zfs-tests/tests/functional/cli_user/zpool_list/zpool_list_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_user/zpool_list/zpool_list_003_pos.ksh
index 000c8b72d..18d831525 100755
--- a/tests/zfs-tests/tests/functional/cli_user/zpool_list/zpool_list_003_pos.ksh
+++ b/tests/zfs-tests/tests/functional/cli_user/zpool_list/zpool_list_003_pos.ksh
@@ -37,16 +37,11 @@
# Verify that 'zpool list -o+' allows users to append a column to the defaults.
#
# STRATEGY:
-# 1. Execute `zpool list -o+guid`
-# 2. Confirm that the "name" and "guid" columns both appear in the output.
-#
-
-function cleanup
-{
- if [[ -f $tmpfile ]]; then
- rm -f $tmpfile
- fi
-}
+# 1. Add a user comment to the pool
+# 2. Execute `zfs list -o +comment`.
+# 3. Verify the first column of the defaults gets printed.
+# 4. Verify the user comment appears as the last column.
+# 5. Verify we see both one of the default entries and the user comment in JSON.
verify_runnable "both"
log_onexit cleanup
@@ -57,10 +52,16 @@ fi
log_assert "Verify 'zpool list -o+<...>' appends columns to the defaults."
-tmpfile=$TEST_BASE_DIR/zpoollist.out.$$
+log_must zpool set comment="helloworld" $TESTPOOL
+
+# Verify the first and last columns are correct
+log_must eval zpool list -o +comment | grep -Eq '^NAME.+COMMENT$'
+log_must eval zpool list -o +comment | grep -Eq "^$TESTPOOL.+helloworld$"
-zpool list -o+guid > $tmpfile
-log_must grep -qi "name" $tmpfile
-log_must grep -qi "guid" $tmpfile
+# Verify we see both a default value and our added value in the JSON
+val=$(zpool list -j -o +comment | jq -r ".pools.$TESTPOOL.properties.comment.value")
+log_must test "$val" == "helloworld"
+val=$(zpool list -j -o +comment | jq -r ".pools.$TESTPOOL.properties.health.value")
+log_must test "$val" == "ONLINE"
log_pass "'zpool list -o+<...>' successfully added columns to the defaults." |
8768ef2 to
1a699c6
Compare
|
Integrated your changes, thanks for making them! I ended up hand-copying the diff (ran into an issue trying to apply the patch), so worth double checking that things look the way you intended. I also edited a couple small things (removing |
This commit allows users to add specific options in addition to the defaults when using `zfs list` or `zpool list`. For example, `zpool list -o +guid` will run `zpool list` showing the default properties in addition to guid. Resolves openzfs#17112. Signed-off-by: Shreshth Srivastava <[email protected]>
1a699c6 to
3777958
Compare
This PR allows users to add specific properties in addition to the defaults when using
zfs list -oorzpool list -o. For example,zpool list -o +guidwill runzpool listshowing the default properties in addition to guid.Resolves #17112.
One note: with the current implementation, if a user tries to append a property that is already in the defaults (e.g. name), they will see that column two times. If this is not acceptable, I can adjust the implementation accordingly.
Types of changes
Checklist:
Signed-off-by.