2008-02-26 23:36:04 +03:00
|
|
|
/*
|
2008-02-28 02:42:31 +03:00
|
|
|
* My intent is to create a loadable 'splat' (solaris porting layer
|
|
|
|
* aggressive test) module which can be used as an access point to
|
|
|
|
* run in kernel Solaris ABI regression tests. This provides a
|
|
|
|
* nice mechanism to validate the shim primates are working properly.
|
2008-02-26 23:36:04 +03:00
|
|
|
*
|
2008-02-28 02:42:31 +03:00
|
|
|
* The basic design is the splat module is that it is constructed of
|
|
|
|
* various splat_* source files each of which contains regression tests.
|
|
|
|
* For example the splat_linux_kmem.c file contains tests for validating
|
|
|
|
* kmem correctness. When the splat module is loaded splat_*_init()
|
|
|
|
* will be called for each subsystems tests, similarly splat_*_fini() is
|
|
|
|
* called when the splat module is removed. Each test can then be
|
2008-02-26 23:36:04 +03:00
|
|
|
* run by making an ioctl() call from a userspace control application
|
|
|
|
* to pick the subsystem and test which should be run.
|
|
|
|
*
|
|
|
|
* Author: Brian Behlendorf
|
|
|
|
*/
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
#include "splat-internal.h"
|
|
|
|
#include <config.h>
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
|
|
|
|
#include <linux/devfs_fs_kernel.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <linux/cdev.h>
|
|
|
|
|
|
|
|
|
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
|
2008-02-28 02:42:31 +03:00
|
|
|
static struct class_simple *splat_class;
|
2008-02-26 23:36:04 +03:00
|
|
|
#else
|
2008-02-28 02:42:31 +03:00
|
|
|
static struct class *splat_class;
|
2008-02-26 23:36:04 +03:00
|
|
|
#endif
|
2008-02-28 02:42:31 +03:00
|
|
|
static struct list_head splat_module_list;
|
|
|
|
static spinlock_t splat_module_lock;
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
static int
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_open(struct inode *inode, struct file *file)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
|
|
|
unsigned int minor = iminor(inode);
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_info_t *info;
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
if (minor >= SPLAT_MINORS)
|
2008-02-26 23:36:04 +03:00
|
|
|
return -ENXIO;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
info = (splat_info_t *)kmalloc(sizeof(*info), GFP_KERNEL);
|
2008-02-26 23:36:04 +03:00
|
|
|
if (info == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
spin_lock_init(&info->info_lock);
|
2008-02-28 02:42:31 +03:00
|
|
|
info->info_size = SPLAT_INFO_BUFFER_SIZE;
|
|
|
|
info->info_buffer = (char *)vmalloc(SPLAT_INFO_BUFFER_SIZE);
|
2008-02-26 23:36:04 +03:00
|
|
|
if (info->info_buffer == NULL) {
|
|
|
|
kfree(info);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->info_head = info->info_buffer;
|
|
|
|
file->private_data = (void *)info;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_release(struct inode *inode, struct file *file)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
|
|
|
unsigned int minor = iminor(inode);
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_info_t *info = (splat_info_t *)file->private_data;
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
if (minor >= SPLAT_MINORS)
|
2008-02-26 23:36:04 +03:00
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
ASSERT(info);
|
|
|
|
ASSERT(info->info_buffer);
|
|
|
|
|
|
|
|
vfree(info->info_buffer);
|
|
|
|
kfree(info);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_buffer_clear(struct file *file, splat_cfg_t *kcfg, unsigned long arg)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_info_t *info = (splat_info_t *)file->private_data;
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
ASSERT(info);
|
|
|
|
ASSERT(info->info_buffer);
|
|
|
|
|
|
|
|
spin_lock(&info->info_lock);
|
|
|
|
memset(info->info_buffer, 0, info->info_size);
|
|
|
|
info->info_head = info->info_buffer;
|
|
|
|
spin_unlock(&info->info_lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_buffer_size(struct file *file, splat_cfg_t *kcfg, unsigned long arg)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_info_t *info = (splat_info_t *)file->private_data;
|
2008-02-26 23:36:04 +03:00
|
|
|
char *buf;
|
|
|
|
int min, size, rc = 0;
|
|
|
|
|
|
|
|
ASSERT(info);
|
|
|
|
ASSERT(info->info_buffer);
|
|
|
|
|
|
|
|
spin_lock(&info->info_lock);
|
|
|
|
if (kcfg->cfg_arg1 > 0) {
|
|
|
|
|
|
|
|
size = kcfg->cfg_arg1;
|
|
|
|
buf = (char *)vmalloc(size);
|
|
|
|
if (buf == NULL) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Zero fill and truncate contents when coping buffer */
|
|
|
|
min = ((size < info->info_size) ? size : info->info_size);
|
|
|
|
memset(buf, 0, size);
|
|
|
|
memcpy(buf, info->info_buffer, min);
|
|
|
|
vfree(info->info_buffer);
|
|
|
|
info->info_size = size;
|
|
|
|
info->info_buffer = buf;
|
|
|
|
info->info_head = info->info_buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
kcfg->cfg_rc1 = info->info_size;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
if (copy_to_user((struct splat_cfg_t __user *)arg, kcfg, sizeof(*kcfg)))
|
2008-02-26 23:36:04 +03:00
|
|
|
rc = -EFAULT;
|
|
|
|
out:
|
|
|
|
spin_unlock(&info->info_lock);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
static splat_subsystem_t *
|
|
|
|
splat_subsystem_find(int id) {
|
|
|
|
splat_subsystem_t *sub;
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
spin_lock(&splat_module_lock);
|
|
|
|
list_for_each_entry(sub, &splat_module_list, subsystem_list) {
|
2008-02-26 23:36:04 +03:00
|
|
|
if (id == sub->desc.id) {
|
2008-02-28 02:42:31 +03:00
|
|
|
spin_unlock(&splat_module_lock);
|
2008-02-26 23:36:04 +03:00
|
|
|
return sub;
|
|
|
|
}
|
|
|
|
}
|
2008-02-28 02:42:31 +03:00
|
|
|
spin_unlock(&splat_module_lock);
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_subsystem_count(splat_cfg_t *kcfg, unsigned long arg)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_subsystem_t *sub;
|
2008-02-26 23:36:04 +03:00
|
|
|
int i = 0;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
spin_lock(&splat_module_lock);
|
|
|
|
list_for_each_entry(sub, &splat_module_list, subsystem_list)
|
2008-02-26 23:36:04 +03:00
|
|
|
i++;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
spin_unlock(&splat_module_lock);
|
2008-02-26 23:36:04 +03:00
|
|
|
kcfg->cfg_rc1 = i;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
if (copy_to_user((struct splat_cfg_t __user *)arg, kcfg, sizeof(*kcfg)))
|
2008-02-26 23:36:04 +03:00
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_subsystem_list(splat_cfg_t *kcfg, unsigned long arg)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_subsystem_t *sub;
|
|
|
|
splat_cfg_t *tmp;
|
2008-02-26 23:36:04 +03:00
|
|
|
int size, i = 0;
|
|
|
|
|
|
|
|
/* Structure will be sized large enough for N subsystem entries
|
|
|
|
* which is passed in by the caller. On exit the number of
|
|
|
|
* entries filled in with valid subsystems will be stored in
|
|
|
|
* cfg_rc1. If the caller does not provide enough entries
|
|
|
|
* for all subsystems we will truncate the list to avoid overrun.
|
|
|
|
*/
|
2008-02-28 02:42:31 +03:00
|
|
|
size = sizeof(*tmp) + kcfg->cfg_data.splat_subsystems.size *
|
|
|
|
sizeof(splat_user_t);
|
2008-02-26 23:36:04 +03:00
|
|
|
tmp = kmalloc(size, GFP_KERNEL);
|
|
|
|
if (tmp == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* Local 'tmp' is used as the structure copied back to user space */
|
|
|
|
memset(tmp, 0, size);
|
|
|
|
memcpy(tmp, kcfg, sizeof(*kcfg));
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
spin_lock(&splat_module_lock);
|
|
|
|
list_for_each_entry(sub, &splat_module_list, subsystem_list) {
|
|
|
|
strncpy(tmp->cfg_data.splat_subsystems.descs[i].name,
|
|
|
|
sub->desc.name, SPLAT_NAME_SIZE);
|
|
|
|
strncpy(tmp->cfg_data.splat_subsystems.descs[i].desc,
|
|
|
|
sub->desc.desc, SPLAT_DESC_SIZE);
|
|
|
|
tmp->cfg_data.splat_subsystems.descs[i].id = sub->desc.id;
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
/* Truncate list if we are about to overrun alloc'ed memory */
|
2008-02-28 02:42:31 +03:00
|
|
|
if ((i++) == kcfg->cfg_data.splat_subsystems.size)
|
2008-02-26 23:36:04 +03:00
|
|
|
break;
|
|
|
|
}
|
2008-02-28 02:42:31 +03:00
|
|
|
spin_unlock(&splat_module_lock);
|
2008-02-26 23:36:04 +03:00
|
|
|
tmp->cfg_rc1 = i;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
if (copy_to_user((struct splat_cfg_t __user *)arg, tmp, size)) {
|
2008-02-26 23:36:04 +03:00
|
|
|
kfree(tmp);
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(tmp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_test_count(splat_cfg_t *kcfg, unsigned long arg)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_subsystem_t *sub;
|
|
|
|
splat_test_t *test;
|
2008-02-27 22:09:51 +03:00
|
|
|
int i = 0;
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
/* Subsystem ID passed as arg1 */
|
2008-02-28 02:42:31 +03:00
|
|
|
sub = splat_subsystem_find(kcfg->cfg_arg1);
|
2008-02-26 23:36:04 +03:00
|
|
|
if (sub == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
spin_lock(&(sub->test_lock));
|
|
|
|
list_for_each_entry(test, &(sub->test_list), test_list)
|
|
|
|
i++;
|
|
|
|
|
|
|
|
spin_unlock(&(sub->test_lock));
|
|
|
|
kcfg->cfg_rc1 = i;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
if (copy_to_user((struct splat_cfg_t __user *)arg, kcfg, sizeof(*kcfg)))
|
2008-02-26 23:36:04 +03:00
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_test_list(splat_cfg_t *kcfg, unsigned long arg)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_subsystem_t *sub;
|
|
|
|
splat_test_t *test;
|
|
|
|
splat_cfg_t *tmp;
|
2008-02-27 22:09:51 +03:00
|
|
|
int size, i = 0;
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
/* Subsystem ID passed as arg1 */
|
2008-02-28 02:42:31 +03:00
|
|
|
sub = splat_subsystem_find(kcfg->cfg_arg1);
|
2008-02-26 23:36:04 +03:00
|
|
|
if (sub == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Structure will be sized large enough for N test entries
|
|
|
|
* which is passed in by the caller. On exit the number of
|
|
|
|
* entries filled in with valid tests will be stored in
|
|
|
|
* cfg_rc1. If the caller does not provide enough entries
|
|
|
|
* for all tests we will truncate the list to avoid overrun.
|
|
|
|
*/
|
2008-02-28 02:42:31 +03:00
|
|
|
size = sizeof(*tmp)+kcfg->cfg_data.splat_tests.size*sizeof(splat_user_t);
|
2008-02-26 23:36:04 +03:00
|
|
|
tmp = kmalloc(size, GFP_KERNEL);
|
|
|
|
if (tmp == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* Local 'tmp' is used as the structure copied back to user space */
|
|
|
|
memset(tmp, 0, size);
|
|
|
|
memcpy(tmp, kcfg, sizeof(*kcfg));
|
|
|
|
|
|
|
|
spin_lock(&(sub->test_lock));
|
|
|
|
list_for_each_entry(test, &(sub->test_list), test_list) {
|
2008-02-28 02:42:31 +03:00
|
|
|
strncpy(tmp->cfg_data.splat_tests.descs[i].name,
|
|
|
|
test->desc.name, SPLAT_NAME_SIZE);
|
|
|
|
strncpy(tmp->cfg_data.splat_tests.descs[i].desc,
|
|
|
|
test->desc.desc, SPLAT_DESC_SIZE);
|
|
|
|
tmp->cfg_data.splat_tests.descs[i].id = test->desc.id;
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
/* Truncate list if we are about to overrun alloc'ed memory */
|
2008-02-28 02:42:31 +03:00
|
|
|
if ((i++) == kcfg->cfg_data.splat_tests.size)
|
2008-02-26 23:36:04 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
spin_unlock(&(sub->test_lock));
|
|
|
|
tmp->cfg_rc1 = i;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
if (copy_to_user((struct splat_cfg_t __user *)arg, tmp, size)) {
|
2008-02-26 23:36:04 +03:00
|
|
|
kfree(tmp);
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(tmp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_validate(struct file *file, splat_subsystem_t *sub, int cmd, void *arg)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_test_t *test;
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
spin_lock(&(sub->test_lock));
|
|
|
|
list_for_each_entry(test, &(sub->test_list), test_list) {
|
|
|
|
if (test->desc.id == cmd) {
|
|
|
|
spin_unlock(&(sub->test_lock));
|
|
|
|
return test->test(file, arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock(&(sub->test_lock));
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_ioctl_cfg(struct file *file, unsigned long arg)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_cfg_t kcfg;
|
2008-02-26 23:36:04 +03:00
|
|
|
int rc = 0;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
if (copy_from_user(&kcfg, (splat_cfg_t *)arg, sizeof(kcfg)))
|
2008-02-26 23:36:04 +03:00
|
|
|
return -EFAULT;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
if (kcfg.cfg_magic != SPLAT_CFG_MAGIC) {
|
|
|
|
splat_print(file, "Bad config magic 0x%x != 0x%x\n",
|
|
|
|
kcfg.cfg_magic, SPLAT_CFG_MAGIC);
|
2008-02-26 23:36:04 +03:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (kcfg.cfg_cmd) {
|
2008-02-28 02:42:31 +03:00
|
|
|
case SPLAT_CFG_BUFFER_CLEAR:
|
2008-02-26 23:36:04 +03:00
|
|
|
/* cfg_arg1 - Unused
|
|
|
|
* cfg_rc1 - Unused
|
|
|
|
*/
|
2008-02-28 02:42:31 +03:00
|
|
|
rc = splat_buffer_clear(file, &kcfg, arg);
|
2008-02-26 23:36:04 +03:00
|
|
|
break;
|
2008-02-28 02:42:31 +03:00
|
|
|
case SPLAT_CFG_BUFFER_SIZE:
|
2008-02-26 23:36:04 +03:00
|
|
|
/* cfg_arg1 - 0 - query size; >0 resize
|
|
|
|
* cfg_rc1 - Set to current buffer size
|
|
|
|
*/
|
2008-02-28 02:42:31 +03:00
|
|
|
rc = splat_buffer_size(file, &kcfg, arg);
|
2008-02-26 23:36:04 +03:00
|
|
|
break;
|
2008-02-28 02:42:31 +03:00
|
|
|
case SPLAT_CFG_SUBSYSTEM_COUNT:
|
2008-02-26 23:36:04 +03:00
|
|
|
/* cfg_arg1 - Unused
|
|
|
|
* cfg_rc1 - Set to number of subsystems
|
|
|
|
*/
|
2008-02-28 02:42:31 +03:00
|
|
|
rc = splat_subsystem_count(&kcfg, arg);
|
2008-02-26 23:36:04 +03:00
|
|
|
break;
|
2008-02-28 02:42:31 +03:00
|
|
|
case SPLAT_CFG_SUBSYSTEM_LIST:
|
2008-02-26 23:36:04 +03:00
|
|
|
/* cfg_arg1 - Unused
|
|
|
|
* cfg_rc1 - Set to number of subsystems
|
2008-02-28 02:42:31 +03:00
|
|
|
* cfg_data.splat_subsystems - Populated with subsystems
|
2008-02-26 23:36:04 +03:00
|
|
|
*/
|
2008-02-28 02:42:31 +03:00
|
|
|
rc = splat_subsystem_list(&kcfg, arg);
|
2008-02-26 23:36:04 +03:00
|
|
|
break;
|
2008-02-28 02:42:31 +03:00
|
|
|
case SPLAT_CFG_TEST_COUNT:
|
2008-02-26 23:36:04 +03:00
|
|
|
/* cfg_arg1 - Set to a target subsystem
|
|
|
|
* cfg_rc1 - Set to number of tests
|
|
|
|
*/
|
2008-02-28 02:42:31 +03:00
|
|
|
rc = splat_test_count(&kcfg, arg);
|
2008-02-26 23:36:04 +03:00
|
|
|
break;
|
2008-02-28 02:42:31 +03:00
|
|
|
case SPLAT_CFG_TEST_LIST:
|
2008-02-26 23:36:04 +03:00
|
|
|
/* cfg_arg1 - Set to a target subsystem
|
|
|
|
* cfg_rc1 - Set to number of tests
|
2008-02-28 02:42:31 +03:00
|
|
|
* cfg_data.splat_subsystems - Populated with tests
|
2008-02-26 23:36:04 +03:00
|
|
|
*/
|
2008-02-28 02:42:31 +03:00
|
|
|
rc = splat_test_list(&kcfg, arg);
|
2008-02-26 23:36:04 +03:00
|
|
|
break;
|
|
|
|
default:
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_print(file, "Bad config command %d\n", kcfg.cfg_cmd);
|
2008-02-26 23:36:04 +03:00
|
|
|
rc = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_ioctl_cmd(struct file *file, unsigned long arg)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_subsystem_t *sub;
|
|
|
|
splat_cmd_t kcmd;
|
2008-02-26 23:36:04 +03:00
|
|
|
int rc = -EINVAL;
|
|
|
|
void *data = NULL;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
if (copy_from_user(&kcmd, (splat_cfg_t *)arg, sizeof(kcmd)))
|
2008-02-26 23:36:04 +03:00
|
|
|
return -EFAULT;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
if (kcmd.cmd_magic != SPLAT_CMD_MAGIC) {
|
|
|
|
splat_print(file, "Bad command magic 0x%x != 0x%x\n",
|
|
|
|
kcmd.cmd_magic, SPLAT_CFG_MAGIC);
|
2008-02-26 23:36:04 +03:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate memory for any opaque data the caller needed to pass on */
|
|
|
|
if (kcmd.cmd_data_size > 0) {
|
|
|
|
data = (void *)kmalloc(kcmd.cmd_data_size, GFP_KERNEL);
|
|
|
|
if (data == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
if (copy_from_user(data, (void *)(arg + offsetof(splat_cmd_t,
|
2008-02-26 23:36:04 +03:00
|
|
|
cmd_data_str)), kcmd.cmd_data_size)) {
|
|
|
|
kfree(data);
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
sub = splat_subsystem_find(kcmd.cmd_subsystem);
|
2008-02-26 23:36:04 +03:00
|
|
|
if (sub != NULL)
|
2008-02-28 02:42:31 +03:00
|
|
|
rc = splat_validate(file, sub, kcmd.cmd_test, data);
|
2008-02-26 23:36:04 +03:00
|
|
|
else
|
|
|
|
rc = -EINVAL;
|
|
|
|
|
|
|
|
if (data != NULL)
|
|
|
|
kfree(data);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_ioctl(struct inode *inode, struct file *file,
|
2008-02-26 23:36:04 +03:00
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
2008-02-27 22:09:51 +03:00
|
|
|
unsigned int minor = iminor(file->f_dentry->d_inode);
|
|
|
|
int rc = 0;
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
/* Ignore tty ioctls */
|
|
|
|
if ((cmd & 0xffffff00) == ((int)'T') << 8)
|
|
|
|
return -ENOTTY;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
if (minor >= SPLAT_MINORS)
|
2008-02-26 23:36:04 +03:00
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
switch (cmd) {
|
2008-02-28 02:42:31 +03:00
|
|
|
case SPLAT_CFG:
|
|
|
|
rc = splat_ioctl_cfg(file, arg);
|
2008-02-26 23:36:04 +03:00
|
|
|
break;
|
2008-02-28 02:42:31 +03:00
|
|
|
case SPLAT_CMD:
|
|
|
|
rc = splat_ioctl_cmd(file, arg);
|
2008-02-26 23:36:04 +03:00
|
|
|
break;
|
|
|
|
default:
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_print(file, "Bad ioctl command %d\n", cmd);
|
2008-02-26 23:36:04 +03:00
|
|
|
rc = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* I'm not sure why you would want to write in to this buffer from
|
|
|
|
* user space since its principle use is to pass test status info
|
|
|
|
* back to the user space, but I don't see any reason to prevent it.
|
|
|
|
*/
|
2008-02-28 02:42:31 +03:00
|
|
|
static ssize_t splat_write(struct file *file, const char __user *buf,
|
2008-02-26 23:36:04 +03:00
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
unsigned int minor = iminor(file->f_dentry->d_inode);
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_info_t *info = (splat_info_t *)file->private_data;
|
2008-02-26 23:36:04 +03:00
|
|
|
int rc = 0;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
if (minor >= SPLAT_MINORS)
|
2008-02-26 23:36:04 +03:00
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
ASSERT(info);
|
|
|
|
ASSERT(info->info_buffer);
|
|
|
|
|
|
|
|
spin_lock(&info->info_lock);
|
|
|
|
|
|
|
|
/* Write beyond EOF */
|
|
|
|
if (*ppos >= info->info_size) {
|
|
|
|
rc = -EFBIG;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Resize count if beyond EOF */
|
|
|
|
if (*ppos + count > info->info_size)
|
|
|
|
count = info->info_size - *ppos;
|
|
|
|
|
|
|
|
if (copy_from_user(info->info_buffer, buf, count)) {
|
|
|
|
rc = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppos += count;
|
|
|
|
rc = count;
|
|
|
|
out:
|
|
|
|
spin_unlock(&info->info_lock);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
static ssize_t splat_read(struct file *file, char __user *buf,
|
2008-02-26 23:36:04 +03:00
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
unsigned int minor = iminor(file->f_dentry->d_inode);
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_info_t *info = (splat_info_t *)file->private_data;
|
2008-02-26 23:36:04 +03:00
|
|
|
int rc = 0;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
if (minor >= SPLAT_MINORS)
|
2008-02-26 23:36:04 +03:00
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
ASSERT(info);
|
|
|
|
ASSERT(info->info_buffer);
|
|
|
|
|
|
|
|
spin_lock(&info->info_lock);
|
|
|
|
|
|
|
|
/* Read beyond EOF */
|
|
|
|
if (*ppos >= info->info_size)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Resize count if beyond EOF */
|
|
|
|
if (*ppos + count > info->info_size)
|
|
|
|
count = info->info_size - *ppos;
|
|
|
|
|
|
|
|
if (copy_to_user(buf, info->info_buffer + *ppos, count)) {
|
|
|
|
rc = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppos += count;
|
|
|
|
rc = count;
|
|
|
|
out:
|
|
|
|
spin_unlock(&info->info_lock);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
static loff_t splat_seek(struct file *file, loff_t offset, int origin)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
|
|
|
unsigned int minor = iminor(file->f_dentry->d_inode);
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_info_t *info = (splat_info_t *)file->private_data;
|
2008-02-26 23:36:04 +03:00
|
|
|
int rc = -EINVAL;
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
if (minor >= SPLAT_MINORS)
|
2008-02-26 23:36:04 +03:00
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
ASSERT(info);
|
|
|
|
ASSERT(info->info_buffer);
|
|
|
|
|
|
|
|
spin_lock(&info->info_lock);
|
|
|
|
|
|
|
|
switch (origin) {
|
|
|
|
case 0: /* SEEK_SET - No-op just do it */
|
|
|
|
break;
|
|
|
|
case 1: /* SEEK_CUR - Seek from current */
|
|
|
|
offset = file->f_pos + offset;
|
|
|
|
break;
|
|
|
|
case 2: /* SEEK_END - Seek from end */
|
|
|
|
offset = info->info_size + offset;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset >= 0) {
|
|
|
|
file->f_pos = offset;
|
|
|
|
file->f_version = 0;
|
|
|
|
rc = offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock(&info->info_lock);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
static struct file_operations splat_fops = {
|
2008-02-26 23:36:04 +03:00
|
|
|
.owner = THIS_MODULE,
|
2008-02-28 02:42:31 +03:00
|
|
|
.open = splat_open,
|
|
|
|
.release = splat_release,
|
|
|
|
.ioctl = splat_ioctl,
|
|
|
|
.read = splat_read,
|
|
|
|
.write = splat_write,
|
|
|
|
.llseek = splat_seek,
|
2008-02-26 23:36:04 +03:00
|
|
|
};
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
static struct cdev splat_cdev = {
|
2008-02-26 23:36:04 +03:00
|
|
|
.owner = THIS_MODULE,
|
2008-02-28 02:42:31 +03:00
|
|
|
.kobj = { .name = "splatctl", },
|
2008-02-26 23:36:04 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_init(void)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
|
|
|
dev_t dev;
|
2008-02-27 22:09:51 +03:00
|
|
|
int rc;
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
spin_lock_init(&splat_module_lock);
|
|
|
|
INIT_LIST_HEAD(&splat_module_list);
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
SPLAT_SUBSYSTEM_INIT(kmem);
|
|
|
|
SPLAT_SUBSYSTEM_INIT(taskq);
|
|
|
|
SPLAT_SUBSYSTEM_INIT(krng);
|
|
|
|
SPLAT_SUBSYSTEM_INIT(mutex);
|
|
|
|
SPLAT_SUBSYSTEM_INIT(condvar);
|
|
|
|
SPLAT_SUBSYSTEM_INIT(thread);
|
|
|
|
SPLAT_SUBSYSTEM_INIT(rwlock);
|
|
|
|
SPLAT_SUBSYSTEM_INIT(time);
|
2008-03-12 23:52:46 +03:00
|
|
|
SPLAT_SUBSYSTEM_INIT(vnode);
|
2008-03-11 23:54:40 +03:00
|
|
|
SPLAT_SUBSYSTEM_INIT(kobj);
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
dev = MKDEV(SPLAT_MAJOR, 0);
|
|
|
|
if ((rc = register_chrdev_region(dev, SPLAT_MINORS, "splatctl")))
|
2008-02-26 23:36:04 +03:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* Support for registering a character driver */
|
2008-02-28 02:42:31 +03:00
|
|
|
cdev_init(&splat_cdev, &splat_fops);
|
|
|
|
if ((rc = cdev_add(&splat_cdev, dev, SPLAT_MINORS))) {
|
|
|
|
printk(KERN_ERR "splat: Error adding cdev, %d\n", rc);
|
|
|
|
kobject_put(&splat_cdev.kobj);
|
|
|
|
unregister_chrdev_region(dev, SPLAT_MINORS);
|
2008-02-26 23:36:04 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Support for udev make driver info available in sysfs */
|
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_class = class_simple_create(THIS_MODULE, "splat");
|
2008-02-26 23:36:04 +03:00
|
|
|
#else
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_class = class_create(THIS_MODULE, "splat");
|
2008-02-26 23:36:04 +03:00
|
|
|
#endif
|
2008-02-28 02:42:31 +03:00
|
|
|
if (IS_ERR(splat_class)) {
|
|
|
|
rc = PTR_ERR(splat_class);
|
|
|
|
printk(KERN_ERR "splat: Error creating splat class, %d\n", rc);
|
|
|
|
cdev_del(&splat_cdev);
|
|
|
|
unregister_chrdev_region(dev, SPLAT_MINORS);
|
2008-02-26 23:36:04 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
|
2008-02-28 02:42:31 +03:00
|
|
|
class_simple_device_add(splat_class, MKDEV(SPLAT_MAJOR, 0),
|
|
|
|
NULL, "splatctl");
|
2008-02-26 23:36:04 +03:00
|
|
|
#else
|
2008-02-28 02:42:31 +03:00
|
|
|
class_device_create(splat_class, NULL, MKDEV(SPLAT_MAJOR, 0),
|
|
|
|
NULL, "splatctl");
|
2008-02-26 23:36:04 +03:00
|
|
|
#endif
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
printk(KERN_INFO "splat: Loaded Solaris Porting Layer "
|
|
|
|
"Aggressive Tests v%s\n", VERSION);
|
2008-02-26 23:36:04 +03:00
|
|
|
return 0;
|
|
|
|
error:
|
2008-02-28 02:42:31 +03:00
|
|
|
printk(KERN_ERR "splat: Error registering splat device, %d\n", rc);
|
2008-02-26 23:36:04 +03:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_fini(void)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
2008-02-28 02:42:31 +03:00
|
|
|
dev_t dev = MKDEV(SPLAT_MAJOR, 0);
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
|
|
|
|
class_simple_device_remove(dev);
|
2008-02-28 02:42:31 +03:00
|
|
|
class_simple_destroy(splat_class);
|
|
|
|
devfs_remove("splat/splatctl");
|
|
|
|
devfs_remove("splat");
|
2008-02-26 23:36:04 +03:00
|
|
|
#else
|
2008-02-28 02:42:31 +03:00
|
|
|
class_device_destroy(splat_class, dev);
|
|
|
|
class_destroy(splat_class);
|
2008-02-26 23:36:04 +03:00
|
|
|
#endif
|
2008-02-28 02:42:31 +03:00
|
|
|
cdev_del(&splat_cdev);
|
|
|
|
unregister_chrdev_region(dev, SPLAT_MINORS);
|
|
|
|
|
2008-03-11 23:54:40 +03:00
|
|
|
SPLAT_SUBSYSTEM_FINI(kobj);
|
2008-03-12 23:52:46 +03:00
|
|
|
SPLAT_SUBSYSTEM_FINI(vnode);
|
2008-02-28 02:42:31 +03:00
|
|
|
SPLAT_SUBSYSTEM_FINI(time);
|
|
|
|
SPLAT_SUBSYSTEM_FINI(rwlock);
|
|
|
|
SPLAT_SUBSYSTEM_FINI(thread);
|
|
|
|
SPLAT_SUBSYSTEM_FINI(condvar);
|
|
|
|
SPLAT_SUBSYSTEM_FINI(mutex);
|
|
|
|
SPLAT_SUBSYSTEM_FINI(krng);
|
|
|
|
SPLAT_SUBSYSTEM_FINI(taskq);
|
|
|
|
SPLAT_SUBSYSTEM_FINI(kmem);
|
|
|
|
|
|
|
|
ASSERT(list_empty(&splat_module_list));
|
|
|
|
printk(KERN_INFO "splat: Unloaded Solaris Porting Layer "
|
|
|
|
"Aggressive Tests v%s\n", VERSION);
|
2008-02-26 23:36:04 +03:00
|
|
|
}
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
module_init(splat_init);
|
|
|
|
module_exit(splat_fini);
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Lawrence Livermore National Labs");
|
2008-02-28 02:42:31 +03:00
|
|
|
MODULE_DESCRIPTION("Solaris Porting Layer Aggresive Tests");
|
2008-02-26 23:36:04 +03:00
|
|
|
MODULE_LICENSE("GPL");
|