当前位置: 首页>>代码示例>>C++>>正文


C++ zfs_alloc函数代码示例

本文整理汇总了C++中zfs_alloc函数的典型用法代码示例。如果您正苦于以下问题:C++ zfs_alloc函数的具体用法?C++ zfs_alloc怎么用?C++ zfs_alloc使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了zfs_alloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: zfs_sort_snaps

static int
zfs_sort_snaps(zfs_handle_t *zhp, void *data)
{
	avl_tree_t *avl = data;
	zfs_node_t *node;
	zfs_node_t search;

	search.zn_handle = zhp;
	node = avl_find(avl, &search, NULL);
	if (node) {
		/*
		 * If this snapshot was renamed while we were creating the
		 * AVL tree, it's possible that we already inserted it under
		 * its old name. Remove the old handle before adding the new
		 * one.
		 */
		zfs_close(node->zn_handle);
		avl_remove(avl, node);
		free(node);
	}

	node = zfs_alloc(zhp->zfs_hdl, sizeof (zfs_node_t));
	node->zn_handle = zhp;
	avl_add(avl, node);

	return (0);
}
开发者ID:Acidburn0zzz,项目名称:zfs,代码行数:27,代码来源:libzfs_iter.c

示例2: zpool_open_silent

/*
 * Like the above, but silent on error.  Used when iterating over pools (because
 * the configuration cache may be out of date).
 */
int
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->zpool_hdl = hdl;
	(void) strlcpy(zhp->zpool_name, pool, sizeof (zhp->zpool_name));

	if (zpool_refresh_stats(zhp, &missing) != 0) {
		zpool_close(zhp);
		return (-1);
	}

	if (missing) {
		zpool_close(zhp);
		*ret = NULL;
		return (0);
	}

	*ret = zhp;
	return (0);
}
开发者ID:andreiw,项目名称:polaris,代码行数:30,代码来源:libzfs_pool.c

示例3: zpool_enable_datasets

int
zpool_enable_datasets(zpool_handle_t *zhp, const char *mntopts, int flags)
{
    get_all_cb_t cb = { 0 };
    libzfs_handle_t *hdl = zhp->zpool_hdl;
    zfs_handle_t *zfsp;
    int i, ret = -1;
    int *good;

    /*
     * Gather all non-snap datasets within the pool.
     */
    if ((zfsp = zfs_open(hdl, zhp->zpool_name, ZFS_TYPE_DATASET)) == NULL)
        goto out;

    libzfs_add_handle(&cb, zfsp);
    if (zfs_iter_filesystems(zfsp, mount_cb, &cb) != 0)
        goto out;
    /*
     * Sort the datasets by mountpoint.
     */
    qsort(cb.cb_handles, cb.cb_used, sizeof (void *),
          libzfs_dataset_cmp);

    /*
     * And mount all the datasets, keeping track of which ones
     * succeeded or failed.
     */
    if ((good = zfs_alloc(zhp->zpool_hdl,
                          cb.cb_used * sizeof (int))) == NULL)
        goto out;

    ret = 0;
    for (i = 0; i < cb.cb_used; i++) {
        if (zfs_mount(cb.cb_handles[i], mntopts, flags) != 0)
            ret = -1;
        else
            good[i] = 1;
    }

    /*
     * Then share all the ones that need to be shared. This needs
     * to be a separate pass in order to avoid excessive reloading
     * of the configuration. Good should never be NULL since
     * zfs_alloc is supposed to exit if memory isn't available.
     */
    for (i = 0; i < cb.cb_used; i++) {
        if (good[i] && zfs_share(cb.cb_handles[i]) != 0)
            ret = -1;
    }

    free(good);

out:
    for (i = 0; i < cb.cb_used; i++)
        zfs_close(cb.cb_handles[i]);
    free(cb.cb_handles);

    return (ret);
}
开发者ID:kelsieflynn,项目名称:SamFlynnOS,代码行数:60,代码来源:libzfs_mount.c

示例4: zfs_graph_create

/*
 * Construct a new graph object.  We allow the size to be specified as a
 * parameter so in the future we can size the hash according to the number of
 * datasets in the pool.
 */
static zfs_graph_t *
zfs_graph_create(libzfs_handle_t *hdl, size_t size)
{
	zfs_graph_t *zgp = zfs_alloc(hdl, sizeof (zfs_graph_t));

	if (zgp == NULL)
		return (NULL);

	zgp->zg_size = size;
	if ((zgp->zg_hash = zfs_alloc(hdl,
	    size * sizeof (zfs_vertex_t *))) == NULL) {
		free(zgp);
		return (NULL);
	}

	return (zgp);
}
开发者ID:BjoKaSH,项目名称:mac-zfs,代码行数:22,代码来源:libzfs_graph.c

