Skip to content

Commit 4f7f590

Browse files
yangerkunsnitm
authored andcommitted
dm dust: report some message results directly back to user
Some messages (queryblock, countbadblocks, removebadblock) are best reported directly to user directly. Do so with DMEMIT. [Bryan: maintain __func__ output in DMEMIT messages] Signed-off-by: yangerkun <[email protected]> Signed-off-by: Bryan Gurney <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent e1fef0b commit 4f7f590

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ Create the dm-dust device:
6969
$ sudo dmsetup create dust1 --table '0 33552384 dust /dev/vdb1 0 4096'
7070

7171
Check the status of the read behavior ("bypass" indicates that all I/O
72-
will be passed through to the underlying device)::
72+
will be passed through to the underlying device; "verbose" indicates that
73+
bad block additions, removals, and remaps will be verbosely logged)::
7374

7475
$ sudo dmsetup status dust1
75-
0 33552384 dust 252:17 bypass
76+
0 33552384 dust 252:17 bypass verbose
7677

7778
$ sudo dd if=/dev/mapper/dust1 of=/dev/null bs=512 count=128 iflag=direct
7879
128+0 records in
@@ -164,7 +165,7 @@ following message command::
164165
A message will print with the number of bad blocks currently
165166
configured on the device::
166167

167-
kernel: device-mapper: dust: countbadblocks: 895 badblock(s) found
168+
countbadblocks: 895 badblock(s) found
168169

169170
Querying for specific bad blocks
170171
--------------------------------
@@ -176,11 +177,11 @@ following message command::
176177

177178
The following message will print if the block is in the list::
178179

179-
device-mapper: dust: queryblock: block 72 found in badblocklist
180+
dust_query_block: block 72 found in badblocklist
180181

181182
The following message will print if the block is not in the list::
182183

183-
device-mapper: dust: queryblock: block 72 not found in badblocklist
184+
dust_query_block: block 72 not found in badblocklist
184185

185186
The "queryblock" message command will work in both the "enabled"
186187
and "disabled" modes, allowing the verification of whether a block
@@ -198,12 +199,12 @@ following message command::
198199

199200
After clearing the bad block list, the following message will appear::
200201

201-
kernel: device-mapper: dust: clearbadblocks: badblocks cleared
202+
dust_clear_badblocks: badblocks cleared
202203

203204
If there were no bad blocks to clear, the following message will
204205
appear::
205206

206-
kernel: device-mapper: dust: clearbadblocks: no badblocks found
207+
dust_clear_badblocks: no badblocks found
207208

208209
Message commands list
209210
---------------------

drivers/md/dm-dust.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,22 @@ static int dust_add_block(struct dust_device *dd, unsigned long long block,
138138
return 0;
139139
}
140140

141-
static int dust_query_block(struct dust_device *dd, unsigned long long block)
141+
static int dust_query_block(struct dust_device *dd, unsigned long long block, char *result,
142+
unsigned int maxlen, unsigned int *sz_ptr)
142143
{
143144
struct badblock *bblock;
144145
unsigned long flags;
146+
unsigned int sz = *sz_ptr;
145147

146148
spin_lock_irqsave(&dd->dust_lock, flags);
147149
bblock = dust_rb_search(&dd->badblocklist, block);
148150
if (bblock != NULL)
149-
DMINFO("%s: block %llu found in badblocklist", __func__, block);
151+
DMEMIT("%s: block %llu found in badblocklist", __func__, block);
150152
else
151-
DMINFO("%s: block %llu not found in badblocklist", __func__, block);
153+
DMEMIT("%s: block %llu not found in badblocklist", __func__, block);
152154
spin_unlock_irqrestore(&dd->dust_lock, flags);
153155

154-
return 0;
156+
return 1;
155157
}
156158

157159
static int __dust_map_read(struct dust_device *dd, sector_t thisblock)
@@ -259,11 +261,13 @@ static bool __dust_clear_badblocks(struct rb_root *tree,
259261
return true;
260262
}
261263

262-
static int dust_clear_badblocks(struct dust_device *dd)
264+
static int dust_clear_badblocks(struct dust_device *dd, char *result, unsigned int maxlen,
265+
unsigned int *sz_ptr)
263266
{
264267
unsigned long flags;
265268
struct rb_root badblocklist;
266269
unsigned long long badblock_count;
270+
unsigned int sz = *sz_ptr;
267271

268272
spin_lock_irqsave(&dd->dust_lock, flags);
269273
badblocklist = dd->badblocklist;
@@ -273,11 +277,11 @@ static int dust_clear_badblocks(struct dust_device *dd)
273277
spin_unlock_irqrestore(&dd->dust_lock, flags);
274278

275279
if (!__dust_clear_badblocks(&badblocklist, badblock_count))
276-
DMINFO("%s: no badblocks found", __func__);
280+
DMEMIT("%s: no badblocks found", __func__);
277281
else
278-
DMINFO("%s: badblocks cleared", __func__);
282+
DMEMIT("%s: badblocks cleared", __func__);
279283

280-
return 0;
284+
return 1;
281285
}
282286

283287
/*
@@ -383,7 +387,7 @@ static void dust_dtr(struct dm_target *ti)
383387
}
384388

385389
static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
386-
char *result_buf, unsigned int maxlen)
390+
char *result, unsigned int maxlen)
387391
{
388392
struct dust_device *dd = ti->private;
389393
sector_t size = i_size_read(dd->dev->bdev->bd_inode) >> SECTOR_SHIFT;
@@ -393,6 +397,7 @@ static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
393397
unsigned char wr_fail_cnt;
394398
unsigned int tmp_ui;
395399
unsigned long flags;
400+
unsigned int sz = 0;
396401
char dummy;
397402

398403
if (argc == 1) {
@@ -410,12 +415,12 @@ static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
410415
r = 0;
411416
} else if (!strcasecmp(argv[0], "countbadblocks")) {
412417
spin_lock_irqsave(&dd->dust_lock, flags);
413-
DMINFO("countbadblocks: %llu badblock(s) found",
418+
DMEMIT("countbadblocks: %llu badblock(s) found",
414419
dd->badblock_count);
415420
spin_unlock_irqrestore(&dd->dust_lock, flags);
416-
r = 0;
421+
r = 1;
417422
} else if (!strcasecmp(argv[0], "clearbadblocks")) {
418-
r = dust_clear_badblocks(dd);
423+
r = dust_clear_badblocks(dd, result, maxlen, &sz);
419424
} else if (!strcasecmp(argv[0], "quiet")) {
420425
if (!dd->quiet_mode)
421426
dd->quiet_mode = true;
@@ -441,7 +446,7 @@ static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
441446
else if (!strcasecmp(argv[0], "removebadblock"))
442447
r = dust_remove_block(dd, block);
443448
else if (!strcasecmp(argv[0], "queryblock"))
444-
r = dust_query_block(dd, block);
449+
r = dust_query_block(dd, block, result, maxlen, &sz);
445450
else
446451
invalid_msg = true;
447452

0 commit comments

Comments
 (0)