]>
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; | |
78 | struct xfs_buf_map *b_map; | |
79 | int b_nmaps; | |
80 | #ifdef XFS_BUF_TRACING | |
81 | struct list_head b_lock_list; | |
82 | const char *b_func; | |
83 | const char *b_file; | |
84 | int b_line; | |
85 | #endif | |
86 | } xfs_buf_t; | |
87 | ||
88 | enum xfs_buf_flags_t { /* b_flags bits */ | |
89 | LIBXFS_B_EXIT = 0x0001, /* ==LIBXFS_EXIT_ON_FAILURE */ | |
90 | LIBXFS_B_DIRTY = 0x0002, /* buffer has been modified */ | |
91 | LIBXFS_B_STALE = 0x0004, /* buffer marked as invalid */ | |
92 | LIBXFS_B_UPTODATE = 0x0008, /* buffer is sync'd to disk */ | |
93 | LIBXFS_B_DISCONTIG = 0x0010, /* discontiguous buffer */ | |
94 | LIBXFS_B_UNCHECKED = 0x0020, /* needs verification */ | |
95 | }; | |
96 | ||
97 | #define XFS_BUF_DADDR_NULL ((xfs_daddr_t) (-1LL)) | |
98 | ||
99 | #define XFS_BUF_PTR(bp) ((char *)(bp)->b_addr) | |
92acb899 | 100 | #define xfs_buf_offset(bp, offset) ((bp)->b_addr + (offset)) |
b626fb59 DC |
101 | #define XFS_BUF_ADDR(bp) ((bp)->b_bn) |
102 | #define XFS_BUF_SIZE(bp) ((bp)->b_bcount) | |
103 | #define XFS_BUF_COUNT(bp) ((bp)->b_bcount) | |
104 | #define XFS_BUF_TARGET(bp) ((bp)->b_dev) | |
105 | #define XFS_BUF_SET_PTR(bp,p,cnt) ({ \ | |
106 | (bp)->b_addr = (char *)(p); \ | |
107 | XFS_BUF_SET_COUNT(bp,cnt); \ | |
108 | }) | |
109 | ||
110 | #define XFS_BUF_SET_ADDR(bp,blk) ((bp)->b_bn = (blk)) | |
111 | #define XFS_BUF_SET_COUNT(bp,cnt) ((bp)->b_bcount = (cnt)) | |
112 | ||
113 | #define XFS_BUF_FSPRIVATE(bp,type) ((type)(bp)->b_fspriv) | |
114 | #define XFS_BUF_SET_FSPRIVATE(bp,val) (bp)->b_fspriv = (void *)(val) | |
115 | #define XFS_BUF_FSPRIVATE2(bp,type) ((type)(bp)->b_fsprivate2) | |
116 | #define XFS_BUF_SET_FSPRIVATE2(bp,val) (bp)->b_fsprivate2 = (void *)(val) | |
117 | #define XFS_BUF_FSPRIVATE3(bp,type) ((type)(bp)->b_fsprivate3) | |
118 | #define XFS_BUF_SET_FSPRIVATE3(bp,val) (bp)->b_fsprivate3 = (void *)(val) | |
119 | ||
120 | #define XFS_BUF_SET_PRIORITY(bp,pri) cache_node_set_priority( \ | |
121 | libxfs_bcache, \ | |
122 | (struct cache_node *)(bp), \ | |
123 | (pri)) | |
124 | #define XFS_BUF_PRIORITY(bp) (cache_node_get_priority( \ | |
125 | (struct cache_node *)(bp))) | |
126 | #define xfs_buf_set_ref(bp,ref) ((void) 0) | |
127 | #define xfs_buf_ioerror(bp,err) ((bp)->b_error = (err)) | |
128 | ||
129 | #define xfs_daddr_to_agno(mp,d) \ | |
130 | ((xfs_agnumber_t)(XFS_BB_TO_FSBT(mp, d) / (mp)->m_sb.sb_agblocks)) | |
131 | #define xfs_daddr_to_agbno(mp,d) \ | |
132 | ((xfs_agblock_t)(XFS_BB_TO_FSBT(mp, d) % (mp)->m_sb.sb_agblocks)) | |
133 | ||
134 | /* Buffer Cache Interfaces */ | |
135 | ||
136 | extern struct cache *libxfs_bcache; | |
137 | extern struct cache_operations libxfs_bcache_operations; | |
138 | ||
139 | #define LIBXFS_GETBUF_TRYLOCK (1 << 0) | |
140 | ||
141 | #ifdef XFS_BUF_TRACING | |
142 | ||
143 | #define libxfs_readbuf(dev, daddr, len, flags, ops) \ | |
144 | libxfs_trace_readbuf(__FUNCTION__, __FILE__, __LINE__, \ | |
145 | (dev), (daddr), (len), (flags), (ops)) | |
146 | #define libxfs_readbuf_map(dev, map, nmaps, flags, ops) \ | |
147 | libxfs_trace_readbuf_map(__FUNCTION__, __FILE__, __LINE__, \ | |
148 | (dev), (map), (nmaps), (flags), (ops)) | |
149 | #define libxfs_writebuf(buf, flags) \ | |
150 | libxfs_trace_writebuf(__FUNCTION__, __FILE__, __LINE__, \ | |
151 | (buf), (flags)) | |
152 | #define libxfs_getbuf(dev, daddr, len) \ | |
153 | libxfs_trace_getbuf(__FUNCTION__, __FILE__, __LINE__, \ | |
154 | (dev), (daddr), (len)) | |
155 | #define libxfs_getbuf_map(dev, map, nmaps, flags) \ | |
156 | libxfs_trace_getbuf_map(__FUNCTION__, __FILE__, __LINE__, \ | |
157 | (dev), (map), (nmaps), (flags)) | |
158 | #define libxfs_getbuf_flags(dev, daddr, len, flags) \ | |
159 | libxfs_trace_getbuf_flags(__FUNCTION__, __FILE__, __LINE__, \ | |
160 | (dev), (daddr), (len), (flags)) | |
161 | #define libxfs_putbuf(buf) \ | |
162 | libxfs_trace_putbuf(__FUNCTION__, __FILE__, __LINE__, (buf)) | |
163 | ||
164 | extern xfs_buf_t *libxfs_trace_readbuf(const char *, const char *, int, | |
165 | struct xfs_buftarg *, xfs_daddr_t, int, int, | |
166 | const struct xfs_buf_ops *); | |
167 | extern xfs_buf_t *libxfs_trace_readbuf_map(const char *, const char *, int, | |
168 | struct xfs_buftarg *, struct xfs_buf_map *, int, int, | |
169 | const struct xfs_buf_ops *); | |
170 | extern int libxfs_trace_writebuf(const char *, const char *, int, | |
171 | xfs_buf_t *, int); | |
172 | extern xfs_buf_t *libxfs_trace_getbuf(const char *, const char *, int, | |
173 | struct xfs_buftarg *, xfs_daddr_t, int); | |
174 | extern xfs_buf_t *libxfs_trace_getbuf_map(const char *, const char *, int, | |
175 | struct xfs_buftarg *, struct xfs_buf_map *, int, int); | |
176 | extern xfs_buf_t *libxfs_trace_getbuf_flags(const char *, const char *, int, | |
177 | struct xfs_buftarg *, xfs_daddr_t, int, unsigned int); | |
178 | extern void libxfs_trace_putbuf (const char *, const char *, int, | |
179 | xfs_buf_t *); | |
180 | ||
181 | #else | |
182 | ||
183 | extern xfs_buf_t *libxfs_readbuf(struct xfs_buftarg *, xfs_daddr_t, int, int, | |
184 | const struct xfs_buf_ops *); | |
185 | extern xfs_buf_t *libxfs_readbuf_map(struct xfs_buftarg *, struct xfs_buf_map *, | |
186 | int, int, const struct xfs_buf_ops *); | |
187 | extern int libxfs_writebuf(xfs_buf_t *, int); | |
188 | extern xfs_buf_t *libxfs_getbuf(struct xfs_buftarg *, xfs_daddr_t, int); | |
189 | extern xfs_buf_t *libxfs_getbuf_map(struct xfs_buftarg *, | |
190 | struct xfs_buf_map *, int, int); | |
191 | extern xfs_buf_t *libxfs_getbuf_flags(struct xfs_buftarg *, xfs_daddr_t, | |
192 | int, unsigned int); | |
193 | extern void libxfs_putbuf (xfs_buf_t *); | |
194 | ||
195 | #endif | |
196 | ||
197 | extern void libxfs_readbuf_verify(struct xfs_buf *bp, | |
198 | const struct xfs_buf_ops *ops); | |
199 | extern xfs_buf_t *libxfs_getsb(struct xfs_mount *, int); | |
200 | extern void libxfs_bcache_purge(void); | |
201 | extern void libxfs_bcache_flush(void); | |
202 | extern void libxfs_purgebuf(xfs_buf_t *); | |
203 | extern int libxfs_bcache_overflowed(void); | |
204 | extern int libxfs_bcache_usage(void); | |
205 | ||
206 | /* Buffer (Raw) Interfaces */ | |
207 | extern xfs_buf_t *libxfs_getbufr(struct xfs_buftarg *, xfs_daddr_t, int); | |
208 | extern void libxfs_putbufr(xfs_buf_t *); | |
209 | ||
210 | extern int libxfs_writebuf_int(xfs_buf_t *, int); | |
211 | extern int libxfs_writebufr(struct xfs_buf *); | |
212 | extern int libxfs_readbufr(struct xfs_buftarg *, xfs_daddr_t, xfs_buf_t *, int, int); | |
213 | extern int libxfs_readbufr_map(struct xfs_buftarg *, struct xfs_buf *, int); | |
214 | ||
9542ae13 DC |
215 | extern int libxfs_device_zero(struct xfs_buftarg *, xfs_daddr_t, uint); |
216 | ||
b626fb59 DC |
217 | extern int libxfs_bhash_size; |
218 | ||
219 | #define LIBXFS_BREAD 0x1 | |
220 | #define LIBXFS_BWRITE 0x2 | |
221 | #define LIBXFS_BZERO 0x4 | |
222 | ||
223 | extern void libxfs_iomove (xfs_buf_t *, uint, int, void *, int); | |
224 | ||
225 | static inline int | |
226 | xfs_buf_verify_cksum(struct xfs_buf *bp, unsigned long cksum_offset) | |
227 | { | |
228 | return xfs_verify_cksum(bp->b_addr, BBTOB(bp->b_length), | |
229 | cksum_offset); | |
230 | } | |
231 | ||
232 | static inline void | |
233 | xfs_buf_update_cksum(struct xfs_buf *bp, unsigned long cksum_offset) | |
234 | { | |
235 | xfs_update_cksum(bp->b_addr, BBTOB(bp->b_length), | |
236 | cksum_offset); | |
237 | } | |
238 | ||
239 | #endif /* __LIBXFS_IO_H__ */ |