Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Dave Kleikamp | 1868f4a | 2005-05-04 15:29:35 -0500 | [diff] [blame] | 2 | * Copyright (C) International Business Machines Corp., 2000-2002 |
| 3 | * Portions Copyright (C) Christoph Hellwig, 2001-2002 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 7 | * the Free Software Foundation; either version 2 of the License, or |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * (at your option) any later version. |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 16 | * along with this program; if not, write to the Free Software |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 22 | #include <linux/pagemap.h> |
| 23 | |
| 24 | struct metapage { |
| 25 | /* Common logsyncblk prefix (see jfs_logmgr.h) */ |
| 26 | u16 xflag; |
| 27 | u16 unused; |
| 28 | lid_t lid; |
| 29 | int lsn; |
| 30 | struct list_head synclist; |
| 31 | /* End of logsyncblk prefix */ |
| 32 | |
| 33 | unsigned long flag; /* See Below */ |
| 34 | unsigned long count; /* Reference count */ |
| 35 | void *data; /* Data pointer */ |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 36 | sector_t index; /* block address of page */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | wait_queue_head_t wait; |
| 38 | |
| 39 | /* implementation */ |
| 40 | struct page *page; |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 41 | unsigned int logical_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | /* Journal management */ |
| 44 | int clsn; |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 45 | int nohomeok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | struct jfs_log *log; |
| 47 | }; |
| 48 | |
| 49 | /* metapage flag */ |
| 50 | #define META_locked 0 |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 51 | #define META_dirty 2 |
| 52 | #define META_sync 3 |
| 53 | #define META_discard 4 |
| 54 | #define META_forcewrite 5 |
| 55 | #define META_io 6 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | #define mark_metapage_dirty(mp) set_bit(META_dirty, &(mp)->flag) |
| 58 | |
| 59 | /* function prototypes */ |
Dave Kleikamp | 1868f4a | 2005-05-04 15:29:35 -0500 | [diff] [blame] | 60 | extern int metapage_init(void); |
| 61 | extern void metapage_exit(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | extern struct metapage *__get_metapage(struct inode *inode, |
| 63 | unsigned long lblock, unsigned int size, |
| 64 | int absolute, unsigned long new); |
| 65 | |
| 66 | #define read_metapage(inode, lblock, size, absolute)\ |
Richard Knutsson | 4d81715 | 2006-09-30 23:27:14 -0700 | [diff] [blame] | 67 | __get_metapage(inode, lblock, size, absolute, false) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | #define get_metapage(inode, lblock, size, absolute)\ |
Richard Knutsson | 4d81715 | 2006-09-30 23:27:14 -0700 | [diff] [blame] | 70 | __get_metapage(inode, lblock, size, absolute, true) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | extern void release_metapage(struct metapage *); |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 73 | extern void grab_metapage(struct metapage *); |
| 74 | extern void force_metapage(struct metapage *); |
| 75 | |
| 76 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 77 | * hold_metapage and put_metapage are used in conjunction. The page lock |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 78 | * is not dropped between the two, so no other threads can get or release |
| 79 | * the metapage |
| 80 | */ |
| 81 | extern void hold_metapage(struct metapage *); |
| 82 | extern void put_metapage(struct metapage *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
| 84 | static inline void write_metapage(struct metapage *mp) |
| 85 | { |
| 86 | set_bit(META_dirty, &mp->flag); |
| 87 | release_metapage(mp); |
| 88 | } |
| 89 | |
| 90 | static inline void flush_metapage(struct metapage *mp) |
| 91 | { |
| 92 | set_bit(META_sync, &mp->flag); |
| 93 | write_metapage(mp); |
| 94 | } |
| 95 | |
| 96 | static inline void discard_metapage(struct metapage *mp) |
| 97 | { |
| 98 | clear_bit(META_dirty, &mp->flag); |
| 99 | set_bit(META_discard, &mp->flag); |
| 100 | release_metapage(mp); |
| 101 | } |
| 102 | |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 103 | static inline void metapage_nohomeok(struct metapage *mp) |
| 104 | { |
| 105 | struct page *page = mp->page; |
| 106 | lock_page(page); |
| 107 | if (!mp->nohomeok++) { |
| 108 | mark_metapage_dirty(mp); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 109 | get_page(page); |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 110 | wait_on_page_writeback(page); |
| 111 | } |
| 112 | unlock_page(page); |
| 113 | } |
| 114 | |
| 115 | /* |
| 116 | * This serializes access to mp->lsn when metapages are added to logsynclist |
| 117 | * without setting nohomeok. i.e. updating imap & dmap |
| 118 | */ |
| 119 | static inline void metapage_wait_for_io(struct metapage *mp) |
| 120 | { |
| 121 | if (test_bit(META_io, &mp->flag)) |
| 122 | wait_on_page_writeback(mp->page); |
| 123 | } |
| 124 | |
| 125 | /* |
| 126 | * This is called when already holding the metapage |
| 127 | */ |
| 128 | static inline void _metapage_homeok(struct metapage *mp) |
| 129 | { |
| 130 | if (!--mp->nohomeok) |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 131 | put_page(mp->page); |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | static inline void metapage_homeok(struct metapage *mp) |
| 135 | { |
| 136 | hold_metapage(mp); |
| 137 | _metapage_homeok(mp); |
| 138 | put_metapage(mp); |
| 139 | } |
| 140 | |
Christoph Hellwig | f5e54d6 | 2006-06-28 04:26:44 -0700 | [diff] [blame] | 141 | extern const struct address_space_operations jfs_metapage_aops; |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | /* |
| 144 | * This routines invalidate all pages for an extent. |
| 145 | */ |
| 146 | extern void __invalidate_metapages(struct inode *, s64, int); |
| 147 | #define invalidate_pxd_metapages(ip, pxd) \ |
| 148 | __invalidate_metapages((ip), addressPXD(&(pxd)), lengthPXD(&(pxd))) |
| 149 | #define invalidate_dxd_metapages(ip, dxd) \ |
| 150 | __invalidate_metapages((ip), addressDXD(&(dxd)), lengthDXD(&(dxd))) |
| 151 | #define invalidate_xad_metapages(ip, xad) \ |
| 152 | __invalidate_metapages((ip), addressXAD(&(xad)), lengthXAD(&(xad))) |
| 153 | |
| 154 | #endif /* _H_JFS_METAPAGE */ |