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. #define MLOG_MASK_PREFIX ML_UPTODATE
  56. #include <cluster/masklog.h>
  57. #include "ocfs2.h"
  58. #include "inode.h"
  59. #include "uptodate.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 = NULL;
  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. mlog(0, "Purge item %llu\n",
  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. mlog(0, "Purge %u %s items from Owner %llu\n", to_purge,
  149. tree ? "array" : "tree",
  150. (unsigned long long)ocfs2_metadata_cache_owner(ci));
  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. mlog(0, "Owner %llu, query block %llu (inline = %u)\n",
  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. mlog(0, "index = %d, item = %p\n", 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. mlog(0, "block %llu takes position %u\n", (unsigned long long) block,
  252. ci->ci_num_cached);
  253. ci->ci_cache.ci_array[ci->ci_num_cached] = block;
  254. ci->ci_num_cached++;
  255. }
  256. /* By now the caller should have checked that the item does *not*
  257. * exist in the tree.
  258. * Requires ip_lock. */
  259. static void __ocfs2_insert_cache_tree(struct ocfs2_caching_info *ci,
  260. struct ocfs2_meta_cache_item *new)
  261. {
  262. sector_t block = new->c_block;
  263. struct rb_node *parent = NULL;
  264. struct rb_node **p = &ci->ci_cache.ci_tree.rb_node;
  265. struct ocfs2_meta_cache_item *tmp;
  266. mlog(0, "Insert block %llu num = %u\n", (unsigned long long) block,
  267. ci->ci_num_cached);
  268. while(*p) {
  269. parent = *p;
  270. tmp = rb_entry(parent, struct ocfs2_meta_cache_item, c_node);
  271. if (block < tmp->c_block)
  272. p = &(*p)->rb_left;
  273. else if (block > tmp->c_block)
  274. p = &(*p)->rb_right;
  275. else {
  276. /* This should never happen! */
  277. mlog(ML_ERROR, "Duplicate block %llu cached!\n",
  278. (unsigned long long) block);
  279. BUG();
  280. }
  281. }
  282. rb_link_node(&new->c_node, parent, p);
  283. rb_insert_color(&new->c_node, &ci->ci_cache.ci_tree);
  284. ci->ci_num_cached++;
  285. }
  286. /* co_cache_lock() must be held */
  287. static inline int ocfs2_insert_can_use_array(struct ocfs2_caching_info *ci)
  288. {
  289. return (ci->ci_flags & OCFS2_CACHE_FL_INLINE) &&
  290. (ci->ci_num_cached < OCFS2_CACHE_INFO_MAX_ARRAY);
  291. }
  292. /* tree should be exactly OCFS2_CACHE_INFO_MAX_ARRAY wide. NULL the
  293. * pointers in tree after we use them - this allows caller to detect
  294. * when to free in case of error.
  295. *
  296. * The co_cache_lock() must be held. */
  297. static void ocfs2_expand_cache(struct ocfs2_caching_info *ci,
  298. struct ocfs2_meta_cache_item **tree)
  299. {
  300. int i;
  301. mlog_bug_on_msg(ci->ci_num_cached != OCFS2_CACHE_INFO_MAX_ARRAY,
  302. "Owner %llu, num cached = %u, should be %u\n",
  303. (unsigned long long)ocfs2_metadata_cache_owner(ci),
  304. ci->ci_num_cached, OCFS2_CACHE_INFO_MAX_ARRAY);
  305. mlog_bug_on_msg(!(ci->ci_flags & OCFS2_CACHE_FL_INLINE),
  306. "Owner %llu not marked as inline anymore!\n",
  307. (unsigned long long)ocfs2_metadata_cache_owner(ci));
  308. /* Be careful to initialize the tree members *first* because
  309. * once the ci_tree is used, the array is junk... */
  310. for (i = 0; i < OCFS2_CACHE_INFO_MAX_ARRAY; i++)
  311. tree[i]->c_block = ci->ci_cache.ci_array[i];
  312. ci->ci_flags &= ~OCFS2_CACHE_FL_INLINE;
  313. ci->ci_cache.ci_tree = RB_ROOT;
  314. /* this will be set again by __ocfs2_insert_cache_tree */
  315. ci->ci_num_cached = 0;
  316. for (i = 0; i < OCFS2_CACHE_INFO_MAX_ARRAY; i++) {
  317. __ocfs2_insert_cache_tree(ci, tree[i]);
  318. tree[i] = NULL;
  319. }
  320. mlog(0, "Expanded %llu to a tree cache: flags 0x%x, num = %u\n",
  321. (unsigned long long)ocfs2_metadata_cache_owner(ci),
  322. ci->ci_flags, ci->ci_num_cached);
  323. }
  324. /* Slow path function - memory allocation is necessary. See the
  325. * comment above ocfs2_set_buffer_uptodate for more information. */
  326. static void __ocfs2_set_buffer_uptodate(struct ocfs2_caching_info *ci,
  327. sector_t block,
  328. int expand_tree)
  329. {
  330. int i;
  331. struct ocfs2_meta_cache_item *new = NULL;
  332. struct ocfs2_meta_cache_item *tree[OCFS2_CACHE_INFO_MAX_ARRAY] =
  333. { NULL, };
  334. mlog(0, "Owner %llu, block %llu, expand = %d\n",
  335. (unsigned long long)ocfs2_metadata_cache_owner(ci),
  336. (unsigned long long)block, expand_tree);
  337. new = kmem_cache_alloc(ocfs2_uptodate_cachep, GFP_NOFS);
  338. if (!new) {
  339. mlog_errno(-ENOMEM);
  340. return;
  341. }
  342. new->c_block = block;
  343. if (expand_tree) {
  344. /* Do *not* allocate an array here - the removal code
  345. * has no way of tracking that. */
  346. for (i = 0; i < OCFS2_CACHE_INFO_MAX_ARRAY; i++) {
  347. tree[i] = kmem_cache_alloc(ocfs2_uptodate_cachep,
  348. GFP_NOFS);
  349. if (!tree[i]) {
  350. mlog_errno(-ENOMEM);
  351. goto out_free;
  352. }
  353. /* These are initialized in ocfs2_expand_cache! */
  354. }
  355. }
  356. ocfs2_metadata_cache_lock(ci);
  357. if (ocfs2_insert_can_use_array(ci)) {
  358. mlog(0, "Someone cleared the tree underneath us\n");
  359. /* Ok, items were removed from the cache in between
  360. * locks. Detect this and revert back to the fast path */
  361. ocfs2_append_cache_array(ci, block);
  362. ocfs2_metadata_cache_unlock(ci);
  363. goto out_free;
  364. }
  365. if (expand_tree)
  366. ocfs2_expand_cache(ci, tree);
  367. __ocfs2_insert_cache_tree(ci, new);
  368. ocfs2_metadata_cache_unlock(ci);
  369. new = NULL;
  370. out_free:
  371. if (new)
  372. kmem_cache_free(ocfs2_uptodate_cachep, new);
  373. /* If these were used, then ocfs2_expand_cache re-set them to
  374. * NULL for us. */
  375. if (tree[0]) {
  376. for (i = 0; i < OCFS2_CACHE_INFO_MAX_ARRAY; i++)
  377. if (tree[i])
  378. kmem_cache_free(ocfs2_uptodate_cachep,
  379. tree[i]);
  380. }
  381. }
  382. /* Item insertion is guarded by co_io_lock(), so the insertion path takes
  383. * advantage of this by not rechecking for a duplicate insert during
  384. * the slow case. Additionally, if the cache needs to be bumped up to
  385. * a tree, the code will not recheck after acquiring the lock --
  386. * multiple paths cannot be expanding to a tree at the same time.
  387. *
  388. * The slow path takes into account that items can be removed
  389. * (including the whole tree wiped and reset) when this process it out
  390. * allocating memory. In those cases, it reverts back to the fast
  391. * path.
  392. *
  393. * Note that this function may actually fail to insert the block if
  394. * memory cannot be allocated. This is not fatal however (but may
  395. * result in a performance penalty)
  396. *
  397. * Readahead buffers can be passed in here before the I/O request is
  398. * completed.
  399. */
  400. void ocfs2_set_buffer_uptodate(struct ocfs2_caching_info *ci,
  401. struct buffer_head *bh)
  402. {
  403. int expand;
  404. /* The block may very well exist in our cache already, so avoid
  405. * doing any more work in that case. */
  406. if (ocfs2_buffer_cached(ci, bh))
  407. return;
  408. mlog(0, "Owner %llu, inserting block %llu\n",
  409. (unsigned long long)ocfs2_metadata_cache_owner(ci),
  410. (unsigned long long)bh->b_blocknr);
  411. /* No need to recheck under spinlock - insertion is guarded by
  412. * co_io_lock() */
  413. ocfs2_metadata_cache_lock(ci);
  414. if (ocfs2_insert_can_use_array(ci)) {
  415. /* Fast case - it's an array and there's a free
  416. * spot. */
  417. ocfs2_append_cache_array(ci, bh->b_blocknr);
  418. ocfs2_metadata_cache_unlock(ci);
  419. return;
  420. }
  421. expand = 0;
  422. if (ci->ci_flags & OCFS2_CACHE_FL_INLINE) {
  423. /* We need to bump things up to a tree. */
  424. expand = 1;
  425. }
  426. ocfs2_metadata_cache_unlock(ci);
  427. __ocfs2_set_buffer_uptodate(ci, bh->b_blocknr, expand);
  428. }
  429. /* Called against a newly allocated buffer. Most likely nobody should
  430. * be able to read this sort of metadata while it's still being
  431. * allocated, but this is careful to take co_io_lock() anyway. */
  432. void ocfs2_set_new_buffer_uptodate(struct ocfs2_caching_info *ci,
  433. struct buffer_head *bh)
  434. {
  435. /* This should definitely *not* exist in our cache */
  436. BUG_ON(ocfs2_buffer_cached(ci, bh));
  437. set_buffer_uptodate(bh);
  438. ocfs2_metadata_cache_io_lock(ci);
  439. ocfs2_set_buffer_uptodate(ci, bh);
  440. ocfs2_metadata_cache_io_unlock(ci);
  441. }
  442. /* Requires ip_lock. */
  443. static void ocfs2_remove_metadata_array(struct ocfs2_caching_info *ci,
  444. int index)
  445. {
  446. sector_t *array = ci->ci_cache.ci_array;
  447. int bytes;
  448. BUG_ON(index < 0 || index >= OCFS2_CACHE_INFO_MAX_ARRAY);
  449. BUG_ON(index >= ci->ci_num_cached);
  450. BUG_ON(!ci->ci_num_cached);
  451. mlog(0, "remove index %d (num_cached = %u\n", index,
  452. ci->ci_num_cached);
  453. ci->ci_num_cached--;
  454. /* don't need to copy if the array is now empty, or if we
  455. * removed at the tail */
  456. if (ci->ci_num_cached && index < ci->ci_num_cached) {
  457. bytes = sizeof(sector_t) * (ci->ci_num_cached - index);
  458. memmove(&array[index], &array[index + 1], bytes);
  459. }
  460. }
  461. /* Requires ip_lock. */
  462. static void ocfs2_remove_metadata_tree(struct ocfs2_caching_info *ci,
  463. struct ocfs2_meta_cache_item *item)
  464. {
  465. mlog(0, "remove block %llu from tree\n",
  466. (unsigned long long) item->c_block);
  467. rb_erase(&item->c_node, &ci->ci_cache.ci_tree);
  468. ci->ci_num_cached--;
  469. }
  470. static void ocfs2_remove_block_from_cache(struct ocfs2_caching_info *ci,
  471. sector_t block)
  472. {
  473. int index;
  474. struct ocfs2_meta_cache_item *item = NULL;
  475. ocfs2_metadata_cache_lock(ci);
  476. mlog(0, "Owner %llu, remove %llu, items = %u, array = %u\n",
  477. (unsigned long long)ocfs2_metadata_cache_owner(ci),
  478. (unsigned long long) block, ci->ci_num_cached,
  479. ci->ci_flags & OCFS2_CACHE_FL_INLINE);
  480. if (ci->ci_flags & OCFS2_CACHE_FL_INLINE) {
  481. index = ocfs2_search_cache_array(ci, block);
  482. if (index != -1)
  483. ocfs2_remove_metadata_array(ci, index);
  484. } else {
  485. item = ocfs2_search_cache_tree(ci, block);
  486. if (item)
  487. ocfs2_remove_metadata_tree(ci, item);
  488. }
  489. ocfs2_metadata_cache_unlock(ci);
  490. if (item)
  491. kmem_cache_free(ocfs2_uptodate_cachep, item);
  492. }
  493. /*
  494. * Called when we remove a chunk of metadata from an inode. We don't
  495. * bother reverting things to an inlined array in the case of a remove
  496. * which moves us back under the limit.
  497. */
  498. void ocfs2_remove_from_cache(struct ocfs2_caching_info *ci,
  499. struct buffer_head *bh)
  500. {
  501. sector_t block = bh->b_blocknr;
  502. ocfs2_remove_block_from_cache(ci, block);
  503. }
  504. /* Called when we remove xattr clusters from an inode. */
  505. void ocfs2_remove_xattr_clusters_from_cache(struct ocfs2_caching_info *ci,
  506. sector_t block,
  507. u32 c_len)
  508. {
  509. struct super_block *sb = ocfs2_metadata_cache_get_super(ci);
  510. unsigned int i, b_len = ocfs2_clusters_to_blocks(sb, 1) * c_len;
  511. for (i = 0; i < b_len; i++, block++)
  512. ocfs2_remove_block_from_cache(ci, block);
  513. }
  514. int __init init_ocfs2_uptodate_cache(void)
  515. {
  516. ocfs2_uptodate_cachep = kmem_cache_create("ocfs2_uptodate",
  517. sizeof(struct ocfs2_meta_cache_item),
  518. 0, SLAB_HWCACHE_ALIGN, NULL);
  519. if (!ocfs2_uptodate_cachep)
  520. return -ENOMEM;
  521. mlog(0, "%u inlined cache items per inode.\n",
  522. OCFS2_CACHE_INFO_MAX_ARRAY);
  523. return 0;
  524. }
  525. void exit_ocfs2_uptodate_cache(void)
  526. {
  527. if (ocfs2_uptodate_cachep)
  528. kmem_cache_destroy(ocfs2_uptodate_cachep);
  529. }