remove all clean blocks of the FILE
| 1276 | |
| 1277 | // remove all clean blocks of the FILE |
| 1278 | void bcache_remove_clean_blocks(struct filemgr *file) |
| 1279 | { |
| 1280 | struct list_elem *e; |
| 1281 | struct bcache_item *item; |
| 1282 | struct fnamedic_item *fname_item; |
| 1283 | |
| 1284 | fname_item = file->bcache; |
| 1285 | |
| 1286 | if (fname_item) { |
| 1287 | // Note that this function is only invoked as part of database file close or |
| 1288 | // removal when there are no database handles for a given file. Therefore, |
| 1289 | // we don't need to grab all the shard locks at once. |
| 1290 | |
| 1291 | // remove all clean blocks from each shard in a file. |
| 1292 | size_t i = 0; |
| 1293 | for (; i < fname_item->num_shards; ++i) { |
| 1294 | spin_lock(&fname_item->shards[i].lock); |
| 1295 | e = list_begin(&fname_item->shards[i].cleanlist); |
| 1296 | while(e){ |
| 1297 | item = _get_entry(e, struct bcache_item, list_elem); |
| 1298 | // remove from clean list |
| 1299 | e = list_remove(&fname_item->shards[i].cleanlist, e); |
| 1300 | // remove from hash table |
| 1301 | hash_remove(&fname_item->shards[i].hashtable, &item->hash_elem); |
| 1302 | // insert into free list |
| 1303 | _bcache_release_freeblock(item); |
| 1304 | } |
| 1305 | spin_unlock(&fname_item->shards[i].lock); |
| 1306 | } |
| 1307 | } |
| 1308 | } |
| 1309 | |
| 1310 | // remove file from filename dictionary |
| 1311 | // MUST sure that there is no dirty block belongs to this FILE |
no test coverage detected