+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ */
#ifndef __LVFS_LINUX_H__
#define __LVFS_LINUX_H__
int flags);
struct l_linux_dirent {
- ino_t d_ino;
- unsigned long d_off;
- unsigned short d_reclen;
- char d_name[1];
+ struct list_head lld_list;
+ ino_t lld_ino;
+ unsigned long lld_off;
+ char lld_name[LL_FID_NAMELEN];
};
-
struct l_readdir_callback {
- struct l_linux_dirent *current_dir;
- struct l_linux_dirent *previous;
- int count;
- int error;
+ struct l_linux_dirent *lrc_dirent;
+ struct list_head *lrc_list;
};
#endif
#include <linux/obd.h>
#include <linux/lustre_lib.h>
+atomic_t obd_memory;
+int obd_memmax;
+
+
/* Debugging check only needed during development */
#ifdef OBD_CTXT_DEBUG
# define ASSERT_CTXT_MAGIC(magic) LASSERT((magic) == OBD_RUN_CTXT_MAGIC)
{
struct l_linux_dirent *dirent;
struct l_readdir_callback *buf = (struct l_readdir_callback *)__buf;
- int reclen = size_round(offsetof(struct l_linux_dirent, d_name) + namlen + 1);
- buf->error = -EINVAL;
- if (reclen > buf->count)
- return -EINVAL;
- dirent = buf->previous;
+ dirent = buf->lrc_dirent;
if (dirent)
- dirent->d_off = offset;
- dirent = buf->current_dir;
- buf->previous = dirent;
- dirent->d_ino = ino;
- dirent->d_reclen = reclen;
- memcpy(dirent->d_name, name, namlen);
- ((char *)dirent) += reclen;
- buf->current_dir = dirent;
- buf->count -= reclen;
+ dirent->lld_off = offset;
+
+ OBD_ALLOC(dirent, sizeof(*dirent));
+
+ list_add_tail(&dirent->lld_list, buf->lrc_list);
+
+ buf->lrc_dirent = dirent;
+ dirent->lld_ino = ino;
+ LASSERT(sizeof(dirent->lld_name) >= namlen + 1);
+ memcpy(dirent->lld_name, name, namlen);
+
return 0;
}
-long l_readdir(struct file * file, void * dirent, unsigned int count)
+long l_readdir(struct file *file, struct list_head *dentry_list)
{
- struct l_linux_dirent * lastdirent;
+ struct l_linux_dirent *lastdirent;
struct l_readdir_callback buf;
int error;
- buf.current_dir = (struct l_linux_dirent *)dirent;
- buf.previous = NULL;
- buf.count = count;
- buf.error = 0;
+ buf.lrc_dirent = NULL;
+ buf.lrc_list = dentry_list;
error = vfs_readdir(file, l_filldir, &buf);
if (error < 0)
return error;
- error = buf.error;
- lastdirent = buf.previous;
- if (lastdirent) {
- lastdirent->d_off = file->f_pos;
- error = count - buf.count;
- }
- return error;
+ lastdirent = buf.lrc_dirent;
+ if (lastdirent)
+ lastdirent->lld_off = file->f_pos;
+
+ return 0;
}
EXPORT_SYMBOL(l_readdir);
+EXPORT_SYMBOL(obd_memory);
+EXPORT_SYMBOL(obd_memmax);
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
static void __exit lvfs_linux_exit(void)
{
+ int leaked;
+ ENTRY;
+
+ leaked = atomic_read(&obd_memory);
+ CDEBUG(leaked ? D_ERROR : D_INFO,
+ "obd mem max: %d leaked: %d\n", obd_memmax, leaked);
return;
}