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