blob: 304f95f8789f170463eeb6b56a78ee21d2d5e330 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 *
4 * Copyright (C) 2011 Novell Inc.
5 * Copyright (C) 2016 Red Hat, Inc.
6 */
7
8enum {
9 OVL_FSYNC_STRICT,
10 OVL_FSYNC_ORDERED,
11 OVL_FSYNC_VOLATILE,
12};
13
14struct ovl_config {
15 char *lowerdir;
16 char *upperdir;
17 char *workdir;
18 bool default_permissions;
19 bool redirect_dir;
20 bool redirect_follow;
21 const char *redirect_mode;
22 bool index;
23 bool nfs_export;
24 int xino;
25 bool metacopy;
26 bool override_creds;
27 int fsync_mode;
28};
29
30struct ovl_sb {
31 struct super_block *sb;
32 dev_t pseudo_dev;
33 /* Unusable (conflicting) uuid */
34 bool bad_uuid;
35};
36
37struct ovl_layer {
38 /* ovl_free_fs() relies on @mnt being the first member! */
39 struct vfsmount *mnt;
40 /* Trap in ovl inode cache */
41 struct inode *trap;
42 struct ovl_sb *fs;
43 /* Index of this layer in fs root (upper idx == 0) */
44 int idx;
45 /* One fsid per unique underlying sb (upper fsid == 0) */
46 int fsid;
47};
48
49/*
50 * ovl_free_fs() relies on @mnt being the first member when unmounting
51 * the private mounts created for each layer. Let's check both the
52 * offset and type.
53 */
54static_assert(offsetof(struct ovl_layer, mnt) == 0);
55static_assert(__same_type(typeof_member(struct ovl_layer, mnt), struct vfsmount *));
56
57struct ovl_path {
58 struct ovl_layer *layer;
59 struct dentry *dentry;
60};
61
62/* private information held for overlayfs's superblock */
63struct ovl_fs {
64 struct vfsmount *upper_mnt;
65 unsigned int numlower;
66 /* Number of unique lower sb that differ from upper sb */
67 unsigned int numlowerfs;
68 struct ovl_layer *lower_layers;
69 struct ovl_sb *lower_fs;
70 /* workbasedir is the path at workdir= mount option */
71 struct dentry *workbasedir;
72 /* workdir is the 'work' directory under workbasedir */
73 struct dentry *workdir;
74 /* index directory listing overlay inodes by origin file handle */
75 struct dentry *indexdir;
76 long namelen;
77 /* pathnames of lower and upper dirs, for show_options */
78 struct ovl_config config;
79 /* creds of process who forced instantiation of super block */
80 const struct cred *creator_cred;
81 bool tmpfile;
82 bool noxattr;
83 /* Did we take the inuse lock? */
84 bool upperdir_locked;
85 bool workdir_locked;
86 /* Traps in ovl inode cache */
87 struct inode *upperdir_trap;
88 struct inode *workbasedir_trap;
89 struct inode *workdir_trap;
90 struct inode *indexdir_trap;
91 /* Inode numbers in all layers do not use the high xino_bits */
92 unsigned int xino_bits;
93};
94
95/* private information held for every overlayfs dentry */
96struct ovl_entry {
97 union {
98 struct {
99 unsigned long flags;
100 };
101 struct rcu_head rcu;
102 };
103 unsigned numlower;
104 struct ovl_path lowerstack[];
105};
106
107struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
108
109static inline struct ovl_entry *OVL_E(struct dentry *dentry)
110{
111 return (struct ovl_entry *) dentry->d_fsdata;
112}
113
114static inline bool ovl_should_sync(struct ovl_fs *ofs)
115{
116 return ofs->config.fsync_mode != OVL_FSYNC_VOLATILE;
117}
118
119static inline bool ovl_should_sync_strict(struct ovl_fs *ofs)
120{
121 return ofs->config.fsync_mode == OVL_FSYNC_STRICT;
122}
123
124struct ovl_inode {
125 union {
126 struct ovl_dir_cache *cache; /* directory */
127 struct inode *lowerdata; /* regular file */
128 };
129 const char *redirect;
130 u64 version;
131 unsigned long flags;
132 struct inode vfs_inode;
133 struct dentry *__upperdentry;
134 struct inode *lower;
135
136 /* synchronize copy up and more */
137 struct mutex lock;
138};
139
140static inline struct ovl_inode *OVL_I(struct inode *inode)
141{
142 return container_of(inode, struct ovl_inode, vfs_inode);
143}
144
145static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
146{
147 return READ_ONCE(oi->__upperdentry);
148}