uptodate.c 18 KB

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