2 * Copyright (c) 2011-2015 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_
65 #include <sys/param.h>
66 #include <sys/types.h>
67 #include <sys/kernel.h>
69 #include <sys/systm.h>
71 #include <sys/malloc.h>
72 #include <sys/mount.h>
73 #include <sys/vnode.h>
75 #include <sys/mountctl.h>
78 #include <sys/thread.h>
79 #include <sys/globaldata.h>
80 #include <sys/lockf.h>
82 #include <sys/queue.h>
83 #include <sys/limits.h>
85 #include <sys/mutex.h>
86 #include <sys/kern_syscall.h>
88 #include <sys/signal2.h>
90 #include <sys/mutex2.h>
91 #include <sys/thread2.h>
93 #include "hammer2_disk.h"
94 #include "hammer2_mount.h"
95 #include "hammer2_ioctl.h"
100 struct hammer2_cluster;
101 struct hammer2_inode;
105 struct hammer2_state;
109 * Mutex and lock shims. Hammer2 requires support for asynchronous and
110 * abortable locks, and both exclusive and shared spinlocks. Normal
111 * synchronous non-abortable locks can be substituted for spinlocks.
113 typedef mtx_t hammer2_mtx_t;
114 typedef mtx_link_t hammer2_mtx_link_t;
115 typedef mtx_state_t hammer2_mtx_state_t;
117 typedef struct spinlock hammer2_spin_t;
119 #define hammer2_mtx_ex mtx_lock_ex_quick
120 #define hammer2_mtx_sh mtx_lock_sh_quick
121 #define hammer2_mtx_unlock mtx_unlock
122 #define hammer2_mtx_owned mtx_owned
123 #define hammer2_mtx_init mtx_init
124 #define hammer2_mtx_temp_release mtx_lock_temp_release
125 #define hammer2_mtx_temp_restore mtx_lock_temp_restore
126 #define hammer2_mtx_refs mtx_lockrefs
128 #define hammer2_spin_init spin_init
129 #define hammer2_spin_sh spin_lock_shared
130 #define hammer2_spin_ex spin_lock
131 #define hammer2_spin_unsh spin_unlock_shared
132 #define hammer2_spin_unex spin_unlock
135 * General lock support
139 hammer2_mtx_upgrade(hammer2_mtx_t *mtx)
143 if (mtx_islocked_ex(mtx)) {
147 mtx_lock_ex_quick(mtx);
154 * Downgrade an inode lock from exclusive to shared only if the inode
155 * lock was previously shared. If the inode lock was previously exclusive,
160 hammer2_mtx_downgrade(hammer2_mtx_t *mtx, int wasexclusive)
162 if (wasexclusive == 0)
167 * The xid tracks internal transactional updates.
169 * XXX fix-me, really needs to be 64-bits
171 typedef uint32_t hammer2_xid_t;
173 #define HAMMER2_XID_MIN 0x00000000U
174 #define HAMMER2_XID_MAX 0x7FFFFFFFU
177 * The chain structure tracks a portion of the media topology from the
178 * root (volume) down. Chains represent volumes, inodes, indirect blocks,
179 * data blocks, and freemap nodes and leafs.
181 * The chain structure utilizes a simple singly-homed topology and the
182 * chain's in-memory topology will move around as the chains do, due mainly
183 * to renames and indirect block creation.
185 * Block Table Updates
187 * Block table updates for insertions and updates are delayed until the
188 * flush. This allows us to avoid having to modify the parent chain
189 * all the way to the root.
191 * Block table deletions are performed immediately (modifying the parent
192 * in the process) because the flush code uses the chain structure to
193 * track delayed updates and the chain will be (likely) gone or moved to
194 * another location in the topology after a deletion.
196 * A prior iteration of the code tried to keep the relationship intact
197 * on deletes by doing a delete-duplicate operation on the chain, but
198 * it added way too much complexity to the codebase.
200 * Flush Synchronization
202 * The flush code must flush modified chains bottom-up. Because chain
203 * structures can shift around and are NOT topologically stable,
204 * modified chains are independently indexed for the flush. As the flush
205 * runs it modifies (or further modifies) and updates the parents,
206 * propagating the flush all the way to the volume root.
208 * Modifying front-end operations can occur during a flush but will block
209 * in two cases: (1) when the front-end tries to operate on the inode
210 * currently in the midst of being flushed and (2) if the front-end
211 * crosses an inode currently being flushed (such as during a rename).
212 * So, for example, if you rename directory "x" to "a/b/c/d/e/f/g/x" and
213 * the flusher is currently working on "a/b/c", the rename will block
214 * temporarily in order to ensure that "x" exists in one place or the
217 * Meta-data statistics are updated by the flusher. The front-end will
218 * make estimates but meta-data must be fully synchronized only during a
219 * flush in order to ensure that it remains correct across a crash.
221 * Multiple flush synchronizations can theoretically be in-flight at the
222 * same time but the implementation is not coded to handle the case and
223 * currently serializes them.
227 * Snapshots currently require the subdirectory tree being snapshotted
228 * to be flushed. The snapshot then creates a new super-root inode which
229 * copies the flushed blockdata of the directory or file that was
234 * - Note that the radix tree runs in powers of 2 only so sub-trees
235 * cannot straddle edges.
237 RB_HEAD(hammer2_chain_tree, hammer2_chain);
238 TAILQ_HEAD(h2_flush_list, hammer2_chain);
239 TAILQ_HEAD(h2_core_list, hammer2_chain);
240 TAILQ_HEAD(h2_iocb_list, hammer2_iocb);
242 #define CHAIN_CORE_DELETE_BMAP_ENTRIES \
243 (HAMMER2_PBUFSIZE / sizeof(hammer2_blockref_t) / sizeof(uint32_t))
245 struct hammer2_chain_core {
248 struct hammer2_chain_tree rbtree; /* sub-chains */
249 int live_zero; /* blockref array opt */
251 u_int live_count; /* live (not deleted) chains in tree */
252 u_int chain_count; /* live + deleted chains under core */
253 int generation; /* generation number (inserts only) */
256 typedef struct hammer2_chain_core hammer2_chain_core_t;
258 #define HAMMER2_CORE_UNUSED0001 0x0001
259 #define HAMMER2_CORE_COUNTEDBREFS 0x0002
261 RB_HEAD(hammer2_io_tree, hammer2_io);
264 * IOCB - IO callback (into chain, cluster, or manual request)
266 struct hammer2_iocb {
267 TAILQ_ENTRY(hammer2_iocb) entry;
268 void (*callback)(struct hammer2_iocb *iocb);
269 struct hammer2_io *dio;
270 struct hammer2_cluster *cluster;
271 struct hammer2_chain *chain;
279 typedef struct hammer2_iocb hammer2_iocb_t;
281 #define HAMMER2_IOCB_INTERLOCK 0x00000001
282 #define HAMMER2_IOCB_ONQ 0x00000002
283 #define HAMMER2_IOCB_DONE 0x00000004
284 #define HAMMER2_IOCB_INPROG 0x00000008
285 #define HAMMER2_IOCB_UNUSED10 0x00000010
286 #define HAMMER2_IOCB_QUICK 0x00010000
287 #define HAMMER2_IOCB_ZERO 0x00020000
288 #define HAMMER2_IOCB_READ 0x00040000
289 #define HAMMER2_IOCB_WAKEUP 0x00080000
292 * DIO - Management structure wrapping system buffer cache.
294 * Used for multiple purposes including concurrent management
295 * if small requests by chains into larger DIOs.
298 RB_ENTRY(hammer2_io) rbnode; /* indexed by device offset */
299 struct h2_iocb_list iocbq;
300 struct spinlock spin;
301 struct hammer2_dev *hmp;
306 int act; /* activity */
309 typedef struct hammer2_io hammer2_io_t;
311 #define HAMMER2_DIO_INPROG 0x80000000 /* bio in progress */
312 #define HAMMER2_DIO_GOOD 0x40000000 /* dio->bp is stable */
313 #define HAMMER2_DIO_WAITING 0x20000000 /* (old) */
314 #define HAMMER2_DIO_DIRTY 0x10000000 /* flush on last drop */
316 #define HAMMER2_DIO_MASK 0x0FFFFFFF
319 * Primary chain structure keeps track of the topology in-memory.
321 struct hammer2_chain {
322 hammer2_chain_core_t core;
323 RB_ENTRY(hammer2_chain) rbnode; /* live chain(s) */
324 hammer2_blockref_t bref;
325 struct hammer2_chain *parent;
326 struct hammer2_state *state; /* if active cache msg */
327 struct hammer2_dev *hmp;
328 struct hammer2_pfs *pmp; /* A PFS or super-root (spmp) */
330 hammer2_xid_t flush_xid; /* flush sequencing */
331 hammer2_key_t data_count; /* delta's to apply */
332 hammer2_key_t inode_count; /* delta's to apply */
333 hammer2_key_t data_count_up; /* delta's to apply */
334 hammer2_key_t inode_count_up; /* delta's to apply */
335 hammer2_io_t *dio; /* physical data buffer */
336 u_int bytes; /* physical data size */
340 int error; /* on-lock data error state */
342 hammer2_media_data_t *data; /* data pointer shortcut */
343 TAILQ_ENTRY(hammer2_chain) flush_node; /* flush list */
346 typedef struct hammer2_chain hammer2_chain_t;
348 int hammer2_chain_cmp(hammer2_chain_t *chain1, hammer2_chain_t *chain2);
349 RB_PROTOTYPE(hammer2_chain_tree, hammer2_chain, rbnode, hammer2_chain_cmp);
352 * Special notes on flags:
354 * INITIAL - This flag allows a chain to be created and for storage to
355 * be allocated without having to immediately instantiate the
356 * related buffer. The data is assumed to be all-zeros. It
357 * is primarily used for indirect blocks.
359 * MODIFIED- The chain's media data has been modified.
360 * UPDATE - Chain might not be modified but parent blocktable needs update
362 * BMAPPED - Indicates that the chain is present in the parent blockmap.
363 * BMAPUPD - Indicates that the chain is present but needs to be updated
364 * in the parent blockmap.
366 #define HAMMER2_CHAIN_MODIFIED 0x00000001 /* dirty chain data */
367 #define HAMMER2_CHAIN_ALLOCATED 0x00000002 /* kmalloc'd chain */
368 #define HAMMER2_CHAIN_DESTROY 0x00000004
369 #define HAMMER2_CHAIN_UNLINKED 0x00000008 /* unlinked file */
370 #define HAMMER2_CHAIN_DELETED 0x00000010 /* deleted chain */
371 #define HAMMER2_CHAIN_INITIAL 0x00000020 /* initial create */
372 #define HAMMER2_CHAIN_UPDATE 0x00000040 /* need parent update */
373 #define HAMMER2_CHAIN_DEFERRED 0x00000080 /* flush depth defer */
374 #define HAMMER2_CHAIN_IOFLUSH 0x00000100 /* bawrite on put */
375 #define HAMMER2_CHAIN_ONFLUSH 0x00000200 /* on a flush list */
376 #define HAMMER2_CHAIN_UNUSED00000400 0x00000400
377 #define HAMMER2_CHAIN_VOLUMESYNC 0x00000800 /* needs volume sync */
378 #define HAMMER2_CHAIN_UNUSED00001000 0x00001000
379 #define HAMMER2_CHAIN_UNUSED00002000 0x00002000
380 #define HAMMER2_CHAIN_ONRBTREE 0x00004000 /* on parent RB tree */
381 #define HAMMER2_CHAIN_UNUSED00008000 0x00008000
382 #define HAMMER2_CHAIN_EMBEDDED 0x00010000 /* embedded data */
383 #define HAMMER2_CHAIN_RELEASE 0x00020000 /* don't keep around */
384 #define HAMMER2_CHAIN_BMAPPED 0x00040000 /* present in blkmap */
385 #define HAMMER2_CHAIN_BMAPUPD 0x00080000 /* +needs updating */
386 #define HAMMER2_CHAIN_UNUSED00100000 0x00100000
387 #define HAMMER2_CHAIN_UNUSED00200000 0x00200000
388 #define HAMMER2_CHAIN_PFSBOUNDARY 0x00400000 /* super->pfs inode */
390 #define HAMMER2_CHAIN_FLUSH_MASK (HAMMER2_CHAIN_MODIFIED | \
391 HAMMER2_CHAIN_UPDATE | \
392 HAMMER2_CHAIN_ONFLUSH)
395 * Hammer2 error codes, used by chain->error and cluster->error. The error
396 * code is typically set on-lock unless no I/O was requested, and set on
397 * I/O otherwise. If set for a cluster it generally means that the cluster
398 * code could not find a valid copy to present.
400 * NOTE: API allows callers to check zero/non-zero to determine if an error
403 * NOTE: Chain's data field is usually NULL on an IO error but not necessarily
404 * NULL on other errors. Check chain->error, not chain->data.
406 #define HAMMER2_ERROR_NONE 0
407 #define HAMMER2_ERROR_IO 1 /* device I/O error */
408 #define HAMMER2_ERROR_CHECK 2 /* check code mismatch */
409 #define HAMMER2_ERROR_INCOMPLETE 3 /* incomplete cluster */
412 * Flags passed to hammer2_chain_lookup() and hammer2_chain_next()
414 * NOTE: MATCHIND allows an indirect block / freemap node to be returned
415 * when the passed key range matches the radix. Remember that key_end
416 * is inclusive (e.g. {0x000,0xFFF}, not {0x000,0x1000}).
418 #define HAMMER2_LOOKUP_NOLOCK 0x00000001 /* ref only */
419 #define HAMMER2_LOOKUP_NODATA 0x00000002 /* data left NULL */
420 #define HAMMER2_LOOKUP_SHARED 0x00000100
421 #define HAMMER2_LOOKUP_MATCHIND 0x00000200 /* return all chains */
422 #define HAMMER2_LOOKUP_UNUSED0400 0x00000400
423 #define HAMMER2_LOOKUP_ALWAYS 0x00000800 /* resolve data */
426 * Flags passed to hammer2_chain_modify() and hammer2_chain_resize()
428 * NOTE: OPTDATA allows us to avoid instantiating buffers for INDIRECT
429 * blocks in the INITIAL-create state.
431 #define HAMMER2_MODIFY_OPTDATA 0x00000002 /* data can be NULL */
432 #define HAMMER2_MODIFY_NO_MODIFY_TID 0x00000004
433 #define HAMMER2_MODIFY_UNUSED0008 0x00000008
434 #define HAMMER2_MODIFY_NOREALLOC 0x00000010
437 * Flags passed to hammer2_chain_lock()
439 * NOTE: RDONLY is set to optimize cluster operations when *no* modifications
440 * will be made to either the cluster being locked or any underlying
441 * cluster. It allows the cluster to lock and access data for a subset
442 * of available nodes instead of all available nodes.
444 #define HAMMER2_RESOLVE_NEVER 1
445 #define HAMMER2_RESOLVE_MAYBE 2
446 #define HAMMER2_RESOLVE_ALWAYS 3
447 #define HAMMER2_RESOLVE_MASK 0x0F
449 #define HAMMER2_RESOLVE_SHARED 0x10 /* request shared lock */
450 #define HAMMER2_RESOLVE_NOREF 0x20 /* already ref'd on lock */
451 #define HAMMER2_RESOLVE_RDONLY 0x40 /* higher level op flag */
454 * Flags passed to hammer2_chain_delete()
456 #define HAMMER2_DELETE_PERMANENT 0x0001
457 #define HAMMER2_DELETE_NOSTATS 0x0002
459 #define HAMMER2_INSERT_NOSTATS 0x0002
460 #define HAMMER2_INSERT_PFSROOT 0x0004
463 * Flags passed to hammer2_chain_delete_duplicate()
465 #define HAMMER2_DELDUP_RECORE 0x0001
468 * Cluster different types of storage together for allocations
470 #define HAMMER2_FREECACHE_INODE 0
471 #define HAMMER2_FREECACHE_INDIR 1
472 #define HAMMER2_FREECACHE_DATA 2
473 #define HAMMER2_FREECACHE_UNUSED3 3
474 #define HAMMER2_FREECACHE_TYPES 4
477 * hammer2_freemap_alloc() block preference
479 #define HAMMER2_OFF_NOPREF ((hammer2_off_t)-1)
482 * BMAP read-ahead maximum parameters
484 #define HAMMER2_BMAP_COUNT 16 /* max bmap read-ahead */
485 #define HAMMER2_BMAP_BYTES (HAMMER2_PBUFSIZE * HAMMER2_BMAP_COUNT)
488 * hammer2_freemap_adjust()
490 #define HAMMER2_FREEMAP_DORECOVER 1
491 #define HAMMER2_FREEMAP_DOMAYFREE 2
492 #define HAMMER2_FREEMAP_DOREALFREE 3
495 * HAMMER2 cluster - A set of chains representing the same entity.
497 * hammer2_cluster typically represents a temporary set of representitive
498 * chains. The one exception is that a hammer2_cluster is embedded in
499 * hammer2_inode. This embedded cluster is ONLY used to track the
500 * representitive chains and cannot be directly locked.
502 * A cluster is usually temporary (and thus per-thread) for locking purposes,
503 * allowing us to embed the asynchronous storage required for cluster
504 * operations in the cluster itself and adjust the state and status without
505 * having to worry too much about SMP issues.
507 * The exception is the cluster embedded in the hammer2_inode structure.
508 * This is used to cache the cluster state on an inode-by-inode basis.
509 * Individual hammer2_chain structures not incorporated into clusters might
510 * also stick around to cache miscellanious elements.
512 * Because the cluster is a 'working copy' and is usually subject to cluster
513 * quorum rules, it is quite possible for us to end up with an insufficient
514 * number of live chains to execute an operation. If an insufficient number
515 * of chains remain in a working copy, the operation may have to be
516 * downgraded, retried, stall until the requisit number of chains are
517 * available, or possibly even error out depending on the mount type.
519 #define HAMMER2_MAXCLUSTER 8
521 struct hammer2_cluster_item {
522 hammer2_mtx_link_t async_link;
523 hammer2_chain_t *chain;
524 struct hammer2_cluster *cluster; /* link back to cluster */
529 typedef struct hammer2_cluster_item hammer2_cluster_item_t;
531 struct hammer2_cluster {
532 int refs; /* track for deallocation */
534 struct hammer2_pfs *pmp;
537 int error; /* error code valid on lock */
539 hammer2_chain_t *focus; /* current focus (or mod) */
540 hammer2_cluster_item_t array[HAMMER2_MAXCLUSTER];
543 typedef struct hammer2_cluster hammer2_cluster_t;
546 * WRHARD - Hard mounts can write fully synchronized
547 * RDHARD - Hard mounts can read fully synchronized
548 * WRSOFT - Soft mounts can write to at least the SOFT_MASTER
549 * RDSOFT - Soft mounts can read from at least a SOFT_SLAVE
550 * RDSLAVE - slaves are accessible (possibly unsynchronized or remote).
551 * MSYNCED - All masters are fully synchronized
552 * SSYNCED - All known local slaves are fully synchronized to masters
554 * All available masters are always incorporated. All PFSs belonging to a
555 * cluster (master, slave, copy, whatever) always try to synchronize the
556 * total number of known masters in the PFSs root inode.
558 * A cluster might have access to many slaves, copies, or caches, but we
559 * have a limited number of cluster slots. Any such elements which are
560 * directly mounted from block device(s) will always be incorporated. Note
561 * that SSYNCED only applies to such elements which are directly mounted,
562 * not to any remote slaves, copies, or caches that could be available. These
563 * bits are used to monitor and drive our synchronization threads.
565 * When asking the question 'is any data accessible at all', then a simple
566 * test against (RDHARD|RDSOFT|RDSLAVE) gives you the answer. If any of
567 * these bits are set the object can be read with certain caveats:
568 * RDHARD - no caveats. RDSOFT - authoritative but might not be synchronized.
569 * and RDSLAVE - not authoritative, has some data but it could be old or
572 * When both soft and hard mounts are available, data will be read and written
573 * via the soft mount only. But all might be in the cluster because
574 * background synchronization threads still need to do their work.
576 #define HAMMER2_CLUSTER_INODE 0x00000001 /* embedded in inode */
577 #define HAMMER2_CLUSTER_NOSYNC 0x00000002 /* not in sync (cumulative) */
578 #define HAMMER2_CLUSTER_LOCKED 0x00000004 /* cluster lks not recursive */
579 #define HAMMER2_CLUSTER_WRHARD 0x00000100 /* hard-mount can write */
580 #define HAMMER2_CLUSTER_RDHARD 0x00000200 /* hard-mount can read */
581 #define HAMMER2_CLUSTER_WRSOFT 0x00000400 /* soft-mount can write */
582 #define HAMMER2_CLUSTER_RDSOFT 0x00000800 /* soft-mount can read */
583 #define HAMMER2_CLUSTER_MSYNCED 0x00001000 /* all masters synchronized */
584 #define HAMMER2_CLUSTER_SSYNCED 0x00002000 /* known slaves synchronized */
586 #define HAMMER2_CLUSTER_ANYDATA ( HAMMER2_CLUSTER_RDHARD | \
587 HAMMER2_CLUSTER_RDSOFT | \
588 HAMMER2_CLUSTER_RDSLAVE)
590 #define HAMMER2_CLUSTER_RDOK ( HAMMER2_CLUSTER_RDHARD | \
591 HAMMER2_CLUSTER_RDSOFT)
593 #define HAMMER2_CLUSTER_WROK ( HAMMER2_CLUSTER_WRHARD | \
594 HAMMER2_CLUSTER_WRSOFT)
596 #define HAMMER2_CLUSTER_ZFLAGS ( HAMMER2_CLUSTER_WRHARD | \
597 HAMMER2_CLUSTER_RDHARD | \
598 HAMMER2_CLUSTER_WRSOFT | \
599 HAMMER2_CLUSTER_RDSOFT | \
600 HAMMER2_CLUSTER_MSYNCED | \
601 HAMMER2_CLUSTER_SSYNCED)
604 * Helper functions (cluster must be locked for flags to be valid).
608 hammer2_cluster_rdok(hammer2_cluster_t *cluster)
610 return (cluster->flags & HAMMER2_CLUSTER_RDOK);
615 hammer2_cluster_wrok(hammer2_cluster_t *cluster)
617 return (cluster->flags & HAMMER2_CLUSTER_WROK);
620 RB_HEAD(hammer2_inode_tree, hammer2_inode);
625 * NOTE: The inode-embedded cluster is never used directly for I/O (since
626 * it may be shared). Instead it will be replicated-in and synchronized
627 * back out if changed.
629 struct hammer2_inode {
630 RB_ENTRY(hammer2_inode) rbnode; /* inumber lookup (HL) */
631 hammer2_mtx_t lock; /* inode lock */
632 struct hammer2_pfs *pmp; /* PFS mount */
633 struct hammer2_inode *pip; /* parent inode */
635 hammer2_cluster_t cluster;
636 struct lockf advlock;
639 u_int refs; /* +vpref, +flushref */
640 uint8_t comp_heuristic;
645 typedef struct hammer2_inode hammer2_inode_t;
647 #define HAMMER2_INODE_MODIFIED 0x0001
648 #define HAMMER2_INODE_SROOT 0x0002 /* kmalloc special case */
649 #define HAMMER2_INODE_RENAME_INPROG 0x0004
650 #define HAMMER2_INODE_ONRBTREE 0x0008
651 #define HAMMER2_INODE_RESIZED 0x0010
652 #define HAMMER2_INODE_MTIME 0x0020
654 int hammer2_inode_cmp(hammer2_inode_t *ip1, hammer2_inode_t *ip2);
655 RB_PROTOTYPE2(hammer2_inode_tree, hammer2_inode, rbnode, hammer2_inode_cmp,
659 * inode-unlink side-structure
661 struct hammer2_inode_unlink {
662 TAILQ_ENTRY(hammer2_inode_unlink) entry;
665 TAILQ_HEAD(h2_unlk_list, hammer2_inode_unlink);
667 typedef struct hammer2_inode_unlink hammer2_inode_unlink_t;
670 * Cluster node synchronization thread element.
672 * Multiple syncthr's can hang off of a hammer2_pfs structure, typically one
673 * for each block device that is part of the PFS. Synchronization threads
674 * for PFSs accessed over the network are handled by their respective hosts.
676 * Synchronization threads are responsible for keeping a local node
677 * synchronized to the greater cluster.
679 * A syncthr can also hang off each hammer2_dev's super-root PFS (spmp).
680 * This thread is responsible for automatic bulkfree and dedup scans.
682 struct hammer2_syncthr {
683 struct hammer2_pfs *pmp;
691 typedef struct hammer2_syncthr hammer2_syncthr_t;
693 #define HAMMER2_SYNCTHR_UNMOUNTING 0x0001 /* unmount request */
694 #define HAMMER2_SYNCTHR_DEV 0x0002 /* related to dev, not pfs */
695 #define HAMMER2_SYNCTHR_SPANNED 0x0004 /* LNK_SPAN active */
696 #define HAMMER2_SYNCTHR_REMASTER 0x0008 /* remaster request */
697 #define HAMMER2_SYNCTHR_STOP 0x0010 /* exit request */
698 #define HAMMER2_SYNCTHR_FREEZE 0x0020 /* force idle */
699 #define HAMMER2_SYNCTHR_FROZEN 0x0040 /* restart */
702 * A hammer2 transaction and flush sequencing structure.
704 * This global structure is tied into hammer2_dev and is used
705 * to sequence modifying operations and flushes.
707 * (a) Any modifying operations with sync_tid >= flush_tid will stall until
708 * all modifying operating with sync_tid < flush_tid complete.
710 * The flush related to flush_tid stalls until all modifying operations
711 * with sync_tid < flush_tid complete.
713 * (b) Once unstalled, modifying operations with sync_tid > flush_tid are
714 * allowed to run. All modifications cause modify/duplicate operations
715 * to occur on the related chains. Note that most INDIRECT blocks will
716 * be unaffected because the modifications just overload the RBTREE
717 * structurally instead of actually modifying the indirect blocks.
719 * (c) The actual flush unstalls and RUNS CONCURRENTLY with (b), but only
720 * utilizes the chain structures with sync_tid <= flush_tid. The
721 * flush will modify related indirect blocks and inodes in-place
722 * (rather than duplicate) since the adjustments are compatible with
723 * (b)'s RBTREE overloading
725 * SPECIAL NOTE: Inode modifications have to also propagate along any
726 * modify/duplicate chains. File writes detect the flush
727 * and force out the conflicting buffer cache buffer(s)
728 * before reusing them.
730 * (d) Snapshots can be made instantly but must be flushed and disconnected
731 * from their duplicative source before they can be mounted. This is
732 * because while H2's on-media structure supports forks, its in-memory
733 * structure only supports very simple forking for background flushing
736 * TODO: Flush merging. When fsync() is called on multiple discrete files
737 * concurrently there is no reason to stall the second fsync.
738 * The final flush that reaches to root can cover both fsync()s.
740 * The chains typically terminate as they fly onto the disk. The flush
741 * ultimately reaches the volume header.
743 struct hammer2_trans {
744 TAILQ_ENTRY(hammer2_trans) entry;
745 struct hammer2_pfs *pmp;
746 hammer2_xid_t sync_xid;
747 hammer2_tid_t inode_tid; /* inode number assignment */
748 thread_t td; /* pointer */
751 uint8_t inodes_created;
755 typedef struct hammer2_trans hammer2_trans_t;
757 #define HAMMER2_TRANS_ISFLUSH 0x0001 /* formal flush */
758 #define HAMMER2_TRANS_CONCURRENT 0x0002 /* concurrent w/flush */
759 #define HAMMER2_TRANS_BUFCACHE 0x0004 /* from bioq strategy write */
760 #define HAMMER2_TRANS_NEWINODE 0x0008 /* caller allocating inode */
761 #define HAMMER2_TRANS_UNUSED0010 0x0010
762 #define HAMMER2_TRANS_PREFLUSH 0x0020 /* preflush state */
764 #define HAMMER2_FREEMAP_HEUR_NRADIX 4 /* pwr 2 PBUFRADIX-MINIORADIX */
765 #define HAMMER2_FREEMAP_HEUR_TYPES 8
766 #define HAMMER2_FREEMAP_HEUR (HAMMER2_FREEMAP_HEUR_NRADIX * \
767 HAMMER2_FREEMAP_HEUR_TYPES)
770 * Transaction Rendezvous
772 TAILQ_HEAD(hammer2_trans_queue, hammer2_trans);
774 struct hammer2_trans_manage {
775 hammer2_xid_t flush_xid; /* last flush transaction */
776 hammer2_xid_t alloc_xid;
777 struct lock translk; /* lockmgr lock */
778 struct hammer2_trans_queue transq; /* modifying transactions */
779 int flushcnt; /* track flush trans */
782 typedef struct hammer2_trans_manage hammer2_trans_manage_t;
785 * Global (per partition) management structure, represents a hard block
786 * device. Typically referenced by hammer2_chain structures when applicable.
787 * Typically not used for network-managed elements.
789 * Note that a single hammer2_dev can be indirectly tied to multiple system
790 * mount points. There is no direct relationship. System mounts are
791 * per-cluster-id, not per-block-device, and a single hard mount might contain
792 * many PFSs and those PFSs might combine together in various ways to form
793 * the set of available clusters.
796 struct vnode *devvp; /* device vnode */
797 int ronly; /* read-only mount */
798 int pmp_count; /* number of actively mounted PFSs */
799 TAILQ_ENTRY(hammer2_dev) mntentry; /* hammer2_mntlist */
801 struct malloc_type *mchain;
804 kdmsg_iocom_t iocom; /* volume-level dmsg interface */
805 struct spinlock io_spin; /* iotree access */
806 struct hammer2_io_tree iotree;
808 hammer2_chain_t vchain; /* anchor chain (topology) */
809 hammer2_chain_t fchain; /* anchor chain (freemap) */
810 struct spinlock list_spin;
811 struct h2_flush_list flushq; /* flush seeds */
812 struct hammer2_pfs *spmp; /* super-root pmp for transactions */
813 struct lock vollk; /* lockmgr lock */
814 hammer2_off_t heur_freemap[HAMMER2_FREEMAP_HEUR];
815 int volhdrno; /* last volhdrno written */
816 hammer2_volume_data_t voldata;
817 hammer2_volume_data_t volsync; /* synchronized voldata */
820 typedef struct hammer2_dev hammer2_dev_t;
823 * Helper functions (cluster must be locked for flags to be valid).
827 hammer2_chain_rdok(hammer2_chain_t *chain)
829 return (chain->error == 0);
834 hammer2_chain_wrok(hammer2_chain_t *chain)
836 return (chain->error == 0 && chain->hmp->ronly == 0);
840 * Per-cluster management structure. This structure will be tied to a
841 * system mount point if the system is mounting the PFS, but is also used
842 * to manage clusters encountered during the super-root scan or received
843 * via LNK_SPANs that might not be mounted.
845 * This structure is also used to represent the super-root that hangs off
846 * of a hard mount point. The super-root is not really a cluster element.
847 * In this case the spmp_hmp field will be non-NULL. It's just easier to do
848 * this than to special case super-root manipulation in the hammer2_chain*
849 * code as being only hammer2_dev-related.
851 * pfs_mode and pfs_nmasters are rollup fields which critically describes
852 * how elements of the cluster act on the cluster. pfs_mode is only applicable
853 * when a PFS is mounted by the system. pfs_nmasters is our best guess as to
854 * how many masters have been configured for a cluster and is always
855 * applicable. pfs_types[] is an array with 1:1 correspondance to the
856 * iroot cluster and describes the PFS types of the nodes making up the
859 * WARNING! Portions of this structure have deferred initialization. In
860 * particular, if not mounted there will be no ihidden or wthread.
861 * umounted network PFSs will also be missing iroot and numerous
862 * other fields will not be initialized prior to mount.
864 * Synchronization threads are chain-specific and only applicable
865 * to local hard PFS entries. A hammer2_pfs structure may contain
866 * more than one when multiple hard PFSs are present on the local
867 * machine which require synchronization monitoring. Most PFSs
868 * (such as snapshots) are 1xMASTER PFSs which do not need a
869 * synchronization thread.
871 * WARNING! The chains making up pfs->iroot's cluster are accounted for in
872 * hammer2_dev->pmp_count when the pfs is associated with a mount
877 TAILQ_ENTRY(hammer2_pfs) mntentry; /* hammer2_pfslist */
879 hammer2_dev_t *spmp_hmp; /* only if super-root pmp */
880 hammer2_inode_t *iroot; /* PFS root inode */
881 hammer2_inode_t *ihidden; /* PFS hidden directory */
882 uint8_t pfs_types[HAMMER2_MAXCLUSTER];
883 struct lock lock; /* PFS lock for certain ops */
884 hammer2_off_t inode_count; /* copy of inode_count */
885 struct netexport export; /* nfs export */
886 int ronly; /* read-only mount */
887 struct malloc_type *minode;
888 struct malloc_type *mmsg;
889 struct spinlock inum_spin; /* inumber lookup */
890 struct hammer2_inode_tree inum_tree; /* (not applicable to spmp) */
891 hammer2_tid_t alloc_tid;
892 hammer2_tid_t flush_tid;
893 hammer2_tid_t inode_tid;
894 uint8_t pfs_nmasters; /* total masters */
895 uint8_t pfs_mode; /* operating mode PFSMODE */
900 uint32_t inmem_dirty_chains;
901 int count_lwinprog; /* logical write in prog */
902 struct spinlock list_spin;
903 struct h2_unlk_list unlinkq; /* last-close unlink */
904 hammer2_syncthr_t primary_thr;
905 thread_t wthread_td; /* write thread td */
906 struct bio_queue_head wthread_bioq; /* logical buffer bioq */
907 hammer2_mtx_t wthread_mtx; /* interlock */
908 int wthread_destroy;/* termination sequencing */
911 typedef struct hammer2_pfs hammer2_pfs_t;
913 #define HAMMER2_DIRTYCHAIN_WAITING 0x80000000
914 #define HAMMER2_DIRTYCHAIN_MASK 0x7FFFFFFF
916 #define HAMMER2_LWINPROG_WAITING 0x80000000
917 #define HAMMER2_LWINPROG_MASK 0x7FFFFFFF
922 #define HAMMER2_BULK_ABORT 0x00000001
929 MALLOC_DECLARE(M_HAMMER2);
931 #define VTOI(vp) ((hammer2_inode_t *)(vp)->v_data)
932 #define ITOV(ip) ((ip)->vp)
935 * Currently locked chains retain the locked buffer cache buffer for
936 * indirect blocks, and indirect blocks can be one of two sizes. The
937 * device buffer has to match the case to avoid deadlocking recursive
938 * chains that might otherwise try to access different offsets within
939 * the same device buffer.
943 hammer2_devblkradix(int radix)
946 if (radix <= HAMMER2_LBUFRADIX) {
947 return (HAMMER2_LBUFRADIX);
949 return (HAMMER2_PBUFRADIX);
952 return (HAMMER2_PBUFRADIX);
956 * XXX almost time to remove this. DIO uses PBUFSIZE exclusively now.
960 hammer2_devblksize(size_t bytes)
963 if (bytes <= HAMMER2_LBUFSIZE) {
964 return(HAMMER2_LBUFSIZE);
966 KKASSERT(bytes <= HAMMER2_PBUFSIZE &&
967 (bytes ^ (bytes - 1)) == ((bytes << 1) - 1));
968 return (HAMMER2_PBUFSIZE);
971 return (HAMMER2_PBUFSIZE);
977 MPTOPMP(struct mount *mp)
979 return ((hammer2_pfs_t *)mp->mnt_data);
982 #define LOCKSTART int __nlocks = curthread->td_locks
983 #define LOCKENTER (++curthread->td_locks)
984 #define LOCKEXIT (--curthread->td_locks)
985 #define LOCKSTOP KKASSERT(curthread->td_locks == __nlocks)
987 extern struct vop_ops hammer2_vnode_vops;
988 extern struct vop_ops hammer2_spec_vops;
989 extern struct vop_ops hammer2_fifo_vops;
991 extern int hammer2_debug;
992 extern int hammer2_cluster_enable;
993 extern int hammer2_hardlink_enable;
994 extern int hammer2_flush_pipe;
995 extern int hammer2_synchronous_flush;
996 extern int hammer2_dio_count;
997 extern long hammer2_limit_dirty_chains;
998 extern long hammer2_iod_file_read;
999 extern long hammer2_iod_meta_read;
1000 extern long hammer2_iod_indr_read;
1001 extern long hammer2_iod_fmap_read;
1002 extern long hammer2_iod_volu_read;
1003 extern long hammer2_iod_file_write;
1004 extern long hammer2_iod_meta_write;
1005 extern long hammer2_iod_indr_write;
1006 extern long hammer2_iod_fmap_write;
1007 extern long hammer2_iod_volu_write;
1008 extern long hammer2_ioa_file_read;
1009 extern long hammer2_ioa_meta_read;
1010 extern long hammer2_ioa_indr_read;
1011 extern long hammer2_ioa_fmap_read;
1012 extern long hammer2_ioa_volu_read;
1013 extern long hammer2_ioa_file_write;
1014 extern long hammer2_ioa_meta_write;
1015 extern long hammer2_ioa_indr_write;
1016 extern long hammer2_ioa_fmap_write;
1017 extern long hammer2_ioa_volu_write;
1019 extern struct objcache *cache_buffer_read;
1020 extern struct objcache *cache_buffer_write;
1023 extern int write_thread_wakeup;
1028 #define hammer2_icrc32(buf, size) iscsi_crc32((buf), (size))
1029 #define hammer2_icrc32c(buf, size, crc) iscsi_crc32_ext((buf), (size), (crc))
1031 int hammer2_signal_check(time_t *timep);
1032 hammer2_cluster_t *hammer2_inode_lock_ex(hammer2_inode_t *ip);
1033 hammer2_cluster_t *hammer2_inode_lock_nex(hammer2_inode_t *ip, int how);
1034 hammer2_cluster_t *hammer2_inode_lock_sh(hammer2_inode_t *ip);
1035 void hammer2_inode_unlock_ex(hammer2_inode_t *ip, hammer2_cluster_t *chain);
1036 void hammer2_inode_unlock_sh(hammer2_inode_t *ip, hammer2_cluster_t *chain);
1037 hammer2_mtx_state_t hammer2_inode_lock_temp_release(hammer2_inode_t *ip);
1038 void hammer2_inode_lock_temp_restore(hammer2_inode_t *ip,
1039 hammer2_mtx_state_t ostate);
1040 int hammer2_inode_lock_upgrade(hammer2_inode_t *ip);
1041 void hammer2_inode_lock_downgrade(hammer2_inode_t *ip, int);
1043 void hammer2_dev_exlock(hammer2_dev_t *hmp);
1044 void hammer2_dev_shlock(hammer2_dev_t *hmp);
1045 void hammer2_dev_unlock(hammer2_dev_t *hmp);
1047 int hammer2_get_dtype(const hammer2_inode_data_t *ipdata);
1048 int hammer2_get_vtype(const hammer2_inode_data_t *ipdata);
1049 u_int8_t hammer2_get_obj_type(enum vtype vtype);
1050 void hammer2_time_to_timespec(u_int64_t xtime, struct timespec *ts);
1051 u_int64_t hammer2_timespec_to_time(const struct timespec *ts);
1052 u_int32_t hammer2_to_unix_xid(const uuid_t *uuid);
1053 void hammer2_guid_to_uuid(uuid_t *uuid, u_int32_t guid);
1054 hammer2_xid_t hammer2_trans_newxid(hammer2_pfs_t *pmp);
1055 void hammer2_trans_manage_init(void);
1057 hammer2_key_t hammer2_dirhash(const unsigned char *name, size_t len);
1058 int hammer2_getradix(size_t bytes);
1060 int hammer2_calc_logical(hammer2_inode_t *ip, hammer2_off_t uoff,
1061 hammer2_key_t *lbasep, hammer2_key_t *leofp);
1062 int hammer2_calc_physical(hammer2_inode_t *ip,
1063 const hammer2_inode_data_t *ipdata,
1064 hammer2_key_t lbase);
1065 void hammer2_update_time(uint64_t *timep);
1066 void hammer2_adjreadcounter(hammer2_blockref_t *bref, size_t bytes);
1071 struct vnode *hammer2_igetv(hammer2_inode_t *ip, hammer2_cluster_t *cparent,
1073 void hammer2_inode_lock_nlinks(hammer2_inode_t *ip);
1074 void hammer2_inode_unlock_nlinks(hammer2_inode_t *ip);
1075 hammer2_inode_t *hammer2_inode_lookup(hammer2_pfs_t *pmp,
1076 hammer2_tid_t inum);
1077 hammer2_inode_t *hammer2_inode_get(hammer2_pfs_t *pmp,
1078 hammer2_inode_t *dip, hammer2_cluster_t *cluster);
1079 void hammer2_inode_free(hammer2_inode_t *ip);
1080 void hammer2_inode_ref(hammer2_inode_t *ip);
1081 void hammer2_inode_drop(hammer2_inode_t *ip);
1082 void hammer2_inode_repoint(hammer2_inode_t *ip, hammer2_inode_t *pip,
1083 hammer2_cluster_t *cluster);
1084 void hammer2_run_unlinkq(hammer2_trans_t *trans, hammer2_pfs_t *pmp);
1086 hammer2_inode_t *hammer2_inode_create(hammer2_trans_t *trans,
1087 hammer2_inode_t *dip,
1088 struct vattr *vap, struct ucred *cred,
1089 const uint8_t *name, size_t name_len,
1090 hammer2_cluster_t **clusterp,
1091 int flags, int *errorp);
1092 int hammer2_inode_connect(hammer2_trans_t *trans,
1093 hammer2_cluster_t **clusterp, int hlink,
1094 hammer2_inode_t *dip, hammer2_cluster_t *dcluster,
1095 const uint8_t *name, size_t name_len,
1097 hammer2_inode_t *hammer2_inode_common_parent(hammer2_inode_t *fdip,
1098 hammer2_inode_t *tdip);
1099 void hammer2_inode_fsync(hammer2_trans_t *trans, hammer2_inode_t *ip,
1100 hammer2_cluster_t *cparent);
1101 int hammer2_unlink_file(hammer2_trans_t *trans, hammer2_inode_t *dip,
1102 const uint8_t *name, size_t name_len, int isdir,
1103 int *hlinkp, struct nchandle *nch, int nlinks);
1104 int hammer2_hardlink_consolidate(hammer2_trans_t *trans,
1105 hammer2_inode_t *ip, hammer2_cluster_t **clusterp,
1106 hammer2_inode_t *cdip, hammer2_cluster_t *cdcluster,
1108 int hammer2_hardlink_deconsolidate(hammer2_trans_t *trans, hammer2_inode_t *dip,
1109 hammer2_chain_t **chainp, hammer2_chain_t **ochainp);
1110 int hammer2_hardlink_find(hammer2_inode_t *dip, hammer2_cluster_t **cparentp,
1111 hammer2_cluster_t **clusterp);
1112 int hammer2_parent_find(hammer2_cluster_t **cparentp,
1113 hammer2_cluster_t *cluster);
1114 void hammer2_inode_install_hidden(hammer2_pfs_t *pmp);
1119 void hammer2_voldata_lock(hammer2_dev_t *hmp);
1120 void hammer2_voldata_unlock(hammer2_dev_t *hmp);
1121 void hammer2_voldata_modify(hammer2_dev_t *hmp);
1122 hammer2_chain_t *hammer2_chain_alloc(hammer2_dev_t *hmp,
1124 hammer2_trans_t *trans,
1125 hammer2_blockref_t *bref);
1126 void hammer2_chain_core_init(hammer2_chain_t *chain);
1127 void hammer2_chain_ref(hammer2_chain_t *chain);
1128 void hammer2_chain_drop(hammer2_chain_t *chain);
1129 void hammer2_chain_lock(hammer2_chain_t *chain, int how);
1130 const hammer2_media_data_t *hammer2_chain_rdata(hammer2_chain_t *chain);
1131 hammer2_media_data_t *hammer2_chain_wdata(hammer2_chain_t *chain);
1136 int hammer2_cluster_isunlinked(hammer2_cluster_t *cluster);
1137 void hammer2_cluster_load_async(hammer2_cluster_t *cluster,
1138 void (*callback)(hammer2_iocb_t *iocb),
1140 void hammer2_chain_moved(hammer2_chain_t *chain);
1141 void hammer2_chain_modify(hammer2_trans_t *trans,
1142 hammer2_chain_t *chain, int flags);
1143 void hammer2_chain_resize(hammer2_trans_t *trans, hammer2_inode_t *ip,
1144 hammer2_chain_t *parent,
1145 hammer2_chain_t *chain,
1146 int nradix, int flags);
1147 void hammer2_chain_unlock(hammer2_chain_t *chain);
1148 void hammer2_chain_wait(hammer2_chain_t *chain);
1149 hammer2_chain_t *hammer2_chain_get(hammer2_chain_t *parent, int generation,
1150 hammer2_blockref_t *bref);
1151 hammer2_chain_t *hammer2_chain_lookup_init(hammer2_chain_t *parent, int flags);
1152 void hammer2_chain_lookup_done(hammer2_chain_t *parent);
1153 hammer2_chain_t *hammer2_chain_lookup(hammer2_chain_t **parentp,
1154 hammer2_key_t *key_nextp,
1155 hammer2_key_t key_beg, hammer2_key_t key_end,
1156 int *cache_indexp, int flags);
1157 hammer2_chain_t *hammer2_chain_next(hammer2_chain_t **parentp,
1158 hammer2_chain_t *chain,
1159 hammer2_key_t *key_nextp,
1160 hammer2_key_t key_beg, hammer2_key_t key_end,
1161 int *cache_indexp, int flags);
1162 hammer2_chain_t *hammer2_chain_scan(hammer2_chain_t *parent,
1163 hammer2_chain_t *chain,
1164 int *cache_indexp, int flags);
1166 int hammer2_chain_create(hammer2_trans_t *trans, hammer2_chain_t **parentp,
1167 hammer2_chain_t **chainp,
1169 hammer2_key_t key, int keybits,
1170 int type, size_t bytes, int flags);
1171 void hammer2_chain_rename(hammer2_trans_t *trans, hammer2_blockref_t *bref,
1172 hammer2_chain_t **parentp,
1173 hammer2_chain_t *chain, int flags);
1174 int hammer2_chain_snapshot(hammer2_trans_t *trans, hammer2_chain_t **chainp,
1175 hammer2_ioc_pfs_t *pfs);
1176 void hammer2_chain_delete(hammer2_trans_t *trans, hammer2_chain_t *parent,
1177 hammer2_chain_t *chain, int flags);
1178 void hammer2_chain_delete_duplicate(hammer2_trans_t *trans,
1179 hammer2_chain_t **chainp, int flags);
1180 void hammer2_flush(hammer2_trans_t *trans, hammer2_chain_t *chain);
1181 void hammer2_chain_commit(hammer2_trans_t *trans, hammer2_chain_t *chain);
1182 void hammer2_chain_setflush(hammer2_trans_t *trans, hammer2_chain_t *chain);
1183 void hammer2_chain_countbrefs(hammer2_chain_t *chain,
1184 hammer2_blockref_t *base, int count);
1186 void hammer2_chain_setcheck(hammer2_chain_t *chain, void *bdata);
1187 int hammer2_chain_testcheck(hammer2_chain_t *chain, void *bdata);
1190 void hammer2_pfs_memory_wait(hammer2_pfs_t *pmp);
1191 void hammer2_pfs_memory_inc(hammer2_pfs_t *pmp);
1192 void hammer2_pfs_memory_wakeup(hammer2_pfs_t *pmp);
1194 void hammer2_base_delete(hammer2_trans_t *trans, hammer2_chain_t *chain,
1195 hammer2_blockref_t *base, int count,
1196 int *cache_indexp, hammer2_chain_t *child);
1197 void hammer2_base_insert(hammer2_trans_t *trans, hammer2_chain_t *chain,
1198 hammer2_blockref_t *base, int count,
1199 int *cache_indexp, hammer2_chain_t *child);
1204 void hammer2_trans_init(hammer2_trans_t *trans, hammer2_pfs_t *pmp,
1206 void hammer2_trans_spmp(hammer2_trans_t *trans, hammer2_pfs_t *pmp);
1207 void hammer2_trans_done(hammer2_trans_t *trans);
1212 int hammer2_ioctl(hammer2_inode_t *ip, u_long com, void *data,
1213 int fflag, struct ucred *cred);
1218 void hammer2_io_putblk(hammer2_io_t **diop);
1219 void hammer2_io_cleanup(hammer2_dev_t *hmp, struct hammer2_io_tree *tree);
1220 char *hammer2_io_data(hammer2_io_t *dio, off_t lbase);
1221 void hammer2_io_getblk(hammer2_dev_t *hmp, off_t lbase, int lsize,
1222 hammer2_iocb_t *iocb);
1223 void hammer2_io_complete(hammer2_iocb_t *iocb);
1224 void hammer2_io_callback(struct bio *bio);
1225 void hammer2_iocb_wait(hammer2_iocb_t *iocb);
1226 int hammer2_io_new(hammer2_dev_t *hmp, off_t lbase, int lsize,
1227 hammer2_io_t **diop);
1228 int hammer2_io_newnz(hammer2_dev_t *hmp, off_t lbase, int lsize,
1229 hammer2_io_t **diop);
1230 int hammer2_io_newq(hammer2_dev_t *hmp, off_t lbase, int lsize,
1231 hammer2_io_t **diop);
1232 int hammer2_io_bread(hammer2_dev_t *hmp, off_t lbase, int lsize,
1233 hammer2_io_t **diop);
1234 void hammer2_io_bawrite(hammer2_io_t **diop);
1235 void hammer2_io_bdwrite(hammer2_io_t **diop);
1236 int hammer2_io_bwrite(hammer2_io_t **diop);
1237 int hammer2_io_isdirty(hammer2_io_t *dio);
1238 void hammer2_io_setdirty(hammer2_io_t *dio);
1239 void hammer2_io_setinval(hammer2_io_t *dio, u_int bytes);
1240 void hammer2_io_brelse(hammer2_io_t **diop);
1241 void hammer2_io_bqrelse(hammer2_io_t **diop);
1246 int hammer2_msg_dbg_rcvmsg(kdmsg_msg_t *msg);
1247 int hammer2_msg_adhoc_input(kdmsg_msg_t *msg);
1252 void hammer2_clusterctl_wakeup(kdmsg_iocom_t *iocom);
1253 void hammer2_volconf_update(hammer2_dev_t *hmp, int index);
1254 void hammer2_dump_chain(hammer2_chain_t *chain, int tab, int *countp, char pfx);
1255 void hammer2_bioq_sync(hammer2_pfs_t *pmp);
1256 int hammer2_vfs_sync(struct mount *mp, int waitflags);
1257 hammer2_pfs_t *hammer2_pfsalloc(hammer2_cluster_t *cluster,
1258 const hammer2_inode_data_t *ripdata,
1259 hammer2_tid_t alloc_tid);
1261 void hammer2_lwinprog_ref(hammer2_pfs_t *pmp);
1262 void hammer2_lwinprog_drop(hammer2_pfs_t *pmp);
1263 void hammer2_lwinprog_wait(hammer2_pfs_t *pmp);
1268 int hammer2_freemap_alloc(hammer2_trans_t *trans, hammer2_chain_t *chain,
1270 void hammer2_freemap_adjust(hammer2_trans_t *trans, hammer2_dev_t *hmp,
1271 hammer2_blockref_t *bref, int how);
1276 int hammer2_cluster_need_resize(hammer2_cluster_t *cluster, int bytes);
1277 uint8_t hammer2_cluster_type(hammer2_cluster_t *cluster);
1278 const hammer2_media_data_t *hammer2_cluster_rdata(hammer2_cluster_t *cluster);
1279 hammer2_media_data_t *hammer2_cluster_wdata(hammer2_cluster_t *cluster);
1280 hammer2_cluster_t *hammer2_cluster_from_chain(hammer2_chain_t *chain);
1281 int hammer2_cluster_modified(hammer2_cluster_t *cluster);
1282 int hammer2_cluster_duplicated(hammer2_cluster_t *cluster);
1283 void hammer2_cluster_set_chainflags(hammer2_cluster_t *cluster, uint32_t flags);
1284 void hammer2_cluster_clr_chainflags(hammer2_cluster_t *cluster, uint32_t flags);
1285 void hammer2_cluster_bref(hammer2_cluster_t *cluster, hammer2_blockref_t *bref);
1286 void hammer2_cluster_setflush(hammer2_trans_t *trans,
1287 hammer2_cluster_t *cluster);
1288 void hammer2_cluster_setmethod_check(hammer2_trans_t *trans,
1289 hammer2_cluster_t *cluster, int check_algo);
1290 hammer2_cluster_t *hammer2_cluster_alloc(hammer2_pfs_t *pmp,
1291 hammer2_trans_t *trans,
1292 hammer2_blockref_t *bref);
1293 void hammer2_cluster_ref(hammer2_cluster_t *cluster);
1294 void hammer2_cluster_drop(hammer2_cluster_t *cluster);
1295 void hammer2_cluster_wait(hammer2_cluster_t *cluster);
1296 void hammer2_cluster_lock(hammer2_cluster_t *cluster, int how);
1297 void hammer2_cluster_resolve(hammer2_cluster_t *cluster);
1298 hammer2_cluster_t *hammer2_cluster_copy(hammer2_cluster_t *ocluster);
1299 void hammer2_cluster_unlock(hammer2_cluster_t *cluster);
1300 void hammer2_cluster_resize(hammer2_trans_t *trans, hammer2_inode_t *ip,
1301 hammer2_cluster_t *cparent, hammer2_cluster_t *cluster,
1302 int nradix, int flags);
1303 hammer2_inode_data_t *hammer2_cluster_modify_ip(hammer2_trans_t *trans,
1304 hammer2_inode_t *ip, hammer2_cluster_t *cluster,
1306 void hammer2_cluster_modify(hammer2_trans_t *trans, hammer2_cluster_t *cluster,
1308 void hammer2_cluster_modsync(hammer2_cluster_t *cluster);
1309 hammer2_cluster_t *hammer2_cluster_lookup_init(hammer2_cluster_t *cparent,
1311 void hammer2_cluster_lookup_done(hammer2_cluster_t *cparent);
1312 hammer2_cluster_t *hammer2_cluster_lookup(hammer2_cluster_t *cparent,
1313 hammer2_key_t *key_nextp,
1314 hammer2_key_t key_beg, hammer2_key_t key_end,
1316 hammer2_cluster_t *hammer2_cluster_next(hammer2_cluster_t *cparent,
1317 hammer2_cluster_t *cluster,
1318 hammer2_key_t *key_nextp,
1319 hammer2_key_t key_beg, hammer2_key_t key_end,
1321 hammer2_cluster_t *hammer2_cluster_scan(hammer2_cluster_t *cparent,
1322 hammer2_cluster_t *cluster, int flags);
1323 int hammer2_cluster_create(hammer2_trans_t *trans, hammer2_cluster_t *cparent,
1324 hammer2_cluster_t **clusterp,
1325 hammer2_key_t key, int keybits,
1326 int type, size_t bytes, int flags);
1327 void hammer2_cluster_rename(hammer2_trans_t *trans, hammer2_blockref_t *bref,
1328 hammer2_cluster_t *cparent, hammer2_cluster_t *cluster,
1330 void hammer2_cluster_delete(hammer2_trans_t *trans, hammer2_cluster_t *pcluster,
1331 hammer2_cluster_t *cluster, int flags);
1332 int hammer2_cluster_snapshot(hammer2_trans_t *trans,
1333 hammer2_cluster_t *ocluster, hammer2_ioc_pfs_t *pfs);
1334 hammer2_cluster_t *hammer2_cluster_parent(hammer2_cluster_t *cluster);
1336 int hammer2_bulk_scan(hammer2_trans_t *trans, hammer2_chain_t *parent,
1337 int (*func)(hammer2_chain_t *chain, void *info),
1339 int hammer2_bulkfree_pass(hammer2_dev_t *hmp,
1340 struct hammer2_ioc_bulkfree *bfi);
1345 void hammer2_iocom_init(hammer2_dev_t *hmp);
1346 void hammer2_iocom_uninit(hammer2_dev_t *hmp);
1347 void hammer2_cluster_reconnect(hammer2_dev_t *hmp, struct file *fp);
1352 void hammer2_syncthr_create(hammer2_syncthr_t *thr, hammer2_pfs_t *pmp,
1353 void (*func)(void *arg));
1354 void hammer2_syncthr_delete(hammer2_syncthr_t *thr);
1355 void hammer2_syncthr_remaster(hammer2_syncthr_t *thr);
1356 void hammer2_syncthr_freeze(hammer2_syncthr_t *thr);
1357 void hammer2_syncthr_unfreeze(hammer2_syncthr_t *thr);
1358 void hammer2_syncthr_primary(void *arg);
1360 #endif /* !_KERNEL */
1361 #endif /* !_VFS_HAMMER2_HAMMER2_H_ */