btree.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. * Written by Koji Sato.
  17. */
  18. #ifndef _NILFS_BTREE_H
  19. #define _NILFS_BTREE_H
  20. #include <linux/types.h>
  21. #include <linux/buffer_head.h>
  22. #include <linux/list.h>
  23. #include <linux/nilfs2_ondisk.h> /* nilfs_btree_node */
  24. #include "btnode.h"
  25. #include "bmap.h"
  26. /**
  27. * struct nilfs_btree_path - A path on which B-tree operations are executed
  28. * @bp_bh: buffer head of node block
  29. * @bp_sib_bh: buffer head of sibling node block
  30. * @bp_index: index of child node
  31. * @bp_oldreq: ptr end request for old ptr
  32. * @bp_newreq: ptr alloc request for new ptr
  33. * @bp_op: rebalance operation
  34. */
  35. struct nilfs_btree_path {
  36. struct buffer_head *bp_bh;
  37. struct buffer_head *bp_sib_bh;
  38. int bp_index;
  39. union nilfs_bmap_ptr_req bp_oldreq;
  40. union nilfs_bmap_ptr_req bp_newreq;
  41. struct nilfs_btnode_chkey_ctxt bp_ctxt;
  42. void (*bp_op)(struct nilfs_bmap *, struct nilfs_btree_path *,
  43. int, __u64 *, __u64 *);
  44. };
  45. #define NILFS_BTREE_ROOT_SIZE NILFS_BMAP_SIZE
  46. #define NILFS_BTREE_ROOT_NCHILDREN_MAX \
  47. ((NILFS_BTREE_ROOT_SIZE - sizeof(struct nilfs_btree_node)) / \
  48. (sizeof(__le64 /* dkey */) + sizeof(__le64 /* dptr */)))
  49. #define NILFS_BTREE_ROOT_NCHILDREN_MIN 0
  50. #define NILFS_BTREE_NODE_EXTRA_PAD_SIZE (sizeof(__le64))
  51. #define NILFS_BTREE_NODE_NCHILDREN_MAX(nodesize) \
  52. (((nodesize) - sizeof(struct nilfs_btree_node) - \
  53. NILFS_BTREE_NODE_EXTRA_PAD_SIZE) / \
  54. (sizeof(__le64 /* dkey */) + sizeof(__le64 /* dptr */)))
  55. #define NILFS_BTREE_NODE_NCHILDREN_MIN(nodesize) \
  56. ((NILFS_BTREE_NODE_NCHILDREN_MAX(nodesize) - 1) / 2 + 1)
  57. #define NILFS_BTREE_KEY_MIN ((__u64)0)
  58. #define NILFS_BTREE_KEY_MAX (~(__u64)0)
  59. extern struct kmem_cache *nilfs_btree_path_cache;
  60. int nilfs_btree_init(struct nilfs_bmap *);
  61. int nilfs_btree_convert_and_insert(struct nilfs_bmap *, __u64, __u64,
  62. const __u64 *, const __u64 *, int);
  63. void nilfs_btree_init_gc(struct nilfs_bmap *);
  64. int nilfs_btree_broken_node_block(struct buffer_head *bh);
  65. #endif /* _NILFS_BTREE_H */