117c76b01SKoji Sato /* 217c76b01SKoji Sato * btree.h - NILFS B-tree. 317c76b01SKoji Sato * 417c76b01SKoji Sato * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 517c76b01SKoji Sato * 617c76b01SKoji Sato * This program is free software; you can redistribute it and/or modify 717c76b01SKoji Sato * it under the terms of the GNU General Public License as published by 817c76b01SKoji Sato * the Free Software Foundation; either version 2 of the License, or 917c76b01SKoji Sato * (at your option) any later version. 1017c76b01SKoji Sato * 1117c76b01SKoji Sato * This program is distributed in the hope that it will be useful, 1217c76b01SKoji Sato * but WITHOUT ANY WARRANTY; without even the implied warranty of 1317c76b01SKoji Sato * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1417c76b01SKoji Sato * GNU General Public License for more details. 1517c76b01SKoji Sato * 16*4b420ab4SRyusuke Konishi * Written by Koji Sato. 1717c76b01SKoji Sato */ 1817c76b01SKoji Sato 1917c76b01SKoji Sato #ifndef _NILFS_BTREE_H 2017c76b01SKoji Sato #define _NILFS_BTREE_H 2117c76b01SKoji Sato 2217c76b01SKoji Sato #include <linux/types.h> 2317c76b01SKoji Sato #include <linux/buffer_head.h> 2417c76b01SKoji Sato #include <linux/list.h> 2517c76b01SKoji Sato #include <linux/nilfs2_fs.h> 2617c76b01SKoji Sato #include "btnode.h" 2717c76b01SKoji Sato #include "bmap.h" 2817c76b01SKoji Sato 2917c76b01SKoji Sato /** 3041c88bd7SLi Hong * struct nilfs_btree_path - A path on which B-tree operations are executed 3141c88bd7SLi Hong * @bp_bh: buffer head of node block 3241c88bd7SLi Hong * @bp_sib_bh: buffer head of sibling node block 3341c88bd7SLi Hong * @bp_index: index of child node 3441c88bd7SLi Hong * @bp_oldreq: ptr end request for old ptr 3541c88bd7SLi Hong * @bp_newreq: ptr alloc request for new ptr 3641c88bd7SLi Hong * @bp_op: rebalance operation 3741c88bd7SLi Hong */ 3841c88bd7SLi Hong struct nilfs_btree_path { 3941c88bd7SLi Hong struct buffer_head *bp_bh; 4041c88bd7SLi Hong struct buffer_head *bp_sib_bh; 4141c88bd7SLi Hong int bp_index; 4241c88bd7SLi Hong union nilfs_bmap_ptr_req bp_oldreq; 4341c88bd7SLi Hong union nilfs_bmap_ptr_req bp_newreq; 4441c88bd7SLi Hong struct nilfs_btnode_chkey_ctxt bp_ctxt; 45e7c274f8SRyusuke Konishi void (*bp_op)(struct nilfs_bmap *, struct nilfs_btree_path *, 4641c88bd7SLi Hong int, __u64 *, __u64 *); 4741c88bd7SLi Hong }; 4817c76b01SKoji Sato 4917c76b01SKoji Sato #define NILFS_BTREE_ROOT_SIZE NILFS_BMAP_SIZE 5017c76b01SKoji Sato #define NILFS_BTREE_ROOT_NCHILDREN_MAX \ 5117c76b01SKoji Sato ((NILFS_BTREE_ROOT_SIZE - sizeof(struct nilfs_btree_node)) / \ 5217c76b01SKoji Sato (sizeof(__le64 /* dkey */) + sizeof(__le64 /* dptr */))) 5317c76b01SKoji Sato #define NILFS_BTREE_ROOT_NCHILDREN_MIN 0 5417c76b01SKoji Sato #define NILFS_BTREE_NODE_EXTRA_PAD_SIZE (sizeof(__le64)) 5517c76b01SKoji Sato #define NILFS_BTREE_NODE_NCHILDREN_MAX(nodesize) \ 5617c76b01SKoji Sato (((nodesize) - sizeof(struct nilfs_btree_node) - \ 5717c76b01SKoji Sato NILFS_BTREE_NODE_EXTRA_PAD_SIZE) / \ 5817c76b01SKoji Sato (sizeof(__le64 /* dkey */) + sizeof(__le64 /* dptr */))) 5917c76b01SKoji Sato #define NILFS_BTREE_NODE_NCHILDREN_MIN(nodesize) \ 6017c76b01SKoji Sato ((NILFS_BTREE_NODE_NCHILDREN_MAX(nodesize) - 1) / 2 + 1) 6117c76b01SKoji Sato #define NILFS_BTREE_KEY_MIN ((__u64)0) 6217c76b01SKoji Sato #define NILFS_BTREE_KEY_MAX (~(__u64)0) 6317c76b01SKoji Sato 6441c88bd7SLi Hong extern struct kmem_cache *nilfs_btree_path_cache; 6517c76b01SKoji Sato 663033342aSRyusuke Konishi int nilfs_btree_init(struct nilfs_bmap *); 6717c76b01SKoji Sato int nilfs_btree_convert_and_insert(struct nilfs_bmap *, __u64, __u64, 683033342aSRyusuke Konishi const __u64 *, const __u64 *, int); 6917c76b01SKoji Sato void nilfs_btree_init_gc(struct nilfs_bmap *); 7017c76b01SKoji Sato 711d5385b9SRyusuke Konishi int nilfs_btree_broken_node_block(struct buffer_head *bh); 721d5385b9SRyusuke Konishi 7317c76b01SKoji Sato #endif /* _NILFS_BTREE_H */ 74