blob: dc062288f24ce55f8efae5bdf68552715000ad38 [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001/*
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
11struct 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 int xino;
22 bool metacopy;
23 bool override_creds;
24};
25
26struct ovl_sb {
27 struct super_block *sb;
28 dev_t pseudo_dev;
29};
30
31struct 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
42struct ovl_path {
43 struct ovl_layer *layer;
44 struct dentry *dentry;
45};
46
47/* private information held for overlayfs's superblock */
48struct ovl_fs {
49 struct vfsmount *upper_mnt;
50 unsigned int numlower;
51 /* Number of unique lower sb that differ from upper sb */
52 unsigned int numlowerfs;
53 struct ovl_layer *lower_layers;
54 struct ovl_sb *lower_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 /* Inode numbers in all layers do not use the high xino_bits */
77 unsigned int xino_bits;
78};
79
80/* private information held for every overlayfs dentry */
81struct ovl_entry {
82 union {
83 struct {
84 unsigned long flags;
85 };
86 struct rcu_head rcu;
87 };
88 unsigned numlower;
89 struct ovl_path lowerstack[];
90};
91
92struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
93
94static inline struct ovl_entry *OVL_E(struct dentry *dentry)
95{
96 return (struct ovl_entry *) dentry->d_fsdata;
97}
98
99struct ovl_inode {
100 union {
101 struct ovl_dir_cache *cache; /* directory */
102 struct inode *lowerdata; /* regular file */
103 };
104 const char *redirect;
105 u64 version;
106 unsigned long flags;
107 struct inode vfs_inode;
108 struct dentry *__upperdentry;
109 struct inode *lower;
110
111 /* synchronize copy up and more */
112 struct mutex lock;
113};
114
115static inline struct ovl_inode *OVL_I(struct inode *inode)
116{
117 return container_of(inode, struct ovl_inode, vfs_inode);
118}
119
120static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
121{
122 return READ_ONCE(oi->__upperdentry);
123}