xref: /freebsd/sys/contrib/openzfs/module/os/linux/zfs/zpl_inode.c (revision dd41de95a84d979615a2ef11df6850622bf6184e)
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.
23  * Copyright (c) 2015 by Chunwei Chen. All rights reserved.
24  */
25 
26 
27 #include <sys/zfs_ctldir.h>
28 #include <sys/zfs_vfsops.h>
29 #include <sys/zfs_vnops.h>
30 #include <sys/zfs_znode.h>
31 #include <sys/dmu_objset.h>
32 #include <sys/vfs.h>
33 #include <sys/zpl.h>
34 #include <sys/file.h>
35 
36 
37 static struct dentry *
38 zpl_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
39 {
40 	cred_t *cr = CRED();
41 	struct inode *ip;
42 	znode_t *zp;
43 	int error;
44 	fstrans_cookie_t cookie;
45 	pathname_t *ppn = NULL;
46 	pathname_t pn;
47 	int zfs_flags = 0;
48 	zfsvfs_t *zfsvfs = dentry->d_sb->s_fs_info;
49 
50 	if (dlen(dentry) >= ZAP_MAXNAMELEN)
51 		return (ERR_PTR(-ENAMETOOLONG));
52 
53 	crhold(cr);
54 	cookie = spl_fstrans_mark();
55 
56 	/* If we are a case insensitive fs, we need the real name */
57 	if (zfsvfs->z_case == ZFS_CASE_INSENSITIVE) {
58 		zfs_flags = FIGNORECASE;
59 		pn_alloc(&pn);
60 		ppn = &pn;
61 	}
62 
63 	error = -zfs_lookup(ITOZ(dir), dname(dentry), &zp,
64 	    zfs_flags, cr, NULL, ppn);
65 	spl_fstrans_unmark(cookie);
66 	ASSERT3S(error, <=, 0);
67 	crfree(cr);
68 
69 	spin_lock(&dentry->d_lock);
70 	dentry->d_time = jiffies;
71 	spin_unlock(&dentry->d_lock);
72 
73 	if (error) {
74 		/*
75 		 * If we have a case sensitive fs, we do not want to
76 		 * insert negative entries, so return NULL for ENOENT.
77 		 * Fall through if the error is not ENOENT. Also free memory.
78 		 */
79 		if (ppn) {
80 			pn_free(ppn);
81 			if (error == -ENOENT)
82 				return (NULL);
83 		}
84 
85 		if (error == -ENOENT)
86 			return (d_splice_alias(NULL, dentry));
87 		else
88 			return (ERR_PTR(error));
89 	}
90 	ip = ZTOI(zp);
91 
92 	/*
93 	 * If we are case insensitive, call the correct function
94 	 * to install the name.
95 	 */
96 	if (ppn) {
97 		struct dentry *new_dentry;
98 		struct qstr ci_name;
99 
100 		if (strcmp(dname(dentry), pn.pn_buf) == 0) {
101 			new_dentry = d_splice_alias(ip,  dentry);
102 		} else {
103 			ci_name.name = pn.pn_buf;
104 			ci_name.len = strlen(pn.pn_buf);
105 			new_dentry = d_add_ci(dentry, ip, &ci_name);
106 		}
107 		pn_free(ppn);
108 		return (new_dentry);
109 	} else {
110 		return (d_splice_alias(ip, dentry));
111 	}
112 }
113 
114 void
115 zpl_vap_init(vattr_t *vap, struct inode *dir, umode_t mode, cred_t *cr)
116 {
117 	vap->va_mask = ATTR_MODE;
118 	vap->va_mode = mode;
119 	vap->va_uid = crgetfsuid(cr);
120 
121 	if (dir && dir->i_mode & S_ISGID) {
122 		vap->va_gid = KGID_TO_SGID(dir->i_gid);
123 		if (S_ISDIR(mode))
124 			vap->va_mode |= S_ISGID;
125 	} else {
126 		vap->va_gid = crgetfsgid(cr);
127 	}
128 }
129 
130 static int
131 #ifdef HAVE_IOPS_CREATE_USERNS
132 zpl_create(struct user_namespace *user_ns, struct inode *dir,
133     struct dentry *dentry, umode_t mode, bool flag)
134 #else
135 zpl_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool flag)
136 #endif
137 {
138 	cred_t *cr = CRED();
139 	znode_t *zp;
140 	vattr_t *vap;
141 	int error;
142 	fstrans_cookie_t cookie;
143 
144 	crhold(cr);
145 	vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP);
146 	zpl_vap_init(vap, dir, mode, cr);
147 
148 	cookie = spl_fstrans_mark();
149 	error = -zfs_create(ITOZ(dir), dname(dentry), vap, 0,
150 	    mode, &zp, cr, 0, NULL);
151 	if (error == 0) {
152 		d_instantiate(dentry, ZTOI(zp));
153 
154 		error = zpl_xattr_security_init(ZTOI(zp), dir, &dentry->d_name);
155 		if (error == 0)
156 			error = zpl_init_acl(ZTOI(zp), dir);
157 
158 		if (error)
159 			(void) zfs_remove(ITOZ(dir), dname(dentry), cr, 0);
160 	}
161 
162 	spl_fstrans_unmark(cookie);
163 	kmem_free(vap, sizeof (vattr_t));
164 	crfree(cr);
165 	ASSERT3S(error, <=, 0);
166 
167 	return (error);
168 }
169 
170 static int
171 #ifdef HAVE_IOPS_MKNOD_USERNS
172 zpl_mknod(struct user_namespace *user_ns, struct inode *dir,
173     struct dentry *dentry, umode_t mode,
174 #else
175 zpl_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
176 #endif
177     dev_t rdev)
178 {
179 	cred_t *cr = CRED();
180 	znode_t *zp;
181 	vattr_t *vap;
182 	int error;
183 	fstrans_cookie_t cookie;
184 
185 	/*
186 	 * We currently expect Linux to supply rdev=0 for all sockets
187 	 * and fifos, but we want to know if this behavior ever changes.
188 	 */
189 	if (S_ISSOCK(mode) || S_ISFIFO(mode))
190 		ASSERT(rdev == 0);
191 
192 	crhold(cr);
193 	vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP);
194 	zpl_vap_init(vap, dir, mode, cr);
195 	vap->va_rdev = rdev;
196 
197 	cookie = spl_fstrans_mark();
198 	error = -zfs_create(ITOZ(dir), dname(dentry), vap, 0,
199 	    mode, &zp, cr, 0, NULL);
200 	if (error == 0) {
201 		d_instantiate(dentry, ZTOI(zp));
202 
203 		error = zpl_xattr_security_init(ZTOI(zp), dir, &dentry->d_name);
204 		if (error == 0)
205 			error = zpl_init_acl(ZTOI(zp), dir);
206 
207 		if (error)
208 			(void) zfs_remove(ITOZ(dir), dname(dentry), cr, 0);
209 	}
210 
211 	spl_fstrans_unmark(cookie);
212 	kmem_free(vap, sizeof (vattr_t));
213 	crfree(cr);
214 	ASSERT3S(error, <=, 0);
215 
216 	return (error);
217 }
218 
219 #ifdef HAVE_TMPFILE
220 static int
221 zpl_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
222 {
223 	cred_t *cr = CRED();
224 	struct inode *ip;
225 	vattr_t *vap;
226 	int error;
227 	fstrans_cookie_t cookie;
228 
229 	crhold(cr);
230 	vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP);
231 	/*
232 	 * The VFS does not apply the umask, therefore it is applied here
233 	 * when POSIX ACLs are not enabled.
234 	 */
235 	if (!IS_POSIXACL(dir))
236 		mode &= ~current_umask();
237 	zpl_vap_init(vap, dir, mode, cr);
238 
239 	cookie = spl_fstrans_mark();
240 	error = -zfs_tmpfile(dir, vap, 0, mode, &ip, cr, 0, NULL);
241 	if (error == 0) {
242 		/* d_tmpfile will do drop_nlink, so we should set it first */
243 		set_nlink(ip, 1);
244 		d_tmpfile(dentry, ip);
245 
246 		error = zpl_xattr_security_init(ip, dir, &dentry->d_name);
247 		if (error == 0)
248 			error = zpl_init_acl(ip, dir);
249 		/*
250 		 * don't need to handle error here, file is already in
251 		 * unlinked set.
252 		 */
253 	}
254 
255 	spl_fstrans_unmark(cookie);
256 	kmem_free(vap, sizeof (vattr_t));
257 	crfree(cr);
258 	ASSERT3S(error, <=, 0);
259 
260 	return (error);
261 }
262 #endif
263 
264 static int
265 zpl_unlink(struct inode *dir, struct dentry *dentry)
266 {
267 	cred_t *cr = CRED();
268 	int error;
269 	fstrans_cookie_t cookie;
270 	zfsvfs_t *zfsvfs = dentry->d_sb->s_fs_info;
271 
272 	crhold(cr);
273 	cookie = spl_fstrans_mark();
274 	error = -zfs_remove(ITOZ(dir), dname(dentry), cr, 0);
275 
276 	/*
277 	 * For a CI FS we must invalidate the dentry to prevent the
278 	 * creation of negative entries.
279 	 */
280 	if (error == 0 && zfsvfs->z_case == ZFS_CASE_INSENSITIVE)
281 		d_invalidate(dentry);
282 
283 	spl_fstrans_unmark(cookie);
284 	crfree(cr);
285 	ASSERT3S(error, <=, 0);
286 
287 	return (error);
288 }
289 
290 static int
291 #ifdef HAVE_IOPS_MKDIR_USERNS
292 zpl_mkdir(struct user_namespace *user_ns, struct inode *dir,
293     struct dentry *dentry, umode_t mode)
294 #else
295 zpl_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
296 #endif
297 {
298 	cred_t *cr = CRED();
299 	vattr_t *vap;
300 	znode_t *zp;
301 	int error;
302 	fstrans_cookie_t cookie;
303 
304 	crhold(cr);
305 	vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP);
306 	zpl_vap_init(vap, dir, mode | S_IFDIR, cr);
307 
308 	cookie = spl_fstrans_mark();
309 	error = -zfs_mkdir(ITOZ(dir), dname(dentry), vap, &zp, cr, 0, NULL);
310 	if (error == 0) {
311 		d_instantiate(dentry, ZTOI(zp));
312 
313 		error = zpl_xattr_security_init(ZTOI(zp), dir, &dentry->d_name);
314 		if (error == 0)
315 			error = zpl_init_acl(ZTOI(zp), dir);
316 
317 		if (error)
318 			(void) zfs_rmdir(ITOZ(dir), dname(dentry), NULL, cr, 0);
319 	}
320 
321 	spl_fstrans_unmark(cookie);
322 	kmem_free(vap, sizeof (vattr_t));
323 	crfree(cr);
324 	ASSERT3S(error, <=, 0);
325 
326 	return (error);
327 }
328 
329 static int
330 zpl_rmdir(struct inode *dir, struct dentry *dentry)
331 {
332 	cred_t *cr = CRED();
333 	int error;
334 	fstrans_cookie_t cookie;
335 	zfsvfs_t *zfsvfs = dentry->d_sb->s_fs_info;
336 
337 	crhold(cr);
338 	cookie = spl_fstrans_mark();
339 	error = -zfs_rmdir(ITOZ(dir), dname(dentry), NULL, cr, 0);
340 
341 	/*
342 	 * For a CI FS we must invalidate the dentry to prevent the
343 	 * creation of negative entries.
344 	 */
345 	if (error == 0 && zfsvfs->z_case == ZFS_CASE_INSENSITIVE)
346 		d_invalidate(dentry);
347 
348 	spl_fstrans_unmark(cookie);
349 	crfree(cr);
350 	ASSERT3S(error, <=, 0);
351 
352 	return (error);
353 }
354 
355 static int
356 #ifdef HAVE_USERNS_IOPS_GETATTR
357 zpl_getattr_impl(struct user_namespace *user_ns,
358     const struct path *path, struct kstat *stat, u32 request_mask,
359     unsigned int query_flags)
360 #else
361 zpl_getattr_impl(const struct path *path, struct kstat *stat, u32 request_mask,
362     unsigned int query_flags)
363 #endif
364 {
365 	int error;
366 	fstrans_cookie_t cookie;
367 
368 	cookie = spl_fstrans_mark();
369 
370 	/*
371 	 * XXX request_mask and query_flags currently ignored.
372 	 */
373 
374 #ifdef HAVE_USERNS_IOPS_GETATTR
375 	error = -zfs_getattr_fast(user_ns, path->dentry->d_inode, stat);
376 #else
377 	error = -zfs_getattr_fast(kcred->user_ns, path->dentry->d_inode, stat);
378 #endif
379 	spl_fstrans_unmark(cookie);
380 	ASSERT3S(error, <=, 0);
381 
382 	return (error);
383 }
384 ZPL_GETATTR_WRAPPER(zpl_getattr);
385 
386 static int
387 #ifdef HAVE_SETATTR_PREPARE_USERNS
388 zpl_setattr(struct user_namespace *user_ns, struct dentry *dentry,
389     struct iattr *ia)
390 #else
391 zpl_setattr(struct dentry *dentry, struct iattr *ia)
392 #endif
393 {
394 	struct inode *ip = dentry->d_inode;
395 	cred_t *cr = CRED();
396 	vattr_t *vap;
397 	int error;
398 	fstrans_cookie_t cookie;
399 
400 	error = zpl_setattr_prepare(kcred->user_ns, dentry, ia);
401 	if (error)
402 		return (error);
403 
404 	crhold(cr);
405 	vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP);
406 	vap->va_mask = ia->ia_valid & ATTR_IATTR_MASK;
407 	vap->va_mode = ia->ia_mode;
408 	vap->va_uid = KUID_TO_SUID(ia->ia_uid);
409 	vap->va_gid = KGID_TO_SGID(ia->ia_gid);
410 	vap->va_size = ia->ia_size;
411 	vap->va_atime = ia->ia_atime;
412 	vap->va_mtime = ia->ia_mtime;
413 	vap->va_ctime = ia->ia_ctime;
414 
415 	if (vap->va_mask & ATTR_ATIME)
416 		ip->i_atime = zpl_inode_timestamp_truncate(ia->ia_atime, ip);
417 
418 	cookie = spl_fstrans_mark();
419 	error = -zfs_setattr(ITOZ(ip), vap, 0, cr);
420 	if (!error && (ia->ia_valid & ATTR_MODE))
421 		error = zpl_chmod_acl(ip);
422 
423 	spl_fstrans_unmark(cookie);
424 	kmem_free(vap, sizeof (vattr_t));
425 	crfree(cr);
426 	ASSERT3S(error, <=, 0);
427 
428 	return (error);
429 }
430 
431 static int
432 #ifdef HAVE_IOPS_RENAME_USERNS
433 zpl_rename2(struct user_namespace *user_ns, struct inode *sdip,
434     struct dentry *sdentry, struct inode *tdip, struct dentry *tdentry,
435     unsigned int flags)
436 #else
437 zpl_rename2(struct inode *sdip, struct dentry *sdentry,
438     struct inode *tdip, struct dentry *tdentry, unsigned int flags)
439 #endif
440 {
441 	cred_t *cr = CRED();
442 	int error;
443 	fstrans_cookie_t cookie;
444 
445 	/* We don't have renameat2(2) support */
446 	if (flags)
447 		return (-EINVAL);
448 
449 	crhold(cr);
450 	cookie = spl_fstrans_mark();
451 	error = -zfs_rename(ITOZ(sdip), dname(sdentry), ITOZ(tdip),
452 	    dname(tdentry), cr, 0);
453 	spl_fstrans_unmark(cookie);
454 	crfree(cr);
455 	ASSERT3S(error, <=, 0);
456 
457 	return (error);
458 }
459 
460 #if !defined(HAVE_RENAME_WANTS_FLAGS) && !defined(HAVE_IOPS_RENAME_USERNS)
461 static int
462 zpl_rename(struct inode *sdip, struct dentry *sdentry,
463     struct inode *tdip, struct dentry *tdentry)
464 {
465 	return (zpl_rename2(sdip, sdentry, tdip, tdentry, 0));
466 }
467 #endif
468 
469 static int
470 #ifdef HAVE_IOPS_SYMLINK_USERNS
471 zpl_symlink(struct user_namespace *user_ns, struct inode *dir,
472     struct dentry *dentry, const char *name)
473 #else
474 zpl_symlink(struct inode *dir, struct dentry *dentry, const char *name)
475 #endif
476 {
477 	cred_t *cr = CRED();
478 	vattr_t *vap;
479 	znode_t *zp;
480 	int error;
481 	fstrans_cookie_t cookie;
482 
483 	crhold(cr);
484 	vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP);
485 	zpl_vap_init(vap, dir, S_IFLNK | S_IRWXUGO, cr);
486 
487 	cookie = spl_fstrans_mark();
488 	error = -zfs_symlink(ITOZ(dir), dname(dentry), vap,
489 	    (char *)name, &zp, cr, 0);
490 	if (error == 0) {
491 		d_instantiate(dentry, ZTOI(zp));
492 
493 		error = zpl_xattr_security_init(ZTOI(zp), dir, &dentry->d_name);
494 		if (error)
495 			(void) zfs_remove(ITOZ(dir), dname(dentry), cr, 0);
496 	}
497 
498 	spl_fstrans_unmark(cookie);
499 	kmem_free(vap, sizeof (vattr_t));
500 	crfree(cr);
501 	ASSERT3S(error, <=, 0);
502 
503 	return (error);
504 }
505 
506 #if defined(HAVE_PUT_LINK_COOKIE)
507 static void
508 zpl_put_link(struct inode *unused, void *cookie)
509 {
510 	kmem_free(cookie, MAXPATHLEN);
511 }
512 #elif defined(HAVE_PUT_LINK_NAMEIDATA)
513 static void
514 zpl_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
515 {
516 	const char *link = nd_get_link(nd);
517 
518 	if (!IS_ERR(link))
519 		kmem_free(link, MAXPATHLEN);
520 }
521 #elif defined(HAVE_PUT_LINK_DELAYED)
522 static void
523 zpl_put_link(void *ptr)
524 {
525 	kmem_free(ptr, MAXPATHLEN);
526 }
527 #endif
528 
529 static int
530 zpl_get_link_common(struct dentry *dentry, struct inode *ip, char **link)
531 {
532 	fstrans_cookie_t cookie;
533 	cred_t *cr = CRED();
534 	int error;
535 
536 	crhold(cr);
537 	*link = NULL;
538 
539 	struct iovec iov;
540 	iov.iov_len = MAXPATHLEN;
541 	iov.iov_base = kmem_zalloc(MAXPATHLEN, KM_SLEEP);
542 
543 	zfs_uio_t uio;
544 	zfs_uio_iovec_init(&uio, &iov, 1, 0, UIO_SYSSPACE, MAXPATHLEN - 1, 0);
545 
546 	cookie = spl_fstrans_mark();
547 	error = -zfs_readlink(ip, &uio, cr);
548 	spl_fstrans_unmark(cookie);
549 	crfree(cr);
550 
551 	if (error)
552 		kmem_free(iov.iov_base, MAXPATHLEN);
553 	else
554 		*link = iov.iov_base;
555 
556 	return (error);
557 }
558 
559 #if defined(HAVE_GET_LINK_DELAYED)
560 static const char *
561 zpl_get_link(struct dentry *dentry, struct inode *inode,
562     struct delayed_call *done)
563 {
564 	char *link = NULL;
565 	int error;
566 
567 	if (!dentry)
568 		return (ERR_PTR(-ECHILD));
569 
570 	error = zpl_get_link_common(dentry, inode, &link);
571 	if (error)
572 		return (ERR_PTR(error));
573 
574 	set_delayed_call(done, zpl_put_link, link);
575 
576 	return (link);
577 }
578 #elif defined(HAVE_GET_LINK_COOKIE)
579 static const char *
580 zpl_get_link(struct dentry *dentry, struct inode *inode, void **cookie)
581 {
582 	char *link = NULL;
583 	int error;
584 
585 	if (!dentry)
586 		return (ERR_PTR(-ECHILD));
587 
588 	error = zpl_get_link_common(dentry, inode, &link);
589 	if (error)
590 		return (ERR_PTR(error));
591 
592 	return (*cookie = link);
593 }
594 #elif defined(HAVE_FOLLOW_LINK_COOKIE)
595 static const char *
596 zpl_follow_link(struct dentry *dentry, void **cookie)
597 {
598 	char *link = NULL;
599 	int error;
600 
601 	error = zpl_get_link_common(dentry, dentry->d_inode, &link);
602 	if (error)
603 		return (ERR_PTR(error));
604 
605 	return (*cookie = link);
606 }
607 #elif defined(HAVE_FOLLOW_LINK_NAMEIDATA)
608 static void *
609 zpl_follow_link(struct dentry *dentry, struct nameidata *nd)
610 {
611 	char *link = NULL;
612 	int error;
613 
614 	error = zpl_get_link_common(dentry, dentry->d_inode, &link);
615 	if (error)
616 		nd_set_link(nd, ERR_PTR(error));
617 	else
618 		nd_set_link(nd, link);
619 
620 	return (NULL);
621 }
622 #endif
623 
624 static int
625 zpl_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
626 {
627 	cred_t *cr = CRED();
628 	struct inode *ip = old_dentry->d_inode;
629 	int error;
630 	fstrans_cookie_t cookie;
631 
632 	if (ip->i_nlink >= ZFS_LINK_MAX)
633 		return (-EMLINK);
634 
635 	crhold(cr);
636 	ip->i_ctime = current_time(ip);
637 	/* Must have an existing ref, so igrab() cannot return NULL */
638 	VERIFY3P(igrab(ip), !=, NULL);
639 
640 	cookie = spl_fstrans_mark();
641 	error = -zfs_link(ITOZ(dir), ITOZ(ip), dname(dentry), cr, 0);
642 	if (error) {
643 		iput(ip);
644 		goto out;
645 	}
646 
647 	d_instantiate(dentry, ip);
648 out:
649 	spl_fstrans_unmark(cookie);
650 	crfree(cr);
651 	ASSERT3S(error, <=, 0);
652 
653 	return (error);
654 }
655 
656 static int
657 #ifdef HAVE_D_REVALIDATE_NAMEIDATA
658 zpl_revalidate(struct dentry *dentry, struct nameidata *nd)
659 {
660 	unsigned int flags = (nd ? nd->flags : 0);
661 #else
662 zpl_revalidate(struct dentry *dentry, unsigned int flags)
663 {
664 #endif /* HAVE_D_REVALIDATE_NAMEIDATA */
665 	/* CSTYLED */
666 	zfsvfs_t *zfsvfs = dentry->d_sb->s_fs_info;
667 	int error;
668 
669 	if (flags & LOOKUP_RCU)
670 		return (-ECHILD);
671 
672 	/*
673 	 * After a rollback negative dentries created before the rollback
674 	 * time must be invalidated.  Otherwise they can obscure files which
675 	 * are only present in the rolled back dataset.
676 	 */
677 	if (dentry->d_inode == NULL) {
678 		spin_lock(&dentry->d_lock);
679 		error = time_before(dentry->d_time, zfsvfs->z_rollback_time);
680 		spin_unlock(&dentry->d_lock);
681 
682 		if (error)
683 			return (0);
684 	}
685 
686 	/*
687 	 * The dentry may reference a stale inode if a mounted file system
688 	 * was rolled back to a point in time where the object didn't exist.
689 	 */
690 	if (dentry->d_inode && ITOZ(dentry->d_inode)->z_is_stale)
691 		return (0);
692 
693 	return (1);
694 }
695 
696 const struct inode_operations zpl_inode_operations = {
697 	.setattr	= zpl_setattr,
698 	.getattr	= zpl_getattr,
699 #ifdef HAVE_GENERIC_SETXATTR
700 	.setxattr	= generic_setxattr,
701 	.getxattr	= generic_getxattr,
702 	.removexattr	= generic_removexattr,
703 #endif
704 	.listxattr	= zpl_xattr_list,
705 #if defined(CONFIG_FS_POSIX_ACL)
706 #if defined(HAVE_SET_ACL)
707 	.set_acl	= zpl_set_acl,
708 #endif /* HAVE_SET_ACL */
709 	.get_acl	= zpl_get_acl,
710 #endif /* CONFIG_FS_POSIX_ACL */
711 };
712 
713 const struct inode_operations zpl_dir_inode_operations = {
714 	.create		= zpl_create,
715 	.lookup		= zpl_lookup,
716 	.link		= zpl_link,
717 	.unlink		= zpl_unlink,
718 	.symlink	= zpl_symlink,
719 	.mkdir		= zpl_mkdir,
720 	.rmdir		= zpl_rmdir,
721 	.mknod		= zpl_mknod,
722 #if defined(HAVE_RENAME_WANTS_FLAGS) || defined(HAVE_IOPS_RENAME_USERNS)
723 	.rename		= zpl_rename2,
724 #else
725 	.rename		= zpl_rename,
726 #endif
727 #ifdef HAVE_TMPFILE
728 	.tmpfile	= zpl_tmpfile,
729 #endif
730 	.setattr	= zpl_setattr,
731 	.getattr	= zpl_getattr,
732 #ifdef HAVE_GENERIC_SETXATTR
733 	.setxattr	= generic_setxattr,
734 	.getxattr	= generic_getxattr,
735 	.removexattr	= generic_removexattr,
736 #endif
737 	.listxattr	= zpl_xattr_list,
738 #if defined(CONFIG_FS_POSIX_ACL)
739 #if defined(HAVE_SET_ACL)
740 	.set_acl	= zpl_set_acl,
741 #endif /* HAVE_SET_ACL */
742 	.get_acl	= zpl_get_acl,
743 #endif /* CONFIG_FS_POSIX_ACL */
744 };
745 
746 const struct inode_operations zpl_symlink_inode_operations = {
747 #ifdef HAVE_GENERIC_READLINK
748 	.readlink	= generic_readlink,
749 #endif
750 #if defined(HAVE_GET_LINK_DELAYED) || defined(HAVE_GET_LINK_COOKIE)
751 	.get_link	= zpl_get_link,
752 #elif defined(HAVE_FOLLOW_LINK_COOKIE) || defined(HAVE_FOLLOW_LINK_NAMEIDATA)
753 	.follow_link	= zpl_follow_link,
754 #endif
755 #if defined(HAVE_PUT_LINK_COOKIE) || defined(HAVE_PUT_LINK_NAMEIDATA)
756 	.put_link	= zpl_put_link,
757 #endif
758 	.setattr	= zpl_setattr,
759 	.getattr	= zpl_getattr,
760 #ifdef HAVE_GENERIC_SETXATTR
761 	.setxattr	= generic_setxattr,
762 	.getxattr	= generic_getxattr,
763 	.removexattr	= generic_removexattr,
764 #endif
765 	.listxattr	= zpl_xattr_list,
766 };
767 
768 const struct inode_operations zpl_special_inode_operations = {
769 	.setattr	= zpl_setattr,
770 	.getattr	= zpl_getattr,
771 #ifdef HAVE_GENERIC_SETXATTR
772 	.setxattr	= generic_setxattr,
773 	.getxattr	= generic_getxattr,
774 	.removexattr	= generic_removexattr,
775 #endif
776 	.listxattr	= zpl_xattr_list,
777 #if defined(CONFIG_FS_POSIX_ACL)
778 #if defined(HAVE_SET_ACL)
779 	.set_acl	= zpl_set_acl,
780 #endif /* HAVE_SET_ACL */
781 	.get_acl	= zpl_get_acl,
782 #endif /* CONFIG_FS_POSIX_ACL */
783 };
784 
785 dentry_operations_t zpl_dentry_operations = {
786 	.d_revalidate	= zpl_revalidate,
787 };
788