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 struct vfsmount *mnt; 35 /* Trap in ovl inode cache */ 36 struct inode *trap; 37 struct ovl_sb *fs; 38 /* Index of this layer in fs root (upper idx == 0) */ 39 int idx; 40 /* One fsid per unique underlying sb (upper fsid == 0) */ 41 int fsid; 42 }; 43 44 struct ovl_path { 45 const struct ovl_layer *layer; 46 struct dentry *dentry; 47 }; 48 49 /* private information held for overlayfs's superblock */ 50 struct ovl_fs { 51 unsigned int numlayer; 52 /* Number of unique fs among layers including upper fs */ 53 unsigned int numfs; 54 const struct ovl_layer *layers; 55 struct ovl_sb *fs; 56 /* workbasedir is the path at workdir= mount option */ 57 struct dentry *workbasedir; 58 /* workdir is the 'work' directory under workbasedir */ 59 struct dentry *workdir; 60 /* index directory listing overlay inodes by origin file handle */ 61 struct dentry *indexdir; 62 long namelen; 63 /* pathnames of lower and upper dirs, for show_options */ 64 struct ovl_config config; 65 /* creds of process who forced instantiation of super block */ 66 const struct cred *creator_cred; 67 bool tmpfile; 68 bool noxattr; 69 /* Did we take the inuse lock? */ 70 bool upperdir_locked; 71 bool workdir_locked; 72 bool share_whiteout; 73 /* Traps in ovl inode cache */ 74 struct inode *workbasedir_trap; 75 struct inode *workdir_trap; 76 struct inode *indexdir_trap; 77 /* -1: disabled, 0: same fs, 1..32: number of unused ino bits */ 78 int xino_mode; 79 /* For allocation of non-persistent inode numbers */ 80 atomic_long_t last_ino; 81 /* Whiteout dentry cache */ 82 struct dentry *whiteout; 83 /* r/o snapshot of upperdir sb's only taken on volatile mounts */ 84 errseq_t errseq; 85 }; 86 ovl_upper_mnt(struct ovl_fs * ofs)87static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs) 88 { 89 return ofs->layers[0].mnt; 90 } 91 OVL_FS(struct super_block * sb)92static inline struct ovl_fs *OVL_FS(struct super_block *sb) 93 { 94 return (struct ovl_fs *)sb->s_fs_info; 95 } 96 ovl_should_sync(struct ovl_fs * ofs)97static inline bool ovl_should_sync(struct ovl_fs *ofs) 98 { 99 return !ofs->config.ovl_volatile; 100 } 101 102 /* private information held for every overlayfs dentry */ 103 struct ovl_entry { 104 union { 105 struct { 106 unsigned long flags; 107 }; 108 struct rcu_head rcu; 109 }; 110 unsigned numlower; 111 struct ovl_path lowerstack[]; 112 }; 113 114 struct ovl_entry *ovl_alloc_entry(unsigned int numlower); 115 OVL_E(struct dentry * dentry)116static inline struct ovl_entry *OVL_E(struct dentry *dentry) 117 { 118 return (struct ovl_entry *) dentry->d_fsdata; 119 } 120 121 struct ovl_inode { 122 union { 123 struct ovl_dir_cache *cache; /* directory */ 124 struct inode *lowerdata; /* regular file */ 125 }; 126 const char *redirect; 127 u64 version; 128 unsigned long flags; 129 struct inode vfs_inode; 130 struct dentry *__upperdentry; 131 struct inode *lower; 132 133 /* synchronize copy up and more */ 134 struct mutex lock; 135 }; 136 OVL_I(struct inode * inode)137static inline struct ovl_inode *OVL_I(struct inode *inode) 138 { 139 return container_of(inode, struct ovl_inode, vfs_inode); 140 } 141 ovl_upperdentry_dereference(struct ovl_inode * oi)142static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi) 143 { 144 return READ_ONCE(oi->__upperdentry); 145 } 146