Page MenuHomeFreeBSD

bhyve/net_backends: Source file descriptors from nvlists
Needs ReviewPublic

Authored by bnovkov on Sun, Jan 11, 1:33 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Jan 31, 11:29 AM
Unknown Object (File)
Thu, Jan 29, 12:50 PM
Unknown Object (File)
Sun, Jan 25, 4:09 PM
Unknown Object (File)
Sun, Jan 25, 3:40 PM
Unknown Object (File)
Sat, Jan 24, 10:10 PM
Unknown Object (File)
Thu, Jan 22, 5:52 PM
Unknown Object (File)
Wed, Jan 21, 4:20 AM
Unknown Object (File)
Tue, Jan 20, 11:29 AM

Details

Reviewers
None
Group Reviewers
bhyve
Summary

This change converts all existing network backends to use the
new, hotplug-friendly file descriptor initialization scheme.
Parts of the backend initialization routines that deal with files
have been factored out and moved to libbhyve and made available
to other hotpluggable device using the pci_init_fds routines.
The backend initialization routines now expect their required file
descriptors to be present in the nvlist object.
The configuration parsing routines were also moved and made available
via libbhyve's pci_parse_config routine.

This is a prerequisite for making the e1000 and virtio-net devices
hotpluggable.

While we're here, add additional failure messages in the backend
initialization routines.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

novel added inline comments.
lib/libbhyve/net_backends.c
54

jemalloc on my system does not like this:

bhyve -c 2 -m 4096 -S -A -I -u -H -P -s 0:0,hostbridge -l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd -s 1:0,lpc -s 2:0,e1000,slirp,mac=52:54:00:77:e7:eb,open -s 7:0,virtio-blk,/data/img/ubuntu2510.img -s 5:0,fbuf,tcp=127.0.0.1:5957 ubuntu2510
<jemalloc>: jemalloc_rtree.c:146: Failed assertion: "!dependent || leaf != NULL"

The following workaround fixes that for me:

--- a/lib/libbhyve/net_backends.c
+++ b/lib/libbhyve/net_backends.c
@@ -40,18 +40,22 @@ static int
 slirp_init_fds(nvlist_t *nvl)
 {
        int error;
-       int sockpair_fds[2];
+       int *sockpair_fds = calloc(2, sizeof(int));
+       if (sockpair_fds == NULL) {
+               nvlist_add_stringf(nvl, "error", "Unable to allocate sockpair_fds");
+               return (-1);
+       }
 
        error = socketpair(PF_LOCAL, SOCK_SEQPACKET | SOCK_NONBLOCK, 0,
            sockpair_fds);
        if (error != 0) {
                nvlist_add_stringf(nvl, "error", "Unable to create pipe: %s",
                    strerror(errno));
+               free(sockpair_fds);
                return (error);
        }
 
-       nvlist_move_descriptor_array(nvl, "sockpair", sockpair_fds,
-           sizeof(sockpair_fds));
+       nvlist_move_descriptor_array(nvl, "sockpair", sockpair_fds, 2);
 
        return (0);
 }

Use procdesc(4) to enable slirp backend hotplugging.