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


C++ zfs_open函数代码示例

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


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

示例1: snapshot_release

int
snapshot_release(char *volname, char *snapname, char *jname,
    boolean_t recursive)
{
	zfs_handle_t *zhp;
	char *p;
	int rv = 0;

	if ((zhp = zfs_open(zlibh, volname, ZFS_TYPE_DATASET)) == 0) {
		NDMP_LOG(LOG_ERR, "Cannot open volume %s", volname);
		return (-1);
	}

	p = strchr(snapname, '@') + 1;
	if (zfs_release(zhp, p, jname, recursive) != 0) {
		NDMP_LOG(LOG_DEBUG, "Cannot release snapshot %s", p);
		rv = -1;
	}
	if (cleanup_fd != -1) {
		(void) close(cleanup_fd);
		cleanup_fd = -1;
	}
	zfs_close(zhp);
	return (rv);
}
开发者ID:fdotli,项目名称:illumos-gate,代码行数:25,代码来源:ndmpd_chkpnt.c

示例2: sa_zfs_is_shared

int
sa_zfs_is_shared(sa_handle_t sahandle, char *path)
{
	int ret = 0;
	char *dataset;
	zfs_handle_t *handle = NULL;
	char shareopts[ZFS_MAXPROPLEN];
	libzfs_handle_t *libhandle;

	dataset = get_zfs_dataset((sa_handle_t)sahandle, path, B_FALSE);
	if (dataset != NULL) {
		libhandle = libzfs_init();
		if (libhandle != NULL) {
			handle = zfs_open(libhandle, dataset,
			    ZFS_TYPE_FILESYSTEM);
			if (handle != NULL) {
				if (zfs_prop_get(handle, ZFS_PROP_SHARENFS,
				    shareopts, sizeof (shareopts), NULL, NULL,
				    0, B_FALSE) == 0 &&
				    strcmp(shareopts, "off") != 0) {
					ret = 1; /* it is shared */
				}
				zfs_close(handle);
			}
			libzfs_fini(libhandle);
		}
		free(dataset);
	}
	return (ret);
}
开发者ID:BjoKaSH,项目名称:ZCE-CDDL-FILES,代码行数:30,代码来源:libshare_zfs.c

示例3: fs_is_chkpntvol

/*
 * Check if the volume type is snapshot volume
 */
boolean_t
fs_is_chkpntvol(char *path)
{
    zfs_handle_t *zhp;
    char vol[ZFS_MAXNAMELEN];

    if (!path || !*path)
        return (FALSE);

    if (get_zfsvolname(vol, sizeof (vol), path) == -1)
        return (FALSE);

    (void) mutex_lock(&zlib_mtx);
    if ((zhp = zfs_open(zlibh, vol, ZFS_TYPE_DATASET)) == NULL) {
        (void) mutex_unlock(&zlib_mtx);
        return (FALSE);
    }

    if (zfs_get_type(zhp) != ZFS_TYPE_SNAPSHOT) {
        zfs_close(zhp);
        (void) mutex_unlock(&zlib_mtx);
        return (FALSE);
    }
    zfs_close(zhp);
    (void) mutex_unlock(&zlib_mtx);

    return (TRUE);
}
开发者ID:mikess,项目名称:illumos-gate,代码行数:31,代码来源:tlm_lib.c

示例4: fsi_zfs_open

static int
fsi_zfs_open(fsi_file_t *ffi, char *filename)
{
	char *fsi_bootstring;
	uint64_t *fmax;
	uint64_t *fpos;
	int rc;

	zfs_ffi = ffi;
	fmax = fsig_filemax(ffi);
	fpos = fsig_filepos(ffi);

	rc = zfs_open(filename);
	if (rc != 1) {
		return (rc);
	}

	*fmax = filemax;
	*fpos = filepos;

	if (bootstring == NULL) {
		rc = asprintf(&bootstring,
			      "zfs-bootfs=%s/%"PRIu64",bootpath='%s'",
			      current_rootpool, current_bootfs_obj,
			      current_bootpath);
		if (rc == -1) {
			return (rc);
		}
		fsi_bootstring = fsi_bootstring_alloc(ffi->ff_fsi,
		    strlen(bootstring) + 1);
		strcpy(fsi_bootstring, bootstring);
	}

	return (rc);
}
开发者ID:Angel666,项目名称:android_hardware_intel,代码行数:35,代码来源:fsi_zfs.c

