diff options
author | Joel Becker <joel.becker@oracle.com> | 2009-01-06 17:57:08 -0500 |
---|---|---|
committer | Joel Becker <joel.becker@oracle.com> | 2009-06-03 22:15:36 -0400 |
commit | 73be192b17e43b6dc4f492dab41d70ab5b9d2908 (patch) | |
tree | 9482070421cda81f490036b28033d4f300a58a94 /fs/ocfs2/blockcheck.c | |
parent | 15633a220ffe74fc61bc8117e6a89a494011ea3d (diff) |
ocfs2: Add statistics for the checksum and ecc operations.
It would be nice to know how often we get checksum failures. Even
better, how many of them we can fix with the single bit ecc. So, we add
a statistics structure. The structure can be installed into debugfs
wherever the user wants.
For ocfs2, we'll put it in the superblock-specific debugfs directory and
pass it down from our higher-level functions. The stats are only
registered with debugfs when the filesystem supports metadata ecc.
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Diffstat (limited to 'fs/ocfs2/blockcheck.c')
-rw-r--r-- | fs/ocfs2/blockcheck.c | 184 |
1 files changed, 176 insertions, 8 deletions
diff --git a/fs/ocfs2/blockcheck.c b/fs/ocfs2/blockcheck.c index 2a947c44e594..a1163b8b417c 100644 --- a/fs/ocfs2/blockcheck.c +++ b/fs/ocfs2/blockcheck.c | |||
@@ -22,6 +22,9 @@ | |||
22 | #include <linux/crc32.h> | 22 | #include <linux/crc32.h> |
23 | #include <linux/buffer_head.h> | 23 | #include <linux/buffer_head.h> |
24 | #include <linux/bitops.h> | 24 | #include <linux/bitops.h> |
25 | #include <linux/debugfs.h> | ||
26 | #include <linux/module.h> | ||
27 | #include <linux/fs.h> | ||
25 | #include <asm/byteorder.h> | 28 | #include <asm/byteorder.h> |
26 | 29 | ||
27 | #include <cluster/masklog.h> | 30 | #include <cluster/masklog.h> |
@@ -222,6 +225,155 @@ void ocfs2_hamming_fix_block(void *data, unsigned int blocksize, | |||
222 | ocfs2_hamming_fix(data, blocksize * 8, 0, fix); | 225 | ocfs2_hamming_fix(data, blocksize * 8, 0, fix); |
223 | } | 226 | } |
224 | 227 | ||
228 | |||
229 | /* | ||
230 | * Debugfs handling. | ||
231 | */ | ||
232 | |||
233 | #ifdef CONFIG_DEBUG_FS | ||
234 | |||
235 | static int blockcheck_u64_get(void *data, u64 *val) | ||
236 | { | ||
237 | *val = *(u64 *)data; | ||
238 | return 0; | ||
239 | } | ||
240 | DEFINE_SIMPLE_ATTRIBUTE(blockcheck_fops, blockcheck_u64_get, NULL, "%llu\n"); | ||
241 | |||
242 | static struct dentry *blockcheck_debugfs_create(const char *name, | ||
243 | struct dentry *parent, | ||
244 | u64 *value) | ||
245 | { | ||
246 | return debugfs_create_file(name, S_IFREG | S_IRUSR, parent, value, | ||
247 | &blockcheck_fops); | ||
248 | } | ||
249 | |||
250 | static void ocfs2_blockcheck_debug_remove(struct ocfs2_blockcheck_stats *stats) | ||
251 | { | ||
252 | if (stats) { | ||
253 | debugfs_remove(stats->b_debug_check); | ||
254 | stats->b_debug_check = NULL; | ||
255 | debugfs_remove(stats->b_debug_failure); | ||
256 | stats->b_debug_failure = NULL; | ||
257 | debugfs_remove(stats->b_debug_recover); | ||
258 | stats->b_debug_recover = NULL; | ||
259 | debugfs_remove(stats->b_debug_dir); | ||
260 | stats->b_debug_dir = NULL; | ||
261 | } | ||
262 | } | ||
263 | |||
264 | static int ocfs2_blockcheck_debug_install(struct ocfs2_blockcheck_stats *stats, | ||
265 | struct dentry *parent) | ||
266 | { | ||
267 | int rc = -EINVAL; | ||
268 | |||
269 | if (!stats) | ||
270 | goto out; | ||
271 | |||
272 | stats->b_debug_dir = debugfs_create_dir("blockcheck", parent); | ||
273 | if (!stats->b_debug_dir) | ||
274 | goto out; | ||
275 | |||
276 | stats->b_debug_check = | ||
277 | blockcheck_debugfs_create("blocks_checked", | ||
278 | stats->b_debug_dir, | ||
279 | &stats->b_check_count); | ||
280 | |||
281 | stats->b_debug_failure = | ||
282 | blockcheck_debugfs_create("checksums_failed", | ||
283 | stats->b_debug_dir, | ||
284 | &stats->b_failure_count); | ||
285 | |||
286 | stats->b_debug_recover = | ||
287 | blockcheck_debugfs_create("ecc_recoveries", | ||
288 | stats->b_debug_dir, | ||
289 | &stats->b_recover_count); | ||
290 | if (stats->b_debug_check && stats->b_debug_failure && | ||
291 | stats->b_debug_recover) | ||
292 | rc = 0; | ||
293 | |||
294 | out: | ||
295 | if (rc) | ||
296 | ocfs2_blockcheck_debug_remove(stats); | ||
297 | return rc; | ||
298 | } | ||
299 | #else | ||
300 | static inline int ocfs2_blockcheck_debug_install(struct ocfs2_blockcheck_stats *stats, | ||
301 | struct dentry *parent) | ||
302 | { | ||
303 | return 0; | ||
304 | } | ||
305 | |||
306 | static inline void ocfs2_blockcheck_debug_remove(struct ocfs2_blockcheck_stats *stats) | ||
307 | { | ||
308 | } | ||
309 | #endif /* CONFIG_DEBUG_FS */ | ||
310 | |||
311 | /* Always-called wrappers for starting and stopping the debugfs files */ | ||
312 | int ocfs2_blockcheck_stats_debugfs_install(struct ocfs2_blockcheck_stats *stats, | ||
313 | struct dentry *parent) | ||
314 | { | ||
315 | return ocfs2_blockcheck_debug_install(stats, parent); | ||
316 | } | ||
317 | |||
318 | void ocfs2_blockcheck_stats_debugfs_remove(struct ocfs2_blockcheck_stats *stats) | ||
319 | { | ||
320 | ocfs2_blockcheck_debug_remove(stats); | ||
321 | } | ||
322 | |||
323 | static void ocfs2_blockcheck_inc_check(struct ocfs2_blockcheck_stats *stats) | ||
324 | { | ||
325 | u64 new_count; | ||
326 | |||
327 | if (!stats) | ||
328 | return; | ||
329 | |||
330 | spin_lock(&stats->b_lock); | ||
331 | stats->b_check_count++; | ||
332 | new_count = stats->b_check_count; | ||
333 | spin_unlock(&stats->b_lock); | ||
334 | |||
335 | if (!new_count) | ||
336 | mlog(ML_NOTICE, "Block check count has wrapped\n"); | ||
337 | } | ||
338 | |||
339 | static void ocfs2_blockcheck_inc_failure(struct ocfs2_blockcheck_stats *stats) | ||
340 | { | ||
341 | u64 new_count; | ||
342 | |||
343 | if (!stats) | ||
344 | return; | ||
345 | |||
346 | spin_lock(&stats->b_lock); | ||
347 | stats->b_failure_count++; | ||
348 | new_count = stats->b_failure_count; | ||
349 | spin_unlock(&stats->b_lock); | ||
350 | |||
351 | if (!new_count) | ||
352 | mlog(ML_NOTICE, "Checksum failure count has wrapped\n"); | ||
353 | } | ||
354 | |||
355 | static void ocfs2_blockcheck_inc_recover(struct ocfs2_blockcheck_stats *stats) | ||
356 | { | ||
357 | u64 new_count; | ||
358 | |||
359 | if (!stats) | ||
360 | return; | ||
361 | |||
362 | spin_lock(&stats->b_lock); | ||
363 | stats->b_recover_count++; | ||
364 | new_count = stats->b_recover_count; | ||
365 | spin_unlock(&stats->b_lock); | ||
366 | |||
367 | if (!new_count) | ||
368 | mlog(ML_NOTICE, "ECC recovery count has wrapped\n"); | ||
369 | } | ||
370 | |||
371 | |||
372 | |||
373 | /* | ||
374 | * These are the low-level APIs for using the ocfs2_block_check structure. | ||
375 | */ | ||
376 | |||
225 | /* | 377 | /* |
226 | * This function generates check information for a block. | 378 | * This function generates check information for a block. |
227 | * data is the block to be checked. bc is a pointer to the | 379 | * data is the block to be checked. bc is a pointer to the |
@@ -266,12 +418,15 @@ void ocfs2_block_check_compute(void *data, size_t blocksize, | |||
266 | * Again, the data passed in should be the on-disk endian. | 418 | * Again, the data passed in should be the on-disk endian. |
267 | */ | 419 | */ |
268 | int ocfs2_block_check_validate(void *data, size_t blocksize, | 420 | int ocfs2_block_check_validate(void *data, size_t blocksize, |
269 | struct ocfs2_block_check *bc) | 421 | struct ocfs2_block_check *bc, |
422 | struct ocfs2_blockcheck_stats *stats) | ||
270 | { | 423 | { |
271 | int rc = 0; | 424 | int rc = 0; |
272 | struct ocfs2_block_check check; | 425 | struct ocfs2_block_check check; |
273 | u32 crc, ecc; | 426 | u32 crc, ecc; |
274 | 427 | ||
428 | ocfs2_blockcheck_inc_check(stats); | ||
429 | |||
275 | check.bc_crc32e = le32_to_cpu(bc->bc_crc32e); | 430 | check.bc_crc32e = le32_to_cpu(bc->bc_crc32e); |
276 | check.bc_ecc = le16_to_cpu(bc->bc_ecc); | 431 | check.bc_ecc = le16_to_cpu(bc->bc_ecc); |
277 | 432 | ||
@@ -282,6 +437,7 @@ int ocfs2_block_check_validate(void *data, size_t blocksize, | |||
282 | if (crc == check.bc_crc32e) | 437 | if (crc == check.bc_crc32e) |
283 | goto out; | 438 | goto out; |
284 | 439 | ||
440 | ocfs2_blockcheck_inc_failure(stats); | ||
285 | mlog(ML_ERROR, | 441 | mlog(ML_ERROR, |
286 | "CRC32 failed: stored: %u, computed %u. Applying ECC.\n", | 442 | "CRC32 failed: stored: %u, computed %u. Applying ECC.\n", |
287 | (unsigned int)check.bc_crc32e, (unsigned int)crc); | 443 | (unsigned int)check.bc_crc32e, (unsigned int)crc); |
@@ -292,8 +448,10 @@ int ocfs2_block_check_validate(void *data, size_t blocksize, | |||
292 | 448 | ||
293 | /* And check the crc32 again */ | 449 | /* And check the crc32 again */ |
294 | crc = crc32_le(~0, data, blocksize); | 450 | crc = crc32_le(~0, data, blocksize); |
295 | if (crc == check.bc_crc32e) | 451 | if (crc == check.bc_crc32e) { |
452 | ocfs2_blockcheck_inc_recover(stats); | ||
296 | goto out; | 453 | goto out; |
454 | } | ||
297 | 455 | ||
298 | mlog(ML_ERROR, "Fixed CRC32 failed: stored: %u, computed %u\n", | 456 | mlog(ML_ERROR, "Fixed CRC32 failed: stored: %u, computed %u\n", |
299 | (unsigned int)check.bc_crc32e, (unsigned int)crc); | 457 | (unsigned int)check.bc_crc32e, (unsigned int)crc); |
@@ -366,7 +524,8 @@ void ocfs2_block_check_compute_bhs(struct buffer_head **bhs, int nr, | |||
366 | * Again, the data passed in should be the on-disk endian. | 524 | * Again, the data passed in should be the on-disk endian. |
367 | */ | 525 | */ |
368 | int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr, | 526 | int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr, |
369 | struct ocfs2_block_check *bc) | 527 | struct ocfs2_block_check *bc, |
528 | struct ocfs2_blockcheck_stats *stats) | ||
370 | { | 529 | { |
371 | int i, rc = 0; | 530 | int i, rc = 0; |
372 | struct ocfs2_block_check check; | 531 | struct ocfs2_block_check check; |
@@ -377,6 +536,8 @@ int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr, | |||
377 | if (!nr) | 536 | if (!nr) |
378 | return 0; | 537 | return 0; |
379 | 538 | ||
539 | ocfs2_blockcheck_inc_check(stats); | ||
540 | |||
380 | check.bc_crc32e = le32_to_cpu(bc->bc_crc32e); | 541 | check.bc_crc32e = le32_to_cpu(bc->bc_crc32e); |
381 | check.bc_ecc = le16_to_cpu(bc->bc_ecc); | 542 | check.bc_ecc = le16_to_cpu(bc->bc_ecc); |
382 | 543 | ||
@@ -388,6 +549,7 @@ int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr, | |||
388 | if (crc == check.bc_crc32e) | 549 | if (crc == check.bc_crc32e) |
389 | goto out; | 550 | goto out; |
390 | 551 | ||
552 | ocfs2_blockcheck_inc_failure(stats); | ||
391 | mlog(ML_ERROR, | 553 | mlog(ML_ERROR, |
392 | "CRC32 failed: stored: %u, computed %u. Applying ECC.\n", | 554 | "CRC32 failed: stored: %u, computed %u. Applying ECC.\n", |
393 | (unsigned int)check.bc_crc32e, (unsigned int)crc); | 555 | (unsigned int)check.bc_crc32e, (unsigned int)crc); |
@@ -416,8 +578,10 @@ int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr, | |||
416 | /* And check the crc32 again */ | 578 | /* And check the crc32 again */ |
417 | for (i = 0, crc = ~0; i < nr; i++) | 579 | for (i = 0, crc = ~0; i < nr; i++) |
418 | crc = crc32_le(crc, bhs[i]->b_data, bhs[i]->b_size); | 580 | crc = crc32_le(crc, bhs[i]->b_data, bhs[i]->b_size); |
419 | if (crc == check.bc_crc32e) | 581 | if (crc == check.bc_crc32e) { |
582 | ocfs2_blockcheck_inc_recover(stats); | ||
420 | goto out; | 583 | goto out; |
584 | } | ||
421 | 585 | ||
422 | mlog(ML_ERROR, "Fixed CRC32 failed: stored: %u, computed %u\n", | 586 | mlog(ML_ERROR, "Fixed CRC32 failed: stored: %u, computed %u\n", |
423 | (unsigned int)check.bc_crc32e, (unsigned int)crc); | 587 | (unsigned int)check.bc_crc32e, (unsigned int)crc); |
@@ -448,9 +612,11 @@ int ocfs2_validate_meta_ecc(struct super_block *sb, void *data, | |||
448 | struct ocfs2_block_check *bc) | 612 | struct ocfs2_block_check *bc) |
449 | { | 613 | { |
450 | int rc = 0; | 614 | int rc = 0; |
615 | struct ocfs2_super *osb = OCFS2_SB(sb); | ||
451 | 616 | ||
452 | if (ocfs2_meta_ecc(OCFS2_SB(sb))) | 617 | if (ocfs2_meta_ecc(osb)) |
453 | rc = ocfs2_block_check_validate(data, sb->s_blocksize, bc); | 618 | rc = ocfs2_block_check_validate(data, sb->s_blocksize, bc, |
619 | &osb->osb_ecc_stats); | ||
454 | 620 | ||
455 | return rc; | 621 | return rc; |
456 | } | 622 | } |
@@ -468,9 +634,11 @@ int ocfs2_validate_meta_ecc_bhs(struct super_block *sb, | |||
468 | struct ocfs2_block_check *bc) | 634 | struct ocfs2_block_check *bc) |
469 | { | 635 | { |
470 | int rc = 0; | 636 | int rc = 0; |
637 | struct ocfs2_super *osb = OCFS2_SB(sb); | ||
471 | 638 | ||
472 | if (ocfs2_meta_ecc(OCFS2_SB(sb))) | 639 | if (ocfs2_meta_ecc(osb)) |
473 | rc = ocfs2_block_check_validate_bhs(bhs, nr, bc); | 640 | rc = ocfs2_block_check_validate_bhs(bhs, nr, bc, |
641 | &osb->osb_ecc_stats); | ||
474 | 642 | ||
475 | return rc; | 643 | return rc; |
476 | } | 644 | } |