示例5: zfs_graph_create

/*
 * Construct a new graph object.  We allow the size to be specified as a
 * parameter so in the future we can size the hash according to the number of
 * datasets in the pool.
 */
static zfs_graph_t *
zfs_graph_create(libzfs_handle_t *hdl, const char *dataset, size_t size)
{
	zfs_graph_t *zgp = zfs_alloc(hdl, sizeof (zfs_graph_t));

	if (zgp == NULL)
		return (NULL);

	zgp->zg_size = size;
	if ((zgp->zg_hash = zfs_alloc(hdl,
	    size * sizeof (zfs_vertex_t *))) == NULL) {
		free(zgp);
		return (NULL);
	}

	zgp->zg_root = dataset;
	zgp->zg_clone_count = 0;

	return (zgp);
}
开发者ID:YaroslavLitvinov,项目名称:zfs-port,代码行数:25,代码来源:libzfs_graph.c

示例6: zfs_edge_create

/*
 * Allocate a new edge pointing to the target vertex.
 */
static zfs_edge_t *
zfs_edge_create(libzfs_handle_t *hdl, zfs_vertex_t *dest)
{
	zfs_edge_t *zep = zfs_alloc(hdl, sizeof (zfs_edge_t));

	if (zep == NULL)
		return (NULL);

	zep->ze_dest = dest;

	return (zep);
}
开发者ID:BjoKaSH,项目名称:mac-zfs,代码行数:15,代码来源:libzfs_graph.c

示例7: derive_key

static int
derive_key(libzfs_handle_t *hdl, zfs_keyformat_t format, uint64_t iters,
    uint8_t *key_material, size_t key_material_len, uint64_t salt,
    uint8_t **key_out)
{
	int ret;
	uint8_t *key;

	*key_out = NULL;

	key = zfs_alloc(hdl, WRAPPING_KEY_LEN);
	if (!key)
		return (ENOMEM);

	switch (format) {
	case ZFS_KEYFORMAT_RAW:
		bcopy(key_material, key, WRAPPING_KEY_LEN);
		break;
	case ZFS_KEYFORMAT_HEX:
		ret = hex_key_to_raw((char *)key_material,
		    WRAPPING_KEY_LEN * 2, key);
		if (ret != 0) {
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
			    "Invalid hex key provided."));
			goto error;
		}
		break;
	case ZFS_KEYFORMAT_PASSPHRASE:
		salt = LE_64(salt);
		ret = pbkdf2(key_material, strlen((char *)key_material),
		    ((uint8_t *)&salt), sizeof (uint64_t), iters,
		    key, WRAPPING_KEY_LEN);
		if (ret != 0) {
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
			    "Failed to generate key from passphrase."));
			goto error;
		}
		break;
	default:
		ret = EINVAL;
		goto error;
	}

	*key_out = key;
	return (0);

error:
	free(key);

	*key_out = NULL;
	return (ret);
}
开发者ID:cbreak-black,项目名称:zfs,代码行数:52,代码来源:libzfs_crypto.c

示例8: construct_graph

/*
 * Construct a complete graph of all necessary vertices.  First, we iterate over
 * only our object's children.  If we don't find any cloned snapshots, then we
 * simple return that.  Otherwise, we have to start at the pool root and iterate
 * over all datasets.
 */
static zfs_graph_t *
construct_graph(libzfs_handle_t *hdl, const char *dataset)
{
	zfs_graph_t *zgp = zfs_graph_create(hdl, ZFS_GRAPH_SIZE);
	zfs_cmd_t zc = { 0 };
	int ret = 0;

	if (zgp == NULL)
		return (zgp);

	/*
	 * We need to explicitly check whether this dataset has clones or not,
	 * since iterate_children() only checks the children.
	 */
	(void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name));
	(void) ioctl(hdl->libzfs_fd, ZFS_IOC_OBJSET_STATS, &zc);

	if (zc.zc_objset_stats.dds_num_clones != 0 ||
	    (ret = iterate_children(hdl, zgp, dataset)) != 0) {
		/*
		 * Determine pool name and try again.
		 */
		char *pool, *slash;

		if ((slash = strchr(dataset, '/')) != NULL ||
		    (slash = strchr(dataset, '@')) != NULL) {
			pool = zfs_alloc(hdl, slash - dataset + 1);
			if (pool == NULL) {
				zfs_graph_destroy(zgp);
				return (NULL);
			}
			(void) strncpy(pool, dataset, slash - dataset);
			pool[slash - dataset] = '\0';

			if (iterate_children(hdl, zgp, pool) == -1 ||
			    zfs_graph_add(hdl, zgp, pool, NULL, 0) != 0) {
				free(pool);
				zfs_graph_destroy(zgp);
				return (NULL);
			}

			free(pool);
		}
	}

	if (ret == -1 || zfs_graph_add(hdl, zgp, dataset, NULL, 0) != 0) {
		zfs_graph_destroy(zgp);
		return (NULL);
	}

	return (zgp);
}
开发者ID:BjoKaSH,项目名称:mac-zfs,代码行数:58,代码来源:libzfs_graph.c

