ovl_entry.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. *
  3. * Copyright (C) 2011 Novell Inc.
  4. * Copyright (C) 2016 Red Hat, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. */
  10. struct ovl_config {
  11. char *lowerdir;
  12. char *upperdir;
  13. char *workdir;
  14. bool default_permissions;
  15. bool redirect_dir;
  16. bool redirect_follow;
  17. const char *redirect_mode;
  18. bool index;
  19. bool nfs_export;
  20. int xino;
  21. bool metacopy;
  22. };
  23. struct ovl_sb {
  24. struct super_block *sb;
  25. dev_t pseudo_dev;
  26. };
  27. struct ovl_layer {
  28. struct vfsmount *mnt;
  29. /* Trap in ovl inode cache */
  30. struct inode *trap;
  31. struct ovl_sb *fs;
  32. /* Index of this layer in fs root (upper idx == 0) */
  33. int idx;
  34. /* One fsid per unique underlying sb (upper fsid == 0) */
  35. int fsid;
  36. };
  37. struct ovl_path {
  38. struct ovl_layer *layer;
  39. struct dentry *dentry;
  40. };
  41. /* private information held for overlayfs's superblock */
  42. struct ovl_fs {
  43. struct vfsmount *upper_mnt;
  44. unsigned int numlower;
  45. /* Number of unique lower sb that differ from upper sb */
  46. unsigned int numlowerfs;
  47. struct ovl_layer *lower_layers;
  48. struct ovl_sb *lower_fs;
  49. /* workbasedir is the path at workdir= mount option */
  50. struct dentry *workbasedir;
  51. /* workdir is the 'work' directory under workbasedir */
  52. struct dentry *workdir;
  53. /* index directory listing overlay inodes by origin file handle */
  54. struct dentry *indexdir;
  55. long namelen;
  56. /* pathnames of lower and upper dirs, for show_options */
  57. struct ovl_config config;
  58. /* creds of process who forced instantiation of super block */
  59. const struct cred *creator_cred;
  60. bool tmpfile;
  61. bool noxattr;
  62. /* Did we take the inuse lock? */
  63. bool upperdir_locked;
  64. bool workdir_locked;
  65. /* Traps in ovl inode cache */
  66. struct inode *upperdir_trap;
  67. struct inode *workbasedir_trap;
  68. struct inode *workdir_trap;
  69. struct inode *indexdir_trap;
  70. /* Inode numbers in all layers do not use the high xino_bits */
  71. unsigned int xino_bits;
  72. };
  73. /* private information held for every overlayfs dentry */
  74. struct ovl_entry {
  75. union {
  76. struct {
  77. unsigned long flags;
  78. };
  79. struct rcu_head rcu;
  80. };
  81. unsigned numlower;
  82. struct ovl_path lowerstack[];
  83. };
  84. struct ovl_entry *ovl_alloc_entry(unsigned int numlower);
  85. static inline struct ovl_entry *OVL_E(struct dentry *dentry)
  86. {
  87. return (struct ovl_entry *) dentry->d_fsdata;
  88. }
  89. struct ovl_inode {
  90. union {
  91. struct ovl_dir_cache *cache; /* directory */
  92. struct inode *lowerdata; /* regular file */
  93. };
  94. const char *redirect;
  95. u64 version;
  96. unsigned long flags;
  97. struct inode vfs_inode;
  98. struct dentry *__upperdentry;
  99. struct inode *lower;
  100. /* synchronize copy up and more */
  101. struct mutex lock;
  102. };
  103. static inline struct ovl_inode *OVL_I(struct inode *inode)
  104. {
  105. return container_of(inode, struct ovl_inode, vfs_inode);
  106. }
  107. static inline struct dentry *ovl_upperdentry_dereference(struct ovl_inode *oi)
  108. {
  109. return READ_ONCE(oi->__upperdentry);
  110. }