Skip to content

Commit de1cbee

Browse files
Dave ChinnerBen Myers
authored andcommitted
xfs: kill b_file_offset
Seeing as we pass block numbers around everywhere in the buffer cache now, it makes no sense to index everything by byte offset. Replace all the byte offset indexing with block number based indexing, and replace all uses of the byte offset with direct conversion from the block index. Signed-off-by: Dave Chinner <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Mark Tinguely <[email protected]> Signed-off-by: Ben Myers <[email protected]>
1 parent e70b73f commit de1cbee

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

fs/xfs/xfs_buf.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ xfs_buf_alloc(
196196
sema_init(&bp->b_sema, 0); /* held, no waiters */
197197
XB_SET_OWNER(bp);
198198
bp->b_target = target;
199-
bp->b_file_offset = blkno << BBSHIFT;
199+
200200
/*
201201
* Set buffer_length and count_desired to the same value initially.
202202
* I/O routines should use count_desired, which will be the same in
@@ -337,8 +337,8 @@ xfs_buf_allocate_memory(
337337
}
338338

339339
use_alloc_page:
340-
end = bp->b_file_offset + bp->b_buffer_length;
341-
page_count = xfs_buf_btoc(end) - xfs_buf_btoct(bp->b_file_offset);
340+
end = BBTOB(bp->b_bn) + bp->b_buffer_length;
341+
page_count = xfs_buf_btoc(end) - xfs_buf_btoct(BBTOB(bp->b_bn));
342342
error = _xfs_buf_get_pages(bp, page_count, flags);
343343
if (unlikely(error))
344344
return error;
@@ -439,19 +439,17 @@ _xfs_buf_find(
439439
xfs_buf_flags_t flags,
440440
xfs_buf_t *new_bp)
441441
{
442-
xfs_off_t offset;
443442
size_t numbytes;
444443
struct xfs_perag *pag;
445444
struct rb_node **rbp;
446445
struct rb_node *parent;
447446
xfs_buf_t *bp;
448447

449-
offset = BBTOB(blkno);
450448
numbytes = BBTOB(numblks);
451449

452450
/* Check for IOs smaller than the sector size / not sector aligned */
453451
ASSERT(!(numbytes < (1 << btp->bt_sshift)));
454-
ASSERT(!(offset & (xfs_off_t)btp->bt_smask));
452+
ASSERT(!(BBTOB(blkno) & (xfs_off_t)btp->bt_smask));
455453

456454
/* get tree root */
457455
pag = xfs_perag_get(btp->bt_mount,
@@ -466,13 +464,13 @@ _xfs_buf_find(
466464
parent = *rbp;
467465
bp = rb_entry(parent, struct xfs_buf, b_rbnode);
468466

469-
if (offset < bp->b_file_offset)
467+
if (blkno < bp->b_bn)
470468
rbp = &(*rbp)->rb_left;
471-
else if (offset > bp->b_file_offset)
469+
else if (blkno > bp->b_bn)
472470
rbp = &(*rbp)->rb_right;
473471
else {
474472
/*
475-
* found a block offset match. If the range doesn't
473+
* found a block number match. If the range doesn't
476474
* match, the only way this is allowed is if the buffer
477475
* in the cache is stale and the transaction that made
478476
* it stale has not yet committed. i.e. we are
@@ -718,7 +716,6 @@ xfs_buf_set_empty(
718716
bp->b_pages = NULL;
719717
bp->b_page_count = 0;
720718
bp->b_addr = NULL;
721-
bp->b_file_offset = 0;
722719
bp->b_buffer_length = bp->b_count_desired = numblks << BBSHIFT;
723720
bp->b_bn = XFS_BUF_DADDR_NULL;
724721
bp->b_flags &= ~XBF_MAPPED;

fs/xfs/xfs_buf.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ typedef struct xfs_buf {
116116
* fast-path on locking.
117117
*/
118118
struct rb_node b_rbnode; /* rbtree node */
119-
xfs_off_t b_file_offset; /* offset in file */
119+
xfs_daddr_t b_bn; /* block number for I/O */
120120
size_t b_buffer_length;/* size of buffer in bytes */
121121
atomic_t b_hold; /* reference count */
122122
atomic_t b_lru_ref; /* lru reclaim ref count */
@@ -128,7 +128,6 @@ typedef struct xfs_buf {
128128
struct list_head b_list;
129129
struct xfs_perag *b_pag; /* contains rbtree root */
130130
xfs_buftarg_t *b_target; /* buffer target (device) */
131-
xfs_daddr_t b_bn; /* block number for I/O */
132131
size_t b_count_desired;/* desired transfer size */
133132
void *b_addr; /* virtual address of buffer */
134133
struct work_struct b_iodone_work;
@@ -245,8 +244,6 @@ void xfs_buf_stale(struct xfs_buf *bp);
245244

246245
#define XFS_BUF_ADDR(bp) ((bp)->b_bn)
247246
#define XFS_BUF_SET_ADDR(bp, bno) ((bp)->b_bn = (xfs_daddr_t)(bno))
248-
#define XFS_BUF_OFFSET(bp) ((bp)->b_file_offset)
249-
#define XFS_BUF_SET_OFFSET(bp, off) ((bp)->b_file_offset = (off))
250247
#define XFS_BUF_COUNT(bp) ((bp)->b_count_desired)
251248
#define XFS_BUF_SET_COUNT(bp, cnt) ((bp)->b_count_desired = (cnt))
252249
#define XFS_BUF_SIZE(bp) ((bp)->b_buffer_length)

0 commit comments

Comments
 (0)