#!/usr/local/bin/scripts/sh # #.Y / 70 83 / / / / 105 / / / / / / ;A4_QUER.Y #.YT 3 2 0 0 3 3 1 / / / #.H!a!0:linux//io/disk/mediaAccess/mediaHandlers.d/A8A2BB3D_78F0_11E6_B6F3_0000C00A45A9!0.!c # #/******************************************************************************* # io disk mediaAccess mediaHandlers.d/A8A2BB3D_78F0_11E6_B6F3_0000C00A45A9 # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # # purpose : media handler for an nbd-media # # begin : Wed Jun 13 12:30:45 CEST 2018 # # changes : # # copyright : (C) 2018 by Thomas Bruecker # # email : public@thomas-r-bruecker.ch # # version : -0.0.0 # #*******************************************************************************/ #/*************************************************************************** # * * # * This program is free software; you can redistribute it and/or modify * # * it under the terms of the GNU General Public License as published by * # * the Free Software Foundation; either version 2 of the License, or * # * (at your option) any later version. * # * * # * This program is distributed in the hope that 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. * # * * # * You should have received a copy of the GNU General Public License * # * along with this program; if not, write to the Free Software * # * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * # * MA 02110-1301 USA. * # * * # ***************************************************************************/ # MyHash("A8A2BB3D_78F0_11E6_B6F3_0000C00A45A9") = 0x089D_3D # # * for every function: # * if returned result is not commented, the function returns 0 on no-error. disk_mediaAccess_0x089D_3D_col__() { # $1: size, # $2: uuid, # $3: prefix; most often: indent, # * writes the size-parameter to "stdout". local MediaHandlerUuid PREFIX SIZE UUID PREFIX="$3" PREFIX1=" $PREFIX0" SIZE="$1" UUID="$2" MediaHandlerUuid="$( echo "${FUNCNAME[1]}" \ | string__SearchAndReplace '^disk_mediaAccess_*' '' \ | string_SearchAndReplace '_' '-' \ )" disk_mediaAccess_0x089D_3D_col___ \ "$MediaHandlerUuid" "$SIZE" "$UUID" "$PREFIX" } disk_mediaAccess_0x089D_3D_col___() { # $1: media-handler-uuid, # $2: size, # $3: uuid, # $4: prefix; most often: indent, # ^* writes the size-parameter to "stdout". local MediaHandlerUuid PREFIX SIZE UUID MediaHandlerUuid="$1" PREFIX0="$4" PREFIX1=" $PREFIX0" SIZE="$2" UUID="$3" START='8' # ^ # ^ sort parameters. disk_mediaAccess_col__METHOD "$MediaHandlerUuid" "$PREFIX0" disk_mediaAccess_col__CommonParameters "$MediaHandlerUuid" "$PREFIX1" disk_mediaAccess_col__SIZE "$SIZE" "$PREFIX1" disk_mediaAccess_col__START "$START" "$PREFIX1" disk_mediaAccess_col__UUID "$UUID" "$PREFIX1" disk_mediaAccess_col__MethodEnd "$PREFIX0" } disk_mediaAccess_A8A2BB3D_78F0_11E6_B6F3_0000C00A45A9() { # handles an nbd-media; # $1: command, in { # "2ChildDev", "2ChildMedia", "CHECK", "DESTROY", "REALIZE", # "RealizeForced", "SIZE", "VERIFY", "WAIT", "_:", "__:" # }, # * $1 in { # "2ChildDev", "2ChildMedia", "CHECK", "DESTROY", "REALIZE", # "RealizeForced", "SIZE", "VERIFY", "WAIT" # }: see "../CommonCommandsSpecification.TXT", # * "PoolSize" # $2: , # $3: , # $4: ; # * writes the pool-size to "stdout"; # * "_:": ^verify command, # ^$2: path to the media (device, file, rootFolder of a filsystem), # ^$3: index into container, # * "__:": ^verify command, # $2: media-handler-uuid, # $3: size, # $4: uuid, # $5: prefix, most often: indent; # ^* writes the size-parameter to "stdout". local COMMAND FORCED INDEX MediaInfo ParentMedia ParentMediaPath COMMAND="$1" INDEX="$2" MediaInfo="$3" ParentMedia="$4" ParentMediaPath="$5" # echo "$COMMAND" >>/dev/stderr # echo "$INDEX" >>/dev/stderr # echo "$MediaInfo" >>/dev/stderr # echo "$ParentMedia" >>/dev/stderr # echo "$ParentMediaPath" >>/dev/stderr # ^pen: wait for compos quick, for verifying and 'wait': disk_mediaAccess__VerifyNoWait "$COMMAND" && return 0 # if ok, return 0; no # waiting for component # medias at all. disk_mediaAccess__RealizeForced2Forced "$COMMAND" # echo FORCED: $FORCED >>/dev/stderr case "$COMMAND" in 2ChildDev) disk_mediaAccess___2ChildDev \ "$INDEX" "$MediaInfo" "$ParentMedia" "$ParentMediaPath" ;; 2ChildMedia) disk_mediaAccess___2ChildMedia0 \ "$MediaInfo" ;; CHECK|REPAIR) return 0 ;; DESTROY) disk_mediaAccess__0x089D_3D_DESTROY \ "$MediaInfo" ;; #^ PoolSize) disk_mediaAccess__0x089D_3D_PoolSize \ "$MediaInfo" ;; REALIZE|RealizeForced) disk_mediaAccess__0x089D_3D_REALIZE \ "$FORCED" \ "$INDEX" "$MediaInfo" "$ParentMediaPath" ;; SIZE) disk_mediaAccess__Size1 ;; _:) shift 1 disk_mediaAccess_0x089D_3D_col__ "$@" ;; # ^ __:) shift 1 disk_mediaAccess_0x089D_3D_col___ "$@" ;; # ^ *) disk_mediaAccess___NoContainer \ "$COMMAND" "$INDEX" "$ParentMedia" \ || return # return on error. disk_mediaAccess__InvalidCommandError \ "$COMMAND" "$INDEX" \ 'A8A2BB3D_78F0_11E6_B6F3_0000C00A45A9' \ "$ParentMedia" ;; esac # return result of previous } # command. disk_mediaAccess_col__LINEAR() { # ': _LINEAR' # $1: size, # $2: uuid, # $3: prefix; most often: indent, # * writes the size-parameter to "stdout". disk_mediaAccess__A8A2BB3D_78F0_11E6_B6F3_0000C00A45A9 "_:" "$@" } disk_mediaAccess_col___LINEAR() { # ': __LINEAR' # $1: media-handler-uuid, # $2: size, # $3: uuid, # $4: prefix; most often: indent, # ^* writes the size-parameter to "stdout". disk_mediaAccess__A8A2BB3D_78F0_11E6_B6F3_0000C00A45A9 "__:" "$@" } disk_mediaAccess__0x089D_3D_DESTROY() { # 'thin_check'; # $1: . # global: NbdClient0x0EAA local INDEX MediaInfo MediaInfo="$1" # echo "$MediaInfo" >>/dev/stderr ParametersFile="$(disk_mediaAccess__Parameters2File "$MediaInfo")" \ || return # return on error. . "$ParametersFile" || return # return on error. # echo "$NbdDevice" >>/dev/stderr # echo "$UUID" >>/dev/stderr ChildMediaName="$UUID" "$NbdClient0x0EAA" -d "$NbdDevice" disk_mediaAccess___UnLinkAndUnMap "$ChildMediaName" } disk_mediaAccess__0x089D_3D_PoolSize() { # writes the pool-size to "stdout"; # $1: . local MediaInfo ParametersFile MediaInfo="$1" # echo "$MediaInfo" >>/dev/stderr ParametersFile="$(disk_mediaAccess__Parameters2File "$MediaInfo")" \ || return # return on error. disk_mediaAccess___0x089D_3D_PoolSize "$ParametersFile" } disk_mediaAccess__0x089D_3D_REALIZE() { # realize media or realize media forced; # $1: , # $2: , # $3: , # $4: . # global: ModProbe0x0EAA NbdClient0x0EAA Sleep0x0EAA local ChildMediaName FORCED INDEX MediaInfo ParametersFile local ParentMediaPath # parameters: local BlockSize ClientOptions COPYRIGHT CopyrightDetails NbdDevid NOTES local PORT OnlyOnHosts RealizationOptions SIZE TargetHost TargetLogFile local TargetHostOptions TargetMedia TargetNbdServer URL UUID FORCED="$1" INDEX="$2" MediaInfo="$3" ParentMediaPath="$4" # echo "$FORCED" >>/dev/stderr # echo "$INDEX" >>/dev/stderr # echo "$MediaInfo" >>/dev/stderr # echo "$ParentMediaPath" >>/dev/stderr # clear global optional not ignored parameters. OnlyOnHosts='' RealizationOptions='' ParametersFile="$(disk_mediaAccess__Parameters2File "$MediaInfo")" \ || return # return on error. . "$ParametersFile" || return # return on error. # echo "$BlockSize" >>/dev/stderr # echo "$ClientOptions" >>/dev/stderr # echo "$COPYRIGHT" >>/dev/stderr # echo "$CopyrightDetails" >>/dev/stderr # echo "$NbdDevice" >>/dev/stderr # echo "$NOTES" >>/dev/stderr # echo "$OnlyOnHosts" >>/dev/stderr # echo "$PORT" >>/dev/stderr # echo "$RealizationOptions" >>/dev/stderr # echo "$SIZE" >>/dev/stderr # echo "$TargetHost" >>/dev/stderr # echo "$TargetHostOptions" >>/dev/stderr # echo "$TargetHostSshPort" >>/dev/stderr # echo "$TargetLogFile" >>/dev/stderr # echo "$TargetMedia" >>/dev/stderr # echo "$TargetNbdServer" >>/dev/stderr # echo "$URL" >>/dev/stderr # echo "$UUID" >>/dev/stderr disk_mediaAccess_isHandled \ "$FORCED" "$OnlyOnHosts" "$RealizationOptions" || return 0 ChildMediaName="$UUID" # handle the realization option "ro" (read-only). disk_mediaAccess__isRealizationOption "$RealizationOptions" 'ro' \ && TargetHostOptions+=' -r' # echo "$TargetHostOptions" >>/dev/stderr ssh -p "$TargetHostSshPort" "$TargetHost" " \ TargetMediaPath=\$( \ QuietMediaAccess_ __Media2AbsolutePath $TargetMedia \ ) || exit; \ \ QuietMediaAccess_ __0x089D_3D_NbdServer \ \"$PORT\" \"$SIZE\" \"$TargetHostOptions\" \"$TargetLogFile\" \ \$TargetMediaPath \"$TargetNbdServer\" \ " "$ModProbe0x0EAA" nbd echo 'waiting for nbd-server' >>/dev/stderr "$Sleep0x0EAA" 2 "$NbdClient0x0EAA" "$TargetHost" "$PORT" "$NbdDevice" -b "$BlockSize" \ $ClientOptions disk_mediaAccess___LinkAndMap \ "$ChildMediaName" "$INDEX" "$ParentMediaPath" "$NbdDevice" } disk_mediaAccess___0x089D_3D_NbdServer() { # starts the nbd-server; # $1: , # $2: , # $3: , # $4: , # $5: , # $6: . local PORT SIZE TargetHostOptions TargetLogFile TargetMediaPath local TargetNbdServer PORT="$1" SIZE="$2" TargetHostOptions="$3" TargetLogFile="$4" TargetMediaPath="$5" TargetNbdServer="$6" # echo "$PORT" >>/dev/stderr # echo "$SIZE" >>/dev/stderr # echo "$TargetHostOptions" >>/dev/stderr # echo "$TargetLogFile" >>/dev/stderr # echo "$TargetMediaPath" >>/dev/stderr # echo "$TargetNbdServer" >>/dev/stderr if [ -z "$SIZE" ]; then "$TargetNbdServer" "$PORT" "$TargetMediaPath" \ $TargetHostOptions >"$TargetLogFile" 2>&1 & else "$TargetNbdServer" "$PORT" "$TargetMediaPath" "$SIZE" \ $TargetHostOptions >"$TargetLogFile" 2>&1 & fi } disk_mediaAccess___0x089D_3D_PoolSize() { # write the pool-size to "stdout"; # $1: path to parameters-file. # global: DeviceMapperBasePath0x0EAA local ParametersFile SIZE # parameters: local DataMedia ParametersFile="$1" # echo "$ParametersFile" >>/dev/stderr . "$ParametersFile" || return # return on error. # echo "$DataMedia" >>/dev/stderr SIZE="$(disk_SIZE "${DeviceMapperBasePath0x0EAA}/$DataMedia" 'S')" echo "$SIZE" }