X7ROOT File Manager
Current Path:
/var/VMOptimizationToolsLinux
var
/
VMOptimizationToolsLinux
/
๐
..
๐
LinuxUpdate.XML
(645 B)
๐
SangforVMSTool
(3.11 KB)
๐
SangforVMSTool.service
(194 B)
๐
action_common.sh
(13.34 KB)
๐
busybox_cmd_ln.sh
(2.24 KB)
๐
collect_test_data.sh
(1.16 KB)
๐
common_config.sh
(278 B)
๐
data_test_tool.sh
(12.59 KB)
๐
debian_vmconfig.sh
(10.74 KB)
๐
guest_system_config.sh
(1.82 KB)
๐
log.sh
(1.36 KB)
๐
mod_test.sh
(3.69 KB)
๐
mod_test1.sh
(914 B)
๐
net_common.sh
(915 B)
๐
redhat_vmconfig.sh
(11.14 KB)
๐
sangfor_guest_datareport
(21.66 KB)
๐
sangfor_heartalive.sh
(2.37 KB)
๐
sangfor_module_update
(28.11 KB)
๐
sangfor_set_network.sh
(504 B)
๐
sangfor_sfping
(3.85 KB)
๐
sangfor_sshkey_gen
(1.29 KB)
๐
sangfor_update_ipc_callback
(5.29 KB)
๐
sangfor_vm_proxyd
(3.45 KB)
๐
sangfor_vm_proxyd_r
(4.4 KB)
๐
sangfor_vm_proxyd_w
(1.32 KB)
๐
sangfor_vmconfig
(2.4 KB)
๐
sangfor_vmconfig_common
(27.99 KB)
๐
sangfor_vmconfig_ipc_callback
(4.75 KB)
๐
sangfor_watchdog
(3.95 KB)
๐
sfping.c
(15.68 KB)
๐
sfping.pl
(6.15 KB)
๐
startall
(1.78 KB)
๐
stopall
(1.11 KB)
๐
suse_vmconfig.sh
(6.19 KB)
๐
tools_x64
๐
tools_x86
๐
uni_test.sh
(2.59 KB)
๐
update_common_func
(4.35 KB)
๐
update_common_header
(4.86 KB)
๐
update_config
(2.89 KB)
๐
update_install
(28.84 KB)
๐
virtio_nic_attr_set.sh
(2.42 KB)
๐
virtio_nic_compat.sh
(5.28 KB)
๐
vm_ip_recover.sh
(16.66 KB)
๐
vm_ipc.sh
(9.06 KB)
๐
vmconfig_common_func
(10.76 KB)
๐
vmconfig_common_header
(3.37 KB)
๐
vmconfig_config
(805 B)
๐
vmtools-install.sh
(31.16 KB)
๐
watch_test.sh
(313 B)
๐
watchdog.sh
(1.39 KB)
๐
x64
๐
x86
Editing: sangfor_guest_datareport
#!/bin/bash shell_dir=`dirname "${BASH_SOURCE[0]}"` proc_name=`basename "${BASH_SOURCE[0]}"` #report_log_file=`basename "${BASH_SOURCE[0]}"` . "${shell_dir}/vm_ipc.sh" . "${shell_dir}/watchdog.sh" . "${shell_dir}/net_common.sh" . "${shell_dir}/action_common.sh" declare -r MSGID_SEND_VERSION=10004 #send packet of os version declare -r MSGID_RECV_REPLY_VERSION=10005 #receive the feedback packet(after send packet of send version) declare -r MSGID_SEND_GUEST_DATA=10006 #send packet of guest machine declare -r MSGID_RECV_CONTROL_CMD=10100 #recv control cmd declare -r MSGID_SEND_CONTROL_REPLY=10101 #send control reply declare -r MSGID_SEND_NETINFO=20202 #send netinfo to host declare -r MSGID_RECV_GET_NETINFO=20201 #recv netinfo query msg declare -r MOD_ID=5 declare -r SDN_MOD_ID=7 declare -r CTRL_MOD_ID=6 declare -r INST_ID=0 declare -r SEND_VERSION=0 declare -r SEND_INFO=1 declare RUN_MODE=0 #default is send packet of os version #excute control command result declare -r CONTROL_SUCCESS=0 declare -r CONTROL_INIT_FAILED=1 declare -r CONTROL_EXCUTE_FAILED=2 declare -r CONTROL_TIMEOUT=3 declare -r CONTROL_INVALID_PARAM=4 declare SEND_INTERVAL=5 #the interval of send packet declare SEND_OS_VERSION_INTERVAL=120 #the interval of send os version,2min declare SEND_OS_VERSION_COUNTS=0 #the counts of send os version declare SEND_OS_VERSION_COUNTS_TIME=0 #the count time of send os version declare GET_INFO_INTERVAL=5 #the frequency of get CPU,IO andm emory,get once five seconds declare GET_DISK_INFO_INTERVAL=60 #the frequency of get disk information,get once every minute declare GET_NETWORK_INFO_INTERVAL=600 #the frequency of get net card, get once ten minute declare GET_GPU_INFO_INTERVAL=5 #the frequency of get GPU, get once ten minute declare CPU_IO_MEM_COUNT_TIME=0 #the first time need to get CPU,IO,MEM declare DISK_COUNT_TIME=60 #the first time need to get disk information declare NETWORK_COUNT_TIME=600 #the first time need to get netcard information declare GPU_COUNT_TIME=0 #the first time need to get GPU information declare CPU_INFO_FIRST="" #save the old information of CPU declare CPU_INFO_SECOND="" #save the new information of CPU declare IO_INFO_FIRST="" #save the old information of IO declare IO_INFO_SECOND="" #save the new information of IO declare MSG_VERSION_DATA="" declare MSG_INFO_DATA="" declare MAJOR_VERSION="" declare MINOR_VERSION="" declare SYS_BIT="" declare SYS_DISTRIBUTION="" declare CPU_USAGE=0 declare RD_IOPS=0 declare RD_BYTEPS=0 declare WR_IOPS=0 declare WR_BYTEPS=0 declare MEMTOTAL="" declare MEMUSED="" declare DISK_TOTAL="" declare DISK_USED="" declare GPU_INFO="{}" declare VNETDEVS=[] REDHAT_RELEASE_FILE="/etc/redhat-release" LSB_RELEASE_FILE="/etc/lsb-release" ISSUE_FILE="/etc/issue" DEFRAG_FILE="/sys/kernel/mm/transparent_hugepage/defrag" #virtio_nic_attr_set file,not service declare -r g_virtio_nic_attr_file="virtio_nic_attr_set.sh" #Get the os distribution get_os_distribution() { test -f ${REDHAT_RELEASE_FILE} if [ $? -eq 0 ]; then SYS_DISTRIBUTION=`cat ${REDHAT_RELEASE_FILE} | sed 's/(.*)//g' | sed 's/[\t]*$//g' 2>/dev/null` # strip \n SYS_DISTRIBUTION=$(echo $SYS_DISTRIBUTION) return fi log "The file ${REDHAT_RELEASE_FILE} not exist!" test -f ${LSB_RELEASE_FILE} if [ $? -eq 0 ]; then SYS_DISTRIBUTION=`cat ${LSB_RELEASE_FILE} | grep -i "distrib_description" | cut -d'=' -f2 | sed 's/\"//g' | sed 's/[\t]*$//g' 2>/dev/null` # strip \n SYS_DISTRIBUTION=$(echo $SYS_DISTRIBUTION) return fi log "The file ${LSB_RELEASE_FILE} not exist!" type lsb_release >/dev/null 2>&1 if [ $? -eq 0 ]; then SYS_DISTRIBUTION=`lsb_release -a 2>/dev/null | grep -i "description" | cut -d':' -f2 | sed 's/^[ \t]*//g' | sed 's/[\t]*$//g' 2>/dev/null` # strip \n SYS_DISTRIBUTION=$(echo $SYS_DISTRIBUTION) return fi log "check lsb_release failed! the os not exist this command!" #test -f ${ISSUE_FILE} #if [ $? -eq 0 ]; then # SYS_DISTRIBUTION=`cat ${ISSUE_FILE} | head -1 2>/dev/null` # return #fi #log "The file ${ISSUE_FILE} not exist!" } #Get the os information of virtual machine get_os_version() { MAJOR_VERSION=`uname -r | awk -F'.' '{ print $1}'`; if [ ! "${MAJOR_VERSION}" ]; then return 1; fi MINOR_VERSION=`uname -r | awk -F'.' '{ print $2}'`; if [ ! "${MINOR_VERSION}" ]; then return 1; fi local sys_ver=`uname -a` if [ ! "${sys_ver}" ]; then return 1; fi [[ "${sys_ver}" =~ "x86_64" ]] && SYS_BIT=64 || SYS_BIT=32 #add distribution of os get_os_distribution return 0; } #Get the information of CPU get_cpu_info() { local array=`cat /proc/stat | head -n 1 | awk '{print $2" "$3" "$4" "$5" "$6" "$7" "$8}'` echo "$array"; } #Get the information of disk IO get_diskio_info() { local array=`cat /proc/diskstats | grep '[vsh]d[a-z][^1-9]' \ | awk 'BEGIN{a=0;b=0;c=0;d=0}{a=(a"+"$4);b=(b"+"$6);c=(c"+"$8);d=(d"+"$10)}END{print a" "b" "c" "d}'` echo "$array"; } #Get the usage of memory get_mem_usage() { MEMTOTAL=`cat /proc/meminfo | grep MemTotal | awk -F" " '{print $2}'` `cat /proc/meminfo | grep MemAvailable >/dev/null 2>&1 ` local is_MemAvailable=$? if [ ${is_MemAvailable} -ne 0 ]; then local MEMFREE=`cat /proc/meminfo | grep MemFree | awk -F" " '{print $2}'` local MEMBUFFERS=`cat /proc/meminfo | grep ^Buffers | awk -F" " '{print $2}'` MEMUSED=`expr ${MEMTOTAL} - ${MEMFREE} - ${MEMBUFFERS}` else local MEMAVAILABLE=`cat /proc/meminfo | grep MemAvailable| awk -F" " '{print $2}'` MEMUSED=`expr ${MEMTOTAL} - ${MEMAVAILABLE}` fi MEMTOTAL=`expr ${MEMTOTAL} \* 1024` MEMUSED=`expr ${MEMUSED} \* 1024` if [ ${MEMTOTAL} -lt ${MEMUSED} ]; then log "get_mem_usage wrong!" return 1; fi return 0; } #Get the total size of disk get_disk_total() { DISK_TOTAL=`cat /proc/partitions | grep [vsh]d[a-z]$ | awk 'BEGIN{a=0}{a=(a"+"$3)}END{print a}'` if [ ! "${DISK_TOTAL}" ]; then return 1; fi DISK_TOTAL=$((${DISK_TOTAL})) DISK_TOTAL=`expr ${DISK_TOTAL} \* 1024` return 0; } #Get used the size of disk get_disk_used() { #check whether the df command is exist type df >/dev/null 2>&1 if [ $? -ne 0 ]; then log "check df failed!" return 1 fi # ๆไบๆไฝ็ณป็ปๅฏ่ฝๅบ็ฐmountๅคไธช็ฎๅฝ็ๆ ๅต(ๅฆsuse12 sp2),้ๅค่ฎก็ฎ่ถ ่ฟDISK_TOTALๅผ๏ผ็จๅบๅผๅธธ้ๅบ #/dev/vda2 18867200 3635204 14823260 20% / #/dev/vda2 18867200 3635204 14823260 20% /var/lib/libvirt/images #/dev/vda2 18867200 3635204 14823260 20% /var/opt #้่ฟๅป้่งฃๅณ่ฏฅ้ฎ้ข DISK_USED=`df -P | grep ^/dev | grep -E -v '^/dev/(fuse|loop|fstab|sr)' |awk '{print $1 " " $3}'|uniq \ |awk 'BEGIN{a=0}{a=(a"+"$2)}END{print a}'` if [ ! "${DISK_USED}" ]; then return 1; fi DISK_USED=$((${DISK_USED})) DISK_USED=`expr ${DISK_USED} \* 1024` return 0; } get_net_pci_by_sys() { local net_pci=`ls /sys/class/net/$1 -n |egrep -o \:[a-z0-9]{2}\:[a-z0-9]{2}\.[0-7] |tail -n 1 \ |cut -d ":" -f 2-3 | tr [:.] " "` if [ ! "${net_pci}" ]; then return 1; fi echo "${net_pci}" return 0; } get_net_pci_by_lspci() { #check whether the lspci command is exist type lspci >/dev/null 2>&1 if [ $? -ne 0 ]; then log "check lspci failed!" return 1 fi local net_pci=`lspci | grep Eth | awk '{print $1}'|sed -n "${2}p" | tr [:.] " "` if [ ! "${net_pci}" ]; then return 1; fi echo "${net_pci}" return 0; } #Get the ipaddress of netcard get_net_ip() { #check whether the ip command is exist type ip >/dev/null 2>&1 if [ $? -ne 0 ]; then log "check ip failed!" return 1 fi #get only the first two IP local ipaddrs=` ip addr ls ${1} |grep -o -E "([0-9]{1,3}\.){1,3}[0-9]{1,3}/[0-9]{1,2}" | head -n 2 | cut -d '/' -f1 | xargs echo -n | tr ' ' ':'` echo "${ipaddrs}" return 0 } get_gpu_info() { nvidia-smi -i 0 >/dev/null 2>&1 if [ 0 -eq $? ]; then local total_memory=$((1024*1024*$(nvidia-smi -i 0 |grep MiB|awk '{print $11}'|awk -FM '{print $1}'))) local used_memory=$((1024*1024*$(nvidia-smi -i 0 |grep MiB|awk '{print $9}'|awk -FM '{print $1}'))) local gpu_usage=`nvidia-smi -i 0 |grep MiB|awk '{print $13}'|awk -F% '{print $1}'` local driver_version=`nvidia-smi -i 0 |grep Version|awk '{print $6}'|awk -F. '{print $1}'` local gpu_model=`nvidia-smi -i 0 |grep GRID|awk '{print $4}'` GPU_INFO={\"total_memory\":\"${total_memory}\",\"used_memory\":\"${used_memory}\",\"gpu_usage\":${gpu_usage},\"driver_version\":${driver_version},\"gpu_model\":\"${gpu_model}\"} else GPU_INFO="{}" fi return 0 } #Get the information of netcard get_net_info() { local net_count=0 net_count=`get_net_count`; #if the count of netcard is zero ,then return directly,the netcard field is set null if [ ${net_count} -eq 0 ]; then VNETDEVS=[] return 0; fi local net_name="" net_name=`get_net_name` if [ -z "$net_name" ]; then log "get_net_name failed" return 1; fi local net_num=0; local tmp_name="" local tmpstr="" #get the PCI and ipaddress of every netcard for tmp_name in ${net_name} do net_num=$(($net_num + 1)); #get pci of netcard tmpstr=`get_net_pci_by_sys ${tmp_name}` if [ $? -eq 1 ]; then tmpstr=`get_net_pci_by_lspci ${net_num}` if [ $? -eq 1 ]; then log "get_net_pci failed" return 1; fi fi #save the pci information local busNumber="" local devNumber="" local funcNumber="" local net_pci_bus=`echo "${tmpstr}" | cut -d " " -f 1` local net_pci_dev=`echo "${tmpstr}" | cut -d " " -f 2` local net_pci_func=`echo "${tmpstr}" | cut -d " " -f 3` ((busNumber=16#${net_pci_bus})) ((devNumber=16#${net_pci_dev})) ((funcNumber=16#${net_pci_func})) #get the ipaddress of netcard local ipaddrs="" ipaddrs=`get_net_ip ${tmp_name}` if [ $? -ne 0 ]; then log "get_net_ip failed!" return 1 fi if [ ${net_num} -eq 1 ]; then VNETDEVS={\"busNumber\":${busNumber},\"devNumber\":${devNumber},\"funcNumber\":${funcNumber},\"ipaddrs\":\"${ipaddrs}\"} continue; fi VNETDEVS=${VNETDEVS}",{\"busNumber\":${busNumber},\"devNumber\":${devNumber},\"funcNumber\":${funcNumber},\"ipaddrs\":\"${ipaddrs}\"}" done #finaly ,add "[]" outside the VNETDEVS VNETDEVS="["${VNETDEVS}"]" return 0; } #get the information of disk get_disk_info() { #get the information of the total size of disk get_disk_total if [ $? -eq 1 ]; then log "get_disk_total failed" return 1; fi #get the usage of disk get_disk_used if [ $? -eq 1 ]; then log "get_disk_used failed" return 1; fi if [ ${DISK_TOTAL} -lt ${DISK_USED} ]; then log "get_disk wrong!" return 1; fi return 0 } #caculate the cpu usage and io caculate_cpu_io() { #caculate the usage of CPU local old_cpu_time=0 local index=1 local tmp_cpu=0 for((index=1;index<8;index++)) do tmp_cpu=`echo "${CPU_INFO_FIRST}" | cut -d " " -f $index` let " old_cpu_time = $tmp_cpu + $old_cpu_time " done local new_cpu_time=0 tmp_cpu=0 for((index=1;index<8;index++)) do tmp_cpu=`echo "${CPU_INFO_SECOND}" | cut -d " " -f $index` let " new_cpu_time = $tmp_cpu + $new_cpu_time " done local cpu_total_diff=`expr $new_cpu_time - $old_cpu_time` local cpu_arr1=`echo "${CPU_INFO_FIRST}" | awk -F' ' '{print $4}'` local cpu_arr2=`echo "${CPU_INFO_SECOND}" | awk -F' ' '{print $4}'` local idle_time_diff=`expr $cpu_arr2 - $cpu_arr1` if [ $cpu_total_diff -eq 0 ]; then CPU_USAGE=0; else CPU_USAGE=`expr 100 \* \( $cpu_total_diff - $idle_time_diff \) \/ \( $new_cpu_time - $old_cpu_time \)`; fi #caculate the Disk io local diskio1=`echo "${IO_INFO_FIRST}" | awk -F' ' '{print $1}'` diskio1=$((${diskio1})) local diskio2=`echo "${IO_INFO_SECOND}" | awk -F' ' '{print $1}'` diskio2=$((${diskio2})) RD_IOPS=`expr \( ${diskio2} - ${diskio1} \) \/ ${GET_INFO_INTERVAL}`; diskio1=`echo "${IO_INFO_FIRST}" | awk -F' ' '{print $2}'` diskio1=$((${diskio1})) diskio2=`echo "${IO_INFO_SECOND}" | awk -F' ' '{print $2}'` diskio2=$((${diskio2})) RD_BYTEPS=`expr \( ${diskio2} - ${diskio1} \) \/ ${GET_INFO_INTERVAL}`; RD_BYTEPS=$((${RD_BYTEPS}*512)) diskio1=`echo "${IO_INFO_FIRST}" | awk -F' ' '{print $3}'` diskio1=$((${diskio1})) diskio2=`echo "${IO_INFO_SECOND}" | awk -F' ' '{print $3}'` diskio2=$((${diskio2})) WR_IOPS=`expr \( ${diskio2} - ${diskio1} \) \/ ${GET_INFO_INTERVAL}`; diskio1=`echo "${IO_INFO_FIRST}" | awk -F' ' '{print $4}'` diskio1=$((${diskio1})) diskio2=`echo "${IO_INFO_SECOND}" | awk -F' ' '{print $4}'` diskio2=$((${diskio2})) WR_BYTEPS=`expr \( ${diskio2} - ${diskio1} \) \/ ${GET_INFO_INTERVAL}`; WR_BYTEPS=$((${WR_BYTEPS}*512)) return 0; } #Get the information of CPU USAGE,IO,MEMORY get_cpu_io_mem_info() { if [ ${CPU_IO_MEM_COUNT_TIME} -eq 0 ]; then CPU_INFO_FIRST=`get_cpu_info` IO_INFO_FIRST=`get_diskio_info` get_mem_usage if [ $? -ne 0 ]; then log "get_mem_usage failed" return 1 fi fi if [ ${CPU_IO_MEM_COUNT_TIME} -ge ${GET_INFO_INTERVAL} ]; then CPU_INFO_SECOND=`get_cpu_info` IO_INFO_SECOND=`get_diskio_info` get_mem_usage if [ $? -ne 0 ]; then log "get_mem_usage failed" return 1 fi caculate_cpu_io if [ $? -ne 0 ]; then log "caculate cpu io failed" return 1 fi CPU_INFO_FIRST=${CPU_INFO_SECOND} IO_INFO_FIRST=${IO_INFO_SECOND} CPU_IO_MEM_COUNT_TIME=0 fi let " CPU_IO_MEM_COUNT_TIME = ${SEND_INTERVAL} + CPU_IO_MEM_COUNT_TIME " return 0 } #Get the report data of virtual machine get_os_info() { local ret="" #Get the information of CPU USAGE,IO,MEMORY get_cpu_io_mem_info if [ $? -eq 1 ]; then log "get_cpu_diskio_usage failed" return 1; fi if [ ${DISK_COUNT_TIME} -ge ${GET_DISK_INFO_INTERVAL} ]; then #get the information of the usage of disk get_disk_info if [ $? -eq 1 ]; then log "get_disk_info failed" return 1; fi DISK_COUNT_TIME=0 fi let " DISK_COUNT_TIME = ${SEND_INTERVAL} + DISK_COUNT_TIME " if [ -e "${shell_dir}/update_network.flag" ];then ret=`cat ${shell_dir}/update_network.flag` fi if [ ${NETWORK_COUNT_TIME} -ge ${GET_NETWORK_INFO_INTERVAL} ] || [ x"" != x"$ret" ]; then #get the information of netcard get_net_info if [ $? -eq 1 ]; then log "get_net_info failed" return 1; fi echo "" > "${shell_dir}/update_network.flag" NETWORK_COUNT_TIME=0 fi let " NETWORK_COUNT_TIME = ${SEND_INTERVAL} + NETWORK_COUNT_TIME " if [ ${GPU_COUNT_TIME} -ge ${GET_GPU_INFO_INTERVAL} ]; then #get the information of GPU get_gpu_info if [ $? -eq 1 ]; then log "get_gpu_info failed" return 1; fi GPU_COUNT_TIME=0 fi let " GPU_COUNT_TIME = ${SEND_INTERVAL} + GPU_COUNT_TIME " return 0; } send_os_version_to_host() { get_os_version; if [ $? -eq 1 ]; then log "get os version failed!!!" return 1 fi MSG_VERSION_DATA="{\"major_version\":\"${MAJOR_VERSION}\",\"minor_version\":\"${MINOR_VERSION}\",\"product_type\":0,\"systerm_bit_type\":${SYS_BIT},\"systerm_distribution\":\"${SYS_DISTRIBUTION}\"}" vm_ipc_to_local_host ${MOD_ID} ${INST_ID} ${MSGID_SEND_VERSION} "${MSG_VERSION_DATA}" || return 1; return 0; } send_os_info_to_host() { get_os_info if [ $? -eq 1 ]; then log "get_os_info failed" return 1 fi MSG_INFO_DATA="{\"mem_total\":\"${MEMTOTAL}\",\"mem_used\":\"${MEMUSED}\",\"cpu_used\":\"${CPU_USAGE}\",\"disk_total\":\"${DISK_TOTAL}\",\"disk_used\":\"${DISK_USED}\",\"rd_bytes\":\"${RD_BYTEPS}\",\"wr_bytes\":\"${WR_BYTEPS}\",\"rd_oper\":\"${RD_IOPS}\",\"wr_oper\":\"${WR_IOPS}\",\"vnetdevs\":${VNETDEVS},\"gpuInfo\":${GPU_INFO}}" vm_ipc_to_local_host ${MOD_ID} ${INST_ID} ${MSGID_SEND_GUEST_DATA} "${MSG_INFO_DATA}" || return 1; return 0; } send_data_to_host() { if [ ${RUN_MODE} -eq ${SEND_VERSION} ]; then if [ ${SEND_OS_VERSION_COUNTS} -ne 0 ] && [ ${SEND_OS_VERSION_COUNTS_TIME} -lt ${SEND_OS_VERSION_INTERVAL} ]; then SEND_OS_VERSION_COUNTS_TIME=$((${SEND_INTERVAL}+${SEND_OS_VERSION_COUNTS_TIME})) log "wait host to reply" return 0; fi send_os_version_to_host; if [ $? -eq 1 ]; then log "send_os_version_to_host failed" return 1; fi SEND_OS_VERSION_COUNTS=$((${SEND_OS_VERSION_COUNTS}+1)) SEND_OS_VERSION_COUNTS_TIME=0 log "send os version success" else send_os_info_to_host; if [ $? -eq 1 ]; then log "send_os_info_to_host failed" return 1; fi fi return 0; } change_send_mod() { log "host reply success, now start send os information" RUN_MODE=${SEND_INFO} } #To active cpu that hotplugged in cpu_active() { #รรรรรรยตรรยตรยณรยปรรsort -Vรรผรรฎยฃยฌรรรรรรยธรรรงรร #for CPU in $(ls /sys/devices/system/cpu/ | grep -i 'cpu[0-9].*' | sort -V) for CPU in $(ls /sys/devices/system/cpu/ | grep -i 'cpu[0-9].*' | sed "s/cpu/ /g" | sort -n) do CPU="cpu${CPU}" CPU_DIR="/sys/devices/system/cpu/${CPU}" CPU_STATE_FILE="${CPU_DIR}/online" if [ -f "${CPU_STATE_FILE}" ]; then STATE=$(cat "${CPU_STATE_FILE}") if [ x"${STATE}" != x"1" ]; then log "\t${CPU} is new cpu, onlining cpu ..." echo 1 > "${CPU_STATE_FILE}" 2>/dev/null fi fi done } #To active memory that hotplugged in memory_active() { #รรรรรรยตรรยตรยณรยปรรsort -Vรรผรรฎยฃยฌรรรรรรยธรรรงรร #for MEMORY in $(ls /sys/devices/system/memory/ | grep -i 'memory[0-9].*' | sort -V) for MEMORY in $(ls /sys/devices/system/memory/ | grep -i 'memory[0-9].*'|sed "s/memory/ /g" | sort -n) do MEMORY="memory${MEMORY}" SPARSEMEM_DIR="/sys/devices/system/memory/${MEMORY}" SPARSEMEM_STATE_FILE="${SPARSEMEM_DIR}/state" STATE=$(cat "${SPARSEMEM_STATE_FILE}" | grep -i online) if [ x"${STATE}" != x"online" ]; then log "\t${MEMORY} is new memory, onlining memory ..." echo online > "${SPARSEMEM_STATE_FILE}" 2>/dev/null fi done } check_hotplug() { cpu_active memory_active } netinfo_send_to_host() { #get the information of netcard log "===================netinfo_send_to_host=========================" get_net_info if [ $? -eq 1 ]; then log "get_net_info failed" return 1; fi MSG_INFO_DATA="{\"vnetdevs\":${VNETDEVS}}" vm_ipc_to_local_host ${SDN_MOD_ID} ${INST_ID} ${MSGID_SEND_NETINFO} "${MSG_INFO_DATA}" || return 1; } update_vm_config_action() { local msg=$1 local action=`echo ${msg} | tr ',' '\n' | grep "action" | cut -d: -f 2 | sed s/[\"{}]//g` if [ x"${action}" = x"update_passwd" ];then log "update_passwd" local password=`echo ${msg} | tr ',' '\n' | grep "passwd" | cut -d: -f 2 | sed s/[\"{}]//g` set_root_pwd $password elif [ x"${action}" = x"update_ip_hostname" ];then log "update_ip_hostname" . "${shell_dir}/sangfor_set_network.sh" echo "1" > "$shell_dir/update_vmconfig.flag" elif [ x"${action}" = x"update_dns" ];then log "update_dns" . "${shell_dir}/sangfor_set_network.sh" "dns" echo "1" > "$shell_dir/update_vmconfig.flag" else log "update_vm_config_action unknown cmd action" fi } excute_control_cmd() { log "start excute control cmd" if [ $# -lt 3 ]; then log "parameter error!" return 1 fi local CTRL_INSTID=$2 local MSGBUF=`cat $3` #msg is save in file that $3 specified if [ ${MSGBUF} = "" ];then log "recv empty msg" return 1 fi local CMD=`echo ${MSGBUF} | tr ',' '\n' | grep "ctrl_cmd" | cut -d: -f 2 | sed s/[\"{}]//g` local VMID=`echo ${MSGBUF} | tr ',' '\n' | grep "vmid" | cut -d: -f 2 | sed s/[\"{}]//g` #msg format: "ctrl_cmd":"shutdown","vmid":"6476227890258" #msg format: "ctrl_cmd":"hotplug_cpu_active","vmid":"6476227890258" #msg format: "ctrl_cmd":"hotplug_memory_active","vmid":"6476227890258" MSG_INFO_DATA="{\"ret_code\":\"${CONTROL_SUCCESS}\",\"vmid\":\"${VMID}\"}" if [ x"${CMD}" = x"shutdown" ];then vm_ipc_to_local_host ${CTRL_MOD_ID} ${CTRL_INSTID} ${MSGID_SEND_CONTROL_REPLY} "${MSG_INFO_DATA}" || return 1 sleep $((${SEND_SLEEP_TIME__}*2)) type shutdown > /dev/null 2>&1 if [ $? -ne 0 ];then halt else shutdown -h now fi return 0 elif [ x"${CMD}" = x"hotplug_nic_attr_set" ]; then log "start exec hotplug_nic_attr_set" test -e "${shell_dir}/${g_virtio_nic_attr_file}" && "${shell_dir}/${g_virtio_nic_attr_file}" elif [ x"${CMD}" = x"update_vm_config" ]; then log "start update_vm_config..." update_vm_config_action ${MSGBUF} elif [ x"${CMD}" = x"get_hostname" ]; then log "get hostname" hostname=`hostname` MSG_INFO_DATA="{\"ret_code\":\"${CONTROL_SUCCESS}\",\"vmid\":\"${VMID}\",\"hostname\":\"${hostname}\"}" else log "unknown cmd type" fi vm_ipc_to_local_host ${CTRL_MOD_ID} ${CTRL_INSTID} ${MSGID_SEND_CONTROL_REPLY} "${MSG_INFO_DATA}" || return 1; return 0; } # kill proccess # if the name of proccess is the same with the name of script,it won't kill itself # param $1: name of proccess(don't include path) # return if success then return 0 or return 1 kill_process() { if [ $# -ne 1 ]; then log "parameter error!" return 1 fi local pid=$$ local procname=${1} #this is pipe,should't execute with awk,because the Shuffle local ps_list=`ps ax | grep "${procname}\>" | grep -v grep | grep -v "\<${pid}\>"` if [ ! -z "${ps_list}" ]; then echo "${ps_list}" | awk '{print "kill " $1 " 2>/dev/null"}' | sh fi return $? } disable_defrag() { if [ ! -f ${DEFRAG_FILE} ]; then log "defrag file does not exist." else `echo never > ${DEFRAG_FILE}` log "disable defrag success." fi } main() { #initialize the environment kill_process "${proc_name}" #join the monitor watchdog_reg_proccess "${proc_name}" #initialize vm_ipc_init ${MOD_ID} ${INST_ID} if [ $? -ne 0 ]; then log "vm_ipc_init() failed! modid='${MOD_ID}' instid='${INST_ID}'" return 1 fi log "vm_ipc_init success." disable_defrag #Registration message callback function vm_ipc_reg_callback ${MSGID_RECV_REPLY_VERSION} change_send_mod #add vm control callback. by fangfei 2015.4.11 vm_ipc_reg_callback ${MSGID_RECV_CONTROL_CMD} excute_control_cmd #add netinfo get callback. by hhw 2016.5.7 vm_ipc_reg_callback ${MSGID_RECV_GET_NETINFO} netinfo_send_to_host log "start while send_data_to_host" while true do send_data_to_host; if [ $? -ne 0 ]; then log "send_data_to_host failed!" return 1; fi vm_ipc_event_loop_once watchdog_check_once check_hotplug sleep ${SEND_INTERVAL} done } if [ $# -eq 1 ]; then if [ "$1" = "DEBUG" ]; then source "${shell_dir}/uni_test.sh" fi fi main
Upload File
Create Folder