bfs: Enable logging on DEBUG build

Fix DEBUG build errors by using B_PRI macros in BlockAllocator.cpp,
CheckVisitor.cpp, Inode.cpp, Journal.cpp, and kernel_interface.cpp

Add optional type parameter from BlockAllocator::IsValidBlockRun()
and actually PRINT it, type parameter is already optional on
BlockAllocator::CheckBlockRun().

Remove a couple of casts as we are printing the expected type, int32.

Cast mode_t to (unsigned int) and use %u because 32-bit Haiku didn't
like B_PRIu32.

Verified to compile on both regular and DEBUG builds on both 32-bit
and 64-bit.

Change-Id: I8bb39afd400768b7f69d36384974f0b91b3ef48c
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3184
Reviewed-by: Adrien Destugues <[email protected]>
Reviewed-by: John Scipione <[email protected]>
This commit is contained in:
John Scipione
2020-09-07 22:09:11 +00:00
parent b91bee0657
commit 3d43a90508
7 changed files with 59 additions and 45 deletions
@@ -49,8 +49,8 @@ public:
virtual void AddDump(TraceOutput& out) virtual void AddDump(TraceOutput& out)
{ {
out.Print("bfs:alloc %lu.%u.%u", fRun.AllocationGroup(), out.Print("bfs:alloc %" B_PRId32 ".%" B_PRIu16 ".%" B_PRIu16,
fRun.Start(), fRun.Length()); fRun.AllocationGroup(), fRun.Start(), fRun.Length());
} }
const block_run& Run() const { return fRun; } const block_run& Run() const { return fRun; }
@@ -71,8 +71,8 @@ public:
virtual void AddDump(TraceOutput& out) virtual void AddDump(TraceOutput& out)
{ {
out.Print("bfs:free %lu.%u.%u", fRun.AllocationGroup(), out.Print("bfs:free %" B_PRId32 ".%" B_PRIu16 ".%" B_PRIu16,
fRun.Start(), fRun.Length()); fRun.AllocationGroup(), fRun.Start(), fRun.Length());
} }
const block_run& Run() const { return fRun; } const block_run& Run() const { return fRun; }
@@ -730,7 +730,8 @@ BlockAllocator::AllocateBlocks(Transaction& transaction, int32 groupIndex,
if (maximum == 0) if (maximum == 0)
return B_BAD_VALUE; return B_BAD_VALUE;
FUNCTION_START(("group = %ld, start = %u, maximum = %u, minimum = %u\n", FUNCTION_START(("group = %" B_PRId32 ", start = %" B_PRIu16
", maximum = %" B_PRIu16 ", minimum = %" B_PRIu16 "\n",
groupIndex, start, maximum, minimum)); groupIndex, start, maximum, minimum));
AllocationBlock cached(fVolume); AllocationBlock cached(fVolume);
@@ -998,8 +999,8 @@ BlockAllocator::Free(Transaction& transaction, block_run run)
uint16 start = run.Start(); uint16 start = run.Start();
uint16 length = run.Length(); uint16 length = run.Length();
FUNCTION_START(("group = %ld, start = %u, length = %u\n", group, start, FUNCTION_START(("group = %" B_PRId32 ", start = %" B_PRIu16
length)); ", length = %" B_PRIu16 "\n", group, start, length))
T(Free(run)); T(Free(run));
// doesn't use Volume::IsValidBlockRun() here because it can check better // doesn't use Volume::IsValidBlockRun() here because it can check better
@@ -1008,8 +1009,9 @@ BlockAllocator::Free(Transaction& transaction, block_run run)
|| start > fGroups[group].NumBits() || start > fGroups[group].NumBits()
|| uint32(start + length) > fGroups[group].NumBits() || uint32(start + length) > fGroups[group].NumBits()
|| length == 0) { || length == 0) {
FATAL(("tried to free an invalid block_run (%d, %u, %u)\n", (int)group, FATAL(("tried to free an invalid block_run"
start, length)); " (%" B_PRId32 ", %" B_PRIu16 ", %" B_PRIu16")\n",
group, start, length));
DEBUGGER(("tried to free invalid block_run")); DEBUGGER(("tried to free invalid block_run"));
return B_BAD_VALUE; return B_BAD_VALUE;
} }
@@ -1017,8 +1019,9 @@ BlockAllocator::Free(Transaction& transaction, block_run run)
// drive // drive
if (group == 0 if (group == 0
&& start < uint32(fVolume->Log().Start() + fVolume->Log().Length())) { && start < uint32(fVolume->Log().Start() + fVolume->Log().Length())) {
FATAL(("tried to free a reserved block_run (%d, %u, %u)\n", (int)group, FATAL(("tried to free a reserved block_run"
start, length)); " (%" B_PRId32 ", %" B_PRIu16 ", %" B_PRIu16")\n",
group, start, length));
DEBUGGER(("tried to free reserved block")); DEBUGGER(("tried to free reserved block"));
return B_BAD_VALUE; return B_BAD_VALUE;
} }
@@ -1244,8 +1247,9 @@ BlockAllocator::CheckBlocks(off_t start, off_t length, bool allocated,
for (; blockOffset < cached.NumBlockBits() && length > 0; for (; blockOffset < cached.NumBlockBits() && length > 0;
blockOffset++, length--, block++) { blockOffset++, length--, block++) {
if (cached.IsUsed(blockOffset) != allocated) { if (cached.IsUsed(blockOffset) != allocated) {
PRINT(("CheckBlocks: Erroneous block (group = %ld, " PRINT(("CheckBlocks: Erroneous block (group = %" B_PRId32
"groupBlock = %ld, blockOffset = %ld)!\n", ", groupBlock = %" B_PRIu32
", blockOffset = %" B_PRIu32 ")!\n",
group, groupBlock, blockOffset)); group, groupBlock, blockOffset));
if (firstError) if (firstError)
@@ -1268,15 +1272,16 @@ BlockAllocator::CheckBlocks(off_t start, off_t length, bool allocated,
bool bool
BlockAllocator::IsValidBlockRun(block_run run) BlockAllocator::IsValidBlockRun(block_run run, const char* type)
{ {
if (run.AllocationGroup() < 0 || run.AllocationGroup() >= fNumGroups if (run.AllocationGroup() < 0 || run.AllocationGroup() >= fNumGroups
|| run.Start() > fGroups[run.AllocationGroup()].fNumBits || run.Start() > fGroups[run.AllocationGroup()].fNumBits
|| uint32(run.Start() + run.Length()) || uint32(run.Start() + run.Length())
> fGroups[run.AllocationGroup()].fNumBits > fGroups[run.AllocationGroup()].fNumBits
|| run.length == 0) { || run.length == 0) {
PRINT(("%s: block_run(%ld, %u, %u) is invalid!\n", type, PRINT(("%s: block_run(%" B_PRId32 ", %" B_PRIu16 ", %" B_PRIu16")"
run.AllocationGroup(), run.Start(), run.Length())); " is invalid!\n", type, run.AllocationGroup(), run.Start(),
run.Length()));
return false; return false;
} }
return true; return true;
@@ -1286,14 +1291,15 @@ BlockAllocator::IsValidBlockRun(block_run run)
status_t status_t
BlockAllocator::CheckBlockRun(block_run run, const char* type, bool allocated) BlockAllocator::CheckBlockRun(block_run run, const char* type, bool allocated)
{ {
if (!IsValidBlockRun(run)) if (!IsValidBlockRun(run, type))
return B_BAD_DATA; return B_BAD_DATA;
status_t status = CheckBlocks(fVolume->ToBlock(run), run.Length(), status_t status = CheckBlocks(fVolume->ToBlock(run), run.Length(),
allocated); allocated);
if (status != B_OK) { if (status != B_OK) {
PRINT(("%s: block_run(%ld, %u, %u) is only partially allocated!\n", PRINT(("%s: block_run(%" B_PRId32 ", %" B_PRIu16 ", %" B_PRIu16")"
type, run.AllocationGroup(), run.Start(), run.Length())); " is only partially allocated!\n", type, run.AllocationGroup(),
run.Start(), run.Length()));
} }
return status; return status;
@@ -52,7 +52,8 @@ public:
status_t CheckBlockRun(block_run run, status_t CheckBlockRun(block_run run,
const char* type = NULL, const char* type = NULL,
bool allocated = true); bool allocated = true);
bool IsValidBlockRun(block_run run); bool IsValidBlockRun(block_run run,
const char* type = NULL);
recursive_lock& Lock() { return fLock; } recursive_lock& Lock() { return fLock; }
@@ -608,7 +608,7 @@ CheckVisitor::_CheckAllocated(block_run run, const char* type)
BlockAllocator& allocator = GetVolume()->Allocator(); BlockAllocator& allocator = GetVolume()->Allocator();
// make sure the block run is valid // make sure the block run is valid
if (!allocator.IsValidBlockRun(run)) { if (!allocator.IsValidBlockRun(run, type)) {
Control().errors |= BFS_INVALID_BLOCK_RUN; Control().errors |= BFS_INVALID_BLOCK_RUN;
return B_OK; return B_OK;
} }
@@ -637,8 +637,9 @@ CheckVisitor::_CheckAllocated(block_run run, const char* type)
else if (status != B_BAD_DATA) else if (status != B_BAD_DATA)
return status; return status;
PRINT(("%s: block_run(%ld, %u, %u): blocks %Ld - %Ld are " PRINT(("%s: block_run(%" B_PRId32 ", %" B_PRIu16 ", %" B_PRIu16 ")"
"not allocated!\n", type, run.AllocationGroup(), run.Start(), ": blocks %" B_PRIdOFF " - %" B_PRIdOFF " are not allocated!\n",
type, run.AllocationGroup(), run.Start(),
run.Length(), firstMissing, afterLastMissing - 1)); run.Length(), firstMissing, afterLastMissing - 1));
Control().stats.missing += afterLastMissing - firstMissing; Control().stats.missing += afterLastMissing - firstMissing;
+1 -1
View File
@@ -47,7 +47,7 @@
// D() // D()
// the statements in D() are only included if DEBUG is defined // the statements in D() are only included if DEBUG is defined
#if 0//DEBUG #if DEBUG
#define PRINT(x) { __out("bfs: "); __out x; } #define PRINT(x) { __out("bfs: "); __out x; }
#define REPORT_ERROR(status) \ #define REPORT_ERROR(status) \
__out("bfs: %s:%d: %s\n", __FUNCTION__, __LINE__, strerror(status)); __out("bfs: %s:%d: %s\n", __FUNCTION__, __LINE__, strerror(status));
@@ -346,7 +346,8 @@ Inode::Inode(Volume* volume, ino_t id)
fCache(NULL), fCache(NULL),
fMap(NULL) fMap(NULL)
{ {
PRINT(("Inode::Inode(volume = %p, id = %Ld) @ %p\n", volume, id, this)); PRINT(("Inode::Inode(volume = %p, id = %" B_PRIdINO ") @ %p\n",
volume, id, this));
rw_lock_init(&fLock, "bfs inode"); rw_lock_init(&fLock, "bfs inode");
recursive_lock_init(&fSmallDataLock, "bfs inode small data"); recursive_lock_init(&fSmallDataLock, "bfs inode small data");
@@ -379,8 +380,8 @@ Inode::Inode(Volume* volume, Transaction& transaction, ino_t id, mode_t mode,
fCache(NULL), fCache(NULL),
fMap(NULL) fMap(NULL)
{ {
PRINT(("Inode::Inode(volume = %p, transaction = %p, id = %Ld) @ %p\n", PRINT(("Inode::Inode(volume = %p, transaction = %p, id = %" B_PRIdINO
volume, &transaction, id, this)); ") @ %p\n", volume, &transaction, id, this));
rw_lock_init(&fLock, "bfs inode"); rw_lock_init(&fLock, "bfs inode");
recursive_lock_init(&fSmallDataLock, "bfs inode small data"); recursive_lock_init(&fSmallDataLock, "bfs inode small data");
@@ -2152,8 +2153,9 @@ status_t
Inode::_FreeStreamArray(Transaction& transaction, block_run* array, Inode::_FreeStreamArray(Transaction& transaction, block_run* array,
uint32 arrayLength, off_t size, off_t& offset, off_t& max) uint32 arrayLength, off_t size, off_t& offset, off_t& max)
{ {
PRINT(("FreeStreamArray: arrayLength %lu, size %Ld, offset %Ld, max %Ld\n", PRINT(("FreeStreamArray: arrayLength %" B_PRId32 ", size %" B_PRIdOFF
arrayLength, size, offset, max)); ", offset %" B_PRIdOFF ", max %" B_PRIdOFF "\n", arrayLength, size,
offset, max));
off_t newOffset = offset; off_t newOffset = offset;
uint32 i = 0; uint32 i = 0;
@@ -2619,7 +2621,7 @@ Inode::Create(Transaction& transaction, Inode* parent, const char* name,
int32 mode, int openMode, uint32 type, bool* _created, ino_t* _id, int32 mode, int openMode, uint32 type, bool* _created, ino_t* _id,
Inode** _inode, fs_vnode_ops* vnodeOps, uint32 publishFlags) Inode** _inode, fs_vnode_ops* vnodeOps, uint32 publishFlags)
{ {
FUNCTION_START(("name = %s, mode = %ld\n", name, mode)); FUNCTION_START(("name = %s, mode = %" B_PRId32 "\n", name, mode));
block_run parentRun = parent ? parent->BlockRun() : block_run::Run(0, 0, 0); block_run parentRun = parent ? parent->BlockRun() : block_run::Run(0, 0, 0);
Volume* volume = transaction.GetVolume(); Volume* volume = transaction.GetVolume();
@@ -465,7 +465,7 @@ Journal::_CheckRunArray(const run_array* array)
return B_ERROR; return B_ERROR;
} }
PRINT(("Log entry has %ld entries\n", array->CountRuns())); PRINT(("Log entry has %" B_PRId32 " entries\n", array->CountRuns()));
return B_OK; return B_OK;
} }
@@ -477,7 +477,7 @@ Journal::_CheckRunArray(const run_array* array)
status_t status_t
Journal::_ReplayRunArray(int32* _start) Journal::_ReplayRunArray(int32* _start)
{ {
PRINT(("ReplayRunArray(start = %ld)\n", *_start)); PRINT(("ReplayRunArray(start = %" B_PRId32 ")\n", *_start));
off_t logOffset = fVolume->ToBlock(fVolume->Log()); off_t logOffset = fVolume->ToBlock(fVolume->Log());
off_t firstBlockNumber = *_start % fLogSize; off_t firstBlockNumber = *_start % fLogSize;
@@ -645,8 +645,8 @@ Journal::_TransactionWritten(int32 transactionID, int32 event, void* _logEntry)
{ {
LogEntry* logEntry = (LogEntry*)_logEntry; LogEntry* logEntry = (LogEntry*)_logEntry;
PRINT(("Log entry %p has been finished, transaction ID = %ld\n", logEntry, PRINT(("Log entry %p has been finished, transaction ID = %" B_PRId32 "\n",
transactionID)); logEntry, transactionID));
Journal* journal = logEntry->GetJournal(); Journal* journal = logEntry->GetJournal();
disk_super_block& superBlock = journal->fVolume->SuperBlock(); disk_super_block& superBlock = journal->fVolume->SuperBlock();
@@ -241,7 +241,7 @@ bfs_read_fs_stat(fs_volume* _volume, struct fs_info* info)
static status_t static status_t
bfs_write_fs_stat(fs_volume* _volume, const struct fs_info* info, uint32 mask) bfs_write_fs_stat(fs_volume* _volume, const struct fs_info* info, uint32 mask)
{ {
FUNCTION_START(("mask = %ld\n", mask)); FUNCTION_START(("mask = %" B_PRId32 "\n", mask));
Volume* volume = (Volume*)_volume->private_volume; Volume* volume = (Volume*)_volume->private_volume;
if (volume->IsReadOnly()) if (volume->IsReadOnly())
@@ -635,8 +635,8 @@ static status_t
bfs_ioctl(fs_volume* _volume, fs_vnode* _node, void* _cookie, uint32 cmd, bfs_ioctl(fs_volume* _volume, fs_vnode* _node, void* _cookie, uint32 cmd,
void* buffer, size_t bufferLength) void* buffer, size_t bufferLength)
{ {
FUNCTION_START(("node = %p, cmd = %lu, buf = %p, len = %ld\n", _node, cmd, FUNCTION_START(("node = %p, cmd = %" B_PRIu32 ", buf = %p"
buffer, bufferLength)); ", len = %" B_PRIuSIZE "\n", _node, cmd, buffer, bufferLength));
Volume* volume = (Volume*)_volume->private_volume; Volume* volume = (Volume*)_volume->private_volume;
@@ -802,8 +802,10 @@ bfs_ioctl(fs_volume* _volume, fs_vnode* _node, void* _cookie, uint32 cmd,
block_run run; block_run run;
while (allocator.AllocateBlocks(transaction, 8, 0, 64, 1, run) while (allocator.AllocateBlocks(transaction, 8, 0, 64, 1, run)
== B_OK) { == B_OK) {
PRINT(("write block_run(%ld, %d, %d)\n", run.allocation_group, PRINT(("write block_run(%" B_PRId32 ", %" B_PRIu16
run.start, run.length)); ", %" B_PRIu16 ")\n", run.allocation_group, run.start,
run.length));
for (int32 i = 0;i < run.length;i++) { for (int32 i = 0;i < run.length;i++) {
status_t status = cached.SetToWritable(transaction, run); status_t status = cached.SetToWritable(transaction, run);
if (status == B_OK) if (status == B_OK)
@@ -934,8 +936,8 @@ bfs_write_stat(fs_volume* _volume, fs_vnode* _node, const struct stat* stat,
// only the user or root can do that // only the user or root can do that
if (!isOwnerOrRoot) if (!isOwnerOrRoot)
RETURN_ERROR(B_NOT_ALLOWED); RETURN_ERROR(B_NOT_ALLOWED);
PRINT(("original mode = %ld, stat->st_mode = %d\n", node.Mode(), PRINT(("original mode = %u, stat->st_mode = %u\n",
stat->st_mode)); (unsigned int)node.Mode(), (unsigned int)stat->st_mode));
node.mode = HOST_ENDIAN_TO_BFS_INT32((node.Mode() & ~S_IUMSK) node.mode = HOST_ENDIAN_TO_BFS_INT32((node.Mode() & ~S_IUMSK)
| (stat->st_mode & S_IUMSK)); | (stat->st_mode & S_IUMSK));
updateTime = true; updateTime = true;
@@ -2039,8 +2041,8 @@ bfs_create_special_node(fs_volume* _volume, fs_vnode* _directory,
if (name == NULL) if (name == NULL)
return B_UNSUPPORTED; return B_UNSUPPORTED;
FUNCTION_START(("name = \"%s\", mode = %d, flags = 0x%lx, subVnode: %p\n", FUNCTION_START(("name = \"%s\", mode = %u, flags = 0x%" B_PRIx32
name, mode, flags, subVnode)); ", subVnode: %p\n", name, (unsigned int)mode, flags, subVnode));
Volume* volume = (Volume*)_volume->private_volume; Volume* volume = (Volume*)_volume->private_volume;
Inode* directory = (Inode*)_directory->private_node; Inode* directory = (Inode*)_directory->private_node;
@@ -2168,7 +2170,8 @@ static status_t
bfs_create_index(fs_volume* _volume, const char* name, uint32 type, bfs_create_index(fs_volume* _volume, const char* name, uint32 type,
uint32 flags) uint32 flags)
{ {
FUNCTION_START(("name = \"%s\", type = %ld, flags = %ld\n", name, type, flags)); FUNCTION_START(("name = \"%s\", type = %" B_PRIu32
", flags = %" B_PRIu32 "\n", name, type, flags));
Volume* volume = (Volume*)_volume->private_volume; Volume* volume = (Volume*)_volume->private_volume;
@@ -2258,7 +2261,8 @@ static status_t
bfs_open_query(fs_volume* _volume, const char* queryString, uint32 flags, bfs_open_query(fs_volume* _volume, const char* queryString, uint32 flags,
port_id port, uint32 token, void** _cookie) port_id port, uint32 token, void** _cookie)
{ {
FUNCTION_START(("bfs_open_query(\"%s\", flags = %lu, port_id = %ld, token = %ld)\n", FUNCTION_START(("bfs_open_query(\"%s\", flags = %" B_PRIu32
", port_id = %" B_PRId32 ", token = %" B_PRIu32 ")\n",
queryString, flags, port, token)); queryString, flags, port, token));
Volume* volume = (Volume*)_volume->private_volume; Volume* volume = (Volume*)_volume->private_volume;