ovl_entry.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. *
  4. * Copyright (C) 2011 Novell Inc.
  5. * Copyright (C) 2016 Red Hat, Inc.
  6. */
  7. struct ovl_config {
  8. char *upperdir;
  9. char *workdir;
  10. char **lowerdirs;
  11. bool default_permissions;
  12. int redirect_mode;
  13. int verity_mode;
  14. bool index;
  15. int uuid;
  16. bool nfs_export;
  17. int xino;
  18. bool metacopy;
  19. bool userxattr;
  20. int fsync_mode;
  21. };
  22. struct ovl_sb {
  23. struct super_block *sb;
  24. dev_t pseudo_dev;
  25. /* Unusable (conflicting) uuid */
  26. bool bad_uuid;
  27. /* Used as a lower layer (but maybe also as upper) */
  28. bool is_lower;
  29. };
  30. struct ovl_layer {
  31. /* ovl_free_fs() relies on @mnt being the first member! */
  32. struct vfsmount *mnt;
  33. /* Trap in ovl inode cache */
  34. struct inode *trap;
  35. struct ovl_sb *fs;
  36. /* Index of this layer in fs root (upper idx == 0) */
  37. int idx;
  38. /* One fsid per unique underlying sb (upper fsid == 0) */
  39. int fsid;
  40. /* xwhiteouts were found on this layer */
  41. bool has_xwhiteouts;
  42. };
  43. struct ovl_path {
  44. const struct ovl_layer *layer;
  45. struct dentry *dentry;
  46. };
  47. struct ovl_entry {
  48. unsigned int __numlower;
  49. struct ovl_path __lowerstack[] __counted_by(__numlower);
  50. };
  51. /* private information held for overlayfs's superblock */
  52. struct ovl_fs {
  53. unsigned int numlayer;
  54. /* Number of unique fs among layers including upper fs */
  55. unsigned int numfs;
  56. /* Number of data-only lower layers */
  57. unsigned int numdatalayer;
  58. struct ovl_layer *layers;
  59. struct ovl_sb *fs;
  60. /* workbasedir is the path at workdir= mount option */
  61. struct dentry *workbasedir;
  62. /* workdir is the 'work' or 'index' directory under workbasedir */
  63. struct dentry *workdir;
  64. long namelen;
  65. /* pathnames of lower and upper dirs, for show_options */
  66. struct ovl_config config;
  67. /* creds of process who forced instantiation of super block */
  68. const struct cred *creator_cred;
  69. bool tmpfile;
  70. bool noxattr;
  71. bool nofh;
  72. /* Did we take the inuse lock? */
  73. bool upperdir_locked;
  74. bool workdir_locked;
  75. /* Traps in ovl inode cache */
  76. struct inode *workbasedir_trap;
  77. struct inode *workdir_trap;
  78. /* -1: disabled, 0: same fs, 1..32: number of unused ino bits */
  79. int xino_mode;
  80. /* For allocation of non-persistent inode numbers */
  81. atomic_long_t last_ino;
  82. /* Shared whiteout cache */
  83. struct dentry *whiteout;
  84. bool no_shared_whiteout;
  85. struct mutex whiteout_lock;
  86. /* r/o snapshot of upperdir sb's only taken on volatile mounts */
  87. errseq_t errseq;
  88. bool casefold;
  89. };
  90. /* Number of lower layers, not including data-only layers */
  91. static inline unsigned int ovl_numlowerlayer(struct ovl_fs *ofs)
  92. {
  93. return ofs->numlayer - ofs->numdatalayer - 1;
  94. }
  95. static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
  96. {
  97. return ofs->layers[0].mnt;
  98. }
  99. static inline struct mnt_idmap *ovl_upper_mnt_idmap(struct ovl_fs *ofs)
  100. {
  101. return mnt_idmap(ovl_upper_mnt(ofs));
  102. }
  103. extern struct file_system_type ovl_fs_type;
  104. static inline struct ovl_fs *OVL_FS(struct super_block *sb)
  105. {
  106. if (IS_ENABLED(CONFIG_OVERLAY_FS_DEBUG))
  107. WARN_ON_ONCE(sb->s_type != &ovl_fs_type);
  108. return (struct ovl_fs *)sb->s_fs_info;
  109. }
  110. static inline unsigned int ovl_numlower(struct ovl_entry *oe)
  111. {
  112. return oe ? oe->__numlower : 0;
  113. }
  114. static inline struct ovl_path *ovl_lowerstack(struct ovl_entry *oe)
  115. {
  116. return ovl_numlower(oe) ? oe->__lowerstack : NULL;
  117. }
  118. static inline struct ovl_path *ovl_lowerpath(struct ovl_entry *oe)
  119. {
  120. return ovl_lowerstack(oe);
  121. }
  122. static inline struct ovl_path *ovl_lowerdata(struct ovl_entry *oe)
  123. {
  124. struct ovl_path *lowerstack = ovl_lowerstack(oe);
  125. return lowerstack ? &lowerstack[oe->__numlower - 1] : NULL;
  126. }
  127. /* May return NULL if lazy lookup of lowerdata is needed */
  128. static inline struct dentry *ovl_lowerdata_dentry(struct ovl_entry *oe)
  129. {
  130. struct ovl_path *lowerdata = ovl_lowerdata(oe);
  131. return lowerdata ? READ_ONCE(lowerdata->dentry) : NULL;
  132. }
  133. /* private information held for every overlayfs dentry */
  134. static inline unsigned long *OVL_E_FLAGS(struct dentry *dentry)
  135. {
  136. return (unsigned long *) &dentry->d_fsdata;
  137. }
  138. struct ovl_inode {
  139. union {
  140. struct ovl_dir_cache *cache; /* directory */
  141. const char *lowerdata_redirect; /* regular file */
  142. };
  143. const char *redirect;
  144. u64 version;
  145. unsigned long flags;
  146. struct inode vfs_inode;
  147. struct dentry *__upperdentry;
  148. struct ovl_entry *oe;
  149. /* synchronize copy up and more */
  150. struct mutex lock;
  151. };
  152. static inline struct ovl_inode *OVL_I(struct inode *inode)
  153. {
  154. return container_of(inode, struct ovl_inode, vfs_inode);
  155. }
  156. static inline struct ovl_entry *OVL_I_E(struct inode *inode)
  157. {
  158. return inode ? OVL_I(inode)->oe : NULL;
  159. }
  160. static inline struct ovl_entry *OVL_E(struct dentry *dentry)
  161. {
  162. return OVL_I_E(d_inode(dentry));
  163. }
  164. static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
  165. {
  166. return READ_ONCE(oi->__upperdentry);
  167. }