[PATCH 047/103] qemu: Use 'effectiveBootIndex' to handle <os><boot dev='network'>

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Fill in the effective boot index for network devices (or hostdev-backed
network devices via 'qemuProcessPrepareDeviceBootorder'. This patch
doesn't clean up the cruft to make it more obvious what's happening.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_command.c | 14 ++++++--------
 src/qemu/qemu_process.c | 27 ++++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 07a8f104f4..bb91098c76 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3699,7 +3699,7 @@ qemuBuildLegacyNicStr(virDomainNetDef *net)
 char *
 qemuBuildNicDevStr(virDomainDef *def,
                    virDomainNetDef *net,
-                   unsigned int bootindex,
+                   unsigned int bootindex G_GNUC_UNUSED,
                    size_t vhostfdSize,
                    virQEMUCaps *qemuCaps)
 {
@@ -3834,8 +3834,8 @@ qemuBuildNicDevStr(virDomainDef *def,
         return NULL;
     if (qemuBuildRomStr(&buf, &net->info) < 0)
         return NULL;
-    if (bootindex)
-        virBufferAsprintf(&buf, ",bootindex=%u", bootindex);
+    if (net->info.effectiveBootIndex > 0)
+        virBufferAsprintf(&buf, ",bootindex=%u", net->info.effectiveBootIndex);

     return virBufferContentAndReset(&buf);
 }
@@ -4621,7 +4621,7 @@ qemuBuildVideoCommandLine(virCommand *cmd,
 char *
 qemuBuildPCIHostdevDevStr(const virDomainDef *def,
                           virDomainHostdevDef *dev,
-                          unsigned int bootIndex, /* used iff dev->info->bootIndex == 0 */
+                          unsigned int bootIndex G_GNUC_UNUSED,
                           virQEMUCaps *qemuCaps G_GNUC_UNUSED)
 {
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
@@ -4653,10 +4653,8 @@ qemuBuildPCIHostdevDevStr(const virDomainDef *def,
                       pcisrc->addr.slot,
                       pcisrc->addr.function);
     virBufferAsprintf(&buf, ",id=%s", dev->info->alias);
-    if (dev->info->bootIndex)
-        bootIndex = dev->info->bootIndex;
-    if (bootIndex)
-        virBufferAsprintf(&buf, ",bootindex=%u", bootIndex);
+    if (dev->info->effectiveBootIndex > 0)
+        virBufferAsprintf(&buf, ",bootindex=%u", dev->info->effectiveBootIndex);
     if (qemuBuildDeviceAddressStr(&buf, def, dev->info) < 0)
         return NULL;
     if (qemuBuildRomStr(&buf, dev->info) < 0)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 58fbb38c5e..c3e994b1a2 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6270,6 +6270,7 @@ qemuProcessPrepareDeviceBootorder(virDomainDef *def)
     unsigned int bootCD = 0;
     unsigned int bootFloppy = 0;
     unsigned int bootDisk = 0;
+    unsigned int bootNetwork = 0;

     if (def->os.nBootDevs == 0)
         return;
@@ -6289,7 +6290,9 @@ qemuProcessPrepareDeviceBootorder(virDomainDef *def)
             break;

         case VIR_DOMAIN_BOOT_NET:
-            /* network boot is handled in network device formatting code */
+            bootNetwork = i + 1;
+            break;
+
         case VIR_DOMAIN_BOOT_LAST:
         default:
             break;
@@ -6321,6 +6324,28 @@ qemuProcessPrepareDeviceBootorder(virDomainDef *def)
             break;
         }
     }
+
+    if (def->nnets > 0 && bootNetwork > 0) {
+        /* If network boot is enabled, the first network device gets enabled. If
+         * that one is backed by a host device, then we need to find the first
+         * corresponding host device */
+        if (virDomainNetGetActualType(def->nets[0]) == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+            for (i = 0; i < def->nhostdevs; i++) {
+                virDomainHostdevDef *hostdev = def->hostdevs[i];
+                virDomainHostdevSubsys *subsys = &hostdev->source.subsys;
+
+                if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+                    subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
+                    hostdev->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED &&
+                    hostdev->parentnet) {
+                    hostdev->info->effectiveBootIndex = bootNetwork;
+                    break;
+                }
+            }
+        } else {
+            def->nets[0]->info.effectiveBootIndex = bootNetwork;
+        }
+    }
 }


-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux