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