|
|
@ -115,16 +115,23 @@ func newPosix(diskPath string) (StorageAPI, error) { |
|
|
|
return fs, nil |
|
|
|
return fs, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// checkDiskFree verifies if disk path has sufficient minimum free disk space.
|
|
|
|
// getDiskInfo returns given disk information.
|
|
|
|
func checkDiskFree(diskPath string, minFreeDisk int64) (err error) { |
|
|
|
func getDiskInfo(diskPath string) (di disk.Info, err error) { |
|
|
|
if err = checkPathLength(diskPath); err != nil { |
|
|
|
if err = checkPathLength(diskPath); err == nil { |
|
|
|
return err |
|
|
|
di, err = disk.GetInfo(diskPath) |
|
|
|
} |
|
|
|
} |
|
|
|
di, err := disk.GetInfo(diskPath) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
if os.IsNotExist(err) { |
|
|
|
if os.IsNotExist(err) { |
|
|
|
return errDiskNotFound |
|
|
|
err = errDiskNotFound |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return di, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// checkDiskFree verifies if disk path has sufficient minimum free disk space.
|
|
|
|
|
|
|
|
func checkDiskFree(diskPath string, minFreeDisk int64) (err error) { |
|
|
|
|
|
|
|
di, err := getDiskInfo(diskPath) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
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 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|