📄 jfs_extent.c
字号:
XADoffset(xp, xoff); xp->flag = xflag; mark_inode_dirty(ip);exit: up(&JFS_IP(ip)->commit_sem); return (rc);}#endif /* _NOTYET *//* * NAME: extHint() * * FUNCTION: produce an extent allocation hint for a file offset. * * PARAMETERS: * ip - the inode of the file. * offset - file offset for which the hint is needed. * xp - pointer to the xad that is to be filled in with * the hint. * * RETURN VALUES: * 0 - success * -EIO - i/o error. */int extHint(struct inode *ip, s64 offset, xad_t * xp){ struct super_block *sb = ip->i_sb; struct xadlist xadl; struct lxdlist lxdl; lxd_t lxd; s64 prev; int rc, nbperpage = JFS_SBI(sb)->nbperpage; /* init the hint as "no hint provided" */ XADaddress(xp, 0); /* determine the starting extent offset of the page previous * to the page containing the offset. */ prev = ((offset & ~POFFSET) >> JFS_SBI(sb)->l2bsize) - nbperpage; /* if the offsets in the first page of the file, * no hint provided. */ if (prev < 0) return (0); /* prepare to lookup the previous page's extent info */ lxdl.maxnlxd = 1; lxdl.nlxd = 1; lxdl.lxd = &lxd; LXDoffset(&lxd, prev) LXDlength(&lxd, nbperpage); xadl.maxnxad = 1; xadl.nxad = 0; xadl.xad = xp; /* perform the lookup */ if ((rc = xtLookupList(ip, &lxdl, &xadl, 0))) return (rc); /* check if not extent exists for the previous page. * this is possible for sparse files. */ if (xadl.nxad == 0) {// assert(ISSPARSE(ip)); return (0); } /* only preserve the abnr flag within the xad flags * of the returned hint. */ xp->flag &= XAD_NOTRECORDED; if(xadl.nxad != 1 || lengthXAD(xp) != nbperpage) { jfs_error(ip->i_sb, "extHint: corrupt xtree"); return -EIO; } return (0);}/* * NAME: extRecord() * * FUNCTION: change a page with a file from not recorded to recorded. * * PARAMETERS: * ip - inode of the file. * cp - cbuf of the file page. * * RETURN VALUES: * 0 - success * -EIO - i/o error. * -ENOSPC - insufficient disk resources. */int extRecord(struct inode *ip, xad_t * xp){ int rc; txBeginAnon(ip->i_sb); down(&JFS_IP(ip)->commit_sem); /* update the extent */ rc = xtUpdate(0, ip, xp); up(&JFS_IP(ip)->commit_sem); return rc;}#ifdef _NOTYET/* * NAME: extFill() * * FUNCTION: allocate disk space for a file page that represents * a file hole. * * PARAMETERS: * ip - the inode of the file. * cp - cbuf of the file page represent the hole. * * RETURN VALUES: * 0 - success * -EIO - i/o error. * -ENOSPC - insufficient disk resources. */int extFill(struct inode *ip, xad_t * xp){ int rc, nbperpage = JFS_SBI(ip->i_sb)->nbperpage; s64 blkno = offsetXAD(xp) >> ip->i_blksize;// assert(ISSPARSE(ip)); /* initialize the extent allocation hint */ XADaddress(xp, 0); /* allocate an extent to fill the hole */ if ((rc = extAlloc(ip, nbperpage, blkno, xp, FALSE))) return (rc); assert(lengthPXD(xp) == nbperpage); return (0);}#endif /* _NOTYET *//* * NAME: extBalloc() * * FUNCTION: allocate disk blocks to form an extent. * * initially, we will try to allocate disk blocks for the * requested size (nblocks). if this fails (nblocks * contigious free blocks not avaliable), we'll try to allocate * a smaller number of blocks (producing a smaller extent), with * this smaller number of blocks consisting of the requested * number of blocks rounded down to the next smaller power of 2 * number (i.e. 16 -> 8). we'll continue to round down and * retry the allocation until the number of blocks to allocate * is smaller than the number of blocks per page. * * PARAMETERS: * ip - the inode of the file. * hint - disk block number to be used as an allocation hint. * *nblocks - pointer to an s64 value. on entry, this value specifies * the desired number of block to be allocated. on successful * exit, this value is set to the number of blocks actually * allocated. * blkno - pointer to a block address that is filled in on successful * return with the starting block number of the newly * allocated block range. * * RETURN VALUES: * 0 - success * -EIO - i/o error. * -ENOSPC - insufficient disk resources. */static intextBalloc(struct inode *ip, s64 hint, s64 * nblocks, s64 * blkno){ struct jfs_inode_info *ji = JFS_IP(ip); struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb); s64 nb, nblks, daddr, max; int rc, nbperpage = sbi->nbperpage; struct bmap *bmp = sbi->bmap; int ag; /* get the number of blocks to initially attempt to allocate. * we'll first try the number of blocks requested unless this * number is greater than the maximum number of contigious free * blocks in the map. in that case, we'll start off with the * maximum free. */ max = (s64) 1 << bmp->db_maxfreebud; if (*nblocks >= max && *nblocks > nbperpage) nb = nblks = (max > nbperpage) ? max : nbperpage; else nb = nblks = *nblocks; /* try to allocate blocks */ while ((rc = dbAlloc(ip, hint, nb, &daddr))) { /* if something other than an out of space error, * stop and return this error. */ if (rc != -ENOSPC) return (rc); /* decrease the allocation request size */ nb = min(nblks, extRoundDown(nb)); /* give up if we cannot cover a page */ if (nb < nbperpage) return (rc); } *nblocks = nb; *blkno = daddr; if (S_ISREG(ip->i_mode) && (ji->fileset == FILESYSTEM_I)) { ag = BLKTOAG(daddr, sbi); spin_lock_irq(&ji->ag_lock); if (ji->active_ag == -1) { atomic_inc(&bmp->db_active[ag]); ji->active_ag = ag; } else if (ji->active_ag != ag) { atomic_dec(&bmp->db_active[ji->active_ag]); atomic_inc(&bmp->db_active[ag]); ji->active_ag = ag; } spin_unlock_irq(&ji->ag_lock); } return (0);}#ifdef _NOTYET/* * NAME: extBrealloc() * * FUNCTION: attempt to extend an extent's allocation. * * initially, we will try to extend the extent's allocation * in place. if this fails, we'll try to move the extent * to a new set of blocks. if moving the extent, we initially * will try to allocate disk blocks for the requested size * (nnew). if this fails (nnew contigious free blocks not * avaliable), we'll try to allocate a smaller number of * blocks (producing a smaller extent), with this smaller * number of blocks consisting of the requested number of * blocks rounded down to the next smaller power of 2 * number (i.e. 16 -> 8). we'll continue to round down and * retry the allocation until the number of blocks to allocate * is smaller than the number of blocks per page. * * PARAMETERS: * ip - the inode of the file. * blkno - starting block number of the extents current allocation. * nblks - number of blocks within the extents current allocation. * newnblks - pointer to a s64 value. on entry, this value is the * the new desired extent size (number of blocks). on * successful exit, this value is set to the extent's actual * new size (new number of blocks). * newblkno - the starting block number of the extents new allocation. * * RETURN VALUES: * 0 - success * -EIO - i/o error. * -ENOSPC - insufficient disk resources. */static intextBrealloc(struct inode *ip, s64 blkno, s64 nblks, s64 * newnblks, s64 * newblkno){ int rc; /* try to extend in place */ if ((rc = dbExtend(ip, blkno, nblks, *newnblks - nblks)) == 0) { *newblkno = blkno; return (0); } else { if (rc != -ENOSPC) return (rc); } /* in place extension not possible. * try to move the extent to a new set of blocks. */ return (extBalloc(ip, blkno, newnblks, newblkno));}#endif /* _NOTYET *//* * NAME: extRoundDown() * * FUNCTION: round down a specified number of blocks to the next * smallest power of 2 number. * * PARAMETERS: * nb - the inode of the file. * * RETURN VALUES: * next smallest power of 2 number. */static s64 extRoundDown(s64 nb){ int i; u64 m, k; for (i = 0, m = (u64) 1 << 63; i < 64; i++, m >>= 1) { if (m & nb) break; } i = 63 - i; k = (u64) 1 << i; k = ((k - 1) & nb) ? k : k >> 1; return (k);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -