[lxc-devel] [lxd/master] mounting: only block devices hold filesystems

hallyn on Github lxc-bot at linuxcontainers.org
Wed Mar 9 00:56:32 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 673 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160309/092bcc1e/attachment.bin>
-------------- next part --------------
From f4fbb390d510e3c245544b04e8e7402bad80dfde Mon Sep 17 00:00:00 2001
From: Serge Hallyn <serge.hallyn at ubuntu.com>
Date: Tue, 8 Mar 2016 16:54:44 -0800
Subject: [PATCH] mounting: only block devices hold filesystems

If we lxc config device add x1 disk type=disk source=/dev/null, lxd
should not try to detect the filesystem (and fail when it can't).

The function as it stands woudl've made sense, but every caller of
it really wants to know whether it's a block device, so rename the
fn and have it return false for chardevs.

Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
 lxd/container_lxc.go | 4 ++--
 lxd/devices.go       | 9 ++-------
 2 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 9cd2f32..67d5350 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -758,7 +758,7 @@ func (c *containerLXC) initLXC() error {
 			// Various option checks
 			isOptional := m["optional"] == "1" || m["optional"] == "true"
 			isReadOnly := m["readonly"] == "1" || m["readonly"] == "true"
-			isFile := !shared.IsDir(srcPath) && !deviceIsDevice(srcPath)
+			isFile := !shared.IsDir(srcPath) && !fileIsBlockdev(srcPath)
 
 			// Deal with a rootfs
 			if tgtPath == "" {
@@ -3611,7 +3611,7 @@ func (c *containerLXC) createDiskDevice(name string, m shared.Device) (string, e
 	// Check if read-only
 	isOptional := m["optional"] == "1" || m["optional"] == "true"
 	isReadOnly := m["readonly"] == "1" || m["readonly"] == "true"
-	isFile := !shared.IsDir(srcPath) && !deviceIsDevice(srcPath)
+	isFile := !shared.IsDir(srcPath) && !fileIsBlockdev(srcPath)
 
 	// Check if the source exists
 	if !shared.PathExists(srcPath) {
diff --git a/lxd/devices.go b/lxd/devices.go
index 004b319..9c50435 100644
--- a/lxd/devices.go
+++ b/lxd/devices.go
@@ -431,7 +431,7 @@ func deviceTaskSchedulerTrigger(srcType string, srcName string, srcStatus string
 	}()
 }
 
-func deviceIsDevice(path string) bool {
+func fileIsBlockdev(path string) bool {
 	// Get a stat struct from the provided path
 	stat := syscall.Stat_t{}
 	err := syscall.Stat(path, &stat)
@@ -439,11 +439,6 @@ func deviceIsDevice(path string) bool {
 		return false
 	}
 
-	// Check if it's a character device
-	if stat.Mode&syscall.S_IFMT == syscall.S_IFCHR {
-		return true
-	}
-
 	// Check if it's a block device
 	if stat.Mode&syscall.S_IFMT == syscall.S_IFBLK {
 		return true
@@ -532,7 +527,7 @@ func deviceMountDisk(srcPath string, dstPath string, readonly bool) error {
 
 	// Detect the filesystem
 	fstype := "none"
-	if deviceIsDevice(srcPath) {
+	if fileIsBlockdev(srcPath) {
 		fstype, err = shared.BlockFsDetect(srcPath)
 		if err != nil {
 			return err


More information about the lxc-devel mailing list