2015-10-16 14:26:01 -04:00
|
|
|
/*
|
2016-04-08 13:37:38 -04:00
|
|
|
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
2015-10-16 14:26:01 -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.
|
|
|
|
*/
|
|
|
|
|
fs: Break fs package to top-level and introduce ObjectAPI interface.
ObjectAPI interface brings in changes needed for XL ObjectAPI layer.
The new interface for any ObjectAPI layer is as below
```
// ObjectAPI interface.
type ObjectAPI interface {
// Bucket resource API.
DeleteBucket(bucket string) *probe.Error
ListBuckets() ([]BucketInfo, *probe.Error)
MakeBucket(bucket string) *probe.Error
GetBucketInfo(bucket string) (BucketInfo, *probe.Error)
// Bucket query API.
ListObjects(bucket, prefix, marker, delimiter string, maxKeys int) (ListObjectsResult, *probe.Error)
ListMultipartUploads(bucket string, resources BucketMultipartResourcesMetadata) (BucketMultipartResourcesMetadata, *probe.Error)
// Object resource API.
GetObject(bucket, object string, startOffset int64) (io.ReadCloser, *probe.Error)
GetObjectInfo(bucket, object string) (ObjectInfo, *probe.Error)
PutObject(bucket string, object string, size int64, data io.Reader, metadata map[string]string) (ObjectInfo, *probe.Error)
DeleteObject(bucket, object string) *probe.Error
// Object query API.
NewMultipartUpload(bucket, object string) (string, *probe.Error)
PutObjectPart(bucket, object, uploadID string, partID int, size int64, data io.Reader, md5Hex string) (string, *probe.Error)
ListObjectParts(bucket, object string, resources ObjectResourcesMetadata) (ObjectResourcesMetadata, *probe.Error)
CompleteMultipartUpload(bucket string, object string, uploadID string, parts []CompletePart) (ObjectInfo, *probe.Error)
AbortMultipartUpload(bucket, object, uploadID string) *probe.Error
}
```
2016-03-30 19:15:28 -04:00
|
|
|
package main
|
2015-10-16 14:26:01 -04:00
|
|
|
|
|
|
|
import (
|
2016-05-28 18:13:15 -04:00
|
|
|
"bytes"
|
2016-06-09 01:02:10 -04:00
|
|
|
"errors"
|
2016-04-08 13:37:38 -04:00
|
|
|
"io"
|
2016-06-25 17:51:06 -04:00
|
|
|
"io/ioutil"
|
2016-04-08 20:13:16 -04:00
|
|
|
"os"
|
2016-05-09 03:46:54 -04:00
|
|
|
slashpath "path"
|
2016-05-28 18:13:15 -04:00
|
|
|
"path/filepath"
|
2016-06-20 09:18:47 -04:00
|
|
|
"runtime"
|
2016-04-08 13:37:38 -04:00
|
|
|
"strings"
|
2016-06-20 19:57:14 -04:00
|
|
|
"sync/atomic"
|
2016-04-08 13:37:38 -04:00
|
|
|
"syscall"
|
2015-10-16 14:26:01 -04:00
|
|
|
|
2016-04-08 20:13:16 -04:00
|
|
|
"github.com/minio/minio/pkg/disk"
|
2015-10-16 14:26:01 -04:00
|
|
|
)
|
|
|
|
|
2016-04-08 13:37:38 -04:00
|
|
|
const (
|
2016-05-04 18:39:06 -04:00
|
|
|
fsMinSpacePercent = 5
|
2016-06-09 01:02:10 -04:00
|
|
|
maxAllowedIOError = 5
|
2016-04-08 13:37:38 -04:00
|
|
|
)
|
|
|
|
|
2016-05-28 18:13:15 -04:00
|
|
|
// posix - implements StorageAPI interface.
|
|
|
|
type posix struct {
|
2016-06-20 19:57:14 -04:00
|
|
|
ioErrCount int32 // ref: https://golang.org/pkg/sync/atomic/#pkg-note-BUG
|
2016-05-05 15:51:56 -04:00
|
|
|
diskPath string
|
|
|
|
minFreeDisk int64
|
2016-03-28 12:52:09 -04:00
|
|
|
}
|
|
|
|
|
2016-06-09 01:02:10 -04:00
|
|
|
var errFaultyDisk = errors.New("Faulty disk")
|
|
|
|
|
2016-05-11 15:55:02 -04:00
|
|
|
// checkPathLength - returns error if given path name length more than 255
|
|
|
|
func checkPathLength(pathName string) error {
|
2016-07-03 14:17:08 -04:00
|
|
|
// Apple OS X path length is limited to 1016
|
|
|
|
if runtime.GOOS == "darwin" && len(pathName) > 1016 {
|
|
|
|
return errFileNameTooLong
|
|
|
|
}
|
|
|
|
|
2016-06-13 05:53:09 -04:00
|
|
|
// Check each path segment length is > 255
|
2016-05-11 15:55:02 -04:00
|
|
|
for len(pathName) > 0 && pathName != "." && pathName != "/" {
|
|
|
|
dir, file := slashpath.Dir(pathName), slashpath.Base(pathName)
|
|
|
|
|
|
|
|
if len(file) > 255 {
|
|
|
|
return errFileNameTooLong
|
|
|
|
}
|
|
|
|
|
|
|
|
pathName = dir
|
2016-06-13 05:53:09 -04:00
|
|
|
} // Success.
|
2016-05-11 15:55:02 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-04-08 13:37:38 -04:00
|
|
|
// isDirEmpty - returns whether given directory is empty or not.
|
2016-05-08 04:58:05 -04:00
|
|
|
func isDirEmpty(dirname string) bool {
|
2016-04-08 13:37:38 -04:00
|
|
|
f, err := os.Open(dirname)
|
2016-05-08 04:58:05 -04:00
|
|
|
if err != nil {
|
2016-05-16 17:31:28 -04:00
|
|
|
errorIf(err, "Unable to access directory.")
|
2016-05-08 04:58:05 -04:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
// List one entry.
|
|
|
|
_, err = f.Readdirnames(1)
|
|
|
|
if err != nil {
|
|
|
|
if err == io.EOF {
|
2016-05-16 17:31:28 -04:00
|
|
|
// Returns true if we have reached EOF, directory is indeed empty.
|
2016-05-08 04:58:05 -04:00
|
|
|
return true
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
2016-05-16 17:31:28 -04:00
|
|
|
errorIf(err, "Unable to list directory.")
|
2016-05-08 04:58:05 -04:00
|
|
|
return false
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
2016-05-08 04:58:05 -04:00
|
|
|
// Directory is not empty.
|
|
|
|
return false
|
2016-02-18 03:38:58 -05:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:37:38 -04:00
|
|
|
// Initialize a new storage disk.
|
2016-04-29 17:24:10 -04:00
|
|
|
func newPosix(diskPath string) (StorageAPI, error) {
|
2016-04-08 13:37:38 -04:00
|
|
|
if diskPath == "" {
|
|
|
|
return nil, errInvalidArgument
|
|
|
|
}
|
2016-06-13 05:53:09 -04:00
|
|
|
var err error
|
|
|
|
// Disallow relative paths, figure out absolute paths.
|
|
|
|
diskPath, err = filepath.Abs(diskPath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-06-20 19:57:14 -04:00
|
|
|
fs := &posix{
|
2016-05-11 21:58:32 -04:00
|
|
|
diskPath: diskPath,
|
|
|
|
minFreeDisk: fsMinSpacePercent, // Minimum 5% disk should be free.
|
2016-05-11 15:55:02 -04:00
|
|
|
}
|
2016-06-13 05:53:09 -04:00
|
|
|
st, err := os.Stat(preparePath(diskPath))
|
2016-04-22 02:40:01 -04:00
|
|
|
if err != nil {
|
2016-05-11 21:58:32 -04:00
|
|
|
if os.IsNotExist(err) {
|
2016-06-29 06:13:44 -04:00
|
|
|
// Disk not found create it.
|
|
|
|
if err = os.MkdirAll(diskPath, 0777); err != nil {
|
|
|
|
return fs, err
|
|
|
|
}
|
|
|
|
return fs, nil
|
2016-05-11 21:58:32 -04:00
|
|
|
}
|
|
|
|
return fs, err
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
|
|
|
if !st.IsDir() {
|
2016-05-11 21:58:32 -04:00
|
|
|
return fs, syscall.ENOTDIR
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
|
|
|
return fs, nil
|
|
|
|
}
|
2016-01-25 02:03:38 -05:00
|
|
|
|
2016-06-29 14:25:35 -04:00
|
|
|
// getDiskInfo returns given disk information.
|
|
|
|
func getDiskInfo(diskPath string) (di disk.Info, err error) {
|
|
|
|
if err = checkPathLength(diskPath); err == nil {
|
|
|
|
di, err = disk.GetInfo(diskPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
err = errDiskNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
return di, err
|
|
|
|
}
|
|
|
|
|
2016-07-04 01:34:45 -04:00
|
|
|
// checkDiskFree verifies if disk path has sufficient minimum free disk space and files.
|
2016-04-08 13:37:38 -04:00
|
|
|
func checkDiskFree(diskPath string, minFreeDisk int64) (err error) {
|
2016-06-29 14:25:35 -04:00
|
|
|
di, err := getDiskInfo(diskPath)
|
2016-04-08 13:37:38 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-02-18 03:38:58 -05:00
|
|
|
|
2016-04-08 13:37:38 -04:00
|
|
|
// Remove 5% from total space for cumulative disk
|
|
|
|
// space used for journalling, inodes etc.
|
|
|
|
availableDiskSpace := (float64(di.Free) / (float64(di.Total) - (0.05 * float64(di.Total)))) * 100
|
2016-08-13 05:30:15 -04:00
|
|
|
if int64(availableDiskSpace) <= minFreeDisk {
|
2016-04-19 05:42:10 -04:00
|
|
|
return errDiskFull
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
2016-03-28 12:52:09 -04:00
|
|
|
|
2016-08-13 05:30:15 -04:00
|
|
|
// Some filesystems do not implement a way to provide total inodes available, instead inodes
|
|
|
|
// are allocated based on available disk space. For example CephFS, StoreNext CVFS, AzureFile driver.
|
|
|
|
// Allow for the available disk to be separately validate and we will validate inodes only if
|
|
|
|
// total inodes are provided by the underlying filesystem.
|
|
|
|
if di.Files != 0 {
|
|
|
|
availableFiles := (float64(di.Ffree) / (float64(di.Files) - (0.05 * float64(di.Files)))) * 100
|
|
|
|
if int64(availableFiles) <= minFreeDisk {
|
|
|
|
return errDiskFull
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-08 13:37:38 -04:00
|
|
|
// Success.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-05-18 00:22:27 -04:00
|
|
|
// getVolDir - will convert incoming volume names to
|
2016-04-13 14:32:47 -04:00
|
|
|
// corresponding valid volume names on the backend in a platform
|
|
|
|
// compatible way for all operating systems. If volume is not found
|
|
|
|
// an error is generated.
|
2016-06-20 19:57:14 -04:00
|
|
|
func (s *posix) getVolDir(volume string) (string, error) {
|
2016-04-13 14:32:47 -04:00
|
|
|
if !isValidVolname(volume) {
|
|
|
|
return "", errInvalidArgument
|
|
|
|
}
|
2016-05-05 04:39:26 -04:00
|
|
|
volumeDir := pathJoin(s.diskPath, volume)
|
2016-05-18 00:22:27 -04:00
|
|
|
return volumeDir, nil
|
2016-04-13 14:32:47 -04:00
|
|
|
}
|
2016-04-08 13:37:38 -04:00
|
|
|
|
2016-04-13 14:32:47 -04:00
|
|
|
// Make a volume entry.
|
2016-06-20 19:57:14 -04:00
|
|
|
func (s *posix) MakeVol(volume string) (err error) {
|
2016-06-09 01:02:10 -04:00
|
|
|
defer func() {
|
|
|
|
if err == syscall.EIO {
|
2016-06-20 19:57:14 -04:00
|
|
|
atomic.AddInt32(&s.ioErrCount, 1)
|
2016-06-09 01:02:10 -04:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if s.ioErrCount > maxAllowedIOError {
|
|
|
|
return errFaultyDisk
|
|
|
|
}
|
|
|
|
|
2016-04-24 03:36:00 -04:00
|
|
|
// Validate if disk is free.
|
|
|
|
if err = checkDiskFree(s.diskPath, s.minFreeDisk); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-05-18 00:22:27 -04:00
|
|
|
volumeDir, err := s.getVolDir(volume)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
2016-06-23 23:19:27 -04:00
|
|
|
// Make a volume entry, with mode 0777 mkdir honors system umask.
|
|
|
|
err = os.Mkdir(preparePath(volumeDir), 0777)
|
2016-07-02 04:59:28 -04:00
|
|
|
if err != nil {
|
|
|
|
if os.IsExist(err) {
|
|
|
|
return errVolumeExists
|
|
|
|
} else if os.IsPermission(err) {
|
|
|
|
return errDiskAccessDenied
|
|
|
|
}
|
|
|
|
return err
|
2016-04-13 14:32:47 -04:00
|
|
|
}
|
2016-05-18 00:22:27 -04:00
|
|
|
// Success
|
|
|
|
return nil
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListVols - list volumes.
|
2016-06-20 19:57:14 -04:00
|
|
|
func (s *posix) ListVols() (volsInfo []VolInfo, err error) {
|
2016-06-09 01:02:10 -04:00
|
|
|
defer func() {
|
|
|
|
if err == syscall.EIO {
|
2016-06-20 19:57:14 -04:00
|
|
|
atomic.AddInt32(&s.ioErrCount, 1)
|
2016-06-09 01:02:10 -04:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if s.ioErrCount > maxAllowedIOError {
|
|
|
|
return nil, errFaultyDisk
|
|
|
|
}
|
|
|
|
|
2016-05-18 00:22:27 -04:00
|
|
|
volsInfo, err = listVols(s.diskPath)
|
2016-04-08 13:37:38 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-04-17 15:00:23 -04:00
|
|
|
for i, vol := range volsInfo {
|
2016-04-08 13:37:38 -04:00
|
|
|
volInfo := VolInfo{
|
2016-05-19 21:52:55 -04:00
|
|
|
Name: vol.Name,
|
2016-04-16 15:48:41 -04:00
|
|
|
Created: vol.Created,
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
2016-04-17 15:00:23 -04:00
|
|
|
volsInfo[i] = volInfo
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
|
|
|
return volsInfo, nil
|
2015-10-16 14:26:01 -04:00
|
|
|
}
|
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-12 18:27:10 -05:00
|
|
|
|
2016-08-11 22:57:14 -04:00
|
|
|
// List all the volumes from diskPath.
|
|
|
|
func listVols(dirPath string) ([]VolInfo, error) {
|
|
|
|
if err := checkPathLength(dirPath); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
entries, err := readDir(dirPath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errDiskNotFound
|
|
|
|
}
|
|
|
|
var volsInfo []VolInfo
|
|
|
|
for _, entry := range entries {
|
|
|
|
if !strings.HasSuffix(entry, slashSeparator) || !isValidVolname(slashpath.Clean(entry)) {
|
|
|
|
// Skip if entry is neither a directory not a valid volume name.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
var fi os.FileInfo
|
|
|
|
fi, err = os.Stat(preparePath(pathJoin(dirPath, entry)))
|
|
|
|
if err != nil {
|
|
|
|
// If the file does not exist, skip the entry.
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
volsInfo = append(volsInfo, VolInfo{
|
|
|
|
Name: fi.Name(),
|
|
|
|
// As os.Stat() doesn't carry other than ModTime(), use
|
|
|
|
// ModTime() as CreatedTime.
|
|
|
|
Created: fi.ModTime(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return volsInfo, nil
|
|
|
|
}
|
|
|
|
|
2016-04-08 13:37:38 -04:00
|
|
|
// StatVol - get volume info.
|
2016-06-20 19:57:14 -04:00
|
|
|
func (s *posix) StatVol(volume string) (volInfo VolInfo, err error) {
|
2016-06-09 01:02:10 -04:00
|
|
|
defer func() {
|
|
|
|
if err == syscall.EIO {
|
2016-06-20 19:57:14 -04:00
|
|
|
atomic.AddInt32(&s.ioErrCount, 1)
|
2016-06-09 01:02:10 -04:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if s.ioErrCount > maxAllowedIOError {
|
|
|
|
return VolInfo{}, errFaultyDisk
|
|
|
|
}
|
|
|
|
|
2016-06-29 14:25:35 -04:00
|
|
|
// Check disk availability.
|
|
|
|
if _, err = getDiskInfo(s.diskPath); err != nil {
|
2016-06-02 19:34:15 -04:00
|
|
|
return VolInfo{}, err
|
|
|
|
}
|
|
|
|
|
2016-04-13 14:32:47 -04:00
|
|
|
// Verify if volume is valid and it exists.
|
2016-05-18 00:22:27 -04:00
|
|
|
volumeDir, err := s.getVolDir(volume)
|
2016-04-13 14:32:47 -04:00
|
|
|
if err != nil {
|
|
|
|
return VolInfo{}, err
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
|
|
|
// Stat a volume entry.
|
|
|
|
var st os.FileInfo
|
2016-06-13 05:53:09 -04:00
|
|
|
st, err = os.Stat(preparePath(volumeDir))
|
2016-04-08 13:37:38 -04:00
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return VolInfo{}, errVolumeNotFound
|
|
|
|
}
|
|
|
|
return VolInfo{}, err
|
2016-04-08 20:13:16 -04:00
|
|
|
}
|
2016-04-16 15:48:41 -04:00
|
|
|
// As os.Stat() doesn't carry other than ModTime(), use ModTime()
|
|
|
|
// as CreatedTime.
|
2016-04-13 14:32:47 -04:00
|
|
|
createdTime := st.ModTime()
|
2016-04-08 13:37:38 -04:00
|
|
|
return VolInfo{
|
2016-04-13 14:32:47 -04:00
|
|
|
Name: volume,
|
|
|
|
Created: createdTime,
|
2016-04-08 13:37:38 -04:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteVol - delete a volume.
|
2016-06-20 19:57:14 -04:00
|
|
|
func (s *posix) DeleteVol(volume string) (err error) {
|
2016-06-09 01:02:10 -04:00
|
|
|
defer func() {
|
|
|
|
if err == syscall.EIO {
|
2016-06-20 19:57:14 -04:00
|
|
|
atomic.AddInt32(&s.ioErrCount, 1)
|
2016-06-09 01:02:10 -04:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if s.ioErrCount > maxAllowedIOError {
|
|
|
|
return errFaultyDisk
|
|
|
|
}
|
|
|
|
|
2016-06-29 14:25:35 -04:00
|
|
|
// Check disk availability.
|
|
|
|
if _, err = getDiskInfo(s.diskPath); err != nil {
|
2016-06-03 01:49:27 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-04-13 14:32:47 -04:00
|
|
|
// Verify if volume is valid and it exists.
|
2016-05-18 00:22:27 -04:00
|
|
|
volumeDir, err := s.getVolDir(volume)
|
2016-04-13 14:32:47 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
2016-06-13 05:53:09 -04:00
|
|
|
err = os.Remove(preparePath(volumeDir))
|
2016-04-16 15:48:41 -04:00
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return errVolumeNotFound
|
|
|
|
} else if strings.Contains(err.Error(), "directory is not empty") {
|
2016-03-28 00:52:38 -04:00
|
|
|
// On windows the string is slightly different, handle it here.
|
2016-04-16 15:48:41 -04:00
|
|
|
return errVolumeNotEmpty
|
|
|
|
} else if strings.Contains(err.Error(), "directory not empty") {
|
2016-05-18 00:22:27 -04:00
|
|
|
// Hopefully for all other operating systems, this is
|
2016-04-16 15:48:41 -04:00
|
|
|
// assumed to be consistent.
|
|
|
|
return errVolumeNotEmpty
|
|
|
|
}
|
|
|
|
return err
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
2016-03-28 00:52:38 -04:00
|
|
|
return nil
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
|
|
|
|
2016-05-05 15:51:56 -04:00
|
|
|
// ListDir - return all the entries at the given directory path.
|
|
|
|
// If an entry is a directory it will be returned with a trailing "/".
|
2016-06-20 19:57:14 -04:00
|
|
|
func (s *posix) ListDir(volume, dirPath string) (entries []string, err error) {
|
2016-06-09 01:02:10 -04:00
|
|
|
defer func() {
|
|
|
|
if err == syscall.EIO {
|
2016-06-20 19:57:14 -04:00
|
|
|
atomic.AddInt32(&s.ioErrCount, 1)
|
2016-06-09 01:02:10 -04:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if s.ioErrCount > maxAllowedIOError {
|
|
|
|
return nil, errFaultyDisk
|
|
|
|
}
|
|
|
|
|
2016-06-29 14:25:35 -04:00
|
|
|
// Check disk availability.
|
|
|
|
if _, err = getDiskInfo(s.diskPath); err != nil {
|
2016-06-03 01:49:27 -04:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-04-13 14:32:47 -04:00
|
|
|
// Verify if volume is valid and it exists.
|
2016-05-18 00:22:27 -04:00
|
|
|
volumeDir, err := s.getVolDir(volume)
|
2016-04-13 14:32:47 -04:00
|
|
|
if err != nil {
|
2016-05-05 15:51:56 -04:00
|
|
|
return nil, err
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
2016-05-05 15:51:56 -04:00
|
|
|
// Stat a volume entry.
|
2016-06-13 05:53:09 -04:00
|
|
|
_, err = os.Stat(preparePath(volumeDir))
|
2016-05-05 15:51:56 -04:00
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return nil, errVolumeNotFound
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
2016-05-05 15:51:56 -04:00
|
|
|
return nil, err
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
2016-05-05 15:51:56 -04:00
|
|
|
return readDir(pathJoin(volumeDir, dirPath))
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
|
|
|
|
2016-06-25 17:51:06 -04:00
|
|
|
// ReadAll reads from r until an error or EOF and returns the data it read.
|
|
|
|
// A successful call returns err == nil, not err == EOF. Because ReadAll is
|
|
|
|
// defined to read from src until EOF, it does not treat an EOF from Read
|
|
|
|
// as an error to be reported.
|
|
|
|
// This API is meant to be used on files which have small memory footprint, do
|
|
|
|
// not use this on large files as it would cause server to crash.
|
|
|
|
func (s *posix) ReadAll(volume, path string) (buf []byte, err error) {
|
|
|
|
defer func() {
|
|
|
|
if err == syscall.EIO {
|
|
|
|
atomic.AddInt32(&s.ioErrCount, 1)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if s.ioErrCount > maxAllowedIOError {
|
|
|
|
return nil, errFaultyDisk
|
|
|
|
}
|
2016-06-29 14:25:35 -04:00
|
|
|
|
|
|
|
// Check disk availability.
|
|
|
|
if _, err = getDiskInfo(s.diskPath); err != nil {
|
2016-06-25 17:51:06 -04:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
volumeDir, err := s.getVolDir(volume)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// Stat a volume entry.
|
|
|
|
_, err = os.Stat(preparePath(volumeDir))
|
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return nil, errVolumeNotFound
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate file path length, before reading.
|
|
|
|
filePath := pathJoin(volumeDir, path)
|
|
|
|
if err = checkPathLength(filePath); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open the file for reading.
|
|
|
|
buf, err = ioutil.ReadFile(preparePath(filePath))
|
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return nil, errFileNotFound
|
|
|
|
} else if os.IsPermission(err) {
|
|
|
|
return nil, errFileAccessDenied
|
|
|
|
} else if pathErr, ok := err.(*os.PathError); ok {
|
2016-07-11 03:15:37 -04:00
|
|
|
switch pathErr.Err {
|
|
|
|
case syscall.ENOTDIR, syscall.EISDIR:
|
2016-06-25 17:51:06 -04:00
|
|
|
return nil, errFileNotFound
|
2016-07-11 03:15:37 -04:00
|
|
|
default:
|
|
|
|
if strings.Contains(pathErr.Err.Error(), "The handle is invalid") {
|
|
|
|
// This case is special and needs to be handled for windows.
|
|
|
|
return nil, errFileNotFound
|
|
|
|
}
|
2016-06-25 17:51:06 -04:00
|
|
|
}
|
|
|
|
return nil, pathErr
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return buf, nil
|
|
|
|
}
|
|
|
|
|
2016-05-28 18:13:15 -04:00
|
|
|
// ReadFile reads exactly len(buf) bytes into buf. It returns the
|
|
|
|
// number of bytes copied. The error is EOF only if no bytes were
|
|
|
|
// read. On return, n == len(buf) if and only if err == nil. n == 0
|
|
|
|
// for io.EOF. Additionally ReadFile also starts reading from an
|
|
|
|
// offset.
|
2016-06-20 19:57:14 -04:00
|
|
|
func (s *posix) ReadFile(volume string, path string, offset int64, buf []byte) (n int64, err error) {
|
2016-06-09 01:02:10 -04:00
|
|
|
defer func() {
|
|
|
|
if err == syscall.EIO {
|
2016-06-20 19:57:14 -04:00
|
|
|
atomic.AddInt32(&s.ioErrCount, 1)
|
2016-06-09 01:02:10 -04:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if s.ioErrCount > maxAllowedIOError {
|
|
|
|
return 0, errFaultyDisk
|
|
|
|
}
|
|
|
|
|
2016-06-29 14:25:35 -04:00
|
|
|
// Check disk availability.
|
|
|
|
if _, err = getDiskInfo(s.diskPath); err != nil {
|
2016-06-03 01:49:27 -04:00
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
2016-05-18 00:22:27 -04:00
|
|
|
volumeDir, err := s.getVolDir(volume)
|
|
|
|
if err != nil {
|
2016-05-28 18:13:15 -04:00
|
|
|
return 0, err
|
2016-05-18 00:22:27 -04:00
|
|
|
}
|
|
|
|
// Stat a volume entry.
|
2016-06-13 05:53:09 -04:00
|
|
|
_, err = os.Stat(preparePath(volumeDir))
|
2016-04-13 14:32:47 -04:00
|
|
|
if err != nil {
|
2016-05-18 00:22:27 -04:00
|
|
|
if os.IsNotExist(err) {
|
2016-05-28 18:13:15 -04:00
|
|
|
return 0, errVolumeNotFound
|
2016-05-18 00:22:27 -04:00
|
|
|
}
|
2016-05-28 18:13:15 -04:00
|
|
|
return 0, err
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
2016-04-13 14:32:47 -04:00
|
|
|
|
2016-06-25 17:51:06 -04:00
|
|
|
// Validate effective path length before reading.
|
2016-05-05 04:39:26 -04:00
|
|
|
filePath := pathJoin(volumeDir, path)
|
2016-05-11 15:55:02 -04:00
|
|
|
if err = checkPathLength(filePath); err != nil {
|
2016-05-28 18:13:15 -04:00
|
|
|
return 0, err
|
2016-05-11 15:55:02 -04:00
|
|
|
}
|
2016-06-25 17:51:06 -04:00
|
|
|
|
|
|
|
// Open the file for reading.
|
2016-06-13 05:53:09 -04:00
|
|
|
file, err := os.Open(preparePath(filePath))
|
2016-04-08 13:37:38 -04:00
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
2016-05-28 18:13:15 -04:00
|
|
|
return 0, errFileNotFound
|
2016-04-13 14:32:47 -04:00
|
|
|
} else if os.IsPermission(err) {
|
2016-05-28 18:13:15 -04:00
|
|
|
return 0, errFileAccessDenied
|
2016-05-20 23:48:47 -04:00
|
|
|
} else if strings.Contains(err.Error(), "not a directory") {
|
2016-07-29 00:57:11 -04:00
|
|
|
return 0, errFileAccessDenied
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
2016-05-28 18:13:15 -04:00
|
|
|
return 0, err
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
2016-07-27 22:22:32 -04:00
|
|
|
|
|
|
|
// Close the file descriptor.
|
|
|
|
defer file.Close()
|
|
|
|
|
2016-04-08 13:37:38 -04:00
|
|
|
st, err := file.Stat()
|
|
|
|
if err != nil {
|
2016-05-28 18:13:15 -04:00
|
|
|
return 0, err
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
2016-07-29 00:57:11 -04:00
|
|
|
|
2016-04-08 13:37:38 -04:00
|
|
|
// Verify if its not a regular file, since subsequent Seek is undefined.
|
|
|
|
if !st.Mode().IsRegular() {
|
2016-07-29 00:57:11 -04:00
|
|
|
return 0, errIsNotRegular
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
2016-07-29 00:57:11 -04:00
|
|
|
|
2016-04-08 13:37:38 -04:00
|
|
|
// Seek to requested offset.
|
|
|
|
_, err = file.Seek(offset, os.SEEK_SET)
|
|
|
|
if err != nil {
|
2016-05-28 18:13:15 -04:00
|
|
|
return 0, err
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
2016-05-28 18:13:15 -04:00
|
|
|
|
2016-06-24 05:06:23 -04:00
|
|
|
// Read full until buffer.
|
2016-05-28 18:13:15 -04:00
|
|
|
m, err := io.ReadFull(file, buf)
|
|
|
|
|
|
|
|
// Success.
|
|
|
|
return int64(m), err
|
2016-04-08 20:13:16 -04:00
|
|
|
}
|
|
|
|
|
2016-05-28 18:13:15 -04:00
|
|
|
// AppendFile - append a byte array at path, if file doesn't exist at
|
|
|
|
// path this call explicitly creates it.
|
2016-06-20 19:57:14 -04:00
|
|
|
func (s *posix) AppendFile(volume, path string, buf []byte) (err error) {
|
2016-06-09 01:02:10 -04:00
|
|
|
defer func() {
|
|
|
|
if err == syscall.EIO {
|
2016-06-20 19:57:14 -04:00
|
|
|
atomic.AddInt32(&s.ioErrCount, 1)
|
2016-06-09 01:02:10 -04:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if s.ioErrCount > maxAllowedIOError {
|
2016-06-19 18:31:13 -04:00
|
|
|
return errFaultyDisk
|
2016-06-09 01:02:10 -04:00
|
|
|
}
|
|
|
|
|
2016-06-03 01:49:27 -04:00
|
|
|
// Validate if disk is free.
|
|
|
|
if err = checkDiskFree(s.diskPath, s.minFreeDisk); err != nil {
|
2016-06-19 18:31:13 -04:00
|
|
|
return err
|
2016-06-03 01:49:27 -04:00
|
|
|
}
|
|
|
|
|
2016-05-18 00:22:27 -04:00
|
|
|
volumeDir, err := s.getVolDir(volume)
|
2016-04-13 14:32:47 -04:00
|
|
|
if err != nil {
|
2016-06-19 18:31:13 -04:00
|
|
|
return err
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
2016-05-18 00:22:27 -04:00
|
|
|
// Stat a volume entry.
|
2016-06-13 05:53:09 -04:00
|
|
|
_, err = os.Stat(preparePath(volumeDir))
|
2016-05-18 00:22:27 -04:00
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
2016-06-19 18:31:13 -04:00
|
|
|
return errVolumeNotFound
|
2016-05-18 00:22:27 -04:00
|
|
|
}
|
2016-06-19 18:31:13 -04:00
|
|
|
return err
|
2016-05-18 00:22:27 -04:00
|
|
|
}
|
2016-05-05 04:39:26 -04:00
|
|
|
filePath := pathJoin(volumeDir, path)
|
2016-05-11 15:55:02 -04:00
|
|
|
if err = checkPathLength(filePath); err != nil {
|
2016-06-19 18:31:13 -04:00
|
|
|
return err
|
2016-05-11 15:55:02 -04:00
|
|
|
}
|
2016-04-08 13:37:38 -04:00
|
|
|
// Verify if the file already exists and is not of regular type.
|
2016-05-04 15:18:40 -04:00
|
|
|
var st os.FileInfo
|
2016-06-13 05:53:09 -04:00
|
|
|
if st, err = os.Stat(preparePath(filePath)); err == nil {
|
2016-07-29 00:57:11 -04:00
|
|
|
if !st.Mode().IsRegular() {
|
2016-06-19 18:31:13 -04:00
|
|
|
return errIsNotRegular
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
|
|
|
}
|
2016-05-28 18:13:15 -04:00
|
|
|
// Create top level directories if they don't exist.
|
2016-06-23 23:19:27 -04:00
|
|
|
// with mode 0777 mkdir honors system umask.
|
|
|
|
if err = mkdirAll(filepath.Dir(filePath), 0777); err != nil {
|
2016-07-03 14:17:08 -04:00
|
|
|
// File path cannot be verified since one of the parents is a file.
|
|
|
|
if strings.Contains(err.Error(), "not a directory") {
|
|
|
|
return errFileAccessDenied
|
|
|
|
} else if runtime.GOOS == "windows" && strings.Contains(err.Error(), "system cannot find the path specified") {
|
2016-07-29 00:57:11 -04:00
|
|
|
// Add specific case for windows.
|
2016-07-03 14:17:08 -04:00
|
|
|
return errFileAccessDenied
|
|
|
|
}
|
2016-06-19 18:31:13 -04:00
|
|
|
return err
|
2016-05-28 18:13:15 -04:00
|
|
|
}
|
2016-06-23 23:19:27 -04:00
|
|
|
|
|
|
|
// Creates the named file with mode 0666 (before umask), or starts appending
|
|
|
|
// to an existig file.
|
|
|
|
w, err := os.OpenFile(preparePath(filePath), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)
|
2016-05-04 15:18:40 -04:00
|
|
|
if err != nil {
|
|
|
|
// File path cannot be verified since one of the parents is a file.
|
|
|
|
if strings.Contains(err.Error(), "not a directory") {
|
2016-06-19 18:31:13 -04:00
|
|
|
return errFileAccessDenied
|
2016-05-04 15:18:40 -04:00
|
|
|
}
|
2016-06-19 18:31:13 -04:00
|
|
|
return err
|
2016-05-04 15:18:40 -04:00
|
|
|
}
|
2016-06-23 23:19:27 -04:00
|
|
|
|
2016-05-28 18:13:15 -04:00
|
|
|
// Close upon return.
|
|
|
|
defer w.Close()
|
|
|
|
|
|
|
|
// Return io.Copy
|
2016-06-19 18:31:13 -04:00
|
|
|
_, err = io.Copy(w, bytes.NewReader(buf))
|
|
|
|
return err
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// StatFile - get file info.
|
2016-06-20 19:57:14 -04:00
|
|
|
func (s *posix) StatFile(volume, path string) (file FileInfo, err error) {
|
2016-06-09 01:02:10 -04:00
|
|
|
defer func() {
|
|
|
|
if err == syscall.EIO {
|
2016-06-20 19:57:14 -04:00
|
|
|
atomic.AddInt32(&s.ioErrCount, 1)
|
2016-06-09 01:02:10 -04:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if s.ioErrCount > maxAllowedIOError {
|
|
|
|
return FileInfo{}, errFaultyDisk
|
|
|
|
}
|
|
|
|
|
2016-06-29 14:25:35 -04:00
|
|
|
// Check disk availability.
|
|
|
|
if _, err = getDiskInfo(s.diskPath); err != nil {
|
2016-06-03 01:49:27 -04:00
|
|
|
return FileInfo{}, err
|
|
|
|
}
|
|
|
|
|
2016-05-18 00:22:27 -04:00
|
|
|
volumeDir, err := s.getVolDir(volume)
|
|
|
|
if err != nil {
|
|
|
|
return FileInfo{}, err
|
|
|
|
}
|
|
|
|
// Stat a volume entry.
|
2016-06-13 05:53:09 -04:00
|
|
|
_, err = os.Stat(preparePath(volumeDir))
|
2016-04-13 14:32:47 -04:00
|
|
|
if err != nil {
|
2016-05-18 00:22:27 -04:00
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return FileInfo{}, errVolumeNotFound
|
|
|
|
}
|
2016-04-13 14:32:47 -04:00
|
|
|
return FileInfo{}, err
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
|
|
|
|
2016-05-09 03:46:54 -04:00
|
|
|
filePath := slashpath.Join(volumeDir, path)
|
2016-05-11 15:55:02 -04:00
|
|
|
if err = checkPathLength(filePath); err != nil {
|
|
|
|
return FileInfo{}, err
|
|
|
|
}
|
2016-06-13 05:53:09 -04:00
|
|
|
st, err := os.Stat(preparePath(filePath))
|
2016-04-08 13:37:38 -04:00
|
|
|
if err != nil {
|
2016-04-13 14:32:47 -04:00
|
|
|
// File is really not found.
|
2016-04-08 13:37:38 -04:00
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return FileInfo{}, errFileNotFound
|
|
|
|
}
|
2016-04-24 03:36:00 -04:00
|
|
|
|
2016-04-13 14:32:47 -04:00
|
|
|
// File path cannot be verified since one of the parents is a file.
|
2016-04-12 15:45:15 -04:00
|
|
|
if strings.Contains(err.Error(), "not a directory") {
|
2016-04-25 13:39:28 -04:00
|
|
|
return FileInfo{}, errFileNotFound
|
2016-04-12 15:45:15 -04:00
|
|
|
}
|
2016-04-24 03:36:00 -04:00
|
|
|
|
2016-04-13 14:32:47 -04:00
|
|
|
// Return all errors here.
|
2016-04-08 13:37:38 -04:00
|
|
|
return FileInfo{}, err
|
|
|
|
}
|
2016-04-13 14:32:47 -04:00
|
|
|
// If its a directory its not a regular file.
|
2016-04-08 13:37:38 -04:00
|
|
|
if st.Mode().IsDir() {
|
2016-04-25 13:39:28 -04:00
|
|
|
return FileInfo{}, errFileNotFound
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
2016-04-24 03:36:00 -04:00
|
|
|
return FileInfo{
|
2016-04-08 13:37:38 -04:00
|
|
|
Volume: volume,
|
|
|
|
Name: path,
|
|
|
|
ModTime: st.ModTime(),
|
|
|
|
Size: st.Size(),
|
|
|
|
Mode: st.Mode(),
|
2016-04-24 03:36:00 -04:00
|
|
|
}, nil
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// deleteFile - delete file path if its empty.
|
2016-04-13 14:32:47 -04:00
|
|
|
func deleteFile(basePath, deletePath string) error {
|
2016-04-08 13:37:38 -04:00
|
|
|
if basePath == deletePath {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
// Verify if the path exists.
|
2016-06-13 05:53:09 -04:00
|
|
|
pathSt, err := os.Stat(preparePath(deletePath))
|
2016-04-13 14:32:47 -04:00
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return errFileNotFound
|
|
|
|
} else if os.IsPermission(err) {
|
|
|
|
return errFileAccessDenied
|
|
|
|
}
|
|
|
|
return err
|
2016-04-08 20:13:16 -04:00
|
|
|
}
|
2016-05-08 04:58:05 -04:00
|
|
|
if pathSt.IsDir() && !isDirEmpty(deletePath) {
|
2016-04-08 13:37:38 -04:00
|
|
|
// Verify if directory is empty.
|
2016-05-08 04:58:05 -04:00
|
|
|
return nil
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
|
|
|
// Attempt to remove path.
|
2016-06-13 05:53:09 -04:00
|
|
|
if err := os.Remove(preparePath(deletePath)); err != nil {
|
2016-04-13 14:32:47 -04:00
|
|
|
return err
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
|
|
|
// Recursively go down the next path and delete again.
|
2016-05-09 03:46:54 -04:00
|
|
|
if err := deleteFile(basePath, slashpath.Dir(deletePath)); err != nil {
|
2016-04-13 14:32:47 -04:00
|
|
|
return err
|
2016-04-08 20:13:16 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-04-08 13:37:38 -04:00
|
|
|
// DeleteFile - delete a file at path.
|
2016-06-20 19:57:14 -04:00
|
|
|
func (s *posix) DeleteFile(volume, path string) (err error) {
|
2016-06-09 01:02:10 -04:00
|
|
|
defer func() {
|
|
|
|
if err == syscall.EIO {
|
2016-06-20 19:57:14 -04:00
|
|
|
atomic.AddInt32(&s.ioErrCount, 1)
|
2016-06-09 01:02:10 -04:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if s.ioErrCount > maxAllowedIOError {
|
|
|
|
return errFaultyDisk
|
|
|
|
}
|
|
|
|
|
2016-06-29 14:25:35 -04:00
|
|
|
// Check disk availability.
|
|
|
|
if _, err = getDiskInfo(s.diskPath); err != nil {
|
2016-06-03 01:49:27 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-05-18 00:22:27 -04:00
|
|
|
volumeDir, err := s.getVolDir(volume)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Stat a volume entry.
|
2016-06-13 05:53:09 -04:00
|
|
|
_, err = os.Stat(preparePath(volumeDir))
|
2016-04-13 14:32:47 -04:00
|
|
|
if err != nil {
|
2016-05-18 00:22:27 -04:00
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return errVolumeNotFound
|
|
|
|
}
|
2016-04-13 14:32:47 -04:00
|
|
|
return err
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Following code is needed so that we retain "/" suffix if any in
|
2016-04-13 14:32:47 -04:00
|
|
|
// path argument.
|
2016-05-05 04:39:26 -04:00
|
|
|
filePath := pathJoin(volumeDir, path)
|
2016-05-11 15:55:02 -04:00
|
|
|
if err = checkPathLength(filePath); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-04-08 13:37:38 -04:00
|
|
|
|
|
|
|
// Delete file and delete parent directory as well if its empty.
|
2016-04-13 14:32:47 -04:00
|
|
|
return deleteFile(volumeDir, filePath)
|
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-12 18:27:10 -05:00
|
|
|
}
|
2016-04-29 15:17:48 -04:00
|
|
|
|
2016-05-28 18:13:15 -04:00
|
|
|
// RenameFile - rename source path to destination path atomically.
|
2016-06-20 19:57:14 -04:00
|
|
|
func (s *posix) RenameFile(srcVolume, srcPath, dstVolume, dstPath string) (err error) {
|
2016-06-09 01:02:10 -04:00
|
|
|
defer func() {
|
|
|
|
if err == syscall.EIO {
|
2016-06-20 19:57:14 -04:00
|
|
|
atomic.AddInt32(&s.ioErrCount, 1)
|
2016-06-09 01:02:10 -04:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if s.ioErrCount > maxAllowedIOError {
|
|
|
|
return errFaultyDisk
|
|
|
|
}
|
|
|
|
|
2016-06-03 01:49:27 -04:00
|
|
|
// Validate if disk is free.
|
2016-06-09 01:02:10 -04:00
|
|
|
if err = checkDiskFree(s.diskPath, s.minFreeDisk); err != nil {
|
2016-06-03 01:49:27 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-05-18 00:22:27 -04:00
|
|
|
srcVolumeDir, err := s.getVolDir(srcVolume)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
dstVolumeDir, err := s.getVolDir(dstVolume)
|
2016-04-29 15:17:48 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-05-18 00:22:27 -04:00
|
|
|
// Stat a volume entry.
|
2016-06-13 05:53:09 -04:00
|
|
|
_, err = os.Stat(preparePath(srcVolumeDir))
|
2016-04-29 15:17:48 -04:00
|
|
|
if err != nil {
|
2016-05-18 00:22:27 -04:00
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return errVolumeNotFound
|
|
|
|
}
|
2016-04-29 15:17:48 -04:00
|
|
|
return err
|
|
|
|
}
|
2016-06-13 05:53:09 -04:00
|
|
|
_, err = os.Stat(preparePath(dstVolumeDir))
|
2016-05-18 00:22:27 -04:00
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return errVolumeNotFound
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-13 14:52:36 -04:00
|
|
|
srcIsDir := strings.HasSuffix(srcPath, slashSeparator)
|
|
|
|
dstIsDir := strings.HasSuffix(dstPath, slashSeparator)
|
2016-05-16 17:31:28 -04:00
|
|
|
// Either src and dst have to be directories or files, else return error.
|
2016-05-13 14:52:36 -04:00
|
|
|
if !(srcIsDir && dstIsDir || !srcIsDir && !dstIsDir) {
|
|
|
|
return errFileAccessDenied
|
|
|
|
}
|
2016-06-17 14:57:51 -04:00
|
|
|
srcFilePath := slashpath.Join(srcVolumeDir, srcPath)
|
|
|
|
if err = checkPathLength(srcFilePath); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
dstFilePath := slashpath.Join(dstVolumeDir, dstPath)
|
|
|
|
if err = checkPathLength(dstFilePath); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-05-13 14:52:36 -04:00
|
|
|
if srcIsDir {
|
|
|
|
// If source is a directory we expect the destination to be non-existent always.
|
2016-06-17 14:57:51 -04:00
|
|
|
_, err = os.Stat(preparePath(dstFilePath))
|
2016-05-13 14:52:36 -04:00
|
|
|
if err == nil {
|
|
|
|
return errFileAccessDenied
|
|
|
|
}
|
|
|
|
if !os.IsNotExist(err) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Destination does not exist, hence proceed with the rename.
|
|
|
|
}
|
2016-06-23 23:19:27 -04:00
|
|
|
// Creates all the parent directories, with mode 0777 mkdir honors system umask.
|
|
|
|
if err = mkdirAll(preparePath(slashpath.Dir(dstFilePath)), 0777); err != nil {
|
2016-05-04 15:18:40 -04:00
|
|
|
// File path cannot be verified since one of the parents is a file.
|
|
|
|
if strings.Contains(err.Error(), "not a directory") {
|
|
|
|
return errFileAccessDenied
|
2016-06-20 09:18:47 -04:00
|
|
|
} else if strings.Contains(err.Error(), "The system cannot find the path specified.") && runtime.GOOS == "windows" {
|
|
|
|
// This is a special case should be handled only for
|
|
|
|
// windows, because windows API does not return "not a
|
|
|
|
// directory" error message. Handle this specifically here.
|
|
|
|
return errFileAccessDenied
|
2016-05-04 15:18:40 -04:00
|
|
|
}
|
2016-04-29 15:17:48 -04:00
|
|
|
return err
|
|
|
|
}
|
2016-06-23 23:19:27 -04:00
|
|
|
// Finally attempt a rename.
|
2016-06-17 14:57:51 -04:00
|
|
|
err = os.Rename(preparePath(srcFilePath), preparePath(dstFilePath))
|
2016-05-03 19:10:24 -04:00
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return errFileNotFound
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
2016-04-29 15:17:48 -04:00
|
|
|
}
|