dm-dust.c (4f7f590b152444c1403ece9eeeddd1e8b22ba04e) | dm-dust.c (0c248ea27fc88cf8a3035ba0ed75b210be9abf80) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (c) 2018 Red Hat, Inc. 4 * 5 * This is a test "dust" device, which fails reads on specified 6 * sectors, emulating the behavior of a hard disk drive sending 7 * a "Read Medium Error" sense. 8 * --- 270 unchanged lines hidden (view full) --- 279 if (!__dust_clear_badblocks(&badblocklist, badblock_count)) 280 DMEMIT("%s: no badblocks found", __func__); 281 else 282 DMEMIT("%s: badblocks cleared", __func__); 283 284 return 1; 285} 286 | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (c) 2018 Red Hat, Inc. 4 * 5 * This is a test "dust" device, which fails reads on specified 6 * sectors, emulating the behavior of a hard disk drive sending 7 * a "Read Medium Error" sense. 8 * --- 270 unchanged lines hidden (view full) --- 279 if (!__dust_clear_badblocks(&badblocklist, badblock_count)) 280 DMEMIT("%s: no badblocks found", __func__); 281 else 282 DMEMIT("%s: badblocks cleared", __func__); 283 284 return 1; 285} 286 |
287static 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 |
|
287/* 288 * Target parameters: 289 * 290 * <device_path> <offset> <blksz> 291 * 292 * device_path: path to the block device 293 * offset: offset to data area from start of device_path 294 * blksz: block size (minimum 512, maximum 1073741824, must be a power of 2) --- 127 unchanged lines hidden (view full) --- 422 } else if (!strcasecmp(argv[0], "clearbadblocks")) { 423 r = dust_clear_badblocks(dd, result, maxlen, &sz); 424 } else if (!strcasecmp(argv[0], "quiet")) { 425 if (!dd->quiet_mode) 426 dd->quiet_mode = true; 427 else 428 dd->quiet_mode = false; 429 r = 0; | 312/* 313 * Target parameters: 314 * 315 * <device_path> <offset> <blksz> 316 * 317 * device_path: path to the block device 318 * offset: offset to data area from start of device_path 319 * blksz: block size (minimum 512, maximum 1073741824, must be a power of 2) --- 127 unchanged lines hidden (view full) --- 447 } else if (!strcasecmp(argv[0], "clearbadblocks")) { 448 r = dust_clear_badblocks(dd, result, maxlen, &sz); 449 } else if (!strcasecmp(argv[0], "quiet")) { 450 if (!dd->quiet_mode) 451 dd->quiet_mode = true; 452 else 453 dd->quiet_mode = false; 454 r = 0; |
455 } else if (!strcasecmp(argv[0], "listbadblocks")) { 456 r = dust_list_badblocks(dd, result, maxlen, &sz); |
|
430 } else { 431 invalid_msg = true; 432 } 433 } else if (argc == 2) { 434 if (sscanf(argv[1], "%llu%c", &tmp, &dummy) != 1) 435 return r; 436 437 block = tmp; --- 127 unchanged lines hidden --- | 457 } else { 458 invalid_msg = true; 459 } 460 } else if (argc == 2) { 461 if (sscanf(argv[1], "%llu%c", &tmp, &dummy) != 1) 462 return r; 463 464 block = tmp; --- 127 unchanged lines hidden --- |