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