-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Open
Shreshth3
wants to merge
1
commit into
openzfs:master
Choose a base branch
from
Shreshth3:list-default
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3863,6 +3863,7 @@ zfs_do_list(int argc, char **argv) | |
| zfs_sort_column_t *sortcol = NULL; | ||
| int flags = ZFS_ITER_PROP_LISTSNAPS | ZFS_ITER_ARGS_CAN_BE_PATHS; | ||
| nvlist_t *data = NULL; | ||
| char full_fields[1024]; | ||
|
|
||
| struct option long_options[] = { | ||
| {"json", no_argument, NULL, 'j'}, | ||
|
|
@@ -3875,7 +3876,23 @@ zfs_do_list(int argc, char **argv) | |
| NULL)) != -1) { | ||
| switch (c) { | ||
| case 'o': | ||
| fields = optarg; | ||
| if (optarg[0] == '+') { | ||
| /* +2 for the , and the null terminator */ | ||
| if (strlen(fields) + strlen(optarg + 1) + 2 <= | ||
| 1024) { | ||
| (void) snprintf(full_fields, | ||
| sizeof (full_fields), "%s,%s", | ||
| fields, optarg + 1); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose this won't work if |
||
| } else { | ||
| (void) fprintf(stderr, gettext( | ||
| "argument too long for '-o'" | ||
| " option.\n")); | ||
| usage(B_FALSE); | ||
| } | ||
| fields = full_fields; | ||
| } else { | ||
| fields = optarg; | ||
| } | ||
| break; | ||
| case 'p': | ||
| cb.cb_literal = B_TRUE; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_009_pos.ksh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #!/bin/ksh -p | ||
| # SPDX-License-Identifier: CDDL-1.0 | ||
| # | ||
| # CDDL HEADER START | ||
| # | ||
| # The contents of this file are subject to the terms of the | ||
| # Common Development and Distribution License (the "License"). | ||
| # You may not use this file except in compliance with the License. | ||
| # | ||
| # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | ||
| # or https://opensource.org/licenses/CDDL-1.0. | ||
| # See the License for the specific language governing permissions | ||
| # and limitations under the License. | ||
| # | ||
| # When distributing Covered Code, include this CDDL HEADER in each | ||
| # file and include the License file at usr/src/OPENSOLARIS.LICENSE. | ||
| # If applicable, add the following below this CDDL HEADER, with the | ||
| # fields enclosed by brackets "[]" replaced with your own identifying | ||
| # information: Portions Copyright [yyyy] [name of copyright owner] | ||
| # | ||
| # CDDL HEADER END | ||
| # | ||
|
|
||
| # | ||
| # Copyright 2007 Sun Microsystems, Inc. All rights reserved. | ||
| # Use is subject to license terms. | ||
| # | ||
|
|
||
| # | ||
| # Copyright (c) 2013, 2016 by Delphix. All rights reserved. | ||
| # | ||
|
|
||
| . $STF_SUITE/include/libtest.shlib | ||
|
|
||
| # | ||
| # DESCRIPTION: | ||
| # Verify 'zfs list -o+' allows users to append a column to the defaults | ||
| # | ||
| # STRATEGY: | ||
| # 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_assert "Verify 'zfs list -o+<...>' appends columns to the defaults." | ||
|
|
||
| log_must zfs set comment:=helloworld $TESTPOOL | ||
|
|
||
| log_must eval zfs list $TESTPOOL -o +comment: | grep -Eq '^NAME.+COMMENT:$' | ||
| log_must eval zfs list $TESTPOOL -o +comment: | grep -Eq "^$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." |
66 changes: 66 additions & 0 deletions
66
tests/zfs-tests/tests/functional/cli_user/zpool_list/zpool_list_003_pos.ksh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| #!/bin/ksh -p | ||
| # SPDX-License-Identifier: CDDL-1.0 | ||
| # | ||
| # CDDL HEADER START | ||
| # | ||
| # The contents of this file are subject to the terms of the | ||
| # Common Development and Distribution License (the "License"). | ||
| # You may not use this file except in compliance with the License. | ||
| # | ||
| # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | ||
| # or https://opensource.org/licenses/CDDL-1.0. | ||
| # See the License for the specific language governing permissions | ||
| # and limitations under the License. | ||
| # | ||
| # When distributing Covered Code, include this CDDL HEADER in each | ||
| # file and include the License file at usr/src/OPENSOLARIS.LICENSE. | ||
| # If applicable, add the following below this CDDL HEADER, with the | ||
| # fields enclosed by brackets "[]" replaced with your own identifying | ||
| # information: Portions Copyright [yyyy] [name of copyright owner] | ||
| # | ||
| # CDDL HEADER END | ||
| # | ||
|
|
||
| # | ||
| # Copyright 2008 Sun Microsystems, Inc. All rights reserved. | ||
| # Use is subject to license terms. | ||
| # | ||
|
|
||
| # | ||
| # Copyright (c) 2013, 2016 by Delphix. All rights reserved. | ||
| # | ||
|
|
||
| . $STF_SUITE/include/libtest.shlib | ||
|
|
||
| # | ||
| # DESCRIPTION: | ||
| # Verify that 'zpool list -o+' allows users to append a column to the defaults. | ||
| # | ||
| # STRATEGY: | ||
| # 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" | ||
|
|
||
| if ! is_global_zone; then | ||
| TESTPOOL=${TESTPOOL%%/*} | ||
| fi | ||
|
|
||
| log_assert "Verify 'zpool list -o+<...>' appends columns to the defaults." | ||
|
|
||
| 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$" | ||
|
|
||
| # 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." |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than
1024here should better besizeof(). But unless1024goes from somewhere, I would prefer to not have arbitrary limits.