All of lore.kernel.org
 help / color / mirror / Atom feed
From: colyli@suse.de
To: axboe@kernel.dk
Cc: linux-bcache@vger.kernel.org, linux-block@vger.kernel.org,
	Christoph Hellwig <hch@lst.de>, Coly Li <colyli@suse.de>
Subject: [PATCH 06/17] bcache: transfer the sb_page reference to register_{bdev,cache}
Date: Fri, 24 Jan 2020 01:01:31 +0800	[thread overview]
Message-ID: <20200123170142.98974-7-colyli@suse.de> (raw)
In-Reply-To: <20200123170142.98974-1-colyli@suse.de>

From: Christoph Hellwig <hch@lst.de>

Avoid an extra reference count roundtrip by transferring the sb_page
ownership to the lower level register helpers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Coly Li <colyli@suse.de>
---
 drivers/md/bcache/super.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index fad9c6cbee5e..cf2cafef381f 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -1368,8 +1368,6 @@ static int register_bdev(struct cache_sb *sb, struct page *sb_page,
 
 	bio_init(&dc->sb_bio, dc->sb_bio.bi_inline_vecs, 1);
 	bio_first_bvec_all(&dc->sb_bio)->bv_page = sb_page;
-	get_page(sb_page);
-
 
 	if (cached_dev_init(dc, sb->block_size << 9))
 		goto err;
@@ -2275,7 +2273,6 @@ static int register_cache(struct cache_sb *sb, struct page *sb_page,
 
 	bio_init(&ca->sb_bio, ca->sb_bio.bi_inline_vecs, 1);
 	bio_first_bvec_all(&ca->sb_bio)->bv_page = sb_page;
-	get_page(sb_page);
 
 	if (blk_queue_discard(bdev_get_queue(bdev)))
 		ca->discard = CACHE_DISCARD(&ca->sb);
@@ -2378,7 +2375,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
 	const char *err;
 	char *path = NULL;
 	struct cache_sb *sb;
-	struct block_device *bdev = NULL;
+	struct block_device *bdev;
 	struct page *sb_page;
 	ssize_t ret;
 
@@ -2444,10 +2441,8 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
 		ret = register_bdev(sb, sb_page, bdev, dc);
 		mutex_unlock(&bch_register_lock);
 		/* blkdev_put() will be called in cached_dev_free() */
-		if (ret < 0) {
-			bdev = NULL;
-			goto out_put_sb_page;
-		}
+		if (ret < 0)
+			goto out_free_sb;
 	} else {
 		struct cache *ca = kzalloc(sizeof(*ca), GFP_KERNEL);
 
@@ -2455,13 +2450,10 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
 			goto out_put_sb_page;
 
 		/* blkdev_put() will be called in bch_cache_release() */
-		if (register_cache(sb, sb_page, bdev, ca) != 0) {
-			bdev = NULL;
-			goto out_put_sb_page;
-		}
+		if (register_cache(sb, sb_page, bdev, ca) != 0)
+			goto out_free_sb;
 	}
 
-	put_page(sb_page);
 done:
 	kfree(sb);
 	kfree(path);
@@ -2471,8 +2463,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
 out_put_sb_page:
 	put_page(sb_page);
 out_blkdev_put:
-	if (bdev)
-		blkdev_put(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL);
+	blkdev_put(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL);
 out_free_sb:
 	kfree(sb);
 out_free_path:
-- 
2.16.4


  parent reply	other threads:[~2020-01-23 17:02 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-23 17:01 [PATCH 00/17] bcache patches for Linux v5.6 colyli
2020-01-23 17:01 ` [PATCH 01/17] bcache: cached_dev_free needs to put the sb page colyli
2020-01-23 17:01 ` [PATCH 02/17] bcache: use a separate data structure for the on-disk super block colyli
2020-01-23 17:01 ` [PATCH 03/17] bcache: rework error unwinding in register_bcache colyli
2020-01-23 17:01 ` [PATCH 04/17] bcache: properly initialize 'path' and 'err' in register_bcache() colyli
2020-01-23 17:01 ` [PATCH 05/17] bcache: fix use-after-free " colyli
2020-01-23 17:01 ` colyli [this message]
2020-01-23 17:01 ` [PATCH 07/17] bcache: return a pointer to the on-disk sb from read_super colyli
2020-01-23 17:01 ` [PATCH 08/17] bcache: store a pointer to the on-disk sb in the cache and cached_dev structures colyli
2020-01-23 17:01 ` [PATCH 09/17] bcache: use read_cache_page_gfp to read the superblock colyli
2020-01-23 17:01 ` [PATCH 10/17] lib: crc64: include <linux/crc64.h> for 'crc64_be' colyli
2020-01-23 17:01 ` [PATCH 11/17] bcache: add code comments for state->pool in __btree_sort() colyli
2020-01-23 17:01 ` [PATCH 12/17] bcache: avoid unnecessary btree nodes flushing in btree_flush_write() colyli
2020-01-23 17:01 ` [PATCH 13/17] bcache: print written and keys in trace_bcache_btree_write colyli
2020-01-23 17:01 ` [PATCH 14/17] bcache: back to cache all readahead I/Os colyli
2020-01-23 17:19   ` Michael Lyle
2020-01-23 17:27     ` Coly Li
2020-01-23 18:31       ` Jens Axboe
2020-01-24  0:49         ` Coly Li
2020-01-24  1:14           ` Jens Axboe
2020-01-24 16:48       ` Michael Lyle
2020-01-23 17:01 ` [PATCH 15/17] bcache: remove member accessed from struct btree colyli
2020-01-23 17:01 ` [PATCH 16/17] bcache: reap c->btree_cache_freeable from the tail in bch_mca_scan() colyli
2020-01-23 17:01 ` [PATCH 17/17] bcache: reap from tail of c->btree_cache " colyli

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=20200123170142.98974-7-colyli@suse.de \
    --to=colyli@suse.de \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-block@vger.kernel.org \
    /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.