Hallo, dies ist ein Test.
PWD: /www/data-lst1/unixsoft/unixsoft/kaempfer/.public_html
Running in File Mode
Relative path: ./../../../../../../usr/sbin/swapadd
Real path: /usr/sbin/swapadd
Zurück
#!/bin/ksh # # Copyright (c) 1991, 2023, Oracle and/or its affiliates. # # Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T # All rights reserved. # . /lib/svc/share/smf_include.sh # Set noinuse checking during boot. We want to disable device in use checking # so that normal swap use, such as specified in /etc/vfstab, will not cause # swap devices to fail to be configured during boot. NOINUSE_CHECK=1; export NOINUSE_CHECK typeset -r ZVOL_LABEL="swap" PATH=/usr/sbin:/usr/bin; export PATH USAGE="Usage: swapadd [-12] [file_system_table]" VFSTAB=/etc/vfstab # Default file system table PASS=2 # Default to checking for existing swap STATUS=0 UPGRADE=0 warn() { echo "WARNING: $*" >& 2 } die() { echo "$*" >& 2 exit 1 } swap_added() { swap -l 2>/dev/null | grep '^\<'$1'\>' >/dev/null 2>&1 } add_swap() { typeset PASS=$1 typeset special=$2 typeset ospecial=$special typeset zvol=${special#/dev/zvol/dsk/} typeset tflag="" if [ "$special" != "$zvol" ]; then keystatus=$(zfs get -H -o value keystatus $zvol 2>/dev/null) if [ "$keystatus" == "unavailable" ]; then zfs key -l $zvol fi tflag=" -t" else # # zfs volumes used for swap are always encrypted without # any special setup, just deal with raw devices. # special=$(lofiadm -c aes-256-cbc -e -a $special 2> /dev/null) if (( $? == 1 )); then special=$(lofiadm $ospecial) if (( $? != 0)); then # During PASS 1 $ospecial could be an NFS file # that is not yet mounted so ignore the error. if (( $PASS == 2 )); then STATUS=1 fi continue fi fi fi if (( $PASS == 1 )); then # # Check to see if there is a crash dump on this volume. # If there is then this swap volume will be added by # pass2 # # For lofi devices this has to check the underlying # device for a dump as the lofi device has an ephemeral # key. # savecore -c -f $ospecial > /dev/null 2>&1 if (( $? == 2 )); then echo "Skipping $special: contains a crash dump" >&2 continue fi fi # # Skip all the swap already added. If something added earlier uses the # same name as something to be added later, the following test won't # work. This should only happen if parts of a particular swap file are # added or deleted by hand between invocations. # if swap_added ${special}; then return fi # # If adding a swap device takes a long time to complete # for some reason, SMF will timeout, kill and restart # this service. The swap command may continue to run. # Check for this and wait for the swap command to # complete, instead of starting another one. # pid=$(pgrep -f "swap -$PASS$tflag -a $special") if (( $? == 1)); then if ! swap -$PASS$tflag -a $special >/dev/null; then STATUS=1 fi else pwait $pid if ! swap_added ${special}; then STATUS=1 fi fi } vfstab_hasswap() { while read special t1 t2 fstype t3 t4 options; do # # Ignore comments, empty lines, and no-action lines # case "$special" in '#'* | '' | '-') continue ;; esac # # Ignore non-swap fstypes # [ "$fstype" == swap ] && return 0 done return 1 } edit_vfstab() { typeset swapcomment="# ZFS swap volumes are permanently added via swap -a. See swap(8)\n# " typeset special t1 t2 fstype t3 t4 flags typeset has_swap_property="${1}" while read line; do # # Ignore comments, empty lines, and no-action lines # case "$line" in '#'* | '' | '-') echo "$line" ; continue ;; esac echo "$line" | read special t1 t2 fstype t3 t4 flags if [ "$fstype" == swap ]; then typeset zvolname=${special#/dev/zvol/dsk/} if [[ $zvolname != $special ]]; then # # If any of the volumes have a swap property set # to anything other then "none" then only remove # swap entries marked "install" # if [[ "${has_swap_property}" == "true" ]]; then if [[ $(zfs list -Ho ${ZVOL_LABEL} $zvolname ) == "on" ]]; then continue; fi elif zfs set ${ZVOL_LABEL}=on $zvolname ; then if [[ "$flags" == "install" ]]; then continue fi echo "$swapcomment\c" && swapcomment="# " else return 1 fi fi fi echo "$line" done return 0 } all_kvol_swap_none() { zfs list -t volume -Ho name,$ZVOL_LABEL | while read vol isswap; do [[ $isswap != "none" ]] && return 0 done return 1 } while getopts 12U opt; do case "$opt" in 1|2) PASS=$opt ;; U) UPGRADE=1 ;; \?) die "$USAGE" ;; esac done shift $(( $OPTIND - 1 )) (( $# > 1 )) && die "$USAGE" (( $# == 1 )) && VFSTAB="$1" if (( UPGRADE == 1)); then has_swap_property=false if [ "x$VFSTAB" == x- ]; then die "can not upgrade standard in" fi if [[ $(getconf _SC_SUNW_FEATURE_AK) == 1 ]]; then exit 0 fi TMPFILE=$VFSTAB.new if ! vfstab_hasswap < $VFSTAB; then exit 0 fi if all_kvol_swap_none; then has_swap_property=true fi if edit_vfstab $has_swap_property < $VFSTAB > $TMPFILE ; then mv -S $TMPFILE $VFSTAB && exit 0 fi rm -f $TMPFILE exit $SMF_EXIT_DEGRADED fi # # First handle any swap volumes that have the property set to on # zfs list -t volume -Ho name,$ZVOL_LABEL | while read vol isswap; do if [[ $isswap == "on" ]]; then add_swap $PASS /dev/zvol/dsk/$vol fi done # # If $VFSTAB is not "-" (stdin), re-open stdin as the specified file # if [ "x$VFSTAB" != x- ]; then [ -s "$VFSTAB" ] || die "swapadd: file system table ($VFSTAB) not found" exec <$VFSTAB fi # # Read the file system table to find entries of file system type "swap". # Add the swap device or file specified in the first column. # while read special t1 t2 fstype t3 t4 options; do # # Ignore comments, empty lines, and no-action lines # case "$special" in '#'* | '' | '-') continue ;; esac # # Ignore non-swap fstypes # [ "$fstype" != swap ] && continue zvolname=${special#/dev/zvol/dsk/} if [[ $zvolname != $special ]]; then typeset prop=$(zfs get -Ho value $ZVOL_LABEL $zvolname) if [[ $prop != "none" ]];then warn "ZFS swap volume \"$zvolname\" in $VFSTAB has $ZVOL_LABEL property set: $prop" warn "please remove it from $VFSTAB. See swap(8)." # # Only put the service into degraded mode if swap has # been disabled on this volume # if [[ $prop == "off" ]]; then STATUS=$SMF_EXIT_DEGRADED fi continue fi fi add_swap $PASS $special done exit $STATUS