HAMMER 35/many: Stabilization pass, cleanups
[dragonfly.git] / sys / vfs / hammer / hammer.h
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  * 
34  * $DragonFly: src/sys/vfs/hammer/hammer.h,v 1.43 2008/03/24 23:50:23 dillon Exp $
35  */
36 /*
37  * This header file contains structures used internally by the HAMMERFS
38  * implementation.  See hammer_disk.h for on-disk structures.
39  */
40
41 #include <sys/param.h>
42 #include <sys/types.h>
43 #include <sys/kernel.h>
44 #include <sys/conf.h>
45 #include <sys/systm.h>
46 #include <sys/tree.h>
47 #include <sys/malloc.h>
48 #include <sys/mount.h>
49 #include <sys/mountctl.h>
50 #include <sys/vnode.h>
51 #include <sys/proc.h>
52 #include <sys/globaldata.h>
53 #include <sys/lockf.h>
54 #include <sys/buf.h>
55 #include <sys/queue.h>
56 #include <sys/globaldata.h>
57
58 #include <sys/buf2.h>
59 #include <sys/signal2.h>
60 #include "hammer_disk.h"
61 #include "hammer_mount.h"
62 #include "hammer_ioctl.h"
63
64 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
65
66 MALLOC_DECLARE(M_HAMMER);
67
68 struct hammer_mount;
69
70 /*
71  * Key structure used for custom RB tree inode lookups.  This prototypes
72  * the function hammer_ino_rb_tree_RB_LOOKUP_INFO(root, info).
73  */
74 typedef struct hammer_inode_info {
75         int64_t         obj_id;         /* (key) object identifier */
76         hammer_tid_t    obj_asof;       /* (key) snapshot transid or 0 */
77 } *hammer_inode_info_t;
78
79 /*
80  * HAMMER Transaction tracking
81  */
82 struct hammer_transaction {
83         struct hammer_mount *hmp;
84         hammer_tid_t    tid;
85         struct hammer_volume *rootvol;
86 /*      TAILQ_HEAD(, hammer_io) recycle_list;*/
87 };
88
89 typedef struct hammer_transaction *hammer_transaction_t;
90
91 /*
92  * HAMMER locks
93  */
94 struct hammer_lock {
95         int     refs;           /* active references delay writes */
96         int     lockcount;      /* lock count for exclusive/shared access */
97         int     wanted;
98         struct thread *locktd;
99 };
100
101 static __inline int
102 hammer_islocked(struct hammer_lock *lock)
103 {
104         return(lock->lockcount != 0);
105 }
106
107 static __inline int
108 hammer_isactive(struct hammer_lock *lock)
109 {
110         return(lock->refs != 0);
111 }
112
113 static __inline int
114 hammer_islastref(struct hammer_lock *lock)
115 {
116         return(lock->refs == 1);
117 }
118
119 /*
120  * This inline is specifically optimized for the case where the caller
121  * owns the lock, but wants to know what kind of lock he owns.  A
122  * negative value indicates a shared lock, a positive value indicates
123  * an exclusive lock.
124  */
125 static __inline int
126 hammer_lock_held(struct hammer_lock *lock)
127 {
128         return(lock->lockcount);
129 }
130
131 /*
132  * Structure used to represent an inode in-memory.
133  *
134  * The record and data associated with an inode may be out of sync with
135  * the disk (xDIRTY flags), or not even on the disk at all (ONDISK flag
136  * clear).
137  *
138  * An inode may also hold a cache of unsynchronized records, used for
139  * database and directories only.  Unsynchronized regular file data is
140  * stored in the buffer cache.
141  *
142  * NOTE: A file which is created and destroyed within the initial
143  * synchronization period can wind up not doing any disk I/O at all.
144  *
145  * Finally, an inode may cache numerous disk-referencing B-Tree cursors.
146  */
147 struct hammer_ino_rb_tree;
148 struct hammer_inode;
149 RB_HEAD(hammer_ino_rb_tree, hammer_inode);
150 RB_PROTOTYPEX(hammer_ino_rb_tree, INFO, hammer_inode, rb_node,
151               hammer_ino_rb_compare, hammer_inode_info_t);
152
153 struct hammer_rec_rb_tree;
154 struct hammer_record;
155 RB_HEAD(hammer_rec_rb_tree, hammer_record);
156 RB_PROTOTYPEX(hammer_rec_rb_tree, INFO, hammer_record, rb_node,
157               hammer_rec_rb_compare, hammer_base_elm_t);
158
159 TAILQ_HEAD(hammer_node_list, hammer_node);
160
161 struct hammer_inode {
162         RB_ENTRY(hammer_inode) rb_node;
163         u_int64_t       obj_id;         /* (key) object identifier */
164         hammer_tid_t    obj_asof;       /* (key) snapshot transid or 0 */
165         hammer_tid_t    last_tid;       /* last modified tid (for fsync) */
166         hammer_tid_t    sync_tid;       /* last inode tid synced to disk */
167         struct hammer_mount *hmp;
168         int             flags;
169         struct vnode    *vp;
170         struct lockf    advlock;
171         struct hammer_lock lock;
172         struct hammer_inode_record ino_rec;
173         struct hammer_inode_data ino_data;
174         struct hammer_rec_rb_tree rec_tree;     /* red-black record tree */
175         struct hammer_node      *cache[2];      /* search initiate cache */
176 };
177
178 typedef struct hammer_inode *hammer_inode_t;
179
180 #define VTOI(vp)        ((struct hammer_inode *)(vp)->v_data)
181
182 #define HAMMER_INODE_DDIRTY     0x0001  /* in-memory ino_data is dirty */
183 #define HAMMER_INODE_RDIRTY     0x0002  /* in-memory ino_rec is dirty */
184 #define HAMMER_INODE_ITIMES     0x0004  /* in-memory mtime/atime modified */
185 #define HAMMER_INODE_XDIRTY     0x0008  /* in-memory records present */
186 #define HAMMER_INODE_ONDISK     0x0010  /* inode is on-disk (else not yet) */
187 #define HAMMER_INODE_FLUSH      0x0020  /* flush on last ref */
188 #define HAMMER_INODE_DELETED    0x0080  /* inode ready for deletion */
189 #define HAMMER_INODE_DELONDISK  0x0100  /* delete synchronized to disk */
190 #define HAMMER_INODE_RO         0x0200  /* read-only (because of as-of) */
191 #define HAMMER_INODE_GONE       0x0400  /* delete flushed out */
192 #define HAMMER_INODE_DONDISK    0x0800  /* data records may be on disk */
193 #define HAMMER_INODE_BUFS       0x1000  /* dirty high level bps present */
194 #define HAMMER_INODE_TIDLOCKED  0x2000  /* tid locked until inode synced */
195
196 #define HAMMER_INODE_MODMASK    (HAMMER_INODE_DDIRTY|HAMMER_INODE_RDIRTY| \
197                                  HAMMER_INODE_XDIRTY|HAMMER_INODE_BUFS|   \
198                                  HAMMER_INODE_ITIMES|HAMMER_INODE_DELETED)
199
200 #define HAMMER_MAX_INODE_CURSORS        4
201
202 /*
203  * Structure used to represent an unsynchronized record in-memory.  This
204  * structure is orgranized in a per-inode RB-tree.  If the inode is not
205  * on disk then neither are any records and the in-memory record tree
206  * represents the entire contents of the inode.  If the inode is on disk
207  * then the on-disk B-Tree is scanned in parallel with the in-memory
208  * RB-Tree to synthesize the current state of the file.
209  *
210  * Only current (delete_tid == 0) unsynchronized records are kept in-memory.
211  *
212  * blocked is the count of the number of cursors (ip_first/ip_next) blocked
213  * on the record waiting for a synchronization to complete.
214  */
215 struct hammer_record {
216         RB_ENTRY(hammer_record)         rb_node;
217         struct hammer_lock              lock;
218         struct hammer_inode             *ip;
219         union hammer_record_ondisk      rec;
220         union hammer_data_ondisk        *data;
221         int                             flags;
222         int                             blocked;
223 };
224
225 typedef struct hammer_record *hammer_record_t;
226
227 #define HAMMER_RECF_ALLOCDATA           0x0001
228 #define HAMMER_RECF_ONRBTREE            0x0002
229 #define HAMMER_RECF_DELETED             0x0004
230 #define HAMMER_RECF_INBAND              0x0008
231 #define HAMMER_RECF_SYNCING             0x0010
232 #define HAMMER_RECF_WANTED              0x0020
233
234 /*
235  * In-memory structures representing on-disk structures.
236  */
237 struct hammer_volume;
238 struct hammer_buffer;
239 struct hammer_node;
240 RB_HEAD(hammer_vol_rb_tree, hammer_volume);
241 RB_HEAD(hammer_buf_rb_tree, hammer_buffer);
242 RB_HEAD(hammer_nod_rb_tree, hammer_node);
243
244 RB_PROTOTYPE2(hammer_vol_rb_tree, hammer_volume, rb_node,
245               hammer_vol_rb_compare, int32_t);
246 RB_PROTOTYPE2(hammer_buf_rb_tree, hammer_buffer, rb_node,
247               hammer_buf_rb_compare, hammer_off_t);
248 RB_PROTOTYPE2(hammer_nod_rb_tree, hammer_node, rb_node,
249               hammer_nod_rb_compare, hammer_off_t);
250
251 /*
252  * IO management - embedded at the head of various in-memory structures
253  */
254 enum hammer_io_type { HAMMER_STRUCTURE_VOLUME,
255                       HAMMER_STRUCTURE_BUFFER };
256
257 union hammer_io_structure;
258 struct hammer_io;
259
260 struct worklist {
261         LIST_ENTRY(worklist) node;
262 };
263
264 /*TAILQ_HEAD(hammer_dep_list, hammer_dep);*/
265
266 struct hammer_io {
267         struct worklist worklist;
268         struct hammer_lock lock;
269         enum hammer_io_type type;
270         struct buf      *bp;
271         int64_t         offset;
272         int             loading;        /* loading/unloading interlock */
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           validated : 1;  /* ondisk has been validated */
278         u_int           flush : 1;      /* flush on last release */
279         u_int           waitdep : 1;    /* flush waits for dependancies */
280 };
281
282 typedef struct hammer_io *hammer_io_t;
283
284 /*
285  * In-memory volume representing on-disk buffer
286  */
287 struct hammer_volume {
288         struct hammer_io io;
289         RB_ENTRY(hammer_volume) rb_node;
290         struct hammer_buf_rb_tree rb_bufs_root;
291         struct hammer_volume_ondisk *ondisk;
292         int32_t vol_no;
293         int64_t nblocks;        /* note: special calculation for statfs */
294         int64_t buffer_base;    /* base offset of buffer 0 */
295         hammer_off_t maxbuf_off; /* Maximum buffer offset */
296         char    *vol_name;
297         struct vnode *devvp;
298         struct hammer_mount *hmp;
299         int     vol_flags;
300 };
301
302 typedef struct hammer_volume *hammer_volume_t;
303
304 /*
305  * In-memory buffer (other then volume, super-cluster, or cluster),
306  * representing an on-disk buffer.
307  */
308 struct hammer_buffer {
309         struct hammer_io io;
310         RB_ENTRY(hammer_buffer) rb_node;
311         void *ondisk;
312         struct hammer_volume *volume;
313         hammer_off_t zone2_offset;
314         hammer_off_t zoneX_offset;
315         struct hammer_node_list clist;
316 };
317
318 typedef struct hammer_buffer *hammer_buffer_t;
319
320 /*
321  * In-memory B-Tree node, representing an on-disk B-Tree node.
322  *
323  * This is a hang-on structure which is backed by a hammer_buffer,
324  * indexed by a hammer_cluster, and used for fine-grained locking of
325  * B-Tree nodes in order to properly control lock ordering.  A hammer_buffer
326  * can contain multiple nodes representing wildly disassociated portions
327  * of the B-Tree so locking cannot be done on a buffer-by-buffer basis.
328  *
329  * This structure uses a cluster-relative index to reduce the number
330  * of layers required to access it, and also because all on-disk B-Tree
331  * references are cluster-relative offsets.
332  */
333 struct hammer_node {
334         struct hammer_lock      lock;           /* node-by-node lock */
335         TAILQ_ENTRY(hammer_node) entry;         /* per-buffer linkage */
336         RB_ENTRY(hammer_node)   rb_node;        /* per-cluster linkage */
337         hammer_off_t            node_offset;    /* full offset spec */
338         struct hammer_mount     *hmp;
339         struct hammer_buffer    *buffer;        /* backing buffer */
340         hammer_node_ondisk_t    ondisk;         /* ptr to on-disk structure */
341         struct hammer_node      **cache1;       /* passive cache(s) */
342         struct hammer_node      **cache2;
343         int                     flags;
344 };
345
346 #define HAMMER_NODE_DELETED     0x0001
347 #define HAMMER_NODE_FLUSH       0x0002
348
349 typedef struct hammer_node      *hammer_node_t;
350
351 /*
352  * List of locked nodes.
353  */
354 struct hammer_node_locklist {
355         struct hammer_node_locklist *next;
356         hammer_node_t   node;
357 };
358
359 typedef struct hammer_node_locklist *hammer_node_locklist_t;
360
361
362 /*
363  * Common I/O management structure - embedded in in-memory structures
364  * which are backed by filesystem buffers.
365  */
366 union hammer_io_structure {
367         struct hammer_io        io;
368         struct hammer_volume    volume;
369         struct hammer_buffer    buffer;
370 };
371
372 typedef union hammer_io_structure *hammer_io_structure_t;
373
374 /*
375  * Allocation holes are recorded for a short period of time in an attempt
376  * to use up the space.
377  */
378
379 #define HAMMER_MAX_HOLES        8
380
381 struct hammer_hole;
382
383 struct hammer_holes {
384         TAILQ_HEAD(, hammer_hole) list;
385         int     count;
386 };
387
388 typedef struct hammer_holes *hammer_holes_t;
389
390 struct hammer_hole {
391         TAILQ_ENTRY(hammer_hole) entry;
392         hammer_off_t    offset;
393         int             bytes;
394 };
395
396 typedef struct hammer_hole *hammer_hole_t;
397
398 #include "hammer_cursor.h"
399
400 /*
401  * Internal hammer mount data structure
402  */
403 struct hammer_mount {
404         struct mount *mp;
405         /*struct vnode *rootvp;*/
406         struct hammer_ino_rb_tree rb_inos_root;
407         struct hammer_vol_rb_tree rb_vols_root;
408         struct hammer_nod_rb_tree rb_nods_root;
409         struct hammer_volume *rootvol;
410         struct hammer_base_elm root_btree_beg;
411         struct hammer_base_elm root_btree_end;
412         char    *zbuf;  /* HAMMER_BUFSIZE bytes worth of all-zeros */
413         int     hflags;
414         int     ronly;
415         int     nvolumes;
416         int     volume_iterator;
417         u_int   check_interrupt;
418         uuid_t  fsid;
419         udev_t  fsid_udev;
420         hammer_tid_t asof;
421         u_int32_t namekey_iterator;
422         hammer_off_t zone_limits[HAMMER_MAX_ZONES];
423         struct netexport export;
424         struct lock blockmap_lock;
425         struct hammer_holes holes[HAMMER_MAX_ZONES];
426 };
427
428 typedef struct hammer_mount     *hammer_mount_t;
429
430 struct hammer_sync_info {
431         int error;
432         int waitfor;
433 };
434
435 #endif
436
437 #if defined(_KERNEL)
438
439 extern struct vop_ops hammer_vnode_vops;
440 extern struct vop_ops hammer_spec_vops;
441 extern struct vop_ops hammer_fifo_vops;
442 extern struct bio_ops hammer_bioops;
443
444 extern int hammer_debug_general;
445 extern int hammer_debug_btree;
446 extern int hammer_debug_tid;
447 extern int hammer_debug_recover;
448 extern int hammer_debug_recover_faults;
449 extern int hammer_count_inodes;
450 extern int hammer_count_records;
451 extern int hammer_count_record_datas;
452 extern int hammer_count_volumes;
453 extern int hammer_count_buffers;
454 extern int hammer_count_nodes;
455
456 int     hammer_vop_inactive(struct vop_inactive_args *);
457 int     hammer_vop_reclaim(struct vop_reclaim_args *);
458 int     hammer_get_vnode(struct hammer_inode *ip, int lktype,
459                         struct vnode **vpp);
460 struct hammer_inode *hammer_get_inode(hammer_transaction_t trans,
461                         struct hammer_node **cache,
462                         u_int64_t obj_id, hammer_tid_t asof, int flags,
463                         int *errorp);
464 void    hammer_put_inode(struct hammer_inode *ip);
465 void    hammer_put_inode_ref(struct hammer_inode *ip);
466
467 int     hammer_unload_inode(hammer_inode_t ip, void *data);
468 int     hammer_unload_volume(hammer_volume_t volume, void *data __unused);
469 int     hammer_unload_buffer(hammer_buffer_t buffer, void *data __unused);
470 int     hammer_install_volume(hammer_mount_t hmp, const char *volname);
471
472 int     hammer_ip_lookup(hammer_cursor_t cursor, hammer_inode_t ip);
473 int     hammer_ip_first(hammer_cursor_t cursor, hammer_inode_t ip);
474 int     hammer_ip_next(hammer_cursor_t cursor);
475 int     hammer_ip_resolve_record_and_data(hammer_cursor_t cursor);
476 int     hammer_ip_resolve_data(hammer_cursor_t cursor);
477 int     hammer_ip_delete_record(hammer_cursor_t cursor, hammer_tid_t tid);
478 int     hammer_delete_at_cursor(hammer_cursor_t cursor, int64_t *stat_bytes);
479 int     hammer_ip_check_directory_empty(hammer_transaction_t trans,
480                         hammer_inode_t ip);
481 int     hammer_sync_hmp(hammer_mount_t hmp, int waitfor);
482 int     hammer_sync_volume(hammer_volume_t volume, void *data);
483 int     hammer_sync_buffer(hammer_buffer_t buffer, void *data);
484
485 hammer_record_t
486         hammer_alloc_mem_record(hammer_inode_t ip);
487 void    hammer_rel_mem_record(hammer_record_t record);
488
489 int     hammer_cursor_up(hammer_cursor_t cursor);
490 int     hammer_cursor_down(hammer_cursor_t cursor);
491 int     hammer_cursor_upgrade(hammer_cursor_t cursor);
492 void    hammer_cursor_downgrade(hammer_cursor_t cursor);
493 int     hammer_cursor_seek(hammer_cursor_t cursor, hammer_node_t node,
494                         int index);
495 void    hammer_lock_ex(struct hammer_lock *lock);
496 int     hammer_lock_ex_try(struct hammer_lock *lock);
497 void    hammer_lock_sh(struct hammer_lock *lock);
498 int     hammer_lock_upgrade(struct hammer_lock *lock);
499 void    hammer_lock_downgrade(struct hammer_lock *lock);
500 void    hammer_unlock(struct hammer_lock *lock);
501 void    hammer_ref(struct hammer_lock *lock);
502 void    hammer_unref(struct hammer_lock *lock);
503
504 u_int32_t hammer_to_unix_xid(uuid_t *uuid);
505 void hammer_guid_to_uuid(uuid_t *uuid, u_int32_t guid);
506 void    hammer_to_timespec(hammer_tid_t tid, struct timespec *ts);
507 hammer_tid_t hammer_timespec_to_transid(struct timespec *ts);
508 hammer_tid_t hammer_alloc_tid(hammer_transaction_t trans);
509 hammer_tid_t hammer_now_tid(void);
510 hammer_tid_t hammer_str_to_tid(const char *str);
511
512 enum vtype hammer_get_vnode_type(u_int8_t obj_type);
513 int hammer_get_dtype(u_int8_t obj_type);
514 u_int8_t hammer_get_obj_type(enum vtype vtype);
515 int64_t hammer_directory_namekey(void *name, int len);
516
517 int     hammer_init_cursor(hammer_transaction_t trans, hammer_cursor_t cursor,
518                            struct hammer_node **cache);
519
520 void    hammer_done_cursor(hammer_cursor_t cursor);
521 void    hammer_mem_done(hammer_cursor_t cursor);
522
523 int     hammer_btree_lookup(hammer_cursor_t cursor);
524 int     hammer_btree_first(hammer_cursor_t cursor);
525 int     hammer_btree_last(hammer_cursor_t cursor);
526 int     hammer_btree_extract(hammer_cursor_t cursor, int flags);
527 int     hammer_btree_iterate(hammer_cursor_t cursor);
528 int     hammer_btree_iterate_reverse(hammer_cursor_t cursor);
529 int     hammer_btree_insert(hammer_cursor_t cursor, hammer_btree_elm_t elm);
530 int     hammer_btree_delete(hammer_cursor_t cursor);
531 int     hammer_btree_cmp(hammer_base_elm_t key1, hammer_base_elm_t key2);
532 int     hammer_btree_chkts(hammer_tid_t ts, hammer_base_elm_t key);
533 int     hammer_btree_correct_rhb(hammer_cursor_t cursor, hammer_tid_t tid);
534 int     hammer_btree_correct_lhb(hammer_cursor_t cursor, hammer_tid_t tid);
535
536
537 int     hammer_btree_lock_children(hammer_cursor_t cursor,
538                         struct hammer_node_locklist **locklistp);
539
540 void    hammer_print_btree_node(hammer_node_ondisk_t ondisk);
541 void    hammer_print_btree_elm(hammer_btree_elm_t elm, u_int8_t type, int i);
542
543 void    *hammer_bread(struct hammer_mount *hmp, hammer_off_t off,
544                         int *errorp, struct hammer_buffer **bufferp);
545 void    *hammer_bnew(struct hammer_mount *hmp, hammer_off_t off,
546                         int *errorp, struct hammer_buffer **bufferp);
547
548 hammer_volume_t hammer_get_root_volume(hammer_mount_t hmp, int *errorp);
549
550 hammer_volume_t hammer_get_volume(hammer_mount_t hmp,
551                         int32_t vol_no, int *errorp);
552 hammer_buffer_t hammer_get_buffer(hammer_mount_t hmp,
553                         hammer_off_t buf_offset, int isnew, int *errorp);
554 void    hammer_uncache_buffer(struct hammer_mount *hmp, hammer_off_t off);
555
556 int             hammer_ref_volume(hammer_volume_t volume);
557 int             hammer_ref_buffer(hammer_buffer_t buffer);
558 void            hammer_flush_buffer_nodes(hammer_buffer_t buffer);
559
560 void            hammer_rel_volume(hammer_volume_t volume, int flush);
561 void            hammer_rel_buffer(hammer_buffer_t buffer, int flush);
562
563 int             hammer_vfs_export(struct mount *mp, int op,
564                         const struct export_args *export);
565 hammer_node_t   hammer_get_node(hammer_mount_t hmp,
566                         hammer_off_t node_offset, int *errorp);
567 int             hammer_ref_node(hammer_node_t node);
568 hammer_node_t   hammer_ref_node_safe(struct hammer_mount *hmp,
569                         struct hammer_node **cache, int *errorp);
570 void            hammer_rel_node(hammer_node_t node);
571 void            hammer_delete_node(hammer_transaction_t trans,
572                         hammer_node_t node);
573 void            hammer_cache_node(hammer_node_t node,
574                         struct hammer_node **cache);
575 void            hammer_uncache_node(struct hammer_node **cache);
576 void            hammer_flush_node(hammer_node_t node);
577
578 void hammer_dup_buffer(struct hammer_buffer **bufferp,
579                         struct hammer_buffer *buffer);
580 hammer_node_t hammer_alloc_btree(hammer_transaction_t trans, int *errorp);
581 void *hammer_alloc_record(hammer_transaction_t trans,
582                         hammer_off_t *rec_offp, u_int16_t rec_type,
583                         struct hammer_buffer **rec_bufferp,
584                         int32_t data_len, void **datap,
585                         struct hammer_buffer **data_bufferp, int *errorp);
586 void *hammer_alloc_data(hammer_transaction_t trans, int32_t data_len,
587                         hammer_off_t *data_offsetp,
588                         struct hammer_buffer **data_bufferp, int *errorp);
589
590 int hammer_generate_undo(hammer_transaction_t trans, hammer_off_t zone1_offset,
591                         void *base, int len);
592
593 void hammer_put_volume(struct hammer_volume *volume, int flush);
594 void hammer_put_buffer(struct hammer_buffer *buffer, int flush);
595
596 hammer_off_t hammer_freemap_alloc(hammer_transaction_t trans,
597                         hammer_off_t owner, int *errorp);
598 void hammer_freemap_free(hammer_transaction_t trans, hammer_off_t phys_offset,
599                         hammer_off_t owner, int *errorp);
600 hammer_off_t hammer_blockmap_alloc(hammer_transaction_t trans, int zone,
601                         int bytes, int *errorp);
602 void hammer_blockmap_free(hammer_transaction_t trans,
603                         hammer_off_t bmap_off, int bytes);
604 int hammer_blockmap_getfree(hammer_mount_t hmp, hammer_off_t bmap_off,
605                         int *curp, int *errorp);
606 hammer_off_t hammer_blockmap_lookup(hammer_mount_t hmp, hammer_off_t bmap_off,
607                         int *errorp);
608 hammer_off_t hammer_undo_lookup(hammer_mount_t hmp, hammer_off_t bmap_off,
609                         int *errorp);
610
611 void hammer_start_transaction(struct hammer_transaction *trans,
612                               struct hammer_mount *hmp);
613 void hammer_simple_transaction(struct hammer_transaction *trans,
614                               struct hammer_mount *hmp);
615 void hammer_start_transaction_tid(struct hammer_transaction *trans,
616                                   struct hammer_mount *hmp, hammer_tid_t tid);
617 void hammer_commit_transaction(struct hammer_transaction *trans);
618 void hammer_abort_transaction(struct hammer_transaction *trans);
619
620 void hammer_modify_inode(struct hammer_transaction *trans,
621                         hammer_inode_t ip, int flags);
622 int  hammer_create_inode(struct hammer_transaction *trans, struct vattr *vap,
623                         struct ucred *cred, struct hammer_inode *dip,
624                         struct hammer_inode **ipp);
625 void hammer_rel_inode(hammer_inode_t ip, int flush);
626 int hammer_sync_inode(hammer_inode_t ip, int waitfor, int handle_delete);
627
628 int  hammer_ip_add_directory(struct hammer_transaction *trans,
629                         hammer_inode_t dip, struct namecache *ncp,
630                         hammer_inode_t nip);
631 int  hammer_ip_del_directory(struct hammer_transaction *trans,
632                         hammer_cursor_t cursor, hammer_inode_t dip,
633                         hammer_inode_t ip);
634 int  hammer_ip_add_record(struct hammer_transaction *trans,
635                         hammer_record_t record);
636 int  hammer_ip_delete_range(struct hammer_transaction *trans,
637                         hammer_inode_t ip, int64_t ran_beg, int64_t ran_end);
638 int  hammer_ip_delete_range_all(struct hammer_transaction *trans,
639                         hammer_inode_t ip);
640 int  hammer_ip_sync_data(struct hammer_transaction *trans,
641                         hammer_inode_t ip, int64_t offset,
642                         void *data, int bytes);
643 int  hammer_ip_sync_record(hammer_transaction_t trans, hammer_record_t rec);
644
645 int hammer_ioctl(hammer_inode_t ip, u_long com, caddr_t data, int fflag,
646                         struct ucred *cred);
647
648 void hammer_io_init(hammer_io_t io, enum hammer_io_type type);
649 int hammer_io_read(struct vnode *devvp, struct hammer_io *io);
650 int hammer_io_new(struct vnode *devvp, struct hammer_io *io);
651 void hammer_io_release(struct hammer_io *io);
652 void hammer_io_flush(struct hammer_io *io);
653 int hammer_io_checkflush(hammer_io_t io);
654 void hammer_io_clear_modify(struct hammer_io *io);
655 void hammer_io_waitdep(struct hammer_io *io);
656
657 void hammer_modify_volume(hammer_transaction_t trans, hammer_volume_t volume,
658                         void *base, int len);
659 void hammer_modify_buffer(hammer_transaction_t trans, hammer_buffer_t buffer,
660                         void *base, int len);
661
662 int hammer_ioc_reblock(hammer_transaction_t trans, hammer_inode_t ip,
663                         struct hammer_ioc_reblock *reblock);
664
665 void hammer_init_holes(hammer_mount_t hmp, hammer_holes_t holes);
666 void hammer_free_holes(hammer_mount_t hmp, hammer_holes_t holes);
667 int hammer_signal_check(hammer_mount_t hmp);
668
669 #endif
670
671 static __inline void
672 hammer_modify_node_noundo(hammer_transaction_t trans, hammer_node_t node)
673 {
674         hammer_modify_buffer(trans, node->buffer, NULL, 0);
675 }
676
677 static __inline void
678 hammer_modify_node_all(hammer_transaction_t trans, struct hammer_node *node)
679 {
680         hammer_modify_buffer(trans, node->buffer,
681                              node->ondisk, sizeof(*node->ondisk));
682 }
683
684 static __inline void
685 hammer_modify_node(hammer_transaction_t trans, hammer_node_t node,
686                    void *base, int len)
687 {
688         KKASSERT((char *)base >= (char *)node->ondisk &&
689                  (char *)base + len <=
690                     (char *)node->ondisk + sizeof(*node->ondisk));
691         hammer_modify_buffer(trans, node->buffer, base, len);
692 }
693
694 static __inline void
695 hammer_modify_record(hammer_transaction_t trans, hammer_buffer_t buffer,
696                      void *base, int len)
697 {
698         KKASSERT((char *)base >= (char *)buffer->ondisk &&
699                  (char *)base + len <= (char *)buffer->ondisk + HAMMER_BUFSIZE);
700         hammer_modify_buffer(trans, buffer, base, len);
701 }
702