[lxc-devel] [lxd/master] Fix handling of devices with minor>255

ktossell on Github lxc-bot at linuxcontainers.org
Wed Apr 12 16:04:57 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 715 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170412/0493f731/attachment.bin>
-------------- next part --------------
From f893fdc620c6ca6f0ff33be730ea8f65fb64ae9d Mon Sep 17 00:00:00 2001
From: Ken Tossell <ktossell at magicleap.com>
Date: Wed, 12 Apr 2017 15:57:06 +0000
Subject: [PATCH] Fix handling of devices with minor>255

Device minor numbers are 12-bit, and the kernel expects
combined major-minor device IDs to be passed as a 32-bit
integer with the following components, from MSB to LSB:

 * 12 zero bits
 * the 4 upper bits of the minor number
 * all 8 bits of the major number
 * the 8 lower bits of the minor number

Currently LXD writes (major | minor >> 8) in the bits where
the kernel expects to find the major number.
---
 lxd/container_lxc.go | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 37ec833..c5e7c0e 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -5350,7 +5350,8 @@ func (c *containerLXC) createUnixDevice(m types.Device) ([]string, error) {
 
 	// Create the new entry
 	if !runningInUserns {
-		if err := syscall.Mknod(devPath, uint32(mode), minor|(major<<8)); err != nil {
+		encoded_device_number := (minor & 0xff) | (major << 8) | ((minor & ^0xff) << 12)
+		if err := syscall.Mknod(devPath, uint32(mode), encoded_device_number); err != nil {
 			return nil, fmt.Errorf("Failed to create device %s for %s: %s", devPath, m["path"], err)
 		}
 


More information about the lxc-devel mailing list