ovl: allocate anon bdev per unique lower fs
[linux] / fs / overlayfs / ovl_entry.h
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 redirect_follow;
18         const char *redirect_mode;
19         bool index;
20         bool nfs_export;
21 };
22
23 struct ovl_sb {
24         struct super_block *sb;
25         dev_t pseudo_dev;
26 };
27
28 struct ovl_layer {
29         struct vfsmount *mnt;
30         struct ovl_sb *fs;
31         /* Index of this layer in fs root (upper idx == 0) */
32         int idx;
33         /* One fsid per unique underlying sb (upper fsid == 0) */
34         int fsid;
35 };
36
37 struct ovl_path {
38         struct ovl_layer *layer;
39         struct dentry *dentry;
40 };
41
42 /* private information held for overlayfs's superblock */
43 struct ovl_fs {
44         struct vfsmount *upper_mnt;
45         unsigned int numlower;
46         /* Number of unique lower sb that differ from upper sb */
47         unsigned int numlowerfs;
48         struct ovl_layer *lower_layers;
49         struct ovl_sb *lower_fs;
50         /* workbasedir is the path at workdir= mount option */
51         struct dentry *workbasedir;
52         /* workdir is the 'work' directory under workbasedir */
53         struct dentry *workdir;
54         /* index directory listing overlay inodes by origin file handle */
55         struct dentry *indexdir;
56         long namelen;
57         /* pathnames of lower and upper dirs, for show_options */
58         struct ovl_config config;
59         /* creds of process who forced instantiation of super block */
60         const struct cred *creator_cred;
61         bool tmpfile;
62         bool noxattr;
63         /* Did we take the inuse lock? */
64         bool upperdir_locked;
65         bool workdir_locked;
66 };
67
68 /* private information held for every overlayfs dentry */
69 struct ovl_entry {
70         union {
71                 struct {
72                         unsigned long flags;
73                 };
74                 struct rcu_head rcu;
75         };
76         unsigned numlower;
77         struct ovl_path lowerstack[];
78 };
79
80 struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
81
82 static inline struct ovl_entry *OVL_E(struct dentry *dentry)
83 {
84         return (struct ovl_entry *) dentry->d_fsdata;
85 }
86
87 struct ovl_inode {
88         struct ovl_dir_cache *cache;
89         const char *redirect;
90         u64 version;
91         unsigned long flags;
92         struct inode vfs_inode;
93         struct dentry *__upperdentry;
94         struct inode *lower;
95
96         /* synchronize copy up and more */
97         struct mutex lock;
98 };
99
100 static inline struct ovl_inode *OVL_I(struct inode *inode)
101 {
102         return container_of(inode, struct ovl_inode, vfs_inode);
103 }
104
105 static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
106 {
107         return READ_ONCE(oi->__upperdentry);
108 }