Fix a path in the comment.
[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 *
af209b0f 34 * $DragonFly: src/sys/vfs/hammer/hammer.h,v 1.80 2008/06/10 22:30:21 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
3897d7e9 272#define HAMMER_RECLAIM_MIN 1000 /* absolute value */
af209b0f
MD
273#define HAMMER_RECLAIM_MID 2000 /* absolute value */
274#define HAMMER_RECLAIM_MAX 3000 /* absolute value */
9f5097dc 275
8750964d 276/*
1f07f686
MD
277 * Structure used to represent an unsynchronized record in-memory. These
278 * records typically represent directory entries. Only non-historical
279 * records are kept in-memory.
280 *
281 * Records are organized as a per-inode RB-Tree. If the inode is not
8cd0a023
MD
282 * on disk then neither are any records and the in-memory record tree
283 * represents the entire contents of the inode. If the inode is on disk
284 * then the on-disk B-Tree is scanned in parallel with the in-memory
285 * RB-Tree to synthesize the current state of the file.
286 *
1f07f686
MD
287 * Records are also used to enforce the ordering of directory create/delete
288 * operations. A new inode will not be flushed to disk unless its related
289 * directory entry is also being flushed at the same time. A directory entry
290 * will not be removed unless its related inode is also being removed at the
291 * same time.
8750964d 292 */
1f07f686 293typedef enum hammer_record_type {
e8599db1 294 HAMMER_MEM_RECORD_GENERAL, /* misc record */
930bf163 295 HAMMER_MEM_RECORD_INODE, /* inode record */
1f07f686 296 HAMMER_MEM_RECORD_ADD, /* positive memory cache record */
47637bff
MD
297 HAMMER_MEM_RECORD_DEL, /* negative delete-on-disk record */
298 HAMMER_MEM_RECORD_DATA /* bulk-data record w/on-disk ref */
1f07f686
MD
299} hammer_record_type_t;
300
8cd0a023
MD
301struct hammer_record {
302 RB_ENTRY(hammer_record) rb_node;
1f07f686
MD
303 TAILQ_ENTRY(hammer_record) target_entry;
304 hammer_inode_state_t flush_state;
305 int flush_group;
306 hammer_record_type_t type;
a89aec1b 307 struct hammer_lock lock;
0832c9bb 308 struct hammer_reserve *resv;
8cd0a023 309 struct hammer_inode *ip;
1f07f686 310 struct hammer_inode *target_ip;
11ad5ade 311 struct hammer_btree_leaf_elm leaf;
8cd0a023 312 union hammer_data_ondisk *data;
8cd0a023
MD
313 int flags;
314};
8750964d 315
8cd0a023
MD
316typedef struct hammer_record *hammer_record_t;
317
d36ec43b
MD
318/*
319 * Record flags. Note that FE can only be set by the frontend if the
320 * record has not been interlocked by the backend w/ BE.
321 */
8cd0a023
MD
322#define HAMMER_RECF_ALLOCDATA 0x0001
323#define HAMMER_RECF_ONRBTREE 0x0002
b84de5af 324#define HAMMER_RECF_DELETED_FE 0x0004 /* deleted (frontend) */
d36ec43b 325#define HAMMER_RECF_DELETED_BE 0x0008 /* deleted (backend) */
11ad5ade 326#define HAMMER_RECF_UNUSED0010 0x0010
d36ec43b 327#define HAMMER_RECF_INTERLOCK_BE 0x0020 /* backend interlock */
0832c9bb
MD
328#define HAMMER_RECF_WANTED 0x0040 /* wanted by the frontend */
329#define HAMMER_RECF_WANTIDLE 0x0080 /* wanted when idle */
1f07f686 330#define HAMMER_RECF_CONVERT_DELETE 0x0100 /* special case */
8cd0a023
MD
331
332/*
47197d71 333 * In-memory structures representing on-disk structures.
8cd0a023 334 */
8750964d 335struct hammer_volume;
427e5fc6 336struct hammer_buffer;
8cd0a023 337struct hammer_node;
e8599db1 338struct hammer_undo;
0832c9bb
MD
339struct hammer_reserve;
340
8750964d 341RB_HEAD(hammer_vol_rb_tree, hammer_volume);
427e5fc6 342RB_HEAD(hammer_buf_rb_tree, hammer_buffer);
8cd0a023 343RB_HEAD(hammer_nod_rb_tree, hammer_node);
e8599db1 344RB_HEAD(hammer_und_rb_tree, hammer_undo);
0832c9bb 345RB_HEAD(hammer_res_rb_tree, hammer_reserve);
8750964d
MD
346
347RB_PROTOTYPE2(hammer_vol_rb_tree, hammer_volume, rb_node,
348 hammer_vol_rb_compare, int32_t);
427e5fc6 349RB_PROTOTYPE2(hammer_buf_rb_tree, hammer_buffer, rb_node,
47197d71 350 hammer_buf_rb_compare, hammer_off_t);
8cd0a023 351RB_PROTOTYPE2(hammer_nod_rb_tree, hammer_node, rb_node,
47197d71 352 hammer_nod_rb_compare, hammer_off_t);
e8599db1
MD
353RB_PROTOTYPE2(hammer_und_rb_tree, hammer_undo, rb_node,
354 hammer_und_rb_compare, hammer_off_t);
0832c9bb
MD
355RB_PROTOTYPE2(hammer_res_rb_tree, hammer_reserve, rb_node,
356 hammer_res_rb_compare, hammer_off_t);
8750964d 357
66325755
MD
358/*
359 * IO management - embedded at the head of various in-memory structures
10a5d1ba
MD
360 *
361 * VOLUME - hammer_volume containing meta-data
362 * META_BUFFER - hammer_buffer containing meta-data
363 * DATA_BUFFER - hammer_buffer containing pure-data
364 *
365 * Dirty volume headers and dirty meta-data buffers are locked until the
366 * flusher can sequence them out. Dirty pure-data buffers can be written.
367 * Clean buffers can be passively released.
66325755 368 */
10a5d1ba
MD
369typedef enum hammer_io_type {
370 HAMMER_STRUCTURE_VOLUME,
371 HAMMER_STRUCTURE_META_BUFFER,
372 HAMMER_STRUCTURE_UNDO_BUFFER,
373 HAMMER_STRUCTURE_DATA_BUFFER
374} hammer_io_type_t;
66325755
MD
375
376union hammer_io_structure;
055f5ff8 377struct hammer_io;
66325755
MD
378
379struct worklist {
380 LIST_ENTRY(worklist) node;
381};
382
10a5d1ba
MD
383TAILQ_HEAD(hammer_io_list, hammer_io);
384typedef struct hammer_io_list *hammer_io_list_t;
055f5ff8 385
66325755 386struct hammer_io {
10a5d1ba
MD
387 struct worklist worklist;
388 struct hammer_lock lock;
389 enum hammer_io_type type;
390 struct hammer_mount *hmp;
391 TAILQ_ENTRY(hammer_io) mod_entry; /* list entry if modified */
392 hammer_io_list_t mod_list;
393 struct buf *bp;
394 int64_t offset;
395 int loading; /* loading/unloading interlock */
396 int modify_refs;
397
66325755
MD
398 u_int modified : 1; /* bp's data was modified */
399 u_int released : 1; /* bp released (w/ B_LOCKED set) */
055f5ff8
MD
400 u_int running : 1; /* bp write IO in progress */
401 u_int waiting : 1; /* someone is waiting on us */
b33e2cc0 402 u_int validated : 1; /* ondisk has been validated */
b58c6388 403 u_int waitdep : 1; /* flush waits for dependancies */
51c35492 404 u_int recovered : 1; /* has recovery ref */
9f5097dc 405 u_int waitmod : 1; /* waiting for modify_refs */
cebe9493 406 u_int reclaim : 1; /* reclaim requested */
66325755
MD
407};
408
8cd0a023
MD
409typedef struct hammer_io *hammer_io_t;
410
af209b0f
MD
411#define HAMMER_CLUSTER_SIZE (64 * 1024)
412#if HAMMER_CLUSTER_SIZE > MAXBSIZE
413#undef HAMMER_CLUSTER_SIZE
414#define HAMMER_CLUSTER_SIZE MAXBSIZE
415#endif
416#define HAMMER_CLUSTER_BUFS (HAMMER_CLUSTER_SIZE / HAMMER_BUFSIZE)
417
66325755 418/*
8cd0a023 419 * In-memory volume representing on-disk buffer
66325755 420 */
8750964d 421struct hammer_volume {
66325755 422 struct hammer_io io;
8750964d 423 RB_ENTRY(hammer_volume) rb_node;
8750964d
MD
424 struct hammer_volume_ondisk *ondisk;
425 int32_t vol_no;
fbc6e32a 426 int64_t nblocks; /* note: special calculation for statfs */
47197d71 427 int64_t buffer_base; /* base offset of buffer 0 */
2f85fa4d
MD
428 hammer_off_t maxbuf_off; /* Maximum buffer offset (zone-2) */
429 hammer_off_t maxraw_off; /* Maximum raw offset for device */
c60bb2c5 430 char *vol_name;
8750964d 431 struct vnode *devvp;
427e5fc6 432 int vol_flags;
8750964d
MD
433};
434
8cd0a023
MD
435typedef struct hammer_volume *hammer_volume_t;
436
66325755 437/*
8cd0a023
MD
438 * In-memory buffer (other then volume, super-cluster, or cluster),
439 * representing an on-disk buffer.
66325755 440 */
427e5fc6 441struct hammer_buffer {
66325755 442 struct hammer_io io;
427e5fc6 443 RB_ENTRY(hammer_buffer) rb_node;
47197d71 444 void *ondisk;
427e5fc6 445 struct hammer_volume *volume;
34d829f7 446 hammer_off_t zoneX_offset;
0832c9bb 447 hammer_off_t zone2_offset;
cebe9493 448 struct hammer_reserve *resv;
8cd0a023 449 struct hammer_node_list clist;
66325755
MD
450};
451
8cd0a023
MD
452typedef struct hammer_buffer *hammer_buffer_t;
453
454/*
455 * In-memory B-Tree node, representing an on-disk B-Tree node.
456 *
457 * This is a hang-on structure which is backed by a hammer_buffer,
458 * indexed by a hammer_cluster, and used for fine-grained locking of
459 * B-Tree nodes in order to properly control lock ordering. A hammer_buffer
460 * can contain multiple nodes representing wildly disassociated portions
461 * of the B-Tree so locking cannot be done on a buffer-by-buffer basis.
462 *
463 * This structure uses a cluster-relative index to reduce the number
464 * of layers required to access it, and also because all on-disk B-Tree
465 * references are cluster-relative offsets.
466 */
467struct hammer_node {
468 struct hammer_lock lock; /* node-by-node lock */
469 TAILQ_ENTRY(hammer_node) entry; /* per-buffer linkage */
470 RB_ENTRY(hammer_node) rb_node; /* per-cluster linkage */
47197d71 471 hammer_off_t node_offset; /* full offset spec */
40043e7f 472 struct hammer_mount *hmp;
8cd0a023
MD
473 struct hammer_buffer *buffer; /* backing buffer */
474 hammer_node_ondisk_t ondisk; /* ptr to on-disk structure */
475 struct hammer_node **cache1; /* passive cache(s) */
476 struct hammer_node **cache2;
b3deaf57 477 int flags;
740d8317 478 int loading; /* load interlock */
8cd0a023
MD
479};
480
b3deaf57
MD
481#define HAMMER_NODE_DELETED 0x0001
482#define HAMMER_NODE_FLUSH 0x0002
b3deaf57 483
8cd0a023
MD
484typedef struct hammer_node *hammer_node_t;
485
b33e2cc0
MD
486/*
487 * List of locked nodes.
488 */
489struct hammer_node_locklist {
490 struct hammer_node_locklist *next;
491 hammer_node_t node;
492};
493
494typedef struct hammer_node_locklist *hammer_node_locklist_t;
495
496
8cd0a023
MD
497/*
498 * Common I/O management structure - embedded in in-memory structures
499 * which are backed by filesystem buffers.
500 */
66325755
MD
501union hammer_io_structure {
502 struct hammer_io io;
503 struct hammer_volume volume;
66325755 504 struct hammer_buffer buffer;
8750964d
MD
505};
506
055f5ff8
MD
507typedef union hammer_io_structure *hammer_io_structure_t;
508
bf686dbe 509/*
cebe9493
MD
510 * Allocation holes are recorded when an allocation does not fit within a
511 * buffer. Later allocations which might fit may then be satisfied from
512 * a recorded hole. The resv reference prevents the big block from being
513 * allocated out of via the normal blockmap mechanism.
514 *
515 * This is strictly a heuristic.
bf686dbe 516 */
bf686dbe
MD
517#define HAMMER_MAX_HOLES 8
518
519struct hammer_hole;
520
521struct hammer_holes {
522 TAILQ_HEAD(, hammer_hole) list;
523 int count;
524};
525
526typedef struct hammer_holes *hammer_holes_t;
527
528struct hammer_hole {
529 TAILQ_ENTRY(hammer_hole) entry;
0832c9bb
MD
530 struct hammer_reserve *resv;
531 hammer_off_t zone_offset;
bf686dbe
MD
532 int bytes;
533};
534
535typedef struct hammer_hole *hammer_hole_t;
427e5fc6 536
cebe9493
MD
537/*
538 * The reserve structure prevents the blockmap from allocating
539 * out of a reserved bigblock. Such reservations are used by
540 * the direct-write mechanism.
541 *
542 * The structure is also used to hold off on reallocations of
543 * big blocks from the freemap until flush dependancies have
544 * been dealt with.
545 */
0832c9bb
MD
546struct hammer_reserve {
547 RB_ENTRY(hammer_reserve) rb_node;
cebe9493
MD
548 TAILQ_ENTRY(hammer_reserve) delay_entry;
549 int flush_group;
0832c9bb 550 int refs;
cebe9493 551 hammer_off_t zone_offset;
0832c9bb
MD
552};
553
554typedef struct hammer_reserve *hammer_reserve_t;
555
8cd0a023
MD
556#include "hammer_cursor.h"
557
e8599db1 558/*
cebe9493
MD
559 * The undo structure tracks recent undos to avoid laying down duplicate
560 * undos within a flush group, saving us a significant amount of overhead.
561 *
562 * This is strictly a heuristic.
e8599db1 563 */
da2da375
MD
564#define HAMMER_MAX_UNDOS 1024
565#define HAMMER_MAX_FLUSHERS 4
e8599db1
MD
566
567struct hammer_undo {
568 RB_ENTRY(hammer_undo) rb_node;
569 TAILQ_ENTRY(hammer_undo) lru_entry;
570 hammer_off_t offset;
571 int bytes;
572};
573
574typedef struct hammer_undo *hammer_undo_t;
575
af209b0f 576struct hammer_flusher_info;
da2da375
MD
577
578struct hammer_flusher {
579 int signal; /* flusher thread sequencer */
580 int act; /* currently active flush group */
581 int done; /* set to act when complete */
582 int next; /* next flush group */
583 int group_lock; /* lock sequencing of the next flush */
584 int exiting; /* request master exit */
585 int count; /* number of slave flushers */
586 int running; /* number of slave flushers running */
587 thread_t td; /* master flusher thread */
588 hammer_tid_t tid; /* last flushed transaction id */
589 int finalize_want; /* serialize finalization */
590 struct hammer_lock finalize_lock; /* serialize finalization */
591 struct hammer_transaction trans; /* shared transaction */
592 struct hammer_flusher_info *info[HAMMER_MAX_FLUSHERS];
593};
594
8750964d
MD
595/*
596 * Internal hammer mount data structure
597 */
598struct hammer_mount {
599 struct mount *mp;
27ea2398 600 /*struct vnode *rootvp;*/
8750964d
MD
601 struct hammer_ino_rb_tree rb_inos_root;
602 struct hammer_vol_rb_tree rb_vols_root;
40043e7f 603 struct hammer_nod_rb_tree rb_nods_root;
e8599db1 604 struct hammer_und_rb_tree rb_undo_root;
0832c9bb
MD
605 struct hammer_res_rb_tree rb_resv_root;
606 struct hammer_buf_rb_tree rb_bufs_root;
8750964d 607 struct hammer_volume *rootvol;
47197d71
MD
608 struct hammer_base_elm root_btree_beg;
609 struct hammer_base_elm root_btree_end;
d26d0ae9 610 char *zbuf; /* HAMMER_BUFSIZE bytes worth of all-zeros */
9f5097dc 611 int flags;
195c19a1
MD
612 int hflags;
613 int ronly;
614 int nvolumes;
d26d0ae9 615 int volume_iterator;
e63644f0
MD
616 int rsv_inodes; /* reserved space due to dirty inodes */
617 int rsv_databufs; /* reserved space due to dirty buffers */
618 int rsv_databytes; /* reserved space due to record data */
619 int rsv_recs; /* reserved space due to dirty records */
da2da375 620
9f5097dc
MD
621 int inode_reclaims; /* inodes pending reclaim by flusher */
622 int count_inodes; /* total number of inodes */
af209b0f 623 int count_iqueued; /* inodes queued to flusher */
da2da375
MD
624
625 struct hammer_flusher flusher;
626
855942b6 627 u_int check_interrupt;
8750964d 628 uuid_t fsid;
66325755 629 udev_t fsid_udev;
10a5d1ba
MD
630 struct hammer_io_list volu_list; /* dirty undo buffers */
631 struct hammer_io_list undo_list; /* dirty undo buffers */
632 struct hammer_io_list data_list; /* dirty data buffers */
0832c9bb 633 struct hammer_io_list alt_data_list; /* dirty data buffers */
10a5d1ba
MD
634 struct hammer_io_list meta_list; /* dirty meta bufs */
635 struct hammer_io_list lose_list; /* loose buffers */
636 int locked_dirty_count; /* meta/volu count */
f90dde4c 637 int io_running_count;
0729c8c8 638 int objid_cache_count;
7f7c1f84 639 hammer_tid_t asof;
b84de5af 640 hammer_off_t next_tid;
e63644f0
MD
641 int64_t copy_stat_freebigblocks; /* number of free bigblocks */
642
66325755 643 u_int32_t namekey_iterator;
f03c9cf4 644 hammer_off_t zone_limits[HAMMER_MAX_ZONES];
513ca7d7 645 struct netexport export;
9480ff55 646 struct hammer_lock sync_lock;
c9b9e29d 647 struct hammer_lock free_lock;
40043e7f 648 struct lock blockmap_lock;
0729c8c8 649 struct hammer_blockmap blockmap[HAMMER_MAX_ZONES];
e8599db1
MD
650 struct hammer_holes holes[HAMMER_MAX_ZONES];
651 struct hammer_undo undos[HAMMER_MAX_UNDOS];
652 int undo_alloc;
653 TAILQ_HEAD(, hammer_undo) undo_lru_list;
059819e3 654 TAILQ_HEAD(, hammer_inode) flush_list;
cebe9493 655 TAILQ_HEAD(, hammer_reserve) delay_list;
0729c8c8 656 TAILQ_HEAD(, hammer_objid_cache) objid_cache_list;
8750964d
MD
657};
658
8cd0a023 659typedef struct hammer_mount *hammer_mount_t;
8750964d 660
9f5097dc
MD
661#define HAMMER_MOUNT_WAITIMAX 0x0001
662
fbc6e32a
MD
663struct hammer_sync_info {
664 int error;
665 int waitfor;
666};
667
8750964d
MD
668#endif
669
670#if defined(_KERNEL)
671
672extern struct vop_ops hammer_vnode_vops;
7a04d74f
MD
673extern struct vop_ops hammer_spec_vops;
674extern struct vop_ops hammer_fifo_vops;
66325755 675extern struct bio_ops hammer_bioops;
427e5fc6 676
2f85fa4d 677extern int hammer_debug_io;
d5ef456e 678extern int hammer_debug_general;
77062c8a 679extern int hammer_debug_debug;
e8599db1 680extern int hammer_debug_inode;
7d683b0f 681extern int hammer_debug_locks;
b3deaf57 682extern int hammer_debug_btree;
d113fda1 683extern int hammer_debug_tid;
b33e2cc0 684extern int hammer_debug_recover;
46fe7ae1 685extern int hammer_debug_recover_faults;
cebe9493 686extern int hammer_debug_write_release;
b3deaf57 687extern int hammer_count_inodes;
af209b0f 688extern int hammer_count_iqueued;
9f5097dc 689extern int hammer_count_reclaiming;
b3deaf57
MD
690extern int hammer_count_records;
691extern int hammer_count_record_datas;
692extern int hammer_count_volumes;
b3deaf57
MD
693extern int hammer_count_buffers;
694extern int hammer_count_nodes;
9480ff55 695extern int hammer_count_dirtybufs;
0832c9bb 696extern int hammer_count_reservations;
9480ff55 697extern int hammer_limit_dirtybufs;
af209b0f 698extern int hammer_limit_iqueued;
47637bff
MD
699extern int hammer_limit_irecs;
700extern int hammer_limit_recs;
1f07f686 701extern int hammer_bio_count;
47637bff
MD
702extern int hammer_stats_btree_iterations;
703extern int hammer_stats_record_iterations;
7d683b0f 704extern int64_t hammer_contention_count;
b3deaf57 705
8750964d
MD
706int hammer_vop_inactive(struct vop_inactive_args *);
707int hammer_vop_reclaim(struct vop_reclaim_args *);
e8599db1 708int hammer_get_vnode(struct hammer_inode *ip, struct vnode **vpp);
36f82b23 709struct hammer_inode *hammer_get_inode(hammer_transaction_t trans,
61aeeb33 710 struct hammer_node **cache,
d113fda1
MD
711 u_int64_t obj_id, hammer_tid_t asof, int flags,
712 int *errorp);
66325755
MD
713void hammer_put_inode(struct hammer_inode *ip);
714void hammer_put_inode_ref(struct hammer_inode *ip);
715
8cd0a023 716int hammer_unload_volume(hammer_volume_t volume, void *data __unused);
51c35492
MD
717int hammer_adjust_volume_mode(hammer_volume_t volume, void *data __unused);
718
a89aec1b 719int hammer_unload_buffer(hammer_buffer_t buffer, void *data __unused);
8cd0a023
MD
720int hammer_install_volume(hammer_mount_t hmp, const char *volname);
721
45a014dc 722int hammer_ip_lookup(hammer_cursor_t cursor);
4e17f465 723int hammer_ip_first(hammer_cursor_t cursor);
a89aec1b 724int hammer_ip_next(hammer_cursor_t cursor);
8cd0a023 725int hammer_ip_resolve_data(hammer_cursor_t cursor);
e63644f0
MD
726int hammer_ip_delete_record(hammer_cursor_t cursor, hammer_inode_t ip,
727 hammer_tid_t tid);
7dc57964 728int hammer_delete_at_cursor(hammer_cursor_t cursor, int64_t *stat_bytes);
b3deaf57 729int hammer_ip_check_directory_empty(hammer_transaction_t trans,
98f7132d 730 hammer_inode_t ip);
fbc6e32a 731int hammer_sync_hmp(hammer_mount_t hmp, int waitfor);
f36a9737
MD
732int hammer_queue_inodes_flusher(hammer_mount_t hmp, int waitfor);
733
fbc6e32a 734
8cd0a023 735hammer_record_t
11ad5ade 736 hammer_alloc_mem_record(hammer_inode_t ip, int data_len);
d36ec43b 737void hammer_flush_record_done(hammer_record_t record, int error);
af209b0f 738void hammer_wait_mem_record_ident(hammer_record_t record, const char *ident);
b3deaf57 739void hammer_rel_mem_record(hammer_record_t record);
b84de5af 740
6a37e7e4 741int hammer_cursor_up(hammer_cursor_t cursor);
f36a9737 742int hammer_cursor_up_locked(hammer_cursor_t cursor);
8cd0a023 743int hammer_cursor_down(hammer_cursor_t cursor);
6a37e7e4
MD
744int hammer_cursor_upgrade(hammer_cursor_t cursor);
745void hammer_cursor_downgrade(hammer_cursor_t cursor);
32c90105
MD
746int hammer_cursor_seek(hammer_cursor_t cursor, hammer_node_t node,
747 int index);
af209b0f 748void hammer_lock_ex_ident(struct hammer_lock *lock, const char *ident);
8cd0a023
MD
749int hammer_lock_ex_try(struct hammer_lock *lock);
750void hammer_lock_sh(struct hammer_lock *lock);
47637bff 751int hammer_lock_sh_try(struct hammer_lock *lock);
6a37e7e4
MD
752int hammer_lock_upgrade(struct hammer_lock *lock);
753void hammer_lock_downgrade(struct hammer_lock *lock);
427e5fc6 754void hammer_unlock(struct hammer_lock *lock);
66325755
MD
755void hammer_ref(struct hammer_lock *lock);
756void hammer_unref(struct hammer_lock *lock);
8cd0a023 757
2f85fa4d
MD
758void hammer_sync_lock_ex(hammer_transaction_t trans);
759void hammer_sync_lock_sh(hammer_transaction_t trans);
47637bff 760int hammer_sync_lock_sh_try(hammer_transaction_t trans);
2f85fa4d
MD
761void hammer_sync_unlock(hammer_transaction_t trans);
762
66325755 763u_int32_t hammer_to_unix_xid(uuid_t *uuid);
8cd0a023
MD
764void hammer_guid_to_uuid(uuid_t *uuid, u_int32_t guid);
765void hammer_to_timespec(hammer_tid_t tid, struct timespec *ts);
766hammer_tid_t hammer_timespec_to_transid(struct timespec *ts);
7f7c1f84 767hammer_tid_t hammer_now_tid(void);
d113fda1 768hammer_tid_t hammer_str_to_tid(const char *str);
0729c8c8
MD
769hammer_tid_t hammer_alloc_objid(hammer_transaction_t trans, hammer_inode_t dip);
770void hammer_clear_objid(hammer_inode_t dip);
771void hammer_destroy_objid_cache(hammer_mount_t hmp);
8cd0a023 772
e8599db1
MD
773int hammer_enter_undo_history(hammer_mount_t hmp, hammer_off_t offset,
774 int bytes);
775void hammer_clear_undo_history(hammer_mount_t hmp);
66325755 776enum vtype hammer_get_vnode_type(u_int8_t obj_type);
6b4f890b 777int hammer_get_dtype(u_int8_t obj_type);
66325755
MD
778u_int8_t hammer_get_obj_type(enum vtype vtype);
779int64_t hammer_directory_namekey(void *name, int len);
e63644f0 780int hammer_nohistory(hammer_inode_t ip);
427e5fc6 781
36f82b23 782int hammer_init_cursor(hammer_transaction_t trans, hammer_cursor_t cursor,
4e17f465
MD
783 struct hammer_node **cache, hammer_inode_t ip);
784int hammer_reinit_cursor(hammer_cursor_t cursor);
785void hammer_normalize_cursor(hammer_cursor_t cursor);
8cd0a023 786void hammer_done_cursor(hammer_cursor_t cursor);
6b4f890b 787void hammer_mem_done(hammer_cursor_t cursor);
8cd0a023
MD
788
789int hammer_btree_lookup(hammer_cursor_t cursor);
d26d0ae9 790int hammer_btree_first(hammer_cursor_t cursor);
32c90105 791int hammer_btree_last(hammer_cursor_t cursor);
8cd0a023
MD
792int hammer_btree_extract(hammer_cursor_t cursor, int flags);
793int hammer_btree_iterate(hammer_cursor_t cursor);
32c90105 794int hammer_btree_iterate_reverse(hammer_cursor_t cursor);
11ad5ade
MD
795int hammer_btree_insert(hammer_cursor_t cursor,
796 hammer_btree_leaf_elm_t elm);
8cd0a023
MD
797int hammer_btree_delete(hammer_cursor_t cursor);
798int hammer_btree_cmp(hammer_base_elm_t key1, hammer_base_elm_t key2);
d26d0ae9 799int hammer_btree_chkts(hammer_tid_t ts, hammer_base_elm_t key);
32c90105
MD
800int hammer_btree_correct_rhb(hammer_cursor_t cursor, hammer_tid_t tid);
801int hammer_btree_correct_lhb(hammer_cursor_t cursor, hammer_tid_t tid);
802
2f85fa4d
MD
803int btree_set_parent(hammer_transaction_t trans, hammer_node_t node,
804 hammer_btree_elm_t elm);
b33e2cc0
MD
805int hammer_btree_lock_children(hammer_cursor_t cursor,
806 struct hammer_node_locklist **locklistp);
2f85fa4d
MD
807void hammer_btree_unlock_children(struct hammer_node_locklist **locklistp);
808
b33e2cc0 809
c0ade690
MD
810void hammer_print_btree_node(hammer_node_ondisk_t ondisk);
811void hammer_print_btree_elm(hammer_btree_elm_t elm, u_int8_t type, int i);
8750964d 812
47197d71
MD
813void *hammer_bread(struct hammer_mount *hmp, hammer_off_t off,
814 int *errorp, struct hammer_buffer **bufferp);
815void *hammer_bnew(struct hammer_mount *hmp, hammer_off_t off,
816 int *errorp, struct hammer_buffer **bufferp);
8cd0a023
MD
817
818hammer_volume_t hammer_get_root_volume(hammer_mount_t hmp, int *errorp);
427e5fc6 819
8cd0a023 820hammer_volume_t hammer_get_volume(hammer_mount_t hmp,
427e5fc6 821 int32_t vol_no, int *errorp);
47197d71
MD
822hammer_buffer_t hammer_get_buffer(hammer_mount_t hmp,
823 hammer_off_t buf_offset, int isnew, int *errorp);
0832c9bb
MD
824void hammer_del_buffers(hammer_mount_t hmp, hammer_off_t base_offset,
825 hammer_off_t zone2_offset, int bytes);
8cd0a023 826
fbc6e32a 827int hammer_ref_volume(hammer_volume_t volume);
8cd0a023
MD
828int hammer_ref_buffer(hammer_buffer_t buffer);
829void hammer_flush_buffer_nodes(hammer_buffer_t buffer);
830
8cd0a023 831void hammer_rel_volume(hammer_volume_t volume, int flush);
8cd0a023
MD
832void hammer_rel_buffer(hammer_buffer_t buffer, int flush);
833
513ca7d7
MD
834int hammer_vfs_export(struct mount *mp, int op,
835 const struct export_args *export);
19619882
MD
836hammer_node_t hammer_get_node(hammer_mount_t hmp, hammer_off_t node_offset,
837 int isnew, int *errorp);
740d8317 838void hammer_ref_node(hammer_node_t node);
055f5ff8
MD
839hammer_node_t hammer_ref_node_safe(struct hammer_mount *hmp,
840 struct hammer_node **cache, int *errorp);
8cd0a023 841void hammer_rel_node(hammer_node_t node);
36f82b23
MD
842void hammer_delete_node(hammer_transaction_t trans,
843 hammer_node_t node);
8cd0a023
MD
844void hammer_cache_node(hammer_node_t node,
845 struct hammer_node **cache);
846void hammer_uncache_node(struct hammer_node **cache);
847void hammer_flush_node(hammer_node_t node);
848
427e5fc6
MD
849void hammer_dup_buffer(struct hammer_buffer **bufferp,
850 struct hammer_buffer *buffer);
36f82b23 851hammer_node_t hammer_alloc_btree(hammer_transaction_t trans, int *errorp);
36f82b23 852void *hammer_alloc_data(hammer_transaction_t trans, int32_t data_len,
bf686dbe
MD
853 hammer_off_t *data_offsetp,
854 struct hammer_buffer **data_bufferp, int *errorp);
855
059819e3
MD
856int hammer_generate_undo(hammer_transaction_t trans, hammer_io_t io,
857 hammer_off_t zone1_offset, void *base, int len);
427e5fc6 858
66325755 859void hammer_put_volume(struct hammer_volume *volume, int flush);
66325755 860void hammer_put_buffer(struct hammer_buffer *buffer, int flush);
427e5fc6 861
36f82b23
MD
862hammer_off_t hammer_freemap_alloc(hammer_transaction_t trans,
863 hammer_off_t owner, int *errorp);
864void hammer_freemap_free(hammer_transaction_t trans, hammer_off_t phys_offset,
c3be93f2 865 hammer_off_t owner, int *errorp);
e63644f0 866int hammer_checkspace(hammer_mount_t hmp);
36f82b23 867hammer_off_t hammer_blockmap_alloc(hammer_transaction_t trans, int zone,
40043e7f 868 int bytes, int *errorp);
0832c9bb
MD
869hammer_reserve_t hammer_blockmap_reserve(hammer_mount_t hmp, int zone,
870 int bytes, hammer_off_t *zone_offp, int *errorp);
871void hammer_blockmap_reserve_complete(hammer_mount_t hmp,
872 hammer_reserve_t resv);
36f82b23
MD
873void hammer_blockmap_free(hammer_transaction_t trans,
874 hammer_off_t bmap_off, int bytes);
bf686dbe
MD
875int hammer_blockmap_getfree(hammer_mount_t hmp, hammer_off_t bmap_off,
876 int *curp, int *errorp);
40043e7f
MD
877hammer_off_t hammer_blockmap_lookup(hammer_mount_t hmp, hammer_off_t bmap_off,
878 int *errorp);
bf686dbe
MD
879hammer_off_t hammer_undo_lookup(hammer_mount_t hmp, hammer_off_t bmap_off,
880 int *errorp);
c9b9e29d 881int64_t hammer_undo_used(hammer_mount_t hmp);
1f07f686
MD
882int64_t hammer_undo_space(hammer_mount_t hmp);
883int64_t hammer_undo_max(hammer_mount_t hmp);
884
8cd0a023
MD
885void hammer_start_transaction(struct hammer_transaction *trans,
886 struct hammer_mount *hmp);
36f82b23
MD
887void hammer_simple_transaction(struct hammer_transaction *trans,
888 struct hammer_mount *hmp);
b84de5af
MD
889void hammer_start_transaction_fls(struct hammer_transaction *trans,
890 struct hammer_mount *hmp);
891void hammer_done_transaction(struct hammer_transaction *trans);
66325755 892
47637bff 893void hammer_modify_inode(hammer_inode_t ip, int flags);
f90dde4c 894void hammer_flush_inode(hammer_inode_t ip, int flags);
b84de5af
MD
895void hammer_flush_inode_done(hammer_inode_t ip);
896void hammer_wait_inode(hammer_inode_t ip);
897
8cd0a023
MD
898int hammer_create_inode(struct hammer_transaction *trans, struct vattr *vap,
899 struct ucred *cred, struct hammer_inode *dip,
900 struct hammer_inode **ipp);
a89aec1b 901void hammer_rel_inode(hammer_inode_t ip, int flush);
51c35492 902int hammer_reload_inode(hammer_inode_t ip, void *arg __unused);
af209b0f 903int hammer_ino_rb_compare(hammer_inode_t ip1, hammer_inode_t ip2);
51c35492 904
1f07f686
MD
905int hammer_sync_inode(hammer_inode_t ip);
906void hammer_test_inode(hammer_inode_t ip);
e8599db1 907void hammer_inode_unloadable_check(hammer_inode_t ip, int getvp);
af209b0f 908void hammer_inode_waitreclaims(hammer_mount_t hmp);
8cd0a023 909
a89aec1b 910int hammer_ip_add_directory(struct hammer_transaction *trans,
8cd0a023
MD
911 hammer_inode_t dip, struct namecache *ncp,
912 hammer_inode_t nip);
a89aec1b 913int hammer_ip_del_directory(struct hammer_transaction *trans,
8cd0a023
MD
914 hammer_cursor_t cursor, hammer_inode_t dip,
915 hammer_inode_t ip);
47637bff 916hammer_record_t hammer_ip_add_bulk(hammer_inode_t ip, off_t file_offset,
0832c9bb 917 void *data, int bytes, int *errorp);
47637bff 918int hammer_ip_frontend_trunc(struct hammer_inode *ip, off_t file_size);
7a04d74f
MD
919int hammer_ip_add_record(struct hammer_transaction *trans,
920 hammer_record_t record);
4e17f465 921int hammer_ip_delete_range(hammer_cursor_t cursor, hammer_inode_t ip,
47637bff 922 int64_t ran_beg, int64_t ran_end, int truncating);
4e17f465
MD
923int hammer_ip_delete_range_all(hammer_cursor_t cursor, hammer_inode_t ip,
924 int *countp);
925int hammer_ip_sync_data(hammer_cursor_t cursor, hammer_inode_t ip,
926 int64_t offset, void *data, int bytes);
36f82b23 927int hammer_ip_sync_record(hammer_transaction_t trans, hammer_record_t rec);
4e17f465 928int hammer_ip_sync_record_cursor(hammer_cursor_t cursor, hammer_record_t rec);
66325755 929
7dc57964
MD
930int hammer_ioctl(hammer_inode_t ip, u_long com, caddr_t data, int fflag,
931 struct ucred *cred);
932
10a5d1ba
MD
933void hammer_io_init(hammer_io_t io, hammer_mount_t hmp,
934 enum hammer_io_type type);
2f85fa4d
MD
935int hammer_io_read(struct vnode *devvp, struct hammer_io *io,
936 hammer_off_t limit);
66325755 937int hammer_io_new(struct vnode *devvp, struct hammer_io *io);
47637bff 938void hammer_io_inval(hammer_volume_t volume, hammer_off_t zone2_offset);
09ac686b 939void hammer_io_release(struct hammer_io *io, int flush);
055f5ff8 940void hammer_io_flush(struct hammer_io *io);
055f5ff8 941void hammer_io_waitdep(struct hammer_io *io);
af209b0f 942void hammer_io_wait_all(hammer_mount_t hmp, const char *ident);
47637bff
MD
943int hammer_io_direct_read(hammer_mount_t hmp, hammer_btree_leaf_elm_t leaf,
944 struct bio *bio);
945int hammer_io_direct_write(hammer_mount_t hmp, hammer_btree_leaf_elm_t leaf,
946 struct bio *bio);
9f5097dc
MD
947void hammer_io_write_interlock(hammer_io_t io);
948void hammer_io_done_interlock(hammer_io_t io);
cebe9493
MD
949void hammer_io_clear_modify(struct hammer_io *io);
950void hammer_io_clear_modlist(struct hammer_io *io);
36f82b23
MD
951void hammer_modify_volume(hammer_transaction_t trans, hammer_volume_t volume,
952 void *base, int len);
953void hammer_modify_buffer(hammer_transaction_t trans, hammer_buffer_t buffer,
954 void *base, int len);
10a5d1ba
MD
955void hammer_modify_volume_done(hammer_volume_t volume);
956void hammer_modify_buffer_done(hammer_buffer_t buffer);
0b075555 957
36f82b23
MD
958int hammer_ioc_reblock(hammer_transaction_t trans, hammer_inode_t ip,
959 struct hammer_ioc_reblock *reblock);
11ad5ade
MD
960int hammer_ioc_prune(hammer_transaction_t trans, hammer_inode_t ip,
961 struct hammer_ioc_prune *prune);
bf686dbe
MD
962
963void hammer_init_holes(hammer_mount_t hmp, hammer_holes_t holes);
964void hammer_free_holes(hammer_mount_t hmp, hammer_holes_t holes);
855942b6 965int hammer_signal_check(hammer_mount_t hmp);
bf686dbe 966
059819e3
MD
967void hammer_flusher_create(hammer_mount_t hmp);
968void hammer_flusher_destroy(hammer_mount_t hmp);
969void hammer_flusher_sync(hammer_mount_t hmp);
970void hammer_flusher_async(hammer_mount_t hmp);
971
f90dde4c 972int hammer_recover(hammer_mount_t hmp, hammer_volume_t rootvol);
51c35492
MD
973void hammer_recover_flush_buffers(hammer_mount_t hmp,
974 hammer_volume_t root_volume);
f90dde4c 975
19619882
MD
976void hammer_crc_set_blockmap(hammer_blockmap_t blockmap);
977void hammer_crc_set_volume(hammer_volume_ondisk_t ondisk);
978
979int hammer_crc_test_blockmap(hammer_blockmap_t blockmap);
980int hammer_crc_test_volume(hammer_volume_ondisk_t ondisk);
19619882 981int hammer_crc_test_btree(hammer_node_ondisk_t ondisk);
77062c8a 982void hkprintf(const char *ctl, ...);
19619882 983
055f5ff8 984#endif
427e5fc6 985
af209b0f
MD
986static __inline void
987hammer_wait_mem_record(hammer_record_t record)
988{
989 hammer_wait_mem_record_ident(record, "hmmwai");
990}
991
992static __inline void
993hammer_lock_ex(struct hammer_lock *lock)
994{
995 hammer_lock_ex_ident(lock, "hmrlck");
996}
997
8cd0a023 998static __inline void
36f82b23 999hammer_modify_node_noundo(hammer_transaction_t trans, hammer_node_t node)
bf686dbe 1000{
36f82b23 1001 hammer_modify_buffer(trans, node->buffer, NULL, 0);
bf686dbe
MD
1002}
1003
1004static __inline void
36f82b23 1005hammer_modify_node_all(hammer_transaction_t trans, struct hammer_node *node)
8cd0a023 1006{
36f82b23
MD
1007 hammer_modify_buffer(trans, node->buffer,
1008 node->ondisk, sizeof(*node->ondisk));
427e5fc6
MD
1009}
1010
bf686dbe 1011static __inline void
36f82b23
MD
1012hammer_modify_node(hammer_transaction_t trans, hammer_node_t node,
1013 void *base, int len)
bf686dbe 1014{
19619882
MD
1015 hammer_crc_t *crcptr;
1016
bf686dbe
MD
1017 KKASSERT((char *)base >= (char *)node->ondisk &&
1018 (char *)base + len <=
1019 (char *)node->ondisk + sizeof(*node->ondisk));
36f82b23 1020 hammer_modify_buffer(trans, node->buffer, base, len);
19619882
MD
1021 crcptr = &node->ondisk->crc;
1022 hammer_modify_buffer(trans, node->buffer, crcptr, sizeof(hammer_crc_t));
1023 --node->buffer->io.modify_refs; /* only want one ref */
bf686dbe
MD
1024}
1025
10a5d1ba
MD
1026static __inline void
1027hammer_modify_node_done(hammer_node_t node)
1028{
19619882 1029 node->ondisk->crc = crc32(&node->ondisk->crc + 1, HAMMER_BTREE_CRCSIZE);
10a5d1ba
MD
1030 hammer_modify_buffer_done(node->buffer);
1031}
1032
e8599db1
MD
1033#define hammer_modify_volume_field(trans, vol, field) \
1034 hammer_modify_volume(trans, vol, &(vol)->ondisk->field, \
1035 sizeof((vol)->ondisk->field))
1036
c9b9e29d
MD
1037#define hammer_modify_node_field(trans, node, field) \
1038 hammer_modify_node(trans, node, &(node)->ondisk->field, \
1039 sizeof((node)->ondisk->field))
1040