summaryrefslogtreecommitdiffstats
path: root/sys/gnu/fs/xfs/FreeBSD/xfs_buf.h
blob: 54a7fc656e4568904f86ce3a76164bc8a71d0e15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/*
 * Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it would be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * Further, this software is distributed without any warranty that it is
 * free of the rightful claim of any third person regarding infringement
 * or the like.	 Any license provided herein, whether implied or
 * otherwise, applies only to this software file.  Patent licenses, if
 * any, provided herein do not apply to combinations of this program with
 * other software, or any other product whatsoever.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write the Free Software Foundation, Inc., 59
 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
 *
 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
 * Mountain View, CA  94043, or:
 *
 * http://www.sgi.com
 *
 * For further information regarding this notice, see:
 *
 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
 */
#ifndef __XFS_BUF_H__
#define __XFS_BUF_H__

#include <sys/bio.h>
#include <sys/buf.h>

/* XXX: move this into buf.h */
#ifndef B_MANAGED
#define B_MANAGED B_08000000 
#endif

struct xfs_buf;
struct xfs_mount;
struct vnode;

typedef void (*xfs_buf_iodone_t)(struct xfs_buf *); /* call-back function on I/O completion */
typedef void (*xfs_buf_relse_t)(struct xfs_buf *); /* call-back function on I/O completion */
typedef int (*xfs_buf_bdstrat_t)(struct xfs_buf *);

typedef struct xfs_buftarg {
	struct cdev	*dev;
	struct vnode	*specvp;
} xfs_buftarg_t;

typedef struct buf xfs_buf_t;
#define xfs_buf buf

/* These are just for xfs_syncsub... it sets an internal variable
 * then passes it to VOP_FLUSH_PAGES or adds the flags to a newly gotten buf_t
 */

#define	XFS_B_ASYNC		B_ASYNC
#define	XFS_B_DELWRI		B_DELWRI
#define	XFS_B_READ		BIO_READ
#define	XFS_B_WRITE		BIO_WRITE

#define	XFS_B_STALE		B_INVAL
#define	XFS_BUF_LOCK		0
#define	XFS_BUF_TRYLOCK		0
#define	XFS_BUF_MAPPED		0
#define	BUF_BUSY		0

				/* debugging routines might need this */
#define XFS_BUF_BFLAGS(x)	((x)->b_flags)
#define XFS_BUF_ZEROFLAGS(x)	((x)->b_flags = 0)
#define XFS_BUF_STALE(x)	((x)->b_flags |= XFS_B_STALE)
#define XFS_BUF_UNSTALE(x)	((x)->b_flags &= ~XFS_B_STALE)
#define XFS_BUF_ISSTALE(x)	((x)->b_flags & XFS_B_STALE)
#define XFS_BUF_SUPER_STALE(x)	{(x)->b_flags |= XFS_B_STALE;\
				(x)->b_flags &= ~(XFS_B_DELWRI|B_CACHE);}

#define XFS_BUF_MANAGE		B_MANAGED
#define XFS_BUF_UNMANAGE(x)	((x)->b_flags &= ~B_MANAGED)

#define XFS_BUF_DELAYWRITE(x)		((x)->b_flags |= XFS_B_DELWRI)
#define XFS_BUF_UNDELAYWRITE(x)	((x)->b_flags &= ~XFS_B_DELWRI)
#define XFS_BUF_ISDELAYWRITE(x)	((x)->b_flags & XFS_B_DELWRI)

#define XFS_BUF_ERROR(x,no)	xfs_buf_set_error((x), (no))
#define XFS_BUF_GETERROR(x)	xfs_buf_get_error(x)
#define XFS_BUF_ISERROR(x)	(((x)->b_ioflags & BIO_ERROR) != 0)

void static __inline__
xfs_buf_set_error(struct buf *bp, int err)
{
	bp->b_ioflags |= BIO_ERROR;
	bp->b_error = err;
}

int static __inline__
xfs_buf_get_error(struct buf *bp)
{
	return XFS_BUF_ISERROR(bp) ? (bp->b_error ? bp->b_error : EIO) : 0;
}

#define XFS_BUF_DONE(x)		((x)->b_flags |= B_CACHE)
#define XFS_BUF_UNDONE(x)	((x)->b_flags &= ~B_CACHE)
#define XFS_BUF_ISDONE(x)	((x)->b_flags & B_CACHE)

#define XFS_BUF_BUSY(x)		((x)->b_flags |= BUF_BUSY)
#define XFS_BUF_UNBUSY(x)	((x)->b_flags &= ~BUF_BUSY)
#define XFS_BUF_ISBUSY(x)	(1)

#define XFS_BUF_ASYNC(x)	((x)->b_flags |=  B_ASYNC)
#define XFS_BUF_UNASYNC(x)	((x)->b_flags &= ~B_ASYNC)
#define XFS_BUF_ISASYNC(x)	((x)->b_flags &   B_ASYNC)

