[PATCH] drvbhyve: Use boot-order for grub-bhyve boot device

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

 



Rather than just picking the first CD (or failing that, HDD) we come
across, if the user has picked a boot device ordering with <boot
order=''>, respect that (and just try to boot the lowest-index device).

Adds two sets of tests to bhyve2xmlargv; 'grub-bootorder' shows that we
pick a user-specified device over the first device in the domain;
'grub-bootorder2' shows that we pick the first (lowest index) device.
---
This is a follow-up to the 'Add non-FreeBSD guest support to Bhyve driver'
patch series to fix the grub-bhyve automagic configuration to respect <boot
order=''> in the domain. (Requested by both Roman and Michal, I believe.)
---
 docs/drvbhyve.html.in                              |  9 +--
 src/bhyve/bhyve_command.c                          | 64 ++++++++++++++++------
 .../bhyvexml2argv-grub-bootorder.args              |  6 ++
 .../bhyvexml2argv-grub-bootorder.devmap            |  1 +
 .../bhyvexml2argv-grub-bootorder.ldargs            |  2 +
 .../bhyvexml2argv-grub-bootorder.xml               | 36 ++++++++++++
 .../bhyvexml2argv-grub-bootorder2.args             |  6 ++
 .../bhyvexml2argv-grub-bootorder2.devmap           |  1 +
 .../bhyvexml2argv-grub-bootorder2.ldargs           |  2 +
 .../bhyvexml2argv-grub-bootorder2.xml              | 38 +++++++++++++
 tests/bhyvexml2argvtest.c                          |  2 +
 11 files changed, 146 insertions(+), 21 deletions(-)
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder.args
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder.devmap
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder.ldargs
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder.xml
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder2.args
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder2.devmap
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder2.ldargs
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder2.xml

diff --git a/docs/drvbhyve.html.in b/docs/drvbhyve.html.in
index bd4b35e..5479511 100644
--- a/docs/drvbhyve.html.in
+++ b/docs/drvbhyve.html.in
@@ -234,10 +234,11 @@ management.</p>
 <p>It's possible to boot non-FreeBSD guests by specifying an explicit
 bootloader, e.g. <code>grub-bhyve(1)</code>. Arguments to the bootloader may be
 specified as well. If the bootloader is <code>grub-bhyve</code> and arguments
-are omitted, libvirt will try and boot the first disk in the domain (either
-<code>cdrom</code>- or <code>disk</code>-type devices). If the disk type is
-<code>disk</code>, it will attempt to boot from the first partition in the disk
-image.</p>
+are omitted, libvirt will try and infer boot ordering from user-supplied
+&lt;boot order='N'&gt; configuration in the domain. Failing that, it will boot
+the first disk in the domain (either <code>cdrom</code>- or
+<code>disk</code>-type devices). If the disk type is <code>disk</code>, it will
+attempt to boot from the first partition in the disk image.</p>
 
 <pre>
   ...
diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index 26d4797..6e3bf03 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -381,38 +381,62 @@ virBhyveUsableDisk(virConnectPtr conn, virDomainDiskDefPtr disk)
     return true;
 }
 
