All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yu Kuai <yukuai1@huaweicloud.com>
To: hch@lst.de, axboe@kernel.dk, agk@redhat.com, snitzer@kernel.org,
	dm-devel@redhat.com
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com
Subject: [PATCH v3 04/10] dm: cleanup close_table_device
Date: Tue, 15 Nov 2022 22:10:48 +0800	[thread overview]
Message-ID: <20221115141054.1051801-5-yukuai1@huaweicloud.com> (raw)
In-Reply-To: <20221115141054.1051801-1-yukuai1@huaweicloud.com>

From: Christoph Hellwig <hch@lst.de>

Take the list unlink and free into close_table_device so that no half
torn down table_devices exist.  Also remove the check for a NULL bdev
as that can't happen - open_table_device never adds a table_device to
the list that does not have a valid block_device.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 drivers/md/dm.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 28d7581b6a82..2917700b1e15 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -774,14 +774,11 @@ static struct table_device *open_table_device(struct mapped_device *md,
  */
 static void close_table_device(struct table_device *td, struct mapped_device *md)
 {
-	if (!td->dm_dev.bdev)
-		return;
-
 	bd_unlink_disk_holder(td->dm_dev.bdev, dm_disk(md));
 	blkdev_put(td->dm_dev.bdev, td->dm_dev.mode | FMODE_EXCL);
 	put_dax(td->dm_dev.dax_dev);
-	td->dm_dev.bdev = NULL;
-	td->dm_dev.dax_dev = NULL;
+	list_del(&td->list);
+	kfree(td);
 }
 
 static struct table_device *find_table_device(struct list_head *l, dev_t dev,
@@ -823,11 +820,8 @@ void dm_put_table_device(struct mapped_device *md, struct dm_dev *d)
 	struct table_device *td = container_of(d, struct table_device, dm_dev);
 
 	mutex_lock(&md->table_devices_lock);
-	if (refcount_dec_and_test(&td->count)) {
+	if (refcount_dec_and_test(&td->count))
 		close_table_device(td, md);
-		list_del(&td->list);
-		kfree(td);
-	}
 	mutex_unlock(&md->table_devices_lock);
 }
 
-- 
2.31.1


WARNING: multiple messages have this Message-ID (diff)
From: Yu Kuai <yukuai1@huaweicloud.com>
To: hch@lst.de, axboe@kernel.dk, agk@redhat.com, snitzer@kernel.org,
	dm-devel@redhat.com
Cc: linux-block@vger.kernel.org, yukuai3@huawei.com,
	yi.zhang@huawei.com, linux-kernel@vger.kernel.org,
	yukuai1@huaweicloud.com
Subject: [dm-devel] [PATCH v3 04/10] dm: cleanup close_table_device
Date: Tue, 15 Nov 2022 22:10:48 +0800	[thread overview]
Message-ID: <20221115141054.1051801-5-yukuai1@huaweicloud.com> (raw)
In-Reply-To: <20221115141054.1051801-1-yukuai1@huaweicloud.com>

From: Christoph Hellwig <hch@lst.de>

Take the list unlink and free into close_table_device so that no half
torn down table_devices exist.  Also remove the check for a NULL bdev
as that can't happen - open_table_device never adds a table_device to
the list that does not have a valid block_device.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 drivers/md/dm.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 28d7581b6a82..2917700b1e15 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -774,14 +774,11 @@ static struct table_device *open_table_device(struct mapped_device *md,
  */
 static void close_table_device(struct table_device *td, struct mapped_device *md)
 {
-	if (!td->dm_dev.bdev)
-		return;
-
 	bd_unlink_disk_holder(td->dm_dev.bdev, dm_disk(md));
 	blkdev_put(td->dm_dev.bdev, td->dm_dev.mode | FMODE_EXCL);
 	put_dax(td->dm_dev.dax_dev);
-	td->dm_dev.bdev = NULL;
-	td->dm_dev.dax_dev = NULL;
+	list_del(&td->list);
+	kfree(td);
 }
 
 static struct table_device *find_table_device(struct list_head *l, dev_t dev,
@@ -823,11 +820,8 @@ void dm_put_table_device(struct mapped_device *md, struct dm_dev *d)
 	struct table_device *td = container_of(d, struct table_device, dm_dev);
 
 	mutex_lock(&md->table_devices_lock);
-	if (refcount_dec_and_test(&td->count)) {
+	if (refcount_dec_and_test(&td->count))
 		close_table_device(td, md);
-		list_del(&td->list);
-		kfree(td);
-	}
 	mutex_unlock(&md->table_devices_lock);
 }
 
-- 
2.31.1

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


  parent reply	other threads:[~2022-11-15 13:49 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-15 14:10 [PATCH v3 00/10] fix delayed holder tracking Yu Kuai
2022-11-15 14:10 ` [dm-devel] " Yu Kuai
2022-11-15 14:10 ` [PATCH v3 01/10] block: clear ->slave_dir when dropping the main slave_dir reference Yu Kuai
2022-11-15 14:10   ` [dm-devel] " Yu Kuai
2022-11-16 22:10   ` Mike Snitzer
2022-11-16 22:10     ` [dm-devel] " Mike Snitzer
2022-11-15 14:10 ` [PATCH v3 02/10] dm: remove free_table_devices Yu Kuai
2022-11-15 14:10   ` [dm-devel] " Yu Kuai
2022-11-16 21:50   ` Mike Snitzer
2022-11-16 21:50     ` Mike Snitzer
2022-11-15 14:10 ` [PATCH v3 03/10] dm: cleanup open_table_device Yu Kuai
2022-11-15 14:10   ` [dm-devel] " Yu Kuai
2022-11-16 21:19   ` Mike Snitzer
2022-11-16 21:19     ` Mike Snitzer
2022-11-15 14:10 ` Yu Kuai [this message]
2022-11-15 14:10   ` [dm-devel] [PATCH v3 04/10] dm: cleanup close_table_device Yu Kuai
2022-11-16 21:46   ` Mike Snitzer
2022-11-16 21:46     ` Mike Snitzer
2022-11-15 14:10 ` [PATCH RFC v3 05/10] dm: make sure create and remove dm device won't race with open and close table Yu Kuai
2022-11-15 14:10   ` [dm-devel] " Yu Kuai
2022-11-16  6:35   ` Christoph Hellwig
2022-11-16  6:35     ` Christoph Hellwig
2022-11-16 21:48   ` [dm-devel] " Mike Snitzer
2022-11-16 21:48     ` Mike Snitzer
2022-11-15 14:10 ` [PATCH v3 06/10] dm: track per-add_disk holder relations in DM Yu Kuai
2022-11-15 14:10   ` [dm-devel] " Yu Kuai
2022-11-16 21:49   ` Mike Snitzer
2022-11-16 21:49     ` Mike Snitzer
2022-11-15 14:10 ` [PATCH v3 07/10] block: remove delayed holder registration Yu Kuai
2022-11-15 14:10   ` [dm-devel] " Yu Kuai
2022-11-15 14:10 ` [PATCH v3 08/10] block: fix use after free for bd_holder_dir Yu Kuai
2022-11-15 14:10   ` [dm-devel] " Yu Kuai
2022-11-16  6:35   ` Christoph Hellwig
2022-11-16  6:35     ` Christoph Hellwig
2022-11-15 14:10 ` [PATCH v3 09/10] block: store the holder kobject in bd_holder_disk Yu Kuai
2022-11-15 14:10   ` [dm-devel] " Yu Kuai
2022-11-16  6:36   ` Christoph Hellwig
2022-11-16  6:36     ` Christoph Hellwig
2022-11-15 14:10 ` [PATCH v3 10/10] block: don't allow a disk link holder to itself Yu Kuai
2022-11-15 14:10   ` [dm-devel] " Yu Kuai
2022-11-16  6:36   ` Christoph Hellwig
2022-11-16  6:36     ` Christoph Hellwig
2022-11-16 22:20 ` [PATCH v3 00/10] fix delayed holder tracking Jens Axboe
2022-11-16 22:20   ` [dm-devel] " Jens Axboe

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=20221115141054.1051801-5-yukuai1@huaweicloud.com \
    --to=yukuai1@huaweicloud.com \
    --cc=agk@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=dm-devel@redhat.com \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=snitzer@kernel.org \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai3@huawei.com \
    /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.