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