uptodate.c 18 KB

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