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 const struct ovl_layer *layers; 61 struct ovl_sb *fs; 62 /* workbasedir is the path at workdir= mount option */ 63 struct dentry *workbasedir; 64 /* workdir is the 'work' directory under workbasedir */ 65 struct dentry *workdir; 66 /* index directory listing overlay inodes by origin file handle */ 67 struct dentry *indexdir; 68 long namelen; 69 /* pathnames of lower and upper dirs, for show_options */ 70 struct ovl_config config; 71 /* creds of process who forced instantiation of super block */ 72 const struct cred *creator_cred; 73 bool tmpfile; 74 bool noxattr; 75 /* Did we take the inuse lock? */ 76 bool upperdir_locked; 77 bool workdir_locked; 78 bool share_whiteout; 79 /* Traps in ovl inode cache */ 80 struct inode *workbasedir_trap; 81 struct inode *workdir_trap; 82 struct inode *indexdir_trap; 83 /* -1: disabled, 0: same fs, 1..32: number of unused ino bits */ 84 int xino_mode; 85 /* For allocation of non-persistent inode numbers */ 86 atomic_long_t last_ino; 87 /* Whiteout dentry cache */ 88 struct dentry *whiteout; 89 /* r/o snapshot of upperdir sb's only taken on volatile mounts */ 90 errseq_t errseq; 91 }; 92 93 static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs) 94 { 95 return ofs->layers[0].mnt; 96 } 97 98 static inline struct mnt_idmap *ovl_upper_mnt_idmap(struct ovl_fs *ofs) 99 { 100 return mnt_idmap(ovl_upper_mnt(ofs)); 101 } 102 103 static inline struct ovl_fs *OVL_FS(struct super_block *sb) 104 { 105 return (struct ovl_fs *)sb->s_fs_info; 106 } 107 108 static inline bool ovl_should_sync(struct ovl_fs *ofs) 109 { 110 return !ofs->config.ovl_volatile; 111 } 112 113 static inline unsigned int ovl_numlower(struct ovl_entry *oe) 114 { 115 return oe ? oe->__numlower : 0; 116 } 117 118 static inline struct ovl_path *ovl_lowerstack(struct ovl_entry *oe) 119 { 120 return ovl_numlower(oe) ? oe->__lowerstack : NULL; 121 } 122 123 static inline struct ovl_path *ovl_lowerpath(struct ovl_entry *oe) 124 { 125 return ovl_lowerstack(oe); 126 } 127 128 static inline struct ovl_path *ovl_lowerdata(struct ovl_entry *oe) 129 { 130 struct ovl_path *lowerstack = ovl_lowerstack(oe); 131 132 return lowerstack ? &lowerstack[oe->__numlower - 1] : NULL; 133 } 134 135 static inline struct dentry *ovl_lowerdata_dentry(struct ovl_entry *oe) 136 { 137 struct ovl_path *lowerdata = ovl_lowerdata(oe); 138 139 return lowerdata ? lowerdata->dentry : NULL; 140 } 141 142 /* private information held for every overlayfs dentry */ 143 static inline unsigned long *OVL_E_FLAGS(struct dentry *dentry) 144 { 145 return (unsigned long *) &dentry->d_fsdata; 146 } 147 148 struct ovl_inode { 149 union { 150 struct ovl_dir_cache *cache; /* directory */ 151 /* place holder for non-dir */ /* regular file */ 152 }; 153 const char *redirect; 154 u64 version; 155 unsigned long flags; 156 struct inode vfs_inode; 157 struct dentry *__upperdentry; 158 struct ovl_entry *oe; 159 160 /* synchronize copy up and more */ 161 struct mutex lock; 162 }; 163 164 static inline struct ovl_inode *OVL_I(struct inode *inode) 165 { 166 return container_of(inode, struct ovl_inode, vfs_inode); 167 } 168 169 static inline struct ovl_entry *OVL_I_E(struct inode *inode) 170 { 171 return inode ? OVL_I(inode)->oe : NULL; 172 } 173 174 static inline struct ovl_entry *OVL_E(struct dentry *dentry) 175 { 176 return OVL_I_E(d_inode(dentry)); 177 } 178 179 static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi) 180 { 181 return READ_ONCE(oi->__upperdentry); 182 } 183