blob: ec237035333afcbb8ffab21951a172e384a6597a [file] [log] [blame]
Miklos Szeredibbb1e542016-12-16 11:02:56 +01001/*
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
11struct ovl_config {
12 char *lowerdir;
13 char *upperdir;
14 char *workdir;
15 bool default_permissions;
Miklos Szeredia6c60652016-12-16 11:02:56 +010016 bool redirect_dir;
Miklos Szeredi438c84c2017-12-11 11:28:10 +010017 bool redirect_follow;
18 const char *redirect_mode;
Amir Goldstein02bcd152017-06-21 15:28:36 +030019 bool index;
Amir Goldsteinf168f102018-01-19 11:26:53 +020020 bool nfs_export;
Amir Goldstein795939a2018-03-29 09:08:18 +030021 int xino;
Vivek Goyald5791042018-05-11 11:49:27 -040022 bool metacopy;
Miklos Szeredibbb1e542016-12-16 11:02:56 +010023};
24
Amir Goldstein51486262018-03-28 20:22:41 +030025struct ovl_sb {
26 struct super_block *sb;
27 dev_t pseudo_dev;
28};
29
Chandan Rajendrab9343632017-07-24 01:57:54 -050030struct ovl_layer {
31 struct vfsmount *mnt;
Amir Goldstein51486262018-03-28 20:22:41 +030032 struct ovl_sb *fs;
33 /* Index of this layer in fs root (upper idx == 0) */
Amir Goldsteind583ed72017-11-08 19:23:36 +020034 int idx;
Amir Goldstein51486262018-03-28 20:22:41 +030035 /* One fsid per unique underlying sb (upper fsid == 0) */
36 int fsid;
Chandan Rajendrab9343632017-07-24 01:57:54 -050037};
38
39struct ovl_path {
40 struct ovl_layer *layer;
41 struct dentry *dentry;
42};
43
Miklos Szeredibbb1e542016-12-16 11:02:56 +010044/* private information held for overlayfs's superblock */
45struct ovl_fs {
46 struct vfsmount *upper_mnt;
Amir Goldstein51486262018-03-28 20:22:41 +030047 unsigned int numlower;
48 /* Number of unique lower sb that differ from upper sb */
49 unsigned int numlowerfs;
Chandan Rajendrab9343632017-07-24 01:57:54 -050050 struct ovl_layer *lower_layers;
Amir Goldstein51486262018-03-28 20:22:41 +030051 struct ovl_sb *lower_fs;
Amir Goldstein2cac0c02017-06-21 15:28:33 +030052 /* workbasedir is the path at workdir= mount option */
53 struct dentry *workbasedir;
54 /* workdir is the 'work' directory under workbasedir */
Miklos Szeredibbb1e542016-12-16 11:02:56 +010055 struct dentry *workdir;
Amir Goldstein02bcd152017-06-21 15:28:36 +030056 /* index directory listing overlay inodes by origin file handle */
57 struct dentry *indexdir;
Miklos Szeredi6b2d5fe2016-12-16 11:02:56 +010058 long namelen;
Miklos Szeredibbb1e542016-12-16 11:02:56 +010059 /* 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 Goldsteine7f52422017-01-17 06:34:53 +020063 bool tmpfile;
Amir Goldstein82b749b2017-05-17 00:12:40 +030064 bool noxattr;
Amir Goldstein85fdee12017-09-29 10:21:21 +030065 /* Did we take the inuse lock? */
66 bool upperdir_locked;
67 bool workdir_locked;
Amir Goldsteine487d882017-11-07 13:55:04 +020068 /* Inode numbers in all layers do not use the high xino_bits */
69 unsigned int xino_bits;
Miklos Szeredibbb1e542016-12-16 11:02:56 +010070};
71
72/* private information held for every overlayfs dentry */
73struct ovl_entry {
Miklos Szeredibbb1e542016-12-16 11:02:56 +010074 union {
Miklos Szeredi55acc662017-07-04 22:03:18 +020075 struct {
Amir Goldsteinc62520a2018-01-14 19:25:31 +020076 unsigned long flags;
Miklos Szeredi55acc662017-07-04 22:03:18 +020077 };
Miklos Szeredibbb1e542016-12-16 11:02:56 +010078 struct rcu_head rcu;
79 };
80 unsigned numlower;
Chandan Rajendrab9343632017-07-24 01:57:54 -050081 struct ovl_path lowerstack[];
Miklos Szeredibbb1e542016-12-16 11:02:56 +010082};
83
84struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
85
Amir Goldsteinc62520a2018-01-14 19:25:31 +020086static inline struct ovl_entry *OVL_E(struct dentry *dentry)
87{
88 return (struct ovl_entry *) dentry->d_fsdata;
89}
90
Amir Goldstein13cf1992017-06-12 09:54:40 +030091struct ovl_inode {
Vivek Goyal2664bd02018-05-11 11:49:30 -040092 union {
93 struct ovl_dir_cache *cache; /* directory */
94 struct inode *lowerdata; /* regular file */
95 };
Miklos Szeredicf31c462017-07-04 22:03:16 +020096 const char *redirect;
Miklos Szeredi04a01ac2017-07-04 22:03:16 +020097 u64 version;
Miklos Szeredi13c72072017-07-04 22:03:16 +020098 unsigned long flags;
Amir Goldstein13cf1992017-06-12 09:54:40 +030099 struct inode vfs_inode;
Miklos Szeredi09d8b582017-07-04 22:03:16 +0200100 struct dentry *__upperdentry;
Miklos Szeredi25b77132017-07-04 22:03:16 +0200101 struct inode *lower;
Amir Goldsteina015daf2017-06-21 15:28:51 +0300102
103 /* synchronize copy up and more */
104 struct mutex lock;
Amir Goldstein13cf1992017-06-12 09:54:40 +0300105};
106
107static inline struct ovl_inode *OVL_I(struct inode *inode)
108{
109 return container_of(inode, struct ovl_inode, vfs_inode);
110}
Miklos Szeredi09d8b582017-07-04 22:03:16 +0200111
112static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
113{
Will Deacon506458e2017-10-24 11:22:48 +0100114 return READ_ONCE(oi->__upperdentry);
Miklos Szeredi09d8b582017-07-04 22:03:16 +0200115}