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 <[email protected]>
This commit is contained in:
Jérôme Duval
2020-10-03 11:52:37 +00:00
parent 1a58c4171d
commit 5e43ea2ed8
+14 -9
View File
@@ -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));