github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/cmd/storage-errors.go (about)

     1  // Copyright (c) 2015-2023 MinIO, Inc.
     2  //
     3  // This file is part of MinIO Object Storage stack
     4  //
     5  // This program is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU Affero General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // This program is distributed in the hope that it will be useful
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU Affero General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Affero General Public License
    16  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17  
    18  package cmd
    19  
    20  import (
    21  	"context"
    22  	"errors"
    23  
    24  	"github.com/minio/minio/internal/logger"
    25  )
    26  
    27  // errMaxVersionsExceeded return error beyond 10000 (default) versions per object
    28  var errMaxVersionsExceeded = StorageErr("maximum versions exceeded, please delete few versions to proceed")
    29  
    30  // errUnexpected - unexpected error, requires manual intervention.
    31  var errUnexpected = StorageErr("unexpected error, please report this issue at https://github.com/minio/minio/issues")
    32  
    33  // errCorruptedFormat - corrupted format.
    34  var errCorruptedFormat = StorageErr("corrupted format")
    35  
    36  // errCorruptedBackend - corrupted backend.
    37  var errCorruptedBackend = StorageErr("corrupted backend")
    38  
    39  // errUnformattedDisk - unformatted disk found.
    40  var errUnformattedDisk = StorageErr("unformatted drive found")
    41  
    42  // errInconsistentDisk - inconsistent disk found.
    43  var errInconsistentDisk = StorageErr("inconsistent drive found")
    44  
    45  // errUnsupporteDisk - when disk does not support O_DIRECT flag.
    46  var errUnsupportedDisk = StorageErr("drive does not support O_DIRECT")
    47  
    48  // errDiskFull - cannot create volume or files when disk is full.
    49  var errDiskFull = StorageErr("drive path full")
    50  
    51  // errDiskNotDir - cannot use storage disk if its not a directory
    52  var errDiskNotDir = StorageErr("drive is not directory or mountpoint")
    53  
    54  // errDiskNotFound - cannot find the underlying configured disk anymore.
    55  var errDiskNotFound = StorageErr("drive not found")
    56  
    57  // errDiskOngoingReq - indicates if the disk has an on-going request in progress.
    58  var errDiskOngoingReq = StorageErr("drive still did not complete the request")
    59  
    60  // errDriveIsRoot - cannot use the disk since its a root disk.
    61  var errDriveIsRoot = StorageErr("drive is part of root drive, will not be used")
    62  
    63  // errFaultyRemoteDisk - remote disk is faulty.
    64  var errFaultyRemoteDisk = StorageErr("remote drive is faulty")
    65  
    66  // errFaultyDisk - disk is faulty.
    67  var errFaultyDisk = StorageErr("drive is faulty")
    68  
    69  // errDiskAccessDenied - we don't have write permissions on disk.
    70  var errDiskAccessDenied = StorageErr("drive access denied")
    71  
    72  // errFileNotFound - cannot find the file.
    73  var errFileNotFound = StorageErr("file not found")
    74  
    75  // errFileNotFound - cannot find requested file version.
    76  var errFileVersionNotFound = StorageErr("file version not found")
    77  
    78  // errTooManyOpenFiles - too many open files.
    79  var errTooManyOpenFiles = StorageErr("too many open files, please increase 'ulimit -n'")
    80  
    81  // errFileNameTooLong - given file name is too long than supported length.
    82  var errFileNameTooLong = StorageErr("file name too long")
    83  
    84  // errVolumeExists - cannot create same volume again.
    85  var errVolumeExists = StorageErr("volume already exists")
    86  
    87  // errIsNotRegular - not of regular file type.
    88  var errIsNotRegular = StorageErr("not of regular file type")
    89  
    90  // errPathNotFound - cannot find the path.
    91  var errPathNotFound = StorageErr("path not found")
    92  
    93  // errVolumeNotFound - cannot find the volume.
    94  var errVolumeNotFound = StorageErr("volume not found")
    95  
    96  // errVolumeNotEmpty - volume not empty.
    97  var errVolumeNotEmpty = StorageErr("volume is not empty")
    98  
    99  // errVolumeAccessDenied - cannot access volume, insufficient permissions.
   100  var errVolumeAccessDenied = StorageErr("volume access denied")
   101  
   102  // errFileAccessDenied - cannot access file, insufficient permissions.
   103  var errFileAccessDenied = StorageErr("file access denied")
   104  
   105  // errFileCorrupt - file has an unexpected size, or is not readable
   106  var errFileCorrupt = StorageErr("file is corrupted")
   107  
   108  // errBitrotHashAlgoInvalid - the algo for bit-rot hash
   109  // verification is empty or invalid.
   110  var errBitrotHashAlgoInvalid = StorageErr("bit-rot hash algorithm is invalid")
   111  
   112  // errCrossDeviceLink - rename across devices not allowed.
   113  var errCrossDeviceLink = StorageErr("Rename across devices not allowed, please fix your backend configuration")
   114  
   115  // errLessData - returned when less data available than what was requested.
   116  var errLessData = StorageErr("less data available than what was requested")
   117  
   118  // errMoreData = returned when more data was sent by the caller than what it was supposed to.
   119  var errMoreData = StorageErr("more data was sent than what was advertised")
   120  
   121  // indicates readDirFn to return without further applying the fn()
   122  var errDoneForNow = errors.New("done for now")
   123  
   124  // errSkipFile returned by the fn() for readDirFn() when it needs
   125  // to proceed to next entry.
   126  var errSkipFile = errors.New("skip this file")
   127  
   128  var errIgnoreFileContrib = errors.New("ignore this file's contribution toward data-usage")
   129  
   130  // errXLBackend XL drive mode requires fresh deployment.
   131  var errXLBackend = errors.New("XL backend requires fresh drive")
   132  
   133  // StorageErr represents error generated by xlStorage call.
   134  type StorageErr string
   135  
   136  func (h StorageErr) Error() string {
   137  	return string(h)
   138  }
   139  
   140  // Collection of basic errors.
   141  var baseErrs = []error{
   142  	errDiskNotFound,
   143  	errFaultyDisk,
   144  	errFaultyRemoteDisk,
   145  }
   146  
   147  var baseIgnoredErrs = baseErrs
   148  
   149  // Is a one place function which converts all os.PathError
   150  // into a more FS object layer friendly form, converts
   151  // known errors into their typed form for top level
   152  // interpretation.
   153  func osErrToFileErr(err error) error {
   154  	if err == nil {
   155  		return nil
   156  	}
   157  	if osIsNotExist(err) {
   158  		return errFileNotFound
   159  	}
   160  	if osIsPermission(err) {
   161  		return errFileAccessDenied
   162  	}
   163  	if isSysErrNotDir(err) || isSysErrIsDir(err) {
   164  		return errFileNotFound
   165  	}
   166  	if isSysErrPathNotFound(err) {
   167  		return errFileNotFound
   168  	}
   169  	if isSysErrTooManyFiles(err) {
   170  		return errTooManyOpenFiles
   171  	}
   172  	if isSysErrHandleInvalid(err) {
   173  		return errFileNotFound
   174  	}
   175  	if isSysErrIO(err) {
   176  		return errFaultyDisk
   177  	}
   178  	if isSysErrInvalidArg(err) {
   179  		logger.LogIf(context.Background(), err)
   180  		// For some odd calls with O_DIRECT reads
   181  		// filesystems can return EINVAL, handle
   182  		// these as FileNotFound instead.
   183  		return errFileNotFound
   184  	}
   185  	if isSysErrNoSpace(err) {
   186  		return errDiskFull
   187  	}
   188  	return err
   189  }