Nuke huge mbuf macros stage 1/2: Remove massive inline mbuf macros to reduce
[dragonfly.git] / sys / kern / kern_physio.c
... / ...
CommitLineData
1/*
2 * Copyright (c) 1994 John S. Dyson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice immediately at the beginning of the file, without modification,
10 * this list of conditions, and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Absolutely no warranty of function or purpose is made by the author
15 * John S. Dyson.
16 * 4. Modifications may be freely made to this file if the above conditions
17 * are met.
18 *
19 * $FreeBSD: src/sys/kern/kern_physio.c,v 1.46.2.3 2003/05/29 06:15:35 alc Exp $
20 * $DragonFly: src/sys/kern/kern_physio.c,v 1.3 2003/06/26 20:27:51 dillon Exp $
21 */
22
23#include <sys/param.h>
24#include <sys/systm.h>
25#include <sys/buf.h>
26#include <sys/conf.h>
27#include <sys/proc.h>
28#include <sys/uio.h>
29
30#include <vm/vm.h>
31#include <vm/vm_extern.h>
32
33static void
34physwakeup(struct buf *bp)
35{
36 wakeup((caddr_t) bp);
37}
38
39int
40physio(dev_t dev, struct uio *uio, int ioflag)
41{
42 int i;
43 int error;
44 int spl;
45 caddr_t sa;
46 off_t blockno;
47 u_int iolen;
48 struct buf *bp;
49
50 /*
51 * NOTE: we no longer have to PHOLD() the process, because the
52 * kernel stack / uarea cannot be swapped, and when it can be in
53 * the future it will only happen if the process is sleeping on
54 * a particular address.
55 */
56 bp = getpbuf(NULL);
57 sa = bp->b_data;
58 error = 0;
59
60 /* XXX: sanity check */
61 if(dev->si_iosize_max < PAGE_SIZE) {
62 printf("WARNING: %s si_iosize_max=%d, using DFLTPHYS.\n",
63 devtoname(dev), dev->si_iosize_max);
64 dev->si_iosize_max = DFLTPHYS;
65 }
66
67 for (i = 0; i < uio->uio_iovcnt; i++) {
68 while (uio->uio_iov[i].iov_len) {
69 if (uio->uio_rw == UIO_READ)
70 bp->b_flags = B_PHYS | B_CALL | B_READ;
71 else
72 bp->b_flags = B_PHYS | B_CALL | B_WRITE;
73 bp->b_dev = dev;
74 bp->b_iodone = physwakeup;
75 bp->b_data = uio->uio_iov[i].iov_base;
76 bp->b_bcount = uio->uio_iov[i].iov_len;
77 bp->b_offset = uio->uio_offset;
78 bp->b_saveaddr = sa;
79
80 /* Don't exceed drivers iosize limit */
81 if (bp->b_bcount > dev->si_iosize_max)
82 bp->b_bcount = dev->si_iosize_max;
83
84 /*
85 * Make sure the pbuf can map the request
86 * XXX: The pbuf has kvasize = MAXPHYS so a request
87 * XXX: larger than MAXPHYS - PAGE_SIZE must be
88 * XXX: page aligned or it will be fragmented.
89 */
90 iolen = ((vm_offset_t) bp->b_data) & PAGE_MASK;
91 if ((bp->b_bcount + iolen) > bp->b_kvasize) {
92 bp->b_bcount = bp->b_kvasize;
93 if (iolen != 0)
94 bp->b_bcount -= PAGE_SIZE;
95 }
96 bp->b_bufsize = bp->b_bcount;
97
98 blockno = bp->b_offset >> DEV_BSHIFT;
99 if ((daddr_t)blockno != blockno) {
100 error = EINVAL; /* blockno overflow */
101 goto doerror;
102 }
103 bp->b_blkno = blockno;
104
105 if (uio->uio_segflg == UIO_USERSPACE)
106 if (vmapbuf(bp) < 0) {
107 error = EFAULT;
108 goto doerror;
109 }
110
111 BUF_STRATEGY(bp, 0);
112 spl = splbio();
113 while ((bp->b_flags & B_DONE) == 0)
114 tsleep((caddr_t)bp, PRIBIO, "physstr", 0);
115 splx(spl);
116
117 if (uio->uio_segflg == UIO_USERSPACE)
118 vunmapbuf(bp);
119 iolen = bp->b_bcount - bp->b_resid;
120 if (iolen == 0 && !(bp->b_flags & B_ERROR))
121 goto doerror; /* EOF */
122 uio->uio_iov[i].iov_len -= iolen;
123 uio->uio_iov[i].iov_base += iolen;
124 uio->uio_resid -= iolen;
125 uio->uio_offset += iolen;
126 if( bp->b_flags & B_ERROR) {
127 error = bp->b_error;
128 goto doerror;
129 }
130 }
131 }
132doerror:
133 relpbuf(bp, NULL);
134 return (error);
135}