From d7477802b8a5451ce525646fd2d4b13ef449c455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 13 Jan 2008 00:03:53 +0000 Subject: [PATCH] * Made the additions of the KDL debugger commands independant from the DEBUG macro; they are now added only if BFS_DEBUGGER_COMMANDS is defined (which is now done by default in the Jamfile). * Added "bfs" KDL command which dumps volume information and the super block. * Made use of the new tracing API to trace block and inode actions (and the new AbstractTraceEntry class I forgot to mention in the last commit). Is compiled in only when BFS_TRACING is enabled (defaults to off in the standard builds). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23464 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../file_systems/bfs/BlockAllocator.cpp | 58 +++++++++- src/add-ons/kernel/file_systems/bfs/Debug.cpp | 39 ++++++- src/add-ons/kernel/file_systems/bfs/Debug.h | 3 +- src/add-ons/kernel/file_systems/bfs/Inode.cpp | 108 +++++++++++++++++- src/add-ons/kernel/file_systems/bfs/Jamfile | 2 + .../file_systems/bfs/kernel_interface.cpp | 6 +- .../file_systems/bfs/system_dependencies.h | 2 + 7 files changed, 204 insertions(+), 14 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp index 399197c8f1..3227bad7f8 100644 --- a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp +++ b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2001-2008, Axel Dörfler, axeld@pinc-software.de. * This file may be used under the terms of the MIT License. */ @@ -36,6 +36,56 @@ // be improved a lot. Furthermore, the allocation policies used here should // have some real world tests. +#if defined(BFS_TRACING) && !defined(BFS_SHELL) && !defined(_BOOT_MODE) +namespace BFSBlockTracing { + +class Allocate : public AbstractTraceEntry { + public: + Allocate(block_run run) + : + fRun(run) + { + Initialized(); + } + + virtual void Dump() + { + AbstractTraceEntry::Dump(); + kprintf("alloc %lu.%u.%u\n", fRun.AllocationGroup(), fRun.Start(), + fRun.Length()); + } + + private: + block_run fRun; +}; + +class Free : public AbstractTraceEntry { + public: + Free(block_run run) + : + fRun(run) + { + Initialized(); + } + + virtual void Dump() + { + AbstractTraceEntry::Dump(); + kprintf("free %lu.%u.%u\n", fRun.AllocationGroup(), fRun.Start(), + fRun.Length()); + } + + private: + block_run fRun; +}; + +} // namespace BFSBlockTracing + +# define T(x) new(std::nothrow) BFSBlockTracing::x; +#else +# define T(x) ; +#endif + struct check_cookie { check_cookie() {} @@ -533,8 +583,8 @@ BlockAllocator::_Initialize(BlockAllocator *allocator) status_t -BlockAllocator::AllocateBlocks(Transaction &transaction, int32 group, uint16 start, - uint16 maximum, uint16 minimum, block_run &run) +BlockAllocator::AllocateBlocks(Transaction &transaction, int32 group, + uint16 start, uint16 maximum, uint16 minimum, block_run &run) { if (maximum == 0) return B_BAD_VALUE; @@ -631,6 +681,7 @@ BlockAllocator::AllocateBlocks(Transaction &transaction, int32 group, uint16 sta // If the value is not correct at mount time, it will be // fixed anyway. + T(Allocate(run)); return B_OK; } @@ -728,6 +779,7 @@ BlockAllocator::Free(Transaction &transaction, block_run run) uint16 length = run.Length(); FUNCTION_START(("group = %ld, start = %u, length = %u\n", group, start, length)); + T(Free(run)); // doesn't use Volume::IsValidBlockRun() here because it can check better // against the group size (the last group may have a different length) diff --git a/src/add-ons/kernel/file_systems/bfs/Debug.cpp b/src/add-ons/kernel/file_systems/bfs/Debug.cpp index 7c3949d925..b1ab3536f1 100644 --- a/src/add-ons/kernel/file_systems/bfs/Debug.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Debug.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2001-2008, Axel Dörfler, axeld@pinc-software.de. * Some code is based on work previously done by Marcus Overhagen. * * This file may be used under the terms of the MIT License. @@ -238,13 +238,16 @@ dump_bplustree_node(const bplustree_node *node, const bplustree_header *header, } -// #pragma mark - +// #pragma mark - debugger commands + + +#ifdef BFS_DEBUGGER_COMMANDS static int -debug_inode(int argc, char **argv) +dump_inode(int argc, char **argv) { - if (argc < 2) { + if (argc != 2) { kprintf("usage: bfsinode \n"); return 0; } @@ -256,16 +259,40 @@ debug_inode(int argc, char **argv) } +static int +dump_volume(int argc, char **argv) +{ + if (argc != 2) { + kprintf("usage: bfs \n"); + return 0; + } + + Volume *volume = (Volume *)parse_expression(argv[1]); + + kprintf("root node: %p\n", volume->RootNode()); + kprintf("indices node: %p\n", volume->IndicesNode()); + + dump_super_block(&volume->SuperBlock()); + + return B_OK; +} + + void remove_debugger_commands() { - remove_debugger_command("bfsinode", debug_inode); + remove_debugger_command("bfsinode", dump_inode); + remove_debugger_command("bfs", dump_volume); } void add_debugger_commands() { - add_debugger_command("bfsinode", debug_inode, "dump an Inode object"); + add_debugger_command("bfsinode", dump_inode, "dump an Inode object"); + add_debugger_command("bfs", dump_volume, "dump a BFS volume"); } + +#endif // BFS_DEBUGGER_COMMANDS + diff --git a/src/add-ons/kernel/file_systems/bfs/Debug.h b/src/add-ons/kernel/file_systems/bfs/Debug.h index ce6a52636d..7fa21d6041 100644 --- a/src/add-ons/kernel/file_systems/bfs/Debug.h +++ b/src/add-ons/kernel/file_systems/bfs/Debug.h @@ -97,7 +97,8 @@ extern void dump_bplustree_node(const bplustree_node *node, const bplustree_header *header = NULL, Volume *volume = NULL); extern void dump_block(const char *buffer, int size); - +#endif +#ifdef BFS_DEBUGGER_COMMANDS extern void remove_debugger_commands(); extern void add_debugger_commands(); #endif diff --git a/src/add-ons/kernel/file_systems/bfs/Inode.cpp b/src/add-ons/kernel/file_systems/bfs/Inode.cpp index d2bb3312ca..10a36ddfda 100644 --- a/src/add-ons/kernel/file_systems/bfs/Inode.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Inode.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2001-2008, Axel Dörfler, axeld@pinc-software.de. * This file may be used under the terms of the MIT License. */ @@ -12,6 +12,106 @@ #include "Index.h" +#if defined(BFS_TRACING) && !defined(BFS_SHELL) && !defined(_BOOT_MODE) +namespace BFSInodeTracing { + +class Create : public AbstractTraceEntry { + public: + Create(Inode* inode, Inode* parent, const char* name, int32 mode, + int openMode, uint32 type) + : + fInode(inode), + fID(inode->ID()), + fParent(parent), + fParentID(parent != NULL ? parent->ID() : 0), + fMode(mode), + fOpenMode(openMode), + fType(type) + { + if (name != NULL) + strlcpy(fName, name, sizeof(fName)); + else + fName[0] = '\0'; + + Initialized(); + } + + virtual void Dump() + { + AbstractTraceEntry::Dump(); + kprintf("CREATE %Ld (%p), parent %Ld (%p), \"%s\", mode %lx, " + "omode %x, type %lx\n", fID, fInode, fParentID, fParent, + fName, fMode, fOpenMode, fType); + } + + private: + Inode* fInode; + ino_t fID; + Inode* fParent; + ino_t fParentID; + char fName[32]; + int32 fMode; + int fOpenMode; + uint32 fType; + +}; + +class Remove : public AbstractTraceEntry { + public: + Remove(Inode* inode, const char* name) + : + fInode(inode), + fID(inode->ID()) + { + strlcpy(fName, name, sizeof(fName)); + Initialized(); + } + + virtual void Dump() + { + AbstractTraceEntry::Dump(); + kprintf("REMOVE %Ld (%p), \"%s\"\n", fID, fInode, fName); + } + + private: + Inode* fInode; + ino_t fID; + char fName[32]; +}; + +class Resize : public AbstractTraceEntry { + public: + Resize(Inode* inode, off_t oldSize, off_t newSize) + : + fInode(inode), + fID(inode->ID()), + fOldSize(oldSize), + fNewSize(newSize) + { + Initialized(); + } + + virtual void Dump() + { + AbstractTraceEntry::Dump(); + kprintf("RESIZE %Ld (%p), %Ld -> %Ld\n", fID, fInode, fOldSize, + fNewSize); + } + + private: + Inode* fInode; + ino_t fID; + off_t fOldSize; + off_t fNewSize; +}; + +} // namespace BFSInodeTracing + +# define T(x) new(std::nothrow) BFSInodeTracing::x; +#else +# define T(x) ; +#endif + class InodeAllocator { public: InodeAllocator(Transaction &transaction); @@ -1943,6 +2043,8 @@ Inode::SetFileSize(Transaction &transaction, off_t size) if (size == oldSize) return B_OK; + T(Resize(this, oldSize, size)); + // should the data stream grow or shrink? status_t status; if (size > oldSize) { @@ -2165,6 +2267,8 @@ Inode::Remove(Transaction &transaction, const char *name, ino_t *_id, return B_ENTRY_NOT_FOUND; } + T(Remove(inode, name)); + // Inode::IsContainer() is true also for indices (furthermore, the S_IFDIR // bit is set for indices in BFS, not for attribute directories) - but you // should really be able to do whatever you want with your indices @@ -2326,6 +2430,8 @@ Inode::Create(Transaction &transaction, Inode *parent, const char *name, if (status < B_OK) return status; + T(Create(inode, parent, name, mode, openMode, type)); + // Initialize the parts of the bfs_inode structure that // InodeAllocator::New() hasn't touched yet diff --git a/src/add-ons/kernel/file_systems/bfs/Jamfile b/src/add-ons/kernel/file_systems/bfs/Jamfile index 741b4888a6..3b9156ac96 100644 --- a/src/add-ons/kernel/file_systems/bfs/Jamfile +++ b/src/add-ons/kernel/file_systems/bfs/Jamfile @@ -10,6 +10,8 @@ SubDir HAIKU_TOP src add-ons kernel file_systems bfs ; # set some additional defines { local defines = + BFS_DEBUGGER_COMMANDS + #BFS_TRACING #BFS_BIG_ENDIAN_ONLY ; diff --git a/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp b/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp index d2628fb0ca..f7a6b66bbe 100644 --- a/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp +++ b/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2001-2008, Axel Dörfler, axeld@pinc-software.de. * This file may be used under the terms of the MIT License. */ @@ -2131,12 +2131,12 @@ bfs_std_ops(int32 op, ...) { switch (op) { case B_MODULE_INIT: -#ifdef DEBUG +#ifdef BFS_DEBUGGER_COMMANDS add_debugger_commands(); #endif return B_OK; case B_MODULE_UNINIT: -#ifdef DEBUG +#ifdef BFS_DEBUGGER_COMMANDS remove_debugger_commands(); #endif return B_OK; diff --git a/src/add-ons/kernel/file_systems/bfs/system_dependencies.h b/src/add-ons/kernel/file_systems/bfs/system_dependencies.h index 32863421ea..8e24fd98b4 100644 --- a/src/add-ons/kernel/file_systems/bfs/system_dependencies.h +++ b/src/add-ons/kernel/file_systems/bfs/system_dependencies.h @@ -19,6 +19,8 @@ #include #ifndef _BOOT_MODE +# include + # include # include # include