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