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