Skip to content

Commit 0c248ea

Browse files
yangerkunsnitm
authored andcommitted
dm dust: add interface to list all badblocks
This interface may help anyone who want to know all badblocks without querying for each block. [Bryan: DMEMIT message if no blocks are in the bad block list.] Signed-off-by: yangerkun <[email protected]> Signed-off-by: Bryan Gurney <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent 4f7f590 commit 0c248ea

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

Documentation/admin-guide/device-mapper/dm-dust.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,22 @@ appear::
206206

207207
dust_clear_badblocks: no badblocks found
208208

209+
Listing the bad block list
210+
--------------------------
211+
212+
To list all bad blocks in the bad block list (using an example device
213+
with blocks 1 and 2 in the bad block list), run the following message
214+
command::
215+
216+
$ sudo dmsetup message dust1 0 listbadblocks
217+
1
218+
2
219+
220+
If there are no bad blocks in the bad block list, the command will
221+
execute with no output::
222+
223+
$ sudo dmsetup message dust1 0 listbadblocks
224+
209225
Message commands list
210226
---------------------
211227

@@ -224,6 +240,7 @@ Single argument message commands::
224240

225241
countbadblocks
226242
clearbadblocks
243+
listbadblocks
227244
disable
228245
enable
229246
quiet

drivers/md/dm-dust.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,31 @@ static int dust_clear_badblocks(struct dust_device *dd, char *result, unsigned i
284284
return 1;
285285
}
286286

287+
static int dust_list_badblocks(struct dust_device *dd, char *result, unsigned int maxlen,
288+
unsigned int *sz_ptr)
289+
{
290+
unsigned long flags;
291+
struct rb_root badblocklist;
292+
struct rb_node *node;
293+
struct badblock *bblk;
294+
unsigned int sz = *sz_ptr;
295+
unsigned long long num = 0;
296+
297+
spin_lock_irqsave(&dd->dust_lock, flags);
298+
badblocklist = dd->badblocklist;
299+
for (node = rb_first(&badblocklist); node; node = rb_next(node)) {
300+
bblk = rb_entry(node, struct badblock, node);
301+
DMEMIT("%llu\n", bblk->bb);
302+
num++;
303+
}
304+
305+
spin_unlock_irqrestore(&dd->dust_lock, flags);
306+
if (!num)
307+
DMEMIT("No blocks in badblocklist");
308+
309+
return 1;
310+
}
311+
287312
/*
288313
* Target parameters:
289314
*
@@ -427,6 +452,8 @@ static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
427452
else
428453
dd->quiet_mode = false;
429454
r = 0;
455+
} else if (!strcasecmp(argv[0], "listbadblocks")) {
456+
r = dust_list_badblocks(dd, result, maxlen, &sz);
430457
} else {
431458
invalid_msg = true;
432459
}

0 commit comments

Comments
 (0)