• 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 	struct vfsmount *mnt;
32 	/* Trap in ovl inode cache */
33 	struct inode *trap;
34 	struct ovl_sb *fs;
35 	/* Index of this layer in fs root (upper idx == 0) */
36 	int idx;
37 	/* One fsid per unique underlying sb (upper fsid == 0) */
38 	int fsid;
39 };
40 
41 struct ovl_path {
42 	struct ovl_layer *layer;
43 	struct dentry *dentry;
44 };
45 
46 /* private information held for overlayfs's superblock */
47 struct ovl_fs {
48 	struct vfsmount *upper_mnt;
49 	unsigned int numlower;
50 	/* Number of unique lower sb that differ from upper sb */
51 	unsigned int numlowerfs;
52 	struct ovl_layer *lower_layers;
53 	struct ovl_sb *lower_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 	/* Traps in ovl inode cache */
71 	struct inode *upperdir_trap;
72 	struct inode *workbasedir_trap;
73 	struct inode *workdir_trap;
74 	struct inode *indexdir_trap;
75 	/* Inode numbers in all layers do not use the high xino_bits */
76 	unsigned int xino_bits;
77 };
78 
79 /* private information held for every overlayfs dentry */
80 struct ovl_entry {
81 	union {
82 		struct {
83 			unsigned long flags;
84 		};
85 		struct rcu_head rcu;
86 	};
87 	unsigned numlower;
88 	struct ovl_path lowerstack[];
89 };
90 
91 struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
92 
OVL_E(struct dentry * dentry)93 static inline struct ovl_entry *OVL_E(struct dentry *dentry)
94 {
95 	return (struct ovl_entry *) dentry->d_fsdata;
96 }
97 
98 struct ovl_inode {
99 	union {
100 		struct ovl_dir_cache *cache;	/* directory */
101 		struct inode *lowerdata;	/* regular file */
102 	};
103 	const char *redirect;
104 	u64 version;
105 	unsigned long flags;
106 	struct inode vfs_inode;
107 	struct dentry *__upperdentry;
108 	struct inode *lower;
109 
110 	/* synchronize copy up and more */
111 	struct mutex lock;
112 };
113 
OVL_I(struct inode * inode)114 static inline struct ovl_inode *OVL_I(struct inode *inode)
115 {
116 	return container_of(inode, struct ovl_inode, vfs_inode);
117 }
118 
ovl_upperdentry_dereference(struct ovl_inode * oi)119 static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
120 {
121 	return READ_ONCE(oi->__upperdentry);
122 }
123