2016-04-07 22:01:15 -04:00
|
|
|
/*
|
2019-04-09 14:39:42 -04:00
|
|
|
* MinIO Cloud Storage, (C) 2016 MinIO, Inc.
|
2016-04-07 22:01:15 -04: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-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"
|
|
|
|
)
|
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.
|
2020-05-19 17:27:20 -04:00
|
|
|
IsOnline() bool // Returns true if disk is online.
|
|
|
|
IsLocal() bool
|
2020-08-18 17:37:26 -04:00
|
|
|
|
2020-01-13 16:09:10 -05:00
|
|
|
Hostname() string // Returns host name if remote host.
|
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)
|
2018-09-10 19:21:59 -04:00
|
|
|
|
2018-05-23 06:11:29 -04:00
|
|
|
DiskInfo() (info DiskInfo, err error)
|
2020-03-18 19:19:29 -04:00
|
|
|
CrawlAndGetDataUsage(ctx context.Context, cache dataUsageCache) (dataUsageCache, error)
|
2016-08-25 20:16:34 -04:00
|
|
|
|
2016-04-07 22:01:15 -04:00
|
|
|
// Volume operations.
|
|
|
|
MakeVol(volume string) (err error)
|
2019-12-23 19:31:03 -05:00
|
|
|
MakeVolBulk(volumes ...string) (err error)
|
2016-04-07 22:01:15 -04:00
|
|
|
ListVols() (vols []VolInfo, err error)
|
|
|
|
StatVol(volume string) (vol VolInfo, err error)
|
2020-03-28 00:52:59 -04:00
|
|
|
DeleteVol(volume string, forceDelete bool) (err error)
|
2016-04-07 22:01:15 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// WalkVersions in sorted order directly on disk.
|
|
|
|
WalkVersions(volume, dirPath string, marker string, recursive bool, endWalkCh <-chan struct{}) (chan FileInfoVersions, error)
|
2019-05-14 16:49:10 -04:00
|
|
|
// Walk in sorted order directly on disk.
|
2020-06-12 23:04:01 -04:00
|
|
|
Walk(volume, dirPath string, marker string, recursive bool, endWalkCh <-chan struct{}) (chan FileInfo, error)
|
2020-03-22 22:23:47 -04:00
|
|
|
// Walk in sorted order directly on disk.
|
|
|
|
WalkSplunk(volume, dirPath string, marker string, endWalkCh <-chan struct{}) (chan FileInfo, error)
|
2019-05-14 16:49:10 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
// Metadata operations
|
|
|
|
DeleteVersion(volume, path string, fi FileInfo) error
|
|
|
|
DeleteVersions(volume string, versions []FileInfo) []error
|
|
|
|
WriteMetadata(volume, path string, fi FileInfo) error
|
|
|
|
ReadVersion(volume, path, versionID string) (FileInfo, error)
|
|
|
|
RenameData(srcVolume, srcPath, dataDir, dstVolume, dstPath string) error
|
|
|
|
|
2016-04-07 22:01:15 -04:00
|
|
|
// File operations.
|
2020-06-12 23:04:01 -04:00
|
|
|
ListDir(volume, dirPath string, count int) ([]string, error)
|
2017-09-25 14:32:56 -04:00
|
|
|
ReadFile(volume string, path string, offset int64, buf []byte, verifier *BitrotVerifier) (n int64, err error)
|
2016-06-19 18:31:13 -04:00
|
|
|
AppendFile(volume string, path string, buf []byte) (err error)
|
2019-01-17 07:58:18 -05:00
|
|
|
CreateFile(volume, path string, size int64, reader io.Reader) error
|
|
|
|
ReadFileStream(volume, path string, offset, length int64) (io.ReadCloser, error)
|
2016-05-28 18:13:15 -04:00
|
|
|
RenameFile(srcVolume, srcPath, dstVolume, dstPath string) error
|
2020-06-12 23:04:01 -04:00
|
|
|
CheckParts(volume string, path string, fi FileInfo) error
|
|
|
|
CheckFile(volume string, path string) (err error)
|
2016-04-07 22:01:15 -04:00
|
|
|
DeleteFile(volume string, path string) (err error)
|
2020-06-12 23:04:01 -04:00
|
|
|
VerifyFile(volume, path string, fi FileInfo) 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.
|
2019-05-22 16:47:15 -04:00
|
|
|
WriteAll(volume string, path string, reader io.Reader) (err error)
|
2018-11-14 09:18:35 -05:00
|
|
|
|
2016-06-25 17:51:06 -04:00
|
|
|
// Read all.
|
|
|
|
ReadAll(volume string, path string) (buf []byte, err error)
|
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) {
|
2017-09-25 14:32:56 -04:00
|
|
|
nn, err := r.storage.ReadFile(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) {
|
|
|
|
err = w.storage.AppendFile(w.volume, w.path, p)
|
|
|
|
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}
|
|
|
|
}
|