| | 637 | void clear_stranded_bstreams(TROVE_coll_id coll_id) |
| | 638 | { |
| | 639 | char path_name[PATH_MAX]; |
| | 640 | DIR *current_dir = NULL; |
| | 641 | struct dirent *current_dirent = NULL; |
| | 642 | struct stat file_info; |
| | 643 | struct file_struct *tmp_item; |
| | 644 | |
| | 645 | DBPF_GET_STRANDED_BSTREAM_DIRNAME(path_name, PATH_MAX, |
| | 646 | my_storage_p->name, coll_id); |
| | 647 | |
| | 648 | /* remove entries in the stranded bstreams directory */ |
| | 649 | current_dir = opendir(path_name); |
| | 650 | if(current_dir) |
| | 651 | { |
| | 652 | while((current_dirent = readdir(current_dir))) |
| | 653 | { |
| | 654 | if((strcmp(current_dirent->d_name, ".") == 0) || |
| | 655 | (strcmp(current_dirent->d_name, "..") == 0)) |
| | 656 | { |
| | 657 | continue; |
| | 658 | } |
| | 659 | tmp_item = (struct file_struct *) malloc(sizeof(struct file_struct)); |
| | 660 | if(!tmp_item) |
| | 661 | { |
| | 662 | gossip_err("Unable to allocate memory for file_struct [%d].\n", errno); |
| | 663 | return; |
| | 664 | } |
| | 665 | tmp_item->pathname = malloc(PATH_MAX); |
| | 666 | if(!tmp_item->pathname) |
| | 667 | { |
| | 668 | gossip_err("Unable to allocate memory for pathname[%d].\n", errno); |
| | 669 | free(tmp_item); |
| | 670 | return; |
| | 671 | } |
| | 672 | snprintf(tmp_item->pathname, PATH_MAX, "%s/%s", path_name, |
| | 673 | current_dirent->d_name); |
| | 674 | if(stat(tmp_item->pathname, &file_info) < 0) |
| | 675 | { |
| | 676 | gossip_err("error doing stat on bstream entry\n"); |
| | 677 | continue; |
| | 678 | } |
| | 679 | assert(S_ISREG(file_info.st_mode)); |
| | 680 | /* Add to the queue */ |
| | 681 | |
| | 682 | pthread_mutex_lock(&dbpf_unlink_context.mutex); |
| | 683 | qlist_add_tail(&tmp_item->list_link, &dbpf_unlink_context.global_list); |
| | 684 | pthread_cond_signal(&dbpf_unlink_context.data_available); |
| | 685 | pthread_mutex_unlock(&dbpf_unlink_context.mutex); |
| | 686 | gossip_debug(GOSSIP_DBPF_OPEN_CACHE_DEBUG, |
| | 687 | "Added [%s] to the queue.\n", tmp_item->pathname); |
| | 688 | } |
| | 689 | closedir(current_dir); |
| | 690 | } |
| | 691 | else |
| | 692 | { |
| | 693 | gossip_err("Unable to open standed bstream directory [%s] to " |
| | 694 | "perform initialization stranded bstream cleanup", path_name); |
| | 695 | } |
| | 696 | } |
| | 697 | |