1 /* SPDX-License-Identifier: GPL-2.0-only */
4 * Copyright (C) 2011 Novell Inc.
5 * Copyright (C) 2016 Red Hat, Inc.
12 bool default_permissions;
25 struct super_block *sb;
27 /* Unusable (conflicting) uuid */
29 /* Used as a lower layer (but maybe also as upper) */
34 /* ovl_free_fs() relies on @mnt being the first member! */
36 /* Trap in ovl inode cache */
39 /* Index of this layer in fs root (upper idx == 0) */
41 /* One fsid per unique underlying sb (upper fsid == 0) */
46 const struct ovl_layer *layer;
47 struct dentry *dentry;
51 unsigned int __numlower;
52 struct ovl_path __lowerstack[];
55 /* private information held for overlayfs's superblock */
57 unsigned int numlayer;
58 /* Number of unique fs among layers including upper fs */
60 /* Number of data-only lower layers */
61 unsigned int numdatalayer;
62 const struct ovl_layer *layers;
64 /* workbasedir is the path at workdir= mount option */
65 struct dentry *workbasedir;
66 /* workdir is the 'work' directory under workbasedir */
67 struct dentry *workdir;
68 /* index directory listing overlay inodes by origin file handle */
69 struct dentry *indexdir;
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;
78 /* Did we take the inuse lock? */
81 /* Traps in ovl inode cache */
82 struct inode *workbasedir_trap;
83 struct inode *workdir_trap;
84 struct inode *indexdir_trap;
85 /* -1: disabled, 0: same fs, 1..32: number of unused ino bits */
87 /* For allocation of non-persistent inode numbers */
88 atomic_long_t last_ino;
89 /* Shared whiteout cache */
90 struct dentry *whiteout;
91 bool no_shared_whiteout;
92 /* r/o snapshot of upperdir sb's only taken on volatile mounts */
96 /* Number of lower layers, not including data-only layers */
97 static inline unsigned int ovl_numlowerlayer(struct ovl_fs *ofs)
99 return ofs->numlayer - ofs->numdatalayer - 1;
102 static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
104 return ofs->layers[0].mnt;
107 static inline struct mnt_idmap *ovl_upper_mnt_idmap(struct ovl_fs *ofs)
109 return mnt_idmap(ovl_upper_mnt(ofs));
112 extern struct file_system_type ovl_fs_type;
114 static inline struct ovl_fs *OVL_FS(struct super_block *sb)
116 if (IS_ENABLED(CONFIG_OVERLAY_FS_DEBUG))
117 WARN_ON_ONCE(sb->s_type != &ovl_fs_type);
119 return (struct ovl_fs *)sb->s_fs_info;
122 static inline bool ovl_should_sync(struct ovl_fs *ofs)
124 return !ofs->config.ovl_volatile;
127 static inline unsigned int ovl_numlower(struct ovl_entry *oe)
129 return oe ? oe->__numlower : 0;
132 static inline struct ovl_path *ovl_lowerstack(struct ovl_entry *oe)
134 return ovl_numlower(oe) ? oe->__lowerstack : NULL;
137 static inline struct ovl_path *ovl_lowerpath(struct ovl_entry *oe)
139 return ovl_lowerstack(oe);
142 static inline struct ovl_path *ovl_lowerdata(struct ovl_entry *oe)
144 struct ovl_path *lowerstack = ovl_lowerstack(oe);
146 return lowerstack ? &lowerstack[oe->__numlower - 1] : NULL;
149 /* May return NULL if lazy lookup of lowerdata is needed */
150 static inline struct dentry *ovl_lowerdata_dentry(struct ovl_entry *oe)
152 struct ovl_path *lowerdata = ovl_lowerdata(oe);
154 return lowerdata ? READ_ONCE(lowerdata->dentry) : NULL;
157 /* private information held for every overlayfs dentry */
158 static inline unsigned long *OVL_E_FLAGS(struct dentry *dentry)
160 return (unsigned long *) &dentry->d_fsdata;
165 struct ovl_dir_cache *cache; /* directory */
166 const char *lowerdata_redirect; /* regular file */
168 const char *redirect;
171 struct inode vfs_inode;
172 struct dentry *__upperdentry;
173 struct ovl_entry *oe;
175 /* synchronize copy up and more */
179 static inline struct ovl_inode *OVL_I(struct inode *inode)
181 return container_of(inode, struct ovl_inode, vfs_inode);
184 static inline struct ovl_entry *OVL_I_E(struct inode *inode)
186 return inode ? OVL_I(inode)->oe : NULL;
189 static inline struct ovl_entry *OVL_E(struct dentry *dentry)
191 return OVL_I_E(d_inode(dentry));
194 static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
196 return READ_ONCE(oi->__upperdentry);