From f13cfcb83e931ed6cabdabee588bbaf308e7952b Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 29 Jul 2023 15:17:56 -0700 Subject: [PATCH] allow disabling O_DIRECT for write ops (#17751) on really slow systems, O_DIRECT simply kills the drives allow for a way to disable them. --- cmd/xl-storage.go | 23 +++++++++++++---------- internal/config/api/help.go | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/cmd/xl-storage.go b/cmd/xl-storage.go index f81b560d3..85634eef4 100644 --- a/cmd/xl-storage.go +++ b/cmd/xl-storage.go @@ -284,16 +284,18 @@ func newXLStorage(ep Endpoint, cleanUp bool) (s *xlStorage, err error) { s.formatLegacy = format.Erasure.DistributionAlgo == formatErasureVersionV2DistributionAlgoV1 } - // Return an error if ODirect is not supported - // unless it is a single erasure disk mode - if err := s.checkODirectDiskSupport(); err == nil { - s.oDirect = true - } else { - // Allow if unsupported platform or single disk. - if errors.Is(err, errUnsupportedDisk) && globalIsErasureSD || !disk.ODirectPlatform { - s.oDirect = false + if !globalAPIConfig.isDisableODirect() { + // Return an error if ODirect is not supported + // unless it is a single erasure disk mode + if err := s.checkODirectDiskSupport(); err == nil { + s.oDirect = true } else { - return s, err + // Allow if unsupported platform or single disk. + if errors.Is(err, errUnsupportedDisk) && globalIsErasureSD || !disk.ODirectPlatform { + s.oDirect = false + } else { + return s, err + } } } @@ -1896,7 +1898,8 @@ func (s *xlStorage) writeAllDirect(ctx context.Context, filePath string, fileSiz return osErrToFileErr(err) } - odirectEnabled := s.oDirect + odirectEnabled := !globalAPIConfig.isDisableODirect() && s.oDirect + var w *os.File if odirectEnabled { w, err = OpenFileDirectIO(filePath, flags, 0o666) diff --git a/internal/config/api/help.go b/internal/config/api/help.go index ea4a408cb..c347884cc 100644 --- a/internal/config/api/help.go +++ b/internal/config/api/help.go @@ -94,7 +94,7 @@ var ( }, config.HelpKV{ Key: apiDisableODirect, - Description: "set to disable O_DIRECT for reads under special conditions. NOTE: it is not recommended to disable O_DIRECT without prior testing" + defaultHelpPostfix(apiDisableODirect), + Description: "set to disable O_DIRECT for read and writes under special conditions. NOTE: it is not recommended to disable O_DIRECT without prior testing" + defaultHelpPostfix(apiDisableODirect), Optional: true, Type: "boolean", },