Skip to content

Commit e346ec2

Browse files
Andrew Stormontbehlendorf
authored andcommitted
Illumos #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> References: https://www.illumos.org/issues/1936 Ported by: Martin Matuska <martin@matuska.org> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #681
1 parent 684e8c0 commit e346ec2

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

cmd/zfs/zfs_main.c

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ get_usage(zfs_help_t idx)
218218
"<filesystem|volume>@<snap>[%<snap>][,...]\n"));
219219
case HELP_GET:
220220
return (gettext("\tget [-rHp] [-d max] "
221-
"[-o \"all\" | field[,...]] [-s source[,...]]\n"
221+
"[-o \"all\" | field[,...]] [-t type[,...]] "
222+
"[-s source[,...]]\n"
222223
"\t <\"all\" | property[,...]> "
223224
"[filesystem|volume|snapshot] ...\n"));
224225
case HELP_INHERIT:
@@ -1460,6 +1461,7 @@ zfs_do_get(int argc, char **argv)
14601461
{
14611462
zprop_get_cbdata_t cb = { 0 };
14621463
int i, c, flags = ZFS_ITER_ARGS_CAN_BE_PATHS;
1464+
int types = ZFS_TYPE_DATASET;
14631465
char *value, *fields;
14641466
int ret = 0;
14651467
int limit = 0;
@@ -1476,7 +1478,7 @@ zfs_do_get(int argc, char **argv)
14761478
cb.cb_type = ZFS_TYPE_DATASET;
14771479

14781480
/* check options */
1479-
while ((c = getopt(argc, argv, ":d:o:s:rHp")) != -1) {
1481+
while ((c = getopt(argc, argv, ":d:o:s:rt:Hp")) != -1) {
14801482
switch (c) {
14811483
case 'p':
14821484
cb.cb_literal = B_TRUE;
@@ -1594,6 +1596,37 @@ zfs_do_get(int argc, char **argv)
15941596
}
15951597
break;
15961598

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

16391672
/* run for each object */
1640-
ret = zfs_for_each(argc, argv, flags, ZFS_TYPE_DATASET, NULL,
1673+
ret = zfs_for_each(argc, argv, flags, types, NULL,
16411674
&cb.cb_proplist, limit, get_callback, &cb);
16421675

16431676
if (cb.cb_proplist == &fake_name)

man/man8/zfs.8

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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
.\" Copyright 2011 Joshua M. Clulow <josh@sysmgr.org>
56
.\" 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.
67
.\" 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
@@ -84,8 +85,8 @@ zfs \- configures ZFS file systems
8485

8586
.LP
8687
.nf
87-
\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[,...]]
88-
"\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 ...
8990
.fi
9091

9192
.LP
@@ -1765,7 +1766,7 @@ Sets the property to the given value for each dataset. Only some properties can
17651766
.ne 2
17661767
.mk
17671768
.na
1768-
\fB\fBzfs get\fR [\fB-r\fR|\fB-d\fR \fIdepth\fR] [\fB-Hp\fR] [\fB-o\fR \fIfield\fR[,...] [\fB-s\fR \fIsource\fR[,...] "\fIall\fR" | \fIproperty\fR[,...] \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR ...\fR
1769+
\fB\fBzfs get\fR [\fB-r\fR|\fB-d\fR \fIdepth\fR] [\fB-Hp\fR] [\fB-o\fR \fIfield\fR[,...] [\fB-t\fR \fItype\fR[,...]] [\fB-s\fR \fIsource\fR[,...] "\fIall\fR" | \fIproperty\fR[,...] \fIfilesystem\fR|\fIvolume\fR|\fIsnapshot\fR ...\fR
17691770
.ad
17701771
.sp .6
17711772
.RS 4n

0 commit comments

Comments
 (0)