xref: /openbmc/linux/fs/overlayfs/ovl_entry.h (revision 4d314f78)
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 {
49bbb1e54dSMiklos Szeredi 	struct vfsmount *upper_mnt;
5094375f9dSAmir Goldstein 	unsigned int numlayer;
5107f1e596SAmir Goldstein 	/* Number of unique fs among layers including upper fs */
5207f1e596SAmir Goldstein 	unsigned int numfs;
5313464165SMiklos Szeredi 	const struct ovl_layer *layers;
5407f1e596SAmir Goldstein 	struct ovl_sb *fs;
552cac0c00SAmir Goldstein 	/* workbasedir is the path at workdir= mount option */
562cac0c00SAmir Goldstein 	struct dentry *workbasedir;
572cac0c00SAmir Goldstein 	/* workdir is the 'work' directory under workbasedir */
58bbb1e54dSMiklos Szeredi 	struct dentry *workdir;
5902bcd157SAmir Goldstein 	/* index directory listing overlay inodes by origin file handle */
6002bcd157SAmir Goldstein 	struct dentry *indexdir;
616b2d5fe4SMiklos Szeredi 	long namelen;
62bbb1e54dSMiklos Szeredi 	/* pathnames of lower and upper dirs, for show_options */
63bbb1e54dSMiklos Szeredi 	struct ovl_config config;
64bbb1e54dSMiklos Szeredi 	/* creds of process who forced instantiation of super block */
65bbb1e54dSMiklos Szeredi 	const struct cred *creator_cred;
66e7f52429SAmir Goldstein 	bool tmpfile;
6782b749b2SAmir Goldstein 	bool noxattr;
6885fdee1eSAmir Goldstein 	/* Did we take the inuse lock? */
6985fdee1eSAmir Goldstein 	bool upperdir_locked;
7085fdee1eSAmir Goldstein 	bool workdir_locked;
71146d62e5SAmir Goldstein 	/* Traps in ovl inode cache */
72146d62e5SAmir Goldstein 	struct inode *upperdir_trap;
730be0bfd2SAmir Goldstein 	struct inode *workbasedir_trap;
74146d62e5SAmir Goldstein 	struct inode *workdir_trap;
75146d62e5SAmir Goldstein 	struct inode *indexdir_trap;
760f831ec8SAmir Goldstein 	/* -1: disabled, 0: same fs, 1..32: number of unused ino bits */
770f831ec8SAmir Goldstein 	int xino_mode;
784d314f78SAmir Goldstein 	/* For allocation of non-persistent inode numbers */
794d314f78SAmir Goldstein 	atomic_long_t last_ino;
80bbb1e54dSMiklos Szeredi };
81bbb1e54dSMiklos Szeredi 
820f831ec8SAmir Goldstein static inline struct ovl_fs *OVL_FS(struct super_block *sb)
830f831ec8SAmir Goldstein {
840f831ec8SAmir Goldstein 	return (struct ovl_fs *)sb->s_fs_info;
850f831ec8SAmir Goldstein }
860f831ec8SAmir Goldstein 
87bbb1e54dSMiklos Szeredi /* private information held for every overlayfs dentry */
88bbb1e54dSMiklos Szeredi struct ovl_entry {
89bbb1e54dSMiklos Szeredi 	union {
9055acc661SMiklos Szeredi 		struct {
91c62520a8SAmir Goldstein 			unsigned long flags;
9255acc661SMiklos Szeredi 		};
93bbb1e54dSMiklos Szeredi 		struct rcu_head rcu;
94bbb1e54dSMiklos Szeredi 	};
95bbb1e54dSMiklos Szeredi 	unsigned numlower;
96b9343632SChandan Rajendra 	struct ovl_path lowerstack[];
97bbb1e54dSMiklos Szeredi };
98bbb1e54dSMiklos Szeredi 
99bbb1e54dSMiklos Szeredi struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
100bbb1e54dSMiklos Szeredi 
101c62520a8SAmir Goldstein static inline struct ovl_entry *OVL_E(struct dentry *dentry)
102c62520a8SAmir Goldstein {
103c62520a8SAmir Goldstein 	return (struct ovl_entry *) dentry->d_fsdata;
104c62520a8SAmir Goldstein }
105c62520a8SAmir Goldstein 
10613cf199dSAmir Goldstein struct ovl_inode {
1072664bd08SVivek Goyal 	union {
1082664bd08SVivek Goyal 		struct ovl_dir_cache *cache;	/* directory */
1092664bd08SVivek Goyal 		struct inode *lowerdata;	/* regular file */
1102664bd08SVivek Goyal 	};
111cf31c463SMiklos Szeredi 	const char *redirect;
11204a01ac7SMiklos Szeredi 	u64 version;
11313c72075SMiklos Szeredi 	unsigned long flags;
11413cf199dSAmir Goldstein 	struct inode vfs_inode;
11509d8b586SMiklos Szeredi 	struct dentry *__upperdentry;
11625b7713aSMiklos Szeredi 	struct inode *lower;
117a015dafcSAmir Goldstein 
118a015dafcSAmir Goldstein 	/* synchronize copy up and more */
119a015dafcSAmir Goldstein 	struct mutex lock;
12013cf199dSAmir Goldstein };
12113cf199dSAmir Goldstein 
12213cf199dSAmir Goldstein static inline struct ovl_inode *OVL_I(struct inode *inode)
12313cf199dSAmir Goldstein {
12413cf199dSAmir Goldstein 	return container_of(inode, struct ovl_inode, vfs_inode);
12513cf199dSAmir Goldstein }
12609d8b586SMiklos Szeredi 
12709d8b586SMiklos Szeredi static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
12809d8b586SMiklos Szeredi {
129506458efSWill Deacon 	return READ_ONCE(oi->__upperdentry);
13009d8b586SMiklos Szeredi }
131