2 * Copyright (c) 2007-2008 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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
34 * $DragonFly: src/sys/vfs/hammer/hammer.h,v 1.82 2008/06/12 00:16:10 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>
45 #include <sys/systm.h>
47 #include <sys/malloc.h>
48 #include <sys/mount.h>
49 #include <sys/mountctl.h>
50 #include <sys/vnode.h>
53 #include <sys/globaldata.h>
54 #include <sys/lockf.h>
56 #include <sys/queue.h>
57 #include <sys/globaldata.h>
60 #include <sys/signal2.h>
61 #include "hammer_disk.h"
62 #include "hammer_mount.h"
63 #include "hammer_ioctl.h"
65 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
67 MALLOC_DECLARE(M_HAMMER
);
72 * Key structure used for custom RB tree inode lookups. This prototypes
73 * the function hammer_ino_rb_tree_RB_LOOKUP_INFO(root, info).
75 typedef struct hammer_inode_info
{
76 int64_t obj_id
; /* (key) object identifier */
77 hammer_tid_t obj_asof
; /* (key) snapshot transid or 0 */
78 } *hammer_inode_info_t
;
80 typedef enum hammer_transaction_type
{
84 } hammer_transaction_type_t
;
87 * HAMMER Transaction tracking
89 struct hammer_transaction
{
90 hammer_transaction_type_t type
;
91 struct hammer_mount
*hmp
;
95 struct hammer_volume
*rootvol
;
98 typedef struct hammer_transaction
*hammer_transaction_t
;
104 int refs
; /* active references delay writes */
105 int lockcount
; /* lock count for exclusive/shared access */
107 struct thread
*locktd
;
111 hammer_islocked(struct hammer_lock
*lock
)
113 return(lock
->lockcount
!= 0);
117 hammer_isactive(struct hammer_lock
*lock
)
119 return(lock
->refs
!= 0);
123 hammer_islastref(struct hammer_lock
*lock
)
125 return(lock
->refs
== 1);
129 * Return if we specifically own the lock exclusively.
132 hammer_lock_excl_owned(struct hammer_lock
*lock
, thread_t td
)
134 if (lock
->lockcount
> 0 && lock
->locktd
== td
)
140 * Flush state, used by various structures
142 typedef enum hammer_inode_state
{
146 } hammer_inode_state_t
;
148 TAILQ_HEAD(hammer_record_list
, hammer_record
);
151 * Cache object ids. A fixed number of objid cache structures are
152 * created to reserve object id's for newly created files in multiples
153 * of 100,000, localized to a particular directory, and recycled as
154 * needed. This allows parallel create operations in different
155 * directories to retain fairly localized object ids which in turn
156 * improves reblocking performance and layout.
158 #define OBJID_CACHE_SIZE 128
159 #define OBJID_CACHE_BULK 100000
161 typedef struct hammer_objid_cache
{
162 TAILQ_ENTRY(hammer_objid_cache
) entry
;
163 struct hammer_inode
*dip
;
164 hammer_tid_t next_tid
;
166 } *hammer_objid_cache_t
;
169 * Structure used to represent an inode in-memory.
171 * The record and data associated with an inode may be out of sync with
172 * the disk (xDIRTY flags), or not even on the disk at all (ONDISK flag
175 * An inode may also hold a cache of unsynchronized records, used for
176 * database and directories only. Unsynchronized regular file data is
177 * stored in the buffer cache.
179 * NOTE: A file which is created and destroyed within the initial
180 * synchronization period can wind up not doing any disk I/O at all.
182 * Finally, an inode may cache numerous disk-referencing B-Tree cursors.
184 struct hammer_ino_rb_tree
;
186 RB_HEAD(hammer_ino_rb_tree
, hammer_inode
);
187 RB_PROTOTYPEX(hammer_ino_rb_tree
, INFO
, hammer_inode
, rb_node
,
188 hammer_ino_rb_compare
, hammer_inode_info_t
);
190 struct hammer_rec_rb_tree
;
191 struct hammer_record
;
192 RB_HEAD(hammer_rec_rb_tree
, hammer_record
);
193 RB_PROTOTYPEX(hammer_rec_rb_tree
, INFO
, hammer_record
, rb_node
,
194 hammer_rec_rb_compare
, hammer_btree_leaf_elm_t
);
196 TAILQ_HEAD(hammer_node_list
, hammer_node
);
198 struct hammer_inode
{
199 RB_ENTRY(hammer_inode
) rb_node
;
200 hammer_inode_state_t flush_state
;
202 TAILQ_ENTRY(hammer_inode
) flush_entry
;
203 struct hammer_record_list target_list
; /* target of dependant recs */
204 u_int64_t obj_id
; /* (key) object identifier */
205 hammer_tid_t obj_asof
; /* (key) snapshot or 0 */
206 struct hammer_mount
*hmp
;
207 hammer_objid_cache_t objid_cache
;
209 int error
; /* flush error */
210 int cursor_ip_refs
; /* sanity */
215 struct lockf advlock
;
216 struct hammer_lock lock
; /* sync copy interlock */
218 struct hammer_btree_leaf_elm ino_leaf
; /* in-memory cache */
219 struct hammer_inode_data ino_data
; /* in-memory cache */
220 struct hammer_rec_rb_tree rec_tree
; /* in-memory cache */
221 struct hammer_node
*cache
[2]; /* search initiate cache */
224 * When a demark is created to synchronize an inode to
225 * disk, certain fields are copied so the front-end VOPs
226 * can continue to run in parallel with the synchronization
227 * occuring in the background.
229 int sync_flags
; /* to-sync flags cache */
230 off_t sync_trunc_off
; /* to-sync truncation */
231 struct hammer_btree_leaf_elm sync_ino_leaf
; /* to-sync cache */
232 struct hammer_inode_data sync_ino_data
; /* to-sync cache */
235 typedef struct hammer_inode
*hammer_inode_t
;
237 #define VTOI(vp) ((struct hammer_inode *)(vp)->v_data)
239 #define HAMMER_INODE_DDIRTY 0x0001 /* in-memory ino_data is dirty */
240 #define HAMMER_INODE_RSV_INODES 0x0002 /* hmp->rsv_inodes bumped */
241 #define HAMMER_INODE_ITIMES 0x0004 /* in-memory mtime/atime modified */
242 #define HAMMER_INODE_XDIRTY 0x0008 /* in-memory records */
243 #define HAMMER_INODE_ONDISK 0x0010 /* inode is on-disk (else not yet) */
244 #define HAMMER_INODE_FLUSH 0x0020 /* flush on last ref */
245 #define HAMMER_INODE_DELETED 0x0080 /* inode delete (backend) */
246 #define HAMMER_INODE_DELONDISK 0x0100 /* delete synchronized to disk */
247 #define HAMMER_INODE_RO 0x0200 /* read-only (because of as-of) */
248 #define HAMMER_INODE_VHELD 0x0400 /* vnode held on sync */
249 #define HAMMER_INODE_DONDISK 0x0800 /* data records may be on disk */
250 #define HAMMER_INODE_BUFS 0x1000 /* dirty high level bps present */
251 #define HAMMER_INODE_REFLUSH 0x2000 /* pipelined flush during flush */
252 #define HAMMER_INODE_RECLAIM 0x4000 /* trying to reclaim */
253 #define HAMMER_INODE_FLUSHW 0x8000 /* Someone waiting for flush */
255 #define HAMMER_INODE_TRUNCATED 0x00010000
256 #define HAMMER_INODE_DELETING 0x00020000 /* inode delete request (frontend)*/
257 #define HAMMER_INODE_RESIGNAL 0x00040000 /* re-signal on re-flush */
258 #define HAMMER_INODE_PARTIALW 0x00080000 /* wait partial record flush */
260 #define HAMMER_INODE_MODMASK (HAMMER_INODE_DDIRTY| \
261 HAMMER_INODE_XDIRTY|HAMMER_INODE_BUFS| \
262 HAMMER_INODE_ITIMES|HAMMER_INODE_TRUNCATED|\
263 HAMMER_INODE_DELETING)
264 #define HAMMER_INODE_MODEASY (HAMMER_INODE_DDIRTY|HAMMER_INODE_ITIMES)
266 #define HAMMER_INODE_MODMASK_NOXDIRTY \
267 (HAMMER_INODE_MODMASK & ~HAMMER_INODE_XDIRTY)
269 #define HAMMER_MAX_INODE_CURSORS 4
271 #define HAMMER_FLUSH_SIGNAL 0x0001
272 #define HAMMER_FLUSH_RECURSION 0x0002
274 #define HAMMER_RECLAIM_MIN 2000 /* absolute value */
275 #define HAMMER_RECLAIM_MID 4000 /* absolute value */
276 #define HAMMER_RECLAIM_MAX 6000 /* absolute value */
279 * Structure used to represent an unsynchronized record in-memory. These
280 * records typically represent directory entries. Only non-historical
281 * records are kept in-memory.
283 * Records are organized as a per-inode RB-Tree. If the inode is not
284 * on disk then neither are any records and the in-memory record tree
285 * represents the entire contents of the inode. If the inode is on disk
286 * then the on-disk B-Tree is scanned in parallel with the in-memory
287 * RB-Tree to synthesize the current state of the file.
289 * Records are also used to enforce the ordering of directory create/delete
290 * operations. A new inode will not be flushed to disk unless its related
291 * directory entry is also being flushed at the same time. A directory entry
292 * will not be removed unless its related inode is also being removed at the
295 typedef enum hammer_record_type
{
296 HAMMER_MEM_RECORD_GENERAL
, /* misc record */
297 HAMMER_MEM_RECORD_INODE
, /* inode record */
298 HAMMER_MEM_RECORD_ADD
, /* positive memory cache record */
299 HAMMER_MEM_RECORD_DEL
, /* negative delete-on-disk record */
300 HAMMER_MEM_RECORD_DATA
/* bulk-data record w/on-disk ref */
301 } hammer_record_type_t
;
303 struct hammer_record
{
304 RB_ENTRY(hammer_record
) rb_node
;
305 TAILQ_ENTRY(hammer_record
) target_entry
;
306 hammer_inode_state_t flush_state
;
308 hammer_record_type_t type
;
309 struct hammer_lock lock
;
310 struct hammer_reserve
*resv
;
311 struct hammer_inode
*ip
;
312 struct hammer_inode
*target_ip
;
313 struct hammer_btree_leaf_elm leaf
;
314 union hammer_data_ondisk
*data
;
318 typedef struct hammer_record
*hammer_record_t
;
321 * Record flags. Note that FE can only be set by the frontend if the
322 * record has not been interlocked by the backend w/ BE.
324 #define HAMMER_RECF_ALLOCDATA 0x0001
325 #define HAMMER_RECF_ONRBTREE 0x0002
326 #define HAMMER_RECF_DELETED_FE 0x0004 /* deleted (frontend) */
327 #define HAMMER_RECF_DELETED_BE 0x0008 /* deleted (backend) */
328 #define HAMMER_RECF_UNUSED0010 0x0010
329 #define HAMMER_RECF_INTERLOCK_BE 0x0020 /* backend interlock */
330 #define HAMMER_RECF_WANTED 0x0040 /* wanted by the frontend */
331 #define HAMMER_RECF_WANTIDLE 0x0080 /* wanted when idle */
332 #define HAMMER_RECF_CONVERT_DELETE 0x0100 /* special case */
335 * In-memory structures representing on-disk structures.
337 struct hammer_volume
;
338 struct hammer_buffer
;
341 struct hammer_reserve
;
343 RB_HEAD(hammer_vol_rb_tree
, hammer_volume
);
344 RB_HEAD(hammer_buf_rb_tree
, hammer_buffer
);
345 RB_HEAD(hammer_nod_rb_tree
, hammer_node
);
346 RB_HEAD(hammer_und_rb_tree
, hammer_undo
);
347 RB_HEAD(hammer_res_rb_tree
, hammer_reserve
);
349 RB_PROTOTYPE2(hammer_vol_rb_tree
, hammer_volume
, rb_node
,
350 hammer_vol_rb_compare
, int32_t);
351 RB_PROTOTYPE2(hammer_buf_rb_tree
, hammer_buffer
, rb_node
,
352 hammer_buf_rb_compare
, hammer_off_t
);
353 RB_PROTOTYPE2(hammer_nod_rb_tree
, hammer_node
, rb_node
,
354 hammer_nod_rb_compare
, hammer_off_t
);
355 RB_PROTOTYPE2(hammer_und_rb_tree
, hammer_undo
, rb_node
,
356 hammer_und_rb_compare
, hammer_off_t
);
357 RB_PROTOTYPE2(hammer_res_rb_tree
, hammer_reserve
, rb_node
,
358 hammer_res_rb_compare
, hammer_off_t
);
361 * IO management - embedded at the head of various in-memory structures
363 * VOLUME - hammer_volume containing meta-data
364 * META_BUFFER - hammer_buffer containing meta-data
365 * DATA_BUFFER - hammer_buffer containing pure-data
367 * Dirty volume headers and dirty meta-data buffers are locked until the
368 * flusher can sequence them out. Dirty pure-data buffers can be written.
369 * Clean buffers can be passively released.
371 typedef enum hammer_io_type
{
372 HAMMER_STRUCTURE_VOLUME
,
373 HAMMER_STRUCTURE_META_BUFFER
,
374 HAMMER_STRUCTURE_UNDO_BUFFER
,
375 HAMMER_STRUCTURE_DATA_BUFFER
378 union hammer_io_structure
;
382 LIST_ENTRY(worklist
) node
;
385 TAILQ_HEAD(hammer_io_list
, hammer_io
);
386 typedef struct hammer_io_list
*hammer_io_list_t
;
389 struct worklist worklist
;
390 struct hammer_lock lock
;
391 enum hammer_io_type type
;
392 struct hammer_mount
*hmp
;
393 TAILQ_ENTRY(hammer_io
) mod_entry
; /* list entry if modified */
394 hammer_io_list_t mod_list
;
397 int loading
; /* loading/unloading interlock */
400 u_int modified
: 1; /* bp's data was modified */
401 u_int released
: 1; /* bp released (w/ B_LOCKED set) */
402 u_int running
: 1; /* bp write IO in progress */
403 u_int waiting
: 1; /* someone is waiting on us */
404 u_int validated
: 1; /* ondisk has been validated */
405 u_int waitdep
: 1; /* flush waits for dependancies */
406 u_int recovered
: 1; /* has recovery ref */
407 u_int waitmod
: 1; /* waiting for modify_refs */
408 u_int reclaim
: 1; /* reclaim requested */
411 typedef struct hammer_io
*hammer_io_t
;
413 #define HAMMER_CLUSTER_SIZE (64 * 1024)
414 #if HAMMER_CLUSTER_SIZE > MAXBSIZE
415 #undef HAMMER_CLUSTER_SIZE
416 #define HAMMER_CLUSTER_SIZE MAXBSIZE
418 #define HAMMER_CLUSTER_BUFS (HAMMER_CLUSTER_SIZE / HAMMER_BUFSIZE)
421 * In-memory volume representing on-disk buffer
423 struct hammer_volume
{
425 RB_ENTRY(hammer_volume
) rb_node
;
426 struct hammer_volume_ondisk
*ondisk
;
428 int64_t nblocks
; /* note: special calculation for statfs */
429 int64_t buffer_base
; /* base offset of buffer 0 */
430 hammer_off_t maxbuf_off
; /* Maximum buffer offset (zone-2) */
431 hammer_off_t maxraw_off
; /* Maximum raw offset for device */
437 typedef struct hammer_volume
*hammer_volume_t
;
440 * In-memory buffer (other then volume, super-cluster, or cluster),
441 * representing an on-disk buffer.
443 struct hammer_buffer
{
445 RB_ENTRY(hammer_buffer
) rb_node
;
447 struct hammer_volume
*volume
;
448 hammer_off_t zoneX_offset
;
449 hammer_off_t zone2_offset
;
450 struct hammer_reserve
*resv
;
451 struct hammer_node_list clist
;
454 typedef struct hammer_buffer
*hammer_buffer_t
;
457 * In-memory B-Tree node, representing an on-disk B-Tree node.
459 * This is a hang-on structure which is backed by a hammer_buffer,
460 * indexed by a hammer_cluster, and used for fine-grained locking of
461 * B-Tree nodes in order to properly control lock ordering. A hammer_buffer
462 * can contain multiple nodes representing wildly disassociated portions
463 * of the B-Tree so locking cannot be done on a buffer-by-buffer basis.
465 * This structure uses a cluster-relative index to reduce the number
466 * of layers required to access it, and also because all on-disk B-Tree
467 * references are cluster-relative offsets.
470 struct hammer_lock lock
; /* node-by-node lock */
471 TAILQ_ENTRY(hammer_node
) entry
; /* per-buffer linkage */
472 RB_ENTRY(hammer_node
) rb_node
; /* per-cluster linkage */
473 hammer_off_t node_offset
; /* full offset spec */
474 struct hammer_mount
*hmp
;
475 struct hammer_buffer
*buffer
; /* backing buffer */
476 hammer_node_ondisk_t ondisk
; /* ptr to on-disk structure */
477 struct hammer_node
**cache1
; /* passive cache(s) */
478 struct hammer_node
**cache2
;
480 int loading
; /* load interlock */
483 #define HAMMER_NODE_DELETED 0x0001
484 #define HAMMER_NODE_FLUSH 0x0002
486 typedef struct hammer_node
*hammer_node_t
;
489 * List of locked nodes.
491 struct hammer_node_locklist
{
492 struct hammer_node_locklist
*next
;
496 typedef struct hammer_node_locklist
*hammer_node_locklist_t
;
500 * Common I/O management structure - embedded in in-memory structures
501 * which are backed by filesystem buffers.
503 union hammer_io_structure
{
505 struct hammer_volume volume
;
506 struct hammer_buffer buffer
;
509 typedef union hammer_io_structure
*hammer_io_structure_t
;
512 * Allocation holes are recorded when an allocation does not fit within a
513 * buffer. Later allocations which might fit may then be satisfied from
514 * a recorded hole. The resv reference prevents the big block from being
515 * allocated out of via the normal blockmap mechanism.
517 * This is strictly a heuristic.
519 #define HAMMER_MAX_HOLES 8
523 struct hammer_holes
{
524 TAILQ_HEAD(, hammer_hole
) list
;
528 typedef struct hammer_holes
*hammer_holes_t
;
531 TAILQ_ENTRY(hammer_hole
) entry
;
532 struct hammer_reserve
*resv
;
533 hammer_off_t zone_offset
;
537 typedef struct hammer_hole
*hammer_hole_t
;
540 * The reserve structure prevents the blockmap from allocating
541 * out of a reserved bigblock. Such reservations are used by
542 * the direct-write mechanism.
544 * The structure is also used to hold off on reallocations of
545 * big blocks from the freemap until flush dependancies have
548 struct hammer_reserve
{
549 RB_ENTRY(hammer_reserve
) rb_node
;
550 TAILQ_ENTRY(hammer_reserve
) delay_entry
;
553 hammer_off_t zone_offset
;
556 typedef struct hammer_reserve
*hammer_reserve_t
;
558 #include "hammer_cursor.h"
561 * The undo structure tracks recent undos to avoid laying down duplicate
562 * undos within a flush group, saving us a significant amount of overhead.
564 * This is strictly a heuristic.
566 #define HAMMER_MAX_UNDOS 1024
567 #define HAMMER_MAX_FLUSHERS 4
570 RB_ENTRY(hammer_undo
) rb_node
;
571 TAILQ_ENTRY(hammer_undo
) lru_entry
;
576 typedef struct hammer_undo
*hammer_undo_t
;
578 struct hammer_flusher_info
;
580 struct hammer_flusher
{
581 int signal
; /* flusher thread sequencer */
582 int act
; /* currently active flush group */
583 int done
; /* set to act when complete */
584 int next
; /* next flush group */
585 int group_lock
; /* lock sequencing of the next flush */
586 int exiting
; /* request master exit */
587 int count
; /* number of slave flushers */
588 int running
; /* number of slave flushers running */
589 thread_t td
; /* master flusher thread */
590 hammer_tid_t tid
; /* last flushed transaction id */
591 int finalize_want
; /* serialize finalization */
592 struct hammer_lock finalize_lock
; /* serialize finalization */
593 struct hammer_transaction trans
; /* shared transaction */
594 struct hammer_flusher_info
*info
[HAMMER_MAX_FLUSHERS
];
598 * Internal hammer mount data structure
600 struct hammer_mount
{
602 /*struct vnode *rootvp;*/
603 struct hammer_ino_rb_tree rb_inos_root
;
604 struct hammer_vol_rb_tree rb_vols_root
;
605 struct hammer_nod_rb_tree rb_nods_root
;
606 struct hammer_und_rb_tree rb_undo_root
;
607 struct hammer_res_rb_tree rb_resv_root
;
608 struct hammer_buf_rb_tree rb_bufs_root
;
609 struct hammer_volume
*rootvol
;
610 struct hammer_base_elm root_btree_beg
;
611 struct hammer_base_elm root_btree_end
;
612 char *zbuf
; /* HAMMER_BUFSIZE bytes worth of all-zeros */
618 int rsv_inodes
; /* reserved space due to dirty inodes */
619 int rsv_databufs
; /* reserved space due to dirty buffers */
620 int rsv_databytes
; /* reserved space due to record data */
621 int rsv_recs
; /* reserved space due to dirty records */
623 int inode_reclaims
; /* inodes pending reclaim by flusher */
624 int count_inodes
; /* total number of inodes */
625 int count_iqueued
; /* inodes queued to flusher */
627 struct hammer_flusher flusher
;
629 u_int check_interrupt
;
632 struct hammer_io_list volu_list
; /* dirty undo buffers */
633 struct hammer_io_list undo_list
; /* dirty undo buffers */
634 struct hammer_io_list data_list
; /* dirty data buffers */
635 struct hammer_io_list alt_data_list
; /* dirty data buffers */
636 struct hammer_io_list meta_list
; /* dirty meta bufs */
637 struct hammer_io_list lose_list
; /* loose buffers */
638 int locked_dirty_count
; /* meta/volu count */
639 int io_running_count
;
640 int objid_cache_count
;
642 hammer_off_t next_tid
;
643 int64_t copy_stat_freebigblocks
; /* number of free bigblocks */
645 u_int32_t namekey_iterator
;
646 hammer_off_t zone_limits
[HAMMER_MAX_ZONES
];
647 struct netexport export
;
648 struct hammer_lock sync_lock
;
649 struct hammer_lock free_lock
;
650 struct hammer_lock undo_lock
;
651 struct hammer_lock blkmap_lock
;
652 struct hammer_blockmap blockmap
[HAMMER_MAX_ZONES
];
653 struct hammer_holes holes
[HAMMER_MAX_ZONES
];
654 struct hammer_undo undos
[HAMMER_MAX_UNDOS
];
656 TAILQ_HEAD(, hammer_undo
) undo_lru_list
;
657 TAILQ_HEAD(, hammer_inode
) flush_list
;
658 TAILQ_HEAD(, hammer_reserve
) delay_list
;
659 TAILQ_HEAD(, hammer_objid_cache
) objid_cache_list
;
662 typedef struct hammer_mount
*hammer_mount_t
;
664 #define HAMMER_MOUNT_WAITIMAX 0x0001
666 struct hammer_sync_info
{
675 extern struct vop_ops hammer_vnode_vops
;
676 extern struct vop_ops hammer_spec_vops
;
677 extern struct vop_ops hammer_fifo_vops
;
678 extern struct bio_ops hammer_bioops
;
680 extern int hammer_debug_io
;
681 extern int hammer_debug_general
;
682 extern int hammer_debug_debug
;
683 extern int hammer_debug_inode
;
684 extern int hammer_debug_locks
;
685 extern int hammer_debug_btree
;
686 extern int hammer_debug_tid
;
687 extern int hammer_debug_recover
;
688 extern int hammer_debug_recover_faults
;
689 extern int hammer_debug_write_release
;
690 extern int hammer_debug_cluster_enable
;
691 extern int hammer_count_inodes
;
692 extern int hammer_count_iqueued
;
693 extern int hammer_count_reclaiming
;
694 extern int hammer_count_records
;
695 extern int hammer_count_record_datas
;
696 extern int hammer_count_volumes
;
697 extern int hammer_count_buffers
;
698 extern int hammer_count_nodes
;
699 extern int hammer_count_dirtybufs
;
700 extern int hammer_count_refedbufs
;
701 extern int hammer_count_reservations
;
702 extern int hammer_count_io_running_read
;
703 extern int hammer_count_io_running_write
;
704 extern int hammer_count_io_locked
;
705 extern int hammer_limit_dirtybufs
;
706 extern int hammer_limit_iqueued
;
707 extern int hammer_limit_irecs
;
708 extern int hammer_limit_recs
;
709 extern int hammer_bio_count
;
710 extern int hammer_stats_btree_iterations
;
711 extern int hammer_stats_record_iterations
;
712 extern int64_t hammer_contention_count
;
714 int hammer_vop_inactive(struct vop_inactive_args
*);
715 int hammer_vop_reclaim(struct vop_reclaim_args
*);
716 int hammer_get_vnode(struct hammer_inode
*ip
, struct vnode
**vpp
);
717 struct hammer_inode
*hammer_get_inode(hammer_transaction_t trans
,
718 struct hammer_node
**cache
,
719 u_int64_t obj_id
, hammer_tid_t asof
, int flags
,
721 void hammer_put_inode(struct hammer_inode
*ip
);
722 void hammer_put_inode_ref(struct hammer_inode
*ip
);
724 int hammer_unload_volume(hammer_volume_t volume
, void *data __unused
);
725 int hammer_adjust_volume_mode(hammer_volume_t volume
, void *data __unused
);
727 int hammer_unload_buffer(hammer_buffer_t buffer
, void *data __unused
);
728 int hammer_install_volume(hammer_mount_t hmp
, const char *volname
);
730 int hammer_ip_lookup(hammer_cursor_t cursor
);
731 int hammer_ip_first(hammer_cursor_t cursor
);
732 int hammer_ip_next(hammer_cursor_t cursor
);
733 int hammer_ip_resolve_data(hammer_cursor_t cursor
);
734 int hammer_ip_delete_record(hammer_cursor_t cursor
, hammer_inode_t ip
,
736 int hammer_delete_at_cursor(hammer_cursor_t cursor
, int64_t *stat_bytes
);
737 int hammer_ip_check_directory_empty(hammer_transaction_t trans
,
739 int hammer_sync_hmp(hammer_mount_t hmp
, int waitfor
);
740 int hammer_queue_inodes_flusher(hammer_mount_t hmp
, int waitfor
);
744 hammer_alloc_mem_record(hammer_inode_t ip
, int data_len
);
745 void hammer_flush_record_done(hammer_record_t record
, int error
);
746 void hammer_wait_mem_record_ident(hammer_record_t record
, const char *ident
);
747 void hammer_rel_mem_record(hammer_record_t record
);
749 int hammer_cursor_up(hammer_cursor_t cursor
);
750 int hammer_cursor_up_locked(hammer_cursor_t cursor
);
751 int hammer_cursor_down(hammer_cursor_t cursor
);
752 int hammer_cursor_upgrade(hammer_cursor_t cursor
);
753 void hammer_cursor_downgrade(hammer_cursor_t cursor
);
754 int hammer_cursor_seek(hammer_cursor_t cursor
, hammer_node_t node
,
756 void hammer_lock_ex_ident(struct hammer_lock
*lock
, const char *ident
);
757 int hammer_lock_ex_try(struct hammer_lock
*lock
);
758 void hammer_lock_sh(struct hammer_lock
*lock
);
759 int hammer_lock_sh_try(struct hammer_lock
*lock
);
760 int hammer_lock_upgrade(struct hammer_lock
*lock
);
761 void hammer_lock_downgrade(struct hammer_lock
*lock
);
762 void hammer_unlock(struct hammer_lock
*lock
);
763 void hammer_ref(struct hammer_lock
*lock
);
764 void hammer_unref(struct hammer_lock
*lock
);
766 void hammer_sync_lock_ex(hammer_transaction_t trans
);
767 void hammer_sync_lock_sh(hammer_transaction_t trans
);
768 int hammer_sync_lock_sh_try(hammer_transaction_t trans
);
769 void hammer_sync_unlock(hammer_transaction_t trans
);
771 u_int32_t
hammer_to_unix_xid(uuid_t
*uuid
);
772 void hammer_guid_to_uuid(uuid_t
*uuid
, u_int32_t guid
);
773 void hammer_to_timespec(hammer_tid_t tid
, struct timespec
*ts
);
774 hammer_tid_t
hammer_timespec_to_transid(struct timespec
*ts
);
775 hammer_tid_t
hammer_now_tid(void);
776 hammer_tid_t
hammer_str_to_tid(const char *str
);
777 hammer_tid_t
hammer_alloc_objid(hammer_transaction_t trans
, hammer_inode_t dip
);
778 void hammer_clear_objid(hammer_inode_t dip
);
779 void hammer_destroy_objid_cache(hammer_mount_t hmp
);
781 int hammer_enter_undo_history(hammer_mount_t hmp
, hammer_off_t offset
,
783 void hammer_clear_undo_history(hammer_mount_t hmp
);
784 enum vtype
hammer_get_vnode_type(u_int8_t obj_type
);
785 int hammer_get_dtype(u_int8_t obj_type
);
786 u_int8_t
hammer_get_obj_type(enum vtype vtype
);
787 int64_t hammer_directory_namekey(void *name
, int len
);
788 int hammer_nohistory(hammer_inode_t ip
);
790 int hammer_init_cursor(hammer_transaction_t trans
, hammer_cursor_t cursor
,
791 struct hammer_node
**cache
, hammer_inode_t ip
);
792 int hammer_reinit_cursor(hammer_cursor_t cursor
);
793 void hammer_normalize_cursor(hammer_cursor_t cursor
);
794 void hammer_done_cursor(hammer_cursor_t cursor
);
795 void hammer_mem_done(hammer_cursor_t cursor
);
797 int hammer_btree_lookup(hammer_cursor_t cursor
);
798 int hammer_btree_first(hammer_cursor_t cursor
);
799 int hammer_btree_last(hammer_cursor_t cursor
);
800 int hammer_btree_extract(hammer_cursor_t cursor
, int flags
);
801 int hammer_btree_iterate(hammer_cursor_t cursor
);
802 int hammer_btree_iterate_reverse(hammer_cursor_t cursor
);
803 int hammer_btree_insert(hammer_cursor_t cursor
,
804 hammer_btree_leaf_elm_t elm
);
805 int hammer_btree_delete(hammer_cursor_t cursor
);
806 int hammer_btree_cmp(hammer_base_elm_t key1
, hammer_base_elm_t key2
);
807 int hammer_btree_chkts(hammer_tid_t ts
, hammer_base_elm_t key
);
808 int hammer_btree_correct_rhb(hammer_cursor_t cursor
, hammer_tid_t tid
);
809 int hammer_btree_correct_lhb(hammer_cursor_t cursor
, hammer_tid_t tid
);
811 int btree_set_parent(hammer_transaction_t trans
, hammer_node_t node
,
812 hammer_btree_elm_t elm
);
813 int hammer_btree_lock_children(hammer_cursor_t cursor
,
814 struct hammer_node_locklist
**locklistp
);
815 void hammer_btree_unlock_children(struct hammer_node_locklist
**locklistp
);
818 void hammer_print_btree_node(hammer_node_ondisk_t ondisk
);
819 void hammer_print_btree_elm(hammer_btree_elm_t elm
, u_int8_t type
, int i
);
821 void *hammer_bread(struct hammer_mount
*hmp
, hammer_off_t off
,
822 int *errorp
, struct hammer_buffer
**bufferp
);
823 void *hammer_bnew(struct hammer_mount
*hmp
, hammer_off_t off
,
824 int *errorp
, struct hammer_buffer
**bufferp
);
826 hammer_volume_t
hammer_get_root_volume(hammer_mount_t hmp
, int *errorp
);
828 hammer_volume_t
hammer_get_volume(hammer_mount_t hmp
,
829 int32_t vol_no
, int *errorp
);
830 hammer_buffer_t
hammer_get_buffer(hammer_mount_t hmp
,
831 hammer_off_t buf_offset
, int isnew
, int *errorp
);
832 void hammer_del_buffers(hammer_mount_t hmp
, hammer_off_t base_offset
,
833 hammer_off_t zone2_offset
, int bytes
);
835 int hammer_ref_volume(hammer_volume_t volume
);
836 int hammer_ref_buffer(hammer_buffer_t buffer
);
837 void hammer_flush_buffer_nodes(hammer_buffer_t buffer
);
839 void hammer_rel_volume(hammer_volume_t volume
, int flush
);
840 void hammer_rel_buffer(hammer_buffer_t buffer
, int flush
);
842 int hammer_vfs_export(struct mount
*mp
, int op
,
843 const struct export_args
*export
);
844 hammer_node_t
hammer_get_node(hammer_mount_t hmp
, hammer_off_t node_offset
,
845 int isnew
, int *errorp
);
846 void hammer_ref_node(hammer_node_t node
);
847 hammer_node_t
hammer_ref_node_safe(struct hammer_mount
*hmp
,
848 struct hammer_node
**cache
, int *errorp
);
849 void hammer_rel_node(hammer_node_t node
);
850 void hammer_delete_node(hammer_transaction_t trans
,
852 void hammer_cache_node(hammer_node_t node
,
853 struct hammer_node
**cache
);
854 void hammer_uncache_node(struct hammer_node
**cache
);
855 void hammer_flush_node(hammer_node_t node
);
857 void hammer_dup_buffer(struct hammer_buffer
**bufferp
,
858 struct hammer_buffer
*buffer
);
859 hammer_node_t
hammer_alloc_btree(hammer_transaction_t trans
, int *errorp
);
860 void *hammer_alloc_data(hammer_transaction_t trans
, int32_t data_len
,
861 hammer_off_t
*data_offsetp
,
862 struct hammer_buffer
**data_bufferp
, int *errorp
);
864 int hammer_generate_undo(hammer_transaction_t trans
, hammer_io_t io
,
865 hammer_off_t zone1_offset
, void *base
, int len
);
867 void hammer_put_volume(struct hammer_volume
*volume
, int flush
);
868 void hammer_put_buffer(struct hammer_buffer
*buffer
, int flush
);
870 hammer_off_t
hammer_freemap_alloc(hammer_transaction_t trans
,
871 hammer_off_t owner
, int *errorp
);
872 void hammer_freemap_free(hammer_transaction_t trans
, hammer_off_t phys_offset
,
873 hammer_off_t owner
, int *errorp
);
874 int hammer_checkspace(hammer_mount_t hmp
);
875 hammer_off_t
hammer_blockmap_alloc(hammer_transaction_t trans
, int zone
,
876 int bytes
, int *errorp
);
877 hammer_reserve_t
hammer_blockmap_reserve(hammer_mount_t hmp
, int zone
,
878 int bytes
, hammer_off_t
*zone_offp
, int *errorp
);
879 void hammer_blockmap_reserve_complete(hammer_mount_t hmp
,
880 hammer_reserve_t resv
);
881 void hammer_blockmap_free(hammer_transaction_t trans
,
882 hammer_off_t bmap_off
, int bytes
);
883 int hammer_blockmap_getfree(hammer_mount_t hmp
, hammer_off_t bmap_off
,
884 int *curp
, int *errorp
);
885 hammer_off_t
hammer_blockmap_lookup(hammer_mount_t hmp
, hammer_off_t bmap_off
,
887 hammer_off_t
hammer_undo_lookup(hammer_mount_t hmp
, hammer_off_t bmap_off
,
889 int64_t hammer_undo_used(hammer_mount_t hmp
);
890 int64_t hammer_undo_space(hammer_mount_t hmp
);
891 int64_t hammer_undo_max(hammer_mount_t hmp
);
893 void hammer_start_transaction(struct hammer_transaction
*trans
,
894 struct hammer_mount
*hmp
);
895 void hammer_simple_transaction(struct hammer_transaction
*trans
,
896 struct hammer_mount
*hmp
);
897 void hammer_start_transaction_fls(struct hammer_transaction
*trans
,
898 struct hammer_mount
*hmp
);
899 void hammer_done_transaction(struct hammer_transaction
*trans
);
901 void hammer_modify_inode(hammer_inode_t ip
, int flags
);
902 void hammer_flush_inode(hammer_inode_t ip
, int flags
);
903 void hammer_flush_inode_done(hammer_inode_t ip
);
904 void hammer_wait_inode(hammer_inode_t ip
);
905 void hammer_wait_inode_recs(hammer_inode_t ip
);
907 int hammer_create_inode(struct hammer_transaction
*trans
, struct vattr
*vap
,
908 struct ucred
*cred
, struct hammer_inode
*dip
,
909 struct hammer_inode
**ipp
);
910 void hammer_rel_inode(hammer_inode_t ip
, int flush
);
911 int hammer_reload_inode(hammer_inode_t ip
, void *arg __unused
);
912 int hammer_ino_rb_compare(hammer_inode_t ip1
, hammer_inode_t ip2
);
914 int hammer_sync_inode(hammer_inode_t ip
);
915 void hammer_test_inode(hammer_inode_t ip
);
916 void hammer_inode_unloadable_check(hammer_inode_t ip
, int getvp
);
917 void hammer_inode_waitreclaims(hammer_inode_t ip
);
919 int hammer_ip_add_directory(struct hammer_transaction
*trans
,
920 hammer_inode_t dip
, struct namecache
*ncp
,
922 int hammer_ip_del_directory(struct hammer_transaction
*trans
,
923 hammer_cursor_t cursor
, hammer_inode_t dip
,
925 hammer_record_t
hammer_ip_add_bulk(hammer_inode_t ip
, off_t file_offset
,
926 void *data
, int bytes
, int *errorp
);
927 int hammer_ip_frontend_trunc(struct hammer_inode
*ip
, off_t file_size
);
928 int hammer_ip_add_record(struct hammer_transaction
*trans
,
929 hammer_record_t record
);
930 int hammer_ip_delete_range(hammer_cursor_t cursor
, hammer_inode_t ip
,
931 int64_t ran_beg
, int64_t ran_end
, int truncating
);
932 int hammer_ip_delete_range_all(hammer_cursor_t cursor
, hammer_inode_t ip
,
934 int hammer_ip_sync_data(hammer_cursor_t cursor
, hammer_inode_t ip
,
935 int64_t offset
, void *data
, int bytes
);
936 int hammer_ip_sync_record(hammer_transaction_t trans
, hammer_record_t rec
);
937 int hammer_ip_sync_record_cursor(hammer_cursor_t cursor
, hammer_record_t rec
);
939 int hammer_ioctl(hammer_inode_t ip
, u_long com
, caddr_t data
, int fflag
,
942 void hammer_io_init(hammer_io_t io
, hammer_mount_t hmp
,
943 enum hammer_io_type type
);
944 int hammer_io_read(struct vnode
*devvp
, struct hammer_io
*io
,
946 int hammer_io_new(struct vnode
*devvp
, struct hammer_io
*io
);
947 void hammer_io_inval(hammer_volume_t volume
, hammer_off_t zone2_offset
);
948 void hammer_io_release(struct hammer_io
*io
, int flush
);
949 void hammer_io_flush(struct hammer_io
*io
);
950 void hammer_io_waitdep(struct hammer_io
*io
);
951 void hammer_io_wait_all(hammer_mount_t hmp
, const char *ident
);
952 int hammer_io_direct_read(hammer_mount_t hmp
, hammer_off_t data_offset
,
954 int hammer_io_direct_write(hammer_mount_t hmp
, hammer_btree_leaf_elm_t leaf
,
956 void hammer_io_write_interlock(hammer_io_t io
);
957 void hammer_io_done_interlock(hammer_io_t io
);
958 void hammer_io_clear_modify(struct hammer_io
*io
);
959 void hammer_io_clear_modlist(struct hammer_io
*io
);
960 void hammer_modify_volume(hammer_transaction_t trans
, hammer_volume_t volume
,
961 void *base
, int len
);
962 void hammer_modify_buffer(hammer_transaction_t trans
, hammer_buffer_t buffer
,
963 void *base
, int len
);
964 void hammer_modify_volume_done(hammer_volume_t volume
);
965 void hammer_modify_buffer_done(hammer_buffer_t buffer
);
967 int hammer_ioc_reblock(hammer_transaction_t trans
, hammer_inode_t ip
,
968 struct hammer_ioc_reblock
*reblock
);
969 int hammer_ioc_prune(hammer_transaction_t trans
, hammer_inode_t ip
,
970 struct hammer_ioc_prune
*prune
);
972 void hammer_init_holes(hammer_mount_t hmp
, hammer_holes_t holes
);
973 void hammer_free_holes(hammer_mount_t hmp
, hammer_holes_t holes
);
974 int hammer_signal_check(hammer_mount_t hmp
);
976 void hammer_flusher_create(hammer_mount_t hmp
);
977 void hammer_flusher_destroy(hammer_mount_t hmp
);
978 void hammer_flusher_sync(hammer_mount_t hmp
);
979 void hammer_flusher_async(hammer_mount_t hmp
);
981 int hammer_recover(hammer_mount_t hmp
, hammer_volume_t rootvol
);
982 void hammer_recover_flush_buffers(hammer_mount_t hmp
,
983 hammer_volume_t root_volume
);
985 void hammer_crc_set_blockmap(hammer_blockmap_t blockmap
);
986 void hammer_crc_set_volume(hammer_volume_ondisk_t ondisk
);
988 int hammer_crc_test_blockmap(hammer_blockmap_t blockmap
);
989 int hammer_crc_test_volume(hammer_volume_ondisk_t ondisk
);
990 int hammer_crc_test_btree(hammer_node_ondisk_t ondisk
);
991 void hkprintf(const char *ctl
, ...);
996 hammer_wait_mem_record(hammer_record_t record
)
998 hammer_wait_mem_record_ident(record
, "hmmwai");
1001 static __inline
void
1002 hammer_lock_ex(struct hammer_lock
*lock
)
1004 hammer_lock_ex_ident(lock
, "hmrlck");
1007 static __inline
void
1008 hammer_modify_node_noundo(hammer_transaction_t trans
, hammer_node_t node
)
1010 hammer_modify_buffer(trans
, node
->buffer
, NULL
, 0);
1013 static __inline
void
1014 hammer_modify_node_all(hammer_transaction_t trans
, struct hammer_node
*node
)
1016 hammer_modify_buffer(trans
, node
->buffer
,
1017 node
->ondisk
, sizeof(*node
->ondisk
));
1020 static __inline
void
1021 hammer_modify_node(hammer_transaction_t trans
, hammer_node_t node
,
1022 void *base
, int len
)
1024 hammer_crc_t
*crcptr
;
1026 KKASSERT((char *)base
>= (char *)node
->ondisk
&&
1027 (char *)base
+ len
<=
1028 (char *)node
->ondisk
+ sizeof(*node
->ondisk
));
1029 hammer_modify_buffer(trans
, node
->buffer
, base
, len
);
1030 crcptr
= &node
->ondisk
->crc
;
1031 hammer_modify_buffer(trans
, node
->buffer
, crcptr
, sizeof(hammer_crc_t
));
1032 --node
->buffer
->io
.modify_refs
; /* only want one ref */
1035 static __inline
void
1036 hammer_modify_node_done(hammer_node_t node
)
1038 node
->ondisk
->crc
= crc32(&node
->ondisk
->crc
+ 1, HAMMER_BTREE_CRCSIZE
);
1039 hammer_modify_buffer_done(node
->buffer
);
1042 #define hammer_modify_volume_field(trans, vol, field) \
1043 hammer_modify_volume(trans, vol, &(vol)->ondisk->field, \
1044 sizeof((vol)->ondisk->field))
1046 #define hammer_modify_node_field(trans, node, field) \
1047 hammer_modify_node(trans, node, &(node)->ondisk->field, \
1048 sizeof((node)->ondisk->field))