jfs_metapage.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (C) International Business Machines Corp., 2000-2002
  3. * Portions Copyright (C) Christoph Hellwig, 2001-2002
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  13. * the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef _H_JFS_METAPAGE
  20. #define _H_JFS_METAPAGE
  21. #include <linux/pagemap.h>
  22. struct metapage {
  23. /* Common logsyncblk prefix (see jfs_logmgr.h) */
  24. u16 xflag;
  25. u16 unused;
  26. lid_t lid;
  27. int lsn;
  28. struct list_head synclist;
  29. /* End of logsyncblk prefix */
  30. unsigned long flag; /* See Below */
  31. unsigned long count; /* Reference count */
  32. void *data; /* Data pointer */
  33. sector_t index; /* block address of page */
  34. wait_queue_head_t wait;
  35. /* implementation */
  36. struct page *page;
  37. unsigned int logical_size;
  38. /* Journal management */
  39. int clsn;
  40. int nohomeok;
  41. struct jfs_log *log;
  42. };
  43. /* metapage flag */
  44. #define META_locked 0
  45. #define META_dirty 2
  46. #define META_sync 3
  47. #define META_discard 4
  48. #define META_forcewrite 5
  49. #define META_io 6
  50. #define mark_metapage_dirty(mp) set_bit(META_dirty, &(mp)->flag)
  51. /* function prototypes */
  52. extern int metapage_init(void);
  53. extern void metapage_exit(void);
  54. extern struct metapage *__get_metapage(struct inode *inode,
  55. unsigned long lblock, unsigned int size,
  56. int absolute, unsigned long new);
  57. #define read_metapage(inode, lblock, size, absolute)\
  58. __get_metapage(inode, lblock, size, absolute, false)
  59. #define get_metapage(inode, lblock, size, absolute)\
  60. __get_metapage(inode, lblock, size, absolute, true)
  61. extern void release_metapage(struct metapage *);
  62. extern void grab_metapage(struct metapage *);
  63. extern void force_metapage(struct metapage *);
  64. /*
  65. * hold_metapage and put_metapage are used in conjunction. The page lock
  66. * is not dropped between the two, so no other threads can get or release
  67. * the metapage
  68. */
  69. extern void hold_metapage(struct metapage *);
  70. extern void put_metapage(struct metapage *);
  71. static inline void write_metapage(struct metapage *mp)
  72. {
  73. set_bit(META_dirty, &mp->flag);
  74. release_metapage(mp);
  75. }
  76. static inline void flush_metapage(struct metapage *mp)
  77. {
  78. set_bit(META_sync, &mp->flag);
  79. write_metapage(mp);
  80. }
  81. static inline void discard_metapage(struct metapage *mp)
  82. {
  83. clear_bit(META_dirty, &mp->flag);
  84. set_bit(META_discard, &mp->flag);
  85. release_metapage(mp);
  86. }
  87. static inline void metapage_nohomeok(struct metapage *mp)
  88. {
  89. struct page *page = mp->page;
  90. lock_page(page);
  91. if (!mp->nohomeok++) {
  92. mark_metapage_dirty(mp);
  93. page_cache_get(page);
  94. wait_on_page_writeback(page);
  95. }
  96. unlock_page(page);
  97. }
  98. /*
  99. * This serializes access to mp->lsn when metapages are added to logsynclist
  100. * without setting nohomeok. i.e. updating imap & dmap
  101. */
  102. static inline void metapage_wait_for_io(struct metapage *mp)
  103. {
  104. if (test_bit(META_io, &mp->flag))
  105. wait_on_page_writeback(mp->page);
  106. }
  107. /*
  108. * This is called when already holding the metapage
  109. */
  110. static inline void _metapage_homeok(struct metapage *mp)
  111. {
  112. if (!--mp->nohomeok)
  113. page_cache_release(mp->page);
  114. }
  115. static inline void metapage_homeok(struct metapage *mp)
  116. {
  117. hold_metapage(mp);
  118. _metapage_homeok(mp);
  119. put_metapage(mp);
  120. }
  121. extern const struct address_space_operations jfs_metapage_aops;
  122. /*
  123. * This routines invalidate all pages for an extent.
  124. */
  125. extern void __invalidate_metapages(struct inode *, s64, int);
  126. #define invalidate_pxd_metapages(ip, pxd) \
  127. __invalidate_metapages((ip), addressPXD(&(pxd)), lengthPXD(&(pxd)))
  128. #define invalidate_dxd_metapages(ip, dxd) \
  129. __invalidate_metapages((ip), addressDXD(&(dxd)), lengthDXD(&(dxd)))
  130. #define invalidate_xad_metapages(ip, xad) \
  131. __invalidate_metapages((ip), addressXAD(&(xad)), lengthXAD(&(xad)))
  132. #endif /* _H_JFS_METAPAGE */