blob: d17a3290f5aab901253c0f2d43b136a237dc893d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Dave Kleikamp1868f4a2005-05-04 15:29:35 -05002 * Copyright (C) International Business Machines Corp., 2000-2002
3 * Portions Copyright (C) Christoph Hellwig, 2001-2002
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
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
22#include <linux/pagemap.h>
23
24struct 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 Kleikamp7fab4792005-05-02 12:25:02 -060036 sector_t index; /* block address of page */
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 wait_queue_head_t wait;
38
39 /* implementation */
40 struct page *page;
Dave Kleikamp7fab4792005-05-02 12:25:02 -060041 unsigned int logical_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43 /* Journal management */
44 int clsn;
Dave Kleikamp7fab4792005-05-02 12:25:02 -060045 int nohomeok;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 struct jfs_log *log;
47};
48
49/* metapage flag */
50#define META_locked 0
Dave Kleikamp7fab4792005-05-02 12:25:02 -060051#define META_free 1
52#define META_dirty 2
53#define META_sync 3
54#define META_discard 4
55#define META_forcewrite 5
56#define META_io 6
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58#define mark_metapage_dirty(mp) set_bit(META_dirty, &(mp)->flag)
59
60/* function prototypes */
Dave Kleikamp1868f4a2005-05-04 15:29:35 -050061extern int metapage_init(void);
62extern void metapage_exit(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063extern struct metapage *__get_metapage(struct inode *inode,
64 unsigned long lblock, unsigned int size,
65 int absolute, unsigned long new);
66
67#define read_metapage(inode, lblock, size, absolute)\
68 __get_metapage(inode, lblock, size, absolute, FALSE)
69
70#define get_metapage(inode, lblock, size, absolute)\
71 __get_metapage(inode, lblock, size, absolute, TRUE)
72
73extern void release_metapage(struct metapage *);
Dave Kleikamp7fab4792005-05-02 12:25:02 -060074extern void grab_metapage(struct metapage *);
75extern void force_metapage(struct metapage *);
76
77/*
78 * hold_metapage and put_metapage are used in conjuction. The page lock
79 * is not dropped between the two, so no other threads can get or release
80 * the metapage
81 */
82extern void hold_metapage(struct metapage *);
83extern void put_metapage(struct metapage *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85static inline void write_metapage(struct metapage *mp)
86{
87 set_bit(META_dirty, &mp->flag);
88 release_metapage(mp);
89}
90
91static inline void flush_metapage(struct metapage *mp)
92{
93 set_bit(META_sync, &mp->flag);
94 write_metapage(mp);
95}
96
97static inline void discard_metapage(struct metapage *mp)
98{
99 clear_bit(META_dirty, &mp->flag);
100 set_bit(META_discard, &mp->flag);
101 release_metapage(mp);
102}
103
Dave Kleikamp7fab4792005-05-02 12:25:02 -0600104static inline void metapage_nohomeok(struct metapage *mp)
105{
106 struct page *page = mp->page;
107 lock_page(page);
108 if (!mp->nohomeok++) {
109 mark_metapage_dirty(mp);
110 page_cache_get(page);
111 wait_on_page_writeback(page);
112 }
113 unlock_page(page);
114}
115
116/*
117 * This serializes access to mp->lsn when metapages are added to logsynclist
118 * without setting nohomeok. i.e. updating imap & dmap
119 */
120static inline void metapage_wait_for_io(struct metapage *mp)
121{
122 if (test_bit(META_io, &mp->flag))
123 wait_on_page_writeback(mp->page);
124}
125
126/*
127 * This is called when already holding the metapage
128 */
129static inline void _metapage_homeok(struct metapage *mp)
130{
131 if (!--mp->nohomeok)
132 page_cache_release(mp->page);
133}
134
135static inline void metapage_homeok(struct metapage *mp)
136{
137 hold_metapage(mp);
138 _metapage_homeok(mp);
139 put_metapage(mp);
140}
141
Christoph Hellwigf5e54d62006-06-28 04:26:44 -0700142extern const struct address_space_operations jfs_metapage_aops;
Dave Kleikamp7fab4792005-05-02 12:25:02 -0600143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144/*
145 * This routines invalidate all pages for an extent.
146 */
147extern void __invalidate_metapages(struct inode *, s64, int);
148#define invalidate_pxd_metapages(ip, pxd) \
149 __invalidate_metapages((ip), addressPXD(&(pxd)), lengthPXD(&(pxd)))
150#define invalidate_dxd_metapages(ip, dxd) \
151 __invalidate_metapages((ip), addressDXD(&(dxd)), lengthDXD(&(dxd)))
152#define invalidate_xad_metapages(ip, xad) \
153 __invalidate_metapages((ip), addressXAD(&(xad)), lengthXAD(&(xad)))
154
155#endif /* _H_JFS_METAPAGE */