Linux Audio

Check our new training course

Loading...
v6.13.7
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/*
  3 *
  4 * Copyright (C) 2011 Novell Inc.
  5 * Copyright (C) 2016 Red Hat, Inc.
  6 */
  7
  8struct ovl_config {
 
  9	char *upperdir;
 10	char *workdir;
 11	char **lowerdirs;
 12	bool default_permissions;
 13	int redirect_mode;
 14	int verity_mode;
 
 15	bool index;
 16	int uuid;
 17	bool nfs_export;
 18	int xino;
 19	bool metacopy;
 20	bool userxattr;
 21	bool ovl_volatile;
 22};
 23
 24struct ovl_sb {
 25	struct super_block *sb;
 26	dev_t pseudo_dev;
 27	/* Unusable (conflicting) uuid */
 28	bool bad_uuid;
 29	/* Used as a lower layer (but maybe also as upper) */
 30	bool is_lower;
 31};
 32
 33struct ovl_layer {
 34	/* ovl_free_fs() relies on @mnt being the first member! */
 35	struct vfsmount *mnt;
 36	/* Trap in ovl inode cache */
 37	struct inode *trap;
 38	struct ovl_sb *fs;
 39	/* Index of this layer in fs root (upper idx == 0) */
 40	int idx;
 41	/* One fsid per unique underlying sb (upper fsid == 0) */
 42	int fsid;
 43	/* xwhiteouts were found on this layer */
 44	bool has_xwhiteouts;
 45};
 46
 47struct ovl_path {
 48	const struct ovl_layer *layer;
 49	struct dentry *dentry;
 50};
 51
 52struct ovl_entry {
 53	unsigned int __numlower;
 54	struct ovl_path __lowerstack[];
 55};
 56
 57/* private information held for overlayfs's superblock */
 58struct ovl_fs {
 59	unsigned int numlayer;
 60	/* Number of unique fs among layers including upper fs */
 61	unsigned int numfs;
 62	/* Number of data-only lower layers */
 63	unsigned int numdatalayer;
 64	struct ovl_layer *layers;
 65	struct ovl_sb *fs;
 66	/* workbasedir is the path at workdir= mount option */
 67	struct dentry *workbasedir;
 68	/* workdir is the 'work' or 'index' directory under workbasedir */
 69	struct dentry *workdir;
 
 
 70	long namelen;
 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;
 75	bool tmpfile;
 76	bool noxattr;
 77	bool nofh;
 78	/* Did we take the inuse lock? */
 79	bool upperdir_locked;
 80	bool workdir_locked;
 
 81	/* Traps in ovl inode cache */
 82	struct inode *workbasedir_trap;
 83	struct inode *workdir_trap;
 
 84	/* -1: disabled, 0: same fs, 1..32: number of unused ino bits */
 85	int xino_mode;
 86	/* For allocation of non-persistent inode numbers */
 87	atomic_long_t last_ino;
 88	/* Shared whiteout cache */
 89	struct dentry *whiteout;
 90	bool no_shared_whiteout;
 91	/* r/o snapshot of upperdir sb's only taken on volatile mounts */
 92	errseq_t errseq;
 93};
 94
 95/* Number of lower layers, not including data-only layers */
 96static inline unsigned int ovl_numlowerlayer(struct ovl_fs *ofs)
 97{
 98	return ofs->numlayer - ofs->numdatalayer - 1;
 99}
