From 15783f09a0cc72410ce5d65e2df46e8b96440d92 Mon Sep 17 00:00:00 2001 From: Masamichi Takagi Date: Wed, 17 Aug 2016 14:28:41 +0900 Subject: [PATCH] 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 --- arch/x86/tools/mcreboot-smp-x86.sh.in | 74 ++++++++++++++------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/arch/x86/tools/mcreboot-smp-x86.sh.in b/arch/x86/tools/mcreboot-smp-x86.sh.in index f1f6e985..4f2da749 100644 --- a/arch/x86/tools/mcreboot-smp-x86.sh.in +++ b/arch/x86/tools/mcreboot-smp-x86.sh.in @@ -24,19 +24,23 @@ cpus="" INTERVAL=1 LOGMODE=0 -while getopts :i:k:c:m: OPT +chown_option=`logname` + +while getopts :i:k:c:m:o: OPT do case ${OPT} in + o) chown_option=${OPTARG} + ;; i) INTERVAL=${OPTARG} expr "${INTERVAL}" + 1 > /dev/null 2>&1 if [ $? -ge 2 ] then - echo "invalid -i value" + echo "invalid -i value" >&2 exit 1 fi if [ ${INTERVAL} -le 0 ] then - echo "invalid -i value" + echo "invalid -i value" >&2 exit 1 fi ;; @@ -44,12 +48,12 @@ do expr "${LOGMODE}" + 1 > /dev/null 2>&1 if [ $? -ge 2 ] then - echo "invalid -k value" + echo "invalid -k value" >&2 exit 1 fi if [ ${LOGMODE} -lt 0 -o ${LOGMODE} -gt 2 ] then - echo "invalid -k value" + echo "invalid -k value" >&2 exit 1 fi ;; @@ -57,7 +61,7 @@ do ;; m) mem=${OPTARG} ;; - *) echo "invalid option -${OPT}" + *) echo "invalid option -${OPT}" >&2 exit 1 esac done @@ -84,7 +88,7 @@ if [ "$cpus" == "" ]; then # Use the second half of the cores 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'` - 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 # 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`" != "" ]; then umount -l /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 # Load IHK if not loaded 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 # Load IHK-SMP if not loaded and reserve CPUs and memory @@ -113,61 +117,61 @@ if [ "`lsmod | grep ihk_smp_x86`" == "" ]; then break fi done - if [ "$ihk_irq" == "" ]; then echo "error: no IRQ available"; 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"; exit; fi; - if ! ${SBINDIR}/ihkconfig 0 reserve cpu ${cpus}; then echo "error: reserving CPUs"; exit; fi - if ! ${SBINDIR}/ihkconfig 0 reserve mem ${mem}; then echo "error: reserving memory"; 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" >&2; exit 1; 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" >&2; exit 1; fi # If loaded, but no resources allocated, get CPUs and memory 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` 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 - 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` 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 # Load mcctrl if not loaded 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 # Check for existing OS instance and destroy if [ -c /dev/mcos0 ]; then # 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` - 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` - 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 # 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` - 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` fi -if ! ${SBINDIR}/ihkconfig 0 create; then echo "error: create"; exit; fi -if ! ${SBINDIR}/ihkosctl 0 assign cpu ${cpus}; then echo "error: assign CPUs"; exit; fi -if ! ${SBINDIR}/ihkosctl 0 assign mem ${mem}; then echo "error: assign memory"; exit; fi -if ! ${SBINDIR}/ihkosctl 0 load ${KERNDIR}/mckernel.img; then echo "error: loading kernel image"; exit; fi -if ! ${SBINDIR}/ihkosctl 0 kargs "hidos ksyslogd=${LOGMODE}"; then echo "error: setting kernel arguments"; exit; fi -if ! ${SBINDIR}/ihkosctl 0 boot; then echo "error: booting"; exit; fi -if ! chown `logname` /dev/mcd* /dev/mcos*; then echo "error: chowning device files"; 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" >&2; exit 1; 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" >&2; exit 1; 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" >&2; exit 1; 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 [ ! -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 ! mount --bind /proc /tmp/mcos/linux_proc; then echo "error: mount /tmp/mcos/linux_proc"; exit; fi - if ! insmod ${KMODDIR}/mcoverlay.ko; then echo "error: inserting mcoverlay.ko"; 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" >&2; exit 1; fi while [ ! -e /proc/mcos0 ] do 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_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 ! 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 while [ ! -e /sys/devices/virtual/mcos/mcos0/sys ] 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_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 ! 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 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