Primary header file infrastructure and A-list implementation for the
[dragonfly.git] / sys / vfs / hammer / hammer.h
1 /*
2  * Copyright (c) 2007 The DragonFly Project.  All rights reserved.
3  * 
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com>
6  * 
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  * 3. Neither the name of The DragonFly Project nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific, prior written permission.
20  * 
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  * 
34  * $DragonFly: src/sys/vfs/hammer/hammer.h,v 1.1 2007/10/10 19:37:25 dillon Exp $
35  */
36 /*
37  * This header file contains structures used internally by the HAMMERFS
38  * implementation.  See hammerfs.h for on-disk structures.
39  */
40
41 #include <sys/tree.h>
42 #include <sys/malloc.h>
43 #include "hammerfs.h"
44 #include "hammer_mount.h"
45
46 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
47
48 MALLOC_DECLARE(M_HAMMER);
49
50 /*
51  * Key structure used for custom RB tree inode lookups.  This prototypes
52  * the function hammer_ino_rb_tree_RB_LOOKUP_INFO(root, info).
53  */
54 typedef struct hammer_inode_info {
55         u_int64_t       obj_id;         /* (key) object identifier */
56         hammer_tid_t    obj_asof;       /* (key) snapshot transid or 0 */
57 } *hammer_inode_info_t;
58
59 /*
60  * Key and caching structure used for HAMMER B-Tree lookups.
61  */
62 struct hammer_btree_info {
63         struct hammer_base_elm key;
64 };
65
66 /*
67  * Structures used to internally represent an inode
68  */
69 struct hammer_ino_rb_tree;
70 struct hammer_inode;
71 RB_HEAD(hammer_ino_rb_tree, hammer_inode);
72 RB_PROTOTYPEX(hammer_ino_rb_tree, INFO, hammer_inode, rb_node,
73              hammer_ino_rb_compare, hammer_inode_info_t);
74
75 struct hammer_inode {
76         RB_ENTRY(hammer_inode) rb_node;
77         u_int64_t       obj_id;         /* (key) object identifier */
78         hammer_tid_t    obj_asof;       /* (key) snapshot transid or 0 */
79         struct hammer_mount *hmp;
80 };
81
82 /*
83  * Structures used to internally represent a volume and a cluster
84  */
85
86 struct hammer_volume;
87 struct hammer_cluster;
88 RB_HEAD(hammer_vol_rb_tree, hammer_volume);
89 RB_HEAD(hammer_clu_rb_tree, hammer_cluster);
90
91 RB_PROTOTYPE2(hammer_vol_rb_tree, hammer_volume, rb_node,
92               hammer_vol_rb_compare, int32_t);
93 RB_PROTOTYPE2(hammer_clu_rb_tree, hammer_cluster, rb_node,
94               hammer_clu_rb_compare, int32_t);
95
96 struct hammer_volume {
97         RB_ENTRY(hammer_volume) rb_node;
98         struct hammer_clu_rb_tree rb_clus_root;
99         struct hammer_volume_ondisk *ondisk;
100         int32_t vol_no;
101         int32_t vol_clsize;
102         int64_t cluster_base;   /* base offset of cluster 0 */
103         char *vol_name;
104         struct vnode *devvp;
105         struct hammer_mount *hmp;
106 };
107
108 struct hammer_cluster {
109         RB_ENTRY(hammer_cluster) rb_node;
110         struct hammer_cluster_ondisk *ondisk;
111         struct hammer_volume *volume;
112         int32_t clu_no;
113 };
114
115 /*
116  * Internal hammer mount data structure
117  */
118 struct hammer_mount {
119         struct mount *mp;
120         struct vnode *rootvp;
121         struct hammer_ino_rb_tree rb_inos_root;
122         struct hammer_vol_rb_tree rb_vols_root;
123         struct hammer_volume *rootvol;
124         struct hammer_cluster *rootcl;
125         uuid_t  fsid;
126 };
127
128
129 #endif
130
131 #if defined(_KERNEL)
132
133 extern struct vop_ops hammer_vnode_vops;
134 int     hammer_vop_inactive(struct vop_inactive_args *);
135 int     hammer_vop_reclaim(struct vop_reclaim_args *);
136 int     hammer_vfs_vget(struct mount *mp, ino_t ino, struct  vnode **vpp);
137
138 int     hammer_unload_inode(struct hammer_inode *inode, void *data __unused);
139 int     hammer_unload_volume(struct hammer_volume *volume, void *data __unused);
140 int     hammer_load_volume(struct hammer_mount *hmp, const char *volname);
141 struct hammer_cluster *hammer_load_cluster(struct hammer_mount *hmp,
142                                 struct hammer_volume *volume, int clu_no,
143                                 int *errorp);
144
145 int     hammer_btree_lookup(struct hammer_mount *hmp,
146                                 struct hammer_btree_info *info);
147
148
149 #endif
150