@@ -242,7 +242,7 @@ get_usage(zpool_help_t idx) {
242
242
case HELP_LABELCLEAR :
243
243
return (gettext ("\tlabelclear [-f] <vdev>\n" ));
244
244
case HELP_LIST :
245
- return (gettext ("\tlist [-gHLPv ] [-o property[,...]] "
245
+ return (gettext ("\tlist [-gHLpPv ] [-o property[,...]] "
246
246
"[-T d|u] [pool] ... [interval [count]]\n" ));
247
247
case HELP_OFFLINE :
248
248
return (gettext ("\toffline [-t] <pool> <device> ...\n" ));
@@ -267,8 +267,8 @@ get_usage(zpool_help_t idx) {
267
267
case HELP_EVENTS :
268
268
return (gettext ("\tevents [-vHfc]\n" ));
269
269
case HELP_GET :
270
- return (gettext ("\tget [-pH] < \"all\" | property [,...]> "
271
- "<pool> ...\n" ));
270
+ return (gettext ("\tget [-Hp] [-o \"all\" | field [,...]] "
271
+ "<\"all\" | property[,...]> < pool> ...\n" ));
272
272
case HELP_SET :
273
273
return (gettext ("\tset <property=value> <pool> \n" ));
274
274
case HELP_SPLIT :
@@ -3024,6 +3024,7 @@ typedef struct list_cbdata {
3024
3024
int cb_namewidth ;
3025
3025
boolean_t cb_scripted ;
3026
3026
zprop_list_t * cb_proplist ;
3027
+ boolean_t cb_literal ;
3027
3028
} list_cbdata_t ;
3028
3029
3029
3030
/*
@@ -3115,7 +3116,7 @@ print_pool(zpool_handle_t *zhp, list_cbdata_t *cb)
3115
3116
right_justify = B_FALSE ;
3116
3117
if (pl -> pl_prop != ZPROP_INVAL ) {
3117
3118
if (zpool_get_prop (zhp , pl -> pl_prop , property ,
3118
- sizeof (property ), NULL ) != 0 )
3119
+ sizeof (property ), NULL , cb -> cb_literal ) != 0 )
3119
3120
propstr = "-" ;
3120
3121
else
3121
3122
propstr = property ;
@@ -3325,7 +3326,7 @@ list_callback(zpool_handle_t *zhp, void *data)
3325
3326
}
3326
3327
3327
3328
/*
3328
- * zpool list [-gHLP ] [-o prop[,prop]*] [-T d|u] [pool] ... [interval [count]]
3329
+ * zpool list [-gHLpP ] [-o prop[,prop]*] [-T d|u] [pool] ... [interval [count]]
3329
3330
*
3330
3331
* -g Display guid for individual vdev name.
3331
3332
* -H Scripted mode. Don't display headers, and separate properties
@@ -3334,6 +3335,7 @@ list_callback(zpool_handle_t *zhp, void *data)
3334
3335
* -o List of properties to display. Defaults to
3335
3336
* "name,size,allocated,free,expandsize,fragmentation,capacity,"
3336
3337
* "dedupratio,health,altroot"
3338
+ * -p Display values in parsable (exact) format.
3337
3339
* -P Display full path for vdev name.
3338
3340
* -T Display a timestamp in date(1) or Unix format
3339
3341
*
@@ -3355,7 +3357,7 @@ zpool_do_list(int argc, char **argv)
3355
3357
boolean_t first = B_TRUE ;
3356
3358
3357
3359
/* check options */
3358
- while ((c = getopt (argc , argv , ":gHLo:PT :v" )) != -1 ) {
3360
+ while ((c = getopt (argc , argv , ":gHLo:pPT :v" )) != -1 ) {
3359
3361
switch (c ) {
3360
3362
case 'g' :
3361
3363
cb .cb_name_flags |= VDEV_NAME_GUID ;
@@ -3372,6 +3374,9 @@ zpool_do_list(int argc, char **argv)
3372
3374
case 'P' :
3373
3375
cb .cb_name_flags |= VDEV_NAME_PATH ;
3374
3376
break ;
3377
+ case 'p' :
3378
+ cb .cb_literal = B_TRUE ;
3379
+ break ;
3375
3380
case 'T' :
3376
3381
get_timestamp_arg (* optarg );
3377
3382
break ;
@@ -5886,7 +5891,7 @@ get_callback(zpool_handle_t *zhp, void *data)
5886
5891
NULL , NULL );
5887
5892
}
5888
5893
} else {
5889
- if (zpool_get_prop_literal (zhp , pl -> pl_prop , value ,
5894
+ if (zpool_get_prop (zhp , pl -> pl_prop , value ,
5890
5895
sizeof (value ), & srctype , cbp -> cb_literal ) != 0 )
5891
5896
continue ;
5892
5897
@@ -5898,24 +5903,99 @@ get_callback(zpool_handle_t *zhp, void *data)
5898
5903
return (0 );
5899
5904
}
5900
5905
5906
+ /*
5907
+ * zpool get [-Hp] [-o "all" | field[,...]] <"all" | property[,...]> <pool> ...
5908
+ *
5909
+ * -H Scripted mode. Don't display headers, and separate properties
5910
+ * by a single tab.
5911
+ * -o List of columns to display. Defaults to
5912
+ * "name,property,value,source".
5913
+ * -p Diplay values in parsable (exact) format.
5914
+ *
5915
+ * Get properties of pools in the system. Output space statistics
5916
+ * for each one as well as other attributes.
5917
+ */
5901
5918
int
5902
5919
zpool_do_get (int argc , char * * argv )
5903
5920
{
5904
5921
zprop_get_cbdata_t cb = { 0 };
5905
5922
zprop_list_t fake_name = { 0 };
5906
- int c , ret ;
5923
+ int ret ;
5924
+ int c , i ;
5925
+ char * value ;
5926
+
5927
+ cb .cb_first = B_TRUE ;
5928
+
5929
+ /*
5930
+ * Set up default columns and sources.
5931
+ */
5932
+ cb .cb_sources = ZPROP_SRC_ALL ;
5933
+ cb .cb_columns [0 ] = GET_COL_NAME ;
5934
+ cb .cb_columns [1 ] = GET_COL_PROPERTY ;
5935
+ cb .cb_columns [2 ] = GET_COL_VALUE ;
5936
+ cb .cb_columns [3 ] = GET_COL_SOURCE ;
5937
+ cb .cb_type = ZFS_TYPE_POOL ;
5907
5938
5908
5939
/* check options */
5909
- while ((c = getopt (argc , argv , "pH " )) != -1 ) {
5940
+ while ((c = getopt (argc , argv , ":Hpo: " )) != -1 ) {
5910
5941
switch (c ) {
5911
5942
case 'p' :
5912
5943
cb .cb_literal = B_TRUE ;
5913
5944
break ;
5914
-
5915
5945
case 'H' :
5916
5946
cb .cb_scripted = B_TRUE ;
5917
5947
break ;
5948
+ case 'o' :
5949
+ bzero (& cb .cb_columns , sizeof (cb .cb_columns ));
5950
+ i = 0 ;
5951
+ while (* optarg != '\0' ) {
5952
+ static char * col_subopts [] =
5953
+ { "name" , "property" , "value" , "source" ,
5954
+ "all" , NULL };
5955
+
5956
+ if (i == ZFS_GET_NCOLS ) {
5957
+ (void ) fprintf (stderr , gettext ("too "
5958
+ "many fields given to -o "
5959
+ "option\n" ));
5960
+ usage (B_FALSE );
5961
+ }
5918
5962
5963
+ switch (getsubopt (& optarg , col_subopts ,
5964
+ & value )) {
5965
+ case 0 :
5966
+ cb .cb_columns [i ++ ] = GET_COL_NAME ;
5967
+ break ;
5968
+ case 1 :
5969
+ cb .cb_columns [i ++ ] = GET_COL_PROPERTY ;
5970
+ break ;
5971
+ case 2 :
5972
+ cb .cb_columns [i ++ ] = GET_COL_VALUE ;
5973
+ break ;
5974
+ case 3 :
5975
+ cb .cb_columns [i ++ ] = GET_COL_SOURCE ;
5976
+ break ;
5977
+ case 4 :
5978
+ if (i > 0 ) {
5979
+ (void ) fprintf (stderr ,
5980
+ gettext ("\"all\" conflicts "
5981
+ "with specific fields "
5982
+ "given to -o option\n" ));
5983
+ usage (B_FALSE );
5984
+ }
5985
+ cb .cb_columns [0 ] = GET_COL_NAME ;
5986
+ cb .cb_columns [1 ] = GET_COL_PROPERTY ;
5987
+ cb .cb_columns [2 ] = GET_COL_VALUE ;
5988
+ cb .cb_columns [3 ] = GET_COL_SOURCE ;
5989
+ i = ZFS_GET_NCOLS ;
5990
+ break ;
5991
+ default :
5992
+ (void ) fprintf (stderr ,
5993
+ gettext ("invalid column name "
5994
+ "'%s'\n" ), value );
5995
+ usage (B_FALSE );
5996
+ }
5997
+ }
5998
+ break ;
5919
5999
case '?' :
5920
6000
(void ) fprintf (stderr , gettext ("invalid option '%c'\n" ),
5921
6001
optopt );
@@ -5932,15 +6012,8 @@ zpool_do_get(int argc, char **argv)
5932
6012
usage (B_FALSE );
5933
6013
}
5934
6014
5935
- cb .cb_first = B_TRUE ;
5936
- cb .cb_sources = ZPROP_SRC_ALL ;
5937
- cb .cb_columns [0 ] = GET_COL_NAME ;
5938
- cb .cb_columns [1 ] = GET_COL_PROPERTY ;
5939
- cb .cb_columns [2 ] = GET_COL_VALUE ;
5940
- cb .cb_columns [3 ] = GET_COL_SOURCE ;
5941
- cb .cb_type = ZFS_TYPE_POOL ;
5942
-
5943
- if (zprop_get_list (g_zfs , argv [0 ], & cb .cb_proplist , ZFS_TYPE_POOL ) != 0 )
6015
+ if (zprop_get_list (g_zfs , argv [0 ], & cb .cb_proplist ,
6016
+ ZFS_TYPE_POOL ) != 0 )
5944
6017
usage (B_FALSE );
5945
6018
5946
6019
argc -- ;
0 commit comments