@ -42,8 +42,6 @@ const (
type posix struct {
ioErrCount int32 // ref: https://golang.org/pkg/sync/atomic/#pkg-note-BUG
diskPath string
minFreeSpace int64
minFreeInodes int64
pool sync . Pool
}
@ -110,8 +108,6 @@ func newPosix(path string) (StorageAPI, error) {
}
fs := & posix {
diskPath : diskPath ,
minFreeSpace : fsMinFreeSpace ,
minFreeInodes : fsMinFreeInodes ,
// 1MiB buffer pool for posix internal operations.
pool : sync . Pool {
New : func ( ) interface { } {
@ -133,9 +129,6 @@ func newPosix(path string) (StorageAPI, error) {
return nil , err
}
}
if err = fs . checkDiskFree ( ) ; err != nil {
return nil , err
}
return fs , nil
}
@ -161,7 +154,7 @@ var ignoreDiskFreeOS = []string{
}
// checkDiskFree verifies if disk path has sufficient minimum free disk space and files.
func ( s * posix ) checkDiskFree ( ) ( err error ) {
func checkDiskFree ( diskPath string , neededSpace int64 ) ( err error ) {
// We don't validate disk space or inode utilization on windows.
// Each windows calls to 'GetVolumeInformationW' takes around 3-5seconds.
// And StatFS is not supported by Go for solaris and netbsd.
@ -170,14 +163,14 @@ func (s *posix) checkDiskFree() (err error) {
}
var di disk . Info
di , err = getDiskInfo ( preparePath ( s . diskPath ) )
di , err = getDiskInfo ( preparePath ( diskPath ) )
if err != nil {
return err
}
// Remove 5% from free space for cumulative disk space used for journalling, inodes etc.
availableDiskSpace := float64 ( di . Free ) * 0.95
if int64 ( availableDiskSpace ) <= s . m inFreeSpace {
if int64 ( availableDiskSpace ) <= fsM inFreeSpace {
return errDiskFull
}
@ -187,11 +180,16 @@ func (s *posix) checkDiskFree() (err error) {
// total inodes are provided by the underlying filesystem.
if di . Files != 0 && di . FSType != "NFS" {
availableFiles := int64 ( di . Ffree )
if availableFiles <= s . m inFreeInodes {
if availableFiles <= fsM inFreeInodes {
return errDiskFull
}
}
// Check if we have enough space to store data
if neededSpace > int64 ( availableDiskSpace ) {
return errDiskFull
}
// Success.
return nil
}
@ -676,7 +674,7 @@ func (s *posix) PrepareFile(volume, path string, fileSize int64) (err error) {
}
// Validate if disk is indeed free.
if err = s . checkDiskFree ( ) ; err != nil {
if err = checkDiskFree ( s . diskPath , fileSize ) ; err != nil {
return err
}