Skip to content

Commit

Permalink
core: Allow RunOnce for single non-bootable disk
Browse files Browse the repository at this point in the history
If a VM contains a single disk not marked as bootable, RunVmCommand
allows to boot OS from this disk. But RunOnce ignores this disk when
setting the boot order. This patch fixes this inconsistence.

Change-Id: Ia5652bb1549bdd5205284be355e3a2903fb6e9f1
Signed-off-by: Shmuel Melamud <smelamud@redhat.com>
  • Loading branch information
smelamud committed Sep 1, 2022
1 parent 7906d9e commit 0dabcf4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,21 +237,32 @@ private static int setDiskBootOrder(
Map<VmDeviceId, DiskVmElement> deviceIdTodiskVmElement) {
LinkedList<VmDevice> diskDevices = new LinkedList<>();
for (VmDevice device : devices) {
if (isDisk(device)) {
Guid id = device.getDeviceId();
if (id != null && !id.equals(Guid.Empty)) {
if (device.getSnapshotId() == null) {
diskDevices.addFirst(device);
} else {
diskDevices.addLast(device);
}
}
if (!isDisk(device)) {
continue;
}
Guid id = device.getDeviceId();
if (id == null || id.equals(Guid.Empty)) {
continue;
}
DiskVmElement dve = deviceIdTodiskVmElement.get(device.getId());
if (dve == null) {
continue;
}
if (device.getSnapshotId() == null) {
diskDevices.addFirst(device);
} else {
diskDevices.addLast(device);
}
}

if (diskDevices.size() == 1) {
diskDevices.get(0).setBootOrder(++bootOrder);
return bootOrder;
}

for (VmDevice device : diskDevices) {
DiskVmElement dve = deviceIdTodiskVmElement.get(device.getId());
if (dve != null && dve.isBoot()) {
if (dve.isBoot()) {
device.setBootOrder(++bootOrder);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,9 @@ private void setIsBootFromHardDiskAllowedForVm() {
}

private boolean isDisksContainBootableDisk(List<Disk> disks) {
if (disks.size() == 1) {
return true;
}
for (Disk disk : disks) {
if (disk.getDiskVmElementForVm(vm.getId()).isBoot()) {
return true;
Expand Down

0 comments on commit 0dabcf4

Please sign in to comment.