blob: 63efee554f69a7c1e862650d8f7b388576fda2cd [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Miklos Szeredibbb1e542016-12-16 11:02:56 +01002/*
3 *
4 * Copyright (C) 2011 Novell Inc.
5 * Copyright (C) 2016 Red Hat, Inc.
Miklos Szeredibbb1e542016-12-16 11:02:56 +01006 */
7
8struct ovl_config {
9 char *lowerdir;
10 char *upperdir;
11 char *workdir;
12 bool default_permissions;
Miklos Szeredia6c60652016-12-16 11:02:56 +010013 bool redirect_dir;
Miklos Szeredi438c84c2017-12-11 11:28:10 +010014 bool redirect_follow;
15 const char *redirect_mode;
Amir Goldstein02bcd152017-06-21 15:28:36 +030016 bool index;
Pavel Tikhomirov5830fb62020-10-13 17:59:54 +030017 bool uuid;
Amir Goldsteinf168f102018-01-19 11:26:53 +020018 bool nfs_export;
Amir Goldstein795939a2018-03-29 09:08:18 +030019 int xino;
Vivek Goyald5791042018-05-11 11:49:27 -040020 bool metacopy;
Miklos Szeredi2d2f2d72020-12-14 15:26:14 +010021 bool userxattr;
Vivek Goyalc86243b02020-08-31 14:15:29 -040022 bool ovl_volatile;
Miklos Szeredibbb1e542016-12-16 11:02:56 +010023};
24
Amir Goldstein51486262018-03-28 20:22:41 +030025struct ovl_sb {
26 struct super_block *sb;
27 dev_t pseudo_dev;
Amir Goldstein7e63c872019-11-14 22:28:41 +020028 /* Unusable (conflicting) uuid */
29 bool bad_uuid;
Amir Goldstein1b81ddd2019-11-16 18:52:20 +020030 /* Used as a lower layer (but maybe also as upper) */
31 bool is_lower;
Amir Goldstein51486262018-03-28 20:22:41 +030032};
33
Chandan Rajendrab9343632017-07-24 01:57:54 -050034struct ovl_layer {
35 struct vfsmount *mnt;
Amir Goldstein146d62e2019-04-18 17:42:08 +030036 /* Trap in ovl inode cache */
37 struct inode *trap;
Amir Goldstein51486262018-03-28 20:22:41 +030038 struct ovl_sb *fs;
39 /* Index of this layer in fs root (upper idx == 0) */
Amir Goldsteind583ed72017-11-08 19:23:36 +020040 int idx;
Amir Goldstein51486262018-03-28 20:22:41 +030041 /* One fsid per unique underlying sb (upper fsid == 0) */
42 int fsid;
Chandan Rajendrab9343632017-07-24 01:57:54 -050043};
44
45struct ovl_path {
Miklos Szeredi13464162020-01-24 09:46:45 +010046 const struct ovl_layer *layer;
Chandan Rajendrab9343632017-07-24 01:57:54 -050047 struct dentry *dentry;
48};
49
Miklos Szeredibbb1e542016-12-16 11:02:56 +010050/* private information held for overlayfs's superblock */
51struct ovl_fs {
Amir Goldstein94375f92019-11-15 14:12:40 +020052 unsigned int numlayer;
Amir Goldstein07f1e592020-01-14 21:59:22 +020053 /* Number of unique fs among layers including upper fs */
54 unsigned int numfs;
Miklos Szeredi13464162020-01-24 09:46:45 +010055 const struct ovl_layer *layers;
Amir Goldstein07f1e592020-01-14 21:59:22 +020056 struct ovl_sb *fs;
Amir Goldstein2cac0c02017-06-21 15:28:33 +030057 /* workbasedir is the path at workdir= mount option */
58 struct dentry *workbasedir;
59 /* workdir is the 'work' directory under workbasedir */
Miklos Szeredibbb1e542016-12-16 11:02:56 +010060 struct dentry *workdir;
Amir Goldstein02bcd152017-06-21 15:28:36 +030061 /* index directory listing overlay inodes by origin file handle */
62 struct dentry *indexdir;
Miklos Szeredi6b2d5fe2016-12-16 11:02:56 +010063 long namelen;
Miklos Szeredibbb1e542016-12-16 11:02:56 +010064 /* pathnames of lower and upper dirs, for show_options */
65 struct ovl_config config;
66 /* creds of process who forced instantiation of super block */
67 const struct cred *creator_cred;
Amir Goldsteine7f52422017-01-17 06:34:53 +020068 bool tmpfile;
Amir Goldstein82b749b2017-05-17 00:12:40 +030069 bool noxattr;
Amir Goldstein85fdee12017-09-29 10:21:21 +030070 /* Did we take the inuse lock? */
71 bool upperdir_locked;
72 bool workdir_locked;
Chengguang Xuc21c8392020-04-24 10:55:17 +080073 bool share_whiteout;
Amir Goldstein146d62e2019-04-18 17:42:08 +030074 /* Traps in ovl inode cache */
Amir Goldstein0be0bfd2019-07-12 15:24:34 +030075 struct inode *workbasedir_trap;
Amir Goldstein146d62e2019-04-18 17:42:08 +030076 struct inode *workdir_trap;
77 struct inode *indexdir_trap;
Amir Goldstein0f831ec2019-11-16 18:14:41 +020078 /* -1: disabled, 0: same fs, 1..32: number of unused ino bits */
79 int xino_mode;
Amir Goldstein4d314f72020-02-21 16:34:43 +020080 /* For allocation of non-persistent inode numbers */
81 atomic_long_t last_ino;
Chengguang Xuc21c8392020-04-24 10:55:17 +080082 /* Whiteout dentry cache */
83 struct dentry *whiteout;
Sargun Dhillon335d3fc2021-01-07 16:10:43 -080084 /* r/o snapshot of upperdir sb's only taken on volatile mounts */
85 errseq_t errseq;
Miklos Szeredibbb1e542016-12-16 11:02:56 +010086};
87
Miklos Szeredi08f4c7c2020-06-04 10:48:19 +020088static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
89{
Miklos Szeredib8e42a62020-06-04 10:48:19 +020090 return ofs->layers[0].mnt;
Miklos Szeredi08f4c7c2020-06-04 10:48:19 +020091}
92
Amir Goldstein0f831ec2019-11-16 18:14:41 +020093static inline struct ovl_fs *OVL_FS(struct super_block *sb)
94{
95 return (struct ovl_fs *)sb->s_fs_info;
96}
97
Vivek Goyalc86243b02020-08-31 14:15:29 -040098static inline bool ovl_should_sync(struct ovl_fs *ofs)
99{
100 return !ofs->config.ovl_volatile;
101}
102
Miklos Szeredibbb1e542016-12-16 11:02:56 +0100103/* private information held for every overlayfs dentry */
104struct ovl_entry {
Miklos Szeredibbb1e542016-12-16 11:02:56 +0100105 union {
Miklos Szeredi55acc662017-07-04 22:03:18 +0200106 struct {
Amir Goldsteinc62520a2018-01-14 19:25:31 +0200107 unsigned long flags;
Miklos Szeredi55acc662017-07-04 22:03:18 +0200108 };
Miklos Szeredibbb1e542016-12-16 11:02:56 +0100109 struct rcu_head rcu;
110 };
111 unsigned numlower;
Chandan Rajendrab9343632017-07-24 01:57:54 -0500112 struct ovl_path lowerstack[];
Miklos Szeredibbb1e542016-12-16 11:02:56 +0100113};
114
115struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
116
Amir Goldsteinc62520a2018-01-14 19:25:31 +0200117static inline struct ovl_entry *OVL_E(struct dentry *dentry)
118{
119 return (struct ovl_entry *) dentry->d_fsdata;
120}
121
Amir Goldstein13cf1992017-06-12 09:54:40 +0300122struct ovl_inode {
Vivek Goyal2664bd02018-05-11 11:49:30 -0400123 union {
124 struct ovl_dir_cache *cache; /* directory */
125 struct inode *lowerdata; /* regular file */
126 };
Miklos Szeredicf31c462017-07-04 22:03:16 +0200127 const char *redirect;
Miklos Szeredi04a01ac2017-07-04 22:03:16 +0200128 u64 version;
Miklos Szeredi13c72072017-07-04 22:03:16 +0200129 unsigned long flags;
Amir Goldstein13cf1992017-06-12 09:54:40 +0300130 struct inode vfs_inode;
Miklos Szeredi09d8b582017-07-04 22:03:16 +0200131 struct dentry *__upperdentry;
Miklos Szeredi25b77132017-07-04 22:03:16 +0200132 struct inode *lower;
Amir Goldsteina015daf2017-06-21 15:28:51 +0300133
134 /* synchronize copy up and more */
135 struct mutex lock;
Amir Goldstein13cf1992017-06-12 09:54:40 +0300136};
137
138static inline struct ovl_inode *OVL_I(struct inode *inode)
139{
140 return container_of(inode, struct ovl_inode, vfs_inode);
141}
Miklos Szeredi09d8b582017-07-04 22:03:16 +0200142
143static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
144{
Will Deacon506458e2017-10-24 11:22:48 +0100145 return READ_ONCE(oi->__upperdentry);
Miklos Szeredi09d8b582017-07-04 22:03:16 +0200146}