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/sbin/hammer/hammer_util.h,v 1.7 2008/01/24 02:16:47 dillon Exp $
37 #include <sys/types.h>
39 #include <sys/queue.h>
41 #include <vfs/hammer/hammer_alist.h>
42 #include <vfs/hammer/hammer_disk.h>
46 * Cache management - so the user code can keep its memory use under control
53 TAILQ_HEAD(volume_list
, volume_info
);
56 TAILQ_ENTRY(cache_info
) entry
;
58 struct volume_info
*volume
;
59 struct supercl_info
*supercl
;
60 struct cluster_info
*cluster
;
61 struct buffer_info
*buffer
;
63 enum cache_type
{ ISVOLUME
, ISSUPERCL
, ISCLUSTER
, ISBUFFER
} type
;
64 int refs
; /* structural references */
65 int modified
; /* ondisk modified flag */
66 int delete; /* delete flag - delete on last ref */
70 * These structures are used by newfs_hammer to track the filesystem
71 * buffers it constructs while building the filesystem. No attempt
72 * is made to try to make this efficient.
75 struct cache_info cache
;
76 TAILQ_ENTRY(volume_info
) entry
;
86 struct hammer_alist_live clu_alist
; /* cluster allocator */
87 struct hammer_alist_live buf_alist
; /* buffer head only */
88 struct hammer_volume_ondisk
*ondisk
;
90 TAILQ_HEAD(, cluster_info
) cluster_list
;
91 TAILQ_HEAD(, supercl_info
) supercl_list
;
95 struct cache_info cache
;
96 TAILQ_ENTRY(supercl_info
) entry
;
100 struct volume_info
*volume
;
102 struct hammer_alist_live clu_alist
;
103 struct hammer_alist_live buf_alist
;
104 struct hammer_supercl_ondisk
*ondisk
;
107 struct cluster_info
{
108 struct cache_info cache
;
109 TAILQ_ENTRY(cluster_info
) entry
;
113 struct supercl_info
*supercl
;
114 struct volume_info
*volume
;
116 struct hammer_alist_live alist_master
;
117 struct hammer_alist_live alist_btree
;
118 struct hammer_alist_live alist_record
;
119 struct hammer_alist_live alist_mdata
;
120 struct hammer_cluster_ondisk
*ondisk
;
122 TAILQ_HEAD(, buffer_info
) buffer_list
;
126 struct cache_info cache
;
127 TAILQ_ENTRY(buffer_info
) entry
;
131 struct cluster_info
*cluster
;
132 struct volume_info
*volume
;
134 struct hammer_alist_live alist
;
135 hammer_fsbuf_ondisk_t ondisk
;
138 extern struct hammer_alist_config Buf_alist_config
;
139 extern struct hammer_alist_config Vol_normal_alist_config
;
140 extern struct hammer_alist_config Vol_super_alist_config
;
141 extern struct hammer_alist_config Supercl_alist_config
;
142 extern struct hammer_alist_config Clu_master_alist_config
;
143 extern struct hammer_alist_config Clu_slave_alist_config
;
144 extern uuid_t Hammer_FSType
;
145 extern uuid_t Hammer_FSId
;
146 extern int64_t BootAreaSize
;
147 extern int64_t MemAreaSize
;
148 extern int UsingSuperClusters
;
149 extern int NumVolumes
;
150 extern int RootVolNo
;
151 extern struct volume_list VolList
;
153 uint32_t crc32(const void *buf
, size_t size
);
155 struct volume_info
*setup_volume(int32_t vol_no
, const char *filename
,
156 int isnew
, int oflags
);
157 struct volume_info
*get_volume(int32_t vol_no
);
158 struct supercl_info
*get_supercl(struct volume_info
*vol
, int32_t scl_no
,
159 hammer_alloc_state_t isnew
);
160 struct cluster_info
*get_cluster(struct volume_info
*vol
, int32_t clu_no
,
161 hammer_alloc_state_t isnew
);
162 struct buffer_info
*get_buffer(struct cluster_info
*cl
, int32_t buf_no
,
164 hammer_node_ondisk_t
get_node(struct cluster_info
*cl
, int32_t offset
,
165 struct buffer_info
**bufp
);
167 void init_alist_templates(void);
168 void rel_volume(struct volume_info
*volume
);
169 void rel_supercl(struct supercl_info
*supercl
);
170 void rel_cluster(struct cluster_info
*cluster
);
171 void rel_buffer(struct buffer_info
*buffer
);
173 void *alloc_btree_element(struct cluster_info
*cluster
, int32_t *offp
);
174 void *alloc_data_element(struct cluster_info
*cluster
,
175 int32_t bytes
, int32_t *offp
);
176 void *alloc_record_element(struct cluster_info
*cluster
, int32_t *offp
,
179 int hammer_btree_cmp(hammer_base_elm_t key1
, hammer_base_elm_t key2
);
181 void flush_all_volumes(void);
182 void flush_volume(struct volume_info
*vol
);
183 void flush_supercl(struct supercl_info
*supercl
);
184 void flush_cluster(struct cluster_info
*cl
);
185 void flush_buffer(struct buffer_info
*buf
);
187 void hammer_super_alist_template(struct hammer_alist_config
*conf
);
188 void hammer_buffer_alist_template(struct hammer_alist_config
*conf
);
190 void hammer_cache_add(struct cache_info
*cache
, enum cache_type type
);
191 void hammer_cache_del(struct cache_info
*cache
);
192 void hammer_cache_flush(void);
194 void panic(const char *ctl
, ...);