From 5e43ea2ed8753de001ed412990438738e44af7df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Fri, 2 Oct 2020 15:35:31 +0200 Subject: [PATCH] block_cache: use printf when not built in kernel mode this is used by userlandfs Change-Id: I2f7971be819c36fcab78eca2d18b45bb0b1a5fad Reviewed-on: https://review.haiku-os.org/c/haiku/+/3277 Reviewed-by: Rene Gollent --- src/system/kernel/cache/block_cache.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/system/kernel/cache/block_cache.cpp b/src/system/kernel/cache/block_cache.cpp index ca5c1125f7..ec21a6b860 100644 --- a/src/system/kernel/cache/block_cache.cpp +++ b/src/system/kernel/cache/block_cache.cpp @@ -33,14 +33,19 @@ // TODO: the retrieval/copy of the original data could be delayed until the // new data must be written, ie. in low memory situations. +#ifdef _KERNEL_MODE +# define TRACE_ALWAYS(x...) dprintf(x) +#else +# define TRACE_ALWAYS(x...) printf(x) +#endif + //#define TRACE_BLOCK_CACHE #ifdef TRACE_BLOCK_CACHE -# define TRACE(x) dprintf x +# define TRACE(x) TRACE_ALWAYS(x) #else # define TRACE(x) ; #endif -#define TRACE_ALWAYS(x) dprintf x // This macro is used for fatal situations that are acceptable in a running // system, like out of memory situations - should only panic for debugging. @@ -1281,8 +1286,8 @@ BlockWriter::_WriteBlock(cached_block* block) if (written != (ssize_t)blockSize) { TB(Error(fCache, block->block_number, "write failed", written)); - TRACE_ALWAYS(("could not write back block %" B_PRIdOFF " (%s)\n", block->block_number, - strerror(errno))); + TRACE_ALWAYS("could not write back block %" B_PRIdOFF " (%s)\n", + block->block_number, strerror(errno)); if (written < 0) return errno; @@ -1515,7 +1520,7 @@ block_cache::NewBlock(off_t blockNumber) } } else { TB(Error(this, blockNumber, "allocation failed")); - dprintf("block allocation failed, unused list is %sempty.\n", + TRACE_ALWAYS("block allocation failed, unused list is %sempty.\n", unused_blocks.IsEmpty() ? "" : "not "); // allocation failed, try to reuse an unused block @@ -1831,9 +1836,9 @@ put_cached_block(block_cache* cache, cached_block* block) #if BLOCK_CACHE_DEBUG_CHANGED if (!block->is_dirty && block->compare != NULL && memcmp(block->current_data, block->compare, cache->block_size)) { - dprintf("new block:\n"); + TRACE_ALWAYS("new block:\n"); dump_block((const char*)block->current_data, 256, " "); - dprintf("unchanged block:\n"); + TRACE_ALWAYS("unchanged block:\n"); dump_block((const char*)block->compare, 256, " "); BlockWriter::WriteBlock(cache, block); panic("block_cache: supposed to be clean block was changed!\n"); @@ -1949,8 +1954,8 @@ retry: cache->RemoveBlock(block); TB(Error(cache, blockNumber, "read failed", bytesRead)); - TRACE_ALWAYS(("could not read block %" B_PRIdOFF ": bytesRead: %zd, error: %s\n", - blockNumber, bytesRead, strerror(errno))); + TRACE_ALWAYS("could not read block %" B_PRIdOFF ": bytesRead: %zd," + " error: %s\n", blockNumber, bytesRead, strerror(errno)); return errno; } TB(Read(cache, block));