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