aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs
diff options
context:
space:
mode:
authorDave Chinner <dchinner@redhat.com>2012-04-23 01:58:51 -0400
committerBen Myers <bpm@sgi.com>2012-05-14 17:20:47 -0400
commit4e94b71b7068b4bd9c615301197e09dbf0c3b770 (patch)
treefc441ec17202a749a6b1a3d5b70ba37101b595da /fs/xfs
parentde1cbee46269a3b707eb99b37f33afdd4cfaaea4 (diff)
xfs: use blocks for counting length of buffers
Now that we pass block counts everywhere, and index buffers by block number, track the length of the buffer in units of blocks rather than bytes. Convert the code to use block counts, and those that need byte counts get converted at the time of use. Also, remove the XFS_BUF_{SET_}SIZE() macros that are just wrappers around the buffer length. They only serve to make the code shouty loud and don't actually add any real value. Signed-off-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Mark Tinguely <tinguely@sgi.com> Signed-off-by: Ben Myers <bpm@sgi.com>
Diffstat (limited to 'fs/xfs')
-rw-r--r--fs/xfs/xfs_attr.c15
-rw-r--r--fs/xfs/xfs_buf.c22
-rw-r--r--fs/xfs/xfs_buf.h4
-rw-r--r--fs/xfs/xfs_log.c5
-rw-r--r--fs/xfs/xfs_log_recover.c8
-rw-r--r--fs/xfs/xfs_trace.h14
6 files changed, 34 insertions, 34 deletions
diff --git a/fs/xfs/xfs_attr.c b/fs/xfs/xfs_attr.c
index 65d61b948ead..6e9bd7e46982 100644
--- a/fs/xfs/xfs_attr.c
+++ b/fs/xfs/xfs_attr.c
@@ -1993,8 +1993,7 @@ xfs_attr_rmtval_get(xfs_da_args_t *args)
1993 if (error) 1993 if (error)
1994 return(error); 1994 return(error);
1995 1995
1996 tmp = (valuelen < XFS_BUF_SIZE(bp)) 1996 tmp = min_t(int, valuelen, BBTOB(bp->b_length));
1997 ? valuelen : XFS_BUF_SIZE(bp);
1998 xfs_buf_iomove(bp, 0, tmp, dst, XBRW_READ); 1997 xfs_buf_iomove(bp, 0, tmp, dst, XBRW_READ);
1999 xfs_buf_relse(bp); 1998 xfs_buf_relse(bp);
2000 dst += tmp; 1999 dst += tmp;
@@ -2097,6 +2096,8 @@ xfs_attr_rmtval_set(xfs_da_args_t *args)
2097 lblkno = args->rmtblkno; 2096 lblkno = args->rmtblkno;
2098 valuelen = args->valuelen; 2097 valuelen = args->valuelen;
2099 while (valuelen > 0) { 2098 while (valuelen > 0) {
2099 int buflen;
2100
2100 /* 2101 /*
2101 * Try to remember where we decided to put the value. 2102 * Try to remember where we decided to put the value.
2102 */ 2103 */
@@ -2118,11 +2119,13 @@ xfs_attr_rmtval_set(xfs_da_args_t *args)
2118 XBF_LOCK | XBF_DONT_BLOCK); 2119 XBF_LOCK | XBF_DONT_BLOCK);
2119 if (!bp) 2120 if (!bp)
2120 return ENOMEM; 2121 return ENOMEM;
2121 tmp = (valuelen < XFS_BUF_SIZE(bp)) ? valuelen : 2122
2122 XFS_BUF_SIZE(bp); 2123 buflen = BBTOB(bp->b_length);
2124 tmp = min_t(int, valuelen, buflen);
2123 xfs_buf_iomove(bp, 0, tmp, src, XBRW_WRITE); 2125 xfs_buf_iomove(bp, 0, tmp, src, XBRW_WRITE);
2124 if (tmp < XFS_BUF_SIZE(bp)) 2126 if (tmp < buflen)
2125 xfs_buf_zero(bp, tmp, XFS_BUF_SIZE(bp) - tmp); 2127 xfs_buf_zero(bp, tmp, buflen - tmp);
2128
2126 error = xfs_bwrite(bp); /* GROT: NOTE: synchronous write */ 2129 error = xfs_bwrite(bp); /* GROT: NOTE: synchronous write */
2127 xfs_buf_relse(bp); 2130 xfs_buf_relse(bp);
2128 if (error) 2131 if (error)
diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index 854b27a8e776..382c49a42ac2 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -198,11 +198,12 @@ xfs_buf_alloc(
198 bp->b_target = target; 198 bp->b_target = target;
199 199
200 /* 200 /*
201 * Set buffer_length and count_desired to the same value initially. 201 * Set length and count_desired to the same value initially.
202 * I/O routines should use count_desired, which will be the same in 202 * I/O routines should use count_desired, which will be the same in
203 * most cases but may be reset (e.g. XFS recovery). 203 * most cases but may be reset (e.g. XFS recovery).
204 */ 204 */
205 bp->b_buffer_length = bp->b_count_desired = numblks << BBSHIFT; 205 bp->b_length = numblks;
206 bp->b_count_desired = numblks << BBSHIFT;
206 bp->b_flags = flags; 207 bp->b_flags = flags;
207 208
208 /* 209 /*
@@ -313,14 +314,14 @@ xfs_buf_allocate_memory(
313 * the memory from the heap - there's no need for the complexity of 314 * the memory from the heap - there's no need for the complexity of
314 * page arrays to keep allocation down to order 0. 315 * page arrays to keep allocation down to order 0.
315 */ 316 */
316 if (bp->b_buffer_length < PAGE_SIZE) { 317 if (bp->b_length < BTOBB(PAGE_SIZE)) {
317 bp->b_addr = kmem_alloc(bp->b_buffer_length, xb_to_km(flags)); 318 bp->b_addr = kmem_alloc(BBTOB(bp->b_length), xb_to_km(flags));
318 if (!bp->b_addr) { 319 if (!bp->b_addr) {
319 /* low memory - use alloc_page loop instead */ 320 /* low memory - use alloc_page loop instead */
320 goto use_alloc_page; 321 goto use_alloc_page;
321 } 322 }
322 323
323 if (((unsigned long)(bp->b_addr + bp->b_buffer_length - 1) & 324 if (((unsigned long)(bp->b_addr + BBTOB(bp->b_length) - 1) &
324 PAGE_MASK) != 325 PAGE_MASK) !=
325 ((unsigned long)bp->b_addr & PAGE_MASK)) { 326 ((unsigned long)bp->b_addr & PAGE_MASK)) {
326 /* b_addr spans two pages - use alloc_page instead */ 327 /* b_addr spans two pages - use alloc_page instead */
@@ -337,7 +338,7 @@ xfs_buf_allocate_memory(
337 } 338 }
338 339
339use_alloc_page: 340use_alloc_page:
340 end = BBTOB(bp->b_bn) + bp->b_buffer_length; 341 end = BBTOB(bp->b_bn + bp->b_length);
341 page_count = xfs_buf_btoc(end) - xfs_buf_btoct(BBTOB(bp->b_bn)); 342 page_count = xfs_buf_btoc(end) - xfs_buf_btoct(BBTOB(bp->b_bn));
342 error = _xfs_buf_get_pages(bp, page_count, flags); 343 error = _xfs_buf_get_pages(bp, page_count, flags);
343 if (unlikely(error)) 344 if (unlikely(error))
@@ -477,7 +478,7 @@ _xfs_buf_find(
477 * reallocating a busy extent. Skip this buffer and 478 * reallocating a busy extent. Skip this buffer and
478 * continue searching to the right for an exact match. 479 * continue searching to the right for an exact match.
479 */ 480 */
480 if (bp->b_buffer_length != numbytes) { 481 if (bp->b_length != numblks) {
481 ASSERT(bp->b_flags & XBF_STALE); 482 ASSERT(bp->b_flags & XBF_STALE);
482 rbp = &(*rbp)->rb_right; 483 rbp = &(*rbp)->rb_right;
483 continue; 484 continue;
@@ -574,7 +575,7 @@ xfs_buf_get(
574 * that we can do IO on it. 575 * that we can do IO on it.
575 */ 576 */
576 bp->b_bn = blkno; 577 bp->b_bn = blkno;
577 bp->b_count_desired = bp->b_buffer_length; 578 bp->b_count_desired = BBTOB(bp->b_length);
578 579
579found: 580found:
580 if (!(bp->b_flags & XBF_MAPPED)) { 581 if (!(bp->b_flags & XBF_MAPPED)) {
@@ -716,7 +717,8 @@ xfs_buf_set_empty(
716 bp->b_pages = NULL; 717 bp->b_pages = NULL;
717 bp->b_page_count = 0; 718 bp->b_page_count = 0;
718 bp->b_addr = NULL; 719 bp->b_addr = NULL;
719 bp->b_buffer_length = bp->b_count_desired = numblks << BBSHIFT; 720 bp->b_length = numblks;
721 bp->b_count_desired = numblks << BBSHIFT;
720 bp->b_bn = XFS_BUF_DADDR_NULL; 722 bp->b_bn = XFS_BUF_DADDR_NULL;
721 bp->b_flags &= ~XBF_MAPPED; 723 bp->b_flags &= ~XBF_MAPPED;
722} 724}
@@ -769,7 +771,7 @@ xfs_buf_associate_memory(
769 } 771 }
770 772
771 bp->b_count_desired = len; 773 bp->b_count_desired = len;
772 bp->b_buffer_length = buflen; 774 bp->b_length = BTOBB(buflen);
773 bp->b_flags |= XBF_MAPPED; 775 bp->b_flags |= XBF_MAPPED;
774 776
775 return 0; 777 return 0;
diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h
index 4d472e5ded7a..3dab208686a4 100644
--- a/fs/xfs/xfs_buf.h
+++ b/fs/xfs/xfs_buf.h
@@ -117,7 +117,7 @@ typedef struct xfs_buf {
117 */ 117 */
118 struct rb_node b_rbnode; /* rbtree node */ 118 struct rb_node b_rbnode; /* rbtree node */
119 xfs_daddr_t b_bn; /* block number for I/O */ 119 xfs_daddr_t b_bn; /* block number for I/O */
120 size_t b_buffer_length;/* size of buffer in bytes */ 120 int b_length; /* size of buffer in BBs */
121 atomic_t b_hold; /* reference count */ 121 atomic_t b_hold; /* reference count */
122 atomic_t b_lru_ref; /* lru reclaim ref count */ 122 atomic_t b_lru_ref; /* lru reclaim ref count */
123 xfs_buf_flags_t b_flags; /* status flags */ 123 xfs_buf_flags_t b_flags; /* status flags */
@@ -246,8 +246,6 @@ void xfs_buf_stale(struct xfs_buf *bp);
246#define XFS_BUF_SET_ADDR(bp, bno) ((bp)->b_bn = (xfs_daddr_t)(bno)) 246#define XFS_BUF_SET_ADDR(bp, bno) ((bp)->b_bn = (xfs_daddr_t)(bno))
247#define XFS_BUF_COUNT(bp) ((bp)->b_count_desired) 247#define XFS_BUF_COUNT(bp) ((bp)->b_count_desired)
248#define XFS_BUF_SET_COUNT(bp, cnt) ((bp)->b_count_desired = (cnt)) 248#define XFS_BUF_SET_COUNT(bp, cnt) ((bp)->b_count_desired = (cnt))
249#define XFS_BUF_SIZE(bp) ((bp)->b_buffer_length)
250#define XFS_BUF_SET_SIZE(bp, cnt) ((bp)->b_buffer_length = (cnt))
251 249
252static inline void xfs_buf_set_ref(struct xfs_buf *bp, int lru_ref) 250static inline void xfs_buf_set_ref(struct xfs_buf *bp, int lru_ref)
253{ 251{
diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c
index 89900129a4a3..f9d8355ffae2 100644
--- a/fs/xfs/xfs_log.c
+++ b/fs/xfs/xfs_log.c
@@ -1197,9 +1197,6 @@ xlog_alloc_log(xfs_mount_t *mp,
1197 spin_lock_init(&log->l_icloglock); 1197 spin_lock_init(&log->l_icloglock);
1198 init_waitqueue_head(&log->l_flush_wait); 1198 init_waitqueue_head(&log->l_flush_wait);
1199 1199
1200 /* log record size must be multiple of BBSIZE; see xlog_rec_header_t */
1201 ASSERT((XFS_BUF_SIZE(bp) & BBMASK) == 0);
1202
1203 iclogp = &log->l_iclog; 1200 iclogp = &log->l_iclog;
1204 /* 1201 /*
1205 * The amount of memory to allocate for the iclog structure is 1202 * The amount of memory to allocate for the iclog structure is
@@ -1239,7 +1236,7 @@ xlog_alloc_log(xfs_mount_t *mp,
1239 head->h_fmt = cpu_to_be32(XLOG_FMT); 1236 head->h_fmt = cpu_to_be32(XLOG_FMT);
1240 memcpy(&head->h_fs_uuid, &mp->m_sb.sb_uuid, sizeof(uuid_t)); 1237 memcpy(&head->h_fs_uuid, &mp->m_sb.sb_uuid, sizeof(uuid_t));
1241 1238
1242 iclog->ic_size = XFS_BUF_SIZE(bp) - log->l_iclog_hsize; 1239 iclog->ic_size = BBTOB(bp->b_length) - log->l_iclog_hsize;
1243 iclog->ic_state = XLOG_STATE_ACTIVE; 1240 iclog->ic_state = XLOG_STATE_ACTIVE;
1244 iclog->ic_log = log; 1241 iclog->ic_log = log;
1245 atomic_set(&iclog->ic_refcnt, 0); 1242 atomic_set(&iclog->ic_refcnt, 0);
diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c
index 8a2165c56108..24f59a25ecdd 100644
--- a/fs/xfs/xfs_log_recover.c
+++ b/fs/xfs/xfs_log_recover.c
@@ -146,7 +146,7 @@ xlog_align(
146{ 146{
147 xfs_daddr_t offset = blk_no & ((xfs_daddr_t)log->l_sectBBsize - 1); 147 xfs_daddr_t offset = blk_no & ((xfs_daddr_t)log->l_sectBBsize - 1);
148 148
149 ASSERT(BBTOB(offset + nbblks) <= XFS_BUF_SIZE(bp)); 149 ASSERT(offset + nbblks <= bp->b_length);
150 return bp->b_addr + BBTOB(offset); 150 return bp->b_addr + BBTOB(offset);
151} 151}
152 152
@@ -174,7 +174,7 @@ xlog_bread_noalign(
174 nbblks = round_up(nbblks, log->l_sectBBsize); 174 nbblks = round_up(nbblks, log->l_sectBBsize);
175 175
176 ASSERT(nbblks > 0); 176 ASSERT(nbblks > 0);
177 ASSERT(BBTOB(nbblks) <= XFS_BUF_SIZE(bp)); 177 ASSERT(nbblks <= bp->b_length);
178 178
179 XFS_BUF_SET_ADDR(bp, log->l_logBBstart + blk_no); 179 XFS_BUF_SET_ADDR(bp, log->l_logBBstart + blk_no);
180 XFS_BUF_READ(bp); 180 XFS_BUF_READ(bp);
@@ -219,7 +219,7 @@ xlog_bread_offset(
219 xfs_caddr_t offset) 219 xfs_caddr_t offset)
220{ 220{
221 xfs_caddr_t orig_offset = bp->b_addr; 221 xfs_caddr_t orig_offset = bp->b_addr;
222 int orig_len = bp->b_buffer_length; 222 int orig_len = BBTOB(bp->b_length);
223 int error, error2; 223 int error, error2;
224 224
225 error = xfs_buf_associate_memory(bp, offset, BBTOB(nbblks)); 225 error = xfs_buf_associate_memory(bp, offset, BBTOB(nbblks));
@@ -260,7 +260,7 @@ xlog_bwrite(
260 nbblks = round_up(nbblks, log->l_sectBBsize); 260 nbblks = round_up(nbblks, log->l_sectBBsize);
261 261
262 ASSERT(nbblks > 0); 262 ASSERT(nbblks > 0);
263 ASSERT(BBTOB(nbblks) <= XFS_BUF_SIZE(bp)); 263 ASSERT(nbblks <= bp->b_length);
264 264
265 XFS_BUF_SET_ADDR(bp, log->l_logBBstart + blk_no); 265 XFS_BUF_SET_ADDR(bp, log->l_logBBstart + blk_no);
266 XFS_BUF_ZEROFLAGS(bp); 266 XFS_BUF_ZEROFLAGS(bp);
diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h
index 2e41756e263a..900764c450a8 100644
--- a/fs/xfs/xfs_trace.h
+++ b/fs/xfs/xfs_trace.h
@@ -281,7 +281,7 @@ DECLARE_EVENT_CLASS(xfs_buf_class,
281 TP_STRUCT__entry( 281 TP_STRUCT__entry(
282 __field(dev_t, dev) 282 __field(dev_t, dev)
283 __field(xfs_daddr_t, bno) 283 __field(xfs_daddr_t, bno)
284 __field(size_t, buffer_length) 284 __field(int, nblks)
285 __field(int, hold) 285 __field(int, hold)
286 __field(int, pincount) 286 __field(int, pincount)
287 __field(unsigned, lockval) 287 __field(unsigned, lockval)
@@ -291,18 +291,18 @@ DECLARE_EVENT_CLASS(xfs_buf_class,
291 TP_fast_assign( 291 TP_fast_assign(
292 __entry->dev = bp->b_target->bt_dev; 292 __entry->dev = bp->b_target->bt_dev;
293 __entry->bno = bp->b_bn; 293 __entry->bno = bp->b_bn;
294 __entry->buffer_length = bp->b_buffer_length; 294 __entry->nblks = bp->b_length;
295 __entry->hold = atomic_read(&bp->b_hold); 295 __entry->hold = atomic_read(&bp->b_hold);
296 __entry->pincount = atomic_read(&bp->b_pin_count); 296 __entry->pincount = atomic_read(&bp->b_pin_count);
297 __entry->lockval = bp->b_sema.count; 297 __entry->lockval = bp->b_sema.count;
298 __entry->flags = bp->b_flags; 298 __entry->flags = bp->b_flags;
299 __entry->caller_ip = caller_ip; 299 __entry->caller_ip = caller_ip;
300 ), 300 ),
301 TP_printk("dev %d:%d bno 0x%llx len 0x%zx hold %d pincount %d " 301 TP_printk("dev %d:%d bno 0x%llx nblks 0x%x hold %d pincount %d "
302 "lock %d flags %s caller %pf", 302 "lock %d flags %s caller %pf",
303 MAJOR(__entry->dev), MINOR(__entry->dev), 303 MAJOR(__entry->dev), MINOR(__entry->dev),
304 (unsigned long long)__entry->bno, 304 (unsigned long long)__entry->bno,
305 __entry->buffer_length, 305 __entry->nblks,
306 __entry->hold, 306 __entry->hold,
307 __entry->pincount, 307 __entry->pincount,
308 __entry->lockval, 308 __entry->lockval,
@@ -362,7 +362,7 @@ DECLARE_EVENT_CLASS(xfs_buf_flags_class,
362 TP_fast_assign( 362 TP_fast_assign(
363 __entry->dev = bp->b_target->bt_dev; 363 __entry->dev = bp->b_target->bt_dev;
364 __entry->bno = bp->b_bn; 364 __entry->bno = bp->b_bn;
365 __entry->buffer_length = bp->b_buffer_length; 365 __entry->buffer_length = BBTOB(bp->b_length);
366 __entry->flags = flags; 366 __entry->flags = flags;
367 __entry->hold = atomic_read(&bp->b_hold); 367 __entry->hold = atomic_read(&bp->b_hold);
368 __entry->pincount = atomic_read(&bp->b_pin_count); 368 __entry->pincount = atomic_read(&bp->b_pin_count);
@@ -406,7 +406,7 @@ TRACE_EVENT(xfs_buf_ioerror,
406 TP_fast_assign( 406 TP_fast_assign(
407 __entry->dev = bp->b_target->bt_dev; 407 __entry->dev = bp->b_target->bt_dev;
408 __entry->bno = bp->b_bn; 408 __entry->bno = bp->b_bn;
409 __entry->buffer_length = bp->b_buffer_length; 409 __entry->buffer_length = BBTOB(bp->b_length);
410 __entry->hold = atomic_read(&bp->b_hold); 410 __entry->hold = atomic_read(&bp->b_hold);
411 __entry->pincount = atomic_read(&bp->b_pin_count); 411 __entry->pincount = atomic_read(&bp->b_pin_count);
412 __entry->lockval = bp->b_sema.count; 412 __entry->lockval = bp->b_sema.count;
@@ -450,7 +450,7 @@ DECLARE_EVENT_CLASS(xfs_buf_item_class,
450 __entry->bli_recur = bip->bli_recur; 450 __entry->bli_recur = bip->bli_recur;
451 __entry->bli_refcount = atomic_read(&bip->bli_refcount); 451 __entry->bli_refcount = atomic_read(&bip->bli_refcount);
452 __entry->buf_bno = bip->bli_buf->b_bn; 452 __entry->buf_bno = bip->bli_buf->b_bn;
453 __entry->buf_len = bip->bli_buf->b_buffer_length; 453 __entry->buf_len = BBTOB(bip->bli_buf->b_length);
454 __entry->buf_flags = bip->bli_buf->b_flags; 454 __entry->buf_flags = bip->bli_buf->b_flags;
455 __entry->buf_hold = atomic_read(&bip->bli_buf->b_hold); 455 __entry->buf_hold = atomic_read(&bip->bli_buf->b_hold);
456 __entry->buf_pincount = atomic_read(&bip->bli_buf->b_pin_count); 456 __entry->buf_pincount = atomic_read(&bip->bli_buf->b_pin_count);