2005-01-07 02:29:27 +00:00
|
|
|
/*-
|
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.
|
|
|
|
* 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
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-11 06:34:30 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
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>
|
2000-05-05 09:59:14 +00:00
|
|
|
#include <sys/bio.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/resourcevar.h>
|
Implement a low-memory deadlock solution.
Removed most of the hacks that were trying to deal with low-memory
situations prior to now.
The new code is based on the concept that I/O must be able to function in
a low memory situation. All major modules related to I/O (except
networking) have been adjusted to allow allocation out of the system
reserve memory pool. These modules now detect a low memory situation but
rather then block they instead continue to operate, then return resources
to the memory pool instead of cache them or leave them wired.
Code has been added to stall in a low-memory situation prior to a vnode
being locked.
Thus situations where a process blocks in a low-memory condition while
holding a locked vnode have been reduced to near nothing. Not only will
I/O continue to operate, but many prior deadlock conditions simply no
longer exist.
Implement a number of VFS/BIO fixes
(found by Ian): in biodone(), bogus-page replacement code, the loop
was not properly incrementing loop variables prior to a continue
statement. We do not believe this code can be hit anyway but we
aren't taking any chances. We'll turn the whole section into a
panic (as it already is in brelse()) after the release is rolled.
In biodone(), the foff calculation was incorrectly
clamped to the iosize, causing the wrong foff to be calculated
for pages in the case of an I/O error or biodone() called without
initiating I/O. The problem always caused a panic before. Now it
doesn't. The problem is mainly an issue with NFS.
Fixed casts for ~PAGE_MASK. This code worked properly before only
because the calculations use signed arithmatic. Better to properly
extend PAGE_MASK first before inverting it for the 64 bit masking
op.
In brelse(), the bogus_page fixup code was improperly throwing
away the original contents of 'm' when it did the j-loop to
fix the bogus pages. The result was that it would potentially
invalidate parts of the *WRONG* page(!), leading to corruption.
There may still be cases where a background bitmap write is
being duplicated, causing potential corruption. We have identified
a potentially serious bug related to this but the fix is still TBD.
So instead this patch contains a KASSERT to detect the problem
and panic the machine rather then continue to corrupt the filesystem.
The problem does not occur very often.. it is very hard to
reproduce, and it may or may not be the cause of the corruption
people have reported.
Review by: (VFS/BIO: mckusick, Ian Dowse <iedowse@maths.tcd.ie>)
Testing by: (VM/Deadlock) Paul Saab <ps@yahoo-inc.com>
2000-11-18 23:06:26 +00:00
|
|
|
#include <sys/vmmeter.h>
|
2000-07-26 23:07:01 +00:00
|
|
|
#include <sys/stat.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
#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
|
|
|
|
Introduce extended attribute support for FFS, allowing arbitrary
(name, value) pairs to be associated with inodes. This support is
used for ACLs, MAC labels, and Capabilities in the TrustedBSD
security extensions, which are currently under development.
In this implementation, attributes are backed to data vnodes in the
style of the quota support in FFS. Support for FFS extended
attributes may be enabled using the FFS_EXTATTR kernel option
(disabled by default). Userland utilities and man pages will be
committed in the next batch. VFS interfaces and man pages have
been in the repo since 4.0-RELEASE and are unchanged.
o ufs/ufs/extattr.h: UFS-specific extattr defines
o ufs/ufs/ufs_extattr.c: bulk of support routines
o ufs/{ufs,ffs,mfs}/*.[ch]: hooks and extattr.h includes
o contrib/softupdates/ffs_softdep.c: extattr.h includes
o conf/options, conf/files, i386/conf/LINT: added FFS_EXTATTR
o coda/coda_vfsops.c: XXX required extattr.h due to ufsmount.h
(This should not be the case, and will be fixed in a future commit)
Currently attributes are not supported in MFS. This will be fixed.
Reviewed by: adrian, bp, freebsd-fs, other unthanked souls
Obtained from: TrustedBSD Project
2000-04-15 03:34:27 +00:00
|
|
|
#include <ufs/ufs/extattr.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>
|
|
|
|
|
2002-06-21 06:18:05 +00:00
|
|
|
static int ffs_indirtrunc(struct inode *, ufs2_daddr_t, ufs2_daddr_t,
|
|
|
|
ufs2_daddr_t, int, ufs2_daddr_t *);
|
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
|
1999-01-07 16:14:19 +00:00
|
|
|
ffs_update(vp, waitfor)
|
1997-10-16 20:32:40 +00:00
|
|
|
struct vnode *vp;
|
|
|
|
int waitfor;
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2002-05-13 09:22:31 +00:00
|
|
|
struct fs *fs;
|
1994-05-24 10:09:53 +00:00
|
|
|
struct buf *bp;
|
|
|
|
struct inode *ip;
|
|
|
|
int error;
|
|
|
|
|
2003-10-05 09:39:02 +00:00
|
|
|
#ifdef DEBUG_VFS_LOCKS
|
|
|
|
if ((vp->v_iflag & VI_XLOCK) == 0)
|
|
|
|
ASSERT_VOP_LOCKED(vp, "ffs_update");
|
|
|
|
#endif
|
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);
|
1994-05-24 10:09:53 +00:00
|
|
|
fs = ip->i_fs;
|
2002-01-15 07:17:12 +00:00
|
|
|
if (fs->fs_ronly)
|
|
|
|
return (0);
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Ensure that uid and gid are correct. This is a temporary
|
|
|
|
* fix until fsck has been changed to do the update.
|
|
|
|
*/
|
2002-06-21 06:18:05 +00:00
|
|
|
if (fs->fs_magic == FS_UFS1_MAGIC && /* XXX */
|
|
|
|
fs->fs_old_inodefmt < FS_44INODEFMT) { /* XXX */
|
|
|
|
ip->i_din1->di_ouid = ip->i_uid; /* XXX */
|
|
|
|
ip->i_din1->di_ogid = ip->i_gid; /* XXX */
|
1994-05-24 10:09:53 +00:00
|
|
|
} /* 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");
|
2002-06-21 06:18:05 +00:00
|
|
|
if (ip->i_ump->um_fstype == UFS1)
|
|
|
|
*((struct ufs1_dinode *)bp->b_data +
|
|
|
|
ino_to_fsbo(fs, ip->i_number)) = *ip->i_din1;
|
|
|
|
else
|
|
|
|
*((struct ufs2_dinode *)bp->b_data +
|
|
|
|
ino_to_fsbo(fs, ip->i_number)) = *ip->i_din2;
|
1999-07-13 18:20:13 +00:00
|
|
|
if (waitfor && !DOINGASYNC(vp)) {
|
1994-05-24 10:09:53 +00:00
|
|
|
return (bwrite(bp));
|
Implement a low-memory deadlock solution.
Removed most of the hacks that were trying to deal with low-memory
situations prior to now.
The new code is based on the concept that I/O must be able to function in
a low memory situation. All major modules related to I/O (except
networking) have been adjusted to allow allocation out of the system
reserve memory pool. These modules now detect a low memory situation but
rather then block they instead continue to operate, then return resources
to the memory pool instead of cache them or leave them wired.
Code has been added to stall in a low-memory situation prior to a vnode
being locked.
Thus situations where a process blocks in a low-memory condition while
holding a locked vnode have been reduced to near nothing. Not only will
I/O continue to operate, but many prior deadlock conditions simply no
longer exist.
Implement a number of VFS/BIO fixes
(found by Ian): in biodone(), bogus-page replacement code, the loop
was not properly incrementing loop variables prior to a continue
statement. We do not believe this code can be hit anyway but we
aren't taking any chances. We'll turn the whole section into a
panic (as it already is in brelse()) after the release is rolled.
In biodone(), the foff calculation was incorrectly
clamped to the iosize, causing the wrong foff to be calculated
for pages in the case of an I/O error or biodone() called without
initiating I/O. The problem always caused a panic before. Now it
doesn't. The problem is mainly an issue with NFS.
Fixed casts for ~PAGE_MASK. This code worked properly before only
because the calculations use signed arithmatic. Better to properly
extend PAGE_MASK first before inverting it for the 64 bit masking
op.
In brelse(), the bogus_page fixup code was improperly throwing
away the original contents of 'm' when it did the j-loop to
fix the bogus pages. The result was that it would potentially
invalidate parts of the *WRONG* page(!), leading to corruption.
There may still be cases where a background bitmap write is
being duplicated, causing potential corruption. We have identified
a potentially serious bug related to this but the fix is still TBD.
So instead this patch contains a KASSERT to detect the problem
and panic the machine rather then continue to corrupt the filesystem.
The problem does not occur very often.. it is very hard to
reproduce, and it may or may not be the cause of the corruption
people have reported.
Review by: (VFS/BIO: mckusick, Ian Dowse <iedowse@maths.tcd.ie>)
Testing by: (VM/Deadlock) Paul Saab <ps@yahoo-inc.com>
2000-11-18 23:06:26 +00:00
|
|
|
} else if (vm_page_count_severe() || buf_dirty_count_severe()) {
|
|
|
|
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
|
2001-09-12 08:38:13 +00:00
|
|
|
ffs_truncate(vp, length, flags, cred, td)
|
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
|
|
|
struct vnode *vp;
|
|
|
|
off_t length;
|
|
|
|
int flags;
|
|
|
|
struct ucred *cred;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2002-05-13 09:22:31 +00:00
|
|
|
struct vnode *ovp = vp;
|
|
|
|
struct inode *oip;
|
2002-06-21 06:18:05 +00:00
|
|
|
ufs2_daddr_t bn, lbn, lastblock, lastiblock[NIADDR], indir_lbn[NIADDR];
|
|
|
|
ufs2_daddr_t oldblks[NDADDR + NIADDR], newblks[NDADDR + NIADDR];
|
Add support to UFS2 to provide storage for extended attributes.
As this code is not actually used by any of the existing
interfaces, it seems unlikely to break anything (famous
last words).
The internal kernel interface to manipulate these attributes
is invoked using two new IO_ flags: IO_NORMAL and IO_EXT.
These flags may be specified in the ioflags word of VOP_READ,
VOP_WRITE, and VOP_TRUNCATE. Specifying IO_NORMAL means that
you want to do I/O to the normal data part of the file and
IO_EXT means that you want to do I/O to the extended attributes
part of the file. IO_NORMAL and IO_EXT are mutually exclusive
for VOP_READ and VOP_WRITE, but may be specified individually
or together in the case of VOP_TRUNCATE. For example, when
removing a file, VOP_TRUNCATE is called with both IO_NORMAL
and IO_EXT set. For backward compatibility, if neither IO_NORMAL
nor IO_EXT is set, then IO_NORMAL is assumed.
Note that the BA_ and IO_ flags have been `merged' so that they
may both be used in the same flags word. This merger is possible
by assigning the IO_ flags to the low sixteen bits and the BA_
flags the high sixteen bits. This works because the high sixteen
bits of the IO_ word is reserved for read-ahead and help with
write clustering so will never be used for flags. This merge
lets us get away from code of the form:
if (ioflags & IO_SYNC)
flags |= BA_SYNC;
For the future, I have considered adding a new field to the
vattr structure, va_extsize. This addition could then be
exported through the stat structure to allow applications to
find out the size of the extended attribute storage and also
would provide a more standard interface for truncating them
(via VOP_SETATTR rather than VOP_TRUNCATE).
I am also contemplating adding a pathconf parameter (for
concreteness, lets call it _PC_MAX_EXTSIZE) which would
let an application determine the maximum size of the extended
atribute storage.
Sponsored by: DARPA & NAI Labs.
2002-07-19 07:29:39 +00:00
|
|
|
ufs2_daddr_t count, blocksreleased = 0, datablocks;
|
2002-05-13 09:22:31 +00:00
|
|
|
struct fs *fs;
|
1994-05-24 10:09:53 +00:00
|
|
|
struct buf *bp;
|
2005-01-24 10:04:22 +00:00
|
|
|
struct ufsmount *ump;
|
Add support to UFS2 to provide storage for extended attributes.
As this code is not actually used by any of the existing
interfaces, it seems unlikely to break anything (famous
last words).
The internal kernel interface to manipulate these attributes
is invoked using two new IO_ flags: IO_NORMAL and IO_EXT.
These flags may be specified in the ioflags word of VOP_READ,
VOP_WRITE, and VOP_TRUNCATE. Specifying IO_NORMAL means that
you want to do I/O to the normal data part of the file and
IO_EXT means that you want to do I/O to the extended attributes
part of the file. IO_NORMAL and IO_EXT are mutually exclusive
for VOP_READ and VOP_WRITE, but may be specified individually
or together in the case of VOP_TRUNCATE. For example, when
removing a file, VOP_TRUNCATE is called with both IO_NORMAL
and IO_EXT set. For backward compatibility, if neither IO_NORMAL
nor IO_EXT is set, then IO_NORMAL is assumed.
Note that the BA_ and IO_ flags have been `merged' so that they
may both be used in the same flags word. This merger is possible
by assigning the IO_ flags to the low sixteen bits and the BA_
flags the high sixteen bits. This works because the high sixteen
bits of the IO_ word is reserved for read-ahead and help with
write clustering so will never be used for flags. This merge
lets us get away from code of the form:
if (ioflags & IO_SYNC)
flags |= BA_SYNC;
For the future, I have considered adding a new field to the
vattr structure, va_extsize. This addition could then be
exported through the stat structure to allow applications to
find out the size of the extended attribute storage and also
would provide a more standard interface for truncating them
(via VOP_SETATTR rather than VOP_TRUNCATE).
I am also contemplating adding a pathconf parameter (for
concreteness, lets call it _PC_MAX_EXTSIZE) which would
let an application determine the maximum size of the extended
atribute storage.
Sponsored by: DARPA & NAI Labs.
2002-07-19 07:29:39 +00:00
|
|
|
int needextclean, softdepslowdown, extblocks;
|
2002-06-21 06:18:05 +00:00
|
|
|
int offset, size, level, nblocks;
|
Add support to UFS2 to provide storage for extended attributes.
As this code is not actually used by any of the existing
interfaces, it seems unlikely to break anything (famous
last words).
The internal kernel interface to manipulate these attributes
is invoked using two new IO_ flags: IO_NORMAL and IO_EXT.
These flags may be specified in the ioflags word of VOP_READ,
VOP_WRITE, and VOP_TRUNCATE. Specifying IO_NORMAL means that
you want to do I/O to the normal data part of the file and
IO_EXT means that you want to do I/O to the extended attributes
part of the file. IO_NORMAL and IO_EXT are mutually exclusive
for VOP_READ and VOP_WRITE, but may be specified individually
or together in the case of VOP_TRUNCATE. For example, when
removing a file, VOP_TRUNCATE is called with both IO_NORMAL
and IO_EXT set. For backward compatibility, if neither IO_NORMAL
nor IO_EXT is set, then IO_NORMAL is assumed.
Note that the BA_ and IO_ flags have been `merged' so that they
may both be used in the same flags word. This merger is possible
by assigning the IO_ flags to the low sixteen bits and the BA_
flags the high sixteen bits. This works because the high sixteen
bits of the IO_ word is reserved for read-ahead and help with
write clustering so will never be used for flags. This merge
lets us get away from code of the form:
if (ioflags & IO_SYNC)
flags |= BA_SYNC;
For the future, I have considered adding a new field to the
vattr structure, va_extsize. This addition could then be
exported through the stat structure to allow applications to
find out the size of the extended attribute storage and also
would provide a more standard interface for truncating them
(via VOP_SETATTR rather than VOP_TRUNCATE).
I am also contemplating adding a pathconf parameter (for
concreteness, lets call it _PC_MAX_EXTSIZE) which would
let an application determine the maximum size of the extended
atribute storage.
Sponsored by: DARPA & NAI Labs.
2002-07-19 07:29:39 +00:00
|
|
|
int i, error, allerror;
|
1994-05-24 10:09:53 +00:00
|
|
|
off_t osize;
|
|
|
|
|
|
|
|
oip = VTOI(ovp);
|
1994-10-22 02:27:35 +00:00
|
|
|
fs = oip->i_fs;
|
2005-01-24 10:04:22 +00:00
|
|
|
ump = oip->i_ump;
|
|
|
|
|
1997-02-10 02:22:35 +00:00
|
|
|
if (length < 0)
|
1994-10-22 02:27:35 +00:00
|
|
|
return (EINVAL);
|
Add support to UFS2 to provide storage for extended attributes.
As this code is not actually used by any of the existing
interfaces, it seems unlikely to break anything (famous
last words).
The internal kernel interface to manipulate these attributes
is invoked using two new IO_ flags: IO_NORMAL and IO_EXT.
These flags may be specified in the ioflags word of VOP_READ,
VOP_WRITE, and VOP_TRUNCATE. Specifying IO_NORMAL means that
you want to do I/O to the normal data part of the file and
IO_EXT means that you want to do I/O to the extended attributes
part of the file. IO_NORMAL and IO_EXT are mutually exclusive
for VOP_READ and VOP_WRITE, but may be specified individually
or together in the case of VOP_TRUNCATE. For example, when
removing a file, VOP_TRUNCATE is called with both IO_NORMAL
and IO_EXT set. For backward compatibility, if neither IO_NORMAL
nor IO_EXT is set, then IO_NORMAL is assumed.
Note that the BA_ and IO_ flags have been `merged' so that they
may both be used in the same flags word. This merger is possible
by assigning the IO_ flags to the low sixteen bits and the BA_
flags the high sixteen bits. This works because the high sixteen
bits of the IO_ word is reserved for read-ahead and help with
write clustering so will never be used for flags. This merge
lets us get away from code of the form:
if (ioflags & IO_SYNC)
flags |= BA_SYNC;
For the future, I have considered adding a new field to the
vattr structure, va_extsize. This addition could then be
exported through the stat structure to allow applications to
find out the size of the extended attribute storage and also
would provide a more standard interface for truncating them
(via VOP_SETATTR rather than VOP_TRUNCATE).
I am also contemplating adding a pathconf parameter (for
concreteness, lets call it _PC_MAX_EXTSIZE) which would
let an application determine the maximum size of the extended
atribute storage.
Sponsored by: DARPA & NAI Labs.
2002-07-19 07:29:39 +00:00
|
|
|
/*
|
|
|
|
* Historically clients did not have to specify which data
|
|
|
|
* they were truncating. So, if not specified, we assume
|
|
|
|
* traditional behavior, e.g., just the normal data.
|
|
|
|
*/
|
|
|
|
if ((flags & (IO_EXT | IO_NORMAL)) == 0)
|
|
|
|
flags |= IO_NORMAL;
|
|
|
|
/*
|
|
|
|
* If we are truncating the extended-attributes, and cannot
|
|
|
|
* do it with soft updates, then do it slowly here. If we are
|
|
|
|
* truncating both the extended attributes and the file contents
|
|
|
|
* (e.g., the file is being unlinked), then pick it off with
|
|
|
|
* soft updates below.
|
|
|
|
*/
|
|
|
|
needextclean = 0;
|
2002-08-05 17:59:20 +00:00
|
|
|
softdepslowdown = DOINGSOFTDEP(ovp) && softdep_slowdown(ovp);
|
Add support to UFS2 to provide storage for extended attributes.
As this code is not actually used by any of the existing
interfaces, it seems unlikely to break anything (famous
last words).
The internal kernel interface to manipulate these attributes
is invoked using two new IO_ flags: IO_NORMAL and IO_EXT.
These flags may be specified in the ioflags word of VOP_READ,
VOP_WRITE, and VOP_TRUNCATE. Specifying IO_NORMAL means that
you want to do I/O to the normal data part of the file and
IO_EXT means that you want to do I/O to the extended attributes
part of the file. IO_NORMAL and IO_EXT are mutually exclusive
for VOP_READ and VOP_WRITE, but may be specified individually
or together in the case of VOP_TRUNCATE. For example, when
removing a file, VOP_TRUNCATE is called with both IO_NORMAL
and IO_EXT set. For backward compatibility, if neither IO_NORMAL
nor IO_EXT is set, then IO_NORMAL is assumed.
Note that the BA_ and IO_ flags have been `merged' so that they
may both be used in the same flags word. This merger is possible
by assigning the IO_ flags to the low sixteen bits and the BA_
flags the high sixteen bits. This works because the high sixteen
bits of the IO_ word is reserved for read-ahead and help with
write clustering so will never be used for flags. This merge
lets us get away from code of the form:
if (ioflags & IO_SYNC)
flags |= BA_SYNC;
For the future, I have considered adding a new field to the
vattr structure, va_extsize. This addition could then be
exported through the stat structure to allow applications to
find out the size of the extended attribute storage and also
would provide a more standard interface for truncating them
(via VOP_SETATTR rather than VOP_TRUNCATE).
I am also contemplating adding a pathconf parameter (for
concreteness, lets call it _PC_MAX_EXTSIZE) which would
let an application determine the maximum size of the extended
atribute storage.
Sponsored by: DARPA & NAI Labs.
2002-07-19 07:29:39 +00:00
|
|
|
extblocks = 0;
|
|
|
|
datablocks = DIP(oip, i_blocks);
|
|
|
|
if (fs->fs_magic == FS_UFS2_MAGIC && oip->i_din2->di_extsize > 0) {
|
|
|
|
extblocks = btodb(fragroundup(fs, oip->i_din2->di_extsize));
|
|
|
|
datablocks -= extblocks;
|
|
|
|
}
|
|
|
|
if ((flags & IO_EXT) && extblocks > 0) {
|
|
|
|
if (DOINGSOFTDEP(ovp) && softdepslowdown == 0 && length == 0) {
|
|
|
|
if ((flags & IO_NORMAL) == 0) {
|
|
|
|
softdep_setup_freeblocks(oip, length, IO_EXT);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
needextclean = 1;
|
|
|
|
} else {
|
|
|
|
if (length != 0)
|
|
|
|
panic("ffs_truncate: partial trunc of extdata");
|
2005-01-11 07:36:22 +00:00
|
|
|
if ((error = VOP_FSYNC(ovp, MNT_WAIT, td)) != 0)
|
Add support to UFS2 to provide storage for extended attributes.
As this code is not actually used by any of the existing
interfaces, it seems unlikely to break anything (famous
last words).
The internal kernel interface to manipulate these attributes
is invoked using two new IO_ flags: IO_NORMAL and IO_EXT.
These flags may be specified in the ioflags word of VOP_READ,
VOP_WRITE, and VOP_TRUNCATE. Specifying IO_NORMAL means that
you want to do I/O to the normal data part of the file and
IO_EXT means that you want to do I/O to the extended attributes
part of the file. IO_NORMAL and IO_EXT are mutually exclusive
for VOP_READ and VOP_WRITE, but may be specified individually
or together in the case of VOP_TRUNCATE. For example, when
removing a file, VOP_TRUNCATE is called with both IO_NORMAL
and IO_EXT set. For backward compatibility, if neither IO_NORMAL
nor IO_EXT is set, then IO_NORMAL is assumed.
Note that the BA_ and IO_ flags have been `merged' so that they
may both be used in the same flags word. This merger is possible
by assigning the IO_ flags to the low sixteen bits and the BA_
flags the high sixteen bits. This works because the high sixteen
bits of the IO_ word is reserved for read-ahead and help with
write clustering so will never be used for flags. This merge
lets us get away from code of the form:
if (ioflags & IO_SYNC)
flags |= BA_SYNC;
For the future, I have considered adding a new field to the
vattr structure, va_extsize. This addition could then be
exported through the stat structure to allow applications to
find out the size of the extended attribute storage and also
would provide a more standard interface for truncating them
(via VOP_SETATTR rather than VOP_TRUNCATE).
I am also contemplating adding a pathconf parameter (for
concreteness, lets call it _PC_MAX_EXTSIZE) which would
let an application determine the maximum size of the extended
atribute storage.
Sponsored by: DARPA & NAI Labs.
2002-07-19 07:29:39 +00:00
|
|
|
return (error);
|
|
|
|
osize = oip->i_din2->di_extsize;
|
|
|
|
oip->i_din2->di_blocks -= extblocks;
|
|
|
|
#ifdef QUOTA
|
|
|
|
(void) chkdq(oip, -extblocks, NOCRED, 0);
|
|
|
|
#endif
|
2005-01-14 07:33:51 +00:00
|
|
|
vinvalbuf(ovp, V_ALT, td, 0, 0);
|
Add support to UFS2 to provide storage for extended attributes.
As this code is not actually used by any of the existing
interfaces, it seems unlikely to break anything (famous
last words).
The internal kernel interface to manipulate these attributes
is invoked using two new IO_ flags: IO_NORMAL and IO_EXT.
These flags may be specified in the ioflags word of VOP_READ,
VOP_WRITE, and VOP_TRUNCATE. Specifying IO_NORMAL means that
you want to do I/O to the normal data part of the file and
IO_EXT means that you want to do I/O to the extended attributes
part of the file. IO_NORMAL and IO_EXT are mutually exclusive
for VOP_READ and VOP_WRITE, but may be specified individually
or together in the case of VOP_TRUNCATE. For example, when
removing a file, VOP_TRUNCATE is called with both IO_NORMAL
and IO_EXT set. For backward compatibility, if neither IO_NORMAL
nor IO_EXT is set, then IO_NORMAL is assumed.
Note that the BA_ and IO_ flags have been `merged' so that they
may both be used in the same flags word. This merger is possible
by assigning the IO_ flags to the low sixteen bits and the BA_
flags the high sixteen bits. This works because the high sixteen
bits of the IO_ word is reserved for read-ahead and help with
write clustering so will never be used for flags. This merge
lets us get away from code of the form:
if (ioflags & IO_SYNC)
flags |= BA_SYNC;
For the future, I have considered adding a new field to the
vattr structure, va_extsize. This addition could then be
exported through the stat structure to allow applications to
find out the size of the extended attribute storage and also
would provide a more standard interface for truncating them
(via VOP_SETATTR rather than VOP_TRUNCATE).
I am also contemplating adding a pathconf parameter (for
concreteness, lets call it _PC_MAX_EXTSIZE) which would
let an application determine the maximum size of the extended
atribute storage.
Sponsored by: DARPA & NAI Labs.
2002-07-19 07:29:39 +00:00
|
|
|
oip->i_din2->di_extsize = 0;
|
|
|
|
for (i = 0; i < NXADDR; i++) {
|
|
|
|
oldblks[i] = oip->i_din2->di_extb[i];
|
|
|
|
oip->i_din2->di_extb[i] = 0;
|
|
|
|
}
|
|
|
|
oip->i_flag |= IN_CHANGE | IN_UPDATE;
|
|
|
|
if ((error = ffs_update(ovp, 1)))
|
|
|
|
return (error);
|
|
|
|
for (i = 0; i < NXADDR; i++) {
|
|
|
|
if (oldblks[i] == 0)
|
|
|
|
continue;
|
2005-01-24 10:04:22 +00:00
|
|
|
ffs_blkfree(ump, fs, oip->i_devvp, oldblks[i],
|
Add support to UFS2 to provide storage for extended attributes.
As this code is not actually used by any of the existing
interfaces, it seems unlikely to break anything (famous
last words).
The internal kernel interface to manipulate these attributes
is invoked using two new IO_ flags: IO_NORMAL and IO_EXT.
These flags may be specified in the ioflags word of VOP_READ,
VOP_WRITE, and VOP_TRUNCATE. Specifying IO_NORMAL means that
you want to do I/O to the normal data part of the file and
IO_EXT means that you want to do I/O to the extended attributes
part of the file. IO_NORMAL and IO_EXT are mutually exclusive
for VOP_READ and VOP_WRITE, but may be specified individually
or together in the case of VOP_TRUNCATE. For example, when
removing a file, VOP_TRUNCATE is called with both IO_NORMAL
and IO_EXT set. For backward compatibility, if neither IO_NORMAL
nor IO_EXT is set, then IO_NORMAL is assumed.
Note that the BA_ and IO_ flags have been `merged' so that they
may both be used in the same flags word. This merger is possible
by assigning the IO_ flags to the low sixteen bits and the BA_
flags the high sixteen bits. This works because the high sixteen
bits of the IO_ word is reserved for read-ahead and help with
write clustering so will never be used for flags. This merge
lets us get away from code of the form:
if (ioflags & IO_SYNC)
flags |= BA_SYNC;
For the future, I have considered adding a new field to the
vattr structure, va_extsize. This addition could then be
exported through the stat structure to allow applications to
find out the size of the extended attribute storage and also
would provide a more standard interface for truncating them
(via VOP_SETATTR rather than VOP_TRUNCATE).
I am also contemplating adding a pathconf parameter (for
concreteness, lets call it _PC_MAX_EXTSIZE) which would
let an application determine the maximum size of the extended
atribute storage.
Sponsored by: DARPA & NAI Labs.
2002-07-19 07:29:39 +00:00
|
|
|
sblksize(fs, osize, i), oip->i_number);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((flags & IO_NORMAL) == 0)
|
|
|
|
return (0);
|
1997-02-10 02:22:35 +00:00
|
|
|
if (length > fs->fs_maxfilesize)
|
|
|
|
return (EFBIG);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (ovp->v_type == VLNK &&
|
2002-06-21 06:18:05 +00:00
|
|
|
(oip->i_size < ovp->v_mount->mnt_maxsymlinklen ||
|
Add support to UFS2 to provide storage for extended attributes.
As this code is not actually used by any of the existing
interfaces, it seems unlikely to break anything (famous
last words).
The internal kernel interface to manipulate these attributes
is invoked using two new IO_ flags: IO_NORMAL and IO_EXT.
These flags may be specified in the ioflags word of VOP_READ,
VOP_WRITE, and VOP_TRUNCATE. Specifying IO_NORMAL means that
you want to do I/O to the normal data part of the file and
IO_EXT means that you want to do I/O to the extended attributes
part of the file. IO_NORMAL and IO_EXT are mutually exclusive
for VOP_READ and VOP_WRITE, but may be specified individually
or together in the case of VOP_TRUNCATE. For example, when
removing a file, VOP_TRUNCATE is called with both IO_NORMAL
and IO_EXT set. For backward compatibility, if neither IO_NORMAL
nor IO_EXT is set, then IO_NORMAL is assumed.
Note that the BA_ and IO_ flags have been `merged' so that they
may both be used in the same flags word. This merger is possible
by assigning the IO_ flags to the low sixteen bits and the BA_
flags the high sixteen bits. This works because the high sixteen
bits of the IO_ word is reserved for read-ahead and help with
write clustering so will never be used for flags. This merge
lets us get away from code of the form:
if (ioflags & IO_SYNC)
flags |= BA_SYNC;
For the future, I have considered adding a new field to the
vattr structure, va_extsize. This addition could then be
exported through the stat structure to allow applications to
find out the size of the extended attribute storage and also
would provide a more standard interface for truncating them
(via VOP_SETATTR rather than VOP_TRUNCATE).
I am also contemplating adding a pathconf parameter (for
concreteness, lets call it _PC_MAX_EXTSIZE) which would
let an application determine the maximum size of the extended
atribute storage.
Sponsored by: DARPA & NAI Labs.
2002-07-19 07:29:39 +00:00
|
|
|
datablocks == 0)) {
|
1994-05-24 10:09:53 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (length != 0)
|
|
|
|
panic("ffs_truncate: partial truncate of symlink");
|
|
|
|
#endif
|
2002-06-21 06:18:05 +00:00
|
|
|
bzero(SHORTLINK(oip), (u_int)oip->i_size);
|
1994-05-24 10:09:53 +00:00
|
|
|
oip->i_size = 0;
|
2004-07-28 06:41:27 +00:00
|
|
|
DIP_SET(oip, i_size, 0);
|
1994-05-24 10:09:53 +00:00
|
|
|
oip->i_flag |= IN_CHANGE | IN_UPDATE;
|
Add support to UFS2 to provide storage for extended attributes.
As this code is not actually used by any of the existing
interfaces, it seems unlikely to break anything (famous
last words).
The internal kernel interface to manipulate these attributes
is invoked using two new IO_ flags: IO_NORMAL and IO_EXT.
These flags may be specified in the ioflags word of VOP_READ,
VOP_WRITE, and VOP_TRUNCATE. Specifying IO_NORMAL means that
you want to do I/O to the normal data part of the file and
IO_EXT means that you want to do I/O to the extended attributes
part of the file. IO_NORMAL and IO_EXT are mutually exclusive
for VOP_READ and VOP_WRITE, but may be specified individually
or together in the case of VOP_TRUNCATE. For example, when
removing a file, VOP_TRUNCATE is called with both IO_NORMAL
and IO_EXT set. For backward compatibility, if neither IO_NORMAL
nor IO_EXT is set, then IO_NORMAL is assumed.
Note that the BA_ and IO_ flags have been `merged' so that they
may both be used in the same flags word. This merger is possible
by assigning the IO_ flags to the low sixteen bits and the BA_
flags the high sixteen bits. This works because the high sixteen
bits of the IO_ word is reserved for read-ahead and help with
write clustering so will never be used for flags. This merge
lets us get away from code of the form:
if (ioflags & IO_SYNC)
flags |= BA_SYNC;
For the future, I have considered adding a new field to the
vattr structure, va_extsize. This addition could then be
exported through the stat structure to allow applications to
find out the size of the extended attribute storage and also
would provide a more standard interface for truncating them
(via VOP_SETATTR rather than VOP_TRUNCATE).
I am also contemplating adding a pathconf parameter (for
concreteness, lets call it _PC_MAX_EXTSIZE) which would
let an application determine the maximum size of the extended
atribute storage.
Sponsored by: DARPA & NAI Labs.
2002-07-19 07:29:39 +00:00
|
|
|
if (needextclean)
|
|
|
|
softdep_setup_freeblocks(oip, length, IO_EXT);
|
1999-01-07 16:14:19 +00:00
|
|
|
return (UFS_UPDATE(ovp, 1));
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
if (oip->i_size == length) {
|
|
|
|
oip->i_flag |= IN_CHANGE | IN_UPDATE;
|
Add support to UFS2 to provide storage for extended attributes.
As this code is not actually used by any of the existing
interfaces, it seems unlikely to break anything (famous
last words).
The internal kernel interface to manipulate these attributes
is invoked using two new IO_ flags: IO_NORMAL and IO_EXT.
These flags may be specified in the ioflags word of VOP_READ,
VOP_WRITE, and VOP_TRUNCATE. Specifying IO_NORMAL means that
you want to do I/O to the normal data part of the file and
IO_EXT means that you want to do I/O to the extended attributes
part of the file. IO_NORMAL and IO_EXT are mutually exclusive
for VOP_READ and VOP_WRITE, but may be specified individually
or together in the case of VOP_TRUNCATE. For example, when
removing a file, VOP_TRUNCATE is called with both IO_NORMAL
and IO_EXT set. For backward compatibility, if neither IO_NORMAL
nor IO_EXT is set, then IO_NORMAL is assumed.
Note that the BA_ and IO_ flags have been `merged' so that they
may both be used in the same flags word. This merger is possible
by assigning the IO_ flags to the low sixteen bits and the BA_
flags the high sixteen bits. This works because the high sixteen
bits of the IO_ word is reserved for read-ahead and help with
write clustering so will never be used for flags. This merge
lets us get away from code of the form:
if (ioflags & IO_SYNC)
flags |= BA_SYNC;
For the future, I have considered adding a new field to the
vattr structure, va_extsize. This addition could then be
exported through the stat structure to allow applications to
find out the size of the extended attribute storage and also
would provide a more standard interface for truncating them
(via VOP_SETATTR rather than VOP_TRUNCATE).
I am also contemplating adding a pathconf parameter (for
concreteness, lets call it _PC_MAX_EXTSIZE) which would
let an application determine the maximum size of the extended
atribute storage.
Sponsored by: DARPA & NAI Labs.
2002-07-19 07:29:39 +00:00
|
|
|
if (needextclean)
|
|
|
|
softdep_setup_freeblocks(oip, length, IO_EXT);
|
1999-01-07 16:14:19 +00:00
|
|
|
return (UFS_UPDATE(ovp, 0));
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
2002-01-16 04:59:09 +00:00
|
|
|
if (fs->fs_ronly)
|
|
|
|
panic("ffs_truncate: read-only filesystem");
|
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
|
2000-07-26 23:07:01 +00:00
|
|
|
if ((oip->i_flags & SF_SNAPSHOT) != 0)
|
|
|
|
ffs_snapremove(ovp);
|
1998-03-08 09:59:44 +00:00
|
|
|
ovp->v_lasta = ovp->v_clen = ovp->v_cstart = ovp->v_lastw = 0;
|
|
|
|
if (DOINGSOFTDEP(ovp)) {
|
Add support to UFS2 to provide storage for extended attributes.
As this code is not actually used by any of the existing
interfaces, it seems unlikely to break anything (famous
last words).
The internal kernel interface to manipulate these attributes
is invoked using two new IO_ flags: IO_NORMAL and IO_EXT.
These flags may be specified in the ioflags word of VOP_READ,
VOP_WRITE, and VOP_TRUNCATE. Specifying IO_NORMAL means that
you want to do I/O to the normal data part of the file and
IO_EXT means that you want to do I/O to the extended attributes
part of the file. IO_NORMAL and IO_EXT are mutually exclusive
for VOP_READ and VOP_WRITE, but may be specified individually
or together in the case of VOP_TRUNCATE. For example, when
removing a file, VOP_TRUNCATE is called with both IO_NORMAL
and IO_EXT set. For backward compatibility, if neither IO_NORMAL
nor IO_EXT is set, then IO_NORMAL is assumed.
Note that the BA_ and IO_ flags have been `merged' so that they
may both be used in the same flags word. This merger is possible
by assigning the IO_ flags to the low sixteen bits and the BA_
flags the high sixteen bits. This works because the high sixteen
bits of the IO_ word is reserved for read-ahead and help with
write clustering so will never be used for flags. This merge
lets us get away from code of the form:
if (ioflags & IO_SYNC)
flags |= BA_SYNC;
For the future, I have considered adding a new field to the
vattr structure, va_extsize. This addition could then be
exported through the stat structure to allow applications to
find out the size of the extended attribute storage and also
would provide a more standard interface for truncating them
(via VOP_SETATTR rather than VOP_TRUNCATE).
I am also contemplating adding a pathconf parameter (for
concreteness, lets call it _PC_MAX_EXTSIZE) which would
let an application determine the maximum size of the extended
atribute storage.
Sponsored by: DARPA & NAI Labs.
2002-07-19 07:29:39 +00:00
|
|
|
if (length > 0 || softdepslowdown) {
|
1998-03-08 09:59:44 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2005-01-11 07:36:22 +00:00
|
|
|
if ((error = VOP_FSYNC(ovp, MNT_WAIT, td)) != 0)
|
1998-03-08 09:59:44 +00:00
|
|
|
return (error);
|
2005-01-24 10:04:22 +00:00
|
|
|
UFS_LOCK(ump);
|
2001-05-08 07:42:20 +00:00
|
|
|
if (oip->i_flag & IN_SPACECOUNTED)
|
Add support to UFS2 to provide storage for extended attributes.
As this code is not actually used by any of the existing
interfaces, it seems unlikely to break anything (famous
last words).
The internal kernel interface to manipulate these attributes
is invoked using two new IO_ flags: IO_NORMAL and IO_EXT.
These flags may be specified in the ioflags word of VOP_READ,
VOP_WRITE, and VOP_TRUNCATE. Specifying IO_NORMAL means that
you want to do I/O to the normal data part of the file and
IO_EXT means that you want to do I/O to the extended attributes
part of the file. IO_NORMAL and IO_EXT are mutually exclusive
for VOP_READ and VOP_WRITE, but may be specified individually
or together in the case of VOP_TRUNCATE. For example, when
removing a file, VOP_TRUNCATE is called with both IO_NORMAL
and IO_EXT set. For backward compatibility, if neither IO_NORMAL
nor IO_EXT is set, then IO_NORMAL is assumed.
Note that the BA_ and IO_ flags have been `merged' so that they
may both be used in the same flags word. This merger is possible
by assigning the IO_ flags to the low sixteen bits and the BA_
flags the high sixteen bits. This works because the high sixteen
bits of the IO_ word is reserved for read-ahead and help with
write clustering so will never be used for flags. This merge
lets us get away from code of the form:
if (ioflags & IO_SYNC)
flags |= BA_SYNC;
For the future, I have considered adding a new field to the
vattr structure, va_extsize. This addition could then be
exported through the stat structure to allow applications to
find out the size of the extended attribute storage and also
would provide a more standard interface for truncating them
(via VOP_SETATTR rather than VOP_TRUNCATE).
I am also contemplating adding a pathconf parameter (for
concreteness, lets call it _PC_MAX_EXTSIZE) which would
let an application determine the maximum size of the extended
atribute storage.
Sponsored by: DARPA & NAI Labs.
2002-07-19 07:29:39 +00:00
|
|
|
fs->fs_pendingblocks -= datablocks;
|
2005-01-24 10:04:22 +00:00
|
|
|
UFS_UNLOCK(ump);
|
1998-03-08 09:59:44 +00:00
|
|
|
} else {
|
|
|
|
#ifdef QUOTA
|
Add support to UFS2 to provide storage for extended attributes.
As this code is not actually used by any of the existing
interfaces, it seems unlikely to break anything (famous
last words).
The internal kernel interface to manipulate these attributes
is invoked using two new IO_ flags: IO_NORMAL and IO_EXT.
These flags may be specified in the ioflags word of VOP_READ,
VOP_WRITE, and VOP_TRUNCATE. Specifying IO_NORMAL means that
you want to do I/O to the normal data part of the file and
IO_EXT means that you want to do I/O to the extended attributes
part of the file. IO_NORMAL and IO_EXT are mutually exclusive
for VOP_READ and VOP_WRITE, but may be specified individually
or together in the case of VOP_TRUNCATE. For example, when
removing a file, VOP_TRUNCATE is called with both IO_NORMAL
and IO_EXT set. For backward compatibility, if neither IO_NORMAL
nor IO_EXT is set, then IO_NORMAL is assumed.
Note that the BA_ and IO_ flags have been `merged' so that they
may both be used in the same flags word. This merger is possible
by assigning the IO_ flags to the low sixteen bits and the BA_
flags the high sixteen bits. This works because the high sixteen
bits of the IO_ word is reserved for read-ahead and help with
write clustering so will never be used for flags. This merge
lets us get away from code of the form:
if (ioflags & IO_SYNC)
flags |= BA_SYNC;
For the future, I have considered adding a new field to the
vattr structure, va_extsize. This addition could then be
exported through the stat structure to allow applications to
find out the size of the extended attribute storage and also
would provide a more standard interface for truncating them
(via VOP_SETATTR rather than VOP_TRUNCATE).
I am also contemplating adding a pathconf parameter (for
concreteness, lets call it _PC_MAX_EXTSIZE) which would
let an application determine the maximum size of the extended
atribute storage.
Sponsored by: DARPA & NAI Labs.
2002-07-19 07:29:39 +00:00
|
|
|
(void) chkdq(oip, -datablocks, NOCRED, 0);
|
1998-03-08 09:59:44 +00:00
|
|
|
#endif
|
Add support to UFS2 to provide storage for extended attributes.
As this code is not actually used by any of the existing
interfaces, it seems unlikely to break anything (famous
last words).
The internal kernel interface to manipulate these attributes
is invoked using two new IO_ flags: IO_NORMAL and IO_EXT.
These flags may be specified in the ioflags word of VOP_READ,
VOP_WRITE, and VOP_TRUNCATE. Specifying IO_NORMAL means that
you want to do I/O to the normal data part of the file and
IO_EXT means that you want to do I/O to the extended attributes
part of the file. IO_NORMAL and IO_EXT are mutually exclusive
for VOP_READ and VOP_WRITE, but may be specified individually
or together in the case of VOP_TRUNCATE. For example, when
removing a file, VOP_TRUNCATE is called with both IO_NORMAL
and IO_EXT set. For backward compatibility, if neither IO_NORMAL
nor IO_EXT is set, then IO_NORMAL is assumed.
Note that the BA_ and IO_ flags have been `merged' so that they
may both be used in the same flags word. This merger is possible
by assigning the IO_ flags to the low sixteen bits and the BA_
flags the high sixteen bits. This works because the high sixteen
bits of the IO_ word is reserved for read-ahead and help with
write clustering so will never be used for flags. This merge
lets us get away from code of the form:
if (ioflags & IO_SYNC)
flags |= BA_SYNC;
For the future, I have considered adding a new field to the
vattr structure, va_extsize. This addition could then be
exported through the stat structure to allow applications to
find out the size of the extended attribute storage and also
would provide a more standard interface for truncating them
(via VOP_SETATTR rather than VOP_TRUNCATE).
I am also contemplating adding a pathconf parameter (for
concreteness, lets call it _PC_MAX_EXTSIZE) which would
let an application determine the maximum size of the extended
atribute storage.
Sponsored by: DARPA & NAI Labs.
2002-07-19 07:29:39 +00:00
|
|
|
softdep_setup_freeblocks(oip, length, needextclean ?
|
|
|
|
IO_EXT | IO_NORMAL : IO_NORMAL);
|
2005-01-14 07:33:51 +00:00
|
|
|
vinvalbuf(ovp, needextclean ? 0 : V_NORMAL, td, 0, 0);
|
1998-03-08 09:59:44 +00:00
|
|
|
oip->i_flag |= IN_CHANGE | IN_UPDATE;
|
1999-01-07 16:14:19 +00:00
|
|
|
return (ffs_update(ovp, 0));
|
1998-03-08 09:59:44 +00:00
|
|
|
}
|
|
|
|
}
|
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);
|
Add support to UFS2 to provide storage for extended attributes.
As this code is not actually used by any of the existing
interfaces, it seems unlikely to break anything (famous
last words).
The internal kernel interface to manipulate these attributes
is invoked using two new IO_ flags: IO_NORMAL and IO_EXT.
These flags may be specified in the ioflags word of VOP_READ,
VOP_WRITE, and VOP_TRUNCATE. Specifying IO_NORMAL means that
you want to do I/O to the normal data part of the file and
IO_EXT means that you want to do I/O to the extended attributes
part of the file. IO_NORMAL and IO_EXT are mutually exclusive
for VOP_READ and VOP_WRITE, but may be specified individually
or together in the case of VOP_TRUNCATE. For example, when
removing a file, VOP_TRUNCATE is called with both IO_NORMAL
and IO_EXT set. For backward compatibility, if neither IO_NORMAL
nor IO_EXT is set, then IO_NORMAL is assumed.
Note that the BA_ and IO_ flags have been `merged' so that they
may both be used in the same flags word. This merger is possible
by assigning the IO_ flags to the low sixteen bits and the BA_
flags the high sixteen bits. This works because the high sixteen
bits of the IO_ word is reserved for read-ahead and help with
write clustering so will never be used for flags. This merge
lets us get away from code of the form:
if (ioflags & IO_SYNC)
flags |= BA_SYNC;
For the future, I have considered adding a new field to the
vattr structure, va_extsize. This addition could then be
exported through the stat structure to allow applications to
find out the size of the extended attribute storage and also
would provide a more standard interface for truncating them
(via VOP_SETATTR rather than VOP_TRUNCATE).
I am also contemplating adding a pathconf parameter (for
concreteness, lets call it _PC_MAX_EXTSIZE) which would
let an application determine the maximum size of the extended
atribute storage.
Sponsored by: DARPA & NAI Labs.
2002-07-19 07:29:39 +00:00
|
|
|
flags |= BA_CLRBUF;
|
|
|
|
error = UFS_BALLOC(ovp, length - 1, 1, cred, flags, &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;
|
2004-07-28 06:41:27 +00:00
|
|
|
DIP_SET(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;
|
Add support to UFS2 to provide storage for extended attributes.
As this code is not actually used by any of the existing
interfaces, it seems unlikely to break anything (famous
last words).
The internal kernel interface to manipulate these attributes
is invoked using two new IO_ flags: IO_NORMAL and IO_EXT.
These flags may be specified in the ioflags word of VOP_READ,
VOP_WRITE, and VOP_TRUNCATE. Specifying IO_NORMAL means that
you want to do I/O to the normal data part of the file and
IO_EXT means that you want to do I/O to the extended attributes
part of the file. IO_NORMAL and IO_EXT are mutually exclusive
for VOP_READ and VOP_WRITE, but may be specified individually
or together in the case of VOP_TRUNCATE. For example, when
removing a file, VOP_TRUNCATE is called with both IO_NORMAL
and IO_EXT set. For backward compatibility, if neither IO_NORMAL
nor IO_EXT is set, then IO_NORMAL is assumed.
Note that the BA_ and IO_ flags have been `merged' so that they
may both be used in the same flags word. This merger is possible
by assigning the IO_ flags to the low sixteen bits and the BA_
flags the high sixteen bits. This works because the high sixteen
bits of the IO_ word is reserved for read-ahead and help with
write clustering so will never be used for flags. This merge
lets us get away from code of the form:
if (ioflags & IO_SYNC)
flags |= BA_SYNC;
For the future, I have considered adding a new field to the
vattr structure, va_extsize. This addition could then be
exported through the stat structure to allow applications to
find out the size of the extended attribute storage and also
would provide a more standard interface for truncating them
(via VOP_SETATTR rather than VOP_TRUNCATE).
I am also contemplating adding a pathconf parameter (for
concreteness, lets call it _PC_MAX_EXTSIZE) which would
let an application determine the maximum size of the extended
atribute storage.
Sponsored by: DARPA & NAI Labs.
2002-07-19 07:29:39 +00:00
|
|
|
if (flags & IO_SYNC)
|
1994-05-24 10:09:53 +00:00
|
|
|
bwrite(bp);
|
|
|
|
else
|
|
|
|
bawrite(bp);
|
|
|
|
oip->i_flag |= IN_CHANGE | IN_UPDATE;
|
1999-01-07 16:14:19 +00:00
|
|
|
return (UFS_UPDATE(ovp, 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;
|
2004-07-28 06:41:27 +00:00
|
|
|
DIP_SET(oip, i_size, length);
|
1994-05-24 10:09:53 +00:00
|
|
|
} else {
|
|
|
|
lbn = lblkno(fs, length);
|
Add support to UFS2 to provide storage for extended attributes.
As this code is not actually used by any of the existing
interfaces, it seems unlikely to break anything (famous
last words).
The internal kernel interface to manipulate these attributes
is invoked using two new IO_ flags: IO_NORMAL and IO_EXT.
These flags may be specified in the ioflags word of VOP_READ,
VOP_WRITE, and VOP_TRUNCATE. Specifying IO_NORMAL means that
you want to do I/O to the normal data part of the file and
IO_EXT means that you want to do I/O to the extended attributes
part of the file. IO_NORMAL and IO_EXT are mutually exclusive
for VOP_READ and VOP_WRITE, but may be specified individually
or together in the case of VOP_TRUNCATE. For example, when
removing a file, VOP_TRUNCATE is called with both IO_NORMAL
and IO_EXT set. For backward compatibility, if neither IO_NORMAL
nor IO_EXT is set, then IO_NORMAL is assumed.
Note that the BA_ and IO_ flags have been `merged' so that they
may both be used in the same flags word. This merger is possible
by assigning the IO_ flags to the low sixteen bits and the BA_
flags the high sixteen bits. This works because the high sixteen
bits of the IO_ word is reserved for read-ahead and help with
write clustering so will never be used for flags. This merge
lets us get away from code of the form:
if (ioflags & IO_SYNC)
flags |= BA_SYNC;
For the future, I have considered adding a new field to the
vattr structure, va_extsize. This addition could then be
exported through the stat structure to allow applications to
find out the size of the extended attribute storage and also
would provide a more standard interface for truncating them
(via VOP_SETATTR rather than VOP_TRUNCATE).
I am also contemplating adding a pathconf parameter (for
concreteness, lets call it _PC_MAX_EXTSIZE) which would
let an application determine the maximum size of the extended
atribute storage.
Sponsored by: DARPA & NAI Labs.
2002-07-19 07:29:39 +00:00
|
|
|
flags |= BA_CLRBUF;
|
|
|
|
error = UFS_BALLOC(ovp, length - 1, 1, cred, flags, &bp);
|
1998-03-08 09:59:44 +00:00
|
|
|
if (error) {
|
1994-05-24 10:09:53 +00:00
|
|
|
return (error);
|
1998-03-08 09:59:44 +00:00
|
|
|
}
|
2001-12-13 05:07:48 +00:00
|
|
|
/*
|
|
|
|
* When we are doing soft updates and the UFS_BALLOC
|
|
|
|
* above fills in a direct block hole with a full sized
|
|
|
|
* block that will be truncated down to a fragment below,
|
|
|
|
* we must flush out the block dependency with an FSYNC
|
|
|
|
* so that we do not get a soft updates inconsistency
|
|
|
|
* when we create the fragment below.
|
|
|
|
*/
|
|
|
|
if (DOINGSOFTDEP(ovp) && lbn < NDADDR &&
|
|
|
|
fragroundup(fs, blkoff(fs, length)) < fs->fs_bsize &&
|
2005-01-11 07:36:22 +00:00
|
|
|
(error = VOP_FSYNC(ovp, MNT_WAIT, td)) != 0)
|
2001-12-13 05:07:48 +00:00
|
|
|
return (error);
|
1994-05-24 10:09:53 +00:00
|
|
|
oip->i_size = length;
|
2004-07-28 06:41:27 +00:00
|
|
|
DIP_SET(oip, i_size, length);
|
1994-05-24 10:09:53 +00:00
|
|
|
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;
|
Add support to UFS2 to provide storage for extended attributes.
As this code is not actually used by any of the existing
interfaces, it seems unlikely to break anything (famous
last words).
The internal kernel interface to manipulate these attributes
is invoked using two new IO_ flags: IO_NORMAL and IO_EXT.
These flags may be specified in the ioflags word of VOP_READ,
VOP_WRITE, and VOP_TRUNCATE. Specifying IO_NORMAL means that
you want to do I/O to the normal data part of the file and
IO_EXT means that you want to do I/O to the extended attributes
part of the file. IO_NORMAL and IO_EXT are mutually exclusive
for VOP_READ and VOP_WRITE, but may be specified individually
or together in the case of VOP_TRUNCATE. For example, when
removing a file, VOP_TRUNCATE is called with both IO_NORMAL
and IO_EXT set. For backward compatibility, if neither IO_NORMAL
nor IO_EXT is set, then IO_NORMAL is assumed.
Note that the BA_ and IO_ flags have been `merged' so that they
may both be used in the same flags word. This merger is possible
by assigning the IO_ flags to the low sixteen bits and the BA_
flags the high sixteen bits. This works because the high sixteen
bits of the IO_ word is reserved for read-ahead and help with
write clustering so will never be used for flags. This merge
lets us get away from code of the form:
if (ioflags & IO_SYNC)
flags |= BA_SYNC;
For the future, I have considered adding a new field to the
vattr structure, va_extsize. This addition could then be
exported through the stat structure to allow applications to
find out the size of the extended attribute storage and also
would provide a more standard interface for truncating them
(via VOP_SETATTR rather than VOP_TRUNCATE).
I am also contemplating adding a pathconf parameter (for
concreteness, lets call it _PC_MAX_EXTSIZE) which would
let an application determine the maximum size of the extended
atribute storage.
Sponsored by: DARPA & NAI Labs.
2002-07-19 07:29:39 +00:00
|
|
|
if (flags & IO_SYNC)
|
1994-05-24 10:09:53 +00:00
|
|
|
bwrite(bp);
|
|
|
|
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.
|
|
|
|
*/
|
2002-06-21 06:18:05 +00:00
|
|
|
for (level = TRIPLE; level >= SINGLE; level--) {
|
|
|
|
oldblks[NDADDR + level] = DIP(oip, i_ib[level]);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (lastiblock[level] < 0) {
|
2004-07-28 06:41:27 +00:00
|
|
|
DIP_SET(oip, i_ib[level], 0);
|
1994-05-24 10:09:53 +00:00
|
|
|
lastiblock[level] = -1;
|
|
|
|
}
|
2002-06-21 06:18:05 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < NDADDR; i++) {
|
|
|
|
oldblks[i] = DIP(oip, i_db[i]);
|
|
|
|
if (i > lastblock)
|
2004-07-28 06:41:27 +00:00
|
|
|
DIP_SET(oip, i_db[i], 0);
|
2002-06-21 06:18:05 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
oip->i_flag |= IN_CHANGE | IN_UPDATE;
|
2000-12-13 08:30:35 +00:00
|
|
|
allerror = UFS_UPDATE(ovp, 1);
|
1998-03-19 22:49:44 +00:00
|
|
|
|
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.
|
|
|
|
*/
|
2002-06-21 06:18:05 +00:00
|
|
|
for (i = 0; i < NDADDR; i++) {
|
|
|
|
newblks[i] = DIP(oip, i_db[i]);
|
2004-07-28 06:41:27 +00:00
|
|
|
DIP_SET(oip, i_db[i], oldblks[i]);
|
2002-06-21 06:18:05 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < NIADDR; i++) {
|
|
|
|
newblks[NDADDR + i] = DIP(oip, i_ib[i]);
|
2004-07-28 06:41:27 +00:00
|
|
|
DIP_SET(oip, i_ib[i], oldblks[NDADDR + i]);
|
2002-06-21 06:18:05 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
oip->i_size = osize;
|
2004-07-28 06:41:27 +00:00
|
|
|
DIP_SET(oip, i_size, osize);
|
1998-03-19 22:49:44 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
error = vtruncbuf(ovp, cred, td, length, fs->fs_bsize);
|
1998-03-19 22:49:44 +00:00
|
|
|
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--) {
|
2002-06-21 06:18:05 +00:00
|
|
|
bn = DIP(oip, i_ib[level]);
|
1994-05-24 10:09:53 +00:00
|
|
|
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) {
|
2004-07-28 06:41:27 +00:00
|
|
|
DIP_SET(oip, i_ib[level], 0);
|
2005-01-24 10:04:22 +00:00
|
|
|
ffs_blkfree(ump, fs, oip->i_devvp, bn,
|
|
|
|
fs->fs_bsize, oip->i_number);
|
1994-05-24 10:09:53 +00:00
|
|
|
blocksreleased += nblocks;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lastiblock[level] >= 0)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All whole direct blocks or frags.
|
|
|
|
*/
|
|
|
|
for (i = NDADDR - 1; i > lastblock; i--) {
|
2002-05-13 09:22:31 +00:00
|
|
|
long bsize;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2002-06-21 06:18:05 +00:00
|
|
|
bn = DIP(oip, i_db[i]);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (bn == 0)
|
|
|
|
continue;
|
2004-07-28 06:41:27 +00:00
|
|
|
DIP_SET(oip, i_db[i], 0);
|
1994-05-24 10:09:53 +00:00
|
|
|
bsize = blksize(fs, oip, i);
|
2005-01-24 10:04:22 +00:00
|
|
|
ffs_blkfree(ump, fs, oip->i_devvp, bn, bsize, oip->i_number);
|
1994-05-24 10:09:53 +00:00
|
|
|
blocksreleased += btodb(bsize);
|
|
|
|
}
|
|
|
|
if (lastblock < 0)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally, look for a change in size of the
|
|
|
|
* last direct block; release any frags.
|
|
|
|
*/
|
2002-06-21 06:18:05 +00:00
|
|
|
bn = DIP(oip, i_db[lastblock]);
|
1994-05-24 10:09:53 +00:00
|
|
|
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;
|
2004-07-28 06:41:27 +00:00
|
|
|
DIP_SET(oip, i_size, length);
|
1994-05-24 10:09:53 +00:00
|
|
|
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);
|
2005-01-24 10:04:22 +00:00
|
|
|
ffs_blkfree(ump, fs, oip->i_devvp, bn,
|
|
|
|
oldspace - newspace, oip->i_number);
|
1994-05-24 10:09:53 +00:00
|
|
|
blocksreleased += btodb(oldspace - newspace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
for (level = SINGLE; level <= TRIPLE; level++)
|
2002-06-21 06:18:05 +00:00
|
|
|
if (newblks[NDADDR + level] != DIP(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++)
|
2002-06-21 06:18:05 +00:00
|
|
|
if (newblks[i] != DIP(oip, i_db[i]))
|
1994-08-03 08:19:35 +00:00
|
|
|
panic("ffs_truncate2");
|
2002-09-25 02:49:48 +00:00
|
|
|
VI_LOCK(ovp);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (length == 0 &&
|
Add support to UFS2 to provide storage for extended attributes.
As this code is not actually used by any of the existing
interfaces, it seems unlikely to break anything (famous
last words).
The internal kernel interface to manipulate these attributes
is invoked using two new IO_ flags: IO_NORMAL and IO_EXT.
These flags may be specified in the ioflags word of VOP_READ,
VOP_WRITE, and VOP_TRUNCATE. Specifying IO_NORMAL means that
you want to do I/O to the normal data part of the file and
IO_EXT means that you want to do I/O to the extended attributes
part of the file. IO_NORMAL and IO_EXT are mutually exclusive
for VOP_READ and VOP_WRITE, but may be specified individually
or together in the case of VOP_TRUNCATE. For example, when
removing a file, VOP_TRUNCATE is called with both IO_NORMAL
and IO_EXT set. For backward compatibility, if neither IO_NORMAL
nor IO_EXT is set, then IO_NORMAL is assumed.
Note that the BA_ and IO_ flags have been `merged' so that they
may both be used in the same flags word. This merger is possible
by assigning the IO_ flags to the low sixteen bits and the BA_
flags the high sixteen bits. This works because the high sixteen
bits of the IO_ word is reserved for read-ahead and help with
write clustering so will never be used for flags. This merge
lets us get away from code of the form:
if (ioflags & IO_SYNC)
flags |= BA_SYNC;
For the future, I have considered adding a new field to the
vattr structure, va_extsize. This addition could then be
exported through the stat structure to allow applications to
find out the size of the extended attribute storage and also
would provide a more standard interface for truncating them
(via VOP_SETATTR rather than VOP_TRUNCATE).
I am also contemplating adding a pathconf parameter (for
concreteness, lets call it _PC_MAX_EXTSIZE) which would
let an application determine the maximum size of the extended
atribute storage.
Sponsored by: DARPA & NAI Labs.
2002-07-19 07:29:39 +00:00
|
|
|
(fs->fs_magic != FS_UFS2_MAGIC || oip->i_din2->di_extsize == 0) &&
|
2004-10-25 09:14:03 +00:00
|
|
|
(vp->v_bufobj.bo_dirty.bv_cnt > 0 ||
|
|
|
|
vp->v_bufobj.bo_clean.bv_cnt > 0))
|
1994-08-03 08:19:35 +00:00
|
|
|
panic("ffs_truncate3");
|
2002-09-25 02:49:48 +00:00
|
|
|
VI_UNLOCK(ovp);
|
1994-05-24 10:09:53 +00:00
|
|
|
#endif /* DIAGNOSTIC */
|
|
|
|
/*
|
|
|
|
* Put back the real size.
|
|
|
|
*/
|
|
|
|
oip->i_size = length;
|
2004-07-28 06:41:27 +00:00
|
|
|
DIP_SET(oip, i_size, length);
|
|
|
|
DIP_SET(oip, i_blocks, DIP(oip, i_blocks) - blocksreleased);
|
1998-03-19 22:49:44 +00:00
|
|
|
|
2002-06-21 06:18:05 +00:00
|
|
|
if (DIP(oip, i_blocks) < 0) /* sanity */
|
2004-07-28 06:41:27 +00:00
|
|
|
DIP_SET(oip, i_blocks, 0);
|
1994-05-24 10:09:53 +00:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ffs_indirtrunc(ip, lbn, dbn, lastbn, level, countp)
|
2002-05-13 09:22:31 +00:00
|
|
|
struct inode *ip;
|
2002-06-21 06:18:05 +00:00
|
|
|
ufs2_daddr_t lbn, lastbn;
|
|
|
|
ufs2_daddr_t dbn;
|
1994-05-24 10:09:53 +00:00
|
|
|
int level;
|
2002-06-21 06:18:05 +00:00
|
|
|
ufs2_daddr_t *countp;
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
|
|
|
struct buf *bp;
|
2002-05-13 09:22:31 +00:00
|
|
|
struct fs *fs = ip->i_fs;
|
1994-05-24 10:09:53 +00:00
|
|
|
struct vnode *vp;
|
2002-06-21 06:18:05 +00:00
|
|
|
caddr_t copy = NULL;
|
|
|
|
int i, nblocks, error = 0, allerror = 0;
|
|
|
|
ufs2_daddr_t nb, nlbn, last;
|
|
|
|
ufs2_daddr_t blkcount, factor, blocksreleased = 0;
|
|
|
|
ufs1_daddr_t *bap1 = NULL;
|
|
|
|
ufs2_daddr_t *bap2 = NULL;
|
|
|
|
# define BAP(ip, i) (((ip)->i_ump->um_fstype == UFS1) ? bap1[i] : bap2[i])
|
1994-05-24 10:09:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
2003-03-04 00:04:44 +00:00
|
|
|
bp = getblk(vp, lbn, (int)fs->fs_bsize, 0, 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 */
|
2000-03-20 10:44:49 +00:00
|
|
|
bp->b_iocmd = BIO_READ;
|
2000-04-02 15:24:56 +00:00
|
|
|
bp->b_flags &= ~B_INVAL;
|
|
|
|
bp->b_ioflags &= ~BIO_ERROR;
|
1994-05-24 10:09:53 +00:00
|
|
|
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);
|
2003-10-18 14:10:28 +00:00
|
|
|
bp->b_iooffset = dbtob(bp->b_blkno);
|
2004-10-24 20:03:41 +00:00
|
|
|
bstrategy(bp);
|
2000-04-29 16:25:22 +00:00
|
|
|
error = bufwait(bp);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
brelse(bp);
|
|
|
|
*countp = 0;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2002-06-21 06:18:05 +00:00
|
|
|
if (ip->i_ump->um_fstype == UFS1)
|
|
|
|
bap1 = (ufs1_daddr_t *)bp->b_data;
|
|
|
|
else
|
|
|
|
bap2 = (ufs2_daddr_t *)bp->b_data;
|
1996-11-05 08:19:40 +00:00
|
|
|
if (lastbn != -1) {
|
2003-02-19 05:47:46 +00:00
|
|
|
MALLOC(copy, caddr_t, fs->fs_bsize, M_TEMP, M_WAITOK);
|
2002-06-21 06:18:05 +00:00
|
|
|
bcopy((caddr_t)bp->b_data, copy, (u_int)fs->fs_bsize);
|
|
|
|
for (i = last + 1; i < NINDIR(fs); i++)
|
2004-07-28 06:41:27 +00:00
|
|
|
if (ip->i_ump->um_fstype == UFS1)
|
|
|
|
bap1[i] = 0;
|
|
|
|
else
|
|
|
|
bap2[i] = 0;
|
1999-07-13 18:20:13 +00:00
|
|
|
if (DOINGASYNC(vp)) {
|
|
|
|
bawrite(bp);
|
|
|
|
} else {
|
1996-11-05 08:19:40 +00:00
|
|
|
error = bwrite(bp);
|
|
|
|
if (error)
|
|
|
|
allerror = error;
|
|
|
|
}
|
2002-06-21 06:18:05 +00:00
|
|
|
if (ip->i_ump->um_fstype == UFS1)
|
|
|
|
bap1 = (ufs1_daddr_t *)copy;
|
|
|
|
else
|
|
|
|
bap2 = (ufs2_daddr_t *)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) {
|
2002-06-21 06:18:05 +00:00
|
|
|
nb = BAP(ip, i);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (nb == 0)
|
|
|
|
continue;
|
|
|
|
if (level > SINGLE) {
|
1999-01-28 00:57:57 +00:00
|
|
|
if ((error = ffs_indirtrunc(ip, nlbn, fsbtodb(fs, nb),
|
2002-06-21 06:18:05 +00:00
|
|
|
(ufs2_daddr_t)-1, level - 1, &blkcount)) != 0)
|
1994-05-24 10:09:53 +00:00
|
|
|
allerror = error;
|
|
|
|
blocksreleased += blkcount;
|
|
|
|
}
|
2005-01-24 10:04:22 +00:00
|
|
|
ffs_blkfree(ip->i_ump, fs, ip->i_devvp, nb, fs->fs_bsize,
|
|
|
|
ip->i_number);
|
1994-05-24 10:09:53 +00:00
|
|
|
blocksreleased += nblocks;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Recursively free last partial block.
|
|
|
|
*/
|
|
|
|
if (level > SINGLE && lastbn >= 0) {
|
|
|
|
last = lastbn % factor;
|
2002-06-21 06:18:05 +00:00
|
|
|
nb = BAP(ip, i);
|
1994-05-24 10:09:53 +00:00
|
|
|
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);
|
|
|
|
}
|
2002-06-21 06:18:05 +00:00
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
*countp = blocksreleased;
|
|
|
|
return (allerror);
|
|
|
|
}
|