2016-04-08 04:01:15 +02:00
|
|
|
/*
|
2019-04-09 20:39:42 +02:00
|
|
|
* MinIO Cloud Storage, (C) 2016 MinIO, Inc.
|
2016-04-08 04:01:15 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-08-19 01:23:42 +02:00
|
|
|
package cmd
|
2016-04-08 04:01:15 +02:00
|
|
|
|
2017-08-15 03:08:42 +02:00
|
|
|
import (
|
2020-03-19 00:19:29 +01:00
|
|
|
"context"
|
2017-08-15 03:08:42 +02:00
|
|
|
"io"
|
|
|
|
)
|
2016-08-26 02:16:34 +02:00
|
|
|
|
2016-04-08 04:01:15 +02:00
|
|
|
// StorageAPI interface.
|
|
|
|
type StorageAPI interface {
|
2016-10-05 21:48:07 +02:00
|
|
|
// Stringified version of disk.
|
|
|
|
String() string
|
|
|
|
|
2016-08-26 02:16:34 +02:00
|
|
|
// Storage operations.
|
2020-05-19 23:27:20 +02:00
|
|
|
IsOnline() bool // Returns true if disk is online.
|
|
|
|
IsLocal() bool
|
2020-08-18 23:37:26 +02:00
|
|
|
|
2020-09-29 04:39:32 +02:00
|
|
|
Hostname() string // Returns host name if remote host.
|
|
|
|
Endpoint() Endpoint // Returns endpoint.
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
Close() error
|
2020-05-28 22:03:04 +02:00
|
|
|
GetDiskID() (string, error)
|
2019-10-25 19:37:53 +02:00
|
|
|
SetDiskID(id string)
|
2021-03-04 23:36:23 +01:00
|
|
|
Healing() *healingTracker // Returns nil if disk is not healing.
|
2018-09-11 01:21:59 +02:00
|
|
|
|
2020-09-04 18:45:06 +02:00
|
|
|
DiskInfo(ctx context.Context) (info DiskInfo, err error)
|
2021-02-27 00:11:42 +01:00
|
|
|
NSScanner(ctx context.Context, cache dataUsageCache) (dataUsageCache, error)
|
2016-08-26 02:16:34 +02:00
|
|
|
|
2016-04-08 04:01:15 +02:00
|
|
|
// Volume operations.
|
2020-09-04 18:45:06 +02: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-08 04:01:15 +02:00
|
|
|
|
2020-10-28 17:18:35 +01: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-13 05:04:01 +02:00
|
|
|
// Metadata operations
|
2021-02-03 19:33:43 +01:00
|
|
|
DeleteVersion(ctx context.Context, volume, path string, fi FileInfo, forceDelMarker bool) error
|
2020-09-04 18:45:06 +02:00
|
|
|
DeleteVersions(ctx context.Context, volume string, versions []FileInfo) []error
|
|
|
|
WriteMetadata(ctx context.Context, volume, path string, fi FileInfo) error
|
2021-04-04 22:32:31 +02:00
|
|
|
UpdateMetadata(ctx context.Context, volume, path string, fi FileInfo) error
|
2021-01-08 04:27:31 +01:00
|
|
|
ReadVersion(ctx context.Context, volume, path, versionID string, readData bool) (FileInfo, error)
|
2020-09-04 18:45:06 +02:00
|
|
|
RenameData(ctx context.Context, srcVolume, srcPath, dataDir, dstVolume, dstPath string) error
|
2020-06-13 05:04:01 +02:00
|
|
|
|
2016-04-08 04:01:15 +02:00
|
|
|
// File operations.
|
2020-09-04 18:45:06 +02: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
|
|
|
|
CheckFile(ctx context.Context, volume string, path string) (err error)
|
2020-10-28 17:18:35 +01:00
|
|
|
Delete(ctx context.Context, volume string, path string, recursive bool) (err error)
|
2020-09-04 18:45:06 +02:00
|
|
|
VerifyFile(ctx context.Context, volume, path string, fi FileInfo) error
|
2016-06-25 23:51:06 +02:00
|
|
|
|
2018-11-14 15:18:35 +01:00
|
|
|
// Write all data, syncs the data to disk.
|
2020-11-03 01:14:31 +01:00
|
|
|
// Should be used for smaller payloads.
|
|
|
|
WriteAll(ctx context.Context, volume string, path string, b []byte) (err error)
|
2018-11-14 15:18:35 +01:00
|
|
|
|
2016-06-25 23:51:06 +02:00
|
|
|
// Read all.
|
2020-09-04 18:45:06 +02:00
|
|
|
ReadAll(ctx context.Context, volume string, path string) (buf []byte, err error)
|
2021-03-04 23:36:23 +01:00
|
|
|
|
|
|
|
GetDiskLoc() (poolIdx, setIdx, diskIdx int) // Retrieve location indexes.
|
|
|
|
SetDiskLoc(poolIdx, setIdx, diskIdx int) // Set location indexes.
|
2016-04-08 04:01:15 +02:00
|
|
|
}
|
2017-08-15 03:08:42 +02: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 18:45:06 +02:00
|
|
|
nn, err := r.storage.ReadFile(context.TODO(), r.volume, r.path, r.offset, p, nil)
|
2017-08-15 03:08:42 +02: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 18:45:06 +02:00
|
|
|
err = w.storage.AppendFile(context.TODO(), w.volume, w.path, p)
|
2017-08-15 03:08:42 +02: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}
|
|
|
|
}
|