1 #! /usr/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 # set_nfstunable.ksh support script.
28 # Sets the specified nfs tunable in /etc/default/nfs to the provided value
29 #
30
31 [[ -n $DEBUG ]] && [[ $DEBUG != 0 ]] && set -x
32
33 NAME=$(basename $0)
34
35 (( $# < 1 )) && echo "usage: $NAME tunable=value ..." && return -1
36
37 id | grep "0(root)" > /dev/null 2>&1
38 if (( $? != 0 )); then
39 echo "Must be root to run this script."
40 return 1
41 fi
42
43 function wait_now
44 {
45 [[ -n $DEBUG ]] && [[ $DEBUG != 0 ]] && set -x
46 (( $# < 2 )) && \
47 echo "Usage: wait_now max_TIMER the_condition" && \
48 return -1
49
50 Timer=$1
51 shift
52 Wcond=$@
53
54 i=0
55 while (( i < Timer ))
56 do
57 eval $Wcond
58 (( $? == 0 )) && return 0
59 sleep 1
60 i=$((i + 1))
61 done
62 echo "wait_now function failed"
63 return $i
64 }
65
66 ret_value=""
67 set_value=""
68 check_tunable=""
69 check_value=""
70 for property in $*; do
71 typeset -u tunable=$(echo $property | awk -F= '{print $1}')
72 value=$(echo $property | awk -F= '{print $2}')
73
74 orig=$(sharectl get -p $tunable nfs | awk -F= '{print $2}')
75 if (( $? != 0 )); then
76 print -u 2 "$NAME: failed to get the original value \
77 of $tunable: $orig"
78 return 1
79 fi
80 if [[ -z $orig ]]; then
81 case $tunable in
82 SERVER_VERSMIN | CLIENT_VERSMIN )
83 orig=2
84 ;;
85 SERVER_VERSMAX | CLIENT_VERSMAX )
86 orig=4
87 ;;
88 SERVER_DEDEGATION )
89 orig=on
90 ;;
91 * )
92 ;;
93 esac
94 fi
95
96 # check if the value equals the original value
97 if [[ $value != $orig ]]; then
98 ret_value="$ret_value $tunable=$orig"
99 set_value="$set_value -p $tunable=$value"
100 check_tunable="$check_tunable -p $tunable"
101 check_value="$check_value $tunable=$value"
102 fi
103 done
104
105 if [[ -n $set_value ]]; then
106 sharectl set $set_value nfs
107 if (( $? != 0 )); then
108 print -u 2 "$NAME: failed to set the nfs tunable: $set_value"
109 return 1
110 fi
111 wait_now 10 \
112 "[[ \$(echo \$(sharectl get $check_tunable nfs)) == $check_value ]]"
113 if (( $? != 0 )); then
114 print -u 2 "$NAME: the nfs tunable has not been updated even
115 after 10 seconds: $(sharectl get $check_tunable nfs)"
116 return 1
117 fi
118 echo $ret_value
119 fi
120 return 0