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