]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify it | |
5 | * under the terms of version 2 of the GNU General Public License as | |
6 | * published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope that it would be useful, but | |
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
11 | * | |
12 | * Further, this software is distributed without any warranty that it is | |
13 | * free of the rightful claim of any third person regarding infringement | |
14 | * or the like. Any license provided herein, whether implied or | |
15 | * otherwise, applies only to this software file. Patent licenses, if | |
16 | * any, provided herein do not apply to combinations of this program with | |
17 | * other software, or any other product whatsoever. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License along | |
20 | * with this program; if not, write the Free Software Foundation, Inc., 59 | |
21 | * Temple Place - Suite 330, Boston MA 02111-1307, USA. | |
22 | * | |
23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, | |
24 | * Mountain View, CA 94043, or: | |
25 | * | |
26 | * http://www.sgi.com | |
27 | * | |
28 | * For further information regarding this notice, see: | |
29 | * | |
30 | * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ | |
31 | */ | |
32 | ||
33 | /* | |
34 | * Written by Steve Lord, Jim Mostek, Russell Cattelan at SGI | |
35 | */ | |
36 | ||
37 | #ifndef __XFS_BUF_H__ | |
38 | #define __XFS_BUF_H__ | |
39 | ||
40 | #include <linux/config.h> | |
41 | #include <linux/list.h> | |
42 | #include <linux/types.h> | |
43 | #include <linux/spinlock.h> | |
44 | #include <asm/system.h> | |
45 | #include <linux/mm.h> | |
46 | #include <linux/fs.h> | |
47 | #include <linux/buffer_head.h> | |
48 | #include <linux/uio.h> | |
49 | ||
50 | /* | |
51 | * Base types | |
52 | */ | |
53 | ||
54 | #define XFS_BUF_DADDR_NULL ((xfs_daddr_t) (-1LL)) | |
55 | ||
56 | #define page_buf_ctob(pp) ((pp) * PAGE_CACHE_SIZE) | |
57 | #define page_buf_btoc(dd) (((dd) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT) | |
58 | #define page_buf_btoct(dd) ((dd) >> PAGE_CACHE_SHIFT) | |
59 | #define page_buf_poff(aa) ((aa) & ~PAGE_CACHE_MASK) | |
60 | ||
61 | typedef enum page_buf_rw_e { | |
62 | PBRW_READ = 1, /* transfer into target memory */ | |
63 | PBRW_WRITE = 2, /* transfer from target memory */ | |
64 | PBRW_ZERO = 3 /* Zero target memory */ | |
65 | } page_buf_rw_t; | |
66 | ||
67 | ||
68 | typedef enum page_buf_flags_e { /* pb_flags values */ | |
69 | PBF_READ = (1 << 0), /* buffer intended for reading from device */ | |
70 | PBF_WRITE = (1 << 1), /* buffer intended for writing to device */ | |
71 | PBF_MAPPED = (1 << 2), /* buffer mapped (pb_addr valid) */ | |
1da177e4 | 72 | PBF_ASYNC = (1 << 4), /* initiator will not wait for completion */ |
c86e711c | 73 | PBF_DONE = (1 << 5), /* all pages in the buffer uptodate */ |
1da177e4 LT |
74 | PBF_DELWRI = (1 << 6), /* buffer has dirty pages */ |
75 | PBF_STALE = (1 << 7), /* buffer has been staled, do not find it */ | |
76 | PBF_FS_MANAGED = (1 << 8), /* filesystem controls freeing memory */ | |
f538d4da | 77 | PBF_ORDERED = (1 << 11), /* use ordered writes */ |
1da177e4 LT |
78 | PBF_READ_AHEAD = (1 << 12), /* asynchronous read-ahead */ |
79 | ||
80 | /* flags used only as arguments to access routines */ | |
81 | PBF_LOCK = (1 << 14), /* lock requested */ | |
82 | PBF_TRYLOCK = (1 << 15), /* lock requested, but do not wait */ | |
83 | PBF_DONT_BLOCK = (1 << 16), /* do not block in current thread */ | |
84 | ||
85 | /* flags used only internally */ | |
86 | _PBF_PAGE_CACHE = (1 << 17),/* backed by pagecache */ | |
87 | _PBF_KMEM_ALLOC = (1 << 18),/* backed by kmem_alloc() */ | |
88 | _PBF_RUN_QUEUES = (1 << 19),/* run block device task queue */ | |
2f926587 | 89 | _PBF_DELWRI_Q = (1 << 21), /* buffer on delwri queue */ |
1da177e4 LT |
90 | } page_buf_flags_t; |
91 | ||
1da177e4 LT |
92 | |
93 | typedef struct xfs_bufhash { | |
94 | struct list_head bh_list; | |
95 | spinlock_t bh_lock; | |
96 | } xfs_bufhash_t; | |
97 | ||
98 | typedef struct xfs_buftarg { | |
99 | dev_t pbr_dev; | |
100 | struct block_device *pbr_bdev; | |
101 | struct address_space *pbr_mapping; | |
102 | unsigned int pbr_bsize; | |
103 | unsigned int pbr_sshift; | |
104 | size_t pbr_smask; | |
105 | ||
106 | /* per-device buffer hash table */ | |
107 | uint bt_hashmask; | |
108 | uint bt_hashshift; | |
109 | xfs_bufhash_t *bt_hash; | |
110 | } xfs_buftarg_t; | |
111 | ||
112 | /* | |
113 | * xfs_buf_t: Buffer structure for page cache-based buffers | |
114 | * | |
115 | * This buffer structure is used by the page cache buffer management routines | |
116 | * to refer to an assembly of pages forming a logical buffer. The actual I/O | |
117 | * is performed with buffer_head structures, as required by drivers. | |
118 | * | |
119 | * The buffer structure is used on temporary basis only, and discarded when | |
120 | * released. The real data storage is recorded in the page cache. Metadata is | |
121 | * hashed to the block device on which the file system resides. | |
122 | */ | |
123 | ||
124 | struct xfs_buf; | |
125 | ||
126 | /* call-back function on I/O completion */ | |
127 | typedef void (*page_buf_iodone_t)(struct xfs_buf *); | |
128 | /* call-back function on I/O completion */ | |
129 | typedef void (*page_buf_relse_t)(struct xfs_buf *); | |
130 | /* pre-write function */ | |
131 | typedef int (*page_buf_bdstrat_t)(struct xfs_buf *); | |
132 | ||
133 | #define PB_PAGES 2 | |
134 | ||
135 | typedef struct xfs_buf { | |
136 | struct semaphore pb_sema; /* semaphore for lockables */ | |
137 | unsigned long pb_queuetime; /* time buffer was queued */ | |
138 | atomic_t pb_pin_count; /* pin count */ | |
139 | wait_queue_head_t pb_waiters; /* unpin waiters */ | |
140 | struct list_head pb_list; | |
141 | page_buf_flags_t pb_flags; /* status flags */ | |
142 | struct list_head pb_hash_list; /* hash table list */ | |
143 | xfs_bufhash_t *pb_hash; /* hash table list start */ | |
144 | xfs_buftarg_t *pb_target; /* buffer target (device) */ | |
145 | atomic_t pb_hold; /* reference count */ | |
146 | xfs_daddr_t pb_bn; /* block number for I/O */ | |
147 | loff_t pb_file_offset; /* offset in file */ | |
148 | size_t pb_buffer_length; /* size of buffer in bytes */ | |
149 | size_t pb_count_desired; /* desired transfer size */ | |
150 | void *pb_addr; /* virtual address of buffer */ | |
151 | struct work_struct pb_iodone_work; | |
152 | atomic_t pb_io_remaining;/* #outstanding I/O requests */ | |
153 | page_buf_iodone_t pb_iodone; /* I/O completion function */ | |
154 | page_buf_relse_t pb_relse; /* releasing function */ | |
155 | page_buf_bdstrat_t pb_strat; /* pre-write function */ | |
156 | struct semaphore pb_iodonesema; /* Semaphore for I/O waiters */ | |
157 | void *pb_fspriv; | |
158 | void *pb_fspriv2; | |
159 | void *pb_fspriv3; | |
160 | unsigned short pb_error; /* error code on I/O */ | |
161 | unsigned short pb_locked; /* page array is locked */ | |
162 | unsigned int pb_page_count; /* size of page array */ | |
163 | unsigned int pb_offset; /* page offset in first page */ | |
164 | struct page **pb_pages; /* array of page pointers */ | |
165 | struct page *pb_page_array[PB_PAGES]; /* inline pages */ | |
166 | #ifdef PAGEBUF_LOCK_TRACKING | |
167 | int pb_last_holder; | |
168 | #endif | |
169 | } xfs_buf_t; | |
170 | ||
171 | ||
172 | /* Finding and Reading Buffers */ | |
173 | ||
174 | extern xfs_buf_t *_pagebuf_find( /* find buffer for block if */ | |
175 | /* the block is in memory */ | |
176 | xfs_buftarg_t *, /* inode for block */ | |
177 | loff_t, /* starting offset of range */ | |
178 | size_t, /* length of range */ | |
179 | page_buf_flags_t, /* PBF_LOCK */ | |
180 | xfs_buf_t *); /* newly allocated buffer */ | |
181 | ||
182 | #define xfs_incore(buftarg,blkno,len,lockit) \ | |
183 | _pagebuf_find(buftarg, blkno ,len, lockit, NULL) | |
184 | ||
185 | extern xfs_buf_t *xfs_buf_get_flags( /* allocate a buffer */ | |
186 | xfs_buftarg_t *, /* inode for buffer */ | |
187 | loff_t, /* starting offset of range */ | |
188 | size_t, /* length of range */ | |
189 | page_buf_flags_t); /* PBF_LOCK, PBF_READ, */ | |
190 | /* PBF_ASYNC */ | |
191 | ||
192 | #define xfs_buf_get(target, blkno, len, flags) \ | |
193 | xfs_buf_get_flags((target), (blkno), (len), PBF_LOCK | PBF_MAPPED) | |
194 | ||
195 | extern xfs_buf_t *xfs_buf_read_flags( /* allocate and read a buffer */ | |
196 | xfs_buftarg_t *, /* inode for buffer */ | |
197 | loff_t, /* starting offset of range */ | |
198 | size_t, /* length of range */ | |
199 | page_buf_flags_t); /* PBF_LOCK, PBF_ASYNC */ | |
200 | ||
201 | #define xfs_buf_read(target, blkno, len, flags) \ | |
202 | xfs_buf_read_flags((target), (blkno), (len), PBF_LOCK | PBF_MAPPED) | |
203 | ||
1da177e4 LT |
204 | extern xfs_buf_t *pagebuf_get_empty( /* allocate pagebuf struct with */ |
205 | /* no memory or disk address */ | |
206 | size_t len, | |
207 | xfs_buftarg_t *); /* mount point "fake" inode */ | |
208 | ||
209 | extern xfs_buf_t *pagebuf_get_no_daddr(/* allocate pagebuf struct */ | |
210 | /* without disk address */ | |
211 | size_t len, | |
212 | xfs_buftarg_t *); /* mount point "fake" inode */ | |
213 | ||
214 | extern int pagebuf_associate_memory( | |
215 | xfs_buf_t *, | |
216 | void *, | |
217 | size_t); | |
218 | ||
219 | extern void pagebuf_hold( /* increment reference count */ | |
220 | xfs_buf_t *); /* buffer to hold */ | |
221 | ||
222 | extern void pagebuf_readahead( /* read ahead into cache */ | |
223 | xfs_buftarg_t *, /* target for buffer (or NULL) */ | |
224 | loff_t, /* starting offset of range */ | |
225 | size_t, /* length of range */ | |
226 | page_buf_flags_t); /* additional read flags */ | |
227 | ||
228 | /* Releasing Buffers */ | |
229 | ||
230 | extern void pagebuf_free( /* deallocate a buffer */ | |
231 | xfs_buf_t *); /* buffer to deallocate */ | |
232 | ||
233 | extern void pagebuf_rele( /* release hold on a buffer */ | |
234 | xfs_buf_t *); /* buffer to release */ | |
235 | ||
236 | /* Locking and Unlocking Buffers */ | |
237 | ||
238 | extern int pagebuf_cond_lock( /* lock buffer, if not locked */ | |
239 | /* (returns -EBUSY if locked) */ | |
240 | xfs_buf_t *); /* buffer to lock */ | |
241 | ||
242 | extern int pagebuf_lock_value( /* return count on lock */ | |
243 | xfs_buf_t *); /* buffer to check */ | |
244 | ||
245 | extern int pagebuf_lock( /* lock buffer */ | |
246 | xfs_buf_t *); /* buffer to lock */ | |
247 | ||
248 | extern void pagebuf_unlock( /* unlock buffer */ | |
249 | xfs_buf_t *); /* buffer to unlock */ | |
250 | ||
251 | /* Buffer Read and Write Routines */ | |
252 | ||
253 | extern void pagebuf_iodone( /* mark buffer I/O complete */ | |
254 | xfs_buf_t *, /* buffer to mark */ | |
1da177e4 LT |
255 | int); /* run completion locally, or in |
256 | * a helper thread. */ | |
257 | ||
258 | extern void pagebuf_ioerror( /* mark buffer in error (or not) */ | |
259 | xfs_buf_t *, /* buffer to mark */ | |
260 | int); /* error to store (0 if none) */ | |
261 | ||
262 | extern int pagebuf_iostart( /* start I/O on a buffer */ | |
263 | xfs_buf_t *, /* buffer to start */ | |
264 | page_buf_flags_t); /* PBF_LOCK, PBF_ASYNC, */ | |
265 | /* PBF_READ, PBF_WRITE, */ | |
266 | /* PBF_DELWRI */ | |
267 | ||
268 | extern int pagebuf_iorequest( /* start real I/O */ | |
269 | xfs_buf_t *); /* buffer to convey to device */ | |
270 | ||
271 | extern int pagebuf_iowait( /* wait for buffer I/O done */ | |
272 | xfs_buf_t *); /* buffer to wait on */ | |
273 | ||
274 | extern void pagebuf_iomove( /* move data in/out of pagebuf */ | |
275 | xfs_buf_t *, /* buffer to manipulate */ | |
276 | size_t, /* starting buffer offset */ | |
277 | size_t, /* length in buffer */ | |
278 | caddr_t, /* data pointer */ | |
279 | page_buf_rw_t); /* direction */ | |
280 | ||
281 | static inline int pagebuf_iostrategy(xfs_buf_t *pb) | |
282 | { | |
283 | return pb->pb_strat ? pb->pb_strat(pb) : pagebuf_iorequest(pb); | |
284 | } | |
285 | ||
286 | static inline int pagebuf_geterror(xfs_buf_t *pb) | |
287 | { | |
288 | return pb ? pb->pb_error : ENOMEM; | |
289 | } | |
290 | ||
291 | /* Buffer Utility Routines */ | |
292 | ||
293 | extern caddr_t pagebuf_offset( /* pointer at offset in buffer */ | |
294 | xfs_buf_t *, /* buffer to offset into */ | |
295 | size_t); /* offset */ | |
296 | ||
297 | /* Pinning Buffer Storage in Memory */ | |
298 | ||
299 | extern void pagebuf_pin( /* pin buffer in memory */ | |
300 | xfs_buf_t *); /* buffer to pin */ | |
301 | ||
302 | extern void pagebuf_unpin( /* unpin buffered data */ | |
303 | xfs_buf_t *); /* buffer to unpin */ | |
304 | ||
305 | extern int pagebuf_ispin( /* check if buffer is pinned */ | |
306 | xfs_buf_t *); /* buffer to check */ | |
307 | ||
308 | /* Delayed Write Buffer Routines */ | |
309 | ||
310 | extern void pagebuf_delwri_dequeue(xfs_buf_t *); | |
311 | ||
312 | /* Buffer Daemon Setup Routines */ | |
313 | ||
314 | extern int pagebuf_init(void); | |
315 | extern void pagebuf_terminate(void); | |
316 | ||
317 | ||
318 | #ifdef PAGEBUF_TRACE | |
319 | extern ktrace_t *pagebuf_trace_buf; | |
320 | extern void pagebuf_trace( | |
321 | xfs_buf_t *, /* buffer being traced */ | |
322 | char *, /* description of operation */ | |
323 | void *, /* arbitrary diagnostic value */ | |
324 | void *); /* return address */ | |
325 | #else | |
326 | # define pagebuf_trace(pb, id, ptr, ra) do { } while (0) | |
327 | #endif | |
328 | ||
329 | #define pagebuf_target_name(target) \ | |
330 | ({ char __b[BDEVNAME_SIZE]; bdevname((target)->pbr_bdev, __b); __b; }) | |
331 | ||
332 | ||
333 | ||
1da177e4 LT |
334 | /* These are just for xfs_syncsub... it sets an internal variable |
335 | * then passes it to VOP_FLUSH_PAGES or adds the flags to a newly gotten buf_t | |
336 | */ | |
337 | #define XFS_B_ASYNC PBF_ASYNC | |
338 | #define XFS_B_DELWRI PBF_DELWRI | |
339 | #define XFS_B_READ PBF_READ | |
340 | #define XFS_B_WRITE PBF_WRITE | |
341 | #define XFS_B_STALE PBF_STALE | |
342 | ||
343 | #define XFS_BUF_TRYLOCK PBF_TRYLOCK | |
344 | #define XFS_INCORE_TRYLOCK PBF_TRYLOCK | |
345 | #define XFS_BUF_LOCK PBF_LOCK | |
346 | #define XFS_BUF_MAPPED PBF_MAPPED | |
347 | ||
348 | #define BUF_BUSY PBF_DONT_BLOCK | |
349 | ||
350 | #define XFS_BUF_BFLAGS(x) ((x)->pb_flags) | |
351 | #define XFS_BUF_ZEROFLAGS(x) \ | |
352 | ((x)->pb_flags &= ~(PBF_READ|PBF_WRITE|PBF_ASYNC|PBF_DELWRI)) | |
353 | ||
354 | #define XFS_BUF_STALE(x) ((x)->pb_flags |= XFS_B_STALE) | |
355 | #define XFS_BUF_UNSTALE(x) ((x)->pb_flags &= ~XFS_B_STALE) | |
356 | #define XFS_BUF_ISSTALE(x) ((x)->pb_flags & XFS_B_STALE) | |
357 | #define XFS_BUF_SUPER_STALE(x) do { \ | |
358 | XFS_BUF_STALE(x); \ | |
359 | pagebuf_delwri_dequeue(x); \ | |
360 | XFS_BUF_DONE(x); \ | |
361 | } while (0) | |
362 | ||
363 | #define XFS_BUF_MANAGE PBF_FS_MANAGED | |
364 | #define XFS_BUF_UNMANAGE(x) ((x)->pb_flags &= ~PBF_FS_MANAGED) | |
365 | ||
366 | #define XFS_BUF_DELAYWRITE(x) ((x)->pb_flags |= PBF_DELWRI) | |
367 | #define XFS_BUF_UNDELAYWRITE(x) pagebuf_delwri_dequeue(x) | |
368 | #define XFS_BUF_ISDELAYWRITE(x) ((x)->pb_flags & PBF_DELWRI) | |
369 | ||
370 | #define XFS_BUF_ERROR(x,no) pagebuf_ioerror(x,no) | |
371 | #define XFS_BUF_GETERROR(x) pagebuf_geterror(x) | |
372 | #define XFS_BUF_ISERROR(x) (pagebuf_geterror(x)?1:0) | |
373 | ||
c86e711c CH |
374 | #define XFS_BUF_DONE(x) ((x)->pb_flags |= PBF_DONE) |
375 | #define XFS_BUF_UNDONE(x) ((x)->pb_flags &= ~PBF_DONE) | |
376 | #define XFS_BUF_ISDONE(x) ((x)->pb_flags & PBF_DONE) | |
1da177e4 | 377 | |
88741a95 CH |
378 | #define XFS_BUF_BUSY(x) do { } while (0) |
379 | #define XFS_BUF_UNBUSY(x) do { } while (0) | |
1da177e4 LT |
380 | #define XFS_BUF_ISBUSY(x) (1) |
381 | ||
382 | #define XFS_BUF_ASYNC(x) ((x)->pb_flags |= PBF_ASYNC) | |
383 | #define XFS_BUF_UNASYNC(x) ((x)->pb_flags &= ~PBF_ASYNC) | |
384 | #define XFS_BUF_ISASYNC(x) ((x)->pb_flags & PBF_ASYNC) | |
385 | ||
f538d4da CH |
386 | #define XFS_BUF_ORDERED(x) ((x)->pb_flags |= PBF_ORDERED) |
387 | #define XFS_BUF_UNORDERED(x) ((x)->pb_flags &= ~PBF_ORDERED) | |
388 | #define XFS_BUF_ISORDERED(x) ((x)->pb_flags & PBF_ORDERED) | |
1da177e4 LT |
389 | |
390 | #define XFS_BUF_SHUT(x) printk("XFS_BUF_SHUT not implemented yet\n") | |
391 | #define XFS_BUF_UNSHUT(x) printk("XFS_BUF_UNSHUT not implemented yet\n") | |
392 | #define XFS_BUF_ISSHUT(x) (0) | |
393 | ||
394 | #define XFS_BUF_HOLD(x) pagebuf_hold(x) | |
395 | #define XFS_BUF_READ(x) ((x)->pb_flags |= PBF_READ) | |
396 | #define XFS_BUF_UNREAD(x) ((x)->pb_flags &= ~PBF_READ) | |
397 | #define XFS_BUF_ISREAD(x) ((x)->pb_flags & PBF_READ) | |
398 | ||
399 | #define XFS_BUF_WRITE(x) ((x)->pb_flags |= PBF_WRITE) | |
400 | #define XFS_BUF_UNWRITE(x) ((x)->pb_flags &= ~PBF_WRITE) | |
401 | #define XFS_BUF_ISWRITE(x) ((x)->pb_flags & PBF_WRITE) | |
402 | ||
403 | #define XFS_BUF_ISUNINITIAL(x) (0) | |
404 | #define XFS_BUF_UNUNINITIAL(x) (0) | |
405 | ||
406 | #define XFS_BUF_BP_ISMAPPED(bp) 1 | |
407 | ||
1da177e4 LT |
408 | #define XFS_BUF_IODONE_FUNC(buf) (buf)->pb_iodone |
409 | #define XFS_BUF_SET_IODONE_FUNC(buf, func) \ | |
410 | (buf)->pb_iodone = (func) | |
411 | #define XFS_BUF_CLR_IODONE_FUNC(buf) \ | |
412 | (buf)->pb_iodone = NULL | |
413 | #define XFS_BUF_SET_BDSTRAT_FUNC(buf, func) \ | |
414 | (buf)->pb_strat = (func) | |
415 | #define XFS_BUF_CLR_BDSTRAT_FUNC(buf) \ | |
416 | (buf)->pb_strat = NULL | |
417 | ||
418 | #define XFS_BUF_FSPRIVATE(buf, type) \ | |
419 | ((type)(buf)->pb_fspriv) | |
420 | #define XFS_BUF_SET_FSPRIVATE(buf, value) \ | |
421 | (buf)->pb_fspriv = (void *)(value) | |
422 | #define XFS_BUF_FSPRIVATE2(buf, type) \ | |
423 | ((type)(buf)->pb_fspriv2) | |
424 | #define XFS_BUF_SET_FSPRIVATE2(buf, value) \ | |
425 | (buf)->pb_fspriv2 = (void *)(value) | |
426 | #define XFS_BUF_FSPRIVATE3(buf, type) \ | |
427 | ((type)(buf)->pb_fspriv3) | |
428 | #define XFS_BUF_SET_FSPRIVATE3(buf, value) \ | |
429 | (buf)->pb_fspriv3 = (void *)(value) | |
430 | #define XFS_BUF_SET_START(buf) | |
431 | ||
432 | #define XFS_BUF_SET_BRELSE_FUNC(buf, value) \ | |
433 | (buf)->pb_relse = (value) | |
434 | ||
435 | #define XFS_BUF_PTR(bp) (xfs_caddr_t)((bp)->pb_addr) | |
436 | ||
a3c476d8 | 437 | static inline xfs_caddr_t xfs_buf_offset(xfs_buf_t *bp, size_t offset) |
1da177e4 LT |
438 | { |
439 | if (bp->pb_flags & PBF_MAPPED) | |
440 | return XFS_BUF_PTR(bp) + offset; | |
441 | return (xfs_caddr_t) pagebuf_offset(bp, offset); | |
442 | } | |
443 | ||
444 | #define XFS_BUF_SET_PTR(bp, val, count) \ | |
445 | pagebuf_associate_memory(bp, val, count) | |
446 | #define XFS_BUF_ADDR(bp) ((bp)->pb_bn) | |
447 | #define XFS_BUF_SET_ADDR(bp, blk) \ | |
448 | ((bp)->pb_bn = (xfs_daddr_t)(blk)) | |
449 | #define XFS_BUF_OFFSET(bp) ((bp)->pb_file_offset) | |
450 | #define XFS_BUF_SET_OFFSET(bp, off) \ | |
451 | ((bp)->pb_file_offset = (off)) | |
452 | #define XFS_BUF_COUNT(bp) ((bp)->pb_count_desired) | |
453 | #define XFS_BUF_SET_COUNT(bp, cnt) \ | |
454 | ((bp)->pb_count_desired = (cnt)) | |
455 | #define XFS_BUF_SIZE(bp) ((bp)->pb_buffer_length) | |
456 | #define XFS_BUF_SET_SIZE(bp, cnt) \ | |
457 | ((bp)->pb_buffer_length = (cnt)) | |
458 | #define XFS_BUF_SET_VTYPE_REF(bp, type, ref) | |
459 | #define XFS_BUF_SET_VTYPE(bp, type) | |
460 | #define XFS_BUF_SET_REF(bp, ref) | |
461 | ||
462 | #define XFS_BUF_ISPINNED(bp) pagebuf_ispin(bp) | |
463 | ||
464 | #define XFS_BUF_VALUSEMA(bp) pagebuf_lock_value(bp) | |
465 | #define XFS_BUF_CPSEMA(bp) (pagebuf_cond_lock(bp) == 0) | |
466 | #define XFS_BUF_VSEMA(bp) pagebuf_unlock(bp) | |
467 | #define XFS_BUF_PSEMA(bp,x) pagebuf_lock(bp) | |
468 | #define XFS_BUF_V_IODONESEMA(bp) up(&bp->pb_iodonesema); | |
469 | ||
470 | /* setup the buffer target from a buftarg structure */ | |
471 | #define XFS_BUF_SET_TARGET(bp, target) \ | |
472 | (bp)->pb_target = (target) | |
473 | #define XFS_BUF_TARGET(bp) ((bp)->pb_target) | |
474 | #define XFS_BUFTARG_NAME(target) \ | |
475 | pagebuf_target_name(target) | |
476 | ||
477 | #define XFS_BUF_SET_VTYPE_REF(bp, type, ref) | |
478 | #define XFS_BUF_SET_VTYPE(bp, type) | |
479 | #define XFS_BUF_SET_REF(bp, ref) | |
480 | ||
481 | static inline int xfs_bawrite(void *mp, xfs_buf_t *bp) | |
482 | { | |
483 | bp->pb_fspriv3 = mp; | |
484 | bp->pb_strat = xfs_bdstrat_cb; | |
485 | pagebuf_delwri_dequeue(bp); | |
486 | return pagebuf_iostart(bp, PBF_WRITE | PBF_ASYNC | _PBF_RUN_QUEUES); | |
487 | } | |
488 | ||
489 | static inline void xfs_buf_relse(xfs_buf_t *bp) | |
490 | { | |
491 | if (!bp->pb_relse) | |
492 | pagebuf_unlock(bp); | |
493 | pagebuf_rele(bp); | |
494 | } | |
495 | ||
496 | #define xfs_bpin(bp) pagebuf_pin(bp) | |
497 | #define xfs_bunpin(bp) pagebuf_unpin(bp) | |
498 | ||
499 | #define xfs_buftrace(id, bp) \ | |
500 | pagebuf_trace(bp, id, NULL, (void *)__builtin_return_address(0)) | |
501 | ||
502 | #define xfs_biodone(pb) \ | |
88741a95 | 503 | pagebuf_iodone(pb, 0) |
1da177e4 LT |
504 | |
505 | #define xfs_biomove(pb, off, len, data, rw) \ | |
506 | pagebuf_iomove((pb), (off), (len), (data), \ | |
507 | ((rw) == XFS_B_WRITE) ? PBRW_WRITE : PBRW_READ) | |
508 | ||
509 | #define xfs_biozero(pb, off, len) \ | |
510 | pagebuf_iomove((pb), (off), (len), NULL, PBRW_ZERO) | |
511 | ||
512 | ||
513 | static inline int XFS_bwrite(xfs_buf_t *pb) | |
514 | { | |
515 | int iowait = (pb->pb_flags & PBF_ASYNC) == 0; | |
516 | int error = 0; | |
517 | ||
518 | if (!iowait) | |
519 | pb->pb_flags |= _PBF_RUN_QUEUES; | |
520 | ||
521 | pagebuf_delwri_dequeue(pb); | |
522 | pagebuf_iostrategy(pb); | |
523 | if (iowait) { | |
524 | error = pagebuf_iowait(pb); | |
525 | xfs_buf_relse(pb); | |
526 | } | |
527 | return error; | |
528 | } | |
529 | ||
530 | #define XFS_bdwrite(pb) \ | |
531 | pagebuf_iostart(pb, PBF_DELWRI | PBF_ASYNC) | |
532 | ||
533 | static inline int xfs_bdwrite(void *mp, xfs_buf_t *bp) | |
534 | { | |
535 | bp->pb_strat = xfs_bdstrat_cb; | |
536 | bp->pb_fspriv3 = mp; | |
537 | ||
538 | return pagebuf_iostart(bp, PBF_DELWRI | PBF_ASYNC); | |
539 | } | |
540 | ||
541 | #define XFS_bdstrat(bp) pagebuf_iorequest(bp) | |
542 | ||
543 | #define xfs_iowait(pb) pagebuf_iowait(pb) | |
544 | ||
545 | #define xfs_baread(target, rablkno, ralen) \ | |
546 | pagebuf_readahead((target), (rablkno), (ralen), PBF_DONT_BLOCK) | |
547 | ||
548 | #define xfs_buf_get_empty(len, target) pagebuf_get_empty((len), (target)) | |
549 | #define xfs_buf_get_noaddr(len, target) pagebuf_get_no_daddr((len), (target)) | |
550 | #define xfs_buf_free(bp) pagebuf_free(bp) | |
551 | ||
552 | ||
553 | /* | |
554 | * Handling of buftargs. | |
555 | */ | |
556 | ||
557 | extern xfs_buftarg_t *xfs_alloc_buftarg(struct block_device *, int); | |
558 | extern void xfs_free_buftarg(xfs_buftarg_t *, int); | |
559 | extern void xfs_wait_buftarg(xfs_buftarg_t *); | |
560 | extern int xfs_setsize_buftarg(xfs_buftarg_t *, unsigned int, unsigned int); | |
1da177e4 LT |
561 | extern int xfs_flush_buftarg(xfs_buftarg_t *, int); |
562 | ||
563 | #define xfs_getsize_buftarg(buftarg) \ | |
564 | block_size((buftarg)->pbr_bdev) | |
565 | #define xfs_readonly_buftarg(buftarg) \ | |
566 | bdev_read_only((buftarg)->pbr_bdev) | |
567 | #define xfs_binval(buftarg) \ | |
568 | xfs_flush_buftarg(buftarg, 1) | |
569 | #define XFS_bflush(buftarg) \ | |
570 | xfs_flush_buftarg(buftarg, 1) | |
571 | ||
572 | #endif /* __XFS_BUF_H__ */ |