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

master
Bala FA 9 years ago committed by Harshavardhana
parent 0e3907072c
commit 57bc08cc7e
  1. 50
      posix.go
  2. 24
      posix_test.go

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

@ -22,6 +22,30 @@ import (
"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.
func TestReadAll(t *testing.T) {
path, err := ioutil.TempDir(os.TempDir(), "minio-")

Loading…
Cancel
Save