Skip to content

Commit 8221bcf

Browse files
InsanePrawnbehlendorf
authored andcommitted
Remove requirement for -d 1 for zfs list and zfs get with bookmarks
df58307 removed the need to specify -d 1 when zfs list and zfs get are called with -t snapshot on a datset. This commit extends the same behaviour to -t bookmark. This commit also introduces the 'snap' shorthand for snapshots from zfs list to zfs get. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Tom Caputi <[email protected]> Reviewed-by: Kjeld Schouten <[email protected]> Signed-off-by: InsanePrawn <[email protected]> Closes #9589
1 parent 7ae3f8d commit 8221bcf

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

cmd/zfs/zfs_main.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,7 +1965,7 @@ zfs_do_get(int argc, char **argv)
19651965
flags &= ~ZFS_ITER_PROP_LISTSNAPS;
19661966
while (*optarg != '\0') {
19671967
static char *type_subopts[] = { "filesystem",
1968-
"volume", "snapshot", "bookmark",
1968+
"volume", "snapshot", "snap", "bookmark",
19691969
"all", NULL };
19701970

19711971
switch (getsubopt(&optarg, type_subopts,
@@ -1977,12 +1977,13 @@ zfs_do_get(int argc, char **argv)
19771977
types |= ZFS_TYPE_VOLUME;
19781978
break;
19791979
case 2:
1980+
case 3:
19801981
types |= ZFS_TYPE_SNAPSHOT;
19811982
break;
1982-
case 3:
1983+
case 4:
19831984
types |= ZFS_TYPE_BOOKMARK;
19841985
break;
1985-
case 4:
1986+
case 5:
19861987
types = ZFS_TYPE_DATASET |
19871988
ZFS_TYPE_BOOKMARK;
19881989
break;
@@ -2015,11 +2016,11 @@ zfs_do_get(int argc, char **argv)
20152016
fields = argv[0];
20162017

20172018
/*
2018-
* Handle users who want to get all snapshots of the current
2019-
* dataset (ex. 'zfs get -t snapshot refer <dataset>').
2019+
* Handle users who want to get all snapshots or bookmarks
2020+
* of a dataset (ex. 'zfs get -t snapshot refer <dataset>').
20202021
*/
2021-
if (types == ZFS_TYPE_SNAPSHOT && argc > 1 &&
2022-
(flags & ZFS_ITER_RECURSE) == 0 && limit == 0) {
2022+
if ((types == ZFS_TYPE_SNAPSHOT || types == ZFS_TYPE_BOOKMARK) &&
2023+
argc > 1 && (flags & ZFS_ITER_RECURSE) == 0 && limit == 0) {
20232024
flags |= (ZFS_ITER_DEPTH_LIMIT | ZFS_ITER_RECURSE);
20242025
limit = 1;
20252026
}
@@ -3519,11 +3520,11 @@ zfs_do_list(int argc, char **argv)
35193520
types &= ~ZFS_TYPE_SNAPSHOT;
35203521

35213522
/*
3522-
* Handle users who want to list all snapshots of the current
3523-
* dataset (ex. 'zfs list -t snapshot <dataset>').
3523+
* Handle users who want to list all snapshots or bookmarks
3524+
* of the current dataset (ex. 'zfs list -t snapshot <dataset>').
35243525
*/
3525-
if (types == ZFS_TYPE_SNAPSHOT && argc > 0 &&
3526-
(flags & ZFS_ITER_RECURSE) == 0 && limit == 0) {
3526+
if ((types == ZFS_TYPE_SNAPSHOT || types == ZFS_TYPE_BOOKMARK) &&
3527+
argc > 0 && (flags & ZFS_ITER_RECURSE) == 0 && limit == 0) {
35273528
flags |= (ZFS_ITER_DEPTH_LIMIT | ZFS_ITER_RECURSE);
35283529
limit = 1;
35293530
}

tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_009_pos.ksh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,16 @@ log_must eval "zfs get -H -t snapshot -o name creation $DEPTH_FS > $DEPTH_OUTPUT
9292
log_must eval "zfs get -H -t snapshot -d 1 -o name creation $DEPTH_FS > $EXPECT_OUTPUT"
9393
log_must diff $DEPTH_OUTPUT $EXPECT_OUTPUT
9494

95+
# Ensure 'zfs get -t snap' works as a shorthand for 'zfs get -t snapshot'
96+
log_must eval "zfs get -H -t snap -d 1 -o name creation $DEPTH_FS > $DEPTH_OUTPUT"
97+
log_must eval "zfs get -H -t snapshot -d 1 -o name creation $DEPTH_FS > $EXPECT_OUTPUT"
98+
log_must diff $DEPTH_OUTPUT $EXPECT_OUTPUT
99+
100+
# Ensure 'zfs get -t bookmark <dataset>' works as though -d 1 was specified
101+
log_must eval "zfs get -H -t bookmark -o name creation $DEPTH_FS > $DEPTH_OUTPUT"
102+
log_must eval "zfs get -H -t bookmark -d 1 -o name creation $DEPTH_FS > $EXPECT_OUTPUT"
103+
log_must diff $DEPTH_OUTPUT $EXPECT_OUTPUT
104+
105+
95106
log_pass "'zfs get -d <n>' should get expected output."
96107

tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ set -A depth_options "d 0" "d 1" "d 2" "d 4" "d 32"
3737
set -A depth_array 0 1 2 4 32
3838

3939
#
40-
# Setup multiple depths datasets, including fs, volume and snapshot.
40+
# Setup multiple depths datasets, including fs, volumes, snapshots and bookmarks.
4141
#
4242
function depth_fs_setup
4343
{
@@ -65,6 +65,7 @@ function depth_fs_setup
6565
log_must zfs create -V 8M $fs/vol_"$j"_depth"$i"
6666
fi
6767
log_must zfs snapshot $fs@snap_"$j"_depth"$i"
68+
log_must zfs bookmark $fs@snap_"$j"_depth"$i" '#bookmark'_"$j"_depth"$i"
6869
(( j=j+1 ))
6970
done
7071
done

0 commit comments

Comments
 (0)