[lxc-devel] [lxd/master] Handle built-in shiftfs

stgraber on Github lxc-bot at linuxcontainers.org
Wed Dec 4 18:54:32 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191204/3618be02/attachment.bin>
-------------- next part --------------
From ec93b6c088dda4bfd93587d2dd6eb0295ea58f23 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 4 Dec 2019 13:53:05 -0500
Subject: [PATCH 1/2] lxd/util: Add HasFilesystem
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/util/kernel.go | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/lxd/util/kernel.go b/lxd/util/kernel.go
index 6f75915ba1..0272dd101e 100644
--- a/lxd/util/kernel.go
+++ b/lxd/util/kernel.go
@@ -1,7 +1,10 @@
 package util
 
 import (
+	"bufio"
 	"fmt"
+	"os"
+	"strings"
 
 	"github.com/lxc/lxd/shared"
 )
@@ -16,3 +19,26 @@ func LoadModule(module string) error {
 	_, err := shared.RunCommand("modprobe", module)
 	return err
 }
+
+// HasFilesystem checks whether a given filesystem is already supported
+// by the kernel. Note that if the filesystem is a module, you may need to
+// load it first.
+func HasFilesystem(filesystem string) bool {
+	file, err := os.Open("/proc/filesystems")
+	if err != nil {
+		return false
+	}
+	defer file.Close()
+
+	scanner := bufio.NewScanner(file)
+	for scanner.Scan() {
+		fields := strings.Fields(strings.TrimSpace(scanner.Text()))
+		entry := fields[len(fields)-1]
+
+		if entry == filesystem {
+			return true
+		}
+	}
+
+	return false
+}

From 1c41bdf376ac398734580b972205f7a87a2b7d72 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 4 Dec 2019 13:53:16 -0500
Subject: [PATCH 2/2] lxd: Detect built-in shiftfs too
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #6545

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/daemon.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/daemon.go b/lxd/daemon.go
index 0e58df8b5d..c5416d7dfc 100644
--- a/lxd/daemon.go
+++ b/lxd/daemon.go
@@ -620,7 +620,7 @@ func (d *Daemon) init() error {
 		logger.Infof(" - unprivileged file capabilities: no")
 	}
 
-	if util.LoadModule("shiftfs") == nil {
+	if util.HasFilesystem("shiftfs") || util.LoadModule("shiftfs") == nil {
 		d.os.Shiftfs = true
 		logger.Infof(" - shiftfs support: yes")
 	} else {


More information about the lxc-devel mailing list