uptodate.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * uptodate.c
  5. *
  6. * Tracking the up-to-date-ness of a local buffer_head with respect to
  7. * the cluster.
  8. *
  9. * Copyright (C) 2002, 2004, 2005 Oracle. All rights reserved.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public
  13. * License as published by the Free Software Foundation; either
  14. * version 2 of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public
  22. * License along with this program; if not, write to the
  23. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  24. * Boston, MA 021110-1307, USA.
  25. *
  26. * Standard buffer head caching flags (uptodate, etc) are insufficient
  27. * in a clustered environment - a buffer may be marked up to date on
  28. * our local node but could have been modified by another cluster
  29. * member. As a result an additional (and performant) caching scheme
  30. * is required. A further requirement is that we consume as little
  31. * memory as possible - we never pin buffer_head structures in order
  32. * to cache them.
  33. *
  34. * We track the existence of up to date buffers on the inodes which
  35. * are associated with them. Because we don't want to pin
  36. * buffer_heads, this is only a (strong) hint and several other checks
  37. * are made in the I/O path to ensure that we don't use a stale or
  38. * invalid buffer without going to disk:
  39. * - buffer_jbd is used liberally - if a bh is in the journal on
  40. * this node then it *must* be up to date.
  41. * - the standard buffer_uptodate() macro is used to detect buffers
  42. * which may be invalid (even if we have an up to date tracking
  43. * item for them)
  44. *
  45. * For a full understanding of how this code works together, one
  46. * should read the callers in dlmglue.c, the I/O functions in
  47. * buffer_head_io.c and ocfs2_journal_access in journal.c
  48. */
  49. #include <linux/fs.h>
  50. #include <linux/types.h>
  51. #include <linux/slab.h>
  52. #include <linux/highmem.h>
  53. #include <linux/buffer_head.h>
  54. #include <linux/rbtree.h>
  55. #include <cluster/masklog.h>
  56. #include "ocfs2.h"
  57. #include "inode.h"
  58. #include "uptodate.h"
  59. #include "ocfs2_trace.h"
  60. struct ocfs2_meta_cache_item {
  61. struct rb_node c_node;
  62. sector_t c_block;
  63. };
  64. static struct kmem_cache *ocfs2_uptodate_cachep;
  65. u64 ocfs2_metadata_cache_owner(struct ocfs2_caching_info *ci)
  66. {
  67. BUG_ON(!ci || !ci->ci_ops);
  68. return ci->ci_ops->co_owner(ci);
  69. }
  70. struct super_block *ocfs2_metadata_cache_get_super(struct ocfs2_caching_info *ci)
  71. {
  72. BUG_ON(!ci || !ci->ci_ops);
  73. return ci->ci_ops->co_get_super(ci);
  74. }
  75. static void ocfs2_metadata_cache_lock(struct ocfs2_caching_info *ci)
  76. {
  77. BUG_ON(!ci || !ci->ci_ops);
  78. ci->ci_ops->co_cache_lock(ci);
  79. }
  80. static void ocfs2_metadata_cache_unlock(struct ocfs2_caching_info *ci)
  81. {
  82. BUG_ON(!ci || !ci->ci_ops);
  83. ci->ci_ops->co_cache_unlock(ci);
  84. }
  85. void ocfs2_metadata_cache_io_lock(struct ocfs2_caching_info *ci)
  86. {
  87. BUG_ON(!ci || !ci->ci_ops);
  88. ci->ci_ops->co_io_lock(ci);
  89. }
  90. void ocfs2_metadata_cache_io_unlock(struct ocfs2_caching_info *ci)
  91. {
  92. BUG_ON(!ci || !ci->ci_ops);
  93. ci->ci_ops->co_io_unlock(ci);
  94. }
  95. static void ocfs2_metadata_cache_reset(struct ocfs2_caching_info *ci,
  96. int clear)
  97. {
  98. ci->ci_flags |= OCFS2_CACHE_FL_INLINE;
  99. ci->ci_num_cached = 0;
  100. if (clear) {
  101. ci->ci_created_trans = 0;
  102. ci->ci_last_trans = 0;
  103. }
  104. }
  105. void ocfs2_metadata_cache_init(struct ocfs2_caching_info *ci,
  106. const struct ocfs2_caching_operations *ops)
  107. {
  108. BUG_ON(!ops);
  109. ci->ci_ops = ops;
  110. ocfs2_metadata_cache_reset(ci, 1);
  111. }
  112. void ocfs2_metadata_cache_exit(struct ocfs2_caching_info *ci)
  113. {
  114. ocfs2_metadata_cache_purge(ci);
  115. ocfs2_metadata_cache_reset(ci, 1);
  116. }
  117. /* No lock taken here as 'root' is not expected to be visible to other
  118. * processes. */
  119. static unsigned int ocfs2_purge_copied_metadata_tree(struct rb_root *root)
  120. {
  121. unsigned int purged = 0;
  122. struct rb_node *node;
  123. struct ocfs2_meta_cache_item *item;
  124. while ((node = rb_last(root)) != NULL) {
  125. item = rb_entry(node, struct ocfs2_meta_cache_item, c_node);
  126. trace_ocfs2_purge_copied_metadata_tree(
  127. (unsigned long long) item->c_block);
  128. rb_erase(&item->c_node, root);
  129. kmem_cache_free(ocfs2_uptodate_cachep, item);
  130. purged++;
  131. }
  132. return purged;
  133. }
  134. /* Called from locking and called from ocfs2_clear_inode. Dump the
  135. * cache for a given inode.
  136. *
  137. * This function is a few more lines longer than necessary due to some
  138. * accounting done here, but I think it's worth tracking down those
  139. * bugs sooner -- Mark */
  140. void ocfs2_metadata_cache_purge(struct ocfs2_caching_info *ci)
  141. {
  142. unsigned int tree, to_purge, purged;
  143. struct rb_root root = RB_ROOT;
  144. BUG_ON(!ci || !ci->ci_ops);
  145. ocfs2_metadata_cache_lock(ci);
  146. tree = !(ci->ci_flags & OCFS2_CACHE_FL_INLINE);
  147. to_purge = ci->ci_num_cached;
  148. trace_ocfs2_metadata_cache_purge(
  149. (unsigned long long)ocfs2_metadata_cache_owner(ci),
  150. to_purge, tree);
  151. /* If we're a tree, save off the root so that we can safely
  152. * initialize the cache. We do the work to free tree members
  153. * without the spinlock. */
  154. if (tree)
  155. root = ci->ci_cache.ci_tree;
  156. ocfs2_metadata_cache_reset(ci, 0);
  157. ocfs2_metadata_cache_unlock(ci);
  158. purged = ocfs2_purge_copied_metadata_tree(&root);
  159. /* If possible, track the number wiped so that we can more
  160. * easily detect counting errors. Unfortunately, this is only
  161. * meaningful for trees. */
  162. if (tree && purged != to_purge)
  163. mlog(ML_ERROR, "Owner %llu, count = %u, purged = %u\n",
  164. (unsigned long long)ocfs2_metadata_cache_owner(ci),
  165. to_purge, purged);
  166. }
  167. /* Returns the index in the cache array, -1 if not found.
  168. * Requires ip_lock. */
  169. static int ocfs2_search_cache_array(struct ocfs2_caching_info *ci,
  170. sector_t item)
  171. {
  172. int i;
  173. for (i = 0; i < ci->ci_num_cached; i++) {
  174. if (item == ci->ci_cache.ci_array[i])
  175. return i;
  176. }
  177. return -1;
  178. }
  179. /* Returns the cache item if found, otherwise NULL.
  180. * Requires ip_lock. */
  181. static struct ocfs2_meta_cache_item *
  182. ocfs2_search_cache_tree(struct ocfs2_caching_info *ci,
  183. sector_t block)
  184. {
  185. struct rb_node * n = ci->ci_cache.ci_tree.rb_node;
  186. struct ocfs2_meta_cache_item *item = NULL;
  187. while (n) {
  188. item = rb_entry(n, struct ocfs2_meta_cache_item, c_node);
  189. if (block < item->c_block)
  190. n = n->rb_left;
  191. else if (block > item->c_block)
  192. n = n->rb_right;
  193. else
  194. return item;
  195. }
  196. return NULL;
  197. }
  198. static int ocfs2_buffer_cached(struct ocfs2_caching_info *ci,
  199. struct buffer_head *bh)
  200. {
  201. int index = -1;
  202. struct ocfs2_meta_cache_item *item = NULL;
  203. ocfs2_metadata_cache_lock(ci);
  204. trace_ocfs2_buffer_cached_begin(
  205. (unsigned long long)ocfs2_metadata_cache_owner(ci),
  206. (unsigned long long) bh->b_blocknr,
  207. !!(ci->ci_flags & OCFS2_CACHE_FL_INLINE));
  208. if (ci->ci_flags & OCFS2_CACHE_FL_INLINE)
  209. index = ocfs2_search_cache_array(ci, bh->b_blocknr);
  210. else
  211. item = ocfs2_search_cache_tree(ci, bh->b_blocknr);
  212. ocfs2_metadata_cache_unlock(ci);
  213. trace_ocfs2_buffer_cached_end(index, item);
  214. return (index != -1) || (item != NULL);
  215. }
  216. /* Warning: even if it returns true, this does *not* guarantee that
  217. * the block is stored in our inode metadata cache.
  218. *
  219. * This can be called under lock_buffer()
  220. */
  221. int ocfs2_buffer_uptodate(struct ocfs2_caching_info *ci,
  222. struct buffer_head *bh)
  223. {
  224. /* Doesn't matter if the bh is in our cache or not -- if it's
  225. * not marked uptodate then we know it can't have correct
  226. * data. */
  227. if (!buffer_uptodate(bh))
  228. return 0;
  229. /* OCFS2 does not allow multiple nodes to be changing the same
  230. * block at the same time. */
  231. if (buffer_jbd(bh))
  232. return 1;
  233. /* Ok, locally the buffer is marked as up to date, now search
  234. * our cache to see if we can trust that. */
  235. return ocfs2_buffer_cached(ci, bh);
  236. }
  237. /*
  238. * Determine whether a buffer is currently out on a read-ahead request.
  239. * ci_io_sem should be held to serialize submitters with the logic here.
  240. */
  241. int ocfs2_buffer_read_ahead(struct ocfs2_caching_info *ci,
  242. struct buffer_head *bh)
  243. {
  244. return buffer_locked(bh) && ocfs2_buffer_cached(ci, bh);
  245. }
  246. /* Requires ip_lock */
  247. static void ocfs2_append_cache_array(struct ocfs2_caching_info *ci,
  248. sector_t block)
  249. {
  250. BUG_ON(ci->ci_num_cached >= OCFS2_CACHE_INFO_MAX_ARRAY);
  251. trace_ocfs2_append_cache_array(
  252. (unsigned long long)ocfs2_metadata_cache_owner(ci),
  253. (unsigned long long)block, ci->ci_num_cached);
  254. ci->ci_cache.ci_array[ci->ci_num_cached] = block;
  255. ci->ci_num_cached++;
  256. }
  257. /* By now the caller should have checked that the item does *not*
  258. * exist in the tree.
  259. * Requires ip_lock. */
  260. static void __ocfs2_insert_cache_tree(struct ocfs2_caching_info *ci,
  261. struct ocfs2_meta_cache_item *new)
  262. {
  263. sector_t block = new->c_block;
  264. struct rb_node *parent = NULL;
  265. struct rb_node **p = &ci->ci_cache.ci_tree.rb_node;
  266. struct ocfs2_meta_cache_item *tmp;
  267. trace_ocfs2_insert_cache_tree(
  268. (unsigned long long)ocfs2_metadata_cache_owner(ci),
  269. (unsigned long long)block, ci->ci_num_cached);
  270. while(*p) {
  271. parent = *p;
  272. tmp = rb_entry(parent, struct ocfs2_meta_cache_item, c_node);
  273. if (block < tmp->c_block)
  274. p = &(*p)->rb_left;
  275. else if (block > tmp->c_block)
  276. p = &(*p)->rb_right;
  277. else {
  278. /* This should never happen! */
  279. mlog(ML_ERROR, "Duplicate block %llu cached!\n",
  280. (unsigned long long) block);
  281. BUG();
  282. }
  283. }
  284. rb_link_node(&new->c_node, parent, p);
  285. rb_insert_color(&new->c_node, &ci->ci_cache.ci_tree);
  286. ci->ci_num_cached++;
  287. }
  288. /* co_cache_lock() must be held */
  289. static inline int ocfs2_insert_can_use_array(struct ocfs2_caching_info *ci)
  290. {
  291. return (ci->ci_flags & OCFS2_CACHE_FL_INLINE) &&
  292. (ci->ci_num_cached < OCFS2_CACHE_INFO_MAX_ARRAY);
  293. }
  294. /* tree should be exactly OCFS2_CACHE_INFO_MAX_ARRAY wide. NULL the
  295. * pointers in tree after we use them - this allows caller to detect
  296. * when to free in case of error.
  297. *
  298. * The co_cache_lock() must be held. */
  299. static void ocfs2_expand_cache(struct ocfs2_caching_info *ci,
  300. struct ocfs2_meta_cache_item **tree)
  301. {
  302. int i;
  303. mlog_bug_on_msg(ci->ci_num_cached != OCFS2_CACHE_INFO_MAX_ARRAY,
  304. "Owner %llu, num cached = %u, should be %u\n",
  305. (unsigned long long)ocfs2_metadata_cache_owner(ci),
  306. ci->ci_num_cached, OCFS2_CACHE_INFO_MAX_ARRAY);
  307. mlog_bug_on_msg(!(ci->ci_flags & OCFS2_CACHE_FL_INLINE),
  308. "Owner %llu not marked as inline anymore!\n",
  309. (unsigned long long)ocfs2_metadata_cache_owner(ci));
  310. /* Be careful to initialize the tree members *first* because
  311. * once the ci_tree is used, the array is junk... */
  312. for (i = 0; i < OCFS2_CACHE_INFO_MAX_ARRAY; i++)
  313. tree[i]->c_block = ci->ci_cache.ci_array[i];
  314. ci->ci_flags &= ~OCFS2_CACHE_FL_INLINE;
  315. ci->ci_cache.ci_tree = RB_ROOT;
  316. /* this will be set again by __ocfs2_insert_cache_tree */
  317. ci->ci_num_cached = 0;
  318. for (i = 0; i < OCFS2_CACHE_INFO_MAX_ARRAY; i++) {
  319. __ocfs2_insert_cache_tree(ci, tree[i]);
  320. tree[i] = NULL;
  321. }
  322. trace_ocfs2_expand_cache(
  323. (unsigned long long)ocfs2_metadata_cache_owner(ci),
  324. ci->ci_flags, ci->ci_num_cached);
  325. }
  326. /* Slow path function - memory allocation is necessary. See the
  327. * comment above ocfs2_set_buffer_uptodate for more information. */
  328. static void __ocfs2_set_buffer_uptodate(struct ocfs2_caching_info *ci,
  329. sector_t block,
  330. int expand_tree)
  331. {
  332. int i;
  333. struct ocfs2_meta_cache_item *new = NULL;
  334. struct ocfs2_meta_cache_item *tree[OCFS2_CACHE_INFO_MAX_ARRAY] =
  335. { NULL, };
  336. trace_ocfs2_set_buffer_uptodate(
  337. (unsigned long long)ocfs2_metadata_cache_owner(ci),
  338. (unsigned long long)block, expand_tree);
  339. new = kmem_cache_alloc(ocfs2_uptodate_cachep, GFP_NOFS);
  340. if (!new) {
  341. mlog_errno(-ENOMEM);
  342. return;
  343. }
  344. new->c_block = block;
  345. if (expand_tree) {
  346. /* Do *not* allocate an array here - the removal code
  347. * has no way of tracking that. */
  348. for (i = 0; i < OCFS2_CACHE_INFO_MAX_ARRAY; i++) {
  349. tree[i] = kmem_cache_alloc(ocfs2_uptodate_cachep,
  350. GFP_NOFS);
  351. if (!tree[i]) {
  352. mlog_errno(-ENOMEM);
  353. goto out_free;
  354. }
  355. /* These are initialized in ocfs2_expand_cache! */
  356. }
  357. }
  358. ocfs2_metadata_cache_lock(ci);
  359. if (ocfs2_insert_can_use_array(ci)) {
  360. /* Ok, items were removed from the cache in between
  361. * locks. Detect this and revert back to the fast path */
  362. ocfs2_append_cache_array(ci, block);
  363. ocfs2_metadata_cache_unlock(ci);
  364. goto out_free;
  365. }
  366. if (expand_tree)
  367. ocfs2_expand_cache(ci, tree);
  368. __ocfs2_insert_cache_tree(ci, new);
  369. ocfs2_metadata_cache_unlock(ci);
  370. new = NULL;
  371. out_free:
  372. if (new)
  373. kmem_cache_free(ocfs2_uptodate_cachep, new);
  374. /* If these were used, then ocfs2_expand_cache re-set them to
  375. * NULL for us. */
  376. if (tree[0]) {
  377. for (i = 0; i < OCFS2_CACHE_INFO_MAX_ARRAY; i++)
  378. if (tree[i])
  379. kmem_cache_free(ocfs2_uptodate_cachep,
  380. tree[i]);
  381. }
  382. }
  383. /* Item insertion is guarded by co_io_lock(), so the insertion path takes
  384. * advantage of this by not rechecking for a duplicate insert during
  385. * the slow case. Additionally, if the cache needs to be bumped up to
  386. * a tree, the code will not recheck after acquiring the lock --
  387. * multiple paths cannot be expanding to a tree at the same time.
  388. *
  389. * The slow path takes into account that items can be removed
  390. * (including the whole tree wiped and reset) when this process it out
  391. * allocating memory. In those cases, it reverts back to the fast
  392. * path.
  393. *
  394. * Note that this function may actually fail to insert the block if
  395. * memory cannot be allocated. This is not fatal however (but may
  396. * result in a performance penalty)
  397. *
  398. * Readahead buffers can be passed in here before the I/O request is
  399. * completed.
  400. */
  401. void ocfs2_set_buffer_uptodate(struct ocfs2_caching_info *ci,
  402. struct buffer_head *bh)
  403. {
  404. int expand;
  405. /* The block may very well exist in our cache already, so avoid
  406. * doing any more work in that case. */
  407. if (ocfs2_buffer_cached(ci, bh))
  408. return;
  409. trace_ocfs2_set_buffer_uptodate_begin(
  410. (unsigned long long)ocfs2_metadata_cache_owner(ci),
  411. (unsigned long long)bh->b_blocknr);
  412. /* No need to recheck under spinlock - insertion is guarded by
  413. * co_io_lock() */
  414. ocfs2_metadata_cache_lock(ci);
  415. if (ocfs2_insert_can_use_array(ci)) {
  416. /* Fast case - it's an array and there's a free
  417. * spot. */
  418. ocfs2_append_cache_array(ci, bh->b_blocknr);
  419. ocfs2_metadata_cache_unlock(ci);
  420. return;
  421. }
  422. expand = 0;
  423. if (ci->ci_flags & OCFS2_CACHE_FL_INLINE) {
  424. /* We need to bump things up to a tree. */
  425. expand = 1;
  426. }
  427. ocfs2_metadata_cache_unlock(ci);
  428. __ocfs2_set_buffer_uptodate(ci, bh->b_blocknr, expand);
  429. }
  430. /* Called against a newly allocated buffer. Most likely nobody should
  431. * be able to read this sort of metadata while it's still being
  432. * allocated, but this is careful to take co_io_lock() anyway. */
  433. void ocfs2_set_new_buffer_uptodate(struct ocfs2_caching_info *ci,
  434. struct buffer_head *bh)
  435. {
  436. /* This should definitely *not* exist in our cache */
  437. BUG_ON(ocfs2_buffer_cached(ci, bh));
  438. set_buffer_uptodate(bh);
  439. ocfs2_metadata_cache_io_lock(ci);
  440. ocfs2_set_buffer_uptodate(ci, bh);
  441. ocfs2_metadata_cache_io_unlock(ci);
  442. }
  443. /* Requires ip_lock. */
  444. static void ocfs2_remove_metadata_array(struct ocfs2_caching_info *ci,
  445. int index)
  446. {
  447. sector_t *array = ci->ci_cache.ci_array;
  448. int bytes;
  449. BUG_ON(index < 0 || index >= OCFS2_CACHE_INFO_MAX_ARRAY);
  450. BUG_ON(index >= ci->ci_num_cached);
  451. BUG_ON(!ci->ci_num_cached);
  452. trace_ocfs2_remove_metadata_array(
  453. (unsigned long long)ocfs2_metadata_cache_owner(ci),
  454. index, ci->ci_num_cached);
  455. ci->ci_num_cached--;
  456. /* don't need to copy if the array is now empty, or if we
  457. * removed at the tail */
  458. if (ci->ci_num_cached && index < ci->ci_num_cached) {
  459. bytes = sizeof(sector_t) * (ci->ci_num_cached - index);
  460. memmove(&array[index], &array[index + 1], bytes);
  461. }
  462. }
  463. /* Requires ip_lock. */
  464. static void ocfs2_remove_metadata_tree(struct ocfs2_caching_info *ci,
  465. struct ocfs2_meta_cache_item *item)
  466. {
  467. trace_ocfs2_remove_metadata_tree(
  468. (unsigned long long)ocfs2_metadata_cache_owner(ci),
  469. (unsigned long long)item->c_block);
  470. rb_erase(&item->c_node, &ci->ci_cache.ci_tree);
  471. ci->ci_num_cached--;
  472. }
  473. static void ocfs2_remove_block_from_cache(struct ocfs2_caching_info *ci,
  474. sector_t block)
  475. {
  476. int index;
  477. struct ocfs2_meta_cache_item *item = NULL;
  478. ocfs2_metadata_cache_lock(ci);
  479. trace_ocfs2_remove_block_from_cache(
  480. (unsigned long long)ocfs2_metadata_cache_owner(ci),
  481. (unsigned long long) block, ci->ci_num_cached,
  482. ci->ci_flags);
  483. if (ci->ci_flags & OCFS2_CACHE_FL_INLINE) {
  484. index = ocfs2_search_cache_array(ci, block);
  485. if (index != -1)
  486. ocfs2_remove_metadata_array(ci, index);
  487. } else {
  488. item = ocfs2_search_cache_tree(ci, block);
  489. if (item)
  490. ocfs2_remove_metadata_tree(ci, item);
  491. }
  492. ocfs2_metadata_cache_unlock(ci);
  493. if (item)
  494. kmem_cache_free(ocfs2_uptodate_cachep, item);
  495. }
  496. /*
  497. * Called when we remove a chunk of metadata from an inode. We don't
  498. * bother reverting things to an inlined array in the case of a remove
  499. * which moves us back under the limit.
  500. */
  501. void ocfs2_remove_from_cache(struct ocfs2_caching_info *ci,
  502. struct buffer_head *bh)
  503. {
  504. sector_t block = bh->b_blocknr;
  505. ocfs2_remove_block_from_cache(ci, block);
  506. }
  507. /* Called when we remove xattr clusters from an inode. */
  508. void ocfs2_remove_xattr_clusters_from_cache(struct ocfs2_caching_info *ci,
  509. sector_t block,
  510. u32 c_len)
  511. {
  512. struct super_block *sb = ocfs2_metadata_cache_get_super(ci);
  513. unsigned int i, b_len = ocfs2_clusters_to_blocks(sb, 1) * c_len;
  514. for (i = 0; i < b_len; i++, block++)
  515. ocfs2_remove_block_from_cache(ci, block);
  516. }
  517. int __init init_ocfs2_uptodate_cache(void)
  518. {
  519. ocfs2_uptodate_cachep = kmem_cache_create("ocfs2_uptodate",
  520. sizeof(struct ocfs2_meta_cache_item),
  521. 0, SLAB_HWCACHE_ALIGN, NULL);
  522. if (!ocfs2_uptodate_cachep)
  523. return -ENOMEM;
  524. return 0;
  525. }
  526. void exit_ocfs2_uptodate_cache(void)
  527. {
  528. if (ocfs2_uptodate_cachep)
  529. kmem_cache_destroy(ocfs2_uptodate_cachep);
  530. }