author | ek110237 |
Wed, 24 Oct 2007 16:54:46 -0700 | |
changeset 5326 | 6752aa2bd5bc |
parent 5147 | 5e950ccc9585 |
child 5331 | 3047ad28a67b |
permissions | -rw-r--r-- |
789 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
1484
d330e98f8ed7
6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents:
1298
diff
changeset
|
5 |
* Common Development and Distribution License (the "License"). |
d330e98f8ed7
6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents:
1298
diff
changeset
|
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 |
*/ |
|
21 |
/* |
|
3461 | 22 |
* Copyright 2007 Sun Microsystems, Inc. All rights reserved. |
789 | 23 |
* Use is subject to license terms. |
24 |
*/ |
|
25 |
||
3246
7a46b8f56ee0
6351954 zfs missing noxattr mount flag (fix keywords)
ck153898
parents:
3234
diff
changeset
|
26 |
#pragma ident "%Z%%M% %I% %E% SMI" |
789 | 27 |
|
28 |
#include <sys/types.h> |
|
29 |
#include <sys/param.h> |
|
30 |
#include <sys/systm.h> |
|
31 |
#include <sys/sysmacros.h> |
|
32 |
#include <sys/kmem.h> |
|
33 |
#include <sys/pathname.h> |
|
34 |
#include <sys/vnode.h> |
|
35 |
#include <sys/vfs.h> |
|
3898
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
36 |
#include <sys/vfs_opreg.h> |
789 | 37 |
#include <sys/mntent.h> |
38 |
#include <sys/mount.h> |
|
39 |
#include <sys/cmn_err.h> |
|
40 |
#include "fs/fs_subr.h" |
|
41 |
#include <sys/zfs_znode.h> |
|
3461 | 42 |
#include <sys/zfs_dir.h> |
789 | 43 |
#include <sys/zil.h> |
44 |
#include <sys/fs/zfs.h> |
|
45 |
#include <sys/dmu.h> |
|
46 |
#include <sys/dsl_prop.h> |
|
3912 | 47 |
#include <sys/dsl_dataset.h> |
4543 | 48 |
#include <sys/dsl_deleg.h> |
789 | 49 |
#include <sys/spa.h> |
50 |
#include <sys/zap.h> |
|
51 |
#include <sys/varargs.h> |
|
52 |
#include <sys/policy.h> |
|
53 |
#include <sys/atomic.h> |
|
54 |
#include <sys/mkdev.h> |
|
55 |
#include <sys/modctl.h> |
|
4543 | 56 |
#include <sys/refstr.h> |
789 | 57 |
#include <sys/zfs_ioctl.h> |
58 |
#include <sys/zfs_ctldir.h> |
|
1544 | 59 |
#include <sys/bootconf.h> |
849
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
60 |
#include <sys/sunddi.h> |
1484
d330e98f8ed7
6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents:
1298
diff
changeset
|
61 |
#include <sys/dnlc.h> |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
62 |
#include <sys/dmu_objset.h> |
789 | 63 |
|
64 |
int zfsfstype; |
|
65 |
vfsops_t *zfs_vfsops = NULL; |
|
849
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
66 |
static major_t zfs_major; |
789 | 67 |
static minor_t zfs_minor; |
68 |
static kmutex_t zfs_dev_mtx; |
|
69 |
||
70 |
static int zfs_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr); |
|
71 |
static int zfs_umount(vfs_t *vfsp, int fflag, cred_t *cr); |
|
1544 | 72 |
static int zfs_mountroot(vfs_t *vfsp, enum whymountroot); |
789 | 73 |
static int zfs_root(vfs_t *vfsp, vnode_t **vpp); |
74 |
static int zfs_statvfs(vfs_t *vfsp, struct statvfs64 *statp); |
|
75 |
static int zfs_vget(vfs_t *vfsp, vnode_t **vpp, fid_t *fidp); |
|
76 |
static void zfs_freevfs(vfs_t *vfsp); |
|
77 |
||
78 |
static const fs_operation_def_t zfs_vfsops_template[] = { |
|
3898
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
79 |
VFSNAME_MOUNT, { .vfs_mount = zfs_mount }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
80 |
VFSNAME_MOUNTROOT, { .vfs_mountroot = zfs_mountroot }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
81 |
VFSNAME_UNMOUNT, { .vfs_unmount = zfs_umount }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
82 |
VFSNAME_ROOT, { .vfs_root = zfs_root }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
83 |
VFSNAME_STATVFS, { .vfs_statvfs = zfs_statvfs }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
84 |
VFSNAME_SYNC, { .vfs_sync = zfs_sync }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
85 |
VFSNAME_VGET, { .vfs_vget = zfs_vget }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
86 |
VFSNAME_FREEVFS, { .vfs_freevfs = zfs_freevfs }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
87 |
NULL, NULL |
789 | 88 |
}; |
89 |
||
90 |
static const fs_operation_def_t zfs_vfsops_eio_template[] = { |
|
3898
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
91 |
VFSNAME_FREEVFS, { .vfs_freevfs = zfs_freevfs }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
92 |
NULL, NULL |
789 | 93 |
}; |
94 |
||
95 |
/* |
|
96 |
* We need to keep a count of active fs's. |
|
97 |
* This is necessary to prevent our module |
|
98 |
* from being unloaded after a umount -f |
|
99 |
*/ |
|
100 |
static uint32_t zfs_active_fs_count = 0; |
|
101 |
||
102 |
static char *noatime_cancel[] = { MNTOPT_ATIME, NULL }; |
|
103 |
static char *atime_cancel[] = { MNTOPT_NOATIME, NULL }; |
|
3234 | 104 |
static char *noxattr_cancel[] = { MNTOPT_XATTR, NULL }; |
105 |
static char *xattr_cancel[] = { MNTOPT_NOXATTR, NULL }; |
|
789 | 106 |
|
3234 | 107 |
/* |
4596
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
108 |
* MO_DEFAULT is not used since the default value is determined |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
109 |
* by the equivalent property. |
3234 | 110 |
*/ |
789 | 111 |
static mntopt_t mntopts[] = { |
3234 | 112 |
{ MNTOPT_NOXATTR, noxattr_cancel, NULL, 0, NULL }, |
113 |
{ MNTOPT_XATTR, xattr_cancel, NULL, 0, NULL }, |
|
4596
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
114 |
{ MNTOPT_NOATIME, noatime_cancel, NULL, 0, NULL }, |
789 | 115 |
{ MNTOPT_ATIME, atime_cancel, NULL, 0, NULL } |
116 |
}; |
|
117 |
||
118 |
static mntopts_t zfs_mntopts = { |
|
119 |
sizeof (mntopts) / sizeof (mntopt_t), |
|
120 |
mntopts |
|
121 |
}; |
|
122 |
||
123 |
/*ARGSUSED*/ |
|
124 |
int |
|
125 |
zfs_sync(vfs_t *vfsp, short flag, cred_t *cr) |
|
126 |
{ |
|
127 |
/* |
|
128 |
* Data integrity is job one. We don't want a compromised kernel |
|
129 |
* writing to the storage pool, so we never sync during panic. |
|
130 |
*/ |
|
131 |
if (panicstr) |
|
132 |
return (0); |
|
133 |
||
134 |
/* |
|
135 |
* SYNC_ATTR is used by fsflush() to force old filesystems like UFS |
|
136 |
* to sync metadata, which they would otherwise cache indefinitely. |
|
137 |
* Semantically, the only requirement is that the sync be initiated. |
|
138 |
* The DMU syncs out txgs frequently, so there's nothing to do. |
|
139 |
*/ |
|
140 |
if (flag & SYNC_ATTR) |
|
141 |
return (0); |
|
142 |
||
143 |
if (vfsp != NULL) { |
|
144 |
/* |
|
145 |
* Sync a specific filesystem. |
|
146 |
*/ |
|
147 |
zfsvfs_t *zfsvfs = vfsp->vfs_data; |
|
148 |
||
149 |
ZFS_ENTER(zfsvfs); |
|
150 |
if (zfsvfs->z_log != NULL) |
|
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2474
diff
changeset
|
151 |
zil_commit(zfsvfs->z_log, UINT64_MAX, 0); |
789 | 152 |
else |
153 |
txg_wait_synced(dmu_objset_pool(zfsvfs->z_os), 0); |
|
154 |
ZFS_EXIT(zfsvfs); |
|
155 |
} else { |
|
156 |
/* |
|
157 |
* Sync all ZFS filesystems. This is what happens when you |
|
158 |
* run sync(1M). Unlike other filesystems, ZFS honors the |
|
159 |
* request by waiting for all pools to commit all dirty data. |
|
160 |
*/ |
|
161 |
spa_sync_allpools(); |
|
162 |
} |
|
163 |
||
164 |
return (0); |
|
165 |
} |
|
166 |
||
1544 | 167 |
static int |
168 |
zfs_create_unique_device(dev_t *dev) |
|
169 |
{ |
|
170 |
major_t new_major; |
|
171 |
||
172 |
do { |
|
173 |
ASSERT3U(zfs_minor, <=, MAXMIN32); |
|
174 |
minor_t start = zfs_minor; |
|
175 |
do { |
|
176 |
mutex_enter(&zfs_dev_mtx); |
|
177 |
if (zfs_minor >= MAXMIN32) { |
|
178 |
/* |
|
179 |
* If we're still using the real major |
|
180 |
* keep out of /dev/zfs and /dev/zvol minor |
|
181 |
* number space. If we're using a getudev()'ed |
|
182 |
* major number, we can use all of its minors. |
|
183 |
*/ |
|
184 |
if (zfs_major == ddi_name_to_major(ZFS_DRIVER)) |
|
185 |
zfs_minor = ZFS_MIN_MINOR; |
|
186 |
else |
|
187 |
zfs_minor = 0; |
|
188 |
} else { |
|
189 |
zfs_minor++; |
|
190 |
} |
|
191 |
*dev = makedevice(zfs_major, zfs_minor); |
|
192 |
mutex_exit(&zfs_dev_mtx); |
|
193 |
} while (vfs_devismounted(*dev) && zfs_minor != start); |
|
194 |
if (zfs_minor == start) { |
|
195 |
/* |
|
196 |
* We are using all ~262,000 minor numbers for the |
|
197 |
* current major number. Create a new major number. |
|
198 |
*/ |
|
199 |
if ((new_major = getudev()) == (major_t)-1) { |
|
200 |
cmn_err(CE_WARN, |
|
201 |
"zfs_mount: Can't get unique major " |
|
202 |
"device number."); |
|
203 |
return (-1); |
|
204 |
} |
|
205 |
mutex_enter(&zfs_dev_mtx); |
|
206 |
zfs_major = new_major; |
|
207 |
zfs_minor = 0; |
|
208 |
||
209 |
mutex_exit(&zfs_dev_mtx); |
|
210 |
} else { |
|
211 |
break; |
|
212 |
} |
|
213 |
/* CONSTANTCONDITION */ |
|
214 |
} while (1); |
|
215 |
||
216 |
return (0); |
|
217 |
} |
|
218 |
||
789 | 219 |
static void |
220 |
atime_changed_cb(void *arg, uint64_t newval) |
|
221 |
{ |
|
222 |
zfsvfs_t *zfsvfs = arg; |
|
223 |
||
224 |
if (newval == TRUE) { |
|
225 |
zfsvfs->z_atime = TRUE; |
|
226 |
vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOATIME); |
|
227 |
vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_ATIME, NULL, 0); |
|
228 |
} else { |
|
229 |
zfsvfs->z_atime = FALSE; |
|
230 |
vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_ATIME); |
|
231 |
vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOATIME, NULL, 0); |
|
232 |
} |
|
233 |
} |
|
234 |
||
235 |
static void |
|
3234 | 236 |
xattr_changed_cb(void *arg, uint64_t newval) |
237 |
{ |
|
238 |
zfsvfs_t *zfsvfs = arg; |
|
239 |
||
240 |
if (newval == TRUE) { |
|
241 |
/* XXX locking on vfs_flag? */ |
|
242 |
zfsvfs->z_vfs->vfs_flag |= VFS_XATTR; |
|
243 |
vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOXATTR); |
|
244 |
vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_XATTR, NULL, 0); |
|
245 |
} else { |
|
246 |
/* XXX locking on vfs_flag? */ |
|
247 |
zfsvfs->z_vfs->vfs_flag &= ~VFS_XATTR; |
|
248 |
vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_XATTR); |
|
249 |
vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOXATTR, NULL, 0); |
|
250 |
} |
|
251 |
} |
|
252 |
||
253 |
static void |
|
789 | 254 |
blksz_changed_cb(void *arg, uint64_t newval) |
255 |
{ |
|
256 |
zfsvfs_t *zfsvfs = arg; |
|
257 |
||
258 |
if (newval < SPA_MINBLOCKSIZE || |
|
259 |
newval > SPA_MAXBLOCKSIZE || !ISP2(newval)) |
|
260 |
newval = SPA_MAXBLOCKSIZE; |
|
261 |
||
262 |
zfsvfs->z_max_blksz = newval; |
|
263 |
zfsvfs->z_vfs->vfs_bsize = newval; |
|
264 |
} |
|
265 |
||
266 |
static void |
|
267 |
readonly_changed_cb(void *arg, uint64_t newval) |
|
268 |
{ |
|
269 |
zfsvfs_t *zfsvfs = arg; |
|
270 |
||
271 |
if (newval) { |
|
272 |
/* XXX locking on vfs_flag? */ |
|
273 |
zfsvfs->z_vfs->vfs_flag |= VFS_RDONLY; |
|
274 |
vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_RW); |
|
275 |
vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_RO, NULL, 0); |
|
276 |
} else { |
|
277 |
/* XXX locking on vfs_flag? */ |
|
278 |
zfsvfs->z_vfs->vfs_flag &= ~VFS_RDONLY; |
|
279 |
vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_RO); |
|
280 |
vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_RW, NULL, 0); |
|
281 |
} |
|
282 |
} |
|
283 |
||
284 |
static void |
|
285 |
devices_changed_cb(void *arg, uint64_t newval) |
|
286 |
{ |
|
287 |
zfsvfs_t *zfsvfs = arg; |
|
288 |
||
289 |
if (newval == FALSE) { |
|
290 |
zfsvfs->z_vfs->vfs_flag |= VFS_NODEVICES; |
|
291 |
vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_DEVICES); |
|
292 |
vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NODEVICES, NULL, 0); |
|
293 |
} else { |
|
294 |
zfsvfs->z_vfs->vfs_flag &= ~VFS_NODEVICES; |
|
295 |
vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NODEVICES); |
|
296 |
vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_DEVICES, NULL, 0); |
|
297 |
} |
|
298 |
} |
|
299 |
||
300 |
static void |
|
301 |
setuid_changed_cb(void *arg, uint64_t newval) |
|
302 |
{ |
|
303 |
zfsvfs_t *zfsvfs = arg; |
|
304 |
||
305 |
if (newval == FALSE) { |
|
306 |
zfsvfs->z_vfs->vfs_flag |= VFS_NOSETUID; |
|
307 |
vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_SETUID); |
|
308 |
vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOSETUID, NULL, 0); |
|
309 |
} else { |
|
310 |
zfsvfs->z_vfs->vfs_flag &= ~VFS_NOSETUID; |
|
311 |
vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOSETUID); |
|
312 |
vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_SETUID, NULL, 0); |
|
313 |
} |
|
314 |
} |
|
315 |
||
316 |
static void |
|
317 |
exec_changed_cb(void *arg, uint64_t newval) |
|
318 |
{ |
|
319 |
zfsvfs_t *zfsvfs = arg; |
|
320 |
||
321 |
if (newval == FALSE) { |
|
322 |
zfsvfs->z_vfs->vfs_flag |= VFS_NOEXEC; |
|
323 |
vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_EXEC); |
|
324 |
vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOEXEC, NULL, 0); |
|
325 |
} else { |
|
326 |
zfsvfs->z_vfs->vfs_flag &= ~VFS_NOEXEC; |
|
327 |
vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOEXEC); |
|
328 |
vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_EXEC, NULL, 0); |
|
329 |
} |
|
330 |
} |
|
331 |
||
332 |
static void |
|
333 |
snapdir_changed_cb(void *arg, uint64_t newval) |
|
334 |
{ |
|
335 |
zfsvfs_t *zfsvfs = arg; |
|
336 |
||
337 |
zfsvfs->z_show_ctldir = newval; |
|
338 |
} |
|
339 |
||
340 |
static void |
|
341 |
acl_mode_changed_cb(void *arg, uint64_t newval) |
|
342 |
{ |
|
343 |
zfsvfs_t *zfsvfs = arg; |
|
344 |
||
345 |
zfsvfs->z_acl_mode = newval; |
|
346 |
} |
|
347 |
||
348 |
static void |
|
349 |
acl_inherit_changed_cb(void *arg, uint64_t newval) |
|
350 |
{ |
|
351 |
zfsvfs_t *zfsvfs = arg; |
|
352 |
||
353 |
zfsvfs->z_acl_inherit = newval; |
|
354 |
} |
|
355 |
||
1544 | 356 |
static int |
357 |
zfs_register_callbacks(vfs_t *vfsp) |
|
358 |
{ |
|
359 |
struct dsl_dataset *ds = NULL; |
|
360 |
objset_t *os = NULL; |
|
361 |
zfsvfs_t *zfsvfs = NULL; |
|
3265
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3246
diff
changeset
|
362 |
int readonly, do_readonly = FALSE; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3246
diff
changeset
|
363 |
int setuid, do_setuid = FALSE; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3246
diff
changeset
|
364 |
int exec, do_exec = FALSE; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3246
diff
changeset
|
365 |
int devices, do_devices = FALSE; |
967e0fca6143
6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents:
3246
diff
changeset
|
366 |
int xattr, do_xattr = FALSE; |
4596
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
367 |
int atime, do_atime = FALSE; |
1544 | 368 |
int error = 0; |
369 |
||
370 |
ASSERT(vfsp); |
|
371 |
zfsvfs = vfsp->vfs_data; |
|
372 |
ASSERT(zfsvfs); |
|
373 |
os = zfsvfs->z_os; |
|
374 |
||
375 |
/* |
|
376 |
* The act of registering our callbacks will destroy any mount |
|
377 |
* options we may have. In order to enable temporary overrides |
|
3234 | 378 |
* of mount options, we stash away the current values and |
1544 | 379 |
* restore them after we register the callbacks. |
380 |
*/ |
|
381 |
if (vfs_optionisset(vfsp, MNTOPT_RO, NULL)) { |
|
382 |
readonly = B_TRUE; |
|
383 |
do_readonly = B_TRUE; |
|
384 |
} else if (vfs_optionisset(vfsp, MNTOPT_RW, NULL)) { |
|
385 |
readonly = B_FALSE; |
|
386 |
do_readonly = B_TRUE; |
|
387 |
} |
|
388 |
if (vfs_optionisset(vfsp, MNTOPT_NOSUID, NULL)) { |
|
389 |
devices = B_FALSE; |
|
390 |
setuid = B_FALSE; |
|
391 |
do_devices = B_TRUE; |
|
392 |
do_setuid = B_TRUE; |
|
393 |
} else { |
|
394 |
if (vfs_optionisset(vfsp, MNTOPT_NODEVICES, NULL)) { |
|
395 |
devices = B_FALSE; |
|
396 |
do_devices = B_TRUE; |
|
3912 | 397 |
} else if (vfs_optionisset(vfsp, MNTOPT_DEVICES, NULL)) { |
1544 | 398 |
devices = B_TRUE; |
399 |
do_devices = B_TRUE; |
|
400 |
} |
|
401 |
||
402 |
if (vfs_optionisset(vfsp, MNTOPT_NOSETUID, NULL)) { |
|
403 |
setuid = B_FALSE; |
|
404 |
do_setuid = B_TRUE; |
|
405 |
} else if (vfs_optionisset(vfsp, MNTOPT_SETUID, NULL)) { |
|
406 |
setuid = B_TRUE; |
|
407 |
do_setuid = B_TRUE; |
|
408 |
} |
|
409 |
} |
|
410 |
if (vfs_optionisset(vfsp, MNTOPT_NOEXEC, NULL)) { |
|
411 |
exec = B_FALSE; |
|
412 |
do_exec = B_TRUE; |
|
413 |
} else if (vfs_optionisset(vfsp, MNTOPT_EXEC, NULL)) { |
|
414 |
exec = B_TRUE; |
|
415 |
do_exec = B_TRUE; |
|
416 |
} |
|
3234 | 417 |
if (vfs_optionisset(vfsp, MNTOPT_NOXATTR, NULL)) { |
418 |
xattr = B_FALSE; |
|
419 |
do_xattr = B_TRUE; |
|
420 |
} else if (vfs_optionisset(vfsp, MNTOPT_XATTR, NULL)) { |
|
421 |
xattr = B_TRUE; |
|
422 |
do_xattr = B_TRUE; |
|
423 |
} |
|
4596
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
424 |
if (vfs_optionisset(vfsp, MNTOPT_NOATIME, NULL)) { |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
425 |
atime = B_FALSE; |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
426 |
do_atime = B_TRUE; |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
427 |
} else if (vfs_optionisset(vfsp, MNTOPT_ATIME, NULL)) { |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
428 |
atime = B_TRUE; |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
429 |
do_atime = B_TRUE; |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
430 |
} |
1544 | 431 |
|
432 |
/* |
|
433 |
* Register property callbacks. |
|
434 |
* |
|
435 |
* It would probably be fine to just check for i/o error from |
|
436 |
* the first prop_register(), but I guess I like to go |
|
437 |
* overboard... |
|
438 |
*/ |
|
439 |
ds = dmu_objset_ds(os); |
|
440 |
error = dsl_prop_register(ds, "atime", atime_changed_cb, zfsvfs); |
|
441 |
error = error ? error : dsl_prop_register(ds, |
|
3234 | 442 |
"xattr", xattr_changed_cb, zfsvfs); |
443 |
error = error ? error : dsl_prop_register(ds, |
|
1544 | 444 |
"recordsize", blksz_changed_cb, zfsvfs); |
445 |
error = error ? error : dsl_prop_register(ds, |
|
446 |
"readonly", readonly_changed_cb, zfsvfs); |
|
447 |
error = error ? error : dsl_prop_register(ds, |
|
448 |
"devices", devices_changed_cb, zfsvfs); |
|
449 |
error = error ? error : dsl_prop_register(ds, |
|
450 |
"setuid", setuid_changed_cb, zfsvfs); |
|
451 |
error = error ? error : dsl_prop_register(ds, |
|
452 |
"exec", exec_changed_cb, zfsvfs); |
|
453 |
error = error ? error : dsl_prop_register(ds, |
|
454 |
"snapdir", snapdir_changed_cb, zfsvfs); |
|
455 |
error = error ? error : dsl_prop_register(ds, |
|
456 |
"aclmode", acl_mode_changed_cb, zfsvfs); |
|
457 |
error = error ? error : dsl_prop_register(ds, |
|
458 |
"aclinherit", acl_inherit_changed_cb, zfsvfs); |
|
459 |
if (error) |
|
460 |
goto unregister; |
|
461 |
||
462 |
/* |
|
463 |
* Invoke our callbacks to restore temporary mount options. |
|
464 |
*/ |
|
465 |
if (do_readonly) |
|
466 |
readonly_changed_cb(zfsvfs, readonly); |
|
467 |
if (do_setuid) |
|
468 |
setuid_changed_cb(zfsvfs, setuid); |
|
469 |
if (do_exec) |
|
470 |
exec_changed_cb(zfsvfs, exec); |
|
471 |
if (do_devices) |
|
472 |
devices_changed_cb(zfsvfs, devices); |
|
3234 | 473 |
if (do_xattr) |
474 |
xattr_changed_cb(zfsvfs, xattr); |
|
4596
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
475 |
if (do_atime) |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
476 |
atime_changed_cb(zfsvfs, atime); |
1544 | 477 |
|
478 |
return (0); |
|
479 |
||
480 |
unregister: |
|
481 |
/* |
|
482 |
* We may attempt to unregister some callbacks that are not |
|
483 |
* registered, but this is OK; it will simply return ENOMSG, |
|
484 |
* which we will ignore. |
|
485 |
*/ |
|
486 |
(void) dsl_prop_unregister(ds, "atime", atime_changed_cb, zfsvfs); |
|
3234 | 487 |
(void) dsl_prop_unregister(ds, "xattr", xattr_changed_cb, zfsvfs); |
1544 | 488 |
(void) dsl_prop_unregister(ds, "recordsize", blksz_changed_cb, zfsvfs); |
489 |
(void) dsl_prop_unregister(ds, "readonly", readonly_changed_cb, zfsvfs); |
|
490 |
(void) dsl_prop_unregister(ds, "devices", devices_changed_cb, zfsvfs); |
|
491 |
(void) dsl_prop_unregister(ds, "setuid", setuid_changed_cb, zfsvfs); |
|
492 |
(void) dsl_prop_unregister(ds, "exec", exec_changed_cb, zfsvfs); |
|
493 |
(void) dsl_prop_unregister(ds, "snapdir", snapdir_changed_cb, zfsvfs); |
|
494 |
(void) dsl_prop_unregister(ds, "aclmode", acl_mode_changed_cb, zfsvfs); |
|
495 |
(void) dsl_prop_unregister(ds, "aclinherit", acl_inherit_changed_cb, |
|
496 |
zfsvfs); |
|
497 |
return (error); |
|
498 |
||
499 |
} |
|
500 |
||
501 |
static int |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
502 |
zfsvfs_setup(zfsvfs_t *zfsvfs, boolean_t mounting) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
503 |
{ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
504 |
uint_t readonly; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
505 |
int error; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
506 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
507 |
error = zfs_register_callbacks(zfsvfs->z_vfs); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
508 |
if (error) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
509 |
return (error); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
510 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
511 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
512 |
* Set the objset user_ptr to track its zfsvfs. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
513 |
*/ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
514 |
mutex_enter(&zfsvfs->z_os->os->os_user_ptr_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
515 |
dmu_objset_set_user(zfsvfs->z_os, zfsvfs); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
516 |
mutex_exit(&zfsvfs->z_os->os->os_user_ptr_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
517 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
518 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
519 |
* If we are not mounting (ie: online recv), then we don't |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
520 |
* have to worry about replaying the log as we blocked all |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
521 |
* operations out since we closed the ZIL. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
522 |
*/ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
523 |
if (mounting) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
524 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
525 |
* During replay we remove the read only flag to |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
526 |
* allow replays to succeed. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
527 |
*/ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
528 |
readonly = zfsvfs->z_vfs->vfs_flag & VFS_RDONLY; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
529 |
if (readonly != 0) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
530 |
zfsvfs->z_vfs->vfs_flag &= ~VFS_RDONLY; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
531 |
else |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
532 |
zfs_unlinked_drain(zfsvfs); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
533 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
534 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
535 |
* Parse and replay the intent log. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
536 |
* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
537 |
* Because of ziltest, this must be done after |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
538 |
* zfs_unlinked_drain(). (Further note: ziltest doesn't |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
539 |
* use readonly mounts, where zfs_unlinked_drain() isn't |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
540 |
* called.) This is because ziltest causes spa_sync() |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
541 |
* to think it's committed, but actually it is not, so |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
542 |
* the intent log contains many txg's worth of changes. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
543 |
* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
544 |
* In particular, if object N is in the unlinked set in |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
545 |
* the last txg to actually sync, then it could be |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
546 |
* actually freed in a later txg and then reallocated in |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
547 |
* a yet later txg. This would write a "create object |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
548 |
* N" record to the intent log. Normally, this would be |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
549 |
* fine because the spa_sync() would have written out |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
550 |
* the fact that object N is free, before we could write |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
551 |
* the "create object N" intent log record. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
552 |
* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
553 |
* But when we are in ziltest mode, we advance the "open |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
554 |
* txg" without actually spa_sync()-ing the changes to |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
555 |
* disk. So we would see that object N is still |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
556 |
* allocated and in the unlinked set, and there is an |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
557 |
* intent log record saying to allocate it. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
558 |
*/ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
559 |
zil_replay(zfsvfs->z_os, zfsvfs, &zfsvfs->z_assign, |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
560 |
zfs_replay_vector); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
561 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
562 |
zfsvfs->z_vfs->vfs_flag |= readonly; /* restore readonly bit */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
563 |
} |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
564 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
565 |
if (!zil_disable) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
566 |
zfsvfs->z_log = zil_open(zfsvfs->z_os, zfs_get_data); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
567 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
568 |
return (0); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
569 |
} |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
570 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
571 |
static int |
1544 | 572 |
zfs_domount(vfs_t *vfsp, char *osname, cred_t *cr) |
573 |
{ |
|
574 |
dev_t mount_dev; |
|
575 |
uint64_t recordsize, readonly; |
|
576 |
int error = 0; |
|
577 |
int mode; |
|
578 |
zfsvfs_t *zfsvfs; |
|
579 |
znode_t *zp = NULL; |
|
580 |
||
581 |
ASSERT(vfsp); |
|
582 |
ASSERT(osname); |
|
583 |
||
584 |
/* |
|
585 |
* Initialize the zfs-specific filesystem structure. |
|
586 |
* Should probably make this a kmem cache, shuffle fields, |
|
587 |
* and just bzero up to z_hold_mtx[]. |
|
588 |
*/ |
|
589 |
zfsvfs = kmem_zalloc(sizeof (zfsvfs_t), KM_SLEEP); |
|
590 |
zfsvfs->z_vfs = vfsp; |
|
591 |
zfsvfs->z_parent = zfsvfs; |
|
592 |
zfsvfs->z_assign = TXG_NOWAIT; |
|
593 |
zfsvfs->z_max_blksz = SPA_MAXBLOCKSIZE; |
|
594 |
zfsvfs->z_show_ctldir = ZFS_SNAPDIR_VISIBLE; |
|
595 |
||
596 |
mutex_init(&zfsvfs->z_znodes_lock, NULL, MUTEX_DEFAULT, NULL); |
|
597 |
list_create(&zfsvfs->z_all_znodes, sizeof (znode_t), |
|
598 |
offsetof(znode_t, z_link_node)); |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
599 |
rrw_init(&zfsvfs->z_teardown_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
600 |
rw_init(&zfsvfs->z_teardown_inactive_lock, NULL, RW_DEFAULT, NULL); |
1544 | 601 |
|
602 |
/* Initialize the generic filesystem structure. */ |
|
603 |
vfsp->vfs_bcount = 0; |
|
604 |
vfsp->vfs_data = NULL; |
|
605 |
||
606 |
if (zfs_create_unique_device(&mount_dev) == -1) { |
|
607 |
error = ENODEV; |
|
608 |
goto out; |
|
609 |
} |
|
610 |
ASSERT(vfs_devismounted(mount_dev) == 0); |
|
611 |
||
612 |
if (error = dsl_prop_get_integer(osname, "recordsize", &recordsize, |
|
613 |
NULL)) |
|
614 |
goto out; |
|
615 |
||
616 |
vfsp->vfs_dev = mount_dev; |
|
617 |
vfsp->vfs_fstype = zfsfstype; |
|
618 |
vfsp->vfs_bsize = recordsize; |
|
619 |
vfsp->vfs_flag |= VFS_NOTRUNC; |
|
620 |
vfsp->vfs_data = zfsvfs; |
|
621 |
||
622 |
if (error = dsl_prop_get_integer(osname, "readonly", &readonly, NULL)) |
|
623 |
goto out; |
|
624 |
||
625 |
if (readonly) |
|
626 |
mode = DS_MODE_PRIMARY | DS_MODE_READONLY; |
|
627 |
else |
|
628 |
mode = DS_MODE_PRIMARY; |
|
629 |
||
630 |
error = dmu_objset_open(osname, DMU_OST_ZFS, mode, &zfsvfs->z_os); |
|
631 |
if (error == EROFS) { |
|
632 |
mode = DS_MODE_PRIMARY | DS_MODE_READONLY; |
|
633 |
error = dmu_objset_open(osname, DMU_OST_ZFS, mode, |
|
634 |
&zfsvfs->z_os); |
|
635 |
} |
|
636 |
||
637 |
if (error) |
|
638 |
goto out; |
|
639 |
||
640 |
if (error = zfs_init_fs(zfsvfs, &zp, cr)) |
|
641 |
goto out; |
|
642 |
||
643 |
/* The call to zfs_init_fs leaves the vnode held, release it here. */ |
|
644 |
VN_RELE(ZTOV(zp)); |
|
645 |
||
646 |
if (dmu_objset_is_snapshot(zfsvfs->z_os)) { |
|
3234 | 647 |
uint64_t xattr; |
648 |
||
1544 | 649 |
ASSERT(mode & DS_MODE_READONLY); |
650 |
atime_changed_cb(zfsvfs, B_FALSE); |
|
651 |
readonly_changed_cb(zfsvfs, B_TRUE); |
|
3234 | 652 |
if (error = dsl_prop_get_integer(osname, "xattr", &xattr, NULL)) |
653 |
goto out; |
|
654 |
xattr_changed_cb(zfsvfs, xattr); |
|
1544 | 655 |
zfsvfs->z_issnap = B_TRUE; |
656 |
} else { |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
657 |
error = zfsvfs_setup(zfsvfs, B_TRUE); |
1544 | 658 |
} |
659 |
||
660 |
if (!zfsvfs->z_issnap) |
|
661 |
zfsctl_create(zfsvfs); |
|
662 |
out: |
|
663 |
if (error) { |
|
664 |
if (zfsvfs->z_os) |
|
665 |
dmu_objset_close(zfsvfs->z_os); |
|
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
666 |
mutex_destroy(&zfsvfs->z_znodes_lock); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
667 |
list_destroy(&zfsvfs->z_all_znodes); |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
668 |
rrw_destroy(&zfsvfs->z_teardown_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
669 |
rw_destroy(&zfsvfs->z_teardown_inactive_lock); |
1544 | 670 |
kmem_free(zfsvfs, sizeof (zfsvfs_t)); |
671 |
} else { |
|
672 |
atomic_add_32(&zfs_active_fs_count, 1); |
|
673 |
} |
|
674 |
||
675 |
return (error); |
|
676 |
} |
|
677 |
||
678 |
void |
|
679 |
zfs_unregister_callbacks(zfsvfs_t *zfsvfs) |
|
680 |
{ |
|
681 |
objset_t *os = zfsvfs->z_os; |
|
682 |
struct dsl_dataset *ds; |
|
683 |
||
684 |
/* |
|
685 |
* Unregister properties. |
|
686 |
*/ |
|
687 |
if (!dmu_objset_is_snapshot(os)) { |
|
688 |
ds = dmu_objset_ds(os); |
|
689 |
VERIFY(dsl_prop_unregister(ds, "atime", atime_changed_cb, |
|
690 |
zfsvfs) == 0); |
|
691 |
||
3234 | 692 |
VERIFY(dsl_prop_unregister(ds, "xattr", xattr_changed_cb, |
693 |
zfsvfs) == 0); |
|
694 |
||
1544 | 695 |
VERIFY(dsl_prop_unregister(ds, "recordsize", blksz_changed_cb, |
696 |
zfsvfs) == 0); |
|
697 |
||
698 |
VERIFY(dsl_prop_unregister(ds, "readonly", readonly_changed_cb, |
|
699 |
zfsvfs) == 0); |
|
700 |
||
701 |
VERIFY(dsl_prop_unregister(ds, "devices", devices_changed_cb, |
|
702 |
zfsvfs) == 0); |
|
703 |
||
704 |
VERIFY(dsl_prop_unregister(ds, "setuid", setuid_changed_cb, |
|
705 |
zfsvfs) == 0); |
|
706 |
||
707 |
VERIFY(dsl_prop_unregister(ds, "exec", exec_changed_cb, |
|
708 |
zfsvfs) == 0); |
|
709 |
||
710 |
VERIFY(dsl_prop_unregister(ds, "snapdir", snapdir_changed_cb, |
|
711 |
zfsvfs) == 0); |
|
712 |
||
713 |
VERIFY(dsl_prop_unregister(ds, "aclmode", acl_mode_changed_cb, |
|
714 |
zfsvfs) == 0); |
|
715 |
||
716 |
VERIFY(dsl_prop_unregister(ds, "aclinherit", |
|
717 |
acl_inherit_changed_cb, zfsvfs) == 0); |
|
718 |
} |
|
719 |
} |
|
720 |
||
3912 | 721 |
/* |
722 |
* Convert a decimal digit string to a uint64_t integer. |
|
723 |
*/ |
|
724 |
static int |
|
725 |
str_to_uint64(char *str, uint64_t *objnum) |
|
726 |
{ |
|
727 |
uint64_t num = 0; |
|
728 |
||
729 |
while (*str) { |
|
730 |
if (*str < '0' || *str > '9') |
|
731 |
return (EINVAL); |
|
732 |
||
733 |
num = num*10 + *str++ - '0'; |
|
734 |
} |
|
735 |
||
736 |
*objnum = num; |
|
737 |
return (0); |
|
738 |
} |
|
739 |
||
740 |
/* |
|
741 |
* The boot path passed from the boot loader is in the form of |
|
742 |
* "rootpool-name/root-filesystem-object-number'. Convert this |
|
743 |
* string to a dataset name: "rootpool-name/root-filesystem-name". |
|
744 |
*/ |
|
745 |
static int |
|
746 |
parse_bootpath(char *bpath, char *outpath) |
|
747 |
{ |
|
748 |
char *slashp; |
|
749 |
uint64_t objnum; |
|
750 |
int error; |
|
751 |
||
752 |
if (*bpath == 0 || *bpath == '/') |
|
753 |
return (EINVAL); |
|
754 |
||
755 |
slashp = strchr(bpath, '/'); |
|
756 |
||
757 |
/* if no '/', just return the pool name */ |
|
758 |
if (slashp == NULL) { |
|
759 |
(void) strcpy(outpath, bpath); |
|
760 |
return (0); |
|
761 |
} |
|
762 |
||
763 |
if (error = str_to_uint64(slashp+1, &objnum)) |
|
764 |
return (error); |
|
765 |
||
766 |
*slashp = '\0'; |
|
767 |
error = dsl_dsobj_to_dsname(bpath, objnum, outpath); |
|
768 |
*slashp = '/'; |
|
769 |
||
770 |
return (error); |
|
771 |
} |
|
772 |
||
1544 | 773 |
static int |
774 |
zfs_mountroot(vfs_t *vfsp, enum whymountroot why) |
|
775 |
{ |
|
776 |
int error = 0; |
|
777 |
int ret = 0; |
|
778 |
static int zfsrootdone = 0; |
|
779 |
zfsvfs_t *zfsvfs = NULL; |
|
780 |
znode_t *zp = NULL; |
|
781 |
vnode_t *vp = NULL; |
|
3912 | 782 |
char *zfs_bootpath; |
1544 | 783 |
|
784 |
ASSERT(vfsp); |
|
785 |
||
786 |
/* |
|
3912 | 787 |
* The filesystem that we mount as root is defined in the |
788 |
* "zfs-bootfs" property. |
|
1544 | 789 |
*/ |
790 |
if (why == ROOT_INIT) { |
|
791 |
if (zfsrootdone++) |
|
792 |
return (EBUSY); |
|
793 |
||
3912 | 794 |
if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(), |
795 |
DDI_PROP_DONTPASS, "zfs-bootfs", &zfs_bootpath) != |
|
796 |
DDI_SUCCESS) |
|
797 |
return (EIO); |
|
798 |
||
799 |
error = parse_bootpath(zfs_bootpath, rootfs.bo_name); |
|
800 |
ddi_prop_free(zfs_bootpath); |
|
801 |
||
802 |
if (error) |
|
803 |
return (error); |
|
1544 | 804 |
|
805 |
if (error = vfs_lock(vfsp)) |
|
806 |
return (error); |
|
807 |
||
3912 | 808 |
if (error = zfs_domount(vfsp, rootfs.bo_name, CRED())) |
1544 | 809 |
goto out; |
810 |
||
811 |
zfsvfs = (zfsvfs_t *)vfsp->vfs_data; |
|
812 |
ASSERT(zfsvfs); |
|
813 |
if (error = zfs_zget(zfsvfs, zfsvfs->z_root, &zp)) |
|
814 |
goto out; |
|
815 |
||
816 |
vp = ZTOV(zp); |
|
817 |
mutex_enter(&vp->v_lock); |
|
818 |
vp->v_flag |= VROOT; |
|
819 |
mutex_exit(&vp->v_lock); |
|
820 |
rootvp = vp; |
|
821 |
||
822 |
/* |
|
823 |
* The zfs_zget call above returns with a hold on vp, we release |
|
824 |
* it here. |
|
825 |
*/ |
|
826 |
VN_RELE(vp); |
|
827 |
||
828 |
/* |
|
829 |
* Mount root as readonly initially, it will be remouted |
|
830 |
* read/write by /lib/svc/method/fs-usr. |
|
831 |
*/ |
|
832 |
readonly_changed_cb(vfsp->vfs_data, B_TRUE); |
|
833 |
vfs_add((struct vnode *)0, vfsp, |
|
834 |
(vfsp->vfs_flag & VFS_RDONLY) ? MS_RDONLY : 0); |
|
835 |
out: |
|
836 |
vfs_unlock(vfsp); |
|
837 |
ret = (error) ? error : 0; |
|
838 |
return (ret); |
|
839 |
} else if (why == ROOT_REMOUNT) { |
|
840 |
readonly_changed_cb(vfsp->vfs_data, B_FALSE); |
|
841 |
vfsp->vfs_flag |= VFS_REMOUNT; |
|
4596
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
842 |
|
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
843 |
/* refresh mount options */ |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
844 |
zfs_unregister_callbacks(vfsp->vfs_data); |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
845 |
return (zfs_register_callbacks(vfsp)); |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
846 |
|
1544 | 847 |
} else if (why == ROOT_UNMOUNT) { |
848 |
zfs_unregister_callbacks((zfsvfs_t *)vfsp->vfs_data); |
|
849 |
(void) zfs_sync(vfsp, 0, 0); |
|
850 |
return (0); |
|
851 |
} |
|
852 |
||
853 |
/* |
|
854 |
* if "why" is equal to anything else other than ROOT_INIT, |
|
855 |
* ROOT_REMOUNT, or ROOT_UNMOUNT, we do not support it. |
|
856 |
*/ |
|
857 |
return (ENOTSUP); |
|
858 |
} |
|
859 |
||
789 | 860 |
/*ARGSUSED*/ |
861 |
static int |
|
862 |
zfs_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr) |
|
863 |
{ |
|
864 |
char *osname; |
|
865 |
pathname_t spn; |
|
866 |
int error = 0; |
|
867 |
uio_seg_t fromspace = (uap->flags & MS_SYSSPACE) ? |
|
3912 | 868 |
UIO_SYSSPACE : UIO_USERSPACE; |
789 | 869 |
int canwrite; |
870 |
||
871 |
if (mvp->v_type != VDIR) |
|
872 |
return (ENOTDIR); |
|
873 |
||
874 |
mutex_enter(&mvp->v_lock); |
|
875 |
if ((uap->flags & MS_REMOUNT) == 0 && |
|
876 |
(uap->flags & MS_OVERLAY) == 0 && |
|
877 |
(mvp->v_count != 1 || (mvp->v_flag & VROOT))) { |
|
878 |
mutex_exit(&mvp->v_lock); |
|
879 |
return (EBUSY); |
|
880 |
} |
|
881 |
mutex_exit(&mvp->v_lock); |
|
882 |
||
883 |
/* |
|
884 |
* ZFS does not support passing unparsed data in via MS_DATA. |
|
885 |
* Users should use the MS_OPTIONSTR interface; this means |
|
886 |
* that all option parsing is already done and the options struct |
|
887 |
* can be interrogated. |
|
888 |
*/ |
|
889 |
if ((uap->flags & MS_DATA) && uap->datalen > 0) |
|
890 |
return (EINVAL); |
|
891 |
||
892 |
/* |
|
893 |
* Get the objset name (the "special" mount argument). |
|
894 |
*/ |
|
895 |
if (error = pn_get(uap->spec, fromspace, &spn)) |
|
896 |
return (error); |
|
897 |
||
898 |
osname = spn.pn_path; |
|
899 |
||
4543 | 900 |
/* |
901 |
* Check for mount privilege? |
|
902 |
* |
|
903 |
* If we don't have privilege then see if |
|
904 |
* we have local permission to allow it |
|
905 |
*/ |
|
906 |
error = secpolicy_fs_mount(cr, mvp, vfsp); |
|
907 |
if (error) { |
|
908 |
error = dsl_deleg_access(osname, ZFS_DELEG_PERM_MOUNT, cr); |
|
909 |
if (error == 0) { |
|
910 |
vattr_t vattr; |
|
911 |
||
912 |
/* |
|
913 |
* Make sure user is the owner of the mount point |
|
914 |
* or has sufficient privileges. |
|
915 |
*/ |
|
916 |
||
917 |
vattr.va_mask = AT_UID; |
|
918 |
||
4614
58fcfc586435
6578215 zfs_mount() needs to handle GETATTR failures better.
marks
parents:
4596
diff
changeset
|
919 |
if (error = VOP_GETATTR(mvp, &vattr, 0, cr)) { |
4543 | 920 |
goto out; |
921 |
} |
|
922 |
||
923 |
if (error = secpolicy_vnode_owner(cr, vattr.va_uid)) { |
|
924 |
goto out; |
|
925 |
} |
|
926 |
||
927 |
if (error = VOP_ACCESS(mvp, VWRITE, 0, cr)) { |
|
928 |
goto out; |
|
929 |
} |
|
930 |
||
931 |
secpolicy_fs_mount_clearopts(cr, vfsp); |
|
932 |
} else { |
|
933 |
goto out; |
|
934 |
} |
|
935 |
} |
|
789 | 936 |
|
937 |
/* |
|
938 |
* Refuse to mount a filesystem if we are in a local zone and the |
|
939 |
* dataset is not visible. |
|
940 |
*/ |
|
941 |
if (!INGLOBALZONE(curproc) && |
|
942 |
(!zone_dataset_visible(osname, &canwrite) || !canwrite)) { |
|
943 |
error = EPERM; |
|
944 |
goto out; |
|
945 |
} |
|
946 |
||
4596
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
947 |
/* |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
948 |
* When doing a remount, we simply refresh our temporary properties |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
949 |
* according to those options set in the current VFS options. |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
950 |
*/ |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
951 |
if (uap->flags & MS_REMOUNT) { |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
952 |
/* refresh mount options */ |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
953 |
zfs_unregister_callbacks(vfsp->vfs_data); |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
954 |
error = zfs_register_callbacks(vfsp); |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
955 |
goto out; |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
956 |
} |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
957 |
|
1544 | 958 |
error = zfs_domount(vfsp, osname, cr); |
789 | 959 |
|
960 |
out: |
|
961 |
pn_free(&spn); |
|
962 |
return (error); |
|
963 |
} |
|
964 |
||
965 |
static int |
|
966 |
zfs_statvfs(vfs_t *vfsp, struct statvfs64 *statp) |
|
967 |
{ |
|
968 |
zfsvfs_t *zfsvfs = vfsp->vfs_data; |
|
969 |
dev32_t d32; |
|
2885 | 970 |
uint64_t refdbytes, availbytes, usedobjs, availobjs; |
789 | 971 |
|
972 |
ZFS_ENTER(zfsvfs); |
|
973 |
||
2885 | 974 |
dmu_objset_space(zfsvfs->z_os, |
975 |
&refdbytes, &availbytes, &usedobjs, &availobjs); |
|
789 | 976 |
|
977 |
/* |
|
978 |
* The underlying storage pool actually uses multiple block sizes. |
|
979 |
* We report the fragsize as the smallest block size we support, |
|
980 |
* and we report our blocksize as the filesystem's maximum blocksize. |
|
981 |
*/ |
|
982 |
statp->f_frsize = 1UL << SPA_MINBLOCKSHIFT; |
|
983 |
statp->f_bsize = zfsvfs->z_max_blksz; |
|
984 |
||
985 |
/* |
|
986 |
* The following report "total" blocks of various kinds in the |
|
987 |
* file system, but reported in terms of f_frsize - the |
|
988 |
* "fragment" size. |
|
989 |
*/ |
|
990 |
||
2885 | 991 |
statp->f_blocks = (refdbytes + availbytes) >> SPA_MINBLOCKSHIFT; |
992 |
statp->f_bfree = availbytes >> SPA_MINBLOCKSHIFT; |
|
789 | 993 |
statp->f_bavail = statp->f_bfree; /* no root reservation */ |
994 |
||
995 |
/* |
|
996 |
* statvfs() should really be called statufs(), because it assumes |
|
997 |
* static metadata. ZFS doesn't preallocate files, so the best |
|
998 |
* we can do is report the max that could possibly fit in f_files, |
|
999 |
* and that minus the number actually used in f_ffree. |
|
1000 |
* For f_ffree, report the smaller of the number of object available |
|
1001 |
* and the number of blocks (each object will take at least a block). |
|
1002 |
*/ |
|
2885 | 1003 |
statp->f_ffree = MIN(availobjs, statp->f_bfree); |
789 | 1004 |
statp->f_favail = statp->f_ffree; /* no "root reservation" */ |
2885 | 1005 |
statp->f_files = statp->f_ffree + usedobjs; |
789 | 1006 |
|
1007 |
(void) cmpldev(&d32, vfsp->vfs_dev); |
|
1008 |
statp->f_fsid = d32; |
|
1009 |
||
1010 |
/* |
|
1011 |
* We're a zfs filesystem. |
|
1012 |
*/ |
|
1013 |
(void) strcpy(statp->f_basetype, vfssw[vfsp->vfs_fstype].vsw_name); |
|
1014 |
||
1123
02a0390fbc7d
6363529 UNIX03/UNIX98 *vsx* CAPI.os/files/fstatvfs/T.fstatvfs 11 FAILS
marks
parents:
849
diff
changeset
|
1015 |
statp->f_flag = vf_to_stf(vfsp->vfs_flag); |
789 | 1016 |
|
1017 |
statp->f_namemax = ZFS_MAXNAMELEN; |
|
1018 |
||
1019 |
/* |
|
1020 |
* We have all of 32 characters to stuff a string here. |
|
1021 |
* Is there anything useful we could/should provide? |
|
1022 |
*/ |
|
1023 |
bzero(statp->f_fstr, sizeof (statp->f_fstr)); |
|
1024 |
||
1025 |
ZFS_EXIT(zfsvfs); |
|
1026 |
return (0); |
|
1027 |
} |
|
1028 |
||
1029 |
static int |
|
1030 |
zfs_root(vfs_t *vfsp, vnode_t **vpp) |
|
1031 |
{ |
|
1032 |
zfsvfs_t *zfsvfs = vfsp->vfs_data; |
|
1033 |
znode_t *rootzp; |
|
1034 |
int error; |
|
1035 |
||
1036 |
ZFS_ENTER(zfsvfs); |
|
1037 |
||
1038 |
error = zfs_zget(zfsvfs, zfsvfs->z_root, &rootzp); |
|
1039 |
if (error == 0) |
|
1040 |
*vpp = ZTOV(rootzp); |
|
1041 |
||
1042 |
ZFS_EXIT(zfsvfs); |
|
1043 |
return (error); |
|
1044 |
} |
|
1045 |
||
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1046 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1047 |
* Teardown the zfsvfs::z_os. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1048 |
* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1049 |
* Note, if 'unmounting' if FALSE, we return with the 'z_teardown_lock' |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1050 |
* and 'z_teardown_inactive_lock' held. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1051 |
*/ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1052 |
static int |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1053 |
zfsvfs_teardown(zfsvfs_t *zfsvfs, boolean_t unmounting) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1054 |
{ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1055 |
objset_t *os = zfsvfs->z_os; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1056 |
znode_t *zp, *nextzp; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1057 |
znode_t markerzp; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1058 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1059 |
rrw_enter(&zfsvfs->z_teardown_lock, RW_WRITER, FTAG); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1060 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1061 |
if (!unmounting) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1062 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1063 |
* We purge the parent filesystem's vfsp as the parent |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1064 |
* filesystem and all of its snapshots have their vnode's |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1065 |
* v_vfsp set to the parent's filesystem's vfsp. Note, |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1066 |
* 'z_parent' is self referential for non-snapshots. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1067 |
*/ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1068 |
(void) dnlc_purge_vfsp(zfsvfs->z_parent->z_vfs, 0); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1069 |
} |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1070 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1071 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1072 |
* Close the zil. NB: Can't close the zil while zfs_inactive |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1073 |
* threads are blocked as zil_close can call zfs_inactive. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1074 |
*/ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1075 |
if (zfsvfs->z_log) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1076 |
zil_close(zfsvfs->z_log); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1077 |
zfsvfs->z_log = NULL; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1078 |
} |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1079 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1080 |
rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_WRITER); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1081 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1082 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1083 |
* If we are not unmounting (ie: online recv) and someone already |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1084 |
* unmounted this file system while we were doing the switcheroo, |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1085 |
* or a reopen of z_os failed then just bail out now. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1086 |
*/ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1087 |
if (!unmounting && (zfsvfs->z_unmounted || zfsvfs->z_os == NULL)) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1088 |
rw_exit(&zfsvfs->z_teardown_inactive_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1089 |
rrw_exit(&zfsvfs->z_teardown_lock, FTAG); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1090 |
return (EIO); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1091 |
} |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1092 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1093 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1094 |
* At this point there are no vops active, and any new vops will |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1095 |
* fail with EIO since we have z_teardown_lock for writer (only |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1096 |
* relavent for forced unmount). |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1097 |
* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1098 |
* Release all holds on dbufs. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1099 |
* Note, the dmu can still callback via znode_pageout_func() |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1100 |
* which can zfs_znode_free() the znode. So we lock |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1101 |
* z_all_znodes; search the list for a held dbuf; drop the lock |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1102 |
* (we know zp can't disappear if we hold a dbuf lock) then |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1103 |
* regrab the lock and restart. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1104 |
* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1105 |
* Since we have to restart the search after finding each held dbuf, |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1106 |
* we do two things to speed up searching: we insert a dummy znode |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1107 |
* ('markerzp') to detect the original tail of the list, and move |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1108 |
* non-held znodes to the end of the list. Once we hit 'markerzp', |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1109 |
* we know we've looked at each znode and can break out. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1110 |
*/ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1111 |
mutex_enter(&zfsvfs->z_znodes_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1112 |
list_insert_tail(&zfsvfs->z_all_znodes, &markerzp); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1113 |
for (zp = list_head(&zfsvfs->z_all_znodes); zp != &markerzp; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1114 |
zp = nextzp) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1115 |
nextzp = list_next(&zfsvfs->z_all_znodes, zp); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1116 |
if (zp->z_dbuf_held) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1117 |
/* dbufs should only be held when force unmounting */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1118 |
zp->z_dbuf_held = 0; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1119 |
mutex_exit(&zfsvfs->z_znodes_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1120 |
dmu_buf_rele(zp->z_dbuf, NULL); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1121 |
/* Start again */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1122 |
mutex_enter(&zfsvfs->z_znodes_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1123 |
nextzp = list_head(&zfsvfs->z_all_znodes); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1124 |
} else { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1125 |
list_remove(&zfsvfs->z_all_znodes, zp); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1126 |
list_insert_tail(&zfsvfs->z_all_znodes, zp); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1127 |
} |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1128 |
} |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1129 |
list_remove(&zfsvfs->z_all_znodes, &markerzp); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1130 |
mutex_exit(&zfsvfs->z_znodes_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1131 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1132 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1133 |
* If we are unmounting, set the unmounted flag and let new vops |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1134 |
* unblock. zfs_inactive will have the unmounted behavior, and all |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1135 |
* other vops will fail with EIO. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1136 |
*/ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1137 |
if (unmounting) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1138 |
zfsvfs->z_unmounted = B_TRUE; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1139 |
rrw_exit(&zfsvfs->z_teardown_lock, FTAG); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1140 |
rw_exit(&zfsvfs->z_teardown_inactive_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1141 |
} |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1142 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1143 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1144 |
* z_os will be NULL if there was an error in attempting to reopen |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1145 |
* zfsvfs, so just return as the properties had already been |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1146 |
* unregistered and cached data had been evicted before. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1147 |
*/ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1148 |
if (zfsvfs->z_os == NULL) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1149 |
return (0); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1150 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1151 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1152 |
* Unregister properties. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1153 |
*/ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1154 |
zfs_unregister_callbacks(zfsvfs); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1155 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1156 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1157 |
* Evict cached data |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1158 |
*/ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1159 |
(void) dmu_objset_evict_dbufs(os); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1160 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1161 |
return (0); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1162 |
} |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1163 |
|
789 | 1164 |
/*ARGSUSED*/ |
1165 |
static int |
|
1166 |
zfs_umount(vfs_t *vfsp, int fflag, cred_t *cr) |
|
1167 |
{ |
|
1168 |
zfsvfs_t *zfsvfs = vfsp->vfs_data; |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1169 |
objset_t *os; |
789 | 1170 |
int ret; |
1171 |
||
4543 | 1172 |
ret = secpolicy_fs_unmount(cr, vfsp); |
1173 |
if (ret) { |
|
1174 |
ret = dsl_deleg_access((char *)refstr_value(vfsp->vfs_resource), |
|
1175 |
ZFS_DELEG_PERM_MOUNT, cr); |
|
1176 |
if (ret) |
|
1177 |
return (ret); |
|
1178 |
} |
|
1484
d330e98f8ed7
6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents:
1298
diff
changeset
|
1179 |
|
4736
f8714efb3e12
6509628 unmount of a snapshot (from 'zfs destroy') is slow
ek110237
parents:
4614
diff
changeset
|
1180 |
/* |
f8714efb3e12
6509628 unmount of a snapshot (from 'zfs destroy') is slow
ek110237
parents:
4614
diff
changeset
|
1181 |
* We purge the parent filesystem's vfsp as the parent filesystem |
f8714efb3e12
6509628 unmount of a snapshot (from 'zfs destroy') is slow
ek110237
parents:
4614
diff
changeset
|
1182 |
* and all of its snapshots have their vnode's v_vfsp set to the |
f8714efb3e12
6509628 unmount of a snapshot (from 'zfs destroy') is slow
ek110237
parents:
4614
diff
changeset
|
1183 |
* parent's filesystem's vfsp. Note, 'z_parent' is self |
f8714efb3e12
6509628 unmount of a snapshot (from 'zfs destroy') is slow
ek110237
parents:
4614
diff
changeset
|
1184 |
* referential for non-snapshots. |
f8714efb3e12
6509628 unmount of a snapshot (from 'zfs destroy') is slow
ek110237
parents:
4614
diff
changeset
|
1185 |
*/ |
f8714efb3e12
6509628 unmount of a snapshot (from 'zfs destroy') is slow
ek110237
parents:
4614
diff
changeset
|
1186 |
(void) dnlc_purge_vfsp(zfsvfs->z_parent->z_vfs, 0); |
1484
d330e98f8ed7
6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents:
1298
diff
changeset
|
1187 |
|
789 | 1188 |
/* |
1189 |
* Unmount any snapshots mounted under .zfs before unmounting the |
|
1190 |
* dataset itself. |
|
1191 |
*/ |
|
1192 |
if (zfsvfs->z_ctldir != NULL && |
|
4543 | 1193 |
(ret = zfsctl_umount_snapshots(vfsp, fflag, cr)) != 0) { |
789 | 1194 |
return (ret); |
4543 | 1195 |
} |
789 | 1196 |
|
4787 | 1197 |
if (!(fflag & MS_FORCE)) { |
4480
0976678e58c5
6544140 assertion failed: err == 0 (0x11 == 0x0), file: ../../common/fs/zfs/zfs_znode.c, line: 555
gw25295
parents:
3912
diff
changeset
|
1198 |
/* |
4787 | 1199 |
* Check the number of active vnodes in the file system. |
1200 |
* Our count is maintained in the vfs structure, but the |
|
1201 |
* number is off by 1 to indicate a hold on the vfs |
|
1202 |
* structure itself. |
|
1203 |
* |
|
1204 |
* The '.zfs' directory maintains a reference of its |
|
1205 |
* own, and any active references underneath are |
|
1206 |
* reflected in the vnode count. |
|
789 | 1207 |
*/ |
4787 | 1208 |
if (zfsvfs->z_ctldir == NULL) { |
1209 |
if (vfsp->vfs_count > 1) |
|
1210 |
return (EBUSY); |
|
1211 |
} else { |
|
1212 |
if (vfsp->vfs_count > 2 || |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1213 |
zfsvfs->z_ctldir->v_count > 1) |
4787 | 1214 |
return (EBUSY); |
789 | 1215 |
} |
1216 |
} |
|
1217 |
||
1218 |
vfsp->vfs_flag |= VFS_UNMOUNTED; |
|
4787 | 1219 |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1220 |
VERIFY(zfsvfs_teardown(zfsvfs, B_TRUE) == 0); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1221 |
os = zfsvfs->z_os; |
4787 | 1222 |
|
1223 |
/* |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1224 |
* z_os will be NULL if there was an error in |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1225 |
* attempting to reopen zfsvfs. |
4787 | 1226 |
*/ |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1227 |
if (os != NULL) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1228 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1229 |
* Unset the objset user_ptr. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1230 |
*/ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1231 |
mutex_enter(&os->os->os_user_ptr_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1232 |
dmu_objset_set_user(os, NULL); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1233 |
mutex_exit(&os->os->os_user_ptr_lock); |
4787 | 1234 |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1235 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1236 |
* Finally close the objset |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1237 |
*/ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1238 |
dmu_objset_close(os); |
4787 | 1239 |
} |
1240 |
||
1241 |
/* |
|
1242 |
* We can now safely destroy the '.zfs' directory node. |
|
1243 |
*/ |
|
1244 |
if (zfsvfs->z_ctldir != NULL) |
|
1245 |
zfsctl_destroy(zfsvfs); |
|
789 | 1246 |
|
1247 |
return (0); |
|
1248 |
} |
|
1249 |
||
1250 |
static int |
|
1251 |
zfs_vget(vfs_t *vfsp, vnode_t **vpp, fid_t *fidp) |
|
1252 |
{ |
|
1253 |
zfsvfs_t *zfsvfs = vfsp->vfs_data; |
|
1254 |
znode_t *zp; |
|
1255 |
uint64_t object = 0; |
|
1256 |
uint64_t fid_gen = 0; |
|
1257 |
uint64_t gen_mask; |
|
1258 |
uint64_t zp_gen; |
|
1259 |
int i, err; |
|
1260 |
||
1261 |
*vpp = NULL; |
|
1262 |
||
1263 |
ZFS_ENTER(zfsvfs); |
|
1264 |
||
1265 |
if (fidp->fid_len == LONG_FID_LEN) { |
|
1266 |
zfid_long_t *zlfid = (zfid_long_t *)fidp; |
|
1267 |
uint64_t objsetid = 0; |
|
1268 |
uint64_t setgen = 0; |
|
1269 |
||
1270 |
for (i = 0; i < sizeof (zlfid->zf_setid); i++) |
|
1271 |
objsetid |= ((uint64_t)zlfid->zf_setid[i]) << (8 * i); |
|
1272 |
||
1273 |
for (i = 0; i < sizeof (zlfid->zf_setgen); i++) |
|
1274 |
setgen |= ((uint64_t)zlfid->zf_setgen[i]) << (8 * i); |
|
1275 |
||
1276 |
ZFS_EXIT(zfsvfs); |
|
1277 |
||
1278 |
err = zfsctl_lookup_objset(vfsp, objsetid, &zfsvfs); |
|
1279 |
if (err) |
|
1280 |
return (EINVAL); |
|
1281 |
ZFS_ENTER(zfsvfs); |
|
1282 |
} |
|
1283 |
||
1284 |
if (fidp->fid_len == SHORT_FID_LEN || fidp->fid_len == LONG_FID_LEN) { |
|
1285 |
zfid_short_t *zfid = (zfid_short_t *)fidp; |
|
1286 |
||
1287 |
for (i = 0; i < sizeof (zfid->zf_object); i++) |
|
1288 |
object |= ((uint64_t)zfid->zf_object[i]) << (8 * i); |
|
1289 |
||
1290 |
for (i = 0; i < sizeof (zfid->zf_gen); i++) |
|
1291 |
fid_gen |= ((uint64_t)zfid->zf_gen[i]) << (8 * i); |
|
1292 |
} else { |
|
1293 |
ZFS_EXIT(zfsvfs); |
|
1294 |
return (EINVAL); |
|
1295 |
} |
|
1296 |
||
1297 |
/* A zero fid_gen means we are in the .zfs control directories */ |
|
1298 |
if (fid_gen == 0 && |
|
1299 |
(object == ZFSCTL_INO_ROOT || object == ZFSCTL_INO_SNAPDIR)) { |
|
1300 |
*vpp = zfsvfs->z_ctldir; |
|
1301 |
ASSERT(*vpp != NULL); |
|
1302 |
if (object == ZFSCTL_INO_SNAPDIR) { |
|
1303 |
VERIFY(zfsctl_root_lookup(*vpp, "snapshot", vpp, NULL, |
|
1304 |
0, NULL, NULL) == 0); |
|
1305 |
} else { |
|
1306 |
VN_HOLD(*vpp); |
|
1307 |
} |
|
1308 |
ZFS_EXIT(zfsvfs); |
|
1309 |
return (0); |
|
1310 |
} |
|
1311 |
||
1312 |
gen_mask = -1ULL >> (64 - 8 * i); |
|
1313 |
||
1314 |
dprintf("getting %llu [%u mask %llx]\n", object, fid_gen, gen_mask); |
|
1315 |
if (err = zfs_zget(zfsvfs, object, &zp)) { |
|
1316 |
ZFS_EXIT(zfsvfs); |
|
1317 |
return (err); |
|
1318 |
} |
|
1319 |
zp_gen = zp->z_phys->zp_gen & gen_mask; |
|
1320 |
if (zp_gen == 0) |
|
1321 |
zp_gen = 1; |
|
3461 | 1322 |
if (zp->z_unlinked || zp_gen != fid_gen) { |
789 | 1323 |
dprintf("znode gen (%u) != fid gen (%u)\n", zp_gen, fid_gen); |
1324 |
VN_RELE(ZTOV(zp)); |
|
1325 |
ZFS_EXIT(zfsvfs); |
|
1326 |
return (EINVAL); |
|
1327 |
} |
|
1328 |
||
1329 |
*vpp = ZTOV(zp); |
|
1330 |
ZFS_EXIT(zfsvfs); |
|
1331 |
return (0); |
|
1332 |
} |
|
1333 |
||
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1334 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1335 |
* Block out VOPs and close zfsvfs_t::z_os |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1336 |
* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1337 |
* Note, if successful, then we return with the 'z_teardown_lock' and |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1338 |
* 'z_teardown_inactive_lock' write held. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1339 |
*/ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1340 |
int |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1341 |
zfs_suspend_fs(zfsvfs_t *zfsvfs, char *name, int *mode) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1342 |
{ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1343 |
int error; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1344 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1345 |
if ((error = zfsvfs_teardown(zfsvfs, B_FALSE)) != 0) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1346 |
return (error); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1347 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1348 |
*mode = zfsvfs->z_os->os_mode; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1349 |
dmu_objset_name(zfsvfs->z_os, name); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1350 |
dmu_objset_close(zfsvfs->z_os); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1351 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1352 |
return (0); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1353 |
} |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1354 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1355 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1356 |
* Reopen zfsvfs_t::z_os and release VOPs. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1357 |
*/ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1358 |
int |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1359 |
zfs_resume_fs(zfsvfs_t *zfsvfs, const char *osname, int mode) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1360 |
{ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1361 |
int err; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1362 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1363 |
ASSERT(RRW_WRITE_HELD(&zfsvfs->z_teardown_lock)); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1364 |
ASSERT(RW_WRITE_HELD(&zfsvfs->z_teardown_inactive_lock)); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1365 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1366 |
err = dmu_objset_open(osname, DMU_OST_ZFS, mode, &zfsvfs->z_os); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1367 |
if (err) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1368 |
zfsvfs->z_os = NULL; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1369 |
} else { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1370 |
znode_t *zp; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1371 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1372 |
VERIFY(zfsvfs_setup(zfsvfs, B_FALSE) == 0); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1373 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1374 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1375 |
* Attempt to re-establish all the active znodes with |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1376 |
* their dbufs. If a zfs_rezget() fails, then we'll let |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1377 |
* any potential callers discover that via ZFS_ENTER_VERIFY_VP |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1378 |
* when they try to use their znode. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1379 |
*/ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1380 |
mutex_enter(&zfsvfs->z_znodes_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1381 |
for (zp = list_head(&zfsvfs->z_all_znodes); zp; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1382 |
zp = list_next(&zfsvfs->z_all_znodes, zp)) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1383 |
ASSERT(!zp->z_dbuf_held); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1384 |
(void) zfs_rezget(zp); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1385 |
} |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1386 |
mutex_exit(&zfsvfs->z_znodes_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1387 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1388 |
} |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1389 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1390 |
/* release the VOPs */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1391 |
rw_exit(&zfsvfs->z_teardown_inactive_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1392 |
rrw_exit(&zfsvfs->z_teardown_lock, FTAG); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1393 |
|
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1394 |
if (err) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1395 |
/* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1396 |
* Since we couldn't reopen zfsvfs::z_os, force |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1397 |
* unmount this file system. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1398 |
*/ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1399 |
if (vn_vfswlock(zfsvfs->z_vfs->vfs_vnodecovered) == 0) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1400 |
(void) dounmount(zfsvfs->z_vfs, MS_FORCE, CRED()); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1401 |
} |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1402 |
return (err); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1403 |
} |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1404 |
|
789 | 1405 |
static void |
1406 |
zfs_freevfs(vfs_t *vfsp) |
|
1407 |
{ |
|
1408 |
zfsvfs_t *zfsvfs = vfsp->vfs_data; |
|
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
1409 |
int i; |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
1410 |
|
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
1411 |
for (i = 0; i != ZFS_OBJ_MTX_SZ; i++) |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
1412 |
mutex_destroy(&zfsvfs->z_hold_mtx[i]); |
789 | 1413 |
|
4787 | 1414 |
mutex_destroy(&zfsvfs->z_znodes_lock); |
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
1415 |
list_destroy(&zfsvfs->z_all_znodes); |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1416 |
rrw_destroy(&zfsvfs->z_teardown_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1417 |
rw_destroy(&zfsvfs->z_teardown_inactive_lock); |
789 | 1418 |
kmem_free(zfsvfs, sizeof (zfsvfs_t)); |
1419 |
||
1420 |
atomic_add_32(&zfs_active_fs_count, -1); |
|
1421 |
} |
|
1422 |
||
1423 |
/* |
|
1424 |
* VFS_INIT() initialization. Note that there is no VFS_FINI(), |
|
1425 |
* so we can't safely do any non-idempotent initialization here. |
|
1426 |
* Leave that to zfs_init() and zfs_fini(), which are called |
|
1427 |
* from the module's _init() and _fini() entry points. |
|
1428 |
*/ |
|
1429 |
/*ARGSUSED*/ |
|
1430 |
static int |
|
1431 |
zfs_vfsinit(int fstype, char *name) |
|
1432 |
{ |
|
1433 |
int error; |
|
1434 |
||
1435 |
zfsfstype = fstype; |
|
1436 |
||
1437 |
/* |
|
1438 |
* Setup vfsops and vnodeops tables. |
|
1439 |
*/ |
|
1440 |
error = vfs_setfsops(fstype, zfs_vfsops_template, &zfs_vfsops); |
|
1441 |
if (error != 0) { |
|
1442 |
cmn_err(CE_WARN, "zfs: bad vfs ops template"); |
|
1443 |
} |
|
1444 |
||
1445 |
error = zfs_create_op_tables(); |
|
1446 |
if (error) { |
|
1447 |
zfs_remove_op_tables(); |
|
1448 |
cmn_err(CE_WARN, "zfs: bad vnode ops template"); |
|
1449 |
(void) vfs_freevfsops_by_type(zfsfstype); |
|
1450 |
return (error); |
|
1451 |
} |
|
1452 |
||
1453 |
mutex_init(&zfs_dev_mtx, NULL, MUTEX_DEFAULT, NULL); |
|
1454 |
||
1455 |
/* |
|
849
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
1456 |
* Unique major number for all zfs mounts. |
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
1457 |
* If we run out of 32-bit minors, we'll getudev() another major. |
789 | 1458 |
*/ |
849
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
1459 |
zfs_major = ddi_name_to_major(ZFS_DRIVER); |
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
1460 |
zfs_minor = ZFS_MIN_MINOR; |
789 | 1461 |
|
1462 |
return (0); |
|
1463 |
} |
|
1464 |
||
1465 |
void |
|
1466 |
zfs_init(void) |
|
1467 |
{ |
|
1468 |
/* |
|
1469 |
* Initialize .zfs directory structures |
|
1470 |
*/ |
|
1471 |
zfsctl_init(); |
|
1472 |
||
1473 |
/* |
|
1474 |
* Initialize znode cache, vnode ops, etc... |
|
1475 |
*/ |
|
1476 |
zfs_znode_init(); |
|
1477 |
} |
|
1478 |
||
1479 |
void |
|
1480 |
zfs_fini(void) |
|
1481 |
{ |
|
1482 |
zfsctl_fini(); |
|
1483 |
zfs_znode_fini(); |
|
1484 |
} |
|
1485 |
||
1486 |
int |
|
1487 |
zfs_busy(void) |
|
1488 |
{ |
|
1489 |
return (zfs_active_fs_count != 0); |
|
1490 |
} |
|
1491 |
||
4577 | 1492 |
int |
5147
5e950ccc9585
6596190 "zfs list" is slow due to version property
rm160521
parents:
4944
diff
changeset
|
1493 |
zfs_get_version(objset_t *os, uint64_t *version) |
4577 | 1494 |
{ |
1495 |
int error; |
|
1496 |
||
5147
5e950ccc9585
6596190 "zfs list" is slow due to version property
rm160521
parents:
4944
diff
changeset
|
1497 |
error = zap_lookup(os, MASTER_NODE_OBJ, ZPL_VERSION_STR, 8, 1, version); |
4577 | 1498 |
return (error); |
1499 |
} |
|
1500 |
||
1501 |
int |
|
1502 |
zfs_set_version(const char *name, uint64_t newvers) |
|
1503 |
{ |
|
1504 |
int error; |
|
1505 |
objset_t *os; |
|
1506 |
dmu_tx_t *tx; |
|
1507 |
uint64_t curvers; |
|
1508 |
||
1509 |
/* |
|
1510 |
* XXX for now, require that the filesystem be unmounted. Would |
|
1511 |
* be nice to find the zfsvfs_t and just update that if |
|
1512 |
* possible. |
|
1513 |
*/ |
|
1514 |
||
1515 |
if (newvers < ZPL_VERSION_INITIAL || newvers > ZPL_VERSION) |
|
1516 |
return (EINVAL); |
|
1517 |
||
1518 |
error = dmu_objset_open(name, DMU_OST_ZFS, DS_MODE_PRIMARY, &os); |
|
1519 |
if (error) |
|
1520 |
return (error); |
|
1521 |
||
1522 |
error = zap_lookup(os, MASTER_NODE_OBJ, ZPL_VERSION_STR, |
|
1523 |
8, 1, &curvers); |
|
1524 |
if (error) |
|
1525 |
goto out; |
|
1526 |
if (newvers < curvers) { |
|
1527 |
error = EINVAL; |
|
1528 |
goto out; |
|
1529 |
} |
|
1530 |
||
1531 |
tx = dmu_tx_create(os); |
|
1532 |
dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, 0, ZPL_VERSION_STR); |
|
1533 |
error = dmu_tx_assign(tx, TXG_WAIT); |
|
1534 |
if (error) { |
|
1535 |
dmu_tx_abort(tx); |
|
1536 |
goto out; |
|
1537 |
} |
|
1538 |
error = zap_update(os, MASTER_NODE_OBJ, ZPL_VERSION_STR, 8, 1, |
|
1539 |
&newvers, tx); |
|
1540 |
||
1541 |
spa_history_internal_log(LOG_DS_UPGRADE, |
|
1542 |
dmu_objset_spa(os), tx, CRED(), |
|
1543 |
"oldver=%llu newver=%llu dataset = %llu", curvers, newvers, |
|
1544 |
dmu_objset_id(os)); |
|
1545 |
dmu_tx_commit(tx); |
|
1546 |
||
1547 |
out: |
|
1548 |
dmu_objset_close(os); |
|
1549 |
return (error); |
|
1550 |
} |
|
1551 |
||
789 | 1552 |
static vfsdef_t vfw = { |
1553 |
VFSDEF_VERSION, |
|
1554 |
MNTTYPE_ZFS, |
|
1555 |
zfs_vfsinit, |
|
1488 | 1556 |
VSW_HASPROTO|VSW_CANRWRO|VSW_CANREMOUNT|VSW_VOLATILEDEV|VSW_STATS, |
789 | 1557 |
&zfs_mntopts |
1558 |
}; |
|
1559 |
||
1560 |
struct modlfs zfs_modlfs = { |
|
4577 | 1561 |
&mod_fsops, "ZFS filesystem version " SPA_VERSION_STRING, &vfw |
789 | 1562 |
}; |