1f38cb554SJohn Wren Kennedy#!/bin/ksh -p
2f38cb554SJohn Wren Kennedy#
3f38cb554SJohn Wren Kennedy# CDDL HEADER START
4f38cb554SJohn Wren Kennedy#
5f38cb554SJohn Wren Kennedy# The contents of this file are subject to the terms of the
6f38cb554SJohn Wren Kennedy# Common Development and Distribution License (the "License").
7f38cb554SJohn Wren Kennedy# You may not use this file except in compliance with the License.
8f38cb554SJohn Wren Kennedy#
9f38cb554SJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10f38cb554SJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing.
11f38cb554SJohn Wren Kennedy# See the License for the specific language governing permissions
12f38cb554SJohn Wren Kennedy# and limitations under the License.
13f38cb554SJohn Wren Kennedy#
14f38cb554SJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
15f38cb554SJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16f38cb554SJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
17f38cb554SJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
18f38cb554SJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
19f38cb554SJohn Wren Kennedy#
20f38cb554SJohn Wren Kennedy# CDDL HEADER END
21f38cb554SJohn Wren Kennedy#
22f38cb554SJohn Wren Kennedy
23f38cb554SJohn Wren Kennedy#
24f38cb554SJohn Wren Kennedy# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
25f38cb554SJohn Wren Kennedy# Use is subject to license terms.
26f38cb554SJohn Wren Kennedy#
27f38cb554SJohn Wren Kennedy
28f38cb554SJohn Wren Kennedy#
29*1d32ba66SJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
30f38cb554SJohn Wren Kennedy#
31f38cb554SJohn Wren Kennedy
32f38cb554SJohn Wren Kennedy. $STF_SUITE/tests/functional/cli_user/zfs_list/zfs_list.kshlib
33f38cb554SJohn Wren Kennedy
34f38cb554SJohn Wren Kennedy#
35f38cb554SJohn Wren Kennedy# DESCRIPTION:
36f38cb554SJohn Wren Kennedy# The sort functionality in 'zfs list' works as expected.
37f38cb554SJohn Wren Kennedy#
38f38cb554SJohn Wren Kennedy# STRATEGY:
39f38cb554SJohn Wren Kennedy# 1. Using several zfs datasets with names, creation dates, checksum options
40f38cb554SJohn Wren Kennedy# 2. Sort the datasets by name, checksum options, creation date.
41f38cb554SJohn Wren Kennedy# 3. Verify that the datasets are sorted correctly.
42f38cb554SJohn Wren Kennedy#
43f38cb554SJohn Wren Kennedy
44f38cb554SJohn Wren Kennedyverify_runnable "both"
45f38cb554SJohn Wren Kennedy
46f38cb554SJohn Wren Kennedy# datasets ordered by name
47f38cb554SJohn Wren Kennedyfs_name="Apple Banana Carrot Orange apple banana carrot"
48f38cb554SJohn Wren Kennedyvol_name="Apple-vol Banana-vol Carrot-vol Orange-vol apple-vol"
49f38cb554SJohn Wren Kennedyvol_name="$vol_name banana-vol carrot-vol"
50f38cb554SJohn Wren Kennedyif is_global_zone ; then
51f38cb554SJohn Wren Kennedy	snap_name="Apple-vol@snap Apple@snap Banana-vol@snap Banana@snap"
52f38cb554SJohn Wren Kennedy	snap_name="$snap_name Carrot-vol@snap Carrot@snap Orange-vol@snap Orange@snap"
53f38cb554SJohn Wren Kennedy	snap_name="$snap_name apple-vol@snap apple@snap banana-vol@snap banana@snap"
54f38cb554SJohn Wren Kennedy	snap_name="$snap_name carrot-vol@snap carrot@snap"
55f38cb554SJohn Wren Kennedyelse
56f38cb554SJohn Wren Kennedy	snap_name="Apple@snap Banana@snap"
57f38cb554SJohn Wren Kennedy	snap_name="$snap_name Carrot@snap Orange@snap"
58f38cb554SJohn Wren Kennedy	snap_name="$snap_name apple@snap banana@snap"
59f38cb554SJohn Wren Kennedy	snap_name="$snap_name carrot@snap"
60f38cb554SJohn Wren Kennedyfi
61f38cb554SJohn Wren Kennedy
62f38cb554SJohn Wren Kennedyfs_creation=$fs_name
63f38cb554SJohn Wren Kennedyvol_creation=$vol_name
64f38cb554SJohn Wren Kennedyif is_global_zone ; then
65f38cb554SJohn Wren Kennedy	snap_creation="Apple@snap Apple-vol@snap Banana@snap Banana-vol@snap"
66f38cb554SJohn Wren Kennedy	snap_creation="$snap_creation Carrot@snap Carrot-vol@snap Orange@snap Orange-vol@snap"
67f38cb554SJohn Wren Kennedy	snap_creation="$snap_creation apple@snap apple-vol@snap banana@snap banana-vol@snap"
68f38cb554SJohn Wren Kennedy	snap_creation="$snap_creation carrot@snap carrot-vol@snap"
69f38cb554SJohn Wren Kennedyelse
70f38cb554SJohn Wren Kennedy	snap_creation="Apple@snap Banana@snap"
71f38cb554SJohn Wren Kennedy	snap_creation="$snap_creation Carrot@snap Orange@snap"
72f38cb554SJohn Wren Kennedy	snap_creation="$snap_creation apple@snap banana@snap"
73f38cb554SJohn Wren Kennedy	snap_creation="$snap_creation carrot@snap"
74f38cb554SJohn Wren Kennedyfi
75f38cb554SJohn Wren Kennedy
76f38cb554SJohn Wren Kennedy#
77f38cb554SJohn Wren Kennedy# datsets ordered by checksum options (note, Orange, Carrot & Banana have the
78f38cb554SJohn Wren Kennedy# same checksum options, so ZFS should revert to sorting them alphabetically by
79f38cb554SJohn Wren Kennedy# name)
80f38cb554SJohn Wren Kennedy#
81f38cb554SJohn Wren Kennedyfs_cksum="carrot apple banana Apple Banana Carrot Orange"
82f38cb554SJohn Wren Kennedyvol_cksum="carrot-vol apple-vol banana-vol Apple-vol Banana-vol"
83f38cb554SJohn Wren Kennedyvol_cksum="$vol_cksum Carrot-vol Orange-vol"
84f38cb554SJohn Wren Kennedysnap_cksum=$snap_creation
85f38cb554SJohn Wren Kennedy
86f38cb554SJohn Wren Kennedyfs_rev_cksum="carrot apple banana Apple Orange Carrot Banana"
87f38cb554SJohn Wren Kennedyvol_rev_cksum="carrot-vol apple-vol banana-vol Apple-vol Orange-vol"
88f38cb554SJohn Wren Kennedyvol_rev_cksum="$vol_rev_cksum Carrot-vol Banana-vol"
89f38cb554SJohn Wren Kennedy
90f38cb554SJohn Wren Kennedylog_assert "The sort functionality in 'zfs list' works as expected."
91f38cb554SJohn Wren Kennedy
92f38cb554SJohn Wren Kennedy#
93f38cb554SJohn Wren Kennedy# we must be in the C locale here, as running in other locales
94f38cb554SJohn Wren Kennedy# will make zfs use that locale's sort order.
95f38cb554SJohn Wren Kennedy#
96f38cb554SJohn Wren KennedyLC_ALL=C; export LC_ALL
97f38cb554SJohn Wren Kennedy
98f38cb554SJohn Wren Kennedy# sort by creation
99f38cb554SJohn Wren Kennedyverify_sort \
100*1d32ba66SJohn Wren Kennedy	"zfs list -H -r -o name -s creation -t filesystem $TESTPOOL/$TESTFS" \
101f38cb554SJohn Wren Kennedy	"$fs_creation" "creation date"
102f38cb554SJohn Wren Kennedyif is_global_zone ; then
103f38cb554SJohn Wren Kennedy	verify_sort \
104*1d32ba66SJohn Wren Kennedy	"zfs list -H -r -o name -s creation -t volume $TESTPOOL/$TESTFS" \
105f38cb554SJohn Wren Kennedy	"$vol_creation" "creation date"
106f38cb554SJohn Wren Kennedyfi
107f38cb554SJohn Wren Kennedyverify_sort \
108*1d32ba66SJohn Wren Kennedy	"zfs list -H -r -o name -s creation -t snapshot $TESTPOOL/$TESTFS" \
109f38cb554SJohn Wren Kennedy	"$snap_creation" "creation date"
110f38cb554SJohn Wren Kennedy
111f38cb554SJohn Wren Kennedy# sort by checksum
112f38cb554SJohn Wren Kennedyverify_sort \
113*1d32ba66SJohn Wren Kennedy	"zfs list -H -r -o name -s checksum -t filesystem $TESTPOOL/$TESTFS" \
114f38cb554SJohn Wren Kennedy	"$fs_cksum" "checksum"
115f38cb554SJohn Wren Kennedyif is_global_zone ; then
116f38cb554SJohn Wren Kennedy	verify_sort \
117*1d32ba66SJohn Wren Kennedy	"zfs list -H -r -o name -s checksum -t volume $TESTPOOL/$TESTFS" \
118f38cb554SJohn Wren Kennedy	"$vol_cksum" "checksum"
119f38cb554SJohn Wren Kennedyfi
120f38cb554SJohn Wren Kennedyverify_sort \
121*1d32ba66SJohn Wren Kennedy	"zfs list -H -r -o name -s checksum -t snapshot $TESTPOOL/$TESTFS" \
122f38cb554SJohn Wren Kennedy	"$snap_cksum" "checksum"
123f38cb554SJohn Wren Kennedyverify_sort \
124*1d32ba66SJohn Wren Kennedy	"zfs list -H -r -o name -S checksum -t snapshot $TESTPOOL/$TESTFS" \
125f38cb554SJohn Wren Kennedy	"$snap_cksum" "checksum"
126f38cb554SJohn Wren Kennedy
127f38cb554SJohn Wren Kennedy# sort by name
128f38cb554SJohn Wren Kennedyverify_sort \
129*1d32ba66SJohn Wren Kennedy	"zfs list -H -r -o name -s name -t filesystem $TESTPOOL/$TESTFS" \
130f38cb554SJohn Wren Kennedy	"$fs_name" "name"
131f38cb554SJohn Wren Kennedyif is_global_zone ; then
132f38cb554SJohn Wren Kennedy	verify_sort \
133*1d32ba66SJohn Wren Kennedy	"zfs list -H -r -o name -s name -t volume $TESTPOOL/$TESTFS" \
134f38cb554SJohn Wren Kennedy	"$vol_name" "name"
135f38cb554SJohn Wren Kennedyfi
136f38cb554SJohn Wren Kennedyverify_sort \
137*1d32ba66SJohn Wren Kennedy	"zfs list -H -r -o name -s name -t snapshot $TESTPOOL/$TESTFS" \
138f38cb554SJohn Wren Kennedy	"$snap_name" "name"
139f38cb554SJohn Wren Kennedy
140f38cb554SJohn Wren Kennedy# reverse sort by creation
141f38cb554SJohn Wren Kennedyverify_reverse_sort \
142*1d32ba66SJohn Wren Kennedy	"zfs list -H -r -o name -S creation -t filesystem $TESTPOOL/$TESTFS" \
143f38cb554SJohn Wren Kennedy	"$fs_creation" "creation date"
144f38cb554SJohn Wren Kennedyif is_global_zone ; then
145f38cb554SJohn Wren Kennedy	verify_reverse_sort \
146*1d32ba66SJohn Wren Kennedy	"zfs list -H -r -o name -S creation -t volume $TESTPOOL/$TESTFS" \
147f38cb554SJohn Wren Kennedy	"$vol_creation" "creation date"
148f38cb554SJohn Wren Kennedyfi
149f38cb554SJohn Wren Kennedyverify_reverse_sort \
150*1d32ba66SJohn Wren Kennedy	"zfs list -H -r -o name -S creation -t snapshot $TESTPOOL/$TESTFS" \
151f38cb554SJohn Wren Kennedy	"$snap_creation" "creation date"
152f38cb554SJohn Wren Kennedy
153f38cb554SJohn Wren Kennedy# reverse sort by checksum
154f38cb554SJohn Wren Kennedyverify_reverse_sort \
155*1d32ba66SJohn Wren Kennedy	"zfs list -H -r -o name -S checksum -t filesystem $TESTPOOL/$TESTFS" \
156f38cb554SJohn Wren Kennedy	"$fs_rev_cksum" "checksum"
157f38cb554SJohn Wren Kennedyif is_global_zone ; then
158f38cb554SJohn Wren Kennedy	verify_reverse_sort \
159*1d32ba66SJohn Wren Kennedy	"zfs list -H -r -o name -S checksum -t volume $TESTPOOL/$TESTFS" \
160f38cb554SJohn Wren Kennedy	"$vol_rev_cksum" "checksum"
161f38cb554SJohn Wren Kennedyfi
162f38cb554SJohn Wren Kennedy
163f38cb554SJohn Wren Kennedy# reverse sort by name
164f38cb554SJohn Wren Kennedyverify_reverse_sort \
165*1d32ba66SJohn Wren Kennedy	"zfs list -H -r -o name -S name -t filesystem $TESTPOOL/$TESTFS"\
166f38cb554SJohn Wren Kennedy	"$fs_name" "name"
167f38cb554SJohn Wren Kennedyif is_global_zone ; then
168f38cb554SJohn Wren Kennedy	verify_reverse_sort \
169*1d32ba66SJohn Wren Kennedy	"zfs list -H -r -o name -S name -t volume $TESTPOOL/$TESTFS"\
170f38cb554SJohn Wren Kennedy	"$vol_name" "name"
171f38cb554SJohn Wren Kennedyfi
172f38cb554SJohn Wren Kennedyverify_reverse_sort \
173*1d32ba66SJohn Wren Kennedy	"zfs list -H -r -o name -S name -t snapshot $TESTPOOL/$TESTFS"\
174f38cb554SJohn Wren Kennedy	"$snap_name" "name"
175f38cb554SJohn Wren Kennedy
176f38cb554SJohn Wren Kennedylog_pass "The sort functionality in 'zfs list' works as expected."
177