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