Lines Matching +full:ip +full:- +full:block

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
4 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
47 return rbm->rgd->rd_bits + rbm->bii; in rbm_bi()
52 BUG_ON(rbm->offset >= rbm->rgd->rd_data); in gfs2_rbm_to_block()
53 return rbm->rgd->rd_data0 + (rbm_bi(rbm)->bi_start * GFS2_NBBY) + in gfs2_rbm_to_block()
54 rbm->offset; in gfs2_rbm_to_block()
59 * to keep track of block allocation. Each block is represented by two
86 * gfs2_setbit - Set a bit in the bitmaps
89 * @new_state: the new state of the block
98 unsigned int buflen = bi->bi_bytes; in gfs2_setbit()
99 const unsigned int bit = (rbm->offset % GFS2_NBBY) * GFS2_BIT_SIZE; in gfs2_setbit()
101 byte1 = bi->bi_bh->b_data + bi->bi_offset + (rbm->offset / GFS2_NBBY); in gfs2_setbit()
102 end = bi->bi_bh->b_data + bi->bi_offset + buflen; in gfs2_setbit()
109 struct gfs2_sbd *sdp = rbm->rgd->rd_sbd; in gfs2_setbit()
112 rbm->offset, cur_state, new_state); in gfs2_setbit()
114 (unsigned long long)rbm->rgd->rd_addr, bi->bi_start, in gfs2_setbit()
115 (unsigned long long)bi->bi_bh->b_blocknr); in gfs2_setbit()
116 fs_warn(sdp, "bi_offset=0x%x bi_bytes=0x%x block=0x%llx\n", in gfs2_setbit()
117 bi->bi_offset, bi->bi_bytes, in gfs2_setbit()
120 gfs2_consist_rgrpd(rbm->rgd); in gfs2_setbit()
125 if (do_clone && bi->bi_clone) { in gfs2_setbit()
126 byte2 = bi->bi_clone + bi->bi_offset + (rbm->offset / GFS2_NBBY); in gfs2_setbit()
133 * gfs2_testbit - test a bit in the bitmaps
140 * Returns: The two bit block state of the requested bit
150 if (use_clone && bi->bi_clone) in gfs2_testbit()
151 buffer = bi->bi_clone; in gfs2_testbit()
153 buffer = bi->bi_bh->b_data; in gfs2_testbit()
154 buffer += bi->bi_offset; in gfs2_testbit()
155 byte = buffer + (rbm->offset / GFS2_NBBY); in gfs2_testbit()
156 bit = (rbm->offset % GFS2_NBBY) * GFS2_BIT_SIZE; in gfs2_testbit()
162 * gfs2_bit_search - search bitmap for a state
195 * rs_cmp - multi-block reservation range compare
200 * returns: 1 if the block range is beyond the reach of the reservation
201 * -1 if the block range is before the start of the reservation
202 * 0 if the block range overlaps with the reservation
206 if (start >= rs->rs_start + rs->rs_requested) in rs_cmp()
208 if (rs->rs_start >= start + len) in rs_cmp()
209 return -1; in rs_cmp()
214 * gfs2_bitfit - Search an rgrp's bitmap buffer to find a bit-pair representing
215 * a block in a given allocation state.
218 * @goal: start search at this block's bit-pair (within @buffer)
219 * @state: GFS2_BLKST_XXX the state of the block we're looking for.
221 * Scope of @goal and returned block number is only within this bitmap buffer,
223 * beginning of a bitmap block buffer, skipping any header structures, but
229 * of the block in case the end is no aligned to a natural boundary.
231 * Return: the block number (bitmap buffer scope) that was found
237 u32 spoint = (goal << 1) & ((8*sizeof(u64)) - 1); in gfs2_bitfit()
253 if (ptr == end && (len & (sizeof(u64) - 1))) in gfs2_bitfit()
254 tmp &= (((u64)~0) >> (64 - 8*(len & (sizeof(u64) - 1)))); in gfs2_bitfit()
258 ptr--; in gfs2_bitfit()
261 return (((const unsigned char *)ptr - buf) * GFS2_NBBY) + bit; in gfs2_bitfit()
265 * gfs2_rbm_from_block - Set the rbm based upon rgd and block number
267 * @block: The block number (filesystem relative)
270 * resource group and a filesystem relative block number. The
277 static int gfs2_rbm_from_block(struct gfs2_rbm *rbm, u64 block) in gfs2_rbm_from_block() argument
279 if (!rgrp_contains_block(rbm->rgd, block)) in gfs2_rbm_from_block()
280 return -E2BIG; in gfs2_rbm_from_block()
281 rbm->bii = 0; in gfs2_rbm_from_block()
282 rbm->offset = block - rbm->rgd->rd_data0; in gfs2_rbm_from_block()
283 /* Check if the block is within the first block */ in gfs2_rbm_from_block()
284 if (rbm->offset < rbm_bi(rbm)->bi_blocks) in gfs2_rbm_from_block()
288 rbm->offset += (sizeof(struct gfs2_rgrp) - in gfs2_rbm_from_block()
290 rbm->bii = rbm->offset / rbm->rgd->rd_sbd->sd_blocks_per_bitmap; in gfs2_rbm_from_block()
291 rbm->offset -= rbm->bii * rbm->rgd->rd_sbd->sd_blocks_per_bitmap; in gfs2_rbm_from_block()
296 * gfs2_rbm_add - add a number of blocks to an rbm
308 struct gfs2_rgrpd *rgd = rbm->rgd; in gfs2_rbm_add()
309 struct gfs2_bitmap *bi = rgd->rd_bits + rbm->bii; in gfs2_rbm_add()
311 if (rbm->offset + blocks < bi->bi_blocks) { in gfs2_rbm_add()
312 rbm->offset += blocks; in gfs2_rbm_add()
315 blocks -= bi->bi_blocks - rbm->offset; in gfs2_rbm_add()
319 if (bi == rgd->rd_bits + rgd->rd_length) in gfs2_rbm_add()
321 if (blocks < bi->bi_blocks) { in gfs2_rbm_add()
322 rbm->offset = blocks; in gfs2_rbm_add()
323 rbm->bii = bi - rgd->rd_bits; in gfs2_rbm_add()
326 blocks -= bi->bi_blocks; in gfs2_rbm_add()
331 * gfs2_unaligned_extlen - Look for free blocks which are not byte aligned
334 * @len: Decremented for each block found (terminate on zero)
336 * Returns: true if a non-free block is encountered or the end of the resource
349 (*len)--; in gfs2_unaligned_extlen()
360 * gfs2_free_extlen - Return extent length of free blocks
364 * Starting at the block specified by the rbm, see how many free blocks
367 * on a block by block basis in case of unaligned blocks. Also this
382 u64 block; in gfs2_free_extlen() local
386 gfs2_unaligned_extlen(&rbm, 4 - n_unaligned, &len)) in gfs2_free_extlen()
393 start = bi->bi_bh->b_data; in gfs2_free_extlen()
394 if (bi->bi_clone) in gfs2_free_extlen()
395 start = bi->bi_clone; in gfs2_free_extlen()
396 start += bi->bi_offset; in gfs2_free_extlen()
397 end = start + bi->bi_bytes; in gfs2_free_extlen()
400 bytes = min_t(u32, len / GFS2_NBBY, (end - start)); in gfs2_free_extlen()
402 chunk_size = ((ptr == NULL) ? bytes : (ptr - start)); in gfs2_free_extlen()
405 len -= chunk_size; in gfs2_free_extlen()
406 block = gfs2_rbm_to_block(&rbm); in gfs2_free_extlen()
407 if (gfs2_rbm_from_block(&rbm, block + chunk_size)) { in gfs2_free_extlen()
422 return size - len; in gfs2_free_extlen()
426 * gfs2_bitcount - count the number of bits in a certain state
430 * @state: the state of the block we're looking for
460 * gfs2_rgrp_verify - Verify that a resource group is consistent
467 struct gfs2_sbd *sdp = rgd->rd_sbd; in gfs2_rgrp_verify()
469 u32 length = rgd->rd_length; in gfs2_rgrp_verify()
477 bi = rgd->rd_bits + buf; in gfs2_rgrp_verify()
480 bi->bi_bh->b_data + in gfs2_rgrp_verify()
481 bi->bi_offset, in gfs2_rgrp_verify()
482 bi->bi_bytes, x); in gfs2_rgrp_verify()
485 if (count[0] != rgd->rd_free) { in gfs2_rgrp_verify()
487 count[0], rgd->rd_free); in gfs2_rgrp_verify()
492 tmp = rgd->rd_data - rgd->rd_free - rgd->rd_dinodes; in gfs2_rgrp_verify()
500 if (count[2] + count[3] != rgd->rd_dinodes) { in gfs2_rgrp_verify()
502 count[2] + count[3], rgd->rd_dinodes); in gfs2_rgrp_verify()
509 * gfs2_blk2rgrpd - Find resource group for a given data/meta block number
511 * @blk: The data block number
519 * match any block within the extent of the rgrp.
529 spin_lock(&sdp->sd_rindex_spin); in gfs2_blk2rgrpd()
530 n = sdp->sd_rindex_tree.rb_node; in gfs2_blk2rgrpd()
534 if (blk < cur->rd_addr) in gfs2_blk2rgrpd()
535 next = n->rb_left; in gfs2_blk2rgrpd()
536 else if (blk >= cur->rd_data0 + cur->rd_data) in gfs2_blk2rgrpd()
537 next = n->rb_right; in gfs2_blk2rgrpd()
539 spin_unlock(&sdp->sd_rindex_spin); in gfs2_blk2rgrpd()
541 if (blk < cur->rd_addr) in gfs2_blk2rgrpd()
543 if (blk >= cur->rd_data0 + cur->rd_data) in gfs2_blk2rgrpd()
550 spin_unlock(&sdp->sd_rindex_spin); in gfs2_blk2rgrpd()
556 * gfs2_rgrpd_get_first - get the first Resource Group in the filesystem
567 spin_lock(&sdp->sd_rindex_spin); in gfs2_rgrpd_get_first()
568 n = rb_first(&sdp->sd_rindex_tree); in gfs2_rgrpd_get_first()
570 spin_unlock(&sdp->sd_rindex_spin); in gfs2_rgrpd_get_first()
576 * gfs2_rgrpd_get_next - get the next RG
584 struct gfs2_sbd *sdp = rgd->rd_sbd; in gfs2_rgrpd_get_next()
587 spin_lock(&sdp->sd_rindex_spin); in gfs2_rgrpd_get_next()
588 n = rb_next(&rgd->rd_node); in gfs2_rgrpd_get_next()
590 n = rb_first(&sdp->sd_rindex_tree); in gfs2_rgrpd_get_next()
592 if (unlikely(&rgd->rd_node == n)) { in gfs2_rgrpd_get_next()
593 spin_unlock(&sdp->sd_rindex_spin); in gfs2_rgrpd_get_next()
597 spin_unlock(&sdp->sd_rindex_spin); in gfs2_rgrpd_get_next()
601 void check_and_update_goal(struct gfs2_inode *ip) in check_and_update_goal() argument
603 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in check_and_update_goal()
604 if (!ip->i_goal || gfs2_blk2rgrpd(sdp, ip->i_goal, 1) == NULL) in check_and_update_goal()
605 ip->i_goal = ip->i_no_addr; in check_and_update_goal()
612 for (x = 0; x < rgd->rd_length; x++) { in gfs2_free_clones()
613 struct gfs2_bitmap *bi = rgd->rd_bits + x; in gfs2_free_clones()
614 kfree(bi->bi_clone); in gfs2_free_clones()
615 bi->bi_clone = NULL; in gfs2_free_clones()
622 struct gfs2_inode *ip = container_of(rs, struct gfs2_inode, i_res); in dump_rs() local
626 (unsigned long long)ip->i_no_addr, in dump_rs()
627 (unsigned long long)rs->rs_start, in dump_rs()
628 rs->rs_requested); in dump_rs()
632 * __rs_deltree - remove a multi-block reservation from the rgd tree
643 rgd = rs->rs_rgd; in __rs_deltree()
645 rb_erase(&rs->rs_node, &rgd->rd_rstree); in __rs_deltree()
646 RB_CLEAR_NODE(&rs->rs_node); in __rs_deltree()
648 if (rs->rs_requested) { in __rs_deltree()
650 BUG_ON(rs->rs_rgd->rd_requested < rs->rs_requested); in __rs_deltree()
651 rs->rs_rgd->rd_requested -= rs->rs_requested; in __rs_deltree()
657 rgd->rd_extfail_pt += rs->rs_requested; in __rs_deltree()
658 rs->rs_requested = 0; in __rs_deltree()
663 * gfs2_rs_deltree - remove a multi-block reservation from the rgd tree
671 rgd = rs->rs_rgd; in gfs2_rs_deltree()
673 spin_lock(&rgd->rd_rsspin); in gfs2_rs_deltree()
675 BUG_ON(rs->rs_requested); in gfs2_rs_deltree()
676 spin_unlock(&rgd->rd_rsspin); in gfs2_rs_deltree()
681 * gfs2_rs_delete - delete a multi-block reservation
682 * @ip: The inode for this reservation
685 void gfs2_rs_delete(struct gfs2_inode *ip) in gfs2_rs_delete() argument
687 struct inode *inode = &ip->i_inode; in gfs2_rs_delete()
689 down_write(&ip->i_rw_mutex); in gfs2_rs_delete()
690 if (atomic_read(&inode->i_writecount) <= 1) in gfs2_rs_delete()
691 gfs2_rs_deltree(&ip->i_res); in gfs2_rs_delete()
692 up_write(&ip->i_rw_mutex); in gfs2_rs_delete()
696 * return_all_reservations - return all reserved blocks back to the rgrp.
701 * all of their corresponding "no-fly zones".
708 spin_lock(&rgd->rd_rsspin); in return_all_reservations()
709 while ((n = rb_first(&rgd->rd_rstree))) { in return_all_reservations()
713 spin_unlock(&rgd->rd_rsspin); in return_all_reservations()
722 while ((n = rb_first(&sdp->sd_rindex_tree))) { in gfs2_clear_rgrpd()
724 gl = rgd->rd_gl; in gfs2_clear_rgrpd()
726 rb_erase(n, &sdp->sd_rindex_tree); in gfs2_clear_rgrpd()
729 if (gl->gl_state != LM_ST_UNLOCKED) { in gfs2_clear_rgrpd()
731 flush_delayed_work(&gl->gl_work); in gfs2_clear_rgrpd()
740 kfree(rgd->rd_bits); in gfs2_clear_rgrpd()
741 rgd->rd_bits = NULL; in gfs2_clear_rgrpd()
747 * compute_bitstructs - Compute the bitmap sizes
750 * Calculates bitmap descriptors, one for each block that contains bitmap data
757 struct gfs2_sbd *sdp = rgd->rd_sbd; in compute_bitstructs()
759 u32 length = rgd->rd_length; /* # blocks in hdr & bitmap */ in compute_bitstructs()
764 return -EINVAL; in compute_bitstructs()
766 rgd->rd_bits = kcalloc(length, sizeof(struct gfs2_bitmap), GFP_NOFS); in compute_bitstructs()
767 if (!rgd->rd_bits) in compute_bitstructs()
768 return -ENOMEM; in compute_bitstructs()
770 bytes_left = rgd->rd_bitbytes; in compute_bitstructs()
773 bi = rgd->rd_bits + x; in compute_bitstructs()
775 bi->bi_flags = 0; in compute_bitstructs()
776 /* small rgrp; bitmap stored completely in header block */ in compute_bitstructs()
779 bi->bi_offset = sizeof(struct gfs2_rgrp); in compute_bitstructs()
780 bi->bi_start = 0; in compute_bitstructs()
781 bi->bi_bytes = bytes; in compute_bitstructs()
782 bi->bi_blocks = bytes * GFS2_NBBY; in compute_bitstructs()
783 /* header block */ in compute_bitstructs()
785 bytes = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_rgrp); in compute_bitstructs()
786 bi->bi_offset = sizeof(struct gfs2_rgrp); in compute_bitstructs()
787 bi->bi_start = 0; in compute_bitstructs()
788 bi->bi_bytes = bytes; in compute_bitstructs()
789 bi->bi_blocks = bytes * GFS2_NBBY; in compute_bitstructs()
790 /* last block */ in compute_bitstructs()
793 bi->bi_offset = sizeof(struct gfs2_meta_header); in compute_bitstructs()
794 bi->bi_start = rgd->rd_bitbytes - bytes_left; in compute_bitstructs()
795 bi->bi_bytes = bytes; in compute_bitstructs()
796 bi->bi_blocks = bytes * GFS2_NBBY; in compute_bitstructs()
799 bytes = sdp->sd_sb.sb_bsize - in compute_bitstructs()
801 bi->bi_offset = sizeof(struct gfs2_meta_header); in compute_bitstructs()
802 bi->bi_start = rgd->rd_bitbytes - bytes_left; in compute_bitstructs()
803 bi->bi_bytes = bytes; in compute_bitstructs()
804 bi->bi_blocks = bytes * GFS2_NBBY; in compute_bitstructs()
807 bytes_left -= bytes; in compute_bitstructs()
812 return -EIO; in compute_bitstructs()
814 bi = rgd->rd_bits + (length - 1); in compute_bitstructs()
815 if ((bi->bi_start + bi->bi_bytes) * GFS2_NBBY != rgd->rd_data) { in compute_bitstructs()
823 (unsigned long long)rgd->rd_addr, in compute_bitstructs()
824 rgd->rd_length, in compute_bitstructs()
825 (unsigned long long)rgd->rd_data0, in compute_bitstructs()
826 rgd->rd_data, in compute_bitstructs()
827 rgd->rd_bitbytes, in compute_bitstructs()
828 bi->bi_start, bi->bi_bytes, bi->bi_offset); in compute_bitstructs()
830 return -EIO; in compute_bitstructs()
837 * gfs2_ri_total - Total up the file system space, according to the rindex.
844 struct inode *inode = sdp->sd_rindex; in gfs2_ri_total()
845 struct gfs2_inode *ip = GFS2_I(inode); in gfs2_ri_total() local
854 error = gfs2_internal_read(ip, buf, &pos, in gfs2_ri_total()
858 total_data += be32_to_cpu(((struct gfs2_rindex *)buf)->ri_data); in gfs2_ri_total()
865 struct gfs2_sbd *sdp = rgd->rd_sbd; in rgd_insert()
866 struct rb_node **newn = &sdp->sd_rindex_tree.rb_node, *parent = NULL; in rgd_insert()
874 if (rgd->rd_addr < cur->rd_addr) in rgd_insert()
875 newn = &((*newn)->rb_left); in rgd_insert()
876 else if (rgd->rd_addr > cur->rd_addr) in rgd_insert()
877 newn = &((*newn)->rb_right); in rgd_insert()
879 return -EEXIST; in rgd_insert()
882 rb_link_node(&rgd->rd_node, parent, newn); in rgd_insert()
883 rb_insert_color(&rgd->rd_node, &sdp->sd_rindex_tree); in rgd_insert()
884 sdp->sd_rgrps++; in rgd_insert()
889 * read_rindex_entry - Pull in a new resource index entry from the disk
890 * @ip: Pointer to the rindex inode
895 static int read_rindex_entry(struct gfs2_inode *ip) in read_rindex_entry() argument
897 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in read_rindex_entry()
898 loff_t pos = sdp->sd_rgrps * sizeof(struct gfs2_rindex); in read_rindex_entry()
903 if (pos >= i_size_read(&ip->i_inode)) in read_rindex_entry()
906 error = gfs2_internal_read(ip, (char *)&buf, &pos, in read_rindex_entry()
913 error = -ENOMEM; in read_rindex_entry()
917 rgd->rd_sbd = sdp; in read_rindex_entry()
918 rgd->rd_addr = be64_to_cpu(buf.ri_addr); in read_rindex_entry()
919 rgd->rd_length = be32_to_cpu(buf.ri_length); in read_rindex_entry()
920 rgd->rd_data0 = be64_to_cpu(buf.ri_data0); in read_rindex_entry()
921 rgd->rd_data = be32_to_cpu(buf.ri_data); in read_rindex_entry()
922 rgd->rd_bitbytes = be32_to_cpu(buf.ri_bitbytes); in read_rindex_entry()
923 spin_lock_init(&rgd->rd_rsspin); in read_rindex_entry()
924 mutex_init(&rgd->rd_mutex); in read_rindex_entry()
926 error = gfs2_glock_get(sdp, rgd->rd_addr, in read_rindex_entry()
927 &gfs2_rgrp_glops, CREATE, &rgd->rd_gl); in read_rindex_entry()
935 rgd->rd_rgl = (struct gfs2_rgrp_lvb *)rgd->rd_gl->gl_lksb.sb_lvbptr; in read_rindex_entry()
936 rgd->rd_flags &= ~GFS2_RDF_PREFERRED; in read_rindex_entry()
937 if (rgd->rd_data > sdp->sd_max_rg_data) in read_rindex_entry()
938 sdp->sd_max_rg_data = rgd->rd_data; in read_rindex_entry()
939 spin_lock(&sdp->sd_rindex_spin); in read_rindex_entry()
941 spin_unlock(&sdp->sd_rindex_spin); in read_rindex_entry()
943 glock_set_object(rgd->rd_gl, rgd); in read_rindex_entry()
949 gfs2_glock_put(rgd->rd_gl); in read_rindex_entry()
952 kfree(rgd->rd_bits); in read_rindex_entry()
953 rgd->rd_bits = NULL; in read_rindex_entry()
959 * set_rgrp_preferences - Run all the rgrps, selecting some we prefer to use
974 for (i = 0; i < sdp->sd_lockstruct.ls_jid; i++) in set_rgrp_preferences()
979 rgd->rd_flags |= GFS2_RDF_PREFERRED; in set_rgrp_preferences()
980 for (i = 0; i < sdp->sd_journals; i++) { in set_rgrp_preferences()
989 * gfs2_ri_update - Pull in a new resource index from the disk
990 * @ip: pointer to the rindex inode
995 static int gfs2_ri_update(struct gfs2_inode *ip) in gfs2_ri_update() argument
997 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_ri_update()
1001 error = read_rindex_entry(ip); in gfs2_ri_update()
1007 if (RB_EMPTY_ROOT(&sdp->sd_rindex_tree)) { in gfs2_ri_update()
1009 return -ENOENT; in gfs2_ri_update()
1013 sdp->sd_rindex_uptodate = 1; in gfs2_ri_update()
1018 * gfs2_rindex_update - Update the rindex if required
1036 struct gfs2_inode *ip = GFS2_I(sdp->sd_rindex); in gfs2_rindex_update() local
1037 struct gfs2_glock *gl = ip->i_gl; in gfs2_rindex_update()
1043 if (!sdp->sd_rindex_uptodate) { in gfs2_rindex_update()
1050 if (!sdp->sd_rindex_uptodate) in gfs2_rindex_update()
1051 error = gfs2_ri_update(ip); in gfs2_rindex_update()
1064 rg_flags = be32_to_cpu(str->rg_flags); in gfs2_rgrp_in()
1066 rgd->rd_flags &= GFS2_RDF_MASK; in gfs2_rgrp_in()
1067 rgd->rd_flags |= rg_flags; in gfs2_rgrp_in()
1068 rgd->rd_free = be32_to_cpu(str->rg_free); in gfs2_rgrp_in()
1069 rgd->rd_dinodes = be32_to_cpu(str->rg_dinodes); in gfs2_rgrp_in()
1070 rgd->rd_igeneration = be64_to_cpu(str->rg_igeneration); in gfs2_rgrp_in()
1078 rgl->rl_magic = cpu_to_be32(GFS2_MAGIC); in gfs2_rgrp_ondisk2lvb()
1079 rgl->rl_flags = str->rg_flags; in gfs2_rgrp_ondisk2lvb()
1080 rgl->rl_free = str->rg_free; in gfs2_rgrp_ondisk2lvb()
1081 rgl->rl_dinodes = str->rg_dinodes; in gfs2_rgrp_ondisk2lvb()
1082 rgl->rl_igeneration = str->rg_igeneration; in gfs2_rgrp_ondisk2lvb()
1083 rgl->__pad = 0UL; in gfs2_rgrp_ondisk2lvb()
1092 str->rg_flags = cpu_to_be32(rgd->rd_flags & ~GFS2_RDF_MASK); in gfs2_rgrp_out()
1093 str->rg_free = cpu_to_be32(rgd->rd_free); in gfs2_rgrp_out()
1094 str->rg_dinodes = cpu_to_be32(rgd->rd_dinodes); in gfs2_rgrp_out()
1096 str->rg_skip = 0; in gfs2_rgrp_out()
1097 else if (next->rd_addr > rgd->rd_addr) in gfs2_rgrp_out()
1098 str->rg_skip = cpu_to_be32(next->rd_addr - rgd->rd_addr); in gfs2_rgrp_out()
1099 str->rg_igeneration = cpu_to_be64(rgd->rd_igeneration); in gfs2_rgrp_out()
1100 str->rg_data0 = cpu_to_be64(rgd->rd_data0); in gfs2_rgrp_out()
1101 str->rg_data = cpu_to_be32(rgd->rd_data); in gfs2_rgrp_out()
1102 str->rg_bitbytes = cpu_to_be32(rgd->rd_bitbytes); in gfs2_rgrp_out()
1103 str->rg_crc = 0; in gfs2_rgrp_out()
1105 str->rg_crc = cpu_to_be32(crc); in gfs2_rgrp_out()
1107 memset(&str->rg_reserved, 0, sizeof(str->rg_reserved)); in gfs2_rgrp_out()
1108 gfs2_rgrp_ondisk2lvb(rgd->rd_rgl, buf); in gfs2_rgrp_out()
1113 struct gfs2_rgrp_lvb *rgl = rgd->rd_rgl; in gfs2_rgrp_lvb_valid()
1114 struct gfs2_rgrp *str = (struct gfs2_rgrp *)rgd->rd_bits[0].bi_bh->b_data; in gfs2_rgrp_lvb_valid()
1115 struct gfs2_sbd *sdp = rgd->rd_sbd; in gfs2_rgrp_lvb_valid()
1118 if (rgl->rl_flags != str->rg_flags) { in gfs2_rgrp_lvb_valid()
1120 (unsigned long long)rgd->rd_addr, in gfs2_rgrp_lvb_valid()
1121 be32_to_cpu(rgl->rl_flags), be32_to_cpu(str->rg_flags)); in gfs2_rgrp_lvb_valid()
1124 if (rgl->rl_free != str->rg_free) { in gfs2_rgrp_lvb_valid()
1126 (unsigned long long)rgd->rd_addr, in gfs2_rgrp_lvb_valid()
1127 be32_to_cpu(rgl->rl_free), be32_to_cpu(str->rg_free)); in gfs2_rgrp_lvb_valid()
1130 if (rgl->rl_dinodes != str->rg_dinodes) { in gfs2_rgrp_lvb_valid()
1132 (unsigned long long)rgd->rd_addr, in gfs2_rgrp_lvb_valid()
1133 be32_to_cpu(rgl->rl_dinodes), in gfs2_rgrp_lvb_valid()
1134 be32_to_cpu(str->rg_dinodes)); in gfs2_rgrp_lvb_valid()
1137 if (rgl->rl_igeneration != str->rg_igeneration) { in gfs2_rgrp_lvb_valid()
1139 (unsigned long long)rgd->rd_addr, in gfs2_rgrp_lvb_valid()
1140 (unsigned long long)be64_to_cpu(rgl->rl_igeneration), in gfs2_rgrp_lvb_valid()
1141 (unsigned long long)be64_to_cpu(str->rg_igeneration)); in gfs2_rgrp_lvb_valid()
1150 const u32 length = rgd->rd_length; in count_unlinked()
1154 for (i = 0, bi = rgd->rd_bits; i < length; i++, bi++) { in count_unlinked()
1156 buffer = bi->bi_bh->b_data + bi->bi_offset; in count_unlinked()
1157 WARN_ON(!buffer_uptodate(bi->bi_bh)); in count_unlinked()
1158 while (goal < bi->bi_blocks) { in count_unlinked()
1159 goal = gfs2_bitfit(buffer, bi->bi_bytes, goal, in count_unlinked()
1176 if (rgd->rd_free) { in rgrp_set_bitmap_flags()
1177 for (x = 0; x < rgd->rd_length; x++) { in rgrp_set_bitmap_flags()
1178 bi = rgd->rd_bits + x; in rgrp_set_bitmap_flags()
1179 clear_bit(GBF_FULL, &bi->bi_flags); in rgrp_set_bitmap_flags()
1182 for (x = 0; x < rgd->rd_length; x++) { in rgrp_set_bitmap_flags()
1183 bi = rgd->rd_bits + x; in rgrp_set_bitmap_flags()
1184 set_bit(GBF_FULL, &bi->bi_flags); in rgrp_set_bitmap_flags()
1190 * gfs2_rgrp_go_instantiate - Read in a RG's header and bitmaps
1201 struct gfs2_rgrpd *rgd = gl->gl_object; in gfs2_rgrp_go_instantiate()
1202 struct gfs2_sbd *sdp = rgd->rd_sbd; in gfs2_rgrp_go_instantiate()
1203 unsigned int length = rgd->rd_length; in gfs2_rgrp_go_instantiate()
1208 if (rgd->rd_bits[0].bi_bh != NULL) in gfs2_rgrp_go_instantiate()
1212 bi = rgd->rd_bits + x; in gfs2_rgrp_go_instantiate()
1213 error = gfs2_meta_read(gl, rgd->rd_addr + x, 0, 0, &bi->bi_bh); in gfs2_rgrp_go_instantiate()
1218 for (y = length; y--;) { in gfs2_rgrp_go_instantiate()
1219 bi = rgd->rd_bits + y; in gfs2_rgrp_go_instantiate()
1220 error = gfs2_meta_wait(sdp, bi->bi_bh); in gfs2_rgrp_go_instantiate()
1223 if (gfs2_metatype_check(sdp, bi->bi_bh, y ? GFS2_METATYPE_RB : in gfs2_rgrp_go_instantiate()
1225 error = -EIO; in gfs2_rgrp_go_instantiate()
1230 gfs2_rgrp_in(rgd, (rgd->rd_bits[0].bi_bh)->b_data); in gfs2_rgrp_go_instantiate()
1232 rgd->rd_flags |= GFS2_RDF_CHECK; in gfs2_rgrp_go_instantiate()
1233 rgd->rd_free_clone = rgd->rd_free; in gfs2_rgrp_go_instantiate()
1234 GLOCK_BUG_ON(rgd->rd_gl, rgd->rd_reserved); in gfs2_rgrp_go_instantiate()
1236 rgd->rd_extfail_pt = rgd->rd_free; in gfs2_rgrp_go_instantiate()
1237 if (cpu_to_be32(GFS2_MAGIC) != rgd->rd_rgl->rl_magic) { in gfs2_rgrp_go_instantiate()
1238 rgd->rd_rgl->rl_unlinked = cpu_to_be32(count_unlinked(rgd)); in gfs2_rgrp_go_instantiate()
1239 gfs2_rgrp_ondisk2lvb(rgd->rd_rgl, in gfs2_rgrp_go_instantiate()
1240 rgd->rd_bits[0].bi_bh->b_data); in gfs2_rgrp_go_instantiate()
1241 } else if (sdp->sd_args.ar_rgrplvb) { in gfs2_rgrp_go_instantiate()
1244 error = -EIO; in gfs2_rgrp_go_instantiate()
1247 if (rgd->rd_rgl->rl_unlinked == 0) in gfs2_rgrp_go_instantiate()
1248 rgd->rd_flags &= ~GFS2_RDF_CHECK; in gfs2_rgrp_go_instantiate()
1253 while (x--) { in gfs2_rgrp_go_instantiate()
1254 bi = rgd->rd_bits + x; in gfs2_rgrp_go_instantiate()
1255 brelse(bi->bi_bh); in gfs2_rgrp_go_instantiate()
1256 bi->bi_bh = NULL; in gfs2_rgrp_go_instantiate()
1257 gfs2_assert_warn(sdp, !bi->bi_clone); in gfs2_rgrp_go_instantiate()
1266 if (!test_bit(GLF_INSTANTIATE_NEEDED, &gh->gh_gl->gl_flags)) in update_rgrp_lvb()
1269 if (cpu_to_be32(GFS2_MAGIC) != rgd->rd_rgl->rl_magic) in update_rgrp_lvb()
1272 rl_flags = be32_to_cpu(rgd->rd_rgl->rl_flags); in update_rgrp_lvb()
1274 rgd->rd_flags &= GFS2_RDF_MASK; in update_rgrp_lvb()
1275 rgd->rd_flags |= (rl_flags | GFS2_RDF_CHECK); in update_rgrp_lvb()
1276 if (rgd->rd_rgl->rl_unlinked == 0) in update_rgrp_lvb()
1277 rgd->rd_flags &= ~GFS2_RDF_CHECK; in update_rgrp_lvb()
1278 rgd->rd_free = be32_to_cpu(rgd->rd_rgl->rl_free); in update_rgrp_lvb()
1280 rgd->rd_free_clone = rgd->rd_free; in update_rgrp_lvb()
1281 GLOCK_BUG_ON(rgd->rd_gl, rgd->rd_reserved); in update_rgrp_lvb()
1283 rgd->rd_extfail_pt = rgd->rd_free; in update_rgrp_lvb()
1284 rgd->rd_dinodes = be32_to_cpu(rgd->rd_rgl->rl_dinodes); in update_rgrp_lvb()
1285 rgd->rd_igeneration = be64_to_cpu(rgd->rd_rgl->rl_igeneration); in update_rgrp_lvb()
1290 * gfs2_rgrp_brelse - Release RG bitmaps read in with gfs2_rgrp_bh_get()
1297 int x, length = rgd->rd_length; in gfs2_rgrp_brelse()
1300 struct gfs2_bitmap *bi = rgd->rd_bits + x; in gfs2_rgrp_brelse()
1301 if (bi->bi_bh) { in gfs2_rgrp_brelse()
1302 brelse(bi->bi_bh); in gfs2_rgrp_brelse()
1303 bi->bi_bh = NULL; in gfs2_rgrp_brelse()
1306 set_bit(GLF_INSTANTIATE_NEEDED, &rgd->rd_gl->gl_flags); in gfs2_rgrp_brelse()
1313 struct super_block *sb = sdp->sd_vfs; in gfs2_rgrp_send_discards()
1317 int rv = -EIO; in gfs2_rgrp_send_discards()
1322 for (x = 0; x < bi->bi_bytes; x++) { in gfs2_rgrp_send_discards()
1323 const u8 *clone = bi->bi_clone ? bi->bi_clone : bi->bi_bh->b_data; in gfs2_rgrp_send_discards()
1324 clone += bi->bi_offset; in gfs2_rgrp_send_discards()
1327 const u8 *orig = bh->b_data + bi->bi_offset + x; in gfs2_rgrp_send_discards()
1335 blk = offset + ((bi->bi_start + x) * GFS2_NBBY); in gfs2_rgrp_send_discards()
1370 if (sdp->sd_args.ar_discard) in gfs2_rgrp_send_discards()
1372 sdp->sd_args.ar_discard = 0; in gfs2_rgrp_send_discards()
1377 * gfs2_fitrim - Generate discard requests for unused bits of the filesystem
1388 struct block_device *bdev = sdp->sd_vfs->s_bdev; in gfs2_fitrim()
1399 unsigned bs_shift = sdp->sd_sb.sb_bsize_shift; in gfs2_fitrim()
1402 return -EPERM; in gfs2_fitrim()
1404 if (!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) in gfs2_fitrim()
1405 return -EROFS; in gfs2_fitrim()
1408 return -EOPNOTSUPP; in gfs2_fitrim()
1411 return -EFAULT; in gfs2_fitrim()
1419 minlen = max_t(u64, r.minlen, sdp->sd_sb.sb_bsize); in gfs2_fitrim()
1422 if (end <= start || minlen > sdp->sd_max_rg_data) in gfs2_fitrim()
1423 return -EINVAL; in gfs2_fitrim()
1429 && (start > rgd_end->rd_data0 + rgd_end->rd_data)) in gfs2_fitrim()
1430 return -EINVAL; /* start is beyond the end of the fs */ in gfs2_fitrim()
1434 ret = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, in gfs2_fitrim()
1439 if (!(rgd->rd_flags & GFS2_RGF_TRIMMED)) { in gfs2_fitrim()
1441 for (x = 0; x < rgd->rd_length; x++) { in gfs2_fitrim()
1442 struct gfs2_bitmap *bi = rgd->rd_bits + x; in gfs2_fitrim()
1445 rgd->rd_data0, NULL, bi, minlen, in gfs2_fitrim()
1458 bh = rgd->rd_bits[0].bi_bh; in gfs2_fitrim()
1460 rgd->rd_flags |= GFS2_RGF_TRIMMED; in gfs2_fitrim()
1461 gfs2_trans_add_meta(rgd->rd_gl, bh); in gfs2_fitrim()
1462 gfs2_rgrp_out(rgd, bh->b_data); in gfs2_fitrim()
1478 return -EFAULT; in gfs2_fitrim()
1484 * rs_insert - insert a new multi-block reservation into the rgrp's rb_tree
1485 * @ip: the inode structure
1488 static void rs_insert(struct gfs2_inode *ip) in rs_insert() argument
1492 struct gfs2_blkreserv *rs = &ip->i_res; in rs_insert()
1493 struct gfs2_rgrpd *rgd = rs->rs_rgd; in rs_insert()
1497 spin_lock(&rgd->rd_rsspin); in rs_insert()
1498 newn = &rgd->rd_rstree.rb_node; in rs_insert()
1504 rc = rs_cmp(rs->rs_start, rs->rs_requested, cur); in rs_insert()
1506 newn = &((*newn)->rb_right); in rs_insert()
1508 newn = &((*newn)->rb_left); in rs_insert()
1510 spin_unlock(&rgd->rd_rsspin); in rs_insert()
1516 rb_link_node(&rs->rs_node, parent, newn); in rs_insert()
1517 rb_insert_color(&rs->rs_node, &rgd->rd_rstree); in rs_insert()
1520 rgd->rd_requested += rs->rs_requested; /* blocks requested */ in rs_insert()
1521 spin_unlock(&rgd->rd_rsspin); in rs_insert()
1526 * rgd_free - return the number of free blocks we can allocate
1531 * That's the clone-free blocks (blocks that are free, not including those
1542 if (WARN_ON_ONCE(rgd->rd_requested < rs->rs_requested)) in rgd_free()
1544 tot_reserved = rgd->rd_requested - rs->rs_requested; in rgd_free()
1546 if (rgd->rd_free_clone < tot_reserved) in rgd_free()
1549 tot_free = rgd->rd_free_clone - tot_reserved; in rgd_free()
1555 * rg_mblk_search - find a group of multiple free blocks to form a reservation
1557 * @ip: pointer to the inode for which we're reserving blocks
1562 static void rg_mblk_search(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip, in rg_mblk_search() argument
1567 struct gfs2_blkreserv *rs = &ip->i_res; in rg_mblk_search()
1571 struct inode *inode = &ip->i_inode; in rg_mblk_search()
1573 spin_lock(&rgd->rd_rsspin); in rg_mblk_search()
1575 if (rgd->rd_free_clone < rgd->rd_requested) in rg_mblk_search()
1577 blocks_available = rgd->rd_free_clone - rgd->rd_reserved; in rg_mblk_search()
1578 if (rgd == rs->rs_rgd) in rg_mblk_search()
1579 blocks_available += rs->rs_reserved; in rg_mblk_search()
1580 spin_unlock(&rgd->rd_rsspin); in rg_mblk_search()
1582 if (S_ISDIR(inode->i_mode)) in rg_mblk_search()
1585 extlen = max_t(u32, atomic_read(&ip->i_sizehint), ap->target); in rg_mblk_search()
1591 /* Find bitmap block that contains bits for goal block */ in rg_mblk_search()
1592 if (rgrp_contains_block(rgd, ip->i_goal)) in rg_mblk_search()
1593 goal = ip->i_goal; in rg_mblk_search()
1595 goal = rgd->rd_last_alloc + rgd->rd_data0; in rg_mblk_search()
1600 ret = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, &extlen, &ip->i_res, true); in rg_mblk_search()
1602 rs->rs_start = gfs2_rbm_to_block(&rbm); in rg_mblk_search()
1603 rs->rs_requested = extlen; in rg_mblk_search()
1604 rs_insert(ip); in rg_mblk_search()
1606 if (goal == rgd->rd_last_alloc + rgd->rd_data0) in rg_mblk_search()
1607 rgd->rd_last_alloc = 0; in rg_mblk_search()
1612 * gfs2_next_unreserved_block - Return next block that is not reserved
1614 * @block: The starting block
1618 * If the block does not appear in any reservation, then return the
1619 * block number unchanged. If it does appear in the reservation, then
1621 * first block number which is not reserved.
1624 static u64 gfs2_next_unreserved_block(struct gfs2_rgrpd *rgd, u64 block, in gfs2_next_unreserved_block() argument
1632 spin_lock(&rgd->rd_rsspin); in gfs2_next_unreserved_block()
1633 n = rgd->rd_rstree.rb_node; in gfs2_next_unreserved_block()
1636 rc = rs_cmp(block, length, rs); in gfs2_next_unreserved_block()
1638 n = n->rb_left; in gfs2_next_unreserved_block()
1640 n = n->rb_right; in gfs2_next_unreserved_block()
1646 while (rs_cmp(block, length, rs) == 0 && rs != ignore_rs) { in gfs2_next_unreserved_block()
1647 block = rs->rs_start + rs->rs_requested; in gfs2_next_unreserved_block()
1648 n = n->rb_right; in gfs2_next_unreserved_block()
1655 spin_unlock(&rgd->rd_rsspin); in gfs2_next_unreserved_block()
1656 return block; in gfs2_next_unreserved_block()
1660 * gfs2_reservation_check_and_update - Check for reservations during block alloc
1667 * a reservation covering this block. If not then this function is a
1668 * no-op. If there is, then the position is moved to the end of the
1670 * non-reserved block.
1680 u64 block = gfs2_rbm_to_block(rbm); in gfs2_reservation_check_and_update() local
1690 if (extlen <= maxext->len) in gfs2_reservation_check_and_update()
1698 nblock = gfs2_next_unreserved_block(rbm->rgd, block, extlen, rs); in gfs2_reservation_check_and_update()
1699 if (nblock == block) { in gfs2_reservation_check_and_update()
1703 if (extlen > maxext->len) { in gfs2_reservation_check_and_update()
1704 maxext->len = extlen; in gfs2_reservation_check_and_update()
1705 maxext->rbm = *rbm; in gfs2_reservation_check_and_update()
1708 u64 len = nblock - block; in gfs2_reservation_check_and_update()
1710 return -E2BIG; in gfs2_reservation_check_and_update()
1715 return -E2BIG; in gfs2_reservation_check_and_update()
1720 * gfs2_rbm_find - Look for blocks of a particular state
1730 * - If looking for free blocks, we set GBF_FULL on each bitmap which
1732 * - If looking for free blocks, we set rd_extfail_pt on each rgrp which
1733 * has come up short on a free block search.
1735 * Returns: 0 on success, -ENOSPC if there is no block of the requested state
1741 bool scan_from_start = rbm->bii == 0 && rbm->offset == 0; in gfs2_rbm_find()
1749 struct gfs2_extent maxext = { .rbm.rgd = rbm->rgd, }; in gfs2_rbm_find()
1756 last_bii = rbm->bii - (rbm->offset == 0); in gfs2_rbm_find()
1760 if (test_bit(GBF_FULL, &bi->bi_flags) && in gfs2_rbm_find()
1764 bh = bi->bi_bh; in gfs2_rbm_find()
1765 buffer = bh->b_data + bi->bi_offset; in gfs2_rbm_find()
1767 if (state != GFS2_BLKST_UNLINKED && bi->bi_clone) in gfs2_rbm_find()
1768 buffer = bi->bi_clone + bi->bi_offset; in gfs2_rbm_find()
1769 offset = gfs2_bitfit(buffer, bi->bi_bytes, rbm->offset, state); in gfs2_rbm_find()
1771 if (state == GFS2_BLKST_FREE && rbm->offset == 0) in gfs2_rbm_find()
1772 set_bit(GBF_FULL, &bi->bi_flags); in gfs2_rbm_find()
1775 rbm->offset = offset; in gfs2_rbm_find()
1785 if (ret == -E2BIG) { in gfs2_rbm_find()
1786 rbm->bii = 0; in gfs2_rbm_find()
1787 rbm->offset = 0; in gfs2_rbm_find()
1793 rbm->offset = 0; in gfs2_rbm_find()
1794 rbm->bii++; in gfs2_rbm_find()
1795 if (rbm->bii == rbm->rgd->rd_length) in gfs2_rbm_find()
1796 rbm->bii = 0; in gfs2_rbm_find()
1798 if (rbm->bii == 0) { in gfs2_rbm_find()
1807 if (wrapped && rbm->bii > last_bii) in gfs2_rbm_find()
1812 return -ENOSPC; in gfs2_rbm_find()
1817 if (wrapped && (scan_from_start || rbm->bii > last_bii) && in gfs2_rbm_find()
1818 *minext < rbm->rgd->rd_extfail_pt) in gfs2_rbm_find()
1819 rbm->rgd->rd_extfail_pt = *minext - 1; in gfs2_rbm_find()
1829 return -ENOSPC; in gfs2_rbm_find()
1833 * try_rgrp_unlink - Look for any unlinked, allocated, but unused inodes
1835 * @last_unlinked: block address of the last dinode we unlinked
1836 * @skip: block address we should explicitly not unlink
1844 u64 block; in try_rgrp_unlink() local
1845 struct gfs2_sbd *sdp = rgd->rd_sbd; in try_rgrp_unlink()
1847 struct gfs2_inode *ip; in try_rgrp_unlink() local
1855 if (error == -ENOSPC) in try_rgrp_unlink()
1860 block = gfs2_rbm_to_block(&rbm); in try_rgrp_unlink()
1861 if (gfs2_rbm_from_block(&rbm, block + 1)) in try_rgrp_unlink()
1863 if (*last_unlinked != NO_BLOCK && block <= *last_unlinked) in try_rgrp_unlink()
1865 if (block == skip) in try_rgrp_unlink()
1867 *last_unlinked = block; in try_rgrp_unlink()
1869 error = gfs2_glock_get(sdp, block, &gfs2_iopen_glops, CREATE, &gl); in try_rgrp_unlink()
1880 ip = gl->gl_object; in try_rgrp_unlink()
1882 if (ip || !gfs2_queue_try_to_evict(gl)) in try_rgrp_unlink()
1892 rgd->rd_flags &= ~GFS2_RDF_CHECK; in try_rgrp_unlink()
1897 * gfs2_rgrp_congested - Use stats to figure out whether an rgrp is congested
1925 const struct gfs2_glock *gl = rgd->rd_gl; in gfs2_rgrp_congested()
1926 const struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; in gfs2_rgrp_congested()
1937 st = &per_cpu_ptr(sdp->sd_lkstats, cpu)->lkstats[LM_TYPE_RGRP]; in gfs2_rgrp_congested()
1938 if (st->stats[GFS2_LKS_SRTTB]) { in gfs2_rgrp_congested()
1939 a_srttb += st->stats[GFS2_LKS_SRTTB]; in gfs2_rgrp_congested()
1943 st = &this_cpu_ptr(sdp->sd_lkstats)->lkstats[LM_TYPE_RGRP]; in gfs2_rgrp_congested()
1946 r_dcount = st->stats[GFS2_LKS_DCOUNT]; in gfs2_rgrp_congested()
1947 var = st->stats[GFS2_LKS_SRTTVARB] + in gfs2_rgrp_congested()
1948 gl->gl_stats.stats[GFS2_LKS_SRTTVARB]; in gfs2_rgrp_congested()
1951 l_srttb = gl->gl_stats.stats[GFS2_LKS_SRTTB]; in gfs2_rgrp_congested()
1952 l_dcount = gl->gl_stats.stats[GFS2_LKS_DCOUNT]; in gfs2_rgrp_congested()
1957 srttb_diff = a_srttb - l_srttb; in gfs2_rgrp_congested()
1970 * gfs2_rgrp_used_recently - test if an rgrp has been used recently
1971 * @rs: The block reservation with the rgrp to test
1982 rs->rs_rgd->rd_gl->gl_dstamp)); in gfs2_rgrp_used_recently()
1987 static u32 gfs2_orlov_skip(const struct gfs2_inode *ip) in gfs2_orlov_skip() argument
1989 const struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_orlov_skip()
1993 return skip % sdp->sd_rgrps; in gfs2_orlov_skip()
1999 struct gfs2_sbd *sdp = rgd->rd_sbd; in gfs2_select_rgrp()
2011 * fast_to_acquire - determine if a resource group will be fast to acquire
2019 struct gfs2_glock *gl = rgd->rd_gl; in fast_to_acquire()
2021 if (gl->gl_state != LM_ST_UNLOCKED && list_empty(&gl->gl_holders) && in fast_to_acquire()
2022 !test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags) && in fast_to_acquire()
2023 !test_bit(GLF_DEMOTE, &gl->gl_flags)) in fast_to_acquire()
2025 if (rgd->rd_flags & GFS2_RDF_PREFERRED) in fast_to_acquire()
2031 * gfs2_inplace_reserve - Reserve space in the filesystem
2032 * @ip: the inode to reserve space for
2035 * We try our best to find an rgrp that has at least ap->target blocks
2038 * at least ap->min_target blocks available.
2041 * -ENOMEM if a suitable rgrp can't be found
2045 int gfs2_inplace_reserve(struct gfs2_inode *ip, struct gfs2_alloc_parms *ap) in gfs2_inplace_reserve() argument
2047 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_inplace_reserve()
2049 struct gfs2_blkreserv *rs = &ip->i_res; in gfs2_inplace_reserve()
2053 u32 target = ap->target; in gfs2_inplace_reserve()
2057 BUG_ON(rs->rs_reserved); in gfs2_inplace_reserve()
2059 if (sdp->sd_args.ar_rgrplvb) in gfs2_inplace_reserve()
2062 return -EINVAL; in gfs2_inplace_reserve()
2064 begin = rs->rs_rgd; in gfs2_inplace_reserve()
2065 } else if (rs->rs_rgd && in gfs2_inplace_reserve()
2066 rgrp_contains_block(rs->rs_rgd, ip->i_goal)) { in gfs2_inplace_reserve()
2067 begin = rs->rs_rgd; in gfs2_inplace_reserve()
2069 check_and_update_goal(ip); in gfs2_inplace_reserve()
2070 rs->rs_rgd = begin = gfs2_blk2rgrpd(sdp, ip->i_goal, 1); in gfs2_inplace_reserve()
2072 if (S_ISDIR(ip->i_inode.i_mode) && (ap->aflags & GFS2_AF_ORLOV)) in gfs2_inplace_reserve()
2073 skip = gfs2_orlov_skip(ip); in gfs2_inplace_reserve()
2074 if (rs->rs_rgd == NULL) in gfs2_inplace_reserve()
2075 return -EBADSLT; in gfs2_inplace_reserve()
2080 rg_locked = gfs2_glock_is_locked_by_me(rs->rs_rgd->rd_gl); in gfs2_inplace_reserve()
2082 rgrp_lock_local(rs->rs_rgd); in gfs2_inplace_reserve()
2084 if (skip && skip--) in gfs2_inplace_reserve()
2088 !fast_to_acquire(rs->rs_rgd)) in gfs2_inplace_reserve()
2092 gfs2_rgrp_congested(rs->rs_rgd, loops)) in gfs2_inplace_reserve()
2095 error = gfs2_glock_nq_init(rs->rs_rgd->rd_gl, in gfs2_inplace_reserve()
2097 &ip->i_rgd_gh); in gfs2_inplace_reserve()
2100 rgrp_lock_local(rs->rs_rgd); in gfs2_inplace_reserve()
2102 gfs2_rgrp_congested(rs->rs_rgd, loops)) in gfs2_inplace_reserve()
2104 if (sdp->sd_args.ar_rgrplvb) { in gfs2_inplace_reserve()
2105 error = update_rgrp_lvb(rs->rs_rgd, in gfs2_inplace_reserve()
2106 &ip->i_rgd_gh); in gfs2_inplace_reserve()
2108 rgrp_unlock_local(rs->rs_rgd); in gfs2_inplace_reserve()
2109 gfs2_glock_dq_uninit(&ip->i_rgd_gh); in gfs2_inplace_reserve()
2116 if ((rs->rs_rgd->rd_flags & (GFS2_RGF_NOALLOC | in gfs2_inplace_reserve()
2118 (loops == 0 && target > rs->rs_rgd->rd_extfail_pt)) in gfs2_inplace_reserve()
2121 if (sdp->sd_args.ar_rgrplvb) { in gfs2_inplace_reserve()
2122 error = gfs2_instantiate(&ip->i_rgd_gh); in gfs2_inplace_reserve()
2129 rg_mblk_search(rs->rs_rgd, ip, ap); in gfs2_inplace_reserve()
2136 rgd = rs->rs_rgd; in gfs2_inplace_reserve()
2137 spin_lock(&rgd->rd_rsspin); in gfs2_inplace_reserve()
2139 blocks_available = rgd->rd_free_clone - rgd->rd_reserved; in gfs2_inplace_reserve()
2141 spin_unlock(&rgd->rd_rsspin); in gfs2_inplace_reserve()
2144 rs->rs_reserved = ap->target; in gfs2_inplace_reserve()
2145 if (rs->rs_reserved > blocks_available) in gfs2_inplace_reserve()
2146 rs->rs_reserved = blocks_available; in gfs2_inplace_reserve()
2147 rgd->rd_reserved += rs->rs_reserved; in gfs2_inplace_reserve()
2148 spin_unlock(&rgd->rd_rsspin); in gfs2_inplace_reserve()
2149 rgrp_unlock_local(rs->rs_rgd); in gfs2_inplace_reserve()
2153 if (rs->rs_rgd->rd_flags & GFS2_RDF_CHECK) in gfs2_inplace_reserve()
2154 try_rgrp_unlink(rs->rs_rgd, &last_unlinked, in gfs2_inplace_reserve()
2155 ip->i_no_addr); in gfs2_inplace_reserve()
2157 rgrp_unlock_local(rs->rs_rgd); in gfs2_inplace_reserve()
2165 gfs2_glock_dq_uninit(&ip->i_rgd_gh); in gfs2_inplace_reserve()
2168 if (gfs2_select_rgrp(&rs->rs_rgd, begin)) in gfs2_inplace_reserve()
2179 if (ip == GFS2_I(sdp->sd_rindex) && !sdp->sd_rindex_uptodate) { in gfs2_inplace_reserve()
2180 error = gfs2_ri_update(ip); in gfs2_inplace_reserve()
2186 if (ap->min_target) in gfs2_inplace_reserve()
2187 target = ap->min_target; in gfs2_inplace_reserve()
2193 return -ENOSPC; in gfs2_inplace_reserve()
2197 * gfs2_inplace_release - release an inplace reservation
2198 * @ip: the inode the reservation was taken out on
2203 void gfs2_inplace_release(struct gfs2_inode *ip) in gfs2_inplace_release() argument
2205 struct gfs2_blkreserv *rs = &ip->i_res; in gfs2_inplace_release()
2207 if (rs->rs_reserved) { in gfs2_inplace_release()
2208 struct gfs2_rgrpd *rgd = rs->rs_rgd; in gfs2_inplace_release()
2210 spin_lock(&rgd->rd_rsspin); in gfs2_inplace_release()
2211 GLOCK_BUG_ON(rgd->rd_gl, rgd->rd_reserved < rs->rs_reserved); in gfs2_inplace_release()
2212 rgd->rd_reserved -= rs->rs_reserved; in gfs2_inplace_release()
2213 spin_unlock(&rgd->rd_rsspin); in gfs2_inplace_release()
2214 rs->rs_reserved = 0; in gfs2_inplace_release()
2216 if (gfs2_holder_initialized(&ip->i_rgd_gh)) in gfs2_inplace_release()
2217 gfs2_glock_dq_uninit(&ip->i_rgd_gh); in gfs2_inplace_release()
2221 * gfs2_alloc_extent - allocate an extent from a given bitmap
2223 * @dinode: TRUE if the first block we allocate is for a dinode
2227 * Set the found bits to @new_state to change block's allocation state.
2232 struct gfs2_rbm pos = { .rgd = rbm->rgd, }; in gfs2_alloc_extent()
2234 u64 block; in gfs2_alloc_extent() local
2238 block = gfs2_rbm_to_block(rbm); in gfs2_alloc_extent()
2239 gfs2_trans_add_meta(rbm->rgd->rd_gl, rbm_bi(rbm)->bi_bh); in gfs2_alloc_extent()
2241 block++; in gfs2_alloc_extent()
2243 ret = gfs2_rbm_from_block(&pos, block); in gfs2_alloc_extent()
2246 gfs2_trans_add_meta(pos.rgd->rd_gl, rbm_bi(&pos)->bi_bh); in gfs2_alloc_extent()
2249 block++; in gfs2_alloc_extent()
2254 * rgblk_free - Change alloc state of given block(s)
2258 * @blen: the length of the block run (all must lie within ONE RG!)
2259 * @new_state: GFS2_BLKST_XXX the after-allocation block state
2271 while (blen--) { in rgblk_free()
2274 if (!bi->bi_clone) { in rgblk_free()
2275 bi->bi_clone = kmalloc(bi->bi_bh->b_size, in rgblk_free()
2277 memcpy(bi->bi_clone + bi->bi_offset, in rgblk_free()
2278 bi->bi_bh->b_data + bi->bi_offset, in rgblk_free()
2279 bi->bi_bytes); in rgblk_free()
2281 gfs2_trans_add_meta(rbm.rgd->rd_gl, bi->bi_bh); in rgblk_free()
2290 * gfs2_rgrp_dump - print out an rgrp
2303 spin_lock(&rgd->rd_rsspin); in gfs2_rgrp_dump()
2306 (unsigned long long)rgd->rd_addr, rgd->rd_flags, in gfs2_rgrp_dump()
2307 rgd->rd_free, rgd->rd_free_clone, rgd->rd_dinodes, in gfs2_rgrp_dump()
2308 rgd->rd_requested, rgd->rd_reserved, rgd->rd_extfail_pt); in gfs2_rgrp_dump()
2309 if (rgd->rd_sbd->sd_args.ar_rgrplvb && rgd->rd_rgl) { in gfs2_rgrp_dump()
2310 struct gfs2_rgrp_lvb *rgl = rgd->rd_rgl; in gfs2_rgrp_dump()
2313 be32_to_cpu(rgl->rl_flags), in gfs2_rgrp_dump()
2314 be32_to_cpu(rgl->rl_free), in gfs2_rgrp_dump()
2315 be32_to_cpu(rgl->rl_dinodes)); in gfs2_rgrp_dump()
2317 for (n = rb_first(&rgd->rd_rstree); n; n = rb_next(&trs->rs_node)) { in gfs2_rgrp_dump()
2321 spin_unlock(&rgd->rd_rsspin); in gfs2_rgrp_dump()
2326 struct gfs2_sbd *sdp = rgd->rd_sbd; in gfs2_rgrp_error()
2327 char fs_id_buf[sizeof(sdp->sd_fsname) + 7]; in gfs2_rgrp_error()
2330 (unsigned long long)rgd->rd_addr); in gfs2_rgrp_error()
2332 sprintf(fs_id_buf, "fsid=%s: ", sdp->sd_fsname); in gfs2_rgrp_error()
2334 rgd->rd_flags |= GFS2_RDF_ERROR; in gfs2_rgrp_error()
2338 * gfs2_adjust_reservation - Adjust (or remove) a reservation after allocation
2339 * @ip: The inode we have just allocated blocks for
2348 static void gfs2_adjust_reservation(struct gfs2_inode *ip, in gfs2_adjust_reservation() argument
2351 struct gfs2_blkreserv *rs = &ip->i_res; in gfs2_adjust_reservation()
2352 struct gfs2_rgrpd *rgd = rbm->rgd; in gfs2_adjust_reservation()
2354 BUG_ON(rs->rs_reserved < len); in gfs2_adjust_reservation()
2355 rs->rs_reserved -= len; in gfs2_adjust_reservation()
2359 if (rs->rs_start == start) { in gfs2_adjust_reservation()
2362 rs->rs_start += len; in gfs2_adjust_reservation()
2363 rlen = min(rs->rs_requested, len); in gfs2_adjust_reservation()
2364 rs->rs_requested -= rlen; in gfs2_adjust_reservation()
2365 rgd->rd_requested -= rlen; in gfs2_adjust_reservation()
2367 if (rs->rs_start < rgd->rd_data0 + rgd->rd_data && in gfs2_adjust_reservation()
2368 rs->rs_requested) in gfs2_adjust_reservation()
2370 /* We used up our block reservation, so we should in gfs2_adjust_reservation()
2372 atomic_add(RGRP_RSRV_ADDBLKS, &ip->i_sizehint); in gfs2_adjust_reservation()
2379 * gfs2_set_alloc_start - Set starting point for block allocation
2381 * @ip: The gfs2 inode
2386 * inode's goal block or the last allocation point in the rgrp.
2390 const struct gfs2_inode *ip, bool dinode) in gfs2_set_alloc_start() argument
2394 if (gfs2_rs_active(&ip->i_res)) { in gfs2_set_alloc_start()
2395 goal = ip->i_res.rs_start; in gfs2_set_alloc_start()
2397 if (!dinode && rgrp_contains_block(rbm->rgd, ip->i_goal)) in gfs2_set_alloc_start()
2398 goal = ip->i_goal; in gfs2_set_alloc_start()
2400 goal = rbm->rgd->rd_last_alloc + rbm->rgd->rd_data0; in gfs2_set_alloc_start()
2403 rbm->bii = 0; in gfs2_set_alloc_start()
2404 rbm->offset = 0; in gfs2_set_alloc_start()
2409 * gfs2_alloc_blocks - Allocate one or more blocks of data and/or a dinode
2410 * @ip: the inode to allocate the block for
2411 * @bn: Used to return the starting block number
2413 * @dinode: 1 if we're allocating a dinode block, else 0
2418 int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks, in gfs2_alloc_blocks() argument
2421 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_alloc_blocks()
2423 struct gfs2_rbm rbm = { .rgd = ip->i_res.rs_rgd, }; in gfs2_alloc_blocks()
2424 u64 block; /* block, within the file system scope */ in gfs2_alloc_blocks() local
2426 int error = -ENOSPC; in gfs2_alloc_blocks()
2428 BUG_ON(ip->i_res.rs_reserved < *nblocks); in gfs2_alloc_blocks()
2431 if (gfs2_rs_active(&ip->i_res)) { in gfs2_alloc_blocks()
2432 gfs2_set_alloc_start(&rbm, ip, dinode); in gfs2_alloc_blocks()
2433 error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, &minext, &ip->i_res, false); in gfs2_alloc_blocks()
2435 if (error == -ENOSPC) { in gfs2_alloc_blocks()
2436 gfs2_set_alloc_start(&rbm, ip, dinode); in gfs2_alloc_blocks()
2443 (unsigned long long)ip->i_no_addr, error, *nblocks, in gfs2_alloc_blocks()
2444 test_bit(GBF_FULL, &rbm.rgd->rd_bits->bi_flags), in gfs2_alloc_blocks()
2445 rbm.rgd->rd_extfail_pt); in gfs2_alloc_blocks()
2450 block = gfs2_rbm_to_block(&rbm); in gfs2_alloc_blocks()
2451 rbm.rgd->rd_last_alloc = block - rbm.rgd->rd_data0; in gfs2_alloc_blocks()
2453 ip->i_goal = block + *nblocks - 1; in gfs2_alloc_blocks()
2454 error = gfs2_meta_inode_buffer(ip, &dibh); in gfs2_alloc_blocks()
2457 (struct gfs2_dinode *)dibh->b_data; in gfs2_alloc_blocks()
2458 gfs2_trans_add_meta(ip->i_gl, dibh); in gfs2_alloc_blocks()
2459 di->di_goal_meta = di->di_goal_data = in gfs2_alloc_blocks()
2460 cpu_to_be64(ip->i_goal); in gfs2_alloc_blocks()
2464 spin_lock(&rbm.rgd->rd_rsspin); in gfs2_alloc_blocks()
2465 gfs2_adjust_reservation(ip, &rbm, *nblocks); in gfs2_alloc_blocks()
2466 if (rbm.rgd->rd_free < *nblocks || rbm.rgd->rd_reserved < *nblocks) { in gfs2_alloc_blocks()
2468 spin_unlock(&rbm.rgd->rd_rsspin); in gfs2_alloc_blocks()
2471 GLOCK_BUG_ON(rbm.rgd->rd_gl, rbm.rgd->rd_reserved < *nblocks); in gfs2_alloc_blocks()
2472 GLOCK_BUG_ON(rbm.rgd->rd_gl, rbm.rgd->rd_free_clone < *nblocks); in gfs2_alloc_blocks()
2473 GLOCK_BUG_ON(rbm.rgd->rd_gl, rbm.rgd->rd_free < *nblocks); in gfs2_alloc_blocks()
2474 rbm.rgd->rd_reserved -= *nblocks; in gfs2_alloc_blocks()
2475 rbm.rgd->rd_free_clone -= *nblocks; in gfs2_alloc_blocks()
2476 rbm.rgd->rd_free -= *nblocks; in gfs2_alloc_blocks()
2477 spin_unlock(&rbm.rgd->rd_rsspin); in gfs2_alloc_blocks()
2481 rbm.rgd->rd_dinodes++; in gfs2_alloc_blocks()
2482 generation = rbm.rgd->rd_igeneration++; in gfs2_alloc_blocks()
2484 generation = rbm.rgd->rd_igeneration++; in gfs2_alloc_blocks()
2485 ip->i_generation = generation; in gfs2_alloc_blocks()
2488 gfs2_trans_add_meta(rbm.rgd->rd_gl, rbm.rgd->rd_bits[0].bi_bh); in gfs2_alloc_blocks()
2489 gfs2_rgrp_out(rbm.rgd, rbm.rgd->rd_bits[0].bi_bh->b_data); in gfs2_alloc_blocks()
2492 gfs2_statfs_change(sdp, 0, -(s64)*nblocks, dinode ? 1 : 0); in gfs2_alloc_blocks()
2494 gfs2_trans_remove_revoke(sdp, block, *nblocks); in gfs2_alloc_blocks()
2496 gfs2_quota_change(ip, *nblocks, ip->i_inode.i_uid, ip->i_inode.i_gid); in gfs2_alloc_blocks()
2498 trace_gfs2_block_alloc(ip, rbm.rgd, block, *nblocks, in gfs2_alloc_blocks()
2500 *bn = block; in gfs2_alloc_blocks()
2506 return -EIO; in gfs2_alloc_blocks()
2510 * __gfs2_free_blocks - free a contiguous run of block(s)
2511 * @ip: the inode these blocks are being freed from
2513 * @bstart: first block of a run of contiguous blocks
2514 * @blen: the length of the block run
2519 void __gfs2_free_blocks(struct gfs2_inode *ip, struct gfs2_rgrpd *rgd, in __gfs2_free_blocks() argument
2522 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in __gfs2_free_blocks()
2526 trace_gfs2_block_alloc(ip, rgd, bstart, blen, GFS2_BLKST_FREE); in __gfs2_free_blocks()
2527 rgd->rd_free += blen; in __gfs2_free_blocks()
2528 rgd->rd_flags &= ~GFS2_RGF_TRIMMED; in __gfs2_free_blocks()
2529 gfs2_trans_add_meta(rgd->rd_gl, rgd->rd_bits[0].bi_bh); in __gfs2_free_blocks()
2530 gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data); in __gfs2_free_blocks()
2534 if (meta || ip->i_depth || gfs2_is_jdata(ip)) in __gfs2_free_blocks()
2535 gfs2_journal_wipe(ip, bstart, blen); in __gfs2_free_blocks()
2539 * gfs2_free_meta - free a contiguous run of data block(s)
2540 * @ip: the inode these blocks are being freed from
2542 * @bstart: first block of a run of contiguous blocks
2543 * @blen: the length of the block run
2547 void gfs2_free_meta(struct gfs2_inode *ip, struct gfs2_rgrpd *rgd, in gfs2_free_meta() argument
2550 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_free_meta()
2552 __gfs2_free_blocks(ip, rgd, bstart, blen, 1); in gfs2_free_meta()
2554 gfs2_quota_change(ip, -(s64)blen, ip->i_inode.i_uid, ip->i_inode.i_gid); in gfs2_free_meta()
2559 struct gfs2_inode *ip = GFS2_I(inode); in gfs2_unlink_di() local
2562 u64 blkno = ip->i_no_addr; in gfs2_unlink_di()
2569 trace_gfs2_block_alloc(ip, rgd, blkno, 1, GFS2_BLKST_UNLINKED); in gfs2_unlink_di()
2570 gfs2_trans_add_meta(rgd->rd_gl, rgd->rd_bits[0].bi_bh); in gfs2_unlink_di()
2571 gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data); in gfs2_unlink_di()
2572 be32_add_cpu(&rgd->rd_rgl->rl_unlinked, 1); in gfs2_unlink_di()
2576 void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip) in gfs2_free_di() argument
2578 struct gfs2_sbd *sdp = rgd->rd_sbd; in gfs2_free_di()
2581 rgblk_free(sdp, rgd, ip->i_no_addr, 1, GFS2_BLKST_FREE); in gfs2_free_di()
2582 if (!rgd->rd_dinodes) in gfs2_free_di()
2584 rgd->rd_dinodes--; in gfs2_free_di()
2585 rgd->rd_free++; in gfs2_free_di()
2587 gfs2_trans_add_meta(rgd->rd_gl, rgd->rd_bits[0].bi_bh); in gfs2_free_di()
2588 gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data); in gfs2_free_di()
2589 be32_add_cpu(&rgd->rd_rgl->rl_unlinked, -1); in gfs2_free_di()
2592 gfs2_statfs_change(sdp, 0, +1, -1); in gfs2_free_di()
2593 trace_gfs2_block_alloc(ip, rgd, ip->i_no_addr, 1, GFS2_BLKST_FREE); in gfs2_free_di()
2594 gfs2_quota_change(ip, -1, ip->i_inode.i_uid, ip->i_inode.i_gid); in gfs2_free_di()
2595 gfs2_journal_wipe(ip, ip->i_no_addr, 1); in gfs2_free_di()
2599 * gfs2_check_blk_type - Check the type of a block
2601 * @no_addr: The block number to check
2602 * @type: The block type we are looking for
2608 * Returns: 0 if the block type matches the expected type
2609 * -ESTALE if it doesn't match
2610 * or -ve errno if something went wrong while checking
2618 int error = -EINVAL; in gfs2_check_blk_type()
2624 error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_SHARED, 0, &rgd_gh); in gfs2_check_blk_type()
2634 * synchronization in case the block is an inode. (In case in gfs2_check_blk_type()
2635 * the block is not an inode, the block type will not match in gfs2_check_blk_type()
2639 error = -ESTALE; in gfs2_check_blk_type()
2649 * gfs2_rlist_add - add a RG to a list of RGs
2650 * @ip: the inode
2652 * @block: the block
2654 * Figure out what RG a block belongs to and add that RG to the list
2660 void gfs2_rlist_add(struct gfs2_inode *ip, struct gfs2_rgrp_list *rlist, in gfs2_rlist_add() argument
2661 u64 block) in gfs2_rlist_add() argument
2663 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_rlist_add()
2669 if (gfs2_assert_warn(sdp, !rlist->rl_ghs)) in gfs2_rlist_add()
2676 if (rlist->rl_rgrps) { in gfs2_rlist_add()
2677 rgd = rlist->rl_rgd[rlist->rl_rgrps - 1]; in gfs2_rlist_add()
2678 if (rgrp_contains_block(rgd, block)) in gfs2_rlist_add()
2680 rgd = gfs2_blk2rgrpd(sdp, block, 1); in gfs2_rlist_add()
2682 rgd = ip->i_res.rs_rgd; in gfs2_rlist_add()
2683 if (!rgd || !rgrp_contains_block(rgd, block)) in gfs2_rlist_add()
2684 rgd = gfs2_blk2rgrpd(sdp, block, 1); in gfs2_rlist_add()
2688 fs_err(sdp, "rlist_add: no rgrp for block %llu\n", in gfs2_rlist_add()
2689 (unsigned long long)block); in gfs2_rlist_add()
2693 for (x = 0; x < rlist->rl_rgrps; x++) { in gfs2_rlist_add()
2694 if (rlist->rl_rgd[x] == rgd) { in gfs2_rlist_add()
2695 swap(rlist->rl_rgd[x], in gfs2_rlist_add()
2696 rlist->rl_rgd[rlist->rl_rgrps - 1]); in gfs2_rlist_add()
2701 if (rlist->rl_rgrps == rlist->rl_space) { in gfs2_rlist_add()
2702 new_space = rlist->rl_space + 10; in gfs2_rlist_add()
2707 if (rlist->rl_rgd) { in gfs2_rlist_add()
2708 memcpy(tmp, rlist->rl_rgd, in gfs2_rlist_add()
2709 rlist->rl_space * sizeof(struct gfs2_rgrpd *)); in gfs2_rlist_add()
2710 kfree(rlist->rl_rgd); in gfs2_rlist_add()
2713 rlist->rl_space = new_space; in gfs2_rlist_add()
2714 rlist->rl_rgd = tmp; in gfs2_rlist_add()
2717 rlist->rl_rgd[rlist->rl_rgrps++] = rgd; in gfs2_rlist_add()
2721 * gfs2_rlist_alloc - all RGs have been added to the rlist, now allocate
2736 rlist->rl_ghs = kmalloc_array(rlist->rl_rgrps, in gfs2_rlist_alloc()
2739 for (x = 0; x < rlist->rl_rgrps; x++) in gfs2_rlist_alloc()
2740 gfs2_holder_init(rlist->rl_rgd[x]->rd_gl, state, flags, in gfs2_rlist_alloc()
2741 &rlist->rl_ghs[x]); in gfs2_rlist_alloc()
2745 * gfs2_rlist_free - free a resource group list
2754 kfree(rlist->rl_rgd); in gfs2_rlist_free()
2756 if (rlist->rl_ghs) { in gfs2_rlist_free()
2757 for (x = 0; x < rlist->rl_rgrps; x++) in gfs2_rlist_free()
2758 gfs2_holder_uninit(&rlist->rl_ghs[x]); in gfs2_rlist_free()
2759 kfree(rlist->rl_ghs); in gfs2_rlist_free()
2760 rlist->rl_ghs = NULL; in gfs2_rlist_free()
2766 mutex_lock(&rgd->rd_mutex); in rgrp_lock_local()
2771 mutex_unlock(&rgd->rd_mutex); in rgrp_unlock_local()