Skip to content

Commit 950b604

Browse files
committed
Revert "ovl: support encoding fid from inode with no alias"
This reverts commit a1a541f which is commit c45beeb upstream. It is reported to part of a series that causes problems in the 6.6.y tree, so revert it at this point in time and it can come back later if still needed. Reported-by: Ignat Korchagin <ignat@cloudflare.com> Link: https://lore.kernel.org/r/ACD4D6CC-C4D5-4657-A805-03C34559046E@cloudflare.com Cc: Dmitry Safonov <dima@arista.com> Cc: Amir Goldstein <amir73il@gmail.com> Cc: Christian Brauner <brauner@kernel.org> Cc: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c2e4205 commit 950b604

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

fs/overlayfs/export.c

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -181,37 +181,35 @@ static int ovl_connect_layer(struct dentry *dentry)
181181
*
182182
* Return 0 for upper file handle, > 0 for lower file handle or < 0 on error.
183183
*/
184-
static int ovl_check_encode_origin(struct inode *inode)
184+
static int ovl_check_encode_origin(struct dentry *dentry)
185185
{
186-
struct ovl_fs *ofs = OVL_FS(inode->i_sb);
186+
struct ovl_fs *ofs = OVL_FS(dentry->d_sb);
187187
bool decodable = ofs->config.nfs_export;
188-
struct dentry *dentry;
189-
int err;
190188

191189
/* No upper layer? */
192190
if (!ovl_upper_mnt(ofs))
193191
return 1;
194192

195193
/* Lower file handle for non-upper non-decodable */
196-
if (!ovl_inode_upper(inode) && !decodable)
194+
if (!ovl_dentry_upper(dentry) && !decodable)
197195
return 1;
198196

199197
/* Upper file handle for pure upper */
200-
if (!ovl_inode_lower(inode))
198+
if (!ovl_dentry_lower(dentry))
201199
return 0;
202200

203201
/*
204202
* Root is never indexed, so if there's an upper layer, encode upper for
205203
* root.
206204
*/
207-
if (inode == d_inode(inode->i_sb->s_root))
205+
if (dentry == dentry->d_sb->s_root)
208206
return 0;
209207

210208
/*
211209
* Upper decodable file handle for non-indexed upper.
212210
*/
213-
if (ovl_inode_upper(inode) && decodable &&
214-
!ovl_test_flag(OVL_INDEX, inode))
211+
if (ovl_dentry_upper(dentry) && decodable &&
212+
!ovl_test_flag(OVL_INDEX, d_inode(dentry)))
215213
return 0;
216214

217215
/*
@@ -220,25 +218,17 @@ static int ovl_check_encode_origin(struct inode *inode)
220218
* ovl_connect_layer() will try to make origin's layer "connected" by
221219
* copying up a "connectable" ancestor.
222220
*/
223-
if (!decodable || !S_ISDIR(inode->i_mode))
224-
return 1;
225-
226-
dentry = d_find_any_alias(inode);
227-
if (!dentry)
228-
return -ENOENT;
229-
230-
err = ovl_connect_layer(dentry);
231-
dput(dentry);
232-
if (err < 0)
233-
return err;
221+
if (d_is_dir(dentry) && decodable)
222+
return ovl_connect_layer(dentry);
234223

235224
/* Lower file handle for indexed and non-upper dir/non-dir */
236225
return 1;
237226
}
238227

239-
static int ovl_dentry_to_fid(struct ovl_fs *ofs, struct inode *inode,
228+
static int ovl_dentry_to_fid(struct ovl_fs *ofs, struct dentry *dentry,
240229
u32 *fid, int buflen)
241230
{
231+
struct inode *inode = d_inode(dentry);
242232
struct ovl_fh *fh = NULL;
243233
int err, enc_lower;
244234
int len;
@@ -247,7 +237,7 @@ static int ovl_dentry_to_fid(struct ovl_fs *ofs, struct inode *inode,
247237
* Check if we should encode a lower or upper file handle and maybe
248238
* copy up an ancestor to make lower file handle connectable.
249239
*/
250-
err = enc_lower = ovl_check_encode_origin(inode);
240+
err = enc_lower = ovl_check_encode_origin(dentry);
251241
if (enc_lower < 0)
252242
goto fail;
253243

@@ -267,22 +257,28 @@ static int ovl_dentry_to_fid(struct ovl_fs *ofs, struct inode *inode,
267257
return err;
268258

269259
fail:
270-
pr_warn_ratelimited("failed to encode file handle (ino=%lu, err=%i)\n",
271-
inode->i_ino, err);
260+
pr_warn_ratelimited("failed to encode file handle (%pd2, err=%i)\n",
261+
dentry, err);
272262
goto out;
273263
}
274264

275265
static int ovl_encode_fh(struct inode *inode, u32 *fid, int *max_len,
276266
struct inode *parent)
277267
{
278268
struct ovl_fs *ofs = OVL_FS(inode->i_sb);
269+
struct dentry *dentry;
279270
int bytes, buflen = *max_len << 2;
280271

281272
/* TODO: encode connectable file handles */
282273
if (parent)
283274
return FILEID_INVALID;
284275

285-
bytes = ovl_dentry_to_fid(ofs, inode, fid, buflen);
276+
dentry = d_find_any_alias(inode);
277+
if (!dentry)
278+
return FILEID_INVALID;
279+
280+
bytes = ovl_dentry_to_fid(ofs, dentry, fid, buflen);
281+
dput(dentry);
286282
if (bytes <= 0)
287283
return FILEID_INVALID;
288284

0 commit comments

Comments
 (0)