You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
188 lines
4.9 KiB
188 lines
4.9 KiB
9 years ago
|
/*
|
||
|
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
||
|
*
|
||
|
* 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.
|
||
|
*/
|
||
|
|
||
8 years ago
|
package cmd
|
||
9 years ago
|
|
||
9 years ago
|
import (
|
||
9 years ago
|
"path/filepath"
|
||
9 years ago
|
"strings"
|
||
|
"sync"
|
||
|
)
|
||
9 years ago
|
|
||
9 years ago
|
const (
|
||
|
// Block size used for all internal operations version 1.
|
||
|
blockSizeV1 = 10 * 1024 * 1024 // 10MiB.
|
||
9 years ago
|
|
||
|
// Staging buffer read size for all internal operations version 1.
|
||
|
readSizeV1 = 128 * 1024 // 128KiB.
|
||
9 years ago
|
|
||
|
// Buckets meta prefix.
|
||
|
bucketMetaPrefix = "buckets"
|
||
9 years ago
|
)
|
||
|
|
||
9 years ago
|
// isErrIgnored should we ignore this error?, takes a list of errors which can be ignored.
|
||
|
func isErrIgnored(err error, ignoredErrs []error) bool {
|
||
|
for _, ignoredErr := range ignoredErrs {
|
||
|
if ignoredErr == err {
|
||
|
return true
|
||
|
}
|
||
|
}
|
||
|
return false
|
||
|
}
|
||
|
|
||
9 years ago
|
// House keeping code needed for FS.
|
||
|
func fsHouseKeeping(storageDisk StorageAPI) error {
|
||
|
// Cleanup all temp entries upon start.
|
||
9 years ago
|
err := cleanupDir(storageDisk, minioMetaBucket, tmpMetaPrefix)
|
||
9 years ago
|
if err != nil {
|
||
9 years ago
|
return toObjectErr(err, minioMetaBucket, tmpMetaPrefix)
|
||
9 years ago
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
9 years ago
|
// Depending on the disk type network or local, initialize storage API.
|
||
|
func newStorageAPI(disk string) (storage StorageAPI, err error) {
|
||
|
if !strings.ContainsRune(disk, ':') || filepath.VolumeName(disk) != "" {
|
||
|
// Initialize filesystem storage API.
|
||
|
return newPosix(disk)
|
||
|
}
|
||
|
// Initialize rpc client storage API.
|
||
|
return newRPCClient(disk)
|
||
|
}
|
||
|
|
||
9 years ago
|
// Initializes meta volume on all input storage disks.
|
||
|
func initMetaVolume(storageDisks []StorageAPI) error {
|
||
9 years ago
|
// This happens for the first time, but keep this here since this
|
||
|
// is the only place where it can be made expensive optimizing all
|
||
|
// other calls. Create minio meta volume, if it doesn't exist yet.
|
||
9 years ago
|
var wg = &sync.WaitGroup{}
|
||
|
|
||
|
// Initialize errs to collect errors inside go-routine.
|
||
|
var errs = make([]error, len(storageDisks))
|
||
|
|
||
|
// Initialize all disks in parallel.
|
||
|
for index, disk := range storageDisks {
|
||
9 years ago
|
if disk == nil {
|
||
9 years ago
|
// Ignore create meta volume on disks which are not found.
|
||
9 years ago
|
continue
|
||
|
}
|
||
9 years ago
|
wg.Add(1)
|
||
|
go func(index int, disk StorageAPI) {
|
||
|
// Indicate this wait group is done.
|
||
|
defer wg.Done()
|
||
|
|
||
|
// Attempt to create `.minio`.
|
||
|
err := disk.MakeVol(minioMetaBucket)
|
||
9 years ago
|
if err != nil {
|
||
|
switch err {
|
||
|
// Ignored errors.
|
||
|
case errVolumeExists, errDiskNotFound, errFaultyDisk:
|
||
|
default:
|
||
|
errs[index] = err
|
||
|
}
|
||
9 years ago
|
}
|
||
9 years ago
|
}(index, disk)
|
||
|
}
|
||
|
|
||
|
// Wait for all cleanup to finish.
|
||
|
wg.Wait()
|
||
|
|
||
|
// Return upon first error.
|
||
|
for _, err := range errs {
|
||
|
if err == nil {
|
||
|
continue
|
||
|
}
|
||
|
return toObjectErr(err, minioMetaBucket)
|
||
|
}
|
||
|
|
||
|
// Return success here.
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
// House keeping code needed for XL.
|
||
|
func xlHouseKeeping(storageDisks []StorageAPI) error {
|
||
|
// This happens for the first time, but keep this here since this
|
||
|
// is the only place where it can be made expensive optimizing all
|
||
|
// other calls. Create metavolume.
|
||
|
var wg = &sync.WaitGroup{}
|
||
|
|
||
|
// Initialize errs to collect errors inside go-routine.
|
||
|
var errs = make([]error, len(storageDisks))
|
||
|
|
||
|
// Initialize all disks in parallel.
|
||
|
for index, disk := range storageDisks {
|
||
|
if disk == nil {
|
||
|
continue
|
||
|
}
|
||
|
wg.Add(1)
|
||
|
go func(index int, disk StorageAPI) {
|
||
|
// Indicate this wait group is done.
|
||
|
defer wg.Done()
|
||
|
|
||
9 years ago
|
// Cleanup all temp entries upon start.
|
||
9 years ago
|
err := cleanupDir(disk, minioMetaBucket, tmpMetaPrefix)
|
||
9 years ago
|
if err != nil {
|
||
|
errs[index] = err
|
||
|
}
|
||
|
}(index, disk)
|
||
|
}
|
||
|
|
||
|
// Wait for all cleanup to finish.
|
||
|
wg.Wait()
|
||
|
|
||
|
// Return upon first error.
|
||
|
for _, err := range errs {
|
||
|
if err == nil {
|
||
|
continue
|
||
9 years ago
|
}
|
||
9 years ago
|
return toObjectErr(err, minioMetaBucket, tmpMetaPrefix)
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
|
// Return success here.
|
||
9 years ago
|
return nil
|
||
|
}
|
||
|
|
||
9 years ago
|
// Cleanup a directory recursively.
|
||
|
func cleanupDir(storage StorageAPI, volume, dirPath string) error {
|
||
|
var delFunc func(string) error
|
||
|
// Function to delete entries recursively.
|
||
|
delFunc = func(entryPath string) error {
|
||
|
if !strings.HasSuffix(entryPath, slashSeparator) {
|
||
9 years ago
|
// Delete the file entry.
|
||
9 years ago
|
return storage.DeleteFile(volume, entryPath)
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
// If it's a directory, list and call delFunc() for each entry.
|
||
|
entries, err := storage.ListDir(volume, entryPath)
|
||
9 years ago
|
// If entryPath prefix never existed, safe to ignore.
|
||
|
if err == errFileNotFound {
|
||
|
return nil
|
||
|
} else if err != nil { // For any other errors fail.
|
||
9 years ago
|
return err
|
||
9 years ago
|
} // else on success..
|
||
9 years ago
|
|
||
9 years ago
|
// Recurse and delete all other entries.
|
||
|
for _, entry := range entries {
|
||
|
if err = delFunc(pathJoin(entryPath, entry)); err != nil {
|
||
9 years ago
|
return err
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
9 years ago
|
err := delFunc(retainSlash(pathJoin(dirPath)))
|
||
|
return err
|
||
9 years ago
|
}
|