From d68a2bfa994d3d064924e8c303a9a7e8e6e02682 Mon Sep 17 00:00:00 2001 From: Ryan Moeller Date: Wed, 8 Jun 2022 13:08:10 +0000 Subject: [PATCH] libzfs: Define the defecto standard errbuf size Every errbuf array in libzfs is 1024 chars. Define ERRBUFLEN in a shared header, and use it. Reviewed-by: Brian Behlendorf Signed-off-by: Ryan Moeller Closes #13539 --- lib/libzfs/libzfs_crypto.c | 10 +++---- lib/libzfs/libzfs_dataset.c | 42 +++++++++++++-------------- lib/libzfs/libzfs_diff.c | 2 +- lib/libzfs/libzfs_impl.h | 4 ++- lib/libzfs/libzfs_pool.c | 14 ++++----- lib/libzfs/libzfs_sendrecv.c | 28 +++++++++--------- lib/libzfs/os/freebsd/libzfs_compat.c | 2 -- lib/libzfs/os/linux/libzfs_pool_os.c | 2 +- 8 files changed, 52 insertions(+), 52 deletions(-) diff --git a/lib/libzfs/libzfs_crypto.c b/lib/libzfs/libzfs_crypto.c index 1effe74f33..737b3f4dcc 100644 --- a/lib/libzfs/libzfs_crypto.c +++ b/lib/libzfs/libzfs_crypto.c @@ -1003,7 +1003,7 @@ zfs_crypto_create(libzfs_handle_t *hdl, char *parent_name, nvlist_t *props, uint_t *wkeylen_out) { int ret; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; uint64_t crypt = ZIO_CRYPT_INHERIT, pcrypt = ZIO_CRYPT_INHERIT; uint64_t keyformat = ZFS_KEYFORMAT_NONE; char *keylocation = NULL; @@ -1174,7 +1174,7 @@ zfs_crypto_clone_check(libzfs_handle_t *hdl, zfs_handle_t *origin_zhp, char *parent_name, nvlist_t *props) { (void) origin_zhp, (void) parent_name; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "Encryption clone error")); @@ -1276,7 +1276,7 @@ zfs_crypto_load_key(zfs_handle_t *zhp, boolean_t noop, const char *alt_keylocation) { int ret, attempts = 0; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; uint64_t keystatus, iters = 0, salt = 0; uint64_t keyformat = ZFS_KEYFORMAT_NONE; char prop_keylocation[MAXNAMELEN]; @@ -1444,7 +1444,7 @@ int zfs_crypto_unload_key(zfs_handle_t *zhp) { int ret; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; char prop_encroot[MAXNAMELEN]; uint64_t keystatus, keyformat; boolean_t is_encroot; @@ -1580,7 +1580,7 @@ int zfs_crypto_rewrap(zfs_handle_t *zhp, nvlist_t *raw_props, boolean_t inheritkey) { int ret; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; boolean_t is_encroot; nvlist_t *props = NULL; uint8_t *wkeydata = NULL; diff --git a/lib/libzfs/libzfs_dataset.c b/lib/libzfs/libzfs_dataset.c index 1f6addcae5..b449fabdf5 100644 --- a/lib/libzfs/libzfs_dataset.c +++ b/lib/libzfs/libzfs_dataset.c @@ -678,7 +678,7 @@ zfs_handle_t * zfs_open(libzfs_handle_t *hdl, const char *path, int types) { zfs_handle_t *zhp; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; char *bookp; (void) snprintf(errbuf, sizeof (errbuf), @@ -1716,7 +1716,7 @@ int zfs_prop_set(zfs_handle_t *zhp, const char *propname, const char *propval) { int ret = -1; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; libzfs_handle_t *hdl = zhp->zfs_hdl; nvlist_t *nvl = NULL; @@ -1750,7 +1750,7 @@ zfs_prop_set_list(zfs_handle_t *zhp, nvlist_t *props) int ret = -1; prop_changelist_t **cls = NULL; int cl_idx; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; libzfs_handle_t *hdl = zhp->zfs_hdl; nvlist_t *nvl; int nvl_len = 0; @@ -1930,7 +1930,7 @@ zfs_prop_inherit(zfs_handle_t *zhp, const char *propname, boolean_t received) int ret; prop_changelist_t *cl; libzfs_handle_t *hdl = zhp->zfs_hdl; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; zfs_prop_t prop; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, @@ -3402,7 +3402,7 @@ check_parents(libzfs_handle_t *hdl, const char *path, uint64_t *zoned, char parent[ZFS_MAX_DATASET_NAME_LEN]; char *slash; zfs_handle_t *zhp; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; uint64_t is_zoned; (void) snprintf(errbuf, sizeof (errbuf), @@ -3580,7 +3580,7 @@ zfs_create_ancestors(libzfs_handle_t *hdl, const char *path) { int prefix; char *path_copy; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; int rc = 0; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, @@ -3624,7 +3624,7 @@ zfs_create(libzfs_handle_t *hdl, const char *path, zfs_type_t type, zpool_handle_t *zpool_handle; uint8_t *wkeydata = NULL; uint_t wkeylen = 0; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; char parent[ZFS_MAX_DATASET_NAME_LEN]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, @@ -3897,7 +3897,7 @@ zfs_destroy_snaps_nvl(libzfs_handle_t *hdl, nvlist_t *snaps, boolean_t defer) } if (nvlist_empty(errlist)) { - char errbuf[1024]; + char errbuf[ERRBUFLEN]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "cannot destroy snapshots")); @@ -3905,7 +3905,7 @@ zfs_destroy_snaps_nvl(libzfs_handle_t *hdl, nvlist_t *snaps, boolean_t defer) } for (pair = nvlist_next_nvpair(errlist, NULL); pair != NULL; pair = nvlist_next_nvpair(errlist, pair)) { - char errbuf[1024]; + char errbuf[ERRBUFLEN]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "cannot destroy snapshot %s"), nvpair_name(pair)); @@ -3934,7 +3934,7 @@ zfs_clone(zfs_handle_t *zhp, const char *target, nvlist_t *props) { char parent[ZFS_MAX_DATASET_NAME_LEN]; int ret; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; libzfs_handle_t *hdl = zhp->zfs_hdl; uint64_t zoned; @@ -4018,7 +4018,7 @@ zfs_promote(zfs_handle_t *zhp) libzfs_handle_t *hdl = zhp->zfs_hdl; char snapname[ZFS_MAX_DATASET_NAME_LEN]; int ret; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "cannot promote '%s'"), zhp->zfs_name); @@ -4100,7 +4100,7 @@ int zfs_snapshot_nvl(libzfs_handle_t *hdl, nvlist_t *snaps, nvlist_t *props) { int ret; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; nvpair_t *elem; nvlist_t *errors; zpool_handle_t *zpool_hdl; @@ -4185,7 +4185,7 @@ zfs_snapshot(libzfs_handle_t *hdl, const char *path, boolean_t recursive, char fsname[ZFS_MAX_DATASET_NAME_LEN]; char *cp; zfs_handle_t *zhp; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "cannot snapshot %s"), path); @@ -4328,7 +4328,7 @@ zfs_rollback(zfs_handle_t *zhp, zfs_handle_t *snap, boolean_t force) */ err = lzc_rollback_to(zhp->zfs_name, snap->zfs_name); if (err != 0) { - char errbuf[1024]; + char errbuf[ERRBUFLEN]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "cannot rollback '%s'"), @@ -4387,7 +4387,7 @@ zfs_rename(zfs_handle_t *zhp, const char *target, renameflags_t flags) char parent[ZFS_MAX_DATASET_NAME_LEN]; char property[ZFS_MAXPROPLEN]; libzfs_handle_t *hdl = zhp->zfs_hdl; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; /* if we have the same exact name, just return success */ if (strcmp(zhp->zfs_name, target) == 0) @@ -4902,7 +4902,7 @@ zfs_hold(zfs_handle_t *zhp, const char *snapname, const char *tag, (void) zfs_hold_one(zfs_handle_dup(zhp), &ha); if (nvlist_empty(ha.nvl)) { - char errbuf[1024]; + char errbuf[ERRBUFLEN]; fnvlist_free(ha.nvl); ret = ENOENT; @@ -4926,7 +4926,7 @@ zfs_hold_nvl(zfs_handle_t *zhp, int cleanup_fd, nvlist_t *holds) int ret; nvlist_t *errors; libzfs_handle_t *hdl = zhp->zfs_hdl; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; nvpair_t *elem; errors = NULL; @@ -5028,7 +5028,7 @@ zfs_release(zfs_handle_t *zhp, const char *snapname, const char *tag, nvlist_t *errors = NULL; nvpair_t *elem; libzfs_handle_t *hdl = zhp->zfs_hdl; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; ha.nvl = fnvlist_alloc(); ha.snapname = snapname; @@ -5108,7 +5108,7 @@ zfs_get_fsacl(zfs_handle_t *zhp, nvlist_t **nvl) int nvsz = 2048; void *nvbuf; int err = 0; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; assert(zhp->zfs_type == ZFS_TYPE_VOLUME || zhp->zfs_type == ZFS_TYPE_FILESYSTEM); @@ -5172,7 +5172,7 @@ zfs_set_fsacl(zfs_handle_t *zhp, boolean_t un, nvlist_t *nvl) zfs_cmd_t zc = {"\0"}; libzfs_handle_t *hdl = zhp->zfs_hdl; char *nvbuf; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; size_t nvsz; int err; @@ -5224,7 +5224,7 @@ int zfs_get_holds(zfs_handle_t *zhp, nvlist_t **nvl) { int err; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; err = lzc_get_holds(zhp->zfs_name, nvl); diff --git a/lib/libzfs/libzfs_diff.c b/lib/libzfs/libzfs_diff.c index a414024bb4..f0e9a262e6 100644 --- a/lib/libzfs/libzfs_diff.c +++ b/lib/libzfs/libzfs_diff.c @@ -709,7 +709,7 @@ zfs_show_diffs(zfs_handle_t *zhp, int outfd, const char *fromsnap, const char *tosnap, int flags) { zfs_cmd_t zc = {"\0"}; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; differ_info_t di = { 0 }; pthread_t tid; int pipefd[2]; diff --git a/lib/libzfs/libzfs_impl.h b/lib/libzfs/libzfs_impl.h index 926e14a371..38104fb5cf 100644 --- a/lib/libzfs/libzfs_impl.h +++ b/lib/libzfs/libzfs_impl.h @@ -44,6 +44,8 @@ extern "C" { #endif +#define ERRBUFLEN 1024 + struct libzfs_handle { int libzfs_error; int libzfs_fd; @@ -208,7 +210,7 @@ typedef struct differ_info { char *ds; char *dsmnt; char *tmpsnap; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; boolean_t isclone; boolean_t scripted; boolean_t classify; diff --git a/lib/libzfs/libzfs_pool.c b/lib/libzfs/libzfs_pool.c index 730e6db53f..98cae5a044 100644 --- a/lib/libzfs/libzfs_pool.c +++ b/lib/libzfs/libzfs_pool.c @@ -776,7 +776,7 @@ zpool_set_prop(zpool_handle_t *zhp, const char *propname, const char *propval) { zfs_cmd_t zc = {"\0"}; int ret = -1; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; nvlist_t *nvl = NULL; nvlist_t *realprops; uint64_t version; @@ -2009,7 +2009,7 @@ zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname, char *origname; int ret; int error = 0; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; origname = fnvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME); @@ -4998,7 +4998,7 @@ zpool_vdev_guid(zpool_handle_t *zhp, const char *vdevname, uint64_t *vdev_guid) verify(zhp != NULL); if (zpool_get_state(zhp) == POOL_STATE_UNAVAIL) { - char errbuf[1024]; + char errbuf[ERRBUFLEN]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "pool is in an unavailable state")); return (zfs_error(zhp->zpool_hdl, EZFS_POOLUNAVAIL, errbuf)); @@ -5006,7 +5006,7 @@ zpool_vdev_guid(zpool_handle_t *zhp, const char *vdevname, uint64_t *vdev_guid) if ((tgt = zpool_find_vdev(zhp, vdevname, &avail_spare, &l2cache, NULL)) == NULL) { - char errbuf[1024]; + char errbuf[ERRBUFLEN]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "can not find %s in %s"), vdevname, zhp->zpool_name); @@ -5216,7 +5216,7 @@ zpool_get_vdev_prop(zpool_handle_t *zhp, const char *vdevname, vdev_prop_t prop, ret = zpool_get_vdev_prop_value(retprops, prop, prop_name, buf, len, srctype, literal); } else { - char errbuf[1024]; + char errbuf[ERRBUFLEN]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "cannot get vdev property %s from" " %s in %s"), prop_name, vdevname, zhp->zpool_name); @@ -5254,7 +5254,7 @@ zpool_get_all_vdev_props(zpool_handle_t *zhp, const char *vdevname, nvlist_free(nvl); if (ret) { - char errbuf[1024]; + char errbuf[ERRBUFLEN]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "cannot get vdev properties for" " %s in %s"), vdevname, zhp->zpool_name); @@ -5295,7 +5295,7 @@ zpool_set_vdev_prop(zpool_handle_t *zhp, const char *vdevname, return (no_memory(zhp->zpool_hdl)); } - char errbuf[1024]; + char errbuf[ERRBUFLEN]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "cannot set property %s for %s on %s"), propname, vdevname, zhp->zpool_name); diff --git a/lib/libzfs/libzfs_sendrecv.c b/lib/libzfs/libzfs_sendrecv.c index 6017b0e43a..683813ee3b 100644 --- a/lib/libzfs/libzfs_sendrecv.c +++ b/lib/libzfs/libzfs_sendrecv.c @@ -734,7 +734,7 @@ zfs_send_space(zfs_handle_t *zhp, const char *snapname, const char *from, if (error == 0) return (0); - char errbuf[1024]; + char errbuf[ERRBUFLEN]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "warning: cannot estimate space for '%s'"), snapname); @@ -804,7 +804,7 @@ dump_ioctl(zfs_handle_t *zhp, const char *fromsnap, uint64_t fromsnap_obj, } if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_SEND, &zc) != 0) { - char errbuf[1024]; + char errbuf[ERRBUFLEN]; int error = errno; (void) snprintf(errbuf, sizeof (errbuf), "%s '%s'", @@ -1615,7 +1615,7 @@ find_redact_book(libzfs_handle_t *hdl, const char *path, const uint64_t *redact_snap_guids, int num_redact_snaps, char **bookname) { - char errbuf[1024]; + char errbuf[ERRBUFLEN]; nvlist_t *bmarks; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, @@ -1679,7 +1679,7 @@ static int zfs_send_resume_impl_cb_impl(libzfs_handle_t *hdl, sendflags_t *flags, int outfd, nvlist_t *resume_nvl) { - char errbuf[1024]; + char errbuf[ERRBUFLEN]; char *toname; char *fromname = NULL; uint64_t resumeobj, resumeoff, toguid, fromguid, bytes; @@ -1827,7 +1827,7 @@ zfs_send_resume_impl_cb_impl(libzfs_handle_t *hdl, sendflags_t *flags, if (flags->progress && send_progress_thread_exit(hdl, tid)) return (-1); - char errbuf[1024]; + char errbuf[ERRBUFLEN]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "warning: cannot send '%s'"), zhp->zfs_name); @@ -1907,7 +1907,7 @@ zfs_send_resume(libzfs_handle_t *hdl, sendflags_t *flags, int outfd, const char *resume_token) { int ret; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; nvlist_t *resume_nvl; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, @@ -1938,7 +1938,7 @@ zfs_send_saved(zfs_handle_t *zhp, sendflags_t *flags, int outfd, uint64_t saved_guid = 0, resume_guid = 0; uint64_t obj = 0, off = 0, bytes = 0; char token_buf[ZFS_MAXPROPLEN]; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "saved send failed")); @@ -2062,7 +2062,7 @@ send_prelim_records(zfs_handle_t *zhp, const char *from, int fd, /* short name of snap we are sending */ char *tosnap = ""; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "warning: cannot send '%s'"), zhp->zfs_name); if (zhp->zfs_type == ZFS_TYPE_FILESYSTEM && zfs_prop_get_int(zhp, @@ -2187,7 +2187,7 @@ zfs_send_cb_impl(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, sendflags_t *flags, int outfd, snapfilter_cb_t filter_func, void *cb_arg, nvlist_t **debugnvp) { - char errbuf[1024]; + char errbuf[ERRBUFLEN]; send_dump_data_t sdd = { 0 }; int err = 0; nvlist_t *fss = NULL; @@ -2510,7 +2510,7 @@ zfs_send_one_cb_impl(zfs_handle_t *zhp, const char *from, int fd, pthread_t ptid; progress_arg_t pa = { 0 }; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "warning: cannot send '%s'"), name); @@ -3654,7 +3654,7 @@ zfs_receive_package(libzfs_handle_t *hdl, int fd, const char *destname, char *cp; char tofs[ZFS_MAX_DATASET_NAME_LEN]; char sendfs[ZFS_MAX_DATASET_NAME_LEN]; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; dmu_replay_record_t drre; int error; boolean_t anyerr = B_FALSE; @@ -3871,7 +3871,7 @@ recv_skip(libzfs_handle_t *hdl, int fd, boolean_t byteswap) dmu_replay_record_t *drr; void *buf = zfs_alloc(hdl, SPA_MAXBLOCKSIZE); uint64_t payload_size; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "cannot receive")); @@ -4239,7 +4239,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, int ioctl_err, ioctl_errno, err; char *cp; struct drr_begin *drrb = &drr->drr_u.drr_begin; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; const char *chopprefix; boolean_t newfs = B_FALSE; boolean_t stream_wantsnewfs, stream_resumingnewfs; @@ -5151,7 +5151,7 @@ zfs_receive_impl(libzfs_handle_t *hdl, const char *tosnap, int err; dmu_replay_record_t drr, drr_noswap; struct drr_begin *drrb = &drr.drr_u.drr_begin; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; zio_cksum_t zcksum = { { 0 } }; uint64_t featureflags; int hdrtype; diff --git a/lib/libzfs/os/freebsd/libzfs_compat.c b/lib/libzfs/os/freebsd/libzfs_compat.c index 289c6703c2..b08b7e2c43 100644 --- a/lib/libzfs/os/freebsd/libzfs_compat.c +++ b/lib/libzfs/os/freebsd/libzfs_compat.c @@ -193,8 +193,6 @@ execvpe(const char *name, char * const argv[], char * const envp[]) return (execvPe(name, path, argv, envp)); } -#define ERRBUFLEN 1024 - static __thread char errbuf[ERRBUFLEN]; const char * diff --git a/lib/libzfs/os/linux/libzfs_pool_os.c b/lib/libzfs/os/linux/libzfs_pool_os.c index 570615cfd4..b135e01469 100644 --- a/lib/libzfs/os/linux/libzfs_pool_os.c +++ b/lib/libzfs/os/linux/libzfs_pool_os.c @@ -216,7 +216,7 @@ zpool_label_disk(libzfs_handle_t *hdl, zpool_handle_t *zhp, const char *name) size_t resv = EFI_MIN_RESV_SIZE; uint64_t slice_size; diskaddr_t start_block; - char errbuf[1024]; + char errbuf[ERRBUFLEN]; /* prepare an error message just in case */ (void) snprintf(errbuf, sizeof (errbuf),