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