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-07 22:01:15 -04:00
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-04-07 22:01:15 -04:00
|
|
|
|
2017-08-14 21:08:42 -04:00
|
|
|
import (
|
2020-03-18 19:19:29 -04:00
|
|
|
"context"
|
2017-08-14 21:08:42 -04:00
|
|
|
"io"
|
2021-05-11 12:19:15 -04:00
|
|
|
"time"
|
2022-04-07 11:10:40 -04:00
|
|
|
|
2023-06-19 20:53:08 -04:00
|
|
|
"github.com/minio/madmin-go/v3"
|
2017-08-14 21:08:42 -04:00
|
|
|
)
|
2016-08-25 20:16:34 -04:00
|
|
|
|
2016-04-07 22:01:15 -04:00
|
|
|
// StorageAPI interface.
|
|
|
|
type StorageAPI interface {
|
2016-10-05 15:48:07 -04:00
|
|
|
// Stringified version of disk.
|
|
|
|
String() string
|
|
|
|
|
2016-08-25 20:16:34 -04:00
|
|
|
// Storage operations.
|
2021-05-11 12:19:15 -04:00
|
|
|
|
2022-03-09 14:38:54 -05:00
|
|
|
// Returns true if disk is online and its valid i.e valid format.json.
|
|
|
|
// This has nothing to do with if the drive is hung or not responding.
|
|
|
|
// For that individual storage API calls will fail properly. The purpose
|
|
|
|
// of this function is to know if the "drive" has "format.json" or not
|
|
|
|
// if it has a "format.json" then is it correct "format.json" or not.
|
|
|
|
IsOnline() bool
|
|
|
|
|
|
|
|
// Returns the last time this disk (re)-connected
|
|
|
|
LastConn() time.Time
|
|
|
|
|
|
|
|
// Indicates if disk is local or not.
|
2020-05-19 17:27:20 -04:00
|
|
|
IsLocal() bool
|
2020-09-28 22:39:32 -04:00
|
|
|
|
2022-03-09 14:38:54 -05:00
|
|
|
// Returns hostname if disk is remote.
|
|
|
|
Hostname() string
|
|
|
|
|
|
|
|
// Returns the entire endpoint.
|
|
|
|
Endpoint() Endpoint
|
|
|
|
|
|
|
|
// Close the disk, mark it purposefully closed, only implemented for remote disks.
|
2018-02-15 20:45:57 -05:00
|
|
|
Close() error
|
2022-03-09 14:38:54 -05:00
|
|
|
|
|
|
|
// Returns the unique 'uuid' of this disk.
|
2020-05-28 16:03:04 -04:00
|
|
|
GetDiskID() (string, error)
|
2022-03-09 14:38:54 -05:00
|
|
|
|
|
|
|
// Set a unique 'uuid' for this disk, only used when
|
|
|
|
// disk is replaced and formatted.
|
2019-10-25 13:37:53 -04:00
|
|
|
SetDiskID(id string)
|
2022-03-09 14:38:54 -05:00
|
|
|
|
|
|
|
// Returns healing information for a newly replaced disk,
|
|
|
|
// returns 'nil' once healing is complete or if the disk
|
|
|
|
// has never been replaced.
|
|
|
|
Healing() *healingTracker
|
2023-07-31 18:20:48 -04:00
|
|
|
DiskInfo(ctx context.Context, metrics bool) (info DiskInfo, err error)
|
2024-01-02 16:51:24 -05:00
|
|
|
NSScanner(ctx context.Context, cache dataUsageCache, updates chan<- dataUsageEntry, scanMode madmin.HealScanMode, shouldSleep func() bool) (dataUsageCache, error)
|
2016-08-25 20:16:34 -04:00
|
|
|
|
2016-04-07 22:01:15 -04:00
|
|
|
// Volume operations.
|
2020-09-04 12:45:06 -04:00
|
|
|
MakeVol(ctx context.Context, volume string) (err error)
|
|
|
|
MakeVolBulk(ctx context.Context, volumes ...string) (err error)
|
|
|
|
ListVols(ctx context.Context) (vols []VolInfo, err error)
|
|
|
|
StatVol(ctx context.Context, volume string) (vol VolInfo, err error)
|
|
|
|
DeleteVol(ctx context.Context, volume string, forceDelete bool) (err error)
|
2016-04-07 22:01:15 -04:00
|
|
|
|
2020-10-28 12:18:35 -04:00
|
|
|
// WalkDir will walk a directory on disk and return a metacache stream on wr.
|
|
|
|
WalkDir(ctx context.Context, opts WalkDirOptions, wr io.Writer) error
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// Metadata operations
|
2023-12-29 18:52:41 -05:00
|
|
|
DeleteVersion(ctx context.Context, volume, path string, fi FileInfo, forceDelMarker bool, opts DeleteOptions) error
|
|
|
|
DeleteVersions(ctx context.Context, volume string, versions []FileInfoVersions, opts DeleteOptions) []error
|
2020-09-04 12:45:06 -04:00
|
|
|
WriteMetadata(ctx context.Context, volume, path string, fi FileInfo) error
|
2023-08-25 10:58:11 -04:00
|
|
|
UpdateMetadata(ctx context.Context, volume, path string, fi FileInfo, opts UpdateMetadataOpts) error
|
2023-11-21 00:33:47 -05:00
|
|
|
ReadVersion(ctx context.Context, volume, path, versionID string, opts ReadOptions) (FileInfo, error)
|
2022-04-20 15:49:05 -04:00
|
|
|
ReadXL(ctx context.Context, volume, path string, readData bool) (RawFileInfo, error)
|
2023-12-29 18:52:41 -05:00
|
|
|
RenameData(ctx context.Context, srcVolume, srcPath string, fi FileInfo, dstVolume, dstPath string, opts RenameOptions) (uint64, error)
|
2020-06-12 23:04:01 -04:00
|
|
|
|
2016-04-07 22:01:15 -04:00
|
|
|
// File operations.
|
2020-09-04 12:45:06 -04:00
|
|
|
ListDir(ctx context.Context, volume, dirPath string, count int) ([]string, error)
|
|
|
|
ReadFile(ctx context.Context, volume string, path string, offset int64, buf []byte, verifier *BitrotVerifier) (n int64, err error)
|
|
|
|
AppendFile(ctx context.Context, volume string, path string, buf []byte) (err error)
|
|
|
|
CreateFile(ctx context.Context, volume, path string, size int64, reader io.Reader) error
|
|
|
|
ReadFileStream(ctx context.Context, volume, path string, offset, length int64) (io.ReadCloser, error)
|
|
|
|
RenameFile(ctx context.Context, srcVolume, srcPath, dstVolume, dstPath string) error
|
|
|
|
CheckParts(ctx context.Context, volume string, path string, fi FileInfo) error
|
2023-12-29 18:52:41 -05:00
|
|
|
Delete(ctx context.Context, volume string, path string, opts DeleteOptions) (err error)
|
2020-09-04 12:45:06 -04:00
|
|
|
VerifyFile(ctx context.Context, volume, path string, fi FileInfo) error
|
2021-10-01 14:50:00 -04:00
|
|
|
StatInfoFile(ctx context.Context, volume, path string, glob bool) (stat []StatInfo, err error)
|
2022-07-19 11:35:29 -04:00
|
|
|
ReadMultiple(ctx context.Context, req ReadMultipleReq, resp chan<- ReadMultipleResp) error
|
2022-11-28 13:20:55 -05:00
|
|
|
CleanAbandonedData(ctx context.Context, volume string, path string) error
|
2016-06-25 17:51:06 -04:00
|
|
|
|
2018-11-14 09:18:35 -05:00
|
|
|
// Write all data, syncs the data to disk.
|
2020-11-02 19:14:31 -05:00
|
|
|
// Should be used for smaller payloads.
|
|
|
|
WriteAll(ctx context.Context, volume string, path string, b []byte) (err error)
|
2018-11-14 09:18:35 -05:00
|
|
|
|
2016-06-25 17:51:06 -04:00
|
|
|
// Read all.
|
2020-09-04 12:45:06 -04:00
|
|
|
ReadAll(ctx context.Context, volume string, path string) (buf []byte, err error)
|
2021-03-04 17:36:23 -05:00
|
|
|
GetDiskLoc() (poolIdx, setIdx, diskIdx int) // Retrieve location indexes.
|
|
|
|
SetDiskLoc(poolIdx, setIdx, diskIdx int) // Set location indexes.
|
2016-04-07 22:01:15 -04:00
|
|
|
}
|
2017-08-14 21:08:42 -04:00
|
|
|
|
2021-11-15 12:46:55 -05:00
|
|
|
type unrecognizedDisk struct {
|
|
|
|
storage StorageAPI
|
2017-08-14 21:08:42 -04:00
|
|
|
}
|
|
|
|
|
2021-11-15 12:46:55 -05:00
|
|
|
func (p *unrecognizedDisk) WalkDir(ctx context.Context, opts WalkDirOptions, wr io.Writer) (err error) {
|
|
|
|
return errDiskNotFound
|
|
|
|
}
|
2017-08-14 21:08:42 -04:00
|
|
|
|
2021-11-15 12:46:55 -05:00
|
|
|
func (p *unrecognizedDisk) String() string {
|
|
|
|
return p.storage.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) IsOnline() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) LastConn() time.Time {
|
|
|
|
return p.storage.LastConn()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) IsLocal() bool {
|
|
|
|
return p.storage.IsLocal()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) Endpoint() Endpoint {
|
|
|
|
return p.storage.Endpoint()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) Hostname() string {
|
|
|
|
return p.storage.Hostname()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) Healing() *healingTracker {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-01-02 16:51:24 -05:00
|
|
|
func (p *unrecognizedDisk) NSScanner(ctx context.Context, cache dataUsageCache, updates chan<- dataUsageEntry, scanMode madmin.HealScanMode, shouldSleep func() bool) (dataUsageCache, error) {
|
2021-11-15 12:46:55 -05:00
|
|
|
return dataUsageCache{}, errDiskNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) GetDiskLoc() (poolIdx, setIdx, diskIdx int) {
|
|
|
|
return -1, -1, -1
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) SetDiskLoc(poolIdx, setIdx, diskIdx int) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) Close() error {
|
|
|
|
return p.storage.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) GetDiskID() (string, error) {
|
|
|
|
return "", errDiskNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) SetDiskID(id string) {
|
|
|
|
}
|
|
|
|
|
2023-07-31 18:20:48 -04:00
|
|
|
func (p *unrecognizedDisk) DiskInfo(ctx context.Context, _ bool) (info DiskInfo, err error) {
|
2021-11-15 12:46:55 -05:00
|
|
|
return info, errDiskNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) MakeVolBulk(ctx context.Context, volumes ...string) (err error) {
|
|
|
|
return errDiskNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) MakeVol(ctx context.Context, volume string) (err error) {
|
|
|
|
return errDiskNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) ListVols(ctx context.Context) ([]VolInfo, error) {
|
|
|
|
return nil, errDiskNotFound
|
2017-08-14 21:08:42 -04:00
|
|
|
}
|
|
|
|
|
2021-11-15 12:46:55 -05:00
|
|
|
func (p *unrecognizedDisk) StatVol(ctx context.Context, volume string) (vol VolInfo, err error) {
|
|
|
|
return vol, errDiskNotFound
|
2017-08-14 21:08:42 -04:00
|
|
|
}
|
|
|
|
|
2021-11-15 12:46:55 -05:00
|
|
|
func (p *unrecognizedDisk) DeleteVol(ctx context.Context, volume string, forceDelete bool) (err error) {
|
|
|
|
return errDiskNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) ListDir(ctx context.Context, volume, dirPath string, count int) ([]string, error) {
|
|
|
|
return nil, errDiskNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) ReadFile(ctx context.Context, volume string, path string, offset int64, buf []byte, verifier *BitrotVerifier) (n int64, err error) {
|
|
|
|
return 0, errDiskNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) AppendFile(ctx context.Context, volume string, path string, buf []byte) (err error) {
|
|
|
|
return errDiskNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) CreateFile(ctx context.Context, volume, path string, size int64, reader io.Reader) error {
|
|
|
|
return errDiskNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) ReadFileStream(ctx context.Context, volume, path string, offset, length int64) (io.ReadCloser, error) {
|
|
|
|
return nil, errDiskNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) RenameFile(ctx context.Context, srcVolume, srcPath, dstVolume, dstPath string) error {
|
|
|
|
return errDiskNotFound
|
|
|
|
}
|
|
|
|
|
2023-12-29 18:52:41 -05:00
|
|
|
func (p *unrecognizedDisk) RenameData(ctx context.Context, srcVolume, srcPath string, fi FileInfo, dstVolume, dstPath string, opts RenameOptions) (uint64, error) {
|
2022-09-05 19:51:37 -04:00
|
|
|
return 0, errDiskNotFound
|
2021-11-15 12:46:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) CheckParts(ctx context.Context, volume string, path string, fi FileInfo) (err error) {
|
|
|
|
return errDiskNotFound
|
|
|
|
}
|
|
|
|
|
2023-12-29 18:52:41 -05:00
|
|
|
func (p *unrecognizedDisk) Delete(ctx context.Context, volume string, path string, opts DeleteOptions) (err error) {
|
2021-11-15 12:46:55 -05:00
|
|
|
return errDiskNotFound
|
|
|
|
}
|
|
|
|
|
2023-12-29 18:52:41 -05:00
|
|
|
// DeleteVersions deletes slice of versions, it can be same object or multiple objects.
|
|
|
|
func (p *unrecognizedDisk) DeleteVersions(ctx context.Context, volume string, versions []FileInfoVersions, opts DeleteOptions) (errs []error) {
|
2021-11-15 12:46:55 -05:00
|
|
|
errs = make([]error, len(versions))
|
|
|
|
|
|
|
|
for i := range errs {
|
|
|
|
errs[i] = errDiskNotFound
|
2017-08-14 21:08:42 -04:00
|
|
|
}
|
2021-11-15 12:46:55 -05:00
|
|
|
return errs
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) VerifyFile(ctx context.Context, volume, path string, fi FileInfo) error {
|
|
|
|
return errDiskNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) WriteAll(ctx context.Context, volume string, path string, b []byte) (err error) {
|
|
|
|
return errDiskNotFound
|
|
|
|
}
|
|
|
|
|
2023-12-29 18:52:41 -05:00
|
|
|
func (p *unrecognizedDisk) DeleteVersion(ctx context.Context, volume, path string, fi FileInfo, forceDelMarker bool, opts DeleteOptions) (err error) {
|
2021-11-15 12:46:55 -05:00
|
|
|
return errDiskNotFound
|
|
|
|
}
|
|
|
|
|
2023-08-25 10:58:11 -04:00
|
|
|
func (p *unrecognizedDisk) UpdateMetadata(ctx context.Context, volume, path string, fi FileInfo, opts UpdateMetadataOpts) (err error) {
|
2021-11-15 12:46:55 -05:00
|
|
|
return errDiskNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *unrecognizedDisk) WriteMetadata(ctx context.Context, volume, path string, fi FileInfo) (err error) {
|
|
|
|
return errDiskNotFound
|
|
|
|
}
|
|
|
|
|
2023-11-21 00:33:47 -05:00
|
|
|
func (p *unrecognizedDisk) ReadVersion(ctx context.Context, volume, path, versionID string, opts ReadOptions) (fi FileInfo, err error) {
|
2021-11-15 12:46:55 -05:00
|
|
|
return fi, errDiskNotFound
|
2017-08-14 21:08:42 -04:00
|
|
|
}
|
|
|
|
|
2022-04-20 15:49:05 -04:00
|
|
|
func (p *unrecognizedDisk) ReadXL(ctx context.Context, volume, path string, readData bool) (rf RawFileInfo, err error) {
|
|
|
|
return rf, errDiskNotFound
|
|
|
|
}
|
|
|
|
|
2021-11-15 12:46:55 -05:00
|
|
|
func (p *unrecognizedDisk) ReadAll(ctx context.Context, volume string, path string) (buf []byte, err error) {
|
|
|
|
return nil, errDiskNotFound
|
2017-08-14 21:08:42 -04:00
|
|
|
}
|
|
|
|
|
2021-11-15 12:46:55 -05:00
|
|
|
func (p *unrecognizedDisk) StatInfoFile(ctx context.Context, volume, path string, glob bool) (stat []StatInfo, err error) {
|
|
|
|
return nil, errDiskNotFound
|
2017-08-14 21:08:42 -04:00
|
|
|
}
|
2022-07-19 11:35:29 -04:00
|
|
|
|
|
|
|
func (p *unrecognizedDisk) ReadMultiple(ctx context.Context, req ReadMultipleReq, resp chan<- ReadMultipleResp) error {
|
|
|
|
close(resp)
|
|
|
|
return errDiskNotFound
|
|
|
|
}
|
2022-11-28 13:20:55 -05:00
|
|
|
|
|
|
|
func (p *unrecognizedDisk) CleanAbandonedData(ctx context.Context, volume string, path string) error {
|
|
|
|
return errDiskNotFound
|
|
|
|
}
|