Skip to content
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

json implemented in zfs CLI #3938

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 9 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ Native ZFS for Linux!
ZFS is an advanced file system and volume manager which was originally
developed for Solaris and is now maintained by the Illumos community.

ZFS on Linux, which is also known as ZoL, is currently feature complete. It
includes fully functional and stable SPA, DMU, ZVOL, and ZPL layers.
ZFS on Linux,which is also known as ZoL,is currently feature complete. It includes fully functional and stable SPA,DMU,ZVOL,and ZPL layers.

Full documentation for installing ZoL on your favorite Linux distribution can
be found at: <http://zfsonlinux.org>

#### Full status (community validation and code implemented) is availlable here :

[STATUS](https://github.com/Alyseo/zfs/blob/json-0.6.4/json/STATUS.md)

### json schemas description :

[README](https://github.com/Alyseo/zfs/blob/json-0.6.4/json/README.md)
12 changes: 6 additions & 6 deletions cmd/mount_zfs/mount_zfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ zfs_selinux_setcontext(zfs_handle_t *zhp, zfs_prop_t zpt, const char *name,
{
char context[ZFS_MAXPROPLEN];

if (zfs_prop_get(zhp, zpt, context, sizeof (context),
if (zfs_prop_get(NULL, zhp, zpt, context, sizeof (context),
NULL, NULL, 0, B_FALSE) == 0) {
if (strcmp(context, "none") != 0)
append_mntopt(name, context, mntopts, mtabopt, B_TRUE);
Expand Down Expand Up @@ -492,7 +492,7 @@ main(int argc, char **argv)
}

/* try to open the dataset to access the mount point */
if ((zhp = zfs_open(g_zfs, dataset,
if ((zhp = zfs_open(NULL, g_zfs, dataset,
ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT)) == NULL) {
(void) fprintf(stderr, gettext("filesystem '%s' cannot be "
"mounted, unable to open the dataset\n"), dataset);
Expand All @@ -508,8 +508,8 @@ main(int argc, char **argv)
* this is needed because the 'context' property overrides others
* if it is not the default, set the 'context' property
*/
if (zfs_prop_get(zhp, ZFS_PROP_SELINUX_CONTEXT, prop, sizeof (prop),
NULL, NULL, 0, B_FALSE) == 0) {
if (zfs_prop_get(NULL, zhp, ZFS_PROP_SELINUX_CONTEXT,
prop, sizeof (prop), NULL, NULL, 0, B_FALSE) == 0) {
if (strcmp(prop, "none") == 0) {
zfs_selinux_setcontext(zhp, ZFS_PROP_SELINUX_FSCONTEXT,
MNTOPT_FSCONTEXT, mntopts, mtabopt);
Expand All @@ -531,15 +531,15 @@ main(int argc, char **argv)
if (zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT)
(void) strlcpy(prop, ZFS_MOUNTPOINT_LEGACY, ZFS_MAXPROPLEN);
else
(void) zfs_prop_get(zhp, ZFS_PROP_MOUNTPOINT, prop,
(void) zfs_prop_get(NULL, zhp, ZFS_PROP_MOUNTPOINT, prop,
sizeof (prop), NULL, NULL, 0, B_FALSE);

/*
* Fetch the max supported zfs version in case we get ENOTSUP
* back from the mount command, since we need the zfs handle
* to do so.
*/
zfs_version = zfs_prop_get_int(zhp, ZFS_PROP_VERSION);
zfs_version = zfs_prop_get_int(NULL, zhp, ZFS_PROP_VERSION);
if (zfs_version == 0) {
fprintf(stderr, gettext("unable to fetch "
"ZFS version for filesystem '%s'\n"), dataset);
Expand Down
2 changes: 1 addition & 1 deletion cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -3565,7 +3565,7 @@ find_zpool(char **target, nvlist_t **configp, int dirc, char **dirv)
*sepp = '\0';
}

pools = zpool_search_import(g_zfs, &args);
pools = zpool_search_import(g_zfs, &args, NULL);

if (pools != NULL) {
nvpair_t *elem = NULL;
Expand Down
47 changes: 25 additions & 22 deletions cmd/zfs/zfs_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ zfs_include_snapshots(zfs_handle_t *zhp, callback_data_t *cb)
* add it to the avl tree and recurse over any children as necessary.
*/
static int
zfs_callback(zfs_handle_t *zhp, void *data)
zfs_callback(zfs_handle_t *zhp, void *data, zfs_json_t *json)
{
callback_data_t *cb = data;
boolean_t dontclose = B_FALSE;
Expand Down Expand Up @@ -134,15 +134,17 @@ zfs_callback(zfs_handle_t *zhp, void *data)
cb->cb_depth < cb->cb_depth_limit)) {
cb->cb_depth++;
if (zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM)
(void) zfs_iter_filesystems(zhp, zfs_callback, data);
(void) zfs_iter_filesystems(zhp,
zfs_callback, data, json);
if (((zfs_get_type(zhp) & (ZFS_TYPE_SNAPSHOT |
ZFS_TYPE_BOOKMARK)) == 0) && include_snaps)
(void) zfs_iter_snapshots(zhp,
(cb->cb_flags & ZFS_ITER_SIMPLE) != 0, zfs_callback,
data);
data, json);
if (((zfs_get_type(zhp) & (ZFS_TYPE_SNAPSHOT |
ZFS_TYPE_BOOKMARK)) == 0) && include_bmarks)
(void) zfs_iter_bookmarks(zhp, zfs_callback, data);
(void) zfs_iter_bookmarks(zhp,
zfs_callback, data, json);
cb->cb_depth--;
}

Expand All @@ -154,7 +156,7 @@ zfs_callback(zfs_handle_t *zhp, void *data)

int
zfs_add_sort_column(zfs_sort_column_t **sc, const char *name,
boolean_t reverse)
boolean_t reverse, zfs_json_t *json)
{
zfs_sort_column_t *col;
zfs_prop_t prop;
Expand Down Expand Up @@ -184,7 +186,7 @@ zfs_add_sort_column(zfs_sort_column_t **sc, const char *name,
}

void
zfs_free_sort_columns(zfs_sort_column_t *sc)
zfs_free_sort_columns(zfs_sort_column_t *sc, zfs_json_t *json)
{
zfs_sort_column_t *col;

Expand All @@ -197,7 +199,7 @@ zfs_free_sort_columns(zfs_sort_column_t *sc)
}

int
zfs_sort_only_by_name(const zfs_sort_column_t *sc)
zfs_sort_only_by_name(const zfs_sort_column_t *sc, zfs_json_t *json)
{
return (sc != NULL && sc->sc_next == NULL &&
sc->sc_prop == ZFS_PROP_NAME);
Expand Down Expand Up @@ -240,8 +242,8 @@ zfs_compare(const void *larg, const void *rarg, void *unused)
* use the hidden CREATETXG property to get an absolute
* ordering of snapshots.
*/
lcreate = zfs_prop_get_int(l, ZFS_PROP_CREATETXG);
rcreate = zfs_prop_get_int(r, ZFS_PROP_CREATETXG);
lcreate = zfs_prop_get_int(NULL, l, ZFS_PROP_CREATETXG);
rcreate = zfs_prop_get_int(NULL, r, ZFS_PROP_CREATETXG);

/*
* Both lcreate and rcreate being 0 means we don't have
Expand Down Expand Up @@ -324,9 +326,9 @@ zfs_sort(const void *larg, const void *rarg, void *data)
lstr = lbuf;
rstr = rbuf;
} else if (zfs_prop_is_string(psc->sc_prop)) {
lvalid = (zfs_prop_get(l, psc->sc_prop, lbuf,
lvalid = (zfs_prop_get(NULL, l, psc->sc_prop, lbuf,
sizeof (lbuf), NULL, NULL, 0, B_TRUE) == 0);
rvalid = (zfs_prop_get(r, psc->sc_prop, rbuf,
rvalid = (zfs_prop_get(NULL, r, psc->sc_prop, rbuf,
sizeof (rbuf), NULL, NULL, 0, B_TRUE) == 0);

lstr = lbuf;
Expand All @@ -338,10 +340,12 @@ zfs_sort(const void *larg, const void *rarg, void *data)
zfs_get_type(r), B_FALSE);

if (lvalid)
(void) zfs_prop_get_numeric(l, psc->sc_prop,
(void) zfs_prop_get_numeric(NULL, l,
psc->sc_prop,
&lnum, NULL, NULL, 0);
if (rvalid)
(void) zfs_prop_get_numeric(r, psc->sc_prop,
(void) zfs_prop_get_numeric(NULL, r,
psc->sc_prop,
&rnum, NULL, NULL, 0);
}

Expand Down Expand Up @@ -372,7 +376,7 @@ zfs_sort(const void *larg, const void *rarg, void *data)
int
zfs_for_each(int argc, char **argv, int flags, zfs_type_t types,
zfs_sort_column_t *sortcol, zprop_list_t **proplist, int limit,
zfs_iter_f callback, void *data)
zfs_iter_f callback, void *data, zfs_json_t *json)
{
callback_data_t cb = {0};
int ret = 0;
Expand Down Expand Up @@ -436,7 +440,7 @@ zfs_for_each(int argc, char **argv, int flags, zfs_type_t types,
* 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_root(g_zfs, zfs_callback, &cb, json);
} else {
int i;
zfs_handle_t *zhp;
Expand All @@ -456,13 +460,13 @@ zfs_for_each(int argc, char **argv, int flags, zfs_type_t types,

for (i = 0; i < argc; i++) {
if (flags & ZFS_ITER_ARGS_CAN_BE_PATHS) {
zhp = zfs_path_to_zhandle(g_zfs, argv[i],
zhp = zfs_path_to_zhandle(json, g_zfs, argv[i],
argtype);
} else {
zhp = zfs_open(g_zfs, argv[i], argtype);
}
} else
zhp = zfs_open(json,
g_zfs, argv[i], argtype);
if (zhp != NULL)
ret |= zfs_callback(zhp, &cb);
ret |= zfs_callback(zhp, &cb, json);
else
ret = 1;
}
Expand All @@ -474,8 +478,7 @@ zfs_for_each(int argc, char **argv, int flags, zfs_type_t types,
*/
for (node = uu_avl_first(cb.cb_avl); node != NULL;
node = uu_avl_next(cb.cb_avl, node))
ret |= callback(node->zn_handle, data);

ret |= callback(node->zn_handle, data, json);
/*
* Finally, clean up the AVL tree.
*/
Expand Down
10 changes: 6 additions & 4 deletions cmd/zfs/zfs_iter.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ typedef struct zfs_sort_column {
#define ZFS_ITER_SIMPLE (1 << 6)

int zfs_for_each(int, char **, int options, zfs_type_t,
zfs_sort_column_t *, zprop_list_t **, int, zfs_iter_f, void *);
int zfs_add_sort_column(zfs_sort_column_t **, const char *, boolean_t);
void zfs_free_sort_columns(zfs_sort_column_t *);
int zfs_sort_only_by_name(const zfs_sort_column_t *);
zfs_sort_column_t *, zprop_list_t **,
int, zfs_iter_f, void *, zfs_json_t *json);
int zfs_add_sort_column(zfs_sort_column_t **,
const char *, boolean_t, zfs_json_t *);
void zfs_free_sort_columns(zfs_sort_column_t *, zfs_json_t *);
int zfs_sort_only_by_name(const zfs_sort_column_t *, zfs_json_t *);

#ifdef __cplusplus
}
Expand Down
Loading