#define XFS_BUF_FLUSH(x)	((x)->b_flags |=  B_00800000)
#define XFS_BUF_UNFLUSH(x)	((x)->b_flags &= ~B_00800000)
#define XFS_BUF_ISFLUSH(x) 	((x)->b_flags &   B_00800000)

#define XFS_BUF_SHUT(x)		printf("XFS_BUF_SHUT not implemented yet\n")
#define XFS_BUF_UNSHUT(x)	printf("XFS_BUF_UNSHUT not implemented yet\n")
#define XFS_BUF_ISSHUT(x)	(0)

#define XFS_BUF_HOLD(x)		((void)0)
#define XFS_BUF_UNHOLD(x)	((void)0)
#define XFS_BUF_ISHOLD(x)	BUF_REFCNT(x)

#define XFS_BUF_READ(x)		((x)->b_iocmd = BIO_READ)
#define XFS_BUF_UNREAD(x)	((x)->b_iocmd = 0)
#define XFS_BUF_ISREAD(x)	((x)->b_iocmd == BIO_READ)

#define XFS_BUF_WRITE(x)	((x)->b_iocmd = BIO_WRITE)
#define XFS_BUF_UNWRITE(x)	((x)->b_iocmd = 0)
#define XFS_BUF_ISWRITE(x)	((x)->b_iocmd == BIO_WRITE)

#define XFS_BUF_ISUNINITIAL(x)	(0)
#define XFS_BUF_UNUNINITIAL(x)	(0)

#define XFS_BUF_IODONE_FUNC(x)		(x)->b_iodone
#define XFS_BUF_SET_IODONE_FUNC(x, f)	(x)->b_iodone = (f)
#define XFS_BUF_CLR_IODONE_FUNC(x)	(x)->b_iodone = NULL

#define XFS_BUF_SET_BDSTRAT_FUNC(x, f)	do { if(f != NULL) {} } while(0)
#define XFS_BUF_CLR_BDSTRAT_FUNC(x)	((void)0)

#define XFS_BUF_BP_ISMAPPED(bp)		(1)

#define XFS_BUF_FSPRIVATE(buf, type) \
			((type)(buf)->b_fsprivate1)
#define XFS_BUF_SET_FSPRIVATE(buf, value) \
			(buf)->b_fsprivate1 = (void *)(value)
#define XFS_BUF_FSPRIVATE2(buf, type) \
			((type)(buf)->b_fsprivate2)
#define XFS_BUF_SET_FSPRIVATE2(buf, value) \
			(buf)->b_fsprivate2 = (void *)(value)
#define XFS_BUF_FSPRIVATE3(buf, type) \
			((type)(buf)->b_fsprivate3)
#define XFS_BUF_SET_FSPRIVATE3(buf, value) \
			(buf)->b_fsprivate3 = (void *)(value)
#define XFS_BUF_SET_START(buf) \
		printf("XFS_BUF_SET_START: %s:%d\n", __FILE__, __LINE__)

#define XFS_BUF_SET_BRELSE_FUNC(buf, value) \
	do { \
		printf("XFS_BUF_SET_BRELSE_FUNC: %s:%d\n", \
		        __FILE__, __LINE__); \
		if (value != NULL ) {} \
	} while(0)

#define XFS_BUF_PTR(bp)		(xfs_caddr_t)((bp)->b_data)

static __inline xfs_caddr_t
xfs_buf_offset(xfs_buf_t *bp, size_t offset)
{
	return XFS_BUF_PTR(bp) + offset;
}

#define XFS_BUF_SET_PTR(bp, val, count)	\
				do { \
					(bp)->b_data = (val); \
					(bp)->b_bcount = (count); \
				} while(0)

#define XFS_BUF_ADDR(bp)	((bp)->b_blkno)
#define XFS_BUF_SET_ADDR(bp, blk) \
				((bp)->b_blkno = blk)
#define XFS_BUF_OFFSET(bp)	((bp)->b_offset)
#define XFS_BUF_SET_OFFSET(bp, off) \
				((bp)->b_offset = off)
#define XFS_BUF_COUNT(bp)	((bp)->b_bcount)
#define XFS_BUF_SET_COUNT(bp, cnt) \
				((bp)->b_bcount = cnt)
#define XFS_BUF_SIZE(bp)	((bp)->b_bufsize)
#define XFS_BUF_SET_SIZE(bp, cnt) \
			        ((bp)->b_bufsize = cnt)
#define	XFS_BUF_SET_VTYPE_REF(bp, type, ref)
#define	XFS_BUF_SET_VTYPE(bp, type)
#define	XFS_BUF_SET_REF(bp, ref)

#define	XFS_BUF_VALUSEMA(bp)	(BUF_REFCNT(bp)? 0 : 1)
#define	XFS_BUF_CPSEMA(bp) \
	(BUF_LOCK(bp, LK_EXCLUSIVE|LK_CANRECURSE | LK_SLEEPFAIL, NULL) == 0)
