Skip to content

Commit 46833ee

Browse files
committed
devmapper: show dmesg if mount fails
If mount fails, the reason might be right there in the kernel log ring buffer. Let's include it in the error message, it might be of great help. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 6b01bc5 commit 46833ee

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

daemon/graphdriver/devmapper/deviceset.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/docker/docker/daemon/graphdriver"
2222
"github.com/docker/docker/dockerversion"
2323
"github.com/docker/docker/pkg/devicemapper"
24+
"github.com/docker/docker/pkg/dmesg"
2425
"github.com/docker/docker/pkg/idtools"
2526
"github.com/docker/docker/pkg/loopback"
2627
"github.com/docker/docker/pkg/mount"
@@ -1199,7 +1200,7 @@ func (devices *DeviceSet) growFS(info *devInfo) error {
11991200
options = joinMountOptions(options, devices.mountOptions)
12001201

12011202
if err := mount.Mount(info.DevName(), fsMountPoint, devices.BaseDeviceFilesystem, options); err != nil {
1202-
return fmt.Errorf("Error mounting '%s' on '%s': %s", info.DevName(), fsMountPoint, err)
1203+
return fmt.Errorf("Error mounting '%s' on '%s': %s\n%v", info.DevName(), fsMountPoint, err, string(dmesg.Dmesg(256)))
12031204
}
12041205

12051206
defer unix.Unmount(fsMountPoint, unix.MNT_DETACH)
@@ -2390,7 +2391,7 @@ func (devices *DeviceSet) MountDevice(hash, path, mountLabel string) error {
23902391
options = joinMountOptions(options, label.FormatMountLabel("", mountLabel))
23912392

23922393
if err := mount.Mount(info.DevName(), path, fstype, options); err != nil {
2393-
return fmt.Errorf("devmapper: Error mounting '%s' on '%s': %s", info.DevName(), path, err)
2394+
return fmt.Errorf("devmapper: Error mounting '%s' on '%s': %s\n%v", info.DevName(), path, err, string(dmesg.Dmesg(256)))
23942395
}
23952396

23962397
if fstype == "xfs" && devices.xfsNospaceRetries != "" {

pkg/dmesg/dmesg_linux.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// +build linux
2+
3+
package dmesg
4+
5+
import (
6+
"unsafe"
7+
8+
"golang.org/x/sys/unix"
9+
)
10+
11+
// Dmesg returns last messages from the kernel log, up to size bytes
12+
func Dmesg(size int) []byte {
13+
t := uintptr(3) // SYSLOG_ACTION_READ_ALL
14+
b := make([]byte, size)
15+
amt, _, err := unix.Syscall(unix.SYS_SYSLOG, t, uintptr(unsafe.Pointer(&b[0])), uintptr(len(b)))
16+
if err != 0 {
17+
return []byte{}
18+
}
19+
return b[:amt]
20+
}

pkg/dmesg/dmesg_linux_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package dmesg
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestDmesg(t *testing.T) {
8+
t.Logf("dmesg output follows:\n%v", string(Dmesg(512)))
9+
}

0 commit comments

Comments
 (0)