1 #
   2 # CDDL HEADER START
   3 #
   4 # The contents of this file are subject to the terms of the
   5 # Common Development and Distribution License (the "License").
   6 # You may not use this file except in compliance with the License.
   7 #
   8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9 # or http://www.opensolaris.org/os/licensing.
  10 # See the License for the specific language governing permissions
  11 # and limitations under the License.
  12 #
  13 # When distributing Covered Code, include this CDDL HEADER in each
  14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15 # If applicable, add the following below this CDDL HEADER, with the
  16 # fields enclosed by brackets "[]" replaced with your own identifying
  17 # information: Portions Copyright [yyyy] [name of copyright owner]
  18 #
  19 # CDDL HEADER END
  20 #
  21 
  22 #
  23 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24 # Use is subject to license terms.
  25 #
  26 # ident "@(#)tp_delete_001.ksh  1.2     08/12/19 SMI"
  27 #
  28 
  29 LOGFILE=${LOGDIR}/mkdir.out
  30 . ${TET_SUITE_ROOT}/lofi-tests/lib/fs_common
  31 
  32 #
  33 # start __stc_assertion__
  34 #
  35 # ASSERTION: delete_001
  36 #
  37 # DESCRIPTION:
  38 #       Delete a lofi device based on the name of the file.
  39 #
  40 # STRATEGY:
  41 #       Setup
  42 #               - Create a file of default size
  43 #               - Add a lofi device using the file
  44 #       Assert
  45 #               - Delete the lofi device by specifying the file name to
  46 #                 'lofiadm -d'
  47 #       Cleanup
  48 #               - Remove the file
  49 #
  50 # end __stc_assertion__
  51 #
  52 function tp_delete_001 {
  53         typeset cmd lofi_add_status
  54         typeset lofi_file=${SCRATCH_DIR}/lofi_file_$$_$TET_TPNUMBER
  55         typeset status=0
  56 
  57         typeset -r ASSERTION="delete_001"
  58         typeset -r TP_NAME=tp_${ASSERTION}
  59         typeset -r ME=$(whence -p ${0})
  60         extract_assertion_info $(dirname $ME)/$TP_NAME
  61 
  62         # Initialization
  63         cti_pass
  64         cti_assert $ASSERTION "Delete lofi device by file name"
  65         create_execution_record         # Record cmds; will display on failure
  66         execution_phase_setup           # Record setup cmds
  67 
  68         # Setup  -- create file for lofi device
  69         make_and_verify_file $DEFAULT_FILE_SIZE $lofi_file
  70         if (( $? != 0 )); then
  71                 cti_unresolved "Unable to test lofi deletion because" \
  72                     "creation of file failed"
  73                 status=1
  74         fi
  75 
  76         # Setup -- add lofi device
  77         if (( $status == 0 )); then
  78                 lofi_dev_returned=`add_lofi_device $lofi_file`
  79                 lofi_add_status=$?
  80                 if (( $lofi_add_status != 0 )) && (( $lofi_add_status != 2 )); then
  81                         cti_unresolved "Unable to test lofi deletion because" \
  82                             "creation failed"
  83                         status=1
  84                 fi
  85         fi
  86 
  87         # Assertion -- delete lofi device using name of file
  88         if (( $status == 0 )); then
  89                 execution_phase_assert          # Record assertion cmds
  90                 del_lofi_device $lofi_file
  91                 if (( $? == 0 )); then
  92                         cti_report "Deletion of lofi device associated with" \
  93                            "$lofi_file succeeded"
  94                 else
  95                         cti_fail "Unable to delete lofi device associated" \
  96                             "with $lofi_file"
  97                         status=1
  98                 fi
  99         fi
 100 
 101         # Cleanup
 102         execution_phase_cleanup         # Record cleanup cmds
 103         if [[ -f "$lofi_file" ]]; then
 104                 cmd="$RM $lofi_file"
 105                 record_cmd_execution $cmd
 106                 cti_execute "PASS" "$cmd"
 107                 if (( $? != 0 )); then
 108                         cti_fail "Unable to remove file $lofi_file" \
 109                             "used to for lofi device.  Possible lofi" \
 110                             "is still using it."
 111                         status=1
 112                 fi
 113         fi
 114 
 115         if [[ -n "$VERBOSE" ]] || (( $status != 0 )); then
 116                 display_execution_record
 117         else
 118                 delete_execution_record
 119         fi
 120 }