+static void
+virBhyveFormatGrubDevice(virBufferPtr devicemap, virDomainDiskDefPtr def)
+{
+
+    if (def->device == VIR_DOMAIN_DISK_DEVICE_CDROM)
+        virBufferAsprintf(devicemap, "(cd) %s\n",
+                          virDomainDiskGetSource(def));
+    else
+        virBufferAsprintf(devicemap, "(hd0) %s\n",
+                          virDomainDiskGetSource(def));
+}
+
 static virCommandPtr
 virBhyveProcessBuildGrubbhyveCmd(virDomainDefPtr def,
                                  virConnectPtr conn,
                                  const char *devmap_file,
                                  char **devicesmap_out)
 {
-    virDomainDiskDefPtr disk, cd;
+    virDomainDiskDefPtr hdd, cd, userdef, diskdef;
     virBuffer devicemap;
     virCommandPtr cmd;
+    int best_idx;
     size_t i;
 
     if (def->os.bootloaderArgs != NULL)
         return virBhyveProcessBuildCustomLoaderCmd(def);
 
+    best_idx = INT_MAX;
     devicemap = (virBuffer)VIR_BUFFER_INITIALIZER;
 
-    /* Search disk list for CD or HDD device. */
-    cd = disk = NULL;
+    /* Search disk list for CD or HDD device. We'll respect <boot order=''> if
+     * present and otherwise pick the first CD or failing that HDD we come
+     * across. */
+    cd = hdd = userdef = NULL;
     for (i = 0; i < def->ndisks; i++) {
         if (!virBhyveUsableDisk(conn, def->disks[i]))
             continue;
 
+        diskdef = def->disks[i];
+
+        if (diskdef->info.bootIndex && diskdef->info.bootIndex < best_idx) {
+            userdef = diskdef;
+            best_idx = userdef->info.bootIndex;
+            continue;
+        }
+
         if (cd == NULL &&
             def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
-            cd = def->disks[i];
-            VIR_INFO("Picking %s as boot CD", virDomainDiskGetSource(cd));
+            cd = diskdef;
+            VIR_INFO("Picking %s as CD", virDomainDiskGetSource(cd));
         }
 
-        if (disk == NULL &&
+        if (hdd == NULL &&
             def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
-            disk = def->disks[i];
-            VIR_INFO("Picking %s as HDD", virDomainDiskGetSource(disk));
+            hdd = diskdef;
+            VIR_INFO("Picking %s as HDD", virDomainDiskGetSource(hdd));
         }
     }
 
@@ -422,22 +446,28 @@ virBhyveProcessBuildGrubbhyveCmd(virDomainDefPtr def,
 
     if (devicesmap_out != NULL) {
         /* Grub device.map (just for boot) */
-        if (disk != NULL)
-            virBufferAsprintf(&devicemap, "(hd0) %s\n",
-                              virDomainDiskGetSource(disk));
+        if (userdef != NULL) {
+            virBhyveFormatGrubDevice(&devicemap, userdef);
+        } else {
+            if (hdd != NULL)
+                virBhyveFormatGrubDevice(&devicemap, hdd);
 
-        if (cd != NULL)
-            virBufferAsprintf(&devicemap, "(cd) %s\n",
-                              virDomainDiskGetSource(cd));
+            if (cd != NULL)
+                virBhyveFormatGrubDevice(&devicemap, cd);
+        }
 
         *devicesmap_out = virBufferContentAndReset(&devicemap);
     }
 
-    if (cd != NULL) {
-        virCommandAddArg(cmd, "--root");
+    virCommandAddArg(cmd, "--root");
+    if (userdef != NULL) {
+        if (userdef->device == VIR_DOMAIN_DISK_DEVICE_CDROM)
+            virCommandAddArg(cmd, "cd");
+        else
+            virCommandAddArg(cmd, "hd0,msdos1");
+    } else if (cd != NULL) {
         virCommandAddArg(cmd, "cd");
     } else {
-        virCommandAddArg(cmd, "--root");
         virCommandAddArg(cmd, "hd0,msdos1");
     }
 
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder.args b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder.args
new file mode 100644
index 0000000..eaba370
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder.args
@@ -0,0 +1,6 @@
+/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
+-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
+-s 2:0,ahci-hd,/tmp/freebsd1.img \
+-s 2:0,ahci-hd,/tmp/freebsd2.img \
+-s 2:0,ahci-hd,/tmp/freebsd3.img \
+bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder.devmap b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder.devmap
new file mode 100644
index 0000000..1be3b50
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder.devmap
@@ -0,0 +1 @@
+(hd0) /tmp/freebsd3.img
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder.ldargs b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder.ldargs
new file mode 100644
index 0000000..91c15ce
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder.ldargs
@@ -0,0 +1,2 @@
+/usr/local/sbin/grub-bhyve --root hd0,msdos1 --device-map '<device.map>' \
+--memory 214 bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder.xml
new file mode 100644
index 0000000..e372024
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder.xml
@@ -0,0 +1,36 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
+  <memory>219136</memory>
+  <vcpu>1</vcpu>
+  <bootloader>/usr/local/sbin/grub-bhyve</bootloader>
+  <os>
+    <type>hvm</type>
+  </os>
+  <devices>
+    <disk type='file'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/freebsd1.img'/>
+      <target dev='hda' bus='sata'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+    </disk>
+    <disk type='file'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/freebsd2.img'/>
+      <target dev='hda' bus='sata'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+    </disk>
+    <disk type='file'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/freebsd3.img'/>
+      <target dev='hda' bus='sata'/>
+      <boot order='1'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+    </disk>
+    <interface type='bridge'>
+      <model type='virtio'/>
+      <source bridge="virbr0"/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </interface>
+  </devices>
+</domain>
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder2.args b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder2.args
new file mode 100644
index 0000000..eaba370
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder2.args
@@ -0,0 +1,6 @@
+/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
+-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
+-s 2:0,ahci-hd,/tmp/freebsd1.img \
+-s 2:0,ahci-hd,/tmp/freebsd2.img \
+-s 2:0,ahci-hd,/tmp/freebsd3.img \
+bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder2.devmap b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder2.devmap
new file mode 100644
index 0000000..1be3b50
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder2.devmap
@@ -0,0 +1 @@
+(hd0) /tmp/freebsd3.img
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder2.ldargs b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder2.ldargs
new file mode 100644
index 0000000..91c15ce
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder2.ldargs
@@ -0,0 +1,2 @@
+/usr/local/sbin/grub-bhyve --root hd0,msdos1 --device-map '<device.map>' \
+--memory 214 bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder2.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder2.xml
new file mode 100644
index 0000000..8742a30
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder2.xml
@@ -0,0 +1,38 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
+  <memory>219136</memory>
+  <vcpu>1</vcpu>
+  <bootloader>/usr/local/sbin/grub-bhyve</bootloader>
+  <os>
+    <type>hvm</type>
+  </os>
+  <devices>
+    <disk type='file'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/freebsd1.img'/>
+      <target dev='hda' bus='sata'/>
+      <boot order='111'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+    </disk>
+    <disk type='file'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/freebsd2.img'/>
+      <target dev='hda' bus='sata'/>
+      <boot order='22'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+    </disk>
+    <disk type='file'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/freebsd3.img'/>
+      <target dev='hda' bus='sata'/>
+      <boot order='3'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+    </disk>
+    <interface type='bridge'>
+      <model type='virtio'/>
+      <source bridge="virbr0"/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </interface>
+  </devices>
+</domain>
diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c
index ec57160..cd3aea0 100644
--- a/tests/bhyvexml2argvtest.c
+++ b/tests/bhyvexml2argvtest.c
@@ -163,6 +163,8 @@ mymain(void)
     DO_TEST("serial");
     DO_TEST("console");
     DO_TEST("grub-defaults");
+    DO_TEST("grub-bootorder");
+    DO_TEST("grub-bootorder2");
     DO_TEST("bhyveload-explicitargs");
     DO_TEST("custom-loader");
     DO_TEST("disk-cdrom-grub");
-- 
1.9.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[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]