Skip to content

Commit 5b1d0ae

Browse files
author
Darrick J. Wong
committed
xfs: simplify xfs_rtbuf_get calling conventions
Now that xfs_rtalloc_args holds references to the last-read bitmap and summary blocks, we don't need to pass the buffer pointer out of xfs_rtbuf_get. Callers no longer have to xfs_trans_brelse on their own, though they are required to call xfs_rtbuf_cache_relse before the xfs_rtalloc_args goes out of scope. While we're at it, create some trivial helpers so that we don't have to remember if "0" means "bitmap" and "1" means "summary". Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent e94b53f commit 5b1d0ae

File tree

3 files changed

+71
-71
lines changed

3 files changed

+71
-71
lines changed

fs/xfs/libxfs/xfs_rtbitmap.c

Lines changed: 49 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ int
7272
xfs_rtbuf_get(
7373
struct xfs_rtalloc_args *args,
7474
xfs_fileoff_t block, /* block number in bitmap or summary */
75-
int issum, /* is summary not bitmap */
76-
struct xfs_buf **bpp) /* output: buffer for the block */
75+
int issum) /* is summary not bitmap */
7776
{
7877
struct xfs_mount *mp = args->mp;
7978
struct xfs_buf **cbpp; /* cached block buffer */
@@ -100,10 +99,9 @@ xfs_rtbuf_get(
10099
/*
101100
* If we have a cached buffer, and the block number matches, use that.
102101
*/
103-
if (*cbpp && *coffp == block) {
104-
*bpp = *cbpp;
102+
if (*cbpp && *coffp == block)
105103
return 0;
106-
}
104+
107105
/*
108106
* Otherwise we have to have to get the buffer. If there was an old
109107
* one, get rid of it first.
@@ -128,7 +126,7 @@ xfs_rtbuf_get(
128126
return error;
129127

130128
xfs_trans_buf_set_type(args->tp, bp, type);
131-
*cbpp = *bpp = bp;
129+
*cbpp = bp;
132130
*coffp = block;
133131
return 0;
134132
}
@@ -147,7 +145,6 @@ xfs_rtfind_back(
147145
struct xfs_mount *mp = args->mp;
148146
int bit; /* bit number in the word */
149147
xfs_fileoff_t block; /* bitmap block number */
150-
struct xfs_buf *bp; /* buf for the block */
151148
int error; /* error value */
152149
xfs_rtxnum_t firstbit; /* first useful bit in the word */
153150
xfs_rtxnum_t i; /* current bit number rel. to start */
@@ -162,10 +159,9 @@ xfs_rtfind_back(
162159
* Compute and read in starting bitmap block for starting block.
163160
*/
164161
block = xfs_rtx_to_rbmblock(mp, start);
165-
error = xfs_rtbuf_get(args, block, 0, &bp);
166-
if (error) {
162+
error = xfs_rtbitmap_read_buf(args, block);
163+
if (error)
167164
return error;
168-
}
169165

170166
/*
171167
* Get the first word's index & point to it.
@@ -177,7 +173,7 @@ xfs_rtfind_back(
177173
* Compute match value, based on the bit at start: if 1 (free)
178174
* then all-ones, else all-zeroes.
179175
*/
180-
incore = xfs_rtbitmap_getword(bp, word);
176+
incore = xfs_rtbitmap_getword(args->rbmbp, word);
181177
want = (incore & ((xfs_rtword_t)1 << bit)) ? -1 : 0;
182178
/*
183179
* If the starting position is not word-aligned, deal with the
@@ -212,10 +208,9 @@ xfs_rtfind_back(
212208
/*
213209
* If done with this block, get the previous one.
214210
*/
215-
error = xfs_rtbuf_get(args, --block, 0, &bp);
216-
if (error) {
211+
error = xfs_rtbitmap_read_buf(args, --block);
212+
if (error)
217213
return error;
218-
}
219214

220215
word = mp->m_blockwsize - 1;
221216
}
@@ -233,7 +228,7 @@ xfs_rtfind_back(
233228
/*
234229
* Compute difference between actual and desired value.
235230
*/
236-
incore = xfs_rtbitmap_getword(bp, word);
231+
incore = xfs_rtbitmap_getword(args->rbmbp, word);
237232
if ((wdiff = incore ^ want)) {
238233
/*
239234
* Different, mark where we are and return.
@@ -251,10 +246,9 @@ xfs_rtfind_back(
251246
/*
252247
* If done with this block, get the previous one.
253248
*/
254-
error = xfs_rtbuf_get(args, --block, 0, &bp);
255-
if (error) {
249+
error = xfs_rtbitmap_read_buf(args, --block);
250+
if (error)
256251
return error;
257-
}
258252

259253
word = mp->m_blockwsize - 1;
260254
}
@@ -273,7 +267,7 @@ xfs_rtfind_back(
273267
/*
274268
* Compute difference between actual and desired value.
275269
*/
276-
incore = xfs_rtbitmap_getword(bp, word);
270+
incore = xfs_rtbitmap_getword(args->rbmbp, word);
277271
if ((wdiff = (incore ^ want) & mask)) {
278272
/*
279273
* Different, mark where we are and return.
@@ -305,7 +299,6 @@ xfs_rtfind_forw(
305299
struct xfs_mount *mp = args->mp;
306300
int bit; /* bit number in the word */
307301
xfs_fileoff_t block; /* bitmap block number */
308-
struct xfs_buf *bp; /* buf for the block */
309302
int error;
310303
xfs_rtxnum_t i; /* current bit number rel. to start */
311304
xfs_rtxnum_t lastbit;/* last useful bit in the word */
@@ -320,10 +313,9 @@ xfs_rtfind_forw(
320313
* Compute and read in starting bitmap block for starting block.
321314
*/
322315
block = xfs_rtx_to_rbmblock(mp, start);
323-
error = xfs_rtbuf_get(args, block, 0, &bp);
324-
if (error) {
316+
error = xfs_rtbitmap_read_buf(args, block);
317+
if (error)
325318
return error;
326-
}
327319

328320
/*
329321
* Get the first word's index & point to it.
@@ -335,7 +327,7 @@ xfs_rtfind_forw(
335327
* Compute match value, based on the bit at start: if 1 (free)
336328
* then all-ones, else all-zeroes.
337329
*/
338-
incore = xfs_rtbitmap_getword(bp, word);
330+
incore = xfs_rtbitmap_getword(args->rbmbp, word);
339331
want = (incore & ((xfs_rtword_t)1 << bit)) ? -1 : 0;
340332
/*
341333
* If the starting position is not word-aligned, deal with the
@@ -369,10 +361,9 @@ xfs_rtfind_forw(
369361
/*
370362
* If done with this block, get the previous one.
371363
*/
372-
error = xfs_rtbuf_get(args, ++block, 0, &bp);
373-
if (error) {
364+
error = xfs_rtbitmap_read_buf(args, ++block);
365+
if (error)
374366
return error;
375-
}
376367

377368
word = 0;
378369
}
@@ -390,7 +381,7 @@ xfs_rtfind_forw(
390381
/*
391382
* Compute difference between actual and desired value.
392383
*/
393-
incore = xfs_rtbitmap_getword(bp, word);
384+
incore = xfs_rtbitmap_getword(args->rbmbp, word);
394385
if ((wdiff = incore ^ want)) {
395386
/*
396387
* Different, mark where we are and return.
@@ -408,10 +399,9 @@ xfs_rtfind_forw(
408399
/*
409400
* If done with this block, get the next one.
410401
*/
411-
error = xfs_rtbuf_get(args, ++block, 0, &bp);
412-
if (error) {
402+
error = xfs_rtbitmap_read_buf(args, ++block);
403+
if (error)
413404
return error;
414-
}
415405

416406
word = 0;
417407
}
@@ -428,7 +418,7 @@ xfs_rtfind_forw(
428418
/*
429419
* Compute difference between actual and desired value.
430420
*/
431-
incore = xfs_rtbitmap_getword(bp, word);
421+
incore = xfs_rtbitmap_getword(args->rbmbp, word);
432422
if ((wdiff = (incore ^ want) & mask)) {
433423
/*
434424
* Different, mark where we are and return.
@@ -479,7 +469,6 @@ xfs_rtmodify_summary_int(
479469
xfs_suminfo_t *sum) /* out: summary info for this block */
480470
{
481471
struct xfs_mount *mp = args->mp;
482-
struct xfs_buf *bp; /* buffer for the summary block */
483472
int error;
484473
xfs_fileoff_t sb; /* summary fsblock */
485474
xfs_rtsumoff_t so; /* index into the summary file */
@@ -494,7 +483,7 @@ xfs_rtmodify_summary_int(
494483
*/
495484
sb = xfs_rtsumoffs_to_block(mp, so);
496485

497-
error = xfs_rtbuf_get(args, sb, 1, &bp);
486+
error = xfs_rtsummary_read_buf(args, sb);
498487
if (error)
499488
return error;
500489

@@ -503,19 +492,20 @@ xfs_rtmodify_summary_int(
503492
*/
504493
infoword = xfs_rtsumoffs_to_infoword(mp, so);
505494
if (delta) {
506-
xfs_suminfo_t val = xfs_suminfo_add(bp, infoword, delta);
495+
xfs_suminfo_t val = xfs_suminfo_add(args->sumbp, infoword,
496+
delta);
507497

508498
if (mp->m_rsum_cache) {
509499
if (val == 0 && log == mp->m_rsum_cache[bbno])
510500
mp->m_rsum_cache[bbno]++;
511501
if (val != 0 && log < mp->m_rsum_cache[bbno])
512502
mp->m_rsum_cache[bbno] = log;
513503
}
514-
xfs_trans_log_rtsummary(args->tp, bp, infoword);
504+
xfs_trans_log_rtsummary(args->tp, args->sumbp, infoword);
515505
if (sum)
516506
*sum = val;
517507
} else if (sum) {
518-
*sum = xfs_suminfo_get(bp, infoword);
508+
*sum = xfs_suminfo_get(args->sumbp, infoword);
519509
}
520510
return 0;
521511
}
@@ -560,7 +550,6 @@ xfs_rtmodify_range(
560550
struct xfs_mount *mp = args->mp;
561551
int bit; /* bit number in the word */
562552
xfs_fileoff_t block; /* bitmap block number */
563-
struct xfs_buf *bp; /* buf for the block */
564553
int error;
565554
int i; /* current bit number rel. to start */
566555
int lastbit; /* last useful bit in word */
@@ -576,10 +565,9 @@ xfs_rtmodify_range(
576565
/*
577566
* Read the bitmap block, and point to its data.
578567
*/
579-
error = xfs_rtbuf_get(args, block, 0, &bp);
580-
if (error) {
568+
error = xfs_rtbitmap_read_buf(args, block);
569+
if (error)
581570
return error;
582-
}
583571

584572
/*
585573
* Compute the starting word's address, and starting bit.
@@ -603,12 +591,12 @@ xfs_rtmodify_range(
603591
/*
604592
* Set/clear the active bits.
605593
*/
606-
incore = xfs_rtbitmap_getword(bp, word);
594+
incore = xfs_rtbitmap_getword(args->rbmbp, word);
607595
if (val)
608596
incore |= mask;
609597
else
610598
incore &= ~mask;
611-
xfs_rtbitmap_setword(bp, word, incore);
599+
xfs_rtbitmap_setword(args->rbmbp, word, incore);
612600
i = lastbit - bit;
613601
/*
614602
* Go on to the next block if that's where the next word is
@@ -619,12 +607,11 @@ xfs_rtmodify_range(
619607
* Log the changed part of this block.
620608
* Get the next one.
621609
*/
622-
xfs_trans_log_rtbitmap(args->tp, bp, firstword,
610+
xfs_trans_log_rtbitmap(args->tp, args->rbmbp, firstword,
623611
word);
624-
error = xfs_rtbuf_get(args, ++block, 0, &bp);
625-
if (error) {
612+
error = xfs_rtbitmap_read_buf(args, ++block);
613+
if (error)
626614
return error;
627-
}
628615

629616
firstword = word = 0;
630617
}
@@ -642,7 +629,7 @@ xfs_rtmodify_range(
642629
/*
643630
* Set the word value correctly.
644631
*/
645-
xfs_rtbitmap_setword(bp, word, val);
632+
xfs_rtbitmap_setword(args->rbmbp, word, val);
646633
i += XFS_NBWORD;
647634
/*
648635
* Go on to the next block if that's where the next word is
@@ -653,9 +640,9 @@ xfs_rtmodify_range(
653640
* Log the changed part of this block.
654641
* Get the next one.
655642
*/
656-
xfs_trans_log_rtbitmap(args->tp, bp, firstword,
643+
xfs_trans_log_rtbitmap(args->tp, args->rbmbp, firstword,
657644
word);
658-
error = xfs_rtbuf_get(args, ++block, 0, &bp);
645+
error = xfs_rtbitmap_read_buf(args, ++block);
659646
if (error)
660647
return error;
661648

@@ -674,19 +661,19 @@ xfs_rtmodify_range(
674661
/*
675662
* Set/clear the active bits.
676663
*/
677-
incore = xfs_rtbitmap_getword(bp, word);
664+
incore = xfs_rtbitmap_getword(args->rbmbp, word);
678665
if (val)
679666
incore |= mask;
680667
else
681668
incore &= ~mask;
682-
xfs_rtbitmap_setword(bp, word, incore);
669+
xfs_rtbitmap_setword(args->rbmbp, word, incore);
683670
word++;
684671
}
685672
/*
686673
* Log any remaining changed bytes.
687674
*/
688675
if (word > firstword)
689-
xfs_trans_log_rtbitmap(args->tp, bp, firstword, word);
676+
xfs_trans_log_rtbitmap(args->tp, args->rbmbp, firstword, word);
690677
return 0;
691678
}
692679

@@ -779,7 +766,6 @@ xfs_rtcheck_range(
779766
struct xfs_mount *mp = args->mp;
780767
int bit; /* bit number in the word */
781768
xfs_fileoff_t block; /* bitmap block number */
782-
struct xfs_buf *bp; /* buf for the block */
783769
int error;
784770
xfs_rtxnum_t i; /* current bit number rel. to start */
785771
xfs_rtxnum_t lastbit; /* last useful bit in word */
@@ -795,10 +781,9 @@ xfs_rtcheck_range(
795781
/*
796782
* Read the bitmap block.
797783
*/
798-
error = xfs_rtbuf_get(args, block, 0, &bp);
799-
if (error) {
784+
error = xfs_rtbitmap_read_buf(args, block);
785+
if (error)
800786
return error;
801-
}
802787

803788
/*
804789
* Compute the starting word's address, and starting bit.
@@ -825,7 +810,7 @@ xfs_rtcheck_range(
825810
/*
826811
* Compute difference between actual and desired value.
827812
*/
828-
incore = xfs_rtbitmap_getword(bp, word);
813+
incore = xfs_rtbitmap_getword(args->rbmbp, word);
829814
if ((wdiff = (incore ^ val) & mask)) {
830815
/*
831816
* Different, compute first wrong bit and return.
@@ -844,10 +829,9 @@ xfs_rtcheck_range(
844829
/*
845830
* If done with this block, get the next one.
846831
*/
847-
error = xfs_rtbuf_get(args, ++block, 0, &bp);
848-
if (error) {
832+
error = xfs_rtbitmap_read_buf(args, ++block);
833+
if (error)
849834
return error;
850-
}
851835

852836
word = 0;
853837
}
@@ -865,7 +849,7 @@ xfs_rtcheck_range(
865849
/*
866850
* Compute difference between actual and desired value.
867851
*/
868-
incore = xfs_rtbitmap_getword(bp, word);
852+
incore = xfs_rtbitmap_getword(args->rbmbp, word);
869853
if ((wdiff = incore ^ val)) {
870854
/*
871855
* Different, compute first wrong bit and return.
@@ -884,10 +868,9 @@ xfs_rtcheck_range(
884868
/*
885869
* If done with this block, get the next one.
886870
*/
887-
error = xfs_rtbuf_get(args, ++block, 0, &bp);
888-
if (error) {
871+
error = xfs_rtbitmap_read_buf(args, ++block);
872+
if (error)
889873
return error;
890-
}
891874

892875
word = 0;
893876
}
@@ -904,7 +887,7 @@ xfs_rtcheck_range(
904887
/*
905888
* Compute difference between actual and desired value.
906889
*/
907-
incore = xfs_rtbitmap_getword(bp, word);
890+
incore = xfs_rtbitmap_getword(args->rbmbp, word);
908891
if ((wdiff = (incore ^ val) & mask)) {
909892
/*
910893
* Different, compute first wrong bit and return.

0 commit comments

Comments
 (0)