Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incusd/storage/lvm: Require 512-bytes physical block size for VM images #1444

Merged
merged 1 commit into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions internal/server/storage/drivers/driver_lvm_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
"path/filepath"
"strconv"
"strings"
"unsafe"

"golang.org/x/sys/unix"

internalInstance "github.com/lxc/incus/v6/internal/instance"
"github.com/lxc/incus/v6/internal/linux"
Expand Down Expand Up @@ -869,3 +872,22 @@ func (d *lvm) deactivateVolume(vol Volume) (bool, error) {

return false, nil
}

func (d *lvm) getBlockSize(path string) (int, error) {
// Open the block device.
f, err := os.Open(path)
if err != nil {
return -1, err
}

defer func() { _ = f.Close() }()

// Query the physical block size.
var res int32
_, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(f.Fd()), unix.BLKPBSZGET, uintptr(unsafe.Pointer(&res)))
if errno != 0 {
return -1, fmt.Errorf("Failed to BLKPBSZGET: %w", unix.Errno(errno))
}

return int(res), nil
}
12 changes: 12 additions & 0 deletions internal/server/storage/drivers/driver_lvm_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ func (d *lvm) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.Oper
if err != nil {
return err
}

// Check the block size for image volumes.
if vol.volType == VolumeTypeImage {
blockSize, err := d.getBlockSize(devPath)
if err != nil {
return err
}

if blockSize != 512 {
return fmt.Errorf("Underlying storage uses %d bytes sector size when virtual machine images require 512 bytes", blockSize)
}
}
}

allowUnsafeResize := false
Expand Down