1 /* SPDX-License-Identifier: GPL-2.0-only */
4 * Copyright (C) 2011 Novell Inc.
5 * Copyright (C) 2016 Red Hat, Inc.
11 bool default_permissions;
23 struct super_block *sb;
25 /* Unusable (conflicting) uuid */
27 /* Used as a lower layer (but maybe also as upper) */
32 /* ovl_free_fs() relies on @mnt being the first member! */
34 /* Trap in ovl inode cache */
37 /* Index of this layer in fs root (upper idx == 0) */
39 /* One fsid per unique underlying sb (upper fsid == 0) */
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
49 static_assert(offsetof(struct ovl_layer, mnt) == 0);
50 static_assert(__same_type(typeof_member(struct ovl_layer, mnt), struct vfsmount *));
53 const struct ovl_layer *layer;
54 struct dentry *dentry;
58 unsigned int __numlower;
59 struct ovl_path __lowerstack[];
62 /* private information held for overlayfs's superblock */
64 unsigned int numlayer;
65 /* Number of unique fs among layers including upper fs */
67 /* Number of data-only lower layers */
68 unsigned int numdatalayer;
69 const struct ovl_layer *layers;
71 /* workbasedir is the path at workdir= mount option */
72 struct dentry *workbasedir;
73 /* workdir is the 'work' directory under workbasedir */
74 struct dentry *workdir;
75 /* index directory listing overlay inodes by origin file handle */
76 struct dentry *indexdir;
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;
84 /* Did we take the inuse lock? */
87 /* Traps in ovl inode cache */
88 struct inode *workbasedir_trap;
89 struct inode *workdir_trap;
90 struct inode *indexdir_trap;
91 /* -1: disabled, 0: same fs, 1..32: number of unused ino bits */
93 /* For allocation of non-persistent inode numbers */
94 atomic_long_t last_ino;
95 /* Shared whiteout cache */
96 struct dentry *whiteout;
97 bool no_shared_whiteout;
98 /* r/o snapshot of upperdir sb's only taken on volatile mounts */
102 /* Number of lower layers, not including data-only layers */
103 static inline unsigned int ovl_numlowerlayer(struct ovl_fs *ofs)
105 return ofs->numlayer - ofs->numdatalayer - 1;
108 static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
110 return ofs->layers[0].mnt;
113 static inline struct mnt_idmap *ovl_upper_mnt_idmap(struct ovl_fs *ofs)
115 return mnt_idmap(ovl_upper_mnt(ofs));
118 static inline struct ovl_fs *OVL_FS(struct super_block *sb)
120 return (struct ovl_fs *)sb->s_fs_info;
123 static inline bool ovl_should_sync(struct ovl_fs *ofs)
125 return !ofs->config.ovl_volatile;
128 static inline unsigned int ovl_numlower(struct ovl_entry *oe)
130 return oe ? oe->__numlower : 0;
133 static inline struct ovl_path *ovl_lowerstack(struct ovl_entry *oe)
135 return ovl_numlower(oe) ? oe->__lowerstack : NULL;
138 static inline struct ovl_path *ovl_lowerpath(struct ovl_entry *oe)
140 return ovl_lowerstack(oe);
143 static inline struct ovl_path *ovl_lowerdata(struct ovl_entry *oe)
145 struct ovl_path *lowerstack = ovl_lowerstack(oe);
147 return lowerstack ? &lowerstack[oe->__numlower - 1] : NULL;
150 /* May return NULL if lazy lookup of lowerdata is needed */
151 static inline struct dentry *ovl_lowerdata_dentry(struct ovl_entry *oe)
153 struct ovl_path *lowerdata = ovl_lowerdata(oe);
155 return lowerdata ? READ_ONCE(lowerdata->dentry) : NULL;
158 /* private information held for every overlayfs dentry */
159 static inline unsigned long *OVL_E_FLAGS(struct dentry *dentry)
161 return (unsigned long *) &dentry->d_fsdata;
166 struct ovl_dir_cache *cache; /* directory */
167 const char *lowerdata_redirect; /* regular file */
169 const char *redirect;
172 struct inode vfs_inode;
173 struct dentry *__upperdentry;
174 struct ovl_entry *oe;
176 /* synchronize copy up and more */
180 static inline struct ovl_inode *OVL_I(struct inode *inode)
182 return container_of(inode, struct ovl_inode, vfs_inode);
185 static inline struct ovl_entry *OVL_I_E(struct inode *inode)
187 return inode ? OVL_I(inode)->oe : NULL;
190 static inline struct ovl_entry *OVL_E(struct dentry *dentry)
192 return OVL_I_E(d_inode(dentry));
195 static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
197 return READ_ONCE(oi->__upperdentry);