示例5: chkpnt_creationtime_bypattern

/*
 * Get the snapshot creation time
 */
int
chkpnt_creationtime_bypattern(char *volname, char *pattern, time_t *tp)
{
    char chk_name[PATH_MAX];
    zfs_handle_t *zhp;
    char *p;

    if (!volname || !*volname)
        return (-1);

    /* Should also return -1 if checkpoint not enabled */

    /* Remove the leading slash */
    p = volname;
    while (*p == '/')
        p++;

    (void) strlcpy(chk_name, p, PATH_MAX);
    (void) strlcat(chk_name, "@", PATH_MAX);
    (void) strlcat(chk_name, pattern, PATH_MAX);

    (void) mutex_lock(&zlib_mtx);
    if ((zhp = zfs_open(zlibh, chk_name, ZFS_TYPE_DATASET)) == NULL) {
        NDMP_LOG(LOG_DEBUG, "chkpnt_creationtime: open %s failed",
                 chk_name);
        (void) mutex_unlock(&zlib_mtx);
        return (-1);
    }

    *tp = zfs_prop_get_int(zhp, ZFS_PROP_CREATION);
    zfs_close(zhp);
    (void) mutex_unlock(&zlib_mtx);

    return (0);
}
开发者ID:mikess,项目名称:illumos-gate,代码行数:38,代码来源:tlm_lib.c

示例6: zfs_crypto_attempt_load_keys

/*
 * This function is best effort. It attempts to load all the keys for the given
 * filesystem and all of its children.
 */
int
zfs_crypto_attempt_load_keys(libzfs_handle_t *hdl, char *fsname)
{
	int ret;
	zfs_handle_t *zhp = NULL;
	loadkey_cbdata_t cb = { 0 };

	zhp = zfs_open(hdl, fsname, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME);
	if (zhp == NULL) {
		ret = ENOENT;
		goto error;
	}

	ret = load_keys_cb(zfs_handle_dup(zhp), &cb);
	if (ret)
		goto error;

	(void) printf(gettext("%llu / %llu keys successfully loaded\n"),
	    (u_longlong_t)(cb.cb_numattempted - cb.cb_numfailed),
	    (u_longlong_t)cb.cb_numattempted);

	if (cb.cb_numfailed != 0) {
		ret = -1;
		goto error;
	}

	zfs_close(zhp);
	return (0);

error:
	if (zhp != NULL)
		zfs_close(zhp);
	return (ret);
}
开发者ID:cbreak-black,项目名称:zfs,代码行数:38,代码来源:libzfs_crypto.c

示例7: snapshot_hold

/*
 * Put a hold on snapshot
 */
int
snapshot_hold(char *volname, char *snapname, char *jname, boolean_t recursive)
{
	zfs_handle_t *zhp;
	char *p;

	if ((zhp = zfs_open(zlibh, volname, ZFS_TYPE_DATASET)) == 0) {
		NDMP_LOG(LOG_ERR, "Cannot open volume %s.", volname);
		return (-1);
	}

	if (cleanup_fd == -1 && (cleanup_fd = open(ZFS_DEV,
	    O_RDWR|O_EXCL)) < 0) {
		NDMP_LOG(LOG_ERR, "Cannot open dev %d", errno);
		zfs_close(zhp);
		return (-1);
	}

	p = strchr(snapname, '@') + 1;
	if (zfs_hold(zhp, p, jname, recursive, cleanup_fd) != 0) {
		NDMP_LOG(LOG_ERR, "Cannot hold snapshot %s", p);
		zfs_close(zhp);
		return (-1);
	}
	zfs_close(zhp);
	return (0);
}
开发者ID:fdotli,项目名称:illumos-gate,代码行数:30,代码来源:ndmpd_chkpnt.c

示例8: rm_homedir

