2 * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
38 /* XXX: move this into buf.h */
40 #define B_MANAGED B_08000000
47 typedef void (*xfs_buf_iodone_t)(struct xfs_buf *); /* call-back function on I/O completion */
48 typedef void (*xfs_buf_relse_t)(struct xfs_buf *); /* call-back function on I/O completion */
49 typedef int (*xfs_buf_bdstrat_t)(struct xfs_buf *);
51 typedef struct xfs_buftarg {
56 typedef struct buf xfs_buf_t;
59 /* These are just for xfs_syncsub... it sets an internal variable
60 * then passes it to VOP_FLUSH_PAGES or adds the flags to a newly gotten buf_t
63 #define XFS_B_ASYNC B_ASYNC
64 #define XFS_B_DELWRI B_DELWRI
65 #define XFS_B_READ BIO_READ
66 #define XFS_B_WRITE BIO_WRITE
68 #define XFS_B_STALE B_INVAL
69 #define XFS_BUF_LOCK 0
70 #define XFS_BUF_TRYLOCK 0
71 #define XFS_BUF_MAPPED 0
74 /* debugging routines might need this */
75 #define XFS_BUF_BFLAGS(x) ((x)->b_flags)
76 #define XFS_BUF_ZEROFLAGS(x) ((x)->b_flags = 0)
77 #define XFS_BUF_STALE(x) ((x)->b_flags |= XFS_B_STALE)
78 #define XFS_BUF_UNSTALE(x) ((x)->b_flags &= ~XFS_B_STALE)
79 #define XFS_BUF_ISSTALE(x) ((x)->b_flags & XFS_B_STALE)
80 #define XFS_BUF_SUPER_STALE(x) {(x)->b_flags |= XFS_B_STALE;\
81 (x)->b_flags &= ~(XFS_B_DELWRI|B_CACHE);}
83 #define XFS_BUF_MANAGE B_MANAGED
84 #define XFS_BUF_UNMANAGE(x) ((x)->b_flags &= ~B_MANAGED)
86 #define XFS_BUF_DELAYWRITE(x) ((x)->b_flags |= XFS_B_DELWRI)
87 #define XFS_BUF_UNDELAYWRITE(x) ((x)->b_flags &= ~XFS_B_DELWRI)
88 #define XFS_BUF_ISDELAYWRITE(x) ((x)->b_flags & XFS_B_DELWRI)
90 #define XFS_BUF_ERROR(x,no) xfs_buf_set_error((x), (no))
91 #define XFS_BUF_GETERROR(x) xfs_buf_get_error(x)
92 #define XFS_BUF_ISERROR(x) (((x)->b_ioflags & BIO_ERROR) != 0)
94 void static __inline__
95 xfs_buf_set_error(struct buf *bp, int err)
97 bp->b_ioflags |= BIO_ERROR;
101 int static __inline__
102 xfs_buf_get_error(struct buf *bp)
104 return XFS_BUF_ISERROR(bp) ? (bp->b_error ? bp->b_error : EIO) : 0;
107 #define XFS_BUF_DONE(x) ((x)->b_flags |= B_CACHE)
108 #define XFS_BUF_UNDONE(x) ((x)->b_flags &= ~B_CACHE)
109 #define XFS_BUF_ISDONE(x) ((x)->b_flags & B_CACHE)
111 #define XFS_BUF_BUSY(x) ((x)->b_flags |= BUF_BUSY)
112 #define XFS_BUF_UNBUSY(x) ((x)->b_flags &= ~BUF_BUSY)
113 #define XFS_BUF_ISBUSY(x) (1)
115 #define XFS_BUF_ASYNC(x) ((x)->b_flags |= B_ASYNC)
116 #define XFS_BUF_UNASYNC(x) ((x)->b_flags &= ~B_ASYNC)
117 #define XFS_BUF_ISASYNC(x) ((x)->b_flags & B_ASYNC)
119 #define XFS_BUF_FLUSH(x) ((x)->b_flags |= B_00800000)
120 #define XFS_BUF_UNFLUSH(x) ((x)->b_flags &= ~B_00800000)
121 #define XFS_BUF_ISFLUSH(x) ((x)->b_flags & B_00800000)
123 #define XFS_BUF_SHUT(x) printf("XFS_BUF_SHUT not implemented yet\n")
124 #define XFS_BUF_UNSHUT(x) printf("XFS_BUF_UNSHUT not implemented yet\n")
125 #define XFS_BUF_ISSHUT(x) (0)
127 #define XFS_BUF_HOLD(x) ((void)0)
128 #define XFS_BUF_UNHOLD(x) ((void)0)
129 #define XFS_BUF_ISHOLD(x) BUF_REFCNT(x)
131 #define XFS_BUF_READ(x) ((x)->b_iocmd = BIO_READ)
132 #define XFS_BUF_UNREAD(x) ((x)->b_iocmd = 0)
133 #define XFS_BUF_ISREAD(x) ((x)->b_iocmd == BIO_READ)
135 #define XFS_BUF_WRITE(x) ((x)->b_iocmd = BIO_WRITE)
136 #define XFS_BUF_UNWRITE(x) ((x)->b_iocmd = 0)
137 #define XFS_BUF_ISWRITE(x) ((x)->b_iocmd == BIO_WRITE)
139 #define XFS_BUF_ISUNINITIAL(x) (0)
140 #define XFS_BUF_UNUNINITIAL(x) (0)
142 #define XFS_BUF_IODONE_FUNC(x) (x)->b_iodone
143 #define XFS_BUF_SET_IODONE_FUNC(x, f) (x)->b_iodone = (f)
144 #define XFS_BUF_CLR_IODONE_FUNC(x) (x)->b_iodone = NULL
146 #define XFS_BUF_SET_BDSTRAT_FUNC(x, f) do { if(f != NULL) {} } while(0)
147 #define XFS_BUF_CLR_BDSTRAT_FUNC(x) ((void)0)
149 #define XFS_BUF_BP_ISMAPPED(bp) (1)
151 #define XFS_BUF_FSPRIVATE(buf, type) \
152 ((type)(buf)->b_fsprivate1)
153 #define XFS_BUF_SET_FSPRIVATE(buf, value) \
154 (buf)->b_fsprivate1 = (void *)(value)
155 #define XFS_BUF_FSPRIVATE2(buf, type) \
156 ((type)(buf)->b_fsprivate2)
157 #define XFS_BUF_SET_FSPRIVATE2(buf, value) \
158 (buf)->b_fsprivate2 = (void *)(value)
159 #define XFS_BUF_FSPRIVATE3(buf, type) \
160 ((type)(buf)->b_fsprivate3)
161 #define XFS_BUF_SET_FSPRIVATE3(buf, value) \
162 (buf)->b_fsprivate3 = (void *)(value)
163 #define XFS_BUF_SET_START(buf) \
164 printf("XFS_BUF_SET_START: %s:%d\n", __FILE__, __LINE__)
166 #define XFS_BUF_SET_BRELSE_FUNC(buf, value) \
168 printf("XFS_BUF_SET_BRELSE_FUNC: %s:%d\n", \
169 __FILE__, __LINE__); \
170 if (value != NULL ) {} \
173 #define XFS_BUF_PTR(bp) (xfs_caddr_t)((bp)->b_data)
175 static __inline xfs_caddr_t
176 xfs_buf_offset(xfs_buf_t *bp, size_t offset)
178 return XFS_BUF_PTR(bp) + offset;
181 #define XFS_BUF_SET_PTR(bp, val, count) \
183 (bp)->b_data = (val); \
184 (bp)->b_bcount = (count); \
187 #define XFS_BUF_ADDR(bp) ((bp)->b_blkno)
188 #define XFS_BUF_SET_ADDR(bp, blk) \
189 ((bp)->b_blkno = blk)
190 #define XFS_BUF_OFFSET(bp) ((bp)->b_offset)
191 #define XFS_BUF_SET_OFFSET(bp, off) \
192 ((bp)->b_offset = off)
193 #define XFS_BUF_COUNT(bp) ((bp)->b_bcount)
194 #define XFS_BUF_SET_COUNT(bp, cnt) \
195 ((bp)->b_bcount = cnt)
196 #define XFS_BUF_SIZE(bp) ((bp)->b_bufsize)
197 #define XFS_BUF_SET_SIZE(bp, cnt) \
198 ((bp)->b_bufsize = cnt)
199 #define XFS_BUF_SET_VTYPE_REF(bp, type, ref)
200 #define XFS_BUF_SET_VTYPE(bp, type)
201 #define XFS_BUF_SET_REF(bp, ref)
203 #define XFS_BUF_VALUSEMA(bp) (BUF_REFCNT(bp)? 0 : 1)
204 #define XFS_BUF_CPSEMA(bp) \
205 (BUF_LOCK(bp, LK_EXCLUSIVE|LK_CANRECURSE | LK_SLEEPFAIL, NULL) == 0)
206 #define XFS_BUF_PSEMA(bp,x) BUF_LOCK(bp, LK_EXCLUSIVE|LK_CANRECURSE, NULL)
207 #define XFS_BUF_VSEMA(bp) BUF_UNLOCK(bp)
208 #define XFS_BUF_V_IODONESEMA(bp) bdone(bp)
210 /* setup the buffer target from a buftarg structure */
211 #define XFS_BUF_SET_TARGET(bp, target) \
212 xfs_buf_set_target(bp, target)
214 void xfs_buf_set_target(xfs_buf_t *, xfs_buftarg_t *);
215 xfs_buftarg_t *xfs_buf_get_target(xfs_buf_t *);
217 /* return the dev_t being used */
218 #define XFS_BUF_TARGET(bp) xfs_buf_get_target(bp)
219 #define XFS_BUFTARG_NAME(targp) devtoname((targp)->dev)
221 #define XFS_BUF_SET_VTYPE_REF(bp, type, ref)
222 #define XFS_BUF_SET_VTYPE(bp, type)
223 #define XFS_BUF_SET_REF(bp, ref)
225 #define XFS_BUF_ISPINNED(bp) xfs_ispin(bp)
228 xfs_buf_read_flags(xfs_buftarg_t *, xfs_daddr_t, size_t, int);
230 #define xfs_buf_read(target, blkno, len, flags) \
231 xfs_buf_read_flags(target, blkno, len, \
232 XFS_BUF_LOCK | XFS_BUF_MAPPED)
235 xfs_buf_get_flags(xfs_buftarg_t *, xfs_daddr_t, size_t, int);
237 #define xfs_buf_get(target, blkno, len, flags) \
238 xfs_buf_get_flags(target, blkno, len, \
239 XFS_BUF_LOCK | XFS_BUF_MAPPED)
241 #define xfs_bdwrite(mp, bp) bdwrite(bp)
243 { ((bp)->b_vp == NULL) ? (bp)->b_bdstrat = xfs_bdstrat_cb: 0; \
244 (bp)->b_fsprivate3 = (mp); bdwrite(bp);}
246 #define xfs_bawrite(mp, bp) bawrite(bp)
248 { ((bp)->b_vp == NULL) ? (bp)->b_bdstrat = xfs_bdstrat_cb: 0; \
249 (bp)->b_fsprivate3 = (mp); bawrite(bp);}
252 #define xfs_buf_relse(bp) brelse(bp)
253 #define xfs_bp_mapin(bp) bp_mapin(bp)
254 #define xfs_xfsd_list_evict(x) _xfs_xfsd_list_evict(x)
255 #define xfs_buftrace(x,y) CTR2(KTR_BUF, "%s bp %p flags %X", bp, bp->b_flags)
256 #define xfs_biodone(bp) bufdone_finish(bp)
258 #define xfs_incore(xfs_buftarg,blkno,len,lockit) \
259 incore(&xfs_buftarg->specvp->v_bufobj, blkno);
261 #define xfs_biomove(pb, off, len, data, rw) \
262 panic("%s:%d: xfs_biomove NI", __FILE__, __LINE__)
264 #define xfs_biozero(pb, off, len) \
265 panic("%s:%d: xfs_biozero NI", __FILE__, __LINE__)
267 /* already a function xfs_bwrite... fix this */
268 #define XFS_bdwrite(bp) bdwrite(bp)
269 #define xfs_iowait(bp) bufwait(bp)
271 #define xfs_binval(buftarg) printf("binval(buftarg.dev) NI\n")
272 #define XFS_bflush(buftarg) printf("bflush(buftarg.dev) NI\n")
274 #define XFS_bdstrat(bp) printf("XFS_bdstrat NI\n")
276 #define xfs_incore_relse(buftarg,delwri_only,wait) \
277 printf("incore_relse(buftarg.dev,delwri_only,wait) NI\n")
279 #define xfs_incore_match(buftarg,blkno,len,field,value) \
280 printf("incore_match(buftarg.dev,blkno,len,field,value) NI \n")
282 void xfs_baread(xfs_buftarg_t *targp, xfs_daddr_t ioff, size_t isize);
284 extern void pdflush(struct vnode *, uint64_t);
285 #define XFS_pdflush(vnode,flags) \
290 int XFS_bwrite(xfs_buf_t *bp);
291 xfs_buf_t* xfs_buf_get_empty(size_t, xfs_buftarg_t *targ);
292 xfs_buf_t* xfs_buf_get_noaddr(size_t, xfs_buftarg_t *targ);
293 void xfs_buf_free(xfs_buf_t *);
294 int xfs_buf_iorequest(struct xfs_buf *bp);
296 void XFS_freerbuf(xfs_buf_t *bp);
297 void XFS_nfreerbuf(xfs_buf_t *bp);
299 void xfs_bpin(xfs_buf_t *bp);
300 void xfs_bunpin(xfs_buf_t *bp);
301 int xfs_ispin(xfs_buf_t *bp);
302 void xfs_bwait_unpin(xfs_buf_t *bp);