/* get the page's starting extent offset */
xoff = pno << sbi->l2nbperpage;
/* check if an allocation hint was provided */ if ((hint = addressXAD(xp))) { /* get the size of the extent described by the hint */
nxlen = lengthXAD(xp);
/* check if the hint is for the portion of the file *immediatelyprevioustothecurrentallocation *requestandifhintextenthasthesameabnr *valueasthecurrentrequest.ifso,wecan *extendthehintextenttoincludethecurrent *extentifwecanallocatetheblocksimmediately *followingthehintextent.
*/ if (offsetXAD(xp) + nxlen == xoff &&
abnr == ((xp->flag & XAD_NOTRECORDED) ? true : false))
xaddr = hint + nxlen;
/* adjust the hint to the last block of the extent */
hint += (nxlen - 1);
}
/* allocate the disk blocks for the extent. initially, extBalloc() *willtrytoallocatediskblocksfortherequestedsize(xlen). *ifthisfails(xlencontiguousfreeblocksnotavailable),it'll *trytoallocateasmallernumberofblocks(producingasmaller *extent),withthissmallernumberofblocksconsistingofthe *requestednumberofblocksroundeddowntothenextsmaller *powerof2number(i.e.16->8).it'llcontinuetorounddown *andretrytheallocationuntilthenumberofblockstoallocate *issmallerthanthenumberofblocksperpage.
*/
nxlen = xlen; if ((rc = extBalloc(ip, hint ? hint : INOHINT(ip), &nxlen, &nxaddr))) {
mutex_unlock(&JFS_IP(ip)->commit_mutex); return (rc);
}
/* determine the value of the extent flag */
xflag = abnr ? XAD_NOTRECORDED : 0;
/* if we can extend the hint extent to cover the current request, *extendit.otherwise,insertanewextentto *coverthecurrentrequest.
*/ if (xaddr && xaddr == nxaddr)
rc = xtExtend(0, ip, xoff, (int) nxlen, 0); else
rc = xtInsert(0, ip, xflag, xoff, (int) nxlen, &nxaddr, 0);
/* if the extend or insert failed, *freethenewlyallocatedblocksandreturntheerror.
*/ if (rc) {
dbFree(ip, nxaddr, nxlen);
dquot_free_block(ip, nxlen);
mutex_unlock(&JFS_IP(ip)->commit_mutex); return (rc);
}
/* set the results of the extent allocation */
XADaddress(xp, nxaddr);
XADlength(xp, nxlen);
XADoffset(xp, xoff);
xp->flag = xflag;
mark_inode_dirty(ip);
mutex_unlock(&JFS_IP(ip)->commit_mutex); /* *COMMIT_SyncListflagsananonymoustlockonpagethatison *synclist. *Weneedtocommittheinodetogetthepagewrittentothedisk.
*/ if (test_and_clear_cflag(COMMIT_Synclist,ip))
jfs_commit_inode(ip, 0);
return (0);
}
/* *NAME:extHint() * *FUNCTION:produceanextentallocationhintforafileoffset. * *PARAMETERS: *ip-theinodeofthefile. *offset-fileoffsetforwhichthehintisneeded. *xp-pointertothexadthatistobefilledinwith *thehint. * *RETURNVALUES: *0-success *-EIO-i/oerror.
*/ int extHint(struct inode *ip, s64 offset, xad_t * xp)
{ struct super_block *sb = ip->i_sb; int nbperpage = JFS_SBI(sb)->nbperpage;
s64 prev; int rc = 0;
s64 xaddr; int xlen; int xflag;
/* init the hint as "no hint provided" */
XADaddress(xp, 0);
/* determine the starting extent offset of the page previous *tothepagecontainingtheoffset.
*/
prev = ((offset & ~POFFSET) >> JFS_SBI(sb)->l2bsize) - nbperpage;
/* if the offset is in the first page of the file, no hint provided.
*/ if (prev < 0) goto out;
/* get the number of blocks to initially attempt to allocate. *we'llfirsttrythenumberofblocksrequestedunlessthis *numberisgreaterthanthemaximumnumberofcontiguousfree *blocksinthemap.inthatcase,we'llstartoffwiththe *maximumfree.
*/
/* give up if no space left */ if (bmp->db_maxfreebud == -1) return -ENOSPC;
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)) != 0) { /* if something other than an out of space error, *stopandreturnthiserror.
*/ 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);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.