btree.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * btree.h - NILFS B-tree.
  3. *
  4. * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. *
  20. * Written by Koji Sato <koji@osrg.net>.
  21. */
  22. #ifndef _NILFS_BTREE_H
  23. #define _NILFS_BTREE_H
  24. #include <linux/types.h>
  25. #include <linux/buffer_head.h>
  26. #include <linux/list.h>
  27. #include <linux/nilfs2_fs.h>
  28. #include "btnode.h"
  29. #include "bmap.h"
  30. /**
  31. * struct nilfs_btree - B-tree structure
  32. * @bt_bmap: bmap base structure
  33. */
  34. struct nilfs_btree {
  35. struct nilfs_bmap bt_bmap;
  36. };
  37. /**
  38. * struct nilfs_btree_path - A path on which B-tree operations are executed
  39. * @bp_bh: buffer head of node block
  40. * @bp_sib_bh: buffer head of sibling node block
  41. * @bp_index: index of child node
  42. * @bp_oldreq: ptr end request for old ptr
  43. * @bp_newreq: ptr alloc request for new ptr
  44. * @bp_op: rebalance operation
  45. */
  46. struct nilfs_btree_path {
  47. struct buffer_head *bp_bh;
  48. struct buffer_head *bp_sib_bh;
  49. int bp_index;
  50. union nilfs_bmap_ptr_req bp_oldreq;
  51. union nilfs_bmap_ptr_req bp_newreq;
  52. struct nilfs_btnode_chkey_ctxt bp_ctxt;
  53. void (*bp_op)(struct nilfs_btree *, struct nilfs_btree_path *,
  54. int, __u64 *, __u64 *);
  55. };
  56. #define NILFS_BTREE_ROOT_SIZE NILFS_BMAP_SIZE
  57. #define NILFS_BTREE_ROOT_NCHILDREN_MAX \
  58. ((NILFS_BTREE_ROOT_SIZE - sizeof(struct nilfs_btree_node)) / \
  59. (sizeof(__le64 /* dkey */) + sizeof(__le64 /* dptr */)))
  60. #define NILFS_BTREE_ROOT_NCHILDREN_MIN 0
  61. #define NILFS_BTREE_NODE_EXTRA_PAD_SIZE (sizeof(__le64))
  62. #define NILFS_BTREE_NODE_NCHILDREN_MAX(nodesize) \
  63. (((nodesize) - sizeof(struct nilfs_btree_node) - \
  64. NILFS_BTREE_NODE_EXTRA_PAD_SIZE) / \
  65. (sizeof(__le64 /* dkey */) + sizeof(__le64 /* dptr */)))
  66. #define NILFS_BTREE_NODE_NCHILDREN_MIN(nodesize) \
  67. ((NILFS_BTREE_NODE_NCHILDREN_MAX(nodesize) - 1) / 2 + 1)
  68. #define NILFS_BTREE_KEY_MIN ((__u64)0)
  69. #define NILFS_BTREE_KEY_MAX (~(__u64)0)
  70. extern struct kmem_cache *nilfs_btree_path_cache;
  71. int nilfs_btree_path_cache_init(void);
  72. void nilfs_btree_path_cache_destroy(void);
  73. int nilfs_btree_init(struct nilfs_bmap *);
  74. int nilfs_btree_convert_and_insert(struct nilfs_bmap *, __u64, __u64,
  75. const __u64 *, const __u64 *, int);
  76. void nilfs_btree_init_gc(struct nilfs_bmap *);
  77. #endif /* _NILFS_BTREE_H */