1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * 4 * Copyright (C) 2011 Novell Inc. 5 * Copyright (C) 2016 Red Hat, Inc. 6 */ 7 8 struct ovl_config { 9 char *lowerdir; 10 char *upperdir; 11 char *workdir; 12 bool default_permissions; 13 bool redirect_dir; 14 bool redirect_follow; 15 const char *redirect_mode; 16 bool index; 17 bool uuid; 18 bool nfs_export; 19 int xino; 20 bool metacopy; 21 bool userxattr; 22 bool ovl_volatile; 23 bool override_creds; 24 }; 25 26 struct ovl_sb { 27 struct super_block *sb; 28 dev_t pseudo_dev; 29 /* Unusable (conflicting) uuid */ 30 bool bad_uuid; 31 /* Used as a lower layer (but maybe also as upper) */ 32 bool is_lower; 33 }; 34 35 struct ovl_layer { 36 /* ovl_free_fs() relies on @mnt being the first member! */ 37 struct vfsmount *mnt; 38 /* Trap in ovl inode cache */ 39 struct inode *trap; 40 struct ovl_sb *fs; 41 /* Index of this layer in fs root (upper idx == 0) */ 42 int idx; 43 /* One fsid per unique underlying sb (upper fsid == 0) */ 44 int fsid; 45 }; 46 47 /* 48 * ovl_free_fs() relies on @mnt being the first member when unmounting 49 * the private mounts created for each layer. Let's check both the 50 * offset and type. 51 */ 52 static_assert(offsetof(struct ovl_layer, mnt) == 0); 53 static_assert(__same_type(typeof_member(struct ovl_layer, mnt), struct vfsmount *)); 54 55 struct ovl_path { 56 const struct ovl_layer *layer; 57 struct dentry *dentry; 58 }; 59 60 /* private information held for overlayfs's superblock */ 61 struct ovl_fs { 62 unsigned int numlayer; 63 /* Number of unique fs among layers including upper fs */ 64 unsigned int numfs; 65 const struct ovl_layer *layers; 66 struct ovl_sb *fs; 67 /* workbasedir is the path at workdir= mount option */ 68 struct dentry *workbasedir; 69 /* workdir is the 'work' directory under workbasedir */ 70 struct dentry *workdir; 71 /* index directory listing overlay inodes by origin file handle */ 72 struct dentry *indexdir; 73 long namelen; 74 /* pathnames of lower and upper dirs, for show_options */ 75 struct ovl_config config; 76 /* creds of process who forced instantiation of super block */ 77 const struct cred *creator_cred; 78 bool tmpfile; 79 bool noxattr; 80 /* Did we take the inuse lock? */ 81 bool upperdir_locked; 82 bool workdir_locked; 83 bool share_whiteout; 84 /* Traps in ovl inode cache */ 85 struct inode *workbasedir_trap; 86 struct inode *workdir_trap; 87 struct inode *indexdir_trap; 88 /* -1: disabled, 0: same fs, 1..32: number of unused ino bits */ 89 int xino_mode; 90 /* For allocation of non-persistent inode numbers */ 91 atomic_long_t last_ino; 92 /* Whiteout dentry cache */ 93 struct dentry *whiteout; 94 /* r/o snapshot of upperdir sb's only taken on volatile mounts */ 95 errseq_t errseq; 96 }; 97 ovl_upper_mnt(struct ovl_fs * ofs)98static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs) 99 { 100 return ofs->layers[0].mnt; 101 } 102 OVL_FS(struct super_block * sb)103static inline struct ovl_fs *OVL_FS(struct super_block *sb) 104 { 105 return (struct ovl_fs *)sb->s_fs_info; 106 } 107 ovl_should_sync(struct ovl_fs * ofs)108static inline bool ovl_should_sync(struct ovl_fs *ofs) 109 { 110 return !ofs->config.ovl_volatile; 111 } 112 113 /* private information held for every overlayfs dentry */ 114 struct ovl_entry { 115 union { 116 struct { 117 unsigned long flags; 118 }; 119 struct rcu_head rcu; 120 }; 121 unsigned numlower; 122 struct ovl_path lowerstack[]; 123 }; 124 125 struct ovl_entry *ovl_alloc_entry(unsigned int numlower); 126 OVL_E(struct dentry * dentry)127static inline struct ovl_entry *OVL_E(struct dentry *dentry) 128 { 129 return (struct ovl_entry *) dentry->d_fsdata; 130 } 131 132 struct ovl_inode { 133 union { 134 struct ovl_dir_cache *cache; /* directory */ 135 struct inode *lowerdata; /* regular file */ 136 }; 137 const char *redirect; 138 u64 version; 139 unsigned long flags; 140 struct inode vfs_inode; 141 struct dentry *__upperdentry; 142 struct ovl_path lowerpath; 143 144 /* synchronize copy up and more */ 145 struct mutex lock; 146 }; 147 OVL_I(struct inode * inode)148static inline struct ovl_inode *OVL_I(struct inode *inode) 149 { 150 return container_of(inode, struct ovl_inode, vfs_inode); 151 } 152 ovl_upperdentry_dereference(struct ovl_inode * oi)153static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi) 154 { 155 return READ_ONCE(oi->__upperdentry); 156 } 157