1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1982, 1986, 1989, 1993
|
|
|
|
* The Regents of the University of California. 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
|
|
|
*
|
1997-02-10 02:22:35 +00:00
|
|
|
* @(#)ffs_inode.c 8.13 (Berkeley) 4/21/95
|
1999-01-06 18:18:06 +00:00
|
|
|
* $Id: ffs_inode.c,v 1.50 1999/01/06 16:52:38 bde Exp $
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
|
1996-01-05 18:31:58 +00:00
|
|
|
#include "opt_quota.h"
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/resourcevar.h>
|
|
|
|
|
|
|
|
#include <vm/vm.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/vm_extern.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
#include <ufs/ufs/quota.h>
|
1997-10-16 20:32:40 +00:00
|
|
|
#include <ufs/ufs/ufsmount.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <ufs/ufs/inode.h>
|
1998-07-03 18:46:52 +00:00
|
|
|
#include <ufs/ufs/ufs_extern.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
#include <ufs/ffs/fs.h>
|
|
|
|
#include <ufs/ffs/ffs_extern.h>
|
|
|
|
|
1997-02-10 02:22:35 +00:00
|
|
|
static int ffs_indirtrunc __P((struct inode *, ufs_daddr_t, ufs_daddr_t,
|
|
|
|
ufs_daddr_t, int, long *));
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the access, modified, and inode change times as specified by the
|
1998-07-03 22:17:03 +00:00
|
|
|
* IN_ACCESS, IN_UPDATE, and IN_CHANGE flags respectively. Write the inode
|
|
|
|
* to disk if the IN_MODIFIED flag is set (it may be set initially, or by
|
|
|
|
* the timestamp update). The IN_LAZYMOD flag is set to force a write
|
|
|
|
* later if not now. If we write now, then clear both IN_MODIFIED and
|
|
|
|
* IN_LAZYMOD to reflect the presumably successful write, and if waitfor is
|
|
|
|
* set, then wait for the write to complete.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
int
|
1997-10-16 20:32:40 +00:00
|
|
|
ffs_update(vp, access, modify, waitfor)
|
|
|
|
struct vnode *vp;
|
|
|
|
struct timeval *access;
|
|
|
|
struct timeval *modify;
|
|
|
|
int waitfor;
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
|
|
|
register struct fs *fs;
|
|
|
|
struct buf *bp;
|
|
|
|
struct inode *ip;
|
|
|
|
int error;
|
|
|
|
|
1999-01-06 16:52:38 +00:00
|
|
|
ufs_itimes(vp);
|
1997-10-16 20:32:40 +00:00
|
|
|
ip = VTOI(vp);
|
1999-01-06 18:18:06 +00:00
|
|
|
if ((ip->i_flag & IN_MODIFIED) == 0 && waitfor == 0)
|
1994-05-24 10:09:53 +00:00
|
|
|
return (0);
|
1998-07-03 22:17:03 +00:00
|
|
|
ip->i_flag &= ~(IN_LAZYMOD | IN_MODIFIED);
|
1998-07-03 18:46:52 +00:00
|
|
|
if (vp->v_mount->mnt_flag & MNT_RDONLY)
|
1994-05-24 10:09:53 +00:00
|
|
|
return (0);
|
|
|
|
fs = ip->i_fs;
|
|
|
|
/*
|
|
|
|
* Ensure that uid and gid are correct. This is a temporary
|
|
|
|
* fix until fsck has been changed to do the update.
|
|
|
|
*/
|
|
|
|
if (fs->fs_inodefmt < FS_44INODEFMT) { /* XXX */
|
|
|
|
ip->i_din.di_ouid = ip->i_uid; /* XXX */
|
|
|
|
ip->i_din.di_ogid = ip->i_gid; /* XXX */
|
|
|
|
} /* XXX */
|
1994-10-10 01:04:55 +00:00
|
|
|
error = bread(ip->i_devvp, fsbtodb(fs, ino_to_fsba(fs, ip->i_number)),
|
|
|
|
(int)fs->fs_bsize, NOCRED, &bp);
|
|
|
|
if (error) {
|
1994-05-24 10:09:53 +00:00
|
|
|
brelse(bp);
|
|
|
|
return (error);
|
|
|
|
}
|
1998-03-08 09:59:44 +00:00
|
|
|
if (DOINGSOFTDEP(vp))
|
|
|
|
softdep_update_inodeblock(ip, bp, waitfor);
|
|
|
|
else if (ip->i_effnlink != ip->i_nlink)
|
|
|
|
panic("ffs_update: bad link cnt");
|
1994-05-24 10:09:53 +00:00
|
|
|
*((struct dinode *)bp->b_data +
|
|
|
|
ino_to_fsbo(fs, ip->i_number)) = ip->i_din;
|
1998-03-08 09:59:44 +00:00
|
|
|
if (waitfor && (vp->v_mount->mnt_flag & MNT_ASYNC) == 0) {
|
1994-05-24 10:09:53 +00:00
|
|
|
return (bwrite(bp));
|
1998-03-08 09:59:44 +00:00
|
|
|
} else {
|
Make our v_usecount vnode reference count work identically to the
original BSD code. The association between the vnode and the vm_object
no longer includes reference counts. The major difference is that
vm_object's are no longer freed gratuitiously from the vnode, and so
once an object is created for the vnode, it will last as long as the
vnode does.
When a vnode object reference count is incremented, then the underlying
vnode reference count is incremented also. The two "objects" are now
more intimately related, and so the interactions are now much less
complex.
When vnodes are now normally placed onto the free queue with an object still
attached. The rundown of the object happens at vnode rundown time, and
happens with exactly the same filesystem semantics of the original VFS
code. There is absolutely no need for vnode_pager_uncache and other
travesties like that anymore.
A side-effect of these changes is that SMP locking should be much simpler,
the I/O copyin/copyout optimizations work, NFS should be more ponderable,
and further work on layered filesystems should be less frustrating, because
of the totally coherent management of the vnode objects and vnodes.
Please be careful with your system while running this code, but I would
greatly appreciate feedback as soon a reasonably possible.
1998-01-06 05:26:17 +00:00
|
|
|
if (bp->b_bufsize == fs->fs_bsize)
|
|
|
|
bp->b_flags |= B_CLUSTEROK;
|
1994-05-24 10:09:53 +00:00
|
|
|
bdwrite(bp);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SINGLE 0 /* index of single indirect block */
|
|
|
|
#define DOUBLE 1 /* index of double indirect block */
|
|
|
|
#define TRIPLE 2 /* index of triple indirect block */
|
|
|
|
/*
|
|
|
|
* Truncate the inode oip to at most length size, freeing the
|
|
|
|
* disk blocks.
|
|
|
|
*/
|
1994-05-25 09:21:21 +00:00
|
|
|
int
|
VFS mega cleanup commit (x/N)
1. Add new file "sys/kern/vfs_default.c" where default actions for
VOPs go. Implement proper defaults for ABORTOP, BWRITE, LEASE,
POLL, REVOKE and STRATEGY. Various stuff spread over the entire
tree belongs here.
2. Change VOP_BLKATOFF to a normal function in cd9660.
3. Kill VOP_BLKATOFF, VOP_TRUNCATE, VOP_VFREE, VOP_VALLOC. These
are private interface functions between UFS and the underlying
storage manager layer (FFS/LFS/MFS/EXT2FS). The functions now
live in struct ufsmount instead.
4. Remove a kludge of VOP_ functions in all filesystems, that did
nothing but obscure the simplicity and break the expandability.
If a filesystem doesn't implement VOP_FOO, it shouldn't have an
entry for it in its vnops table. The system will try to DTRT
if it is not implemented. There are still some cruft left, but
the bulk of it is done.
5. Fix another VCALL in vfs_cache.c (thanks Bruce!)
1997-10-16 10:50:27 +00:00
|
|
|
ffs_truncate(vp, length, flags, cred, p)
|
|
|
|
struct vnode *vp;
|
|
|
|
off_t length;
|
|
|
|
int flags;
|
|
|
|
struct ucred *cred;
|
|
|
|
struct proc *p;
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
VFS mega cleanup commit (x/N)
1. Add new file "sys/kern/vfs_default.c" where default actions for
VOPs go. Implement proper defaults for ABORTOP, BWRITE, LEASE,
POLL, REVOKE and STRATEGY. Various stuff spread over the entire
tree belongs here.
2. Change VOP_BLKATOFF to a normal function in cd9660.
3. Kill VOP_BLKATOFF, VOP_TRUNCATE, VOP_VFREE, VOP_VALLOC. These
are private interface functions between UFS and the underlying
storage manager layer (FFS/LFS/MFS/EXT2FS). The functions now
live in struct ufsmount instead.
4. Remove a kludge of VOP_ functions in all filesystems, that did
nothing but obscure the simplicity and break the expandability.
If a filesystem doesn't implement VOP_FOO, it shouldn't have an
entry for it in its vnops table. The system will try to DTRT
if it is not implemented. There are still some cruft left, but
the bulk of it is done.
5. Fix another VCALL in vfs_cache.c (thanks Bruce!)
1997-10-16 10:50:27 +00:00
|
|
|
register struct vnode *ovp = vp;
|
1997-02-10 02:22:35 +00:00
|
|
|
ufs_daddr_t lastblock;
|
1994-05-24 10:09:53 +00:00
|
|
|
register struct inode *oip;
|
1997-02-10 02:22:35 +00:00
|
|
|
ufs_daddr_t bn, lbn, lastiblock[NIADDR], indir_lbn[NIADDR];
|
|
|
|
ufs_daddr_t oldblks[NDADDR + NIADDR], newblks[NDADDR + NIADDR];
|
1994-05-24 10:09:53 +00:00
|
|
|
register struct fs *fs;
|
|
|
|
struct buf *bp;
|
|
|
|
int offset, size, level;
|
1998-10-25 17:44:59 +00:00
|
|
|
long count, nblocks, blocksreleased = 0;
|
1994-05-24 10:09:53 +00:00
|
|
|
struct timeval tv;
|
|
|
|
register int i;
|
|
|
|
int aflags, error, allerror;
|
|
|
|
off_t osize;
|
|
|
|
|
|
|
|
oip = VTOI(ovp);
|
1998-03-08 09:59:44 +00:00
|
|
|
if (oip->i_size == length)
|
|
|
|
return (0);
|
1994-10-22 02:27:35 +00:00
|
|
|
fs = oip->i_fs;
|
1997-02-10 02:22:35 +00:00
|
|
|
if (length < 0)
|
1994-10-22 02:27:35 +00:00
|
|
|
return (EINVAL);
|
1997-02-10 02:22:35 +00:00
|
|
|
if (length > fs->fs_maxfilesize)
|
|
|
|
return (EFBIG);
|
1998-03-30 09:56:58 +00:00
|
|
|
getmicrotime(&tv);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (ovp->v_type == VLNK &&
|
1994-08-02 13:51:05 +00:00
|
|
|
(oip->i_size < ovp->v_mount->mnt_maxsymlinklen || oip->i_din.di_blocks == 0)) {
|
1994-05-24 10:09:53 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (length != 0)
|
|
|
|
panic("ffs_truncate: partial truncate of symlink");
|
|
|
|
#endif
|
|
|
|
bzero((char *)&oip->i_shortlink, (u_int)oip->i_size);
|
|
|
|
oip->i_size = 0;
|
|
|
|
oip->i_flag |= IN_CHANGE | IN_UPDATE;
|
1997-10-16 20:32:40 +00:00
|
|
|
return (UFS_UPDATE(ovp, &tv, &tv, 1));
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
if (oip->i_size == length) {
|
|
|
|
oip->i_flag |= IN_CHANGE | IN_UPDATE;
|
1997-10-16 20:32:40 +00:00
|
|
|
return (UFS_UPDATE(ovp, &tv, &tv, 0));
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
#ifdef QUOTA
|
1994-10-10 01:04:55 +00:00
|
|
|
error = getinoquota(oip);
|
|
|
|
if (error)
|
1994-05-24 10:09:53 +00:00
|
|
|
return (error);
|
|
|
|
#endif
|
1998-03-08 09:59:44 +00:00
|
|
|
ovp->v_lasta = ovp->v_clen = ovp->v_cstart = ovp->v_lastw = 0;
|
|
|
|
if (DOINGSOFTDEP(ovp)) {
|
|
|
|
if (length > 0) {
|
|
|
|
/*
|
|
|
|
* If a file is only partially truncated, then
|
|
|
|
* we have to clean up the data structures
|
|
|
|
* describing the allocation past the truncation
|
|
|
|
* point. Finding and deallocating those structures
|
|
|
|
* is a lot of work. Since partial truncation occurs
|
|
|
|
* rarely, we solve the problem by syncing the file
|
|
|
|
* so that it will have no data structures left.
|
|
|
|
*/
|
|
|
|
if ((error = VOP_FSYNC(ovp, cred, MNT_WAIT,
|
|
|
|
p)) != 0)
|
|
|
|
return (error);
|
|
|
|
} else {
|
|
|
|
#ifdef QUOTA
|
|
|
|
(void) chkdq(oip, -oip->i_blocks, NOCRED, 0);
|
|
|
|
#endif
|
|
|
|
softdep_setup_freeblocks(oip, length);
|
1998-05-04 17:43:48 +00:00
|
|
|
vinvalbuf(ovp, 0, cred, p, 0, 0);
|
1998-03-08 09:59:44 +00:00
|
|
|
oip->i_flag |= IN_CHANGE | IN_UPDATE;
|
|
|
|
return (ffs_update(ovp, &tv, &tv, 0));
|
|
|
|
}
|
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
osize = oip->i_size;
|
|
|
|
/*
|
|
|
|
* Lengthen the size of the file. We must ensure that the
|
|
|
|
* last byte of the file is allocated. Since the smallest
|
1994-08-29 06:09:15 +00:00
|
|
|
* value of osize is 0, length will be at least 1.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
if (osize < length) {
|
This mega-commit is meant to fix numerous interrelated problems. There
has been some bitrot and incorrect assumptions in the vfs_bio code. These
problems have manifest themselves worse on NFS type filesystems, but can
still affect local filesystems under certain circumstances. Most of
the problems have involved mmap consistancy, and as a side-effect broke
the vfs.ioopt code. This code might have been committed seperately, but
almost everything is interrelated.
1) Allow (pmap_object_init_pt) prefaulting of buffer-busy pages that
are fully valid.
2) Rather than deactivating erroneously read initial (header) pages in
kern_exec, we now free them.
3) Fix the rundown of non-VMIO buffers that are in an inconsistent
(missing vp) state.
4) Fix the disassociation of pages from buffers in brelse. The previous
code had rotted and was faulty in a couple of important circumstances.
5) Remove a gratuitious buffer wakeup in vfs_vmio_release.
6) Remove a crufty and currently unused cluster mechanism for VBLK
files in vfs_bio_awrite. When the code is functional, I'll add back
a cleaner version.
7) The page busy count wakeups assocated with the buffer cache usage were
incorrectly cleaned up in a previous commit by me. Revert to the
original, correct version, but with a cleaner implementation.
8) The cluster read code now tries to keep data associated with buffers
more aggressively (without breaking the heuristics) when it is presumed
that the read data (buffers) will be soon needed.
9) Change to filesystem lockmgr locks so that they use LK_NOPAUSE. The
delay loop waiting is not useful for filesystem locks, due to the
length of the time intervals.
10) Correct and clean-up spec_getpages.
11) Implement a fully functional nfs_getpages, nfs_putpages.
12) Fix nfs_write so that modifications are coherent with the NFS data on
the server disk (at least as well as NFS seems to allow.)
13) Properly support MS_INVALIDATE on NFS.
14) Properly pass down MS_INVALIDATE to lower levels of the VM code from
vm_map_clean.
15) Better support the notion of pages being busy but valid, so that
fewer in-transit waits occur. (use p->busy more for pageouts instead
of PG_BUSY.) Since the page is fully valid, it is still usable for
reads.
16) It is possible (in error) for cached pages to be busy. Make the
page allocation code handle that case correctly. (It should probably
be a printf or panic, but I want the system to handle coding errors
robustly. I'll probably add a printf.)
17) Correct the design and usage of vm_page_sleep. It didn't handle
consistancy problems very well, so make the design a little less
lofty. After vm_page_sleep, if it ever blocked, it is still important
to relookup the page (if the object generation count changed), and
verify it's status (always.)
18) In vm_pageout.c, vm_pageout_clean had rotted, so clean that up.
19) Push the page busy for writes and VM_PROT_READ into vm_pageout_flush.
20) Fix vm_pager_put_pages and it's descendents to support an int flag
instead of a boolean, so that we can pass down the invalidate bit.
1998-03-07 21:37:31 +00:00
|
|
|
vnode_pager_setsize(ovp, length);
|
1994-05-24 10:09:53 +00:00
|
|
|
aflags = B_CLRBUF;
|
VFS mega cleanup commit (x/N)
1. Add new file "sys/kern/vfs_default.c" where default actions for
VOPs go. Implement proper defaults for ABORTOP, BWRITE, LEASE,
POLL, REVOKE and STRATEGY. Various stuff spread over the entire
tree belongs here.
2. Change VOP_BLKATOFF to a normal function in cd9660.
3. Kill VOP_BLKATOFF, VOP_TRUNCATE, VOP_VFREE, VOP_VALLOC. These
are private interface functions between UFS and the underlying
storage manager layer (FFS/LFS/MFS/EXT2FS). The functions now
live in struct ufsmount instead.
4. Remove a kludge of VOP_ functions in all filesystems, that did
nothing but obscure the simplicity and break the expandability.
If a filesystem doesn't implement VOP_FOO, it shouldn't have an
entry for it in its vnops table. The system will try to DTRT
if it is not implemented. There are still some cruft left, but
the bulk of it is done.
5. Fix another VCALL in vfs_cache.c (thanks Bruce!)
1997-10-16 10:50:27 +00:00
|
|
|
if (flags & IO_SYNC)
|
1994-05-24 10:09:53 +00:00
|
|
|
aflags |= B_SYNC;
|
1998-03-08 09:59:44 +00:00
|
|
|
error = VOP_BALLOC(ovp, length - 1, 1,
|
|
|
|
cred, aflags, &bp);
|
1994-10-10 01:04:55 +00:00
|
|
|
if (error)
|
1994-05-24 10:09:53 +00:00
|
|
|
return (error);
|
|
|
|
oip->i_size = length;
|
Make our v_usecount vnode reference count work identically to the
original BSD code. The association between the vnode and the vm_object
no longer includes reference counts. The major difference is that
vm_object's are no longer freed gratuitiously from the vnode, and so
once an object is created for the vnode, it will last as long as the
vnode does.
When a vnode object reference count is incremented, then the underlying
vnode reference count is incremented also. The two "objects" are now
more intimately related, and so the interactions are now much less
complex.
When vnodes are now normally placed onto the free queue with an object still
attached. The rundown of the object happens at vnode rundown time, and
happens with exactly the same filesystem semantics of the original VFS
code. There is absolutely no need for vnode_pager_uncache and other
travesties like that anymore.
A side-effect of these changes is that SMP locking should be much simpler,
the I/O copyin/copyout optimizations work, NFS should be more ponderable,
and further work on layered filesystems should be less frustrating, because
of the totally coherent management of the vnode objects and vnodes.
Please be careful with your system while running this code, but I would
greatly appreciate feedback as soon a reasonably possible.
1998-01-06 05:26:17 +00:00
|
|
|
if (bp->b_bufsize == fs->fs_bsize)
|
|
|
|
bp->b_flags |= B_CLUSTEROK;
|
1995-08-04 05:49:17 +00:00
|
|
|
if (aflags & B_SYNC)
|
1994-05-24 10:09:53 +00:00
|
|
|
bwrite(bp);
|
1995-11-05 21:01:15 +00:00
|
|
|
else if (ovp->v_mount->mnt_flag & MNT_ASYNC)
|
|
|
|
bdwrite(bp);
|
1994-05-24 10:09:53 +00:00
|
|
|
else
|
|
|
|
bawrite(bp);
|
|
|
|
oip->i_flag |= IN_CHANGE | IN_UPDATE;
|
1997-10-16 20:32:40 +00:00
|
|
|
return (UFS_UPDATE(ovp, &tv, &tv, 1));
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Shorten the size of the file. If the file is not being
|
1998-06-14 19:31:28 +00:00
|
|
|
* truncated to a block boundary, the contents of the
|
1994-05-24 10:09:53 +00:00
|
|
|
* partial block following the end of the file must be
|
1998-06-14 19:31:28 +00:00
|
|
|
* zero'ed in case it ever becomes accessible again because
|
|
|
|
* of subsequent file growth. Directories however are not
|
|
|
|
* zero'ed as they should grow back initialized to empty.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
offset = blkoff(fs, length);
|
|
|
|
if (offset == 0) {
|
|
|
|
oip->i_size = length;
|
|
|
|
} else {
|
|
|
|
lbn = lblkno(fs, length);
|
|
|
|
aflags = B_CLRBUF;
|
VFS mega cleanup commit (x/N)
1. Add new file "sys/kern/vfs_default.c" where default actions for
VOPs go. Implement proper defaults for ABORTOP, BWRITE, LEASE,
POLL, REVOKE and STRATEGY. Various stuff spread over the entire
tree belongs here.
2. Change VOP_BLKATOFF to a normal function in cd9660.
3. Kill VOP_BLKATOFF, VOP_TRUNCATE, VOP_VFREE, VOP_VALLOC. These
are private interface functions between UFS and the underlying
storage manager layer (FFS/LFS/MFS/EXT2FS). The functions now
live in struct ufsmount instead.
4. Remove a kludge of VOP_ functions in all filesystems, that did
nothing but obscure the simplicity and break the expandability.
If a filesystem doesn't implement VOP_FOO, it shouldn't have an
entry for it in its vnops table. The system will try to DTRT
if it is not implemented. There are still some cruft left, but
the bulk of it is done.
5. Fix another VCALL in vfs_cache.c (thanks Bruce!)
1997-10-16 10:50:27 +00:00
|
|
|
if (flags & IO_SYNC)
|
1994-05-24 10:09:53 +00:00
|
|
|
aflags |= B_SYNC;
|
1998-03-08 09:59:44 +00:00
|
|
|
error = VOP_BALLOC(ovp, length - 1, 1, cred, aflags, &bp);
|
|
|
|
if (error) {
|
1994-05-24 10:09:53 +00:00
|
|
|
return (error);
|
1998-03-08 09:59:44 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
oip->i_size = length;
|
|
|
|
size = blksize(fs, oip, lbn);
|
1998-06-14 19:31:28 +00:00
|
|
|
if (ovp->v_type != VDIR)
|
|
|
|
bzero((char *)bp->b_data + offset,
|
|
|
|
(u_int)(size - offset));
|
|
|
|
/* Kirk's code has reallocbuf(bp, size, 1) here */
|
1995-03-26 23:29:13 +00:00
|
|
|
allocbuf(bp, size);
|
Make our v_usecount vnode reference count work identically to the
original BSD code. The association between the vnode and the vm_object
no longer includes reference counts. The major difference is that
vm_object's are no longer freed gratuitiously from the vnode, and so
once an object is created for the vnode, it will last as long as the
vnode does.
When a vnode object reference count is incremented, then the underlying
vnode reference count is incremented also. The two "objects" are now
more intimately related, and so the interactions are now much less
complex.
When vnodes are now normally placed onto the free queue with an object still
attached. The rundown of the object happens at vnode rundown time, and
happens with exactly the same filesystem semantics of the original VFS
code. There is absolutely no need for vnode_pager_uncache and other
travesties like that anymore.
A side-effect of these changes is that SMP locking should be much simpler,
the I/O copyin/copyout optimizations work, NFS should be more ponderable,
and further work on layered filesystems should be less frustrating, because
of the totally coherent management of the vnode objects and vnodes.
Please be careful with your system while running this code, but I would
greatly appreciate feedback as soon a reasonably possible.
1998-01-06 05:26:17 +00:00
|
|
|
if (bp->b_bufsize == fs->fs_bsize)
|
|
|
|
bp->b_flags |= B_CLUSTEROK;
|
1995-08-04 05:49:17 +00:00
|
|
|
if (aflags & B_SYNC)
|
1994-05-24 10:09:53 +00:00
|
|
|
bwrite(bp);
|
1995-11-05 21:01:15 +00:00
|
|
|
else if (ovp->v_mount->mnt_flag & MNT_ASYNC)
|
|
|
|
bdwrite(bp);
|
1994-05-24 10:09:53 +00:00
|
|
|
else
|
|
|
|
bawrite(bp);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Calculate index into inode's block list of
|
|
|
|
* last direct and indirect blocks (if any)
|
|
|
|
* which we want to keep. Lastblock is -1 when
|
|
|
|
* the file is truncated to 0.
|
|
|
|
*/
|
|
|
|
lastblock = lblkno(fs, length + fs->fs_bsize - 1) - 1;
|
|
|
|
lastiblock[SINGLE] = lastblock - NDADDR;
|
|
|
|
lastiblock[DOUBLE] = lastiblock[SINGLE] - NINDIR(fs);
|
|
|
|
lastiblock[TRIPLE] = lastiblock[DOUBLE] - NINDIR(fs) * NINDIR(fs);
|
|
|
|
nblocks = btodb(fs->fs_bsize);
|
|
|
|
/*
|
|
|
|
* Update file and block pointers on disk before we start freeing
|
|
|
|
* blocks. If we crash before free'ing blocks below, the blocks
|
|
|
|
* will be returned to the free list. lastiblock values are also
|
|
|
|
* normalized to -1 for calls to ffs_indirtrunc below.
|
|
|
|
*/
|
|
|
|
bcopy((caddr_t)&oip->i_db[0], (caddr_t)oldblks, sizeof oldblks);
|
|
|
|
for (level = TRIPLE; level >= SINGLE; level--)
|
|
|
|
if (lastiblock[level] < 0) {
|
|
|
|
oip->i_ib[level] = 0;
|
|
|
|
lastiblock[level] = -1;
|
|
|
|
}
|
|
|
|
for (i = NDADDR - 1; i > lastblock; i--)
|
|
|
|
oip->i_db[i] = 0;
|
|
|
|
oip->i_flag |= IN_CHANGE | IN_UPDATE;
|
1998-03-19 22:49:44 +00:00
|
|
|
allerror = UFS_UPDATE(ovp, &tv, &tv, ((length > 0) ? 0 : 1));
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Having written the new inode to disk, save its new configuration
|
|
|
|
* and put back the old block pointers long enough to process them.
|
|
|
|
* Note that we save the new block configuration so we can check it
|
|
|
|
* when we are done.
|
|
|
|
*/
|
|
|
|
bcopy((caddr_t)&oip->i_db[0], (caddr_t)newblks, sizeof newblks);
|
|
|
|
bcopy((caddr_t)oldblks, (caddr_t)&oip->i_db[0], sizeof oldblks);
|
|
|
|
oip->i_size = osize;
|
1998-03-19 22:49:44 +00:00
|
|
|
|
|
|
|
error = vtruncbuf(ovp, cred, p, length, fs->fs_bsize);
|
|
|
|
if (error && (allerror == 0))
|
|
|
|
allerror = error;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Indirect blocks first.
|
|
|
|
*/
|
|
|
|
indir_lbn[SINGLE] = -NDADDR;
|
|
|
|
indir_lbn[DOUBLE] = indir_lbn[SINGLE] - NINDIR(fs) - 1;
|
|
|
|
indir_lbn[TRIPLE] = indir_lbn[DOUBLE] - NINDIR(fs) * NINDIR(fs) - 1;
|
|
|
|
for (level = TRIPLE; level >= SINGLE; level--) {
|
|
|
|
bn = oip->i_ib[level];
|
|
|
|
if (bn != 0) {
|
|
|
|
error = ffs_indirtrunc(oip, indir_lbn[level],
|
|
|
|
fsbtodb(fs, bn), lastiblock[level], level, &count);
|
|
|
|
if (error)
|
|
|
|
allerror = error;
|
|
|
|
blocksreleased += count;
|
|
|
|
if (lastiblock[level] < 0) {
|
|
|
|
oip->i_ib[level] = 0;
|
|
|
|
ffs_blkfree(oip, bn, fs->fs_bsize);
|
|
|
|
blocksreleased += nblocks;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lastiblock[level] >= 0)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All whole direct blocks or frags.
|
|
|
|
*/
|
|
|
|
for (i = NDADDR - 1; i > lastblock; i--) {
|
|
|
|
register long bsize;
|
|
|
|
|
|
|
|
bn = oip->i_db[i];
|
|
|
|
if (bn == 0)
|
|
|
|
continue;
|
|
|
|
oip->i_db[i] = 0;
|
|
|
|
bsize = blksize(fs, oip, i);
|
|
|
|
ffs_blkfree(oip, bn, bsize);
|
|
|
|
blocksreleased += btodb(bsize);
|
|
|
|
}
|
|
|
|
if (lastblock < 0)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally, look for a change in size of the
|
|
|
|
* last direct block; release any frags.
|
|
|
|
*/
|
|
|
|
bn = oip->i_db[lastblock];
|
|
|
|
if (bn != 0) {
|
|
|
|
long oldspace, newspace;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate amount of space we're giving
|
|
|
|
* back as old block size minus new block size.
|
|
|
|
*/
|
|
|
|
oldspace = blksize(fs, oip, lastblock);
|
|
|
|
oip->i_size = length;
|
|
|
|
newspace = blksize(fs, oip, lastblock);
|
|
|
|
if (newspace == 0)
|
1994-08-03 08:19:35 +00:00
|
|
|
panic("ffs_truncate: newspace");
|
1994-05-24 10:09:53 +00:00
|
|
|
if (oldspace - newspace > 0) {
|
|
|
|
/*
|
|
|
|
* Block number of space to be free'd is
|
|
|
|
* the old block # plus the number of frags
|
|
|
|
* required for the storage we're keeping.
|
|
|
|
*/
|
|
|
|
bn += numfrags(fs, newspace);
|
|
|
|
ffs_blkfree(oip, bn, oldspace - newspace);
|
|
|
|
blocksreleased += btodb(oldspace - newspace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
for (level = SINGLE; level <= TRIPLE; level++)
|
|
|
|
if (newblks[NDADDR + level] != oip->i_ib[level])
|
1994-08-03 08:19:35 +00:00
|
|
|
panic("ffs_truncate1");
|
1994-05-24 10:09:53 +00:00
|
|
|
for (i = 0; i < NDADDR; i++)
|
|
|
|
if (newblks[i] != oip->i_db[i])
|
1994-08-03 08:19:35 +00:00
|
|
|
panic("ffs_truncate2");
|
1994-05-24 10:09:53 +00:00
|
|
|
if (length == 0 &&
|
1998-10-31 15:31:29 +00:00
|
|
|
(!TAILQ_EMPTY(&ovp->v_dirtyblkhd) ||
|
|
|
|
!TAILQ_EMPTY(&ovp->v_cleanblkhd)))
|
1994-08-03 08:19:35 +00:00
|
|
|
panic("ffs_truncate3");
|
1994-05-24 10:09:53 +00:00
|
|
|
#endif /* DIAGNOSTIC */
|
|
|
|
/*
|
|
|
|
* Put back the real size.
|
|
|
|
*/
|
|
|
|
oip->i_size = length;
|
|
|
|
oip->i_blocks -= blocksreleased;
|
1998-03-19 22:49:44 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
if (oip->i_blocks < 0) /* sanity */
|
|
|
|
oip->i_blocks = 0;
|
|
|
|
oip->i_flag |= IN_CHANGE;
|
|
|
|
#ifdef QUOTA
|
|
|
|
(void) chkdq(oip, -blocksreleased, NOCRED, 0);
|
|
|
|
#endif
|
|
|
|
return (allerror);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release blocks associated with the inode ip and stored in the indirect
|
|
|
|
* block bn. Blocks are free'd in LIFO order up to (but not including)
|
|
|
|
* lastbn. If level is greater than SINGLE, the block is an indirect block
|
|
|
|
* and recursive calls to indirtrunc must be used to cleanse other indirect
|
|
|
|
* blocks.
|
|
|
|
*
|
|
|
|
* NB: triple indirect blocks are untested.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ffs_indirtrunc(ip, lbn, dbn, lastbn, level, countp)
|
|
|
|
register struct inode *ip;
|
1997-02-10 02:22:35 +00:00
|
|
|
ufs_daddr_t lbn, lastbn;
|
|
|
|
ufs_daddr_t dbn;
|
1994-05-24 10:09:53 +00:00
|
|
|
int level;
|
|
|
|
long *countp;
|
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
struct buf *bp;
|
|
|
|
register struct fs *fs = ip->i_fs;
|
1997-02-10 02:22:35 +00:00
|
|
|
register ufs_daddr_t *bap;
|
1994-05-24 10:09:53 +00:00
|
|
|
struct vnode *vp;
|
1997-02-10 02:22:35 +00:00
|
|
|
ufs_daddr_t *copy = NULL, nb, nlbn, last;
|
1994-05-24 10:09:53 +00:00
|
|
|
long blkcount, factor;
|
|
|
|
int nblocks, blocksreleased = 0;
|
|
|
|
int error = 0, allerror = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate index in current block of last
|
|
|
|
* block to be kept. -1 indicates the entire
|
|
|
|
* block so we need not calculate the index.
|
|
|
|
*/
|
|
|
|
factor = 1;
|
|
|
|
for (i = SINGLE; i < level; i++)
|
|
|
|
factor *= NINDIR(fs);
|
|
|
|
last = lastbn;
|
|
|
|
if (lastbn > 0)
|
|
|
|
last /= factor;
|
|
|
|
nblocks = btodb(fs->fs_bsize);
|
|
|
|
/*
|
|
|
|
* Get buffer of block pointers, zero those entries corresponding
|
|
|
|
* to blocks to be free'd, and update on disk copy first. Since
|
|
|
|
* double(triple) indirect before single(double) indirect, calls
|
|
|
|
* to bmap on these blocks will fail. However, we already have
|
|
|
|
* the on disk address, so we have to set the b_blkno field
|
|
|
|
* explicitly instead of letting bread do everything for us.
|
|
|
|
*/
|
|
|
|
vp = ITOV(ip);
|
|
|
|
bp = getblk(vp, lbn, (int)fs->fs_bsize, 0, 0);
|
1995-03-04 03:24:45 +00:00
|
|
|
if ((bp->b_flags & B_CACHE) == 0) {
|
1994-05-24 10:09:53 +00:00
|
|
|
curproc->p_stats->p_ru.ru_inblock++; /* pay for read */
|
|
|
|
bp->b_flags |= B_READ;
|
|
|
|
if (bp->b_bcount > bp->b_bufsize)
|
|
|
|
panic("ffs_indirtrunc: bad buffer size");
|
|
|
|
bp->b_blkno = dbn;
|
These changes embody the support of the fully coherent merged VM buffer cache,
much higher filesystem I/O performance, and much better paging performance. It
represents the culmination of over 6 months of R&D.
The majority of the merged VM/cache work is by John Dyson.
The following highlights the most significant changes. Additionally, there are
(mostly minor) changes to the various filesystem modules (nfs, msdosfs, etc) to
support the new VM/buffer scheme.
vfs_bio.c:
Significant rewrite of most of vfs_bio to support the merged VM buffer cache
scheme. The scheme is almost fully compatible with the old filesystem
interface. Significant improvement in the number of opportunities for write
clustering.
vfs_cluster.c, vfs_subr.c
Upgrade and performance enhancements in vfs layer code to support merged
VM/buffer cache. Fixup of vfs_cluster to eliminate the bogus pagemove stuff.
vm_object.c:
Yet more improvements in the collapse code. Elimination of some windows that
can cause list corruption.
vm_pageout.c:
Fixed it, it really works better now. Somehow in 2.0, some "enhancements"
broke the code. This code has been reworked from the ground-up.
vm_fault.c, vm_page.c, pmap.c, vm_object.c
Support for small-block filesystems with merged VM/buffer cache scheme.
pmap.c vm_map.c
Dynamic kernel VM size, now we dont have to pre-allocate excessive numbers of
kernel PTs.
vm_glue.c
Much simpler and more effective swapping code. No more gratuitous swapping.
proc.h
Fixed the problem that the p_lock flag was not being cleared on a fork.
swap_pager.c, vnode_pager.c
Removal of old vfs_bio cruft to support the past pseudo-coherency. Now the
code doesn't need it anymore.
machdep.c
Changes to better support the parameter values for the merged VM/buffer cache
scheme.
machdep.c, kern_exec.c, vm_glue.c
Implemented a seperate submap for temporary exec string space and another one
to contain process upages. This eliminates all map fragmentation problems
that previously existed.
ffs_inode.c, ufs_inode.c, ufs_readwrite.c
Changes for merged VM/buffer cache. Add "bypass" support for sneaking in on
busy buffers.
Submitted by: John Dyson and David Greenman
1995-01-09 16:06:02 +00:00
|
|
|
vfs_busy_pages(bp, 0);
|
1998-07-04 20:45:42 +00:00
|
|
|
VOP_STRATEGY(bp->b_vp, bp);
|
1994-05-24 10:09:53 +00:00
|
|
|
error = biowait(bp);
|
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
brelse(bp);
|
|
|
|
*countp = 0;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1997-02-10 02:22:35 +00:00
|
|
|
bap = (ufs_daddr_t *)bp->b_data;
|
1996-11-05 08:19:40 +00:00
|
|
|
if (lastbn != -1) {
|
1997-02-10 02:22:35 +00:00
|
|
|
MALLOC(copy, ufs_daddr_t *, fs->fs_bsize, M_TEMP, M_WAITOK);
|
1996-11-05 08:19:40 +00:00
|
|
|
bcopy((caddr_t)bap, (caddr_t)copy, (u_int)fs->fs_bsize);
|
|
|
|
bzero((caddr_t)&bap[last + 1],
|
1997-02-10 02:22:35 +00:00
|
|
|
(u_int)(NINDIR(fs) - (last + 1)) * sizeof (ufs_daddr_t));
|
1996-11-05 08:19:40 +00:00
|
|
|
if ((vp->v_mount->mnt_flag & MNT_ASYNC) == 0) {
|
|
|
|
error = bwrite(bp);
|
|
|
|
if (error)
|
|
|
|
allerror = error;
|
|
|
|
} else {
|
|
|
|
bawrite(bp);
|
|
|
|
}
|
|
|
|
bap = copy;
|
1995-12-11 04:58:34 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Recursively free totally unused blocks.
|
|
|
|
*/
|
|
|
|
for (i = NINDIR(fs) - 1, nlbn = lbn + 1 - i * factor; i > last;
|
|
|
|
i--, nlbn += factor) {
|
|
|
|
nb = bap[i];
|
|
|
|
if (nb == 0)
|
|
|
|
continue;
|
|
|
|
if (level > SINGLE) {
|
1997-02-10 02:22:35 +00:00
|
|
|
if (error = ffs_indirtrunc(ip, nlbn, fsbtodb(fs, nb),
|
|
|
|
(ufs_daddr_t)-1, level - 1, &blkcount))
|
1994-05-24 10:09:53 +00:00
|
|
|
allerror = error;
|
|
|
|
blocksreleased += blkcount;
|
|
|
|
}
|
|
|
|
ffs_blkfree(ip, nb, fs->fs_bsize);
|
|
|
|
blocksreleased += nblocks;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Recursively free last partial block.
|
|
|
|
*/
|
|
|
|
if (level > SINGLE && lastbn >= 0) {
|
|
|
|
last = lastbn % factor;
|
|
|
|
nb = bap[i];
|
|
|
|
if (nb != 0) {
|
1994-10-10 01:04:55 +00:00
|
|
|
error = ffs_indirtrunc(ip, nlbn, fsbtodb(fs, nb),
|
|
|
|
last, level - 1, &blkcount);
|
|
|
|
if (error)
|
1994-05-24 10:09:53 +00:00
|
|
|
allerror = error;
|
|
|
|
blocksreleased += blkcount;
|
|
|
|
}
|
|
|
|
}
|
1996-11-05 08:19:40 +00:00
|
|
|
if (copy != NULL) {
|
|
|
|
FREE(copy, M_TEMP);
|
|
|
|
} else {
|
|
|
|
bp->b_flags |= B_INVAL | B_NOCACHE;
|
|
|
|
brelse(bp);
|
|
|
|
}
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
*countp = blocksreleased;
|
|
|
|
return (allerror);
|
|
|
|
}
|