uptodate.c 18 KB

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