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; 17f168f109SAmir Goldstein bool nfs_export; 18795939a9SAmir Goldstein int xino; 19d5791044SVivek Goyal bool metacopy; 20bbb1e54dSMiklos Szeredi }; 21bbb1e54dSMiklos Szeredi 225148626bSAmir Goldstein struct ovl_sb { 235148626bSAmir Goldstein struct super_block *sb; 245148626bSAmir Goldstein dev_t pseudo_dev; 257e63c87fSAmir Goldstein /* Unusable (conflicting) uuid */ 267e63c87fSAmir Goldstein bool bad_uuid; 271b81ddddSAmir Goldstein /* Used as a lower layer (but maybe also as upper) */ 281b81ddddSAmir Goldstein bool is_lower; 295148626bSAmir Goldstein }; 305148626bSAmir Goldstein 31b9343632SChandan Rajendra struct ovl_layer { 32b9343632SChandan Rajendra struct vfsmount *mnt; 33146d62e5SAmir Goldstein /* Trap in ovl inode cache */ 34146d62e5SAmir Goldstein struct inode *trap; 355148626bSAmir Goldstein struct ovl_sb *fs; 365148626bSAmir Goldstein /* Index of this layer in fs root (upper idx == 0) */ 37d583ed7dSAmir Goldstein int idx; 385148626bSAmir Goldstein /* One fsid per unique underlying sb (upper fsid == 0) */ 395148626bSAmir Goldstein int fsid; 40b9343632SChandan Rajendra }; 41b9343632SChandan Rajendra 42b9343632SChandan Rajendra struct ovl_path { 4313464165SMiklos Szeredi const struct ovl_layer *layer; 44b9343632SChandan Rajendra struct dentry *dentry; 45b9343632SChandan Rajendra }; 46b9343632SChandan Rajendra 47bbb1e54dSMiklos Szeredi /* private information held for overlayfs's superblock */ 48bbb1e54dSMiklos Szeredi struct ovl_fs { 49bbb1e54dSMiklos Szeredi struct vfsmount *upper_mnt; 5094375f9dSAmir Goldstein unsigned int numlayer; 5107f1e596SAmir Goldstein /* Number of unique fs among layers including upper fs */ 5207f1e596SAmir Goldstein unsigned int numfs; 5313464165SMiklos Szeredi const struct ovl_layer *layers; 5407f1e596SAmir Goldstein struct ovl_sb *fs; 552cac0c00SAmir Goldstein /* workbasedir is the path at workdir= mount option */ 562cac0c00SAmir Goldstein struct dentry *workbasedir; 572cac0c00SAmir Goldstein /* workdir is the 'work' directory under workbasedir */ 58bbb1e54dSMiklos Szeredi struct dentry *workdir; 5902bcd157SAmir Goldstein /* index directory listing overlay inodes by origin file handle */ 6002bcd157SAmir Goldstein struct dentry *indexdir; 616b2d5fe4SMiklos Szeredi long namelen; 62bbb1e54dSMiklos Szeredi /* pathnames of lower and upper dirs, for show_options */ 63bbb1e54dSMiklos Szeredi struct ovl_config config; 64bbb1e54dSMiklos Szeredi /* creds of process who forced instantiation of super block */ 65bbb1e54dSMiklos Szeredi const struct cred *creator_cred; 66e7f52429SAmir Goldstein bool tmpfile; 6782b749b2SAmir Goldstein bool noxattr; 6885fdee1eSAmir Goldstein /* Did we take the inuse lock? */ 6985fdee1eSAmir Goldstein bool upperdir_locked; 7085fdee1eSAmir Goldstein bool workdir_locked; 71146d62e5SAmir Goldstein /* Traps in ovl inode cache */ 72146d62e5SAmir Goldstein struct inode *upperdir_trap; 730be0bfd2SAmir Goldstein struct inode *workbasedir_trap; 74146d62e5SAmir Goldstein struct inode *workdir_trap; 75146d62e5SAmir Goldstein struct inode *indexdir_trap; 760f831ec8SAmir Goldstein /* -1: disabled, 0: same fs, 1..32: number of unused ino bits */ 770f831ec8SAmir Goldstein int xino_mode; 78bbb1e54dSMiklos Szeredi }; 79bbb1e54dSMiklos Szeredi 800f831ec8SAmir Goldstein static inline struct ovl_fs *OVL_FS(struct super_block *sb) 810f831ec8SAmir Goldstein { 820f831ec8SAmir Goldstein return (struct ovl_fs *)sb->s_fs_info; 830f831ec8SAmir Goldstein } 840f831ec8SAmir Goldstein 85bbb1e54dSMiklos Szeredi /* private information held for every overlayfs dentry */ 86bbb1e54dSMiklos Szeredi struct ovl_entry { 87bbb1e54dSMiklos Szeredi union { 8855acc661SMiklos Szeredi struct { 89c62520a8SAmir Goldstein unsigned long flags; 9055acc661SMiklos Szeredi }; 91bbb1e54dSMiklos Szeredi struct rcu_head rcu; 92bbb1e54dSMiklos Szeredi }; 93bbb1e54dSMiklos Szeredi unsigned numlower; 94b9343632SChandan Rajendra struct ovl_path lowerstack[]; 95bbb1e54dSMiklos Szeredi }; 96bbb1e54dSMiklos Szeredi 97bbb1e54dSMiklos Szeredi struct ovl_entry *ovl_alloc_entry(unsigned int numlower); 98bbb1e54dSMiklos Szeredi 99c62520a8SAmir Goldstein static inline struct ovl_entry *OVL_E(struct dentry *dentry) 100c62520a8SAmir Goldstein { 101c62520a8SAmir Goldstein return (struct ovl_entry *) dentry->d_fsdata; 102c62520a8SAmir Goldstein } 103c62520a8SAmir Goldstein 10413cf199dSAmir Goldstein struct ovl_inode { 1052664bd08SVivek Goyal union { 1062664bd08SVivek Goyal struct ovl_dir_cache *cache; /* directory */ 1072664bd08SVivek Goyal struct inode *lowerdata; /* regular file */ 1082664bd08SVivek Goyal }; 109cf31c463SMiklos Szeredi const char *redirect; 11004a01ac7SMiklos Szeredi u64 version; 11113c72075SMiklos Szeredi unsigned long flags; 11213cf199dSAmir Goldstein struct inode vfs_inode; 11309d8b586SMiklos Szeredi struct dentry *__upperdentry; 11425b7713aSMiklos Szeredi struct inode *lower; 115a015dafcSAmir Goldstein 116a015dafcSAmir Goldstein /* synchronize copy up and more */ 117a015dafcSAmir Goldstein struct mutex lock; 11813cf199dSAmir Goldstein }; 11913cf199dSAmir Goldstein 12013cf199dSAmir Goldstein static inline struct ovl_inode *OVL_I(struct inode *inode) 12113cf199dSAmir Goldstein { 12213cf199dSAmir Goldstein return container_of(inode, struct ovl_inode, vfs_inode); 12313cf199dSAmir Goldstein } 12409d8b586SMiklos Szeredi 12509d8b586SMiklos Szeredi static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi) 12609d8b586SMiklos Szeredi { 127506458efSWill Deacon return READ_ONCE(oi->__upperdentry); 12809d8b586SMiklos Szeredi } 129