From: Darrick J. Wong <darrick.wong@xxxxxxxxxx> Get rid of all the dangerous casting between xfs_buf and cache_node since we can dereference directly. Signed-off-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx> Reviewed-by: Christoph Hellwig <hch@xxxxxx> --- libxfs/libxfs_io.h | 5 ++--- libxfs/rdwr.c | 28 +++++++++++++++------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h index 646e340b..cd159881 100644 --- a/libxfs/libxfs_io.h +++ b/libxfs/libxfs_io.h @@ -109,10 +109,9 @@ typedef unsigned int xfs_buf_flags_t; #define XFS_BUF_SET_PRIORITY(bp,pri) cache_node_set_priority( \ libxfs_bcache, \ - (struct cache_node *)(bp), \ + &(bp)->b_node, \ (pri)) -#define XFS_BUF_PRIORITY(bp) (cache_node_get_priority( \ - (struct cache_node *)(bp))) +#define XFS_BUF_PRIORITY(bp) (cache_node_get_priority(&(bp)->b_node)) #define xfs_buf_set_ref(bp,ref) ((void) 0) #define xfs_buf_ioerror(bp,err) ((bp)->b_error = (err)) diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c index bb925711..f92c7db9 100644 --- a/libxfs/rdwr.c +++ b/libxfs/rdwr.c @@ -525,8 +525,8 @@ __cache_lookup(struct xfs_bufkey *key, unsigned int flags) bp->b_holder = pthread_self(); } - cache_node_set_priority(libxfs_bcache, (struct cache_node *)bp, - cache_node_get_priority((struct cache_node *)bp) - + cache_node_set_priority(libxfs_bcache, &bp->b_node, + cache_node_get_priority(&bp->b_node) - CACHE_PREFETCH_PRIORITY); #ifdef XFS_BUF_TRACING pthread_mutex_lock(&libxfs_bcache->c_mutex); @@ -542,7 +542,7 @@ __cache_lookup(struct xfs_bufkey *key, unsigned int flags) return bp; out_put: - cache_node_put(libxfs_bcache, (struct cache_node *)bp); + cache_node_put(libxfs_bcache, &bp->b_node); return NULL; } @@ -639,23 +639,25 @@ libxfs_buf_relse( } if (!list_empty(&bp->b_node.cn_hash)) - cache_node_put(libxfs_bcache, (struct cache_node *)bp); + cache_node_put(libxfs_bcache, &bp->b_node); else if (--bp->b_node.cn_count == 0) libxfs_putbufr(bp); } static struct cache_node * -libxfs_balloc(cache_key_t key) +libxfs_balloc( + cache_key_t key) { - struct xfs_bufkey *bufkey = (struct xfs_bufkey *)key; + struct xfs_bufkey *bufkey = (struct xfs_bufkey *)key; + struct xfs_buf *bp; if (bufkey->map) - return (struct cache_node *) - libxfs_getbufr_map(bufkey->buftarg, - bufkey->blkno, bufkey->bblen, - bufkey->map, bufkey->nmaps); - return (struct cache_node *)libxfs_getbufr(bufkey->buftarg, - bufkey->blkno, bufkey->bblen); + bp = libxfs_getbufr_map(bufkey->buftarg, bufkey->blkno, + bufkey->bblen, bufkey->map, bufkey->nmaps); + else + bp = libxfs_getbufr(bufkey->buftarg, bufkey->blkno, + bufkey->bblen); + return &bp->b_node; } @@ -1127,7 +1129,7 @@ libxfs_putbufr(xfs_buf_t *bp) { if (bp->b_flags & LIBXFS_B_DIRTY) libxfs_bwrite(bp); - libxfs_brelse((struct cache_node *)bp); + libxfs_brelse(&bp->b_node); }