/* Remove a home directory structure */
int
rm_homedir(char *dir)
{
	struct stat stbuf;
	char *nm;

	if ((stat(dir, &stbuf) != 0) || !S_ISDIR(stbuf.st_mode))
		return 0;

	if (g_zfs == NULL)
		g_zfs = libzfs_init();

	if ((strcmp(stbuf.st_fstype, MNTTYPE_ZFS) == 0) && 
	    (g_zfs != NULL) &&
	    ((nm = get_mnt_special(dir, stbuf.st_fstype)) != NULL)) {
		zfs_handle_t *zhp;

	    	if ((zhp = zfs_open(g_zfs, nm, ZFS_TYPE_FILESYSTEM)) != NULL) {
			if ((zfs_unmount(zhp, NULL, 0) == 0) &&
			    (zfs_destroy(zhp, B_FALSE) == 0)) {
				zfs_close(zhp);
				return 0;
			}

			(void) zfs_mount(zhp, NULL, 0);
			zfs_close(zhp);
		}
	}

	(void) sprintf(cmdbuf, "rm -rf %s", dir);

	return (system(cmdbuf));
}
开发者ID:fatman2021,项目名称:illumos-gate,代码行数:34,代码来源:homedir.c

示例9: 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

示例10: rm_homedir

/* Remove a home directory structure */
int
rm_homedir(char *dir, int flags)
{
	struct stat stbuf;
	char *nm, *rp;

	rp = realpath(dir, NULL);
	if (rp && (strcmp(rp, "/") == 0)) {
		return (0);
	}

	if ((stat(dir, &stbuf) != 0) || !S_ISDIR(stbuf.st_mode))
		return (0);

	if ((strcmp(stbuf.st_fstype, MNTTYPE_ZFS) == 0) &&
	    (flags & MANAGE_ZFS)) {
		if (g_zfs == NULL)
			g_zfs = libzfs_init();

		if (g_zfs == NULL) {
			errmsg(M_OOPS, "libzfs_init failure", strerror(errno));
			return (EX_HOMEDIR);
		}

		if ((nm = get_mnt_special(dir, stbuf.st_fstype)) != NULL) {
			zfs_handle_t *zhp;

			if ((zhp = zfs_open(g_zfs, nm, ZFS_TYPE_FILESYSTEM))
			    != NULL) {
				if ((zfs_unmount(zhp, NULL, 0) == 0) &&
				    (zfs_destroy(zhp, B_FALSE) == 0)) {
					zfs_close(zhp);
					libzfs_fini(g_zfs);
					g_zfs = NULL;
					return (0);
				}

				errmsg(M_OOPS, "destroy the home directory",
				    libzfs_error_description(g_zfs));

				(void) zfs_mount(zhp, NULL, 0);
				zfs_close(zhp);

				libzfs_fini(g_zfs);
				g_zfs = NULL;
				return (EX_HOMEDIR);
			}
		}
	}

	(void) sprintf(cmdbuf, "rm -rf %s", dir);

	if (g_zfs != NULL) {
		libzfs_fini(g_zfs);
		g_zfs = NULL;
	}

	return (system(cmdbuf));
}
开发者ID:drscream,项目名称:illumos-joyent,代码行数:60,代码来源:homedir.c

示例11: sa_zfs_setprop

/*
 * Sets the share properties on a ZFS share. For now, this method sets only
 * the "sharesmb" property.
 *
 * This method includes building a comma seperated name-value string to be
 * set on the "sharesmb" property of a ZFS share. This name-value string is
 * build in 2 steps:
 *    - New property values given as name-value pair are set first.
 *    - Existing optionset properties, which are not part of the new properties
 *	passed in step 1, are appended to the newly set properties.
 */
