remove elements in the cache considering that 'added_size' will be added */
| 668 | /* remove elements in the cache considering that 'added_size' will be |
| 669 | added */ |
| 670 | static void fs_trim_cache(FSDevice *fs1, int64_t added_size) |
| 671 | { |
| 672 | FSDeviceMem *fs = (FSDeviceMem *)fs1; |
| 673 | struct list_head *el, *el1; |
| 674 | FSINode *n; |
| 675 | |
| 676 | if ((fs->inode_cache_size + added_size) <= fs->inode_cache_size_limit) |
| 677 | return; |
| 678 | list_for_each_prev_safe(el, el1, &fs->inode_cache_list) { |
| 679 | n = list_entry(el, FSINode, u.reg.link); |
| 680 | assert(n->u.reg.state == REG_STATE_LOADED); |
| 681 | /* cannot remove open files */ |
| 682 | // printf("open_count=%d\n", n->open_count); |
| 683 | if (n->open_count != 0) |
| 684 | continue; |
| 685 | #ifdef DEBUG_CACHE |
| 686 | printf("fs_trim_cache: remove '%s' size=%ld\n", |
| 687 | n->u.reg.filename, (long)n->u.reg.size); |
| 688 | #endif |
| 689 | file_buffer_reset(&n->u.reg.fbuf); |
| 690 | n->u.reg.state = REG_STATE_UNLOADED; |
| 691 | list_del(&n->u.reg.link); |
| 692 | fs->inode_cache_size -= n->u.reg.size; |
| 693 | assert(fs->inode_cache_size >= 0); |
| 694 | if ((fs->inode_cache_size + added_size) <= fs->inode_cache_size_limit) |
| 695 | break; |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | static void fs_open_end(FSOpenInfo *oi) |
| 700 | { |
no test coverage detected