[Virtio-fs] 回复:add no-pivot option to virtiofsd process

白宇 bekars at qq.com
Tue Oct 22 07:00:01 UTC 2019


From 278d81f5a00c35e431a0a450b6c6eb7b7edca787 Mon Sep 17 00:00:00 2001
From: bekars <baiyu10 at baidu.com>
Date: Sun, 20 Oct 2019 17:41:11 +0800
Subject: [PATCH] add no pivot_root to virtiofsd.


Signed-off-by: bekars <baiyu10 at baidu.com>
---
 configure                          | 11 +++++++++++
 contrib/virtiofsd/Makefile.objs    |  4 ++++
 contrib/virtiofsd/passthrough_ll.c |  6 ++++++
 3 files changed, 21 insertions(+)


diff --git a/configure b/configure
index 268b090..1943b4d 100755
--- a/configure
+++ b/configure
@@ -456,6 +456,7 @@ coroutine_pool=""
 debug_stack_usage="no"
 crypto_afalg="no"
 seccomp=""
+no_pivot="no"
 vvfat="yes"
 glusterfs=""
 glusterfs_xlator_opt="no"
@@ -1380,6 +1381,10 @@ for opt do
   ;;
   --disable-seccomp) seccomp="no"
   ;;
+  --enable-no-pivot) no_pivot="yes"
+  ;;
+  --disable-no-pivot) no_pivot="no"
+  ;;
   --disable-vvfat) vvfat="no"
   ;;
   --enable-vvfat) vvfat="yes"
@@ -1817,6 +1822,7 @@ disabled with --disable-FEATURE, default is enabled if available:
   lzfse           support of lzfse compression library
                   (for reading lzfse-compressed dmg images)
   seccomp         seccomp support
+  no-pivot        no pivot_root in ramfs system
   coroutine-pool  coroutine freelist (better performance)
   vvfat           Virtual VFAT backend
   glusterfs       GlusterFS backend
@@ -6443,6 +6449,7 @@ echo "QGA VSS support   $guest_agent_with_vss"
 echo "QGA w32 disk info $guest_agent_ntddscsi"
 echo "QGA MSI support   $guest_agent_msi"
 echo "seccomp support   $seccomp"
+echo "no pivot_root     $no_pivot"
 echo "coroutine backend $coroutine"
 echo "coroutine pool    $coroutine_pool"
 echo "debug stack usage $debug_stack_usage"
@@ -7037,6 +7044,10 @@ if test "$seccomp" = "yes"; then
   echo "SECCOMP_LIBS=$seccomp_libs" >> $config_host_mak
 fi
 
+if test "$no_pivot" = "yes"; then
+  echo "CONFIG_NO_PIVOT=y" >> $config_host_mak
+fi
+
 # XXX: suppress that
 if [ "$bsd" = "yes" ] ; then
   echo "CONFIG_BSD=y" >> $config_host_mak
diff --git a/contrib/virtiofsd/Makefile.objs b/contrib/virtiofsd/Makefile.objs
index 4832f3c..90a7453 100644
--- a/contrib/virtiofsd/Makefile.objs
+++ b/contrib/virtiofsd/Makefile.objs
@@ -13,3 +13,7 @@ virtiofsd-obj-y += seccomp.o
 seccomp.o-cflags := $(SECCOMP_CFLAGS)
 seccomp.o-libs := $(SECCOMP_LIBS)
 endif
+
+ifeq ($(CONFIG_NO_PIVOT),y)
+passthrough_ll.o-cflags += -DCONFIG_NO_PIVOT
+endif
diff --git a/contrib/virtiofsd/passthrough_ll.c b/contrib/virtiofsd/passthrough_ll.c
index 5bfd650..f84dcca 100644
--- a/contrib/virtiofsd/passthrough_ll.c
+++ b/contrib/virtiofsd/passthrough_ll.c
@@ -2061,7 +2061,11 @@ static void setup_pivot_root(const char *source)
 		err(1, "fchdir(newroot)");
 	}
 
+#ifdef CONFIG_NO_PIVOT
+	if (chroot(source) < 0){
+#else
 	if (syscall(__NR_pivot_root, ".", ".") < 0){
+#endif
 		err(1, "pivot_root(., .)");
 	}
 
@@ -2069,6 +2073,7 @@ static void setup_pivot_root(const char *source)
 		err(1, "fchdir(oldroot)");
 	}
 
+#ifndef CONFIG_NO_PIVOT
 	if (mount("", ".", "", MS_SLAVE | MS_REC, NULL) < 0) {
 		err(1, "mount(., MS_SLAVE | MS_REC)");
 	}
@@ -2076,6 +2081,7 @@ static void setup_pivot_root(const char *source)
 	if (umount2(".", MNT_DETACH) < 0) {
 		err(1, "umount2(., MNT_DETACH)");
 	}
+#endif
 
 	if (fchdir(newroot) < 0) {
 		err(1, "fchdir(newroot)");
-- 
2.7.0







------------------ 原始邮件 ------------------
发件人: "白宇"<bekars at qq.com>;
发送时间: 2019年10月22日(星期二) 下午2:56
收件人: "virtio-fs"<virtio-fs at redhat.com>;

主题: add no-pivot option to virtiofsd process



Virtiofsd can't be started on rootfs system (/ is rootfs filesystem), such as diskless system, because rootfs don't allow pivot_root. I commit the issue here: kata-containers/runtime#2067  for kata project. I add a no-pivot option to allow the virtiofsd daemon process to run in a rootfs system, it is turned off by default. The attached file is the patch file.


I submitted the patch to kata, they suggest me to discuss in virtiofs upstream project firstly.  https://github.com/kata-containers/packaging/pull/765


Could it be merged to the virtiofs project ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/virtio-fs/attachments/20191022/aacd57e8/attachment.htm>


More information about the Virtio-fs mailing list