xref: /openbmc/linux/fs/overlayfs/ovl_entry.h (revision 8c609698)
1 /*
2  *
3  * Copyright (C) 2011 Novell Inc.
4  * Copyright (C) 2016 Red Hat, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 as published by
8  * the Free Software Foundation.
9  */
10 
11 struct ovl_config {
12 	char *lowerdir;
13 	char *upperdir;
14 	char *workdir;
15 	bool default_permissions;
16 	bool redirect_dir;
17 	bool index;
18 };
19 
20 /* private information held for overlayfs's superblock */
21 struct ovl_fs {
22 	struct vfsmount *upper_mnt;
23 	unsigned numlower;
24 	struct vfsmount **lower_mnt;
25 	/* workbasedir is the path at workdir= mount option */
26 	struct dentry *workbasedir;
27 	/* workdir is the 'work' directory under workbasedir */
28 	struct dentry *workdir;
29 	/* index directory listing overlay inodes by origin file handle */
30 	struct dentry *indexdir;
31 	long namelen;
32 	/* pathnames of lower and upper dirs, for show_options */
33 	struct ovl_config config;
34 	/* creds of process who forced instantiation of super block */
35 	const struct cred *creator_cred;
36 	bool tmpfile;
37 	bool noxattr;
38 	/* sb common to all layers */
39 	struct super_block *same_sb;
40 	/* Did we take the inuse lock? */
41 	bool upperdir_locked;
42 	bool workdir_locked;
43 };
44 
45 /* private information held for every overlayfs dentry */
46 struct ovl_entry {
47 	union {
48 		struct {
49 			unsigned long has_upper;
50 			bool opaque;
51 		};
52 		struct rcu_head rcu;
53 	};
54 	unsigned numlower;
55 	struct path lowerstack[];
56 };
57 
58 struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
59 
60 struct ovl_inode {
61 	struct ovl_dir_cache *cache;
62 	const char *redirect;
63 	u64 version;
64 	unsigned long flags;
65 	struct inode vfs_inode;
66 	struct dentry *__upperdentry;
67 	struct inode *lower;
68 
69 	/* synchronize copy up and more */
70 	struct mutex lock;
71 };
72 
73 static inline struct ovl_inode *OVL_I(struct inode *inode)
74 {
75 	return container_of(inode, struct ovl_inode, vfs_inode);
76 }
77 
78 static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
79 {
80 	return READ_ONCE(oi->__upperdentry);
81 }
82