openzfs icon indicating copy to clipboard operation
openzfs copied to clipboard

cloned encrypted zvol does not get create_minor.

Open lundman opened this issue 4 years ago • 3 comments

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 avatar Aug 10 '21 08:08 lundman

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;

  • A) Have spa_keystore_load_wkey call zvol_create_minors_recursive on the pool (BOOM) ?
  • B) Have spa_keystore_load_wkey detect and iterate any other children using newly loaded key ?
  • C) Call spa_keystore_load_wkey first, then zvol_create_minors_recursive ?
  • D) Panic

lundman avatar Aug 10 '21 08:08 lundman

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 avatar Aug 10 '21 09:08 lundman

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'

lundman avatar Aug 10 '21 11:08 lundman