HAMMER 38B/Many: Undo/Synchronization and crash recovery
[dragonfly.git] / sys / vfs / hammer / hammer.h
CommitLineData
8750964d
MD
1/*
2 * Copyright (c) 2007 The DragonFly Project. All rights reserved.
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 *
b84de5af 34 * $DragonFly: src/sys/vfs/hammer/hammer.h,v 1.48 2008/04/24 21:20:33 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>
427e5fc6 52#include <sys/globaldata.h>
66325755
MD
53#include <sys/lockf.h>
54#include <sys/buf.h>
8cd0a023 55#include <sys/queue.h>
66325755
MD
56#include <sys/globaldata.h>
57
58#include <sys/buf2.h>
855942b6 59#include <sys/signal2.h>
427e5fc6 60#include "hammer_disk.h"
8750964d 61#include "hammer_mount.h"
7dc57964 62#include "hammer_ioctl.h"
8750964d
MD
63
64#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
65
66MALLOC_DECLARE(M_HAMMER);
67
66325755
MD
68struct hammer_mount;
69
8750964d
MD
70/*
71 * Key structure used for custom RB tree inode lookups. This prototypes
72 * the function hammer_ino_rb_tree_RB_LOOKUP_INFO(root, info).
73 */
74typedef struct hammer_inode_info {
513ca7d7 75 int64_t obj_id; /* (key) object identifier */
8750964d
MD
76 hammer_tid_t obj_asof; /* (key) snapshot transid or 0 */
77} *hammer_inode_info_t;
78
b84de5af
MD
79typedef enum hammer_transaction_type {
80 HAMMER_TRANS_RO,
81 HAMMER_TRANS_STD,
82 HAMMER_TRANS_FLS
83} hammer_transaction_type_t;
84
66325755
MD
85/*
86 * HAMMER Transaction tracking
87 */
88struct hammer_transaction {
b84de5af 89 hammer_transaction_type_t type;
66325755
MD
90 struct hammer_mount *hmp;
91 hammer_tid_t tid;
b84de5af 92 hammer_tid_t time;
a89aec1b 93 struct hammer_volume *rootvol;
46fe7ae1 94/* TAILQ_HEAD(, hammer_io) recycle_list;*/
66325755
MD
95};
96
8cd0a023
MD
97typedef struct hammer_transaction *hammer_transaction_t;
98
66325755
MD
99/*
100 * HAMMER locks
101 */
427e5fc6 102struct hammer_lock {
0b075555 103 int refs; /* active references delay writes */
0b075555 104 int lockcount; /* lock count for exclusive/shared access */
427e5fc6
MD
105 int wanted;
106 struct thread *locktd;
8750964d
MD
107};
108
427e5fc6
MD
109static __inline int
110hammer_islocked(struct hammer_lock *lock)
111{
8cd0a023 112 return(lock->lockcount != 0);
427e5fc6
MD
113}
114
0b075555
MD
115static __inline int
116hammer_isactive(struct hammer_lock *lock)
117{
118 return(lock->refs != 0);
119}
120
427e5fc6
MD
121static __inline int
122hammer_islastref(struct hammer_lock *lock)
123{
124 return(lock->refs == 1);
125}
c60bb2c5 126
6a37e7e4 127/*
7aa3b8a6 128 * Return if we specifically own the lock exclusively.
6a37e7e4
MD
129 */
130static __inline int
7aa3b8a6 131hammer_lock_excl_owned(struct hammer_lock *lock, thread_t td)
6a37e7e4 132{
7aa3b8a6
MD
133 if (lock->lockcount > 0 && lock->locktd == td)
134 return(1);
135 return(0);
6a37e7e4
MD
136}
137
8750964d 138/*
8cd0a023
MD
139 * Structure used to represent an inode in-memory.
140 *
141 * The record and data associated with an inode may be out of sync with
142 * the disk (xDIRTY flags), or not even on the disk at all (ONDISK flag
143 * clear).
144 *
145 * An inode may also hold a cache of unsynchronized records, used for
146 * database and directories only. Unsynchronized regular file data is
147 * stored in the buffer cache.
148 *
149 * NOTE: A file which is created and destroyed within the initial
150 * synchronization period can wind up not doing any disk I/O at all.
151 *
152 * Finally, an inode may cache numerous disk-referencing B-Tree cursors.
8750964d
MD
153 */
154struct hammer_ino_rb_tree;
155struct hammer_inode;
156RB_HEAD(hammer_ino_rb_tree, hammer_inode);
157RB_PROTOTYPEX(hammer_ino_rb_tree, INFO, hammer_inode, rb_node,
8cd0a023
MD
158 hammer_ino_rb_compare, hammer_inode_info_t);
159
160struct hammer_rec_rb_tree;
161struct hammer_record;
162RB_HEAD(hammer_rec_rb_tree, hammer_record);
163RB_PROTOTYPEX(hammer_rec_rb_tree, INFO, hammer_record, rb_node,
164 hammer_rec_rb_compare, hammer_base_elm_t);
165
166TAILQ_HEAD(hammer_node_list, hammer_node);
8750964d 167
b84de5af
MD
168typedef enum hammer_inode_state {
169 HAMMER_FST_IDLE,
170 HAMMER_FST_SETUP,
171 HAMMER_FST_FLUSH
172} hammer_inode_state_t;
173
8750964d
MD
174struct hammer_inode {
175 RB_ENTRY(hammer_inode) rb_node;
b84de5af 176 hammer_inode_state_t flush_state;
059819e3 177 TAILQ_ENTRY(hammer_inode) flush_entry;
b84de5af
MD
178 u_int64_t obj_id; /* (key) object identifier */
179 hammer_tid_t obj_asof; /* (key) snapshot or 0 */
180 struct hammer_mount *hmp;
181 int flags;
182 int error; /* flush error */
183 int cursor_ip_refs; /* sanity */
184 struct vnode *vp;
185 struct lockf advlock;
186 struct hammer_lock lock; /* sync copy interlock */
187 TAILQ_HEAD(, bio) bio_list; /* BIOs to flush out */
188 TAILQ_HEAD(, bio) bio_alt_list; /* BIOs to flush out */
189 off_t trunc_off;
190 struct hammer_inode_record ino_rec; /* in-memory cache */
191 struct hammer_inode_data ino_data; /* in-memory cache */
192 struct hammer_rec_rb_tree rec_tree; /* in-memory cache */
61aeeb33 193 struct hammer_node *cache[2]; /* search initiate cache */
b84de5af
MD
194
195 /*
196 * When a demark is created to synchronize an inode to
197 * disk, certain fields are copied so the front-end VOPs
198 * can continue to run in parallel with the synchronization
199 * occuring in the background.
200 */
201 int sync_flags; /* to-sync flags cache */
202 off_t sync_trunc_off; /* to-sync truncation */
203 struct hammer_inode_record sync_ino_rec;/* to-sync cache */
204 struct hammer_inode_data sync_ino_data; /* to-sync cache */
8750964d
MD
205};
206
8cd0a023
MD
207typedef struct hammer_inode *hammer_inode_t;
208
66325755
MD
209#define VTOI(vp) ((struct hammer_inode *)(vp)->v_data)
210
8cd0a023
MD
211#define HAMMER_INODE_DDIRTY 0x0001 /* in-memory ino_data is dirty */
212#define HAMMER_INODE_RDIRTY 0x0002 /* in-memory ino_rec is dirty */
213#define HAMMER_INODE_ITIMES 0x0004 /* in-memory mtime/atime modified */
059819e3 214#define HAMMER_INODE_XDIRTY 0x0008 /* in-memory records/flsbufs present */
8cd0a023 215#define HAMMER_INODE_ONDISK 0x0010 /* inode is on-disk (else not yet) */
a89aec1b 216#define HAMMER_INODE_FLUSH 0x0020 /* flush on last ref */
c0ade690 217#define HAMMER_INODE_DELETED 0x0080 /* inode ready for deletion */
76376933 218#define HAMMER_INODE_DELONDISK 0x0100 /* delete synchronized to disk */
d113fda1
MD
219#define HAMMER_INODE_RO 0x0200 /* read-only (because of as-of) */
220#define HAMMER_INODE_GONE 0x0400 /* delete flushed out */
0a72edae 221#define HAMMER_INODE_DONDISK 0x0800 /* data records may be on disk */
f3b0f382 222#define HAMMER_INODE_BUFS 0x1000 /* dirty high level bps present */
b84de5af
MD
223#define HAMMER_INODE_REFLUSH 0x2000 /* pipelined flush during flush */
224#define HAMMER_INODE_UNUSED4000 0x4000
059819e3 225#define HAMMER_INODE_FLUSHW 0x8000 /* Someone waiting for flush */
8cd0a023 226
b84de5af
MD
227#define HAMMER_INODE_TRUNCATED 0x00010000
228
0b075555 229#define HAMMER_INODE_MODMASK (HAMMER_INODE_DDIRTY|HAMMER_INODE_RDIRTY| \
f3b0f382 230 HAMMER_INODE_XDIRTY|HAMMER_INODE_BUFS| \
b84de5af 231 HAMMER_INODE_ITIMES|HAMMER_INODE_TRUNCATED)
0b075555 232
8cd0a023 233#define HAMMER_MAX_INODE_CURSORS 4
66325755 234
8750964d 235/*
8cd0a023
MD
236 * Structure used to represent an unsynchronized record in-memory. This
237 * structure is orgranized in a per-inode RB-tree. If the inode is not
238 * on disk then neither are any records and the in-memory record tree
239 * represents the entire contents of the inode. If the inode is on disk
240 * then the on-disk B-Tree is scanned in parallel with the in-memory
241 * RB-Tree to synthesize the current state of the file.
242 *
243 * Only current (delete_tid == 0) unsynchronized records are kept in-memory.
b33e2cc0
MD
244 *
245 * blocked is the count of the number of cursors (ip_first/ip_next) blocked
246 * on the record waiting for a synchronization to complete.
8750964d 247 */
8cd0a023
MD
248struct hammer_record {
249 RB_ENTRY(hammer_record) rb_node;
b84de5af 250 hammer_inode_state_t state;
a89aec1b 251 struct hammer_lock lock;
8cd0a023
MD
252 struct hammer_inode *ip;
253 union hammer_record_ondisk rec;
254 union hammer_data_ondisk *data;
8cd0a023
MD
255 int flags;
256};
8750964d 257
8cd0a023
MD
258typedef struct hammer_record *hammer_record_t;
259
260#define HAMMER_RECF_ALLOCDATA 0x0001
261#define HAMMER_RECF_ONRBTREE 0x0002
b84de5af 262#define HAMMER_RECF_DELETED_FE 0x0004 /* deleted (frontend) */
40043e7f 263#define HAMMER_RECF_INBAND 0x0008
b84de5af 264#define HAMMER_RECF_DELETED_BE 0x0010 /* deleted (backend) */
b33e2cc0 265#define HAMMER_RECF_WANTED 0x0020
b84de5af 266#define HAMMER_RECF_DELETE_ONDISK 0x0040
8cd0a023
MD
267
268/*
47197d71 269 * In-memory structures representing on-disk structures.
8cd0a023 270 */
8750964d 271struct hammer_volume;
427e5fc6 272struct hammer_buffer;
8cd0a023 273struct hammer_node;
8750964d 274RB_HEAD(hammer_vol_rb_tree, hammer_volume);
427e5fc6 275RB_HEAD(hammer_buf_rb_tree, hammer_buffer);
8cd0a023 276RB_HEAD(hammer_nod_rb_tree, hammer_node);
8750964d
MD
277
278RB_PROTOTYPE2(hammer_vol_rb_tree, hammer_volume, rb_node,
279 hammer_vol_rb_compare, int32_t);
427e5fc6 280RB_PROTOTYPE2(hammer_buf_rb_tree, hammer_buffer, rb_node,
47197d71 281 hammer_buf_rb_compare, hammer_off_t);
8cd0a023 282RB_PROTOTYPE2(hammer_nod_rb_tree, hammer_node, rb_node,
47197d71 283 hammer_nod_rb_compare, hammer_off_t);
8750964d 284
66325755
MD
285/*
286 * IO management - embedded at the head of various in-memory structures
287 */
288enum hammer_io_type { HAMMER_STRUCTURE_VOLUME,
66325755
MD
289 HAMMER_STRUCTURE_BUFFER };
290
291union hammer_io_structure;
055f5ff8 292struct hammer_io;
66325755
MD
293
294struct worklist {
295 LIST_ENTRY(worklist) node;
296};
297
b58c6388 298/*TAILQ_HEAD(hammer_dep_list, hammer_dep);*/
055f5ff8 299
66325755
MD
300struct hammer_io {
301 struct worklist worklist;
302 struct hammer_lock lock;
303 enum hammer_io_type type;
304 struct buf *bp;
305 int64_t offset;
b58c6388 306 int loading; /* loading/unloading interlock */
66325755
MD
307 u_int modified : 1; /* bp's data was modified */
308 u_int released : 1; /* bp released (w/ B_LOCKED set) */
055f5ff8
MD
309 u_int running : 1; /* bp write IO in progress */
310 u_int waiting : 1; /* someone is waiting on us */
b33e2cc0 311 u_int validated : 1; /* ondisk has been validated */
b58c6388
MD
312 u_int flush : 1; /* flush on last release */
313 u_int waitdep : 1; /* flush waits for dependancies */
66325755
MD
314};
315
8cd0a023
MD
316typedef struct hammer_io *hammer_io_t;
317
66325755 318/*
8cd0a023 319 * In-memory volume representing on-disk buffer
66325755 320 */
8750964d 321struct hammer_volume {
66325755 322 struct hammer_io io;
8750964d 323 RB_ENTRY(hammer_volume) rb_node;
47197d71 324 struct hammer_buf_rb_tree rb_bufs_root;
8750964d
MD
325 struct hammer_volume_ondisk *ondisk;
326 int32_t vol_no;
fbc6e32a 327 int64_t nblocks; /* note: special calculation for statfs */
47197d71
MD
328 int64_t buffer_base; /* base offset of buffer 0 */
329 hammer_off_t maxbuf_off; /* Maximum buffer offset */
c60bb2c5 330 char *vol_name;
8750964d
MD
331 struct vnode *devvp;
332 struct hammer_mount *hmp;
427e5fc6 333 int vol_flags;
8750964d
MD
334};
335
8cd0a023
MD
336typedef struct hammer_volume *hammer_volume_t;
337
66325755 338/*
8cd0a023
MD
339 * In-memory buffer (other then volume, super-cluster, or cluster),
340 * representing an on-disk buffer.
66325755 341 */
427e5fc6 342struct hammer_buffer {
66325755 343 struct hammer_io io;
427e5fc6 344 RB_ENTRY(hammer_buffer) rb_node;
47197d71 345 void *ondisk;
427e5fc6 346 struct hammer_volume *volume;
34d829f7
MD
347 hammer_off_t zone2_offset;
348 hammer_off_t zoneX_offset;
8cd0a023 349 struct hammer_node_list clist;
66325755
MD
350};
351
8cd0a023
MD
352typedef struct hammer_buffer *hammer_buffer_t;
353
354/*
355 * In-memory B-Tree node, representing an on-disk B-Tree node.
356 *
357 * This is a hang-on structure which is backed by a hammer_buffer,
358 * indexed by a hammer_cluster, and used for fine-grained locking of
359 * B-Tree nodes in order to properly control lock ordering. A hammer_buffer
360 * can contain multiple nodes representing wildly disassociated portions
361 * of the B-Tree so locking cannot be done on a buffer-by-buffer basis.
362 *
363 * This structure uses a cluster-relative index to reduce the number
364 * of layers required to access it, and also because all on-disk B-Tree
365 * references are cluster-relative offsets.
366 */
367struct hammer_node {
368 struct hammer_lock lock; /* node-by-node lock */
369 TAILQ_ENTRY(hammer_node) entry; /* per-buffer linkage */
370 RB_ENTRY(hammer_node) rb_node; /* per-cluster linkage */
47197d71 371 hammer_off_t node_offset; /* full offset spec */
40043e7f 372 struct hammer_mount *hmp;
8cd0a023
MD
373 struct hammer_buffer *buffer; /* backing buffer */
374 hammer_node_ondisk_t ondisk; /* ptr to on-disk structure */
375 struct hammer_node **cache1; /* passive cache(s) */
376 struct hammer_node **cache2;
b3deaf57 377 int flags;
740d8317 378 int loading; /* load interlock */
8cd0a023
MD
379};
380
b3deaf57
MD
381#define HAMMER_NODE_DELETED 0x0001
382#define HAMMER_NODE_FLUSH 0x0002
b3deaf57 383
8cd0a023
MD
384typedef struct hammer_node *hammer_node_t;
385
b33e2cc0
MD
386/*
387 * List of locked nodes.
388 */
389struct hammer_node_locklist {
390 struct hammer_node_locklist *next;
391 hammer_node_t node;
392};
393
394typedef struct hammer_node_locklist *hammer_node_locklist_t;
395
396
8cd0a023
MD
397/*
398 * Common I/O management structure - embedded in in-memory structures
399 * which are backed by filesystem buffers.
400 */
66325755
MD
401union hammer_io_structure {
402 struct hammer_io io;
403 struct hammer_volume volume;
66325755 404 struct hammer_buffer buffer;
8750964d
MD
405};
406
055f5ff8
MD
407typedef union hammer_io_structure *hammer_io_structure_t;
408
bf686dbe
MD
409/*
410 * Allocation holes are recorded for a short period of time in an attempt
411 * to use up the space.
412 */
413
414#define HAMMER_MAX_HOLES 8
415
416struct hammer_hole;
417
418struct hammer_holes {
419 TAILQ_HEAD(, hammer_hole) list;
420 int count;
421};
422
423typedef struct hammer_holes *hammer_holes_t;
424
425struct hammer_hole {
426 TAILQ_ENTRY(hammer_hole) entry;
427 hammer_off_t offset;
428 int bytes;
429};
430
431typedef struct hammer_hole *hammer_hole_t;
427e5fc6 432
8cd0a023
MD
433#include "hammer_cursor.h"
434
8750964d
MD
435/*
436 * Internal hammer mount data structure
437 */
438struct hammer_mount {
439 struct mount *mp;
27ea2398 440 /*struct vnode *rootvp;*/
8750964d
MD
441 struct hammer_ino_rb_tree rb_inos_root;
442 struct hammer_vol_rb_tree rb_vols_root;
40043e7f 443 struct hammer_nod_rb_tree rb_nods_root;
8750964d 444 struct hammer_volume *rootvol;
47197d71
MD
445 struct hammer_base_elm root_btree_beg;
446 struct hammer_base_elm root_btree_end;
d26d0ae9 447 char *zbuf; /* HAMMER_BUFSIZE bytes worth of all-zeros */
195c19a1
MD
448 int hflags;
449 int ronly;
450 int nvolumes;
d26d0ae9 451 int volume_iterator;
059819e3
MD
452 int flusher_seq;
453 int flusher_act;
454 int flusher_exiting;
455 thread_t flusher_td;
855942b6 456 u_int check_interrupt;
8750964d 457 uuid_t fsid;
66325755 458 udev_t fsid_udev;
7f7c1f84 459 hammer_tid_t asof;
b84de5af 460 hammer_off_t next_tid;
66325755 461 u_int32_t namekey_iterator;
f03c9cf4 462 hammer_off_t zone_limits[HAMMER_MAX_ZONES];
513ca7d7 463 struct netexport export;
40043e7f 464 struct lock blockmap_lock;
bf686dbe 465 struct hammer_holes holes[HAMMER_MAX_ZONES];
059819e3 466 TAILQ_HEAD(, hammer_inode) flush_list;
8750964d
MD
467};
468
8cd0a023 469typedef struct hammer_mount *hammer_mount_t;
8750964d 470
fbc6e32a
MD
471struct hammer_sync_info {
472 int error;
473 int waitfor;
474};
475
8750964d
MD
476#endif
477
478#if defined(_KERNEL)
479
480extern struct vop_ops hammer_vnode_vops;
7a04d74f
MD
481extern struct vop_ops hammer_spec_vops;
482extern struct vop_ops hammer_fifo_vops;
66325755 483extern struct bio_ops hammer_bioops;
427e5fc6 484
d5ef456e 485extern int hammer_debug_general;
7d683b0f 486extern int hammer_debug_locks;
b3deaf57 487extern int hammer_debug_btree;
d113fda1 488extern int hammer_debug_tid;
b33e2cc0 489extern int hammer_debug_recover;
46fe7ae1 490extern int hammer_debug_recover_faults;
b3deaf57
MD
491extern int hammer_count_inodes;
492extern int hammer_count_records;
493extern int hammer_count_record_datas;
494extern int hammer_count_volumes;
b3deaf57
MD
495extern int hammer_count_buffers;
496extern int hammer_count_nodes;
7d683b0f 497extern int64_t hammer_contention_count;
b3deaf57 498
8750964d
MD
499int hammer_vop_inactive(struct vop_inactive_args *);
500int hammer_vop_reclaim(struct vop_reclaim_args *);
66325755
MD
501int hammer_get_vnode(struct hammer_inode *ip, int lktype,
502 struct vnode **vpp);
36f82b23 503struct hammer_inode *hammer_get_inode(hammer_transaction_t trans,
61aeeb33 504 struct hammer_node **cache,
d113fda1
MD
505 u_int64_t obj_id, hammer_tid_t asof, int flags,
506 int *errorp);
66325755
MD
507void hammer_put_inode(struct hammer_inode *ip);
508void hammer_put_inode_ref(struct hammer_inode *ip);
509
8cd0a023 510int hammer_unload_volume(hammer_volume_t volume, void *data __unused);
a89aec1b 511int hammer_unload_buffer(hammer_buffer_t buffer, void *data __unused);
8cd0a023
MD
512int hammer_install_volume(hammer_mount_t hmp, const char *volname);
513
a89aec1b
MD
514int hammer_ip_lookup(hammer_cursor_t cursor, hammer_inode_t ip);
515int hammer_ip_first(hammer_cursor_t cursor, hammer_inode_t ip);
516int hammer_ip_next(hammer_cursor_t cursor);
40043e7f 517int hammer_ip_resolve_record_and_data(hammer_cursor_t cursor);
8cd0a023 518int hammer_ip_resolve_data(hammer_cursor_t cursor);
195c19a1 519int hammer_ip_delete_record(hammer_cursor_t cursor, hammer_tid_t tid);
7dc57964 520int hammer_delete_at_cursor(hammer_cursor_t cursor, int64_t *stat_bytes);
b3deaf57
MD
521int hammer_ip_check_directory_empty(hammer_transaction_t trans,
522 hammer_inode_t ip);
fbc6e32a
MD
523int hammer_sync_hmp(hammer_mount_t hmp, int waitfor);
524int hammer_sync_volume(hammer_volume_t volume, void *data);
fbc6e32a
MD
525int hammer_sync_buffer(hammer_buffer_t buffer, void *data);
526
8cd0a023 527hammer_record_t
40043e7f 528 hammer_alloc_mem_record(hammer_inode_t ip);
b84de5af
MD
529void hammer_flush_record_done(hammer_record_t record);
530void hammer_wait_mem_record(hammer_record_t record);
b3deaf57 531void hammer_rel_mem_record(hammer_record_t record);
8cd0a023 532
b84de5af 533
6a37e7e4 534int hammer_cursor_up(hammer_cursor_t cursor);
8cd0a023 535int hammer_cursor_down(hammer_cursor_t cursor);
6a37e7e4
MD
536int hammer_cursor_upgrade(hammer_cursor_t cursor);
537void hammer_cursor_downgrade(hammer_cursor_t cursor);
32c90105
MD
538int hammer_cursor_seek(hammer_cursor_t cursor, hammer_node_t node,
539 int index);
8cd0a023
MD
540void hammer_lock_ex(struct hammer_lock *lock);
541int hammer_lock_ex_try(struct hammer_lock *lock);
542void hammer_lock_sh(struct hammer_lock *lock);
6a37e7e4
MD
543int hammer_lock_upgrade(struct hammer_lock *lock);
544void hammer_lock_downgrade(struct hammer_lock *lock);
427e5fc6 545void hammer_unlock(struct hammer_lock *lock);
66325755
MD
546void hammer_ref(struct hammer_lock *lock);
547void hammer_unref(struct hammer_lock *lock);
8cd0a023 548
66325755 549u_int32_t hammer_to_unix_xid(uuid_t *uuid);
8cd0a023
MD
550void hammer_guid_to_uuid(uuid_t *uuid, u_int32_t guid);
551void hammer_to_timespec(hammer_tid_t tid, struct timespec *ts);
552hammer_tid_t hammer_timespec_to_transid(struct timespec *ts);
a89aec1b 553hammer_tid_t hammer_alloc_tid(hammer_transaction_t trans);
7f7c1f84 554hammer_tid_t hammer_now_tid(void);
d113fda1 555hammer_tid_t hammer_str_to_tid(const char *str);
8cd0a023 556
66325755 557enum vtype hammer_get_vnode_type(u_int8_t obj_type);
6b4f890b 558int hammer_get_dtype(u_int8_t obj_type);
66325755
MD
559u_int8_t hammer_get_obj_type(enum vtype vtype);
560int64_t hammer_directory_namekey(void *name, int len);
427e5fc6 561
36f82b23
MD
562int hammer_init_cursor(hammer_transaction_t trans, hammer_cursor_t cursor,
563 struct hammer_node **cache);
195c19a1 564
8cd0a023 565void hammer_done_cursor(hammer_cursor_t cursor);
6b4f890b 566void hammer_mem_done(hammer_cursor_t cursor);
8cd0a023
MD
567
568int hammer_btree_lookup(hammer_cursor_t cursor);
d26d0ae9 569int hammer_btree_first(hammer_cursor_t cursor);
32c90105 570int hammer_btree_last(hammer_cursor_t cursor);
8cd0a023
MD
571int hammer_btree_extract(hammer_cursor_t cursor, int flags);
572int hammer_btree_iterate(hammer_cursor_t cursor);
32c90105 573int hammer_btree_iterate_reverse(hammer_cursor_t cursor);
8cd0a023
MD
574int hammer_btree_insert(hammer_cursor_t cursor, hammer_btree_elm_t elm);
575int hammer_btree_delete(hammer_cursor_t cursor);
576int hammer_btree_cmp(hammer_base_elm_t key1, hammer_base_elm_t key2);
d26d0ae9 577int hammer_btree_chkts(hammer_tid_t ts, hammer_base_elm_t key);
32c90105
MD
578int hammer_btree_correct_rhb(hammer_cursor_t cursor, hammer_tid_t tid);
579int hammer_btree_correct_lhb(hammer_cursor_t cursor, hammer_tid_t tid);
580
fe7678ee 581
b33e2cc0
MD
582int hammer_btree_lock_children(hammer_cursor_t cursor,
583 struct hammer_node_locklist **locklistp);
b33e2cc0 584
c0ade690
MD
585void hammer_print_btree_node(hammer_node_ondisk_t ondisk);
586void hammer_print_btree_elm(hammer_btree_elm_t elm, u_int8_t type, int i);
8750964d 587
47197d71
MD
588void *hammer_bread(struct hammer_mount *hmp, hammer_off_t off,
589 int *errorp, struct hammer_buffer **bufferp);
590void *hammer_bnew(struct hammer_mount *hmp, hammer_off_t off,
591 int *errorp, struct hammer_buffer **bufferp);
8cd0a023
MD
592
593hammer_volume_t hammer_get_root_volume(hammer_mount_t hmp, int *errorp);
059819e3
MD
594int hammer_dowrite(hammer_transaction_t trans, hammer_inode_t ip,
595 struct bio *bio);
427e5fc6 596
8cd0a023 597hammer_volume_t hammer_get_volume(hammer_mount_t hmp,
427e5fc6 598 int32_t vol_no, int *errorp);
47197d71
MD
599hammer_buffer_t hammer_get_buffer(hammer_mount_t hmp,
600 hammer_off_t buf_offset, int isnew, int *errorp);
b58c6388 601void hammer_uncache_buffer(struct hammer_mount *hmp, hammer_off_t off);
8cd0a023 602
fbc6e32a 603int hammer_ref_volume(hammer_volume_t volume);
8cd0a023
MD
604int hammer_ref_buffer(hammer_buffer_t buffer);
605void hammer_flush_buffer_nodes(hammer_buffer_t buffer);
606
8cd0a023 607void hammer_rel_volume(hammer_volume_t volume, int flush);
8cd0a023
MD
608void hammer_rel_buffer(hammer_buffer_t buffer, int flush);
609
513ca7d7
MD
610int hammer_vfs_export(struct mount *mp, int op,
611 const struct export_args *export);
47197d71
MD
612hammer_node_t hammer_get_node(hammer_mount_t hmp,
613 hammer_off_t node_offset, int *errorp);
740d8317 614void hammer_ref_node(hammer_node_t node);
055f5ff8
MD
615hammer_node_t hammer_ref_node_safe(struct hammer_mount *hmp,
616 struct hammer_node **cache, int *errorp);
8cd0a023 617void hammer_rel_node(hammer_node_t node);
36f82b23
MD
618void hammer_delete_node(hammer_transaction_t trans,
619 hammer_node_t node);
8cd0a023
MD
620void hammer_cache_node(hammer_node_t node,
621 struct hammer_node **cache);
622void hammer_uncache_node(struct hammer_node **cache);
623void hammer_flush_node(hammer_node_t node);
624
427e5fc6
MD
625void hammer_dup_buffer(struct hammer_buffer **bufferp,
626 struct hammer_buffer *buffer);
36f82b23
MD
627hammer_node_t hammer_alloc_btree(hammer_transaction_t trans, int *errorp);
628void *hammer_alloc_record(hammer_transaction_t trans,
bf686dbe 629 hammer_off_t *rec_offp, u_int16_t rec_type,
40043e7f
MD
630 struct hammer_buffer **rec_bufferp,
631 int32_t data_len, void **datap,
632 struct hammer_buffer **data_bufferp, int *errorp);
36f82b23 633void *hammer_alloc_data(hammer_transaction_t trans, int32_t data_len,
bf686dbe
MD
634 hammer_off_t *data_offsetp,
635 struct hammer_buffer **data_bufferp, int *errorp);
636
059819e3
MD
637int hammer_generate_undo(hammer_transaction_t trans, hammer_io_t io,
638 hammer_off_t zone1_offset, void *base, int len);
427e5fc6 639
66325755 640void hammer_put_volume(struct hammer_volume *volume, int flush);
66325755 641void hammer_put_buffer(struct hammer_buffer *buffer, int flush);
427e5fc6 642
36f82b23
MD
643hammer_off_t hammer_freemap_alloc(hammer_transaction_t trans,
644 hammer_off_t owner, int *errorp);
645void hammer_freemap_free(hammer_transaction_t trans, hammer_off_t phys_offset,
c3be93f2 646 hammer_off_t owner, int *errorp);
36f82b23 647hammer_off_t hammer_blockmap_alloc(hammer_transaction_t trans, int zone,
40043e7f 648 int bytes, int *errorp);
36f82b23
MD
649void hammer_blockmap_free(hammer_transaction_t trans,
650 hammer_off_t bmap_off, int bytes);
bf686dbe
MD
651int hammer_blockmap_getfree(hammer_mount_t hmp, hammer_off_t bmap_off,
652 int *curp, int *errorp);
40043e7f
MD
653hammer_off_t hammer_blockmap_lookup(hammer_mount_t hmp, hammer_off_t bmap_off,
654 int *errorp);
bf686dbe
MD
655hammer_off_t hammer_undo_lookup(hammer_mount_t hmp, hammer_off_t bmap_off,
656 int *errorp);
40043e7f 657
8cd0a023
MD
658void hammer_start_transaction(struct hammer_transaction *trans,
659 struct hammer_mount *hmp);
36f82b23
MD
660void hammer_simple_transaction(struct hammer_transaction *trans,
661 struct hammer_mount *hmp);
b84de5af
MD
662void hammer_start_transaction_fls(struct hammer_transaction *trans,
663 struct hammer_mount *hmp);
664void hammer_done_transaction(struct hammer_transaction *trans);
66325755
MD
665
666void hammer_modify_inode(struct hammer_transaction *trans,
8cd0a023 667 hammer_inode_t ip, int flags);
b84de5af
MD
668void hammer_flush_inode(hammer_inode_t ip, int forceit);
669void hammer_flush_inode_done(hammer_inode_t ip);
670void hammer_wait_inode(hammer_inode_t ip);
671
8cd0a023
MD
672int hammer_create_inode(struct hammer_transaction *trans, struct vattr *vap,
673 struct ucred *cred, struct hammer_inode *dip,
674 struct hammer_inode **ipp);
a89aec1b 675void hammer_rel_inode(hammer_inode_t ip, int flush);
b84de5af 676int hammer_sync_inode(hammer_inode_t ip, int handle_delete);
8cd0a023 677
a89aec1b 678int hammer_ip_add_directory(struct hammer_transaction *trans,
8cd0a023
MD
679 hammer_inode_t dip, struct namecache *ncp,
680 hammer_inode_t nip);
a89aec1b 681int hammer_ip_del_directory(struct hammer_transaction *trans,
8cd0a023
MD
682 hammer_cursor_t cursor, hammer_inode_t dip,
683 hammer_inode_t ip);
7a04d74f
MD
684int hammer_ip_add_record(struct hammer_transaction *trans,
685 hammer_record_t record);
a89aec1b 686int hammer_ip_delete_range(struct hammer_transaction *trans,
47197d71 687 hammer_inode_t ip, int64_t ran_beg, int64_t ran_end);
7a04d74f
MD
688int hammer_ip_delete_range_all(struct hammer_transaction *trans,
689 hammer_inode_t ip);
c0ade690 690int hammer_ip_sync_data(struct hammer_transaction *trans,
8cd0a023 691 hammer_inode_t ip, int64_t offset,
47197d71 692 void *data, int bytes);
36f82b23 693int hammer_ip_sync_record(hammer_transaction_t trans, hammer_record_t rec);
66325755 694
7dc57964
MD
695int hammer_ioctl(hammer_inode_t ip, u_long com, caddr_t data, int fflag,
696 struct ucred *cred);
697
055f5ff8 698void hammer_io_init(hammer_io_t io, enum hammer_io_type type);
66325755
MD
699int hammer_io_read(struct vnode *devvp, struct hammer_io *io);
700int hammer_io_new(struct vnode *devvp, struct hammer_io *io);
b58c6388 701void hammer_io_release(struct hammer_io *io);
055f5ff8 702void hammer_io_flush(struct hammer_io *io);
8cd0a023 703int hammer_io_checkflush(hammer_io_t io);
61aeeb33 704void hammer_io_clear_modify(struct hammer_io *io);
055f5ff8 705void hammer_io_waitdep(struct hammer_io *io);
66325755 706
36f82b23
MD
707void hammer_modify_volume(hammer_transaction_t trans, hammer_volume_t volume,
708 void *base, int len);
709void hammer_modify_buffer(hammer_transaction_t trans, hammer_buffer_t buffer,
710 void *base, int len);
0b075555 711
36f82b23
MD
712int hammer_ioc_reblock(hammer_transaction_t trans, hammer_inode_t ip,
713 struct hammer_ioc_reblock *reblock);
bf686dbe
MD
714
715void hammer_init_holes(hammer_mount_t hmp, hammer_holes_t holes);
716void hammer_free_holes(hammer_mount_t hmp, hammer_holes_t holes);
855942b6 717int hammer_signal_check(hammer_mount_t hmp);
bf686dbe 718
059819e3
MD
719void hammer_flusher_create(hammer_mount_t hmp);
720void hammer_flusher_destroy(hammer_mount_t hmp);
721void hammer_flusher_sync(hammer_mount_t hmp);
722void hammer_flusher_async(hammer_mount_t hmp);
723
055f5ff8 724#endif
427e5fc6 725
8cd0a023 726static __inline void
36f82b23 727hammer_modify_node_noundo(hammer_transaction_t trans, hammer_node_t node)
bf686dbe 728{
36f82b23 729 hammer_modify_buffer(trans, node->buffer, NULL, 0);
bf686dbe
MD
730}
731
732static __inline void
36f82b23 733hammer_modify_node_all(hammer_transaction_t trans, struct hammer_node *node)
8cd0a023 734{
36f82b23
MD
735 hammer_modify_buffer(trans, node->buffer,
736 node->ondisk, sizeof(*node->ondisk));
427e5fc6
MD
737}
738
bf686dbe 739static __inline void
36f82b23
MD
740hammer_modify_node(hammer_transaction_t trans, hammer_node_t node,
741 void *base, int len)
bf686dbe
MD
742{
743 KKASSERT((char *)base >= (char *)node->ondisk &&
744 (char *)base + len <=
745 (char *)node->ondisk + sizeof(*node->ondisk));
36f82b23 746 hammer_modify_buffer(trans, node->buffer, base, len);
bf686dbe
MD
747}
748
749static __inline void
36f82b23
MD
750hammer_modify_record(hammer_transaction_t trans, hammer_buffer_t buffer,
751 void *base, int len)
bf686dbe
MD
752{
753 KKASSERT((char *)base >= (char *)buffer->ondisk &&
754 (char *)base + len <= (char *)buffer->ondisk + HAMMER_BUFSIZE);
36f82b23 755 hammer_modify_buffer(trans, buffer, base, len);
bf686dbe
MD
756}
757