* 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
This commit is contained in:
Axel Dörfler
2008-01-13 00:03:53 +00:00
parent f44927fccb
commit d7477802b8
7 changed files with 204 additions and 14 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2001-2007, Axel Dörfler, [email protected].
* Copyright 2001-2008, Axel Dörfler, [email protected].
* 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)
+33 -6
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2001-2007, Axel Dörfler, [email protected].
* Copyright 2001-2008, Axel Dörfler, [email protected].
* 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 <ptr-to-inode>\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 <ptr-to-volume>\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
+2 -1
View File
@@ -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
+107 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2001-2007, Axel Dörfler, [email protected].
* Copyright 2001-2008, Axel Dörfler, [email protected].
* 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
@@ -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
;
@@ -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;
@@ -19,6 +19,8 @@
#include <ByteOrder.h>
#ifndef _BOOT_MODE
# include <tracing.h>
# include <driver_settings.h>
# include <fs_attr.h>
# include <fs_cache.h>