2010-05-18 02:18:00 +04:00
|
|
|
/*****************************************************************************\
|
|
|
|
* Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
|
|
|
|
* Copyright (C) 2007 The Regents of the University of California.
|
|
|
|
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
|
|
|
|
* Written by Brian Behlendorf <behlendorf1@llnl.gov>.
|
2008-05-26 08:38:26 +04:00
|
|
|
* UCRL-CODE-235197
|
|
|
|
*
|
2010-05-18 02:18:00 +04:00
|
|
|
* This file is part of the SPL, Solaris Porting Layer.
|
2013-03-05 05:26:55 +04:00
|
|
|
* For details, see <http://zfsonlinux.org/>.
|
2010-05-18 02:18:00 +04:00
|
|
|
*
|
|
|
|
* The SPL is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
2008-05-26 08:38:26 +04:00
|
|
|
*
|
2010-05-18 02:18:00 +04:00
|
|
|
* The SPL is distributed in the hope that it will be useful, but WITHOUT
|
2008-05-26 08:38:26 +04:00
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2010-05-18 02:18:00 +04:00
|
|
|
* with the SPL. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*****************************************************************************
|
|
|
|
* Solaris Porting LAyer Tests (SPLAT) Test Control Interface.
|
|
|
|
*
|
|
|
|
* The 'splat' (Solaris Porting LAyer Tests) module is designed as a
|
|
|
|
* framework which runs various in kernel regression tests to validate
|
|
|
|
* the SPL primitives honor the Solaris ABI.
|
2008-02-26 23:36:04 +03:00
|
|
|
*
|
2010-05-18 02:18:00 +04:00
|
|
|
* The splat module is constructed of various splat_* source files each
|
|
|
|
* of which contain regression tests for a particular subsystem. For
|
|
|
|
* example, the splat_kmem.c file contains all the tests for validating
|
|
|
|
* the kmem interfaces have been implemented correctly. When the splat
|
|
|
|
* module is loaded splat_*_init() will be called for each subsystems
|
|
|
|
* tests. It is the responsibility of splat_*_init() to register all
|
2016-12-15 05:24:47 +03:00
|
|
|
* the tests for this subsystem using the splat_test_init().
|
2010-05-18 02:18:00 +04:00
|
|
|
* Similarly splat_*_fini() is called when the splat module is removed
|
2016-12-15 05:24:47 +03:00
|
|
|
* and is responsible for unregistering its tests via the splat_test_fini.
|
|
|
|
* Once a test is registered it can then be run with an ioctl()
|
2010-05-18 02:18:00 +04:00
|
|
|
* call which specifies the subsystem and test to be run. The provided
|
|
|
|
* splat command line tool can be used to display all available
|
|
|
|
* subsystems and tests. It can also be used to run the full suite
|
|
|
|
* of regression tests or particular tests.
|
|
|
|
\*****************************************************************************/
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2014-11-14 21:18:05 +03:00
|
|
|
#include <sys/debug.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/types.h>
|
2012-11-03 02:29:44 +04:00
|
|
|
#include <linux/cdev.h>
|
|
|
|
#include <linux/fs.h>
|
2014-09-30 03:42:15 +04:00
|
|
|
#include <linux/miscdevice.h>
|
2014-11-14 21:18:05 +03:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/vmalloc.h>
|
2008-02-28 02:42:31 +03:00
|
|
|
#include "splat-internal.h"
|
2008-02-26 23:36:04 +03:00
|
|
|
|
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
|
|
|
{
|
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
|
|
|
info = (splat_info_t *)kmalloc(sizeof(*info), GFP_KERNEL);
|
2008-02-26 23:36:04 +03:00
|
|
|
if (info == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2014-09-30 02:00:46 +04:00
|
|
|
mutex_init(&info->info_lock, SPLAT_NAME, MUTEX_DEFAULT, NULL);
|
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;
|
|
|
|
}
|
2010-07-01 21:12:57 +04:00
|
|
|
memset(info->info_buffer, 0, info->info_size);
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
info->info_head = info->info_buffer;
|
|
|
|
file->private_data = (void *)info;
|
|
|
|
|
2010-07-01 21:12:57 +04:00
|
|
|
splat_print(file, "%s\n", spl_version);
|
|
|
|
|
|
|
|
return 0;
|
2008-02-26 23:36:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
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);
|
|
|
|
|
2012-11-03 02:31:04 +04:00
|
|
|
mutex_destroy(&info->info_lock);
|
2008-02-26 23:36:04 +03:00
|
|
|
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);
|
|
|
|
|
2014-09-30 02:00:46 +04:00
|
|
|
mutex_enter(&info->info_lock);
|
2008-02-26 23:36:04 +03:00
|
|
|
memset(info->info_buffer, 0, info->info_size);
|
|
|
|
info->info_head = info->info_buffer;
|
2014-09-30 02:00:46 +04:00
|
|
|
mutex_exit(&info->info_lock);
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2014-09-30 02:00:46 +04:00
|
|
|
mutex_enter(&info->info_lock);
|
2008-02-26 23:36:04 +03:00
|
|
|
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:
|
2014-09-30 02:00:46 +04:00
|
|
|
mutex_exit(&info->info_lock);
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
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
|
2009-05-21 21:56:11 +04:00
|
|
|
splat_ioctl_cfg(struct file *file, unsigned int cmd, 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;
|
|
|
|
|
2009-05-21 21:56:11 +04:00
|
|
|
/* User and kernel space agree about arg size */
|
|
|
|
if (_IOC_SIZE(cmd) != sizeof(kcfg))
|
|
|
|
return -EBADMSG;
|
|
|
|
|
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
|
2009-05-21 21:56:11 +04:00
|
|
|
* cfg_data.splat_subsystems - Set 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:
|
2009-05-21 21:56:11 +04: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
|
2009-05-21 21:56:11 +04:00
|
|
|
splat_ioctl_cmd(struct file *file, unsigned int cmd, 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;
|
|
|
|
|
2009-05-21 21:56:11 +04:00
|
|
|
/* User and kernel space agree about arg size */
|
|
|
|
if (_IOC_SIZE(cmd) != sizeof(kcmd))
|
|
|
|
return -EBADMSG;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-11-10 23:58:07 +03:00
|
|
|
static long
|
|
|
|
splat_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
2008-02-27 22:09:51 +03:00
|
|
|
int rc = 0;
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
/* Ignore tty ioctls */
|
|
|
|
if ((cmd & 0xffffff00) == ((int)'T') << 8)
|
|
|
|
return -ENOTTY;
|
|
|
|
|
|
|
|
switch (cmd) {
|
2008-02-28 02:42:31 +03:00
|
|
|
case SPLAT_CFG:
|
2009-05-21 21:56:11 +04:00
|
|
|
rc = splat_ioctl_cfg(file, cmd, arg);
|
2008-02-26 23:36:04 +03:00
|
|
|
break;
|
2008-02-28 02:42:31 +03:00
|
|
|
case SPLAT_CMD:
|
2009-05-21 21:56:11 +04:00
|
|
|
rc = splat_ioctl_cmd(file, cmd, 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;
|
|
|
|
}
|
|
|
|
|
2009-05-21 03:33:08 +04:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
/* Compatibility handler for ioctls from 32-bit ELF binaries */
|
|
|
|
static long
|
|
|
|
splat_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
2010-11-10 23:58:07 +03:00
|
|
|
return splat_unlocked_ioctl(file, cmd, arg);
|
2009-05-21 03:33:08 +04:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_COMPAT */
|
|
|
|
|
2008-02-26 23:36:04 +03:00
|
|
|
/* 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)
|
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
ASSERT(info);
|
|
|
|
ASSERT(info->info_buffer);
|
|
|
|
|
2014-09-30 02:00:46 +04:00
|
|
|
mutex_enter(&info->info_lock);
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
/* 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:
|
2014-09-30 02:00:46 +04:00
|
|
|
mutex_exit(&info->info_lock);
|
2008-02-26 23:36:04 +03:00
|
|
|
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)
|
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
ASSERT(info);
|
|
|
|
ASSERT(info->info_buffer);
|
|
|
|
|
2014-09-30 02:00:46 +04:00
|
|
|
mutex_enter(&info->info_lock);
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
/* 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:
|
2014-09-30 02:00:46 +04:00
|
|
|
mutex_exit(&info->info_lock);
|
2008-02-26 23:36:04 +03:00
|
|
|
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
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
ASSERT(info);
|
|
|
|
ASSERT(info->info_buffer);
|
|
|
|
|
2014-09-30 02:00:46 +04:00
|
|
|
mutex_enter(&info->info_lock);
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-09-30 02:00:46 +04:00
|
|
|
mutex_exit(&info->info_lock);
|
2008-02-26 23:36:04 +03:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-02-28 02:42:31 +03:00
|
|
|
static struct file_operations splat_fops = {
|
2009-05-21 03:33:08 +04:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = splat_open,
|
|
|
|
.release = splat_release,
|
2010-11-10 23:58:07 +03:00
|
|
|
.unlocked_ioctl = splat_unlocked_ioctl,
|
2009-05-21 03:33:08 +04:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
.compat_ioctl = splat_compat_ioctl,
|
|
|
|
#endif
|
|
|
|
.read = splat_read,
|
|
|
|
.write = splat_write,
|
|
|
|
.llseek = splat_seek,
|
2008-02-26 23:36:04 +03:00
|
|
|
};
|
|
|
|
|
2014-09-30 03:42:15 +04:00
|
|
|
static struct miscdevice splat_misc = {
|
|
|
|
.minor = MISC_DYNAMIC_MINOR,
|
|
|
|
.name = SPLAT_NAME,
|
|
|
|
.fops = &splat_fops,
|
|
|
|
};
|
|
|
|
|
2016-12-15 05:24:47 +03:00
|
|
|
static void splat_subsystem_init(const char *name,
|
|
|
|
splat_subsystem_t *(*init)(void))
|
|
|
|
{
|
|
|
|
splat_subsystem_t *sub;
|
|
|
|
sub = init();
|
|
|
|
if (sub == NULL) {
|
|
|
|
printk(KERN_ERR "splat: Error initializing: %s\n", name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
spin_lock(&splat_module_lock);
|
|
|
|
list_add_tail(&sub->subsystem_list, &splat_module_list);
|
|
|
|
spin_unlock(&splat_module_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void splat_subsystem_fini(const char *name,
|
|
|
|
int (*id_func)(void), void (*fini)(splat_subsystem_t *))
|
|
|
|
{
|
|
|
|
splat_subsystem_t *sub, *tmp;
|
|
|
|
int id, flag = 0;
|
|
|
|
|
|
|
|
id = id_func();
|
|
|
|
spin_lock(&splat_module_lock);
|
|
|
|
list_for_each_entry_safe(sub, tmp, &splat_module_list, subsystem_list) {
|
|
|
|
if (sub->desc.id == id) {
|
|
|
|
list_del_init(&sub->subsystem_list);
|
|
|
|
flag = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock(&splat_module_lock);
|
|
|
|
if (flag == 0)
|
|
|
|
printk(KERN_ERR "splat: Error finalizing: %s\n", name);
|
|
|
|
else
|
|
|
|
fini(sub);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SPLAT_SUBSYSTEM_INIT(type) \
|
|
|
|
splat_subsystem_init(#type, splat_##type##_init)
|
|
|
|
#define SPLAT_SUBSYSTEM_FINI(type) \
|
|
|
|
splat_subsystem_fini(#type, splat_##type##_id, splat_##type##_fini)
|
|
|
|
|
|
|
|
void splat_test_init(splat_subsystem_t *sub, const char *name,
|
|
|
|
const char *desc, unsigned int tid, splat_test_func_t func)
|
|
|
|
{
|
|
|
|
splat_test_t *test;
|
|
|
|
test = kmalloc(sizeof (splat_test_t), GFP_KERNEL);
|
|
|
|
if (test == NULL) {
|
|
|
|
printk(KERN_ERR "splat: Error initializing: %s/%u\n",
|
|
|
|
name, tid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memset(test, 0, sizeof (splat_test_t));
|
|
|
|
strncpy(test->desc.name, name, SPLAT_NAME_SIZE-1);
|
|
|
|
strncpy(test->desc.desc, desc, SPLAT_DESC_SIZE-1);
|
|
|
|
test->desc.id = tid;
|
|
|
|
test->test = func;
|
|
|
|
INIT_LIST_HEAD(&test->test_list);
|
|
|
|
spin_lock(&sub->test_lock);
|
|
|
|
list_add_tail(&test->test_list, &sub->test_list);
|
|
|
|
spin_unlock(&sub->test_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void splat_test_fini(splat_subsystem_t *sub, unsigned int tid)
|
|
|
|
{
|
|
|
|
splat_test_t *test, *tmp;
|
|
|
|
int flag = 0;
|
|
|
|
|
|
|
|
spin_lock(&sub->test_lock);
|
|
|
|
list_for_each_entry_safe(test, tmp, &sub->test_list, test_list) {
|
|
|
|
if (test->desc.id == tid) {
|
|
|
|
list_del_init(&test->test_list);
|
|
|
|
kfree(test);
|
|
|
|
flag = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock(&sub->test_lock);
|
|
|
|
|
|
|
|
if (flag == 0)
|
|
|
|
printk(KERN_ERR "splat: Error finalizing: %u\n", tid);
|
|
|
|
}
|
|
|
|
|
2015-02-19 02:24:15 +03:00
|
|
|
static int __init
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_init(void)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
2014-09-30 03:42:15 +04:00
|
|
|
int error;
|
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-03-28 21:21:09 +03:00
|
|
|
SPLAT_SUBSYSTEM_INIT(atomic);
|
2009-01-07 23:54:03 +03:00
|
|
|
SPLAT_SUBSYSTEM_INIT(list);
|
2009-01-13 20:30:59 +03:00
|
|
|
SPLAT_SUBSYSTEM_INIT(generic);
|
2009-07-28 04:18:59 +04:00
|
|
|
SPLAT_SUBSYSTEM_INIT(cred);
|
2011-02-26 02:48:18 +03:00
|
|
|
SPLAT_SUBSYSTEM_INIT(zlib);
|
2011-06-21 21:57:48 +04:00
|
|
|
SPLAT_SUBSYSTEM_INIT(linux);
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2014-09-30 03:42:15 +04:00
|
|
|
error = misc_register(&splat_misc);
|
|
|
|
if (error) {
|
|
|
|
printk(KERN_INFO "SPLAT: misc_register() failed %d\n", error);
|
|
|
|
} else {
|
|
|
|
printk(KERN_INFO "SPLAT: Loaded module v%s-%s%s\n",
|
|
|
|
SPL_META_VERSION, SPL_META_RELEASE, SPL_DEBUG_STR);
|
2008-02-26 23:36:04 +03:00
|
|
|
}
|
|
|
|
|
2014-09-30 03:42:15 +04:00
|
|
|
return (error);
|
2008-02-26 23:36:04 +03:00
|
|
|
}
|
|
|
|
|
2015-02-19 02:24:15 +03:00
|
|
|
static void __exit
|
2008-02-28 02:42:31 +03:00
|
|
|
splat_fini(void)
|
2008-02-26 23:36:04 +03:00
|
|
|
{
|
2015-09-01 19:17:24 +03:00
|
|
|
misc_deregister(&splat_misc);
|
2008-02-28 02:42:31 +03:00
|
|
|
|
2011-06-21 21:57:48 +04:00
|
|
|
SPLAT_SUBSYSTEM_FINI(linux);
|
2011-02-26 02:48:18 +03:00
|
|
|
SPLAT_SUBSYSTEM_FINI(zlib);
|
2009-07-28 04:18:59 +04:00
|
|
|
SPLAT_SUBSYSTEM_FINI(cred);
|
2009-01-13 20:30:59 +03:00
|
|
|
SPLAT_SUBSYSTEM_FINI(generic);
|
2009-01-07 23:54:03 +03:00
|
|
|
SPLAT_SUBSYSTEM_FINI(list);
|
2008-03-28 21:21:09 +03:00
|
|
|
SPLAT_SUBSYSTEM_FINI(atomic);
|
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));
|
2012-03-23 23:03:57 +04:00
|
|
|
printk(KERN_INFO "SPLAT: Unloaded module v%s-%s%s\n",
|
2014-09-30 03:42:15 +04:00
|
|
|
SPL_META_VERSION, SPL_META_RELEASE, SPL_DEBUG_STR);
|
2008-02-26 23:36:04 +03:00
|
|
|
}
|
|
|
|
|
2015-02-19 02:24:15 +03:00
|
|
|
module_init(splat_init);
|
|
|
|
module_exit(splat_fini);
|
2008-02-26 23:36:04 +03:00
|
|
|
|
2008-05-26 08:38:26 +04:00
|
|
|
MODULE_DESCRIPTION("Solaris Porting LAyer Tests");
|
2014-09-30 00:01:22 +04:00
|
|
|
MODULE_AUTHOR(SPL_META_AUTHOR);
|
|
|
|
MODULE_LICENSE(SPL_META_LICENSE);
|
2013-12-04 22:14:14 +04:00
|
|
|
MODULE_VERSION(SPL_META_VERSION "-" SPL_META_RELEASE);
|