| Commit | Line | Data |
|---|---|---|
| ed3afcca MD |
1 | /* |
| 2 | * Copyright (c) 2007 The DragonFly Project. All rights reserved. | |
| 84e57c2c | 3 | * |
| ed3afcca MD |
4 | * This code is derived from software contributed to The DragonFly Project |
| 5 | * by Matthew Dillon <dillon@backplane.com> | |
| 84e57c2c | 6 | * |
| ed3afcca MD |
7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions | |
| 9 | * are met: | |
| 84e57c2c | 10 | * |
| ed3afcca MD |
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. | |
| 84e57c2c | 20 | * |
| ed3afcca MD |
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. | |
| 84e57c2c | 33 | * |
| 17dd83bc | 34 | * $DragonFly: src/sbin/hammer/hammer_util.h,v 1.19 2008/07/10 04:44:58 dillon Exp $ |
| ed3afcca MD |
35 | */ |
| 36 | ||
| 37 | #include <sys/types.h> | |
| 61aeeb33 MD |
38 | #include <sys/tree.h> |
| 39 | #include <sys/queue.h> | |
| 40 | ||
| ed3afcca | 41 | #include <vfs/hammer/hammer_disk.h> |
| ed3afcca | 42 | #include <uuid.h> |
| ed3afcca | 43 | |
| 61aeeb33 MD |
44 | /* |
| 45 | * Cache management - so the user code can keep its memory use under control | |
| 46 | */ | |
| 47 | struct volume_info; | |
| ed3afcca MD |
48 | struct buffer_info; |
| 49 | ||
| 61aeeb33 MD |
50 | TAILQ_HEAD(volume_list, volume_info); |
| 51 | ||
| 52 | struct cache_info { | |
| 53 | TAILQ_ENTRY(cache_info) entry; | |
| 54 | union { | |
| 55 | struct volume_info *volume; | |
| 61aeeb33 MD |
56 | struct buffer_info *buffer; |
| 57 | } u; | |
| 47197d71 | 58 | enum cache_type { ISVOLUME, ISBUFFER } type; |
| 61aeeb33 MD |
59 | int refs; /* structural references */ |
| 60 | int modified; /* ondisk modified flag */ | |
| 61 | int delete; /* delete flag - delete on last ref */ | |
| 62 | }; | |
| 63 | ||
| ba7b52c9 MD |
64 | #define HAMMER_BUFLISTS 64 |
| 65 | #define HAMMER_BUFLISTMASK (HAMMER_BUFLISTS - 1) | |
| 66 | ||
| ed3afcca MD |
67 | /* |
| 68 | * These structures are used by newfs_hammer to track the filesystem | |
| 69 | * buffers it constructs while building the filesystem. No attempt | |
| 70 | * is made to try to make this efficient. | |
| 71 | */ | |
| 72 | struct volume_info { | |
| 61aeeb33 MD |
73 | struct cache_info cache; |
| 74 | TAILQ_ENTRY(volume_info) entry; | |
| 75 | int vol_no; | |
| c3be93f2 MD |
76 | hammer_off_t vol_alloc; /* volume-relative offset */ |
| 77 | hammer_off_t vol_free_off; /* zone-2 offset */ | |
| 78 | hammer_off_t vol_free_end; /* zone-2 offset */ | |
| ed3afcca | 79 | |
| 61aeeb33 MD |
80 | char *name; |
| 81 | int fd; | |
| 82 | off_t size; | |
| e0fb398b | 83 | off_t device_offset; |
| 61aeeb33 | 84 | const char *type; |
| ed3afcca | 85 | |
| ed3afcca MD |
86 | struct hammer_volume_ondisk *ondisk; |
| 87 | ||
| ba7b52c9 | 88 | TAILQ_HEAD(, buffer_info) buffer_lists[HAMMER_BUFLISTS]; |
| ed3afcca MD |
89 | }; |
| 90 | ||
| 91 | struct buffer_info { | |
| 61aeeb33 MD |
92 | struct cache_info cache; |
| 93 | TAILQ_ENTRY(buffer_info) entry; | |
| 47197d71 | 94 | hammer_off_t buf_offset; /* full hammer offset spec */ |
| b46b99bf MD |
95 | int64_t raw_offset; /* physical offset */ |
| 96 | int flags; /* origination flags */ | |
| 97 | int use_count; /* read count */ | |
| ed3afcca | 98 | struct volume_info *volume; |
| 47197d71 | 99 | void *ondisk; |
| ed3afcca MD |
100 | }; |
| 101 | ||
| b46b99bf MD |
102 | #define HAMMER_BUFINFO_READAHEAD 0x0001 |
| 103 | ||
| ed3afcca MD |
104 | extern uuid_t Hammer_FSType; |
| 105 | extern uuid_t Hammer_FSId; | |
| 61aeeb33 MD |
106 | extern int64_t BootAreaSize; |
| 107 | extern int64_t MemAreaSize; | |
| 64c21cf3 | 108 | extern int64_t UndoBufferSize; |
| ba7b52c9 | 109 | extern int DebugOpt; |
| ed3afcca | 110 | extern int NumVolumes; |
| d38ab092 | 111 | extern int RootVolNo; |
| 61aeeb33 | 112 | extern struct volume_list VolList; |
| b46b99bf MD |
113 | extern int UseReadBehind; |
| 114 | extern int UseReadAhead; | |
| b9107f58 | 115 | extern int AssertOnFailure; |
| ed3afcca MD |
116 | |
| 117 | uint32_t crc32(const void *buf, size_t size); | |
| 17dd83bc | 118 | uint32_t crc32_ext(const void *buf, size_t size, uint32_t ocrc); |
| ed3afcca | 119 | |
| 61aeeb33 MD |
120 | struct volume_info *setup_volume(int32_t vol_no, const char *filename, |
| 121 | int isnew, int oflags); | |
| ed3afcca | 122 | struct volume_info *get_volume(int32_t vol_no); |
| 74e7e48a | 123 | struct volume_info *test_volume(int32_t vol_no); |
| 47197d71 | 124 | struct buffer_info *get_buffer(hammer_off_t buf_offset, int isnew); |
| 40043e7f MD |
125 | void *get_buffer_data(hammer_off_t buf_offset, struct buffer_info **bufferp, |
| 126 | int isnew); | |
| 47197d71 | 127 | hammer_node_ondisk_t get_node(hammer_off_t node_offset, |
| d38ab092 | 128 | struct buffer_info **bufp); |
| 61aeeb33 | 129 | |
| 61aeeb33 | 130 | void rel_volume(struct volume_info *volume); |
| 61aeeb33 MD |
131 | void rel_buffer(struct buffer_info *buffer); |
| 132 | ||
| f03c9cf4 MD |
133 | hammer_off_t blockmap_lookup(hammer_off_t bmap_off, |
| 134 | struct hammer_blockmap_layer1 *layer1, | |
| 6ed4c886 MD |
135 | struct hammer_blockmap_layer2 *layer2, |
| 136 | int *errorp); | |
| 7e1ba5da | 137 | void format_blockmap(hammer_blockmap_t blockmap, hammer_off_t zone_base); |
| 3f673d5c MD |
138 | void format_undomap(hammer_volume_ondisk_t ondisk); |
| 139 | ||
| 47197d71 | 140 | void *alloc_btree_element(hammer_off_t *offp); |
| 84e57c2c | 141 | void *alloc_data_element(hammer_off_t *offp, int32_t data_len, |
| 11ad5ade MD |
142 | struct buffer_info **data_bufferp); |
| 143 | ||
| 5a19cfc8 | 144 | int hammer_btree_cmp(hammer_base_elm_t key1, hammer_base_elm_t key2); |
| a7fbbf91 MD |
145 | void hammer_key_beg_init(hammer_base_elm_t base); |
| 146 | void hammer_key_end_init(hammer_base_elm_t base); | |
| 147 | int hammer_crc_test_leaf(void *data, hammer_btree_leaf_elm_t leaf); | |
| c3be93f2 MD |
148 | |
| 149 | void format_freemap(struct volume_info *root_vol, hammer_blockmap_t blockmap); | |
| 150 | int64_t initialize_freemap(struct volume_info *vol); | |
| 151 | ||
| ed3afcca MD |
152 | void flush_all_volumes(void); |
| 153 | void flush_volume(struct volume_info *vol); | |
| ed3afcca MD |
154 | void flush_buffer(struct buffer_info *buf); |
| 155 | ||
| 0faa08a1 | 156 | void hammer_cache_set(int bytes); |
| 61aeeb33 MD |
157 | void hammer_cache_add(struct cache_info *cache, enum cache_type type); |
| 158 | void hammer_cache_del(struct cache_info *cache); | |
| b46b99bf | 159 | void hammer_cache_used(struct cache_info *cache); |
| 61aeeb33 MD |
160 | void hammer_cache_flush(void); |
| 161 | ||
| b58f1e66 | 162 | void panic(const char *ctl, ...) __printflike(1, 2); |
| 61aeeb33 | 163 |