- Turn on IFM_HDX
[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 *
47197d71 34 * $DragonFly: src/sys/vfs/hammer/hammer.h,v 1.35 2008/02/08 08:30:59 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>
427e5fc6 59#include "hammer_disk.h"
8750964d 60#include "hammer_mount.h"
7dc57964 61#include "hammer_ioctl.h"
8750964d
MD
62
63#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
64
65MALLOC_DECLARE(M_HAMMER);
66
66325755
MD
67struct hammer_mount;
68
8750964d
MD
69/*
70 * Key structure used for custom RB tree inode lookups. This prototypes
71 * the function hammer_ino_rb_tree_RB_LOOKUP_INFO(root, info).
72 */
73typedef struct hammer_inode_info {
513ca7d7 74 int64_t obj_id; /* (key) object identifier */
8750964d
MD
75 hammer_tid_t obj_asof; /* (key) snapshot transid or 0 */
76} *hammer_inode_info_t;
77
66325755
MD
78/*
79 * HAMMER Transaction tracking
80 */
81struct hammer_transaction {
82 struct hammer_mount *hmp;
83 hammer_tid_t tid;
a89aec1b 84 struct hammer_volume *rootvol;
46fe7ae1 85/* TAILQ_HEAD(, hammer_io) recycle_list;*/
66325755
MD
86};
87
8cd0a023
MD
88typedef struct hammer_transaction *hammer_transaction_t;
89
66325755
MD
90/*
91 * HAMMER locks
92 */
427e5fc6 93struct hammer_lock {
0b075555 94 int refs; /* active references delay writes */
0b075555 95 int lockcount; /* lock count for exclusive/shared access */
427e5fc6
MD
96 int wanted;
97 struct thread *locktd;
8750964d
MD
98};
99
427e5fc6
MD
100static __inline int
101hammer_islocked(struct hammer_lock *lock)
102{
8cd0a023 103 return(lock->lockcount != 0);
427e5fc6
MD
104}
105
0b075555
MD
106static __inline int
107hammer_isactive(struct hammer_lock *lock)
108{
109 return(lock->refs != 0);
110}
111
427e5fc6
MD
112static __inline int
113hammer_islastref(struct hammer_lock *lock)
114{
115 return(lock->refs == 1);
116}
c60bb2c5 117
6a37e7e4
MD
118/*
119 * This inline is specifically optimized for the case where the caller
120 * owns the lock, but wants to know what kind of lock he owns. A
121 * negative value indicates a shared lock, a positive value indicates
122 * an exclusive lock.
123 */
124static __inline int
125hammer_lock_held(struct hammer_lock *lock)
126{
127 return(lock->lockcount);
128}
129
8750964d 130/*
8cd0a023
MD
131 * Structure used to represent an inode in-memory.
132 *
133 * The record and data associated with an inode may be out of sync with
134 * the disk (xDIRTY flags), or not even on the disk at all (ONDISK flag
135 * clear).
136 *
137 * An inode may also hold a cache of unsynchronized records, used for
138 * database and directories only. Unsynchronized regular file data is
139 * stored in the buffer cache.
140 *
141 * NOTE: A file which is created and destroyed within the initial
142 * synchronization period can wind up not doing any disk I/O at all.
143 *
144 * Finally, an inode may cache numerous disk-referencing B-Tree cursors.
8750964d
MD
145 */
146struct hammer_ino_rb_tree;
147struct hammer_inode;
148RB_HEAD(hammer_ino_rb_tree, hammer_inode);
149RB_PROTOTYPEX(hammer_ino_rb_tree, INFO, hammer_inode, rb_node,
8cd0a023
MD
150 hammer_ino_rb_compare, hammer_inode_info_t);
151
152struct hammer_rec_rb_tree;
153struct hammer_record;
154RB_HEAD(hammer_rec_rb_tree, hammer_record);
155RB_PROTOTYPEX(hammer_rec_rb_tree, INFO, hammer_record, rb_node,
156 hammer_rec_rb_compare, hammer_base_elm_t);
157
158TAILQ_HEAD(hammer_node_list, hammer_node);
8750964d
MD
159
160struct hammer_inode {
161 RB_ENTRY(hammer_inode) rb_node;
162 u_int64_t obj_id; /* (key) object identifier */
163 hammer_tid_t obj_asof; /* (key) snapshot transid or 0 */
8cd0a023 164 hammer_tid_t last_tid; /* last modified tid (for fsync) */
66325755
MD
165 struct hammer_mount *hmp;
166 int flags;
c60bb2c5 167 struct vnode *vp;
66325755 168 struct lockf advlock;
8cd0a023 169 struct hammer_lock lock;
c60bb2c5
MD
170 struct hammer_inode_record ino_rec;
171 struct hammer_inode_data ino_data;
8cd0a023 172 struct hammer_rec_rb_tree rec_tree; /* red-black record tree */
61aeeb33 173 struct hammer_node *cache[2]; /* search initiate cache */
8750964d
MD
174};
175
8cd0a023
MD
176typedef struct hammer_inode *hammer_inode_t;
177
66325755
MD
178#define VTOI(vp) ((struct hammer_inode *)(vp)->v_data)
179
8cd0a023
MD
180#define HAMMER_INODE_DDIRTY 0x0001 /* in-memory ino_data is dirty */
181#define HAMMER_INODE_RDIRTY 0x0002 /* in-memory ino_rec is dirty */
182#define HAMMER_INODE_ITIMES 0x0004 /* in-memory mtime/atime modified */
d113fda1 183#define HAMMER_INODE_XDIRTY 0x0008 /* in-memory records present */
8cd0a023 184#define HAMMER_INODE_ONDISK 0x0010 /* inode is on-disk (else not yet) */
a89aec1b 185#define HAMMER_INODE_FLUSH 0x0020 /* flush on last ref */
c0ade690 186#define HAMMER_INODE_DELETED 0x0080 /* inode ready for deletion */
76376933 187#define HAMMER_INODE_DELONDISK 0x0100 /* delete synchronized to disk */
d113fda1
MD
188#define HAMMER_INODE_RO 0x0200 /* read-only (because of as-of) */
189#define HAMMER_INODE_GONE 0x0400 /* delete flushed out */
0a72edae 190#define HAMMER_INODE_DONDISK 0x0800 /* data records may be on disk */
f3b0f382 191#define HAMMER_INODE_BUFS 0x1000 /* dirty high level bps present */
42c7d26b 192#define HAMMER_INODE_TIDLOCKED 0x2000 /* tid locked until inode synced */
8cd0a023 193
0b075555 194#define HAMMER_INODE_MODMASK (HAMMER_INODE_DDIRTY|HAMMER_INODE_RDIRTY| \
f3b0f382 195 HAMMER_INODE_XDIRTY|HAMMER_INODE_BUFS| \
d113fda1 196 HAMMER_INODE_ITIMES|HAMMER_INODE_DELETED)
0b075555 197
8cd0a023 198#define HAMMER_MAX_INODE_CURSORS 4
66325755 199
8750964d 200/*
8cd0a023
MD
201 * Structure used to represent an unsynchronized record in-memory. This
202 * structure is orgranized in a per-inode RB-tree. If the inode is not
203 * on disk then neither are any records and the in-memory record tree
204 * represents the entire contents of the inode. If the inode is on disk
205 * then the on-disk B-Tree is scanned in parallel with the in-memory
206 * RB-Tree to synthesize the current state of the file.
207 *
208 * Only current (delete_tid == 0) unsynchronized records are kept in-memory.
b33e2cc0
MD
209 *
210 * blocked is the count of the number of cursors (ip_first/ip_next) blocked
211 * on the record waiting for a synchronization to complete.
8750964d 212 */
8cd0a023
MD
213struct hammer_record {
214 RB_ENTRY(hammer_record) rb_node;
a89aec1b 215 struct hammer_lock lock;
8cd0a023
MD
216 struct hammer_inode *ip;
217 union hammer_record_ondisk rec;
218 union hammer_data_ondisk *data;
8cd0a023 219 int flags;
47197d71 220 int rec_len;
b33e2cc0 221 int blocked;
8cd0a023 222};
8750964d 223
8cd0a023
MD
224typedef struct hammer_record *hammer_record_t;
225
226#define HAMMER_RECF_ALLOCDATA 0x0001
227#define HAMMER_RECF_ONRBTREE 0x0002
a89aec1b 228#define HAMMER_RECF_DELETED 0x0004
47197d71 229#define HAMMER_RECF_UNUSED0008 0x0008
b3deaf57 230#define HAMMER_RECF_SYNCING 0x0010
b33e2cc0 231#define HAMMER_RECF_WANTED 0x0020
8cd0a023
MD
232
233/*
47197d71 234 * In-memory structures representing on-disk structures.
8cd0a023 235 */
8750964d 236struct hammer_volume;
427e5fc6 237struct hammer_buffer;
8cd0a023 238struct hammer_node;
8750964d 239RB_HEAD(hammer_vol_rb_tree, hammer_volume);
427e5fc6 240RB_HEAD(hammer_buf_rb_tree, hammer_buffer);
8cd0a023 241RB_HEAD(hammer_nod_rb_tree, hammer_node);
8750964d
MD
242
243RB_PROTOTYPE2(hammer_vol_rb_tree, hammer_volume, rb_node,
244 hammer_vol_rb_compare, int32_t);
427e5fc6 245RB_PROTOTYPE2(hammer_buf_rb_tree, hammer_buffer, rb_node,
47197d71 246 hammer_buf_rb_compare, hammer_off_t);
8cd0a023 247RB_PROTOTYPE2(hammer_nod_rb_tree, hammer_node, rb_node,
47197d71 248 hammer_nod_rb_compare, hammer_off_t);
8750964d 249
66325755
MD
250/*
251 * IO management - embedded at the head of various in-memory structures
252 */
253enum hammer_io_type { HAMMER_STRUCTURE_VOLUME,
66325755
MD
254 HAMMER_STRUCTURE_BUFFER };
255
256union hammer_io_structure;
055f5ff8 257struct hammer_io;
66325755
MD
258
259struct worklist {
260 LIST_ENTRY(worklist) node;
261};
262
055f5ff8
MD
263TAILQ_HEAD(hammer_io_list, hammer_io);
264
66325755
MD
265struct hammer_io {
266 struct worklist worklist;
267 struct hammer_lock lock;
268 enum hammer_io_type type;
269 struct buf *bp;
270 int64_t offset;
055f5ff8
MD
271 TAILQ_ENTRY(hammer_io) entry; /* based on modified flag */
272 struct hammer_io_list *entry_list;
273 struct hammer_io_list deplist;
66325755
MD
274 u_int modified : 1; /* bp's data was modified */
275 u_int released : 1; /* bp released (w/ B_LOCKED set) */
055f5ff8
MD
276 u_int running : 1; /* bp write IO in progress */
277 u_int waiting : 1; /* someone is waiting on us */
eaeff70d 278 u_int loading : 1; /* ondisk is loading */
b33e2cc0 279 u_int validated : 1; /* ondisk has been validated */
66325755
MD
280};
281
8cd0a023
MD
282typedef struct hammer_io *hammer_io_t;
283
66325755 284/*
8cd0a023 285 * In-memory volume representing on-disk buffer
66325755 286 */
8750964d 287struct hammer_volume {
66325755 288 struct hammer_io io;
8750964d 289 RB_ENTRY(hammer_volume) rb_node;
47197d71
MD
290 struct hammer_nod_rb_tree rb_nods_root;
291 struct hammer_buf_rb_tree rb_bufs_root;
8750964d
MD
292 struct hammer_volume_ondisk *ondisk;
293 int32_t vol_no;
fbc6e32a 294 int64_t nblocks; /* note: special calculation for statfs */
47197d71
MD
295 int64_t buffer_base; /* base offset of buffer 0 */
296 hammer_off_t maxbuf_off; /* Maximum buffer offset */
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
MD
306 * In-memory buffer (other then volume, super-cluster, or cluster),
307 * representing an on-disk buffer.
66325755 308 */
427e5fc6 309struct hammer_buffer {
66325755 310 struct hammer_io io;
427e5fc6 311 RB_ENTRY(hammer_buffer) rb_node;
47197d71 312 void *ondisk;
427e5fc6 313 struct hammer_volume *volume;
47197d71 314 hammer_off_t buf_offset;
8cd0a023 315 struct hammer_node_list clist;
66325755
MD
316};
317
8cd0a023
MD
318typedef struct hammer_buffer *hammer_buffer_t;
319
320/*
321 * In-memory B-Tree node, representing an on-disk B-Tree node.
322 *
323 * This is a hang-on structure which is backed by a hammer_buffer,
324 * indexed by a hammer_cluster, and used for fine-grained locking of
325 * B-Tree nodes in order to properly control lock ordering. A hammer_buffer
326 * can contain multiple nodes representing wildly disassociated portions
327 * of the B-Tree so locking cannot be done on a buffer-by-buffer basis.
328 *
329 * This structure uses a cluster-relative index to reduce the number
330 * of layers required to access it, and also because all on-disk B-Tree
331 * references are cluster-relative offsets.
332 */
333struct hammer_node {
334 struct hammer_lock lock; /* node-by-node lock */
335 TAILQ_ENTRY(hammer_node) entry; /* per-buffer linkage */
336 RB_ENTRY(hammer_node) rb_node; /* per-cluster linkage */
47197d71 337 hammer_off_t node_offset; /* full offset spec */
8cd0a023 338 struct hammer_buffer *buffer; /* backing buffer */
47197d71 339 struct hammer_volume *volume; /* backing volume */
8cd0a023
MD
340 hammer_node_ondisk_t ondisk; /* ptr to on-disk structure */
341 struct hammer_node **cache1; /* passive cache(s) */
342 struct hammer_node **cache2;
b3deaf57 343 int flags;
8cd0a023
MD
344};
345
b3deaf57
MD
346#define HAMMER_NODE_DELETED 0x0001
347#define HAMMER_NODE_FLUSH 0x0002
b3deaf57 348
8cd0a023
MD
349typedef struct hammer_node *hammer_node_t;
350
b33e2cc0
MD
351/*
352 * List of locked nodes.
353 */
354struct hammer_node_locklist {
355 struct hammer_node_locklist *next;
356 hammer_node_t node;
357};
358
359typedef struct hammer_node_locklist *hammer_node_locklist_t;
360
361
8cd0a023
MD
362/*
363 * Common I/O management structure - embedded in in-memory structures
364 * which are backed by filesystem buffers.
365 */
66325755
MD
366union hammer_io_structure {
367 struct hammer_io io;
368 struct hammer_volume volume;
66325755 369 struct hammer_buffer buffer;
8750964d
MD
370};
371
055f5ff8
MD
372typedef union hammer_io_structure *hammer_io_structure_t;
373
427e5fc6
MD
374#define HAMFS_CLUSTER_DIRTY 0x0001
375
8cd0a023
MD
376#include "hammer_cursor.h"
377
8750964d
MD
378/*
379 * Internal hammer mount data structure
380 */
381struct hammer_mount {
382 struct mount *mp;
27ea2398 383 /*struct vnode *rootvp;*/
8750964d
MD
384 struct hammer_ino_rb_tree rb_inos_root;
385 struct hammer_vol_rb_tree rb_vols_root;
386 struct hammer_volume *rootvol;
47197d71
MD
387 struct hammer_base_elm root_btree_beg;
388 struct hammer_base_elm root_btree_end;
d26d0ae9 389 char *zbuf; /* HAMMER_BUFSIZE bytes worth of all-zeros */
195c19a1
MD
390 int hflags;
391 int ronly;
392 int nvolumes;
d26d0ae9 393 int volume_iterator;
8750964d 394 uuid_t fsid;
66325755 395 udev_t fsid_udev;
7f7c1f84 396 hammer_tid_t asof;
66325755 397 u_int32_t namekey_iterator;
513ca7d7 398 struct netexport export;
8750964d
MD
399};
400
8cd0a023 401typedef struct hammer_mount *hammer_mount_t;
8750964d 402
fbc6e32a
MD
403struct hammer_sync_info {
404 int error;
405 int waitfor;
406};
407
8750964d
MD
408#endif
409
410#if defined(_KERNEL)
411
412extern struct vop_ops hammer_vnode_vops;
7a04d74f
MD
413extern struct vop_ops hammer_spec_vops;
414extern struct vop_ops hammer_fifo_vops;
66325755 415extern struct bio_ops hammer_bioops;
427e5fc6 416
d5ef456e 417extern int hammer_debug_general;
b3deaf57 418extern int hammer_debug_btree;
d113fda1 419extern int hammer_debug_tid;
b33e2cc0 420extern int hammer_debug_recover;
46fe7ae1 421extern int hammer_debug_recover_faults;
b3deaf57
MD
422extern int hammer_count_inodes;
423extern int hammer_count_records;
424extern int hammer_count_record_datas;
425extern int hammer_count_volumes;
b3deaf57
MD
426extern int hammer_count_buffers;
427extern int hammer_count_nodes;
b3deaf57 428
8750964d
MD
429int hammer_vop_inactive(struct vop_inactive_args *);
430int hammer_vop_reclaim(struct vop_reclaim_args *);
66325755
MD
431int hammer_get_vnode(struct hammer_inode *ip, int lktype,
432 struct vnode **vpp);
8cd0a023 433struct hammer_inode *hammer_get_inode(hammer_mount_t hmp,
61aeeb33 434 struct hammer_node **cache,
d113fda1
MD
435 u_int64_t obj_id, hammer_tid_t asof, int flags,
436 int *errorp);
66325755
MD
437void hammer_put_inode(struct hammer_inode *ip);
438void hammer_put_inode_ref(struct hammer_inode *ip);
439
d113fda1 440int hammer_unload_inode(hammer_inode_t ip, void *data);
8cd0a023 441int hammer_unload_volume(hammer_volume_t volume, void *data __unused);
a89aec1b 442int hammer_unload_buffer(hammer_buffer_t buffer, void *data __unused);
8cd0a023
MD
443int hammer_install_volume(hammer_mount_t hmp, const char *volname);
444
a89aec1b
MD
445int hammer_ip_lookup(hammer_cursor_t cursor, hammer_inode_t ip);
446int hammer_ip_first(hammer_cursor_t cursor, hammer_inode_t ip);
447int hammer_ip_next(hammer_cursor_t cursor);
8cd0a023 448int hammer_ip_resolve_data(hammer_cursor_t cursor);
195c19a1 449int hammer_ip_delete_record(hammer_cursor_t cursor, hammer_tid_t tid);
7dc57964 450int hammer_delete_at_cursor(hammer_cursor_t cursor, int64_t *stat_bytes);
b3deaf57
MD
451int hammer_ip_check_directory_empty(hammer_transaction_t trans,
452 hammer_inode_t ip);
fbc6e32a
MD
453int hammer_sync_hmp(hammer_mount_t hmp, int waitfor);
454int hammer_sync_volume(hammer_volume_t volume, void *data);
fbc6e32a
MD
455int hammer_sync_buffer(hammer_buffer_t buffer, void *data);
456
8cd0a023 457hammer_record_t
47197d71 458 hammer_alloc_mem_record(hammer_inode_t ip, int32_t rec_len);
b3deaf57 459void hammer_rel_mem_record(hammer_record_t record);
8cd0a023 460
6a37e7e4 461int hammer_cursor_up(hammer_cursor_t cursor);
8cd0a023 462int hammer_cursor_down(hammer_cursor_t cursor);
6a37e7e4
MD
463int hammer_cursor_upgrade(hammer_cursor_t cursor);
464void hammer_cursor_downgrade(hammer_cursor_t cursor);
32c90105
MD
465int hammer_cursor_seek(hammer_cursor_t cursor, hammer_node_t node,
466 int index);
8cd0a023
MD
467void hammer_lock_ex(struct hammer_lock *lock);
468int hammer_lock_ex_try(struct hammer_lock *lock);
469void hammer_lock_sh(struct hammer_lock *lock);
6a37e7e4
MD
470int hammer_lock_upgrade(struct hammer_lock *lock);
471void hammer_lock_downgrade(struct hammer_lock *lock);
427e5fc6 472void hammer_unlock(struct hammer_lock *lock);
66325755
MD
473void hammer_ref(struct hammer_lock *lock);
474void hammer_unref(struct hammer_lock *lock);
8cd0a023 475
66325755 476u_int32_t hammer_to_unix_xid(uuid_t *uuid);
8cd0a023
MD
477void hammer_guid_to_uuid(uuid_t *uuid, u_int32_t guid);
478void hammer_to_timespec(hammer_tid_t tid, struct timespec *ts);
479hammer_tid_t hammer_timespec_to_transid(struct timespec *ts);
a89aec1b 480hammer_tid_t hammer_alloc_tid(hammer_transaction_t trans);
7f7c1f84 481hammer_tid_t hammer_now_tid(void);
d113fda1 482hammer_tid_t hammer_str_to_tid(const char *str);
8cd0a023 483
66325755 484enum vtype hammer_get_vnode_type(u_int8_t obj_type);
6b4f890b 485int hammer_get_dtype(u_int8_t obj_type);
66325755
MD
486u_int8_t hammer_get_obj_type(enum vtype vtype);
487int64_t hammer_directory_namekey(void *name, int len);
427e5fc6 488
47197d71
MD
489int hammer_init_cursor_hmp(hammer_cursor_t cursor,
490 struct hammer_node **cache, hammer_mount_t hmp);
195c19a1 491
8cd0a023 492void hammer_done_cursor(hammer_cursor_t cursor);
6b4f890b 493void hammer_mem_done(hammer_cursor_t cursor);
8cd0a023
MD
494
495int hammer_btree_lookup(hammer_cursor_t cursor);
d26d0ae9 496int hammer_btree_first(hammer_cursor_t cursor);
32c90105 497int hammer_btree_last(hammer_cursor_t cursor);
8cd0a023
MD
498int hammer_btree_extract(hammer_cursor_t cursor, int flags);
499int hammer_btree_iterate(hammer_cursor_t cursor);
32c90105 500int hammer_btree_iterate_reverse(hammer_cursor_t cursor);
8cd0a023
MD
501int hammer_btree_insert(hammer_cursor_t cursor, hammer_btree_elm_t elm);
502int hammer_btree_delete(hammer_cursor_t cursor);
503int hammer_btree_cmp(hammer_base_elm_t key1, hammer_base_elm_t key2);
d26d0ae9 504int hammer_btree_chkts(hammer_tid_t ts, hammer_base_elm_t key);
32c90105
MD
505int hammer_btree_correct_rhb(hammer_cursor_t cursor, hammer_tid_t tid);
506int hammer_btree_correct_lhb(hammer_cursor_t cursor, hammer_tid_t tid);
507
fe7678ee 508
b33e2cc0
MD
509int hammer_btree_lock_children(hammer_cursor_t cursor,
510 struct hammer_node_locklist **locklistp);
511void hammer_btree_unlock_children(struct hammer_node_locklist **locklistp);
512
c0ade690
MD
513void hammer_print_btree_node(hammer_node_ondisk_t ondisk);
514void hammer_print_btree_elm(hammer_btree_elm_t elm, u_int8_t type, int i);
8750964d 515
47197d71
MD
516void *hammer_bread(struct hammer_mount *hmp, hammer_off_t off,
517 int *errorp, struct hammer_buffer **bufferp);
518void *hammer_bnew(struct hammer_mount *hmp, hammer_off_t off,
519 int *errorp, struct hammer_buffer **bufferp);
8cd0a023
MD
520
521hammer_volume_t hammer_get_root_volume(hammer_mount_t hmp, int *errorp);
427e5fc6 522
8cd0a023 523hammer_volume_t hammer_get_volume(hammer_mount_t hmp,
427e5fc6 524 int32_t vol_no, int *errorp);
47197d71
MD
525hammer_buffer_t hammer_get_buffer(hammer_mount_t hmp,
526 hammer_off_t buf_offset, int isnew, int *errorp);
8cd0a023 527
fbc6e32a 528int hammer_ref_volume(hammer_volume_t volume);
8cd0a023
MD
529int hammer_ref_buffer(hammer_buffer_t buffer);
530void hammer_flush_buffer_nodes(hammer_buffer_t buffer);
531
8cd0a023 532void hammer_rel_volume(hammer_volume_t volume, int flush);
8cd0a023
MD
533void hammer_rel_buffer(hammer_buffer_t buffer, int flush);
534
513ca7d7
MD
535int hammer_vfs_export(struct mount *mp, int op,
536 const struct export_args *export);
47197d71
MD
537hammer_node_t hammer_get_node(hammer_mount_t hmp,
538 hammer_off_t node_offset, int *errorp);
8cd0a023 539int hammer_ref_node(hammer_node_t node);
055f5ff8
MD
540hammer_node_t hammer_ref_node_safe(struct hammer_mount *hmp,
541 struct hammer_node **cache, int *errorp);
8cd0a023
MD
542void hammer_rel_node(hammer_node_t node);
543void hammer_cache_node(hammer_node_t node,
544 struct hammer_node **cache);
545void hammer_uncache_node(struct hammer_node **cache);
546void hammer_flush_node(hammer_node_t node);
547
427e5fc6
MD
548void hammer_dup_buffer(struct hammer_buffer **bufferp,
549 struct hammer_buffer *buffer);
47197d71
MD
550hammer_node_t hammer_alloc_btree(hammer_mount_t hmp, int *errorp);
551void *hammer_alloc_record(hammer_mount_t hmp,
552 hammer_off_t *rec_offp, u_int8_t rec_type,
553 int32_t rec_len, struct hammer_buffer **rec_bufferp,
554 hammer_off_t *data_offp, int32_t data_len,
555 void **data1p, void **data2p, int32_t *data2_index,
556 struct hammer_buffer **data2_bufferp,
557 int *errorp);
558void hammer_free_fifo(hammer_mount_t hmp, hammer_off_t fifo_offset);
559void hammer_unwind_fifo(hammer_mount_t hmp, hammer_off_t rec_offset);
560void hammer_init_fifo(hammer_fifo_head_t head, u_int16_t type);
561int hammer_generate_undo(hammer_mount_t hmp, hammer_off_t undo_offset,
562 void *base, int len);
427e5fc6 563
66325755 564void hammer_put_volume(struct hammer_volume *volume, int flush);
66325755 565void hammer_put_buffer(struct hammer_buffer *buffer, int flush);
427e5fc6 566
8cd0a023
MD
567void hammer_start_transaction(struct hammer_transaction *trans,
568 struct hammer_mount *hmp);
d113fda1
MD
569void hammer_start_transaction_tid(struct hammer_transaction *trans,
570 struct hammer_mount *hmp, hammer_tid_t tid);
66325755
MD
571void hammer_commit_transaction(struct hammer_transaction *trans);
572void hammer_abort_transaction(struct hammer_transaction *trans);
573
574void hammer_modify_inode(struct hammer_transaction *trans,
8cd0a023
MD
575 hammer_inode_t ip, int flags);
576int hammer_create_inode(struct hammer_transaction *trans, struct vattr *vap,
577 struct ucred *cred, struct hammer_inode *dip,
578 struct hammer_inode **ipp);
a89aec1b 579void hammer_rel_inode(hammer_inode_t ip, int flush);
c0ade690 580int hammer_sync_inode(hammer_inode_t ip, int waitfor, int handle_delete);
8cd0a023 581
a89aec1b 582int hammer_ip_add_directory(struct hammer_transaction *trans,
8cd0a023
MD
583 hammer_inode_t dip, struct namecache *ncp,
584 hammer_inode_t nip);
a89aec1b 585int hammer_ip_del_directory(struct hammer_transaction *trans,
8cd0a023
MD
586 hammer_cursor_t cursor, hammer_inode_t dip,
587 hammer_inode_t ip);
7a04d74f
MD
588int hammer_ip_add_record(struct hammer_transaction *trans,
589 hammer_record_t record);
a89aec1b 590int hammer_ip_delete_range(struct hammer_transaction *trans,
47197d71 591 hammer_inode_t ip, int64_t ran_beg, int64_t ran_end);
7a04d74f
MD
592int hammer_ip_delete_range_all(struct hammer_transaction *trans,
593 hammer_inode_t ip);
c0ade690 594int hammer_ip_sync_data(struct hammer_transaction *trans,
8cd0a023 595 hammer_inode_t ip, int64_t offset,
47197d71
MD
596 void *data, int bytes);
597int hammer_ip_sync_record(hammer_record_t rec);
d26d0ae9 598int hammer_write_record(hammer_cursor_t cursor, hammer_record_ondisk_t rec,
47197d71 599 int32_t rec_len, void *data, int cursor_flags);
66325755 600
7dc57964
MD
601int hammer_ioctl(hammer_inode_t ip, u_long com, caddr_t data, int fflag,
602 struct ucred *cred);
603
055f5ff8 604void hammer_io_init(hammer_io_t io, enum hammer_io_type type);
66325755
MD
605int hammer_io_read(struct vnode *devvp, struct hammer_io *io);
606int hammer_io_new(struct vnode *devvp, struct hammer_io *io);
607void hammer_io_release(struct hammer_io *io, int flush);
055f5ff8 608void hammer_io_flush(struct hammer_io *io);
8cd0a023 609int hammer_io_checkflush(hammer_io_t io);
61aeeb33 610void hammer_io_clear_modify(struct hammer_io *io);
055f5ff8 611void hammer_io_waitdep(struct hammer_io *io);
66325755 612
47197d71
MD
613void hammer_modify_volume(hammer_volume_t volume, void *base, int len);
614void hammer_modify_buffer(hammer_buffer_t buffer, void *base, int len);
0b075555 615
055f5ff8 616#endif
427e5fc6 617
8cd0a023
MD
618static __inline void
619hammer_modify_node(struct hammer_node *node)
620{
47197d71 621 hammer_modify_buffer(node->buffer, node->ondisk, sizeof(*node->ondisk));
427e5fc6
MD
622}
623