Fix build breakage occuring when INVARIANTS not defined and introduced
[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 *
eaeff70d 34 * $DragonFly: src/sys/vfs/hammer/hammer.h,v 1.27 2008/01/21 00:00:19 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>
44#include <sys/systm.h>
8750964d
MD
45#include <sys/tree.h>
46#include <sys/malloc.h>
427e5fc6
MD
47#include <sys/mount.h>
48#include <sys/vnode.h>
49#include <sys/globaldata.h>
66325755
MD
50#include <sys/lockf.h>
51#include <sys/buf.h>
8cd0a023 52#include <sys/queue.h>
66325755
MD
53#include <sys/globaldata.h>
54
55#include <sys/buf2.h>
c60bb2c5 56#include "hammer_alist.h"
427e5fc6 57#include "hammer_disk.h"
8750964d
MD
58#include "hammer_mount.h"
59
60#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
61
62MALLOC_DECLARE(M_HAMMER);
63
66325755
MD
64struct hammer_mount;
65
8750964d
MD
66/*
67 * Key structure used for custom RB tree inode lookups. This prototypes
68 * the function hammer_ino_rb_tree_RB_LOOKUP_INFO(root, info).
69 */
70typedef struct hammer_inode_info {
71 u_int64_t obj_id; /* (key) object identifier */
72 hammer_tid_t obj_asof; /* (key) snapshot transid or 0 */
73} *hammer_inode_info_t;
74
66325755
MD
75/*
76 * HAMMER Transaction tracking
77 */
78struct hammer_transaction {
79 struct hammer_mount *hmp;
80 hammer_tid_t tid;
a89aec1b 81 struct hammer_volume *rootvol;
66325755
MD
82};
83
8cd0a023
MD
84typedef struct hammer_transaction *hammer_transaction_t;
85
66325755
MD
86/*
87 * HAMMER locks
88 */
427e5fc6 89struct hammer_lock {
0b075555 90 int refs; /* active references delay writes */
0b075555 91 int lockcount; /* lock count for exclusive/shared access */
427e5fc6
MD
92 int wanted;
93 struct thread *locktd;
8750964d
MD
94};
95
427e5fc6
MD
96static __inline int
97hammer_islocked(struct hammer_lock *lock)
98{
8cd0a023 99 return(lock->lockcount != 0);
427e5fc6
MD
100}
101
0b075555
MD
102static __inline int
103hammer_isactive(struct hammer_lock *lock)
104{
105 return(lock->refs != 0);
106}
107
427e5fc6
MD
108static __inline int
109hammer_islastref(struct hammer_lock *lock)
110{
111 return(lock->refs == 1);
112}
c60bb2c5 113
6a37e7e4
MD
114/*
115 * This inline is specifically optimized for the case where the caller
116 * owns the lock, but wants to know what kind of lock he owns. A
117 * negative value indicates a shared lock, a positive value indicates
118 * an exclusive lock.
119 */
120static __inline int
121hammer_lock_held(struct hammer_lock *lock)
122{
123 return(lock->lockcount);
124}
125
8750964d 126/*
8cd0a023
MD
127 * Structure used to represent an inode in-memory.
128 *
129 * The record and data associated with an inode may be out of sync with
130 * the disk (xDIRTY flags), or not even on the disk at all (ONDISK flag
131 * clear).
132 *
133 * An inode may also hold a cache of unsynchronized records, used for
134 * database and directories only. Unsynchronized regular file data is
135 * stored in the buffer cache.
136 *
137 * NOTE: A file which is created and destroyed within the initial
138 * synchronization period can wind up not doing any disk I/O at all.
139 *
140 * Finally, an inode may cache numerous disk-referencing B-Tree cursors.
8750964d
MD
141 */
142struct hammer_ino_rb_tree;
143struct hammer_inode;
144RB_HEAD(hammer_ino_rb_tree, hammer_inode);
145RB_PROTOTYPEX(hammer_ino_rb_tree, INFO, hammer_inode, rb_node,
8cd0a023
MD
146 hammer_ino_rb_compare, hammer_inode_info_t);
147
148struct hammer_rec_rb_tree;
149struct hammer_record;
150RB_HEAD(hammer_rec_rb_tree, hammer_record);
151RB_PROTOTYPEX(hammer_rec_rb_tree, INFO, hammer_record, rb_node,
152 hammer_rec_rb_compare, hammer_base_elm_t);
153
154TAILQ_HEAD(hammer_node_list, hammer_node);
8750964d
MD
155
156struct hammer_inode {
157 RB_ENTRY(hammer_inode) rb_node;
158 u_int64_t obj_id; /* (key) object identifier */
159 hammer_tid_t obj_asof; /* (key) snapshot transid or 0 */
8cd0a023 160 hammer_tid_t last_tid; /* last modified tid (for fsync) */
66325755
MD
161 struct hammer_mount *hmp;
162 int flags;
c60bb2c5 163 struct vnode *vp;
66325755 164 struct lockf advlock;
8cd0a023 165 struct hammer_lock lock;
c60bb2c5
MD
166 struct hammer_inode_record ino_rec;
167 struct hammer_inode_data ino_data;
8cd0a023 168 struct hammer_rec_rb_tree rec_tree; /* red-black record tree */
61aeeb33 169 struct hammer_node *cache[2]; /* search initiate cache */
8750964d
MD
170};
171
8cd0a023
MD
172typedef struct hammer_inode *hammer_inode_t;
173
66325755
MD
174#define VTOI(vp) ((struct hammer_inode *)(vp)->v_data)
175
8cd0a023
MD
176#define HAMMER_INODE_DDIRTY 0x0001 /* in-memory ino_data is dirty */
177#define HAMMER_INODE_RDIRTY 0x0002 /* in-memory ino_rec is dirty */
178#define HAMMER_INODE_ITIMES 0x0004 /* in-memory mtime/atime modified */
d113fda1 179#define HAMMER_INODE_XDIRTY 0x0008 /* in-memory records present */
8cd0a023 180#define HAMMER_INODE_ONDISK 0x0010 /* inode is on-disk (else not yet) */
a89aec1b 181#define HAMMER_INODE_FLUSH 0x0020 /* flush on last ref */
c0ade690 182#define HAMMER_INODE_DELETED 0x0080 /* inode ready for deletion */
76376933 183#define HAMMER_INODE_DELONDISK 0x0100 /* delete synchronized to disk */
d113fda1
MD
184#define HAMMER_INODE_RO 0x0200 /* read-only (because of as-of) */
185#define HAMMER_INODE_GONE 0x0400 /* delete flushed out */
0a72edae 186#define HAMMER_INODE_DONDISK 0x0800 /* data records may be on disk */
f3b0f382 187#define HAMMER_INODE_BUFS 0x1000 /* dirty high level bps present */
8cd0a023 188
0b075555 189#define HAMMER_INODE_MODMASK (HAMMER_INODE_DDIRTY|HAMMER_INODE_RDIRTY| \
f3b0f382 190 HAMMER_INODE_XDIRTY|HAMMER_INODE_BUFS| \
d113fda1 191 HAMMER_INODE_ITIMES|HAMMER_INODE_DELETED)
0b075555 192
8cd0a023 193#define HAMMER_MAX_INODE_CURSORS 4
66325755 194
8750964d 195/*
8cd0a023
MD
196 * Structure used to represent an unsynchronized record in-memory. This
197 * structure is orgranized in a per-inode RB-tree. If the inode is not
198 * on disk then neither are any records and the in-memory record tree
199 * represents the entire contents of the inode. If the inode is on disk
200 * then the on-disk B-Tree is scanned in parallel with the in-memory
201 * RB-Tree to synthesize the current state of the file.
202 *
203 * Only current (delete_tid == 0) unsynchronized records are kept in-memory.
8750964d 204 */
8cd0a023
MD
205struct hammer_record {
206 RB_ENTRY(hammer_record) rb_node;
a89aec1b 207 struct hammer_lock lock;
8cd0a023
MD
208 struct hammer_inode *ip;
209 union hammer_record_ondisk rec;
210 union hammer_data_ondisk *data;
8cd0a023
MD
211 int flags;
212};
8750964d 213
8cd0a023
MD
214typedef struct hammer_record *hammer_record_t;
215
216#define HAMMER_RECF_ALLOCDATA 0x0001
217#define HAMMER_RECF_ONRBTREE 0x0002
a89aec1b 218#define HAMMER_RECF_DELETED 0x0004
c0ade690 219#define HAMMER_RECF_EMBEDDED_DATA 0x0008
b3deaf57 220#define HAMMER_RECF_SYNCING 0x0010
8cd0a023
MD
221
222/*
223 * Structures used to internally represent a volume and a cluster
224 */
8750964d
MD
225struct hammer_volume;
226struct hammer_cluster;
427e5fc6
MD
227struct hammer_supercl;
228struct hammer_buffer;
8cd0a023 229struct hammer_node;
8750964d
MD
230RB_HEAD(hammer_vol_rb_tree, hammer_volume);
231RB_HEAD(hammer_clu_rb_tree, hammer_cluster);
427e5fc6
MD
232RB_HEAD(hammer_scl_rb_tree, hammer_supercl);
233RB_HEAD(hammer_buf_rb_tree, hammer_buffer);
8cd0a023 234RB_HEAD(hammer_nod_rb_tree, hammer_node);
8750964d
MD
235
236RB_PROTOTYPE2(hammer_vol_rb_tree, hammer_volume, rb_node,
237 hammer_vol_rb_compare, int32_t);
238RB_PROTOTYPE2(hammer_clu_rb_tree, hammer_cluster, rb_node,
239 hammer_clu_rb_compare, int32_t);
427e5fc6
MD
240RB_PROTOTYPE2(hammer_scl_rb_tree, hammer_supercl, rb_node,
241 hammer_scl_rb_compare, int32_t);
242RB_PROTOTYPE2(hammer_buf_rb_tree, hammer_buffer, rb_node,
243 hammer_buf_rb_compare, int32_t);
8cd0a023
MD
244RB_PROTOTYPE2(hammer_nod_rb_tree, hammer_node, rb_node,
245 hammer_nod_rb_compare, int32_t);
8750964d 246
66325755
MD
247/*
248 * IO management - embedded at the head of various in-memory structures
249 */
250enum hammer_io_type { HAMMER_STRUCTURE_VOLUME,
251 HAMMER_STRUCTURE_SUPERCL,
252 HAMMER_STRUCTURE_CLUSTER,
253 HAMMER_STRUCTURE_BUFFER };
254
255union hammer_io_structure;
055f5ff8 256struct hammer_io;
66325755
MD
257
258struct worklist {
259 LIST_ENTRY(worklist) node;
260};
261
055f5ff8
MD
262TAILQ_HEAD(hammer_io_list, hammer_io);
263
66325755
MD
264struct hammer_io {
265 struct worklist worklist;
266 struct hammer_lock lock;
267 enum hammer_io_type type;
268 struct buf *bp;
269 int64_t offset;
055f5ff8
MD
270 TAILQ_ENTRY(hammer_io) entry; /* based on modified flag */
271 struct hammer_io_list *entry_list;
272 struct hammer_io_list deplist;
66325755
MD
273 u_int modified : 1; /* bp's data was modified */
274 u_int released : 1; /* bp released (w/ B_LOCKED set) */
055f5ff8
MD
275 u_int running : 1; /* bp write IO in progress */
276 u_int waiting : 1; /* someone is waiting on us */
eaeff70d 277 u_int loading : 1; /* ondisk is loading */
66325755
MD
278};
279
8cd0a023
MD
280typedef struct hammer_io *hammer_io_t;
281
66325755 282/*
8cd0a023 283 * In-memory volume representing on-disk buffer
66325755 284 */
8750964d 285struct hammer_volume {
66325755 286 struct hammer_io io;
8750964d
MD
287 RB_ENTRY(hammer_volume) rb_node;
288 struct hammer_clu_rb_tree rb_clus_root;
427e5fc6 289 struct hammer_scl_rb_tree rb_scls_root;
8750964d 290 struct hammer_volume_ondisk *ondisk;
427e5fc6 291 struct hammer_alist_live alist;
8750964d
MD
292 int32_t vol_no;
293 int32_t vol_clsize;
d26d0ae9 294 int32_t clu_iterator; /* cluster allocation iterator */
fbc6e32a 295 int64_t nblocks; /* note: special calculation for statfs */
8750964d 296 int64_t cluster_base; /* base offset of cluster 0 */
c60bb2c5 297 char *vol_name;
8750964d
MD
298 struct vnode *devvp;
299 struct hammer_mount *hmp;
427e5fc6 300 int vol_flags;
8750964d
MD
301};
302
8cd0a023
MD
303typedef struct hammer_volume *hammer_volume_t;
304
66325755 305/*
8cd0a023 306 * In-memory super-cluster representing on-disk buffer
66325755 307 */
427e5fc6 308struct hammer_supercl {
66325755 309 struct hammer_io io;
427e5fc6 310 RB_ENTRY(hammer_supercl) rb_node;
427e5fc6
MD
311 struct hammer_supercl_ondisk *ondisk;
312 struct hammer_volume *volume;
313 struct hammer_alist_live alist;
314 int32_t scl_no;
427e5fc6 315};
c60bb2c5 316
8cd0a023
MD
317typedef struct hammer_supercl *hammer_supercl_t;
318
66325755 319/*
8cd0a023
MD
320 * In-memory cluster representing on-disk buffer
321 *
322 * The cluster's indexing range is cached in hammer_cluster, separate
323 * from the ondisk info in order to allow cursors to point to it.
66325755 324 */
8750964d 325struct hammer_cluster {
66325755 326 struct hammer_io io;
8750964d 327 RB_ENTRY(hammer_cluster) rb_node;
427e5fc6 328 struct hammer_buf_rb_tree rb_bufs_root;
8750964d
MD
329 struct hammer_cluster_ondisk *ondisk;
330 struct hammer_volume *volume;
427e5fc6
MD
331 struct hammer_alist_live alist_master;
332 struct hammer_alist_live alist_btree;
333 struct hammer_alist_live alist_record;
334 struct hammer_alist_live alist_mdata;
8cd0a023
MD
335 struct hammer_nod_rb_tree rb_nods_root; /* cursors in cluster */
336 struct hammer_base_elm clu_btree_beg; /* copy of on-disk info */
337 struct hammer_base_elm clu_btree_end; /* copy of on-disk info */
8750964d 338 int32_t clu_no;
427e5fc6
MD
339};
340
8cd0a023
MD
341typedef struct hammer_cluster *hammer_cluster_t;
342
eaeff70d
MD
343/*
344 * Passed to hammer_get_cluster()
345 */
346#define GET_CLUSTER_NEW 0x0001
347#define GET_CLUSTER_NORECOVER 0x0002
348
66325755 349/*
8cd0a023
MD
350 * In-memory buffer (other then volume, super-cluster, or cluster),
351 * representing an on-disk buffer.
66325755 352 */
427e5fc6 353struct hammer_buffer {
66325755 354 struct hammer_io io;
427e5fc6 355 RB_ENTRY(hammer_buffer) rb_node;
427e5fc6 356 hammer_fsbuf_ondisk_t ondisk;
427e5fc6 357 struct hammer_volume *volume;
8cd0a023 358 struct hammer_cluster *cluster;
427e5fc6 359 int32_t buf_no;
8cd0a023
MD
360 u_int64_t buf_type;
361 struct hammer_alist_live alist;
362 struct hammer_node_list clist;
66325755
MD
363};
364
8cd0a023
MD
365typedef struct hammer_buffer *hammer_buffer_t;
366
367/*
368 * In-memory B-Tree node, representing an on-disk B-Tree node.
369 *
370 * This is a hang-on structure which is backed by a hammer_buffer,
371 * indexed by a hammer_cluster, and used for fine-grained locking of
372 * B-Tree nodes in order to properly control lock ordering. A hammer_buffer
373 * can contain multiple nodes representing wildly disassociated portions
374 * of the B-Tree so locking cannot be done on a buffer-by-buffer basis.
375 *
376 * This structure uses a cluster-relative index to reduce the number
377 * of layers required to access it, and also because all on-disk B-Tree
378 * references are cluster-relative offsets.
379 */
380struct hammer_node {
381 struct hammer_lock lock; /* node-by-node lock */
382 TAILQ_ENTRY(hammer_node) entry; /* per-buffer linkage */
383 RB_ENTRY(hammer_node) rb_node; /* per-cluster linkage */
384 int32_t node_offset; /* cluster-rel offset */
385 struct hammer_cluster *cluster;
386 struct hammer_buffer *buffer; /* backing buffer */
387 hammer_node_ondisk_t ondisk; /* ptr to on-disk structure */
388 struct hammer_node **cache1; /* passive cache(s) */
389 struct hammer_node **cache2;
b3deaf57 390 int flags;
8cd0a023
MD
391};
392
b3deaf57
MD
393#define HAMMER_NODE_DELETED 0x0001
394#define HAMMER_NODE_FLUSH 0x0002
b3deaf57 395
8cd0a023
MD
396typedef struct hammer_node *hammer_node_t;
397
398/*
399 * Common I/O management structure - embedded in in-memory structures
400 * which are backed by filesystem buffers.
401 */
66325755
MD
402union hammer_io_structure {
403 struct hammer_io io;
404 struct hammer_volume volume;
405 struct hammer_supercl supercl;
406 struct hammer_cluster cluster;
407 struct hammer_buffer buffer;
8750964d
MD
408};
409
055f5ff8
MD
410typedef union hammer_io_structure *hammer_io_structure_t;
411
427e5fc6
MD
412#define HAMFS_CLUSTER_DIRTY 0x0001
413
8cd0a023
MD
414#include "hammer_cursor.h"
415
8750964d
MD
416/*
417 * Internal hammer mount data structure
418 */
419struct hammer_mount {
420 struct mount *mp;
27ea2398 421 /*struct vnode *rootvp;*/
8750964d
MD
422 struct hammer_ino_rb_tree rb_inos_root;
423 struct hammer_vol_rb_tree rb_vols_root;
424 struct hammer_volume *rootvol;
425 struct hammer_cluster *rootcl;
d26d0ae9 426 char *zbuf; /* HAMMER_BUFSIZE bytes worth of all-zeros */
195c19a1
MD
427 int hflags;
428 int ronly;
429 int nvolumes;
d26d0ae9 430 int volume_iterator;
8750964d 431 uuid_t fsid;
66325755 432 udev_t fsid_udev;
7f7c1f84 433 hammer_tid_t asof;
66325755 434 u_int32_t namekey_iterator;
8750964d
MD
435};
436
8cd0a023 437typedef struct hammer_mount *hammer_mount_t;
8750964d 438
fbc6e32a
MD
439struct hammer_sync_info {
440 int error;
441 int waitfor;
442};
443
8750964d
MD
444#endif
445
446#if defined(_KERNEL)
447
448extern struct vop_ops hammer_vnode_vops;
7a04d74f
MD
449extern struct vop_ops hammer_spec_vops;
450extern struct vop_ops hammer_fifo_vops;
427e5fc6
MD
451extern struct hammer_alist_config Buf_alist_config;
452extern struct hammer_alist_config Vol_normal_alist_config;
453extern struct hammer_alist_config Vol_super_alist_config;
454extern struct hammer_alist_config Supercl_alist_config;
455extern struct hammer_alist_config Clu_master_alist_config;
456extern struct hammer_alist_config Clu_slave_alist_config;
66325755 457extern struct bio_ops hammer_bioops;
427e5fc6 458
b3deaf57 459extern int hammer_debug_btree;
d113fda1 460extern int hammer_debug_tid;
b3deaf57
MD
461extern int hammer_count_inodes;
462extern int hammer_count_records;
463extern int hammer_count_record_datas;
464extern int hammer_count_volumes;
465extern int hammer_count_supercls;
466extern int hammer_count_clusters;
467extern int hammer_count_buffers;
468extern int hammer_count_nodes;
469extern int hammer_count_spikes;
470
8750964d
MD
471int hammer_vop_inactive(struct vop_inactive_args *);
472int hammer_vop_reclaim(struct vop_reclaim_args *);
7f7c1f84 473int hammer_vfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp);
66325755
MD
474int hammer_get_vnode(struct hammer_inode *ip, int lktype,
475 struct vnode **vpp);
8cd0a023 476struct hammer_inode *hammer_get_inode(hammer_mount_t hmp,
61aeeb33 477 struct hammer_node **cache,
d113fda1
MD
478 u_int64_t obj_id, hammer_tid_t asof, int flags,
479 int *errorp);
66325755
MD
480void hammer_put_inode(struct hammer_inode *ip);
481void hammer_put_inode_ref(struct hammer_inode *ip);
482
d113fda1 483int hammer_unload_inode(hammer_inode_t ip, void *data);
8cd0a023 484int hammer_unload_volume(hammer_volume_t volume, void *data __unused);
a89aec1b
MD
485int hammer_unload_supercl(hammer_supercl_t supercl, void *data __unused);
486int hammer_unload_cluster(hammer_cluster_t cluster, void *data __unused);
487int hammer_unload_buffer(hammer_buffer_t buffer, void *data __unused);
8cd0a023
MD
488int hammer_install_volume(hammer_mount_t hmp, const char *volname);
489
a89aec1b
MD
490int hammer_ip_lookup(hammer_cursor_t cursor, hammer_inode_t ip);
491int hammer_ip_first(hammer_cursor_t cursor, hammer_inode_t ip);
492int hammer_ip_next(hammer_cursor_t cursor);
8cd0a023 493int hammer_ip_resolve_data(hammer_cursor_t cursor);
195c19a1 494int hammer_ip_delete_record(hammer_cursor_t cursor, hammer_tid_t tid);
b3deaf57
MD
495int hammer_ip_check_directory_empty(hammer_transaction_t trans,
496 hammer_inode_t ip);
fbc6e32a
MD
497int hammer_sync_hmp(hammer_mount_t hmp, int waitfor);
498int hammer_sync_volume(hammer_volume_t volume, void *data);
499int hammer_sync_cluster(hammer_cluster_t cluster, void *data);
500int hammer_sync_buffer(hammer_buffer_t buffer, void *data);
501
8cd0a023 502hammer_record_t
7f7c1f84 503 hammer_alloc_mem_record(hammer_inode_t ip);
b3deaf57 504void hammer_rel_mem_record(hammer_record_t record);
8cd0a023 505
6a37e7e4 506int hammer_cursor_up(hammer_cursor_t cursor);
8cd0a023
MD
507int hammer_cursor_toroot(hammer_cursor_t cursor);
508int hammer_cursor_down(hammer_cursor_t cursor);
6a37e7e4
MD
509int hammer_cursor_upgrade(hammer_cursor_t cursor);
510void hammer_cursor_downgrade(hammer_cursor_t cursor);
8cd0a023
MD
511
512void hammer_lock_ex(struct hammer_lock *lock);
513int hammer_lock_ex_try(struct hammer_lock *lock);
514void hammer_lock_sh(struct hammer_lock *lock);
6a37e7e4
MD
515int hammer_lock_upgrade(struct hammer_lock *lock);
516void hammer_lock_downgrade(struct hammer_lock *lock);
427e5fc6 517void hammer_unlock(struct hammer_lock *lock);
66325755
MD
518void hammer_ref(struct hammer_lock *lock);
519void hammer_unref(struct hammer_lock *lock);
8cd0a023 520
66325755 521u_int32_t hammer_to_unix_xid(uuid_t *uuid);
8cd0a023
MD
522void hammer_guid_to_uuid(uuid_t *uuid, u_int32_t guid);
523void hammer_to_timespec(hammer_tid_t tid, struct timespec *ts);
524hammer_tid_t hammer_timespec_to_transid(struct timespec *ts);
a89aec1b 525hammer_tid_t hammer_alloc_tid(hammer_transaction_t trans);
7f7c1f84 526hammer_tid_t hammer_now_tid(void);
d113fda1 527hammer_tid_t hammer_str_to_tid(const char *str);
eaeff70d 528u_int64_t hammer_alloc_recid(hammer_cluster_t cluster);
8cd0a023 529
66325755 530enum vtype hammer_get_vnode_type(u_int8_t obj_type);
6b4f890b 531int hammer_get_dtype(u_int8_t obj_type);
66325755
MD
532u_int8_t hammer_get_obj_type(enum vtype vtype);
533int64_t hammer_directory_namekey(void *name, int len);
427e5fc6 534
61aeeb33 535int hammer_init_cursor_hmp(hammer_cursor_t cursor, struct hammer_node **cache, hammer_mount_t hmp);
d26d0ae9 536int hammer_init_cursor_cluster(hammer_cursor_t cursor, hammer_cluster_t cluster);
195c19a1 537
8cd0a023 538void hammer_done_cursor(hammer_cursor_t cursor);
6b4f890b 539void hammer_mem_done(hammer_cursor_t cursor);
8cd0a023
MD
540
541int hammer_btree_lookup(hammer_cursor_t cursor);
d26d0ae9 542int hammer_btree_first(hammer_cursor_t cursor);
8cd0a023
MD
543int hammer_btree_extract(hammer_cursor_t cursor, int flags);
544int hammer_btree_iterate(hammer_cursor_t cursor);
545int hammer_btree_insert(hammer_cursor_t cursor, hammer_btree_elm_t elm);
9944ae54
MD
546int hammer_btree_insert_cluster(hammer_cursor_t cursor,
547 hammer_cluster_t cluster, int32_t rec_offset);
8cd0a023
MD
548int hammer_btree_delete(hammer_cursor_t cursor);
549int hammer_btree_cmp(hammer_base_elm_t key1, hammer_base_elm_t key2);
d26d0ae9 550int hammer_btree_chkts(hammer_tid_t ts, hammer_base_elm_t key);
fe7678ee 551
c0ade690
MD
552void hammer_print_btree_node(hammer_node_ondisk_t ondisk);
553void hammer_print_btree_elm(hammer_btree_elm_t elm, u_int8_t type, int i);
8750964d 554
c60bb2c5 555void *hammer_bread(struct hammer_cluster *cluster, int32_t cloff,
9944ae54
MD
556 u_int64_t buf_type, int *errorp,
557 struct hammer_buffer **bufferp);
8cd0a023
MD
558
559hammer_volume_t hammer_get_root_volume(hammer_mount_t hmp, int *errorp);
560hammer_cluster_t hammer_get_root_cluster(hammer_mount_t hmp, int *errorp);
427e5fc6 561
8cd0a023 562hammer_volume_t hammer_get_volume(hammer_mount_t hmp,
427e5fc6 563 int32_t vol_no, int *errorp);
61aeeb33
MD
564hammer_supercl_t hammer_get_supercl(hammer_volume_t volume, int32_t scl_no,
565 int *errorp, hammer_alloc_state_t isnew);
566hammer_cluster_t hammer_get_cluster(hammer_volume_t volume, int32_t clu_no,
eaeff70d 567 int *errorp, int getflags);
8cd0a023
MD
568hammer_buffer_t hammer_get_buffer(hammer_cluster_t cluster,
569 int32_t buf_no, u_int64_t buf_type, int *errorp);
570
fbc6e32a 571int hammer_ref_volume(hammer_volume_t volume);
8cd0a023
MD
572int hammer_ref_cluster(hammer_cluster_t cluster);
573int hammer_ref_buffer(hammer_buffer_t buffer);
574void hammer_flush_buffer_nodes(hammer_buffer_t buffer);
575
8cd0a023
MD
576void hammer_rel_volume(hammer_volume_t volume, int flush);
577void hammer_rel_supercl(hammer_supercl_t supercl, int flush);
578void hammer_rel_cluster(hammer_cluster_t cluster, int flush);
579void hammer_rel_buffer(hammer_buffer_t buffer, int flush);
580
581hammer_node_t hammer_get_node(hammer_cluster_t cluster,
582 int32_t node_offset, int *errorp);
583int 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
MD
586void hammer_rel_node(hammer_node_t node);
587void hammer_cache_node(hammer_node_t node,
588 struct hammer_node **cache);
589void hammer_uncache_node(struct hammer_node **cache);
590void hammer_flush_node(hammer_node_t node);
591
427e5fc6
MD
592void hammer_dup_buffer(struct hammer_buffer **bufferp,
593 struct hammer_buffer *buffer);
594void hammer_dup_cluster(struct hammer_cluster **clusterp,
595 struct hammer_cluster *cluster);
d26d0ae9
MD
596hammer_cluster_t hammer_alloc_cluster(hammer_mount_t hmp,
597 hammer_cluster_t cluster_hint, int *errorp);
598void hammer_init_cluster(hammer_cluster_t cluster,
599 hammer_base_elm_t left_bound,
600 hammer_base_elm_t right_bound);
8cd0a023 601hammer_node_t hammer_alloc_btree(struct hammer_cluster *cluster, int *errorp);
427e5fc6
MD
602void *hammer_alloc_data(struct hammer_cluster *cluster, int32_t bytes,
603 int *errorp, struct hammer_buffer **bufferp);
604void *hammer_alloc_record(struct hammer_cluster *cluster,
605 int *errorp, struct hammer_buffer **bufferp);
4d75d829
MD
606void hammer_initbuffer(hammer_alist_t live, hammer_fsbuf_head_t head,
607 u_int64_t type);
427e5fc6
MD
608void hammer_free_data_ptr(struct hammer_buffer *buffer,
609 void *data, int bytes);
610void hammer_free_record_ptr(struct hammer_buffer *buffer,
611 union hammer_record_ondisk *rec);
d26d0ae9 612void hammer_free_cluster(hammer_cluster_t cluster);
427e5fc6
MD
613void hammer_free_btree(struct hammer_cluster *cluster, int32_t bclu_offset);
614void hammer_free_data(struct hammer_cluster *cluster, int32_t bclu_offset,
615 int32_t bytes);
616void hammer_free_record(struct hammer_cluster *cluster, int32_t bclu_offset);
617
66325755
MD
618void hammer_put_volume(struct hammer_volume *volume, int flush);
619void hammer_put_supercl(struct hammer_supercl *supercl, int flush);
620void hammer_put_cluster(struct hammer_cluster *cluster, int flush);
621void hammer_put_buffer(struct hammer_buffer *buffer, int flush);
427e5fc6
MD
622
623void hammer_init_alist_config(void);
8750964d 624
8cd0a023
MD
625void hammer_start_transaction(struct hammer_transaction *trans,
626 struct hammer_mount *hmp);
d113fda1
MD
627void hammer_start_transaction_tid(struct hammer_transaction *trans,
628 struct hammer_mount *hmp, hammer_tid_t tid);
66325755
MD
629void hammer_commit_transaction(struct hammer_transaction *trans);
630void hammer_abort_transaction(struct hammer_transaction *trans);
631
632void hammer_modify_inode(struct hammer_transaction *trans,
8cd0a023
MD
633 hammer_inode_t ip, int flags);
634int hammer_create_inode(struct hammer_transaction *trans, struct vattr *vap,
635 struct ucred *cred, struct hammer_inode *dip,
636 struct hammer_inode **ipp);
a89aec1b 637void hammer_rel_inode(hammer_inode_t ip, int flush);
c0ade690 638int hammer_sync_inode(hammer_inode_t ip, int waitfor, int handle_delete);
8cd0a023 639
a89aec1b 640int hammer_ip_add_directory(struct hammer_transaction *trans,
8cd0a023
MD
641 hammer_inode_t dip, struct namecache *ncp,
642 hammer_inode_t nip);
a89aec1b 643int hammer_ip_del_directory(struct hammer_transaction *trans,
8cd0a023
MD
644 hammer_cursor_t cursor, hammer_inode_t dip,
645 hammer_inode_t ip);
7a04d74f
MD
646int hammer_ip_add_record(struct hammer_transaction *trans,
647 hammer_record_t record);
a89aec1b 648int hammer_ip_delete_range(struct hammer_transaction *trans,
d26d0ae9
MD
649 hammer_inode_t ip, int64_t ran_beg, int64_t ran_end,
650 struct hammer_cursor **spikep);
7a04d74f
MD
651int hammer_ip_delete_range_all(struct hammer_transaction *trans,
652 hammer_inode_t ip);
c0ade690 653int hammer_ip_sync_data(struct hammer_transaction *trans,
8cd0a023 654 hammer_inode_t ip, int64_t offset,
d26d0ae9
MD
655 void *data, int bytes, struct hammer_cursor **spikep);
656int hammer_ip_sync_record(hammer_record_t rec, struct hammer_cursor **spikep);
657int hammer_write_record(hammer_cursor_t cursor, hammer_record_ondisk_t rec,
658 void *data, int cursor_flags);
659
660void hammer_load_spike(hammer_cursor_t cursor, struct hammer_cursor **spikep);
661int hammer_spike(struct hammer_cursor **spikep);
4d75d829 662int hammer_recover(struct hammer_cluster *cluster);
eaeff70d 663int buffer_alist_recover(void *info, int32_t blk, int32_t radix, int32_t count);
66325755 664
055f5ff8 665void hammer_io_init(hammer_io_t io, enum hammer_io_type type);
66325755
MD
666int hammer_io_read(struct vnode *devvp, struct hammer_io *io);
667int hammer_io_new(struct vnode *devvp, struct hammer_io *io);
668void hammer_io_release(struct hammer_io *io, int flush);
055f5ff8 669void hammer_io_flush(struct hammer_io *io);
8cd0a023 670int hammer_io_checkflush(hammer_io_t io);
fbc6e32a 671void hammer_io_notify_cluster(hammer_cluster_t cluster);
61aeeb33 672void hammer_io_clear_modify(struct hammer_io *io);
055f5ff8 673void hammer_io_waitdep(struct hammer_io *io);
66325755 674
055f5ff8
MD
675void hammer_modify_volume(hammer_volume_t volume);
676void hammer_modify_supercl(hammer_supercl_t supercl);
677void hammer_modify_cluster(hammer_cluster_t cluster);
678void hammer_modify_buffer(hammer_buffer_t buffer);
0b075555 679
055f5ff8 680#endif
427e5fc6 681
8cd0a023
MD
682static __inline void
683hammer_modify_node(struct hammer_node *node)
684{
fbc6e32a 685 hammer_modify_buffer(node->buffer);
8cd0a023
MD
686}
687
427e5fc6
MD
688/*
689 * Return the cluster-relative byte offset of an element within a buffer
690 */
691static __inline int
692hammer_bclu_offset(struct hammer_buffer *buffer, void *ptr)
693{
694 int bclu_offset;
695
696 bclu_offset = buffer->buf_no * HAMMER_BUFSIZE +
697 ((char *)ptr - (char *)buffer->ondisk);
698 return(bclu_offset);
699}
700