xref: /openbmc/linux/fs/overlayfs/ovl_entry.h (revision b8e42a65)
1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2bbb1e54dSMiklos Szeredi /*
3bbb1e54dSMiklos Szeredi  *
4bbb1e54dSMiklos Szeredi  * Copyright (C) 2011 Novell Inc.
5bbb1e54dSMiklos Szeredi  * Copyright (C) 2016 Red Hat, Inc.
6bbb1e54dSMiklos Szeredi  */
7bbb1e54dSMiklos Szeredi 
8bbb1e54dSMiklos Szeredi struct ovl_config {
9bbb1e54dSMiklos Szeredi 	char *lowerdir;
10bbb1e54dSMiklos Szeredi 	char *upperdir;
11bbb1e54dSMiklos Szeredi 	char *workdir;
12bbb1e54dSMiklos Szeredi 	bool default_permissions;
13a6c60655SMiklos Szeredi 	bool redirect_dir;
14438c84c2SMiklos Szeredi 	bool redirect_follow;
15438c84c2SMiklos Szeredi 	const char *redirect_mode;
1602bcd157SAmir Goldstein 	bool index;
17f168f109SAmir Goldstein 	bool nfs_export;
18795939a9SAmir Goldstein 	int xino;
19d5791044SVivek Goyal 	bool metacopy;
20bbb1e54dSMiklos Szeredi };
21bbb1e54dSMiklos Szeredi 
225148626bSAmir Goldstein struct ovl_sb {
235148626bSAmir Goldstein 	struct super_block *sb;
245148626bSAmir Goldstein 	dev_t pseudo_dev;
257e63c87fSAmir Goldstein 	/* Unusable (conflicting) uuid */
267e63c87fSAmir Goldstein 	bool bad_uuid;
271b81ddddSAmir Goldstein 	/* Used as a lower layer (but maybe also as upper) */
281b81ddddSAmir Goldstein 	bool is_lower;
295148626bSAmir Goldstein };
305148626bSAmir Goldstein 
31b9343632SChandan Rajendra struct ovl_layer {
32b9343632SChandan Rajendra 	struct vfsmount *mnt;
33146d62e5SAmir Goldstein 	/* Trap in ovl inode cache */
34146d62e5SAmir Goldstein 	struct inode *trap;
355148626bSAmir Goldstein 	struct ovl_sb *fs;
365148626bSAmir Goldstein 	/* Index of this layer in fs root (upper idx == 0) */
37d583ed7dSAmir Goldstein 	int idx;
385148626bSAmir Goldstein 	/* One fsid per unique underlying sb (upper fsid == 0) */
395148626bSAmir Goldstein 	int fsid;
40b9343632SChandan Rajendra };
41b9343632SChandan Rajendra 
42b9343632SChandan Rajendra struct ovl_path {
4313464165SMiklos Szeredi 	const struct ovl_layer *layer;
44b9343632SChandan Rajendra 	struct dentry *dentry;
45b9343632SChandan Rajendra };
46b9343632SChandan Rajendra 
47bbb1e54dSMiklos Szeredi /* private information held for overlayfs's superblock */
48bbb1e54dSMiklos Szeredi struct ovl_fs {
4994375f9dSAmir Goldstein 	unsigned int numlayer;
5007f1e596SAmir Goldstein 	/* Number of unique fs among layers including upper fs */
5107f1e596SAmir Goldstein 	unsigned int numfs;
5213464165SMiklos Szeredi 	const struct ovl_layer *layers;
5307f1e596SAmir Goldstein 	struct ovl_sb *fs;
542cac0c00SAmir Goldstein 	/* workbasedir is the path at workdir= mount option */
552cac0c00SAmir Goldstein 	struct dentry *workbasedir;
562cac0c00SAmir Goldstein 	/* workdir is the 'work' directory under workbasedir */
57bbb1e54dSMiklos Szeredi 	struct dentry *workdir;
5802bcd157SAmir Goldstein 	/* index directory listing overlay inodes by origin file handle */
5902bcd157SAmir Goldstein 	struct dentry *indexdir;
606b2d5fe4SMiklos Szeredi 	long namelen;
61bbb1e54dSMiklos Szeredi 	/* pathnames of lower and upper dirs, for show_options */
62bbb1e54dSMiklos Szeredi 	struct ovl_config config;
63bbb1e54dSMiklos Szeredi 	/* creds of process who forced instantiation of super block */
64bbb1e54dSMiklos Szeredi 	const struct cred *creator_cred;
65e7f52429SAmir Goldstein 	bool tmpfile;
6682b749b2SAmir Goldstein 	bool noxattr;
6785fdee1eSAmir Goldstein 	/* Did we take the inuse lock? */
6885fdee1eSAmir Goldstein 	bool upperdir_locked;
6985fdee1eSAmir Goldstein 	bool workdir_locked;
70c21c839bSChengguang Xu 	bool share_whiteout;
71146d62e5SAmir Goldstein 	/* Traps in ovl inode cache */
720be0bfd2SAmir Goldstein 	struct inode *workbasedir_trap;
73146d62e5SAmir Goldstein 	struct inode *workdir_trap;
74146d62e5SAmir Goldstein 	struct inode *indexdir_trap;
750f831ec8SAmir Goldstein 	/* -1: disabled, 0: same fs, 1..32: number of unused ino bits */
760f831ec8SAmir Goldstein 	int xino_mode;
774d314f78SAmir Goldstein 	/* For allocation of non-persistent inode numbers */
784d314f78SAmir Goldstein 	atomic_long_t last_ino;
79c21c839bSChengguang Xu 	/* Whiteout dentry cache */
80c21c839bSChengguang Xu 	struct dentry *whiteout;
81bbb1e54dSMiklos Szeredi };
82bbb1e54dSMiklos Szeredi 
8308f4c7c8SMiklos Szeredi static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
8408f4c7c8SMiklos Szeredi {
85b8e42a65SMiklos Szeredi 	return ofs->layers[0].mnt;
8608f4c7c8SMiklos Szeredi }
8708f4c7c8SMiklos Szeredi 
880f831ec8SAmir Goldstein static inline struct ovl_fs *OVL_FS(struct super_block *sb)
890f831ec8SAmir Goldstein {
900f831ec8SAmir Goldstein 	return (struct ovl_fs *)sb->s_fs_info;
910f831ec8SAmir Goldstein }
920f831ec8SAmir Goldstein 
93bbb1e54dSMiklos Szeredi /* private information held for every overlayfs dentry */
94bbb1e54dSMiklos Szeredi struct ovl_entry {
95bbb1e54dSMiklos Szeredi 	union {
9655acc661SMiklos Szeredi 		struct {
97c62520a8SAmir Goldstein 			unsigned long flags;
9855acc661SMiklos Szeredi 		};
99bbb1e54dSMiklos Szeredi 		struct rcu_head rcu;
100bbb1e54dSMiklos Szeredi 	};
101bbb1e54dSMiklos Szeredi 	unsigned numlower;
102b9343632SChandan Rajendra 	struct ovl_path lowerstack[];
103bbb1e54dSMiklos Szeredi };
104bbb1e54dSMiklos Szeredi 
105bbb1e54dSMiklos Szeredi struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
106bbb1e54dSMiklos Szeredi 
107c62520a8SAmir Goldstein static inline struct ovl_entry *OVL_E(struct dentry *dentry)
108c62520a8SAmir Goldstein {
109c62520a8SAmir Goldstein 	return (struct ovl_entry *) dentry->d_fsdata;
110c62520a8SAmir Goldstein }
111c62520a8SAmir Goldstein 
11213cf199dSAmir Goldstein struct ovl_inode {
1132664bd08SVivek Goyal 	union {
1142664bd08SVivek Goyal 		struct ovl_dir_cache *cache;	/* directory */
1152664bd08SVivek Goyal 		struct inode *lowerdata;	/* regular file */
1162664bd08SVivek Goyal 	};
117cf31c463SMiklos Szeredi 	const char *redirect;
11804a01ac7SMiklos Szeredi 	u64 version;
11913c72075SMiklos Szeredi 	unsigned long flags;
12013cf199dSAmir Goldstein 	struct inode vfs_inode;
12109d8b586SMiklos Szeredi 	struct dentry *__upperdentry;
12225b7713aSMiklos Szeredi 	struct inode *lower;
123a015dafcSAmir Goldstein 
124a015dafcSAmir Goldstein 	/* synchronize copy up and more */
125a015dafcSAmir Goldstein 	struct mutex lock;
12613cf199dSAmir Goldstein };
12713cf199dSAmir Goldstein 
12813cf199dSAmir Goldstein static inline struct ovl_inode *OVL_I(struct inode *inode)
12913cf199dSAmir Goldstein {
13013cf199dSAmir Goldstein 	return container_of(inode, struct ovl_inode, vfs_inode);
13113cf199dSAmir Goldstein }
13209d8b586SMiklos Szeredi 
13309d8b586SMiklos Szeredi static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
13409d8b586SMiklos Szeredi {
135506458efSWill Deacon 	return READ_ONCE(oi->__upperdentry);
13609d8b586SMiklos Szeredi }
137