xen FreeBSD blkfront.c only maps 4 devices from Xen XCP-NG (XenServer)

So, to my surprise, FreeBSD 13.2 (and most versions, likely) can't map more 4 virtual block devices to a FreeBSD DomU (guest) - despite, not using the emulated drives, but using the PV drivers. (ada0,1,2 ... I believe ada3 is being reserved for the CDROM drive.)

Despite these being "ada" ... they are do not to be emulated SATA drives, but just a naming convention to allow more easy conversation of images. (I thought I remember FreeBSD VMs coming up with /dev/xbd0 instead of /dev/ada0 in the past ... maybe that is bhyve and not Xen.) Any who, since xbd4 comes in with major number of 202, xbd_vdevice_to_unit(), maps this to xbd, instead of ada. Then in xbd_instance_create() ...
C:
if (strcmp(name, "xbd") != 0)
- so if the device name isn't xbd ... then don't map the device. Thus, xbd4 and greater have major numbers of 202, with its name getting set to xbd, and thus these messages aren't seen:

Code:
xbd1: attaching as ada0


Since I've been using zfs root, for, well, a decade now, the /dev/ names aren't that important, but would like to get access to the other drives. I've created this hack/patch, compiled and running now. Would like to clean this up, as this I'd like to map all the xbd's as /dev/xbd* ... or at least have that option, but want to get some input ... am I missing something simple to see all the drives via virtio_blk ?

Diff:
--- sys/dev/xen/blkfront/blkfront.c.orig    2023-02-18 21:51:13.000000000 +0000
+++ sys/dev/xen/blkfront/blkfront.c    2023-06-05 17:04:21.234109000 +0000
@@ -925,6 +925,10 @@
     SYSCTL_ADD_PROC(sysctl_ctx, children, OID_AUTO,
         "features", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, xbd,
         0, xbd_sysctl_features, "A", "protocol features (negotiated)");
+
+    SYSCTL_ADD_INT(sysctl_ctx, children, OID_AUTO,
+        "enable_xbd_devs", CTLFLAG_RDTUN, &xbd->enable_xbd_devs,
+        0, "Support more ATA/VDISKs on IDE/ATA via virt_blk using the /dev/xbd* devices.");
 }

 /*
@@ -1004,11 +1008,16 @@
     int unit, error = 0;
     const char *name;

+    int major = vdevice >> 8;
+    int minor = vdevice & 0xff;
+
+    device_printf(sc->xbd_dev, "xbd_vdevice_to_unit: vdevice: %0x08x (%8d) major: %4d minor: %4d \n", vdevice, vdevice, major, minor);
+
     xbd_vdevice_to_unit(vdevice, &unit, &name);

     sc->xbd_unit = unit;

-    if (strcmp(name, "xbd") != 0)
+    if ( ( strcmp(name, "xbd") != 0 ) || sc->enable_xbd_devs )
         device_printf(sc->xbd_dev, "attaching as %s%d\n", name, unit);

     if (xbd_feature_string(sc, features, sizeof(features)) > 0) {

I created a zpool of the extra drives, ran some bonnie on it, and dd to fill it up ... looks good ...
Code:
> zpool status test
  pool: test
 state: ONLINE
config:

    NAME        STATE     READ WRITE CKSUM
    test        ONLINE       0     0     0
      raidz1-0  ONLINE       0     0     0
        xbd4    ONLINE       0     0     0
        xbd5    ONLINE       0     0     0
        xbd6    ONLINE       0     0     0

errors: No known data errors

However, I don't like the sysctl like this ... as this requires the unit number in in /boot/loader.conf ... I would like to make this at the top parent - dev.xbd.enable_xbd_devs ... and of course, will still tweak things to get get the ada drives maps back to xbd.

Code:
dev.xbd.0.enable_xbd_devs=1
dev.xbd.1.enable_xbd_devs=1
dev.xbd.2.enable_xbd_devs=1
dev.xbd.3.enable_xbd_devs=1
dev.xbd.4.enable_xbd_devs=1
dev.xbd.5.enable_xbd_devs=1
dev.xbd.6.enable_xbd_devs=1
dev.xbd.7.enable_xbd_devs=1
dev.xbd.8.enable_xbd_devs=1
dev.xbd.9.enable_xbd_devs=1
dev.xbd.10.enable_xbd_devs=1
dev.xbd.11.enable_xbd_devs=1
dev.xbd.12.enable_xbd_devs=1
dev.xbd.13.enable_xbd_devs=1
dev.xbd.14.enable_xbd_devs=1
dev.xbd.15.enable_xbd_devs=1
 
Back
Top