version 1.111, 2008/07/31 05:38:06 |
version 1.112, 2008/07/31 09:35:09 |
Line 1612 ffs_nodealloccg(struct inode *ip, int cg |
|
Line 1612 ffs_nodealloccg(struct inode *ip, int cg |
|
u_int8_t *inosused; |
u_int8_t *inosused; |
int error, start, len, loc, map, i; |
int error, start, len, loc, map, i; |
int32_t initediblk; |
int32_t initediblk; |
|
daddr_t nalloc; |
struct ufs2_dinode *dp2; |
struct ufs2_dinode *dp2; |
#ifdef FFS_EI |
#ifdef FFS_EI |
const int needswap = UFS_FSNEEDSWAP(fs); |
const int needswap = UFS_FSNEEDSWAP(fs); |
Line 1623 ffs_nodealloccg(struct inode *ip, int cg |
|
Line 1624 ffs_nodealloccg(struct inode *ip, int cg |
|
if (fs->fs_cs(fs, cg).cs_nifree == 0) |
if (fs->fs_cs(fs, cg).cs_nifree == 0) |
return (0); |
return (0); |
mutex_exit(&ump->um_lock); |
mutex_exit(&ump->um_lock); |
|
ibp = NULL; |
|
initediblk = -1; |
|
retry: |
error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)), |
error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)), |
(int)fs->fs_cgsize, NOCRED, B_MODIFY, &bp); |
(int)fs->fs_cgsize, NOCRED, B_MODIFY, &bp); |
if (error) |
if (error) |
Line 1630 ffs_nodealloccg(struct inode *ip, int cg |
|
Line 1634 ffs_nodealloccg(struct inode *ip, int cg |
|
cgp = (struct cg *)bp->b_data; |
cgp = (struct cg *)bp->b_data; |
if (!cg_chkmagic(cgp, needswap) || cgp->cg_cs.cs_nifree == 0) |
if (!cg_chkmagic(cgp, needswap) || cgp->cg_cs.cs_nifree == 0) |
goto fail; |
goto fail; |
|
|
|
if (ibp != NULL && |
|
initediblk != ufs_rw32(cgp->cg_initediblk, needswap)) { |
|
/* Another thread allocated more inodes so we retry the test. */ |
|
brelse(ibp, BC_INVAL); |
|
ibp = NULL; |
|
} |
|
/* |
|
* Check to see if we need to initialize more inodes. |
|
*/ |
|
if (fs->fs_magic == FS_UFS2_MAGIC && ibp == NULL) { |
|
initediblk = ufs_rw32(cgp->cg_initediblk, needswap); |
|
nalloc = fs->fs_ipg - ufs_rw32(cgp->cg_cs.cs_nifree, needswap); |
|
if (nalloc + INOPB(fs) > initediblk && |
|
initediblk < ufs_rw32(cgp->cg_niblk, needswap)) { |
|
/* |
|
* We have to release the cg buffer here to prevent |
|
* a deadlock when reading the inode block will |
|
* run a copy-on-write that might use this cg. |
|
*/ |
|
brelse(bp, 0); |
|
bp = NULL; |
|
error = ffs_getblk(ip->i_devvp, fsbtodb(fs, |
|
ino_to_fsba(fs, cg * fs->fs_ipg + initediblk)), |
|
FFS_NOBLK, fs->fs_bsize, false, &ibp); |
|
if (error) |
|
goto fail; |
|
goto retry; |
|
} |
|
} |
|
|
cgp->cg_old_time = ufs_rw32(time_second, needswap); |
cgp->cg_old_time = ufs_rw32(time_second, needswap); |
if ((fs->fs_magic != FS_UFS1_MAGIC) || |
if ((fs->fs_magic != FS_UFS1_MAGIC) || |
(fs->fs_old_flags & FS_FLAGS_UPDATED)) |
(fs->fs_old_flags & FS_FLAGS_UPDATED)) |
|
|
/* |
/* |
* Check to see if we need to initialize more inodes. |
* Check to see if we need to initialize more inodes. |
*/ |
*/ |
initediblk = ufs_rw32(cgp->cg_initediblk, needswap); |
if (ibp != NULL) { |
ibp = NULL; |
KASSERT(initediblk == ufs_rw32(cgp->cg_initediblk, needswap)); |
if (fs->fs_magic == FS_UFS2_MAGIC && |
|
ipref + INOPB(fs) > initediblk && |
|
initediblk < ufs_rw32(cgp->cg_niblk, needswap)) { |
|
if (ffs_getblk(ip->i_devvp, fsbtodb(fs, |
|
ino_to_fsba(fs, cg * fs->fs_ipg + initediblk)), |
|
FFS_NOBLK, fs->fs_bsize, false, &ibp) != 0) |
|
goto fail; |
|
memset(ibp->b_data, 0, fs->fs_bsize); |
memset(ibp->b_data, 0, fs->fs_bsize); |
dp2 = (struct ufs2_dinode *)(ibp->b_data); |
dp2 = (struct ufs2_dinode *)(ibp->b_data); |
for (i = 0; i < INOPB(fs); i++) { |
for (i = 0; i < INOPB(fs); i++) { |
|
|
mutex_exit(&ump->um_lock); |
mutex_exit(&ump->um_lock); |
if (DOINGSOFTDEP(ITOV(ip))) |
if (DOINGSOFTDEP(ITOV(ip))) |
softdep_setup_inomapdep(bp, ip, cg * fs->fs_ipg + ipref); |
softdep_setup_inomapdep(bp, ip, cg * fs->fs_ipg + ipref); |
bdwrite(bp); |
if (ibp != NULL) { |
if (ibp != NULL) |
bwrite(bp); |
bawrite(ibp); |
bawrite(ibp); |
|
} else |
|
bdwrite(bp); |
return (cg * fs->fs_ipg + ipref); |
return (cg * fs->fs_ipg + ipref); |
fail: |
fail: |
brelse(bp, 0); |
if (bp != NULL) |
|
brelse(bp, 0); |
|
if (ibp != NULL) |
|
brelse(ibp, BC_INVAL); |
mutex_enter(&ump->um_lock); |
mutex_enter(&ump->um_lock); |
return (0); |
return (0); |
} |
} |