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 * 1617c76b01SKoji Sato * You should have received a copy of the GNU General Public License 1717c76b01SKoji Sato * along with this program; if not, write to the Free Software 1817c76b01SKoji Sato * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 1917c76b01SKoji Sato * 2017c76b01SKoji Sato * Written by Koji Sato <koji@osrg.net>. 2117c76b01SKoji Sato */ 2217c76b01SKoji Sato 2317c76b01SKoji Sato #ifndef _NILFS_BTREE_H 2417c76b01SKoji Sato #define _NILFS_BTREE_H 2517c76b01SKoji Sato 2617c76b01SKoji Sato #include <linux/types.h> 2717c76b01SKoji Sato #include <linux/buffer_head.h> 2817c76b01SKoji Sato #include <linux/list.h> 2917c76b01SKoji Sato #include <linux/nilfs2_fs.h> 3017c76b01SKoji Sato #include "btnode.h" 3117c76b01SKoji Sato #include "bmap.h" 3217c76b01SKoji Sato 3317c76b01SKoji Sato /** 3417c76b01SKoji Sato * struct nilfs_btree - B-tree structure 3517c76b01SKoji Sato * @bt_bmap: bmap base structure 3617c76b01SKoji Sato */ 3717c76b01SKoji Sato struct nilfs_btree { 3817c76b01SKoji Sato struct nilfs_bmap bt_bmap; 3917c76b01SKoji Sato }; 4017c76b01SKoji Sato 41*41c88bd7SLi Hong /** 42*41c88bd7SLi Hong * struct nilfs_btree_path - A path on which B-tree operations are executed 43*41c88bd7SLi Hong * @bp_bh: buffer head of node block 44*41c88bd7SLi Hong * @bp_sib_bh: buffer head of sibling node block 45*41c88bd7SLi Hong * @bp_index: index of child node 46*41c88bd7SLi Hong * @bp_oldreq: ptr end request for old ptr 47*41c88bd7SLi Hong * @bp_newreq: ptr alloc request for new ptr 48*41c88bd7SLi Hong * @bp_op: rebalance operation 49*41c88bd7SLi Hong */ 50*41c88bd7SLi Hong struct nilfs_btree_path { 51*41c88bd7SLi Hong struct buffer_head *bp_bh; 52*41c88bd7SLi Hong struct buffer_head *bp_sib_bh; 53*41c88bd7SLi Hong int bp_index; 54*41c88bd7SLi Hong union nilfs_bmap_ptr_req bp_oldreq; 55*41c88bd7SLi Hong union nilfs_bmap_ptr_req bp_newreq; 56*41c88bd7SLi Hong struct nilfs_btnode_chkey_ctxt bp_ctxt; 57*41c88bd7SLi Hong void (*bp_op)(struct nilfs_btree *, struct nilfs_btree_path *, 58*41c88bd7SLi Hong int, __u64 *, __u64 *); 59*41c88bd7SLi Hong }; 6017c76b01SKoji Sato 6117c76b01SKoji Sato #define NILFS_BTREE_ROOT_SIZE NILFS_BMAP_SIZE 6217c76b01SKoji Sato #define NILFS_BTREE_ROOT_NCHILDREN_MAX \ 6317c76b01SKoji Sato ((NILFS_BTREE_ROOT_SIZE - sizeof(struct nilfs_btree_node)) / \ 6417c76b01SKoji Sato (sizeof(__le64 /* dkey */) + sizeof(__le64 /* dptr */))) 6517c76b01SKoji Sato #define NILFS_BTREE_ROOT_NCHILDREN_MIN 0 6617c76b01SKoji Sato #define NILFS_BTREE_NODE_EXTRA_PAD_SIZE (sizeof(__le64)) 6717c76b01SKoji Sato #define NILFS_BTREE_NODE_NCHILDREN_MAX(nodesize) \ 6817c76b01SKoji Sato (((nodesize) - sizeof(struct nilfs_btree_node) - \ 6917c76b01SKoji Sato NILFS_BTREE_NODE_EXTRA_PAD_SIZE) / \ 7017c76b01SKoji Sato (sizeof(__le64 /* dkey */) + sizeof(__le64 /* dptr */))) 7117c76b01SKoji Sato #define NILFS_BTREE_NODE_NCHILDREN_MIN(nodesize) \ 7217c76b01SKoji Sato ((NILFS_BTREE_NODE_NCHILDREN_MAX(nodesize) - 1) / 2 + 1) 7317c76b01SKoji Sato #define NILFS_BTREE_KEY_MIN ((__u64)0) 7417c76b01SKoji Sato #define NILFS_BTREE_KEY_MAX (~(__u64)0) 7517c76b01SKoji Sato 76*41c88bd7SLi Hong extern struct kmem_cache *nilfs_btree_path_cache; 7717c76b01SKoji Sato 7817c76b01SKoji Sato int nilfs_btree_path_cache_init(void); 7917c76b01SKoji Sato void nilfs_btree_path_cache_destroy(void); 803033342aSRyusuke Konishi int nilfs_btree_init(struct nilfs_bmap *); 8117c76b01SKoji Sato int nilfs_btree_convert_and_insert(struct nilfs_bmap *, __u64, __u64, 823033342aSRyusuke Konishi const __u64 *, const __u64 *, int); 8317c76b01SKoji Sato void nilfs_btree_init_gc(struct nilfs_bmap *); 8417c76b01SKoji Sato 8517c76b01SKoji Sato #endif /* _NILFS_BTREE_H */ 86