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