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; 84*335d3fc5SSargun Dhillon /* r/o snapshot of upperdir sb's only taken on volatile mounts */ 85*335d3fc5SSargun 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 930f831ec8SAmir Goldstein static inline struct ovl_fs *OVL_FS(struct super_block *sb) 940f831ec8SAmir Goldstein { 950f831ec8SAmir Goldstein return (struct ovl_fs *)sb->s_fs_info; 960f831ec8SAmir Goldstein } 970f831ec8SAmir Goldstein 98c86243b0SVivek Goyal static inline bool ovl_should_sync(struct ovl_fs *ofs) 99c86243b0SVivek Goyal { 100c86243b0SVivek Goyal return !ofs->config.ovl_volatile; 101c86243b0SVivek Goyal } 102c86243b0SVivek Goyal 103bbb1e54dSMiklos Szeredi /* private information held for every overlayfs dentry */ 104bbb1e54dSMiklos Szeredi struct ovl_entry { 105bbb1e54dSMiklos Szeredi union { 10655acc661SMiklos Szeredi struct { 107c62520a8SAmir Goldstein unsigned long flags; 10855acc661SMiklos Szeredi }; 109bbb1e54dSMiklos Szeredi struct rcu_head rcu; 110bbb1e54dSMiklos Szeredi }; 111bbb1e54dSMiklos Szeredi unsigned numlower; 112b9343632SChandan Rajendra struct ovl_path lowerstack[]; 113bbb1e54dSMiklos Szeredi }; 114bbb1e54dSMiklos Szeredi 115bbb1e54dSMiklos Szeredi struct ovl_entry *ovl_alloc_entry(unsigned int numlower); 116bbb1e54dSMiklos Szeredi 117c62520a8SAmir Goldstein static inline struct ovl_entry *OVL_E(struct dentry *dentry) 118c62520a8SAmir Goldstein { 119c62520a8SAmir Goldstein return (struct ovl_entry *) dentry->d_fsdata; 120c62520a8SAmir Goldstein } 121c62520a8SAmir Goldstein 12213cf199dSAmir Goldstein struct ovl_inode { 1232664bd08SVivek Goyal union { 1242664bd08SVivek Goyal struct ovl_dir_cache *cache; /* directory */ 1252664bd08SVivek Goyal struct inode *lowerdata; /* regular file */ 1262664bd08SVivek Goyal }; 127cf31c463SMiklos Szeredi const char *redirect; 12804a01ac7SMiklos Szeredi u64 version; 12913c72075SMiklos Szeredi unsigned long flags; 13013cf199dSAmir Goldstein struct inode vfs_inode; 13109d8b586SMiklos Szeredi struct dentry *__upperdentry; 13225b7713aSMiklos Szeredi struct inode *lower; 133a015dafcSAmir Goldstein 134a015dafcSAmir Goldstein /* synchronize copy up and more */ 135a015dafcSAmir Goldstein struct mutex lock; 13613cf199dSAmir Goldstein }; 13713cf199dSAmir Goldstein 13813cf199dSAmir Goldstein static inline struct ovl_inode *OVL_I(struct inode *inode) 13913cf199dSAmir Goldstein { 14013cf199dSAmir Goldstein return container_of(inode, struct ovl_inode, vfs_inode); 14113cf199dSAmir Goldstein } 14209d8b586SMiklos Szeredi 14309d8b586SMiklos Szeredi static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi) 14409d8b586SMiklos Szeredi { 145506458efSWill Deacon return READ_ONCE(oi->__upperdentry); 14609d8b586SMiklos Szeredi } 147