blob: b7a73ea147b8f6a2389eca78cbc00664a49f8c39 [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;
Vivek Goyalc86243b02020-08-31 14:15:29 -040021 bool ovl_volatile;
Miklos Szeredibbb1e542016-12-16 11:02:56 +010022};
23
Amir Goldstein51486262018-03-28 20:22:41 +030024struct ovl_sb {
25 struct super_block *sb;
26 dev_t pseudo_dev;
Amir Goldstein7e63c872019-11-14 22:28:41 +020027 /* Unusable (conflicting) uuid */
28 bool bad_uuid;
Amir Goldstein1b81ddd2019-11-16 18:52:20 +020029 /* Used as a lower layer (but maybe also as upper) */
30 bool is_lower;
Amir Goldstein51486262018-03-28 20:22:41 +030031};
32
Chandan Rajendrab9343632017-07-24 01:57:54 -050033struct ovl_layer {
34 struct vfsmount *mnt;
Amir Goldstein146d62e2019-04-18 17:42:08 +030035 /* Trap in ovl inode cache */
36 struct inode *trap;
Amir Goldstein51486262018-03-28 20:22:41 +030037 struct ovl_sb *fs;
38 /* Index of this layer in fs root (upper idx == 0) */
Amir Goldsteind583ed72017-11-08 19:23:36 +020039 int idx;
Amir Goldstein51486262018-03-28 20:22:41 +030040 /* One fsid per unique underlying sb (upper fsid == 0) */
41 int fsid;
Chandan Rajendrab9343632017-07-24 01:57:54 -050042};
43
44struct ovl_path {
Miklos Szeredi13464162020-01-24 09:46:45 +010045 const struct ovl_layer *layer;
Chandan Rajendrab9343632017-07-24 01:57:54 -050046 struct dentry *dentry;
47};
48
Miklos Szeredibbb1e542016-12-16 11:02:56 +010049/* private information held for overlayfs's superblock */
50struct ovl_fs {
Amir Goldstein94375f92019-11-15 14:12:40 +020051 unsigned int numlayer;
Amir Goldstein07f1e592020-01-14 21:59:22 +020052 /* Number of unique fs among layers including upper fs */
53 unsigned int numfs;
Miklos Szeredi13464162020-01-24 09:46:45 +010054 const struct ovl_layer *layers;
Amir Goldstein07f1e592020-01-14 21:59:22 +020055 struct ovl_sb *fs;
Amir Goldstein2cac0c02017-06-21 15:28:33 +030056 /* workbasedir is the path at workdir= mount option */
57 struct dentry *workbasedir;
58 /* workdir is the 'work' directory under workbasedir */
Miklos Szeredibbb1e542016-12-16 11:02:56 +010059 struct dentry *workdir;
Amir Goldstein02bcd152017-06-21 15:28:36 +030060 /* index directory listing overlay inodes by origin file handle */
61 struct dentry *indexdir;
Miklos Szeredi6b2d5fe2016-12-16 11:02:56 +010062 long namelen;
Miklos Szeredibbb1e542016-12-16 11:02:56 +010063 /* 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 Goldsteine7f52422017-01-17 06:34:53 +020067 bool tmpfile;
Amir Goldstein82b749b2017-05-17 00:12:40 +030068 bool noxattr;
Amir Goldstein85fdee12017-09-29 10:21:21 +030069 /* Did we take the inuse lock? */
70 bool upperdir_locked;
71 bool workdir_locked;
Chengguang Xuc21c8392020-04-24 10:55:17 +080072 bool share_whiteout;
Amir Goldstein146d62e2019-04-18 17:42:08 +030073 /* Traps in ovl inode cache */
Amir Goldstein0be0bfd2019-07-12 15:24:34 +030074 struct inode *workbasedir_trap;
Amir Goldstein146d62e2019-04-18 17:42:08 +030075 struct inode *workdir_trap;
76 struct inode *indexdir_trap;
Amir Goldstein0f831ec2019-11-16 18:14:41 +020077 /* -1: disabled, 0: same fs, 1..32: number of unused ino bits */
78 int xino_mode;
Amir Goldstein4d314f72020-02-21 16:34:43 +020079 /* For allocation of non-persistent inode numbers */
80 atomic_long_t last_ino;
Chengguang Xuc21c8392020-04-24 10:55:17 +080081 /* Whiteout dentry cache */
82 struct dentry *whiteout;
Miklos Szeredibbb1e542016-12-16 11:02:56 +010083};
84
Miklos Szeredi08f4c7c2020-06-04 10:48:19 +020085static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
86{
Miklos Szeredib8e42a62020-06-04 10:48:19 +020087 return ofs->layers[0].mnt;
Miklos Szeredi08f4c7c2020-06-04 10:48:19 +020088}
89
Amir Goldstein0f831ec2019-11-16 18:14:41 +020090static inline struct ovl_fs *OVL_FS(struct super_block *sb)
91{
92 return (struct ovl_fs *)sb->s_fs_info;
93}
94
Vivek Goyalc86243b02020-08-31 14:15:29 -040095static inline bool ovl_should_sync(struct ovl_fs *ofs)
96{
97 return !ofs->config.ovl_volatile;
98}
99
Miklos Szeredibbb1e542016-12-16 11:02:56 +0100100/* private information held for every overlayfs dentry */
101struct ovl_entry {
Miklos Szeredibbb1e542016-12-16 11:02:56 +0100102 union {
Miklos Szeredi55acc662017-07-04 22:03:18 +0200103 struct {
Amir Goldsteinc62520a2018-01-14 19:25:31 +0200104 unsigned long flags;
Miklos Szeredi55acc662017-07-04 22:03:18 +0200105 };
Miklos Szeredibbb1e542016-12-16 11:02:56 +0100106 struct rcu_head rcu;
107 };
108 unsigned numlower;
Chandan Rajendrab9343632017-07-24 01:57:54 -0500109 struct ovl_path lowerstack[];
Miklos Szeredibbb1e542016-12-16 11:02:56 +0100110};
111
112struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
113
Amir Goldsteinc62520a2018-01-14 19:25:31 +0200114static inline struct ovl_entry *OVL_E(struct dentry *dentry)
115{
116 return (struct ovl_entry *) dentry->d_fsdata;
117}
118
Amir Goldstein13cf1992017-06-12 09:54:40 +0300119struct ovl_inode {
Vivek Goyal2664bd02018-05-11 11:49:30 -0400120 union {
121 struct ovl_dir_cache *cache; /* directory */
122 struct inode *lowerdata; /* regular file */
123 };
Miklos Szeredicf31c462017-07-04 22:03:16 +0200124 const char *redirect;
Miklos Szeredi04a01ac2017-07-04 22:03:16 +0200125 u64 version;
Miklos Szeredi13c72072017-07-04 22:03:16 +0200126 unsigned long flags;
Amir Goldstein13cf1992017-06-12 09:54:40 +0300127 struct inode vfs_inode;
Miklos Szeredi09d8b582017-07-04 22:03:16 +0200128 struct dentry *__upperdentry;
Miklos Szeredi25b77132017-07-04 22:03:16 +0200129 struct inode *lower;
Amir Goldsteina015daf2017-06-21 15:28:51 +0300130
131 /* synchronize copy up and more */
132 struct mutex lock;
Amir Goldstein13cf1992017-06-12 09:54:40 +0300133};
134
135static inline struct ovl_inode *OVL_I(struct inode *inode)
136{
137 return container_of(inode, struct ovl_inode, vfs_inode);
138}
Miklos Szeredi09d8b582017-07-04 22:03:16 +0200139
140static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
141{
Will Deacon506458e2017-10-24 11:22:48 +0100142 return READ_ONCE(oi->__upperdentry);
Miklos Szeredi09d8b582017-07-04 22:03:16 +0200143}