Skip to content

Commit dcb399d

Browse files
committed
ovl: pass ovl_fs to xino helpers
Internal ovl methods should use ovl_fs and not sb as much as possible. Use a constant_table to translate from enum xino mode to string in preperation for new mount api option parsing. Signed-off-by: Amir Goldstein <amir73il@gmail.com>
1 parent 367d002 commit dcb399d

4 files changed

Lines changed: 43 additions & 31 deletions

File tree

fs/overlayfs/inode.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ int ovl_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
9797

9898
static void ovl_map_dev_ino(struct dentry *dentry, struct kstat *stat, int fsid)
9999
{
100-
bool samefs = ovl_same_fs(dentry->d_sb);
101-
unsigned int xinobits = ovl_xino_bits(dentry->d_sb);
100+
struct ovl_fs *ofs = OVL_FS(dentry->d_sb);
101+
bool samefs = ovl_same_fs(ofs);
102+
unsigned int xinobits = ovl_xino_bits(ofs);
102103
unsigned int xinoshift = 64 - xinobits;
103104

104105
if (samefs) {
@@ -123,7 +124,7 @@ static void ovl_map_dev_ino(struct dentry *dentry, struct kstat *stat, int fsid)
123124
stat->ino |= ((u64)fsid) << (xinoshift + 1);
124125
stat->dev = dentry->d_sb->s_dev;
125126
return;
126-
} else if (ovl_xino_warn(dentry->d_sb)) {
127+
} else if (ovl_xino_warn(ofs)) {
127128
pr_warn_ratelimited("inode number too big (%pd2, ino=%llu, xinobits=%d)\n",
128129
dentry, stat->ino, xinobits);
129130
}
@@ -149,7 +150,7 @@ static void ovl_map_dev_ino(struct dentry *dentry, struct kstat *stat, int fsid)
149150
* is unique per underlying fs, so we use the unique anonymous
150151
* bdev assigned to the underlying fs.
151152
*/
152-
stat->dev = OVL_FS(dentry->d_sb)->fs[fsid].pseudo_dev;
153+
stat->dev = ofs->fs[fsid].pseudo_dev;
153154
}
154155
}
155156

