Skip to content

Commit

Permalink
libzfs: Define the defecto standard errbuf size
Browse files Browse the repository at this point in the history
Every errbuf array in libzfs is 1024 chars.

Define ERRBUFLEN in a shared header, and use it.

Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ryan Moeller <[email protected]>
Closes #13539
  • Loading branch information
Ryan Moeller authored and behlendorf committed Jun 9, 2022
1 parent 6f73d02 commit d68a2bf
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 52 deletions.
10 changes: 5 additions & 5 deletions lib/libzfs/libzfs_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
42 changes: 21 additions & 21 deletions lib/libzfs/libzfs_dataset.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -3897,15 +3897,15 @@ 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"));

ret = zfs_standard_error(hdl, ret, errbuf);
}
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));
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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'"),
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion lib/libzfs/libzfs_diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 3 additions & 1 deletion lib/libzfs/libzfs_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
extern "C" {
#endif

#define ERRBUFLEN 1024

struct libzfs_handle {
int libzfs_error;
int libzfs_fd;
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions lib/libzfs/libzfs_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -4998,15 +4998,15 @@ 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));
}

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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit d68a2bf

Please sign in to comment.