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 struct nilfs_btree; 3417c76b01SKoji Sato struct nilfs_btree_path; 3517c76b01SKoji Sato 3617c76b01SKoji Sato /** 3717c76b01SKoji Sato * struct nilfs_btree_operations - B-tree operation table 3817c76b01SKoji Sato */ 3917c76b01SKoji Sato struct nilfs_btree_operations { 4017c76b01SKoji Sato __u64 (*btop_find_target)(const struct nilfs_btree *, 4117c76b01SKoji Sato const struct nilfs_btree_path *, __u64); 4217c76b01SKoji Sato void (*btop_set_target)(struct nilfs_btree *, __u64, __u64); 4317c76b01SKoji Sato 4417c76b01SKoji Sato struct the_nilfs *(*btop_get_nilfs)(struct nilfs_btree *); 4517c76b01SKoji Sato 4617c76b01SKoji Sato int (*btop_propagate)(struct nilfs_btree *, 4717c76b01SKoji Sato struct nilfs_btree_path *, 4817c76b01SKoji Sato int, 4917c76b01SKoji Sato struct buffer_head *); 5017c76b01SKoji Sato int (*btop_assign)(struct nilfs_btree *, 5117c76b01SKoji Sato struct nilfs_btree_path *, 5217c76b01SKoji Sato int, 5317c76b01SKoji Sato struct buffer_head **, 5417c76b01SKoji Sato sector_t, 5517c76b01SKoji Sato union nilfs_binfo *); 5617c76b01SKoji Sato }; 5717c76b01SKoji Sato 5817c76b01SKoji Sato /** 5917c76b01SKoji Sato * struct nilfs_btree_node - B-tree node 6017c76b01SKoji Sato * @bn_flags: flags 6117c76b01SKoji Sato * @bn_level: level 6217c76b01SKoji Sato * @bn_nchildren: number of children 6317c76b01SKoji Sato * @bn_pad: padding 6417c76b01SKoji Sato */ 6517c76b01SKoji Sato struct nilfs_btree_node { 6617c76b01SKoji Sato __u8 bn_flags; 6717c76b01SKoji Sato __u8 bn_level; 6817c76b01SKoji Sato __le16 bn_nchildren; 6917c76b01SKoji Sato __le32 bn_pad; 7017c76b01SKoji Sato }; 7117c76b01SKoji Sato 7217c76b01SKoji Sato /* flags */ 7317c76b01SKoji Sato #define NILFS_BTREE_NODE_ROOT 0x01 7417c76b01SKoji Sato 7517c76b01SKoji Sato /* level */ 7617c76b01SKoji Sato #define NILFS_BTREE_LEVEL_DATA 0 7717c76b01SKoji Sato #define NILFS_BTREE_LEVEL_NODE_MIN (NILFS_BTREE_LEVEL_DATA + 1) 7817c76b01SKoji Sato #define NILFS_BTREE_LEVEL_MAX 14 7917c76b01SKoji Sato 8017c76b01SKoji Sato /** 8117c76b01SKoji Sato * struct nilfs_btree - B-tree structure 8217c76b01SKoji Sato * @bt_bmap: bmap base structure 8317c76b01SKoji Sato * @bt_ops: B-tree operation table 8417c76b01SKoji Sato */ 8517c76b01SKoji Sato struct nilfs_btree { 8617c76b01SKoji Sato struct nilfs_bmap bt_bmap; 8717c76b01SKoji Sato 8817c76b01SKoji Sato /* B-tree-specific members */ 8917c76b01SKoji Sato const struct nilfs_btree_operations *bt_ops; 9017c76b01SKoji Sato }; 9117c76b01SKoji Sato 9217c76b01SKoji Sato 9317c76b01SKoji Sato #define NILFS_BTREE_ROOT_SIZE NILFS_BMAP_SIZE 9417c76b01SKoji Sato #define NILFS_BTREE_ROOT_NCHILDREN_MAX \ 9517c76b01SKoji Sato ((NILFS_BTREE_ROOT_SIZE - sizeof(struct nilfs_btree_node)) / \ 9617c76b01SKoji Sato (sizeof(__le64 /* dkey */) + sizeof(__le64 /* dptr */))) 9717c76b01SKoji Sato #define NILFS_BTREE_ROOT_NCHILDREN_MIN 0 9817c76b01SKoji Sato #define NILFS_BTREE_NODE_EXTRA_PAD_SIZE (sizeof(__le64)) 9917c76b01SKoji Sato #define NILFS_BTREE_NODE_NCHILDREN_MAX(nodesize) \ 10017c76b01SKoji Sato (((nodesize) - sizeof(struct nilfs_btree_node) - \ 10117c76b01SKoji Sato NILFS_BTREE_NODE_EXTRA_PAD_SIZE) / \ 10217c76b01SKoji Sato (sizeof(__le64 /* dkey */) + sizeof(__le64 /* dptr */))) 10317c76b01SKoji Sato #define NILFS_BTREE_NODE_NCHILDREN_MIN(nodesize) \ 10417c76b01SKoji Sato ((NILFS_BTREE_NODE_NCHILDREN_MAX(nodesize) - 1) / 2 + 1) 10517c76b01SKoji Sato #define NILFS_BTREE_KEY_MIN ((__u64)0) 10617c76b01SKoji Sato #define NILFS_BTREE_KEY_MAX (~(__u64)0) 10717c76b01SKoji Sato 10817c76b01SKoji Sato 10917c76b01SKoji Sato int nilfs_btree_path_cache_init(void); 11017c76b01SKoji Sato void nilfs_btree_path_cache_destroy(void); 111*3033342aSRyusuke Konishi int nilfs_btree_init(struct nilfs_bmap *); 11217c76b01SKoji Sato int nilfs_btree_convert_and_insert(struct nilfs_bmap *, __u64, __u64, 113*3033342aSRyusuke Konishi const __u64 *, const __u64 *, int); 11417c76b01SKoji Sato void nilfs_btree_init_gc(struct nilfs_bmap *); 11517c76b01SKoji Sato 11617c76b01SKoji Sato #endif /* _NILFS_BTREE_H */ 117