Fix divide by 0 error when directio.AlignSize is 0 (#7591)

master
Krishna Srinivas 6 years ago committed by kannappanr
parent 83ca1a8d64
commit b93ef73f9b
  1. 3
      cmd/posix.go

@ -45,6 +45,7 @@ const (
diskMinTotalSpace = diskMinFreeSpace // Min 900MiB total space. diskMinTotalSpace = diskMinFreeSpace // Min 900MiB total space.
maxAllowedIOError = 5 maxAllowedIOError = 5
posixWriteBlockSize = 4 * humanize.MiByte posixWriteBlockSize = 4 * humanize.MiByte
directioAlignSize = 4096 // DirectIO alignment needs to be 4K. Defined here as directio.AlignSize is defined as 0 in MacOS causing divide by 0 error.
) )
// isValidVolname verifies a volname name in accordance with object // isValidVolname verifies a volname name in accordance with object
@ -1142,7 +1143,7 @@ func (s *posix) CreateFile(volume, path string, fileSize int64, r io.Reader) (er
if err != nil { if err != nil {
return err return err
} }
remainingAligned := (remaining / directio.AlignSize) * directio.AlignSize remainingAligned := (remaining / directioAlignSize) * directioAlignSize
remainingAlignedBuf := buf[:remainingAligned] remainingAlignedBuf := buf[:remainingAligned]
remainingUnalignedBuf := buf[remainingAligned:] remainingUnalignedBuf := buf[remainingAligned:]
if len(remainingAlignedBuf) > 0 { if len(remainingAlignedBuf) > 0 {

Loading…
Cancel
Save