1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2011 Novell Inc.
4 * Copyright (C) 2016 Red Hat, Inc.
8 #include <linux/mount.h>
9 #include <linux/slab.h>
10 #include <linux/cred.h>
11 #include <linux/xattr.h>
12 #include <linux/exportfs.h>
13 #include <linux/uuid.h>
14 #include <linux/namei.h>
15 #include <linux/ratelimit.h>
16 #include "overlayfs.h"
18 int ovl_want_write(struct dentry
*dentry
)
20 struct ovl_fs
*ofs
= dentry
->d_sb
->s_fs_info
;
21 return mnt_want_write(ofs
->upper_mnt
);
24 void ovl_drop_write(struct dentry
*dentry
)
26 struct ovl_fs
*ofs
= dentry
->d_sb
->s_fs_info
;
27 mnt_drop_write(ofs
->upper_mnt
);
30 struct dentry
*ovl_workdir(struct dentry
*dentry
)
32 struct ovl_fs
*ofs
= dentry
->d_sb
->s_fs_info
;
36 const struct cred
*ovl_override_creds(struct super_block
*sb
)
38 struct ovl_fs
*ofs
= sb
->s_fs_info
;
40 return override_creds(ofs
->creator_cred
);
44 * Check if underlying fs supports file handles and try to determine encoding
45 * type, in order to deduce maximum inode number used by fs.
47 * Return 0 if file handles are not supported.
48 * Return 1 (FILEID_INO32_GEN) if fs uses the default 32bit inode encoding.
49 * Return -1 if fs uses a non default encoding with unknown inode size.
51 int ovl_can_decode_fh(struct super_block
*sb
)
53 if (!sb
->s_export_op
|| !sb
->s_export_op
->fh_to_dentry
)
56 return sb
->s_export_op
->encode_fh
? -1 : FILEID_INO32_GEN
;
59 struct dentry
*ovl_indexdir(struct super_block
*sb
)
61 struct ovl_fs
*ofs
= sb
->s_fs_info
;
66 /* Index all files on copy up. For now only enabled for NFS export */
67 bool ovl_index_all(struct super_block
*sb
)
69 struct ovl_fs
*ofs
= sb
->s_fs_info
;
71 return ofs
->config
.nfs_export
&& ofs
->config
.index
;
74 /* Verify lower origin on lookup. For now only enabled for NFS export */
75 bool ovl_verify_lower(struct super_block
*sb
)
77 struct ovl_fs
*ofs
= sb
->s_fs_info
;
79 return ofs
->config
.nfs_export
&& ofs
->config
.index
;
82 struct ovl_entry
*ovl_alloc_entry(unsigned int numlower
)
84 size_t size
= offsetof(struct ovl_entry
, lowerstack
[numlower
]);
85 struct ovl_entry
*oe
= kzalloc(size
, GFP_KERNEL
);
88 oe
->numlower
= numlower
;
93 bool ovl_dentry_remote(struct dentry
*dentry
)
95 return dentry
->d_flags
&
96 (DCACHE_OP_REVALIDATE
| DCACHE_OP_WEAK_REVALIDATE
);
99 void ovl_dentry_update_reval(struct dentry
*dentry
, struct dentry
*upperdentry
,
102 struct ovl_entry
*oe
= OVL_E(dentry
);
103 unsigned int i
, flags
= 0;
106 flags
|= upperdentry
->d_flags
;
107 for (i
= 0; i
< oe
->numlower
; i
++)
108 flags
|= oe
->lowerstack
[i
].dentry
->d_flags
;
110 spin_lock(&dentry
->d_lock
);
111 dentry
->d_flags
&= ~mask
;
112 dentry
->d_flags
|= flags
& mask
;
113 spin_unlock(&dentry
->d_lock
);
116 bool ovl_dentry_weird(struct dentry
*dentry
)
118 return dentry
->d_flags
& (DCACHE_NEED_AUTOMOUNT
|
119 DCACHE_MANAGE_TRANSIT
|
124 enum ovl_path_type
ovl_path_type(struct dentry
*dentry
)
126 struct ovl_entry
*oe
= dentry
->d_fsdata
;
127 enum ovl_path_type type
= 0;
129 if (ovl_dentry_upper(dentry
)) {
130 type
= __OVL_PATH_UPPER
;
133 * Non-dir dentry can hold lower dentry of its copy up origin.
136 if (ovl_test_flag(OVL_CONST_INO
, d_inode(dentry
)))
137 type
|= __OVL_PATH_ORIGIN
;
138 if (d_is_dir(dentry
) ||
139 !ovl_has_upperdata(d_inode(dentry
)))
140 type
|= __OVL_PATH_MERGE
;
143 if (oe
->numlower
> 1)
144 type
|= __OVL_PATH_MERGE
;
149 void ovl_path_upper(struct dentry
*dentry
, struct path
*path
)
151 struct ovl_fs
*ofs
= dentry
->d_sb
->s_fs_info
;
153 path
->mnt
= ofs
->upper_mnt
;
154 path
->dentry
= ovl_dentry_upper(dentry
);
157 void ovl_path_lower(struct dentry
*dentry
, struct path
*path
)
159 struct ovl_entry
*oe
= dentry
->d_fsdata
;
162 path
->mnt
= oe
->lowerstack
[0].layer
->mnt
;
163 path
->dentry
= oe
->lowerstack
[0].dentry
;
165 *path
= (struct path
) { };
169 void ovl_path_lowerdata(struct dentry
*dentry
, struct path
*path
)
171 struct ovl_entry
*oe
= dentry
->d_fsdata
;
174 path
->mnt
= oe
->lowerstack
[oe
->numlower
- 1].layer
->mnt
;
175 path
->dentry
= oe
->lowerstack
[oe
->numlower
- 1].dentry
;
177 *path
= (struct path
) { };
181 enum ovl_path_type
ovl_path_real(struct dentry
*dentry
, struct path
*path
)
183 enum ovl_path_type type
= ovl_path_type(dentry
);
185 if (!OVL_TYPE_UPPER(type
))
186 ovl_path_lower(dentry
, path
);
188 ovl_path_upper(dentry
, path
);
193 struct dentry
*ovl_dentry_upper(struct dentry
*dentry
)
195 return ovl_upperdentry_dereference(OVL_I(d_inode(dentry
)));
198 struct dentry
*ovl_dentry_lower(struct dentry
*dentry
)
200 struct ovl_entry
*oe
= dentry
->d_fsdata
;
202 return oe
->numlower
? oe
->lowerstack
[0].dentry
: NULL
;
205 const struct ovl_layer
*ovl_layer_lower(struct dentry
*dentry
)
207 struct ovl_entry
*oe
= dentry
->d_fsdata
;
209 return oe
->numlower
? oe
->lowerstack
[0].layer
: NULL
;
213 * ovl_dentry_lower() could return either a data dentry or metacopy dentry
214 * dependig on what is stored in lowerstack[0]. At times we need to find
215 * lower dentry which has data (and not metacopy dentry). This helper
216 * returns the lower data dentry.
218 struct dentry
*ovl_dentry_lowerdata(struct dentry
*dentry
)
220 struct ovl_entry
*oe
= dentry
->d_fsdata
;
222 return oe
->numlower
? oe
->lowerstack
[oe
->numlower
- 1].dentry
: NULL
;
225 struct dentry
*ovl_dentry_real(struct dentry
*dentry
)
227 return ovl_dentry_upper(dentry
) ?: ovl_dentry_lower(dentry
);
230 struct dentry
*ovl_i_dentry_upper(struct inode
*inode
)
232 return ovl_upperdentry_dereference(OVL_I(inode
));
235 struct inode
*ovl_inode_upper(struct inode
*inode
)
237 struct dentry
*upperdentry
= ovl_i_dentry_upper(inode
);
239 return upperdentry
? d_inode(upperdentry
) : NULL
;
242 struct inode
*ovl_inode_lower(struct inode
*inode
)
244 return OVL_I(inode
)->lower
;
247 struct inode
*ovl_inode_real(struct inode
*inode
)
249 return ovl_inode_upper(inode
) ?: ovl_inode_lower(inode
);
252 /* Return inode which contains lower data. Do not return metacopy */
253 struct inode
*ovl_inode_lowerdata(struct inode
*inode
)
255 if (WARN_ON(!S_ISREG(inode
->i_mode
)))
258 return OVL_I(inode
)->lowerdata
?: ovl_inode_lower(inode
);
261 /* Return real inode which contains data. Does not return metacopy inode */
262 struct inode
*ovl_inode_realdata(struct inode
*inode
)
264 struct inode
*upperinode
;
266 upperinode
= ovl_inode_upper(inode
);
267 if (upperinode
&& ovl_has_upperdata(inode
))
270 return ovl_inode_lowerdata(inode
);
273 struct ovl_dir_cache
*ovl_dir_cache(struct inode
*inode
)
275 return OVL_I(inode
)->cache
;
278 void ovl_set_dir_cache(struct inode
*inode
, struct ovl_dir_cache
*cache
)
280 OVL_I(inode
)->cache
= cache
;
283 void ovl_dentry_set_flag(unsigned long flag
, struct dentry
*dentry
)
285 set_bit(flag
, &OVL_E(dentry
)->flags
);
288 void ovl_dentry_clear_flag(unsigned long flag
, struct dentry
*dentry
)
290 clear_bit(flag
, &OVL_E(dentry
)->flags
);
293 bool ovl_dentry_test_flag(unsigned long flag
, struct dentry
*dentry
)
295 return test_bit(flag
, &OVL_E(dentry
)->flags
);
298 bool ovl_dentry_is_opaque(struct dentry
*dentry
)
300 return ovl_dentry_test_flag(OVL_E_OPAQUE
, dentry
);
303 bool ovl_dentry_is_whiteout(struct dentry
*dentry
)
305 return !dentry
->d_inode
&& ovl_dentry_is_opaque(dentry
);
308 void ovl_dentry_set_opaque(struct dentry
*dentry
)
310 ovl_dentry_set_flag(OVL_E_OPAQUE
, dentry
);
314 * For hard links and decoded file handles, it's possible for ovl_dentry_upper()
315 * to return positive, while there's no actual upper alias for the inode.
316 * Copy up code needs to know about the existence of the upper alias, so it
317 * can't use ovl_dentry_upper().
319 bool ovl_dentry_has_upper_alias(struct dentry
*dentry
)
321 return ovl_dentry_test_flag(OVL_E_UPPER_ALIAS
, dentry
);
324 void ovl_dentry_set_upper_alias(struct dentry
*dentry
)
326 ovl_dentry_set_flag(OVL_E_UPPER_ALIAS
, dentry
);
329 static bool ovl_should_check_upperdata(struct inode
*inode
)
331 if (!S_ISREG(inode
->i_mode
))
334 if (!ovl_inode_lower(inode
))
340 bool ovl_has_upperdata(struct inode
*inode
)
342 if (!ovl_should_check_upperdata(inode
))
345 if (!ovl_test_flag(OVL_UPPERDATA
, inode
))
348 * Pairs with smp_wmb() in ovl_set_upperdata(). Main user of
349 * ovl_has_upperdata() is ovl_copy_up_meta_inode_data(). Make sure
350 * if setting of OVL_UPPERDATA is visible, then effects of writes
351 * before that are visible too.
357 void ovl_set_upperdata(struct inode
*inode
)
360 * Pairs with smp_rmb() in ovl_has_upperdata(). Make sure
361 * if OVL_UPPERDATA flag is visible, then effects of write operations
362 * before it are visible as well.
365 ovl_set_flag(OVL_UPPERDATA
, inode
);
368 /* Caller should hold ovl_inode->lock */
369 bool ovl_dentry_needs_data_copy_up_locked(struct dentry
*dentry
, int flags
)
371 if (!ovl_open_flags_need_copy_up(flags
))
374 return !ovl_test_flag(OVL_UPPERDATA
, d_inode(dentry
));
377 bool ovl_dentry_needs_data_copy_up(struct dentry
*dentry
, int flags
)
379 if (!ovl_open_flags_need_copy_up(flags
))
382 return !ovl_has_upperdata(d_inode(dentry
));
385 bool ovl_redirect_dir(struct super_block
*sb
)
387 struct ovl_fs
*ofs
= sb
->s_fs_info
;
389 return ofs
->config
.redirect_dir
&& !ofs
->noxattr
;
392 const char *ovl_dentry_get_redirect(struct dentry
*dentry
)
394 return OVL_I(d_inode(dentry
))->redirect
;
397 void ovl_dentry_set_redirect(struct dentry
*dentry
, const char *redirect
)
399 struct ovl_inode
*oi
= OVL_I(d_inode(dentry
));
402 oi
->redirect
= redirect
;
405 void ovl_inode_update(struct inode
*inode
, struct dentry
*upperdentry
)
407 struct inode
*upperinode
= d_inode(upperdentry
);
409 WARN_ON(OVL_I(inode
)->__upperdentry
);
412 * Make sure upperdentry is consistent before making it visible
415 OVL_I(inode
)->__upperdentry
= upperdentry
;
416 if (inode_unhashed(inode
)) {
417 inode
->i_private
= upperinode
;
418 __insert_inode_hash(inode
, (unsigned long) upperinode
);
422 static void ovl_dentry_version_inc(struct dentry
*dentry
, bool impurity
)
424 struct inode
*inode
= d_inode(dentry
);
426 WARN_ON(!inode_is_locked(inode
));
428 * Version is used by readdir code to keep cache consistent. For merge
429 * dirs all changes need to be noted. For non-merge dirs, cache only
430 * contains impure (ones which have been copied up and have origins)
431 * entries, so only need to note changes to impure entries.
433 if (OVL_TYPE_MERGE(ovl_path_type(dentry
)) || impurity
)
434 OVL_I(inode
)->version
++;
437 void ovl_dir_modified(struct dentry
*dentry
, bool impurity
)
439 /* Copy mtime/ctime */
440 ovl_copyattr(d_inode(ovl_dentry_upper(dentry
)), d_inode(dentry
));
442 ovl_dentry_version_inc(dentry
, impurity
);
445 u64
ovl_dentry_version_get(struct dentry
*dentry
)
447 struct inode
*inode
= d_inode(dentry
);
449 WARN_ON(!inode_is_locked(inode
));
450 return OVL_I(inode
)->version
;
453 bool ovl_is_whiteout(struct dentry
*dentry
)
455 struct inode
*inode
= dentry
->d_inode
;
457 return inode
&& IS_WHITEOUT(inode
);
460 struct file
*ovl_path_open(struct path
*path
, int flags
)
462 return dentry_open(path
, flags
| O_NOATIME
, current_cred());
465 /* Caller should hold ovl_inode->lock */
466 static bool ovl_already_copied_up_locked(struct dentry
*dentry
, int flags
)
468 bool disconnected
= dentry
->d_flags
& DCACHE_DISCONNECTED
;
470 if (ovl_dentry_upper(dentry
) &&
471 (ovl_dentry_has_upper_alias(dentry
) || disconnected
) &&
472 !ovl_dentry_needs_data_copy_up_locked(dentry
, flags
))
478 bool ovl_already_copied_up(struct dentry
*dentry
, int flags
)
480 bool disconnected
= dentry
->d_flags
& DCACHE_DISCONNECTED
;
483 * Check if copy-up has happened as well as for upper alias (in
484 * case of hard links) is there.
486 * Both checks are lockless:
487 * - false negatives: will recheck under oi->lock
489 * + ovl_dentry_upper() uses memory barriers to ensure the
490 * upper dentry is up-to-date
491 * + ovl_dentry_has_upper_alias() relies on locking of
492 * upper parent i_rwsem to prevent reordering copy-up
495 if (ovl_dentry_upper(dentry
) &&
496 (ovl_dentry_has_upper_alias(dentry
) || disconnected
) &&
497 !ovl_dentry_needs_data_copy_up(dentry
, flags
))
503 int ovl_copy_up_start(struct dentry
*dentry
, int flags
)
505 struct inode
*inode
= d_inode(dentry
);
508 err
= ovl_inode_lock_interruptible(inode
);
509 if (!err
&& ovl_already_copied_up_locked(dentry
, flags
)) {
510 err
= 1; /* Already copied up */
511 ovl_inode_unlock(inode
);
517 void ovl_copy_up_end(struct dentry
*dentry
)
519 ovl_inode_unlock(d_inode(dentry
));
522 bool ovl_check_origin_xattr(struct dentry
*dentry
)
526 res
= vfs_getxattr(dentry
, OVL_XATTR_ORIGIN
, NULL
, 0);
528 /* Zero size value means "copied up but origin unknown" */
535 bool ovl_check_dir_xattr(struct dentry
*dentry
, const char *name
)
540 if (!d_is_dir(dentry
))
543 res
= vfs_getxattr(dentry
, name
, &val
, 1);
544 if (res
== 1 && val
== 'y')
550 int ovl_check_setxattr(struct dentry
*dentry
, struct dentry
*upperdentry
,
551 const char *name
, const void *value
, size_t size
,
555 struct ovl_fs
*ofs
= dentry
->d_sb
->s_fs_info
;
560 err
= ovl_do_setxattr(upperdentry
, name
, value
, size
, 0);
562 if (err
== -EOPNOTSUPP
) {
563 pr_warn("cannot set %s xattr on upper\n", name
);
571 int ovl_set_impure(struct dentry
*dentry
, struct dentry
*upperdentry
)
575 if (ovl_test_flag(OVL_IMPURE
, d_inode(dentry
)))
579 * Do not fail when upper doesn't support xattrs.
580 * Upper inodes won't have origin nor redirect xattr anyway.
582 err
= ovl_check_setxattr(dentry
, upperdentry
, OVL_XATTR_IMPURE
,
585 ovl_set_flag(OVL_IMPURE
, d_inode(dentry
));
590 void ovl_set_flag(unsigned long flag
, struct inode
*inode
)
592 set_bit(flag
, &OVL_I(inode
)->flags
);
595 void ovl_clear_flag(unsigned long flag
, struct inode
*inode
)
597 clear_bit(flag
, &OVL_I(inode
)->flags
);
600 bool ovl_test_flag(unsigned long flag
, struct inode
*inode
)
602 return test_bit(flag
, &OVL_I(inode
)->flags
);
606 * Caller must hold a reference to inode to prevent it from being freed while
607 * it is marked inuse.
609 bool ovl_inuse_trylock(struct dentry
*dentry
)
611 struct inode
*inode
= d_inode(dentry
);
614 spin_lock(&inode
->i_lock
);
615 if (!(inode
->i_state
& I_OVL_INUSE
)) {
616 inode
->i_state
|= I_OVL_INUSE
;
619 spin_unlock(&inode
->i_lock
);
624 void ovl_inuse_unlock(struct dentry
*dentry
)
627 struct inode
*inode
= d_inode(dentry
);
629 spin_lock(&inode
->i_lock
);
630 WARN_ON(!(inode
->i_state
& I_OVL_INUSE
));
631 inode
->i_state
&= ~I_OVL_INUSE
;
632 spin_unlock(&inode
->i_lock
);
636 bool ovl_is_inuse(struct dentry
*dentry
)
638 struct inode
*inode
= d_inode(dentry
);
641 spin_lock(&inode
->i_lock
);
642 inuse
= (inode
->i_state
& I_OVL_INUSE
);
643 spin_unlock(&inode
->i_lock
);
649 * Does this overlay dentry need to be indexed on copy up?
651 bool ovl_need_index(struct dentry
*dentry
)
653 struct dentry
*lower
= ovl_dentry_lower(dentry
);
655 if (!lower
|| !ovl_indexdir(dentry
->d_sb
))
658 /* Index all files for NFS export and consistency verification */
659 if (ovl_index_all(dentry
->d_sb
))
662 /* Index only lower hardlinks on copy up */
663 if (!d_is_dir(lower
) && d_inode(lower
)->i_nlink
> 1)
669 /* Caller must hold OVL_I(inode)->lock */
670 static void ovl_cleanup_index(struct dentry
*dentry
)
672 struct dentry
*indexdir
= ovl_indexdir(dentry
->d_sb
);
673 struct inode
*dir
= indexdir
->d_inode
;
674 struct dentry
*lowerdentry
= ovl_dentry_lower(dentry
);
675 struct dentry
*upperdentry
= ovl_dentry_upper(dentry
);
676 struct dentry
*index
= NULL
;
678 struct qstr name
= { };
681 err
= ovl_get_index_name(lowerdentry
, &name
);
685 inode
= d_inode(upperdentry
);
686 if (!S_ISDIR(inode
->i_mode
) && inode
->i_nlink
!= 1) {
687 pr_warn_ratelimited("cleanup linked index (%pd2, ino=%lu, nlink=%u)\n",
688 upperdentry
, inode
->i_ino
, inode
->i_nlink
);
690 * We either have a bug with persistent union nlink or a lower
691 * hardlink was added while overlay is mounted. Adding a lower
692 * hardlink and then unlinking all overlay hardlinks would drop
693 * overlay nlink to zero before all upper inodes are unlinked.
694 * As a safety measure, when that situation is detected, set
695 * the overlay nlink to the index inode nlink minus one for the
696 * index entry itself.
698 set_nlink(d_inode(dentry
), inode
->i_nlink
- 1);
699 ovl_set_nlink_upper(dentry
);
703 inode_lock_nested(dir
, I_MUTEX_PARENT
);
704 index
= lookup_one_len(name
.name
, indexdir
, name
.len
);
705 err
= PTR_ERR(index
);
708 } else if (ovl_index_all(dentry
->d_sb
)) {
709 /* Whiteout orphan index to block future open by handle */
710 err
= ovl_cleanup_and_whiteout(indexdir
, dir
, index
);
712 /* Cleanup orphan index entries */
713 err
= ovl_cleanup(dir
, index
);
726 pr_err("cleanup index of '%pd2' failed (%i)\n", dentry
, err
);
731 * Operations that change overlay inode and upper inode nlink need to be
732 * synchronized with copy up for persistent nlink accounting.
734 int ovl_nlink_start(struct dentry
*dentry
)
736 struct inode
*inode
= d_inode(dentry
);
737 const struct cred
*old_cred
;
744 * With inodes index is enabled, we store the union overlay nlink
745 * in an xattr on the index inode. When whiting out an indexed lower,
746 * we need to decrement the overlay persistent nlink, but before the
747 * first copy up, we have no upper index inode to store the xattr.
749 * As a workaround, before whiteout/rename over an indexed lower,
750 * copy up to create the upper index. Creating the upper index will
751 * initialize the overlay nlink, so it could be dropped if unlink
752 * or rename succeeds.
754 * TODO: implement metadata only index copy up when called with
755 * ovl_copy_up_flags(dentry, O_PATH).
757 if (ovl_need_index(dentry
) && !ovl_dentry_has_upper_alias(dentry
)) {
758 err
= ovl_copy_up(dentry
);
763 err
= ovl_inode_lock_interruptible(inode
);
767 if (d_is_dir(dentry
) || !ovl_test_flag(OVL_INDEX
, inode
))
770 old_cred
= ovl_override_creds(dentry
->d_sb
);
772 * The overlay inode nlink should be incremented/decremented IFF the
773 * upper operation succeeds, along with nlink change of upper inode.
774 * Therefore, before link/unlink/rename, we store the union nlink
775 * value relative to the upper inode nlink in an upper inode xattr.
777 err
= ovl_set_nlink_upper(dentry
);
778 revert_creds(old_cred
);
782 ovl_inode_unlock(inode
);
787 void ovl_nlink_end(struct dentry
*dentry
)
789 struct inode
*inode
= d_inode(dentry
);
791 if (ovl_test_flag(OVL_INDEX
, inode
) && inode
->i_nlink
== 0) {
792 const struct cred
*old_cred
;
794 old_cred
= ovl_override_creds(dentry
->d_sb
);
795 ovl_cleanup_index(dentry
);
796 revert_creds(old_cred
);
799 ovl_inode_unlock(inode
);
802 int ovl_lock_rename_workdir(struct dentry
*workdir
, struct dentry
*upperdir
)
804 /* Workdir should not be the same as upperdir */
805 if (workdir
== upperdir
)
808 /* Workdir should not be subdir of upperdir and vice versa */
809 if (lock_rename(workdir
, upperdir
) != NULL
)
815 unlock_rename(workdir
, upperdir
);
817 pr_err("failed to lock workdir+upperdir\n");
821 /* err < 0, 0 if no metacopy xattr, 1 if metacopy xattr found */
822 int ovl_check_metacopy_xattr(struct dentry
*dentry
)
826 /* Only regular files can have metacopy xattr */
827 if (!S_ISREG(d_inode(dentry
)->i_mode
))
830 res
= vfs_getxattr(dentry
, OVL_XATTR_METACOPY
, NULL
, 0);
832 if (res
== -ENODATA
|| res
== -EOPNOTSUPP
)
839 pr_warn_ratelimited("failed to get metacopy (%i)\n", res
);
843 bool ovl_is_metacopy_dentry(struct dentry
*dentry
)
845 struct ovl_entry
*oe
= dentry
->d_fsdata
;
847 if (!d_is_reg(dentry
))
850 if (ovl_dentry_upper(dentry
)) {
851 if (!ovl_has_upperdata(d_inode(dentry
)))
856 return (oe
->numlower
> 1);
859 ssize_t
ovl_getxattr(struct dentry
*dentry
, char *name
, char **value
,
865 res
= vfs_getxattr(dentry
, name
, NULL
, 0);
867 if (res
== -ENODATA
|| res
== -EOPNOTSUPP
)
873 buf
= kzalloc(res
+ padding
, GFP_KERNEL
);
877 res
= vfs_getxattr(dentry
, name
, buf
, res
);
886 pr_warn_ratelimited("failed to get xattr %s: err=%zi)\n",
892 char *ovl_get_redirect_xattr(struct dentry
*dentry
, int padding
)
895 char *s
, *next
, *buf
= NULL
;
897 res
= ovl_getxattr(dentry
, OVL_XATTR_REDIRECT
, &buf
, padding
+ 1);
906 for (s
= buf
; *s
++ == '/'; s
= next
) {
907 next
= strchrnul(s
, '/');
912 if (strchr(buf
, '/') != NULL
)
918 pr_warn_ratelimited("invalid redirect (%s)\n", buf
);