int sfqdfull_init() { if (SFQD_FULL_USE_HEAP_QUEUE==1) { sfqdfull_heap_queue=(struct heap*)malloc(sizeof(struct heap)); heap_init(sfqdfull_heap_queue); } else { sfqdfull_llist_queue=PINT_llist_new(); assert(sfqdfull_llist_queue!=NULL); sfqdfull_list_queue_count=(int*)malloc(num_apps*sizeof(int)); } sfqdfull_last_finish_tags=(int*)malloc(num_apps*sizeof(int)); int i; for (i=0;i<num_apps;i++) { sfqdfull_list_queue_count[i]=0; //last_finish_tags[i]=0; do not forget! } char* deptht=(char*)malloc(sizeof(char)*40); snprintf(deptht, 40, "%s.depthtrack.txt", log_prefix); depthtrack = fopen(deptht,"w");// }
/* PINT_create_extent_list() * * Return an extent llist based on extent string input * * Parameters: * extent_str - pointer to string * * Returns an extent list matching structure of * the input extent_str on success; returns NULL * the extent_str is invalid, or an error occurs * */ PINT_llist *PINT_create_extent_list(char *extent_str) { PVFS_handle_extent cur_extent, *new_extent = NULL; PINT_llist *extent_list = NULL; int status = 0; if (extent_str) { extent_list = PINT_llist_new(); assert(extent_list); while(PINT_parse_handle_ranges(extent_str,&cur_extent,&status)) { new_extent = malloc(sizeof(PVFS_handle_extent)); assert(new_extent); new_extent->first = cur_extent.first; new_extent->last = cur_extent.last; PINT_llist_add_to_tail(extent_list,(void *)new_extent); } } return extent_list; }
int dsfq_init()// { pthread_mutex_init(&dsfq_queue_mutex, NULL); pthread_mutex_init(&dsfq_accept_mutex, NULL); pthread_cond_init (&dsfq_accept_cond, NULL); pthread_mutex_init(&dsfq_broadcast_mutex, NULL); pthread_cond_init (&dsfq_broadcast_complete_cond, NULL); pthread_cond_init (&dsfq_broadcast_begin_cond,NULL); pthread_cond_init (&dsfq_threshold_cond,NULL); //read threshold from config file if (!dsfq_parse_server_config()) { fprintf(stderr, "reading config is successful\n"); } else { fprintf(stderr, "error reading config\n"); exit(-1); } char filename[100]; snprintf(filename,100, "dsfq.%s.b.txt",log_prefix); fprintf(stderr,"bfile:%s\n",filename); broadcast_file = fopen(filename, "w+"); /* assuming a dictionary * dict = iniparser_load(config_s) has been loaded * execute num_apps = iniparser_getint(dict, "apps:count" ,0) for your own use */ dsfq_llist_queue=PINT_llist_new(); //parse other server information now! dsfq_stats= (struct dsfq_statistics*)malloc(sizeof(struct dsfq_statistics)*num_apps); dsfq_last_finish_tags= (int*)malloc(sizeof(int)*num_apps); memset(dsfq_stats,0,sizeof(struct dsfq_statistics)*num_apps); memset(dsfq_last_finish_tags,0,sizeof(int)*num_apps); int i; //initialize listening ports and connection to other proxies //retry every 1 second broadcast_buffer=(struct proxy_message **)malloc(sizeof(struct proxy_message *)*other_server_count);//receive queue receive_buffer=(struct proxy_message **)malloc(sizeof(struct proxy_message *)*other_server_count);//receive queue for (i=0;i<other_server_count;i++) { broadcast_buffer[i]=(struct proxy_message *)malloc(sizeof(struct proxy_message)*num_apps); receive_buffer[i]=(struct proxy_message *)malloc(sizeof(struct proxy_message)*num_apps); } client_ips = (char**)malloc(other_server_count*sizeof(char*)); broadcast_buffer_size = (int*)malloc(sizeof(int )*other_server_count); receive_buffer_size = (int*)malloc(sizeof(int )*other_server_count); broadcast_sockets= (struct pollfd *) malloc(other_server_count*sizeof(struct pollfd));//we need the same number of sockets to receive receive_sockets= (struct pollfd *) malloc(other_server_count*sizeof(struct pollfd));//we need the same number of sockets to receive memset(broadcast_sockets, 0,other_server_count*sizeof(struct pollfd) ); memset(receive_sockets, 0,other_server_count*sizeof(struct pollfd) ); memset(broadcast_buffer_size, 0, sizeof(int )*other_server_count); memset(receive_buffer_size, 0, sizeof(int )*other_server_count); for (i=0;i<other_server_count;i++) { broadcast_buffer[i]=(struct proxy_message*)malloc(sizeof(struct proxy_message *)*num_apps); } long int listen_socket=BMI_sockio_new_sock();//setup listening socket int ret=BMI_sockio_set_sockopt(listen_socket,SO_REUSEADDR, 1);//reuse immediately if (ret==-1) { fprintf(stderr, "Error setting SO_REUSEADDR: %i when starting proxy communicating listening socket\n",ret); } ret = BMI_sockio_bind_sock(listen_socket,dsfq_proxy_listen_port);//bind to the specific port if (ret==-1) { fprintf(stderr, "Error binding socket: %li\n",listen_socket); return 1; } if (listen(listen_socket, BACKLOG) == -1) { fprintf(stderr, "Error listening on socket %li\n", listen_socket); return 1; } fprintf(stderr, "Proxy communication started, waiting on message...%li\n",listen_socket); int rc; pthread_t thread_accept; rc = pthread_create(&thread_accept, NULL, dsfq_proxy_accept_work, (void*)listen_socket); if (rc){ fprintf(stderr,"ERROR; return code from pthread_create() is %d\n", rc); exit(-1); } /* start contacting other proxies */ PINT_llist_p proxy_entry; if (other_server_names) proxy_entry = other_server_names->next; for (i=0;i<other_server_count;i++) { if (proxy_entry==NULL) { fprintf(stderr, "%ith proxy name entry does not exist!\n", i+1); break; } int server_socket = BMI_sockio_new_sock(); char * peer_ip = (char*)malloc(25); int peer_port; char * peer_name = ((char*)(proxy_entry->item)); fprintf(stderr,"connecting to other proxy:%s, %s\n", peer_name,other_server_address[i]); int ret=0; proxy_retry: if ((ret=BMI_sockio_connect_sock(server_socket,other_server_address[i],dsfq_proxy_listen_port,peer_ip, &peer_port))!=server_socket)//we establish a pairing connecting to our local server //begin to contact other proxies in other servers { fprintf(stderr, "connecting to proxy failed, %i\n",ret); sleep(1); goto proxy_retry; } else { fprintf(stderr,"successful, peer_ip:%s peer_port: %i\n", peer_ip, peer_port); broadcast_sockets[i].fd=server_socket; broadcast_sockets[i].events=POLLOUT; } proxy_entry = proxy_entry->next; } //try to wait other proxies' connection /* default retry time is 1 second * loop here; don't exit until all the sockets have been established * llist of outgoing server sockets with names for searching and sockets to send * combine the values of all applications together in a single message, checking threshold value of the sum of all applications * double buffering enables the proxy to be able to receive message while sending the ready messages(blocking until all the servers are notified) * make num_apps copies for each server so that this message progress can be polled and track each server's broadcasted status * */ pthread_mutex_lock(&dsfq_accept_mutex); while (!accept_ready) { fprintf(stderr,"waiting for accept all to finish\n"); pthread_cond_wait(&dsfq_accept_cond, &dsfq_accept_mutex); } int j; for (j=0;j<other_server_count;j++) { fprintf(stderr,"socket:%i\n",broadcast_sockets[j].fd); } pthread_mutex_unlock(&dsfq_accept_mutex); fprintf(stderr,"wait on other proxies' initialization is over\n"); rc=0; pthread_t thread_broadcast_work; rc = pthread_create(&thread_broadcast_work, NULL, dsfq_proxy_broadcast_work, NULL); if (rc){ fprintf(stderr,"ERROR; return code from pthread_create() is %d\n", rc); exit(-1); } pthread_t thread_receive_work; rc = pthread_create(&thread_receive_work, NULL, dsfq_proxy_receive_work, NULL); if (rc){ fprintf(stderr,"ERROR; return code from pthread_create() is %d\n", rc); exit(-1); } pthread_t thread_coordinator_work; rc = pthread_create(&thread_coordinator_work, NULL, dsfq_broadcast_trigger_work, NULL); if (rc){ fprintf(stderr,"ERROR; return code from pthread_create() is %d\n", rc); exit(-1); } }
int dsfq_parse_server_config() { char myhost[100]; fprintf(stderr, "host name returned %i\n",gethostname(myhost, 100)); FILE * server_config = fopen(pvfs_config,"r"); if (!server_config) { fprintf(stderr, "opening %s error\n", pvfs_config); return -1; } char line[10000]; int ret=0; if (ret=fread(line, 1, 9999, server_config)) { fprintf(stderr,"returning %i\n",ret); line[ret]='\0'; } char * begin = strtok(line, "\n"); char * alias, * alias2; other_server_names = PINT_llist_new(); while (begin) { if (alias=strstr(begin, "Alias ")) { alias2 = strstr(alias+6, " "); char * tmp = (char*)malloc((alias2-alias-6+1)*sizeof (char)); tmp[alias2-alias-6]='\0'; memcpy(tmp,alias+6,alias2-alias-6); if (!strcmp(myhost, tmp)) { fprintf(stderr,"excluding same host name from server config: %s\n", myhost); } else { PINT_llist_add_to_tail(other_server_names, tmp); other_server_count++; } } begin = strtok(NULL, "\n"); } other_server_ips = (struct sockaddr_in **)malloc(sizeof(struct sockaddr_in *)*other_server_count); other_server_address = (char**)malloc(sizeof(char*)*other_server_count); PINT_llist_doall(other_server_names, dsfq_fill_ip); fclose(server_config); return 0; //read server names //use resolve to resolve ip address }
int main(int argc, char **argv) { int ret = -1; /* all parameters read in from fs.conf */ struct server_configuration_s server_config; PINT_llist_p fs_configs; char *server_alias; /* make sure that the buffers we intend to use for reading keys and * values is at least large enough to hold the maximum size of xattr keys * and values */ if(DEF_KEY_SIZE < PVFS_REQ_LIMIT_KEY_LEN) { DEF_KEY_SIZE = PVFS_REQ_LIMIT_KEY_LEN; } if(DEF_DATA_SIZE < PVFS_REQ_LIMIT_VAL_LEN) { DEF_DATA_SIZE = PVFS_REQ_LIMIT_VAL_LEN; } if (parse_args(argc, argv, &opts)) { fprintf(stderr,"%s: error: argument parsing failed.\n", argv[0]); return -1; } if(opts.alias_set) { server_alias = opts.alias; } else { server_alias = PINT_util_guess_alias(); } ret = PINT_parse_config(&server_config, opts.fs_conf, server_alias); if(ret < 0) { gossip_err("Error: Please check your config files.\n"); if(!opts.alias_set) { free(server_alias); } return -1; } if(!opts.alias_set) { free(server_alias); } if(opts.all_set) { /* get all the collection ids from the fs config */ fs_configs = PINT_config_get_filesystems(&server_config); } else { /* get the collection id from the specified fs name */ PVFS_fs_id fs_id = PINT_config_get_fs_id_by_fs_name( &server_config, opts.fs); fs_configs = PINT_llist_new(); PINT_llist_add_to_head( fs_configs, (void *)PINT_config_find_fs_id(&server_config, fs_id)); } ret = PINT_llist_doall_arg(fs_configs, migrate_collection, &server_config); if(ret < 0) { PINT_config_release(&server_config); if(!opts.all_set) { PINT_llist_free(fs_configs, fs_config_dummy_free); } return(-1); } return 0; }