summaryrefslogtreecommitdiffstats
path: root/xlators/mount/fuse/utils/mount.glusterfs.in
blob: 954032620155818c6f95c03fc015a1670c59ff71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/bin/bash
# (C) 2006, 2007, 2008 Z RESEARCH Inc. <http://www.zresearch.com>
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#   
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#   
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA

function _init ()
{
    # log level definitions
    LOG_NONE=NONE;
    LOG_CRITICAL=CRITICAL;
    LOG_ERROR=ERROR;
    LOG_WARNING=WARNING;
    LOG_NORMAL=NORMAL
    LOG_DEBUG=DEBUG;
    LOG_TRACE=TRACE;

    # set default log level to NORMAL
    log_level=$LOG_NORMAL;
    prefix="@prefix@";
    exec_prefix=@exec_prefix@;
    cmd_line=$(echo "@sbindir@/glusterfs");
}

function start_glusterfs ()
{
    if [ -n "$log_level_str" ]; then
	case "$log_level_str" in
	    "ERROR")
		log_level=$LOG_ERROR;
		;;
            "NORMAL")
                log_level=$LOG_NORMAL
                ;;
	    "DEBUG")
		log_level=$LOG_DEBUG;
		;;
	    "CRITICAL")
		log_level=$LOG_CRITICAL;
		;;
	    "WARNING")
		log_level=$LOG_WARNING;
		;;
	    "TRACE")
		log_level=$LOG_TRACE;
		;;
	    "NONE")
		log_level=$LOG_NONE;
		;;
	    *)
		echo "invalid log level $log_level_str, using NORMAL";
		log_level=$LOG_NORMAL;
		;;
	esac
    fi
    cmd_line=$(echo "$cmd_line --log-level=$log_level");
    
    if [ -n "$log_file" ]; then
	cmd_line=$(echo "$cmd_line --log-file=$log_file");
    fi

    if [ -n "$volfile_check" ]; then
	cmd_line=$(echo "$cmd_line --volfile-check");
    fi

    if [ -n "$direct_io_mode" ]; then
	cmd_line=$(echo "$cmd_line --disable-direct-io-mode");
    fi
    
    if [ -z "$volfile_loc" ]; then
        if  [ -n "$server_ip" ]; then
	    if [ -n "$transport" ]; then 
	        cmd_line=$(echo "$cmd_line \
--volfile-server=$server_ip \
--volfile-server-port=$server_port \
--volfile-server-transport=$transport");
	    else
	        cmd_line=$(echo "$cmd_line \
--volfile-server=$server_ip \
--volfile-server-port=$server_port");
	    fi
            if [ -n "$volume_id" ]; then
                cmd_line=$(echo "$cmd_line --volfile-id=$volume_id");
            fi
        fi
    else
        cmd_line=$(echo "$cmd_line --volfile=$volfile_loc");
    fi

    if [ -n "$log_server" ]; then
        if [ -n "$log_server_port" ]; then
            cmd_line=$(echo "$cmd_line \
--log-server=$log_server \
--log-server-port=$log_server_port");
        fi
    fi

    if [ -n "$volume_name" ]; then
        cmd_line=$(echo "$cmd_line --volume-name=$volume_name");
    fi
    
    cmd_line=$(echo "$cmd_line $mount_point");
    exec $cmd_line;
}

function usage ()
{

echo "Usage:  mount.glusterfs <volumeserver>:<volumeid/volumeport> -o <options> <mountpoint> 
Options: 
man 8 mount.glusterfs 

To display the version number of the mount helper: 
mount.glusterfs --version"

}

function main ()
{
    helper=$(echo "$@" | sed -n 's/.*\--[ ]*\([^ ]*\).*/\1/p');

    options=$(echo "$@" | sed -n 's/.*\-o[ ]*\([^ ]*\).*/\1/p');

    new_log_level=$(echo "$options" | sed -n 's/.*log-level=\([^,]*\).*/\1/p');
    
    [ -n "$new_log_level" ] && {
	log_level_str="$new_log_level";
    }

    log_file=$(echo "$options" | sed -n 's/.*log-file=\([^,]*\).*/\1/p');

    transport=$(echo "$options" | sed -n 's/.*transport=\([^,]*\).*/\1/p');

    direct_io_mode=$(echo "$options" | sed -n 's/.*direct-io-mode=\([^,]*\).*/\1/p');

    volume_name=$(echo "$options" | sed -n 's/.*volume-name=\([^,]*\).*/\1/p');

    volume_id=$(echo "$options" | sed -n 's/.*volume_id=\([^,]*\).*/\1/p');

    volfile_check=$(echo "$options" | sed -n 's/.*volfile-check=\([^,]*\).*/\1/p');

    server_port=$(echo "$options" | sed -n 's/.*server-port=\([^,]*\).*/\1/p');

    log_server=$(echo "$options" | sed -n 's/.*log-server=\([^,]*\).*/\1/p');
    
    log_server_port=$(echo "$options" | sed -n 's/.*log-server-port=\([^,]*\).*/\1/p');
   
    volfile_loc="$1";
    
    [ -r "$volfile_loc" ] || {
	server_ip=$(echo "$volfile_loc" | sed -n 's/\([^\:]*\).*/\1/p');
        test_str=$(echo "$volfile_loc" | sed -n 's/.*:\([^ ]*\).*/\1/p');
        [ -n "$test_str" ] && {
            # Backward compatibility
            test_str1=$(echo "$test_str" | sed -e 's/[0-9]//g');
            [ -n "$test_str1" ] && {
                volume_id="$test_str";
            } || {
                server_port=$test_str;
            }
        } 
	volfile_loc="";
    }

    [ -n "$server_port" ] || {
        server_port="6996";
    }

    new_fs_options=$(echo "$options" | sed -e 's/[,]*log-file=[^,]*//' \
        -e 's/[,]*log-level=[^,]*//' \
        -e 's/[,]*volume-name=[^,]*//' \
        -e 's/[,]*direct-io-mode=[^,]*//' \
        -e 's/[,]*volfile-check=[^,]*//' \
        -e 's/[,]*transport=[^,]*//' \
        -e 's/[,]*server-port=[^,]*//' \
        -e 's/[,]*volume-id=[^,]*//' \
        -e 's/[,]*log-server=[^,]*//' \
        -e 's/[,]*log-server-port=[^,]*//');

    # 
    [ -n "$helper" ] && {
        cmd_line=$(echo "$cmd_line --$helper");
        exec $cmd_line;
        exit 0;
    }

    mount_provided=$(echo "$@" | cut -f2 -d'/');

    [ -n "$mount_provided" ] && {
        mount_point="/$mount_provided";
    }

    [ -z "$mount_point" ] && {
        usage;
        exit 0;
    }

    # Simple check to avoid multiple identical mounts
    if grep -q " $mount_point fuse" /etc/mtab; then
        echo -n "$0: according to mtab, GlusterFS is already mounted on "
        echo "$mount_point"
        sleep 1;
        exit 0;
    fi

    fs_options=$(echo "$fs_options,$new_fs_options");
    
    start_glusterfs;

    sleep 3;
}

_init "$@" && main "$@";