Page MenuHomeFreeBSD

bhyve: add helper to create a bootorder
ClosedPublic

Authored by corvink on Mar 27 2023, 10:29 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Oct 18, 3:06 PM
Unknown Object (File)
Sep 19 2024, 2:37 AM
Unknown Object (File)
Sep 18 2024, 10:25 PM
Unknown Object (File)
Sep 10 2024, 4:10 PM
Unknown Object (File)
Aug 26 2024, 10:01 PM
Unknown Object (File)
Aug 19 2024, 4:31 AM
Unknown Object (File)
Aug 12 2024, 10:15 AM
Unknown Object (File)
Jul 8 2024, 10:25 PM

Details

Summary

Qemu's fwcfg allows to define a bootorder. Therefore, the hypervisor has
to create a fwcfg item named bootorder, which has a newline seperated
list of boot entries. Qemu's OVMF will pick up the bootorder and applies
it.

Add the moment, bhyve's OVMF doesn't support a custom bootorder by
qemu's fwcfg. However, in the future bhyve will gain support for qemu's
OVMF. Additonally, we can port relevant parts from qemu to bhyve's OVMF
implementation if desired.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 50599
Build 47490: arc lint + arc unit

Event Timeline

rew added inline comments.
usr.sbin/bhyve/pci_emul.c
977

why negative error here?

1440–1441
1587

why not return the error instead?

usr.sbin/bhyve/pci_emul.c
975

Note that style(9) also really wants you to declare all the variables within a block up front.

982

A TAILQ is fine. If the logic is simpler, a growable array of pointers might be the other option to consider as then checking for a conflict is simpler I think. In the iteration case you just have to skip NULL pointers in the array.

1418

Have you considered using open_memstream() to construct this string? It will do all the realloc + NUL terminate for you letting you do something like:

struct boot_device *device;
FILE *fp;
char *bootorder;
size_t bootorder_len;

if (TAILQ_EMPTY(&boot_devices))
    return (0);

fp = open_memstream(&fp, &bootorder_len);
TAILQ_FOREACH(device, &boot_devices, boot_device_chain) {
    fwrite(fp, "/pci@i0cf8/pci@%d,%d\n", device->pdi->pdi_slot,
        device->pdi->pdi_func);
}
fclose(cp);

return (qemu_fwcfg_add_file("bootorder", bootorder_len, bootorder));
1583

The comment mostly duplicates the function name so you can probably omit it.

  • fix style issues
  • use memstream to build a bootorder fwcfg item

Just one more suggestion. If you decide to use fprintf, you can still count it as reviewed.

usr.sbin/bhyve/pci_emul.c
1423

Is the NAME_MAX restriction part of the fwcfg API for this node? If not, maybe just use fprintf directly without the bootpath temporary variable?

This revision is now accepted and ready to land.Jun 19 2023, 5:21 PM
markj added inline comments.
usr.sbin/bhyve/pci_emul.c
989
1583
This revision was automatically updated to reflect the committed changes.