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