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