Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <yangerkun@huawei.com>
Signed-off-by: Bryan Gurney <bgurney@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>

authored by

yangerkun and committed by
Mike Snitzer
4f7f590b e1fef0b0

+26 -20
+8 -7
Documentation/admin-guide/device-mapper/dm-dust.rst
··· 69 69 $ sudo dmsetup create dust1 --table '0 33552384 dust /dev/vdb1 0 4096' 70 70 71 71 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):: 73 74 74 75 $ sudo dmsetup status dust1 75 - 0 33552384 dust 252:17 bypass 76 + 0 33552384 dust 252:17 bypass verbose 76 77 77 78 $ sudo dd if=/dev/mapper/dust1 of=/dev/null bs=512 count=128 iflag=direct 78 79 128+0 records in ··· 165 164 A message will print with the number of bad blocks currently 166 165 configured on the device:: 167 166 168 - kernel: device-mapper: dust: countbadblocks: 895 badblock(s) found 167 + countbadblocks: 895 badblock(s) found 169 168 170 169 Querying for specific bad blocks 171 170 -------------------------------- ··· 177 176 178 177 The following message will print if the block is in the list:: 179 178 180 - device-mapper: dust: queryblock: block 72 found in badblocklist 179 + dust_query_block: block 72 found in badblocklist 181 180 182 181 The following message will print if the block is not in the list:: 183 182 184 - device-mapper: dust: queryblock: block 72 not found in badblocklist 183 + dust_query_block: block 72 not found in badblocklist 185 184 186 185 The "queryblock" message command will work in both the "enabled" 187 186 and "disabled" modes, allowing the verification of whether a block ··· 199 198 200 199 After clearing the bad block list, the following message will appear:: 201 200 202 - kernel: device-mapper: dust: clearbadblocks: badblocks cleared 201 + dust_clear_badblocks: badblocks cleared 203 202 204 203 If there were no bad blocks to clear, the following message will 205 204 appear:: 206 205 207 - kernel: device-mapper: dust: clearbadblocks: no badblocks found 206 + dust_clear_badblocks: no badblocks found 208 207 209 208 Message commands list 210 209 ---------------------
+18 -13
drivers/md/dm-dust.c
··· 138 138 return 0; 139 139 } 140 140 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) 142 143 { 143 144 struct badblock *bblock; 144 145 unsigned long flags; 146 + unsigned int sz = *sz_ptr; 145 147 146 148 spin_lock_irqsave(&dd->dust_lock, flags); 147 149 bblock = dust_rb_search(&dd->badblocklist, block); 148 150 if (bblock != NULL) 149 - DMINFO("%s: block %llu found in badblocklist", __func__, block); 151 + DMEMIT("%s: block %llu found in badblocklist", __func__, block); 150 152 else 151 - DMINFO("%s: block %llu not found in badblocklist", __func__, block); 153 + DMEMIT("%s: block %llu not found in badblocklist", __func__, block); 152 154 spin_unlock_irqrestore(&dd->dust_lock, flags); 153 155 154 - return 0; 156 + return 1; 155 157 } 156 158 157 159 static int __dust_map_read(struct dust_device *dd, sector_t thisblock) ··· 261 259 return true; 262 260 } 263 261 264 - static int dust_clear_badblocks(struct dust_device *dd) 262 + static int dust_clear_badblocks(struct dust_device *dd, char *result, unsigned int maxlen, 263 + unsigned int *sz_ptr) 265 264 { 266 265 unsigned long flags; 267 266 struct rb_root badblocklist; 268 267 unsigned long long badblock_count; 268 + unsigned int sz = *sz_ptr; 269 269 270 270 spin_lock_irqsave(&dd->dust_lock, flags); 271 271 badblocklist = dd->badblocklist; ··· 277 273 spin_unlock_irqrestore(&dd->dust_lock, flags); 278 274 279 275 if (!__dust_clear_badblocks(&badblocklist, badblock_count)) 280 - DMINFO("%s: no badblocks found", __func__); 276 + DMEMIT("%s: no badblocks found", __func__); 281 277 else 282 - DMINFO("%s: badblocks cleared", __func__); 278 + DMEMIT("%s: badblocks cleared", __func__); 283 279 284 - return 0; 280 + return 1; 285 281 } 286 282 287 283 /* ··· 387 383 } 388 384 389 385 static int dust_message(struct dm_target *ti, unsigned int argc, char **argv, 390 - char *result_buf, unsigned int maxlen) 386 + char *result, unsigned int maxlen) 391 387 { 392 388 struct dust_device *dd = ti->private; 393 389 sector_t size = i_size_read(dd->dev->bdev->bd_inode) >> SECTOR_SHIFT; ··· 397 393 unsigned char wr_fail_cnt; 398 394 unsigned int tmp_ui; 399 395 unsigned long flags; 396 + unsigned int sz = 0; 400 397 char dummy; 401 398 402 399 if (argc == 1) { ··· 415 410 r = 0; 416 411 } else if (!strcasecmp(argv[0], "countbadblocks")) { 417 412 spin_lock_irqsave(&dd->dust_lock, flags); 418 - DMINFO("countbadblocks: %llu badblock(s) found", 413 + DMEMIT("countbadblocks: %llu badblock(s) found", 419 414 dd->badblock_count); 420 415 spin_unlock_irqrestore(&dd->dust_lock, flags); 421 - r = 0; 416 + r = 1; 422 417 } else if (!strcasecmp(argv[0], "clearbadblocks")) { 423 - r = dust_clear_badblocks(dd); 418 + r = dust_clear_badblocks(dd, result, maxlen, &sz); 424 419 } else if (!strcasecmp(argv[0], "quiet")) { 425 420 if (!dd->quiet_mode) 426 421 dd->quiet_mode = true; ··· 446 441 else if (!strcasecmp(argv[0], "removebadblock")) 447 442 r = dust_remove_block(dd, block); 448 443 else if (!strcasecmp(argv[0], "queryblock")) 449 - r = dust_query_block(dd, block); 444 + r = dust_query_block(dd, block, result, maxlen, &sz); 450 445 else 451 446 invalid_msg = true; 452 447