xref: /openbmc/linux/fs/overlayfs/ovl_entry.h (revision 9a6b55ac)
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 
8 struct 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 nfs_export;
18 	int xino;
19 	bool metacopy;
20 };
21 
22 struct ovl_sb {
23 	struct super_block *sb;
24 	dev_t pseudo_dev;
25 	/* Unusable (conflicting) uuid */
26 	bool bad_uuid;
27 };
28 
29 struct ovl_layer {
30 	struct vfsmount *mnt;
31 	/* Trap in ovl inode cache */
32 	struct inode *trap;
33 	struct ovl_sb *fs;
34 	/* Index of this layer in fs root (upper idx == 0) */
35 	int idx;
36 	/* One fsid per unique underlying sb (upper fsid == 0) */
37 	int fsid;
38 };
39 
40 struct ovl_path {
41 	struct ovl_layer *layer;
42 	struct dentry *dentry;
43 };
44 
45 /* private information held for overlayfs's superblock */
46 struct ovl_fs {
47 	struct vfsmount *upper_mnt;
48 	unsigned int numlower;
49 	/* Number of unique lower sb that differ from upper sb */
50 	unsigned int numlowerfs;
51 	struct ovl_layer *lower_layers;
52 	struct ovl_sb *lower_fs;
53 	/* workbasedir is the path at workdir= mount option */
54 	struct dentry *workbasedir;
55 	/* workdir is the 'work' directory under workbasedir */
56 	struct dentry *workdir;
57 	/* index directory listing overlay inodes by origin file handle */
58 	struct dentry *indexdir;
59 	long namelen;
60 	/* pathnames of lower and upper dirs, for show_options */
61 	struct ovl_config config;
62 	/* creds of process who forced instantiation of super block */
63 	const struct cred *creator_cred;
64 	bool tmpfile;
65 	bool noxattr;
66 	/* Did we take the inuse lock? */
67 	bool upperdir_locked;
68 	bool workdir_locked;
69 	/* Traps in ovl inode cache */
70 	struct inode *upperdir_trap;
71 	struct inode *workbasedir_trap;
72 	struct inode *workdir_trap;
73 	struct inode *indexdir_trap;
74 	/* Inode numbers in all layers do not use the high xino_bits */
75 	unsigned int xino_bits;
76 };
77 
78 /* private information held for every overlayfs dentry */
79 struct ovl_entry {
80 	union {
81 		struct {
82 			unsigned long flags;
83 		};
84 		struct rcu_head rcu;
85 	};
86 	unsigned numlower;
87 	struct ovl_path lowerstack[];
88 };
89 
90 struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
91 
92 static inline struct ovl_entry *OVL_E(struct dentry *dentry)
93 {
94 	return (struct ovl_entry *) dentry->d_fsdata;
95 }
96 
97 struct ovl_inode {
98 	union {
99 		struct ovl_dir_cache *cache;	/* directory */
100 		struct inode *lowerdata;	/* regular file */
101 	};
102 	const char *redirect;
103 	u64 version;
104 	unsigned long flags;
105 	struct inode vfs_inode;
106 	struct dentry *__upperdentry;
107 	struct inode *lower;
108 
109 	/* synchronize copy up and more */
110 	struct mutex lock;
111 };
112 
113 static inline struct ovl_inode *OVL_I(struct inode *inode)
114 {
115 	return container_of(inode, struct ovl_inode, vfs_inode);
116 }
117 
118 static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
119 {
120 	return READ_ONCE(oi->__upperdentry);
121 }
122