All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: sandeen@sandeen.net, darrick.wong@oracle.com
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH 20/25] libxfs: remove dangerous casting between xfs_buf and cache_node
Date: Mon, 24 Feb 2020 16:13:36 -0800	[thread overview]
Message-ID: <158258961671.451378.13182510046201286918.stgit@magnolia> (raw)
In-Reply-To: <158258948821.451378.9298492251721116455.stgit@magnolia>

From: Darrick J. Wong <darrick.wong@oracle.com>

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@oracle.com>
---
 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);
 }
 
 


  parent reply	other threads:[~2020-02-25  0:15 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
2020-02-25  0:11 ` [PATCH 01/25] libxfs: open-code "exit on buffer read failure" in upper level callers Darrick J. Wong
2020-02-25 17:42   ` Christoph Hellwig
2020-02-25 18:40     ` Darrick J. Wong
2020-02-25 18:42       ` Christoph Hellwig
2020-02-25 19:19         ` Darrick J. Wong
2020-02-25 19:26   ` [PATCH v2 " Darrick J. Wong
2020-02-25  0:11 ` [PATCH 02/25] libxfs: remove LIBXFS_EXIT_ON_FAILURE Darrick J. Wong
2020-02-25 17:43   ` Christoph Hellwig
2020-02-25  0:11 ` [PATCH 03/25] libxfs: remove LIBXFS_B_EXIT Darrick J. Wong
2020-02-25 17:43   ` Christoph Hellwig
2020-02-25  0:11 ` [PATCH 04/25] libxfs: replace libxfs_putbuf with libxfs_buf_relse Darrick J. Wong
2020-02-25  0:12 ` [PATCH 05/25] libxfs: replace libxfs_getbuf with libxfs_buf_get Darrick J. Wong
2020-02-25  0:12 ` [PATCH 06/25] libxfs: replace libxfs_readbuf with libxfs_buf_read Darrick J. Wong
2020-02-25  0:12 ` [PATCH 07/25] libxfs: rename libxfs_writebufr to libxfs_bwrite Darrick J. Wong
2020-02-25 17:44   ` Christoph Hellwig
2020-02-25  0:12 ` [PATCH 08/25] libxfs: make libxfs_readbuf_verify return an error code Darrick J. Wong
2020-02-25  0:12 ` [PATCH 09/25] libxfs: make libxfs_readbufr stash the error value in b_error Darrick J. Wong
2020-02-25  0:12 ` [PATCH 10/25] libxfs: introduce libxfs_buf_read_uncached Darrick J. Wong
2020-02-25 17:44   ` Christoph Hellwig
2020-02-25  0:12 ` [PATCH 11/25] xfs_db: use uncached buffer reads to get the superblock Darrick J. Wong
2020-02-25 17:45   ` Christoph Hellwig
2020-02-25  0:12 ` [PATCH 12/25] xfs_copy: " Darrick J. Wong
2020-02-25 17:45   ` Christoph Hellwig
2020-02-25  0:12 ` [PATCH 13/25] libxfs: move log functions for convenience Darrick J. Wong
2020-02-25 17:47   ` Christoph Hellwig
2020-02-25 18:47     ` Darrick J. Wong
2020-02-25  0:12 ` [PATCH 14/25] libxfs: convert libxfs_log_clear to use uncached buffers Darrick J. Wong
2020-02-25 17:49   ` Christoph Hellwig
2020-02-25 18:48     ` Darrick J. Wong
2020-02-25  0:13 ` [PATCH 15/25] libxlog: use uncached buffers instead of open-coding them Darrick J. Wong
2020-02-25 17:50   ` Christoph Hellwig
2020-02-25  0:13 ` [PATCH 16/25] libxfs: use uncached buffers for initial mkfs writes Darrick J. Wong
2020-02-25  0:13 ` [PATCH 17/25] libxfs: straighten out libxfs_writebuf naming confusion Darrick J. Wong
2020-02-25 17:50   ` Christoph Hellwig
2020-02-25  0:13 ` [PATCH 18/25] libxfs: remove unused flags parameter to libxfs_buf_mark_dirty Darrick J. Wong
2020-02-25 17:51   ` Christoph Hellwig
2020-02-25 18:52     ` Darrick J. Wong
2020-02-25  0:13 ` [PATCH 19/25] libxfs: remove libxfs_writebuf_int Darrick J. Wong
2020-02-25  0:13 ` Darrick J. Wong [this message]
2020-02-25 17:52   ` [PATCH 20/25] libxfs: remove dangerous casting between xfs_buf and cache_node Christoph Hellwig
2020-02-25 18:52     ` Darrick J. Wong
2020-02-25  0:13 ` [PATCH 21/25] libxfs: remove dangerous casting between cache_node and xfs_buf Darrick J. Wong
2020-02-25 17:52   ` Christoph Hellwig
2020-02-25  0:13 ` [PATCH 22/25] libxfs: remove the libxfs_{get,put}bufr APIs Darrick J. Wong
2020-02-25 17:52   ` Christoph Hellwig
2020-02-25  0:13 ` [PATCH 23/25] libxfs: hide libxfs_getbuf_flags Darrick J. Wong
2020-02-25  0:14 ` [PATCH 24/25] libxfs: rename libxfs_readbuf_map to libxfs_buf_read_map Darrick J. Wong
2020-02-25  0:14 ` [PATCH 25/25] libxfs: rename libxfs_getbuf_map to libxfs_buf_get_map Darrick J. Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=158258961671.451378.13182510046201286918.stgit@magnolia \
    --to=darrick.wong@oracle.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@sandeen.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.