• Home
  • Raw
  • Download

Lines Matching +full:lower +full:- +full:case

1 // SPDX-License-Identifier: GPL-2.0-only
33 struct ovl_fs *ofs = OVL_FS(d->sb); in ovl_check_redirect()
43 * that will stop further lookup in lower layers (d->stop=true) in ovl_check_redirect()
45 * element and that should force continue lookup in lower in ovl_check_redirect()
46 * layers (reset d->stop). in ovl_check_redirect()
48 d->stop = false; in ovl_check_redirect()
52 memcpy(buf, d->name.name, prelen); in ovl_check_redirect()
56 kfree(d->redirect); in ovl_check_redirect()
57 d->redirect = buf; in ovl_check_redirect()
58 d->name.name = d->redirect; in ovl_check_redirect()
59 d->name.len = strlen(d->redirect); in ovl_check_redirect()
67 * A non-dir origin may be disconnected, which is fine, because in ovl_acceptable()
78 return is_subdir(dentry, ((struct vfsmount *)ctx)->mnt_root); in ovl_acceptable()
85 * Return -ENODATA for "origin unknown".
90 if (fb_len < sizeof(struct ovl_fb) || fb_len < fb->len) in ovl_check_fb_len()
91 return -EINVAL; in ovl_check_fb_len()
93 if (fb->magic != OVL_FH_MAGIC) in ovl_check_fb_len()
94 return -EINVAL; in ovl_check_fb_len()
97 if (fb->version > OVL_FH_VERSION || fb->flags & ~OVL_FH_FLAG_ALL) in ovl_check_fb_len()
98 return -ENODATA; in ovl_check_fb_len()
101 if (!(fb->flags & OVL_FH_FLAG_ANY_ENDIAN) && in ovl_check_fb_len()
102 (fb->flags & OVL_FH_FLAG_BIG_ENDIAN) != OVL_FH_FLAG_CPU_ENDIAN) in ovl_check_fb_len()
103 return -ENODATA; in ovl_check_fb_len()
116 if (res == -ENODATA || res == -EOPNOTSUPP) in ovl_get_fh()
126 return ERR_PTR(-ENOMEM); in ovl_get_fh()
128 res = ovl_do_getxattr(ofs, dentry, ox, fh->buf, res); in ovl_get_fh()
132 err = ovl_check_fb_len(&fh->fb, res); in ovl_get_fh()
134 if (err == -ENODATA) in ovl_get_fh()
160 * Make sure that the stored uuid matches the uuid of the lower in ovl_decode_real_fh()
163 if (!uuid_equal(&fh->fb.uuid, &mnt->mnt_sb->s_uuid)) in ovl_decode_real_fh()
166 bytes = (fh->fb.len - offsetof(struct ovl_fb, fid)); in ovl_decode_real_fh()
167 real = exportfs_decode_fh(mnt, (struct fid *)fh->fb.fid, in ovl_decode_real_fh()
168 bytes >> 2, (int)fh->fb.type, in ovl_decode_real_fh()
172 * Treat stale file handle to lower file as "origin unknown". in ovl_decode_real_fh()
177 if (real == ERR_PTR(-ESTALE) && in ovl_decode_real_fh()
178 !(fh->fb.flags & OVL_FH_FLAG_PATH_UPPER)) in ovl_decode_real_fh()
202 if (!IS_ERR(ret) && d_flags_negative(smp_load_acquire(&ret->d_flags))) { in ovl_lookup_positive_unlocked()
203 if (drop_negative && ret->d_lockref.count == 1) { in ovl_lookup_positive_unlocked()
204 spin_lock(&ret->d_lock); in ovl_lookup_positive_unlocked()
206 if (d_is_negative(ret) && ret->d_lockref.count == 1) in ovl_lookup_positive_unlocked()
208 spin_unlock(&ret->d_lock); in ovl_lookup_positive_unlocked()
211 ret = ERR_PTR(-ENOENT); in ovl_lookup_positive_unlocked()
229 if (err == -ENOENT || err == -ENAMETOOLONG) in ovl_lookup_single()
236 err = -EREMOTE; in ovl_lookup_single()
240 d->stop = d->opaque = true; in ovl_lookup_single()
247 if (last_element && d->metacopy && !d_is_reg(this)) { in ovl_lookup_single()
248 d->stop = true; in ovl_lookup_single()
252 if (d->is_dir || !last_element) { in ovl_lookup_single()
253 d->stop = true; in ovl_lookup_single()
256 err = ovl_check_metacopy_xattr(OVL_FS(d->sb), this); in ovl_lookup_single()
260 d->metacopy = err; in ovl_lookup_single()
261 d->stop = !d->metacopy; in ovl_lookup_single()
262 if (!d->metacopy || d->last) in ovl_lookup_single()
265 if (ovl_lookup_trap_inode(d->sb, this)) { in ovl_lookup_single()
267 err = -ELOOP; in ovl_lookup_single()
272 d->is_dir = true; in ovl_lookup_single()
273 if (d->last) in ovl_lookup_single()
276 if (ovl_is_opaquedir(d->sb, this)) { in ovl_lookup_single()
277 d->stop = true; in ovl_lookup_single()
279 d->opaque = true; in ovl_lookup_single()
304 size_t rem = d->name.len - 1; in ovl_lookup_layer()
308 if (d->name.name[0] != '/') in ovl_lookup_layer()
309 return ovl_lookup_single(base, d, d->name.name, d->name.len, in ovl_lookup_layer()
313 const char *s = d->name.name + d->name.len - rem; in ovl_lookup_layer()
315 size_t thislen = next - s; in ovl_lookup_layer()
319 if (WARN_ON(s[-1] != '/')) in ovl_lookup_layer()
320 return -EIO; in ovl_lookup_layer()
323 d->name.len - rem, next, &base, in ovl_lookup_layer()
332 rem -= thislen + 1; in ovl_lookup_layer()
334 if (WARN_ON(rem >= d->name.len)) in ovl_lookup_layer()
335 return -EIO; in ovl_lookup_layer()
348 for (i = 1; i < ofs->numlayer; i++) { in ovl_check_origin_fh()
350 * If lower fs uuid is not unique among lower fs we cannot match in ovl_check_origin_fh()
351 * fh->uuid to layer. in ovl_check_origin_fh()
353 if (ofs->layers[i].fsid && in ovl_check_origin_fh()
354 ofs->layers[i].fs->bad_uuid) in ovl_check_origin_fh()
357 origin = ovl_decode_real_fh(fh, ofs->layers[i].mnt, in ovl_check_origin_fh()
364 return -ESTALE; in ovl_check_origin_fh()
369 inode_wrong_type(d_inode(upperdentry), d_inode(origin)->i_mode)) in ovl_check_origin_fh()
376 return -ENOMEM; in ovl_check_origin_fh()
380 .layer = &ofs->layers[i] in ovl_check_origin_fh()
387 upperdentry, d_inode(upperdentry)->i_mode & S_IFMT, in ovl_check_origin_fh()
388 d_inode(origin)->i_mode & S_IFMT); in ovl_check_origin_fh()
390 return -EIO; in ovl_check_origin_fh()
406 if (err == -ESTALE) in ovl_check_origin()
416 * Return 0 on match, -ESTALE on mismatch, < 0 on error.
425 return -ENODATA; in ovl_verify_fh()
430 if (fh->fb.len != ofh->fb.len || memcmp(&fh->fb, &ofh->fb, fh->fb.len)) in ovl_verify_fh()
431 err = -ESTALE; in ovl_verify_fh()
443 * Return 0 on match, -ESTALE on mismatch, -ENODATA on no xattr, < 0 on error.
461 if (set && err == -ENODATA) in ovl_verify_set_fh()
462 err = ovl_do_setxattr(ofs, dentry, ox, fh->buf, fh->fb.len); in ovl_verify_set_fh()
474 inode ? inode->i_ino : 0, err); in ovl_verify_set_fh()
495 return upper ?: ERR_PTR(-ESTALE); in ovl_index_upper()
501 return ERR_PTR(-EIO); in ovl_index_upper()
509 * OVL_XATTR_ORIGIN and that origin file handle can be decoded to lower path.
510 * Return 0 on match, -ESTALE on mismatch or stale origin, < 0 on error.
524 err = -EINVAL; in ovl_verify_index()
525 if (index->d_name.len < sizeof(struct ovl_fb)*2) in ovl_verify_index()
528 err = -ENOMEM; in ovl_verify_index()
529 len = index->d_name.len / 2; in ovl_verify_index()
534 err = -EINVAL; in ovl_verify_index()
535 if (hex2bin(fh->buf, index->d_name.name, len)) in ovl_verify_index()
538 err = ovl_check_fb_len(&fh->fb, len); in ovl_verify_index()
554 if (d_is_dir(index) && !ofs->config.nfs_export) in ovl_verify_index()
559 * real upper dir. Non-dir index entries are hardlinks to the upper in ovl_verify_index()
560 * real inode. For non-dir index, we can read the copy up origin xattr in ovl_verify_index()
573 if (err == -ESTALE) in ovl_verify_index()
576 err = -ESTALE; in ovl_verify_index()
585 /* Check if non-dir index is orphan and don't warn before cleaning it */ in ovl_verify_index()
586 if (!d_is_dir(index) && d_inode(index)->i_nlink == 1) { in ovl_verify_index()
602 index, d_inode(index)->i_mode & S_IFMT, err); in ovl_verify_index()
607 index, d_inode(index)->i_mode & S_IFMT, in ovl_verify_index()
608 d_inode(index)->i_nlink); in ovl_verify_index()
609 err = -ENOENT; in ovl_verify_index()
617 n = kcalloc(fh->fb.len, 2, GFP_KERNEL); in ovl_get_index_name_fh()
619 return -ENOMEM; in ovl_get_index_name_fh()
621 s = bin2hex(n, fh->buf, fh->fb.len); in ovl_get_index_name_fh()
622 *name = (struct qstr) QSTR_INIT(n, s - n); in ovl_get_index_name_fh()
629 * Lookup in indexdir for the index entry of a lower real inode or a copy up
630 * origin inode. The index entry name is the hex representation of the lower
633 * If the index dentry in negative, then either no lower aliases have been
669 index = lookup_positive_unlocked(name.name, ofs->indexdir, name.len); in ovl_get_index_fh()
672 if (PTR_ERR(index) == -ENOENT) in ovl_get_index_fh()
678 err = -ESTALE; in ovl_get_index_fh()
680 err = -EIO; in ovl_get_index_fh()
701 index = lookup_positive_unlocked(name.name, ofs->indexdir, name.len); in ovl_lookup_index()
704 if (err == -ENOENT) { in ovl_lookup_index()
709 "overlayfs: mount with '-o index=off' to disable inodes index.\n", in ovl_lookup_index()
710 d_inode(origin)->i_ino, name.len, name.name, in ovl_lookup_index()
724 index = ERR_PTR(-ESTALE); in ovl_lookup_index()
727 inode_wrong_type(inode, d_inode(origin)->i_mode)) { in ovl_lookup_index()
730 * except for the case of a whiteout index. A whiteout in ovl_lookup_index()
731 * index should only exist if all lower aliases have been in ovl_lookup_index()
732 * unlinked, which means that finding a lower origin on lookup in ovl_lookup_index()
736 index, d_inode(index)->i_mode & S_IFMT, in ovl_lookup_index()
737 d_inode(origin)->i_mode & S_IFMT); in ovl_lookup_index()
749 if (err == -ESTALE) { in ovl_lookup_index()
769 index = ERR_PTR(-EIO); in ovl_lookup_index()
775 * Returns -1 if this is the last layer.
779 struct ovl_entry *oe = dentry->d_fsdata; in ovl_path_next()
784 if (path->dentry) in ovl_path_next()
785 return oe->numlower ? 1 : -1; in ovl_path_next()
788 BUG_ON(idx > oe->numlower); in ovl_path_next()
789 path->dentry = oe->lowerstack[idx - 1].dentry; in ovl_path_next()
790 path->mnt = oe->lowerstack[idx - 1].layer->mnt; in ovl_path_next()
792 return (idx < oe->numlower) ? idx + 1 : -1; in ovl_path_next()
797 struct dentry *lower, struct dentry *upper) in ovl_fix_origin() argument
808 err = ovl_set_origin(dentry, lower, upper); in ovl_fix_origin()
810 err = ovl_set_impure(dentry->d_parent, upper->d_parent); in ovl_fix_origin()
821 struct ovl_fs *ofs = dentry->d_sb->s_fs_info; in ovl_lookup()
822 struct ovl_entry *poe = dentry->d_parent->d_fsdata; in ovl_lookup()
823 struct ovl_entry *roe = dentry->d_sb->s_root->d_fsdata; in ovl_lookup()
837 .sb = dentry->d_sb, in ovl_lookup()
838 .name = dentry->d_name, in ovl_lookup()
842 .last = ofs->config.redirect_follow ? false : !poe->numlower, in ovl_lookup()
847 if (dentry->d_name.len > ofs->namelen) in ovl_lookup()
848 return ERR_PTR(-ENAMETOOLONG); in ovl_lookup()
850 old_cred = ovl_override_creds(dentry->d_sb); in ovl_lookup()
851 upperdir = ovl_dentry_upper(dentry->d_parent); in ovl_lookup()
857 if (upperdentry && upperdentry->d_flags & DCACHE_OP_REAL) { in ovl_lookup()
859 err = -EREMOTE; in ovl_lookup()
868 * connected dentry, that is not under any of the lower in ovl_lookup()
870 * number - it's the same as if we held a reference in ovl_lookup()
871 * to a dentry in lower layer that was moved under us. in ovl_lookup()
882 err = -ENOMEM; in ovl_lookup()
892 if (!d.stop && poe->numlower) { in ovl_lookup()
893 err = -ENOMEM; in ovl_lookup()
894 stack = kcalloc(ofs->numlayer - 1, sizeof(struct ovl_path), in ovl_lookup()
900 for (i = 0; !d.stop && i < poe->numlower; i++) { in ovl_lookup()
901 struct ovl_path lower = poe->lowerstack[i]; in ovl_lookup() local
903 if (!ofs->config.redirect_follow) in ovl_lookup()
904 d.last = i == poe->numlower - 1; in ovl_lookup()
906 d.last = lower.layer->idx == roe->numlower; in ovl_lookup()
908 err = ovl_lookup_layer(lower.dentry, &d, &this, false); in ovl_lookup()
915 if ((uppermetacopy || d.metacopy) && !ofs->config.metacopy) { in ovl_lookup()
917 err = -EPERM; in ovl_lookup()
924 * of lower dir and set upper parent "impure". in ovl_lookup()
926 if (upperdentry && !ctr && !ofs->noxattr && d.is_dir) { in ovl_lookup()
936 * lower dir that does not match a stored origin xattr. In any in ovl_lookup()
937 * case, only verified origin is used for index lookup. in ovl_lookup()
939 * For non-dir dentry, if index=on, then ensure origin in ovl_lookup()
944 ((d.is_dir && ovl_verify_lower(dentry->d_sb)) || in ovl_lookup()
945 (!d.is_dir && ofs->config.index && origin_path))) { in ovl_lookup()
959 * lower chain, except top most lower metacopy dentry. in ovl_lookup()
967 stack[ctr].layer = lower.layer; in ovl_lookup()
973 * a symlink into the lower layer without the permission checks. in ovl_lookup()
975 * comes from an USB drive). This can allow a non-readable file in ovl_lookup()
981 err = -EPERM; in ovl_lookup()
982 if (d.redirect && !ofs->config.redirect_follow) { in ovl_lookup()
994 i = lower.layer->idx - 1; in ovl_lookup()
999 * For regular non-metacopy upper dentries, there is no lower in ovl_lookup()
1003 * For metacopy dentry, path based lookup will find lower dentries. in ovl_lookup()
1007 pr_warn_ratelimited("metacopy with no lower data found - abort lookup (%pd2)\n", in ovl_lookup()
1009 err = -EIO; in ovl_lookup()
1013 err = -EIO; in ovl_lookup()
1018 origin = origin_path->dentry; in ovl_lookup()
1023 * Always lookup index if there is no-upperdentry. in ovl_lookup()
1025 * For the case of upperdentry, we have set origin by now if it in ovl_lookup()
1028 * For directories, lookup index by lower inode and verify it matches in ovl_lookup()
1029 * upper inode. We only trust dir index if we verified that lower dir in ovl_lookup()
1035 * based dentry lookup in lower in this case. in ovl_lookup()
1044 if (origin && ovl_indexdir(dentry->d_sb) && in ovl_lookup()
1045 (!d.is_dir || ovl_index_all(dentry->d_sb))) { in ovl_lookup()
1055 err = -ENOMEM; in ovl_lookup()
1059 memcpy(oe->lowerstack, stack, sizeof(struct ovl_path) * ctr); in ovl_lookup()
1060 dentry->d_fsdata = oe; in ovl_lookup()
1089 stack[ctr - 1].dentry : NULL, in ovl_lookup()
1092 inode = ovl_get_inode(dentry->d_sb, &oip); in ovl_lookup()
1105 dput(origin_path->dentry); in ovl_lookup()
1114 dentry->d_fsdata = NULL; in ovl_lookup()
1123 dput(origin_path->dentry); in ovl_lookup()
1136 struct ovl_entry *poe = dentry->d_parent->d_fsdata; in ovl_lower_positive()
1137 const struct qstr *name = &dentry->d_name; in ovl_lower_positive()
1144 * If dentry is negative, then lower is positive iff this is a in ovl_lower_positive()
1147 if (!dentry->d_inode) in ovl_lower_positive()
1150 /* Negative upper -> positive lower */ in ovl_lower_positive()
1154 old_cred = ovl_override_creds(dentry->d_sb); in ovl_lower_positive()
1155 /* Positive upper -> have to look up lower to see whether it exists */ in ovl_lower_positive()
1156 for (i = 0; !done && !positive && i < poe->numlower; i++) { in ovl_lower_positive()
1158 struct dentry *lowerdir = poe->lowerstack[i].dentry; in ovl_lower_positive()
1160 this = lookup_positive_unlocked(name->name, lowerdir, in ovl_lower_positive()
1161 name->len); in ovl_lower_positive()
1164 case -ENOENT: in ovl_lower_positive()
1165 case -ENAMETOOLONG: in ovl_lower_positive()