Modify mcreboot.sh for job scheduler
1. Add an option to specify owner of device files 2. Output message to stderr and return one on error
This commit is contained in:
@@ -24,19 +24,23 @@ cpus=""
|
|||||||
|
|
||||||
INTERVAL=1
|
INTERVAL=1
|
||||||
LOGMODE=0
|
LOGMODE=0
|
||||||
while getopts :i:k:c:m: OPT
|
chown_option=`logname`
|
||||||
|
|
||||||
|
while getopts :i:k:c:m:o: OPT
|
||||||
do
|
do
|
||||||
case ${OPT} in
|
case ${OPT} in
|
||||||
|
o) chown_option=${OPTARG}
|
||||||
|
;;
|
||||||
i) INTERVAL=${OPTARG}
|
i) INTERVAL=${OPTARG}
|
||||||
expr "${INTERVAL}" + 1 > /dev/null 2>&1
|
expr "${INTERVAL}" + 1 > /dev/null 2>&1
|
||||||
if [ $? -ge 2 ]
|
if [ $? -ge 2 ]
|
||||||
then
|
then
|
||||||
echo "invalid -i value"
|
echo "invalid -i value" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [ ${INTERVAL} -le 0 ]
|
if [ ${INTERVAL} -le 0 ]
|
||||||
then
|
then
|
||||||
echo "invalid -i value"
|
echo "invalid -i value" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
@@ -44,12 +48,12 @@ do
|
|||||||
expr "${LOGMODE}" + 1 > /dev/null 2>&1
|
expr "${LOGMODE}" + 1 > /dev/null 2>&1
|
||||||
if [ $? -ge 2 ]
|
if [ $? -ge 2 ]
|
||||||
then
|
then
|
||||||
echo "invalid -k value"
|
echo "invalid -k value" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [ ${LOGMODE} -lt 0 -o ${LOGMODE} -gt 2 ]
|
if [ ${LOGMODE} -lt 0 -o ${LOGMODE} -gt 2 ]
|
||||||
then
|
then
|
||||||
echo "invalid -k value"
|
echo "invalid -k value" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
@@ -57,7 +61,7 @@ do
|
|||||||
;;
|
;;
|
||||||
m) mem=${OPTARG}
|
m) mem=${OPTARG}
|
||||||
;;
|
;;
|
||||||
*) echo "invalid option -${OPT}"
|
*) echo "invalid option -${OPT}" >&2
|
||||||
exit 1
|
exit 1
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@@ -84,7 +88,7 @@ if [ "$cpus" == "" ]; then
|
|||||||
# Use the second half of the cores
|
# Use the second half of the cores
|
||||||
let nr_cpus="$nr_cpus / 2"
|
let nr_cpus="$nr_cpus / 2"
|
||||||
cpus=`lscpu --parse | awk -F"," '{if ($4 == 0) print $1}' | tail -n $nr_cpus | xargs echo -n | sed 's/ /,/g'`
|
cpus=`lscpu --parse | awk -F"," '{if ($4 == 0) print $1}' | tail -n $nr_cpus | xargs echo -n | sed 's/ /,/g'`
|
||||||
if [ "$cpus" == "" ]; then echo "error: no available CPUs on NUMA node 0?"; exit; fi
|
if [ "$cpus" == "" ]; then echo "error: no available CPUs on NUMA node 0?" >&2; exit 1; fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove mcoverlay if loaded
|
# Remove mcoverlay if loaded
|
||||||
@@ -95,13 +99,13 @@ if [ "$enable_mcoverlay" == "yes" ]; then
|
|||||||
if [ "`cat /proc/mounts | grep /tmp/mcos/linux_proc`" != "" ]; then umount -l /tmp/mcos/linux_proc; fi
|
if [ "`cat /proc/mounts | grep /tmp/mcos/linux_proc`" != "" ]; then umount -l /tmp/mcos/linux_proc; fi
|
||||||
if [ "`cat /proc/mounts | grep /tmp/mcos`" != "" ]; then umount -l /tmp/mcos; fi
|
if [ "`cat /proc/mounts | grep /tmp/mcos`" != "" ]; then umount -l /tmp/mcos; fi
|
||||||
if [ -e /tmp/mcos ]; then rm -rf /tmp/mcos; fi
|
if [ -e /tmp/mcos ]; then rm -rf /tmp/mcos; fi
|
||||||
if ! rmmod mcoverlay; then echo "error: removing mcoverlay"; exit; fi
|
if ! rmmod mcoverlay; then echo "error: removing mcoverlay" >&2; exit 1; fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Load IHK if not loaded
|
# Load IHK if not loaded
|
||||||
if [ "`lsmod | grep ihk`" == "" ]; then
|
if [ "`lsmod | grep ihk`" == "" ]; then
|
||||||
if ! insmod ${KMODDIR}/ihk.ko; then echo "error: loading ihk"; exit; fi;
|
if ! insmod ${KMODDIR}/ihk.ko; then echo "error: loading ihk" >&2; exit 1; fi;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Load IHK-SMP if not loaded and reserve CPUs and memory
|
# Load IHK-SMP if not loaded and reserve CPUs and memory
|
||||||
@@ -113,61 +117,61 @@ if [ "`lsmod | grep ihk_smp_x86`" == "" ]; then
|
|||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [ "$ihk_irq" == "" ]; then echo "error: no IRQ available"; exit; fi
|
if [ "$ihk_irq" == "" ]; then echo "error: no IRQ available" >&2; exit 1; fi
|
||||||
if ! insmod ${KMODDIR}/ihk-smp-x86.ko ihk_start_irq=$ihk_irq ihk_ikc_irq_core=$ihk_ikc_irq_core; then echo "error: loading ihk-smp-x86"; exit; fi;
|
if ! insmod ${KMODDIR}/ihk-smp-x86.ko ihk_start_irq=$ihk_irq ihk_ikc_irq_core=$ihk_ikc_irq_core; then echo "error: loading ihk-smp-x86" >&2; exit 1; fi;
|
||||||
if ! ${SBINDIR}/ihkconfig 0 reserve cpu ${cpus}; then echo "error: reserving CPUs"; exit; fi
|
if ! ${SBINDIR}/ihkconfig 0 reserve cpu ${cpus}; then echo "error: reserving CPUs" >&2; exit 1; fi
|
||||||
if ! ${SBINDIR}/ihkconfig 0 reserve mem ${mem}; then echo "error: reserving memory"; exit; fi
|
if ! ${SBINDIR}/ihkconfig 0 reserve mem ${mem}; then echo "error: reserving memory" >&2; exit 1; fi
|
||||||
# If loaded, but no resources allocated, get CPUs and memory
|
# If loaded, but no resources allocated, get CPUs and memory
|
||||||
else
|
else
|
||||||
if ! ${SBINDIR}/ihkconfig 0 query cpu > /dev/null; then echo "error: querying cpus"; exit; fi
|
if ! ${SBINDIR}/ihkconfig 0 query cpu > /dev/null; then echo "error: querying cpus" >&2; exit 1; fi
|
||||||
cpus_allocated=`${SBINDIR}/ihkosctl 0 query cpu`
|
cpus_allocated=`${SBINDIR}/ihkosctl 0 query cpu`
|
||||||
if [ "$cpus_allocated" == "" ]; then
|
if [ "$cpus_allocated" == "" ]; then
|
||||||
if ! ${SBINDIR}/ihkconfig 0 reserve cpu ${cpus}; then echo "error: reserving CPUs"; exit; fi
|
if ! ${SBINDIR}/ihkconfig 0 reserve cpu ${cpus}; then echo "error: reserving CPUs" >&2; exit 1; fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! ${SBINDIR}/ihkosctl 0 query mem > /dev/null; then echo "error: querying memory"; exit; fi
|
if ! ${SBINDIR}/ihkosctl 0 query mem > /dev/null; then echo "error: querying memory" >&2; exit 1; fi
|
||||||
mem_allocated=`${SBINDIR}/ihkosctl 0 query mem`
|
mem_allocated=`${SBINDIR}/ihkosctl 0 query mem`
|
||||||
if [ "$mem_allocated" == "" ]; then
|
if [ "$mem_allocated" == "" ]; then
|
||||||
if ! ${SBINDIR}/ihkconfig 0 reserve mem ${mem}; then echo "error: reserving memory"; exit; fi
|
if ! ${SBINDIR}/ihkconfig 0 reserve mem ${mem}; then echo "error: reserving memory" >&2; exit 1; fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Load mcctrl if not loaded
|
# Load mcctrl if not loaded
|
||||||
if [ "`lsmod | grep mcctrl`" == "" ]; then
|
if [ "`lsmod | grep mcctrl`" == "" ]; then
|
||||||
if ! insmod ${KMODDIR}/mcctrl.ko; then echo "error: inserting mcctrl.ko"; exit; fi
|
if ! insmod ${KMODDIR}/mcctrl.ko; then echo "error: inserting mcctrl.ko" >&2; exit 1; fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check for existing OS instance and destroy
|
# Check for existing OS instance and destroy
|
||||||
if [ -c /dev/mcos0 ]; then
|
if [ -c /dev/mcos0 ]; then
|
||||||
# Query CPU cores and memory of OS instance so that the same values are used as previously
|
# Query CPU cores and memory of OS instance so that the same values are used as previously
|
||||||
if ! ${SBINDIR}/ihkosctl 0 query cpu > /dev/null; then echo "error: querying cpus"; exit; fi
|
if ! ${SBINDIR}/ihkosctl 0 query cpu > /dev/null; then echo "error: querying cpus" >&2; exit 1; fi
|
||||||
cpus=`${SBINDIR}/ihkosctl 0 query cpu`
|
cpus=`${SBINDIR}/ihkosctl 0 query cpu`
|
||||||
if ! ${SBINDIR}/ihkosctl 0 query mem > /dev/null; then echo "error: querying memory"; exit; fi
|
if ! ${SBINDIR}/ihkosctl 0 query mem > /dev/null; then echo "error: querying memory" >&2; exit 1; fi
|
||||||
mem=`${SBINDIR}/ihkosctl 0 query mem`
|
mem=`${SBINDIR}/ihkosctl 0 query mem`
|
||||||
|
|
||||||
if ! ${SBINDIR}/ihkconfig 0 destroy 0; then echo "warning: destroy failed"; fi
|
if ! ${SBINDIR}/ihkconfig 0 destroy 0; then echo "warning: destroy failed" >&2; fi
|
||||||
else
|
else
|
||||||
# Otherwise query IHK-SMP for resources
|
# Otherwise query IHK-SMP for resources
|
||||||
if ! ${SBINDIR}/ihkconfig 0 query cpu > /dev/null; then echo "error: querying cpus"; exit; fi
|
if ! ${SBINDIR}/ihkconfig 0 query cpu > /dev/null; then echo "error: querying cpus" >&2; exit 1; fi
|
||||||
cpus=`${SBINDIR}/ihkconfig 0 query cpu`
|
cpus=`${SBINDIR}/ihkconfig 0 query cpu`
|
||||||
if ! ${SBINDIR}/ihkconfig 0 query mem > /dev/null; then echo "error: querying memory"; exit; fi
|
if ! ${SBINDIR}/ihkconfig 0 query mem > /dev/null; then echo "error: querying memory" >&2; exit 1; fi
|
||||||
mem=`${SBINDIR}/ihkconfig 0 query mem`
|
mem=`${SBINDIR}/ihkconfig 0 query mem`
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! ${SBINDIR}/ihkconfig 0 create; then echo "error: create"; exit; fi
|
if ! ${SBINDIR}/ihkconfig 0 create; then echo "error: create" >&2; exit; fi
|
||||||
if ! ${SBINDIR}/ihkosctl 0 assign cpu ${cpus}; then echo "error: assign CPUs"; exit; fi
|
if ! ${SBINDIR}/ihkosctl 0 assign cpu ${cpus}; then echo "error: assign CPUs" >&2; exit 1; fi
|
||||||
if ! ${SBINDIR}/ihkosctl 0 assign mem ${mem}; then echo "error: assign memory"; exit; fi
|
if ! ${SBINDIR}/ihkosctl 0 assign mem ${mem}; then echo "error: assign memory" >&2; exit 1; fi
|
||||||
if ! ${SBINDIR}/ihkosctl 0 load ${KERNDIR}/mckernel.img; then echo "error: loading kernel image"; exit; fi
|
if ! ${SBINDIR}/ihkosctl 0 load ${KERNDIR}/mckernel.img; then echo "error: loading kernel image" >&2; exit 1; fi
|
||||||
if ! ${SBINDIR}/ihkosctl 0 kargs "hidos ksyslogd=${LOGMODE}"; then echo "error: setting kernel arguments"; exit; fi
|
if ! ${SBINDIR}/ihkosctl 0 kargs "hidos ksyslogd=${LOGMODE}"; then echo "error: setting kernel arguments" >&2; exit 1; fi
|
||||||
if ! ${SBINDIR}/ihkosctl 0 boot; then echo "error: booting"; exit; fi
|
if ! ${SBINDIR}/ihkosctl 0 boot; then echo "error: booting" >&2; exit 1; fi
|
||||||
if ! chown `logname` /dev/mcd* /dev/mcos*; then echo "error: chowning device files"; exit; fi
|
if ! chown ${chown_option} /dev/mcd* /dev/mcos*; then echo "error: chowning device files" >&2; exit 1; fi
|
||||||
|
|
||||||
if [ "$enable_mcoverlay" == "yes" ]; then
|
if [ "$enable_mcoverlay" == "yes" ]; then
|
||||||
if [ ! -e /tmp/mcos ]; then mkdir -p /tmp/mcos; fi
|
if [ ! -e /tmp/mcos ]; then mkdir -p /tmp/mcos; fi
|
||||||
if ! mount -t tmpfs tmpfs /tmp/mcos; then echo "error: mount /tmp/mcos"; exit; fi
|
if ! mount -t tmpfs tmpfs /tmp/mcos; then echo "error: mount /tmp/mcos" >&2; exit 1; fi
|
||||||
if [ ! -e /tmp/mcos/linux_proc ]; then mkdir -p /tmp/mcos/linux_proc; fi
|
if [ ! -e /tmp/mcos/linux_proc ]; then mkdir -p /tmp/mcos/linux_proc; fi
|
||||||
if ! mount --bind /proc /tmp/mcos/linux_proc; then echo "error: mount /tmp/mcos/linux_proc"; exit; fi
|
if ! mount --bind /proc /tmp/mcos/linux_proc; then echo "error: mount /tmp/mcos/linux_proc" >&2; exit 1; fi
|
||||||
if ! insmod ${KMODDIR}/mcoverlay.ko; then echo "error: inserting mcoverlay.ko"; exit; fi
|
if ! insmod ${KMODDIR}/mcoverlay.ko; then echo "error: inserting mcoverlay.ko" >&2; exit 1; fi
|
||||||
while [ ! -e /proc/mcos0 ]
|
while [ ! -e /proc/mcos0 ]
|
||||||
do
|
do
|
||||||
sleep 1
|
sleep 1
|
||||||
@@ -175,7 +179,7 @@ if [ "$enable_mcoverlay" == "yes" ]; then
|
|||||||
if [ ! -e /tmp/mcos/mcos0_proc ]; then mkdir -p /tmp/mcos/mcos0_proc; fi
|
if [ ! -e /tmp/mcos/mcos0_proc ]; then mkdir -p /tmp/mcos/mcos0_proc; fi
|
||||||
if [ ! -e /tmp/mcos/mcos0_proc_upper ]; then mkdir -p /tmp/mcos/mcos0_proc_upper; fi
|
if [ ! -e /tmp/mcos/mcos0_proc_upper ]; then mkdir -p /tmp/mcos/mcos0_proc_upper; fi
|
||||||
if [ ! -e /tmp/mcos/mcos0_proc_work ]; then mkdir -p /tmp/mcos/mcos0_proc_work; fi
|
if [ ! -e /tmp/mcos/mcos0_proc_work ]; then mkdir -p /tmp/mcos/mcos0_proc_work; fi
|
||||||
if ! mount -t mcoverlay mcoverlay -o lowerdir=/proc/mcos0:/proc,upperdir=/tmp/mcos/mcos0_proc_upper,workdir=/tmp/mcos/mcos0_proc_work,nocopyupw,nofscheck /tmp/mcos/mcos0_proc; then echo "error: mount /tmp/mcos/mcos0_proc"; exit; fi
|
if ! mount -t mcoverlay mcoverlay -o lowerdir=/proc/mcos0:/proc,upperdir=/tmp/mcos/mcos0_proc_upper,workdir=/tmp/mcos/mcos0_proc_work,nocopyupw,nofscheck /tmp/mcos/mcos0_proc; then echo "error: mount /tmp/mcos/mcos0_proc" >&2; exit 1; fi
|
||||||
mount --make-rprivate /proc
|
mount --make-rprivate /proc
|
||||||
while [ ! -e /sys/devices/virtual/mcos/mcos0/sys ]
|
while [ ! -e /sys/devices/virtual/mcos/mcos0/sys ]
|
||||||
do
|
do
|
||||||
@@ -184,7 +188,7 @@ if [ "$enable_mcoverlay" == "yes" ]; then
|
|||||||
if [ ! -e /tmp/mcos/mcos0_sys ]; then mkdir -p /tmp/mcos/mcos0_sys; fi
|
if [ ! -e /tmp/mcos/mcos0_sys ]; then mkdir -p /tmp/mcos/mcos0_sys; fi
|
||||||
if [ ! -e /tmp/mcos/mcos0_sys_upper ]; then mkdir -p /tmp/mcos/mcos0_sys_upper; fi
|
if [ ! -e /tmp/mcos/mcos0_sys_upper ]; then mkdir -p /tmp/mcos/mcos0_sys_upper; fi
|
||||||
if [ ! -e /tmp/mcos/mcos0_sys_work ]; then mkdir -p /tmp/mcos/mcos0_sys_work; fi
|
if [ ! -e /tmp/mcos/mcos0_sys_work ]; then mkdir -p /tmp/mcos/mcos0_sys_work; fi
|
||||||
if ! mount -t mcoverlay mcoverlay -o lowerdir=/sys/devices/virtual/mcos/mcos0/sys:/sys,upperdir=/tmp/mcos/mcos0_sys_upper,workdir=/tmp/mcos/mcos0_sys_work,nocopyupw,nofscheck /tmp/mcos/mcos0_sys; then echo "error: mount /tmp/mcos/mcos0_sys"; exit; fi
|
if ! mount -t mcoverlay mcoverlay -o lowerdir=/sys/devices/virtual/mcos/mcos0/sys:/sys,upperdir=/tmp/mcos/mcos0_sys_upper,workdir=/tmp/mcos/mcos0_sys_work,nocopyupw,nofscheck /tmp/mcos/mcos0_sys; then echo "error: mount /tmp/mcos/mcos0_sys" >&2; exit 1; fi
|
||||||
mount --make-rprivate /sys
|
mount --make-rprivate /sys
|
||||||
for cpuid in `find /sys/devices/system/cpu/* -maxdepth 0 -name "cpu[0123456789]*" -printf "%f "`; do
|
for cpuid in `find /sys/devices/system/cpu/* -maxdepth 0 -name "cpu[0123456789]*" -printf "%f "`; do
|
||||||
if [ ! -e "/sys/devices/virtual/mcos/mcos0/sys/devices/system/cpu/$cpuid" ]; then
|
if [ ! -e "/sys/devices/virtual/mcos/mcos0/sys/devices/system/cpu/$cpuid" ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user