FS: check whether disk format is FS or not. (#2083)

Fixes #2060
This commit is contained in:
Bala FA 2016-07-04 08:31:40 +05:30 committed by Harshavardhana
parent 355f06cfea
commit 52b55afce0
4 changed files with 55 additions and 4 deletions

22
fs-v1-errors.go Normal file
View file

@ -0,0 +1,22 @@
/*
* 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 "errors"
// errFSDiskFormat - returned when given disk format is other than FS format.
var errFSDiskFormat = errors.New("Disk is not in FS format.")

View file

@ -93,6 +93,11 @@ func newFSFormatV1() (format formatConfigV1) {
}
}
// isFSFormat - returns whether given formatConfigV1 is FS type or not.
func isFSFormat(format formatConfigV1) bool {
return format.Format == "fs"
}
// writes FS format (format.json) into minioMetaBucket.
func writeFSFormatData(storage StorageAPI, fsFormat formatConfigV1) error {
metadataBytes, err := json.Marshal(fsFormat)

View file

@ -103,7 +103,7 @@ func newFSObjects(disk string) (ObjectLayer, error) {
// loading format.json from minioMetaBucket.
// Note: The format.json content is ignored, reserved for future use.
_, err = loadFormatFS(storage)
format, err := loadFormatFS(storage)
if err != nil {
if err == errFileNotFound {
// format.json doesn't exist, create it inside minioMetaBucket.
@ -114,6 +114,8 @@ func newFSObjects(disk string) (ObjectLayer, error) {
} else {
return nil, err
}
} else if !isFSFormat(format) {
return nil, errFSDiskFormat
}
// Register the callback that should be called when the process shuts down.

View file

@ -31,9 +31,31 @@ func TestNewFS(t *testing.T) {
disk := filepath.Join(os.TempDir(), "minio-"+nextSuffix())
defer removeAll(disk)
// Initializes single disk, validate if there is no error.
_, err := newFSObjects(disk)
// Setup to test errFSDiskFormat.
disks := []string{}
for i := 0; i < 6; i++ {
xlDisk := filepath.Join(os.TempDir(), "minio-"+nextSuffix())
defer removeAll(xlDisk)
disks = append(disks, xlDisk)
}
// Initializes all disks with XL
_, err := newXLObjects(disks)
if err != nil {
t.Fatalf("Unable to initialize erasure, %s", err)
t.Fatalf("Unable to initialize XL object, %s", err)
}
testCases := []struct {
disk string
expectedErr error
}{
{disk, nil},
{disks[0], errFSDiskFormat},
}
for _, testCase := range testCases {
if _, err := newFSObjects(testCase.disk); err != testCase.expectedErr {
t.Fatalf("expected: %s, got: %s", testCase.expectedErr, err)
}
}
}