Dynamic Reconfiguration ユーザーズガイド 2.6
目次 前ページ次ページ

第4章 連携スクリプト使用例

4.2 bindp

#!/bin/sh
PATH=/usr/bin:/usr/sbin:/opt/FJSVdr/bin; export PATH
# ----- script starts here -----
#
# get process id of "Bound"
PID=`ps -e -o fname -o pid | awk '{if ($1=="Bound") print $2}'`
if [ -z "$PID" ]
then
    exit 0
fi
case "$1" in
'checkadd')
    # checking procedure whether connect is possible or not
    exit 0
    ;;
'preadd')
    # procedure before device is added
    exit 0
    ;;
'postadd')
    # procedure after device is added
    
    # get incoming CPU IDs
    DETACHCPUS=`dr_info cpu`
    if [ $? -ne 0 ]
    then
        exit 1
    fi
    cpu1=`echo $DETACHCPUS | cut -f1 -d':'`
    cpu2=`echo $DETACHCPUS | cut -f2 -d':'`
    cpu3=`echo $DETACHCPUS | cut -f3 -d':'`
    cpu4=`echo $DETACHCPUS | cut -f4 -d':'`
    # get biggest CPU ID from incoming CPUs.
    for ID in $cpu1 $cpu2 $cpu3 $cpu4
    do
        psrinfo $ID | grep on-line > /dev/null 2>&1
        if [ $? -eq 0 ]
        then
            CPU=$ID
        fi
    done
    if [ -z "$CPU" ]
    then
            exit 0
    fi
    # re-bind  to incoming CPU
    pbind -u $PID > /dev/null 2>&1
    pbind -b $CPU $PID > /dev/null 2>&1
    dr_message bindp 0002 $PID $CPU
    exit 0
    ;;
'canceladd')
    # procedure when attach is cancelled
    exit 0
    ;;
'checkremove')
    # checking procedure whether disconnect is possible or not
    exit 0
    ;;
'preremove')
    # procedure before device is removed
    
    # get CPU ID that "Bound" is bound.
    CPU=`pbind | grep $PID | awk '{print $4}'`
    if [ -z "$CPU" ]
    then
        # "Bound" process is not bound cpu.
        exit 0
    fi
    # get outgoing CPU IDs
    DETACHCPUS=`dr_info cpu`
    if [ $? -ne 0 ]
    then
        exit 1
    fi
    cpu1=`echo $DETACHCPUS | cut -f1 -d':'`
    cpu2=`echo $DETACHCPUS | cut -f2 -d':'`
    cpu3=`echo $DETACHCPUS | cut -f3 -d':'`
    cpu4=`echo $DETACHCPUS | cut -f4 -d':'`
    # check if $CPU is going to detach
    if [ "x$CPU" = "x$cpu1" -o "x$CPU" = "x$cpu2" -o "x$CPU" = "x$cpu3" -o "x$CPU" = "x$cpu4" ]
    then
        # $PID is bound to outgoing CPU.
        dr_query bindp 0001 $PID
        if [ $? -ne 0 ]
        then
            # user rejected DR.
            dr_message bindp 0003 $PID $CPU
            exit 11
        fi
        # unbind 
        pbind -u $PID > /dev/null 2>&1
        dr_message bindp 0001 $PID $CPU
        # save $CPU for cancel procedure
        dr_put_db bindp cpu=$CPU
    fi
    exit 0
    ;;
'postremove')
    # procedure after device is removed
    
    # get biggest CPU ID.
        NUMCPU=`psrinfo | grep on-line | wc -l`
        MAXID=`psrinfo | grep on-line | sed -n "${NUMCPU}p" | awk '{print $1}'`
    # bind
    pbind -b $MAXID $PID > /dev/null 2>&1
    dr_message bindp 0002 $PID $MAXID
    exit 0
    ;;
'cancelremove')
    # procedure when detach is cancelled
    CPU=`dr_get_db bindp cpu`
    if [ -z "$CPU" ]
    then
        exit 0
    fi
    if [ $PID ]
    then
        pbind -b $CPU $PID > /dev/null 2>&1
        dr_message bindp 0002 $PID $CPU
    fi
    exit 0
    ;;
*)
    exit 1
    ;;
esac

目次 前ページ次ページ

All Rights Reserved, Copyright(C) 富士通株式会社 2005