If unsure, say N.
+config CEPH_BOOKKEEPER
+ bool "Ceph leaks detection tool"
+ depends on CEPH_FS
+ help
+ Leaks detection tool for the Ceph fs.
+
osd_client.o osdmap.o crush/crush.o crush/mapper.o crush/hash.o \
debugfs.o \
auth.o auth_none.o \
- ceph_fs.o ceph_strings.o ceph_hash.o ceph_frag.o
+ ceph_fs.o ceph_strings.o ceph_hash.o ceph_frag.o bookkeeper.o
else
#Otherwise we were called directly from the command
--- /dev/null
+#include "ceph_debug.h"
+
+#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
+
+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) {
+ printk(KERN_ERR "ERROR: memory overrun (under)!\n");
+ overrun = 1;
+ }
+
+ if (p->suffix_magic != CEPH_BK_MAGIC) {
+ printk(KERN_ERR "ERROR: Memory overrun (over)!\n");
+ overrun = 1;
+ }
+
+ if (overrun) {
+ printk(KERN_ERR "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;
+
+ printk(KERN_ERR "bookkeeper: total bytes alloc: %zu\n", _total_alloc);
+ printk(KERN_ERR "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);
+ printk(KERN_ERR "%s(%d): p=%p (%zu bytes)\n", entry->fname,
+ entry->line,
+ ((void *)entry)+sizeof(struct alloc_data),
+ entry->size);
+ }
+ } else {
+ dout("No leaks found! Yay!\n");
+ }
+}
+
+char *ceph_kstrdup(char *fname, int line, const char *src, gfp_t flags)
+{
+ int len;
+ char *dst;
+
+ if (!src)
+ return NULL;
+
+ len = strlen(src);
+ dst = ceph_kmalloc(fname, line, len + 1, flags);
+ if (!dst)
+ return NULL;
+
+ memcpy(dst, src, len);
+ dst[len] = '\0';
+
+ return dst;
+}
+
+char *ceph_kstrndup(char *fname, int line, const char *src, int n, gfp_t flags)
+{
+ int len;
+ char *dst;
+
+ if (!src)
+ return NULL;
+
+ len = strlen(src);
+ if (len > n)
+ len = n;
+
+ dst = ceph_kmalloc(fname, line, len + 1, flags);
+ if (!dst)
+ return NULL;
+
+ memcpy(dst, src, len);
+ dst[len] = '\0';
+
+ return dst;
+}
+
+void ceph_bookkeeper_init(void)
+{
+ printk(KERN_ERR "bookkeeper: start\n");
+ dout("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
+
+#include <linux/module.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 char *ceph_kstrdup(char *fname, int line, const char *src, gfp_t flags);
+extern char *ceph_kstrndup(char *fname, int line, const char *src, int n, 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 kcalloc(n, size, flags) ceph_kmalloc(__FILE__, __LINE__, n * size, \
+ flags | __GFP_ZERO)
+#define kstrdup(src, flags) ceph_kstrdup(__FILE__, __LINE__, \
+ src, flags)
+#define kstrndup(src, n, flags) ceph_kstrndup(__FILE__, __LINE__, \
+ src, n, flags)
+#define kfree ceph_kfree
+#endif
+
+#ifdef CEPH_DISABLE_BOOKKEEPER
+#ifdef CEPH_BOOKKEEPER_DEFINED
+#undef kmalloc
+#undef kzalloc
+#undef kcalloc
+#undef kstrdup
+#undef kstrndup
+#undef kfree
+#endif
+#endif
+
+#endif
#ifdef __KERNEL__
# include <linux/slab.h>
+# include "../bookkeeper.h"
#else
# include <stdlib.h>
# include <assert.h>
*/
static struct dentry *ceph_debugfs_dir;
+#ifdef CONFIG_CEPH_BOOKKEEPER
+static struct dentry *ceph_debugfs_bookkeeper;
+#endif
static int monmap_show(struct seq_file *s, void *p)
{
DEFINE_SHOW_FUNC(dentry_lru_show)
DEFINE_SHOW_FUNC(caps_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 __init ceph_debugfs_init(void)
{
ceph_debugfs_dir = debugfs_create_dir("ceph", NULL);
if (!client->debugfs_caps)
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(client->osdc.debugfs_file);
debugfs_remove(client->mdsc.debugfs_file);
debugfs_remove(client->monc.debugfs_file);
+#ifdef CONFIG_CEPH_BOOKKEEPER
+ debugfs_remove(ceph_debugfs_bookkeeper);
+#endif
debugfs_remove(client->debugfs_dir);
}
#include <linux/version.h>
#include <linux/vmalloc.h>
+#include "bookkeeper.h"
#include "decode.h"
#include "super.h"
#include "mon_client.h"
{
int ret = 0;
+#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);
#include "ceph_debug.h"
+#define CEPH_DISABLE_BOOKKEEPER
+#include "bookkeeper.h"
+
#include <asm/unaligned.h>
#include <linux/backing-dev.h>
#include <linux/completion.h>
#include <linux/pagemap.h>
#include <linux/wait.h>
+#undef CEPH_DISABLE_BOOKKEEPER
+#include "bookkeeper.h"
+
#include "types.h"
#include "messenger.h"
#include "msgpool.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