[Bug 262189] ZFS volume not showing up in /dev/zvol when 1 CPU

From: <bugzilla-noreply_at_freebsd.org>
Date: Fri, 25 Feb 2022 14:49:58 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=262189

Aleksandr Fedorov <afedorov@FreeBSD.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |afedorov@FreeBSD.org

--- Comment #2 from Aleksandr Fedorov <afedorov@FreeBSD.org> ---
There are two things.

First, I think /dev/zvol/<pool>/device is created asynchronously. Therefore,
after the completion of the "zfs create ..." command, the device may not have
been created yet and the dd command will fail.

I think that if you add "sleep 5" to the script, the error will not be
reproduced:

seq 1 100 | while read i; do
zfs create -o volmode=dev -V 1G $name_pool/data$i

sleep 5

dd if=/dev/zero of=/dev/zvol/$name_pool/data$i bs=1M
done

Second, the OpenZFS code creates a ZVOL device in a very strange way:
https://github.com/openzfs/zfs/blob/master/module/zfs/zvol.c#L1394

/*
* It's unfortunate we need to remove minors before we create new ones:
* this is necessary because our backing gendisk (zvol_state->zv_disk)
* could be different when we set, for instance, volmode from "geom"
* to "dev" (or vice versa).
*/

First, a ZVOL device is created with the default volmode, then it's removed and
created with the requested one. In FreeBSD, the default value for
vfs.zfs.vol.mode is 1 (GEOM). Therefore, there is a race between the ZFS and
GEOM threads. That's why you see this error: "g_dev_taste:
g_dev_taste(zvol/test/data22) failed to g_attach, error=6".

For example output of the "cat /var/run/devd.pipe" when I create ZVOL (zfs
create -V 1G -o volmode=dev datapool/test).
!system=GEOM subsystem=DEV type=CREATE cdev=zvol/datapool/test
!system=DEVFS subsystem=CDEV type=DESTROY cdev=zvol/datapool/test
!system=GEOM subsystem=DEV type=DESTROY cdev=zvol/datapool/test
!system=DEVFS subsystem=CDEV type=CREATE cdev=zvol/datapool/test

-- 
You are receiving this mail because:
You are the assignee for the bug.