David Gwynne
2008-Oct-01 05:59 UTC
[zfs-discuss] make zfs(1M) use literals when displaying properties in scripted mode
as the topic says, this uses literals when the zfs command is asked to list stuff in script mode (ie, zfs list -H). this is useful if you want the sizes of things in raw values. i have no onnv systems to build this on, so i am unable to demonstrate this, but i would really like to see this (or something like this) integrated. alternatively i could add a new flag to zfs list that toggles this behaviour. comments? suggestions? diff -r fb422f16cbd0 usr/src/cmd/zfs/zfs_main.c --- a/usr/src/cmd/zfs/zfs_main.c Tue Sep 30 14:29:46 2008 -0700 +++ b/usr/src/cmd/zfs/zfs_main.c Wed Oct 01 10:57:27 2008 +1000 @@ -1695,7 +1695,7 @@ right_justify = B_FALSE; if (pl->pl_prop != ZPROP_INVAL) { if (zfs_prop_get(zhp, pl->pl_prop, property, - sizeof (property), NULL, NULL, 0, B_FALSE) != 0) + sizeof (property), NULL, NULL, 0, scripted) != 0) propstr = "-"; else propstr = property;
Eric Schrock
2008-Oct-01 06:09 UTC
[zfs-discuss] make zfs(1M) use literals when displaying properties in scripted mode
A better solution (one that wouldn''t break backwards compatability) would be to add the ''-p'' option (parseable output) from ''zfs get'' to the ''zfs list'' command as well. - Eric On Wed, Oct 01, 2008 at 03:59:27PM +1000, David Gwynne wrote:> as the topic says, this uses literals when the zfs command is asked > to list stuff in script mode (ie, zfs list -H). this is useful if > you want the sizes of things in raw values. > > i have no onnv systems to build this on, so i am unable to demonstrate > this, but i would really like to see this (or something like this) > integrated. > > alternatively i could add a new flag to zfs list that toggles this > behaviour. > > comments? suggestions? > > diff -r fb422f16cbd0 usr/src/cmd/zfs/zfs_main.c > --- a/usr/src/cmd/zfs/zfs_main.c Tue Sep 30 14:29:46 2008 -0700 > +++ b/usr/src/cmd/zfs/zfs_main.c Wed Oct 01 10:57:27 2008 +1000 > @@ -1695,7 +1695,7 @@ > right_justify = B_FALSE; > if (pl->pl_prop != ZPROP_INVAL) { > if (zfs_prop_get(zhp, pl->pl_prop, property, > - sizeof (property), NULL, NULL, 0, B_FALSE) != 0) > + sizeof (property), NULL, NULL, 0, scripted) != 0) > propstr = "-"; > else > propstr = property; > _______________________________________________ > zfs-discuss mailing list > zfs-discuss at opensolaris.org > http://mail.opensolaris.org/mailman/listinfo/zfs-discuss-- Eric Schrock, Fishworks http://blogs.sun.com/eschrock
David Gwynne
2008-Oct-01 21:50 UTC
[zfs-discuss] make zfs(1M) use literals when displaying properties in scripted mode
On Tue, Sep 30, 2008 at 11:09:05PM -0700, Eric Schrock wrote:> A better solution (one that wouldn''t break backwards compatability) > would be to add the ''-p'' option (parseable output) from ''zfs get'' to the > ''zfs list'' command as well.yes, that makes sense to me. thanks for pointing the -p out in zfs get, it means i get get the numbers i need on s10 without having to do crazy stuff to get a custom zfs binary. here''s an updated diff that implements -p on zfs list. thanks to james mcpherson for both fixing and testing this for me. diff -r 4fa3bfcd83d7 -r dbe864e2cc70 usr/src/cmd/zfs/zfs_main.c --- a/usr/src/cmd/zfs/zfs_main.c Wed Oct 01 00:06:47 2008 -0700 +++ b/usr/src/cmd/zfs/zfs_main.c Thu Oct 02 07:26:16 2008 +1000 @@ -1623,6 +1623,7 @@ typedef struct list_cbdata { boolean_t cb_first; boolean_t cb_scripted; + boolean_t cb_literal; zprop_list_t *cb_proplist; } list_cbdata_t; @@ -1672,7 +1673,8 @@ * to the described layout. */ static void -print_dataset(zfs_handle_t *zhp, zprop_list_t *pl, boolean_t scripted) +print_dataset(zfs_handle_t *zhp, zprop_list_t *pl, boolean_t scripted, + boolean_t literal) { boolean_t first = B_TRUE; char property[ZFS_MAXPROPLEN]; @@ -1695,7 +1697,7 @@ right_justify = B_FALSE; if (pl->pl_prop != ZPROP_INVAL) { if (zfs_prop_get(zhp, pl->pl_prop, property, - sizeof (property), NULL, NULL, 0, B_FALSE) != 0) + sizeof (property), NULL, NULL, 0, literal) != 0) propstr = "-"; else propstr = property; @@ -1742,7 +1744,7 @@ cbp->cb_first = B_FALSE; } - print_dataset(zhp, cbp->cb_proplist, cbp->cb_scripted); + print_dataset(zhp, cbp->cb_proplist, cbp->cb_scripted, cbp->cb_literal); return (0); } @@ -1752,6 +1754,7 @@ { int c; boolean_t scripted = B_FALSE; + boolean_t literal = B_FALSE; static char default_fields[] "name,used,available,referenced,mountpoint"; int types = ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME; @@ -1764,10 +1767,13 @@ int flags = ZFS_ITER_PROP_LISTSNAPS | ZFS_ITER_ARGS_CAN_BE_PATHS; /* check options */ - while ((c = getopt(argc, argv, ":o:rt:Hs:S:")) != -1) { + while ((c = getopt(argc, argv, ":o:prt:Hs:S:")) != -1) { switch (c) { case ''o'': fields = optarg; + break; + case ''p'': + literal = B_TRUE; break; case ''r'': flags |= ZFS_ITER_RECURSE; @@ -1855,6 +1861,7 @@ != 0) usage(B_FALSE); + cb.cb_literal = literal; cb.cb_scripted = scripted; cb.cb_first = B_TRUE;