3 * Copyright (C) 2011 Novell Inc.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
11 #include <linux/namei.h>
12 #include <linux/xattr.h>
13 #include <linux/security.h>
14 #include <linux/cred.h>
15 #include <linux/module.h>
16 #include <linux/posix_acl.h>
17 #include <linux/posix_acl_xattr.h>
18 #include <linux/atomic.h>
19 #include <linux/ratelimit.h>
20 #include "overlayfs.h"
22 static unsigned short ovl_redirect_max
= 256;
23 module_param_named(redirect_max
, ovl_redirect_max
, ushort
, 0644);
24 MODULE_PARM_DESC(ovl_redirect_max
,
25 "Maximum length of absolute redirect xattr value");
27 int ovl_cleanup(struct inode
*wdir
, struct dentry
*wdentry
)
32 if (d_is_dir(wdentry
))
33 err
= ovl_do_rmdir(wdir
, wdentry
);
35 err
= ovl_do_unlink(wdir
, wdentry
);
39 pr_err("overlayfs: cleanup of '%pd2' failed (%i)\n",
46 struct dentry
*ovl_lookup_temp(struct dentry
*workdir
)
50 static atomic_t temp_id
= ATOMIC_INIT(0);
52 /* counter is allowed to wrap, since temp dentries are ephemeral */
53 snprintf(name
, sizeof(name
), "#%x", atomic_inc_return(&temp_id
));
55 temp
= lookup_one_len(name
, workdir
, strlen(name
));
56 if (!IS_ERR(temp
) && temp
->d_inode
) {
57 pr_err("overlayfs: workdir/%s already exists\n", name
);
65 /* caller holds i_mutex on workdir */
66 static struct dentry
*ovl_whiteout(struct dentry
*workdir
)
69 struct dentry
*whiteout
;
70 struct inode
*wdir
= workdir
->d_inode
;
72 whiteout
= ovl_lookup_temp(workdir
);
76 err
= ovl_do_whiteout(wdir
, whiteout
);
79 whiteout
= ERR_PTR(err
);
85 /* Caller must hold i_mutex on both workdir and dir */
86 int ovl_cleanup_and_whiteout(struct dentry
*workdir
, struct inode
*dir
,
87 struct dentry
*dentry
)
89 struct inode
*wdir
= workdir
->d_inode
;
90 struct dentry
*whiteout
;
94 whiteout
= ovl_whiteout(workdir
);
95 err
= PTR_ERR(whiteout
);
100 flags
= RENAME_EXCHANGE
;
102 err
= ovl_do_rename(wdir
, whiteout
, dir
, dentry
, flags
);
106 ovl_cleanup(wdir
, dentry
);
113 ovl_cleanup(wdir
, whiteout
);
117 struct dentry
*ovl_create_real(struct inode
*dir
, struct dentry
*newdentry
,
118 struct ovl_cattr
*attr
)
122 if (IS_ERR(newdentry
))
126 if (newdentry
->d_inode
)
129 if (attr
->hardlink
) {
130 err
= ovl_do_link(attr
->hardlink
, dir
, newdentry
);
132 switch (attr
->mode
& S_IFMT
) {
134 err
= ovl_do_create(dir
, newdentry
, attr
->mode
);
138 err
= ovl_do_mkdir(dir
, newdentry
, attr
->mode
);
145 err
= ovl_do_mknod(dir
, newdentry
, attr
->mode
,
150 err
= ovl_do_symlink(dir
, newdentry
, attr
->link
);
157 if (!err
&& WARN_ON(!newdentry
->d_inode
)) {
159 * Not quite sure if non-instantiated dentry is legal or not.
160 * VFS doesn't seem to care so check and warn here.
172 static int ovl_set_opaque_xerr(struct dentry
*dentry
, struct dentry
*upper
,
177 err
= ovl_check_setxattr(dentry
, upper
, OVL_XATTR_OPAQUE
, "y", 1, xerr
);
179 ovl_dentry_set_opaque(dentry
);
184 static int ovl_set_opaque(struct dentry
*dentry
, struct dentry
*upperdentry
)
187 * Fail with -EIO when trying to create opaque dir and upper doesn't
188 * support xattrs. ovl_rename() calls ovl_set_opaque_xerr(-EXDEV) to
189 * return a specific error for noxattr case.
191 return ovl_set_opaque_xerr(dentry
, upperdentry
, -EIO
);
194 /* Common operations required to be done after creation of file on upper */
195 static void ovl_instantiate(struct dentry
*dentry
, struct inode
*inode
,
196 struct dentry
*newdentry
, bool hardlink
)
198 ovl_dentry_version_inc(dentry
->d_parent
, false);
199 ovl_dentry_set_upper_alias(dentry
);
201 ovl_inode_update(inode
, newdentry
);
202 ovl_copyattr(newdentry
->d_inode
, inode
);
204 WARN_ON(ovl_inode_real(inode
) != d_inode(newdentry
));
208 d_instantiate(dentry
, inode
);
209 /* Force lookup of new upper hardlink to find its lower */
214 static bool ovl_type_merge(struct dentry
*dentry
)
216 return OVL_TYPE_MERGE(ovl_path_type(dentry
));
219 static bool ovl_type_origin(struct dentry
*dentry
)
221 return OVL_TYPE_ORIGIN(ovl_path_type(dentry
));
224 static int ovl_create_upper(struct dentry
*dentry
, struct inode
*inode
,
225 struct ovl_cattr
*attr
)
227 struct dentry
*upperdir
= ovl_dentry_upper(dentry
->d_parent
);
228 struct inode
*udir
= upperdir
->d_inode
;
229 struct dentry
*newdentry
;
232 if (!attr
->hardlink
&& !IS_POSIXACL(udir
))
233 attr
->mode
&= ~current_umask();
235 inode_lock_nested(udir
, I_MUTEX_PARENT
);
236 newdentry
= ovl_create_real(udir
,
237 lookup_one_len(dentry
->d_name
.name
,
241 err
= PTR_ERR(newdentry
);
242 if (IS_ERR(newdentry
))
245 if (ovl_type_merge(dentry
->d_parent
) && d_is_dir(newdentry
)) {
246 /* Setting opaque here is just an optimization, allow to fail */
247 ovl_set_opaque(dentry
, newdentry
);
250 ovl_instantiate(dentry
, inode
, newdentry
, !!attr
->hardlink
);
257 static struct dentry
*ovl_clear_empty(struct dentry
*dentry
,
258 struct list_head
*list
)
260 struct dentry
*workdir
= ovl_workdir(dentry
);
261 struct inode
*wdir
= workdir
->d_inode
;
262 struct dentry
*upperdir
= ovl_dentry_upper(dentry
->d_parent
);
263 struct inode
*udir
= upperdir
->d_inode
;
264 struct path upperpath
;
265 struct dentry
*upper
;
266 struct dentry
*opaquedir
;
270 if (WARN_ON(!workdir
))
271 return ERR_PTR(-EROFS
);
273 err
= ovl_lock_rename_workdir(workdir
, upperdir
);
277 ovl_path_upper(dentry
, &upperpath
);
278 err
= vfs_getattr(&upperpath
, &stat
,
279 STATX_BASIC_STATS
, AT_STATX_SYNC_AS_STAT
);
284 if (!S_ISDIR(stat
.mode
))
286 upper
= upperpath
.dentry
;
287 if (upper
->d_parent
->d_inode
!= udir
)
290 opaquedir
= ovl_create_real(wdir
, ovl_lookup_temp(workdir
),
291 OVL_CATTR(stat
.mode
));
292 err
= PTR_ERR(opaquedir
);
293 if (IS_ERR(opaquedir
))
296 err
= ovl_copy_xattr(upper
, opaquedir
);
300 err
= ovl_set_opaque(dentry
, opaquedir
);
304 inode_lock(opaquedir
->d_inode
);
305 err
= ovl_set_attr(opaquedir
, &stat
);
306 inode_unlock(opaquedir
->d_inode
);
310 err
= ovl_do_rename(wdir
, opaquedir
, udir
, upper
, RENAME_EXCHANGE
);
314 ovl_cleanup_whiteouts(upper
, list
);
315 ovl_cleanup(wdir
, upper
);
316 unlock_rename(workdir
, upperdir
);
318 /* dentry's upper doesn't match now, get rid of it */
324 ovl_cleanup(wdir
, opaquedir
);
327 unlock_rename(workdir
, upperdir
);
332 static int ovl_set_upper_acl(struct dentry
*upperdentry
, const char *name
,
333 const struct posix_acl
*acl
)
339 if (!IS_ENABLED(CONFIG_FS_POSIX_ACL
) || !acl
)
342 size
= posix_acl_to_xattr(NULL
, acl
, NULL
, 0);
343 buffer
= kmalloc(size
, GFP_KERNEL
);
347 size
= posix_acl_to_xattr(&init_user_ns
, acl
, buffer
, size
);
352 err
= vfs_setxattr(upperdentry
, name
, buffer
, size
, XATTR_CREATE
);
358 static int ovl_create_over_whiteout(struct dentry
*dentry
, struct inode
*inode
,
359 struct ovl_cattr
*cattr
)
361 struct dentry
*workdir
= ovl_workdir(dentry
);
362 struct inode
*wdir
= workdir
->d_inode
;
363 struct dentry
*upperdir
= ovl_dentry_upper(dentry
->d_parent
);
364 struct inode
*udir
= upperdir
->d_inode
;
365 struct dentry
*upper
;
366 struct dentry
*newdentry
;
368 struct posix_acl
*acl
, *default_acl
;
369 bool hardlink
= !!cattr
->hardlink
;
371 if (WARN_ON(!workdir
))
375 err
= posix_acl_create(dentry
->d_parent
->d_inode
,
376 &cattr
->mode
, &default_acl
, &acl
);
381 err
= ovl_lock_rename_workdir(workdir
, upperdir
);
385 upper
= lookup_one_len(dentry
->d_name
.name
, upperdir
,
387 err
= PTR_ERR(upper
);
391 newdentry
= ovl_create_real(wdir
, ovl_lookup_temp(workdir
), cattr
);
392 err
= PTR_ERR(newdentry
);
393 if (IS_ERR(newdentry
))
397 * mode could have been mutilated due to umask (e.g. sgid directory)
400 !S_ISLNK(cattr
->mode
) &&
401 newdentry
->d_inode
->i_mode
!= cattr
->mode
) {
402 struct iattr attr
= {
403 .ia_valid
= ATTR_MODE
,
404 .ia_mode
= cattr
->mode
,
406 inode_lock(newdentry
->d_inode
);
407 err
= notify_change(newdentry
, &attr
, NULL
);
408 inode_unlock(newdentry
->d_inode
);
413 err
= ovl_set_upper_acl(newdentry
, XATTR_NAME_POSIX_ACL_ACCESS
,
418 err
= ovl_set_upper_acl(newdentry
, XATTR_NAME_POSIX_ACL_DEFAULT
,
424 if (!hardlink
&& S_ISDIR(cattr
->mode
)) {
425 err
= ovl_set_opaque(dentry
, newdentry
);
429 err
= ovl_do_rename(wdir
, newdentry
, udir
, upper
,
434 ovl_cleanup(wdir
, upper
);
436 err
= ovl_do_rename(wdir
, newdentry
, udir
, upper
, 0);
440 ovl_instantiate(dentry
, inode
, newdentry
, hardlink
);
445 unlock_rename(workdir
, upperdir
);
448 posix_acl_release(acl
);
449 posix_acl_release(default_acl
);
454 ovl_cleanup(wdir
, newdentry
);
459 static int ovl_create_or_link(struct dentry
*dentry
, struct inode
*inode
,
460 struct ovl_cattr
*attr
, bool origin
)
463 const struct cred
*old_cred
;
464 struct cred
*override_cred
;
465 struct dentry
*parent
= dentry
->d_parent
;
467 err
= ovl_copy_up(parent
);
471 old_cred
= ovl_override_creds(dentry
->d_sb
);
474 * When linking a file with copy up origin into a new parent, mark the
475 * new parent dir "impure".
478 err
= ovl_set_impure(parent
, ovl_dentry_upper(parent
));
480 goto out_revert_creds
;
484 override_cred
= prepare_creds();
486 override_cred
->fsuid
= inode
->i_uid
;
487 override_cred
->fsgid
= inode
->i_gid
;
488 if (!attr
->hardlink
) {
489 err
= security_dentry_create_files_as(dentry
,
490 attr
->mode
, &dentry
->d_name
, old_cred
,
493 put_cred(override_cred
);
494 goto out_revert_creds
;
497 put_cred(override_creds(override_cred
));
498 put_cred(override_cred
);
500 if (!ovl_dentry_is_whiteout(dentry
))
501 err
= ovl_create_upper(dentry
, inode
, attr
);
503 err
= ovl_create_over_whiteout(dentry
, inode
, attr
);
506 revert_creds(old_cred
);
510 static int ovl_create_object(struct dentry
*dentry
, int mode
, dev_t rdev
,
515 struct ovl_cattr attr
= {
520 err
= ovl_want_write(dentry
);
525 inode
= ovl_new_inode(dentry
->d_sb
, mode
, rdev
);
529 inode_init_owner(inode
, dentry
->d_parent
->d_inode
, mode
);
530 attr
.mode
= inode
->i_mode
;
532 err
= ovl_create_or_link(dentry
, inode
, &attr
, false);
537 ovl_drop_write(dentry
);
542 static int ovl_create(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
,
545 return ovl_create_object(dentry
, (mode
& 07777) | S_IFREG
, 0, NULL
);
548 static int ovl_mkdir(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
550 return ovl_create_object(dentry
, (mode
& 07777) | S_IFDIR
, 0, NULL
);
553 static int ovl_mknod(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
,
556 /* Don't allow creation of "whiteout" on overlay */
557 if (S_ISCHR(mode
) && rdev
== WHITEOUT_DEV
)
560 return ovl_create_object(dentry
, mode
, rdev
, NULL
);
563 static int ovl_symlink(struct inode
*dir
, struct dentry
*dentry
,
566 return ovl_create_object(dentry
, S_IFLNK
, 0, link
);
569 static int ovl_link(struct dentry
*old
, struct inode
*newdir
,
576 err
= ovl_want_write(old
);
580 err
= ovl_copy_up(old
);
584 err
= ovl_nlink_start(old
, &locked
);
588 inode
= d_inode(old
);
591 err
= ovl_create_or_link(new, inode
,
592 &(struct ovl_cattr
) {.hardlink
= ovl_dentry_upper(old
)},
593 ovl_type_origin(old
));
597 ovl_nlink_end(old
, locked
);
604 static bool ovl_matches_upper(struct dentry
*dentry
, struct dentry
*upper
)
606 return d_inode(ovl_dentry_upper(dentry
)) == d_inode(upper
);
609 static int ovl_remove_and_whiteout(struct dentry
*dentry
,
610 struct list_head
*list
)
612 struct dentry
*workdir
= ovl_workdir(dentry
);
613 struct dentry
*upperdir
= ovl_dentry_upper(dentry
->d_parent
);
614 struct dentry
*upper
;
615 struct dentry
*opaquedir
= NULL
;
618 if (WARN_ON(!workdir
))
621 if (!list_empty(list
)) {
622 opaquedir
= ovl_clear_empty(dentry
, list
);
623 err
= PTR_ERR(opaquedir
);
624 if (IS_ERR(opaquedir
))
628 err
= ovl_lock_rename_workdir(workdir
, upperdir
);
632 upper
= lookup_one_len(dentry
->d_name
.name
, upperdir
,
634 err
= PTR_ERR(upper
);
639 if ((opaquedir
&& upper
!= opaquedir
) ||
640 (!opaquedir
&& ovl_dentry_upper(dentry
) &&
641 !ovl_matches_upper(dentry
, upper
))) {
645 err
= ovl_cleanup_and_whiteout(workdir
, d_inode(upperdir
), upper
);
649 ovl_dentry_version_inc(dentry
->d_parent
, true);
655 unlock_rename(workdir
, upperdir
);
662 static int ovl_remove_upper(struct dentry
*dentry
, bool is_dir
,
663 struct list_head
*list
)
665 struct dentry
*upperdir
= ovl_dentry_upper(dentry
->d_parent
);
666 struct inode
*dir
= upperdir
->d_inode
;
667 struct dentry
*upper
;
668 struct dentry
*opaquedir
= NULL
;
671 if (!list_empty(list
)) {
672 opaquedir
= ovl_clear_empty(dentry
, list
);
673 err
= PTR_ERR(opaquedir
);
674 if (IS_ERR(opaquedir
))
678 inode_lock_nested(dir
, I_MUTEX_PARENT
);
679 upper
= lookup_one_len(dentry
->d_name
.name
, upperdir
,
681 err
= PTR_ERR(upper
);
686 if ((opaquedir
&& upper
!= opaquedir
) ||
687 (!opaquedir
&& !ovl_matches_upper(dentry
, upper
)))
691 err
= vfs_rmdir(dir
, upper
);
693 err
= vfs_unlink(dir
, upper
, NULL
);
694 ovl_dentry_version_inc(dentry
->d_parent
, ovl_type_origin(dentry
));
697 * Keeping this dentry hashed would mean having to release
698 * upperpath/lowerpath, which could only be done if we are the
699 * sole user of this dentry. Too tricky... Just unhash for
713 static bool ovl_pure_upper(struct dentry
*dentry
)
715 return !ovl_dentry_lower(dentry
) &&
716 !ovl_test_flag(OVL_WHITEOUTS
, d_inode(dentry
));
719 static int ovl_do_remove(struct dentry
*dentry
, bool is_dir
)
723 const struct cred
*old_cred
;
724 bool lower_positive
= ovl_lower_positive(dentry
);
727 /* No need to clean pure upper removed by vfs_rmdir() */
728 if (is_dir
&& (lower_positive
|| !ovl_pure_upper(dentry
))) {
729 err
= ovl_check_empty_dir(dentry
, &list
);
734 err
= ovl_want_write(dentry
);
738 err
= ovl_copy_up(dentry
->d_parent
);
742 err
= ovl_nlink_start(dentry
, &locked
);
746 old_cred
= ovl_override_creds(dentry
->d_sb
);
748 err
= ovl_remove_upper(dentry
, is_dir
, &list
);
750 err
= ovl_remove_and_whiteout(dentry
, &list
);
751 revert_creds(old_cred
);
754 clear_nlink(dentry
->d_inode
);
756 drop_nlink(dentry
->d_inode
);
758 ovl_nlink_end(dentry
, locked
);
760 ovl_drop_write(dentry
);
762 ovl_cache_free(&list
);
766 static int ovl_unlink(struct inode
*dir
, struct dentry
*dentry
)
768 return ovl_do_remove(dentry
, false);
771 static int ovl_rmdir(struct inode
*dir
, struct dentry
*dentry
)
773 return ovl_do_remove(dentry
, true);
776 static bool ovl_type_merge_or_lower(struct dentry
*dentry
)
778 enum ovl_path_type type
= ovl_path_type(dentry
);
780 return OVL_TYPE_MERGE(type
) || !OVL_TYPE_UPPER(type
);
783 static bool ovl_can_move(struct dentry
*dentry
)
785 return ovl_redirect_dir(dentry
->d_sb
) ||
786 !d_is_dir(dentry
) || !ovl_type_merge_or_lower(dentry
);
789 static char *ovl_get_redirect(struct dentry
*dentry
, bool samedir
)
792 struct dentry
*d
, *tmp
;
793 int buflen
= ovl_redirect_max
+ 1;
796 ret
= kstrndup(dentry
->d_name
.name
, dentry
->d_name
.len
,
801 buf
= ret
= kmalloc(buflen
, GFP_KERNEL
);
807 for (d
= dget(dentry
); !IS_ROOT(d
);) {
811 spin_lock(&d
->d_lock
);
812 name
= ovl_dentry_get_redirect(d
);
814 thislen
= strlen(name
);
816 name
= d
->d_name
.name
;
817 thislen
= d
->d_name
.len
;
820 /* If path is too long, fall back to userspace move */
821 if (thislen
+ (name
[0] != '/') > buflen
) {
822 ret
= ERR_PTR(-EXDEV
);
823 spin_unlock(&d
->d_lock
);
828 memcpy(&buf
[buflen
], name
, thislen
);
829 tmp
= dget_dlock(d
->d_parent
);
830 spin_unlock(&d
->d_lock
);
835 /* Absolute redirect: finished */
836 if (buf
[buflen
] == '/')
841 ret
= kstrdup(&buf
[buflen
], GFP_KERNEL
);
846 return ret
? ret
: ERR_PTR(-ENOMEM
);
849 static int ovl_set_redirect(struct dentry
*dentry
, bool samedir
)
852 const char *redirect
= ovl_dentry_get_redirect(dentry
);
854 if (redirect
&& (samedir
|| redirect
[0] == '/'))
857 redirect
= ovl_get_redirect(dentry
, samedir
);
858 if (IS_ERR(redirect
))
859 return PTR_ERR(redirect
);
861 err
= ovl_check_setxattr(dentry
, ovl_dentry_upper(dentry
),
863 redirect
, strlen(redirect
), -EXDEV
);
865 spin_lock(&dentry
->d_lock
);
866 ovl_dentry_set_redirect(dentry
, redirect
);
867 spin_unlock(&dentry
->d_lock
);
870 pr_warn_ratelimited("overlayfs: failed to set redirect (%i)\n",
872 /* Fall back to userspace copy-up */
878 static int ovl_rename(struct inode
*olddir
, struct dentry
*old
,
879 struct inode
*newdir
, struct dentry
*new,
884 struct dentry
*old_upperdir
;
885 struct dentry
*new_upperdir
;
886 struct dentry
*olddentry
;
887 struct dentry
*newdentry
;
891 bool cleanup_whiteout
= false;
892 bool overwrite
= !(flags
& RENAME_EXCHANGE
);
893 bool is_dir
= d_is_dir(old
);
894 bool new_is_dir
= d_is_dir(new);
895 bool samedir
= olddir
== newdir
;
896 struct dentry
*opaquedir
= NULL
;
897 const struct cred
*old_cred
= NULL
;
901 if (flags
& ~(RENAME_EXCHANGE
| RENAME_NOREPLACE
))
904 flags
&= ~RENAME_NOREPLACE
;
906 /* Don't copy up directory trees */
908 if (!ovl_can_move(old
))
910 if (!overwrite
&& !ovl_can_move(new))
913 if (overwrite
&& new_is_dir
&& !ovl_pure_upper(new)) {
914 err
= ovl_check_empty_dir(new, &list
);
920 if (ovl_lower_positive(old
)) {
921 if (!ovl_dentry_is_whiteout(new)) {
922 /* Whiteout source */
923 flags
|= RENAME_WHITEOUT
;
925 /* Switch whiteouts */
926 flags
|= RENAME_EXCHANGE
;
928 } else if (is_dir
&& ovl_dentry_is_whiteout(new)) {
929 flags
|= RENAME_EXCHANGE
;
930 cleanup_whiteout
= true;
934 err
= ovl_want_write(old
);
938 err
= ovl_copy_up(old
);
942 err
= ovl_copy_up(new->d_parent
);
946 err
= ovl_copy_up(new);
950 err
= ovl_nlink_start(new, &locked
);
955 old_cred
= ovl_override_creds(old
->d_sb
);
957 if (!list_empty(&list
)) {
958 opaquedir
= ovl_clear_empty(new, &list
);
959 err
= PTR_ERR(opaquedir
);
960 if (IS_ERR(opaquedir
)) {
962 goto out_revert_creds
;
966 old_upperdir
= ovl_dentry_upper(old
->d_parent
);
967 new_upperdir
= ovl_dentry_upper(new->d_parent
);
971 * When moving a merge dir or non-dir with copy up origin into
972 * a new parent, we are marking the new parent dir "impure".
973 * When ovl_iterate() iterates an "impure" upper dir, it will
974 * lookup the origin inodes of the entries to fill d_ino.
976 if (ovl_type_origin(old
)) {
977 err
= ovl_set_impure(new->d_parent
, new_upperdir
);
979 goto out_revert_creds
;
981 if (!overwrite
&& ovl_type_origin(new)) {
982 err
= ovl_set_impure(old
->d_parent
, old_upperdir
);
984 goto out_revert_creds
;
988 trap
= lock_rename(new_upperdir
, old_upperdir
);
990 olddentry
= lookup_one_len(old
->d_name
.name
, old_upperdir
,
992 err
= PTR_ERR(olddentry
);
993 if (IS_ERR(olddentry
))
997 if (!ovl_matches_upper(old
, olddentry
))
1000 newdentry
= lookup_one_len(new->d_name
.name
, new_upperdir
,
1002 err
= PTR_ERR(newdentry
);
1003 if (IS_ERR(newdentry
))
1006 old_opaque
= ovl_dentry_is_opaque(old
);
1007 new_opaque
= ovl_dentry_is_opaque(new);
1010 if (d_inode(new) && ovl_dentry_upper(new)) {
1012 if (newdentry
!= opaquedir
)
1015 if (!ovl_matches_upper(new, newdentry
))
1019 if (!d_is_negative(newdentry
) &&
1020 (!new_opaque
|| !ovl_is_whiteout(newdentry
)))
1024 if (olddentry
== trap
)
1026 if (newdentry
== trap
)
1029 if (WARN_ON(olddentry
->d_inode
== newdentry
->d_inode
))
1034 if (ovl_type_merge_or_lower(old
))
1035 err
= ovl_set_redirect(old
, samedir
);
1036 else if (!old_opaque
&& ovl_type_merge(new->d_parent
))
1037 err
= ovl_set_opaque_xerr(old
, olddentry
, -EXDEV
);
1041 if (!overwrite
&& new_is_dir
) {
1042 if (ovl_type_merge_or_lower(new))
1043 err
= ovl_set_redirect(new, samedir
);
1044 else if (!new_opaque
&& ovl_type_merge(old
->d_parent
))
1045 err
= ovl_set_opaque_xerr(new, newdentry
, -EXDEV
);
1050 err
= ovl_do_rename(old_upperdir
->d_inode
, olddentry
,
1051 new_upperdir
->d_inode
, newdentry
, flags
);
1055 if (cleanup_whiteout
)
1056 ovl_cleanup(old_upperdir
->d_inode
, newdentry
);
1058 if (overwrite
&& d_inode(new)) {
1060 clear_nlink(d_inode(new));
1062 drop_nlink(d_inode(new));
1065 ovl_dentry_version_inc(old
->d_parent
, ovl_type_origin(old
) ||
1066 (!overwrite
&& ovl_type_origin(new)));
1067 ovl_dentry_version_inc(new->d_parent
, ovl_type_origin(old
) ||
1068 (d_inode(new) && ovl_type_origin(new)));
1075 unlock_rename(new_upperdir
, old_upperdir
);
1077 revert_creds(old_cred
);
1078 ovl_nlink_end(new, locked
);
1080 ovl_drop_write(old
);
1083 ovl_cache_free(&list
);
1087 const struct inode_operations ovl_dir_inode_operations
= {
1088 .lookup
= ovl_lookup
,
1090 .symlink
= ovl_symlink
,
1091 .unlink
= ovl_unlink
,
1093 .rename
= ovl_rename
,
1095 .setattr
= ovl_setattr
,
1096 .create
= ovl_create
,
1098 .permission
= ovl_permission
,
1099 .getattr
= ovl_getattr
,
1100 .listxattr
= ovl_listxattr
,
1101 .get_acl
= ovl_get_acl
,
1102 .update_time
= ovl_update_time
,