diff mbox series

[RFC,1/2] dm dust: add interface to list all badblocks

Message ID 20200605073201.1742675-2-yangerkun@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: Mike Snitzer
Headers show
Series introduce interface to list all badblocks | expand

Commit Message

yangerkun June 5, 2020, 7:32 a.m. UTC
This interface may help anyone want to know all badblocks without query
block one by one.

Signed-off-by: yangerkun <yangerkun@huawei.com>
---
 drivers/md/dm-dust.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Comments

Bryan Gurney June 5, 2020, 7:47 p.m. UTC | #1
On Fri, Jun 5, 2020 at 3:48 AM yangerkun <yangerkun@huawei.com> wrote:
>
> This interface may help anyone want to know all badblocks without query
> block one by one.
>
> Signed-off-by: yangerkun <yangerkun@huawei.com>
> ---
>  drivers/md/dm-dust.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
>
> diff --git a/drivers/md/dm-dust.c b/drivers/md/dm-dust.c
> index ff03b90072c5..903c0d158c6e 100644
> --- a/drivers/md/dm-dust.c
> +++ b/drivers/md/dm-dust.c
> @@ -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 as 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;
>                 }
> --
> 2.25.4
>

I tested this, and it looks good.

I see that the message says "badblocks list as below"; I'm wondering
if that was meant to say "badblocks list is below".  Or perhaps it
might be better to say "badblocks list below".

Aside from that potential correction,

Reviewed-by: Bryan Gurney <bgurney@redhat.com>


Thanks,

Bryan

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
diff mbox series

Patch

diff --git a/drivers/md/dm-dust.c b/drivers/md/dm-dust.c
index ff03b90072c5..903c0d158c6e 100644
--- a/drivers/md/dm-dust.c
+++ b/drivers/md/dm-dust.c
@@ -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 as 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;
 		}