• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 	bool override_creds;
21 };
22 
23 struct ovl_sb {
24 	struct super_block *sb;
25 	dev_t pseudo_dev;
26 	/* Unusable (conflicting) uuid */
27 	bool bad_uuid;
28 };
29 
30 struct ovl_layer {
31 	/* ovl_free_fs() relies on @mnt being the first member! */
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 /*
43  * ovl_free_fs() relies on @mnt being the first member when unmounting
44  * the private mounts created for each layer. Let's check both the
45  * offset and type.
46  */
47 static_assert(offsetof(struct ovl_layer, mnt) == 0);
48 static_assert(__same_type(typeof_member(struct ovl_layer, mnt), struct vfsmount *));
49 
50 struct ovl_path {
51 	struct ovl_layer *layer;
52 	struct dentry *dentry;
53 };
54 
55 /* private information held for overlayfs's superblock */
56 struct ovl_fs {
57 	struct vfsmount *upper_mnt;
58 	unsigned int numlower;
59 	/* Number of unique lower sb that differ from upper sb */
60 	unsigned int numlowerfs;
61 	struct ovl_layer *lower_layers;
62 	struct ovl_sb *lower_fs;
63 	/* workbasedir is the path at workdir= mount option */
64 	struct dentry *workbasedir;
65 	/* workdir is the 'work' directory under workbasedir */
66 	struct dentry *workdir;
67 	/* index directory listing overlay inodes by origin file handle */
68 	struct dentry *indexdir;
69 	long namelen;
70 	/* pathnames of lower and upper dirs, for show_options */
71 	struct ovl_config config;
72 	/* creds of process who forced instantiation of super block */
73 	const struct cred *creator_cred;
74 	bool tmpfile;
75 	bool noxattr;
76 	/* Did we take the inuse lock? */
77 	bool upperdir_locked;
78 	bool workdir_locked;
79 	/* Traps in ovl inode cache */
80 	struct inode *upperdir_trap;
81 	struct inode *workbasedir_trap;
82 	struct inode *workdir_trap;
83 	struct inode *indexdir_trap;
84 	/* Inode numbers in all layers do not use the high xino_bits */
85 	unsigned int xino_bits;
86 };
87 
88 /* private information held for every overlayfs dentry */
89 struct ovl_entry {
90 	union {
91 		struct {
92 			unsigned long flags;
93 		};
94 		struct rcu_head rcu;
95 	};
96 	unsigned numlower;
97 	struct ovl_path lowerstack[];
98 };
99 
100 struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
101 
OVL_E(struct dentry * dentry)102 static inline struct ovl_entry *OVL_E(struct dentry *dentry)
103 {
104 	return (struct ovl_entry *) dentry->d_fsdata;
105 }
106 
107 struct ovl_inode {
108 	union {
109 		struct ovl_dir_cache *cache;	/* directory */
110 		struct inode *lowerdata;	/* regular file */
111 	};
112 	const char *redirect;
113 	u64 version;
114 	unsigned long flags;
115 	struct inode vfs_inode;
116 	struct dentry *__upperdentry;
117 	struct inode *lower;
118 
119 	/* synchronize copy up and more */
120 	struct mutex lock;
121 };
122 
OVL_I(struct inode * inode)123 static inline struct ovl_inode *OVL_I(struct inode *inode)
124 {
125 	return container_of(inode, struct ovl_inode, vfs_inode);
126 }
127 
ovl_upperdentry_dereference(struct ovl_inode * oi)128 static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
129 {
130 	return READ_ONCE(oi->__upperdentry);
131 }
132