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