mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-23 02:44:41 +03:00
Rebase master to b105
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <libnvpair.h>
|
||||
#include <sys/mnttab.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/varargs.h>
|
||||
@@ -175,6 +176,13 @@ extern void libzfs_print_on_error(libzfs_handle_t *, boolean_t);
|
||||
extern int libzfs_errno(libzfs_handle_t *);
|
||||
extern const char *libzfs_error_action(libzfs_handle_t *);
|
||||
extern const char *libzfs_error_description(libzfs_handle_t *);
|
||||
extern void libzfs_mnttab_init(libzfs_handle_t *);
|
||||
extern void libzfs_mnttab_fini(libzfs_handle_t *);
|
||||
extern int libzfs_mnttab_find(libzfs_handle_t *, const char *,
|
||||
struct mnttab *);
|
||||
extern void libzfs_mnttab_add(libzfs_handle_t *, const char *,
|
||||
const char *, const char *);
|
||||
extern void libzfs_mnttab_remove(libzfs_handle_t *, const char *);
|
||||
|
||||
/*
|
||||
* Basic handle functions
|
||||
@@ -289,6 +297,7 @@ extern int zpool_get_errlog(zpool_handle_t *, nvlist_t **);
|
||||
* Import and export functions
|
||||
*/
|
||||
extern int zpool_export(zpool_handle_t *, boolean_t);
|
||||
extern int zpool_export_force(zpool_handle_t *);
|
||||
extern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *,
|
||||
char *altroot);
|
||||
extern int zpool_import_props(libzfs_handle_t *, nvlist_t *, const char *,
|
||||
|
||||
@@ -63,6 +63,7 @@ struct libzfs_handle {
|
||||
int libzfs_printerr;
|
||||
void *libzfs_sharehdl; /* libshare handle */
|
||||
uint_t libzfs_shareflags;
|
||||
avl_tree_t libzfs_mnttab_cache;
|
||||
};
|
||||
#define ZFSSHARE_MISS 0x01 /* Didn't find entry in cache */
|
||||
|
||||
|
||||
+278
-85
@@ -38,7 +38,6 @@
|
||||
#include <zone.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mntent.h>
|
||||
#include <sys/mnttab.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/avl.h>
|
||||
#include <priv.h>
|
||||
@@ -108,7 +107,6 @@ path_to_str(const char *path, int types)
|
||||
return (path_to_str(path, types & ~ZFS_TYPE_SNAPSHOT));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The user has requested either filesystems or volumes.
|
||||
* We have no way of knowing a priori what type this would be, so always
|
||||
@@ -319,38 +317,35 @@ zpool_free_handles(libzfs_handle_t *hdl)
|
||||
* Utility function to gather stats (objset and zpl) for the given object.
|
||||
*/
|
||||
static int
|
||||
get_stats(zfs_handle_t *zhp)
|
||||
get_stats_ioctl(zfs_handle_t *zhp, zfs_cmd_t *zc)
|
||||
{
|
||||
zfs_cmd_t zc = { 0 };
|
||||
libzfs_handle_t *hdl = zhp->zfs_hdl;
|
||||
nvlist_t *allprops, *userprops;
|
||||
|
||||
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
|
||||
(void) strlcpy(zc->zc_name, zhp->zfs_name, sizeof (zc->zc_name));
|
||||
|
||||
if (zcmd_alloc_dst_nvlist(hdl, &zc, 0) != 0)
|
||||
return (-1);
|
||||
|
||||
while (ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_OBJSET_STATS, &zc) != 0) {
|
||||
while (ioctl(hdl->libzfs_fd, ZFS_IOC_OBJSET_STATS, zc) != 0) {
|
||||
if (errno == ENOMEM) {
|
||||
if (zcmd_expand_dst_nvlist(hdl, &zc) != 0) {
|
||||
zcmd_free_nvlists(&zc);
|
||||
if (zcmd_expand_dst_nvlist(hdl, zc) != 0) {
|
||||
return (-1);
|
||||
}
|
||||
} else {
|
||||
zcmd_free_nvlists(&zc);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
zhp->zfs_dmustats = zc.zc_objset_stats; /* structure assignment */
|
||||
static int
|
||||
put_stats_zhdl(zfs_handle_t *zhp, zfs_cmd_t *zc)
|
||||
{
|
||||
nvlist_t *allprops, *userprops;
|
||||
|
||||
if (zcmd_read_dst_nvlist(hdl, &zc, &allprops) != 0) {
|
||||
zcmd_free_nvlists(&zc);
|
||||
zhp->zfs_dmustats = zc->zc_objset_stats; /* structure assignment */
|
||||
|
||||
if (zcmd_read_dst_nvlist(zhp->zfs_hdl, zc, &allprops) != 0) {
|
||||
return (-1);
|
||||
}
|
||||
|
||||
zcmd_free_nvlists(&zc);
|
||||
|
||||
if ((userprops = process_user_props(zhp, allprops)) == NULL) {
|
||||
nvlist_free(allprops);
|
||||
return (-1);
|
||||
@@ -365,6 +360,22 @@ get_stats(zfs_handle_t *zhp)
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
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);
|
||||
if (get_stats_ioctl(zhp, &zc) != 0)
|
||||
rc = -1;
|
||||
else if (put_stats_zhdl(zhp, &zc) != 0)
|
||||
rc = -1;
|
||||
zcmd_free_nvlists(&zc);
|
||||
return (rc);
|
||||
}
|
||||
|
||||
/*
|
||||
* Refresh the properties currently stored in the handle.
|
||||
*/
|
||||
@@ -378,16 +389,11 @@ zfs_refresh_properties(zfs_handle_t *zhp)
|
||||
* Makes a handle from the given dataset name. Used by zfs_open() and
|
||||
* zfs_iter_* to create child handles on the fly.
|
||||
*/
|
||||
zfs_handle_t *
|
||||
make_dataset_handle(libzfs_handle_t *hdl, const char *path)
|
||||
static int
|
||||
make_dataset_handle_common(zfs_handle_t *zhp, zfs_cmd_t *zc)
|
||||
{
|
||||
zfs_handle_t *zhp = calloc(sizeof (zfs_handle_t), 1);
|
||||
char *logstr;
|
||||
|
||||
if (zhp == NULL)
|
||||
return (NULL);
|
||||
|
||||
zhp->zfs_hdl = hdl;
|
||||
libzfs_handle_t *hdl = zhp->zfs_hdl;
|
||||
|
||||
/*
|
||||
* Preserve history log string.
|
||||
@@ -396,17 +402,16 @@ make_dataset_handle(libzfs_handle_t *hdl, const char *path)
|
||||
*/
|
||||
logstr = zhp->zfs_hdl->libzfs_log_str;
|
||||
zhp->zfs_hdl->libzfs_log_str = NULL;
|
||||
top:
|
||||
(void) strlcpy(zhp->zfs_name, path, sizeof (zhp->zfs_name));
|
||||
|
||||
if (get_stats(zhp) != 0) {
|
||||
top:
|
||||
if (put_stats_zhdl(zhp, zc) != 0) {
|
||||
zhp->zfs_hdl->libzfs_log_str = logstr;
|
||||
free(zhp);
|
||||
return (NULL);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
if (zhp->zfs_dmustats.dds_inconsistent) {
|
||||
zfs_cmd_t zc = { 0 };
|
||||
zfs_cmd_t zc2 = { 0 };
|
||||
|
||||
/*
|
||||
* If it is dds_inconsistent, then we've caught it in
|
||||
@@ -423,28 +428,33 @@ top:
|
||||
* will fail with EBUSY and we will drive on as usual.
|
||||
*/
|
||||
|
||||
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
|
||||
(void) strlcpy(zc2.zc_name, zhp->zfs_name,
|
||||
sizeof (zc2.zc_name));
|
||||
|
||||
if (zhp->zfs_dmustats.dds_type == DMU_OST_ZVOL) {
|
||||
(void) zvol_remove_link(hdl, zhp->zfs_name);
|
||||
zc.zc_objset_type = DMU_OST_ZVOL;
|
||||
zc2.zc_objset_type = DMU_OST_ZVOL;
|
||||
} else {
|
||||
zc.zc_objset_type = DMU_OST_ZFS;
|
||||
zc2.zc_objset_type = DMU_OST_ZFS;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we can successfully destroy it, pretend that it
|
||||
* never existed.
|
||||
*/
|
||||
if (ioctl(hdl->libzfs_fd, ZFS_IOC_DESTROY, &zc) == 0) {
|
||||
if (ioctl(hdl->libzfs_fd, ZFS_IOC_DESTROY, &zc2) == 0) {
|
||||
zhp->zfs_hdl->libzfs_log_str = logstr;
|
||||
free(zhp);
|
||||
errno = ENOENT;
|
||||
return (NULL);
|
||||
return (-1);
|
||||
}
|
||||
/* If we can successfully roll it back, reget the stats */
|
||||
if (ioctl(hdl->libzfs_fd, ZFS_IOC_ROLLBACK, &zc) == 0)
|
||||
/* If we can successfully roll it back, reset the stats */
|
||||
if (ioctl(hdl->libzfs_fd, ZFS_IOC_ROLLBACK, &zc2) == 0) {
|
||||
if (get_stats_ioctl(zhp, zc) != 0) {
|
||||
zhp->zfs_hdl->libzfs_log_str = logstr;
|
||||
return (-1);
|
||||
}
|
||||
goto top;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -469,6 +479,52 @@ top:
|
||||
|
||||
zhp->zfs_hdl->libzfs_log_str = logstr;
|
||||
zhp->zpool_hdl = zpool_handle(zhp);
|
||||
return (0);
|
||||
}
|
||||
|
||||
zfs_handle_t *
|
||||
make_dataset_handle(libzfs_handle_t *hdl, const char *path)
|
||||
{
|
||||
zfs_cmd_t zc = { 0 };
|
||||
|
||||
zfs_handle_t *zhp = calloc(sizeof (zfs_handle_t), 1);
|
||||
|
||||
if (zhp == NULL)
|
||||
return (NULL);
|
||||
|
||||
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);
|
||||
}
|
||||
if (get_stats_ioctl(zhp, &zc) == -1) {
|
||||
zcmd_free_nvlists(&zc);
|
||||
free(zhp);
|
||||
return (NULL);
|
||||
}
|
||||
if (make_dataset_handle_common(zhp, &zc) == -1) {
|
||||
free(zhp);
|
||||
zhp = NULL;
|
||||
}
|
||||
zcmd_free_nvlists(&zc);
|
||||
return (zhp);
|
||||
}
|
||||
|
||||
static zfs_handle_t *
|
||||
make_dataset_handle_zc(libzfs_handle_t *hdl, zfs_cmd_t *zc)
|
||||
{
|
||||
zfs_handle_t *zhp = calloc(sizeof (zfs_handle_t), 1);
|
||||
|
||||
if (zhp == NULL)
|
||||
return (NULL);
|
||||
|
||||
zhp->zfs_hdl = hdl;
|
||||
(void) strlcpy(zhp->zfs_name, zc->zc_name, sizeof (zhp->zfs_name));
|
||||
if (make_dataset_handle_common(zhp, zc) == -1) {
|
||||
free(zhp);
|
||||
return (NULL);
|
||||
}
|
||||
return (zhp);
|
||||
}
|
||||
|
||||
@@ -527,6 +583,117 @@ zfs_close(zfs_handle_t *zhp)
|
||||
free(zhp);
|
||||
}
|
||||
|
||||
typedef struct mnttab_node {
|
||||
struct mnttab mtn_mt;
|
||||
avl_node_t mtn_node;
|
||||
} mnttab_node_t;
|
||||
|
||||
static int
|
||||
libzfs_mnttab_cache_compare(const void *arg1, const void *arg2)
|
||||
{
|
||||
const mnttab_node_t *mtn1 = arg1;
|
||||
const mnttab_node_t *mtn2 = arg2;
|
||||
int rv;
|
||||
|
||||
rv = strcmp(mtn1->mtn_mt.mnt_special, mtn2->mtn_mt.mnt_special);
|
||||
|
||||
if (rv == 0)
|
||||
return (0);
|
||||
return (rv > 0 ? 1 : -1);
|
||||
}
|
||||
|
||||
void
|
||||
libzfs_mnttab_init(libzfs_handle_t *hdl)
|
||||
{
|
||||
struct mnttab entry;
|
||||
|
||||
assert(avl_numnodes(&hdl->libzfs_mnttab_cache) == 0);
|
||||
avl_create(&hdl->libzfs_mnttab_cache, libzfs_mnttab_cache_compare,
|
||||
sizeof (mnttab_node_t), offsetof(mnttab_node_t, mtn_node));
|
||||
|
||||
rewind(hdl->libzfs_mnttab);
|
||||
while (getmntent(hdl->libzfs_mnttab, &entry) == 0) {
|
||||
mnttab_node_t *mtn;
|
||||
|
||||
if (strcmp(entry.mnt_fstype, MNTTYPE_ZFS) != 0)
|
||||
continue;
|
||||
mtn = zfs_alloc(hdl, sizeof (mnttab_node_t));
|
||||
mtn->mtn_mt.mnt_special = zfs_strdup(hdl, entry.mnt_special);
|
||||
mtn->mtn_mt.mnt_mountp = zfs_strdup(hdl, entry.mnt_mountp);
|
||||
mtn->mtn_mt.mnt_fstype = zfs_strdup(hdl, entry.mnt_fstype);
|
||||
mtn->mtn_mt.mnt_mntopts = zfs_strdup(hdl, entry.mnt_mntopts);
|
||||
avl_add(&hdl->libzfs_mnttab_cache, mtn);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
libzfs_mnttab_fini(libzfs_handle_t *hdl)
|
||||
{
|
||||
void *cookie = NULL;
|
||||
mnttab_node_t *mtn;
|
||||
|
||||
while (mtn = avl_destroy_nodes(&hdl->libzfs_mnttab_cache, &cookie)) {
|
||||
free(mtn->mtn_mt.mnt_special);
|
||||
free(mtn->mtn_mt.mnt_mountp);
|
||||
free(mtn->mtn_mt.mnt_fstype);
|
||||
free(mtn->mtn_mt.mnt_mntopts);
|
||||
free(mtn);
|
||||
}
|
||||
avl_destroy(&hdl->libzfs_mnttab_cache);
|
||||
}
|
||||
|
||||
int
|
||||
libzfs_mnttab_find(libzfs_handle_t *hdl, const char *fsname,
|
||||
struct mnttab *entry)
|
||||
{
|
||||
mnttab_node_t find;
|
||||
mnttab_node_t *mtn;
|
||||
|
||||
if (avl_numnodes(&hdl->libzfs_mnttab_cache) == 0)
|
||||
libzfs_mnttab_init(hdl);
|
||||
|
||||
find.mtn_mt.mnt_special = (char *)fsname;
|
||||
mtn = avl_find(&hdl->libzfs_mnttab_cache, &find, NULL);
|
||||
if (mtn) {
|
||||
*entry = mtn->mtn_mt;
|
||||
return (0);
|
||||
}
|
||||
return (ENOENT);
|
||||
}
|
||||
|
||||
void
|
||||
libzfs_mnttab_add(libzfs_handle_t *hdl, const char *special,
|
||||
const char *mountp, const char *mntopts)
|
||||
{
|
||||
mnttab_node_t *mtn;
|
||||
|
||||
if (avl_numnodes(&hdl->libzfs_mnttab_cache) == 0)
|
||||
return;
|
||||
mtn = zfs_alloc(hdl, sizeof (mnttab_node_t));
|
||||
mtn->mtn_mt.mnt_special = zfs_strdup(hdl, special);
|
||||
mtn->mtn_mt.mnt_mountp = zfs_strdup(hdl, mountp);
|
||||
mtn->mtn_mt.mnt_fstype = zfs_strdup(hdl, MNTTYPE_ZFS);
|
||||
mtn->mtn_mt.mnt_mntopts = zfs_strdup(hdl, mntopts);
|
||||
avl_add(&hdl->libzfs_mnttab_cache, mtn);
|
||||
}
|
||||
|
||||
void
|
||||
libzfs_mnttab_remove(libzfs_handle_t *hdl, const char *fsname)
|
||||
{
|
||||
mnttab_node_t find;
|
||||
mnttab_node_t *ret;
|
||||
|
||||
find.mtn_mt.mnt_special = (char *)fsname;
|
||||
if (ret = avl_find(&hdl->libzfs_mnttab_cache, (void *)&find, NULL)) {
|
||||
avl_remove(&hdl->libzfs_mnttab_cache, ret);
|
||||
free(ret->mtn_mt.mnt_special);
|
||||
free(ret->mtn_mt.mnt_mountp);
|
||||
free(ret->mtn_mt.mnt_fstype);
|
||||
free(ret->mtn_mt.mnt_mntopts);
|
||||
free(ret);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
zfs_spa_version(zfs_handle_t *zhp, int *spa_version)
|
||||
{
|
||||
@@ -2123,15 +2290,11 @@ get_numeric_property(zfs_handle_t *zhp, zfs_prop_t prop, zprop_source_t *src,
|
||||
*/
|
||||
if (!zhp->zfs_mntcheck &&
|
||||
(mntopt_on != NULL || prop == ZFS_PROP_MOUNTED)) {
|
||||
struct mnttab entry, search = { 0 };
|
||||
FILE *mnttab = zhp->zfs_hdl->libzfs_mnttab;
|
||||
libzfs_handle_t *hdl = zhp->zfs_hdl;
|
||||
struct mnttab entry;
|
||||
|
||||
search.mnt_special = (char *)zhp->zfs_name;
|
||||
search.mnt_fstype = MNTTYPE_ZFS;
|
||||
rewind(mnttab);
|
||||
|
||||
if (getmntany(mnttab, &entry, &search) == 0) {
|
||||
zhp->zfs_mntopts = zfs_strdup(zhp->zfs_hdl,
|
||||
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);
|
||||
@@ -2575,6 +2738,46 @@ zfs_get_type(const zfs_handle_t *zhp)
|
||||
return (zhp->zfs_type);
|
||||
}
|
||||
|
||||
static int
|
||||
zfs_do_list_ioctl(zfs_handle_t *zhp, int arg, zfs_cmd_t *zc)
|
||||
{
|
||||
int rc;
|
||||
uint64_t orig_cookie;
|
||||
|
||||
orig_cookie = zc->zc_cookie;
|
||||
top:
|
||||
(void) strlcpy(zc->zc_name, zhp->zfs_name, sizeof (zc->zc_name));
|
||||
rc = ioctl(zhp->zfs_hdl->libzfs_fd, arg, zc);
|
||||
|
||||
if (rc == -1) {
|
||||
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);
|
||||
}
|
||||
zc->zc_cookie = orig_cookie;
|
||||
goto top;
|
||||
/*
|
||||
* An errno value of ESRCH indicates normal completion.
|
||||
* If ENOENT is returned, then the underlying dataset
|
||||
* has been removed since we obtained the handle.
|
||||
*/
|
||||
case ESRCH:
|
||||
case ENOENT:
|
||||
rc = 1;
|
||||
break;
|
||||
default:
|
||||
rc = zfs_standard_error(zhp->zfs_hdl, errno,
|
||||
dgettext(TEXT_DOMAIN,
|
||||
"cannot iterate filesystems"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (rc);
|
||||
}
|
||||
|
||||
/*
|
||||
* Iterate over all child filesystems
|
||||
*/
|
||||
@@ -2588,9 +2791,11 @@ zfs_iter_filesystems(zfs_handle_t *zhp, zfs_iter_f func, void *data)
|
||||
if (zhp->zfs_type != ZFS_TYPE_FILESYSTEM)
|
||||
return (0);
|
||||
|
||||
for ((void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
|
||||
ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_DATASET_LIST_NEXT, &zc) == 0;
|
||||
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name))) {
|
||||
if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0)
|
||||
return (-1);
|
||||
|
||||
while ((ret = zfs_do_list_ioctl(zhp, ZFS_IOC_DATASET_LIST_NEXT,
|
||||
&zc)) == 0) {
|
||||
/*
|
||||
* Ignore private dataset names.
|
||||
*/
|
||||
@@ -2601,24 +2806,18 @@ zfs_iter_filesystems(zfs_handle_t *zhp, zfs_iter_f func, void *data)
|
||||
* Silently ignore errors, as the only plausible explanation is
|
||||
* that the pool has since been removed.
|
||||
*/
|
||||
if ((nzhp = make_dataset_handle(zhp->zfs_hdl,
|
||||
zc.zc_name)) == NULL)
|
||||
if ((nzhp = make_dataset_handle_zc(zhp->zfs_hdl,
|
||||
&zc)) == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((ret = func(nzhp, data)) != 0)
|
||||
if ((ret = func(nzhp, data)) != 0) {
|
||||
zcmd_free_nvlists(&zc);
|
||||
return (ret);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* An errno value of ESRCH indicates normal completion. If ENOENT is
|
||||
* returned, then the underlying dataset has been removed since we
|
||||
* obtained the handle.
|
||||
*/
|
||||
if (errno != ESRCH && errno != ENOENT)
|
||||
return (zfs_standard_error(zhp->zfs_hdl, errno,
|
||||
dgettext(TEXT_DOMAIN, "cannot iterate filesystems")));
|
||||
|
||||
return (0);
|
||||
zcmd_free_nvlists(&zc);
|
||||
return ((ret < 0) ? ret : 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2634,29 +2833,23 @@ zfs_iter_snapshots(zfs_handle_t *zhp, zfs_iter_f func, void *data)
|
||||
if (zhp->zfs_type == ZFS_TYPE_SNAPSHOT)
|
||||
return (0);
|
||||
|
||||
for ((void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
|
||||
ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_SNAPSHOT_LIST_NEXT,
|
||||
&zc) == 0;
|
||||
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name))) {
|
||||
if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0)
|
||||
return (-1);
|
||||
while ((ret = zfs_do_list_ioctl(zhp, ZFS_IOC_SNAPSHOT_LIST_NEXT,
|
||||
&zc)) == 0) {
|
||||
|
||||
if ((nzhp = make_dataset_handle(zhp->zfs_hdl,
|
||||
zc.zc_name)) == NULL)
|
||||
if ((nzhp = make_dataset_handle_zc(zhp->zfs_hdl,
|
||||
&zc)) == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((ret = func(nzhp, data)) != 0)
|
||||
if ((ret = func(nzhp, data)) != 0) {
|
||||
zcmd_free_nvlists(&zc);
|
||||
return (ret);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* An errno value of ESRCH indicates normal completion. If ENOENT is
|
||||
* returned, then the underlying dataset has been removed since we
|
||||
* obtained the handle. Silently ignore this case, and return success.
|
||||
*/
|
||||
if (errno != ESRCH && errno != ENOENT)
|
||||
return (zfs_standard_error(zhp->zfs_hdl, errno,
|
||||
dgettext(TEXT_DOMAIN, "cannot iterate filesystems")));
|
||||
|
||||
return (0);
|
||||
zcmd_free_nvlists(&zc);
|
||||
return ((ret < 0) ? ret : 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2709,8 +2902,8 @@ check_parents(libzfs_handle_t *hdl, const char *path, uint64_t *zoned,
|
||||
zfs_handle_t *zhp;
|
||||
char errbuf[1024];
|
||||
|
||||
(void) snprintf(errbuf, sizeof (errbuf), "cannot create '%s'",
|
||||
path);
|
||||
(void) snprintf(errbuf, sizeof (errbuf),
|
||||
dgettext(TEXT_DOMAIN, "cannot create '%s'"), path);
|
||||
|
||||
/* get parent, and check to see if this is just a pool */
|
||||
if (parent_name(path, parent, sizeof (parent)) != 0) {
|
||||
|
||||
+22
-33
@@ -74,7 +74,6 @@
|
||||
#include <unistd.h>
|
||||
#include <zone.h>
|
||||
#include <sys/mntent.h>
|
||||
#include <sys/mnttab.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
@@ -236,18 +235,9 @@ dir_is_empty(const char *dirname)
|
||||
boolean_t
|
||||
is_mounted(libzfs_handle_t *zfs_hdl, const char *special, char **where)
|
||||
{
|
||||
struct mnttab search = { 0 }, entry;
|
||||
struct mnttab entry;
|
||||
|
||||
/*
|
||||
* Search for the entry in /etc/mnttab. We don't bother getting the
|
||||
* mountpoint, as we can just search for the special device. This will
|
||||
* also let us find mounts when the mountpoint is 'legacy'.
|
||||
*/
|
||||
search.mnt_special = (char *)special;
|
||||
search.mnt_fstype = MNTTYPE_ZFS;
|
||||
|
||||
rewind(zfs_hdl->libzfs_mnttab);
|
||||
if (getmntany(zfs_hdl->libzfs_mnttab, &entry, &search) != 0)
|
||||
if (libzfs_mnttab_find(zfs_hdl, special, &entry) != 0)
|
||||
return (B_FALSE);
|
||||
|
||||
if (where != NULL)
|
||||
@@ -358,12 +348,14 @@ zfs_mount(zfs_handle_t *zhp, const char *options, int flags)
|
||||
} else {
|
||||
zfs_error_aux(hdl, strerror(errno));
|
||||
}
|
||||
|
||||
return (zfs_error_fmt(hdl, EZFS_MOUNTFAILED,
|
||||
dgettext(TEXT_DOMAIN, "cannot mount '%s'"),
|
||||
zhp->zfs_name));
|
||||
}
|
||||
|
||||
/* add the mounted entry into our cache */
|
||||
libzfs_mnttab_add(hdl, zfs_get_name(zhp), mountpoint,
|
||||
mntopts);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -389,26 +381,23 @@ unmount_one(libzfs_handle_t *hdl, const char *mountpoint, int flags)
|
||||
int
|
||||
zfs_unmount(zfs_handle_t *zhp, const char *mountpoint, int flags)
|
||||
{
|
||||
struct mnttab search = { 0 }, entry;
|
||||
libzfs_handle_t *hdl = zhp->zfs_hdl;
|
||||
struct mnttab entry;
|
||||
char *mntpt = NULL;
|
||||
|
||||
/* check to see if need to unmount the filesystem */
|
||||
search.mnt_special = zhp->zfs_name;
|
||||
search.mnt_fstype = MNTTYPE_ZFS;
|
||||
rewind(zhp->zfs_hdl->libzfs_mnttab);
|
||||
/* check to see if we need to unmount the filesystem */
|
||||
if (mountpoint != NULL || ((zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) &&
|
||||
getmntany(zhp->zfs_hdl->libzfs_mnttab, &entry, &search) == 0)) {
|
||||
|
||||
libzfs_mnttab_find(hdl, zhp->zfs_name, &entry) == 0)) {
|
||||
/*
|
||||
* mountpoint may have come from a call to
|
||||
* getmnt/getmntany if it isn't NULL. If it is NULL,
|
||||
* we know it comes from getmntany which can then get
|
||||
* overwritten later. We strdup it to play it safe.
|
||||
* we know it comes from libzfs_mnttab_find which can
|
||||
* then get freed later. We strdup it to play it safe.
|
||||
*/
|
||||
if (mountpoint == NULL)
|
||||
mntpt = zfs_strdup(zhp->zfs_hdl, entry.mnt_mountp);
|
||||
mntpt = zfs_strdup(hdl, entry.mnt_mountp);
|
||||
else
|
||||
mntpt = zfs_strdup(zhp->zfs_hdl, mountpoint);
|
||||
mntpt = zfs_strdup(hdl, mountpoint);
|
||||
|
||||
/*
|
||||
* Unshare and unmount the filesystem
|
||||
@@ -416,11 +405,12 @@ zfs_unmount(zfs_handle_t *zhp, const char *mountpoint, int flags)
|
||||
if (zfs_unshare_proto(zhp, mntpt, share_all_proto) != 0)
|
||||
return (-1);
|
||||
|
||||
if (unmount_one(zhp->zfs_hdl, mntpt, flags) != 0) {
|
||||
if (unmount_one(hdl, mntpt, flags) != 0) {
|
||||
free(mntpt);
|
||||
(void) zfs_shareall(zhp);
|
||||
return (-1);
|
||||
}
|
||||
libzfs_mnttab_remove(hdl, zhp->zfs_name);
|
||||
free(mntpt);
|
||||
}
|
||||
|
||||
@@ -849,7 +839,7 @@ unshare_one(libzfs_handle_t *hdl, const char *name, const char *mountpoint,
|
||||
char *mntpt;
|
||||
/*
|
||||
* Mountpoint could get trashed if libshare calls getmntany
|
||||
* which id does during API initialization, so strdup the
|
||||
* which it does during API initialization, so strdup the
|
||||
* value.
|
||||
*/
|
||||
mntpt = zfs_strdup(hdl, mountpoint);
|
||||
@@ -887,18 +877,17 @@ int
|
||||
zfs_unshare_proto(zfs_handle_t *zhp, const char *mountpoint,
|
||||
zfs_share_proto_t *proto)
|
||||
{
|
||||
struct mnttab search = { 0 }, entry;
|
||||
libzfs_handle_t *hdl = zhp->zfs_hdl;
|
||||
struct mnttab entry;
|
||||
char *mntpt = NULL;
|
||||
|
||||
/* check to see if need to unmount the filesystem */
|
||||
search.mnt_special = (char *)zfs_get_name(zhp);
|
||||
search.mnt_fstype = MNTTYPE_ZFS;
|
||||
rewind(zhp->zfs_hdl->libzfs_mnttab);
|
||||
if (mountpoint != NULL)
|
||||
mntpt = zfs_strdup(zhp->zfs_hdl, mountpoint);
|
||||
mountpoint = mntpt = zfs_strdup(hdl, mountpoint);
|
||||
|
||||
if (mountpoint != NULL || ((zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) &&
|
||||
getmntany(zhp->zfs_hdl->libzfs_mnttab, &entry, &search) == 0)) {
|
||||
libzfs_mnttab_find(hdl, zfs_get_name(zhp), &entry) == 0)) {
|
||||
zfs_share_proto_t *curr_proto;
|
||||
|
||||
if (mountpoint == NULL)
|
||||
@@ -907,8 +896,8 @@ zfs_unshare_proto(zfs_handle_t *zhp, const char *mountpoint,
|
||||
for (curr_proto = proto; *curr_proto != PROTO_END;
|
||||
curr_proto++) {
|
||||
|
||||
if (is_shared(zhp->zfs_hdl, mntpt, *curr_proto) &&
|
||||
unshare_one(zhp->zfs_hdl, zhp->zfs_name,
|
||||
if (is_shared(hdl, mntpt, *curr_proto) &&
|
||||
unshare_one(hdl, zhp->zfs_name,
|
||||
mntpt, *curr_proto) != 0) {
|
||||
if (mntpt != NULL)
|
||||
free(mntpt);
|
||||
|
||||
@@ -1127,7 +1127,7 @@ zpool_add(zpool_handle_t *zhp, nvlist_t *nvroot)
|
||||
* mounted datasets in the pool.
|
||||
*/
|
||||
int
|
||||
zpool_export(zpool_handle_t *zhp, boolean_t force)
|
||||
zpool_export_common(zpool_handle_t *zhp, boolean_t force, boolean_t hardforce)
|
||||
{
|
||||
zfs_cmd_t zc = { 0 };
|
||||
char msg[1024];
|
||||
@@ -1140,6 +1140,7 @@ zpool_export(zpool_handle_t *zhp, boolean_t force)
|
||||
|
||||
(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
|
||||
zc.zc_cookie = force;
|
||||
zc.zc_guid = hardforce;
|
||||
|
||||
if (zfs_ioctl(zhp->zpool_hdl, ZFS_IOC_POOL_EXPORT, &zc) != 0) {
|
||||
switch (errno) {
|
||||
@@ -1160,6 +1161,18 @@ zpool_export(zpool_handle_t *zhp, boolean_t force)
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
zpool_export(zpool_handle_t *zhp, boolean_t force)
|
||||
{
|
||||
return (zpool_export_common(zhp, force, B_FALSE));
|
||||
}
|
||||
|
||||
int
|
||||
zpool_export_force(zpool_handle_t *zhp)
|
||||
{
|
||||
return (zpool_export_common(zhp, B_TRUE, B_TRUE));
|
||||
}
|
||||
|
||||
/*
|
||||
* zpool_import() is a contracted interface. Should be kept the same
|
||||
* if possible.
|
||||
@@ -1182,7 +1195,9 @@ zpool_import(libzfs_handle_t *hdl, nvlist_t *config, const char *newname,
|
||||
}
|
||||
|
||||
if (nvlist_add_string(props,
|
||||
zpool_prop_to_name(ZPOOL_PROP_ALTROOT), altroot) != 0) {
|
||||
zpool_prop_to_name(ZPOOL_PROP_ALTROOT), altroot) != 0 ||
|
||||
nvlist_add_string(props,
|
||||
zpool_prop_to_name(ZPOOL_PROP_CACHEFILE), "none") != 0) {
|
||||
nvlist_free(props);
|
||||
return (zfs_error_fmt(hdl, EZFS_NOMEM,
|
||||
dgettext(TEXT_DOMAIN, "cannot import '%s'"),
|
||||
|
||||
@@ -796,6 +796,10 @@ zprop_print_headers(zprop_get_cbdata_t *cbp, zfs_type_t type)
|
||||
cbp->cb_colwidths[GET_COL_SOURCE] = strlen(dgettext(TEXT_DOMAIN,
|
||||
"SOURCE"));
|
||||
|
||||
/* first property is always NAME */
|
||||
assert(cbp->cb_proplist->pl_prop ==
|
||||
((type == ZFS_TYPE_POOL) ? ZPOOL_PROP_NAME : ZFS_PROP_NAME));
|
||||
|
||||
/*
|
||||
* Go through and calculate the widths for each column. For the
|
||||
* 'source' column, we kludge it up by taking the worst-case scenario of
|
||||
@@ -823,9 +827,13 @@ zprop_print_headers(zprop_get_cbdata_t *cbp, zfs_type_t type)
|
||||
}
|
||||
|
||||
/*
|
||||
* 'VALUE' column
|
||||
* 'VALUE' column. The first property is always the 'name'
|
||||
* property that was tacked on either by /sbin/zfs's
|
||||
* zfs_do_get() or when calling zprop_expand_list(), so we
|
||||
* ignore its width. If the user specified the name property
|
||||
* to display, then it will be later in the list in any case.
|
||||
*/
|
||||
if ((pl->pl_prop != ZFS_PROP_NAME || !pl->pl_all) &&
|
||||
if (pl != cbp->cb_proplist &&
|
||||
pl->pl_width > cbp->cb_colwidths[GET_COL_VALUE])
|
||||
cbp->cb_colwidths[GET_COL_VALUE] = pl->pl_width;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user