示例9: zfs_vertex_create

/*
 * Allocate a new vertex with the given name.
 */
static zfs_vertex_t *
zfs_vertex_create(libzfs_handle_t *hdl, const char *dataset)
{
	zfs_vertex_t *zvp = zfs_alloc(hdl, sizeof (zfs_vertex_t));

	if (zvp == NULL)
		return (NULL);

	assert(strlen(dataset) < ZFS_MAXNAMELEN);

	(void) strlcpy(zvp->zv_dataset, dataset, sizeof (zvp->zv_dataset));

	if ((zvp->zv_edges = zfs_alloc(hdl,
	    MIN_EDGECOUNT * sizeof (void *))) == NULL) {
		free(zvp);
		return (NULL);
	}

	zvp->zv_edgealloc = MIN_EDGECOUNT;

	return (zvp);
}
开发者ID:BjoKaSH,项目名称:mac-zfs,代码行数:25,代码来源:libzfs_graph.c

示例10: topo_sort

/*
 * Given a graph, do a recursive topological sort into the given array.  This is
 * really just a depth first search, so that the deepest nodes appear first.
 * hijack the 'zv_visited' marker to avoid visiting the same vertex twice.
 */
static int
topo_sort(libzfs_handle_t *hdl, boolean_t allowrecursion, char **result,
    size_t *idx, zfs_vertex_t *zgv)
{
	int i;

	if (zgv->zv_visited == VISIT_SORT_PRE && !allowrecursion) {
		/*
		 * If we've already seen this vertex as part of our depth-first
		 * search, then we have a cyclic dependency, and we must return
		 * an error.
		 */
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
		    "recursive dependency at '%s'"),
		    zgv->zv_dataset);
		return (zfs_error(hdl, EZFS_RECURSIVE,
		    dgettext(TEXT_DOMAIN,
		    "cannot determine dependent datasets")));
	} else if (zgv->zv_visited >= VISIT_SORT_PRE) {
		/*
		 * If we've already processed this as part of the topological
		 * sort, then don't bother doing so again.
		 */
		return (0);
	}

	zgv->zv_visited = VISIT_SORT_PRE;

	/* avoid doing a search if we don't have to */
	zfs_vertex_sort_edges(zgv);
	for (i = 0; i < zgv->zv_edgecount; i++) {
		if (topo_sort(hdl, allowrecursion, result, idx,
		    zgv->zv_edges[i]->ze_dest) != 0)
			return (-1);
	}

	/* we may have visited this in the course of the above */
	if (zgv->zv_visited == VISIT_SORT_POST)
		return (0);

	if ((result[*idx] = zfs_alloc(hdl,
	    strlen(zgv->zv_dataset) + 1)) == NULL)
		return (-1);

	(void) strcpy(result[*idx], zgv->zv_dataset);
	*idx += 1;
	zgv->zv_visited = VISIT_SORT_POST;
	return (0);
}
开发者ID:BjoKaSH,项目名称:mac-zfs,代码行数:54,代码来源:libzfs_graph.c

示例11: get_keydata_curl

/*ARGSUSED*/
static size_t
get_keydata_curl(void *ptr, size_t size, size_t nmemb, void *arg)
{
	struct cb_arg_curl *cb = arg;
	size_t datalen = size * nmemb;

	if (ptr == NULL || datalen == 0)
		return (0);

	cb->cb_keydatalen = datalen;
	cb->cb_keydata = zfs_alloc(cb->cb_hdl, datalen);
	bcopy(ptr, cb->cb_keydata, datalen);

	return (datalen);
}
开发者ID:corbosman,项目名称:zfs-crypto,代码行数:16,代码来源:libzfs_crypto.c

示例12: zpool_handle

/*
 * Returns a handle to the pool that contains the provided dataset.
 * If a handle to that pool already exists then that handle is returned.
 * Otherwise, a new handle is created and added to the list of handles.
 */
