From 6885c72f328bfc8264b0763cbd62d49a55ed8935 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Fri, 8 May 2020 20:07:51 +0100 Subject: [PATCH] disable check for DirectIO in standalone FS mode (#9558) --- cmd/fs-v1.go | 5 +---- cmd/posix.go | 13 ++++++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cmd/fs-v1.go b/cmd/fs-v1.go index 9bafc37a0..5337b9fff 100644 --- a/cmd/fs-v1.go +++ b/cmd/fs-v1.go @@ -129,12 +129,9 @@ func NewFSObjectLayer(fsPath string) (ObjectLayer, error) { } var err error - if fsPath, err = getValidPath(fsPath); err != nil { + if fsPath, err = getValidPath(fsPath, false); err != nil { if err == errMinDiskSize { return nil, config.ErrUnableToWriteInBackend(err).Hint(err.Error()) - } else if err == errUnsupportedDisk { - hint := fmt.Sprintf("'%s' does not support O_DIRECT flags, refusing to use", fsPath) - return nil, config.ErrUnsupportedBackend(err).Hint(hint) } // Show a descriptive error with a hint about how to fix it. diff --git a/cmd/posix.go b/cmd/posix.go index 3c91cd72b..aee1999ba 100644 --- a/cmd/posix.go +++ b/cmd/posix.go @@ -140,7 +140,7 @@ func checkPathLength(pathName string) error { return nil } -func getValidPath(path string) (string, error) { +func getValidPath(path string, requireDirectIO bool) (string, error) { if path == "" { return path, errInvalidArgument } @@ -181,9 +181,16 @@ func getValidPath(path string) (string, error) { fn := pathJoin(path, ".writable-check-"+hex.EncodeToString(rnd[:])+".tmp") defer os.Remove(fn) + var file *os.File + + if requireDirectIO { + file, err = disk.OpenFileDirectIO(fn, os.O_CREATE|os.O_EXCL, 0666) + } else { + file, err = os.OpenFile(fn, os.O_CREATE|os.O_EXCL, 0666) + } + // open file in direct I/O and use default umask, this also verifies // if direct i/o failed. - file, err := disk.OpenFileDirectIO(fn, os.O_CREATE|os.O_EXCL, 0666) if err != nil { if isSysErrInvalidArg(err) { return path, errUnsupportedDisk @@ -222,7 +229,7 @@ func isDirEmpty(dirname string) bool { // Initialize a new storage disk. func newPosix(path string) (*posix, error) { var err error - if path, err = getValidPath(path); err != nil { + if path, err = getValidPath(path, true); err != nil { return nil, err } _, err = os.Stat(path)