Deleted Added
full compact
zfs_main.c (263403) zfs_main.c (263405)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 7 unchanged lines hidden (view full) ---

16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 7 unchanged lines hidden (view full) ---

16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
25 * Copyright (c) 2012 by Delphix. All rights reserved.
26 * Copyright 2012 Milan Jurik. All rights reserved.
27 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
28 * Copyright (c) 2011-2012 Pawel Jakub Dawidek <pawel@dawidek.net>.
29 * All rights reserved.
30 * Copyright (c) 2012 Martin Matuska <mm@FreeBSD.org>. All rights reserved.
31 * Copyright (c) 2013 Steven Hartland. All rights reserved.
24 * Copyright (c) 2012 by Delphix. All rights reserved.
25 * Copyright 2012 Milan Jurik. All rights reserved.
26 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
27 * Copyright (c) 2011-2012 Pawel Jakub Dawidek <pawel@dawidek.net>.
28 * All rights reserved.
29 * Copyright (c) 2012 Martin Matuska <mm@FreeBSD.org>. All rights reserved.
30 * Copyright (c) 2013 Steven Hartland. All rights reserved.
31 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
32 */
33
34#include <assert.h>
35#include <ctype.h>
36#include <errno.h>
37#include <libgen.h>
38#include <libintl.h>
39#include <libuutil.h>

--- 204 unchanged lines hidden (view full) ---

244 case HELP_UPGRADE:
245 return (gettext("\tupgrade [-v]\n"
246 "\tupgrade [-r] [-V version] <-a | filesystem ...>\n"));
247 case HELP_JAIL:
248 return (gettext("\tjail <jailid|jailname> <filesystem>\n"));
249 case HELP_UNJAIL:
250 return (gettext("\tunjail <jailid|jailname> <filesystem>\n"));
251 case HELP_LIST:
32 */
33
34#include <assert.h>
35#include <ctype.h>
36#include <errno.h>
37#include <libgen.h>
38#include <libintl.h>
39#include <libuutil.h>

--- 204 unchanged lines hidden (view full) ---

