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