Skip to content

Commit 81d1196

Browse files
committed
Merge remote-tracking branch 'stable/linux-6.6.y' into rpi-6.6.y
2 parents 11381ac + 3b4299f commit 81d1196

File tree

7 files changed

+72
-140
lines changed

7 files changed

+72
-140
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0
22
VERSION = 6
33
PATCHLEVEL = 6
4-
SUBLEVEL = 72
4+
SUBLEVEL = 73
55
EXTRAVERSION =
66
NAME = Pinguïn Aangedreven
77

fs/overlayfs/copy_up.c

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,13 @@ int ovl_set_attr(struct ovl_fs *ofs, struct dentry *upperdentry,
371371
return err;
372372
}
373373

374-
struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct inode *realinode,
374+
struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct dentry *real,
375375
bool is_upper)
376376
{
377377
struct ovl_fh *fh;
378378
int fh_type, dwords;
379379
int buflen = MAX_HANDLE_SZ;
380-
uuid_t *uuid = &realinode->i_sb->s_uuid;
380+
uuid_t *uuid = &real->d_sb->s_uuid;
381381
int err;
382382

383383
/* Make sure the real fid stays 32bit aligned */
@@ -394,8 +394,7 @@ struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct inode *realinode,
394394
* the price or reconnecting the dentry.
395395
*/
396396
dwords = buflen >> 2;
397-
fh_type = exportfs_encode_inode_fh(realinode, (void *)fh->fb.fid,
398-
&dwords, NULL, 0);
397+
fh_type = exportfs_encode_fh(real, (void *)fh->fb.fid, &dwords, 0);
399398
buflen = (dwords << 2);
400399

401400
err = -EIO;
@@ -427,29 +426,29 @@ struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct inode *realinode,
427426
return ERR_PTR(err);
428427
}
429428

