Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  *
0004  * Copyright (C) 2011 Novell Inc.
0005  * Copyright (C) 2016 Red Hat, Inc.
0006  */
0007 
0008 struct ovl_config {
0009     char *lowerdir;
0010     char *upperdir;
0011     char *workdir;
0012     bool default_permissions;
0013     bool redirect_dir;
0014     bool redirect_follow;
0015     const char *redirect_mode;
0016     bool index;
0017     bool uuid;
0018     bool nfs_export;
0019     int xino;
0020     bool metacopy;
0021     bool userxattr;
0022     bool ovl_volatile;
0023 };
0024 
0025 struct ovl_sb {
0026     struct super_block *sb;
0027     dev_t pseudo_dev;
0028     /* Unusable (conflicting) uuid */
0029     bool bad_uuid;
0030     /* Used as a lower layer (but maybe also as upper) */
0031     bool is_lower;
0032 };
0033 
0034 struct ovl_layer {
0035     struct vfsmount *mnt;
0036     /* Trap in ovl inode cache */
0037     struct inode *trap;
0038     struct ovl_sb *fs;
0039     /* Index of this layer in fs root (upper idx == 0) */
0040     int idx;
0041     /* One fsid per unique underlying sb (upper fsid == 0) */
0042     int fsid;
0043 };
0044 
0045 struct ovl_path {
0046     const struct ovl_layer *layer;
0047     struct dentry *dentry;
0048 };
0049 
0050 /* private information held for overlayfs's superblock */
0051 struct ovl_fs {
0052     unsigned int numlayer;
0053     /* Number of unique fs among layers including upper fs */
0054     unsigned int numfs;
0055     const struct ovl_layer *layers;
0056     struct ovl_sb *fs;
0057     /* workbasedir is the path at workdir= mount option */
0058     struct dentry *workbasedir;
0059     /* workdir is the 'work' directory under workbasedir */
0060     struct dentry *workdir;
0061     /* index directory listing overlay inodes by origin file handle */
0062     struct dentry *indexdir;
0063     long namelen;
0064     /* pathnames of lower and upper dirs, for show_options */
0065     struct ovl_config config;
0066     /* creds of process who forced instantiation of super block */
0067     const struct cred *creator_cred;
0068     bool tmpfile;
0069     bool noxattr;
0070     /* Did we take the inuse lock? */
0071     bool upperdir_locked;
0072     bool workdir_locked;
0073     bool share_whiteout;
0074     /* Traps in ovl inode cache */
0075     struct inode *workbasedir_trap;
0076     struct inode *workdir_trap;
0077     struct inode *indexdir_trap;
0078     /* -1: disabled, 0: same fs, 1..32: number of unused ino bits */
0079     int xino_mode;
0080     /* For allocation of non-persistent inode numbers */
0081     atomic_long_t last_ino;
0082     /* Whiteout dentry cache */
0083     struct dentry *whiteout;
0084     /* r/o snapshot of upperdir sb's only taken on volatile mounts */
0085     errseq_t errseq;
0086 };
0087 
0088 static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
0089 {
0090     return ofs->layers[0].mnt;
0091 }
0092 
0093 static inline struct user_namespace *ovl_upper_mnt_userns(struct ovl_fs *ofs)
0094 {
0095     return mnt_user_ns(ovl_upper_mnt(ofs));
0096 }
0097 
0098 static inline struct ovl_fs *OVL_FS(struct super_block *sb)
0099 {
0100     return (struct ovl_fs *)sb->s_fs_info;
0101 }
0102 
0103 static inline bool ovl_should_sync(struct ovl_fs *ofs)
0104 {
0105     return !ofs->config.ovl_volatile;
0106 }
0107 
0108 /* private information held for every overlayfs dentry */
0109 struct ovl_entry {
0110     union {
0111         struct {
0112             unsigned long flags;
0113         };
0114         struct rcu_head rcu;
0115     };
0116     unsigned numlower;
0117     struct ovl_path lowerstack[];
0118 };
0119 
0120 struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
0121 
0122 static inline struct ovl_entry *OVL_E(struct dentry *dentry)
0123 {
0124     return (struct ovl_entry *) dentry->d_fsdata;
0125 }
0126 
0127 struct ovl_inode {
0128     union {
0129         struct ovl_dir_cache *cache;    /* directory */
0130         struct inode *lowerdata;    /* regular file */
0131     };
0132     const char *redirect;
0133     u64 version;
0134     unsigned long flags;
0135     struct inode vfs_inode;
0136     struct dentry *__upperdentry;
0137     struct ovl_path lowerpath;
0138 
0139     /* synchronize copy up and more */
0140     struct mutex lock;
0141 };
0142 
0143 static inline struct ovl_inode *OVL_I(struct inode *inode)
0144 {
0145     return container_of(inode, struct ovl_inode, vfs_inode);
0146 }
0147 
0148 static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
0149 {
0150     return READ_ONCE(oi->__upperdentry);
0151 }