Add an extern for hidirtybuffers.
[dragonfly.git] / sys / vfs / hammer / hammer.h
CommitLineData
8750964d 1/*
1f07f686 2 * Copyright (c) 2007-2008 The DragonFly Project. All rights reserved.
8750964d
MD
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 *
9f5097dc 34 * $DragonFly: src/sys/vfs/hammer/hammer.h,v 1.76 2008/06/09 04:19:10 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
427e5fc6
MD
41#include <sys/param.h>
42#include <sys/types.h>
43#include <sys/kernel.h>
42c7d26b 44#include <sys/conf.h>
427e5fc6 45#include <sys/systm.h>
8750964d
MD
46#include <sys/tree.h>
47#include <sys/malloc.h>
427e5fc6 48#include <sys/mount.h>
513ca7d7 49#include <sys/mountctl.h>
427e5fc6 50#include <sys/vnode.h>
42c7d26b 51#include <sys/proc.h>
e63644f0 52#include <sys/stat.h>
427e5fc6 53#include <sys/globaldata.h>
66325755
MD
54#include <sys/lockf.h>
55#include <sys/buf.h>
8cd0a023 56#include <sys/queue.h>
66325755
MD
57#include <sys/globaldata.h>
58
59#include <sys/buf2.h>
855942b6 60#include <sys/signal2.h>
427e5fc6 61#include "hammer_disk.h"
8750964d 62#include "hammer_mount.h"
7dc57964 63#include "hammer_ioctl.h"
8750964d
MD
64
65#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
66
67MALLOC_DECLARE(M_HAMMER);
68
66325755
MD
69struct hammer_mount;
70
8750964d
MD
71/*
72 * Key structure used for custom RB tree inode lookups. This prototypes
73 * the function hammer_ino_rb_tree_RB_LOOKUP_INFO(root, info).
74 */
75typedef struct hammer_inode_info {
513ca7d7 76 int64_t obj_id; /* (key) object identifier */
8750964d
MD
77 hammer_tid_t obj_asof; /* (key) snapshot transid or 0 */
78} *hammer_inode_info_t;
79
b84de5af
MD
80typedef enum hammer_transaction_type {
81 HAMMER_TRANS_RO,
82 HAMMER_TRANS_STD,
83 HAMMER_TRANS_FLS
84} hammer_transaction_type_t;
85
66325755
MD
86/*
87 * HAMMER Transaction tracking
88 */
89struct hammer_transaction {
b84de5af 90 hammer_transaction_type_t type;
66325755
MD
91 struct hammer_mount *hmp;
92 hammer_tid_t tid;
b84de5af 93 hammer_tid_t time;
2f85fa4d 94 int sync_lock_refs;
a89aec1b 95 struct hammer_volume *rootvol;
66325755
MD
96};
97
8cd0a023
MD
98typedef struct hammer_transaction *hammer_transaction_t;
99
66325755
MD
100/*
101 * HAMMER locks
102 */
427e5fc6 103struct hammer_lock {
0b075555 104 int refs; /* active references delay writes */
0b075555 105 int lockcount; /* lock count for exclusive/shared access */
427e5fc6
MD
106 int wanted;
107 struct thread *locktd;
8750964d
MD
108};
109
427e5fc6
MD
110static __inline int
111hammer_islocked(struct hammer_lock *lock)
112{
8cd0a023 113 return(lock->lockcount != 0);
427e5fc6
MD
114}
115
0b075555
MD
116static __inline int
117hammer_isactive(struct hammer_lock *lock)
118{
119 return(lock->refs != 0);
120}
121
427e5fc6
MD
122static __inline int
123hammer_islastref(struct hammer_lock *lock)
124{
125 return(lock->refs == 1);
126}
c60bb2c5 127
6a37e7e4 128/*
7aa3b8a6 129 * Return if we specifically own the lock exclusively.
6a37e7e4
MD
130 */
131static __inline int
7aa3b8a6 132hammer_lock_excl_owned(struct hammer_lock *lock, thread_t td)
6a37e7e4 133{
7aa3b8a6
MD
134 if (lock->lockcount > 0 && lock->locktd == td)
135 return(1);
136 return(0);
6a37e7e4
MD
137}
138
ec4e8497 139/*
1f07f686 140 * Flush state, used by various structures
ec4e8497 141 */
1f07f686
MD
142typedef enum hammer_inode_state {
143 HAMMER_FST_IDLE,
144 HAMMER_FST_SETUP,
145 HAMMER_FST_FLUSH
146} hammer_inode_state_t;
ec4e8497 147
1f07f686 148TAILQ_HEAD(hammer_record_list, hammer_record);
ec4e8497 149
0729c8c8
MD
150/*
151 * Cache object ids. A fixed number of objid cache structures are
152 * created to reserve object id's for newly created files in multiples
153 * of 100,000, localized to a particular directory, and recycled as
154 * needed. This allows parallel create operations in different
155 * directories to retain fairly localized object ids which in turn
156 * improves reblocking performance and layout.
157 */
158#define OBJID_CACHE_SIZE 128
159#define OBJID_CACHE_BULK 100000
160
161typedef struct hammer_objid_cache {
162 TAILQ_ENTRY(hammer_objid_cache) entry;
163 struct hammer_inode *dip;
164 hammer_tid_t next_tid;
165 int count;
166} *hammer_objid_cache_t;
167
8750964d 168/*
8cd0a023
MD
169 * Structure used to represent an inode in-memory.
170 *
171 * The record and data associated with an inode may be out of sync with
172 * the disk (xDIRTY flags), or not even on the disk at all (ONDISK flag
173 * clear).
174 *
175 * An inode may also hold a cache of unsynchronized records, used for
176 * database and directories only. Unsynchronized regular file data is
177 * stored in the buffer cache.
178 *
179 * NOTE: A file which is created and destroyed within the initial
180 * synchronization period can wind up not doing any disk I/O at all.
181 *
182 * Finally, an inode may cache numerous disk-referencing B-Tree cursors.
8750964d
MD
183 */
184struct hammer_ino_rb_tree;
185struct hammer_inode;
186RB_HEAD(hammer_ino_rb_tree, hammer_inode);
187RB_PROTOTYPEX(hammer_ino_rb_tree, INFO, hammer_inode, rb_node,
8cd0a023
MD
188 hammer_ino_rb_compare, hammer_inode_info_t);
189
190struct hammer_rec_rb_tree;
191struct hammer_record;
192RB_HEAD(hammer_rec_rb_tree, hammer_record);
193RB_PROTOTYPEX(hammer_rec_rb_tree, INFO, hammer_record, rb_node,
0832c9bb 194 hammer_rec_rb_compare, hammer_btree_leaf_elm_t);
8cd0a023
MD
195
196TAILQ_HEAD(hammer_node_list, hammer_node);
8750964d
MD
197
198struct hammer_inode {
1f07f686
MD
199 RB_ENTRY(hammer_inode) rb_node;
200 hammer_inode_state_t flush_state;
201 int flush_group;
059819e3 202 TAILQ_ENTRY(hammer_inode) flush_entry;
1f07f686 203 struct hammer_record_list target_list; /* target of dependant recs */
b84de5af
MD
204 u_int64_t obj_id; /* (key) object identifier */
205 hammer_tid_t obj_asof; /* (key) snapshot or 0 */
206 struct hammer_mount *hmp;
0729c8c8 207 hammer_objid_cache_t objid_cache;
b84de5af
MD
208 int flags;
209 int error; /* flush error */
210 int cursor_ip_refs; /* sanity */
47637bff
MD
211 int rsv_databufs;
212 int rsv_recs;
0832c9bb 213 int idle_wakeup;
b84de5af
MD
214 struct vnode *vp;
215 struct lockf advlock;
216 struct hammer_lock lock; /* sync copy interlock */
b84de5af 217 off_t trunc_off;
11ad5ade 218 struct hammer_btree_leaf_elm ino_leaf; /* in-memory cache */
b84de5af
MD
219 struct hammer_inode_data ino_data; /* in-memory cache */
220 struct hammer_rec_rb_tree rec_tree; /* in-memory cache */
61aeeb33 221 struct hammer_node *cache[2]; /* search initiate cache */
b84de5af
MD
222
223 /*
224 * When a demark is created to synchronize an inode to
225 * disk, certain fields are copied so the front-end VOPs
226 * can continue to run in parallel with the synchronization
227 * occuring in the background.
228 */
229 int sync_flags; /* to-sync flags cache */
230 off_t sync_trunc_off; /* to-sync truncation */
11ad5ade 231 struct hammer_btree_leaf_elm sync_ino_leaf; /* to-sync cache */
b84de5af 232 struct hammer_inode_data sync_ino_data; /* to-sync cache */
8750964d
MD
233};
234
8cd0a023
MD
235typedef struct hammer_inode *hammer_inode_t;
236
66325755
MD
237#define VTOI(vp) ((struct hammer_inode *)(vp)->v_data)
238
8cd0a023 239#define HAMMER_INODE_DDIRTY 0x0001 /* in-memory ino_data is dirty */
e63644f0 240#define HAMMER_INODE_RSV_INODES 0x0002 /* hmp->rsv_inodes bumped */
8cd0a023 241#define HAMMER_INODE_ITIMES 0x0004 /* in-memory mtime/atime modified */
1f07f686 242#define HAMMER_INODE_XDIRTY 0x0008 /* in-memory records */
8cd0a023 243#define HAMMER_INODE_ONDISK 0x0010 /* inode is on-disk (else not yet) */
a89aec1b 244#define HAMMER_INODE_FLUSH 0x0020 /* flush on last ref */
869e8f55 245#define HAMMER_INODE_DELETED 0x0080 /* inode delete (backend) */
76376933 246#define HAMMER_INODE_DELONDISK 0x0100 /* delete synchronized to disk */
d113fda1 247#define HAMMER_INODE_RO 0x0200 /* read-only (because of as-of) */
e8599db1 248#define HAMMER_INODE_VHELD 0x0400 /* vnode held on sync */
0a72edae 249#define HAMMER_INODE_DONDISK 0x0800 /* data records may be on disk */
f3b0f382 250#define HAMMER_INODE_BUFS 0x1000 /* dirty high level bps present */
b84de5af 251#define HAMMER_INODE_REFLUSH 0x2000 /* pipelined flush during flush */
9f5097dc 252#define HAMMER_INODE_RECLAIM 0x4000 /* trying to reclaim */
059819e3 253#define HAMMER_INODE_FLUSHW 0x8000 /* Someone waiting for flush */
8cd0a023 254
b84de5af 255#define HAMMER_INODE_TRUNCATED 0x00010000
869e8f55 256#define HAMMER_INODE_DELETING 0x00020000 /* inode delete request (frontend)*/
4e17f465 257#define HAMMER_INODE_RESIGNAL 0x00040000 /* re-signal on re-flush */
b84de5af 258
11ad5ade
MD
259#define HAMMER_INODE_MODMASK (HAMMER_INODE_DDIRTY| \
260 HAMMER_INODE_XDIRTY|HAMMER_INODE_BUFS| \
1f07f686
MD
261 HAMMER_INODE_ITIMES|HAMMER_INODE_TRUNCATED|\
262 HAMMER_INODE_DELETING)
263
264#define HAMMER_INODE_MODMASK_NOXDIRTY \
265 (HAMMER_INODE_MODMASK & ~HAMMER_INODE_XDIRTY)
0b075555 266
8cd0a023 267#define HAMMER_MAX_INODE_CURSORS 4
66325755 268
f90dde4c 269#define HAMMER_FLUSH_SIGNAL 0x0001
4e17f465 270#define HAMMER_FLUSH_RECURSION 0x0002
f90dde4c 271
9f5097dc
MD
272#define HAMMER_RECLAIM_MIN 100
273#define HAMMER_RECLAIM_FACTOR 4
274
8750964d 275/*
1f07f686
MD
276 * Structure used to represent an unsynchronized record in-memory. These
277 * records typically represent directory entries. Only non-historical
278 * records are kept in-memory.
279 *
280 * Records are organized as a per-inode RB-Tree. If the inode is not
8cd0a023
MD
281 * on disk then neither are any records and the in-memory record tree
282 * represents the entire contents of the inode. If the inode is on disk
283 * then the on-disk B-Tree is scanned in parallel with the in-memory
284 * RB-Tree to synthesize the current state of the file.
285 *
1f07f686
MD
286 * Records are also used to enforce the ordering of directory create/delete
287 * operations. A new inode will not be flushed to disk unless its related
288 * directory entry is also being flushed at the same time. A directory entry
289 * will not be removed unless its related inode is also being removed at the
290 * same time.
8750964d 291 */
1f07f686 292typedef enum hammer_record_type {
e8599db1 293 HAMMER_MEM_RECORD_GENERAL, /* misc record */
930bf163 294 HAMMER_MEM_RECORD_INODE, /* inode record */
1f07f686 295 HAMMER_MEM_RECORD_ADD, /* positive memory cache record */
47637bff
MD
296 HAMMER_MEM_RECORD_DEL, /* negative delete-on-disk record */
297 HAMMER_MEM_RECORD_DATA /* bulk-data record w/on-disk ref */
1f07f686
MD
298} hammer_record_type_t;
299
8cd0a023
MD
300struct hammer_record {
301 RB_ENTRY(hammer_record) rb_node;
1f07f686
MD
302 TAILQ_ENTRY(hammer_record) target_entry;
303 hammer_inode_state_t flush_state;
304 int flush_group;
305 hammer_record_type_t type;
a89aec1b 306 struct hammer_lock lock;
0832c9bb 307 struct hammer_reserve *resv;
8cd0a023 308 struct hammer_inode *ip;
1f07f686 309 struct hammer_inode *target_ip;
11ad5ade 310 struct hammer_btree_leaf_elm leaf;
8cd0a023 311 union hammer_data_ondisk *data;
8cd0a023
MD
312 int flags;
313};
8750964d 314
8cd0a023
MD
315typedef struct hammer_record *hammer_record_t;
316
d36ec43b
MD
317/*
318 * Record flags. Note that FE can only be set by the frontend if the
319 * record has not been interlocked by the backend w/ BE.
320 */
8cd0a023
MD
321#define HAMMER_RECF_ALLOCDATA 0x0001
322#define HAMMER_RECF_ONRBTREE 0x0002
b84de5af 323#define HAMMER_RECF_DELETED_FE 0x0004 /* deleted (frontend) */
d36ec43b 324#define HAMMER_RECF_DELETED_BE 0x0008 /* deleted (backend) */
11ad5ade 325#define HAMMER_RECF_UNUSED0010 0x0010
d36ec43b 326#define HAMMER_RECF_INTERLOCK_BE 0x0020 /* backend interlock */
0832c9bb
MD
327#define HAMMER_RECF_WANTED 0x0040 /* wanted by the frontend */
328#define HAMMER_RECF_WANTIDLE 0x0080 /* wanted when idle */
1f07f686 329#define HAMMER_RECF_CONVERT_DELETE 0x0100 /* special case */
8cd0a023
MD
330
331/*
47197d71 332 * In-memory structures representing on-disk structures.
8cd0a023 333 */
8750964d 334struct hammer_volume;
427e5fc6 335struct hammer_buffer;
8cd0a023 336struct hammer_node;
e8599db1 337struct hammer_undo;
0832c9bb
MD
338struct hammer_reserve;
339
8750964d 340RB_HEAD(hammer_vol_rb_tree, hammer_volume);
427e5fc6 341RB_HEAD(hammer_buf_rb_tree, hammer_buffer);
8cd0a023 342RB_HEAD(hammer_nod_rb_tree, hammer_node);
e8599db1 343RB_HEAD(hammer_und_rb_tree, hammer_undo);
0832c9bb 344RB_HEAD(hammer_res_rb_tree, hammer_reserve);
8750964d
MD
345
346RB_PROTOTYPE2(hammer_vol_rb_tree, hammer_volume, rb_node,
347 hammer_vol_rb_compare, int32_t);
427e5fc6 348RB_PROTOTYPE2(hammer_buf_rb_tree, hammer_buffer, rb_node,
47197d71 349 hammer_buf_rb_compare, hammer_off_t);
8cd0a023 350RB_PROTOTYPE2(hammer_nod_rb_tree, hammer_node, rb_node,
47197d71 351 hammer_nod_rb_compare, hammer_off_t);
e8599db1
MD
352RB_PROTOTYPE2(hammer_und_rb_tree, hammer_undo, rb_node,
353 hammer_und_rb_compare, hammer_off_t);
0832c9bb
MD
354RB_PROTOTYPE2(hammer_res_rb_tree, hammer_reserve, rb_node,
355 hammer_res_rb_compare, hammer_off_t);
8750964d 356
66325755
MD
357/*
358 * IO management - embedded at the head of various in-memory structures
10a5d1ba
MD
359 *
360 * VOLUME - hammer_volume containing meta-data
361 * META_BUFFER - hammer_buffer containing meta-data
362 * DATA_BUFFER - hammer_buffer containing pure-data
363 *
364 * Dirty volume headers and dirty meta-data buffers are locked until the
365 * flusher can sequence them out. Dirty pure-data buffers can be written.
366 * Clean buffers can be passively released.
66325755 367 */
10a5d1ba
MD
368typedef enum hammer_io_type {
369 HAMMER_STRUCTURE_VOLUME,
370 HAMMER_STRUCTURE_META_BUFFER,
371 HAMMER_STRUCTURE_UNDO_BUFFER,
372 HAMMER_STRUCTURE_DATA_BUFFER
373} hammer_io_type_t;
66325755
MD
374
375union hammer_io_structure;
055f5ff8 376struct hammer_io;
66325755
MD
377
378struct worklist {
379 LIST_ENTRY(worklist) node;
380};
381
10a5d1ba
MD
382TAILQ_HEAD(hammer_io_list, hammer_io);
383typedef struct hammer_io_list *hammer_io_list_t;
055f5ff8 384
66325755 385struct hammer_io {
10a5d1ba
MD
386 struct worklist worklist;
387 struct hammer_lock lock;
388 enum hammer_io_type type;
389 struct hammer_mount *hmp;
390 TAILQ_ENTRY(hammer_io) mod_entry; /* list entry if modified */
391 hammer_io_list_t mod_list;
392 struct buf *bp;
393 int64_t offset;
394 int loading; /* loading/unloading interlock */
395 int modify_refs;
396
66325755
MD
397 u_int modified : 1; /* bp's data was modified */
398 u_int released : 1; /* bp released (w/ B_LOCKED set) */
055f5ff8
MD
399 u_int running : 1; /* bp write IO in progress */
400 u_int waiting : 1; /* someone is waiting on us */
b33e2cc0 401 u_int validated : 1; /* ondisk has been validated */
b58c6388 402 u_int waitdep : 1; /* flush waits for dependancies */
51c35492 403 u_int recovered : 1; /* has recovery ref */
9f5097dc 404 u_int waitmod : 1; /* waiting for modify_refs */
66325755
MD
405};
406
8cd0a023
MD
407typedef struct hammer_io *hammer_io_t;
408
66325755 409/*
8cd0a023 410 * In-memory volume representing on-disk buffer
66325755 411 */
8750964d 412struct hammer_volume {
66325755 413 struct hammer_io io;
8750964d 414 RB_ENTRY(hammer_volume) rb_node;
8750964d
MD
415 struct hammer_volume_ondisk *ondisk;
416 int32_t vol_no;
fbc6e32a 417 int64_t nblocks; /* note: special calculation for statfs */
47197d71 418 int64_t buffer_base; /* base offset of buffer 0 */
2f85fa4d
MD
419 hammer_off_t maxbuf_off; /* Maximum buffer offset (zone-2) */
420 hammer_off_t maxraw_off; /* Maximum raw offset for device */
c60bb2c5 421 char *vol_name;
8750964d 422 struct vnode *devvp;
427e5fc6 423 int vol_flags;
8750964d
MD
424};
425
8cd0a023
MD
426typedef struct hammer_volume *hammer_volume_t;
427
66325755 428/*
8cd0a023
MD
429 * In-memory buffer (other then volume, super-cluster, or cluster),
430 * representing an on-disk buffer.
66325755 431 */
427e5fc6 432struct hammer_buffer {
66325755 433 struct hammer_io io;
427e5fc6 434 RB_ENTRY(hammer_buffer) rb_node;
47197d71 435 void *ondisk;
427e5fc6 436 struct hammer_volume *volume;
34d829f7 437 hammer_off_t zoneX_offset;
0832c9bb 438 hammer_off_t zone2_offset;
8cd0a023 439 struct hammer_node_list clist;
66325755
MD
440};
441
8cd0a023
MD
442typedef struct hammer_buffer *hammer_buffer_t;
443
444/*
445 * In-memory B-Tree node, representing an on-disk B-Tree node.
446 *
447 * This is a hang-on structure which is backed by a hammer_buffer,
448 * indexed by a hammer_cluster, and used for fine-grained locking of
449 * B-Tree nodes in order to properly control lock ordering. A hammer_buffer
450 * can contain multiple nodes representing wildly disassociated portions
451 * of the B-Tree so locking cannot be done on a buffer-by-buffer basis.
452 *
453 * This structure uses a cluster-relative index to reduce the number
454 * of layers required to access it, and also because all on-disk B-Tree
455 * references are cluster-relative offsets.
456 */
457struct hammer_node {
458 struct hammer_lock lock; /* node-by-node lock */
459 TAILQ_ENTRY(hammer_node) entry; /* per-buffer linkage */
460 RB_ENTRY(hammer_node) rb_node; /* per-cluster linkage */
47197d71 461 hammer_off_t node_offset; /* full offset spec */
40043e7f 462 struct hammer_mount *hmp;
8cd0a023
MD
463 struct hammer_buffer *buffer; /* backing buffer */
464 hammer_node_ondisk_t ondisk; /* ptr to on-disk structure */
465 struct hammer_node **cache1; /* passive cache(s) */
466 struct hammer_node **cache2;
b3deaf57 467 int flags;
740d8317 468 int loading; /* load interlock */
8cd0a023
MD
469};
470
b3deaf57
MD
471#define HAMMER_NODE_DELETED 0x0001
472#define HAMMER_NODE_FLUSH 0x0002
b3deaf57 473
8cd0a023
MD
474typedef struct hammer_node *hammer_node_t;
475
b33e2cc0
MD
476/*
477 * List of locked nodes.
478 */
479struct hammer_node_locklist {
480 struct hammer_node_locklist *next;
481 hammer_node_t node;
482};
483
484typedef struct hammer_node_locklist *hammer_node_locklist_t;
485
486
8cd0a023
MD
487/*
488 * Common I/O management structure - embedded in in-memory structures
489 * which are backed by filesystem buffers.
490 */
66325755
MD
491union hammer_io_structure {
492 struct hammer_io io;
493 struct hammer_volume volume;
66325755 494 struct hammer_buffer buffer;
8750964d
MD
495};
496
055f5ff8
MD
497typedef union hammer_io_structure *hammer_io_structure_t;
498
bf686dbe
MD
499/*
500 * Allocation holes are recorded for a short period of time in an attempt
501 * to use up the space.
502 */
503
504#define HAMMER_MAX_HOLES 8
505
506struct hammer_hole;
507
508struct hammer_holes {
509 TAILQ_HEAD(, hammer_hole) list;
510 int count;
511};
512
513typedef struct hammer_holes *hammer_holes_t;
514
515struct hammer_hole {
516 TAILQ_ENTRY(hammer_hole) entry;
0832c9bb
MD
517 struct hammer_reserve *resv;
518 hammer_off_t zone_offset;
bf686dbe
MD
519 int bytes;
520};
521
522typedef struct hammer_hole *hammer_hole_t;
427e5fc6 523
0832c9bb
MD
524struct hammer_reserve {
525 RB_ENTRY(hammer_reserve) rb_node;
526 hammer_off_t zone_offset;
527 int refs;
528};
529
530typedef struct hammer_reserve *hammer_reserve_t;
531
8cd0a023
MD
532#include "hammer_cursor.h"
533
e8599db1
MD
534/*
535 * Undo history tracking
536 */
537#define HAMMER_MAX_UNDOS 256
538
539struct hammer_undo {
540 RB_ENTRY(hammer_undo) rb_node;
541 TAILQ_ENTRY(hammer_undo) lru_entry;
542 hammer_off_t offset;
543 int bytes;
544};
545
546typedef struct hammer_undo *hammer_undo_t;
547
8750964d
MD
548/*
549 * Internal hammer mount data structure
550 */
551struct hammer_mount {
552 struct mount *mp;
27ea2398 553 /*struct vnode *rootvp;*/
8750964d
MD
554 struct hammer_ino_rb_tree rb_inos_root;
555 struct hammer_vol_rb_tree rb_vols_root;
40043e7f 556 struct hammer_nod_rb_tree rb_nods_root;
e8599db1 557 struct hammer_und_rb_tree rb_undo_root;
0832c9bb
MD
558 struct hammer_res_rb_tree rb_resv_root;
559 struct hammer_buf_rb_tree rb_bufs_root;
8750964d 560 struct hammer_volume *rootvol;
47197d71
MD
561 struct hammer_base_elm root_btree_beg;
562 struct hammer_base_elm root_btree_end;
d26d0ae9 563 char *zbuf; /* HAMMER_BUFSIZE bytes worth of all-zeros */
9f5097dc 564 int flags;
195c19a1
MD
565 int hflags;
566 int ronly;
567 int nvolumes;
d26d0ae9 568 int volume_iterator;
e63644f0
MD
569 int rsv_inodes; /* reserved space due to dirty inodes */
570 int rsv_databufs; /* reserved space due to dirty buffers */
571 int rsv_databytes; /* reserved space due to record data */
572 int rsv_recs; /* reserved space due to dirty records */
1f07f686
MD
573 int flusher_signal; /* flusher thread sequencer */
574 int flusher_act; /* currently active flush group */
575 int flusher_done; /* set to act when complete */
576 int flusher_next; /* next flush group */
4e17f465 577 int flusher_lock; /* lock sequencing of the next flush */
059819e3 578 int flusher_exiting;
9f5097dc
MD
579 int inode_reclaims; /* inodes pending reclaim by flusher */
580 int count_inodes; /* total number of inodes */
f36a9737 581 hammer_tid_t flusher_tid; /* last flushed transaction id */
059819e3 582 thread_t flusher_td;
855942b6 583 u_int check_interrupt;
8750964d 584 uuid_t fsid;
66325755 585 udev_t fsid_udev;
10a5d1ba
MD
586 struct hammer_io_list volu_list; /* dirty undo buffers */
587 struct hammer_io_list undo_list; /* dirty undo buffers */
588 struct hammer_io_list data_list; /* dirty data buffers */
0832c9bb 589 struct hammer_io_list alt_data_list; /* dirty data buffers */
10a5d1ba
MD
590 struct hammer_io_list meta_list; /* dirty meta bufs */
591 struct hammer_io_list lose_list; /* loose buffers */
592 int locked_dirty_count; /* meta/volu count */
f90dde4c 593 int io_running_count;
0729c8c8 594 int objid_cache_count;
7f7c1f84 595 hammer_tid_t asof;
b84de5af 596 hammer_off_t next_tid;
e63644f0
MD
597 int64_t copy_stat_freebigblocks; /* number of free bigblocks */
598
66325755 599 u_int32_t namekey_iterator;
f03c9cf4 600 hammer_off_t zone_limits[HAMMER_MAX_ZONES];
513ca7d7 601 struct netexport export;
9480ff55 602 struct hammer_lock sync_lock;
c9b9e29d 603 struct hammer_lock free_lock;
40043e7f 604 struct lock blockmap_lock;
0729c8c8 605 struct hammer_blockmap blockmap[HAMMER_MAX_ZONES];
e8599db1
MD
606 struct hammer_holes holes[HAMMER_MAX_ZONES];
607 struct hammer_undo undos[HAMMER_MAX_UNDOS];
608 int undo_alloc;
609 TAILQ_HEAD(, hammer_undo) undo_lru_list;
059819e3 610 TAILQ_HEAD(, hammer_inode) flush_list;
0729c8c8 611 TAILQ_HEAD(, hammer_objid_cache) objid_cache_list;
8750964d
MD
612};
613
8cd0a023 614typedef struct hammer_mount *hammer_mount_t;
8750964d 615
9f5097dc
MD
616#define HAMMER_MOUNT_WAITIMAX 0x0001
617
fbc6e32a
MD
618struct hammer_sync_info {
619 int error;
620 int waitfor;
621};
622
8750964d
MD
623#endif
624
625#if defined(_KERNEL)
626
627extern struct vop_ops hammer_vnode_vops;
7a04d74f
MD
628extern struct vop_ops hammer_spec_vops;
629extern struct vop_ops hammer_fifo_vops;
66325755 630extern struct bio_ops hammer_bioops;
427e5fc6 631
2f85fa4d 632extern int hammer_debug_io;
d5ef456e 633extern int hammer_debug_general;
77062c8a 634extern int hammer_debug_debug;
e8599db1 635extern int hammer_debug_inode;
7d683b0f 636extern int hammer_debug_locks;
b3deaf57 637extern int hammer_debug_btree;
d113fda1 638extern int hammer_debug_tid;
b33e2cc0 639extern int hammer_debug_recover;
46fe7ae1 640extern int hammer_debug_recover_faults;
b3deaf57 641extern int hammer_count_inodes;
9f5097dc 642extern int hammer_count_reclaiming;
b3deaf57
MD
643extern int hammer_count_records;
644extern int hammer_count_record_datas;
645extern int hammer_count_volumes;
b3deaf57
MD
646extern int hammer_count_buffers;
647extern int hammer_count_nodes;
9480ff55 648extern int hammer_count_dirtybufs;
0832c9bb 649extern int hammer_count_reservations;
9480ff55 650extern int hammer_limit_dirtybufs;
47637bff
MD
651extern int hammer_limit_irecs;
652extern int hammer_limit_recs;
1f07f686 653extern int hammer_bio_count;
47637bff
MD
654extern int hammer_stats_btree_iterations;
655extern int hammer_stats_record_iterations;
7d683b0f 656extern int64_t hammer_contention_count;
b3deaf57 657
8750964d
MD
658int hammer_vop_inactive(struct vop_inactive_args *);
659int hammer_vop_reclaim(struct vop_reclaim_args *);
e8599db1 660int hammer_get_vnode(struct hammer_inode *ip, struct vnode **vpp);
36f82b23 661struct hammer_inode *hammer_get_inode(hammer_transaction_t trans,
61aeeb33 662 struct hammer_node **cache,
d113fda1
MD
663 u_int64_t obj_id, hammer_tid_t asof, int flags,
664 int *errorp);
66325755
MD
665void hammer_put_inode(struct hammer_inode *ip);
666void hammer_put_inode_ref(struct hammer_inode *ip);
9f5097dc
MD
667void hammer_inode_waitreclaims(hammer_mount_t hmp);
668void hammer_inode_wakereclaims(hammer_mount_t hmp);
66325755 669
8cd0a023 670int hammer_unload_volume(hammer_volume_t volume, void *data __unused);
51c35492
MD
671int hammer_adjust_volume_mode(hammer_volume_t volume, void *data __unused);
672
a89aec1b 673int hammer_unload_buffer(hammer_buffer_t buffer, void *data __unused);
8cd0a023
MD
674int hammer_install_volume(hammer_mount_t hmp, const char *volname);
675
45a014dc 676int hammer_ip_lookup(hammer_cursor_t cursor);
4e17f465 677int hammer_ip_first(hammer_cursor_t cursor);
a89aec1b 678int hammer_ip_next(hammer_cursor_t cursor);
8cd0a023 679int hammer_ip_resolve_data(hammer_cursor_t cursor);
e63644f0
MD
680int hammer_ip_delete_record(hammer_cursor_t cursor, hammer_inode_t ip,
681 hammer_tid_t tid);
7dc57964 682int hammer_delete_at_cursor(hammer_cursor_t cursor, int64_t *stat_bytes);
b3deaf57 683int hammer_ip_check_directory_empty(hammer_transaction_t trans,
98f7132d 684 hammer_inode_t ip);
fbc6e32a 685int hammer_sync_hmp(hammer_mount_t hmp, int waitfor);
f36a9737
MD
686int hammer_queue_inodes_flusher(hammer_mount_t hmp, int waitfor);
687
fbc6e32a 688
8cd0a023 689hammer_record_t
11ad5ade 690 hammer_alloc_mem_record(hammer_inode_t ip, int data_len);
d36ec43b 691void hammer_flush_record_done(hammer_record_t record, int error);
b84de5af 692void hammer_wait_mem_record(hammer_record_t record);
b3deaf57 693void hammer_rel_mem_record(hammer_record_t record);
b84de5af 694
6a37e7e4 695int hammer_cursor_up(hammer_cursor_t cursor);
f36a9737 696int hammer_cursor_up_locked(hammer_cursor_t cursor);
8cd0a023 697int hammer_cursor_down(hammer_cursor_t cursor);
6a37e7e4
MD
698int hammer_cursor_upgrade(hammer_cursor_t cursor);
699void hammer_cursor_downgrade(hammer_cursor_t cursor);
32c90105
MD
700int hammer_cursor_seek(hammer_cursor_t cursor, hammer_node_t node,
701 int index);
8cd0a023
MD
702void hammer_lock_ex(struct hammer_lock *lock);
703int hammer_lock_ex_try(struct hammer_lock *lock);
704void hammer_lock_sh(struct hammer_lock *lock);
47637bff 705int hammer_lock_sh_try(struct hammer_lock *lock);
6a37e7e4
MD
706int hammer_lock_upgrade(struct hammer_lock *lock);
707void hammer_lock_downgrade(struct hammer_lock *lock);
427e5fc6 708void hammer_unlock(struct hammer_lock *lock);
66325755
MD
709void hammer_ref(struct hammer_lock *lock);
710void hammer_unref(struct hammer_lock *lock);
8cd0a023 711
2f85fa4d
MD
712void hammer_sync_lock_ex(hammer_transaction_t trans);
713void hammer_sync_lock_sh(hammer_transaction_t trans);
47637bff 714int hammer_sync_lock_sh_try(hammer_transaction_t trans);
2f85fa4d
MD
715void hammer_sync_unlock(hammer_transaction_t trans);
716
66325755 717u_int32_t hammer_to_unix_xid(uuid_t *uuid);
8cd0a023
MD
718void hammer_guid_to_uuid(uuid_t *uuid, u_int32_t guid);
719void hammer_to_timespec(hammer_tid_t tid, struct timespec *ts);
720hammer_tid_t hammer_timespec_to_transid(struct timespec *ts);
7f7c1f84 721hammer_tid_t hammer_now_tid(void);
d113fda1 722hammer_tid_t hammer_str_to_tid(const char *str);
0729c8c8
MD
723hammer_tid_t hammer_alloc_objid(hammer_transaction_t trans, hammer_inode_t dip);
724void hammer_clear_objid(hammer_inode_t dip);
725void hammer_destroy_objid_cache(hammer_mount_t hmp);
8cd0a023 726
e8599db1
MD
727int hammer_enter_undo_history(hammer_mount_t hmp, hammer_off_t offset,
728 int bytes);
729void hammer_clear_undo_history(hammer_mount_t hmp);
66325755 730enum vtype hammer_get_vnode_type(u_int8_t obj_type);
6b4f890b 731int hammer_get_dtype(u_int8_t obj_type);
66325755
MD
732u_int8_t hammer_get_obj_type(enum vtype vtype);
733int64_t hammer_directory_namekey(void *name, int len);
e63644f0 734int hammer_nohistory(hammer_inode_t ip);
427e5fc6 735
36f82b23 736int hammer_init_cursor(hammer_transaction_t trans, hammer_cursor_t cursor,
4e17f465
MD
737 struct hammer_node **cache, hammer_inode_t ip);
738int hammer_reinit_cursor(hammer_cursor_t cursor);
739void hammer_normalize_cursor(hammer_cursor_t cursor);
8cd0a023 740void hammer_done_cursor(hammer_cursor_t cursor);
6b4f890b 741void hammer_mem_done(hammer_cursor_t cursor);
8cd0a023
MD
742
743int hammer_btree_lookup(hammer_cursor_t cursor);
d26d0ae9 744int hammer_btree_first(hammer_cursor_t cursor);
32c90105 745int hammer_btree_last(hammer_cursor_t cursor);
8cd0a023
MD
746int hammer_btree_extract(hammer_cursor_t cursor, int flags);
747int hammer_btree_iterate(hammer_cursor_t cursor);
32c90105 748int hammer_btree_iterate_reverse(hammer_cursor_t cursor);
11ad5ade
MD
749int hammer_btree_insert(hammer_cursor_t cursor,
750 hammer_btree_leaf_elm_t elm);
8cd0a023
MD
751int hammer_btree_delete(hammer_cursor_t cursor);
752int hammer_btree_cmp(hammer_base_elm_t key1, hammer_base_elm_t key2);
d26d0ae9 753int hammer_btree_chkts(hammer_tid_t ts, hammer_base_elm_t key);
32c90105
MD
754int hammer_btree_correct_rhb(hammer_cursor_t cursor, hammer_tid_t tid);
755int hammer_btree_correct_lhb(hammer_cursor_t cursor, hammer_tid_t tid);
756
2f85fa4d
MD
757int btree_set_parent(hammer_transaction_t trans, hammer_node_t node,
758 hammer_btree_elm_t elm);
b33e2cc0
MD
759int hammer_btree_lock_children(hammer_cursor_t cursor,
760 struct hammer_node_locklist **locklistp);
2f85fa4d
MD
761void hammer_btree_unlock_children(struct hammer_node_locklist **locklistp);
762
b33e2cc0 763
c0ade690
MD
764void hammer_print_btree_node(hammer_node_ondisk_t ondisk);
765void hammer_print_btree_elm(hammer_btree_elm_t elm, u_int8_t type, int i);
8750964d 766
47197d71
MD
767void *hammer_bread(struct hammer_mount *hmp, hammer_off_t off,
768 int *errorp, struct hammer_buffer **bufferp);
769void *hammer_bnew(struct hammer_mount *hmp, hammer_off_t off,
770 int *errorp, struct hammer_buffer **bufferp);
8cd0a023
MD
771
772hammer_volume_t hammer_get_root_volume(hammer_mount_t hmp, int *errorp);
427e5fc6 773
8cd0a023 774hammer_volume_t hammer_get_volume(hammer_mount_t hmp,
427e5fc6 775 int32_t vol_no, int *errorp);
47197d71
MD
776hammer_buffer_t hammer_get_buffer(hammer_mount_t hmp,
777 hammer_off_t buf_offset, int isnew, int *errorp);
0832c9bb
MD
778void hammer_del_buffers(hammer_mount_t hmp, hammer_off_t base_offset,
779 hammer_off_t zone2_offset, int bytes);
8cd0a023 780
fbc6e32a 781int hammer_ref_volume(hammer_volume_t volume);
8cd0a023
MD
782int hammer_ref_buffer(hammer_buffer_t buffer);
783void hammer_flush_buffer_nodes(hammer_buffer_t buffer);
784
8cd0a023 785void hammer_rel_volume(hammer_volume_t volume, int flush);
8cd0a023
MD
786void hammer_rel_buffer(hammer_buffer_t buffer, int flush);
787
513ca7d7
MD
788int hammer_vfs_export(struct mount *mp, int op,
789 const struct export_args *export);
19619882
MD
790hammer_node_t hammer_get_node(hammer_mount_t hmp, hammer_off_t node_offset,
791 int isnew, int *errorp);
740d8317 792void hammer_ref_node(hammer_node_t node);
055f5ff8
MD
793hammer_node_t hammer_ref_node_safe(struct hammer_mount *hmp,
794 struct hammer_node **cache, int *errorp);
8cd0a023 795void hammer_rel_node(hammer_node_t node);
36f82b23
MD
796void hammer_delete_node(hammer_transaction_t trans,
797 hammer_node_t node);
8cd0a023
MD
798void hammer_cache_node(hammer_node_t node,
799 struct hammer_node **cache);
800void hammer_uncache_node(struct hammer_node **cache);
801void hammer_flush_node(hammer_node_t node);
802
427e5fc6
MD
803void hammer_dup_buffer(struct hammer_buffer **bufferp,
804 struct hammer_buffer *buffer);
36f82b23 805hammer_node_t hammer_alloc_btree(hammer_transaction_t trans, int *errorp);
36f82b23 806void *hammer_alloc_data(hammer_transaction_t trans, int32_t data_len,
bf686dbe
MD
807 hammer_off_t *data_offsetp,
808 struct hammer_buffer **data_bufferp, int *errorp);
809
059819e3
MD
810int hammer_generate_undo(hammer_transaction_t trans, hammer_io_t io,
811 hammer_off_t zone1_offset, void *base, int len);
427e5fc6 812
66325755 813void hammer_put_volume(struct hammer_volume *volume, int flush);
66325755 814void hammer_put_buffer(struct hammer_buffer *buffer, int flush);
427e5fc6 815
36f82b23
MD
816hammer_off_t hammer_freemap_alloc(hammer_transaction_t trans,
817 hammer_off_t owner, int *errorp);
818void hammer_freemap_free(hammer_transaction_t trans, hammer_off_t phys_offset,
c3be93f2 819 hammer_off_t owner, int *errorp);
e63644f0 820int hammer_checkspace(hammer_mount_t hmp);
36f82b23 821hammer_off_t hammer_blockmap_alloc(hammer_transaction_t trans, int zone,
40043e7f 822 int bytes, int *errorp);
0832c9bb
MD
823hammer_reserve_t hammer_blockmap_reserve(hammer_mount_t hmp, int zone,
824 int bytes, hammer_off_t *zone_offp, int *errorp);
825void hammer_blockmap_reserve_complete(hammer_mount_t hmp,
826 hammer_reserve_t resv);
36f82b23
MD
827void hammer_blockmap_free(hammer_transaction_t trans,
828 hammer_off_t bmap_off, int bytes);
bf686dbe
MD
829int hammer_blockmap_getfree(hammer_mount_t hmp, hammer_off_t bmap_off,
830 int *curp, int *errorp);
40043e7f
MD
831hammer_off_t hammer_blockmap_lookup(hammer_mount_t hmp, hammer_off_t bmap_off,
832 int *errorp);
bf686dbe
MD
833hammer_off_t hammer_undo_lookup(hammer_mount_t hmp, hammer_off_t bmap_off,
834 int *errorp);
c9b9e29d 835int64_t hammer_undo_used(hammer_mount_t hmp);
1f07f686
MD
836int64_t hammer_undo_space(hammer_mount_t hmp);
837int64_t hammer_undo_max(hammer_mount_t hmp);
838
8cd0a023
MD
839void hammer_start_transaction(struct hammer_transaction *trans,
840 struct hammer_mount *hmp);
36f82b23
MD
841void hammer_simple_transaction(struct hammer_transaction *trans,
842 struct hammer_mount *hmp);
b84de5af
MD
843void hammer_start_transaction_fls(struct hammer_transaction *trans,
844 struct hammer_mount *hmp);
845void hammer_done_transaction(struct hammer_transaction *trans);
66325755 846
47637bff 847void hammer_modify_inode(hammer_inode_t ip, int flags);
f90dde4c 848void hammer_flush_inode(hammer_inode_t ip, int flags);
b84de5af
MD
849void hammer_flush_inode_done(hammer_inode_t ip);
850void hammer_wait_inode(hammer_inode_t ip);
851
8cd0a023
MD
852int hammer_create_inode(struct hammer_transaction *trans, struct vattr *vap,
853 struct ucred *cred, struct hammer_inode *dip,
854 struct hammer_inode **ipp);
a89aec1b 855void hammer_rel_inode(hammer_inode_t ip, int flush);
51c35492
MD
856int hammer_reload_inode(hammer_inode_t ip, void *arg __unused);
857
1f07f686
MD
858int hammer_sync_inode(hammer_inode_t ip);
859void hammer_test_inode(hammer_inode_t ip);
e8599db1 860void hammer_inode_unloadable_check(hammer_inode_t ip, int getvp);
8cd0a023 861
a89aec1b 862int hammer_ip_add_directory(struct hammer_transaction *trans,
8cd0a023
MD
863 hammer_inode_t dip, struct namecache *ncp,
864 hammer_inode_t nip);
a89aec1b 865int hammer_ip_del_directory(struct hammer_transaction *trans,
8cd0a023
MD
866 hammer_cursor_t cursor, hammer_inode_t dip,
867 hammer_inode_t ip);
47637bff 868hammer_record_t hammer_ip_add_bulk(hammer_inode_t ip, off_t file_offset,
0832c9bb 869 void *data, int bytes, int *errorp);
47637bff 870int hammer_ip_frontend_trunc(struct hammer_inode *ip, off_t file_size);
7a04d74f
MD
871int hammer_ip_add_record(struct hammer_transaction *trans,
872 hammer_record_t record);
4e17f465 873int hammer_ip_delete_range(hammer_cursor_t cursor, hammer_inode_t ip,
47637bff 874 int64_t ran_beg, int64_t ran_end, int truncating);
4e17f465
MD
875int hammer_ip_delete_range_all(hammer_cursor_t cursor, hammer_inode_t ip,
876 int *countp);
877int hammer_ip_sync_data(hammer_cursor_t cursor, hammer_inode_t ip,
878 int64_t offset, void *data, int bytes);
47637bff
MD
879int hammer_dowrite(hammer_cursor_t cursor, hammer_inode_t ip,
880 off_t file_offset, void *data, int bytes);
36f82b23 881int hammer_ip_sync_record(hammer_transaction_t trans, hammer_record_t rec);
4e17f465 882int hammer_ip_sync_record_cursor(hammer_cursor_t cursor, hammer_record_t rec);
66325755 883
7dc57964
MD
884int hammer_ioctl(hammer_inode_t ip, u_long com, caddr_t data, int fflag,
885 struct ucred *cred);
886
10a5d1ba
MD
887void hammer_io_init(hammer_io_t io, hammer_mount_t hmp,
888 enum hammer_io_type type);
2f85fa4d
MD
889int hammer_io_read(struct vnode *devvp, struct hammer_io *io,
890 hammer_off_t limit);
66325755 891int hammer_io_new(struct vnode *devvp, struct hammer_io *io);
47637bff 892void hammer_io_inval(hammer_volume_t volume, hammer_off_t zone2_offset);
09ac686b 893void hammer_io_release(struct hammer_io *io, int flush);
055f5ff8 894void hammer_io_flush(struct hammer_io *io);
61aeeb33 895void hammer_io_clear_modify(struct hammer_io *io);
055f5ff8 896void hammer_io_waitdep(struct hammer_io *io);
47637bff
MD
897int hammer_io_direct_read(hammer_mount_t hmp, hammer_btree_leaf_elm_t leaf,
898 struct bio *bio);
899int hammer_io_direct_write(hammer_mount_t hmp, hammer_btree_leaf_elm_t leaf,
900 struct bio *bio);
9f5097dc
MD
901void hammer_io_write_interlock(hammer_io_t io);
902void hammer_io_done_interlock(hammer_io_t io);
36f82b23
MD
903void hammer_modify_volume(hammer_transaction_t trans, hammer_volume_t volume,
904 void *base, int len);
905void hammer_modify_buffer(hammer_transaction_t trans, hammer_buffer_t buffer,
906 void *base, int len);
10a5d1ba
MD
907void hammer_modify_volume_done(hammer_volume_t volume);
908void hammer_modify_buffer_done(hammer_buffer_t buffer);
0b075555 909
36f82b23
MD
910int hammer_ioc_reblock(hammer_transaction_t trans, hammer_inode_t ip,
911 struct hammer_ioc_reblock *reblock);
11ad5ade
MD
912int hammer_ioc_prune(hammer_transaction_t trans, hammer_inode_t ip,
913 struct hammer_ioc_prune *prune);
bf686dbe
MD
914
915void hammer_init_holes(hammer_mount_t hmp, hammer_holes_t holes);
916void hammer_free_holes(hammer_mount_t hmp, hammer_holes_t holes);
855942b6 917int hammer_signal_check(hammer_mount_t hmp);
bf686dbe 918
059819e3
MD
919void hammer_flusher_create(hammer_mount_t hmp);
920void hammer_flusher_destroy(hammer_mount_t hmp);
921void hammer_flusher_sync(hammer_mount_t hmp);
922void hammer_flusher_async(hammer_mount_t hmp);
923
f90dde4c 924int hammer_recover(hammer_mount_t hmp, hammer_volume_t rootvol);
51c35492
MD
925void hammer_recover_flush_buffers(hammer_mount_t hmp,
926 hammer_volume_t root_volume);
f90dde4c 927
19619882
MD
928void hammer_crc_set_blockmap(hammer_blockmap_t blockmap);
929void hammer_crc_set_volume(hammer_volume_ondisk_t ondisk);
930
931int hammer_crc_test_blockmap(hammer_blockmap_t blockmap);
932int hammer_crc_test_volume(hammer_volume_ondisk_t ondisk);
19619882 933int hammer_crc_test_btree(hammer_node_ondisk_t ondisk);
77062c8a 934void hkprintf(const char *ctl, ...);
19619882 935
055f5ff8 936#endif
427e5fc6 937
8cd0a023 938static __inline void
36f82b23 939hammer_modify_node_noundo(hammer_transaction_t trans, hammer_node_t node)
bf686dbe 940{
36f82b23 941 hammer_modify_buffer(trans, node->buffer, NULL, 0);
bf686dbe
MD
942}
943
944static __inline void
36f82b23 945hammer_modify_node_all(hammer_transaction_t trans, struct hammer_node *node)
8cd0a023 946{
36f82b23
MD
947 hammer_modify_buffer(trans, node->buffer,
948 node->ondisk, sizeof(*node->ondisk));
427e5fc6
MD
949}
950
bf686dbe 951static __inline void
36f82b23
MD
952hammer_modify_node(hammer_transaction_t trans, hammer_node_t node,
953 void *base, int len)
bf686dbe 954{
19619882
MD
955 hammer_crc_t *crcptr;
956
bf686dbe
MD
957 KKASSERT((char *)base >= (char *)node->ondisk &&
958 (char *)base + len <=
959 (char *)node->ondisk + sizeof(*node->ondisk));
36f82b23 960 hammer_modify_buffer(trans, node->buffer, base, len);
19619882
MD
961 crcptr = &node->ondisk->crc;
962 hammer_modify_buffer(trans, node->buffer, crcptr, sizeof(hammer_crc_t));
963 --node->buffer->io.modify_refs; /* only want one ref */
bf686dbe
MD
964}
965
10a5d1ba
MD
966static __inline void
967hammer_modify_node_done(hammer_node_t node)
968{
19619882 969 node->ondisk->crc = crc32(&node->ondisk->crc + 1, HAMMER_BTREE_CRCSIZE);
10a5d1ba
MD
970 hammer_modify_buffer_done(node->buffer);
971}
972
e8599db1
MD
973#define hammer_modify_volume_field(trans, vol, field) \
974 hammer_modify_volume(trans, vol, &(vol)->ondisk->field, \
975 sizeof((vol)->ondisk->field))
976
c9b9e29d
MD
977#define hammer_modify_node_field(trans, node, field) \
978 hammer_modify_node(trans, node, &(node)->ondisk->field, \
979 sizeof((node)->ondisk->field))
980