summaryrefslogtreecommitdiff
path: root/sys/ufs/ffs/ffs_alloc.c
diff options
context:
space:
mode:
authorConstantine Sapuntzakis <csapuntz@cvs.openbsd.org>2001-11-21 21:23:57 +0000
committerConstantine Sapuntzakis <csapuntz@cvs.openbsd.org>2001-11-21 21:23:57 +0000
commit2eb4d9d2d38cc3eb793eb11a9635b95d702fbc8c (patch)
treeb79f1f20dc3691c47d6083bdb3f285c530af0c46 /sys/ufs/ffs/ffs_alloc.c
parent707190112f1bbf51379b1e841680aac8aaec1c77 (diff)
Don't use #define QUOTA - use stub file instead
Pass over the quota code in ufs/. Make code paths clearer. Clean up some names. Move all code that manipulates quotas directly into ufs_quota.c Use vfs_mount_foreach_vnode to traverse list of vnodes in mountpoint.
Diffstat (limited to 'sys/ufs/ffs/ffs_alloc.c')
-rw-r--r--sys/ufs/ffs/ffs_alloc.c105
1 files changed, 54 insertions, 51 deletions
diff --git a/sys/ufs/ffs/ffs_alloc.c b/sys/ufs/ffs/ffs_alloc.c
index 7c2870fed77..8ddf99405fc 100644
--- a/sys/ufs/ffs/ffs_alloc.c
+++ b/sys/ufs/ffs/ffs_alloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ffs_alloc.c,v 1.34 2001/11/15 06:08:31 art Exp $ */
+/* $OpenBSD: ffs_alloc.c,v 1.35 2001/11/21 21:23:56 csapuntz Exp $ */
/* $NetBSD: ffs_alloc.c,v 1.11 1996/05/11 18:27:09 mycroft Exp $ */
/*
@@ -104,9 +104,7 @@ ffs_alloc(ip, lbn, bpref, size, cred, bnp)
register struct fs *fs;
daddr_t bno;
int cg;
-#ifdef QUOTA
int error;
-#endif
*bnp = 0;
fs = ip->i_fs;
@@ -123,10 +121,10 @@ ffs_alloc(ip, lbn, bpref, size, cred, bnp)
goto nospace;
if (cred->cr_uid != 0 && freespace(fs, fs->fs_minfree) <= 0)
goto nospace;
-#ifdef QUOTA
- if ((error = chkdq(ip, (long)btodb(size), cred, 0)) != 0)
+
+ if ((error = ufs_quota_alloc_blocks(ip, btodb(size), cred)) != 0)
return (error);
-#endif
+
if (bpref >= fs->fs_size)
bpref = 0;
if (bpref == 0)
@@ -141,12 +139,12 @@ ffs_alloc(ip, lbn, bpref, size, cred, bnp)
*bnp = bno;
return (0);
}
-#ifdef QUOTA
+
/*
* Restore user's disk quota because allocation failed.
*/
- (void) chkdq(ip, (long)-btodb(size), cred, FORCE);
-#endif
+ (void) ufs_quota_free_blocks(ip, btodb(size), cred);
+
nospace:
ffs_fserr(fs, cred->cr_uid, "file system full");
uprintf("\n%s: write failed, file system is full\n", fs->fs_fsmnt);
@@ -172,7 +170,8 @@ ffs_realloccg(ip, lbprev, bpref, osize, nsize, cred, bpp, blknop)
ufs_daddr_t *blknop;
{
register struct fs *fs;
- struct buf *bp;
+ struct buf *bp = NULL;
+ ufs_daddr_t quota_updated = 0;
int cg, request, error;
daddr_t bprev, bno;
@@ -201,18 +200,15 @@ ffs_realloccg(ip, lbprev, bpref, osize, nsize, cred, bpp, blknop)
* Allocate the extra space in the buffer.
*/
if (bpp != NULL &&
- (error = bread(ITOV(ip), lbprev, osize, NOCRED, &bp)) != 0) {
- brelse(bp);
- return (error);
- }
-#ifdef QUOTA
- if ((error = chkdq(ip, (long)btodb(nsize - osize), cred, 0)) != 0) {
- if (bpp != NULL) {
- brelse(bp);
- }
- return (error);
- }
-#endif
+ (error = bread(ITOV(ip), lbprev, osize, NOCRED, &bp)) != 0)
+ goto error;
+
+ if ((error = ufs_quota_alloc_blocks(ip, btodb(nsize - osize), cred))
+ != 0)
+ goto error;
+
+ quota_updated = btodb(nsize - osize);
+
/*
* Check for extension in the existing location.
*/
@@ -283,43 +279,50 @@ ffs_realloccg(ip, lbprev, bpref, osize, nsize, cred, bpp, blknop)
}
bno = (daddr_t)ffs_hashalloc(ip, cg, (long)bpref, request,
ffs_alloccg);
- if (bno > 0) {
- (void) uvm_vnp_uncache(ITOV(ip));
- if (!DOINGSOFTDEP(ITOV(ip)))
- ffs_blkfree(ip, bprev, (long)osize);
- if (nsize < request)
- ffs_blkfree(ip, bno + numfrags(fs, nsize),
- (long)(request - nsize));
- ip->i_ffs_blocks += btodb(nsize - osize);
- ip->i_flag |= IN_CHANGE | IN_UPDATE;
- if (bpp != NULL) {
- bp->b_blkno = fsbtodb(fs, bno);
- allocbuf(bp, nsize);
- bp->b_flags |= B_DONE;
- bzero((char *)bp->b_data + osize, (u_int)nsize - osize);
- *bpp = bp;
- }
- if (blknop != NULL) {
- *blknop = bno;
- }
- return (0);
- }
-#ifdef QUOTA
- /*
- * Restore user's disk quota because allocation failed.
- */
- (void) chkdq(ip, (long)-btodb(nsize - osize), cred, FORCE);
-#endif
+ if (bno <= 0)
+ goto nospace;
+
+ (void) uvm_vnp_uncache(ITOV(ip));
+ if (!DOINGSOFTDEP(ITOV(ip)))
+ ffs_blkfree(ip, bprev, (long)osize);
+ if (nsize < request)
+ ffs_blkfree(ip, bno + numfrags(fs, nsize),
+ (long)(request - nsize));
+ ip->i_ffs_blocks += btodb(nsize - osize);
+ ip->i_flag |= IN_CHANGE | IN_UPDATE;
if (bpp != NULL) {
- brelse(bp);
+ bp->b_blkno = fsbtodb(fs, bno);
+ allocbuf(bp, nsize);
+ bp->b_flags |= B_DONE;
+ bzero((char *)bp->b_data + osize, (u_int)nsize - osize);
+ *bpp = bp;
}
+ if (blknop != NULL) {
+ *blknop = bno;
+ }
+ return (0);
+
nospace:
/*
* no space available
*/
ffs_fserr(fs, cred->cr_uid, "file system full");
uprintf("\n%s: write failed, file system is full\n", fs->fs_fsmnt);
- return (ENOSPC);
+ error = ENOSPC;
+
+error:
+ if (bp != NULL) {
+ brelse(bp);
+ bp = NULL;
+ }
+
+ /*
+ * Restore user's disk quota because allocation failed.
+ */
+ if (quota_updated != 0)
+ (void)ufs_quota_free_blocks(ip, quota_updated, cred);
+
+ return error;
}
/*