diff options
author | 2011-07-08 05:27:46 +0000 | |
---|---|---|
committer | 2011-07-08 05:27:46 +0000 | |
commit | e8fc709ea3ea14b26b1cc2af95b7d5a88a1910b3 (patch) | |
tree | e8b4f5cc066a3e32c7f2a3c3f7f03ead4ed4b370 | |
parent | We unconditionnally add -l to the daemon_flags, so fix our pexp (diff) | |
download | wireguard-openbsd-e8fc709ea3ea14b26b1cc2af95b7d5a88a1910b3.tar.xz wireguard-openbsd-e8fc709ea3ea14b26b1cc2af95b7d5a88a1910b3.zip |
Refactor vnd(4) to use vn_rdwr() instead of setting up the uio/iovec
structs and calling vn_lock+VOP_READ/WRITE+VOP_UNLOCK.
-rw-r--r-- | sys/dev/vnd.c | 89 |
1 files changed, 31 insertions, 58 deletions
diff --git a/sys/dev/vnd.c b/sys/dev/vnd.c index 60222a8cdd8..4babdd5a018 100644 --- a/sys/dev/vnd.c +++ b/sys/dev/vnd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vnd.c,v 1.144 2011/07/08 05:11:21 matthew Exp $ */ +/* $OpenBSD: vnd.c,v 1.145 2011/07/08 05:27:46 matthew Exp $ */ /* $NetBSD: vnd.c,v 1.26 1996/03/30 23:06:11 christos Exp $ */ /* @@ -267,11 +267,9 @@ vndstrategy(struct buf *bp) { int unit = DISKUNIT(bp->b_dev); struct vnd_softc *sc; - int s, part; - struct iovec aiov; - struct uio auio; - struct proc *p = curproc; - daddr64_t off; + struct partition *p; + size_t off; + int s; DNPRINTF(VDB_FOLLOW, "vndstrategy(%p): unit %d\n", bp, unit); @@ -289,42 +287,27 @@ vndstrategy(struct buf *bp) if (bounds_check_with_label(bp, sc->sc_dk.dk_label) == -1) goto done; - part = DISKPART(bp->b_dev); - off = DL_SECTOBLK(sc->sc_dk.dk_label, - DL_GETPOFFSET(&sc->sc_dk.dk_label->d_partitions[part])); - aiov.iov_base = bp->b_data; - auio.uio_resid = aiov.iov_len = bp->b_bcount; - auio.uio_iov = &aiov; - auio.uio_iovcnt = 1; - auio.uio_offset = dbtob((off_t)(bp->b_blkno + off)); - auio.uio_segflg = UIO_SYSSPACE; - auio.uio_procp = p; - - vn_lock(sc->sc_vp, LK_EXCLUSIVE | LK_RETRY, p); - if (bp->b_flags & B_READ) { - auio.uio_rw = UIO_READ; - bp->b_error = VOP_READ(sc->sc_vp, &auio, 0, - sc->sc_cred); - if (sc->sc_keyctx) - vndencryptbuf(sc, bp, 0); - } else { - if (sc->sc_keyctx) - vndencryptbuf(sc, bp, 1); - auio.uio_rw = UIO_WRITE; - /* - * Upper layer has already checked I/O for - * limits, so there is no need to do it again. - */ - bp->b_error = VOP_WRITE(sc->sc_vp, &auio, - IO_NOLIMIT, sc->sc_cred); - /* Data in buffer cache needs to be in clear */ - if (sc->sc_keyctx) - vndencryptbuf(sc, bp, 0); - } - VOP_UNLOCK(sc->sc_vp, 0, p); + p = &sc->sc_dk.dk_label->d_partitions[DISKPART(bp->b_dev)]; + off = DL_GETPOFFSET(p) * sc->sc_dk.dk_label->d_secsize + + (u_int64_t)bp->b_blkno * DEV_BSIZE; + + if (sc->sc_keyctx && !(bp->b_flags & B_READ)) + vndencryptbuf(sc, bp, 1); + + /* + * Use IO_NOLIMIT because upper layer has already checked I/O + * for limits, so there is no need to do it again. + */ + bp->b_error = vn_rdwr((bp->b_flags & B_READ) ? UIO_READ : UIO_WRITE, + sc->sc_vp, bp->b_data, bp->b_bcount, off, UIO_SYSSPACE, IO_NOLIMIT, + sc->sc_cred, &bp->b_resid, curproc); if (bp->b_error) bp->b_flags |= B_ERROR; - bp->b_resid = auio.uio_resid; + + /* Data in buffer cache needs to be in clear */ + if (sc->sc_keyctx) + vndencryptbuf(sc, bp, 0); + goto done; bad: @@ -613,29 +596,19 @@ vndioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p) int vndsetcred(struct vnd_softc *sc, struct ucred *cred) { - struct uio auio; - struct iovec aiov; - char *tmpbuf; + void *buf; + size_t size; int error; - struct proc *p = curproc; sc->sc_cred = crdup(cred); - tmpbuf = malloc(DEV_BSIZE, M_TEMP, M_WAITOK); + buf = malloc(DEV_BSIZE, M_TEMP, M_WAITOK); + size = MIN(DEV_BSIZE, sc->sc_size * sc->sc_secsize); /* XXX: Horrible kludge to establish credentials for NFS */ - aiov.iov_base = tmpbuf; - aiov.iov_len = MIN(DEV_BSIZE, sc->sc_size * sc->sc_secsize); - auio.uio_iov = &aiov; - auio.uio_iovcnt = 1; - auio.uio_offset = 0; - auio.uio_rw = UIO_READ; - auio.uio_segflg = UIO_SYSSPACE; - auio.uio_resid = aiov.iov_len; - vn_lock(sc->sc_vp, LK_RETRY | LK_EXCLUSIVE, p); - error = VOP_READ(sc->sc_vp, &auio, 0, sc->sc_cred); - VOP_UNLOCK(sc->sc_vp, 0, p); - - free(tmpbuf, M_TEMP); + error = vn_rdwr(UIO_READ, sc->sc_vp, buf, size, 0, UIO_SYSSPACE, 0, + sc->sc_cred, NULL, curproc); + + free(buf, M_TEMP); return (error); } |