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.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or https://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
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]
22 * Copyright (c) 2011, Lawrence Livermore National Security, LLC.
23 * Copyright (c) 2015 by Chunwei Chen. All rights reserved.
27 #include <sys/sysmacros.h>
28 #include <sys/zfs_ctldir.h>
29 #include <sys/zfs_vfsops.h>
30 #include <sys/zfs_vnops.h>
31 #include <sys/zfs_znode.h>
32 #include <sys/dmu_objset.h>
37 static struct dentry
*
38 zpl_lookup(struct inode
*dir
, struct dentry
*dentry
, unsigned int flags
)
44 fstrans_cookie_t cookie
;
45 pathname_t
*ppn
= NULL
;
48 zfsvfs_t
*zfsvfs
= dentry
->d_sb
->s_fs_info
;
50 if (dlen(dentry
) >= ZAP_MAXNAMELEN
)
51 return (ERR_PTR(-ENAMETOOLONG
));
54 cookie
= spl_fstrans_mark();
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
;
63 error
= -zfs_lookup(ITOZ(dir
), dname(dentry
), &zp
,
64 zfs_flags
, cr
, NULL
, ppn
);
65 spl_fstrans_unmark(cookie
);
66 ASSERT3S(error
, <=, 0);
69 spin_lock(&dentry
->d_lock
);
70 dentry
->d_time
= jiffies
;
71 spin_unlock(&dentry
->d_lock
);
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.
86 return (d_splice_alias(NULL
, dentry
));
88 return (ERR_PTR(error
));
93 * If we are case insensitive, call the correct function
94 * to install the name.
97 struct dentry
*new_dentry
;
100 if (strcmp(dname(dentry
), pn
.pn_buf
) == 0) {
101 new_dentry
= d_splice_alias(ip
, dentry
);
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
);
110 return (d_splice_alias(ip
, dentry
));
115 zpl_vap_init(vattr_t
*vap
, struct inode
*dir
, umode_t mode
, cred_t
*cr
,
118 vap
->va_mask
= ATTR_MODE
;
121 vap
->va_uid
= zfs_vfsuid_to_uid(mnt_ns
,
122 zfs_i_user_ns(dir
), crgetuid(cr
));
124 if (dir
->i_mode
& S_ISGID
) {
125 vap
->va_gid
= KGID_TO_SGID(dir
->i_gid
);
127 vap
->va_mode
|= S_ISGID
;
129 vap
->va_gid
= zfs_vfsgid_to_gid(mnt_ns
,
130 zfs_i_user_ns(dir
), crgetgid(cr
));
135 #ifdef HAVE_IOPS_CREATE_USERNS
136 zpl_create(struct user_namespace
*user_ns
, struct inode
*dir
,
137 struct dentry
*dentry
, umode_t mode
, bool flag
)
138 #elif defined(HAVE_IOPS_CREATE_IDMAP)
139 zpl_create(struct mnt_idmap
*user_ns
, struct inode
*dir
,
140 struct dentry
*dentry
, umode_t mode
, bool flag
)
142 zpl_create(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
, bool flag
)
149 fstrans_cookie_t cookie
;
150 #if !(defined(HAVE_IOPS_CREATE_USERNS) || defined(HAVE_IOPS_CREATE_IDMAP))
151 zidmap_t
*user_ns
= kcred
->user_ns
;
155 vap
= kmem_zalloc(sizeof (vattr_t
), KM_SLEEP
);
156 zpl_vap_init(vap
, dir
, mode
, cr
, user_ns
);
158 cookie
= spl_fstrans_mark();
159 error
= -zfs_create(ITOZ(dir
), dname(dentry
), vap
, 0,
160 mode
, &zp
, cr
, 0, NULL
, user_ns
);
162 error
= zpl_xattr_security_init(ZTOI(zp
), dir
, &dentry
->d_name
);
164 error
= zpl_init_acl(ZTOI(zp
), dir
);
167 (void) zfs_remove(ITOZ(dir
), dname(dentry
), cr
, 0);
168 remove_inode_hash(ZTOI(zp
));
171 d_instantiate(dentry
, ZTOI(zp
));
175 spl_fstrans_unmark(cookie
);
176 kmem_free(vap
, sizeof (vattr_t
));
178 ASSERT3S(error
, <=, 0);
184 #ifdef HAVE_IOPS_MKNOD_USERNS
185 zpl_mknod(struct user_namespace
*user_ns
, struct inode
*dir
,
186 struct dentry
*dentry
, umode_t mode
,
187 #elif defined(HAVE_IOPS_MKNOD_IDMAP)
188 zpl_mknod(struct mnt_idmap
*user_ns
, struct inode
*dir
,
189 struct dentry
*dentry
, umode_t mode
,
191 zpl_mknod(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
,
199 fstrans_cookie_t cookie
;
200 #if !(defined(HAVE_IOPS_MKNOD_USERNS) || defined(HAVE_IOPS_MKNOD_IDMAP))
201 zidmap_t
*user_ns
= kcred
->user_ns
;
205 * We currently expect Linux to supply rdev=0 for all sockets
206 * and fifos, but we want to know if this behavior ever changes.
208 if (S_ISSOCK(mode
) || S_ISFIFO(mode
))
212 vap
= kmem_zalloc(sizeof (vattr_t
), KM_SLEEP
);
213 zpl_vap_init(vap
, dir
, mode
, cr
, user_ns
);
216 cookie
= spl_fstrans_mark();
217 error
= -zfs_create(ITOZ(dir
), dname(dentry
), vap
, 0,
218 mode
, &zp
, cr
, 0, NULL
, user_ns
);
220 error
= zpl_xattr_security_init(ZTOI(zp
), dir
, &dentry
->d_name
);
222 error
= zpl_init_acl(ZTOI(zp
), dir
);
225 (void) zfs_remove(ITOZ(dir
), dname(dentry
), cr
, 0);
226 remove_inode_hash(ZTOI(zp
));
229 d_instantiate(dentry
, ZTOI(zp
));
233 spl_fstrans_unmark(cookie
);
234 kmem_free(vap
, sizeof (vattr_t
));
236 ASSERT3S(error
, <=, 0);
243 #ifdef HAVE_TMPFILE_IDMAP
244 zpl_tmpfile(struct mnt_idmap
*userns
, struct inode
*dir
,
245 struct file
*file
, umode_t mode
)
246 #elif !defined(HAVE_TMPFILE_DENTRY)
247 zpl_tmpfile(struct user_namespace
*userns
, struct inode
*dir
,
248 struct file
*file
, umode_t mode
)
250 #ifdef HAVE_TMPFILE_USERNS
251 zpl_tmpfile(struct user_namespace
*userns
, struct inode
*dir
,
252 struct dentry
*dentry
, umode_t mode
)
254 zpl_tmpfile(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
262 fstrans_cookie_t cookie
;
263 #if !(defined(HAVE_TMPFILE_USERNS) || defined(HAVE_TMPFILE_IDMAP))
264 zidmap_t
*userns
= kcred
->user_ns
;
268 vap
= kmem_zalloc(sizeof (vattr_t
), KM_SLEEP
);
270 * The VFS does not apply the umask, therefore it is applied here
271 * when POSIX ACLs are not enabled.
273 if (!IS_POSIXACL(dir
))
274 mode
&= ~current_umask();
275 zpl_vap_init(vap
, dir
, mode
, cr
, userns
);
277 cookie
= spl_fstrans_mark();
278 error
= -zfs_tmpfile(dir
, vap
, 0, mode
, &ip
, cr
, 0, NULL
, userns
);
280 /* d_tmpfile will do drop_nlink, so we should set it first */
282 #ifndef HAVE_TMPFILE_DENTRY
285 error
= zpl_xattr_security_init(ip
, dir
,
286 &file
->f_path
.dentry
->d_name
);
288 d_tmpfile(dentry
, ip
);
290 error
= zpl_xattr_security_init(ip
, dir
, &dentry
->d_name
);
293 error
= zpl_init_acl(ip
, dir
);
294 #ifndef HAVE_TMPFILE_DENTRY
295 error
= finish_open_simple(file
, error
);
298 * don't need to handle error here, file is already in
303 spl_fstrans_unmark(cookie
);
304 kmem_free(vap
, sizeof (vattr_t
));
306 ASSERT3S(error
, <=, 0);
313 zpl_unlink(struct inode
*dir
, struct dentry
*dentry
)
317 fstrans_cookie_t cookie
;
318 zfsvfs_t
*zfsvfs
= dentry
->d_sb
->s_fs_info
;
321 cookie
= spl_fstrans_mark();
322 error
= -zfs_remove(ITOZ(dir
), dname(dentry
), cr
, 0);
325 * For a CI FS we must invalidate the dentry to prevent the
326 * creation of negative entries.
328 if (error
== 0 && zfsvfs
->z_case
== ZFS_CASE_INSENSITIVE
)
329 d_invalidate(dentry
);
331 spl_fstrans_unmark(cookie
);
333 ASSERT3S(error
, <=, 0);
339 #ifdef HAVE_IOPS_MKDIR_USERNS
340 zpl_mkdir(struct user_namespace
*user_ns
, struct inode
*dir
,
341 struct dentry
*dentry
, umode_t mode
)
342 #elif defined(HAVE_IOPS_MKDIR_IDMAP)
343 zpl_mkdir(struct mnt_idmap
*user_ns
, struct inode
*dir
,
344 struct dentry
*dentry
, umode_t mode
)
346 zpl_mkdir(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
353 fstrans_cookie_t cookie
;
354 #if !(defined(HAVE_IOPS_MKDIR_USERNS) || defined(HAVE_IOPS_MKDIR_IDMAP))
355 zidmap_t
*user_ns
= kcred
->user_ns
;
359 vap
= kmem_zalloc(sizeof (vattr_t
), KM_SLEEP
);
360 zpl_vap_init(vap
, dir
, mode
| S_IFDIR
, cr
, user_ns
);
362 cookie
= spl_fstrans_mark();
363 error
= -zfs_mkdir(ITOZ(dir
), dname(dentry
), vap
, &zp
, cr
, 0, NULL
,
366 error
= zpl_xattr_security_init(ZTOI(zp
), dir
, &dentry
->d_name
);
368 error
= zpl_init_acl(ZTOI(zp
), dir
);
371 (void) zfs_rmdir(ITOZ(dir
), dname(dentry
), NULL
, cr
, 0);
372 remove_inode_hash(ZTOI(zp
));
375 d_instantiate(dentry
, ZTOI(zp
));
379 spl_fstrans_unmark(cookie
);
380 kmem_free(vap
, sizeof (vattr_t
));
382 ASSERT3S(error
, <=, 0);
388 zpl_rmdir(struct inode
*dir
, struct dentry
*dentry
)
392 fstrans_cookie_t cookie
;
393 zfsvfs_t
*zfsvfs
= dentry
->d_sb
->s_fs_info
;
396 cookie
= spl_fstrans_mark();
397 error
= -zfs_rmdir(ITOZ(dir
), dname(dentry
), NULL
, cr
, 0);
400 * For a CI FS we must invalidate the dentry to prevent the
401 * creation of negative entries.
403 if (error
== 0 && zfsvfs
->z_case
== ZFS_CASE_INSENSITIVE
)
404 d_invalidate(dentry
);
406 spl_fstrans_unmark(cookie
);
408 ASSERT3S(error
, <=, 0);
414 #ifdef HAVE_USERNS_IOPS_GETATTR
415 zpl_getattr_impl(struct user_namespace
*user_ns
,
416 const struct path
*path
, struct kstat
*stat
, u32 request_mask
,
417 unsigned int query_flags
)
418 #elif defined(HAVE_IDMAP_IOPS_GETATTR)
419 zpl_getattr_impl(struct mnt_idmap
*user_ns
,
420 const struct path
*path
, struct kstat
*stat
, u32 request_mask
,
421 unsigned int query_flags
)
423 zpl_getattr_impl(const struct path
*path
, struct kstat
*stat
, u32 request_mask
,
424 unsigned int query_flags
)
428 fstrans_cookie_t cookie
;
429 struct inode
*ip
= path
->dentry
->d_inode
;
430 znode_t
*zp __maybe_unused
= ITOZ(ip
);
432 cookie
= spl_fstrans_mark();
435 * XXX query_flags currently ignored.
438 #if (defined(HAVE_USERNS_IOPS_GETATTR) || defined(HAVE_IDMAP_IOPS_GETATTR))
439 error
= -zfs_getattr_fast(user_ns
, ip
, stat
);
441 error
= -zfs_getattr_fast(kcred
->user_ns
, ip
, stat
);
445 if (request_mask
& STATX_BTIME
) {
446 stat
->btime
= zp
->z_btime
;
447 stat
->result_mask
|= STATX_BTIME
;
451 #ifdef STATX_ATTR_IMMUTABLE
452 if (zp
->z_pflags
& ZFS_IMMUTABLE
)
453 stat
->attributes
|= STATX_ATTR_IMMUTABLE
;
454 stat
->attributes_mask
|= STATX_ATTR_IMMUTABLE
;
457 #ifdef STATX_ATTR_APPEND
458 if (zp
->z_pflags
& ZFS_APPENDONLY
)
459 stat
->attributes
|= STATX_ATTR_APPEND
;
460 stat
->attributes_mask
|= STATX_ATTR_APPEND
;
463 #ifdef STATX_ATTR_NODUMP
464 if (zp
->z_pflags
& ZFS_NODUMP
)
465 stat
->attributes
|= STATX_ATTR_NODUMP
;
466 stat
->attributes_mask
|= STATX_ATTR_NODUMP
;
469 spl_fstrans_unmark(cookie
);
470 ASSERT3S(error
, <=, 0);
474 ZPL_GETATTR_WRAPPER(zpl_getattr
);
477 #ifdef HAVE_USERNS_IOPS_SETATTR
478 zpl_setattr(struct user_namespace
*user_ns
, struct dentry
*dentry
,
480 #elif defined(HAVE_IDMAP_IOPS_SETATTR)
481 zpl_setattr(struct mnt_idmap
*user_ns
, struct dentry
*dentry
,
484 zpl_setattr(struct dentry
*dentry
, struct iattr
*ia
)
487 struct inode
*ip
= dentry
->d_inode
;
491 fstrans_cookie_t cookie
;
493 #ifdef HAVE_SETATTR_PREPARE_USERNS
494 error
= zpl_setattr_prepare(user_ns
, dentry
, ia
);
495 #elif defined(HAVE_SETATTR_PREPARE_IDMAP)
496 error
= zpl_setattr_prepare(user_ns
, dentry
, ia
);
498 error
= zpl_setattr_prepare(zfs_init_idmap
, dentry
, ia
);
504 vap
= kmem_zalloc(sizeof (vattr_t
), KM_SLEEP
);
505 vap
->va_mask
= ia
->ia_valid
& ATTR_IATTR_MASK
;
506 vap
->va_mode
= ia
->ia_mode
;
507 if (ia
->ia_valid
& ATTR_UID
)
508 #ifdef HAVE_IATTR_VFSID
509 vap
->va_uid
= zfs_vfsuid_to_uid(user_ns
, zfs_i_user_ns(ip
),
510 __vfsuid_val(ia
->ia_vfsuid
));
512 vap
->va_uid
= KUID_TO_SUID(ia
->ia_uid
);
514 if (ia
->ia_valid
& ATTR_GID
)
515 #ifdef HAVE_IATTR_VFSID
516 vap
->va_gid
= zfs_vfsgid_to_gid(user_ns
, zfs_i_user_ns(ip
),
517 __vfsgid_val(ia
->ia_vfsgid
));
519 vap
->va_gid
= KGID_TO_SGID(ia
->ia_gid
);
521 vap
->va_size
= ia
->ia_size
;
522 vap
->va_atime
= ia
->ia_atime
;
523 vap
->va_mtime
= ia
->ia_mtime
;
524 vap
->va_ctime
= ia
->ia_ctime
;
526 if (vap
->va_mask
& ATTR_ATIME
)
527 ip
->i_atime
= zpl_inode_timestamp_truncate(ia
->ia_atime
, ip
);
529 cookie
= spl_fstrans_mark();
530 #ifdef HAVE_USERNS_IOPS_SETATTR
531 error
= -zfs_setattr(ITOZ(ip
), vap
, 0, cr
, user_ns
);
532 #elif defined(HAVE_IDMAP_IOPS_SETATTR)
533 error
= -zfs_setattr(ITOZ(ip
), vap
, 0, cr
, user_ns
);
535 error
= -zfs_setattr(ITOZ(ip
), vap
, 0, cr
, zfs_init_idmap
);
537 if (!error
&& (ia
->ia_valid
& ATTR_MODE
))
538 error
= zpl_chmod_acl(ip
);
540 spl_fstrans_unmark(cookie
);
541 kmem_free(vap
, sizeof (vattr_t
));
543 ASSERT3S(error
, <=, 0);
549 #ifdef HAVE_IOPS_RENAME_USERNS
550 zpl_rename2(struct user_namespace
*user_ns
, struct inode
*sdip
,
551 struct dentry
*sdentry
, struct inode
*tdip
, struct dentry
*tdentry
,
553 #elif defined(HAVE_IOPS_RENAME_IDMAP)
554 zpl_rename2(struct mnt_idmap
*user_ns
, struct inode
*sdip
,
555 struct dentry
*sdentry
, struct inode
*tdip
, struct dentry
*tdentry
,
558 zpl_rename2(struct inode
*sdip
, struct dentry
*sdentry
,
559 struct inode
*tdip
, struct dentry
*tdentry
, unsigned int rflags
)
563 vattr_t
*wo_vap
= NULL
;
565 fstrans_cookie_t cookie
;
566 #if !(defined(HAVE_IOPS_RENAME_USERNS) || defined(HAVE_IOPS_RENAME_IDMAP))
567 zidmap_t
*user_ns
= kcred
->user_ns
;
571 if (rflags
& RENAME_WHITEOUT
) {
572 wo_vap
= kmem_zalloc(sizeof (vattr_t
), KM_SLEEP
);
573 zpl_vap_init(wo_vap
, sdip
, S_IFCHR
, cr
, user_ns
);
574 wo_vap
->va_rdev
= makedevice(0, 0);
577 cookie
= spl_fstrans_mark();
578 error
= -zfs_rename(ITOZ(sdip
), dname(sdentry
), ITOZ(tdip
),
579 dname(tdentry
), cr
, 0, rflags
, wo_vap
, user_ns
);
580 spl_fstrans_unmark(cookie
);
582 kmem_free(wo_vap
, sizeof (vattr_t
));
584 ASSERT3S(error
, <=, 0);
589 #if !defined(HAVE_IOPS_RENAME_USERNS) && \
590 !defined(HAVE_RENAME_WANTS_FLAGS) && \
591 !defined(HAVE_RENAME2) && \
592 !defined(HAVE_IOPS_RENAME_IDMAP)
594 zpl_rename(struct inode
*sdip
, struct dentry
*sdentry
,
595 struct inode
*tdip
, struct dentry
*tdentry
)
597 return (zpl_rename2(sdip
, sdentry
, tdip
, tdentry
, 0));
602 #ifdef HAVE_IOPS_SYMLINK_USERNS
603 zpl_symlink(struct user_namespace
*user_ns
, struct inode
*dir
,
604 struct dentry
*dentry
, const char *name
)
605 #elif defined(HAVE_IOPS_SYMLINK_IDMAP)
606 zpl_symlink(struct mnt_idmap
*user_ns
, struct inode
*dir
,
607 struct dentry
*dentry
, const char *name
)
609 zpl_symlink(struct inode
*dir
, struct dentry
*dentry
, const char *name
)
616 fstrans_cookie_t cookie
;
617 #if !(defined(HAVE_IOPS_SYMLINK_USERNS) || defined(HAVE_IOPS_SYMLINK_IDMAP))
618 zidmap_t
*user_ns
= kcred
->user_ns
;
622 vap
= kmem_zalloc(sizeof (vattr_t
), KM_SLEEP
);
623 zpl_vap_init(vap
, dir
, S_IFLNK
| S_IRWXUGO
, cr
, user_ns
);
625 cookie
= spl_fstrans_mark();
626 error
= -zfs_symlink(ITOZ(dir
), dname(dentry
), vap
,
627 (char *)name
, &zp
, cr
, 0, user_ns
);
629 error
= zpl_xattr_security_init(ZTOI(zp
), dir
, &dentry
->d_name
);
631 (void) zfs_remove(ITOZ(dir
), dname(dentry
), cr
, 0);
632 remove_inode_hash(ZTOI(zp
));
635 d_instantiate(dentry
, ZTOI(zp
));
639 spl_fstrans_unmark(cookie
);
640 kmem_free(vap
, sizeof (vattr_t
));
642 ASSERT3S(error
, <=, 0);
647 #if defined(HAVE_PUT_LINK_COOKIE)
649 zpl_put_link(struct inode
*unused
, void *cookie
)
651 kmem_free(cookie
, MAXPATHLEN
);
653 #elif defined(HAVE_PUT_LINK_NAMEIDATA)
655 zpl_put_link(struct dentry
*dentry
, struct nameidata
*nd
, void *ptr
)
657 const char *link
= nd_get_link(nd
);
660 kmem_free(link
, MAXPATHLEN
);
662 #elif defined(HAVE_PUT_LINK_DELAYED)
664 zpl_put_link(void *ptr
)
666 kmem_free(ptr
, MAXPATHLEN
);
671 zpl_get_link_common(struct dentry
*dentry
, struct inode
*ip
, char **link
)
673 fstrans_cookie_t cookie
;
681 iov
.iov_len
= MAXPATHLEN
;
682 iov
.iov_base
= kmem_zalloc(MAXPATHLEN
, KM_SLEEP
);
685 zfs_uio_iovec_init(&uio
, &iov
, 1, 0, UIO_SYSSPACE
, MAXPATHLEN
- 1, 0);
687 cookie
= spl_fstrans_mark();
688 error
= -zfs_readlink(ip
, &uio
, cr
);
689 spl_fstrans_unmark(cookie
);
693 kmem_free(iov
.iov_base
, MAXPATHLEN
);
695 *link
= iov
.iov_base
;
700 #if defined(HAVE_GET_LINK_DELAYED)
702 zpl_get_link(struct dentry
*dentry
, struct inode
*inode
,
703 struct delayed_call
*done
)
709 return (ERR_PTR(-ECHILD
));
711 error
= zpl_get_link_common(dentry
, inode
, &link
);
713 return (ERR_PTR(error
));
715 set_delayed_call(done
, zpl_put_link
, link
);
719 #elif defined(HAVE_GET_LINK_COOKIE)
721 zpl_get_link(struct dentry
*dentry
, struct inode
*inode
, void **cookie
)
727 return (ERR_PTR(-ECHILD
));
729 error
= zpl_get_link_common(dentry
, inode
, &link
);
731 return (ERR_PTR(error
));
733 return (*cookie
= link
);
735 #elif defined(HAVE_FOLLOW_LINK_COOKIE)
737 zpl_follow_link(struct dentry
*dentry
, void **cookie
)
742 error
= zpl_get_link_common(dentry
, dentry
->d_inode
, &link
);
744 return (ERR_PTR(error
));
746 return (*cookie
= link
);
748 #elif defined(HAVE_FOLLOW_LINK_NAMEIDATA)
750 zpl_follow_link(struct dentry
*dentry
, struct nameidata
*nd
)
755 error
= zpl_get_link_common(dentry
, dentry
->d_inode
, &link
);
757 nd_set_link(nd
, ERR_PTR(error
));
759 nd_set_link(nd
, link
);
766 zpl_link(struct dentry
*old_dentry
, struct inode
*dir
, struct dentry
*dentry
)
769 struct inode
*ip
= old_dentry
->d_inode
;
771 fstrans_cookie_t cookie
;
773 if (ip
->i_nlink
>= ZFS_LINK_MAX
)
777 zpl_inode_set_ctime_to_ts(ip
, current_time(ip
));
778 /* Must have an existing ref, so igrab() cannot return NULL */
779 VERIFY3P(igrab(ip
), !=, NULL
);
781 cookie
= spl_fstrans_mark();
782 error
= -zfs_link(ITOZ(dir
), ITOZ(ip
), dname(dentry
), cr
, 0);
788 d_instantiate(dentry
, ip
);
790 spl_fstrans_unmark(cookie
);
792 ASSERT3S(error
, <=, 0);
797 const struct inode_operations zpl_inode_operations
= {
798 .setattr
= zpl_setattr
,
799 .getattr
= zpl_getattr
,
800 #ifdef HAVE_GENERIC_SETXATTR
801 .setxattr
= generic_setxattr
,
802 .getxattr
= generic_getxattr
,
803 .removexattr
= generic_removexattr
,
805 .listxattr
= zpl_xattr_list
,
806 #if defined(CONFIG_FS_POSIX_ACL)
807 #if defined(HAVE_SET_ACL)
808 .set_acl
= zpl_set_acl
,
809 #endif /* HAVE_SET_ACL */
810 #if defined(HAVE_GET_INODE_ACL)
811 .get_inode_acl
= zpl_get_acl
,
813 .get_acl
= zpl_get_acl
,
814 #endif /* HAVE_GET_INODE_ACL */
815 #endif /* CONFIG_FS_POSIX_ACL */
818 #ifdef HAVE_RENAME2_OPERATIONS_WRAPPER
819 const struct inode_operations_wrapper zpl_dir_inode_operations
= {
822 const struct inode_operations zpl_dir_inode_operations
= {
824 .create
= zpl_create
,
825 .lookup
= zpl_lookup
,
827 .unlink
= zpl_unlink
,
828 .symlink
= zpl_symlink
,
833 .rename2
= zpl_rename2
,
834 #elif defined(HAVE_RENAME_WANTS_FLAGS) || defined(HAVE_IOPS_RENAME_USERNS)
835 .rename
= zpl_rename2
,
836 #elif defined(HAVE_IOPS_RENAME_IDMAP)
837 .rename
= zpl_rename2
,
839 .rename
= zpl_rename
,
842 .tmpfile
= zpl_tmpfile
,
844 .setattr
= zpl_setattr
,
845 .getattr
= zpl_getattr
,
846 #ifdef HAVE_GENERIC_SETXATTR
847 .setxattr
= generic_setxattr
,
848 .getxattr
= generic_getxattr
,
849 .removexattr
= generic_removexattr
,
851 .listxattr
= zpl_xattr_list
,
852 #if defined(CONFIG_FS_POSIX_ACL)
853 #if defined(HAVE_SET_ACL)
854 .set_acl
= zpl_set_acl
,
855 #endif /* HAVE_SET_ACL */
856 #if defined(HAVE_GET_INODE_ACL)
857 .get_inode_acl
= zpl_get_acl
,
859 .get_acl
= zpl_get_acl
,
860 #endif /* HAVE_GET_INODE_ACL */
861 #endif /* CONFIG_FS_POSIX_ACL */
862 #ifdef HAVE_RENAME2_OPERATIONS_WRAPPER
864 .rename2
= zpl_rename2
,
868 const struct inode_operations zpl_symlink_inode_operations
= {
869 #ifdef HAVE_GENERIC_READLINK
870 .readlink
= generic_readlink
,
872 #if defined(HAVE_GET_LINK_DELAYED) || defined(HAVE_GET_LINK_COOKIE)
873 .get_link
= zpl_get_link
,
874 #elif defined(HAVE_FOLLOW_LINK_COOKIE) || defined(HAVE_FOLLOW_LINK_NAMEIDATA)
875 .follow_link
= zpl_follow_link
,
877 #if defined(HAVE_PUT_LINK_COOKIE) || defined(HAVE_PUT_LINK_NAMEIDATA)
878 .put_link
= zpl_put_link
,
880 .setattr
= zpl_setattr
,
881 .getattr
= zpl_getattr
,
882 #ifdef HAVE_GENERIC_SETXATTR
883 .setxattr
= generic_setxattr
,
884 .getxattr
= generic_getxattr
,
885 .removexattr
= generic_removexattr
,
887 .listxattr
= zpl_xattr_list
,
890 const struct inode_operations zpl_special_inode_operations
= {
891 .setattr
= zpl_setattr
,
892 .getattr
= zpl_getattr
,
893 #ifdef HAVE_GENERIC_SETXATTR
894 .setxattr
= generic_setxattr
,
895 .getxattr
= generic_getxattr
,
896 .removexattr
= generic_removexattr
,
898 .listxattr
= zpl_xattr_list
,
899 #if defined(CONFIG_FS_POSIX_ACL)
900 #if defined(HAVE_SET_ACL)
901 .set_acl
= zpl_set_acl
,
902 #endif /* HAVE_SET_ACL */
903 #if defined(HAVE_GET_INODE_ACL)
904 .get_inode_acl
= zpl_get_acl
,
906 .get_acl
= zpl_get_acl
,
907 #endif /* HAVE_GET_INODE_ACL */
908 #endif /* CONFIG_FS_POSIX_ACL */