github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/cmd/storage-interface.go (about) 1 // Copyright (c) 2015-2021 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 "io" 23 "time" 24 25 "github.com/minio/madmin-go/v3" 26 xioutil "github.com/minio/minio/internal/ioutil" 27 ) 28 29 // StorageAPI interface. 30 type StorageAPI interface { 31 // Stringified version of disk. 32 String() string 33 34 // Storage operations. 35 36 // Returns true if disk is online and its valid i.e valid format.json. 37 // This has nothing to do with if the drive is hung or not responding. 38 // For that individual storage API calls will fail properly. The purpose 39 // of this function is to know if the "drive" has "format.json" or not 40 // if it has a "format.json" then is it correct "format.json" or not. 41 IsOnline() bool 42 43 // Returns the last time this disk (re)-connected 44 LastConn() time.Time 45 46 // Indicates if disk is local or not. 47 IsLocal() bool 48 49 // Returns hostname if disk is remote. 50 Hostname() string 51 52 // Returns the entire endpoint. 53 Endpoint() Endpoint 54 55 // Close the disk, mark it purposefully closed, only implemented for remote disks. 56 Close() error 57 58 // Returns the unique 'uuid' of this disk. 59 GetDiskID() (string, error) 60 61 // Set a unique 'uuid' for this disk, only used when 62 // disk is replaced and formatted. 63 SetDiskID(id string) 64 65 // Returns healing information for a newly replaced disk, 66 // returns 'nil' once healing is complete or if the disk 67 // has never been replaced. 68 Healing() *healingTracker 69 DiskInfo(ctx context.Context, opts DiskInfoOptions) (info DiskInfo, err error) 70 NSScanner(ctx context.Context, cache dataUsageCache, updates chan<- dataUsageEntry, scanMode madmin.HealScanMode, shouldSleep func() bool) (dataUsageCache, error) 71 72 // Volume operations. 73 MakeVol(ctx context.Context, volume string) (err error) 74 MakeVolBulk(ctx context.Context, volumes ...string) (err error) 75 ListVols(ctx context.Context) (vols []VolInfo, err error) 76 StatVol(ctx context.Context, volume string) (vol VolInfo, err error) 77 DeleteVol(ctx context.Context, volume string, forceDelete bool) (err error) 78 79 // WalkDir will walk a directory on disk and return a metacache stream on wr. 80 WalkDir(ctx context.Context, opts WalkDirOptions, wr io.Writer) error 81 82 // Metadata operations 83 DeleteVersion(ctx context.Context, volume, path string, fi FileInfo, forceDelMarker bool, opts DeleteOptions) error 84 DeleteVersions(ctx context.Context, volume string, versions []FileInfoVersions, opts DeleteOptions) []error 85 WriteMetadata(ctx context.Context, origvolume, volume, path string, fi FileInfo) error 86 UpdateMetadata(ctx context.Context, volume, path string, fi FileInfo, opts UpdateMetadataOpts) error 87 ReadVersion(ctx context.Context, origvolume, volume, path, versionID string, opts ReadOptions) (FileInfo, error) 88 ReadXL(ctx context.Context, volume, path string, readData bool) (RawFileInfo, error) 89 RenameData(ctx context.Context, srcVolume, srcPath string, fi FileInfo, dstVolume, dstPath string, opts RenameOptions) (uint64, error) 90 91 // File operations. 92 ListDir(ctx context.Context, origvolume, volume, dirPath string, count int) ([]string, error) 93 ReadFile(ctx context.Context, volume string, path string, offset int64, buf []byte, verifier *BitrotVerifier) (n int64, err error) 94 AppendFile(ctx context.Context, volume string, path string, buf []byte) (err error) 95 CreateFile(ctx context.Context, origvolume, olume, path string, size int64, reader io.Reader) error 96 ReadFileStream(ctx context.Context, volume, path string, offset, length int64) (io.ReadCloser, error) 97 RenameFile(ctx context.Context, srcVolume, srcPath, dstVolume, dstPath string) error 98 CheckParts(ctx context.Context, volume string, path string, fi FileInfo) error 99 Delete(ctx context.Context, volume string, path string, opts DeleteOptions) (err error) 100 VerifyFile(ctx context.Context, volume, path string, fi FileInfo) error 101 StatInfoFile(ctx context.Context, volume, path string, glob bool) (stat []StatInfo, err error) 102 ReadMultiple(ctx context.Context, req ReadMultipleReq, resp chan<- ReadMultipleResp) error 103 CleanAbandonedData(ctx context.Context, volume string, path string) error 104 105 // Write all data, syncs the data to disk. 106 // Should be used for smaller payloads. 107 WriteAll(ctx context.Context, volume string, path string, b []byte) (err error) 108 109 // Read all. 110 ReadAll(ctx context.Context, volume string, path string) (buf []byte, err error) 111 GetDiskLoc() (poolIdx, setIdx, diskIdx int) // Retrieve location indexes. 112 SetDiskLoc(poolIdx, setIdx, diskIdx int) // Set location indexes. 113 SetFormatData(b []byte) // Set formatData cached value 114 } 115 116 type unrecognizedDisk struct { 117 storage StorageAPI 118 } 119 120 func (p *unrecognizedDisk) WalkDir(ctx context.Context, opts WalkDirOptions, wr io.Writer) (err error) { 121 return errDiskNotFound 122 } 123 124 func (p *unrecognizedDisk) String() string { 125 return p.storage.String() 126 } 127 128 func (p *unrecognizedDisk) IsOnline() bool { 129 return false 130 } 131 132 func (p *unrecognizedDisk) LastConn() time.Time { 133 return p.storage.LastConn() 134 } 135 136 func (p *unrecognizedDisk) IsLocal() bool { 137 return p.storage.IsLocal() 138 } 139 140 func (p *unrecognizedDisk) Endpoint() Endpoint { 141 return p.storage.Endpoint() 142 } 143 144 func (p *unrecognizedDisk) Hostname() string { 145 return p.storage.Hostname() 146 } 147 148 func (p *unrecognizedDisk) Healing() *healingTracker { 149 return nil 150 } 151 152 func (p *unrecognizedDisk) NSScanner(ctx context.Context, cache dataUsageCache, updates chan<- dataUsageEntry, scanMode madmin.HealScanMode, shouldSleep func() bool) (dataUsageCache, error) { 153 return dataUsageCache{}, errDiskNotFound 154 } 155 156 func (p *unrecognizedDisk) SetFormatData(b []byte) { 157 } 158 159 func (p *unrecognizedDisk) GetDiskLoc() (poolIdx, setIdx, diskIdx int) { 160 return -1, -1, -1 161 } 162 163 func (p *unrecognizedDisk) SetDiskLoc(poolIdx, setIdx, diskIdx int) { 164 } 165 166 func (p *unrecognizedDisk) Close() error { 167 return p.storage.Close() 168 } 169 170 func (p *unrecognizedDisk) GetDiskID() (string, error) { 171 return "", errDiskNotFound 172 } 173 174 func (p *unrecognizedDisk) SetDiskID(id string) { 175 } 176 177 func (p *unrecognizedDisk) DiskInfo(ctx context.Context, _ DiskInfoOptions) (info DiskInfo, err error) { 178 return info, errDiskNotFound 179 } 180 181 func (p *unrecognizedDisk) MakeVolBulk(ctx context.Context, volumes ...string) (err error) { 182 return errDiskNotFound 183 } 184 185 func (p *unrecognizedDisk) MakeVol(ctx context.Context, volume string) (err error) { 186 return errDiskNotFound 187 } 188 189 func (p *unrecognizedDisk) ListVols(ctx context.Context) ([]VolInfo, error) { 190 return nil, errDiskNotFound 191 } 192 193 func (p *unrecognizedDisk) StatVol(ctx context.Context, volume string) (vol VolInfo, err error) { 194 return vol, errDiskNotFound 195 } 196 197 func (p *unrecognizedDisk) DeleteVol(ctx context.Context, volume string, forceDelete bool) (err error) { 198 return errDiskNotFound 199 } 200 201 func (p *unrecognizedDisk) ListDir(ctx context.Context, origvolume, volume, dirPath string, count int) ([]string, error) { 202 return nil, errDiskNotFound 203 } 204 205 func (p *unrecognizedDisk) ReadFile(ctx context.Context, volume string, path string, offset int64, buf []byte, verifier *BitrotVerifier) (n int64, err error) { 206 return 0, errDiskNotFound 207 } 208 209 func (p *unrecognizedDisk) AppendFile(ctx context.Context, volume string, path string, buf []byte) (err error) { 210 return errDiskNotFound 211 } 212 213 func (p *unrecognizedDisk) CreateFile(ctx context.Context, origvolume, volume, path string, size int64, reader io.Reader) error { 214 return errDiskNotFound 215 } 216 217 func (p *unrecognizedDisk) ReadFileStream(ctx context.Context, volume, path string, offset, length int64) (io.ReadCloser, error) { 218 return nil, errDiskNotFound 219 } 220 221 func (p *unrecognizedDisk) RenameFile(ctx context.Context, srcVolume, srcPath, dstVolume, dstPath string) error { 222 return errDiskNotFound 223 } 224 225 func (p *unrecognizedDisk) RenameData(ctx context.Context, srcVolume, srcPath string, fi FileInfo, dstVolume, dstPath string, opts RenameOptions) (uint64, error) { 226 return 0, errDiskNotFound 227 } 228 229 func (p *unrecognizedDisk) CheckParts(ctx context.Context, volume string, path string, fi FileInfo) (err error) { 230 return errDiskNotFound 231 } 232 233 func (p *unrecognizedDisk) Delete(ctx context.Context, volume string, path string, opts DeleteOptions) (err error) { 234 return errDiskNotFound 235 } 236 237 // DeleteVersions deletes slice of versions, it can be same object or multiple objects. 238 func (p *unrecognizedDisk) DeleteVersions(ctx context.Context, volume string, versions []FileInfoVersions, opts DeleteOptions) (errs []error) { 239 errs = make([]error, len(versions)) 240 241 for i := range errs { 242 errs[i] = errDiskNotFound 243 } 244 return errs 245 } 246 247 func (p *unrecognizedDisk) VerifyFile(ctx context.Context, volume, path string, fi FileInfo) error { 248 return errDiskNotFound 249 } 250 251 func (p *unrecognizedDisk) WriteAll(ctx context.Context, volume string, path string, b []byte) (err error) { 252 return errDiskNotFound 253 } 254 255 func (p *unrecognizedDisk) DeleteVersion(ctx context.Context, volume, path string, fi FileInfo, forceDelMarker bool, opts DeleteOptions) (err error) { 256 return errDiskNotFound 257 } 258 259 func (p *unrecognizedDisk) UpdateMetadata(ctx context.Context, volume, path string, fi FileInfo, opts UpdateMetadataOpts) (err error) { 260 return errDiskNotFound 261 } 262 263 func (p *unrecognizedDisk) WriteMetadata(ctx context.Context, origvolume, volume, path string, fi FileInfo) (err error) { 264 return errDiskNotFound 265 } 266 267 func (p *unrecognizedDisk) ReadVersion(ctx context.Context, origvolume, volume, path, versionID string, opts ReadOptions) (fi FileInfo, err error) { 268 return fi, errDiskNotFound 269 } 270 271 func (p *unrecognizedDisk) ReadXL(ctx context.Context, volume, path string, readData bool) (rf RawFileInfo, err error) { 272 return rf, errDiskNotFound 273 } 274 275 func (p *unrecognizedDisk) ReadAll(ctx context.Context, volume string, path string) (buf []byte, err error) { 276 return nil, errDiskNotFound 277 } 278 279 func (p *unrecognizedDisk) StatInfoFile(ctx context.Context, volume, path string, glob bool) (stat []StatInfo, err error) { 280 return nil, errDiskNotFound 281 } 282 283 func (p *unrecognizedDisk) ReadMultiple(ctx context.Context, req ReadMultipleReq, resp chan<- ReadMultipleResp) error { 284 xioutil.SafeClose(resp) 285 return errDiskNotFound 286 } 287 288 func (p *unrecognizedDisk) CleanAbandonedData(ctx context.Context, volume string, path string) error { 289 return errDiskNotFound 290 }