For an encrypted dataset it is possible that by the time we arrive in zio_write() [ zio_write_encrypt() ] that when we lookup which key is needed to encrypted this data that key isn't available to us.
Is there some value of zio->io_error I can set that will not result in a panic ? but will put the write in to some state where we can try again later - I guess not just this write but maybe the whole transaction group ? I can, and I think I have, fixed the mount time case by returning false from zfs_is_mountable() if the dataset is encrypted and the key needed isn't present. However the key could go away - without us knowing so in some cases (not really for the pure software case but it can happen with hardware token keys). -- Darren J Moffat