posix: remove disk free space check for read-only and delete methods. (#2033)

This commit is contained in:
Bala FA 2016-06-29 23:55:35 +05:30 committed by Harshavardhana
parent 0e3907072c
commit 57bc08cc7e
2 changed files with 53 additions and 21 deletions

View File

@ -115,16 +115,23 @@ func newPosix(diskPath string) (StorageAPI, error) {
return fs, nil return fs, nil
} }
// 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
}
// checkDiskFree verifies if disk path has sufficient minimum free disk space. // checkDiskFree verifies if disk path has sufficient minimum free disk space.
func checkDiskFree(diskPath string, minFreeDisk int64) (err error) { func checkDiskFree(diskPath string, minFreeDisk int64) (err error) {
if err = checkPathLength(diskPath); err != nil { di, err := getDiskInfo(diskPath)
return err
}
di, err := disk.GetInfo(diskPath)
if err != nil { if err != nil {
if os.IsNotExist(err) {
return errDiskNotFound
}
return err return err
} }
@ -256,8 +263,8 @@ func (s *posix) StatVol(volume string) (volInfo VolInfo, err error) {
return VolInfo{}, errFaultyDisk return VolInfo{}, errFaultyDisk
} }
// Validate if disk is free. // Check disk availability.
if err = checkDiskFree(s.diskPath, s.minFreeDisk); err != nil { if _, err = getDiskInfo(s.diskPath); err != nil {
return VolInfo{}, err return VolInfo{}, err
} }
@ -296,8 +303,8 @@ func (s *posix) DeleteVol(volume string) (err error) {
return errFaultyDisk return errFaultyDisk
} }
// Validate if disk is free. // Check disk availability.
if err = checkDiskFree(s.diskPath, s.minFreeDisk); err != nil { if _, err = getDiskInfo(s.diskPath); err != nil {
return err return err
} }
@ -336,8 +343,8 @@ func (s *posix) ListDir(volume, dirPath string) (entries []string, err error) {
return nil, errFaultyDisk return nil, errFaultyDisk
} }
// Validate if disk is free. // Check disk availability.
if err = checkDiskFree(s.diskPath, s.minFreeDisk); err != nil { if _, err = getDiskInfo(s.diskPath); err != nil {
return nil, err return nil, err
} }
@ -373,8 +380,9 @@ func (s *posix) ReadAll(volume, path string) (buf []byte, err error) {
if s.ioErrCount > maxAllowedIOError { if s.ioErrCount > maxAllowedIOError {
return nil, errFaultyDisk return nil, errFaultyDisk
} }
// Validate if disk is free.
if err = checkDiskFree(s.diskPath, s.minFreeDisk); err != nil { // Check disk availability.
if _, err = getDiskInfo(s.diskPath); err != nil {
return nil, err return nil, err
} }
@ -434,8 +442,8 @@ func (s *posix) ReadFile(volume string, path string, offset int64, buf []byte) (
return 0, errFaultyDisk return 0, errFaultyDisk
} }
// Validate if disk is free. // Check disk availability.
if err = checkDiskFree(s.diskPath, s.minFreeDisk); err != nil { if _, err = getDiskInfo(s.diskPath); err != nil {
return 0, err return 0, err
} }
@ -572,8 +580,8 @@ func (s *posix) StatFile(volume, path string) (file FileInfo, err error) {
return FileInfo{}, errFaultyDisk return FileInfo{}, errFaultyDisk
} }
// Validate if disk is free. // Check disk availability.
if err = checkDiskFree(s.diskPath, s.minFreeDisk); err != nil { if _, err = getDiskInfo(s.diskPath); err != nil {
return FileInfo{}, err return FileInfo{}, err
} }
@ -664,8 +672,8 @@ func (s *posix) DeleteFile(volume, path string) (err error) {
return errFaultyDisk return errFaultyDisk
} }
// Validate if disk is free. // Check disk availability.
if err = checkDiskFree(s.diskPath, s.minFreeDisk); err != nil { if _, err = getDiskInfo(s.diskPath); err != nil {
return err return err
} }

View File

@ -22,6 +22,30 @@ import (
"testing" "testing"
) )
// Tests posix.getDiskInfo()
func TestGetDiskInfo(t *testing.T) {
path, err := ioutil.TempDir(os.TempDir(), "minio-")
if err != nil {
t.Fatalf("Unable to create a temporary directory, %s", err)
}
defer removeAll(path)
testCases := []struct {
diskPath string
expectedErr error
}{
{path, nil},
{"/nonexistent-dir", errDiskNotFound},
}
// Check test cases.
for _, testCase := range testCases {
if _, err := getDiskInfo(testCase.diskPath); err != testCase.expectedErr {
t.Fatalf("expected: %s, got: %s", testCase.expectedErr, err)
}
}
}
// Tests the functionality implemented by ReadAll storage API. // Tests the functionality implemented by ReadAll storage API.
func TestReadAll(t *testing.T) { func TestReadAll(t *testing.T) {
path, err := ioutil.TempDir(os.TempDir(), "minio-") path, err := ioutil.TempDir(os.TempDir(), "minio-")