~ubuntu-branches/debian/stretch/nfs-utils/stretch

« back to all changes in this revision

Viewing changes to utils/osd_login/osd_login

  • Committer: Package Import Robot
  • Author(s): Luk Claes
  • Date: 2012-05-25 20:41:58 UTC
  • mfrom: (1.2.22)
  • Revision ID: package-import@ubuntu.com-20120525204158-fte9hh32egwbk5g3
Tags: 1:1.2.6-1
* New upstream version
  - Remove 18-dont-use-PAGE_SIZE.patch: merged upstream.
  - Update other patches.
  - Install osd_login (part of the autologin feature).
    - Add open-iscsi and watchdog to Recommends.
* Check for blank exports file (Closes: #673798).
* Add 18-osd_login-sbindir.patch to avoid FTBFS
* Add 19-iscsiadm-path.patch so osd_login works

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
PARENT_PID=$BASHPID
 
29
WATCHDOG_TIMEOUT=15
 
30
 
 
31
protocol=""
 
32
portal=""
 
33
uri=""
 
34
osdname=""
 
35
systemid=""
 
36
 
 
37
usage()
 
38
{
 
39
        echo "Usage: $0 -u <URI> -o <OSDNAME> -s <SYSTEMID>"
 
40
        echo "Options:"
 
41
        echo  "-u               target uri e.g. iscsi://<ip>:<port>"
 
42
        echo  "-o               osdname of the target OSD"
 
43
        echo  "-s               systemid of the target OSD"
 
44
}
 
45
 
 
46
parse_cmdline()
 
47
{
 
48
        argc=$#
 
49
        if [ $# -lt 3 ]; then
 
50
                usage
 
51
                exit 1
 
52
        fi
 
53
 
 
54
        # parse the input arguments
 
55
        while getopts "u:o:s:" options; do
 
56
            case $options in
 
57
                u ) uri=$OPTARG;;
 
58
                o ) osdname=$OPTARG;;
 
59
                s ) systemid=$OPTARG;;
 
60
                \? ) usage
 
61
                        exit 1;;
 
62
                * )  usage
 
63
                        exit 1;;
 
64
            esac
 
65
        done
 
66
 
 
67
        echo "-u : $uri"
 
68
        echo "-o : $osdname"
 
69
        echo "-s : $systemid"
 
70
 
 
71
        protocol=`echo $uri | awk -F ':' '{print $1}'`
 
72
        portal=`echo $uri | awk -F '//' '{print $2}'`
 
73
}
 
74
 
 
75
watchdog()
 
76
{
 
77
        timeout=$1
 
78
        portal=$2
 
79
 
 
80
        sleep $timeout
 
81
        if kill -9 $PARENT_PID; then
 
82
            echo "watchdog : Timed out (>$timeout seconds) while login into $portal" | logger -t "osd_login"
 
83
        fi
 
84
        echo "watchdog: exiting .."
 
85
        exit 2
 
86
}
 
87
 
 
88
login_iscsi_osd()
 
89
{
 
90
        echo "login into: $1"
 
91
        if ! iscsiadm -m discovery -o nonpersistent -t sendtargets -p $1 --login; then
 
92
                echo "iscsiadm -m discovery -t sendtargets -p $1 --login returned error $? !"
 
93
                sleep 1;
 
94
        fi
 
95
}
 
96
 
 
97
echo "============= osd_login ========="
 
98
echo "progname : $0"
 
99
parse_cmdline "$@"
 
100
echo "protocol: $protocol"
 
101
echo "portal: $portal"
 
102
 
 
103
watchdog $WATCHDOG_TIMEOUT $portal &
 
104
watchdog_pid=$!
 
105
 
 
106
case $protocol in
 
107
iscsi)
 
108
        login_iscsi_osd $portal |& logger -t "osd_login"
 
109
        ;;
 
110
*)
 
111
        echo "Error: protocol $protocol not supported !" | logger -t "osd_login"
 
112
        ;;
 
113
esac
 
114
 
 
115
kill -9 $watchdog_pid
 
116
exit 0