hammer2 - Refactor frontend part 14/many
[dragonfly.git] / sys / vfs / hammer2 / hammer2.h
CommitLineData
703720e4 1/*
506bd6d1 2 * Copyright (c) 2011-2015 The DragonFly Project. All rights reserved.
703720e4
MD
3 *
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>
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
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
17 * distribution.
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.
21 *
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
33 * SUCH DAMAGE.
34 */
35
36/*
278ab2b2
MD
37 * HAMMER2 IN-MEMORY CACHE OF MEDIA STRUCTURES
38 *
703720e4
MD
39 * This header file contains structures used internally by the HAMMER2
40 * implementation. See hammer2_disk.h for on-disk structures.
278ab2b2
MD
41 *
42 * There is an in-memory representation of all on-media data structure.
da6f36f4
MD
43 * Almost everything is represented by a hammer2_chain structure in-memory.
44 * Other higher-level structures typically map to chains.
278ab2b2
MD
45 *
46 * A great deal of data is accessed simply via its buffer cache buffer,
da6f36f4
MD
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.
278ab2b2
MD
50 *
51 * When modifications are made to a chain a new filesystem block must be
da6f36f4
MD
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
55 * flushed.
278ab2b2
MD
56 *
57 * The in-memory representation may remain cached (for example in order to
58 * placemark clustering locks) even after the related data has been
59 * detached.
703720e4
MD
60 */
61
62#ifndef _VFS_HAMMER2_HAMMER2_H_
63#define _VFS_HAMMER2_HAMMER2_H_
64
65#include <sys/param.h>
66#include <sys/types.h>
67#include <sys/kernel.h>
68#include <sys/conf.h>
69#include <sys/systm.h>
70#include <sys/tree.h>
71#include <sys/malloc.h>
72#include <sys/mount.h>
73#include <sys/vnode.h>
74#include <sys/proc.h>
75#include <sys/mountctl.h>
76#include <sys/priv.h>
77#include <sys/stat.h>
46558838 78#include <sys/thread.h>
703720e4
MD
79#include <sys/globaldata.h>
80#include <sys/lockf.h>
81#include <sys/buf.h>
82#include <sys/queue.h>
83#include <sys/limits.h>
5bc5bca2 84#include <sys/dmsg.h>
355d67fc 85#include <sys/mutex.h>
278ab2b2
MD
86#include <sys/kern_syscall.h>
87
94491fa0 88#include <sys/signal2.h>
278ab2b2 89#include <sys/buf2.h>
355d67fc 90#include <sys/mutex2.h>
5ceaaa82 91#include <sys/thread2.h>
703720e4
MD
92
93#include "hammer2_disk.h"
94#include "hammer2_mount.h"
2910a90c 95#include "hammer2_ioctl.h"
703720e4 96
bca9f8e6
MD
97struct hammer2_io;
98struct hammer2_iocb;
5c23d7f1 99struct hammer2_chain;
278ab2b2 100struct hammer2_cluster;
703720e4 101struct hammer2_inode;
506bd6d1
MD
102struct hammer2_dev;
103struct hammer2_pfs;
10c86c4e 104struct hammer2_span;
26bf1a36
MD
105struct hammer2_state;
106struct hammer2_msg;
2ed4fece 107struct hammer2_thread;
c847e838 108union hammer2_xop;
703720e4 109
94491fa0
MD
110/*
111 * Mutex and lock shims. Hammer2 requires support for asynchronous and
112 * abortable locks, and both exclusive and shared spinlocks. Normal
113 * synchronous non-abortable locks can be substituted for spinlocks.
114 */
115typedef mtx_t hammer2_mtx_t;
116typedef mtx_link_t hammer2_mtx_link_t;
117typedef mtx_state_t hammer2_mtx_state_t;
118
119typedef struct spinlock hammer2_spin_t;
120
121#define hammer2_mtx_ex mtx_lock_ex_quick
122#define hammer2_mtx_sh mtx_lock_sh_quick
123#define hammer2_mtx_unlock mtx_unlock
124#define hammer2_mtx_owned mtx_owned
125#define hammer2_mtx_init mtx_init
126#define hammer2_mtx_temp_release mtx_lock_temp_release
127#define hammer2_mtx_temp_restore mtx_lock_temp_restore
128#define hammer2_mtx_refs mtx_lockrefs
129
130#define hammer2_spin_init spin_init
131#define hammer2_spin_sh spin_lock_shared
132#define hammer2_spin_ex spin_lock
133#define hammer2_spin_unsh spin_unlock_shared
134#define hammer2_spin_unex spin_unlock
135
c847e838
MD
136TAILQ_HEAD(hammer2_xop_list, hammer2_xop_head);
137
138typedef struct hammer2_xop_list hammer2_xop_list_t;
139
140
94491fa0
MD
141/*
142 * General lock support
143 */
144static __inline
145int
146hammer2_mtx_upgrade(hammer2_mtx_t *mtx)
147{
148 int wasexclusive;
149
150 if (mtx_islocked_ex(mtx)) {
151 wasexclusive = 1;
152 } else {
153 mtx_unlock(mtx);
154 mtx_lock_ex_quick(mtx);
155 wasexclusive = 0;
156 }
157 return wasexclusive;
158}
159
160/*
161 * Downgrade an inode lock from exclusive to shared only if the inode
162 * lock was previously shared. If the inode lock was previously exclusive,
163 * this is a NOP.
164 */
165static __inline
166void
167hammer2_mtx_downgrade(hammer2_mtx_t *mtx, int wasexclusive)
168{
169 if (wasexclusive == 0)
170 mtx_downgrade(mtx);
171}
172
50456506
MD
173/*
174 * The xid tracks internal transactional updates.
175 *
176 * XXX fix-me, really needs to be 64-bits
177 */
178typedef uint32_t hammer2_xid_t;
179
180#define HAMMER2_XID_MIN 0x00000000U
181#define HAMMER2_XID_MAX 0x7FFFFFFFU
182
50e4f8f4 183/*
1897c66e
MD
184 * The chain structure tracks a portion of the media topology from the
185 * root (volume) down. Chains represent volumes, inodes, indirect blocks,
186 * data blocks, and freemap nodes and leafs.
187 *
da6f36f4
MD
188 * The chain structure utilizes a simple singly-homed topology and the
189 * chain's in-memory topology will move around as the chains do, due mainly
190 * to renames and indirect block creation.
191 *
192 * Block Table Updates
1897c66e 193 *
da6f36f4
MD
194 * Block table updates for insertions and updates are delayed until the
195 * flush. This allows us to avoid having to modify the parent chain
196 * all the way to the root.
1897c66e 197 *
da6f36f4
MD
198 * Block table deletions are performed immediately (modifying the parent
199 * in the process) because the flush code uses the chain structure to
200 * track delayed updates and the chain will be (likely) gone or moved to
201 * another location in the topology after a deletion.
8138a154 202 *
da6f36f4
MD
203 * A prior iteration of the code tried to keep the relationship intact
204 * on deletes by doing a delete-duplicate operation on the chain, but
205 * it added way too much complexity to the codebase.
8138a154 206 *
da6f36f4 207 * Flush Synchronization
8138a154 208 *
da6f36f4
MD
209 * The flush code must flush modified chains bottom-up. Because chain
210 * structures can shift around and are NOT topologically stable,
211 * modified chains are independently indexed for the flush. As the flush
212 * runs it modifies (or further modifies) and updates the parents,
213 * propagating the flush all the way to the volume root.
5c23d7f1 214 *
da6f36f4
MD
215 * Modifying front-end operations can occur during a flush but will block
216 * in two cases: (1) when the front-end tries to operate on the inode
217 * currently in the midst of being flushed and (2) if the front-end
218 * crosses an inode currently being flushed (such as during a rename).
219 * So, for example, if you rename directory "x" to "a/b/c/d/e/f/g/x" and
220 * the flusher is currently working on "a/b/c", the rename will block
221 * temporarily in order to ensure that "x" exists in one place or the
222 * other.
0dea3156 223 *
da6f36f4
MD
224 * Meta-data statistics are updated by the flusher. The front-end will
225 * make estimates but meta-data must be fully synchronized only during a
226 * flush in order to ensure that it remains correct across a crash.
0dea3156 227 *
da6f36f4
MD
228 * Multiple flush synchronizations can theoretically be in-flight at the
229 * same time but the implementation is not coded to handle the case and
230 * currently serializes them.
0dea3156 231 *
da6f36f4 232 * Snapshots:
0dea3156 233 *
da6f36f4
MD
234 * Snapshots currently require the subdirectory tree being snapshotted
235 * to be flushed. The snapshot then creates a new super-root inode which
236 * copies the flushed blockdata of the directory or file that was
237 * snapshotted.
0dea3156 238 *
da6f36f4 239 * RBTREE NOTES:
0dea3156 240 *
da6f36f4
MD
241 * - Note that the radix tree runs in powers of 2 only so sub-trees
242 * cannot straddle edges.
50e4f8f4 243 */
ecc33e71 244RB_HEAD(hammer2_chain_tree, hammer2_chain);
da6f36f4 245TAILQ_HEAD(h2_flush_list, hammer2_chain);
1897c66e 246TAILQ_HEAD(h2_core_list, hammer2_chain);
bca9f8e6 247TAILQ_HEAD(h2_iocb_list, hammer2_iocb);
1897c66e 248
8138a154
MD
249#define CHAIN_CORE_DELETE_BMAP_ENTRIES \
250 (HAMMER2_PBUFSIZE / sizeof(hammer2_blockref_t) / sizeof(uint32_t))
5c23d7f1 251
f1c7c224
MD
252/*
253 * Core topology for chain (embedded in chain). Protected by a spinlock.
254 */
0dea3156 255struct hammer2_chain_core {
94491fa0 256 hammer2_spin_t spin;
da6f36f4 257 struct hammer2_chain_tree rbtree; /* sub-chains */
c057466c 258 int live_zero; /* blockref array opt */
1897c66e 259 u_int live_count; /* live (not deleted) chains in tree */
8138a154 260 u_int chain_count; /* live + deleted chains under core */
a4dc31e0 261 int generation; /* generation number (inserts only) */
0dea3156
MD
262};
263
264typedef struct hammer2_chain_core hammer2_chain_core_t;
265
bca9f8e6
MD
266RB_HEAD(hammer2_io_tree, hammer2_io);
267
fdf62707 268/*
bca9f8e6 269 * IOCB - IO callback (into chain, cluster, or manual request)
fdf62707 270 */
bca9f8e6
MD
271struct hammer2_iocb {
272 TAILQ_ENTRY(hammer2_iocb) entry;
273 void (*callback)(struct hammer2_iocb *iocb);
274 struct hammer2_io *dio;
275 struct hammer2_cluster *cluster;
276 struct hammer2_chain *chain;
277 void *ptr;
278 off_t lbase;
279 int lsize;
280 uint32_t flags;
281 int error;
282};
283
284typedef struct hammer2_iocb hammer2_iocb_t;
285
286#define HAMMER2_IOCB_INTERLOCK 0x00000001
287#define HAMMER2_IOCB_ONQ 0x00000002
288#define HAMMER2_IOCB_DONE 0x00000004
289#define HAMMER2_IOCB_INPROG 0x00000008
3148f677 290#define HAMMER2_IOCB_UNUSED10 0x00000010
bca9f8e6
MD
291#define HAMMER2_IOCB_QUICK 0x00010000
292#define HAMMER2_IOCB_ZERO 0x00020000
293#define HAMMER2_IOCB_READ 0x00040000
294#define HAMMER2_IOCB_WAKEUP 0x00080000
fdf62707 295
bca9f8e6
MD
296/*
297 * DIO - Management structure wrapping system buffer cache.
298 *
299 * Used for multiple purposes including concurrent management
300 * if small requests by chains into larger DIOs.
301 */
fdf62707 302struct hammer2_io {
0924b3f8 303 RB_ENTRY(hammer2_io) rbnode; /* indexed by device offset */
bca9f8e6 304 struct h2_iocb_list iocbq;
fdf62707 305 struct spinlock spin;
506bd6d1 306 struct hammer2_dev *hmp;
fdf62707 307 struct buf *bp;
fdf62707
MD
308 off_t pbase;
309 int psize;
fdf62707 310 int refs;
0924b3f8 311 int act; /* activity */
fdf62707
MD
312};
313
314typedef struct hammer2_io hammer2_io_t;
315
bca9f8e6 316#define HAMMER2_DIO_INPROG 0x80000000 /* bio in progress */
3148f677 317#define HAMMER2_DIO_GOOD 0x40000000 /* dio->bp is stable */
bca9f8e6
MD
318#define HAMMER2_DIO_WAITING 0x20000000 /* (old) */
319#define HAMMER2_DIO_DIRTY 0x10000000 /* flush on last drop */
320
321#define HAMMER2_DIO_MASK 0x0FFFFFFF
322
fdf62707
MD
323/*
324 * Primary chain structure keeps track of the topology in-memory.
325 */
50e4f8f4 326struct hammer2_chain {
f1c7c224 327 hammer2_mtx_t lock;
da6f36f4 328 hammer2_chain_core_t core;
8138a154 329 RB_ENTRY(hammer2_chain) rbnode; /* live chain(s) */
0dea3156 330 hammer2_blockref_t bref;
da6f36f4 331 struct hammer2_chain *parent;
0dea3156 332 struct hammer2_state *state; /* if active cache msg */
506bd6d1
MD
333 struct hammer2_dev *hmp;
334 struct hammer2_pfs *pmp; /* A PFS or super-root (spmp) */
50456506 335
fdf62707 336 hammer2_io_t *dio; /* physical data buffer */
0dea3156 337 u_int bytes; /* physical data size */
5c23d7f1 338 u_int flags;
0dea3156 339 u_int refs;
731b2a84 340 u_int lockcnt;
23c7c7dd
MD
341 int error; /* on-lock data error state */
342
0dea3156 343 hammer2_media_data_t *data; /* data pointer shortcut */
da6f36f4 344 TAILQ_ENTRY(hammer2_chain) flush_node; /* flush list */
50e4f8f4
MD
345};
346
347typedef struct hammer2_chain hammer2_chain_t;
348
5c23d7f1 349int hammer2_chain_cmp(hammer2_chain_t *chain1, hammer2_chain_t *chain2);
ecc33e71 350RB_PROTOTYPE(hammer2_chain_tree, hammer2_chain, rbnode, hammer2_chain_cmp);
5c23d7f1 351
1a7cfe5a
MD
352/*
353 * Special notes on flags:
354 *
b93cc2e0
MD
355 * INITIAL - This flag allows a chain to be created and for storage to
356 * be allocated without having to immediately instantiate the
357 * related buffer. The data is assumed to be all-zeros. It
358 * is primarily used for indirect blocks.
1a7cfe5a 359 *
b93cc2e0 360 * MODIFIED - The chain's media data has been modified.
da6f36f4 361 *
b93cc2e0
MD
362 * UPDATE - Chain might not be modified but parent blocktable needs update
363 *
364 * FICTITIOUS - Faked chain as a placeholder for an error condition. This
365 * chain is unsuitable for I/O.
366 *
367 * BMAPPED - Indicates that the chain is present in the parent blockmap.
368 *
369 * BMAPUPD - Indicates that the chain is present but needs to be updated
370 * in the parent blockmap.
1a7cfe5a 371 */
0dea3156
MD
372#define HAMMER2_CHAIN_MODIFIED 0x00000001 /* dirty chain data */
373#define HAMMER2_CHAIN_ALLOCATED 0x00000002 /* kmalloc'd chain */
da6f36f4 374#define HAMMER2_CHAIN_DESTROY 0x00000004
1f6671f8 375#define HAMMER2_CHAIN_UNUSED0008 0x00000008
5f6853df 376#define HAMMER2_CHAIN_DELETED 0x00000010 /* deleted chain */
01eabad4 377#define HAMMER2_CHAIN_INITIAL 0x00000020 /* initial create */
da6f36f4
MD
378#define HAMMER2_CHAIN_UPDATE 0x00000040 /* need parent update */
379#define HAMMER2_CHAIN_DEFERRED 0x00000080 /* flush depth defer */
37aa19df 380#define HAMMER2_CHAIN_IOFLUSH 0x00000100 /* bawrite on put */
da6f36f4 381#define HAMMER2_CHAIN_ONFLUSH 0x00000200 /* on a flush list */
b93cc2e0 382#define HAMMER2_CHAIN_FICTITIOUS 0x00000400 /* unsuitable for I/O */
0dea3156 383#define HAMMER2_CHAIN_VOLUMESYNC 0x00000800 /* needs volume sync */
eedd52a3 384#define HAMMER2_CHAIN_DELAYED 0x00001000 /* delayed flush */
f1c7c224 385#define HAMMER2_CHAIN_COUNTEDBREFS 0x00002000 /* block table stats */
5f6853df 386#define HAMMER2_CHAIN_ONRBTREE 0x00004000 /* on parent RB tree */
22211834 387#define HAMMER2_CHAIN_UNUSED00008000 0x00008000
512beabd 388#define HAMMER2_CHAIN_EMBEDDED 0x00010000 /* embedded data */
10136ab6 389#define HAMMER2_CHAIN_RELEASE 0x00020000 /* don't keep around */
da6f36f4
MD
390#define HAMMER2_CHAIN_BMAPPED 0x00040000 /* present in blkmap */
391#define HAMMER2_CHAIN_BMAPUPD 0x00080000 /* +needs updating */
f1c7c224
MD
392#define HAMMER2_CHAIN_IOINPROG 0x00100000 /* I/O interlock */
393#define HAMMER2_CHAIN_IOSIGNAL 0x00200000 /* I/O interlock */
50456506 394#define HAMMER2_CHAIN_PFSBOUNDARY 0x00400000 /* super->pfs inode */
c667909f 395
da6f36f4
MD
396#define HAMMER2_CHAIN_FLUSH_MASK (HAMMER2_CHAIN_MODIFIED | \
397 HAMMER2_CHAIN_UPDATE | \
398 HAMMER2_CHAIN_ONFLUSH)
399
23c7c7dd
MD
400/*
401 * Hammer2 error codes, used by chain->error and cluster->error. The error
402 * code is typically set on-lock unless no I/O was requested, and set on
403 * I/O otherwise. If set for a cluster it generally means that the cluster
404 * code could not find a valid copy to present.
405 *
b93cc2e0
MD
406 * IO - An I/O error occurred
407 * CHECK - I/O succeeded but did not match the check code
408 * INCOMPLETE - A cluster is not complete enough to use, or
409 * a chain cannot be loaded because its parent has an error.
410 *
23c7c7dd
MD
411 * NOTE: API allows callers to check zero/non-zero to determine if an error
412 * condition exists.
413 *
414 * NOTE: Chain's data field is usually NULL on an IO error but not necessarily
415 * NULL on other errors. Check chain->error, not chain->data.
416 */
417#define HAMMER2_ERROR_NONE 0
418#define HAMMER2_ERROR_IO 1 /* device I/O error */
419#define HAMMER2_ERROR_CHECK 2 /* check code mismatch */
420#define HAMMER2_ERROR_INCOMPLETE 3 /* incomplete cluster */
0cc33e20 421#define HAMMER2_ERROR_DEPTH 4 /* temporary depth limit */
23c7c7dd 422
c667909f
MD
423/*
424 * Flags passed to hammer2_chain_lookup() and hammer2_chain_next()
1a7cfe5a 425 *
c847e838
MD
426 * NOTES:
427 * NOLOCK - Input and output chains are referenced only and not
428 * locked. Output chain might be temporarily locked
429 * internally.
430 *
431 * NODATA - Asks that the chain->data not be resolved in order
432 * to avoid I/O.
433 *
434 * NODIRECT - Prevents a lookup of offset 0 in an inode from returning
435 * the inode itself if the inode is in DIRECTDATA mode
436 * (i.e. file is <= 512 bytes). Used by the synchronization
437 * code to prevent confusion.
438 *
439 * SHARED - The input chain is expected to be locked shared,
440 * and the output chain is locked shared.
441 *
442 * MATCHIND - Allows an indirect block / freemap node to be returned
443 * when the passed key range matches the radix. Remember
444 * that key_end is inclusive (e.g. {0x000,0xFFF},
445 * not {0x000,0x1000}).
446 *
447 * (Cannot be used for remote or cluster ops).
448 *
449 * ALLNODES - Allows NULL focus.
450 *
451 * ALWAYS - Always resolve the data. If ALWAYS and NODATA are both
452 * missing, bulk file data is not resolved but inodes and
453 * other meta-data will.
f7712c43 454 *
c847e838
MD
455 * NOUNLOCK - Used by hammer2_chain_next() to leave the lock on
456 * the input chain intact. The chain is still dropped.
457 * This allows the caller to add a reference to the chain
458 * and retain it in a locked state (used by the
459 * XOP/feed/collect code).
c667909f
MD
460 */
461#define HAMMER2_LOOKUP_NOLOCK 0x00000001 /* ref only */
8cce658d 462#define HAMMER2_LOOKUP_NODATA 0x00000002 /* data left NULL */
f7712c43 463#define HAMMER2_LOOKUP_NODIRECT 0x00000004 /* no offset=0 DD */
a0ed3c24 464#define HAMMER2_LOOKUP_SHARED 0x00000100
10136ab6 465#define HAMMER2_LOOKUP_MATCHIND 0x00000200 /* return all chains */
a6cf1052 466#define HAMMER2_LOOKUP_ALLNODES 0x00000400 /* allow NULL focus */
1a7cfe5a 467#define HAMMER2_LOOKUP_ALWAYS 0x00000800 /* resolve data */
c847e838 468#define HAMMER2_LOOKUP_NOUNLOCK 0x00001000 /* leave lock intact */
5c23d7f1 469
01eabad4
MD
470/*
471 * Flags passed to hammer2_chain_modify() and hammer2_chain_resize()
472 *
473 * NOTE: OPTDATA allows us to avoid instantiating buffers for INDIRECT
474 * blocks in the INITIAL-create state.
475 */
01eabad4 476#define HAMMER2_MODIFY_OPTDATA 0x00000002 /* data can be NULL */
4d5318eb 477#define HAMMER2_MODIFY_NO_MODIFY_TID 0x00000004
c603b86b 478#define HAMMER2_MODIFY_KEEPMODIFY 0x00000008
1a7cfe5a 479#define HAMMER2_MODIFY_NOREALLOC 0x00000010
01eabad4
MD
480
481/*
482 * Flags passed to hammer2_chain_lock()
b8ba9690
MD
483 *
484 * NOTE: RDONLY is set to optimize cluster operations when *no* modifications
485 * will be made to either the cluster being locked or any underlying
486 * cluster. It allows the cluster to lock and access data for a subset
487 * of available nodes instead of all available nodes.
01eabad4
MD
488 */
489#define HAMMER2_RESOLVE_NEVER 1
490#define HAMMER2_RESOLVE_MAYBE 2
491#define HAMMER2_RESOLVE_ALWAYS 3
a0ed3c24
MD
492#define HAMMER2_RESOLVE_MASK 0x0F
493
1a7cfe5a 494#define HAMMER2_RESOLVE_SHARED 0x10 /* request shared lock */
e513e77e 495#define HAMMER2_RESOLVE_UNUSED20 0x20
b8ba9690 496#define HAMMER2_RESOLVE_RDONLY 0x40 /* higher level op flag */
01eabad4 497
91abd410
MD
498/*
499 * Flags passed to hammer2_chain_delete()
500 */
da6f36f4 501#define HAMMER2_DELETE_PERMANENT 0x0001
b3659de2
MD
502#define HAMMER2_DELETE_NOSTATS 0x0002
503
504#define HAMMER2_INSERT_NOSTATS 0x0002
506bd6d1 505#define HAMMER2_INSERT_PFSROOT 0x0004
91abd410 506
09dd2dfe
MD
507/*
508 * Flags passed to hammer2_chain_delete_duplicate()
509 */
510#define HAMMER2_DELDUP_RECORE 0x0001
511
6ba3b984
MD
512/*
513 * Cluster different types of storage together for allocations
514 */
515#define HAMMER2_FREECACHE_INODE 0
516#define HAMMER2_FREECACHE_INDIR 1
517#define HAMMER2_FREECACHE_DATA 2
518#define HAMMER2_FREECACHE_UNUSED3 3
519#define HAMMER2_FREECACHE_TYPES 4
520
1a7cfe5a
MD
521/*
522 * hammer2_freemap_alloc() block preference
523 */
524#define HAMMER2_OFF_NOPREF ((hammer2_off_t)-1)
525
6ba3b984
MD
526/*
527 * BMAP read-ahead maximum parameters
528 */
529#define HAMMER2_BMAP_COUNT 16 /* max bmap read-ahead */
530#define HAMMER2_BMAP_BYTES (HAMMER2_PBUFSIZE * HAMMER2_BMAP_COUNT)
531
10136ab6
MD
532/*
533 * hammer2_freemap_adjust()
534 */
535#define HAMMER2_FREEMAP_DORECOVER 1
536#define HAMMER2_FREEMAP_DOMAYFREE 2
537#define HAMMER2_FREEMAP_DOREALFREE 3
538
703720e4 539/*
278ab2b2 540 * HAMMER2 cluster - A set of chains representing the same entity.
5c23d7f1 541 *
94491fa0
MD
542 * hammer2_cluster typically represents a temporary set of representitive
543 * chains. The one exception is that a hammer2_cluster is embedded in
544 * hammer2_inode. This embedded cluster is ONLY used to track the
545 * representitive chains and cannot be directly locked.
546 *
5ceaaa82
MD
547 * A cluster is usually temporary (and thus per-thread) for locking purposes,
548 * allowing us to embed the asynchronous storage required for cluster
549 * operations in the cluster itself and adjust the state and status without
550 * having to worry too much about SMP issues.
551 *
552 * The exception is the cluster embedded in the hammer2_inode structure.
553 * This is used to cache the cluster state on an inode-by-inode basis.
554 * Individual hammer2_chain structures not incorporated into clusters might
555 * also stick around to cache miscellanious elements.
94491fa0
MD
556 *
557 * Because the cluster is a 'working copy' and is usually subject to cluster
558 * quorum rules, it is quite possible for us to end up with an insufficient
559 * number of live chains to execute an operation. If an insufficient number
560 * of chains remain in a working copy, the operation may have to be
5ceaaa82
MD
561 * downgraded, retried, stall until the requisit number of chains are
562 * available, or possibly even error out depending on the mount type.
8db69c9f
MD
563 *
564 * A cluster's focus is set when it is locked. The focus can only be set
565 * to a chain still part of the synchronized set.
5c23d7f1 566 */
278ab2b2 567#define HAMMER2_MAXCLUSTER 8
c847e838
MD
568#define HAMMER2_XOPFIFO 16
569#define HAMMER2_XOPFIFO_MASK (HAMMER2_XOPFIFO - 1)
2ed4fece 570#define HAMMER2_XOPGROUPS 16
c847e838
MD
571#define HAMMER2_XOPGROUPS_MASK (HAMMER2_XOPGROUPS - 1)
572#define HAMMER2_XOPMASK_VOP 0x80000000U
278ab2b2 573
4b7e61e0 574struct hammer2_cluster_item {
a6cf1052 575#if 0
4b7e61e0 576 hammer2_mtx_link_t async_link;
a6cf1052 577#endif
4b7e61e0 578 hammer2_chain_t *chain;
a6cf1052 579#if 0
4b7e61e0 580 struct hammer2_cluster *cluster; /* link back to cluster */
a6cf1052 581#endif
4b7e61e0 582 int cache_index;
b8ba9690 583 uint32_t flags;
4b7e61e0
MD
584};
585
586typedef struct hammer2_cluster_item hammer2_cluster_item_t;
587
8db69c9f
MD
588/*
589 * INVALID - Invalid for focus, i.e. not part of synchronized set.
590 * Once set, this bit is sticky across operations.
e513e77e
MD
591 *
592 * FEMOD - Indicates that front-end modifying operations can
593 * mess with this entry and MODSYNC will copy also
594 * effect it.
8db69c9f
MD
595 */
596#define HAMMER2_CITEM_INVALID 0x00000001
e513e77e 597#define HAMMER2_CITEM_FEMOD 0x00000002
c847e838 598#define HAMMER2_CITEM_NULL 0x00000004
8db69c9f 599
278ab2b2 600struct hammer2_cluster {
278ab2b2 601 int refs; /* track for deallocation */
b8ba9690 602 int ddflag;
506bd6d1 603 struct hammer2_pfs *pmp;
278ab2b2
MD
604 uint32_t flags;
605 int nchains;
23c7c7dd 606 int error; /* error code valid on lock */
8db69c9f 607 int focus_index;
bca9f8e6 608 hammer2_iocb_t iocb;
278ab2b2 609 hammer2_chain_t *focus; /* current focus (or mod) */
4b7e61e0 610 hammer2_cluster_item_t array[HAMMER2_MAXCLUSTER];
278ab2b2
MD
611};
612
94491fa0 613typedef struct hammer2_cluster hammer2_cluster_t;
278ab2b2 614
5ceaaa82
MD
615/*
616 * WRHARD - Hard mounts can write fully synchronized
617 * RDHARD - Hard mounts can read fully synchronized
b93cc2e0
MD
618 * UNHARD - Unsynchronized masters present
619 * NOHARD - No masters visible
5ceaaa82
MD
620 * WRSOFT - Soft mounts can write to at least the SOFT_MASTER
621 * RDSOFT - Soft mounts can read from at least a SOFT_SLAVE
b93cc2e0
MD
622 * UNSOFT - Unsynchronized slaves present
623 * NOSOFT - No slaves visible
5ceaaa82
MD
624 * RDSLAVE - slaves are accessible (possibly unsynchronized or remote).
625 * MSYNCED - All masters are fully synchronized
626 * SSYNCED - All known local slaves are fully synchronized to masters
627 *
628 * All available masters are always incorporated. All PFSs belonging to a
629 * cluster (master, slave, copy, whatever) always try to synchronize the
630 * total number of known masters in the PFSs root inode.
631 *
632 * A cluster might have access to many slaves, copies, or caches, but we
633 * have a limited number of cluster slots. Any such elements which are
634 * directly mounted from block device(s) will always be incorporated. Note
635 * that SSYNCED only applies to such elements which are directly mounted,
636 * not to any remote slaves, copies, or caches that could be available. These
637 * bits are used to monitor and drive our synchronization threads.
638 *
639 * When asking the question 'is any data accessible at all', then a simple
640 * test against (RDHARD|RDSOFT|RDSLAVE) gives you the answer. If any of
641 * these bits are set the object can be read with certain caveats:
642 * RDHARD - no caveats. RDSOFT - authoritative but might not be synchronized.
643 * and RDSLAVE - not authoritative, has some data but it could be old or
644 * incomplete.
645 *
646 * When both soft and hard mounts are available, data will be read and written
647 * via the soft mount only. But all might be in the cluster because
648 * background synchronization threads still need to do their work.
649 */
a6cf1052
MD
650#define HAMMER2_CLUSTER_INODE 0x00000001 /* embedded in inode struct */
651#define HAMMER2_CLUSTER_UNUSED2 0x00000002
b8ba9690 652#define HAMMER2_CLUSTER_LOCKED 0x00000004 /* cluster lks not recursive */
5ceaaa82
MD
653#define HAMMER2_CLUSTER_WRHARD 0x00000100 /* hard-mount can write */
654#define HAMMER2_CLUSTER_RDHARD 0x00000200 /* hard-mount can read */
b93cc2e0
MD
655#define HAMMER2_CLUSTER_UNHARD 0x00000400 /* unsynchronized masters */
656#define HAMMER2_CLUSTER_NOHARD 0x00000800 /* no masters visible */
657#define HAMMER2_CLUSTER_WRSOFT 0x00001000 /* soft-mount can write */
658#define HAMMER2_CLUSTER_RDSOFT 0x00002000 /* soft-mount can read */
659#define HAMMER2_CLUSTER_UNSOFT 0x00004000 /* unsynchronized slaves */
660#define HAMMER2_CLUSTER_NOSOFT 0x00008000 /* no slaves visible */
661#define HAMMER2_CLUSTER_MSYNCED 0x00010000 /* all masters synchronized */
662#define HAMMER2_CLUSTER_SSYNCED 0x00020000 /* known slaves synchronized */
5ceaaa82
MD
663
664#define HAMMER2_CLUSTER_ANYDATA ( HAMMER2_CLUSTER_RDHARD | \
665 HAMMER2_CLUSTER_RDSOFT | \
666 HAMMER2_CLUSTER_RDSLAVE)
667
668#define HAMMER2_CLUSTER_RDOK ( HAMMER2_CLUSTER_RDHARD | \
669 HAMMER2_CLUSTER_RDSOFT)
670
671#define HAMMER2_CLUSTER_WROK ( HAMMER2_CLUSTER_WRHARD | \
672 HAMMER2_CLUSTER_WRSOFT)
278ab2b2 673
b8ba9690
MD
674#define HAMMER2_CLUSTER_ZFLAGS ( HAMMER2_CLUSTER_WRHARD | \
675 HAMMER2_CLUSTER_RDHARD | \
676 HAMMER2_CLUSTER_WRSOFT | \
677 HAMMER2_CLUSTER_RDSOFT | \
678 HAMMER2_CLUSTER_MSYNCED | \
679 HAMMER2_CLUSTER_SSYNCED)
5c23d7f1 680
23c7c7dd
MD
681/*
682 * Helper functions (cluster must be locked for flags to be valid).
683 */
684static __inline
685int
686hammer2_cluster_rdok(hammer2_cluster_t *cluster)
687{
688 return (cluster->flags & HAMMER2_CLUSTER_RDOK);
689}
690
691static __inline
692int
693hammer2_cluster_wrok(hammer2_cluster_t *cluster)
694{
695 return (cluster->flags & HAMMER2_CLUSTER_WROK);
696}
697
9797e933
MD
698RB_HEAD(hammer2_inode_tree, hammer2_inode);
699
5c23d7f1
MD
700/*
701 * A hammer2 inode.
46558838 702 *
bca9f8e6
MD
703 * NOTE: The inode-embedded cluster is never used directly for I/O (since
704 * it may be shared). Instead it will be replicated-in and synchronized
705 * back out if changed.
703720e4
MD
706 */
707struct hammer2_inode {
9797e933 708 RB_ENTRY(hammer2_inode) rbnode; /* inumber lookup (HL) */
94491fa0 709 hammer2_mtx_t lock; /* inode lock */
506bd6d1 710 struct hammer2_pfs *pmp; /* PFS mount */
e028fa74 711 struct hammer2_inode *pip; /* parent inode */
703720e4 712 struct vnode *vp;
eedd52a3 713 struct spinlock cluster_spin; /* update cluster */
278ab2b2 714 hammer2_cluster_t cluster;
37aa19df 715 struct lockf advlock;
476d2aad
MD
716 u_int flags;
717 u_int refs; /* +vpref, +flushref */
1e5c08ba 718 uint8_t comp_heuristic;
7a9b14a0 719 hammer2_inode_meta_t meta; /* copy of meta-data */
159c3ca2 720 hammer2_blockref_t bref; /* copy of bref statistics */
2121ef11 721 hammer2_off_t osize;
703720e4
MD
722};
723
54eb943b
MD
724typedef struct hammer2_inode hammer2_inode_t;
725
2121ef11
MD
726/*
727 * MODIFIED - Inode is in a modified state, ip->meta may have changes.
728 * RESIZED - Inode truncated (any) or inode extended beyond
729 * EMBEDDED_BYTES.
730 */
476d2aad 731#define HAMMER2_INODE_MODIFIED 0x0001
99da41ea 732#define HAMMER2_INODE_SROOT 0x0002 /* kmalloc special case */
51bf8e9b 733#define HAMMER2_INODE_RENAME_INPROG 0x0004
9797e933 734#define HAMMER2_INODE_ONRBTREE 0x0008
2121ef11
MD
735#define HAMMER2_INODE_RESIZED 0x0010 /* requires inode_fsync */
736#define HAMMER2_INODE_UNUSED0020 0x0020
1f6671f8 737#define HAMMER2_INODE_ISUNLINKED 0x0040
7a9b14a0 738#define HAMMER2_INODE_METAGOOD 0x0080 /* inode meta-data good */
9797e933
MD
739
740int hammer2_inode_cmp(hammer2_inode_t *ip1, hammer2_inode_t *ip2);
741RB_PROTOTYPE2(hammer2_inode_tree, hammer2_inode, rbnode, hammer2_inode_cmp,
742 hammer2_tid_t);
5c23d7f1 743
eae2ed61
MD
744/*
745 * inode-unlink side-structure
746 */
747struct hammer2_inode_unlink {
748 TAILQ_ENTRY(hammer2_inode_unlink) entry;
749 hammer2_inode_t *ip;
750};
da6f36f4 751TAILQ_HEAD(h2_unlk_list, hammer2_inode_unlink);
eae2ed61
MD
752
753typedef struct hammer2_inode_unlink hammer2_inode_unlink_t;
754
0dea3156 755/*
c603b86b 756 * Transaction management sub-structure under hammer2_pfs
0dea3156
MD
757 */
758struct hammer2_trans {
c603b86b
MD
759 uint32_t flags;
760 uint32_t sync_wait;
0dea3156
MD
761};
762
763typedef struct hammer2_trans hammer2_trans_t;
764
c603b86b
MD
765#define HAMMER2_TRANS_ISFLUSH 0x80000000 /* flush code */
766#define HAMMER2_TRANS_BUFCACHE 0x40000000 /* bio strategy */
767#define HAMMER2_TRANS_PREFLUSH 0x20000000 /* preflush state */
768#define HAMMER2_TRANS_FPENDING 0x10000000 /* flush pending */
769#define HAMMER2_TRANS_WAITING 0x08000000 /* someone waiting */
770#define HAMMER2_TRANS_MASK 0x00FFFFFF /* count mask */
d001f460 771
91abd410
MD
772#define HAMMER2_FREEMAP_HEUR_NRADIX 4 /* pwr 2 PBUFRADIX-MINIORADIX */
773#define HAMMER2_FREEMAP_HEUR_TYPES 8
774#define HAMMER2_FREEMAP_HEUR (HAMMER2_FREEMAP_HEUR_NRADIX * \
775 HAMMER2_FREEMAP_HEUR_TYPES)
004f88b4 776
1f6671f8 777/*
2ed4fece 778 * Hammer2 support thread element.
b0f58de8 779 *
2ed4fece
MD
780 * Potentially many support threads can hang off of hammer2, primarily
781 * off the hammer2_pfs structure. Typically:
8db69c9f 782 *
2ed4fece
MD
783 * td x Nodes A synchronization thread for each node.
784 * td x Nodes x workers Worker threads for frontend operations.
785 * td x 1 Bioq thread for logical buffer writes.
8db69c9f 786 *
2ed4fece
MD
787 * In addition, the synchronization thread(s) associated with the
788 * super-root PFS (spmp) for a node is responsible for automatic bulkfree
789 * and dedup scans.
8db69c9f 790 */
2ed4fece 791struct hammer2_thread {
8db69c9f 792 struct hammer2_pfs *pmp;
8db69c9f
MD
793 thread_t td;
794 uint32_t flags;
f7712c43 795 int depth;
2ed4fece
MD
796 int clindex; /* cluster element index */
797 int repidx;
2ed4fece 798 struct lock lk; /* thread control lock */
c847e838 799 hammer2_xop_list_t xopq;
2ed4fece
MD
800};
801
802typedef struct hammer2_thread hammer2_thread_t;
803
804#define HAMMER2_THREAD_UNMOUNTING 0x0001 /* unmount request */
805#define HAMMER2_THREAD_DEV 0x0002 /* related to dev, not pfs */
806#define HAMMER2_THREAD_UNUSED04 0x0004
807#define HAMMER2_THREAD_REMASTER 0x0008 /* remaster request */
808#define HAMMER2_THREAD_STOP 0x0010 /* exit request */
809#define HAMMER2_THREAD_FREEZE 0x0020 /* force idle */
810#define HAMMER2_THREAD_FROZEN 0x0040 /* restart */
811
812
813/*
c847e838 814 * hammer2_xop - container for VOP/XOP operation (allocated, not on stack).
2ed4fece
MD
815 *
816 * This structure is used to distribute a VOP operation across multiple
817 * nodes. It provides a rendezvous for concurrent node execution and
818 * can be detached from the frontend operation to allow the frontend to
819 * return early.
820 */
c847e838
MD
821typedef void (*hammer2_xop_func_t)(union hammer2_xop *xop, int clidx);
822
823typedef struct hammer2_xop_fifo {
824 TAILQ_ENTRY(hammer2_xop_head) entry;
825 hammer2_chain_t *array[HAMMER2_XOPFIFO];
826 int errors[HAMMER2_XOPFIFO];
827 int ri;
828 int wi;
829 int unused03;
830} hammer2_xop_fifo_t;
831
832struct hammer2_xop_head {
833 hammer2_xop_func_t func;
834 struct hammer2_inode *ip;
e12ae3a5
MD
835 struct hammer2_inode *ip2;
836 struct hammer2_inode *ip3;
c847e838
MD
837 struct hammer2_xop_group *xgrp;
838 uint32_t check_counter;
839 uint32_t run_mask;
840 uint32_t chk_mask;
841 int state;
842 int error;
12ff971c
MD
843 char *name;
844 size_t name_len;
e12ae3a5
MD
845 char *name2;
846 size_t name2_len;
c847e838
MD
847 hammer2_key_t lkey;
848 hammer2_key_t nkey;
849 hammer2_xop_fifo_t collect[HAMMER2_MAXCLUSTER];
850 hammer2_cluster_t cluster; /* help collections */
8db69c9f
MD
851};
852
c847e838
MD
853typedef struct hammer2_xop_head hammer2_xop_head_t;
854
c603b86b
MD
855struct hammer2_xop_strategy {
856 hammer2_xop_head_t head;
857 hammer2_key_t lbase;
858 int finished;
859 struct bio *bio;
860};
861
c847e838
MD
862struct hammer2_xop_readdir {
863 hammer2_xop_head_t head;
864};
865
c603b86b
MD
866struct hammer2_xop_nresolve {
867 hammer2_xop_head_t head;
c603b86b
MD
868};
869
e12ae3a5
MD
870struct hammer2_xop_nlink {
871 hammer2_xop_head_t head;
872};
873
874struct hammer2_xop_unlink {
875 hammer2_xop_head_t head;
876 int isdir;
877 int dopermanent;
878};
879
880struct hammer2_xop_nrename {
881 hammer2_xop_head_t head;
882 hammer2_tid_t lhc;
883 int ip_key;
884};
885
c603b86b
MD
886struct hammer2_xop_scanlhc {
887 hammer2_xop_head_t head;
888 hammer2_key_t lhc;
889};
890
891struct hammer2_xop_create {
892 hammer2_xop_head_t head;
893 hammer2_inode_meta_t meta; /* initial metadata */
894 hammer2_key_t lhc;
895 int flags;
c603b86b
MD
896};
897
e12ae3a5
MD
898struct hammer2_xop_connect {
899 hammer2_xop_head_t head;
900 hammer2_key_t lhc;
901};
902
c603b86b
MD
903struct hammer2_xop_destroy {
904 hammer2_xop_head_t head;
905 hammer2_key_t lhc;
906 int flags;
907};
908
12ff971c
MD
909struct hammer2_xop_flush {
910 hammer2_xop_head_t head;
911};
912
c847e838 913typedef struct hammer2_xop_readdir hammer2_xop_readdir_t;
c603b86b 914typedef struct hammer2_xop_nresolve hammer2_xop_nresolve_t;
e12ae3a5
MD
915typedef struct hammer2_xop_nlink hammer2_xop_nlink_t;
916typedef struct hammer2_xop_unlink hammer2_xop_unlink_t;
917typedef struct hammer2_xop_nrename hammer2_xop_nrename_t;
c603b86b
MD
918typedef struct hammer2_xop_strategy hammer2_xop_strategy_t;
919typedef struct hammer2_xop_create hammer2_xop_create_t;
920typedef struct hammer2_xop_destroy hammer2_xop_destroy_t;
921typedef struct hammer2_xop_scanlhc hammer2_xop_scanlhc_t;
e12ae3a5 922typedef struct hammer2_xop_connect hammer2_xop_connect_t;
12ff971c 923typedef struct hammer2_xop_flush hammer2_xop_flush_t;
c847e838
MD
924
925union hammer2_xop {
926 hammer2_xop_head_t head;
927 hammer2_xop_readdir_t xop_readdir;
c603b86b 928 hammer2_xop_nresolve_t xop_nresolve;
e12ae3a5
MD
929 hammer2_xop_nlink_t xop_nlink;
930 hammer2_xop_unlink_t xop_unlink;
931 hammer2_xop_nrename_t xop_nrename;
c603b86b
MD
932 hammer2_xop_strategy_t xop_strategy;
933 hammer2_xop_create_t xop_create;
934 hammer2_xop_destroy_t xop_destroy;
935 hammer2_xop_scanlhc_t xop_scanlhc;
12ff971c 936 hammer2_xop_flush_t xop_flush;
e12ae3a5 937 hammer2_xop_connect_t xop_connect;
c847e838 938};
2ed4fece 939
c847e838 940typedef union hammer2_xop hammer2_xop_t;
8db69c9f 941
2ed4fece
MD
942/*
943 * hammer2_xop_group - Manage XOP support threads.
944 */
945struct hammer2_xop_group {
946 hammer2_thread_t thrs[HAMMER2_MAXCLUSTER];
947 hammer2_mtx_t mtx;
c603b86b 948 hammer2_mtx_t mtx2;
2ed4fece 949};
8db69c9f 950
2ed4fece 951typedef struct hammer2_xop_group hammer2_xop_group_t;
8db69c9f 952
c603b86b
MD
953/*
954 * flags to hammer2_xop_collect()
955 */
956#define HAMMER2_XOP_COLLECT_NOWAIT 0x00000001
12ff971c 957#define HAMMER2_XOP_COLLECT_WAITALL 0x00000002
c603b86b
MD
958
959/*
960 * flags to hammer2_xop_alloc()
961 *
962 * TRANS - The frontend is in a transaction, backend operations
963 * will do per-node transactions.
964 */
965#define HAMMER2_XOP_TRANS 0x00000001
966
50456506 967/*
506bd6d1
MD
968 * Global (per partition) management structure, represents a hard block
969 * device. Typically referenced by hammer2_chain structures when applicable.
970 * Typically not used for network-managed elements.
971 *
972 * Note that a single hammer2_dev can be indirectly tied to multiple system
973 * mount points. There is no direct relationship. System mounts are
974 * per-cluster-id, not per-block-device, and a single hard mount might contain
975 * many PFSs and those PFSs might combine together in various ways to form
976 * the set of available clusters.
50456506 977 */
506bd6d1 978struct hammer2_dev {
50e4f8f4 979 struct vnode *devvp; /* device vnode */
50e4f8f4 980 int ronly; /* read-only mount */
f7712c43 981 int mount_count; /* number of actively mounted PFSs */
506bd6d1 982 TAILQ_ENTRY(hammer2_dev) mntentry; /* hammer2_mntlist */
703720e4 983
5c23d7f1 984 struct malloc_type *mchain;
54eb943b
MD
985 int nipstacks;
986 int maxipstacks;
063639ba 987 kdmsg_iocom_t iocom; /* volume-level dmsg interface */
fdf62707
MD
988 struct spinlock io_spin; /* iotree access */
989 struct hammer2_io_tree iotree;
990 int iofree_count;
7bed8d7e
MD
991 hammer2_chain_t vchain; /* anchor chain (topology) */
992 hammer2_chain_t fchain; /* anchor chain (freemap) */
da6f36f4
MD
993 struct spinlock list_spin;
994 struct h2_flush_list flushq; /* flush seeds */
506bd6d1 995 struct hammer2_pfs *spmp; /* super-root pmp for transactions */
50456506 996 struct lock vollk; /* lockmgr lock */
91abd410 997 hammer2_off_t heur_freemap[HAMMER2_FREEMAP_HEUR];
3fc4c63d 998 int volhdrno; /* last volhdrno written */
e513e77e 999 char devrepname[64]; /* for kprintf */
54eb943b 1000 hammer2_volume_data_t voldata;
3fc4c63d 1001 hammer2_volume_data_t volsync; /* synchronized voldata */
703720e4
MD
1002};
1003
506bd6d1 1004typedef struct hammer2_dev hammer2_dev_t;
54eb943b 1005
23c7c7dd
MD
1006/*
1007 * Helper functions (cluster must be locked for flags to be valid).
1008 */
1009static __inline
1010int
1011hammer2_chain_rdok(hammer2_chain_t *chain)
1012{
1013 return (chain->error == 0);
1014}
1015
1016static __inline
1017int
1018hammer2_chain_wrok(hammer2_chain_t *chain)
1019{
1020 return (chain->error == 0 && chain->hmp->ronly == 0);
1021}
1022
e4e20f48 1023/*
506bd6d1
MD
1024 * Per-cluster management structure. This structure will be tied to a
1025 * system mount point if the system is mounting the PFS, but is also used
1026 * to manage clusters encountered during the super-root scan or received
1027 * via LNK_SPANs that might not be mounted.
7750fd72 1028 *
506bd6d1
MD
1029 * This structure is also used to represent the super-root that hangs off
1030 * of a hard mount point. The super-root is not really a cluster element.
1031 * In this case the spmp_hmp field will be non-NULL. It's just easier to do
1032 * this than to special case super-root manipulation in the hammer2_chain*
1033 * code as being only hammer2_dev-related.
7750fd72 1034 *
506bd6d1
MD
1035 * pfs_mode and pfs_nmasters are rollup fields which critically describes
1036 * how elements of the cluster act on the cluster. pfs_mode is only applicable
1037 * when a PFS is mounted by the system. pfs_nmasters is our best guess as to
1038 * how many masters have been configured for a cluster and is always
22211834
MD
1039 * applicable. pfs_types[] is an array with 1:1 correspondance to the
1040 * iroot cluster and describes the PFS types of the nodes making up the
1041 * cluster.
7750fd72 1042 *
506bd6d1
MD
1043 * WARNING! Portions of this structure have deferred initialization. In
1044 * particular, if not mounted there will be no ihidden or wthread.
1045 * umounted network PFSs will also be missing iroot and numerous
1046 * other fields will not be initialized prior to mount.
7750fd72 1047 *
506bd6d1
MD
1048 * Synchronization threads are chain-specific and only applicable
1049 * to local hard PFS entries. A hammer2_pfs structure may contain
1050 * more than one when multiple hard PFSs are present on the local
1051 * machine which require synchronization monitoring. Most PFSs
1052 * (such as snapshots) are 1xMASTER PFSs which do not need a
1053 * synchronization thread.
7750fd72 1054 *
506bd6d1 1055 * WARNING! The chains making up pfs->iroot's cluster are accounted for in
f7712c43 1056 * hammer2_dev->mount_count when the pfs is associated with a mount
506bd6d1 1057 * point.
e4e20f48 1058 */
506bd6d1 1059struct hammer2_pfs {
7bed8d7e 1060 struct mount *mp;
506bd6d1 1061 TAILQ_ENTRY(hammer2_pfs) mntentry; /* hammer2_pfslist */
58e43599 1062 uuid_t pfs_clid;
506bd6d1 1063 hammer2_dev_t *spmp_hmp; /* only if super-root pmp */
e4e20f48 1064 hammer2_inode_t *iroot; /* PFS root inode */
044541cd 1065 hammer2_inode_t *ihidden; /* PFS hidden directory */
22211834 1066 uint8_t pfs_types[HAMMER2_MAXCLUSTER];
c7916d0b 1067 char *pfs_names[HAMMER2_MAXCLUSTER];
c603b86b 1068 hammer2_trans_t trans;
044541cd 1069 struct lock lock; /* PFS lock for certain ops */
e4e20f48
MD
1070 struct netexport export; /* nfs export */
1071 int ronly; /* read-only mount */
99da41ea 1072 struct malloc_type *minode;
3a5aa68f 1073 struct malloc_type *mmsg;
9797e933 1074 struct spinlock inum_spin; /* inumber lookup */
50456506 1075 struct hammer2_inode_tree inum_tree; /* (not applicable to spmp) */
e513e77e
MD
1076 hammer2_tid_t modify_tid; /* modify transaction id */
1077 hammer2_tid_t inode_tid; /* inode allocator */
7750fd72
MD
1078 uint8_t pfs_nmasters; /* total masters */
1079 uint8_t pfs_mode; /* operating mode PFSMODE */
1080 uint8_t unused01;
1081 uint8_t unused02;
c847e838 1082 int xop_iterator;
355d67fc 1083 long inmem_inodes;
da6f36f4 1084 uint32_t inmem_dirty_chains;
3f5b8b3b 1085 int count_lwinprog; /* logical write in prog */
da6f36f4
MD
1086 struct spinlock list_spin;
1087 struct h2_unlk_list unlinkq; /* last-close unlink */
2ed4fece 1088 hammer2_thread_t sync_thrs[HAMMER2_MAXCLUSTER];
8db69c9f 1089 uint32_t flags; /* cached cluster flags */
2ed4fece 1090 hammer2_xop_group_t xop_groups[HAMMER2_XOPGROUPS];
e4e20f48
MD
1091};
1092
506bd6d1 1093typedef struct hammer2_pfs hammer2_pfs_t;
e4e20f48 1094
0924b3f8
MD
1095#define HAMMER2_DIRTYCHAIN_WAITING 0x80000000
1096#define HAMMER2_DIRTYCHAIN_MASK 0x7FFFFFFF
1097
3f5b8b3b 1098#define HAMMER2_LWINPROG_WAITING 0x80000000
d34788ef
MD
1099#define HAMMER2_LWINPROG_WAITING0 0x40000000
1100#define HAMMER2_LWINPROG_MASK 0x3FFFFFFF
3f5b8b3b 1101
c847e838
MD
1102/*
1103 * hammer2_cluster_check
1104 */
1105#define HAMMER2_CHECK_NULL 0x00000001
1106
3148f677
MD
1107/*
1108 * Bulkscan
1109 */
1110#define HAMMER2_BULK_ABORT 0x00000001
1111
1112/*
1113 * Misc
1114 */
703720e4
MD
1115#if defined(_KERNEL)
1116
1117MALLOC_DECLARE(M_HAMMER2);
1118
e4e20f48
MD
1119#define VTOI(vp) ((hammer2_inode_t *)(vp)->v_data)
1120#define ITOV(ip) ((ip)->vp)
1121
91abd410
MD
1122/*
1123 * Currently locked chains retain the locked buffer cache buffer for
1124 * indirect blocks, and indirect blocks can be one of two sizes. The
1125 * device buffer has to match the case to avoid deadlocking recursive
1126 * chains that might otherwise try to access different offsets within
1127 * the same device buffer.
1128 */
a98aa0b0
MD
1129static __inline
1130int
1131hammer2_devblkradix(int radix)
1132{
f89b6495 1133#if 0
91abd410
MD
1134 if (radix <= HAMMER2_LBUFRADIX) {
1135 return (HAMMER2_LBUFRADIX);
1136 } else {
1137 return (HAMMER2_PBUFRADIX);
1138 }
f89b6495
MD
1139#endif
1140 return (HAMMER2_PBUFRADIX);
a98aa0b0
MD
1141}
1142
71008001
MD
1143/*
1144 * XXX almost time to remove this. DIO uses PBUFSIZE exclusively now.
1145 */
a98aa0b0
MD
1146static __inline
1147size_t
1148hammer2_devblksize(size_t bytes)
1149{
71008001 1150#if 0
a5913bdf 1151 if (bytes <= HAMMER2_LBUFSIZE) {
a98aa0b0 1152 return(HAMMER2_LBUFSIZE);
a5913bdf
MD
1153 } else {
1154 KKASSERT(bytes <= HAMMER2_PBUFSIZE &&
1155 (bytes ^ (bytes - 1)) == ((bytes << 1) - 1));
91abd410 1156 return (HAMMER2_PBUFSIZE);
a5913bdf 1157 }
71008001
MD
1158#endif
1159 return (HAMMER2_PBUFSIZE);
a98aa0b0
MD
1160}
1161
1162
e118c14f 1163static __inline
506bd6d1 1164hammer2_pfs_t *
e4e20f48 1165MPTOPMP(struct mount *mp)
703720e4 1166{
506bd6d1 1167 return ((hammer2_pfs_t *)mp->mnt_data);
703720e4
MD
1168}
1169
05dd26e4
MD
1170#define LOCKSTART int __nlocks = curthread->td_locks
1171#define LOCKENTER (++curthread->td_locks)
1172#define LOCKEXIT (--curthread->td_locks)
1173#define LOCKSTOP KKASSERT(curthread->td_locks == __nlocks)
1174
703720e4
MD
1175extern struct vop_ops hammer2_vnode_vops;
1176extern struct vop_ops hammer2_spec_vops;
1177extern struct vop_ops hammer2_fifo_vops;
1178
37aa19df 1179extern int hammer2_debug;
01eabad4 1180extern int hammer2_cluster_enable;
e708f8b9 1181extern int hammer2_hardlink_enable;
3f5b8b3b 1182extern int hammer2_flush_pipe;
8138a154 1183extern int hammer2_synchronous_flush;
837bd39b 1184extern int hammer2_dio_count;
0924b3f8 1185extern long hammer2_limit_dirty_chains;
01eabad4
MD
1186extern long hammer2_iod_file_read;
1187extern long hammer2_iod_meta_read;
1188extern long hammer2_iod_indr_read;
a98aa0b0
MD
1189extern long hammer2_iod_fmap_read;
1190extern long hammer2_iod_volu_read;
01eabad4
MD
1191extern long hammer2_iod_file_write;
1192extern long hammer2_iod_meta_write;
1193extern long hammer2_iod_indr_write;
9061bde5 1194extern long hammer2_iod_fmap_write;
01eabad4
MD
1195extern long hammer2_iod_volu_write;
1196extern long hammer2_ioa_file_read;
1197extern long hammer2_ioa_meta_read;
1198extern long hammer2_ioa_indr_read;
a98aa0b0
MD
1199extern long hammer2_ioa_fmap_read;
1200extern long hammer2_ioa_volu_read;
01eabad4
MD
1201extern long hammer2_ioa_file_write;
1202extern long hammer2_ioa_meta_write;
1203extern long hammer2_ioa_indr_write;
9061bde5 1204extern long hammer2_ioa_fmap_write;
01eabad4 1205extern long hammer2_ioa_volu_write;
37aa19df 1206
355d67fc
MD
1207extern struct objcache *cache_buffer_read;
1208extern struct objcache *cache_buffer_write;
2ed4fece 1209extern struct objcache *cache_xops;
355d67fc 1210
7cfa8da5
MD
1211/*
1212 * hammer2_subr.c
1213 */
3a5aa68f
MD
1214#define hammer2_icrc32(buf, size) iscsi_crc32((buf), (size))
1215#define hammer2_icrc32c(buf, size, crc) iscsi_crc32_ext((buf), (size), (crc))
0c3a8cd0 1216
d662271e 1217int hammer2_signal_check(time_t *timep);
b93cc2e0
MD
1218const char *hammer2_error_str(int error);
1219
159c3ca2 1220void hammer2_inode_lock(hammer2_inode_t *ip, int how);
b93cc2e0 1221void hammer2_inode_unlock(hammer2_inode_t *ip, hammer2_cluster_t *cluster);
159c3ca2 1222hammer2_cluster_t *hammer2_inode_cluster(hammer2_inode_t *ip, int how);
c847e838 1223hammer2_chain_t *hammer2_inode_chain(hammer2_inode_t *ip, int clindex, int how);
94491fa0
MD
1224hammer2_mtx_state_t hammer2_inode_lock_temp_release(hammer2_inode_t *ip);
1225void hammer2_inode_lock_temp_restore(hammer2_inode_t *ip,
1226 hammer2_mtx_state_t ostate);
1227int hammer2_inode_lock_upgrade(hammer2_inode_t *ip);
1228void hammer2_inode_lock_downgrade(hammer2_inode_t *ip, int);
e118c14f 1229
506bd6d1
MD
1230void hammer2_dev_exlock(hammer2_dev_t *hmp);
1231void hammer2_dev_shlock(hammer2_dev_t *hmp);
1232void hammer2_dev_unlock(hammer2_dev_t *hmp);
703720e4 1233
6a5f4fe6 1234int hammer2_get_dtype(const hammer2_inode_data_t *ipdata);
159c3ca2 1235int hammer2_get_vtype(uint8_t type);
37494cab 1236u_int8_t hammer2_get_obj_type(enum vtype vtype);
cd4b3d92 1237void hammer2_time_to_timespec(u_int64_t xtime, struct timespec *ts);
6a5f4fe6
MD
1238u_int64_t hammer2_timespec_to_time(const struct timespec *ts);
1239u_int32_t hammer2_to_unix_xid(const uuid_t *uuid);
b2b78aaa 1240void hammer2_guid_to_uuid(uuid_t *uuid, u_int32_t guid);
c603b86b 1241void hammer2_trans_manage_init(hammer2_pfs_t *pmp);
e028fa74 1242
7cfa8da5 1243hammer2_key_t hammer2_dirhash(const unsigned char *name, size_t len);
1a7cfe5a 1244int hammer2_getradix(size_t bytes);
7cfa8da5 1245
8cce658d 1246int hammer2_calc_logical(hammer2_inode_t *ip, hammer2_off_t uoff,
1897c66e 1247 hammer2_key_t *lbasep, hammer2_key_t *leofp);
7a9b14a0 1248int hammer2_calc_physical(hammer2_inode_t *ip, hammer2_key_t lbase);
b2b78aaa 1249void hammer2_update_time(uint64_t *timep);
278ab2b2 1250void hammer2_adjreadcounter(hammer2_blockref_t *bref, size_t bytes);
8cce658d 1251
7cfa8da5
MD
1252/*
1253 * hammer2_inode.c
1254 */
c603b86b 1255struct vnode *hammer2_igetv(hammer2_inode_t *ip, int *errorp);
506bd6d1 1256hammer2_inode_t *hammer2_inode_lookup(hammer2_pfs_t *pmp,
9797e933 1257 hammer2_tid_t inum);
506bd6d1 1258hammer2_inode_t *hammer2_inode_get(hammer2_pfs_t *pmp,
278ab2b2 1259 hammer2_inode_t *dip, hammer2_cluster_t *cluster);
7cfa8da5
MD
1260void hammer2_inode_free(hammer2_inode_t *ip);
1261void hammer2_inode_ref(hammer2_inode_t *ip);
1262void hammer2_inode_drop(hammer2_inode_t *ip);
ea155208 1263void hammer2_inode_repoint(hammer2_inode_t *ip, hammer2_inode_t *pip,
278ab2b2 1264 hammer2_cluster_t *cluster);
a6cf1052
MD
1265void hammer2_inode_repoint_one(hammer2_inode_t *ip, hammer2_cluster_t *cluster,
1266 int idx);
c603b86b
MD
1267void hammer2_inode_modify(hammer2_inode_t *ip);
1268void hammer2_run_unlinkq(hammer2_pfs_t *pmp);
6934ae32 1269
c603b86b 1270hammer2_inode_t *hammer2_inode_create(hammer2_inode_t *dip,
e708f8b9
MD
1271 struct vattr *vap, struct ucred *cred,
1272 const uint8_t *name, size_t name_len,
e12ae3a5 1273 hammer2_key_t inum, uint8_t type, uint8_t target_type,
506bd6d1 1274 int flags, int *errorp);
e12ae3a5
MD
1275int hammer2_inode_connect_simple(hammer2_inode_t *dip, hammer2_inode_t *ip,
1276 const char *name, size_t name_len,
1277 hammer2_key_t lhc);
0dea3156
MD
1278hammer2_inode_t *hammer2_inode_common_parent(hammer2_inode_t *fdip,
1279 hammer2_inode_t *tdip);
c603b86b 1280void hammer2_inode_fsync(hammer2_inode_t *ip, hammer2_cluster_t *cparent);
e12ae3a5 1281int hammer2_inode_unlink_finisher(hammer2_inode_t *ip, int isopen);
da6f36f4
MD
1282int hammer2_parent_find(hammer2_cluster_t **cparentp,
1283 hammer2_cluster_t *cluster);
506bd6d1 1284void hammer2_inode_install_hidden(hammer2_pfs_t *pmp);
ae183399 1285
7cfa8da5
MD
1286/*
1287 * hammer2_chain.c
1288 */
506bd6d1
MD
1289void hammer2_voldata_lock(hammer2_dev_t *hmp);
1290void hammer2_voldata_unlock(hammer2_dev_t *hmp);
1291void hammer2_voldata_modify(hammer2_dev_t *hmp);
1292hammer2_chain_t *hammer2_chain_alloc(hammer2_dev_t *hmp,
1293 hammer2_pfs_t *pmp,
fdf62707 1294 hammer2_blockref_t *bref);
23c7c7dd 1295void hammer2_chain_core_init(hammer2_chain_t *chain);
0dea3156
MD
1296void hammer2_chain_ref(hammer2_chain_t *chain);
1297void hammer2_chain_drop(hammer2_chain_t *chain);
23c7c7dd 1298void hammer2_chain_lock(hammer2_chain_t *chain, int how);
f1c7c224 1299void hammer2_chain_load_data(hammer2_chain_t *chain);
bca9f8e6
MD
1300const hammer2_media_data_t *hammer2_chain_rdata(hammer2_chain_t *chain);
1301hammer2_media_data_t *hammer2_chain_wdata(hammer2_chain_t *chain);
1302
c603b86b
MD
1303int hammer2_chain_hardlink_find(hammer2_inode_t *dip,
1304 hammer2_chain_t **parentp,
e12ae3a5
MD
1305 hammer2_chain_t **chainp,
1306 int flags);
c603b86b 1307
71008001
MD
1308/*
1309 * hammer2_cluster.c
1310 */
bca9f8e6
MD
1311void hammer2_cluster_load_async(hammer2_cluster_t *cluster,
1312 void (*callback)(hammer2_iocb_t *iocb),
1313 void *ptr);
0dea3156 1314void hammer2_chain_moved(hammer2_chain_t *chain);
c603b86b 1315void hammer2_chain_modify(hammer2_chain_t *chain, int flags);
d34788ef
MD
1316void hammer2_chain_modify_ip(hammer2_inode_t *ip, hammer2_chain_t *chain,
1317 int flags);
c603b86b
MD
1318void hammer2_chain_resize(hammer2_inode_t *ip, hammer2_chain_t *parent,
1319 hammer2_chain_t *chain, int nradix, int flags);
0dea3156
MD
1320void hammer2_chain_unlock(hammer2_chain_t *chain);
1321void hammer2_chain_wait(hammer2_chain_t *chain);
8138a154
MD
1322hammer2_chain_t *hammer2_chain_get(hammer2_chain_t *parent, int generation,
1323 hammer2_blockref_t *bref);
0dea3156
MD
1324hammer2_chain_t *hammer2_chain_lookup_init(hammer2_chain_t *parent, int flags);
1325void hammer2_chain_lookup_done(hammer2_chain_t *parent);
e12ae3a5 1326hammer2_chain_t *hammer2_chain_getparent(hammer2_chain_t **parentp, int how);
0dea3156 1327hammer2_chain_t *hammer2_chain_lookup(hammer2_chain_t **parentp,
1897c66e 1328 hammer2_key_t *key_nextp,
c667909f 1329 hammer2_key_t key_beg, hammer2_key_t key_end,
b8ba9690 1330 int *cache_indexp, int flags);
0dea3156 1331hammer2_chain_t *hammer2_chain_next(hammer2_chain_t **parentp,
5c23d7f1 1332 hammer2_chain_t *chain,
1897c66e 1333 hammer2_key_t *key_nextp,
c667909f 1334 hammer2_key_t key_beg, hammer2_key_t key_end,
1897c66e 1335 int *cache_indexp, int flags);
10136ab6
MD
1336hammer2_chain_t *hammer2_chain_scan(hammer2_chain_t *parent,
1337 hammer2_chain_t *chain,
1338 int *cache_indexp, int flags);
91abd410 1339
c603b86b 1340int hammer2_chain_create(hammer2_chain_t **parentp,
0dea3156 1341 hammer2_chain_t **chainp,
506bd6d1 1342 hammer2_pfs_t *pmp,
5c23d7f1 1343 hammer2_key_t key, int keybits,
b3659de2 1344 int type, size_t bytes, int flags);
c603b86b 1345void hammer2_chain_rename(hammer2_blockref_t *bref,
da6f36f4 1346 hammer2_chain_t **parentp,
b3659de2 1347 hammer2_chain_t *chain, int flags);
c603b86b 1348int hammer2_chain_snapshot(hammer2_chain_t **chainp,
c847e838 1349 hammer2_ioc_pfs_t *pmp);
c603b86b 1350void hammer2_chain_delete(hammer2_chain_t *parent,
da6f36f4 1351 hammer2_chain_t *chain, int flags);
c603b86b
MD
1352void hammer2_flush(hammer2_chain_t *chain, int istop);
1353void hammer2_delayed_flush(hammer2_chain_t *chain);
1354void hammer2_chain_setflush(hammer2_chain_t *chain);
51a0d27c 1355void hammer2_chain_countbrefs(hammer2_chain_t *chain,
1897c66e 1356 hammer2_blockref_t *base, int count);
1897c66e 1357
a71db85d
MD
1358void hammer2_chain_setcheck(hammer2_chain_t *chain, void *bdata);
1359int hammer2_chain_testcheck(hammer2_chain_t *chain, void *bdata);
1360
1361
506bd6d1
MD
1362void hammer2_pfs_memory_wait(hammer2_pfs_t *pmp);
1363void hammer2_pfs_memory_inc(hammer2_pfs_t *pmp);
1364void hammer2_pfs_memory_wakeup(hammer2_pfs_t *pmp);
278ab2b2 1365
c603b86b 1366void hammer2_base_delete(hammer2_chain_t *chain,
51a0d27c 1367 hammer2_blockref_t *base, int count,
a7720be7 1368 int *cache_indexp, hammer2_chain_t *child);
c603b86b 1369void hammer2_base_insert(hammer2_chain_t *chain,
51a0d27c 1370 hammer2_blockref_t *base, int count,
a7720be7 1371 int *cache_indexp, hammer2_chain_t *child);
0dea3156
MD
1372
1373/*
1374 * hammer2_trans.c
1375 */
c603b86b
MD
1376void hammer2_trans_init(hammer2_pfs_t *pmp, uint32_t flags);
1377void hammer2_trans_done(hammer2_pfs_t *pmp);
1378hammer2_tid_t hammer2_trans_newinum(hammer2_pfs_t *pmp);
c7916d0b 1379void hammer2_trans_assert_strategy(hammer2_pfs_t *pmp);
50e4f8f4 1380
2910a90c
MD
1381/*
1382 * hammer2_ioctl.c
1383 */
1384int hammer2_ioctl(hammer2_inode_t *ip, u_long com, void *data,
1385 int fflag, struct ucred *cred);
1386
fdf62707
MD
1387/*
1388 * hammer2_io.c
1389 */
fdf62707 1390void hammer2_io_putblk(hammer2_io_t **diop);
506bd6d1 1391void hammer2_io_cleanup(hammer2_dev_t *hmp, struct hammer2_io_tree *tree);
fdf62707 1392char *hammer2_io_data(hammer2_io_t *dio, off_t lbase);
506bd6d1 1393void hammer2_io_getblk(hammer2_dev_t *hmp, off_t lbase, int lsize,
bca9f8e6
MD
1394 hammer2_iocb_t *iocb);
1395void hammer2_io_complete(hammer2_iocb_t *iocb);
1396void hammer2_io_callback(struct bio *bio);
1397void hammer2_iocb_wait(hammer2_iocb_t *iocb);
506bd6d1 1398int hammer2_io_new(hammer2_dev_t *hmp, off_t lbase, int lsize,
fdf62707 1399 hammer2_io_t **diop);
506bd6d1 1400int hammer2_io_newnz(hammer2_dev_t *hmp, off_t lbase, int lsize,
fdf62707 1401 hammer2_io_t **diop);
506bd6d1 1402int hammer2_io_newq(hammer2_dev_t *hmp, off_t lbase, int lsize,
fdf62707 1403 hammer2_io_t **diop);
506bd6d1 1404int hammer2_io_bread(hammer2_dev_t *hmp, off_t lbase, int lsize,
fdf62707 1405 hammer2_io_t **diop);
fdf62707
MD
1406void hammer2_io_bawrite(hammer2_io_t **diop);
1407void hammer2_io_bdwrite(hammer2_io_t **diop);
1408int hammer2_io_bwrite(hammer2_io_t **diop);
8138a154 1409int hammer2_io_isdirty(hammer2_io_t *dio);
fdf62707
MD
1410void hammer2_io_setdirty(hammer2_io_t *dio);
1411void hammer2_io_setinval(hammer2_io_t *dio, u_int bytes);
1412void hammer2_io_brelse(hammer2_io_t **diop);
1413void hammer2_io_bqrelse(hammer2_io_t **diop);
fdf62707 1414
2ed4fece
MD
1415/*
1416 * hammer2_xops.c
1417 */
c847e838 1418void hammer2_xop_group_init(hammer2_pfs_t *pmp, hammer2_xop_group_t *xgrp);
c603b86b 1419hammer2_xop_t *hammer2_xop_alloc(hammer2_inode_t *ip);
e12ae3a5
MD
1420void hammer2_xop_setname(hammer2_xop_head_t *xop,
1421 const char *name, size_t name_len);
1422void hammer2_xop_setname2(hammer2_xop_head_t *xop,
1423 const char *name, size_t name_len);
1424void hammer2_xop_setip2(hammer2_xop_head_t *xop, hammer2_inode_t *ip2);
1425void hammer2_xop_setip3(hammer2_xop_head_t *xop, hammer2_inode_t *ip3);
c603b86b 1426void hammer2_xop_reinit(hammer2_xop_head_t *xop);
c847e838
MD
1427void hammer2_xop_helper_create(hammer2_pfs_t *pmp);
1428void hammer2_xop_helper_cleanup(hammer2_pfs_t *pmp);
c603b86b
MD
1429void hammer2_xop_start(hammer2_xop_head_t *xop, hammer2_xop_func_t func);
1430int hammer2_xop_collect(hammer2_xop_head_t *xop, int flags);
c847e838
MD
1431void hammer2_xop_retire(hammer2_xop_head_t *xop, uint32_t mask);
1432int hammer2_xop_active(hammer2_xop_head_t *xop);
1433int hammer2_xop_feed(hammer2_xop_head_t *xop, hammer2_chain_t *chain,
1434 int clindex, int error);
1435
1436
1437void hammer2_xop_readdir(hammer2_xop_t *xop, int clidx);
c603b86b 1438void hammer2_xop_nresolve(hammer2_xop_t *xop, int clidx);
e12ae3a5
MD
1439void hammer2_xop_unlink(hammer2_xop_t *xop, int clidx);
1440void hammer2_xop_nrename(hammer2_xop_t *xop, int clidx);
1441void hammer2_xop_nlink(hammer2_xop_t *xop, int clidx);
c603b86b
MD
1442void hammer2_inode_xop_scanlhc(hammer2_xop_t *xop, int clidx);
1443void hammer2_inode_xop_create(hammer2_xop_t *xop, int clidx);
1444void hammer2_inode_xop_destroy(hammer2_xop_t *xop, int clidx);
e12ae3a5 1445void hammer2_inode_xop_connect(hammer2_xop_t *xop, int clidx);
12ff971c 1446void hammer2_inode_xop_flush(hammer2_xop_t *xop, int clidx);
c603b86b 1447#if 0
2ed4fece
MD
1448int hammer2_xop_nmkdir(struct vop_nmkdir_args *ap);
1449int hammer2_xop_advlock(struct vop_advlock_args *ap);
1450int hammer2_xop_nlink(struct vop_nlink_args *ap);
1451int hammer2_xop_ncreate(struct vop_ncreate_args *ap);
1452int hammer2_xop_nmknod(struct vop_nmknod_args *ap);
1453int hammer2_xop_nsymlink(struct vop_nsymlink_args *ap);
1454int hammer2_xop_nremove(struct vop_nremove_args *ap);
1455int hammer2_xop_nrmdir(struct vop_nrmdir_args *ap);
1456int hammer2_xop_nrename(struct vop_nrename_args *ap);
c603b86b 1457#endif
2ed4fece 1458
9b8b748f
MD
1459/*
1460 * hammer2_msgops.c
1461 */
3a5aa68f
MD
1462int hammer2_msg_dbg_rcvmsg(kdmsg_msg_t *msg);
1463int hammer2_msg_adhoc_input(kdmsg_msg_t *msg);
26bf1a36 1464
1a34728c
MD
1465/*
1466 * hammer2_vfsops.c
1467 */
3a5aa68f 1468void hammer2_clusterctl_wakeup(kdmsg_iocom_t *iocom);
506bd6d1 1469void hammer2_volconf_update(hammer2_dev_t *hmp, int index);
8138a154 1470void hammer2_dump_chain(hammer2_chain_t *chain, int tab, int *countp, char pfx);
a7720be7 1471int hammer2_vfs_sync(struct mount *mp, int waitflags);
506bd6d1
MD
1472hammer2_pfs_t *hammer2_pfsalloc(hammer2_cluster_t *cluster,
1473 const hammer2_inode_data_t *ripdata,
e513e77e 1474 hammer2_tid_t modify_tid);
506bd6d1
MD
1475
1476void hammer2_lwinprog_ref(hammer2_pfs_t *pmp);
1477void hammer2_lwinprog_drop(hammer2_pfs_t *pmp);
d34788ef 1478void hammer2_lwinprog_wait(hammer2_pfs_t *pmp, int pipe);
1a34728c 1479
df9ea374
MD
1480/*
1481 * hammer2_freemap.c
1482 */
c603b86b
MD
1483int hammer2_freemap_alloc(hammer2_chain_t *chain, size_t bytes);
1484void hammer2_freemap_adjust(hammer2_dev_t *hmp,
91abd410
MD
1485 hammer2_blockref_t *bref, int how);
1486
278ab2b2
MD
1487/*
1488 * hammer2_cluster.c
1489 */
05dd26e4 1490int hammer2_cluster_need_resize(hammer2_cluster_t *cluster, int bytes);
278ab2b2 1491uint8_t hammer2_cluster_type(hammer2_cluster_t *cluster);
bca9f8e6 1492const hammer2_media_data_t *hammer2_cluster_rdata(hammer2_cluster_t *cluster);
c847e838
MD
1493const hammer2_media_data_t *hammer2_cluster_rdata_bytes(
1494 hammer2_cluster_t *cluster, size_t *bytesp);
6a5f4fe6 1495hammer2_media_data_t *hammer2_cluster_wdata(hammer2_cluster_t *cluster);
278ab2b2
MD
1496hammer2_cluster_t *hammer2_cluster_from_chain(hammer2_chain_t *chain);
1497int hammer2_cluster_modified(hammer2_cluster_t *cluster);
278ab2b2 1498int hammer2_cluster_duplicated(hammer2_cluster_t *cluster);
278ab2b2 1499void hammer2_cluster_bref(hammer2_cluster_t *cluster, hammer2_blockref_t *bref);
c603b86b
MD
1500void hammer2_cluster_setflush(hammer2_cluster_t *cluster);
1501void hammer2_cluster_setmethod_check(hammer2_cluster_t *cluster,
1502 int check_algo);
506bd6d1 1503hammer2_cluster_t *hammer2_cluster_alloc(hammer2_pfs_t *pmp,
c603b86b 1504 hammer2_blockref_t *bref);
278ab2b2
MD
1505void hammer2_cluster_ref(hammer2_cluster_t *cluster);
1506void hammer2_cluster_drop(hammer2_cluster_t *cluster);
1507void hammer2_cluster_wait(hammer2_cluster_t *cluster);
23c7c7dd 1508void hammer2_cluster_lock(hammer2_cluster_t *cluster, int how);
eedd52a3 1509void hammer2_cluster_lock_except(hammer2_cluster_t *cluster, int idx, int how);
c847e838
MD
1510int hammer2_cluster_check(hammer2_cluster_t *cluster, hammer2_key_t lokey,
1511 int flags);
23c7c7dd 1512void hammer2_cluster_resolve(hammer2_cluster_t *cluster);
0057d3b8 1513void hammer2_cluster_forcegood(hammer2_cluster_t *cluster);
fe73aa5d 1514hammer2_cluster_t *hammer2_cluster_copy(hammer2_cluster_t *ocluster);
278ab2b2 1515void hammer2_cluster_unlock(hammer2_cluster_t *cluster);
eedd52a3 1516void hammer2_cluster_unlock_except(hammer2_cluster_t *cluster, int idx);
c603b86b 1517void hammer2_cluster_resize(hammer2_inode_t *ip,
278ab2b2
MD
1518 hammer2_cluster_t *cparent, hammer2_cluster_t *cluster,
1519 int nradix, int flags);
c603b86b 1520void hammer2_cluster_modify(hammer2_cluster_t *cluster,
278ab2b2 1521 int flags);
c603b86b
MD
1522hammer2_inode_data_t *hammer2_cluster_modify_ip(hammer2_inode_t *ip,
1523 hammer2_cluster_t *cluster, int flags);
6a5f4fe6 1524void hammer2_cluster_modsync(hammer2_cluster_t *cluster);
278ab2b2
MD
1525hammer2_cluster_t *hammer2_cluster_lookup_init(hammer2_cluster_t *cparent,
1526 int flags);
1527void hammer2_cluster_lookup_done(hammer2_cluster_t *cparent);
1528hammer2_cluster_t *hammer2_cluster_lookup(hammer2_cluster_t *cparent,
1529 hammer2_key_t *key_nextp,
1530 hammer2_key_t key_beg, hammer2_key_t key_end,
b8ba9690 1531 int flags);
278ab2b2
MD
1532hammer2_cluster_t *hammer2_cluster_next(hammer2_cluster_t *cparent,
1533 hammer2_cluster_t *cluster,
1534 hammer2_key_t *key_nextp,
1535 hammer2_key_t key_beg, hammer2_key_t key_end,
1536 int flags);
8db69c9f
MD
1537void hammer2_cluster_next_single_chain(hammer2_cluster_t *cparent,
1538 hammer2_cluster_t *cluster,
1539 hammer2_key_t *key_nextp,
1540 hammer2_key_t key_beg,
1541 hammer2_key_t key_end,
1542 int i, int flags);
278ab2b2
MD
1543hammer2_cluster_t *hammer2_cluster_scan(hammer2_cluster_t *cparent,
1544 hammer2_cluster_t *cluster, int flags);
c603b86b 1545int hammer2_cluster_create(hammer2_pfs_t *pmp, hammer2_cluster_t *cparent,
278ab2b2 1546 hammer2_cluster_t **clusterp,
b3659de2
MD
1547 hammer2_key_t key, int keybits,
1548 int type, size_t bytes, int flags);
c603b86b 1549void hammer2_cluster_rename(hammer2_blockref_t *bref,
b3659de2
MD
1550 hammer2_cluster_t *cparent, hammer2_cluster_t *cluster,
1551 int flags);
c603b86b 1552void hammer2_cluster_delete(hammer2_cluster_t *pcluster,
278ab2b2 1553 hammer2_cluster_t *cluster, int flags);
c603b86b
MD
1554int hammer2_cluster_snapshot(hammer2_cluster_t *ocluster,
1555 hammer2_ioc_pfs_t *pmp);
da6f36f4
MD
1556hammer2_cluster_t *hammer2_cluster_parent(hammer2_cluster_t *cluster);
1557
c603b86b 1558int hammer2_bulk_scan(hammer2_chain_t *parent,
3148f677
MD
1559 int (*func)(hammer2_chain_t *chain, void *info),
1560 void *info);
506bd6d1 1561int hammer2_bulkfree_pass(hammer2_dev_t *hmp,
3148f677 1562 struct hammer2_ioc_bulkfree *bfi);
df9ea374 1563
d157d4dc
MD
1564/*
1565 * hammer2_iocom.c
1566 */
506bd6d1
MD
1567void hammer2_iocom_init(hammer2_dev_t *hmp);
1568void hammer2_iocom_uninit(hammer2_dev_t *hmp);
1569void hammer2_cluster_reconnect(hammer2_dev_t *hmp, struct file *fp);
d157d4dc 1570
5ceaaa82 1571/*
2ed4fece 1572 * hammer2_thread.c
5ceaaa82 1573 */
2ed4fece
MD
1574void hammer2_thr_create(hammer2_thread_t *thr, hammer2_pfs_t *pmp,
1575 const char *id, int clindex, int repidx,
1576 void (*func)(void *arg));
1577void hammer2_thr_delete(hammer2_thread_t *thr);
1578void hammer2_thr_remaster(hammer2_thread_t *thr);
1579void hammer2_thr_freeze_async(hammer2_thread_t *thr);
1580void hammer2_thr_freeze(hammer2_thread_t *thr);
1581void hammer2_thr_unfreeze(hammer2_thread_t *thr);
1582void hammer2_primary_sync_thread(void *arg);
1583void hammer2_primary_xops_thread(void *arg);
5ceaaa82 1584
b2900845
MD
1585/*
1586 * hammer2_strategy.c
1587 */
1588int hammer2_vop_strategy(struct vop_strategy_args *ap);
1589int hammer2_vop_bmap(struct vop_bmap_args *ap);
3c8b994d 1590void hammer2_write_thread(void *arg);
2ed4fece 1591void hammer2_bioq_sync(hammer2_pfs_t *pmp);
b2900845 1592
47902fef
VS
1593#endif /* !_KERNEL */
1594#endif /* !_VFS_HAMMER2_HAMMER2_H_ */