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