From 572b1fd9be69c20a98d885e18b327031ef4f4b51 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Fri, 18 Oct 2013 11:38:21 +0200 Subject: [PATCH] devmapper: Fix major/minor extraction The way devices are mapped is a bit more complex than before. This implements the method from new_decode_dev in: https://github.com/mirrors/linux-2.6/blob/master/include/linux/kdev_t.h Which is what is needed on kernels > 2.6 --- devmapper/deviceset.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/devmapper/deviceset.go b/devmapper/deviceset.go index f9526a634d..26594c54dc 100644 --- a/devmapper/deviceset.go +++ b/devmapper/deviceset.go @@ -349,6 +349,14 @@ func (devices *DeviceSet) log(level int, file string, line int, dmError int, mes utils.Debugf("libdevmapper(%d): %s:%d (%d) %s", level, file, line, dmError, message) } +func major (device uint64) uint64 { + return (device >> 8) & 0xfff +} + +func minor (device uint64) uint64 { + return (device & 0xff) | ((device >> 12) & 0xfff00) +} + func (devices *DeviceSet) initDevmapper() error { logInit(devices) @@ -380,7 +388,7 @@ func (devices *DeviceSet) initDevmapper() error { // - Managed by docker // - The target of this device is at major and minor // - If is defined, use that file inside the device as a loopback image. Otherwise use the device itself. - devices.devicePrefix = fmt.Sprintf("docker-%d,%d-%d", sysSt.Dev >>8, sysSt.Dev & 0xff, sysSt.Ino) + devices.devicePrefix = fmt.Sprintf("docker-%d,%d-%d", major(sysSt.Dev), minor(sysSt.Dev), sysSt.Ino) utils.Debugf("Generated prefix: %s", devices.devicePrefix) // Check for the existence of the device -pool