hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/gfs2/rgrp.c
....@@ -1,10 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
34 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
4
- *
5
- * This copyrighted material is made available to anyone wishing to use,
6
- * modify, copy, or redistribute it subject to the terms and conditions
7
- * of the GNU General Public License version 2.
85 */
96
107 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -38,16 +35,6 @@
3835
3936 #define BFITNOENT ((u32)~0)
4037 #define NO_BLOCK ((u64)~0)
41
-
42
-#if BITS_PER_LONG == 32
43
-#define LBITMASK (0x55555555UL)
44
-#define LBITSKIP55 (0x55555555UL)
45
-#define LBITSKIP00 (0x00000000UL)
46
-#else
47
-#define LBITMASK (0x5555555555555555UL)
48
-#define LBITSKIP55 (0x5555555555555555UL)
49
-#define LBITSKIP00 (0x0000000000000000UL)
50
-#endif
5138
5239 /*
5340 * These routines are used by the resource group routines (rgrp.c)
....@@ -90,7 +77,7 @@
9077 {
9178 unsigned char *byte1, *byte2, *end, cur_state;
9279 struct gfs2_bitmap *bi = rbm_bi(rbm);
93
- unsigned int buflen = bi->bi_len;
80
+ unsigned int buflen = bi->bi_bytes;
9481 const unsigned int bit = (rbm->offset % GFS2_NBBY) * GFS2_BIT_SIZE;
9582
9683 byte1 = bi->bi_bh->b_data + bi->bi_offset + (rbm->offset / GFS2_NBBY);
....@@ -101,12 +88,16 @@
10188 cur_state = (*byte1 >> bit) & GFS2_BIT_MASK;
10289
10390 if (unlikely(!valid_change[new_state * 4 + cur_state])) {
104
- pr_warn("buf_blk = 0x%x old_state=%d, new_state=%d\n",
91
+ struct gfs2_sbd *sdp = rbm->rgd->rd_sbd;
92
+
93
+ fs_warn(sdp, "buf_blk = 0x%x old_state=%d, new_state=%d\n",
10594 rbm->offset, cur_state, new_state);
106
- pr_warn("rgrp=0x%llx bi_start=0x%x\n",
107
- (unsigned long long)rbm->rgd->rd_addr, bi->bi_start);
108
- pr_warn("bi_offset=0x%x bi_len=0x%x\n",
109
- bi->bi_offset, bi->bi_len);
95
+ fs_warn(sdp, "rgrp=0x%llx bi_start=0x%x biblk: 0x%llx\n",
96
+ (unsigned long long)rbm->rgd->rd_addr, bi->bi_start,
97
+ (unsigned long long)bi->bi_bh->b_blocknr);
98
+ fs_warn(sdp, "bi_offset=0x%x bi_bytes=0x%x block=0x%llx\n",
99
+ bi->bi_offset, bi->bi_bytes,
100
+ (unsigned long long)gfs2_rbm_to_block(rbm));
110101 dump_stack();
111102 gfs2_consist_rgrpd(rbm->rgd);
112103 return;
....@@ -269,15 +260,10 @@
269260
270261 static int gfs2_rbm_from_block(struct gfs2_rbm *rbm, u64 block)
271262 {
272
- u64 rblock = block - rbm->rgd->rd_data0;
273
-
274
- if (WARN_ON_ONCE(rblock > UINT_MAX))
275
- return -EINVAL;
276
- if (block >= rbm->rgd->rd_data0 + rbm->rgd->rd_data)
263
+ if (!rgrp_contains_block(rbm->rgd, block))
277264 return -E2BIG;
278
-
279265 rbm->bii = 0;
280
- rbm->offset = (u32)(rblock);
266
+ rbm->offset = block - rbm->rgd->rd_data0;
281267 /* Check if the block is within the first block */
282268 if (rbm->offset < rbm_bi(rbm)->bi_blocks)
283269 return 0;
....@@ -382,7 +368,7 @@
382368 if (bi->bi_clone)
383369 start = bi->bi_clone;
384370 start += bi->bi_offset;
385
- end = start + bi->bi_len;
371
+ end = start + bi->bi_bytes;
386372 BUG_ON(rbm.offset & 3);
387373 start += (rbm.offset / GFS2_NBBY);
388374 bytes = min_t(u32, len / GFS2_NBBY, (end - start));
....@@ -467,28 +453,28 @@
467453 count[x] += gfs2_bitcount(rgd,
468454 bi->bi_bh->b_data +
469455 bi->bi_offset,
470
- bi->bi_len, x);
456
+ bi->bi_bytes, x);
471457 }
472458
473459 if (count[0] != rgd->rd_free) {
474
- if (gfs2_consist_rgrpd(rgd))
475
- fs_err(sdp, "free data mismatch: %u != %u\n",
476
- count[0], rgd->rd_free);
460
+ gfs2_lm(sdp, "free data mismatch: %u != %u\n",
461
+ count[0], rgd->rd_free);
462
+ gfs2_consist_rgrpd(rgd);
477463 return;
478464 }
479465
480466 tmp = rgd->rd_data - rgd->rd_free - rgd->rd_dinodes;
481467 if (count[1] != tmp) {
482
- if (gfs2_consist_rgrpd(rgd))
483
- fs_err(sdp, "used data mismatch: %u != %u\n",
484
- count[1], tmp);
468
+ gfs2_lm(sdp, "used data mismatch: %u != %u\n",
469
+ count[1], tmp);
470
+ gfs2_consist_rgrpd(rgd);
485471 return;
486472 }
487473
488474 if (count[2] + count[3] != rgd->rd_dinodes) {
489
- if (gfs2_consist_rgrpd(rgd))
490
- fs_err(sdp, "used metadata mismatch: %u != %u\n",
491
- count[2] + count[3], rgd->rd_dinodes);
475
+ gfs2_lm(sdp, "used metadata mismatch: %u != %u\n",
476
+ count[2] + count[3], rgd->rd_dinodes);
477
+ gfs2_consist_rgrpd(rgd);
492478 return;
493479 }
494480 }
....@@ -604,21 +590,12 @@
604590 }
605591 }
606592
607
-/**
608
- * gfs2_rsqa_alloc - make sure we have a reservation assigned to the inode
609
- * plus a quota allocations data structure, if necessary
610
- * @ip: the inode for this reservation
611
- */
612
-int gfs2_rsqa_alloc(struct gfs2_inode *ip)
613
-{
614
- return gfs2_qa_alloc(ip);
615
-}
616
-
617
-static void dump_rs(struct seq_file *seq, const struct gfs2_blkreserv *rs)
593
+static void dump_rs(struct seq_file *seq, const struct gfs2_blkreserv *rs,
594
+ const char *fs_id_buf)
618595 {
619596 struct gfs2_inode *ip = container_of(rs, struct gfs2_inode, i_res);
620597
621
- gfs2_print_dbg(seq, " B: n:%llu s:%llu b:%u f:%u\n",
598
+ gfs2_print_dbg(seq, "%s B: n:%llu s:%llu b:%u f:%u\n", fs_id_buf,
622599 (unsigned long long)ip->i_no_addr,
623600 (unsigned long long)gfs2_rbm_to_block(&rs->rs_rbm),
624601 rs->rs_rbm.offset, rs->rs_free);
....@@ -685,18 +662,18 @@
685662 }
686663
687664 /**
688
- * gfs2_rsqa_delete - delete a multi-block reservation and quota allocation
665
+ * gfs2_rs_delete - delete a multi-block reservation
689666 * @ip: The inode for this reservation
690
- * @wcount: The inode's write count, or NULL
691667 *
692668 */
693
-void gfs2_rsqa_delete(struct gfs2_inode *ip, atomic_t *wcount)
669
+void gfs2_rs_delete(struct gfs2_inode *ip)
694670 {
671
+ struct inode *inode = &ip->i_inode;
672
+
695673 down_write(&ip->i_rw_mutex);
696
- if ((wcount == NULL) || (atomic_read(wcount) <= 1))
674
+ if (atomic_read(&inode->i_writecount) <= 1)
697675 gfs2_rs_deltree(&ip->i_res);
698676 up_write(&ip->i_rw_mutex);
699
- gfs2_qa_delete(ip, wcount);
700677 }
701678
702679 /**
....@@ -733,8 +710,12 @@
733710 rb_erase(n, &sdp->sd_rindex_tree);
734711
735712 if (gl) {
736
- glock_clear_object(gl, rgd);
713
+ if (gl->gl_state != LM_ST_UNLOCKED) {
714
+ gfs2_glock_cb(gl, LM_ST_UNLOCKED);
715
+ flush_delayed_work(&gl->gl_work);
716
+ }
737717 gfs2_rgrp_brelse(rgd);
718
+ glock_clear_object(gl, rgd);
738719 gfs2_glock_put(gl);
739720 }
740721
....@@ -744,15 +725,6 @@
744725 rgd->rd_bits = NULL;
745726 kmem_cache_free(gfs2_rgrpd_cachep, rgd);
746727 }
747
-}
748
-
749
-static void gfs2_rindex_print(const struct gfs2_rgrpd *rgd)
750
-{
751
- pr_info("ri_addr = %llu\n", (unsigned long long)rgd->rd_addr);
752
- pr_info("ri_length = %u\n", rgd->rd_length);
753
- pr_info("ri_data0 = %llu\n", (unsigned long long)rgd->rd_data0);
754
- pr_info("ri_data = %u\n", rgd->rd_data);
755
- pr_info("ri_bitbytes = %u\n", rgd->rd_bitbytes);
756728 }
757729
758730 /**
....@@ -790,21 +762,21 @@
790762 bytes = bytes_left;
791763 bi->bi_offset = sizeof(struct gfs2_rgrp);
792764 bi->bi_start = 0;
793
- bi->bi_len = bytes;
765
+ bi->bi_bytes = bytes;
794766 bi->bi_blocks = bytes * GFS2_NBBY;
795767 /* header block */
796768 } else if (x == 0) {
797769 bytes = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_rgrp);
798770 bi->bi_offset = sizeof(struct gfs2_rgrp);
799771 bi->bi_start = 0;
800
- bi->bi_len = bytes;
772
+ bi->bi_bytes = bytes;
801773 bi->bi_blocks = bytes * GFS2_NBBY;
802774 /* last block */
803775 } else if (x + 1 == length) {
804776 bytes = bytes_left;
805777 bi->bi_offset = sizeof(struct gfs2_meta_header);
806778 bi->bi_start = rgd->rd_bitbytes - bytes_left;
807
- bi->bi_len = bytes;
779
+ bi->bi_bytes = bytes;
808780 bi->bi_blocks = bytes * GFS2_NBBY;
809781 /* other blocks */
810782 } else {
....@@ -812,7 +784,7 @@
812784 sizeof(struct gfs2_meta_header);
813785 bi->bi_offset = sizeof(struct gfs2_meta_header);
814786 bi->bi_start = rgd->rd_bitbytes - bytes_left;
815
- bi->bi_len = bytes;
787
+ bi->bi_bytes = bytes;
816788 bi->bi_blocks = bytes * GFS2_NBBY;
817789 }
818790
....@@ -824,12 +796,21 @@
824796 return -EIO;
825797 }
826798 bi = rgd->rd_bits + (length - 1);
827
- if ((bi->bi_start + bi->bi_len) * GFS2_NBBY != rgd->rd_data) {
828
- if (gfs2_consist_rgrpd(rgd)) {
829
- gfs2_rindex_print(rgd);
830
- fs_err(sdp, "start=%u len=%u offset=%u\n",
831
- bi->bi_start, bi->bi_len, bi->bi_offset);
832
- }
799
+ if ((bi->bi_start + bi->bi_bytes) * GFS2_NBBY != rgd->rd_data) {
800
+ gfs2_lm(sdp,
801
+ "ri_addr = %llu\n"
802
+ "ri_length = %u\n"
803
+ "ri_data0 = %llu\n"
804
+ "ri_data = %u\n"
805
+ "ri_bitbytes = %u\n"
806
+ "start=%u len=%u offset=%u\n",
807
+ (unsigned long long)rgd->rd_addr,
808
+ rgd->rd_length,
809
+ (unsigned long long)rgd->rd_data0,
810
+ rgd->rd_data,
811
+ rgd->rd_bitbytes,
812
+ bi->bi_start, bi->bi_bytes, bi->bi_offset);
813
+ gfs2_consist_rgrpd(rgd);
833814 return -EIO;
834815 }
835816
....@@ -898,7 +879,6 @@
898879 static int read_rindex_entry(struct gfs2_inode *ip)
899880 {
900881 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
901
- const unsigned bsize = sdp->sd_sb.sb_bsize;
902882 loff_t pos = sdp->sd_rgrps * sizeof(struct gfs2_rindex);
903883 struct gfs2_rindex buf;
904884 int error;
....@@ -926,14 +906,14 @@
926906 rgd->rd_bitbytes = be32_to_cpu(buf.ri_bitbytes);
927907 spin_lock_init(&rgd->rd_rsspin);
928908
929
- error = compute_bitstructs(rgd);
930
- if (error)
931
- goto fail;
932
-
933909 error = gfs2_glock_get(sdp, rgd->rd_addr,
934910 &gfs2_rgrp_glops, CREATE, &rgd->rd_gl);
935911 if (error)
936912 goto fail;
913
+
914
+ error = compute_bitstructs(rgd);
915
+ if (error)
916
+ goto fail_glock;
937917
938918 rgd->rd_rgl = (struct gfs2_rgrp_lvb *)rgd->rd_gl->gl_lksb.sb_lvbptr;
939919 rgd->rd_flags &= ~(GFS2_RDF_UPTODATE | GFS2_RDF_PREFERRED);
....@@ -944,13 +924,11 @@
944924 spin_unlock(&sdp->sd_rindex_spin);
945925 if (!error) {
946926 glock_set_object(rgd->rd_gl, rgd);
947
- rgd->rd_gl->gl_vm.start = (rgd->rd_addr * bsize) & PAGE_MASK;
948
- rgd->rd_gl->gl_vm.end = PAGE_ALIGN((rgd->rd_addr +
949
- rgd->rd_length) * bsize) - 1;
950927 return 0;
951928 }
952929
953930 error = 0; /* someone else read in the rgrp; free it and ignore it */
931
+fail_glock:
954932 gfs2_glock_put(rgd->rd_gl);
955933
956934 fail:
....@@ -1117,12 +1095,36 @@
11171095 {
11181096 struct gfs2_rgrp_lvb *rgl = rgd->rd_rgl;
11191097 struct gfs2_rgrp *str = (struct gfs2_rgrp *)rgd->rd_bits[0].bi_bh->b_data;
1098
+ struct gfs2_sbd *sdp = rgd->rd_sbd;
1099
+ int valid = 1;
11201100
1121
- if (rgl->rl_flags != str->rg_flags || rgl->rl_free != str->rg_free ||
1122
- rgl->rl_dinodes != str->rg_dinodes ||
1123
- rgl->rl_igeneration != str->rg_igeneration)
1124
- return 0;
1125
- return 1;
1101
+ if (rgl->rl_flags != str->rg_flags) {
1102
+ fs_warn(sdp, "GFS2: rgd: %llu lvb flag mismatch %u/%u",
1103
+ (unsigned long long)rgd->rd_addr,
1104
+ be32_to_cpu(rgl->rl_flags), be32_to_cpu(str->rg_flags));
1105
+ valid = 0;
1106
+ }
1107
+ if (rgl->rl_free != str->rg_free) {
1108
+ fs_warn(sdp, "GFS2: rgd: %llu lvb free mismatch %u/%u",
1109
+ (unsigned long long)rgd->rd_addr,
1110
+ be32_to_cpu(rgl->rl_free), be32_to_cpu(str->rg_free));
1111
+ valid = 0;
1112
+ }
1113
+ if (rgl->rl_dinodes != str->rg_dinodes) {
1114
+ fs_warn(sdp, "GFS2: rgd: %llu lvb dinode mismatch %u/%u",
1115
+ (unsigned long long)rgd->rd_addr,
1116
+ be32_to_cpu(rgl->rl_dinodes),
1117
+ be32_to_cpu(str->rg_dinodes));
1118
+ valid = 0;
1119
+ }
1120
+ if (rgl->rl_igeneration != str->rg_igeneration) {
1121
+ fs_warn(sdp, "GFS2: rgd: %llu lvb igen mismatch %llu/%llu",
1122
+ (unsigned long long)rgd->rd_addr,
1123
+ (unsigned long long)be64_to_cpu(rgl->rl_igeneration),
1124
+ (unsigned long long)be64_to_cpu(str->rg_igeneration));
1125
+ valid = 0;
1126
+ }
1127
+ return valid;
11261128 }
11271129
11281130 static u32 count_unlinked(struct gfs2_rgrpd *rgd)
....@@ -1136,8 +1138,8 @@
11361138 goal = 0;
11371139 buffer = bi->bi_bh->b_data + bi->bi_offset;
11381140 WARN_ON(!buffer_uptodate(bi->bi_bh));
1139
- while (goal < bi->bi_len * GFS2_NBBY) {
1140
- goal = gfs2_bitfit(buffer, bi->bi_len, goal,
1141
+ while (goal < bi->bi_blocks) {
1142
+ goal = gfs2_bitfit(buffer, bi->bi_bytes, goal,
11411143 GFS2_BLKST_UNLINKED);
11421144 if (goal == BFITNOENT)
11431145 break;
....@@ -1277,23 +1279,6 @@
12771279 bi->bi_bh = NULL;
12781280 }
12791281 }
1280
-
1281
-}
1282
-
1283
-/**
1284
- * gfs2_rgrp_go_unlock - Unlock a rgrp glock
1285
- * @gh: The glock holder for the resource group
1286
- *
1287
- */
1288
-
1289
-void gfs2_rgrp_go_unlock(struct gfs2_holder *gh)
1290
-{
1291
- struct gfs2_rgrpd *rgd = gh->gh_gl->gl_object;
1292
- int demote_requested = test_bit(GLF_DEMOTE, &gh->gh_gl->gl_flags) |
1293
- test_bit(GLF_PENDING_DEMOTE, &gh->gh_gl->gl_flags);
1294
-
1295
- if (rgd && demote_requested)
1296
- gfs2_rgrp_brelse(rgd);
12971282 }
12981283
12991284 int gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 offset,
....@@ -1309,7 +1294,7 @@
13091294 u32 trimmed = 0;
13101295 u8 diff;
13111296
1312
- for (x = 0; x < bi->bi_len; x++) {
1297
+ for (x = 0; x < bi->bi_bytes; x++) {
13131298 const u8 *clone = bi->bi_clone ? bi->bi_clone : bi->bi_bh->b_data;
13141299 clone += bi->bi_offset;
13151300 clone += x;
....@@ -1406,7 +1391,8 @@
14061391
14071392 start = r.start >> bs_shift;
14081393 end = start + (r.len >> bs_shift);
1409
- minlen = max_t(u64, r.minlen,
1394
+ minlen = max_t(u64, r.minlen, sdp->sd_sb.sb_bsize);
1395
+ minlen = max_t(u64, minlen,
14101396 q->limits.discard_granularity) >> bs_shift;
14111397
14121398 if (end <= start || minlen > sdp->sd_max_rg_data)
....@@ -1558,8 +1544,8 @@
15581544 if (S_ISDIR(inode->i_mode))
15591545 extlen = 1;
15601546 else {
1561
- extlen = max_t(u32, atomic_read(&rs->rs_sizehint), ap->target);
1562
- extlen = clamp(extlen, RGRP_RSRV_MINBLKS, free_blocks);
1547
+ extlen = max_t(u32, atomic_read(&ip->i_sizehint), ap->target);
1548
+ extlen = clamp(extlen, (u32)RGRP_RSRV_MINBLKS, free_blocks);
15631549 }
15641550 if ((rgd->rd_free_clone < rgd->rd_reserved) || (free_blocks < extlen))
15651551 return;
....@@ -1712,25 +1698,22 @@
17121698 static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minext,
17131699 const struct gfs2_inode *ip, bool nowrap)
17141700 {
1701
+ bool scan_from_start = rbm->bii == 0 && rbm->offset == 0;
17151702 struct buffer_head *bh;
1716
- int initial_bii;
1717
- u32 initial_offset;
1718
- int first_bii = rbm->bii;
1719
- u32 first_offset = rbm->offset;
1703
+ int last_bii;
17201704 u32 offset;
17211705 u8 *buffer;
1722
- int n = 0;
1723
- int iters = rbm->rgd->rd_length;
1706
+ bool wrapped = false;
17241707 int ret;
17251708 struct gfs2_bitmap *bi;
17261709 struct gfs2_extent maxext = { .rbm.rgd = rbm->rgd, };
17271710
1728
- /* If we are not starting at the beginning of a bitmap, then we
1729
- * need to add one to the bitmap count to ensure that we search
1730
- * the starting bitmap twice.
1711
+ /*
1712
+ * Determine the last bitmap to search. If we're not starting at the
1713
+ * beginning of a bitmap, we need to search that bitmap twice to scan
1714
+ * the entire resource group.
17311715 */
1732
- if (rbm->offset != 0)
1733
- iters++;
1716
+ last_bii = rbm->bii - (rbm->offset == 0);
17341717
17351718 while(1) {
17361719 bi = rbm_bi(rbm);
....@@ -1744,35 +1727,29 @@
17441727 WARN_ON(!buffer_uptodate(bh));
17451728 if (state != GFS2_BLKST_UNLINKED && bi->bi_clone)
17461729 buffer = bi->bi_clone + bi->bi_offset;
1747
- initial_offset = rbm->offset;
1748
- offset = gfs2_bitfit(buffer, bi->bi_len, rbm->offset, state);
1749
- if (offset == BFITNOENT)
1750
- goto bitmap_full;
1730
+ offset = gfs2_bitfit(buffer, bi->bi_bytes, rbm->offset, state);
1731
+ if (offset == BFITNOENT) {
1732
+ if (state == GFS2_BLKST_FREE && rbm->offset == 0)
1733
+ set_bit(GBF_FULL, &bi->bi_flags);
1734
+ goto next_bitmap;
1735
+ }
17511736 rbm->offset = offset;
17521737 if (ip == NULL)
17531738 return 0;
17541739
1755
- initial_bii = rbm->bii;
17561740 ret = gfs2_reservation_check_and_update(rbm, ip,
17571741 minext ? *minext : 0,
17581742 &maxext);
17591743 if (ret == 0)
17601744 return 0;
1761
- if (ret > 0) {
1762
- n += (rbm->bii - initial_bii);
1745
+ if (ret > 0)
17631746 goto next_iter;
1764
- }
17651747 if (ret == -E2BIG) {
17661748 rbm->bii = 0;
17671749 rbm->offset = 0;
1768
- n += (rbm->bii - initial_bii);
17691750 goto res_covered_end_of_rgrp;
17701751 }
17711752 return ret;
1772
-
1773
-bitmap_full: /* Mark bitmap as full and fall through */
1774
- if ((state == GFS2_BLKST_FREE) && initial_offset == 0)
1775
- set_bit(GBF_FULL, &bi->bi_flags);
17761753
17771754 next_bitmap: /* Find next bitmap in the rgrp */
17781755 rbm->offset = 0;
....@@ -1780,11 +1757,16 @@
17801757 if (rbm->bii == rbm->rgd->rd_length)
17811758 rbm->bii = 0;
17821759 res_covered_end_of_rgrp:
1783
- if ((rbm->bii == 0) && nowrap)
1784
- break;
1785
- n++;
1760
+ if (rbm->bii == 0) {
1761
+ if (wrapped)
1762
+ break;
1763
+ wrapped = true;
1764
+ if (nowrap)
1765
+ break;
1766
+ }
17861767 next_iter:
1787
- if (n >= iters)
1768
+ /* Have we scanned the entire resource group? */
1769
+ if (wrapped && rbm->bii > last_bii)
17881770 break;
17891771 }
17901772
....@@ -1794,8 +1776,8 @@
17941776 /* If the extent was too small, and it's smaller than the smallest
17951777 to have failed before, remember for future reference that it's
17961778 useless to search this rgrp again for this amount or more. */
1797
- if ((first_offset == 0) && (first_bii == 0) &&
1798
- (*minext < rbm->rgd->rd_extfail_pt))
1779
+ if (wrapped && (scan_from_start || rbm->bii > last_bii) &&
1780
+ *minext < rbm->rgd->rd_extfail_pt)
17991781 rbm->rgd->rd_extfail_pt = *minext;
18001782
18011783 /* If the maximum extent we found is big enough to fulfill the
....@@ -1830,10 +1812,8 @@
18301812 struct gfs2_rbm rbm = { .rgd = rgd, .bii = 0, .offset = 0 };
18311813
18321814 while (1) {
1833
- down_write(&sdp->sd_log_flush_lock);
18341815 error = gfs2_rbm_find(&rbm, GFS2_BLKST_UNLINKED, NULL, NULL,
18351816 true);
1836
- up_write(&sdp->sd_log_flush_lock);
18371817 if (error == -ENOSPC)
18381818 break;
18391819 if (WARN_ON_ONCE(error))
....@@ -1861,7 +1841,7 @@
18611841 */
18621842 ip = gl->gl_object;
18631843
1864
- if (ip || queue_work(gfs2_delete_workqueue, &gl->gl_delete) == 0)
1844
+ if (ip || !gfs2_queue_delete_work(gl, 0))
18651845 gfs2_glock_put(gl);
18661846 else
18671847 found++;
....@@ -2016,7 +1996,7 @@
20161996 * We try our best to find an rgrp that has at least ap->target blocks
20171997 * available. After a couple of passes (loops == 2), the prospects of finding
20181998 * such an rgrp diminish. At this stage, we return the first rgrp that has
2019
- * atleast ap->min_target blocks available. Either way, we set ap->allowed to
1999
+ * at least ap->min_target blocks available. Either way, we set ap->allowed to
20202000 * the number of blocks available in the chosen rgrp.
20212001 *
20222002 * Returns: 0 on success,
....@@ -2070,7 +2050,7 @@
20702050 }
20712051 error = gfs2_glock_nq_init(rs->rs_rbm.rgd->rd_gl,
20722052 LM_ST_EXCLUSIVE, flags,
2073
- &rs->rs_rgd_gh);
2053
+ &ip->i_rgd_gh);
20742054 if (unlikely(error))
20752055 return error;
20762056 if (!gfs2_rs_active(rs) && (loops < 2) &&
....@@ -2079,13 +2059,13 @@
20792059 if (sdp->sd_args.ar_rgrplvb) {
20802060 error = update_rgrp_lvb(rs->rs_rbm.rgd);
20812061 if (unlikely(error)) {
2082
- gfs2_glock_dq_uninit(&rs->rs_rgd_gh);
2062
+ gfs2_glock_dq_uninit(&ip->i_rgd_gh);
20832063 return error;
20842064 }
20852065 }
20862066 }
20872067
2088
- /* Skip unuseable resource groups */
2068
+ /* Skip unusable resource groups */
20892069 if ((rs->rs_rbm.rgd->rd_flags & (GFS2_RGF_NOALLOC |
20902070 GFS2_RDF_ERROR)) ||
20912071 (loops == 0 && ap->target > rs->rs_rbm.rgd->rd_extfail_pt))
....@@ -2122,7 +2102,7 @@
21222102
21232103 /* Unlock rgrp if required */
21242104 if (!rg_locked)
2125
- gfs2_glock_dq_uninit(&rs->rs_rgd_gh);
2105
+ gfs2_glock_dq_uninit(&ip->i_rgd_gh);
21262106 next_rgrp:
21272107 /* Find the next rgrp, and continue looking */
21282108 if (gfs2_select_rgrp(&rs->rs_rbm.rgd, begin))
....@@ -2159,10 +2139,8 @@
21592139
21602140 void gfs2_inplace_release(struct gfs2_inode *ip)
21612141 {
2162
- struct gfs2_blkreserv *rs = &ip->i_res;
2163
-
2164
- if (gfs2_holder_initialized(&rs->rs_rgd_gh))
2165
- gfs2_glock_dq_uninit(&rs->rs_rgd_gh);
2142
+ if (gfs2_holder_initialized(&ip->i_rgd_gh))
2143
+ gfs2_glock_dq_uninit(&ip->i_rgd_gh);
21662144 }
21672145
21682146 /**
....@@ -2201,27 +2179,21 @@
22012179 /**
22022180 * rgblk_free - Change alloc state of given block(s)
22032181 * @sdp: the filesystem
2182
+ * @rgd: the resource group the blocks are in
22042183 * @bstart: the start of a run of blocks to free
22052184 * @blen: the length of the block run (all must lie within ONE RG!)
22062185 * @new_state: GFS2_BLKST_XXX the after-allocation block state
2207
- *
2208
- * Returns: Resource group containing the block(s)
22092186 */
22102187
2211
-static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, u64 bstart,
2212
- u32 blen, unsigned char new_state)
2188
+static void rgblk_free(struct gfs2_sbd *sdp, struct gfs2_rgrpd *rgd,
2189
+ u64 bstart, u32 blen, unsigned char new_state)
22132190 {
22142191 struct gfs2_rbm rbm;
22152192 struct gfs2_bitmap *bi, *bi_prev = NULL;
22162193
2217
- rbm.rgd = gfs2_blk2rgrpd(sdp, bstart, 1);
2218
- if (!rbm.rgd) {
2219
- if (gfs2_consist(sdp))
2220
- fs_err(sdp, "block = %llu\n", (unsigned long long)bstart);
2221
- return NULL;
2222
- }
2223
-
2224
- gfs2_rbm_from_block(&rbm, bstart);
2194
+ rbm.rgd = rgd;
2195
+ if (WARN_ON_ONCE(gfs2_rbm_from_block(&rbm, bstart)))
2196
+ return;
22252197 while (blen--) {
22262198 bi = rbm_bi(&rbm);
22272199 if (bi != bi_prev) {
....@@ -2230,7 +2202,7 @@
22302202 GFP_NOFS | __GFP_NOFAIL);
22312203 memcpy(bi->bi_clone + bi->bi_offset,
22322204 bi->bi_bh->b_data + bi->bi_offset,
2233
- bi->bi_len);
2205
+ bi->bi_bytes);
22342206 }
22352207 gfs2_trans_add_meta(rbm.rgd->rd_gl, bi->bi_bh);
22362208 bi_prev = bi;
....@@ -2238,33 +2210,39 @@
22382210 gfs2_setbit(&rbm, false, new_state);
22392211 gfs2_rbm_incr(&rbm);
22402212 }
2241
-
2242
- return rbm.rgd;
22432213 }
22442214
22452215 /**
22462216 * gfs2_rgrp_dump - print out an rgrp
22472217 * @seq: The iterator
2248
- * @gl: The glock in question
2218
+ * @rgd: The rgrp in question
2219
+ * @fs_id_buf: pointer to file system id (if requested)
22492220 *
22502221 */
22512222
2252
-void gfs2_rgrp_dump(struct seq_file *seq, const struct gfs2_glock *gl)
2223
+void gfs2_rgrp_dump(struct seq_file *seq, struct gfs2_rgrpd *rgd,
2224
+ const char *fs_id_buf)
22532225 {
2254
- struct gfs2_rgrpd *rgd = gl->gl_object;
22552226 struct gfs2_blkreserv *trs;
22562227 const struct rb_node *n;
22572228
2258
- if (rgd == NULL)
2259
- return;
2260
- gfs2_print_dbg(seq, " R: n:%llu f:%02x b:%u/%u i:%u r:%u e:%u\n",
2229
+ gfs2_print_dbg(seq, "%s R: n:%llu f:%02x b:%u/%u i:%u r:%u e:%u\n",
2230
+ fs_id_buf,
22612231 (unsigned long long)rgd->rd_addr, rgd->rd_flags,
22622232 rgd->rd_free, rgd->rd_free_clone, rgd->rd_dinodes,
22632233 rgd->rd_reserved, rgd->rd_extfail_pt);
2234
+ if (rgd->rd_sbd->sd_args.ar_rgrplvb) {
2235
+ struct gfs2_rgrp_lvb *rgl = rgd->rd_rgl;
2236
+
2237
+ gfs2_print_dbg(seq, "%s L: f:%02x b:%u i:%u\n", fs_id_buf,
2238
+ be32_to_cpu(rgl->rl_flags),
2239
+ be32_to_cpu(rgl->rl_free),
2240
+ be32_to_cpu(rgl->rl_dinodes));
2241
+ }
22642242 spin_lock(&rgd->rd_rsspin);
22652243 for (n = rb_first(&rgd->rd_rstree); n; n = rb_next(&trs->rs_node)) {
22662244 trs = rb_entry(n, struct gfs2_blkreserv, rs_node);
2267
- dump_rs(seq, trs);
2245
+ dump_rs(seq, trs, fs_id_buf);
22682246 }
22692247 spin_unlock(&rgd->rd_rsspin);
22702248 }
....@@ -2272,10 +2250,13 @@
22722250 static void gfs2_rgrp_error(struct gfs2_rgrpd *rgd)
22732251 {
22742252 struct gfs2_sbd *sdp = rgd->rd_sbd;
2253
+ char fs_id_buf[sizeof(sdp->sd_fsname) + 7];
2254
+
22752255 fs_warn(sdp, "rgrp %llu has an error, marking it readonly until umount\n",
22762256 (unsigned long long)rgd->rd_addr);
22772257 fs_warn(sdp, "umount on all nodes and run fsck.gfs2 to fix the error\n");
2278
- gfs2_rgrp_dump(NULL, rgd->rd_gl);
2258
+ sprintf(fs_id_buf, "fsid=%s: ", sdp->sd_fsname);
2259
+ gfs2_rgrp_dump(NULL, rgd, fs_id_buf);
22792260 rgd->rd_flags |= GFS2_RDF_ERROR;
22802261 }
22812262
....@@ -2312,7 +2293,7 @@
23122293 goto out;
23132294 /* We used up our block reservation, so we should
23142295 reserve more blocks next time. */
2315
- atomic_add(RGRP_RSRV_ADDBLKS, &rs->rs_sizehint);
2296
+ atomic_add(RGRP_RSRV_ADDBLKS, &ip->i_sizehint);
23162297 }
23172298 __rs_deltree(rs);
23182299 }
....@@ -2346,7 +2327,10 @@
23462327 else
23472328 goal = rbm->rgd->rd_last_alloc + rbm->rgd->rd_data0;
23482329
2349
- gfs2_rbm_from_block(rbm, goal);
2330
+ if (WARN_ON_ONCE(gfs2_rbm_from_block(rbm, goal))) {
2331
+ rbm->bii = 0;
2332
+ rbm->offset = 0;
2333
+ }
23502334 }
23512335
23522336 /**
....@@ -2409,7 +2393,7 @@
24092393 }
24102394 }
24112395 if (rbm.rgd->rd_free < *nblocks) {
2412
- pr_warn("nblocks=%u\n", *nblocks);
2396
+ fs_warn(sdp, "nblocks=%u\n", *nblocks);
24132397 goto rgrp_error;
24142398 }
24152399
....@@ -2426,7 +2410,7 @@
24262410
24272411 gfs2_statfs_change(sdp, 0, -(s64)*nblocks, dinode ? 1 : 0);
24282412 if (dinode)
2429
- gfs2_trans_add_unrevoke(sdp, block, *nblocks);
2413
+ gfs2_trans_remove_revoke(sdp, block, *nblocks);
24302414
24312415 gfs2_quota_change(ip, *nblocks, ip->i_inode.i_uid, ip->i_inode.i_gid);
24322416
....@@ -2444,20 +2428,19 @@
24442428 /**
24452429 * __gfs2_free_blocks - free a contiguous run of block(s)
24462430 * @ip: the inode these blocks are being freed from
2431
+ * @rgd: the resource group the blocks are in
24472432 * @bstart: first block of a run of contiguous blocks
24482433 * @blen: the length of the block run
24492434 * @meta: 1 if the blocks represent metadata
24502435 *
24512436 */
24522437
2453
-void __gfs2_free_blocks(struct gfs2_inode *ip, u64 bstart, u32 blen, int meta)
2438
+void __gfs2_free_blocks(struct gfs2_inode *ip, struct gfs2_rgrpd *rgd,
2439
+ u64 bstart, u32 blen, int meta)
24542440 {
24552441 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
2456
- struct gfs2_rgrpd *rgd;
24572442
2458
- rgd = rgblk_free(sdp, bstart, blen, GFS2_BLKST_FREE);
2459
- if (!rgd)
2460
- return;
2443
+ rgblk_free(sdp, rgd, bstart, blen, GFS2_BLKST_FREE);
24612444 trace_gfs2_block_alloc(ip, rgd, bstart, blen, GFS2_BLKST_FREE);
24622445 rgd->rd_free += blen;
24632446 rgd->rd_flags &= ~GFS2_RGF_TRIMMED;
....@@ -2465,23 +2448,25 @@
24652448 gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data);
24662449
24672450 /* Directories keep their data in the metadata address space */
2468
- if (meta || ip->i_depth)
2469
- gfs2_meta_wipe(ip, bstart, blen);
2451
+ if (meta || ip->i_depth || gfs2_is_jdata(ip))
2452
+ gfs2_journal_wipe(ip, bstart, blen);
24702453 }
24712454
24722455 /**
24732456 * gfs2_free_meta - free a contiguous run of data block(s)
24742457 * @ip: the inode these blocks are being freed from
2458
+ * @rgd: the resource group the blocks are in
24752459 * @bstart: first block of a run of contiguous blocks
24762460 * @blen: the length of the block run
24772461 *
24782462 */
24792463
2480
-void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen)
2464
+void gfs2_free_meta(struct gfs2_inode *ip, struct gfs2_rgrpd *rgd,
2465
+ u64 bstart, u32 blen)
24812466 {
24822467 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
24832468
2484
- __gfs2_free_blocks(ip, bstart, blen, 1);
2469
+ __gfs2_free_blocks(ip, rgd, bstart, blen, 1);
24852470 gfs2_statfs_change(sdp, 0, +blen, 0);
24862471 gfs2_quota_change(ip, -(s64)blen, ip->i_inode.i_uid, ip->i_inode.i_gid);
24872472 }
....@@ -2493,9 +2478,10 @@
24932478 struct gfs2_rgrpd *rgd;
24942479 u64 blkno = ip->i_no_addr;
24952480
2496
- rgd = rgblk_free(sdp, blkno, 1, GFS2_BLKST_UNLINKED);
2481
+ rgd = gfs2_blk2rgrpd(sdp, blkno, true);
24972482 if (!rgd)
24982483 return;
2484
+ rgblk_free(sdp, rgd, blkno, 1, GFS2_BLKST_UNLINKED);
24992485 trace_gfs2_block_alloc(ip, rgd, blkno, 1, GFS2_BLKST_UNLINKED);
25002486 gfs2_trans_add_meta(rgd->rd_gl, rgd->rd_bits[0].bi_bh);
25012487 gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data);
....@@ -2505,13 +2491,8 @@
25052491 void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip)
25062492 {
25072493 struct gfs2_sbd *sdp = rgd->rd_sbd;
2508
- struct gfs2_rgrpd *tmp_rgd;
25092494
2510
- tmp_rgd = rgblk_free(sdp, ip->i_no_addr, 1, GFS2_BLKST_FREE);
2511
- if (!tmp_rgd)
2512
- return;
2513
- gfs2_assert_withdraw(sdp, rgd == tmp_rgd);
2514
-
2495
+ rgblk_free(sdp, rgd, ip->i_no_addr, 1, GFS2_BLKST_FREE);
25152496 if (!rgd->rd_dinodes)
25162497 gfs2_consist_rgrpd(rgd);
25172498 rgd->rd_dinodes--;
....@@ -2524,7 +2505,7 @@
25242505 gfs2_statfs_change(sdp, 0, +1, -1);
25252506 trace_gfs2_block_alloc(ip, rgd, ip->i_no_addr, 1, GFS2_BLKST_FREE);
25262507 gfs2_quota_change(ip, -1, ip->i_inode.i_uid, ip->i_inode.i_gid);
2527
- gfs2_meta_wipe(ip, ip->i_no_addr, 1);
2508
+ gfs2_journal_wipe(ip, ip->i_no_addr, 1);
25282509 }
25292510
25302511 /**
....@@ -2555,12 +2536,13 @@
25552536
25562537 rbm.rgd = rgd;
25572538 error = gfs2_rbm_from_block(&rbm, no_addr);
2558
- WARN_ON_ONCE(error != 0);
2559
-
2560
- if (gfs2_testbit(&rbm, false) != type)
2561
- error = -ESTALE;
2539
+ if (!WARN_ON_ONCE(error)) {
2540
+ if (gfs2_testbit(&rbm, false) != type)
2541
+ error = -ESTALE;
2542
+ }
25622543
25632544 gfs2_glock_dq_uninit(&rgd_gh);
2545
+
25642546 fail:
25652547 return error;
25662548 }
....@@ -2641,13 +2623,12 @@
26412623 * gfs2_rlist_alloc - all RGs have been added to the rlist, now allocate
26422624 * and initialize an array of glock holders for them
26432625 * @rlist: the list of resource groups
2644
- * @state: the lock state to acquire the RG lock in
26452626 *
26462627 * FIXME: Don't use NOFAIL
26472628 *
26482629 */
26492630
2650
-void gfs2_rlist_alloc(struct gfs2_rgrp_list *rlist, unsigned int state)
2631
+void gfs2_rlist_alloc(struct gfs2_rgrp_list *rlist)
26512632 {
26522633 unsigned int x;
26532634
....@@ -2656,7 +2637,7 @@
26562637 GFP_NOFS | __GFP_NOFAIL);
26572638 for (x = 0; x < rlist->rl_rgrps; x++)
26582639 gfs2_holder_init(rlist->rl_rgd[x]->rd_gl,
2659
- state, 0,
2640
+ LM_ST_EXCLUSIVE, 0,
26602641 &rlist->rl_ghs[x]);
26612642 }
26622643