FC path inquiry settings.
[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 *
8cd0a023 34 * $DragonFly: src/sys/vfs/hammer/hammer.h,v 1.6 2007/11/19 00:53:40 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;
81};
82
8cd0a023
MD
83typedef struct hammer_transaction *hammer_transaction_t;
84
66325755
MD
85/*
86 * HAMMER locks
87 */
427e5fc6
MD
88struct hammer_lock {
89 int refs;
8cd0a023 90 int lockcount;
427e5fc6
MD
91 int wanted;
92 struct thread *locktd;
8750964d
MD
93};
94
427e5fc6
MD
95static __inline int
96hammer_islocked(struct hammer_lock *lock)
97{
8cd0a023 98 return(lock->lockcount != 0);
427e5fc6
MD
99}
100
101static __inline int
102hammer_islastref(struct hammer_lock *lock)
103{
104 return(lock->refs == 1);
105}
c60bb2c5 106
8750964d 107/*
8cd0a023
MD
108 * Structure used to represent an inode in-memory.
109 *
110 * The record and data associated with an inode may be out of sync with
111 * the disk (xDIRTY flags), or not even on the disk at all (ONDISK flag
112 * clear).
113 *
114 * An inode may also hold a cache of unsynchronized records, used for
115 * database and directories only. Unsynchronized regular file data is
116 * stored in the buffer cache.
117 *
118 * NOTE: A file which is created and destroyed within the initial
119 * synchronization period can wind up not doing any disk I/O at all.
120 *
121 * Finally, an inode may cache numerous disk-referencing B-Tree cursors.
8750964d
MD
122 */
123struct hammer_ino_rb_tree;
124struct hammer_inode;
125RB_HEAD(hammer_ino_rb_tree, hammer_inode);
126RB_PROTOTYPEX(hammer_ino_rb_tree, INFO, hammer_inode, rb_node,
8cd0a023
MD
127 hammer_ino_rb_compare, hammer_inode_info_t);
128
129struct hammer_rec_rb_tree;
130struct hammer_record;
131RB_HEAD(hammer_rec_rb_tree, hammer_record);
132RB_PROTOTYPEX(hammer_rec_rb_tree, INFO, hammer_record, rb_node,
133 hammer_rec_rb_compare, hammer_base_elm_t);
134
135TAILQ_HEAD(hammer_node_list, hammer_node);
8750964d
MD
136
137struct hammer_inode {
138 RB_ENTRY(hammer_inode) rb_node;
139 u_int64_t obj_id; /* (key) object identifier */
140 hammer_tid_t obj_asof; /* (key) snapshot transid or 0 */
8cd0a023 141 hammer_tid_t last_tid; /* last modified tid (for fsync) */
66325755
MD
142 struct hammer_mount *hmp;
143 int flags;
c60bb2c5 144 struct vnode *vp;
66325755 145 struct lockf advlock;
8cd0a023 146 struct hammer_lock lock;
c60bb2c5
MD
147 struct hammer_inode_record ino_rec;
148 struct hammer_inode_data ino_data;
8cd0a023
MD
149 struct hammer_rec_rb_tree rec_tree; /* red-black record tree */
150 struct hammer_node *cache; /* cached B-Tree node shortcut */
8750964d
MD
151};
152
8cd0a023
MD
153typedef struct hammer_inode *hammer_inode_t;
154
66325755
MD
155#define VTOI(vp) ((struct hammer_inode *)(vp)->v_data)
156
8cd0a023
MD
157#define HAMMER_INODE_DDIRTY 0x0001 /* in-memory ino_data is dirty */
158#define HAMMER_INODE_RDIRTY 0x0002 /* in-memory ino_rec is dirty */
159#define HAMMER_INODE_ITIMES 0x0004 /* in-memory mtime/atime modified */
160#define HAMMER_INODE_ONDISK 0x0010 /* inode is on-disk (else not yet) */
161
162#define HAMMER_MAX_INODE_CURSORS 4
66325755 163
8750964d 164/*
8cd0a023
MD
165 * Structure used to represent an unsynchronized record in-memory. This
166 * structure is orgranized in a per-inode RB-tree. If the inode is not
167 * on disk then neither are any records and the in-memory record tree
168 * represents the entire contents of the inode. If the inode is on disk
169 * then the on-disk B-Tree is scanned in parallel with the in-memory
170 * RB-Tree to synthesize the current state of the file.
171 *
172 * Only current (delete_tid == 0) unsynchronized records are kept in-memory.
8750964d 173 */
8cd0a023
MD
174struct hammer_record {
175 RB_ENTRY(hammer_record) rb_node;
176 hammer_tid_t last_tid;
177 struct hammer_inode *ip;
178 union hammer_record_ondisk rec;
179 union hammer_data_ondisk *data;
180 int32_t data_len;
181 int flags;
182};
8750964d 183
8cd0a023
MD
184typedef struct hammer_record *hammer_record_t;
185
186#define HAMMER_RECF_ALLOCDATA 0x0001
187#define HAMMER_RECF_ONRBTREE 0x0002
188#define HAMMER_RECF_DELETION 0x0004 /* placemark a deletion */
189
190/*
191 * Structures used to internally represent a volume and a cluster
192 */
8750964d
MD
193struct hammer_volume;
194struct hammer_cluster;
427e5fc6
MD
195struct hammer_supercl;
196struct hammer_buffer;
8cd0a023 197struct hammer_node;
8750964d
MD
198RB_HEAD(hammer_vol_rb_tree, hammer_volume);
199RB_HEAD(hammer_clu_rb_tree, hammer_cluster);
427e5fc6
MD
200RB_HEAD(hammer_scl_rb_tree, hammer_supercl);
201RB_HEAD(hammer_buf_rb_tree, hammer_buffer);
8cd0a023 202RB_HEAD(hammer_nod_rb_tree, hammer_node);
8750964d
MD
203
204RB_PROTOTYPE2(hammer_vol_rb_tree, hammer_volume, rb_node,
205 hammer_vol_rb_compare, int32_t);
206RB_PROTOTYPE2(hammer_clu_rb_tree, hammer_cluster, rb_node,
207 hammer_clu_rb_compare, int32_t);
427e5fc6
MD
208RB_PROTOTYPE2(hammer_scl_rb_tree, hammer_supercl, rb_node,
209 hammer_scl_rb_compare, int32_t);
210RB_PROTOTYPE2(hammer_buf_rb_tree, hammer_buffer, rb_node,
211 hammer_buf_rb_compare, int32_t);
8cd0a023
MD
212RB_PROTOTYPE2(hammer_nod_rb_tree, hammer_node, rb_node,
213 hammer_nod_rb_compare, int32_t);
8750964d 214
66325755
MD
215/*
216 * IO management - embedded at the head of various in-memory structures
217 */
218enum hammer_io_type { HAMMER_STRUCTURE_VOLUME,
219 HAMMER_STRUCTURE_SUPERCL,
220 HAMMER_STRUCTURE_CLUSTER,
221 HAMMER_STRUCTURE_BUFFER };
222
223union hammer_io_structure;
224
225struct worklist {
226 LIST_ENTRY(worklist) node;
227};
228
229struct hammer_io {
230 struct worklist worklist;
231 struct hammer_lock lock;
232 enum hammer_io_type type;
233 struct buf *bp;
234 int64_t offset;
235 u_int modified : 1; /* bp's data was modified */
236 u_int released : 1; /* bp released (w/ B_LOCKED set) */
237};
238
8cd0a023
MD
239typedef struct hammer_io *hammer_io_t;
240
66325755 241/*
8cd0a023 242 * In-memory volume representing on-disk buffer
66325755 243 */
8750964d 244struct hammer_volume {
66325755 245 struct hammer_io io;
8750964d
MD
246 RB_ENTRY(hammer_volume) rb_node;
247 struct hammer_clu_rb_tree rb_clus_root;
427e5fc6 248 struct hammer_scl_rb_tree rb_scls_root;
8750964d 249 struct hammer_volume_ondisk *ondisk;
427e5fc6 250 struct hammer_alist_live alist;
8750964d
MD
251 int32_t vol_no;
252 int32_t vol_clsize;
253 int64_t cluster_base; /* base offset of cluster 0 */
c60bb2c5 254 char *vol_name;
8750964d
MD
255 struct vnode *devvp;
256 struct hammer_mount *hmp;
427e5fc6 257 int vol_flags;
8750964d
MD
258};
259
8cd0a023
MD
260typedef struct hammer_volume *hammer_volume_t;
261
66325755 262/*
8cd0a023 263 * In-memory super-cluster representing on-disk buffer
66325755 264 */
427e5fc6 265struct hammer_supercl {
66325755 266 struct hammer_io io;
427e5fc6 267 RB_ENTRY(hammer_supercl) rb_node;
427e5fc6
MD
268 struct hammer_supercl_ondisk *ondisk;
269 struct hammer_volume *volume;
270 struct hammer_alist_live alist;
271 int32_t scl_no;
427e5fc6 272};
c60bb2c5 273
8cd0a023
MD
274typedef struct hammer_supercl *hammer_supercl_t;
275
66325755 276/*
8cd0a023
MD
277 * In-memory cluster representing on-disk buffer
278 *
279 * The cluster's indexing range is cached in hammer_cluster, separate
280 * from the ondisk info in order to allow cursors to point to it.
66325755 281 */
8750964d 282struct hammer_cluster {
66325755 283 struct hammer_io io;
8750964d 284 RB_ENTRY(hammer_cluster) rb_node;
427e5fc6 285 struct hammer_buf_rb_tree rb_bufs_root;
8750964d
MD
286 struct hammer_cluster_ondisk *ondisk;
287 struct hammer_volume *volume;
427e5fc6
MD
288 struct hammer_alist_live alist_master;
289 struct hammer_alist_live alist_btree;
290 struct hammer_alist_live alist_record;
291 struct hammer_alist_live alist_mdata;
8cd0a023
MD
292 struct hammer_nod_rb_tree rb_nods_root; /* cursors in cluster */
293 struct hammer_base_elm clu_btree_beg; /* copy of on-disk info */
294 struct hammer_base_elm clu_btree_end; /* copy of on-disk info */
8750964d 295 int32_t clu_no;
427e5fc6
MD
296};
297
8cd0a023
MD
298typedef struct hammer_cluster *hammer_cluster_t;
299
66325755 300/*
8cd0a023
MD
301 * In-memory buffer (other then volume, super-cluster, or cluster),
302 * representing an on-disk buffer.
66325755 303 */
427e5fc6 304struct hammer_buffer {
66325755 305 struct hammer_io io;
427e5fc6 306 RB_ENTRY(hammer_buffer) rb_node;
427e5fc6 307 hammer_fsbuf_ondisk_t ondisk;
427e5fc6 308 struct hammer_volume *volume;
8cd0a023 309 struct hammer_cluster *cluster;
427e5fc6 310 int32_t buf_no;
8cd0a023
MD
311 u_int64_t buf_type;
312 struct hammer_alist_live alist;
313 struct hammer_node_list clist;
314 struct hammer_node *save_scan;
66325755
MD
315};
316
8cd0a023
MD
317typedef struct hammer_buffer *hammer_buffer_t;
318
319/*
320 * In-memory B-Tree node, representing an on-disk B-Tree node.
321 *
322 * This is a hang-on structure which is backed by a hammer_buffer,
323 * indexed by a hammer_cluster, and used for fine-grained locking of
324 * B-Tree nodes in order to properly control lock ordering. A hammer_buffer
325 * can contain multiple nodes representing wildly disassociated portions
326 * of the B-Tree so locking cannot be done on a buffer-by-buffer basis.
327 *
328 * This structure uses a cluster-relative index to reduce the number
329 * of layers required to access it, and also because all on-disk B-Tree
330 * references are cluster-relative offsets.
331 */
332struct hammer_node {
333 struct hammer_lock lock; /* node-by-node lock */
334 TAILQ_ENTRY(hammer_node) entry; /* per-buffer linkage */
335 RB_ENTRY(hammer_node) rb_node; /* per-cluster linkage */
336 int32_t node_offset; /* cluster-rel offset */
337 struct hammer_cluster *cluster;
338 struct hammer_buffer *buffer; /* backing buffer */
339 hammer_node_ondisk_t ondisk; /* ptr to on-disk structure */
340 struct hammer_node **cache1; /* passive cache(s) */
341 struct hammer_node **cache2;
342};
343
344typedef struct hammer_node *hammer_node_t;
345
346/*
347 * Common I/O management structure - embedded in in-memory structures
348 * which are backed by filesystem buffers.
349 */
66325755
MD
350union hammer_io_structure {
351 struct hammer_io io;
352 struct hammer_volume volume;
353 struct hammer_supercl supercl;
354 struct hammer_cluster cluster;
355 struct hammer_buffer buffer;
8750964d
MD
356};
357
427e5fc6
MD
358#define HAMFS_CLUSTER_DIRTY 0x0001
359
8cd0a023
MD
360#include "hammer_cursor.h"
361
8750964d
MD
362/*
363 * Internal hammer mount data structure
364 */
365struct hammer_mount {
366 struct mount *mp;
27ea2398 367 /*struct vnode *rootvp;*/
8750964d
MD
368 struct hammer_ino_rb_tree rb_inos_root;
369 struct hammer_vol_rb_tree rb_vols_root;
370 struct hammer_volume *rootvol;
371 struct hammer_cluster *rootcl;
66325755 372 char *zbuf; /* HAMMER_BUFSIZE bytes worth of all-zeros */
8750964d 373 uuid_t fsid;
66325755
MD
374 udev_t fsid_udev;
375 u_int32_t namekey_iterator;
8cd0a023
MD
376 hammer_tid_t last_tid; /* tid for transaction id */
377 hammer_tid_t last_ino; /* inode creation iterator */
8750964d
MD
378};
379
8cd0a023 380typedef struct hammer_mount *hammer_mount_t;
8750964d
MD
381
382#endif
383
384#if defined(_KERNEL)
385
386extern struct vop_ops hammer_vnode_vops;
427e5fc6
MD
387extern struct hammer_alist_config Buf_alist_config;
388extern struct hammer_alist_config Vol_normal_alist_config;
389extern struct hammer_alist_config Vol_super_alist_config;
390extern struct hammer_alist_config Supercl_alist_config;
391extern struct hammer_alist_config Clu_master_alist_config;
392extern struct hammer_alist_config Clu_slave_alist_config;
66325755 393extern struct bio_ops hammer_bioops;
427e5fc6 394
8750964d
MD
395int hammer_vop_inactive(struct vop_inactive_args *);
396int hammer_vop_reclaim(struct vop_reclaim_args *);
397int hammer_vfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp);
398
66325755
MD
399int hammer_get_vnode(struct hammer_inode *ip, int lktype,
400 struct vnode **vpp);
8cd0a023 401struct hammer_inode *hammer_get_inode(hammer_mount_t hmp,
66325755 402 u_int64_t obj_id, int *errorp);
66325755
MD
403void hammer_put_inode(struct hammer_inode *ip);
404void hammer_put_inode_ref(struct hammer_inode *ip);
405
8cd0a023
MD
406int hammer_unload_inode(hammer_inode_t ip, void *data __unused);
407int hammer_unload_volume(hammer_volume_t volume, void *data __unused);
408int hammer_install_volume(hammer_mount_t hmp, const char *volname);
409
410hammer_record_ondisk_t
411 hammer_ip_first(hammer_cursor_t cursor, hammer_inode_t ip);
412hammer_record_ondisk_t
413 hammer_ip_next(hammer_cursor_t cursor);
414int hammer_ip_resolve_data(hammer_cursor_t cursor);
415hammer_record_t
416 hammer_alloc_ip_record(struct hammer_transaction *trans,
417 hammer_inode_t ip);
418void hammer_free_ip_record(hammer_record_t record);
419
420int hammer_cursor_up(hammer_cursor_t cursor);
421int hammer_cursor_toroot(hammer_cursor_t cursor);
422int hammer_cursor_down(hammer_cursor_t cursor);
423
424void hammer_lock_ex(struct hammer_lock *lock);
425int hammer_lock_ex_try(struct hammer_lock *lock);
426void hammer_lock_sh(struct hammer_lock *lock);
427e5fc6 427void hammer_unlock(struct hammer_lock *lock);
66325755
MD
428void hammer_ref(struct hammer_lock *lock);
429void hammer_unref(struct hammer_lock *lock);
8cd0a023
MD
430void hammer_downgrade(struct hammer_lock *lock);
431
66325755 432u_int32_t hammer_to_unix_xid(uuid_t *uuid);
8cd0a023
MD
433void hammer_guid_to_uuid(uuid_t *uuid, u_int32_t guid);
434void hammer_to_timespec(hammer_tid_t tid, struct timespec *ts);
435hammer_tid_t hammer_timespec_to_transid(struct timespec *ts);
436
66325755
MD
437enum vtype hammer_get_vnode_type(u_int8_t obj_type);
438u_int8_t hammer_get_obj_type(enum vtype vtype);
439int64_t hammer_directory_namekey(void *name, int len);
427e5fc6 440
8cd0a023
MD
441int hammer_init_cursor_hmp(hammer_cursor_t cursor, hammer_mount_t hmp);
442int hammer_init_cursor_ip(hammer_cursor_t cursor, hammer_inode_t ip);
443void hammer_done_cursor(hammer_cursor_t cursor);
444
445int hammer_btree_lookup(hammer_cursor_t cursor);
446int hammer_btree_extract(hammer_cursor_t cursor, int flags);
447int hammer_btree_iterate(hammer_cursor_t cursor);
448int hammer_btree_insert(hammer_cursor_t cursor, hammer_btree_elm_t elm);
449int hammer_btree_delete(hammer_cursor_t cursor);
450int hammer_btree_cmp(hammer_base_elm_t key1, hammer_base_elm_t key2);
8750964d 451
c60bb2c5 452void *hammer_bread(struct hammer_cluster *cluster, int32_t cloff,
8cd0a023
MD
453 u_int64_t buf_type, int *errorp,
454 struct hammer_buffer **bufferp);
455
456hammer_volume_t hammer_get_root_volume(hammer_mount_t hmp, int *errorp);
457hammer_cluster_t hammer_get_root_cluster(hammer_mount_t hmp, int *errorp);
427e5fc6 458
8cd0a023 459hammer_volume_t hammer_get_volume(hammer_mount_t hmp,
427e5fc6 460 int32_t vol_no, int *errorp);
8cd0a023 461hammer_supercl_t hammer_get_supercl(hammer_volume_t volume,
427e5fc6 462 int32_t scl_no, int *errorp, int isnew);
8cd0a023 463hammer_cluster_t hammer_get_cluster(hammer_volume_t volume,
427e5fc6 464 int32_t clu_no, int *errorp, int isnew);
8cd0a023
MD
465hammer_buffer_t hammer_get_buffer(hammer_cluster_t cluster,
466 int32_t buf_no, u_int64_t buf_type, int *errorp);
467
468int hammer_ref_cluster(hammer_cluster_t cluster);
469int hammer_ref_buffer(hammer_buffer_t buffer);
470void hammer_flush_buffer_nodes(hammer_buffer_t buffer);
471
472
473void hammer_rel_volume(hammer_volume_t volume, int flush);
474void hammer_rel_supercl(hammer_supercl_t supercl, int flush);
475void hammer_rel_cluster(hammer_cluster_t cluster, int flush);
476void hammer_rel_buffer(hammer_buffer_t buffer, int flush);
477
478hammer_node_t hammer_get_node(hammer_cluster_t cluster,
479 int32_t node_offset, int *errorp);
480int hammer_ref_node(hammer_node_t node);
481void hammer_rel_node(hammer_node_t node);
482void hammer_cache_node(hammer_node_t node,
483 struct hammer_node **cache);
484void hammer_uncache_node(struct hammer_node **cache);
485void hammer_flush_node(hammer_node_t node);
486
66325755 487struct hammer_cluster *hammer_get_rootcl(struct hammer_mount *hmp);
427e5fc6
MD
488void hammer_dup_buffer(struct hammer_buffer **bufferp,
489 struct hammer_buffer *buffer);
490void hammer_dup_cluster(struct hammer_cluster **clusterp,
491 struct hammer_cluster *cluster);
8cd0a023 492hammer_node_t hammer_alloc_btree(struct hammer_cluster *cluster, int *errorp);
427e5fc6
MD
493void *hammer_alloc_data(struct hammer_cluster *cluster, int32_t bytes,
494 int *errorp, struct hammer_buffer **bufferp);
495void *hammer_alloc_record(struct hammer_cluster *cluster,
496 int *errorp, struct hammer_buffer **bufferp);
497void hammer_free_btree_ptr(struct hammer_buffer *buffer,
8cd0a023 498 hammer_node_ondisk_t node);
427e5fc6
MD
499void hammer_free_data_ptr(struct hammer_buffer *buffer,
500 void *data, int bytes);
501void hammer_free_record_ptr(struct hammer_buffer *buffer,
502 union hammer_record_ondisk *rec);
503void hammer_free_btree(struct hammer_cluster *cluster, int32_t bclu_offset);
504void hammer_free_data(struct hammer_cluster *cluster, int32_t bclu_offset,
505 int32_t bytes);
506void hammer_free_record(struct hammer_cluster *cluster, int32_t bclu_offset);
507
66325755
MD
508void hammer_put_volume(struct hammer_volume *volume, int flush);
509void hammer_put_supercl(struct hammer_supercl *supercl, int flush);
510void hammer_put_cluster(struct hammer_cluster *cluster, int flush);
511void hammer_put_buffer(struct hammer_buffer *buffer, int flush);
427e5fc6
MD
512
513void hammer_init_alist_config(void);
8750964d 514
8cd0a023
MD
515void hammer_start_transaction(struct hammer_transaction *trans,
516 struct hammer_mount *hmp);
66325755
MD
517void hammer_commit_transaction(struct hammer_transaction *trans);
518void hammer_abort_transaction(struct hammer_transaction *trans);
519
520void hammer_modify_inode(struct hammer_transaction *trans,
8cd0a023
MD
521 hammer_inode_t ip, int flags);
522int hammer_create_inode(struct hammer_transaction *trans, struct vattr *vap,
523 struct ucred *cred, struct hammer_inode *dip,
524 struct hammer_inode **ipp);
525void hammer_rel_inode(hammer_inode_t ip);
526
66325755 527int hammer_add_directory(struct hammer_transaction *trans,
8cd0a023
MD
528 hammer_inode_t dip, struct namecache *ncp,
529 hammer_inode_t nip);
530int hammer_del_directory(struct hammer_transaction *trans,
531 hammer_cursor_t cursor, hammer_inode_t dip,
532 hammer_inode_t ip);
533int hammer_delete_range(struct hammer_transaction *trans,
534 hammer_inode_t ip, int64_t off_beg, int64_t off_end);
535int hammer_add_data(struct hammer_transaction *trans,
536 hammer_inode_t ip, int64_t offset,
537 void *data, int bytes);
66325755
MD
538
539int hammer_io_read(struct vnode *devvp, struct hammer_io *io);
540int hammer_io_new(struct vnode *devvp, struct hammer_io *io);
541void hammer_io_release(struct hammer_io *io, int flush);
8cd0a023 542int hammer_io_checkflush(hammer_io_t io);
66325755 543
8750964d
MD
544#endif
545
427e5fc6
MD
546/*
547 * Inline support functions (not kernel specific)
548 */
549static __inline void
550hammer_modify_volume(struct hammer_volume *volume)
551{
66325755 552 volume->io.modified = 1;
427e5fc6
MD
553}
554
555static __inline void
556hammer_modify_supercl(struct hammer_supercl *supercl)
557{
66325755 558 supercl->io.modified = 1;
427e5fc6
MD
559}
560
561static __inline void
562hammer_modify_cluster(struct hammer_cluster *cluster)
563{
66325755 564 cluster->io.modified = 1;
427e5fc6
MD
565}
566
567static __inline void
568hammer_modify_buffer(struct hammer_buffer *buffer)
569{
66325755 570 buffer->io.modified = 1;
427e5fc6
MD
571}
572
8cd0a023
MD
573static __inline void
574hammer_modify_node(struct hammer_node *node)
575{
576 node->buffer->io.modified = 1;
577}
578
427e5fc6
MD
579/*
580 * Return the cluster-relative byte offset of an element within a buffer
581 */
582static __inline int
583hammer_bclu_offset(struct hammer_buffer *buffer, void *ptr)
584{
585 int bclu_offset;
586
587 bclu_offset = buffer->buf_no * HAMMER_BUFSIZE +
588 ((char *)ptr - (char *)buffer->ondisk);
589 return(bclu_offset);
590}
591