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> --- 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 5285abd5..09a2a716 100644 --- a/libxfs/rdwr.c +++ b/libxfs/rdwr.c @@ -518,8 +518,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); @@ -535,7 +535,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; } @@ -632,23 +632,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; } @@ -1120,7 +1122,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); }