Skip to contentSkip to conversation

introduce interface to list all badblocks

PATCH Superseded yangerkun 3 participants 7 messages Jun 8, 2020 – Jun 16, 2020

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

yangerkun

author
#0 lore raw

cover introduce interface to list all badblocks

We can add/remove/query the badblocks, but no interface to list all badblocks when we want to know the badblocks we ever set still available. Add message listbadblocks to do this.

To list all bad blocks in the bad block list, run the following message command:

    $ sudo dmsetup message dust1 0 listbadblocks

The following message will appear, listing one bad block number per line (using an example device with blocks 1 and 2 in the bad block list):

device-mapper: dust: dust_list_badblocks: badblocks list below:
device-mapper: dust: bad block: 1
device-mapper: dust: bad block: 2
device-mapper: dust: dust_list_badblocks: badblocks list end.

yangerkun (2):
dm dust: add interface to list all badblocks
dm dust: introduce listbadblocks in the rst

 .../admin-guide/device-mapper/dm-dust.rst     | 18 ++++++++++++++++
 drivers/md/dm-dust.c                          | 21 +++++++++++++++++++
 2 files changed, 39 insertions(+)
Signature · 1 line
2.23.0.rc2.8.gff66981f45
author
#1 lore raw

PATCH 1/2 dm dust: add interface to list all badblocks

This interface may help anyone want to know all badblocks without query block one by one.

---
 drivers/md/dm-dust.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/md/dm-dust.c +21 -0
index ff03b90072c5..da5c10605c59 100644
@@ -280,6 +280,24 @@ static int dust_clear_badblocks(struct dust_device *dd)
 	return 0;
 }
 
+static void dust_list_badblocks(struct dust_device *dd)
+{
+	unsigned long flags;
+	struct rb_root badblocklist;
+	struct rb_node *node;
+	struct badblock *bblk;
+
+	DMINFO("%s: badblocks list below:", __func__);
+	spin_lock_irqsave(&dd->dust_lock, flags);
+	badblocklist = dd->badblocklist;
+	for (node = rb_first(&badblocklist); node; node = rb_next(node)) {
+		bblk = rb_entry(node, struct badblock, node);
+		DMINFO("bad block: %llu", bblk->bb);
+	}
+	spin_unlock_irqrestore(&dd->dust_lock, flags);
+	DMINFO("%s: badblocks list end.", __func__);
+}
+
 /*
  * Target parameters:
  *
@@ -422,6 +440,9 @@ static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
 			else
 				dd->quiet_mode = false;
 			r = 0;
+		} else if (!strcasecmp(argv[0], "listbadblocks")) {
+			dust_list_badblocks(dd);
+			r = 0;
 		} else {
 			invalid_msg = true;
 		}
Signature · 1 line
2.23.0.rc2.8.gff66981f45
author
#2 lore raw

PATCH 2/2 dm dust: introduce listbadblocks in the rst

In reply to yangerkun

Since we support the listbadblocks command, introduce the detail in the doc.

---
 .../admin-guide/device-mapper/dm-dust.rst      | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
Documentation/admin-guide/device-mapper/dm-dust.rst +18 -0
index b6e7e7ead831..2c51a4acb8be 100644
@@ -205,6 +205,23 @@ appear::
 
         kernel: device-mapper: dust: clearbadblocks: no badblocks found
 
+Listing the bad block list
+--------------------------
+
+To list all bad blocks in the bad block list, run the following message
+command::
+
+        $ sudo dmsetup message dust1 0 listbadblocks
+
+The following message will appear, listing one bad block number per
+line (using an example device with blocks 1 and 2 in the bad block
+list)::
+
+        device-mapper: dust: dust_list_badblocks: badblocks list below:
+        device-mapper: dust: bad block: 1
+        device-mapper: dust: bad block: 2
+        device-mapper: dust: dust_list_badblocks: badblocks list end.
+
 Message commands list
 ---------------------
 
@@ -223,6 +240,7 @@ Single argument message commands::
 
         countbadblocks
         clearbadblocks
+        listbadblocks
         disable
         enable
         quiet
Signature · 1 line
2.23.0.rc2.8.gff66981f45
author
#3 lore raw
In reply to yangerkun

Hi,

Sorry for not send to Mike. Can you consider to apply this patchset?

Thanks,
Kun.

Quoted 19 lines · yangerkun

We can add/remove/query the badblocks, but no interface to list all badblocks when we want to know the badblocks we ever set still available. Add message listbadblocks to do this.

To list all bad blocks in the bad block list, run the following message command:

     $ sudo dmsetup message dust1 0 listbadblocks

The following message will appear, listing one bad block number per line (using an example device with blocks 1 and 2 in the bad block list):

device-mapper: dust: dust_list_badblocks: badblocks list below:
device-mapper: dust: bad block: 1
device-mapper: dust: bad block: 2
device-mapper: dust: dust_list_badblocks: badblocks list end.

Quoted 8 lines

yangerkun (2):
dm dust: add interface to list all badblocks
dm dust: introduce listbadblocks in the rst

  .../admin-guide/device-mapper/dm-dust.rst     | 18 ++++++++++++++++
  drivers/md/dm-dust.c                          | 21 +++++++++++++++++++
  2 files changed, 39 insertions(+)

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel

#4 lore raw
In reply to yangerkun
Quoted 2 lines · yangerkun
    $ sudo dmsetup message dust1 0 listbadblocks
The following message will appear, listing one bad block number per

Did you consider returning the data directly to the caller so it can be accessed directly?

(e.g. like @stats_list handled in dm-stats.c)

Alasdair

#5 lore raw
Quoted 8 lines · Alasdair G Kergon
Quoted 2 lines · yangerkun
    $ sudo dmsetup message dust1 0 listbadblocks
The following message will appear, listing one bad block number per

Did you consider returning the data directly to the caller so it can be accessed directly?

(e.g. like @stats_list handled in dm-stats.c)

Having this returned in the message response would certainly be more natural and would simplify parsing the data: sending it to the log seems like it would allow log lines from distinct devices to become interleaved when the lists are long and the message is sent to two or more devices near simultaneously. Without something to identify the devices in each message you can't distinguish them.

Even with large numbers of bad blocks userspace libdevmapper will automatically handle re-trying with a larger buffer if the list is too big for the default.

We use (sometimes very large) message replies heavily in libdm-stats.

device-mapper.h provides the DMEMIT macro to output message replies. See dm_stats_print() or various target status() functions for examples.

Regards,
Bryn.

author
#6 lore raw
Quoted 21 lines · Bryn M. Reeves
Quoted 8 lines · Alasdair G Kergon
Quoted 2 lines · yangerkun
     $ sudo dmsetup message dust1 0 listbadblocks
The following message will appear, listing one bad block number per

Did you consider returning the data directly to the caller so it can be accessed directly?

(e.g. like @stats_list handled in dm-stats.c)

Having this returned in the message response would certainly be more natural and would simplify parsing the data: sending it to the log seems like it would allow log lines from distinct devices to become interleaved when the lists are long and the message is sent to two or more devices near simultaneously. Without something to identify the devices in each message you can't distinguish them.

Even with large numbers of bad blocks userspace libdevmapper will automatically handle re-trying with a larger buffer if the list is too big for the default.

Quoted 9 lines

We use (sometimes very large) message replies heavily in libdm-stats.

device-mapper.h provides the DMEMIT macro to output message replies. See dm_stats_print() or various target status() functions for examples.

Regards,
Bryn.

Hi,

Thanks for your reply! I will read this code and consider to realize it!

Thanks,
Kun.

Quoted 3 lines

.

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel