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) ...@@ -268,7 +268,7 @@ process_pkts(void *buf,unsigned len, dag_instance_t *i)
i->hwinfo.pkts++; i->hwinfo.pkts++;
} }
mapid_delete_flows(&i->mapidlib); //mapid_delete_flows(&i->mapidlib);
return len - c; return len - c;
...@@ -313,7 +313,7 @@ process_pkts_offline(void *buf,unsigned len, dag_instance_t *i) ...@@ -313,7 +313,7 @@ process_pkts_offline(void *buf,unsigned len, dag_instance_t *i)
i->hwinfo.pkts++; i->hwinfo.pkts++;
} }
mapid_delete_flows(&i->mapidlib); //mapid_delete_flows(&i->mapidlib);
return len - c; return len - c;
......
...@@ -116,9 +116,6 @@ mapid_init(mapidlib_instance_t *i) ...@@ -116,9 +116,6 @@ mapid_init(mapidlib_instance_t *i)
struct group *mapi_group; struct group *mapi_group;
struct shmid_ds shm_data; struct shmid_ds shm_data;
pthread_mutex_init(&i->lock,NULL);
flist_init(&i->close);
#ifdef WITH_PRIORITIES #ifdef WITH_PRIORITIES
int j = 0; int j = 0;
i->flowlist=malloc(sizeof(flist_t*) * PRIORITIES); i->flowlist=malloc(sizeof(flist_t*) * PRIORITIES);
...@@ -135,7 +132,6 @@ mapid_init(mapidlib_instance_t *i) ...@@ -135,7 +132,6 @@ mapid_init(mapidlib_instance_t *i)
#endif #endif
if(!libs_loaded) { if(!libs_loaded) {
//mapid_conf = printf_string(CONF_FILE,getenv("HOME"));
mapid_conf = printf_string( CONFDIR"/"CONF_FILE ); mapid_conf = printf_string( CONFDIR"/"CONF_FILE );
//Load function libraries //Load function libraries
...@@ -541,19 +537,21 @@ static void delete_flow(mapidlib_instance_t *i,struct mapidlibflow *flow) { ...@@ -541,19 +537,21 @@ static void delete_flow(mapidlib_instance_t *i,struct mapidlibflow *flow) {
DEBUG_CMD(Debug_Message("Deleting flow %d", flow->fd)); DEBUG_CMD(Debug_Message("Deleting flow %d", flow->fd));
//global optimization ((mapid_flow_info_t*)flist_get(flow->hwinfo->gflist->fflist,flow->fd))->status = FLOW_CLOSED; // Update global function list
temp = (void*)flist_get(flow->hwinfo->gflist->fflist,flow->fd); time(&flow->end); // moved from mapid_close_flow
temp = (void*)flist_get(flow->hwinfo->gflist->fflist,flow->fd); // global optimization
if(!temp){ if(!temp){
DEBUG_CMD(Debug_Message("ERROR: Attempt to delete a flow that doesnt exist")); DEBUG_CMD(Debug_Message("ERROR: Attempt to delete a flow that doesnt exist"));
return; return;
} }
functions= ((mapid_flow_info_t*)temp)->flist; functions = ((mapid_flow_info_t*)temp)->flist;
if(functions!=NULL) if(functions!=NULL)
for(funct_node=flist_head(functions);funct_node!=NULL;funct_node=flist_next(funct_node)) { for(funct_node=flist_head(functions);funct_node!=NULL;funct_node=flist_next(funct_node)) {
funct=(mapidflib_function_t*)flist_data(funct_node); funct=(mapidflib_function_t*)flist_data(funct_node);
if(funct->ref==0 && funct->instance->refcount>0 ) if(funct->ref==0 && funct->instance->refcount>0 )
//Check to see if other functions references this function fix_funct_ref(flow->hwinfo->gflist,funct); // Check to see if other functions references this function
fix_funct_ref(flow->hwinfo->gflist,funct);
} }
#ifdef WITH_MODIFY_PKTS #ifdef WITH_MODIFY_PKTS
...@@ -561,10 +559,6 @@ static void delete_flow(mapidlib_instance_t *i,struct mapidlibflow *flow) { ...@@ -561,10 +559,6 @@ static void delete_flow(mapidlib_instance_t *i,struct mapidlibflow *flow) {
free(flow->mod_pkt); free(flow->mod_pkt);
#endif #endif
// commented: lock moved to free_functionlist()
// lock=&flow->hwinfo->gflist->lock;
// pthread_spin_lock(lock);
#ifdef WITH_PRIORITIES #ifdef WITH_PRIORITIES
f=flist_remove(i->flowlist[flow->priority],flow->fd); f=flist_remove(i->flowlist[flow->priority],flow->fd);
#else #else
...@@ -585,12 +579,9 @@ static void delete_flow(mapidlib_instance_t *i,struct mapidlibflow *flow) { ...@@ -585,12 +579,9 @@ static void delete_flow(mapidlib_instance_t *i,struct mapidlibflow *flow) {
free_functionlist(f); free_functionlist(f);
free_sharedmem(f); free_sharedmem(f);
free(f); free(f);
// pthread_spin_unlock(lock);
} }
/*void mapid_delete_flows(mapidlib_instance_t *i) { // TODO delete this function ...
void mapid_delete_flows(mapidlib_instance_t *i) {
flist_node_t *n; flist_node_t *n;
int fd; int fd;
...@@ -605,7 +596,7 @@ void mapid_delete_flows(mapidlib_instance_t *i) { ...@@ -605,7 +596,7 @@ void mapid_delete_flows(mapidlib_instance_t *i) {
} }
pthread_mutex_unlock(&i->lock); pthread_mutex_unlock(&i->lock);
} }*/
//Frees resources allocated by mapidlib, should be called by the drivers when devices are deleted //Frees resources allocated by mapidlib, should be called by the drivers when devices are deleted
...@@ -975,8 +966,6 @@ int ...@@ -975,8 +966,6 @@ int
mapid_close_flow(mapidlib_instance_t *i,int fd) mapid_close_flow(mapidlib_instance_t *i,int fd)
{ {
struct mapidlibflow *f; struct mapidlibflow *f;
mapidflib_function_t *fn;
flist_node_t *fnode;
#ifdef WITH_PRIORITIES #ifdef WITH_PRIORITIES
f=flist_priorities_get(i->flowlist,fd); f=flist_priorities_get(i->flowlist,fd);
...@@ -987,30 +976,8 @@ mapid_close_flow(mapidlib_instance_t *i,int fd) ...@@ -987,30 +976,8 @@ mapid_close_flow(mapidlib_instance_t *i,int fd)
if(f==NULL) if(f==NULL)
return -1; return -1;
f->status=FLOW_CLOSED; f->status = FLOW_CLOSED; // flow is deleted in mapid_process_pkt, in order to avoid a race condition with process packet thread
//Update global function list
((mapid_flow_info_t*)flist_get(f->hwinfo->gflist->fflist,f->fd))->status=FLOW_CLOSED;
time(&f->end);
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; return 0;
} }
...@@ -1371,7 +1338,7 @@ mapid_apply_function(mapidlib_instance_t *i, ...@@ -1371,7 +1338,7 @@ mapid_apply_function(mapidlib_instance_t *i,
return fid; 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; flist_node_t *n;
struct mapidlibflow *flow; struct mapidlibflow *flow;
...@@ -1404,15 +1371,6 @@ int mapid_finished(mapidlib_instance_t *i) ...@@ -1404,15 +1371,6 @@ int mapid_finished(mapidlib_instance_t *i)
} }
#endif #endif
/*
n = flist_head(i->flowlist);
while (n)
{
flow=flist_data(n);
flow->status=FLOW_FINISHED;
n = flist_next(n);
}
*/
return 0; return 0;
} }
...@@ -1569,6 +1527,9 @@ void mapid_process_pkt(mapidlib_instance_t *i, ...@@ -1569,6 +1527,9 @@ void mapid_process_pkt(mapidlib_instance_t *i,
n2 = flist_next(n2); 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 #ifdef WITH_PRIORITIES
} }
......
...@@ -54,8 +54,6 @@ typedef struct mapidlib_instance { ...@@ -54,8 +54,6 @@ typedef struct mapidlib_instance {
key_t shm_spinlock_key; key_t shm_spinlock_key;
int shm_spinlock_id; int shm_spinlock_id;
char shm_spinlock_fname[MAPI_STR_LENGTH]; char shm_spinlock_fname[MAPI_STR_LENGTH];
pthread_mutex_t lock;
flist_t close;
}mapidlib_instance_t; }mapidlib_instance_t;
...@@ -119,7 +117,7 @@ void mapid_process_pkt(mapidlib_instance_t *i, ...@@ -119,7 +117,7 @@ void mapid_process_pkt(mapidlib_instance_t *i,
unsigned char* link_pkt, unsigned char* link_pkt,
mapid_pkthdr_t* pkt_head); mapid_pkthdr_t* pkt_head);
int mapid_get_errno(mapidlib_instance_t *i,int fid); 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_get_devid(mapidlib_instance_t *i,int fd);
int mapid_load_library(char *lib); int mapid_load_library(char *lib);
int mapid_get_flow_info(mapidlib_instance_t *i,int fd,mapi_flow_info_t *info); 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 ...@@ -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); rlen = rec->caplen+sizeof(struct pcap_pkthdr);
} }
mapid_delete_flows(&i->mapidlib); //mapid_delete_flows(&i->mapidlib);
return len - c; return len - c;
......
Supports Markdown
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