int
sa_zfs_setprop(sa_handle_t handle, char *path, nvlist_t *nvl)
{
	zfs_handle_t *z_fs;
	libzfs_handle_t *z_lib;
	char sharesmb_val[MAXPATHLEN];
	char *dataset, *lastcomma;

	if (nvlist_empty(nvl))
		return (0);

	if ((handle == NULL) || (path == NULL))
		return (-1);

	if ((dataset = get_zfs_dataset(handle, path, B_FALSE)) == NULL)
		return (-1);

	if ((z_lib = libzfs_init()) == NULL) {
		free(dataset);
		return (-1);
	}

	z_fs = zfs_open(z_lib, dataset, ZFS_TYPE_DATASET);
	if (z_fs == NULL) {
		free(dataset);
		libzfs_fini(z_lib);
		return (-1);
	}

	bzero(sharesmb_val, MAXPATHLEN);
	if (sa_zfs_sprintf_new_prop(nvl, sharesmb_val) != 0) {
		free(dataset);
		zfs_close(z_fs);
		libzfs_fini(z_lib);
		return (-1);
	}

	if (sa_zfs_sprintf_existing_prop(z_fs, sharesmb_val) != 0) {
		free(dataset);
		zfs_close(z_fs);
		libzfs_fini(z_lib);
		return (-1);
	}

	lastcomma = strrchr(sharesmb_val, ',');
	if ((lastcomma != NULL) && (lastcomma[1] == '\0'))
		*lastcomma = '\0';

	(void) zfs_prop_set(z_fs, zfs_prop_to_name(ZFS_PROP_SHARESMB),
	    sharesmb_val);
	free(dataset);
	zfs_close(z_fs);
	libzfs_fini(z_lib);

	return (0);
}
开发者ID:BjoKaSH,项目名称:ZCE-CDDL-FILES,代码行数:67,代码来源:libshare_zfs.c

示例12: libzfs_zpool_create

/**
 * Create the zpool
 * @param p_libzfshd: libzfs handle
 * @param psz_zpool: zpool name
 * @param pnv_root: the root tree of vdev
 * @param pnv_props: the tree of properties (can be NULL)
 * @param pnv_fsprops: the tree of the file system properties (can be NULL)
 * @param ppsz_error: the error message if any
 * @return 0 in case of error, the error code overwise
 */
int libzfs_zpool_create(libzfs_handle_t *p_libzfshd, const char* psz_zpool,
                        nvlist_t *pnv_root, nvlist_t *pnv_props,
                        nvlist_t *pnv_fsprops, const char **ppsz_error)
{
        int i_error;
        char *psz_altroot;

        /* Check the zpool name */
        if(libzfs_zpool_name_valid(psz_zpool, ppsz_error))
                return EINVAL;

        /** Check the properties
            TODO: zpool_valid_proplist and zfs_valid_proplist */

        if((i_error = spa_create(psz_zpool, pnv_root, pnv_props, "libzfswrap_zpool_create", pnv_fsprops)))
        {
                switch(i_error)
                {
                case EBUSY:
                        *ppsz_error = "one or more vdevs refer to the same device";
                        break;
                case EOVERFLOW:
                        *ppsz_error = "one or more devices is less than the minimum size (64Mo)";
                        break;
                case ENOSPC:
                        *ppsz_error = "one or more devices is out of space";
                        break;
                case ENOTBLK:
                        *ppsz_error = "cache device must be a disk or disk slice";
                        break;
                case EEXIST:
                        *ppsz_error = "the pool already exist";
                        break;
                default:
                        *ppsz_error = "unable to create the spa";
                }
                return i_error;
        }

        /* If this is an alternate root pool, then automatically set the
           mountpoint to be '/' */
        if(nvlist_lookup_string(pnv_props, zpool_prop_to_name(ZPOOL_PROP_ALTROOT), &psz_altroot) == 0)
        {
                zfs_handle_t *p_zhd;
                assert((p_zhd = zfs_open(p_libzfshd, psz_zpool, ZFS_TYPE_DATASET)) != NULL);
                assert(zfs_prop_set(p_zhd, zfs_prop_to_name(ZFS_PROP_MOUNTPOINT), "/") == 0);
                zfs_close(p_zhd);
        }

        return 0;
}
开发者ID:Anuradha-Talur,项目名称:nfs-ganesha,代码行数:61,代码来源:libzfs.c

示例13: be_get_zone_be_list

/*
 * Function:	be_get_zone_be_list
 * Description:	Finds all the BEs for this zone on the system.
 * Parameters:
 *		zone_be_name - The name of the BE to look up.
 *              zone_be_container_ds - The dataset for the zone.
 *		zbe_nodes - A reference pointer to the list of BEs. The list
 *			   structure will be allocated here and must
 *			   be freed by a call to be_free_list. If there are no
 *			   BEs found on the system this reference will be
 *			   set to NULL.
 * Return:
 *		BE_SUCCESS - Success
 *		be_errno_t - Failure
 * Scope:
 *		Semi-private (library wide use only)
 */
