ovl: deduplicate lowerpath and lowerstack[]
[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;
13464165 60 const struct ovl_layer *layers;
07f1e596 61 struct ovl_sb *fs;
2cac0c00
AG
62 /* workbasedir is the path at workdir= mount option */
63 struct dentry *workbasedir;
64 /* workdir is the 'work' directory under workbasedir */
bbb1e54d 65 struct dentry *workdir;
02bcd157
AG
66 /* index directory listing overlay inodes by origin file handle */
67 struct dentry *indexdir;
6b2d5fe4 68 long namelen;
bbb1e54d
MS
69 /* pathnames of lower and upper dirs, for show_options */
70 struct ovl_config config;
71 /* creds of process who forced instantiation of super block */
72 const struct cred *creator_cred;
e7f52429 73 bool tmpfile;
82b749b2 74 bool noxattr;
85fdee1e
AG
75 /* Did we take the inuse lock? */
76 bool upperdir_locked;
77 bool workdir_locked;
c21c839b 78 bool share_whiteout;
146d62e5 79 /* Traps in ovl inode cache */
0be0bfd2 80 struct inode *workbasedir_trap;
146d62e5
AG
81 struct inode *workdir_trap;
82 struct inode *indexdir_trap;
0f831ec8
AG
83 /* -1: disabled, 0: same fs, 1..32: number of unused ino bits */
84 int xino_mode;
4d314f78
AG
85 /* For allocation of non-persistent inode numbers */
86 atomic_long_t last_ino;
c21c839b
CX
87 /* Whiteout dentry cache */
88 struct dentry *whiteout;
335d3fc5
SD
89 /* r/o snapshot of upperdir sb's only taken on volatile mounts */
90 errseq_t errseq;
bbb1e54d
MS
91};
92
08f4c7c8
MS
93static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
94{
b8e42a65 95 return ofs->layers[0].mnt;
08f4c7c8
MS
96}
97
abf08576
CB
98static inline struct mnt_idmap *ovl_upper_mnt_idmap(struct ovl_fs *ofs)
99{
100 return mnt_idmap(ovl_upper_mnt(ofs));
101}
102
0f831ec8
AG
103static inline struct ovl_fs *OVL_FS(struct super_block *sb)
104{
105 return (struct ovl_fs *)sb->s_fs_info;
106}
107
c86243b0
VG
108static inline bool ovl_should_sync(struct ovl_fs *ofs)
109{
110 return !ofs->config.ovl_volatile;
111}
112
5522c9c7
AG
113static inline unsigned int ovl_numlower(struct ovl_entry *oe)
114{
115 return oe ? oe->__numlower : 0;
116}
117
118static inline struct ovl_path *ovl_lowerstack(struct ovl_entry *oe)
119{
120 return ovl_numlower(oe) ? oe->__lowerstack : NULL;
121}
122
ac900ed4
AG
123static inline struct ovl_path *ovl_lowerpath(struct ovl_entry *oe)
124{
125 return ovl_lowerstack(oe);
126}
127
0af950f5 128/* private information held for every overlayfs dentry */
a6ff2bc0
AG
129static inline unsigned long *OVL_E_FLAGS(struct dentry *dentry)
130{
0af950f5 131 return (unsigned long *) &dentry->d_fsdata;
a6ff2bc0
AG
132}
133
13cf199d 134struct ovl_inode {
2664bd08
VG
135 union {
136 struct ovl_dir_cache *cache; /* directory */
137 struct inode *lowerdata; /* regular file */
138 };
cf31c463 139 const char *redirect;
04a01ac7 140 u64 version;
13c72075 141 unsigned long flags;
13cf199d 142 struct inode vfs_inode;
09d8b586 143 struct dentry *__upperdentry;
0af950f5 144 struct ovl_entry *oe;
a015dafc
AG
145
146 /* synchronize copy up and more */
147 struct mutex lock;
13cf199d
AG
148};
149
150static inline struct ovl_inode *OVL_I(struct inode *inode)
151{
152 return container_of(inode, struct ovl_inode, vfs_inode);
153}
09d8b586 154
0af950f5
AG
155static inline struct ovl_entry *OVL_I_E(struct inode *inode)
156{
157 return inode ? OVL_I(inode)->oe : NULL;
158}
159
160static inline struct ovl_entry *OVL_E(struct dentry *dentry)
161{
162 return OVL_I_E(d_inode(dentry));
163}
164
09d8b586
MS
165static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
166{
506458ef 167 return READ_ONCE(oi->__upperdentry);
09d8b586 168}