xref: /linux/fs/overlayfs/ovl_entry.h (revision 44f57d78)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  *
4  * Copyright (C) 2011 Novell Inc.
5  * Copyright (C) 2016 Red Hat, Inc.
6  */
7 
8 struct ovl_config {
9 	char *lowerdir;
10 	char *upperdir;
11 	char *workdir;
12 	bool default_permissions;
13 	bool redirect_dir;
14 	bool redirect_follow;
15 	const char *redirect_mode;
16 	bool index;
17 	bool nfs_export;
18 	int xino;
19 	bool metacopy;
20 };
21 
22 struct ovl_sb {
23 	struct super_block *sb;
24 	dev_t pseudo_dev;
25 };
26 
27 struct ovl_layer {
28 	struct vfsmount *mnt;
29 	/* Trap in ovl inode cache */
30 	struct inode *trap;
31 	struct ovl_sb *fs;
32 	/* Index of this layer in fs root (upper idx == 0) */
33 	int idx;
34 	/* One fsid per unique underlying sb (upper fsid == 0) */
35 	int fsid;
36 };
37 
38 struct ovl_path {
39 	struct ovl_layer *layer;
40 	struct dentry *dentry;
41 };
42 
43 /* private information held for overlayfs's superblock */
44 struct ovl_fs {
45 	struct vfsmount *upper_mnt;
46 	unsigned int numlower;
47 	/* Number of unique lower sb that differ from upper sb */
48 	unsigned int numlowerfs;
49 	struct ovl_layer *lower_layers;
50 	struct ovl_sb *lower_fs;
51 	/* workbasedir is the path at workdir= mount option */
52 	struct dentry *workbasedir;
53 	/* workdir is the 'work' directory under workbasedir */
54 	struct dentry *workdir;
55 	/* index directory listing overlay inodes by origin file handle */
56 	struct dentry *indexdir;
57 	long namelen;
58 	/* pathnames of lower and upper dirs, for show_options */
59 	struct ovl_config config;
60 	/* creds of process who forced instantiation of super block */
61 	const struct cred *creator_cred;
62 	bool tmpfile;
63 	bool noxattr;
64 	/* Did we take the inuse lock? */
65 	bool upperdir_locked;
66 	bool workdir_locked;
67 	/* Traps in ovl inode cache */
68 	struct inode *upperdir_trap;
69 	struct inode *workdir_trap;
70 	struct inode *indexdir_trap;
71 	/* Inode numbers in all layers do not use the high xino_bits */
72 	unsigned int xino_bits;
73 };
74 
75 /* private information held for every overlayfs dentry */
76 struct ovl_entry {
77 	union {
78 		struct {
79 			unsigned long flags;
80 		};
81 		struct rcu_head rcu;
82 	};
83 	unsigned numlower;
84 	struct ovl_path lowerstack[];
85 };
86 
87 struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
88 
89 static inline struct ovl_entry *OVL_E(struct dentry *dentry)
90 {
91 	return (struct ovl_entry *) dentry->d_fsdata;
92 }
93 
94 struct ovl_inode {
95 	union {
96 		struct ovl_dir_cache *cache;	/* directory */
97 		struct inode *lowerdata;	/* regular file */
98 	};
99 	const char *redirect;
100 	u64 version;
101 	unsigned long flags;
102 	struct inode vfs_inode;
103 	struct dentry *__upperdentry;
104 	struct inode *lower;
105 
106 	/* synchronize copy up and more */
107 	struct mutex lock;
108 };
109 
110 static inline struct ovl_inode *OVL_I(struct inode *inode)
111 {
112 	return container_of(inode, struct ovl_inode, vfs_inode);
113 }
114 
115 static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
116 {
117 	return READ_ONCE(oi->__upperdentry);
118 }
119