Whamcloud - gitweb
LU-12616 obclass: fix MDS start/stop race
[fs/lustre-release.git] / lustre / conf / resource / Lustre
1 #!/bin/sh
2 #
3 # License:      GNU General Public License (GPL)v2
4 # Description:  Manages Lustre server on a shared storage
5 # Written by:   Gabriele Paciucci, Nathaniel Clark
6 # Release Date: 28 February 2017
7 # Release Version: 1.0.1
8 # Copyright (c) 2017, Intel Corporation
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms and conditions of the GNU General Public License,
12 # version 2, as published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # General Public License for more details.
18 #
19 #
20 # usage: ./Lustre {start|stop|status|monitor|validate-all|meta-data}
21 #
22 #               OCF parameters are as follows:
23 #               OCF_RESKEY_target - the device or ZFS volume to mount/umount
24 #               OCF_RESKEY_mountpoint - the mountpoint to use
25 #               OCF_RESKEY_mountoptions - any mount options to use
26 #######################################################################
27 # Initialization:
28
29 : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
30 . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
31
32
33 # Variables used by multiple methods
34
35
36 #######################################################################
37
38 # USAGE
39
40 usage() {
41     echo "usage: $0 {start|stop|status|monitor|validate-all|meta-data}"
42 }
43
44 # META-DATA
45
46 meta_data() {
47     cat <<END
48 <?xml version="1.0"?>
49 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
50 <resource-agent name="Lustre">
51 <version>1.0.1</version>
52 <longdesc lang="en">
53 This script manages Lustre Targets (MGT, MDT, OST).
54 The script is able to mount/umount Lustre Targets.
55
56 The standard monitor operation of depth 0 (also known as probe)
57 checks if the filesystem is mounted and lustre is healthy
58 </longdesc>
59 <shortdesc lang="en">Lustre management</shortdesc>
60
61 <parameters>
62
63 <parameter name="target" unique="1" required="1">
64 <longdesc lang="en">
65 The name of the target created during the Lustre format
66 (e.g. /dev/sda, ZPOOL/MGS, /dev/mapper/mpatha)
67 </longdesc>
68 <shortdesc lang="en">Lustre target name</shortdesc>
69 <content type="string" default="" />
70 </parameter>
71
72 <parameter name="mountpoint" unique="1" required="1">
73 <longdesc lang="en">
74 The mount point where the Lustre target will be mounted.
75 </longdesc>
76 <shortdesc lang="en">Mount point for Lustre</shortdesc>
77 <content type="string" default="" />
78 </parameter>
79
80 <parameter name="mountoptions" unique="1" required="0">
81 <longdesc lang="en">
82 Any additional mount options for the Lustre target. (eg: "-o skpath=/path/to/keys")
83 </longdesc>
84 <shortdesc lang="en">Mount options for Lustre target</shortdesc>
85 <content type="string" default="" />
86 </parameter>
87
88 </parameters>
89
90 <actions>
91 <action name="start"   timeout="300s" />
92 <action name="stop"    timeout="300s" />
93 <action name="monitor" depth="0"  timeout="300s" interval="20s" />
94 <action name="validate-all"  timeout="30s" />
95 <action name="meta-data"  timeout="5s" />
96 </actions>
97 </resource-agent>
98 END
99     exit $OCF_SUCCESS
100 }
101
102 #####################################################################
103 # STATUS
104 #
105
106 lustre_is_mounted () {
107     # Verify if this is consistent, check pointpoint and filesystem
108     # against source (i.e. device)
109     local dev=$(findmnt -t lustre -ln -o SOURCE -T $(realpath "$OCF_RESKEY_mountpoint"))
110     local target=$(realpath "$OCF_RESKEY_target" 2> /dev/null)
111
112     [ -n "$dev" ] && [ "$dev" == "$OCF_RESKEY_target" -o "$dev" == "$target" ]
113 }
114
115 lustre_monitor () {
116     if ! lustre_is_mounted; then
117         ocf_log err "$OCF_RESKEY_target is not mounted"
118         return $OCF_NOT_RUNNING
119     fi
120
121     # TODO: Add better status monitoring
122     return $OCF_SUCCESS
123 }
124
125 #####################################################################
126 # ACTIONS
127 #
128
129 lustre_mount () {
130     if ! lustre_is_mounted; then
131         ocf_log info "Starting to mount $OCF_RESKEY_target"
132
133         output=$(mount -t lustre $OCF_RESKEY_mountoptions $OCF_RESKEY_target $OCF_RESKEY_mountpoint 2>&1)
134         rc=$?
135         if [ $rc -eq 0 ]; then
136             ocf_log info "$OCF_RESKEY_target mounted successfully"
137             [ -n "$output" ] && ocf_log info "$output"
138             return $OCF_SUCCESS
139         fi
140         ocf_log err "$OCF_RESKEY_target mount failed, rc=$rc"
141         ocf_log err "$output"
142         return $OCF_ERR_GENERIC
143     fi
144     return $OCF_SUCCESS
145 }
146
147 lustre_umount () {
148     if lustre_is_mounted; then
149         ocf_log info "Starting to unmount $OCF_RESKEY_target"
150
151         output=$(umount $OCF_RESKEY_mountpoint 2>&1)
152         rc=$?
153         if [ $rc -eq 0 ]; then
154             ocf_log info "$OCF_RESKEY_target unmounted successfully"
155             [ -n "$output" ] && ocf_log info "$output"
156             return $OCF_SUCCESS
157         fi
158         ocf_log err "$OCF_RESKEY_target unmount failed, rc=$rc"
159         ocf_log err "$output"
160         return $OCF_ERR_GENERIC
161     fi
162     return $OCF_SUCCESS
163 }
164
165 all_start () {
166     lustre_mount
167     mnt_success=$?
168     if [ "$mnt_success" != "$OCF_SUCCESS" ]; then
169         ocf_log err "$OCF_RESKEY_target can not be mounted with this error: $mnt_success"
170         return $OCF_ERR_GENERIC
171     fi
172     return $OCF_SUCCESS
173 }
174
175 all_stop () {
176     lustre_umount
177     mnt_success=$?
178     if [ "$mnt_success" != "$OCF_SUCCESS" ]; then
179         ocf_log err "$OCF_RESKEY_target can not be unmounted with this error: $mnt_success"
180         return $OCF_ERR_GENERIC
181     fi
182     return $OCF_SUCCESS
183 }
184
185 validate () {
186     if [ ! -d "$(realpath $OCF_RESKEY_mountpoint)" ]; then
187         ocf_log err "$OCF_RESKEY_mountpoint can not be found"
188         return $OCF_ERR_INSTALLED
189     fi
190     if ! modinfo -n lustre >/dev/null 2>&1; then
191         ocf_log err "lustre module not available"
192         return $OCF_ERR_INSTALLED
193     fi
194     return $OCF_SUCCESS
195 }
196
197 case $1 in
198     meta-data)          meta_data;;
199     start)              all_start;;
200     stop)               all_stop;;
201     status|monitor)     lustre_monitor;;
202     validate-all)       validate;;
203     usage)              usage
204         exit $OCF_SUCCESS
205         ;;
206     *)                  exit $OCF_ERR_UNIMPLEMENTED;;
207 esac