dhcpcd: update README.DRAGONFLY
[dragonfly.git] / usr.sbin / makefs / hammer2 / hammer2.h
blob3d97335636ee301f61b395e2fd329bc047633691
1 /*
2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2022 Tomohiro Kusumi <tkusumi@netbsd.org>
5 * Copyright (c) 2011-2022 The DragonFly Project. All rights reserved.
7 * This code is derived from software contributed to The DragonFly Project
8 * by Matthew Dillon <dillon@dragonflybsd.org>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 * 3. Neither the name of The DragonFly Project nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific, prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
32 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
34 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
39 * HAMMER2 IN-MEMORY CACHE OF MEDIA STRUCTURES
41 * This header file contains structures used internally by the HAMMER2
42 * implementation. See hammer2_disk.h for on-disk structures.
44 * There is an in-memory representation of all on-media data structure.
45 * Almost everything is represented by a hammer2_chain structure in-memory.
46 * Other higher-level structures typically map to chains.
48 * A great deal of data is accessed simply via its buffer cache buffer,
49 * which is mapped for the duration of the chain's lock. Hammer2 must
50 * implement its own buffer cache layer on top of the system layer to
51 * allow for different threads to lock different sub-block-sized buffers.
53 * When modifications are made to a chain a new filesystem block must be
54 * allocated. Multiple modifications do not typically allocate new blocks
55 * until the current block has been flushed. Flushes do not block the
56 * front-end unless the front-end operation crosses the current inode being
57 * flushed.
59 * The in-memory representation may remain cached (for example in order to
60 * placemark clustering locks) even after the related data has been
61 * detached.
64 #ifndef _VFS_HAMMER2_HAMMER2_H_
65 #define _VFS_HAMMER2_HAMMER2_H_
67 #ifdef _KERNEL
68 #error "_KERNEL shouldn't be defined"
69 #endif
70 #ifdef _KERNEL_STRUCTURES
71 #error "_KERNEL_STRUCTURES shouldn't be defined"
72 #endif
74 #ifdef _KERNEL
75 #include <sys/param.h>
76 #endif
77 #include <sys/types.h>
78 #ifdef _KERNEL
79 #include <sys/kernel.h>
80 #endif
81 //#include <sys/conf.h>
82 #ifdef _KERNEL
83 #include <sys/systm.h>
84 #endif
85 //#include <sys/diskslice.h>
86 #include <sys/tree.h>
87 //#include <sys/malloc.h>
88 #include <sys/mount.h>
90 #include <sys/vnode.h>
91 #include <sys/proc.h>
92 #include <sys/caps.h>
93 #include <sys/stat.h>
94 #include <sys/thread.h>
95 #include <sys/lockf.h>
96 #include <sys/buf.h>
98 #include <sys/queue.h>
100 #include <sys/limits.h>
101 #include <sys/dmsg.h>
102 #include <sys/mutex.h>
103 #include <sys/lock.h>
104 #include <sys/file.h>
105 #include <sys/objcache.h>
108 #ifdef _KERNEL
109 #include <sys/signal2.h>
110 #include <sys/buf2.h>
111 #include <sys/mutex2.h>
112 #include <sys/spinlock2.h>
113 #endif
116 #include "hammer2_xxhash.h"
117 #include "hammer2_disk.h"
118 #include "hammer2_mount.h"
119 #include "hammer2_ioctl.h"
122 #include <sys/time.h>
123 #include <sys/vfscache.h>
124 #include <sys/errno.h>
126 #include <machine/atomic.h>
128 #include <unistd.h>
129 #include <stdio.h>
130 #include <stdlib.h>
131 #include <stdint.h>
132 #include <stdbool.h>
133 #include <string.h>
134 #include <uuid.h>
136 #include <vfs/hammer2/hammer2_disk.h>
137 #include <vfs/hammer2/hammer2_ioctl.h>
138 #include <vfs/hammer2/hammer2_mount.h>
139 #include <vfs/hammer2/hammer2_xxhash.h>
140 #include <mkfs_hammer2.h>
142 #include "hammer2_compat.h"
144 struct hammer2_io;
145 struct hammer2_chain;
146 struct hammer2_inode;
147 struct hammer2_depend;
148 struct hammer2_dev;
149 struct hammer2_pfs;
150 union hammer2_xop;
153 * Mutex and lock shims. Hammer2 requires support for asynchronous and
154 * abortable locks, and both exclusive and shared spinlocks. Normal
155 * synchronous non-abortable locks can be substituted for spinlocks.
158 typedef mtx_t hammer2_mtx_t;
159 typedef mtx_state_t hammer2_mtx_state_t;
161 typedef struct spinlock hammer2_spin_t;
163 #define hammer2_mtx_ex mtx_lock_ex_quick
164 #define hammer2_mtx_ex_try mtx_lock_ex_try
165 #define hammer2_mtx_sh mtx_lock_sh_quick
166 #define hammer2_mtx_sh_again mtx_lock_sh_again
167 #define hammer2_mtx_sh_try mtx_lock_sh_try
168 #define hammer2_mtx_unlock mtx_unlock
169 #define hammer2_mtx_upgrade_try mtx_upgrade_try
170 #define hammer2_mtx_downgrade mtx_downgrade
171 #define hammer2_mtx_owned mtx_owned
172 #define hammer2_mtx_init mtx_init
173 #define hammer2_mtx_temp_release mtx_lock_temp_release
174 #define hammer2_mtx_temp_restore mtx_lock_temp_restore
175 #define hammer2_mtx_refs mtx_lockrefs
177 #define hammer2_spin_init spin_init
178 #define hammer2_spin_sh spin_lock_shared
179 #define hammer2_spin_ex spin_lock
180 #define hammer2_spin_unsh spin_unlock_shared
181 #define hammer2_spin_unex spin_unlock
182 #define hammer2_spin_lock_update spin_lock_update
183 #define hammer2_spin_unlock_update spin_unlock_update
186 TAILQ_HEAD(hammer2_xop_list, hammer2_xop_head);
187 TAILQ_HEAD(hammer2_chain_list, hammer2_chain);
189 typedef struct hammer2_xop_list hammer2_xop_list_t;
192 * Cap the dynamic calculation for the maximum number of dirty
193 * chains and dirty inodes allowed.
195 #define HAMMER2_LIMIT_DIRTY_CHAINS (1024*1024)
196 #define HAMMER2_LIMIT_DIRTY_INODES (65536)
198 #define HAMMER2_IOHASH_SIZE 32768
199 #define HAMMER2_IOHASH_MASK (HAMMER2_IOHASH_SIZE - 1)
201 #define HAMMER2_INUMHASH_SIZE 32768
202 #define HAMMER2_INUMHASH_MASK (HAMMER2_IOHASH_SIZE - 1)
205 * The chain structure tracks a portion of the media topology from the
206 * root (volume) down. Chains represent volumes, inodes, indirect blocks,
207 * data blocks, and freemap nodes and leafs.
209 * The chain structure utilizes a simple singly-homed topology and the
210 * chain's in-memory topology will move around as the chains do, due mainly
211 * to renames and indirect block creation.
213 * Block Table Updates
215 * Block table updates for insertions and updates are delayed until the
216 * flush. This allows us to avoid having to modify the parent chain
217 * all the way to the root.
219 * Block table deletions are performed immediately (modifying the parent
220 * in the process) because the flush code uses the chain structure to
221 * track delayed updates and the chain will be (likely) gone or moved to
222 * another location in the topology after a deletion.
224 * A prior iteration of the code tried to keep the relationship intact
225 * on deletes by doing a delete-duplicate operation on the chain, but
226 * it added way too much complexity to the codebase.
228 * Flush Synchronization
230 * The flush code must flush modified chains bottom-up. Because chain
231 * structures can shift around and are NOT topologically stable,
232 * modified chains are independently indexed for the flush. As the flush
233 * runs it modifies (or further modifies) and updates the parents,
234 * propagating the flush all the way to the volume root.
236 * Modifying front-end operations can occur during a flush but will block
237 * in two cases: (1) when the front-end tries to operate on the inode
238 * currently in the midst of being flushed and (2) if the front-end
239 * crosses an inode currently being flushed (such as during a rename).
240 * So, for example, if you rename directory "x" to "a/b/c/d/e/f/g/x" and
241 * the flusher is currently working on "a/b/c", the rename will block
242 * temporarily in order to ensure that "x" exists in one place or the
243 * other.
245 * Meta-data statistics are updated by the flusher. The front-end will
246 * make estimates but meta-data must be fully synchronized only during a
247 * flush in order to ensure that it remains correct across a crash.
249 * Multiple flush synchronizations can theoretically be in-flight at the
250 * same time but the implementation is not coded to handle the case and
251 * currently serializes them.
253 * Snapshots:
255 * Snapshots currently require the subdirectory tree being snapshotted
256 * to be flushed. The snapshot then creates a new super-root inode which
257 * copies the flushed blockdata of the directory or file that was
258 * snapshotted.
260 * Radix tree NOTES:
262 * - Note that the radix tree runs in powers of 2 only so sub-trees
263 * cannot straddle edges.
265 RB_HEAD(hammer2_chain_tree, hammer2_chain);
267 struct hammer2_reptrack {
268 hammer2_spin_t spin;
269 struct hammer2_reptrack *next;
270 struct hammer2_chain *chain;
274 * Core topology for chain (embedded in chain). Protected by a spinlock.
276 struct hammer2_chain_core {
277 hammer2_spin_t spin;
278 struct hammer2_reptrack *reptrack;
279 struct hammer2_chain_tree rbtree; /* sub-chains */
280 int live_zero; /* blockref array opt */
281 u_int live_count; /* live (not deleted) chains in tree */
282 u_int chain_count; /* live + deleted chains under core */
283 int generation; /* generation number (inserts only) */
286 typedef struct hammer2_chain_core hammer2_chain_core_t;
289 * DIO - Management structure wrapping system buffer cache.
291 * HAMMER2 uses an I/O abstraction that allows it to cache and manipulate
292 * fixed-sized filesystem buffers frontend by variable-sized hammer2_chain
293 * structures.
295 /* #define HAMMER2_IO_DEBUG */
297 #ifdef HAMMER2_IO_DEBUG
298 #define HAMMER2_IO_DEBUG_ARGS , const char *file, int line
299 #define HAMMER2_IO_DEBUG_CALL , file, line
300 #define HAMMER2_IO_DEBUG_COUNT 2048
301 #define HAMMER2_IO_DEBUG_MASK (HAMMER2_IO_DEBUG_COUNT - 1)
302 #else
303 #define HAMMER2_IO_DEBUG_ARGS
304 #define HAMMER2_IO_DEBUG_CALL
305 #endif
307 struct hammer2_io {
308 struct hammer2_io *next;
309 struct hammer2_dev *hmp;
310 struct m_vnode *devvp;
311 struct m_buf *bp;
312 off_t dbase; /* offset of devvp within volumes */
313 off_t pbase;
314 uint64_t refs;
315 int psize;
316 int act; /* activity */
317 int btype; /* approximate BREF_TYPE_* */
318 int ticks;
319 int error;
320 #ifdef HAMMER2_IO_DEBUG
321 int debug_index;
322 #else
323 int unused01;
324 #endif
325 uint64_t dedup_valid; /* valid for dedup operation */
326 uint64_t dedup_alloc; /* allocated / de-dupable */
327 #ifdef HAMMER2_IO_DEBUG
328 const char *debug_file[HAMMER2_IO_DEBUG_COUNT];
329 void *debug_td[HAMMER2_IO_DEBUG_COUNT];
330 int debug_line[HAMMER2_IO_DEBUG_COUNT];
331 uint64_t debug_refs[HAMMER2_IO_DEBUG_COUNT];
332 #endif
335 typedef struct hammer2_io hammer2_io_t;
337 struct hammer2_io_hash {
338 hammer2_spin_t spin;
339 struct hammer2_io *base;
342 typedef struct hammer2_io_hash hammer2_io_hash_t;
344 #define HAMMER2_DIO_INPROG 0x8000000000000000LLU /* bio in progress */
345 #define HAMMER2_DIO_GOOD 0x4000000000000000LLU /* dio->bp is stable */
346 #define HAMMER2_DIO_WAITING 0x2000000000000000LLU /* wait on INPROG */
347 #define HAMMER2_DIO_DIRTY 0x1000000000000000LLU /* flush last drop */
348 #define HAMMER2_DIO_FLUSH 0x0800000000000000LLU /* immediate flush */
350 #define HAMMER2_DIO_MASK 0x00FFFFFFFFFFFFFFLLU
352 struct hammer2_inum_hash {
353 hammer2_spin_t spin;
354 struct hammer2_inode *base;
357 typedef struct hammer2_inum_hash hammer2_inum_hash_t;
360 * Primary chain structure keeps track of the topology in-memory.
362 struct hammer2_chain {
363 hammer2_mtx_t lock;
364 hammer2_chain_core_t core;
365 RB_ENTRY(hammer2_chain) rbnode; /* live chain(s) */
366 hammer2_blockref_t bref;
367 struct hammer2_chain *parent;
368 struct hammer2_dev *hmp;
369 struct hammer2_pfs *pmp; /* A PFS or super-root (spmp) */
371 struct lock diolk; /* xop focus interlock */
372 hammer2_io_t *dio; /* physical data buffer */
373 hammer2_media_data_t *data; /* data pointer shortcut */
374 u_int bytes; /* physical data size */
375 u_int flags;
376 u_int refs;
377 u_int lockcnt;
378 int error; /* on-lock data error state */
379 int cache_index; /* heur speeds up lookup */
382 typedef struct hammer2_chain hammer2_chain_t;
384 int hammer2_chain_cmp(hammer2_chain_t *chain1, hammer2_chain_t *chain2);
385 RB_PROTOTYPE(hammer2_chain_tree, hammer2_chain, rbnode, hammer2_chain_cmp);
388 * Passed to hammer2_chain_create(), causes methods to be inherited from
389 * parent.
391 #define HAMMER2_METH_DEFAULT -1
394 * Special notes on flags:
396 * INITIAL - This flag allows a chain to be created and for storage to
397 * be allocated without having to immediately instantiate the
398 * related buffer. The data is assumed to be all-zeros. It
399 * is primarily used for indirect blocks.
401 * MODIFIED - The chain's media data has been modified. Prevents chain
402 * free on lastdrop if still in the topology.
404 * UPDATE - Chain might not be modified but parent blocktable needs
405 * an update. Prevents chain free on lastdrop if still in
406 * the topology.
408 * BLKMAPPED - Indicates that the chain is present in the parent blockmap.
410 * BLKMAPUPD - Indicates that the chain is present but needs to be updated
411 * in the parent blockmap.
413 #define HAMMER2_CHAIN_MODIFIED 0x00000001 /* dirty chain data */
414 #define HAMMER2_CHAIN_ALLOCATED 0x00000002 /* kmalloc'd chain */
415 #define HAMMER2_CHAIN_DESTROY 0x00000004
416 #define HAMMER2_CHAIN_DEDUPABLE 0x00000008 /* registered w/dedup */
417 #define HAMMER2_CHAIN_DELETED 0x00000010 /* deleted chain */
418 #define HAMMER2_CHAIN_INITIAL 0x00000020 /* initial create */
419 #define HAMMER2_CHAIN_UPDATE 0x00000040 /* need parent update */
420 #define HAMMER2_CHAIN_NOTTESTED 0x00000080 /* crc not generated */
421 #define HAMMER2_CHAIN_TESTEDGOOD 0x00000100 /* crc tested good */
422 #define HAMMER2_CHAIN_ONFLUSH 0x00000200 /* on a flush list */
423 #define HAMMER2_CHAIN_UNUSED0400 0x00000400
424 #define HAMMER2_CHAIN_VOLUMESYNC 0x00000800 /* needs volume sync */
425 #define HAMMER2_CHAIN_UNUSED1000 0x00001000
426 #define HAMMER2_CHAIN_COUNTEDBREFS 0x00002000 /* block table stats */
427 #define HAMMER2_CHAIN_ONRBTREE 0x00004000 /* on parent RB tree */
428 #define HAMMER2_CHAIN_UNUSED8000 0x00008000
429 #define HAMMER2_CHAIN_UNUSED10000 0x00010000
430 #define HAMMER2_CHAIN_RELEASE 0x00020000 /* don't keep around */
431 #define HAMMER2_CHAIN_BLKMAPPED 0x00040000 /* present in blkmap */
432 #define HAMMER2_CHAIN_BLKMAPUPD 0x00080000 /* +needs updating */
433 #define HAMMER2_CHAIN_IOINPROG 0x00100000 /* I/O interlock */
434 #define HAMMER2_CHAIN_IOSIGNAL 0x00200000 /* I/O interlock */
435 #define HAMMER2_CHAIN_PFSBOUNDARY 0x00400000 /* super->pfs inode */
436 #define HAMMER2_CHAIN_HINT_LEAF_COUNT 0x00800000 /* redo leaf count */
437 #define HAMMER2_CHAIN_UNUSED1000000 0x01000000
439 #define HAMMER2_CHAIN_FLUSH_MASK (HAMMER2_CHAIN_MODIFIED | \
440 HAMMER2_CHAIN_UPDATE | \
441 HAMMER2_CHAIN_ONFLUSH | \
442 HAMMER2_CHAIN_DESTROY)
445 * Hammer2 error codes, used by chain->error and cluster->error. The error
446 * code is typically set on-lock unless no I/O was requested, and set on
447 * I/O otherwise. If set for a cluster it generally means that the cluster
448 * code could not find a valid copy to present.
450 * All H2 error codes are flags and can be accumulated by ORing them
451 * together.
453 * IO - An I/O error occurred
454 * CHECK - I/O succeeded but did not match the check code
455 * INCOMPLETE - A cluster is not complete enough to use, or
456 * a chain cannot be loaded because its parent has an error.
458 * NOTE: API allows callers to check zero/non-zero to determine if an error
459 * condition exists.
461 * NOTE: Chain's data field is usually NULL on an IO error but not necessarily
462 * NULL on other errors. Check chain->error, not chain->data.
464 #define HAMMER2_ERROR_NONE 0 /* no error (must be 0) */
465 #define HAMMER2_ERROR_EIO 0x00000001 /* device I/O error */
466 #define HAMMER2_ERROR_CHECK 0x00000002 /* check code error */
467 #define HAMMER2_ERROR_INCOMPLETE 0x00000004 /* incomplete cluster */
468 #define HAMMER2_ERROR_DEPTH 0x00000008 /* tmp depth limit */
469 #define HAMMER2_ERROR_BADBREF 0x00000010 /* illegal bref */
470 #define HAMMER2_ERROR_ENOSPC 0x00000020 /* allocation failure */
471 #define HAMMER2_ERROR_ENOENT 0x00000040 /* entry not found */
472 #define HAMMER2_ERROR_ENOTEMPTY 0x00000080 /* dir not empty */
473 #define HAMMER2_ERROR_EAGAIN 0x00000100 /* retry */
474 #define HAMMER2_ERROR_ENOTDIR 0x00000200 /* not directory */
475 #define HAMMER2_ERROR_EISDIR 0x00000400 /* is directory */
476 #define HAMMER2_ERROR_EINPROGRESS 0x00000800 /* already running */
477 #define HAMMER2_ERROR_ABORTED 0x00001000 /* aborted operation */
478 #define HAMMER2_ERROR_EOF 0x00002000 /* end of scan */
479 #define HAMMER2_ERROR_EINVAL 0x00004000 /* catch-all */
480 #define HAMMER2_ERROR_EEXIST 0x00008000 /* entry exists */
481 #define HAMMER2_ERROR_EDEADLK 0x00010000
482 #define HAMMER2_ERROR_ESRCH 0x00020000
483 #define HAMMER2_ERROR_ETIMEDOUT 0x00040000
486 * Flags passed to hammer2_chain_lookup() and hammer2_chain_next()
488 * NOTES:
489 * NODATA - Asks that the chain->data not be resolved in order
490 * to avoid I/O.
492 * NODIRECT - Prevents a lookup of offset 0 in an inode from returning
493 * the inode itself if the inode is in DIRECTDATA mode
494 * (i.e. file is <= 512 bytes). Used by the synchronization
495 * code to prevent confusion.
497 * SHARED - The input chain is expected to be locked shared,
498 * and the output chain is locked shared.
500 * MATCHIND - Allows an indirect block / freemap node to be returned
501 * when the passed key range matches the radix. Remember
502 * that key_end is inclusive (e.g. {0x000,0xFFF},
503 * not {0x000,0x1000}).
505 * (Cannot be used for remote or cluster ops).
507 * ALWAYS - Always resolve the data. If ALWAYS and NODATA are both
508 * missing, bulk file data is not resolved but inodes and
509 * other meta-data will.
511 #define HAMMER2_LOOKUP_UNUSED0001 0x00000001
512 #define HAMMER2_LOOKUP_NODATA 0x00000002 /* data left NULL */
513 #define HAMMER2_LOOKUP_NODIRECT 0x00000004 /* no offset=0 DD */
514 #define HAMMER2_LOOKUP_SHARED 0x00000100
515 #define HAMMER2_LOOKUP_MATCHIND 0x00000200 /* return all chains */
516 #define HAMMER2_LOOKUP_UNUSED0400 0x00000400
517 #define HAMMER2_LOOKUP_ALWAYS 0x00000800 /* resolve data */
518 #define HAMMER2_LOOKUP_UNUSED1000 0x00001000
521 * Flags passed to hammer2_chain_modify() and hammer2_chain_resize()
523 * NOTE: OPTDATA allows us to avoid instantiating buffers for INDIRECT
524 * blocks in the INITIAL-create state.
526 #define HAMMER2_MODIFY_OPTDATA 0x00000002 /* data can be NULL */
529 * Flags passed to hammer2_chain_lock()
531 * NOTE: NONBLOCK is only used for hammer2_chain_repparent() and getparent(),
532 * other functions (e.g. hammer2_chain_lookup(), etc) can't handle its
533 * operation.
535 #define HAMMER2_RESOLVE_NEVER 1
536 #define HAMMER2_RESOLVE_MAYBE 2
537 #define HAMMER2_RESOLVE_ALWAYS 3
538 #define HAMMER2_RESOLVE_MASK 0x0F
540 #define HAMMER2_RESOLVE_SHARED 0x10 /* request shared lock */
541 #define HAMMER2_RESOLVE_LOCKAGAIN 0x20 /* another shared lock */
542 #define HAMMER2_RESOLVE_UNUSED40 0x40
543 #define HAMMER2_RESOLVE_NONBLOCK 0x80 /* non-blocking */
546 * Flags passed to hammer2_chain_delete()
548 #define HAMMER2_DELETE_PERMANENT 0x0001
551 * Flags passed to hammer2_chain_insert() or hammer2_chain_rename()
552 * or hammer2_chain_create().
554 #define HAMMER2_INSERT_PFSROOT 0x0004
555 #define HAMMER2_INSERT_SAMEPARENT 0x0008
558 * hammer2_freemap_adjust()
560 #define HAMMER2_FREEMAP_DORECOVER 1
561 #if 0
562 #define HAMMER2_FREEMAP_DOMAYFREE 2
563 #define HAMMER2_FREEMAP_DOREALFREE 3
564 #endif
567 * HAMMER2 cluster - A set of chains representing the same entity.
569 * hammer2_cluster typically represents a temporary set of representitive
570 * chains. The one exception is that a hammer2_cluster is embedded in
571 * hammer2_inode. This embedded cluster is ONLY used to track the
572 * representitive chains and cannot be directly locked.
574 * A cluster is usually temporary (and thus per-thread) for locking purposes,
575 * allowing us to embed the asynchronous storage required for cluster
576 * operations in the cluster itself and adjust the state and status without
577 * having to worry too much about SMP issues.
579 * The exception is the cluster embedded in the hammer2_inode structure.
580 * This is used to cache the cluster state on an inode-by-inode basis.
581 * Individual hammer2_chain structures not incorporated into clusters might
582 * also stick around to cache miscellanious elements.
584 * Because the cluster is a 'working copy' and is usually subject to cluster
585 * quorum rules, it is quite possible for us to end up with an insufficient
586 * number of live chains to execute an operation. If an insufficient number
587 * of chains remain in a working copy, the operation may have to be
588 * downgraded, retried, stall until the requisit number of chains are
589 * available, or possibly even error out depending on the mount type.
591 * A cluster's focus is set when it is locked. The focus can only be set
592 * to a chain still part of the synchronized set.
594 #define HAMMER2_XOPFIFO 16
595 #define HAMMER2_XOPFIFO_MASK (HAMMER2_XOPFIFO - 1)
596 #define HAMMER2_XOPTHREADS_MIN 32
597 #define HAMMER2_XOPGROUPS_MIN 4
599 #define HAMMER2_MAXCLUSTER 8
600 #define HAMMER2_XOPMASK_CLUSTER ((uint64_t)((1LLU << HAMMER2_MAXCLUSTER) - 1))
601 #define HAMMER2_XOPMASK_VOP ((uint64_t)0x0000000080000000LLU)
602 #define HAMMER2_XOPMASK_FIFOW ((uint64_t)0x0000000040000000LLU)
603 #define HAMMER2_XOPMASK_WAIT ((uint64_t)0x0000000020000000LLU)
604 #define HAMMER2_XOPMASK_FEED ((uint64_t)0x0000000100000000LLU)
606 #define HAMMER2_XOPMASK_ALLDONE (HAMMER2_XOPMASK_VOP | HAMMER2_XOPMASK_CLUSTER)
608 struct hammer2_cluster_item {
609 hammer2_chain_t *chain;
610 int error;
611 uint32_t flags;
614 typedef struct hammer2_cluster_item hammer2_cluster_item_t;
617 * INVALID - Invalid for focus, i.e. not part of synchronized set.
618 * Once set, this bit is sticky across operations.
620 * FEMOD - Indicates that front-end modifying operations can
621 * mess with this entry and MODSYNC will copy also
622 * effect it.
624 #define HAMMER2_CITEM_INVALID 0x00000001
625 #define HAMMER2_CITEM_FEMOD 0x00000002
626 #define HAMMER2_CITEM_NULL 0x00000004
628 struct hammer2_cluster {
629 int refs; /* track for deallocation */
630 int ddflag;
631 struct hammer2_pfs *pmp;
632 uint32_t flags;
633 int nchains;
634 int error; /* error code valid on lock */
635 int focus_index;
636 hammer2_chain_t *focus; /* current focus (or mod) */
637 hammer2_cluster_item_t array[HAMMER2_MAXCLUSTER];
640 typedef struct hammer2_cluster hammer2_cluster_t;
643 * WRHARD - Hard mounts can write fully synchronized
644 * RDHARD - Hard mounts can read fully synchronized
645 * UNHARD - Unsynchronized masters present
646 * NOHARD - No masters visible
647 * WRSOFT - Soft mounts can write to at least the SOFT_MASTER
648 * RDSOFT - Soft mounts can read from at least a SOFT_SLAVE
649 * UNSOFT - Unsynchronized slaves present
650 * NOSOFT - No slaves visible
651 * RDSLAVE - slaves are accessible (possibly unsynchronized or remote).
652 * MSYNCED - All masters are fully synchronized
653 * SSYNCED - All known local slaves are fully synchronized to masters
655 * All available masters are always incorporated. All PFSs belonging to a
656 * cluster (master, slave, copy, whatever) always try to synchronize the
657 * total number of known masters in the PFSs root inode.
659 * A cluster might have access to many slaves, copies, or caches, but we
660 * have a limited number of cluster slots. Any such elements which are
661 * directly mounted from block device(s) will always be incorporated. Note
662 * that SSYNCED only applies to such elements which are directly mounted,
663 * not to any remote slaves, copies, or caches that could be available. These
664 * bits are used to monitor and drive our synchronization threads.
666 * When asking the question 'is any data accessible at all', then a simple
667 * test against (RDHARD|RDSOFT|RDSLAVE) gives you the answer. If any of
668 * these bits are set the object can be read with certain caveats:
669 * RDHARD - no caveats. RDSOFT - authoritative but might not be synchronized.
670 * and RDSLAVE - not authoritative, has some data but it could be old or
671 * incomplete.
673 * When both soft and hard mounts are available, data will be read and written
674 * via the soft mount only. But all might be in the cluster because
675 * background synchronization threads still need to do their work.
677 #define HAMMER2_CLUSTER_INODE 0x00000001 /* embedded in inode struct */
678 #define HAMMER2_CLUSTER_UNUSED2 0x00000002
679 #define HAMMER2_CLUSTER_LOCKED 0x00000004 /* cluster lks not recursive */
680 #define HAMMER2_CLUSTER_WRHARD 0x00000100 /* hard-mount can write */
681 #define HAMMER2_CLUSTER_RDHARD 0x00000200 /* hard-mount can read */
682 #define HAMMER2_CLUSTER_UNHARD 0x00000400 /* unsynchronized masters */
683 #define HAMMER2_CLUSTER_NOHARD 0x00000800 /* no masters visible */
684 #define HAMMER2_CLUSTER_WRSOFT 0x00001000 /* soft-mount can write */
685 #define HAMMER2_CLUSTER_RDSOFT 0x00002000 /* soft-mount can read */
686 #define HAMMER2_CLUSTER_UNSOFT 0x00004000 /* unsynchronized slaves */
687 #define HAMMER2_CLUSTER_NOSOFT 0x00008000 /* no slaves visible */
688 #define HAMMER2_CLUSTER_MSYNCED 0x00010000 /* all masters synchronized */
689 #define HAMMER2_CLUSTER_SSYNCED 0x00020000 /* known slaves synchronized */
691 #define HAMMER2_CLUSTER_ANYDATA ( HAMMER2_CLUSTER_RDHARD | \
692 HAMMER2_CLUSTER_RDSOFT | \
693 HAMMER2_CLUSTER_RDSLAVE)
694 #if 0
695 #define HAMMER2_CLUSTER_RDOK ( HAMMER2_CLUSTER_RDHARD | \
696 HAMMER2_CLUSTER_RDSOFT)
698 #define HAMMER2_CLUSTER_WROK ( HAMMER2_CLUSTER_WRHARD | \
699 HAMMER2_CLUSTER_WRSOFT)
700 #endif
701 #define HAMMER2_CLUSTER_ZFLAGS ( HAMMER2_CLUSTER_WRHARD | \
702 HAMMER2_CLUSTER_RDHARD | \
703 HAMMER2_CLUSTER_WRSOFT | \
704 HAMMER2_CLUSTER_RDSOFT | \
705 HAMMER2_CLUSTER_MSYNCED | \
706 HAMMER2_CLUSTER_SSYNCED)
708 TAILQ_HEAD(inoq_head, hammer2_inode); /* ip->entry */
709 TAILQ_HEAD(depq_head, hammer2_depend); /* depend->entry */
710 TAILQ_HEAD(recq_head, hammer2_inode); /* ip->recq_entry */
712 struct hammer2_depend {
713 TAILQ_ENTRY(hammer2_depend) entry;
714 struct inoq_head sideq;
715 long count;
716 int pass2;
717 int unused01;
720 typedef struct hammer2_depend hammer2_depend_t;
723 * A hammer2 inode.
725 * NOTE: The inode-embedded cluster is never used directly for I/O (since
726 * it may be shared). Instead it will be replicated-in and synchronized
727 * back out if changed.
729 struct hammer2_inode {
730 struct hammer2_inode *next; /* inode tree */
731 TAILQ_ENTRY(hammer2_inode) entry; /* SYNCQ/SIDEQ */
732 TAILQ_ENTRY(hammer2_inode) recq_entry; /* makefs */
733 hammer2_depend_t *depend; /* non-NULL if SIDEQ */
734 hammer2_depend_t depend_static; /* (in-place allocation) */
735 hammer2_mtx_t lock; /* inode lock */
736 hammer2_mtx_t truncate_lock; /* prevent truncates */
737 struct hammer2_pfs *pmp; /* PFS mount */
738 struct m_vnode *vp;
739 hammer2_spin_t cluster_spin; /* update cluster */
740 hammer2_cluster_t cluster;
741 hammer2_cluster_item_t ccache[HAMMER2_MAXCLUSTER];
742 int ccache_nchains;
743 //struct lockf advlock;
744 u_int flags;
745 u_int refs; /* +vpref, +flushref */
746 int ihash; /* xop worker distribution */
747 uint8_t comp_heuristic;
748 hammer2_inode_meta_t meta; /* copy of meta-data */
749 hammer2_off_t osize;
752 typedef struct hammer2_inode hammer2_inode_t;
755 * MODIFIED - Inode is in a modified state, ip->meta may have changes.
756 * RESIZED - Inode truncated (any) or inode extended beyond
757 * EMBEDDED_BYTES.
759 * SYNCQ - Inode is included in the current filesystem sync. The
760 * DELETING and CREATING flags will be acted upon.
762 * SIDEQ - Inode has likely been disconnected from the vnode topology
763 * and so is not visible to the vnode-based filesystem syncer
764 * code, but is dirty and must be included in the next
765 * filesystem sync. These inodes are moved to the SYNCQ at
766 * the time the sync occurs.
768 * Inodes are not placed on this queue simply because they have
769 * become dirty, if a vnode is attached.
771 * DELETING - Inode is flagged for deletion during the next filesystem
772 * sync. That is, the inode's chain is currently connected
773 * and must be deleting during the current or next fs sync.
775 * CREATING - Inode is flagged for creation during the next filesystem
776 * sync. That is, the inode's chain topology exists (so
777 * kernel buffer flushes can occur), but is currently
778 * disconnected and must be inserted during the current or
779 * next fs sync. If the DELETING flag is also set, the
780 * topology can be thrown away instead.
782 * If an inode that is already part of the current filesystem sync is
783 * modified by the frontend, including by buffer flushes, the inode lock
784 * code detects the SYNCQ flag and moves the inode to the head of the
785 * flush-in-progress, then blocks until the flush has gotten past it.
787 #define HAMMER2_INODE_MODIFIED 0x0001
788 #define HAMMER2_INODE_UNUSED0002 0x0002
789 #define HAMMER2_INODE_UNUSED0004 0x0004
790 #define HAMMER2_INODE_ONHASH 0x0008
791 #define HAMMER2_INODE_RESIZED 0x0010 /* requires inode_chain_sync */
792 #define HAMMER2_INODE_UNUSED0020 0x0020
793 #define HAMMER2_INODE_ISUNLINKED 0x0040
794 #define HAMMER2_INODE_UNUSED0080 0x0080
795 #define HAMMER2_INODE_SIDEQ 0x0100 /* on side processing queue */
796 #define HAMMER2_INODE_NOSIDEQ 0x0200 /* disable sideq operation */
797 #define HAMMER2_INODE_DIRTYDATA 0x0400 /* interlocks inode flush */
798 #define HAMMER2_INODE_SYNCQ 0x0800 /* sync interlock, sequenced */
799 #define HAMMER2_INODE_DELETING 0x1000 /* sync interlock, chain topo */
800 #define HAMMER2_INODE_CREATING 0x2000 /* sync interlock, chain topo */
801 #define HAMMER2_INODE_SYNCQ_WAKEUP 0x4000 /* sync interlock wakeup */
802 #define HAMMER2_INODE_SYNCQ_PASS2 0x8000 /* force retry delay */
804 #define HAMMER2_INODE_DIRTY (HAMMER2_INODE_MODIFIED | \
805 HAMMER2_INODE_DIRTYDATA | \
806 HAMMER2_INODE_DELETING | \
807 HAMMER2_INODE_CREATING)
810 * Transaction management sub-structure under hammer2_pfs
812 struct hammer2_trans {
813 uint32_t flags;
814 uint32_t sync_wait;
817 typedef struct hammer2_trans hammer2_trans_t;
819 #define HAMMER2_TRANS_ISFLUSH 0x80000000 /* flush code */
820 #define HAMMER2_TRANS_BUFCACHE 0x40000000 /* bio strategy */
821 #define HAMMER2_TRANS_SIDEQ 0x20000000 /* run sideq */
822 #define HAMMER2_TRANS_UNUSED10 0x10000000
823 #define HAMMER2_TRANS_WAITING 0x08000000 /* someone waiting */
824 #define HAMMER2_TRANS_RESCAN 0x04000000 /* rescan sideq */
825 #define HAMMER2_TRANS_MASK 0x00FFFFFF /* count mask */
827 #define HAMMER2_FREEMAP_HEUR_NRADIX 4 /* pwr 2 PBUFRADIX-LBUFRADIX */
828 #define HAMMER2_FREEMAP_HEUR_TYPES 8
829 #define HAMMER2_FREEMAP_HEUR_SIZE (HAMMER2_FREEMAP_HEUR_NRADIX * \
830 HAMMER2_FREEMAP_HEUR_TYPES)
832 #define HAMMER2_DEDUP_HEUR_SIZE (65536 * 4)
833 #define HAMMER2_DEDUP_HEUR_MASK (HAMMER2_DEDUP_HEUR_SIZE - 1)
835 #define HAMMER2_FLUSH_TOP 0x0001
836 #define HAMMER2_FLUSH_ALL 0x0002
837 #define HAMMER2_FLUSH_INODE_STOP 0x0004 /* stop at sub-inode */
838 #define HAMMER2_FLUSH_FSSYNC 0x0008 /* part of filesystem sync */
842 * Hammer2 support thread element.
844 * Potentially many support threads can hang off of hammer2, primarily
845 * off the hammer2_pfs structure. Typically:
847 * td x Nodes A synchronization thread for each node.
848 * td x Nodes x workers Worker threads for frontend operations.
849 * td x 1 Bioq thread for logical buffer writes.
851 * In addition, the synchronization thread(s) associated with the
852 * super-root PFS (spmp) for a node is responsible for automatic bulkfree
853 * and dedup scans.
855 struct hammer2_thread {
856 struct hammer2_pfs *pmp;
857 struct hammer2_dev *hmp;
858 hammer2_xop_list_t xopq;
859 thread_t td;
860 uint32_t flags;
861 int clindex; /* cluster element index */
862 int repidx;
863 char *scratch; /* MAXPHYS */
866 typedef struct hammer2_thread hammer2_thread_t;
868 #define HAMMER2_THREAD_UNMOUNTING 0x0001 /* unmount request */
869 #define HAMMER2_THREAD_DEV 0x0002 /* related to dev, not pfs */
870 #define HAMMER2_THREAD_WAITING 0x0004 /* thread in idle tsleep */
871 #define HAMMER2_THREAD_REMASTER 0x0008 /* remaster request */
872 #define HAMMER2_THREAD_STOP 0x0010 /* exit request */
873 #define HAMMER2_THREAD_FREEZE 0x0020 /* force idle */
874 #define HAMMER2_THREAD_FROZEN 0x0040 /* thread is frozen */
875 #define HAMMER2_THREAD_XOPQ 0x0080 /* work pending */
876 #define HAMMER2_THREAD_STOPPED 0x0100 /* thread has stopped */
877 #define HAMMER2_THREAD_UNFREEZE 0x0200
879 #define HAMMER2_THREAD_WAKEUP_MASK (HAMMER2_THREAD_UNMOUNTING | \
880 HAMMER2_THREAD_REMASTER | \
881 HAMMER2_THREAD_STOP | \
882 HAMMER2_THREAD_FREEZE | \
883 HAMMER2_THREAD_XOPQ)
886 * Support structure for dedup heuristic.
888 struct hammer2_dedup {
889 hammer2_off_t data_off;
890 uint64_t data_crc;
891 uint32_t ticks;
892 uint32_t saved_error;
895 typedef struct hammer2_dedup hammer2_dedup_t;
898 * hammer2_xop - container for VOP/XOP operation (allocated, not on stack).
900 * This structure is used to distribute a VOP operation across multiple
901 * nodes. It provides a rendezvous for concurrent node execution and
902 * can be detached from the frontend operation to allow the frontend to
903 * return early.
905 * This structure also sequences operations on up to three inodes.
907 typedef void (*hammer2_xop_func_t)(union hammer2_xop *xop, void *scratch,
908 int clindex);
910 struct hammer2_xop_desc {
911 hammer2_xop_func_t storage_func; /* local storage function */
912 hammer2_xop_func_t dmsg_dispatch; /* dmsg dispatch function */
913 hammer2_xop_func_t dmsg_process; /* dmsg processing function */
914 const char *id;
917 typedef struct hammer2_xop_desc hammer2_xop_desc_t;
919 struct hammer2_xop_fifo {
920 TAILQ_ENTRY(hammer2_xop_head) entry;
921 hammer2_chain_t **array;
922 int *errors;
923 int ri;
924 int wi;
925 int flags;
926 hammer2_thread_t *thr;
929 typedef struct hammer2_xop_fifo hammer2_xop_fifo_t;
931 #define HAMMER2_XOP_FIFO_RUN 0x0001
932 #define HAMMER2_XOP_FIFO_STALL 0x0002
934 struct hammer2_xop_head {
935 hammer2_xop_desc_t *desc;
936 hammer2_tid_t mtid;
937 struct hammer2_inode *ip1;
938 struct hammer2_inode *ip2;
939 struct hammer2_inode *ip3;
940 struct hammer2_inode *ip4;
941 uint64_t run_mask;
942 uint64_t chk_mask;
943 int fifo_size;
944 int flags;
945 int state;
946 int error;
947 hammer2_key_t collect_key;
948 char *name1;
949 size_t name1_len;
950 char *name2;
951 size_t name2_len;
952 hammer2_xop_fifo_t collect[HAMMER2_MAXCLUSTER];
953 hammer2_cluster_t cluster; /* help collections */
954 hammer2_io_t *focus_dio;
957 typedef struct hammer2_xop_head hammer2_xop_head_t;
959 #define fifo_mask(xop_head) ((xop_head)->fifo_size - 1)
961 struct hammer2_xop_ipcluster {
962 hammer2_xop_head_t head;
965 struct hammer2_xop_strategy {
966 hammer2_xop_head_t head;
967 hammer2_key_t lbase;
968 int finished;
969 hammer2_mtx_t lock;
970 struct bio *bio;
973 struct hammer2_xop_readdir {
974 hammer2_xop_head_t head;
975 hammer2_key_t lkey;
978 struct hammer2_xop_nresolve {
979 hammer2_xop_head_t head;
980 hammer2_key_t lhc; /* if name is NULL used lhc */
983 struct hammer2_xop_unlink {
984 hammer2_xop_head_t head;
985 int isdir;
986 int dopermanent;
989 #define H2DOPERM_PERMANENT 0x01
990 #define H2DOPERM_FORCE 0x02
991 #define H2DOPERM_IGNINO 0x04
993 struct hammer2_xop_nrename {
994 hammer2_xop_head_t head;
995 hammer2_tid_t lhc;
996 int ip_key;
999 struct hammer2_xop_scanlhc {
1000 hammer2_xop_head_t head;
1001 hammer2_key_t lhc;
1004 struct hammer2_xop_scanall {
1005 hammer2_xop_head_t head;
1006 hammer2_key_t key_beg; /* inclusive */
1007 hammer2_key_t key_end; /* inclusive */
1008 int resolve_flags;
1009 int lookup_flags;
1012 struct hammer2_xop_lookup {
1013 hammer2_xop_head_t head;
1014 hammer2_key_t lhc;
1017 struct hammer2_xop_mkdirent {
1018 hammer2_xop_head_t head;
1019 hammer2_dirent_head_t dirent;
1020 hammer2_key_t lhc;
1023 struct hammer2_xop_create {
1024 hammer2_xop_head_t head;
1025 hammer2_inode_meta_t meta; /* initial metadata */
1026 hammer2_key_t lhc;
1027 int flags;
1030 struct hammer2_xop_destroy {
1031 hammer2_xop_head_t head;
1034 struct hammer2_xop_fsync {
1035 hammer2_xop_head_t head;
1036 hammer2_inode_meta_t meta;
1037 hammer2_off_t osize;
1038 u_int ipflags;
1039 int clear_directdata;
1042 struct hammer2_xop_unlinkall {
1043 hammer2_xop_head_t head;
1044 hammer2_key_t key_beg;
1045 hammer2_key_t key_end;
1048 struct hammer2_xop_connect {
1049 hammer2_xop_head_t head;
1050 hammer2_key_t lhc;
1053 struct hammer2_xop_flush {
1054 hammer2_xop_head_t head;
1057 typedef struct hammer2_xop_readdir hammer2_xop_readdir_t;
1058 typedef struct hammer2_xop_nresolve hammer2_xop_nresolve_t;
1059 typedef struct hammer2_xop_unlink hammer2_xop_unlink_t;
1060 typedef struct hammer2_xop_nrename hammer2_xop_nrename_t;
1061 typedef struct hammer2_xop_ipcluster hammer2_xop_ipcluster_t;
1062 typedef struct hammer2_xop_strategy hammer2_xop_strategy_t;
1063 typedef struct hammer2_xop_mkdirent hammer2_xop_mkdirent_t;
1064 typedef struct hammer2_xop_create hammer2_xop_create_t;
1065 typedef struct hammer2_xop_destroy hammer2_xop_destroy_t;
1066 typedef struct hammer2_xop_fsync hammer2_xop_fsync_t;
1067 typedef struct hammer2_xop_unlinkall hammer2_xop_unlinkall_t;
1068 typedef struct hammer2_xop_scanlhc hammer2_xop_scanlhc_t;
1069 typedef struct hammer2_xop_scanall hammer2_xop_scanall_t;
1070 typedef struct hammer2_xop_lookup hammer2_xop_lookup_t;
1071 typedef struct hammer2_xop_connect hammer2_xop_connect_t;
1072 typedef struct hammer2_xop_flush hammer2_xop_flush_t;
1074 union hammer2_xop {
1075 hammer2_xop_head_t head;
1076 hammer2_xop_ipcluster_t xop_ipcluster;
1077 hammer2_xop_readdir_t xop_readdir;
1078 hammer2_xop_nresolve_t xop_nresolve;
1079 hammer2_xop_unlink_t xop_unlink;
1080 hammer2_xop_nrename_t xop_nrename;
1081 hammer2_xop_strategy_t xop_strategy;
1082 hammer2_xop_mkdirent_t xop_mkdirent;
1083 hammer2_xop_create_t xop_create;
1084 hammer2_xop_destroy_t xop_destroy;
1085 hammer2_xop_fsync_t xop_fsync;
1086 hammer2_xop_unlinkall_t xop_unlinkall;
1087 hammer2_xop_scanlhc_t xop_scanlhc;
1088 hammer2_xop_scanall_t xop_scanall;
1089 hammer2_xop_lookup_t xop_lookup;
1090 hammer2_xop_flush_t xop_flush;
1091 hammer2_xop_connect_t xop_connect;
1094 typedef union hammer2_xop hammer2_xop_t;
1097 * hammer2_xop_group - Manage XOP support threads.
1099 struct hammer2_xop_group {
1100 hammer2_thread_t thrs[HAMMER2_MAXCLUSTER];
1103 typedef struct hammer2_xop_group hammer2_xop_group_t;
1106 * flags to hammer2_xop_collect()
1108 #define HAMMER2_XOP_COLLECT_NOWAIT 0x00000001
1109 #define HAMMER2_XOP_COLLECT_WAITALL 0x00000002
1112 * flags to hammer2_xop_alloc()
1114 * MODIFYING - This is a modifying transaction, allocate a mtid.
1116 #define HAMMER2_XOP_MODIFYING 0x00000001
1117 #define HAMMER2_XOP_STRATEGY 0x00000002
1118 #define HAMMER2_XOP_INODE_STOP 0x00000004
1119 #define HAMMER2_XOP_VOLHDR 0x00000008
1120 #define HAMMER2_XOP_FSSYNC 0x00000010
1123 * Device vnode management structure
1125 struct hammer2_devvp {
1126 TAILQ_ENTRY(hammer2_devvp) entry;
1127 struct m_vnode *devvp; /* device vnode */
1128 char *path; /* device vnode path */
1129 int open; /* 1 if devvp open */
1132 typedef struct hammer2_devvp hammer2_devvp_t;
1134 TAILQ_HEAD(hammer2_devvp_list, hammer2_devvp);
1136 typedef struct hammer2_devvp_list hammer2_devvp_list_t;
1139 * Volume management structure
1141 struct hammer2_vfsvolume {
1142 hammer2_devvp_t *dev; /* device vnode management */
1143 int id; /* volume id */
1144 hammer2_off_t offset; /* offset within volumes */
1145 hammer2_off_t size; /* volume size */
1148 typedef struct hammer2_vfsvolume hammer2_vfsvolume_t;
1151 * Global (per partition) management structure, represents a hard block
1152 * device. Typically referenced by hammer2_chain structures when applicable.
1153 * Typically not used for network-managed elements.
1155 * Note that a single hammer2_dev can be indirectly tied to multiple system
1156 * mount points. There is no direct relationship. System mounts are
1157 * per-cluster-id, not per-block-device, and a single hard mount might contain
1158 * many PFSs and those PFSs might combine together in various ways to form
1159 * the set of available clusters.
1161 struct hammer2_dev {
1162 struct m_vnode *devvp; /* device vnode for root volume */
1163 int ronly; /* read-only mount */
1164 int mount_count; /* number of actively mounted PFSs */
1165 TAILQ_ENTRY(hammer2_dev) mntentry; /* hammer2_mntlist */
1167 struct malloc_type *mchain_obj;
1168 struct malloc_type *mio_obj;
1169 struct malloc_type *mmsg;
1170 //kdmsg_iocom_t iocom; /* volume-level dmsg interface */
1171 hammer2_io_hash_t iohash[HAMMER2_IOHASH_SIZE];
1172 int iofree_count;
1173 int io_iterator;
1174 int freemap_relaxed;
1175 int unused01;
1176 hammer2_chain_t vchain; /* anchor chain (topology) */
1177 hammer2_chain_t fchain; /* anchor chain (freemap) */
1178 hammer2_spin_t list_spin;
1179 struct hammer2_pfs *spmp; /* super-root pmp for transactions */
1180 struct lock vollk; /* lockmgr lock */
1181 struct lock bulklk; /* bulkfree operation lock */
1182 struct lock bflock; /* bulk-free manual function lock */
1183 hammer2_off_t heur_freemap[HAMMER2_FREEMAP_HEUR_SIZE];
1184 hammer2_dedup_t heur_dedup[HAMMER2_DEDUP_HEUR_SIZE];
1185 int volhdrno; /* last volhdrno written */
1186 uint32_t hflags; /* HMNT2 flags applicable to device */
1187 hammer2_off_t free_reserved; /* nominal free reserved */
1188 hammer2_off_t total_size; /* total size of volumes */
1189 int nvolumes; /* total number of volumes */
1190 hammer2_thread_t bfthr; /* bulk-free thread */
1191 char devrepname[64]; /* for kprintf */
1192 hammer2_volume_data_t voldata;
1193 hammer2_volume_data_t volsync; /* synchronized voldata */
1195 hammer2_devvp_list_t devvpl; /* list of device vnodes including *devvp */
1196 hammer2_vfsvolume_t volumes[HAMMER2_MAX_VOLUMES]; /* list of volumes */
1199 typedef struct hammer2_dev hammer2_dev_t;
1202 * Per-cluster management structure. This structure will be tied to a
1203 * system mount point if the system is mounting the PFS, but is also used
1204 * to manage clusters encountered during the super-root scan or received
1205 * via LNK_SPANs that might not be mounted.
1207 * This structure is also used to represent the super-root that hangs off
1208 * of a hard mount point. The super-root is not really a cluster element.
1209 * In this case the spmp_hmp field will be non-NULL. It's just easier to do
1210 * this than to special case super-root manipulation in the hammer2_chain*
1211 * code as being only hammer2_dev-related.
1213 * pfs_mode and pfs_nmasters are rollup fields which critically describes
1214 * how elements of the cluster act on the cluster. pfs_mode is only applicable
1215 * when a PFS is mounted by the system. pfs_nmasters is our best guess as to
1216 * how many masters have been configured for a cluster and is always
1217 * applicable. pfs_types[] is an array with 1:1 correspondance to the
1218 * iroot cluster and describes the PFS types of the nodes making up the
1219 * cluster.
1221 * WARNING! Portions of this structure have deferred initialization. In
1222 * particular, if not mounted there will be no wthread.
1223 * umounted network PFSs will also be missing iroot and numerous
1224 * other fields will not be initialized prior to mount.
1226 * Synchronization threads are chain-specific and only applicable
1227 * to local hard PFS entries. A hammer2_pfs structure may contain
1228 * more than one when multiple hard PFSs are present on the local
1229 * machine which require synchronization monitoring. Most PFSs
1230 * (such as snapshots) are 1xMASTER PFSs which do not need a
1231 * synchronization thread.
1233 * WARNING! The chains making up pfs->iroot's cluster are accounted for in
1234 * hammer2_dev->mount_count when the pfs is associated with a mount
1235 * point.
1237 struct hammer2_pfs {
1238 struct mount *mp;
1239 TAILQ_ENTRY(hammer2_pfs) mntentry; /* hammer2_pfslist */
1240 uuid_t pfs_clid;
1241 hammer2_dev_t *spmp_hmp; /* only if super-root pmp */
1242 hammer2_dev_t *force_local; /* only if 'local' mount */
1243 hammer2_inode_t *iroot; /* PFS root inode */
1244 uint8_t pfs_types[HAMMER2_MAXCLUSTER];
1245 char *pfs_names[HAMMER2_MAXCLUSTER];
1246 hammer2_dev_t *pfs_hmps[HAMMER2_MAXCLUSTER];
1247 hammer2_blockset_t pfs_iroot_blocksets[HAMMER2_MAXCLUSTER];
1248 hammer2_spin_t blockset_spin;
1249 hammer2_trans_t trans;
1250 struct lock lock; /* PFS lock for certain ops */
1251 //struct netexport export; /* nfs export */
1252 int unused00;
1253 int ronly; /* read-only mount */
1254 int hflags; /* pfs-specific mount flags */
1255 struct malloc_type *minode_obj;
1256 /* note: inumhash not applicable to spmp */
1257 hammer2_inum_hash_t inumhash[HAMMER2_INUMHASH_SIZE];
1258 long inum_count; /* #of inodes in inumhash */
1259 int flags;
1260 hammer2_tid_t modify_tid; /* modify transaction id */
1261 hammer2_tid_t inode_tid; /* inode allocator */
1262 uint8_t pfs_nmasters; /* total masters */
1263 uint8_t pfs_mode; /* operating mode PFSMODE */
1264 uint8_t unused01;
1265 uint8_t unused02;
1266 int free_ticks; /* free_* calculations */
1267 long inmem_inodes;
1268 hammer2_off_t free_reserved;
1269 hammer2_off_t free_nominal;
1270 uint32_t inmem_dirty_chains;
1271 int count_lwinprog; /* logical write in prog */
1272 hammer2_spin_t list_spin;
1273 struct inoq_head syncq; /* SYNCQ flagged inodes */
1274 struct depq_head depq; /* SIDEQ flagged inodes */
1275 long sideq_count; /* total inodes on depq */
1276 hammer2_thread_t sync_thrs[HAMMER2_MAXCLUSTER];
1277 uint32_t cluster_flags; /* cached cluster flags */
1278 int has_xop_threads;
1279 hammer2_spin_t xop_spin; /* xop sequencer */
1280 hammer2_xop_group_t *xop_groups;
1281 struct recq_head recq; /* makefs */
1284 typedef struct hammer2_pfs hammer2_pfs_t;
1286 TAILQ_HEAD(hammer2_pfslist, hammer2_pfs);
1289 * pmp->flags
1291 #define HAMMER2_PMPF_SPMP 0x00000001
1292 #define HAMMER2_PMPF_EMERG 0x00000002 /* Emergency delete mode */
1294 #define HAMMER2_DIRTYCHAIN_WAITING 0x80000000
1295 #define HAMMER2_DIRTYCHAIN_MASK 0x7FFFFFFF
1297 #define HAMMER2_LWINPROG_WAITING 0x80000000
1298 #define HAMMER2_LWINPROG_WAITING0 0x40000000
1299 #define HAMMER2_LWINPROG_MASK 0x3FFFFFFF
1302 * hammer2_cluster_check
1304 #define HAMMER2_CHECK_NULL 0x00000001
1307 * Misc
1309 //#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
1310 #define VTOI(vp) ((hammer2_inode_t *)(vp)->v_data)
1311 //#endif
1313 //#if defined(_KERNEL)
1315 #ifdef MALLOC_DECLARE
1316 MALLOC_DECLARE(M_HAMMER2);
1317 #endif
1319 static __inline
1320 hammer2_pfs_t *
1321 MPTOPMP(struct mount *mp)
1323 return ((hammer2_pfs_t *)mp->mnt_data);
1326 #define HAMMER2_DEDUP_FRAG (HAMMER2_PBUFSIZE / 64)
1327 #define HAMMER2_DEDUP_FRAGRADIX (HAMMER2_PBUFRADIX - 6)
1329 static __inline
1330 uint64_t
1331 hammer2_dedup_mask(hammer2_io_t *dio, hammer2_off_t data_off, u_int bytes)
1333 int bbeg;
1334 int bits;
1335 uint64_t mask;
1337 bbeg = (int)((data_off & ~HAMMER2_OFF_MASK_RADIX) - dio->pbase) >>
1338 HAMMER2_DEDUP_FRAGRADIX;
1339 bits = (int)((bytes + (HAMMER2_DEDUP_FRAG - 1)) >>
1340 HAMMER2_DEDUP_FRAGRADIX);
1341 if (bbeg + bits == 64)
1342 mask = (uint64_t)-1;
1343 else
1344 mask = ((uint64_t)1 << (bbeg + bits)) - 1;
1346 mask &= ~(((uint64_t)1 << bbeg) - 1);
1348 return mask;
1351 static __inline
1353 hammer2_error_to_errno(int error)
1355 if (error) {
1356 if (error & HAMMER2_ERROR_EIO)
1357 error = EIO;
1358 else if (error & HAMMER2_ERROR_CHECK)
1359 error = EDOM;
1360 else if (error & HAMMER2_ERROR_ABORTED)
1361 error = EINTR;
1362 else if (error & HAMMER2_ERROR_BADBREF)
1363 error = EIO;
1364 else if (error & HAMMER2_ERROR_ENOSPC)
1365 error = ENOSPC;
1366 else if (error & HAMMER2_ERROR_ENOENT)
1367 error = ENOENT;
1368 else if (error & HAMMER2_ERROR_ENOTEMPTY)
1369 error = ENOTEMPTY;
1370 else if (error & HAMMER2_ERROR_EAGAIN)
1371 error = EAGAIN;
1372 else if (error & HAMMER2_ERROR_ENOTDIR)
1373 error = ENOTDIR;
1374 else if (error & HAMMER2_ERROR_EISDIR)
1375 error = EISDIR;
1376 else if (error & HAMMER2_ERROR_EINPROGRESS)
1377 error = EINPROGRESS;
1378 else if (error & HAMMER2_ERROR_EEXIST)
1379 error = EEXIST;
1380 else if (error & HAMMER2_ERROR_EINVAL)
1381 error = EINVAL;
1382 else if (error & HAMMER2_ERROR_EDEADLK)
1383 error = EDEADLK;
1384 else if (error & HAMMER2_ERROR_ESRCH)
1385 error = ESRCH;
1386 else if (error & HAMMER2_ERROR_ETIMEDOUT)
1387 error = ETIMEDOUT;
1388 else
1389 error = EDOM;
1391 return error;
1394 static __inline
1396 hammer2_errno_to_error(int error)
1398 switch(error) {
1399 case 0:
1400 return 0;
1401 case EIO:
1402 return HAMMER2_ERROR_EIO;
1403 case EDOM:
1404 return HAMMER2_ERROR_CHECK;
1405 case EINTR:
1406 return HAMMER2_ERROR_ABORTED;
1407 //case EIO:
1408 // return HAMMER2_ERROR_BADBREF;
1409 case ENOSPC:
1410 return HAMMER2_ERROR_ENOSPC;
1411 case ENOENT:
1412 return HAMMER2_ERROR_ENOENT;
1413 case ENOTEMPTY:
1414 return HAMMER2_ERROR_ENOTEMPTY;
1415 case EAGAIN:
1416 return HAMMER2_ERROR_EAGAIN;
1417 case ENOTDIR:
1418 return HAMMER2_ERROR_ENOTDIR;
1419 case EISDIR:
1420 return HAMMER2_ERROR_EISDIR;
1421 case EINPROGRESS:
1422 return HAMMER2_ERROR_EINPROGRESS;
1423 case EEXIST:
1424 return HAMMER2_ERROR_EEXIST;
1425 case EINVAL:
1426 return HAMMER2_ERROR_EINVAL;
1427 case EDEADLK:
1428 return HAMMER2_ERROR_EDEADLK;
1429 case ESRCH:
1430 return HAMMER2_ERROR_ESRCH;
1431 case ETIMEDOUT:
1432 return HAMMER2_ERROR_ETIMEDOUT;
1433 default:
1434 return HAMMER2_ERROR_EINVAL;
1439 extern struct vop_ops hammer2_vnode_vops;
1440 extern struct vop_ops hammer2_spec_vops;
1441 extern struct vop_ops hammer2_fifo_vops;
1442 extern struct hammer2_pfslist hammer2_pfslist;
1443 extern struct lock hammer2_mntlk;
1445 extern int hammer2_aux_flags;
1446 extern int hammer2_debug;
1447 extern int hammer2_xop_nthreads;
1448 extern int hammer2_xop_sgroups;
1449 extern int hammer2_xop_xgroups;
1450 extern int hammer2_xop_xbase;
1451 extern int hammer2_xop_mod;
1452 extern long hammer2_debug_inode;
1453 extern int hammer2_cluster_meta_read;
1454 extern int hammer2_cluster_data_read;
1455 extern int hammer2_cluster_write;
1456 extern int hammer2_dedup_enable;
1457 extern int hammer2_always_compress;
1458 extern int hammer2_flush_pipe;
1459 extern int hammer2_dio_count;
1460 extern int hammer2_dio_limit;
1461 extern int hammer2_bulkfree_tps;
1462 extern int hammer2_spread_workers;
1463 extern int hammer2_limit_saved_depth;
1464 extern long hammer2_chain_allocs;
1465 extern long hammer2_limit_saved_chains;
1466 extern long hammer2_limit_dirty_chains;
1467 extern long hammer2_limit_dirty_inodes;
1468 extern long hammer2_count_modified_chains;
1469 extern long hammer2_iod_file_read;
1470 extern long hammer2_iod_meta_read;
1471 extern long hammer2_iod_indr_read;
1472 extern long hammer2_iod_fmap_read;
1473 extern long hammer2_iod_volu_read;
1474 extern long hammer2_iod_file_write;
1475 extern long hammer2_iod_file_wembed;
1476 extern long hammer2_iod_file_wzero;
1477 extern long hammer2_iod_file_wdedup;
1478 extern long hammer2_iod_meta_write;
1479 extern long hammer2_iod_indr_write;
1480 extern long hammer2_iod_fmap_write;
1481 extern long hammer2_iod_volu_write;
1483 extern long hammer2_process_icrc32;
1484 extern long hammer2_process_xxhash64;
1486 extern struct objcache *cache_buffer_read;
1487 extern struct objcache *cache_buffer_write;
1488 extern struct objcache *cache_xops;
1491 * hammer2_subr.c
1493 #define hammer2_icrc32(buf, size) iscsi_crc32((buf), (size))
1494 #define hammer2_icrc32c(buf, size, crc) iscsi_crc32_ext((buf), (size), (crc))
1496 int hammer2_signal_check(time_t *timep);
1497 const char *hammer2_error_str(int error);
1498 const char *hammer2_bref_type_str(int btype);
1500 int hammer2_get_dtype(uint8_t type);
1501 int hammer2_get_vtype(uint8_t type);
1502 uint8_t hammer2_get_obj_type(enum vtype vtype);
1503 void hammer2_time_to_timespec(uint64_t xtime, struct timespec *ts);
1504 uint64_t hammer2_timespec_to_time(const struct timespec *ts);
1505 void hammer2_time_to_timeval(uint64_t xtime, struct timeval *tv);
1506 uint32_t hammer2_to_unix_xid(const uuid_t *uuid);
1507 void hammer2_guid_to_uuid(uuid_t *uuid, uint32_t guid);
1509 hammer2_key_t hammer2_dirhash(const char *aname, size_t len);
1510 int hammer2_getradix(size_t bytes);
1512 int hammer2_calc_logical(hammer2_inode_t *ip, hammer2_off_t uoff,
1513 hammer2_key_t *lbasep, hammer2_key_t *leofp);
1514 int hammer2_calc_physical(hammer2_inode_t *ip, hammer2_key_t lbase);
1515 void hammer2_update_time(uint64_t *timep, bool is_mtime);
1516 void hammer2_adjreadcounter(int btype, size_t bytes);
1517 void hammer2_adjwritecounter(int btype, size_t bytes);
1520 * hammer2_inode.c
1522 struct m_vnode *hammer2_igetv(hammer2_inode_t *ip, int *errorp);
1523 hammer2_inode_t *hammer2_inode_lookup(hammer2_pfs_t *pmp,
1524 hammer2_tid_t inum);
1525 hammer2_inode_t *hammer2_inode_get(hammer2_pfs_t *pmp,
1526 hammer2_xop_head_t *xop, hammer2_tid_t inum, int idx);
1527 void hammer2_inode_ref(hammer2_inode_t *ip);
1528 void hammer2_inode_drop(hammer2_inode_t *ip);
1529 void hammer2_inode_repoint(hammer2_inode_t *ip, hammer2_cluster_t *cluster);
1530 void hammer2_inode_repoint_one(hammer2_inode_t *ip, hammer2_cluster_t *cluster,
1531 int idx);
1532 hammer2_key_t hammer2_inode_data_count(const hammer2_inode_t *ip);
1533 hammer2_key_t hammer2_inode_inode_count(const hammer2_inode_t *ip);
1534 void hammer2_inode_modify(hammer2_inode_t *ip);
1535 void hammer2_inode_delayed_sideq(hammer2_inode_t *ip);
1536 void hammer2_inode_lock(hammer2_inode_t *ip, int how);
1537 void hammer2_inode_lock4(hammer2_inode_t *ip1, hammer2_inode_t *ip2,
1538 hammer2_inode_t *ip3, hammer2_inode_t *ip4);
1539 void hammer2_inode_unlock(hammer2_inode_t *ip);
1540 void hammer2_inode_depend(hammer2_inode_t *ip1, hammer2_inode_t *ip2);
1541 hammer2_chain_t *hammer2_inode_chain(hammer2_inode_t *ip, int clindex, int how);
1542 hammer2_chain_t *hammer2_inode_chain_and_parent(hammer2_inode_t *ip,
1543 int clindex, hammer2_chain_t **parentp, int how);
1544 hammer2_mtx_state_t hammer2_inode_lock_temp_release(hammer2_inode_t *ip);
1545 void hammer2_inode_lock_temp_restore(hammer2_inode_t *ip,
1546 hammer2_mtx_state_t ostate);
1547 int hammer2_inode_lock_upgrade(hammer2_inode_t *ip);
1548 void hammer2_inode_lock_downgrade(hammer2_inode_t *ip, int);
1550 hammer2_inode_t *hammer2_inode_create_normal(hammer2_inode_t *pip,
1551 struct vattr *vap, struct ucred *cred,
1552 hammer2_key_t inum, int *errorp);
1553 hammer2_inode_t *hammer2_inode_create_pfs(hammer2_pfs_t *spmp,
1554 const char *name, size_t name_len,
1555 int *errorp);
1556 int hammer2_inode_chain_ins(hammer2_inode_t *ip);
1557 int hammer2_inode_chain_des(hammer2_inode_t *ip);
1558 int hammer2_inode_chain_sync(hammer2_inode_t *ip);
1559 int hammer2_inode_chain_flush(hammer2_inode_t *ip, int flags);
1560 int hammer2_inode_unlink_finisher(hammer2_inode_t *ip, struct m_vnode **vpp);
1561 void hammer2_inode_vprecycle(struct m_vnode *vp);
1562 int hammer2_dirent_create(hammer2_inode_t *dip, const char *name,
1563 size_t name_len, hammer2_key_t inum, uint8_t type);
1565 int vflush(struct mount *mp, int rootrefs, int flags);
1568 * hammer2_chain.c
1570 hammer2_chain_t *hammer2_chain_alloc(hammer2_dev_t *hmp,
1571 hammer2_pfs_t *pmp,
1572 hammer2_blockref_t *bref);
1573 void hammer2_chain_init(hammer2_chain_t *chain);
1574 void hammer2_chain_ref(hammer2_chain_t *chain);
1575 void hammer2_chain_ref_hold(hammer2_chain_t *chain);
1576 void hammer2_chain_drop(hammer2_chain_t *chain);
1577 void hammer2_chain_drop_unhold(hammer2_chain_t *chain);
1578 void hammer2_chain_unhold(hammer2_chain_t *chain);
1579 void hammer2_chain_rehold(hammer2_chain_t *chain);
1580 int hammer2_chain_lock(hammer2_chain_t *chain, int how);
1581 //void hammer2_chain_lock_unhold(hammer2_chain_t *chain, int how);
1582 void hammer2_chain_load_data(hammer2_chain_t *chain);
1584 int hammer2_chain_inode_find(hammer2_pfs_t *pmp, hammer2_key_t inum,
1585 int clindex, int flags,
1586 hammer2_chain_t **parentp,
1587 hammer2_chain_t **chainp);
1588 int hammer2_chain_modify(hammer2_chain_t *chain, hammer2_tid_t mtid,
1589 hammer2_off_t dedup_off, int flags);
1590 int hammer2_chain_modify_ip(hammer2_inode_t *ip, hammer2_chain_t *chain,
1591 hammer2_tid_t mtid, int flags);
1592 int hammer2_chain_resize(hammer2_chain_t *chain,
1593 hammer2_tid_t mtid, hammer2_off_t dedup_off,
1594 int nradix, int flags);
1595 void hammer2_chain_unlock(hammer2_chain_t *chain);
1596 //void hammer2_chain_unlock_hold(hammer2_chain_t *chain);
1597 hammer2_chain_t *hammer2_chain_get(hammer2_chain_t *parent, int generation,
1598 hammer2_blockref_t *bref, int how);
1599 hammer2_chain_t *hammer2_chain_lookup_init(hammer2_chain_t *parent, int flags);
1600 void hammer2_chain_lookup_done(hammer2_chain_t *parent);
1601 hammer2_chain_t *hammer2_chain_getparent(hammer2_chain_t *chain, int flags);
1602 hammer2_chain_t *hammer2_chain_repparent(hammer2_chain_t **chainp, int flags);
1603 hammer2_chain_t *hammer2_chain_lookup(hammer2_chain_t **parentp,
1604 hammer2_key_t *key_nextp,
1605 hammer2_key_t key_beg, hammer2_key_t key_end,
1606 int *errorp, int flags);
1607 hammer2_chain_t *hammer2_chain_next(hammer2_chain_t **parentp,
1608 hammer2_chain_t *chain,
1609 hammer2_key_t *key_nextp,
1610 hammer2_key_t key_beg, hammer2_key_t key_end,
1611 int *errorp, int flags);
1612 int hammer2_chain_scan(hammer2_chain_t *parent,
1613 hammer2_chain_t **chainp,
1614 hammer2_blockref_t *bref,
1615 int *firstp, int flags);
1617 int hammer2_chain_create(hammer2_chain_t **parentp, hammer2_chain_t **chainp,
1618 hammer2_dev_t *hmp, hammer2_pfs_t *pmp,
1619 int methods, hammer2_key_t key, int keybits,
1620 int type, size_t bytes, hammer2_tid_t mtid,
1621 hammer2_off_t dedup_off, int flags);
1622 void hammer2_chain_rename(hammer2_chain_t **parentp,
1623 hammer2_chain_t *chain,
1624 hammer2_tid_t mtid, int flags);
1625 int hammer2_chain_delete(hammer2_chain_t *parent, hammer2_chain_t *chain,
1626 hammer2_tid_t mtid, int flags);
1627 int hammer2_chain_indirect_maintenance(hammer2_chain_t *parent,
1628 hammer2_chain_t *chain);
1629 void hammer2_chain_setflush(hammer2_chain_t *chain);
1630 void hammer2_chain_countbrefs(hammer2_chain_t *chain,
1631 hammer2_blockref_t *base, int count);
1632 hammer2_chain_t *hammer2_chain_bulksnap(hammer2_dev_t *hmp);
1633 void hammer2_chain_bulkdrop(hammer2_chain_t *copy);
1635 void hammer2_chain_setcheck(hammer2_chain_t *chain, void *bdata);
1636 int hammer2_chain_testcheck(hammer2_chain_t *chain, void *bdata);
1637 int hammer2_chain_dirent_test(hammer2_chain_t *chain, const char *name,
1638 size_t name_len);
1640 void hammer2_base_delete(hammer2_chain_t *parent,
1641 hammer2_blockref_t *base, int count,
1642 hammer2_chain_t *chain,
1643 hammer2_blockref_t *obref);
1644 void hammer2_base_insert(hammer2_chain_t *parent,
1645 hammer2_blockref_t *base, int count,
1646 hammer2_chain_t *chain,
1647 hammer2_blockref_t *elm);
1648 void hammer2_dump_chain(hammer2_chain_t *chain, int tab, int bi, int *countp,
1649 char pfx, u_int flags);
1650 void hammer2_dump_chains(hammer2_dev_t *hmp, char vpfx, char fpfx);
1653 * hammer2_flush.c
1655 void hammer2_trans_manage_init(hammer2_pfs_t *pmp);
1656 int hammer2_flush(hammer2_chain_t *chain, int istop);
1657 void hammer2_trans_init(hammer2_pfs_t *pmp, uint32_t flags);
1658 void hammer2_trans_setflags(hammer2_pfs_t *pmp, uint32_t flags);
1659 void hammer2_trans_clearflags(hammer2_pfs_t *pmp, uint32_t flags);
1660 hammer2_tid_t hammer2_trans_sub(hammer2_pfs_t *pmp);
1661 void hammer2_trans_done(hammer2_pfs_t *pmp, uint32_t flags);
1662 hammer2_tid_t hammer2_trans_newinum(hammer2_pfs_t *pmp);
1663 void hammer2_trans_assert_strategy(hammer2_pfs_t *pmp);
1666 * hammer2_ioctl.c
1668 void hammer2_inum_hash_init(hammer2_pfs_t *pmp);
1669 int hammer2_ioctl(hammer2_inode_t *ip, u_long com, void *data,
1670 int fflag, struct ucred *cred);
1671 int hammer2_ioctl_version_get(hammer2_inode_t *ip, void *data);
1672 int hammer2_ioctl_pfs_get(hammer2_inode_t *ip, void *data);
1673 int hammer2_ioctl_pfs_lookup(hammer2_inode_t *ip, void *data);
1674 int hammer2_ioctl_pfs_create(hammer2_inode_t *ip, void *data);
1675 int hammer2_ioctl_pfs_delete(hammer2_inode_t *ip, void *data);
1676 int hammer2_ioctl_pfs_snapshot(hammer2_inode_t *ip, void *data);
1677 int hammer2_ioctl_inode_get(hammer2_inode_t *ip, void *data);
1678 int hammer2_ioctl_inode_set(hammer2_inode_t *ip, void *data);
1679 int hammer2_ioctl_emerg_mode(hammer2_inode_t *ip, u_int mode);
1680 int hammer2_ioctl_bulkfree_scan(hammer2_inode_t *ip, void *data);
1681 int hammer2_ioctl_destroy(hammer2_inode_t *ip, void *data);
1682 int hammer2_ioctl_growfs(hammer2_inode_t *ip, void *data, struct ucred *cred);
1685 * hammer2_io.c
1687 void hammer2_io_hash_init(hammer2_dev_t *hmp);
1688 void hammer2_io_inval(hammer2_io_t *dio, hammer2_off_t data_off, u_int bytes);
1689 void hammer2_io_hash_cleanup_all(hammer2_dev_t *hmp);
1690 char *hammer2_io_data(hammer2_io_t *dio, off_t lbase);
1691 void hammer2_io_bkvasync(hammer2_io_t *dio);
1692 void hammer2_io_dedup_set(hammer2_dev_t *hmp, hammer2_blockref_t *bref);
1693 void hammer2_io_dedup_delete(hammer2_dev_t *hmp, uint8_t btype,
1694 hammer2_off_t data_off, u_int bytes);
1695 void hammer2_io_dedup_assert(hammer2_dev_t *hmp, hammer2_off_t data_off,
1696 u_int bytes);
1697 int hammer2_io_new(hammer2_dev_t *hmp, int btype, off_t lbase, int lsize,
1698 hammer2_io_t **diop);
1699 int hammer2_io_newnz(hammer2_dev_t *hmp, int btype, off_t lbase, int lsize,
1700 hammer2_io_t **diop);
1701 int _hammer2_io_bread(hammer2_dev_t *hmp, int btype, off_t lbase, int lsize,
1702 hammer2_io_t **diop HAMMER2_IO_DEBUG_ARGS);
1703 void hammer2_io_setdirty(hammer2_io_t *dio);
1705 hammer2_io_t *_hammer2_io_getblk(hammer2_dev_t *hmp, int btype, off_t lbase,
1706 int lsize, int op HAMMER2_IO_DEBUG_ARGS);
1707 hammer2_io_t *_hammer2_io_getquick(hammer2_dev_t *hmp, off_t lbase,
1708 int lsize HAMMER2_IO_DEBUG_ARGS);
1709 void _hammer2_io_putblk(hammer2_io_t **diop HAMMER2_IO_DEBUG_ARGS);
1710 int _hammer2_io_bwrite(hammer2_io_t **diop HAMMER2_IO_DEBUG_ARGS);
1711 void _hammer2_io_bawrite(hammer2_io_t **diop HAMMER2_IO_DEBUG_ARGS);
1712 void _hammer2_io_bdwrite(hammer2_io_t **diop HAMMER2_IO_DEBUG_ARGS);
1713 void _hammer2_io_brelse(hammer2_io_t **diop HAMMER2_IO_DEBUG_ARGS);
1714 void _hammer2_io_bqrelse(hammer2_io_t **diop HAMMER2_IO_DEBUG_ARGS);
1715 void _hammer2_io_ref(hammer2_io_t *dio HAMMER2_IO_DEBUG_ARGS);
1717 #ifndef HAMMER2_IO_DEBUG
1719 #define hammer2_io_getblk(hmp, btype, lbase, lsize, op) \
1720 _hammer2_io_getblk((hmp), (btype), (lbase), (lsize), (op))
1721 #define hammer2_io_getquick(hmp, lbase, lsize) \
1722 _hammer2_io_getquick((hmp), (lbase), (lsize))
1723 #define hammer2_io_putblk(diop) \
1724 _hammer2_io_putblk(diop)
1725 #define hammer2_io_bwrite(diop) \
1726 _hammer2_io_bwrite((diop))
1727 #define hammer2_io_bawrite(diop) \
1728 _hammer2_io_bawrite((diop))
1729 #define hammer2_io_bdwrite(diop) \
1730 _hammer2_io_bdwrite((diop))
1731 #define hammer2_io_brelse(diop) \
1732 _hammer2_io_brelse((diop))
1733 #define hammer2_io_bqrelse(diop) \
1734 _hammer2_io_bqrelse((diop))
1735 #define hammer2_io_ref(dio) \
1736 _hammer2_io_ref((dio))
1738 #define hammer2_io_bread(hmp, btype, lbase, lsize, diop) \
1739 _hammer2_io_bread((hmp), (btype), (lbase), (lsize), (diop))
1741 #else
1743 #define hammer2_io_getblk(hmp, btype, lbase, lsize, op) \
1744 _hammer2_io_getblk((hmp), (btype), (lbase), (lsize), (op), \
1745 __FILE__, __LINE__)
1747 #define hammer2_io_getquick(hmp, lbase, lsize) \
1748 _hammer2_io_getquick((hmp), (lbase), (lsize), __FILE__, __LINE__)
1750 #define hammer2_io_putblk(diop) \
1751 _hammer2_io_putblk(diop, __FILE__, __LINE__)
1753 #define hammer2_io_bwrite(diop) \
1754 _hammer2_io_bwrite((diop), __FILE__, __LINE__)
1755 #define hammer2_io_bawrite(diop) \
1756 _hammer2_io_bawrite((diop), __FILE__, __LINE__)
1757 #define hammer2_io_bdwrite(diop) \
1758 _hammer2_io_bdwrite((diop), __FILE__, __LINE__)
1759 #define hammer2_io_brelse(diop) \
1760 _hammer2_io_brelse((diop), __FILE__, __LINE__)
1761 #define hammer2_io_bqrelse(diop) \
1762 _hammer2_io_bqrelse((diop), __FILE__, __LINE__)
1763 #define hammer2_io_ref(dio) \
1764 _hammer2_io_ref((dio), __FILE__, __LINE__)
1766 #define hammer2_io_bread(hmp, btype, lbase, lsize, diop) \
1767 _hammer2_io_bread((hmp), (btype), (lbase), (lsize), (diop), \
1768 __FILE__, __LINE__)
1770 #endif
1773 * hammer2_admin.c
1775 void hammer2_thr_signal(hammer2_thread_t *thr, uint32_t flags);
1776 void hammer2_thr_signal2(hammer2_thread_t *thr,
1777 uint32_t pflags, uint32_t nflags);
1778 void hammer2_thr_wait(hammer2_thread_t *thr, uint32_t flags);
1779 void hammer2_thr_wait_neg(hammer2_thread_t *thr, uint32_t flags);
1780 int hammer2_thr_wait_any(hammer2_thread_t *thr, uint32_t flags, int timo);
1781 void hammer2_thr_create(hammer2_thread_t *thr,
1782 hammer2_pfs_t *pmp, hammer2_dev_t *hmp,
1783 const char *id, int clindex, int repidx,
1784 void (*func)(void *arg));
1785 void hammer2_thr_delete(hammer2_thread_t *thr);
1786 void hammer2_thr_remaster(hammer2_thread_t *thr);
1787 void hammer2_thr_freeze_async(hammer2_thread_t *thr);
1788 void hammer2_thr_freeze(hammer2_thread_t *thr);
1789 void hammer2_thr_unfreeze(hammer2_thread_t *thr);
1790 int hammer2_thr_break(hammer2_thread_t *thr);
1791 void hammer2_primary_xops_thread(void *arg);
1794 * hammer2_thread.c (XOP API)
1796 void *hammer2_xop_alloc(hammer2_inode_t *ip, int flags);
1797 void hammer2_xop_setname(hammer2_xop_head_t *xop,
1798 const char *name, size_t name_len);
1799 void hammer2_xop_setname2(hammer2_xop_head_t *xop,
1800 const char *name, size_t name_len);
1801 size_t hammer2_xop_setname_inum(hammer2_xop_head_t *xop, hammer2_key_t inum);
1802 void hammer2_xop_setip2(hammer2_xop_head_t *xop, hammer2_inode_t *ip2);
1803 void hammer2_xop_setip3(hammer2_xop_head_t *xop, hammer2_inode_t *ip3);
1804 void hammer2_xop_setip4(hammer2_xop_head_t *xop, hammer2_inode_t *ip4);
1805 void hammer2_xop_reinit(hammer2_xop_head_t *xop);
1806 void hammer2_xop_helper_create(hammer2_pfs_t *pmp);
1807 void hammer2_xop_helper_cleanup(hammer2_pfs_t *pmp);
1808 void hammer2_xop_start(hammer2_xop_head_t *xop, hammer2_xop_desc_t *desc);
1809 void hammer2_xop_start_except(hammer2_xop_head_t *xop, hammer2_xop_desc_t *desc,
1810 int notidx);
1811 int hammer2_xop_collect(hammer2_xop_head_t *xop, int flags);
1812 void hammer2_xop_retire(hammer2_xop_head_t *xop, uint64_t mask);
1813 int hammer2_xop_active(hammer2_xop_head_t *xop);
1814 int hammer2_xop_feed(hammer2_xop_head_t *xop, hammer2_chain_t *chain,
1815 int clindex, int error);
1818 * hammer2_synchro.c
1820 void hammer2_primary_sync_thread(void *arg);
1823 * XOP backends in hammer2_xops.c, primarily for VNOPS. Other XOP backends
1824 * may be integrated into other source files.
1826 void hammer2_xop_ipcluster(hammer2_xop_t *xop, void *scratch, int clindex);
1827 void hammer2_xop_readdir(hammer2_xop_t *xop, void *scratch, int clindex);
1828 void hammer2_xop_nresolve(hammer2_xop_t *xop, void *scratch, int clindex);
1829 void hammer2_xop_unlink(hammer2_xop_t *xop, void *scratch, int clindex);
1830 void hammer2_xop_nrename(hammer2_xop_t *xop, void *scratch, int clindex);
1831 void hammer2_xop_scanlhc(hammer2_xop_t *xop, void *scratch, int clindex);
1832 void hammer2_xop_scanall(hammer2_xop_t *xop, void *scratch, int clindex);
1833 void hammer2_xop_lookup(hammer2_xop_t *xop, void *scratch, int clindex);
1834 void hammer2_xop_delete(hammer2_xop_t *xop, void *scratch, int clindex);
1835 void hammer2_xop_inode_mkdirent(hammer2_xop_t *xop, void *scratch, int clindex);
1836 void hammer2_xop_inode_create(hammer2_xop_t *xop, void *scratch, int clindex);
1837 void hammer2_xop_inode_create_det(hammer2_xop_t *xop,
1838 void *scratch, int clindex);
1839 void hammer2_xop_inode_create_ins(hammer2_xop_t *xop,
1840 void *scratch, int clindex);
1841 void hammer2_xop_inode_destroy(hammer2_xop_t *xop, void *scratch, int clindex);
1842 void hammer2_xop_inode_chain_sync(hammer2_xop_t *xop, void *scratch,
1843 int clindex);
1844 void hammer2_xop_inode_unlinkall(hammer2_xop_t *xop, void *scratch,
1845 int clindex);
1846 void hammer2_xop_inode_connect(hammer2_xop_t *xop, void *scratch, int clindex);
1847 void hammer2_xop_inode_flush(hammer2_xop_t *xop, void *scratch, int clindex);
1848 void hammer2_xop_strategy_read(hammer2_xop_t *xop, void *scratch, int clindex);
1849 void hammer2_xop_strategy_write(hammer2_xop_t *xop, void *scratch, int clindex);
1851 void hammer2_dmsg_ipcluster(hammer2_xop_t *xop, void *scratch, int clindex);
1852 void hammer2_dmsg_readdir(hammer2_xop_t *xop, void *scratch, int clindex);
1853 void hammer2_dmsg_nresolve(hammer2_xop_t *xop, void *scratch, int clindex);
1854 void hammer2_dmsg_unlink(hammer2_xop_t *xop, void *scratch, int clindex);
1855 void hammer2_dmsg_nrename(hammer2_xop_t *xop, void *scratch, int clindex);
1856 void hammer2_dmsg_scanlhc(hammer2_xop_t *xop, void *scratch, int clindex);
1857 void hammer2_dmsg_scanall(hammer2_xop_t *xop, void *scratch, int clindex);
1858 void hammer2_dmsg_lookup(hammer2_xop_t *xop, void *scratch, int clindex);
1859 void hammer2_dmsg_inode_mkdirent(hammer2_xop_t *xop, void *scratch,
1860 int clindex);
1861 void hammer2_dmsg_inode_create(hammer2_xop_t *xop, void *scratch, int clindex);
1862 void hammer2_dmsg_inode_destroy(hammer2_xop_t *xop, void *scratch, int clindex);
1863 void hammer2_dmsg_inode_chain_sync(hammer2_xop_t *xop, void *scratch,
1864 int clindex);
1865 void hammer2_dmsg_inode_unlinkall(hammer2_xop_t *xop, void *scratch,
1866 int clindex);
1867 void hammer2_dmsg_inode_connect(hammer2_xop_t *xop, void *scratch, int clindex);
1868 void hammer2_dmsg_inode_flush(hammer2_xop_t *xop, void *scratch, int clindex);
1869 void hammer2_dmsg_strategy_read(hammer2_xop_t *xop, void *scratch, int clindex);
1870 void hammer2_dmsg_strategy_write(hammer2_xop_t *xop, void *scratch,
1871 int clindex);
1873 void hammer2_rmsg_ipcluster(hammer2_xop_t *xop, void *scratch, int clindex);
1874 void hammer2_rmsg_readdir(hammer2_xop_t *xop, void *scratch, int clindex);
1875 void hammer2_rmsg_nresolve(hammer2_xop_t *xop, void *scratch, int clindex);
1876 void hammer2_rmsg_unlink(hammer2_xop_t *xop, void *scratch, int clindex);
1877 void hammer2_rmsg_nrename(hammer2_xop_t *xop, void *scratch, int clindex);
1878 void hammer2_rmsg_scanlhc(hammer2_xop_t *xop, void *scratch, int clindex);
1879 void hammer2_rmsg_scanall(hammer2_xop_t *xop, void *scratch, int clindex);
1880 void hammer2_rmsg_lookup(hammer2_xop_t *xop, void *scratch, int clindex);
1881 void hammer2_rmsg_inode_mkdirent(hammer2_xop_t *xop, void *scratch,
1882 int clindex);
1883 void hammer2_rmsg_inode_create(hammer2_xop_t *xop, void *scratch, int clindex);
1884 void hammer2_rmsg_inode_destroy(hammer2_xop_t *xop, void *scratch, int clindex);
1885 void hammer2_rmsg_inode_chain_sync(hammer2_xop_t *xop, void *scratch,
1886 int clindex);
1887 void hammer2_rmsg_inode_unlinkall(hammer2_xop_t *xop, void *scratch,
1888 int clindex);
1889 void hammer2_rmsg_inode_connect(hammer2_xop_t *xop, void *scratch, int clindex);
1890 void hammer2_rmsg_inode_flush(hammer2_xop_t *xop, void *scratch, int clindex);
1891 void hammer2_rmsg_strategy_read(hammer2_xop_t *xop, void *scratch, int clindex);
1892 void hammer2_rmsg_strategy_write(hammer2_xop_t *xop, void *scratch,
1893 int clindex);
1895 extern hammer2_xop_desc_t hammer2_ipcluster_desc;
1896 extern hammer2_xop_desc_t hammer2_readdir_desc;
1897 extern hammer2_xop_desc_t hammer2_nresolve_desc;
1898 extern hammer2_xop_desc_t hammer2_unlink_desc;
1899 extern hammer2_xop_desc_t hammer2_nrename_desc;
1900 extern hammer2_xop_desc_t hammer2_scanlhc_desc;
1901 extern hammer2_xop_desc_t hammer2_scanall_desc;
1902 extern hammer2_xop_desc_t hammer2_lookup_desc;
1903 extern hammer2_xop_desc_t hammer2_delete_desc;
1904 extern hammer2_xop_desc_t hammer2_inode_mkdirent_desc;
1905 extern hammer2_xop_desc_t hammer2_inode_create_desc;
1906 extern hammer2_xop_desc_t hammer2_inode_create_det_desc;
1907 extern hammer2_xop_desc_t hammer2_inode_create_ins_desc;
1908 extern hammer2_xop_desc_t hammer2_inode_destroy_desc;
1909 extern hammer2_xop_desc_t hammer2_inode_chain_sync_desc;
1910 extern hammer2_xop_desc_t hammer2_inode_unlinkall_desc;
1911 extern hammer2_xop_desc_t hammer2_inode_connect_desc;
1912 extern hammer2_xop_desc_t hammer2_inode_flush_desc;
1913 extern hammer2_xop_desc_t hammer2_strategy_read_desc;
1914 extern hammer2_xop_desc_t hammer2_strategy_write_desc;
1917 * hammer2_msgops.c
1920 int hammer2_msg_dbg_rcvmsg(kdmsg_msg_t *msg);
1921 int hammer2_msg_adhoc_input(kdmsg_msg_t *msg);
1925 * hammer2_vfsops.c
1927 int hammer2_vfs_sync(struct mount *mp, int waitflags);
1928 int hammer2_vfs_sync_pmp(hammer2_pfs_t *pmp, int waitfor);
1929 int hammer2_vfs_enospace(hammer2_inode_t *ip, off_t bytes, struct ucred *cred);
1931 hammer2_pfs_t *hammer2_pfsalloc(hammer2_chain_t *chain,
1932 const hammer2_inode_data_t *ripdata,
1933 hammer2_dev_t *force_local);
1934 void hammer2_pfsdealloc(hammer2_pfs_t *pmp, int clindex, int destroying);
1935 int hammer2_vfs_vget(struct mount *mp, struct m_vnode *dvp,
1936 ino_t ino, struct m_vnode **vpp);
1937 int hammer2_vfs_root(struct mount *mp, struct m_vnode **vpp);
1939 void hammer2_lwinprog_ref(hammer2_pfs_t *pmp);
1940 void hammer2_lwinprog_drop(hammer2_pfs_t *pmp);
1941 void hammer2_lwinprog_wait(hammer2_pfs_t *pmp, int pipe);
1943 void hammer2_pfs_memory_wait(hammer2_pfs_t *pmp);
1944 void hammer2_pfs_memory_inc(hammer2_pfs_t *pmp);
1945 void hammer2_pfs_memory_wakeup(hammer2_pfs_t *pmp, int count);
1947 void hammer2_voldata_lock(hammer2_dev_t *hmp);
1948 void hammer2_voldata_unlock(hammer2_dev_t *hmp);
1949 void hammer2_voldata_modify(hammer2_dev_t *hmp);
1951 int hammer2_vfs_init(void);
1952 int hammer2_vfs_uninit(void);
1954 int hammer2_vfs_mount(struct m_vnode *makefs_devvp, struct mount *mp,
1955 const char *label, const struct hammer2_mount_info *mi);
1956 int hammer2_vfs_unmount(struct mount *mp, int mntflags);
1959 * hammer2_freemap.c
1961 int hammer2_freemap_alloc(hammer2_chain_t *chain, size_t bytes);
1962 void hammer2_freemap_adjust(hammer2_dev_t *hmp,
1963 hammer2_blockref_t *bref, int how);
1966 * hammer2_cluster.c
1968 uint8_t hammer2_cluster_type(hammer2_cluster_t *cluster);
1969 void hammer2_cluster_bref(hammer2_cluster_t *cluster, hammer2_blockref_t *bref);
1970 void hammer2_cluster_ref(hammer2_cluster_t *cluster);
1971 void hammer2_cluster_drop(hammer2_cluster_t *cluster);
1972 void hammer2_cluster_unhold(hammer2_cluster_t *cluster);
1973 void hammer2_cluster_rehold(hammer2_cluster_t *cluster);
1974 void hammer2_cluster_lock(hammer2_cluster_t *cluster, int how);
1975 int hammer2_cluster_check(hammer2_cluster_t *cluster, hammer2_key_t lokey,
1976 int flags);
1977 void hammer2_cluster_unlock(hammer2_cluster_t *cluster);
1979 void hammer2_bulkfree_init(hammer2_dev_t *hmp);
1980 void hammer2_bulkfree_uninit(hammer2_dev_t *hmp);
1981 int hammer2_bulkfree_pass(hammer2_dev_t *hmp, hammer2_chain_t *vchain,
1982 struct hammer2_ioc_bulkfree *bfi);
1983 void hammer2_dummy_xop_from_chain(hammer2_xop_head_t *xop,
1984 hammer2_chain_t *chain);
1987 * hammer2_iocom.c
1990 void hammer2_iocom_init(hammer2_dev_t *hmp);
1991 void hammer2_iocom_uninit(hammer2_dev_t *hmp);
1992 void hammer2_cluster_reconnect(hammer2_dev_t *hmp, struct file *fp);
1994 void hammer2_volconf_update(hammer2_dev_t *hmp, int index);
1997 * hammer2_strategy.c
1999 int hammer2_vop_strategy(struct vop_strategy_args *ap);
2000 int hammer2_vop_bmap(struct vop_bmap_args *ap);
2001 void hammer2_bioq_sync(hammer2_pfs_t *pmp);
2002 void hammer2_dedup_record(hammer2_chain_t *chain, hammer2_io_t *dio,
2003 const char *data);
2004 void hammer2_dedup_clear(hammer2_dev_t *hmp);
2007 * hammer2_ondisk.c
2009 int hammer2_open_devvp(const hammer2_devvp_list_t *devvpl, int ronly);
2010 int hammer2_close_devvp(const hammer2_devvp_list_t *devvpl, int ronly);
2011 int hammer2_init_devvp(struct m_vnode *devvp, hammer2_devvp_list_t *devvpl);
2012 void hammer2_cleanup_devvp(hammer2_devvp_list_t *devvpl);
2013 int hammer2_init_vfsvolumes(struct mount *mp,
2014 const hammer2_devvp_list_t *devvpl,
2015 hammer2_vfsvolume_t *volumes,
2016 hammer2_volume_data_t *rootvoldata,
2017 int *rootvolzone,
2018 struct m_vnode **rootvoldevvp);
2019 hammer2_vfsvolume_t *hammer2_get_volume_from_hmp(hammer2_dev_t *hmp,
2020 hammer2_off_t offset);
2023 * hammer2_vnops.c
2025 int hammer2_reclaim(struct m_vnode *vp);
2026 int hammer2_readdir(struct m_vnode *vp, void *buf, size_t size, off_t *offsetp,
2027 int *ndirentp, int *eofflagp);
2028 int hammer2_readlink(struct m_vnode *vp, void *buf, size_t size);
2029 int hammer2_read(struct m_vnode *vp, void *buf, size_t size, off_t offset);
2030 int hammer2_write(struct m_vnode *vp, void *buf, size_t size, off_t offset);
2031 int hammer2_nresolve(struct m_vnode *dvp, struct m_vnode **vpp, char *name, int nlen);
2032 int hammer2_nmkdir(struct m_vnode *dvp, struct m_vnode **vpp, char *name, int nlen,
2033 mode_t mode);
2034 int hammer2_nlink(struct m_vnode *dvp, struct m_vnode *vp, char *name, int nlen);
2035 int hammer2_ncreate(struct m_vnode *dvp, struct m_vnode **vpp, char *name, int nlen,
2036 mode_t mode);
2037 int hammer2_nmknod(struct m_vnode *dvp, struct m_vnode **vpp, char *name, int nlen,
2038 int type, mode_t mode);
2039 int hammer2_nsymlink(struct m_vnode *dvp, struct m_vnode **vpp, char *name, int nlen,
2040 char *target, mode_t mode);
2043 * hammer2_buf.c
2045 struct m_buf *getblkx(struct m_vnode *vp, off_t loffset, int size, int blkflags,
2046 int slptimeo);
2047 int breadx(struct m_vnode *vp, off_t loffset, int size, struct m_buf **bpp);
2048 int bread_kvabio(struct m_vnode *vp, off_t loffset, int size, struct m_buf **bpp);
2049 void bqrelse(struct m_buf *bp);
2050 int bawrite(struct m_buf *bp);
2051 int uiomove(caddr_t cp, size_t n, struct uio *uio);
2052 int uiomovebp(struct m_buf *bp, caddr_t cp, size_t n, struct uio *uio);
2055 * More complex inlines
2058 #define hammer2_xop_gdata(xop) _hammer2_xop_gdata((xop), __FILE__, __LINE__)
2060 static __inline
2061 const hammer2_media_data_t *
2062 _hammer2_xop_gdata(hammer2_xop_head_t *xop, const char *file, int line)
2064 hammer2_chain_t *focus;
2065 const void *data;
2067 focus = xop->cluster.focus;
2068 if (focus->dio) {
2069 lockmgr(&focus->diolk, LK_SHARED);
2070 if ((xop->focus_dio = focus->dio) != NULL) {
2071 _hammer2_io_ref(xop->focus_dio HAMMER2_IO_DEBUG_CALL);
2072 hammer2_io_bkvasync(xop->focus_dio);
2074 data = focus->data;
2075 lockmgr(&focus->diolk, LK_RELEASE);
2076 } else {
2077 data = focus->data;
2080 return data;
2083 #define hammer2_xop_pdata(xop) _hammer2_xop_pdata((xop), __FILE__, __LINE__)
2085 static __inline
2086 void
2087 _hammer2_xop_pdata(hammer2_xop_head_t *xop, const char *file, int line)
2089 if (xop->focus_dio)
2090 _hammer2_io_putblk(&xop->focus_dio HAMMER2_IO_DEBUG_CALL);
2093 static __inline
2094 void
2095 hammer2_knote(struct m_vnode *vp, int flags)
2097 if (flags)
2098 KNOTE(&vp->v_pollinfo.vpi_kqinfo.ki_note, flags);
2101 static __inline
2102 void
2103 hammer2_iocom_init(hammer2_dev_t *hmp)
2107 static __inline
2108 void
2109 hammer2_iocom_uninit(hammer2_dev_t *hmp)
2113 //#endif /* !_KERNEL */
2114 #endif /* !_VFS_HAMMER2_HAMMER2_H_ */