xref: /openbmc/linux/fs/overlayfs/ovl_entry.h (revision a16be368)
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 	/* Used as a lower layer (but maybe also as upper) */
28 	bool is_lower;
29 };
30 
31 struct ovl_layer {
32 	struct vfsmount *mnt;
33 	/* Trap in ovl inode cache */
34 	struct inode *trap;
35 	struct ovl_sb *fs;
36 	/* Index of this layer in fs root (upper idx == 0) */
37 	int idx;
38 	/* One fsid per unique underlying sb (upper fsid == 0) */
39 	int fsid;
40 };
41 
42 struct ovl_path {
43 	const struct ovl_layer *layer;
44 	struct dentry *dentry;
45 };
46 
47 /* private information held for overlayfs's superblock */
48 struct ovl_fs {
49 	unsigned int numlayer;
50 	/* Number of unique fs among layers including upper fs */
51 	unsigned int numfs;
52 	const struct ovl_layer *layers;
53 	struct ovl_sb *fs;
54 	/* workbasedir is the path at workdir= mount option */
55 	struct dentry *workbasedir;
56 	/* workdir is the 'work' directory under workbasedir */
57 	struct dentry *workdir;
58 	/* index directory listing overlay inodes by origin file handle */
59 	struct dentry *indexdir;
60 	long namelen;
61 	/* pathnames of lower and upper dirs, for show_options */
62 	struct ovl_config config;
63 	/* creds of process who forced instantiation of super block */
64 	const struct cred *creator_cred;
65 	bool tmpfile;
66 	bool noxattr;
67 	/* Did we take the inuse lock? */
68 	bool upperdir_locked;
69 	bool workdir_locked;
70 	bool share_whiteout;
71 	/* Traps in ovl inode cache */
72 	struct inode *workbasedir_trap;
73 	struct inode *workdir_trap;
74 	struct inode *indexdir_trap;
75 	/* -1: disabled, 0: same fs, 1..32: number of unused ino bits */
76 	int xino_mode;
77 	/* For allocation of non-persistent inode numbers */
78 	atomic_long_t last_ino;
79 	/* Whiteout dentry cache */
80 	struct dentry *whiteout;
81 };
82 
83 static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
84 {
85 	return ofs->layers[0].mnt;
86 }
87 
88 static inline struct ovl_fs *OVL_FS(struct super_block *sb)
89 {
90 	return (struct ovl_fs *)sb->s_fs_info;
91 }
92 
93 /* private information held for every overlayfs dentry */
94 struct ovl_entry {
95 	union {
96 		struct {
97 			unsigned long flags;
98 		};
99 		struct rcu_head rcu;
100 	};
101 	unsigned numlower;
102 	struct ovl_path lowerstack[];
103 };
104 
105 struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
106 
107 static inline struct ovl_entry *OVL_E(struct dentry *dentry)
108 {
109 	return (struct ovl_entry *) dentry->d_fsdata;
110 }
111 
112 struct ovl_inode {
113 	union {
114 		struct ovl_dir_cache *cache;	/* directory */
115 		struct inode *lowerdata;	/* regular file */
116 	};
117 	const char *redirect;
118 	u64 version;
119 	unsigned long flags;
120 	struct inode vfs_inode;
121 	struct dentry *__upperdentry;
122 	struct inode *lower;
123 
124 	/* synchronize copy up and more */
125 	struct mutex lock;
126 };
127 
128 static inline struct ovl_inode *OVL_I(struct inode *inode)
129 {
130 	return container_of(inode, struct ovl_inode, vfs_inode);
131 }
132 
133 static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
134 {
135 	return READ_ONCE(oi->__upperdentry);
136 }
137