blob: 4179f9df4deb62ebe921ca4aad753f95a906600f [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Dave Kleikamp1868f4a2005-05-04 15:29:35 -05003 * Copyright (C) International Business Machines Corp., 2000-2002
4 * Portions Copyright (C) Christoph Hellwig, 2001-2002
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6#ifndef _H_JFS_METAPAGE
7#define _H_JFS_METAPAGE
8
9#include <linux/pagemap.h>
10
11struct metapage {
12 /* Common logsyncblk prefix (see jfs_logmgr.h) */
13 u16 xflag;
14 u16 unused;
15 lid_t lid;
16 int lsn;
17 struct list_head synclist;
18 /* End of logsyncblk prefix */
19
20 unsigned long flag; /* See Below */
21 unsigned long count; /* Reference count */
22 void *data; /* Data pointer */
Dave Kleikamp63f83c92006-10-02 09:55:27 -050023 sector_t index; /* block address of page */
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 wait_queue_head_t wait;
25
26 /* implementation */
27 struct page *page;
Dave Kleikamp11ab8312017-07-05 15:26:49 -040028 struct super_block *sb;
Dave Kleikamp7fab4792005-05-02 12:25:02 -060029 unsigned int logical_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31 /* Journal management */
32 int clsn;
Dave Kleikamp7fab4792005-05-02 12:25:02 -060033 int nohomeok;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 struct jfs_log *log;
35};
36
37/* metapage flag */
38#define META_locked 0
Dave Kleikamp7fab4792005-05-02 12:25:02 -060039#define META_dirty 2
40#define META_sync 3
41#define META_discard 4
42#define META_forcewrite 5
43#define META_io 6
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45#define mark_metapage_dirty(mp) set_bit(META_dirty, &(mp)->flag)
46
47/* function prototypes */
Dave Kleikamp1868f4a2005-05-04 15:29:35 -050048extern int metapage_init(void);
49extern void metapage_exit(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050extern struct metapage *__get_metapage(struct inode *inode,
51 unsigned long lblock, unsigned int size,
52 int absolute, unsigned long new);
53
54#define read_metapage(inode, lblock, size, absolute)\
Richard Knutsson4d817152006-09-30 23:27:14 -070055 __get_metapage(inode, lblock, size, absolute, false)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57#define get_metapage(inode, lblock, size, absolute)\
Richard Knutsson4d817152006-09-30 23:27:14 -070058 __get_metapage(inode, lblock, size, absolute, true)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60extern void release_metapage(struct metapage *);
Dave Kleikamp7fab4792005-05-02 12:25:02 -060061extern void grab_metapage(struct metapage *);
62extern void force_metapage(struct metapage *);
63
64/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -030065 * hold_metapage and put_metapage are used in conjunction. The page lock
Dave Kleikamp7fab4792005-05-02 12:25:02 -060066 * is not dropped between the two, so no other threads can get or release
67 * the metapage
68 */
69extern void hold_metapage(struct metapage *);
70extern void put_metapage(struct metapage *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72static inline void write_metapage(struct metapage *mp)
73{
74 set_bit(META_dirty, &mp->flag);
75 release_metapage(mp);
76}
77
78static inline void flush_metapage(struct metapage *mp)
79{
80 set_bit(META_sync, &mp->flag);
81 write_metapage(mp);
82}
83
84static inline void discard_metapage(struct metapage *mp)
85{
86 clear_bit(META_dirty, &mp->flag);
87 set_bit(META_discard, &mp->flag);
88 release_metapage(mp);
89}
90
Dave Kleikamp7fab4792005-05-02 12:25:02 -060091static inline void metapage_nohomeok(struct metapage *mp)
92{
93 struct page *page = mp->page;
94 lock_page(page);
95 if (!mp->nohomeok++) {
96 mark_metapage_dirty(mp);
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +030097 get_page(page);
Dave Kleikamp7fab4792005-05-02 12:25:02 -060098 wait_on_page_writeback(page);
99 }
100 unlock_page(page);
101}
102
103/*
104 * This serializes access to mp->lsn when metapages are added to logsynclist
105 * without setting nohomeok. i.e. updating imap & dmap
106 */
107static inline void metapage_wait_for_io(struct metapage *mp)
108{
109 if (test_bit(META_io, &mp->flag))
110 wait_on_page_writeback(mp->page);
111}
112
113/*
114 * This is called when already holding the metapage
115 */
116static inline void _metapage_homeok(struct metapage *mp)
117{
118 if (!--mp->nohomeok)
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300119 put_page(mp->page);
Dave Kleikamp7fab4792005-05-02 12:25:02 -0600120}
121
122static inline void metapage_homeok(struct metapage *mp)
123{
124 hold_metapage(mp);
125 _metapage_homeok(mp);
126 put_metapage(mp);
127}
128
Christoph Hellwigf5e54d62006-06-28 04:26:44 -0700129extern const struct address_space_operations jfs_metapage_aops;
Dave Kleikamp7fab4792005-05-02 12:25:02 -0600130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131/*
132 * This routines invalidate all pages for an extent.
133 */
134extern void __invalidate_metapages(struct inode *, s64, int);
135#define invalidate_pxd_metapages(ip, pxd) \
136 __invalidate_metapages((ip), addressPXD(&(pxd)), lengthPXD(&(pxd)))
137#define invalidate_dxd_metapages(ip, dxd) \
138 __invalidate_metapages((ip), addressDXD(&(dxd)), lengthDXD(&(dxd)))
139#define invalidate_xad_metapages(ip, xad) \
140 __invalidate_metapages((ip), addressXAD(&(xad)), lengthXAD(&(xad)))
141
142#endif /* _H_JFS_METAPAGE */