Skip to content

Commit

Permalink
chore: preallocate disk images for QEMU VMs
Browse files Browse the repository at this point in the history
This improves the performance of the I/O operations if the underlying
filesystem supports it.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
  • Loading branch information
smira committed Jan 19, 2023
1 parent d4b8b35 commit bb50f6a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pkg/provision/providers/vm/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package vm
import (
"fmt"
"os"
"syscall"

"github.com/siderolabs/talos/pkg/provision"
)
Expand Down Expand Up @@ -44,20 +45,25 @@ func (p *Provisioner) CreateDisks(state *State, nodeReq provision.NodeRequest) (

diskF, err = os.Create(diskPath)
if err != nil {
return
return nil, err
}

defer diskF.Close() //nolint:errcheck

err = diskF.Truncate(int64(disk.Size))
if err = diskF.Truncate(int64(disk.Size)); err != nil {
return nil, err
}

if err = syscall.Fallocate(int(diskF.Fd()), 0, 0, int64(disk.Size)); err != nil {
fmt.Fprintf(os.Stderr, "WARNING: failed to preallocate disk space for %q (size %d): %s", diskPath, disk.Size, err)
}

diskPaths[i] = diskPath
}

if len(diskPaths) == 0 {
err = fmt.Errorf("node request must have at least one disk defined to be used as primary disk")

return
return nil, fmt.Errorf("node request must have at least one disk defined to be used as primary disk")
}

return
return diskPaths, nil
}

0 comments on commit bb50f6a

Please sign in to comment.