static zpool_handle_t *
zpool_handle(zfs_handle_t *zhp)
{
	char *pool_name;
	int len;
	zpool_handle_t *zph;

	len = strcspn(zhp->zfs_name, "/@") + 1;
	pool_name = zfs_alloc(zhp->zfs_hdl, len);
	(void) strlcpy(pool_name, zhp->zfs_name, len);

	zph = zpool_find_handle(zhp, pool_name, len);
	if (zph == NULL)
		zph = zpool_add_handle(zhp, pool_name);

	free(pool_name);
	return (zph);
}
开发者ID:Anuradha-Talur,项目名称:nfs-ganesha,代码行数:23,代码来源:libzfs.c

示例13: get_dependents

/*
 * The only public interface for this file.  Do the dirty work of constructing a
 * child list for the given object.  Construct the graph, do the toplogical
 * sort, and then return the array of strings to the caller.
 *
 * The 'allowrecursion' parameter controls behavior when cycles are found.  If
 * it is set, the the cycle is ignored and the results returned as if the cycle
 * did not exist.  If it is not set, then the routine will generate an error if
 * a cycle is found.
 */
int
get_dependents(libzfs_handle_t *hdl, boolean_t allowrecursion,
    const char *dataset, char ***result, size_t *count)
{
	zfs_graph_t *zgp;
	zfs_vertex_t *zvp;

	if ((zgp = construct_graph(hdl, dataset)) == NULL)
		return (-1);

	if ((*result = zfs_alloc(hdl,
	    zgp->zg_nvertex * sizeof (char *))) == NULL) {
		zfs_graph_destroy(zgp);
		return (-1);
	}

	if ((zvp = zfs_graph_lookup(hdl, zgp, dataset, 0)) == NULL) {
		free(*result);
		zfs_graph_destroy(zgp);
		return (-1);
	}

	*count = 0;
	if (topo_sort(hdl, allowrecursion, *result, count, zvp) != 0) {
		free(*result);
		zfs_graph_destroy(zgp);
		return (-1);
	}

	/*
	 * Get rid of the last entry, which is our starting vertex and not
	 * strictly a dependent.
	 */
	assert(*count > 0);
	free((*result)[*count - 1]);
	(*count)--;

	zfs_graph_destroy(zgp);

	return (0);
}
开发者ID:BjoKaSH,项目名称:mac-zfs,代码行数:51,代码来源:libzfs_graph.c

示例14: zcmd_write_src_nvlist

int
zcmd_write_src_nvlist(libzfs_handle_t *hdl, zfs_cmd_t *zc, nvlist_t *nvl,
    size_t *size)
{
	char *packed;
	size_t len;

	verify(nvlist_size(nvl, &len, NV_ENCODE_NATIVE) == 0);

	if ((packed = zfs_alloc(hdl, len)) == NULL)
		return (-1);

	verify(nvlist_pack(nvl, &packed, &len, NV_ENCODE_NATIVE, 0) == 0);

	zc->zc_nvlist_src = (uint64_t)(uintptr_t)packed;
	zc->zc_nvlist_src_size = len;

	if (size)
		*size = len;
	return (0);
}
开发者ID:roddi,项目名称:mac-zfs,代码行数:21,代码来源:libzfs_util.c

示例15: zpool_open_canfail

/*
 * Open a handle to the given pool, even if the pool is currently in the FAULTED
 * state.
 */
zpool_handle_t *
zpool_open_canfail(libzfs_handle_t *hdl, const char *pool)
{
	zpool_handle_t *zhp;
	boolean_t missing;

	/*
	 * Make sure the pool name is valid.
	 */
	if (!zpool_name_valid(hdl, B_TRUE, pool)) {
		(void) zfs_error(hdl, EZFS_INVALIDNAME,
		    dgettext(TEXT_DOMAIN, "cannot open '%s'"),
		    pool);
		return (NULL);
	}

	if ((zhp = zfs_alloc(hdl, sizeof (zpool_handle_t))) == NULL)
		return (NULL);

	zhp->zpool_hdl = hdl;
	(void) strlcpy(zhp->zpool_name, pool, sizeof (zhp->zpool_name));

	if (zpool_refresh_stats(zhp, &missing) != 0) {
		zpool_close(zhp);
		return (NULL);
	}

	if (missing) {
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
		    "no such pool"));
		(void) zfs_error(hdl, EZFS_NOENT,
		    dgettext(TEXT_DOMAIN, "cannot open '%s'"),
		    pool);
		zpool_close(zhp);
		return (NULL);
	}

	return (zhp);
}
开发者ID:andreiw,项目名称:polaris,代码行数:43,代码来源:libzfs_pool.c


注:本文中的zfs_alloc函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。