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>
76 #include <sys/diskslice.h>
78 #include <sys/malloc.h>
79 #include <sys/mount.h>
80 #include <sys/vnode.h>
84 #include <sys/thread.h>
85 #include <sys/lockf.h>
87 #include <sys/queue.h>
88 #include <sys/limits.h>
90 #include <sys/mutex.h>
93 #include <sys/objcache.h>
96 #include <sys/signal2.h>
98 #include <sys/mutex2.h>
99 #include <sys/spinlock2.h>
102 #include "hammer2_xxhash.h"
103 #include "hammer2_disk.h"
104 #include "hammer2_mount.h"
105 #include "hammer2_ioctl.h"
108 struct hammer2_chain
;
109 struct hammer2_inode
;
110 struct hammer2_depend
;
116 * Mutex and lock shims. Hammer2 requires support for asynchronous and
117 * abortable locks, and both exclusive and shared spinlocks. Normal
118 * synchronous non-abortable locks can be substituted for spinlocks.
120 typedef mtx_t hammer2_mtx_t
;
121 typedef mtx_state_t hammer2_mtx_state_t
;
123 typedef struct spinlock hammer2_spin_t
;
125 #define hammer2_mtx_ex mtx_lock_ex_quick
126 #define hammer2_mtx_ex_try mtx_lock_ex_try
127 #define hammer2_mtx_sh mtx_lock_sh_quick
128 #define hammer2_mtx_sh_again mtx_lock_sh_again
129 #define hammer2_mtx_sh_try mtx_lock_sh_try
130 #define hammer2_mtx_unlock mtx_unlock
131 #define hammer2_mtx_upgrade_try mtx_upgrade_try
132 #define hammer2_mtx_downgrade mtx_downgrade
133 #define hammer2_mtx_owned mtx_owned
134 #define hammer2_mtx_init mtx_init
135 #define hammer2_mtx_temp_release mtx_lock_temp_release
136 #define hammer2_mtx_temp_restore mtx_lock_temp_restore
137 #define hammer2_mtx_refs mtx_lockrefs
139 #define hammer2_spin_init spin_init
140 #define hammer2_spin_sh spin_lock_shared
141 #define hammer2_spin_ex spin_lock
142 #define hammer2_spin_unsh spin_unlock_shared
143 #define hammer2_spin_unex spin_unlock
144 #define hammer2_spin_lock_update spin_lock_update
145 #define hammer2_spin_unlock_update spin_unlock_update
147 TAILQ_HEAD(hammer2_xop_list
, hammer2_xop_head
);
148 TAILQ_HEAD(hammer2_chain_list
, hammer2_chain
);
150 typedef struct hammer2_xop_list hammer2_xop_list_t
;
153 * Cap the dynamic calculation for the maximum number of dirty
154 * chains and dirty inodes allowed.
156 #define HAMMER2_LIMIT_DIRTY_CHAINS (1024*1024)
157 #define HAMMER2_LIMIT_DIRTY_INODES (65536)
159 #define HAMMER2_IOHASH_SIZE 32768
160 #define HAMMER2_IOHASH_MASK (HAMMER2_IOHASH_SIZE - 1)
162 #define HAMMER2_INUMHASH_SIZE 32768
163 #define HAMMER2_INUMHASH_MASK (HAMMER2_IOHASH_SIZE - 1)
166 * The chain structure tracks a portion of the media topology from the
167 * root (volume) down. Chains represent volumes, inodes, indirect blocks,
168 * data blocks, and freemap nodes and leafs.
170 * The chain structure utilizes a simple singly-homed topology and the
171 * chain's in-memory topology will move around as the chains do, due mainly
172 * to renames and indirect block creation.
174 * Block Table Updates
176 * Block table updates for insertions and updates are delayed until the
177 * flush. This allows us to avoid having to modify the parent chain
178 * all the way to the root.
180 * Block table deletions are performed immediately (modifying the parent
181 * in the process) because the flush code uses the chain structure to
182 * track delayed updates and the chain will be (likely) gone or moved to
183 * another location in the topology after a deletion.
185 * A prior iteration of the code tried to keep the relationship intact
186 * on deletes by doing a delete-duplicate operation on the chain, but
187 * it added way too much complexity to the codebase.
189 * Flush Synchronization
191 * The flush code must flush modified chains bottom-up. Because chain
192 * structures can shift around and are NOT topologically stable,
193 * modified chains are independently indexed for the flush. As the flush
194 * runs it modifies (or further modifies) and updates the parents,
195 * propagating the flush all the way to the volume root.
197 * Modifying front-end operations can occur during a flush but will block
198 * in two cases: (1) when the front-end tries to operate on the inode
199 * currently in the midst of being flushed and (2) if the front-end
200 * crosses an inode currently being flushed (such as during a rename).
201 * So, for example, if you rename directory "x" to "a/b/c/d/e/f/g/x" and
202 * the flusher is currently working on "a/b/c", the rename will block
203 * temporarily in order to ensure that "x" exists in one place or the
206 * Meta-data statistics are updated by the flusher. The front-end will
207 * make estimates but meta-data must be fully synchronized only during a
208 * flush in order to ensure that it remains correct across a crash.
210 * Multiple flush synchronizations can theoretically be in-flight at the
211 * same time but the implementation is not coded to handle the case and
212 * currently serializes them.
216 * Snapshots currently require the subdirectory tree being snapshotted
217 * to be flushed. The snapshot then creates a new super-root inode which
218 * copies the flushed blockdata of the directory or file that was
223 * - Note that the radix tree runs in powers of 2 only so sub-trees
224 * cannot straddle edges.
226 RB_HEAD(hammer2_chain_tree
, hammer2_chain
);
228 struct hammer2_reptrack
{
230 struct hammer2_reptrack
*next
;
231 struct hammer2_chain
*chain
;
235 * Core topology for chain (embedded in chain). Protected by a spinlock.
237 struct hammer2_chain_core
{
239 struct hammer2_reptrack
*reptrack
;
240 struct hammer2_chain_tree rbtree
; /* sub-chains */
241 int live_zero
; /* blockref array opt */
242 u_int live_count
; /* live (not deleted) chains in tree */
243 u_int chain_count
; /* live + deleted chains under core */
244 int generation
; /* generation number (inserts only) */
247 typedef struct hammer2_chain_core hammer2_chain_core_t
;
250 * DIO - Management structure wrapping system buffer cache.
252 * HAMMER2 uses an I/O abstraction that allows it to cache and manipulate
253 * fixed-sized filesystem buffers frontend by variable-sized hammer2_chain
256 /* #define HAMMER2_IO_DEBUG */
258 #ifdef HAMMER2_IO_DEBUG
259 #define HAMMER2_IO_DEBUG_ARGS , const char *file, int line
260 #define HAMMER2_IO_DEBUG_CALL , file, line
261 #define HAMMER2_IO_DEBUG_COUNT 2048
262 #define HAMMER2_IO_DEBUG_MASK (HAMMER2_IO_DEBUG_COUNT - 1)
264 #define HAMMER2_IO_DEBUG_ARGS
265 #define HAMMER2_IO_DEBUG_CALL
269 struct hammer2_io
*next
;
270 struct hammer2_dev
*hmp
;
273 off_t dbase
; /* offset of devvp within volumes */
277 int act
; /* activity */
278 int btype
; /* approximate BREF_TYPE_* */
281 #ifdef HAMMER2_IO_DEBUG
286 uint64_t dedup_valid
; /* valid for dedup operation */
287 uint64_t dedup_alloc
; /* allocated / de-dupable */
288 #ifdef HAMMER2_IO_DEBUG
289 const char *debug_file
[HAMMER2_IO_DEBUG_COUNT
];
290 void *debug_td
[HAMMER2_IO_DEBUG_COUNT
];
291 int debug_line
[HAMMER2_IO_DEBUG_COUNT
];
292 uint64_t debug_refs
[HAMMER2_IO_DEBUG_COUNT
];
296 typedef struct hammer2_io hammer2_io_t
;
298 struct hammer2_io_hash
{
300 struct hammer2_io
*base
;
303 typedef struct hammer2_io_hash hammer2_io_hash_t
;
305 #define HAMMER2_DIO_INPROG 0x8000000000000000LLU /* bio in progress */
306 #define HAMMER2_DIO_GOOD 0x4000000000000000LLU /* dio->bp is stable */
307 #define HAMMER2_DIO_WAITING 0x2000000000000000LLU /* wait on INPROG */
308 #define HAMMER2_DIO_DIRTY 0x1000000000000000LLU /* flush last drop */
309 #define HAMMER2_DIO_FLUSH 0x0800000000000000LLU /* immediate flush */
311 #define HAMMER2_DIO_MASK 0x00FFFFFFFFFFFFFFLLU
313 struct hammer2_inum_hash
{
315 struct hammer2_inode
*base
;
318 typedef struct hammer2_inum_hash hammer2_inum_hash_t
;
321 * Primary chain structure keeps track of the topology in-memory.
323 struct hammer2_chain
{
325 hammer2_chain_core_t core
;
326 RB_ENTRY(hammer2_chain
) rbnode
; /* live chain(s) */
327 hammer2_blockref_t bref
;
328 struct hammer2_chain
*parent
;
329 struct hammer2_dev
*hmp
;
330 struct hammer2_pfs
*pmp
; /* A PFS or super-root (spmp) */
332 struct lock diolk
; /* xop focus interlock */
333 hammer2_io_t
*dio
; /* physical data buffer */
334 hammer2_media_data_t
*data
; /* data pointer shortcut */
335 u_int bytes
; /* physical data size */
339 int error
; /* on-lock data error state */
340 int cache_index
; /* heur speeds up lookup */
342 TAILQ_ENTRY(hammer2_chain
) lru_node
; /* 0-refs LRU */
345 typedef struct hammer2_chain hammer2_chain_t
;
347 int hammer2_chain_cmp(hammer2_chain_t
*chain1
, hammer2_chain_t
*chain2
);
348 RB_PROTOTYPE(hammer2_chain_tree
, hammer2_chain
, rbnode
, hammer2_chain_cmp
);
351 * Passed to hammer2_chain_create(), causes methods to be inherited from
354 #define HAMMER2_METH_DEFAULT -1
357 * Special notes on flags:
359 * INITIAL - This flag allows a chain to be created and for storage to
360 * be allocated without having to immediately instantiate the
361 * related buffer. The data is assumed to be all-zeros. It
362 * is primarily used for indirect blocks.
364 * MODIFIED - The chain's media data has been modified. Prevents chain
365 * free on lastdrop if still in the topology.
367 * UPDATE - Chain might not be modified but parent blocktable needs
368 * an update. Prevents chain free on lastdrop if still in
371 * BLKMAPPED - Indicates that the chain is present in the parent blockmap.
373 * BLKMAPUPD - Indicates that the chain is present but needs to be updated
374 * in the parent blockmap.
376 #define HAMMER2_CHAIN_MODIFIED 0x00000001 /* dirty chain data */
377 #define HAMMER2_CHAIN_ALLOCATED 0x00000002 /* kmalloc'd chain */
378 #define HAMMER2_CHAIN_DESTROY 0x00000004
379 #define HAMMER2_CHAIN_DEDUPABLE 0x00000008 /* registered w/dedup */
380 #define HAMMER2_CHAIN_DELETED 0x00000010 /* deleted chain */
381 #define HAMMER2_CHAIN_INITIAL 0x00000020 /* initial create */
382 #define HAMMER2_CHAIN_UPDATE 0x00000040 /* need parent update */
383 #define HAMMER2_CHAIN_NOTTESTED 0x00000080 /* crc not generated */
384 #define HAMMER2_CHAIN_TESTEDGOOD 0x00000100 /* crc tested good */
385 #define HAMMER2_CHAIN_ONFLUSH 0x00000200 /* on a flush list */
386 #define HAMMER2_CHAIN_UNUSED0400 0x00000400
387 #define HAMMER2_CHAIN_VOLUMESYNC 0x00000800 /* needs volume sync */
388 #define HAMMER2_CHAIN_UNUSED1000 0x00001000
389 #define HAMMER2_CHAIN_COUNTEDBREFS 0x00002000 /* block table stats */
390 #define HAMMER2_CHAIN_ONRBTREE 0x00004000 /* on parent RB tree */
391 #define HAMMER2_CHAIN_UNUSED8000 0x00008000
392 #define HAMMER2_CHAIN_UNUSED10000 0x00010000
393 #define HAMMER2_CHAIN_RELEASE 0x00020000 /* don't keep around */
394 #define HAMMER2_CHAIN_BLKMAPPED 0x00040000 /* present in blkmap */
395 #define HAMMER2_CHAIN_BLKMAPUPD 0x00080000 /* +needs updating */
396 #define HAMMER2_CHAIN_IOINPROG 0x00100000 /* I/O interlock */
397 #define HAMMER2_CHAIN_IOSIGNAL 0x00200000 /* I/O interlock */
398 #define HAMMER2_CHAIN_PFSBOUNDARY 0x00400000 /* super->pfs inode */
399 #define HAMMER2_CHAIN_HINT_LEAF_COUNT 0x00800000 /* redo leaf count */
400 #define HAMMER2_CHAIN_UNUSED1000000 0x01000000
402 #define HAMMER2_CHAIN_FLUSH_MASK (HAMMER2_CHAIN_MODIFIED | \
403 HAMMER2_CHAIN_UPDATE | \
404 HAMMER2_CHAIN_ONFLUSH | \
405 HAMMER2_CHAIN_DESTROY)
408 * Hammer2 error codes, used by chain->error and cluster->error. The error
409 * code is typically set on-lock unless no I/O was requested, and set on
410 * I/O otherwise. If set for a cluster it generally means that the cluster
411 * code could not find a valid copy to present.
413 * All H2 error codes are flags and can be accumulated by ORing them
416 * IO - An I/O error occurred
417 * CHECK - I/O succeeded but did not match the check code
418 * INCOMPLETE - A cluster is not complete enough to use, or
419 * a chain cannot be loaded because its parent has an error.
421 * NOTE: API allows callers to check zero/non-zero to determine if an error
424 * NOTE: Chain's data field is usually NULL on an IO error but not necessarily
425 * NULL on other errors. Check chain->error, not chain->data.
427 #define HAMMER2_ERROR_NONE 0 /* no error (must be 0) */
428 #define HAMMER2_ERROR_EIO 0x00000001 /* device I/O error */
429 #define HAMMER2_ERROR_CHECK 0x00000002 /* check code error */
430 #define HAMMER2_ERROR_INCOMPLETE 0x00000004 /* incomplete cluster */
431 #define HAMMER2_ERROR_DEPTH 0x00000008 /* tmp depth limit */
432 #define HAMMER2_ERROR_BADBREF 0x00000010 /* illegal bref */
433 #define HAMMER2_ERROR_ENOSPC 0x00000020 /* allocation failure */
434 #define HAMMER2_ERROR_ENOENT 0x00000040 /* entry not found */
435 #define HAMMER2_ERROR_ENOTEMPTY 0x00000080 /* dir not empty */
436 #define HAMMER2_ERROR_EAGAIN 0x00000100 /* retry */
437 #define HAMMER2_ERROR_ENOTDIR 0x00000200 /* not directory */
438 #define HAMMER2_ERROR_EISDIR 0x00000400 /* is directory */
439 #define HAMMER2_ERROR_EINPROGRESS 0x00000800 /* already running */
440 #define HAMMER2_ERROR_ABORTED 0x00001000 /* aborted operation */
441 #define HAMMER2_ERROR_EOF 0x00002000 /* end of scan */
442 #define HAMMER2_ERROR_EINVAL 0x00004000 /* catch-all */
443 #define HAMMER2_ERROR_EEXIST 0x00008000 /* entry exists */
444 #define HAMMER2_ERROR_EDEADLK 0x00010000
445 #define HAMMER2_ERROR_ESRCH 0x00020000
446 #define HAMMER2_ERROR_ETIMEDOUT 0x00040000
449 * Flags passed to hammer2_chain_lookup() and hammer2_chain_next()
452 * NODATA - Asks that the chain->data not be resolved in order
455 * NODIRECT - Prevents a lookup of offset 0 in an inode from returning
456 * the inode itself if the inode is in DIRECTDATA mode
457 * (i.e. file is <= 512 bytes). Used by the synchronization
458 * code to prevent confusion.
460 * SHARED - The input chain is expected to be locked shared,
461 * and the output chain is locked shared.
463 * MATCHIND - Allows an indirect block / freemap node to be returned
464 * when the passed key range matches the radix. Remember
465 * that key_end is inclusive (e.g. {0x000,0xFFF},
466 * not {0x000,0x1000}).
468 * (Cannot be used for remote or cluster ops).
470 * ALWAYS - Always resolve the data. If ALWAYS and NODATA are both
471 * missing, bulk file data is not resolved but inodes and
472 * other meta-data will.
474 #define HAMMER2_LOOKUP_UNUSED0001 0x00000001
475 #define HAMMER2_LOOKUP_NODATA 0x00000002 /* data left NULL */
476 #define HAMMER2_LOOKUP_NODIRECT 0x00000004 /* no offset=0 DD */
477 #define HAMMER2_LOOKUP_SHARED 0x00000100
478 #define HAMMER2_LOOKUP_MATCHIND 0x00000200 /* return all chains */
479 #define HAMMER2_LOOKUP_UNUSED0400 0x00000400
480 #define HAMMER2_LOOKUP_ALWAYS 0x00000800 /* resolve data */
481 #define HAMMER2_LOOKUP_UNUSED1000 0x00001000
484 * Flags passed to hammer2_chain_modify() and hammer2_chain_resize()
486 * NOTE: OPTDATA allows us to avoid instantiating buffers for INDIRECT
487 * blocks in the INITIAL-create state.
489 #define HAMMER2_MODIFY_OPTDATA 0x00000002 /* data can be NULL */
492 * Flags passed to hammer2_chain_lock()
494 * NOTE: NONBLOCK is only used for hammer2_chain_repparent() and getparent(),
495 * other functions (e.g. hammer2_chain_lookup(), etc) can't handle its
498 #define HAMMER2_RESOLVE_NEVER 1
499 #define HAMMER2_RESOLVE_MAYBE 2
500 #define HAMMER2_RESOLVE_ALWAYS 3
501 #define HAMMER2_RESOLVE_MASK 0x0F
503 #define HAMMER2_RESOLVE_SHARED 0x10 /* request shared lock */
504 #define HAMMER2_RESOLVE_LOCKAGAIN 0x20 /* another shared lock */
505 #define HAMMER2_RESOLVE_UNUSED40 0x40
506 #define HAMMER2_RESOLVE_NONBLOCK 0x80 /* non-blocking */
509 * Flags passed to hammer2_chain_delete()
511 #define HAMMER2_DELETE_PERMANENT 0x0001
514 * Flags passed to hammer2_chain_insert() or hammer2_chain_rename()
515 * or hammer2_chain_create().
517 #define HAMMER2_INSERT_PFSROOT 0x0004
518 #define HAMMER2_INSERT_SAMEPARENT 0x0008
521 * hammer2_freemap_adjust()
523 #define HAMMER2_FREEMAP_DORECOVER 1
525 #define HAMMER2_FREEMAP_DOMAYFREE 2
526 #define HAMMER2_FREEMAP_DOREALFREE 3
530 * HAMMER2 cluster - A set of chains representing the same entity.
532 * hammer2_cluster typically represents a temporary set of representitive
533 * chains. The one exception is that a hammer2_cluster is embedded in
534 * hammer2_inode. This embedded cluster is ONLY used to track the
535 * representitive chains and cannot be directly locked.
537 * A cluster is usually temporary (and thus per-thread) for locking purposes,
538 * allowing us to embed the asynchronous storage required for cluster
539 * operations in the cluster itself and adjust the state and status without
540 * having to worry too much about SMP issues.
542 * The exception is the cluster embedded in the hammer2_inode structure.
543 * This is used to cache the cluster state on an inode-by-inode basis.
544 * Individual hammer2_chain structures not incorporated into clusters might
545 * also stick around to cache miscellanious elements.
547 * Because the cluster is a 'working copy' and is usually subject to cluster
548 * quorum rules, it is quite possible for us to end up with an insufficient
549 * number of live chains to execute an operation. If an insufficient number
550 * of chains remain in a working copy, the operation may have to be
551 * downgraded, retried, stall until the requisit number of chains are
552 * available, or possibly even error out depending on the mount type.
554 * A cluster's focus is set when it is locked. The focus can only be set
555 * to a chain still part of the synchronized set.
557 #define HAMMER2_XOPFIFO 16
558 #define HAMMER2_XOPFIFO_MASK (HAMMER2_XOPFIFO - 1)
559 #define HAMMER2_XOPTHREADS_MIN 32
560 #define HAMMER2_XOPGROUPS_MIN 4
562 #define HAMMER2_MAXCLUSTER 8
563 #define HAMMER2_XOPMASK_CLUSTER ((uint64_t)((1LLU << HAMMER2_MAXCLUSTER) - 1))
564 #define HAMMER2_XOPMASK_VOP ((uint64_t)0x0000000080000000LLU)
565 #define HAMMER2_XOPMASK_FIFOW ((uint64_t)0x0000000040000000LLU)
566 #define HAMMER2_XOPMASK_WAIT ((uint64_t)0x0000000020000000LLU)
567 #define HAMMER2_XOPMASK_FEED ((uint64_t)0x0000000100000000LLU)
569 #define HAMMER2_XOPMASK_ALLDONE (HAMMER2_XOPMASK_VOP | HAMMER2_XOPMASK_CLUSTER)
571 struct hammer2_cluster_item
{
572 hammer2_chain_t
*chain
;
577 typedef struct hammer2_cluster_item hammer2_cluster_item_t
;
580 * INVALID - Invalid for focus, i.e. not part of synchronized set.
581 * Once set, this bit is sticky across operations.
583 * FEMOD - Indicates that front-end modifying operations can
584 * mess with this entry and MODSYNC will copy also
587 #define HAMMER2_CITEM_INVALID 0x00000001
588 #define HAMMER2_CITEM_FEMOD 0x00000002
589 #define HAMMER2_CITEM_NULL 0x00000004
591 struct hammer2_cluster
{
592 int refs
; /* track for deallocation */
594 struct hammer2_pfs
*pmp
;
597 int error
; /* error code valid on lock */
599 hammer2_chain_t
*focus
; /* current focus (or mod) */
600 hammer2_cluster_item_t array
[HAMMER2_MAXCLUSTER
];
603 typedef struct hammer2_cluster hammer2_cluster_t
;
606 * WRHARD - Hard mounts can write fully synchronized
607 * RDHARD - Hard mounts can read fully synchronized
608 * UNHARD - Unsynchronized masters present
609 * NOHARD - No masters visible
610 * WRSOFT - Soft mounts can write to at least the SOFT_MASTER
611 * RDSOFT - Soft mounts can read from at least a SOFT_SLAVE
612 * UNSOFT - Unsynchronized slaves present
613 * NOSOFT - No slaves visible
614 * RDSLAVE - slaves are accessible (possibly unsynchronized or remote).
615 * MSYNCED - All masters are fully synchronized
616 * SSYNCED - All known local slaves are fully synchronized to masters
618 * All available masters are always incorporated. All PFSs belonging to a
619 * cluster (master, slave, copy, whatever) always try to synchronize the
620 * total number of known masters in the PFSs root inode.
622 * A cluster might have access to many slaves, copies, or caches, but we
623 * have a limited number of cluster slots. Any such elements which are
624 * directly mounted from block device(s) will always be incorporated. Note
625 * that SSYNCED only applies to such elements which are directly mounted,
626 * not to any remote slaves, copies, or caches that could be available. These
627 * bits are used to monitor and drive our synchronization threads.
629 * When asking the question 'is any data accessible at all', then a simple
630 * test against (RDHARD|RDSOFT|RDSLAVE) gives you the answer. If any of
631 * these bits are set the object can be read with certain caveats:
632 * RDHARD - no caveats. RDSOFT - authoritative but might not be synchronized.
633 * and RDSLAVE - not authoritative, has some data but it could be old or
636 * When both soft and hard mounts are available, data will be read and written
637 * via the soft mount only. But all might be in the cluster because
638 * background synchronization threads still need to do their work.
640 #define HAMMER2_CLUSTER_INODE 0x00000001 /* embedded in inode struct */
641 #define HAMMER2_CLUSTER_UNUSED2 0x00000002
642 #define HAMMER2_CLUSTER_LOCKED 0x00000004 /* cluster lks not recursive */
643 #define HAMMER2_CLUSTER_WRHARD 0x00000100 /* hard-mount can write */
644 #define HAMMER2_CLUSTER_RDHARD 0x00000200 /* hard-mount can read */
645 #define HAMMER2_CLUSTER_UNHARD 0x00000400 /* unsynchronized masters */
646 #define HAMMER2_CLUSTER_NOHARD 0x00000800 /* no masters visible */
647 #define HAMMER2_CLUSTER_WRSOFT 0x00001000 /* soft-mount can write */
648 #define HAMMER2_CLUSTER_RDSOFT 0x00002000 /* soft-mount can read */
649 #define HAMMER2_CLUSTER_UNSOFT 0x00004000 /* unsynchronized slaves */
650 #define HAMMER2_CLUSTER_NOSOFT 0x00008000 /* no slaves visible */
651 #define HAMMER2_CLUSTER_MSYNCED 0x00010000 /* all masters synchronized */
652 #define HAMMER2_CLUSTER_SSYNCED 0x00020000 /* known slaves synchronized */
654 #define HAMMER2_CLUSTER_ANYDATA ( HAMMER2_CLUSTER_RDHARD | \
655 HAMMER2_CLUSTER_RDSOFT | \
656 HAMMER2_CLUSTER_RDSLAVE)
658 #define HAMMER2_CLUSTER_RDOK ( HAMMER2_CLUSTER_RDHARD | \
659 HAMMER2_CLUSTER_RDSOFT)
661 #define HAMMER2_CLUSTER_WROK ( HAMMER2_CLUSTER_WRHARD | \
662 HAMMER2_CLUSTER_WRSOFT)
664 #define HAMMER2_CLUSTER_ZFLAGS ( HAMMER2_CLUSTER_WRHARD | \
665 HAMMER2_CLUSTER_RDHARD | \
666 HAMMER2_CLUSTER_WRSOFT | \
667 HAMMER2_CLUSTER_RDSOFT | \
668 HAMMER2_CLUSTER_MSYNCED | \
669 HAMMER2_CLUSTER_SSYNCED)
671 TAILQ_HEAD(inoq_head
, hammer2_inode
); /* ip->entry */
672 TAILQ_HEAD(depq_head
, hammer2_depend
); /* depend->entry */
674 struct hammer2_depend
{
675 TAILQ_ENTRY(hammer2_depend
) entry
;
676 struct inoq_head sideq
;
682 typedef struct hammer2_depend hammer2_depend_t
;
687 * NOTE: The inode-embedded cluster is never used directly for I/O (since
688 * it may be shared). Instead it will be replicated-in and synchronized
689 * back out if changed.
691 struct hammer2_inode
{
692 struct hammer2_inode
*next
; /* inode tree */
693 TAILQ_ENTRY(hammer2_inode
) entry
; /* SYNCQ/SIDEQ */
694 hammer2_depend_t
*depend
; /* non-NULL if SIDEQ */
695 hammer2_depend_t depend_static
; /* (in-place allocation) */
696 hammer2_mtx_t lock
; /* inode lock */
697 hammer2_mtx_t truncate_lock
; /* prevent truncates */
698 struct hammer2_pfs
*pmp
; /* PFS mount */
700 hammer2_spin_t cluster_spin
; /* update cluster */
701 hammer2_cluster_t cluster
;
702 hammer2_cluster_item_t ccache
[HAMMER2_MAXCLUSTER
];
704 struct lockf advlock
;
706 u_int refs
; /* +vpref, +flushref */
707 int ihash
; /* xop worker distribution */
708 uint8_t comp_heuristic
;
709 hammer2_inode_meta_t meta
; /* copy of meta-data */
713 typedef struct hammer2_inode hammer2_inode_t
;
716 * MODIFIED - Inode is in a modified state, ip->meta may have changes.
717 * RESIZED - Inode truncated (any) or inode extended beyond
720 * SYNCQ - Inode is included in the current filesystem sync. The
721 * DELETING and CREATING flags will be acted upon.
723 * SIDEQ - Inode has likely been disconnected from the vnode topology
724 * and so is not visible to the vnode-based filesystem syncer
725 * code, but is dirty and must be included in the next
726 * filesystem sync. These inodes are moved to the SYNCQ at
727 * the time the sync occurs.
729 * Inodes are not placed on this queue simply because they have
730 * become dirty, if a vnode is attached.
732 * DELETING - Inode is flagged for deletion during the next filesystem
733 * sync. That is, the inode's chain is currently connected
734 * and must be deleting during the current or next fs sync.
736 * CREATING - Inode is flagged for creation during the next filesystem
737 * sync. That is, the inode's chain topology exists (so
738 * kernel buffer flushes can occur), but is currently
739 * disconnected and must be inserted during the current or
740 * next fs sync. If the DELETING flag is also set, the
741 * topology can be thrown away instead.
743 * If an inode that is already part of the current filesystem sync is
744 * modified by the frontend, including by buffer flushes, the inode lock
745 * code detects the SYNCQ flag and moves the inode to the head of the
746 * flush-in-progress, then blocks until the flush has gotten past it.
748 #define HAMMER2_INODE_MODIFIED 0x0001
749 #define HAMMER2_INODE_UNUSED0002 0x0002
750 #define HAMMER2_INODE_UNUSED0004 0x0004
751 #define HAMMER2_INODE_ONHASH 0x0008
752 #define HAMMER2_INODE_RESIZED 0x0010 /* requires inode_chain_sync */
753 #define HAMMER2_INODE_UNUSED0020 0x0020
754 #define HAMMER2_INODE_ISUNLINKED 0x0040
755 #define HAMMER2_INODE_UNUSED0080 0x0080
756 #define HAMMER2_INODE_SIDEQ 0x0100 /* on side processing queue */
757 #define HAMMER2_INODE_NOSIDEQ 0x0200 /* disable sideq operation */
758 #define HAMMER2_INODE_DIRTYDATA 0x0400 /* interlocks inode flush */
759 #define HAMMER2_INODE_SYNCQ 0x0800 /* sync interlock, sequenced */
760 #define HAMMER2_INODE_DELETING 0x1000 /* sync interlock, chain topo */
761 #define HAMMER2_INODE_CREATING 0x2000 /* sync interlock, chain topo */
762 #define HAMMER2_INODE_SYNCQ_WAKEUP 0x4000 /* sync interlock wakeup */
763 #define HAMMER2_INODE_SYNCQ_PASS2 0x8000 /* force retry delay */
765 #define HAMMER2_INODE_DIRTY (HAMMER2_INODE_MODIFIED | \
766 HAMMER2_INODE_DIRTYDATA | \
767 HAMMER2_INODE_DELETING | \
768 HAMMER2_INODE_CREATING)
771 * Transaction management sub-structure under hammer2_pfs
773 struct hammer2_trans
{
778 typedef struct hammer2_trans hammer2_trans_t
;
780 #define HAMMER2_TRANS_ISFLUSH 0x80000000 /* flush code */
781 #define HAMMER2_TRANS_BUFCACHE 0x40000000 /* bio strategy */
782 #define HAMMER2_TRANS_SIDEQ 0x20000000 /* run sideq */
783 #define HAMMER2_TRANS_UNUSED10 0x10000000
784 #define HAMMER2_TRANS_WAITING 0x08000000 /* someone waiting */
785 #define HAMMER2_TRANS_RESCAN 0x04000000 /* rescan sideq */
786 #define HAMMER2_TRANS_MASK 0x00FFFFFF /* count mask */
788 #define HAMMER2_FREEMAP_HEUR_NRADIX 4 /* pwr 2 PBUFRADIX-LBUFRADIX */
789 #define HAMMER2_FREEMAP_HEUR_TYPES 8
790 #define HAMMER2_FREEMAP_HEUR_SIZE (HAMMER2_FREEMAP_HEUR_NRADIX * \
791 HAMMER2_FREEMAP_HEUR_TYPES)
793 #define HAMMER2_DEDUP_HEUR_SIZE (65536 * 4)
794 #define HAMMER2_DEDUP_HEUR_MASK (HAMMER2_DEDUP_HEUR_SIZE - 1)
796 #define HAMMER2_FLUSH_TOP 0x0001
797 #define HAMMER2_FLUSH_ALL 0x0002
798 #define HAMMER2_FLUSH_INODE_STOP 0x0004 /* stop at sub-inode */
799 #define HAMMER2_FLUSH_FSSYNC 0x0008 /* part of filesystem sync */
803 * Hammer2 support thread element.
805 * Potentially many support threads can hang off of hammer2, primarily
806 * off the hammer2_pfs structure. Typically:
808 * td x Nodes A synchronization thread for each node.
809 * td x Nodes x workers Worker threads for frontend operations.
810 * td x 1 Bioq thread for logical buffer writes.
812 * In addition, the synchronization thread(s) associated with the
813 * super-root PFS (spmp) for a node is responsible for automatic bulkfree
816 struct hammer2_thread
{
817 struct hammer2_pfs
*pmp
;
818 struct hammer2_dev
*hmp
;
819 hammer2_xop_list_t xopq
;
822 int clindex
; /* cluster element index */
824 char *scratch
; /* MAXPHYS */
827 typedef struct hammer2_thread hammer2_thread_t
;
829 #define HAMMER2_THREAD_UNMOUNTING 0x0001 /* unmount request */
830 #define HAMMER2_THREAD_DEV 0x0002 /* related to dev, not pfs */
831 #define HAMMER2_THREAD_WAITING 0x0004 /* thread in idle tsleep */
832 #define HAMMER2_THREAD_REMASTER 0x0008 /* remaster request */
833 #define HAMMER2_THREAD_STOP 0x0010 /* exit request */
834 #define HAMMER2_THREAD_FREEZE 0x0020 /* force idle */
835 #define HAMMER2_THREAD_FROZEN 0x0040 /* thread is frozen */
836 #define HAMMER2_THREAD_XOPQ 0x0080 /* work pending */
837 #define HAMMER2_THREAD_STOPPED 0x0100 /* thread has stopped */
838 #define HAMMER2_THREAD_UNFREEZE 0x0200
840 #define HAMMER2_THREAD_WAKEUP_MASK (HAMMER2_THREAD_UNMOUNTING | \
841 HAMMER2_THREAD_REMASTER | \
842 HAMMER2_THREAD_STOP | \
843 HAMMER2_THREAD_FREEZE | \
847 * Support structure for dedup heuristic.
849 struct hammer2_dedup
{
850 hammer2_off_t data_off
;
853 uint32_t saved_error
;
856 typedef struct hammer2_dedup hammer2_dedup_t
;
859 * hammer2_xop - container for VOP/XOP operation (allocated, not on stack).
861 * This structure is used to distribute a VOP operation across multiple
862 * nodes. It provides a rendezvous for concurrent node execution and
863 * can be detached from the frontend operation to allow the frontend to
866 * This structure also sequences operations on up to three inodes.
868 typedef void (*hammer2_xop_func_t
)(union hammer2_xop
*xop
, void *scratch
,
871 struct hammer2_xop_desc
{
872 hammer2_xop_func_t storage_func
; /* local storage function */
873 hammer2_xop_func_t dmsg_dispatch
; /* dmsg dispatch function */
874 hammer2_xop_func_t dmsg_process
; /* dmsg processing function */
878 typedef struct hammer2_xop_desc hammer2_xop_desc_t
;
880 struct hammer2_xop_fifo
{
881 TAILQ_ENTRY(hammer2_xop_head
) entry
;
882 hammer2_chain_t
*array
[HAMMER2_XOPFIFO
];
883 int errors
[HAMMER2_XOPFIFO
];
887 hammer2_thread_t
*thr
;
890 typedef struct hammer2_xop_fifo hammer2_xop_fifo_t
;
892 #define HAMMER2_XOP_FIFO_RUN 0x0001
893 #define HAMMER2_XOP_FIFO_STALL 0x0002
895 struct hammer2_xop_head
{
896 hammer2_xop_desc_t
*desc
;
898 struct hammer2_inode
*ip1
;
899 struct hammer2_inode
*ip2
;
900 struct hammer2_inode
*ip3
;
901 struct hammer2_inode
*ip4
;
907 hammer2_key_t collect_key
;
912 hammer2_xop_fifo_t collect
[HAMMER2_MAXCLUSTER
];
913 hammer2_cluster_t cluster
; /* help collections */
914 hammer2_io_t
*focus_dio
;
917 typedef struct hammer2_xop_head hammer2_xop_head_t
;
919 struct hammer2_xop_ipcluster
{
920 hammer2_xop_head_t head
;
923 struct hammer2_xop_strategy
{
924 hammer2_xop_head_t head
;
931 struct hammer2_xop_readdir
{
932 hammer2_xop_head_t head
;
936 struct hammer2_xop_nresolve
{
937 hammer2_xop_head_t head
;
938 hammer2_key_t lhc
; /* if name is NULL used lhc */
941 struct hammer2_xop_unlink
{
942 hammer2_xop_head_t head
;
947 #define H2DOPERM_PERMANENT 0x01
948 #define H2DOPERM_FORCE 0x02
949 #define H2DOPERM_IGNINO 0x04
951 struct hammer2_xop_nrename
{
952 hammer2_xop_head_t head
;
957 struct hammer2_xop_scanlhc
{
958 hammer2_xop_head_t head
;
962 struct hammer2_xop_scanall
{
963 hammer2_xop_head_t head
;
964 hammer2_key_t key_beg
; /* inclusive */
965 hammer2_key_t key_end
; /* inclusive */
970 struct hammer2_xop_lookup
{
971 hammer2_xop_head_t head
;
975 struct hammer2_xop_mkdirent
{
976 hammer2_xop_head_t head
;
977 hammer2_dirent_head_t dirent
;
981 struct hammer2_xop_create
{
982 hammer2_xop_head_t head
;
983 hammer2_inode_meta_t meta
; /* initial metadata */
988 struct hammer2_xop_destroy
{
989 hammer2_xop_head_t head
;
992 struct hammer2_xop_fsync
{
993 hammer2_xop_head_t head
;
994 hammer2_inode_meta_t meta
;
997 int clear_directdata
;
1000 struct hammer2_xop_unlinkall
{
1001 hammer2_xop_head_t head
;
1002 hammer2_key_t key_beg
;
1003 hammer2_key_t key_end
;
1006 struct hammer2_xop_connect
{
1007 hammer2_xop_head_t head
;
1011 struct hammer2_xop_flush
{
1012 hammer2_xop_head_t head
;
1015 typedef struct hammer2_xop_readdir hammer2_xop_readdir_t
;
1016 typedef struct hammer2_xop_nresolve hammer2_xop_nresolve_t
;
1017 typedef struct hammer2_xop_unlink hammer2_xop_unlink_t
;
1018 typedef struct hammer2_xop_nrename hammer2_xop_nrename_t
;
1019 typedef struct hammer2_xop_ipcluster hammer2_xop_ipcluster_t
;
1020 typedef struct hammer2_xop_strategy hammer2_xop_strategy_t
;
1021 typedef struct hammer2_xop_mkdirent hammer2_xop_mkdirent_t
;
1022 typedef struct hammer2_xop_create hammer2_xop_create_t
;
1023 typedef struct hammer2_xop_destroy hammer2_xop_destroy_t
;
1024 typedef struct hammer2_xop_fsync hammer2_xop_fsync_t
;
1025 typedef struct hammer2_xop_unlinkall hammer2_xop_unlinkall_t
;
1026 typedef struct hammer2_xop_scanlhc hammer2_xop_scanlhc_t
;
1027 typedef struct hammer2_xop_scanall hammer2_xop_scanall_t
;
1028 typedef struct hammer2_xop_lookup hammer2_xop_lookup_t
;
1029 typedef struct hammer2_xop_connect hammer2_xop_connect_t
;
1030 typedef struct hammer2_xop_flush hammer2_xop_flush_t
;
1033 hammer2_xop_head_t head
;
1034 hammer2_xop_ipcluster_t xop_ipcluster
;
1035 hammer2_xop_readdir_t xop_readdir
;
1036 hammer2_xop_nresolve_t xop_nresolve
;
1037 hammer2_xop_unlink_t xop_unlink
;
1038 hammer2_xop_nrename_t xop_nrename
;
1039 hammer2_xop_strategy_t xop_strategy
;
1040 hammer2_xop_mkdirent_t xop_mkdirent
;
1041 hammer2_xop_create_t xop_create
;
1042 hammer2_xop_destroy_t xop_destroy
;
1043 hammer2_xop_fsync_t xop_fsync
;
1044 hammer2_xop_unlinkall_t xop_unlinkall
;
1045 hammer2_xop_scanlhc_t xop_scanlhc
;
1046 hammer2_xop_scanall_t xop_scanall
;
1047 hammer2_xop_lookup_t xop_lookup
;
1048 hammer2_xop_flush_t xop_flush
;
1049 hammer2_xop_connect_t xop_connect
;
1052 typedef union hammer2_xop hammer2_xop_t
;
1055 * hammer2_xop_group - Manage XOP support threads.
1057 struct hammer2_xop_group
{
1058 hammer2_thread_t thrs
[HAMMER2_MAXCLUSTER
];
1061 typedef struct hammer2_xop_group hammer2_xop_group_t
;
1064 * flags to hammer2_xop_collect()
1066 #define HAMMER2_XOP_COLLECT_NOWAIT 0x00000001
1067 #define HAMMER2_XOP_COLLECT_WAITALL 0x00000002
1070 * flags to hammer2_xop_alloc()
1072 * MODIFYING - This is a modifying transaction, allocate a mtid.
1074 #define HAMMER2_XOP_MODIFYING 0x00000001
1075 #define HAMMER2_XOP_STRATEGY 0x00000002
1076 #define HAMMER2_XOP_INODE_STOP 0x00000004
1077 #define HAMMER2_XOP_VOLHDR 0x00000008
1078 #define HAMMER2_XOP_FSSYNC 0x00000010
1081 * Device vnode management structure
1083 struct hammer2_devvp
{
1084 TAILQ_ENTRY(hammer2_devvp
) entry
;
1085 struct vnode
*devvp
; /* device vnode */
1086 char *path
; /* device vnode path */
1087 int open
; /* 1 if devvp open */
1090 typedef struct hammer2_devvp hammer2_devvp_t
;
1092 TAILQ_HEAD(hammer2_devvp_list
, hammer2_devvp
);
1094 typedef struct hammer2_devvp_list hammer2_devvp_list_t
;
1097 * Volume management structure
1099 struct hammer2_volume
{
1100 hammer2_devvp_t
*dev
; /* device vnode management */
1101 int id
; /* volume id */
1102 hammer2_off_t offset
; /* offset within volumes */
1103 hammer2_off_t size
; /* volume size */
1106 typedef struct hammer2_volume hammer2_volume_t
;
1109 * Global (per partition) management structure, represents a hard block
1110 * device. Typically referenced by hammer2_chain structures when applicable.
1111 * Typically not used for network-managed elements.
1113 * Note that a single hammer2_dev can be indirectly tied to multiple system
1114 * mount points. There is no direct relationship. System mounts are
1115 * per-cluster-id, not per-block-device, and a single hard mount might contain
1116 * many PFSs and those PFSs might combine together in various ways to form
1117 * the set of available clusters.
1119 struct hammer2_dev
{
1120 struct vnode
*devvp
; /* device vnode for root volume */
1121 int ronly
; /* read-only mount */
1122 int mount_count
; /* number of actively mounted PFSs */
1123 TAILQ_ENTRY(hammer2_dev
) mntentry
; /* hammer2_mntlist */
1125 struct malloc_type
*mchain_obj
;
1126 struct malloc_type
*mio_obj
;
1127 struct malloc_type
*mmsg
;
1128 kdmsg_iocom_t iocom
; /* volume-level dmsg interface */
1129 hammer2_io_hash_t iohash
[HAMMER2_IOHASH_SIZE
];
1132 int freemap_relaxed
;
1134 hammer2_chain_t vchain
; /* anchor chain (topology) */
1135 hammer2_chain_t fchain
; /* anchor chain (freemap) */
1136 hammer2_spin_t list_spin
;
1137 struct hammer2_pfs
*spmp
; /* super-root pmp for transactions */
1138 struct lock vollk
; /* lockmgr lock */
1139 struct lock bulklk
; /* bulkfree operation lock */
1140 struct lock bflock
; /* bulk-free manual function lock */
1141 hammer2_off_t heur_freemap
[HAMMER2_FREEMAP_HEUR_SIZE
];
1142 hammer2_dedup_t heur_dedup
[HAMMER2_DEDUP_HEUR_SIZE
];
1143 int volhdrno
; /* last volhdrno written */
1144 uint32_t hflags
; /* HMNT2 flags applicable to device */
1145 hammer2_off_t free_reserved
; /* nominal free reserved */
1146 hammer2_off_t total_size
; /* total size of volumes */
1147 int nvolumes
; /* total number of volumes */
1148 hammer2_thread_t bfthr
; /* bulk-free thread */
1149 char devrepname
[64]; /* for kprintf */
1150 hammer2_volume_data_t voldata
;
1151 hammer2_volume_data_t volsync
; /* synchronized voldata */
1153 hammer2_devvp_list_t devvpl
; /* list of device vnodes including *devvp */
1154 hammer2_volume_t volumes
[HAMMER2_MAX_VOLUMES
]; /* list of volumes */
1157 typedef struct hammer2_dev hammer2_dev_t
;
1160 * Per-cluster management structure. This structure will be tied to a
1161 * system mount point if the system is mounting the PFS, but is also used
1162 * to manage clusters encountered during the super-root scan or received
1163 * via LNK_SPANs that might not be mounted.
1165 * This structure is also used to represent the super-root that hangs off
1166 * of a hard mount point. The super-root is not really a cluster element.
1167 * In this case the spmp_hmp field will be non-NULL. It's just easier to do
1168 * this than to special case super-root manipulation in the hammer2_chain*
1169 * code as being only hammer2_dev-related.
1171 * pfs_mode and pfs_nmasters are rollup fields which critically describes
1172 * how elements of the cluster act on the cluster. pfs_mode is only applicable
1173 * when a PFS is mounted by the system. pfs_nmasters is our best guess as to
1174 * how many masters have been configured for a cluster and is always
1175 * applicable. pfs_types[] is an array with 1:1 correspondance to the
1176 * iroot cluster and describes the PFS types of the nodes making up the
1179 * WARNING! Portions of this structure have deferred initialization. In
1180 * particular, if not mounted there will be no wthread.
1181 * umounted network PFSs will also be missing iroot and numerous
1182 * other fields will not be initialized prior to mount.
1184 * Synchronization threads are chain-specific and only applicable
1185 * to local hard PFS entries. A hammer2_pfs structure may contain
1186 * more than one when multiple hard PFSs are present on the local
1187 * machine which require synchronization monitoring. Most PFSs
1188 * (such as snapshots) are 1xMASTER PFSs which do not need a
1189 * synchronization thread.
1191 * WARNING! The chains making up pfs->iroot's cluster are accounted for in
1192 * hammer2_dev->mount_count when the pfs is associated with a mount
1195 struct hammer2_pfs
{
1197 TAILQ_ENTRY(hammer2_pfs
) mntentry
; /* hammer2_pfslist */
1199 hammer2_dev_t
*spmp_hmp
; /* only if super-root pmp */
1200 hammer2_dev_t
*force_local
; /* only if 'local' mount */
1201 hammer2_inode_t
*iroot
; /* PFS root inode */
1202 uint8_t pfs_types
[HAMMER2_MAXCLUSTER
];
1203 char *pfs_names
[HAMMER2_MAXCLUSTER
];
1204 hammer2_dev_t
*pfs_hmps
[HAMMER2_MAXCLUSTER
];
1205 hammer2_blockset_t pfs_iroot_blocksets
[HAMMER2_MAXCLUSTER
];
1206 hammer2_spin_t blockset_spin
;
1207 hammer2_trans_t trans
;
1208 struct lock lock
; /* PFS lock for certain ops */
1209 struct netexport export
; /* nfs export */
1211 int ronly
; /* read-only mount */
1212 int hflags
; /* pfs-specific mount flags */
1213 struct malloc_type
*minode_obj
;
1214 /* note: inumhash not applicable to spmp */
1215 hammer2_inum_hash_t inumhash
[HAMMER2_INUMHASH_SIZE
];
1216 long inum_count
; /* #of inodes in inumhash */
1218 hammer2_tid_t modify_tid
; /* modify transaction id */
1219 hammer2_tid_t inode_tid
; /* inode allocator */
1220 uint8_t pfs_nmasters
; /* total masters */
1221 uint8_t pfs_mode
; /* operating mode PFSMODE */
1224 int free_ticks
; /* free_* calculations */
1226 hammer2_off_t free_reserved
;
1227 hammer2_off_t free_nominal
;
1228 uint32_t inmem_dirty_chains
;
1229 int count_lwinprog
; /* logical write in prog */
1230 hammer2_spin_t list_spin
;
1231 struct inoq_head syncq
; /* SYNCQ flagged inodes */
1232 struct depq_head depq
; /* SIDEQ flagged inodes */
1233 long sideq_count
; /* total inodes on depq */
1234 hammer2_thread_t sync_thrs
[HAMMER2_MAXCLUSTER
];
1235 uint32_t cluster_flags
; /* cached cluster flags */
1236 int has_xop_threads
;
1237 hammer2_spin_t xop_spin
; /* xop sequencer */
1238 hammer2_xop_group_t
*xop_groups
;
1241 typedef struct hammer2_pfs hammer2_pfs_t
;
1243 TAILQ_HEAD(hammer2_pfslist
, hammer2_pfs
);
1248 #define HAMMER2_PMPF_SPMP 0x00000001
1249 #define HAMMER2_PMPF_EMERG 0x00000002 /* Emergency delete mode */
1252 * NOTE: The LRU list contains at least all the chains with refs == 0
1253 * that can be recycled, and may contain additional chains which
1256 #define HAMMER2_LRU_LIMIT 4096
1258 #define HAMMER2_DIRTYCHAIN_WAITING 0x80000000
1259 #define HAMMER2_DIRTYCHAIN_MASK 0x7FFFFFFF
1261 #define HAMMER2_LWINPROG_WAITING 0x80000000
1262 #define HAMMER2_LWINPROG_WAITING0 0x40000000
1263 #define HAMMER2_LWINPROG_MASK 0x3FFFFFFF
1266 * hammer2_cluster_check
1268 #define HAMMER2_CHECK_NULL 0x00000001
1273 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
1274 #define VTOI(vp) ((hammer2_inode_t *)(vp)->v_data)
1277 #if defined(_KERNEL)
1279 #ifdef MALLOC_DECLARE
1280 MALLOC_DECLARE(M_HAMMER2
);
1285 MPTOPMP(struct mount
*mp
)
1287 return ((hammer2_pfs_t
*)mp
->mnt_data
);
1290 #define HAMMER2_DEDUP_FRAG (HAMMER2_PBUFSIZE / 64)
1291 #define HAMMER2_DEDUP_FRAGRADIX (HAMMER2_PBUFRADIX - 6)
1295 hammer2_dedup_mask(hammer2_io_t
*dio
, hammer2_off_t data_off
, u_int bytes
)
1301 bbeg
= (int)((data_off
& ~HAMMER2_OFF_MASK_RADIX
) - dio
->pbase
) >>
1302 HAMMER2_DEDUP_FRAGRADIX
;
1303 bits
= (int)((bytes
+ (HAMMER2_DEDUP_FRAG
- 1)) >>
1304 HAMMER2_DEDUP_FRAGRADIX
);
1305 if (bbeg
+ bits
== 64)
1306 mask
= (uint64_t)-1;
1308 mask
= ((uint64_t)1 << (bbeg
+ bits
)) - 1;
1310 mask
&= ~(((uint64_t)1 << bbeg
) - 1);
1317 hammer2_error_to_errno(int error
)
1320 if (error
& HAMMER2_ERROR_EIO
)
1322 else if (error
& HAMMER2_ERROR_CHECK
)
1324 else if (error
& HAMMER2_ERROR_ABORTED
)
1326 else if (error
& HAMMER2_ERROR_BADBREF
)
1328 else if (error
& HAMMER2_ERROR_ENOSPC
)
1330 else if (error
& HAMMER2_ERROR_ENOENT
)
1332 else if (error
& HAMMER2_ERROR_ENOTEMPTY
)
1334 else if (error
& HAMMER2_ERROR_EAGAIN
)
1336 else if (error
& HAMMER2_ERROR_ENOTDIR
)
1338 else if (error
& HAMMER2_ERROR_EISDIR
)
1340 else if (error
& HAMMER2_ERROR_EINPROGRESS
)
1341 error
= EINPROGRESS
;
1342 else if (error
& HAMMER2_ERROR_EEXIST
)
1344 else if (error
& HAMMER2_ERROR_EINVAL
)
1346 else if (error
& HAMMER2_ERROR_EDEADLK
)
1348 else if (error
& HAMMER2_ERROR_ESRCH
)
1350 else if (error
& HAMMER2_ERROR_ETIMEDOUT
)
1360 hammer2_errno_to_error(int error
)
1366 return HAMMER2_ERROR_EIO
;
1368 return HAMMER2_ERROR_CHECK
;
1370 return HAMMER2_ERROR_ABORTED
;
1372 // return HAMMER2_ERROR_BADBREF;
1374 return HAMMER2_ERROR_ENOSPC
;
1376 return HAMMER2_ERROR_ENOENT
;
1378 return HAMMER2_ERROR_ENOTEMPTY
;
1380 return HAMMER2_ERROR_EAGAIN
;
1382 return HAMMER2_ERROR_ENOTDIR
;
1384 return HAMMER2_ERROR_EISDIR
;
1386 return HAMMER2_ERROR_EINPROGRESS
;
1388 return HAMMER2_ERROR_EEXIST
;
1390 return HAMMER2_ERROR_EINVAL
;
1392 return HAMMER2_ERROR_EDEADLK
;
1394 return HAMMER2_ERROR_ESRCH
;
1396 return HAMMER2_ERROR_ETIMEDOUT
;
1398 return HAMMER2_ERROR_EINVAL
;
1403 extern struct vop_ops hammer2_vnode_vops
;
1404 extern struct vop_ops hammer2_spec_vops
;
1405 extern struct vop_ops hammer2_fifo_vops
;
1406 extern struct hammer2_pfslist hammer2_pfslist
;
1407 extern struct lock hammer2_mntlk
;
1409 extern int hammer2_aux_flags
;
1410 extern int hammer2_debug
;
1411 extern int hammer2_xop_nthreads
;
1412 extern int hammer2_xop_sgroups
;
1413 extern int hammer2_xop_xgroups
;
1414 extern int hammer2_xop_xbase
;
1415 extern int hammer2_xop_mod
;
1416 extern long hammer2_debug_inode
;
1417 extern int hammer2_cluster_meta_read
;
1418 extern int hammer2_cluster_data_read
;
1419 extern int hammer2_cluster_write
;
1420 extern int hammer2_dedup_enable
;
1421 extern int hammer2_always_compress
;
1422 extern int hammer2_flush_pipe
;
1423 extern int hammer2_dio_count
;
1424 extern int hammer2_dio_limit
;
1425 extern int hammer2_bulkfree_tps
;
1426 extern int hammer2_spread_workers
;
1427 extern int hammer2_limit_saved_depth
;
1428 extern long hammer2_chain_allocs
;
1429 extern long hammer2_limit_saved_chains
;
1430 extern long hammer2_limit_dirty_chains
;
1431 extern long hammer2_limit_dirty_inodes
;
1432 extern long hammer2_count_modified_chains
;
1433 extern long hammer2_iod_file_read
;
1434 extern long hammer2_iod_meta_read
;
1435 extern long hammer2_iod_indr_read
;
1436 extern long hammer2_iod_fmap_read
;
1437 extern long hammer2_iod_volu_read
;
1438 extern long hammer2_iod_file_write
;
1439 extern long hammer2_iod_file_wembed
;
1440 extern long hammer2_iod_file_wzero
;
1441 extern long hammer2_iod_file_wdedup
;
1442 extern long hammer2_iod_meta_write
;
1443 extern long hammer2_iod_indr_write
;
1444 extern long hammer2_iod_fmap_write
;
1445 extern long hammer2_iod_volu_write
;
1447 extern long hammer2_process_icrc32
;
1448 extern long hammer2_process_xxhash64
;
1450 extern struct objcache
*cache_buffer_read
;
1451 extern struct objcache
*cache_buffer_write
;
1452 extern struct objcache
*cache_xops
;
1457 #define hammer2_icrc32(buf, size) iscsi_crc32((buf), (size))
1458 #define hammer2_icrc32c(buf, size, crc) iscsi_crc32_ext((buf), (size), (crc))
1460 int hammer2_signal_check(time_t *timep
);
1461 const char *hammer2_error_str(int error
);
1462 const char *hammer2_bref_type_str(int btype
);
1464 int hammer2_get_dtype(uint8_t type
);
1465 int hammer2_get_vtype(uint8_t type
);
1466 uint8_t hammer2_get_obj_type(enum vtype vtype
);
1467 void hammer2_time_to_timespec(uint64_t xtime
, struct timespec
*ts
);
1468 uint64_t hammer2_timespec_to_time(const struct timespec
*ts
);
1469 uint32_t hammer2_to_unix_xid(const uuid_t
*uuid
);
1470 void hammer2_guid_to_uuid(uuid_t
*uuid
, uint32_t guid
);
1472 hammer2_key_t
hammer2_dirhash(const char *aname
, size_t len
);
1473 int hammer2_getradix(size_t bytes
);
1475 int hammer2_calc_logical(hammer2_inode_t
*ip
, hammer2_off_t uoff
,
1476 hammer2_key_t
*lbasep
, hammer2_key_t
*leofp
);
1477 int hammer2_calc_physical(hammer2_inode_t
*ip
, hammer2_key_t lbase
);
1478 void hammer2_update_time(uint64_t *timep
);
1479 void hammer2_adjreadcounter(int btype
, size_t bytes
);
1480 void hammer2_adjwritecounter(int btype
, size_t bytes
);
1485 struct vnode
*hammer2_igetv(hammer2_inode_t
*ip
, int *errorp
);
1486 hammer2_inode_t
*hammer2_inode_lookup(hammer2_pfs_t
*pmp
,
1487 hammer2_tid_t inum
);
1488 hammer2_inode_t
*hammer2_inode_get(hammer2_pfs_t
*pmp
,
1489 hammer2_xop_head_t
*xop
, hammer2_tid_t inum
, int idx
);
1490 void hammer2_inode_ref(hammer2_inode_t
*ip
);
1491 void hammer2_inode_drop(hammer2_inode_t
*ip
);
1492 void hammer2_inode_repoint(hammer2_inode_t
*ip
, hammer2_cluster_t
*cluster
);
1493 void hammer2_inode_repoint_one(hammer2_inode_t
*ip
, hammer2_cluster_t
*cluster
,
1495 hammer2_key_t
hammer2_inode_data_count(const hammer2_inode_t
*ip
);
1496 hammer2_key_t
hammer2_inode_inode_count(const hammer2_inode_t
*ip
);
1497 void hammer2_inode_modify(hammer2_inode_t
*ip
);
1498 void hammer2_inode_delayed_sideq(hammer2_inode_t
*ip
);
1499 void hammer2_inode_lock(hammer2_inode_t
*ip
, int how
);
1500 void hammer2_inode_lock4(hammer2_inode_t
*ip1
, hammer2_inode_t
*ip2
,
1501 hammer2_inode_t
*ip3
, hammer2_inode_t
*ip4
);
1502 void hammer2_inode_unlock(hammer2_inode_t
*ip
);
1503 void hammer2_inode_depend(hammer2_inode_t
*ip1
, hammer2_inode_t
*ip2
);
1504 hammer2_chain_t
*hammer2_inode_chain(hammer2_inode_t
*ip
, int clindex
, int how
);
1505 hammer2_chain_t
*hammer2_inode_chain_and_parent(hammer2_inode_t
*ip
,
1506 int clindex
, hammer2_chain_t
**parentp
, int how
);
1507 hammer2_mtx_state_t
hammer2_inode_lock_temp_release(hammer2_inode_t
*ip
);
1508 void hammer2_inode_lock_temp_restore(hammer2_inode_t
*ip
,
1509 hammer2_mtx_state_t ostate
);
1510 int hammer2_inode_lock_upgrade(hammer2_inode_t
*ip
);
1511 void hammer2_inode_lock_downgrade(hammer2_inode_t
*ip
, int);
1513 hammer2_inode_t
*hammer2_inode_create_normal(hammer2_inode_t
*pip
,
1514 struct vattr
*vap
, struct ucred
*cred
,
1515 hammer2_key_t inum
, int *errorp
);
1516 hammer2_inode_t
*hammer2_inode_create_pfs(hammer2_pfs_t
*spmp
,
1517 const char *name
, size_t name_len
,
1519 int hammer2_inode_chain_ins(hammer2_inode_t
*ip
);
1520 int hammer2_inode_chain_des(hammer2_inode_t
*ip
);
1521 int hammer2_inode_chain_sync(hammer2_inode_t
*ip
);
1522 int hammer2_inode_chain_flush(hammer2_inode_t
*ip
, int flags
);
1523 int hammer2_inode_unlink_finisher(hammer2_inode_t
*ip
, struct vnode
**vpp
);
1524 void hammer2_inode_vprecycle(struct vnode
*vp
);
1525 int hammer2_dirent_create(hammer2_inode_t
*dip
, const char *name
,
1526 size_t name_len
, hammer2_key_t inum
, uint8_t type
);
1531 hammer2_chain_t
*hammer2_chain_alloc(hammer2_dev_t
*hmp
,
1533 hammer2_blockref_t
*bref
);
1534 void hammer2_chain_init(hammer2_chain_t
*chain
);
1535 void hammer2_chain_ref(hammer2_chain_t
*chain
);
1536 void hammer2_chain_ref_hold(hammer2_chain_t
*chain
);
1537 void hammer2_chain_drop(hammer2_chain_t
*chain
);
1538 void hammer2_chain_drop_unhold(hammer2_chain_t
*chain
);
1539 void hammer2_chain_unhold(hammer2_chain_t
*chain
);
1540 void hammer2_chain_rehold(hammer2_chain_t
*chain
);
1541 int hammer2_chain_lock(hammer2_chain_t
*chain
, int how
);
1542 //void hammer2_chain_lock_unhold(hammer2_chain_t *chain, int how);
1543 void hammer2_chain_load_data(hammer2_chain_t
*chain
);
1545 int hammer2_chain_inode_find(hammer2_pfs_t
*pmp
, hammer2_key_t inum
,
1546 int clindex
, int flags
,
1547 hammer2_chain_t
**parentp
,
1548 hammer2_chain_t
**chainp
);
1549 int hammer2_chain_modify(hammer2_chain_t
*chain
, hammer2_tid_t mtid
,
1550 hammer2_off_t dedup_off
, int flags
);
1551 int hammer2_chain_modify_ip(hammer2_inode_t
*ip
, hammer2_chain_t
*chain
,
1552 hammer2_tid_t mtid
, int flags
);
1553 int hammer2_chain_resize(hammer2_chain_t
*chain
,
1554 hammer2_tid_t mtid
, hammer2_off_t dedup_off
,
1555 int nradix
, int flags
);
1556 void hammer2_chain_unlock(hammer2_chain_t
*chain
);
1557 //void hammer2_chain_unlock_hold(hammer2_chain_t *chain);
1558 hammer2_chain_t
*hammer2_chain_get(hammer2_chain_t
*parent
, int generation
,
1559 hammer2_blockref_t
*bref
, int how
);
1560 hammer2_chain_t
*hammer2_chain_lookup_init(hammer2_chain_t
*parent
, int flags
);
1561 void hammer2_chain_lookup_done(hammer2_chain_t
*parent
);
1562 hammer2_chain_t
*hammer2_chain_getparent(hammer2_chain_t
*chain
, int flags
);
1563 hammer2_chain_t
*hammer2_chain_repparent(hammer2_chain_t
**chainp
, int flags
);
1564 hammer2_chain_t
*hammer2_chain_lookup(hammer2_chain_t
**parentp
,
1565 hammer2_key_t
*key_nextp
,
1566 hammer2_key_t key_beg
, hammer2_key_t key_end
,
1567 int *errorp
, int flags
);
1568 hammer2_chain_t
*hammer2_chain_next(hammer2_chain_t
**parentp
,
1569 hammer2_chain_t
*chain
,
1570 hammer2_key_t
*key_nextp
,
1571 hammer2_key_t key_beg
, hammer2_key_t key_end
,
1572 int *errorp
, int flags
);
1573 int hammer2_chain_scan(hammer2_chain_t
*parent
,
1574 hammer2_chain_t
**chainp
,
1575 hammer2_blockref_t
*bref
,
1576 int *firstp
, int flags
);
1578 int hammer2_chain_create(hammer2_chain_t
**parentp
, hammer2_chain_t
**chainp
,
1579 hammer2_dev_t
*hmp
, hammer2_pfs_t
*pmp
,
1580 int methods
, hammer2_key_t key
, int keybits
,
1581 int type
, size_t bytes
, hammer2_tid_t mtid
,
1582 hammer2_off_t dedup_off
, int flags
);
1583 void hammer2_chain_rename(hammer2_chain_t
**parentp
,
1584 hammer2_chain_t
*chain
,
1585 hammer2_tid_t mtid
, int flags
);
1586 int hammer2_chain_delete(hammer2_chain_t
*parent
, hammer2_chain_t
*chain
,
1587 hammer2_tid_t mtid
, int flags
);
1588 int hammer2_chain_indirect_maintenance(hammer2_chain_t
*parent
,
1589 hammer2_chain_t
*chain
);
1590 void hammer2_chain_setflush(hammer2_chain_t
*chain
);
1591 void hammer2_chain_countbrefs(hammer2_chain_t
*chain
,
1592 hammer2_blockref_t
*base
, int count
);
1593 hammer2_chain_t
*hammer2_chain_bulksnap(hammer2_dev_t
*hmp
);
1594 void hammer2_chain_bulkdrop(hammer2_chain_t
*copy
);
1596 void hammer2_chain_setcheck(hammer2_chain_t
*chain
, void *bdata
);
1597 int hammer2_chain_testcheck(hammer2_chain_t
*chain
, void *bdata
);
1598 int hammer2_chain_dirent_test(hammer2_chain_t
*chain
, const char *name
,
1601 void hammer2_base_delete(hammer2_chain_t
*parent
,
1602 hammer2_blockref_t
*base
, int count
,
1603 hammer2_chain_t
*chain
,
1604 hammer2_blockref_t
*obref
);
1605 void hammer2_base_insert(hammer2_chain_t
*parent
,
1606 hammer2_blockref_t
*base
, int count
,
1607 hammer2_chain_t
*chain
,
1608 hammer2_blockref_t
*elm
);
1609 void hammer2_dump_chain(hammer2_chain_t
*chain
, int tab
, int bi
, int *countp
,
1610 char pfx
, u_int flags
);
1615 void hammer2_trans_manage_init(hammer2_pfs_t
*pmp
);
1616 int hammer2_flush(hammer2_chain_t
*chain
, int istop
);
1617 void hammer2_trans_init(hammer2_pfs_t
*pmp
, uint32_t flags
);
1618 void hammer2_trans_setflags(hammer2_pfs_t
*pmp
, uint32_t flags
);
1619 void hammer2_trans_clearflags(hammer2_pfs_t
*pmp
, uint32_t flags
);
1620 hammer2_tid_t
hammer2_trans_sub(hammer2_pfs_t
*pmp
);
1621 void hammer2_trans_done(hammer2_pfs_t
*pmp
, uint32_t flags
);
1622 hammer2_tid_t
hammer2_trans_newinum(hammer2_pfs_t
*pmp
);
1623 void hammer2_trans_assert_strategy(hammer2_pfs_t
*pmp
);
1628 int hammer2_ioctl(hammer2_inode_t
*ip
, u_long com
, void *data
,
1629 int fflag
, struct ucred
*cred
);
1634 void hammer2_io_hash_init(hammer2_dev_t
*hmp
);
1635 void hammer2_inum_hash_init(hammer2_pfs_t
*pmp
);
1636 void hammer2_io_inval(hammer2_io_t
*dio
, hammer2_off_t data_off
, u_int bytes
);
1637 void hammer2_io_hash_cleanup_all(hammer2_dev_t
*hmp
);
1638 char *hammer2_io_data(hammer2_io_t
*dio
, off_t lbase
);
1639 void hammer2_io_bkvasync(hammer2_io_t
*dio
);
1640 void hammer2_io_dedup_set(hammer2_dev_t
*hmp
, hammer2_blockref_t
*bref
);
1641 void hammer2_io_dedup_delete(hammer2_dev_t
*hmp
, uint8_t btype
,
1642 hammer2_off_t data_off
, u_int bytes
);
1643 void hammer2_io_dedup_assert(hammer2_dev_t
*hmp
, hammer2_off_t data_off
,
1645 int hammer2_io_new(hammer2_dev_t
*hmp
, int btype
, off_t lbase
, int lsize
,
1646 hammer2_io_t
**diop
);
1647 int hammer2_io_newnz(hammer2_dev_t
*hmp
, int btype
, off_t lbase
, int lsize
,
1648 hammer2_io_t
**diop
);
1649 int _hammer2_io_bread(hammer2_dev_t
*hmp
, int btype
, off_t lbase
, int lsize
,
1650 hammer2_io_t
**diop HAMMER2_IO_DEBUG_ARGS
);
1651 void hammer2_io_setdirty(hammer2_io_t
*dio
);
1653 hammer2_io_t
*_hammer2_io_getblk(hammer2_dev_t
*hmp
, int btype
, off_t lbase
,
1654 int lsize
, int op HAMMER2_IO_DEBUG_ARGS
);
1655 hammer2_io_t
*_hammer2_io_getquick(hammer2_dev_t
*hmp
, off_t lbase
,
1656 int lsize HAMMER2_IO_DEBUG_ARGS
);
1657 void _hammer2_io_putblk(hammer2_io_t
**diop HAMMER2_IO_DEBUG_ARGS
);
1658 int _hammer2_io_bwrite(hammer2_io_t
**diop HAMMER2_IO_DEBUG_ARGS
);
1659 void _hammer2_io_bawrite(hammer2_io_t
**diop HAMMER2_IO_DEBUG_ARGS
);
1660 void _hammer2_io_bdwrite(hammer2_io_t
**diop HAMMER2_IO_DEBUG_ARGS
);
1661 void _hammer2_io_brelse(hammer2_io_t
**diop HAMMER2_IO_DEBUG_ARGS
);
1662 void _hammer2_io_bqrelse(hammer2_io_t
**diop HAMMER2_IO_DEBUG_ARGS
);
1663 void _hammer2_io_ref(hammer2_io_t
*dio HAMMER2_IO_DEBUG_ARGS
);
1665 #ifndef HAMMER2_IO_DEBUG
1667 #define hammer2_io_getblk(hmp, btype, lbase, lsize, op) \
1668 _hammer2_io_getblk((hmp), (btype), (lbase), (lsize), (op))
1669 #define hammer2_io_getquick(hmp, lbase, lsize) \
1670 _hammer2_io_getquick((hmp), (lbase), (lsize))
1671 #define hammer2_io_putblk(diop) \
1672 _hammer2_io_putblk(diop)
1673 #define hammer2_io_bwrite(diop) \
1674 _hammer2_io_bwrite((diop))
1675 #define hammer2_io_bawrite(diop) \
1676 _hammer2_io_bawrite((diop))
1677 #define hammer2_io_bdwrite(diop) \
1678 _hammer2_io_bdwrite((diop))
1679 #define hammer2_io_brelse(diop) \
1680 _hammer2_io_brelse((diop))
1681 #define hammer2_io_bqrelse(diop) \
1682 _hammer2_io_bqrelse((diop))
1683 #define hammer2_io_ref(dio) \
1684 _hammer2_io_ref((dio))
1686 #define hammer2_io_bread(hmp, btype, lbase, lsize, diop) \
1687 _hammer2_io_bread((hmp), (btype), (lbase), (lsize), (diop))
1691 #define hammer2_io_getblk(hmp, btype, lbase, lsize, op) \
1692 _hammer2_io_getblk((hmp), (btype), (lbase), (lsize), (op), \
1695 #define hammer2_io_getquick(hmp, lbase, lsize) \
1696 _hammer2_io_getquick((hmp), (lbase), (lsize), __FILE__, __LINE__)
1698 #define hammer2_io_putblk(diop) \
1699 _hammer2_io_putblk(diop, __FILE__, __LINE__)
1701 #define hammer2_io_bwrite(diop) \
1702 _hammer2_io_bwrite((diop), __FILE__, __LINE__)
1703 #define hammer2_io_bawrite(diop) \
1704 _hammer2_io_bawrite((diop), __FILE__, __LINE__)
1705 #define hammer2_io_bdwrite(diop) \
1706 _hammer2_io_bdwrite((diop), __FILE__, __LINE__)
1707 #define hammer2_io_brelse(diop) \
1708 _hammer2_io_brelse((diop), __FILE__, __LINE__)
1709 #define hammer2_io_bqrelse(diop) \
1710 _hammer2_io_bqrelse((diop), __FILE__, __LINE__)
1711 #define hammer2_io_ref(dio) \
1712 _hammer2_io_ref((dio), __FILE__, __LINE__)
1714 #define hammer2_io_bread(hmp, btype, lbase, lsize, diop) \
1715 _hammer2_io_bread((hmp), (btype), (lbase), (lsize), (diop), \
1723 void hammer2_thr_signal(hammer2_thread_t
*thr
, uint32_t flags
);
1724 void hammer2_thr_signal2(hammer2_thread_t
*thr
,
1725 uint32_t pflags
, uint32_t nflags
);
1726 void hammer2_thr_wait(hammer2_thread_t
*thr
, uint32_t flags
);
1727 void hammer2_thr_wait_neg(hammer2_thread_t
*thr
, uint32_t flags
);
1728 int hammer2_thr_wait_any(hammer2_thread_t
*thr
, uint32_t flags
, int timo
);
1729 void hammer2_thr_create(hammer2_thread_t
*thr
,
1730 hammer2_pfs_t
*pmp
, hammer2_dev_t
*hmp
,
1731 const char *id
, int clindex
, int repidx
,
1732 void (*func
)(void *arg
));
1733 void hammer2_thr_delete(hammer2_thread_t
*thr
);
1734 void hammer2_thr_remaster(hammer2_thread_t
*thr
);
1735 void hammer2_thr_freeze_async(hammer2_thread_t
*thr
);
1736 void hammer2_thr_freeze(hammer2_thread_t
*thr
);
1737 void hammer2_thr_unfreeze(hammer2_thread_t
*thr
);
1738 int hammer2_thr_break(hammer2_thread_t
*thr
);
1739 void hammer2_primary_xops_thread(void *arg
);
1742 * hammer2_thread.c (XOP API)
1744 void *hammer2_xop_alloc(hammer2_inode_t
*ip
, int flags
);
1745 void hammer2_xop_setname(hammer2_xop_head_t
*xop
,
1746 const char *name
, size_t name_len
);
1747 void hammer2_xop_setname2(hammer2_xop_head_t
*xop
,
1748 const char *name
, size_t name_len
);
1749 size_t hammer2_xop_setname_inum(hammer2_xop_head_t
*xop
, hammer2_key_t inum
);
1750 void hammer2_xop_setip2(hammer2_xop_head_t
*xop
, hammer2_inode_t
*ip2
);
1751 void hammer2_xop_setip3(hammer2_xop_head_t
*xop
, hammer2_inode_t
*ip3
);
1752 void hammer2_xop_setip4(hammer2_xop_head_t
*xop
, hammer2_inode_t
*ip4
);
1753 void hammer2_xop_reinit(hammer2_xop_head_t
*xop
);
1754 void hammer2_xop_helper_create(hammer2_pfs_t
*pmp
);
1755 void hammer2_xop_helper_cleanup(hammer2_pfs_t
*pmp
);
1756 void hammer2_xop_start(hammer2_xop_head_t
*xop
, hammer2_xop_desc_t
*desc
);
1757 void hammer2_xop_start_except(hammer2_xop_head_t
*xop
, hammer2_xop_desc_t
*desc
,
1759 int hammer2_xop_collect(hammer2_xop_head_t
*xop
, int flags
);
1760 void hammer2_xop_retire(hammer2_xop_head_t
*xop
, uint64_t mask
);
1761 int hammer2_xop_active(hammer2_xop_head_t
*xop
);
1762 int hammer2_xop_feed(hammer2_xop_head_t
*xop
, hammer2_chain_t
*chain
,
1763 int clindex
, int error
);
1768 void hammer2_primary_sync_thread(void *arg
);
1771 * XOP backends in hammer2_xops.c, primarily for VNOPS. Other XOP backends
1772 * may be integrated into other source files.
1774 void hammer2_xop_ipcluster(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1775 void hammer2_xop_readdir(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1776 void hammer2_xop_nresolve(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1777 void hammer2_xop_unlink(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1778 void hammer2_xop_nrename(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1779 void hammer2_xop_scanlhc(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1780 void hammer2_xop_scanall(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1781 void hammer2_xop_lookup(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1782 void hammer2_xop_delete(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1783 void hammer2_xop_inode_mkdirent(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1784 void hammer2_xop_inode_create(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1785 void hammer2_xop_inode_create_det(hammer2_xop_t
*xop
,
1786 void *scratch
, int clindex
);
1787 void hammer2_xop_inode_create_ins(hammer2_xop_t
*xop
,
1788 void *scratch
, int clindex
);
1789 void hammer2_xop_inode_destroy(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1790 void hammer2_xop_inode_chain_sync(hammer2_xop_t
*xop
, void *scratch
,
1792 void hammer2_xop_inode_unlinkall(hammer2_xop_t
*xop
, void *scratch
,
1794 void hammer2_xop_inode_connect(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1795 void hammer2_xop_inode_flush(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1796 void hammer2_xop_strategy_read(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1797 void hammer2_xop_strategy_write(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1799 void hammer2_dmsg_ipcluster(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1800 void hammer2_dmsg_readdir(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1801 void hammer2_dmsg_nresolve(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1802 void hammer2_dmsg_unlink(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1803 void hammer2_dmsg_nrename(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1804 void hammer2_dmsg_scanlhc(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1805 void hammer2_dmsg_scanall(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1806 void hammer2_dmsg_lookup(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1807 void hammer2_dmsg_inode_mkdirent(hammer2_xop_t
*xop
, void *scratch
,
1809 void hammer2_dmsg_inode_create(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1810 void hammer2_dmsg_inode_destroy(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1811 void hammer2_dmsg_inode_chain_sync(hammer2_xop_t
*xop
, void *scratch
,
1813 void hammer2_dmsg_inode_unlinkall(hammer2_xop_t
*xop
, void *scratch
,
1815 void hammer2_dmsg_inode_connect(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1816 void hammer2_dmsg_inode_flush(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1817 void hammer2_dmsg_strategy_read(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1818 void hammer2_dmsg_strategy_write(hammer2_xop_t
*xop
, void *scratch
,
1821 void hammer2_rmsg_ipcluster(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1822 void hammer2_rmsg_readdir(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1823 void hammer2_rmsg_nresolve(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1824 void hammer2_rmsg_unlink(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1825 void hammer2_rmsg_nrename(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1826 void hammer2_rmsg_scanlhc(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1827 void hammer2_rmsg_scanall(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1828 void hammer2_rmsg_lookup(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1829 void hammer2_rmsg_inode_mkdirent(hammer2_xop_t
*xop
, void *scratch
,
1831 void hammer2_rmsg_inode_create(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1832 void hammer2_rmsg_inode_destroy(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1833 void hammer2_rmsg_inode_chain_sync(hammer2_xop_t
*xop
, void *scratch
,
1835 void hammer2_rmsg_inode_unlinkall(hammer2_xop_t
*xop
, void *scratch
,
1837 void hammer2_rmsg_inode_connect(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1838 void hammer2_rmsg_inode_flush(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1839 void hammer2_rmsg_strategy_read(hammer2_xop_t
*xop
, void *scratch
, int clindex
);
1840 void hammer2_rmsg_strategy_write(hammer2_xop_t
*xop
, void *scratch
,
1843 extern hammer2_xop_desc_t hammer2_ipcluster_desc
;
1844 extern hammer2_xop_desc_t hammer2_readdir_desc
;
1845 extern hammer2_xop_desc_t hammer2_nresolve_desc
;
1846 extern hammer2_xop_desc_t hammer2_unlink_desc
;
1847 extern hammer2_xop_desc_t hammer2_nrename_desc
;
1848 extern hammer2_xop_desc_t hammer2_scanlhc_desc
;
1849 extern hammer2_xop_desc_t hammer2_scanall_desc
;
1850 extern hammer2_xop_desc_t hammer2_lookup_desc
;
1851 extern hammer2_xop_desc_t hammer2_delete_desc
;
1852 extern hammer2_xop_desc_t hammer2_inode_mkdirent_desc
;
1853 extern hammer2_xop_desc_t hammer2_inode_create_desc
;
1854 extern hammer2_xop_desc_t hammer2_inode_create_det_desc
;
1855 extern hammer2_xop_desc_t hammer2_inode_create_ins_desc
;
1856 extern hammer2_xop_desc_t hammer2_inode_destroy_desc
;
1857 extern hammer2_xop_desc_t hammer2_inode_chain_sync_desc
;
1858 extern hammer2_xop_desc_t hammer2_inode_unlinkall_desc
;
1859 extern hammer2_xop_desc_t hammer2_inode_connect_desc
;
1860 extern hammer2_xop_desc_t hammer2_inode_flush_desc
;
1861 extern hammer2_xop_desc_t hammer2_strategy_read_desc
;
1862 extern hammer2_xop_desc_t hammer2_strategy_write_desc
;
1867 int hammer2_msg_dbg_rcvmsg(kdmsg_msg_t
*msg
);
1868 int hammer2_msg_adhoc_input(kdmsg_msg_t
*msg
);
1873 int hammer2_vfs_sync(struct mount
*mp
, int waitflags
);
1874 int hammer2_vfs_sync_pmp(hammer2_pfs_t
*pmp
, int waitfor
);
1875 int hammer2_vfs_enospace(hammer2_inode_t
*ip
, off_t bytes
, struct ucred
*cred
);
1877 hammer2_pfs_t
*hammer2_pfsalloc(hammer2_chain_t
*chain
,
1878 const hammer2_inode_data_t
*ripdata
,
1879 hammer2_dev_t
*force_local
);
1880 void hammer2_pfsdealloc(hammer2_pfs_t
*pmp
, int clindex
, int destroying
);
1881 int hammer2_vfs_vget(struct mount
*mp
, struct vnode
*dvp
,
1882 ino_t ino
, struct vnode
**vpp
);
1884 void hammer2_lwinprog_ref(hammer2_pfs_t
*pmp
);
1885 void hammer2_lwinprog_drop(hammer2_pfs_t
*pmp
);
1886 void hammer2_lwinprog_wait(hammer2_pfs_t
*pmp
, int pipe
);
1888 void hammer2_pfs_memory_wait(hammer2_pfs_t
*pmp
);
1889 void hammer2_pfs_memory_inc(hammer2_pfs_t
*pmp
);
1890 void hammer2_pfs_memory_wakeup(hammer2_pfs_t
*pmp
, int count
);
1892 void hammer2_voldata_lock(hammer2_dev_t
*hmp
);
1893 void hammer2_voldata_unlock(hammer2_dev_t
*hmp
);
1894 void hammer2_voldata_modify(hammer2_dev_t
*hmp
);
1899 int hammer2_freemap_alloc(hammer2_chain_t
*chain
, size_t bytes
);
1900 void hammer2_freemap_adjust(hammer2_dev_t
*hmp
,
1901 hammer2_blockref_t
*bref
, int how
);
1906 uint8_t hammer2_cluster_type(hammer2_cluster_t
*cluster
);
1907 void hammer2_cluster_bref(hammer2_cluster_t
*cluster
, hammer2_blockref_t
*bref
);
1908 void hammer2_cluster_ref(hammer2_cluster_t
*cluster
);
1909 void hammer2_cluster_drop(hammer2_cluster_t
*cluster
);
1910 void hammer2_cluster_unhold(hammer2_cluster_t
*cluster
);
1911 void hammer2_cluster_rehold(hammer2_cluster_t
*cluster
);
1912 void hammer2_cluster_lock(hammer2_cluster_t
*cluster
, int how
);
1913 int hammer2_cluster_check(hammer2_cluster_t
*cluster
, hammer2_key_t lokey
,
1915 void hammer2_cluster_unlock(hammer2_cluster_t
*cluster
);
1917 void hammer2_bulkfree_init(hammer2_dev_t
*hmp
);
1918 void hammer2_bulkfree_uninit(hammer2_dev_t
*hmp
);
1919 int hammer2_bulkfree_pass(hammer2_dev_t
*hmp
, hammer2_chain_t
*vchain
,
1920 struct hammer2_ioc_bulkfree
*bfi
);
1921 void hammer2_dummy_xop_from_chain(hammer2_xop_head_t
*xop
,
1922 hammer2_chain_t
*chain
);
1927 void hammer2_iocom_init(hammer2_dev_t
*hmp
);
1928 void hammer2_iocom_uninit(hammer2_dev_t
*hmp
);
1929 void hammer2_cluster_reconnect(hammer2_dev_t
*hmp
, struct file
*fp
);
1930 void hammer2_volconf_update(hammer2_dev_t
*hmp
, int index
);
1933 * hammer2_strategy.c
1935 int hammer2_vop_strategy(struct vop_strategy_args
*ap
);
1936 int hammer2_vop_bmap(struct vop_bmap_args
*ap
);
1937 void hammer2_bioq_sync(hammer2_pfs_t
*pmp
);
1938 void hammer2_dedup_record(hammer2_chain_t
*chain
, hammer2_io_t
*dio
,
1940 void hammer2_dedup_clear(hammer2_dev_t
*hmp
);
1945 int hammer2_open_devvp(const hammer2_devvp_list_t
*devvpl
, int ronly
);
1946 int hammer2_close_devvp(const hammer2_devvp_list_t
*devvpl
, int ronly
);
1947 int hammer2_init_devvp(const char *blkdevs
, int rootmount
,
1948 hammer2_devvp_list_t
*devvpl
);
1949 void hammer2_cleanup_devvp(hammer2_devvp_list_t
*devvpl
);
1950 int hammer2_init_volumes(struct mount
*mp
, const hammer2_devvp_list_t
*devvpl
,
1951 hammer2_volume_t
*volumes
,
1952 hammer2_volume_data_t
*rootvoldata
,
1954 struct vnode
**rootvoldevvp
);
1955 hammer2_volume_t
*hammer2_get_volume(hammer2_dev_t
*hmp
, hammer2_off_t offset
);
1958 * More complex inlines
1961 #define hammer2_xop_gdata(xop) _hammer2_xop_gdata((xop), __FILE__, __LINE__)
1964 const hammer2_media_data_t
*
1965 _hammer2_xop_gdata(hammer2_xop_head_t
*xop
, const char *file
, int line
)
1967 hammer2_chain_t
*focus
;
1970 focus
= xop
->cluster
.focus
;
1972 lockmgr(&focus
->diolk
, LK_SHARED
);
1973 if ((xop
->focus_dio
= focus
->dio
) != NULL
) {
1974 _hammer2_io_ref(xop
->focus_dio HAMMER2_IO_DEBUG_CALL
);
1975 hammer2_io_bkvasync(xop
->focus_dio
);
1978 lockmgr(&focus
->diolk
, LK_RELEASE
);
1986 #define hammer2_xop_pdata(xop) _hammer2_xop_pdata((xop), __FILE__, __LINE__)
1990 _hammer2_xop_pdata(hammer2_xop_head_t
*xop
, const char *file
, int line
)
1993 _hammer2_io_putblk(&xop
->focus_dio HAMMER2_IO_DEBUG_CALL
);
1998 hammer2_knote(struct vnode
*vp
, int flags
)
2001 KNOTE(&vp
->v_pollinfo
.vpi_kqinfo
.ki_note
, flags
);
2004 #endif /* !_KERNEL */
2005 #endif /* !_VFS_HAMMER2_HAMMER2_H_ */