2 * Copyright (c) 2011-2018 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@dragonflybsd.org>
6 * by Venkatesh Srinivas <vsrinivas@dragonflybsd.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * 3. Neither the name of The DragonFly Project nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific, prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * HAMMER2 IN-MEMORY CACHE OF MEDIA STRUCTURES
39 * This header file contains structures used internally by the HAMMER2
40 * implementation. See hammer2_disk.h for on-disk structures.
42 * There is an in-memory representation of all on-media data structure.
43 * Almost everything is represented by a hammer2_chain structure in-memory.
44 * Other higher-level structures typically map to chains.
46 * A great deal of data is accessed simply via its buffer cache buffer,
47 * which is mapped for the duration of the chain's lock. Hammer2 must
48 * implement its own buffer cache layer on top of the system layer to
49 * allow for different threads to lock different sub-block-sized buffers.
51 * When modifications are made to a chain a new filesystem block must be
52 * allocated. Multiple modifications do not typically allocate new blocks
53 * until the current block has been flushed. Flushes do not block the
54 * front-end unless the front-end operation crosses the current inode being
57 * The in-memory representation may remain cached (for example in order to
58 * placemark clustering locks) even after the related data has been
62 #ifndef _VFS_HAMMER2_HAMMER2_H_
63 #define _VFS_HAMMER2_HAMMER2_H_
66 #include <sys/param.h>
68 #include <sys/types.h>
70 #include <sys/kernel.h>
74 #include <sys/systm.h>
77 #include <sys/malloc.h>
78 #include <sys/mount.h>
79 #include <sys/vnode.h>
81 #include <sys/mountctl.h>
84 #include <sys/thread.h>
85 #include <sys/globaldata.h>
86 #include <sys/lockf.h>
88 #include <sys/queue.h>
89 #include <sys/limits.h>
91 #include <sys/mutex.h>
93 #include <sys/kern_syscall.h>
97 #include <sys/signal2.h>
99 #include <sys/mutex2.h>
100 #include <sys/spinlock2.h>
103 #include "hammer2_xxhash.h"
104 #include "hammer2_disk.h"
105 #include "hammer2_mount.h"
106 #include "hammer2_ioctl.h"
109 struct hammer2_chain;
110 struct hammer2_cluster;
111 struct hammer2_inode;
112 struct hammer2_depend;
117 struct hammer2_thread;
121 * Mutex and lock shims. Hammer2 requires support for asynchronous and
122 * abortable locks, and both exclusive and shared spinlocks. Normal
123 * synchronous non-abortable locks can be substituted for spinlocks.
125 typedef mtx_t hammer2_mtx_t;
126 typedef mtx_link_t hammer2_mtx_link_t;
127 typedef mtx_state_t hammer2_mtx_state_t;
129 typedef struct spinlock hammer2_spin_t;
131 #define hammer2_mtx_ex mtx_lock_ex_quick
132 #define hammer2_mtx_ex_try mtx_lock_ex_try
133 #define hammer2_mtx_sh mtx_lock_sh_quick
134 #define hammer2_mtx_sh_again mtx_lock_sh_again
135 #define hammer2_mtx_sh_try mtx_lock_sh_try
136 #define hammer2_mtx_unlock mtx_unlock
137 #define hammer2_mtx_downgrade mtx_downgrade
138 #define hammer2_mtx_owned mtx_owned
139 #define hammer2_mtx_init mtx_init
140 #define hammer2_mtx_temp_release mtx_lock_temp_release
141 #define hammer2_mtx_temp_restore mtx_lock_temp_restore
142 #define hammer2_mtx_refs mtx_lockrefs
144 #define hammer2_spin_init spin_init
145 #define hammer2_spin_sh spin_lock_shared
146 #define hammer2_spin_ex spin_lock
147 #define hammer2_spin_unsh spin_unlock_shared
148 #define hammer2_spin_unex spin_unlock
150 TAILQ_HEAD(hammer2_xop_list, hammer2_xop_head);
151 TAILQ_HEAD(hammer2_chain_list, hammer2_chain);
153 typedef struct hammer2_xop_list hammer2_xop_list_t;
157 * General lock support
161 hammer2_mtx_upgrade_try(hammer2_mtx_t *mtx)
163 return mtx_upgrade_try(mtx);
169 * The xid tracks internal transactional updates.
171 * XXX fix-me, really needs to be 64-bits
173 typedef uint32_t hammer2_xid_t;
175 #define HAMMER2_XID_MIN 0x00000000U
176 #define HAMMER2_XID_MAX 0x7FFFFFFFU
179 * Cap the dynamic calculation for the maximum number of dirty
180 * chains and dirty inodes allowed.
182 #define HAMMER2_LIMIT_DIRTY_CHAINS (1024*1024)
183 #define HAMMER2_LIMIT_DIRTY_INODES (65536)
186 * The chain structure tracks a portion of the media topology from the
187 * root (volume) down. Chains represent volumes, inodes, indirect blocks,
188 * data blocks, and freemap nodes and leafs.
190 * The chain structure utilizes a simple singly-homed topology and the
191 * chain's in-memory topology will move around as the chains do, due mainly
192 * to renames and indirect block creation.
194 * Block Table Updates
196 * Block table updates for insertions and updates are delayed until the
197 * flush. This allows us to avoid having to modify the parent chain
198 * all the way to the root.
200 * Block table deletions are performed immediately (modifying the parent
201 * in the process) because the flush code uses the chain structure to
202 * track delayed updates and the chain will be (likely) gone or moved to
203 * another location in the topology after a deletion.
205 * A prior iteration of the code tried to keep the relationship intact
206 * on deletes by doing a delete-duplicate operation on the chain, but
207 * it added way too much complexity to the codebase.
209 * Flush Synchronization
211 * The flush code must flush modified chains bottom-up. Because chain
212 * structures can shift around and are NOT topologically stable,
213 * modified chains are independently indexed for the flush. As the flush
214 * runs it modifies (or further modifies) and updates the parents,
215 * propagating the flush all the way to the volume root.
217 * Modifying front-end operations can occur during a flush but will block
218 * in two cases: (1) when the front-end tries to operate on the inode
219 * currently in the midst of being flushed and (2) if the front-end
220 * crosses an inode currently being flushed (such as during a rename).
221 * So, for example, if you rename directory "x" to "a/b/c/d/e/f/g/x" and
222 * the flusher is currently working on "a/b/c", the rename will block
223 * temporarily in order to ensure that "x" exists in one place or the
226 * Meta-data statistics are updated by the flusher. The front-end will
227 * make estimates but meta-data must be fully synchronized only during a
228 * flush in order to ensure that it remains correct across a crash.
230 * Multiple flush synchronizations can theoretically be in-flight at the
231 * same time but the implementation is not coded to handle the case and
232 * currently serializes them.
236 * Snapshots currently require the subdirectory tree being snapshotted
237 * to be flushed. The snapshot then creates a new super-root inode which
238 * copies the flushed blockdata of the directory or file that was
243 * - Note that the radix tree runs in powers of 2 only so sub-trees
244 * cannot straddle edges.
246 RB_HEAD(hammer2_chain_tree, hammer2_chain);
247 TAILQ_HEAD(h2_flush_list, hammer2_chain);
248 TAILQ_HEAD(h2_core_list, hammer2_chain);
250 struct hammer2_reptrack {
252 struct hammer2_reptrack *next;
253 struct hammer2_chain *chain;
257 * Core topology for chain (embedded in chain). Protected by a spinlock.
259 struct hammer2_chain_core {
261 struct hammer2_reptrack *reptrack;
262 struct hammer2_chain_tree rbtree; /* sub-chains */
263 int live_zero; /* blockref array opt */
264 u_int live_count; /* live (not deleted) chains in tree */
265 u_int chain_count; /* live + deleted chains under core */
266 int generation; /* generation number (inserts only) */
269 typedef struct hammer2_chain_core hammer2_chain_core_t;
271 RB_HEAD(hammer2_io_tree, hammer2_io);
274 * DIO - Management structure wrapping system buffer cache.
276 * HAMMER2 uses an I/O abstraction that allows it to cache and manipulate
277 * fixed-sized filesystem buffers frontend by variable-sized hammer2_chain
280 /* #define HAMMER2_IO_DEBUG */
282 #ifdef HAMMER2_IO_DEBUG
283 #define HAMMER2_IO_DEBUG_ARGS , const char *file, int line
284 #define HAMMER2_IO_DEBUG_CALL , file, line
285 #define HAMMER2_IO_DEBUG_COUNT 2048
286 #define HAMMER2_IO_DEBUG_MASK (HAMMER2_IO_DEBUG_COUNT - 1)
288 #define HAMMER2_IO_DEBUG_ARGS
289 #define HAMMER2_IO_DEBUG_CALL
293 RB_ENTRY(hammer2_io) rbnode; /* indexed by device offset */
294 struct hammer2_dev *hmp;
299 int act; /* activity */
300 int btype; /* approximate BREF_TYPE_* */
303 #ifdef HAMMER2_IO_DEBUG
308 uint64_t dedup_valid; /* valid for dedup operation */
309 uint64_t dedup_alloc; /* allocated / de-dupable */
310 #ifdef HAMMER2_IO_DEBUG
311 const char *debug_file[HAMMER2_IO_DEBUG_COUNT];
312 void *debug_td[HAMMER2_IO_DEBUG_COUNT];
313 int debug_line[HAMMER2_IO_DEBUG_COUNT];
314 uint64_t debug_refs[HAMMER2_IO_DEBUG_COUNT];
318 typedef struct hammer2_io hammer2_io_t;
320 #define HAMMER2_DIO_INPROG 0x8000000000000000LLU /* bio in progress */
321 #define HAMMER2_DIO_GOOD 0x4000000000000000LLU /* dio->bp is stable */
322 #define HAMMER2_DIO_WAITING 0x2000000000000000LLU /* wait on INPROG */
323 #define HAMMER2_DIO_DIRTY 0x1000000000000000LLU /* flush last drop */
324 #define HAMMER2_DIO_FLUSH 0x0800000000000000LLU /* immediate flush */
326 #define HAMMER2_DIO_MASK 0x00FFFFFFFFFFFFFFLLU
329 * Primary chain structure keeps track of the topology in-memory.
331 struct hammer2_chain {
333 hammer2_chain_core_t core;
334 RB_ENTRY(hammer2_chain) rbnode; /* live chain(s) */
335 hammer2_blockref_t bref;
336 struct hammer2_chain *parent;
337 struct hammer2_dev *hmp;
338 struct hammer2_pfs *pmp; /* A PFS or super-root (spmp) */
340 struct lock diolk; /* xop focus interlock */
341 hammer2_io_t *dio; /* physical data buffer */
342 hammer2_media_data_t *data; /* data pointer shortcut */
343 u_int bytes; /* physical data size */
347 int error; /* on-lock data error state */
348 int cache_index; /* heur speeds up lookup */
350 TAILQ_ENTRY(hammer2_chain) lru_node; /* 0-refs LRU */
353 typedef struct hammer2_chain hammer2_chain_t;
355 int hammer2_chain_cmp(hammer2_chain_t *chain1, hammer2_chain_t *chain2);
356 RB_PROTOTYPE(hammer2_chain_tree, hammer2_chain, rbnode, hammer2_chain_cmp);
359 * Special notes on flags:
361 * INITIAL - This flag allows a chain to be created and for storage to
362 * be allocated without having to immediately instantiate the
363 * related buffer. The data is assumed to be all-zeros. It
364 * is primarily used for indirect blocks.
366 * MODIFIED - The chain's media data has been modified. Prevents chain
367 * free on lastdrop if still in the topology.
369 * UPDATE - Chain might not be modified but parent blocktable needs
370 * an update. Prevents chain free on lastdrop if still in
373 * FICTITIOUS - Faked chain as a placeholder for an error condition. This
374 * chain is unsuitable for I/O.
376 * BMAPPED - Indicates that the chain is present in the parent blockmap.
378 * BMAPUPD - Indicates that the chain is present but needs to be updated
379 * in the parent blockmap.
381 #define HAMMER2_CHAIN_MODIFIED 0x00000001 /* dirty chain data */
382 #define HAMMER2_CHAIN_ALLOCATED 0x00000002 /* kmalloc'd chain */
383 #define HAMMER2_CHAIN_DESTROY 0x00000004
384 #define HAMMER2_CHAIN_DEDUPABLE 0x00000008 /* registered w/dedup */
385 #define HAMMER2_CHAIN_DELETED 0x00000010 /* deleted chain */
386 #define HAMMER2_CHAIN_INITIAL 0x00000020 /* initial create */
387 #define HAMMER2_CHAIN_UPDATE 0x00000040 /* need parent update */
388 #define HAMMER2_CHAIN_UNUSED0080 0x00000080
389 #define HAMMER2_CHAIN_TESTEDGOOD 0x00000100 /* crc tested good */
390 #define HAMMER2_CHAIN_ONFLUSH 0x00000200 /* on a flush list */
391 #define HAMMER2_CHAIN_FICTITIOUS 0x00000400 /* unsuitable for I/O */
392 #define HAMMER2_CHAIN_VOLUMESYNC 0x00000800 /* needs volume sync */
393 #define HAMMER2_CHAIN_UNUSED1000 0x00001000
394 #define HAMMER2_CHAIN_COUNTEDBREFS 0x00002000 /* block table stats */
395 #define HAMMER2_CHAIN_ONRBTREE 0x00004000 /* on parent RB tree */
396 #define HAMMER2_CHAIN_ONLRU 0x00008000 /* on LRU list */
397 #define HAMMER2_CHAIN_EMBEDDED 0x00010000 /* embedded data */
398 #define HAMMER2_CHAIN_RELEASE 0x00020000 /* don't keep around */
399 #define HAMMER2_CHAIN_BMAPPED 0x00040000 /* present in blkmap */
400 #define HAMMER2_CHAIN_BMAPUPD 0x00080000 /* +needs updating */
401 #define HAMMER2_CHAIN_IOINPROG 0x00100000 /* I/O interlock */
402 #define HAMMER2_CHAIN_IOSIGNAL 0x00200000 /* I/O interlock */
403 #define HAMMER2_CHAIN_PFSBOUNDARY 0x00400000 /* super->pfs inode */
404 #define HAMMER2_CHAIN_HINT_LEAF_COUNT 0x00800000 /* redo leaf count */
405 #define HAMMER2_CHAIN_LRUHINT 0x01000000 /* was reused */
407 #define HAMMER2_CHAIN_FLUSH_MASK (HAMMER2_CHAIN_MODIFIED | \
408 HAMMER2_CHAIN_UPDATE | \
409 HAMMER2_CHAIN_ONFLUSH | \
410 HAMMER2_CHAIN_DESTROY)
413 * Hammer2 error codes, used by chain->error and cluster->error. The error
414 * code is typically set on-lock unless no I/O was requested, and set on
415 * I/O otherwise. If set for a cluster it generally means that the cluster
416 * code could not find a valid copy to present.
418 * All H2 error codes are flags and can be accumulated by ORing them
421 * IO - An I/O error occurred
422 * CHECK - I/O succeeded but did not match the check code
423 * INCOMPLETE - A cluster is not complete enough to use, or
424 * a chain cannot be loaded because its parent has an error.
426 * NOTE: API allows callers to check zero/non-zero to determine if an error
429 * NOTE: Chain's data field is usually NULL on an IO error but not necessarily
430 * NULL on other errors. Check chain->error, not chain->data.
432 #define HAMMER2_ERROR_NONE 0 /* no error (must be 0) */
433 #define HAMMER2_ERROR_EIO 0x00000001 /* device I/O error */
434 #define HAMMER2_ERROR_CHECK 0x00000002 /* check code error */
435 #define HAMMER2_ERROR_INCOMPLETE 0x00000004 /* incomplete cluster */
436 #define HAMMER2_ERROR_DEPTH 0x00000008 /* tmp depth limit */
437 #define HAMMER2_ERROR_BADBREF 0x00000010 /* illegal bref */
438 #define HAMMER2_ERROR_ENOSPC 0x00000020 /* allocation failure */
439 #define HAMMER2_ERROR_ENOENT 0x00000040 /* entry not found */
440 #define HAMMER2_ERROR_ENOTEMPTY 0x00000080 /* dir not empty */
441 #define HAMMER2_ERROR_EAGAIN 0x00000100 /* retry */
442 #define HAMMER2_ERROR_ENOTDIR 0x00000200 /* not directory */
443 #define HAMMER2_ERROR_EISDIR 0x00000400 /* is directory */
444 #define HAMMER2_ERROR_EINPROGRESS 0x00000800 /* already running */
445 #define HAMMER2_ERROR_ABORTED 0x00001000 /* aborted operation */
446 #define HAMMER2_ERROR_EOF 0x00002000 /* end of scan */
447 #define HAMMER2_ERROR_EINVAL 0x00004000 /* catch-all */
448 #define HAMMER2_ERROR_EEXIST 0x00008000 /* entry exists */
449 #define HAMMER2_ERROR_EDEADLK 0x00010000
450 #define HAMMER2_ERROR_ESRCH 0x00020000
451 #define HAMMER2_ERROR_ETIMEDOUT 0x00040000
454 * Flags passed to hammer2_chain_lookup() and hammer2_chain_next()
457 * NODATA - Asks that the chain->data not be resolved in order
460 * NODIRECT - Prevents a lookup of offset 0 in an inode from returning
461 * the inode itself if the inode is in DIRECTDATA mode
462 * (i.e. file is <= 512 bytes). Used by the synchronization
463 * code to prevent confusion.
465 * SHARED - The input chain is expected to be locked shared,
466 * and the output chain is locked shared.
468 * MATCHIND - Allows an indirect block / freemap node to be returned
469 * when the passed key range matches the radix. Remember
470 * that key_end is inclusive (e.g. {0x000,0xFFF},
471 * not {0x000,0x1000}).
473 * (Cannot be used for remote or cluster ops).
475 * ALLNODES - Allows NULL focus.
477 * ALWAYS - Always resolve the data. If ALWAYS and NODATA are both
478 * missing, bulk file data is not resolved but inodes and
479 * other meta-data will.
481 #define HAMMER2_LOOKUP_UNUSED0001 0x00000001
482 #define HAMMER2_LOOKUP_NODATA 0x00000002 /* data left NULL */
483 #define HAMMER2_LOOKUP_NODIRECT 0x00000004 /* no offset=0 DD */
484 #define HAMMER2_LOOKUP_SHARED 0x00000100
485 #define HAMMER2_LOOKUP_MATCHIND 0x00000200 /* return all chains */
486 #define HAMMER2_LOOKUP_ALLNODES 0x00000400 /* allow NULL focus */
487 #define HAMMER2_LOOKUP_ALWAYS 0x00000800 /* resolve data */
488 #define HAMMER2_LOOKUP_UNUSED1000 0x00001000
491 * Flags passed to hammer2_chain_modify() and hammer2_chain_resize()
493 * NOTE: OPTDATA allows us to avoid instantiating buffers for INDIRECT
494 * blocks in the INITIAL-create state.
496 #define HAMMER2_MODIFY_OPTDATA 0x00000002 /* data can be NULL */
497 #define HAMMER2_MODIFY_NO_MODIFY_TID 0x00000004
498 #define HAMMER2_MODIFY_UNUSED0008 0x00000008
501 * Flags passed to hammer2_chain_lock()
503 * NOTE: RDONLY is set to optimize cluster operations when *no* modifications
504 * will be made to either the cluster being locked or any underlying
505 * cluster. It allows the cluster to lock and access data for a subset
506 * of available nodes instead of all available nodes.
508 * NOTE: NONBLOCK is only used for hammer2_chain_repparent() and getparent(),
509 * other functions (e.g. hammer2_chain_lookup(), etc) can't handle its
512 #define HAMMER2_RESOLVE_NEVER 1
513 #define HAMMER2_RESOLVE_MAYBE 2
514 #define HAMMER2_RESOLVE_ALWAYS 3
515 #define HAMMER2_RESOLVE_MASK 0x0F
517 #define HAMMER2_RESOLVE_SHARED 0x10 /* request shared lock */
518 #define HAMMER2_RESOLVE_LOCKAGAIN 0x20 /* another shared lock */
519 #define HAMMER2_RESOLVE_UNUSED40 0x40
520 #define HAMMER2_RESOLVE_NONBLOCK 0x80 /* non-blocking */
523 * Flags passed to hammer2_chain_delete()
525 #define HAMMER2_DELETE_PERMANENT 0x0001
528 * Flags passed to hammer2_chain_insert() or hammer2_chain_rename()
529 * or hammer2_chain_create().
531 #define HAMMER2_INSERT_PFSROOT 0x0004
532 #define HAMMER2_INSERT_SAMEPARENT 0x0008
535 * Flags passed to hammer2_chain_delete_duplicate()
537 #define HAMMER2_DELDUP_RECORE 0x0001
540 * Cluster different types of storage together for allocations
542 #define HAMMER2_FREECACHE_INODE 0
543 #define HAMMER2_FREECACHE_INDIR 1
544 #define HAMMER2_FREECACHE_DATA 2
545 #define HAMMER2_FREECACHE_UNUSED3 3
546 #define HAMMER2_FREECACHE_TYPES 4
549 * hammer2_freemap_alloc() block preference
551 #define HAMMER2_OFF_NOPREF ((hammer2_off_t)-1)
554 * BMAP read-ahead maximum parameters
556 #define HAMMER2_BMAP_COUNT 16 /* max bmap read-ahead */
557 #define HAMMER2_BMAP_BYTES (HAMMER2_PBUFSIZE * HAMMER2_BMAP_COUNT)
560 * hammer2_freemap_adjust()
562 #define HAMMER2_FREEMAP_DORECOVER 1
563 #define HAMMER2_FREEMAP_DOMAYFREE 2
564 #define HAMMER2_FREEMAP_DOREALFREE 3
567 * HAMMER2 cluster - A set of chains representing the same entity.
569 * hammer2_cluster typically represents a temporary set of representitive
570 * chains. The one exception is that a hammer2_cluster is embedded in
571 * hammer2_inode. This embedded cluster is ONLY used to track the
572 * representitive chains and cannot be directly locked.
574 * A cluster is usually temporary (and thus per-thread) for locking purposes,
575 * allowing us to embed the asynchronous storage required for cluster
576 * operations in the cluster itself and adjust the state and status without
577 * having to worry too much about SMP issues.
579 * The exception is the cluster embedded in the hammer2_inode structure.
580 * This is used to cache the cluster state on an inode-by-inode basis.
581 * Individual hammer2_chain structures not incorporated into clusters might
582 * also stick around to cache miscellanious elements.
584 * Because the cluster is a 'working copy' and is usually subject to cluster
585 * quorum rules, it is quite possible for us to end up with an insufficient
586 * number of live chains to execute an operation. If an insufficient number
587 * of chains remain in a working copy, the operation may have to be
588 * downgraded, retried, stall until the requisit number of chains are
589 * available, or possibly even error out depending on the mount type.
591 * A cluster's focus is set when it is locked. The focus can only be set
592 * to a chain still part of the synchronized set.
594 #define HAMMER2_XOPFIFO 16
595 #define HAMMER2_XOPFIFO_MASK (HAMMER2_XOPFIFO - 1)
596 #define HAMMER2_XOPGROUPS 32
597 #define HAMMER2_XOPGROUPS_MASK (HAMMER2_XOPGROUPS - 1)
599 #define HAMMER2_MAXCLUSTER 8
600 #define HAMMER2_XOPMASK_CLUSTER (uint64_t)((1LLU << HAMMER2_MAXCLUSTER) - 1)
601 #define HAMMER2_XOPMASK_VOP (uint64_t)0x0000000080000000LLU
602 #define HAMMER2_XOPMASK_FIFOW (uint64_t)0x0000000040000000LLU
603 #define HAMMER2_XOPMASK_WAIT (uint64_t)0x0000000020000000LLU
604 #define HAMMER2_XOPMASK_FEED (uint64_t)0x0000000100000000LLU
606 #define HAMMER2_XOPMASK_ALLDONE (HAMMER2_XOPMASK_VOP | HAMMER2_XOPMASK_CLUSTER)
608 #define HAMMER2_SPECTHREADS 1 /* sync */
610 struct hammer2_cluster_item {
611 hammer2_chain_t *chain;
616 typedef struct hammer2_cluster_item hammer2_cluster_item_t;
619 * INVALID - Invalid for focus, i.e. not part of synchronized set.
620 * Once set, this bit is sticky across operations.
622 * FEMOD - Indicates that front-end modifying operations can
623 * mess with this entry and MODSYNC will copy also
626 #define HAMMER2_CITEM_INVALID 0x00000001
627 #define HAMMER2_CITEM_FEMOD 0x00000002
628 #define HAMMER2_CITEM_NULL 0x00000004
630 struct hammer2_cluster {
631 int refs; /* track for deallocation */
633 struct hammer2_pfs *pmp;
636 int error; /* error code valid on lock */
638 hammer2_chain_t *focus; /* current focus (or mod) */
639 hammer2_cluster_item_t array[HAMMER2_MAXCLUSTER];
642 typedef struct hammer2_cluster hammer2_cluster_t;
645 * WRHARD - Hard mounts can write fully synchronized
646 * RDHARD - Hard mounts can read fully synchronized
647 * UNHARD - Unsynchronized masters present
648 * NOHARD - No masters visible
649 * WRSOFT - Soft mounts can write to at least the SOFT_MASTER
650 * RDSOFT - Soft mounts can read from at least a SOFT_SLAVE
651 * UNSOFT - Unsynchronized slaves present
652 * NOSOFT - No slaves visible
653 * RDSLAVE - slaves are accessible (possibly unsynchronized or remote).
654 * MSYNCED - All masters are fully synchronized
655 * SSYNCED - All known local slaves are fully synchronized to masters
657 * All available masters are always incorporated. All PFSs belonging to a
658 * cluster (master, slave, copy, whatever) always try to synchronize the
659 * total number of known masters in the PFSs root inode.
661 * A cluster might have access to many slaves, copies, or caches, but we
662 * have a limited number of cluster slots. Any such elements which are
663 * directly mounted from block device(s) will always be incorporated. Note
664 * that SSYNCED only applies to such elements which are directly mounted,
665 * not to any remote slaves, copies, or caches that could be available. These
666 * bits are used to monitor and drive our synchronization threads.
668 * When asking the question 'is any data accessible at all', then a simple
669 * test against (RDHARD|RDSOFT|RDSLAVE) gives you the answer. If any of
670 * these bits are set the object can be read with certain caveats:
671 * RDHARD - no caveats. RDSOFT - authoritative but might not be synchronized.
672 * and RDSLAVE - not authoritative, has some data but it could be old or
675 * When both soft and hard mounts are available, data will be read and written
676 * via the soft mount only. But all might be in the cluster because
677 * background synchronization threads still need to do their work.
679 #define HAMMER2_CLUSTER_INODE 0x00000001 /* embedded in inode struct */
680 #define HAMMER2_CLUSTER_UNUSED2 0x00000002
681 #define HAMMER2_CLUSTER_LOCKED 0x00000004 /* cluster lks not recursive */
682 #define HAMMER2_CLUSTER_WRHARD 0x00000100 /* hard-mount can write */
683 #define HAMMER2_CLUSTER_RDHARD 0x00000200 /* hard-mount can read */
684 #define HAMMER2_CLUSTER_UNHARD 0x00000400 /* unsynchronized masters */
685 #define HAMMER2_CLUSTER_NOHARD 0x00000800 /* no masters visible */
686 #define HAMMER2_CLUSTER_WRSOFT 0x00001000 /* soft-mount can write */
687 #define HAMMER2_CLUSTER_RDSOFT 0x00002000 /* soft-mount can read */
688 #define HAMMER2_CLUSTER_UNSOFT 0x00004000 /* unsynchronized slaves */
689 #define HAMMER2_CLUSTER_NOSOFT 0x00008000 /* no slaves visible */
690 #define HAMMER2_CLUSTER_MSYNCED 0x00010000 /* all masters synchronized */
691 #define HAMMER2_CLUSTER_SSYNCED 0x00020000 /* known slaves synchronized */
693 #define HAMMER2_CLUSTER_ANYDATA ( HAMMER2_CLUSTER_RDHARD | \
694 HAMMER2_CLUSTER_RDSOFT | \
695 HAMMER2_CLUSTER_RDSLAVE)
697 #define HAMMER2_CLUSTER_RDOK ( HAMMER2_CLUSTER_RDHARD | \
698 HAMMER2_CLUSTER_RDSOFT)
700 #define HAMMER2_CLUSTER_WROK ( HAMMER2_CLUSTER_WRHARD | \
701 HAMMER2_CLUSTER_WRSOFT)
703 #define HAMMER2_CLUSTER_ZFLAGS ( HAMMER2_CLUSTER_WRHARD | \
704 HAMMER2_CLUSTER_RDHARD | \
705 HAMMER2_CLUSTER_WRSOFT | \
706 HAMMER2_CLUSTER_RDSOFT | \
707 HAMMER2_CLUSTER_MSYNCED | \
708 HAMMER2_CLUSTER_SSYNCED)
711 * Helper functions (cluster must be locked for flags to be valid).
715 hammer2_cluster_rdok(hammer2_cluster_t *cluster)
717 return (cluster->flags & HAMMER2_CLUSTER_RDOK);
722 hammer2_cluster_wrok(hammer2_cluster_t *cluster)
724 return (cluster->flags & HAMMER2_CLUSTER_WROK);
727 RB_HEAD(hammer2_inode_tree, hammer2_inode); /* ip->rbnode */
728 TAILQ_HEAD(inoq_head, hammer2_inode); /* ip->entry */
729 TAILQ_HEAD(depq_head, hammer2_depend); /* depend->entry */
731 struct hammer2_depend {
732 TAILQ_ENTRY(hammer2_depend) entry;
733 struct inoq_head sideq;
739 typedef struct hammer2_depend hammer2_depend_t;
744 * NOTE: The inode-embedded cluster is never used directly for I/O (since
745 * it may be shared). Instead it will be replicated-in and synchronized
746 * back out if changed.
748 struct hammer2_inode {
749 RB_ENTRY(hammer2_inode) rbnode; /* inumber lookup (HL) */
750 TAILQ_ENTRY(hammer2_inode) entry; /* SYNCQ/SIDEQ */
751 hammer2_depend_t *depend; /* non-NULL if SIDEQ */
752 hammer2_depend_t depend_static; /* (in-place allocation) */
753 hammer2_mtx_t lock; /* inode lock */
754 hammer2_mtx_t truncate_lock; /* prevent truncates */
755 struct hammer2_pfs *pmp; /* PFS mount */
757 struct spinlock cluster_spin; /* update cluster */
758 hammer2_cluster_t cluster;
759 struct lockf advlock;
761 u_int refs; /* +vpref, +flushref */
762 uint8_t comp_heuristic;
763 hammer2_inode_meta_t meta; /* copy of meta-data */
767 typedef struct hammer2_inode hammer2_inode_t;
770 * MODIFIED - Inode is in a modified state, ip->meta may have changes.
771 * RESIZED - Inode truncated (any) or inode extended beyond
774 * SYNCQ - Inode is included in the current filesystem sync. The
775 * DELETING and CREATING flags will be acted upon.
777 * SIDEQ - Inode has likely been disconnected from the vnode topology
778 * and so is not visible to the vnode-based filesystem syncer
779 * code, but is dirty and must be included in the next
780 * filesystem sync. These inodes are moved to the SYNCQ at
781 * the time the sync occurs.
783 * Inodes are not placed on this queue simply because they have
784 * become dirty, if a vnode is attached.
786 * DELETING - Inode is flagged for deletion during the next filesystem
787 * sync. That is, the inode's chain is currently connected
788 * and must be deleting during the current or next fs sync.
790 * CREATING - Inode is flagged for creation during the next filesystem
791 * sync. That is, the inode's chain topology exists (so
792 * kernel buffer flushes can occur), but is currently
793 * disconnected and must be inserted during the current or
794 * next fs sync. If the DELETING flag is also set, the
795 * topology can be thrown away instead.
797 * If an inode that is already part of the current filesystem sync is
798 * modified by the frontend, including by buffer flushes, the inode lock
799 * code detects the SYNCQ flag and moves the inode to the head of the
800 * flush-in-progress, then blocks until the flush has gotten past it.
802 #define HAMMER2_INODE_MODIFIED 0x0001
803 #define HAMMER2_INODE_SROOT 0x0002 /* kmalloc special case */
804 #define HAMMER2_INODE_RENAME_INPROG 0x0004
805 #define HAMMER2_INODE_ONRBTREE 0x0008
806 #define HAMMER2_INODE_RESIZED 0x0010 /* requires inode_fsync */
807 #define HAMMER2_INODE_UNUSED0020 0x0020
808 #define HAMMER2_INODE_ISUNLINKED 0x0040
809 #define HAMMER2_INODE_METAGOOD 0x0080 /* inode meta-data good */
810 #define HAMMER2_INODE_SIDEQ 0x0100 /* on side processing queue */
811 #define HAMMER2_INODE_NOSIDEQ 0x0200 /* disable sideq operation */
812 #define HAMMER2_INODE_DIRTYDATA 0x0400 /* interlocks inode flush */
813 #define HAMMER2_INODE_SYNCQ 0x0800 /* sync interlock, sequenced */
814 #define HAMMER2_INODE_DELETING 0x1000 /* sync interlock, chain topo */
815 #define HAMMER2_INODE_CREATING 0x2000 /* sync interlock, chain topo */
816 #define HAMMER2_INODE_SYNCQ_WAKEUP 0x4000 /* sync interlock wakeup */
817 #define HAMMER2_INODE_SYNCQ_PASS2 0x8000 /* force retry delay */
819 #define HAMMER2_INODE_DIRTY (HAMMER2_INODE_MODIFIED | \
820 HAMMER2_INODE_DIRTYDATA | \
821 HAMMER2_INODE_DELETING | \
822 HAMMER2_INODE_CREATING)
824 int hammer2_inode_cmp(hammer2_inode_t *ip1, hammer2_inode_t *ip2);
825 RB_PROTOTYPE2(hammer2_inode_tree, hammer2_inode, rbnode, hammer2_inode_cmp,
829 * Transaction management sub-structure under hammer2_pfs
831 struct hammer2_trans {
836 typedef struct hammer2_trans hammer2_trans_t;
838 #define HAMMER2_TRANS_ISFLUSH 0x80000000 /* flush code */
839 #define HAMMER2_TRANS_BUFCACHE 0x40000000 /* bio strategy */
840 #define HAMMER2_TRANS_SIDEQ 0x20000000 /* run sideq */
841 #define HAMMER2_TRANS_UNUSED10 0x10000000
842 #define HAMMER2_TRANS_WAITING 0x08000000 /* someone waiting */
843 #define HAMMER2_TRANS_RESCAN 0x04000000 /* rescan sideq */
844 #define HAMMER2_TRANS_MASK 0x00FFFFFF /* count mask */
846 #define HAMMER2_FREEMAP_HEUR_NRADIX 4 /* pwr 2 PBUFRADIX-MINIORADIX */
847 #define HAMMER2_FREEMAP_HEUR_TYPES 8
848 #define HAMMER2_FREEMAP_HEUR_SIZE (HAMMER2_FREEMAP_HEUR_NRADIX * \
849 HAMMER2_FREEMAP_HEUR_TYPES)
851 #define HAMMER2_DEDUP_HEUR_SIZE (65536 * 4)
852 #define HAMMER2_DEDUP_HEUR_MASK (HAMMER2_DEDUP_HEUR_SIZE - 1)
854 #define HAMMER2_FLUSH_TOP 0x0001
855 #define HAMMER2_FLUSH_ALL 0x0002
856 #define HAMMER2_FLUSH_INODE_STOP 0x0004 /* stop at sub-inode */
857 #define HAMMER2_FLUSH_FSSYNC 0x0008 /* part of filesystem sync */
861 * Hammer2 support thread element.
863 * Potentially many support threads can hang off of hammer2, primarily
864 * off the hammer2_pfs structure. Typically:
866 * td x Nodes A synchronization thread for each node.
867 * td x Nodes x workers Worker threads for frontend operations.
868 * td x 1 Bioq thread for logical buffer writes.
870 * In addition, the synchronization thread(s) associated with the
871 * super-root PFS (spmp) for a node is responsible for automatic bulkfree
874 struct hammer2_thread {
875 struct hammer2_pfs *pmp;
876 struct hammer2_dev *hmp;
877 hammer2_xop_list_t xopq;
881 int clindex; /* cluster element index */
883 char *scratch; /* MAXPHYS */
886 typedef struct hammer2_thread hammer2_thread_t;
888 #define HAMMER2_THREAD_UNMOUNTING 0x0001 /* unmount request */
889 #define HAMMER2_THREAD_DEV 0x0002 /* related to dev, not pfs */
890 #define HAMMER2_THREAD_WAITING 0x0004 /* thread in idle tsleep */
891 #define HAMMER2_THREAD_REMASTER 0x0008 /* remaster request */
892 #define HAMMER2_THREAD_STOP 0x0010 /* exit request */
893 #define HAMMER2_THREAD_FREEZE 0x0020 /* force idle */
894 #define HAMMER2_THREAD_FROZEN 0x0040 /* thread is frozen */
895 #define HAMMER2_THREAD_XOPQ 0x0080 /* work pending */
896 #define HAMMER2_THREAD_STOPPED 0x0100 /* thread has stopped */
897 #define HAMMER2_THREAD_UNFREEZE 0x0200
899 #define HAMMER2_THREAD_WAKEUP_MASK (HAMMER2_THREAD_UNMOUNTING | \
900 HAMMER2_THREAD_REMASTER | \
901 HAMMER2_THREAD_STOP | \
902 HAMMER2_THREAD_FREEZE | \
906 * Support structure for dedup heuristic.
908 struct hammer2_dedup {
909 hammer2_off_t data_off;
915 typedef struct hammer2_dedup hammer2_dedup_t;
918 * hammer2_xop - container for VOP/XOP operation (allocated, not on stack).
920 * This structure is used to distribute a VOP operation across multiple
921 * nodes. It provides a rendezvous for concurrent node execution and
922 * can be detached from the frontend operation to allow the frontend to
925 * This structure also sequences operations on up to three inodes.
927 typedef void (*hammer2_xop_func_t)(union hammer2_xop *xop, void *scratch,
930 struct hammer2_xop_desc {
931 hammer2_xop_func_t storage_func; /* local storage function */
932 hammer2_xop_func_t dmsg_dispatch; /* dmsg dispatch function */
933 hammer2_xop_func_t dmsg_process; /* dmsg processing function */
937 typedef struct hammer2_xop_desc hammer2_xop_desc_t;
939 struct hammer2_xop_fifo {
940 TAILQ_ENTRY(hammer2_xop_head) entry;
941 hammer2_chain_t *array[HAMMER2_XOPFIFO];
942 int errors[HAMMER2_XOPFIFO];
946 hammer2_thread_t *thr;
949 typedef struct hammer2_xop_fifo hammer2_xop_fifo_t;
951 #define HAMMER2_XOP_FIFO_RUN 0x0001
952 #define HAMMER2_XOP_FIFO_STALL 0x0002
954 struct hammer2_xop_head {
955 hammer2_xop_desc_t *desc;
957 struct hammer2_inode *ip1;
958 struct hammer2_inode *ip2;
959 struct hammer2_inode *ip3;
965 hammer2_key_t collect_key;
970 hammer2_xop_fifo_t collect[HAMMER2_MAXCLUSTER];
971 hammer2_cluster_t cluster; /* help collections */
972 hammer2_io_t *focus_dio;
975 typedef struct hammer2_xop_head hammer2_xop_head_t;
977 struct hammer2_xop_ipcluster {
978 hammer2_xop_head_t head;
981 struct hammer2_xop_strategy {
982 hammer2_xop_head_t head;
989 struct hammer2_xop_readdir {
990 hammer2_xop_head_t head;
994 struct hammer2_xop_nresolve {
995 hammer2_xop_head_t head;
996 hammer2_key_t lhc; /* if name is NULL used lhc */
999 struct hammer2_xop_unlink {
1000 hammer2_xop_head_t head;
1005 #define H2DOPERM_PERMANENT 0x01
1006 #define H2DOPERM_FORCE 0x02
1007 #define H2DOPERM_IGNINO 0x04
1009 struct hammer2_xop_nrename {
1010 hammer2_xop_head_t head;
1015 struct hammer2_xop_scanlhc {
1016 hammer2_xop_head_t head;
1020 struct hammer2_xop_scanall {
1021 hammer2_xop_head_t head;
1022 hammer2_key_t key_beg; /* inclusive */
1023 hammer2_key_t key_end; /* inclusive */
1028 struct hammer2_xop_lookup {
1029 hammer2_xop_head_t head;
1033 struct hammer2_xop_mkdirent {
1034 hammer2_xop_head_t head;
1035 hammer2_dirent_head_t dirent;
1039 struct hammer2_xop_create {
1040 hammer2_xop_head_t head;
1041 hammer2_inode_meta_t meta; /* initial metadata */
1046 struct hammer2_xop_destroy {
1047 hammer2_xop_head_t head;
1050 struct hammer2_xop_fsync {
1051 hammer2_xop_head_t head;
1052 hammer2_inode_meta_t meta;
1053 hammer2_off_t osize;
1055 int clear_directdata;
1058 struct hammer2_xop_unlinkall {
1059 hammer2_xop_head_t head;
1060 hammer2_key_t key_beg;
1061 hammer2_key_t key_end;
1064 struct hammer2_xop_connect {
1065 hammer2_xop_head_t head;
1069 struct hammer2_xop_flush {
1070 hammer2_xop_head_t head;
1073 typedef struct hammer2_xop_readdir hammer2_xop_readdir_t;
1074 typedef struct hammer2_xop_nresolve hammer2_xop_nresolve_t;
1075 typedef struct hammer2_xop_unlink hammer2_xop_unlink_t;
1076 typedef struct hammer2_xop_nrename hammer2_xop_nrename_t;
1077 typedef struct hammer2_xop_ipcluster hammer2_xop_ipcluster_t;
1078 typedef struct hammer2_xop_strategy hammer2_xop_strategy_t;
1079 typedef struct hammer2_xop_mkdirent hammer2_xop_mkdirent_t;
1080 typedef struct hammer2_xop_create hammer2_xop_create_t;
1081 typedef struct hammer2_xop_destroy hammer2_xop_destroy_t;
1082 typedef struct hammer2_xop_fsync hammer2_xop_fsync_t;
1083 typedef struct hammer2_xop_unlinkall hammer2_xop_unlinkall_t;
1084 typedef struct hammer2_xop_scanlhc hammer2_xop_scanlhc_t;
1085 typedef struct hammer2_xop_scanall hammer2_xop_scanall_t;
1086 typedef struct hammer2_xop_lookup hammer2_xop_lookup_t;
1087 typedef struct hammer2_xop_connect hammer2_xop_connect_t;
1088 typedef struct hammer2_xop_flush hammer2_xop_flush_t;
1091 hammer2_xop_head_t head;
1092 hammer2_xop_ipcluster_t xop_ipcluster;
1093 hammer2_xop_readdir_t xop_readdir;
1094 hammer2_xop_nresolve_t xop_nresolve;
1095 hammer2_xop_unlink_t xop_unlink;
1096 hammer2_xop_nrename_t xop_nrename;
1097 hammer2_xop_strategy_t xop_strategy;
1098 hammer2_xop_mkdirent_t xop_mkdirent;
1099 hammer2_xop_create_t xop_create;
1100 hammer2_xop_destroy_t xop_destroy;
1101 hammer2_xop_fsync_t xop_fsync;
1102 hammer2_xop_unlinkall_t xop_unlinkall;
1103 hammer2_xop_scanlhc_t xop_scanlhc;
1104 hammer2_xop_scanall_t xop_scanall;
1105 hammer2_xop_lookup_t xop_lookup;
1106 hammer2_xop_flush_t xop_flush;
1107 hammer2_xop_connect_t xop_connect;
1110 typedef union hammer2_xop hammer2_xop_t;
1113 * hammer2_xop_group - Manage XOP support threads.
1115 struct hammer2_xop_group {
1116 hammer2_thread_t thrs[HAMMER2_MAXCLUSTER];
1119 typedef struct hammer2_xop_group hammer2_xop_group_t;
1122 * flags to hammer2_xop_collect()
1124 #define HAMMER2_XOP_COLLECT_NOWAIT 0x00000001
1125 #define HAMMER2_XOP_COLLECT_WAITALL 0x00000002
1128 * flags to hammer2_xop_alloc()
1130 * MODIFYING - This is a modifying transaction, allocate a mtid.
1131 * RECURSE - Recurse top-level inode (for root flushes)
1133 #define HAMMER2_XOP_MODIFYING 0x00000001
1134 #define HAMMER2_XOP_STRATEGY 0x00000002
1135 #define HAMMER2_XOP_INODE_STOP 0x00000004
1136 #define HAMMER2_XOP_VOLHDR 0x00000008
1137 #define HAMMER2_XOP_FSSYNC 0x00000010
1138 #define HAMMER2_XOP_IROOT 0x00000020
1141 * Global (per partition) management structure, represents a hard block
1142 * device. Typically referenced by hammer2_chain structures when applicable.
1143 * Typically not used for network-managed elements.
1145 * Note that a single hammer2_dev can be indirectly tied to multiple system
1146 * mount points. There is no direct relationship. System mounts are
1147 * per-cluster-id, not per-block-device, and a single hard mount might contain
1148 * many PFSs and those PFSs might combine together in various ways to form
1149 * the set of available clusters.
1151 struct hammer2_dev {
1152 struct vnode *devvp; /* device vnode */
1153 int ronly; /* read-only mount */
1154 int mount_count; /* number of actively mounted PFSs */
1155 TAILQ_ENTRY(hammer2_dev) mntentry; /* hammer2_mntlist */
1157 struct malloc_type *mchain;
1160 kdmsg_iocom_t iocom; /* volume-level dmsg interface */
1161 struct spinlock io_spin; /* iotree, iolruq access */
1162 struct hammer2_io_tree iotree;
1164 int freemap_relaxed;
1165 hammer2_chain_t vchain; /* anchor chain (topology) */
1166 hammer2_chain_t fchain; /* anchor chain (freemap) */
1167 struct spinlock list_spin;
1168 struct hammer2_pfs *spmp; /* super-root pmp for transactions */
1169 struct lock vollk; /* lockmgr lock */
1170 struct lock bulklk; /* bulkfree operation lock */
1171 struct lock bflock; /* bulk-free manual function lock */
1172 hammer2_off_t heur_freemap[HAMMER2_FREEMAP_HEUR_SIZE];
1173 hammer2_dedup_t heur_dedup[HAMMER2_DEDUP_HEUR_SIZE];
1174 int volhdrno; /* last volhdrno written */
1175 uint32_t hflags; /* HMNT2 flags applicable to device */
1176 hammer2_off_t free_reserved; /* nominal free reserved */
1177 hammer2_thread_t bfthr; /* bulk-free thread */
1178 char devrepname[64]; /* for kprintf */
1179 hammer2_ioc_bulkfree_t bflast; /* stats for last bulkfree run */
1180 hammer2_volume_data_t voldata;
1181 hammer2_volume_data_t volsync; /* synchronized voldata */
1184 typedef struct hammer2_dev hammer2_dev_t;
1187 * Helper functions (cluster must be locked for flags to be valid).
1191 hammer2_chain_rdok(hammer2_chain_t *chain)
1193 return (chain->error == 0);
1198 hammer2_chain_wrok(hammer2_chain_t *chain)
1200 return (chain->error == 0 && chain->hmp->ronly == 0);
1204 * Per-cluster management structure. This structure will be tied to a
1205 * system mount point if the system is mounting the PFS, but is also used
1206 * to manage clusters encountered during the super-root scan or received
1207 * via LNK_SPANs that might not be mounted.
1209 * This structure is also used to represent the super-root that hangs off
1210 * of a hard mount point. The super-root is not really a cluster element.
1211 * In this case the spmp_hmp field will be non-NULL. It's just easier to do
1212 * this than to special case super-root manipulation in the hammer2_chain*
1213 * code as being only hammer2_dev-related.
1215 * pfs_mode and pfs_nmasters are rollup fields which critically describes
1216 * how elements of the cluster act on the cluster. pfs_mode is only applicable
1217 * when a PFS is mounted by the system. pfs_nmasters is our best guess as to
1218 * how many masters have been configured for a cluster and is always
1219 * applicable. pfs_types[] is an array with 1:1 correspondance to the
1220 * iroot cluster and describes the PFS types of the nodes making up the
1223 * WARNING! Portions of this structure have deferred initialization. In
1224 * particular, if not mounted there will be no wthread.
1225 * umounted network PFSs will also be missing iroot and numerous
1226 * other fields will not be initialized prior to mount.
1228 * Synchronization threads are chain-specific and only applicable
1229 * to local hard PFS entries. A hammer2_pfs structure may contain
1230 * more than one when multiple hard PFSs are present on the local
1231 * machine which require synchronization monitoring. Most PFSs
1232 * (such as snapshots) are 1xMASTER PFSs which do not need a
1233 * synchronization thread.
1235 * WARNING! The chains making up pfs->iroot's cluster are accounted for in
1236 * hammer2_dev->mount_count when the pfs is associated with a mount
1239 struct hammer2_pfs {
1241 TAILQ_ENTRY(hammer2_pfs) mntentry; /* hammer2_pfslist */
1243 hammer2_dev_t *spmp_hmp; /* only if super-root pmp */
1244 hammer2_dev_t *force_local; /* only if 'local' mount */
1245 hammer2_inode_t *iroot; /* PFS root inode */
1246 uint8_t pfs_types[HAMMER2_MAXCLUSTER];
1247 char *pfs_names[HAMMER2_MAXCLUSTER];
1248 hammer2_dev_t *pfs_hmps[HAMMER2_MAXCLUSTER];
1249 hammer2_blockset_t pfs_iroot_blocksets[HAMMER2_MAXCLUSTER];
1250 hammer2_trans_t trans;
1251 struct lock lock; /* PFS lock for certain ops */
1252 struct lock lock_nlink; /* rename and nlink lock */
1253 struct netexport export; /* nfs export */
1255 int ronly; /* read-only mount */
1256 int hflags; /* pfs-specific mount flags */
1257 struct malloc_type *minode;
1258 struct malloc_type *mmsg;
1259 struct spinlock inum_spin; /* inumber lookup */
1260 struct hammer2_inode_tree inum_tree; /* (not applicable to spmp) */
1261 long inum_count; /* #of inodes in inum_tree */
1262 struct spinlock lru_spin; /* inumber lookup */
1263 struct hammer2_chain_list lru_list; /* basis for LRU tests */
1264 int lru_count; /* #of chains on LRU */
1266 hammer2_tid_t modify_tid; /* modify transaction id */
1267 hammer2_tid_t inode_tid; /* inode allocator */
1268 uint8_t pfs_nmasters; /* total masters */
1269 uint8_t pfs_mode; /* operating mode PFSMODE */
1272 int free_ticks; /* free_* calculations */
1274 hammer2_off_t free_reserved;
1275 hammer2_off_t free_nominal;
1276 uint32_t inmem_dirty_chains;
1277 int count_lwinprog; /* logical write in prog */
1278 struct spinlock list_spin;
1279 struct inoq_head syncq; /* SYNCQ flagged inodes */
1280 struct depq_head depq; /* SIDEQ flagged inodes */
1281 long sideq_count; /* total inodes on depq */
1282 hammer2_thread_t sync_thrs[HAMMER2_MAXCLUSTER];
1283 uint32_t cluster_flags; /* cached cluster flags */
1284 int has_xop_threads;
1285 struct spinlock xop_spin; /* xop sequencer */
1286 hammer2_xop_group_t xop_groups[HAMMER2_XOPGROUPS];
1289 typedef struct hammer2_pfs hammer2_pfs_t;
1291 TAILQ_HEAD(hammer2_pfslist, hammer2_pfs);
1293 #define HAMMER2_PMPF_SPMP 0x00000001
1296 * NOTE: The LRU list contains at least all the chains with refs == 0
1297 * that can be recycled, and may contain additional chains which
1300 #define HAMMER2_LRU_LIMIT 4096
1302 #define HAMMER2_DIRTYCHAIN_WAITING 0x80000000
1303 #define HAMMER2_DIRTYCHAIN_MASK 0x7FFFFFFF
1305 #define HAMMER2_LWINPROG_WAITING 0x80000000
1306 #define HAMMER2_LWINPROG_WAITING0 0x40000000
1307 #define HAMMER2_LWINPROG_MASK 0x3FFFFFFF
1310 * hammer2_cluster_check
1312 #define HAMMER2_CHECK_NULL 0x00000001
1317 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
1318 #define VTOI(vp) ((hammer2_inode_t *)(vp)->v_data)
1321 #if defined(_KERNEL)
1323 MALLOC_DECLARE(M_HAMMER2);
1325 #define ITOV(ip) ((ip)->vp)
1328 * Currently locked chains retain the locked buffer cache buffer for
1329 * indirect blocks, and indirect blocks can be one of two sizes. The
1330 * device buffer has to match the case to avoid deadlocking recursive
1331 * chains that might otherwise try to access different offsets within
1332 * the same device buffer.
1336 hammer2_devblkradix(int radix)
1339 if (radix <= HAMMER2_LBUFRADIX) {
1340 return (HAMMER2_LBUFRADIX);
1342 return (HAMMER2_PBUFRADIX);
1345 return (HAMMER2_PBUFRADIX);
1349 * XXX almost time to remove this. DIO uses PBUFSIZE exclusively now.
1353 hammer2_devblksize(size_t bytes)
1356 if (bytes <= HAMMER2_LBUFSIZE) {
1357 return(HAMMER2_LBUFSIZE);
1359 KKASSERT(bytes <= HAMMER2_PBUFSIZE &&
1360 (bytes ^ (bytes - 1)) == ((bytes << 1) - 1));
1361 return (HAMMER2_PBUFSIZE);
1364 return (HAMMER2_PBUFSIZE);
1370 MPTOPMP(struct mount *mp)
1372 return ((hammer2_pfs_t *)mp->mnt_data);
1375 #define HAMMER2_DEDUP_FRAG (HAMMER2_PBUFSIZE / 64)
1376 #define HAMMER2_DEDUP_FRAGRADIX (HAMMER2_PBUFRADIX - 6)
1380 hammer2_dedup_mask(hammer2_io_t *dio, hammer2_off_t data_off, u_int bytes)
1386 bbeg = (int)((data_off & ~HAMMER2_OFF_MASK_RADIX) - dio->pbase) >>
1387 HAMMER2_DEDUP_FRAGRADIX;
1388 bits = (int)((bytes + (HAMMER2_DEDUP_FRAG - 1)) >>
1389 HAMMER2_DEDUP_FRAGRADIX);
1390 mask = ((uint64_t)1 << bbeg) - 1;
1391 if (bbeg + bits == 64)
1392 mask = (uint64_t)-1;
1394 mask = ((uint64_t)1 << (bbeg + bits)) - 1;
1396 mask &= ~(((uint64_t)1 << bbeg) - 1);
1403 hammer2_error_to_errno(int error)
1406 if (error & HAMMER2_ERROR_EIO)
1408 else if (error & HAMMER2_ERROR_CHECK)
1410 else if (error & HAMMER2_ERROR_ABORTED)
1412 else if (error & HAMMER2_ERROR_BADBREF)
1414 else if (error & HAMMER2_ERROR_ENOSPC)
1416 else if (error & HAMMER2_ERROR_ENOENT)
1418 else if (error & HAMMER2_ERROR_ENOTEMPTY)
1420 else if (error & HAMMER2_ERROR_EAGAIN)
1422 else if (error & HAMMER2_ERROR_ENOTDIR)
1424 else if (error & HAMMER2_ERROR_EISDIR)
1426 else if (error & HAMMER2_ERROR_EINPROGRESS)
1427 error = EINPROGRESS;
1428 else if (error & HAMMER2_ERROR_EEXIST)
1438 hammer2_errno_to_error(int error)
1444 return HAMMER2_ERROR_EIO;
1447 return HAMMER2_ERROR_EINVAL;
1452 extern struct vop_ops hammer2_vnode_vops;
1453 extern struct vop_ops hammer2_spec_vops;
1454 extern struct vop_ops hammer2_fifo_vops;
1455 extern struct hammer2_pfslist hammer2_pfslist;
1456 extern struct lock hammer2_mntlk;
1459 extern int hammer2_debug;
1460 extern long hammer2_debug_inode;
1461 extern int hammer2_cluster_meta_read;
1462 extern int hammer2_cluster_data_read;
1463 extern int hammer2_cluster_write;
1464 extern int hammer2_dedup_enable;
1465 extern int hammer2_always_compress;
1466 extern int hammer2_inval_enable;
1467 extern int hammer2_flush_pipe;
1468 extern int hammer2_dio_count;
1469 extern int hammer2_dio_limit;
1470 extern int hammer2_bulkfree_tps;
1471 extern int hammer2_worker_rmask;
1472 extern long hammer2_chain_allocs;
1473 extern long hammer2_chain_frees;
1474 extern long hammer2_limit_dirty_chains;
1475 extern long hammer2_limit_dirty_inodes;
1476 extern long hammer2_count_modified_chains;
1477 extern long hammer2_iod_invals;
1478 extern long hammer2_iod_file_read;
1479 extern long hammer2_iod_meta_read;
1480 extern long hammer2_iod_indr_read;
1481 extern long hammer2_iod_fmap_read;
1482 extern long hammer2_iod_volu_read;
1483 extern long hammer2_iod_file_write;
1484 extern long hammer2_iod_file_wembed;
1485 extern long hammer2_iod_file_wzero;
1486 extern long hammer2_iod_file_wdedup;
1487 extern long hammer2_iod_meta_write;
1488 extern long hammer2_iod_indr_write;
1489 extern long hammer2_iod_fmap_write;
1490 extern long hammer2_iod_volu_write;
1492 extern long hammer2_process_xxhash64;
1493 extern long hammer2_process_icrc32;
1495 extern struct objcache *cache_buffer_read;
1496 extern struct objcache *cache_buffer_write;
1497 extern struct objcache *cache_xops;
1502 #define hammer2_icrc32(buf, size) iscsi_crc32((buf), (size))
1503 #define hammer2_icrc32c(buf, size, crc) iscsi_crc32_ext((buf), (size), (crc))
1505 int hammer2_signal_check(time_t *timep);
1506 const char *hammer2_error_str(int error);
1507 const char *hammer2_bref_type_str(hammer2_blockref_t *bref);
1509 void hammer2_inode_delayed_sideq(hammer2_inode_t *ip);
1510 void hammer2_inode_lock(hammer2_inode_t *ip, int how);
1511 void hammer2_inode_lock4(hammer2_inode_t *ip1, hammer2_inode_t *ip2,
1512 hammer2_inode_t *ip3, hammer2_inode_t *ip4);
1513 void hammer2_inode_unlock(hammer2_inode_t *ip);
1514 void hammer2_inode_depend(hammer2_inode_t *ip1, hammer2_inode_t *ip2);
1515 hammer2_chain_t *hammer2_inode_chain(hammer2_inode_t *ip, int clindex, int how);
1516 hammer2_chain_t *hammer2_inode_chain_and_parent(hammer2_inode_t *ip,
1517 int clindex, hammer2_chain_t **parentp, int how);
1518 hammer2_mtx_state_t hammer2_inode_lock_temp_release(hammer2_inode_t *ip);
1519 void hammer2_inode_lock_temp_restore(hammer2_inode_t *ip,
1520 hammer2_mtx_state_t ostate);
1521 int hammer2_inode_lock_upgrade(hammer2_inode_t *ip);
1522 void hammer2_inode_lock_downgrade(hammer2_inode_t *ip, int);
1524 void hammer2_dev_exlock(hammer2_dev_t *hmp);
1525 void hammer2_dev_shlock(hammer2_dev_t *hmp);
1526 void hammer2_dev_unlock(hammer2_dev_t *hmp);
1528 int hammer2_get_dtype(uint8_t type);
1529 int hammer2_get_vtype(uint8_t type);
1530 uint8_t hammer2_get_obj_type(enum vtype vtype);
1531 void hammer2_time_to_timespec(uint64_t xtime, struct timespec *ts);
1532 uint64_t hammer2_timespec_to_time(const struct timespec *ts);
1533 uint32_t hammer2_to_unix_xid(const uuid_t *uuid);
1534 void hammer2_guid_to_uuid(uuid_t *uuid, uint32_t guid);
1535 void hammer2_trans_manage_init(hammer2_pfs_t *pmp);
1537 hammer2_key_t hammer2_dirhash(const unsigned char *name, size_t len);
1538 int hammer2_getradix(size_t bytes);
1540 int hammer2_calc_logical(hammer2_inode_t *ip, hammer2_off_t uoff,
1541 hammer2_key_t *lbasep, hammer2_key_t *leofp);
1542 int hammer2_calc_physical(hammer2_inode_t *ip, hammer2_key_t lbase);
1543 void hammer2_update_time(uint64_t *timep);
1544 void hammer2_adjreadcounter(hammer2_blockref_t *bref, size_t bytes);
1549 struct vnode *hammer2_igetv(hammer2_inode_t *ip, int *errorp);
1550 hammer2_inode_t *hammer2_inode_lookup(hammer2_pfs_t *pmp,
1551 hammer2_tid_t inum);
1552 hammer2_inode_t *hammer2_inode_get(hammer2_pfs_t *pmp,
1553 hammer2_xop_head_t *xop, hammer2_tid_t inum, int idx);
1554 void hammer2_inode_free(hammer2_inode_t *ip);
1555 void hammer2_inode_ref(hammer2_inode_t *ip);
1556 void hammer2_inode_drop(hammer2_inode_t *ip);
1557 void hammer2_inode_repoint(hammer2_inode_t *ip, hammer2_inode_t *pip,
1558 hammer2_cluster_t *cluster);
1559 void hammer2_inode_repoint_one(hammer2_inode_t *ip, hammer2_cluster_t *cluster,
1561 void hammer2_inode_modify(hammer2_inode_t *ip);
1562 void hammer2_inode_run_sideq(hammer2_pfs_t *pmp, int doall);
1564 hammer2_inode_t *hammer2_inode_create_normal(hammer2_inode_t *pip,
1565 struct vattr *vap, struct ucred *cred,
1566 hammer2_key_t inum, int *errorp);
1567 hammer2_inode_t *hammer2_inode_create_pfs(hammer2_pfs_t *spmp,
1568 const uint8_t *name, size_t name_len,
1570 int hammer2_inode_chain_ins(hammer2_inode_t *ip);
1571 int hammer2_inode_chain_des(hammer2_inode_t *ip);
1572 int hammer2_inode_chain_sync(hammer2_inode_t *ip);
1573 int hammer2_inode_chain_flush(hammer2_inode_t *ip, int flags);
1574 int hammer2_inode_unlink_finisher(hammer2_inode_t *ip, int isopen);
1575 int hammer2_dirent_create(hammer2_inode_t *dip, const char *name,
1576 size_t name_len, hammer2_key_t inum, uint8_t type);
1581 void hammer2_voldata_lock(hammer2_dev_t *hmp);
1582 void hammer2_voldata_unlock(hammer2_dev_t *hmp);
1583 void hammer2_voldata_modify(hammer2_dev_t *hmp);
1584 hammer2_chain_t *hammer2_chain_alloc(hammer2_dev_t *hmp,
1586 hammer2_blockref_t *bref);
1587 void hammer2_chain_core_init(hammer2_chain_t *chain);
1588 void hammer2_chain_ref(hammer2_chain_t *chain);
1589 void hammer2_chain_ref_hold(hammer2_chain_t *chain);
1590 void hammer2_chain_drop(hammer2_chain_t *chain);
1591 void hammer2_chain_drop_unhold(hammer2_chain_t *chain);
1592 void hammer2_chain_unhold(hammer2_chain_t *chain);
1593 void hammer2_chain_rehold(hammer2_chain_t *chain);
1594 int hammer2_chain_lock(hammer2_chain_t *chain, int how);
1595 void hammer2_chain_lock_unhold(hammer2_chain_t *chain, int how);
1596 void hammer2_chain_load_data(hammer2_chain_t *chain);
1597 const hammer2_media_data_t *hammer2_chain_rdata(hammer2_chain_t *chain);
1598 hammer2_media_data_t *hammer2_chain_wdata(hammer2_chain_t *chain);
1600 int hammer2_chain_inode_find(hammer2_pfs_t *pmp, hammer2_key_t inum,
1601 int clindex, int flags,
1602 hammer2_chain_t **parentp,
1603 hammer2_chain_t **chainp);
1604 int hammer2_chain_modify(hammer2_chain_t *chain, hammer2_tid_t mtid,
1605 hammer2_off_t dedup_off, int flags);
1606 int hammer2_chain_modify_ip(hammer2_inode_t *ip, hammer2_chain_t *chain,
1607 hammer2_tid_t mtid, int flags);
1608 int hammer2_chain_resize(hammer2_chain_t *chain,
1609 hammer2_tid_t mtid, hammer2_off_t dedup_off,
1610 int nradix, int flags);
1611 void hammer2_chain_unlock(hammer2_chain_t *chain);
1612 void hammer2_chain_unlock_hold(hammer2_chain_t *chain);
1613 void hammer2_chain_wait(hammer2_chain_t *chain);
1614 hammer2_chain_t *hammer2_chain_get(hammer2_chain_t *parent, int generation,
1615 hammer2_blockref_t *bref, int how);
1616 hammer2_chain_t *hammer2_chain_lookup_init(hammer2_chain_t *parent, int flags);
1617 void hammer2_chain_lookup_done(hammer2_chain_t *parent);
1618 hammer2_chain_t *hammer2_chain_getparent(hammer2_chain_t *chain, int flags);
1619 hammer2_chain_t *hammer2_chain_repparent(hammer2_chain_t **chainp, int flags);
1620 hammer2_chain_t *hammer2_chain_lookup(hammer2_chain_t **parentp,
1621 hammer2_key_t *key_nextp,
1622 hammer2_key_t key_beg, hammer2_key_t key_end,
1623 int *errorp, int flags);
1624 hammer2_chain_t *hammer2_chain_next(hammer2_chain_t **parentp,
1625 hammer2_chain_t *chain,
1626 hammer2_key_t *key_nextp,
1627 hammer2_key_t key_beg, hammer2_key_t key_end,
1628 int *errorp, int flags);
1629 int hammer2_chain_scan(hammer2_chain_t *parent,
1630 hammer2_chain_t **chainp,
1631 hammer2_blockref_t *bref,
1632 int *firstp, int flags);
1634 int hammer2_chain_create(hammer2_chain_t **parentp, hammer2_chain_t **chainp,
1635 hammer2_dev_t *hmp, hammer2_pfs_t *pmp,
1636 int methods, hammer2_key_t key, int keybits,
1637 int type, size_t bytes, hammer2_tid_t mtid,
1638 hammer2_off_t dedup_off, int flags);
1639 void hammer2_chain_rename(hammer2_chain_t **parentp,
1640 hammer2_chain_t *chain,
1641 hammer2_tid_t mtid, int flags);
1642 int hammer2_chain_delete(hammer2_chain_t *parent, hammer2_chain_t *chain,
1643 hammer2_tid_t mtid, int flags);
1644 int hammer2_chain_indirect_maintenance(hammer2_chain_t *parent,
1645 hammer2_chain_t *chain);
1646 void hammer2_chain_setflush(hammer2_chain_t *chain);
1647 void hammer2_chain_countbrefs(hammer2_chain_t *chain,
1648 hammer2_blockref_t *base, int count);
1649 hammer2_chain_t *hammer2_chain_bulksnap(hammer2_dev_t *hmp);
1650 void hammer2_chain_bulkdrop(hammer2_chain_t *copy);
1652 void hammer2_chain_setcheck(hammer2_chain_t *chain, void *bdata);
1653 int hammer2_chain_testcheck(hammer2_chain_t *chain, void *bdata);
1654 int hammer2_chain_dirent_test(hammer2_chain_t *chain, const char *name,
1657 void hammer2_pfs_memory_wait(hammer2_pfs_t *pmp);
1658 void hammer2_pfs_memory_inc(hammer2_pfs_t *pmp);
1659 void hammer2_pfs_memory_wakeup(hammer2_pfs_t *pmp);
1661 void hammer2_base_delete(hammer2_chain_t *parent,
1662 hammer2_blockref_t *base, int count,
1663 hammer2_chain_t *chain,
1664 hammer2_blockref_t *obref);
1665 void hammer2_base_insert(hammer2_chain_t *parent,
1666 hammer2_blockref_t *base, int count,
1667 hammer2_chain_t *chain,
1668 hammer2_blockref_t *elm);
1673 int hammer2_flush(hammer2_chain_t *chain, int istop);
1674 void hammer2_delayed_flush(hammer2_chain_t *chain);
1679 void hammer2_trans_init(hammer2_pfs_t *pmp, uint32_t flags);
1680 void hammer2_trans_setflags(hammer2_pfs_t *pmp, uint32_t flags);
1681 void hammer2_trans_clearflags(hammer2_pfs_t *pmp, uint32_t flags);
1682 hammer2_tid_t hammer2_trans_sub(hammer2_pfs_t *pmp);
1683 void hammer2_trans_done(hammer2_pfs_t *pmp, uint32_t flags);
1684 hammer2_tid_t hammer2_trans_newinum(hammer2_pfs_t *pmp);
1685 void hammer2_trans_assert_strategy(hammer2_pfs_t *pmp);
1686 void hammer2_dedup_record(hammer2_chain_t *chain, hammer2_io_t *dio,
1692 int hammer2_ioctl(hammer2_inode_t *ip, u_long com, void *data,
1693 int fflag, struct ucred *cred);
1698 void hammer2_io_inval(hammer2_io_t *dio, hammer2_off_t data_off, u_int bytes);
1699 void hammer2_io_cleanup(hammer2_dev_t *hmp, struct hammer2_io_tree *tree);
1700 char *hammer2_io_data(hammer2_io_t *dio, off_t lbase);
1701 void hammer2_io_bkvasync(hammer2_io_t *dio);
1702 void hammer2_io_dedup_set(hammer2_dev_t *hmp, hammer2_blockref_t *bref);
1703 void hammer2_io_dedup_delete(hammer2_dev_t *hmp, uint8_t btype,
1704 hammer2_off_t data_off, u_int bytes);
1705 void hammer2_io_dedup_assert(hammer2_dev_t *hmp, hammer2_off_t data_off,
1707 void hammer2_io_callback(struct bio *bio);
1708 int hammer2_io_new(hammer2_dev_t *hmp, int btype, off_t lbase, int lsize,
1709 hammer2_io_t **diop);
1710 int hammer2_io_newnz(hammer2_dev_t *hmp, int btype, off_t lbase, int lsize,
1711 hammer2_io_t **diop);
1712 int _hammer2_io_bread(hammer2_dev_t *hmp, int btype, off_t lbase, int lsize,
1713 hammer2_io_t **diop HAMMER2_IO_DEBUG_ARGS);
1714 void hammer2_io_setdirty(hammer2_io_t *dio);
1716 hammer2_io_t *_hammer2_io_getblk(hammer2_dev_t *hmp, int btype, off_t lbase,
1717 int lsize, int op HAMMER2_IO_DEBUG_ARGS);
1718 hammer2_io_t *_hammer2_io_getquick(hammer2_dev_t *hmp, off_t lbase,
1719 int lsize HAMMER2_IO_DEBUG_ARGS);
1720 void _hammer2_io_putblk(hammer2_io_t **diop HAMMER2_IO_DEBUG_ARGS);
1721 int _hammer2_io_bwrite(hammer2_io_t **diop HAMMER2_IO_DEBUG_ARGS);
1722 void _hammer2_io_bawrite(hammer2_io_t **diop HAMMER2_IO_DEBUG_ARGS);
1723 void _hammer2_io_bdwrite(hammer2_io_t **diop HAMMER2_IO_DEBUG_ARGS);
1724 void _hammer2_io_brelse(hammer2_io_t **diop HAMMER2_IO_DEBUG_ARGS);
1725 void _hammer2_io_bqrelse(hammer2_io_t **diop HAMMER2_IO_DEBUG_ARGS);
1726 void _hammer2_io_ref(hammer2_io_t *dio HAMMER2_IO_DEBUG_ARGS);
1728 #ifndef HAMMER2_IO_DEBUG
1730 #define hammer2_io_getblk(hmp, btype, lbase, lsize, op) \
1731 _hammer2_io_getblk((hmp), (btype), (lbase), (lsize), (op))
1732 #define hammer2_io_getquick(hmp, lbase, lsize) \
1733 _hammer2_io_getquick((hmp), (lbase), (lsize))
1734 #define hammer2_io_putblk(diop) \
1735 _hammer2_io_putblk(diop)
1736 #define hammer2_io_bwrite(diop) \
1737 _hammer2_io_bwrite((diop))
1738 #define hammer2_io_bawrite(diop) \
1739 _hammer2_io_bawrite((diop))
1740 #define hammer2_io_bdwrite(diop) \
1741 _hammer2_io_bdwrite((diop))
1742 #define hammer2_io_brelse(diop) \
1743 _hammer2_io_brelse((diop))
1744 #define hammer2_io_bqrelse(diop) \
1745 _hammer2_io_bqrelse((diop))
1746 #define hammer2_io_ref(dio) \
1747 _hammer2_io_ref((dio))
1749 #define hammer2_io_bread(hmp, btype, lbase, lsize, diop) \
1750 _hammer2_io_bread((hmp), (btype), (lbase), (lsize), (diop))
1754 #define hammer2_io_getblk(hmp, btype, lbase, lsize, op) \
1755 _hammer2_io_getblk((hmp), (btype), (lbase), (lsize), (op), \
1758 #define hammer2_io_getquick(hmp, lbase, lsize) \
1759 _hammer2_io_getquick((hmp), (lbase), (lsize), __FILE__, __LINE__)
1761 #define hammer2_io_putblk(diop) \
1762 _hammer2_io_putblk(diop, __FILE__, __LINE__)
1764 #define hammer2_io_bwrite(diop) \
1765 _hammer2_io_bwrite((diop), __FILE__, __LINE__)
1766 #define hammer2_io_bawrite(diop) \
1767 _hammer2_io_bawrite((diop), __FILE__, __LINE__)
1768 #define hammer2_io_bdwrite(diop) \
1769 _hammer2_io_bdwrite((diop), __FILE__, __LINE__)
1770 #define hammer2_io_brelse(diop) \
1771 _hammer2_io_brelse((diop), __FILE__, __LINE__)
1772 #define hammer2_io_bqrelse(diop) \
1773 _hammer2_io_bqrelse((diop), __FILE__, __LINE__)
1774 #define hammer2_io_ref(dio) \
1775 _hammer2_io_ref((dio), __FILE__, __LINE__)
1777 #define hammer2_io_bread(hmp, btype, lbase, lsize, diop) \
1778 _hammer2_io_bread((hmp), (btype), (lbase), (lsize), (diop), \
1786 void hammer2_thr_signal(hammer2_thread_t *thr, uint32_t flags);
1787 void hammer2_thr_signal2(hammer2_thread_t *thr,
1788 uint32_t pflags, uint32_t nflags);
1789 void hammer2_thr_wait(hammer2_thread_t *thr, uint32_t flags);
1790 void hammer2_thr_wait_neg(hammer2_thread_t *thr, uint32_t flags);
1791 int hammer2_thr_wait_any(hammer2_thread_t *thr, uint32_t flags, int timo);
1792 void hammer2_thr_create(hammer2_thread_t *thr,
1793 hammer2_pfs_t *pmp, hammer2_dev_t *hmp,
1794 const char *id, int clindex, int repidx,
1795 void (*func)(void *arg));
1796 void hammer2_thr_delete(hammer2_thread_t *thr);
1797 void hammer2_thr_remaster(hammer2_thread_t *thr);
1798 void hammer2_thr_freeze_async(hammer2_thread_t *thr);
1799 void hammer2_thr_freeze(hammer2_thread_t *thr);
1800 void hammer2_thr_unfreeze(hammer2_thread_t *thr);
1801 int hammer2_thr_break(hammer2_thread_t *thr);
1802 void hammer2_primary_xops_thread(void *arg);
1805 * hammer2_thread.c (XOP API)
1807 void hammer2_xop_group_init(hammer2_pfs_t *pmp, hammer2_xop_group_t *xgrp);
1808 void *hammer2_xop_alloc(hammer2_inode_t *ip, int flags);
1809 void hammer2_xop_setname(hammer2_xop_head_t *xop,
1810 const char *name, size_t name_len);
1811 void hammer2_xop_setname2(hammer2_xop_head_t *xop,
1812 const char *name, size_t name_len);
1813 size_t hammer2_xop_setname_inum(hammer2_xop_head_t *xop, hammer2_key_t inum);
1814 void hammer2_xop_setip2(hammer2_xop_head_t *xop, hammer2_inode_t *ip2);
1815 void hammer2_xop_setip3(hammer2_xop_head_t *xop, hammer2_inode_t *ip3);
1816 void hammer2_xop_reinit(hammer2_xop_head_t *xop);
1817 void hammer2_xop_helper_create(hammer2_pfs_t *pmp);
1818 void hammer2_xop_helper_cleanup(hammer2_pfs_t *pmp);
1819 void hammer2_xop_start(hammer2_xop_head_t *xop, hammer2_xop_desc_t *desc);
1820 void hammer2_xop_start_except(hammer2_xop_head_t *xop, hammer2_xop_desc_t *desc,
1822 int hammer2_xop_collect(hammer2_xop_head_t *xop, int flags);
1823 void hammer2_xop_retire(hammer2_xop_head_t *xop, uint64_t mask);
1824 int hammer2_xop_active(hammer2_xop_head_t *xop);
1825 int hammer2_xop_feed(hammer2_xop_head_t *xop, hammer2_chain_t *chain,
1826 int clindex, int error);
1831 void hammer2_primary_sync_thread(void *arg);
1834 * XOP backends in hammer2_xops.c, primarily for VNOPS. Other XOP backends
1835 * may be integrated into other source files.
1837 void hammer2_xop_ipcluster(hammer2_xop_t *xop, void *scratch, int clindex);
1838 void hammer2_xop_readdir(hammer2_xop_t *xop, void *scratch, int clindex);
1839 void hammer2_xop_nresolve(hammer2_xop_t *xop, void *scratch, int clindex);
1840 void hammer2_xop_unlink(hammer2_xop_t *xop, void *scratch, int clindex);
1841 void hammer2_xop_nrename(hammer2_xop_t *xop, void *scratch, int clindex);
1842 void hammer2_xop_scanlhc(hammer2_xop_t *xop, void *scratch, int clindex);
1843 void hammer2_xop_scanall(hammer2_xop_t *xop, void *scratch, int clindex);
1844 void hammer2_xop_lookup(hammer2_xop_t *xop, void *scratch, int clindex);
1845 void hammer2_xop_delete(hammer2_xop_t *xop, void *scratch, int clindex);
1846 void hammer2_xop_inode_mkdirent(hammer2_xop_t *xop, void *scratch, int clindex);
1847 void hammer2_xop_inode_create(hammer2_xop_t *xop, void *scratch, int clindex);
1848 void hammer2_xop_inode_create_det(hammer2_xop_t *xop,
1849 void *scratch, int clindex);
1850 void hammer2_xop_inode_create_ins(hammer2_xop_t *xop,
1851 void *scratch, int clindex);
1852 void hammer2_xop_inode_destroy(hammer2_xop_t *xop, void *scratch, int clindex);
1853 void hammer2_xop_inode_chain_sync(hammer2_xop_t *xop, void *scratch,
1855 void hammer2_xop_inode_unlinkall(hammer2_xop_t *xop, void *scratch,
1857 void hammer2_xop_inode_connect(hammer2_xop_t *xop, void *scratch, int clindex);
1858 void hammer2_xop_inode_flush(hammer2_xop_t *xop, void *scratch, int clindex);
1859 void hammer2_xop_strategy_read(hammer2_xop_t *xop, void *scratch, int clindex);
1860 void hammer2_xop_strategy_write(hammer2_xop_t *xop, void *scratch, int clindex);
1862 void hammer2_dmsg_ipcluster(hammer2_xop_t *xop, void *scratch, int clindex);
1863 void hammer2_dmsg_readdir(hammer2_xop_t *xop, void *scratch, int clindex);
1864 void hammer2_dmsg_nresolve(hammer2_xop_t *xop, void *scratch, int clindex);
1865 void hammer2_dmsg_unlink(hammer2_xop_t *xop, void *scratch, int clindex);
1866 void hammer2_dmsg_nrename(hammer2_xop_t *xop, void *scratch, int clindex);
1867 void hammer2_dmsg_scanlhc(hammer2_xop_t *xop, void *scratch, int clindex);
1868 void hammer2_dmsg_scanall(hammer2_xop_t *xop, void *scratch, int clindex);
1869 void hammer2_dmsg_lookup(hammer2_xop_t *xop, void *scratch, int clindex);
1870 void hammer2_dmsg_inode_mkdirent(hammer2_xop_t *xop, void *scratch,
1872 void hammer2_dmsg_inode_create(hammer2_xop_t *xop, void *scratch, int clindex);
1873 void hammer2_dmsg_inode_destroy(hammer2_xop_t *xop, void *scratch, int clindex);
1874 void hammer2_dmsg_inode_chain_sync(hammer2_xop_t *xop, void *scratch,
1876 void hammer2_dmsg_inode_unlinkall(hammer2_xop_t *xop, void *scratch,
1878 void hammer2_dmsg_inode_connect(hammer2_xop_t *xop, void *scratch, int clindex);
1879 void hammer2_dmsg_inode_flush(hammer2_xop_t *xop, void *scratch, int clindex);
1880 void hammer2_dmsg_strategy_read(hammer2_xop_t *xop, void *scratch, int clindex);
1881 void hammer2_dmsg_strategy_write(hammer2_xop_t *xop, void *scratch,
1884 void hammer2_rmsg_ipcluster(hammer2_xop_t *xop, void *scratch, int clindex);
1885 void hammer2_rmsg_readdir(hammer2_xop_t *xop, void *scratch, int clindex);
1886 void hammer2_rmsg_nresolve(hammer2_xop_t *xop, void *scratch, int clindex);
1887 void hammer2_rmsg_unlink(hammer2_xop_t *xop, void *scratch, int clindex);
1888 void hammer2_rmsg_nrename(hammer2_xop_t *xop, void *scratch, int clindex);
1889 void hammer2_rmsg_scanlhc(hammer2_xop_t *xop, void *scratch, int clindex);
1890 void hammer2_rmsg_scanall(hammer2_xop_t *xop, void *scratch, int clindex);
1891 void hammer2_rmsg_lookup(hammer2_xop_t *xop, void *scratch, int clindex);
1892 void hammer2_rmsg_inode_mkdirent(hammer2_xop_t *xop, void *scratch,
1894 void hammer2_rmsg_inode_create(hammer2_xop_t *xop, void *scratch, int clindex);
1895 void hammer2_rmsg_inode_destroy(hammer2_xop_t *xop, void *scratch, int clindex);
1896 void hammer2_rmsg_inode_chain_sync(hammer2_xop_t *xop, void *scratch,
1898 void hammer2_rmsg_inode_unlinkall(hammer2_xop_t *xop, void *scratch,
1900 void hammer2_rmsg_inode_connect(hammer2_xop_t *xop, void *scratch, int clindex);
1901 void hammer2_rmsg_inode_flush(hammer2_xop_t *xop, void *scratch, int clindex);
1902 void hammer2_rmsg_strategy_read(hammer2_xop_t *xop, void *scratch, int clindex);
1903 void hammer2_rmsg_strategy_write(hammer2_xop_t *xop, void *scratch,
1906 extern hammer2_xop_desc_t hammer2_ipcluster_desc;
1907 extern hammer2_xop_desc_t hammer2_readdir_desc;
1908 extern hammer2_xop_desc_t hammer2_nresolve_desc;
1909 extern hammer2_xop_desc_t hammer2_unlink_desc;
1910 extern hammer2_xop_desc_t hammer2_nrename_desc;
1911 extern hammer2_xop_desc_t hammer2_scanlhc_desc;
1912 extern hammer2_xop_desc_t hammer2_scanall_desc;
1913 extern hammer2_xop_desc_t hammer2_lookup_desc;
1914 extern hammer2_xop_desc_t hammer2_delete_desc;
1915 extern hammer2_xop_desc_t hammer2_inode_mkdirent_desc;
1916 extern hammer2_xop_desc_t hammer2_inode_create_desc;
1917 extern hammer2_xop_desc_t hammer2_inode_create_det_desc;
1918 extern hammer2_xop_desc_t hammer2_inode_create_ins_desc;
1919 extern hammer2_xop_desc_t hammer2_inode_destroy_desc;
1920 extern hammer2_xop_desc_t hammer2_inode_chain_sync_desc;
1921 extern hammer2_xop_desc_t hammer2_inode_unlinkall_desc;
1922 extern hammer2_xop_desc_t hammer2_inode_connect_desc;
1923 extern hammer2_xop_desc_t hammer2_inode_flush_desc;
1924 extern hammer2_xop_desc_t hammer2_strategy_read_desc;
1925 extern hammer2_xop_desc_t hammer2_strategy_write_desc;
1930 int hammer2_msg_dbg_rcvmsg(kdmsg_msg_t *msg);
1931 int hammer2_msg_adhoc_input(kdmsg_msg_t *msg);
1936 void hammer2_volconf_update(hammer2_dev_t *hmp, int index);
1937 void hammer2_dump_chain(hammer2_chain_t *chain, int tab, int *countp, char pfx,
1939 int hammer2_vfs_sync(struct mount *mp, int waitflags);
1940 int hammer2_vfs_sync_pmp(hammer2_pfs_t *pmp, int waitfor);
1941 int hammer2_vfs_enospace(hammer2_inode_t *ip, off_t bytes, struct ucred *cred);
1943 hammer2_pfs_t *hammer2_pfsalloc(hammer2_chain_t *chain,
1944 const hammer2_inode_data_t *ripdata,
1945 hammer2_tid_t modify_tid,
1946 hammer2_dev_t *force_local);
1947 void hammer2_pfsdealloc(hammer2_pfs_t *pmp, int clindex, int destroying);
1948 int hammer2_vfs_vget(struct mount *mp, struct vnode *dvp,
1949 ino_t ino, struct vnode **vpp);
1951 void hammer2_lwinprog_ref(hammer2_pfs_t *pmp);
1952 void hammer2_lwinprog_drop(hammer2_pfs_t *pmp);
1953 void hammer2_lwinprog_wait(hammer2_pfs_t *pmp, int pipe);
1958 int hammer2_freemap_alloc(hammer2_chain_t *chain, size_t bytes);
1959 void hammer2_freemap_adjust(hammer2_dev_t *hmp,
1960 hammer2_blockref_t *bref, int how);
1965 uint8_t hammer2_cluster_type(hammer2_cluster_t *cluster);
1966 void hammer2_cluster_bref(hammer2_cluster_t *cluster, hammer2_blockref_t *bref);
1967 hammer2_cluster_t *hammer2_cluster_alloc(hammer2_pfs_t *pmp,
1968 hammer2_blockref_t *bref);
1969 void hammer2_cluster_ref(hammer2_cluster_t *cluster);
1970 void hammer2_cluster_drop(hammer2_cluster_t *cluster);
1971 void hammer2_cluster_unhold(hammer2_cluster_t *cluster);
1972 void hammer2_cluster_rehold(hammer2_cluster_t *cluster);
1973 void hammer2_cluster_lock(hammer2_cluster_t *cluster, int how);
1974 int hammer2_cluster_check(hammer2_cluster_t *cluster, hammer2_key_t lokey,
1976 void hammer2_cluster_resolve(hammer2_cluster_t *cluster);
1977 void hammer2_cluster_forcegood(hammer2_cluster_t *cluster);
1978 void hammer2_cluster_unlock(hammer2_cluster_t *cluster);
1980 void hammer2_bulkfree_init(hammer2_dev_t *hmp);
1981 void hammer2_bulkfree_uninit(hammer2_dev_t *hmp);
1982 int hammer2_bulkfree_pass(hammer2_dev_t *hmp, hammer2_chain_t *vchain,
1983 struct hammer2_ioc_bulkfree *bfi);
1984 void hammer2_dummy_xop_from_chain(hammer2_xop_head_t *xop,
1985 hammer2_chain_t *chain);
1990 void hammer2_iocom_init(hammer2_dev_t *hmp);
1991 void hammer2_iocom_uninit(hammer2_dev_t *hmp);
1992 void hammer2_cluster_reconnect(hammer2_dev_t *hmp, struct file *fp);
1995 * hammer2_strategy.c
1997 int hammer2_vop_strategy(struct vop_strategy_args *ap);
1998 int hammer2_vop_bmap(struct vop_bmap_args *ap);
1999 void hammer2_write_thread(void *arg);
2000 void hammer2_bioq_sync(hammer2_pfs_t *pmp);
2001 void hammer2_dedup_clear(hammer2_dev_t *hmp);
2004 * More complex inlines
2007 #define hammer2_xop_gdata(xop) _hammer2_xop_gdata((xop), __FILE__, __LINE__)
2010 const hammer2_media_data_t *
2011 _hammer2_xop_gdata(hammer2_xop_head_t *xop, const char *file, int line)
2013 hammer2_chain_t *focus;
2016 focus = xop->cluster.focus;
2018 lockmgr(&focus->diolk, LK_SHARED);
2019 if ((xop->focus_dio = focus->dio) != NULL) {
2020 _hammer2_io_ref(xop->focus_dio HAMMER2_IO_DEBUG_CALL);
2021 hammer2_io_bkvasync(xop->focus_dio);
2024 lockmgr(&focus->diolk, LK_RELEASE);
2032 #define hammer2_xop_pdata(xop) _hammer2_xop_pdata((xop), __FILE__, __LINE__)
2036 _hammer2_xop_pdata(hammer2_xop_head_t *xop, const char *file, int line)
2039 _hammer2_io_putblk(&xop->focus_dio HAMMER2_IO_DEBUG_CALL);
2042 #endif /* !_KERNEL */
2043 #endif /* !_VFS_HAMMER2_HAMMER2_H_ */