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