2 * Copyright (c) 2007 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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
34 * $DragonFly: src/sys/vfs/hammer/hammer.h,v 1.2 2007/10/12 18:57:45 dillon Exp $
37 * This header file contains structures used internally by the HAMMERFS
38 * implementation. See hammer_disk.h for on-disk structures.
42 #include <sys/malloc.h>
44 #include "hammer_disk.h"
45 #include "hammer_alist.h"
46 #include "hammer_mount.h"
48 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
50 MALLOC_DECLARE(M_HAMMER);
53 * Key structure used for custom RB tree inode lookups. This prototypes
54 * the function hammer_ino_rb_tree_RB_LOOKUP_INFO(root, info).
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;
62 * Key and caching structure used for HAMMER B-Tree lookups.
64 struct hammer_btree_info {
65 struct hammer_base_elm key;
66 struct hammer_cluster *cluster;
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 */
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 */
82 * Structures used to internally represent an inode
84 struct hammer_ino_rb_tree;
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);
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 */
95 struct hammer_inode_record ino_rec;
96 struct hammer_inode_data ino_data;
100 * Structures used to internally represent a volume and a cluster
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);
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);
113 struct hammer_volume {
114 RB_ENTRY(hammer_volume) rb_node;
115 struct hammer_clu_rb_tree rb_clus_root;
117 struct hammer_volume_ondisk *ondisk;
120 int64_t cluster_base; /* base offset of cluster 0 */
123 struct hammer_mount *hmp;
129 #define HAMFS_CLUSTER_DIRTY 0x0001
131 struct hammer_cluster {
132 RB_ENTRY(hammer_cluster) rb_node;
134 struct hammer_cluster_ondisk *ondisk;
135 struct hammer_volume *volume;
142 * Internal hammer mount data structure
144 struct hammer_mount {
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;
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);
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);
170 int hammer_btree_lookup(struct hammer_btree_info *info, int flags);
171 void hammer_btree_lookup_done(struct hammer_btree_info *info);
173 void *hammer_bread(struct hammer_cluster *cluster, int32_t cloff,
174 int *errorp, struct buf **bufp);