| 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 *upperdir; |
| 10 |
char *workdir; |
| 11 |
char **lowerdirs; |
| 12 |
bool default_permissions; |
| 13 |
int redirect_mode; |
| 14 |
int verity_mode; |
| 15 |
bool index; |
| 16 |
int uuid; |
| 17 |
bool nfs_export; |
| 18 |
int xino; |
| 19 |
bool metacopy; |
| 20 |
bool userxattr; |
| 21 |
int fsync_mode; |
| 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 |
/* xwhiteouts were found on this layer */ |
| 44 |
bool has_xwhiteouts; |
| 45 |
}; |
| 46 |
|
| 47 |
struct ovl_path { |
| 48 |
const struct ovl_layer *layer; |
| 49 |
struct dentry *dentry; |
| 50 |
}; |
| 51 |
|
| 52 |
struct ovl_entry { |
| 53 |
unsigned int __numlower; |
| 54 |
struct ovl_path __lowerstack[] __counted_by(__numlower); |
| 55 |
}; |
| 56 |
|
| 57 |
/* private information held for overlayfs's superblock */ |
| 58 |
struct ovl_fs { |
| 59 |
unsigned int numlayer; |
| 60 |
/* Number of unique fs among layers including upper fs */ |
| 61 |
unsigned int numfs; |
| 62 |
/* Number of data-only lower layers */ |
| 63 |
unsigned int numdatalayer; |
| 64 |
struct ovl_layer *layers; |
| 65 |
struct ovl_sb *fs; |
| 66 |
/* workbasedir is the path at workdir= mount option */ |
| 67 |
struct dentry *workbasedir; |
| 68 |
/* workdir is the 'work' or 'index' directory under workbasedir */ |
| 69 |
struct dentry *workdir; |
| 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 |
bool nofh; |
| 78 |
/* Did we take the inuse lock? */ |
| 79 |
bool upperdir_locked; |
| 80 |
bool workdir_locked; |
| 81 |
/* Traps in ovl inode cache */ |
| 82 |
struct inode *workbasedir_trap; |
| 83 |
struct inode *workdir_trap; |
| 84 |
/* -1: disabled, 0: same fs, 1..32: number of unused ino bits */ |
| 85 |
int xino_mode; |
| 86 |
/* For allocation of non-persistent inode numbers */ |
| 87 |
atomic_long_t last_ino; |
| 88 |
/* Shared whiteout cache */ |
| 89 |
struct dentry *whiteout; |
| 90 |
bool no_shared_whiteout; |
| 91 |
struct mutex whiteout_lock; |
| 92 |
/* r/o snapshot of upperdir sb's only taken on volatile mounts */ |
| 93 |
errseq_t errseq; |
| 94 |
bool casefold; |
| 95 |
}; |
| 96 |
|
| 97 |
/* Number of lower layers, not including data-only layers */ |
| 98 |
static inline unsigned int ovl_numlowerlayer(struct ovl_fs *ofs) |
| 99 |
{ |
| 100 |
return ofs->numlayer - ofs->numdatalayer - 1; |
| 101 |
} |
| 102 |
|
| 103 |
static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs) |
| 104 |
{ |
| 105 |
return ofs->layers[0].mnt; |
| 106 |
} |
| 107 |
|
| 108 |
static inline struct mnt_idmap *ovl_upper_mnt_idmap(struct ovl_fs *ofs) |
| 109 |
{ |
| 110 |
return mnt_idmap(ovl_upper_mnt(ofs)); |
| 111 |
} |
| 112 |
|
| 113 |
extern struct file_system_type ovl_fs_type; |
| 114 |
|
| 115 |
static inline struct ovl_fs *OVL_FS(struct super_block *sb) |
| 116 |
{ |
| 117 |
if (IS_ENABLED(CONFIG_OVERLAY_FS_DEBUG)) |
| 118 |
WARN_ON_ONCE(sb->s_type != &ovl_fs_type); |
| 119 |
|
| 120 |
return (struct ovl_fs *)sb->s_fs_info; |
| 121 |
} |
| 122 |
|
| 123 |
static inline unsigned int ovl_numlower(struct ovl_entry *oe) |
| 124 |
{ |
| 125 |
return oe ? oe->__numlower : 0; |
| 126 |
} |
| 127 |
|
| 128 |
static inline struct ovl_path *ovl_lowerstack(struct ovl_entry *oe) |
| 129 |
{ |
| 130 |
return ovl_numlower(oe) ? oe->__lowerstack : NULL; |
| 131 |
} |
| 132 |
|
| 133 |
static inline struct ovl_path *ovl_lowerpath(struct ovl_entry *oe) |
| 134 |
{ |
| 135 |
return ovl_lowerstack(oe); |
| 136 |
} |
| 137 |
|
| 138 |
static inline struct ovl_path *ovl_lowerdata(struct ovl_entry *oe) |
| 139 |
{ |
| 140 |
struct ovl_path *lowerstack = ovl_lowerstack(oe); |
| 141 |
|
| 142 |
return lowerstack ? &lowerstack[oe->__numlower - 1] : NULL; |
| 143 |
} |
| 144 |
|
| 145 |
/* May return NULL if lazy lookup of lowerdata is needed */ |
| 146 |
static inline struct dentry *ovl_lowerdata_dentry(struct ovl_entry *oe) |
| 147 |
{ |
| 148 |
struct ovl_path *lowerdata = ovl_lowerdata(oe); |
| 149 |
|
| 150 |
return lowerdata ? READ_ONCE(lowerdata->dentry) : NULL; |
| 151 |
} |
| 152 |
|
| 153 |
/* private information held for every overlayfs dentry */ |
| 154 |
static inline unsigned long *OVL_E_FLAGS(struct dentry *dentry) |
| 155 |
{ |
| 156 |
return (unsigned long *) &dentry->d_fsdata; |
| 157 |
} |
| 158 |
|
| 159 |
struct ovl_inode { |
| 160 |
union { |
| 161 |
struct ovl_dir_cache *cache; /* directory */ |
| 162 |
const char *lowerdata_redirect; /* regular file */ |
| 163 |
}; |
| 164 |
const char *redirect; |
| 165 |
u64 version; |
| 166 |
unsigned long flags; |
| 167 |
struct inode vfs_inode; |
| 168 |
struct dentry *__upperdentry; |
| 169 |
struct ovl_entry *oe; |
| 170 |
|
| 171 |
/* synchronize copy up and more */ |
| 172 |
struct mutex lock; |
| 173 |
}; |
| 174 |
|
| 175 |
static inline struct ovl_inode *OVL_I(struct inode *inode) |
| 176 |
{ |
| 177 |
return container_of(inode, struct ovl_inode, vfs_inode); |
| 178 |
} |
| 179 |
|
| 180 |
static inline struct ovl_entry *OVL_I_E(struct inode *inode) |
| 181 |
{ |
| 182 |
return inode ? OVL_I(inode)->oe : NULL; |
| 183 |
} |
| 184 |
|
| 185 |
static inline struct ovl_entry *OVL_E(struct dentry *dentry) |
| 186 |
{ |
| 187 |
return OVL_I_E(d_inode(dentry)); |
| 188 |
} |
| 189 |
|
| 190 |
static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi) |
| 191 |
{ |
| 192 |
return READ_ONCE(oi->__upperdentry); |
| 193 |
} |