Merge from vendor branch OPENSSL:
[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.2 2007/10/12 18:57:45 dillon Exp $
35  */
36 /*
37  * This header file contains structures used internally by the HAMMERFS
38  * implementation.  See hammer_disk.h for on-disk structures.
39  */
40
41 #include <sys/tree.h>
42 #include <sys/malloc.h>
43 #include <sys/buf.h>
44 #include "hammer_disk.h"
45 #include "hammer_alist.h"
46 #include "hammer_mount.h"
47
48 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
49
50 MALLOC_DECLARE(M_HAMMER);
51
52 /*
53  * Key structure used for custom RB tree inode lookups.  This prototypes
54  * the function hammer_ino_rb_tree_RB_LOOKUP_INFO(root, info).
55  */
56 typedef struct hammer_inode_info {
57         u_int64_t       obj_id;         /* (key) object identifier */
58         hammer_tid_t    obj_asof;       /* (key) snapshot transid or 0 */
59 } *hammer_inode_info_t;
60
61 /*
62  * Key and caching structure used for HAMMER B-Tree lookups.
63  */
64 struct hammer_btree_info {
65         struct hammer_base_elm key;
66         struct hammer_cluster *cluster;
67         struct buf *bp_node;
68         struct buf *bp2;
69         struct buf *bp3;
70         struct hammer_btree_node *node; /* marker for insertion/deletion */
71         int index;                      /* marker for insertion/deletion */
72         union hammer_btree_elm *elm;    /* marker for insertion/deletion */
73         union hammer_record_ondisk *rec;/* returned record pointer */
74         union hammer_data_ondisk *data; /* returned data pointer */
75 };
76
77 #define HAMMER_BTREE_GET_RECORD         0x0001
78 #define HAMMER_BTREE_GET_DATA           0x0002
79 #define HAMMER_BTREE_CLUSTER_TAG        0x0004  /* stop at the cluster tag */
80
81 /*
82  * Structures used to internally represent an inode
83  */
84 struct hammer_ino_rb_tree;
85 struct hammer_inode;
86 RB_HEAD(hammer_ino_rb_tree, hammer_inode);
87 RB_PROTOTYPEX(hammer_ino_rb_tree, INFO, hammer_inode, rb_node,
88              hammer_ino_rb_compare, hammer_inode_info_t);
89
90 struct hammer_inode {
91         RB_ENTRY(hammer_inode) rb_node;
92         u_int64_t       obj_id;         /* (key) object identifier */
93         hammer_tid_t    obj_asof;       /* (key) snapshot transid or 0 */
94         struct vnode    *vp;
95         struct hammer_inode_record ino_rec;
96         struct hammer_inode_data ino_data;
97 };
98
99 /*
100  * Structures used to internally represent a volume and a cluster
101  */
102
103 struct hammer_volume;
104 struct hammer_cluster;
105 RB_HEAD(hammer_vol_rb_tree, hammer_volume);
106 RB_HEAD(hammer_clu_rb_tree, hammer_cluster);
107
108 RB_PROTOTYPE2(hammer_vol_rb_tree, hammer_volume, rb_node,
109               hammer_vol_rb_compare, int32_t);
110 RB_PROTOTYPE2(hammer_clu_rb_tree, hammer_cluster, rb_node,
111               hammer_clu_rb_compare, int32_t);
112
113 struct hammer_volume {
114         RB_ENTRY(hammer_volume) rb_node;
115         struct hammer_clu_rb_tree rb_clus_root;
116         struct buf *bp;
117         struct hammer_volume_ondisk *ondisk;
118         int32_t vol_no;
119         int32_t vol_clsize;
120         int64_t cluster_base;   /* base offset of cluster 0 */
121         char    *vol_name;
122         struct vnode *devvp;
123         struct hammer_mount *hmp;
124         int     lock_count;
125         int     ref_count;
126         int     flags;
127 };
128
129 #define HAMFS_CLUSTER_DIRTY     0x0001
130
131 struct hammer_cluster {
132         RB_ENTRY(hammer_cluster) rb_node;
133         struct buf *bp;
134         struct hammer_cluster_ondisk *ondisk;
135         struct hammer_volume *volume;
136         int32_t clu_no;
137         int     lock_count;
138         int     ref_count;
139 };
140
141 /*
142  * Internal hammer mount data structure
143  */
144 struct hammer_mount {
145         struct mount *mp;
146         struct vnode *rootvp;
147         struct hammer_ino_rb_tree rb_inos_root;
148         struct hammer_vol_rb_tree rb_vols_root;
149         struct hammer_volume *rootvol;
150         struct hammer_cluster *rootcl;
151         uuid_t  fsid;
152 };
153
154
155 #endif
156
157 #if defined(_KERNEL)
158
159 extern struct vop_ops hammer_vnode_vops;
160 int     hammer_vop_inactive(struct vop_inactive_args *);
161 int     hammer_vop_reclaim(struct vop_reclaim_args *);
162 int     hammer_vfs_vget(struct mount *mp, ino_t ino, struct  vnode **vpp);
163
164 int     hammer_unload_inode(struct hammer_inode *inode, void *data __unused);
165 int     hammer_unload_volume(struct hammer_volume *volume, void *data __unused);
166 int     hammer_load_volume(struct hammer_mount *hmp, const char *volname);
167 struct hammer_cluster *hammer_load_cluster(struct hammer_volume *volume,
168                                            int clu_no, int *errorp);
169
170 int     hammer_btree_lookup(struct hammer_btree_info *info, int flags);
171 void    hammer_btree_lookup_done(struct hammer_btree_info *info);
172
173 void    *hammer_bread(struct hammer_cluster *cluster, int32_t cloff,
174                       int *errorp, struct buf **bufp);
175
176 #endif
177