From 6cc55dd65b363fe520c2ab29a9303f79afd4cadb Mon Sep 17 00:00:00 2001 From: Vivek Goyal Date: Wed, 7 Sep 2016 14:03:01 -0400 Subject: [PATCH] devmapper: Fail to start container if xfs_nospace_max_retries can't be enforced We just introduced a new tunable dm.xfs_nospace_max_retries. But this tunable will work only on new kernels where xfs supports this feature. On older kernels xfs does not allow tuning this behavior. There are two issues. First one is that if xfsSetNospaceRetries() fails, it returns error but leaves the device activated and mounted. We should be unmounting the device and deactivate it before returning. Second issue is, if docker is started on older kernel, with dm.xfs_nospace_max_retries specified, then docker will silently ignore the fact that /sys file to tweak this behavior is not present and will continue. But I think it might be better to fail container creation/start if kernel does not support this feature. This patch fixes it. After this patch, user will get an error like following when container is run. # docker run -ti fedora bash docker: Error response from daemon: devmapper: user specified daemon option dm.xfs_nospace_max_retries but it does not seem to be supported on this system :open /sys/fs/xfs/dm-5/error/metadata/ENOSPC/max_retries: no such file or directory. Signed-off-by: Vivek Goyal --- daemon/graphdriver/devmapper/deviceset.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/daemon/graphdriver/devmapper/deviceset.go b/daemon/graphdriver/devmapper/deviceset.go index 4206471904..684aed48e1 100644 --- a/daemon/graphdriver/devmapper/deviceset.go +++ b/daemon/graphdriver/devmapper/deviceset.go @@ -2325,11 +2325,7 @@ func (devices *DeviceSet) xfsSetNospaceRetries(info *devInfo) error { filePath := "/sys/fs/xfs/" + dmDeviceName + "/error/metadata/ENOSPC/max_retries" maxRetriesFile, err := os.OpenFile(filePath, os.O_WRONLY, 0) if err != nil { - // Older kernels don't have this feature/file - if os.IsNotExist(err) { - return nil - } - return fmt.Errorf("devmapper: Failed to open file %v:%v", filePath, err) + return fmt.Errorf("devmapper: user specified daemon option dm.xfs_nospace_max_retries but it does not seem to be supported on this system :%v", err) } defer maxRetriesFile.Close() @@ -2383,6 +2379,8 @@ func (devices *DeviceSet) MountDevice(hash, path, mountLabel string) error { if fstype == "xfs" && devices.xfsNospaceRetries != "" { if err := devices.xfsSetNospaceRetries(info); err != nil { + syscall.Unmount(path, syscall.MNT_DETACH) + devices.deactivateDevice(info) return err } }