244 case HELP_UPGRADE:
245 return (gettext("\tupgrade [-v]\n"
246 "\tupgrade [-r] [-V version] <-a | filesystem ...>\n"));
247 case HELP_JAIL:
248 return (gettext("\tjail <jailid|jailname> <filesystem>\n"));
249 case HELP_UNJAIL:
250 return (gettext("\tunjail <jailid|jailname> <filesystem>\n"));
251 case HELP_LIST:
252 return (gettext("\tlist [-rH][-d max] "
253 "[-o property[,...]] [-t type[,...]] [-s property] ...\n"
254 "\t [-S property] ... "
252 return (gettext("\tlist [-Hp] [-r|-d max] [-o property[,...]] "
253 "[-s property]...\n\t [-S property]... [-t type[,...]] "
255 "[filesystem|volume|snapshot] ...\n"));
256 case HELP_MOUNT:
257 return (gettext("\tmount\n"
258 "\tmount [-vO] [-o opts] <-a | filesystem>\n"));
259 case HELP_PROMOTE:
260 return (gettext("\tpromote <clone-filesystem>\n"));
261 case HELP_RECEIVE:
262 return (gettext("\treceive|recv [-vnFu] <filesystem|volume|"

--- 42 unchanged lines hidden (view full) ---

305 "\tunallow [-rld] -e [<perm|@setname>[,...]] "
306 "<filesystem|volume>\n"
307 "\tunallow [-r] -c [<perm|@setname>[,...]] "
308 "<filesystem|volume>\n"
309 "\tunallow [-r] -s @setname [<perm|@setname>[,...]] "
310 "<filesystem|volume>\n"));
311 case HELP_USERSPACE:
312 return (gettext("\tuserspace [-Hinp] [-o field[,...]] "
254 "[filesystem|volume|snapshot] ...\n"));
255 case HELP_MOUNT:
256 return (gettext("\tmount\n"
257 "\tmount [-vO] [-o opts] <-a | filesystem>\n"));
258 case HELP_PROMOTE:
259 return (gettext("\tpromote <clone-filesystem>\n"));
260 case HELP_RECEIVE:
261 return (gettext("\treceive|recv [-vnFu] <filesystem|volume|"

--- 42 unchanged lines hidden (view full) ---

304 "\tunallow [-rld] -e [<perm|@setname>[,...]] "
305 "<filesystem|volume>\n"
306 "\tunallow [-r] -c [<perm|@setname>[,...]] "
307 "<filesystem|volume>\n"
308 "\tunallow [-r] -s @setname [<perm|@setname>[,...]] "
309 "<filesystem|volume>\n"));
310 case HELP_USERSPACE:
311 return (gettext("\tuserspace [-Hinp] [-o field[,...]] "
313 "[-s field] ...\n\t[-S field] ... "
314 "[-t type[,...]] <filesystem|snapshot>\n"));
312 "[-s field]...\n\t [-S field]... [-t type[,...]] "
313 "\n"));
315 case HELP_GROUPSPACE:
316 return (gettext("\tgroupspace [-Hinp] [-o field[,...]] "
314 case HELP_GROUPSPACE:
315 return (gettext("\tgroupspace [-Hinp] [-o field[,...]] "
317 "[-s field] ...\n\t[-S field] ... "
318 "[-t type[,...]] <filesystem|snapshot>\n"));
316 "[-s field]...\n\t [-S field]... [-t type[,...]] "
317 "\n"));
319 case HELP_HOLD:
320 return (gettext("\thold [-r] <tag> <snapshot> ...\n"));
321 case HELP_HOLDS:
322 return (gettext("\tholds [-r] <snapshot> ...\n"));
323 case HELP_RELEASE:
324 return (gettext("\trelease [-r] <tag> <snapshot> ...\n"));
325 case HELP_DIFF:
326 return (gettext("\tdiff [-FHt] <snapshot> "

--- 1792 unchanged lines hidden (view full) ---

2119 * [-S field [-S field]...] [-t type[,...]] filesystem | snapshot
2120 * zfs groupspace [-Hinp] [-o field[,...]] [-s field [-s field]...]
2121 * [-S field [-S field]...] [-t type[,...]] filesystem | snapshot
2122 *
2123 * -H Scripted mode; elide headers and separate columns by tabs.
2124 * -i Translate SID to POSIX ID.
2125 * -n Print numeric ID instead of user/group name.
2126 * -o Control which fields to display.
318 case HELP_HOLD:
319 return (gettext("\thold [-r] <tag> <snapshot> ...\n"));
320 case HELP_HOLDS:
321 return (gettext("\tholds [-r] <snapshot> ...\n"));
322 case HELP_RELEASE:
323 return (gettext("\trelease [-r] <tag> <snapshot> ...\n"));
324 case HELP_DIFF:
325 return (gettext("\tdiff [-FHt] <snapshot> "

--- 1792 unchanged lines hidden (view full) ---

2118 * [-S field [-S field]...] [-t type[,...]] filesystem | snapshot
2119 * zfs groupspace [-Hinp] [-o field[,...]] [-s field [-s field]...]
2120 * [-S field [-S field]...] [-t type[,...]] filesystem | snapshot
2121 *
2122 * -H Scripted mode; elide headers and separate columns by tabs.
2123 * -i Translate SID to POSIX ID.
2124 * -n Print numeric ID instead of user/group name.
2125 * -o Control which fields to display.
2127 * -p Use exact (parseable) numeric output.
2126 * -p Use exact (parsable) numeric output.
2128 * -s Specify sort columns, descending order.
2129 * -S Specify sort columns, ascending order.
2130 * -t Control which object types to display.
2131 *
2132 * Displays space consumed by, and quotas on, each user in the specified
2133 * filesystem or snapshot.
2134 */
2135

--- 670 unchanged lines hidden (view full) ---

2806 uu_avl_walk_end(walk);
2807 uu_avl_destroy(avl_tree);
2808 uu_avl_pool_destroy(avl_pool);
2809
2810 return (ret);
2811}
2812
2813/*
2127 * -s Specify sort columns, descending order.
2128 * -S Specify sort columns, ascending order.
2129 * -t Control which object types to display.
2130 *
2131 * Displays space consumed by, and quotas on, each user in the specified
2132 * filesystem or snapshot.
2133 */
2134

--- 670 unchanged lines hidden (view full) ---

2805 uu_avl_walk_end(walk);
2806 uu_avl_destroy(avl_tree);
2807 uu_avl_pool_destroy(avl_pool);
2808
2809 return (ret);
2810}
2811
2812/*
2814 * list [-r][-d max] [-H] [-o property[,property]...] [-t type[,type]...]
2815 * [-s property [-s property]...] [-S property [-S property]...]
2816 * <dataset> ...
2813 * list [-Hp][-r|-d max] [-o property[,...]] [-s property] ... [-S property] ...
2814 * [-t type[,...]] [filesystem|volume|snapshot] ...
2817 *
2815 *
2818 * -r Recurse over all children
2816 * -H Scripted mode; elide headers and separate columns by tabs.
2817 * -p Display values in parsable (literal) format.
2818 * -r Recurse over all children.
2819 * -d Limit recursion by depth.
2819 * -d Limit recursion by depth.
2820 * -H Scripted mode; elide headers and separate columns by tabs
2821 * -o Control which fields to display.
2820 * -o Control which fields to display.
2822 * -t Control which object types to display.
2823 * -s Specify sort columns, descending order.
2824 * -S Specify sort columns, ascending order.
2821 * -s Specify sort columns, descending order.
2822 * -S Specify sort columns, ascending order.
2823 * -t Control which object types to display.
2825 *
2824 *
2826 * When given no arguments, lists all filesystems in the system.
2825 * When given no arguments, list all filesystems in the system.
2827 * Otherwise, list the specified datasets, optionally recursing down them if
2828 * '-r' is specified.
2829 */
2830typedef struct list_cbdata {
2831 boolean_t cb_first;
2826 * Otherwise, list the specified datasets, optionally recursing down them if
2827 * '-r' is specified.
2828 */
2829typedef struct list_cbdata {
2830 boolean_t cb_first;
2831 boolean_t cb_literal;
2832 boolean_t cb_scripted;
2833 zprop_list_t *cb_proplist;
2834} list_cbdata_t;
2835
2836/*
2837 * Given a list of columns to display, output appropriate headers for each one.
2838 */
2839static void
2832 boolean_t cb_scripted;
2833 zprop_list_t *cb_proplist;
2834} list_cbdata_t;
2835
2836/*
2837 * Given a list of columns to display, output appropriate headers for each one.
2838 */
2839static void
2840print_header(zprop_list_t *pl)
2840print_header(list_cbdata_t *cb)
2841{
2841{
2842 zprop_list_t *pl = cb->cb_proplist;
2842 char headerbuf[ZFS_MAXPROPLEN];
2843 const char *header;
2844 int i;
2845 boolean_t first = B_TRUE;
2846 boolean_t right_justify;
2847
2848 for (; pl != NULL; pl = pl->pl_next) {
2849 if (!first) {

--- 24 unchanged lines hidden (view full) ---

2874 (void) printf("\n");
2875}
2876
2877/*
2878 * Given a dataset and a list of fields, print out all the properties according
2879 * to the described layout.
2880 */
2881static void
2843 char headerbuf[ZFS_MAXPROPLEN];
2844 const char *header;
2845 int i;
2846 boolean_t first = B_TRUE;
2847 boolean_t right_justify;
2848
2849 for (; pl != NULL; pl = pl->pl_next) {
2850 if (!first) {

--- 24 unchanged lines hidden (view full) ---

2875 (void) printf("\n");
2876}
2877
2878/*
2879 * Given a dataset and a list of fields, print out all the properties according
2880 * to the described layout.
2881 */
2882static void
2882print_dataset(zfs_handle_t *zhp, zprop_list_t *pl, boolean_t scripted)
2883print_dataset(zfs_handle_t *zhp, list_cbdata_t *cb)
2883{
2884{
2885 zprop_list_t *pl = cb->cb_proplist;
2884 boolean_t first = B_TRUE;
2885 char property[ZFS_MAXPROPLEN];
2886 nvlist_t *userprops = zfs_get_user_props(zhp);
2887 nvlist_t *propval;
2888 char *propstr;
2889 boolean_t right_justify;
2886 boolean_t first = B_TRUE;
2887 char property[ZFS_MAXPROPLEN];
2888 nvlist_t *userprops = zfs_get_user_props(zhp);
2889 nvlist_t *propval;
2890 char *propstr;
2891 boolean_t right_justify;
2890 int width;
2891
2892 for (; pl != NULL; pl = pl->pl_next) {
2893 if (!first) {
2892
2893 for (; pl != NULL; pl = pl->pl_next) {
2894 if (!first) {
2894 if (scripted)
2895 if (cb->cb_scripted)
2895 (void) printf("\t");
2896 else
2897 (void) printf(" ");
2898 } else {
2899 first = B_FALSE;
2900 }
2901
2902 if (pl->pl_prop == ZFS_PROP_NAME) {
2903 (void) strlcpy(property, zfs_get_name(zhp),
2904 sizeof(property));
2905 propstr = property;
2906 right_justify = zfs_prop_align_right(pl->pl_prop);
2907 } else if (pl->pl_prop != ZPROP_INVAL) {
2908 if (zfs_prop_get(zhp, pl->pl_prop, property,
2896 (void) printf("\t");
2897 else
2898 (void) printf(" ");
2899 } else {
2900 first = B_FALSE;
2901 }
2902
2903 if (pl->pl_prop == ZFS_PROP_NAME) {
2904 (void) strlcpy(property, zfs_get_name(zhp),
2905 sizeof(property));
2906 propstr = property;
2907 right_justify = zfs_prop_align_right(pl->pl_prop);
2908 } else if (pl->pl_prop != ZPROP_INVAL) {
2909 if (zfs_prop_get(zhp, pl->pl_prop, property,
2909 sizeof (property), NULL, NULL, 0, B_FALSE) != 0)
2910 sizeof (property), NULL, NULL, 0,
2911 cb->cb_literal) != 0)
2910 propstr = "-";
2911 else
2912 propstr = property;
2912 propstr = "-";
2913 else
2914 propstr = property;
2913
2914 right_justify = zfs_prop_align_right(pl->pl_prop);
2915 } else if (zfs_prop_userquota(pl->pl_user_prop)) {
2916 if (zfs_prop_get_userquota(zhp, pl->pl_user_prop,
2915 right_justify = zfs_prop_align_right(pl->pl_prop);
2916 } else if (zfs_prop_userquota(pl->pl_user_prop)) {
2917 if (zfs_prop_get_userquota(zhp, pl->pl_user_prop,
2917 property, sizeof (property), B_FALSE) != 0)
2918 property, sizeof (property), cb->cb_literal) != 0)
2918 propstr = "-";
2919 else
2920 propstr = property;
2921 right_justify = B_TRUE;
2922 } else if (zfs_prop_written(pl->pl_user_prop)) {
2923 if (zfs_prop_get_written(zhp, pl->pl_user_prop,
2919 propstr = "-";
2920 else
2921 propstr = property;
2922 right_justify = B_TRUE;
2923 } else if (zfs_prop_written(pl->pl_user_prop)) {
2924 if (zfs_prop_get_written(zhp, pl->pl_user_prop,
2924 property, sizeof (property), B_FALSE) != 0)
2925 property, sizeof (property), cb->cb_literal) != 0)
2925 propstr = "-";
2926 else
2927 propstr = property;
2928 right_justify = B_TRUE;
2929 } else {
2930 if (nvlist_lookup_nvlist(userprops,
2931 pl->pl_user_prop, &propval) != 0)
2932 propstr = "-";
2933 else
2934 verify(nvlist_lookup_string(propval,
2935 ZPROP_VALUE, &propstr) == 0);
2936 right_justify = B_FALSE;
2937 }
2938
2926 propstr = "-";
2927 else
2928 propstr = property;
2929 right_justify = B_TRUE;
2930 } else {
2931 if (nvlist_lookup_nvlist(userprops,
2932 pl->pl_user_prop, &propval) != 0)
2933 propstr = "-";
2934 else
2935 verify(nvlist_lookup_string(propval,
2936 ZPROP_VALUE, &propstr) == 0);
2937 right_justify = B_FALSE;
2938 }
2939
2939 width = pl->pl_width;
2940
2941 /*
2942 * If this is being called in scripted mode, or if this is the
2943 * last column and it is left-justified, don't include a width
2944 * format specifier.
2945 */
2940 /*
2941 * If this is being called in scripted mode, or if this is the
2942 * last column and it is left-justified, don't include a width
2943 * format specifier.
2944 */
2946 if (scripted || (pl->pl_next == NULL && !right_justify))
2945 if (cb->cb_scripted || (pl->pl_next == NULL && !right_justify))
2947 (void) printf("%s", propstr);
2948 else if (right_justify)
2946 (void) printf("%s", propstr);
2947 else if (right_justify)
2949 (void) printf("%*s", width, propstr);
2948 (void) printf("%*s", pl->pl_width, propstr);
2950 else
2949 else
2951 (void) printf("%-*s", width, propstr);
2950 (void) printf("%-*s", pl->pl_width, propstr);
2952 }
2953
2954 (void) printf("\n");
2955}
2956
2957/*
2958 * Generic callback function to list a dataset or snapshot.
2959 */
2960static int
2961list_callback(zfs_handle_t *zhp, void *data)
2962{
2963 list_cbdata_t *cbp = data;
2964
2965 if (cbp->cb_first) {
2966 if (!cbp->cb_scripted)
2951 }
2952
2953 (void) printf("\n");
2954}
2955
2956/*
2957 * Generic callback function to list a dataset or snapshot.
2958 */
2959static int
2960list_callback(zfs_handle_t *zhp, void *data)
2961{
2962 list_cbdata_t *cbp = data;
2963
2964 if (cbp->cb_first) {
2965 if (!cbp->cb_scripted)
2967 print_header(cbp->cb_proplist);
2966 print_header(cbp);
2968 cbp->cb_first = B_FALSE;
2969 }
2970
2967 cbp->cb_first = B_FALSE;
2968 }
2969
2971 print_dataset(zhp, cbp->cb_proplist, cbp->cb_scripted);
2970 print_dataset(zhp, cbp);
2972
2973 return (0);
2974}
2975
2976static int
2977zfs_do_list(int argc, char **argv)
2978{
2979 int c;
2971
2972 return (0);
2973}
2974
2975static int
2976zfs_do_list(int argc, char **argv)
2977{
2978 int c;
2980 boolean_t scripted = B_FALSE;
2981 static char default_fields[] =
2982 "name,used,available,referenced,mountpoint";
2983 int types = ZFS_TYPE_DATASET;
2984 boolean_t types_specified = B_FALSE;
2985 char *fields = NULL;
2986 list_cbdata_t cb = { 0 };
2987 char *value;
2988 int limit = 0;
2989 int ret = 0;
2990 zfs_sort_column_t *sortcol = NULL;
2991 int flags = ZFS_ITER_PROP_LISTSNAPS | ZFS_ITER_ARGS_CAN_BE_PATHS;
2992
2993 /* check options */
2979 static char default_fields[] =
2980 "name,used,available,referenced,mountpoint";
2981 int types = ZFS_TYPE_DATASET;
2982 boolean_t types_specified = B_FALSE;
2983 char *fields = NULL;
2984 list_cbdata_t cb = { 0 };
2985 char *value;
2986 int limit = 0;
2987 int ret = 0;
2988 zfs_sort_column_t *sortcol = NULL;
2989 int flags = ZFS_ITER_PROP_LISTSNAPS | ZFS_ITER_ARGS_CAN_BE_PATHS;
2990
2991 /* check options */
2994 while ((c = getopt(argc, argv, ":d:o:rt:Hs:S:")) != -1) {
2992 while ((c = getopt(argc, argv, "HS:d:o:prs:t:")) != -1) {
2995 switch (c) {
2996 case 'o':
2997 fields = optarg;
2998 break;
2993 switch (c) {
2994 case 'o':
2995 fields = optarg;
2996 break;
2997 case 'p':
2998 cb.cb_literal = B_TRUE;
2999 flags |= ZFS_ITER_LITERAL_PROPS;
3000 break;
2999 case 'd':
3000 limit = parse_depth(optarg, &flags);
3001 break;
3002 case 'r':
3003 flags |= ZFS_ITER_RECURSE;
3004 break;
3005 case 'H':
3001 case 'd':
3002 limit = parse_depth(optarg, &flags);
3003 break;
3004 case 'r':
3005 flags |= ZFS_ITER_RECURSE;
3006 break;
3007 case 'H':
3006 scripted = B_TRUE;
3008 cb.cb_scripted = B_TRUE;
3007 break;
3008 case 's':
3009 if (zfs_add_sort_column(&sortcol, optarg,
3010 B_FALSE) != 0) {
3011 (void) fprintf(stderr,
3012 gettext("invalid property '%s'\n"), optarg);
3013 usage(B_FALSE);
3014 }

--- 73 unchanged lines hidden (view full) ---

3088 * If the user specifies '-o all', the zprop_get_list() doesn't
3089 * normally include the name of the dataset. For 'zfs list', we always
3090 * want this property to be first.
3091 */
3092 if (zprop_get_list(g_zfs, fields, &cb.cb_proplist, ZFS_TYPE_DATASET)
3093 != 0)
3094 usage(B_FALSE);
3095
3009 break;
3010 case 's':
3011 if (zfs_add_sort_column(&sortcol, optarg,
3012 B_FALSE) != 0) {
3013 (void) fprintf(stderr,
3014 gettext("invalid property '%s'\n"), optarg);
3015 usage(B_FALSE);
3016 }

--- 73 unchanged lines hidden (view full) ---

3090 * If the user specifies '-o all', the zprop_get_list() doesn't
3091 * normally include the name of the dataset. For 'zfs list', we always
3092 * want this property to be first.
3093 */
3094 if (zprop_get_list(g_zfs, fields, &cb.cb_proplist, ZFS_TYPE_DATASET)
3095 != 0)
3096 usage(B_FALSE);
3097
3096 cb.cb_scripted = scripted;
3097 cb.cb_first = B_TRUE;
3098
3099 ret = zfs_for_each(argc, argv, flags, types, sortcol, &cb.cb_proplist,
3100 limit, list_callback, &cb);
3101
3102 zprop_free_list(cb.cb_proplist);
3103 zfs_free_sort_columns(sortcol);
3104

--- 3673 unchanged lines hidden ---
3098 cb.cb_first = B_TRUE;
3099
3100 ret = zfs_for_each(argc, argv, flags, types, sortcol, &cb.cb_proplist,
3101 limit, list_callback, &cb);
3102
3103 zprop_free_list(cb.cb_proplist);
3104 zfs_free_sort_columns(sortcol);
3105

--- 3673 unchanged lines hidden ---