author | Tom Erickson <Tom.Erickson@Sun.COM> |
Fri, 08 Jan 2010 16:55:38 -0800 | |
changeset 11461 | 5113530c9d30 |
parent 11449 | a6be67f77b9f |
child 11515 | a122949107d4 |
permissions | -rw-r--r-- |
789 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
1544 | 5 |
* Common Development and Distribution License (the "License"). |
6 |
* You may not use this file except in compliance with the License. |
|
789 | 7 |
* |
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
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 |
*/ |
|
3126 | 21 |
|
789 | 22 |
/* |
11417
de9a68916900
6911611 zfs_send()'s use of snapshot holds is still racy
Chris Kirby <Chris.Kirby@sun.com>
parents:
11022
diff
changeset
|
23 |
* Copyright 2010 Sun Microsystems, Inc. All rights reserved. |
789 | 24 |
* Use is subject to license terms. |
25 |
*/ |
|
26 |
||
27 |
#include <assert.h> |
|
2676 | 28 |
#include <ctype.h> |
789 | 29 |
#include <errno.h> |
30 |
#include <libgen.h> |
|
31 |
#include <libintl.h> |
|
32 |
#include <libuutil.h> |
|
4543 | 33 |
#include <libnvpair.h> |
789 | 34 |
#include <locale.h> |
35 |
#include <stddef.h> |
|
36 |
#include <stdio.h> |
|
37 |
#include <stdlib.h> |
|
38 |
#include <strings.h> |
|
39 |
#include <unistd.h> |
|
40 |
#include <fcntl.h> |
|
41 |
#include <zone.h> |
|
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
42 |
#include <grp.h> |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
43 |
#include <pwd.h> |
789 | 44 |
#include <sys/mkdev.h> |
45 |
#include <sys/mntent.h> |
|
46 |
#include <sys/mnttab.h> |
|
47 |
#include <sys/mount.h> |
|
48 |
#include <sys/stat.h> |
|
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
49 |
#include <sys/fs/zfs.h> |
789 | 50 |
|
51 |
#include <libzfs.h> |
|
4543 | 52 |
#include <libuutil.h> |
789 | 53 |
|
54 |
#include "zfs_iter.h" |
|
2082 | 55 |
#include "zfs_util.h" |
56 |
||
57 |
libzfs_handle_t *g_zfs; |
|
789 | 58 |
|
59 |
static FILE *mnttab_file; |
|
4988
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4860
diff
changeset
|
60 |
static char history_str[HIS_MAX_RECORD_LEN]; |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
61 |
const char *pypath = "/usr/lib/zfs/pyzfs.py"; |
789 | 62 |
|
63 |
static int zfs_do_clone(int argc, char **argv); |
|
64 |
static int zfs_do_create(int argc, char **argv); |
|
65 |
static int zfs_do_destroy(int argc, char **argv); |
|
66 |
static int zfs_do_get(int argc, char **argv); |
|
67 |
static int zfs_do_inherit(int argc, char **argv); |
|
68 |
static int zfs_do_list(int argc, char **argv); |
|
69 |
static int zfs_do_mount(int argc, char **argv); |
|
70 |
static int zfs_do_rename(int argc, char **argv); |
|
71 |
static int zfs_do_rollback(int argc, char **argv); |
|
72 |
static int zfs_do_set(int argc, char **argv); |
|
4577 | 73 |
static int zfs_do_upgrade(int argc, char **argv); |
789 | 74 |
static int zfs_do_snapshot(int argc, char **argv); |
75 |
static int zfs_do_unmount(int argc, char **argv); |
|
76 |
static int zfs_do_share(int argc, char **argv); |
|
77 |
static int zfs_do_unshare(int argc, char **argv); |
|
1749 | 78 |
static int zfs_do_send(int argc, char **argv); |
79 |
static int zfs_do_receive(int argc, char **argv); |
|
2082 | 80 |
static int zfs_do_promote(int argc, char **argv); |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
81 |
static int zfs_do_userspace(int argc, char **argv); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
82 |
static int zfs_do_python(int argc, char **argv); |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
83 |
static int zfs_do_hold(int argc, char **argv); |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
84 |
static int zfs_do_release(int argc, char **argv); |
789 | 85 |
|
86 |
/* |
|
6865 | 87 |
* Enable a reasonable set of defaults for libumem debugging on DEBUG builds. |
789 | 88 |
*/ |
6865 | 89 |
|
90 |
#ifdef DEBUG |
|
789 | 91 |
const char * |
3126 | 92 |
_umem_debug_init(void) |
789 | 93 |
{ |
94 |
return ("default,verbose"); /* $UMEM_DEBUG setting */ |
|
95 |
} |
|
96 |
||
97 |
const char * |
|
98 |
_umem_logging_init(void) |
|
99 |
{ |
|
100 |
return ("fail,contents"); /* $UMEM_LOGGING setting */ |
|
101 |
} |
|
6865 | 102 |
#endif |
789 | 103 |
|
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
104 |
typedef enum { |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
105 |
HELP_CLONE, |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
106 |
HELP_CREATE, |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
107 |
HELP_DESTROY, |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
108 |
HELP_GET, |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
109 |
HELP_INHERIT, |
4577 | 110 |
HELP_UPGRADE, |
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
111 |
HELP_LIST, |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
112 |
HELP_MOUNT, |
2082 | 113 |
HELP_PROMOTE, |
1749 | 114 |
HELP_RECEIVE, |
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
115 |
HELP_RENAME, |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
116 |
HELP_ROLLBACK, |
1749 | 117 |
HELP_SEND, |
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
118 |
HELP_SET, |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
119 |
HELP_SHARE, |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
120 |
HELP_SNAPSHOT, |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
121 |
HELP_UNMOUNT, |
4543 | 122 |
HELP_UNSHARE, |
123 |
HELP_ALLOW, |
|
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
124 |
HELP_UNALLOW, |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
125 |
HELP_USERSPACE, |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
126 |
HELP_GROUPSPACE, |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
127 |
HELP_HOLD, |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
128 |
HELP_HOLDS, |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
129 |
HELP_RELEASE |
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
130 |
} zfs_help_t; |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
131 |
|
789 | 132 |
typedef struct zfs_command { |
133 |
const char *name; |
|
134 |
int (*func)(int argc, char **argv); |
|
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
135 |
zfs_help_t usage; |
789 | 136 |
} zfs_command_t; |
137 |
||
138 |
/* |
|
139 |
* Master command table. Each ZFS command has a name, associated function, and |
|
1544 | 140 |
* usage message. The usage messages need to be internationalized, so we have |
141 |
* to have a function to return the usage message based on a command index. |
|
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
142 |
* |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
143 |
* These commands are organized according to how they are displayed in the usage |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
144 |
* message. An empty command (one with a NULL name) indicates an empty line in |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
145 |
* the generic usage message. |
789 | 146 |
*/ |
147 |
static zfs_command_t command_table[] = { |
|
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
148 |
{ "create", zfs_do_create, HELP_CREATE }, |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
149 |
{ "destroy", zfs_do_destroy, HELP_DESTROY }, |
789 | 150 |
{ NULL }, |
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
151 |
{ "snapshot", zfs_do_snapshot, HELP_SNAPSHOT }, |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
152 |
{ "rollback", zfs_do_rollback, HELP_ROLLBACK }, |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
153 |
{ "clone", zfs_do_clone, HELP_CLONE }, |
2082 | 154 |
{ "promote", zfs_do_promote, HELP_PROMOTE }, |
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
155 |
{ "rename", zfs_do_rename, HELP_RENAME }, |
789 | 156 |
{ NULL }, |
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
157 |
{ "list", zfs_do_list, HELP_LIST }, |
789 | 158 |
{ NULL }, |
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
159 |
{ "set", zfs_do_set, HELP_SET }, |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
160 |
{ "get", zfs_do_get, HELP_GET }, |
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
161 |
{ "inherit", zfs_do_inherit, HELP_INHERIT }, |
4577 | 162 |
{ "upgrade", zfs_do_upgrade, HELP_UPGRADE }, |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
163 |
{ "userspace", zfs_do_userspace, HELP_USERSPACE }, |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
164 |
{ "groupspace", zfs_do_userspace, HELP_GROUPSPACE }, |
789 | 165 |
{ NULL }, |
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
166 |
{ "mount", zfs_do_mount, HELP_MOUNT }, |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
167 |
{ "unmount", zfs_do_unmount, HELP_UNMOUNT }, |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
168 |
{ "share", zfs_do_share, HELP_SHARE }, |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
169 |
{ "unshare", zfs_do_unshare, HELP_UNSHARE }, |
789 | 170 |
{ NULL }, |
1749 | 171 |
{ "send", zfs_do_send, HELP_SEND }, |
172 |
{ "receive", zfs_do_receive, HELP_RECEIVE }, |
|
4543 | 173 |
{ NULL }, |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
174 |
{ "allow", zfs_do_python, HELP_ALLOW }, |
4543 | 175 |
{ NULL }, |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
176 |
{ "unallow", zfs_do_python, HELP_UNALLOW }, |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
177 |
{ NULL }, |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
178 |
{ "hold", zfs_do_hold, HELP_HOLD }, |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
179 |
{ "holds", zfs_do_python, HELP_HOLDS }, |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
180 |
{ "release", zfs_do_release, HELP_RELEASE }, |
789 | 181 |
}; |
182 |
||
183 |
#define NCOMMAND (sizeof (command_table) / sizeof (command_table[0])) |
|
184 |
||
185 |
zfs_command_t *current_command; |
|
186 |
||
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
187 |
static const char * |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
188 |
get_usage(zfs_help_t idx) |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
189 |
{ |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
190 |
switch (idx) { |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
191 |
case HELP_CLONE: |
7265 | 192 |
return (gettext("\tclone [-p] [-o property=value] ... " |
193 |
"<snapshot> <filesystem|volume>\n")); |
|
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
194 |
case HELP_CREATE: |
4849
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
195 |
return (gettext("\tcreate [-p] [-o property=value] ... " |
2676 | 196 |
"<filesystem>\n" |
4849
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
197 |
"\tcreate [-ps] [-b blocksize] [-o property=value] ... " |
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
198 |
"-V <size> <volume>\n")); |
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
199 |
case HELP_DESTROY: |
10385
21cb6e67d108
6873727 zfs destroy -d <fs> should fail more gracefully when children are present
Chris Kirby <chris.kirby@sun.com>
parents:
10342
diff
changeset
|
200 |
return (gettext("\tdestroy [-rRf] <filesystem|volume>\n" |
21cb6e67d108
6873727 zfs destroy -d <fs> should fail more gracefully when children are present
Chris Kirby <chris.kirby@sun.com>
parents:
10342
diff
changeset
|
201 |
"\tdestroy [-rRd] <snapshot>\n")); |
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
202 |
case HELP_GET: |
9365
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
203 |
return (gettext("\tget [-rHp] [-d max] " |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
204 |
"[-o \"all\" | field[,...]] [-s source[,...]]\n" |
4849
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
205 |
"\t <\"all\" | property[,...]> " |
2676 | 206 |
"[filesystem|volume|snapshot] ...\n")); |
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
207 |
case HELP_INHERIT: |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
208 |
return (gettext("\tinherit [-rS] <property> " |
7265 | 209 |
"<filesystem|volume|snapshot> ...\n")); |
4577 | 210 |
case HELP_UPGRADE: |
211 |
return (gettext("\tupgrade [-v]\n" |
|
212 |
"\tupgrade [-r] [-V version] <-a | filesystem ...>\n")); |
|
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
213 |
case HELP_LIST: |
9365
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
214 |
return (gettext("\tlist [-rH][-d max] " |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
215 |
"[-o property[,...]] [-t type[,...]] [-s property] ...\n" |
4849
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
216 |
"\t [-S property] ... " |
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
217 |
"[filesystem|volume|snapshot] ...\n")); |
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
218 |
case HELP_MOUNT: |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
219 |
return (gettext("\tmount\n" |
4849
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
220 |
"\tmount [-vO] [-o opts] <-a | filesystem>\n")); |
2082 | 221 |
case HELP_PROMOTE: |
4849
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
222 |
return (gettext("\tpromote <clone-filesystem>\n")); |
1749 | 223 |
case HELP_RECEIVE: |
2665 | 224 |
return (gettext("\treceive [-vnF] <filesystem|volume|" |
225 |
"snapshot>\n" |
|
226 |
"\treceive [-vnF] -d <filesystem>\n")); |
|
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
227 |
case HELP_RENAME: |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
228 |
return (gettext("\trename <filesystem|volume|snapshot> " |
4007 | 229 |
"<filesystem|volume|snapshot>\n" |
4490 | 230 |
"\trename -p <filesystem|volume> <filesystem|volume>\n" |
4007 | 231 |
"\trename -r <snapshot> <snapshot>")); |
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
232 |
case HELP_ROLLBACK: |
5568 | 233 |
return (gettext("\trollback [-rRf] <snapshot>\n")); |
1749 | 234 |
case HELP_SEND: |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
235 |
return (gettext("\tsend [-RDp] [-[iI] snapshot] <snapshot>\n")); |
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
236 |
case HELP_SET: |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
237 |
return (gettext("\tset <property=value> " |
7265 | 238 |
"<filesystem|volume|snapshot> ...\n")); |
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
239 |
case HELP_SHARE: |
4849
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
240 |
return (gettext("\tshare <-a | filesystem>\n")); |
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
241 |
case HELP_SNAPSHOT: |
7265 | 242 |
return (gettext("\tsnapshot [-r] [-o property=value] ... " |
4849
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
243 |
"<filesystem@snapname|volume@snapname>\n")); |
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
244 |
case HELP_UNMOUNT: |
4849
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
245 |
return (gettext("\tunmount [-f] " |
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
246 |
"<-a | filesystem|mountpoint>\n")); |
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
247 |
case HELP_UNSHARE: |
10228
ca7b8ea13ef5
6835751 typo in zfs upgrade -v
stephanie scheffler <Stephanie.Scheffler@Sun.COM>
parents:
9564
diff
changeset
|
248 |
return (gettext("\tunshare " |
4849
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
249 |
"<-a | filesystem|mountpoint>\n")); |
4543 | 250 |
case HELP_ALLOW: |
9564
eebe5932551d
6817789 zfs allow usage statement incomplete
stephanie scheffler <Stephanie.Scheffler@Sun.COM>
parents:
9554
diff
changeset
|
251 |
return (gettext("\tallow <filesystem|volume>\n" |
eebe5932551d
6817789 zfs allow usage statement incomplete
stephanie scheffler <Stephanie.Scheffler@Sun.COM>
parents:
9554
diff
changeset
|
252 |
"\tallow [-ldug] " |
4849
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
253 |
"<\"everyone\"|user|group>[,...] <perm|@setname>[,...]\n" |
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
254 |
"\t <filesystem|volume>\n" |
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
255 |
"\tallow [-ld] -e <perm|@setname>[,...] " |
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
256 |
"<filesystem|volume>\n" |
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
257 |
"\tallow -c <perm|@setname>[,...] <filesystem|volume>\n" |
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
258 |
"\tallow -s @setname <perm|@setname>[,...] " |
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
259 |
"<filesystem|volume>\n")); |
4543 | 260 |
case HELP_UNALLOW: |
4849
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
261 |
return (gettext("\tunallow [-rldug] " |
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
262 |
"<\"everyone\"|user|group>[,...]\n" |
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
263 |
"\t [<perm|@setname>[,...]] <filesystem|volume>\n" |
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
264 |
"\tunallow [-rld] -e [<perm|@setname>[,...]] " |
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
265 |
"<filesystem|volume>\n" |
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
266 |
"\tunallow [-r] -c [<perm|@setname>[,...]] " |
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
267 |
"<filesystem|volume>\n" |
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
268 |
"\tunallow [-r] -s @setname [<perm|@setname>[,...]] " |
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
269 |
"<filesystem|volume>\n")); |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
270 |
case HELP_USERSPACE: |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
271 |
return (gettext("\tuserspace [-hniHp] [-o field[,...]] " |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
272 |
"[-sS field] ... [-t type[,...]]\n" |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
273 |
"\t <filesystem|snapshot>\n")); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
274 |
case HELP_GROUPSPACE: |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
275 |
return (gettext("\tgroupspace [-hniHpU] [-o field[,...]] " |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
276 |
"[-sS field] ... [-t type[,...]]\n" |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
277 |
"\t <filesystem|snapshot>\n")); |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
278 |
case HELP_HOLD: |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
279 |
return (gettext("\thold [-r] <tag> <snapshot> ...\n")); |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
280 |
case HELP_HOLDS: |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
281 |
return (gettext("\tholds [-r] <snapshot> ...\n")); |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
282 |
case HELP_RELEASE: |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
283 |
return (gettext("\trelease [-r] <tag> <snapshot> ...\n")); |
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
284 |
} |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
285 |
|
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
286 |
abort(); |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
287 |
/* NOTREACHED */ |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
288 |
} |
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
289 |
|
789 | 290 |
/* |
291 |
* Utility function to guarantee malloc() success. |
|
292 |
*/ |
|
293 |
void * |
|
294 |
safe_malloc(size_t size) |
|
295 |
{ |
|
296 |
void *data; |
|
297 |
||
298 |
if ((data = calloc(1, size)) == NULL) { |
|
299 |
(void) fprintf(stderr, "internal error: out of memory\n"); |
|
300 |
exit(1); |
|
301 |
} |
|
302 |
||
303 |
return (data); |
|
304 |
} |
|
305 |
||
306 |
/* |
|
5094 | 307 |
* Callback routine that will print out information for each of |
3654
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
308 |
* the properties. |
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
309 |
*/ |
5094 | 310 |
static int |
311 |
usage_prop_cb(int prop, void *cb) |
|
3654
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
312 |
{ |
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
313 |
FILE *fp = cb; |
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
314 |
|
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6289
diff
changeset
|
315 |
(void) fprintf(fp, "\t%-15s ", zfs_prop_to_name(prop)); |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6289
diff
changeset
|
316 |
|
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6289
diff
changeset
|
317 |
if (zfs_prop_readonly(prop)) |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6289
diff
changeset
|
318 |
(void) fprintf(fp, " NO "); |
3654
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
319 |
else |
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6289
diff
changeset
|
320 |
(void) fprintf(fp, "YES "); |
3654
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
321 |
|
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
322 |
if (zfs_prop_inheritable(prop)) |
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
323 |
(void) fprintf(fp, " YES "); |
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
324 |
else |
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
325 |
(void) fprintf(fp, " NO "); |
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
326 |
|
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
327 |
if (zfs_prop_values(prop) == NULL) |
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
328 |
(void) fprintf(fp, "-\n"); |
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
329 |
else |
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
330 |
(void) fprintf(fp, "%s\n", zfs_prop_values(prop)); |
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
331 |
|
5094 | 332 |
return (ZPROP_CONT); |
3654
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
333 |
} |
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
334 |
|
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
335 |
/* |
789 | 336 |
* Display usage message. If we're inside a command, display only the usage for |
337 |
* that command. Otherwise, iterate over the entire command table and display |
|
338 |
* a complete usage message. |
|
339 |
*/ |
|
340 |
static void |
|
2082 | 341 |
usage(boolean_t requested) |
789 | 342 |
{ |
343 |
int i; |
|
2082 | 344 |
boolean_t show_properties = B_FALSE; |
789 | 345 |
FILE *fp = requested ? stdout : stderr; |
346 |
||
347 |
if (current_command == NULL) { |
|
348 |
||
349 |
(void) fprintf(fp, gettext("usage: zfs command args ...\n")); |
|
350 |
(void) fprintf(fp, |
|
351 |
gettext("where 'command' is one of the following:\n\n")); |
|
352 |
||
353 |
for (i = 0; i < NCOMMAND; i++) { |
|
354 |
if (command_table[i].name == NULL) |
|
355 |
(void) fprintf(fp, "\n"); |
|
356 |
else |
|
357 |
(void) fprintf(fp, "%s", |
|
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
358 |
get_usage(command_table[i].usage)); |
789 | 359 |
} |
360 |
||
361 |
(void) fprintf(fp, gettext("\nEach dataset is of the form: " |
|
362 |
"pool/[dataset/]*dataset[@name]\n")); |
|
363 |
} else { |
|
364 |
(void) fprintf(fp, gettext("usage:\n")); |
|
1387
7dc47b4865df
6340747 i18n : zfs command line tools don't have correctly i18n'd usage messages
eschrock
parents:
1356
diff
changeset
|
365 |
(void) fprintf(fp, "%s", get_usage(current_command->usage)); |
789 | 366 |
} |
367 |
||
2190 | 368 |
if (current_command != NULL && |
369 |
(strcmp(current_command->name, "set") == 0 || |
|
789 | 370 |
strcmp(current_command->name, "get") == 0 || |
371 |
strcmp(current_command->name, "inherit") == 0 || |
|
2190 | 372 |
strcmp(current_command->name, "list") == 0)) |
2082 | 373 |
show_properties = B_TRUE; |
789 | 374 |
|
375 |
if (show_properties) { |
|
376 |
(void) fprintf(fp, |
|
377 |
gettext("\nThe following properties are supported:\n")); |
|
378 |
||
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
379 |
(void) fprintf(fp, "\n\t%-14s %s %s %s\n\n", |
789 | 380 |
"PROPERTY", "EDIT", "INHERIT", "VALUES"); |
381 |
||
3654
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
382 |
/* Iterate over all properties */ |
5094 | 383 |
(void) zprop_iter(usage_prop_cb, fp, B_FALSE, B_TRUE, |
384 |
ZFS_TYPE_DATASET); |
|
3654
9c6042b08979
6483718 need a stable interface to get all native properties
gw25295
parents:
3635
diff
changeset
|
385 |
|
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
386 |
(void) fprintf(fp, "\t%-15s ", "userused@..."); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
387 |
(void) fprintf(fp, " NO NO <size>\n"); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
388 |
(void) fprintf(fp, "\t%-15s ", "groupused@..."); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
389 |
(void) fprintf(fp, " NO NO <size>\n"); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
390 |
(void) fprintf(fp, "\t%-15s ", "userquota@..."); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
391 |
(void) fprintf(fp, "YES NO <size> | none\n"); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
392 |
(void) fprintf(fp, "\t%-15s ", "groupquota@..."); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
393 |
(void) fprintf(fp, "YES NO <size> | none\n"); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
394 |
|
789 | 395 |
(void) fprintf(fp, gettext("\nSizes are specified in bytes " |
396 |
"with standard units such as K, M, G, etc.\n")); |
|
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7386
diff
changeset
|
397 |
(void) fprintf(fp, gettext("\nUser-defined properties can " |
2676 | 398 |
"be specified by using a name containing a colon (:).\n")); |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
399 |
(void) fprintf(fp, gettext("\nThe {user|group}{used|quota}@ " |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
400 |
"properties must be appended with\n" |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
401 |
"a user or group specifier of one of these forms:\n" |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
402 |
" POSIX name (eg: \"matt\")\n" |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
403 |
" POSIX id (eg: \"126829\")\n" |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
404 |
" SMB name@domain (eg: \"matt@sun\")\n" |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
405 |
" SMB SID (eg: \"S-1-234-567-89\")\n")); |
2190 | 406 |
} else { |
407 |
(void) fprintf(fp, |
|
8269
03a7e9050cfd
6674216 "zfs share" doesn't work, but "zfs set sharenfs=on" does
Mark J Musante <Mark.Musante@Sun.COM>
parents:
8213
diff
changeset
|
408 |
gettext("\nFor the property list, run: %s\n"), |
03a7e9050cfd
6674216 "zfs share" doesn't work, but "zfs set sharenfs=on" does
Mark J Musante <Mark.Musante@Sun.COM>
parents:
8213
diff
changeset
|
409 |
"zfs set|get"); |
5993 | 410 |
(void) fprintf(fp, |
8269
03a7e9050cfd
6674216 "zfs share" doesn't work, but "zfs set sharenfs=on" does
Mark J Musante <Mark.Musante@Sun.COM>
parents:
8213
diff
changeset
|
411 |
gettext("\nFor the delegated permission list, run: %s\n"), |
03a7e9050cfd
6674216 "zfs share" doesn't work, but "zfs set sharenfs=on" does
Mark J Musante <Mark.Musante@Sun.COM>
parents:
8213
diff
changeset
|
412 |
"zfs allow|unallow"); |
789 | 413 |
} |
414 |
||
2676 | 415 |
/* |
416 |
* See comments at end of main(). |
|
417 |
*/ |
|
418 |
if (getenv("ZFS_ABORT") != NULL) { |
|
419 |
(void) printf("dumping core by request\n"); |
|
420 |
abort(); |
|
421 |
} |
|
422 |
||
789 | 423 |
exit(requested ? 0 : 2); |
424 |
} |
|
425 |
||
7265 | 426 |
static int |
427 |
parseprop(nvlist_t *props) |
|
428 |
{ |
|
429 |
char *propname = optarg; |
|
430 |
char *propval, *strval; |
|
431 |
||
432 |
if ((propval = strchr(propname, '=')) == NULL) { |
|
433 |
(void) fprintf(stderr, gettext("missing " |
|
434 |
"'=' for -o option\n")); |
|
435 |
return (-1); |
|
436 |
} |
|
437 |
*propval = '\0'; |
|
438 |
propval++; |
|
439 |
if (nvlist_lookup_string(props, propname, &strval) == 0) { |
|
440 |
(void) fprintf(stderr, gettext("property '%s' " |
|
441 |
"specified multiple times\n"), propname); |
|
442 |
return (-1); |
|
443 |
} |
|
444 |
if (nvlist_add_string(props, propname, propval) != 0) { |
|
445 |
(void) fprintf(stderr, gettext("internal " |
|
446 |
"error: out of memory\n")); |
|
447 |
return (-1); |
|
448 |
} |
|
449 |
return (0); |
|
450 |
} |
|
451 |
||
9365
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
452 |
static int |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
453 |
parse_depth(char *opt, int *flags) |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
454 |
{ |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
455 |
char *tmp; |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
456 |
int depth; |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
457 |
|
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
458 |
depth = (int)strtol(opt, &tmp, 0); |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
459 |
if (*tmp) { |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
460 |
(void) fprintf(stderr, |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
461 |
gettext("%s is not an integer\n"), optarg); |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
462 |
usage(B_FALSE); |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
463 |
} |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
464 |
if (depth < 0) { |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
465 |
(void) fprintf(stderr, |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
466 |
gettext("Depth can not be negative.\n")); |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
467 |
usage(B_FALSE); |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
468 |
} |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
469 |
*flags |= (ZFS_ITER_DEPTH_LIMIT|ZFS_ITER_RECURSE); |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
470 |
return (depth); |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
471 |
} |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
472 |
|
789 | 473 |
/* |
7265 | 474 |
* zfs clone [-p] [-o prop=value] ... <snap> <fs | vol> |
789 | 475 |
* |
476 |
* Given an existing dataset, create a writable copy whose initial contents |
|
477 |
* are the same as the source. The newly created dataset maintains a |
|
478 |
* dependency on the original; the original cannot be destroyed so long as |
|
479 |
* the clone exists. |
|
4490 | 480 |
* |
481 |
* The '-p' flag creates all the non-existing ancestors of the target first. |
|
789 | 482 |
*/ |
483 |
static int |
|
484 |
zfs_do_clone(int argc, char **argv) |
|
485 |
{ |
|
7265 | 486 |
zfs_handle_t *zhp = NULL; |
4490 | 487 |
boolean_t parents = B_FALSE; |
7265 | 488 |
nvlist_t *props; |
789 | 489 |
int ret; |
4490 | 490 |
int c; |
789 | 491 |
|
7265 | 492 |
if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0) { |
493 |
(void) fprintf(stderr, gettext("internal error: " |
|
494 |
"out of memory\n")); |
|
495 |
return (1); |
|
496 |
} |
|
497 |
||
789 | 498 |
/* check options */ |
7265 | 499 |
while ((c = getopt(argc, argv, "o:p")) != -1) { |
4490 | 500 |
switch (c) { |
7265 | 501 |
case 'o': |
502 |
if (parseprop(props)) |
|
503 |
return (1); |
|
504 |
break; |
|
4490 | 505 |
case 'p': |
506 |
parents = B_TRUE; |
|
507 |
break; |
|
508 |
case '?': |
|
509 |
(void) fprintf(stderr, gettext("invalid option '%c'\n"), |
|
510 |
optopt); |
|
7265 | 511 |
goto usage; |
4490 | 512 |
} |
789 | 513 |
} |
514 |
||
4490 | 515 |
argc -= optind; |
516 |
argv += optind; |
|
517 |
||
789 | 518 |
/* check number of arguments */ |
4490 | 519 |
if (argc < 1) { |
789 | 520 |
(void) fprintf(stderr, gettext("missing source dataset " |
521 |
"argument\n")); |
|
7265 | 522 |
goto usage; |
789 | 523 |
} |
4490 | 524 |
if (argc < 2) { |
789 | 525 |
(void) fprintf(stderr, gettext("missing target dataset " |
526 |
"argument\n")); |
|
7265 | 527 |
goto usage; |
789 | 528 |
} |
4490 | 529 |
if (argc > 2) { |
789 | 530 |
(void) fprintf(stderr, gettext("too many arguments\n")); |
7265 | 531 |
goto usage; |
789 | 532 |
} |
533 |
||
534 |
/* open the source dataset */ |
|
4490 | 535 |
if ((zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_SNAPSHOT)) == NULL) |
789 | 536 |
return (1); |
537 |
||
4490 | 538 |
if (parents && zfs_name_valid(argv[1], ZFS_TYPE_FILESYSTEM | |
539 |
ZFS_TYPE_VOLUME)) { |
|
540 |
/* |
|
541 |
* Now create the ancestors of the target dataset. If the |
|
542 |
* target already exists and '-p' option was used we should not |
|
543 |
* complain. |
|
544 |
*/ |
|
545 |
if (zfs_dataset_exists(g_zfs, argv[1], ZFS_TYPE_FILESYSTEM | |
|
546 |
ZFS_TYPE_VOLUME)) |
|
547 |
return (0); |
|
548 |
if (zfs_create_ancestors(g_zfs, argv[1]) != 0) |
|
549 |
return (1); |
|
550 |
} |
|
551 |
||
789 | 552 |
/* pass to libzfs */ |
7265 | 553 |
ret = zfs_clone(zhp, argv[1], props); |
789 | 554 |
|
555 |
/* create the mountpoint if necessary */ |
|
556 |
if (ret == 0) { |
|
5094 | 557 |
zfs_handle_t *clone; |
558 |
||
559 |
clone = zfs_open(g_zfs, argv[1], ZFS_TYPE_DATASET); |
|
789 | 560 |
if (clone != NULL) { |
561 |
if ((ret = zfs_mount(clone, NULL, 0)) == 0) |
|
562 |
ret = zfs_share(clone); |
|
563 |
zfs_close(clone); |
|
564 |
} |
|
565 |
} |
|
566 |
||
567 |
zfs_close(zhp); |
|
7265 | 568 |
nvlist_free(props); |
569 |
||
570 |
return (!!ret); |
|
571 |
||
572 |
usage: |
|
573 |
if (zhp) |
|
574 |
zfs_close(zhp); |
|
575 |
nvlist_free(props); |
|
576 |
usage(B_FALSE); |
|
577 |
return (-1); |
|
789 | 578 |
} |
579 |
||
580 |
/* |
|
4490 | 581 |
* zfs create [-p] [-o prop=value] ... fs |
582 |
* zfs create [-ps] [-b blocksize] [-o prop=value] ... -V vol size |
|
789 | 583 |
* |
584 |
* Create a new dataset. This command can be used to create filesystems |
|
585 |
* and volumes. Snapshot creation is handled by 'zfs snapshot'. |
|
586 |
* For volumes, the user must specify a size to be used. |
|
587 |
* |
|
588 |
* The '-s' flag applies only to volumes, and indicates that we should not try |
|
589 |
* to set the reservation for this volume. By default we set a reservation |
|
5481
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
590 |
* equal to the size for any volume. For pools with SPA_VERSION >= |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
591 |
* SPA_VERSION_REFRESERVATION, we set a refreservation instead. |
4490 | 592 |
* |
593 |
* The '-p' flag creates all the non-existing ancestors of the target first. |
|
789 | 594 |
*/ |
595 |
static int |
|
596 |
zfs_do_create(int argc, char **argv) |
|
597 |
{ |
|
598 |
zfs_type_t type = ZFS_TYPE_FILESYSTEM; |
|
2676 | 599 |
zfs_handle_t *zhp = NULL; |
600 |
uint64_t volsize; |
|
789 | 601 |
int c; |
2082 | 602 |
boolean_t noreserve = B_FALSE; |
5367 | 603 |
boolean_t bflag = B_FALSE; |
4490 | 604 |
boolean_t parents = B_FALSE; |
2676 | 605 |
int ret = 1; |
7265 | 606 |
nvlist_t *props; |
2676 | 607 |
uint64_t intval; |
6168
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
608 |
int canmount; |
2676 | 609 |
|
610 |
if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0) { |
|
611 |
(void) fprintf(stderr, gettext("internal error: " |
|
612 |
"out of memory\n")); |
|
613 |
return (1); |
|
614 |
} |
|
789 | 615 |
|
616 |
/* check options */ |
|
4490 | 617 |
while ((c = getopt(argc, argv, ":V:b:so:p")) != -1) { |
789 | 618 |
switch (c) { |
619 |
case 'V': |
|
620 |
type = ZFS_TYPE_VOLUME; |
|
2676 | 621 |
if (zfs_nicestrtonum(g_zfs, optarg, &intval) != 0) { |
622 |
(void) fprintf(stderr, gettext("bad volume " |
|
623 |
"size '%s': %s\n"), optarg, |
|
624 |
libzfs_error_description(g_zfs)); |
|
625 |
goto error; |
|
626 |
} |
|
627 |
||
628 |
if (nvlist_add_uint64(props, |
|
629 |
zfs_prop_to_name(ZFS_PROP_VOLSIZE), |
|
630 |
intval) != 0) { |
|
631 |
(void) fprintf(stderr, gettext("internal " |
|
632 |
"error: out of memory\n")); |
|
633 |
goto error; |
|
634 |
} |
|
635 |
volsize = intval; |
|
789 | 636 |
break; |
4490 | 637 |
case 'p': |
638 |
parents = B_TRUE; |
|
639 |
break; |
|
789 | 640 |
case 'b': |
5367 | 641 |
bflag = B_TRUE; |
2676 | 642 |
if (zfs_nicestrtonum(g_zfs, optarg, &intval) != 0) { |
643 |
(void) fprintf(stderr, gettext("bad volume " |
|
644 |
"block size '%s': %s\n"), optarg, |
|
645 |
libzfs_error_description(g_zfs)); |
|
646 |
goto error; |
|
647 |
} |
|
648 |
||
649 |
if (nvlist_add_uint64(props, |
|
650 |
zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE), |
|
651 |
intval) != 0) { |
|
652 |
(void) fprintf(stderr, gettext("internal " |
|
653 |
"error: out of memory\n")); |
|
654 |
goto error; |
|
655 |
} |
|
656 |
break; |
|
657 |
case 'o': |
|
7265 | 658 |
if (parseprop(props)) |
2676 | 659 |
goto error; |
789 | 660 |
break; |
661 |
case 's': |
|
2082 | 662 |
noreserve = B_TRUE; |
789 | 663 |
break; |
664 |
case ':': |
|
665 |
(void) fprintf(stderr, gettext("missing size " |
|
666 |
"argument\n")); |
|
2676 | 667 |
goto badusage; |
789 | 668 |
break; |
669 |
case '?': |
|
670 |
(void) fprintf(stderr, gettext("invalid option '%c'\n"), |
|
671 |
optopt); |
|
2676 | 672 |
goto badusage; |
789 | 673 |
} |
674 |
} |
|
675 |
||
5367 | 676 |
if ((bflag || noreserve) && type != ZFS_TYPE_VOLUME) { |
677 |
(void) fprintf(stderr, gettext("'-s' and '-b' can only be " |
|
678 |
"used when creating a volume\n")); |
|
2676 | 679 |
goto badusage; |
789 | 680 |
} |
681 |
||
682 |
argc -= optind; |
|
683 |
argv += optind; |
|
684 |
||
685 |
/* check number of arguments */ |
|
686 |
if (argc == 0) { |
|
687 |
(void) fprintf(stderr, gettext("missing %s argument\n"), |
|
688 |
zfs_type_to_name(type)); |
|
2676 | 689 |
goto badusage; |
789 | 690 |
} |
691 |
if (argc > 1) { |
|
692 |
(void) fprintf(stderr, gettext("too many arguments\n")); |
|
2676 | 693 |
goto badusage; |
694 |
} |
|
695 |
||
5481
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
696 |
if (type == ZFS_TYPE_VOLUME && !noreserve) { |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
697 |
zpool_handle_t *zpool_handle; |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
698 |
uint64_t spa_version; |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
699 |
char *p; |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
700 |
zfs_prop_t resv_prop; |
7265 | 701 |
char *strval; |
5481
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
702 |
|
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
703 |
if (p = strchr(argv[0], '/')) |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
704 |
*p = '\0'; |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
705 |
zpool_handle = zpool_open(g_zfs, argv[0]); |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
706 |
if (p != NULL) |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
707 |
*p = '/'; |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
708 |
if (zpool_handle == NULL) |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
709 |
goto error; |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
710 |
spa_version = zpool_get_prop_int(zpool_handle, |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
711 |
ZPOOL_PROP_VERSION, NULL); |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
712 |
zpool_close(zpool_handle); |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
713 |
if (spa_version >= SPA_VERSION_REFRESERVATION) |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
714 |
resv_prop = ZFS_PROP_REFRESERVATION; |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
715 |
else |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
716 |
resv_prop = ZFS_PROP_RESERVATION; |
11449
a6be67f77b9f
6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
11417
diff
changeset
|
717 |
volsize = zvol_volsize_to_reservation(volsize, props); |
5481
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
718 |
|
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
719 |
if (nvlist_lookup_string(props, zfs_prop_to_name(resv_prop), |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
720 |
&strval) != 0) { |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
721 |
if (nvlist_add_uint64(props, |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
722 |
zfs_prop_to_name(resv_prop), volsize) != 0) { |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
723 |
(void) fprintf(stderr, gettext("internal " |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
724 |
"error: out of memory\n")); |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
725 |
nvlist_free(props); |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
726 |
return (1); |
1364fb7de75d
6619182 new non-sparse zvols should get refreservations
ck153898
parents:
5446
diff
changeset
|
727 |
} |
2676 | 728 |
} |
789 | 729 |
} |
730 |
||
4490 | 731 |
if (parents && zfs_name_valid(argv[0], type)) { |
732 |
/* |
|
733 |
* Now create the ancestors of target dataset. If the target |
|
734 |
* already exists and '-p' option was used we should not |
|
735 |
* complain. |
|
736 |
*/ |
|
737 |
if (zfs_dataset_exists(g_zfs, argv[0], type)) { |
|
738 |
ret = 0; |
|
739 |
goto error; |
|
740 |
} |
|
741 |
if (zfs_create_ancestors(g_zfs, argv[0]) != 0) |
|
742 |
goto error; |
|
743 |
} |
|
744 |
||
789 | 745 |
/* pass to libzfs */ |
2676 | 746 |
if (zfs_create(g_zfs, argv[0], type, props) != 0) |
747 |
goto error; |
|
789 | 748 |
|
5094 | 749 |
if ((zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_DATASET)) == NULL) |
2676 | 750 |
goto error; |
6168
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
751 |
/* |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
752 |
* if the user doesn't want the dataset automatically mounted, |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
753 |
* then skip the mount/share step |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
754 |
*/ |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
755 |
|
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
756 |
canmount = zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT); |
789 | 757 |
|
758 |
/* |
|
759 |
* Mount and/or share the new filesystem as appropriate. We provide a |
|
760 |
* verbose error message to let the user know that their filesystem was |
|
761 |
* in fact created, even if we failed to mount or share it. |
|
762 |
*/ |
|
6168
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
763 |
ret = 0; |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
764 |
if (canmount == ZFS_CANMOUNT_ON) { |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
765 |
if (zfs_mount(zhp, NULL, 0) != 0) { |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
766 |
(void) fprintf(stderr, gettext("filesystem " |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
767 |
"successfully created, but not mounted\n")); |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
768 |
ret = 1; |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
769 |
} else if (zfs_share(zhp) != 0) { |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
770 |
(void) fprintf(stderr, gettext("filesystem " |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
771 |
"successfully created, but not shared\n")); |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
772 |
ret = 1; |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
773 |
} |
789 | 774 |
} |
775 |
||
2676 | 776 |
error: |
777 |
if (zhp) |
|
778 |
zfs_close(zhp); |
|
779 |
nvlist_free(props); |
|
789 | 780 |
return (ret); |
2676 | 781 |
badusage: |
782 |
nvlist_free(props); |
|
783 |
usage(B_FALSE); |
|
784 |
return (2); |
|
789 | 785 |
} |
786 |
||
787 |
/* |
|
10385
21cb6e67d108
6873727 zfs destroy -d <fs> should fail more gracefully when children are present
Chris Kirby <chris.kirby@sun.com>
parents:
10342
diff
changeset
|
788 |
* zfs destroy [-rRf] <fs, vol> |
21cb6e67d108
6873727 zfs destroy -d <fs> should fail more gracefully when children are present
Chris Kirby <chris.kirby@sun.com>
parents:
10342
diff
changeset
|
789 |
* zfs destroy [-rRd] <snap> |
789 | 790 |
* |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
791 |
* -r Recursively destroy all children |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
792 |
* -R Recursively destroy all dependents, including clones |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
793 |
* -f Force unmounting of any dependents |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
794 |
* -d If we can't destroy now, mark for deferred destruction |
789 | 795 |
* |
796 |
* Destroys the given dataset. By default, it will unmount any filesystems, |
|
797 |
* and refuse to destroy a dataset that has any dependents. A dependent can |
|
798 |
* either be a child, or a clone of a child. |
|
799 |
*/ |
|
800 |
typedef struct destroy_cbdata { |
|
2082 | 801 |
boolean_t cb_first; |
789 | 802 |
int cb_force; |
803 |
int cb_recurse; |
|
804 |
int cb_error; |
|
805 |
int cb_needforce; |
|
806 |
int cb_doclones; |
|
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3126
diff
changeset
|
807 |
boolean_t cb_closezhp; |
789 | 808 |
zfs_handle_t *cb_target; |
2199 | 809 |
char *cb_snapname; |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
810 |
boolean_t cb_defer_destroy; |
789 | 811 |
} destroy_cbdata_t; |
812 |
||
813 |
/* |
|
814 |
* Check for any dependents based on the '-r' or '-R' flags. |
|
815 |
*/ |
|
816 |
static int |
|
817 |
destroy_check_dependent(zfs_handle_t *zhp, void *data) |
|
818 |
{ |
|
819 |
destroy_cbdata_t *cbp = data; |
|
820 |
const char *tname = zfs_get_name(cbp->cb_target); |
|
821 |
const char *name = zfs_get_name(zhp); |
|
822 |
||
823 |
if (strncmp(tname, name, strlen(tname)) == 0 && |
|
824 |
(name[strlen(tname)] == '/' || name[strlen(tname)] == '@')) { |
|
825 |
/* |
|
826 |
* This is a direct descendant, not a clone somewhere else in |
|
827 |
* the hierarchy. |
|
828 |
*/ |
|
829 |
if (cbp->cb_recurse) |
|
830 |
goto out; |
|
831 |
||
832 |
if (cbp->cb_first) { |
|
833 |
(void) fprintf(stderr, gettext("cannot destroy '%s': " |
|
834 |
"%s has children\n"), |
|
835 |
zfs_get_name(cbp->cb_target), |
|
836 |
zfs_type_to_name(zfs_get_type(cbp->cb_target))); |
|
837 |
(void) fprintf(stderr, gettext("use '-r' to destroy " |
|
838 |
"the following datasets:\n")); |
|
2082 | 839 |
cbp->cb_first = B_FALSE; |
789 | 840 |
cbp->cb_error = 1; |
841 |
} |
|
842 |
||
843 |
(void) fprintf(stderr, "%s\n", zfs_get_name(zhp)); |
|
844 |
} else { |
|
845 |
/* |
|
846 |
* This is a clone. We only want to report this if the '-r' |
|
847 |
* wasn't specified, or the target is a snapshot. |
|
848 |
*/ |
|
849 |
if (!cbp->cb_recurse && |
|
850 |
zfs_get_type(cbp->cb_target) != ZFS_TYPE_SNAPSHOT) |
|
851 |
goto out; |
|
852 |
||
853 |
if (cbp->cb_first) { |
|
854 |
(void) fprintf(stderr, gettext("cannot destroy '%s': " |
|
855 |
"%s has dependent clones\n"), |
|
856 |
zfs_get_name(cbp->cb_target), |
|
857 |
zfs_type_to_name(zfs_get_type(cbp->cb_target))); |
|
858 |
(void) fprintf(stderr, gettext("use '-R' to destroy " |
|
859 |
"the following datasets:\n")); |
|
2082 | 860 |
cbp->cb_first = B_FALSE; |
789 | 861 |
cbp->cb_error = 1; |
862 |
} |
|
863 |
||
864 |
(void) fprintf(stderr, "%s\n", zfs_get_name(zhp)); |
|
865 |
} |
|
866 |
||
867 |
out: |
|
868 |
zfs_close(zhp); |
|
869 |
return (0); |
|
870 |
} |
|
871 |
||
872 |
static int |
|
873 |
destroy_callback(zfs_handle_t *zhp, void *data) |
|
874 |
{ |
|
875 |
destroy_cbdata_t *cbp = data; |
|
876 |
||
877 |
/* |
|
878 |
* Ignore pools (which we've already flagged as an error before getting |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10385
diff
changeset
|
879 |
* here). |
789 | 880 |
*/ |
881 |
if (strchr(zfs_get_name(zhp), '/') == NULL && |
|
882 |
zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) { |
|
883 |
zfs_close(zhp); |
|
884 |
return (0); |
|
885 |
} |
|
886 |
||
887 |
/* |
|
888 |
* Bail out on the first error. |
|
889 |
*/ |
|
890 |
if (zfs_unmount(zhp, NULL, cbp->cb_force ? MS_FORCE : 0) != 0 || |
|
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
891 |
zfs_destroy(zhp, cbp->cb_defer_destroy) != 0) { |
789 | 892 |
zfs_close(zhp); |
893 |
return (-1); |
|
894 |
} |
|
895 |
||
896 |
zfs_close(zhp); |
|
897 |
return (0); |
|
898 |
} |
|
899 |
||
2199 | 900 |
static int |
901 |
destroy_snap_clones(zfs_handle_t *zhp, void *arg) |
|
902 |
{ |
|
903 |
destroy_cbdata_t *cbp = arg; |
|
904 |
char thissnap[MAXPATHLEN]; |
|
905 |
zfs_handle_t *szhp; |
|
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3126
diff
changeset
|
906 |
boolean_t closezhp = cbp->cb_closezhp; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3126
diff
changeset
|
907 |
int rv; |
2199 | 908 |
|
909 |
(void) snprintf(thissnap, sizeof (thissnap), |
|
910 |
"%s@%s", zfs_get_name(zhp), cbp->cb_snapname); |
|
911 |
||
912 |
libzfs_print_on_error(g_zfs, B_FALSE); |
|
913 |
szhp = zfs_open(g_zfs, thissnap, ZFS_TYPE_SNAPSHOT); |
|
914 |
libzfs_print_on_error(g_zfs, B_TRUE); |
|
915 |
if (szhp) { |
|
916 |
/* |
|
917 |
* Destroy any clones of this snapshot |
|
918 |
*/ |
|
2474
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
919 |
if (zfs_iter_dependents(szhp, B_FALSE, destroy_callback, |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
920 |
cbp) != 0) { |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
921 |
zfs_close(szhp); |
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3126
diff
changeset
|
922 |
if (closezhp) |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3126
diff
changeset
|
923 |
zfs_close(zhp); |
2474
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
924 |
return (-1); |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
925 |
} |
2199 | 926 |
zfs_close(szhp); |
927 |
} |
|
928 |
||
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3126
diff
changeset
|
929 |
cbp->cb_closezhp = B_TRUE; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3126
diff
changeset
|
930 |
rv = zfs_iter_filesystems(zhp, destroy_snap_clones, arg); |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3126
diff
changeset
|
931 |
if (closezhp) |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3126
diff
changeset
|
932 |
zfs_close(zhp); |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3126
diff
changeset
|
933 |
return (rv); |
2199 | 934 |
} |
789 | 935 |
|
936 |
static int |
|
937 |
zfs_do_destroy(int argc, char **argv) |
|
938 |
{ |
|
939 |
destroy_cbdata_t cb = { 0 }; |
|
940 |
int c; |
|
941 |
zfs_handle_t *zhp; |
|
2199 | 942 |
char *cp; |
10385
21cb6e67d108
6873727 zfs destroy -d <fs> should fail more gracefully when children are present
Chris Kirby <chris.kirby@sun.com>
parents:
10342
diff
changeset
|
943 |
zfs_type_t type = ZFS_TYPE_DATASET; |
789 | 944 |
|
945 |
/* check options */ |
|
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
946 |
while ((c = getopt(argc, argv, "dfrR")) != -1) { |
789 | 947 |
switch (c) { |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
948 |
case 'd': |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
949 |
cb.cb_defer_destroy = B_TRUE; |
10385
21cb6e67d108
6873727 zfs destroy -d <fs> should fail more gracefully when children are present
Chris Kirby <chris.kirby@sun.com>
parents:
10342
diff
changeset
|
950 |
type = ZFS_TYPE_SNAPSHOT; |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
951 |
break; |
789 | 952 |
case 'f': |
953 |
cb.cb_force = 1; |
|
954 |
break; |
|
955 |
case 'r': |
|
956 |
cb.cb_recurse = 1; |
|
957 |
break; |
|
958 |
case 'R': |
|
959 |
cb.cb_recurse = 1; |
|
960 |
cb.cb_doclones = 1; |
|
961 |
break; |
|
962 |
case '?': |
|
963 |
default: |
|
964 |
(void) fprintf(stderr, gettext("invalid option '%c'\n"), |
|
965 |
optopt); |
|
2082 | 966 |
usage(B_FALSE); |
789 | 967 |
} |
968 |
} |
|
969 |
||
970 |
argc -= optind; |
|
971 |
argv += optind; |
|
972 |
||
973 |
/* check number of arguments */ |
|
974 |
if (argc == 0) { |
|
975 |
(void) fprintf(stderr, gettext("missing path argument\n")); |
|
2082 | 976 |
usage(B_FALSE); |
789 | 977 |
} |
978 |
if (argc > 1) { |
|
979 |
(void) fprintf(stderr, gettext("too many arguments\n")); |
|
2082 | 980 |
usage(B_FALSE); |
789 | 981 |
} |
982 |
||
2199 | 983 |
/* |
984 |
* If we are doing recursive destroy of a snapshot, then the |
|
985 |
* named snapshot may not exist. Go straight to libzfs. |
|
986 |
*/ |
|
987 |
if (cb.cb_recurse && (cp = strchr(argv[0], '@'))) { |
|
988 |
int ret; |
|
989 |
||
990 |
*cp = '\0'; |
|
5094 | 991 |
if ((zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_DATASET)) == NULL) |
2199 | 992 |
return (1); |
993 |
*cp = '@'; |
|
994 |
cp++; |
|
995 |
||
996 |
if (cb.cb_doclones) { |
|
10385
21cb6e67d108
6873727 zfs destroy -d <fs> should fail more gracefully when children are present
Chris Kirby <chris.kirby@sun.com>
parents:
10342
diff
changeset
|
997 |
boolean_t defer = cb.cb_defer_destroy; |
21cb6e67d108
6873727 zfs destroy -d <fs> should fail more gracefully when children are present
Chris Kirby <chris.kirby@sun.com>
parents:
10342
diff
changeset
|
998 |
|
21cb6e67d108
6873727 zfs destroy -d <fs> should fail more gracefully when children are present
Chris Kirby <chris.kirby@sun.com>
parents:
10342
diff
changeset
|
999 |
/* |
21cb6e67d108
6873727 zfs destroy -d <fs> should fail more gracefully when children are present
Chris Kirby <chris.kirby@sun.com>
parents:
10342
diff
changeset
|
1000 |
* Temporarily ignore the defer_destroy setting since |
21cb6e67d108
6873727 zfs destroy -d <fs> should fail more gracefully when children are present
Chris Kirby <chris.kirby@sun.com>
parents:
10342
diff
changeset
|
1001 |
* it's not supported for clones. |
21cb6e67d108
6873727 zfs destroy -d <fs> should fail more gracefully when children are present
Chris Kirby <chris.kirby@sun.com>
parents:
10342
diff
changeset
|
1002 |
*/ |
21cb6e67d108
6873727 zfs destroy -d <fs> should fail more gracefully when children are present
Chris Kirby <chris.kirby@sun.com>
parents:
10342
diff
changeset
|
1003 |
cb.cb_defer_destroy = B_FALSE; |
2199 | 1004 |
cb.cb_snapname = cp; |
2474
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
1005 |
if (destroy_snap_clones(zhp, &cb) != 0) { |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
1006 |
zfs_close(zhp); |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
1007 |
return (1); |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
1008 |
} |
10385
21cb6e67d108
6873727 zfs destroy -d <fs> should fail more gracefully when children are present
Chris Kirby <chris.kirby@sun.com>
parents:
10342
diff
changeset
|
1009 |
cb.cb_defer_destroy = defer; |
2199 | 1010 |
} |
1011 |
||
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
1012 |
ret = zfs_destroy_snaps(zhp, cp, cb.cb_defer_destroy); |
2199 | 1013 |
zfs_close(zhp); |
1014 |
if (ret) { |
|
1015 |
(void) fprintf(stderr, |
|
1016 |
gettext("no snapshots destroyed\n")); |
|
1017 |
} |
|
1018 |
return (ret != 0); |
|
1019 |
} |
|
1020 |
||
789 | 1021 |
/* Open the given dataset */ |
10385
21cb6e67d108
6873727 zfs destroy -d <fs> should fail more gracefully when children are present
Chris Kirby <chris.kirby@sun.com>
parents:
10342
diff
changeset
|
1022 |
if ((zhp = zfs_open(g_zfs, argv[0], type)) == NULL) |
789 | 1023 |
return (1); |
1024 |
||
1025 |
cb.cb_target = zhp; |
|
1026 |
||
1027 |
/* |
|
1028 |
* Perform an explicit check for pools before going any further. |
|
1029 |
*/ |
|
1030 |
if (!cb.cb_recurse && strchr(zfs_get_name(zhp), '/') == NULL && |
|
1031 |
zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) { |
|
1032 |
(void) fprintf(stderr, gettext("cannot destroy '%s': " |
|
1033 |
"operation does not apply to pools\n"), |
|
1034 |
zfs_get_name(zhp)); |
|
1035 |
(void) fprintf(stderr, gettext("use 'zfs destroy -r " |
|
1036 |
"%s' to destroy all datasets in the pool\n"), |
|
1037 |
zfs_get_name(zhp)); |
|
1038 |
(void) fprintf(stderr, gettext("use 'zpool destroy %s' " |
|
1039 |
"to destroy the pool itself\n"), zfs_get_name(zhp)); |
|
1040 |
zfs_close(zhp); |
|
1041 |
return (1); |
|
1042 |
} |
|
1043 |
||
1044 |
/* |
|
1045 |
* Check for any dependents and/or clones. |
|
1046 |
*/ |
|
2082 | 1047 |
cb.cb_first = B_TRUE; |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
1048 |
if (!cb.cb_doclones && !cb.cb_defer_destroy && |
2474
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
1049 |
zfs_iter_dependents(zhp, B_TRUE, destroy_check_dependent, |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
1050 |
&cb) != 0) { |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
1051 |
zfs_close(zhp); |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
1052 |
return (1); |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
1053 |
} |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
1054 |
|
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
1055 |
if (cb.cb_error || (!cb.cb_defer_destroy && |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
1056 |
(zfs_iter_dependents(zhp, B_FALSE, destroy_callback, &cb) != 0))) { |
789 | 1057 |
zfs_close(zhp); |
1058 |
return (1); |
|
1059 |
} |
|
1060 |
||
1061 |
/* |
|
2474
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
1062 |
* Do the real thing. The callback will close the handle regardless of |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
1063 |
* whether it succeeds or not. |
789 | 1064 |
*/ |
4543 | 1065 |
|
2474
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
1066 |
if (destroy_callback(zhp, &cb) != 0) |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
1067 |
return (1); |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
1068 |
|
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
1069 |
return (0); |
789 | 1070 |
} |
1071 |
||
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1072 |
static boolean_t |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1073 |
is_recvd_column(zprop_get_cbdata_t *cbp) |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1074 |
{ |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1075 |
int i; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1076 |
zfs_get_column_t col; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1077 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1078 |
for (i = 0; i < ZFS_GET_NCOLS && |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1079 |
(col = cbp->cb_columns[i]) != GET_COL_NONE; i++) |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1080 |
if (col == GET_COL_RECVD) |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1081 |
return (B_TRUE); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1082 |
return (B_FALSE); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1083 |
} |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1084 |
|
789 | 1085 |
/* |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1086 |
* zfs get [-rHp] [-o all | field[,field]...] [-s source[,source]...] |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1087 |
* < all | property[,property]... > < fs | snap | vol > ... |
789 | 1088 |
* |
1089 |
* -r recurse over any child datasets |
|
1090 |
* -H scripted mode. Headers are stripped, and fields are separated |
|
1091 |
* by tabs instead of spaces. |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1092 |
* -o Set of fields to display. One of "name,property,value, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1093 |
* received,source". Default is "name,property,value,source". |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1094 |
* "all" is an alias for all five. |
789 | 1095 |
* -s Set of sources to allow. One of |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1096 |
* "local,default,inherited,received,temporary,none". Default is |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1097 |
* all six. |
789 | 1098 |
* -p Display values in parsable (literal) format. |
1099 |
* |
|
1100 |
* Prints properties for the given datasets. The user can control which |
|
1101 |
* columns to display as well as which property types to allow. |
|
1102 |
*/ |
|
1103 |
||
1104 |
/* |
|
1105 |
* Invoked to display the properties for a single dataset. |
|
1106 |
*/ |
|
1107 |
static int |
|
1108 |
get_callback(zfs_handle_t *zhp, void *data) |
|
1109 |
{ |
|
1110 |
char buf[ZFS_MAXPROPLEN]; |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1111 |
char rbuf[ZFS_MAXPROPLEN]; |
5094 | 1112 |
zprop_source_t sourcetype; |
789 | 1113 |
char source[ZFS_MAXNAMELEN]; |
5094 | 1114 |
zprop_get_cbdata_t *cbp = data; |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1115 |
nvlist_t *user_props = zfs_get_user_props(zhp); |
5094 | 1116 |
zprop_list_t *pl = cbp->cb_proplist; |
2676 | 1117 |
nvlist_t *propval; |
1118 |
char *strval; |
|
1119 |
char *sourceval; |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1120 |
boolean_t received = is_recvd_column(cbp); |
2676 | 1121 |
|
1122 |
for (; pl != NULL; pl = pl->pl_next) { |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1123 |
char *recvdval = NULL; |
2676 | 1124 |
/* |
1125 |
* Skip the special fake placeholder. This will also skip over |
|
1126 |
* the name property when 'all' is specified. |
|
1127 |
*/ |
|
1128 |
if (pl->pl_prop == ZFS_PROP_NAME && |
|
1129 |
pl == cbp->cb_proplist) |
|
1130 |
continue; |
|
1131 |
||
5094 | 1132 |
if (pl->pl_prop != ZPROP_INVAL) { |
2676 | 1133 |
if (zfs_prop_get(zhp, pl->pl_prop, buf, |
1134 |
sizeof (buf), &sourcetype, source, |
|
1135 |
sizeof (source), |
|
1136 |
cbp->cb_literal) != 0) { |
|
1137 |
if (pl->pl_all) |
|
1138 |
continue; |
|
3912 | 1139 |
if (!zfs_prop_valid_for_type(pl->pl_prop, |
5094 | 1140 |
ZFS_TYPE_DATASET)) { |
3912 | 1141 |
(void) fprintf(stderr, |
1142 |
gettext("No such property '%s'\n"), |
|
1143 |
zfs_prop_to_name(pl->pl_prop)); |
|
1144 |
continue; |
|
1145 |
} |
|
5094 | 1146 |
sourcetype = ZPROP_SRC_NONE; |
2676 | 1147 |
(void) strlcpy(buf, "-", sizeof (buf)); |
1148 |
} |
|
1149 |
||
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1150 |
if (received && (zfs_prop_get_recvd(zhp, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1151 |
zfs_prop_to_name(pl->pl_prop), rbuf, sizeof (rbuf), |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1152 |
cbp->cb_literal) == 0)) |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1153 |
recvdval = rbuf; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1154 |
|
5094 | 1155 |
zprop_print_one_property(zfs_get_name(zhp), cbp, |
2676 | 1156 |
zfs_prop_to_name(pl->pl_prop), |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1157 |
buf, sourcetype, source, recvdval); |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1158 |
} else if (zfs_prop_userquota(pl->pl_user_prop)) { |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1159 |
sourcetype = ZPROP_SRC_LOCAL; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1160 |
|
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1161 |
if (zfs_prop_get_userquota(zhp, pl->pl_user_prop, |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1162 |
buf, sizeof (buf), cbp->cb_literal) != 0) { |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1163 |
sourcetype = ZPROP_SRC_NONE; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1164 |
(void) strlcpy(buf, "-", sizeof (buf)); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1165 |
} |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1166 |
|
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1167 |
zprop_print_one_property(zfs_get_name(zhp), cbp, |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1168 |
pl->pl_user_prop, buf, sourcetype, source, NULL); |
2676 | 1169 |
} else { |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1170 |
if (nvlist_lookup_nvlist(user_props, |
2676 | 1171 |
pl->pl_user_prop, &propval) != 0) { |
1172 |
if (pl->pl_all) |
|
1173 |
continue; |
|
5094 | 1174 |
sourcetype = ZPROP_SRC_NONE; |
2676 | 1175 |
strval = "-"; |
1176 |
} else { |
|
1177 |
verify(nvlist_lookup_string(propval, |
|
5094 | 1178 |
ZPROP_VALUE, &strval) == 0); |
2676 | 1179 |
verify(nvlist_lookup_string(propval, |
5094 | 1180 |
ZPROP_SOURCE, &sourceval) == 0); |
2676 | 1181 |
|
1182 |
if (strcmp(sourceval, |
|
1183 |
zfs_get_name(zhp)) == 0) { |
|
5094 | 1184 |
sourcetype = ZPROP_SRC_LOCAL; |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1185 |
} else if (strcmp(sourceval, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1186 |
ZPROP_SOURCE_VAL_RECVD) == 0) { |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1187 |
sourcetype = ZPROP_SRC_RECEIVED; |
2676 | 1188 |
} else { |
5094 | 1189 |
sourcetype = ZPROP_SRC_INHERITED; |
2676 | 1190 |
(void) strlcpy(source, |
1191 |
sourceval, sizeof (source)); |
|
1192 |
} |
|
1193 |
} |
|
1194 |
||
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1195 |
if (received && (zfs_prop_get_recvd(zhp, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1196 |
pl->pl_user_prop, rbuf, sizeof (rbuf), |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1197 |
cbp->cb_literal) == 0)) |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1198 |
recvdval = rbuf; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1199 |
|
5094 | 1200 |
zprop_print_one_property(zfs_get_name(zhp), cbp, |
2676 | 1201 |
pl->pl_user_prop, strval, sourcetype, |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1202 |
source, recvdval); |
866 | 1203 |
} |
789 | 1204 |
} |
1205 |
||
1206 |
return (0); |
|
1207 |
} |
|
1208 |
||
1209 |
static int |
|
1210 |
zfs_do_get(int argc, char **argv) |
|
1211 |
{ |
|
5094 | 1212 |
zprop_get_cbdata_t cb = { 0 }; |
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
1213 |
int i, c, flags = 0; |
2676 | 1214 |
char *value, *fields; |
866 | 1215 |
int ret; |
9365
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
1216 |
int limit = 0; |
5094 | 1217 |
zprop_list_t fake_name = { 0 }; |
789 | 1218 |
|
1219 |
/* |
|
1220 |
* Set up default columns and sources. |
|
1221 |
*/ |
|
5094 | 1222 |
cb.cb_sources = ZPROP_SRC_ALL; |
789 | 1223 |
cb.cb_columns[0] = GET_COL_NAME; |
1224 |
cb.cb_columns[1] = GET_COL_PROPERTY; |
|
1225 |
cb.cb_columns[2] = GET_COL_VALUE; |
|
1226 |
cb.cb_columns[3] = GET_COL_SOURCE; |
|
5094 | 1227 |
cb.cb_type = ZFS_TYPE_DATASET; |
789 | 1228 |
|
1229 |
/* check options */ |
|
9365
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
1230 |
while ((c = getopt(argc, argv, ":d:o:s:rHp")) != -1) { |
789 | 1231 |
switch (c) { |
1232 |
case 'p': |
|
2082 | 1233 |
cb.cb_literal = B_TRUE; |
789 | 1234 |
break; |
9365
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
1235 |
case 'd': |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
1236 |
limit = parse_depth(optarg, &flags); |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
1237 |
break; |
789 | 1238 |
case 'r': |
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
1239 |
flags |= ZFS_ITER_RECURSE; |
789 | 1240 |
break; |
1241 |
case 'H': |
|
2082 | 1242 |
cb.cb_scripted = B_TRUE; |
789 | 1243 |
break; |
1244 |
case ':': |
|
1245 |
(void) fprintf(stderr, gettext("missing argument for " |
|
1246 |
"'%c' option\n"), optopt); |
|
2082 | 1247 |
usage(B_FALSE); |
789 | 1248 |
break; |
1249 |
case 'o': |
|
1250 |
/* |
|
1251 |
* Process the set of columns to display. We zero out |
|
1252 |
* the structure to give us a blank slate. |
|
1253 |
*/ |
|
1254 |
bzero(&cb.cb_columns, sizeof (cb.cb_columns)); |
|
1255 |
i = 0; |
|
1256 |
while (*optarg != '\0') { |
|
1257 |
static char *col_subopts[] = |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1258 |
{ "name", "property", "value", "received", |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1259 |
"source", "all", NULL }; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1260 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1261 |
if (i == ZFS_GET_NCOLS) { |
789 | 1262 |
(void) fprintf(stderr, gettext("too " |
1263 |
"many fields given to -o " |
|
1264 |
"option\n")); |
|
2082 | 1265 |
usage(B_FALSE); |
789 | 1266 |
} |
1267 |
||
1268 |
switch (getsubopt(&optarg, col_subopts, |
|
1269 |
&value)) { |
|
1270 |
case 0: |
|
1271 |
cb.cb_columns[i++] = GET_COL_NAME; |
|
1272 |
break; |
|
1273 |
case 1: |
|
1274 |
cb.cb_columns[i++] = GET_COL_PROPERTY; |
|
1275 |
break; |
|
1276 |
case 2: |
|
1277 |
cb.cb_columns[i++] = GET_COL_VALUE; |
|
1278 |
break; |
|
1279 |
case 3: |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1280 |
cb.cb_columns[i++] = GET_COL_RECVD; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1281 |
flags |= ZFS_ITER_RECVD_PROPS; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1282 |
break; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1283 |
case 4: |
789 | 1284 |
cb.cb_columns[i++] = GET_COL_SOURCE; |
1285 |
break; |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1286 |
case 5: |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1287 |
if (i > 0) { |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1288 |
(void) fprintf(stderr, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1289 |
gettext("\"all\" conflicts " |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1290 |
"with specific fields " |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1291 |
"given to -o option\n")); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1292 |
usage(B_FALSE); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1293 |
} |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1294 |
cb.cb_columns[0] = GET_COL_NAME; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1295 |
cb.cb_columns[1] = GET_COL_PROPERTY; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1296 |
cb.cb_columns[2] = GET_COL_VALUE; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1297 |
cb.cb_columns[3] = GET_COL_RECVD; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1298 |
cb.cb_columns[4] = GET_COL_SOURCE; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1299 |
flags |= ZFS_ITER_RECVD_PROPS; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1300 |
i = ZFS_GET_NCOLS; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1301 |
break; |
789 | 1302 |
default: |
1303 |
(void) fprintf(stderr, |
|
1304 |
gettext("invalid column name " |
|
1305 |
"'%s'\n"), value); |
|
3912 | 1306 |
usage(B_FALSE); |
789 | 1307 |
} |
1308 |
} |
|
1309 |
break; |
|
1310 |
||
1311 |
case 's': |
|
1312 |
cb.cb_sources = 0; |
|
1313 |
while (*optarg != '\0') { |
|
1314 |
static char *source_subopts[] = { |
|
1315 |
"local", "default", "inherited", |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1316 |
"received", "temporary", "none", |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1317 |
NULL }; |
789 | 1318 |
|
1319 |
switch (getsubopt(&optarg, source_subopts, |
|
1320 |
&value)) { |
|
1321 |
case 0: |
|
5094 | 1322 |
cb.cb_sources |= ZPROP_SRC_LOCAL; |
789 | 1323 |
break; |
1324 |
case 1: |
|
5094 | 1325 |
cb.cb_sources |= ZPROP_SRC_DEFAULT; |
789 | 1326 |
break; |
1327 |
case 2: |
|
5094 | 1328 |
cb.cb_sources |= ZPROP_SRC_INHERITED; |
789 | 1329 |
break; |
1330 |
case 3: |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1331 |
cb.cb_sources |= ZPROP_SRC_RECEIVED; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1332 |
break; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1333 |
case 4: |
5094 | 1334 |
cb.cb_sources |= ZPROP_SRC_TEMPORARY; |
789 | 1335 |
break; |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1336 |
case 5: |
5094 | 1337 |
cb.cb_sources |= ZPROP_SRC_NONE; |
789 | 1338 |
break; |
1339 |
default: |
|
1340 |
(void) fprintf(stderr, |
|
1341 |
gettext("invalid source " |
|
1342 |
"'%s'\n"), value); |
|
3912 | 1343 |
usage(B_FALSE); |
789 | 1344 |
} |
1345 |
} |
|
1346 |
break; |
|
1347 |
||
1348 |
case '?': |
|
1349 |
(void) fprintf(stderr, gettext("invalid option '%c'\n"), |
|
1350 |
optopt); |
|
2082 | 1351 |
usage(B_FALSE); |
789 | 1352 |
} |
1353 |
} |
|
1354 |
||
1355 |
argc -= optind; |
|
1356 |
argv += optind; |
|
1357 |
||
1358 |
if (argc < 1) { |
|
1359 |
(void) fprintf(stderr, gettext("missing property " |
|
1360 |
"argument\n")); |
|
2082 | 1361 |
usage(B_FALSE); |
789 | 1362 |
} |
1363 |
||
1364 |
fields = argv[0]; |
|
1365 |
||
5094 | 1366 |
if (zprop_get_list(g_zfs, fields, &cb.cb_proplist, ZFS_TYPE_DATASET) |
1367 |
!= 0) |
|
2082 | 1368 |
usage(B_FALSE); |
789 | 1369 |
|
1370 |
argc--; |
|
1371 |
argv++; |
|
1372 |
||
1373 |
/* |
|
2676 | 1374 |
* As part of zfs_expand_proplist(), we keep track of the maximum column |
1375 |
* width for each property. For the 'NAME' (and 'SOURCE') columns, we |
|
1376 |
* need to know the maximum name length. However, the user likely did |
|
1377 |
* not specify 'name' as one of the properties to fetch, so we need to |
|
1378 |
* make sure we always include at least this property for |
|
1379 |
* print_get_headers() to work properly. |
|
789 | 1380 |
*/ |
2676 | 1381 |
if (cb.cb_proplist != NULL) { |
1382 |
fake_name.pl_prop = ZFS_PROP_NAME; |
|
1383 |
fake_name.pl_width = strlen(gettext("NAME")); |
|
1384 |
fake_name.pl_next = cb.cb_proplist; |
|
1385 |
cb.cb_proplist = &fake_name; |
|
789 | 1386 |
} |
1387 |
||
2676 | 1388 |
cb.cb_first = B_TRUE; |
1389 |
||
789 | 1390 |
/* run for each object */ |
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
1391 |
ret = zfs_for_each(argc, argv, flags, ZFS_TYPE_DATASET, NULL, |
9365
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
1392 |
&cb.cb_proplist, limit, get_callback, &cb); |
2676 | 1393 |
|
1394 |
if (cb.cb_proplist == &fake_name) |
|
5094 | 1395 |
zprop_free_list(fake_name.pl_next); |
2676 | 1396 |
else |
5094 | 1397 |
zprop_free_list(cb.cb_proplist); |
2676 | 1398 |
|
1399 |
return (ret); |
|
789 | 1400 |
} |
1401 |
||
1402 |
/* |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1403 |
* inherit [-rS] <property> <fs|vol> ... |
789 | 1404 |
* |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1405 |
* -r Recurse over all children |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1406 |
* -S Revert to received value, if any |
789 | 1407 |
* |
1408 |
* For each dataset specified on the command line, inherit the given property |
|
1409 |
* from its parent. Inheriting a property at the pool level will cause it to |
|
1410 |
* use the default value. The '-r' flag will recurse over all children, and is |
|
1411 |
* useful for setting a property on a hierarchy-wide basis, regardless of any |
|
1412 |
* local modifications for each dataset. |
|
1413 |
*/ |
|
2926 | 1414 |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1415 |
typedef struct inherit_cbdata { |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1416 |
const char *cb_propname; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1417 |
boolean_t cb_received; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1418 |
} inherit_cbdata_t; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1419 |
|
789 | 1420 |
static int |
7265 | 1421 |
inherit_recurse_cb(zfs_handle_t *zhp, void *data) |
789 | 1422 |
{ |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1423 |
inherit_cbdata_t *cb = data; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1424 |
zfs_prop_t prop = zfs_name_to_prop(cb->cb_propname); |
7265 | 1425 |
|
1426 |
/* |
|
1427 |
* If we're doing it recursively, then ignore properties that |
|
1428 |
* are not valid for this type of dataset. |
|
1429 |
*/ |
|
1430 |
if (prop != ZPROP_INVAL && |
|
1431 |
!zfs_prop_valid_for_type(prop, zfs_get_type(zhp))) |
|
1432 |
return (0); |
|
1433 |
||
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1434 |
return (zfs_prop_inherit(zhp, cb->cb_propname, cb->cb_received) != 0); |
7265 | 1435 |
} |
1436 |
||
1437 |
static int |
|
1438 |
inherit_cb(zfs_handle_t *zhp, void *data) |
|
1439 |
{ |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1440 |
inherit_cbdata_t *cb = data; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1441 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1442 |
return (zfs_prop_inherit(zhp, cb->cb_propname, cb->cb_received) != 0); |
789 | 1443 |
} |
1444 |
||
1445 |
static int |
|
1446 |
zfs_do_inherit(int argc, char **argv) |
|
1447 |
{ |
|
1448 |
int c; |
|
1449 |
zfs_prop_t prop; |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1450 |
inherit_cbdata_t cb = { 0 }; |
4543 | 1451 |
char *propname; |
2926 | 1452 |
int ret; |
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
1453 |
int flags = 0; |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1454 |
boolean_t received = B_FALSE; |
789 | 1455 |
|
1456 |
/* check options */ |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1457 |
while ((c = getopt(argc, argv, "rS")) != -1) { |
789 | 1458 |
switch (c) { |
1459 |
case 'r': |
|
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
1460 |
flags |= ZFS_ITER_RECURSE; |
789 | 1461 |
break; |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1462 |
case 'S': |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1463 |
received = B_TRUE; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1464 |
break; |
789 | 1465 |
case '?': |
1466 |
default: |
|
1467 |
(void) fprintf(stderr, gettext("invalid option '%c'\n"), |
|
1468 |
optopt); |
|
2082 | 1469 |
usage(B_FALSE); |
789 | 1470 |
} |
1471 |
} |
|
1472 |
||
1473 |
argc -= optind; |
|
1474 |
argv += optind; |
|
1475 |
||
1476 |
/* check number of arguments */ |
|
1477 |
if (argc < 1) { |
|
1478 |
(void) fprintf(stderr, gettext("missing property argument\n")); |
|
2082 | 1479 |
usage(B_FALSE); |
789 | 1480 |
} |
1481 |
if (argc < 2) { |
|
1482 |
(void) fprintf(stderr, gettext("missing dataset argument\n")); |
|
2082 | 1483 |
usage(B_FALSE); |
789 | 1484 |
} |
1485 |
||
4543 | 1486 |
propname = argv[0]; |
2676 | 1487 |
argc--; |
1488 |
argv++; |
|
1489 |
||
5094 | 1490 |
if ((prop = zfs_name_to_prop(propname)) != ZPROP_INVAL) { |
2676 | 1491 |
if (zfs_prop_readonly(prop)) { |
1492 |
(void) fprintf(stderr, gettext( |
|
1493 |
"%s property is read-only\n"), |
|
4543 | 1494 |
propname); |
2676 | 1495 |
return (1); |
1496 |
} |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1497 |
if (!zfs_prop_inheritable(prop) && !received) { |
2676 | 1498 |
(void) fprintf(stderr, gettext("'%s' property cannot " |
4543 | 1499 |
"be inherited\n"), propname); |
2676 | 1500 |
if (prop == ZFS_PROP_QUOTA || |
5378
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1501 |
prop == ZFS_PROP_RESERVATION || |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1502 |
prop == ZFS_PROP_REFQUOTA || |
111aa1baa84a
PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents:
5367
diff
changeset
|
1503 |
prop == ZFS_PROP_REFRESERVATION) |
2676 | 1504 |
(void) fprintf(stderr, gettext("use 'zfs set " |
4543 | 1505 |
"%s=none' to clear\n"), propname); |
2676 | 1506 |
return (1); |
1507 |
} |
|
4543 | 1508 |
} else if (!zfs_prop_user(propname)) { |
1509 |
(void) fprintf(stderr, gettext("invalid property '%s'\n"), |
|
1510 |
propname); |
|
2082 | 1511 |
usage(B_FALSE); |
789 | 1512 |
} |
2676 | 1513 |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1514 |
cb.cb_propname = propname; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1515 |
cb.cb_received = received; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1516 |
|
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
1517 |
if (flags & ZFS_ITER_RECURSE) { |
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
1518 |
ret = zfs_for_each(argc, argv, flags, ZFS_TYPE_DATASET, |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1519 |
NULL, NULL, 0, inherit_recurse_cb, &cb); |
7265 | 1520 |
} else { |
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
1521 |
ret = zfs_for_each(argc, argv, flags, ZFS_TYPE_DATASET, |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1522 |
NULL, NULL, 0, inherit_cb, &cb); |
7265 | 1523 |
} |
2926 | 1524 |
|
1525 |
return (ret); |
|
789 | 1526 |
} |
1527 |
||
4577 | 1528 |
typedef struct upgrade_cbdata { |
1529 |
uint64_t cb_numupgraded; |
|
1530 |
uint64_t cb_numsamegraded; |
|
4849
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
1531 |
uint64_t cb_numfailed; |
4577 | 1532 |
uint64_t cb_version; |
1533 |
boolean_t cb_newer; |
|
1534 |
boolean_t cb_foundone; |
|
1535 |
char cb_lastfs[ZFS_MAXNAMELEN]; |
|
1536 |
} upgrade_cbdata_t; |
|
1537 |
||
1538 |
static int |
|
1539 |
same_pool(zfs_handle_t *zhp, const char *name) |
|
1540 |
{ |
|
1541 |
int len1 = strcspn(name, "/@"); |
|
1542 |
const char *zhname = zfs_get_name(zhp); |
|
1543 |
int len2 = strcspn(zhname, "/@"); |
|
1544 |
||
1545 |
if (len1 != len2) |
|
1546 |
return (B_FALSE); |
|
4988
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4860
diff
changeset
|
1547 |
return (strncmp(name, zhname, len1) == 0); |
4577 | 1548 |
} |
1549 |
||
1550 |
static int |
|
1551 |
upgrade_list_callback(zfs_handle_t *zhp, void *data) |
|
1552 |
{ |
|
1553 |
upgrade_cbdata_t *cb = data; |
|
1554 |
int version = zfs_prop_get_int(zhp, ZFS_PROP_VERSION); |
|
1555 |
||
1556 |
/* list if it's old/new */ |
|
1557 |
if ((!cb->cb_newer && version < ZPL_VERSION) || |
|
5367 | 1558 |
(cb->cb_newer && version > ZPL_VERSION)) { |
4577 | 1559 |
char *str; |
1560 |
if (cb->cb_newer) { |
|
1561 |
str = gettext("The following filesystems are " |
|
1562 |
"formatted using a newer software version and\n" |
|
1563 |
"cannot be accessed on the current system.\n\n"); |
|
1564 |
} else { |
|
1565 |
str = gettext("The following filesystems are " |
|
1566 |
"out of date, and can be upgraded. After being\n" |
|
1567 |
"upgraded, these filesystems (and any 'zfs send' " |
|
1568 |
"streams generated from\n" |
|
1569 |
"subsequent snapshots) will no longer be " |
|
1570 |
"accessible by older software versions.\n\n"); |
|
1571 |
} |
|
1572 |
||
1573 |
if (!cb->cb_foundone) { |
|
1574 |
(void) puts(str); |
|
1575 |
(void) printf(gettext("VER FILESYSTEM\n")); |
|
1576 |
(void) printf(gettext("--- ------------\n")); |
|
1577 |
cb->cb_foundone = B_TRUE; |
|
1578 |
} |
|
1579 |
||
1580 |
(void) printf("%2u %s\n", version, zfs_get_name(zhp)); |
|
1581 |
} |
|
1582 |
||
1583 |
return (0); |
|
1584 |
} |
|
1585 |
||
1586 |
static int |
|
1587 |
upgrade_set_callback(zfs_handle_t *zhp, void *data) |
|
1588 |
{ |
|
1589 |
upgrade_cbdata_t *cb = data; |
|
1590 |
int version = zfs_prop_get_int(zhp, ZFS_PROP_VERSION); |
|
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1591 |
int i; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1592 |
static struct { int zplver; int spaver; } table[] = { |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1593 |
{ZPL_VERSION_FUID, SPA_VERSION_FUID}, |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1594 |
{ZPL_VERSION_USERSPACE, SPA_VERSION_USERSPACE}, |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1595 |
{0, 0} |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1596 |
}; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1597 |
|
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1598 |
|
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1599 |
for (i = 0; table[i].zplver; i++) { |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1600 |
if (cb->cb_version >= table[i].zplver) { |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1601 |
int spa_version; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1602 |
|
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1603 |
if (zfs_spa_version(zhp, &spa_version) < 0) |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1604 |
return (-1); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1605 |
|
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1606 |
if (spa_version < table[i].spaver) { |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1607 |
/* can't upgrade */ |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1608 |
(void) printf(gettext("%s: can not be " |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1609 |
"upgraded; the pool version needs to first " |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1610 |
"be upgraded\nto version %d\n\n"), |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1611 |
zfs_get_name(zhp), table[i].spaver); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1612 |
cb->cb_numfailed++; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1613 |
return (0); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1614 |
} |
5331 | 1615 |
} |
1616 |
} |
|
1617 |
||
4577 | 1618 |
/* upgrade */ |
1619 |
if (version < cb->cb_version) { |
|
1620 |
char verstr[16]; |
|
4849
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
1621 |
(void) snprintf(verstr, sizeof (verstr), |
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
1622 |
"%llu", cb->cb_version); |
4577 | 1623 |
if (cb->cb_lastfs[0] && !same_pool(zhp, cb->cb_lastfs)) { |
1624 |
/* |
|
1625 |
* If they did "zfs upgrade -a", then we could |
|
1626 |
* be doing ioctls to different pools. We need |
|
1627 |
* to log this history once to each pool. |
|
1628 |
*/ |
|
4988
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4860
diff
changeset
|
1629 |
verify(zpool_stage_history(g_zfs, history_str) == 0); |
4577 | 1630 |
} |
1631 |
if (zfs_prop_set(zhp, "version", verstr) == 0) |
|
1632 |
cb->cb_numupgraded++; |
|
4849
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
1633 |
else |
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
1634 |
cb->cb_numfailed++; |
4577 | 1635 |
(void) strcpy(cb->cb_lastfs, zfs_get_name(zhp)); |
1636 |
} else if (version > cb->cb_version) { |
|
1637 |
/* can't downgrade */ |
|
1638 |
(void) printf(gettext("%s: can not be downgraded; " |
|
1639 |
"it is already at version %u\n"), |
|
1640 |
zfs_get_name(zhp), version); |
|
4849
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
1641 |
cb->cb_numfailed++; |
4577 | 1642 |
} else { |
1643 |
cb->cb_numsamegraded++; |
|
1644 |
} |
|
1645 |
return (0); |
|
1646 |
} |
|
1647 |
||
1648 |
/* |
|
1649 |
* zfs upgrade |
|
1650 |
* zfs upgrade -v |
|
1651 |
* zfs upgrade [-r] [-V <version>] <-a | filesystem> |
|
1652 |
*/ |
|
1653 |
static int |
|
1654 |
zfs_do_upgrade(int argc, char **argv) |
|
1655 |
{ |
|
1656 |
boolean_t all = B_FALSE; |
|
1657 |
boolean_t showversions = B_FALSE; |
|
1658 |
int ret; |
|
1659 |
upgrade_cbdata_t cb = { 0 }; |
|
1660 |
char c; |
|
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
1661 |
int flags = ZFS_ITER_ARGS_CAN_BE_PATHS; |
4577 | 1662 |
|
1663 |
/* check options */ |
|
1664 |
while ((c = getopt(argc, argv, "rvV:a")) != -1) { |
|
1665 |
switch (c) { |
|
1666 |
case 'r': |
|
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
1667 |
flags |= ZFS_ITER_RECURSE; |
4577 | 1668 |
break; |
1669 |
case 'v': |
|
1670 |
showversions = B_TRUE; |
|
1671 |
break; |
|
1672 |
case 'V': |
|
1673 |
if (zfs_prop_string_to_index(ZFS_PROP_VERSION, |
|
1674 |
optarg, &cb.cb_version) != 0) { |
|
1675 |
(void) fprintf(stderr, |
|
1676 |
gettext("invalid version %s\n"), optarg); |
|
1677 |
usage(B_FALSE); |
|
1678 |
} |
|
1679 |
break; |
|
1680 |
case 'a': |
|
1681 |
all = B_TRUE; |
|
1682 |
break; |
|
1683 |
case '?': |
|
1684 |
default: |
|
1685 |
(void) fprintf(stderr, gettext("invalid option '%c'\n"), |
|
1686 |
optopt); |
|
1687 |
usage(B_FALSE); |
|
1688 |
} |
|
1689 |
} |
|
1690 |
||
1691 |
argc -= optind; |
|
1692 |
argv += optind; |
|
1693 |
||
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
1694 |
if ((!all && !argc) && ((flags & ZFS_ITER_RECURSE) | cb.cb_version)) |
4577 | 1695 |
usage(B_FALSE); |
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
1696 |
if (showversions && (flags & ZFS_ITER_RECURSE || all || |
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
1697 |
cb.cb_version || argc)) |
4577 | 1698 |
usage(B_FALSE); |
1699 |
if ((all || argc) && (showversions)) |
|
1700 |
usage(B_FALSE); |
|
1701 |
if (all && argc) |
|
1702 |
usage(B_FALSE); |
|
1703 |
||
1704 |
if (showversions) { |
|
1705 |
/* Show info on available versions. */ |
|
1706 |
(void) printf(gettext("The following filesystem versions are " |
|
1707 |
"supported:\n\n")); |
|
1708 |
(void) printf(gettext("VER DESCRIPTION\n")); |
|
1709 |
(void) printf("--- -----------------------------------------" |
|
1710 |
"---------------\n"); |
|
1711 |
(void) printf(gettext(" 1 Initial ZFS filesystem version\n")); |
|
1712 |
(void) printf(gettext(" 2 Enhanced directory entries\n")); |
|
5331 | 1713 |
(void) printf(gettext(" 3 Case insensitive and File system " |
10228
ca7b8ea13ef5
6835751 typo in zfs upgrade -v
stephanie scheffler <Stephanie.Scheffler@Sun.COM>
parents:
9564
diff
changeset
|
1714 |
"unique identifier (FUID)\n")); |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1715 |
(void) printf(gettext(" 4 userquota, groupquota " |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1716 |
"properties\n")); |
4577 | 1717 |
(void) printf(gettext("\nFor more information on a particular " |
1718 |
"version, including supported releases, see:\n\n")); |
|
1719 |
(void) printf("http://www.opensolaris.org/os/community/zfs/" |
|
1720 |
"version/zpl/N\n\n"); |
|
1721 |
(void) printf(gettext("Where 'N' is the version number.\n")); |
|
1722 |
ret = 0; |
|
1723 |
} else if (argc || all) { |
|
1724 |
/* Upgrade filesystems */ |
|
1725 |
if (cb.cb_version == 0) |
|
1726 |
cb.cb_version = ZPL_VERSION; |
|
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
1727 |
ret = zfs_for_each(argc, argv, flags, ZFS_TYPE_FILESYSTEM, |
9365
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
1728 |
NULL, NULL, 0, upgrade_set_callback, &cb); |
4577 | 1729 |
(void) printf(gettext("%llu filesystems upgraded\n"), |
1730 |
cb.cb_numupgraded); |
|
1731 |
if (cb.cb_numsamegraded) { |
|
1732 |
(void) printf(gettext("%llu filesystems already at " |
|
1733 |
"this version\n"), |
|
1734 |
cb.cb_numsamegraded); |
|
1735 |
} |
|
4849
3a61e0a9a953
6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents:
4787
diff
changeset
|
1736 |
if (cb.cb_numfailed != 0) |
4577 | 1737 |
ret = 1; |
1738 |
} else { |
|
1739 |
/* List old-version filesytems */ |
|
1740 |
boolean_t found; |
|
1741 |
(void) printf(gettext("This system is currently running " |
|
1742 |
"ZFS filesystem version %llu.\n\n"), ZPL_VERSION); |
|
1743 |
||
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
1744 |
flags |= ZFS_ITER_RECURSE; |
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
1745 |
ret = zfs_for_each(0, NULL, flags, ZFS_TYPE_FILESYSTEM, |
9365
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
1746 |
NULL, NULL, 0, upgrade_list_callback, &cb); |
4577 | 1747 |
|
1748 |
found = cb.cb_foundone; |
|
1749 |
cb.cb_foundone = B_FALSE; |
|
1750 |
cb.cb_newer = B_TRUE; |
|
1751 |
||
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
1752 |
ret = zfs_for_each(0, NULL, flags, ZFS_TYPE_FILESYSTEM, |
9365
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
1753 |
NULL, NULL, 0, upgrade_list_callback, &cb); |
4577 | 1754 |
|
1755 |
if (!cb.cb_foundone && !found) { |
|
1756 |
(void) printf(gettext("All filesystems are " |
|
1757 |
"formatted with the current version.\n")); |
|
1758 |
} |
|
1759 |
} |
|
1760 |
||
1761 |
return (ret); |
|
1762 |
} |
|
1763 |
||
789 | 1764 |
/* |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1765 |
* zfs userspace |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1766 |
*/ |
9554
787363635b6a
6837523 gnu xgettext's useless comments should be filtered
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9396
diff
changeset
|
1767 |
static int |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1768 |
userspace_cb(void *arg, const char *domain, uid_t rid, uint64_t space) |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1769 |
{ |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1770 |
zfs_userquota_prop_t *typep = arg; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1771 |
zfs_userquota_prop_t p = *typep; |
9554
787363635b6a
6837523 gnu xgettext's useless comments should be filtered
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9396
diff
changeset
|
1772 |
char *name = NULL; |
787363635b6a
6837523 gnu xgettext's useless comments should be filtered
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9396
diff
changeset
|
1773 |
char *ug, *propname; |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1774 |
char namebuf[32]; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1775 |
char sizebuf[32]; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1776 |
|
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1777 |
if (domain == NULL || domain[0] == '\0') { |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1778 |
if (p == ZFS_PROP_GROUPUSED || p == ZFS_PROP_GROUPQUOTA) { |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1779 |
struct group *g = getgrgid(rid); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1780 |
if (g) |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1781 |
name = g->gr_name; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1782 |
} else { |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1783 |
struct passwd *p = getpwuid(rid); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1784 |
if (p) |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1785 |
name = p->pw_name; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1786 |
} |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1787 |
} |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1788 |
|
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1789 |
if (p == ZFS_PROP_GROUPUSED || p == ZFS_PROP_GROUPQUOTA) |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1790 |
ug = "group"; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1791 |
else |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1792 |
ug = "user"; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1793 |
|
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1794 |
if (p == ZFS_PROP_USERUSED || p == ZFS_PROP_GROUPUSED) |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1795 |
propname = "used"; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1796 |
else |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1797 |
propname = "quota"; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1798 |
|
9554
787363635b6a
6837523 gnu xgettext's useless comments should be filtered
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9396
diff
changeset
|
1799 |
if (name == NULL) { |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1800 |
(void) snprintf(namebuf, sizeof (namebuf), |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1801 |
"%llu", (longlong_t)rid); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1802 |
name = namebuf; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1803 |
} |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1804 |
zfs_nicenum(space, sizebuf, sizeof (sizebuf)); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1805 |
|
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1806 |
(void) printf("%s %s %s%c%s %s\n", propname, ug, domain, |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1807 |
domain[0] ? '-' : ' ', name, sizebuf); |
9554
787363635b6a
6837523 gnu xgettext's useless comments should be filtered
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9396
diff
changeset
|
1808 |
|
787363635b6a
6837523 gnu xgettext's useless comments should be filtered
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9396
diff
changeset
|
1809 |
return (0); |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1810 |
} |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1811 |
|
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1812 |
static int |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1813 |
zfs_do_userspace(int argc, char **argv) |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1814 |
{ |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1815 |
zfs_handle_t *zhp; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1816 |
zfs_userquota_prop_t p; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1817 |
int error; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1818 |
|
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1819 |
/* |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1820 |
* Try the python version. If the execv fails, we'll continue |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1821 |
* and do a simplistic implementation. |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1822 |
*/ |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1823 |
(void) execv(pypath, argv-1); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1824 |
|
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1825 |
(void) printf("internal error: %s not found\n" |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1826 |
"falling back on built-in implementation, " |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1827 |
"some features will not work\n", pypath); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1828 |
|
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1829 |
if ((zhp = zfs_open(g_zfs, argv[argc-1], ZFS_TYPE_DATASET)) == NULL) |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1830 |
return (1); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1831 |
|
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1832 |
(void) printf("PROP TYPE NAME VALUE\n"); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1833 |
|
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1834 |
for (p = 0; p < ZFS_NUM_USERQUOTA_PROPS; p++) { |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1835 |
error = zfs_userspace(zhp, p, userspace_cb, &p); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1836 |
if (error) |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1837 |
break; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1838 |
} |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1839 |
return (error); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1840 |
} |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1841 |
|
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1842 |
/* |
9365
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
1843 |
* list [-r][-d max] [-H] [-o property[,property]...] [-t type[,type]...] |
2379 | 1844 |
* [-s property [-s property]...] [-S property [-S property]...] |
1845 |
* <dataset> ... |
|
789 | 1846 |
* |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1847 |
* -r Recurse over all children |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1848 |
* -d Limit recursion by depth. |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1849 |
* -H Scripted mode; elide headers and separate columns by tabs |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1850 |
* -o Control which fields to display. |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1851 |
* -t Control which object types to display. |
2379 | 1852 |
* -s Specify sort columns, descending order. |
1853 |
* -S Specify sort columns, ascending order. |
|
789 | 1854 |
* |
1855 |
* When given no arguments, lists all filesystems in the system. |
|
1856 |
* Otherwise, list the specified datasets, optionally recursing down them if |
|
1857 |
* '-r' is specified. |
|
1858 |
*/ |
|
1859 |
typedef struct list_cbdata { |
|
2082 | 1860 |
boolean_t cb_first; |
1861 |
boolean_t cb_scripted; |
|
5094 | 1862 |
zprop_list_t *cb_proplist; |
789 | 1863 |
} list_cbdata_t; |
1864 |
||
1865 |
/* |
|
1866 |
* Given a list of columns to display, output appropriate headers for each one. |
|
1867 |
*/ |
|
1868 |
static void |
|
5094 | 1869 |
print_header(zprop_list_t *pl) |
789 | 1870 |
{ |
2676 | 1871 |
char headerbuf[ZFS_MAXPROPLEN]; |
1872 |
const char *header; |
|
789 | 1873 |
int i; |
2676 | 1874 |
boolean_t first = B_TRUE; |
1875 |
boolean_t right_justify; |
|
1876 |
||
1877 |
for (; pl != NULL; pl = pl->pl_next) { |
|
1878 |
if (!first) { |
|
789 | 1879 |
(void) printf(" "); |
2676 | 1880 |
} else { |
1881 |
first = B_FALSE; |
|
1882 |
} |
|
1883 |
||
1884 |
right_justify = B_FALSE; |
|
5094 | 1885 |
if (pl->pl_prop != ZPROP_INVAL) { |
2676 | 1886 |
header = zfs_prop_column_name(pl->pl_prop); |
1887 |
right_justify = zfs_prop_align_right(pl->pl_prop); |
|
1888 |
} else { |
|
1889 |
for (i = 0; pl->pl_user_prop[i] != '\0'; i++) |
|
1890 |
headerbuf[i] = toupper(pl->pl_user_prop[i]); |
|
1891 |
headerbuf[i] = '\0'; |
|
1892 |
header = headerbuf; |
|
1893 |
} |
|
1894 |
||
1895 |
if (pl->pl_next == NULL && !right_justify) |
|
1896 |
(void) printf("%s", header); |
|
1897 |
else if (right_justify) |
|
1898 |
(void) printf("%*s", pl->pl_width, header); |
|
1899 |
else |
|
1900 |
(void) printf("%-*s", pl->pl_width, header); |
|
789 | 1901 |
} |
1902 |
||
1903 |
(void) printf("\n"); |
|
1904 |
} |
|
1905 |
||
1906 |
/* |
|
1907 |
* Given a dataset and a list of fields, print out all the properties according |
|
1908 |
* to the described layout. |
|
1909 |
*/ |
|
1910 |
static void |
|
5094 | 1911 |
print_dataset(zfs_handle_t *zhp, zprop_list_t *pl, boolean_t scripted) |
789 | 1912 |
{ |
2676 | 1913 |
boolean_t first = B_TRUE; |
789 | 1914 |
char property[ZFS_MAXPROPLEN]; |
2676 | 1915 |
nvlist_t *userprops = zfs_get_user_props(zhp); |
1916 |
nvlist_t *propval; |
|
1917 |
char *propstr; |
|
1918 |
boolean_t right_justify; |
|
1919 |
int width; |
|
1920 |
||
1921 |
for (; pl != NULL; pl = pl->pl_next) { |
|
1922 |
if (!first) { |
|
789 | 1923 |
if (scripted) |
1924 |
(void) printf("\t"); |
|
1925 |
else |
|
1926 |
(void) printf(" "); |
|
2676 | 1927 |
} else { |
1928 |
first = B_FALSE; |
|
789 | 1929 |
} |
1930 |
||
5094 | 1931 |
if (pl->pl_prop != ZPROP_INVAL) { |
2676 | 1932 |
if (zfs_prop_get(zhp, pl->pl_prop, property, |
1933 |
sizeof (property), NULL, NULL, 0, B_FALSE) != 0) |
|
1934 |
propstr = "-"; |
|
1935 |
else |
|
1936 |
propstr = property; |
|
1937 |
||
1938 |
right_justify = zfs_prop_align_right(pl->pl_prop); |
|
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1939 |
} else if (zfs_prop_userquota(pl->pl_user_prop)) { |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1940 |
if (zfs_prop_get_userquota(zhp, pl->pl_user_prop, |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1941 |
property, sizeof (property), B_FALSE) != 0) |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1942 |
propstr = "-"; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1943 |
else |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1944 |
propstr = property; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1945 |
right_justify = B_TRUE; |
2676 | 1946 |
} else { |
1947 |
if (nvlist_lookup_nvlist(userprops, |
|
1948 |
pl->pl_user_prop, &propval) != 0) |
|
1949 |
propstr = "-"; |
|
1950 |
else |
|
1951 |
verify(nvlist_lookup_string(propval, |
|
5094 | 1952 |
ZPROP_VALUE, &propstr) == 0); |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
1953 |
right_justify = B_FALSE; |
2676 | 1954 |
} |
1955 |
||
1956 |
width = pl->pl_width; |
|
789 | 1957 |
|
866 | 1958 |
/* |
1959 |
* If this is being called in scripted mode, or if this is the |
|
1960 |
* last column and it is left-justified, don't include a width |
|
1961 |
* format specifier. |
|
1962 |
*/ |
|
2676 | 1963 |
if (scripted || (pl->pl_next == NULL && !right_justify)) |
1964 |
(void) printf("%s", propstr); |
|
1965 |
else if (right_justify) |
|
1966 |
(void) printf("%*s", width, propstr); |
|
1967 |
else |
|
1968 |
(void) printf("%-*s", width, propstr); |
|
789 | 1969 |
} |
1970 |
||
1971 |
(void) printf("\n"); |
|
1972 |
} |
|
1973 |
||
1974 |
/* |
|
1975 |
* Generic callback function to list a dataset or snapshot. |
|
1976 |
*/ |
|
1977 |
static int |
|
1978 |
list_callback(zfs_handle_t *zhp, void *data) |
|
1979 |
{ |
|
1980 |
list_cbdata_t *cbp = data; |
|
1981 |
||
1982 |
if (cbp->cb_first) { |
|
1983 |
if (!cbp->cb_scripted) |
|
2676 | 1984 |
print_header(cbp->cb_proplist); |
2082 | 1985 |
cbp->cb_first = B_FALSE; |
789 | 1986 |
} |
1987 |
||
2676 | 1988 |
print_dataset(zhp, cbp->cb_proplist, cbp->cb_scripted); |
789 | 1989 |
|
1990 |
return (0); |
|
1991 |
} |
|
1992 |
||
1993 |
static int |
|
1994 |
zfs_do_list(int argc, char **argv) |
|
1995 |
{ |
|
1996 |
int c; |
|
2082 | 1997 |
boolean_t scripted = B_FALSE; |
789 | 1998 |
static char default_fields[] = |
1999 |
"name,used,available,referenced,mountpoint"; |
|
8415
d5525cd1cbc2
6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents:
8269
diff
changeset
|
2000 |
int types = ZFS_TYPE_DATASET; |
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
2001 |
boolean_t types_specified = B_FALSE; |
789 | 2002 |
char *fields = NULL; |
2003 |
list_cbdata_t cb = { 0 }; |
|
2004 |
char *value; |
|
9365
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
2005 |
int limit = 0; |
789 | 2006 |
int ret; |
2379 | 2007 |
zfs_sort_column_t *sortcol = NULL; |
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
2008 |
int flags = ZFS_ITER_PROP_LISTSNAPS | ZFS_ITER_ARGS_CAN_BE_PATHS; |
789 | 2009 |
|
2010 |
/* check options */ |
|
9365
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
2011 |
while ((c = getopt(argc, argv, ":d:o:rt:Hs:S:")) != -1) { |
789 | 2012 |
switch (c) { |
2013 |
case 'o': |
|
2014 |
fields = optarg; |
|
2015 |
break; |
|
9365
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
2016 |
case 'd': |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
2017 |
limit = parse_depth(optarg, &flags); |
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
2018 |
break; |
789 | 2019 |
case 'r': |
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
2020 |
flags |= ZFS_ITER_RECURSE; |
789 | 2021 |
break; |
2022 |
case 'H': |
|
2082 | 2023 |
scripted = B_TRUE; |
789 | 2024 |
break; |
2379 | 2025 |
case 's': |
2676 | 2026 |
if (zfs_add_sort_column(&sortcol, optarg, |
2027 |
B_FALSE) != 0) { |
|
2379 | 2028 |
(void) fprintf(stderr, |
2029 |
gettext("invalid property '%s'\n"), optarg); |
|
2030 |
usage(B_FALSE); |
|
2031 |
} |
|
2032 |
break; |
|
2033 |
case 'S': |
|
2676 | 2034 |
if (zfs_add_sort_column(&sortcol, optarg, |
2035 |
B_TRUE) != 0) { |
|
2379 | 2036 |
(void) fprintf(stderr, |
2037 |
gettext("invalid property '%s'\n"), optarg); |
|
2038 |
usage(B_FALSE); |
|
2039 |
} |
|
2040 |
break; |
|
789 | 2041 |
case 't': |
2042 |
types = 0; |
|
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
2043 |
types_specified = B_TRUE; |
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
2044 |
flags &= ~ZFS_ITER_PROP_LISTSNAPS; |
789 | 2045 |
while (*optarg != '\0') { |
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
2046 |
static char *type_subopts[] = { "filesystem", |
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
2047 |
"volume", "snapshot", "all", NULL }; |
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
2048 |
|
789 | 2049 |
switch (getsubopt(&optarg, type_subopts, |
2050 |
&value)) { |
|
2051 |
case 0: |
|
2052 |
types |= ZFS_TYPE_FILESYSTEM; |
|
2053 |
break; |
|
2054 |
case 1: |
|
2055 |
types |= ZFS_TYPE_VOLUME; |
|
2056 |
break; |
|
2057 |
case 2: |
|
2058 |
types |= ZFS_TYPE_SNAPSHOT; |
|
2059 |
break; |
|
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
2060 |
case 3: |
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
2061 |
types = ZFS_TYPE_DATASET; |
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
2062 |
break; |
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
2063 |
|
789 | 2064 |
default: |
2065 |
(void) fprintf(stderr, |
|
2066 |
gettext("invalid type '%s'\n"), |
|
2067 |
value); |
|
2082 | 2068 |
usage(B_FALSE); |
789 | 2069 |
} |
2070 |
} |
|
2071 |
break; |
|
2072 |
case ':': |
|
2073 |
(void) fprintf(stderr, gettext("missing argument for " |
|
2074 |
"'%c' option\n"), optopt); |
|
2082 | 2075 |
usage(B_FALSE); |
789 | 2076 |
break; |
2077 |
case '?': |
|
2078 |
(void) fprintf(stderr, gettext("invalid option '%c'\n"), |
|
2079 |
optopt); |
|
2082 | 2080 |
usage(B_FALSE); |
789 | 2081 |
} |
2082 |
} |
|
2083 |
||
2084 |
argc -= optind; |
|
2085 |
argv += optind; |
|
2086 |
||
2087 |
if (fields == NULL) |
|
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7386
diff
changeset
|
2088 |
fields = default_fields; |
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7386
diff
changeset
|
2089 |
|
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7386
diff
changeset
|
2090 |
/* |
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
2091 |
* If "-o space" and no types were specified, don't display snapshots. |
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7386
diff
changeset
|
2092 |
*/ |
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
2093 |
if (strcmp(fields, "space") == 0 && types_specified == B_FALSE) |
7390
6d408f0a5fbd
PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
7386
diff
changeset
|
2094 |
types &= ~ZFS_TYPE_SNAPSHOT; |
789 | 2095 |
|
866 | 2096 |
/* |
5094 | 2097 |
* If the user specifies '-o all', the zprop_get_list() doesn't |
866 | 2098 |
* normally include the name of the dataset. For 'zfs list', we always |
2099 |
* want this property to be first. |
|
2100 |
*/ |
|
5094 | 2101 |
if (zprop_get_list(g_zfs, fields, &cb.cb_proplist, ZFS_TYPE_DATASET) |
2102 |
!= 0) |
|
2082 | 2103 |
usage(B_FALSE); |
2676 | 2104 |
|
789 | 2105 |
cb.cb_scripted = scripted; |
2082 | 2106 |
cb.cb_first = B_TRUE; |
789 | 2107 |
|
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
2108 |
ret = zfs_for_each(argc, argv, flags, types, sortcol, &cb.cb_proplist, |
9365
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
2109 |
limit, list_callback, &cb); |
2379 | 2110 |
|
5094 | 2111 |
zprop_free_list(cb.cb_proplist); |
2379 | 2112 |
zfs_free_sort_columns(sortcol); |
789 | 2113 |
|
4221
50b4bab9766b
6540584 zfs list command should not produce "no datasets available" message in script mode
mmusante
parents:
4007
diff
changeset
|
2114 |
if (ret == 0 && cb.cb_first && !cb.cb_scripted) |
789 | 2115 |
(void) printf(gettext("no datasets available\n")); |
2116 |
||
2117 |
return (ret); |
|
2118 |
} |
|
2119 |
||
2120 |
/* |
|
4490 | 2121 |
* zfs rename <fs | snap | vol> <fs | snap | vol> |
2122 |
* zfs rename -p <fs | vol> <fs | vol> |
|
2123 |
* zfs rename -r <snap> <snap> |
|
789 | 2124 |
* |
2125 |
* Renames the given dataset to another of the same type. |
|
4490 | 2126 |
* |
2127 |
* The '-p' flag creates all the non-existing ancestors of the target first. |
|
789 | 2128 |
*/ |
2129 |
/* ARGSUSED */ |
|
2130 |
static int |
|
2131 |
zfs_do_rename(int argc, char **argv) |
|
2132 |
{ |
|
2133 |
zfs_handle_t *zhp; |
|
4007 | 2134 |
int c; |
2082 | 2135 |
int ret; |
4490 | 2136 |
boolean_t recurse = B_FALSE; |
2137 |
boolean_t parents = B_FALSE; |
|
789 | 2138 |
|
2139 |
/* check options */ |
|
4490 | 2140 |
while ((c = getopt(argc, argv, "pr")) != -1) { |
4007 | 2141 |
switch (c) { |
4490 | 2142 |
case 'p': |
2143 |
parents = B_TRUE; |
|
2144 |
break; |
|
4007 | 2145 |
case 'r': |
4490 | 2146 |
recurse = B_TRUE; |
4007 | 2147 |
break; |
2148 |
case '?': |
|
2149 |
default: |
|
2150 |
(void) fprintf(stderr, gettext("invalid option '%c'\n"), |
|
2151 |
optopt); |
|
2152 |
usage(B_FALSE); |
|
2153 |
} |
|
789 | 2154 |
} |
2155 |
||
4007 | 2156 |
argc -= optind; |
2157 |
argv += optind; |
|
2158 |
||
789 | 2159 |
/* check number of arguments */ |
4007 | 2160 |
if (argc < 1) { |
789 | 2161 |
(void) fprintf(stderr, gettext("missing source dataset " |
2162 |
"argument\n")); |
|
2082 | 2163 |
usage(B_FALSE); |
789 | 2164 |
} |
4007 | 2165 |
if (argc < 2) { |
789 | 2166 |
(void) fprintf(stderr, gettext("missing target dataset " |
2167 |
"argument\n")); |
|
2082 | 2168 |
usage(B_FALSE); |
789 | 2169 |
} |
4007 | 2170 |
if (argc > 2) { |
789 | 2171 |
(void) fprintf(stderr, gettext("too many arguments\n")); |
2082 | 2172 |
usage(B_FALSE); |
789 | 2173 |
} |
2174 |
||
4490 | 2175 |
if (recurse && parents) { |
2176 |
(void) fprintf(stderr, gettext("-p and -r options are mutually " |
|
2177 |
"exclusive\n")); |
|
2178 |
usage(B_FALSE); |
|
2179 |
} |
|
2180 |
||
4007 | 2181 |
if (recurse && strchr(argv[0], '@') == 0) { |
2182 |
(void) fprintf(stderr, gettext("source dataset for recursive " |
|
2183 |
"rename must be a snapshot\n")); |
|
2184 |
usage(B_FALSE); |
|
2185 |
} |
|
2186 |
||
4490 | 2187 |
if ((zhp = zfs_open(g_zfs, argv[0], parents ? ZFS_TYPE_FILESYSTEM | |
5094 | 2188 |
ZFS_TYPE_VOLUME : ZFS_TYPE_DATASET)) == NULL) |
789 | 2189 |
return (1); |
2190 |
||
4490 | 2191 |
/* If we were asked and the name looks good, try to create ancestors. */ |
2192 |
if (parents && zfs_name_valid(argv[1], zfs_get_type(zhp)) && |
|
2193 |
zfs_create_ancestors(g_zfs, argv[1]) != 0) { |
|
2194 |
zfs_close(zhp); |
|
2195 |
return (1); |
|
2196 |
} |
|
2197 |
||
4007 | 2198 |
ret = (zfs_rename(zhp, argv[1], recurse) != 0); |
2082 | 2199 |
|
2200 |
zfs_close(zhp); |
|
2201 |
return (ret); |
|
2202 |
} |
|
2203 |
||
2204 |
/* |
|
2205 |
* zfs promote <fs> |
|
2206 |
* |
|
2207 |
* Promotes the given clone fs to be the parent |
|
2208 |
*/ |
|
2209 |
/* ARGSUSED */ |
|
2210 |
static int |
|
2211 |
zfs_do_promote(int argc, char **argv) |
|
2212 |
{ |
|
2213 |
zfs_handle_t *zhp; |
|
2214 |
int ret; |
|
2215 |
||
2216 |
/* check options */ |
|
2217 |
if (argc > 1 && argv[1][0] == '-') { |
|
2218 |
(void) fprintf(stderr, gettext("invalid option '%c'\n"), |
|
2219 |
argv[1][1]); |
|
2220 |
usage(B_FALSE); |
|
2221 |
} |
|
2222 |
||
2223 |
/* check number of arguments */ |
|
2224 |
if (argc < 2) { |
|
2225 |
(void) fprintf(stderr, gettext("missing clone filesystem" |
|
2597 | 2226 |
" argument\n")); |
2082 | 2227 |
usage(B_FALSE); |
2228 |
} |
|
2229 |
if (argc > 2) { |
|
2230 |
(void) fprintf(stderr, gettext("too many arguments\n")); |
|
2231 |
usage(B_FALSE); |
|
2232 |
} |
|
2233 |
||
2234 |
zhp = zfs_open(g_zfs, argv[1], ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME); |
|
2235 |
if (zhp == NULL) |
|
2236 |
return (1); |
|
2237 |
||
2238 |
ret = (zfs_promote(zhp) != 0); |
|
2239 |
||
2926 | 2240 |
|
789 | 2241 |
zfs_close(zhp); |
2242 |
return (ret); |
|
2243 |
} |
|
2244 |
||
2245 |
/* |
|
5568 | 2246 |
* zfs rollback [-rRf] <snapshot> |
789 | 2247 |
* |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2248 |
* -r Delete any intervening snapshots before doing rollback |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2249 |
* -R Delete any snapshots and their clones |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2250 |
* -f ignored for backwards compatability |
789 | 2251 |
* |
2252 |
* Given a filesystem, rollback to a specific snapshot, discarding any changes |
|
2253 |
* since then and making it the active dataset. If more recent snapshots exist, |
|
2254 |
* the command will complain unless the '-r' flag is given. |
|
2255 |
*/ |
|
2256 |
typedef struct rollback_cbdata { |
|
2257 |
uint64_t cb_create; |
|
2082 | 2258 |
boolean_t cb_first; |
789 | 2259 |
int cb_doclones; |
2260 |
char *cb_target; |
|
2261 |
int cb_error; |
|
2082 | 2262 |
boolean_t cb_recurse; |
2263 |
boolean_t cb_dependent; |
|
789 | 2264 |
} rollback_cbdata_t; |
2265 |
||
2266 |
/* |
|
2267 |
* Report any snapshots more recent than the one specified. Used when '-r' is |
|
2268 |
* not specified. We reuse this same callback for the snapshot dependents - if |
|
2269 |
* 'cb_dependent' is set, then this is a dependent and we should report it |
|
2270 |
* without checking the transaction group. |
|
2271 |
*/ |
|
2272 |
static int |
|
2273 |
rollback_check(zfs_handle_t *zhp, void *data) |
|
2274 |
{ |
|
2275 |
rollback_cbdata_t *cbp = data; |
|
2276 |
||
2082 | 2277 |
if (cbp->cb_doclones) { |
2278 |
zfs_close(zhp); |
|
789 | 2279 |
return (0); |
2082 | 2280 |
} |
789 | 2281 |
|
2282 |
if (!cbp->cb_dependent) { |
|
2283 |
if (strcmp(zfs_get_name(zhp), cbp->cb_target) != 0 && |
|
1294
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1264
diff
changeset
|
2284 |
zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT && |
789 | 2285 |
zfs_prop_get_int(zhp, ZFS_PROP_CREATETXG) > |
2286 |
cbp->cb_create) { |
|
2287 |
||
2288 |
if (cbp->cb_first && !cbp->cb_recurse) { |
|
2289 |
(void) fprintf(stderr, gettext("cannot " |
|
2290 |
"rollback to '%s': more recent snapshots " |
|
2291 |
"exist\n"), |
|
2292 |
cbp->cb_target); |
|
2293 |
(void) fprintf(stderr, gettext("use '-r' to " |
|
2294 |
"force deletion of the following " |
|
2295 |
"snapshots:\n")); |
|
2296 |
cbp->cb_first = 0; |
|
2297 |
cbp->cb_error = 1; |
|
2298 |
} |
|
2299 |
||
2300 |
if (cbp->cb_recurse) { |
|
2082 | 2301 |
cbp->cb_dependent = B_TRUE; |
2474
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
2302 |
if (zfs_iter_dependents(zhp, B_TRUE, |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
2303 |
rollback_check, cbp) != 0) { |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
2304 |
zfs_close(zhp); |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
2305 |
return (-1); |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
2306 |
} |
2082 | 2307 |
cbp->cb_dependent = B_FALSE; |
789 | 2308 |
} else { |
2309 |
(void) fprintf(stderr, "%s\n", |
|
2310 |
zfs_get_name(zhp)); |
|
2311 |
} |
|
2312 |
} |
|
2313 |
} else { |
|
2314 |
if (cbp->cb_first && cbp->cb_recurse) { |
|
2315 |
(void) fprintf(stderr, gettext("cannot rollback to " |
|
2316 |
"'%s': clones of previous snapshots exist\n"), |
|
2317 |
cbp->cb_target); |
|
2318 |
(void) fprintf(stderr, gettext("use '-R' to " |
|
2319 |
"force deletion of the following clones and " |
|
2320 |
"dependents:\n")); |
|
2321 |
cbp->cb_first = 0; |
|
2322 |
cbp->cb_error = 1; |
|
2323 |
} |
|
2324 |
||
2325 |
(void) fprintf(stderr, "%s\n", zfs_get_name(zhp)); |
|
2326 |
} |
|
2327 |
||
2328 |
zfs_close(zhp); |
|
2329 |
return (0); |
|
2330 |
} |
|
2331 |
||
2332 |
static int |
|
2333 |
zfs_do_rollback(int argc, char **argv) |
|
2334 |
{ |
|
2335 |
int ret; |
|
2336 |
int c; |
|
5749 | 2337 |
boolean_t force = B_FALSE; |
789 | 2338 |
rollback_cbdata_t cb = { 0 }; |
2339 |
zfs_handle_t *zhp, *snap; |
|
2340 |
char parentname[ZFS_MAXNAMELEN]; |
|
2341 |
char *delim; |
|
2342 |
||
2343 |
/* check options */ |
|
5568 | 2344 |
while ((c = getopt(argc, argv, "rRf")) != -1) { |
789 | 2345 |
switch (c) { |
2346 |
case 'r': |
|
2347 |
cb.cb_recurse = 1; |
|
2348 |
break; |
|
2349 |
case 'R': |
|
2350 |
cb.cb_recurse = 1; |
|
2351 |
cb.cb_doclones = 1; |
|
2352 |
break; |
|
5568 | 2353 |
case 'f': |
5749 | 2354 |
force = B_TRUE; |
5568 | 2355 |
break; |
789 | 2356 |
case '?': |
2357 |
(void) fprintf(stderr, gettext("invalid option '%c'\n"), |
|
2358 |
optopt); |
|
2082 | 2359 |
usage(B_FALSE); |
789 | 2360 |
} |
2361 |
} |
|
2362 |
||
2363 |
argc -= optind; |
|
2364 |
argv += optind; |
|
2365 |
||
2366 |
/* check number of arguments */ |
|
2367 |
if (argc < 1) { |
|
2368 |
(void) fprintf(stderr, gettext("missing dataset argument\n")); |
|
2082 | 2369 |
usage(B_FALSE); |
789 | 2370 |
} |
2371 |
if (argc > 1) { |
|
2372 |
(void) fprintf(stderr, gettext("too many arguments\n")); |
|
2082 | 2373 |
usage(B_FALSE); |
789 | 2374 |
} |
2375 |
||
2376 |
/* open the snapshot */ |
|
2082 | 2377 |
if ((snap = zfs_open(g_zfs, argv[0], ZFS_TYPE_SNAPSHOT)) == NULL) |
789 | 2378 |
return (1); |
2379 |
||
1294
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1264
diff
changeset
|
2380 |
/* open the parent dataset */ |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1264
diff
changeset
|
2381 |
(void) strlcpy(parentname, argv[0], sizeof (parentname)); |
789 | 2382 |
verify((delim = strrchr(parentname, '@')) != NULL); |
2383 |
*delim = '\0'; |
|
5094 | 2384 |
if ((zhp = zfs_open(g_zfs, parentname, ZFS_TYPE_DATASET)) == NULL) { |
789 | 2385 |
zfs_close(snap); |
2386 |
return (1); |
|
2387 |
} |
|
2388 |
||
2389 |
/* |
|
2390 |
* Check for more recent snapshots and/or clones based on the presence |
|
2391 |
* of '-r' and '-R'. |
|
2392 |
*/ |
|
1294
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1264
diff
changeset
|
2393 |
cb.cb_target = argv[0]; |
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1264
diff
changeset
|
2394 |
cb.cb_create = zfs_prop_get_int(snap, ZFS_PROP_CREATETXG); |
2082 | 2395 |
cb.cb_first = B_TRUE; |
789 | 2396 |
cb.cb_error = 0; |
2474
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
2397 |
if ((ret = zfs_iter_children(zhp, rollback_check, &cb)) != 0) |
c001ad7e0c25
6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents:
2379
diff
changeset
|
2398 |
goto out; |
789 | 2399 |
|
2400 |
if ((ret = cb.cb_error) != 0) |
|
2401 |
goto out; |
|
2402 |
||
2403 |
/* |
|
1294
87b43e5de5ee
6364129 need to unmount any child datasets before doing the rollback
lling
parents:
1264
diff
changeset
|
2404 |
* Rollback parent to the given snapshot. |
789 | 2405 |
*/ |
5749 | 2406 |
ret = zfs_rollback(zhp, snap, force); |
789 | 2407 |
|
2408 |
out: |
|
2409 |
zfs_close(snap); |
|
2410 |
zfs_close(zhp); |
|
2411 |
||
2412 |
if (ret == 0) |
|
2413 |
return (0); |
|
2414 |
else |
|
2415 |
return (1); |
|
2416 |
} |
|
2417 |
||
2418 |
/* |
|
2419 |
* zfs set property=value { fs | snap | vol } ... |
|
2420 |
* |
|
2421 |
* Sets the given property for all datasets specified on the command line. |
|
2422 |
*/ |
|
2423 |
typedef struct set_cbdata { |
|
2424 |
char *cb_propname; |
|
2425 |
char *cb_value; |
|
2426 |
} set_cbdata_t; |
|
2427 |
||
2428 |
static int |
|
2429 |
set_callback(zfs_handle_t *zhp, void *data) |
|
2430 |
{ |
|
2431 |
set_cbdata_t *cbp = data; |
|
2432 |
||
2676 | 2433 |
if (zfs_prop_set(zhp, cbp->cb_propname, cbp->cb_value) != 0) { |
2169
0152c8ed1663
6385436 zfs set <property> returns an error, but still sets property value (fix build)
nd150628
parents:
2082
diff
changeset
|
2434 |
switch (libzfs_errno(g_zfs)) { |
0152c8ed1663
6385436 zfs set <property> returns an error, but still sets property value (fix build)
nd150628
parents:
2082
diff
changeset
|
2435 |
case EZFS_MOUNTFAILED: |
0152c8ed1663
6385436 zfs set <property> returns an error, but still sets property value (fix build)
nd150628
parents:
2082
diff
changeset
|
2436 |
(void) fprintf(stderr, gettext("property may be set " |
0152c8ed1663
6385436 zfs set <property> returns an error, but still sets property value (fix build)
nd150628
parents:
2082
diff
changeset
|
2437 |
"but unable to remount filesystem\n")); |
0152c8ed1663
6385436 zfs set <property> returns an error, but still sets property value (fix build)
nd150628
parents:
2082
diff
changeset
|
2438 |
break; |
3126 | 2439 |
case EZFS_SHARENFSFAILED: |
2169
0152c8ed1663
6385436 zfs set <property> returns an error, but still sets property value (fix build)
nd150628
parents:
2082
diff
changeset
|
2440 |
(void) fprintf(stderr, gettext("property may be set " |
0152c8ed1663
6385436 zfs set <property> returns an error, but still sets property value (fix build)
nd150628
parents:
2082
diff
changeset
|
2441 |
"but unable to reshare filesystem\n")); |
0152c8ed1663
6385436 zfs set <property> returns an error, but still sets property value (fix build)
nd150628
parents:
2082
diff
changeset
|
2442 |
break; |
0152c8ed1663
6385436 zfs set <property> returns an error, but still sets property value (fix build)
nd150628
parents:
2082
diff
changeset
|
2443 |
} |
789 | 2444 |
return (1); |
2169
0152c8ed1663
6385436 zfs set <property> returns an error, but still sets property value (fix build)
nd150628
parents:
2082
diff
changeset
|
2445 |
} |
2856 | 2446 |
return (0); |
789 | 2447 |
} |
2448 |
||
2449 |
static int |
|
2450 |
zfs_do_set(int argc, char **argv) |
|
2451 |
{ |
|
2452 |
set_cbdata_t cb; |
|
2926 | 2453 |
int ret; |
789 | 2454 |
|
2455 |
/* check for options */ |
|
2456 |
if (argc > 1 && argv[1][0] == '-') { |
|
2457 |
(void) fprintf(stderr, gettext("invalid option '%c'\n"), |
|
2458 |
argv[1][1]); |
|
2082 | 2459 |
usage(B_FALSE); |
789 | 2460 |
} |
2461 |
||
2462 |
/* check number of arguments */ |
|
2463 |
if (argc < 2) { |
|
2464 |
(void) fprintf(stderr, gettext("missing property=value " |
|
2465 |
"argument\n")); |
|
2082 | 2466 |
usage(B_FALSE); |
789 | 2467 |
} |
2468 |
if (argc < 3) { |
|
2469 |
(void) fprintf(stderr, gettext("missing dataset name\n")); |
|
2082 | 2470 |
usage(B_FALSE); |
789 | 2471 |
} |
2472 |
||
2473 |
/* validate property=value argument */ |
|
2474 |
cb.cb_propname = argv[1]; |
|
6993
ccf0a8c4b9a5
6490524 zfs "set" subcommand should enforce prop=value syntax for sharenfs
sg201626
parents:
6865
diff
changeset
|
2475 |
if (((cb.cb_value = strchr(cb.cb_propname, '=')) == NULL) || |
ccf0a8c4b9a5
6490524 zfs "set" subcommand should enforce prop=value syntax for sharenfs
sg201626
parents:
6865
diff
changeset
|
2476 |
(cb.cb_value[1] == '\0')) { |
789 | 2477 |
(void) fprintf(stderr, gettext("missing value in " |
2478 |
"property=value argument\n")); |
|
2082 | 2479 |
usage(B_FALSE); |
789 | 2480 |
} |
2481 |
||
2482 |
*cb.cb_value = '\0'; |
|
2483 |
cb.cb_value++; |
|
2484 |
||
2485 |
if (*cb.cb_propname == '\0') { |
|
2486 |
(void) fprintf(stderr, |
|
2487 |
gettext("missing property in property=value argument\n")); |
|
2082 | 2488 |
usage(B_FALSE); |
789 | 2489 |
} |
2490 |
||
7538
18c2451107fd
PSARC 2008/469 Excluding snapshot info from 'zfs list'
Rich Morris <Richard.Morris@Sun.COM>
parents:
7390
diff
changeset
|
2491 |
ret = zfs_for_each(argc - 2, argv + 2, NULL, |
9365
7838a22eccd6
PSARC/2009/171 zfs list -d and zfs get -d
Chris Gerhard <Chris.Gerhard@sun.com>
parents:
8811
diff
changeset
|
2492 |
ZFS_TYPE_DATASET, NULL, NULL, 0, set_callback, &cb); |
2926 | 2493 |
|
2494 |
return (ret); |
|
789 | 2495 |
} |
2496 |
||
2497 |
/* |
|
7265 | 2498 |
* zfs snapshot [-r] [-o prop=value] ... <fs@snap> |
789 | 2499 |
* |
2500 |
* Creates a snapshot with the given name. While functionally equivalent to |
|
5331 | 2501 |
* 'zfs create', it is a separate command to differentiate intent. |
789 | 2502 |
*/ |
2503 |
static int |
|
2504 |
zfs_do_snapshot(int argc, char **argv) |
|
2505 |
{ |
|
4490 | 2506 |
boolean_t recursive = B_FALSE; |
2199 | 2507 |
int ret; |
2508 |
char c; |
|
7265 | 2509 |
nvlist_t *props; |
2510 |
||
2511 |
if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0) { |
|
2512 |
(void) fprintf(stderr, gettext("internal error: " |
|
2513 |
"out of memory\n")); |
|
2514 |
return (1); |
|
2515 |
} |
|
2199 | 2516 |
|
789 | 2517 |
/* check options */ |
7265 | 2518 |
while ((c = getopt(argc, argv, "ro:")) != -1) { |
2199 | 2519 |
switch (c) { |
7265 | 2520 |
case 'o': |
2521 |
if (parseprop(props)) |
|
2522 |
return (1); |
|
2523 |
break; |
|
2199 | 2524 |
case 'r': |
2525 |
recursive = B_TRUE; |
|
2526 |
break; |
|
2527 |
case '?': |
|
2528 |
(void) fprintf(stderr, gettext("invalid option '%c'\n"), |
|
2529 |
optopt); |
|
7265 | 2530 |
goto usage; |
2199 | 2531 |
} |
789 | 2532 |
} |
2533 |
||
2199 | 2534 |
argc -= optind; |
2535 |
argv += optind; |
|
2536 |
||
789 | 2537 |
/* check number of arguments */ |
2199 | 2538 |
if (argc < 1) { |
789 | 2539 |
(void) fprintf(stderr, gettext("missing snapshot argument\n")); |
7265 | 2540 |
goto usage; |
789 | 2541 |
} |
2199 | 2542 |
if (argc > 1) { |
789 | 2543 |
(void) fprintf(stderr, gettext("too many arguments\n")); |
7265 | 2544 |
goto usage; |
789 | 2545 |
} |
2546 |
||
7265 | 2547 |
ret = zfs_snapshot(g_zfs, argv[0], recursive, props); |
2548 |
nvlist_free(props); |
|
2199 | 2549 |
if (ret && recursive) |
2550 |
(void) fprintf(stderr, gettext("no snapshots were created\n")); |
|
2551 |
return (ret != 0); |
|
7265 | 2552 |
|
2553 |
usage: |
|
2554 |
nvlist_free(props); |
|
2555 |
usage(B_FALSE); |
|
2556 |
return (-1); |
|
789 | 2557 |
} |
2558 |
||
2559 |
/* |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2560 |
* zfs send [-vDp] -R [-i|-I <@snap>] <fs@snap> |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2561 |
* zfs send [-vDp] [-i|-I <@snap>] <fs@snap> |
789 | 2562 |
* |
2563 |
* Send a backup stream to stdout. |
|
2564 |
*/ |
|
2565 |
static int |
|
1749 | 2566 |
zfs_do_send(int argc, char **argv) |
789 | 2567 |
{ |
2568 |
char *fromname = NULL; |
|
5367 | 2569 |
char *toname = NULL; |
2885 | 2570 |
char *cp; |
2571 |
zfs_handle_t *zhp; |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10588
diff
changeset
|
2572 |
sendflags_t flags = { 0 }; |
789 | 2573 |
int c, err; |
2574 |
||
2575 |
/* check options */ |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2576 |
while ((c = getopt(argc, argv, ":i:I:RDpv")) != -1) { |
789 | 2577 |
switch (c) { |
2578 |
case 'i': |
|
2885 | 2579 |
if (fromname) |
2580 |
usage(B_FALSE); |
|
789 | 2581 |
fromname = optarg; |
2582 |
break; |
|
5367 | 2583 |
case 'I': |
2584 |
if (fromname) |
|
2585 |
usage(B_FALSE); |
|
2586 |
fromname = optarg; |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10588
diff
changeset
|
2587 |
flags.doall = B_TRUE; |
5367 | 2588 |
break; |
2589 |
case 'R': |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10588
diff
changeset
|
2590 |
flags.replicate = B_TRUE; |
5367 | 2591 |
break; |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2592 |
case 'p': |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2593 |
flags.props = B_TRUE; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2594 |
break; |
5367 | 2595 |
case 'v': |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10588
diff
changeset
|
2596 |
flags.verbose = B_TRUE; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10588
diff
changeset
|
2597 |
break; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10588
diff
changeset
|
2598 |
case 'D': |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10588
diff
changeset
|
2599 |
flags.dedup = B_TRUE; |
5367 | 2600 |
break; |
789 | 2601 |
case ':': |
2602 |
(void) fprintf(stderr, gettext("missing argument for " |
|
2603 |
"'%c' option\n"), optopt); |
|
2082 | 2604 |
usage(B_FALSE); |
789 | 2605 |
break; |
2606 |
case '?': |
|
2607 |
(void) fprintf(stderr, gettext("invalid option '%c'\n"), |
|
2608 |
optopt); |
|
2082 | 2609 |
usage(B_FALSE); |
789 | 2610 |
} |
2611 |
} |
|
2612 |
||
2613 |
argc -= optind; |
|
2614 |
argv += optind; |
|
2615 |
||
2616 |
/* check number of arguments */ |
|
2617 |
if (argc < 1) { |
|
2618 |
(void) fprintf(stderr, gettext("missing snapshot argument\n")); |
|
2082 | 2619 |
usage(B_FALSE); |
789 | 2620 |
} |
2621 |
if (argc > 1) { |
|
2622 |
(void) fprintf(stderr, gettext("too many arguments\n")); |
|
2082 | 2623 |
usage(B_FALSE); |
789 | 2624 |
} |
2625 |
||
2626 |
if (isatty(STDOUT_FILENO)) { |
|
2627 |
(void) fprintf(stderr, |
|
2885 | 2628 |
gettext("Error: Stream can not be written to a terminal.\n" |
3912 | 2629 |
"You must redirect standard output.\n")); |
789 | 2630 |
return (1); |
2631 |
} |
|
2632 |
||
5367 | 2633 |
cp = strchr(argv[0], '@'); |
2634 |
if (cp == NULL) { |
|
2635 |
(void) fprintf(stderr, |
|
2636 |
gettext("argument must be a snapshot\n")); |
|
2637 |
usage(B_FALSE); |
|
2638 |
} |
|
2639 |
*cp = '\0'; |
|
2640 |
toname = cp + 1; |
|
2641 |
zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME); |
|
2642 |
if (zhp == NULL) |
|
2665 | 2643 |
return (1); |
2644 |
||
2885 | 2645 |
/* |
2646 |
* If they specified the full path to the snapshot, chop off |
|
5367 | 2647 |
* everything except the short name of the snapshot, but special |
2648 |
* case if they specify the origin. |
|
2885 | 2649 |
*/ |
2650 |
if (fromname && (cp = strchr(fromname, '@')) != NULL) { |
|
5367 | 2651 |
char origin[ZFS_MAXNAMELEN]; |
2652 |
zprop_source_t src; |
|
2653 |
||
2654 |
(void) zfs_prop_get(zhp, ZFS_PROP_ORIGIN, |
|
2655 |
origin, sizeof (origin), &src, NULL, 0, B_FALSE); |
|
2656 |
||
2657 |
if (strcmp(origin, fromname) == 0) { |
|
2658 |
fromname = NULL; |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10588
diff
changeset
|
2659 |
flags.fromorigin = B_TRUE; |
5367 | 2660 |
} else { |
2661 |
*cp = '\0'; |
|
2662 |
if (cp != fromname && strcmp(argv[0], fromname)) { |
|
2663 |
(void) fprintf(stderr, |
|
2664 |
gettext("incremental source must be " |
|
2665 |
"in same filesystem\n")); |
|
2666 |
usage(B_FALSE); |
|
2667 |
} |
|
2668 |
fromname = cp + 1; |
|
2669 |
if (strchr(fromname, '@') || strchr(fromname, '/')) { |
|
2670 |
(void) fprintf(stderr, |
|
2671 |
gettext("invalid incremental source\n")); |
|
2672 |
usage(B_FALSE); |
|
2673 |
} |
|
2885 | 2674 |
} |
789 | 2675 |
} |
2676 |
||
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10588
diff
changeset
|
2677 |
if (flags.replicate && fromname == NULL) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10588
diff
changeset
|
2678 |
flags.doall = B_TRUE; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10588
diff
changeset
|
2679 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10588
diff
changeset
|
2680 |
err = zfs_send(zhp, fromname, toname, flags, STDOUT_FILENO, NULL, 0); |
2885 | 2681 |
zfs_close(zhp); |
789 | 2682 |
|
2683 |
return (err != 0); |
|
2684 |
} |
|
2685 |
||
2686 |
/* |
|
11461
5113530c9d30
PSARC 2009/663 zfs receive -e
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11449
diff
changeset
|
2687 |
* zfs receive [-denvF] <fs@snap> |
789 | 2688 |
* |
2689 |
* Restore a backup stream from stdin. |
|
2690 |
*/ |
|
2691 |
static int |
|
1749 | 2692 |
zfs_do_receive(int argc, char **argv) |
789 | 2693 |
{ |
2694 |
int c, err; |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2695 |
recvflags_t flags = { 0 }; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2696 |
|
789 | 2697 |
/* check options */ |
11461
5113530c9d30
PSARC 2009/663 zfs receive -e
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11449
diff
changeset
|
2698 |
while ((c = getopt(argc, argv, ":denuvF")) != -1) { |
789 | 2699 |
switch (c) { |
2700 |
case 'd': |
|
5367 | 2701 |
flags.isprefix = B_TRUE; |
789 | 2702 |
break; |
11461
5113530c9d30
PSARC 2009/663 zfs receive -e
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11449
diff
changeset
|
2703 |
case 'e': |
5113530c9d30
PSARC 2009/663 zfs receive -e
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11449
diff
changeset
|
2704 |
flags.isprefix = B_TRUE; |
5113530c9d30
PSARC 2009/663 zfs receive -e
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11449
diff
changeset
|
2705 |
flags.istail = B_TRUE; |
5113530c9d30
PSARC 2009/663 zfs receive -e
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11449
diff
changeset
|
2706 |
break; |
789 | 2707 |
case 'n': |
5367 | 2708 |
flags.dryrun = B_TRUE; |
789 | 2709 |
break; |
8584
327a1b6dd944
6794452 zfs receive can't restore a root pool
Lori Alt <Lori.Alt@Sun.COM>
parents:
8415
diff
changeset
|
2710 |
case 'u': |
327a1b6dd944
6794452 zfs receive can't restore a root pool
Lori Alt <Lori.Alt@Sun.COM>
parents:
8415
diff
changeset
|
2711 |
flags.nomount = B_TRUE; |
327a1b6dd944
6794452 zfs receive can't restore a root pool
Lori Alt <Lori.Alt@Sun.COM>
parents:
8415
diff
changeset
|
2712 |
break; |
789 | 2713 |
case 'v': |
5367 | 2714 |
flags.verbose = B_TRUE; |
789 | 2715 |
break; |
2665 | 2716 |
case 'F': |
5367 | 2717 |
flags.force = B_TRUE; |
2665 | 2718 |
break; |
789 | 2719 |
case ':': |
2720 |
(void) fprintf(stderr, gettext("missing argument for " |
|
2721 |
"'%c' option\n"), optopt); |
|
2082 | 2722 |
usage(B_FALSE); |
789 | 2723 |
break; |
2724 |
case '?': |
|
2725 |
(void) fprintf(stderr, gettext("invalid option '%c'\n"), |
|
2726 |
optopt); |
|
2082 | 2727 |
usage(B_FALSE); |
789 | 2728 |
} |
2729 |
} |
|
2730 |
||
2731 |
argc -= optind; |
|
2732 |
argv += optind; |
|
2733 |
||
2734 |
/* check number of arguments */ |
|
2735 |
if (argc < 1) { |
|
2736 |
(void) fprintf(stderr, gettext("missing snapshot argument\n")); |
|
2082 | 2737 |
usage(B_FALSE); |
789 | 2738 |
} |
2739 |
if (argc > 1) { |
|
2740 |
(void) fprintf(stderr, gettext("too many arguments\n")); |
|
2082 | 2741 |
usage(B_FALSE); |
789 | 2742 |
} |
2743 |
||
2744 |
if (isatty(STDIN_FILENO)) { |
|
2745 |
(void) fprintf(stderr, |
|
2746 |
gettext("Error: Backup stream can not be read " |
|
3912 | 2747 |
"from a terminal.\n" |
2748 |
"You must redirect standard input.\n")); |
|
789 | 2749 |
return (1); |
2750 |
} |
|
2751 |
||
5367 | 2752 |
err = zfs_receive(g_zfs, argv[0], flags, STDIN_FILENO, NULL); |
2926 | 2753 |
|
4543 | 2754 |
return (err != 0); |
2755 |
} |
|
2756 |
||
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2757 |
static int |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2758 |
zfs_do_hold_rele_impl(int argc, char **argv, boolean_t holding) |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2759 |
{ |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2760 |
int errors = 0; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2761 |
int i; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2762 |
const char *tag; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2763 |
boolean_t recursive = B_FALSE; |
10342
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10242
diff
changeset
|
2764 |
boolean_t temphold = B_FALSE; |
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10242
diff
changeset
|
2765 |
const char *opts = holding ? "rt" : "r"; |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2766 |
int c; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2767 |
|
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2768 |
/* check options */ |
10342
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10242
diff
changeset
|
2769 |
while ((c = getopt(argc, argv, opts)) != -1) { |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2770 |
switch (c) { |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2771 |
case 'r': |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2772 |
recursive = B_TRUE; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2773 |
break; |
10342
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10242
diff
changeset
|
2774 |
case 't': |
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10242
diff
changeset
|
2775 |
temphold = B_TRUE; |
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10242
diff
changeset
|
2776 |
break; |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2777 |
case '?': |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2778 |
(void) fprintf(stderr, gettext("invalid option '%c'\n"), |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2779 |
optopt); |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2780 |
usage(B_FALSE); |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2781 |
} |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2782 |
} |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2783 |
|
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2784 |
argc -= optind; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2785 |
argv += optind; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2786 |
|
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2787 |
/* check number of arguments */ |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2788 |
if (argc < 2) |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2789 |
usage(B_FALSE); |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2790 |
|
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2791 |
tag = argv[0]; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2792 |
--argc; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2793 |
++argv; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2794 |
|
10342
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10242
diff
changeset
|
2795 |
if (holding && tag[0] == '.') { |
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10242
diff
changeset
|
2796 |
/* tags starting with '.' are reserved for libzfs */ |
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10242
diff
changeset
|
2797 |
(void) fprintf(stderr, gettext("tag may not start with '.'\n")); |
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10242
diff
changeset
|
2798 |
usage(B_FALSE); |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2799 |
} |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2800 |
|
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2801 |
for (i = 0; i < argc; ++i) { |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2802 |
zfs_handle_t *zhp; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2803 |
char parent[ZFS_MAXNAMELEN]; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2804 |
const char *delim; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2805 |
char *path = argv[i]; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2806 |
|
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2807 |
delim = strchr(path, '@'); |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2808 |
if (delim == NULL) { |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2809 |
(void) fprintf(stderr, |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2810 |
gettext("'%s' is not a snapshot\n"), path); |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2811 |
++errors; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2812 |
continue; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2813 |
} |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2814 |
(void) strncpy(parent, path, delim - path); |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2815 |
parent[delim - path] = '\0'; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2816 |
|
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2817 |
zhp = zfs_open(g_zfs, parent, |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2818 |
ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME); |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2819 |
if (zhp == NULL) { |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2820 |
++errors; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2821 |
continue; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2822 |
} |
10342
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10242
diff
changeset
|
2823 |
if (holding) { |
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10242
diff
changeset
|
2824 |
if (zfs_hold(zhp, delim+1, tag, recursive, |
11417
de9a68916900
6911611 zfs_send()'s use of snapshot holds is still racy
Chris Kirby <Chris.Kirby@sun.com>
parents:
11022
diff
changeset
|
2825 |
temphold, B_FALSE) != 0) |
10342
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10242
diff
changeset
|
2826 |
++errors; |
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10242
diff
changeset
|
2827 |
} else { |
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10242
diff
changeset
|
2828 |
if (zfs_release(zhp, delim+1, tag, recursive) != 0) |
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10242
diff
changeset
|
2829 |
++errors; |
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10242
diff
changeset
|
2830 |
} |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2831 |
zfs_close(zhp); |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2832 |
} |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2833 |
|
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2834 |
return (errors != 0); |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2835 |
} |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2836 |
|
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2837 |
/* |
10342
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10242
diff
changeset
|
2838 |
* zfs hold [-r] [-t] <tag> <snap> ... |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2839 |
* |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2840 |
* -r Recursively hold |
10342
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10242
diff
changeset
|
2841 |
* -t Temporary hold (hidden option) |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2842 |
* |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2843 |
* Apply a user-hold with the given tag to the list of snapshots. |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2844 |
*/ |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2845 |
static int |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2846 |
zfs_do_hold(int argc, char **argv) |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2847 |
{ |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2848 |
return (zfs_do_hold_rele_impl(argc, argv, B_TRUE)); |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2849 |
} |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2850 |
|
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2851 |
/* |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2852 |
* zfs release [-r] <tag> <snap> ... |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2853 |
* |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2854 |
* -r Recursively release |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2855 |
* |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2856 |
* Release a user-hold with the given tag from the list of snapshots. |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2857 |
*/ |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2858 |
static int |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2859 |
zfs_do_release(int argc, char **argv) |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2860 |
{ |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2861 |
return (zfs_do_hold_rele_impl(argc, argv, B_FALSE)); |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2862 |
} |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10228
diff
changeset
|
2863 |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2864 |
typedef struct get_all_cbdata { |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2865 |
zfs_handle_t **cb_handles; |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2866 |
size_t cb_alloc; |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2867 |
size_t cb_used; |
3126 | 2868 |
uint_t cb_types; |
4737 | 2869 |
boolean_t cb_verbose; |
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2870 |
} get_all_cbdata_t; |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2871 |
|
4737 | 2872 |
#define CHECK_SPINNER 30 |
2873 |
#define SPINNER_TIME 3 /* seconds */ |
|
2874 |
#define MOUNT_TIME 5 /* seconds */ |
|
2875 |
||
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2876 |
static int |
3126 | 2877 |
get_one_dataset(zfs_handle_t *zhp, void *data) |
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2878 |
{ |
4737 | 2879 |
static char spin[] = { '-', '\\', '|', '/' }; |
2880 |
static int spinval = 0; |
|
2881 |
static int spincheck = 0; |
|
2882 |
static time_t last_spin_time = (time_t)0; |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2883 |
get_all_cbdata_t *cbp = data; |
3126 | 2884 |
zfs_type_t type = zfs_get_type(zhp); |
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2885 |
|
4737 | 2886 |
if (cbp->cb_verbose) { |
2887 |
if (--spincheck < 0) { |
|
2888 |
time_t now = time(NULL); |
|
2889 |
if (last_spin_time + SPINNER_TIME < now) { |
|
2890 |
(void) printf("\b%c", spin[spinval++ % 4]); |
|
2891 |
(void) fflush(stdout); |
|
2892 |
last_spin_time = now; |
|
2893 |
} |
|
2894 |
spincheck = CHECK_SPINNER; |
|
2895 |
} |
|
2896 |
} |
|
2897 |
||
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2898 |
/* |
3126 | 2899 |
* Interate over any nested datasets. |
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2900 |
*/ |
3126 | 2901 |
if (type == ZFS_TYPE_FILESYSTEM && |
2902 |
zfs_iter_filesystems(zhp, get_one_dataset, data) != 0) { |
|
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3126
diff
changeset
|
2903 |
zfs_close(zhp); |
3126 | 2904 |
return (1); |
2905 |
} |
|
2906 |
||
2907 |
/* |
|
2908 |
* Skip any datasets whose type does not match. |
|
2909 |
*/ |
|
2910 |
if ((type & cbp->cb_types) == 0) { |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2911 |
zfs_close(zhp); |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2912 |
return (0); |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2913 |
} |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2914 |
|
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2915 |
if (cbp->cb_alloc == cbp->cb_used) { |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2916 |
zfs_handle_t **handles; |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2917 |
|
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2918 |
if (cbp->cb_alloc == 0) |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2919 |
cbp->cb_alloc = 64; |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2920 |
else |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2921 |
cbp->cb_alloc *= 2; |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2922 |
|
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2923 |
handles = safe_malloc(cbp->cb_alloc * sizeof (void *)); |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2924 |
|
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2925 |
if (cbp->cb_handles) { |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2926 |
bcopy(cbp->cb_handles, handles, |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2927 |
cbp->cb_used * sizeof (void *)); |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2928 |
free(cbp->cb_handles); |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2929 |
} |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2930 |
|
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2931 |
cbp->cb_handles = handles; |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2932 |
} |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2933 |
|
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2934 |
cbp->cb_handles[cbp->cb_used++] = zhp; |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2935 |
|
3126 | 2936 |
return (0); |
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2937 |
} |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2938 |
|
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2939 |
static void |
4737 | 2940 |
get_all_datasets(uint_t types, zfs_handle_t ***dslist, size_t *count, |
2941 |
boolean_t verbose) |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2942 |
{ |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2943 |
get_all_cbdata_t cb = { 0 }; |
3126 | 2944 |
cb.cb_types = types; |
4737 | 2945 |
cb.cb_verbose = verbose; |
2946 |
||
2947 |
if (verbose) { |
|
2948 |
(void) printf("%s: *", gettext("Reading ZFS config")); |
|
2949 |
(void) fflush(stdout); |
|
2950 |
} |
|
3126 | 2951 |
|
2952 |
(void) zfs_iter_root(g_zfs, get_one_dataset, &cb); |
|
2953 |
||
2954 |
*dslist = cb.cb_handles; |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2955 |
*count = cb.cb_used; |
4737 | 2956 |
|
2957 |
if (verbose) { |
|
2958 |
(void) printf("\b%s\n", gettext("done.")); |
|
2959 |
} |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2960 |
} |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2961 |
|
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2962 |
static int |
3126 | 2963 |
dataset_cmp(const void *a, const void *b) |
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2964 |
{ |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2965 |
zfs_handle_t **za = (zfs_handle_t **)a; |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2966 |
zfs_handle_t **zb = (zfs_handle_t **)b; |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2967 |
char mounta[MAXPATHLEN]; |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2968 |
char mountb[MAXPATHLEN]; |
3126 | 2969 |
boolean_t gota, gotb; |
2970 |
||
2971 |
if ((gota = (zfs_get_type(*za) == ZFS_TYPE_FILESYSTEM)) != 0) |
|
2972 |
verify(zfs_prop_get(*za, ZFS_PROP_MOUNTPOINT, mounta, |
|
2973 |
sizeof (mounta), NULL, NULL, 0, B_FALSE) == 0); |
|
2974 |
if ((gotb = (zfs_get_type(*zb) == ZFS_TYPE_FILESYSTEM)) != 0) |
|
2975 |
verify(zfs_prop_get(*zb, ZFS_PROP_MOUNTPOINT, mountb, |
|
2976 |
sizeof (mountb), NULL, NULL, 0, B_FALSE) == 0); |
|
2977 |
||
2978 |
if (gota && gotb) |
|
2979 |
return (strcmp(mounta, mountb)); |
|
2980 |
||
2981 |
if (gota) |
|
2982 |
return (-1); |
|
2983 |
if (gotb) |
|
2984 |
return (1); |
|
2985 |
||
2986 |
return (strcmp(zfs_get_name(a), zfs_get_name(b))); |
|
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
2987 |
} |
789 | 2988 |
|
2989 |
/* |
|
2990 |
* Generic callback for sharing or mounting filesystems. Because the code is so |
|
2991 |
* similar, we have a common function with an extra parameter to determine which |
|
2992 |
* mode we are using. |
|
2993 |
*/ |
|
2994 |
#define OP_SHARE 0x1 |
|
2995 |
#define OP_MOUNT 0x2 |
|
2996 |
||
2997 |
/* |
|
3126 | 2998 |
* Share or mount a dataset. |
789 | 2999 |
*/ |
3000 |
static int |
|
5331 | 3001 |
share_mount_one(zfs_handle_t *zhp, int op, int flags, char *protocol, |
3002 |
boolean_t explicit, const char *options) |
|
789 | 3003 |
{ |
3004 |
char mountpoint[ZFS_MAXPROPLEN]; |
|
3005 |
char shareopts[ZFS_MAXPROPLEN]; |
|
5331 | 3006 |
char smbshareopts[ZFS_MAXPROPLEN]; |
3126 | 3007 |
const char *cmdname = op == OP_SHARE ? "share" : "mount"; |
789 | 3008 |
struct mnttab mnt; |
2676 | 3009 |
uint64_t zoned, canmount; |
3126 | 3010 |
zfs_type_t type = zfs_get_type(zhp); |
5331 | 3011 |
boolean_t shared_nfs, shared_smb; |
3126 | 3012 |
|
3013 |
assert(type & (ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME)); |
|
3014 |
||
3015 |
if (type == ZFS_TYPE_FILESYSTEM) { |
|
3016 |
/* |
|
3017 |
* Check to make sure we can mount/share this dataset. If we |
|
3018 |
* are in the global zone and the filesystem is exported to a |
|
3019 |
* local zone, or if we are in a local zone and the |
|
3020 |
* filesystem is not exported, then it is an error. |
|
3021 |
*/ |
|
3022 |
zoned = zfs_prop_get_int(zhp, ZFS_PROP_ZONED); |
|
3023 |
||
3024 |
if (zoned && getzoneid() == GLOBAL_ZONEID) { |
|
3025 |
if (!explicit) |
|
3026 |
return (0); |
|
3027 |
||
3028 |
(void) fprintf(stderr, gettext("cannot %s '%s': " |
|
3029 |
"dataset is exported to a local zone\n"), cmdname, |
|
3030 |
zfs_get_name(zhp)); |
|
3031 |
return (1); |
|
3032 |
||
3033 |
} else if (!zoned && getzoneid() != GLOBAL_ZONEID) { |
|
3034 |
if (!explicit) |
|
3035 |
return (0); |
|
3036 |
||
3037 |
(void) fprintf(stderr, gettext("cannot %s '%s': " |
|
3038 |
"permission denied\n"), cmdname, |
|
3039 |
zfs_get_name(zhp)); |
|
3040 |
return (1); |
|
3041 |
} |
|
3042 |
||
3043 |
/* |
|
3044 |
* Ignore any filesystems which don't apply to us. This |
|
3045 |
* includes those with a legacy mountpoint, or those with |
|
3046 |
* legacy share options. |
|
3047 |
*/ |
|
3048 |
verify(zfs_prop_get(zhp, ZFS_PROP_MOUNTPOINT, mountpoint, |
|
3049 |
sizeof (mountpoint), NULL, NULL, 0, B_FALSE) == 0); |
|
3050 |
verify(zfs_prop_get(zhp, ZFS_PROP_SHARENFS, shareopts, |
|
3051 |
sizeof (shareopts), NULL, NULL, 0, B_FALSE) == 0); |
|
5331 | 3052 |
verify(zfs_prop_get(zhp, ZFS_PROP_SHARESMB, smbshareopts, |
3053 |
sizeof (smbshareopts), NULL, NULL, 0, B_FALSE) == 0); |
|
3126 | 3054 |
|
5331 | 3055 |
if (op == OP_SHARE && strcmp(shareopts, "off") == 0 && |
3056 |
strcmp(smbshareopts, "off") == 0) { |
|
3126 | 3057 |
if (!explicit) |
789 | 3058 |
return (0); |
3059 |
||
3060 |
(void) fprintf(stderr, gettext("cannot share '%s': " |
|
3061 |
"legacy share\n"), zfs_get_name(zhp)); |
|
3062 |
(void) fprintf(stderr, gettext("use share(1M) to " |
|
8269
03a7e9050cfd
6674216 "zfs share" doesn't work, but "zfs set sharenfs=on" does
Mark J Musante <Mark.Musante@Sun.COM>
parents:
8213
diff
changeset
|
3063 |
"share this filesystem, or set " |
03a7e9050cfd
6674216 "zfs share" doesn't work, but "zfs set sharenfs=on" does
Mark J Musante <Mark.Musante@Sun.COM>
parents:
8213
diff
changeset
|
3064 |
"sharenfs property on\n")); |
789 | 3065 |
return (1); |
3066 |
} |
|
3126 | 3067 |
|
3068 |
/* |
|
3069 |
* We cannot share or mount legacy filesystems. If the |
|
3070 |
* shareopts is non-legacy but the mountpoint is legacy, we |
|
3071 |
* treat it as a legacy share. |
|
3072 |
*/ |
|
3073 |
if (strcmp(mountpoint, "legacy") == 0) { |
|
3074 |
if (!explicit) |
|
3075 |
return (0); |
|
3076 |
||
3077 |
(void) fprintf(stderr, gettext("cannot %s '%s': " |
|
3078 |
"legacy mountpoint\n"), cmdname, zfs_get_name(zhp)); |
|
5367 | 3079 |
(void) fprintf(stderr, gettext("use %s(1M) to " |
3080 |
"%s this filesystem\n"), cmdname, cmdname); |
|
3126 | 3081 |
return (1); |
3082 |
} |
|
3083 |
||
3084 |
if (strcmp(mountpoint, "none") == 0) { |
|
3085 |
if (!explicit) |
|
3086 |
return (0); |
|
3087 |
||
3088 |
(void) fprintf(stderr, gettext("cannot %s '%s': no " |
|
3089 |
"mountpoint set\n"), cmdname, zfs_get_name(zhp)); |
|
3090 |
return (1); |
|
3091 |
} |
|
3092 |
||
6168
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
3093 |
/* |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
3094 |
* canmount explicit outcome |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
3095 |
* on no pass through |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
3096 |
* on yes pass through |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
3097 |
* off no return 0 |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
3098 |
* off yes display error, return 1 |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
3099 |
* noauto no return 0 |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
3100 |
* noauto yes pass through |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
3101 |
*/ |
8269
03a7e9050cfd
6674216 "zfs share" doesn't work, but "zfs set sharenfs=on" does
Mark J Musante <Mark.Musante@Sun.COM>
parents:
8213
diff
changeset
|
3102 |
canmount = zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT); |
6168
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
3103 |
if (canmount == ZFS_CANMOUNT_OFF) { |
3126 | 3104 |
if (!explicit) |
3105 |
return (0); |
|
3106 |
||
3107 |
(void) fprintf(stderr, gettext("cannot %s '%s': " |
|
3108 |
"'canmount' property is set to 'off'\n"), cmdname, |
|
3109 |
zfs_get_name(zhp)); |
|
3110 |
return (1); |
|
6168
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
3111 |
} else if (canmount == ZFS_CANMOUNT_NOAUTO && !explicit) { |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
3112 |
return (0); |
3126 | 3113 |
} |
3114 |
||
3115 |
/* |
|
3116 |
* At this point, we have verified that the mountpoint and/or |
|
3117 |
* shareopts are appropriate for auto management. If the |
|
3118 |
* filesystem is already mounted or shared, return (failing |
|
3119 |
* for explicit requests); otherwise mount or share the |
|
3120 |
* filesystem. |
|
3121 |
*/ |
|
3122 |
switch (op) { |
|
3123 |
case OP_SHARE: |
|
5331 | 3124 |
|
3125 |
shared_nfs = zfs_is_shared_nfs(zhp, NULL); |
|
3126 |
shared_smb = zfs_is_shared_smb(zhp, NULL); |
|
3127 |
||
3128 |
if (shared_nfs && shared_smb || |
|
3129 |
(shared_nfs && strcmp(shareopts, "on") == 0 && |
|
3130 |
strcmp(smbshareopts, "off") == 0) || |
|
3131 |
(shared_smb && strcmp(smbshareopts, "on") == 0 && |
|
3132 |
strcmp(shareopts, "off") == 0)) { |
|
3126 | 3133 |
if (!explicit) |
3134 |
return (0); |
|
3135 |
||
789 | 3136 |
(void) fprintf(stderr, gettext("cannot share " |
3137 |
"'%s': filesystem already shared\n"), |
|
3138 |
zfs_get_name(zhp)); |
|
3139 |
return (1); |
|
3140 |
} |
|
3126 | 3141 |
|
3142 |
if (!zfs_is_mounted(zhp, NULL) && |
|
3143 |
zfs_mount(zhp, NULL, 0) != 0) |
|
3144 |
return (1); |
|
3145 |
||
5331 | 3146 |
if (protocol == NULL) { |
3147 |
if (zfs_shareall(zhp) != 0) |
|
3148 |
return (1); |
|
3149 |
} else if (strcmp(protocol, "nfs") == 0) { |
|
3150 |
if (zfs_share_nfs(zhp)) |
|
3151 |
return (1); |
|
3152 |
} else if (strcmp(protocol, "smb") == 0) { |
|
3153 |
if (zfs_share_smb(zhp)) |
|
3154 |
return (1); |
|
3155 |
} else { |
|
3156 |
(void) fprintf(stderr, gettext("cannot share " |
|
3157 |
"'%s': invalid share type '%s' " |
|
3158 |
"specified\n"), |
|
3159 |
zfs_get_name(zhp), protocol); |
|
3126 | 3160 |
return (1); |
5331 | 3161 |
} |
3162 |
||
3126 | 3163 |
break; |
3164 |
||
3165 |
case OP_MOUNT: |
|
3166 |
if (options == NULL) |
|
3167 |
mnt.mnt_mntopts = ""; |
|
3168 |
else |
|
3169 |
mnt.mnt_mntopts = (char *)options; |
|
3170 |
||
3171 |
if (!hasmntopt(&mnt, MNTOPT_REMOUNT) && |
|
3172 |
zfs_is_mounted(zhp, NULL)) { |
|
3173 |
if (!explicit) |
|
3174 |
return (0); |
|
3175 |
||
789 | 3176 |
(void) fprintf(stderr, gettext("cannot mount " |
3177 |
"'%s': filesystem already mounted\n"), |
|
3178 |
zfs_get_name(zhp)); |
|
3179 |
return (1); |
|
3180 |
} |
|
3126 | 3181 |
|
3182 |
if (zfs_mount(zhp, options, flags) != 0) |
|
3183 |
return (1); |
|
3184 |
break; |
|
789 | 3185 |
} |
3126 | 3186 |
} else { |
3187 |
assert(op == OP_SHARE); |
|
3188 |
||
3189 |
/* |
|
3190 |
* Ignore any volumes that aren't shared. |
|
3191 |
*/ |
|
3192 |
verify(zfs_prop_get(zhp, ZFS_PROP_SHAREISCSI, shareopts, |
|
3193 |
sizeof (shareopts), NULL, NULL, 0, B_FALSE) == 0); |
|
3194 |
||
3195 |
if (strcmp(shareopts, "off") == 0) { |
|
3196 |
if (!explicit) |
|
3197 |
return (0); |
|
3198 |
||
3199 |
(void) fprintf(stderr, gettext("cannot share '%s': " |
|
3200 |
"'shareiscsi' property not set\n"), |
|
3201 |
zfs_get_name(zhp)); |
|
3202 |
(void) fprintf(stderr, gettext("set 'shareiscsi' " |
|
3203 |
"property or use iscsitadm(1M) to share this " |
|
3204 |
"volume\n")); |
|
3205 |
return (1); |
|
789 | 3206 |
} |
3126 | 3207 |
|
3208 |
if (zfs_is_shared_iscsi(zhp)) { |
|
3209 |
if (!explicit) |
|
3210 |
return (0); |
|
3211 |
||
3212 |
(void) fprintf(stderr, gettext("cannot share " |
|
3213 |
"'%s': volume already shared\n"), |
|
3214 |
zfs_get_name(zhp)); |
|
789 | 3215 |
return (1); |
3126 | 3216 |
} |
3217 |
||
3218 |
if (zfs_share_iscsi(zhp) != 0) |
|
3219 |
return (1); |
|
789 | 3220 |
} |
3221 |
||
3222 |
return (0); |
|
3223 |
} |
|
3224 |
||
4737 | 3225 |
/* |
3226 |
* Reports progress in the form "(current/total)". Not thread-safe. |
|
3227 |
*/ |
|
3228 |
static void |
|
3229 |
report_mount_progress(int current, int total) |
|
3230 |
{ |
|
3231 |
static int len; |
|
3232 |
static char *reverse = "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b" |
|
3233 |
"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"; |
|
3234 |
static time_t last_progress_time; |
|
3235 |
time_t now = time(NULL); |
|
3236 |
||
3237 |
/* report 1..n instead of 0..n-1 */ |
|
3238 |
++current; |
|
3239 |
||
3240 |
/* display header if we're here for the first time */ |
|
3241 |
if (current == 1) { |
|
3242 |
(void) printf(gettext("Mounting ZFS filesystems: ")); |
|
3243 |
len = 0; |
|
5367 | 3244 |
} else if (current != total && last_progress_time + MOUNT_TIME >= now) { |
3245 |
/* too soon to report again */ |
|
3246 |
return; |
|
3247 |
} |
|
4737 | 3248 |
|
3249 |
last_progress_time = now; |
|
3250 |
||
3251 |
/* back up to prepare for overwriting */ |
|
3252 |
if (len) |
|
3253 |
(void) printf("%*.*s", len, len, reverse); |
|
3254 |
||
3255 |
/* We put a newline at the end if this is the last one. */ |
|
3256 |
len = printf("(%d/%d)%s", current, total, current == total ? "\n" : ""); |
|
3257 |
(void) fflush(stdout); |
|
3258 |
} |
|
3259 |
||
6289
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3260 |
static void |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3261 |
append_options(char *mntopts, char *newopts) |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3262 |
{ |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3263 |
int len = strlen(mntopts); |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3264 |
|
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3265 |
/* original length plus new string to append plus 1 for the comma */ |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3266 |
if (len + 1 + strlen(newopts) >= MNT_LINE_MAX) { |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3267 |
(void) fprintf(stderr, gettext("the opts argument for " |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3268 |
"'%c' option is too long (more than %d chars)\n"), |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3269 |
"-o", MNT_LINE_MAX); |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3270 |
usage(B_FALSE); |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3271 |
} |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3272 |
|
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3273 |
if (*mntopts) |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3274 |
mntopts[len++] = ','; |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3275 |
|
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3276 |
(void) strcpy(&mntopts[len], newopts); |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3277 |
} |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3278 |
|
789 | 3279 |
static int |
3126 | 3280 |
share_mount(int op, int argc, char **argv) |
789 | 3281 |
{ |
3282 |
int do_all = 0; |
|
4737 | 3283 |
boolean_t verbose = B_FALSE; |
2372
ecbf1ba25c2e
6449033 PIT nightly fails due to the fix for 6436514
lling
parents:
2369
diff
changeset
|
3284 |
int c, ret = 0; |
6289
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3285 |
char *options = NULL; |
3126 | 3286 |
int types, flags = 0; |
789 | 3287 |
|
3288 |
/* check options */ |
|
4737 | 3289 |
while ((c = getopt(argc, argv, op == OP_MOUNT ? ":avo:O" : "a")) |
789 | 3290 |
!= -1) { |
3291 |
switch (c) { |
|
3292 |
case 'a': |
|
3293 |
do_all = 1; |
|
3294 |
break; |
|
4737 | 3295 |
case 'v': |
3296 |
verbose = B_TRUE; |
|
3297 |
break; |
|
789 | 3298 |
case 'o': |
6289
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3299 |
if (*optarg == '\0') { |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3300 |
(void) fprintf(stderr, gettext("empty mount " |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3301 |
"options (-o) specified\n")); |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3302 |
usage(B_FALSE); |
4717
20ba35462dba
6579753 segmentation fault if zfs mount -o with very long options
rm160521
parents:
4715
diff
changeset
|
3303 |
} |
6289
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3304 |
|
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3305 |
if (options == NULL) |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3306 |
options = safe_malloc(MNT_LINE_MAX + 1); |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3307 |
|
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3308 |
/* option validation is done later */ |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3309 |
append_options(options, optarg); |
789 | 3310 |
break; |
4717
20ba35462dba
6579753 segmentation fault if zfs mount -o with very long options
rm160521
parents:
4715
diff
changeset
|
3311 |
|
789 | 3312 |
case 'O': |
3126 | 3313 |
flags |= MS_OVERLAY; |
789 | 3314 |
break; |
3315 |
case ':': |
|
3316 |
(void) fprintf(stderr, gettext("missing argument for " |
|
3317 |
"'%c' option\n"), optopt); |
|
2082 | 3318 |
usage(B_FALSE); |
789 | 3319 |
break; |
3320 |
case '?': |
|
3321 |
(void) fprintf(stderr, gettext("invalid option '%c'\n"), |
|
3322 |
optopt); |
|
2082 | 3323 |
usage(B_FALSE); |
789 | 3324 |
} |
3325 |
} |
|
3326 |
||
3327 |
argc -= optind; |
|
3328 |
argv += optind; |
|
3329 |
||
3330 |
/* check number of arguments */ |
|
3331 |
if (do_all) { |
|
3126 | 3332 |
zfs_handle_t **dslist = NULL; |
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
3333 |
size_t i, count = 0; |
5331 | 3334 |
char *protocol = NULL; |
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
3335 |
|
3126 | 3336 |
if (op == OP_MOUNT) { |
3337 |
types = ZFS_TYPE_FILESYSTEM; |
|
3338 |
} else if (argc > 0) { |
|
5331 | 3339 |
if (strcmp(argv[0], "nfs") == 0 || |
3340 |
strcmp(argv[0], "smb") == 0) { |
|
3126 | 3341 |
types = ZFS_TYPE_FILESYSTEM; |
3342 |
} else if (strcmp(argv[0], "iscsi") == 0) { |
|
3343 |
types = ZFS_TYPE_VOLUME; |
|
3344 |
} else { |
|
3345 |
(void) fprintf(stderr, gettext("share type " |
|
5331 | 3346 |
"must be 'nfs', 'smb' or 'iscsi'\n")); |
3126 | 3347 |
usage(B_FALSE); |
3348 |
} |
|
5331 | 3349 |
protocol = argv[0]; |
3126 | 3350 |
argc--; |
3351 |
argv++; |
|
3352 |
} else { |
|
3353 |
types = ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME; |
|
3354 |
} |
|
3355 |
||
789 | 3356 |
if (argc != 0) { |
3357 |
(void) fprintf(stderr, gettext("too many arguments\n")); |
|
2082 | 3358 |
usage(B_FALSE); |
789 | 3359 |
} |
3360 |
||
4737 | 3361 |
get_all_datasets(types, &dslist, &count, verbose); |
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
3362 |
|
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
3363 |
if (count == 0) |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
3364 |
return (0); |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
3365 |
|
3126 | 3366 |
qsort(dslist, count, sizeof (void *), dataset_cmp); |
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
3367 |
|
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
3368 |
for (i = 0; i < count; i++) { |
4737 | 3369 |
if (verbose) |
3370 |
report_mount_progress(i, count); |
|
3371 |
||
5331 | 3372 |
if (share_mount_one(dslist[i], op, flags, protocol, |
3373 |
B_FALSE, options) != 0) |
|
2369
8e9197fd3c58
6436514 zfs share on /var/mail needs to be run explicitly after system boots
lling
parents:
2199
diff
changeset
|
3374 |
ret = 1; |
3126 | 3375 |
zfs_close(dslist[i]); |
1356
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
3376 |
} |
e021b5e4aa0e
6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents:
1294
diff
changeset
|
3377 |
|
3126 | 3378 |
free(dslist); |
789 | 3379 |
} else if (argc == 0) { |
3380 |
struct mnttab entry; |
|
3381 |
||
4717
20ba35462dba
6579753 segmentation fault if zfs mount -o with very long options
rm160521
parents:
4715
diff
changeset
|
3382 |
if ((op == OP_SHARE) || (options != NULL)) { |
789 | 3383 |
(void) fprintf(stderr, gettext("missing filesystem " |
4717
20ba35462dba
6579753 segmentation fault if zfs mount -o with very long options
rm160521
parents:
4715
diff
changeset
|
3384 |
"argument (specify -a for all)\n")); |
2082 | 3385 |
usage(B_FALSE); |
789 | 3386 |
} |
3387 |
||
3388 |
/* |
|
3389 |
* When mount is given no arguments, go through /etc/mnttab and |
|
3390 |
* display any active ZFS mounts. We hide any snapshots, since |
|
3391 |
* they are controlled automatically. |
|
3392 |
*/ |
|
3393 |
rewind(mnttab_file); |
|
3394 |
while (getmntent(mnttab_file, &entry) == 0) { |
|
3395 |
if (strcmp(entry.mnt_fstype, MNTTYPE_ZFS) != 0 || |
|
3396 |
strchr(entry.mnt_special, '@') != NULL) |
|
3397 |
continue; |
|
3398 |
||
3399 |
(void) printf("%-30s %s\n", entry.mnt_special, |
|
3400 |
entry.mnt_mountp); |
|
3401 |
} |
|
3402 |
||
3403 |
} else { |
|
3404 |
zfs_handle_t *zhp; |
|
3405 |
||
3126 | 3406 |
types = ZFS_TYPE_FILESYSTEM; |
3407 |
if (op == OP_SHARE) |
|
3408 |
types |= ZFS_TYPE_VOLUME; |
|
3409 |
||
789 | 3410 |
if (argc > 1) { |
3411 |
(void) fprintf(stderr, |
|
3412 |
gettext("too many arguments\n")); |
|
2082 | 3413 |
usage(B_FALSE); |
789 | 3414 |
} |
3415 |
||
3126 | 3416 |
if ((zhp = zfs_open(g_zfs, argv[0], types)) == NULL) { |
789 | 3417 |
ret = 1; |
3126 | 3418 |
} else { |
5331 | 3419 |
ret = share_mount_one(zhp, op, flags, NULL, B_TRUE, |
3126 | 3420 |
options); |
789 | 3421 |
zfs_close(zhp); |
3422 |
} |
|
3423 |
} |
|
3424 |
||
3425 |
return (ret); |
|
3426 |
} |
|
3427 |
||
3428 |
/* |
|
3126 | 3429 |
* zfs mount -a [nfs | iscsi] |
789 | 3430 |
* zfs mount filesystem |
3431 |
* |
|
3432 |
* Mount all filesystems, or mount the given filesystem. |
|
3433 |
*/ |
|
3434 |
static int |
|
3435 |
zfs_do_mount(int argc, char **argv) |
|
3436 |
{ |
|
3126 | 3437 |
return (share_mount(OP_MOUNT, argc, argv)); |
789 | 3438 |
} |
3439 |
||
3440 |
/* |
|
5331 | 3441 |
* zfs share -a [nfs | iscsi | smb] |
789 | 3442 |
* zfs share filesystem |
3443 |
* |
|
3444 |
* Share all filesystems, or share the given filesystem. |
|
3445 |
*/ |
|
3446 |
static int |
|
3447 |
zfs_do_share(int argc, char **argv) |
|
3448 |
{ |
|
3126 | 3449 |
return (share_mount(OP_SHARE, argc, argv)); |
789 | 3450 |
} |
3451 |
||
3452 |
typedef struct unshare_unmount_node { |
|
3453 |
zfs_handle_t *un_zhp; |
|
3454 |
char *un_mountp; |
|
3455 |
uu_avl_node_t un_avlnode; |
|
3456 |
} unshare_unmount_node_t; |
|
3457 |
||
3458 |
/* ARGSUSED */ |
|
3459 |
static int |
|
3460 |
unshare_unmount_compare(const void *larg, const void *rarg, void *unused) |
|
3461 |
{ |
|
3462 |
const unshare_unmount_node_t *l = larg; |
|
3463 |
const unshare_unmount_node_t *r = rarg; |
|
3464 |
||
3465 |
return (strcmp(l->un_mountp, r->un_mountp)); |
|
3466 |
} |
|
3467 |
||
3468 |
/* |
|
3469 |
* Convenience routine used by zfs_do_umount() and manual_unmount(). Given an |
|
3470 |
* absolute path, find the entry /etc/mnttab, verify that its a ZFS filesystem, |
|
3471 |
* and unmount it appropriately. |
|
3472 |
*/ |
|
3473 |
static int |
|
3126 | 3474 |
unshare_unmount_path(int op, char *path, int flags, boolean_t is_manual) |
789 | 3475 |
{ |
3476 |
zfs_handle_t *zhp; |
|
3477 |
int ret; |
|
3478 |
struct stat64 statbuf; |
|
3479 |
struct extmnttab entry; |
|
3126 | 3480 |
const char *cmdname = (op == OP_SHARE) ? "unshare" : "unmount"; |
6289
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3481 |
ino_t path_inode; |
789 | 3482 |
|
3483 |
/* |
|
3484 |
* Search for the path in /etc/mnttab. Rather than looking for the |
|
3485 |
* specific path, which can be fooled by non-standard paths (i.e. ".." |
|
3486 |
* or "//"), we stat() the path and search for the corresponding |
|
3487 |
* (major,minor) device pair. |
|
3488 |
*/ |
|
3489 |
if (stat64(path, &statbuf) != 0) { |
|
3490 |
(void) fprintf(stderr, gettext("cannot %s '%s': %s\n"), |
|
3491 |
cmdname, path, strerror(errno)); |
|
3492 |
return (1); |
|
3493 |
} |
|
6289
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3494 |
path_inode = statbuf.st_ino; |
789 | 3495 |
|
3496 |
/* |
|
3497 |
* Search for the given (major,minor) pair in the mount table. |
|
3498 |
*/ |
|
3499 |
rewind(mnttab_file); |
|
3500 |
while ((ret = getextmntent(mnttab_file, &entry, 0)) == 0) { |
|
3501 |
if (entry.mnt_major == major(statbuf.st_dev) && |
|
3502 |
entry.mnt_minor == minor(statbuf.st_dev)) |
|
3503 |
break; |
|
3504 |
} |
|
3505 |
if (ret != 0) { |
|
5904
ac17ccc8902b
6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents:
5749
diff
changeset
|
3506 |
if (op == OP_SHARE) { |
ac17ccc8902b
6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents:
5749
diff
changeset
|
3507 |
(void) fprintf(stderr, gettext("cannot %s '%s': not " |
ac17ccc8902b
6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents:
5749
diff
changeset
|
3508 |
"currently mounted\n"), cmdname, path); |
ac17ccc8902b
6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents:
5749
diff
changeset
|
3509 |
return (1); |
ac17ccc8902b
6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents:
5749
diff
changeset
|
3510 |
} |
ac17ccc8902b
6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents:
5749
diff
changeset
|
3511 |
(void) fprintf(stderr, gettext("warning: %s not in mnttab\n"), |
ac17ccc8902b
6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents:
5749
diff
changeset
|
3512 |
path); |
ac17ccc8902b
6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents:
5749
diff
changeset
|
3513 |
if ((ret = umount2(path, flags)) != 0) |
ac17ccc8902b
6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents:
5749
diff
changeset
|
3514 |
(void) fprintf(stderr, gettext("%s: %s\n"), path, |
ac17ccc8902b
6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents:
5749
diff
changeset
|
3515 |
strerror(errno)); |
ac17ccc8902b
6587767 'zpool create' get different behavior while mountpoint not empty but has file or dir
timh
parents:
5749
diff
changeset
|
3516 |
return (ret != 0); |
789 | 3517 |
} |
3518 |
||
3519 |
if (strcmp(entry.mnt_fstype, MNTTYPE_ZFS) != 0) { |
|
3520 |
(void) fprintf(stderr, gettext("cannot %s '%s': not a ZFS " |
|
3521 |
"filesystem\n"), cmdname, path); |
|
3522 |
return (1); |
|
3523 |
} |
|
3524 |
||
2082 | 3525 |
if ((zhp = zfs_open(g_zfs, entry.mnt_special, |
3526 |
ZFS_TYPE_FILESYSTEM)) == NULL) |
|
789 | 3527 |
return (1); |
3528 |
||
6289
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3529 |
ret = 1; |
7386
78eaaa8a7347
6663585 'zfs unshare' & 'zfs unmount' should only support 'filesystem' or 'mountpoint' as argument
Sachin Gaikwad <Sachin.Gaikwad@Sun.COM>
parents:
7273
diff
changeset
|
3530 |
if (stat64(entry.mnt_mountp, &statbuf) != 0) { |
78eaaa8a7347
6663585 'zfs unshare' & 'zfs unmount' should only support 'filesystem' or 'mountpoint' as argument
Sachin Gaikwad <Sachin.Gaikwad@Sun.COM>
parents:
7273
diff
changeset
|
3531 |
(void) fprintf(stderr, gettext("cannot %s '%s': %s\n"), |
78eaaa8a7347
6663585 'zfs unshare' & 'zfs unmount' should only support 'filesystem' or 'mountpoint' as argument
Sachin Gaikwad <Sachin.Gaikwad@Sun.COM>
parents:
7273
diff
changeset
|
3532 |
cmdname, path, strerror(errno)); |
78eaaa8a7347
6663585 'zfs unshare' & 'zfs unmount' should only support 'filesystem' or 'mountpoint' as argument
Sachin Gaikwad <Sachin.Gaikwad@Sun.COM>
parents:
7273
diff
changeset
|
3533 |
goto out; |
78eaaa8a7347
6663585 'zfs unshare' & 'zfs unmount' should only support 'filesystem' or 'mountpoint' as argument
Sachin Gaikwad <Sachin.Gaikwad@Sun.COM>
parents:
7273
diff
changeset
|
3534 |
} else if (statbuf.st_ino != path_inode) { |
78eaaa8a7347
6663585 'zfs unshare' & 'zfs unmount' should only support 'filesystem' or 'mountpoint' as argument
Sachin Gaikwad <Sachin.Gaikwad@Sun.COM>
parents:
7273
diff
changeset
|
3535 |
(void) fprintf(stderr, gettext("cannot " |
78eaaa8a7347
6663585 'zfs unshare' & 'zfs unmount' should only support 'filesystem' or 'mountpoint' as argument
Sachin Gaikwad <Sachin.Gaikwad@Sun.COM>
parents:
7273
diff
changeset
|
3536 |
"%s '%s': not a mountpoint\n"), cmdname, path); |
78eaaa8a7347
6663585 'zfs unshare' & 'zfs unmount' should only support 'filesystem' or 'mountpoint' as argument
Sachin Gaikwad <Sachin.Gaikwad@Sun.COM>
parents:
7273
diff
changeset
|
3537 |
goto out; |
78eaaa8a7347
6663585 'zfs unshare' & 'zfs unmount' should only support 'filesystem' or 'mountpoint' as argument
Sachin Gaikwad <Sachin.Gaikwad@Sun.COM>
parents:
7273
diff
changeset
|
3538 |
} |
78eaaa8a7347
6663585 'zfs unshare' & 'zfs unmount' should only support 'filesystem' or 'mountpoint' as argument
Sachin Gaikwad <Sachin.Gaikwad@Sun.COM>
parents:
7273
diff
changeset
|
3539 |
|
3126 | 3540 |
if (op == OP_SHARE) { |
6289
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3541 |
char nfs_mnt_prop[ZFS_MAXPROPLEN]; |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3542 |
char smbshare_prop[ZFS_MAXPROPLEN]; |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3543 |
|
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3544 |
verify(zfs_prop_get(zhp, ZFS_PROP_SHARENFS, nfs_mnt_prop, |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3545 |
sizeof (nfs_mnt_prop), NULL, NULL, 0, B_FALSE) == 0); |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3546 |
verify(zfs_prop_get(zhp, ZFS_PROP_SHARESMB, smbshare_prop, |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3547 |
sizeof (smbshare_prop), NULL, NULL, 0, B_FALSE) == 0); |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3548 |
|
5331 | 3549 |
if (strcmp(nfs_mnt_prop, "off") == 0 && |
3550 |
strcmp(smbshare_prop, "off") == 0) { |
|
789 | 3551 |
(void) fprintf(stderr, gettext("cannot unshare " |
3552 |
"'%s': legacy share\n"), path); |
|
3553 |
(void) fprintf(stderr, gettext("use " |
|
3554 |
"unshare(1M) to unshare this filesystem\n")); |
|
5331 | 3555 |
} else if (!zfs_is_shared(zhp)) { |
789 | 3556 |
(void) fprintf(stderr, gettext("cannot unshare '%s': " |
3557 |
"not currently shared\n"), path); |
|
3558 |
} else { |
|
5331 | 3559 |
ret = zfs_unshareall_bypath(zhp, path); |
789 | 3560 |
} |
3561 |
} else { |
|
6289
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3562 |
char mtpt_prop[ZFS_MAXPROPLEN]; |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3563 |
|
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3564 |
verify(zfs_prop_get(zhp, ZFS_PROP_MOUNTPOINT, mtpt_prop, |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3565 |
sizeof (mtpt_prop), NULL, NULL, 0, B_FALSE) == 0); |
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3566 |
|
7386
78eaaa8a7347
6663585 'zfs unshare' & 'zfs unmount' should only support 'filesystem' or 'mountpoint' as argument
Sachin Gaikwad <Sachin.Gaikwad@Sun.COM>
parents:
7273
diff
changeset
|
3567 |
if (is_manual) { |
1264
976065f98c2b
6372107 legacy "umount" command unmount filesystems in the subdirs when zfs mountpoint is a regular path
lling
parents:
1204
diff
changeset
|
3568 |
ret = zfs_unmount(zhp, NULL, flags); |
6289
9a83171c70d6
6603209 Multiple -o options to 'zfs mount' ignore all but the last.
mmusante
parents:
6168
diff
changeset
|
3569 |
} else if (strcmp(mtpt_prop, "legacy") == 0) { |
1264
976065f98c2b
6372107 legacy "umount" command unmount filesystems in the subdirs when zfs mountpoint is a regular path
lling
parents:
1204
diff
changeset
|
3570 |
(void) fprintf(stderr, gettext("cannot unmount " |
976065f98c2b
6372107 legacy "umount" command unmount filesystems in the subdirs when zfs mountpoint is a regular path
lling
parents:
1204
diff
changeset
|
3571 |
"'%s': legacy mountpoint\n"), |
976065f98c2b
6372107 legacy "umount" command unmount filesystems in the subdirs when zfs mountpoint is a regular path
lling
parents:
1204
diff
changeset
|
3572 |
zfs_get_name(zhp)); |
976065f98c2b
6372107 legacy "umount" command unmount filesystems in the subdirs when zfs mountpoint is a regular path
lling
parents:
1204
diff
changeset
|
3573 |
(void) fprintf(stderr, gettext("use umount(1M) " |
976065f98c2b
6372107 legacy "umount" command unmount filesystems in the subdirs when zfs mountpoint is a regular path
lling
parents:
1204
diff
changeset
|
3574 |
"to unmount this filesystem\n")); |
789 | 3575 |
} else { |
3576 |
ret = zfs_unmountall(zhp, flags); |
|
3577 |
} |
|
3578 |
} |
|
3579 |
||
7386
78eaaa8a7347
6663585 'zfs unshare' & 'zfs unmount' should only support 'filesystem' or 'mountpoint' as argument
Sachin Gaikwad <Sachin.Gaikwad@Sun.COM>
parents:
7273
diff
changeset
|
3580 |
out: |
789 | 3581 |
zfs_close(zhp); |
3582 |
||
3583 |
return (ret != 0); |
|
3584 |
} |
|
3585 |
||
3586 |
/* |
|
3587 |
* Generic callback for unsharing or unmounting a filesystem. |
|
3588 |
*/ |
|
3589 |
static int |
|
3126 | 3590 |
unshare_unmount(int op, int argc, char **argv) |
789 | 3591 |
{ |
3592 |
int do_all = 0; |
|
3593 |
int flags = 0; |
|
3594 |
int ret = 0; |
|
3126 | 3595 |
int types, c; |
789 | 3596 |
zfs_handle_t *zhp; |
5331 | 3597 |
char nfsiscsi_mnt_prop[ZFS_MAXPROPLEN]; |
3598 |
char sharesmb[ZFS_MAXPROPLEN]; |
|
789 | 3599 |
|
3600 |
/* check options */ |
|
3126 | 3601 |
while ((c = getopt(argc, argv, op == OP_SHARE ? "a" : "af")) != -1) { |
789 | 3602 |
switch (c) { |
3603 |
case 'a': |
|
3604 |
do_all = 1; |
|
3605 |
break; |
|
3606 |
case 'f': |
|
3607 |
flags = MS_FORCE; |
|
3608 |
break; |
|
3609 |
case '?': |
|
3610 |
(void) fprintf(stderr, gettext("invalid option '%c'\n"), |
|
3611 |
optopt); |
|
2082 | 3612 |
usage(B_FALSE); |
789 | 3613 |
} |
3614 |
} |
|
3615 |
||
3616 |
argc -= optind; |
|
3617 |
argv += optind; |
|
3618 |
||
3619 |
if (do_all) { |
|
3620 |
/* |
|
3621 |
* We could make use of zfs_for_each() to walk all datasets in |
|
3622 |
* the system, but this would be very inefficient, especially |
|
3623 |
* since we would have to linearly search /etc/mnttab for each |
|
3624 |
* one. Instead, do one pass through /etc/mnttab looking for |
|
3625 |
* zfs entries and call zfs_unmount() for each one. |
|
3626 |
* |
|
3627 |
* Things get a little tricky if the administrator has created |
|
3628 |
* mountpoints beneath other ZFS filesystems. In this case, we |
|
3629 |
* have to unmount the deepest filesystems first. To accomplish |
|
3630 |
* this, we place all the mountpoints in an AVL tree sorted by |
|
3631 |
* the special type (dataset name), and walk the result in |
|
3632 |
* reverse to make sure to get any snapshots first. |
|
3633 |
*/ |
|
3634 |
struct mnttab entry; |
|
3635 |
uu_avl_pool_t *pool; |
|
3636 |
uu_avl_t *tree; |
|
3637 |
unshare_unmount_node_t *node; |
|
3638 |
uu_avl_index_t idx; |
|
3639 |
uu_avl_walk_t *walk; |
|
3640 |
||
3126 | 3641 |
if (argc != 0) { |
3642 |
(void) fprintf(stderr, gettext("too many arguments\n")); |
|
3643 |
usage(B_FALSE); |
|
3644 |
} |
|
3645 |
||
789 | 3646 |
if ((pool = uu_avl_pool_create("unmount_pool", |
3647 |
sizeof (unshare_unmount_node_t), |
|
3648 |
offsetof(unshare_unmount_node_t, un_avlnode), |
|
3649 |
unshare_unmount_compare, |
|
3650 |
UU_DEFAULT)) == NULL) { |
|
3651 |
(void) fprintf(stderr, gettext("internal error: " |
|
3652 |
"out of memory\n")); |
|
3653 |
exit(1); |
|
3654 |
} |
|
3655 |
||
3656 |
if ((tree = uu_avl_create(pool, NULL, UU_DEFAULT)) == NULL) { |
|
3657 |
(void) fprintf(stderr, gettext("internal error: " |
|
3658 |
"out of memory\n")); |
|
3659 |
exit(1); |
|
3660 |
} |
|
3661 |
||
3662 |
rewind(mnttab_file); |
|
3663 |
while (getmntent(mnttab_file, &entry) == 0) { |
|
3664 |
||
3665 |
/* ignore non-ZFS entries */ |
|
3666 |
if (strcmp(entry.mnt_fstype, MNTTYPE_ZFS) != 0) |
|
3667 |
continue; |
|
3668 |
||
3669 |
/* ignore snapshots */ |
|
3670 |
if (strchr(entry.mnt_special, '@') != NULL) |
|
3671 |
continue; |
|
3672 |
||
2082 | 3673 |
if ((zhp = zfs_open(g_zfs, entry.mnt_special, |
789 | 3674 |
ZFS_TYPE_FILESYSTEM)) == NULL) { |
3675 |
ret = 1; |
|
3676 |
continue; |
|
3677 |
} |
|
3678 |
||
5331 | 3679 |
switch (op) { |
3680 |
case OP_SHARE: |
|
3681 |
verify(zfs_prop_get(zhp, ZFS_PROP_SHARENFS, |
|
3682 |
nfsiscsi_mnt_prop, |
|
3683 |
sizeof (nfsiscsi_mnt_prop), |
|
3684 |
NULL, NULL, 0, B_FALSE) == 0); |
|
3685 |
if (strcmp(nfsiscsi_mnt_prop, "off") != 0) |
|
3686 |
break; |
|
3687 |
verify(zfs_prop_get(zhp, ZFS_PROP_SHARESMB, |
|
3688 |
nfsiscsi_mnt_prop, |
|
3689 |
sizeof (nfsiscsi_mnt_prop), |
|
3690 |
NULL, NULL, 0, B_FALSE) == 0); |
|
3691 |
if (strcmp(nfsiscsi_mnt_prop, "off") == 0) |
|
3692 |
continue; |
|
3693 |
break; |
|
3694 |
case OP_MOUNT: |
|
3695 |
/* Ignore legacy mounts */ |
|
3696 |
verify(zfs_prop_get(zhp, ZFS_PROP_MOUNTPOINT, |
|
3697 |
nfsiscsi_mnt_prop, |
|
3698 |
sizeof (nfsiscsi_mnt_prop), |
|
3699 |
NULL, NULL, 0, B_FALSE) == 0); |
|
3700 |
if (strcmp(nfsiscsi_mnt_prop, "legacy") == 0) |
|
3701 |
continue; |
|
6168
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
3702 |
/* Ignore canmount=noauto mounts */ |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
3703 |
if (zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT) == |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
3704 |
ZFS_CANMOUNT_NOAUTO) |
51c045dcc498
PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents:
5993
diff
changeset
|
3705 |
continue; |
5331 | 3706 |
default: |
3707 |
break; |
|
789 | 3708 |
} |
3709 |
||
3710 |
node = safe_malloc(sizeof (unshare_unmount_node_t)); |
|
3711 |
node->un_zhp = zhp; |
|
3712 |
||
3713 |
if ((node->un_mountp = strdup(entry.mnt_mountp)) == |
|
3714 |
NULL) { |
|
3715 |
(void) fprintf(stderr, gettext("internal error:" |
|
3716 |
" out of memory\n")); |
|
3717 |
exit(1); |
|
3718 |
} |
|
3719 |
||
3720 |
uu_avl_node_init(node, &node->un_avlnode, pool); |
|
3721 |
||
3722 |
if (uu_avl_find(tree, node, NULL, &idx) == NULL) { |
|
3723 |
uu_avl_insert(tree, node, idx); |
|
3724 |
} else { |
|
3725 |
zfs_close(node->un_zhp); |
|
3726 |
free(node->un_mountp); |
|
3727 |
free(node); |
|
3728 |
} |
|
3729 |
} |
|
3730 |
||
3731 |
/* |
|
3732 |
* Walk the AVL tree in reverse, unmounting each filesystem and |
|
3733 |
* removing it from the AVL tree in the process. |
|
3734 |
*/ |
|
3735 |
if ((walk = uu_avl_walk_start(tree, |
|
3736 |
UU_WALK_REVERSE | UU_WALK_ROBUST)) == NULL) { |
|
3737 |
(void) fprintf(stderr, |
|
3738 |
gettext("internal error: out of memory")); |
|
3739 |
exit(1); |
|
3740 |
} |
|
3741 |
||
3742 |
while ((node = uu_avl_walk_next(walk)) != NULL) { |
|
3743 |
uu_avl_remove(tree, node); |
|
3744 |
||
3126 | 3745 |
switch (op) { |
789 | 3746 |
case OP_SHARE: |
5331 | 3747 |
if (zfs_unshareall_bypath(node->un_zhp, |
789 | 3748 |
node->un_mountp) != 0) |
3749 |
ret = 1; |
|
3750 |
break; |
|
3751 |
||
3752 |
case OP_MOUNT: |
|
3753 |
if (zfs_unmount(node->un_zhp, |
|
3754 |
node->un_mountp, flags) != 0) |
|
3755 |
ret = 1; |
|
3756 |
break; |
|
3757 |
} |
|
3758 |
||
3759 |
zfs_close(node->un_zhp); |
|
3760 |
free(node->un_mountp); |
|
3761 |
free(node); |
|
3762 |
} |
|
3763 |
||
3764 |
uu_avl_walk_end(walk); |
|
3765 |
uu_avl_destroy(tree); |
|
3766 |
uu_avl_pool_destroy(pool); |
|
3126 | 3767 |
|
3768 |
if (op == OP_SHARE) { |
|
3769 |
/* |
|
3770 |
* Finally, unshare any volumes shared via iSCSI. |
|
3771 |
*/ |
|
3772 |
zfs_handle_t **dslist = NULL; |
|
3773 |
size_t i, count = 0; |
|
3774 |
||
4737 | 3775 |
get_all_datasets(ZFS_TYPE_VOLUME, &dslist, &count, |
3776 |
B_FALSE); |
|
3126 | 3777 |
|
3778 |
if (count != 0) { |
|
3779 |
qsort(dslist, count, sizeof (void *), |
|
3780 |
dataset_cmp); |
|
3781 |
||
3782 |
for (i = 0; i < count; i++) { |
|
3783 |
if (zfs_unshare_iscsi(dslist[i]) != 0) |
|
3784 |
ret = 1; |
|
3785 |
zfs_close(dslist[i]); |
|
3786 |
} |
|
3787 |
||
3788 |
free(dslist); |
|
3789 |
} |
|
3790 |
} |
|
789 | 3791 |
} else { |
3126 | 3792 |
if (argc != 1) { |
3793 |
if (argc == 0) |
|
3794 |
(void) fprintf(stderr, |
|
3795 |
gettext("missing filesystem argument\n")); |
|
3796 |
else |
|
3797 |
(void) fprintf(stderr, |
|
3798 |
gettext("too many arguments\n")); |
|
3799 |
usage(B_FALSE); |
|
3800 |
} |
|
3801 |
||
789 | 3802 |
/* |
3803 |
* We have an argument, but it may be a full path or a ZFS |
|
3804 |
* filesystem. Pass full paths off to unmount_path() (shared by |
|
3805 |
* manual_unmount), otherwise open the filesystem and pass to |
|
3806 |
* zfs_unmount(). |
|
3807 |
*/ |
|
3808 |
if (argv[0][0] == '/') |
|
3126 | 3809 |
return (unshare_unmount_path(op, argv[0], |
3912 | 3810 |
flags, B_FALSE)); |
2082 | 3811 |
|
3126 | 3812 |
types = ZFS_TYPE_FILESYSTEM; |
3813 |
if (op == OP_SHARE) |
|
3814 |
types |= ZFS_TYPE_VOLUME; |
|
3815 |
||
3816 |
if ((zhp = zfs_open(g_zfs, argv[0], types)) == NULL) |
|
789 | 3817 |
return (1); |
3818 |
||
3126 | 3819 |
if (zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) { |
3820 |
verify(zfs_prop_get(zhp, op == OP_SHARE ? |
|
5331 | 3821 |
ZFS_PROP_SHARENFS : ZFS_PROP_MOUNTPOINT, |
3822 |
nfsiscsi_mnt_prop, sizeof (nfsiscsi_mnt_prop), NULL, |
|
3823 |
NULL, 0, B_FALSE) == 0); |
|
3126 | 3824 |
|
3825 |
switch (op) { |
|
3826 |
case OP_SHARE: |
|
5331 | 3827 |
verify(zfs_prop_get(zhp, ZFS_PROP_SHARENFS, |
3828 |
nfsiscsi_mnt_prop, |
|
3829 |
sizeof (nfsiscsi_mnt_prop), |
|
3830 |
NULL, NULL, 0, B_FALSE) == 0); |
|
3831 |
verify(zfs_prop_get(zhp, ZFS_PROP_SHARESMB, |
|
3832 |
sharesmb, sizeof (sharesmb), NULL, NULL, |
|
3833 |
0, B_FALSE) == 0); |
|
3834 |
||
3835 |
if (strcmp(nfsiscsi_mnt_prop, "off") == 0 && |
|
3836 |
strcmp(sharesmb, "off") == 0) { |
|
3126 | 3837 |
(void) fprintf(stderr, gettext("cannot " |
3838 |
"unshare '%s': legacy share\n"), |
|
3839 |
zfs_get_name(zhp)); |
|
3840 |
(void) fprintf(stderr, gettext("use " |
|
3841 |
"unshare(1M) to unshare this " |
|
3842 |
"filesystem\n")); |
|
3843 |
ret = 1; |
|
5331 | 3844 |
} else if (!zfs_is_shared(zhp)) { |
3126 | 3845 |
(void) fprintf(stderr, gettext("cannot " |
3846 |
"unshare '%s': not currently " |
|
3847 |
"shared\n"), zfs_get_name(zhp)); |
|
3848 |
ret = 1; |
|
5331 | 3849 |
} else if (zfs_unshareall(zhp) != 0) { |
3126 | 3850 |
ret = 1; |
3851 |
} |
|
3852 |
break; |
|
3853 |
||
3854 |
case OP_MOUNT: |
|
5331 | 3855 |
if (strcmp(nfsiscsi_mnt_prop, "legacy") == 0) { |
3126 | 3856 |
(void) fprintf(stderr, gettext("cannot " |
3857 |
"unmount '%s': legacy " |
|
3858 |
"mountpoint\n"), zfs_get_name(zhp)); |
|
3859 |
(void) fprintf(stderr, gettext("use " |
|
3860 |
"umount(1M) to unmount this " |
|
3861 |
"filesystem\n")); |
|
3862 |
ret = 1; |
|
3863 |
} else if (!zfs_is_mounted(zhp, NULL)) { |
|
3864 |
(void) fprintf(stderr, gettext("cannot " |
|
3865 |
"unmount '%s': not currently " |
|
3866 |
"mounted\n"), |
|
3867 |
zfs_get_name(zhp)); |
|
3868 |
ret = 1; |
|
3869 |
} else if (zfs_unmountall(zhp, flags) != 0) { |
|
3870 |
ret = 1; |
|
3871 |
} |
|
3872 |
break; |
|
3873 |
} |
|
3874 |
} else { |
|
3875 |
assert(op == OP_SHARE); |
|
3876 |
||
5331 | 3877 |
verify(zfs_prop_get(zhp, ZFS_PROP_SHAREISCSI, |
3878 |
nfsiscsi_mnt_prop, sizeof (nfsiscsi_mnt_prop), |
|
3879 |
NULL, NULL, 0, B_FALSE) == 0); |
|
3880 |
||
3881 |
if (strcmp(nfsiscsi_mnt_prop, "off") == 0) { |
|
789 | 3882 |
(void) fprintf(stderr, gettext("cannot unshare " |
3126 | 3883 |
"'%s': 'shareiscsi' property not set\n"), |
3884 |
zfs_get_name(zhp)); |
|
3885 |
(void) fprintf(stderr, gettext("set " |
|
3886 |
"'shareiscsi' property or use " |
|
3887 |
"iscsitadm(1M) to share this volume\n")); |
|
789 | 3888 |
ret = 1; |
3126 | 3889 |
} else if (!zfs_is_shared_iscsi(zhp)) { |
3890 |
(void) fprintf(stderr, gettext("cannot " |
|
3891 |
"unshare '%s': not currently shared\n"), |
|
789 | 3892 |
zfs_get_name(zhp)); |
3893 |
ret = 1; |
|
3126 | 3894 |
} else if (zfs_unshare_iscsi(zhp) != 0) { |
789 | 3895 |
ret = 1; |
3896 |
} |
|
3897 |
} |
|
3898 |
||
3899 |
zfs_close(zhp); |
|
3900 |
} |
|
3901 |
||
3902 |
return (ret); |
|
3903 |
} |
|
3904 |
||
3905 |
/* |
|
3906 |
* zfs unmount -a |
|
3907 |
* zfs unmount filesystem |
|
3908 |
* |
|
3909 |
* Unmount all filesystems, or a specific ZFS filesystem. |
|
3910 |
*/ |
|
3911 |
static int |
|
3912 |
zfs_do_unmount(int argc, char **argv) |
|
3913 |
{ |
|
3914 |
return (unshare_unmount(OP_MOUNT, argc, argv)); |
|
3915 |
} |
|
3916 |
||
3917 |
/* |
|
3918 |
* zfs unshare -a |
|
3919 |
* zfs unshare filesystem |
|
3920 |
* |
|
3921 |
* Unshare all filesystems, or a specific ZFS filesystem. |
|
3922 |
*/ |
|
3923 |
static int |
|
3924 |
zfs_do_unshare(int argc, char **argv) |
|
3925 |
{ |
|
3926 |
return (unshare_unmount(OP_SHARE, argc, argv)); |
|
3927 |
} |
|
3928 |
||
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
3929 |
/* ARGSUSED */ |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
3930 |
static int |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
3931 |
zfs_do_python(int argc, char **argv) |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
3932 |
{ |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
3933 |
(void) execv(pypath, argv-1); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
3934 |
(void) printf("internal error: %s not found\n", pypath); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
3935 |
return (-1); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
3936 |
} |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
9365
diff
changeset
|
3937 |
|
789 | 3938 |
/* |
3939 |
* Called when invoked as /etc/fs/zfs/mount. Do the mount if the mountpoint is |
|
3940 |
* 'legacy'. Otherwise, complain that use should be using 'zfs mount'. |
|
3941 |
*/ |
|
3942 |
static int |
|
3943 |
manual_mount(int argc, char **argv) |
|
3944 |
{ |
|
3945 |
zfs_handle_t *zhp; |
|
3946 |
char mountpoint[ZFS_MAXPROPLEN]; |
|
3947 |
char mntopts[MNT_LINE_MAX] = { '\0' }; |
|
3948 |
int ret; |
|
3949 |
int c; |
|
3950 |
int flags = 0; |
|
3951 |
char *dataset, *path; |
|
3952 |
||
3953 |
/* check options */ |
|
1544 | 3954 |
while ((c = getopt(argc, argv, ":mo:O")) != -1) { |
789 | 3955 |
switch (c) { |
3956 |
case 'o': |
|
3957 |
(void) strlcpy(mntopts, optarg, sizeof (mntopts)); |
|
3958 |
break; |
|
3959 |
case 'O': |
|
3960 |
flags |= MS_OVERLAY; |
|
3961 |
break; |
|
1544 | 3962 |
case 'm': |
3963 |
flags |= MS_NOMNTTAB; |
|
3964 |
break; |
|
789 | 3965 |
case ':': |
3966 |
(void) fprintf(stderr, gettext("missing argument for " |
|
3967 |
"'%c' option\n"), optopt); |
|
2082 | 3968 |
usage(B_FALSE); |
789 | 3969 |
break; |
3970 |
case '?': |
|
3971 |
(void) fprintf(stderr, gettext("invalid option '%c'\n"), |
|
3972 |
optopt); |
|
3973 |
(void) fprintf(stderr, gettext("usage: mount [-o opts] " |
|
3974 |
"<path>\n")); |
|
3975 |
return (2); |
|
3976 |
} |
|
3977 |
} |
|
3978 |
||
3979 |
argc -= optind; |
|
3980 |
argv += optind; |
|
3981 |
||
3982 |
/* check that we only have two arguments */ |
|
3983 |
if (argc != 2) { |
|
3984 |
if (argc == 0) |
|
3985 |
(void) fprintf(stderr, gettext("missing dataset " |
|
3986 |
"argument\n")); |
|
3987 |
else if (argc == 1) |
|
3988 |
(void) fprintf(stderr, |
|
3989 |
gettext("missing mountpoint argument\n")); |
|
3990 |
else |
|
3991 |
(void) fprintf(stderr, gettext("too many arguments\n")); |
|
3992 |
(void) fprintf(stderr, "usage: mount <dataset> <mountpoint>\n"); |
|
3993 |
return (2); |
|
3994 |
} |
|
3995 |
||
3996 |
dataset = argv[0]; |
|
3997 |
path = argv[1]; |
|
3998 |
||
3999 |
/* try to open the dataset */ |
|
2082 | 4000 |
if ((zhp = zfs_open(g_zfs, dataset, ZFS_TYPE_FILESYSTEM)) == NULL) |
789 | 4001 |
return (1); |
4002 |
||
4003 |
(void) zfs_prop_get(zhp, ZFS_PROP_MOUNTPOINT, mountpoint, |
|
2082 | 4004 |
sizeof (mountpoint), NULL, NULL, 0, B_FALSE); |
789 | 4005 |
|
4006 |
/* check for legacy mountpoint and complain appropriately */ |
|
4007 |
ret = 0; |
|
4008 |
if (strcmp(mountpoint, ZFS_MOUNTPOINT_LEGACY) == 0) { |
|
4009 |
if (mount(dataset, path, MS_OPTIONSTR | flags, MNTTYPE_ZFS, |
|
4010 |
NULL, 0, mntopts, sizeof (mntopts)) != 0) { |
|
4011 |
(void) fprintf(stderr, gettext("mount failed: %s\n"), |
|
4012 |
strerror(errno)); |
|
4013 |
ret = 1; |
|
4014 |
} |
|
4015 |
} else { |
|
4016 |
(void) fprintf(stderr, gettext("filesystem '%s' cannot be " |
|
4017 |
"mounted using 'mount -F zfs'\n"), dataset); |
|
4018 |
(void) fprintf(stderr, gettext("Use 'zfs set mountpoint=%s' " |
|
4019 |
"instead.\n"), path); |
|
4020 |
(void) fprintf(stderr, gettext("If you must use 'mount -F zfs' " |
|
4021 |
"or /etc/vfstab, use 'zfs set mountpoint=legacy'.\n")); |
|
4022 |
(void) fprintf(stderr, gettext("See zfs(1M) for more " |
|
4023 |
"information.\n")); |
|
4024 |
ret = 1; |
|
4025 |
} |
|
4026 |
||
4027 |
return (ret); |
|
4028 |
} |
|
4029 |
||
4030 |
/* |
|
4031 |
* Called when invoked as /etc/fs/zfs/umount. Unlike a manual mount, we allow |
|
4032 |
* unmounts of non-legacy filesystems, as this is the dominant administrative |
|
4033 |
* interface. |
|
4034 |
*/ |
|
4035 |
static int |
|
4036 |
manual_unmount(int argc, char **argv) |
|
4037 |
{ |
|
4038 |
int flags = 0; |
|
4039 |
int c; |
|
4040 |
||
4041 |
/* check options */ |
|
4042 |
while ((c = getopt(argc, argv, "f")) != -1) { |
|
4043 |
switch (c) { |
|
4044 |
case 'f': |
|
4045 |
flags = MS_FORCE; |
|
4046 |
break; |
|
4047 |
case '?': |
|
4048 |
(void) fprintf(stderr, gettext("invalid option '%c'\n"), |
|
4049 |
optopt); |
|
4050 |
(void) fprintf(stderr, gettext("usage: unmount [-f] " |
|
4051 |
"<path>\n")); |
|
4052 |
return (2); |
|
4053 |
} |
|
4054 |
} |
|
4055 |
||
4056 |
argc -= optind; |
|
4057 |
argv += optind; |
|
4058 |
||
4059 |
/* check arguments */ |
|
4060 |
if (argc != 1) { |
|
4061 |
if (argc == 0) |
|
4062 |
(void) fprintf(stderr, gettext("missing path " |
|
4063 |
"argument\n")); |
|
4064 |
else |
|
4065 |
(void) fprintf(stderr, gettext("too many arguments\n")); |
|
4066 |
(void) fprintf(stderr, gettext("usage: unmount [-f] <path>\n")); |
|
4067 |
return (2); |
|
4068 |
} |
|
4069 |
||
2082 | 4070 |
return (unshare_unmount_path(OP_MOUNT, argv[0], flags, B_TRUE)); |
789 | 4071 |
} |
4072 |
||
4073 |
static int |
|
4543 | 4074 |
find_command_idx(char *command, int *idx) |
4075 |
{ |
|
4076 |
int i; |
|
4077 |
||
4078 |
for (i = 0; i < NCOMMAND; i++) { |
|
4079 |
if (command_table[i].name == NULL) |
|
4080 |
continue; |
|
4081 |
||
4082 |
if (strcmp(command, command_table[i].name) == 0) { |
|
4083 |
*idx = i; |
|
4084 |
return (0); |
|
4085 |
} |
|
4086 |
} |
|
4087 |
return (1); |
|
4088 |
} |
|
4089 |
||
789 | 4090 |
int |
4091 |
main(int argc, char **argv) |
|
4092 |
{ |
|
4093 |
int ret; |
|
4094 |
int i; |
|
4095 |
char *progname; |
|
4096 |
char *cmdname; |
|
4097 |
||
4098 |
(void) setlocale(LC_ALL, ""); |
|
4099 |
(void) textdomain(TEXT_DOMAIN); |
|
4100 |
||
4101 |
opterr = 0; |
|
4102 |
||
2082 | 4103 |
if ((g_zfs = libzfs_init()) == NULL) { |
4104 |
(void) fprintf(stderr, gettext("internal error: failed to " |
|
4105 |
"initialize ZFS library\n")); |
|
4106 |
return (1); |
|
4107 |
} |
|
4108 |
||
4988
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4860
diff
changeset
|
4109 |
zpool_set_history_str("zfs", argc, argv, history_str); |
db8abd9846d4
6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents:
4860
diff
changeset
|
4110 |
verify(zpool_stage_history(g_zfs, history_str) == 0); |
4543 | 4111 |
|
2082 | 4112 |
libzfs_print_on_error(g_zfs, B_TRUE); |
4113 |
||
789 | 4114 |
if ((mnttab_file = fopen(MNTTAB, "r")) == NULL) { |
4115 |
(void) fprintf(stderr, gettext("internal error: unable to " |
|
4116 |
"open %s\n"), MNTTAB); |
|
4117 |
return (1); |
|
4118 |
} |
|
4119 |
||
4120 |
/* |
|
4121 |
* This command also doubles as the /etc/fs mount and unmount program. |
|
4122 |
* Determine if we should take this behavior based on argv[0]. |
|
4123 |
*/ |
|
4124 |
progname = basename(argv[0]); |
|
4125 |
if (strcmp(progname, "mount") == 0) { |
|
4126 |
ret = manual_mount(argc, argv); |
|
4127 |
} else if (strcmp(progname, "umount") == 0) { |
|
4128 |
ret = manual_unmount(argc, argv); |
|
4129 |
} else { |
|
4130 |
/* |
|
4131 |
* Make sure the user has specified some command. |
|
4132 |
*/ |
|
4133 |
if (argc < 2) { |
|
4134 |
(void) fprintf(stderr, gettext("missing command\n")); |
|
2082 | 4135 |
usage(B_FALSE); |
789 | 4136 |
} |
4137 |
||
4138 |
cmdname = argv[1]; |
|
4139 |
||
4140 |
/* |
|
4141 |
* The 'umount' command is an alias for 'unmount' |
|
4142 |
*/ |
|
4143 |
if (strcmp(cmdname, "umount") == 0) |
|
4144 |
cmdname = "unmount"; |
|
4145 |
||
4146 |
/* |
|
1749 | 4147 |
* The 'recv' command is an alias for 'receive' |
4148 |
*/ |
|
4149 |
if (strcmp(cmdname, "recv") == 0) |
|
4150 |
cmdname = "receive"; |
|
4151 |
||
4152 |
/* |
|
789 | 4153 |
* Special case '-?' |
4154 |
*/ |
|
4155 |
if (strcmp(cmdname, "-?") == 0) |
|
2082 | 4156 |
usage(B_TRUE); |
789 | 4157 |
|
4158 |
/* |
|
4159 |
* Run the appropriate command. |
|
4160 |
*/ |
|
8811
f8deccf701cf
6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8584
diff
changeset
|
4161 |
libzfs_mnttab_cache(g_zfs, B_TRUE); |
4543 | 4162 |
if (find_command_idx(cmdname, &i) == 0) { |
4163 |
current_command = &command_table[i]; |
|
4164 |
ret = command_table[i].func(argc - 1, argv + 1); |
|
4787 | 4165 |
} else if (strchr(cmdname, '=') != NULL) { |
4166 |
verify(find_command_idx("set", &i) == 0); |
|
4167 |
current_command = &command_table[i]; |
|
4168 |
ret = command_table[i].func(argc, argv); |
|
4169 |
} else { |
|
789 | 4170 |
(void) fprintf(stderr, gettext("unrecognized " |
4171 |
"command '%s'\n"), cmdname); |
|
2082 | 4172 |
usage(B_FALSE); |
789 | 4173 |
} |
8811
f8deccf701cf
6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
8584
diff
changeset
|
4174 |
libzfs_mnttab_cache(g_zfs, B_FALSE); |
789 | 4175 |
} |
4176 |
||
4177 |
(void) fclose(mnttab_file); |
|
4178 |
||
2082 | 4179 |
libzfs_fini(g_zfs); |
4180 |
||
789 | 4181 |
/* |
4182 |
* The 'ZFS_ABORT' environment variable causes us to dump core on exit |
|
4183 |
* for the purposes of running ::findleaks. |
|
4184 |
*/ |
|
4185 |
if (getenv("ZFS_ABORT") != NULL) { |
|
4186 |
(void) printf("dumping core by request\n"); |
|
4187 |
abort(); |
|
4188 |
} |
|
4189 |
||
4190 |
return (ret); |
|
4191 |
} |