use ufs_balloc_range() rather than local (mostly identical, but with some
bugs) ext2fs variant
This commit is contained in:
parent
2cbb8bc3bf
commit
a120eaa3ea
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ext2fs_balloc.c,v 1.17 2002/05/05 17:01:41 chs Exp $ */
|
||||
/* $NetBSD: ext2fs_balloc.c,v 1.18 2002/09/26 11:06:36 jdolecek Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Manuel Bouyer.
|
||||
@ -38,7 +38,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ext2fs_balloc.c,v 1.17 2002/05/05 17:01:41 chs Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ext2fs_balloc.c,v 1.18 2002/09/26 11:06:36 jdolecek Exp $");
|
||||
|
||||
#if defined(_KERNEL_OPT)
|
||||
#include "opt_uvmhist.h"
|
||||
@ -368,97 +368,3 @@ ext2fs_gop_alloc(struct vnode *vp, off_t off, off_t len, int flags,
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* allocate a range of blocks in a file.
|
||||
* after this function returns, any page entirely contained within the range
|
||||
* will map to invalid data and thus must be overwritten before it is made
|
||||
* accessible to others.
|
||||
*/
|
||||
|
||||
int
|
||||
ext2fs_balloc_range(vp, off, len, cred, flags)
|
||||
struct vnode *vp;
|
||||
off_t off, len;
|
||||
struct ucred *cred;
|
||||
int flags;
|
||||
{
|
||||
off_t oldeof, eof, pagestart;
|
||||
struct genfs_node *gp = VTOG(vp);
|
||||
int i, delta, error, npages;
|
||||
int bshift = vp->v_mount->mnt_fs_bshift;
|
||||
int bsize = 1 << bshift;
|
||||
int ppb = max(bsize >> PAGE_SHIFT, 1);
|
||||
struct vm_page *pgs[ppb];
|
||||
UVMHIST_FUNC("ext2fs_balloc_range"); UVMHIST_CALLED(ubchist);
|
||||
UVMHIST_LOG(ubchist, "vp %p off 0x%x len 0x%x u_size 0x%x",
|
||||
vp, off, len, vp->v_size);
|
||||
|
||||
oldeof = vp->v_size;
|
||||
eof = MAX(oldeof, off + len);
|
||||
UVMHIST_LOG(ubchist, "new eof 0x%x", eof,0,0,0);
|
||||
pgs[0] = NULL;
|
||||
|
||||
/*
|
||||
* cache the new range of the file. this will create zeroed pages
|
||||
* where the new block will be and keep them locked until the
|
||||
* new block is allocated, so there will be no window where
|
||||
* the old contents of the new block is visible to racing threads.
|
||||
*/
|
||||
|
||||
pagestart = trunc_page(off) & ~(bsize - 1);
|
||||
npages = MIN(ppb, (round_page(eof) - pagestart) >> PAGE_SHIFT);
|
||||
memset(pgs, 0, npages * sizeof(struct vm_page *));
|
||||
simple_lock(&vp->v_interlock);
|
||||
error = VOP_GETPAGES(vp, pagestart, pgs, &npages, 0,
|
||||
VM_PROT_READ, 0, PGO_SYNCIO | PGO_PASTEOF);
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
for (i = 0; i < npages; i++) {
|
||||
UVMHIST_LOG(ubchist, "got pgs[%d] %p", i, pgs[i],0,0);
|
||||
KASSERT((pgs[i]->flags & PG_RELEASED) == 0);
|
||||
pgs[i]->flags &= ~PG_CLEAN;
|
||||
uvm_pageactivate(pgs[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
* adjust off to be block-aligned.
|
||||
*/
|
||||
|
||||
delta = off & (bsize - 1);
|
||||
off -= delta;
|
||||
len += delta;
|
||||
|
||||
/*
|
||||
* now allocate the range.
|
||||
*/
|
||||
|
||||
lockmgr(&gp->g_glock, LK_EXCLUSIVE, NULL);
|
||||
error = GOP_ALLOC(vp, off, len, flags, cred);
|
||||
UVMHIST_LOG(ubchist, "alloc %d", error,0,0,0);
|
||||
lockmgr(&gp->g_glock, LK_RELEASE, NULL);
|
||||
|
||||
/*
|
||||
* clear PG_RDONLY on any pages we are holding
|
||||
* (since they now have backing store) and unbusy them.
|
||||
* if we got an error, free any pages we created past the old eob.
|
||||
*/
|
||||
|
||||
simple_lock(&vp->v_interlock);
|
||||
for (i = 0; i < npages; i++) {
|
||||
pgs[i]->flags &= ~PG_RDONLY;
|
||||
if (error) {
|
||||
pgs[i]->flags |= PG_RELEASED;
|
||||
}
|
||||
}
|
||||
if (error) {
|
||||
uvm_lock_pageq();
|
||||
uvm_page_unbusy(pgs, npages);
|
||||
uvm_unlock_pageq();
|
||||
} else {
|
||||
uvm_page_unbusy(pgs, npages);
|
||||
}
|
||||
simple_unlock(&vp->v_interlock);
|
||||
return (error);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ext2fs_extern.h,v 1.11 2001/09/15 20:36:41 chs Exp $ */
|
||||
/* $NetBSD: ext2fs_extern.h,v 1.12 2002/09/26 11:06:36 jdolecek Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997 Manuel Bouyer.
|
||||
@ -72,8 +72,6 @@ int ext2fs_vfree __P((void *));
|
||||
int ext2fs_balloc __P((struct inode *, ufs_daddr_t, int, struct ucred *,
|
||||
struct buf **, int));
|
||||
int ext2fs_gop_alloc __P((struct vnode *, off_t, off_t, int, struct ucred *));
|
||||
int ext2fs_balloc_range __P((struct vnode *, off_t, off_t, struct ucred *,
|
||||
int));
|
||||
|
||||
/* ext2fs_bmap.c */
|
||||
int ext2fs_bmap __P((void *));
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ext2fs_inode.c,v 1.27 2001/11/08 02:39:07 lukem Exp $ */
|
||||
/* $NetBSD: ext2fs_inode.c,v 1.28 2002/09/26 11:06:36 jdolecek Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Manuel Bouyer.
|
||||
@ -38,7 +38,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ext2fs_inode.c,v 1.27 2001/11/08 02:39:07 lukem Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ext2fs_inode.c,v 1.28 2002/09/26 11:06:36 jdolecek Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
@ -236,7 +236,7 @@ ext2fs_truncate(v)
|
||||
if (length > fs->fs_maxfilesize)
|
||||
return (EFBIG);
|
||||
#endif
|
||||
ext2fs_balloc_range(ovp, length - 1, 1, ap->a_cred,
|
||||
ufs_balloc_range(ovp, length - 1, 1, ap->a_cred,
|
||||
ap->a_flags & IO_SYNC ? B_SYNC : 0);
|
||||
oip->i_flag |= IN_CHANGE | IN_UPDATE;
|
||||
return (VOP_UPDATE(ovp, NULL, NULL, 1));
|
||||
|
Loading…
Reference in New Issue
Block a user