Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 11 | struct ovl_config { |
| 12 | char *lowerdir; |
| 13 | char *upperdir; |
| 14 | char *workdir; |
| 15 | bool default_permissions; |
Miklos Szeredi | a6c6065 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 16 | bool redirect_dir; |
Miklos Szeredi | 438c84c | 2017-12-11 11:28:10 +0100 | [diff] [blame] | 17 | bool redirect_follow; |
| 18 | const char *redirect_mode; |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 19 | bool index; |
Amir Goldstein | f168f10 | 2018-01-19 11:26:53 +0200 | [diff] [blame] | 20 | bool nfs_export; |
Amir Goldstein | 795939a | 2018-03-29 09:08:18 +0300 | [diff] [blame] | 21 | int xino; |
Vivek Goyal | d579104 | 2018-05-11 11:49:27 -0400 | [diff] [blame] | 22 | bool metacopy; |
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; |
| 28 | }; |
| 29 | |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame] | 30 | struct ovl_layer { |
| 31 | struct vfsmount *mnt; |
Amir Goldstein | 5148626 | 2018-03-28 20:22:41 +0300 | [diff] [blame] | 32 | struct ovl_sb *fs; |
| 33 | /* Index of this layer in fs root (upper idx == 0) */ |
Amir Goldstein | d583ed7 | 2017-11-08 19:23:36 +0200 | [diff] [blame] | 34 | int idx; |
Amir Goldstein | 5148626 | 2018-03-28 20:22:41 +0300 | [diff] [blame] | 35 | /* One fsid per unique underlying sb (upper fsid == 0) */ |
| 36 | int fsid; |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | struct ovl_path { |
| 40 | struct ovl_layer *layer; |
| 41 | struct dentry *dentry; |
| 42 | }; |
| 43 | |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 44 | /* private information held for overlayfs's superblock */ |
| 45 | struct ovl_fs { |
| 46 | struct vfsmount *upper_mnt; |
Amir Goldstein | 5148626 | 2018-03-28 20:22:41 +0300 | [diff] [blame] | 47 | unsigned int numlower; |
| 48 | /* Number of unique lower sb that differ from upper sb */ |
| 49 | unsigned int numlowerfs; |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame] | 50 | struct ovl_layer *lower_layers; |
Amir Goldstein | 5148626 | 2018-03-28 20:22:41 +0300 | [diff] [blame] | 51 | struct ovl_sb *lower_fs; |
Amir Goldstein | 2cac0c0 | 2017-06-21 15:28:33 +0300 | [diff] [blame] | 52 | /* workbasedir is the path at workdir= mount option */ |
| 53 | struct dentry *workbasedir; |
| 54 | /* workdir is the 'work' directory under workbasedir */ |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 55 | struct dentry *workdir; |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 56 | /* index directory listing overlay inodes by origin file handle */ |
| 57 | struct dentry *indexdir; |
Miklos Szeredi | 6b2d5fe | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 58 | long namelen; |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 59 | /* pathnames of lower and upper dirs, for show_options */ |
| 60 | struct ovl_config config; |
| 61 | /* creds of process who forced instantiation of super block */ |
| 62 | const struct cred *creator_cred; |
Amir Goldstein | e7f5242 | 2017-01-17 06:34:53 +0200 | [diff] [blame] | 63 | bool tmpfile; |
Amir Goldstein | 82b749b | 2017-05-17 00:12:40 +0300 | [diff] [blame] | 64 | bool noxattr; |
Amir Goldstein | 85fdee1 | 2017-09-29 10:21:21 +0300 | [diff] [blame] | 65 | /* Did we take the inuse lock? */ |
| 66 | bool upperdir_locked; |
| 67 | bool workdir_locked; |
Amir Goldstein | e487d88 | 2017-11-07 13:55:04 +0200 | [diff] [blame] | 68 | /* Inode numbers in all layers do not use the high xino_bits */ |
| 69 | unsigned int xino_bits; |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | /* private information held for every overlayfs dentry */ |
| 73 | struct ovl_entry { |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 74 | union { |
Miklos Szeredi | 55acc66 | 2017-07-04 22:03:18 +0200 | [diff] [blame] | 75 | struct { |
Amir Goldstein | c62520a | 2018-01-14 19:25:31 +0200 | [diff] [blame] | 76 | unsigned long flags; |
Miklos Szeredi | 55acc66 | 2017-07-04 22:03:18 +0200 | [diff] [blame] | 77 | }; |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 78 | struct rcu_head rcu; |
| 79 | }; |
| 80 | unsigned numlower; |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame] | 81 | struct ovl_path lowerstack[]; |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | struct ovl_entry *ovl_alloc_entry(unsigned int numlower); |
| 85 | |
Amir Goldstein | c62520a | 2018-01-14 19:25:31 +0200 | [diff] [blame] | 86 | static inline struct ovl_entry *OVL_E(struct dentry *dentry) |
| 87 | { |
| 88 | return (struct ovl_entry *) dentry->d_fsdata; |
| 89 | } |
| 90 | |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 91 | struct ovl_inode { |
Vivek Goyal | 2664bd0 | 2018-05-11 11:49:30 -0400 | [diff] [blame] | 92 | union { |
| 93 | struct ovl_dir_cache *cache; /* directory */ |
| 94 | struct inode *lowerdata; /* regular file */ |
| 95 | }; |
Miklos Szeredi | cf31c46 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 96 | const char *redirect; |
Miklos Szeredi | 04a01ac | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 97 | u64 version; |
Miklos Szeredi | 13c7207 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 98 | unsigned long flags; |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 99 | struct inode vfs_inode; |
Miklos Szeredi | 09d8b58 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 100 | struct dentry *__upperdentry; |
Miklos Szeredi | 25b7713 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 101 | struct inode *lower; |
Amir Goldstein | a015daf | 2017-06-21 15:28:51 +0300 | [diff] [blame] | 102 | |
| 103 | /* synchronize copy up and more */ |
| 104 | struct mutex lock; |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | static inline struct ovl_inode *OVL_I(struct inode *inode) |
| 108 | { |
| 109 | return container_of(inode, struct ovl_inode, vfs_inode); |
| 110 | } |
Miklos Szeredi | 09d8b58 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 111 | |
| 112 | static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi) |
| 113 | { |
Will Deacon | 506458e | 2017-10-24 11:22:48 +0100 | [diff] [blame] | 114 | return READ_ONCE(oi->__upperdentry); |
Miklos Szeredi | 09d8b58 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 115 | } |