]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/bio.h
This commit was generated by cvs2svn to compensate for changes in r80016,
[FreeBSD/FreeBSD.git] / sys / sys / bio.h
1 /*
2  * Copyright (c) 1982, 1986, 1989, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  * (c) UNIX System Laboratories, Inc.
5  * All or some portions of this file are derived from material licensed
6  * to the University of California by American Telephone and Telegraph
7  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8  * the permission of UNIX System Laboratories, Inc.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *      This product includes software developed by the University of
21  *      California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *      @(#)buf.h       8.9 (Berkeley) 3/30/95
39  * $FreeBSD$
40  */
41
42 #ifndef _SYS_BIO_H_
43 #define _SYS_BIO_H_
44
45 #include <sys/queue.h>
46
47 struct bio;
48 struct buf;
49
50 struct iodone_chain {
51         long    ic_prev_flags;
52         void    (*ic_prev_iodone) __P((struct bio *));
53         void    *ic_prev_iodone_chain;
54         struct {
55                 long    ia_long;
56                 void    *ia_ptr;
57         }       ic_args[5];
58 };
59
60 /*
61  * The bio structure describes an I/O operation in the kernel.
62  */
63 struct bio {
64         u_int   bio_cmd;                /* I/O operation. */
65         dev_t   bio_dev;                /* Device to do I/O on. */
66         daddr_t bio_blkno;              /* Underlying physical block number. */
67         off_t   bio_offset;             /* Offset into file. */
68         long    bio_bcount;             /* Valid bytes in buffer. */
69         caddr_t bio_data;               /* Memory, superblocks, indirect etc. */
70         u_int   bio_flags;              /* BIO_ flags. */
71         struct buf      *_bio_buf;      /* Parent buffer. */
72         int     bio_error;              /* Errno for BIO_ERROR. */
73         long    bio_resid;              /* Remaining I/0 in bytes. */
74         void    (*bio_done) __P((struct bio *));
75         void    *bio_driver1;           /* Private use by the callee. */
76         void    *bio_driver2;           /* Private use by the callee. */
77         void    *bio_caller1;           /* Private use by the caller. */
78         void    *bio_caller2;           /* Private use by the caller. */
79         TAILQ_ENTRY(bio) bio_queue;     /* Disksort queue. */
80
81         /* XXX: these go away when bio chaining is introduced */
82         daddr_t bio_pblkno;               /* physical block number */
83         struct  iodone_chain *bio_done_chain;
84 };
85
86 /* bio_cmd */
87 #define BIO_READ        1
88 #define BIO_WRITE       2
89 #define BIO_DELETE      4
90 #define BIO_FORMAT      8
91 #define BIO_CMD1        0x40000000      /* Available for local hacks */
92 #define BIO_CMD2        0x80000000      /* Available for local hacks */
93
94 /* bio_flags */
95 #define BIO_ERROR       0x00000001
96 #define BIO_ORDERED     0x00000002
97 #define BIO_DONE        0x00000004
98 #define BIO_FLAG2       0x40000000      /* Available for local hacks */
99 #define BIO_FLAG1       0x80000000      /* Available for local hacks */
100
101 #ifdef _KERNEL
102
103 static __inline__ void
104 biodone(struct bio *bp)
105 {
106         bp->bio_flags |= BIO_DONE;
107         bp->bio_done(bp);
108 }
109
110 #ifndef _DEVICESTAT_H
111 struct devstat;
112 void devstat_end_transaction_bio(struct devstat *, struct bio *);
113 #endif
114
115 static __inline__ void
116 biofinish(struct bio *bp, struct devstat *stat, int error)
117 {
118         
119         if (error) {
120                 bp->bio_error = error;
121                 bp->bio_flags |= BIO_ERROR;
122         }
123         if (stat != NULL)
124                 devstat_end_transaction_bio(stat, bp);
125         biodone(bp);
126 }
127
128 struct bio_queue_head {
129         TAILQ_HEAD(bio_queue, bio) queue;
130         daddr_t last_pblkno;
131         struct  bio *insert_point;
132         struct  bio *switch_point;
133         int busy;
134 };
135
136 static __inline void bioq_init __P((struct bio_queue_head *head));
137 static __inline void bioq_insert_tail __P((struct bio_queue_head *head,
138                                            struct bio *bp));
139 static __inline void bioq_remove __P((struct bio_queue_head *head,
140                                       struct bio *bp));
141 static __inline struct bio *bioq_first __P((struct bio_queue_head *head));
142
143 static __inline void
144 bioq_init(struct bio_queue_head *head)
145 {
146         TAILQ_INIT(&head->queue);
147         head->last_pblkno = 0;
148         head->insert_point = NULL;
149         head->switch_point = NULL;
150 }
151
152 static __inline void
153 bioq_insert_tail(struct bio_queue_head *head, struct bio *bp)
154 {
155         if ((bp->bio_flags & BIO_ORDERED) != 0) {
156                 head->insert_point = bp;
157                 head->switch_point = NULL;
158         }
159         TAILQ_INSERT_TAIL(&head->queue, bp, bio_queue);
160 }
161
162 static __inline void
163 bioq_remove(struct bio_queue_head *head, struct bio *bp)
164 {
165         if (bp == head->switch_point)
166                 head->switch_point = TAILQ_NEXT(bp, bio_queue);
167         if (bp == head->insert_point) {
168                 head->insert_point = TAILQ_PREV(bp, bio_queue, bio_queue);
169                 if (head->insert_point == NULL)
170                         head->last_pblkno = 0;
171         } else if (bp == TAILQ_FIRST(&head->queue))
172                 head->last_pblkno = bp->bio_pblkno;
173         TAILQ_REMOVE(&head->queue, bp, bio_queue);
174         if (TAILQ_FIRST(&head->queue) == head->switch_point)
175                 head->switch_point = NULL;
176 }
177
178 static __inline struct bio *
179 bioq_first(struct bio_queue_head *head)
180 {
181         return (TAILQ_FIRST(&head->queue));
182 }
183
184 /*
185  * Zero out the bio's data area.
186  */
187 #define clrbio(bp) {                                                    \
188         bzero((bp)->bio_data, (u_int)(bp)->bio_bcount);                 \
189         (bp)->bio_resid = 0;                                            \
190 }
191
192 int     physio __P((dev_t dev, struct uio *uio, int ioflag));
193 #define physread physio
194 #define physwrite physio
195
196 #endif /* _KERNEL */
197
198 #endif /* !_SYS_BIO_H_ */