kernel/Kconfig\
kernel/Makefile\
kernel/addr.c\
- kernel/bookkeeper.c\
- kernel/bookkeeper.h\
kernel/caps.c\
kernel/ceph_debug.h\
kernel/ceph_fs.h\
#ifdef __KERNEL__
# include <linux/slab.h>
-# include "../bookkeeper.h"
#else
# include <stdlib.h>
# include <assert.h>
If unsure, say N.
-config CEPH_BOOKKEEPER
- bool "Ceph leaks detection tool"
- depends on CEPH_FS
- help
- Leaks detection tool for the Ceph fs.
-
mds_client.o mdsmap.o \
mon_client.o \
osd_client.o osdmap.o crush/crush.o crush/mapper.o \
- debugfs.o bookkeeper.o
+ debugfs.o
else
#Otherwise we were called directly from the command
+++ /dev/null
-#include <linux/spinlock.h>
-#include <linux/slab.h>
-#include <linux/kallsyms.h>
-
-#define CEPH_OVERRIDE_BOOKKEEPER /* avoid kmalloc/kfree recursion */
-
-#define CEPH_BK_MAGIC 0x140985AC
-
-#include "ceph_debug.h"
-
-int ceph_debug_tools __read_mostly = -1;
-#define DOUT_VAR ceph_debug_tools
-#define DOUT_MASK DOUT_MASK_TOOLS
-#include "super.h"
-
-static struct list_head _bk_allocs;
-
-static DEFINE_SPINLOCK(_bk_lock);
-
-static size_t _total_alloc;
-static size_t _total_free;
-
-struct alloc_data {
- u32 prefix_magic;
- struct list_head node;
- size_t size;
- char *fname;
- int line;
- u32 suffix_magic;
-};
-
-void *ceph_kmalloc(char *fname, int line, size_t size, gfp_t flags)
-{
- struct alloc_data *p = kmalloc(size+sizeof(struct alloc_data), flags);
-
- if (!p)
- return NULL;
-
- p->prefix_magic = CEPH_BK_MAGIC;
- p->size = size;
- p->fname = fname;
- p->line = line;
- p->suffix_magic = CEPH_BK_MAGIC;
-
- spin_lock(&_bk_lock);
- _total_alloc += size;
-
- list_add_tail(&p->node, &_bk_allocs);
- spin_unlock(&_bk_lock);
-
- return ((void *)p)+sizeof(struct alloc_data);
-}
-
-void ceph_kfree(const void *ptr)
-{
- struct alloc_data *p = (struct alloc_data *)(ptr -
- sizeof(struct alloc_data));
- int overrun = 0;
-
- if (!ptr)
- return;
-
- if (p->prefix_magic != CEPH_BK_MAGIC) {
- derr(0, "ERROR: memory overrun (under)!\n");
- overrun = 1;
- }
-
- if (p->suffix_magic != CEPH_BK_MAGIC) {
- derr(0, "ERROR: Memory overrun (over)!\n");
- overrun = 1;
- }
-
- if (overrun) {
- derr(0, "Memory allocated at %s(%d): p=%p (%zu bytes)\n",
- p->fname, p->line, ((void *)p)+sizeof(struct alloc_data),
- p->size);
- }
-
- BUG_ON(overrun);
-
- spin_lock(&_bk_lock);
- _total_free += p->size;
- list_del(&p->node);
- spin_unlock(&_bk_lock);
-
- kfree(p);
-
- return;
-}
-
-
-void ceph_bookkeeper_dump(void)
-{
- struct list_head *p;
- struct alloc_data *entry;
-
- dout(1, "bookkeeper: total bytes alloc: %zu\n", _total_alloc);
- dout(1, "bookkeeper: total bytes free: %zu\n", _total_free);
-
- if (_total_alloc != _total_free) {
- list_for_each(p, &_bk_allocs) {
- entry = list_entry(p, struct alloc_data, node);
- dout(1, "%s(%d): p=%p (%zu bytes)\n", entry->fname,
- entry->line,
- ((void *)entry)+sizeof(struct alloc_data),
- entry->size);
- }
- } else {
- dout(1, "No leaks found! Yay!\n");
- }
-}
-
-void ceph_bookkeeper_init(void)
-{
- dout(10, "bookkeeper: start\n");
- INIT_LIST_HEAD(&_bk_allocs);
-}
-
-void ceph_bookkeeper_finalize(void)
-{
- ceph_bookkeeper_dump();
-}
+++ /dev/null
-#ifdef CONFIG_CEPH_BOOKKEEPER
-
-#ifndef _FS_CEPH_BOOKKEEPER_H
-#define _FS_CEPH_BOOKKEEPER_H
-
-extern void ceph_bookkeeper_dump(void);
-extern void ceph_bookkeeper_init(void);
-extern void ceph_bookkeeper_finalize(void);
-extern void *ceph_kmalloc(char *fname, int line, size_t size, gfp_t flags);
-extern void ceph_kfree(const void *ptr);
-
-#endif
-
-
-#ifndef CEPH_OVERRIDE_BOOKKEEPER
-#define CEPH_BOOKKEEPER_DEFINED
-#define kmalloc(size, flags) ceph_kmalloc(__FILE__, __LINE__, size, flags)
-#define kzalloc(size, flags) ceph_kmalloc(__FILE__, __LINE__, size, \
- flags | __GFP_ZERO)
-#define kfree ceph_kfree
-#endif
-
-#ifdef CEPH_DISABLE_BOOKKEEPER
-#ifdef CEPH_BOOKKEEPER_DEFINED
-#undef kmalloc
-#undef kzalloc
-#undef kfree
-#endif
-#endif
-
-#endif
#include <linux/string.h>
-#include "bookkeeper.h"
-
extern int ceph_debug __read_mostly; /* debug level. */
extern int ceph_debug_console __read_mostly; /* send debug output to console? */
extern int ceph_debug_mask __read_mostly;
#include "super.h"
#include "mds_client.h"
-#include "bookkeeper.h"
static struct dentry *ceph_debugfs_dir;
static struct dentry *ceph_debugfs_debug;
static struct dentry *ceph_debugfs_debug_console;
static struct dentry *ceph_debugfs_debug_mask;
static struct dentry *ceph_debugfs_caps_reservation;
-#ifdef CONFIG_CEPH_BOOKKEEPER
-static struct dentry *ceph_debugfs_bookkeeper;
-#endif
/*
* ceph_debug_mask
DEFINE_SHOW_FUNC(caps_reservation_show)
DEFINE_SHOW_FUNC(dentry_lru_show)
-#ifdef CONFIG_CEPH_BOOKKEEPER
-static int debugfs_bookkeeper_set(void *data, u64 val)
-{
- if (val)
- ceph_bookkeeper_dump();
- return 0;
-}
-
-static int debugfs_bookkeeper_get(void *data, u64 *val)
-{
- *val = 0;
- return 0;
-}
-
-DEFINE_SIMPLE_ATTRIBUTE(bookkeeper_fops, debugfs_bookkeeper_get,
- debugfs_bookkeeper_set, "%llu\n");
-#endif
-
int ceph_debugfs_init(void)
{
int ret = -ENOMEM;
if (!ceph_debugfs_caps_reservation)
goto out;
-#ifdef CONFIG_CEPH_BOOKKEEPER
- ceph_debugfs_bookkeeper = debugfs_create_file("show_bookkeeper",
- 0600,
- ceph_debugfs_dir,
- NULL,
- &bookkeeper_fops);
- if (!ceph_debugfs_bookkeeper)
- goto out;
-#endif
return 0;
out:
debugfs_remove(ceph_debugfs_debug_mask);
debugfs_remove(ceph_debugfs_debug_msgr);
debugfs_remove(ceph_debugfs_debug);
-#ifdef CONFIG_CEPH_BOOKKEEPER
- debugfs_remove(ceph_debugfs_bookkeeper);
-#endif
debugfs_remove(ceph_debugfs_dir);
}
EOF
git add fs/ceph/ceph_debug.h
-git add fs/ceph/bookkeeper.h
-git add fs/ceph/bookkeeper.c
git commit -F - <<EOF
ceph: debugging
Some debugging infrastructure, including the ability to adjust the
-level of debug output on a per-file basis. A memory leak detection
-tool can also be enabled via .config.
+level of debug output on a per-file basis.
EOF
#include "ceph_debug.h"
#include "ceph_ver.h"
-#include "bookkeeper.h"
#include "decode.h"
/*
dout(1, "init_ceph\n");
dout(0, "ceph (%s)\n", STRINGIFY(CEPH_GIT_VER));
-#ifdef CONFIG_CEPH_BOOKKEEPER
- ceph_bookkeeper_init();
-#endif
ret = ceph_debugfs_init();
if (ret < 0)
goto out;
destroy_caches();
ceph_msgr_exit();
ceph_debugfs_cleanup();
-#ifdef CONFIG_CEPH_BOOKKEEPER
- ceph_bookkeeper_finalize();
-#endif
}
module_init(init_ceph);
#ifndef _FS_CEPH_SUPER_H
#define _FS_CEPH_SUPER_H
-#define CEPH_DISABLE_BOOKKEEPER
-#include "bookkeeper.h"
-
#include <linux/fs.h>
#include <linux/wait.h>
#include <linux/completion.h>
#include <linux/exportfs.h>
#include <linux/backing-dev.h>
-#undef CEPH_DISABLE_BOOKKEEPER
-#include "bookkeeper.h"
-
#include "types.h"
#include "ceph_debug.h"
#include "messenger.h"
#include "mds_client.h"
#include "osd_client.h"
#include "ceph_fs.h"
-#include "bookkeeper.h"
/* f_type in struct statfs */
#define CEPH_SUPER_MAGIC 0x00c36400