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 (
|
|
|
|
"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-01-13 22:09:10 +01:00
|
|
|
IsOnline() bool // Returns true if disk is online.
|
|
|
|
Hostname() string // Returns host name if remote host.
|
2018-02-16 02:45:57 +01:00
|
|
|
Close() error
|
2019-10-25 19:37:53 +02:00
|
|
|
SetDiskID(id string)
|
2018-09-11 01:21:59 +02:00
|
|
|
|
2018-05-23 12:11:29 +02:00
|
|
|
DiskInfo() (info DiskInfo, err error)
|
2019-12-12 15:02:37 +01:00
|
|
|
CrawlAndGetDataUsage(endCh <-chan struct{}) (DataUsageInfo, error)
|
2016-08-26 02:16:34 +02:00
|
|
|
|
2016-04-08 04:01:15 +02:00
|
|
|
// Volume operations.
|
|
|
|
MakeVol(volume string) (err error)
|
2019-12-24 01:31:03 +01:00
|
|
|
MakeVolBulk(volumes ...string) (err error)
|
2016-04-08 04:01:15 +02:00
|
|
|
ListVols() (vols []VolInfo, err error)
|
|
|
|
StatVol(volume string) (vol VolInfo, err error)
|
|
|
|
DeleteVol(volume string) (err error)
|
|
|
|
|
2019-05-14 22:49:10 +02:00
|
|
|
// Walk in sorted order directly on disk.
|
|
|
|
Walk(volume, dirPath string, marker string, recursive bool, leafFile string,
|
|
|
|
readMetadataFn readMetadataFunc, endWalkCh chan struct{}) (chan FileInfo, error)
|
|
|
|
|
2016-04-08 04:01:15 +02:00
|
|
|
// File operations.
|
2019-04-23 23:54:28 +02:00
|
|
|
ListDir(volume, dirPath string, count int, leafFile string) ([]string, error)
|
2017-09-25 20:32:56 +02:00
|
|
|
ReadFile(volume string, path string, offset int64, buf []byte, verifier *BitrotVerifier) (n int64, err error)
|
2016-06-20 00:31:13 +02:00
|
|
|
AppendFile(volume string, path string, buf []byte) (err error)
|
2019-01-17 13:58:18 +01:00
|
|
|
CreateFile(volume, path string, size int64, reader io.Reader) error
|
|
|
|
ReadFileStream(volume, path string, offset, length int64) (io.ReadCloser, error)
|
2016-05-29 00:13:15 +02:00
|
|
|
RenameFile(srcVolume, srcPath, dstVolume, dstPath string) error
|
2016-04-08 04:01:15 +02:00
|
|
|
StatFile(volume string, path string) (file FileInfo, err error)
|
|
|
|
DeleteFile(volume string, path string) (err error)
|
2019-05-13 21:25:49 +02:00
|
|
|
DeleteFileBulk(volume string, paths []string) (errs []error, err error)
|
2019-09-11 22:49:53 +02:00
|
|
|
VerifyFile(volume, path string, size int64, algo BitrotAlgorithm, sum []byte, shardSize int64) 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.
|
2019-05-22 22:47:15 +02:00
|
|
|
WriteAll(volume string, path string, reader io.Reader) (err error)
|
2018-11-14 15:18:35 +01:00
|
|
|
|
2016-06-25 23:51:06 +02:00
|
|
|
// Read all.
|
|
|
|
ReadAll(volume string, path string) (buf []byte, err error)
|
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) {
|
2017-09-25 20:32:56 +02:00
|
|
|
nn, err := r.storage.ReadFile(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) {
|
|
|
|
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}
|
|
|
|
}
|