-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlizardfs
executable file
·154 lines (127 loc) · 3.32 KB
/
lizardfs
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
#!/bin/bash
usage() {
err "Invalid usage. Usage: "
err "\t$0 init"
err "\t$0 attach <json params>"
err "\t$0 detach <mount device>"
err "\t$0 mount <mount dir> <mount device> <json params>"
err "\t$0 unmount <mount dir>"
exit 1
}
err() {
echo -ne $* 1>&2 '\n'
}
log() {
echo -ne $* >&1
}
detach() {
log "{\"status\": \"Not supported\" }"
exit 0
}
ismounted() {
MOUNT=`findmnt -n ${MNTPATH} 2>/dev/null | cut -d' ' -f1`
if [ "${MOUNT}" == "${MNTPATH}" ]; then
echo "1"
else
echo "0"
fi
}
unmount() {
MNTPATH=$1
echo $1 $2 $3 $4 >> unmount.log
if [ $(ismounted) -eq 0 ] ; then
log "{\"status\": \"Success\"}"
exit 0
fi
umount ${MNTPATH} &> /dev/null
if [ $? -ne 0 ]; then
err "{ \"status\": \"Failed\", \"message\": \"Failed to unmount volume at ${MNTPATH}\"}"
exit 1
fi
rmdir ${MNTPATH} &> /dev/null
log "{\"status\": \"Success\"}"
exit 0
}
attach() {
log "{\"status\": \"Not supported\" }"
exit 0
}
getvolumename() {
log "{\"status\": \"Not supported\" }"
exit 0
}
waitforattach() {
# Whatever, you can't attach/detach/waitforattach a LizardFS volume (same as NFS) : return some junk
log "{\"status\": \"Success\", \"device\": \"/dev/bounded-local\"}"
exit
}
domount() {
MNTPATH=$1
LFSFOLDER=${MNTPATH##*/}
# Okay, I want to provision the folder in the root of my LizardFS : each pod bound to a PVC bound to a PV has a folder created (folder name is the PV name bound to the PVC)
# Obvisouly you need to have a fuse mountpoint on /mnt pointing to the root of your LizardFS.
# TO DO : Automated quickmount -> mkdir -> unmount so all the logic is embedded in the flexvolume driver.
mkdir -p /mnt/$LFSFOLDER
# It appears the controllers do a first request on mount with the following arguments :
# /var/lib/kubelet/plugins/kubernetes.io/flexvolume/lowet84/lizardfs/mounts/mfs-volume /dev/bounded-local {"host":"mfsmaster","kubernetes.io/fsType":"","kubernetes.io/readwrite":"rw","port":"9421"}
# $PATH (we don't want to mount that obvisouly) $DEV $JSON_OPTS
# I don't know the usefulness of this, thus, we return success for the subsequent query with the correct parameters
if [ $# -eq 3 ]
then
log "{\"status\": \"Success\"}"
exit 0
else
# /var/lib/kubelet/pods/c6f7f490-6009-11e7-83d0-005056af1192/volumes/lowet84~lizardfs/mfs-volume {"host":"mfsmaster","kubernetes.io/fsType":"","kubernetes.io/readwrite":"rw","port":"9421"}
# $PATH $JSON_OPTS
HOST=$(echo $2|jq -r '.["host"]')
PORT=$(echo $2|jq -r '.["port"]')
fi
if [ $(ismounted) -eq 1 ] ; then
log "{\"status\": \"Success\"}"
exit 0
fi
mkdir -p ${MNTPATH} &> /dev/null
echo "mfsmount -H $HOST -P $PORT -o big_writes,nosuid,nodev,noatime -S $LFSFOLDER $MNTPATH" >> mount.log
mfsmount -H $HOST -P $PORT -o big_writes,nosuid,nodev,noatime -S $LFSFOLDER $MNTPATH &> /dev/null
if [ $? -ne 0 ]; then
err "{ \"status\": \"Failure\", \"message\": \"Failed to mount lizardfs at ${MNTPATH}\"}"
exit 1
fi
log "{\"status\": \"Success\"}"
exit 0
}
op=$1
if [ "$op" = "init" ]; then
log "{\"status\": \"Success\"}"
exit 0
fi
if [ $# -lt 2 ]; then
usage
fi
shift
case "$op" in
attach)
attach $*
;;
detach)
detach $*
;;
mount)
domount $*
;;
mountdevice)
domount $*
;;
unmount)
unmount $*
;;
getvolumename)
getvolumename $*
;;
waitforattach)
waitforattach $*
;;
*)
usage
esac
exit 1