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