libzfs: don't NULL-check infallible allocations
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #13229
This commit is contained in:
parent
bc3f12bfac
commit
18dbf5c8c3
|
@ -447,12 +447,7 @@ changelist_add_mounted(zfs_handle_t *zhp, void *data)
|
|||
|
||||
ASSERT3U(clp->cl_prop, ==, ZFS_PROP_MOUNTPOINT);
|
||||
|
||||
if ((cn = zfs_alloc(zfs_get_handle(zhp),
|
||||
sizeof (prop_changenode_t))) == NULL) {
|
||||
zfs_close(zhp);
|
||||
return (ENOMEM);
|
||||
}
|
||||
|
||||
cn = zfs_alloc(zfs_get_handle(zhp), sizeof (prop_changenode_t));
|
||||
cn->cn_handle = zhp;
|
||||
cn->cn_mounted = zfs_is_mounted(zhp, NULL);
|
||||
ASSERT3U(cn->cn_mounted, ==, B_TRUE);
|
||||
|
@ -522,12 +517,7 @@ change_one(zfs_handle_t *zhp, void *data)
|
|||
(clp->cl_shareprop != ZPROP_INVAL &&
|
||||
(share_sourcetype == ZPROP_SRC_DEFAULT ||
|
||||
share_sourcetype == ZPROP_SRC_INHERITED))) {
|
||||
if ((cn = zfs_alloc(zfs_get_handle(zhp),
|
||||
sizeof (prop_changenode_t))) == NULL) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
cn = zfs_alloc(zfs_get_handle(zhp), sizeof (prop_changenode_t));
|
||||
cn->cn_handle = zhp;
|
||||
cn->cn_mounted = (clp->cl_gflags & CL_GATHER_MOUNT_ALWAYS) ||
|
||||
zfs_is_mounted(zhp, NULL);
|
||||
|
@ -630,8 +620,7 @@ changelist_gather(zfs_handle_t *zhp, zfs_prop_t prop, int gather_flags,
|
|||
char property[ZFS_MAXPROPLEN];
|
||||
boolean_t legacy = B_FALSE;
|
||||
|
||||
if ((clp = zfs_alloc(zhp->zfs_hdl, sizeof (prop_changelist_t))) == NULL)
|
||||
return (NULL);
|
||||
clp = zfs_alloc(zhp->zfs_hdl, sizeof (prop_changelist_t));
|
||||
|
||||
/*
|
||||
* For mountpoint-related tasks, we want to sort everything by
|
||||
|
@ -744,13 +733,7 @@ changelist_gather(zfs_handle_t *zhp, zfs_prop_t prop, int gather_flags,
|
|||
* Always add ourself to the list. We add ourselves to the end so that
|
||||
* we're the last to be unmounted.
|
||||
*/
|
||||
if ((cn = zfs_alloc(zhp->zfs_hdl,
|
||||
sizeof (prop_changenode_t))) == NULL) {
|
||||
zfs_close(temp);
|
||||
changelist_free(clp);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
cn = zfs_alloc(zhp->zfs_hdl, sizeof (prop_changenode_t));
|
||||
cn->cn_handle = temp;
|
||||
cn->cn_mounted = (clp->cl_gflags & CL_GATHER_MOUNT_ALWAYS) ||
|
||||
zfs_is_mounted(temp, NULL);
|
||||
|
|
|
@ -126,8 +126,7 @@ namespace_reload(libzfs_handle_t *hdl)
|
|||
return (no_memory(hdl));
|
||||
}
|
||||
|
||||
if (zcmd_alloc_dst_nvlist(hdl, &zc, 0) != 0)
|
||||
return (-1);
|
||||
zcmd_alloc_dst_nvlist(hdl, &zc, 0);
|
||||
|
||||
for (;;) {
|
||||
zc.zc_cookie = hdl->libzfs_ns_gen;
|
||||
|
@ -141,10 +140,7 @@ namespace_reload(libzfs_handle_t *hdl)
|
|||
return (0);
|
||||
|
||||
case ENOMEM:
|
||||
if (zcmd_expand_dst_nvlist(hdl, &zc) != 0) {
|
||||
zcmd_free_nvlists(&zc);
|
||||
return (-1);
|
||||
}
|
||||
zcmd_expand_dst_nvlist(hdl, &zc);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -181,18 +177,8 @@ namespace_reload(libzfs_handle_t *hdl)
|
|||
nvlist_t *child;
|
||||
uu_avl_index_t where;
|
||||
|
||||
if ((cn = zfs_alloc(hdl, sizeof (config_node_t))) == NULL) {
|
||||
nvlist_free(config);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if ((cn->cn_name = zfs_strdup(hdl,
|
||||
nvpair_name(elem))) == NULL) {
|
||||
free(cn);
|
||||
nvlist_free(config);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
cn = zfs_alloc(hdl, sizeof (config_node_t));
|
||||
cn->cn_name = zfs_strdup(hdl, nvpair_name(elem));
|
||||
child = fnvpair_value_nvlist(elem);
|
||||
if (nvlist_dup(child, &cn->cn_config, 0) != 0) {
|
||||
free(cn->cn_name);
|
||||
|
@ -273,8 +259,7 @@ zpool_refresh_stats(zpool_handle_t *zhp, boolean_t *missing)
|
|||
if (zhp->zpool_config_size == 0)
|
||||
zhp->zpool_config_size = 1 << 16;
|
||||
|
||||
if (zcmd_alloc_dst_nvlist(hdl, &zc, zhp->zpool_config_size) != 0)
|
||||
return (-1);
|
||||
zcmd_alloc_dst_nvlist(hdl, &zc, zhp->zpool_config_size);
|
||||
|
||||
for (;;) {
|
||||
if (zfs_ioctl(zhp->zpool_hdl, ZFS_IOC_POOL_STATS,
|
||||
|
@ -286,12 +271,9 @@ zpool_refresh_stats(zpool_handle_t *zhp, boolean_t *missing)
|
|||
break;
|
||||
}
|
||||
|
||||
if (errno == ENOMEM) {
|
||||
if (zcmd_expand_dst_nvlist(hdl, &zc) != 0) {
|
||||
zcmd_free_nvlists(&zc);
|
||||
return (-1);
|
||||
}
|
||||
} else {
|
||||
if (errno == ENOMEM)
|
||||
zcmd_expand_dst_nvlist(hdl, &zc);
|
||||
else {
|
||||
zcmd_free_nvlists(&zc);
|
||||
if (errno == ENOENT || errno == EINVAL)
|
||||
*missing = B_TRUE;
|
||||
|
|
|
@ -783,8 +783,6 @@ derive_key(libzfs_handle_t *hdl, zfs_keyformat_t format, uint64_t iters,
|
|||
*key_out = NULL;
|
||||
|
||||
key = zfs_alloc(hdl, WRAPPING_KEY_LEN);
|
||||
if (!key)
|
||||
return (ENOMEM);
|
||||
|
||||
switch (format) {
|
||||
case ZFS_KEYFORMAT_RAW:
|
||||
|
|
|
@ -331,13 +331,10 @@ get_stats_ioctl(zfs_handle_t *zhp, zfs_cmd_t *zc)
|
|||
(void) strlcpy(zc->zc_name, zhp->zfs_name, sizeof (zc->zc_name));
|
||||
|
||||
while (zfs_ioctl(hdl, ZFS_IOC_OBJSET_STATS, zc) != 0) {
|
||||
if (errno == ENOMEM) {
|
||||
if (zcmd_expand_dst_nvlist(hdl, zc) != 0) {
|
||||
return (-1);
|
||||
}
|
||||
} else {
|
||||
if (errno == ENOMEM)
|
||||
zcmd_expand_dst_nvlist(hdl, zc);
|
||||
else
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
@ -353,17 +350,14 @@ get_recvd_props_ioctl(zfs_handle_t *zhp)
|
|||
zfs_cmd_t zc = {"\0"};
|
||||
int err;
|
||||
|
||||
if (zcmd_alloc_dst_nvlist(hdl, &zc, 0) != 0)
|
||||
return (-1);
|
||||
zcmd_alloc_dst_nvlist(hdl, &zc, 0);
|
||||
|
||||
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
|
||||
|
||||
while (zfs_ioctl(hdl, ZFS_IOC_OBJSET_RECVD_PROPS, &zc) != 0) {
|
||||
if (errno == ENOMEM) {
|
||||
if (zcmd_expand_dst_nvlist(hdl, &zc) != 0) {
|
||||
return (-1);
|
||||
}
|
||||
} else {
|
||||
if (errno == ENOMEM)
|
||||
zcmd_expand_dst_nvlist(hdl, &zc);
|
||||
else {
|
||||
zcmd_free_nvlists(&zc);
|
||||
return (-1);
|
||||
}
|
||||
|
@ -415,8 +409,8 @@ get_stats(zfs_handle_t *zhp)
|
|||
int rc = 0;
|
||||
zfs_cmd_t zc = {"\0"};
|
||||
|
||||
if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0)
|
||||
return (-1);
|
||||
zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0);
|
||||
|
||||
if (get_stats_ioctl(zhp, &zc) != 0)
|
||||
rc = -1;
|
||||
else if (put_stats_zhdl(zhp, &zc) != 0)
|
||||
|
@ -489,10 +483,8 @@ make_dataset_handle(libzfs_handle_t *hdl, const char *path)
|
|||
|
||||
zhp->zfs_hdl = hdl;
|
||||
(void) strlcpy(zhp->zfs_name, path, sizeof (zhp->zfs_name));
|
||||
if (zcmd_alloc_dst_nvlist(hdl, &zc, 0) != 0) {
|
||||
free(zhp);
|
||||
return (NULL);
|
||||
}
|
||||
zcmd_alloc_dst_nvlist(hdl, &zc, 0);
|
||||
|
||||
if (get_stats_ioctl(zhp, &zc) == -1) {
|
||||
zcmd_free_nvlists(&zc);
|
||||
free(zhp);
|
||||
|
@ -1847,9 +1839,8 @@ zfs_prop_set_list(zfs_handle_t *zhp, nvlist_t *props)
|
|||
*/
|
||||
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
|
||||
|
||||
if ((ret = zcmd_write_src_nvlist(hdl, &zc, nvl)) != 0 ||
|
||||
(ret = zcmd_alloc_dst_nvlist(hdl, &zc, 0)) != 0)
|
||||
goto error;
|
||||
zcmd_write_src_nvlist(hdl, &zc, nvl);
|
||||
zcmd_alloc_dst_nvlist(hdl, &zc, 0);
|
||||
|
||||
ret = zfs_ioctl(hdl, ZFS_IOC_SET_PROP, &zc);
|
||||
|
||||
|
@ -1885,8 +1876,7 @@ zfs_prop_set_list(zfs_handle_t *zhp, nvlist_t *props)
|
|||
zfs_prop_to_name(ZFS_PROP_VOLSIZE),
|
||||
old_volsize) != 0)
|
||||
goto error;
|
||||
if (zcmd_write_src_nvlist(hdl, &zc, nvl) != 0)
|
||||
goto error;
|
||||
zcmd_write_src_nvlist(hdl, &zc, nvl);
|
||||
(void) zfs_ioctl(hdl, ZFS_IOC_SET_PROP, &zc);
|
||||
}
|
||||
} else {
|
||||
|
@ -2195,12 +2185,9 @@ get_numeric_property(zfs_handle_t *zhp, zfs_prop_t prop, zprop_source_t *src,
|
|||
libzfs_handle_t *hdl = zhp->zfs_hdl;
|
||||
struct mnttab entry;
|
||||
|
||||
if (libzfs_mnttab_find(hdl, zhp->zfs_name, &entry) == 0) {
|
||||
if (libzfs_mnttab_find(hdl, zhp->zfs_name, &entry) == 0)
|
||||
zhp->zfs_mntopts = zfs_strdup(hdl,
|
||||
entry.mnt_mntopts);
|
||||
if (zhp->zfs_mntopts == NULL)
|
||||
return (-1);
|
||||
}
|
||||
|
||||
zhp->zfs_mntcheck = B_TRUE;
|
||||
}
|
||||
|
@ -2267,8 +2254,8 @@ get_numeric_property(zfs_handle_t *zhp, zfs_prop_t prop, zprop_source_t *src,
|
|||
case ZFS_PROP_NORMALIZE:
|
||||
case ZFS_PROP_UTF8ONLY:
|
||||
case ZFS_PROP_CASE:
|
||||
if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0)
|
||||
return (-1);
|
||||
zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0);
|
||||
|
||||
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
|
||||
if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_OBJSET_ZPLPROPS, &zc)) {
|
||||
zcmd_free_nvlists(&zc);
|
||||
|
@ -4505,10 +4492,6 @@ zfs_rename(zfs_handle_t *zhp, const char *target, renameflags_t flags)
|
|||
}
|
||||
if (flags.recursive) {
|
||||
char *parentname = zfs_strdup(zhp->zfs_hdl, zhp->zfs_name);
|
||||
if (parentname == NULL) {
|
||||
ret = -1;
|
||||
goto error;
|
||||
}
|
||||
delim = strchr(parentname, '@');
|
||||
*delim = '\0';
|
||||
zfs_handle_t *zhrp = zfs_open(zhp->zfs_hdl, parentname,
|
||||
|
@ -4670,14 +4653,9 @@ zfs_expand_proplist(zfs_handle_t *zhp, zprop_list_t **plp, boolean_t received,
|
|||
}
|
||||
|
||||
if (*last == NULL) {
|
||||
if ((entry = zfs_alloc(hdl,
|
||||
sizeof (zprop_list_t))) == NULL ||
|
||||
((entry->pl_user_prop = zfs_strdup(hdl,
|
||||
nvpair_name(elem)))) == NULL) {
|
||||
free(entry);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
entry = zfs_alloc(hdl, sizeof (zprop_list_t));
|
||||
entry->pl_user_prop =
|
||||
zfs_strdup(hdl, nvpair_name(elem));
|
||||
entry->pl_prop = ZPROP_INVAL;
|
||||
entry->pl_width = strlen(nvpair_name(elem));
|
||||
entry->pl_all = B_TRUE;
|
||||
|
@ -4790,10 +4768,7 @@ zfs_smb_acl_mgmt(libzfs_handle_t *hdl, char *dataset, char *path,
|
|||
(void) no_memory(hdl);
|
||||
return (-1);
|
||||
}
|
||||
if (zcmd_write_src_nvlist(hdl, &zc, nvlist) != 0) {
|
||||
nvlist_free(nvlist);
|
||||
return (-1);
|
||||
}
|
||||
zcmd_write_src_nvlist(hdl, &zc, nvlist);
|
||||
break;
|
||||
case ZFS_SMB_ACL_PURGE:
|
||||
break;
|
||||
|
|
|
@ -602,11 +602,10 @@ get_snapshot_names(differ_info_t *di, const char *fromsnap,
|
|||
|
||||
di->isclone = B_TRUE;
|
||||
di->fromsnap = zfs_strdup(hdl, fromsnap);
|
||||
if (tsnlen) {
|
||||
if (tsnlen)
|
||||
di->tosnap = zfs_strdup(hdl, tosnap);
|
||||
} else {
|
||||
else
|
||||
return (make_temp_snapshot(di));
|
||||
}
|
||||
} else {
|
||||
int dslen = fdslen ? fdslen : tdslen;
|
||||
|
||||
|
|
|
@ -175,10 +175,10 @@ extern int zprop_expand_list(libzfs_handle_t *hdl, zprop_list_t **plp,
|
|||
|
||||
typedef struct prop_changelist prop_changelist_t;
|
||||
|
||||
extern int zcmd_alloc_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *, size_t);
|
||||
extern int zcmd_write_src_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t *);
|
||||
extern int zcmd_write_conf_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t *);
|
||||
extern int zcmd_expand_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *);
|
||||
extern void zcmd_alloc_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *, size_t);
|
||||
extern void zcmd_write_src_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t *);
|
||||
extern void zcmd_write_conf_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t *);
|
||||
extern void zcmd_expand_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *);
|
||||
extern int zcmd_read_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t **);
|
||||
extern void zcmd_free_nvlists(zfs_cmd_t *);
|
||||
|
||||
|
|
|
@ -73,23 +73,15 @@ refresh_config(libzfs_handle_t *hdl, nvlist_t *config)
|
|||
zfs_cmd_t zc = {"\0"};
|
||||
int err, dstbuf_size;
|
||||
|
||||
if (zcmd_write_conf_nvlist(hdl, &zc, config) != 0)
|
||||
return (NULL);
|
||||
zcmd_write_conf_nvlist(hdl, &zc, config);
|
||||
|
||||
dstbuf_size = MAX(CONFIG_BUF_MINSIZE, zc.zc_nvlist_conf_size * 32);
|
||||
|
||||
if (zcmd_alloc_dst_nvlist(hdl, &zc, dstbuf_size) != 0) {
|
||||
zcmd_free_nvlists(&zc);
|
||||
return (NULL);
|
||||
}
|
||||
zcmd_alloc_dst_nvlist(hdl, &zc, dstbuf_size);
|
||||
|
||||
while ((err = zfs_ioctl(hdl, ZFS_IOC_POOL_TRYIMPORT,
|
||||
&zc)) != 0 && errno == ENOMEM) {
|
||||
if (zcmd_expand_dst_nvlist(hdl, &zc) != 0) {
|
||||
zcmd_free_nvlists(&zc);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
&zc)) != 0 && errno == ENOMEM)
|
||||
zcmd_expand_dst_nvlist(hdl, &zc);
|
||||
|
||||
if (err) {
|
||||
zcmd_free_nvlists(&zc);
|
||||
|
@ -442,12 +434,7 @@ zpool_in_use(libzfs_handle_t *hdl, int fd, pool_state_t *state, char **namestr,
|
|||
|
||||
|
||||
if (ret) {
|
||||
if ((*namestr = zfs_strdup(hdl, name)) == NULL) {
|
||||
if (cb.cb_zhp)
|
||||
zpool_close(cb.cb_zhp);
|
||||
nvlist_free(config);
|
||||
return (-1);
|
||||
}
|
||||
*namestr = zfs_strdup(hdl, name);
|
||||
*state = (pool_state_t)stateval;
|
||||
}
|
||||
|
||||
|
|
|
@ -75,10 +75,7 @@ top:
|
|||
switch (errno) {
|
||||
case ENOMEM:
|
||||
/* expand nvlist memory and try again */
|
||||
if (zcmd_expand_dst_nvlist(zhp->zfs_hdl, zc) != 0) {
|
||||
zcmd_free_nvlists(zc);
|
||||
return (-1);
|
||||
}
|
||||
zcmd_expand_dst_nvlist(zhp->zfs_hdl, zc);
|
||||
zc->zc_cookie = orig_cookie;
|
||||
goto top;
|
||||
/*
|
||||
|
@ -113,8 +110,7 @@ zfs_iter_filesystems(zfs_handle_t *zhp, zfs_iter_f func, void *data)
|
|||
if (zhp->zfs_type != ZFS_TYPE_FILESYSTEM)
|
||||
return (0);
|
||||
|
||||
if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0)
|
||||
return (-1);
|
||||
zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0);
|
||||
|
||||
while ((ret = zfs_do_list_ioctl(zhp, ZFS_IOC_DATASET_LIST_NEXT,
|
||||
&zc)) == 0) {
|
||||
|
@ -154,8 +150,7 @@ zfs_iter_snapshots(zfs_handle_t *zhp, boolean_t simple, zfs_iter_f func,
|
|||
|
||||
zc.zc_simple = simple;
|
||||
|
||||
if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0)
|
||||
return (-1);
|
||||
zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0);
|
||||
|
||||
if (min_txg != 0) {
|
||||
range_nvl = fnvlist_alloc();
|
||||
|
@ -167,12 +162,8 @@ zfs_iter_snapshots(zfs_handle_t *zhp, boolean_t simple, zfs_iter_f func,
|
|||
fnvlist_add_uint64(range_nvl, SNAP_ITER_MAX_TXG, max_txg);
|
||||
}
|
||||
|
||||
if (range_nvl != NULL &&
|
||||
zcmd_write_src_nvlist(zhp->zfs_hdl, &zc, range_nvl) != 0) {
|
||||
zcmd_free_nvlists(&zc);
|
||||
fnvlist_free(range_nvl);
|
||||
return (-1);
|
||||
}
|
||||
if (range_nvl != NULL)
|
||||
zcmd_write_src_nvlist(zhp->zfs_hdl, &zc, range_nvl);
|
||||
|
||||
while ((ret = zfs_do_list_ioctl(zhp, ZFS_IOC_SNAPSHOT_LIST_NEXT,
|
||||
&zc)) == 0) {
|
||||
|
|
|
@ -1572,29 +1572,19 @@ zpool_disable_datasets(zpool_handle_t *zhp, boolean_t force)
|
|||
*/
|
||||
if (used == alloc) {
|
||||
if (alloc == 0) {
|
||||
|
||||
if ((sets = zfs_alloc(hdl,
|
||||
8 * sizeof (struct sets_s))) == NULL)
|
||||
goto out;
|
||||
|
||||
sets = zfs_alloc(hdl,
|
||||
8 * sizeof (struct sets_s));
|
||||
alloc = 8;
|
||||
} else {
|
||||
void *ptr;
|
||||
|
||||
if ((ptr = zfs_realloc(hdl, sets,
|
||||
sets = zfs_realloc(hdl, sets,
|
||||
alloc * sizeof (struct sets_s),
|
||||
alloc * 2 * sizeof (struct sets_s)))
|
||||
== NULL)
|
||||
goto out;
|
||||
sets = ptr;
|
||||
alloc * 2 * sizeof (struct sets_s));
|
||||
|
||||
alloc *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
if ((sets[used].mountpoint = zfs_strdup(hdl,
|
||||
entry.mnt_mountp)) == NULL)
|
||||
goto out;
|
||||
sets[used].mountpoint = zfs_strdup(hdl, entry.mnt_mountp);
|
||||
|
||||
/*
|
||||
* This is allowed to fail, in case there is some I/O error. It
|
||||
|
|
|
@ -79,16 +79,12 @@ zpool_get_all_props(zpool_handle_t *zhp)
|
|||
|
||||
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
|
||||
|
||||
if (zcmd_alloc_dst_nvlist(hdl, &zc, 0) != 0)
|
||||
return (-1);
|
||||
zcmd_alloc_dst_nvlist(hdl, &zc, 0);
|
||||
|
||||
while (zfs_ioctl(hdl, ZFS_IOC_POOL_GET_PROPS, &zc) != 0) {
|
||||
if (errno == ENOMEM) {
|
||||
if (zcmd_expand_dst_nvlist(hdl, &zc) != 0) {
|
||||
zcmd_free_nvlists(&zc);
|
||||
return (-1);
|
||||
}
|
||||
} else {
|
||||
if (errno == ENOMEM)
|
||||
zcmd_expand_dst_nvlist(hdl, &zc);
|
||||
else {
|
||||
zcmd_free_nvlists(&zc);
|
||||
return (-1);
|
||||
}
|
||||
|
@ -813,10 +809,7 @@ zpool_set_prop(zpool_handle_t *zhp, const char *propname, const char *propval)
|
|||
*/
|
||||
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
|
||||
|
||||
if (zcmd_write_src_nvlist(zhp->zpool_hdl, &zc, nvl) != 0) {
|
||||
nvlist_free(nvl);
|
||||
return (-1);
|
||||
}
|
||||
zcmd_write_src_nvlist(zhp->zpool_hdl, &zc, nvl);
|
||||
|
||||
ret = zfs_ioctl(zhp->zpool_hdl, ZFS_IOC_POOL_SET_PROPS, &zc);
|
||||
|
||||
|
@ -982,10 +975,8 @@ vdev_expand_proplist(zpool_handle_t *zhp, const char *vdevname,
|
|||
|
||||
strval = fnvlist_lookup_string(propval, ZPROP_VALUE);
|
||||
|
||||
if ((entry = zfs_alloc(zhp->zpool_hdl,
|
||||
sizeof (zprop_list_t))) == NULL)
|
||||
return (ENOMEM);
|
||||
|
||||
entry = zfs_alloc(zhp->zpool_hdl,
|
||||
sizeof (zprop_list_t));
|
||||
entry->pl_prop = prop;
|
||||
entry->pl_user_prop = zfs_strdup(zhp->zpool_hdl,
|
||||
propname);
|
||||
|
@ -1179,8 +1170,7 @@ zpool_open_canfail(libzfs_handle_t *hdl, const char *pool)
|
|||
return (NULL);
|
||||
}
|
||||
|
||||
if ((zhp = zfs_alloc(hdl, sizeof (zpool_handle_t))) == NULL)
|
||||
return (NULL);
|
||||
zhp = zfs_alloc(hdl, sizeof (zpool_handle_t));
|
||||
|
||||
zhp->zpool_hdl = hdl;
|
||||
(void) strlcpy(zhp->zpool_name, pool, sizeof (zhp->zpool_name));
|
||||
|
@ -1211,8 +1201,7 @@ zpool_open_silent(libzfs_handle_t *hdl, const char *pool, zpool_handle_t **ret)
|
|||
zpool_handle_t *zhp;
|
||||
boolean_t missing;
|
||||
|
||||
if ((zhp = zfs_alloc(hdl, sizeof (zpool_handle_t))) == NULL)
|
||||
return (-1);
|
||||
zhp = zfs_alloc(hdl, sizeof (zpool_handle_t));
|
||||
|
||||
zhp->zpool_hdl = hdl;
|
||||
(void) strlcpy(zhp->zpool_name, pool, sizeof (zhp->zpool_name));
|
||||
|
@ -1388,8 +1377,7 @@ zpool_create(libzfs_handle_t *hdl, const char *pool, nvlist_t *nvroot,
|
|||
if (!zpool_name_valid(hdl, B_FALSE, pool))
|
||||
return (zfs_error(hdl, EZFS_INVALIDNAME, msg));
|
||||
|
||||
if (zcmd_write_conf_nvlist(hdl, &zc, nvroot) != 0)
|
||||
return (-1);
|
||||
zcmd_write_conf_nvlist(hdl, &zc, nvroot);
|
||||
|
||||
if (props) {
|
||||
prop_flags_t flags = { .create = B_TRUE, .import = B_FALSE };
|
||||
|
@ -1450,8 +1438,8 @@ zpool_create(libzfs_handle_t *hdl, const char *pool, nvlist_t *nvroot,
|
|||
}
|
||||
}
|
||||
|
||||
if (zc_props && zcmd_write_src_nvlist(hdl, &zc, zc_props) != 0)
|
||||
goto create_failed;
|
||||
if (zc_props)
|
||||
zcmd_write_src_nvlist(hdl, &zc, zc_props);
|
||||
|
||||
(void) strlcpy(zc.zc_name, pool, sizeof (zc.zc_name));
|
||||
|
||||
|
@ -1665,8 +1653,7 @@ zpool_add(zpool_handle_t *zhp, nvlist_t *nvroot)
|
|||
return (zfs_error(hdl, EZFS_BADVERSION, msg));
|
||||
}
|
||||
|
||||
if (zcmd_write_conf_nvlist(hdl, &zc, nvroot) != 0)
|
||||
return (-1);
|
||||
zcmd_write_conf_nvlist(hdl, &zc, nvroot);
|
||||
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
|
||||
|
||||
if (zfs_ioctl(hdl, ZFS_IOC_VDEV_ADD, &zc) != 0) {
|
||||
|
@ -2048,10 +2035,7 @@ zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname,
|
|||
if ((props = zpool_valid_proplist(hdl, origname,
|
||||
props, version, flags, errbuf)) == NULL)
|
||||
return (-1);
|
||||
if (zcmd_write_src_nvlist(hdl, &zc, props) != 0) {
|
||||
nvlist_free(props);
|
||||
return (-1);
|
||||
}
|
||||
zcmd_write_src_nvlist(hdl, &zc, props);
|
||||
nvlist_free(props);
|
||||
}
|
||||
|
||||
|
@ -2059,23 +2043,13 @@ zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname,
|
|||
|
||||
zc.zc_guid = fnvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID);
|
||||
|
||||
if (zcmd_write_conf_nvlist(hdl, &zc, config) != 0) {
|
||||
zcmd_free_nvlists(&zc);
|
||||
return (-1);
|
||||
}
|
||||
if (zcmd_alloc_dst_nvlist(hdl, &zc, zc.zc_nvlist_conf_size * 2) != 0) {
|
||||
zcmd_free_nvlists(&zc);
|
||||
return (-1);
|
||||
}
|
||||
zcmd_write_conf_nvlist(hdl, &zc, config);
|
||||
zcmd_alloc_dst_nvlist(hdl, &zc, zc.zc_nvlist_conf_size * 2);
|
||||
|
||||
zc.zc_cookie = flags;
|
||||
while ((ret = zfs_ioctl(hdl, ZFS_IOC_POOL_IMPORT, &zc)) != 0 &&
|
||||
errno == ENOMEM) {
|
||||
if (zcmd_expand_dst_nvlist(hdl, &zc) != 0) {
|
||||
zcmd_free_nvlists(&zc);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
errno == ENOMEM)
|
||||
zcmd_expand_dst_nvlist(hdl, &zc);
|
||||
if (ret != 0)
|
||||
error = errno;
|
||||
|
||||
|
@ -3408,8 +3382,7 @@ zpool_vdev_attach(zpool_handle_t *zhp, const char *old_disk,
|
|||
|
||||
free(newname);
|
||||
|
||||
if (zcmd_write_conf_nvlist(hdl, &zc, nvroot) != 0)
|
||||
return (-1);
|
||||
zcmd_write_conf_nvlist(hdl, &zc, nvroot);
|
||||
|
||||
ret = zfs_ioctl(hdl, ZFS_IOC_VDEV_ATTACH, &zc);
|
||||
|
||||
|
@ -3815,10 +3788,9 @@ zpool_vdev_split(zpool_handle_t *zhp, char *newname, nvlist_t **newroot,
|
|||
zc.zc_cookie = ZPOOL_EXPORT_AFTER_SPLIT;
|
||||
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
|
||||
(void) strlcpy(zc.zc_string, newname, sizeof (zc.zc_string));
|
||||
if (zcmd_write_conf_nvlist(hdl, &zc, newconfig) != 0)
|
||||
goto out;
|
||||
if (zc_props != NULL && zcmd_write_src_nvlist(hdl, &zc, zc_props) != 0)
|
||||
goto out;
|
||||
zcmd_write_conf_nvlist(hdl, &zc, newconfig);
|
||||
if (zc_props != NULL)
|
||||
zcmd_write_src_nvlist(hdl, &zc, zc_props);
|
||||
|
||||
if (zfs_ioctl(hdl, ZFS_IOC_VDEV_SPLIT, &zc) != 0) {
|
||||
retval = zpool_standard_error(hdl, errno, msg);
|
||||
|
@ -4020,19 +3992,12 @@ zpool_clear(zpool_handle_t *zhp, const char *path, nvlist_t *rewindnvl)
|
|||
zpool_get_load_policy(rewindnvl, &policy);
|
||||
zc.zc_cookie = policy.zlp_rewind;
|
||||
|
||||
if (zcmd_alloc_dst_nvlist(hdl, &zc, zhp->zpool_config_size * 2) != 0)
|
||||
return (-1);
|
||||
|
||||
if (zcmd_write_src_nvlist(hdl, &zc, rewindnvl) != 0)
|
||||
return (-1);
|
||||
zcmd_alloc_dst_nvlist(hdl, &zc, zhp->zpool_config_size * 2);
|
||||
zcmd_write_src_nvlist(hdl, &zc, rewindnvl);
|
||||
|
||||
while ((error = zfs_ioctl(hdl, ZFS_IOC_CLEAR, &zc)) != 0 &&
|
||||
errno == ENOMEM) {
|
||||
if (zcmd_expand_dst_nvlist(hdl, &zc) != 0) {
|
||||
zcmd_free_nvlists(&zc);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
errno == ENOMEM)
|
||||
zcmd_expand_dst_nvlist(hdl, &zc);
|
||||
|
||||
if (!error || ((policy.zlp_rewind & ZPOOL_TRY_REWIND) &&
|
||||
errno != EPERM && errno != EACCES)) {
|
||||
|
@ -4408,13 +4373,11 @@ zpool_log_history(libzfs_handle_t *hdl, const char *message)
|
|||
{
|
||||
zfs_cmd_t zc = {"\0"};
|
||||
nvlist_t *args;
|
||||
int err;
|
||||
|
||||
args = fnvlist_alloc();
|
||||
fnvlist_add_string(args, "message", message);
|
||||
err = zcmd_write_src_nvlist(hdl, &zc, args);
|
||||
if (err == 0)
|
||||
err = zfs_ioctl(hdl, ZFS_IOC_LOG_HISTORY, &zc);
|
||||
zcmd_write_src_nvlist(hdl, &zc, args);
|
||||
int err = zfs_ioctl(hdl, ZFS_IOC_LOG_HISTORY, &zc);
|
||||
nvlist_free(args);
|
||||
zcmd_free_nvlists(&zc);
|
||||
return (err);
|
||||
|
@ -4556,8 +4519,7 @@ zpool_events_next(libzfs_handle_t *hdl, nvlist_t **nvp,
|
|||
if (flags & ZEVENT_NONBLOCK)
|
||||
zc.zc_guid = ZEVENT_NONBLOCK;
|
||||
|
||||
if (zcmd_alloc_dst_nvlist(hdl, &zc, ZEVENT_SIZE) != 0)
|
||||
return (-1);
|
||||
zcmd_alloc_dst_nvlist(hdl, &zc, ZEVENT_SIZE);
|
||||
|
||||
retry:
|
||||
if (zfs_ioctl(hdl, ZFS_IOC_EVENTS_NEXT, &zc) != 0) {
|
||||
|
@ -4574,13 +4536,8 @@ retry:
|
|||
|
||||
goto out;
|
||||
case ENOMEM:
|
||||
if (zcmd_expand_dst_nvlist(hdl, &zc) != 0) {
|
||||
error = zfs_error_fmt(hdl, EZFS_NOMEM,
|
||||
dgettext(TEXT_DOMAIN, "cannot get event"));
|
||||
goto out;
|
||||
} else {
|
||||
goto retry;
|
||||
}
|
||||
zcmd_expand_dst_nvlist(hdl, &zc);
|
||||
goto retry;
|
||||
default:
|
||||
error = zpool_standard_error_fmt(hdl, errno,
|
||||
dgettext(TEXT_DOMAIN, "cannot get event"));
|
||||
|
|
|
@ -2778,8 +2778,6 @@ recv_read_nvlist(libzfs_handle_t *hdl, int fd, int len, nvlist_t **nvp,
|
|||
int err;
|
||||
|
||||
buf = zfs_alloc(hdl, len);
|
||||
if (buf == NULL)
|
||||
return (ENOMEM);
|
||||
|
||||
if (len > hdl->libzfs_max_nvlist) {
|
||||
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "nvlist too large"));
|
||||
|
@ -3521,12 +3519,10 @@ again:
|
|||
zc.zc_cookie = B_TRUE; /* received */
|
||||
(void) snprintf(zc.zc_name, sizeof (zc.zc_name),
|
||||
"%s@%s", fsname, nvpair_name(snapelem));
|
||||
if (zcmd_write_src_nvlist(hdl, &zc,
|
||||
props) == 0) {
|
||||
(void) zfs_ioctl(hdl,
|
||||
ZFS_IOC_SET_PROP, &zc);
|
||||
zcmd_free_nvlists(&zc);
|
||||
}
|
||||
zcmd_write_src_nvlist(hdl, &zc, props);
|
||||
(void) zfs_ioctl(hdl,
|
||||
ZFS_IOC_SET_PROP, &zc);
|
||||
zcmd_free_nvlists(&zc);
|
||||
}
|
||||
|
||||
/* check for different snapname */
|
||||
|
@ -4879,10 +4875,9 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap,
|
|||
|
||||
(void) strcpy(zc.zc_name, destsnap);
|
||||
zc.zc_cookie = B_TRUE; /* received */
|
||||
if (zcmd_write_src_nvlist(hdl, &zc, snapprops_nvlist) == 0) {
|
||||
(void) zfs_ioctl(hdl, ZFS_IOC_SET_PROP, &zc);
|
||||
zcmd_free_nvlists(&zc);
|
||||
}
|
||||
zcmd_write_src_nvlist(hdl, &zc, snapprops_nvlist);
|
||||
(void) zfs_ioctl(hdl, ZFS_IOC_SET_PROP, &zc);
|
||||
zcmd_free_nvlists(&zc);
|
||||
}
|
||||
if (err == 0 && snapholds_nvlist) {
|
||||
nvpair_t *pair;
|
||||
|
|
|
@ -1149,7 +1149,7 @@ zfs_path_to_zhandle(libzfs_handle_t *hdl, const char *path, zfs_type_t argtype)
|
|||
* Initialize the zc_nvlist_dst member to prepare for receiving an nvlist from
|
||||
* an ioctl().
|
||||
*/
|
||||
int
|
||||
void
|
||||
zcmd_alloc_dst_nvlist(libzfs_handle_t *hdl, zfs_cmd_t *zc, size_t len)
|
||||
{
|
||||
if (len == 0)
|
||||
|
@ -1157,10 +1157,6 @@ zcmd_alloc_dst_nvlist(libzfs_handle_t *hdl, zfs_cmd_t *zc, size_t len)
|
|||
zc->zc_nvlist_dst_size = len;
|
||||
zc->zc_nvlist_dst =
|
||||
(uint64_t)(uintptr_t)zfs_alloc(hdl, zc->zc_nvlist_dst_size);
|
||||
if (zc->zc_nvlist_dst == 0)
|
||||
return (-1);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1168,16 +1164,12 @@ zcmd_alloc_dst_nvlist(libzfs_handle_t *hdl, zfs_cmd_t *zc, size_t len)
|
|||
* expand the nvlist to the size specified in 'zc_nvlist_dst_size', which was
|
||||
* filled in by the kernel to indicate the actual required size.
|
||||
*/
|
||||
int
|
||||
void
|
||||
zcmd_expand_dst_nvlist(libzfs_handle_t *hdl, zfs_cmd_t *zc)
|
||||
{
|
||||
free((void *)(uintptr_t)zc->zc_nvlist_dst);
|
||||
zc->zc_nvlist_dst =
|
||||
(uint64_t)(uintptr_t)zfs_alloc(hdl, zc->zc_nvlist_dst_size);
|
||||
if (zc->zc_nvlist_dst == 0)
|
||||
return (-1);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1194,36 +1186,33 @@ zcmd_free_nvlists(zfs_cmd_t *zc)
|
|||
zc->zc_nvlist_dst = 0;
|
||||
}
|
||||
|
||||
static int
|
||||
static void
|
||||
zcmd_write_nvlist_com(libzfs_handle_t *hdl, uint64_t *outnv, uint64_t *outlen,
|
||||
nvlist_t *nvl)
|
||||
{
|
||||
char *packed;
|
||||
|
||||
size_t len = fnvlist_size(nvl);
|
||||
if ((packed = zfs_alloc(hdl, len)) == NULL)
|
||||
return (-1);
|
||||
packed = zfs_alloc(hdl, len);
|
||||
|
||||
verify(nvlist_pack(nvl, &packed, &len, NV_ENCODE_NATIVE, 0) == 0);
|
||||
|
||||
*outnv = (uint64_t)(uintptr_t)packed;
|
||||
*outlen = len;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
void
|
||||
zcmd_write_conf_nvlist(libzfs_handle_t *hdl, zfs_cmd_t *zc, nvlist_t *nvl)
|
||||
{
|
||||
return (zcmd_write_nvlist_com(hdl, &zc->zc_nvlist_conf,
|
||||
&zc->zc_nvlist_conf_size, nvl));
|
||||
zcmd_write_nvlist_com(hdl, &zc->zc_nvlist_conf,
|
||||
&zc->zc_nvlist_conf_size, nvl);
|
||||
}
|
||||
|
||||
int
|
||||
void
|
||||
zcmd_write_src_nvlist(libzfs_handle_t *hdl, zfs_cmd_t *zc, nvlist_t *nvl)
|
||||
{
|
||||
return (zcmd_write_nvlist_com(hdl, &zc->zc_nvlist_src,
|
||||
&zc->zc_nvlist_src_size, nvl));
|
||||
zcmd_write_nvlist_com(hdl, &zc->zc_nvlist_src,
|
||||
&zc->zc_nvlist_src_size, nvl);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1863,8 +1852,7 @@ zprop_expand_list_cb(int prop, void *cb)
|
|||
zprop_list_t *entry;
|
||||
expand_data_t *edp = cb;
|
||||
|
||||
if ((entry = zfs_alloc(edp->hdl, sizeof (zprop_list_t))) == NULL)
|
||||
return (ZPROP_INVAL);
|
||||
entry = zfs_alloc(edp->hdl, sizeof (zprop_list_t));
|
||||
|
||||
entry->pl_prop = prop;
|
||||
entry->pl_width = zprop_width(prop, &entry->pl_fixed, edp->type);
|
||||
|
|
|
@ -338,15 +338,13 @@ zpool_nextboot(libzfs_handle_t *hdl, uint64_t pool_guid, uint64_t dev_guid,
|
|||
{
|
||||
zfs_cmd_t zc = {"\0"};
|
||||
nvlist_t *args;
|
||||
int error;
|
||||
|
||||
args = fnvlist_alloc();
|
||||
fnvlist_add_uint64(args, ZPOOL_CONFIG_POOL_GUID, pool_guid);
|
||||
fnvlist_add_uint64(args, ZPOOL_CONFIG_GUID, dev_guid);
|
||||
fnvlist_add_string(args, "command", command);
|
||||
error = zcmd_write_src_nvlist(hdl, &zc, args);
|
||||
if (error == 0)
|
||||
error = zfs_ioctl(hdl, ZFS_IOC_NEXTBOOT, &zc);
|
||||
zcmd_write_src_nvlist(hdl, &zc, args);
|
||||
int error = zfs_ioctl(hdl, ZFS_IOC_NEXTBOOT, &zc);
|
||||
zcmd_free_nvlists(&zc);
|
||||
nvlist_free(args);
|
||||
return (error);
|
||||
|
|
Loading…
Reference in New Issue