Skip to content

Commit

Permalink
Go: Don't grow sparse file too fast
Browse files Browse the repository at this point in the history
APFS exhibits a weird behavior wrt sparse files: we cannot create (or
grow) them "too fast": there's a limit, apparently related to the
available disk space.  However, if the additional space is small
enough, we can procede way beyond the available disk space.  So grow
incrementally, by steps of 1GB.

More details available in docker/for-mac#2383.

Signed-off-by: Akim Demaille <akim.demaille@docker.com>
  • Loading branch information
akimd committed Jan 18, 2018
1 parent d60a7c8 commit d797c3a
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion go/disk.go
Expand Up @@ -223,7 +223,28 @@ func (d *RawDisk) getCurrentSize() (int, error) {

// Resize the virtual size of the disk
func (d *RawDisk) resize() error {
return os.Truncate(d.Path, int64(d.Size)*mib)
s, err := d.getCurrentSize()
if err != nil {
return fmt.Errorf("Cannot resize %q: %v", d, err)
}
log.Infof("Resize %q from %vMiB to %vMiB", d, s, d.GetSize())
// APFS exhibits a weird behavior wrt sparse files: we cannot
// create (or grow) them "too fast": there's a limit,
// apparently related to the available disk space. However,
// if the additional space is small enough, we can procede way
// beyond the available disk space. So grow incrementally,
// by steps of 1GB.
for s < d.Size {
s += 1000
if d.Size < s {
s = d.Size
}
if err := os.Truncate(d.Path, int64(s)*mib); err != nil {
return fmt.Errorf("Cannot resize %q to %vMiB: %v", d, s, err)
}
}
log.Infof("Resized %q to %vMiB", d, d.GetSize())
return nil
}

// Stop cleans up this disk when we are quitting.
Expand Down

0 comments on commit d797c3a

Please sign in to comment.