btree.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. struct nilfs_btree;
  31. struct nilfs_btree_path;
  32. /**
  33. * struct nilfs_btree_operations - B-tree operation table
  34. */
  35. struct nilfs_btree_operations {
  36. __u64 (*btop_find_target)(const struct nilfs_btree *,
  37. const struct nilfs_btree_path *, __u64);
  38. void (*btop_set_target)(struct nilfs_btree *, __u64, __u64);
  39. struct the_nilfs *(*btop_get_nilfs)(struct nilfs_btree *);
  40. int (*btop_propagate)(struct nilfs_btree *,
  41. struct nilfs_btree_path *,
  42. int,
  43. struct buffer_head *);
  44. int (*btop_assign)(struct nilfs_btree *,
  45. struct nilfs_btree_path *,
  46. int,
  47. struct buffer_head **,
  48. sector_t,
  49. union nilfs_binfo *);
  50. };
  51. /**
  52. * struct nilfs_btree_node - B-tree node
  53. * @bn_flags: flags
  54. * @bn_level: level
  55. * @bn_nchildren: number of children
  56. * @bn_pad: padding
  57. */
  58. struct nilfs_btree_node {
  59. __u8 bn_flags;
  60. __u8 bn_level;
  61. __le16 bn_nchildren;
  62. __le32 bn_pad;
  63. };
  64. /* flags */
  65. #define NILFS_BTREE_NODE_ROOT 0x01
  66. /* level */
  67. #define NILFS_BTREE_LEVEL_DATA 0
  68. #define NILFS_BTREE_LEVEL_NODE_MIN (NILFS_BTREE_LEVEL_DATA + 1)
  69. #define NILFS_BTREE_LEVEL_MAX 14
  70. /**
  71. * struct nilfs_btree - B-tree structure
  72. * @bt_bmap: bmap base structure
  73. * @bt_ops: B-tree operation table
  74. */
  75. struct nilfs_btree {
  76. struct nilfs_bmap bt_bmap;
  77. /* B-tree-specific members */
  78. const struct nilfs_btree_operations *bt_ops;
  79. };
  80. #define NILFS_BTREE_ROOT_SIZE NILFS_BMAP_SIZE
  81. #define NILFS_BTREE_ROOT_NCHILDREN_MAX \
  82. ((NILFS_BTREE_ROOT_SIZE - sizeof(struct nilfs_btree_node)) / \
  83. (sizeof(__le64 /* dkey */) + sizeof(__le64 /* dptr */)))
  84. #define NILFS_BTREE_ROOT_NCHILDREN_MIN 0
  85. #define NILFS_BTREE_NODE_EXTRA_PAD_SIZE (sizeof(__le64))
  86. #define NILFS_BTREE_NODE_NCHILDREN_MAX(nodesize) \
  87. (((nodesize) - sizeof(struct nilfs_btree_node) - \
  88. NILFS_BTREE_NODE_EXTRA_PAD_SIZE) / \
  89. (sizeof(__le64 /* dkey */) + sizeof(__le64 /* dptr */)))
  90. #define NILFS_BTREE_NODE_NCHILDREN_MIN(nodesize) \
  91. ((NILFS_BTREE_NODE_NCHILDREN_MAX(nodesize) - 1) / 2 + 1)
  92. #define NILFS_BTREE_KEY_MIN ((__u64)0)
  93. #define NILFS_BTREE_KEY_MAX (~(__u64)0)
  94. int nilfs_btree_path_cache_init(void);
  95. void nilfs_btree_path_cache_destroy(void);
  96. int nilfs_btree_init(struct nilfs_bmap *, __u64, __u64);
  97. int nilfs_btree_convert_and_insert(struct nilfs_bmap *, __u64, __u64,
  98. const __u64 *, const __u64 *,
  99. int, __u64, __u64);
  100. void nilfs_btree_init_gc(struct nilfs_bmap *);
  101. #endif /* _NILFS_BTREE_H */