From 0ae142b64039ba741ff69605d2a110074454a0ce Mon Sep 17 00:00:00 2001 From: Brooks Davis Date: Mon, 7 Nov 2022 18:09:41 +0000 Subject: [PATCH] nvpair: Always use XDR encoding Recievers are agnostic to stream format and just call nvpair_unpack or nvpair_xunpack which decode what ever stream type is received. It is easier to make a system with different unpacked sizes work with XDR than with native where streams are unpacked in place. This change provides forward compatability with systems were the size of pointers exceeds 64-bits. For example, a CheriBSD pure-capability kernel targeting Morello should be able to work with a FreeBSD aarch64 zfs or zpool command build with this change applied. Signed-off-by: Brooks Davis --- lib/libzfs/libzfs_dataset.c | 4 ++-- lib/libzfs/libzfs_util.c | 2 +- module/nvpair/fnvpair.c | 6 +++--- module/nvpair/nvpair.c | 3 +-- module/zfs/fm.c | 4 ++-- module/zfs/spa_history.c | 2 +- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/libzfs/libzfs_dataset.c b/lib/libzfs/libzfs_dataset.c index 87bc4ea66c..ff2212cd8c 100644 --- a/lib/libzfs/libzfs_dataset.c +++ b/lib/libzfs/libzfs_dataset.c @@ -5218,12 +5218,12 @@ zfs_set_fsacl(zfs_handle_t *zhp, boolean_t un, nvlist_t *nvl) assert(zhp->zfs_type == ZFS_TYPE_VOLUME || zhp->zfs_type == ZFS_TYPE_FILESYSTEM); - err = nvlist_size(nvl, &nvsz, NV_ENCODE_NATIVE); + err = nvlist_size(nvl, &nvsz, NV_ENCODE_XDR); assert(err == 0); nvbuf = malloc(nvsz); - err = nvlist_pack(nvl, &nvbuf, &nvsz, NV_ENCODE_NATIVE, 0); + err = nvlist_pack(nvl, &nvbuf, &nvsz, NV_ENCODE_XDR, 0); assert(err == 0); zc.zc_nvlist_src_size = nvsz; diff --git a/lib/libzfs/libzfs_util.c b/lib/libzfs/libzfs_util.c index b4679dbb36..86ed001ad7 100644 --- a/lib/libzfs/libzfs_util.c +++ b/lib/libzfs/libzfs_util.c @@ -1207,7 +1207,7 @@ zcmd_write_nvlist_com(libzfs_handle_t *hdl, uint64_t *outnv, uint64_t *outlen, size_t len = fnvlist_size(nvl); packed = zfs_alloc(hdl, len); - verify(nvlist_pack(nvl, &packed, &len, NV_ENCODE_NATIVE, 0) == 0); + verify(nvlist_pack(nvl, &packed, &len, NV_ENCODE_XDR, 0) == 0); *outnv = (uint64_t)(uintptr_t)packed; *outlen = len; diff --git a/module/nvpair/fnvpair.c b/module/nvpair/fnvpair.c index 86b0b4cdfc..effc4594cc 100644 --- a/module/nvpair/fnvpair.c +++ b/module/nvpair/fnvpair.c @@ -40,7 +40,7 @@ * functions, which can return the requested value (rather than filling in * a pointer). * - * These functions use NV_UNIQUE_NAME, encoding NV_ENCODE_NATIVE, and allocate + * These functions use NV_UNIQUE_NAME, encoding NV_ENCODE_XDR, and allocate * with KM_SLEEP. * * More wrappers should be added as needed -- for example @@ -65,7 +65,7 @@ size_t fnvlist_size(nvlist_t *nvl) { size_t size; - VERIFY0(nvlist_size(nvl, &size, NV_ENCODE_NATIVE)); + VERIFY0(nvlist_size(nvl, &size, NV_ENCODE_XDR)); return (size); } @@ -77,7 +77,7 @@ char * fnvlist_pack(nvlist_t *nvl, size_t *sizep) { char *packed = 0; - VERIFY3U(nvlist_pack(nvl, &packed, sizep, NV_ENCODE_NATIVE, + VERIFY3U(nvlist_pack(nvl, &packed, sizep, NV_ENCODE_XDR, KM_SLEEP), ==, 0); return (packed); } diff --git a/module/nvpair/nvpair.c b/module/nvpair/nvpair.c index c8161f116b..18301150d1 100644 --- a/module/nvpair/nvpair.c +++ b/module/nvpair/nvpair.c @@ -2753,8 +2753,7 @@ nvlist_xunpack(char *buf, size_t buflen, nvlist_t **nvlp, nv_alloc_t *nva) if ((err = nvlist_xalloc(&nvl, 0, nva)) != 0) return (err); - if ((err = nvlist_common(nvl, buf, &buflen, NV_ENCODE_NATIVE, - NVS_OP_DECODE)) != 0) + if ((err = nvlist_common(nvl, buf, &buflen, -1, NVS_OP_DECODE)) != 0) nvlist_free(nvl); else *nvlp = nvl; diff --git a/module/zfs/fm.c b/module/zfs/fm.c index 3f05d75977..bf8458b768 100644 --- a/module/zfs/fm.c +++ b/module/zfs/fm.c @@ -226,7 +226,7 @@ zfs_zevent_post(nvlist_t *nvl, nvlist_t *detector, zevent_cb_t *cb) goto out; } - error = nvlist_size(nvl, &nvl_size, NV_ENCODE_NATIVE); + error = nvlist_size(nvl, &nvl_size, NV_ENCODE_XDR); if (error) { atomic_inc_64(&erpt_kstat_data.erpt_dropped.value.ui64); goto out; @@ -337,7 +337,7 @@ zfs_zevent_next(zfs_zevent_t *ze, nvlist_t **event, uint64_t *event_size, } } - VERIFY(nvlist_size(ev->ev_nvl, &size, NV_ENCODE_NATIVE) == 0); + VERIFY(nvlist_size(ev->ev_nvl, &size, NV_ENCODE_XDR) == 0); if (size > *event_size) { *event_size = size; error = ENOMEM; diff --git a/module/zfs/spa_history.c b/module/zfs/spa_history.c index 6d468e7164..508a329614 100644 --- a/module/zfs/spa_history.c +++ b/module/zfs/spa_history.c @@ -330,7 +330,7 @@ spa_history_log_sync(void *arg, dmu_tx_t *tx) fnvlist_lookup_string(nvl, ZPOOL_HIST_IOCTL)); } - VERIFY3U(nvlist_pack(nvl, &record_packed, &reclen, NV_ENCODE_NATIVE, + VERIFY3U(nvlist_pack(nvl, &record_packed, &reclen, NV_ENCODE_XDR, KM_SLEEP), ==, 0); mutex_enter(&spa->spa_history_lock);