Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 2 | /* |
| 3 | * |
| 4 | * Copyright (C) 2011 Novell Inc. |
| 5 | * Copyright (C) 2016 Red Hat, Inc. |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | struct ovl_config { |
| 9 | char *lowerdir; |
| 10 | char *upperdir; |
| 11 | char *workdir; |
| 12 | bool default_permissions; |
Miklos Szeredi | a6c6065 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 13 | bool redirect_dir; |
Miklos Szeredi | 438c84c | 2017-12-11 11:28:10 +0100 | [diff] [blame] | 14 | bool redirect_follow; |
| 15 | const char *redirect_mode; |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 16 | bool index; |
Pavel Tikhomirov | 5830fb6 | 2020-10-13 17:59:54 +0300 | [diff] [blame] | 17 | bool uuid; |
Amir Goldstein | f168f10 | 2018-01-19 11:26:53 +0200 | [diff] [blame] | 18 | bool nfs_export; |
Amir Goldstein | 795939a | 2018-03-29 09:08:18 +0300 | [diff] [blame] | 19 | int xino; |
Vivek Goyal | d579104 | 2018-05-11 11:49:27 -0400 | [diff] [blame] | 20 | bool metacopy; |
Miklos Szeredi | 2d2f2d7 | 2020-12-14 15:26:14 +0100 | [diff] [blame] | 21 | bool userxattr; |
Vivek Goyal | c86243b0 | 2020-08-31 14:15:29 -0400 | [diff] [blame] | 22 | bool ovl_volatile; |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 23 | }; |
| 24 | |
Amir Goldstein | 5148626 | 2018-03-28 20:22:41 +0300 | [diff] [blame] | 25 | struct ovl_sb { |
| 26 | struct super_block *sb; |
| 27 | dev_t pseudo_dev; |
Amir Goldstein | 7e63c87 | 2019-11-14 22:28:41 +0200 | [diff] [blame] | 28 | /* Unusable (conflicting) uuid */ |
| 29 | bool bad_uuid; |
Amir Goldstein | 1b81ddd | 2019-11-16 18:52:20 +0200 | [diff] [blame] | 30 | /* Used as a lower layer (but maybe also as upper) */ |
| 31 | bool is_lower; |
Amir Goldstein | 5148626 | 2018-03-28 20:22:41 +0300 | [diff] [blame] | 32 | }; |
| 33 | |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame] | 34 | struct ovl_layer { |
| 35 | struct vfsmount *mnt; |
Amir Goldstein | 146d62e | 2019-04-18 17:42:08 +0300 | [diff] [blame] | 36 | /* Trap in ovl inode cache */ |
| 37 | struct inode *trap; |
Amir Goldstein | 5148626 | 2018-03-28 20:22:41 +0300 | [diff] [blame] | 38 | struct ovl_sb *fs; |
| 39 | /* Index of this layer in fs root (upper idx == 0) */ |
Amir Goldstein | d583ed7 | 2017-11-08 19:23:36 +0200 | [diff] [blame] | 40 | int idx; |
Amir Goldstein | 5148626 | 2018-03-28 20:22:41 +0300 | [diff] [blame] | 41 | /* One fsid per unique underlying sb (upper fsid == 0) */ |
| 42 | int fsid; |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | struct ovl_path { |
Miklos Szeredi | 1346416 | 2020-01-24 09:46:45 +0100 | [diff] [blame] | 46 | const struct ovl_layer *layer; |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame] | 47 | struct dentry *dentry; |
| 48 | }; |
| 49 | |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 50 | /* private information held for overlayfs's superblock */ |
| 51 | struct ovl_fs { |
Amir Goldstein | 94375f9 | 2019-11-15 14:12:40 +0200 | [diff] [blame] | 52 | unsigned int numlayer; |
Amir Goldstein | 07f1e59 | 2020-01-14 21:59:22 +0200 | [diff] [blame] | 53 | /* Number of unique fs among layers including upper fs */ |
| 54 | unsigned int numfs; |
Miklos Szeredi | 1346416 | 2020-01-24 09:46:45 +0100 | [diff] [blame] | 55 | const struct ovl_layer *layers; |
Amir Goldstein | 07f1e59 | 2020-01-14 21:59:22 +0200 | [diff] [blame] | 56 | struct ovl_sb *fs; |
Amir Goldstein | 2cac0c0 | 2017-06-21 15:28:33 +0300 | [diff] [blame] | 57 | /* workbasedir is the path at workdir= mount option */ |
| 58 | struct dentry *workbasedir; |
| 59 | /* workdir is the 'work' directory under workbasedir */ |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 60 | struct dentry *workdir; |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 61 | /* index directory listing overlay inodes by origin file handle */ |
| 62 | struct dentry *indexdir; |
Miklos Szeredi | 6b2d5fe | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 63 | long namelen; |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 64 | /* 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 Goldstein | e7f5242 | 2017-01-17 06:34:53 +0200 | [diff] [blame] | 68 | bool tmpfile; |
Amir Goldstein | 82b749b | 2017-05-17 00:12:40 +0300 | [diff] [blame] | 69 | bool noxattr; |
Amir Goldstein | 85fdee1 | 2017-09-29 10:21:21 +0300 | [diff] [blame] | 70 | /* Did we take the inuse lock? */ |
| 71 | bool upperdir_locked; |
| 72 | bool workdir_locked; |
Chengguang Xu | c21c839 | 2020-04-24 10:55:17 +0800 | [diff] [blame] | 73 | bool share_whiteout; |
Amir Goldstein | 146d62e | 2019-04-18 17:42:08 +0300 | [diff] [blame] | 74 | /* Traps in ovl inode cache */ |
Amir Goldstein | 0be0bfd | 2019-07-12 15:24:34 +0300 | [diff] [blame] | 75 | struct inode *workbasedir_trap; |
Amir Goldstein | 146d62e | 2019-04-18 17:42:08 +0300 | [diff] [blame] | 76 | struct inode *workdir_trap; |
| 77 | struct inode *indexdir_trap; |
Amir Goldstein | 0f831ec | 2019-11-16 18:14:41 +0200 | [diff] [blame] | 78 | /* -1: disabled, 0: same fs, 1..32: number of unused ino bits */ |
| 79 | int xino_mode; |
Amir Goldstein | 4d314f7 | 2020-02-21 16:34:43 +0200 | [diff] [blame] | 80 | /* For allocation of non-persistent inode numbers */ |
| 81 | atomic_long_t last_ino; |
Chengguang Xu | c21c839 | 2020-04-24 10:55:17 +0800 | [diff] [blame] | 82 | /* Whiteout dentry cache */ |
| 83 | struct dentry *whiteout; |
Sargun Dhillon | 335d3fc | 2021-01-07 16:10:43 -0800 | [diff] [blame] | 84 | /* r/o snapshot of upperdir sb's only taken on volatile mounts */ |
| 85 | errseq_t errseq; |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 86 | }; |
| 87 | |
Miklos Szeredi | 08f4c7c | 2020-06-04 10:48:19 +0200 | [diff] [blame] | 88 | static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs) |
| 89 | { |
Miklos Szeredi | b8e42a6 | 2020-06-04 10:48:19 +0200 | [diff] [blame] | 90 | return ofs->layers[0].mnt; |
Miklos Szeredi | 08f4c7c | 2020-06-04 10:48:19 +0200 | [diff] [blame] | 91 | } |
| 92 | |
Amir Goldstein | 0f831ec | 2019-11-16 18:14:41 +0200 | [diff] [blame] | 93 | static inline struct ovl_fs *OVL_FS(struct super_block *sb) |
| 94 | { |
| 95 | return (struct ovl_fs *)sb->s_fs_info; |
| 96 | } |
| 97 | |
Vivek Goyal | c86243b0 | 2020-08-31 14:15:29 -0400 | [diff] [blame] | 98 | static inline bool ovl_should_sync(struct ovl_fs *ofs) |
| 99 | { |
| 100 | return !ofs->config.ovl_volatile; |
| 101 | } |
| 102 | |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 103 | /* private information held for every overlayfs dentry */ |
| 104 | struct ovl_entry { |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 105 | union { |
Miklos Szeredi | 55acc66 | 2017-07-04 22:03:18 +0200 | [diff] [blame] | 106 | struct { |
Amir Goldstein | c62520a | 2018-01-14 19:25:31 +0200 | [diff] [blame] | 107 | unsigned long flags; |
Miklos Szeredi | 55acc66 | 2017-07-04 22:03:18 +0200 | [diff] [blame] | 108 | }; |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 109 | struct rcu_head rcu; |
| 110 | }; |
| 111 | unsigned numlower; |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame] | 112 | struct ovl_path lowerstack[]; |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | struct ovl_entry *ovl_alloc_entry(unsigned int numlower); |
| 116 | |
Amir Goldstein | c62520a | 2018-01-14 19:25:31 +0200 | [diff] [blame] | 117 | static inline struct ovl_entry *OVL_E(struct dentry *dentry) |
| 118 | { |
| 119 | return (struct ovl_entry *) dentry->d_fsdata; |
| 120 | } |
| 121 | |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 122 | struct ovl_inode { |
Vivek Goyal | 2664bd0 | 2018-05-11 11:49:30 -0400 | [diff] [blame] | 123 | union { |
| 124 | struct ovl_dir_cache *cache; /* directory */ |
| 125 | struct inode *lowerdata; /* regular file */ |
| 126 | }; |
Miklos Szeredi | cf31c46 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 127 | const char *redirect; |
Miklos Szeredi | 04a01ac | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 128 | u64 version; |
Miklos Szeredi | 13c7207 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 129 | unsigned long flags; |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 130 | struct inode vfs_inode; |
Miklos Szeredi | 09d8b58 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 131 | struct dentry *__upperdentry; |
Miklos Szeredi | 25b7713 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 132 | struct inode *lower; |
Amir Goldstein | a015daf | 2017-06-21 15:28:51 +0300 | [diff] [blame] | 133 | |
| 134 | /* synchronize copy up and more */ |
| 135 | struct mutex lock; |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | static inline struct ovl_inode *OVL_I(struct inode *inode) |
| 139 | { |
| 140 | return container_of(inode, struct ovl_inode, vfs_inode); |
| 141 | } |
Miklos Szeredi | 09d8b58 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 142 | |
| 143 | static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi) |
| 144 | { |
Will Deacon | 506458e | 2017-10-24 11:22:48 +0100 | [diff] [blame] | 145 | return READ_ONCE(oi->__upperdentry); |
Miklos Szeredi | 09d8b58 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 146 | } |