From 0ce698eb1f5b8a5b85b1305ef96e65346a18a6da Mon Sep 17 00:00:00 2001 From: Yoichi Umezawa Date: Mon, 8 Feb 2016 11:36:03 +0900 Subject: [PATCH] mcexec: support for /sys mounted by mcoverlayfs --- arch/x86/tools/mcreboot-smp-x86.sh.in | 16 ++++++++++++++++ executer/user/mcexec.c | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/arch/x86/tools/mcreboot-smp-x86.sh.in b/arch/x86/tools/mcreboot-smp-x86.sh.in index 786254e2..4e1619cc 100644 --- a/arch/x86/tools/mcreboot-smp-x86.sh.in +++ b/arch/x86/tools/mcreboot-smp-x86.sh.in @@ -44,6 +44,7 @@ fi # Remove mcoverlay if loaded if [ "$enable_mcoverlay" != "" ]; then if [ "`lsmod | grep mcoverlay`" != "" ]; then + if [ "`cat /proc/mounts | grep /tmp/mcos/mcos0_sys`" != "" ]; then umount -l /tmp/mcos/mcos0_sys; fi if [ "`cat /proc/mounts | grep /tmp/mcos/mcos0_proc`" != "" ]; then umount -l /tmp/mcos/mcos0_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 @@ -123,5 +124,20 @@ if [ "$enable_mcoverlay" != "" ]; then 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 mount --make-rprivate /proc + 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 + 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 + rm -rf /tmp/mcos/mcos0_sys/devices/system/cpu/$cpuid + fi + done + for cpuid in `find /sys/bus/cpu/devices/* -maxdepth 0 -name "cpu[0123456789]*" -printf "%f "`; do + if [ ! -e "/sys/devices/virtual/mcos/mcos0/sys/bus/cpu/devices/$cpuid" ]; then + rm -rf /tmp/mcos/mcos0_sys/bus/cpu/devices/$cpuid + fi + done fi diff --git a/executer/user/mcexec.c b/executer/user/mcexec.c index b4b001b1..7f69f495 100644 --- a/executer/user/mcexec.c +++ b/executer/user/mcexec.c @@ -1304,6 +1304,7 @@ int main(int argc, char **argv) #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,0,0) __dprintf("mcoverlay enable\n"); char mcos_procdir[PATH_MAX]; + char mcos_sysdir[PATH_MAX]; error = isunshare(); if (error == 0) { @@ -1319,6 +1320,13 @@ int main(int argc, char **argv) strerror(errno)); return 1; } + + sprintf(mcos_sysdir, "/tmp/mcos/mcos%d_sys", mcosid); + if (mount(mcos_sysdir, "/sys", NULL, MS_BIND, NULL)) { + fprintf(stderr, "Error: Failed to mount. (%s)\n", + strerror(errno)); + return 1; + } } else if (error == -1) { return 1; }