Lines Matching +full:ip +full:- +full:blocks
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) International Business Machines Corp., 2000-2004
57 * ip - the inode of the file.
58 * xlen - requested extent length.
59 * pno - the starting page number with the file.
60 * xp - pointer to an xad. on entry, xad describes an
62 * xaddr of the xad is non-zero. on successful exit,
64 * abnr - bool indicating whether the newly allocated extent
68 * 0 - success
69 * -EIO - i/o error.
70 * -ENOSPC - insufficient disk resources.
73 extAlloc(struct inode *ip, s64 xlen, s64 pno, xad_t * xp, bool abnr) in extAlloc() argument
75 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb); in extAlloc()
80 /* This blocks if we are low on resources */ in extAlloc()
81 txBeginAnon(ip->i_sb); in extAlloc()
84 mutex_lock(&JFS_IP(ip)->commit_mutex); in extAlloc()
91 xoff = pno << sbi->l2nbperpage; in extAlloc()
103 * extent if we can allocate the blocks immediately in extAlloc()
107 abnr == ((xp->flag & XAD_NOTRECORDED) ? true : false)) in extAlloc()
111 hint += (nxlen - 1); in extAlloc()
114 /* allocate the disk blocks for the extent. initially, extBalloc() in extAlloc()
115 * will try to allocate disk blocks for the requested size (xlen). in extAlloc()
116 * if this fails (xlen contiguous free blocks not available), it'll in extAlloc()
117 * try to allocate a smaller number of blocks (producing a smaller in extAlloc()
118 * extent), with this smaller number of blocks consisting of the in extAlloc()
119 * requested number of blocks rounded down to the next smaller in extAlloc()
120 * power of 2 number (i.e. 16 -> 8). it'll continue to round down in extAlloc()
121 * and retry the allocation until the number of blocks to allocate in extAlloc()
122 * is smaller than the number of blocks per page. in extAlloc()
125 if ((rc = extBalloc(ip, hint ? hint : INOHINT(ip), &nxlen, &nxaddr))) { in extAlloc()
126 mutex_unlock(&JFS_IP(ip)->commit_mutex); in extAlloc()
130 /* Allocate blocks to quota. */ in extAlloc()
131 rc = dquot_alloc_block(ip, nxlen); in extAlloc()
133 dbFree(ip, nxaddr, (s64) nxlen); in extAlloc()
134 mutex_unlock(&JFS_IP(ip)->commit_mutex); in extAlloc()
146 rc = xtExtend(0, ip, xoff, (int) nxlen, 0); in extAlloc()
148 rc = xtInsert(0, ip, xflag, xoff, (int) nxlen, &nxaddr, 0); in extAlloc()
151 * free the newly allocated blocks and return the error. in extAlloc()
154 dbFree(ip, nxaddr, nxlen); in extAlloc()
155 dquot_free_block(ip, nxlen); in extAlloc()
156 mutex_unlock(&JFS_IP(ip)->commit_mutex); in extAlloc()
164 xp->flag = xflag; in extAlloc()
166 mark_inode_dirty(ip); in extAlloc()
168 mutex_unlock(&JFS_IP(ip)->commit_mutex); in extAlloc()
174 if (test_and_clear_cflag(COMMIT_Synclist,ip)) in extAlloc()
175 jfs_commit_inode(ip, 0); in extAlloc()
189 * ip - the inode of the file.
190 * cp - cbuf for the partial backed last page.
191 * xlen - request size of the resulting extent.
192 * xp - pointer to an xad. on successful exit, the xad
194 * abnr - bool indicating whether the newly allocated extent
198 * 0 - success
199 * -EIO - i/o error.
200 * -ENOSPC - insufficient disk resources.
202 int extRealloc(struct inode *ip, s64 nxlen, xad_t * xp, bool abnr) in extRealloc() argument
204 struct super_block *sb = ip->i_sb; in extRealloc()
207 int rc, nbperpage = JFS_SBI(sb)->nbperpage; in extRealloc()
210 /* This blocks if we are low on resources */ in extRealloc()
211 txBeginAnon(ip->i_sb); in extRealloc()
213 mutex_lock(&JFS_IP(ip)->commit_mutex); in extRealloc()
219 * number of blocks. in extRealloc()
229 if ((xp->flag & XAD_NOTRECORDED) && !abnr) { in extRealloc()
230 xp->flag = 0; in extRealloc()
231 if ((rc = xtUpdate(0, ip, xp))) in extRealloc()
235 /* try to allocated the request number of blocks for the in extRealloc()
238 * try to allocate a new set of blocks large enough for the in extRealloc()
243 if ((rc = extBrealloc(ip, xaddr, xlen, &nxlen, &nxaddr))) in extRealloc()
246 /* Allocat blocks to quota. */ in extRealloc()
247 rc = dquot_alloc_block(ip, nxlen); in extRealloc()
249 dbFree(ip, nxaddr, (s64) nxlen); in extRealloc()
250 mutex_unlock(&JFS_IP(ip)->commit_mutex); in extRealloc()
254 delta = nxlen - xlen; in extRealloc()
267 if (abnr && (!(xp->flag & XAD_NOTRECORDED)) && (nxlen > nbperpage)) { in extRealloc()
269 nextend = ntail - xlen; in extRealloc()
270 ninsert = nxlen - nbperpage; in extRealloc()
278 xflag = xp->flag; in extRealloc()
287 if ((rc = xtExtend(0, ip, xoff + xlen, (int) nextend, 0))) { in extRealloc()
288 dbFree(ip, xaddr + xlen, delta); in extRealloc()
289 dquot_free_block(ip, nxlen); in extRealloc()
298 if ((rc = xtTailgate(0, ip, xoff, (int) ntail, nxaddr, 0))) { in extRealloc()
299 dbFree(ip, nxaddr, nxlen); in extRealloc()
300 dquot_free_block(ip, nxlen); in extRealloc()
308 /* perform the insert. if it fails, free the blocks in extRealloc()
313 if (xtInsert (0, ip, xflag, xoff + ntail, (int) ninsert, in extRealloc()
315 dbFree(ip, xaddr, (s64) ninsert); in extRealloc()
326 xp->flag = xflag; in extRealloc()
328 mark_inode_dirty(ip); in extRealloc()
330 mutex_unlock(&JFS_IP(ip)->commit_mutex); in extRealloc()
342 * ip - the inode of the file.
343 * offset - file offset for which the hint is needed.
344 * xp - pointer to the xad that is to be filled in with
348 * 0 - success
349 * -EIO - i/o error.
351 int extHint(struct inode *ip, s64 offset, xad_t * xp) in extHint() argument
353 struct super_block *sb = ip->i_sb; in extHint()
354 int nbperpage = JFS_SBI(sb)->nbperpage; in extHint()
367 prev = ((offset & ~POFFSET) >> JFS_SBI(sb)->l2bsize) - nbperpage; in extHint()
374 rc = xtLookup(ip, prev, nbperpage, &xflag, &xaddr, &xlen, 0); in extHint()
378 jfs_error(ip->i_sb, "corrupt xtree\n"); in extHint()
379 rc = -EIO; in extHint()
388 xp->flag = xflag & XAD_NOTRECORDED; in extHint()
403 * ip - inode of the file.
404 * cp - cbuf of the file page.
407 * 0 - success
408 * -EIO - i/o error.
409 * -ENOSPC - insufficient disk resources.
411 int extRecord(struct inode *ip, xad_t * xp) in extRecord() argument
415 txBeginAnon(ip->i_sb); in extRecord()
417 mutex_lock(&JFS_IP(ip)->commit_mutex); in extRecord()
420 rc = xtUpdate(0, ip, xp); in extRecord()
422 mutex_unlock(&JFS_IP(ip)->commit_mutex); in extRecord()
435 * ip - the inode of the file.
436 * cp - cbuf of the file page represent the hole.
439 * 0 - success
440 * -EIO - i/o error.
441 * -ENOSPC - insufficient disk resources.
443 int extFill(struct inode *ip, xad_t * xp) in extFill() argument
445 int rc, nbperpage = JFS_SBI(ip->i_sb)->nbperpage; in extFill()
446 s64 blkno = offsetXAD(xp) >> ip->i_blkbits; in extFill()
448 // assert(ISSPARSE(ip)); in extFill()
454 if ((rc = extAlloc(ip, nbperpage, blkno, xp, false))) in extFill()
467 * FUNCTION: allocate disk blocks to form an extent.
469 * initially, we will try to allocate disk blocks for the
471 * contiguous free blocks not available), we'll try to allocate
472 * a smaller number of blocks (producing a smaller extent), with
473 * this smaller number of blocks consisting of the requested
474 * number of blocks rounded down to the next smaller power of 2
475 * number (i.e. 16 -> 8). we'll continue to round down and
476 * retry the allocation until the number of blocks to allocate
477 * is smaller than the number of blocks per page.
480 * ip - the inode of the file.
481 * hint - disk block number to be used as an allocation hint.
482 * *nblocks - pointer to an s64 value. on entry, this value specifies
484 * exit, this value is set to the number of blocks actually
486 * blkno - pointer to a block address that is filled in on successful
491 * 0 - success
492 * -EIO - i/o error.
493 * -ENOSPC - insufficient disk resources.
496 extBalloc(struct inode *ip, s64 hint, s64 * nblocks, s64 * blkno) in extBalloc() argument
498 struct jfs_inode_info *ji = JFS_IP(ip); in extBalloc()
499 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb); in extBalloc()
501 int rc, nbperpage = sbi->nbperpage; in extBalloc()
502 struct bmap *bmp = sbi->bmap; in extBalloc()
505 /* get the number of blocks to initially attempt to allocate. in extBalloc()
506 * we'll first try the number of blocks requested unless this in extBalloc()
508 * blocks in the map. in that case, we'll start off with the in extBalloc()
513 if (bmp->db_maxfreebud == -1) in extBalloc()
514 return -ENOSPC; in extBalloc()
516 max = (s64) 1 << bmp->db_maxfreebud; in extBalloc()
522 /* try to allocate blocks */ in extBalloc()
523 while ((rc = dbAlloc(ip, hint, nb, &daddr)) != 0) { in extBalloc()
527 if (rc != -ENOSPC) in extBalloc()
541 if (S_ISREG(ip->i_mode) && (ji->fileset == FILESYSTEM_I)) { in extBalloc()
543 spin_lock_irq(&ji->ag_lock); in extBalloc()
544 if (ji->active_ag == -1) { in extBalloc()
545 atomic_inc(&bmp->db_active[ag]); in extBalloc()
546 ji->active_ag = ag; in extBalloc()
547 } else if (ji->active_ag != ag) { in extBalloc()
548 atomic_dec(&bmp->db_active[ji->active_ag]); in extBalloc()
549 atomic_inc(&bmp->db_active[ag]); in extBalloc()
550 ji->active_ag = ag; in extBalloc()
552 spin_unlock_irq(&ji->ag_lock); in extBalloc()
567 * to a new set of blocks. If moving the extent, we initially
568 * will try to allocate disk blocks for the requested size
569 * (newnblks). if this fails (new contiguous free blocks not
571 * blocks (producing a smaller extent), with this smaller
572 * number of blocks consisting of the requested number of
573 * blocks rounded down to the next smaller power of 2
574 * number (i.e. 16 -> 8). We'll continue to round down and
575 * retry the allocation until the number of blocks to allocate
576 * is smaller than the number of blocks per page.
579 * ip - the inode of the file.
580 * blkno - starting block number of the extents current allocation.
581 * nblks - number of blocks within the extents current allocation.
582 * newnblks - pointer to a s64 value. on entry, this value is the
583 * the new desired extent size (number of blocks). on
585 * new size (new number of blocks).
586 * newblkno - the starting block number of the extents new allocation.
589 * 0 - success
590 * -EIO - i/o error.
591 * -ENOSPC - insufficient disk resources.
594 extBrealloc(struct inode *ip, in extBrealloc() argument
600 if ((rc = dbExtend(ip, blkno, nblks, *newnblks - nblks)) == 0) { in extBrealloc()
604 if (rc != -ENOSPC) in extBrealloc()
609 * try to move the extent to a new set of blocks. in extBrealloc()
611 return (extBalloc(ip, blkno, newnblks, newblkno)); in extBrealloc()
619 * FUNCTION: round down a specified number of blocks to the next
623 * nb - the inode of the file.
638 i = 63 - i; in extRoundDown()
640 k = ((k - 1) & nb) ? k : k >> 1; in extRoundDown()