Skip to content

New stable API (For Initial Review) #3299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions cmd/zfs/zfs_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ zfs_for_each(int argc, char **argv, int flags, zfs_type_t types,
int ret = 0;
zfs_node_t *node;
uu_avl_walk_t *walk;
zfs_type_t argtype;

avl_pool = uu_avl_pool_create("zfs_pool", sizeof (zfs_node_t),
offsetof(zfs_node_t, zn_avlnode), zfs_sort, UU_DEFAULT);
Expand All @@ -386,7 +387,11 @@ zfs_for_each(int argc, char **argv, int flags, zfs_type_t types,
nomem();

cb.cb_sortcol = sortcol;
cb.cb_flags = flags;
/*
* XXX: We are phasing out the legacy recursive interface in
* favor of the new stable list API.
*/
cb.cb_flags = flags & ~ZFS_ITER_RECURSE;
cb.cb_proplist = proplist;
cb.cb_types = types;
cb.cb_depth_limit = limit;
Expand Down Expand Up @@ -431,27 +436,29 @@ zfs_for_each(int argc, char **argv, int flags, zfs_type_t types,
if ((cb.cb_avl = uu_avl_create(avl_pool, NULL, UU_DEFAULT)) == NULL)
nomem();

/*
* zfs_iter_generic() lets the kernel worry about default types.
*/
argtype = types * !!(flags & ZFS_ITER_TYPES_SPECIFIED);
if (argc == 0) {
/*
* If given no arguments, iterate over all datasets.
*/
cb.cb_flags |= ZFS_ITER_RECURSE;
ret = zfs_iter_root(g_zfs, zfs_callback, &cb);
ret = zfs_iter_generic(g_zfs, NULL, argtype, (flags &
ZFS_ITER_DEPTH_LIMIT) ? limit : -1, zfs_callback, &cb);
} else {
int i;
zfs_handle_t *zhp;
zfs_type_t argtype;

/*
* If we're recursive, then we always allow filesystems as
* arguments. If we also are interested in snapshots, then we
* can take volumes as well.
*/
argtype = types;
if (flags & ZFS_ITER_RECURSE) {
argtype |= ZFS_TYPE_FILESYSTEM;
if (types & ZFS_TYPE_SNAPSHOT)
argtype |= ZFS_TYPE_VOLUME;
argtype |= ZFS_TYPE_VOLUME | ZFS_TYPE_SNAPSHOT;
}

for (i = 0; i < argc; i++) {
Expand All @@ -462,7 +469,10 @@ zfs_for_each(int argc, char **argv, int flags, zfs_type_t types,
zhp = zfs_open(g_zfs, argv[i], argtype);
}
if (zhp != NULL)
ret |= zfs_callback(zhp, &cb);
ret |= zfs_iter_generic(zfs_get_handle(zhp),
zfs_get_name(zhp), argtype, (flags &
ZFS_ITER_DEPTH_LIMIT) ? limit : -1,
zfs_callback, &cb);
else
ret = 1;
}
Expand Down
1 change: 1 addition & 0 deletions cmd/zfs/zfs_iter.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ typedef struct zfs_sort_column {
#define ZFS_ITER_RECVD_PROPS (1 << 4)
#define ZFS_ITER_LITERAL_PROPS (1 << 5)
#define ZFS_ITER_SIMPLE (1 << 6)
#define ZFS_ITER_TYPES_SPECIFIED (1 << 7)

int zfs_for_each(int, char **, int options, zfs_type_t,
zfs_sort_column_t *, zprop_list_t **, int, zfs_iter_f, void *);
Expand Down
10 changes: 4 additions & 6 deletions cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,7 @@ zfs_do_get(int argc, char **argv)

case 't':
types = 0;
flags &= ~ZFS_ITER_PROP_LISTSNAPS;
flags |= ZFS_ITER_TYPES_SPECIFIED;
while (*optarg != '\0') {
static char *type_subopts[] = { "filesystem",
"volume", "snapshot", "bookmark",
Expand Down Expand Up @@ -3034,14 +3034,13 @@ zfs_do_list(int argc, char **argv)
static char default_fields[] =
"name,used,available,referenced,mountpoint";
int types = ZFS_TYPE_DATASET;
boolean_t types_specified = B_FALSE;
char *fields = NULL;
list_cbdata_t cb = { 0 };
char *value;
int limit = 0;
int ret = 0;
zfs_sort_column_t *sortcol = NULL;
int flags = ZFS_ITER_PROP_LISTSNAPS | ZFS_ITER_ARGS_CAN_BE_PATHS;
int flags = ZFS_ITER_ARGS_CAN_BE_PATHS;

/* check options */
while ((c = getopt(argc, argv, "HS:d:o:prs:t:")) != -1) {
Expand Down Expand Up @@ -3080,8 +3079,7 @@ zfs_do_list(int argc, char **argv)
break;
case 't':
types = 0;
types_specified = B_TRUE;
flags &= ~ZFS_ITER_PROP_LISTSNAPS;
flags |= ZFS_ITER_TYPES_SPECIFIED;
while (*optarg != '\0') {
static char *type_subopts[] = { "filesystem",
"volume", "snapshot", "snap", "bookmark",
Expand Down Expand Up @@ -3142,7 +3140,7 @@ zfs_do_list(int argc, char **argv)
/*
* If "-o space" and no types were specified, don't display snapshots.
*/
if (strcmp(fields, "space") == 0 && types_specified == B_FALSE)
if (strcmp(fields, "space") == 0 && (flags & ZFS_ITER_TYPES_SPECIFIED))
types &= ~ZFS_TYPE_SNAPSHOT;

/*
Expand Down
2 changes: 2 additions & 0 deletions include/libzfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ void zprop_print_one_property(const char *, zprop_get_cbdata_t *,
* Iterator functions.
*/
typedef int (*zfs_iter_f)(zfs_handle_t *, void *);
extern int zfs_iter_generic(libzfs_handle_t *, const char *, zfs_type_t,
int64_t, zfs_iter_f, void *);
extern int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *);
extern int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *);
extern int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f, void *);
Expand Down
10 changes: 10 additions & 0 deletions include/libzfs_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ extern "C" {
int libzfs_core_init(void);
void libzfs_core_fini(void);

int lzc_list (const char *, int, nvlist_t *);
int lzc_snapshot(nvlist_t *, nvlist_t *, nvlist_t **);
int lzc_create(const char *, dmu_objset_type_t, nvlist_t *);
int lzc_clone(const char *, const char *, nvlist_t *);
int lzc_promote(const char *);
int lzc_set_props(const char *, nvlist_t *, boolean_t);
int lzc_destroy_one(const char *, nvlist_t *);
int lzc_destroy_snaps(nvlist_t *, boolean_t, nvlist_t **);
int lzc_bookmark(nvlist_t *, nvlist_t **);
int lzc_get_bookmarks(const char *, nvlist_t *, nvlist_t **);
Expand All @@ -52,13 +56,19 @@ int lzc_hold(nvlist_t *, int, nvlist_t **);
int lzc_release(nvlist_t *, nvlist_t **);
int lzc_get_holds(const char *, nvlist_t **);

int lzc_inherit(const char *fsname, const char *propname, nvlist_t *opts);
int lzc_rename(const char *oldname, const char *newname, nvlist_t *opts,
char **errname);

enum lzc_send_flags {
LZC_SEND_FLAG_EMBED_DATA = 1 << 0
};

int lzc_send(const char *, const char *, int, enum lzc_send_flags);
int lzc_send_ext(const char *, const char *, int, nvlist_t *);
int lzc_receive(const char *, nvlist_t *, const char *, boolean_t, int);
int lzc_send_space(const char *, const char *, uint64_t *);
int lzc_send_progress(const char *, int, uint64_t *);

boolean_t lzc_exists(const char *);

Expand Down
4 changes: 2 additions & 2 deletions include/sys/dmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ int dsl_destroy_snapshots_nvl(struct nvlist *snaps, boolean_t defer,
struct nvlist *errlist);
int dmu_objset_snapshot_one(const char *fsname, const char *snapname);
int dmu_objset_snapshot_tmp(const char *, const char *, int);
int dmu_objset_find(char *name, int func(const char *, void *), void *arg,
int flags);
int dmu_objset_find(const char *name, int func(const char *, void *),
void *arg, int flags);
void dmu_objset_byteswap(void *buf, size_t size);
int dsl_dataset_rename_snapshot(const char *fsname,
const char *oldsnapname, const char *newsnapname, boolean_t recursive);
Expand Down
10 changes: 10 additions & 0 deletions include/sys/dmu_objset.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ void dmu_objset_fast_stat(objset_t *os, dmu_objset_stats_t *stat);
void dmu_objset_space(objset_t *os, uint64_t *refdbytesp, uint64_t *availbytesp,
uint64_t *usedobjsp, uint64_t *availobjsp);
uint64_t dmu_objset_fsid_guid(objset_t *os);
int dmu_objset_find_dp_impl(struct dsl_pool *dp, uint64_t ddobj,
int func(struct dsl_pool *, struct dsl_dataset *, void *),
void *arg, int flags, unsigned int depth);
int dmu_objset_find_dp(struct dsl_pool *dp, uint64_t ddobj,
int func(struct dsl_pool *, struct dsl_dataset *, void *),
void *arg, int flags);
Expand All @@ -168,6 +171,13 @@ int dmu_objset_userspace_upgrade(objset_t *os);
boolean_t dmu_objset_userspace_present(objset_t *os);
int dmu_fsname(const char *snapname, char *buf);

/* Code for handling userspace interface */
extern const char *dmu_objset_types[];

const char *dmu_objset_type_name(dmu_objset_type_t type);
nvlist_t *dmu_objset_stats_nvlist(dmu_objset_stats_t *stat);
int dmu_objset_stat_nvlts (nvlist_t *nvl, dmu_objset_stats_t *stat);

void dmu_objset_init(void);
void dmu_objset_fini(void);

Expand Down
2 changes: 1 addition & 1 deletion include/sys/dmu_send.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct drr_begin;
struct avl_tree;

int dmu_send(const char *tosnap, const char *fromsnap, boolean_t embedok,
int outfd, struct vnode *vp, offset_t *off);
boolean_t fromorigin, int outfd, struct vnode *vp, offset_t *off);
int dmu_send_estimate(struct dsl_dataset *ds, struct dsl_dataset *fromds,
uint64_t *sizep);
int dmu_send_obj(const char *pool, uint64_t tosnap, uint64_t fromsnap,
Expand Down
1 change: 1 addition & 0 deletions include/sys/dsl_prop.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ int dsl_prop_get(const char *ddname, const char *propname,
int dsl_prop_get_integer(const char *ddname, const char *propname,
uint64_t *valuep, char *setpoint);
int dsl_prop_get_all(objset_t *os, nvlist_t **nvp);
int dsl_prop_get_all_new(objset_t *os, nvlist_t **nvp);
int dsl_prop_get_received(const char *dsname, nvlist_t **nvp);
int dsl_prop_get_ds(struct dsl_dataset *ds, const char *propname,
int intsz, int numints, void *buf, char *setpoint);
Expand Down
5 changes: 5 additions & 0 deletions include/sys/fs/zfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,11 @@ typedef enum zfs_ioc {
*/
ZFS_IOC_FREEBSD = ('Z' << 8) + 0xC0,

/*
* OpenZFS - 1/64 numbers reserved.
*/
ZFS_IOC_OPENZFS = ('Z' << 8) + 0x100,
ZFS_IOC_LIBZFS_CORE,
ZFS_IOC_LAST
} zfs_ioc_t;

Expand Down
8 changes: 8 additions & 0 deletions include/sys/zfs_ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,14 @@ typedef struct zfs_cmd {
zfs_stat_t zc_stat;
} zfs_cmd_t;

typedef struct zfs_pipe_record {
uint32_t zpr_data_size; /* Payload size */
uint8_t zpr_header_size; /* Extension space after 8 bytes */
uint8_t zpr_err; /* Return code */
uint8_t zpr_endian; /* Endian bit: 0 is BE, 1 is LE */
uint8_t zpr_reserved; /* Reserved space */
} zfs_pipe_record_t;

typedef struct zfs_useracct {
char zu_domain[256];
uid_t zu_rid;
Expand Down
Loading