Since the commit :
commit 116e85d29648e0ee6ef07be8f75760280b403d2a MFV r323790: 8567 Inconsistent return value in zpool_read_label
I'm no longer able to add to a zpool a cache device which doens't contain a previous vdev label:
[15:13 root@sh-3-4-fbsd][~]# zpool add -n testpool da126 internal error: out of memory
da126 being a new disk which was never used.
Note that the zpool "tespool" is big. It contains 65 vdevs/slog/caches .
If I try to add da126 in a smaller zpool it works and after that I'm able to swap in to my "testpool" zpool.
I'm attaching a patch that fix my issue, in my case I guess errno is setted to ENOMEM by a previous not related to the fstat64 call that happen in zpool_read_label.