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-04-08 13:37:38 -04:00
|
|
|
"io"
|
2016-04-08 20:13:16 -04:00
|
|
|
"os"
|
2016-05-09 03:46:54 -04:00
|
|
|
slashpath "path"
|
2016-05-11 15:55:02 -04:00
|
|
|
"runtime"
|
2016-04-08 13:37:38 -04:00
|
|
|
"strings"
|
|
|
|
"syscall"
|
2015-10-16 14:26:01 -04:00
|
|
|
|
2016-04-08 20:13:16 -04:00
|
|
|
"github.com/minio/minio/pkg/disk"
|
2016-04-08 13:37:38 -04:00
|
|
|
"github.com/minio/minio/pkg/safe"
|
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-04-08 13:37:38 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// fsStorage - implements StorageAPI interface.
|
|
|
|
type fsStorage struct {
|
2016-05-05 15:51:56 -04:00
|
|
|
diskPath string
|
|
|
|
minFreeDisk int64
|
2016-03-28 12:52:09 -04:00
|
|
|
}
|
|
|
|
|
2016-05-11 15:55:02 -04:00
|
|
|
// checkPathLength - returns error if given path name length more than 255
|
|
|
|
func checkPathLength(pathName string) error {
|
|
|
|
// For MS Windows, the maximum path length is 255
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
if len(pathName) > 255 {
|
|
|
|
return errFileNameTooLong
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// For non-windows system, check each path segment length is > 255
|
|
|
|
for len(pathName) > 0 && pathName != "." && pathName != "/" {
|
|
|
|
dir, file := slashpath.Dir(pathName), slashpath.Base(pathName)
|
|
|
|
|
|
|
|
if len(file) > 255 {
|
|
|
|
return errFileNameTooLong
|
|
|
|
}
|
|
|
|
|
|
|
|
pathName = dir
|
|
|
|
}
|
|
|
|
|
|
|
|
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-05-11 21:58:32 -04:00
|
|
|
fs := fsStorage{
|
|
|
|
diskPath: diskPath,
|
|
|
|
minFreeDisk: fsMinSpacePercent, // Minimum 5% disk should be free.
|
2016-05-11 15:55:02 -04:00
|
|
|
}
|
2016-04-22 02:40:01 -04:00
|
|
|
st, err := os.Stat(diskPath)
|
|
|
|
if err != nil {
|
2016-05-11 21:58:32 -04:00
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return fs, errDiskNotFound
|
|
|
|
}
|
|
|
|
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-05-08 04:58:05 -04:00
|
|
|
// checkDiskFree verifies if disk path has sufficient minium free disk space.
|
2016-04-08 13:37:38 -04:00
|
|
|
func checkDiskFree(diskPath string, minFreeDisk int64) (err error) {
|
2016-05-11 15:55:02 -04:00
|
|
|
if err = checkPathLength(diskPath); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-04-08 13:37:38 -04:00
|
|
|
di, err := disk.GetInfo(diskPath)
|
|
|
|
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
|
|
|
|
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-04-08 13:37:38 -04:00
|
|
|
// Success.
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-05-18 00:22:27 -04:00
|
|
|
// List all the volumes from diskPath.
|
|
|
|
func listVols(dirPath string) ([]VolInfo, error) {
|
2016-05-11 15:55:02 -04:00
|
|
|
if err := checkPathLength(dirPath); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-05-05 15:51:56 -04:00
|
|
|
entries, err := readDir(dirPath)
|
2016-04-16 15:48:41 -04:00
|
|
|
if err != nil {
|
2016-05-11 15:54:21 -04:00
|
|
|
return nil, errDiskNotFound
|
2016-04-16 15:48:41 -04:00
|
|
|
}
|
|
|
|
var volsInfo []VolInfo
|
2016-05-05 15:51:56 -04:00
|
|
|
for _, entry := range entries {
|
2016-05-09 03:46:54 -04:00
|
|
|
if !strings.HasSuffix(entry, slashSeparator) || !isValidVolname(slashpath.Clean(entry)) {
|
2016-05-05 15:51:56 -04:00
|
|
|
// Skip if entry is neither a directory not a valid volume name.
|
|
|
|
continue
|
|
|
|
}
|
2016-05-11 15:54:21 -04:00
|
|
|
var fi os.FileInfo
|
|
|
|
fi, err = os.Stat(pathJoin(dirPath, entry))
|
2016-04-16 15:48:41 -04:00
|
|
|
if err != nil {
|
2016-05-11 15:54:21 -04:00
|
|
|
// If the file does not exist, skip the entry.
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
continue
|
|
|
|
}
|
2016-04-16 15:48:41 -04:00
|
|
|
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(),
|
|
|
|
})
|
|
|
|
}
|
2016-05-18 00:22:27 -04:00
|
|
|
return volsInfo, nil
|
2016-04-16 15:48:41 -04:00
|
|
|
}
|
|
|
|
|
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-05-18 00:22:27 -04:00
|
|
|
func (s fsStorage) getVolDir(volume string) (string, error) {
|
2016-04-13 14:32:47 -04:00
|
|
|
if !isValidVolname(volume) {
|
|
|
|
return "", errInvalidArgument
|
|
|
|
}
|
2016-05-11 15:55:02 -04:00
|
|
|
if err := checkPathLength(volume); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
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.
|
|
|
|
func (s fsStorage) MakeVol(volume string) (err error) {
|
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-05-18 00:22:27 -04:00
|
|
|
// Make a volume entry.
|
|
|
|
err = os.Mkdir(volumeDir, 0700)
|
|
|
|
if err != nil && os.IsExist(err) {
|
|
|
|
return errVolumeExists
|
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.
|
|
|
|
func (s fsStorage) ListVols() (volsInfo []VolInfo, err error) {
|
2016-04-21 23:07:47 -04:00
|
|
|
// Get disk info to be populated for VolInfo.
|
|
|
|
var diskInfo disk.Info
|
|
|
|
diskInfo, err = disk.GetInfo(s.diskPath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
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-13 14:32:47 -04:00
|
|
|
// Volname on case sensitive fs backends can come in as
|
|
|
|
// capitalized, but object layer cannot consume it
|
|
|
|
// directly. Convert it as we see fit.
|
2016-04-16 15:48:41 -04:00
|
|
|
volName := strings.ToLower(vol.Name)
|
2016-04-08 13:37:38 -04:00
|
|
|
volInfo := VolInfo{
|
2016-04-13 14:32:47 -04:00
|
|
|
Name: volName,
|
2016-04-16 15:48:41 -04:00
|
|
|
Created: vol.Created,
|
2016-04-21 23:07:47 -04:00
|
|
|
Total: diskInfo.Total,
|
|
|
|
Free: diskInfo.Free,
|
|
|
|
FSType: diskInfo.FSType,
|
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-04-08 13:37:38 -04:00
|
|
|
// StatVol - get volume info.
|
|
|
|
func (s fsStorage) StatVol(volume string) (volInfo VolInfo, err error) {
|
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
|
|
|
|
st, err = os.Stat(volumeDir)
|
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return VolInfo{}, errVolumeNotFound
|
|
|
|
}
|
|
|
|
return VolInfo{}, err
|
2016-04-08 20:13:16 -04:00
|
|
|
}
|
2016-04-21 23:07:47 -04:00
|
|
|
// Get disk info, to be returned back along with volume info.
|
|
|
|
var diskInfo disk.Info
|
|
|
|
diskInfo, err = disk.GetInfo(s.diskPath)
|
|
|
|
if err != nil {
|
|
|
|
return VolInfo{}, err
|
|
|
|
}
|
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-21 23:07:47 -04:00
|
|
|
Free: diskInfo.Free,
|
|
|
|
Total: diskInfo.Total,
|
|
|
|
FSType: diskInfo.FSType,
|
2016-04-08 13:37:38 -04:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteVol - delete a volume.
|
|
|
|
func (s fsStorage) DeleteVol(volume string) error {
|
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-04-13 14:32:47 -04:00
|
|
|
err = os.Remove(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 "/".
|
|
|
|
func (s fsStorage) ListDir(volume, dirPath string) ([]string, error) {
|
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.
|
|
|
|
_, err = os.Stat(volumeDir)
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// ReadFile - read a file at a given offset.
|
|
|
|
func (s fsStorage) ReadFile(volume string, path string, offset int64) (readCloser io.ReadCloser, err error) {
|
2016-05-18 00:22:27 -04:00
|
|
|
volumeDir, err := s.getVolDir(volume)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// Stat a volume entry.
|
|
|
|
_, err = os.Stat(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 nil, errVolumeNotFound
|
|
|
|
}
|
2016-04-13 14:32:47 -04:00
|
|
|
return nil, err
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
2016-04-13 14:32:47 -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 {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-04-08 13:37:38 -04:00
|
|
|
file, err := os.Open(filePath)
|
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return nil, errFileNotFound
|
2016-04-13 14:32:47 -04:00
|
|
|
} else if os.IsPermission(err) {
|
|
|
|
return nil, errFileAccessDenied
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
st, err := file.Stat()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// Verify if its not a regular file, since subsequent Seek is undefined.
|
|
|
|
if !st.Mode().IsRegular() {
|
2016-04-25 13:39:28 -04:00
|
|
|
return nil, errFileNotFound
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
|
|
|
// Seek to requested offset.
|
|
|
|
_, err = file.Seek(offset, os.SEEK_SET)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return file, nil
|
2016-04-08 20:13:16 -04:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:37:38 -04:00
|
|
|
// CreateFile - create a file at path.
|
|
|
|
func (s fsStorage) CreateFile(volume, path string) (writeCloser io.WriteCloser, err error) {
|
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 nil, err
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
2016-05-18 00:22:27 -04:00
|
|
|
// Stat a volume entry.
|
|
|
|
_, err = os.Stat(volumeDir)
|
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return nil, errVolumeNotFound
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-05-04 15:18:40 -04:00
|
|
|
if err = checkDiskFree(s.diskPath, s.minFreeDisk); err != nil {
|
2016-04-13 14:32:47 -04:00
|
|
|
return nil, err
|
2016-04-08 13:37:38 -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 {
|
|
|
|
return nil, err
|
|
|
|
}
|
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
|
|
|
|
if st, err = os.Stat(filePath); err == nil {
|
2016-04-08 13:37:38 -04:00
|
|
|
if st.IsDir() {
|
|
|
|
return nil, errIsNotRegular
|
|
|
|
}
|
|
|
|
}
|
2016-05-04 15:18:40 -04:00
|
|
|
w, err := safe.CreateFileWithPrefix(filePath, "$tmpfile")
|
|
|
|
if err != nil {
|
|
|
|
// File path cannot be verified since one of the parents is a file.
|
|
|
|
if strings.Contains(err.Error(), "not a directory") {
|
|
|
|
return nil, errFileAccessDenied
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return w, nil
|
2016-04-08 13:37:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// StatFile - get file info.
|
|
|
|
func (s fsStorage) StatFile(volume, path string) (file FileInfo, err error) {
|
2016-05-18 00:22:27 -04:00
|
|
|
volumeDir, err := s.getVolDir(volume)
|
|
|
|
if err != nil {
|
|
|
|
return FileInfo{}, err
|
|
|
|
}
|
|
|
|
// Stat a volume entry.
|
|
|
|
_, err = os.Stat(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-04-08 13:37:38 -04:00
|
|
|
st, err := os.Stat(filePath)
|
|
|
|
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-24 03:36:00 -04:00
|
|
|
|
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-04-13 14:32:47 -04:00
|
|
|
pathSt, err := os.Stat(deletePath)
|
|
|
|
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-04-13 14:32:47 -04:00
|
|
|
if err := os.Remove(deletePath); err != nil {
|
|
|
|
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.
|
|
|
|
func (s fsStorage) DeleteFile(volume, path string) error {
|
2016-05-18 00:22:27 -04:00
|
|
|
volumeDir, err := s.getVolDir(volume)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Stat a volume entry.
|
|
|
|
_, err = os.Stat(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
|
|
|
|
|
|
|
// RenameFile - rename file.
|
|
|
|
func (s fsStorage) RenameFile(srcVolume, srcPath, dstVolume, dstPath string) error {
|
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.
|
|
|
|
_, err = os.Stat(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-05-18 00:22:27 -04:00
|
|
|
_, err = os.Stat(dstVolumeDir)
|
|
|
|
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
|
|
|
|
}
|
|
|
|
if srcIsDir {
|
|
|
|
// If source is a directory we expect the destination to be non-existent always.
|
|
|
|
_, err = os.Stat(slashpath.Join(dstVolumeDir, dstPath))
|
|
|
|
if err == nil {
|
|
|
|
return errFileAccessDenied
|
|
|
|
}
|
|
|
|
if !os.IsNotExist(err) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Destination does not exist, hence proceed with the rename.
|
|
|
|
}
|
|
|
|
if err = os.MkdirAll(slashpath.Dir(slashpath.Join(dstVolumeDir, dstPath)), 0755); 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-04-29 15:17:48 -04:00
|
|
|
return err
|
|
|
|
}
|
2016-05-09 03:46:54 -04:00
|
|
|
err = os.Rename(slashpath.Join(srcVolumeDir, srcPath), slashpath.Join(dstVolumeDir, dstPath))
|
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
|
|
|
}
|