mirror of https://github.com/minio/minio.git
XL/fs: Initialize export paths supplied on command line (#2020)
Fixes #2013
This commit is contained in:
parent
8e8f6f90a4
commit
0e3907072c
2
fs-v1.go
2
fs-v1.go
|
@ -81,7 +81,7 @@ func shutdownFS(storage StorageAPI) {
|
|||
// newFSObjects - initialize new fs object layer.
|
||||
func newFSObjects(disk string) (ObjectLayer, error) {
|
||||
storage, err := newStorageAPI(disk)
|
||||
if err != nil {
|
||||
if err != nil && err != errDiskNotFound {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestNewFS - tests initialization of all input disks
|
||||
// and constructs a valid `FS` object layer.
|
||||
func TestNewFS(t *testing.T) {
|
||||
// Do not attempt to create this path, the test validates
|
||||
// so that newFSObjects initializes non existing paths
|
||||
// and successfully returns initialized object layer.
|
||||
disk := filepath.Join(os.TempDir(), "minio-"+nextSuffix())
|
||||
defer removeAll(disk)
|
||||
|
||||
// Initializes single disk, validate if there is no error.
|
||||
_, err := newFSObjects(disk)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to initialize erasure, %s", err)
|
||||
}
|
||||
}
|
6
posix.go
6
posix.go
|
@ -101,7 +101,11 @@ func newPosix(diskPath string) (StorageAPI, error) {
|
|||
st, err := os.Stat(preparePath(diskPath))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return fs, errDiskNotFound
|
||||
// Disk not found create it.
|
||||
if err = os.MkdirAll(diskPath, 0777); err != nil {
|
||||
return fs, err
|
||||
}
|
||||
return fs, nil
|
||||
}
|
||||
return fs, err
|
||||
}
|
||||
|
|
|
@ -30,7 +30,9 @@ import (
|
|||
"os"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
@ -61,6 +63,32 @@ const (
|
|||
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
|
||||
)
|
||||
|
||||
// Random number state.
|
||||
// We generate random temporary file names so that there's a good
|
||||
// chance the file doesn't exist yet.
|
||||
var randN uint32
|
||||
var randmu sync.Mutex
|
||||
|
||||
// reseed - returns a new seed everytime the function is called.
|
||||
func reseed() uint32 {
|
||||
return uint32(time.Now().UnixNano() + int64(os.Getpid()))
|
||||
}
|
||||
|
||||
// nextSuffix - provides a new unique suffix everytime the function is called.
|
||||
func nextSuffix() string {
|
||||
randmu.Lock()
|
||||
r := randN
|
||||
// Initial seed required, generate one.
|
||||
if r == 0 {
|
||||
r = reseed()
|
||||
}
|
||||
// constants from Numerical Recipes
|
||||
r = r*1664525 + 1013904223
|
||||
randN = r
|
||||
randmu.Unlock()
|
||||
return strconv.Itoa(int(1e9 + r%1e9))[1:]
|
||||
}
|
||||
|
||||
// TestServer encapsulates an instantiation of a Minio instance with a temporary backend.
|
||||
// Example usage:
|
||||
// s := StartTestServer(t,"XL")
|
||||
|
|
4
xl-v1.go
4
xl-v1.go
|
@ -128,7 +128,9 @@ func newXLObjects(disks []string) (ObjectLayer, error) {
|
|||
// Attempt to load all `format.json`.
|
||||
formatConfigs, sErrs := loadAllFormats(storageDisks)
|
||||
|
||||
// Generic format check validates all necessary cases.
|
||||
// Generic format check validates
|
||||
// if (no quorum) return error
|
||||
// if (disks not recognized) // Always error.
|
||||
if err := genericFormatCheck(formatConfigs, sErrs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -16,7 +16,11 @@
|
|||
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Collection of disks verbatim used for tests.
|
||||
var disks = []string{
|
||||
|
@ -112,3 +116,23 @@ func TestStorageInfo(t *testing.T) {
|
|||
t.Fatalf("Diskinfo total values should be greater 0")
|
||||
}
|
||||
}
|
||||
|
||||
// TestNewXL - tests initialization of all input disks
|
||||
// and constructs a valid `XL` object
|
||||
func TestNewXL(t *testing.T) {
|
||||
var nDisks = 16 // Maximum disks.
|
||||
var erasureDisks []string
|
||||
for i := 0; i < nDisks; i++ {
|
||||
// Do not attempt to create this path, the test validates
|
||||
// so that newFSObjects initializes non existing paths
|
||||
// and successfully returns initialized object layer.
|
||||
disk := filepath.Join(os.TempDir(), "minio-"+nextSuffix())
|
||||
erasureDisks = append(erasureDisks, disk)
|
||||
defer removeAll(disk)
|
||||
}
|
||||
// Initializes all erasure disks
|
||||
_, err := newXLObjects(erasureDisks)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to initialize erasure, %s", err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue