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>
|
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/malloc.h>
|
Huge cleanup of random(4) code.
* GENERAL
- Update copyright.
- Make kernel options for RANDOM_YARROW and RANDOM_DUMMY. Set
neither to ON, which means we want Fortuna
- If there is no 'device random' in the kernel, there will be NO
random(4) device in the kernel, and the KERN_ARND sysctl will
return nothing. With RANDOM_DUMMY there will be a random(4) that
always blocks.
- Repair kern.arandom (KERN_ARND sysctl). The old version went
through arc4random(9) and was a bit weird.
- Adjust arc4random stirring a bit - the existing code looks a little
suspect.
- Fix the nasty pre- and post-read overloading by providing explictit
functions to do these tasks.
- Redo read_random(9) so as to duplicate random(4)'s read internals.
This makes it a first-class citizen rather than a hack.
- Move stuff out of locked regions when it does not need to be
there.
- Trim RANDOM_DEBUG printfs. Some are excess to requirement, some
behind boot verbose.
- Use SYSINIT to sequence the startup.
- Fix init/deinit sysctl stuff.
- Make relevant sysctls also tunables.
- Add different harvesting "styles" to allow for different requirements
(direct, queue, fast).
- Add harvesting of FFS atime events. This needs to be checked for
weighing down the FS code.
- Add harvesting of slab allocator events. This needs to be checked for
weighing down the allocator code.
- Fix the random(9) manpage.
- Loadable modules are not present for now. These will be re-engineered
when the dust settles.
- Use macros for locks.
- Fix comments.
* src/share/man/...
- Update the man pages.
* src/etc/...
- The startup/shutdown work is done in D2924.
* src/UPDATING
- Add UPDATING announcement.
* src/sys/dev/random/build.sh
- Add copyright.
- Add libz for unit tests.
* src/sys/dev/random/dummy.c
- Remove; no longer needed. Functionality incorporated into randomdev.*.
* live_entropy_sources.c live_entropy_sources.h
- Remove; content moved.
- move content to randomdev.[ch] and optimise.
* src/sys/dev/random/random_adaptors.c src/sys/dev/random/random_adaptors.h
- Remove; plugability is no longer used. Compile-time algorithm
selection is the way to go.
* src/sys/dev/random/random_harvestq.c src/sys/dev/random/random_harvestq.h
- Add early (re)boot-time randomness caching.
* src/sys/dev/random/randomdev_soft.c src/sys/dev/random/randomdev_soft.h
- Remove; no longer needed.
* src/sys/dev/random/uint128.h
- Provide a fake uint128_t; if a real one ever arrived, we can use
that instead. All that is needed here is N=0, N++, N==0, and some
localised trickery is used to manufacture a 128-bit 0ULLL.
* src/sys/dev/random/unit_test.c src/sys/dev/random/unit_test.h
- Improve unit tests; previously the testing human needed clairvoyance;
now the test will do a basic check of compressibility. Clairvoyant
talent is still a good idea.
- This is still a long way off a proper unit test.
* src/sys/dev/random/fortuna.c src/sys/dev/random/fortuna.h
- Improve messy union to just uint128_t.
- Remove unneeded 'static struct fortuna_start_cache'.
- Tighten up up arithmetic.
- Provide a method to allow eternal junk to be introduced; harden
it against blatant by compress/hashing.
- Assert that locks are held correctly.
- Fix the nasty pre- and post-read overloading by providing explictit
functions to do these tasks.
- Turn into self-sufficient module (no longer requires randomdev_soft.[ch])
* src/sys/dev/random/yarrow.c src/sys/dev/random/yarrow.h
- Improve messy union to just uint128_t.
- Remove unneeded 'staic struct start_cache'.
- Tighten up up arithmetic.
- Provide a method to allow eternal junk to be introduced; harden
it against blatant by compress/hashing.
- Assert that locks are held correctly.
- Fix the nasty pre- and post-read overloading by providing explictit
functions to do these tasks.
- Turn into self-sufficient module (no longer requires randomdev_soft.[ch])
- Fix some magic numbers elsewhere used as FAST and SLOW.
Differential Revision: https://reviews.freebsd.org/D2025
Reviewed by: vsevolod,delphij,rwatson,trasz,jmg
Approved by: so (delphij)
2015-06-30 17:00:45 +00:00
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/proc.h>
|
2016-04-07 04:23:25 +00:00
|
|
|
#include <sys/racct.h>
|
Huge cleanup of random(4) code.
* GENERAL
- Update copyright.
- Make kernel options for RANDOM_YARROW and RANDOM_DUMMY. Set
neither to ON, which means we want Fortuna
- If there is no 'device random' in the kernel, there will be NO
random(4) device in the kernel, and the KERN_ARND sysctl will
return nothing. With RANDOM_DUMMY there will be a random(4) that
always blocks.
- Repair kern.arandom (KERN_ARND sysctl). The old version went
through arc4random(9) and was a bit weird.
- Adjust arc4random stirring a bit - the existing code looks a little
suspect.
- Fix the nasty pre- and post-read overloading by providing explictit
functions to do these tasks.
- Redo read_random(9) so as to duplicate random(4)'s read internals.
This makes it a first-class citizen rather than a hack.
- Move stuff out of locked regions when it does not need to be
there.
- Trim RANDOM_DEBUG printfs. Some are excess to requirement, some
behind boot verbose.
- Use SYSINIT to sequence the startup.
- Fix init/deinit sysctl stuff.
- Make relevant sysctls also tunables.
- Add different harvesting "styles" to allow for different requirements
(direct, queue, fast).
- Add harvesting of FFS atime events. This needs to be checked for
weighing down the FS code.
- Add harvesting of slab allocator events. This needs to be checked for
weighing down the allocator code.
- Fix the random(9) manpage.
- Loadable modules are not present for now. These will be re-engineered
when the dust settles.
- Use macros for locks.
- Fix comments.
* src/share/man/...
- Update the man pages.
* src/etc/...
- The startup/shutdown work is done in D2924.
* src/UPDATING
- Add UPDATING announcement.
* src/sys/dev/random/build.sh
- Add copyright.
- Add libz for unit tests.
* src/sys/dev/random/dummy.c
- Remove; no longer needed. Functionality incorporated into randomdev.*.
* live_entropy_sources.c live_entropy_sources.h
- Remove; content moved.
- move content to randomdev.[ch] and optimise.
* src/sys/dev/random/random_adaptors.c src/sys/dev/random/random_adaptors.h
- Remove; plugability is no longer used. Compile-time algorithm
selection is the way to go.
* src/sys/dev/random/random_harvestq.c src/sys/dev/random/random_harvestq.h
- Add early (re)boot-time randomness caching.
* src/sys/dev/random/randomdev_soft.c src/sys/dev/random/randomdev_soft.h
- Remove; no longer needed.
* src/sys/dev/random/uint128.h
- Provide a fake uint128_t; if a real one ever arrived, we can use
that instead. All that is needed here is N=0, N++, N==0, and some
localised trickery is used to manufacture a 128-bit 0ULLL.
* src/sys/dev/random/unit_test.c src/sys/dev/random/unit_test.h
- Improve unit tests; previously the testing human needed clairvoyance;
now the test will do a basic check of compressibility. Clairvoyant
talent is still a good idea.
- This is still a long way off a proper unit test.
* src/sys/dev/random/fortuna.c src/sys/dev/random/fortuna.h
- Improve messy union to just uint128_t.
- Remove unneeded 'static struct fortuna_start_cache'.
- Tighten up up arithmetic.
- Provide a method to allow eternal junk to be introduced; harden
it against blatant by compress/hashing.
- Assert that locks are held correctly.
- Fix the nasty pre- and post-read overloading by providing explictit
functions to do these tasks.
- Turn into self-sufficient module (no longer requires randomdev_soft.[ch])
* src/sys/dev/random/yarrow.c src/sys/dev/random/yarrow.h
- Improve messy union to just uint128_t.
- Remove unneeded 'staic struct start_cache'.
- Tighten up up arithmetic.
- Provide a method to allow eternal junk to be introduced; harden
it against blatant by compress/hashing.
- Assert that locks are held correctly.
- Fix the nasty pre- and post-read overloading by providing explictit
functions to do these tasks.
- Turn into self-sufficient module (no longer requires randomdev_soft.[ch])
- Fix some magic numbers elsewhere used as FAST and SLOW.
Differential Revision: https://reviews.freebsd.org/D2025
Reviewed by: vsevolod,delphij,rwatson,trasz,jmg
Approved by: so (delphij)
2015-06-30 17:00:45 +00:00
|
|
|
#include <sys/random.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/resourcevar.h>
|
2013-05-31 00:43:41 +00:00
|
|
|
#include <sys/rwlock.h>
|
2000-07-26 23:07:01 +00:00
|
|
|
#include <sys/stat.h>
|
Huge cleanup of random(4) code.
* GENERAL
- Update copyright.
- Make kernel options for RANDOM_YARROW and RANDOM_DUMMY. Set
neither to ON, which means we want Fortuna
- If there is no 'device random' in the kernel, there will be NO
random(4) device in the kernel, and the KERN_ARND sysctl will
return nothing. With RANDOM_DUMMY there will be a random(4) that
always blocks.
- Repair kern.arandom (KERN_ARND sysctl). The old version went
through arc4random(9) and was a bit weird.
- Adjust arc4random stirring a bit - the existing code looks a little
suspect.
- Fix the nasty pre- and post-read overloading by providing explictit
functions to do these tasks.
- Redo read_random(9) so as to duplicate random(4)'s read internals.
This makes it a first-class citizen rather than a hack.
- Move stuff out of locked regions when it does not need to be
there.
- Trim RANDOM_DEBUG printfs. Some are excess to requirement, some
behind boot verbose.
- Use SYSINIT to sequence the startup.
- Fix init/deinit sysctl stuff.
- Make relevant sysctls also tunables.
- Add different harvesting "styles" to allow for different requirements
(direct, queue, fast).
- Add harvesting of FFS atime events. This needs to be checked for
weighing down the FS code.
- Add harvesting of slab allocator events. This needs to be checked for
weighing down the allocator code.
- Fix the random(9) manpage.
- Loadable modules are not present for now. These will be re-engineered
when the dust settles.
- Use macros for locks.
- Fix comments.
* src/share/man/...
- Update the man pages.
* src/etc/...
- The startup/shutdown work is done in D2924.
* src/UPDATING
- Add UPDATING announcement.
* src/sys/dev/random/build.sh
- Add copyright.
- Add libz for unit tests.
* src/sys/dev/random/dummy.c
- Remove; no longer needed. Functionality incorporated into randomdev.*.
* live_entropy_sources.c live_entropy_sources.h
- Remove; content moved.
- move content to randomdev.[ch] and optimise.
* src/sys/dev/random/random_adaptors.c src/sys/dev/random/random_adaptors.h
- Remove; plugability is no longer used. Compile-time algorithm
selection is the way to go.
* src/sys/dev/random/random_harvestq.c src/sys/dev/random/random_harvestq.h
- Add early (re)boot-time randomness caching.
* src/sys/dev/random/randomdev_soft.c src/sys/dev/random/randomdev_soft.h
- Remove; no longer needed.
* src/sys/dev/random/uint128.h
- Provide a fake uint128_t; if a real one ever arrived, we can use
that instead. All that is needed here is N=0, N++, N==0, and some
localised trickery is used to manufacture a 128-bit 0ULLL.
* src/sys/dev/random/unit_test.c src/sys/dev/random/unit_test.h
- Improve unit tests; previously the testing human needed clairvoyance;
now the test will do a basic check of compressibility. Clairvoyant
talent is still a good idea.
- This is still a long way off a proper unit test.
* src/sys/dev/random/fortuna.c src/sys/dev/random/fortuna.h
- Improve messy union to just uint128_t.
- Remove unneeded 'static struct fortuna_start_cache'.
- Tighten up up arithmetic.
- Provide a method to allow eternal junk to be introduced; harden
it against blatant by compress/hashing.
- Assert that locks are held correctly.
- Fix the nasty pre- and post-read overloading by providing explictit
functions to do these tasks.
- Turn into self-sufficient module (no longer requires randomdev_soft.[ch])
* src/sys/dev/random/yarrow.c src/sys/dev/random/yarrow.h
- Improve messy union to just uint128_t.
- Remove unneeded 'staic struct start_cache'.
- Tighten up up arithmetic.
- Provide a method to allow eternal junk to be introduced; harden
it against blatant by compress/hashing.
- Assert that locks are held correctly.
- Fix the nasty pre- and post-read overloading by providing explictit
functions to do these tasks.
- Turn into self-sufficient module (no longer requires randomdev_soft.[ch])
- Fix some magic numbers elsewhere used as FAST and SLOW.
Differential Revision: https://reviews.freebsd.org/D2025
Reviewed by: vsevolod,delphij,rwatson,trasz,jmg
Approved by: so (delphij)
2015-06-30 17:00:45 +00:00
|
|
|
#include <sys/vmmeter.h>
|
|
|
|
#include <sys/vnode.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>
|
2009-01-20 11:27:45 +00:00
|
|
|
#include <vm/vm_object.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
|
2006-10-10 09:20:54 +00:00
|
|
|
* later if not now. The IN_LAZYACCESS is set instead of IN_MODIFIED if the fs
|
|
|
|
* is currently being suspended (or is suspended) and vnode has been accessed.
|
|
|
|
* If we write now, then clear IN_MODIFIED, IN_LAZYACCESS 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;
|
2012-03-01 18:45:25 +00:00
|
|
|
int flags, error;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2006-10-10 09:20:54 +00:00
|
|
|
ASSERT_VOP_ELOCKED(vp, "ffs_update");
|
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);
|
2006-10-10 09:20:54 +00:00
|
|
|
ip->i_flag &= ~(IN_LAZYACCESS | IN_LAZYMOD | IN_MODIFIED);
|
1994-05-24 10:09:53 +00:00
|
|
|
fs = ip->i_fs;
|
2011-07-15 16:20:33 +00:00
|
|
|
if (fs->fs_ronly && ip->i_ump->um_fsckpid == 0)
|
2002-01-15 07:17:12 +00:00
|
|
|
return (0);
|
2012-03-01 18:45:25 +00:00
|
|
|
/*
|
|
|
|
* If we are updating a snapshot and another process is currently
|
|
|
|
* writing the buffer containing the inode for this snapshot then
|
|
|
|
* a deadlock can occur when it tries to check the snapshot to see
|
|
|
|
* if that block needs to be copied. Thus when updating a snapshot
|
|
|
|
* we check to see if the buffer is already locked, and if it is
|
|
|
|
* we drop the snapshot lock until the buffer has been written
|
|
|
|
* and is available to us. We have to grab a reference to the
|
|
|
|
* snapshot vnode to prevent it from being removed while we are
|
|
|
|
* waiting for the buffer.
|
|
|
|
*/
|
|
|
|
flags = 0;
|
|
|
|
if (IS_SNAPSHOT(ip))
|
|
|
|
flags = GB_LOCK_NOWAIT;
|
2012-03-28 21:21:19 +00:00
|
|
|
loop:
|
2012-03-01 18:45:25 +00:00
|
|
|
error = breadn_flags(ip->i_devvp,
|
|
|
|
fsbtodb(fs, ino_to_fsba(fs, ip->i_number)),
|
|
|
|
(int) fs->fs_bsize, 0, 0, 0, NOCRED, flags, &bp);
|
|
|
|
if (error != 0) {
|
2016-01-27 21:23:01 +00:00
|
|
|
if (error != EBUSY)
|
2012-03-01 18:45:25 +00:00
|
|
|
return (error);
|
|
|
|
KASSERT((IS_SNAPSHOT(ip)), ("EBUSY from non-snapshot"));
|
2012-03-28 21:21:19 +00:00
|
|
|
/*
|
|
|
|
* Wait for our inode block to become available.
|
|
|
|
*
|
|
|
|
* Hold a reference to the vnode to protect against
|
|
|
|
* ffs_snapgone(). Since we hold a reference, it can only
|
|
|
|
* get reclaimed (VI_DOOMED flag) in a forcible downgrade
|
|
|
|
* or unmount. For an unmount, the entire filesystem will be
|
|
|
|
* gone, so we cannot attempt to touch anything associated
|
|
|
|
* with it while the vnode is unlocked; all we can do is
|
|
|
|
* pause briefly and try again. If when we relock the vnode
|
|
|
|
* we discover that it has been reclaimed, updating it is no
|
|
|
|
* longer necessary and we can just return an error.
|
|
|
|
*/
|
|
|
|
vref(vp);
|
2012-03-01 18:45:25 +00:00
|
|
|
VOP_UNLOCK(vp, 0);
|
2012-03-28 21:21:19 +00:00
|
|
|
pause("ffsupd", 1);
|
2012-03-01 18:45:25 +00:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
|
|
|
vrele(vp);
|
2012-03-28 21:21:19 +00:00
|
|
|
if ((vp->v_iflag & VI_DOOMED) != 0)
|
|
|
|
return (ENOENT);
|
|
|
|
goto loop;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
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");
|
Huge cleanup of random(4) code.
* GENERAL
- Update copyright.
- Make kernel options for RANDOM_YARROW and RANDOM_DUMMY. Set
neither to ON, which means we want Fortuna
- If there is no 'device random' in the kernel, there will be NO
random(4) device in the kernel, and the KERN_ARND sysctl will
return nothing. With RANDOM_DUMMY there will be a random(4) that
always blocks.
- Repair kern.arandom (KERN_ARND sysctl). The old version went
through arc4random(9) and was a bit weird.
- Adjust arc4random stirring a bit - the existing code looks a little
suspect.
- Fix the nasty pre- and post-read overloading by providing explictit
functions to do these tasks.
- Redo read_random(9) so as to duplicate random(4)'s read internals.
This makes it a first-class citizen rather than a hack.
- Move stuff out of locked regions when it does not need to be
there.
- Trim RANDOM_DEBUG printfs. Some are excess to requirement, some
behind boot verbose.
- Use SYSINIT to sequence the startup.
- Fix init/deinit sysctl stuff.
- Make relevant sysctls also tunables.
- Add different harvesting "styles" to allow for different requirements
(direct, queue, fast).
- Add harvesting of FFS atime events. This needs to be checked for
weighing down the FS code.
- Add harvesting of slab allocator events. This needs to be checked for
weighing down the allocator code.
- Fix the random(9) manpage.
- Loadable modules are not present for now. These will be re-engineered
when the dust settles.
- Use macros for locks.
- Fix comments.
* src/share/man/...
- Update the man pages.
* src/etc/...
- The startup/shutdown work is done in D2924.
* src/UPDATING
- Add UPDATING announcement.
* src/sys/dev/random/build.sh
- Add copyright.
- Add libz for unit tests.
* src/sys/dev/random/dummy.c
- Remove; no longer needed. Functionality incorporated into randomdev.*.
* live_entropy_sources.c live_entropy_sources.h
- Remove; content moved.
- move content to randomdev.[ch] and optimise.
* src/sys/dev/random/random_adaptors.c src/sys/dev/random/random_adaptors.h
- Remove; plugability is no longer used. Compile-time algorithm
selection is the way to go.
* src/sys/dev/random/random_harvestq.c src/sys/dev/random/random_harvestq.h
- Add early (re)boot-time randomness caching.
* src/sys/dev/random/randomdev_soft.c src/sys/dev/random/randomdev_soft.h
- Remove; no longer needed.
* src/sys/dev/random/uint128.h
- Provide a fake uint128_t; if a real one ever arrived, we can use
that instead. All that is needed here is N=0, N++, N==0, and some
localised trickery is used to manufacture a 128-bit 0ULLL.
* src/sys/dev/random/unit_test.c src/sys/dev/random/unit_test.h
- Improve unit tests; previously the testing human needed clairvoyance;
now the test will do a basic check of compressibility. Clairvoyant
talent is still a good idea.
- This is still a long way off a proper unit test.
* src/sys/dev/random/fortuna.c src/sys/dev/random/fortuna.h
- Improve messy union to just uint128_t.
- Remove unneeded 'static struct fortuna_start_cache'.
- Tighten up up arithmetic.
- Provide a method to allow eternal junk to be introduced; harden
it against blatant by compress/hashing.
- Assert that locks are held correctly.
- Fix the nasty pre- and post-read overloading by providing explictit
functions to do these tasks.
- Turn into self-sufficient module (no longer requires randomdev_soft.[ch])
* src/sys/dev/random/yarrow.c src/sys/dev/random/yarrow.h
- Improve messy union to just uint128_t.
- Remove unneeded 'staic struct start_cache'.
- Tighten up up arithmetic.
- Provide a method to allow eternal junk to be introduced; harden
it against blatant by compress/hashing.
- Assert that locks are held correctly.
- Fix the nasty pre- and post-read overloading by providing explictit
functions to do these tasks.
- Turn into self-sufficient module (no longer requires randomdev_soft.[ch])
- Fix some magic numbers elsewhere used as FAST and SLOW.
Differential Revision: https://reviews.freebsd.org/D2025
Reviewed by: vsevolod,delphij,rwatson,trasz,jmg
Approved by: so (delphij)
2015-06-30 17:00:45 +00:00
|
|
|
if (ip->i_ump->um_fstype == UFS1) {
|
2002-06-21 06:18:05 +00:00
|
|
|
*((struct ufs1_dinode *)bp->b_data +
|
|
|
|
ino_to_fsbo(fs, ip->i_number)) = *ip->i_din1;
|
Huge cleanup of random(4) code.
* GENERAL
- Update copyright.
- Make kernel options for RANDOM_YARROW and RANDOM_DUMMY. Set
neither to ON, which means we want Fortuna
- If there is no 'device random' in the kernel, there will be NO
random(4) device in the kernel, and the KERN_ARND sysctl will
return nothing. With RANDOM_DUMMY there will be a random(4) that
always blocks.
- Repair kern.arandom (KERN_ARND sysctl). The old version went
through arc4random(9) and was a bit weird.
- Adjust arc4random stirring a bit - the existing code looks a little
suspect.
- Fix the nasty pre- and post-read overloading by providing explictit
functions to do these tasks.
- Redo read_random(9) so as to duplicate random(4)'s read internals.
This makes it a first-class citizen rather than a hack.
- Move stuff out of locked regions when it does not need to be
there.
- Trim RANDOM_DEBUG printfs. Some are excess to requirement, some
behind boot verbose.
- Use SYSINIT to sequence the startup.
- Fix init/deinit sysctl stuff.
- Make relevant sysctls also tunables.
- Add different harvesting "styles" to allow for different requirements
(direct, queue, fast).
- Add harvesting of FFS atime events. This needs to be checked for
weighing down the FS code.
- Add harvesting of slab allocator events. This needs to be checked for
weighing down the allocator code.
- Fix the random(9) manpage.
- Loadable modules are not present for now. These will be re-engineered
when the dust settles.
- Use macros for locks.
- Fix comments.
* src/share/man/...
- Update the man pages.
* src/etc/...
- The startup/shutdown work is done in D2924.
* src/UPDATING
- Add UPDATING announcement.
* src/sys/dev/random/build.sh
- Add copyright.
- Add libz for unit tests.
* src/sys/dev/random/dummy.c
- Remove; no longer needed. Functionality incorporated into randomdev.*.
* live_entropy_sources.c live_entropy_sources.h
- Remove; content moved.
- move content to randomdev.[ch] and optimise.
* src/sys/dev/random/random_adaptors.c src/sys/dev/random/random_adaptors.h
- Remove; plugability is no longer used. Compile-time algorithm
selection is the way to go.
* src/sys/dev/random/random_harvestq.c src/sys/dev/random/random_harvestq.h
- Add early (re)boot-time randomness caching.
* src/sys/dev/random/randomdev_soft.c src/sys/dev/random/randomdev_soft.h
- Remove; no longer needed.
* src/sys/dev/random/uint128.h
- Provide a fake uint128_t; if a real one ever arrived, we can use
that instead. All that is needed here is N=0, N++, N==0, and some
localised trickery is used to manufacture a 128-bit 0ULLL.
* src/sys/dev/random/unit_test.c src/sys/dev/random/unit_test.h
- Improve unit tests; previously the testing human needed clairvoyance;
now the test will do a basic check of compressibility. Clairvoyant
talent is still a good idea.
- This is still a long way off a proper unit test.
* src/sys/dev/random/fortuna.c src/sys/dev/random/fortuna.h
- Improve messy union to just uint128_t.
- Remove unneeded 'static struct fortuna_start_cache'.
- Tighten up up arithmetic.
- Provide a method to allow eternal junk to be introduced; harden
it against blatant by compress/hashing.
- Assert that locks are held correctly.
- Fix the nasty pre- and post-read overloading by providing explictit
functions to do these tasks.
- Turn into self-sufficient module (no longer requires randomdev_soft.[ch])
* src/sys/dev/random/yarrow.c src/sys/dev/random/yarrow.h
- Improve messy union to just uint128_t.
- Remove unneeded 'staic struct start_cache'.
- Tighten up up arithmetic.
- Provide a method to allow eternal junk to be introduced; harden
it against blatant by compress/hashing.
- Assert that locks are held correctly.
- Fix the nasty pre- and post-read overloading by providing explictit
functions to do these tasks.
- Turn into self-sufficient module (no longer requires randomdev_soft.[ch])
- Fix some magic numbers elsewhere used as FAST and SLOW.
Differential Revision: https://reviews.freebsd.org/D2025
Reviewed by: vsevolod,delphij,rwatson,trasz,jmg
Approved by: so (delphij)
2015-06-30 17:00:45 +00:00
|
|
|
/* XXX: FIX? The entropy here is desirable, but the harvesting may be expensive */
|
|
|
|
random_harvest_queue(&(ip->i_din1), sizeof(ip->i_din1), 1, RANDOM_FS_ATIME);
|
|
|
|
} else {
|
2002-06-21 06:18:05 +00:00
|
|
|
*((struct ufs2_dinode *)bp->b_data +
|
|
|
|
ino_to_fsbo(fs, ip->i_number)) = *ip->i_din2;
|
Huge cleanup of random(4) code.
* GENERAL
- Update copyright.
- Make kernel options for RANDOM_YARROW and RANDOM_DUMMY. Set
neither to ON, which means we want Fortuna
- If there is no 'device random' in the kernel, there will be NO
random(4) device in the kernel, and the KERN_ARND sysctl will
return nothing. With RANDOM_DUMMY there will be a random(4) that
always blocks.
- Repair kern.arandom (KERN_ARND sysctl). The old version went
through arc4random(9) and was a bit weird.
- Adjust arc4random stirring a bit - the existing code looks a little
suspect.
- Fix the nasty pre- and post-read overloading by providing explictit
functions to do these tasks.
- Redo read_random(9) so as to duplicate random(4)'s read internals.
This makes it a first-class citizen rather than a hack.
- Move stuff out of locked regions when it does not need to be
there.
- Trim RANDOM_DEBUG printfs. Some are excess to requirement, some
behind boot verbose.
- Use SYSINIT to sequence the startup.
- Fix init/deinit sysctl stuff.
- Make relevant sysctls also tunables.
- Add different harvesting "styles" to allow for different requirements
(direct, queue, fast).
- Add harvesting of FFS atime events. This needs to be checked for
weighing down the FS code.
- Add harvesting of slab allocator events. This needs to be checked for
weighing down the allocator code.
- Fix the random(9) manpage.
- Loadable modules are not present for now. These will be re-engineered
when the dust settles.
- Use macros for locks.
- Fix comments.
* src/share/man/...
- Update the man pages.
* src/etc/...
- The startup/shutdown work is done in D2924.
* src/UPDATING
- Add UPDATING announcement.
* src/sys/dev/random/build.sh
- Add copyright.
- Add libz for unit tests.
* src/sys/dev/random/dummy.c
- Remove; no longer needed. Functionality incorporated into randomdev.*.
* live_entropy_sources.c live_entropy_sources.h
- Remove; content moved.
- move content to randomdev.[ch] and optimise.
* src/sys/dev/random/random_adaptors.c src/sys/dev/random/random_adaptors.h
- Remove; plugability is no longer used. Compile-time algorithm
selection is the way to go.
* src/sys/dev/random/random_harvestq.c src/sys/dev/random/random_harvestq.h
- Add early (re)boot-time randomness caching.
* src/sys/dev/random/randomdev_soft.c src/sys/dev/random/randomdev_soft.h
- Remove; no longer needed.
* src/sys/dev/random/uint128.h
- Provide a fake uint128_t; if a real one ever arrived, we can use
that instead. All that is needed here is N=0, N++, N==0, and some
localised trickery is used to manufacture a 128-bit 0ULLL.
* src/sys/dev/random/unit_test.c src/sys/dev/random/unit_test.h
- Improve unit tests; previously the testing human needed clairvoyance;
now the test will do a basic check of compressibility. Clairvoyant
talent is still a good idea.
- This is still a long way off a proper unit test.
* src/sys/dev/random/fortuna.c src/sys/dev/random/fortuna.h
- Improve messy union to just uint128_t.
- Remove unneeded 'static struct fortuna_start_cache'.
- Tighten up up arithmetic.
- Provide a method to allow eternal junk to be introduced; harden
it against blatant by compress/hashing.
- Assert that locks are held correctly.
- Fix the nasty pre- and post-read overloading by providing explictit
functions to do these tasks.
- Turn into self-sufficient module (no longer requires randomdev_soft.[ch])
* src/sys/dev/random/yarrow.c src/sys/dev/random/yarrow.h
- Improve messy union to just uint128_t.
- Remove unneeded 'staic struct start_cache'.
- Tighten up up arithmetic.
- Provide a method to allow eternal junk to be introduced; harden
it against blatant by compress/hashing.
- Assert that locks are held correctly.
- Fix the nasty pre- and post-read overloading by providing explictit
functions to do these tasks.
- Turn into self-sufficient module (no longer requires randomdev_soft.[ch])
- Fix some magic numbers elsewhere used as FAST and SLOW.
Differential Revision: https://reviews.freebsd.org/D2025
Reviewed by: vsevolod,delphij,rwatson,trasz,jmg
Approved by: so (delphij)
2015-06-30 17:00:45 +00:00
|
|
|
/* XXX: FIX? The entropy here is desirable, but the harvesting may be expensive */
|
|
|
|
random_harvest_queue(&(ip->i_din2), sizeof(ip->i_din2), 1, RANDOM_FS_ATIME);
|
|
|
|
}
|
2012-03-11 21:25:42 +00:00
|
|
|
if (waitfor && !DOINGASYNC(vp))
|
2012-03-01 18:45:25 +00:00
|
|
|
error = bwrite(bp);
|
2012-03-11 20:23:46 +00:00
|
|
|
else if (vm_page_count_severe() || buf_dirty_count_severe()) {
|
|
|
|
bawrite(bp);
|
|
|
|
error = 0;
|
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);
|
2012-03-01 18:45:25 +00:00
|
|
|
error = 0;
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
2012-03-01 18:45:25 +00:00
|
|
|
return (error);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define SINGLE 0 /* index of single indirect block */
|
|
|
|
#define DOUBLE 1 /* index of double indirect block */
|
|
|
|
#define TRIPLE 2 /* index of triple indirect block */
|
|
|
|
/*
|
2005-04-05 08:49:41 +00:00
|
|
|
* Truncate the inode ip to at most length size, freeing the
|
1994-05-24 10:09:53 +00:00
|
|
|
* disk blocks.
|
|
|
|
*/
|
1994-05-25 09:21:21 +00:00
|
|
|
int
|
2012-04-23 13:21:28 +00:00
|
|
|
ffs_truncate(vp, length, flags, cred)
|
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;
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2005-04-05 08:49:41 +00:00
|
|
|
struct inode *ip;
|
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];
|
2016-02-24 01:58:40 +00:00
|
|
|
ufs2_daddr_t count, blocksreleased = 0, datablocks, blkno;
|
2008-03-22 09:15:16 +00:00
|
|
|
struct bufobj *bo;
|
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;
|
2011-06-10 22:48:35 +00:00
|
|
|
int softdeptrunc, journaltrunc;
|
|
|
|
int needextclean, extblocks;
|
2002-06-21 06:18:05 +00:00
|
|
|
int offset, size, level, nblocks;
|
2016-02-24 01:58:40 +00:00
|
|
|
int i, error, allerror, indiroff;
|
1994-05-24 10:09:53 +00:00
|
|
|
off_t osize;
|
|
|
|
|
2005-04-05 08:49:41 +00:00
|
|
|
ip = VTOI(vp);
|
|
|
|
fs = ip->i_fs;
|
|
|
|
ump = ip->i_ump;
|
2008-03-22 09:15:16 +00:00
|
|
|
bo = &vp->v_bufobj;
|
2005-01-24 10:04:22 +00:00
|
|
|
|
2005-02-22 23:56:42 +00:00
|
|
|
ASSERT_VOP_LOCKED(vp, "ffs_truncate");
|
|
|
|
|
1997-02-10 02:22:35 +00:00
|
|
|
if (length < 0)
|
1994-10-22 02:27:35 +00:00
|
|
|
return (EINVAL);
|
2010-04-24 07:05:35 +00:00
|
|
|
if (length > fs->fs_maxfilesize)
|
|
|
|
return (EFBIG);
|
2011-06-10 22:48:35 +00:00
|
|
|
#ifdef QUOTA
|
|
|
|
error = getinoquota(ip);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
#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
|
|
|
/*
|
|
|
|
* 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;
|
2010-07-06 07:11:04 +00:00
|
|
|
if (!DOINGSOFTDEP(vp) && !DOINGASYNC(vp))
|
|
|
|
flags |= IO_SYNC;
|
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 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.
|
|
|
|
*/
|
2010-04-24 07:05:35 +00:00
|
|
|
allerror = 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
|
|
|
needextclean = 0;
|
2011-06-10 22:48:35 +00:00
|
|
|
softdeptrunc = 0;
|
|
|
|
journaltrunc = DOINGSUJ(vp);
|
|
|
|
if (journaltrunc == 0 && DOINGSOFTDEP(vp) && length == 0)
|
|
|
|
softdeptrunc = !softdep_slowdown(vp);
|
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;
|
2005-04-05 08:49:41 +00:00
|
|
|
datablocks = DIP(ip, i_blocks);
|
|
|
|
if (fs->fs_magic == FS_UFS2_MAGIC && ip->i_din2->di_extsize > 0) {
|
|
|
|
extblocks = btodb(fragroundup(fs, ip->i_din2->di_extsize));
|
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 -= extblocks;
|
|
|
|
}
|
|
|
|
if ((flags & IO_EXT) && extblocks > 0) {
|
2011-06-10 22:48:35 +00:00
|
|
|
if (length != 0)
|
|
|
|
panic("ffs_truncate: partial trunc of extdata");
|
|
|
|
if (softdeptrunc || journaltrunc) {
|
|
|
|
if ((flags & IO_NORMAL) == 0)
|
|
|
|
goto extclean;
|
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
|
|
|
needextclean = 1;
|
|
|
|
} else {
|
2012-03-25 00:02:37 +00:00
|
|
|
if ((error = ffs_syncvnode(vp, MNT_WAIT, 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
|
|
|
return (error);
|
|
|
|
#ifdef QUOTA
|
2005-04-05 08:49:41 +00:00
|
|
|
(void) chkdq(ip, -extblocks, NOCRED, 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
|
|
|
#endif
|
2008-10-10 21:23:50 +00:00
|
|
|
vinvalbuf(vp, V_ALT, 0, 0);
|
2011-08-25 08:17:39 +00:00
|
|
|
vn_pages_remove(vp,
|
2009-01-20 22:00:19 +00:00
|
|
|
OFF_TO_IDX(lblktosize(fs, -extblocks)), 0);
|
2011-06-10 22:48:35 +00:00
|
|
|
osize = ip->i_din2->di_extsize;
|
|
|
|
ip->i_din2->di_blocks -= extblocks;
|
2005-04-05 08:49:41 +00:00
|
|
|
ip->i_din2->di_extsize = 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
|
|
|
for (i = 0; i < NXADDR; i++) {
|
2005-04-05 08:49:41 +00:00
|
|
|
oldblks[i] = ip->i_din2->di_extb[i];
|
|
|
|
ip->i_din2->di_extb[i] = 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
|
|
|
}
|
2009-01-27 21:48:47 +00:00
|
|
|
ip->i_flag |= IN_CHANGE;
|
2012-03-11 20:26:19 +00:00
|
|
|
if ((error = ffs_update(vp, !DOINGASYNC(vp))))
|
2011-06-10 22:48:35 +00:00
|
|
|
return (error);
|
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
|
|
|
for (i = 0; i < NXADDR; i++) {
|
|
|
|
if (oldblks[i] == 0)
|
|
|
|
continue;
|
2005-04-05 08:49:41 +00:00
|
|
|
ffs_blkfree(ump, fs, ip->i_devvp, oldblks[i],
|
2011-06-15 23:19:09 +00:00
|
|
|
sblksize(fs, osize, i), ip->i_number,
|
|
|
|
vp->v_type, NULL);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-10 22:48:35 +00:00
|
|
|
if ((flags & IO_NORMAL) == 0)
|
|
|
|
return (0);
|
2005-04-05 08:49:41 +00:00
|
|
|
if (vp->v_type == VLNK &&
|
|
|
|
(ip->i_size < vp->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)) {
|
2007-11-08 17:21:51 +00:00
|
|
|
#ifdef INVARIANTS
|
1994-05-24 10:09:53 +00:00
|
|
|
if (length != 0)
|
|
|
|
panic("ffs_truncate: partial truncate of symlink");
|
|
|
|
#endif
|
2005-04-05 08:49:41 +00:00
|
|
|
bzero(SHORTLINK(ip), (u_int)ip->i_size);
|
|
|
|
ip->i_size = 0;
|
|
|
|
DIP_SET(ip, i_size, 0);
|
|
|
|
ip->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)
|
2011-06-10 22:48:35 +00:00
|
|
|
goto extclean;
|
2012-03-11 20:26:19 +00:00
|
|
|
return (ffs_update(vp, !DOINGASYNC(vp)));
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
2005-04-05 08:49:41 +00:00
|
|
|
if (ip->i_size == length) {
|
|
|
|
ip->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)
|
2011-06-10 22:48:35 +00:00
|
|
|
goto extclean;
|
2012-03-11 20:26:19 +00:00
|
|
|
return (ffs_update(vp, 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");
|
2012-03-01 18:45:25 +00:00
|
|
|
if (IS_SNAPSHOT(ip))
|
2005-04-05 08:49:41 +00:00
|
|
|
ffs_snapremove(vp);
|
|
|
|
vp->v_lasta = vp->v_clen = vp->v_cstart = vp->v_lastw = 0;
|
2010-04-24 07:05:35 +00:00
|
|
|
osize = ip->i_size;
|
|
|
|
/*
|
|
|
|
* Lengthen the size of the file. We must ensure that the
|
|
|
|
* last byte of the file is allocated. Since the smallest
|
|
|
|
* value of osize is 0, length will be at least 1.
|
|
|
|
*/
|
|
|
|
if (osize < length) {
|
|
|
|
vnode_pager_setsize(vp, length);
|
|
|
|
flags |= BA_CLRBUF;
|
|
|
|
error = UFS_BALLOC(vp, length - 1, 1, cred, flags, &bp);
|
|
|
|
if (error) {
|
|
|
|
vnode_pager_setsize(vp, osize);
|
2011-06-10 22:48:35 +00:00
|
|
|
return (error);
|
2010-04-24 07:05:35 +00:00
|
|
|
}
|
|
|
|
ip->i_size = length;
|
|
|
|
DIP_SET(ip, i_size, length);
|
|
|
|
if (bp->b_bufsize == fs->fs_bsize)
|
|
|
|
bp->b_flags |= B_CLUSTEROK;
|
|
|
|
if (flags & IO_SYNC)
|
|
|
|
bwrite(bp);
|
2012-03-11 20:26:19 +00:00
|
|
|
else if (DOINGASYNC(vp))
|
|
|
|
bdwrite(bp);
|
2010-04-24 07:05:35 +00:00
|
|
|
else
|
|
|
|
bawrite(bp);
|
|
|
|
ip->i_flag |= IN_CHANGE | IN_UPDATE;
|
2012-03-11 20:26:19 +00:00
|
|
|
return (ffs_update(vp, !DOINGASYNC(vp)));
|
2010-04-24 07:05:35 +00:00
|
|
|
}
|
2016-02-24 01:58:40 +00:00
|
|
|
/*
|
|
|
|
* Lookup block number for a given offset. Zero length files
|
|
|
|
* have no blocks, so return a blkno of -1.
|
|
|
|
*/
|
|
|
|
lbn = lblkno(fs, length - 1);
|
|
|
|
if (length == 0) {
|
|
|
|
blkno = -1;
|
|
|
|
} else if (lbn < NDADDR) {
|
|
|
|
blkno = DIP(ip, i_db[lbn]);
|
|
|
|
} else {
|
|
|
|
error = UFS_BALLOC(vp, lblktosize(fs, (off_t)lbn), fs->fs_bsize,
|
|
|
|
cred, BA_METAONLY, &bp);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
indiroff = (lbn - NDADDR) % NINDIR(fs);
|
|
|
|
if (ip->i_ump->um_fstype == UFS1)
|
|
|
|
blkno = ((ufs1_daddr_t *)(bp->b_data))[indiroff];
|
|
|
|
else
|
|
|
|
blkno = ((ufs2_daddr_t *)(bp->b_data))[indiroff];
|
|
|
|
/*
|
|
|
|
* If the block number is non-zero, then the indirect block
|
|
|
|
* must have been previously allocated and need not be written.
|
|
|
|
* If the block number is zero, then we may have allocated
|
|
|
|
* the indirect block and hence need to write it out.
|
|
|
|
*/
|
|
|
|
if (blkno != 0)
|
|
|
|
brelse(bp);
|
|
|
|
else if (DOINGSOFTDEP(vp) || DOINGASYNC(vp))
|
|
|
|
bdwrite(bp);
|
|
|
|
else
|
|
|
|
bwrite(bp);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If the block number at the new end of the file is zero,
|
|
|
|
* then we must allocate it to ensure that the last block of
|
|
|
|
* the file is allocated. Soft updates does not handle this
|
|
|
|
* case, so here we have to clean up the soft updates data
|
|
|
|
* structures describing the allocation past the truncation
|
|
|
|
* point. Finding and deallocating those structures is a lot of
|
|
|
|
* work. Since partial truncation with a hole at the end occurs
|
|
|
|
* rarely, we solve the problem by syncing the file so that it
|
|
|
|
* will have no soft updates data structures left.
|
|
|
|
*/
|
|
|
|
if (blkno == 0 && (error = ffs_syncvnode(vp, MNT_WAIT, 0)) != 0)
|
|
|
|
return (error);
|
|
|
|
if (blkno != 0 && DOINGSOFTDEP(vp)) {
|
2011-06-10 22:48:35 +00:00
|
|
|
if (softdeptrunc == 0 && journaltrunc == 0) {
|
1998-03-08 09:59:44 +00:00
|
|
|
/*
|
2016-02-24 01:58:40 +00:00
|
|
|
* If soft updates cannot handle this truncation,
|
|
|
|
* clean up soft dependency data structures and
|
|
|
|
* fall through to the synchronous truncation.
|
1998-03-08 09:59:44 +00:00
|
|
|
*/
|
2012-03-25 00:02:37 +00:00
|
|
|
if ((error = ffs_syncvnode(vp, MNT_WAIT, 0)) != 0)
|
2011-06-10 22:48:35 +00:00
|
|
|
return (error);
|
1998-03-08 09:59:44 +00:00
|
|
|
} else {
|
2011-06-10 22:48:35 +00:00
|
|
|
flags = IO_NORMAL | (needextclean ? IO_EXT: 0);
|
|
|
|
if (journaltrunc)
|
|
|
|
softdep_journal_freeblocks(ip, cred, length,
|
|
|
|
flags);
|
|
|
|
else
|
|
|
|
softdep_setup_freeblocks(ip, length, flags);
|
2005-02-22 23:56:42 +00:00
|
|
|
ASSERT_VOP_LOCKED(vp, "ffs_truncate1");
|
2011-06-10 22:48:35 +00:00
|
|
|
if (journaltrunc == 0) {
|
|
|
|
ip->i_flag |= IN_CHANGE | IN_UPDATE;
|
|
|
|
error = ffs_update(vp, 0);
|
|
|
|
}
|
|
|
|
return (error);
|
2009-01-20 11:30:22 +00:00
|
|
|
}
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
/*
|
2016-02-24 01:58:40 +00:00
|
|
|
* Shorten the size of the file. If the last block of the
|
|
|
|
* shortened file is unallocated, we must allocate it.
|
|
|
|
* Additionally, if the file is not being truncated to a
|
|
|
|
* block boundary, the contents of the partial block
|
|
|
|
* following the end of the file must be zero'ed in
|
|
|
|
* case it ever becomes accessible again because of
|
|
|
|
* subsequent file growth. Directories however are not
|
1998-06-14 19:31:28 +00:00
|
|
|
* zero'ed as they should grow back initialized to empty.
|
1994-05-24 10:09:53 +00:00
|
|
|
*/
|
|
|
|
offset = blkoff(fs, length);
|
2016-02-24 01:58:40 +00:00
|
|
|
if (blkno != 0 && offset == 0) {
|
2005-04-05 08:49:41 +00:00
|
|
|
ip->i_size = length;
|
|
|
|
DIP_SET(ip, 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;
|
2005-04-05 08:49:41 +00:00
|
|
|
error = UFS_BALLOC(vp, length - 1, 1, cred, flags, &bp);
|
2010-04-24 07:05:35 +00:00
|
|
|
if (error)
|
2011-06-10 22:48:35 +00:00
|
|
|
return (error);
|
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.
|
|
|
|
*/
|
2005-04-05 08:49:41 +00:00
|
|
|
if (DOINGSOFTDEP(vp) && lbn < NDADDR &&
|
2001-12-13 05:07:48 +00:00
|
|
|
fragroundup(fs, blkoff(fs, length)) < fs->fs_bsize &&
|
2012-03-25 00:02:37 +00:00
|
|
|
(error = ffs_syncvnode(vp, MNT_WAIT, 0)) != 0)
|
2011-06-10 22:48:35 +00:00
|
|
|
return (error);
|
2005-04-05 08:49:41 +00:00
|
|
|
ip->i_size = length;
|
|
|
|
DIP_SET(ip, i_size, length);
|
|
|
|
size = blksize(fs, ip, lbn);
|
2016-02-24 01:58:40 +00:00
|
|
|
if (vp->v_type != VDIR && offset != 0)
|
1998-06-14 19:31:28 +00:00
|
|
|
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);
|
2012-03-11 20:26:19 +00:00
|
|
|
else if (DOINGASYNC(vp))
|
|
|
|
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.
|
|
|
|
*/
|
2002-06-21 06:18:05 +00:00
|
|
|
for (level = TRIPLE; level >= SINGLE; level--) {
|
2005-04-05 08:49:41 +00:00
|
|
|
oldblks[NDADDR + level] = DIP(ip, i_ib[level]);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (lastiblock[level] < 0) {
|
2005-04-05 08:49:41 +00:00
|
|
|
DIP_SET(ip, 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++) {
|
2005-04-05 08:49:41 +00:00
|
|
|
oldblks[i] = DIP(ip, i_db[i]);
|
2002-06-21 06:18:05 +00:00
|
|
|
if (i > lastblock)
|
2005-04-05 08:49:41 +00:00
|
|
|
DIP_SET(ip, i_db[i], 0);
|
2002-06-21 06:18:05 +00:00
|
|
|
}
|
2005-04-05 08:49:41 +00:00
|
|
|
ip->i_flag |= IN_CHANGE | IN_UPDATE;
|
2012-03-11 20:26:19 +00:00
|
|
|
allerror = ffs_update(vp, !DOINGASYNC(vp));
|
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++) {
|
2005-04-05 08:49:41 +00:00
|
|
|
newblks[i] = DIP(ip, i_db[i]);
|
|
|
|
DIP_SET(ip, i_db[i], oldblks[i]);
|
2002-06-21 06:18:05 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < NIADDR; i++) {
|
2005-04-05 08:49:41 +00:00
|
|
|
newblks[NDADDR + i] = DIP(ip, i_ib[i]);
|
|
|
|
DIP_SET(ip, i_ib[i], oldblks[NDADDR + i]);
|
2002-06-21 06:18:05 +00:00
|
|
|
}
|
2005-04-05 08:49:41 +00:00
|
|
|
ip->i_size = osize;
|
|
|
|
DIP_SET(ip, i_size, osize);
|
1998-03-19 22:49:44 +00:00
|
|
|
|
2012-04-23 13:21:28 +00:00
|
|
|
error = vtruncbuf(vp, cred, 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--) {
|
2005-04-05 08:49:41 +00:00
|
|
|
bn = DIP(ip, i_ib[level]);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (bn != 0) {
|
2005-04-05 08:49:41 +00:00
|
|
|
error = ffs_indirtrunc(ip, indir_lbn[level],
|
1994-05-24 10:09:53 +00:00
|
|
|
fsbtodb(fs, bn), lastiblock[level], level, &count);
|
|
|
|
if (error)
|
|
|
|
allerror = error;
|
|
|
|
blocksreleased += count;
|
|
|
|
if (lastiblock[level] < 0) {
|
2005-04-05 08:49:41 +00:00
|
|
|
DIP_SET(ip, i_ib[level], 0);
|
|
|
|
ffs_blkfree(ump, fs, ip->i_devvp, bn,
|
2011-06-15 23:19:09 +00:00
|
|
|
fs->fs_bsize, ip->i_number,
|
|
|
|
vp->v_type, NULL);
|
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
|
|
|
|
2005-04-05 08:49:41 +00:00
|
|
|
bn = DIP(ip, i_db[i]);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (bn == 0)
|
|
|
|
continue;
|
2005-04-05 08:49:41 +00:00
|
|
|
DIP_SET(ip, i_db[i], 0);
|
|
|
|
bsize = blksize(fs, ip, i);
|
2010-04-24 07:05:35 +00:00
|
|
|
ffs_blkfree(ump, fs, ip->i_devvp, bn, bsize, ip->i_number,
|
2011-06-15 23:19:09 +00:00
|
|
|
vp->v_type, NULL);
|
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.
|
|
|
|
*/
|
2005-04-05 08:49:41 +00:00
|
|
|
bn = DIP(ip, 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.
|
|
|
|
*/
|
2005-04-05 08:49:41 +00:00
|
|
|
oldspace = blksize(fs, ip, lastblock);
|
|
|
|
ip->i_size = length;
|
|
|
|
DIP_SET(ip, i_size, length);
|
|
|
|
newspace = blksize(fs, ip, lastblock);
|
1994-05-24 10:09:53 +00:00
|
|
|
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-04-05 08:49:41 +00:00
|
|
|
ffs_blkfree(ump, fs, ip->i_devvp, bn,
|
2011-06-15 23:19:09 +00:00
|
|
|
oldspace - newspace, ip->i_number, vp->v_type, NULL);
|
1994-05-24 10:09:53 +00:00
|
|
|
blocksreleased += btodb(oldspace - newspace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done:
|
2007-11-08 17:21:51 +00:00
|
|
|
#ifdef INVARIANTS
|
1994-05-24 10:09:53 +00:00
|
|
|
for (level = SINGLE; level <= TRIPLE; level++)
|
2005-04-05 08:49:41 +00:00
|
|
|
if (newblks[NDADDR + level] != DIP(ip, 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++)
|
2005-04-05 08:49:41 +00:00
|
|
|
if (newblks[i] != DIP(ip, i_db[i]))
|
1994-08-03 08:19:35 +00:00
|
|
|
panic("ffs_truncate2");
|
2008-03-22 09:15:16 +00:00
|
|
|
BO_LOCK(bo);
|
1994-05-24 10:09:53 +00:00
|
|
|
if (length == 0 &&
|
2005-04-05 08:49:41 +00:00
|
|
|
(fs->fs_magic != FS_UFS2_MAGIC || ip->i_din2->di_extsize == 0) &&
|
2008-03-22 09:15:16 +00:00
|
|
|
(bo->bo_dirty.bv_cnt > 0 || bo->bo_clean.bv_cnt > 0))
|
1994-08-03 08:19:35 +00:00
|
|
|
panic("ffs_truncate3");
|
2008-03-22 09:15:16 +00:00
|
|
|
BO_UNLOCK(bo);
|
2007-11-08 17:21:51 +00:00
|
|
|
#endif /* INVARIANTS */
|
1994-05-24 10:09:53 +00:00
|
|
|
/*
|
|
|
|
* Put back the real size.
|
|
|
|
*/
|
2005-04-05 08:49:41 +00:00
|
|
|
ip->i_size = length;
|
|
|
|
DIP_SET(ip, i_size, length);
|
2013-02-03 17:16:32 +00:00
|
|
|
if (DIP(ip, i_blocks) >= blocksreleased)
|
|
|
|
DIP_SET(ip, i_blocks, DIP(ip, i_blocks) - blocksreleased);
|
|
|
|
else /* sanity */
|
2005-04-05 08:49:41 +00:00
|
|
|
DIP_SET(ip, i_blocks, 0);
|
|
|
|
ip->i_flag |= IN_CHANGE;
|
1994-05-24 10:09:53 +00:00
|
|
|
#ifdef QUOTA
|
2005-04-05 08:49:41 +00:00
|
|
|
(void) chkdq(ip, -blocksreleased, NOCRED, 0);
|
1994-05-24 10:09:53 +00:00
|
|
|
#endif
|
2011-06-10 22:48:35 +00:00
|
|
|
return (allerror);
|
|
|
|
|
|
|
|
extclean:
|
|
|
|
if (journaltrunc)
|
|
|
|
softdep_journal_freeblocks(ip, cred, length, IO_EXT);
|
|
|
|
else
|
|
|
|
softdep_setup_freeblocks(ip, length, IO_EXT);
|
2016-05-17 21:30:58 +00:00
|
|
|
return (ffs_update(vp, (flags & IO_SYNC) != 0 || !DOINGASYNC(vp)));
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2010-11-11 11:35:42 +00:00
|
|
|
factor = lbn_offset(fs, level);
|
1994-05-24 10:09:53 +00:00
|
|
|
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) {
|
2016-04-07 04:23:25 +00:00
|
|
|
#ifdef RACCT
|
|
|
|
if (racct_enable) {
|
|
|
|
PROC_LOCK(curproc);
|
|
|
|
racct_add_buf(curproc, bp, 0);
|
|
|
|
PROC_UNLOCK(curproc);
|
|
|
|
}
|
|
|
|
#endif /* RACCT */
|
2007-06-01 01:12:45 +00:00
|
|
|
curthread->td_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) {
|
2008-10-23 15:53:51 +00:00
|
|
|
copy = malloc(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)) {
|
2012-03-11 20:26:19 +00:00
|
|
|
bdwrite(bp);
|
1999-07-13 18:20:13 +00:00
|
|
|
} 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,
|
2011-06-15 23:19:09 +00:00
|
|
|
ip->i_number, vp->v_type, NULL);
|
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) {
|
2008-10-23 15:53:51 +00:00
|
|
|
free(copy, M_TEMP);
|
1996-11-05 08:19:40 +00:00
|
|
|
} 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);
|
|
|
|
}
|
2008-09-16 10:59:35 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
ffs_rdonly(struct inode *ip)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (ip->i_ump->um_fs->fs_ronly != 0);
|
|
|
|
}
|
|
|
|
|