From d0ae69087c46a7f863ccde2f453804e0169a570b Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 26 May 2020 09:32:33 -0700 Subject: [PATCH] fix: add proper errors for disks with preexisting content (#9703) --- cmd/config/errors.go | 6 ++++++ cmd/format-xl.go | 14 ++++++++------ cmd/prepare-storage.go | 3 ++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/cmd/config/errors.go b/cmd/config/errors.go index 6ae509114..7b6428e78 100644 --- a/cmd/config/errors.go +++ b/cmd/config/errors.go @@ -181,6 +181,12 @@ Example 1: "", ) + ErrCorruptedBackend = newErrFn( + "Unable to use the specified backend, pre-existing content detected", + "Please ensure your disk mount does not have any pre-existing content", + "", + ) + ErrUnableToWriteInBackend = newErrFn( "Unable to write to the backend", "Please ensure MinIO binary has write permissions for the backend", diff --git a/cmd/format-xl.go b/cmd/format-xl.go index 565f647e2..8d7ad9f24 100644 --- a/cmd/format-xl.go +++ b/cmd/format-xl.go @@ -27,6 +27,7 @@ import ( "sync" humanize "github.com/dustin/go-humanize" + "github.com/minio/minio/cmd/config" "github.com/minio/minio/cmd/config/storageclass" "github.com/minio/minio/cmd/logger" "github.com/minio/minio/pkg/color" @@ -379,11 +380,12 @@ func saveFormatXL(disk StorageAPI, format interface{}, diskID string) error { } var ignoredHiddenDirectories = map[string]struct{}{ - minioMetaBucket: {}, - ".snapshot": {}, - "lost+found": {}, - "$RECYCLE.BIN": {}, - "System Volume Information": {}, + minioMetaBucket: {}, // metabucket '.minio.sys' + ".minio": {}, // users may choose to double down the backend as the config folder for certs + ".snapshot": {}, // .snapshot for ignoring NetApp based persistent volumes WAFL snapshot + "lost+found": {}, // 'lost+found' directory default on ext4 filesystems + "$RECYCLE.BIN": {}, // windows specific directory for each drive (hidden) + "System Volume Information": {}, // windows specific directory for each drive (hidden) } func isHiddenDirectories(vols ...VolInfo) bool { @@ -499,7 +501,7 @@ func formatXLFixDeploymentID(endpoints Endpoints, storageDisks []StorageAPI, ref formats, sErrs := loadFormatXLAll(storageDisks, false) for i, sErr := range sErrs { if _, ok := formatCriticalErrors[sErr]; ok { - return fmt.Errorf("Disk %s: %w", endpoints[i], sErr) + return config.ErrCorruptedBackend(err).Hint(fmt.Sprintf("Clear any pre-existing content on %s", endpoints[i])) } } diff --git a/cmd/prepare-storage.go b/cmd/prepare-storage.go index 6f8fa8c06..9c813c96e 100644 --- a/cmd/prepare-storage.go +++ b/cmd/prepare-storage.go @@ -27,6 +27,7 @@ import ( "time" "github.com/dustin/go-humanize" + "github.com/minio/minio/cmd/config" xhttp "github.com/minio/minio/cmd/http" "github.com/minio/minio/cmd/logger" "github.com/minio/minio/cmd/rest" @@ -227,7 +228,7 @@ func connectLoadInitFormats(retryCount int, firstDisk bool, endpoints Endpoints, // Check if we have for i, sErr := range sErrs { if _, ok := formatCriticalErrors[sErr]; ok { - return nil, nil, fmt.Errorf("Disk %s: %w", endpoints[i], sErr) + return nil, nil, config.ErrCorruptedBackend(err).Hint(fmt.Sprintf("Clear any pre-existing content on %s", endpoints[i])) } // not critical error but still print the error, nonetheless, which is perhaps unhandled if sErr != errUnformattedDisk && sErr != errDiskNotFound && retryCount >= 5 {