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 }; 24 25 struct ovl_sb { 26 struct super_block *sb; 27 dev_t pseudo_dev; 28 /* Unusable (conflicting) uuid */ 29 bool bad_uuid; 30 /* Used as a lower layer (but maybe also as upper) */ 31 bool is_lower; 32 }; 33 34 struct ovl_layer { 35 struct vfsmount *mnt; 36 /* Trap in ovl inode cache */ 37 struct inode *trap; 38 struct ovl_sb *fs; 39 /* Index of this layer in fs root (upper idx == 0) */ 40 int idx; 41 /* One fsid per unique underlying sb (upper fsid == 0) */ 42 int fsid; 43 }; 44 45 struct ovl_path { 46 const struct ovl_layer *layer; 47 struct dentry *dentry; 48 }; 49 50 struct ovl_entry { 51 unsigned int __numlower; 52 struct ovl_path __lowerstack[]; 53 }; 54 55 /* private information held for overlayfs's superblock */ 56 struct ovl_fs { 57 unsigned int numlayer; 58 /* Number of unique fs among layers including upper fs */ 59 unsigned int numfs; 60 /* Number of data-only lower layers */ 61 unsigned int numdatalayer; 62 const struct ovl_layer *layers; 63 struct ovl_sb *fs; 64 /* workbasedir is the path at workdir= mount option */ 65 struct dentry *workbasedir; 66 /* workdir is the 'work' directory under workbasedir */ 67 struct dentry *workdir; 68 /* index directory listing overlay inodes by origin file handle */ 69 struct dentry *indexdir; 70 long namelen; 71 /* pathnames of lower and upper dirs, for show_options */ 72 struct ovl_config config; 73 /* creds of process who forced instantiation of super block */ 74 const struct cred *creator_cred; 75 bool tmpfile; 76 bool noxattr; 77 /* Did we take the inuse lock? */ 78 bool upperdir_locked; 79 bool workdir_locked; 80 bool share_whiteout; 81 /* Traps in ovl inode cache */ 82 struct inode *workbasedir_trap; 83 struct inode *workdir_trap; 84 struct inode *indexdir_trap; 85 /* -1: disabled, 0: same fs, 1..32: number of unused ino bits */ 86 int xino_mode; 87 /* For allocation of non-persistent inode numbers */ 88 atomic_long_t last_ino; 89 /* Whiteout dentry cache */ 90 struct dentry *whiteout; 91 /* r/o snapshot of upperdir sb's only taken on volatile mounts */ 92 errseq_t errseq; 93 }; 94 95 96 /* Number of lower layers, not including data-only layers */ 97 static inline unsigned int ovl_numlowerlayer(struct ovl_fs *ofs) 98 { 99 return ofs->numlayer - ofs->numdatalayer - 1; 100 } 101 102 static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs) 103 { 104 return ofs->layers[0].mnt; 105 } 106 107 static inline struct mnt_idmap *ovl_upper_mnt_idmap(struct ovl_fs *ofs) 108 { 109 return mnt_idmap(ovl_upper_mnt(ofs)); 110 } 111 112 static inline struct ovl_fs *OVL_FS(struct super_block *sb) 113 { 114 return (struct ovl_fs *)sb->s_fs_info; 115 } 116 117 static inline bool ovl_should_sync(struct ovl_fs *ofs) 118 { 119 return !ofs->config.ovl_volatile; 120 } 121 122 static inline unsigned int ovl_numlower(struct ovl_entry *oe) 123 { 124 return oe ? oe->__numlower : 0; 125 } 126 127 static inline struct ovl_path *ovl_lowerstack(struct ovl_entry *oe) 128 { 129 return ovl_numlower(oe) ? oe->__lowerstack : NULL; 130 } 131 132 static inline struct ovl_path *ovl_lowerpath(struct ovl_entry *oe) 133 { 134 return ovl_lowerstack(oe); 135 } 136 137 static inline struct ovl_path *ovl_lowerdata(struct ovl_entry *oe) 138 { 139 struct ovl_path *lowerstack = ovl_lowerstack(oe); 140 141 return lowerstack ? &lowerstack[oe->__numlower - 1] : NULL; 142 } 143 144 static inline struct dentry *ovl_lowerdata_dentry(struct ovl_entry *oe) 145 { 146 struct ovl_path *lowerdata = ovl_lowerdata(oe); 147 148 return lowerdata ? lowerdata->dentry : NULL; 149 } 150 151 /* private information held for every overlayfs dentry */ 152 static inline unsigned long *OVL_E_FLAGS(struct dentry *dentry) 153 { 154 return (unsigned long *) &dentry->d_fsdata; 155 } 156 157 struct ovl_inode { 158 union { 159 struct ovl_dir_cache *cache; /* directory */ 160 /* place holder for non-dir */ /* regular file */ 161 }; 162 const char *redirect; 163 u64 version; 164 unsigned long flags; 165 struct inode vfs_inode; 166 struct dentry *__upperdentry; 167 struct ovl_entry *oe; 168 169 /* synchronize copy up and more */ 170 struct mutex lock; 171 }; 172 173 static inline struct ovl_inode *OVL_I(struct inode *inode) 174 { 175 return container_of(inode, struct ovl_inode, vfs_inode); 176 } 177 178 static inline struct ovl_entry *OVL_I_E(struct inode *inode) 179 { 180 return inode ? OVL_I(inode)->oe : NULL; 181 } 182 183 static inline struct ovl_entry *OVL_E(struct dentry *dentry) 184 { 185 return OVL_I_E(d_inode(dentry)); 186 } 187 188 static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi) 189 { 190 return READ_ONCE(oi->__upperdentry); 191 } 192