Commit c3ddc472 authored by 's avatar
Browse files

function delete_flow() is called inside mapid_process_pkt(). Thus, race...

function delete_flow() is called inside mapid_process_pkt(). Thus, race condition with process packet thread is avoided

git-svn-id: file:///home/svn/mapi/trunk@1319 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 03672cd0
......@@ -268,7 +268,7 @@ process_pkts(void *buf,unsigned len, dag_instance_t *i)
i->hwinfo.pkts++;
}
mapid_delete_flows(&i->mapidlib);
//mapid_delete_flows(&i->mapidlib);
return len - c;
......@@ -313,7 +313,7 @@ process_pkts_offline(void *buf,unsigned len, dag_instance_t *i)
i->hwinfo.pkts++;
}
mapid_delete_flows(&i->mapidlib);
//mapid_delete_flows(&i->mapidlib);
return len - c;
......
......@@ -116,9 +116,6 @@ mapid_init(mapidlib_instance_t *i)
struct group *mapi_group;
struct shmid_ds shm_data;
pthread_mutex_init(&i->lock,NULL);
flist_init(&i->close);
#ifdef WITH_PRIORITIES
int j = 0;
i->flowlist=malloc(sizeof(flist_t*) * PRIORITIES);
......@@ -135,7 +132,6 @@ mapid_init(mapidlib_instance_t *i)
#endif
if(!libs_loaded) {
//mapid_conf = printf_string(CONF_FILE,getenv("HOME"));
mapid_conf = printf_string( CONFDIR"/"CONF_FILE );
//Load function libraries
......@@ -540,20 +536,22 @@ static void delete_flow(mapidlib_instance_t *i,struct mapidlibflow *flow) {
mapidflib_function_t *funct;
DEBUG_CMD(Debug_Message("Deleting flow %d", flow->fd));
((mapid_flow_info_t*)flist_get(flow->hwinfo->gflist->fflist,flow->fd))->status = FLOW_CLOSED; // Update global function list
time(&flow->end); // moved from mapid_close_flow
temp = (void*)flist_get(flow->hwinfo->gflist->fflist,flow->fd); // global optimization
//global optimization
temp = (void*)flist_get(flow->hwinfo->gflist->fflist,flow->fd);
if(!temp){
DEBUG_CMD(Debug_Message("ERROR: Attempt to delete a flow that doesnt exist"));
return;
}
functions= ((mapid_flow_info_t*)temp)->flist;
functions = ((mapid_flow_info_t*)temp)->flist;
if(functions!=NULL)
for(funct_node=flist_head(functions);funct_node!=NULL;funct_node=flist_next(funct_node)) {
funct=(mapidflib_function_t*)flist_data(funct_node);
if(funct->ref==0 && funct->instance->refcount>0 )
//Check to see if other functions references this function
fix_funct_ref(flow->hwinfo->gflist,funct);
fix_funct_ref(flow->hwinfo->gflist,funct); // Check to see if other functions references this function
}
#ifdef WITH_MODIFY_PKTS
......@@ -561,10 +559,6 @@ static void delete_flow(mapidlib_instance_t *i,struct mapidlibflow *flow) {
free(flow->mod_pkt);
#endif
// commented: lock moved to free_functionlist()
// lock=&flow->hwinfo->gflist->lock;
// pthread_spin_lock(lock);
#ifdef WITH_PRIORITIES
f=flist_remove(i->flowlist[flow->priority],flow->fd);
#else
......@@ -585,12 +579,9 @@ static void delete_flow(mapidlib_instance_t *i,struct mapidlibflow *flow) {
free_functionlist(f);
free_sharedmem(f);
free(f);
// pthread_spin_unlock(lock);
}
void mapid_delete_flows(mapidlib_instance_t *i) {
/*void mapid_delete_flows(mapidlib_instance_t *i) { // TODO delete this function ...
flist_node_t *n;
int fd;
......@@ -605,7 +596,7 @@ void mapid_delete_flows(mapidlib_instance_t *i) {
}
pthread_mutex_unlock(&i->lock);
}
}*/
//Frees resources allocated by mapidlib, should be called by the drivers when devices are deleted
......@@ -975,8 +966,6 @@ int
mapid_close_flow(mapidlib_instance_t *i,int fd)
{
struct mapidlibflow *f;
mapidflib_function_t *fn;
flist_node_t *fnode;
#ifdef WITH_PRIORITIES
f=flist_priorities_get(i->flowlist,fd);
......@@ -987,30 +976,8 @@ mapid_close_flow(mapidlib_instance_t *i,int fd)
if(f==NULL)
return -1;
f->status=FLOW_CLOSED;
//Update global function list
((mapid_flow_info_t*)flist_get(f->hwinfo->gflist->fflist,f->fd))->status=FLOW_CLOSED;
time(&f->end);
f->status = FLOW_CLOSED; // flow is deleted in mapid_process_pkt, in order to avoid a race condition with process packet thread
pthread_mutex_lock(&i->lock);
DEBUG_CMD(Debug_Message("Added flow to delete list, fd=%d", fd));
flist_append(&i->close,fd, (void *)0x1); /* 0x1 ... so flist_get works as exist operator */
for(fnode = flist_head(f->functionlist); fnode != NULL; fnode = flist_next(fnode)){
fn = flist_data(fnode);
if(fn->instance->def->cleanup != NULL && fn->instance->status == MAPIFUNC_INIT){
fn->instance->def->cleanup(fn->instance);
fn->instance->status = MAPIFUNC_UNINIT; // in order to avoid the unnecessary call of cleanup function in free_functionlist()
}
}
pthread_mutex_unlock(&i->lock);
//it is not possible to delete flows here as it can cause race condition with process packet thread
// delete_flow(i, f);
return 0;
}
......@@ -1371,7 +1338,7 @@ mapid_apply_function(mapidlib_instance_t *i,
return fid;
}
int mapid_finished(mapidlib_instance_t *i)
int mapid_finished(mapidlib_instance_t *i) // XXX is this function essential ???
{
flist_node_t *n;
struct mapidlibflow *flow;
......@@ -1404,15 +1371,6 @@ int mapid_finished(mapidlib_instance_t *i)
}
#endif
/*
n = flist_head(i->flowlist);
while (n)
{
flow=flist_data(n);
flow->status=FLOW_FINISHED;
n = flist_next(n);
}
*/
return 0;
}
......@@ -1569,6 +1527,9 @@ void mapid_process_pkt(mapidlib_instance_t *i,
n2 = flist_next(n2);
}
}
else if(flow->status == FLOW_CLOSED){ // flow has closed, so we can delete it and deallocate all of its resources
delete_flow(i, flow);
}
}
#ifdef WITH_PRIORITIES
}
......
......@@ -54,9 +54,7 @@ typedef struct mapidlib_instance {
key_t shm_spinlock_key;
int shm_spinlock_id;
char shm_spinlock_fname[MAPI_STR_LENGTH];
pthread_mutex_t lock;
flist_t close;
}mapidlib_instance_t;
typedef int (*mapid_add_function)(mapidlib_instance_t *i, int fd, char *funct, ...);
......@@ -119,7 +117,7 @@ void mapid_process_pkt(mapidlib_instance_t *i,
unsigned char* link_pkt,
mapid_pkthdr_t* pkt_head);
int mapid_get_errno(mapidlib_instance_t *i,int fid);
void mapid_delete_flows(mapidlib_instance_t *i);
//void mapid_delete_flows(mapidlib_instance_t *i);
int mapid_get_devid(mapidlib_instance_t *i,int fd);
int mapid_load_library(char *lib);
int mapid_get_flow_info(mapidlib_instance_t *i,int fd,mapi_flow_info_t *info);
......
......@@ -201,7 +201,7 @@ process_pkts(void *buf,unsigned len, nic_instance_t *i,MAPI_UNUSED int devid, in
rlen = rec->caplen+sizeof(struct pcap_pkthdr);
}
mapid_delete_flows(&i->mapidlib);
//mapid_delete_flows(&i->mapidlib);
return len - c;
......
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