1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2bbb1e54dSMiklos Szeredi /* 3bbb1e54dSMiklos Szeredi * 4bbb1e54dSMiklos Szeredi * Copyright (C) 2011 Novell Inc. 5bbb1e54dSMiklos Szeredi * Copyright (C) 2016 Red Hat, Inc. 6bbb1e54dSMiklos Szeredi */ 7bbb1e54dSMiklos Szeredi 8bbb1e54dSMiklos Szeredi struct ovl_config { 9bbb1e54dSMiklos Szeredi char *lowerdir; 10bbb1e54dSMiklos Szeredi char *upperdir; 11bbb1e54dSMiklos Szeredi char *workdir; 12bbb1e54dSMiklos Szeredi bool default_permissions; 13a6c60655SMiklos Szeredi bool redirect_dir; 14438c84c2SMiklos Szeredi bool redirect_follow; 15438c84c2SMiklos Szeredi const char *redirect_mode; 1602bcd157SAmir Goldstein bool index; 175830fb6bSPavel Tikhomirov bool uuid; 18f168f109SAmir Goldstein bool nfs_export; 19795939a9SAmir Goldstein int xino; 20d5791044SVivek Goyal bool metacopy; 212d2f2d73SMiklos Szeredi bool userxattr; 22c86243b0SVivek Goyal bool ovl_volatile; 23bbb1e54dSMiklos Szeredi }; 24bbb1e54dSMiklos Szeredi 255148626bSAmir Goldstein struct ovl_sb { 265148626bSAmir Goldstein struct super_block *sb; 275148626bSAmir Goldstein dev_t pseudo_dev; 287e63c87fSAmir Goldstein /* Unusable (conflicting) uuid */ 297e63c87fSAmir Goldstein bool bad_uuid; 301b81ddddSAmir Goldstein /* Used as a lower layer (but maybe also as upper) */ 311b81ddddSAmir Goldstein bool is_lower; 325148626bSAmir Goldstein }; 335148626bSAmir Goldstein 34b9343632SChandan Rajendra struct ovl_layer { 35b9343632SChandan Rajendra struct vfsmount *mnt; 36146d62e5SAmir Goldstein /* Trap in ovl inode cache */ 37146d62e5SAmir Goldstein struct inode *trap; 385148626bSAmir Goldstein struct ovl_sb *fs; 395148626bSAmir Goldstein /* Index of this layer in fs root (upper idx == 0) */ 40d583ed7dSAmir Goldstein int idx; 415148626bSAmir Goldstein /* One fsid per unique underlying sb (upper fsid == 0) */ 425148626bSAmir Goldstein int fsid; 43b9343632SChandan Rajendra }; 44b9343632SChandan Rajendra 45b9343632SChandan Rajendra struct ovl_path { 4613464165SMiklos Szeredi const struct ovl_layer *layer; 47b9343632SChandan Rajendra struct dentry *dentry; 48b9343632SChandan Rajendra }; 49b9343632SChandan Rajendra 50bbb1e54dSMiklos Szeredi /* private information held for overlayfs's superblock */ 51bbb1e54dSMiklos Szeredi struct ovl_fs { 5294375f9dSAmir Goldstein unsigned int numlayer; 5307f1e596SAmir Goldstein /* Number of unique fs among layers including upper fs */ 5407f1e596SAmir Goldstein unsigned int numfs; 5513464165SMiklos Szeredi const struct ovl_layer *layers; 5607f1e596SAmir Goldstein struct ovl_sb *fs; 572cac0c00SAmir Goldstein /* workbasedir is the path at workdir= mount option */ 582cac0c00SAmir Goldstein struct dentry *workbasedir; 592cac0c00SAmir Goldstein /* workdir is the 'work' directory under workbasedir */ 60bbb1e54dSMiklos Szeredi struct dentry *workdir; 6102bcd157SAmir Goldstein /* index directory listing overlay inodes by origin file handle */ 6202bcd157SAmir Goldstein struct dentry *indexdir; 636b2d5fe4SMiklos Szeredi long namelen; 64bbb1e54dSMiklos Szeredi /* pathnames of lower and upper dirs, for show_options */ 65bbb1e54dSMiklos Szeredi struct ovl_config config; 66bbb1e54dSMiklos Szeredi /* creds of process who forced instantiation of super block */ 67bbb1e54dSMiklos Szeredi const struct cred *creator_cred; 68e7f52429SAmir Goldstein bool tmpfile; 6982b749b2SAmir Goldstein bool noxattr; 7085fdee1eSAmir Goldstein /* Did we take the inuse lock? */ 7185fdee1eSAmir Goldstein bool upperdir_locked; 7285fdee1eSAmir Goldstein bool workdir_locked; 73c21c839bSChengguang Xu bool share_whiteout; 74146d62e5SAmir Goldstein /* Traps in ovl inode cache */ 750be0bfd2SAmir Goldstein struct inode *workbasedir_trap; 76146d62e5SAmir Goldstein struct inode *workdir_trap; 77146d62e5SAmir Goldstein struct inode *indexdir_trap; 780f831ec8SAmir Goldstein /* -1: disabled, 0: same fs, 1..32: number of unused ino bits */ 790f831ec8SAmir Goldstein int xino_mode; 804d314f78SAmir Goldstein /* For allocation of non-persistent inode numbers */ 814d314f78SAmir Goldstein atomic_long_t last_ino; 82c21c839bSChengguang Xu /* Whiteout dentry cache */ 83c21c839bSChengguang Xu struct dentry *whiteout; 84335d3fc5SSargun Dhillon /* r/o snapshot of upperdir sb's only taken on volatile mounts */ 85335d3fc5SSargun Dhillon errseq_t errseq; 86bbb1e54dSMiklos Szeredi }; 87bbb1e54dSMiklos Szeredi 8808f4c7c8SMiklos Szeredi static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs) 8908f4c7c8SMiklos Szeredi { 90b8e42a65SMiklos Szeredi return ofs->layers[0].mnt; 9108f4c7c8SMiklos Szeredi } 9208f4c7c8SMiklos Szeredi 93b65c20acSChristian Brauner static inline struct user_namespace *ovl_upper_mnt_userns(struct ovl_fs *ofs) 94b65c20acSChristian Brauner { 95bc70682aSChristian Brauner return mnt_user_ns(ovl_upper_mnt(ofs)); 96b65c20acSChristian Brauner } 97b65c20acSChristian Brauner 98*abf08576SChristian Brauner static inline struct mnt_idmap *ovl_upper_mnt_idmap(struct ovl_fs *ofs) 99*abf08576SChristian Brauner { 100*abf08576SChristian Brauner return mnt_idmap(ovl_upper_mnt(ofs)); 101*abf08576SChristian Brauner } 102*abf08576SChristian Brauner 1030f831ec8SAmir Goldstein static inline struct ovl_fs *OVL_FS(struct super_block *sb) 1040f831ec8SAmir Goldstein { 1050f831ec8SAmir Goldstein return (struct ovl_fs *)sb->s_fs_info; 1060f831ec8SAmir Goldstein } 1070f831ec8SAmir Goldstein 108c86243b0SVivek Goyal static inline bool ovl_should_sync(struct ovl_fs *ofs) 109c86243b0SVivek Goyal { 110c86243b0SVivek Goyal return !ofs->config.ovl_volatile; 111c86243b0SVivek Goyal } 112c86243b0SVivek Goyal 113bbb1e54dSMiklos Szeredi /* private information held for every overlayfs dentry */ 114bbb1e54dSMiklos Szeredi struct ovl_entry { 115bbb1e54dSMiklos Szeredi union { 11655acc661SMiklos Szeredi struct { 117c62520a8SAmir Goldstein unsigned long flags; 11855acc661SMiklos Szeredi }; 119bbb1e54dSMiklos Szeredi struct rcu_head rcu; 120bbb1e54dSMiklos Szeredi }; 121bbb1e54dSMiklos Szeredi unsigned numlower; 122b9343632SChandan Rajendra struct ovl_path lowerstack[]; 123bbb1e54dSMiklos Szeredi }; 124bbb1e54dSMiklos Szeredi 125bbb1e54dSMiklos Szeredi struct ovl_entry *ovl_alloc_entry(unsigned int numlower); 126bbb1e54dSMiklos Szeredi 127c62520a8SAmir Goldstein static inline struct ovl_entry *OVL_E(struct dentry *dentry) 128c62520a8SAmir Goldstein { 129c62520a8SAmir Goldstein return (struct ovl_entry *) dentry->d_fsdata; 130c62520a8SAmir Goldstein } 131c62520a8SAmir Goldstein 13213cf199dSAmir Goldstein struct ovl_inode { 1332664bd08SVivek Goyal union { 1342664bd08SVivek Goyal struct ovl_dir_cache *cache; /* directory */ 1352664bd08SVivek Goyal struct inode *lowerdata; /* regular file */ 1362664bd08SVivek Goyal }; 137cf31c463SMiklos Szeredi const char *redirect; 13804a01ac7SMiklos Szeredi u64 version; 13913c72075SMiklos Szeredi unsigned long flags; 14013cf199dSAmir Goldstein struct inode vfs_inode; 14109d8b586SMiklos Szeredi struct dentry *__upperdentry; 142ffa5723cSAmir Goldstein struct ovl_path lowerpath; 143a015dafcSAmir Goldstein 144a015dafcSAmir Goldstein /* synchronize copy up and more */ 145a015dafcSAmir Goldstein struct mutex lock; 14613cf199dSAmir Goldstein }; 14713cf199dSAmir Goldstein 14813cf199dSAmir Goldstein static inline struct ovl_inode *OVL_I(struct inode *inode) 14913cf199dSAmir Goldstein { 15013cf199dSAmir Goldstein return container_of(inode, struct ovl_inode, vfs_inode); 15113cf199dSAmir Goldstein } 15209d8b586SMiklos Szeredi 15309d8b586SMiklos Szeredi static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi) 15409d8b586SMiklos Szeredi { 155506458efSWill Deacon return READ_ONCE(oi->__upperdentry); 15609d8b586SMiklos Szeredi } 157