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 openzfs#13539
  • Loading branch information
Ryan Moeller authored and andrewc12 committed Sep 23, 2022
1 parent 75c71f7 commit ac8c8f2
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 @@ -1013,7 +1013,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 @@ -1184,7 +1184,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 @@ -1286,7 +1286,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 @@ -1454,7 +1454,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 @@ -1590,7 +1590,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 @@ -677,7 +677,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 @@ -1719,7 +1719,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 @@ -1753,7 +1753,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 @@ -1933,7 +1933,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 @@ -3410,7 +3410,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 @@ -3588,7 +3588,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 @@ -3632,7 +3632,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 @@ -3905,15 +3905,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 @@ -3942,7 +3942,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 @@ -4026,7 +4026,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 @@ -4108,7 +4108,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 @@ -4193,7 +4193,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 @@ -4336,7 +4336,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 @@ -4395,7 +4395,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 @@ -4910,7 +4910,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 @@ -4934,7 +4934,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 @@ -5036,7 +5036,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 @@ -5116,7 +5116,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 @@ -5180,7 +5180,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 @@ -5232,7 +5232,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 @@ -775,7 +775,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 @@ -2008,7 +2008,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 @@ -4997,15 +4997,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 @@ -5215,7 +5215,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 @@ -5253,7 +5253,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 @@ -5294,7 +5294,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 ac8c8f2

Please sign in to comment.