1bbb1e54dSMiklos Szeredi /* 2bbb1e54dSMiklos Szeredi * 3bbb1e54dSMiklos Szeredi * Copyright (C) 2011 Novell Inc. 4bbb1e54dSMiklos Szeredi * Copyright (C) 2016 Red Hat, Inc. 5bbb1e54dSMiklos Szeredi * 6bbb1e54dSMiklos Szeredi * This program is free software; you can redistribute it and/or modify it 7bbb1e54dSMiklos Szeredi * under the terms of the GNU General Public License version 2 as published by 8bbb1e54dSMiklos Szeredi * the Free Software Foundation. 9bbb1e54dSMiklos Szeredi */ 10bbb1e54dSMiklos Szeredi 11bbb1e54dSMiklos Szeredi struct ovl_config { 12bbb1e54dSMiklos Szeredi char *lowerdir; 13bbb1e54dSMiklos Szeredi char *upperdir; 14bbb1e54dSMiklos Szeredi char *workdir; 15bbb1e54dSMiklos Szeredi bool default_permissions; 16a6c60655SMiklos Szeredi bool redirect_dir; 17438c84c2SMiklos Szeredi bool redirect_follow; 18438c84c2SMiklos Szeredi const char *redirect_mode; 1902bcd157SAmir Goldstein bool index; 20f168f109SAmir Goldstein bool nfs_export; 21795939a9SAmir Goldstein int xino; 22d5791044SVivek Goyal bool metacopy; 23bbb1e54dSMiklos Szeredi }; 24bbb1e54dSMiklos Szeredi 255148626bSAmir Goldstein struct ovl_sb { 265148626bSAmir Goldstein struct super_block *sb; 275148626bSAmir Goldstein dev_t pseudo_dev; 285148626bSAmir Goldstein }; 295148626bSAmir Goldstein 30b9343632SChandan Rajendra struct ovl_layer { 31b9343632SChandan Rajendra struct vfsmount *mnt; 325148626bSAmir Goldstein struct ovl_sb *fs; 335148626bSAmir Goldstein /* Index of this layer in fs root (upper idx == 0) */ 34d583ed7dSAmir Goldstein int idx; 355148626bSAmir Goldstein /* One fsid per unique underlying sb (upper fsid == 0) */ 365148626bSAmir Goldstein int fsid; 37b9343632SChandan Rajendra }; 38b9343632SChandan Rajendra 39b9343632SChandan Rajendra struct ovl_path { 40b9343632SChandan Rajendra struct ovl_layer *layer; 41b9343632SChandan Rajendra struct dentry *dentry; 42b9343632SChandan Rajendra }; 43b9343632SChandan Rajendra 44bbb1e54dSMiklos Szeredi /* private information held for overlayfs's superblock */ 45bbb1e54dSMiklos Szeredi struct ovl_fs { 46bbb1e54dSMiklos Szeredi struct vfsmount *upper_mnt; 475148626bSAmir Goldstein unsigned int numlower; 485148626bSAmir Goldstein /* Number of unique lower sb that differ from upper sb */ 495148626bSAmir Goldstein unsigned int numlowerfs; 50b9343632SChandan Rajendra struct ovl_layer *lower_layers; 515148626bSAmir Goldstein struct ovl_sb *lower_fs; 522cac0c00SAmir Goldstein /* workbasedir is the path at workdir= mount option */ 532cac0c00SAmir Goldstein struct dentry *workbasedir; 542cac0c00SAmir Goldstein /* workdir is the 'work' directory under workbasedir */ 55bbb1e54dSMiklos Szeredi struct dentry *workdir; 5602bcd157SAmir Goldstein /* index directory listing overlay inodes by origin file handle */ 5702bcd157SAmir Goldstein struct dentry *indexdir; 586b2d5fe4SMiklos Szeredi long namelen; 59bbb1e54dSMiklos Szeredi /* pathnames of lower and upper dirs, for show_options */ 60bbb1e54dSMiklos Szeredi struct ovl_config config; 61bbb1e54dSMiklos Szeredi /* creds of process who forced instantiation of super block */ 62bbb1e54dSMiklos Szeredi const struct cred *creator_cred; 63e7f52429SAmir Goldstein bool tmpfile; 6482b749b2SAmir Goldstein bool noxattr; 6585fdee1eSAmir Goldstein /* Did we take the inuse lock? */ 6685fdee1eSAmir Goldstein bool upperdir_locked; 6785fdee1eSAmir Goldstein bool workdir_locked; 68e487d889SAmir Goldstein /* Inode numbers in all layers do not use the high xino_bits */ 69e487d889SAmir Goldstein unsigned int xino_bits; 70bbb1e54dSMiklos Szeredi }; 71bbb1e54dSMiklos Szeredi 72bbb1e54dSMiklos Szeredi /* private information held for every overlayfs dentry */ 73bbb1e54dSMiklos Szeredi struct ovl_entry { 74bbb1e54dSMiklos Szeredi union { 7555acc661SMiklos Szeredi struct { 76c62520a8SAmir Goldstein unsigned long flags; 7755acc661SMiklos Szeredi }; 78bbb1e54dSMiklos Szeredi struct rcu_head rcu; 79bbb1e54dSMiklos Szeredi }; 80bbb1e54dSMiklos Szeredi unsigned numlower; 81b9343632SChandan Rajendra struct ovl_path lowerstack[]; 82bbb1e54dSMiklos Szeredi }; 83bbb1e54dSMiklos Szeredi 84bbb1e54dSMiklos Szeredi struct ovl_entry *ovl_alloc_entry(unsigned int numlower); 85bbb1e54dSMiklos Szeredi 86c62520a8SAmir Goldstein static inline struct ovl_entry *OVL_E(struct dentry *dentry) 87c62520a8SAmir Goldstein { 88c62520a8SAmir Goldstein return (struct ovl_entry *) dentry->d_fsdata; 89c62520a8SAmir Goldstein } 90c62520a8SAmir Goldstein 9113cf199dSAmir Goldstein struct ovl_inode { 9204a01ac7SMiklos Szeredi struct ovl_dir_cache *cache; 93cf31c463SMiklos Szeredi const char *redirect; 9404a01ac7SMiklos Szeredi u64 version; 9513c72075SMiklos Szeredi unsigned long flags; 9613cf199dSAmir Goldstein struct inode vfs_inode; 9709d8b586SMiklos Szeredi struct dentry *__upperdentry; 9825b7713aSMiklos Szeredi struct inode *lower; 99a015dafcSAmir Goldstein 100a015dafcSAmir Goldstein /* synchronize copy up and more */ 101a015dafcSAmir Goldstein struct mutex lock; 10213cf199dSAmir Goldstein }; 10313cf199dSAmir Goldstein 10413cf199dSAmir Goldstein static inline struct ovl_inode *OVL_I(struct inode *inode) 10513cf199dSAmir Goldstein { 10613cf199dSAmir Goldstein return container_of(inode, struct ovl_inode, vfs_inode); 10713cf199dSAmir Goldstein } 10809d8b586SMiklos Szeredi 10909d8b586SMiklos Szeredi static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi) 11009d8b586SMiklos Szeredi { 111506458efSWill Deacon return READ_ONCE(oi->__upperdentry); 11209d8b586SMiklos Szeredi } 113