ovl: Allocate anonymous devs for lowerdirs
PATCH 2/3 ovl: relax same fs constrain for constant st_ino
In reply to Chandan RajendraFrom: Amir Goldstein <[email protected]>
For the case of all layers not on the same fs, use the copy up origin st_ino for non-dir, if we know it.
This guaranties constant and system-wide unique st_ino/st_dev for non-dir across copy up. Like the same fs case, st_ino of non-dir is also persistent. Unlink the same fs case, st_dev is not persistent.
--- fs/overlayfs/inode.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-)
fs/overlayfs/inode.c +21 -15
@@ -82,6 +82,7 @@ int ovl_getattr(const struct path *path, struct kstat *stat,struct path realpath;const struct cred *old_cred;bool is_dir =S_ISDIR (dentry->d_inode->i_mode); +bool samefs =ovl_same_sb (dentry->d_sb);int err; type =ovl_path_real (dentry, &realpath);
@@ -91,16 +92,16 @@ int ovl_getattr(const struct path *path, struct kstat *stat, goto out;/* -* When all layers are on the same fs, all real inode number are -* unique, so we use the overlay st_dev, which is friendly to du -x. -* -* We also use st_ino of the copy up origin, if we know it. -* This guaranties constant st_dev/st_ino across copy up. +* For non-dir or same fs, we use st_ino of the copy up origin, if we +* know it. This guaranties constant st_dev/st_ino across copy up. * * If filesystem supports NFS export ops, this also guaranties * persistent st_ino across mount cycle. +* +* When all layers are on the same fs, all real inode number are +* unique, so we use the overlay st_dev, which is friendly to du -x. */ -if (ovl_same_sb (dentry->d_sb)) { +if (!is_dir || samefs) {if (OVL_TYPE_ORIGIN (type)) {struct kstat lowerstat;u32 lowermask =STATX_INO | (!is_dir ?STATX_NLINK :0 );
@@ -111,7 +112,6 @@ int ovl_getattr(const struct path *path, struct kstat *stat,if (err) goto out; -WARN_ON_ONCE (stat->dev != lowerstat.dev);/* * Lower hardlinks may be broken on copy up to different * upper files, so we cannot use the lower origin st_ino
@@ -123,22 +123,28 @@ int ovl_getattr(const struct path *path, struct kstat *stat,if (is_dir || lowerstat.nlink ==1 ||ovl_test_flag (OVL_INDEX ,d_inode (dentry))) stat->ino = lowerstat.ino; + +if (samefs) +WARN_ON_ONCE (stat->dev != lowerstat.dev); +else + stat->dev = lowerstat.dev; } - stat->dev = dentry->d_sb->s_dev; - }else if (is_dir) { +if (samefs) + stat->dev = dentry->d_sb->s_dev; +else + stat->dev =ovl_get_pseudo_dev (dentry, stat->dev); + }else {/* -* If not all layers are on the same fs the pair {real st_ino; -* overlay st_dev} is not unique, so use the non persistent -* overlay st_ino. -* * Always use the overlay st_dev for directories, so 'find * -xdev' will scan the entire overlay mount and won't cross the * overlay mount boundaries. +* +* If not all layers are on the same fs the pair {real st_ino; +* overlay st_dev} is not unique, so use the non persistent +* overlay st_ino for directories. */ stat->dev = dentry->d_sb->s_dev; stat->ino = dentry->d_inode->i_ino; - }else { - stat->dev =ovl_get_pseudo_dev (dentry, stat->dev); }/*
Signature · 1 line
2.9.5
PATCH 3/3 ovl: Relax same fs constraint for constant d_ino
In reply to Chandan RajendraFor a pure upper dir in a non-samefs setup, ovl_getattr() returns the overlay inode number as the value of st_ino. To keep in line with this behaviour, ovl_fill_real() has been modified to return overlay inode number of the "." entry as the d_ino of a pure upper dir.
--- fs/overlayfs/readdir.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
fs/overlayfs/readdir.c +11 -9
@@ -428,7 +428,6 @@ static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry)* sure that d_ino will be consistent with st_ino from stat(2). */ static int ovl_cache_update_ino (struct path *path,struct ovl_cache_entry *p) - {struct dentry *dir = path->dentry;struct dentry *this =NULL ;
@@ -436,9 +435,6 @@ static int ovl_cache_update_ino(struct path *path, struct ovl_cache_entry *p)u64 ino = p->real_ino;int err =0 ; -if (!ovl_same_sb (dir->d_sb)) - goto out; -if (p->name[0 ] =='.' ) {if (p->len ==1 ) { this =dget (dir);
@@ -470,8 +466,8 @@ static int ovl_cache_update_ino(struct path *path, struct ovl_cache_entry *p) err =vfs_getattr (&statpath, &stat,STATX_INO ,0 );if (err) goto fail; - -WARN_ON_ONCE (dir->d_sb->s_dev != stat.dev); +if (d_is_dir (this) ||ovl_same_sb (this->d_sb)) +WARN_ON_ONCE (dir->d_sb->s_dev != stat.dev); ino = stat.ino; }
@@ -593,6 +589,7 @@ struct ovl_readdir_translate {struct ovl_dir_cache *cache;struct dir_context ctx;u64 parent_ino; +u64 current_ino; }; static int ovl_fill_real(struct dir_context *ctx, const char *name,
@@ -605,6 +602,8 @@ static int ovl_fill_real(struct dir_context *ctx, const char *name,if (rdt->parent_ino &&strcmp (name,".." ) ==0 ) ino = rdt->parent_ino; +else if (rdt->current_ino && namelen ==1 && name[0 ] =='.' ) + ino = rdt->current_ino;else if (rdt->cache) {struct ovl_cache_entry *p;
@@ -645,6 +644,9 @@ static int ovl_iterate_real(struct file *file, struct dir_context *ctx)return PTR_ERR (rdt.cache); } +if (!ovl_same_sb (dir->d_sb)) + rdt.current_ino = dir->d_inode->i_ino; +return iterate_dir (od->realfile, &rdt.ctx); }
@@ -665,9 +667,9 @@ static int ovl_iterate(struct file *file, struct dir_context *ctx)* dir is impure then need to adjust d_ino for copied up * entries. */ -if (ovl_same_sb (dentry->d_sb) && - (ovl_test_flag (OVL_IMPURE ,d_inode (dentry)) || -OVL_TYPE_MERGE (ovl_path_type (dentry->d_parent)))) { +if (ovl_test_flag (OVL_IMPURE ,d_inode (dentry)) || +OVL_TYPE_MERGE (ovl_path_type (dentry->d_parent)) || + !ovl_same_sb (dentry->d_sb)) {return ovl_iterate_real (file, ctx); }return iterate_dir (od->realfile, ctx);
Signature · 1 line
2.9.5
PATCH 1/3 ovl: Allocate anonymous devs for lowerdirs
For stat(2) on lowerdir non-dir entries in non-samefs case, this commit provides unique values for st_dev. The unique values are obtained by allocating anonymous bdevs for each of the lowerdirs in the overlayfs instance.
--- fs/overlayfs/copy_up.c | 1 - fs/overlayfs/inode.c | 18 +++++++++++++ fs/overlayfs/namei.c | 37 +++++++++++++------------- fs/overlayfs/overlayfs.h | 5 ++-- fs/overlayfs/ovl_entry.h | 14 ++++++++-- fs/overlayfs/readdir.c | 4 +-- fs/overlayfs/super.c | 67 ++++++++++++++++++++++++++++++------------------ fs/overlayfs/util.c | 8 ++++-- 8 files changed, 101 insertions(+), 53 deletions(-)
fs/overlayfs/copy_up.c +0 -1
@@ -22,7 +22,6 @@#include <linux/ratelimit.h> #include <linux/exportfs.h> #include "overlayfs.h" -#include "ovl_entry.h" #define OVL_COPY_UP_CHUNK_SIZE (1 << 20)
fs/overlayfs/inode.c +18 -0
@@ -8,6 +8,7 @@*/ #include <linux/fs.h> +#include <linux/mount.h> #include <linux/slab.h> #include <linux/cred.h> #include <linux/xattr.h>
@@ -15,6 +16,21 @@#include <linux/ratelimit.h> #include "overlayfs.h" + +static dev_t ovl_get_pseudo_dev (struct dentry *dentry,dev_t dev) +{ +struct ovl_fs *ofs = dentry->d_sb->s_fs_info; +struct ovl_entry *oe = dentry->d_fsdata; + +if (ofs->upper_mnt && ofs->upper_mnt->mnt_sb->s_dev == dev) +return dev; + +if (oe->numlower) +return oe->lowerstack[0 ].layer->pseudo_dev; + +return dev; +} +int ovl_setattr (struct dentry *dentry,struct iattr *attr) {int err;
@@ -121,6 +137,8 @@ int ovl_getattr(const struct path *path, struct kstat *stat,*/ stat->dev = dentry->d_sb->s_dev; stat->ino = dentry->d_inode->i_ino; + }else { + stat->dev =ovl_get_pseudo_dev (dentry, stat->dev); }/*
fs/overlayfs/namei.c +18 -19
@@ -15,7 +15,6 @@#include <linux/mount.h> #include <linux/exportfs.h> #include "overlayfs.h" -#include "ovl_entry.h" struct ovl_lookup_data {struct qstr name;
@@ -286,16 +285,15 @@ static int ovl_lookup_layer(struct dentry *base, struct ovl_lookup_data *d,static int ovl_check_origin (struct dentry *upperdentry, -struct path *lowerstack,unsigned int numlower, -struct path **stackp,unsigned int *ctrp) +struct ovl_lower *lower,unsigned int numlower, +struct ovl_lower **stackp,unsigned int *ctrp) {struct vfsmount *mnt;struct dentry *origin =NULL ;int i; -for (i =0 ; i < numlower; i++) { - mnt = lowerstack[i].mnt; + mnt = lower[i].layer->mnt; origin =ovl_get_origin (upperdentry, mnt);if (IS_ERR (origin))return PTR_ERR (origin);
@@ -309,12 +307,12 @@ static int ovl_check_origin(struct dentry *upperdentry,BUG_ON (*ctrp);if (!*stackp) - *stackp =kmalloc (sizeof (struct path ),GFP_KERNEL ); + *stackp =kmalloc (sizeof (struct ovl_lower ),GFP_KERNEL );if (!*stackp) {dput (origin);return -ENOMEM ; } - **stackp = (struct path ) { .dentry = origin, .mnt = mnt }; + **stackp = (struct ovl_lower ) { .dentry = origin, .layer = lower[i].layer }; *ctrp =1 ;return 0 ;
@@ -384,13 +382,13 @@ int ovl_verify_origin(struct dentry *dentry, struct vfsmount *mnt,* OVL_XATTR_ORIGIN and that origin file handle can be decoded to lower path. * Return 0 on match, -ESTALE on mismatch or stale origin, < 0 on error. */ -int ovl_verify_index (struct dentry *index,struct path *lowerstack, +int ovl_verify_index (struct dentry *index,struct ovl_lower *lower,unsigned int numlower) {struct ovl_fh *fh =NULL ;size_t len; -struct path origin = { }; -struct path *stack = &origin; +struct ovl_lower origin = { }; +struct ovl_lower *stack = &origin;unsigned int ctr =0 ;int err;
@@ -430,7 +428,7 @@ int ovl_verify_index(struct dentry *index, struct path *lowerstack,if (err) goto fail; - err =ovl_check_origin (index, lowerstack, numlower, &stack, &ctr); + err =ovl_check_origin (index, lower, numlower, &stack, &ctr);if (!err && !ctr) err = -ESTALE ;if (err)
@@ -568,7 +566,8 @@ int ovl_path_next(int idx, struct dentry *dentry, struct path *path) idx++; }BUG_ON (idx > oe->numlower); - *path = oe->lowerstack[idx -1 ]; + path->dentry = oe->lowerstack[idx -1 ].dentry; + path->mnt = oe->lowerstack[idx -1 ].layer->mnt;return (idx < oe->numlower) ? idx +1 :-1 ; }
@@ -581,7 +580,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,struct ovl_fs *ofs = dentry->d_sb->s_fs_info;struct ovl_entry *poe = dentry->d_parent->d_fsdata;struct ovl_entry *roe = dentry->d_sb->s_root->d_fsdata; -struct path *stack =NULL ; +struct ovl_lower *stack =NULL ;struct dentry *upperdir, *upperdentry =NULL ;struct dentry *index =NULL ;unsigned int ctr =0 ;
@@ -645,17 +644,17 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,if (!d.stop && poe->numlower) { err = -ENOMEM ; - stack =kcalloc (ofs->numlower,sizeof (struct path ), + stack =kcalloc (ofs->numlower,sizeof (struct ovl_lower ),GFP_KERNEL );if (!stack) goto out_put_upper; }for (i =0 ; !d.stop && i < poe->numlower; i++) { -struct path lowerpath = poe->lowerstack[i]; +struct ovl_lower lower = poe->lowerstack[i]; d.last = i == poe->numlower -1 ; - err =ovl_lookup_layer (lowerpath.dentry, &d, &this); + err =ovl_lookup_layer (lower.dentry, &d, &this);if (err) goto out_put;
@@ -663,7 +662,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,continue ; stack[ctr].dentry = this; - stack[ctr].mnt = lowerpath.mnt; + stack[ctr].layer = lower.layer; ctr++;if (d.stop)
@@ -674,7 +673,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,/* Find the current layer on the root dentry */ for (i =0 ; i < poe->numlower; i++) -if (poe->lowerstack[i].mnt == lowerpath.mnt) +if (poe->lowerstack[i].layer->mnt == lower.layer->mnt)break ;if (WARN_ON (i == poe->numlower))break ;
@@ -699,7 +698,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, goto out_put; oe->opaque = upperopaque; -memcpy (oe->lowerstack, stack,sizeof (struct path ) * ctr); +memcpy (oe->lowerstack, stack,sizeof (struct ovl_lower ) * ctr); dentry->d_fsdata = oe;if (upperdentry)
fs/overlayfs/overlayfs.h +3 -2
@@ -9,6 +9,7 @@#include <linux/kernel.h> #include <linux/uuid.h> +#include "ovl_entry.h" enum ovl_path_type { __OVL_PATH_UPPER = (1 <<0 ),
@@ -245,7 +246,7 @@ static inline bool ovl_is_impuredir(struct dentry *dentry)/* namei.c */ int ovl_verify_origin (struct dentry *dentry,struct vfsmount *mnt,struct dentry *origin,bool is_upper,bool set); -int ovl_verify_index (struct dentry *index,struct path *lowerstack, +int ovl_verify_index (struct dentry *index,struct ovl_lower *lower,unsigned int numlower);int ovl_get_index_name (struct dentry *origin,struct qstr *name);int ovl_path_next (int idx,struct dentry *dentry,struct path *path);
@@ -262,7 +263,7 @@ int ovl_check_d_type_supported(struct path *realpath);void ovl_workdir_cleanup (struct inode *dir,struct vfsmount *mnt,struct dentry *dentry,int level);int ovl_indexdir_cleanup (struct dentry *dentry,struct vfsmount *mnt, -struct path *lowerstack,unsigned int numlower); +struct ovl_lower *lower,unsigned int numlower);/* inode.c */ int ovl_set_nlink_upper (struct dentry *dentry);
fs/overlayfs/ovl_entry.h +12 -2
@@ -17,11 +17,21 @@ struct ovl_config {bool index; }; +struct ovl_lower_mnt { +struct vfsmount *mnt; +dev_t pseudo_dev; +}; + +struct ovl_lower { +struct ovl_lower_mnt *layer; +struct dentry *dentry; +}; +/* private information held for overlayfs's superblock */ struct ovl_fs {struct vfsmount *upper_mnt;unsigned numlower; -struct vfsmount **lower_mnt; +struct ovl_lower_mnt *lower_mnt;/* workbasedir is the path at workdir= mount option */ struct dentry *workbasedir;/* workdir is the 'work' directory under workbasedir */
@@ -49,7 +59,7 @@ struct ovl_entry {struct rcu_head rcu; };unsigned numlower; -struct path lowerstack[]; +struct ovl_lower lowerstack[]; };struct ovl_entry *ovl_alloc_entry (unsigned int numlower);
fs/overlayfs/readdir.c +2 -2
@@ -985,7 +985,7 @@ void ovl_workdir_cleanup(struct inode *dir, struct vfsmount *mnt, }int ovl_indexdir_cleanup (struct dentry *dentry,struct vfsmount *mnt, -struct path *lowerstack,unsigned int numlower) +struct ovl_lower *lower,unsigned int numlower) {int err;struct inode *dir = dentry->d_inode;
@@ -1020,7 +1020,7 @@ int ovl_indexdir_cleanup(struct dentry *dentry, struct vfsmount *mnt, err =PTR_ERR (index);break ; } - err =ovl_verify_index (index, lowerstack, numlower); + err =ovl_verify_index (index, lower, numlower);if (err) {if (err == -EROFS )break ;
fs/overlayfs/super.c +42 -25
147 lines not on this page · raw message
fs/overlayfs/util.c +6 -2
@@ -17,7 +17,6 @@#include <linux/namei.h> #include <linux/ratelimit.h> #include "overlayfs.h" -#include "ovl_entry.h" int ovl_want_write (struct dentry *dentry) {
@@ -125,7 +124,12 @@ void ovl_path_lower(struct dentry *dentry, struct path *path) {struct ovl_entry *oe = dentry->d_fsdata; - *path = oe->numlower ? oe->lowerstack[0 ] : (struct path ) { }; +if (oe->numlower) { + path->mnt = oe->lowerstack[0 ].layer->mnt; + path->dentry = oe->lowerstack[0 ].dentry; + }else { + *path = (struct path ) { }; + } }enum ovl_path_type ovl_path_real (struct dentry *dentry,struct path *path)
Signature · 1 line
2.9.5