1ae98043fSRyusuke Konishi /* SPDX-License-Identifier: GPL-2.0+ */ 217c76b01SKoji Sato /* 3*94ee1d91SRyusuke Konishi * NILFS B-tree. 417c76b01SKoji Sato * 517c76b01SKoji Sato * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. 617c76b01SKoji Sato * 74b420ab4SRyusuke Konishi * Written by Koji Sato. 817c76b01SKoji Sato */ 917c76b01SKoji Sato 1017c76b01SKoji Sato #ifndef _NILFS_BTREE_H 1117c76b01SKoji Sato #define _NILFS_BTREE_H 1217c76b01SKoji Sato 1317c76b01SKoji Sato #include <linux/types.h> 1417c76b01SKoji Sato #include <linux/buffer_head.h> 1517c76b01SKoji Sato #include <linux/list.h> 16e63e88bcSRyusuke Konishi #include <linux/nilfs2_ondisk.h> /* nilfs_btree_node */ 1717c76b01SKoji Sato #include "btnode.h" 1817c76b01SKoji Sato #include "bmap.h" 1917c76b01SKoji Sato 2017c76b01SKoji Sato /** 2141c88bd7SLi Hong * struct nilfs_btree_path - A path on which B-tree operations are executed 2241c88bd7SLi Hong * @bp_bh: buffer head of node block 2341c88bd7SLi Hong * @bp_sib_bh: buffer head of sibling node block 2441c88bd7SLi Hong * @bp_index: index of child node 2541c88bd7SLi Hong * @bp_oldreq: ptr end request for old ptr 2641c88bd7SLi Hong * @bp_newreq: ptr alloc request for new ptr 2741c88bd7SLi Hong * @bp_op: rebalance operation 2841c88bd7SLi Hong */ 2941c88bd7SLi Hong struct nilfs_btree_path { 3041c88bd7SLi Hong struct buffer_head *bp_bh; 3141c88bd7SLi Hong struct buffer_head *bp_sib_bh; 3241c88bd7SLi Hong int bp_index; 3341c88bd7SLi Hong union nilfs_bmap_ptr_req bp_oldreq; 3441c88bd7SLi Hong union nilfs_bmap_ptr_req bp_newreq; 3541c88bd7SLi Hong struct nilfs_btnode_chkey_ctxt bp_ctxt; 36e7c274f8SRyusuke Konishi void (*bp_op)(struct nilfs_bmap *, struct nilfs_btree_path *, 3741c88bd7SLi Hong int, __u64 *, __u64 *); 3841c88bd7SLi Hong }; 3917c76b01SKoji Sato 4017c76b01SKoji Sato #define NILFS_BTREE_ROOT_SIZE NILFS_BMAP_SIZE 4117c76b01SKoji Sato #define NILFS_BTREE_ROOT_NCHILDREN_MAX \ 4217c76b01SKoji Sato ((NILFS_BTREE_ROOT_SIZE - sizeof(struct nilfs_btree_node)) / \ 4317c76b01SKoji Sato (sizeof(__le64 /* dkey */) + sizeof(__le64 /* dptr */))) 4417c76b01SKoji Sato #define NILFS_BTREE_ROOT_NCHILDREN_MIN 0 4517c76b01SKoji Sato #define NILFS_BTREE_NODE_EXTRA_PAD_SIZE (sizeof(__le64)) 4617c76b01SKoji Sato #define NILFS_BTREE_NODE_NCHILDREN_MAX(nodesize) \ 4717c76b01SKoji Sato (((nodesize) - sizeof(struct nilfs_btree_node) - \ 4817c76b01SKoji Sato NILFS_BTREE_NODE_EXTRA_PAD_SIZE) / \ 4917c76b01SKoji Sato (sizeof(__le64 /* dkey */) + sizeof(__le64 /* dptr */))) 5017c76b01SKoji Sato #define NILFS_BTREE_NODE_NCHILDREN_MIN(nodesize) \ 5117c76b01SKoji Sato ((NILFS_BTREE_NODE_NCHILDREN_MAX(nodesize) - 1) / 2 + 1) 5217c76b01SKoji Sato #define NILFS_BTREE_KEY_MIN ((__u64)0) 5317c76b01SKoji Sato #define NILFS_BTREE_KEY_MAX (~(__u64)0) 5417c76b01SKoji Sato 5541c88bd7SLi Hong extern struct kmem_cache *nilfs_btree_path_cache; 5617c76b01SKoji Sato 573033342aSRyusuke Konishi int nilfs_btree_init(struct nilfs_bmap *); 5817c76b01SKoji Sato int nilfs_btree_convert_and_insert(struct nilfs_bmap *, __u64, __u64, 593033342aSRyusuke Konishi const __u64 *, const __u64 *, int); 6017c76b01SKoji Sato void nilfs_btree_init_gc(struct nilfs_bmap *); 6117c76b01SKoji Sato 621d5385b9SRyusuke Konishi int nilfs_btree_broken_node_block(struct buffer_head *bh); 631d5385b9SRyusuke Konishi 6417c76b01SKoji Sato #endif /* _NILFS_BTREE_H */ 65