Skip to content

Commit 926e94d

Browse files
amir73ilMiklos Szeredi
authored andcommitted
ovl: enable xino automatically in more cases
So far, with xino=auto, we only enable xino if we know that all underlying filesystem use 32bit inode numbers. When users configure overlay with xino=auto, they already declare that they are ready to handle 64bit inode number from overlay. It is a very common case, that underlying filesystem uses 64bit ino, but rarely or never uses the high inode number bits (e.g. tmpfs, xfs). Leaving it for the users to declare high ino bits are unused with xino=on is not a recipe for many users to enjoy the benefits of xino. There appears to be very little reason not to enable xino when users declare xino=auto even if we do not know how many bits underlying filesystem uses for inode numbers. In the worst case of xino bits overflow by real inode number, we already fall back to the non-xino behavior - real inode number with unique pseudo dev or to non persistent inode number and overlay st_dev (for directories). The only annoyance from auto enabling xino is that xino bits overflow emits a warning to kmsg. Suppress those warnings unless users explicitly asked for xino=on, suggesting that they expected high ino bits to be unused by underlying filesystem. Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent dfe51d4 commit 926e94d

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

fs/overlayfs/inode.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ static int ovl_map_dev_ino(struct dentry *dentry, struct kstat *stat, int fsid)
9999
* This way all overlay inode numbers are unique and use the
100100
* overlay st_dev.
101101
*/
102-
if (unlikely(stat->ino >> xinoshift)) {
103-
pr_warn_ratelimited("inode number too big (%pd2, ino=%llu, xinobits=%d)\n",
104-
dentry, stat->ino, xinobits);
105-
} else {
102+
if (likely(!(stat->ino >> xinoshift))) {
106103
stat->ino |= ((u64)fsid) << (xinoshift + 1);
107104
stat->dev = dentry->d_sb->s_dev;
108105
return 0;
106+
} else if (ovl_xino_warn(dentry->d_sb)) {
107+
pr_warn_ratelimited("inode number too big (%pd2, ino=%llu, xinobits=%d)\n",
108+
dentry, stat->ino, xinobits);
109109
}
110110
}
111111

fs/overlayfs/overlayfs.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ enum ovl_entry_flag {
4848
OVL_E_CONNECTED,
4949
};
5050

51+
enum {
52+
OVL_XINO_OFF,
53+
OVL_XINO_AUTO,
54+
OVL_XINO_ON,
55+
};
56+
5157
/*
5258
* The tuple (fh,uuid) is a universal unique identifier for a copy up origin,
5359
* where:
@@ -301,6 +307,16 @@ static inline bool ovl_is_impuredir(struct dentry *dentry)
301307
return ovl_check_dir_xattr(dentry, OVL_XATTR_IMPURE);
302308
}
303309

310+
/*
311+
* With xino=auto, we do best effort to keep all inodes on same st_dev and
312+
* d_ino consistent with st_ino.
313+
* With xino=on, we do the same effort but we warn if we failed.
314+
*/
315+
static inline bool ovl_xino_warn(struct super_block *sb)
316+
{
317+
return OVL_FS(sb)->config.xino == OVL_XINO_ON;
318+
}
319+
304320
/* All layers on same fs? */
305321
static inline bool ovl_same_fs(struct super_block *sb)
306322
{

fs/overlayfs/readdir.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,15 @@ static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry)
438438

439439
/* Map inode number to lower fs unique range */
440440
static u64 ovl_remap_lower_ino(u64 ino, int xinobits, int fsid,
441-
const char *name, int namelen)
441+
const char *name, int namelen, bool warn)
442442
{
443443
unsigned int xinoshift = 64 - xinobits;
444444

445445
if (unlikely(ino >> xinoshift)) {
446-
pr_warn_ratelimited("d_ino too big (%.*s, ino=%llu, xinobits=%d)\n",
447-
namelen, name, ino, xinobits);
446+
if (warn) {
447+
pr_warn_ratelimited("d_ino too big (%.*s, ino=%llu, xinobits=%d)\n",
448+
namelen, name, ino, xinobits);
449+
}
448450
return ino;
449451
}
450452

@@ -521,7 +523,8 @@ static int ovl_cache_update_ino(struct path *path, struct ovl_cache_entry *p)
521523
} else if (xinobits && !OVL_TYPE_UPPER(type)) {
522524
ino = ovl_remap_lower_ino(ino, xinobits,
523525
ovl_layer_lower(this)->fsid,
524-
p->name, p->len);
526+
p->name, p->len,
527+
ovl_xino_warn(dir->d_sb));
525528
}
526529

527530
out:
@@ -651,6 +654,7 @@ struct ovl_readdir_translate {
651654
u64 parent_ino;
652655
int fsid;
653656
int xinobits;
657+
bool xinowarn;
654658
};
655659

656660
static int ovl_fill_real(struct dir_context *ctx, const char *name,
@@ -671,7 +675,7 @@ static int ovl_fill_real(struct dir_context *ctx, const char *name,
671675
ino = p->ino;
672676
} else if (rdt->xinobits) {
673677
ino = ovl_remap_lower_ino(ino, rdt->xinobits, rdt->fsid,
674-
name, namelen);
678+
name, namelen, rdt->xinowarn);
675679
}
676680

677681
return orig_ctx->actor(orig_ctx, name, namelen, offset, ino, d_type);
@@ -702,6 +706,7 @@ static int ovl_iterate_real(struct file *file, struct dir_context *ctx)
702706
.ctx.actor = ovl_fill_real,
703707
.orig_ctx = ctx,
704708
.xinobits = ovl_xino_bits(dir->d_sb),
709+
.xinowarn = ovl_xino_warn(dir->d_sb),
705710
};
706711

707712
if (rdt.xinobits && lower_layer)

fs/overlayfs/super.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,6 @@ static const char *ovl_redirect_mode_def(void)
317317
return ovl_redirect_dir_def ? "on" : "off";
318318
}
319319

320-
enum {
321-
OVL_XINO_OFF,
322-
OVL_XINO_AUTO,
323-
OVL_XINO_ON,
324-
};
325-
326320
static const char * const ovl_xino_str[] = {
327321
"off",
328322
"auto",
@@ -1479,8 +1473,8 @@ static int ovl_get_layers(struct super_block *sb, struct ovl_fs *ofs,
14791473

14801474
/*
14811475
* When all layers on same fs, overlay can use real inode numbers.
1482-
* With mount option "xino=on", mounter declares that there are enough
1483-
* free high bits in underlying fs to hold the unique fsid.
1476+
* With mount option "xino=<on|auto>", mounter declares that there are
1477+
* enough free high bits in underlying fs to hold the unique fsid.
14841478
* If overlayfs does encounter underlying inodes using the high xino
14851479
* bits reserved for fsid, it emits a warning and uses the original
14861480
* inode number or a non persistent inode number allocated from a
@@ -1492,7 +1486,7 @@ static int ovl_get_layers(struct super_block *sb, struct ovl_fs *ofs,
14921486
ofs->xino_mode = 0;
14931487
} else if (ofs->config.xino == OVL_XINO_OFF) {
14941488
ofs->xino_mode = -1;
1495-
} else if (ofs->config.xino == OVL_XINO_ON && ofs->xino_mode < 0) {
1489+
} else if (ofs->xino_mode < 0) {
14961490
/*
14971491
* This is a roundup of number of bits needed for encoding
14981492
* fsid, where fsid 0 is reserved for upper fs (even with

0 commit comments

Comments
 (0)