ovl_entry.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. bool ovl_volatile;
  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[];
  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. /* r/o snapshot of upperdir sb's only taken on volatile mounts */
  86. errseq_t errseq;
  87. };
  88. /* Number of lower layers, not including data-only layers */
  89. static inline unsigned int ovl_numlowerlayer(struct ovl_fs *ofs)
  90. {
  91. return ofs->numlayer - ofs->numdatalayer - 1;
  92. }
  93. static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
  94. {
  95. return ofs->layers[0].mnt;
  96. }
  97. static inline struct mnt_idmap *ovl_upper_mnt_idmap(struct ovl_fs *ofs)
  98. {
  99. return mnt_idmap(ovl_upper_mnt(ofs));
  100. }
  101. extern struct file_system_type ovl_fs_type;
  102. static inline struct ovl_fs *OVL_FS(struct super_block *sb)
  103. {
  104. if (IS_ENABLED(CONFIG_OVERLAY_FS_DEBUG))
  105. WARN_ON_ONCE(sb->s_type != &ovl_fs_type);
  106. return (struct ovl_fs *)sb->s_fs_info;
  107. }
  108. static inline bool ovl_should_sync(struct ovl_fs *ofs)
  109. {
  110. return !ofs->config.ovl_volatile;
  111. }
  112. static inline unsigned int ovl_numlower(struct ovl_entry *oe)
  113. {
  114. return oe ? oe->__numlower : 0;
  115. }
  116. static inline struct ovl_path *ovl_lowerstack(struct ovl_entry *oe)
  117. {
  118. return ovl_numlower(oe) ? oe->__lowerstack : NULL;
  119. }
  120. static inline struct ovl_path *ovl_lowerpath(struct ovl_entry *oe)
  121. {
  122. return ovl_lowerstack(oe);
  123. }
  124. static inline struct ovl_path *ovl_lowerdata(struct ovl_entry *oe)
  125. {
  126. struct ovl_path *lowerstack = ovl_lowerstack(oe);
  127. return lowerstack ? &lowerstack[oe->__numlower - 1] : NULL;
  128. }
  129. /* May return NULL if lazy lookup of lowerdata is needed */
  130. static inline struct dentry *ovl_lowerdata_dentry(struct ovl_entry *oe)
  131. {
  132. struct ovl_path *lowerdata = ovl_lowerdata(oe);
  133. return lowerdata ? READ_ONCE(lowerdata->dentry) : NULL;
  134. }
  135. /* private information held for every overlayfs dentry */
  136. static inline unsigned long *OVL_E_FLAGS(struct dentry *dentry)
  137. {
  138. return (unsigned long *) &dentry->d_fsdata;
  139. }
  140. struct ovl_inode {
  141. union {
  142. struct ovl_dir_cache *cache; /* directory */
  143. const char *lowerdata_redirect; /* regular file */
  144. };
  145. const char *redirect;
  146. u64 version;
  147. unsigned long flags;
  148. struct inode vfs_inode;
  149. struct dentry *__upperdentry;
  150. struct ovl_entry *oe;
  151. /* synchronize copy up and more */
  152. struct mutex lock;
  153. };
  154. static inline struct ovl_inode *OVL_I(struct inode *inode)
  155. {
  156. return container_of(inode, struct ovl_inode, vfs_inode);
  157. }
  158. static inline struct ovl_entry *OVL_I_E(struct inode *inode)
  159. {
  160. return inode ? OVL_I(inode)->oe : NULL;
  161. }
  162. static inline struct ovl_entry *OVL_E(struct dentry *dentry)
  163. {
  164. return OVL_I_E(d_inode(dentry));
  165. }
  166. static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
  167. {
  168. return READ_ONCE(oi->__upperdentry);
  169. }