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