51 #include <linux/types.h>
52 #include <linux/slab.h>
55 #include <linux/rbtree.h>
76 return ci->
ci_ops->co_owner(ci);
83 return ci->
ci_ops->co_get_super(ci);
90 ci->
ci_ops->co_cache_lock(ci);
97 ci->
ci_ops->co_cache_unlock(ci);
104 ci->
ci_ops->co_io_lock(ci);
111 ci->
ci_ops->co_io_unlock(ci);
133 ocfs2_metadata_cache_reset(ci, 1);
139 ocfs2_metadata_cache_reset(ci, 1);
145 static unsigned int ocfs2_purge_copied_metadata_tree(
struct rb_root *root)
147 unsigned int purged = 0;
154 trace_ocfs2_purge_copied_metadata_tree(
155 (
unsigned long long) item->
c_block);
173 unsigned int tree, to_purge, purged;
178 ocfs2_metadata_cache_lock(ci);
182 trace_ocfs2_metadata_cache_purge(
192 ocfs2_metadata_cache_reset(ci, 0);
193 ocfs2_metadata_cache_unlock(ci);
195 purged = ocfs2_purge_copied_metadata_tree(&root);
199 if (tree && purged != to_purge)
234 else if (block > item->
c_block)
244 struct buffer_head *bh)
249 ocfs2_metadata_cache_lock(ci);
251 trace_ocfs2_buffer_cached_begin(
253 (
unsigned long long) bh->b_blocknr,
257 index = ocfs2_search_cache_array(ci, bh->b_blocknr);
259 item = ocfs2_search_cache_tree(ci, bh->b_blocknr);
261 ocfs2_metadata_cache_unlock(ci);
263 trace_ocfs2_buffer_cached_end(index, item);
265 return (index != -1) || (item !=
NULL);
274 struct buffer_head *bh)
279 if (!buffer_uptodate(bh))
289 return ocfs2_buffer_cached(ci, bh);
297 struct buffer_head *bh)
299 return buffer_locked(bh) && ocfs2_buffer_cached(ci, bh);
308 trace_ocfs2_append_cache_array(
327 trace_ocfs2_insert_cache_tree(
343 (
unsigned long long) block);
348 rb_link_node(&new->c_node, parent, p);
371 "Owner %llu, num cached = %u, should be %u\n",
375 "Owner %llu not marked as inline anymore!\n",
389 __ocfs2_insert_cache_tree(ci, tree[i]);
393 trace_ocfs2_expand_cache(
409 trace_ocfs2_set_buffer_uptodate(
411 (
unsigned long long)block, expand_tree);
418 new->c_block =
block;
435 ocfs2_metadata_cache_lock(ci);
436 if (ocfs2_insert_can_use_array(ci)) {
439 ocfs2_append_cache_array(ci, block);
440 ocfs2_metadata_cache_unlock(ci);
445 ocfs2_expand_cache(ci, tree);
447 __ocfs2_insert_cache_tree(ci,
new);
448 ocfs2_metadata_cache_unlock(ci);
484 struct buffer_head *bh)
490 if (ocfs2_buffer_cached(ci, bh))
493 trace_ocfs2_set_buffer_uptodate_begin(
495 (
unsigned long long)bh->b_blocknr);
499 ocfs2_metadata_cache_lock(ci);
500 if (ocfs2_insert_can_use_array(ci)) {
503 ocfs2_append_cache_array(ci, bh->b_blocknr);
504 ocfs2_metadata_cache_unlock(ci);
513 ocfs2_metadata_cache_unlock(ci);
515 __ocfs2_set_buffer_uptodate(ci, bh->b_blocknr, expand);
522 struct buffer_head *bh)
525 BUG_ON(ocfs2_buffer_cached(ci, bh));
527 set_buffer_uptodate(bh);
541 BUG_ON(index < 0 || index >= OCFS2_CACHE_INFO_MAX_ARRAY);
545 trace_ocfs2_remove_metadata_array(
555 memmove(&array[index], &array[index + 1], bytes);
563 trace_ocfs2_remove_metadata_tree(
565 (
unsigned long long)item->
c_block);
577 ocfs2_metadata_cache_lock(ci);
578 trace_ocfs2_remove_block_from_cache(
584 index = ocfs2_search_cache_array(ci, block);
586 ocfs2_remove_metadata_array(ci, index);
588 item = ocfs2_search_cache_tree(ci, block);
590 ocfs2_remove_metadata_tree(ci, item);
592 ocfs2_metadata_cache_unlock(ci);
604 struct buffer_head *bh)
608 ocfs2_remove_block_from_cache(ci, block);
617 unsigned int i, b_len = ocfs2_clusters_to_blocks(sb, 1) *
c_len;
619 for (i = 0; i < b_len; i++, block++)
620 ocfs2_remove_block_from_cache(ci, block);
628 if (!ocfs2_uptodate_cachep)
636 if (ocfs2_uptodate_cachep)