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; |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 17 | bool index; |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 18 | }; |
| 19 | |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame] | 20 | struct ovl_layer { |
| 21 | struct vfsmount *mnt; |
Chandan Rajendra | 2a9c6d0 | 2017-11-01 20:12:49 +0200 | [diff] [blame] | 22 | dev_t pseudo_dev; |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame] | 23 | }; |
| 24 | |
| 25 | struct ovl_path { |
| 26 | struct ovl_layer *layer; |
| 27 | struct dentry *dentry; |
| 28 | }; |
| 29 | |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 30 | /* private information held for overlayfs's superblock */ |
| 31 | struct ovl_fs { |
| 32 | struct vfsmount *upper_mnt; |
| 33 | unsigned numlower; |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame] | 34 | struct ovl_layer *lower_layers; |
Amir Goldstein | 2cac0c0 | 2017-06-21 15:28:33 +0300 | [diff] [blame] | 35 | /* workbasedir is the path at workdir= mount option */ |
| 36 | struct dentry *workbasedir; |
| 37 | /* workdir is the 'work' directory under workbasedir */ |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 38 | struct dentry *workdir; |
Amir Goldstein | 02bcd15 | 2017-06-21 15:28:36 +0300 | [diff] [blame] | 39 | /* index directory listing overlay inodes by origin file handle */ |
| 40 | struct dentry *indexdir; |
Miklos Szeredi | 6b2d5fe | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 41 | long namelen; |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 42 | /* pathnames of lower and upper dirs, for show_options */ |
| 43 | struct ovl_config config; |
| 44 | /* creds of process who forced instantiation of super block */ |
| 45 | const struct cred *creator_cred; |
Amir Goldstein | e7f5242 | 2017-01-17 06:34:53 +0200 | [diff] [blame] | 46 | bool tmpfile; |
Amir Goldstein | 82b749b | 2017-05-17 00:12:40 +0300 | [diff] [blame] | 47 | bool noxattr; |
Amir Goldstein | 7bcd74b | 2017-03-22 08:42:21 -0400 | [diff] [blame] | 48 | /* sb common to all layers */ |
| 49 | struct super_block *same_sb; |
Amir Goldstein | 85fdee1 | 2017-09-29 10:21:21 +0300 | [diff] [blame] | 50 | /* Did we take the inuse lock? */ |
| 51 | bool upperdir_locked; |
| 52 | bool workdir_locked; |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | /* private information held for every overlayfs dentry */ |
| 56 | struct ovl_entry { |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 57 | union { |
Miklos Szeredi | 55acc66 | 2017-07-04 22:03:18 +0200 | [diff] [blame] | 58 | struct { |
| 59 | unsigned long has_upper; |
| 60 | bool opaque; |
| 61 | }; |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 62 | struct rcu_head rcu; |
| 63 | }; |
| 64 | unsigned numlower; |
Chandan Rajendra | b934363 | 2017-07-24 01:57:54 -0500 | [diff] [blame] | 65 | struct ovl_path lowerstack[]; |
Miklos Szeredi | bbb1e54 | 2016-12-16 11:02:56 +0100 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | struct ovl_entry *ovl_alloc_entry(unsigned int numlower); |
| 69 | |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 70 | struct ovl_inode { |
Miklos Szeredi | 04a01ac | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 71 | struct ovl_dir_cache *cache; |
Miklos Szeredi | cf31c46 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 72 | const char *redirect; |
Miklos Szeredi | 04a01ac | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 73 | u64 version; |
Miklos Szeredi | 13c7207 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 74 | unsigned long flags; |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 75 | struct inode vfs_inode; |
Miklos Szeredi | 09d8b58 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 76 | struct dentry *__upperdentry; |
Miklos Szeredi | 25b7713 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 77 | struct inode *lower; |
Amir Goldstein | a015daf | 2017-06-21 15:28:51 +0300 | [diff] [blame] | 78 | |
| 79 | /* synchronize copy up and more */ |
| 80 | struct mutex lock; |
Amir Goldstein | 13cf199 | 2017-06-12 09:54:40 +0300 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | static inline struct ovl_inode *OVL_I(struct inode *inode) |
| 84 | { |
| 85 | return container_of(inode, struct ovl_inode, vfs_inode); |
| 86 | } |
Miklos Szeredi | 09d8b58 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 87 | |
| 88 | static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi) |
| 89 | { |
Will Deacon | 506458e | 2017-10-24 11:22:48 +0100 | [diff] [blame] | 90 | return READ_ONCE(oi->__upperdentry); |
Miklos Szeredi | 09d8b58 | 2017-07-04 22:03:16 +0200 | [diff] [blame] | 91 | } |