Skip to content

Commit 441cac7

Browse files
author
Andrew Stormont
committed
1936 add support for "-t <datatype>" argument to zfs get
Reviewed by: Kartik Mistry <kartik@nexenta.com> Reviewed by: Dan McDonald <danmcd@nexenta.com> Reviewed by: Richard Elling <richard.elling@gmail.com> Reviewed by: Garrett D'Amore <garrett@damore.org> Approved by: Richard Lowe <richlowe@richlowe.net>
1 parent 2c6a6ad commit 441cac7

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

usr/src/cmd/zfs/zfs_main.c

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ get_usage(zfs_help_t idx)
216216
"<filesystem|volume>@<snap>[%<snap>][,...]\n"));
217217
case HELP_GET:
218218
return (gettext("\tget [-rHp] [-d max] "
219-
"[-o \"all\" | field[,...]] [-s source[,...]]\n"
219+
"[-o \"all\" | field[,...]] [-t type[,...]] "
220+
"[-s source[,...]]\n"
220221
"\t <\"all\" | property[,...]> "
221222
"[filesystem|volume|snapshot] ...\n"));
222223
case HELP_INHERIT:
@@ -1457,6 +1458,7 @@ zfs_do_get(int argc, char **argv)
14571458
{
14581459
zprop_get_cbdata_t cb = { 0 };
14591460
int i, c, flags = ZFS_ITER_ARGS_CAN_BE_PATHS;
1461+
int types = ZFS_TYPE_DATASET;
14601462
char *value, *fields;
14611463
int ret = 0;
14621464
int limit = 0;
@@ -1473,7 +1475,7 @@ zfs_do_get(int argc, char **argv)
14731475
cb.cb_type = ZFS_TYPE_DATASET;
14741476

14751477
/* check options */
1476-
while ((c = getopt(argc, argv, ":d:o:s:rHp")) != -1) {
1478+
while ((c = getopt(argc, argv, ":d:o:s:rt:Hp")) != -1) {
14771479
switch (c) {
14781480
case 'p':
14791481
cb.cb_literal = B_TRUE;
@@ -1591,6 +1593,37 @@ zfs_do_get(int argc, char **argv)
15911593
}
15921594
break;
15931595

1596+
case 't':
1597+
types = 0;
1598+
flags &= ~ZFS_ITER_PROP_LISTSNAPS;
1599+
while (*optarg != '\0') {
1600+
static char *type_subopts[] = { "filesystem",
1601+
"volume", "snapshot", "all", NULL };
1602+
1603+
switch (getsubopt(&optarg, type_subopts,
1604+
&value)) {
1605+
case 0:
1606+
types |= ZFS_TYPE_FILESYSTEM;
1607+
break;
1608+
case 1:
1609+
types |= ZFS_TYPE_VOLUME;
1610+
break;
1611+
case 2:
1612+
types |= ZFS_TYPE_SNAPSHOT;
1613+
break;
1614+
case 3:
1615+
types = ZFS_TYPE_DATASET;
1616+
break;
1617+
1618+
default:
1619+
(void) fprintf(stderr,
1620+
gettext("invalid type '%s'\n"),
1621+
value);
1622+
usage(B_FALSE);
1623+
}
1624+
}
1625+
break;
1626+
15941627
case '?':
15951628
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
15961629
optopt);
@@ -1634,7 +1667,7 @@ zfs_do_get(int argc, char **argv)
16341667
cb.cb_first = B_TRUE;
16351668

16361669
/* run for each object */
1637-
ret = zfs_for_each(argc, argv, flags, ZFS_TYPE_DATASET, NULL,
1670+
ret = zfs_for_each(argc, argv, flags, types, NULL,
16381671
&cb.cb_proplist, limit, get_callback, &cb);
16391672

16401673
if (cb.cb_proplist == &fake_name)

usr/src/man/man1m/zfs.1m

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
'\" te
22
.\" Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved.
33
.\" Copyright (c) 2011 by Delphix. All rights reserved.
4+
.\" Copyright (c) 2012 Nexenta Systems, Inc. All Rights Reserved.
45
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
56
.\" See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with
67
.\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
7-
.\" Copyright 2011 Nexenta Systems, Inc. All rights reserved.
8-
.\" Copyright 2011 by Delphix. All rights reserved.
98
.\" Copyright 2011 Joshua M. Clulow <josh@sysmgr.org>
109
.TH ZFS 1M "28 Jul 2011"
1110
.SH NAME
@@ -86,8 +85,8 @@ zfs \- configures ZFS file systems
8685

8786
.LP
8887
.nf
89-
\fBzfs\fR \fBget\fR [\fB-r\fR|\fB-d\fR \fIdepth\fR][\fB-Hp\fR][\fB-o\fR \fIfield\fR[,...]] [\fB-s\fR \fIsource\fR[,...]]
90-
"\fIall\fR" | \fIproperty\fR[,...] \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR ...
88+
\fBzfs\fR \fBget\fR [\fB-r\fR|\fB-d\fR \fIdepth\fR][\fB-Hp\fR][\fB-o\fR \fIfield\fR[,...]] [\fB-t\fR \fItype\fR[,...]]
89+
[\fB-s\fR \fIsource\fR[,...]] "\fIall\fR" | \fIproperty\fR[,...] \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR ...
9190
.fi
9291

9392
.LP
@@ -2199,7 +2198,7 @@ Properties" section.
21992198
.ne 2
22002199
.na
22012200
\fB\fBzfs get\fR [\fB-r\fR|\fB-d\fR \fIdepth\fR] [\fB-Hp\fR] [\fB-o\fR
2202-
\fIfield\fR[,...] [\fB-s\fR \fIsource\fR[,...] "\fIall\fR" |
2201+
\fIfield\fR[,...] [\fB-t\fR \fItype\fR[,...]] [\fB-s\fR \fIsource\fR[,...] "\fIall\fR" |
22032202
\fIproperty\fR[,...] \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR ...\fR
22042203
.ad
22052204
.sp .6

0 commit comments

Comments
 (0)