• Home
  • Raw
  • Download

Lines Matching +full:ip +full:- +full:blocks

2  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
3 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
55 * bits. So, each byte represents GFS2_NBBY (i.e. 4) blocks.
77 const struct gfs2_inode *ip, bool nowrap);
81 * gfs2_setbit - Set a bit in the bitmaps
93 unsigned int buflen = bi->bi_len; in gfs2_setbit()
94 const unsigned int bit = (rbm->offset % GFS2_NBBY) * GFS2_BIT_SIZE; in gfs2_setbit()
96 byte1 = bi->bi_bh->b_data + bi->bi_offset + (rbm->offset / GFS2_NBBY); in gfs2_setbit()
97 end = bi->bi_bh->b_data + bi->bi_offset + buflen; in gfs2_setbit()
105 rbm->offset, cur_state, new_state); in gfs2_setbit()
107 (unsigned long long)rbm->rgd->rd_addr, bi->bi_start); in gfs2_setbit()
109 bi->bi_offset, bi->bi_len); in gfs2_setbit()
111 gfs2_consist_rgrpd(rbm->rgd); in gfs2_setbit()
116 if (do_clone && bi->bi_clone) { in gfs2_setbit()
117 byte2 = bi->bi_clone + bi->bi_offset + (rbm->offset / GFS2_NBBY); in gfs2_setbit()
124 * gfs2_testbit - test a bit in the bitmaps
129 * not the "real" bitmaps, to avoid allocating recently freed blocks.
141 if (use_clone && bi->bi_clone) in gfs2_testbit()
142 buffer = bi->bi_clone; in gfs2_testbit()
144 buffer = bi->bi_bh->b_data; in gfs2_testbit()
145 buffer += bi->bi_offset; in gfs2_testbit()
146 byte = buffer + (rbm->offset / GFS2_NBBY); in gfs2_testbit()
147 bit = (rbm->offset % GFS2_NBBY) * GFS2_BIT_SIZE; in gfs2_testbit()
166 * This allows searching of a whole u64 at once (32 blocks) with a
186 * rs_cmp - multi-block reservation range compare
188 * @len: number of blocks in the new reservation
192 * -1 if the block range is before the start of the reservation
197 u64 startblk = gfs2_rbm_to_block(&rs->rs_rbm); in rs_cmp()
199 if (blk >= startblk + rs->rs_free) in rs_cmp()
201 if (blk + len - 1 < startblk) in rs_cmp()
202 return -1; in rs_cmp()
207 * gfs2_bitfit - Search an rgrp's bitmap buffer to find a bit-pair representing
211 * @goal: start search at this block's bit-pair (within @buffer)
230 u32 spoint = (goal << 1) & ((8*sizeof(u64)) - 1); in gfs2_bitfit()
246 if (ptr == end && (len & (sizeof(u64) - 1))) in gfs2_bitfit()
247 tmp &= (((u64)~0) >> (64 - 8*(len & (sizeof(u64) - 1)))); in gfs2_bitfit()
251 ptr--; in gfs2_bitfit()
254 return (((const unsigned char *)ptr - buf) * GFS2_NBBY) + bit; in gfs2_bitfit()
258 * gfs2_rbm_from_block - Set the rbm based upon rgd and block number
272 u64 rblock = block - rbm->rgd->rd_data0; in gfs2_rbm_from_block()
275 return -EINVAL; in gfs2_rbm_from_block()
276 if (block >= rbm->rgd->rd_data0 + rbm->rgd->rd_data) in gfs2_rbm_from_block()
277 return -E2BIG; in gfs2_rbm_from_block()
279 rbm->bii = 0; in gfs2_rbm_from_block()
280 rbm->offset = (u32)(rblock); in gfs2_rbm_from_block()
282 if (rbm->offset < rbm_bi(rbm)->bi_blocks) in gfs2_rbm_from_block()
286 rbm->offset += (sizeof(struct gfs2_rgrp) - in gfs2_rbm_from_block()
288 rbm->bii = rbm->offset / rbm->rgd->rd_sbd->sd_blocks_per_bitmap; in gfs2_rbm_from_block()
289 rbm->offset -= rbm->bii * rbm->rgd->rd_sbd->sd_blocks_per_bitmap; in gfs2_rbm_from_block()
294 * gfs2_rbm_incr - increment an rbm structure
307 if (rbm->offset + 1 < rbm_bi(rbm)->bi_blocks) { /* in the same bitmap */ in gfs2_rbm_incr()
308 rbm->offset++; in gfs2_rbm_incr()
311 if (rbm->bii == rbm->rgd->rd_length - 1) /* at the last bitmap */ in gfs2_rbm_incr()
314 rbm->offset = 0; in gfs2_rbm_incr()
315 rbm->bii++; in gfs2_rbm_incr()
320 * gfs2_unaligned_extlen - Look for free blocks which are not byte aligned
322 * @n_unaligned: Number of unaligned blocks to check
325 * Returns: true if a non-free block is encountered
337 (*len)--; in gfs2_unaligned_extlen()
348 * gfs2_free_extlen - Return extent length of free blocks
352 * Starting at the block specified by the rbm, see how many free blocks
353 * there are, not reading more than len blocks ahead. This can be done
354 * using memchr_inv when the blocks are byte aligned, but has to be done
355 * on a block by block basis in case of unaligned blocks. Also this
359 * Returns: Number of free blocks in the extent
374 gfs2_unaligned_extlen(&rbm, 4 - n_unaligned, &len)) in gfs2_free_extlen()
381 start = bi->bi_bh->b_data; in gfs2_free_extlen()
382 if (bi->bi_clone) in gfs2_free_extlen()
383 start = bi->bi_clone; in gfs2_free_extlen()
384 start += bi->bi_offset; in gfs2_free_extlen()
385 end = start + bi->bi_len; in gfs2_free_extlen()
388 bytes = min_t(u32, len / GFS2_NBBY, (end - start)); in gfs2_free_extlen()
390 chunk_size = ((ptr == NULL) ? bytes : (ptr - start)); in gfs2_free_extlen()
393 len -= chunk_size; in gfs2_free_extlen()
410 return size - len; in gfs2_free_extlen()
414 * gfs2_bitcount - count the number of bits in a certain state
448 * gfs2_rgrp_verify - Verify that a resource group is consistent
455 struct gfs2_sbd *sdp = rgd->rd_sbd; in gfs2_rgrp_verify()
457 u32 length = rgd->rd_length; in gfs2_rgrp_verify()
463 /* Count # blocks in each of 4 possible allocation states */ in gfs2_rgrp_verify()
465 bi = rgd->rd_bits + buf; in gfs2_rgrp_verify()
468 bi->bi_bh->b_data + in gfs2_rgrp_verify()
469 bi->bi_offset, in gfs2_rgrp_verify()
470 bi->bi_len, x); in gfs2_rgrp_verify()
473 if (count[0] != rgd->rd_free) { in gfs2_rgrp_verify()
476 count[0], rgd->rd_free); in gfs2_rgrp_verify()
480 tmp = rgd->rd_data - rgd->rd_free - rgd->rd_dinodes; in gfs2_rgrp_verify()
488 if (count[2] + count[3] != rgd->rd_dinodes) { in gfs2_rgrp_verify()
491 count[2] + count[3], rgd->rd_dinodes); in gfs2_rgrp_verify()
497 * gfs2_blk2rgrpd - Find resource group for a given data/meta block number
503 * is when we need to match blocks which are not represented by the rgrp
504 * bitmap, but which are part of the rgrp (i.e. padding blocks) which are
506 * matches only valid data/metadata blocks, but with @exact false, it will
517 spin_lock(&sdp->sd_rindex_spin); in gfs2_blk2rgrpd()
518 n = sdp->sd_rindex_tree.rb_node; in gfs2_blk2rgrpd()
522 if (blk < cur->rd_addr) in gfs2_blk2rgrpd()
523 next = n->rb_left; in gfs2_blk2rgrpd()
524 else if (blk >= cur->rd_data0 + cur->rd_data) in gfs2_blk2rgrpd()
525 next = n->rb_right; in gfs2_blk2rgrpd()
527 spin_unlock(&sdp->sd_rindex_spin); in gfs2_blk2rgrpd()
529 if (blk < cur->rd_addr) in gfs2_blk2rgrpd()
531 if (blk >= cur->rd_data0 + cur->rd_data) in gfs2_blk2rgrpd()
538 spin_unlock(&sdp->sd_rindex_spin); in gfs2_blk2rgrpd()
544 * gfs2_rgrpd_get_first - get the first Resource Group in the filesystem
555 spin_lock(&sdp->sd_rindex_spin); in gfs2_rgrpd_get_first()
556 n = rb_first(&sdp->sd_rindex_tree); in gfs2_rgrpd_get_first()
558 spin_unlock(&sdp->sd_rindex_spin); in gfs2_rgrpd_get_first()
564 * gfs2_rgrpd_get_next - get the next RG
572 struct gfs2_sbd *sdp = rgd->rd_sbd; in gfs2_rgrpd_get_next()
575 spin_lock(&sdp->sd_rindex_spin); in gfs2_rgrpd_get_next()
576 n = rb_next(&rgd->rd_node); in gfs2_rgrpd_get_next()
578 n = rb_first(&sdp->sd_rindex_tree); in gfs2_rgrpd_get_next()
580 if (unlikely(&rgd->rd_node == n)) { in gfs2_rgrpd_get_next()
581 spin_unlock(&sdp->sd_rindex_spin); in gfs2_rgrpd_get_next()
585 spin_unlock(&sdp->sd_rindex_spin); in gfs2_rgrpd_get_next()
589 void check_and_update_goal(struct gfs2_inode *ip) in check_and_update_goal() argument
591 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in check_and_update_goal()
592 if (!ip->i_goal || gfs2_blk2rgrpd(sdp, ip->i_goal, 1) == NULL) in check_and_update_goal()
593 ip->i_goal = ip->i_no_addr; in check_and_update_goal()
600 for (x = 0; x < rgd->rd_length; x++) { in gfs2_free_clones()
601 struct gfs2_bitmap *bi = rgd->rd_bits + x; in gfs2_free_clones()
602 kfree(bi->bi_clone); in gfs2_free_clones()
603 bi->bi_clone = NULL; in gfs2_free_clones()
608 * gfs2_rsqa_alloc - make sure we have a reservation assigned to the inode
610 * @ip: the inode for this reservation
612 int gfs2_rsqa_alloc(struct gfs2_inode *ip) in gfs2_rsqa_alloc() argument
614 return gfs2_qa_alloc(ip); in gfs2_rsqa_alloc()
619 struct gfs2_inode *ip = container_of(rs, struct gfs2_inode, i_res); in dump_rs() local
622 (unsigned long long)ip->i_no_addr, in dump_rs()
623 (unsigned long long)gfs2_rbm_to_block(&rs->rs_rbm), in dump_rs()
624 rs->rs_rbm.offset, rs->rs_free); in dump_rs()
628 * __rs_deltree - remove a multi-block reservation from the rgd tree
639 rgd = rs->rs_rbm.rgd; in __rs_deltree()
641 rb_erase(&rs->rs_node, &rgd->rd_rstree); in __rs_deltree()
642 RB_CLEAR_NODE(&rs->rs_node); in __rs_deltree()
644 if (rs->rs_free) { in __rs_deltree()
645 u64 last_block = gfs2_rbm_to_block(&rs->rs_rbm) + in __rs_deltree()
646 rs->rs_free - 1; in __rs_deltree()
647 struct gfs2_rbm last_rbm = { .rgd = rs->rs_rbm.rgd, }; in __rs_deltree()
650 /* return reserved blocks to the rgrp */ in __rs_deltree()
651 BUG_ON(rs->rs_rbm.rgd->rd_reserved < rs->rs_free); in __rs_deltree()
652 rs->rs_rbm.rgd->rd_reserved -= rs->rs_free; in __rs_deltree()
654 it will only do so if the freed blocks are somehow in __rs_deltree()
655 contiguous with a span of free blocks that follows. Still, in __rs_deltree()
657 rgd->rd_extfail_pt += rs->rs_free; in __rs_deltree()
658 rs->rs_free = 0; in __rs_deltree()
661 start = rbm_bi(&rs->rs_rbm); in __rs_deltree()
664 clear_bit(GBF_FULL, &start->bi_flags); in __rs_deltree()
670 * gfs2_rs_deltree - remove a multi-block reservation from the rgd tree
678 rgd = rs->rs_rbm.rgd; in gfs2_rs_deltree()
680 spin_lock(&rgd->rd_rsspin); in gfs2_rs_deltree()
682 BUG_ON(rs->rs_free); in gfs2_rs_deltree()
683 spin_unlock(&rgd->rd_rsspin); in gfs2_rs_deltree()
688 * gfs2_rsqa_delete - delete a multi-block reservation and quota allocation
689 * @ip: The inode for this reservation
693 void gfs2_rsqa_delete(struct gfs2_inode *ip, atomic_t *wcount) in gfs2_rsqa_delete() argument
695 down_write(&ip->i_rw_mutex); in gfs2_rsqa_delete()
697 gfs2_rs_deltree(&ip->i_res); in gfs2_rsqa_delete()
698 up_write(&ip->i_rw_mutex); in gfs2_rsqa_delete()
699 gfs2_qa_delete(ip, wcount); in gfs2_rsqa_delete()
703 * return_all_reservations - return all reserved blocks back to the rgrp.
706 * We previously reserved a bunch of blocks for allocation. Now we need to
708 * all of their corresponding "no-fly zones".
715 spin_lock(&rgd->rd_rsspin); in return_all_reservations()
716 while ((n = rb_first(&rgd->rd_rstree))) { in return_all_reservations()
720 spin_unlock(&rgd->rd_rsspin); in return_all_reservations()
729 while ((n = rb_first(&sdp->sd_rindex_tree))) { in gfs2_clear_rgrpd()
731 gl = rgd->rd_gl; in gfs2_clear_rgrpd()
733 rb_erase(n, &sdp->sd_rindex_tree); in gfs2_clear_rgrpd()
742 kfree(rgd->rd_bits); in gfs2_clear_rgrpd()
743 rgd->rd_bits = NULL; in gfs2_clear_rgrpd()
751 pr_info("ri_addr = %llu\n", (unsigned long long)rgd->rd_addr); in gfs2_rindex_print()
752 pr_info("ri_length = %u\n", rgd->rd_length); in gfs2_rindex_print()
753 pr_info("ri_data0 = %llu\n", (unsigned long long)rgd->rd_data0); in gfs2_rindex_print()
754 pr_info("ri_data = %u\n", rgd->rd_data); in gfs2_rindex_print()
755 pr_info("ri_bitbytes = %u\n", rgd->rd_bitbytes); in gfs2_rindex_print()
759 * gfs2_compute_bitstructs - Compute the bitmap sizes
769 struct gfs2_sbd *sdp = rgd->rd_sbd; in compute_bitstructs()
771 u32 length = rgd->rd_length; /* # blocks in hdr & bitmap */ in compute_bitstructs()
776 return -EINVAL; in compute_bitstructs()
778 rgd->rd_bits = kcalloc(length, sizeof(struct gfs2_bitmap), GFP_NOFS); in compute_bitstructs()
779 if (!rgd->rd_bits) in compute_bitstructs()
780 return -ENOMEM; in compute_bitstructs()
782 bytes_left = rgd->rd_bitbytes; in compute_bitstructs()
785 bi = rgd->rd_bits + x; in compute_bitstructs()
787 bi->bi_flags = 0; in compute_bitstructs()
791 bi->bi_offset = sizeof(struct gfs2_rgrp); in compute_bitstructs()
792 bi->bi_start = 0; in compute_bitstructs()
793 bi->bi_len = bytes; in compute_bitstructs()
794 bi->bi_blocks = bytes * GFS2_NBBY; in compute_bitstructs()
797 bytes = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_rgrp); in compute_bitstructs()
798 bi->bi_offset = sizeof(struct gfs2_rgrp); in compute_bitstructs()
799 bi->bi_start = 0; in compute_bitstructs()
800 bi->bi_len = bytes; in compute_bitstructs()
801 bi->bi_blocks = bytes * GFS2_NBBY; in compute_bitstructs()
805 bi->bi_offset = sizeof(struct gfs2_meta_header); in compute_bitstructs()
806 bi->bi_start = rgd->rd_bitbytes - bytes_left; in compute_bitstructs()
807 bi->bi_len = bytes; in compute_bitstructs()
808 bi->bi_blocks = bytes * GFS2_NBBY; in compute_bitstructs()
809 /* other blocks */ in compute_bitstructs()
811 bytes = sdp->sd_sb.sb_bsize - in compute_bitstructs()
813 bi->bi_offset = sizeof(struct gfs2_meta_header); in compute_bitstructs()
814 bi->bi_start = rgd->rd_bitbytes - bytes_left; in compute_bitstructs()
815 bi->bi_len = bytes; in compute_bitstructs()
816 bi->bi_blocks = bytes * GFS2_NBBY; in compute_bitstructs()
819 bytes_left -= bytes; in compute_bitstructs()
824 return -EIO; in compute_bitstructs()
826 bi = rgd->rd_bits + (length - 1); in compute_bitstructs()
827 if ((bi->bi_start + bi->bi_len) * GFS2_NBBY != rgd->rd_data) { in compute_bitstructs()
831 bi->bi_start, bi->bi_len, bi->bi_offset); in compute_bitstructs()
833 return -EIO; in compute_bitstructs()
840 * gfs2_ri_total - Total up the file system space, according to the rindex.
847 struct inode *inode = sdp->sd_rindex; in gfs2_ri_total()
848 struct gfs2_inode *ip = GFS2_I(inode); in gfs2_ri_total() local
857 error = gfs2_internal_read(ip, buf, &pos, in gfs2_ri_total()
861 total_data += be32_to_cpu(((struct gfs2_rindex *)buf)->ri_data); in gfs2_ri_total()
868 struct gfs2_sbd *sdp = rgd->rd_sbd; in rgd_insert()
869 struct rb_node **newn = &sdp->sd_rindex_tree.rb_node, *parent = NULL; in rgd_insert()
877 if (rgd->rd_addr < cur->rd_addr) in rgd_insert()
878 newn = &((*newn)->rb_left); in rgd_insert()
879 else if (rgd->rd_addr > cur->rd_addr) in rgd_insert()
880 newn = &((*newn)->rb_right); in rgd_insert()
882 return -EEXIST; in rgd_insert()
885 rb_link_node(&rgd->rd_node, parent, newn); in rgd_insert()
886 rb_insert_color(&rgd->rd_node, &sdp->sd_rindex_tree); in rgd_insert()
887 sdp->sd_rgrps++; in rgd_insert()
892 * read_rindex_entry - Pull in a new resource index entry from the disk
893 * @ip: Pointer to the rindex inode
898 static int read_rindex_entry(struct gfs2_inode *ip) in read_rindex_entry() argument
900 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in read_rindex_entry()
901 const unsigned bsize = sdp->sd_sb.sb_bsize; in read_rindex_entry()
902 loff_t pos = sdp->sd_rgrps * sizeof(struct gfs2_rindex); in read_rindex_entry()
907 if (pos >= i_size_read(&ip->i_inode)) in read_rindex_entry()
910 error = gfs2_internal_read(ip, (char *)&buf, &pos, in read_rindex_entry()
917 error = -ENOMEM; in read_rindex_entry()
921 rgd->rd_sbd = sdp; in read_rindex_entry()
922 rgd->rd_addr = be64_to_cpu(buf.ri_addr); in read_rindex_entry()
923 rgd->rd_length = be32_to_cpu(buf.ri_length); in read_rindex_entry()
924 rgd->rd_data0 = be64_to_cpu(buf.ri_data0); in read_rindex_entry()
925 rgd->rd_data = be32_to_cpu(buf.ri_data); in read_rindex_entry()
926 rgd->rd_bitbytes = be32_to_cpu(buf.ri_bitbytes); in read_rindex_entry()
927 spin_lock_init(&rgd->rd_rsspin); in read_rindex_entry()
933 error = gfs2_glock_get(sdp, rgd->rd_addr, in read_rindex_entry()
934 &gfs2_rgrp_glops, CREATE, &rgd->rd_gl); in read_rindex_entry()
938 rgd->rd_rgl = (struct gfs2_rgrp_lvb *)rgd->rd_gl->gl_lksb.sb_lvbptr; in read_rindex_entry()
939 rgd->rd_flags &= ~(GFS2_RDF_UPTODATE | GFS2_RDF_PREFERRED); in read_rindex_entry()
940 if (rgd->rd_data > sdp->sd_max_rg_data) in read_rindex_entry()
941 sdp->sd_max_rg_data = rgd->rd_data; in read_rindex_entry()
942 spin_lock(&sdp->sd_rindex_spin); in read_rindex_entry()
944 spin_unlock(&sdp->sd_rindex_spin); in read_rindex_entry()
946 glock_set_object(rgd->rd_gl, rgd); in read_rindex_entry()
947 rgd->rd_gl->gl_vm.start = (rgd->rd_addr * bsize) & PAGE_MASK; in read_rindex_entry()
948 rgd->rd_gl->gl_vm.end = PAGE_ALIGN((rgd->rd_addr + in read_rindex_entry()
949 rgd->rd_length) * bsize) - 1; in read_rindex_entry()
954 gfs2_glock_put(rgd->rd_gl); in read_rindex_entry()
957 kfree(rgd->rd_bits); in read_rindex_entry()
958 rgd->rd_bits = NULL; in read_rindex_entry()
964 * set_rgrp_preferences - Run all the rgrps, selecting some we prefer to use
979 for (i = 0; i < sdp->sd_lockstruct.ls_jid; i++) in set_rgrp_preferences()
984 rgd->rd_flags |= GFS2_RDF_PREFERRED; in set_rgrp_preferences()
985 for (i = 0; i < sdp->sd_journals; i++) { in set_rgrp_preferences()
994 * gfs2_ri_update - Pull in a new resource index from the disk
995 * @ip: pointer to the rindex inode
1000 static int gfs2_ri_update(struct gfs2_inode *ip) in gfs2_ri_update() argument
1002 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_ri_update()
1006 error = read_rindex_entry(ip); in gfs2_ri_update()
1014 sdp->sd_rindex_uptodate = 1; in gfs2_ri_update()
1019 * gfs2_rindex_update - Update the rindex if required
1037 struct gfs2_inode *ip = GFS2_I(sdp->sd_rindex); in gfs2_rindex_update() local
1038 struct gfs2_glock *gl = ip->i_gl; in gfs2_rindex_update()
1044 if (!sdp->sd_rindex_uptodate) { in gfs2_rindex_update()
1051 if (!sdp->sd_rindex_uptodate) in gfs2_rindex_update()
1052 error = gfs2_ri_update(ip); in gfs2_rindex_update()
1065 rg_flags = be32_to_cpu(str->rg_flags); in gfs2_rgrp_in()
1067 rgd->rd_flags &= GFS2_RDF_MASK; in gfs2_rgrp_in()
1068 rgd->rd_flags |= rg_flags; in gfs2_rgrp_in()
1069 rgd->rd_free = be32_to_cpu(str->rg_free); in gfs2_rgrp_in()
1070 rgd->rd_dinodes = be32_to_cpu(str->rg_dinodes); in gfs2_rgrp_in()
1071 rgd->rd_igeneration = be64_to_cpu(str->rg_igeneration); in gfs2_rgrp_in()
1079 rgl->rl_magic = cpu_to_be32(GFS2_MAGIC); in gfs2_rgrp_ondisk2lvb()
1080 rgl->rl_flags = str->rg_flags; in gfs2_rgrp_ondisk2lvb()
1081 rgl->rl_free = str->rg_free; in gfs2_rgrp_ondisk2lvb()
1082 rgl->rl_dinodes = str->rg_dinodes; in gfs2_rgrp_ondisk2lvb()
1083 rgl->rl_igeneration = str->rg_igeneration; in gfs2_rgrp_ondisk2lvb()
1084 rgl->__pad = 0UL; in gfs2_rgrp_ondisk2lvb()
1093 str->rg_flags = cpu_to_be32(rgd->rd_flags & ~GFS2_RDF_MASK); in gfs2_rgrp_out()
1094 str->rg_free = cpu_to_be32(rgd->rd_free); in gfs2_rgrp_out()
1095 str->rg_dinodes = cpu_to_be32(rgd->rd_dinodes); in gfs2_rgrp_out()
1097 str->rg_skip = 0; in gfs2_rgrp_out()
1098 else if (next->rd_addr > rgd->rd_addr) in gfs2_rgrp_out()
1099 str->rg_skip = cpu_to_be32(next->rd_addr - rgd->rd_addr); in gfs2_rgrp_out()
1100 str->rg_igeneration = cpu_to_be64(rgd->rd_igeneration); in gfs2_rgrp_out()
1101 str->rg_data0 = cpu_to_be64(rgd->rd_data0); in gfs2_rgrp_out()
1102 str->rg_data = cpu_to_be32(rgd->rd_data); in gfs2_rgrp_out()
1103 str->rg_bitbytes = cpu_to_be32(rgd->rd_bitbytes); in gfs2_rgrp_out()
1104 str->rg_crc = 0; in gfs2_rgrp_out()
1106 str->rg_crc = cpu_to_be32(crc); in gfs2_rgrp_out()
1108 memset(&str->rg_reserved, 0, sizeof(str->rg_reserved)); in gfs2_rgrp_out()
1109 gfs2_rgrp_ondisk2lvb(rgd->rd_rgl, buf); in gfs2_rgrp_out()
1114 struct gfs2_rgrp_lvb *rgl = rgd->rd_rgl; in gfs2_rgrp_lvb_valid()
1115 struct gfs2_rgrp *str = (struct gfs2_rgrp *)rgd->rd_bits[0].bi_bh->b_data; in gfs2_rgrp_lvb_valid()
1117 if (rgl->rl_flags != str->rg_flags || rgl->rl_free != str->rg_free || in gfs2_rgrp_lvb_valid()
1118 rgl->rl_dinodes != str->rg_dinodes || in gfs2_rgrp_lvb_valid()
1119 rgl->rl_igeneration != str->rg_igeneration) in gfs2_rgrp_lvb_valid()
1127 const u32 length = rgd->rd_length; in count_unlinked()
1131 for (i = 0, bi = rgd->rd_bits; i < length; i++, bi++) { in count_unlinked()
1133 buffer = bi->bi_bh->b_data + bi->bi_offset; in count_unlinked()
1134 WARN_ON(!buffer_uptodate(bi->bi_bh)); in count_unlinked()
1135 while (goal < bi->bi_len * GFS2_NBBY) { in count_unlinked()
1136 goal = gfs2_bitfit(buffer, bi->bi_len, goal, in count_unlinked()
1150 * gfs2_rgrp_bh_get - Read in a RG's header and bitmaps
1153 * Read in all of a Resource Group's header and bitmap blocks.
1161 struct gfs2_sbd *sdp = rgd->rd_sbd; in gfs2_rgrp_bh_get()
1162 struct gfs2_glock *gl = rgd->rd_gl; in gfs2_rgrp_bh_get()
1163 unsigned int length = rgd->rd_length; in gfs2_rgrp_bh_get()
1168 if (rgd->rd_bits[0].bi_bh != NULL) in gfs2_rgrp_bh_get()
1172 bi = rgd->rd_bits + x; in gfs2_rgrp_bh_get()
1173 error = gfs2_meta_read(gl, rgd->rd_addr + x, 0, 0, &bi->bi_bh); in gfs2_rgrp_bh_get()
1178 for (y = length; y--;) { in gfs2_rgrp_bh_get()
1179 bi = rgd->rd_bits + y; in gfs2_rgrp_bh_get()
1180 error = gfs2_meta_wait(sdp, bi->bi_bh); in gfs2_rgrp_bh_get()
1183 if (gfs2_metatype_check(sdp, bi->bi_bh, y ? GFS2_METATYPE_RB : in gfs2_rgrp_bh_get()
1185 error = -EIO; in gfs2_rgrp_bh_get()
1190 if (!(rgd->rd_flags & GFS2_RDF_UPTODATE)) { in gfs2_rgrp_bh_get()
1192 clear_bit(GBF_FULL, &rgd->rd_bits[x].bi_flags); in gfs2_rgrp_bh_get()
1193 gfs2_rgrp_in(rgd, (rgd->rd_bits[0].bi_bh)->b_data); in gfs2_rgrp_bh_get()
1194 rgd->rd_flags |= (GFS2_RDF_UPTODATE | GFS2_RDF_CHECK); in gfs2_rgrp_bh_get()
1195 rgd->rd_free_clone = rgd->rd_free; in gfs2_rgrp_bh_get()
1197 rgd->rd_extfail_pt = rgd->rd_free; in gfs2_rgrp_bh_get()
1199 if (cpu_to_be32(GFS2_MAGIC) != rgd->rd_rgl->rl_magic) { in gfs2_rgrp_bh_get()
1200 rgd->rd_rgl->rl_unlinked = cpu_to_be32(count_unlinked(rgd)); in gfs2_rgrp_bh_get()
1201 gfs2_rgrp_ondisk2lvb(rgd->rd_rgl, in gfs2_rgrp_bh_get()
1202 rgd->rd_bits[0].bi_bh->b_data); in gfs2_rgrp_bh_get()
1204 else if (sdp->sd_args.ar_rgrplvb) { in gfs2_rgrp_bh_get()
1207 error = -EIO; in gfs2_rgrp_bh_get()
1210 if (rgd->rd_rgl->rl_unlinked == 0) in gfs2_rgrp_bh_get()
1211 rgd->rd_flags &= ~GFS2_RDF_CHECK; in gfs2_rgrp_bh_get()
1216 while (x--) { in gfs2_rgrp_bh_get()
1217 bi = rgd->rd_bits + x; in gfs2_rgrp_bh_get()
1218 brelse(bi->bi_bh); in gfs2_rgrp_bh_get()
1219 bi->bi_bh = NULL; in gfs2_rgrp_bh_get()
1220 gfs2_assert_warn(sdp, !bi->bi_clone); in gfs2_rgrp_bh_get()
1230 if (rgd->rd_flags & GFS2_RDF_UPTODATE) in update_rgrp_lvb()
1233 if (cpu_to_be32(GFS2_MAGIC) != rgd->rd_rgl->rl_magic) in update_rgrp_lvb()
1236 rl_flags = be32_to_cpu(rgd->rd_rgl->rl_flags); in update_rgrp_lvb()
1238 rgd->rd_flags &= GFS2_RDF_MASK; in update_rgrp_lvb()
1239 rgd->rd_flags |= (rl_flags | GFS2_RDF_CHECK); in update_rgrp_lvb()
1240 if (rgd->rd_rgl->rl_unlinked == 0) in update_rgrp_lvb()
1241 rgd->rd_flags &= ~GFS2_RDF_CHECK; in update_rgrp_lvb()
1242 rgd->rd_free = be32_to_cpu(rgd->rd_rgl->rl_free); in update_rgrp_lvb()
1243 rgd->rd_free_clone = rgd->rd_free; in update_rgrp_lvb()
1244 rgd->rd_dinodes = be32_to_cpu(rgd->rd_rgl->rl_dinodes); in update_rgrp_lvb()
1245 rgd->rd_igeneration = be64_to_cpu(rgd->rd_rgl->rl_igeneration); in update_rgrp_lvb()
1251 struct gfs2_rgrpd *rgd = gh->gh_gl->gl_object; in gfs2_rgrp_go_lock()
1252 struct gfs2_sbd *sdp = rgd->rd_sbd; in gfs2_rgrp_go_lock()
1254 if (gh->gh_flags & GL_SKIP && sdp->sd_args.ar_rgrplvb) in gfs2_rgrp_go_lock()
1260 * gfs2_rgrp_brelse - Release RG bitmaps read in with gfs2_rgrp_bh_get()
1267 int x, length = rgd->rd_length; in gfs2_rgrp_brelse()
1270 struct gfs2_bitmap *bi = rgd->rd_bits + x; in gfs2_rgrp_brelse()
1271 if (bi->bi_bh) { in gfs2_rgrp_brelse()
1272 brelse(bi->bi_bh); in gfs2_rgrp_brelse()
1273 bi->bi_bh = NULL; in gfs2_rgrp_brelse()
1280 * gfs2_rgrp_go_unlock - Unlock a rgrp glock
1287 struct gfs2_rgrpd *rgd = gh->gh_gl->gl_object; in gfs2_rgrp_go_unlock()
1288 int demote_requested = test_bit(GLF_DEMOTE, &gh->gh_gl->gl_flags) | in gfs2_rgrp_go_unlock()
1289 test_bit(GLF_PENDING_DEMOTE, &gh->gh_gl->gl_flags); in gfs2_rgrp_go_unlock()
1299 struct super_block *sb = sdp->sd_vfs; in gfs2_rgrp_send_discards()
1308 for (x = 0; x < bi->bi_len; x++) { in gfs2_rgrp_send_discards()
1309 const u8 *clone = bi->bi_clone ? bi->bi_clone : bi->bi_bh->b_data; in gfs2_rgrp_send_discards()
1310 clone += bi->bi_offset; in gfs2_rgrp_send_discards()
1313 const u8 *orig = bh->b_data + bi->bi_offset + x; in gfs2_rgrp_send_discards()
1321 blk = offset + ((bi->bi_start + x) * GFS2_NBBY); in gfs2_rgrp_send_discards()
1356 if (sdp->sd_args.ar_discard) in gfs2_rgrp_send_discards()
1358 sdp->sd_args.ar_discard = 0; in gfs2_rgrp_send_discards()
1359 return -EIO; in gfs2_rgrp_send_discards()
1363 * gfs2_fitrim - Generate discard requests for unused bits of the filesystem
1374 struct request_queue *q = bdev_get_queue(sdp->sd_vfs->s_bdev); in gfs2_fitrim()
1385 unsigned bs_shift = sdp->sd_sb.sb_bsize_shift; in gfs2_fitrim()
1388 return -EPERM; in gfs2_fitrim()
1391 return -EOPNOTSUPP; in gfs2_fitrim()
1394 return -EFAULT; in gfs2_fitrim()
1403 q->limits.discard_granularity) >> bs_shift; in gfs2_fitrim()
1405 if (end <= start || minlen > sdp->sd_max_rg_data) in gfs2_fitrim()
1406 return -EINVAL; in gfs2_fitrim()
1412 && (start > rgd_end->rd_data0 + rgd_end->rd_data)) in gfs2_fitrim()
1413 return -EINVAL; /* start is beyond the end of the fs */ in gfs2_fitrim()
1417 ret = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, &gh); in gfs2_fitrim()
1421 if (!(rgd->rd_flags & GFS2_RGF_TRIMMED)) { in gfs2_fitrim()
1423 for (x = 0; x < rgd->rd_length; x++) { in gfs2_fitrim()
1424 struct gfs2_bitmap *bi = rgd->rd_bits + x; in gfs2_fitrim()
1426 rgd->rd_data0, NULL, bi, minlen, in gfs2_fitrim()
1438 bh = rgd->rd_bits[0].bi_bh; in gfs2_fitrim()
1439 rgd->rd_flags |= GFS2_RGF_TRIMMED; in gfs2_fitrim()
1440 gfs2_trans_add_meta(rgd->rd_gl, bh); in gfs2_fitrim()
1441 gfs2_rgrp_out(rgd, bh->b_data); in gfs2_fitrim()
1456 return -EFAULT; in gfs2_fitrim()
1462 * rs_insert - insert a new multi-block reservation into the rgrp's rb_tree
1463 * @ip: the inode structure
1466 static void rs_insert(struct gfs2_inode *ip) in rs_insert() argument
1470 struct gfs2_blkreserv *rs = &ip->i_res; in rs_insert()
1471 struct gfs2_rgrpd *rgd = rs->rs_rbm.rgd; in rs_insert()
1472 u64 fsblock = gfs2_rbm_to_block(&rs->rs_rbm); in rs_insert()
1476 spin_lock(&rgd->rd_rsspin); in rs_insert()
1477 newn = &rgd->rd_rstree.rb_node; in rs_insert()
1483 rc = rs_cmp(fsblock, rs->rs_free, cur); in rs_insert()
1485 newn = &((*newn)->rb_right); in rs_insert()
1487 newn = &((*newn)->rb_left); in rs_insert()
1489 spin_unlock(&rgd->rd_rsspin); in rs_insert()
1495 rb_link_node(&rs->rs_node, parent, newn); in rs_insert()
1496 rb_insert_color(&rs->rs_node, &rgd->rd_rstree); in rs_insert()
1499 rgd->rd_reserved += rs->rs_free; /* blocks reserved */ in rs_insert()
1500 spin_unlock(&rgd->rd_rsspin); in rs_insert()
1505 * rgd_free - return the number of free blocks we can allocate.
1508 * This function returns the number of free blocks for an rgrp.
1509 * That's the clone-free blocks (blocks that are free, not including those
1512 * It also subtracts any blocks reserved by someone else, but does not
1513 * include free blocks that are still part of our current reservation,
1520 if (WARN_ON_ONCE(rgd->rd_reserved < rs->rs_free)) in rgd_free()
1522 tot_reserved = rgd->rd_reserved - rs->rs_free; in rgd_free()
1524 if (rgd->rd_free_clone < tot_reserved) in rgd_free()
1527 tot_free = rgd->rd_free_clone - tot_reserved; in rgd_free()
1533 * rg_mblk_search - find a group of multiple free blocks to form a reservation
1535 * @ip: pointer to the inode for which we're reserving blocks
1540 static void rg_mblk_search(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip, in rg_mblk_search() argument
1545 struct gfs2_blkreserv *rs = &ip->i_res; in rg_mblk_search()
1549 struct inode *inode = &ip->i_inode; in rg_mblk_search()
1551 if (S_ISDIR(inode->i_mode)) in rg_mblk_search()
1554 extlen = max_t(u32, atomic_read(&rs->rs_sizehint), ap->target); in rg_mblk_search()
1557 if ((rgd->rd_free_clone < rgd->rd_reserved) || (free_blocks < extlen)) in rg_mblk_search()
1561 if (rgrp_contains_block(rgd, ip->i_goal)) in rg_mblk_search()
1562 goal = ip->i_goal; in rg_mblk_search()
1564 goal = rgd->rd_last_alloc + rgd->rd_data0; in rg_mblk_search()
1569 ret = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, &extlen, ip, true); in rg_mblk_search()
1571 rs->rs_rbm = rbm; in rg_mblk_search()
1572 rs->rs_free = extlen; in rg_mblk_search()
1573 rs_insert(ip); in rg_mblk_search()
1575 if (goal == rgd->rd_last_alloc + rgd->rd_data0) in rg_mblk_search()
1576 rgd->rd_last_alloc = 0; in rg_mblk_search()
1581 * gfs2_next_unreserved_block - Return next block that is not reserved
1585 * @ip: Ignore any reservations for this inode
1595 const struct gfs2_inode *ip) in gfs2_next_unreserved_block() argument
1601 spin_lock(&rgd->rd_rsspin); in gfs2_next_unreserved_block()
1602 n = rgd->rd_rstree.rb_node; in gfs2_next_unreserved_block()
1607 n = n->rb_left; in gfs2_next_unreserved_block()
1609 n = n->rb_right; in gfs2_next_unreserved_block()
1615 while ((rs_cmp(block, length, rs) == 0) && (&ip->i_res != rs)) { in gfs2_next_unreserved_block()
1616 block = gfs2_rbm_to_block(&rs->rs_rbm) + rs->rs_free; in gfs2_next_unreserved_block()
1617 n = n->rb_right; in gfs2_next_unreserved_block()
1624 spin_unlock(&rgd->rd_rsspin); in gfs2_next_unreserved_block()
1629 * gfs2_reservation_check_and_update - Check for reservations during block alloc
1631 * @ip: The inode for which we are searching for blocks
1637 * no-op. If there is, then the position is moved to the end of the
1639 * non-reserved block.
1645 const struct gfs2_inode *ip, in gfs2_reservation_check_and_update() argument
1660 if (extlen <= maxext->len) in gfs2_reservation_check_and_update()
1668 nblock = gfs2_next_unreserved_block(rbm->rgd, block, extlen, ip); in gfs2_reservation_check_and_update()
1673 if (extlen > maxext->len) { in gfs2_reservation_check_and_update()
1674 maxext->len = extlen; in gfs2_reservation_check_and_update()
1675 maxext->rbm = *rbm; in gfs2_reservation_check_and_update()
1687 * gfs2_rbm_find - Look for blocks of a particular state
1692 * @ip: If set, check for reservations
1697 * - If looking for free blocks, we set GBF_FULL on each bitmap which
1698 * has no free blocks in it.
1699 * - If looking for free blocks, we set rd_extfail_pt on each rgrp which
1702 * Returns: 0 on success, -ENOSPC if there is no block of the requested state
1706 const struct gfs2_inode *ip, bool nowrap) in gfs2_rbm_find() argument
1711 int first_bii = rbm->bii; in gfs2_rbm_find()
1712 u32 first_offset = rbm->offset; in gfs2_rbm_find()
1716 int iters = rbm->rgd->rd_length; in gfs2_rbm_find()
1719 struct gfs2_extent maxext = { .rbm.rgd = rbm->rgd, }; in gfs2_rbm_find()
1725 if (rbm->offset != 0) in gfs2_rbm_find()
1730 if ((ip == NULL || !gfs2_rs_active(&ip->i_res)) && in gfs2_rbm_find()
1731 test_bit(GBF_FULL, &bi->bi_flags) && in gfs2_rbm_find()
1735 bh = bi->bi_bh; in gfs2_rbm_find()
1736 buffer = bh->b_data + bi->bi_offset; in gfs2_rbm_find()
1738 if (state != GFS2_BLKST_UNLINKED && bi->bi_clone) in gfs2_rbm_find()
1739 buffer = bi->bi_clone + bi->bi_offset; in gfs2_rbm_find()
1740 initial_offset = rbm->offset; in gfs2_rbm_find()
1741 offset = gfs2_bitfit(buffer, bi->bi_len, rbm->offset, state); in gfs2_rbm_find()
1744 rbm->offset = offset; in gfs2_rbm_find()
1745 if (ip == NULL) in gfs2_rbm_find()
1748 initial_bii = rbm->bii; in gfs2_rbm_find()
1749 ret = gfs2_reservation_check_and_update(rbm, ip, in gfs2_rbm_find()
1755 n += (rbm->bii - initial_bii); in gfs2_rbm_find()
1758 if (ret == -E2BIG) { in gfs2_rbm_find()
1759 rbm->bii = 0; in gfs2_rbm_find()
1760 rbm->offset = 0; in gfs2_rbm_find()
1761 n += (rbm->bii - initial_bii); in gfs2_rbm_find()
1768 set_bit(GBF_FULL, &bi->bi_flags); in gfs2_rbm_find()
1771 rbm->offset = 0; in gfs2_rbm_find()
1772 rbm->bii++; in gfs2_rbm_find()
1773 if (rbm->bii == rbm->rgd->rd_length) in gfs2_rbm_find()
1774 rbm->bii = 0; in gfs2_rbm_find()
1776 if ((rbm->bii == 0) && nowrap) in gfs2_rbm_find()
1785 return -ENOSPC; in gfs2_rbm_find()
1791 (*minext < rbm->rgd->rd_extfail_pt)) in gfs2_rbm_find()
1792 rbm->rgd->rd_extfail_pt = *minext; in gfs2_rbm_find()
1802 return -ENOSPC; in gfs2_rbm_find()
1806 * try_rgrp_unlink - Look for any unlinked, allocated, but unused inodes
1818 struct gfs2_sbd *sdp = rgd->rd_sbd; in try_rgrp_unlink()
1820 struct gfs2_inode *ip; in try_rgrp_unlink() local
1826 down_write(&sdp->sd_log_flush_lock); in try_rgrp_unlink()
1829 up_write(&sdp->sd_log_flush_lock); in try_rgrp_unlink()
1830 if (error == -ENOSPC) in try_rgrp_unlink()
1855 ip = gl->gl_object; in try_rgrp_unlink()
1857 if (ip || queue_work(gfs2_delete_workqueue, &gl->gl_delete) == 0) in try_rgrp_unlink()
1867 rgd->rd_flags &= ~GFS2_RDF_CHECK; in try_rgrp_unlink()
1872 * gfs2_rgrp_congested - Use stats to figure out whether an rgrp is congested
1900 const struct gfs2_glock *gl = rgd->rd_gl; in gfs2_rgrp_congested()
1901 const struct gfs2_sbd *sdp = gl->gl_name.ln_sbd; in gfs2_rgrp_congested()
1912 st = &per_cpu_ptr(sdp->sd_lkstats, cpu)->lkstats[LM_TYPE_RGRP]; in gfs2_rgrp_congested()
1913 if (st->stats[GFS2_LKS_SRTTB]) { in gfs2_rgrp_congested()
1914 a_srttb += st->stats[GFS2_LKS_SRTTB]; in gfs2_rgrp_congested()
1918 st = &this_cpu_ptr(sdp->sd_lkstats)->lkstats[LM_TYPE_RGRP]; in gfs2_rgrp_congested()
1921 r_dcount = st->stats[GFS2_LKS_DCOUNT]; in gfs2_rgrp_congested()
1922 var = st->stats[GFS2_LKS_SRTTVARB] + in gfs2_rgrp_congested()
1923 gl->gl_stats.stats[GFS2_LKS_SRTTVARB]; in gfs2_rgrp_congested()
1926 l_srttb = gl->gl_stats.stats[GFS2_LKS_SRTTB]; in gfs2_rgrp_congested()
1927 l_dcount = gl->gl_stats.stats[GFS2_LKS_DCOUNT]; in gfs2_rgrp_congested()
1932 srttb_diff = a_srttb - l_srttb; in gfs2_rgrp_congested()
1957 rs->rs_rbm.rgd->rd_gl->gl_dstamp)); in gfs2_rgrp_used_recently()
1962 static u32 gfs2_orlov_skip(const struct gfs2_inode *ip) in gfs2_orlov_skip() argument
1964 const struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_orlov_skip()
1968 return skip % sdp->sd_rgrps; in gfs2_orlov_skip()
1974 struct gfs2_sbd *sdp = rgd->rd_sbd; in gfs2_select_rgrp()
1986 * fast_to_acquire - determine if a resource group will be fast to acquire
1993 struct gfs2_glock *gl = rgd->rd_gl; in fast_to_acquire()
1995 if (gl->gl_state != LM_ST_UNLOCKED && list_empty(&gl->gl_holders) && in fast_to_acquire()
1996 !test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags) && in fast_to_acquire()
1997 !test_bit(GLF_DEMOTE, &gl->gl_flags)) in fast_to_acquire()
1999 if (rgd->rd_flags & GFS2_RDF_PREFERRED) in fast_to_acquire()
2005 * gfs2_inplace_reserve - Reserve space in the filesystem
2006 * @ip: the inode to reserve space for
2009 * We try our best to find an rgrp that has at least ap->target blocks
2012 * atleast ap->min_target blocks available. Either way, we set ap->allowed to
2013 * the number of blocks available in the chosen rgrp.
2016 * -ENOMEM if a suitable rgrp can't be found
2020 int gfs2_inplace_reserve(struct gfs2_inode *ip, struct gfs2_alloc_parms *ap) in gfs2_inplace_reserve() argument
2022 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_inplace_reserve()
2024 struct gfs2_blkreserv *rs = &ip->i_res; in gfs2_inplace_reserve()
2030 if (sdp->sd_args.ar_rgrplvb) in gfs2_inplace_reserve()
2032 if (gfs2_assert_warn(sdp, ap->target)) in gfs2_inplace_reserve()
2033 return -EINVAL; in gfs2_inplace_reserve()
2035 begin = rs->rs_rbm.rgd; in gfs2_inplace_reserve()
2036 } else if (rs->rs_rbm.rgd && in gfs2_inplace_reserve()
2037 rgrp_contains_block(rs->rs_rbm.rgd, ip->i_goal)) { in gfs2_inplace_reserve()
2038 begin = rs->rs_rbm.rgd; in gfs2_inplace_reserve()
2040 check_and_update_goal(ip); in gfs2_inplace_reserve()
2041 rs->rs_rbm.rgd = begin = gfs2_blk2rgrpd(sdp, ip->i_goal, 1); in gfs2_inplace_reserve()
2043 if (S_ISDIR(ip->i_inode.i_mode) && (ap->aflags & GFS2_AF_ORLOV)) in gfs2_inplace_reserve()
2044 skip = gfs2_orlov_skip(ip); in gfs2_inplace_reserve()
2045 if (rs->rs_rbm.rgd == NULL) in gfs2_inplace_reserve()
2046 return -EBADSLT; in gfs2_inplace_reserve()
2051 if (!gfs2_glock_is_locked_by_me(rs->rs_rbm.rgd->rd_gl)) { in gfs2_inplace_reserve()
2053 if (skip && skip--) in gfs2_inplace_reserve()
2057 !fast_to_acquire(rs->rs_rbm.rgd)) in gfs2_inplace_reserve()
2061 gfs2_rgrp_congested(rs->rs_rbm.rgd, loops)) in gfs2_inplace_reserve()
2064 error = gfs2_glock_nq_init(rs->rs_rbm.rgd->rd_gl, in gfs2_inplace_reserve()
2066 &rs->rs_rgd_gh); in gfs2_inplace_reserve()
2070 gfs2_rgrp_congested(rs->rs_rbm.rgd, loops)) in gfs2_inplace_reserve()
2072 if (sdp->sd_args.ar_rgrplvb) { in gfs2_inplace_reserve()
2073 error = update_rgrp_lvb(rs->rs_rbm.rgd); in gfs2_inplace_reserve()
2075 gfs2_glock_dq_uninit(&rs->rs_rgd_gh); in gfs2_inplace_reserve()
2082 if ((rs->rs_rbm.rgd->rd_flags & (GFS2_RGF_NOALLOC | in gfs2_inplace_reserve()
2084 (loops == 0 && ap->target > rs->rs_rbm.rgd->rd_extfail_pt)) in gfs2_inplace_reserve()
2087 if (sdp->sd_args.ar_rgrplvb) in gfs2_inplace_reserve()
2088 gfs2_rgrp_bh_get(rs->rs_rbm.rgd); in gfs2_inplace_reserve()
2092 rg_mblk_search(rs->rs_rbm.rgd, ip, ap); in gfs2_inplace_reserve()
2099 free_blocks = rgd_free(rs->rs_rbm.rgd, rs); in gfs2_inplace_reserve()
2100 if (free_blocks >= ap->target || in gfs2_inplace_reserve()
2101 (loops == 2 && ap->min_target && in gfs2_inplace_reserve()
2102 free_blocks >= ap->min_target)) { in gfs2_inplace_reserve()
2103 ap->allowed = free_blocks; in gfs2_inplace_reserve()
2108 if (rs->rs_rbm.rgd->rd_flags & GFS2_RDF_CHECK) in gfs2_inplace_reserve()
2109 try_rgrp_unlink(rs->rs_rbm.rgd, &last_unlinked, in gfs2_inplace_reserve()
2110 ip->i_no_addr); in gfs2_inplace_reserve()
2118 gfs2_glock_dq_uninit(&rs->rs_rgd_gh); in gfs2_inplace_reserve()
2121 if (gfs2_select_rgrp(&rs->rs_rbm.rgd, begin)) in gfs2_inplace_reserve()
2126 /* If we've scanned all the rgrps, but found no free blocks in gfs2_inplace_reserve()
2132 if (ip == GFS2_I(sdp->sd_rindex) && !sdp->sd_rindex_uptodate) { in gfs2_inplace_reserve()
2133 error = gfs2_ri_update(ip); in gfs2_inplace_reserve()
2143 return -ENOSPC; in gfs2_inplace_reserve()
2147 * gfs2_inplace_release - release an inplace reservation
2148 * @ip: the inode the reservation was taken out on
2153 void gfs2_inplace_release(struct gfs2_inode *ip) in gfs2_inplace_release() argument
2155 struct gfs2_blkreserv *rs = &ip->i_res; in gfs2_inplace_release()
2157 if (gfs2_holder_initialized(&rs->rs_rgd_gh)) in gfs2_inplace_release()
2158 gfs2_glock_dq_uninit(&rs->rs_rgd_gh); in gfs2_inplace_release()
2162 * gfs2_alloc_extent - allocate an extent from a given bitmap
2173 struct gfs2_rbm pos = { .rgd = rbm->rgd, }; in gfs2_alloc_extent()
2180 gfs2_trans_add_meta(rbm->rgd->rd_gl, rbm_bi(rbm)->bi_bh); in gfs2_alloc_extent()
2187 gfs2_trans_add_meta(pos.rgd->rd_gl, rbm_bi(&pos)->bi_bh); in gfs2_alloc_extent()
2195 * rgblk_free - Change alloc state of given block(s)
2197 * @bstart: the start of a run of blocks to free
2199 * @new_state: GFS2_BLKST_XXX the after-allocation block state
2218 while (blen--) { in rgblk_free()
2221 if (!bi->bi_clone) { in rgblk_free()
2222 bi->bi_clone = kmalloc(bi->bi_bh->b_size, in rgblk_free()
2224 memcpy(bi->bi_clone + bi->bi_offset, in rgblk_free()
2225 bi->bi_bh->b_data + bi->bi_offset, in rgblk_free()
2226 bi->bi_len); in rgblk_free()
2228 gfs2_trans_add_meta(rbm.rgd->rd_gl, bi->bi_bh); in rgblk_free()
2239 * gfs2_rgrp_dump - print out an rgrp
2247 struct gfs2_rgrpd *rgd = gl->gl_object; in gfs2_rgrp_dump()
2254 (unsigned long long)rgd->rd_addr, rgd->rd_flags, in gfs2_rgrp_dump()
2255 rgd->rd_free, rgd->rd_free_clone, rgd->rd_dinodes, in gfs2_rgrp_dump()
2256 rgd->rd_reserved, rgd->rd_extfail_pt); in gfs2_rgrp_dump()
2257 spin_lock(&rgd->rd_rsspin); in gfs2_rgrp_dump()
2258 for (n = rb_first(&rgd->rd_rstree); n; n = rb_next(&trs->rs_node)) { in gfs2_rgrp_dump()
2262 spin_unlock(&rgd->rd_rsspin); in gfs2_rgrp_dump()
2267 struct gfs2_sbd *sdp = rgd->rd_sbd; in gfs2_rgrp_error()
2269 (unsigned long long)rgd->rd_addr); in gfs2_rgrp_error()
2271 gfs2_rgrp_dump(NULL, rgd->rd_gl); in gfs2_rgrp_error()
2272 rgd->rd_flags |= GFS2_RDF_ERROR; in gfs2_rgrp_error()
2276 * gfs2_adjust_reservation - Adjust (or remove) a reservation after allocation
2277 * @ip: The inode we have just allocated blocks for
2278 * @rbm: The start of the allocated blocks
2286 static void gfs2_adjust_reservation(struct gfs2_inode *ip, in gfs2_adjust_reservation() argument
2289 struct gfs2_blkreserv *rs = &ip->i_res; in gfs2_adjust_reservation()
2290 struct gfs2_rgrpd *rgd = rbm->rgd; in gfs2_adjust_reservation()
2295 spin_lock(&rgd->rd_rsspin); in gfs2_adjust_reservation()
2297 if (gfs2_rbm_eq(&rs->rs_rbm, rbm)) { in gfs2_adjust_reservation()
2299 ret = gfs2_rbm_from_block(&rs->rs_rbm, block + len); in gfs2_adjust_reservation()
2300 rlen = min(rs->rs_free, len); in gfs2_adjust_reservation()
2301 rs->rs_free -= rlen; in gfs2_adjust_reservation()
2302 rgd->rd_reserved -= rlen; in gfs2_adjust_reservation()
2304 if (rs->rs_free && !ret) in gfs2_adjust_reservation()
2307 reserve more blocks next time. */ in gfs2_adjust_reservation()
2308 atomic_add(RGRP_RSRV_ADDBLKS, &rs->rs_sizehint); in gfs2_adjust_reservation()
2313 spin_unlock(&rgd->rd_rsspin); in gfs2_adjust_reservation()
2317 * gfs2_set_alloc_start - Set starting point for block allocation
2319 * @ip: The gfs2 inode
2328 const struct gfs2_inode *ip, bool dinode) in gfs2_set_alloc_start() argument
2332 if (gfs2_rs_active(&ip->i_res)) { in gfs2_set_alloc_start()
2333 *rbm = ip->i_res.rs_rbm; in gfs2_set_alloc_start()
2337 if (!dinode && rgrp_contains_block(rbm->rgd, ip->i_goal)) in gfs2_set_alloc_start()
2338 goal = ip->i_goal; in gfs2_set_alloc_start()
2340 goal = rbm->rgd->rd_last_alloc + rbm->rgd->rd_data0; in gfs2_set_alloc_start()
2346 * gfs2_alloc_blocks - Allocate one or more blocks of data and/or a dinode
2347 * @ip: the inode to allocate the block for
2349 * @nblocks: requested number of blocks/extent length (value/result)
2356 int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks, in gfs2_alloc_blocks() argument
2359 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_alloc_blocks()
2361 struct gfs2_rbm rbm = { .rgd = ip->i_res.rs_rbm.rgd, }; in gfs2_alloc_blocks()
2366 gfs2_set_alloc_start(&rbm, ip, dinode); in gfs2_alloc_blocks()
2367 error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, NULL, ip, false); in gfs2_alloc_blocks()
2369 if (error == -ENOSPC) { in gfs2_alloc_blocks()
2370 gfs2_set_alloc_start(&rbm, ip, dinode); in gfs2_alloc_blocks()
2374 /* Since all blocks are reserved in advance, this shouldn't happen */ in gfs2_alloc_blocks()
2377 (unsigned long long)ip->i_no_addr, error, *nblocks, in gfs2_alloc_blocks()
2378 test_bit(GBF_FULL, &rbm.rgd->rd_bits->bi_flags), in gfs2_alloc_blocks()
2379 rbm.rgd->rd_extfail_pt); in gfs2_alloc_blocks()
2385 rbm.rgd->rd_last_alloc = block - rbm.rgd->rd_data0; in gfs2_alloc_blocks()
2386 if (gfs2_rs_active(&ip->i_res)) in gfs2_alloc_blocks()
2387 gfs2_adjust_reservation(ip, &rbm, *nblocks); in gfs2_alloc_blocks()
2390 ndata--; in gfs2_alloc_blocks()
2393 ip->i_goal = block + ndata - 1; in gfs2_alloc_blocks()
2394 error = gfs2_meta_inode_buffer(ip, &dibh); in gfs2_alloc_blocks()
2397 (struct gfs2_dinode *)dibh->b_data; in gfs2_alloc_blocks()
2398 gfs2_trans_add_meta(ip->i_gl, dibh); in gfs2_alloc_blocks()
2399 di->di_goal_meta = di->di_goal_data = in gfs2_alloc_blocks()
2400 cpu_to_be64(ip->i_goal); in gfs2_alloc_blocks()
2404 if (rbm.rgd->rd_free < *nblocks) { in gfs2_alloc_blocks()
2409 rbm.rgd->rd_free -= *nblocks; in gfs2_alloc_blocks()
2411 rbm.rgd->rd_dinodes++; in gfs2_alloc_blocks()
2412 *generation = rbm.rgd->rd_igeneration++; in gfs2_alloc_blocks()
2414 *generation = rbm.rgd->rd_igeneration++; in gfs2_alloc_blocks()
2417 gfs2_trans_add_meta(rbm.rgd->rd_gl, rbm.rgd->rd_bits[0].bi_bh); in gfs2_alloc_blocks()
2418 gfs2_rgrp_out(rbm.rgd, rbm.rgd->rd_bits[0].bi_bh->b_data); in gfs2_alloc_blocks()
2420 gfs2_statfs_change(sdp, 0, -(s64)*nblocks, dinode ? 1 : 0); in gfs2_alloc_blocks()
2424 gfs2_quota_change(ip, *nblocks, ip->i_inode.i_uid, ip->i_inode.i_gid); in gfs2_alloc_blocks()
2426 rbm.rgd->rd_free_clone -= *nblocks; in gfs2_alloc_blocks()
2427 trace_gfs2_block_alloc(ip, rbm.rgd, block, *nblocks, in gfs2_alloc_blocks()
2434 return -EIO; in gfs2_alloc_blocks()
2438 * __gfs2_free_blocks - free a contiguous run of block(s)
2439 * @ip: the inode these blocks are being freed from
2440 * @bstart: first block of a run of contiguous blocks
2442 * @meta: 1 if the blocks represent metadata
2446 void __gfs2_free_blocks(struct gfs2_inode *ip, u64 bstart, u32 blen, int meta) in __gfs2_free_blocks() argument
2448 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in __gfs2_free_blocks()
2454 trace_gfs2_block_alloc(ip, rgd, bstart, blen, GFS2_BLKST_FREE); in __gfs2_free_blocks()
2455 rgd->rd_free += blen; in __gfs2_free_blocks()
2456 rgd->rd_flags &= ~GFS2_RGF_TRIMMED; in __gfs2_free_blocks()
2457 gfs2_trans_add_meta(rgd->rd_gl, rgd->rd_bits[0].bi_bh); in __gfs2_free_blocks()
2458 gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data); in __gfs2_free_blocks()
2461 if (meta || ip->i_depth) in __gfs2_free_blocks()
2462 gfs2_meta_wipe(ip, bstart, blen); in __gfs2_free_blocks()
2466 * gfs2_free_meta - free a contiguous run of data block(s)
2467 * @ip: the inode these blocks are being freed from
2468 * @bstart: first block of a run of contiguous blocks
2473 void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen) in gfs2_free_meta() argument
2475 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_free_meta()
2477 __gfs2_free_blocks(ip, bstart, blen, 1); in gfs2_free_meta()
2479 gfs2_quota_change(ip, -(s64)blen, ip->i_inode.i_uid, ip->i_inode.i_gid); in gfs2_free_meta()
2484 struct gfs2_inode *ip = GFS2_I(inode); in gfs2_unlink_di() local
2487 u64 blkno = ip->i_no_addr; in gfs2_unlink_di()
2492 trace_gfs2_block_alloc(ip, rgd, blkno, 1, GFS2_BLKST_UNLINKED); in gfs2_unlink_di()
2493 gfs2_trans_add_meta(rgd->rd_gl, rgd->rd_bits[0].bi_bh); in gfs2_unlink_di()
2494 gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data); in gfs2_unlink_di()
2495 be32_add_cpu(&rgd->rd_rgl->rl_unlinked, 1); in gfs2_unlink_di()
2498 void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip) in gfs2_free_di() argument
2500 struct gfs2_sbd *sdp = rgd->rd_sbd; in gfs2_free_di()
2503 tmp_rgd = rgblk_free(sdp, ip->i_no_addr, 1, GFS2_BLKST_FREE); in gfs2_free_di()
2508 if (!rgd->rd_dinodes) in gfs2_free_di()
2510 rgd->rd_dinodes--; in gfs2_free_di()
2511 rgd->rd_free++; in gfs2_free_di()
2513 gfs2_trans_add_meta(rgd->rd_gl, rgd->rd_bits[0].bi_bh); in gfs2_free_di()
2514 gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data); in gfs2_free_di()
2515 be32_add_cpu(&rgd->rd_rgl->rl_unlinked, -1); in gfs2_free_di()
2517 gfs2_statfs_change(sdp, 0, +1, -1); in gfs2_free_di()
2518 trace_gfs2_block_alloc(ip, rgd, ip->i_no_addr, 1, GFS2_BLKST_FREE); in gfs2_free_di()
2519 gfs2_quota_change(ip, -1, ip->i_inode.i_uid, ip->i_inode.i_gid); in gfs2_free_di()
2520 gfs2_meta_wipe(ip, ip->i_no_addr, 1); in gfs2_free_di()
2524 * gfs2_check_blk_type - Check the type of a block
2530 * -ESTALE if it doesn't match
2531 * or -ve errno if something went wrong while checking
2539 int error = -EINVAL; in gfs2_check_blk_type()
2545 error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_SHARED, 0, &rgd_gh); in gfs2_check_blk_type()
2554 error = -ESTALE; in gfs2_check_blk_type()
2562 * gfs2_rlist_add - add a RG to a list of RGs
2563 * @ip: the inode
2573 void gfs2_rlist_add(struct gfs2_inode *ip, struct gfs2_rgrp_list *rlist, in gfs2_rlist_add() argument
2576 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); in gfs2_rlist_add()
2582 if (gfs2_assert_warn(sdp, !rlist->rl_ghs)) in gfs2_rlist_add()
2589 if (rlist->rl_rgrps) { in gfs2_rlist_add()
2590 rgd = rlist->rl_rgd[rlist->rl_rgrps - 1]; in gfs2_rlist_add()
2595 rgd = ip->i_res.rs_rbm.rgd; in gfs2_rlist_add()
2606 for (x = 0; x < rlist->rl_rgrps; x++) { in gfs2_rlist_add()
2607 if (rlist->rl_rgd[x] == rgd) { in gfs2_rlist_add()
2608 swap(rlist->rl_rgd[x], in gfs2_rlist_add()
2609 rlist->rl_rgd[rlist->rl_rgrps - 1]); in gfs2_rlist_add()
2614 if (rlist->rl_rgrps == rlist->rl_space) { in gfs2_rlist_add()
2615 new_space = rlist->rl_space + 10; in gfs2_rlist_add()
2620 if (rlist->rl_rgd) { in gfs2_rlist_add()
2621 memcpy(tmp, rlist->rl_rgd, in gfs2_rlist_add()
2622 rlist->rl_space * sizeof(struct gfs2_rgrpd *)); in gfs2_rlist_add()
2623 kfree(rlist->rl_rgd); in gfs2_rlist_add()
2626 rlist->rl_space = new_space; in gfs2_rlist_add()
2627 rlist->rl_rgd = tmp; in gfs2_rlist_add()
2630 rlist->rl_rgd[rlist->rl_rgrps++] = rgd; in gfs2_rlist_add()
2634 * gfs2_rlist_alloc - all RGs have been added to the rlist, now allocate
2647 rlist->rl_ghs = kmalloc_array(rlist->rl_rgrps, in gfs2_rlist_alloc()
2650 for (x = 0; x < rlist->rl_rgrps; x++) in gfs2_rlist_alloc()
2651 gfs2_holder_init(rlist->rl_rgd[x]->rd_gl, in gfs2_rlist_alloc()
2653 &rlist->rl_ghs[x]); in gfs2_rlist_alloc()
2657 * gfs2_rlist_free - free a resource group list
2666 kfree(rlist->rl_rgd); in gfs2_rlist_free()
2668 if (rlist->rl_ghs) { in gfs2_rlist_free()
2669 for (x = 0; x < rlist->rl_rgrps; x++) in gfs2_rlist_free()
2670 gfs2_holder_uninit(&rlist->rl_ghs[x]); in gfs2_rlist_free()
2671 kfree(rlist->rl_ghs); in gfs2_rlist_free()
2672 rlist->rl_ghs = NULL; in gfs2_rlist_free()