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