Lines Matching +full:lower +full:- +full:case
1 // SPDX-License-Identifier: GPL-2.0-only
7 * Copyright (C) 2017-2018 CTERA Networks. All Rights Reserved.
41 * Before encoding a non-upper directory file handle from real layer N, we need
43 * lower decoded dentry. This is done by following the overlay ancestry up to a
53 * copied up and renamed, upper dir /a will be indexed by lower dir /a from
56 * dentry from the connected lower dentry /a/b/c.
61 * and when the time comes to decode the file handle from lower dentry /a/b/c,
66 * entry /a in the lower layers above layer N and find the indexed dir /a from
68 * will need to verify there are no redirects in lower layers above N. In the
82 if (dentry == dentry->d_sb->s_root)
87 * lower layer
93 /* We can get upper/overlay path from indexed/lower dentry */
94 return ovl_lowerstack(oe)->layer->idx;
99 * have the same uppermost lower layer as the origin's layer. We may need to
112 if (WARN_ON(dentry == dentry->d_sb->s_root) ||
114 return -EIO;
116 origin_layer = ovl_lowerstack(oe)->layer->idx;
125 err = -EIO;
159 * encoding also after copy up. If non-pure upper is not indexed, then it was
160 * copied up before NFS export was enabled. In that case we don't need to worry
162 * file handle. Overlay root dentry is a private case of non-indexed upper.
168 * --------------------------------
170 * Non-indexed upper | U
172 * Non-upper | L (*)
175 * L = lower file handle
177 * (*) Decoding a connected overlay dir from real lower dentry is not always
178 * possible when there are redirects in lower layers and non-indexed merge dirs.
179 * To mitigate those case, we may copy up the lower dir ancestor before encode
180 * of a decodable file handle for non-upper dir.
182 * Return 0 for upper file handle, > 0 for lower file handle or < 0 on error.
186 struct ovl_fs *ofs = OVL_FS(inode->i_sb);
187 bool decodable = ofs->config.nfs_export;
195 /* Lower file handle for non-upper non-decodable */
207 if (inode == d_inode(inode->i_sb->s_root))
211 * Upper decodable file handle for non-indexed upper.
219 * lower dir or under a non-indexed upper is not always possible.
223 if (!decodable || !S_ISDIR(inode->i_mode))
228 return -ENOENT;
235 /* Lower file handle for indexed and non-upper dir/non-dir */
247 * Check if we should encode a lower or upper file handle and maybe
248 * copy up an ancestor to make lower file handle connectable.
254 /* Encode an upper or lower file handle */
271 inode->i_ino, err);
278 struct ovl_fs *ofs = OVL_FS(inode->i_sb);
304 struct dentry *lower = lowerpath ? lowerpath->dentry : NULL;
314 if (d_is_dir(upper ?: lower))
315 return ERR_PTR(-EIO);
317 oe = ovl_alloc_entry(!!lower);
319 return ERR_PTR(-ENOMEM);
322 if (lower) {
323 ovl_lowerstack(oe)->dentry = dget(lower);
324 ovl_lowerstack(oe)->layer = lowerpath->layer;
341 dentry = d_alloc_anon(inode->i_sb);
354 dentry = ERR_PTR(-ENOMEM);
360 /* Get the upper or lower dentry in stack whose on layer @idx */
371 if (lowerstack[i].layer->idx == idx)
397 * connected overlay dir, we return -ECHILD and restart the lookup of
401 err = -ECHILD;
403 if (ovl_dentry_real_at(connected, layer->idx) != parent)
408 * from racing with underlying layer rename. In this case, we don't
415 * permission checking altogether, but for now just use non-idmap
423 } else if (!this || !this->d_inode) {
425 err = -ENOENT;
427 } else if (ovl_dentry_real_at(this, layer->idx) != real) {
429 err = -ESTALE;
440 real, layer->idx, connected, err);
465 inode = ovl_lookup_inode(sb, real, !layer->idx);
474 * For decoded lower dir file handle, lookup index by origin to check
475 * if lower dir was copied up and and/or removed.
477 if (!this && layer->idx && ofs->indexdir && !WARN_ON(!d_is_dir(real))) {
492 * ovl_lookup_real() in lower layer may call recursively once to
494 * back lower parents to the topmost indexed parent. The second
498 this = ovl_lookup_real(sb, upper, &ofs->layers[0]);
505 if (ovl_dentry_real_at(this, layer->idx) != real) {
507 this = ERR_PTR(-EIO);
522 struct dentry *ancestor = ERR_PTR(-EIO);
524 if (real == layer->mnt->mnt_root)
525 return dget(sb->s_root);
540 if (parent == layer->mnt->mnt_root) {
541 ancestor = dget(sb->s_root);
548 * by legit overlay rename, so we return error in that case.
551 ancestor = ERR_PTR(-EXDEV);
585 layer->idx);
601 * root. In that case, we need to restart connecting.
602 * This game can go on forever in the worst case. We
606 if (parent == layer->mnt->mnt_root) {
608 connected = dget(sb->s_root);
616 * return error in that case.
619 err = -EXDEV;
635 * In this case, we need to restart the lookup from the
642 if (err == -ECHILD) {
664 real, layer->idx, connected, err);
670 * Get an overlay dentry from upper/lower real dentries and index.
678 const struct ovl_layer *layer = upper ? &ofs->layers[0] : lowerpath->layer;
679 struct dentry *real = upper ?: (index ?: lowerpath->dentry);
682 * Obtain a disconnected overlay dentry from a non-dir real dentry
689 if ((real->d_flags & DCACHE_DISCONNECTED) || d_unhashed(real))
690 return ERR_PTR(-ENOENT);
707 return ERR_PTR(-EACCES);
736 !(origin.dentry->d_flags & DCACHE_DISCONNECTED)) {
750 if (ofs->indexdir) {
786 /* Get a connected non-upper dir or disconnected non-dir */
803 /* If on-wire inner fid is aligned - nothing to do */
808 return ERR_PTR(-EINVAL);
811 return ERR_PTR(-EINVAL);
815 return ERR_PTR(-ENOMEM);
818 memcpy(fh->buf, fid, buflen - OVL_FH_WIRE_OFFSET);
840 flags = fh->fb.flags;
845 if (IS_ERR(dentry) && err != -ESTALE)
849 /* We may have needed to re-align OVL_FILEID_V0 */
866 return ERR_PTR(-EACCES);
877 return -EIO;
887 return ERR_PTR(-EIO);
898 /* encode_fh() encodes non-decodable file handles with nfs_export=off */