b7a73ea147b8f6a2389eca78cbc00664a49f8c39
[linux-2.6-microblaze.git] / fs / overlayfs / ovl_entry.h
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 uuid;
18         bool nfs_export;
19         int xino;
20         bool metacopy;
21         bool ovl_volatile;
22 };
23
24 struct ovl_sb {
25         struct super_block *sb;
26         dev_t pseudo_dev;
27         /* Unusable (conflicting) uuid */
28         bool bad_uuid;
29         /* Used as a lower layer (but maybe also as upper) */
30         bool is_lower;
31 };
32
33 struct ovl_layer {
34         struct vfsmount *mnt;
35         /* Trap in ovl inode cache */
36         struct inode *trap;
37         struct ovl_sb *fs;
38         /* Index of this layer in fs root (upper idx == 0) */
39         int idx;
40         /* One fsid per unique underlying sb (upper fsid == 0) */
41         int fsid;
42 };
43
44 struct ovl_path {
45         const struct ovl_layer *layer;
46         struct dentry *dentry;
47 };
48
49 /* private information held for overlayfs's superblock */
50 struct ovl_fs {
51         unsigned int numlayer;
52         /* Number of unique fs among layers including upper fs */
53         unsigned int numfs;
54         const struct ovl_layer *layers;
55         struct ovl_sb *fs;
56         /* workbasedir is the path at workdir= mount option */
57         struct dentry *workbasedir;
58         /* workdir is the 'work' directory under workbasedir */
59         struct dentry *workdir;
60         /* index directory listing overlay inodes by origin file handle */
61         struct dentry *indexdir;
62         long namelen;
63         /* pathnames of lower and upper dirs, for show_options */
64         struct ovl_config config;
65         /* creds of process who forced instantiation of super block */
66         const struct cred *creator_cred;
67         bool tmpfile;
68         bool noxattr;
69         /* Did we take the inuse lock? */
70         bool upperdir_locked;
71         bool workdir_locked;
72         bool share_whiteout;
73         /* Traps in ovl inode cache */
74         struct inode *workbasedir_trap;
75         struct inode *workdir_trap;
76         struct inode *indexdir_trap;
77         /* -1: disabled, 0: same fs, 1..32: number of unused ino bits */
78         int xino_mode;
79         /* For allocation of non-persistent inode numbers */
80         atomic_long_t last_ino;
81         /* Whiteout dentry cache */
82         struct dentry *whiteout;
83 };
84
85 static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
86 {
87         return ofs->layers[0].mnt;
88 }
89
90 static inline struct ovl_fs *OVL_FS(struct super_block *sb)
91 {
92         return (struct ovl_fs *)sb->s_fs_info;
93 }
94
95 static inline bool ovl_should_sync(struct ovl_fs *ofs)
96 {
97         return !ofs->config.ovl_volatile;
98 }
99
100 /* private information held for every overlayfs dentry */
101 struct ovl_entry {
102         union {
103                 struct {
104                         unsigned long flags;
105                 };
106                 struct rcu_head rcu;
107         };
108         unsigned numlower;
109         struct ovl_path lowerstack[];
110 };
111
112 struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
113
114 static inline struct ovl_entry *OVL_E(struct dentry *dentry)
115 {
116         return (struct ovl_entry *) dentry->d_fsdata;
117 }
118
119 struct ovl_inode {
120         union {
121                 struct ovl_dir_cache *cache;    /* directory */
122                 struct inode *lowerdata;        /* regular file */
123         };
124         const char *redirect;
125         u64 version;
126         unsigned long flags;
127         struct inode vfs_inode;
128         struct dentry *__upperdentry;
129         struct inode *lower;
130
131         /* synchronize copy up and more */
132         struct mutex lock;
133 };
134
135 static inline struct ovl_inode *OVL_I(struct inode *inode)
136 {
137         return container_of(inode, struct ovl_inode, vfs_inode);
138 }
139
140 static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
141 {
142         return READ_ONCE(oi->__upperdentry);
143 }