#!/bin/sh # # License: GNU General Public License (GPL)v2 # Description: Manages Lustre server on a shared storage # Written by: Gabriele Paciucci, Nathaniel Clark # Release Date: 28 February 2017 # Release Version: 1.0.1 # Copyright (c) 2017, Intel Corporation # # This program is free software; you can redistribute it and/or modify # it under the terms and conditions of the GNU General Public License, # version 2, as published by the Free Software Foundation. # # This program is distributed in the hope 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. # # # usage: ./Lustre {start|stop|status|monitor|validate-all|meta-data} # # OCF parameters are as follows: # OCF_RESKEY_target - the device or ZFS volume to mount/umount # OCF_RESKEY_mountpoint - the mountpoint to use # OCF_RESKEY_mountoptions - any mount options to use ####################################################################### # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs # Variables used by multiple methods ####################################################################### # USAGE usage() { echo "usage: $0 {start|stop|status|monitor|validate-all|meta-data}" } # META-DATA meta_data() { cat < 1.0.1 This script manages Lustre Targets (MGT, MDT, OST). The script is able to mount/umount Lustre Targets. The standard monitor operation of depth 0 (also known as probe) checks if the filesystem is mounted and lustre is healthy Lustre management The name of the target created during the Lustre format (e.g. /dev/sda, ZPOOL/MGS, /dev/mapper/mpatha) Lustre target name The mount point where the Lustre target will be mounted. Mount point for Lustre Any additional mount options for the Lustre target. (eg: "-o skpath=/path/to/keys") Mount options for Lustre target END exit $OCF_SUCCESS } ##################################################################### # STATUS # lustre_is_mounted () { # Verify if this is consistent, check pointpoint and filesystem # against source (i.e. device) local dev=$(findmnt -t lustre -ln -o SOURCE -T $(realpath "$OCF_RESKEY_mountpoint")) [ -n "$dev" ] && [ "$dev" == "$OCF_RESKEY_target" -o "$dev" == $(realpath "$OCF_RESKEY_target") ] } lustre_monitor () { if ! lustre_is_mounted; then ocf_log err "$OCF_RESKEY_target is not mounted" return $OCF_NOT_RUNNING fi # TODO: Add better status monitoring return $OCF_SUCCESS } ##################################################################### # ACTIONS # lustre_mount () { if ! lustre_is_mounted; then ocf_log info "Starting to mount $OCF_RESKEY_target" output=$(mount -t lustre $OCF_RESKEY_mountoptions $OCF_RESKEY_target $OCF_RESKEY_mountpoint 2>&1) rc=$? if [ $rc -eq 0 ]; then ocf_log info "$OCF_RESKEY_target mounted successfully" [ -n "$output" ] && ocf_log info "$output" return $OCF_SUCCESS fi ocf_log err "$OCF_RESKEY_target mount failed, rc=$rc" ocf_log err "$output" return $OCF_ERR_GENERIC fi return $OCF_SUCCESS } lustre_umount () { if lustre_is_mounted; then ocf_log info "Starting to unmount $OCF_RESKEY_target" output=$(umount $OCF_RESKEY_mountpoint 2>&1) rc=$? if [ $rc -eq 0 ]; then ocf_log info "$OCF_RESKEY_target unmounted successfully" [ -n "$output" ] && ocf_log info "$output" return $OCF_SUCCESS fi ocf_log err "$OCF_RESKEY_target unmount failed, rc=$rc" ocf_log err "$output" return $OCF_ERR_GENERIC fi return $OCF_SUCCESS } all_start () { lustre_mount mnt_success=$? if [ "$mnt_success" != "$OCF_SUCCESS" ]; then ocf_log err "$OCF_RESKEY_target can not be mounted with this error: $mnt_success" return $OCF_ERR_GENERIC fi return $OCF_SUCCESS } all_stop () { lustre_umount mnt_success=$? if [ "$mnt_success" != "$OCF_SUCCESS" ]; then ocf_log err "$OCF_RESKEY_target can not be unmounted with this error: $mnt_success" return $OCF_ERR_GENERIC fi return $OCF_SUCCESS } validate () { if [ ! -d "$(realpath $OCF_RESKEY_mountpoint)" ]; then ocf_log err "$OCF_RESKEY_mountpoint can not be found" return $OCF_ERR_INSTALLED fi if ! modinfo -n lustre >/dev/null 2>&1; then ocf_log err "lustre module not available" return $OCF_ERR_INSTALLED fi return $OCF_SUCCESS } case $1 in meta-data) meta_data;; start) all_start;; stop) all_stop;; status|monitor) lustre_monitor;; validate-all) validate;; usage) usage exit $OCF_SUCCESS ;; *) exit $OCF_ERR_UNIMPLEMENTED;; esac