Skip to content

Commit 97e9938

Browse files
author
Darrick J. Wong
committed
xfs: use accessor functions for bitmap words
Create get and set functions for rtbitmap words so that we can redefine the ondisk format with a specific endianness. Note that this requires the definition of a distinct type for ondisk rtbitmap words so that the compiler can perform proper typechecking as we go back and forth. In the upcoming rtgroups feature, we're going to fix the problem that rtwords are written in host endian order, which means we'll need the distinct rtword/rtword_raw types. Suggested-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent 312d610 commit 97e9938

File tree

4 files changed

+70
-77
lines changed

4 files changed

+70
-77
lines changed

fs/xfs/libxfs/xfs_format.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,14 @@ struct xfs_agfl {
690690
ASSERT(xfs_daddr_to_agno(mp, d) == \
691691
xfs_daddr_to_agno(mp, (d) + (len) - 1)))
692692

693+
/*
694+
* Realtime bitmap information is accessed by the word, which is currently
695+
* stored in host-endian format.
696+
*/
697+
union xfs_rtword_raw {
698+
__u32 old;
699+
};
700+
693701
/*
694702
* XFS Timestamps
695703
* ==============

fs/xfs/libxfs/xfs_rtbitmap.c

Lines changed: 34 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ xfs_rtfind_back(
9999
xfs_rtxnum_t limit, /* last rtext to look at */
100100
xfs_rtxnum_t *rtx) /* out: start rtext found */
101101
{
102-
xfs_rtword_t *b; /* current word in buffer */
103102
int bit; /* bit number in the word */
104103
xfs_fileoff_t block; /* bitmap block number */
105104
struct xfs_buf *bp; /* buf for the block */
@@ -110,6 +109,7 @@ xfs_rtfind_back(
110109
xfs_rtword_t mask; /* mask of relevant bits for value */
111110
xfs_rtword_t want; /* mask for "good" values */
112111
xfs_rtword_t wdiff; /* difference from wanted value */
112+
xfs_rtword_t incore;
113113
unsigned int word; /* word number in the buffer */
114114

115115
/*
@@ -125,14 +125,14 @@ xfs_rtfind_back(
125125
* Get the first word's index & point to it.
126126
*/
127127
word = xfs_rtx_to_rbmword(mp, start);
128-
b = xfs_rbmblock_wordptr(bp, word);
129128
bit = (int)(start & (XFS_NBWORD - 1));
130129
len = start - limit + 1;
131130
/*
132131
* Compute match value, based on the bit at start: if 1 (free)
133132
* then all-ones, else all-zeroes.
134133
*/
135-
want = (*b & ((xfs_rtword_t)1 << bit)) ? -1 : 0;
134+
incore = xfs_rtbitmap_getword(bp, word);
135+
want = (incore & ((xfs_rtword_t)1 << bit)) ? -1 : 0;
136136
/*
137137
* If the starting position is not word-aligned, deal with the
138138
* partial word.
@@ -149,7 +149,7 @@ xfs_rtfind_back(
149149
* Calculate the difference between the value there
150150
* and what we're looking for.
151151
*/
152-
if ((wdiff = (*b ^ want) & mask)) {
152+
if ((wdiff = (incore ^ want) & mask)) {
153153
/*
154154
* Different. Mark where we are and return.
155155
*/
@@ -174,12 +174,6 @@ xfs_rtfind_back(
174174
}
175175

176176
word = mp->m_blockwsize - 1;
177-
b = xfs_rbmblock_wordptr(bp, word);
178-
} else {
179-
/*
180-
* Go on to the previous word in the buffer.
181-
*/
182-
b--;
183177
}
184178
} else {
185179
/*
@@ -195,7 +189,8 @@ xfs_rtfind_back(
195189
/*
196190
* Compute difference between actual and desired value.
197191
*/
198-
if ((wdiff = *b ^ want)) {
192+
incore = xfs_rtbitmap_getword(bp, word);
193+
if ((wdiff = incore ^ want)) {
199194
/*
200195
* Different, mark where we are and return.
201196
*/
@@ -220,12 +215,6 @@ xfs_rtfind_back(
220215
}
221216

222217
word = mp->m_blockwsize - 1;
223-
b = xfs_rbmblock_wordptr(bp, word);
224-
} else {
225-
/*
226-
* Go on to the previous word in the buffer.
227-
*/
228-
b--;
229218
}
230219
}
231220
/*
@@ -242,7 +231,8 @@ xfs_rtfind_back(
242231
/*
243232
* Compute difference between actual and desired value.
244233
*/
245-
if ((wdiff = (*b ^ want) & mask)) {
234+
incore = xfs_rtbitmap_getword(bp, word);
235+
if ((wdiff = (incore ^ want) & mask)) {
246236
/*
247237
* Different, mark where we are and return.
248238
*/
@@ -273,7 +263,6 @@ xfs_rtfind_forw(
273263
xfs_rtxnum_t limit, /* last rtext to look at */
274264
xfs_rtxnum_t *rtx) /* out: start rtext found */
275265
{
276-
xfs_rtword_t *b; /* current word in buffer */
277266
int bit; /* bit number in the word */
278267
xfs_fileoff_t block; /* bitmap block number */
279268
struct xfs_buf *bp; /* buf for the block */
@@ -284,6 +273,7 @@ xfs_rtfind_forw(
284273
xfs_rtword_t mask; /* mask of relevant bits for value */
285274
xfs_rtword_t want; /* mask for "good" values */
286275
xfs_rtword_t wdiff; /* difference from wanted value */
276+
xfs_rtword_t incore;
287277
unsigned int word; /* word number in the buffer */
288278

289279
/*
@@ -299,14 +289,14 @@ xfs_rtfind_forw(
299289
* Get the first word's index & point to it.
300290
*/
301291
word = xfs_rtx_to_rbmword(mp, start);
302-
b = xfs_rbmblock_wordptr(bp, word);
303292
bit = (int)(start & (XFS_NBWORD - 1));
304293
len = limit - start + 1;
305294
/*
306295
* Compute match value, based on the bit at start: if 1 (free)
307296
* then all-ones, else all-zeroes.
308297
*/
309-
want = (*b & ((xfs_rtword_t)1 << bit)) ? -1 : 0;
298+
incore = xfs_rtbitmap_getword(bp, word);
299+
want = (incore & ((xfs_rtword_t)1 << bit)) ? -1 : 0;
310300
/*
311301
* If the starting position is not word-aligned, deal with the
312302
* partial word.
@@ -322,7 +312,7 @@ xfs_rtfind_forw(
322312
* Calculate the difference between the value there
323313
* and what we're looking for.
324314
*/
325-
if ((wdiff = (*b ^ want) & mask)) {
315+
if ((wdiff = (incore ^ want) & mask)) {
326316
/*
327317
* Different. Mark where we are and return.
328318
*/
@@ -347,12 +337,6 @@ xfs_rtfind_forw(
347337
}
348338

349339
word = 0;
350-
b = xfs_rbmblock_wordptr(bp, word);
351-
} else {
352-
/*
353-
* Go on to the previous word in the buffer.
354-
*/
355-
b++;
356340
}
357341
} else {
358342
/*
@@ -368,7 +352,8 @@ xfs_rtfind_forw(
368352
/*
369353
* Compute difference between actual and desired value.
370354
*/
371-
if ((wdiff = *b ^ want)) {
355+
incore = xfs_rtbitmap_getword(bp, word);
356+
if ((wdiff = incore ^ want)) {
372357
/*
373358
* Different, mark where we are and return.
374359
*/
@@ -393,12 +378,6 @@ xfs_rtfind_forw(
393378
}
394379

395380
word = 0;
396-
b = xfs_rbmblock_wordptr(bp, word);
397-
} else {
398-
/*
399-
* Go on to the next word in the buffer.
400-
*/
401-
b++;
402381
}
403382
}
404383
/*
@@ -413,7 +392,8 @@ xfs_rtfind_forw(
413392
/*
414393
* Compute difference between actual and desired value.
415394
*/
416-
if ((wdiff = (*b ^ want) & mask)) {
395+
incore = xfs_rtbitmap_getword(bp, word);
396+
if ((wdiff = (incore ^ want) & mask)) {
417397
/*
418398
* Different, mark where we are and return.
419399
*/
@@ -568,15 +548,14 @@ xfs_rtmodify_range(
568548
xfs_rtxlen_t len, /* length of extent to modify */
569549
int val) /* 1 for free, 0 for allocated */
570550
{
571-
xfs_rtword_t *b; /* current word in buffer */
572551
int bit; /* bit number in the word */
573552
xfs_fileoff_t block; /* bitmap block number */
574553
struct xfs_buf *bp; /* buf for the block */
575554
int error; /* error value */
576-
xfs_rtword_t *first; /* first used word in the buffer */
577555
int i; /* current bit number rel. to start */
578556
int lastbit; /* last useful bit in word */
579557
xfs_rtword_t mask; /* mask o frelevant bits for value */
558+
xfs_rtword_t incore;
580559
unsigned int firstword; /* first word used in the buffer */
581560
unsigned int word; /* word number in the buffer */
582561

@@ -596,7 +575,6 @@ xfs_rtmodify_range(
596575
* Compute the starting word's address, and starting bit.
597576
*/
598577
firstword = word = xfs_rtx_to_rbmword(mp, start);
599-
first = b = xfs_rbmblock_wordptr(bp, word);
600578
bit = (int)(start & (XFS_NBWORD - 1));
601579
/*
602580
* 0 (allocated) => all zeroes; 1 (free) => all ones.
@@ -615,10 +593,12 @@ xfs_rtmodify_range(
615593
/*
616594
* Set/clear the active bits.
617595
*/
596+
incore = xfs_rtbitmap_getword(bp, word);
618597
if (val)
619-
*b |= mask;
598+
incore |= mask;
620599
else
621-
*b &= ~mask;
600+
incore &= ~mask;
601+
xfs_rtbitmap_setword(bp, word, incore);
622602
i = lastbit - bit;
623603
/*
624604
* Go on to the next block if that's where the next word is
@@ -636,12 +616,6 @@ xfs_rtmodify_range(
636616
}
637617

638618
firstword = word = 0;
639-
first = b = xfs_rbmblock_wordptr(bp, word);
640-
} else {
641-
/*
642-
* Go on to the next word in the buffer
643-
*/
644-
b++;
645619
}
646620
} else {
647621
/*
@@ -657,7 +631,7 @@ xfs_rtmodify_range(
657631
/*
658632
* Set the word value correctly.
659633
*/
660-
*b = val;
634+
xfs_rtbitmap_setword(bp, word, val);
661635
i += XFS_NBWORD;
662636
/*
663637
* Go on to the next block if that's where the next word is
@@ -675,12 +649,6 @@ xfs_rtmodify_range(
675649
}
676650

677651
firstword = word = 0;
678-
first = b = xfs_rbmblock_wordptr(bp, word);
679-
} else {
680-
/*
681-
* Go on to the next word in the buffer
682-
*/
683-
b++;
684652
}
685653
}
686654
/*
@@ -695,17 +663,18 @@ xfs_rtmodify_range(
695663
/*
696664
* Set/clear the active bits.
697665
*/
666+
incore = xfs_rtbitmap_getword(bp, word);
698667
if (val)
699-
*b |= mask;
668+
incore |= mask;
700669
else
701-
*b &= ~mask;
670+
incore &= ~mask;
671+
xfs_rtbitmap_setword(bp, word, incore);
702672
word++;
703-
b++;
704673
}
705674
/*
706675
* Log any remaining changed bytes.
707676
*/
708-
if (b > first)
677+
if (word > firstword)
709678
xfs_trans_log_rtbitmap(tp, bp, firstword, word);
710679
return 0;
711680
}
@@ -800,7 +769,6 @@ xfs_rtcheck_range(
800769
xfs_rtxnum_t *new, /* out: first rtext not matching */
801770
int *stat) /* out: 1 for matches, 0 for not */
802771
{
803-
xfs_rtword_t *b; /* current word in buffer */
804772
int bit; /* bit number in the word */
805773
xfs_fileoff_t block; /* bitmap block number */
806774
struct xfs_buf *bp; /* buf for the block */
@@ -809,6 +777,7 @@ xfs_rtcheck_range(
809777
xfs_rtxnum_t lastbit; /* last useful bit in word */
810778
xfs_rtword_t mask; /* mask of relevant bits for value */
811779
xfs_rtword_t wdiff; /* difference from wanted value */
780+
xfs_rtword_t incore;
812781
unsigned int word; /* word number in the buffer */
813782

814783
/*
@@ -827,7 +796,6 @@ xfs_rtcheck_range(
827796
* Compute the starting word's address, and starting bit.
828797
*/
829798
word = xfs_rtx_to_rbmword(mp, start);
830-
b = xfs_rbmblock_wordptr(bp, word);
831799
bit = (int)(start & (XFS_NBWORD - 1));
832800
/*
833801
* 0 (allocated) => all zero's; 1 (free) => all one's.
@@ -849,7 +817,8 @@ xfs_rtcheck_range(
849817
/*
850818
* Compute difference between actual and desired value.
851819
*/
852-
if ((wdiff = (*b ^ val) & mask)) {
820+
incore = xfs_rtbitmap_getword(bp, word);
821+
if ((wdiff = (incore ^ val) & mask)) {
853822
/*
854823
* Different, compute first wrong bit and return.
855824
*/
@@ -875,12 +844,6 @@ xfs_rtcheck_range(
875844
}
876845

877846
word = 0;
878-
b = xfs_rbmblock_wordptr(bp, word);
879-
} else {
880-
/*
881-
* Go on to the next word in the buffer.
882-
*/
883-
b++;
884847
}
885848
} else {
886849
/*
@@ -896,7 +859,8 @@ xfs_rtcheck_range(
896859
/*
897860
* Compute difference between actual and desired value.
898861
*/
899-
if ((wdiff = *b ^ val)) {
862+
incore = xfs_rtbitmap_getword(bp, word);
863+
if ((wdiff = incore ^ val)) {
900864
/*
901865
* Different, compute first wrong bit and return.
902866
*/
@@ -922,12 +886,6 @@ xfs_rtcheck_range(
922886
}
923887

924888
word = 0;
925-
b = xfs_rbmblock_wordptr(bp, word);
926-
} else {
927-
/*
928-
* Go on to the next word in the buffer.
929-
*/
930-
b++;
931889
}
932890
}
933891
/*
@@ -942,7 +900,8 @@ xfs_rtcheck_range(
942900
/*
943901
* Compute difference between actual and desired value.
944902
*/
945-
if ((wdiff = (*b ^ val) & mask)) {
903+
incore = xfs_rtbitmap_getword(bp, word);
904+
if ((wdiff = (incore ^ val) & mask)) {
946905
/*
947906
* Different, compute first wrong bit and return.
948907
*/

0 commit comments

Comments
 (0)