#ifndef EXPORT_SYMTAB
# define EXPORT_SYMTAB
#endif
-#define DEBUG_SUBSYSTEM S_PORTALS
-
-#include <linux/config.h>
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/mm.h>
-#include <linux/string.h>
-#include <linux/stat.h>
-#include <linux/init.h>
-#include <linux/errno.h>
-#include <linux/smp_lock.h>
-#include <linux/unistd.h>
-
-#include <asm/system.h>
-#include <asm/uaccess.h>
-
-#include <linux/fs.h>
-#include <linux/stat.h>
-#include <asm/uaccess.h>
-#include <asm/segment.h>
-#include <linux/miscdevice.h>
-
-#include <portals/lib-p30.h>
-#include <portals/p30.h>
-#include <linux/kp30.h>
-#include <linux/portals_compat25.h>
-
-#define PORTAL_MINOR 240
-
-struct nal_cmd_handler {
- nal_cmd_handler_fn *nch_handler;
- void *nch_private;
-};
-
-static struct nal_cmd_handler nal_cmd[NAL_MAX_NR + 1];
-static DECLARE_MUTEX(nal_cmd_sem);
+#define DEBUG_SUBSYSTEM S_LNET
-#ifdef PORTAL_DEBUG
-void kportal_assertion_failed(char *expr, char *file, const char *func,
- const int line)
-{
- portals_debug_msg(0, D_EMERG, file, func, line, CDEBUG_STACK,
- "ASSERTION(%s) failed\n", expr);
- LBUG_WITH_LOC(file, func, line);
-}
-#endif
+#include <lnet/lib-lnet.h>
+#include <lnet/lnet.h>
+#include <libcfs/kp30.h>
+#include "tracefile.h"
void
-kportal_daemonize (char *str)
+kportal_memhog_free (struct libcfs_device_userstate *ldu)
{
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,63))
- daemonize(str);
-#else
- daemonize();
- snprintf (current->comm, sizeof (current->comm), "%s", str);
-#endif
-}
-
-void
-kportal_memhog_free (struct portals_device_userstate *pdu)
-{
- struct page **level0p = &pdu->pdu_memhog_root_page;
- struct page **level1p;
- struct page **level2p;
+ cfs_page_t **level0p = &ldu->ldu_memhog_root_page;
+ cfs_page_t **level1p;
+ cfs_page_t **level2p;
int count1;
int count2;
-
+
if (*level0p != NULL) {
- level1p = (struct page **)page_address(*level0p);
+ level1p = (cfs_page_t **)cfs_page_address(*level0p);
count1 = 0;
-
- while (count1 < PAGE_SIZE/sizeof(struct page *) &&
+
+ while (count1 < CFS_PAGE_SIZE/sizeof(cfs_page_t *) &&
*level1p != NULL) {
- level2p = (struct page **)page_address(*level1p);
+ level2p = (cfs_page_t **)cfs_page_address(*level1p);
count2 = 0;
-
- while (count2 < PAGE_SIZE/sizeof(struct page *) &&
+
+ while (count2 < CFS_PAGE_SIZE/sizeof(cfs_page_t *) &&
*level2p != NULL) {
-
- __free_page(*level2p);
- pdu->pdu_memhog_pages--;
+
+ cfs_free_page(*level2p);
+ ldu->ldu_memhog_pages--;
level2p++;
count2++;
}
-
- __free_page(*level1p);
- pdu->pdu_memhog_pages--;
+
+ cfs_free_page(*level1p);
+ ldu->ldu_memhog_pages--;
level1p++;
count1++;
}
-
- __free_page(*level0p);
- pdu->pdu_memhog_pages--;
+
+ cfs_free_page(*level0p);
+ ldu->ldu_memhog_pages--;
*level0p = NULL;
}
-
- LASSERT (pdu->pdu_memhog_pages == 0);
+
+ LASSERT (ldu->ldu_memhog_pages == 0);
}
int
-kportal_memhog_alloc (struct portals_device_userstate *pdu, int npages, int flags)
+kportal_memhog_alloc (struct libcfs_device_userstate *ldu, int npages, int flags)
{
- struct page **level0p;
- struct page **level1p;
- struct page **level2p;
+ cfs_page_t **level0p;
+ cfs_page_t **level1p;
+ cfs_page_t **level2p;
int count1;
int count2;
-
- LASSERT (pdu->pdu_memhog_pages == 0);
- LASSERT (pdu->pdu_memhog_root_page == NULL);
+
+ LASSERT (ldu->ldu_memhog_pages == 0);
+ LASSERT (ldu->ldu_memhog_root_page == NULL);
if (npages < 0)
return -EINVAL;
if (npages == 0)
return 0;
- level0p = &pdu->pdu_memhog_root_page;
- *level0p = alloc_page(flags);
+ level0p = &ldu->ldu_memhog_root_page;
+ *level0p = cfs_alloc_page(flags);
if (*level0p == NULL)
return -ENOMEM;
- pdu->pdu_memhog_pages++;
+ ldu->ldu_memhog_pages++;
- level1p = (struct page **)page_address(*level0p);
+ level1p = (cfs_page_t **)cfs_page_address(*level0p);
count1 = 0;
- memset(level1p, 0, PAGE_SIZE);
-
- while (pdu->pdu_memhog_pages < npages &&
- count1 < PAGE_SIZE/sizeof(struct page *)) {
+ memset(level1p, 0, CFS_PAGE_SIZE);
+
+ while (ldu->ldu_memhog_pages < npages &&
+ count1 < CFS_PAGE_SIZE/sizeof(cfs_page_t *)) {
- if (signal_pending(current))
+ if (cfs_signal_pending())
return (-EINTR);
-
- *level1p = alloc_page(flags);
+
+ *level1p = cfs_alloc_page(flags);
if (*level1p == NULL)
return -ENOMEM;
- pdu->pdu_memhog_pages++;
+ ldu->ldu_memhog_pages++;
- level2p = (struct page **)page_address(*level1p);
+ level2p = (cfs_page_t **)cfs_page_address(*level1p);
count2 = 0;
- memset(level2p, 0, PAGE_SIZE);
-
- while (pdu->pdu_memhog_pages < npages &&
- count2 < PAGE_SIZE/sizeof(struct page *)) {
-
- if (signal_pending(current))
+ memset(level2p, 0, CFS_PAGE_SIZE);
+
+ while (ldu->ldu_memhog_pages < npages &&
+ count2 < CFS_PAGE_SIZE/sizeof(cfs_page_t *)) {
+
+ if (cfs_signal_pending())
return (-EINTR);
- *level2p = alloc_page(flags);
+ *level2p = cfs_alloc_page(flags);
if (*level2p == NULL)
return (-ENOMEM);
- pdu->pdu_memhog_pages++;
-
+ ldu->ldu_memhog_pages++;
+
level2p++;
count2++;
}
-
+
level1p++;
count1++;
}
return 0;
}
-void
-kportal_blockallsigs ()
-{
- unsigned long flags;
-
- SIGNAL_MASK_LOCK(current, flags);
- sigfillset(¤t->blocked);
- RECALC_SIGPENDING;
- SIGNAL_MASK_UNLOCK(current, flags);
-}
-
/* called when opening /dev/device */
-static int libcfs_psdev_open(struct inode * inode, struct file * file)
+static int libcfs_psdev_open(unsigned long flags, void *args)
{
- struct portals_device_userstate *pdu;
+ struct libcfs_device_userstate *ldu;
ENTRY;
-
- if (!inode)
- RETURN(-EINVAL);
PORTAL_MODULE_USE;
- PORTAL_ALLOC(pdu, sizeof(*pdu));
- if (pdu != NULL) {
- pdu->pdu_memhog_pages = 0;
- pdu->pdu_memhog_root_page = NULL;
+ LIBCFS_ALLOC(ldu, sizeof(*ldu));
+ if (ldu != NULL) {
+ ldu->ldu_memhog_pages = 0;
+ ldu->ldu_memhog_root_page = NULL;
}
- file->private_data = pdu;
-
+ *(struct libcfs_device_userstate **)args = ldu;
+
RETURN(0);
}
/* called when closing /dev/device */
-static int libcfs_psdev_release(struct inode * inode, struct file * file)
+static int libcfs_psdev_release(unsigned long flags, void *args)
{
- struct portals_device_userstate *pdu;
+ struct libcfs_device_userstate *ldu;
ENTRY;
- if (!inode)
- RETURN(-EINVAL);
-
- pdu = file->private_data;
- if (pdu != NULL) {
- kportal_memhog_free(pdu);
- PORTAL_FREE(pdu, sizeof(*pdu));
+ ldu = (struct libcfs_device_userstate *)args;
+ if (ldu != NULL) {
+ kportal_memhog_free(ldu);
+ LIBCFS_FREE(ldu, sizeof(*ldu));
}
-
+
PORTAL_MODULE_UNUSE;
RETURN(0);
}
-static inline void freedata(void *data, int len)
-{
- PORTAL_FREE(data, len);
-}
-
-int
-libcfs_nal_cmd_register(int nal, nal_cmd_handler_fn *handler, void *private)
-{
- int rc = 0;
-
- CDEBUG(D_IOCTL, "Register NAL %d, handler: %p\n", nal, handler);
-
- if (nal > 0 && nal <= NAL_MAX_NR) {
- down(&nal_cmd_sem);
- if (nal_cmd[nal].nch_handler != NULL)
- rc = -EBUSY;
- else {
- nal_cmd[nal].nch_handler = handler;
- nal_cmd[nal].nch_private = private;
- }
- up(&nal_cmd_sem);
- }
- return rc;
-}
-EXPORT_SYMBOL(libcfs_nal_cmd_register);
-
-void
-libcfs_nal_cmd_unregister(int nal)
-{
- CDEBUG(D_IOCTL, "Unregister NAL %d\n", nal);
-
- LASSERT(nal > 0 && nal <= NAL_MAX_NR);
- LASSERT(nal_cmd[nal].nch_handler != NULL);
-
- down(&nal_cmd_sem);
- nal_cmd[nal].nch_handler = NULL;
- nal_cmd[nal].nch_private = NULL;
- up(&nal_cmd_sem);
-}
-EXPORT_SYMBOL(libcfs_nal_cmd_unregister);
-
-int
-libcfs_nal_cmd(struct portals_cfg *pcfg)
-{
- __u32 nal = pcfg->pcfg_nal;
- int rc = -EINVAL;
- ENTRY;
-
- down(&nal_cmd_sem);
- if (nal > 0 && nal <= NAL_MAX_NR &&
- nal_cmd[nal].nch_handler != NULL) {
- CDEBUG(D_IOCTL, "calling handler nal: %d, cmd: %d\n", nal,
- pcfg->pcfg_command);
- rc = nal_cmd[nal].nch_handler(pcfg, nal_cmd[nal].nch_private);
- }
- up(&nal_cmd_sem);
-
- RETURN(rc);
-}
-EXPORT_SYMBOL(libcfs_nal_cmd);
-
-static DECLARE_RWSEM(ioctl_list_sem);
-static LIST_HEAD(ioctl_list);
+static struct rw_semaphore ioctl_list_sem;
+static struct list_head ioctl_list;
int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand)
{
int rc = 0;
- down_read(&ioctl_list_sem);
+
+ down_write(&ioctl_list_sem);
if (!list_empty(&hand->item))
rc = -EBUSY;
- up_read(&ioctl_list_sem);
-
- if (rc == 0) {
- down_write(&ioctl_list_sem);
+ else
list_add_tail(&hand->item, &ioctl_list);
- up_write(&ioctl_list_sem);
- }
- RETURN(0);
+ up_write(&ioctl_list_sem);
+
+ return rc;
}
EXPORT_SYMBOL(libcfs_register_ioctl);
int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand)
{
int rc = 0;
- down_read(&ioctl_list_sem);
+
+ down_write(&ioctl_list_sem);
if (list_empty(&hand->item))
rc = -ENOENT;
- up_read(&ioctl_list_sem);
-
- if (rc == 0) {
- down_write(&ioctl_list_sem);
+ else
list_del_init(&hand->item);
- up_write(&ioctl_list_sem);
- }
- RETURN(0);
+ up_write(&ioctl_list_sem);
+
+ return rc;
}
EXPORT_SYMBOL(libcfs_deregister_ioctl);
-static int libcfs_ioctl(struct inode *inode, struct file *file,
- unsigned int cmd, unsigned long arg)
+static int libcfs_ioctl(struct cfs_psdev_file *pfile, unsigned long cmd, void *arg)
{
+ char buf[1024];
int err = -EINVAL;
- char buf[1024];
- struct portal_ioctl_data *data;
+ struct libcfs_ioctl_data *data;
ENTRY;
- if (current->fsuid != 0)
- RETURN(err = -EACCES);
+ /* 'cmd' and permissions get checked in our arch-specific caller */
- if ( _IOC_TYPE(cmd) != IOC_PORTAL_TYPE ||
- _IOC_NR(cmd) < IOC_PORTAL_MIN_NR ||
- _IOC_NR(cmd) > IOC_PORTAL_MAX_NR ) {
- CDEBUG(D_IOCTL, "invalid ioctl ( type %d, nr %d, size %d )\n",
- _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
- RETURN(-EINVAL);
- }
-
- if (portal_ioctl_getdata(buf, buf + 800, (void *)arg)) {
+ if (libcfs_ioctl_getdata(buf, buf + 800, (void *)arg)) {
CERROR("PORTALS ioctl: data error\n");
RETURN(-EINVAL);
}
-
- data = (struct portal_ioctl_data *)buf;
+ data = (struct libcfs_ioctl_data *)buf;
switch (cmd) {
- case IOC_PORTAL_SET_DAEMON:
- RETURN (portals_debug_set_daemon (
- (unsigned int) data->ioc_count,
- (unsigned int) data->ioc_inllen1,
- (char *) data->ioc_inlbuf1,
- (unsigned int) data->ioc_misc));
- case IOC_PORTAL_GET_DEBUG: {
- __s32 size = portals_debug_copy_to_user(data->ioc_pbuf1,
- data->ioc_plen1);
-
- if (size < 0)
- RETURN(size);
-
- data->ioc_size = size;
- err = copy_to_user((char *)arg, data, sizeof(*data));
- RETURN(err);
- }
- case IOC_PORTAL_CLEAR_DEBUG:
- portals_debug_clear_buffer();
+ case IOC_LIBCFS_CLEAR_DEBUG:
+ libcfs_debug_clear_buffer();
RETURN(0);
- case IOC_PORTAL_PANIC:
- if (!capable (CAP_SYS_BOOT))
- RETURN (-EPERM);
- panic("debugctl-invoked panic");
- RETURN(0);
- case IOC_PORTAL_MARK_DEBUG:
+ /*
+ * case IOC_LIBCFS_PANIC:
+ * Handled in arch/cfs_module.c
+ */
+ case IOC_LIBCFS_MARK_DEBUG:
if (data->ioc_inlbuf1 == NULL ||
data->ioc_inlbuf1[data->ioc_inllen1 - 1] != '\0')
RETURN(-EINVAL);
- portals_debug_mark_buffer(data->ioc_inlbuf1);
+ libcfs_debug_mark_buffer(data->ioc_inlbuf1);
RETURN(0);
#if LWT_SUPPORT
- case IOC_PORTAL_LWT_CONTROL:
- err = lwt_control (data->ioc_flags, data->ioc_misc);
+ case IOC_LIBCFS_LWT_CONTROL:
+ err = lwt_control ((data->ioc_flags & 1) != 0,
+ (data->ioc_flags & 2) != 0);
break;
-
- case IOC_PORTAL_LWT_SNAPSHOT:
- err = lwt_snapshot (&data->ioc_nid,
- &data->ioc_count, &data->ioc_misc,
+
+ case IOC_LIBCFS_LWT_SNAPSHOT: {
+ cycles_t now;
+ int ncpu;
+ int total_size;
+
+ err = lwt_snapshot (&now, &ncpu, &total_size,
data->ioc_pbuf1, data->ioc_plen1);
+ data->ioc_u64[0] = now;
+ data->ioc_u32[0] = ncpu;
+ data->ioc_u32[1] = total_size;
+
+ /* Hedge against broken user/kernel typedefs (e.g. cycles_t) */
+ data->ioc_u32[2] = sizeof(lwt_event_t);
+ data->ioc_u32[3] = offsetof(lwt_event_t, lwte_where);
+
if (err == 0 &&
- copy_to_user((char *)arg, data, sizeof (*data)))
+ libcfs_ioctl_popdata(arg, data, sizeof (*data)))
err = -EFAULT;
break;
-
- case IOC_PORTAL_LWT_LOOKUP_STRING:
+ }
+
+ case IOC_LIBCFS_LWT_LOOKUP_STRING:
err = lwt_lookup_string (&data->ioc_count, data->ioc_pbuf1,
data->ioc_pbuf2, data->ioc_plen2);
if (err == 0 &&
- copy_to_user((char *)arg, data, sizeof (*data)))
+ libcfs_ioctl_popdata(arg, data, sizeof (*data)))
err = -EFAULT;
break;
#endif
- case IOC_PORTAL_NAL_CMD: {
- struct portals_cfg pcfg;
-
- LASSERT (data->ioc_plen1 == sizeof(pcfg));
- if (copy_from_user(&pcfg, (void *)data->ioc_pbuf1,
- sizeof(pcfg))) {
- err = -EFAULT;
- break;
- }
-
- CDEBUG (D_IOCTL, "nal command nal %d cmd %d\n", pcfg.pcfg_nal,
- pcfg.pcfg_command);
- err = libcfs_nal_cmd(&pcfg);
-
- if (err == 0 &&
- copy_to_user((char *)data->ioc_pbuf1, &pcfg,
- sizeof (pcfg)))
- err = -EFAULT;
- break;
- }
-
- case IOC_PORTAL_MEMHOG:
- if (!capable (CAP_SYS_ADMIN))
- err = -EPERM;
- else if (file->private_data == NULL) {
+ case IOC_LIBCFS_MEMHOG:
+ if (pfile->private_data == NULL) {
err = -EINVAL;
} else {
- kportal_memhog_free(file->private_data);
- err = kportal_memhog_alloc(file->private_data,
+ kportal_memhog_free(pfile->private_data);
+ /* XXX The ioc_flags is not GFP flags now, need to be fixed */
+ err = kportal_memhog_alloc(pfile->private_data,
data->ioc_count,
data->ioc_flags);
if (err != 0)
- kportal_memhog_free(file->private_data);
+ kportal_memhog_free(pfile->private_data);
}
break;
+ case IOC_LIBCFS_PING_TEST: {
+ extern void (kping_client)(struct libcfs_ioctl_data *);
+ void (*ping)(struct libcfs_ioctl_data *);
+
+ CDEBUG(D_IOCTL, "doing %d pings to nid %s (%s)\n",
+ data->ioc_count, libcfs_nid2str(data->ioc_nid),
+ libcfs_nid2str(data->ioc_nid));
+ ping = PORTAL_SYMBOL_GET(kping_client);
+ if (!ping)
+ CERROR("PORTAL_SYMBOL_GET failed\n");
+ else {
+ ping(data);
+ PORTAL_SYMBOL_PUT(kping_client);
+ }
+ RETURN(0);
+ }
+
default: {
struct libcfs_ioctl_handler *hand;
err = -EINVAL;
down_read(&ioctl_list_sem);
list_for_each_entry(hand, &ioctl_list, item) {
- err = hand->handle_ioctl(data, cmd, arg);
- if (err != -EINVAL)
+ err = hand->handle_ioctl(cmd, data);
+ if (err != -EINVAL) {
+ if (err == 0)
+ err = libcfs_ioctl_popdata(arg,
+ data, sizeof (*data));
break;
+ }
}
up_read(&ioctl_list_sem);
- } break;
+ break;
+ }
}
RETURN(err);
}
-
-static struct file_operations libcfs_fops = {
- ioctl: libcfs_ioctl,
- open: libcfs_psdev_open,
- release: libcfs_psdev_release
-};
-
-
-static struct miscdevice libcfs_dev = {
- PORTAL_MINOR,
- "portals",
- &libcfs_fops
+struct cfs_psdev_ops libcfs_psdev_ops = {
+ libcfs_psdev_open,
+ libcfs_psdev_release,
+ NULL,
+ NULL,
+ libcfs_ioctl
};
extern int insert_proc(void);
MODULE_DESCRIPTION("Portals v3.1");
MODULE_LICENSE("GPL");
+extern cfs_psdev_t libcfs_dev;
+extern struct rw_semaphore tracefile_sem;
+extern struct semaphore trace_thread_sem;
+
+extern void libcfs_init_nidstrings(void);
+extern int libcfs_arch_init(void);
+extern void libcfs_arch_cleanup(void);
+
static int init_libcfs_module(void)
{
int rc;
- rc = portals_debug_init(5 * 1024 * 1024);
+ libcfs_arch_init();
+ libcfs_init_nidstrings();
+ init_rwsem(&tracefile_sem);
+ init_mutex(&trace_thread_sem);
+ init_rwsem(&ioctl_list_sem);
+ CFS_INIT_LIST_HEAD(&ioctl_list);
+
+ rc = libcfs_debug_init(5 * 1024 * 1024);
if (rc < 0) {
- printk(KERN_ERR "LustreError: portals_debug_init: %d\n", rc);
+ printk(KERN_ERR "LustreError: libcfs_debug_init: %d\n", rc);
return (rc);
}
goto cleanup_debug;
}
#endif
- rc = misc_register(&libcfs_dev);
+ rc = cfs_psdev_register(&libcfs_dev);
if (rc) {
CERROR("misc_register: error %d\n", rc);
goto cleanup_lwt;
return (0);
cleanup_deregister:
- misc_deregister(&libcfs_dev);
+ cfs_psdev_deregister(&libcfs_dev);
cleanup_lwt:
#if LWT_SUPPORT
lwt_fini();
cleanup_debug:
#endif
- portals_debug_cleanup();
+ libcfs_debug_cleanup();
return rc;
}
remove_proc();
CDEBUG(D_MALLOC, "before Portals cleanup: kmem %d\n",
- atomic_read(&portal_kmemory));
-
+ atomic_read(&libcfs_kmemory));
- rc = misc_deregister(&libcfs_dev);
+ rc = cfs_psdev_deregister(&libcfs_dev);
if (rc)
CERROR("misc_deregister error %d\n", rc);
lwt_fini();
#endif
- if (atomic_read(&portal_kmemory) != 0)
+ if (atomic_read(&libcfs_kmemory) != 0)
CERROR("Portals memory leaked: %d bytes\n",
- atomic_read(&portal_kmemory));
+ atomic_read(&libcfs_kmemory));
- rc = portals_debug_cleanup();
+ rc = libcfs_debug_cleanup();
if (rc)
- printk(KERN_ERR "LustreError: portals_debug_cleanup: %d\n", rc);
+ printk(KERN_ERR "LustreError: libcfs_debug_cleanup: %d\n", rc);
+ libcfs_arch_cleanup();
}
-EXPORT_SYMBOL(kportal_daemonize);
-EXPORT_SYMBOL(kportal_blockallsigs);
-EXPORT_SYMBOL(kportal_assertion_failed);
-
-module_init(init_libcfs_module);
-module_exit(exit_libcfs_module);
+cfs_module(libcfs, "1.0.0", init_libcfs_module, exit_libcfs_module);