430-
struct ovl_fh *ovl_get_origin_fh(struct ovl_fs *ofs, struct dentry *origin)
429+
int ovl_set_origin(struct ovl_fs *ofs, struct dentry *lower,
430+
struct dentry *upper)
431431
{
432+
const struct ovl_fh *fh = NULL;
433+
int err;
434+
432435
/*
433436
* When lower layer doesn't support export operations store a 'null' fh,
434437
* so we can use the overlay.origin xattr to distignuish between a copy
435438
* up and a pure upper inode.
436439
*/
437-
if (!ovl_can_decode_fh(origin->d_sb))
438-
return NULL;
439-
440-
return ovl_encode_real_fh(ofs, d_inode(origin), false);
441-
}
442-
443-
int ovl_set_origin_fh(struct ovl_fs *ofs, const struct ovl_fh *fh,
444-
struct dentry *upper)
445-
{
446-
int err;
440+
if (ovl_can_decode_fh(lower->d_sb)) {
441+
fh = ovl_encode_real_fh(ofs, lower, false);
442+
if (IS_ERR(fh))
443+
return PTR_ERR(fh);
444+
}
447445

448446
/*
449447
* Do not fail when upper doesn't support xattrs.
450448
*/
451449
err = ovl_check_setxattr(ofs, upper, OVL_XATTR_ORIGIN, fh->buf,
452450
fh ? fh->fb.len : 0, 0);
451+
kfree(fh);
453452

454453
/* Ignore -EPERM from setting "user.*" on symlink/special */
455454
return err == -EPERM ? 0 : err;
@@ -462,7 +461,7 @@ static int ovl_set_upper_fh(struct ovl_fs *ofs, struct dentry *upper,
462461
const struct ovl_fh *fh;
463462
int err;
464463

465-
fh = ovl_encode_real_fh(ofs, d_inode(upper), true);
464+
fh = ovl_encode_real_fh(ofs, upper, true);
466465
if (IS_ERR(fh))
467466
return PTR_ERR(fh);
468467

@@ -477,7 +476,7 @@ static int ovl_set_upper_fh(struct ovl_fs *ofs, struct dentry *upper,
477476
*
478477
* Caller must hold i_mutex on indexdir.
479478
*/
480-
static int ovl_create_index(struct dentry *dentry, const struct ovl_fh *fh,
479+
static int ovl_create_index(struct dentry *dentry, struct dentry *origin,
481480
struct dentry *upper)
482481
{
483482
struct ovl_fs *ofs = OVL_FS(dentry->d_sb);
@@ -503,7 +502,7 @@ static int ovl_create_index(struct dentry *dentry, const struct ovl_fh *fh,
503502
if (WARN_ON(ovl_test_flag(OVL_INDEX, d_inode(dentry))))
504503
return -EIO;
505504

506-
err = ovl_get_index_name_fh(fh, &name);
505+
err = ovl_get_index_name(ofs, origin, &name);
507506
if (err)
508507
return err;
509508

@@ -542,7 +541,6 @@ struct ovl_copy_up_ctx {
542541
struct dentry *destdir;
543542
struct qstr destname;
544543
struct dentry *workdir;
545-
const struct ovl_fh *origin_fh;
546544
bool origin;
547545
bool indexed;
548546
bool metacopy;
@@ -639,7 +637,7 @@ static int ovl_copy_up_metadata(struct ovl_copy_up_ctx *c, struct dentry *temp)
639637
* hard link.
640638
*/
641639
if (c->origin) {
642-
err = ovl_set_origin_fh(ofs, c->origin_fh, temp);
640+
err = ovl_set_origin(ofs, c->lowerpath.dentry, temp);
643641
if (err)
644642
return err;
645643
}
@@ -751,7 +749,7 @@ static int ovl_copy_up_workdir(struct ovl_copy_up_ctx *c)
751749
goto cleanup;
752750

753751
if (S_ISDIR(c->stat.mode) && c->indexed) {
754-
err = ovl_create_index(c->dentry, c->origin_fh, temp);
752+
err = ovl_create_index(c->dentry, c->lowerpath.dentry, temp);
755753
if (err)
756754
goto cleanup;
757755
}
@@ -863,8 +861,6 @@ static int ovl_do_copy_up(struct ovl_copy_up_ctx *c)
863861
{
864862
int err;
865863
struct ovl_fs *ofs = OVL_FS(c->dentry->d_sb);
866-
struct dentry *origin = c->lowerpath.dentry;
867-
struct ovl_fh *fh = NULL;
868864
bool to_index = false;
869865

870866
/*
@@ -881,33 +877,25 @@ static int ovl_do_copy_up(struct ovl_copy_up_ctx *c)
881877
to_index = true;
882878
}
883879

884-
if (S_ISDIR(c->stat.mode) || c->stat.nlink == 1 || to_index) {
885-
fh = ovl_get_origin_fh(ofs, origin);
886-
if (IS_ERR(fh))
887-
return PTR_ERR(fh);
888-
889-
/* origin_fh may be NULL */
890-
c->origin_fh = fh;
880+
if (S_ISDIR(c->stat.mode) || c->stat.nlink == 1 || to_index)
891881
c->origin = true;
892-
}
893882

894883
if (to_index) {
895884
c->destdir = ovl_indexdir(c->dentry->d_sb);
896-
err = ovl_get_index_name(ofs, origin, &c->destname);
885+
err = ovl_get_index_name(ofs, c->lowerpath.dentry, &c->destname);
897886
if (err)
898-
goto out_free_fh;
887+
return err;
899888
} else if (WARN_ON(!c->parent)) {
900889
/* Disconnected dentry must be copied up to index dir */
901-
err = -EIO;
902-
goto out_free_fh;
890+
return -EIO;
903891
} else {
904892
/*
905893
* Mark parent "impure" because it may now contain non-pure
906894
* upper
907895
*/
908896
err = ovl_set_impure(c->parent, c->destdir);
909897
if (err)
910-
goto out_free_fh;
898+
return err;
911899
}
912900

913901
/* Should we copyup with O_TMPFILE or with workdir? */
@@ -939,8 +927,6 @@ static int ovl_do_copy_up(struct ovl_copy_up_ctx *c)
939927
out:
940928
if (to_index)
941929
kfree(c->destname.name);
942-
out_free_fh:
943-
kfree(fh);
944930
return err;
945931
}
946932

fs/overlayfs/export.c

Lines changed: 22 additions & 27 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,23 +218,14 @@ 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
{
242231
struct ovl_fh *fh = NULL;
@@ -247,13 +236,13 @@ static int ovl_dentry_to_fid(struct ovl_fs *ofs, struct inode *inode,
247236
* Check if we should encode a lower or upper file handle and maybe
248237
* copy up an ancestor to make lower file handle connectable.
249238
*/
250-
err = enc_lower = ovl_check_encode_origin(inode);
239+
err = enc_lower = ovl_check_encode_origin(dentry);
251240
if (enc_lower < 0)
252241
goto fail;
253242

254243
/* Encode an upper or lower file handle */
255-
fh = ovl_encode_real_fh(ofs, enc_lower ? ovl_inode_lower(inode) :
256-
ovl_inode_upper(inode), !enc_lower);
244+
fh = ovl_encode_real_fh(ofs, enc_lower ? ovl_dentry_lower(dentry) :
245+
ovl_dentry_upper(dentry), !enc_lower);
257246
if (IS_ERR(fh))
258247
return PTR_ERR(fh);
259248

@@ -267,22 +256,28 @@ static int ovl_dentry_to_fid(struct ovl_fs *ofs, struct inode *inode,
267256
return err;
268257

269258
fail:
270-
pr_warn_ratelimited("failed to encode file handle (ino=%lu, err=%i)\n",
271-
inode->i_ino, err);
259+
pr_warn_ratelimited("failed to encode file handle (%pd2, err=%i)\n",
260+
dentry, err);
272261
goto out;
273262
}
274263

275264
static int ovl_encode_fh(struct inode *inode, u32 *fid, int *max_len,
276265
struct inode *parent)
277266
{
278267
struct ovl_fs *ofs = OVL_FS(inode->i_sb);
268+
struct dentry *dentry;
279269
int bytes, buflen = *max_len << 2;
280270

281271
/* TODO: encode connectable file handles */
282272
if (parent)
283273
return FILEID_INVALID;
284274

285-
bytes = ovl_dentry_to_fid(ofs, inode, fid, buflen);
275+
dentry = d_find_any_alias(inode);
276+
if (!dentry)
277+
return FILEID_INVALID;
278+
279+
bytes = ovl_dentry_to_fid(ofs, dentry, fid, buflen);
280+
dput(dentry);
286281
if (bytes <= 0)
287282
return FILEID_INVALID;
288283

0 commit comments

Comments
 (0)