1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2011 Novell Inc.
7 #include <linux/module.h>
9 #include <linux/slab.h>
10 #include <linux/file.h>
11 #include <linux/fileattr.h>
12 #include <linux/splice.h>
13 #include <linux/xattr.h>
14 #include <linux/security.h>
15 #include <linux/uaccess.h>
16 #include <linux/sched/signal.h>
17 #include <linux/cred.h>
18 #include <linux/namei.h>
19 #include <linux/fdtable.h>
20 #include <linux/ratelimit.h>
21 #include <linux/exportfs.h>
22 #include "overlayfs.h"
24 #define OVL_COPY_UP_CHUNK_SIZE (1 << 20)
26 static int ovl_ccup_set(const char *buf, const struct kernel_param *param)
28 pr_warn("\"check_copy_up\" module option is obsolete\n");
32 static int ovl_ccup_get(char *buf, const struct kernel_param *param)
34 return sprintf(buf, "N\n");
37 module_param_call(check_copy_up, ovl_ccup_set, ovl_ccup_get, NULL, 0644);
38 MODULE_PARM_DESC(check_copy_up, "Obsolete; does nothing");
40 static bool ovl_must_copy_xattr(const char *name)
42 return !strcmp(name, XATTR_POSIX_ACL_ACCESS) ||
43 !strcmp(name, XATTR_POSIX_ACL_DEFAULT) ||
44 !strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN);
47 int ovl_copy_xattr(struct super_block *sb, struct dentry *old,
50 ssize_t list_size, size, value_size = 0;
51 char *buf, *name, *value = NULL;
55 if (!(old->d_inode->i_opflags & IOP_XATTR) ||
56 !(new->d_inode->i_opflags & IOP_XATTR))
59 list_size = vfs_listxattr(old, NULL, 0);
61 if (list_size == -EOPNOTSUPP)
66 buf = kvzalloc(list_size, GFP_KERNEL);
70 list_size = vfs_listxattr(old, buf, list_size);
76 for (name = buf; list_size; name += slen) {
77 slen = strnlen(name, list_size) + 1;
79 /* underlying fs providing us with an broken xattr list? */
80 if (WARN_ON(slen > list_size)) {
86 if (ovl_is_private_xattr(sb, name))
89 error = security_inode_copy_up_xattr(name);
90 if (error < 0 && error != -EOPNOTSUPP)
94 continue; /* Discard */
97 size = vfs_getxattr(&init_user_ns, old, name, value, value_size);
99 size = vfs_getxattr(&init_user_ns, old, name, NULL, 0);
106 if (size > value_size) {
109 new = kvmalloc(size, GFP_KERNEL);
120 error = vfs_setxattr(&init_user_ns, new, name, value, size, 0);
122 if (error != -EOPNOTSUPP || ovl_must_copy_xattr(name))
125 /* Ignore failure to copy unknown xattrs */
135 static int ovl_copy_fileattr(struct inode *inode, struct path *old,
138 struct fileattr oldfa = { .flags_valid = true };
139 struct fileattr newfa = { .flags_valid = true };
142 err = ovl_real_fileattr_get(old, &oldfa);
144 /* Ntfs-3g returns -EINVAL for "no fileattr support" */
145 if (err == -ENOTTY || err == -EINVAL)
147 pr_warn("failed to retrieve lower fileattr (%pd2, err=%i)\n",
153 * We cannot set immutable and append-only flags on upper inode,
154 * because we would not be able to link upper inode to upper dir
155 * not set overlay private xattr on upper inode.
156 * Store these flags in overlay.protattr xattr instead.
158 if (oldfa.flags & OVL_PROT_FS_FLAGS_MASK) {
159 err = ovl_set_protattr(inode, new->dentry, &oldfa);
164 /* Don't bother copying flags if none are set */
165 if (!(oldfa.flags & OVL_COPY_FS_FLAGS_MASK))
168 err = ovl_real_fileattr_get(new, &newfa);
170 pr_warn("failed to retrieve upper fileattr (%pd2, err=%i)\n",
175 BUILD_BUG_ON(OVL_COPY_FS_FLAGS_MASK & ~FS_COMMON_FL);
176 newfa.flags &= ~OVL_COPY_FS_FLAGS_MASK;
177 newfa.flags |= (oldfa.flags & OVL_COPY_FS_FLAGS_MASK);
179 BUILD_BUG_ON(OVL_COPY_FSX_FLAGS_MASK & ~FS_XFLAG_COMMON);
180 newfa.fsx_xflags &= ~OVL_COPY_FSX_FLAGS_MASK;
181 newfa.fsx_xflags |= (oldfa.fsx_xflags & OVL_COPY_FSX_FLAGS_MASK);
183 return ovl_real_fileattr_set(new, &newfa);
186 static int ovl_copy_up_data(struct ovl_fs *ofs, struct path *old,
187 struct path *new, loff_t len)
189 struct file *old_file;
190 struct file *new_file;
194 loff_t data_pos = -1;
196 bool skip_hole = false;
202 old_file = ovl_path_open(old, O_LARGEFILE | O_RDONLY);
203 if (IS_ERR(old_file))
204 return PTR_ERR(old_file);
206 new_file = ovl_path_open(new, O_LARGEFILE | O_WRONLY);
207 if (IS_ERR(new_file)) {
208 error = PTR_ERR(new_file);
212 /* Try to use clone_file_range to clone up within the same fs */
213 cloned = do_clone_file_range(old_file, 0, new_file, 0, len, 0);
216 /* Couldn't clone, so now we try to copy the data */
218 /* Check if lower fs supports seek operation */
219 if (old_file->f_mode & FMODE_LSEEK &&
220 old_file->f_op->llseek)
224 size_t this_len = OVL_COPY_UP_CHUNK_SIZE;
230 if (signal_pending_state(TASK_KILLABLE, current)) {
236 * Fill zero for hole will cost unnecessary disk space
237 * and meanwhile slow down the copy-up speed, so we do
238 * an optimization for hole during copy-up, it relies
239 * on SEEK_DATA implementation in lower fs so if lower
240 * fs does not support it, copy-up will behave as before.
242 * Detail logic of hole detection as below:
243 * When we detect next data position is larger than current
244 * position we will skip that hole, otherwise we copy
245 * data in the size of OVL_COPY_UP_CHUNK_SIZE. Actually,
246 * it may not recognize all kind of holes and sometimes
247 * only skips partial of hole area. However, it will be
248 * enough for most of the use cases.
251 if (skip_hole && data_pos < old_pos) {
252 data_pos = vfs_llseek(old_file, old_pos, SEEK_DATA);
253 if (data_pos > old_pos) {
254 hole_len = data_pos - old_pos;
256 old_pos = new_pos = data_pos;
258 } else if (data_pos == -ENXIO) {
260 } else if (data_pos < 0) {
265 bytes = do_splice_direct(old_file, &old_pos,
267 this_len, SPLICE_F_MOVE);
272 WARN_ON(old_pos != new_pos);
277 if (!error && ovl_should_sync(ofs))
278 error = vfs_fsync(new_file, 0);
285 static int ovl_set_size(struct dentry *upperdentry, struct kstat *stat)
287 struct iattr attr = {
288 .ia_valid = ATTR_SIZE,
289 .ia_size = stat->size,
292 return notify_change(&init_user_ns, upperdentry, &attr, NULL);
295 static int ovl_set_timestamps(struct dentry *upperdentry, struct kstat *stat)
297 struct iattr attr = {
299 ATTR_ATIME | ATTR_MTIME | ATTR_ATIME_SET | ATTR_MTIME_SET,
300 .ia_atime = stat->atime,
301 .ia_mtime = stat->mtime,
304 return notify_change(&init_user_ns, upperdentry, &attr, NULL);
307 int ovl_set_attr(struct dentry *upperdentry, struct kstat *stat)
311 if (!S_ISLNK(stat->mode)) {
312 struct iattr attr = {
313 .ia_valid = ATTR_MODE,
314 .ia_mode = stat->mode,
316 err = notify_change(&init_user_ns, upperdentry, &attr, NULL);
319 struct iattr attr = {
320 .ia_valid = ATTR_UID | ATTR_GID,
324 err = notify_change(&init_user_ns, upperdentry, &attr, NULL);
327 ovl_set_timestamps(upperdentry, stat);
332 struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct dentry *real,
337 int buflen = MAX_HANDLE_SZ;
338 uuid_t *uuid = &real->d_sb->s_uuid;
341 /* Make sure the real fid stays 32bit aligned */
342 BUILD_BUG_ON(OVL_FH_FID_OFFSET % 4);
343 BUILD_BUG_ON(MAX_HANDLE_SZ + OVL_FH_FID_OFFSET > 255);
345 fh = kzalloc(buflen + OVL_FH_FID_OFFSET, GFP_KERNEL);
347 return ERR_PTR(-ENOMEM);
350 * We encode a non-connectable file handle for non-dir, because we
351 * only need to find the lower inode number and we don't want to pay
352 * the price or reconnecting the dentry.
354 dwords = buflen >> 2;
355 fh_type = exportfs_encode_fh(real, (void *)fh->fb.fid, &dwords, 0);
356 buflen = (dwords << 2);
359 if (WARN_ON(fh_type < 0) ||
360 WARN_ON(buflen > MAX_HANDLE_SZ) ||
361 WARN_ON(fh_type == FILEID_INVALID))
364 fh->fb.version = OVL_FH_VERSION;
365 fh->fb.magic = OVL_FH_MAGIC;
366 fh->fb.type = fh_type;
367 fh->fb.flags = OVL_FH_FLAG_CPU_ENDIAN;
369 * When we will want to decode an overlay dentry from this handle
370 * and all layers are on the same fs, if we get a disconncted real
371 * dentry when we decode fid, the only way to tell if we should assign
372 * it to upperdentry or to lowerstack is by checking this flag.
375 fh->fb.flags |= OVL_FH_FLAG_PATH_UPPER;
376 fh->fb.len = sizeof(fh->fb) + buflen;
377 if (ofs->config.uuid)
387 int ovl_set_origin(struct ovl_fs *ofs, struct dentry *lower,
388 struct dentry *upper)
390 const struct ovl_fh *fh = NULL;
394 * When lower layer doesn't support export operations store a 'null' fh,
395 * so we can use the overlay.origin xattr to distignuish between a copy
396 * up and a pure upper inode.
398 if (ovl_can_decode_fh(lower->d_sb)) {
399 fh = ovl_encode_real_fh(ofs, lower, false);
405 * Do not fail when upper doesn't support xattrs.
407 err = ovl_check_setxattr(ofs, upper, OVL_XATTR_ORIGIN, fh->buf,
408 fh ? fh->fb.len : 0, 0);
411 /* Ignore -EPERM from setting "user.*" on symlink/special */
412 return err == -EPERM ? 0 : err;
415 /* Store file handle of @upper dir in @index dir entry */
416 static int ovl_set_upper_fh(struct ovl_fs *ofs, struct dentry *upper,
417 struct dentry *index)
419 const struct ovl_fh *fh;
422 fh = ovl_encode_real_fh(ofs, upper, true);
426 err = ovl_do_setxattr(ofs, index, OVL_XATTR_UPPER, fh->buf, fh->fb.len);
433 * Create and install index entry.
435 * Caller must hold i_mutex on indexdir.
437 static int ovl_create_index(struct dentry *dentry, struct dentry *origin,
438 struct dentry *upper)
440 struct ovl_fs *ofs = OVL_FS(dentry->d_sb);
441 struct dentry *indexdir = ovl_indexdir(dentry->d_sb);
442 struct inode *dir = d_inode(indexdir);
443 struct dentry *index = NULL;
444 struct dentry *temp = NULL;
445 struct qstr name = { };
449 * For now this is only used for creating index entry for directories,
450 * because non-dir are copied up directly to index and then hardlinked
453 * TODO: implement create index for non-dir, so we can call it when
454 * encoding file handle for non-dir in case index does not exist.
456 if (WARN_ON(!d_is_dir(dentry)))
459 /* Directory not expected to be indexed before copy up */
460 if (WARN_ON(ovl_test_flag(OVL_INDEX, d_inode(dentry))))
463 err = ovl_get_index_name(ofs, origin, &name);
467 temp = ovl_create_temp(indexdir, OVL_CATTR(S_IFDIR | 0));
472 err = ovl_set_upper_fh(ofs, upper, temp);
476 index = lookup_one_len(name.name, indexdir, name.len);
478 err = PTR_ERR(index);
480 err = ovl_do_rename(dir, temp, dir, index, 0);
485 ovl_cleanup(dir, temp);
492 struct ovl_copy_up_ctx {
493 struct dentry *parent;
494 struct dentry *dentry;
495 struct path lowerpath;
499 struct dentry *destdir;
500 struct qstr destname;
501 struct dentry *workdir;
507 static int ovl_link_up(struct ovl_copy_up_ctx *c)
510 struct dentry *upper;
511 struct dentry *upperdir = ovl_dentry_upper(c->parent);
512 struct inode *udir = d_inode(upperdir);
514 /* Mark parent "impure" because it may now contain non-pure upper */
515 err = ovl_set_impure(c->parent, upperdir);
519 err = ovl_set_nlink_lower(c->dentry);
523 inode_lock_nested(udir, I_MUTEX_PARENT);
524 upper = lookup_one_len(c->dentry->d_name.name, upperdir,
525 c->dentry->d_name.len);
526 err = PTR_ERR(upper);
527 if (!IS_ERR(upper)) {
528 err = ovl_do_link(ovl_dentry_upper(c->dentry), udir, upper);
532 /* Restore timestamps on parent (best effort) */
533 ovl_set_timestamps(upperdir, &c->pstat);
534 ovl_dentry_set_upper_alias(c->dentry);
541 err = ovl_set_nlink_upper(c->dentry);
546 static int ovl_copy_up_inode(struct ovl_copy_up_ctx *c, struct dentry *temp)
548 struct ovl_fs *ofs = OVL_FS(c->dentry->d_sb);
549 struct inode *inode = d_inode(c->dentry);
550 struct path upperpath, datapath;
553 ovl_path_upper(c->dentry, &upperpath);
554 if (WARN_ON(upperpath.dentry != NULL))
557 upperpath.dentry = temp;
560 * Copy up data first and then xattrs. Writing data after
561 * xattrs will remove security.capability xattr automatically.
563 if (S_ISREG(c->stat.mode) && !c->metacopy) {
564 ovl_path_lowerdata(c->dentry, &datapath);
565 err = ovl_copy_up_data(ofs, &datapath, &upperpath,
571 err = ovl_copy_xattr(c->dentry->d_sb, c->lowerpath.dentry, temp);
575 if (inode->i_flags & OVL_COPY_I_FLAGS_MASK) {
577 * Copy the fileattr inode flags that are the source of already
580 err = ovl_copy_fileattr(inode, &c->lowerpath, &upperpath);
586 * Store identifier of lower inode in upper inode xattr to
587 * allow lookup of the copy up origin inode.
589 * Don't set origin when we are breaking the association with a lower
593 err = ovl_set_origin(ofs, c->lowerpath.dentry, temp);
599 err = ovl_check_setxattr(ofs, temp, OVL_XATTR_METACOPY,
600 NULL, 0, -EOPNOTSUPP);
605 inode_lock(temp->d_inode);
606 if (S_ISREG(c->stat.mode))
607 err = ovl_set_size(temp, &c->stat);
609 err = ovl_set_attr(temp, &c->stat);
610 inode_unlock(temp->d_inode);
615 struct ovl_cu_creds {
616 const struct cred *old;
620 static int ovl_prep_cu_creds(struct dentry *dentry, struct ovl_cu_creds *cc)
624 cc->old = cc->new = NULL;
625 err = security_inode_copy_up(dentry, &cc->new);
630 cc->old = override_creds(cc->new);
635 static void ovl_revert_cu_creds(struct ovl_cu_creds *cc)
638 revert_creds(cc->old);
644 * Copyup using workdir to prepare temp file. Used when copying up directories,
645 * special files or when upper fs doesn't support O_TMPFILE.
647 static int ovl_copy_up_workdir(struct ovl_copy_up_ctx *c)
650 struct inode *udir = d_inode(c->destdir), *wdir = d_inode(c->workdir);
651 struct dentry *temp, *upper;
652 struct ovl_cu_creds cc;
654 struct ovl_cattr cattr = {
655 /* Can't properly set mode on creation because of the umask */
656 .mode = c->stat.mode & S_IFMT,
657 .rdev = c->stat.rdev,
661 /* workdir and destdir could be the same when copying up to indexdir */
663 if (lock_rename(c->workdir, c->destdir) != NULL)
666 err = ovl_prep_cu_creds(c->dentry, &cc);
670 temp = ovl_create_temp(c->workdir, &cattr);
671 ovl_revert_cu_creds(&cc);
677 err = ovl_copy_up_inode(c, temp);
681 if (S_ISDIR(c->stat.mode) && c->indexed) {
682 err = ovl_create_index(c->dentry, c->lowerpath.dentry, temp);
687 upper = lookup_one_len(c->destname.name, c->destdir, c->destname.len);
688 err = PTR_ERR(upper);
692 err = ovl_do_rename(wdir, temp, udir, upper, 0);
698 ovl_set_upperdata(d_inode(c->dentry));
699 inode = d_inode(c->dentry);
700 ovl_inode_update(inode, temp);
701 if (S_ISDIR(inode->i_mode))
702 ovl_set_flag(OVL_WHITEOUTS, inode);
704 unlock_rename(c->workdir, c->destdir);
709 ovl_cleanup(wdir, temp);
714 /* Copyup using O_TMPFILE which does not require cross dir locking */
715 static int ovl_copy_up_tmpfile(struct ovl_copy_up_ctx *c)
717 struct inode *udir = d_inode(c->destdir);
718 struct dentry *temp, *upper;
719 struct ovl_cu_creds cc;
722 err = ovl_prep_cu_creds(c->dentry, &cc);
726 temp = ovl_do_tmpfile(c->workdir, c->stat.mode);
727 ovl_revert_cu_creds(&cc);
730 return PTR_ERR(temp);
732 err = ovl_copy_up_inode(c, temp);
736 inode_lock_nested(udir, I_MUTEX_PARENT);
738 upper = lookup_one_len(c->destname.name, c->destdir, c->destname.len);
739 err = PTR_ERR(upper);
740 if (!IS_ERR(upper)) {
741 err = ovl_do_link(temp, udir, upper);
750 ovl_set_upperdata(d_inode(c->dentry));
751 ovl_inode_update(d_inode(c->dentry), temp);
761 * Copy up a single dentry
763 * All renames start with copy up of source if necessary. The actual
764 * rename will only proceed once the copy up was successful. Copy up uses
765 * upper parent i_mutex for exclusion. Since rename can change d_parent it
766 * is possible that the copy up will lock the old parent. At that point
767 * the file will have already been copied up anyway.
769 static int ovl_do_copy_up(struct ovl_copy_up_ctx *c)
772 struct ovl_fs *ofs = OVL_FS(c->dentry->d_sb);
773 bool to_index = false;
776 * Indexed non-dir is copied up directly to the index entry and then
777 * hardlinked to upper dir. Indexed dir is copied up to indexdir,
778 * then index entry is created and then copied up dir installed.
779 * Copying dir up to indexdir instead of workdir simplifies locking.
781 if (ovl_need_index(c->dentry)) {
783 if (S_ISDIR(c->stat.mode))
784 c->workdir = ovl_indexdir(c->dentry->d_sb);
789 if (S_ISDIR(c->stat.mode) || c->stat.nlink == 1 || to_index)
793 c->destdir = ovl_indexdir(c->dentry->d_sb);
794 err = ovl_get_index_name(ofs, c->lowerpath.dentry, &c->destname);
797 } else if (WARN_ON(!c->parent)) {
798 /* Disconnected dentry must be copied up to index dir */
802 * Mark parent "impure" because it may now contain non-pure
805 err = ovl_set_impure(c->parent, c->destdir);
810 /* Should we copyup with O_TMPFILE or with workdir? */
811 if (S_ISREG(c->stat.mode) && ofs->tmpfile)
812 err = ovl_copy_up_tmpfile(c);
814 err = ovl_copy_up_workdir(c);
819 ovl_set_flag(OVL_INDEX, d_inode(c->dentry));
822 /* Initialize nlink for copy up of disconnected dentry */
823 err = ovl_set_nlink_upper(c->dentry);
825 struct inode *udir = d_inode(c->destdir);
827 /* Restore timestamps on parent (best effort) */
829 ovl_set_timestamps(c->destdir, &c->pstat);
832 ovl_dentry_set_upper_alias(c->dentry);
837 kfree(c->destname.name);
841 static bool ovl_need_meta_copy_up(struct dentry *dentry, umode_t mode,
844 struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
846 if (!ofs->config.metacopy)
852 if (flags && ((OPEN_FMODE(flags) & FMODE_WRITE) || (flags & O_TRUNC)))
858 static ssize_t ovl_getxattr(struct dentry *dentry, char *name, char **value)
863 res = vfs_getxattr(&init_user_ns, dentry, name, NULL, 0);
864 if (res == -ENODATA || res == -EOPNOTSUPP)
868 buf = kzalloc(res, GFP_KERNEL);
872 res = vfs_getxattr(&init_user_ns, dentry, name, buf, res);
881 /* Copy up data of an inode which was copied up metadata only in the past. */
882 static int ovl_copy_up_meta_inode_data(struct ovl_copy_up_ctx *c)
884 struct ovl_fs *ofs = OVL_FS(c->dentry->d_sb);
885 struct path upperpath, datapath;
887 char *capability = NULL;
890 ovl_path_upper(c->dentry, &upperpath);
891 if (WARN_ON(upperpath.dentry == NULL))
894 ovl_path_lowerdata(c->dentry, &datapath);
895 if (WARN_ON(datapath.dentry == NULL))
899 err = cap_size = ovl_getxattr(upperpath.dentry, XATTR_NAME_CAPS,
905 err = ovl_copy_up_data(ofs, &datapath, &upperpath, c->stat.size);
910 * Writing to upper file will clear security.capability xattr. We
911 * don't want that to happen for normal copy-up operation.
914 err = vfs_setxattr(&init_user_ns, upperpath.dentry,
915 XATTR_NAME_CAPS, capability, cap_size, 0);
921 err = ovl_do_removexattr(ofs, upperpath.dentry, OVL_XATTR_METACOPY);
925 ovl_set_upperdata(d_inode(c->dentry));
932 static int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry,
936 DEFINE_DELAYED_CALL(done);
937 struct path parentpath;
938 struct ovl_copy_up_ctx ctx = {
941 .workdir = ovl_workdir(dentry),
944 if (WARN_ON(!ctx.workdir))
947 ovl_path_lower(dentry, &ctx.lowerpath);
948 err = vfs_getattr(&ctx.lowerpath, &ctx.stat,
949 STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
953 ctx.metacopy = ovl_need_meta_copy_up(dentry, ctx.stat.mode, flags);
956 ovl_path_upper(parent, &parentpath);
957 ctx.destdir = parentpath.dentry;
958 ctx.destname = dentry->d_name;
960 err = vfs_getattr(&parentpath, &ctx.pstat,
961 STATX_ATIME | STATX_MTIME,
962 AT_STATX_SYNC_AS_STAT);
967 /* maybe truncate regular file. this has no effect on dirs */
971 if (S_ISLNK(ctx.stat.mode)) {
972 ctx.link = vfs_get_link(ctx.lowerpath.dentry, &done);
973 if (IS_ERR(ctx.link))
974 return PTR_ERR(ctx.link);
977 err = ovl_copy_up_start(dentry, flags);
978 /* err < 0: interrupted, err > 0: raced with another copy-up */
983 if (!ovl_dentry_upper(dentry))
984 err = ovl_do_copy_up(&ctx);
985 if (!err && parent && !ovl_dentry_has_upper_alias(dentry))
986 err = ovl_link_up(&ctx);
987 if (!err && ovl_dentry_needs_data_copy_up_locked(dentry, flags))
988 err = ovl_copy_up_meta_inode_data(&ctx);
989 ovl_copy_up_end(dentry);
991 do_delayed_call(&done);
996 static int ovl_copy_up_flags(struct dentry *dentry, int flags)
999 const struct cred *old_cred;
1000 bool disconnected = (dentry->d_flags & DCACHE_DISCONNECTED);
1003 * With NFS export, copy up can get called for a disconnected non-dir.
1004 * In this case, we will copy up lower inode to index dir without
1005 * linking it to upper dir.
1007 if (WARN_ON(disconnected && d_is_dir(dentry)))
1010 old_cred = ovl_override_creds(dentry->d_sb);
1012 struct dentry *next;
1013 struct dentry *parent = NULL;
1015 if (ovl_already_copied_up(dentry, flags))
1018 next = dget(dentry);
1019 /* find the topmost dentry not yet copied up */
1020 for (; !disconnected;) {
1021 parent = dget_parent(next);
1023 if (ovl_dentry_upper(parent))
1030 err = ovl_copy_up_one(parent, next, flags);
1035 revert_creds(old_cred);
1040 static bool ovl_open_need_copy_up(struct dentry *dentry, int flags)
1042 /* Copy up of disconnected dentry does not set upper alias */
1043 if (ovl_already_copied_up(dentry, flags))
1046 if (special_file(d_inode(dentry)->i_mode))
1049 if (!ovl_open_flags_need_copy_up(flags))
1055 int ovl_maybe_copy_up(struct dentry *dentry, int flags)
1059 if (ovl_open_need_copy_up(dentry, flags)) {
1060 err = ovl_want_write(dentry);
1062 err = ovl_copy_up_flags(dentry, flags);
1063 ovl_drop_write(dentry);
1070 int ovl_copy_up_with_data(struct dentry *dentry)
1072 return ovl_copy_up_flags(dentry, O_WRONLY);
1075 int ovl_copy_up(struct dentry *dentry)
1077 return ovl_copy_up_flags(dentry, 0);