From 4e6e8c47b5b9fb318e48a442a61c1b1af939b85e Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 8 May 2021 15:40:29 -0700 Subject: [PATCH] add root_disk threshold detection (#12259) as there is no automatic way to detect if there is a root disk mounted on / or /var for the container environments due to how the root disk information is masked inside overlay root inside container. this PR brings an environment variable to set root disk size threshold manually to detect the root disks in such situations. --- cmd/config/constants.go | 2 ++ cmd/xl-storage.go | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/cmd/config/constants.go b/cmd/config/constants.go index 856e59a6c..0538656a8 100644 --- a/cmd/config/constants.go +++ b/cmd/config/constants.go @@ -35,6 +35,8 @@ const ( EnvArgs = "MINIO_ARGS" EnvDNSWebhook = "MINIO_DNS_WEBHOOK_ENDPOINT" + EnvRootDiskThresholdSize = "MINIO_ROOTDISK_THRESHOLD_SIZE" + EnvUpdate = "MINIO_UPDATE" EnvEndpoints = "MINIO_ENDPOINTS" // legacy diff --git a/cmd/xl-storage.go b/cmd/xl-storage.go index b670e504c..f87d4da1a 100644 --- a/cmd/xl-storage.go +++ b/cmd/xl-storage.go @@ -260,6 +260,25 @@ func newXLStorage(ep Endpoint) (*xlStorage, error) { if err != nil { return nil, err } + if !rootDisk { + // If for some reason we couldn't detect the + // root disk use - MINIO_ROOTDISK_THRESHOLD_SIZE + // to figure out if the disk is root disk or not. + if rootDiskSize := env.Get(config.EnvRootDiskThresholdSize, ""); rootDiskSize != "" { + info, err := disk.GetInfo(path) + if err != nil { + return nil, err + } + size, err := humanize.ParseBytes(rootDiskSize) + if err != nil { + return nil, err + } + // size of the disk is less than the threshold or + // equal to the size of the disk at path, treat + // such disks as rootDisks and reject them. + rootDisk = info.Total <= size + } + } p := &xlStorage{ diskPath: path,