Skip to content

Commit

Permalink
platform/qemu: strengthen data block device checks
Browse files Browse the repository at this point in the history
On ppc64le and s390x, the Ignition config is passed as a block device.
In the `RemovePrimaryBlockDevice()` code, we need to make sure we don't
inadvertently select the `ignition` block device as the new boot device.

More generally, the reliance on the `virtio-backend` string is weak.
Instead, use a more specific device name for the real block devices when
preparing the QEMU arguments, and filter on that.

Partially fixes: #2725
Partially fixes: #3360
  • Loading branch information
jlebon committed Sep 13, 2023
1 parent 45e72e0 commit e016eef
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mantle/platform/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func (inst *QemuInstance) SwitchBootOrder() (err2 error) {

// RemovePrimaryBlockDevice deletes the primary device from a qemu instance
// and sets the seconday device as primary. It expects that all block devices
// are mirrors.
// with device name disk-<N> are mirrors.
func (inst *QemuInstance) RemovePrimaryBlockDevice() (err2 error) {
var primaryDevice string
var secondaryDevicePath string
Expand All @@ -397,7 +397,7 @@ func (inst *QemuInstance) RemovePrimaryBlockDevice() (err2 error) {
// a `BackingFileDepth` parameter of a device and check if
// it is a removable and part of `virtio-blk-pci` devices.
for _, dev := range blkdevs.Return {
if !dev.Removable && strings.Contains(dev.DevicePath, "virtio-backend") {
if !dev.Removable && strings.HasPrefix(dev.Device, "disk-") {
if dev.Inserted.BackingFileDepth == 1 {
primaryDevice = dev.DevicePath
} else {
Expand Down Expand Up @@ -1131,7 +1131,7 @@ func (builder *QemuBuilder) addDiskImpl(disk *Disk, primary bool) error {
opts = "," + strings.Join(diskOpts, ",")
}

id := fmt.Sprintf("d%d", builder.diskID)
id := fmt.Sprintf("disk-%d", builder.diskID)

// Avoid file locking detection, and the disks we create
// here are always currently ephemeral.
Expand Down

0 comments on commit e016eef

Please sign in to comment.