From: Yang Yang <yang.yang@vivo.com>
To: Alasdair Kergon <agk@redhat.com>,
Mike Snitzer <snitzer@kernel.org>,
Mikulas Patocka <mpatocka@redhat.com>,
dm-devel@lists.linux.dev, linux-kernel@vger.kernel.org
Cc: Yang Yang <yang.yang@vivo.com>
Subject: [PATCH 3/5] dm: support retrieving struct dm_target from struct dm_dev
Date: Tue, 14 May 2024 17:04:42 +0800 [thread overview]
Message-ID: <20240514090445.2847-4-yang.yang@vivo.com> (raw)
In-Reply-To: <20240514090445.2847-1-yang.yang@vivo.com>
Add a list to the struct dm_dev structure to store the associated
targets, while also allowing differentiation between different target
types.
Signed-off-by: Yang Yang <yang.yang@vivo.com>
---
drivers/md/dm-table.c | 36 +++++++++++++++++++++++++++++++++++
include/linux/device-mapper.h | 3 +++
2 files changed, 39 insertions(+)
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index bd68af10afed..f6554590b7af 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -741,6 +741,8 @@ int dm_table_add_target(struct dm_table *t, const char *type,
if (ti->flush_pass_around == 0)
t->flush_pass_around = 0;
+ INIT_LIST_HEAD(&ti->list);
+
return 0;
bad:
@@ -2134,6 +2136,25 @@ void dm_table_postsuspend_targets(struct dm_table *t)
suspend_targets(t, POSTSUSPEND);
}
+static int dm_link_dev_to_target(struct dm_target *ti, struct dm_dev *dev,
+ sector_t start, sector_t len, void *data)
+{
+ struct list_head *targets = &dev->targets;
+ struct dm_target *pti;
+
+ if (!list_empty(targets)) {
+ list_for_each_entry(pti, targets, list) {
+ if (pti->type == ti->type)
+ return 0;
+ }
+ }
+
+ if (list_empty(&ti->list))
+ list_add_tail(&ti->list, targets);
+
+ return 0;
+}
+
int dm_table_resume_targets(struct dm_table *t)
{
unsigned int i;
@@ -2162,6 +2183,21 @@ int dm_table_resume_targets(struct dm_table *t)
ti->type->resume(ti);
}
+ if (t->flush_pass_around) {
+ struct list_head *devices = &t->devices;
+ struct dm_dev_internal *dd;
+
+ list_for_each_entry(dd, devices, list)
+ INIT_LIST_HEAD(&dd->dm_dev->targets);
+
+ for (i = 0; i < t->num_targets; i++) {
+ struct dm_target *ti = dm_table_get_target(t, i);
+
+ if (ti->type->iterate_devices)
+ ti->type->iterate_devices(ti, dm_link_dev_to_target, NULL);
+ }
+ }
+
return 0;
}
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index 0893ff8c01b6..19e03f9b2589 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -169,6 +169,7 @@ struct dm_dev {
struct dax_device *dax_dev;
blk_mode_t mode;
char name[16];
+ struct list_head targets;
};
/*
@@ -298,6 +299,8 @@ struct dm_target {
struct dm_table *table;
struct target_type *type;
+ struct list_head list;
+
/* target limits */
sector_t begin;
sector_t len;
--
2.34.1
next prev parent reply other threads:[~2024-05-14 9:05 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-14 9:04 [PATCH 0/5] dm: empty flush optimization Yang Yang
2024-05-14 9:04 ` [PATCH 1/5] dm: introduce flush_pass_around flag Yang Yang
2024-05-14 9:04 ` [PATCH 2/5] dm: add __send_empty_flush_bios() helper Yang Yang
2024-05-14 9:04 ` Yang Yang [this message]
2024-05-15 15:42 ` [PATCH 3/5] dm: support retrieving struct dm_target from struct dm_dev Benjamin Marzinski
2024-05-15 15:53 ` Mikulas Patocka
2024-05-16 20:49 ` [PATCH] dm: optimize flushes Mikulas Patocka
2024-05-17 8:55 ` YangYang
2024-05-22 16:10 ` Mike Snitzer
2024-05-22 21:05 ` Mikulas Patocka
2024-05-23 17:46 ` [PATCH v2] " Mikulas Patocka
2024-05-23 18:02 ` Mike Snitzer
2024-05-28 11:37 ` Mikulas Patocka
2024-05-23 22:17 ` Eric Wheeler
2024-05-15 16:00 ` [PATCH 3/5] dm: support retrieving struct dm_target from struct dm_dev Benjamin Marzinski
2024-05-16 2:12 ` YangYang
2024-05-16 16:39 ` Benjamin Marzinski
2024-05-16 1:55 ` YangYang
2024-05-16 15:29 ` Benjamin Marzinski
2024-05-17 7:48 ` YangYang
2024-05-17 14:33 ` Benjamin Marzinski
2024-05-20 3:12 ` YangYang
2024-05-14 9:04 ` [PATCH 4/5] dm: Avoid sending redundant empty flush bios to the same block device Yang Yang
2024-05-14 9:04 ` [PATCH 5/5] dm linear: enable flush optimization function Yang Yang
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=20240514090445.2847-4-yang.yang@vivo.com \
--to=yang.yang@vivo.com \
--cc=agk@redhat.com \
--cc=dm-devel@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=mpatocka@redhat.com \
--cc=snitzer@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®