]>
Commit | Line | Data |
---|---|---|
b626fb59 DC |
1 | /* |
2 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. | |
3 | * All Rights Reserved. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or | |
6 | * modify it under the terms of the GNU General Public License as | |
7 | * published by the Free Software Foundation. | |
8 | * | |
9 | * This program is distributed in the hope that it would be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program; if not, write the Free Software Foundation, | |
16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
17 | */ | |
18 | ||
19 | #ifndef __LIBXFS_IO_H_ | |
20 | #define __LIBXFS_IO_H_ | |
21 | ||
22 | /* | |
23 | * Kernel equivalent buffer based I/O interface | |
24 | */ | |
25 | ||
26 | struct xfs_buf; | |
27 | struct xfs_mount; | |
28 | struct xfs_perag; | |
29 | ||
30 | /* | |
31 | * IO verifier callbacks need the xfs_mount pointer, so we have to behave | |
32 | * somewhat like the kernel now for userspace IO in terms of having buftarg | |
33 | * based devices... | |
34 | */ | |
35 | struct xfs_buftarg { | |
36 | struct xfs_mount *bt_mount; | |
37 | dev_t dev; | |
38 | }; | |
39 | ||
40 | extern void libxfs_buftarg_init(struct xfs_mount *mp, dev_t ddev, | |
41 | dev_t logdev, dev_t rtdev); | |
42 | ||
43 | #define LIBXFS_BBTOOFF64(bbs) (((xfs_off_t)(bbs)) << BBSHIFT) | |
44 | ||
45 | #define XB_PAGES 2 | |
46 | struct xfs_buf_map { | |
47 | xfs_daddr_t bm_bn; /* block number for I/O */ | |
48 | int bm_len; /* size of I/O */ | |
49 | }; | |
50 | ||
51 | #define DEFINE_SINGLE_BUF_MAP(map, blkno, numblk) \ | |
52 | struct xfs_buf_map (map) = { .bm_bn = (blkno), .bm_len = (numblk) }; | |
53 | ||
54 | struct xfs_buf_ops { | |
a3fac935 | 55 | char *name; |
b626fb59 DC |
56 | void (*verify_read)(struct xfs_buf *); |
57 | void (*verify_write)(struct xfs_buf *); | |
58 | }; | |
59 | ||
60 | typedef struct xfs_buf { | |
61 | struct cache_node b_node; | |
62 | unsigned int b_flags; | |
63 | xfs_daddr_t b_bn; | |
64 | unsigned b_bcount; | |
65 | unsigned int b_length; | |
66 | struct xfs_buftarg *b_target; | |
67 | #define b_dev b_target->dev | |
68 | pthread_mutex_t b_lock; | |
69 | pthread_t b_holder; | |
70 | unsigned int b_recur; | |
71 | void *b_fspriv; | |
72 | void *b_fsprivate2; | |
73 | void *b_fsprivate3; | |
74 | void *b_addr; | |
75 | int b_error; | |
76 | const struct xfs_buf_ops *b_ops; | |
77 | struct xfs_perag *b_pag; | |
85428dd2 | 78 | struct xfs_buf_map *b_maps; |
2c6c6328 | 79 | struct xfs_buf_map __b_map; |
b626fb59 DC |
80 | int b_nmaps; |
81 | #ifdef XFS_BUF_TRACING | |
82 | struct list_head b_lock_list; | |
83 | const char *b_func; | |
84 | const char *b_file; | |
85 | int b_line; | |
86 | #endif | |
87 | } xfs_buf_t; | |
88 | ||
89 | enum xfs_buf_flags_t { /* b_flags bits */ | |
90 | LIBXFS_B_EXIT = 0x0001, /* ==LIBXFS_EXIT_ON_FAILURE */ | |
91 | LIBXFS_B_DIRTY = 0x0002, /* buffer has been modified */ | |
92 | LIBXFS_B_STALE = 0x0004, /* buffer marked as invalid */ | |
93 | LIBXFS_B_UPTODATE = 0x0008, /* buffer is sync'd to disk */ | |
94 | LIBXFS_B_DISCONTIG = 0x0010, /* discontiguous buffer */ | |
95 | LIBXFS_B_UNCHECKED = 0x0020, /* needs verification */ | |
96 | }; | |
97 | ||
98 | #define XFS_BUF_DADDR_NULL ((xfs_daddr_t) (-1LL)) | |
99 | ||
100 | #define XFS_BUF_PTR(bp) ((char *)(bp)->b_addr) | |
92acb899 | 101 | #define xfs_buf_offset(bp, offset) ((bp)->b_addr + (offset)) |
b626fb59 DC |
102 | #define XFS_BUF_ADDR(bp) ((bp)->b_bn) |
103 | #define XFS_BUF_SIZE(bp) ((bp)->b_bcount) | |
104 | #define XFS_BUF_COUNT(bp) ((bp)->b_bcount) | |
105 | #define XFS_BUF_TARGET(bp) ((bp)->b_dev) | |
106 | #define XFS_BUF_SET_PTR(bp,p,cnt) ({ \ | |
107 | (bp)->b_addr = (char *)(p); \ | |
108 | XFS_BUF_SET_COUNT(bp,cnt); \ | |
109 | }) | |
110 | ||
111 | #define XFS_BUF_SET_ADDR(bp,blk) ((bp)->b_bn = (blk)) | |
112 | #define XFS_BUF_SET_COUNT(bp,cnt) ((bp)->b_bcount = (cnt)) | |
113 | ||
b626fb59 DC |
114 | #define XFS_BUF_FSPRIVATE2(bp,type) ((type)(bp)->b_fsprivate2) |
115 | #define XFS_BUF_SET_FSPRIVATE2(bp,val) (bp)->b_fsprivate2 = (void *)(val) | |
116 | #define XFS_BUF_FSPRIVATE3(bp,type) ((type)(bp)->b_fsprivate3) | |
117 | #define XFS_BUF_SET_FSPRIVATE3(bp,val) (bp)->b_fsprivate3 = (void *)(val) | |
118 | ||
119 | #define XFS_BUF_SET_PRIORITY(bp,pri) cache_node_set_priority( \ | |
120 | libxfs_bcache, \ | |
121 | (struct cache_node *)(bp), \ | |
122 | (pri)) | |
123 | #define XFS_BUF_PRIORITY(bp) (cache_node_get_priority( \ | |
124 | (struct cache_node *)(bp))) | |
125 | #define xfs_buf_set_ref(bp,ref) ((void) 0) | |
126 | #define xfs_buf_ioerror(bp,err) ((bp)->b_error = (err)) | |
127 | ||
128 | #define xfs_daddr_to_agno(mp,d) \ | |
129 | ((xfs_agnumber_t)(XFS_BB_TO_FSBT(mp, d) / (mp)->m_sb.sb_agblocks)) | |
130 | #define xfs_daddr_to_agbno(mp,d) \ | |
131 | ((xfs_agblock_t)(XFS_BB_TO_FSBT(mp, d) % (mp)->m_sb.sb_agblocks)) | |
132 | ||
133 | /* Buffer Cache Interfaces */ | |
134 | ||
135 | extern struct cache *libxfs_bcache; | |
136 | extern struct cache_operations libxfs_bcache_operations; | |
137 | ||
138 | #define LIBXFS_GETBUF_TRYLOCK (1 << 0) | |
139 | ||
140 | #ifdef XFS_BUF_TRACING | |
141 | ||
142 | #define libxfs_readbuf(dev, daddr, len, flags, ops) \ | |
143 | libxfs_trace_readbuf(__FUNCTION__, __FILE__, __LINE__, \ | |
144 | (dev), (daddr), (len), (flags), (ops)) | |
145 | #define libxfs_readbuf_map(dev, map, nmaps, flags, ops) \ | |
146 | libxfs_trace_readbuf_map(__FUNCTION__, __FILE__, __LINE__, \ | |
147 | (dev), (map), (nmaps), (flags), (ops)) | |
148 | #define libxfs_writebuf(buf, flags) \ | |
149 | libxfs_trace_writebuf(__FUNCTION__, __FILE__, __LINE__, \ | |
150 | (buf), (flags)) | |
151 | #define libxfs_getbuf(dev, daddr, len) \ | |
152 | libxfs_trace_getbuf(__FUNCTION__, __FILE__, __LINE__, \ | |
153 | (dev), (daddr), (len)) | |
154 | #define libxfs_getbuf_map(dev, map, nmaps, flags) \ | |
155 | libxfs_trace_getbuf_map(__FUNCTION__, __FILE__, __LINE__, \ | |
156 | (dev), (map), (nmaps), (flags)) | |
157 | #define libxfs_getbuf_flags(dev, daddr, len, flags) \ | |
158 | libxfs_trace_getbuf_flags(__FUNCTION__, __FILE__, __LINE__, \ | |
159 | (dev), (daddr), (len), (flags)) | |
160 | #define libxfs_putbuf(buf) \ | |
161 | libxfs_trace_putbuf(__FUNCTION__, __FILE__, __LINE__, (buf)) | |
162 | ||
163 | extern xfs_buf_t *libxfs_trace_readbuf(const char *, const char *, int, | |
164 | struct xfs_buftarg *, xfs_daddr_t, int, int, | |
165 | const struct xfs_buf_ops *); | |
166 | extern xfs_buf_t *libxfs_trace_readbuf_map(const char *, const char *, int, | |
167 | struct xfs_buftarg *, struct xfs_buf_map *, int, int, | |
168 | const struct xfs_buf_ops *); | |
169 | extern int libxfs_trace_writebuf(const char *, const char *, int, | |
170 | xfs_buf_t *, int); | |
171 | extern xfs_buf_t *libxfs_trace_getbuf(const char *, const char *, int, | |
172 | struct xfs_buftarg *, xfs_daddr_t, int); | |
173 | extern xfs_buf_t *libxfs_trace_getbuf_map(const char *, const char *, int, | |
174 | struct xfs_buftarg *, struct xfs_buf_map *, int, int); | |
175 | extern xfs_buf_t *libxfs_trace_getbuf_flags(const char *, const char *, int, | |
176 | struct xfs_buftarg *, xfs_daddr_t, int, unsigned int); | |
177 | extern void libxfs_trace_putbuf (const char *, const char *, int, | |
178 | xfs_buf_t *); | |
179 | ||
180 | #else | |
181 | ||
182 | extern xfs_buf_t *libxfs_readbuf(struct xfs_buftarg *, xfs_daddr_t, int, int, | |
183 | const struct xfs_buf_ops *); | |
184 | extern xfs_buf_t *libxfs_readbuf_map(struct xfs_buftarg *, struct xfs_buf_map *, | |
185 | int, int, const struct xfs_buf_ops *); | |
186 | extern int libxfs_writebuf(xfs_buf_t *, int); | |
187 | extern xfs_buf_t *libxfs_getbuf(struct xfs_buftarg *, xfs_daddr_t, int); | |
188 | extern xfs_buf_t *libxfs_getbuf_map(struct xfs_buftarg *, | |
189 | struct xfs_buf_map *, int, int); | |
190 | extern xfs_buf_t *libxfs_getbuf_flags(struct xfs_buftarg *, xfs_daddr_t, | |
191 | int, unsigned int); | |
192 | extern void libxfs_putbuf (xfs_buf_t *); | |
193 | ||
194 | #endif | |
195 | ||
196 | extern void libxfs_readbuf_verify(struct xfs_buf *bp, | |
197 | const struct xfs_buf_ops *ops); | |
198 | extern xfs_buf_t *libxfs_getsb(struct xfs_mount *, int); | |
199 | extern void libxfs_bcache_purge(void); | |
200 | extern void libxfs_bcache_flush(void); | |
201 | extern void libxfs_purgebuf(xfs_buf_t *); | |
202 | extern int libxfs_bcache_overflowed(void); | |
203 | extern int libxfs_bcache_usage(void); | |
204 | ||
205 | /* Buffer (Raw) Interfaces */ | |
206 | extern xfs_buf_t *libxfs_getbufr(struct xfs_buftarg *, xfs_daddr_t, int); | |
207 | extern void libxfs_putbufr(xfs_buf_t *); | |
208 | ||
209 | extern int libxfs_writebuf_int(xfs_buf_t *, int); | |
210 | extern int libxfs_writebufr(struct xfs_buf *); | |
211 | extern int libxfs_readbufr(struct xfs_buftarg *, xfs_daddr_t, xfs_buf_t *, int, int); | |
212 | extern int libxfs_readbufr_map(struct xfs_buftarg *, struct xfs_buf *, int); | |
213 | ||
9542ae13 DC |
214 | extern int libxfs_device_zero(struct xfs_buftarg *, xfs_daddr_t, uint); |
215 | ||
b626fb59 DC |
216 | extern int libxfs_bhash_size; |
217 | ||
218 | #define LIBXFS_BREAD 0x1 | |
219 | #define LIBXFS_BWRITE 0x2 | |
220 | #define LIBXFS_BZERO 0x4 | |
221 | ||
222 | extern void libxfs_iomove (xfs_buf_t *, uint, int, void *, int); | |
223 | ||
224 | static inline int | |
225 | xfs_buf_verify_cksum(struct xfs_buf *bp, unsigned long cksum_offset) | |
226 | { | |
227 | return xfs_verify_cksum(bp->b_addr, BBTOB(bp->b_length), | |
228 | cksum_offset); | |
229 | } | |
230 | ||
231 | static inline void | |
232 | xfs_buf_update_cksum(struct xfs_buf *bp, unsigned long cksum_offset) | |
233 | { | |
234 | xfs_update_cksum(bp->b_addr, BBTOB(bp->b_length), | |
235 | cksum_offset); | |
236 | } | |
237 | ||
238 | #endif /* __LIBXFS_IO_H__ */ |