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"
|
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
|
|
|
IsOnline() bool // Returns true if disk is online.
|
|
|
|
LastConn() time.Time // Returns the last time this disk (re)-connected
|
|
|
|
|
2020-05-19 17:27:20 -04:00
|
|
|
IsLocal() bool
|
2020-08-18 17:37:26 -04:00
|
|
|
|
2020-09-28 22:39:32 -04:00
|
|
|
Hostname() string // Returns host name if remote host.
|
|
|
|
Endpoint() Endpoint // Returns endpoint.
|
|
|
|
|
2018-02-15 20:45:57 -05:00
|
|
|
Close() error
|
2020-05-28 16:03:04 -04:00
|
|
|
GetDiskID() (string, error)
|
2019-10-25 13:37:53 -04:00
|
|
|
SetDiskID(id string)
|
2021-03-04 17:36:23 -05:00
|
|
|
Healing() *healingTracker // Returns nil if disk is not healing.
|
2018-09-10 19:21:59 -04:00
|
|
|
|
2020-09-04 12:45:06 -04:00
|
|
|
DiskInfo(ctx context.Context) (info DiskInfo, err error)
|
2021-05-19 17:38:30 -04:00
|
|
|
NSScanner(ctx context.Context, cache dataUsageCache, updates chan<- dataUsageEntry) (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
|
2021-02-03 13:33:43 -05:00
|
|
|
DeleteVersion(ctx context.Context, volume, path string, fi FileInfo, forceDelMarker bool) error
|
2020-09-04 12:45:06 -04:00
|
|
|
DeleteVersions(ctx context.Context, volume string, versions []FileInfo) []error
|
|
|
|
WriteMetadata(ctx context.Context, volume, path string, fi FileInfo) error
|
2021-04-04 16:32:31 -04:00
|
|
|
UpdateMetadata(ctx context.Context, volume, path string, fi FileInfo) error
|
2021-01-07 22:27:31 -05:00
|
|
|
ReadVersion(ctx context.Context, volume, path, versionID string, readData bool) (FileInfo, error)
|
2021-04-20 13:44:39 -04:00
|
|
|
RenameData(ctx context.Context, srcVolume, srcPath string, fi FileInfo, dstVolume, dstPath string) 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
|
2020-10-28 12:18:35 -04:00
|
|
|
Delete(ctx context.Context, volume string, path string, recursive bool) (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)
|
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
|
|
|
|
|
|
|
// storageReader is an io.Reader view of a disk
|
|
|
|
type storageReader struct {
|
|
|
|
storage StorageAPI
|
|
|
|
volume, path string
|
|
|
|
offset int64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *storageReader) Read(p []byte) (n int, err error) {
|
2020-09-04 12:45:06 -04:00
|
|
|
nn, err := r.storage.ReadFile(context.TODO(), r.volume, r.path, r.offset, p, nil)
|
2017-08-14 21:08:42 -04:00
|
|
|
r.offset += nn
|
|
|
|
n = int(nn)
|
|
|
|
|
|
|
|
if err == io.ErrUnexpectedEOF && nn > 0 {
|
|
|
|
err = io.EOF
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// storageWriter is a io.Writer view of a disk.
|
|
|
|
type storageWriter struct {
|
|
|
|
storage StorageAPI
|
|
|
|
volume, path string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *storageWriter) Write(p []byte) (n int, err error) {
|
2020-09-04 12:45:06 -04:00
|
|
|
err = w.storage.AppendFile(context.TODO(), w.volume, w.path, p)
|
2017-08-14 21:08:42 -04:00
|
|
|
if err == nil {
|
|
|
|
n = len(p)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// StorageWriter returns a new io.Writer which appends data to the file
|
|
|
|
// at the given disk, volume and path.
|
|
|
|
func StorageWriter(storage StorageAPI, volume, path string) io.Writer {
|
|
|
|
return &storageWriter{storage, volume, path}
|
|
|
|
}
|
|
|
|
|
|
|
|
// StorageReader returns a new io.Reader which reads data to the file
|
|
|
|
// at the given disk, volume, path and offset.
|
|
|
|
func StorageReader(storage StorageAPI, volume, path string, offset int64) io.Reader {
|
|
|
|
return &storageReader{storage, volume, path, offset}
|
|
|
|
}
|