ovl: implement lookup in data-only layers
[linux-2.6-block.git] / fs / overlayfs / ovl_entry.h
CommitLineData
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
8struct ovl_config {
9 char *lowerdir;
10 char *upperdir;
11 char *workdir;
12 bool default_permissions;
a6c60655 13 bool redirect_dir;
438c84c2
MS
14 bool redirect_follow;
15 const char *redirect_mode;
02bcd157 16 bool index;
5830fb6b 17 bool uuid;
f168f109 18 bool nfs_export;
795939a9 19 int xino;
d5791044 20 bool metacopy;
2d2f2d73 21 bool userxattr;
c86243b0 22 bool ovl_volatile;
bbb1e54d
MS
23};
24
5148626b
AG
25struct ovl_sb {
26 struct super_block *sb;
27 dev_t pseudo_dev;
7e63c87f
AG
28 /* Unusable (conflicting) uuid */
29 bool bad_uuid;
1b81dddd
AG
30 /* Used as a lower layer (but maybe also as upper) */
31 bool is_lower;
5148626b
AG
32};
33
b9343632
CR
34struct ovl_layer {
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;
b9343632
CR
43};
44
45struct ovl_path {
13464165 46 const struct ovl_layer *layer;
b9343632
CR
47 struct dentry *dentry;
48};
49
0af950f5
AG
50struct ovl_entry {
51 unsigned int __numlower;
52 struct ovl_path __lowerstack[];
53};
54
bbb1e54d
MS
55/* private information held for overlayfs's superblock */
56struct ovl_fs {
94375f9d 57 unsigned int numlayer;
07f1e596
AG
58 /* Number of unique fs among layers including upper fs */
59 unsigned int numfs;
37ebf056
AG
60 /* Number of data-only lower layers */
61 unsigned int numdatalayer;
13464165 62 const struct ovl_layer *layers;
07f1e596 63 struct ovl_sb *fs;
2cac0c00
AG
64 /* workbasedir is the path at workdir= mount option */
65 struct dentry *workbasedir;
66 /* workdir is the 'work' directory under workbasedir */
bbb1e54d 67 struct dentry *workdir;
02bcd157
AG
68 /* index directory listing overlay inodes by origin file handle */
69 struct dentry *indexdir;
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;
85fdee1e
AG
77 /* Did we take the inuse lock? */
78 bool upperdir_locked;
79 bool workdir_locked;
c21c839b 80 bool share_whiteout;
146d62e5 81 /* Traps in ovl inode cache */
0be0bfd2 82 struct inode *workbasedir_trap;
146d62e5
AG
83 struct inode *workdir_trap;
84 struct inode *indexdir_trap;
0f831ec8
AG
85 /* -1: disabled, 0: same fs, 1..32: number of unused ino bits */
86 int xino_mode;
4d314f78
AG
87 /* For allocation of non-persistent inode numbers */
88 atomic_long_t last_ino;
c21c839b
CX
89 /* Whiteout dentry cache */
90 struct dentry *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
96/* Number of lower layers, not including data-only layers */
97static inline unsigned int ovl_numlowerlayer(struct ovl_fs *ofs)
98{
99 return ofs->numlayer - ofs->numdatalayer - 1;
100}
101
08f4c7c8
MS
102static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
103{
b8e42a65 104 return ofs->layers[0].mnt;
08f4c7c8
MS
105}
106
abf08576
CB
107static inline struct mnt_idmap *ovl_upper_mnt_idmap(struct ovl_fs *ofs)
108{
109 return mnt_idmap(ovl_upper_mnt(ofs));
110}
111
0f831ec8
AG
112static inline struct ovl_fs *OVL_FS(struct super_block *sb)
113{
114 return (struct ovl_fs *)sb->s_fs_info;
115}
116
c86243b0
VG
117static inline bool ovl_should_sync(struct ovl_fs *ofs)
118{
119 return !ofs->config.ovl_volatile;
120}
121
5522c9c7
AG
122static inline unsigned int ovl_numlower(struct ovl_entry *oe)
123{
124 return oe ? oe->__numlower : 0;
125}
126
127static inline struct ovl_path *ovl_lowerstack(struct ovl_entry *oe)
128{
129 return ovl_numlower(oe) ? oe->__lowerstack : NULL;
130}
131
ac900ed4
AG
132static inline struct ovl_path *ovl_lowerpath(struct ovl_entry *oe)
133{
134 return ovl_lowerstack(oe);
135}
136
ab1eb5ff
AG
137static inline struct ovl_path *ovl_lowerdata(struct ovl_entry *oe)
138{
139 struct ovl_path *lowerstack = ovl_lowerstack(oe);
140
141 return lowerstack ? &lowerstack[oe->__numlower - 1] : NULL;
142}
143
144static inline struct dentry *ovl_lowerdata_dentry(struct ovl_entry *oe)
145{
146 struct ovl_path *lowerdata = ovl_lowerdata(oe);
147
148 return lowerdata ? lowerdata->dentry : NULL;
149}
150
0af950f5 151/* private information held for every overlayfs dentry */
a6ff2bc0
AG
152static inline unsigned long *OVL_E_FLAGS(struct dentry *dentry)
153{
0af950f5 154 return (unsigned long *) &dentry->d_fsdata;
a6ff2bc0
AG
155}
156
13cf199d 157struct ovl_inode {
2664bd08
VG
158 union {
159 struct ovl_dir_cache *cache; /* directory */
ab1eb5ff 160 /* place holder for non-dir */ /* regular file */
2664bd08 161 };
cf31c463 162 const char *redirect;
04a01ac7 163 u64 version;
13c72075 164 unsigned long flags;
13cf199d 165 struct inode vfs_inode;
09d8b586 166 struct dentry *__upperdentry;
0af950f5 167 struct ovl_entry *oe;
a015dafc
AG
168
169 /* synchronize copy up and more */
170 struct mutex lock;
13cf199d
AG
171};
172
173static inline struct ovl_inode *OVL_I(struct inode *inode)
174{
175 return container_of(inode, struct ovl_inode, vfs_inode);
176}
09d8b586 177
0af950f5
AG
178static inline struct ovl_entry *OVL_I_E(struct inode *inode)
179{
180 return inode ? OVL_I(inode)->oe : NULL;
181}
182
183static inline struct ovl_entry *OVL_E(struct dentry *dentry)
184{
185 return OVL_I_E(d_inode(dentry));
186}
187
09d8b586
MS
188static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
189{
506458ef 190 return READ_ONCE(oi->__upperdentry);
09d8b586 191}