2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-04-08 13:37:38 -04:00
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-04-08 13:37:38 -04:00
|
|
|
|
2021-10-04 12:01:52 -04:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/minio/minio/internal/logger"
|
|
|
|
)
|
2021-02-17 18:34:42 -05:00
|
|
|
|
2016-05-28 18:13:15 -04:00
|
|
|
// errUnexpected - unexpected error, requires manual intervention.
|
2020-08-03 21:17:48 -04:00
|
|
|
var errUnexpected = StorageErr("unexpected error, please report this issue at https://github.com/minio/minio/issues")
|
2016-05-28 18:13:15 -04:00
|
|
|
|
2016-05-20 05:22:22 -04:00
|
|
|
// errCorruptedFormat - corrupted backend format.
|
2022-08-04 19:10:08 -04:00
|
|
|
var errCorruptedFormat = StorageErr("corrupted backend format, specified drive mount has unexpected previous content")
|
2016-05-20 05:22:22 -04:00
|
|
|
|
|
|
|
// errUnformattedDisk - unformatted disk found.
|
2022-08-04 19:10:08 -04:00
|
|
|
var errUnformattedDisk = StorageErr("unformatted drive found")
|
2016-05-20 05:22:22 -04:00
|
|
|
|
2020-10-24 16:23:08 -04:00
|
|
|
// errInconsistentDisk - inconsistent disk found.
|
2022-08-04 19:10:08 -04:00
|
|
|
var errInconsistentDisk = StorageErr("inconsistent drive found")
|
2020-10-24 16:23:08 -04:00
|
|
|
|
2020-05-07 19:12:16 -04:00
|
|
|
// errUnsupporteDisk - when disk does not support O_DIRECT flag.
|
2022-08-04 19:10:08 -04:00
|
|
|
var errUnsupportedDisk = StorageErr("drive does not support O_DIRECT")
|
2020-05-07 19:12:16 -04:00
|
|
|
|
2016-04-19 05:42:10 -04:00
|
|
|
// errDiskFull - cannot create volume or files when disk is full.
|
2022-08-04 19:10:08 -04:00
|
|
|
var errDiskFull = StorageErr("drive path full")
|
2016-04-08 13:37:38 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// errDiskNotDir - cannot use storage disk if its not a directory
|
2022-08-04 19:10:08 -04:00
|
|
|
var errDiskNotDir = StorageErr("drive is not directory or mountpoint")
|
2020-06-12 23:04:01 -04:00
|
|
|
|
2017-08-11 14:38:46 -04:00
|
|
|
// errDiskNotFound - cannot find the underlying configured disk anymore.
|
2022-08-04 19:10:08 -04:00
|
|
|
var errDiskNotFound = StorageErr("drive not found")
|
2016-05-09 21:57:39 -04:00
|
|
|
|
2016-11-20 19:57:12 -05:00
|
|
|
// errFaultyRemoteDisk - remote disk is faulty.
|
2022-08-04 19:10:08 -04:00
|
|
|
var errFaultyRemoteDisk = StorageErr("remote drive is faulty")
|
2016-11-20 19:57:12 -05:00
|
|
|
|
|
|
|
// errFaultyDisk - disk is faulty.
|
2022-08-04 19:10:08 -04:00
|
|
|
var errFaultyDisk = StorageErr("drive is faulty")
|
2016-11-20 19:57:12 -05:00
|
|
|
|
2016-07-02 04:59:28 -04:00
|
|
|
// errDiskAccessDenied - we don't have write permissions on disk.
|
2022-08-04 19:10:08 -04:00
|
|
|
var errDiskAccessDenied = StorageErr("drive access denied")
|
2016-07-02 04:59:28 -04:00
|
|
|
|
2016-04-08 13:37:38 -04:00
|
|
|
// errFileNotFound - cannot find the file.
|
2020-01-14 21:45:17 -05:00
|
|
|
var errFileNotFound = StorageErr("file not found")
|
2016-04-08 13:37:38 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// errFileNotFound - cannot find requested file version.
|
|
|
|
var errFileVersionNotFound = StorageErr("file version not found")
|
|
|
|
|
2019-05-02 10:09:57 -04:00
|
|
|
// errTooManyOpenFiles - too many open files.
|
2020-09-28 22:39:32 -04:00
|
|
|
var errTooManyOpenFiles = StorageErr("too many open files, please increase 'ulimit -n'")
|
2019-05-02 10:09:57 -04:00
|
|
|
|
2016-05-11 15:55:02 -04:00
|
|
|
// errFileNameTooLong - given file name is too long than supported length.
|
2020-01-14 21:45:17 -05:00
|
|
|
var errFileNameTooLong = StorageErr("file name too long")
|
2016-05-11 15:55:02 -04:00
|
|
|
|
2022-09-07 10:25:39 -04:00
|
|
|
// errFileNeedsHealing - given file name needs to heal.
|
|
|
|
var errFileNeedsHealing = StorageErr("file name needs healing")
|
|
|
|
|
2016-04-08 13:37:38 -04:00
|
|
|
// errVolumeExists - cannot create same volume again.
|
2020-01-14 21:45:17 -05:00
|
|
|
var errVolumeExists = StorageErr("volume already exists")
|
2016-04-08 13:37:38 -04:00
|
|
|
|
2016-04-24 03:36:00 -04:00
|
|
|
// errIsNotRegular - not of regular file type.
|
2020-01-14 21:45:17 -05:00
|
|
|
var errIsNotRegular = StorageErr("not of regular file type")
|
2016-04-08 13:37:38 -04:00
|
|
|
|
2021-01-02 15:01:29 -05:00
|
|
|
// errPathNotFound - cannot find the path.
|
|
|
|
var errPathNotFound = StorageErr("path not found")
|
|
|
|
|
2016-04-08 13:37:38 -04:00
|
|
|
// errVolumeNotFound - cannot find the volume.
|
2020-01-14 21:45:17 -05:00
|
|
|
var errVolumeNotFound = StorageErr("volume not found")
|
2016-04-13 14:32:47 -04:00
|
|
|
|
2016-04-16 15:48:41 -04:00
|
|
|
// errVolumeNotEmpty - volume not empty.
|
2020-01-14 21:45:17 -05:00
|
|
|
var errVolumeNotEmpty = StorageErr("volume is not empty")
|
2016-04-16 15:48:41 -04:00
|
|
|
|
2016-06-02 19:34:15 -04:00
|
|
|
// errVolumeAccessDenied - cannot access volume, insufficient permissions.
|
2020-01-14 21:45:17 -05:00
|
|
|
var errVolumeAccessDenied = StorageErr("volume access denied")
|
2016-04-13 14:32:47 -04:00
|
|
|
|
2019-03-20 16:06:53 -04:00
|
|
|
// errFileAccessDenied - cannot access file, insufficient permissions.
|
2020-01-14 21:45:17 -05:00
|
|
|
var errFileAccessDenied = StorageErr("file access denied")
|
2017-05-16 17:21:52 -04:00
|
|
|
|
2019-10-01 16:12:15 -04:00
|
|
|
// errFileCorrupt - file has an unexpected size, or is not readable
|
2020-01-14 21:45:17 -05:00
|
|
|
var errFileCorrupt = StorageErr("file is corrupted")
|
2019-07-12 19:29:44 -04:00
|
|
|
|
2017-05-16 17:21:52 -04:00
|
|
|
// errBitrotHashAlgoInvalid - the algo for bit-rot hash
|
|
|
|
// verification is empty or invalid.
|
2020-01-14 21:45:17 -05:00
|
|
|
var errBitrotHashAlgoInvalid = StorageErr("bit-rot hash algorithm is invalid")
|
2017-05-16 17:21:52 -04:00
|
|
|
|
2017-08-15 18:10:50 -04:00
|
|
|
// errCrossDeviceLink - rename across devices not allowed.
|
2020-01-14 21:45:17 -05:00
|
|
|
var errCrossDeviceLink = StorageErr("Rename across devices not allowed, please fix your backend configuration")
|
2017-08-15 18:10:50 -04:00
|
|
|
|
2018-08-06 18:14:08 -04:00
|
|
|
// errLessData - returned when less data available than what was requested.
|
2020-01-14 21:45:17 -05:00
|
|
|
var errLessData = StorageErr("less data available than what was requested")
|
2018-08-06 18:14:08 -04:00
|
|
|
|
2019-01-17 07:58:18 -05:00
|
|
|
// errMoreData = returned when more data was sent by the caller than what it was supposed to.
|
2020-01-14 21:45:17 -05:00
|
|
|
var errMoreData = StorageErr("more data was sent than what was advertised")
|
2019-01-17 07:58:18 -05:00
|
|
|
|
2021-02-17 18:34:42 -05:00
|
|
|
// indicates readDirFn to return without further applying the fn()
|
|
|
|
var errDoneForNow = errors.New("done for now")
|
|
|
|
|
|
|
|
// errSkipFile returned by the fn() for readDirFn() when it needs
|
|
|
|
// to proceed to next entry.
|
|
|
|
var errSkipFile = errors.New("skip this file")
|
|
|
|
|
2022-05-30 13:58:37 -04:00
|
|
|
// errXLBackend XL drive mode requires fresh deployment.
|
2022-08-04 19:10:08 -04:00
|
|
|
var errXLBackend = errors.New("XL backend requires fresh drive")
|
2022-05-30 13:58:37 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// StorageErr represents error generated by xlStorage call.
|
2020-01-14 21:45:17 -05:00
|
|
|
type StorageErr string
|
2017-05-16 17:21:52 -04:00
|
|
|
|
2020-01-14 21:45:17 -05:00
|
|
|
func (h StorageErr) Error() string {
|
2019-10-01 16:12:15 -04:00
|
|
|
return string(h)
|
2017-05-16 17:21:52 -04:00
|
|
|
}
|
2017-11-25 14:58:29 -05:00
|
|
|
|
|
|
|
// Collection of basic errors.
|
|
|
|
var baseErrs = []error{
|
|
|
|
errDiskNotFound,
|
|
|
|
errFaultyDisk,
|
|
|
|
errFaultyRemoteDisk,
|
|
|
|
}
|
|
|
|
|
|
|
|
var baseIgnoredErrs = baseErrs
|
2020-06-12 23:04:01 -04:00
|
|
|
|
|
|
|
// Is a one place function which converts all os.PathError
|
|
|
|
// into a more FS object layer friendly form, converts
|
|
|
|
// known errors into their typed form for top level
|
|
|
|
// interpretation.
|
|
|
|
func osErrToFileErr(err error) error {
|
|
|
|
if err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2020-11-23 11:36:49 -05:00
|
|
|
if osIsNotExist(err) {
|
2020-06-12 23:04:01 -04:00
|
|
|
return errFileNotFound
|
|
|
|
}
|
2020-11-23 11:36:49 -05:00
|
|
|
if osIsPermission(err) {
|
2020-06-12 23:04:01 -04:00
|
|
|
return errFileAccessDenied
|
|
|
|
}
|
2021-02-22 04:36:17 -05:00
|
|
|
if isSysErrNotDir(err) || isSysErrIsDir(err) {
|
2020-06-12 23:04:01 -04:00
|
|
|
return errFileNotFound
|
|
|
|
}
|
|
|
|
if isSysErrPathNotFound(err) {
|
|
|
|
return errFileNotFound
|
|
|
|
}
|
|
|
|
if isSysErrTooManyFiles(err) {
|
|
|
|
return errTooManyOpenFiles
|
|
|
|
}
|
|
|
|
if isSysErrHandleInvalid(err) {
|
|
|
|
return errFileNotFound
|
|
|
|
}
|
2020-08-04 15:09:41 -04:00
|
|
|
if isSysErrIO(err) {
|
|
|
|
return errFaultyDisk
|
|
|
|
}
|
|
|
|
if isSysErrInvalidArg(err) {
|
2021-10-04 12:01:52 -04:00
|
|
|
logger.LogIf(context.Background(), err)
|
2021-09-30 14:53:01 -04:00
|
|
|
// For some odd calls with O_DIRECT reads
|
|
|
|
// filesystems can return EINVAL, handle
|
|
|
|
// these as FileNotFound instead.
|
|
|
|
return errFileNotFound
|
2020-08-04 15:09:41 -04:00
|
|
|
}
|
|
|
|
if isSysErrNoSpace(err) {
|
|
|
|
return errDiskFull
|
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
return err
|
|
|
|
}
|