f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#!/bin/ksh -p
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER START
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# The contents of this file are subject to the terms of the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Common Development and Distribution License (the "License").
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You may not use this file except in compliance with the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# or http://www.opensolaris.org/os/licensing.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# See the License for the specific language governing permissions
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# and limitations under the License.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# CDDL HEADER END
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# Use is subject to license terms.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy. $STF_SUITE/tests/functional/cli_user/zfs_list/zfs_list.kshlib
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# DESCRIPTION:
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# The sort functionality in 'zfs list' works as expected.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# STRATEGY:
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 1. Using several zfs datasets with names, creation dates, checksum options
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 2. Sort the datasets by name, checksum options, creation date.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# 3. Verify that the datasets are sorted correctly.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyverify_runnable "both"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# datasets ordered by name
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfs_name="Apple Banana Carrot Orange apple banana carrot"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyvol_name="Apple-vol Banana-vol Carrot-vol Orange-vol apple-vol"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyvol_name="$vol_name banana-vol carrot-vol"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyif is_global_zone ; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy snap_name="Apple-vol@snap Apple@snap Banana-vol@snap Banana@snap"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy snap_name="$snap_name Carrot-vol@snap Carrot@snap Orange-vol@snap Orange@snap"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy snap_name="$snap_name apple-vol@snap apple@snap banana-vol@snap banana@snap"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy snap_name="$snap_name carrot-vol@snap carrot@snap"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyelse
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy snap_name="Apple@snap Banana@snap"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy snap_name="$snap_name Carrot@snap Orange@snap"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy snap_name="$snap_name apple@snap banana@snap"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy snap_name="$snap_name carrot@snap"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfs_creation=$fs_name
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyvol_creation=$vol_name
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyif is_global_zone ; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy snap_creation="Apple@snap Apple-vol@snap Banana@snap Banana-vol@snap"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy snap_creation="$snap_creation Carrot@snap Carrot-vol@snap Orange@snap Orange-vol@snap"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy snap_creation="$snap_creation apple@snap apple-vol@snap banana@snap banana-vol@snap"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy snap_creation="$snap_creation carrot@snap carrot-vol@snap"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyelse
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy snap_creation="Apple@snap Banana@snap"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy snap_creation="$snap_creation Carrot@snap Orange@snap"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy snap_creation="$snap_creation apple@snap banana@snap"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy snap_creation="$snap_creation carrot@snap"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# datsets ordered by checksum options (note, Orange, Carrot & Banana have the
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# same checksum options, so ZFS should revert to sorting them alphabetically by
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# name)
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfs_cksum="carrot apple banana Apple Banana Carrot Orange"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyvol_cksum="carrot-vol apple-vol banana-vol Apple-vol Banana-vol"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyvol_cksum="$vol_cksum Carrot-vol Orange-vol"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedysnap_cksum=$snap_creation
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfs_rev_cksum="carrot apple banana Apple Orange Carrot Banana"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyvol_rev_cksum="carrot-vol apple-vol banana-vol Apple-vol Orange-vol"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyvol_rev_cksum="$vol_rev_cksum Carrot-vol Banana-vol"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_assert "The sort functionality in 'zfs list' works as expected."
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# we must be in the C locale here, as running in other locales
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# will make zfs use that locale's sort order.
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy#
f38cb554a534c6df738be3f4d23327e69888e634John Wren KennedyLC_ALL=C; export LC_ALL
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# sort by creation
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyverify_sort \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy "zfs list -H -r -o name -s creation -t filesystem $TESTPOOL/$TESTFS" \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$fs_creation" "creation date"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyif is_global_zone ; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy verify_sort \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy "zfs list -H -r -o name -s creation -t volume $TESTPOOL/$TESTFS" \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$vol_creation" "creation date"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyverify_sort \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy "zfs list -H -r -o name -s creation -t snapshot $TESTPOOL/$TESTFS" \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$snap_creation" "creation date"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# sort by checksum
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyverify_sort \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy "zfs list -H -r -o name -s checksum -t filesystem $TESTPOOL/$TESTFS" \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$fs_cksum" "checksum"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyif is_global_zone ; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy verify_sort \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy "zfs list -H -r -o name -s checksum -t volume $TESTPOOL/$TESTFS" \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$vol_cksum" "checksum"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyverify_sort \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy "zfs list -H -r -o name -s checksum -t snapshot $TESTPOOL/$TESTFS" \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$snap_cksum" "checksum"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyverify_sort \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy "zfs list -H -r -o name -S checksum -t snapshot $TESTPOOL/$TESTFS" \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$snap_cksum" "checksum"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# sort by name
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyverify_sort \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy "zfs list -H -r -o name -s name -t filesystem $TESTPOOL/$TESTFS" \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$fs_name" "name"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyif is_global_zone ; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy verify_sort \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy "zfs list -H -r -o name -s name -t volume $TESTPOOL/$TESTFS" \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$vol_name" "name"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyverify_sort \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy "zfs list -H -r -o name -s name -t snapshot $TESTPOOL/$TESTFS" \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$snap_name" "name"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# reverse sort by creation
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyverify_reverse_sort \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy "zfs list -H -r -o name -S creation -t filesystem $TESTPOOL/$TESTFS" \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$fs_creation" "creation date"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyif is_global_zone ; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy verify_reverse_sort \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy "zfs list -H -r -o name -S creation -t volume $TESTPOOL/$TESTFS" \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$vol_creation" "creation date"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyverify_reverse_sort \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy "zfs list -H -r -o name -S creation -t snapshot $TESTPOOL/$TESTFS" \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$snap_creation" "creation date"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# reverse sort by checksum
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyverify_reverse_sort \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy "zfs list -H -r -o name -S checksum -t filesystem $TESTPOOL/$TESTFS" \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$fs_rev_cksum" "checksum"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyif is_global_zone ; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy verify_reverse_sort \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy "zfs list -H -r -o name -S checksum -t volume $TESTPOOL/$TESTFS" \
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$vol_rev_cksum" "checksum"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy# reverse sort by name
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyverify_reverse_sort \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy "zfs list -H -r -o name -S name -t filesystem $TESTPOOL/$TESTFS"\
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$fs_name" "name"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyif is_global_zone ; then
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy verify_reverse_sort \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy "zfs list -H -r -o name -S name -t volume $TESTPOOL/$TESTFS"\
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$vol_name" "name"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyfi
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedyverify_reverse_sort \
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy "zfs list -H -r -o name -S name -t snapshot $TESTPOOL/$TESTFS"\
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy "$snap_name" "name"
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedy
f38cb554a534c6df738be3f4d23327e69888e634John Wren Kennedylog_pass "The sort functionality in 'zfs list' works as expected."