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