]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/osd_login/osd_login
osd_login: Commit the files that go along with autologin script
[nfs-utils.git] / utils / osd_login / osd_login
1 #!/bin/bash
2 #
3 # osd_login : This script is part of the autologin feature
4 #             mandated by the pnfs-objects standard.
5 # It is called from objlayoutdriver.ko in the kernel.
6
7 # Copyright (C) 2012, Sachin Bhamare <sbhamare@panasas.com>
8 # Copyright (C) 2012, Boaz Harrosh <bharrosh@panasas.com>
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License version 2 as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 # MA 02110-1301 USA
23
24 umask 022
25
26 PATH="/sbin:/usr/sbin:/bin:/usr/bin"
27
28 iscsiadm=/sbin/iscsiadm
29
30 PARENT_PID=$BASHPID
31 WATCHDOG_TIMEOUT=15
32
33 protocol=""
34 portal=""
35 uri=""
36 osdname=""
37 systemid=""
38
39 usage()
40 {
41         echo "Usage: $0 -u <URI> -o <OSDNAME> -s <SYSTEMID>"
42         echo "Options:"
43         echo  "-u               target uri e.g. iscsi://<ip>:<port>"
44         echo  "-o               osdname of the target OSD"
45         echo  "-s               systemid of the target OSD"
46 }
47
48 parse_cmdline()
49 {
50         argc=$#
51         if [ $# -lt 3 ]; then
52                 usage
53                 exit 1
54         fi
55
56         # parse the input arguments
57         while getopts "u:o:s:" options; do
58             case $options in
59                 u ) uri=$OPTARG;;
60                 o ) osdname=$OPTARG;;
61                 s ) systemid=$OPTARG;;
62                 \? ) usage
63                         exit 1;;
64                 * )  usage
65                         exit 1;;
66             esac
67         done
68
69         echo "-u : $uri"
70         echo "-o : $osdname"
71         echo "-s : $systemid"
72
73         protocol=`echo $uri | awk -F ':' '{print $1}'`
74         portal=`echo $uri | awk -F '//' '{print $2}'`
75 }
76
77 watchdog()
78 {
79         timeout=$1
80         portal=$2
81
82         sleep $timeout
83         if kill -9 $PARENT_PID; then
84             echo "watchdog : Timed out (>$timeout seconds) while login into $portal" | logger -t "osd_login"
85         fi
86         echo "watchdog: exiting .."
87         exit 2
88 }
89
90 login_iscsi_osd()
91 {
92         echo "login into: $1"
93         if ! $iscsiadm -m discovery -o nonpersistent -t sendtargets -p $1 --login; then
94                 echo "$iscsiadm -m discovery -t sendtargets -p $1 --login returned error $? !"
95                 sleep 1;
96         fi
97 }
98
99 echo "============= osd_login ========="
100 echo "progname : $0"
101 parse_cmdline "$@"
102 echo "protocol: $protocol"
103 echo "portal: $portal"
104
105 watchdog $WATCHDOG_TIMEOUT $portal &
106 watchdog_pid=$!
107
108 case $protocol in
109 iscsi)
110         login_iscsi_osd $portal |& logger -t "osd_login"
111         ;;
112 *)
113         echo "Error: protocol $protocol not supported !" | logger -t "osd_login"
114         ;;
115 esac
116
117 kill -9 $watchdog_pid
118 exit 0