"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/extras/hook-scripts/add-brick/post/disabled-quota-root-xattr-heal.sh" (16 Sep 2020, 3165 Bytes) of package /linux/misc/glusterfs-8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/sh
    2 
    3 ##---------------------------------------------------------------------------
    4 ## This script updates the 'limit-set' xattr on the newly added node. Please
    5 ## refer hook-scripts/add-brick/pre/S28Quota-root-xattr-heal.sh for the complete
    6 ## description.
    7 ## Do the following only if limit configured on root.
    8 ## 1. Do an auxiliary mount.
    9 ## 2. Get 'limit-set' xattr on root
   10 ## 3. Set xattrs with the same value on the root.
   11 ## 4. Disable itself
   12 ##---------------------------------------------------------------------------
   13 
   14 QUOTA_LIMIT_XATTR="trusted.glusterfs.quota.limit-set"
   15 QUOTA_OBJECT_LIMIT_XATTR="trusted.glusterfs.quota.limit-objects"
   16 MOUNT_DIR=$(mktemp -d -t "${0##*/}.XXXXXX");
   17 OPTSPEC="volname:,version:,gd-workdir:,volume-op:"
   18 PROGNAME="Quota-xattr-heal-add-brick"
   19 VOL_NAME=
   20 VERSION=
   21 VOLUME_OP=
   22 GLUSTERD_WORKDIR=
   23 ENABLED_NAME_PREFIX="S28"
   24 ENABLED_NAME="Quota-root-xattr-heal.sh"
   25 
   26 THIS_SCRIPT=$(echo "${0}" | awk -F'/' '{print $NF}')
   27 
   28 cleanup_mountpoint ()
   29 {
   30 
   31   if umount -f "${MOUNT_DIR}"; then
   32     return $?
   33   fi
   34 
   35   if rmdir "${MOUNT_DIR}"; then
   36     return $?
   37   fi
   38 }
   39 
   40 disable_and_exit ()
   41 {
   42   if [ -e "${ENABLED_STATE}" ]
   43   then
   44     unlink "${ENABLED_STATE}";
   45     exit $?
   46   fi
   47 
   48   exit 0
   49 }
   50 
   51 get_and_set_xattr ()
   52 {
   53   XATTR=$1
   54 
   55   VALUE=$(getfattr -n "${XATTR}" -e hex --absolute-names "${MOUNT_DIR}" 2>&1)
   56   RET=$?
   57   if [ 0 -eq ${RET} ]; then
   58     VALUE=$(echo "${VALUE}" | grep "${XATTR}" | awk -F'=' '{print $NF}')
   59     setfattr -n "${XATTR}" -v "${VALUE}" "${MOUNT_DIR}";
   60     RET=$?
   61   else
   62     if echo "${VALUE}" | grep -iq "No such attribute" ; then
   63       RET=0
   64     fi
   65   fi
   66 
   67   return ${RET};
   68 }
   69 
   70 ##------------------------------------------
   71 ## Parse the arguments
   72 ##------------------------------------------
   73 ARGS=$(getopt -o '' -l ${OPTSPEC} -n ${PROGNAME} -- "$@")
   74 eval set -- "$ARGS"
   75 
   76 while true;
   77 do
   78   case $1 in
   79     --volname)
   80       shift
   81       VOL_NAME=$1
   82     ;;
   83     --version)
   84       shift
   85       VERSION=$1
   86     ;;
   87     --gd-workdir)
   88       shift
   89       GLUSTERD_WORKDIR=$1
   90     ;;
   91     --volume-op)
   92       shift
   93       VOLUME_OP=$1
   94     ;;
   95     *)
   96       shift
   97       break
   98     ;;
   99   esac
  100   shift
  101 done
  102 ##----------------------------------------
  103 
  104 # Avoid long lines
  105 ENABLED_STATE_1="${GLUSTERD_WORKDIR}/hooks/${VERSION}/${VOLUME_OP}/"
  106 ENABLED_STATE_2="post/${ENABLED_NAME_PREFIX}${VOL_NAME}-${ENABLED_NAME}"
  107 ENABLED_STATE="${ENABLED_STATE_1}${ENABLED_STATE_2}"
  108 
  109 if [ "${THIS_SCRIPT}" != *"${VOL_NAME}"* ]; then
  110   exit 0
  111 fi
  112 
  113 ## Is quota enabled?
  114 FLAG=$(grep "^features.quota=" "${GLUSTERD_WORKDIR}/vols/${VOL_NAME}/info" \
  115 | awk -F'=' '{print $NF}');
  116 if [ "${FLAG}" != "on" ]
  117 then
  118   disable_and_exit
  119 fi
  120 
  121 ## -----------------------------------
  122 ## Mount the volume in temp directory.
  123 ## -----------------------------------
  124 # Avoid long lines
  125 CMD_1="glusterfs -s localhost"
  126 CMD_2="--volfile-id=${VOL_NAME} client-pid=-42 ${MOUNT_DIR}"
  127 CMD="${CMD_1}${CMD_2}"
  128 
  129 if ${CMD}
  130 then
  131   exit $?;
  132 fi
  133 ## -----------------------------------
  134 
  135 RET1=$(get_and_set_xattr "${QUOTA_LIMIT_XATTR}")
  136 RET2=$(get_and_set_xattr "${QUOTA_OBJECT_LIMIT_XATTR}")
  137 
  138 ## Clean up and exit
  139 cleanup_mountpoint;
  140 
  141 if [ "${RET1}" -ne 0 ] || [ "${RET2}" -ne 0 ]; then
  142   exit 1
  143 fi
  144 
  145 disable_and_exit;