xref: /openbmc/linux/fs/overlayfs/ovl_entry.h (revision 890f0b0d)
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 };
79 
80 static inline struct ovl_fs *OVL_FS(struct super_block *sb)
81 {
82 	return (struct ovl_fs *)sb->s_fs_info;
83 }
84 
85 /* private information held for every overlayfs dentry */
86 struct ovl_entry {
87 	union {
88 		struct {
89 			unsigned long flags;
90 		};
91 		struct rcu_head rcu;
92 	};
93 	unsigned numlower;
94 	struct ovl_path lowerstack[];
95 };
96 
97 struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
98 
99 static inline struct ovl_entry *OVL_E(struct dentry *dentry)
100 {
101 	return (struct ovl_entry *) dentry->d_fsdata;
102 }
103 
104 struct ovl_inode {
105 	union {
106 		struct ovl_dir_cache *cache;	/* directory */
107 		struct inode *lowerdata;	/* regular file */
108 	};
109 	const char *redirect;
110 	u64 version;
111 	unsigned long flags;
112 	struct inode vfs_inode;
113 	struct dentry *__upperdentry;
114 	struct inode *lower;
115 
116 	/* synchronize copy up and more */
117 	struct mutex lock;
118 };
119 
120 static inline struct ovl_inode *OVL_I(struct inode *inode)
121 {
122 	return container_of(inode, struct ovl_inode, vfs_inode);
123 }
124 
125 static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
126 {
127 	return READ_ONCE(oi->__upperdentry);
128 }
129