#define	XFS_BUF_PSEMA(bp,x)	BUF_LOCK(bp, LK_EXCLUSIVE|LK_CANRECURSE, NULL)
#define	XFS_BUF_VSEMA(bp)	BUF_UNLOCK(bp)
#define	XFS_BUF_V_IODONESEMA(bp) bdone(bp)

/* setup the buffer target from a buftarg structure */
#define XFS_BUF_SET_TARGET(bp, target) \
	xfs_buf_set_target(bp, target)

void xfs_buf_set_target(xfs_buf_t *, xfs_buftarg_t *);
xfs_buftarg_t *xfs_buf_get_target(xfs_buf_t *);

/* return the dev_t being used */
#define XFS_BUF_TARGET(bp)	xfs_buf_get_target(bp)
#define	XFS_BUFTARG_NAME(targp)	devtoname((targp)->dev)

#define XFS_BUF_SET_VTYPE_REF(bp, type, ref)
#define XFS_BUF_SET_VTYPE(bp, type)
#define XFS_BUF_SET_REF(bp, ref)

#define XFS_BUF_ISPINNED(bp)	xfs_ispin(bp)

xfs_buf_t *
xfs_buf_read_flags(xfs_buftarg_t *, xfs_daddr_t, size_t, int);

#define xfs_buf_read(target, blkno, len, flags) \
                xfs_buf_read_flags(target, blkno, len, \
                       XFS_BUF_LOCK | XFS_BUF_MAPPED)

xfs_buf_t *
xfs_buf_get_flags(xfs_buftarg_t *, xfs_daddr_t, size_t, int);

#define xfs_buf_get(target, blkno, len, flags) \
                xfs_buf_get_flags(target, blkno, len, \
                       XFS_BUF_LOCK | XFS_BUF_MAPPED)

#define xfs_bdwrite(mp, bp) bdwrite(bp)
/*
	{ ((bp)->b_vp == NULL) ? (bp)->b_bdstrat = xfs_bdstrat_cb: 0; \
		(bp)->b_fsprivate3 = (mp); bdwrite(bp);}
*/
#define xfs_bawrite(mp, bp) bawrite(bp)
/*
	{ ((bp)->b_vp == NULL) ? (bp)->b_bdstrat = xfs_bdstrat_cb: 0; \
		(bp)->b_fsprivate3 = (mp); bawrite(bp);}
*/

#define xfs_buf_relse(bp)            brelse(bp)
#define xfs_bp_mapin(bp)             bp_mapin(bp)
#define xfs_xfsd_list_evict(x)       _xfs_xfsd_list_evict(x)
#define xfs_buftrace(x,y)            CTR2(KTR_BUF, "%s bp %p flags %X", bp, bp->b_flags)
#define xfs_biodone(bp)              bufdone_finish(bp)

#define xfs_incore(xfs_buftarg,blkno,len,lockit)  \
			  incore(&xfs_buftarg->specvp->v_bufobj, blkno);

#define xfs_biomove(pb, off, len, data, rw) \
		panic("%s:%d: xfs_biomove NI", __FILE__, __LINE__)

#define xfs_biozero(pb, off, len) \
		panic("%s:%d: xfs_biozero NI", __FILE__, __LINE__)

/* already a function xfs_bwrite... fix this */
#define XFS_bdwrite(bp)              bdwrite(bp)
#define xfs_iowait(bp)               bufwait(bp)

#define xfs_binval(buftarg)          printf("binval(buftarg.dev) NI\n")
#define XFS_bflush(buftarg)          printf("bflush(buftarg.dev) NI\n")

#define XFS_bdstrat(bp)		     printf("XFS_bdstrat NI\n")

#define xfs_incore_relse(buftarg,delwri_only,wait) \
            printf("incore_relse(buftarg.dev,delwri_only,wait) NI\n")

#define xfs_incore_match(buftarg,blkno,len,field,value) \
            printf("incore_match(buftarg.dev,blkno,len,field,value) NI \n")

void xfs_baread(xfs_buftarg_t *targp, xfs_daddr_t ioff, size_t isize);

extern void pdflush(struct vnode *, uint64_t);
#define XFS_pdflush(vnode,flags) \
            pdflush(vnode,flags)

struct xfs_mount;

int XFS_bwrite(xfs_buf_t *bp);
xfs_buf_t* xfs_buf_get_empty(size_t, xfs_buftarg_t *targ);
xfs_buf_t* xfs_buf_get_noaddr(size_t, xfs_buftarg_t *targ);
void xfs_buf_free(xfs_buf_t *);
int xfs_buf_iorequest(struct xfs_buf *bp);

void XFS_freerbuf(xfs_buf_t *bp);
void XFS_nfreerbuf(xfs_buf_t *bp);

void xfs_bpin(xfs_buf_t *bp);
void xfs_bunpin(xfs_buf_t *bp);
int  xfs_ispin(xfs_buf_t *bp);
void xfs_bwait_unpin(xfs_buf_t *bp);

#endif
OpenPOWER on IntegriCloud