xfs: clean up unit usage in xfs_buf
PATCH 3/4 xfs: use blocks for counting length of buffers
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
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 onyl serve to make the code shouty loud and don't actually add any real value.
--- fs/xfs/xfs_attr.c | 12 ++++++------ fs/xfs/xfs_buf.c | 22 ++++++++++++---------- fs/xfs/xfs_buf.h | 4 +--- fs/xfs/xfs_log.c | 5 +---- fs/xfs/xfs_log_recover.c | 8 ++++---- fs/xfs/xfs_trace.h | 8 ++++---- 6 files changed, 28 insertions(+), 31 deletions(-)
fs/xfs/xfs_attr.c +6 -6
@@ -1993,8 +1993,8 @@ xfs_attr_rmtval_get(xfs_da_args_t *args)if (error)return (error); - tmp = (valuelen <XFS_BUF_SIZE (bp)) - ? valuelen :XFS_BUF_SIZE (bp); + tmp = (valuelen <BBTOB (bp->b_length)) + ? valuelen :BBTOB (bp->b_length);xfs_buf_iomove (bp,0 , tmp, dst,XBRW_READ );xfs_buf_relse (bp); dst += tmp;
@@ -2118,11 +2118,11 @@ xfs_attr_rmtval_set(xfs_da_args_t *args) XBF_LOCK | XBF_DONT_BLOCK);if (!bp)return ENOMEM ; - tmp = (valuelen <XFS_BUF_SIZE (bp)) ? valuelen : -XFS_BUF_SIZE (bp); + tmp = valuelen <BBTOB (bp->b_length) ? valuelen : +BBTOB (bp->b_length);xfs_buf_iomove (bp,0 , tmp, src,XBRW_WRITE ); -if (tmp <XFS_BUF_SIZE (bp)) -xfs_buf_zero (bp, tmp,XFS_BUF_SIZE (bp) - tmp); +if (tmp <BBTOB (bp->b_length)) +xfs_buf_zero (bp, tmp,BBTOB (bp->b_length) - tmp); error =xfs_bwrite (bp);/* GROT: NOTE: synchronous write */ xfs_buf_relse (bp);if (error)
fs/xfs/xfs_buf.c +12 -10
@@ -193,11 +193,12 @@ xfs_buf_alloc( bp->b_target = target;/* -* Set buffer_length and count_desired to the same value initially. +* Set length and count_desired to the same value initially. * I/O routines should use count_desired, which will be the same in * most cases but may be reset (e.g. XFS recovery). */ - bp->b_buffer_length = bp->b_count_desired = numblks <<BBSHIFT ; + bp->b_length = numblks; + bp->b_count_desired = numblks <<BBSHIFT ; bp->b_flags = flags;/*
@@ -309,14 +310,14 @@ xfs_buf_allocate_memory(* the memory from the heap - there's no need for the complexity of * page arrays to keep allocation down to order 0. */ -if (bp->b_buffer_length <PAGE_SIZE ) { - bp->b_addr =kmem_alloc (bp->b_buffer_length,xb_to_km (flags)); +if (bp->b_length <BTOBB (PAGE_SIZE )) { + bp->b_addr =kmem_alloc (BBTOB (bp->b_length),xb_to_km (flags));if (!bp->b_addr) {/* low memory - use alloc_page loop instead */ goto use_alloc_page; } -if (((unsigned long )(bp->b_addr + bp->b_buffer_length -1 ) & +if (((unsigned long )(bp->b_addr +BBTOB (bp->b_length) -1 ) &PAGE_MASK ) != ((unsigned long )bp->b_addr &PAGE_MASK )) {/* b_addr spans two pages - use alloc_page instead */
@@ -333,7 +334,7 @@ xfs_buf_allocate_memory( } use_alloc_page: - end =BBTOB (bp->b_bn) + bp->b_buffer_length; + end =BBTOB (bp->b_bn + bp->b_length); page_count =xfs_buf_btoc (end) -xfs_buf_btoct (BBTOB (bp->b_bn)); error =_xfs_buf_get_pages (bp, page_count, flags);if (unlikely (error))
@@ -474,7 +475,7 @@ lookup_again:* reallocating a busy extent. Skip this buffer and * continue searching to the right for an exact match. */ -if (bp->b_buffer_length != numbytes) { +if (bp->b_length != numblks) {ASSERT (bp->b_flags &XBF_STALE ); rbp = &(*rbp)->rb_right;continue ;
@@ -599,7 +600,7 @@ xfs_buf_get(* that we can do IO on it. */ bp->b_bn = blkno; - bp->b_count_desired = bp->b_buffer_length; + bp->b_count_desired =BBTOB (bp->b_length); found:if (!(bp->b_flags &XBF_MAPPED )) {
@@ -743,7 +744,8 @@ xfs_buf_set_empty( bp->b_pages =NULL ; bp->b_page_count =0 ; bp->b_addr =NULL ; - bp->b_buffer_length = bp->b_count_desired = numblks <<BBSHIFT ; + bp->b_length = numblks; + bp->b_count_desired = numblks <<BBSHIFT ; bp->b_bn =XFS_BUF_DADDR_NULL ; bp->b_flags &= ~XBF_MAPPED ; }
@@ -796,7 +798,7 @@ xfs_buf_associate_memory( } bp->b_count_desired = len; - bp->b_buffer_length = buflen; + bp->b_length =BTOBB (buflen); bp->b_flags |=XBF_MAPPED ;return 0 ;
fs/xfs/xfs_buf.h +1 -3
@@ -120,7 +120,7 @@ typedef struct xfs_buf {*/ struct rb_node b_rbnode;/* rbtree node */ xfs_daddr_t b_bn;/* block number for I/O */ -size_t b_buffer_length;/* size of buffer in bytes */ +size_t b_length;/* size of buffer in BBs */ atomic_t b_hold;/* reference count */ atomic_t b_lru_ref;/* lru reclaim ref count */ xfs_buf_flags_t b_flags;/* status flags */
@@ -249,8 +249,6 @@ void xfs_buf_stale(struct xfs_buf *bp);#define XFS_BUF_SET_ADDR (bp, bno) ((bp)->b_bn = (xfs_daddr_t)(bno))#define XFS_BUF_COUNT (bp) ((bp)->b_count_desired)#define XFS_BUF_SET_COUNT (bp, cnt) ((bp)->b_count_desired = (cnt)) -#define XFS_BUF_SIZE (bp) ((bp)->b_buffer_length) -#define XFS_BUF_SET_SIZE (bp, cnt) ((bp)->b_buffer_length = (cnt))static inline void xfs_buf_set_ref (struct xfs_buf *bp,int lru_ref) {
fs/xfs/xfs_log.c +1 -4
@@ -1197,9 +1197,6 @@ xlog_alloc_log(xfs_mount_t *mp,spin_lock_init (&log->l_icloglock);init_waitqueue_head (&log->l_flush_wait); -/* log record size must be multiple of BBSIZE; see xlog_rec_header_t */ -ASSERT ((XFS_BUF_SIZE (bp) &BBMASK ) ==0 ); - iclogp = &log->l_iclog;/* * The amount of memory to allocate for the iclog structure is
@@ -1239,7 +1236,7 @@ xlog_alloc_log(xfs_mount_t *mp, head->h_fmt =cpu_to_be32 (XLOG_FMT );memcpy (&head->h_fs_uuid, &mp->m_sb.sb_uuid,sizeof (uuid_t)); - iclog->ic_size =XFS_BUF_SIZE (bp) - log->l_iclog_hsize; + iclog->ic_size =BBTOB (bp->b_length) - log->l_iclog_hsize; iclog->ic_state =XLOG_STATE_ACTIVE ; iclog->ic_log = log;atomic_set (&iclog->ic_refcnt,0 );
fs/xfs/xfs_log_recover.c +4 -4
@@ -146,7 +146,7 @@ xlog_align( {xfs_daddr_t offset = blk_no & ((xfs_daddr_t )log->l_sectBBsize -1 ); -ASSERT (BBTOB (offset + nbblks) <=XFS_BUF_SIZE (bp)); +ASSERT (offset + nbblks <= bp->b_length);return bp->b_addr +BBTOB (offset); }
@@ -174,7 +174,7 @@ xlog_bread_noalign( nbblks =round_up (nbblks, log->l_sectBBsize);ASSERT (nbblks >0 ); -ASSERT (BBTOB (nbblks) <=XFS_BUF_SIZE (bp)); +ASSERT (nbblks <= bp->b_length);XFS_BUF_SET_ADDR (bp, log->l_logBBstart + blk_no);XFS_BUF_READ (bp);
@@ -218,7 +218,7 @@ xlog_bread_offset( xfs_caddr_t offset) {xfs_caddr_t orig_offset = bp->b_addr; -int orig_len = bp->b_buffer_length; +int orig_len =BBTOB (bp->b_length);int error, error2; error =xfs_buf_associate_memory (bp, offset,BBTOB (nbblks));
@@ -259,7 +259,7 @@ xlog_bwrite( nbblks =round_up (nbblks, log->l_sectBBsize);ASSERT (nbblks >0 ); -ASSERT (BBTOB (nbblks) <=XFS_BUF_SIZE (bp)); +ASSERT (nbblks <= bp->b_length);XFS_BUF_SET_ADDR (bp, log->l_logBBstart + blk_no);XFS_BUF_ZEROFLAGS (bp);
fs/xfs/xfs_trace.h +4 -4
@@ -291,7 +291,7 @@ DECLARE_EVENT_CLASS(xfs_buf_class,TP_fast_assign ( __entry->dev = bp->b_target->bt_dev; __entry->bno = bp->b_bn; - __entry->buffer_length = bp->b_buffer_length; + __entry->buffer_length =BBTOB (bp->b_length); __entry->hold =atomic_read (&bp->b_hold); __entry->pincount =atomic_read (&bp->b_pin_count); __entry->lockval = bp->b_sema.count;
@@ -362,7 +362,7 @@ DECLARE_EVENT_CLASS(xfs_buf_flags_class,TP_fast_assign ( __entry->dev = bp->b_target->bt_dev; __entry->bno = bp->b_bn; - __entry->buffer_length = bp->b_buffer_length; + __entry->buffer_length =BBTOB (bp->b_length); __entry->flags = flags; __entry->hold =atomic_read (&bp->b_hold); __entry->pincount =atomic_read (&bp->b_pin_count);
@@ -408,7 +408,7 @@ TRACE_EVENT(xfs_buf_ioerror,TP_fast_assign ( __entry->dev = bp->b_target->bt_dev; __entry->bno = bp->b_bn; - __entry->buffer_length = bp->b_buffer_length; + __entry->buffer_length =BBTOB (bp->b_length); __entry->hold =atomic_read (&bp->b_hold); __entry->pincount =atomic_read (&bp->b_pin_count); __entry->lockval = bp->b_sema.count;
@@ -452,7 +452,7 @@ DECLARE_EVENT_CLASS(xfs_buf_item_class, __entry->bli_recur = bip->bli_recur; __entry->bli_refcount =atomic_read (&bip->bli_refcount); __entry->buf_bno = bip->bli_buf->b_bn; - __entry->buf_len = bip->bli_buf->b_buffer_length; + __entry->buf_len =BBTOB (bip->bli_buf->b_length); __entry->buf_flags = bip->bli_buf->b_flags; __entry->buf_hold =atomic_read (&bip->bli_buf->b_hold); __entry->buf_pincount =atomic_read (&bip->bli_buf->b_pin_count);
Signature · 6 lines
1.7.9 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
cover xfs: clean up unit usage in xfs_buf
This is an update an repost of the start of a series I posted back in December. It has been rebased on top of Christoph's ilock hold reduction and xfsbufd removal patch series, as well as all the outstanding patches I've sent out recently, so I guarantee it won't apply to a dev tree cleanly.
Basically this series cleans up the buffer cache API to use daddr formats for block numbers and basic blocks for lengths when trying to get or read a buffer and from there cleans up the internal usage of the same thing. Essentially we end up with tracking buffers by their daddr blkno, and BB based length, including the length of the IO needed to do out of the buffer. The b_offset field is still in bytes, as that is mostly used as a byte offset into the allocated memory that the buffer holds, rather than a disk based offset.
Ther's nothing controversial here (at least, not from the raction to the first posting). It lays the groundwork for introducing compound buffers, and those are needed to be able to remove the intermediate xfs_dabuf that the directory code uses for discontiguous large directory blocks. This will then allow all metadata types to use the the buffer cache to trigger CRC calculations on immediately after read (validation) and prior to write (calculation).
The compound buffer patches will follow soon - i'm trying to break this up into bite-sized chunks so that reviewers have a chance to keep up with the rate can test them and I post them...
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH 1/4 xfs: clean up buffer get/read call API
From: Dave Chinner <[email protected]>
The xfs_buf_get/read API is not consistent in the units it uses, and does not use appropriate or consistent units/types for the variables.
Convert the API to use disk addresses and block counts for all buffer get and read calls. Use consistent naming for all the functions and their declarations, and convert the internal functions to use disk addresses and block counts to avoid need to convert them from one type to another and back again.
Fix all the callers to use disk addresses and block counts. In many cases, this removes an additional conversion from the function call as the callers already have a block count.
--- fs/xfs/xfs_buf.c | 86 ++++++++++++++++++++++++--------------------- fs/xfs/xfs_buf.h | 38 +++++++++++--------- fs/xfs/xfs_fsops.c | 4 +- fs/xfs/xfs_log.c | 6 ++-- fs/xfs/xfs_log_recover.c | 2 +- fs/xfs/xfs_mount.c | 12 +++--- fs/xfs/xfs_rtalloc.c | 8 ++-- fs/xfs/xfs_vnodeops.c | 2 +- 8 files changed, 84 insertions(+), 74 deletions(-)
fs/xfs/xfs_buf.c +46 -40
@@ -166,8 +166,8 @@ xfs_buf_stale(struct xfs_buf *xfs_buf_alloc (struct xfs_buftarg *target, -xfs_off_t range_base, -size_t range_length, +xfs_daddr_t blkno, +size_t numblks,xfs_buf_flags_t flags) {struct xfs_buf *bp;
@@ -191,14 +191,21 @@ xfs_buf_alloc(sema_init (&bp->b_sema,0 );/* held, no waiters */ XB_SET_OWNER (bp); bp->b_target = target; - bp->b_file_offset = range_base; + bp->b_file_offset = blkno <<BBSHIFT ;/* * Set buffer_length and count_desired to the same value initially. * I/O routines should use count_desired, which will be the same in * most cases but may be reset (e.g. XFS recovery). */ - bp->b_buffer_length = bp->b_count_desired = range_length; + bp->b_buffer_length = bp->b_count_desired = numblks <<BBSHIFT ; bp->b_flags = flags; + +/* +* We do not set the block number here in the buffer because we have not +* finished initialising the buffer. We insert the buffer into the cache +* in this state, so this ensures that we are unable to do IO on a +* buffer that hasn't been fully initialised. +*/ bp->b_bn =XFS_BUF_DADDR_NULL ;atomic_set (&bp->b_pin_count,0 );init_waitqueue_head (&bp->b_waiters);
@@ -422,30 +429,30 @@ _xfs_buf_map_pages(*/ xfs_buf_t *_xfs_buf_find ( -xfs_buftarg_t *btp,/* block device target */ -xfs_off_t ioff,/* starting offset of range */ -size_t isize,/* length of range */ +struct xfs_buftarg *btp, +xfs_daddr_t blkno, +size_t numblks,xfs_buf_flags_t flags,xfs_buf_t *new_bp) { -xfs_off_t range_base; -size_t range_length; +xfs_off_t offset; +size_t numbytes;struct xfs_perag *pag;struct rb_node **rbp;struct rb_node *parent;xfs_buf_t *bp; - range_base = (ioff <<BBSHIFT ); - range_length = (isize <<BBSHIFT ); + offset = blkno <<BBSHIFT ; + numbytes = numblks <<BBSHIFT ;/* Check for IOs smaller than the sector size / not sector aligned */ -ASSERT (!(range_length < (1 << btp->bt_sshift))); -ASSERT (!(range_base & (xfs_off_t )btp->bt_smask)); +ASSERT (!(numbytes < (1 << btp->bt_sshift))); +ASSERT (!(offset & (xfs_off_t )btp->bt_smask));/* get tree root */ lookup_again: pag =xfs_perag_get (btp->bt_mount, -xfs_daddr_to_agno (btp->bt_mount, ioff)); +xfs_daddr_to_agno (btp->bt_mount, blkno));/* walk tree */ spin_lock (&pag->pag_buf_lock);
@@ -456,9 +463,9 @@ lookup_again: parent = *rbp; bp = rb_entry(parent, struct xfs_buf, b_rbnode); -if (range_base < bp->b_file_offset) +if (offset < bp->b_file_offset) rbp = &(*rbp)->rb_left; -else if (range_base > bp->b_file_offset) +else if (offset > bp->b_file_offset) rbp = &(*rbp)->rb_right;else {/*
@@ -469,7 +476,7 @@ lookup_again:* reallocating a busy extent. Skip this buffer and * continue searching to the right for an exact match. */ -if (bp->b_buffer_length != range_length) { +if (bp->b_buffer_length != numbytes) {ASSERT (bp->b_flags &XBF_STALE ); rbp = &(*rbp)->rb_right;continue ;
@@ -547,25 +554,24 @@ found:*/ struct xfs_buf *xfs_buf_get ( -xfs_buftarg_t *target,/* target for buffer */ -xfs_off_t ioff,/* starting offset of range */ -size_t isize,/* length of range */ +xfs_buftarg_t *target, +xfs_daddr_t blkno, +size_t numblks,xfs_buf_flags_t flags) {struct xfs_buf *bp;struct xfs_buf *new_bp;int error =0 ; - bp =_xfs_buf_find (target, ioff, isize, flags,NULL ); + bp =_xfs_buf_find (target, blkno, numblks, flags,NULL );if (likely (bp)) goto found; - new_bp =xfs_buf_alloc (target, ioff <<BBSHIFT , isize <<BBSHIFT , - flags); + new_bp =xfs_buf_alloc (target, blkno, numblks, flags);if (unlikely (!new_bp))return NULL ; - bp =_xfs_buf_find (target, ioff, isize, flags, new_bp); + bp =_xfs_buf_find (target, blkno, numblks, flags, new_bp);if (!bp) {kmem_zone_free (xfs_buf_zone, new_bp);return NULL ;
@@ -594,7 +600,7 @@ xfs_buf_get(* Now we have a workable buffer, fill in the block number so * that we can do IO on it. */ - bp->b_bn = ioff; + bp->b_bn = blkno; bp->b_count_desired = bp->b_buffer_length; found:
@@ -640,15 +646,15 @@ _xfs_buf_read(xfs_buf_t *xfs_buf_read (xfs_buftarg_t *target, -xfs_off_t ioff, -size_t isize, +xfs_daddr_t blkno, +size_t numblks,xfs_buf_flags_t flags) {xfs_buf_t *bp; flags |=XBF_READ ; - bp =xfs_buf_get (target, ioff, isize, flags); + bp =xfs_buf_get (target, blkno, numblks, flags);if (bp) {trace_xfs_buf_read (bp, flags, _RET_IP_);
@@ -683,13 +689,13 @@ xfs_buf_read(void xfs_buf_readahead (xfs_buftarg_t *target, -xfs_off_t ioff, -size_t isize) +xfs_daddr_t blkno, +size_t numblks) {if (bdi_read_congested (target->bt_bdi))return ; -xfs_buf_read (target, ioff, isize, +xfs_buf_read (target, blkno, numblks,XBF_TRYLOCK |XBF_ASYNC |XBF_READ_AHEAD |XBF_DONT_BLOCK ); }
@@ -699,16 +705,15 @@ xfs_buf_readahead(*/ struct xfs_buf *xfs_buf_read_uncached ( -struct xfs_mount *mp,struct xfs_buftarg *target,xfs_daddr_t daddr, -size_t length, +size_t numblks,int flags) {xfs_buf_t *bp;int error; - bp =xfs_buf_get_uncached (target, length, flags); + bp =xfs_buf_get_uncached (target, numblks, flags);if (!bp)return NULL ;
@@ -716,7 +721,7 @@ xfs_buf_read_uncached(XFS_BUF_SET_ADDR (bp, daddr);XFS_BUF_READ (bp); -xfsbdstrat (mp, bp); +xfsbdstrat (target->bt_mount, bp); error =xfs_buf_iowait (bp);if (error || bp->b_error) {xfs_buf_relse (bp);
@@ -732,7 +737,7 @@ xfs_buf_read_uncached(void xfs_buf_set_empty (struct xfs_buf *bp, -size_t len) +size_t numblks) {if (bp->b_pages)_xfs_buf_free_pages (bp);
@@ -741,7 +746,7 @@ xfs_buf_set_empty( bp->b_page_count =0 ; bp->b_addr =NULL ; bp->b_file_offset =0 ; - bp->b_buffer_length = bp->b_count_desired = len; + bp->b_buffer_length = bp->b_count_desired = numblks <<BBSHIFT ; bp->b_bn =XFS_BUF_DADDR_NULL ; bp->b_flags &= ~XBF_MAPPED ; }
@@ -803,17 +808,18 @@ xfs_buf_associate_memory(xfs_buf_t *xfs_buf_get_uncached (struct xfs_buftarg *target, -size_t len, +size_t numblks,int flags) { -unsigned long page_count =PAGE_ALIGN (len) >>PAGE_SHIFT ; +unsigned long page_count;int error, i;xfs_buf_t *bp; - bp =xfs_buf_alloc (target,0 , len,0 ); + bp =xfs_buf_alloc (target,0 , numblks,0 );if (unlikely (bp ==NULL )) goto fail; + page_count =PAGE_ALIGN (numblks <<BBSHIFT ) >>PAGE_SHIFT ; error =_xfs_buf_get_pages (bp, page_count,0 );if (error) goto fail_free_buf;
fs/xfs/xfs_buf.h +21 -17
@@ -153,26 +153,30 @@ typedef struct xfs_buf {/* Finding and Reading Buffers */ -extern xfs_buf_t *_xfs_buf_find (xfs_buftarg_t *,xfs_off_t ,size_t , -xfs_buf_flags_t ,xfs_buf_t *); +struct xfs_buf *_xfs_buf_find (struct xfs_buftarg *target,xfs_daddr_t blkno, +size_t numblks,xfs_buf_flags_t flags, +struct xfs_buf *new_bp);#define xfs_incore (buftarg,blkno,len,lockit) \ _xfs_buf_find(buftarg, blkno ,len, lockit, NULL) -extern xfs_buf_t *xfs_buf_get (xfs_buftarg_t *,xfs_off_t ,size_t , -xfs_buf_flags_t ); -extern xfs_buf_t *xfs_buf_read (xfs_buftarg_t *,xfs_off_t ,size_t , -xfs_buf_flags_t ); - -struct xfs_buf *xfs_buf_alloc (struct xfs_buftarg *,xfs_off_t ,size_t , -xfs_buf_flags_t ); -extern void xfs_buf_set_empty (struct xfs_buf *bp,size_t len); -extern xfs_buf_t *xfs_buf_get_uncached (struct xfs_buftarg *,size_t ,int ); -extern int xfs_buf_associate_memory (xfs_buf_t *,void *,size_t ); -extern void xfs_buf_hold (xfs_buf_t *); -extern void xfs_buf_readahead (xfs_buftarg_t *,xfs_off_t ,size_t ); -struct xfs_buf *xfs_buf_read_uncached (struct xfs_mount *mp, -struct xfs_buftarg *target, -xfs_daddr_t daddr,size_t length,int flags); +struct xfs_buf *xfs_buf_get (struct xfs_buftarg *target,xfs_daddr_t blkno, +size_t numblks,xfs_buf_flags_t flags); +struct xfs_buf *xfs_buf_read (struct xfs_buftarg *target,xfs_daddr_t blkno, +size_t numblks,xfs_buf_flags_t flags); +void xfs_buf_readahead (struct xfs_buftarg *target,xfs_daddr_t blkno, +size_t numblks); + +struct xfs_buf *xfs_buf_get_empty (struct xfs_buftarg *target,size_t numblks); +struct xfs_buf *xfs_buf_alloc (struct xfs_buftarg *target,xfs_daddr_t blkno, +size_t numblks,xfs_buf_flags_t flags); +void xfs_buf_set_empty (struct xfs_buf *bp,size_t numblks); +int xfs_buf_associate_memory (struct xfs_buf *bp,void *mem,size_t length); + +struct xfs_buf *xfs_buf_get_uncached (struct xfs_buftarg *target,size_t numblks, +int flags); +struct xfs_buf *xfs_buf_read_uncached (struct xfs_buftarg *target, +xfs_daddr_t daddr,size_t numblks,int flags); +void xfs_buf_hold (struct xfs_buf *bp);/* Releasing Buffers */ extern void xfs_buf_free (xfs_buf_t *);
fs/xfs/xfs_fsops.c +2 -2
@@ -147,9 +147,9 @@ xfs_growfs_data_private(if ((error =xfs_sb_validate_fsb_count (&mp->m_sb, nb)))return error; dpct = pct - mp->m_sb.sb_imax_pct; - bp =xfs_buf_read_uncached (mp, mp->m_ddev_targp, + bp =xfs_buf_read_uncached (mp->m_ddev_targp,XFS_FSB_TO_BB (mp, nb) -XFS_FSS_TO_BB (mp,1 ), -BBTOB (XFS_FSS_TO_BB (mp,1 )),0 ); +XFS_FSS_TO_BB (mp,1 ),0 );if (!bp)return EIO ;xfs_buf_relse (bp);
fs/xfs/xfs_log.c +3 -3
@@ -1187,7 +1187,7 @@ xlog_alloc_log(xfs_mount_t *mp,xlog_get_iclog_buffer_size (mp, log); error =ENOMEM ; - bp =xfs_buf_alloc (mp->m_logdev_targp,0 , log->l_iclog_size,0 ); + bp =xfs_buf_alloc (mp->m_logdev_targp,0 ,BTOBB (log->l_iclog_size),0 );if (!bp) goto out_free_log; bp->b_iodone = xlog_iodone;
@@ -1219,7 +1219,7 @@ xlog_alloc_log(xfs_mount_t *mp, prev_iclog = iclog; bp =xfs_buf_get_uncached (mp->m_logdev_targp, - log->l_iclog_size,0 ); +BTOBB (log->l_iclog_size),0 );if (!bp) goto out_free_iclog;
@@ -1588,7 +1588,7 @@ xlog_dealloc_log(xlog_t *log)* always need to ensure that the extra buffer does not point to memory * owned by another log buffer before we free it. */ -xfs_buf_set_empty (log->l_xbuf, log->l_iclog_size); +xfs_buf_set_empty (log->l_xbuf,BTOBB (log->l_iclog_size));xfs_buf_free (log->l_xbuf); iclog = log->l_iclog;
fs/xfs/xfs_log_recover.c +1 -1
@@ -120,7 +120,7 @@ xlog_get_bp( nbblks += log->l_sectBBsize; nbblks =round_up (nbblks, log->l_sectBBsize); - bp =xfs_buf_get_uncached (log->l_mp->m_logdev_targp,BBTOB (nbblks),0 ); + bp =xfs_buf_get_uncached (log->l_mp->m_logdev_targp, nbblks,0 );if (bp)xfs_buf_unlock (bp);return bp;
fs/xfs/xfs_mount.c +6 -6
@@ -684,8 +684,8 @@ xfs_readsb(xfs_mount_t *mp, int flags) sector_size =xfs_getsize_buftarg (mp->m_ddev_targp); reread: - bp =xfs_buf_read_uncached (mp, mp->m_ddev_targp, -XFS_SB_DADDR , sector_size,0 ); + bp =xfs_buf_read_uncached (mp->m_ddev_targp,XFS_SB_DADDR , +BTOBB (sector_size),0 );if (!bp) {if (loud)xfs_warn (mp,"SB buffer read failed" );
@@ -1033,9 +1033,9 @@ xfs_check_sizes(xfs_mount_t *mp)xfs_warn (mp,"filesystem size mismatch detected" );return XFS_ERROR (EFBIG ); } - bp =xfs_buf_read_uncached (mp, mp->m_ddev_targp, + bp =xfs_buf_read_uncached (mp->m_ddev_targp, d -XFS_FSS_TO_BB (mp,1 ), -BBTOB (XFS_FSS_TO_BB (mp,1 )),0 ); +XFS_FSS_TO_BB (mp,1 ),0 );if (!bp) {xfs_warn (mp,"last sector read failed" );return EIO ;
@@ -1048,9 +1048,9 @@ xfs_check_sizes(xfs_mount_t *mp)xfs_warn (mp,"log size mismatch detected" );return XFS_ERROR (EFBIG ); } - bp =xfs_buf_read_uncached (mp, mp->m_logdev_targp, + bp =xfs_buf_read_uncached (mp->m_logdev_targp, d -XFS_FSB_TO_BB (mp,1 ), -XFS_FSB_TO_B (mp,1 ),0 ); +XFS_FSB_TO_BB (mp,1 ),0 );if (!bp) {xfs_warn (mp,"log device read failed" );return EIO ;
fs/xfs/xfs_rtalloc.c +4 -4
@@ -1872,9 +1872,9 @@ xfs_growfs_rt(/* * Read in the last block of the device, make sure it exists. */ - bp =xfs_buf_read_uncached (mp, mp->m_rtdev_targp, + bp =xfs_buf_read_uncached (mp->m_rtdev_targp,XFS_FSB_TO_BB (mp, nrblocks -1 ), -XFS_FSB_TO_B (mp,1 ),0 ); +XFS_FSB_TO_BB (mp,1 ),0 );if (!bp)return EIO ;xfs_buf_relse (bp);
@@ -2219,9 +2219,9 @@ xfs_rtmount_init( (unsigned long long) mp->m_sb.sb_rblocks);return XFS_ERROR (EFBIG ); } - bp =xfs_buf_read_uncached (mp, mp->m_rtdev_targp, + bp =xfs_buf_read_uncached (mp->m_rtdev_targp, d -XFS_FSB_TO_BB (mp,1 ), -XFS_FSB_TO_B (mp,1 ),0 ); +XFS_FSB_TO_BB (mp,1 ),0 );if (!bp) {xfs_warn (mp,"realtime device size check failed" );return EIO ;
fs/xfs/xfs_vnodeops.c +1 -1
@@ -1966,7 +1966,7 @@ xfs_zero_remaining_bytes( bp =xfs_buf_get_uncached (XFS_IS_REALTIME_INODE (ip) ? mp->m_rtdev_targp : mp->m_ddev_targp, - mp->m_sb.sb_blocksize,XBF_DONT_BLOCK ); +BTOBB (mp->m_sb.sb_blocksize),XBF_DONT_BLOCK );if (!bp)return XFS_ERROR (ENOMEM );
Signature · 6 lines
1.7.9 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 2/4 xfs: kill b_file_offset
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
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.
--- fs/xfs/xfs_buf.c | 19 ++++++++----------- fs/xfs/xfs_buf.h | 5 +---- 2 files changed, 9 insertions(+), 15 deletions(-)
fs/xfs/xfs_buf.c +8 -11
@@ -191,7 +191,7 @@ xfs_buf_alloc(sema_init (&bp->b_sema,0 );/* held, no waiters */ XB_SET_OWNER (bp); bp->b_target = target; - bp->b_file_offset = blkno <<BBSHIFT ; +/* * Set buffer_length and count_desired to the same value initially. * I/O routines should use count_desired, which will be the same in
@@ -228,7 +228,7 @@ _xfs_buf_get_pages( {/* Make sure that we have a page list */ if (bp->b_pages ==NULL ) { - bp->b_offset =xfs_buf_poff (bp->b_file_offset); + bp->b_offset =xfs_buf_poff (BBTOB (bp->b_bn)); bp->b_page_count = page_count;if (page_count <=XB_PAGES ) { bp->b_pages = bp->b_page_array;
@@ -333,8 +333,8 @@ xfs_buf_allocate_memory( } use_alloc_page: - end = bp->b_file_offset + bp->b_buffer_length; - page_count =xfs_buf_btoc (end) -xfs_buf_btoct (bp->b_file_offset); + end =BBTOB (bp->b_bn) + bp->b_buffer_length; + page_count =xfs_buf_btoc (end) -xfs_buf_btoct (BBTOB (bp->b_bn)); error =_xfs_buf_get_pages (bp, page_count, flags);if (unlikely (error))return error;
@@ -435,19 +435,17 @@ _xfs_buf_find(xfs_buf_flags_t flags, xfs_buf_t *new_bp) { - xfs_off_t offset; size_t numbytes;struct xfs_perag *pag;struct rb_node **rbp;struct rb_node *parent;xfs_buf_t *bp; - offset = blkno <<BBSHIFT ; numbytes = numblks <<BBSHIFT ;/* Check for IOs smaller than the sector size / not sector aligned */ ASSERT (!(numbytes < (1 << btp->bt_sshift))); -ASSERT (!(offset & (xfs_off_t )btp->bt_smask)); +ASSERT (!(BBTOB (blkno) & (xfs_off_t )btp->bt_smask));/* get tree root */ lookup_again:
@@ -463,13 +461,13 @@ lookup_again: parent = *rbp; bp = rb_entry(parent, struct xfs_buf, b_rbnode); -if (offset < bp->b_file_offset) +if (blkno < bp->b_bn) rbp = &(*rbp)->rb_left; -else if (offset > bp->b_file_offset) +else if (blkno > bp->b_bn) rbp = &(*rbp)->rb_right;else {/* -* found a block offset match. If the range doesn't +* found a block number match. If the range doesn't * match, the only way this is allowed is if the buffer * in the cache is stale and the transaction that made * it stale has not yet committed. i.e. we are
@@ -745,7 +743,6 @@ xfs_buf_set_empty( bp->b_pages =NULL ; bp->b_page_count =0 ; bp->b_addr =NULL ; - bp->b_file_offset =0 ; bp->b_buffer_length = bp->b_count_desired = numblks <<BBSHIFT ; bp->b_bn =XFS_BUF_DADDR_NULL ; bp->b_flags &= ~XBF_MAPPED ;
fs/xfs/xfs_buf.h +1 -4
@@ -119,7 +119,7 @@ typedef struct xfs_buf {* fast-path on locking. */ struct rb_node b_rbnode;/* rbtree node */ -xfs_off_t b_file_offset;/* offset in file */ +xfs_daddr_t b_bn;/* block number for I/O */ size_t b_buffer_length;/* size of buffer in bytes */ atomic_t b_hold;/* reference count */ atomic_t b_lru_ref;/* lru reclaim ref count */
@@ -131,7 +131,6 @@ typedef struct xfs_buf {struct list_head b_list;struct xfs_perag *b_pag;/* contains rbtree root */ xfs_buftarg_t *b_target;/* buffer target (device) */ -xfs_daddr_t b_bn;/* block number for I/O */ size_t b_count_desired;/* desired transfer size */ void *b_addr;/* virtual address of buffer */ struct work_struct b_iodone_work;
@@ -248,8 +247,6 @@ void xfs_buf_stale(struct xfs_buf *bp);#define XFS_BUF_ADDR (bp) ((bp)->b_bn)#define XFS_BUF_SET_ADDR (bp, bno) ((bp)->b_bn = (xfs_daddr_t)(bno)) -#define XFS_BUF_OFFSET (bp) ((bp)->b_file_offset) -#define XFS_BUF_SET_OFFSET (bp, off) ((bp)->b_file_offset = (off))#define XFS_BUF_COUNT (bp) ((bp)->b_count_desired)#define XFS_BUF_SET_COUNT (bp, cnt) ((bp)->b_count_desired = (cnt))#define XFS_BUF_SIZE (bp) ((bp)->b_buffer_length)
Signature · 6 lines
1.7.9 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 4/4 xfs: use blocks for storing the desired IO size
In reply to Dave ChinnerNow that we pass block counts everywhere, and index buffers by block number and length in units of blocks, convert the desired IO size into block counts rather than bytes. Convert the code to use block counts, and those that need byte counts get converted at the time of use.
Rename the b_desired_count variable to something closer to it's purpose - b_io_length - as it is only used to specify the length of an IO for a subset of the buffer. The only time this is used is for log IO - both writing iclogs and during log recovery. In all other cases, the b_io_length matches b_length, and hence a lot of code confuses the two. e.g. the buf item code uses the io count exclusively when it should be using the buffer length. Fix these apprpriately as they are found.
Also, remove the XFS_BUF_{SET_}COUNT() macros that are just wrappers around the desired IO length. They only serve to make the code shouty loud, don't actually add any real value, and are often used incorrectly.
--- fs/xfs/xfs_buf.c | 23 ++++++++++++----------- fs/xfs/xfs_buf.h | 4 +--- fs/xfs/xfs_buf_item.c | 15 ++++++++------- fs/xfs/xfs_da_btree.c | 16 ++++++++-------- fs/xfs/xfs_log.c | 2 +- fs/xfs/xfs_log_recover.c | 15 ++++++++------- fs/xfs/xfs_trans_buf.c | 4 ++-- 7 files changed, 40 insertions(+), 39 deletions(-)
fs/xfs/xfs_buf.c +12 -11
@@ -193,12 +193,12 @@ xfs_buf_alloc( bp->b_target = target;/* -* Set length and count_desired to the same value initially. -* I/O routines should use count_desired, which will be the same in +* Set length and io_length to the same value initially. +* I/O routines should use io_length, which will be the same in * most cases but may be reset (e.g. XFS recovery). */ bp->b_length = numblks; - bp->b_count_desired = numblks <<BBSHIFT ; + bp->b_io_length = numblks; bp->b_flags = flags;/*
@@ -298,7 +298,7 @@ xfs_buf_allocate_memory(xfs_buf_t *bp, uint flags) { - size_t size = bp->b_count_desired; + size_t size;size_t nbytes, offset;gfp_t gfp_mask =xb_to_gfp (flags);unsigned short page_count, i;
@@ -341,6 +341,7 @@ use_alloc_page:return error; offset = bp->b_offset; + size =BBTOB (bp->b_length); bp->b_flags |= _XBF_PAGES;for (i =0 ; i < bp->b_page_count; i++) {
@@ -600,7 +601,7 @@ xfs_buf_get(* that we can do IO on it. */ bp->b_bn = blkno; - bp->b_count_desired =BBTOB (bp->b_length); + bp->b_io_length = bp->b_length; found:if (!(bp->b_flags &XBF_MAPPED )) {
@@ -745,7 +746,7 @@ xfs_buf_set_empty( bp->b_page_count =0 ; bp->b_addr =NULL ; bp->b_length = numblks; - bp->b_count_desired = numblks <<BBSHIFT ; + bp->b_io_length = numblks; bp->b_bn =XFS_BUF_DADDR_NULL ; bp->b_flags &= ~XBF_MAPPED ; }
@@ -797,7 +798,7 @@ xfs_buf_associate_memory( pageaddr +=PAGE_SIZE ; } - bp->b_count_desired = len; + bp->b_io_length =BTOBB (len); bp->b_length =BTOBB (buflen); bp->b_flags |=XBF_MAPPED ;
@@ -1041,7 +1042,7 @@ xfs_buf_ioerror_alert(xfs_alert (bp->b_target->bt_mount,"metadata I/O error: block 0x%llx (\"%s\") error %d buf count %zd" , (__uint64_t )XFS_BUF_ADDR (bp), func, - bp->b_error,XFS_BUF_COUNT (bp)); + bp->b_error,BBTOB (bp->b_length)); }int
@@ -1213,7 +1214,7 @@ _xfs_buf_ioapply(int rw, map_i, total_nr_pages, nr_pages;struct bio *bio;int offset = bp->b_offset; -int size = bp->b_count_desired; +int size =BBTOB (bp->b_io_length);sector_t sector = bp->b_bn; total_nr_pages = bp->b_page_count;
@@ -1261,7 +1262,7 @@ next_chunk:break ; offset =0 ; - sector += nbytes >>BBSHIFT ; + sector +=BTOBB (nbytes); size -= nbytes; total_nr_pages--; }
@@ -1355,7 +1356,7 @@ xfs_buf_iomove( page = bp->b_pages[xfs_buf_btoct (boff + bp->b_offset)]; cpoff =xfs_buf_poff (boff + bp->b_offset); csize =min_t (size_t, -PAGE_SIZE -cpoff, bp->b_count_desired-boff); +PAGE_SIZE - cpoff,BBTOB (bp->b_io_length) - boff);ASSERT (((csize + cpoff) <=PAGE_SIZE ));
fs/xfs/xfs_buf.h +1 -3
@@ -131,7 +131,7 @@ typedef struct xfs_buf {struct list_head b_list;struct xfs_perag *b_pag;/* contains rbtree root */ xfs_buftarg_t *b_target;/* buffer target (device) */ -size_t b_count_desired;/* desired transfer size */ +size_t b_io_length;/* IO size in BBs */ void *b_addr;/* virtual address of buffer */ struct work_struct b_iodone_work;xfs_buf_iodone_t b_iodone;/* I/O completion function */
@@ -247,8 +247,6 @@ void xfs_buf_stale(struct xfs_buf *bp);#define XFS_BUF_ADDR (bp) ((bp)->b_bn)#define XFS_BUF_SET_ADDR (bp, bno) ((bp)->b_bn = (xfs_daddr_t)(bno)) -#define XFS_BUF_COUNT (bp) ((bp)->b_count_desired) -#define XFS_BUF_SET_COUNT (bp, cnt) ((bp)->b_count_desired = (cnt))static inline void xfs_buf_set_ref (struct xfs_buf *bp,int lru_ref) {
fs/xfs/xfs_buf_item.c +8 -7
@@ -123,11 +123,11 @@ xfs_buf_item_log_check(ASSERT (bip->bli_logged !=NULL ); bp = bip->bli_buf; -ASSERT (XFS_BUF_COUNT (bp) >0 ); +ASSERT (bp->b_length >0 );ASSERT (bp->b_addr !=NULL ); orig = bip->bli_orig; buffer = bp->b_addr; -for (x =0 ; x <XFS_BUF_COUNT (bp); x++) { +for (x =0 ; x <BBTOB (bp->b_length); x++) {if (orig[x] != buffer[x] && !btst (bip->bli_logged, x)) { xfs_emerg(bp->b_mount, "%s: bip %x buffer %x orig %x index %d",
@@ -657,7 +657,8 @@ xfs_buf_item_init(* truncate any pieces. map_size is the size of the * bitmap needed to describe the chunks of the buffer. */ - chunks = (int )((XFS_BUF_COUNT (bp) + (XFS_BLF_CHUNK -1 )) >>XFS_BLF_SHIFT ); + chunks = (int )((BBTOB (bp->b_length) + (XFS_BLF_CHUNK -1 )) >> +XFS_BLF_SHIFT ); map_size = (int )((chunks +NBWORD ) >>BIT_TO_WORD_SHIFT ); bip = (xfs_buf_log_item_t*)kmem_zone_zalloc(xfs_buf_item_zone,
@@ -667,7 +668,7 @@ xfs_buf_item_init(xfs_buf_hold (bp); bip->bli_format.blf_type =XFS_LI_BUF ; bip->bli_format.blf_blkno = (__int64_t )XFS_BUF_ADDR (bp); - bip->bli_format.blf_len = (ushort )BTOBB (XFS_BUF_COUNT (bp)); + bip->bli_format.blf_len = (ushort )bp->b_length; bip->bli_format.blf_map_size = map_size;#ifdef XFS_TRANS_DEBUG
@@ -679,9 +680,9 @@ xfs_buf_item_init(* the buffer to indicate which bytes the callers have asked * to have logged. */ - bip->bli_orig = (char *)kmem_alloc (XFS_BUF_COUNT (bp),KM_SLEEP ); -memcpy (bip->bli_orig, bp->b_addr,XFS_BUF_COUNT (bp)); - bip->bli_logged = (char *)kmem_zalloc (XFS_BUF_COUNT (bp) /NBBY ,KM_SLEEP ); + bip->bli_orig =kmem_alloc (BBTOB (bp->b_length),KM_SLEEP ); +memcpy (bip->bli_orig, bp->b_addr,BBTOB (bp->b_length)); + bip->bli_logged =kmem_zalloc (BBTOB (bp->b_length) /NBBY ,KM_SLEEP );#endif /*
fs/xfs/xfs_da_btree.c +8 -8
@@ -2277,20 +2277,20 @@ xfs_da_buf_make(int nbuf, xfs_buf_t **bps)if (nbuf ==1 ) { dabuf->nbuf =1 ; bp = bps[0 ]; - dabuf->bbcount = (short )BTOBB (XFS_BUF_COUNT (bp)); + dabuf->bbcount = bp->b_length; dabuf->data = bp->b_addr; dabuf->bps[0 ] = bp; }else { dabuf->nbuf = nbuf;for (i =0 , dabuf->bbcount =0 ; i < nbuf; i++) { dabuf->bps[i] = bp = bps[i]; - dabuf->bbcount +=BTOBB (XFS_BUF_COUNT (bp)); + dabuf->bbcount += bp->b_length; } dabuf->data =kmem_alloc (BBTOB (dabuf->bbcount),KM_SLEEP ); -for (i = off =0 ; i < nbuf; i++, off +=XFS_BUF_COUNT (bp)) { +for (i = off =0 ; i < nbuf; i++, off +=BBTOB (bp->b_length)) { bp = bps[i];memcpy ((char *)dabuf->data + off, bp->b_addr, -XFS_BUF_COUNT (bp)); +BBTOB (bp->b_length)); } }return dabuf;
@@ -2310,10 +2310,10 @@ xfs_da_buf_clean(xfs_dabuf_t *dabuf)ASSERT (dabuf->nbuf >1 ); dabuf->dirty =0 ;for (i = off =0 ; i < dabuf->nbuf; - i++, off +=XFS_BUF_COUNT (bp)) { + i++, off +=BBTOB (bp->b_length)) { bp = dabuf->bps[i];memcpy (bp->b_addr, dabuf->data + off, -XFS_BUF_COUNT (bp)); +BBTOB (bp->b_length)); } } }
@@ -2356,10 +2356,10 @@ xfs_da_log_buf(xfs_trans_t *tp, xfs_dabuf_t *dabuf, uint first, uint last) } dabuf->dirty =1 ;ASSERT (first <= last); -for (i = off =0 ; i < dabuf->nbuf; i++, off +=XFS_BUF_COUNT (bp)) { +for (i = off =0 ; i < dabuf->nbuf; i++, off +=BBTOB (bp->b_length)) { bp = dabuf->bps[i]; f = off; - l = f +XFS_BUF_COUNT (bp) -1 ; + l = f +BBTOB (bp->b_length) -1 ;if (f < first) f = first;if (l > last)
fs/xfs/xfs_log.c +1 -1
@@ -1487,7 +1487,7 @@ xlog_sync(xlog_t *log, }else { iclog->ic_bwritecnt =1 ; } -XFS_BUF_SET_COUNT (bp, count); + bp->b_io_length =BTOBB (count); bp->b_fspriv = iclog;XFS_BUF_ZEROFLAGS (bp);XFS_BUF_ASYNC (bp);
fs/xfs/xfs_log_recover.c +8 -7
@@ -178,7 +178,7 @@ xlog_bread_noalign(XFS_BUF_SET_ADDR (bp, log->l_logBBstart + blk_no);XFS_BUF_READ (bp); -XFS_BUF_SET_COUNT (bp,BBTOB (nbblks)); + bp->b_io_length = nbblks;xfsbdstrat (log->l_mp, bp); error =xfs_buf_iowait (bp);
@@ -265,7 +265,7 @@ xlog_bwrite(XFS_BUF_ZEROFLAGS (bp);xfs_buf_hold (bp);xfs_buf_lock (bp); -XFS_BUF_SET_COUNT (bp,BBTOB (nbblks)); + bp->b_io_length = nbblks; error =xfs_bwrite (bp);if (error)
@@ -1772,7 +1772,7 @@ xlog_recover_do_inode_buffer(trace_xfs_log_recover_buf_inode_buf (mp->m_log, buf_f); - inodes_per_buf =XFS_BUF_COUNT (bp) >> mp->m_sb.sb_inodelog; + inodes_per_buf =BBTOB (bp->b_io_length) >> mp->m_sb.sb_inodelog;for (i =0 ; i < inodes_per_buf; i++) { next_unlinked_offset = (i * mp->m_sb.sb_inodesize) + offsetof(xfs_dinode_t , di_next_unlinked);
@@ -1814,7 +1814,8 @@ xlog_recover_do_inode_buffer(ASSERT (item->ri_buf[item_index].i_addr !=NULL );ASSERT ((item->ri_buf[item_index].i_len %XFS_BLF_CHUNK ) ==0 ); -ASSERT ((reg_buf_offset + reg_buf_bytes) <=XFS_BUF_COUNT (bp)); +ASSERT ((reg_buf_offset + reg_buf_bytes) <= +BBTOB (bp->b_io_length));/* * The current logged region contains a copy of the
@@ -1873,8 +1874,8 @@ xlog_recover_do_reg_buffer(ASSERT (nbits >0 );ASSERT (item->ri_buf[i].i_addr !=NULL );ASSERT (item->ri_buf[i].i_len %XFS_BLF_CHUNK ==0 ); -ASSERT (XFS_BUF_COUNT (bp) >= - ((uint )bit <<XFS_BLF_SHIFT )+(nbits<<XFS_BLF_SHIFT )); +ASSERT (BBTOB (bp->b_io_length) >= + ((uint )bit <<XFS_BLF_SHIFT ) + (nbits <<XFS_BLF_SHIFT ));/* * Do a sanity check if this is a dquot buffer. Just checking
@@ -2167,7 +2168,7 @@ xlog_recover_buffer_pass2(*/ if (XFS_DINODE_MAGIC ==be16_to_cpu (*((__be16 *)xfs_buf_offset (bp,0 ))) && - (XFS_BUF_COUNT (bp) !=MAX (log->l_mp->m_sb.sb_blocksize, + (BBTOB (bp->b_io_length) !=MAX (log->l_mp->m_sb.sb_blocksize, (__uint32_t )XFS_INODE_CLUSTER_SIZE (log->l_mp)))) {xfs_buf_stale (bp); error =xfs_bwrite (bp);
fs/xfs/xfs_trans_buf.c +2 -2
@@ -56,7 +56,7 @@ xfs_trans_buf_item_match(if (blip->bli_item.li_type ==XFS_LI_BUF && blip->bli_buf->b_target == target &&XFS_BUF_ADDR (blip->bli_buf) == blkno && -XFS_BUF_COUNT (blip->bli_buf) == len) +BBTOB (blip->bli_buf->b_length) == len)return blip->bli_buf; }
@@ -585,7 +585,7 @@ xfs_trans_log_buf(xfs_trans_t *tp,ASSERT (bp->b_transp == tp);ASSERT (bip !=NULL ); -ASSERT ((first <= last) && (last <XFS_BUF_COUNT (bp))); +ASSERT (first <= last && last <BBTOB (bp->b_length));ASSERT (bp->b_iodone ==NULL || bp->b_iodone == xfs_buf_iodone_callbacks);
Signature · 6 lines
1.7.9 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 2/4] xfs: kill b_file_offset
In reply to Dave ChinnerLooks good.
Minor comments below:
fs/xfs/xfs_buf.c xfs_buf_allocate_memory( · line 337
Quoted 4 lines · Dave Chinner
fs/xfs/xfs_buf.c +2
-2- end = bp->b_file_offset + bp->b_buffer_length; - page_count =xfs_buf_btoc (end) -xfs_buf_btoct (bp->b_file_offset); + end =BBTOB (bp->b_bn) + bp->b_buffer_length; + page_count =xfs_buf_btoc (end) -xfs_buf_btoct (BBTOB (bp->b_bn));
Btw, xfs_buf_btoc and xfs_buf_btoct are more remoal candidates, they actually make the code harder to read compared to using the opencoded arithmetics..
fs/xfs/xfs_buf.c _xfs_buf_find( · line 448
Quoted 6 lines
fs/xfs/xfs_buf.c +1
-1numbytes = numblks <<BBSHIFT ;/* Check for IOs smaller than the sector size / not sector aligned */ ASSERT (!(numbytes < (1 << btp->bt_sshift))); -ASSERT (!(offset & (xfs_off_t )btp->bt_smask)); +ASSERT (!(BBTOB (blkno) & (xfs_off_t )btp->bt_smask));
I don't think it makes sense to keep this assert, given that the return value from BBTOB is aligned by defintion.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 3/4] xfs: use blocks for counting length of buffers
In reply to Dave Chinnerfs/xfs/xfs_attr.c xfs_attr_rmtval_get(xfs_da_args_t *args) · line 1997
Quoted 2 lines
fs/xfs/xfs_attr.c +2
-0+ tmp = (valuelen <BBTOB (bp->b_length)) + ? valuelen :BBTOB (bp->b_length);
maybe use min or min_t here while you're at it?
fs/xfs/xfs_attr.c xfs_attr_rmtval_set(xfs_da_args_t *args) · line 2122
Quoted 4 lines
fs/xfs/xfs_attr.c +2
-2- tmp = (valuelen <XFS_BUF_SIZE (bp)) ? valuelen : -XFS_BUF_SIZE (bp); + tmp = valuelen <BBTOB (bp->b_length) ? valuelen : +BBTOB (bp->b_length);
Same here.
fs/xfs/xfs_attr.c xfs_attr_rmtval_set(xfs_da_args_t *args) · line 2125
Quoted 5 lines
fs/xfs/xfs_attr.c +2
-2xfs_buf_iomove (bp,0 , tmp, src,XBRW_WRITE ); -if (tmp <XFS_BUF_SIZE (bp)) -xfs_buf_zero (bp, tmp,XFS_BUF_SIZE (bp) - tmp); +if (tmp <BBTOB (bp->b_length)) +xfs_buf_zero (bp, tmp,BBTOB (bp->b_length) - tmp);
Also a local buf_len variable in this function would probably be useful.
fs/xfs/xfs_buf.h typedef struct xfs_buf { · line 123
Quoted 2 lines
fs/xfs/xfs_buf.h +1
-1-size_t b_buffer_length;/* size of buffer in bytes */ +size_t b_length;/* size of buffer in BBs */
A count of blocks probably shold not be a size_t, but a uint.
fs/xfs/xfs_trace.h DECLARE_EVENT_CLASS(xfs_buf_class, · line 294
Quoted 5 lines
fs/xfs/xfs_trace.h +1
-1TP_fast_assign ( __entry->dev = bp->b_target->bt_dev; __entry->bno = bp->b_bn; - __entry->buffer_length = bp->b_buffer_length; + __entry->buffer_length =BBTOB (bp->b_length);
Given that we print the bno in blocks it might make sense to print this as number of blocks, too? Change the description string to nblks in that case as well.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 4/4] xfs: use blocks for storing the desired IO size
In reply to Dave ChinnerLooks good except for the size_t usage mentioned in the review for the previous patch.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 2/4] xfs: kill b_file_offset
In reply to Christoph HellwigQuoted 8 lines · Christoph Hellwig
Looks good.
Reviewed-by Christoph Hellwig <[email protected]>Minor comments below:
On Wed, Mar 28, 2012 at 04:19:16PM +1100, Dave Chinner wrote:
Quoted 8 lines
fs/xfs/xfs_buf.c xfs_buf_allocate_memory( · line 337
Quoted 4 lines
fs/xfs/xfs_buf.c +2
-2- end = bp->b_file_offset + bp->b_buffer_length; - page_count =xfs_buf_btoc (end) -xfs_buf_btoct (bp->b_file_offset); + end =BBTOB (bp->b_bn) + bp->b_buffer_length; + page_count =xfs_buf_btoc (end) -xfs_buf_btoct (BBTOB (bp->b_bn));Btw,
xfs_buf_btocandxfs_buf_btoctare more remoal candidates, they actually make the code harder to read compared to using the opencoded arithmetics..
Ok, I'll consider doing that in the next set of patches.
Quoted 9 lines
fs/xfs/xfs_buf.c _xfs_buf_find( · line 448
Quoted 6 lines
fs/xfs/xfs_buf.c +1
-1numbytes = numblks <<BBSHIFT ;/* Check for IOs smaller than the sector size / not sector aligned */ ASSERT (!(numbytes < (1 << btp->bt_sshift))); -ASSERT (!(offset & (xfs_off_t )btp->bt_smask)); +ASSERT (!(BBTOB (blkno) & (xfs_off_t )btp->bt_smask));I don't think it makes sense to keep this assert, given that the return value from BBTOB is aligned by defintion.
I kept them there for the 4k sector case. Basic Blocks are always 512 bytes, so for filesystems with sector sizes greater than 512 bytes we still need a sector alignment and size check.
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 3/4] xfs: use blocks for counting length of buffers
In reply to Christoph HellwigQuoted 25 lines · Christoph Hellwig
fs/xfs/xfs_attr.c xfs_attr_rmtval_get(xfs_da_args_t *args) · line 1997
Quoted 2 lines
fs/xfs/xfs_attr.c +2
-0+ tmp = (valuelen <BBTOB (bp->b_length)) + ? valuelen :BBTOB (bp->b_length);maybe use min or
min_there while you're at it?fs/xfs/xfs_attr.c xfs_attr_rmtval_set(xfs_da_args_t *args) · line 2122
Quoted 4 lines
fs/xfs/xfs_attr.c +2
-2- tmp = (valuelen <XFS_BUF_SIZE (bp)) ? valuelen : -XFS_BUF_SIZE (bp); + tmp = valuelen <BBTOB (bp->b_length) ? valuelen : +BBTOB (bp->b_length);Same here.
fs/xfs/xfs_attr.c xfs_attr_rmtval_set(xfs_da_args_t *args) · line 2125
Quoted 5 lines
fs/xfs/xfs_attr.c +2
-2xfs_buf_iomove (bp,0 , tmp, src,XBRW_WRITE ); -if (tmp <XFS_BUF_SIZE (bp)) -xfs_buf_zero (bp, tmp,XFS_BUF_SIZE (bp) - tmp); +if (tmp <BBTOB (bp->b_length)) +xfs_buf_zero (bp, tmp,BBTOB (bp->b_length) - tmp);Also a local
buf_lenvariable in this function would probably be useful.fs/xfs/xfs_buf.h typedef struct xfs_buf { · line 123
Quoted 2 lines
fs/xfs/xfs_buf.h +1
-1-size_t b_buffer_length;/* size of buffer in bytes */ +size_t b_length;/* size of buffer in BBs */ A count of blocks probably shold not be a
size_t, but a uint.
Quoted 9 lines
fs/xfs/xfs_trace.h DECLARE_EVENT_CLASS(xfs_buf_class, · line 294
Quoted 5 lines
fs/xfs/xfs_trace.h +1
-1TP_fast_assign ( __entry->dev = bp->b_target->bt_dev; __entry->bno = bp->b_bn; - __entry->buffer_length = bp->b_buffer_length; + __entry->buffer_length =BBTOB (bp->b_length);Given that we print the bno in blocks it might make sense to print this as number of blocks, too? Change the description string to nblks in that case as well.
All makes sense. Will do.
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs