Commit 3cd0f0df authored by Arun Gopalakrishnan's avatar Arun Gopalakrishnan Committed by Hari Kanigeri

IPC_Fix_Nameserver_And_Multiproc This includes the fixes in nameserver and...

IPC_Fix_Nameserver_And_Multiproc This includes the fixes in nameserver and multiproc modules during testing.

The additional changes in ioctl file to make sysc with
the changes propossed by Suman (command changes, copy
commands at a common place etc)
Signed-off-by: default avatarArun M G <arunmg@ti.com>
parent 34ae4756
......@@ -44,16 +44,18 @@ enum CMD_NAMESERVER {
* IOCTL command IDs for nameserver
*
*/
/*
* Command for nameserver_setup
*/
#define CMD_NAMESERVER_SETUP _IO(IPC_IOC_MAGIC, NAMESERVER_SETUP)
#define CMD_NAMESERVER_SETUP _IOWR(IPC_IOC_MAGIC, NAMESERVER_SETUP, \
struct nameserver_cmd_args)
/*
* Command for nameserver_destroy
*/
#define CMD_NAMESERVER_DESTROY _IO(IPC_IOC_MAGIC, NAMESERVER_DESTROY)
#define CMD_NAMESERVER_DESTROY _IOWR(IPC_IOC_MAGIC, \
NAMESERVER_DESTROY, \
struct nameserver_cmd_args)
/*
* Command for nameserver_params_init
......@@ -65,13 +67,15 @@ enum CMD_NAMESERVER {
/*
* Command for nameserver_create
*/
#define CMD_NAMESERVER_CREATE _IOWR(IPC_IOC_MAGIC, NAMESERVER_CREATE,\
#define CMD_NAMESERVER_CREATE _IOWR(IPC_IOC_MAGIC, \
NAMESERVER_CREATE, \
struct nameserver_cmd_args)
/*
* Command for nameserver_delete
*/
#define CMD_NAMESERVER_DELETE _IOWR(IPC_IOC_MAGIC, NAMESERVER_DELETE,\
#define CMD_NAMESERVER_DELETE _IOWR(IPC_IOC_MAGIC, \
NAMESERVER_DELETE, \
struct nameserver_cmd_args)
/*
......@@ -108,13 +112,13 @@ enum CMD_NAMESERVER {
/*
* Command for nameserver_remove
*/
#define CMD_NAMESERVER_REMOVE _IOW(IPC_IOC_MAGIC, NAMESERVER_REMOVE, \
#define CMD_NAMESERVER_REMOVE _IOWR(IPC_IOC_MAGIC, NAMESERVER_REMOVE,\
struct nameserver_cmd_args)
/*
* Command for nameserver_remove_entry
*/
#define CMD_NAMESERVER_REMOVEENTRY _IOW(IPC_IOC_MAGIC, \
#define CMD_NAMESERVER_REMOVEENTRY _IOWR(IPC_IOC_MAGIC, \
NAMESERVER_REMOVEENTRY, \
struct nameserver_cmd_args)
......@@ -212,7 +216,7 @@ enum CMD_NAMESERVER {
* Command arguments for nameserver
*/
struct nameserver_cmd_args {
union nameserver_arg cmd_arg;
union nameserver_arg args;
s32 api_status;
};
......
......@@ -26,9 +26,9 @@
#include <linux/types.h>
#include <linux/string.h>
#include <gt.h>
#include <multiproc.h>
#define MULTIPROC_MAXPROCESSORS 4
/*
* Local processor's id. It has to be set before any module init.
*/
......@@ -40,7 +40,7 @@ struct multiproc_module_object {
/* TDO:Add these back to the StateObject and configure them during Driver
* bootup using a Module_Init function.
*/
static char modena[32] = "Modena";
static char modena[32] = "MPU";
static char tesla[32] = "Tesla";
static char sysm3[32] = "SysM3";
static char appm3[32] = "AppM3";
......@@ -61,9 +61,6 @@ bool multiproc_set_local_id(u16 proc_id)
{
bool status = true;
gt_1trace(mulproc_mask, GT_ENTER,
"multiProc_set_local_id: id = %d\n", proc_id);
if (proc_id >= MULTIPROC_MAXPROCESSORS)
status = false;
else
......@@ -81,9 +78,6 @@ u16 multiproc_get_id(const char *proc_name)
s32 i;
u16 proc_id = MULTIPROC_INVALIDID;
gt_1trace(mulproc_mask, GT_ENTER,
"multiproc_get_id: proc_name = %%s\n", proc_name);
/* If the name is NULL, just return the local id */
if (proc_name == NULL) {
proc_id = module->local_id;
......@@ -107,10 +101,8 @@ u16 multiproc_get_id(const char *proc_name)
*/
char *multiproc_get_name(u16 proc_id)
{
char *proc_name = 0;
char *proc_name = NULL;
gt_1trace(mulproc_mask, GT_ENTER,
"multiproc_get_name: id = %d\n", proc_id);
if (proc_id >= MULTIPROC_MAXPROCESSORS)
goto end;
......
......@@ -16,24 +16,20 @@
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/
#include <linux/module.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/list.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <gt.h>
#include <nameserver.h>
#include <multiproc.h>
#include <nameserver_remote.h>
/* Stubs for ipc dependent module functions */
#define nameserver_remote_transport() 0
#define NS_MAX_NAME_LEN 16
#define NS_MAX_RUNTIME_ENTRY 0
#define NS_MAX_VALUE_LEN 0
#define NS_MAX_NAME_LEN 32
#define NS_MAX_RUNTIME_ENTRY (~0)
#define NS_MAX_VALUE_LEN 4
/*
* The dynamic name/value table looks like the following. This approach allows
......@@ -228,14 +224,10 @@ int nameserver_setup(void)
s32 retval = 0;
u16 nr_procs = 0;
gt_0trace(ns_debugmask, GT_ENTER, "nameserver_setup:\n");
nr_procs = multiproc_get_max_processors();
list = kmalloc(nr_procs * sizeof(struct nameserver_remote_object *),
GFP_KERNEL);
if (list == NULL) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_setup: memory allocation"
" failed!\n");
retval = -ENOMEM;
goto error;
}
......@@ -244,9 +236,6 @@ int nameserver_setup(void)
nameserver_state.remote_handle_list = list;
nameserver_state.list_lock = kmalloc(sizeof(struct mutex), GFP_KERNEL);
if (nameserver_state.list_lock == NULL) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_setup: memory allocation"
" failed!\n");
retval = -ENOMEM;
goto error;
}
......@@ -256,9 +245,11 @@ int nameserver_setup(void)
return 0;
error:
printk(KERN_ERR "nameserver_setup failed, retval: %x\n", retval);
kfree(list);
return retval;
}
EXPORT_SYMBOL(nameserver_setup);
/*
* ======== nameserver_destroy ========
......@@ -270,7 +261,6 @@ int nameserver_destroy(void)
s32 retval = 0;
struct mutex *lock = NULL;
gt_0trace(ns_debugmask, GT_ENTER, "nameserver_destroy:\n");
if (WARN_ON(nameserver_state.list_lock == NULL)) {
retval = -ENODEV;
goto exit;
......@@ -278,18 +268,13 @@ int nameserver_destroy(void)
/* If a nameserver instance exist, do not proceed */
if (!list_empty(&nameserver_state.obj_list)) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_destroy: nameserver in use!\n");
retval = -EBUSY;
goto exit;
}
retval = mutex_lock_interruptible(nameserver_state.list_lock);
if (retval) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_destroy: lock failed!\n");
if (retval)
goto exit;
}
lock = nameserver_state.list_lock;
nameserver_state.list_lock = NULL;
......@@ -300,8 +285,10 @@ int nameserver_destroy(void)
return 0;
exit:
printk(KERN_ERR "nameserver_destroy failed, retval: %x\n", retval);
return retval;
}
EXPORT_SYMBOL(nameserver_destroy);
/*!
* Purpose:
......@@ -310,10 +297,7 @@ exit:
*/
int nameserver_params_init(struct nameserver_params *params)
{
gt_1trace(ns_debugmask, GT_ENTER, "nameserver_params_init:\n"
"params: %x\n", params);
BUG_ON(params == NULL);
params->check_existing = true;
params->gate_handle = NULL;
params->max_name_len = NS_MAX_NAME_LEN;
......@@ -322,6 +306,7 @@ int nameserver_params_init(struct nameserver_params *params)
params->table_heap = NULL;
return 0;
}
EXPORT_SYMBOL(nameserver_params_init);
/*
* ======== nameserver_get_params ========
......@@ -334,10 +319,7 @@ int nameserver_get_params(void *handle,
{
struct nameserver_object *nshandle = NULL;
gt_2trace(ns_debugmask, GT_ENTER, "nameserver_get_params:\n"
"handle: %x, params: %x\n", handle, params);
BUG_ON(params == NULL);
if (handle == NULL) {
params->check_existing = true;
params->max_name_len = NS_MAX_NAME_LEN;
......@@ -357,6 +339,7 @@ int nameserver_get_params(void *handle,
}
return 0;
}
EXPORT_SYMBOL(nameserver_get_params);
/*
* ======== nameserver_get_params ========
......@@ -368,18 +351,17 @@ void *nameserver_get_handle(const char *name)
{
struct nameserver_object *obj = NULL;
gt_1trace(ns_debugmask, GT_6CLASS,
"nameserver_get_handle:\n name: %s\n", name);
BUG_ON(name == NULL);
list_for_each_entry(obj, &nameserver_state.obj_list, elem) {
if (strcmp(obj->name, name) == 0)
goto exit;
goto succes;
}
return NULL;
exit:
succes:
return (void *)obj;
}
EXPORT_SYMBOL(nameserver_get_handle);
/*
* ======== nameserver_create ========
......@@ -393,50 +375,34 @@ void *nameserver_create(const char *name,
u32 name_len;
s32 retval = 0;
gt_2trace(ns_debugmask, GT_6CLASS, "nameserver_create:\n"
" name: %s,\n params: %x\n", name, params);
BUG_ON(name == NULL);
BUG_ON(params == NULL);
name_len = strlen(name) + 1;
if (name_len > params->max_name_len) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_create_instance: argument is too"
" big!\n");
retval = E2BIG;
goto exit;
}
retval = mutex_lock_interruptible(nameserver_state.list_lock);
if (retval) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_create_instance: lock failed!\n");
if (retval)
goto exit;
}
/* check if the name is already registered or not */
new_obj = nameserver_get_handle(name);
if (new_obj != NULL) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_create_instance: name in use!\n");
retval = EEXIST;
goto error;
}
new_obj = kmalloc(sizeof(struct nameserver_object), GFP_KERNEL);
if (new_obj == NULL) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_create_instance: memory allocation"
" failed!\n");
retval = -ENOMEM;
goto error;
}
new_obj->name = kmalloc(name_len, GFP_ATOMIC);
if (new_obj->name == NULL) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_create_instance: memory allocation"
" failed!\n");
retval = -ENOMEM;
goto error;
}
......@@ -449,21 +415,14 @@ void *nameserver_create(const char *name,
else
new_obj->params.max_value_len = params->max_value_len;
/* Set up the gate for this instance */
if (params->gate_handle == NULL) {
new_obj->gate_handle =
new_obj->gate_handle =
kmalloc(sizeof(struct mutex), GFP_KERNEL);
if (new_obj->gate_handle == NULL) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_create_instance: memory "
"allocation failed!\n");
if (new_obj->gate_handle == NULL) {
retval = -ENOMEM;
goto error_mutex;
}
mutex_init(new_obj->gate_handle);
} else
new_obj->gate_handle = (struct mutex *)params->gate_handle;
}
mutex_init(new_obj->gate_handle);
new_obj->count = 0;
/* Put in the nameserver instance to local list */
INIT_LIST_HEAD(&new_obj->name_list);
......@@ -479,8 +438,10 @@ error:
kfree(new_obj);
exit:
printk(KERN_ERR "nameserver_create failed retval:%x \n", retval);
return NULL;
}
EXPORT_SYMBOL(nameserver_create);
/*
......@@ -495,34 +456,21 @@ int nameserver_delete(void **handle)
bool localgate = false;
s32 retval = 0;
gt_2trace(ns_debugmask, GT_6CLASS,
"nameserver_delete:\n"
"handle: %x, *handle: %x\n", handle, *handle);
BUG_ON(handle == NULL);
BUG_ON(*handle == NULL);
temp_obj = (struct nameserver_object *) (*handle);
retval = mutex_lock_interruptible(temp_obj->gate_handle);
if (retval) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_delete_instance: lock failed!\n");
if (retval)
goto exit;
}
/* Do not proceed if an entry in the in the table */
if (temp_obj->count != 0) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_delete_instance: instance in use!\n");
retval = -EBUSY;
goto error;
}
retval = mutex_lock_interruptible(nameserver_state.list_lock);
if (retval) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_delete_instance: lock failed!\n");
if (retval)
goto error;
}
list_del(&temp_obj->elem);
mutex_unlock(nameserver_state.list_lock);
......@@ -544,8 +492,10 @@ int nameserver_delete(void **handle)
error:
mutex_unlock(temp_obj->gate_handle);
exit:
printk(KERN_ERR "nameserver_delete failed retval:%x \n", retval);
return retval;
}
EXPORT_SYMBOL(nameserver_delete);
/*
* ======== nameserver_is_entry_found ========
......@@ -598,11 +548,6 @@ void *nameserver_add(void *handle, const char *name,
u32 name_len;
s32 retval = 0;
gt_4trace(ns_debugmask, GT_6CLASS,
"nameserver_add:\n"
"name: %s,\n handle: %x, buffer: %x,"
" length: %x\n", name, handle, buffer,
length);
BUG_ON(handle == NULL);
BUG_ON(name == NULL);
BUG_ON(buffer == NULL);
......@@ -613,15 +558,10 @@ void *nameserver_add(void *handle, const char *name,
temp_obj = (struct nameserver_object *)handle;
retval = mutex_lock_interruptible(temp_obj->gate_handle);
if (retval) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_add: lock failed!\n");
if (retval)
goto exit;
}
if (temp_obj->count >= temp_obj->params.max_runtime_entries) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_add: table full!)\n");
retval = -ENOSPC;
goto error;
}
......@@ -629,8 +569,6 @@ void *nameserver_add(void *handle, const char *name,
/* make the null char in to account */
name_len = strlen(name) + 1;
if (name_len > temp_obj->params.max_name_len) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_add: argument too big!\n");
retval = -E2BIG;
goto error;
}
......@@ -640,16 +578,12 @@ void *nameserver_add(void *handle, const char *name,
found = nameserver_is_entry_found(name, hash,
&temp_obj->name_list, &new_node);
if (found == true) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_add: entry exists!\n");
retval = -EEXIST;
goto error;
}
new_node = kmalloc(sizeof(struct nameserver_entry), GFP_KERNEL);
if (new_node == NULL) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_add: memory allocation failed!\n");
retval = -ENOMEM;
goto error;
}
......@@ -659,17 +593,13 @@ void *nameserver_add(void *handle, const char *name,
new_node->len = length;
new_node->next = NULL;
new_node->name = kmalloc(name_len, GFP_KERNEL);
if (new_node->name) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_add: memory allocation failed!\n");
if (new_node->name == NULL) {
retval = -ENOMEM;
goto error;
}
new_node->buf = kmalloc(length, GFP_KERNEL);
if (new_node->buf) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_add: memory allocation failed!\n");
if (new_node->buf == NULL) {
retval = -ENOMEM;
goto error1;
}
......@@ -688,9 +618,11 @@ error:
mutex_unlock(temp_obj->gate_handle);
kfree(new_node);
exit:
printk(KERN_ERR "nameserver_add failed status: %x \n", retval);
return NULL;
}
EXPORT_SYMBOL(nameserver_add);
/*
* ======== nameserver_add_uint32 ========
......@@ -701,16 +633,13 @@ void *nameserver_add_uint32(void *handle, const char *name,
u32 value)
{
struct nameserver_entry *new_node = NULL;
gt_3trace(ns_debugmask, GT_6CLASS,
"nameserver_add_uint32:\n"
"name: %s,\n handle: %x, value: %x\n",
name, handle, value);
BUG_ON(handle == NULL);
BUG_ON(name == NULL);
new_node = nameserver_add(handle, name, &value, sizeof(u32));
return new_node;
}
EXPORT_SYMBOL(nameserver_add_uint32);
/*
* ======== nameserver_remove ========
......@@ -726,35 +655,25 @@ int nameserver_remove(void *handle, const char *name)
u32 name_len;
s32 retval = 0;
gt_2trace(ns_debugmask, GT_6CLASS,
"nameserver_remove:\n"
"name: %s, \n handle: %x \n", name, handle);
BUG_ON(handle == NULL);
BUG_ON(name == NULL);
temp_obj = (struct nameserver_object *)handle;
name_len = strlen(name) + 1;
if (name_len > temp_obj->params.max_name_len) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_remove: argument too big!)\n");
retval = -E2BIG;
goto exit;
}
retval = mutex_lock_interruptible(temp_obj->gate_handle);
if (retval) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_remove: lock failed!\n");
if (retval)
goto exit;
}
/* TODO :check collide & hash usage */
hash = nameserver_string_hash(name);
found = nameserver_is_entry_found(name, hash,
&temp_obj->name_list, &entry);
if (found == false) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_remove: entry not exist!)\n");
retval = -ENOENT;
goto error;
}
......@@ -771,8 +690,10 @@ error:
mutex_unlock(temp_obj->gate_handle);
exit:
printk(KERN_ERR "nameserver_remove failed status:%x \n", retval);
return retval;
}
EXPORT_SYMBOL(nameserver_remove);
/*
* ======== nameserver_remove_entry ========
......@@ -785,9 +706,6 @@ int nameserver_remove_entry(void *nshandle, void *nsentry)
struct nameserver_object *handle = NULL;
s32 retval = 0;
gt_2trace(ns_debugmask, GT_6CLASS,
"nameserver_remove_entry:\n"
"nshandle: %x, nsentry: %x \n", nshandle, nsentry);
BUG_ON(nshandle == NULL);
BUG_ON(nsentry == NULL);
......@@ -806,8 +724,10 @@ int nameserver_remove_entry(void *nshandle, void *nsentry)
return 0;
exit:
printk(KERN_ERR "nameserver_remove_entry failed status:%x \n", retval);
return retval;
}
EXPORT_SYMBOL(nameserver_remove_entry);
/*
......@@ -825,10 +745,6 @@ int nameserver_get_local(void *handle, const char *name,
u32 hash;
s32 retval = 0;
gt_4trace(ns_debugmask, GT_6CLASS,
"nameserver_get_local:\n"
"handle: %x, buffer: %x, length: %x, \n"
"name: %s\n", handle, buffer, length, name);
BUG_ON(handle == NULL);
BUG_ON(name == NULL);
BUG_ON(buffer == NULL);
......@@ -839,19 +755,14 @@ int nameserver_get_local(void *handle, const char *name,
temp_obj = (struct nameserver_object *)handle;
retval = mutex_lock_interruptible(temp_obj->gate_handle);
if (retval) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_get_local: lock failed!\n");
if (retval)
goto exit;
}
/* TODO :check collide & hash usage */
hash = nameserver_string_hash(name);
found = nameserver_is_entry_found(name, hash,
&temp_obj->name_list, &entry);
if (found == false) {
gt_0trace(ns_debugmask, GT_6CLASS,
"nameserver_get_local: entry not exist!\n");
retval = -ENOENT;
goto error;
}
......@@ -868,8 +779,11 @@ error:
mutex_unlock(temp_obj->gate_handle);
exit:
printk(KERN_ERR "nameserver_get_local failed status:%x \n",
retval);
return retval;
}
EXPORT_SYMBOL(nameserver_get_local);
/*
* ======== nameserver_get ========
......@@ -886,11 +800,6 @@ int nameserver_get(void *handle, const char *name,
s32 retval = -1;
u32 i;
gt_5trace(ns_debugmask, GT_6CLASS,
"nameserver_get:\n"
"handle: %x, buffer: %x,\n length: %x,"
" proc_id: %x, \n name: %s\n",
handle, buffer, length, proc_id, name);
BUG_ON(handle == NULL);
BUG_ON(name == NULL);
BUG_ON(buffer == NULL);
......@@ -945,8 +854,10 @@ int nameserver_get(void *handle, const char *name,
retval = -ENOENT;
exit:
printk(KERN_ERR "nameserver_get_local failed status:%x \n", retval);
return retval;
}
EXPORT_SYMBOL(nameserver_get);
/*
* ======== nameserver_get ========
......@@ -968,10 +879,6 @@ int nameserver_match(void *handle, const char *name, u32 *value)
u32 hash;
bool found = false;
gt_3trace(ns_debugmask, GT_6CLASS,
"nameserver_match:\n"
"handle: %x, value: %x,\n name: %s\n",
handle, value, name);
BUG_ON(handle == NULL);
BUG_ON(name == NULL);
BUG_ON(value == NULL);
......@@ -993,8 +900,10 @@ int nameserver_match(void *handle, const char *name, u32 *value)
retval = -ENOENT;
exit:
printk(KERN_ERR "nameserver_match failed status:%x \n", retval);
return retval;
}
EXPORT_SYMBOL(nameserver_match);
/*
* ======== nameserver_register_remote_driver ========
......@@ -1007,10 +916,6 @@ int nameserver_register_remote_driver(void *handle, u16 proc_id)
s32 retval = 0;
u16 proc_count;
gt_2trace(ns_debugmask, GT_6CLASS,
"nameserver_register_remote_driver:\n"
"handle: %x, proc_id: %x\n", handle, proc_id);
BUG_ON(handle == NULL);
proc_count = multiproc_get_max_processors();
if (WARN_ON(proc_id >= proc_count)) {
......@@ -1023,8 +928,12 @@ int nameserver_register_remote_driver(void *handle, u16 proc_id)
return 0;
exit:
printk(KERN_ERR
"nameserver_register_remote_driver failed status:%x \n",
retval);
return retval;
}
EXPORT_SYMBOL(nameserver_register_remote_driver);
/*
* ======== nameserver_unregister_remote_driver ========
......@@ -1036,9 +945,6 @@ int nameserver_unregister_remote_driver(u16 proc_id)
s32 retval = 0;
u16 proc_count;
gt_1trace(ns_debugmask, GT_6CLASS,
"nameserver_unregister_remote_driver:\n"
"proc_id: %x\n", proc_id);
proc_count = multiproc_get_max_processors();
if (WARN_ON(proc_id >= proc_count)) {
retval = -EINVAL;
......@@ -1049,6 +955,10 @@ int nameserver_unregister_remote_driver(u16 proc_id)
return 0;
exit:
printk(KERN_ERR
"nameserver_unregister_remote_driver failed status:%x \n",
retval);
return retval;
}
EXPORT_SYMBOL(nameserver_unregister_remote_driver);
......@@ -19,7 +19,6 @@
#include <linux/bug.h>
#include <linux/fs.h>
#include <gt.h>
#include <nameserver.h>
#include <nameserver_ioctl.h>
......@@ -59,32 +58,18 @@ static int nameserver_ioctl_destroy(void)
* This wrapper function will call the nameserver function to
* get the default configuration of a nameserver instance
*/
static int nameserver_ioctl_params_init(struct nameserver_cmd_args *args)
static int nameserver_ioctl_params_init(struct nameserver_cmd_args *cargs)
{
struct nameserver_cmd_args uarg;
struct nameserver_cmd_args *cargs = &uarg;
struct nameserver_params params;
s32 retval = 0;
ulong size;
size = copy_from_user(cargs, args,
sizeof(struct nameserver_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
retval = nameserver_params_init(&params);
size = copy_to_user(cargs->cmd_arg.params_init.params, &params,
size = copy_to_user(cargs->args.params_init.params, &params,
sizeof(struct nameserver_params));
if (size) {
if (size)
retval = -EFAULT;
goto exit;
}
return 0;
exit:
return retval;
}
......@@ -94,47 +79,32 @@ exit:
* This wrapper function will call the nameserver function to
* get the handle of a nameserver instance from name
*/
static int nameserver_ioctl_get_handle(struct nameserver_cmd_args *args)
static int nameserver_ioctl_get_handle(struct nameserver_cmd_args *cargs)
{
struct nameserver_cmd_args uarg;
struct nameserver_cmd_args *cargs = &uarg;
void *handle = NULL;
char *name = NULL;
s32 retval = 0;
ulong size;
size = copy_from_user(cargs, args,
sizeof(struct nameserver_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
name = kmalloc(cargs->cmd_arg.get_handle.name_len, GFP_KERNEL);
name = kmalloc(cargs->args.get_handle.name_len + 1, GFP_KERNEL);
if (name == NULL) {
retval = -ENOMEM;
goto exit;
}
size = copy_from_user(name, cargs->cmd_arg.get_handle.name,
cargs->cmd_arg.get_handle.name_len);
name[cargs->args.get_handle.name_len] = '\0';
size = copy_from_user(name, cargs->args.get_handle.name,
cargs->args.get_handle.name_len);
if (size) {
retval = -EFAULT;
goto name_from_usr_error;
}
handle = nameserver_get_handle(name);
size = copy_to_user(&args->cmd_arg.get_handle.handle, &handle,
sizeof(void *));
if (size) {
retval = -EFAULT;
goto handle_to_usr_error;
}
cargs->args.get_handle.handle = handle;
kfree(name);
return 0;
handle_to_usr_error: /* Fall through */
name_from_usr_error:
kfree(name);
......@@ -148,37 +118,29 @@ exit:
* This wrapper function will call the nameserver function to
* create a name server instance
*/
static int nameserver_ioctl_create(struct nameserver_cmd_args *args)
static int nameserver_ioctl_create(struct nameserver_cmd_args *cargs)
{
struct nameserver_cmd_args uarg;
struct nameserver_cmd_args *cargs = &uarg;
struct nameserver_params params;
void *handle = NULL;
char *name = NULL;
s32 retval = 0;
ulong size;
size = copy_from_user(cargs, args,
sizeof(struct nameserver_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
name = kmalloc(cargs->cmd_arg.create.name_len, GFP_KERNEL);
name = kmalloc(cargs->args.create.name_len + 1, GFP_KERNEL);
if (name == NULL) {
retval = -ENOMEM;
goto exit;
}
size = copy_from_user(name, cargs->cmd_arg.create.name,
cargs->cmd_arg.create.name_len);
name[cargs->args.get_handle.name_len] = '\0';
size = copy_from_user(name, cargs->args.create.name,
cargs->args.create.name_len);
if (size) {
retval = -EFAULT;
goto copy_from_usr_error;
}
size = copy_from_user(&params, cargs->cmd_arg.create.params,
size = copy_from_user(&params, cargs->args.create.params,
sizeof(struct nameserver_params));
if (size) {
retval = -EFAULT;
......@@ -186,20 +148,10 @@ static int nameserver_ioctl_create(struct nameserver_cmd_args *args)
}
handle = nameserver_create(name, &params);
size = copy_to_user(&args->cmd_arg.create.handle, &handle,
sizeof(void *));
if (size) {
retval = -EFAULT;
goto copy_to_usr_error;
}
cargs->args.create.handle = handle;
kfree(name);
return 0;
copy_to_usr_error:
if (handle)
nameserver_delete(handle);
copy_from_usr_error:
kfree(name);
......@@ -214,34 +166,10 @@ exit:
* This wrapper function will call the nameserver function to
* delete a name server instance
*/
static int nameserver_ioctl_delete(struct nameserver_cmd_args *args)
static int nameserver_ioctl_delete(struct nameserver_cmd_args *cargs)
{
struct nameserver_cmd_args uarg;
struct nameserver_cmd_args *cargs = &uarg;
s32 retval = 0;
ulong size;
size = copy_from_user(cargs, args,
sizeof(struct nameserver_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
retval = nameserver_delete(&cargs->cmd_arg.delete_instance.handle);
if (retval)
goto exit;
size = copy_to_user(&args->cmd_arg.delete_instance.handle,
&cargs->cmd_arg.delete_instance.handle, sizeof(void *));
if (size) {
retval = -EFAULT;
goto exit;
}
return 0;
exit:
retval = nameserver_delete(&cargs->args.delete_instance.handle);
return retval;
}
......@@ -251,65 +179,49 @@ exit:
* This wrapper function will call the nameserver function to
* add an entry into a nameserver instance
*/
static int nameserver_ioctl_add(struct nameserver_cmd_args *args)
static int nameserver_ioctl_add(struct nameserver_cmd_args *cargs)
{
struct nameserver_cmd_args uarg;
struct nameserver_cmd_args *cargs = &uarg;
char *name = NULL;
char *buf = NULL;
void *entry;
s32 retval = 0;
ulong size;
size = copy_from_user(cargs, args,
sizeof(struct nameserver_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
name = kmalloc(cargs->cmd_arg.add.name_len, GFP_KERNEL);
if (name) {
name = kmalloc(cargs->args.add.name_len + 1, GFP_KERNEL);
if (name == NULL) {
retval = -ENOMEM;
goto exit;
}
size = copy_from_user(name, cargs->cmd_arg.add.name,
cargs->cmd_arg.add.name_len);
name[cargs->args.get_handle.name_len] = '\0';
size = copy_from_user(name, cargs->args.add.name,
cargs->args.add.name_len);
if (size) {
retval = -EFAULT;
goto name_from_usr_error;
}
buf = kmalloc(cargs->cmd_arg.add.len, GFP_KERNEL);
buf = kmalloc(cargs->args.add.len, GFP_KERNEL);
if (buf == NULL) {
retval = -ENOMEM;
goto buf_alloc_error;
}
size = copy_from_user(buf, cargs->cmd_arg.add.buf,
cargs->cmd_arg.add.len);
size = copy_from_user(buf, cargs->args.add.buf,
cargs->args.add.len);
if (size) {
retval = -EFAULT;
goto buf_from_usr_error;
}
entry = nameserver_add(cargs->cmd_arg.add.handle, name, buf,
cargs->cmd_arg.add.len);
size = copy_to_user(cargs->cmd_arg.add.entry, &entry, sizeof(void *));
if (size) {
retval = -EFAULT;
goto entry_to_usr_error;
}
entry = nameserver_add(cargs->args.add.handle, name, buf,
cargs->args.add.len);
cargs->args.add.entry = entry;
cargs->args.add.node = entry;
kfree(name);
kfree(buf);
return 0;
entry_to_usr_error:
if (entry)
nameserver_remove(entry, name);
buf_from_usr_error:
kfree(buf);
......@@ -328,51 +240,33 @@ exit:
* This wrapper function will call the nameserver function to
* add a Uint32 entry into a nameserver instance
*/
static int nameserver_ioctl_add_uint32(struct nameserver_cmd_args *args)
static int nameserver_ioctl_add_uint32(struct nameserver_cmd_args *cargs)
{
struct nameserver_cmd_args uarg;
struct nameserver_cmd_args *cargs = &uarg;
char *name = NULL;
void *entry;
s32 retval = 0;
ulong size;
size = copy_from_user(cargs, args,
sizeof(struct nameserver_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
name = kmalloc(cargs->cmd_arg.addu32.name_len, GFP_KERNEL);
if (name) {
name = kmalloc(cargs->args.addu32.name_len + 1, GFP_KERNEL);
if (name == NULL) {
retval = -ENOMEM;
goto exit;
}
size = copy_from_user(name, cargs->cmd_arg.addu32.name,
cargs->cmd_arg.addu32.name_len);
name[cargs->args.get_handle.name_len] = '\0';
size = copy_from_user(name, cargs->args.addu32.name,
cargs->args.addu32.name_len);
if (size) {
retval = -EFAULT;
goto name_from_usr_error;
}
entry = nameserver_add_uint32(cargs->cmd_arg.addu32.handle, name,
cargs->cmd_arg.addu32.value);
size = copy_to_user(cargs->cmd_arg.addu32.entry, &entry,
sizeof(void *));
if (size) {
retval = -EFAULT;
goto entry_to_usr_error;
}
entry = nameserver_add_uint32(cargs->args.addu32.handle, name,
cargs->args.addu32.value);
cargs->args.addu32.entry = entry;
kfree(name);
return 0;
entry_to_usr_error:
if (entry)
nameserver_remove(entry, name);
name_from_usr_error:
kfree(name);
......@@ -380,6 +274,7 @@ exit:
return retval;
}
/*
* ======== nameserver_ioctl_match ========
* Purpose:
......@@ -387,37 +282,29 @@ exit:
* to retrieve the value portion of a name/value
* pair from local table
*/
static int nameserver_ioctl_match(struct nameserver_cmd_args *args)
static int nameserver_ioctl_match(struct nameserver_cmd_args *cargs)
{
struct nameserver_cmd_args uarg;
struct nameserver_cmd_args *cargs = &uarg;
char *name = NULL;
u32 buf;
s32 retval = 0;
ulong size;
size = copy_from_user(cargs, args,
sizeof(struct nameserver_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
name = kmalloc(cargs->cmd_arg.match.name_len, GFP_KERNEL);
if (name) {
name = kmalloc(cargs->args.match.name_len + 1, GFP_KERNEL);
if (name == NULL) {
retval = -ENOMEM;
goto exit;
}
size = copy_from_user(name, cargs->cmd_arg.match.name,
cargs->cmd_arg.match.name_len);
name[cargs->args.get_handle.name_len] = '\0';
size = copy_from_user(name, cargs->args.match.name,
cargs->args.match.name_len);
if (size) {
retval = -EFAULT;
goto name_from_usr_error;
}
retval = nameserver_match(cargs->cmd_arg.match.handle, name, &buf);
size = copy_to_user(cargs->cmd_arg.match.value, &buf, sizeof(u32 *));
retval = nameserver_match(cargs->args.match.handle, name, &buf);
size = copy_to_user(cargs->args.match.value, &buf, sizeof(u32 *));
if (size) {
retval = -EFAULT;
goto buf_to_usr_error;
......@@ -440,35 +327,27 @@ exit:
* This wrapper function will call the nameserver function to
* remove a name/value pair from a name server
*/
static int nameserver_ioctl_remove(struct nameserver_cmd_args *args)
static int nameserver_ioctl_remove(struct nameserver_cmd_args *cargs)
{
struct nameserver_cmd_args uarg;
struct nameserver_cmd_args *cargs = &uarg;
char *name = NULL;
s32 retval = 0;
ulong size;
size = copy_from_user(cargs, args,
sizeof(struct nameserver_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
name = kmalloc(cargs->cmd_arg.remove.name_len, GFP_KERNEL);
if (name) {
name = kmalloc(cargs->args.remove.name_len + 1, GFP_KERNEL);
if (name == NULL) {
retval = -ENOMEM;
goto exit;
}
size = copy_from_user(name, cargs->cmd_arg.remove.name,
cargs->cmd_arg.remove.name_len);
name[cargs->args.get_handle.name_len] = '\0';
size = copy_from_user(name, cargs->args.remove.name,
cargs->args.remove.name_len);
if (size) {
retval = -EFAULT;
goto name_from_usr_error;
}
retval = nameserver_remove(cargs->cmd_arg.remove.handle, name);
retval = nameserver_remove(cargs->args.remove.handle, name);
kfree(name);
return 0;
......@@ -479,34 +358,19 @@ exit:
return retval;
}
/*
* ======== nameserver_ioctl_remove_entry ========
* Purpose:
* This wrapper function will call the nameserver function to
* remove an entry from a name server
*/
static int nameserver_ioctl_remove_entry(struct nameserver_cmd_args *args)
static int nameserver_ioctl_remove_entry(struct nameserver_cmd_args *cargs)
{
struct nameserver_cmd_args uarg;
struct nameserver_cmd_args *cargs = &uarg;
s32 retval = 0;
ulong size;
size = copy_from_user(cargs, args,
sizeof(struct nameserver_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
retval = nameserver_remove_entry(cargs->cmd_arg.remove_entry.handle,
cargs->cmd_arg.remove_entry.entry);
if (retval)
goto exit;
return 0;
exit:
retval = nameserver_remove_entry(cargs->args.remove_entry.handle,
cargs->args.remove_entry.entry);
return retval;
}
......@@ -516,45 +380,37 @@ exit:
* This wrapper function will call the nameserver function to
* retrieve the value portion of a name/value pair from local table
*/
static int nameserver_ioctl_get_local(struct nameserver_cmd_args *args)
static int nameserver_ioctl_get_local(struct nameserver_cmd_args *cargs)
{
struct nameserver_cmd_args uarg;
struct nameserver_cmd_args *cargs = &uarg;
char *name = NULL;
char *buf = NULL;
s32 retval = 0;
ulong size;
size = copy_from_user(cargs, args,
sizeof(struct nameserver_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
name = kmalloc(cargs->cmd_arg.get_local.name_len, GFP_KERNEL);
if (name) {
name = kmalloc(cargs->args.get_local.name_len + 1, GFP_KERNEL);
if (name == NULL) {
retval = -ENOMEM;
goto exit;
}
buf = kmalloc(cargs->cmd_arg.get_local.len, GFP_KERNEL);
if (buf) {
name[cargs->args.get_handle.name_len] = '\0';
buf = kmalloc(cargs->args.get_local.len, GFP_KERNEL);
if (buf == NULL) {
retval = -ENOMEM;
goto buf_alloc_error;
}
size = copy_from_user(name, cargs->cmd_arg.get_local.name,
cargs->cmd_arg.get_local.name_len);
size = copy_from_user(name, cargs->args.get_local.name,
cargs->args.get_local.name_len);
if (size) {
retval = -EFAULT;
goto name_from_usr_error;
}
retval = nameserver_get_local(cargs->cmd_arg.get_local.handle, name,
buf, cargs->cmd_arg.get_local.len);
size = copy_to_user(cargs->cmd_arg.get_local.buf, buf,
cargs->cmd_arg.get_local.len);
retval = nameserver_get_local(cargs->args.get_local.handle, name,
buf, cargs->args.get_local.len);
size = copy_to_user(cargs->args.get_local.buf, buf,
cargs->args.get_local.len);
if (size) {
retval = -EFAULT;
goto buf_to_usr_error;
......@@ -575,65 +431,58 @@ exit:
return retval;
}
/*
* ======== nameserver_ioctl_get ========
* Purpose:
* This wrapper function will call the nameserver function to
* retrieve the value portion of a name/value pair from table
*/
static int nameserver_ioctl_get(struct nameserver_cmd_args *args)
static int nameserver_ioctl_get(struct nameserver_cmd_args *cargs)
{
struct nameserver_cmd_args uarg;
struct nameserver_cmd_args *cargs = &uarg;
char *name = NULL;
char *buf = NULL;
u16 *proc_id = NULL;
s32 retval = 0;
ulong size;
size = copy_from_user(cargs, args,
sizeof(struct nameserver_cmd_args));
if (size) {
retval = -EFAULT;
goto exit;
}
name = kmalloc(cargs->cmd_arg.get.name_len, GFP_KERNEL);
if (name) {
name = kmalloc(cargs->args.get.name_len + 1, GFP_KERNEL);
if (name == NULL) {
retval = -ENOMEM;
goto exit;
}
buf = kmalloc(cargs->cmd_arg.get.len, GFP_KERNEL);
if (buf) {
name[cargs->args.get_handle.name_len] = '\0';
buf = kmalloc(cargs->args.get.len, GFP_KERNEL);
if (buf == NULL) {
retval = -ENOMEM;
goto buf_alloc_error;
}
proc_id = kmalloc(cargs->cmd_arg.get.proc_len, GFP_KERNEL);
if (proc_id) {
proc_id = kmalloc(cargs->args.get.proc_len, GFP_KERNEL);
if (proc_id == NULL) {
retval = -ENOMEM;
goto proc_alloc_error;
}
size = copy_from_user(name, cargs->cmd_arg.get.name,
cargs->cmd_arg.get.name_len);
size = copy_from_user(name, cargs->args.get.name,
cargs->args.get.name_len);
if (size) {
retval = -EFAULT;
goto name_from_usr_error;
}
retval = copy_from_user(proc_id, cargs->cmd_arg.get.proc_id,
cargs->cmd_arg.get.proc_len);
retval = copy_from_user(proc_id, cargs->args.get.proc_id,
cargs->args.get.proc_len);
if (size) {
retval = -EFAULT;
goto proc_from_usr_error;
}
retval = nameserver_get(cargs->cmd_arg.get.handle, name, buf,
cargs->cmd_arg.get.len, proc_id);
size = copy_to_user(cargs->cmd_arg.get.buf, buf,
cargs->cmd_arg.get.len);
retval = nameserver_get(cargs->args.get.handle, name, buf,
cargs->args.get.len, proc_id);
size = copy_to_user(cargs->args.get.buf, buf,
cargs->args.get.len);
if (size) {
retval = -EFAULT;
goto buf_to_usr_error;
......@@ -667,84 +516,99 @@ exit:
int nameserver_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long args)
{
s32 os_status = 0;
s32 size = 0;
struct nameserver_cmd_args __user *uarg =
(struct nameserver_cmd_args __user *)args;
s32 retval = 0;
struct nameserver_cmd_args cargs;
gt_4trace(curTrace, GT_ENTER, "nameserver_ioctl"
"inode: %x, filp: %x,\n cmd: %x, args: %x",
inode, filp, cmd, args);
if (_IOC_DIR(cmd) & _IOC_READ)
retval = !access_ok(VERIFY_WRITE, uarg, _IOC_SIZE(cmd));
os_status = !access_ok(VERIFY_WRITE, uarg, _IOC_SIZE(cmd));
else if (_IOC_DIR(cmd) & _IOC_WRITE)
retval = !access_ok(VERIFY_READ, uarg, _IOC_SIZE(cmd));
os_status = !access_ok(VERIFY_READ, uarg, _IOC_SIZE(cmd));
if (retval) {
retval = -EFAULT;
if (os_status) {
os_status = -EFAULT;
goto exit;
}
/* Copy the full args from user-side */
size = copy_from_user(&cargs, uarg,
sizeof(struct nameserver_cmd_args));
if (size) {
os_status = -EFAULT;
goto exit;
}
switch (cmd) {
case CMD_NAMESERVER_ADD:
retval = nameserver_ioctl_add(uarg);
os_status = nameserver_ioctl_add(&cargs);
break;
case CMD_NAMESERVER_ADDUINT32:
retval = nameserver_ioctl_add_uint32(uarg);
os_status = nameserver_ioctl_add_uint32(&cargs);
break;
case CMD_NAMESERVER_GET:
retval = nameserver_ioctl_get(uarg);
os_status = nameserver_ioctl_get(&cargs);
break;
case CMD_NAMESERVER_GETLOCAL:
retval = nameserver_ioctl_get_local(uarg);
os_status = nameserver_ioctl_get_local(&cargs);
break;
case CMD_NAMESERVER_MATCH:
retval = nameserver_ioctl_match(uarg);
os_status = nameserver_ioctl_match(&cargs);
break;
case CMD_NAMESERVER_REMOVE:
retval = nameserver_ioctl_remove(uarg);
os_status = nameserver_ioctl_remove(&cargs);
break;
case CMD_NAMESERVER_REMOVEENTRY:
retval = nameserver_ioctl_remove_entry(uarg);
os_status = nameserver_ioctl_remove_entry(&cargs);
break;
case CMD_NAMESERVER_PARAMS_INIT:
retval = nameserver_ioctl_params_init(uarg);
os_status = nameserver_ioctl_params_init(&cargs);
break;
case CMD_NAMESERVER_CREATE:
retval = nameserver_ioctl_create(uarg);
os_status = nameserver_ioctl_create(&cargs);
break;
case CMD_NAMESERVER_DELETE:
retval = nameserver_ioctl_delete(uarg);
os_status = nameserver_ioctl_delete(&cargs);
break;
case CMD_NAMESERVER_GETHANDLE:
retval = nameserver_ioctl_get_handle(uarg);
os_status = nameserver_ioctl_get_handle(&cargs);
break;
case CMD_NAMESERVER_SETUP:
retval = nameserver_ioctl_setup();
os_status = nameserver_ioctl_setup();
break;
case CMD_NAMESERVER_DESTROY:
retval = nameserver_ioctl_destroy();
os_status = nameserver_ioctl_destroy();
break;
default:
WARN_ON(cmd);
retval = -ENOTTY;
os_status = -ENOTTY;
break;
}
/* Copy the full args to the user-side. */
size = copy_to_user(uarg, &cargs, sizeof(struct nameserver_cmd_args));
if (size) {
os_status = -EFAULT;
goto exit;
}
exit:
return retval;
return os_status;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment