From 4b576a8e0eb99ec1a79ca432350fb7ac27a5c089 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 26 Jul 2021 11:59:43 +0100 Subject: [PATCH] cache: Reduce verbosity of debugging The cache filter is very verbose in its debugging. Reduce the default level. Use -D cache.verbose=1 to restore original debugging. Compare commit 745a0f13662031c2b9c9b69f62b4ae3a6b2f38f0. (cherry picked from commit 6be735edf7d5fb3fb8350c72e6d9525badbab14d) --- filters/cache/blk.c | 53 +++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/filters/cache/blk.c b/filters/cache/blk.c index 12e8407e..f52f30e3 100644 --- a/filters/cache/blk.c +++ b/filters/cache/blk.c @@ -93,6 +93,9 @@ enum bm_entry { BLOCK_DIRTY = 3, }; +/* Extra debugging (-D cache.verbose=1). */ +NBDKIT_DLL_PUBLIC int cache_debug_verbose = 0; + int blk_init (void) { @@ -199,12 +202,14 @@ blk_read (nbdkit_next *next, reclaim (fd, &bm); - nbdkit_debug ("cache: blk_read block %" PRIu64 " (offset %" PRIu64 ") is %s", - blknum, (uint64_t) offset, - state == BLOCK_NOT_CACHED ? "not cached" : - state == BLOCK_CLEAN ? "clean" : - state == BLOCK_DIRTY ? "dirty" : - "unknown"); + if (cache_debug_verbose) + nbdkit_debug ("cache: blk_read block %" PRIu64 + " (offset %" PRIu64 ") is %s", + blknum, (uint64_t) offset, + state == BLOCK_NOT_CACHED ? "not cached" : + state == BLOCK_CLEAN ? "clean" : + state == BLOCK_DIRTY ? "dirty" : + "unknown"); if (state == BLOCK_NOT_CACHED) { /* Read underlying plugin. */ unsigned n = blksize, tail = 0; @@ -225,9 +230,10 @@ blk_read (nbdkit_next *next, /* If cache-on-read, copy the block to the cache. */ if (cache_on_read) { - nbdkit_debug ("cache: cache-on-read block %" PRIu64 - " (offset %" PRIu64 ")", - blknum, (uint64_t) offset); + if (cache_debug_verbose) + nbdkit_debug ("cache: cache-on-read block %" PRIu64 + " (offset %" PRIu64 ")", + blknum, (uint64_t) offset); if (pwrite (fd, block, blksize, offset) == -1) { *err = errno; @@ -259,12 +265,14 @@ blk_cache (nbdkit_next *next, reclaim (fd, &bm); - nbdkit_debug ("cache: blk_cache block %" PRIu64 " (offset %" PRIu64 ") is %s", - blknum, (uint64_t) offset, - state == BLOCK_NOT_CACHED ? "not cached" : - state == BLOCK_CLEAN ? "clean" : - state == BLOCK_DIRTY ? "dirty" : - "unknown"); + if (cache_debug_verbose) + nbdkit_debug ("cache: blk_cache block %" PRIu64 + " (offset %" PRIu64 ") is %s", + blknum, (uint64_t) offset, + state == BLOCK_NOT_CACHED ? "not cached" : + state == BLOCK_CLEAN ? "clean" : + state == BLOCK_DIRTY ? "dirty" : + "unknown"); if (state == BLOCK_NOT_CACHED) { /* Read underlying plugin, copy to cache regardless of cache-on-read. */ @@ -284,8 +292,9 @@ blk_cache (nbdkit_next *next, */ memset (block + n, 0, tail); - nbdkit_debug ("cache: cache block %" PRIu64 " (offset %" PRIu64 ")", - blknum, (uint64_t) offset); + if (cache_debug_verbose) + nbdkit_debug ("cache: cache block %" PRIu64 " (offset %" PRIu64 ")", + blknum, (uint64_t) offset); if (pwrite (fd, block, blksize, offset) == -1) { *err = errno; @@ -324,8 +333,9 @@ blk_writethrough (nbdkit_next *next, reclaim (fd, &bm); - nbdkit_debug ("cache: writethrough block %" PRIu64 " (offset %" PRIu64 ")", - blknum, (uint64_t) offset); + if (cache_debug_verbose) + nbdkit_debug ("cache: writethrough block %" PRIu64 " (offset %" PRIu64 ")", + blknum, (uint64_t) offset); if (pwrite (fd, block, blksize, offset) == -1) { *err = errno; @@ -357,8 +367,9 @@ blk_write (nbdkit_next *next, reclaim (fd, &bm); - nbdkit_debug ("cache: writeback block %" PRIu64 " (offset %" PRIu64 ")", - blknum, (uint64_t) offset); + if (cache_debug_verbose) + nbdkit_debug ("cache: writeback block %" PRIu64 " (offset %" PRIu64 ")", + blknum, (uint64_t) offset); if (pwrite (fd, block, blksize, offset) == -1) { *err = errno; -- 2.31.1