ovl_entry.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 *lowerdir;
  9. char *upperdir;
  10. char *workdir;
  11. bool default_permissions;
  12. bool redirect_dir;
  13. bool redirect_follow;
  14. const char *redirect_mode;
  15. bool index;
  16. bool uuid;
  17. bool nfs_export;
  18. int xino;
  19. bool metacopy;
  20. bool userxattr;
  21. bool ovl_volatile;
  22. bool override_creds;
  23. };
  24. struct ovl_sb {
  25. struct super_block *sb;
  26. dev_t pseudo_dev;
  27. /* Unusable (conflicting) uuid */
  28. bool bad_uuid;
  29. /* Used as a lower layer (but maybe also as upper) */
  30. bool is_lower;
  31. };
  32. struct ovl_layer {
  33. /* ovl_free_fs() relies on @mnt being the first member! */
  34. struct vfsmount *mnt;
  35. /* Trap in ovl inode cache */
  36. struct inode *trap;
  37. struct ovl_sb *fs;
  38. /* Index of this layer in fs root (upper idx == 0) */
  39. int idx;
  40. /* One fsid per unique underlying sb (upper fsid == 0) */
  41. int fsid;
  42. };
  43. /*
  44. * ovl_free_fs() relies on @mnt being the first member when unmounting
  45. * the private mounts created for each layer. Let's check both the
  46. * offset and type.
  47. */
  48. static_assert(offsetof(struct ovl_layer, mnt) == 0);
  49. static_assert(__same_type(typeof_member(struct ovl_layer, mnt), struct vfsmount *));
  50. struct ovl_path {
  51. const struct ovl_layer *layer;
  52. struct dentry *dentry;
  53. };
  54. /* private information held for overlayfs's superblock */
  55. struct ovl_fs {
  56. unsigned int numlayer;
  57. /* Number of unique fs among layers including upper fs */
  58. unsigned int numfs;
  59. const struct ovl_layer *layers;
  60. struct ovl_sb *fs;
  61. /* workbasedir is the path at workdir= mount option */
  62. struct dentry *workbasedir;
  63. /* workdir is the 'work' directory under workbasedir */
  64. struct dentry *workdir;
  65. /* index directory listing overlay inodes by origin file handle */
  66. struct dentry *indexdir;
  67. long namelen;
  68. /* pathnames of lower and upper dirs, for show_options */
  69. struct ovl_config config;
  70. /* creds of process who forced instantiation of super block */
  71. const struct cred *creator_cred;
  72. bool tmpfile;
  73. bool noxattr;
  74. /* Did we take the inuse lock? */
  75. bool upperdir_locked;
  76. bool workdir_locked;
  77. bool share_whiteout;
  78. /* Traps in ovl inode cache */
  79. struct inode *workbasedir_trap;
  80. struct inode *workdir_trap;
  81. struct inode *indexdir_trap;
  82. /* -1: disabled, 0: same fs, 1..32: number of unused ino bits */
  83. int xino_mode;
  84. /* For allocation of non-persistent inode numbers */
  85. atomic_long_t last_ino;
  86. /* Whiteout dentry cache */
  87. struct dentry *whiteout;
  88. /* r/o snapshot of upperdir sb's only taken on volatile mounts */
  89. errseq_t errseq;
  90. };
  91. static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
  92. {
  93. return ofs->layers[0].mnt;
  94. }
  95. static inline struct user_namespace *ovl_upper_mnt_userns(struct ovl_fs *ofs)
  96. {
  97. return mnt_user_ns(ovl_upper_mnt(ofs));
  98. }
  99. static inline struct ovl_fs *OVL_FS(struct super_block *sb)
  100. {
  101. return (struct ovl_fs *)sb->s_fs_info;
  102. }
  103. static inline bool ovl_should_sync(struct ovl_fs *ofs)
  104. {
  105. return !ofs->config.ovl_volatile;
  106. }
  107. /* private information held for every overlayfs dentry */
  108. struct ovl_entry {
  109. union {
  110. struct {
  111. unsigned long flags;
  112. };
  113. struct rcu_head rcu;
  114. };
  115. unsigned numlower;
  116. struct ovl_path lowerstack[];
  117. };
  118. struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
  119. static inline struct ovl_entry *OVL_E(struct dentry *dentry)
  120. {
  121. return (struct ovl_entry *) dentry->d_fsdata;
  122. }
  123. struct ovl_inode {
  124. union {
  125. struct ovl_dir_cache *cache; /* directory */
  126. struct inode *lowerdata; /* regular file */
  127. };
  128. const char *redirect;
  129. u64 version;
  130. unsigned long flags;
  131. struct inode vfs_inode;
  132. struct dentry *__upperdentry;
  133. struct ovl_path lowerpath;
  134. /* synchronize copy up and more */
  135. struct mutex lock;
  136. };
  137. static inline struct ovl_inode *OVL_I(struct inode *inode)
  138. {
  139. return container_of(inode, struct ovl_inode, vfs_inode);
  140. }
  141. static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
  142. {
  143. return READ_ONCE(oi->__upperdentry);
  144. }