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