static int fatfs_provider_opendir(void *ip, posix_dir_t *dir) { FATFS *fs = (FATFS*) ip; DIR *d = new_dir(); (void) fs; if (!d) return -1; dir->raw = d; if (wf_opendir(d, dir->path) != FR_OK) { release_dir(d); return -1; } return 0; }
void * do_work_handler(void *arg) { struct config_instance_t * inst = (struct config_instance_t *)arg; pthread_t self_id = pthread_self(); int work_idx; int i; char send_dir[512] = ""; uint64_t file_id = inst->fileid; int source_file_fid; __u8 * msg_buff; signal(SIGPIPE,SIG_IGN); for(i = 0 ; i < MAX_THREAD_PER_INST ; i++){ if(inst->work_thread_t[i] == self_id){ work_idx = i; print_debug("my work idx is %d\n", work_idx); } } if(work_idx == 0){ counter_init(&send_success_cnt); } sprintf(send_dir, "%s/send/%llu/", sync_work_dir, file_id); if (access(send_dir, F_OK)) mkdir(send_dir, 0777); msg_buff = (__u8*)malloc(MB(16)); if (!msg_buff){ print_error("Alloc memory fails\n"); return NULL; } while(1){ struct dir_instance_t * dir_head; struct dir_instance_t * dir_curr; pthread_mutex_lock(&inst->work_thread_lock[work_idx]); while(inst->work_dir_head[work_idx] == NULL){ pthread_cond_wait(&inst->work_thread_wait[work_idx] , &inst->work_thread_lock[work_idx]); } dir_head = inst->work_dir_head[work_idx]; //inst->work_dir_head[work_idx] = NULL; pthread_mutex_unlock(&inst->work_thread_lock[work_idx]); source_file_fid = open(inst->filename, O_RDONLY | O_CREAT, 0666); if (source_file_fid < 0){ print_error("open %s error\n", inst->filename); release_dir(dir_head); usleep(0); continue; } for_each_entry_dir(dir_curr, dir_head){ vmsync_file_lock(inst->lock_fd[dir_curr->blockid % LOCK_HASH_SIZE]); do_file_sync(inst , work_idx , msg_buff , source_file_fid , send_dir , dir_curr); vmsync_file_unlock(inst->lock_fd[dir_curr->blockid % LOCK_HASH_SIZE]); } //print_debug("load all %d load sgl %d del all %d del sgl %d create sgl %d snd_msg %d\n" , // all_load_cnt , sgl_load_cnt , all_del_cnt , sgl_del_cnt , sgl_create_cnt , snd_msg_cnt); close(source_file_fid); release_dir(dir_head); pthread_mutex_lock(&inst->work_thread_lock[work_idx]); inst->work_dir_head[work_idx] = NULL; pthread_mutex_unlock(&inst->work_thread_lock[work_idx]); }
static int fatfs_provider_closedir(void *ip, posix_dir_t *dir) { (void) ip; release_dir((DIR*) dir->raw); return 0; }