openzfsonosx / openzfs

OpenZFS on Linux and FreeBSD, and, macOS. This is where development for macOS happens.
https://github.com/openzfs/zfs/wiki
Other
144 stars 12 forks source link

cloned encrypted zvol does not get create_minor. #99

Open lundman opened 3 years ago

lundman commented 3 years ago
zfs create -V1G -o encryption=on -o keyformat=passphrase BOOM/vol1
zfs snap BOOM/vol1@snap
zfs clone BOOM/vol1@snap BOOM/vol2
zpool export -a
zpool import -l

Only BOOM/vol1 gets a /dev/diskX entry, and BOOM/vol2 does not. Both list keys as available.

This appears related to https://github.com/openzfs/zfs/issues/10603

lundman commented 3 years ago

What appears to happen is;

Pass 1;

zvol_create_minors_recursive()
 - calls dmu_objset_find(DS_FIND_CHILDREN)
 - and calls zvol_create_minors_cb() for BOTH zvols.
 - but since they do not have keys loaded, zvol_create_minors_cb() just returns.

At this point, spa import calls to load the keys, the stack looks like;

  0  99115      zvol_create_minors_cb:entry BOOM/vol1
              zfs`dmu_objset_find_impl+0x389
              zfs`zvol_create_minors_recursive+0x86
              zfs`spa_keystore_load_wkey+0x28a
              zfs`zfs_ioc_load_key+0x8e

Note here, that after the key has been loaded, it directly calls zvol_create_minors_cb() with ONLY BOOM/vol1!
It does not call again for BOOM/vol2 presumably as "now the key have been loaded".

We should possibly change it by;

lundman commented 3 years ago

zfs_ioc_load_key is just called for BOOM/vol1 and nothing else. and spa_keystore_load_wkey() only deals with that. Even if you call zfs_ioc_load_key for BOOM/vol2 it will not call zvol_create_minors_cb because it will error with EEXIST.

lundman commented 3 years ago

This would work:

692d652

<zfs`zvol_create_minors_recursive (zvol.c:1188)> zvol_create_minors_recursive: on 'BOOM/disk1'
<zfs`zvol_add_clones (zvol.c:1084)> adding clone 'BOOM/disk2'
<zfs`zvol_os_create_minor (zvol_os.c:686)> zvol_os_create_minor: 'BOOM/disk1'
<zfs`zvol_os_create_minor (zvol_os.c:686)> zvol_os_create_minor: 'BOOM/disk2'