Use the orignal dummynet's indentation style
[dragonfly.git] / sys / vfs / hammer / hammer.h
CommitLineData
8750964d
MD
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 *
c60bb2c5 34 * $DragonFly: src/sys/vfs/hammer/hammer.h,v 1.2 2007/10/12 18:57:45 dillon Exp $
8750964d
MD
35 */
36/*
37 * This header file contains structures used internally by the HAMMERFS
c60bb2c5 38 * implementation. See hammer_disk.h for on-disk structures.
8750964d
MD
39 */
40
41#include <sys/tree.h>
42#include <sys/malloc.h>
c60bb2c5
MD
43#include <sys/buf.h>
44#include "hammer_disk.h"
45#include "hammer_alist.h"
8750964d
MD
46#include "hammer_mount.h"
47
48#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
49
50MALLOC_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 */
56typedef 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 */
64struct hammer_btree_info {
65 struct hammer_base_elm key;
c60bb2c5
MD
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 */
8750964d
MD
75};
76
c60bb2c5
MD
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
8750964d
MD
81/*
82 * Structures used to internally represent an inode
83 */
84struct hammer_ino_rb_tree;
85struct hammer_inode;
86RB_HEAD(hammer_ino_rb_tree, hammer_inode);
87RB_PROTOTYPEX(hammer_ino_rb_tree, INFO, hammer_inode, rb_node,
88 hammer_ino_rb_compare, hammer_inode_info_t);
89
90struct 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 */
c60bb2c5
MD
94 struct vnode *vp;
95 struct hammer_inode_record ino_rec;
96 struct hammer_inode_data ino_data;
8750964d
MD
97};
98
99/*
100 * Structures used to internally represent a volume and a cluster
101 */
102
103struct hammer_volume;
104struct hammer_cluster;
105RB_HEAD(hammer_vol_rb_tree, hammer_volume);
106RB_HEAD(hammer_clu_rb_tree, hammer_cluster);
107
108RB_PROTOTYPE2(hammer_vol_rb_tree, hammer_volume, rb_node,
109 hammer_vol_rb_compare, int32_t);
110RB_PROTOTYPE2(hammer_clu_rb_tree, hammer_cluster, rb_node,
111 hammer_clu_rb_compare, int32_t);
112
113struct hammer_volume {
114 RB_ENTRY(hammer_volume) rb_node;
115 struct hammer_clu_rb_tree rb_clus_root;
c60bb2c5 116 struct buf *bp;
8750964d
MD
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 */
c60bb2c5 121 char *vol_name;
8750964d
MD
122 struct vnode *devvp;
123 struct hammer_mount *hmp;
c60bb2c5
MD
124 int lock_count;
125 int ref_count;
126 int flags;
8750964d
MD
127};
128
c60bb2c5
MD
129#define HAMFS_CLUSTER_DIRTY 0x0001
130
8750964d
MD
131struct hammer_cluster {
132 RB_ENTRY(hammer_cluster) rb_node;
c60bb2c5 133 struct buf *bp;
8750964d
MD
134 struct hammer_cluster_ondisk *ondisk;
135 struct hammer_volume *volume;
136 int32_t clu_no;
c60bb2c5
MD
137 int lock_count;
138 int ref_count;
8750964d
MD
139};
140
141/*
142 * Internal hammer mount data structure
143 */
144struct 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
159extern struct vop_ops hammer_vnode_vops;
160int hammer_vop_inactive(struct vop_inactive_args *);
161int hammer_vop_reclaim(struct vop_reclaim_args *);
162int hammer_vfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp);
163
164int hammer_unload_inode(struct hammer_inode *inode, void *data __unused);
165int hammer_unload_volume(struct hammer_volume *volume, void *data __unused);
166int hammer_load_volume(struct hammer_mount *hmp, const char *volname);
c60bb2c5
MD
167struct hammer_cluster *hammer_load_cluster(struct hammer_volume *volume,
168 int clu_no, int *errorp);
8750964d 169
c60bb2c5
MD
170int hammer_btree_lookup(struct hammer_btree_info *info, int flags);
171void hammer_btree_lookup_done(struct hammer_btree_info *info);
8750964d 172
c60bb2c5
MD
173void *hammer_bread(struct hammer_cluster *cluster, int32_t cloff,
174 int *errorp, struct buf **bufp);
8750964d
MD
175
176#endif
177