Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
bbb1e54d MS |
2 | /* |
3 | * | |
4 | * Copyright (C) 2011 Novell Inc. | |
5 | * Copyright (C) 2016 Red Hat, Inc. | |
bbb1e54d MS |
6 | */ |
7 | ||
8 | struct ovl_config { | |
bbb1e54d MS |
9 | char *upperdir; |
10 | char *workdir; | |
a535116d | 11 | char **lowerdirs; |
bbb1e54d | 12 | bool default_permissions; |
af5f2396 | 13 | int redirect_mode; |
ae8cba40 | 14 | int verity_mode; |
02bcd157 | 15 | bool index; |
b0504bfe | 16 | int uuid; |
f168f109 | 17 | bool nfs_export; |
795939a9 | 18 | int xino; |
d5791044 | 19 | bool metacopy; |
2d2f2d73 | 20 | bool userxattr; |
c86243b0 | 21 | bool ovl_volatile; |
bbb1e54d MS |
22 | }; |
23 | ||
5148626b AG |
24 | struct ovl_sb { |
25 | struct super_block *sb; | |
26 | dev_t pseudo_dev; | |
7e63c87f AG |
27 | /* Unusable (conflicting) uuid */ |
28 | bool bad_uuid; | |
1b81dddd AG |
29 | /* Used as a lower layer (but maybe also as upper) */ |
30 | bool is_lower; | |
5148626b AG |
31 | }; |
32 | ||
b9343632 | 33 | struct ovl_layer { |
f723edb8 | 34 | /* ovl_free_fs() relies on @mnt being the first member! */ |
b9343632 | 35 | struct vfsmount *mnt; |
146d62e5 AG |
36 | /* Trap in ovl inode cache */ |
37 | struct inode *trap; | |
5148626b AG |
38 | struct ovl_sb *fs; |
39 | /* Index of this layer in fs root (upper idx == 0) */ | |
d583ed7d | 40 | int idx; |
5148626b AG |
41 | /* One fsid per unique underlying sb (upper fsid == 0) */ |
42 | int fsid; | |
420332b9 AG |
43 | /* xwhiteouts were found on this layer */ |
44 | bool has_xwhiteouts; | |
b9343632 CR |
45 | }; |
46 | ||
47 | struct ovl_path { | |
13464165 | 48 | const struct ovl_layer *layer; |
b9343632 CR |
49 | struct dentry *dentry; |
50 | }; | |
51 | ||
0af950f5 AG |
52 | struct ovl_entry { |
53 | unsigned int __numlower; | |
54 | struct ovl_path __lowerstack[]; | |
55 | }; | |
56 | ||
bbb1e54d MS |
57 | /* private information held for overlayfs's superblock */ |
58 | struct ovl_fs { | |
94375f9d | 59 | unsigned int numlayer; |
07f1e596 AG |
60 | /* Number of unique fs among layers including upper fs */ |
61 | unsigned int numfs; | |
37ebf056 AG |
62 | /* Number of data-only lower layers */ |
63 | unsigned int numdatalayer; | |
420332b9 | 64 | struct ovl_layer *layers; |
07f1e596 | 65 | struct ovl_sb *fs; |
2cac0c00 AG |
66 | /* workbasedir is the path at workdir= mount option */ |
67 | struct dentry *workbasedir; | |
02d70090 | 68 | /* workdir is the 'work' or 'index' directory under workbasedir */ |
bbb1e54d | 69 | struct dentry *workdir; |
6b2d5fe4 | 70 | long namelen; |
bbb1e54d MS |
71 | /* pathnames of lower and upper dirs, for show_options */ |
72 | struct ovl_config config; | |
73 | /* creds of process who forced instantiation of super block */ | |
74 | const struct cred *creator_cred; | |
e7f52429 | 75 | bool tmpfile; |
82b749b2 | 76 | bool noxattr; |
16aac5ad | 77 | bool nofh; |
85fdee1e AG |
78 | /* Did we take the inuse lock? */ |
79 | bool upperdir_locked; | |
80 | bool workdir_locked; | |
146d62e5 | 81 | /* Traps in ovl inode cache */ |
0be0bfd2 | 82 | struct inode *workbasedir_trap; |
146d62e5 | 83 | struct inode *workdir_trap; |
0f831ec8 AG |
84 | /* -1: disabled, 0: same fs, 1..32: number of unused ino bits */ |
85 | int xino_mode; | |
4d314f78 AG |
86 | /* For allocation of non-persistent inode numbers */ |
87 | atomic_long_t last_ino; | |
e4599d4b | 88 | /* Shared whiteout cache */ |
c21c839b | 89 | struct dentry *whiteout; |
e4599d4b | 90 | bool no_shared_whiteout; |
335d3fc5 SD |
91 | /* r/o snapshot of upperdir sb's only taken on volatile mounts */ |
92 | errseq_t errseq; | |
bbb1e54d MS |
93 | }; |
94 | ||
37ebf056 AG |
95 | /* Number of lower layers, not including data-only layers */ |
96 | static inline unsigned int ovl_numlowerlayer(struct ovl_fs *ofs) | |
97 | { | |
98 | return ofs->numlayer - ofs->numdatalayer - 1; | |
99 | } | |
100 | ||
08f4c7c8 MS |
101 | static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs) |
102 | { | |
b8e42a65 | 103 | return ofs->layers[0].mnt; |
08f4c7c8 MS |
104 | } |
105 | ||
abf08576 CB |
106 | static inline struct mnt_idmap *ovl_upper_mnt_idmap(struct ovl_fs *ofs) |
107 | { | |
108 | return mnt_idmap(ovl_upper_mnt(ofs)); | |
109 | } | |
110 | ||
f01d0889 AR |
111 | extern struct file_system_type ovl_fs_type; |
112 | ||
0f831ec8 AG |
113 | static inline struct ovl_fs *OVL_FS(struct super_block *sb) |
114 | { | |
adcd459f AR |
115 | if (IS_ENABLED(CONFIG_OVERLAY_FS_DEBUG)) |
116 | WARN_ON_ONCE(sb->s_type != &ovl_fs_type); | |
117 | ||
0f831ec8 AG |
118 | return (struct ovl_fs *)sb->s_fs_info; |
119 | } | |
120 | ||
c86243b0 VG |
121 | static inline bool ovl_should_sync(struct ovl_fs *ofs) |
122 | { | |
123 | return !ofs->config.ovl_volatile; | |
124 | } | |
125 | ||
5522c9c7 AG |
126 | static inline unsigned int ovl_numlower(struct ovl_entry *oe) |
127 | { | |
128 | return oe ? oe->__numlower : 0; | |
129 | } | |
130 | ||
131 | static inline struct ovl_path *ovl_lowerstack(struct ovl_entry *oe) | |
132 | { | |
133 | return ovl_numlower(oe) ? oe->__lowerstack : NULL; | |
134 | } | |
135 | ||
ac900ed4 AG |
136 | static inline struct ovl_path *ovl_lowerpath(struct ovl_entry *oe) |
137 | { | |
138 | return ovl_lowerstack(oe); | |
139 | } | |
140 | ||
ab1eb5ff AG |
141 | static inline struct ovl_path *ovl_lowerdata(struct ovl_entry *oe) |
142 | { | |
143 | struct ovl_path *lowerstack = ovl_lowerstack(oe); | |
144 | ||
145 | return lowerstack ? &lowerstack[oe->__numlower - 1] : NULL; | |
146 | } | |
147 | ||
2b21da92 | 148 | /* May return NULL if lazy lookup of lowerdata is needed */ |
ab1eb5ff AG |
149 | static inline struct dentry *ovl_lowerdata_dentry(struct ovl_entry *oe) |
150 | { | |
151 | struct ovl_path *lowerdata = ovl_lowerdata(oe); | |
152 | ||
42dd69ae | 153 | return lowerdata ? READ_ONCE(lowerdata->dentry) : NULL; |
ab1eb5ff AG |
154 | } |
155 | ||
0af950f5 | 156 | /* private information held for every overlayfs dentry */ |
a6ff2bc0 AG |
157 | static inline unsigned long *OVL_E_FLAGS(struct dentry *dentry) |
158 | { | |
0af950f5 | 159 | return (unsigned long *) &dentry->d_fsdata; |
a6ff2bc0 AG |
160 | } |
161 | ||
13cf199d | 162 | struct ovl_inode { |
2664bd08 VG |
163 | union { |
164 | struct ovl_dir_cache *cache; /* directory */ | |
2b21da92 | 165 | const char *lowerdata_redirect; /* regular file */ |
2664bd08 | 166 | }; |
cf31c463 | 167 | const char *redirect; |
04a01ac7 | 168 | u64 version; |
13c72075 | 169 | unsigned long flags; |
13cf199d | 170 | struct inode vfs_inode; |
09d8b586 | 171 | struct dentry *__upperdentry; |
0af950f5 | 172 | struct ovl_entry *oe; |
a015dafc AG |
173 | |
174 | /* synchronize copy up and more */ | |
175 | struct mutex lock; | |
13cf199d AG |
176 | }; |
177 | ||
178 | static inline struct ovl_inode *OVL_I(struct inode *inode) | |
179 | { | |
180 | return container_of(inode, struct ovl_inode, vfs_inode); | |
181 | } | |
09d8b586 | 182 | |
0af950f5 AG |
183 | static inline struct ovl_entry *OVL_I_E(struct inode *inode) |
184 | { | |
185 | return inode ? OVL_I(inode)->oe : NULL; | |
186 | } | |
187 | ||
188 | static inline struct ovl_entry *OVL_E(struct dentry *dentry) | |
189 | { | |
190 | return OVL_I_E(d_inode(dentry)); | |
191 | } | |
192 | ||
09d8b586 MS |
193 | static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi) |
194 | { | |
506458ef | 195 | return READ_ONCE(oi->__upperdentry); |
09d8b586 | 196 | } |