100
101static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
102{
103	return ofs->layers[0].mnt;
104}
105
106static inline struct mnt_idmap *ovl_upper_mnt_idmap(struct ovl_fs *ofs)
107{
108	return mnt_idmap(ovl_upper_mnt(ofs));
109}
110
111extern struct file_system_type ovl_fs_type;
112
113static inline struct ovl_fs *OVL_FS(struct super_block *sb)
114{
115	if (IS_ENABLED(CONFIG_OVERLAY_FS_DEBUG))
116		WARN_ON_ONCE(sb->s_type != &ovl_fs_type);
117
118	return (struct ovl_fs *)sb->s_fs_info;
119}
120
121static inline bool ovl_should_sync(struct ovl_fs *ofs)
122{
123	return !ofs->config.ovl_volatile;
124}
125
126static inline unsigned int ovl_numlower(struct ovl_entry *oe)
127{
128	return oe ? oe->__numlower : 0;
129}
130
131static inline struct ovl_path *ovl_lowerstack(struct ovl_entry *oe)
132{
133	return ovl_numlower(oe) ? oe->__lowerstack : NULL;
134}
135
136static inline struct ovl_path *ovl_lowerpath(struct ovl_entry *oe)
137{
138	return ovl_lowerstack(oe);
139}
140
141static inline struct ovl_path *ovl_lowerdata(struct ovl_entry *oe)
142{
143	struct ovl_path *lowerstack = ovl_lowerstack(oe);
144
145	return lowerstack ? &lowerstack[oe->__numlower - 1] : NULL;
146}
147
148/* May return NULL if lazy lookup of lowerdata is needed */
149static inline struct dentry *ovl_lowerdata_dentry(struct ovl_entry *oe)
150{
151	struct ovl_path *lowerdata = ovl_lowerdata(oe);
152
153	return lowerdata ? READ_ONCE(lowerdata->dentry) : NULL;
154}
155
156/* private information held for every overlayfs dentry */
157static inline unsigned long *OVL_E_FLAGS(struct dentry *dentry)
158{
159	return (unsigned long *) &dentry->d_fsdata;
160}
161
162struct ovl_inode {
163	union {
164		struct ovl_dir_cache *cache;	/* directory */
165		const char *lowerdata_redirect;	/* regular file */
166	};
167	const char *redirect;
168	u64 version;
169	unsigned long flags;
170	struct inode vfs_inode;
171	struct dentry *__upperdentry;
172	struct ovl_entry *oe;
173
174	/* synchronize copy up and more */
175	struct mutex lock;
176};
177
178static inline struct ovl_inode *OVL_I(struct inode *inode)
179{
180	return container_of(inode, struct ovl_inode, vfs_inode);
181}
182
183static inline struct ovl_entry *OVL_I_E(struct inode *inode)
184{
185	return inode ? OVL_I(inode)->oe : NULL;
186}
187
188static inline struct ovl_entry *OVL_E(struct dentry *dentry)
189{
190	return OVL_I_E(d_inode(dentry));
191}
192
193static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
194{
195	return READ_ONCE(oi->__upperdentry);
196}
v6.2
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/*
  3 *
  4 * Copyright (C) 2011 Novell Inc.
  5 * Copyright (C) 2016 Red Hat, Inc.
  6 */
  7
  8struct ovl_config {
  9	char *lowerdir;
 10	char *upperdir;
 11	char *workdir;
 
 12	bool default_permissions;
 13	bool redirect_dir;
 14	bool redirect_follow;
 15	const char *redirect_mode;
 16	bool index;
 17	bool uuid;
 18	bool nfs_export;
 19	int xino;
 20	bool metacopy;
 21	bool userxattr;
 22	bool ovl_volatile;
 23};
 24
 25struct ovl_sb {
 26	struct super_block *sb;
 27	dev_t pseudo_dev;
 28	/* Unusable (conflicting) uuid */
 29	bool bad_uuid;
 30	/* Used as a lower layer (but maybe also as upper) */
 31	bool is_lower;
 32};
 33
 34struct ovl_layer {
 
 35	struct vfsmount *mnt;
 36	/* Trap in ovl inode cache */
 37	struct inode *trap;
 38	struct ovl_sb *fs;
 39	/* Index of this layer in fs root (upper idx == 0) */
 40	int idx;
 41	/* One fsid per unique underlying sb (upper fsid == 0) */
 42	int fsid;
 
 
 43};
 44
 45struct ovl_path {
 46	const struct ovl_layer *layer;
 47	struct dentry *dentry;
 48};
 49
 
 
 
 
 
 50/* private information held for overlayfs's superblock */
 51struct ovl_fs {
 52	unsigned int numlayer;
 53	/* Number of unique fs among layers including upper fs */
 54	unsigned int numfs;
 55	const struct ovl_layer *layers;
 
 
 56	struct ovl_sb *fs;
 57	/* workbasedir is the path at workdir= mount option */
 58	struct dentry *workbasedir;
 59	/* workdir is the 'work' directory under workbasedir */
 60	struct dentry *workdir;
 61	/* index directory listing overlay inodes by origin file handle */
 62	struct dentry *indexdir;
 63	long namelen;
 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;
 68	bool tmpfile;
 69	bool noxattr;
 
 70	/* Did we take the inuse lock? */
 71	bool upperdir_locked;
 72	bool workdir_locked;
 73	bool share_whiteout;
 74	/* Traps in ovl inode cache */
 75	struct inode *workbasedir_trap;
 76	struct inode *workdir_trap;
 77	struct inode *indexdir_trap;
 78	/* -1: disabled, 0: same fs, 1..32: number of unused ino bits */
 79	int xino_mode;
 80	/* For allocation of non-persistent inode numbers */
 81	atomic_long_t last_ino;
 82	/* Whiteout dentry cache */
 83	struct dentry *whiteout;
 
 84	/* r/o snapshot of upperdir sb's only taken on volatile mounts */
 85	errseq_t errseq;
 86};
 87
 
 
 
 
 
 
 88static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
 89{
 90	return ofs->layers[0].mnt;
 91}
 92
 93static inline struct user_namespace *ovl_upper_mnt_userns(struct ovl_fs *ofs)
 94{
 95	return mnt_user_ns(ovl_upper_mnt(ofs));
 96}
 97
 
 
 98static inline struct ovl_fs *OVL_FS(struct super_block *sb)
 99{
 
 
 
100	return (struct ovl_fs *)sb->s_fs_info;
101}
102
103static inline bool ovl_should_sync(struct ovl_fs *ofs)
104{
105	return !ofs->config.ovl_volatile;
106}
107
108/* private information held for every overlayfs dentry */
109struct ovl_entry {
110	union {
111		struct {
112			unsigned long flags;
113		};
114		struct rcu_head rcu;
115	};
116	unsigned numlower;
117	struct ovl_path lowerstack[];
118};
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
120struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
 
121
122static inline struct ovl_entry *OVL_E(struct dentry *dentry)
 
123{
124	return (struct ovl_entry *) dentry->d_fsdata;
125}
126
127struct ovl_inode {
128	union {
129		struct ovl_dir_cache *cache;	/* directory */
130		struct inode *lowerdata;	/* regular file */
131	};
132	const char *redirect;
133	u64 version;
134	unsigned long flags;
135	struct inode vfs_inode;
136	struct dentry *__upperdentry;
137	struct ovl_path lowerpath;
138
139	/* synchronize copy up and more */
140	struct mutex lock;
141};
142
143static inline struct ovl_inode *OVL_I(struct inode *inode)
144{
145	return container_of(inode, struct ovl_inode, vfs_inode);
 
 
 
 
 
 
 
 
 
 
146}
147
148static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
149{
150	return READ_ONCE(oi->__upperdentry);
151}