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