-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathiorelay-bind-nfs.sh
executable file
·84 lines (78 loc) · 2.18 KB
/
iorelay-bind-nfs.sh
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
#!/bin/bash
###############################################################################
#
# Copyright (C) 2007-2008 Lawrence Livermore National Security, LLC.
# Produced at Lawrence Livermore National Laboratory.
# Written by Jim Garlick <[email protected]>.
#
# UCRL-CODE-235358
#
# This file is part of chaos-spankings, a set of spank plugins for SLURM.
#
# This 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 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, see <http://www.gnu.org/licenses/>.
#
###############################################################################
#
# iorelay-bind-nfs - bind directories from mntpt over all nfs mounted
# file systems
#
# Run as root in private namespace
#
declare -r prog=iorelay-bind-nfs
die ()
{
echo "$prog: $1" >&2
exit 1
}
warn ()
{
echo "$prog: $1" >&2
}
usage ()
{
echo "Usage: $prog -m mntpt"
exit 1
}
listnfs ()
{
local src dst typ opts a1 a2
cat /proc/mounts | while read src dst typ opts a1 a2; do
[ ${typ} = nfs ] && echo ${dst}
fi
done
}
[ -n "$SLURM_NODELIST" ] || die "SLURM_NODELIST is not set"
relayhost=$(echo $SLURM_NODELIST | glob-hosts -n1)
[ "$(hostname)" = "$relayhost" ] && exit 0 # silently exit if relayhost
uopt=0
mntpt=""
while getopts "m:" opt; do
case ${opt} in
m) mntpt=${OPTARG} ;;
*) usage ;;
esac
done
shift $((${OPTIND} - 1))
[ $# = 0 ] || usage
[ -n "$mntpt" ] || usage
[ -d $mntpt ] || die "not a directory: $mntpt"
count=0
for dir in $(listnfs); do
if [ -d ${mntpt}/${dir} ]; then
mount --bind ${mntpt}/${dir} ${dir} || warn "bind ${dir} failed"
count=$(($count+1))
fi
done
warn "relayed $count file systems"
exit 0