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
35 #ifndef HAMMER_UTIL_H_
36 #define HAMMER_UTIL_H_
38 #include <sys/types.h>
42 #include <sys/queue.h>
43 #include <sys/mount.h>
56 #include <vfs/hammer/hammer_disk.h>
57 #include <vfs/hammer/hammer_ioctl.h>
61 * pidfile management - common definitions so code is more robust
64 #define PIDFILE_BUFSIZE 64
65 static const char pidfile_loc[] = "/var/run";
68 * Cache management - so the user code can keep its memory use under control
73 TAILQ_HEAD(volume_list, volume_info);
76 TAILQ_ENTRY(cache_info) entry;
77 struct buffer_info *buffer;
78 int refs; /* structural references */
79 int modified; /* ondisk modified flag */
80 int delete; /* delete flag - delete on last ref */
83 #define HAMMER_BUFLISTS 64
84 #define HAMMER_BUFLISTMASK (HAMMER_BUFLISTS - 1)
87 * These structures are used by newfs_hammer to track the filesystem
88 * buffers it constructs while building the filesystem. No attempt
89 * is made to try to make this efficient.
92 struct cache_info cache; /* not used */
93 TAILQ_ENTRY(volume_info) entry;
97 hammer_off_t vol_free_off; /* zone-2 offset */
98 hammer_off_t vol_free_end; /* zone-2 offset */
106 struct hammer_volume_ondisk *ondisk;
108 TAILQ_HEAD(, buffer_info) buffer_lists[HAMMER_BUFLISTS];
112 struct cache_info cache;
113 TAILQ_ENTRY(buffer_info) entry;
114 hammer_off_t buf_offset; /* full hammer offset spec */
115 int64_t raw_offset; /* physical offset */
116 int flags; /* origination flags */
117 int use_count; /* read count */
118 struct volume_info *volume;
123 struct softprune *next;
126 struct hammer_ioc_prune prune;
132 * Data structure for zone statistics.
135 int zone; /* zone index, not used */
136 hammer_off_t blocks; /* number of big-blocks */
137 hammer_off_t items; /* number of items */
138 hammer_off_t used; /* bytes used */
141 extern uuid_t Hammer_FSType;
142 extern uuid_t Hammer_FSId;
144 extern const char *ScoreBoardFile;
145 extern const char *RestrictTarget;
146 extern struct volume_list VolList;
147 extern int UseReadBehind;
148 extern int UseReadAhead;
149 extern int AssertOnFailure;
151 uint32_t crc32(const void *buf, size_t size);
152 uint32_t crc32_ext(const void *buf, size_t size, uint32_t ocrc);
154 struct volume_info *init_volume(int32_t vol_no, const char *filename,
156 struct volume_info *load_volume(const char *filename, int oflags);
157 void check_volume(struct volume_info *vol);
158 struct volume_info *get_volume(int32_t vol_no);
159 struct volume_info *get_root_volume(void);
160 struct buffer_info *get_buffer(hammer_off_t buf_offset, int isnew);
161 void *get_buffer_data(hammer_off_t buf_offset, struct buffer_info **bufferp,
163 hammer_node_ondisk_t get_node(hammer_off_t node_offset,
164 struct buffer_info **bufp);
166 void rel_volume(struct volume_info *volume);
167 void rel_buffer(struct buffer_info *buffer);
169 hammer_off_t alloc_bigblock(struct volume_info *volume, int zone);
170 void *alloc_blockmap(int zone, int bytes, hammer_off_t *result_offp,
171 struct buffer_info **bufferp);
172 hammer_off_t blockmap_lookup(hammer_off_t bmap_off,
173 struct hammer_blockmap_layer1 *layer1,
174 struct hammer_blockmap_layer2 *layer2,
176 void format_undomap(struct volume_info *root_vol, int64_t *undo_buffer_size);
178 void *alloc_btree_element(hammer_off_t *offp,
179 struct buffer_info **data_bufferp);
180 void *alloc_meta_element(hammer_off_t *offp, int32_t data_len,
181 struct buffer_info **data_bufferp);
182 void *alloc_data_element(hammer_off_t *offp, int32_t data_len,
183 struct buffer_info **data_bufferp);
185 int hammer_btree_cmp(hammer_base_elm_t key1, hammer_base_elm_t key2);
186 void hammer_key_beg_init(hammer_base_elm_t base);
187 void hammer_key_end_init(hammer_base_elm_t base);
188 int hammer_crc_test_leaf(void *data, hammer_btree_leaf_elm_t leaf);
190 void format_blockmap(struct volume_info *vol, int zone, hammer_off_t offset);
191 void format_freemap(struct volume_info *root_vol);
192 int64_t initialize_freemap(struct volume_info *vol);
193 int64_t count_freemap(struct volume_info *vol);
195 void flush_all_volumes(void);
196 void flush_volume(struct volume_info *vol);
197 void flush_buffer(struct buffer_info *buf);
199 int64_t init_boot_area_size(int64_t value, off_t avg_vol_size);
200 int64_t init_mem_area_size(int64_t value, off_t avg_vol_size);
202 void hammer_cache_set(int bytes);
203 void hammer_cache_add(struct cache_info *cache);
204 void hammer_cache_del(struct cache_info *cache);
205 void hammer_cache_used(struct cache_info *cache);
206 void hammer_cache_flush(void);
208 void score_printf(size_t i, size_t w, const char *ctl, ...) __printflike(3, 4);
210 struct zone_stat *hammer_init_zone_stat(void);
211 struct zone_stat *hammer_init_zone_stat_bits(void);
212 void hammer_cleanup_zone_stat(struct zone_stat *stats);
213 void hammer_add_zone_stat(struct zone_stat *stats, hammer_off_t offset,
215 void hammer_add_zone_stat_layer2(struct zone_stat *stats,
216 struct hammer_blockmap_layer2 *layer2);
217 void hammer_print_zone_stat(const struct zone_stat *stats);
219 #endif /* !HAMMER_UTIL_H_ */