HAMMER 22/many: Recovery and B-Tree work.
[dragonfly.git] / sys / vfs / hammer / hammer.h
blob5b1d98b5211d928d4f5ba8c5d38af61e6ea365fd
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:
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.
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.
34 * $DragonFly: src/sys/vfs/hammer/hammer.h,v 1.27 2008/01/21 00:00:19 dillon Exp $
37 * This header file contains structures used internally by the HAMMERFS
38 * implementation. See hammer_disk.h for on-disk structures.
41 #include <sys/param.h>
42 #include <sys/types.h>
43 #include <sys/kernel.h>
44 #include <sys/systm.h>
45 #include <sys/tree.h>
46 #include <sys/malloc.h>
47 #include <sys/mount.h>
48 #include <sys/vnode.h>
49 #include <sys/globaldata.h>
50 #include <sys/lockf.h>
51 #include <sys/buf.h>
52 #include <sys/queue.h>
53 #include <sys/globaldata.h>
55 #include <sys/buf2.h>
56 #include "hammer_alist.h"
57 #include "hammer_disk.h"
58 #include "hammer_mount.h"
60 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
62 MALLOC_DECLARE(M_HAMMER);
64 struct hammer_mount;
67 * Key structure used for custom RB tree inode lookups. This prototypes
68 * the function hammer_ino_rb_tree_RB_LOOKUP_INFO(root, info).
70 typedef 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;
76 * HAMMER Transaction tracking
78 struct hammer_transaction {
79 struct hammer_mount *hmp;
80 hammer_tid_t tid;
81 struct hammer_volume *rootvol;
84 typedef struct hammer_transaction *hammer_transaction_t;
87 * HAMMER locks
89 struct hammer_lock {
90 int refs; /* active references delay writes */
91 int lockcount; /* lock count for exclusive/shared access */
92 int wanted;
93 struct thread *locktd;
96 static __inline int
97 hammer_islocked(struct hammer_lock *lock)
99 return(lock->lockcount != 0);
102 static __inline int
103 hammer_isactive(struct hammer_lock *lock)
105 return(lock->refs != 0);
108 static __inline int
109 hammer_islastref(struct hammer_lock *lock)
111 return(lock->refs == 1);
115 * This inline is specifically optimized for the case where the caller
116 * owns the lock, but wants to know what kind of lock he owns. A
117 * negative value indicates a shared lock, a positive value indicates
118 * an exclusive lock.
120 static __inline int
121 hammer_lock_held(struct hammer_lock *lock)
123 return(lock->lockcount);
127 * Structure used to represent an inode in-memory.
129 * The record and data associated with an inode may be out of sync with
130 * the disk (xDIRTY flags), or not even on the disk at all (ONDISK flag
131 * clear).
133 * An inode may also hold a cache of unsynchronized records, used for
134 * database and directories only. Unsynchronized regular file data is
135 * stored in the buffer cache.
137 * NOTE: A file which is created and destroyed within the initial
138 * synchronization period can wind up not doing any disk I/O at all.
140 * Finally, an inode may cache numerous disk-referencing B-Tree cursors.
142 struct hammer_ino_rb_tree;
143 struct hammer_inode;
144 RB_HEAD(hammer_ino_rb_tree, hammer_inode);
145 RB_PROTOTYPEX(hammer_ino_rb_tree, INFO, hammer_inode, rb_node,
146 hammer_ino_rb_compare, hammer_inode_info_t);
148 struct hammer_rec_rb_tree;
149 struct hammer_record;
150 RB_HEAD(hammer_rec_rb_tree, hammer_record);
151 RB_PROTOTYPEX(hammer_rec_rb_tree, INFO, hammer_record, rb_node,
152 hammer_rec_rb_compare, hammer_base_elm_t);
154 TAILQ_HEAD(hammer_node_list, hammer_node);
156 struct hammer_inode {
157 RB_ENTRY(hammer_inode) rb_node;
158 u_int64_t obj_id; /* (key) object identifier */
159 hammer_tid_t obj_asof; /* (key) snapshot transid or 0 */
160 hammer_tid_t last_tid; /* last modified tid (for fsync) */
161 struct hammer_mount *hmp;
162 int flags;
163 struct vnode *vp;
164 struct lockf advlock;
165 struct hammer_lock lock;
166 struct hammer_inode_record ino_rec;
167 struct hammer_inode_data ino_data;
168 struct hammer_rec_rb_tree rec_tree; /* red-black record tree */
169 struct hammer_node *cache[2]; /* search initiate cache */
172 typedef struct hammer_inode *hammer_inode_t;
174 #define VTOI(vp) ((struct hammer_inode *)(vp)->v_data)
176 #define HAMMER_INODE_DDIRTY 0x0001 /* in-memory ino_data is dirty */
177 #define HAMMER_INODE_RDIRTY 0x0002 /* in-memory ino_rec is dirty */
178 #define HAMMER_INODE_ITIMES 0x0004 /* in-memory mtime/atime modified */
179 #define HAMMER_INODE_XDIRTY 0x0008 /* in-memory records present */
180 #define HAMMER_INODE_ONDISK 0x0010 /* inode is on-disk (else not yet) */
181 #define HAMMER_INODE_FLUSH 0x0020 /* flush on last ref */
182 #define HAMMER_INODE_DELETED 0x0080 /* inode ready for deletion */
183 #define HAMMER_INODE_DELONDISK 0x0100 /* delete synchronized to disk */
184 #define HAMMER_INODE_RO 0x0200 /* read-only (because of as-of) */
185 #define HAMMER_INODE_GONE 0x0400 /* delete flushed out */
186 #define HAMMER_INODE_DONDISK 0x0800 /* data records may be on disk */
187 #define HAMMER_INODE_BUFS 0x1000 /* dirty high level bps present */
189 #define HAMMER_INODE_MODMASK (HAMMER_INODE_DDIRTY|HAMMER_INODE_RDIRTY| \
190 HAMMER_INODE_XDIRTY|HAMMER_INODE_BUFS| \
191 HAMMER_INODE_ITIMES|HAMMER_INODE_DELETED)
193 #define HAMMER_MAX_INODE_CURSORS 4
196 * Structure used to represent an unsynchronized record in-memory. This
197 * structure is orgranized in a per-inode RB-tree. If the inode is not
198 * on disk then neither are any records and the in-memory record tree
199 * represents the entire contents of the inode. If the inode is on disk
200 * then the on-disk B-Tree is scanned in parallel with the in-memory
201 * RB-Tree to synthesize the current state of the file.
203 * Only current (delete_tid == 0) unsynchronized records are kept in-memory.
205 struct hammer_record {
206 RB_ENTRY(hammer_record) rb_node;
207 struct hammer_lock lock;
208 struct hammer_inode *ip;
209 union hammer_record_ondisk rec;
210 union hammer_data_ondisk *data;
211 int flags;
214 typedef struct hammer_record *hammer_record_t;
216 #define HAMMER_RECF_ALLOCDATA 0x0001
217 #define HAMMER_RECF_ONRBTREE 0x0002
218 #define HAMMER_RECF_DELETED 0x0004
219 #define HAMMER_RECF_EMBEDDED_DATA 0x0008
220 #define HAMMER_RECF_SYNCING 0x0010
223 * Structures used to internally represent a volume and a cluster
225 struct hammer_volume;
226 struct hammer_cluster;
227 struct hammer_supercl;
228 struct hammer_buffer;
229 struct hammer_node;
230 RB_HEAD(hammer_vol_rb_tree, hammer_volume);
231 RB_HEAD(hammer_clu_rb_tree, hammer_cluster);
232 RB_HEAD(hammer_scl_rb_tree, hammer_supercl);
233 RB_HEAD(hammer_buf_rb_tree, hammer_buffer);
234 RB_HEAD(hammer_nod_rb_tree, hammer_node);
236 RB_PROTOTYPE2(hammer_vol_rb_tree, hammer_volume, rb_node,
237 hammer_vol_rb_compare, int32_t);
238 RB_PROTOTYPE2(hammer_clu_rb_tree, hammer_cluster, rb_node,
239 hammer_clu_rb_compare, int32_t);
240 RB_PROTOTYPE2(hammer_scl_rb_tree, hammer_supercl, rb_node,
241 hammer_scl_rb_compare, int32_t);
242 RB_PROTOTYPE2(hammer_buf_rb_tree, hammer_buffer, rb_node,
243 hammer_buf_rb_compare, int32_t);
244 RB_PROTOTYPE2(hammer_nod_rb_tree, hammer_node, rb_node,
245 hammer_nod_rb_compare, int32_t);
248 * IO management - embedded at the head of various in-memory structures
250 enum hammer_io_type { HAMMER_STRUCTURE_VOLUME,
251 HAMMER_STRUCTURE_SUPERCL,
252 HAMMER_STRUCTURE_CLUSTER,
253 HAMMER_STRUCTURE_BUFFER };
255 union hammer_io_structure;
256 struct hammer_io;
258 struct worklist {
259 LIST_ENTRY(worklist) node;
262 TAILQ_HEAD(hammer_io_list, hammer_io);
264 struct hammer_io {
265 struct worklist worklist;
266 struct hammer_lock lock;
267 enum hammer_io_type type;
268 struct buf *bp;
269 int64_t offset;
270 TAILQ_ENTRY(hammer_io) entry; /* based on modified flag */
271 struct hammer_io_list *entry_list;
272 struct hammer_io_list deplist;
273 u_int modified : 1; /* bp's data was modified */
274 u_int released : 1; /* bp released (w/ B_LOCKED set) */
275 u_int running : 1; /* bp write IO in progress */
276 u_int waiting : 1; /* someone is waiting on us */
277 u_int loading : 1; /* ondisk is loading */
280 typedef struct hammer_io *hammer_io_t;
283 * In-memory volume representing on-disk buffer
285 struct hammer_volume {
286 struct hammer_io io;
287 RB_ENTRY(hammer_volume) rb_node;
288 struct hammer_clu_rb_tree rb_clus_root;
289 struct hammer_scl_rb_tree rb_scls_root;
290 struct hammer_volume_ondisk *ondisk;
291 struct hammer_alist_live alist;
292 int32_t vol_no;
293 int32_t vol_clsize;
294 int32_t clu_iterator; /* cluster allocation iterator */
295 int64_t nblocks; /* note: special calculation for statfs */
296 int64_t cluster_base; /* base offset of cluster 0 */
297 char *vol_name;
298 struct vnode *devvp;
299 struct hammer_mount *hmp;
300 int vol_flags;
303 typedef struct hammer_volume *hammer_volume_t;
306 * In-memory super-cluster representing on-disk buffer
308 struct hammer_supercl {
309 struct hammer_io io;
310 RB_ENTRY(hammer_supercl) rb_node;
311 struct hammer_supercl_ondisk *ondisk;
312 struct hammer_volume *volume;
313 struct hammer_alist_live alist;
314 int32_t scl_no;
317 typedef struct hammer_supercl *hammer_supercl_t;
320 * In-memory cluster representing on-disk buffer
322 * The cluster's indexing range is cached in hammer_cluster, separate
323 * from the ondisk info in order to allow cursors to point to it.
325 struct hammer_cluster {
326 struct hammer_io io;
327 RB_ENTRY(hammer_cluster) rb_node;
328 struct hammer_buf_rb_tree rb_bufs_root;
329 struct hammer_cluster_ondisk *ondisk;
330 struct hammer_volume *volume;
331 struct hammer_alist_live alist_master;
332 struct hammer_alist_live alist_btree;
333 struct hammer_alist_live alist_record;
334 struct hammer_alist_live alist_mdata;
335 struct hammer_nod_rb_tree rb_nods_root; /* cursors in cluster */
336 struct hammer_base_elm clu_btree_beg; /* copy of on-disk info */
337 struct hammer_base_elm clu_btree_end; /* copy of on-disk info */
338 int32_t clu_no;
341 typedef struct hammer_cluster *hammer_cluster_t;
344 * Passed to hammer_get_cluster()
346 #define GET_CLUSTER_NEW 0x0001
347 #define GET_CLUSTER_NORECOVER 0x0002
350 * In-memory buffer (other then volume, super-cluster, or cluster),
351 * representing an on-disk buffer.
353 struct hammer_buffer {
354 struct hammer_io io;
355 RB_ENTRY(hammer_buffer) rb_node;
356 hammer_fsbuf_ondisk_t ondisk;
357 struct hammer_volume *volume;
358 struct hammer_cluster *cluster;
359 int32_t buf_no;
360 u_int64_t buf_type;
361 struct hammer_alist_live alist;
362 struct hammer_node_list clist;
365 typedef struct hammer_buffer *hammer_buffer_t;
368 * In-memory B-Tree node, representing an on-disk B-Tree node.
370 * This is a hang-on structure which is backed by a hammer_buffer,
371 * indexed by a hammer_cluster, and used for fine-grained locking of
372 * B-Tree nodes in order to properly control lock ordering. A hammer_buffer
373 * can contain multiple nodes representing wildly disassociated portions
374 * of the B-Tree so locking cannot be done on a buffer-by-buffer basis.
376 * This structure uses a cluster-relative index to reduce the number
377 * of layers required to access it, and also because all on-disk B-Tree
378 * references are cluster-relative offsets.
380 struct hammer_node {
381 struct hammer_lock lock; /* node-by-node lock */
382 TAILQ_ENTRY(hammer_node) entry; /* per-buffer linkage */
383 RB_ENTRY(hammer_node) rb_node; /* per-cluster linkage */
384 int32_t node_offset; /* cluster-rel offset */
385 struct hammer_cluster *cluster;
386 struct hammer_buffer *buffer; /* backing buffer */
387 hammer_node_ondisk_t ondisk; /* ptr to on-disk structure */
388 struct hammer_node **cache1; /* passive cache(s) */
389 struct hammer_node **cache2;
390 int flags;
393 #define HAMMER_NODE_DELETED 0x0001
394 #define HAMMER_NODE_FLUSH 0x0002
396 typedef struct hammer_node *hammer_node_t;
399 * Common I/O management structure - embedded in in-memory structures
400 * which are backed by filesystem buffers.
402 union hammer_io_structure {
403 struct hammer_io io;
404 struct hammer_volume volume;
405 struct hammer_supercl supercl;
406 struct hammer_cluster cluster;
407 struct hammer_buffer buffer;
410 typedef union hammer_io_structure *hammer_io_structure_t;
412 #define HAMFS_CLUSTER_DIRTY 0x0001
414 #include "hammer_cursor.h"
417 * Internal hammer mount data structure
419 struct hammer_mount {
420 struct mount *mp;
421 /*struct vnode *rootvp;*/
422 struct hammer_ino_rb_tree rb_inos_root;
423 struct hammer_vol_rb_tree rb_vols_root;
424 struct hammer_volume *rootvol;
425 struct hammer_cluster *rootcl;
426 char *zbuf; /* HAMMER_BUFSIZE bytes worth of all-zeros */
427 int hflags;
428 int ronly;
429 int nvolumes;
430 int volume_iterator;
431 uuid_t fsid;
432 udev_t fsid_udev;
433 hammer_tid_t asof;
434 u_int32_t namekey_iterator;
437 typedef struct hammer_mount *hammer_mount_t;
439 struct hammer_sync_info {
440 int error;
441 int waitfor;
444 #endif
446 #if defined(_KERNEL)
448 extern struct vop_ops hammer_vnode_vops;
449 extern struct vop_ops hammer_spec_vops;
450 extern struct vop_ops hammer_fifo_vops;
451 extern struct hammer_alist_config Buf_alist_config;
452 extern struct hammer_alist_config Vol_normal_alist_config;
453 extern struct hammer_alist_config Vol_super_alist_config;
454 extern struct hammer_alist_config Supercl_alist_config;
455 extern struct hammer_alist_config Clu_master_alist_config;
456 extern struct hammer_alist_config Clu_slave_alist_config;
457 extern struct bio_ops hammer_bioops;
459 extern int hammer_debug_btree;
460 extern int hammer_debug_tid;
461 extern int hammer_count_inodes;
462 extern int hammer_count_records;
463 extern int hammer_count_record_datas;
464 extern int hammer_count_volumes;
465 extern int hammer_count_supercls;
466 extern int hammer_count_clusters;
467 extern int hammer_count_buffers;
468 extern int hammer_count_nodes;
469 extern int hammer_count_spikes;
471 int hammer_vop_inactive(struct vop_inactive_args *);
472 int hammer_vop_reclaim(struct vop_reclaim_args *);
473 int hammer_vfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp);
474 int hammer_get_vnode(struct hammer_inode *ip, int lktype,
475 struct vnode **vpp);
476 struct hammer_inode *hammer_get_inode(hammer_mount_t hmp,
477 struct hammer_node **cache,
478 u_int64_t obj_id, hammer_tid_t asof, int flags,
479 int *errorp);
480 void hammer_put_inode(struct hammer_inode *ip);
481 void hammer_put_inode_ref(struct hammer_inode *ip);
483 int hammer_unload_inode(hammer_inode_t ip, void *data);
484 int hammer_unload_volume(hammer_volume_t volume, void *data __unused);
485 int hammer_unload_supercl(hammer_supercl_t supercl, void *data __unused);
486 int hammer_unload_cluster(hammer_cluster_t cluster, void *data __unused);
487 int hammer_unload_buffer(hammer_buffer_t buffer, void *data __unused);
488 int hammer_install_volume(hammer_mount_t hmp, const char *volname);
490 int hammer_ip_lookup(hammer_cursor_t cursor, hammer_inode_t ip);
491 int hammer_ip_first(hammer_cursor_t cursor, hammer_inode_t ip);
492 int hammer_ip_next(hammer_cursor_t cursor);
493 int hammer_ip_resolve_data(hammer_cursor_t cursor);
494 int hammer_ip_delete_record(hammer_cursor_t cursor, hammer_tid_t tid);
495 int hammer_ip_check_directory_empty(hammer_transaction_t trans,
496 hammer_inode_t ip);
497 int hammer_sync_hmp(hammer_mount_t hmp, int waitfor);
498 int hammer_sync_volume(hammer_volume_t volume, void *data);
499 int hammer_sync_cluster(hammer_cluster_t cluster, void *data);
500 int hammer_sync_buffer(hammer_buffer_t buffer, void *data);
502 hammer_record_t
503 hammer_alloc_mem_record(hammer_inode_t ip);
504 void hammer_rel_mem_record(hammer_record_t record);
506 int hammer_cursor_up(hammer_cursor_t cursor);
507 int hammer_cursor_toroot(hammer_cursor_t cursor);
508 int hammer_cursor_down(hammer_cursor_t cursor);
509 int hammer_cursor_upgrade(hammer_cursor_t cursor);
510 void hammer_cursor_downgrade(hammer_cursor_t cursor);
512 void hammer_lock_ex(struct hammer_lock *lock);
513 int hammer_lock_ex_try(struct hammer_lock *lock);
514 void hammer_lock_sh(struct hammer_lock *lock);
515 int hammer_lock_upgrade(struct hammer_lock *lock);
516 void hammer_lock_downgrade(struct hammer_lock *lock);
517 void hammer_unlock(struct hammer_lock *lock);
518 void hammer_ref(struct hammer_lock *lock);
519 void hammer_unref(struct hammer_lock *lock);
521 u_int32_t hammer_to_unix_xid(uuid_t *uuid);
522 void hammer_guid_to_uuid(uuid_t *uuid, u_int32_t guid);
523 void hammer_to_timespec(hammer_tid_t tid, struct timespec *ts);
524 hammer_tid_t hammer_timespec_to_transid(struct timespec *ts);
525 hammer_tid_t hammer_alloc_tid(hammer_transaction_t trans);
526 hammer_tid_t hammer_now_tid(void);
527 hammer_tid_t hammer_str_to_tid(const char *str);
528 u_int64_t hammer_alloc_recid(hammer_cluster_t cluster);
530 enum vtype hammer_get_vnode_type(u_int8_t obj_type);
531 int hammer_get_dtype(u_int8_t obj_type);
532 u_int8_t hammer_get_obj_type(enum vtype vtype);
533 int64_t hammer_directory_namekey(void *name, int len);
535 int hammer_init_cursor_hmp(hammer_cursor_t cursor, struct hammer_node **cache, hammer_mount_t hmp);
536 int hammer_init_cursor_cluster(hammer_cursor_t cursor, hammer_cluster_t cluster);
538 void hammer_done_cursor(hammer_cursor_t cursor);
539 void hammer_mem_done(hammer_cursor_t cursor);
541 int hammer_btree_lookup(hammer_cursor_t cursor);
542 int hammer_btree_first(hammer_cursor_t cursor);
543 int hammer_btree_extract(hammer_cursor_t cursor, int flags);
544 int hammer_btree_iterate(hammer_cursor_t cursor);
545 int hammer_btree_insert(hammer_cursor_t cursor, hammer_btree_elm_t elm);
546 int hammer_btree_insert_cluster(hammer_cursor_t cursor,
547 hammer_cluster_t cluster, int32_t rec_offset);
548 int hammer_btree_delete(hammer_cursor_t cursor);
549 int hammer_btree_cmp(hammer_base_elm_t key1, hammer_base_elm_t key2);
550 int hammer_btree_chkts(hammer_tid_t ts, hammer_base_elm_t key);
552 void hammer_print_btree_node(hammer_node_ondisk_t ondisk);
553 void hammer_print_btree_elm(hammer_btree_elm_t elm, u_int8_t type, int i);
555 void *hammer_bread(struct hammer_cluster *cluster, int32_t cloff,
556 u_int64_t buf_type, int *errorp,
557 struct hammer_buffer **bufferp);
559 hammer_volume_t hammer_get_root_volume(hammer_mount_t hmp, int *errorp);
560 hammer_cluster_t hammer_get_root_cluster(hammer_mount_t hmp, int *errorp);
562 hammer_volume_t hammer_get_volume(hammer_mount_t hmp,
563 int32_t vol_no, int *errorp);
564 hammer_supercl_t hammer_get_supercl(hammer_volume_t volume, int32_t scl_no,
565 int *errorp, hammer_alloc_state_t isnew);
566 hammer_cluster_t hammer_get_cluster(hammer_volume_t volume, int32_t clu_no,
567 int *errorp, int getflags);
568 hammer_buffer_t hammer_get_buffer(hammer_cluster_t cluster,
569 int32_t buf_no, u_int64_t buf_type, int *errorp);
571 int hammer_ref_volume(hammer_volume_t volume);
572 int hammer_ref_cluster(hammer_cluster_t cluster);
573 int hammer_ref_buffer(hammer_buffer_t buffer);
574 void hammer_flush_buffer_nodes(hammer_buffer_t buffer);
576 void hammer_rel_volume(hammer_volume_t volume, int flush);
577 void hammer_rel_supercl(hammer_supercl_t supercl, int flush);
578 void hammer_rel_cluster(hammer_cluster_t cluster, int flush);
579 void hammer_rel_buffer(hammer_buffer_t buffer, int flush);
581 hammer_node_t hammer_get_node(hammer_cluster_t cluster,
582 int32_t node_offset, int *errorp);
583 int hammer_ref_node(hammer_node_t node);
584 hammer_node_t hammer_ref_node_safe(struct hammer_mount *hmp,
585 struct hammer_node **cache, int *errorp);
586 void hammer_rel_node(hammer_node_t node);
587 void hammer_cache_node(hammer_node_t node,
588 struct hammer_node **cache);
589 void hammer_uncache_node(struct hammer_node **cache);
590 void hammer_flush_node(hammer_node_t node);
592 void hammer_dup_buffer(struct hammer_buffer **bufferp,
593 struct hammer_buffer *buffer);
594 void hammer_dup_cluster(struct hammer_cluster **clusterp,
595 struct hammer_cluster *cluster);
596 hammer_cluster_t hammer_alloc_cluster(hammer_mount_t hmp,
597 hammer_cluster_t cluster_hint, int *errorp);
598 void hammer_init_cluster(hammer_cluster_t cluster,
599 hammer_base_elm_t left_bound,
600 hammer_base_elm_t right_bound);
601 hammer_node_t hammer_alloc_btree(struct hammer_cluster *cluster, int *errorp);
602 void *hammer_alloc_data(struct hammer_cluster *cluster, int32_t bytes,
603 int *errorp, struct hammer_buffer **bufferp);
604 void *hammer_alloc_record(struct hammer_cluster *cluster,
605 int *errorp, struct hammer_buffer **bufferp);
606 void hammer_initbuffer(hammer_alist_t live, hammer_fsbuf_head_t head,
607 u_int64_t type);
608 void hammer_free_data_ptr(struct hammer_buffer *buffer,
609 void *data, int bytes);
610 void hammer_free_record_ptr(struct hammer_buffer *buffer,
611 union hammer_record_ondisk *rec);
612 void hammer_free_cluster(hammer_cluster_t cluster);
613 void hammer_free_btree(struct hammer_cluster *cluster, int32_t bclu_offset);
614 void hammer_free_data(struct hammer_cluster *cluster, int32_t bclu_offset,
615 int32_t bytes);
616 void hammer_free_record(struct hammer_cluster *cluster, int32_t bclu_offset);
618 void hammer_put_volume(struct hammer_volume *volume, int flush);
619 void hammer_put_supercl(struct hammer_supercl *supercl, int flush);
620 void hammer_put_cluster(struct hammer_cluster *cluster, int flush);
621 void hammer_put_buffer(struct hammer_buffer *buffer, int flush);
623 void hammer_init_alist_config(void);
625 void hammer_start_transaction(struct hammer_transaction *trans,
626 struct hammer_mount *hmp);
627 void hammer_start_transaction_tid(struct hammer_transaction *trans,
628 struct hammer_mount *hmp, hammer_tid_t tid);
629 void hammer_commit_transaction(struct hammer_transaction *trans);
630 void hammer_abort_transaction(struct hammer_transaction *trans);
632 void hammer_modify_inode(struct hammer_transaction *trans,
633 hammer_inode_t ip, int flags);
634 int hammer_create_inode(struct hammer_transaction *trans, struct vattr *vap,
635 struct ucred *cred, struct hammer_inode *dip,
636 struct hammer_inode **ipp);
637 void hammer_rel_inode(hammer_inode_t ip, int flush);
638 int hammer_sync_inode(hammer_inode_t ip, int waitfor, int handle_delete);
640 int hammer_ip_add_directory(struct hammer_transaction *trans,
641 hammer_inode_t dip, struct namecache *ncp,
642 hammer_inode_t nip);
643 int hammer_ip_del_directory(struct hammer_transaction *trans,
644 hammer_cursor_t cursor, hammer_inode_t dip,
645 hammer_inode_t ip);
646 int hammer_ip_add_record(struct hammer_transaction *trans,
647 hammer_record_t record);
648 int hammer_ip_delete_range(struct hammer_transaction *trans,
649 hammer_inode_t ip, int64_t ran_beg, int64_t ran_end,
650 struct hammer_cursor **spikep);
651 int hammer_ip_delete_range_all(struct hammer_transaction *trans,
652 hammer_inode_t ip);
653 int hammer_ip_sync_data(struct hammer_transaction *trans,
654 hammer_inode_t ip, int64_t offset,
655 void *data, int bytes, struct hammer_cursor **spikep);
656 int hammer_ip_sync_record(hammer_record_t rec, struct hammer_cursor **spikep);
657 int hammer_write_record(hammer_cursor_t cursor, hammer_record_ondisk_t rec,
658 void *data, int cursor_flags);
660 void hammer_load_spike(hammer_cursor_t cursor, struct hammer_cursor **spikep);
661 int hammer_spike(struct hammer_cursor **spikep);
662 int hammer_recover(struct hammer_cluster *cluster);
663 int buffer_alist_recover(void *info, int32_t blk, int32_t radix, int32_t count);
665 void hammer_io_init(hammer_io_t io, enum hammer_io_type type);
666 int hammer_io_read(struct vnode *devvp, struct hammer_io *io);
667 int hammer_io_new(struct vnode *devvp, struct hammer_io *io);
668 void hammer_io_release(struct hammer_io *io, int flush);
669 void hammer_io_flush(struct hammer_io *io);
670 int hammer_io_checkflush(hammer_io_t io);
671 void hammer_io_notify_cluster(hammer_cluster_t cluster);
672 void hammer_io_clear_modify(struct hammer_io *io);
673 void hammer_io_waitdep(struct hammer_io *io);
675 void hammer_modify_volume(hammer_volume_t volume);
676 void hammer_modify_supercl(hammer_supercl_t supercl);
677 void hammer_modify_cluster(hammer_cluster_t cluster);
678 void hammer_modify_buffer(hammer_buffer_t buffer);
680 #endif
682 static __inline void
683 hammer_modify_node(struct hammer_node *node)
685 hammer_modify_buffer(node->buffer);
689 * Return the cluster-relative byte offset of an element within a buffer
691 static __inline int
692 hammer_bclu_offset(struct hammer_buffer *buffer, void *ptr)
694 int bclu_offset;
696 bclu_offset = buffer->buf_no * HAMMER_BUFSIZE +
697 ((char *)ptr - (char *)buffer->ondisk);
698 return(bclu_offset);