@@ -186,7 +187,7 @@ int ovl_getattr(struct mnt_idmap *idmap, const struct path *path,
186187
* If lower filesystem supports NFS file handles, this also guaranties
187188
* persistent st_ino across mount cycle.
188189
*/
189-
if (!is_dir || ovl_same_dev(dentry->d_sb)) {
190+
if (!is_dir || ovl_same_dev(OVL_FS(dentry->d_sb))) {
190191
if (!OVL_TYPE_UPPER(type)) {
191192
fsid = ovl_layer_lower(dentry)->fsid;
192193
} else if (OVL_TYPE_ORIGIN(type)) {
@@ -961,7 +962,7 @@ static inline void ovl_lockdep_annotate_inode_mutex_key(struct inode *inode)
961962

962963
static void ovl_next_ino(struct inode *inode)
963964
{
964-
struct ovl_fs *ofs = inode->i_sb->s_fs_info;
965+
struct ovl_fs *ofs = OVL_FS(inode->i_sb);
965966

966967
inode->i_ino = atomic_long_inc_return(&ofs->last_ino);
967968
if (unlikely(!inode->i_ino))
@@ -970,7 +971,8 @@ static void ovl_next_ino(struct inode *inode)
970971

971972
static void ovl_map_ino(struct inode *inode, unsigned long ino, int fsid)
972973
{
973-
int xinobits = ovl_xino_bits(inode->i_sb);
974+
struct ovl_fs *ofs = OVL_FS(inode->i_sb);
975+
int xinobits = ovl_xino_bits(ofs);
974976
unsigned int xinoshift = 64 - xinobits;
975977

976978
/*
@@ -981,7 +983,7 @@ static void ovl_map_ino(struct inode *inode, unsigned long ino, int fsid)
981983
* with d_ino also causes nfsd readdirplus to fail.
982984
*/
983985
inode->i_ino = ino;
984-
if (ovl_same_fs(inode->i_sb)) {
986+
if (ovl_same_fs(ofs)) {
985987
return;
986988
} else if (xinobits && likely(!(ino >> xinoshift))) {
987989
inode->i_ino |= (unsigned long)fsid << (xinoshift + 1);

fs/overlayfs/overlayfs.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -494,26 +494,26 @@ static inline bool ovl_is_impuredir(struct super_block *sb,
494494
* d_ino consistent with st_ino.
495495
* With xino=on, we do the same effort but we warn if we failed.
496496
*/
497-
static inline bool ovl_xino_warn(struct super_block *sb)
497+
static inline bool ovl_xino_warn(struct ovl_fs *ofs)
498498
{
499-
return OVL_FS(sb)->config.xino == OVL_XINO_ON;
499+
return ofs->config.xino == OVL_XINO_ON;
500500
}
501501

502502
/* All layers on same fs? */
503-
static inline bool ovl_same_fs(struct super_block *sb)
503+
static inline bool ovl_same_fs(struct ovl_fs *ofs)
504504
{
505-
return OVL_FS(sb)->xino_mode == 0;
505+
return ofs->xino_mode == 0;
506506
}
507507

508508
/* All overlay inodes have same st_dev? */
509-
static inline bool ovl_same_dev(struct super_block *sb)
509+
static inline bool ovl_same_dev(struct ovl_fs *ofs)
510510
{
511-
return OVL_FS(sb)->xino_mode >= 0;
511+
return ofs->xino_mode >= 0;
512512
}
513513

514-
static inline unsigned int ovl_xino_bits(struct super_block *sb)
514+
static inline unsigned int ovl_xino_bits(struct ovl_fs *ofs)
515515
{
516-
return ovl_same_dev(sb) ? OVL_FS(sb)->xino_mode : 0;
516+
return ovl_same_dev(ofs) ? ofs->xino_mode : 0;
517517
}
518518

519519
static inline void ovl_inode_lock(struct inode *inode)

fs/overlayfs/readdir.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static bool ovl_calc_d_ino(struct ovl_readdir_data *rdd,
118118
return false;
119119

120120
/* Always recalc d_ino when remapping lower inode numbers */
121-
if (ovl_xino_bits(rdd->dentry->d_sb))
121+
if (ovl_xino_bits(OVL_FS(rdd->dentry->d_sb)))
122122
return true;
123123

124124
/* Always recalc d_ino for parent */
@@ -460,13 +460,14 @@ static int ovl_cache_update_ino(const struct path *path, struct ovl_cache_entry
460460

461461
{
462462
struct dentry *dir = path->dentry;
463+
struct ovl_fs *ofs = OVL_FS(dir->d_sb);
463464
struct dentry *this = NULL;
464465
enum ovl_path_type type;
465466
u64 ino = p->real_ino;
466-
int xinobits = ovl_xino_bits(dir->d_sb);
467+
int xinobits = ovl_xino_bits(ofs);
467468
int err = 0;
468469

469-
if (!ovl_same_dev(dir->d_sb))
470+
if (!ovl_same_dev(ofs))
470471
goto out;
471472

472473
if (p->name[0] == '.') {
@@ -515,7 +516,7 @@ static int ovl_cache_update_ino(const struct path *path, struct ovl_cache_entry
515516
ino = ovl_remap_lower_ino(ino, xinobits,
516517
ovl_layer_lower(this)->fsid,
517518
p->name, p->len,
518-
ovl_xino_warn(dir->d_sb));
519+
ovl_xino_warn(ofs));
519520
}
520521

521522
out:
@@ -694,12 +695,13 @@ static int ovl_iterate_real(struct file *file, struct dir_context *ctx)
694695
int err;
695696
struct ovl_dir_file *od = file->private_data;
696697
struct dentry *dir = file->f_path.dentry;
698+
struct ovl_fs *ofs = OVL_FS(dir->d_sb);
697699
const struct ovl_layer *lower_layer = ovl_layer_lower(dir);
698700
struct ovl_readdir_translate rdt = {
699701
.ctx.actor = ovl_fill_real,
700702
.orig_ctx = ctx,
701-
.xinobits = ovl_xino_bits(dir->d_sb),
702-
.xinowarn = ovl_xino_warn(dir->d_sb),
703+
.xinobits = ovl_xino_bits(ofs),
704+
.xinowarn = ovl_xino_warn(ofs),
703705
};
704706

705707
if (rdt.xinobits && lower_layer)
@@ -735,6 +737,7 @@ static int ovl_iterate(struct file *file, struct dir_context *ctx)
735737
{
736738
struct ovl_dir_file *od = file->private_data;
737739
struct dentry *dentry = file->f_path.dentry;
740+
struct ovl_fs *ofs = OVL_FS(dentry->d_sb);
738741
struct ovl_cache_entry *p;
739742
const struct cred *old_cred;
740743
int err;
@@ -749,8 +752,8 @@ static int ovl_iterate(struct file *file, struct dir_context *ctx)
749752
* dir is impure then need to adjust d_ino for copied up
750753
* entries.
751754
*/
752-
if (ovl_xino_bits(dentry->d_sb) ||
753-
(ovl_same_fs(dentry->d_sb) &&
755+
if (ovl_xino_bits(ofs) ||
756+
(ovl_same_fs(ofs) &&
754757
(ovl_is_impure_dir(file) ||
755758
OVL_TYPE_MERGE(ovl_path_type(dentry->d_parent))))) {
756759
err = ovl_iterate_real(file, ctx);

fs/overlayfs/super.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/posix_acl_xattr.h>
1717
#include <linux/exportfs.h>
1818
#include <linux/file.h>
19+
#include <linux/fs_parser.h>
1920
#include "overlayfs.h"
2021

2122
MODULE_AUTHOR("Miklos Szeredi <miklos@szeredi.hu>");
@@ -334,12 +335,18 @@ static const char *ovl_redirect_mode_def(void)
334335
return ovl_redirect_dir_def ? "on" : "off";
335336
}
336337

337-
static const char * const ovl_xino_str[] = {
338-
"off",
339-
"auto",
340-
"on",
338+
static const struct constant_table ovl_parameter_xino[] = {
339+
{ "off", OVL_XINO_OFF },
340+
{ "auto", OVL_XINO_AUTO },
341+
{ "on", OVL_XINO_ON },
342+
{}
341343
};
342344

345+
static const char *ovl_xino_mode(struct ovl_config *config)
346+
{
347+
return ovl_parameter_xino[config->xino].name;
348+
}
349+
343350
static inline int ovl_xino_def(void)
344351
{
345352
return ovl_xino_auto_def ? OVL_XINO_AUTO : OVL_XINO_OFF;
@@ -374,8 +381,8 @@ static int ovl_show_options(struct seq_file *m, struct dentry *dentry)
374381
if (ofs->config.nfs_export != ovl_nfs_export_def)
375382
seq_printf(m, ",nfs_export=%s", ofs->config.nfs_export ?
376383
"on" : "off");
377-
if (ofs->config.xino != ovl_xino_def() && !ovl_same_fs(sb))
378-
seq_printf(m, ",xino=%s", ovl_xino_str[ofs->config.xino]);
384+
if (ofs->config.xino != ovl_xino_def() && !ovl_same_fs(ofs))
385+
seq_printf(m, ",xino=%s", ovl_xino_mode(&ofs->config));
379386
if (ofs->config.metacopy != ovl_metacopy_def)
380387
seq_printf(m, ",metacopy=%s",
381388
ofs->config.metacopy ? "on" : "off");
@@ -1566,7 +1573,7 @@ static int ovl_get_fsid(struct ovl_fs *ofs, const struct path *path)
15661573
pr_warn("%s uuid detected in lower fs '%pd2', falling back to xino=%s,index=off,nfs_export=off.\n",
15671574
uuid_is_null(&sb->s_uuid) ? "null" :
15681575
"conflicting",
1569-
path->dentry, ovl_xino_str[ofs->config.xino]);
1576+
path->dentry, ovl_xino_mode(&ofs->config));
15701577
}
15711578
}
15721579

0 commit comments

Comments
 (0)