]>
Commit | Line | Data |
---|---|---|
ee154f01 BB |
1 | /* |
2 | * CDDL HEADER START | |
3 | * | |
4 | * The contents of this file are subject to the terms of the | |
5 | * Common Development and Distribution License (the "License"). | |
6 | * You may not use this file except in compliance with the License. | |
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 | /* | |
22 | * Copyright (c) 2011, Lawrence Livermore National Security, LLC. | |
5475aada | 23 | * Copyright (c) 2015 by Chunwei Chen. All rights reserved. |
ee154f01 BB |
24 | */ |
25 | ||
26 | ||
278bee93 | 27 | #include <sys/zfs_ctldir.h> |
ee154f01 BB |
28 | #include <sys/zfs_vfsops.h> |
29 | #include <sys/zfs_vnops.h> | |
ebe7e575 | 30 | #include <sys/zfs_znode.h> |
ee154f01 BB |
31 | #include <sys/vfs.h> |
32 | #include <sys/zpl.h> | |
33 | ||
34 | ||
35 | static struct dentry * | |
8f195a90 | 36 | #ifdef HAVE_LOOKUP_NAMEIDATA |
ee154f01 | 37 | zpl_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) |
8f195a90 YS |
38 | #else |
39 | zpl_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) | |
40 | #endif | |
ee154f01 | 41 | { |
81e97e21 | 42 | cred_t *cr = CRED(); |
ee154f01 | 43 | struct inode *ip; |
ee154f01 | 44 | int error; |
40d06e3c | 45 | fstrans_cookie_t cookie; |
ee154f01 | 46 | |
9878a89d | 47 | if (dlen(dentry) > ZFS_MAXNAMELEN) |
d1d7e268 | 48 | return (ERR_PTR(-ENAMETOOLONG)); |
9878a89d | 49 | |
81e97e21 | 50 | crhold(cr); |
40d06e3c | 51 | cookie = spl_fstrans_mark(); |
ee154f01 | 52 | error = -zfs_lookup(dir, dname(dentry), &ip, 0, cr, NULL, NULL); |
40d06e3c | 53 | spl_fstrans_unmark(cookie); |
ee154f01 | 54 | ASSERT3S(error, <=, 0); |
81e97e21 | 55 | crfree(cr); |
ee154f01 | 56 | |
7b3e34ba BB |
57 | spin_lock(&dentry->d_lock); |
58 | dentry->d_time = jiffies; | |
ee930353 BB |
59 | #ifndef HAVE_S_D_OP |
60 | d_set_d_op(dentry, &zpl_dentry_operations); | |
61 | #endif /* HAVE_S_D_OP */ | |
7b3e34ba BB |
62 | spin_unlock(&dentry->d_lock); |
63 | ||
ee154f01 BB |
64 | if (error) { |
65 | if (error == -ENOENT) | |
d1d7e268 | 66 | return (d_splice_alias(NULL, dentry)); |
ee154f01 | 67 | else |
d1d7e268 | 68 | return (ERR_PTR(error)); |
ee154f01 BB |
69 | } |
70 | ||
d1d7e268 | 71 | return (d_splice_alias(ip, dentry)); |
ee154f01 BB |
72 | } |
73 | ||
ebe7e575 | 74 | void |
7b3e34ba | 75 | zpl_vap_init(vattr_t *vap, struct inode *dir, zpl_umode_t mode, cred_t *cr) |
9fd91dae BB |
76 | { |
77 | vap->va_mask = ATTR_MODE; | |
78 | vap->va_mode = mode; | |
9fd91dae BB |
79 | vap->va_uid = crgetfsuid(cr); |
80 | ||
81 | if (dir && dir->i_mode & S_ISGID) { | |
570d6edf | 82 | vap->va_gid = KGID_TO_SGID(dir->i_gid); |
9fd91dae BB |
83 | if (S_ISDIR(mode)) |
84 | vap->va_mode |= S_ISGID; | |
85 | } else { | |
86 | vap->va_gid = crgetfsgid(cr); | |
87 | } | |
88 | } | |
89 | ||
ee154f01 | 90 | static int |
558ef6d0 | 91 | #ifdef HAVE_CREATE_NAMEIDATA |
b39d3b9f | 92 | zpl_create(struct inode *dir, struct dentry *dentry, zpl_umode_t mode, |
ee154f01 | 93 | struct nameidata *nd) |
558ef6d0 YS |
94 | #else |
95 | zpl_create(struct inode *dir, struct dentry *dentry, zpl_umode_t mode, | |
96 | bool flag) | |
97 | #endif | |
ee154f01 | 98 | { |
81e97e21 | 99 | cred_t *cr = CRED(); |
ee154f01 BB |
100 | struct inode *ip; |
101 | vattr_t *vap; | |
102 | int error; | |
40d06e3c | 103 | fstrans_cookie_t cookie; |
ee154f01 | 104 | |
81e97e21 | 105 | crhold(cr); |
d1d7e268 | 106 | vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP); |
7b3e34ba | 107 | zpl_vap_init(vap, dir, mode, cr); |
ee154f01 | 108 | |
40d06e3c | 109 | cookie = spl_fstrans_mark(); |
e89260a1 BB |
110 | error = -zfs_create(dir, dname(dentry), vap, 0, mode, &ip, cr, 0, NULL); |
111 | if (error == 0) { | |
7b3e34ba | 112 | d_instantiate(dentry, ip); |
214806c7 DL |
113 | |
114 | error = zpl_xattr_security_init(ip, dir, &dentry->d_name); | |
115 | if (error == 0) | |
116 | error = zpl_init_acl(ip, dir); | |
117 | ||
118 | if (error) | |
119 | (void) zfs_remove(dir, dname(dentry), cr); | |
e89260a1 BB |
120 | } |
121 | ||
a438ff0e | 122 | spl_fstrans_unmark(cookie); |
d1d7e268 | 123 | kmem_free(vap, sizeof (vattr_t)); |
81e97e21 | 124 | crfree(cr); |
ee154f01 BB |
125 | ASSERT3S(error, <=, 0); |
126 | ||
127 | return (error); | |
128 | } | |
129 | ||
130 | static int | |
b39d3b9f BB |
131 | zpl_mknod(struct inode *dir, struct dentry *dentry, zpl_umode_t mode, |
132 | dev_t rdev) | |
ee154f01 | 133 | { |
81e97e21 | 134 | cred_t *cr = CRED(); |
ee154f01 BB |
135 | struct inode *ip; |
136 | vattr_t *vap; | |
137 | int error; | |
40d06e3c | 138 | fstrans_cookie_t cookie; |
ee154f01 | 139 | |
aa6d8c10 NB |
140 | /* |
141 | * We currently expect Linux to supply rdev=0 for all sockets | |
142 | * and fifos, but we want to know if this behavior ever changes. | |
143 | */ | |
144 | if (S_ISSOCK(mode) || S_ISFIFO(mode)) | |
145 | ASSERT(rdev == 0); | |
146 | ||
81e97e21 | 147 | crhold(cr); |
d1d7e268 | 148 | vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP); |
7b3e34ba | 149 | zpl_vap_init(vap, dir, mode, cr); |
ee154f01 | 150 | vap->va_rdev = rdev; |
ee154f01 | 151 | |
40d06e3c | 152 | cookie = spl_fstrans_mark(); |
7b3e34ba | 153 | error = -zfs_create(dir, dname(dentry), vap, 0, mode, &ip, cr, 0, NULL); |
023699cd | 154 | if (error == 0) { |
7b3e34ba | 155 | d_instantiate(dentry, ip); |
214806c7 DL |
156 | |
157 | error = zpl_xattr_security_init(ip, dir, &dentry->d_name); | |
158 | if (error == 0) | |
159 | error = zpl_init_acl(ip, dir); | |
160 | ||
161 | if (error) | |
162 | (void) zfs_remove(dir, dname(dentry), cr); | |
023699cd | 163 | } |
7b3e34ba | 164 | |
a438ff0e | 165 | spl_fstrans_unmark(cookie); |
d1d7e268 | 166 | kmem_free(vap, sizeof (vattr_t)); |
81e97e21 | 167 | crfree(cr); |
ee154f01 BB |
168 | ASSERT3S(error, <=, 0); |
169 | ||
34d5a5fd | 170 | return (error); |
ee154f01 BB |
171 | } |
172 | ||
173 | static int | |
174 | zpl_unlink(struct inode *dir, struct dentry *dentry) | |
175 | { | |
81e97e21 | 176 | cred_t *cr = CRED(); |
ee154f01 | 177 | int error; |
40d06e3c | 178 | fstrans_cookie_t cookie; |
ee154f01 | 179 | |
81e97e21 | 180 | crhold(cr); |
40d06e3c | 181 | cookie = spl_fstrans_mark(); |
ee154f01 | 182 | error = -zfs_remove(dir, dname(dentry), cr); |
40d06e3c | 183 | spl_fstrans_unmark(cookie); |
81e97e21 | 184 | crfree(cr); |
ee154f01 BB |
185 | ASSERT3S(error, <=, 0); |
186 | ||
187 | return (error); | |
188 | } | |
189 | ||
190 | static int | |
b39d3b9f | 191 | zpl_mkdir(struct inode *dir, struct dentry *dentry, zpl_umode_t mode) |
ee154f01 | 192 | { |
81e97e21 | 193 | cred_t *cr = CRED(); |
ee154f01 BB |
194 | vattr_t *vap; |
195 | struct inode *ip; | |
196 | int error; | |
40d06e3c | 197 | fstrans_cookie_t cookie; |
ee154f01 | 198 | |
81e97e21 | 199 | crhold(cr); |
d1d7e268 | 200 | vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP); |
7b3e34ba | 201 | zpl_vap_init(vap, dir, mode | S_IFDIR, cr); |
ee154f01 | 202 | |
40d06e3c | 203 | cookie = spl_fstrans_mark(); |
ee154f01 | 204 | error = -zfs_mkdir(dir, dname(dentry), vap, &ip, cr, 0, NULL); |
023699cd | 205 | if (error == 0) { |
7b3e34ba | 206 | d_instantiate(dentry, ip); |
214806c7 DL |
207 | |
208 | error = zpl_xattr_security_init(ip, dir, &dentry->d_name); | |
209 | if (error == 0) | |
210 | error = zpl_init_acl(ip, dir); | |
211 | ||
212 | if (error) | |
213 | (void) zfs_rmdir(dir, dname(dentry), NULL, cr, 0); | |
023699cd | 214 | } |
7b3e34ba | 215 | |
a438ff0e | 216 | spl_fstrans_unmark(cookie); |
d1d7e268 | 217 | kmem_free(vap, sizeof (vattr_t)); |
81e97e21 | 218 | crfree(cr); |
ee154f01 BB |
219 | ASSERT3S(error, <=, 0); |
220 | ||
221 | return (error); | |
222 | } | |
223 | ||
224 | static int | |
225 | zpl_rmdir(struct inode * dir, struct dentry *dentry) | |
226 | { | |
81e97e21 | 227 | cred_t *cr = CRED(); |
ee154f01 | 228 | int error; |
40d06e3c | 229 | fstrans_cookie_t cookie; |
ee154f01 | 230 | |
81e97e21 | 231 | crhold(cr); |
40d06e3c | 232 | cookie = spl_fstrans_mark(); |
ee154f01 | 233 | error = -zfs_rmdir(dir, dname(dentry), NULL, cr, 0); |
40d06e3c | 234 | spl_fstrans_unmark(cookie); |
81e97e21 | 235 | crfree(cr); |
ee154f01 BB |
236 | ASSERT3S(error, <=, 0); |
237 | ||
238 | return (error); | |
239 | } | |
240 | ||
241 | static int | |
242 | zpl_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) | |
243 | { | |
ee154f01 | 244 | int error; |
40d06e3c | 245 | fstrans_cookie_t cookie; |
ee154f01 | 246 | |
40d06e3c | 247 | cookie = spl_fstrans_mark(); |
057e8eee | 248 | error = -zfs_getattr_fast(dentry->d_inode, stat); |
40d06e3c | 249 | spl_fstrans_unmark(cookie); |
ee154f01 BB |
250 | ASSERT3S(error, <=, 0); |
251 | ||
252 | return (error); | |
253 | } | |
254 | ||
255 | static int | |
5484965a | 256 | zpl_setattr(struct dentry *dentry, struct iattr *ia) |
ee154f01 | 257 | { |
023699cd | 258 | struct inode *ip = dentry->d_inode; |
81e97e21 | 259 | cred_t *cr = CRED(); |
5484965a | 260 | vattr_t *vap; |
ee154f01 | 261 | int error; |
40d06e3c | 262 | fstrans_cookie_t cookie; |
ee154f01 | 263 | |
023699cd | 264 | error = inode_change_ok(ip, ia); |
ee154f01 BB |
265 | if (error) |
266 | return (error); | |
267 | ||
81e97e21 | 268 | crhold(cr); |
d1d7e268 | 269 | vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP); |
5484965a BB |
270 | vap->va_mask = ia->ia_valid & ATTR_IATTR_MASK; |
271 | vap->va_mode = ia->ia_mode; | |
570d6edf RY |
272 | vap->va_uid = KUID_TO_SUID(ia->ia_uid); |
273 | vap->va_gid = KGID_TO_SGID(ia->ia_gid); | |
5484965a BB |
274 | vap->va_size = ia->ia_size; |
275 | vap->va_atime = ia->ia_atime; | |
276 | vap->va_mtime = ia->ia_mtime; | |
277 | vap->va_ctime = ia->ia_ctime; | |
278 | ||
40d06e3c | 279 | cookie = spl_fstrans_mark(); |
023699cd MM |
280 | error = -zfs_setattr(ip, vap, 0, cr); |
281 | if (!error && (ia->ia_valid & ATTR_MODE)) | |
282 | error = zpl_chmod_acl(ip); | |
5484965a | 283 | |
a438ff0e | 284 | spl_fstrans_unmark(cookie); |
d1d7e268 | 285 | kmem_free(vap, sizeof (vattr_t)); |
81e97e21 | 286 | crfree(cr); |
ee154f01 BB |
287 | ASSERT3S(error, <=, 0); |
288 | ||
5484965a | 289 | return (error); |
ee154f01 BB |
290 | } |
291 | ||
292 | static int | |
293 | zpl_rename(struct inode *sdip, struct dentry *sdentry, | |
294 | struct inode *tdip, struct dentry *tdentry) | |
295 | { | |
81e97e21 | 296 | cred_t *cr = CRED(); |
ee154f01 | 297 | int error; |
40d06e3c | 298 | fstrans_cookie_t cookie; |
ee154f01 | 299 | |
81e97e21 | 300 | crhold(cr); |
40d06e3c | 301 | cookie = spl_fstrans_mark(); |
ee154f01 | 302 | error = -zfs_rename(sdip, dname(sdentry), tdip, dname(tdentry), cr, 0); |
40d06e3c | 303 | spl_fstrans_unmark(cookie); |
81e97e21 | 304 | crfree(cr); |
ee154f01 BB |
305 | ASSERT3S(error, <=, 0); |
306 | ||
307 | return (error); | |
308 | } | |
309 | ||
310 | static int | |
311 | zpl_symlink(struct inode *dir, struct dentry *dentry, const char *name) | |
312 | { | |
81e97e21 | 313 | cred_t *cr = CRED(); |
ee154f01 BB |
314 | vattr_t *vap; |
315 | struct inode *ip; | |
316 | int error; | |
40d06e3c | 317 | fstrans_cookie_t cookie; |
ee154f01 | 318 | |
81e97e21 | 319 | crhold(cr); |
d1d7e268 | 320 | vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP); |
7b3e34ba | 321 | zpl_vap_init(vap, dir, S_IFLNK | S_IRWXUGO, cr); |
ee154f01 | 322 | |
40d06e3c | 323 | cookie = spl_fstrans_mark(); |
ee154f01 | 324 | error = -zfs_symlink(dir, dname(dentry), vap, (char *)name, &ip, cr, 0); |
227bc969 | 325 | if (error == 0) { |
7b3e34ba | 326 | d_instantiate(dentry, ip); |
214806c7 DL |
327 | |
328 | error = zpl_xattr_security_init(ip, dir, &dentry->d_name); | |
329 | if (error) | |
330 | (void) zfs_remove(dir, dname(dentry), cr); | |
227bc969 | 331 | } |
7b3e34ba | 332 | |
a438ff0e | 333 | spl_fstrans_unmark(cookie); |
d1d7e268 | 334 | kmem_free(vap, sizeof (vattr_t)); |
81e97e21 | 335 | crfree(cr); |
ee154f01 BB |
336 | ASSERT3S(error, <=, 0); |
337 | ||
338 | return (error); | |
339 | } | |
340 | ||
bd29109f | 341 | #ifdef HAVE_FOLLOW_LINK_NAMEIDATA |
ee154f01 BB |
342 | static void * |
343 | zpl_follow_link(struct dentry *dentry, struct nameidata *nd) | |
bd29109f BB |
344 | #else |
345 | const char * | |
346 | zpl_follow_link(struct dentry *dentry, void **symlink_cookie) | |
347 | #endif | |
ee154f01 | 348 | { |
81e97e21 | 349 | cred_t *cr = CRED(); |
8b4f9a2d BB |
350 | struct inode *ip = dentry->d_inode; |
351 | struct iovec iov; | |
352 | uio_t uio; | |
353 | char *link; | |
8b4f9a2d | 354 | int error; |
40d06e3c | 355 | fstrans_cookie_t cookie; |
8b4f9a2d | 356 | |
81e97e21 | 357 | crhold(cr); |
8b4f9a2d BB |
358 | |
359 | iov.iov_len = MAXPATHLEN; | |
360 | iov.iov_base = link = kmem_zalloc(MAXPATHLEN, KM_SLEEP); | |
361 | ||
362 | uio.uio_iov = &iov; | |
363 | uio.uio_iovcnt = 1; | |
5475aada | 364 | uio.uio_skip = 0; |
8b4f9a2d BB |
365 | uio.uio_resid = (MAXPATHLEN - 1); |
366 | uio.uio_segflg = UIO_SYSSPACE; | |
367 | ||
40d06e3c | 368 | cookie = spl_fstrans_mark(); |
50950001 | 369 | error = -zfs_readlink(ip, &uio, cr); |
40d06e3c | 370 | spl_fstrans_unmark(cookie); |
bd29109f BB |
371 | |
372 | if (error) | |
8b4f9a2d | 373 | kmem_free(link, MAXPATHLEN); |
bd29109f BB |
374 | |
375 | crfree(cr); | |
376 | ||
377 | #ifdef HAVE_FOLLOW_LINK_NAMEIDATA | |
378 | if (error) | |
8b4f9a2d | 379 | nd_set_link(nd, ERR_PTR(error)); |
bd29109f | 380 | else |
8b4f9a2d | 381 | nd_set_link(nd, link); |
8b4f9a2d | 382 | |
8b4f9a2d | 383 | return (NULL); |
bd29109f BB |
384 | #else |
385 | if (error) | |
386 | return (ERR_PTR(error)); | |
387 | else | |
388 | return (*symlink_cookie = link); | |
389 | #endif | |
ee154f01 BB |
390 | } |
391 | ||
bd29109f | 392 | #ifdef HAVE_PUT_LINK_NAMEIDATA |
ee154f01 BB |
393 | static void |
394 | zpl_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr) | |
395 | { | |
0a6b03d3 | 396 | const char *link = nd_get_link(nd); |
ee154f01 | 397 | |
ee154f01 | 398 | if (!IS_ERR(link)) |
8b4f9a2d | 399 | kmem_free(link, MAXPATHLEN); |
ee154f01 | 400 | } |
bd29109f BB |
401 | #else |
402 | static void | |
403 | zpl_put_link(struct inode *unused, void *symlink_cookie) | |
404 | { | |
405 | kmem_free(symlink_cookie, MAXPATHLEN); | |
406 | } | |
407 | #endif | |
ee154f01 BB |
408 | |
409 | static int | |
410 | zpl_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry) | |
411 | { | |
81e97e21 | 412 | cred_t *cr = CRED(); |
ee154f01 | 413 | struct inode *ip = old_dentry->d_inode; |
ee154f01 | 414 | int error; |
40d06e3c | 415 | fstrans_cookie_t cookie; |
ee154f01 BB |
416 | |
417 | if (ip->i_nlink >= ZFS_LINK_MAX) | |
d1d7e268 | 418 | return (-EMLINK); |
ee154f01 | 419 | |
81e97e21 | 420 | crhold(cr); |
ee154f01 BB |
421 | ip->i_ctime = CURRENT_TIME_SEC; |
422 | igrab(ip); /* Use ihold() if available */ | |
423 | ||
40d06e3c | 424 | cookie = spl_fstrans_mark(); |
ee154f01 BB |
425 | error = -zfs_link(dir, ip, dname(dentry), cr); |
426 | if (error) { | |
427 | iput(ip); | |
428 | goto out; | |
429 | } | |
430 | ||
431 | d_instantiate(dentry, ip); | |
432 | out: | |
a438ff0e | 433 | spl_fstrans_unmark(cookie); |
81e97e21 | 434 | crfree(cr); |
ee154f01 BB |
435 | ASSERT3S(error, <=, 0); |
436 | ||
437 | return (error); | |
438 | } | |
439 | ||
ea1fdf46 | 440 | #ifdef HAVE_INODE_TRUNCATE_RANGE |
5cb63a57 | 441 | static void |
d1d7e268 | 442 | zpl_truncate_range(struct inode *ip, loff_t start, loff_t end) |
5cb63a57 ED |
443 | { |
444 | cred_t *cr = CRED(); | |
445 | flock64_t bf; | |
40d06e3c | 446 | fstrans_cookie_t cookie; |
5cb63a57 ED |
447 | |
448 | ASSERT3S(start, <=, end); | |
449 | ||
450 | /* | |
451 | * zfs_freesp() will interpret (len == 0) as meaning "truncate until | |
452 | * the end of the file". We don't want that. | |
453 | */ | |
454 | if (start == end) | |
455 | return; | |
456 | ||
457 | crhold(cr); | |
458 | ||
459 | bf.l_type = F_WRLCK; | |
460 | bf.l_whence = 0; | |
461 | bf.l_start = start; | |
462 | bf.l_len = end - start; | |
463 | bf.l_pid = 0; | |
40d06e3c | 464 | cookie = spl_fstrans_mark(); |
5cb63a57 | 465 | zfs_space(ip, F_FREESP, &bf, FWRITE, start, cr); |
40d06e3c | 466 | spl_fstrans_unmark(cookie); |
5cb63a57 ED |
467 | |
468 | crfree(cr); | |
469 | } | |
ea1fdf46 | 470 | #endif /* HAVE_INODE_TRUNCATE_RANGE */ |
5cb63a57 | 471 | |
cb2d1901 ED |
472 | #ifdef HAVE_INODE_FALLOCATE |
473 | static long | |
474 | zpl_fallocate(struct inode *ip, int mode, loff_t offset, loff_t len) | |
475 | { | |
d1d7e268 | 476 | return (zpl_fallocate_common(ip, mode, offset, len)); |
cb2d1901 ED |
477 | } |
478 | #endif /* HAVE_INODE_FALLOCATE */ | |
479 | ||
7b3e34ba BB |
480 | static int |
481 | #ifdef HAVE_D_REVALIDATE_NAMEIDATA | |
482 | zpl_revalidate(struct dentry *dentry, struct nameidata *nd) | |
483 | { | |
09a661e9 | 484 | unsigned int flags = (nd ? nd->flags : 0); |
7b3e34ba BB |
485 | #else |
486 | zpl_revalidate(struct dentry *dentry, unsigned int flags) | |
487 | { | |
488 | #endif /* HAVE_D_REVALIDATE_NAMEIDATA */ | |
489 | zfs_sb_t *zsb = dentry->d_sb->s_fs_info; | |
490 | int error; | |
491 | ||
492 | if (flags & LOOKUP_RCU) | |
493 | return (-ECHILD); | |
494 | ||
278bee93 BB |
495 | /* |
496 | * Automounted snapshots rely on periodic dentry revalidation | |
497 | * to defer snapshots from being automatically unmounted. | |
498 | */ | |
499 | if (zsb->z_issnap) { | |
500 | if (time_after(jiffies, zsb->z_snap_defer_time + | |
501 | MAX(zfs_expire_snapshot * HZ / 2, HZ))) { | |
502 | zsb->z_snap_defer_time = jiffies; | |
503 | zfsctl_snapshot_unmount_delay( | |
504 | dmu_objset_id(zsb->z_os), zfs_expire_snapshot); | |
505 | } | |
506 | } | |
507 | ||
7b3e34ba BB |
508 | /* |
509 | * After a rollback negative dentries created before the rollback | |
510 | * time must be invalidated. Otherwise they can obscure files which | |
511 | * are only present in the rolled back dataset. | |
512 | */ | |
513 | if (dentry->d_inode == NULL) { | |
514 | spin_lock(&dentry->d_lock); | |
515 | error = time_before(dentry->d_time, zsb->z_rollback_time); | |
516 | spin_unlock(&dentry->d_lock); | |
517 | ||
518 | if (error) | |
519 | return (0); | |
520 | } | |
521 | ||
522 | /* | |
523 | * The dentry may reference a stale inode if a mounted file system | |
524 | * was rolled back to a point in time where the object didn't exist. | |
525 | */ | |
526 | if (dentry->d_inode && ITOZ(dentry->d_inode)->z_is_stale) | |
527 | return (0); | |
528 | ||
529 | return (1); | |
530 | } | |
cb2d1901 | 531 | |
ee154f01 | 532 | const struct inode_operations zpl_inode_operations = { |
ee154f01 BB |
533 | .create = zpl_create, |
534 | .link = zpl_link, | |
535 | .unlink = zpl_unlink, | |
536 | .symlink = zpl_symlink, | |
537 | .mkdir = zpl_mkdir, | |
538 | .rmdir = zpl_rmdir, | |
539 | .mknod = zpl_mknod, | |
540 | .rename = zpl_rename, | |
541 | .setattr = zpl_setattr, | |
542 | .getattr = zpl_getattr, | |
543 | .setxattr = generic_setxattr, | |
544 | .getxattr = generic_getxattr, | |
545 | .removexattr = generic_removexattr, | |
546 | .listxattr = zpl_xattr_list, | |
ea1fdf46 | 547 | #ifdef HAVE_INODE_TRUNCATE_RANGE |
5cb63a57 | 548 | .truncate_range = zpl_truncate_range, |
ea1fdf46 | 549 | #endif /* HAVE_INODE_TRUNCATE_RANGE */ |
cb2d1901 ED |
550 | #ifdef HAVE_INODE_FALLOCATE |
551 | .fallocate = zpl_fallocate, | |
552 | #endif /* HAVE_INODE_FALLOCATE */ | |
b695c34e | 553 | #if defined(CONFIG_FS_POSIX_ACL) |
023699cd MM |
554 | #if defined(HAVE_GET_ACL) |
555 | .get_acl = zpl_get_acl, | |
556 | #elif defined(HAVE_CHECK_ACL) | |
557 | .check_acl = zpl_check_acl, | |
558 | #elif defined(HAVE_PERMISSION) | |
559 | .permission = zpl_permission, | |
560 | #endif /* HAVE_GET_ACL | HAVE_CHECK_ACL | HAVE_PERMISSION */ | |
b695c34e | 561 | #endif /* CONFIG_FS_POSIX_ACL */ |
ee154f01 BB |
562 | }; |
563 | ||
564 | const struct inode_operations zpl_dir_inode_operations = { | |
ee154f01 BB |
565 | .create = zpl_create, |
566 | .lookup = zpl_lookup, | |
567 | .link = zpl_link, | |
568 | .unlink = zpl_unlink, | |
569 | .symlink = zpl_symlink, | |
570 | .mkdir = zpl_mkdir, | |
571 | .rmdir = zpl_rmdir, | |
572 | .mknod = zpl_mknod, | |
573 | .rename = zpl_rename, | |
574 | .setattr = zpl_setattr, | |
a6695d83 BB |
575 | .getattr = zpl_getattr, |
576 | .setxattr = generic_setxattr, | |
577 | .getxattr = generic_getxattr, | |
578 | .removexattr = generic_removexattr, | |
579 | .listxattr = zpl_xattr_list, | |
b695c34e | 580 | #if defined(CONFIG_FS_POSIX_ACL) |
023699cd MM |
581 | #if defined(HAVE_GET_ACL) |
582 | .get_acl = zpl_get_acl, | |
583 | #elif defined(HAVE_CHECK_ACL) | |
584 | .check_acl = zpl_check_acl, | |
585 | #elif defined(HAVE_PERMISSION) | |
586 | .permission = zpl_permission, | |
587 | #endif /* HAVE_GET_ACL | HAVE_CHECK_ACL | HAVE_PERMISSION */ | |
b695c34e | 588 | #endif /* CONFIG_FS_POSIX_ACL */ |
ee154f01 BB |
589 | }; |
590 | ||
591 | const struct inode_operations zpl_symlink_inode_operations = { | |
ee154f01 BB |
592 | .readlink = generic_readlink, |
593 | .follow_link = zpl_follow_link, | |
594 | .put_link = zpl_put_link, | |
6f2255ba BB |
595 | .setattr = zpl_setattr, |
596 | .getattr = zpl_getattr, | |
f31b3ebe BB |
597 | .setxattr = generic_setxattr, |
598 | .getxattr = generic_getxattr, | |
599 | .removexattr = generic_removexattr, | |
600 | .listxattr = zpl_xattr_list, | |
ee154f01 BB |
601 | }; |
602 | ||
603 | const struct inode_operations zpl_special_inode_operations = { | |
a6695d83 BB |
604 | .setattr = zpl_setattr, |
605 | .getattr = zpl_getattr, | |
606 | .setxattr = generic_setxattr, | |
607 | .getxattr = generic_getxattr, | |
608 | .removexattr = generic_removexattr, | |
609 | .listxattr = zpl_xattr_list, | |
b695c34e | 610 | #if defined(CONFIG_FS_POSIX_ACL) |
023699cd MM |
611 | #if defined(HAVE_GET_ACL) |
612 | .get_acl = zpl_get_acl, | |
613 | #elif defined(HAVE_CHECK_ACL) | |
614 | .check_acl = zpl_check_acl, | |
615 | #elif defined(HAVE_PERMISSION) | |
616 | .permission = zpl_permission, | |
617 | #endif /* HAVE_GET_ACL | HAVE_CHECK_ACL | HAVE_PERMISSION */ | |
b695c34e | 618 | #endif /* CONFIG_FS_POSIX_ACL */ |
ee154f01 | 619 | }; |
7b3e34ba BB |
620 | |
621 | dentry_operations_t zpl_dentry_operations = { | |
622 | .d_revalidate = zpl_revalidate, | |
623 | }; |