2003-03-26 23:40:42 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2000-2003 Tor Egge
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-06-11 06:34:30 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2003-03-26 23:40:42 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/proc.h>
|
2003-04-29 13:36:06 +00:00
|
|
|
#include <sys/limits.h>
|
2003-03-26 23:40:42 +00:00
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/filio.h>
|
|
|
|
#include <sys/ttycom.h>
|
|
|
|
#include <sys/bio.h>
|
|
|
|
#include <sys/buf.h>
|
2013-03-09 02:32:23 +00:00
|
|
|
#include <sys/rwlock.h>
|
2003-08-16 06:15:17 +00:00
|
|
|
#include <ufs/ufs/extattr.h>
|
2003-03-26 23:40:42 +00:00
|
|
|
#include <ufs/ufs/quota.h>
|
|
|
|
#include <ufs/ufs/inode.h>
|
2003-08-16 06:15:17 +00:00
|
|
|
#include <ufs/ufs/ufsmount.h>
|
2003-08-18 17:27:08 +00:00
|
|
|
#include <ufs/ufs/ufs_extern.h>
|
2003-03-26 23:40:42 +00:00
|
|
|
#include <ufs/ffs/fs.h>
|
2005-02-08 16:25:50 +00:00
|
|
|
#include <ufs/ffs/ffs_extern.h>
|
2003-03-26 23:40:42 +00:00
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_extern.h>
|
|
|
|
#include <vm/vm_object.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
|
|
|
static int ffs_rawread_readahead(struct vnode *vp,
|
|
|
|
caddr_t udata,
|
|
|
|
off_t offset,
|
|
|
|
size_t len,
|
|
|
|
struct thread *td,
|
2015-07-23 19:13:41 +00:00
|
|
|
struct buf *bp);
|
2003-03-26 23:40:42 +00:00
|
|
|
static int ffs_rawread_main(struct vnode *vp,
|
|
|
|
struct uio *uio);
|
|
|
|
|
2008-02-25 18:45:57 +00:00
|
|
|
static int ffs_rawread_sync(struct vnode *vp);
|
2003-03-26 23:40:42 +00:00
|
|
|
|
|
|
|
int ffs_rawread(struct vnode *vp, struct uio *uio, int *workdone);
|
|
|
|
|
|
|
|
SYSCTL_DECL(_vfs_ffs);
|
|
|
|
|
|
|
|
static int ffsrawbufcnt = 4;
|
|
|
|
SYSCTL_INT(_vfs_ffs, OID_AUTO, ffsrawbufcnt, CTLFLAG_RD, &ffsrawbufcnt, 0,
|
|
|
|
"Buffers available for raw reads");
|
|
|
|
|
|
|
|
static int allowrawread = 1;
|
|
|
|
SYSCTL_INT(_vfs_ffs, OID_AUTO, allowrawread, CTLFLAG_RW, &allowrawread, 0,
|
|
|
|
"Flag to enable raw reads");
|
|
|
|
|
|
|
|
static int rawreadahead = 1;
|
|
|
|
SYSCTL_INT(_vfs_ffs, OID_AUTO, rawreadahead, CTLFLAG_RW, &rawreadahead, 0,
|
|
|
|
"Flag to enable readahead for long raw reads");
|
|
|
|
|
2014-06-08 10:55:06 +00:00
|
|
|
static void
|
|
|
|
ffs_rawread_setup(void *arg __unused)
|
2003-03-26 23:40:42 +00:00
|
|
|
{
|
2014-06-08 10:55:06 +00:00
|
|
|
|
2003-03-26 23:40:42 +00:00
|
|
|
ffsrawbufcnt = (nswbuf > 100 ) ? (nswbuf - (nswbuf >> 4)) : nswbuf - 8;
|
|
|
|
}
|
2014-06-08 10:55:06 +00:00
|
|
|
SYSINIT(ffs_raw, SI_SUB_VM_CONF, SI_ORDER_ANY, ffs_rawread_setup, NULL);
|
2003-03-26 23:40:42 +00:00
|
|
|
|
|
|
|
static int
|
2008-02-25 18:45:57 +00:00
|
|
|
ffs_rawread_sync(struct vnode *vp)
|
2003-03-26 23:40:42 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
int upgraded;
|
2004-10-25 09:14:03 +00:00
|
|
|
struct bufobj *bo;
|
2006-03-02 22:13:28 +00:00
|
|
|
struct mount *mp;
|
2009-12-21 12:29:38 +00:00
|
|
|
vm_object_t obj;
|
2003-03-26 23:40:42 +00:00
|
|
|
|
|
|
|
/* Check for dirty mmap, pending writes and dirty buffers */
|
2004-10-25 09:14:03 +00:00
|
|
|
bo = &vp->v_bufobj;
|
2008-03-22 09:15:16 +00:00
|
|
|
BO_LOCK(bo);
|
|
|
|
VI_LOCK(vp);
|
2004-10-25 09:14:03 +00:00
|
|
|
if (bo->bo_numoutput > 0 ||
|
2004-10-26 09:04:20 +00:00
|
|
|
bo->bo_dirty.bv_cnt > 0 ||
|
2009-12-21 12:29:38 +00:00
|
|
|
((obj = vp->v_object) != NULL &&
|
|
|
|
(obj->flags & OBJ_MIGHTBEDIRTY) != 0)) {
|
2003-03-26 23:40:42 +00:00
|
|
|
VI_UNLOCK(vp);
|
2008-03-22 09:15:16 +00:00
|
|
|
BO_UNLOCK(bo);
|
2003-03-26 23:40:42 +00:00
|
|
|
|
2006-03-02 22:13:28 +00:00
|
|
|
if (vn_start_write(vp, &mp, V_NOWAIT) != 0) {
|
2008-02-25 18:45:57 +00:00
|
|
|
if (VOP_ISLOCKED(vp) != LK_EXCLUSIVE)
|
2006-03-02 22:13:28 +00:00
|
|
|
upgraded = 1;
|
|
|
|
else
|
|
|
|
upgraded = 0;
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(vp, 0);
|
2006-03-02 22:13:28 +00:00
|
|
|
(void) vn_start_write(vp, &mp, V_WAIT);
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_LOCK(vp, LK_EXCLUSIVE);
|
2008-02-25 18:45:57 +00:00
|
|
|
} else if (VOP_ISLOCKED(vp) != LK_EXCLUSIVE) {
|
2003-03-26 23:40:42 +00:00
|
|
|
upgraded = 1;
|
|
|
|
/* Upgrade to exclusive lock, this might block */
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_LOCK(vp, LK_UPGRADE);
|
2003-03-26 23:40:42 +00:00
|
|
|
} else
|
|
|
|
upgraded = 0;
|
|
|
|
|
|
|
|
|
|
|
|
VI_LOCK(vp);
|
2006-05-05 21:27:31 +00:00
|
|
|
/* Check if vnode was reclaimed while unlocked. */
|
|
|
|
if ((vp->v_iflag & VI_DOOMED) != 0) {
|
|
|
|
VI_UNLOCK(vp);
|
|
|
|
if (upgraded != 0)
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_LOCK(vp, LK_DOWNGRADE);
|
2006-05-05 21:27:31 +00:00
|
|
|
vn_finished_write(mp);
|
|
|
|
return (EIO);
|
|
|
|
}
|
|
|
|
/* Attempt to msync mmap() regions to clean dirty mmap */
|
2009-12-21 12:29:38 +00:00
|
|
|
if ((obj = vp->v_object) != NULL &&
|
|
|
|
(obj->flags & OBJ_MIGHTBEDIRTY) != 0) {
|
2003-03-26 23:40:42 +00:00
|
|
|
VI_UNLOCK(vp);
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_WLOCK(obj);
|
2009-12-21 12:29:38 +00:00
|
|
|
vm_object_page_clean(obj, 0, 0, OBJPC_SYNC);
|
2013-03-09 02:32:23 +00:00
|
|
|
VM_OBJECT_WUNLOCK(obj);
|
2008-03-22 09:15:16 +00:00
|
|
|
} else
|
|
|
|
VI_UNLOCK(vp);
|
2003-03-26 23:40:42 +00:00
|
|
|
|
|
|
|
/* Wait for pending writes to complete */
|
2008-03-22 09:15:16 +00:00
|
|
|
BO_LOCK(bo);
|
2004-10-25 09:14:03 +00:00
|
|
|
error = bufobj_wwait(&vp->v_bufobj, 0, 0);
|
|
|
|
if (error != 0) {
|
|
|
|
/* XXX: can't happen with a zero timeout ??? */
|
2008-03-22 09:15:16 +00:00
|
|
|
BO_UNLOCK(bo);
|
2004-10-25 09:14:03 +00:00
|
|
|
if (upgraded != 0)
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_LOCK(vp, LK_DOWNGRADE);
|
2006-05-05 21:27:31 +00:00
|
|
|
vn_finished_write(mp);
|
2004-10-25 09:14:03 +00:00
|
|
|
return (error);
|
2003-03-26 23:40:42 +00:00
|
|
|
}
|
|
|
|
/* Flush dirty buffers */
|
2004-10-26 09:04:20 +00:00
|
|
|
if (bo->bo_dirty.bv_cnt > 0) {
|
2008-03-22 09:15:16 +00:00
|
|
|
BO_UNLOCK(bo);
|
2012-03-25 00:02:37 +00:00
|
|
|
if ((error = ffs_syncvnode(vp, MNT_WAIT, 0)) != 0) {
|
2003-03-26 23:40:42 +00:00
|
|
|
if (upgraded != 0)
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_LOCK(vp, LK_DOWNGRADE);
|
2006-05-05 21:27:31 +00:00
|
|
|
vn_finished_write(mp);
|
2003-03-26 23:40:42 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2008-03-22 09:15:16 +00:00
|
|
|
BO_LOCK(bo);
|
2004-10-26 09:04:20 +00:00
|
|
|
if (bo->bo_numoutput > 0 || bo->bo_dirty.bv_cnt > 0)
|
2003-03-26 23:40:42 +00:00
|
|
|
panic("ffs_rawread_sync: dirty bufs");
|
|
|
|
}
|
2008-03-22 09:15:16 +00:00
|
|
|
BO_UNLOCK(bo);
|
2003-03-26 23:40:42 +00:00
|
|
|
if (upgraded != 0)
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_LOCK(vp, LK_DOWNGRADE);
|
2006-03-02 22:13:28 +00:00
|
|
|
vn_finished_write(mp);
|
2003-03-26 23:40:42 +00:00
|
|
|
} else {
|
|
|
|
VI_UNLOCK(vp);
|
2008-03-22 09:15:16 +00:00
|
|
|
BO_UNLOCK(bo);
|
2003-03-26 23:40:42 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
ffs_rawread_readahead(struct vnode *vp,
|
|
|
|
caddr_t udata,
|
|
|
|
off_t offset,
|
|
|
|
size_t len,
|
|
|
|
struct thread *td,
|
2015-07-23 19:13:41 +00:00
|
|
|
struct buf *bp)
|
2003-03-26 23:40:42 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
u_int iolen;
|
|
|
|
off_t blockno;
|
|
|
|
int blockoff;
|
|
|
|
int bsize;
|
|
|
|
struct vnode *dp;
|
|
|
|
int bforwards;
|
2003-08-17 19:26:03 +00:00
|
|
|
struct inode *ip;
|
|
|
|
ufs2_daddr_t blkno;
|
2003-03-26 23:40:42 +00:00
|
|
|
|
|
|
|
bsize = vp->v_mount->mnt_stat.f_iosize;
|
|
|
|
|
2003-08-17 19:26:03 +00:00
|
|
|
ip = VTOI(vp);
|
2016-09-17 16:47:34 +00:00
|
|
|
dp = ITODEVVP(ip);
|
2003-08-17 19:26:03 +00:00
|
|
|
|
2003-03-26 23:40:42 +00:00
|
|
|
iolen = ((vm_offset_t) udata) & PAGE_MASK;
|
|
|
|
bp->b_bcount = len;
|
|
|
|
if (bp->b_bcount + iolen > bp->b_kvasize) {
|
|
|
|
bp->b_bcount = bp->b_kvasize;
|
|
|
|
if (iolen != 0)
|
|
|
|
bp->b_bcount -= PAGE_SIZE;
|
|
|
|
}
|
2003-11-15 09:28:09 +00:00
|
|
|
bp->b_flags = 0; /* XXX necessary ? */
|
2003-03-26 23:40:42 +00:00
|
|
|
bp->b_iocmd = BIO_READ;
|
2005-04-30 11:28:19 +00:00
|
|
|
bp->b_iodone = bdone;
|
2003-03-26 23:40:42 +00:00
|
|
|
bp->b_data = udata;
|
2003-10-22 18:57:59 +00:00
|
|
|
blockno = offset / bsize;
|
|
|
|
blockoff = (offset % bsize) / DEV_BSIZE;
|
2003-03-26 23:40:42 +00:00
|
|
|
if ((daddr_t) blockno != blockno) {
|
|
|
|
return EINVAL; /* blockno overflow */
|
|
|
|
}
|
|
|
|
|
|
|
|
bp->b_lblkno = bp->b_blkno = blockno;
|
|
|
|
|
2003-08-17 19:26:03 +00:00
|
|
|
error = ufs_bmaparray(vp, bp->b_lblkno, &blkno, NULL, &bforwards, NULL);
|
|
|
|
if (error != 0)
|
2003-03-26 23:40:42 +00:00
|
|
|
return error;
|
2003-10-22 18:57:59 +00:00
|
|
|
if (blkno == -1) {
|
2003-03-26 23:40:42 +00:00
|
|
|
|
|
|
|
/* Fill holes with NULs to preserve semantics */
|
|
|
|
|
|
|
|
if (bp->b_bcount + blockoff * DEV_BSIZE > bsize)
|
|
|
|
bp->b_bcount = bsize - blockoff * DEV_BSIZE;
|
|
|
|
bp->b_bufsize = bp->b_bcount;
|
|
|
|
|
2013-03-19 14:43:57 +00:00
|
|
|
if (vmapbuf(bp, 1) < 0)
|
2003-03-26 23:40:42 +00:00
|
|
|
return EFAULT;
|
|
|
|
|
2011-02-02 16:35:10 +00:00
|
|
|
maybe_yield();
|
2003-03-26 23:40:42 +00:00
|
|
|
bzero(bp->b_data, bp->b_bufsize);
|
|
|
|
|
|
|
|
/* Mark operation completed (similar to bufdone()) */
|
|
|
|
|
|
|
|
bp->b_resid = 0;
|
|
|
|
bp->b_flags |= B_DONE;
|
|
|
|
return 0;
|
|
|
|
}
|
2003-10-22 18:57:59 +00:00
|
|
|
bp->b_blkno = blkno + blockoff;
|
|
|
|
bp->b_offset = bp->b_iooffset = (blkno + blockoff) * DEV_BSIZE;
|
2003-03-26 23:40:42 +00:00
|
|
|
|
|
|
|
if (bp->b_bcount + blockoff * DEV_BSIZE > bsize * (1 + bforwards))
|
|
|
|
bp->b_bcount = bsize * (1 + bforwards) - blockoff * DEV_BSIZE;
|
|
|
|
bp->b_bufsize = bp->b_bcount;
|
|
|
|
|
2013-03-19 14:43:57 +00:00
|
|
|
if (vmapbuf(bp, 1) < 0)
|
2003-03-26 23:40:42 +00:00
|
|
|
return EFAULT;
|
|
|
|
|
2005-01-11 09:10:46 +00:00
|
|
|
BO_STRATEGY(&dp->v_bufobj, bp);
|
2003-03-26 23:40:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
ffs_rawread_main(struct vnode *vp,
|
|
|
|
struct uio *uio)
|
|
|
|
{
|
|
|
|
int error, nerror;
|
|
|
|
struct buf *bp, *nbp, *tbp;
|
|
|
|
u_int iolen;
|
|
|
|
caddr_t udata;
|
|
|
|
long resid;
|
|
|
|
off_t offset;
|
|
|
|
struct thread *td;
|
|
|
|
|
|
|
|
td = uio->uio_td ? uio->uio_td : curthread;
|
|
|
|
udata = uio->uio_iov->iov_base;
|
|
|
|
resid = uio->uio_resid;
|
|
|
|
offset = uio->uio_offset;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* keep the process from being swapped
|
|
|
|
*/
|
|
|
|
PHOLD(td->td_proc);
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
nerror = 0;
|
|
|
|
|
|
|
|
bp = NULL;
|
|
|
|
nbp = NULL;
|
|
|
|
|
|
|
|
while (resid > 0) {
|
|
|
|
|
|
|
|
if (bp == NULL) { /* Setup first read */
|
|
|
|
/* XXX: Leave some bufs for swap */
|
|
|
|
bp = getpbuf(&ffsrawbufcnt);
|
2007-02-04 23:42:02 +00:00
|
|
|
pbgetvp(vp, bp);
|
2003-03-26 23:40:42 +00:00
|
|
|
error = ffs_rawread_readahead(vp, udata, offset,
|
2015-07-23 19:13:41 +00:00
|
|
|
resid, td, bp);
|
2003-03-26 23:40:42 +00:00
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (resid > bp->b_bufsize) { /* Setup fist readahead */
|
|
|
|
/* XXX: Leave bufs for swap */
|
|
|
|
if (rawreadahead != 0)
|
|
|
|
nbp = trypbuf(&ffsrawbufcnt);
|
|
|
|
else
|
|
|
|
nbp = NULL;
|
|
|
|
if (nbp != NULL) {
|
2007-02-04 23:42:02 +00:00
|
|
|
pbgetvp(vp, nbp);
|
2003-03-26 23:40:42 +00:00
|
|
|
|
|
|
|
nerror = ffs_rawread_readahead(vp,
|
|
|
|
udata +
|
|
|
|
bp->b_bufsize,
|
|
|
|
offset +
|
|
|
|
bp->b_bufsize,
|
|
|
|
resid -
|
|
|
|
bp->b_bufsize,
|
|
|
|
td,
|
2015-07-23 19:13:41 +00:00
|
|
|
nbp);
|
2003-03-26 23:40:42 +00:00
|
|
|
if (nerror) {
|
2007-02-04 23:42:02 +00:00
|
|
|
pbrelvp(nbp);
|
2003-03-26 23:40:42 +00:00
|
|
|
relpbuf(nbp, &ffsrawbufcnt);
|
|
|
|
nbp = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-27 19:28:11 +00:00
|
|
|
bwait(bp, PRIBIO, "rawrd");
|
2003-03-26 23:40:42 +00:00
|
|
|
vunmapbuf(bp);
|
|
|
|
|
|
|
|
iolen = bp->b_bcount - bp->b_resid;
|
|
|
|
if (iolen == 0 && (bp->b_ioflags & BIO_ERROR) == 0) {
|
|
|
|
nerror = 0; /* Ignore possible beyond EOF error */
|
|
|
|
break; /* EOF */
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((bp->b_ioflags & BIO_ERROR) != 0) {
|
|
|
|
error = bp->b_error;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
resid -= iolen;
|
|
|
|
udata += iolen;
|
|
|
|
offset += iolen;
|
|
|
|
if (iolen < bp->b_bufsize) {
|
|
|
|
/* Incomplete read. Try to read remaining part */
|
|
|
|
error = ffs_rawread_readahead(vp,
|
|
|
|
udata,
|
|
|
|
offset,
|
|
|
|
bp->b_bufsize - iolen,
|
|
|
|
td,
|
2015-07-23 19:13:41 +00:00
|
|
|
bp);
|
2003-03-26 23:40:42 +00:00
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
} else if (nbp != NULL) { /* Complete read with readahead */
|
|
|
|
|
|
|
|
tbp = bp;
|
|
|
|
bp = nbp;
|
|
|
|
nbp = tbp;
|
|
|
|
|
|
|
|
if (resid <= bp->b_bufsize) { /* No more readaheads */
|
2007-02-04 23:42:02 +00:00
|
|
|
pbrelvp(nbp);
|
2003-03-26 23:40:42 +00:00
|
|
|
relpbuf(nbp, &ffsrawbufcnt);
|
|
|
|
nbp = NULL;
|
|
|
|
} else { /* Setup next readahead */
|
|
|
|
nerror = ffs_rawread_readahead(vp,
|
|
|
|
udata +
|
|
|
|
bp->b_bufsize,
|
|
|
|
offset +
|
|
|
|
bp->b_bufsize,
|
|
|
|
resid -
|
|
|
|
bp->b_bufsize,
|
|
|
|
td,
|
2015-07-23 19:13:41 +00:00
|
|
|
nbp);
|
2003-03-26 23:40:42 +00:00
|
|
|
if (nerror != 0) {
|
2007-02-04 23:42:02 +00:00
|
|
|
pbrelvp(nbp);
|
2003-03-26 23:40:42 +00:00
|
|
|
relpbuf(nbp, &ffsrawbufcnt);
|
|
|
|
nbp = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (nerror != 0) {/* Deferred Readahead error */
|
|
|
|
break;
|
|
|
|
} else if (resid > 0) { /* More to read, no readahead */
|
|
|
|
error = ffs_rawread_readahead(vp, udata, offset,
|
2015-07-23 19:13:41 +00:00
|
|
|
resid, td, bp);
|
2003-03-26 23:40:42 +00:00
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-04 23:42:02 +00:00
|
|
|
if (bp != NULL) {
|
|
|
|
pbrelvp(bp);
|
2003-03-26 23:40:42 +00:00
|
|
|
relpbuf(bp, &ffsrawbufcnt);
|
2007-02-04 23:42:02 +00:00
|
|
|
}
|
2003-03-26 23:40:42 +00:00
|
|
|
if (nbp != NULL) { /* Run down readahead buffer */
|
2003-03-27 19:28:11 +00:00
|
|
|
bwait(nbp, PRIBIO, "rawrd");
|
2003-03-26 23:40:42 +00:00
|
|
|
vunmapbuf(nbp);
|
2007-02-04 23:42:02 +00:00
|
|
|
pbrelvp(nbp);
|
2003-03-26 23:40:42 +00:00
|
|
|
relpbuf(nbp, &ffsrawbufcnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error == 0)
|
|
|
|
error = nerror;
|
|
|
|
PRELE(td->td_proc);
|
|
|
|
uio->uio_iov->iov_base = udata;
|
|
|
|
uio->uio_resid = resid;
|
|
|
|
uio->uio_offset = offset;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
ffs_rawread(struct vnode *vp,
|
|
|
|
struct uio *uio,
|
|
|
|
int *workdone)
|
|
|
|
{
|
|
|
|
if (allowrawread != 0 &&
|
|
|
|
uio->uio_iovcnt == 1 &&
|
|
|
|
uio->uio_segflg == UIO_USERSPACE &&
|
|
|
|
uio->uio_resid == uio->uio_iov->iov_len &&
|
2004-06-03 01:47:37 +00:00
|
|
|
(((uio->uio_td != NULL) ? uio->uio_td : curthread)->td_pflags &
|
|
|
|
TDP_DEADLKTREAT) == 0) {
|
2003-03-26 23:40:42 +00:00
|
|
|
int secsize; /* Media sector size */
|
|
|
|
off_t filebytes; /* Bytes left of file */
|
|
|
|
int blockbytes; /* Bytes left of file in full blocks */
|
|
|
|
int partialbytes; /* Bytes in last partial block */
|
|
|
|
int skipbytes; /* Bytes not to read in ffs_rawread */
|
|
|
|
struct inode *ip;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
|
|
/* Only handle sector aligned reads */
|
|
|
|
ip = VTOI(vp);
|
2016-09-17 16:47:34 +00:00
|
|
|
secsize = ITODEVVP(ip)->v_bufobj.bo_bsize;
|
2003-03-26 23:40:42 +00:00
|
|
|
if ((uio->uio_offset & (secsize - 1)) == 0 &&
|
|
|
|
(uio->uio_resid & (secsize - 1)) == 0) {
|
|
|
|
|
|
|
|
/* Sync dirty pages and buffers if needed */
|
2008-02-25 18:45:57 +00:00
|
|
|
error = ffs_rawread_sync(vp);
|
2003-03-26 23:40:42 +00:00
|
|
|
if (error != 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
/* Check for end of file */
|
|
|
|
if (ip->i_size > uio->uio_offset) {
|
|
|
|
filebytes = ip->i_size - uio->uio_offset;
|
|
|
|
|
|
|
|
/* No special eof handling needed ? */
|
|
|
|
if (uio->uio_resid <= filebytes) {
|
|
|
|
*workdone = 1;
|
|
|
|
return ffs_rawread_main(vp, uio);
|
|
|
|
}
|
|
|
|
|
|
|
|
partialbytes = ((unsigned int) ip->i_size) %
|
2016-09-17 16:47:34 +00:00
|
|
|
ITOFS(ip)->fs_bsize;
|
2003-03-26 23:40:42 +00:00
|
|
|
blockbytes = (int) filebytes - partialbytes;
|
|
|
|
if (blockbytes > 0) {
|
|
|
|
skipbytes = uio->uio_resid -
|
|
|
|
blockbytes;
|
|
|
|
uio->uio_resid = blockbytes;
|
|
|
|
error = ffs_rawread_main(vp, uio);
|
|
|
|
uio->uio_resid += skipbytes;
|
|
|
|
if (error != 0)
|
|
|
|
return error;
|
|
|
|
/* Read remaining part using buffer */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*workdone = 0;
|
|
|
|
return 0;
|
|
|
|
}
|