[Devel] [PATCH rh7 2/4] overlayfs: introduce d_select_inode dentry operation
Maxim Patlasov
mpatlasov at virtuozzo.com
Tue Jul 26 18:07:01 PDT 2016
The patch is simplified defensive backport of upstream commit
4bacc9c9234c7c8eec44f5ed4e960d9f96fa0f01:
> overlayfs: Make f_path always point to the overlay and f_inode to the underlay
>
> Make file->f_path always point to the overlay dentry so that the path in
> /proc/pid/fd is correct and to ensure that label-based LSMs have access to the
> overlay as well as the underlay (path-based LSMs probably don't need it).
> ...
> Signed-off-by: David Howells <dhowells at redhat.com>
> Signed-off-by: Al Viro <viro at zeniv.linux.org.uk>
Original patch is prone to errors because other parts of linux kernel are not
prepared to such a change of semantics of f_path and f_inode. So, we only backport
simplified d_select_inode keeping f_path and f_inode intact.
https://jira.sw.ru/browse/PSBM-47981
Signed-off-by: Maxim Patlasov <mpatlasov at virtuozzo.com>
---
fs/dcache.c | 5 ++++-
fs/overlayfs/inode.c | 15 +++++++++++++++
fs/overlayfs/overlayfs.h | 1 +
fs/overlayfs/super.c | 2 ++
include/linux/dcache.h | 2 ++
5 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/fs/dcache.c b/fs/dcache.c
index 6433814..7db8aef 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1635,7 +1635,8 @@ void d_set_d_op(struct dentry *dentry, const struct dentry_operations *op)
DCACHE_OP_COMPARE |
DCACHE_OP_REVALIDATE |
DCACHE_OP_WEAK_REVALIDATE |
- DCACHE_OP_DELETE ));
+ DCACHE_OP_DELETE |
+ DCACHE_OP_SELECT_INODE));
dentry->d_op = op;
if (!op)
return;
@@ -1651,6 +1652,8 @@ void d_set_d_op(struct dentry *dentry, const struct dentry_operations *op)
dentry->d_flags |= DCACHE_OP_DELETE;
if (op->d_prune)
dentry->d_flags |= DCACHE_OP_PRUNE;
+ if (op->d_select_inode)
+ dentry->d_flags |= DCACHE_OP_SELECT_INODE;
}
EXPORT_SYMBOL(d_set_d_op);
diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
index 1d2c32f..5fe7acf 100644
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -368,6 +368,21 @@ out:
return err;
}
+struct inode *ovl_d_select_inode(struct dentry *dentry)
+{
+ struct path realpath;
+
+ if (d_is_dir(dentry))
+ return d_backing_inode(dentry);
+
+ ovl_path_real(dentry, &realpath);
+
+ if (realpath.dentry->d_flags & DCACHE_OP_SELECT_INODE)
+ return realpath.dentry->d_op->d_select_inode(realpath.dentry);
+
+ return d_backing_inode(realpath.dentry);
+}
+
static const struct inode_operations_wrapper ovl_file_inode_operations = {
.ops = {
.setattr = ovl_setattr,
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index 45d183b..8da9684 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -173,6 +173,7 @@ ssize_t ovl_getxattr(struct dentry *dentry, const char *name,
void *value, size_t size);
ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size);
int ovl_removexattr(struct dentry *dentry, const char *name);
+struct inode *ovl_d_select_inode(struct dentry *dentry);
struct inode *ovl_new_inode(struct super_block *sb, umode_t mode,
struct ovl_entry *oe);
diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index d5c57b4..24ec90b 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -316,10 +316,12 @@ static int ovl_dentry_weak_revalidate(struct dentry *dentry, unsigned int flags)
static const struct dentry_operations ovl_dentry_operations = {
.d_release = ovl_dentry_release,
+ .d_select_inode = ovl_d_select_inode,
};
static const struct dentry_operations ovl_reval_dentry_operations = {
.d_release = ovl_dentry_release,
+ .d_select_inode = ovl_d_select_inode,
.d_revalidate = ovl_dentry_revalidate,
.d_weak_revalidate = ovl_dentry_weak_revalidate,
};
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index 2f6e4d8..267dbc6 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -160,6 +160,7 @@ struct dentry_operations {
char *(*d_dname)(struct dentry *, char *, int);
struct vfsmount *(*d_automount)(struct path *);
int (*d_manage)(struct dentry *, bool);
+ struct inode *(*d_select_inode)(struct dentry *);
} ____cacheline_aligned;
/*
@@ -221,6 +222,7 @@ struct dentry_operations {
#define DCACHE_FILE_TYPE 0x04000000 /* Other file type */
#define DCACHE_MAY_FREE 0x00800000
+#define DCACHE_OP_SELECT_INODE 0x20000000 /* Unioned entry: dcache op selects inode */
extern seqlock_t rename_lock;
More information about the Devel
mailing list