sys/vfs/hammer: Add hammer_node_max_elements()
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Fri, 10 Jul 2015 14:07:28 +0000 (23:07 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Fri, 10 Jul 2015 17:33:11 +0000 (02:33 +0900)
- Add inline function hammer_node_max_elements() and make
  it available to userspace.

- The relation between btree node type and # of elements is
  a part of ondisk definition, so it's better to have it in
  the same header file.

sbin/hammer/cmd_show.c
sys/vfs/hammer/hammer_btree.c
sys/vfs/hammer/hammer_btree.h

index 0c512d4..2beba35 100644 (file)
@@ -170,8 +170,8 @@ print_btree_node(hammer_off_t node_offset, btree_search_t search,
        }
        printf(" {\n");
 
-       maxcount = (node->type == HAMMER_BTREE_TYPE_INTERNAL) ?
-                  HAMMER_BTREE_INT_ELMS : HAMMER_BTREE_LEAF_ELMS;
+       maxcount = hammer_node_max_elements(node->type);
+       assert(maxcount != -1);
 
        for (i = 0; i < node->count && i < maxcount; ++i) {
                elm = &node->elms[i];
index 27482dc..d27b753 100644 (file)
@@ -3048,11 +3048,12 @@ static __inline
 int
 btree_max_elements(u_int8_t type)
 {
-       if (type == HAMMER_BTREE_TYPE_LEAF)
-               return(HAMMER_BTREE_LEAF_ELMS);
-       if (type == HAMMER_BTREE_TYPE_INTERNAL)
-               return(HAMMER_BTREE_INT_ELMS);
-       panic("btree_max_elements: bad type %d", type);
+       int n;
+
+       n = hammer_node_max_elements(type);
+       if (n == -1)
+               panic("btree_max_elements: bad type %d", type);
+       return(n);
 }
 
 void
index 526d59c..ff664a0 100644 (file)
@@ -209,6 +209,19 @@ typedef union hammer_btree_elm *hammer_btree_elm_t;
 #define HAMMER_BTREE_TYPE_RECORD       ((u_int8_t)'R')
 #define HAMMER_BTREE_TYPE_DELETED      ((u_int8_t)'D')
 
+static __inline
+int
+hammer_node_max_elements(u_int8_t type)
+{
+       switch (type) {
+       case HAMMER_BTREE_TYPE_LEAF:
+               return(HAMMER_BTREE_LEAF_ELMS);
+       case HAMMER_BTREE_TYPE_INTERNAL:
+               return(HAMMER_BTREE_INT_ELMS);
+       }
+       return(-1);  /* invalid type */
+}
+
 struct hammer_node_ondisk {
        /*
         * B-Tree node header (64 bytes)