int
be_get_zone_be_list(
/* LINTED */
	char *zone_be_name,
	char *zone_be_container_ds,
	be_node_list_t **zbe_nodes)
{
	zfs_handle_t *zhp = NULL;
	list_callback_data_t cb = { 0 };
	int ret = BE_SUCCESS;

	if (zbe_nodes == NULL)
		return (BE_ERR_INVAL);

	if (!zfs_dataset_exists(g_zfs, zone_be_container_ds,
	    ZFS_TYPE_FILESYSTEM)) {
		return (BE_ERR_BE_NOENT);
	}

	zone_be = B_TRUE;

	if ((zhp = zfs_open(g_zfs, zone_be_container_ds,
	    ZFS_TYPE_FILESYSTEM)) == NULL) {
		be_print_err(gettext("be_get_zone_be_list: failed to open "
		    "the zone BE dataset %s: %s\n"), zone_be_container_ds,
		    libzfs_error_description(g_zfs));
		ret = zfs_err_to_be_err(g_zfs);
		goto cleanup;
	}

	(void) strcpy(be_container_ds, zone_be_container_ds);

	if (cb.be_nodes_head == NULL) {
		if ((cb.be_nodes_head = be_list_alloc(&ret,
		    sizeof (be_node_list_t))) == NULL) {
			ZFS_CLOSE(zhp);
			goto cleanup;
		}
		cb.be_nodes = cb.be_nodes_head;
	}
	if (ret == 0)
		ret = zfs_iter_filesystems(zhp, be_add_children_callback, &cb);
	ZFS_CLOSE(zhp);

	*zbe_nodes = cb.be_nodes_head;

cleanup:
	zone_be = B_FALSE;

	return (ret);
}
开发者ID:NanXiao,项目名称:illumos-joyent,代码行数:68,代码来源:be_list.c

示例14: zpl_open

static int
zpl_open(struct inode *ip, struct file *filp)
{
	cred_t *cr = CRED();
	int error;

	error = generic_file_open(ip, filp);
	if (error)
		return (error);

	crhold(cr);
	error = -zfs_open(ip, filp->f_mode, filp->f_flags, cr);
	crfree(cr);
	ASSERT3S(error, <=, 0);

	return (error);
}
开发者ID:shenyan1,项目名称:zfs,代码行数:17,代码来源:zpl_file.c

示例15: validate_zfs_iscsitgt

/*
 * Just checking the existance of the given target. Here we check whether
 * both zfs and iscsitarget aware of the given target/volume. It neither
 * care about the credentials nor SHAREISCSI properties.
 */
static char *
validate_zfs_iscsitgt(tgt_node_t *x)
{
	char		*msg		= NULL;
	char		*prop		= NULL;
	char		*dataset	= NULL;
	libzfs_handle_t	*zh		= NULL;
	zfs_handle_t	*zfsh		= NULL;
	tgt_node_t	*n		= NULL;

	if (tgt_find_value_str(x, XML_ELEMENT_NAME, &dataset) == False) {
		xml_rtn_msg(&msg, ERR_SYNTAX_MISSING_NAME);
		return (msg);
	}

	if (((zh = libzfs_init()) == NULL) ||
	    ((zfsh = zfs_open(zh, dataset, ZFS_TYPE_DATASET)) == NULL)) {
		xml_rtn_msg(&msg, ERR_TARG_NOT_FOUND);
		goto error;
	}

	while ((n = tgt_node_next_child(targets_config, XML_ELEMENT_TARG, n)) !=
	    NULL) {
		if (strcmp(n->x_value, dataset) == 0)
			break;
	}
	if (n == NULL) {
		xml_rtn_msg(&msg, ERR_TARG_NOT_FOUND);
		goto error;
	}

	xml_rtn_msg(&msg, ERR_SUCCESS);

error:
	if (zfsh)
		zfs_close(zfsh);
	if (prop)
		free(prop);
	if (zh)
		libzfs_fini(zh);
	if (dataset)
		free(dataset);

	return (msg);

}
开发者ID:CoryXie,项目名称:opensolaris,代码行数:51,代码来源:mgmt_modify.c


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