Debian Codegraph @

heartbeat/Filesystem

raw symbols SCIP
1 #!/bin/sh
2 #
3 # Support: [email protected]
4 # License: GNU General Public License (GPL)
5 #
6 # Filesystem
7 # Description: Manages a Filesystem on a shared storage medium.
8 # Original Author: Eric Z. Ayers ([email protected])
9 # Original Release: 25 Oct 2000
10 #
11 # usage: ./Filesystem {start|stop|status|monitor|validate-all|meta-data}
12 #
13 # OCF parameters are as below:
14 # OCF_RESKEY_device
15 # OCF_RESKEY_directory
16 # OCF_RESKEY_fstype
17 # OCF_RESKEY_options
18 # OCF_RESKEY_statusfile_prefix
19 # OCF_RESKEY_run_fsck
20 # OCF_RESKEY_fast_stop
21 # OCF_RESKEY_force_clones
22 # OCF_RESKEY_force_unmount
23 # OCF_RESKEY_term_signals
24 # OCF_RESKEY_kill_signals
25 # OCF_RESKEY_signal_delay
26 # See also the ocf_heartbeat_Filesystem(7) man page.
27
28 #
29 #OCF_RESKEY_device : name of block device for the filesystem. e.g. /dev/sda1, /dev/md0
30 # Or a -U or -L option for mount, or an NFS mount specification
31 #OCF_RESKEY_directory : the mount point for the filesystem
32 #OCF_RESKEY_fstype : optional name of the filesystem type. e.g. ext2
33 #OCF_RESKEY_options : options to be given to the mount command via -o
34 #OCF_RESKEY_statusfile_prefix : the prefix used for a status file for monitoring
35 #OCF_RESKEY_run_fsck : fsck execution mode: auto(default)/force/no
36 #OCF_RESKEY_fast_stop : fast stop: yes(default)/no
37 #OCF_RESKEY_force_clones : allow running the resource as clone. e.g. local xfs mounts
38 # for each brick in a glusterfs setup
39 #
40 #
41 # This assumes you want to manage a filesystem on a shared (SCSI) bus,
42 # on a replicated device (such as DRBD), or a network filesystem (such
43 # as NFS or Samba).
44 #
45 # Do not put this filesystem in /etc/fstab. This script manages all of
46 # that for you.
47 #
48 # NOTE: If 2 or more nodes mount the same file system read-write, and
49 # that file system is not designed for that specific purpose
50 # (such as GFS or OCFS2), and is not a network file system like
51 # NFS or Samba, then the filesystem is going to become
52 # corrupted.
53 #
54 # As a result, you should use this together with the stonith
55 # option and redundant, independent communications paths.
56 #
57 # If you don't do this, don't blame us when you scramble your
58 # disk.
59
60 #######################################################################
61 # Initialization:
62
63 : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
64 . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
65
66 # Defaults
67 DFLT_STATUSDIR=".Filesystem_status/"
68
69 # Parameter defaults
70
71 OCF_RESKEY_device_default=""
72 OCF_RESKEY_directory_default=""
73 OCF_RESKEY_fstype_default=""
74 OCF_RESKEY_options_default=""
75 OCF_RESKEY_statusfile_prefix_default="${DFLT_STATUSDIR}"
76 OCF_RESKEY_run_fsck_default="auto"
77 OCF_RESKEY_fast_stop_default="no"
78 OCF_RESKEY_force_clones_default="false"
79 OCF_RESKEY_force_unmount_default="true"
80 OCF_RESKEY_term_signals_default="TERM"
81 OCF_RESKEY_kill_signals_default="KILL"
82 OCF_RESKEY_signal_delay_default="1"
83
84 # RHEL specific defaults
85 if is_redhat_based; then
86 get_os_ver
87 ocf_version_cmp "$VER" "9.0" 2>/dev/null
88
89 case "$?" in
90 # RHEL >= 9
91 1|2)
92 OCF_RESKEY_force_unmount_default="safe";;
93 # RHEL < 9 and fallback if ocf_version_cmp() fails
94 *)
95 OCF_RESKEY_fast_stop_default="yes";;
96 esac
97 fi
98
99
100 if [ -z "${OCF_RESKEY_fast_stop}" ]; then
101 case "$OCF_RESKEY_fstype" in
102 gfs2)
103 OCF_RESKEY_fast_stop="no";;
104 *)
105 OCF_RESKEY_fast_stop=${OCF_RESKEY_fast_stop_default};;
106 esac
107 fi
108 : "fast_stop ::" ${OCF_RESKEY_fast_stop}
109 : "device ::" ${OCF_RESKEY_device=${OCF_RESKEY_device_default}}
110 : "directory ::" ${OCF_RESKEY_directory=${OCF_RESKEY_directory_default}}
111 : "fstype ::" ${OCF_RESKEY_fstype=${OCF_RESKEY_fstype_default}}
112 : "options ::" ${OCF_RESKEY_options=${OCF_RESKEY_options_default}}
113 : "statusfile_prefix::" ${OCF_RESKEY_statusfile_prefix=${OCF_RESKEY_statusfile_prefix_default}}
114 : "run_fsck ::" ${OCF_RESKEY_run_fsck=${OCF_RESKEY_run_fsck_default}}
115 : "force_clones ::" ${OCF_RESKEY_force_clones=${OCF_RESKEY_force_clones_default}}
116 : "force_umount ::" ${OCF_RESKEY_force_unmount=${OCF_RESKEY_force_unmount_default}}
117 : "term_signals ::" ${OCF_RESKEY_term_signals=${OCF_RESKEY_term_signals_default}}
118 : "kill_signals ::" ${OCF_RESKEY_kill_signals=${OCF_RESKEY_kill_signals_default}}
119 : "signal_delay ::" ${OCF_RESKEY_signal_delay=${OCF_RESKEY_signal_delay_default}}
120
121 # Variables used by multiple methods
122 HOSTOS=$(uname)
123 TAB=' '
124
125 # The status file is going to an extra directory, by default
126 #
127 prefix=${OCF_RESKEY_statusfile_prefix}
128 : ${prefix:=$DFLT_STATUSDIR}
129 suffix="${OCF_RESOURCE_INSTANCE}"
130 [ "$OCF_RESKEY_CRM_meta_clone" ] &&
131 suffix="${suffix}_$OCF_RESKEY_CRM_meta_clone"
132 suffix="${suffix}_$(uname -n)"
133 STATUSFILE="${OCF_RESKEY_directory}/$prefix$suffix"
134
135 #######################################################################
136
137 usage() {
138 cat <<-EOT
139 usage: $0 {start|stop|status|monitor|validate-all|meta-data}
140 EOT
141 }
142
143 meta_data() {
144 cat <<END
145 <?xml version="1.0"?>
146 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
147 <resource-agent name="Filesystem" version="1.1">
148 <version>1.0</version>
149
150 <longdesc lang="en">
151 Resource script for Filesystem. It manages a Filesystem on a
152 shared storage medium.
153
154 The standard monitor operation of depth 0 (also known as probe)
155 checks if the filesystem is mounted. If you want deeper tests,
156 set OCF_CHECK_LEVEL to one of the following values:
157
158 10: read first 16 blocks of the device (raw read)
159
160 This doesn't exercise the filesystem at all, but the device on
161 which the filesystem lives. This is noop for non-block devices
162 such as NFS, SMBFS, or bind mounts.
163
164 20: test if a status file can be written and read
165
166 The status file must be writable by root. This is not always the
167 case with an NFS mount, as NFS exports usually have the
168 "root_squash" option set. In such a setup, you must either use
169 read-only monitoring (depth=10), export with "no_root_squash" on
170 your NFS server, or grant world write permissions on the
171 directory where the status file is to be placed.
172 </longdesc>
173 <shortdesc lang="en">Manages filesystem mounts</shortdesc>
174
175 <parameters>
176 <parameter name="device" required="1">
177 <longdesc lang="en">
178 The name of block device for the filesystem, or -U, -L options for mount, or NFS mount specification.
179
180 NOTE: On Linux /dev/disk/by-{uuid,label}/ are preferred to -U/-L.
181 </longdesc>
182 <shortdesc lang="en">block device</shortdesc>
183 <content type="string" default="${OCF_RESKEY_device_default}" />
184 </parameter>
185
186 <parameter name="directory" required="1">
187 <longdesc lang="en">
188 The mount point for the filesystem.
189 </longdesc>
190 <shortdesc lang="en">mount point</shortdesc>
191 <content type="string" default="${OCF_RESKEY_directory_default}" />
192 </parameter>
193
194 <parameter name="fstype" required="1">
195 <longdesc lang="en">
196 The type of filesystem to be mounted.
197 </longdesc>
198 <shortdesc lang="en">filesystem type</shortdesc>
199 <content type="string" default="${OCF_RESKEY_fstype_default}" />
200 </parameter>
201
202 <parameter name="options">
203 <longdesc lang="en">
204 Any extra options to be given as -o options to mount.
205
206 For bind mounts, add "bind" here and set fstype to "none".
207 We will do the right thing for options such as "bind,ro".
208 </longdesc>
209 <shortdesc lang="en">options</shortdesc>
210 <content type="string" default="${OCF_RESKEY_options_default}" />
211 </parameter>
212
213 <parameter name="statusfile_prefix">
214 <longdesc lang="en">
215 The prefix to be used for a status file for resource monitoring
216 with depth 20. If you don't specify this parameter, all status
217 files will be created in a separate directory.
218 </longdesc>
219 <shortdesc lang="en">status file prefix</shortdesc>
220 <content type="string" default="${OCF_RESKEY_statusfile_prefix_default}" />
221 </parameter>
222
223 <parameter name="run_fsck">
224 <longdesc lang="en">
225 Specify how to decide whether to run fsck or not.
226
227 "auto" : decide to run fsck depending on the fstype(default)
228 "force" : always run fsck regardless of the fstype
229 "no" : do not run fsck ever.
230 </longdesc>
231 <shortdesc lang="en">run_fsck</shortdesc>
232 <content type="string" default="${OCF_RESKEY_run_fsck_default}" />
233 </parameter>
234
235 <parameter name="fast_stop">
236 <longdesc lang="en">
237 Normally, we expect no users of the filesystem and the stop
238 operation to finish quickly. If you cannot control the filesystem
239 users easily and want to prevent the stop action from failing,
240 then set this parameter to "no" and add an appropriate timeout
241 for the stop operation.
242
243 This defaults to "no" for GFS2 filesystems.
244 </longdesc>
245 <shortdesc lang="en">fast stop</shortdesc>
246 <content type="boolean" default="${OCF_RESKEY_fast_stop_default}" />
247 </parameter>
248
249 <parameter name="force_clones">
250 <longdesc lang="en">
251 The use of a clone setup for local filesystems is forbidden
252 by default. For special setups like glusterfs, cloning a mount
253 of a local device with a filesystem like ext4 or xfs independently
254 on several nodes is a valid use case.
255
256 Only set this to "true" if you know what you are doing!
257 </longdesc>
258 <shortdesc lang="en">allow running as a clone, regardless of filesystem type</shortdesc>
259 <content type="boolean" default="${OCF_RESKEY_force_clones_default}" />
260 </parameter>
261
262 <parameter name="force_unmount">
263 <longdesc lang="en"><![CDATA[
264 This option allows specifying how to handle processes that are
265 currently accessing the mount directory.
266
267 "true" : Kill processes accessing mount point
268 "safe" : Kill processes accessing mount point using methods that
269 avoid functions that could potentially block during process
270 detection
271 "false" : Do not kill any processes.
272
273 You may add one or more comma separated modifiers
274 "[no]move", "[no]xargs", "[no]ps".
275 For example:
276
277 "true,xargs,nops":
278 find processes using system tools,
279 then kill them "simultaneously" using "xargs kill",
280 do not bother to show process details.
281
282 "safe,move,noxargs,ps":
283 move the mount first, then
284 find processes by walking /proc/ "manually", then
285 show process details and kill them individually in a loop.
286
287 "safe,move,xargs,ps":
288 move the mount first, then
289 find processes by walking /proc/ "manually", then
290 use "xargs ps" to show process details before
291 using "xargs kill" to get rid of them.
292
293 If you have modifiers that contradict each other, the last mentioned wins,
294 "ps,nops" results in nops.
295
296 The 'safe' option uses shell logic to walk the /proc/<pid>/ directories
297 for pids using the mount point while the default option uses the
298 fuser cli tool. fuser is known to perform operations that can potentially
299 block if unresponsive nfs mounts are in use on the system.
300
301 If new users of the file system are being spawned continuously by unmanaged 3rd
302 party apps, we likely never win the race and the file system will be kept busy.
303 Which may result in a timeout and stop failure, potentially escalating to
304 hard-reset of this node via fencing.
305
306 The 'move' option tries to "mount --move" the mount point somewhere those
307 "rogue apps" do not expect it, then proceed to kill current users and attempt
308 to umount.
309
310 For 'move' to work, you will have to make sure the mount point does not reside
311 under a shared mount, for example by mount -o bind,private /mount /mount
312 before mounting /mount/point.
313 ]]></longdesc>
314 <shortdesc lang="en">Kill processes before unmount</shortdesc>
315 <content type="string" default="${OCF_RESKEY_force_unmount_default}" />
316 </parameter>
317
318 <parameter name="term_signals">
319 <longdesc lang="en">
320 Signals (names or numbers, whitespace separated) to send processes during graceful termination phase in stop-action.
321 </longdesc>
322 <shortdesc lang="en">Signals (names or numbers, whitespace separated) to send processes during graceful termination phase in stop-action</shortdesc>
323 <content type="string" default="${OCF_RESKEY_term_signals_default}" />
324 </parameter>
325
326 <parameter name="kill_signals">
327 <longdesc lang="en">
328 Signals (names or numbers, whitespace separated) to send processes during forceful killing phase in stop-action.
329 </longdesc>
330 <shortdesc lang="en">Signals (names or numbers, whitespace separated) to send processes during forceful killing phase in stop-action</shortdesc>
331 <content type="string" default="${OCF_RESKEY_kill_signals_default}" />
332 </parameter>
333
334 <parameter name="signal_delay">
335 <longdesc lang="en">
336 How many seconds to wait after sending term/kill signals to processes in stop-action.
337 </longdesc>
338 <shortdesc lang="en">How many seconds to wait after sending term/kill signals to processes in stop-action</shortdesc>
339 <content type="string" default="${OCF_RESKEY_signal_delay_default}" />
340 </parameter>
341
342 </parameters>
343
344 <actions>
345 <action name="start" timeout="60s" />
346 <action name="stop" timeout="60s" />
347 <action name="monitor" depth="0" timeout="40s" interval="20s" />
348 <action name="validate-all" timeout="5s" />
349 <action name="meta-data" timeout="5s" />
350 </actions>
351 </resource-agent>
352 END
353 }
354
355 #
356 # Make sure the kernel does the right thing with the FS buffers
357 # This function should be called after unmounting and before mounting
358 # It may not be necessary in 2.4 and later kernels, but it shouldn't hurt
359 # anything either...
360 #
361 # It's really a bug that you have to do this at all...
362 #
363 flushbufs() {
364 if have_binary $BLOCKDEV ; then
365 if [ "$blockdevice" = "yes" ] ; then
366 $BLOCKDEV --flushbufs $1
367 return $?
368 fi
369 fi
370 return 0
371 }
372
373 # Take advantage of /etc/mtab if present, use portable mount command
374 # otherwise. Normalize format to "dev mountpoint fstype".
375 is_bind_mount() {
376 echo "$options" | grep -w bind >/dev/null 2>&1
377 }
378
379 list_mounts() {
380 local inpf=""
381 local mount_list=""
382 local check_list="x"
383
384 if [ -e "/proc/mounts" ] && ! is_bind_mount; then
385 inpf=/proc/mounts
386 elif [ -f "/etc/mtab" -a -r "/etc/mtab" ]; then
387 inpf=/etc/mtab
388 fi
389
390 # Make sure that the mount list has not been changed while reading.
391 while [ "$mount_list" != "$check_list" ]; do
392 check_list="$mount_list"
393 if [ "$inpf" ]; then
394 # <device> <mountpoint> <fstype> ...
395 # Spaces in device or mountpoint are octal \040 in $inpf
396 # Convert literal spaces (field separators) to tabs
397 mount_list=$(cut -d' ' -f1,2,3 < $inpf | tr ' ' "$TAB")
398 else
399 # <device> on <mountpoint> type <fstype> ...
400 # Use tabs as field separators
401 match_string='\(.*\) on \(.*\) type \([^[:space:]]\+\) .*'
402 replace_string="\\1${TAB}\\2${TAB}\\3"
403 mount_list=$($MOUNT | sed "s/$match_string/$replace_string/g")
404 fi
405 done
406
407 # Convert octal \040 to space characters
408 printf "$mount_list"
409 }
410
411 determine_blockdevice() {
412 if [ $blockdevice = "yes" ]; then
413 return
414 fi
415
416 # Get the current real device name, if possible.
417 # (specified devname could be -L or -U...)
418 case "$FSTYPE" in
419 nfs4|nfs|aznfs|efs|smbfs|cifs|glusterfs|ceph|tmpfs|overlay|overlayfs|rozofs|zfs|cvfs|none|lustre)
420 : ;;
421 *)
422 match_string="${TAB}${CANONICALIZED_MOUNTPOINT}${TAB}"
423 DEVICE=$(list_mounts | grep "$match_string" | cut -d"$TAB" -f1)
424 if [ -b "$DEVICE" ]; then
425 blockdevice=yes
426 fi
427 ;;
428 esac
429 }
430
431 # Lists all filesystems potentially mounted under a given path,
432 # excluding the path itself.
433 list_submounts() {
434 list_mounts | grep "${TAB}${1}/" | cut -d"$TAB" -f2 | sort -r
435 }
436
437 # Lists all bind mounts of a given file system,
438 # excluding the path itself.
439 list_bindmounts() {
440 if is_bind_mount; then
441 # skip bind mount
442 # we should not umount the original file system via a bind mount
443 return
444 fi
445
446 match_string="${TAB}${1}${TAB}"
447 if list_mounts | grep "$match_string" >/dev/null 2>&1; then
448 mount_disk=$(list_mounts | grep "$match_string" | cut -d"$TAB" -f1)
449 else
450 return
451 fi
452
453 if [ -b "$mount_disk" ]; then
454 list_mounts | grep -w "$mount_disk" | grep -v "$match_string" | cut -d"$TAB" -f2 | sort -r
455 fi
456 }
457
458 # kernels < 2.6.26 can't handle bind remounts
459 bind_kernel_check() {
460 echo "$options" | grep -w ro >/dev/null 2>&1 ||
461 return
462 uname -r | awk -F. '
463 $1==2 && $2==6 {
464 sub("[^0-9].*","",$3);
465 if ($3<26)
466 exit(1);
467 }'
468 [ $? -ne 0 ] &&
469 ocf_log warn "kernel $(uname -r) cannot handle read only bind mounts"
470 }
471
472 bind_root_mount_check() {
473 if [ "$(df -P "$1" | awk 'END{print $6}')" = "/" ]; then
474 return 1
475 else
476 return 0
477 fi
478 }
479
480 bind_mount() {
481 if is_bind_mount && [ "$options" != "-o bind" ]
482 then
483 bind_kernel_check
484 bind_opts=$(echo "$options" | sed 's/bind/remount/')
485 $MOUNT $bind_opts "$MOUNTPOINT"
486 else
487 true # make sure to return OK
488 fi
489 }
490
491 is_option() {
492 echo "$OCF_RESKEY_options" | grep -w "$1" >/dev/null 2>&1
493 }
494
495 is_fsck_needed() {
496 case $OCF_RESKEY_run_fsck in
497 force) true;;
498 no) false;;
499 ""|auto)
500 case "$FSTYPE" in
501 ext4|ext4dev|ext3|reiserfs|reiser4|nss|xfs|jfs|vfat|fat|nfs4|nfs|aznfs|efs|cifs|smbfs|ocfs2|gfs2|none|lustre|glusterfs|ceph|tmpfs|overlay|overlayfs|rozofs|zfs|cvfs)
502 false;;
503 *)
504 true;;
505 esac;;
506 *)
507 ocf_log warn "Invalid parameter value for fsck: '$OCF_RESKEY_run_fsck'; setting to 'auto'"
508 OCF_RESKEY_run_fsck="auto"
509 is_fsck_needed;;
510 esac
511 }
512
513 fstype_supported()
514 {
515 local support="$FSTYPE"
516 local rc
517
518 if [ "X${HOSTOS}" = "XOpenBSD" ];then
519 # skip checking /proc/filesystems for obsd
520 return $OCF_SUCCESS
521 fi
522
523 if [ -z "$FSTYPE" -o "$FSTYPE" = none ]; then
524 : No FSTYPE specified, rely on the system has the right file-system support already
525 return $OCF_SUCCESS
526 fi
527
528 # support fuse-filesystems (e.g. GlusterFS) and Amazon Elastic File
529 # System (EFS)
530 case "$FSTYPE" in
531 fuse.*|glusterfs|rozofs) support="fuse";;
532 efs) check_binary "mount.efs"; support="nfs4";;
533 aznfs) check_binary "mount.aznfs"; support="nfs4";;
534 esac
535
536 if [ "$support" != "$FSTYPE" ]; then
537 ocf_log info "Checking support for $FSTYPE as \"$support\""
538 fi
539
540 grep -w "$support"'$' /proc/filesystems >/dev/null
541 if [ $? -eq 0 ]; then
542 # found the fs type
543 return $OCF_SUCCESS
544 fi
545
546 # if here, we should attempt to load the module and then
547 # check the if the filesystem support exists again.
548 $MODPROBE $support >/dev/null
549 if [ $? -ne 0 ]; then
550 ocf_exit_reason "Couldn't find filesystem $support in /proc/filesystems and failed to load kernel module"
551 return $OCF_ERR_INSTALLED
552 fi
553
554 # It is possible for the module to load and not be complete initialized
555 # before we check /proc/filesystems again. Give this a few trys before
556 # giving up entirely.
557 for try in $(seq 5); do
558 grep -w "$support"'$' /proc/filesystems >/dev/null
559 if [ $? -eq 0 ] ; then
560 # yes. found the filesystem after doing the modprobe
561 return $OCF_SUCCESS
562 fi
563 ocf_log debug "Unable to find support for $support in /proc/filesystems after modprobe, trying again"
564 sleep 1
565 done
566
567 ocf_exit_reason "Couldn't find filesystem $support in /proc/filesystems"
568 return $OCF_ERR_INSTALLED
569 }
570
571
572 #
573 # In the case a fresh filesystem is just created from another
574 # node on the shared storage, and is not visible yet. Then try
575 # partprobe to refresh /dev/disk/by-{label,uuid}/* up to date.
576 #
577 # DEVICE can be /dev/xxx, -U, -L
578 #
579 trigger_udev_rules_if_needed()
580 {
581 local refresh_flag="no"
582 local tmp
583 local timeout
584
585 if [ $blockdevice = "yes" ]; then
586 tmp="$DEVICE"
587 if [ "$DEVICE" != "/dev/null" -a ! -b "$DEVICE" ] ; then
588 refresh_flag="yes"
589 fi
590 else
591 tmp="$(echo $DEVICE|awk '{$1=""; print substr($0,2)}')"
592 case "$DEVICE" in
593 -U*|--uuid*)
594 tmp="/dev/disk/by-uuid/$tmp"
595 ;;
596 -L*|--label*)
597 tmp="/dev/disk/by-label/$tmp"
598 ;;
599 *)
600 # bind mount?
601 return ;;
602 esac
603 [ ! -b "$tmp" ] && refresh_flag="yes"
604 fi
605
606 [ "$refresh_flag" = "no" ] && return
607
608 have_binary partprobe && partprobe >/dev/null 2>&1
609 timeout=${OCF_RESKEY_CRM_meta_timeout:="60000"}
610 timeout=$((timeout/1000))
611 have_binary udevadm && udevadm settle -t $timeout --exit-if-exists=$tmp
612
613 return $?
614 }
615
616 #
617 # START: Start up the filesystem
618 #
619 Filesystem_start()
620 {
621 # Check if there are any mounts mounted under the mountpoint
622 match_string="${TAB}${CANONICALIZED_MOUNTPOINT}"
623 if list_mounts | grep -E "$match_string/\w+" >/dev/null 2>&1; then
624 ocf_log err "There is one or more mounts mounted under $MOUNTPOINT."
625 return $OCF_ERR_CONFIGURED
626 fi
627
628 if $move_before_umount && test -d "$MOVED_CANONICALIZED_MOUNTPOINT"; then
629 CANONICALIZED_MOUNTPOINT=$MOVED_CANONICALIZED_MOUNTPOINT \
630 move_before_umount=false \
631 Filesystem_status
632 rc=$?
633 if [ $rc -ne $OCF_NOT_RUNNING ]; then
634 msg="move_before_umount=$move_before_umount and $MOVED_CANONICALIZED_MOUNTPOINT status is [$rc]"
635 rc=$OCF_ERR_GENERIC
636 ocf_exit_reason "$msg"
637 return $rc
638 fi
639 fi
640
641 # See if the device is already mounted.
642 move_before_umount=false Filesystem_status
643 case "$?" in
644 $OCF_SUCCESS)
645 ocf_log info "Filesystem $MOUNTPOINT is already mounted."
646 return $OCF_SUCCESS
647 ;;
648 $OCF_ERR_CONFIGURED)
649 return $OCF_ERR_CONFIGURED
650 ;;
651 esac
652
653 fstype_supported || exit $OCF_ERR_INSTALLED
654
655 # Check the filesystem & auto repair.
656 # NOTE: Some filesystem types don't need this step... Please modify
657 # accordingly
658
659 trigger_udev_rules_if_needed
660
661 if [ $blockdevice = "yes" ]; then
662 if [ "$DEVICE" != "/dev/null" -a ! -b "$DEVICE" ] ; then
663 ocf_exit_reason "Couldn't find device [$DEVICE]. Expected /dev/??? to exist"
664 exit $OCF_ERR_INSTALLED
665 fi
666
667 if is_fsck_needed; then
668 ocf_log info "Starting filesystem check on $DEVICE"
669 if [ -z "$FSTYPE" ]; then
670 $FSCK -p "$DEVICE"
671 else
672 $FSCK -t "$FSTYPE" -p "$DEVICE"
673 fi
674
675 # NOTE: if any errors at all are detected, it returns non-zero
676 # if the error is >= 4 then there is a big problem
677 if [ $? -ge 4 ]; then
678 ocf_exit_reason "Couldn't successfully fsck filesystem for $DEVICE"
679 return $OCF_ERR_GENERIC
680 fi
681 fi
682 fi
683
684 [ -d "$MOUNTPOINT" ] ||
685 ocf_run mkdir -p "$MOUNTPOINT"
686 if [ ! -d "$MOUNTPOINT" ] ; then
687 ocf_exit_reason "Couldn't find directory [$MOUNTPOINT] to use as a mount point"
688 exit $OCF_ERR_INSTALLED
689 fi
690
691 flushbufs "$DEVICE"
692 # Mount the filesystem.
693 case "$FSTYPE" in
694 none) $MOUNT $options $device_opt "$DEVICE" "$MOUNTPOINT" &&
695 bind_mount
696 ;;
697 "") $MOUNT $options $device_opt "$DEVICE" "$MOUNTPOINT" ;;
698 *) $MOUNT -t "$FSTYPE" $options $device_opt "$DEVICE" "$MOUNTPOINT" ;;
699 esac
700
701 if [ $? -ne 0 ]; then
702 ocf_exit_reason "Couldn't mount device [$DEVICE] as $MOUNTPOINT"
703 return $OCF_ERR_GENERIC
704 fi
705 return $OCF_SUCCESS
706 }
707 # end of Filesystem_start
708
709 get_pids()
710 {
711 local dir=$1
712 local procs
713 local mmap_procs
714
715 if is_bind_mount && ocf_is_true "$FORCE_UNMOUNT" && ! bind_root_mount_check "$DEVICE"; then
716 ocf_log debug "Change force_umount from '$FORCE_UNMOUNT' to 'safe'"
717 FORCE_UNMOUNT=safe
718 fi
719
720 if ocf_is_true "$FORCE_UNMOUNT"; then
721 if [ "X${HOSTOS}" = "XOpenBSD" ]; then
722 fstat | grep "$dir" | awk '{print $3}'
723 elif [ "X${HOSTOS}" = "XFreeBSD" ]; then
724 $FUSER -c "$dir" 2>/dev/null
725 else
726 $FUSER -Mm "$dir" 2>/dev/null
727 fi
728 elif [ "$FORCE_UNMOUNT" = "safe" ]; then
729 # Yes, in theory, ${dir} could contain "intersting" characters
730 # and would need to be quoted for glob (find) and regex (grep).
731 # Don't do that, then.
732
733 # Avoid /proc/[0-9]*, it may cause "Argument list too long".
734 # There are several ways to filter for /proc/<pid>
735 # -mindepth 1 -not -path "/proc/[0-9]*" -prune -o ...
736 # -path "/proc/[!0-9]*" -prune -o ...
737 # -path "/proc/[0-9]*" -a ...
738 # the latter seemd to be significantly faster for this one in my naive test.
739
740 # root, cwd, exe, maps, fd: all per process, not per task ("thread").
741 # -maxdepth to avoid repeatedly scanning the same thing
742 # for all threads of a heavily threaded process.
743 #
744 # Adding -maxdepth reduced scanning from > 16 seconds to < 2 seconds
745 # on a mostly idle system that happened to run a few java processes.
746 #
747 # We can also add a dedicated helper in C do twhat is done below,
748 # which would reduce the scanning time by an
749 # additional factor of 10 again.
750 #
751 # Or trust that fuser (above) learned something in the last 15 years
752 # and avoids blocking operations meanwhile?
753 (
754 # If you want to debug this, drop this redirection.
755 # But it producess too much "No such file" noise for kernel
756 # threads or due to races with exiting processes or closing fds.
757 exec 2>/dev/null;
758 find /proc -mindepth 1 -maxdepth 3 \
759 -path "/proc/[0-9]*" \
760 -type l \( -lname "${dir}/*" -o -lname "${dir}" \) -print |
761 awk -F/ '{print $3}' | uniq
762
763 # If we have "map_files/", "find" above already found the
764 # relevant symlinks, and we don't need to grep "maps" below.
765 # Available since kernel 3.3, respectively 4.3.
766 test -d /proc/$$/map_files ||
767 # memory mappings are also per process, not per task.
768 # This finds only /proc/<pid>/maps, and not /proc/<pid>/task/<tid>/maps;
769 # if you also want the latter, drop -maxdepth.
770 find /proc -mindepth 2 -maxdepth 2 -path "/proc/[0-9]*/maps" -print |
771 xargs -r grep -l " ${dir}/" | awk -F/ '{print $3}' | uniq
772 ) | sort -u
773 fi
774 }
775
776 signal_processes() {
777 local dir=$1
778 local sig=$2
779 local pids pid
780 local nr_pids
781 local sed_script=""
782 # fuser returns a non-zero return code if none of the
783 # specified files is accessed or in case of a fatal
784 # error.
785 # We don't know whether we have one single line or mutiple lines.
786 # Canonicalize.
787 pids=$(get_pids "$dir" | tr -s ' \t\n' '\n')
788 nr_pids=$(echo "$pids" | grep -c "^.")
789
790 # for many pids, reporting and killing them indivitually just takes too long.
791 # may even be too many words for the shell!
792 #
793 # If the list of pids is too long for a single shell variable,
794 # fix your fork bomb workload, and get a better shell anyways.
795 #
796 if [ $nr_pids -eq 0 ]; then
797 ocf_log info "No processes on $dir were signalled. force_unmount is set to '$FORCE_UNMOUNT'"
798 return 1
799 fi
800 if $do_xargs_kill; then
801 if $do_ps_f; then
802 # echo "$pids" | xargs -r kill -s STOP
803 echo "sending signal $sig to $nr_pids processes:"
804
805 # According to my man page, 'ps -f "$pid"' might be good enough,
806 # but needs rather specific formatting of that argument.
807 # And 'ps -f $pid' might produce too many words.
808 # Use xargs anyway.
809 echo "$pids" | xargs ps -f 2>&1
810 fi
811 echo "$pids" | xargs -r kill -s $sig 2>&1
812 if ! $do_ps_f; then
813 if [ $nr_pids -gt 24 ]; then
814 sed_script="11 s/^.*/... and more .../; 12,$(( $nr_pids - 10))d"
815 pids=$(echo "$pids" | sed -e "$sed_script" | tr '\n' ' ')
816 fi
817 echo "sent signal $sig to ${nr_pids} processes ["${pids}"]"
818 fi
819 else
820 for pid in $pids; do
821 if $do_ps_f; then
822 echo "sending signal $sig to: $(ps -f $pid | tail -1)"
823 else
824 echo "sending signal $sig to $pid"
825 fi
826 kill -s $sig $pid
827 done
828 fi | ocf_log_pipe info
829 return 0
830 }
831 try_umount() {
832 local force_arg="$1" SUB="$2"
833 $UMOUNT $force_arg "$SUB" 2>&1 | ocf_log_pipe warn
834 list_mounts | grep "${TAB}${SUB}${TAB}" >/dev/null 2>&1 || {
835 ocf_log info "unmounted $SUB successfully"
836 return $OCF_SUCCESS
837 }
838 return $OCF_ERR_GENERIC
839 }
840 timeout_child() {
841 local pid="$1" timeout="$2" killer ret
842
843 # start job in the background that will KILL the given process after timeout expires
844 sleep $timeout && kill -s KILL $pid &
845 killer=$!
846
847 # block until the child process either exits on its own or gets killed by the above killer pipeline
848 wait $pid
849 ret=$?
850
851 # ret would be 127 + child exit code if the timeout expired (see "man wait" for more info)
852 [ $ret -lt 128 ] && kill -s KILL $killer
853 return $ret
854 }
855 fs_stop_loop() {
856 local force_arg="$1" SUB="$2" signals="$3" sig sent_signal
857 while true; do
858 sent_signal=false
859 for sig in $signals; do
860 signal_processes "$SUB" $sig && sent_signal=true
861 done
862 if $sent_signal; then
863 # Try to umount immediately after signalling, to reduce
864 # the time window in which new users of the file system
865 # may be spawned.
866 try_umount "$force_arg" "$SUB" && return $OCF_SUCCESS
867 sleep $OCF_RESKEY_signal_delay
868 fi
869 # Try to umount after the signal_delay, maybe some processes
870 # needed a moment to "exit cleanly" after receiving SIGTERM.
871 try_umount "$force_arg" "$SUB" && return $OCF_SUCCESS
872 done
873 }
874
875 fs_stop() {
876 local SUB="$1" timeout=$2 grace_time ret
877 grace_time=$((timeout/2))
878
879 # Just walking /proc may take "a long time", even if we don't find any users of this FS.
880 # If dependencies are properly configured, umount should just work.
881 # Only if that fails, try to find and kill processes that still use it.
882 try_umount "" "$SUB" && return $OCF_SUCCESS
883
884 # try gracefully terminating processes for up to half of the configured timeout
885 fs_stop_loop "" "$SUB" "$OCF_RESKEY_term_signals" &
886 timeout_child $! $grace_time
887 ret=$?
888 [ $ret -eq $OCF_SUCCESS ] && return $ret
889
890 # try killing them for the rest of the timeout
891 fs_stop_loop "$umount_force" "$SUB" "$OCF_RESKEY_kill_signals" &
892 timeout_child $! $grace_time
893 ret=$?
894 [ $ret -eq $OCF_SUCCESS ] && return $ret
895
896 # timeout expired
897 ocf_exit_reason "Couldn't unmount $SUB within given timeout"
898 return $OCF_ERR_GENERIC
899 }
900
901 try_mount_move()
902 {
903 test -d "$MOVED_CANONICALIZED_MOUNTPOINT" || mkdir "$MOVED_CANONICALIZED_MOUNTPOINT" || return
904 mount --move "$CANONICALIZED_MOUNTPOINT" "$MOVED_CANONICALIZED_MOUNTPOINT" || return
905 ocf_log info "Moved $MOUNTPOINT to $MOVED_CANONICALIZED_MOUNTPOINT"
906 return 0
907 # To test really bad timing of "action timeout":
908 # test -e /tmp/fail-after-move && rm -f /tmp/fail-after-move && kill -KILL $$
909 }
910
911 #
912 # STOP: Unmount the filesystem
913 #
914 Filesystem_stop()
915 {
916 # See if the device is currently mounted
917 move_before_umount=false Filesystem_status >/dev/null 2>&1
918 if [ $? -eq $OCF_NOT_RUNNING ]; then
919 # Already unmounted, wonderful.
920 # But did we also unmount the moved fs?
921 if $move_before_umount; then
922 CANONICALIZED_MOUNTPOINT=$MOVED_CANONICALIZED_MOUNTPOINT \
923 move_before_umount=false \
924 Filesystem_stop
925 return $?
926 else
927 rc=$OCF_SUCCESS
928 fi
929 else
930 # Wipe the status file, but continue with a warning if
931 # removal fails -- the file system might be read only
932 if [ $OCF_CHECK_LEVEL -eq 20 ]; then
933 rm -f "${STATUSFILE}"
934 if [ $? -ne 0 ]; then
935 ocf_log warn "Failed to remove status file ${STATUSFILE}."
936 fi
937 fi
938
939 # Determine the real blockdevice this is mounted on (if
940 # possible) prior to unmounting.
941 determine_blockdevice
942
943 # For networked filesystems, there's merit in trying -f:
944 case "$FSTYPE" in
945 nfs4|nfs|aznfs|efs|cifs|smbfs) umount_force="-f" ;;
946 esac
947
948 if $move_before_umount && try_mount_move ; then
949 CANONICALIZED_MOUNTPOINT=$MOVED_CANONICALIZED_MOUNTPOINT \
950 move_before_umount=false \
951 Filesystem_stop
952 return $?
953 fi
954
955 # Umount all sub-filesystems mounted under $MOUNTPOINT/ too.
956 local timeout
957 while read SUB; do
958 ocf_log info "Trying to unmount $SUB"
959 if ocf_is_true "$FAST_STOP"; then
960 timeout=6
961 else
962 timeout=${OCF_RESKEY_CRM_meta_timeout:="20000"}
963 timeout=$((timeout/1000))
964 fi
965 fs_stop "$SUB" $timeout
966 rc=$?
967 if [ $rc -ne $OCF_SUCCESS ]; then
968 ocf_exit_reason "Couldn't unmount $SUB, giving up!"
969 fi
970 done <<-EOF
971 $(list_submounts "$CANONICALIZED_MOUNTPOINT"; \
972 list_bindmounts "$CANONICALIZED_MOUNTPOINT"; \
973 echo $CANONICALIZED_MOUNTPOINT)
974 EOF
975 fi
976
977 flushbufs "$DEVICE"
978
979 return $rc
980 }
981 # end of Filesystem_stop
982
983 #
984 # STATUS: is the filesystem mounted or not?
985 #
986 Filesystem_status()
987 {
988 if $move_before_umount && test -d $MOVED_CANONICALIZED_MOUNTPOINT; then
989 # Have to recurse once.
990 CANONICALIZED_MOUNTPOINT=$MOVED_CANONICALIZED_MOUNTPOINT \
991 move_before_umount=false \
992 OP= \
993 Filesystem_status
994 rc=$?
995 if [ $rc -eq $OCF_SUCCESS ]; then
996 rc=$OCF_ERR_GENERIC
997 msg="move_before_umount=$move_before_umount and something is mounted on $MOVED_CANONICALIZED_MOUNTPOINT"
998 ocf_exit_reason "$msg"
999 return $rc
1000 fi
1001 fi
1002
1003 local match_string="${TAB}${CANONICALIZED_MOUNTPOINT}${TAB}"
1004 local mounted_device=$(list_mounts | grep "$match_string" | awk '{print $1}')
1005
1006 if [ -n "$mounted_device" ]; then
1007 if [ "X$blockdevice" = "Xyes" ]; then
1008 if [ -e "$DEVICE" ] ; then
1009 local canonicalized_device="$(readlink -f "$DEVICE")"
1010 if [ $? -ne 0 ]; then
1011 ocf_exit_reason "Could not canonicalize $DEVICE because readlink failed"
1012 exit $OCF_ERR_GENERIC
1013 fi
1014 else
1015 local canonicalized_device="$DEVICE"
1016 fi
1017 if [ -e "$mounted_device" ] ; then
1018 local canonicalized_mounted_device="$(readlink -f "$mounted_device")"
1019 if [ $? -ne 0 ]; then
1020 ocf_exit_reason "Could not canonicalize $mounted_device because readlink failed"
1021 exit $OCF_ERR_GENERIC
1022 fi
1023 else
1024 local canonicalized_mounted_device="$mounted_device"
1025 fi
1026 if [ "$canonicalized_device" != "$canonicalized_mounted_device" ]; then
1027 if ocf_is_probe || [ "$__OCF_ACTION" = "stop" ]; then
1028 ocf_log debug "Another device ($mounted_device) is already mounted on $MOUNTPOINT"
1029 rc=$OCF_NOT_RUNNING
1030 else
1031 ocf_exit_reason "Another device ($mounted_device) is already mounted on $MOUNTPOINT"
1032 if [ "$__OCF_ACTION" = "monitor" ]; then
1033 rc=$OCF_ERR_GENERIC
1034 else
1035 rc=$OCF_ERR_CONFIGURED
1036 fi
1037 fi
1038 fi
1039 else
1040 rc=$OCF_SUCCESS
1041 msg="$MOUNTPOINT is mounted (running)"
1042 fi
1043 else
1044 rc=$OCF_NOT_RUNNING
1045 msg="$MOUNTPOINT is unmounted (stopped)"
1046 fi
1047
1048 # Special case "monitor" to check whether the UUID cached and
1049 # on-disk still match?
1050 case "$OP" in
1051 status) ocf_log info "$msg";;
1052 esac
1053
1054 return $rc
1055 }
1056 # end of Filesystem_status
1057
1058
1059 # Note: the read/write tests below will stall in case the
1060 # underlying block device (or in the case of a NAS mount, the
1061 # NAS server) has gone away. In that case, if I/O does not
1062 # return to normal in time, the operation hits its timeout
1063 # and it is up to the CRM to initiate appropriate recovery
1064 # actions (such as fencing the node).
1065 #
1066 # MONITOR 10: read the device
1067 #
1068 Filesystem_monitor_10()
1069 {
1070 if [ "$blockdevice" = "no" ] ; then
1071 ocf_log warn "$DEVICE is not a block device, monitor 10 is noop"
1072 return $OCF_SUCCESS
1073 fi
1074 dd_opts="iflag=direct bs=4k count=1"
1075 err_output=$(dd if="$DEVICE" $dd_opts 2>&1 >/dev/null)
1076 if [ $? -ne 0 ]; then
1077 ocf_exit_reason "Failed to read device $DEVICE"
1078 ocf_log err "dd said: $err_output"
1079 return $OCF_ERR_GENERIC
1080 fi
1081 return $OCF_SUCCESS
1082 }
1083 #
1084 # MONITOR 20: write and read a status file
1085 #
1086 Filesystem_monitor_20()
1087 {
1088 if [ "$blockdevice" = "no" ] ; then
1089 # O_DIRECT not supported on cifs/smbfs
1090 dd_opts="oflag=sync bs=4k conv=fsync,sync"
1091 else
1092 # Writing to the device in O_DIRECT mode is imperative
1093 # to bypass caches.
1094 dd_opts="oflag=direct,sync bs=4k conv=fsync,sync"
1095 fi
1096 status_dir=$(dirname "$STATUSFILE")
1097 [ -d "$status_dir" ] || mkdir -p "$status_dir"
1098 err_output=$(echo "${OCF_RESOURCE_INSTANCE}" | dd of="${STATUSFILE}" $dd_opts 2>&1)
1099 if [ $? -ne 0 ]; then
1100 ocf_exit_reason "Failed to write status file ${STATUSFILE}"
1101 ocf_log err "dd said: $err_output"
1102 return $OCF_ERR_GENERIC
1103 fi
1104 test -f "${STATUSFILE}"
1105 if [ $? -ne 0 ]; then
1106 ocf_exit_reason "Cannot stat the status file ${STATUSFILE}"
1107 return $OCF_ERR_GENERIC
1108 fi
1109 cat "${STATUSFILE}" > /dev/null
1110 if [ $? -ne 0 ]; then
1111 ocf_exit_reason "Cannot read the status file ${STATUSFILE}"
1112 return $OCF_ERR_GENERIC
1113 fi
1114 return $OCF_SUCCESS
1115 }
1116
1117 Filesystem_monitor()
1118 {
1119 Filesystem_status
1120 rc=$?
1121 if [ $rc -ne $OCF_SUCCESS ]; then
1122 return $rc
1123 fi
1124
1125 if [ $rc -eq $OCF_SUCCESS -a $OCF_CHECK_LEVEL -gt 0 ]; then
1126 case "$OCF_CHECK_LEVEL" in
1127 10) Filesystem_monitor_10; rc=$?;;
1128 20) Filesystem_monitor_20; rc=$?;;
1129 *)
1130 ocf_exit_reason "unsupported monitor level $OCF_CHECK_LEVEL"
1131 rc=$OCF_ERR_CONFIGURED
1132 ;;
1133 esac
1134 fi
1135 return $rc
1136 }
1137 # end of Filesystem_monitor
1138
1139
1140 #
1141 # VALIDATE_ALL: Are the instance parameters valid?
1142 # FIXME!! The only part that's useful is the return code.
1143 # This code always returns $OCF_SUCCESS (!)
1144 # FIXME!! Needs some tuning to match fstype_supported() (e.g., for
1145 # fuse). Can we just call fstype_supported() with a flag like
1146 # "no_modprobe" instead?
1147 #
1148 Filesystem_validate_all()
1149 {
1150 # If we are supposed to do monitoring with status files, then
1151 # we need a utility to write in O_DIRECT mode.
1152 if [ $OCF_CHECK_LEVEL -gt 0 ]; then
1153 check_binary dd
1154 # Note: really old coreutils version do not support
1155 # the "oflag" option for dd. We don't check for that
1156 # here. In case dd does not support oflag, monitor is
1157 # bound to fail, with dd spewing an error message to
1158 # the logs. On such systems, we must do without status
1159 # file monitoring.
1160 fi
1161
1162 #TODO: How to check the $options ?
1163 return $OCF_SUCCESS
1164 }
1165
1166 #
1167 # set the blockdevice variable to "no" or "yes"
1168 #
1169 set_blockdevice_var() {
1170 blockdevice=no
1171
1172 # these are definitely not block devices
1173 case "$FSTYPE" in
1174 nfs4|nfs|aznfs|efs|smbfs|cifs|none|glusterfs|ceph|tmpfs|overlay|overlayfs|rozofs|zfs|cvfs|lustre) return;;
1175 esac
1176
1177 if $(is_option "loop"); then
1178 return
1179 fi
1180
1181 case "$DEVICE" in
1182 --uuid=*|--uuid\ *|--label=*|--label\ *)
1183 device_opt=$(echo $DEVICE | sed "s/\([[:blank:]]\|=\).*//")
1184 DEVICE=$(echo $DEVICE | sed -E "s/$device_opt([[:blank:]]*|=)//")
1185 ;;
1186 -U*|-L*) # short versions of --uuid/--label
1187 device_opt=$(echo $DEVICE | cut -c1-2)
1188 DEVICE=$(echo $DEVICE | sed "s/$device_opt[[:blank:]]*//")
1189 ;;
1190 /dev/null) # Special case for BSC
1191 blockdevice=yes
1192 ;;
1193 *)
1194 if [ ! -b "$DEVICE" -a ! -d "$DEVICE" -a "X$OP" != Xstart ] && ! ocf_is_probe ; then
1195 ocf_log warn "Couldn't find device [$DEVICE]. Expected /dev/??? to exist"
1196 fi
1197 if [ ! -d "$DEVICE" ]; then
1198 blockdevice=yes
1199 fi
1200 ;;
1201 esac
1202 }
1203
1204 # Check the arguments passed to this script
1205 if [ $# -ne 1 ]; then
1206 usage
1207 exit $OCF_ERR_ARGS
1208 fi
1209
1210 # Check the OCF_RESKEY_ environment variables...
1211
1212 DEVICE="$OCF_RESKEY_device"
1213 case "$DEVICE" in
1214 [[:space:]]*|*[[:space:]])
1215 [ "$__OCF_ACTION" = "stop" ] && exit $OCF_SUCCESS
1216 ocf_exit_reason "device parameter does not accept leading or trailing whitespace characters"
1217 exit $OCF_ERR_CONFIGURED
1218 ;;
1219 esac
1220 FSTYPE=$OCF_RESKEY_fstype
1221 if [ ! -z "$OCF_RESKEY_options" ]; then
1222 options="-o $OCF_RESKEY_options"
1223 fi
1224 FAST_STOP=${OCF_RESKEY_fast_stop:="yes"}
1225
1226 parse_force_unmount_modifiers()
1227 {
1228 # keep previous "kill one by one" behavior as default for now
1229 move_before_umount=''
1230 do_xargs_kill=''
1231 do_ps_f=''
1232 force_unmount=''
1233
1234 local IFS=','
1235 local m
1236
1237 set -- $OCF_RESKEY_force_unmount
1238
1239 for m ; do
1240 case $m in
1241 "") : ;; # silently ignore "*,,*" in the original value.
1242 move) move_before_umount=true ;;
1243 nomove) move_before_umount=false ;;
1244 ps) do_ps_f=true ;;
1245 nops) do_ps_f=false ;;
1246 xargs) do_xargs_kill=true ;;
1247 noxargs) do_xargs_kill=false ;;
1248 # see ocf_is_true
1249 yes|true|1|YES|TRUE|True|ja|on|ON|\
1250 safe|\
1251 false|no) force_unmount=$m ;;
1252 *) ocf_log warn "force_unmount: unknown modifier $m ignored" ;;
1253 esac
1254 done
1255
1256 # not mentioned, or explicitly empty? "sane defaults"
1257 if [ -z "$move_before_umount$do_xargs_kill$do_ps_f$force_unmount" ]; then
1258 FORCE_UNMOUNT=false
1259 else
1260 FORCE_UNMOUNT=${force_unmount:-yes}
1261 fi
1262 : move : ${move_before_umount:=false}
1263 if $move_before_umount; then
1264 : xargs : ${do_xargs_kill:=true}
1265 : ps : ${do_ps_f:=false}
1266 else
1267 : xargs : ${do_xargs_kill:=false}
1268 : ps : ${do_ps_f:=true}
1269 fi
1270 }
1271
1272 parse_force_unmount_modifiers
1273
1274
1275 OP=$1
1276
1277 # These operations do not require instance parameters
1278 case $OP in
1279 meta-data) meta_data
1280 exit $OCF_SUCCESS
1281 ;;
1282 usage) usage
1283 exit $OCF_SUCCESS
1284 ;;
1285 esac
1286
1287 if [ x = x"$DEVICE" ]; then
1288 ocf_exit_reason "Please set OCF_RESKEY_device to the device to be managed"
1289 exit $OCF_ERR_CONFIGURED
1290 fi
1291
1292 set_blockdevice_var
1293
1294 # Normalize instance parameters:
1295
1296 # It is possible that OCF_RESKEY_directory has one or even multiple trailing "/".
1297 # But the output of `mount` and /proc/mounts do not.
1298 if [ -z "$OCF_RESKEY_directory" ]; then
1299 if [ X$OP = "Xstart" -o $blockdevice = "no" ]; then
1300 ocf_exit_reason "Please specify the directory"
1301 exit $OCF_ERR_CONFIGURED
1302 fi
1303 else
1304 MOUNTPOINT="$(echo "$OCF_RESKEY_directory" | sed 's/\/*$//')"
1305 : ${MOUNTPOINT:=/}
1306 case "$MOUNTPOINT" in
1307 [[:space:]]*|*[[:space:]])
1308 [ "$__OCF_ACTION" = "stop" ] && exit $OCF_SUCCESS
1309 ocf_exit_reason "directory parameter does not accept leading or trailing whitespace characters"
1310 exit $OCF_ERR_CONFIGURED
1311 ;;
1312 esac
1313 if [ -e "$MOUNTPOINT" ] ; then
1314 CANONICALIZED_MOUNTPOINT="$(readlink -f "$MOUNTPOINT")"
1315 if [ $? -ne 0 ]; then
1316 ocf_exit_reason "Could not canonicalize $MOUNTPOINT because readlink failed"
1317 exit $OCF_ERR_GENERIC
1318 fi
1319 else
1320 CANONICALIZED_MOUNTPOINT="$MOUNTPOINT"
1321 fi
1322
1323 if echo "$CANONICALIZED_MOUNTPOINT" | grep -q "^\s*/\s*$"; then
1324 if ocf_is_probe; then
1325 ocf_log debug "/ cannot be managed in a cluster"
1326 exit $OCF_NOT_RUNNING
1327 elif [ "$__OCF_ACTION" = "start" ] || [ "$__OCF_ACTION" = "monitor" ] || [ "$__OCF_ACTION" = "status" ]; then
1328 ocf_exit_reason "/ cannot be managed in a cluster"
1329 exit $OCF_ERR_CONFIGURED
1330 elif [ "$__OCF_ACTION" = "stop" ]; then
1331 exit $OCF_SUCCESS
1332 fi
1333 fi
1334 fi
1335
1336 MOVED_CANONICALIZED_MOUNTPOINT=$(echo "$CANONICALIZED_MOUNTPOINT" | sed -e 's,/\([^/]\+\)$,/.\1,')
1337
1338
1339 # Check to make sure the utilites are found
1340 if [ "X${HOSTOS}" != "XOpenBSD" ];then
1341 check_binary $MODPROBE
1342 check_binary $FUSER
1343 fi
1344 check_binary $FSCK
1345 check_binary $MOUNT
1346 check_binary $UMOUNT
1347
1348 if [ "$OP" != "monitor" ] && [ "$OP" != "validate-all" ]; then
1349 ocf_log info "Running $OP for $DEVICE on $MOUNTPOINT"
1350 fi
1351
1352 case $OP in
1353 status) Filesystem_status
1354 exit $?
1355 ;;
1356 monitor) Filesystem_monitor
1357 exit $?
1358 ;;
1359 validate-all) Filesystem_validate_all
1360 exit $?
1361 ;;
1362 stop) Filesystem_stop
1363 exit $?
1364 ;;
1365 esac
1366
1367 CLUSTERSAFE=0
1368 is_option "ro" &&
1369 CLUSTERSAFE=2
1370
1371 case "$FSTYPE" in
1372 none|overlay|overlayfs|tmpfs)
1373 CLUSTERSAFE=1 # this is kind of safe too
1374 ;;
1375 nfs4|nfs|aznfs|efs|smbfs|cifs|gfs2|glusterfs|ceph|ocfs2|cvfs|lustre)
1376 CLUSTERSAFE=1 # this is kind of safe too
1377 systemd_drop_in "99-Filesystem-remote" "After" "remote-fs.target"
1378 ;;
1379 # add here CLUSTERSAFE=0 for all filesystems which are not
1380 # cluster aware and which, even if when mounted read-only,
1381 # could still modify parts of it such as journal/metadata
1382 ext4|ext4dev|ext3|reiserfs|reiser4|xfs|jfs)
1383 if ocf_is_true "$OCF_RESKEY_force_clones"; then
1384 CLUSTERSAFE=2
1385 systemd_drop_in "99-Filesystem-remote" "After" "remote-fs.target"
1386 else
1387 CLUSTERSAFE=0 # these are not allowed
1388 fi
1389 ;;
1390 esac
1391
1392 if ocf_is_clone; then
1393 case $CLUSTERSAFE in
1394 0)
1395 ocf_exit_reason "DANGER! $FSTYPE on $DEVICE is NOT cluster-aware!"
1396 ocf_log err "DO NOT RUN IT AS A CLONE!"
1397 ocf_log err "Politely refusing to proceed to avoid data corruption."
1398 exit $OCF_ERR_CONFIGURED
1399 ;;
1400 2)
1401 ocf_log warn "$FSTYPE on $DEVICE is NOT cluster-aware!"
1402 if ocf_is_true "$OCF_RESKEY_force_clones"; then
1403 ocf_log warn "But we'll let it run because we trust _YOU_ verified it's safe to do so."
1404 else
1405 ocf_log warn "But we'll let it run because it is mounted read-only."
1406 ocf_log warn "Please make sure that it's meta data is read-only too!"
1407 fi
1408 ;;
1409 esac
1410 fi
1411
1412 case $OP in
1413 start) Filesystem_start
1414 ;;
1415 *) usage
1416 exit $OCF_ERR_UNIMPLEMENTED
1417 ;;
1418 esac
1419 exit $?