From owner-p4-projects@FreeBSD.ORG Sat May 8 05:28:20 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 36B76106567D; Sat, 8 May 2010 05:28:20 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id E07991065676 for ; Sat, 8 May 2010 05:28:19 +0000 (UTC) (envelope-from lz@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id CE0198FC18 for ; Sat, 8 May 2010 05:28:19 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o485SJan040736 for ; Sat, 8 May 2010 05:28:19 GMT (envelope-from lz@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o485SJgO040734 for perforce@freebsd.org; Sat, 8 May 2010 05:28:19 GMT (envelope-from lz@FreeBSD.org) Date: Sat, 8 May 2010 05:28:19 GMT Message-Id: <201005080528.o485SJgO040734@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to lz@FreeBSD.org using -f From: Zheng Liu To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 177940 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 May 2010 05:28:20 -0000 http://p4web.freebsd.org/@@177940?ac=10 Change 177940 by lz@gnehzuil-freebsd on 2010/05/08 05:27:30 Add ext2_alloc_rsv() function. * Add ext2_alloc_rsv() function and change call from ext2_alloc to ext2_alloc_rsv in ext2_balloc. But it do not implement in ext2_alloc_rsv(). * Modify license in ext2_rsv_win.h and marco style. Affected files ... .. //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_alloc.c#3 edit .. //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_balloc.c#3 edit .. //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_rsv_win.h#3 edit Differences ... ==== //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_alloc.c#3 (text+ko) ==== @@ -79,10 +79,11 @@ rwip = malloc(sizeof(struct ext2_rsv_win_info), M_EXT2NODE, M_NOWAIT | M_ZERO); + + /* If malloc failed, we just do not use + * reservation window mechanism + */ if (rwip == NULL) - /* If malloc failed, we just do not use - * reservation window mechnism - */ return; rwp = &rwip->rwi_entry; @@ -101,6 +102,7 @@ * It is called at following locations: * 1. free an inode * 2. sync inode + * 3. truncate a file */ void ext2_discard_rsv_win(struct inode *ip) @@ -126,7 +128,7 @@ /* * Remove a ext2_rsv_win structure from RB tree. */ -void +static void ext2_rsv_win_remove(struct m_ext2fs *sbp, struct ext2_rsv_win *rwp) { rwp->rw_start = EXT2_RWI_NOT_ALLOCATED; @@ -136,6 +138,55 @@ } /* + * Allocate a block using reservation window in ext2 file system. + */ +int +ext2_alloc_rsv(struct inode *ip, int32_t lbn, int32_t bpref, + int size, struct ucred *cred, int32_t *bnp) +{ + struct m_ext2fs *fs; + struct ext2mount *ump; + int32_t bno; + int cg; + *bnp = 0; + fs = ip->i_e2fs; + ump = ip->i_ump; + mtx_assert(EXT2_MTX(ump), MA_OWNED); +#ifdef DIAGNOSTIC + if ((u_int)size > fs->e2fs_bsize || blkoff(fs, size) != 0) { + vn_printf(ip->i_devvp, "bsize = %lu, size = %d, fs = %s\n", + (long unsigned int)fs->e2fs_bsize, size, fs->e2fs_fsmnt); + panic("ext2_alloc: bad size"); + } + if (cred == NOCRED) + panic("ext2_alloc: missing credential"); +#endif /* DIAGNOSTIC */ + if (size == fs->e2fs_bsize && fs->e2fs->e2fs_fbcount == 0) + goto nospace; + if (cred->cr_uid != 0 && + fs->e2fs->e2fs_fbcount < fs->e2fs->e2fs_rbcount) + goto nospace; + if (bpref >= fs->e2fs->e2fs_bcount) + bpref = 0; + if (bpref == 0) + cg = ino_to_cg(fs, ip->i_number); + else + cg = dtog(fs, bpref); + bno = (daddr_t)ext2_hashalloc(ip, cg, bpref, fs->e2fs_bsize, + ext2_alloccg); + if (bno > 0) { + ip->i_blocks += btodb(fs->e2fs_bsize); + ip->i_flag |= IN_CHANGE | IN_UPDATE; + *bnp = bno; + return (0); + } +nospace: + EXT2_UNLOCK(ump); + ext2_fserr(fs, cred->cr_uid, "file system full"); + uprintf("\n%s: write failed, file system is full\n", fs->e2fs_fsmnt); + return (ENOSPC); +} +/* * Allocate a block in the file system. * * A preference may be optionally specified. If a preference is given ==== //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_balloc.c#3 (text+ko) ==== @@ -143,9 +143,14 @@ else nsize = fs->e2fs_bsize; EXT2_LOCK(ump); +/* error = ext2_alloc(ip, lbn, ext2_blkpref(ip, lbn, (int)lbn, &ip->i_db[0], 0), nsize, cred, &newb); +*/ + error = ext2_alloc_rsv(ip, lbn, + ext2_blkpref(ip, lbn, (int)lbn, &ip->i_db[0], 0), + nsize, cred, &newb); if (error) return (error); bp = getblk(vp, lbn, nsize, 0, 0, 0); @@ -177,9 +182,14 @@ EXT2_LOCK(ump); pref = ext2_blkpref(ip, lbn, indirs[0].in_off + EXT2_NDIR_BLOCKS, &ip->i_db[0], 0); +/* if ((error = ext2_alloc(ip, lbn, pref, (int)fs->e2fs_bsize, cred, &newb))) return (error); +*/ + if ((error = ext2_alloc_rsv(ip, lbn, pref, + (int)fs->e2fs_bsize, cred, &newb))) + return (error); nb = newb; bp = getblk(vp, indirs[1].in_lbn, fs->e2fs_bsize, 0, 0, 0); bp->b_blkno = fsbtodb(fs, newb); @@ -218,7 +228,10 @@ if (pref == 0) pref = ext2_blkpref(ip, lbn, indirs[i].in_off, bap, bp->b_lblkno); +/* error = ext2_alloc(ip, lbn, pref, (int)fs->e2fs_bsize, cred, &newb); +*/ + error = ext2_alloc_rsv(ip, lbn, pref, (int)fs->e2fs_bsize, cred, &newb); if (error) { brelse(bp); return (error); @@ -257,11 +270,18 @@ EXT2_LOCK(ump); pref = ext2_blkpref(ip, lbn, indirs[i].in_off, &bap[0], bp->b_lblkno); +/* if ((error = ext2_alloc(ip, lbn, pref, (int)fs->e2fs_bsize, cred, &newb)) != 0) { brelse(bp); return (error); } +*/ + if ((error = ext2_alloc_rsv(ip, lbn, pref, + (int)fs->e2fs_bsize, cred, &newb)) != 0) { + brelse(bp); + return (error); + } nb = newb; nbp = getblk(vp, lbn, fs->e2fs_bsize, 0, 0, 0); nbp->b_blkno = fsbtodb(fs, nb); ==== //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_rsv_win.h#3 (text+ko) ==== @@ -1,11 +1,6 @@ /*- - * Copyright (c) 1982, 1989, 1993 - * The Regents of the University of California. All rights reserved. - * (c) UNIX System Laboratories, Inc. - * All or some portions of this file are derived from material licensed - * to the University of California by American Telephone and Telegraph - * Co. or Unix System Laboratories, Inc. and are reproduced herein with - * the permission of UNIX System Laboratories, Inc. + * Copyright (c) 2010, 2010 Zheng Liu + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -15,14 +10,11 @@ * 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 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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) @@ -31,20 +23,20 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)ext2_rsv_win.h 8.9 (Berkeley) 5/14/95 - * $FreeBSD: src/sys/fs/ext2fs/ext2_rsv_win.h,v 0.1 2010/01/14 14:30:54 lz Exp $ + * $FreeBSD: src/sys/fs/ext2fs/ext2_rsv_win.h,v 0.1 2010/05/08 12:41:51 lz Exp $ */ - -#ifndef _EXT2_RSV_WIN_H_ -#define _EXT2_RSV_WIN_H_ +#ifndef _FS_EXT2FS_EXT2_RSV_WIN_H_ +#define _FS_EXT2FS_EXT2_RSV_WIN_H_ #include #define EXT2_RWI_DEFAULT_RESERVE_BLKS 8 #define EXT2_RWI_NOT_ALLOCATED 0 +#define EXT2_MAX_RSV_WIN_BLKS 1027 + /* - * reservation window entry + * Reservation window entry */ struct ext2_rsv_win { RB_ENTRY(ext2_rsv_win) rw_link; /* RB tree links */ @@ -86,5 +78,7 @@ struct inode; void ext2_init_rsv_win_info(struct inode *ip); void ext2_discard_rsv_win(struct inode *ip); +int ext2_alloc_rsv(struct inode *, int32_t, int32_t, + int, struct ucred *, int32_t *); -#endif /* !_EXT2_RSV_WIN_H_ */ +#endif /* !_FS_EXT2FS_EXT2_EXTERN_H_ */