[lxc-devel] [lxd/master] lxd/main: Move forkzfs mntns to cgo

stgraber on Github lxc-bot at linuxcontainers.org
Wed Apr 8 02:28:20 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200407/c84d48d8/attachment.bin>
-------------- next part --------------
From e6faae922025e8c2362c418ae172c3973d7bac8f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 7 Apr 2020 22:26:58 -0400
Subject: [PATCH] lxd/main: Move forkzfs mntns to cgo
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/main_forkzfs.go | 8 +-------
 lxd/main_nsexec.go  | 9 ++++++++-
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/lxd/main_forkzfs.go b/lxd/main_forkzfs.go
index 9927259e24..3ce0e06863 100644
--- a/lxd/main_forkzfs.go
+++ b/lxd/main_forkzfs.go
@@ -51,14 +51,8 @@ func (c *cmdForkZFS) Run(cmd *cobra.Command, args []string) error {
 		return fmt.Errorf("This must be run as root")
 	}
 
-	// Unshare a clean mount namespace
-	err := unix.Unshare(unix.CLONE_NEWNS)
-	if err != nil {
-		return err
-	}
-
 	// Mark mount tree as private
-	err = unix.Mount("none", "/", "", unix.MS_REC|unix.MS_PRIVATE, "")
+	err := unix.Mount("none", "/", "", unix.MS_REC|unix.MS_PRIVATE, "")
 	if err != nil {
 		return err
 	}
diff --git a/lxd/main_nsexec.go b/lxd/main_nsexec.go
index 9568df2031..279f7f8411 100644
--- a/lxd/main_nsexec.go
+++ b/lxd/main_nsexec.go
@@ -287,6 +287,7 @@ static char *file_to_buf(char *path, ssize_t *length)
 
 __attribute__((constructor)) void init(void) {
 	__do_free char *cmdline = NULL;
+	int ret;
 
 	cmdline_buf = file_to_buf("/proc/self/cmdline", &cmdline_size);
 	if (!cmdline_buf)
@@ -317,7 +318,13 @@ __attribute__((constructor)) void init(void) {
 		forkproxy();
 	else if (strcmp(cmdline_cur, "forkuevent") == 0)
 		forkuevent();
-	else if (strncmp(cmdline_cur, "-", 1) == 0 || strcmp(cmdline_cur, "daemon") == 0)
+	else if (strcmp(cmdline_cur, "forkzfs") == 0) {
+		ret = unshare(CLONE_NEWNS);
+		if (ret < 0) {
+			fprintf(stderr, "Failed unshare of mount namespace: %s\n", strerror(errno));
+			return;
+		}
+	} else if (strncmp(cmdline_cur, "-", 1) == 0 || strcmp(cmdline_cur, "daemon") == 0)
 		checkfeature();
 }
 */


More information about the lxc-devel mailing list