Bug 246750 - ZFS: Confusing error message when creating ZFS pool on vdev
Summary: ZFS: Confusing error message when creating ZFS pool on vdev
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-fs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-26 12:13 UTC by Mateusz Kwiatkowski
Modified: 2022-11-07 23:43 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mateusz Kwiatkowski 2020-05-26 12:13:16 UTC
On default FreeBSD configuration (vfs.zfs.vol.recursive == 0) it's impossible to create ZFS pools on vdevs. When users try to do this they see generic and confusing error message:

```
# zfs create -V 1G -s zroot/kwiat
# zpool create -f kwiat /dev/zvol/zroot/kwiat
cannot create 'kwiat': no such pool or dataset
```

For someone not experienced in ZFS it will take some time to learn how to workaround this as it seems it's not documented anywhere. What's more, on Linux it just works.

My ideas how to improve this:

1) Better error message when vfs.zfs.vol.recursive==0 and backing device is zvol.
Example: "cannot create 'kwiat': creating pool on zvol is dangerous. See man zpool(8) for more info."

2) Document it in the zpool(8) manpage in "zpool create" section
Comment 1 Mateusz Kwiatkowski 2020-05-26 18:57:38 UTC
After reboot, pool on zvol cannot be imported even with vfs.zfs.vol.recursive=1. zpool import command hangs indefinitely and ignores ^C. 

Output of procstat -k of that process:
  PID    TID COMM                TDNAME              KSTACK
 49700 102119 zpool               -                   mi_switch sleepq_switch _sx_xlock_hard _sx_xlock spa_all_configs zfs_ioc_pool_configs zfsdev_ioctl devfs_ioctl vn_ioctl devfs_ioctl_f kern_ioctl sys_ioctl amd64_syscall fast_syscall_common
Comment 2 Andriy Gapon freebsd_committer freebsd_triage 2020-05-27 06:45:28 UTC
(In reply to Mateusz Kwiatkowski from comment #1)
That kind of a hang is exactly why vfs.zfs.vol.recursive is zero by default.
Comment 3 Mateusz Kwiatkowski 2020-05-27 07:47:11 UTC
(In reply to Andriy Gapon from comment #2)
That's my guess too. UX could be better either way.
Comment 4 dan 2022-11-07 23:43:52 UTC
Pretty serious bug, no way to mount a zfs pool from a zvol without it.
Any progress on this?

Issue:
zfs create -V30G -o volmode=full zroot/asterisk2
(install a ZFS guest on it)
router:~ # gpart show /dev/zvol/zroot/asterisk2
=>      40  62914480  zvol/zroot/asterisk2  GPT  (30G)
        40    532480                     1  efi  (260M)
    532520      2008                        - free -  (1.0M)
    534528  16777216                     2  freebsd-swap  (8.0G)
  17311744  45600768                     3  freebsd-zfs  (22G)
  62912512      2008                        - free -  (1.0M)

router:~ # gdisk -l /dev/zvol/zroot/asterisk2
GPT fdisk (gdisk) version 1.0.9

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/zvol/zroot/asterisk2: 62914560 sectors, 30.0 GiB
Sector size (logical): 512 bytes
Disk identifier (GUID): 8ACD2112-5EBF-11ED-8F56-00A098E3C14E
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 40, last usable sector is 62914519
Partitions will be aligned on 8-sector boundaries
Total free space is 4016 sectors (2.0 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              40          532519   260.0 MiB   EF00  efiboot0
   2          534528        17311743   8.0 GiB     A502  swap0
   3        17311744        62912511   21.7 GiB    A504  zfs0
router:~ # zpool import
   pool: testing
     id: 8013833172609421701
  state: UNAVAIL
status: One or more devices are missing from the system.
 action: The pool cannot be imported. Attach the missing
        devices and try again.
   see: https://openzfs.github.io/openzfs-docs/msg/ZFS-8000-3C
 config:

        testing                   UNAVAIL  insufficient replicas
          zvol/zroot/asterisk2p3  UNAVAIL  cannot open
router:~ # sysctl vfs.zfs.vol.recursive=1
vfs.zfs.vol.recursive: 0 -> 1
router:~ # zpool import
   pool: testing
     id: 8013833172609421701
  state: ONLINE
 action: The pool can be imported using its name or numeric identifier.
 config:

        testing                   ONLINE
          zvol/zroot/asterisk2p3  ONLINE
zpool import -fR /mnt testing

This hangs forever....
The only way to import that pool from the zvol.