1c5f27475707cedfebc2f609567839a043f8e1ca
[dragonfly.git] / sys / vfs / hammer2 / hammer2.h
1 /*
2  * Copyright (c) 2011-2014 The DragonFly Project.  All rights reserved.
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 /*
37  * HAMMER2 IN-MEMORY CACHE OF MEDIA STRUCTURES
38  *
39  * This header file contains structures used internally by the HAMMER2
40  * implementation.  See hammer2_disk.h for on-disk structures.
41  *
42  * There is an in-memory representation of all on-media data structure.
43  * Basically everything is represented by a hammer2_chain structure
44  * in-memory and other higher-level structures map to chains.
45  *
46  * A great deal of data is accessed simply via its buffer cache buffer,
47  * which is mapped for the duration of the chain's lock.  However, because
48  * chains may represent blocks smaller than the 16KB minimum we impose
49  * on buffer cache buffers, we cannot hold related buffer cache buffers
50  * locked for smaller blocks.  In these situations we kmalloc() a copy
51  * of the block.
52  *
53  * When modifications are made to a chain a new filesystem block must be
54  * allocated.  Multiple modifications do not necessarily allocate new
55  * blocks.  However, when a flush occurs a flush synchronization point
56  * is created and any new modifications made after this point will allocate
57  * a new block even if the chain is already in a modified state.
58  *
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.
62  *
63  *                              CORE SHARING
64  *
65  * In order to support concurrent flushes a flush synchronization point
66  * is created represented by a transaction id.  Among other things,
67  * operations may move filesystem objects from one part of the topology
68  * to another (for example, if you rename a file or when indirect blocks
69  * are created or destroyed, and a few other things).  When this occurs
70  * across a flush synchronization point the flusher needs to be able to
71  * recurse down BOTH the 'before' version of the topology and the 'after'
72  * version.
73  *
74  * To facilitate this modifications to chains do what is called a
75  * DELETE-DUPLICATE operation.  Chains are not actually moved in-memory.
76  * Instead the chain we wish to move is deleted and a new chain is created
77  * at the target location in the topology.  ANY SUBCHAINS PLACED UNDER THE
78  * CHAIN BEING MOVED HAVE TO EXIST IN BOTH PLACES.  To make this work
79  * all sub-chains are managed by the hammer2_chain_core structure.  This
80  * structure can be multi-homed, meaning that it can have more than one
81  * chain as its parent.  When a chain is delete-duplicated the chain's core
82  * becomes shared under both the old and new chain.
83  *
84  *                              STALE CHAINS
85  *
86  * When a chain is delete-duplicated the old chain typically becomes stale.
87  * This is detected via the HAMMER2_CHAIN_DUPLICATED flag in chain->flags.
88  * To avoid executing live filesystem operations on stale chains, the inode
89  * locking code will follow stale chains via core->ownerq until it finds
90  * the live chain.  The lock prevents ripups by other threads.  Lookups
91  * must properly order locking operations to prevent other threads from
92  * racing the lookup operation and will also follow stale chains when
93  * required.
94  */
95
96 #ifndef _VFS_HAMMER2_HAMMER2_H_
97 #define _VFS_HAMMER2_HAMMER2_H_
98
99 #include <sys/param.h>
100 #include <sys/types.h>
101 #include <sys/kernel.h>
102 #include <sys/conf.h>
103 #include <sys/systm.h>
104 #include <sys/tree.h>
105 #include <sys/malloc.h>
106 #include <sys/mount.h>
107 #include <sys/vnode.h>
108 #include <sys/proc.h>
109 #include <sys/mountctl.h>
110 #include <sys/priv.h>
111 #include <sys/stat.h>
112 #include <sys/thread.h>
113 #include <sys/globaldata.h>
114 #include <sys/lockf.h>
115 #include <sys/buf.h>
116 #include <sys/queue.h>
117 #include <sys/limits.h>
118 #include <sys/signal2.h>
119 #include <sys/dmsg.h>
120 #include <sys/mutex.h>
121 #include <sys/kern_syscall.h>
122
123 #include <sys/buf2.h>
124 #include <sys/mutex2.h>
125
126 #include "hammer2_disk.h"
127 #include "hammer2_mount.h"
128 #include "hammer2_ioctl.h"
129 #include "hammer2_ccms.h"
130
131 struct hammer2_chain;
132 struct hammer2_cluster;
133 struct hammer2_inode;
134 struct hammer2_mount;
135 struct hammer2_pfsmount;
136 struct hammer2_span;
137 struct hammer2_state;
138 struct hammer2_msg;
139
140 /*
141  * The chain structure tracks a portion of the media topology from the
142  * root (volume) down.  Chains represent volumes, inodes, indirect blocks,
143  * data blocks, and freemap nodes and leafs.
144  *
145  * The chain structure can be multi-homed and its topological recursion
146  * (chain->core) can be shared amongst several chains.  Chain structures
147  * are topologically stable once placed in the in-memory topology (they
148  * don't move around).  Modifications which cross flush synchronization
149  * boundaries, renames, resizing, or any move of the chain to elsewhere
150  * in the topology is accomplished via the DELETE-DUPLICATE mechanism.
151  *
152  * Deletions and delete-duplicates:
153  *
154  *      Any movement of chains within the topology utilize a delete-duplicate
155  *      operation instead of a simple rename.  That is, the chain must be
156  *      deleted from its original location and then duplicated to the new
157  *      location.  A new chain structure is allocated while the old is
158  *      deleted.  Deleted chains are removed from the above chain_core's
159  *      rbtree but remain linked via the shadow topology for flush
160  *      synchronization purposes.
161  *
162  *      delete_bmap is allocated and a bit set if the chain was originally
163  *      loaded via the blockmap.
164  *
165  * Flush synchronization:
166  *
167  *      Flushes must synchronize chains up through the root.  To do this
168  *      the in-memory topology would normally have to be frozen during the
169  *      flush.  To avoid freezing the topology and to allow concurrent
170  *      foreground / flush activity, any new modifications made while a
171  *      flush is in progress retains the original chain in a shadow topology
172  *      that is only visible to the flush code.  Only one flush can be
173  *      running at a time so the shadow hierarchy can be implemented with
174  *      just a few link fields in our in-memory data structures.
175  *
176  * Advantages:
177  *
178  *      (1) Fully coherent snapshots can be taken without requiring
179  *          a pre-flush, resulting in extremely fast (sub-millisecond)
180  *          snapshots.
181  *
182  *      (2) Multiple synchronization points can be in-flight at the same
183  *          time, representing multiple snapshots or flushes.
184  *
185  *      (3) The algorithms needed to keep track of everything are actually
186  *          not that complex.
187  *
188  * Special Considerations:
189  *
190  *      A chain is ref-counted on a per-chain basis, but the chain's lock
191  *      is associated with the shared chain_core and is not per-chain.
192  *
193  *      The power-of-2 nature of the media radix tree ensures that there
194  *      will be no overlaps which straddle edges.
195  */
196 RB_HEAD(hammer2_chain_tree, hammer2_chain);
197 TAILQ_HEAD(h2_flush_deferral_list, hammer2_chain);
198 TAILQ_HEAD(h2_core_list, hammer2_chain);
199
200 #define CHAIN_CORE_DELETE_BMAP_ENTRIES  \
201         (HAMMER2_PBUFSIZE / sizeof(hammer2_blockref_t) / sizeof(uint32_t))
202
203 struct hammer2_chain_core {
204         int             good;
205         struct ccms_cst cst;
206         struct h2_core_list ownerq;       /* all chains sharing this core */
207         struct hammer2_chain_tree rbtree; /* live chains */
208         struct hammer2_chain_tree dbtree; /* bmapped deletions */
209         struct h2_core_list dbq;          /* other deletions */
210         int             live_zero;      /* blockref array opt */
211         u_int           sharecnt;
212         u_int           flags;
213         u_int           live_count;     /* live (not deleted) chains in tree */
214         u_int           chain_count;    /* live + deleted chains under core */
215         int             generation;     /* generation number (inserts only) */
216 };
217
218 typedef struct hammer2_chain_core hammer2_chain_core_t;
219
220 #define HAMMER2_CORE_UNUSED0001         0x0001
221 #define HAMMER2_CORE_COUNTEDBREFS       0x0002
222
223 /*
224  * H2 is a copy-on-write filesystem.  In order to allow chains to allocate
225  * smaller blocks (down to 64-bytes), but improve performance and make
226  * clustered I/O possible using larger block sizes, the kernel buffer cache
227  * is abstracted via the hammer2_io structure.
228  */
229 RB_HEAD(hammer2_io_tree, hammer2_io);
230
231 struct hammer2_io {
232         RB_ENTRY(hammer2_io) rbnode;    /* indexed by device offset */
233         struct spinlock spin;
234         struct hammer2_mount *hmp;
235         struct buf      *bp;
236         struct bio      *bio;
237         off_t           pbase;
238         int             psize;
239         void            (*callback)(struct hammer2_io *dio,
240                                     struct hammer2_cluster *cluster,
241                                     struct hammer2_chain *chain,
242                                     void *arg1, off_t arg2);
243         struct hammer2_cluster *arg_l;          /* INPROG I/O only */
244         struct hammer2_chain *arg_c;            /* INPROG I/O only */
245         void            *arg_p;                 /* INPROG I/O only */
246         off_t           arg_o;                  /* INPROG I/O only */
247         int             refs;
248         int             act;                    /* activity */
249 };
250
251 typedef struct hammer2_io hammer2_io_t;
252
253 /*
254  * Primary chain structure keeps track of the topology in-memory.
255  */
256 struct hammer2_chain {
257         TAILQ_ENTRY(hammer2_chain) core_entry;  /* contemporary chains */
258         RB_ENTRY(hammer2_chain) rbnode;         /* live chain(s) */
259         TAILQ_ENTRY(hammer2_chain) db_entry;    /* non bmapped deletions */
260         hammer2_blockref_t      bref;
261         hammer2_chain_core_t    *core;
262         hammer2_chain_core_t    *above;
263         struct hammer2_state    *state;         /* if active cache msg */
264         struct hammer2_mount    *hmp;
265         struct hammer2_pfsmount *pmp;           /* can be NULL */
266
267         hammer2_blockref_t      dsrc;                   /* DEBUG */
268         int                     ninserts;               /* DEBUG */
269         int                     nremoves;               /* DEBUG */
270         hammer2_tid_t           dsrc_dupfromat;         /* DEBUG */
271         uint32_t                dsrc_dupfromflags;      /* DEBUG */
272         int                     dsrc_reason;            /* DEBUG */
273         int                     dsrc_ninserts;          /* DEBUG */
274         uint32_t                dsrc_flags;             /* DEBUG */
275         hammer2_tid_t           dsrc_modify;            /* DEBUG */
276         hammer2_tid_t           dsrc_delete;            /* DEBUG */
277         hammer2_tid_t           dsrc_update_lo;         /* DEBUG */
278         struct hammer2_chain    *dsrc_original;         /* DEBUG */
279
280         hammer2_tid_t   modify_tid;             /* flush filter */
281         hammer2_tid_t   delete_tid;             /* flush filter */
282         hammer2_tid_t   update_lo;              /* flush propagation */
283         hammer2_tid_t   update_hi;              /* setsubmod propagation */
284         hammer2_key_t   data_count;             /* delta's to apply */
285         hammer2_key_t   inode_count;            /* delta's to apply */
286         hammer2_io_t    *dio;                   /* physical data buffer */
287         u_int           bytes;                  /* physical data size */
288         u_int           flags;
289         u_int           refs;
290         u_int           lockcnt;
291         hammer2_media_data_t *data;             /* data pointer shortcut */
292         TAILQ_ENTRY(hammer2_chain) flush_node;  /* flush deferral list */
293
294         int             inode_reason;
295 };
296
297 typedef struct hammer2_chain hammer2_chain_t;
298
299 int hammer2_chain_cmp(hammer2_chain_t *chain1, hammer2_chain_t *chain2);
300 RB_PROTOTYPE(hammer2_chain_tree, hammer2_chain, rbnode, hammer2_chain_cmp);
301
302 /*
303  * Special notes on flags:
304  *
305  * INITIAL - This flag allows a chain to be created and for storage to
306  *           be allocated without having to immediately instantiate the
307  *           related buffer.  The data is assumed to be all-zeros.  It
308  *           is primarily used for indirect blocks.
309  *
310  * MODIFIED- The chain's media data has been modified.
311  */
312 #define HAMMER2_CHAIN_MODIFIED          0x00000001      /* dirty chain data */
313 #define HAMMER2_CHAIN_ALLOCATED         0x00000002      /* kmalloc'd chain */
314 #define HAMMER2_CHAIN_FLUSH_TEMPORARY   0x00000004
315 #define HAMMER2_CHAIN_FORCECOW          0x00000008      /* force copy-on-wr */
316 #define HAMMER2_CHAIN_DELETED           0x00000010      /* deleted chain */
317 #define HAMMER2_CHAIN_INITIAL           0x00000020      /* initial create */
318 #define HAMMER2_CHAIN_FLUSH_CREATE      0x00000040      /* needs flush blkadd */
319 #define HAMMER2_CHAIN_FLUSH_DELETE      0x00000080      /* needs flush blkdel */
320 #define HAMMER2_CHAIN_IOFLUSH           0x00000100      /* bawrite on put */
321 #define HAMMER2_CHAIN_DEFERRED          0x00000200      /* on a deferral list */
322 #define HAMMER2_CHAIN_UNLINKED          0x00000400      /* delete on reclaim */
323 #define HAMMER2_CHAIN_VOLUMESYNC        0x00000800      /* needs volume sync */
324 #define HAMMER2_CHAIN_ONDBQ             0x00001000      /* !bmapped deletes */
325 #define HAMMER2_CHAIN_MOUNTED           0x00002000      /* PFS is mounted */
326 #define HAMMER2_CHAIN_ONRBTREE          0x00004000      /* on parent RB tree */
327 #define HAMMER2_CHAIN_SNAPSHOT          0x00008000      /* snapshot special */
328 #define HAMMER2_CHAIN_EMBEDDED          0x00010000      /* embedded data */
329 #define HAMMER2_CHAIN_RELEASE           0x00020000      /* don't keep around */
330 #define HAMMER2_CHAIN_BMAPPED           0x00040000      /* in parent blkmap */
331 #define HAMMER2_CHAIN_ONDBTREE          0x00080000      /* bmapped deletes */
332 #define HAMMER2_CHAIN_DUPLICATED        0x00100000      /* fwd delete-dup */
333 #define HAMMER2_CHAIN_PFSROOT           0x00200000      /* in pfs->cluster */
334
335 /*
336  * Flags passed to hammer2_chain_lookup() and hammer2_chain_next()
337  *
338  * NOTE: MATCHIND allows an indirect block / freemap node to be returned
339  *       when the passed key range matches the radix.  Remember that key_end
340  *       is inclusive (e.g. {0x000,0xFFF}, not {0x000,0x1000}).
341  */
342 #define HAMMER2_LOOKUP_NOLOCK           0x00000001      /* ref only */
343 #define HAMMER2_LOOKUP_NODATA           0x00000002      /* data left NULL */
344 #define HAMMER2_LOOKUP_SHARED           0x00000100
345 #define HAMMER2_LOOKUP_MATCHIND         0x00000200      /* return all chains */
346 #define HAMMER2_LOOKUP_UNUSED0400       0x00000400
347 #define HAMMER2_LOOKUP_ALWAYS           0x00000800      /* resolve data */
348
349 /*
350  * Flags passed to hammer2_chain_modify() and hammer2_chain_resize()
351  *
352  * NOTE: OPTDATA allows us to avoid instantiating buffers for INDIRECT
353  *       blocks in the INITIAL-create state.
354  */
355 #define HAMMER2_MODIFY_OPTDATA          0x00000002      /* data can be NULL */
356 #define HAMMER2_MODIFY_NO_MODIFY_TID    0x00000004
357 #define HAMMER2_MODIFY_ASSERTNOCOPY     0x00000008      /* assert no del-dup */
358 #define HAMMER2_MODIFY_NOREALLOC        0x00000010
359 #define HAMMER2_MODIFY_INPLACE          0x00000020      /* don't del-dup */
360
361 /*
362  * Flags passed to hammer2_chain_lock()
363  */
364 #define HAMMER2_RESOLVE_NEVER           1
365 #define HAMMER2_RESOLVE_MAYBE           2
366 #define HAMMER2_RESOLVE_ALWAYS          3
367 #define HAMMER2_RESOLVE_MASK            0x0F
368
369 #define HAMMER2_RESOLVE_SHARED          0x10    /* request shared lock */
370 #define HAMMER2_RESOLVE_NOREF           0x20    /* already ref'd on lock */
371
372 /*
373  * Flags passed to hammer2_chain_delete()
374  */
375 #define HAMMER2_DELETE_UNUSED0001       0x0001
376
377 /*
378  * Flags passed to hammer2_chain_delete_duplicate()
379  */
380 #define HAMMER2_DELDUP_RECORE           0x0001
381
382 /*
383  * Cluster different types of storage together for allocations
384  */
385 #define HAMMER2_FREECACHE_INODE         0
386 #define HAMMER2_FREECACHE_INDIR         1
387 #define HAMMER2_FREECACHE_DATA          2
388 #define HAMMER2_FREECACHE_UNUSED3       3
389 #define HAMMER2_FREECACHE_TYPES         4
390
391 /*
392  * hammer2_freemap_alloc() block preference
393  */
394 #define HAMMER2_OFF_NOPREF              ((hammer2_off_t)-1)
395
396 /*
397  * BMAP read-ahead maximum parameters
398  */
399 #define HAMMER2_BMAP_COUNT              16      /* max bmap read-ahead */
400 #define HAMMER2_BMAP_BYTES              (HAMMER2_PBUFSIZE * HAMMER2_BMAP_COUNT)
401
402 /*
403  * Misc
404  */
405 #define HAMMER2_FLUSH_DEPTH_LIMIT       10      /* stack recursion limit */
406
407 /*
408  * hammer2_freemap_adjust()
409  */
410 #define HAMMER2_FREEMAP_DORECOVER       1
411 #define HAMMER2_FREEMAP_DOMAYFREE       2
412 #define HAMMER2_FREEMAP_DOREALFREE      3
413
414 /*
415  * HAMMER2 cluster - A set of chains representing the same entity.
416  *
417  * The hammer2_pfsmount structure embeds a hammer2_cluster.  All other
418  * hammer2_cluster use cases use temporary allocations.
419  *
420  * The cluster API mimics the chain API.  Except as used in the pfsmount,
421  * the cluster structure is a temporary 'working copy' of a set of chains
422  * representing targets compatible with the operation.  However, for
423  * performance reasons the cluster API does not necessarily issue concurrent
424  * requests to the underlying chain API for all compatible chains all the
425  * time.  This may sometimes necessitate revisiting parent cluster nodes
426  * to 'flesh out' (validate more chains).
427  *
428  * If an insufficient number of chains remain in a working copy, the operation
429  * may have to be downgraded, retried, or stall until the requisit number
430  * of chains are available.
431  */
432 #define HAMMER2_MAXCLUSTER      8
433
434 struct hammer2_cluster {
435         int                     status;         /* operational status */
436         int                     refs;           /* track for deallocation */
437         struct hammer2_pfsmount *pmp;
438         uint32_t                flags;
439         int                     nchains;
440         hammer2_chain_t         *focus;         /* current focus (or mod) */
441         hammer2_chain_t         *array[HAMMER2_MAXCLUSTER];
442         int                     cache_index[HAMMER2_MAXCLUSTER];
443 };
444
445 typedef struct hammer2_cluster hammer2_cluster_t;
446
447 #define HAMMER2_CLUSTER_PFS     0x00000001      /* embedded in pfsmount */
448 #define HAMMER2_CLUSTER_INODE   0x00000002      /* embedded in inode */
449
450
451 RB_HEAD(hammer2_inode_tree, hammer2_inode);
452
453 /*
454  * A hammer2 inode.
455  *
456  * NOTE: The inode's attribute CST which is also used to lock the inode
457  *       is embedded in the chain (chain.cst) and aliased w/ attr_cst.
458  */
459 struct hammer2_inode {
460         RB_ENTRY(hammer2_inode) rbnode;         /* inumber lookup (HL) */
461         ccms_cst_t              topo_cst;       /* directory topology cst */
462         struct hammer2_pfsmount *pmp;           /* PFS mount */
463         struct hammer2_inode    *pip;           /* parent inode */
464         struct vnode            *vp;
465         hammer2_cluster_t       cluster;
466         struct lockf            advlock;
467         hammer2_tid_t           inum;
468         u_int                   flags;
469         u_int                   refs;           /* +vpref, +flushref */
470         uint8_t                 comp_heuristic;
471         hammer2_off_t           size;
472         uint64_t                mtime;
473 };
474
475 typedef struct hammer2_inode hammer2_inode_t;
476
477 #define HAMMER2_INODE_MODIFIED          0x0001
478 #define HAMMER2_INODE_SROOT             0x0002  /* kmalloc special case */
479 #define HAMMER2_INODE_RENAME_INPROG     0x0004
480 #define HAMMER2_INODE_ONRBTREE          0x0008
481 #define HAMMER2_INODE_RESIZED           0x0010
482 #define HAMMER2_INODE_MTIME             0x0020
483
484 int hammer2_inode_cmp(hammer2_inode_t *ip1, hammer2_inode_t *ip2);
485 RB_PROTOTYPE2(hammer2_inode_tree, hammer2_inode, rbnode, hammer2_inode_cmp,
486                 hammer2_tid_t);
487
488 /*
489  * inode-unlink side-structure
490  */
491 struct hammer2_inode_unlink {
492         TAILQ_ENTRY(hammer2_inode_unlink) entry;
493         hammer2_inode_t *ip;
494 };
495 TAILQ_HEAD(hammer2_unlk_list, hammer2_inode_unlink);
496
497 typedef struct hammer2_inode_unlink hammer2_inode_unlink_t;
498
499 /*
500  * A hammer2 transaction and flush sequencing structure.
501  *
502  * This global structure is tied into hammer2_mount and is used
503  * to sequence modifying operations and flushes.
504  *
505  * (a) Any modifying operations with sync_tid >= flush_tid will stall until
506  *     all modifying operating with sync_tid < flush_tid complete.
507  *
508  *     The flush related to flush_tid stalls until all modifying operations
509  *     with sync_tid < flush_tid complete.
510  *
511  * (b) Once unstalled, modifying operations with sync_tid > flush_tid are
512  *     allowed to run.  All modifications cause modify/duplicate operations
513  *     to occur on the related chains.  Note that most INDIRECT blocks will
514  *     be unaffected because the modifications just overload the RBTREE
515  *     structurally instead of actually modifying the indirect blocks.
516  *
517  * (c) The actual flush unstalls and RUNS CONCURRENTLY with (b), but only
518  *     utilizes the chain structures with sync_tid <= flush_tid.  The
519  *     flush will modify related indirect blocks and inodes in-place
520  *     (rather than duplicate) since the adjustments are compatible with
521  *     (b)'s RBTREE overloading
522  *
523  *     SPECIAL NOTE:  Inode modifications have to also propagate along any
524  *                    modify/duplicate chains.  File writes detect the flush
525  *                    and force out the conflicting buffer cache buffer(s)
526  *                    before reusing them.
527  *
528  * (d) Snapshots can be made instantly but must be flushed and disconnected
529  *     from their duplicative source before they can be mounted.  This is
530  *     because while H2's on-media structure supports forks, its in-memory
531  *     structure only supports very simple forking for background flushing
532  *     purposes.
533  *
534  * TODO: Flush merging.  When fsync() is called on multiple discrete files
535  *       concurrently there is no reason to stall the second fsync.
536  *       The final flush that reaches to root can cover both fsync()s.
537  *
538  *     The chains typically terminate as they fly onto the disk.  The flush
539  *     ultimately reaches the volume header.
540  */
541 struct hammer2_trans {
542         TAILQ_ENTRY(hammer2_trans) entry;
543         struct hammer2_pfsmount *pmp;           /* might be NULL */
544         struct hammer2_mount    *hmp_single;    /* if single-targetted */
545         hammer2_tid_t           orig_tid;
546         hammer2_tid_t           sync_tid;       /* effective transaction id */
547         hammer2_tid_t           inode_tid;
548         thread_t                td;             /* pointer */
549         int                     flags;
550         int                     blocked;
551         uint8_t                 inodes_created;
552         uint8_t                 dummy[7];
553 };
554
555 typedef struct hammer2_trans hammer2_trans_t;
556
557 #define HAMMER2_TRANS_ISFLUSH           0x0001  /* formal flush */
558 #define HAMMER2_TRANS_CONCURRENT        0x0002  /* concurrent w/flush */
559 #define HAMMER2_TRANS_BUFCACHE          0x0004  /* from bioq strategy write */
560 #define HAMMER2_TRANS_NEWINODE          0x0008  /* caller allocating inode */
561 #define HAMMER2_TRANS_ISALLOCATING      0x0010  /* in allocator */
562 #define HAMMER2_TRANS_PREFLUSH          0x0020  /* preflush state */
563
564 #define HAMMER2_FREEMAP_HEUR_NRADIX     4       /* pwr 2 PBUFRADIX-MINIORADIX */
565 #define HAMMER2_FREEMAP_HEUR_TYPES      8
566 #define HAMMER2_FREEMAP_HEUR            (HAMMER2_FREEMAP_HEUR_NRADIX * \
567                                          HAMMER2_FREEMAP_HEUR_TYPES)
568
569 #define HAMMER2_CLUSTER_COPY_CHAINS     0x0001  /* copy chains */
570 #define HAMMER2_CLUSTER_COPY_NOREF      0x0002  /* do not ref chains */
571
572 /*
573  * Global (per device) mount structure for device (aka vp->v_mount->hmp)
574  */
575 TAILQ_HEAD(hammer2_trans_queue, hammer2_trans);
576
577 struct hammer2_mount {
578         struct vnode    *devvp;         /* device vnode */
579         int             ronly;          /* read-only mount */
580         int             pmp_count;      /* PFS mounts backed by us */
581         TAILQ_ENTRY(hammer2_mount) mntentry; /* hammer2_mntlist */
582
583         struct malloc_type *mchain;
584         int             nipstacks;
585         int             maxipstacks;
586         struct spinlock io_spin;        /* iotree access */
587         struct hammer2_io_tree iotree;
588         int             iofree_count;
589         hammer2_chain_t vchain;         /* anchor chain (topology) */
590         hammer2_chain_t fchain;         /* anchor chain (freemap) */
591         hammer2_inode_t *sroot;         /* super-root localized to media */
592         struct lock     alloclk;        /* lockmgr lock */
593         struct lock     voldatalk;      /* lockmgr lock */
594         struct hammer2_trans_queue transq; /* all in-progress transactions */
595         hammer2_off_t   heur_freemap[HAMMER2_FREEMAP_HEUR];
596         int             flushcnt;       /* #of flush trans on the list */
597
598         int             volhdrno;       /* last volhdrno written */
599         hammer2_volume_data_t voldata;
600         hammer2_volume_data_t volsync;  /* synchronized voldata */
601 };
602
603 typedef struct hammer2_mount hammer2_mount_t;
604
605 /*
606  * HAMMER2 PFS mount point structure (aka vp->v_mount->mnt_data).
607  * This has a 1:1 correspondence to struct mount (note that the
608  * hammer2_mount structure has a N:1 correspondence).
609  *
610  * This structure represents a cluster mount and not necessarily a
611  * PFS under a specific device mount (HMP).  The distinction is important
612  * because the elements backing a cluster mount can change on the fly.
613  *
614  * Usually the first element under the cluster represents the original
615  * user-requested mount that bootstraps the whole mess.  In significant
616  * setups the original is usually just a read-only media image (or
617  * representitive file) that simply contains a bootstrap volume header
618  * listing the configuration.
619  */
620 struct hammer2_pfsmount {
621         struct mount            *mp;
622         hammer2_cluster_t       cluster;
623         hammer2_inode_t         *iroot;         /* PFS root inode */
624         hammer2_inode_t         *ihidden;       /* PFS hidden directory */
625         struct lock             lock;           /* PFS lock for certain ops */
626         hammer2_off_t           inode_count;    /* copy of inode_count */
627         ccms_domain_t           ccms_dom;
628         struct netexport        export;         /* nfs export */
629         int                     ronly;          /* read-only mount */
630         struct malloc_type      *minode;
631         struct malloc_type      *mmsg;
632         kdmsg_iocom_t           iocom;
633         struct spinlock         inum_spin;      /* inumber lookup */
634         struct hammer2_inode_tree inum_tree;
635         long                    inmem_inodes;
636         long                    inmem_dirty_chains;
637         int                     count_lwinprog; /* logical write in prog */
638         struct spinlock         unlinkq_spin;
639         struct hammer2_unlk_list unlinkq;
640         thread_t                wthread_td;     /* write thread td */
641         struct bio_queue_head   wthread_bioq;   /* logical buffer bioq */
642         struct mtx              wthread_mtx;    /* interlock */
643         int                     wthread_destroy;/* termination sequencing */
644 };
645
646 typedef struct hammer2_pfsmount hammer2_pfsmount_t;
647
648 #define HAMMER2_DIRTYCHAIN_WAITING      0x80000000
649 #define HAMMER2_DIRTYCHAIN_MASK         0x7FFFFFFF
650
651 #define HAMMER2_LWINPROG_WAITING        0x80000000
652 #define HAMMER2_LWINPROG_MASK           0x7FFFFFFF
653
654 #if defined(_KERNEL)
655
656 MALLOC_DECLARE(M_HAMMER2);
657
658 #define VTOI(vp)        ((hammer2_inode_t *)(vp)->v_data)
659 #define ITOV(ip)        ((ip)->vp)
660
661 /*
662  * Currently locked chains retain the locked buffer cache buffer for
663  * indirect blocks, and indirect blocks can be one of two sizes.  The
664  * device buffer has to match the case to avoid deadlocking recursive
665  * chains that might otherwise try to access different offsets within
666  * the same device buffer.
667  */
668 static __inline
669 int
670 hammer2_devblkradix(int radix)
671 {
672         if (radix <= HAMMER2_LBUFRADIX) {
673                 return (HAMMER2_LBUFRADIX);
674         } else {
675                 return (HAMMER2_PBUFRADIX);
676         }
677 }
678
679 static __inline
680 size_t
681 hammer2_devblksize(size_t bytes)
682 {
683         if (bytes <= HAMMER2_LBUFSIZE) {
684                 return(HAMMER2_LBUFSIZE);
685         } else {
686                 KKASSERT(bytes <= HAMMER2_PBUFSIZE &&
687                          (bytes ^ (bytes - 1)) == ((bytes << 1) - 1));
688                 return (HAMMER2_PBUFSIZE);
689         }
690 }
691
692
693 static __inline
694 hammer2_pfsmount_t *
695 MPTOPMP(struct mount *mp)
696 {
697         return ((hammer2_pfsmount_t *)mp->mnt_data);
698 }
699
700 extern struct vop_ops hammer2_vnode_vops;
701 extern struct vop_ops hammer2_spec_vops;
702 extern struct vop_ops hammer2_fifo_vops;
703
704 extern int hammer2_debug;
705 extern int hammer2_cluster_enable;
706 extern int hammer2_hardlink_enable;
707 extern int hammer2_flush_pipe;
708 extern int hammer2_synchronous_flush;
709 extern long hammer2_limit_dirty_chains;
710 extern long hammer2_iod_file_read;
711 extern long hammer2_iod_meta_read;
712 extern long hammer2_iod_indr_read;
713 extern long hammer2_iod_fmap_read;
714 extern long hammer2_iod_volu_read;
715 extern long hammer2_iod_file_write;
716 extern long hammer2_iod_meta_write;
717 extern long hammer2_iod_indr_write;
718 extern long hammer2_iod_fmap_write;
719 extern long hammer2_iod_volu_write;
720 extern long hammer2_ioa_file_read;
721 extern long hammer2_ioa_meta_read;
722 extern long hammer2_ioa_indr_read;
723 extern long hammer2_ioa_fmap_read;
724 extern long hammer2_ioa_volu_read;
725 extern long hammer2_ioa_file_write;
726 extern long hammer2_ioa_meta_write;
727 extern long hammer2_ioa_indr_write;
728 extern long hammer2_ioa_fmap_write;
729 extern long hammer2_ioa_volu_write;
730
731 extern struct objcache *cache_buffer_read;
732 extern struct objcache *cache_buffer_write;
733
734 extern int destroy;
735 extern int write_thread_wakeup;
736
737 extern mtx_t thread_protect;
738
739 /*
740  * hammer2_subr.c
741  */
742 #define hammer2_icrc32(buf, size)       iscsi_crc32((buf), (size))
743 #define hammer2_icrc32c(buf, size, crc) iscsi_crc32_ext((buf), (size), (crc))
744
745 hammer2_cluster_t *hammer2_inode_lock_ex(hammer2_inode_t *ip);
746 hammer2_cluster_t *hammer2_inode_lock_sh(hammer2_inode_t *ip);
747 void hammer2_inode_unlock_ex(hammer2_inode_t *ip, hammer2_cluster_t *chain);
748 void hammer2_inode_unlock_sh(hammer2_inode_t *ip, hammer2_cluster_t *chain);
749 void hammer2_voldata_lock(hammer2_mount_t *hmp);
750 void hammer2_voldata_unlock(hammer2_mount_t *hmp, int modify);
751 ccms_state_t hammer2_inode_lock_temp_release(hammer2_inode_t *ip);
752 void hammer2_inode_lock_temp_restore(hammer2_inode_t *ip, ccms_state_t ostate);
753 ccms_state_t hammer2_inode_lock_upgrade(hammer2_inode_t *ip);
754 void hammer2_inode_lock_downgrade(hammer2_inode_t *ip, ccms_state_t ostate);
755
756 void hammer2_mount_exlock(hammer2_mount_t *hmp);
757 void hammer2_mount_shlock(hammer2_mount_t *hmp);
758 void hammer2_mount_unlock(hammer2_mount_t *hmp);
759
760 int hammer2_get_dtype(hammer2_inode_data_t *ipdata);
761 int hammer2_get_vtype(hammer2_inode_data_t *ipdata);
762 u_int8_t hammer2_get_obj_type(enum vtype vtype);
763 void hammer2_time_to_timespec(u_int64_t xtime, struct timespec *ts);
764 u_int64_t hammer2_timespec_to_time(struct timespec *ts);
765 u_int32_t hammer2_to_unix_xid(uuid_t *uuid);
766 void hammer2_guid_to_uuid(uuid_t *uuid, u_int32_t guid);
767
768 hammer2_key_t hammer2_dirhash(const unsigned char *name, size_t len);
769 int hammer2_getradix(size_t bytes);
770
771 int hammer2_calc_logical(hammer2_inode_t *ip, hammer2_off_t uoff,
772                         hammer2_key_t *lbasep, hammer2_key_t *leofp);
773 int hammer2_calc_physical(hammer2_inode_t *ip, hammer2_inode_data_t *ipdata,
774                         hammer2_key_t lbase);
775 void hammer2_update_time(uint64_t *timep);
776 void hammer2_adjreadcounter(hammer2_blockref_t *bref, size_t bytes);
777
778 /*
779  * hammer2_inode.c
780  */
781 struct vnode *hammer2_igetv(hammer2_inode_t *ip, hammer2_cluster_t *cparent,
782                         int *errorp);
783 void hammer2_inode_lock_nlinks(hammer2_inode_t *ip);
784 void hammer2_inode_unlock_nlinks(hammer2_inode_t *ip);
785 hammer2_inode_t *hammer2_inode_lookup(hammer2_pfsmount_t *pmp,
786                         hammer2_tid_t inum);
787 hammer2_inode_t *hammer2_inode_get(hammer2_pfsmount_t *pmp,
788                         hammer2_inode_t *dip, hammer2_cluster_t *cluster);
789 void hammer2_inode_free(hammer2_inode_t *ip);
790 void hammer2_inode_ref(hammer2_inode_t *ip);
791 void hammer2_inode_drop(hammer2_inode_t *ip);
792 void hammer2_inode_repoint(hammer2_inode_t *ip, hammer2_inode_t *pip,
793                         hammer2_cluster_t *cluster);
794 void hammer2_run_unlinkq(hammer2_trans_t *trans, hammer2_pfsmount_t *pmp);
795
796 hammer2_inode_t *hammer2_inode_create(hammer2_trans_t *trans,
797                         hammer2_inode_t *dip,
798                         struct vattr *vap, struct ucred *cred,
799                         const uint8_t *name, size_t name_len,
800                         hammer2_cluster_t **clusterp, int *errorp);
801 int hammer2_inode_connect(hammer2_trans_t *trans,
802                         hammer2_cluster_t **clusterp, int hlink,
803                         hammer2_inode_t *dip, hammer2_cluster_t *dcluster,
804                         const uint8_t *name, size_t name_len,
805                         hammer2_key_t key);
806 hammer2_inode_t *hammer2_inode_common_parent(hammer2_inode_t *fdip,
807                         hammer2_inode_t *tdip);
808 void hammer2_inode_fsync(hammer2_trans_t *trans, hammer2_inode_t *ip,
809                         hammer2_cluster_t *cparent);
810 int hammer2_unlink_file(hammer2_trans_t *trans, hammer2_inode_t *dip,
811                         const uint8_t *name, size_t name_len, int isdir,
812                         int *hlinkp, struct nchandle *nch);
813 int hammer2_hardlink_consolidate(hammer2_trans_t *trans,
814                         hammer2_inode_t *ip, hammer2_cluster_t **clusterp,
815                         hammer2_inode_t *cdip, hammer2_cluster_t *cdcluster,
816                         int nlinks);
817 int hammer2_hardlink_deconsolidate(hammer2_trans_t *trans, hammer2_inode_t *dip,
818                         hammer2_chain_t **chainp, hammer2_chain_t **ochainp);
819 int hammer2_hardlink_find(hammer2_inode_t *dip, hammer2_cluster_t *cluster);
820 void hammer2_inode_install_hidden(hammer2_pfsmount_t *pmp);
821
822 /*
823  * hammer2_chain.c
824  */
825 void hammer2_modify_volume(hammer2_mount_t *hmp);
826 hammer2_chain_t *hammer2_chain_alloc(hammer2_mount_t *hmp,
827                                 hammer2_pfsmount_t *pmp,
828                                 hammer2_trans_t *trans,
829                                 hammer2_blockref_t *bref);
830 void hammer2_chain_core_alloc(hammer2_trans_t *trans, hammer2_chain_t *nchain,
831                                 hammer2_chain_t *ochain);
832 void hammer2_chain_ref(hammer2_chain_t *chain);
833 void hammer2_chain_drop(hammer2_chain_t *chain);
834 int hammer2_chain_lock(hammer2_chain_t *chain, int how);
835 void hammer2_chain_load_async(hammer2_cluster_t *cluster,
836                                 void (*func)(hammer2_io_t *dio,
837                                              hammer2_cluster_t *cluster,
838                                              hammer2_chain_t *chain,
839                                              void *arg_p, off_t arg_o),
840                                 void *arg_p);
841 void hammer2_chain_moved(hammer2_chain_t *chain);
842 void hammer2_chain_modify(hammer2_trans_t *trans,
843                                 hammer2_chain_t **chainp, int flags);
844 void hammer2_chain_resize(hammer2_trans_t *trans, hammer2_inode_t *ip,
845                                 hammer2_chain_t *parent,
846                                 hammer2_chain_t **chainp,
847                                 int nradix, int flags);
848 void hammer2_chain_unlock(hammer2_chain_t *chain);
849 void hammer2_chain_wait(hammer2_chain_t *chain);
850 hammer2_chain_t *hammer2_chain_get(hammer2_chain_t *parent, int generation,
851                                 hammer2_blockref_t *bref);
852 hammer2_chain_t *hammer2_chain_lookup_init(hammer2_chain_t *parent, int flags);
853 void hammer2_chain_lookup_done(hammer2_chain_t *parent);
854 hammer2_chain_t *hammer2_chain_lookup(hammer2_chain_t **parentp,
855                                 hammer2_key_t *key_nextp,
856                                 hammer2_key_t key_beg, hammer2_key_t key_end,
857                                 int *cache_indexp, int flags, int *ddflagp);
858 hammer2_chain_t *hammer2_chain_next(hammer2_chain_t **parentp,
859                                 hammer2_chain_t *chain,
860                                 hammer2_key_t *key_nextp,
861                                 hammer2_key_t key_beg, hammer2_key_t key_end,
862                                 int *cache_indexp, int flags);
863 hammer2_chain_t *hammer2_chain_scan(hammer2_chain_t *parent,
864                                 hammer2_chain_t *chain,
865                                 int *cache_indexp, int flags);
866
867 int hammer2_chain_create(hammer2_trans_t *trans,
868                                 hammer2_chain_t **parentp,
869                                 hammer2_chain_t **chainp,
870                                 hammer2_key_t key, int keybits,
871                                 int type, size_t bytes);
872 void hammer2_chain_duplicate(hammer2_trans_t *trans, hammer2_chain_t **parentp,
873                                 hammer2_chain_t **chainp,
874                                 hammer2_blockref_t *bref, int snapshot,
875                                 int duplicate_reason);
876 int hammer2_chain_snapshot(hammer2_trans_t *trans, hammer2_chain_t **chainp,
877                                 hammer2_ioc_pfs_t *pfs);
878 void hammer2_chain_delete(hammer2_trans_t *trans, hammer2_chain_t *chain,
879                                 int flags);
880 void hammer2_chain_delete_duplicate(hammer2_trans_t *trans,
881                                 hammer2_chain_t **chainp, int flags);
882 void hammer2_flush(hammer2_trans_t *trans, hammer2_chain_t **chainp);
883 void hammer2_chain_commit(hammer2_trans_t *trans, hammer2_chain_t *chain);
884 void hammer2_chain_setsubmod(hammer2_trans_t *trans, hammer2_chain_t *chain);
885 void hammer2_chain_countbrefs(hammer2_chain_t *chain,
886                                 hammer2_blockref_t *base, int count);
887
888 void hammer2_pfs_memory_wait(hammer2_pfsmount_t *pmp);
889 void hammer2_pfs_memory_inc(hammer2_pfsmount_t *pmp);
890 void hammer2_pfs_memory_wakeup(hammer2_pfsmount_t *pmp);
891
892 int hammer2_base_find(hammer2_chain_t *chain,
893                                 hammer2_blockref_t *base, int count,
894                                 int *cache_indexp, hammer2_key_t *key_nextp,
895                                 hammer2_key_t key_beg, hammer2_key_t key_end,
896                                 int delete_filter);
897 void hammer2_base_delete(hammer2_trans_t *trans, hammer2_chain_t *chain,
898                                 hammer2_blockref_t *base, int count,
899                                 int *cache_indexp, hammer2_chain_t *child);
900 void hammer2_base_insert(hammer2_trans_t *trans, hammer2_chain_t *chain,
901                                 hammer2_blockref_t *base, int count,
902                                 int *cache_indexp, hammer2_chain_t *child);
903 void hammer2_chain_refactor(hammer2_chain_t **chainp);
904
905 /*
906  * hammer2_trans.c
907  */
908 void hammer2_trans_init(hammer2_trans_t *trans, hammer2_pfsmount_t *pmp,
909                                 hammer2_mount_t *hmp, int flags);
910 void hammer2_trans_done(hammer2_trans_t *trans);
911
912 /*
913  * hammer2_ioctl.c
914  */
915 int hammer2_ioctl(hammer2_inode_t *ip, u_long com, void *data,
916                                 int fflag, struct ucred *cred);
917
918 /*
919  * hammer2_io.c
920  */
921 hammer2_io_t *hammer2_io_getblk(hammer2_mount_t *hmp, off_t lbase,
922                                 int lsize, int *ownerp);
923 void hammer2_io_putblk(hammer2_io_t **diop);
924 void hammer2_io_cleanup(hammer2_mount_t *hmp, struct hammer2_io_tree *tree);
925 char *hammer2_io_data(hammer2_io_t *dio, off_t lbase);
926 int hammer2_io_new(hammer2_mount_t *hmp, off_t lbase, int lsize,
927                                 hammer2_io_t **diop);
928 int hammer2_io_newnz(hammer2_mount_t *hmp, off_t lbase, int lsize,
929                                 hammer2_io_t **diop);
930 int hammer2_io_newq(hammer2_mount_t *hmp, off_t lbase, int lsize,
931                                 hammer2_io_t **diop);
932 int hammer2_io_bread(hammer2_mount_t *hmp, off_t lbase, int lsize,
933                                 hammer2_io_t **diop);
934 void hammer2_io_breadcb(hammer2_mount_t *hmp, off_t lbase, int lsize,
935                                 void (*callback)(hammer2_io_t *dio,
936                                                  hammer2_cluster_t *arg_l,
937                                                  hammer2_chain_t *arg_c,
938                                                  void *arg_p, off_t arg_o),
939                                 hammer2_cluster_t *arg_l,
940                                 hammer2_chain_t *arg_c,
941                                 void *arg_p, off_t arg_o);
942 void hammer2_io_bawrite(hammer2_io_t **diop);
943 void hammer2_io_bdwrite(hammer2_io_t **diop);
944 int hammer2_io_bwrite(hammer2_io_t **diop);
945 int hammer2_io_isdirty(hammer2_io_t *dio);
946 void hammer2_io_setdirty(hammer2_io_t *dio);
947 void hammer2_io_setinval(hammer2_io_t *dio, u_int bytes);
948 void hammer2_io_brelse(hammer2_io_t **diop);
949 void hammer2_io_bqrelse(hammer2_io_t **diop);
950
951 /*
952  * hammer2_msgops.c
953  */
954 int hammer2_msg_dbg_rcvmsg(kdmsg_msg_t *msg);
955 int hammer2_msg_adhoc_input(kdmsg_msg_t *msg);
956
957 /*
958  * hammer2_vfsops.c
959  */
960 void hammer2_clusterctl_wakeup(kdmsg_iocom_t *iocom);
961 void hammer2_volconf_update(hammer2_pfsmount_t *pmp, int index);
962 void hammer2_cluster_reconnect(hammer2_pfsmount_t *pmp, struct file *fp);
963 void hammer2_dump_chain(hammer2_chain_t *chain, int tab, int *countp, char pfx);
964 void hammer2_bioq_sync(hammer2_pfsmount_t *pmp);
965 int hammer2_vfs_sync(struct mount *mp, int waitflags);
966 void hammer2_lwinprog_ref(hammer2_pfsmount_t *pmp);
967 void hammer2_lwinprog_drop(hammer2_pfsmount_t *pmp);
968 void hammer2_lwinprog_wait(hammer2_pfsmount_t *pmp);
969
970 /*
971  * hammer2_freemap.c
972  */
973 int hammer2_freemap_alloc(hammer2_trans_t *trans, hammer2_chain_t *chain,
974                                 size_t bytes);
975 void hammer2_freemap_adjust(hammer2_trans_t *trans, hammer2_mount_t *hmp,
976                                 hammer2_blockref_t *bref, int how);
977
978 /*
979  * hammer2_cluster.c
980  */
981 u_int hammer2_cluster_bytes(hammer2_cluster_t *cluster);
982 uint8_t hammer2_cluster_type(hammer2_cluster_t *cluster);
983 hammer2_media_data_t *hammer2_cluster_data(hammer2_cluster_t *cluster);
984 hammer2_cluster_t *hammer2_cluster_from_chain(hammer2_chain_t *chain);
985 int hammer2_cluster_modified(hammer2_cluster_t *cluster);
986 int hammer2_cluster_unlinked(hammer2_cluster_t *cluster);
987 int hammer2_cluster_duplicated(hammer2_cluster_t *cluster);
988 void hammer2_cluster_set_chainflags(hammer2_cluster_t *cluster, uint32_t flags);
989 void hammer2_cluster_bref(hammer2_cluster_t *cluster, hammer2_blockref_t *bref);
990 void hammer2_cluster_setsubmod(hammer2_trans_t *trans,
991                         hammer2_cluster_t *cluster);
992 hammer2_cluster_t *hammer2_cluster_alloc(hammer2_pfsmount_t *pmp,
993                         hammer2_trans_t *trans,
994                         hammer2_blockref_t *bref);
995 void hammer2_cluster_core_alloc(hammer2_trans_t *trans,
996                         hammer2_cluster_t *ncluster,
997                         hammer2_cluster_t *ocluster);
998 void hammer2_cluster_ref(hammer2_cluster_t *cluster);
999 void hammer2_cluster_drop(hammer2_cluster_t *cluster);
1000 void hammer2_cluster_wait(hammer2_cluster_t *cluster);
1001 int hammer2_cluster_lock(hammer2_cluster_t *cluster, int how);
1002 void hammer2_cluster_replace(hammer2_cluster_t *dst, hammer2_cluster_t *src);
1003 void hammer2_cluster_replace_locked(hammer2_cluster_t *dst,
1004                         hammer2_cluster_t *src);
1005 hammer2_cluster_t *hammer2_cluster_copy(hammer2_cluster_t *ocluster,
1006                         int with_chains);
1007 void hammer2_cluster_refactor(hammer2_cluster_t *cluster);
1008 void hammer2_cluster_unlock(hammer2_cluster_t *cluster);
1009 void hammer2_cluster_resize(hammer2_trans_t *trans, hammer2_inode_t *ip,
1010                         hammer2_cluster_t *cparent, hammer2_cluster_t *cluster,
1011                         int nradix, int flags);
1012 hammer2_inode_data_t *hammer2_cluster_modify_ip(hammer2_trans_t *trans,
1013                         hammer2_inode_t *ip, hammer2_cluster_t *cluster,
1014                         int flags);
1015 void hammer2_cluster_modify(hammer2_trans_t *trans, hammer2_cluster_t *cluster,
1016                         int flags);
1017 hammer2_cluster_t *hammer2_cluster_lookup_init(hammer2_cluster_t *cparent,
1018                         int flags);
1019 void hammer2_cluster_lookup_done(hammer2_cluster_t *cparent);
1020 hammer2_cluster_t *hammer2_cluster_lookup(hammer2_cluster_t *cparent,
1021                         hammer2_key_t *key_nextp,
1022                         hammer2_key_t key_beg, hammer2_key_t key_end,
1023                         int flags, int *ddflagp);
1024 hammer2_cluster_t *hammer2_cluster_next(hammer2_cluster_t *cparent,
1025                         hammer2_cluster_t *cluster,
1026                         hammer2_key_t *key_nextp,
1027                         hammer2_key_t key_beg, hammer2_key_t key_end,
1028                         int flags);
1029 hammer2_cluster_t *hammer2_cluster_scan(hammer2_cluster_t *cparent,
1030                         hammer2_cluster_t *cluster, int flags);
1031 int hammer2_cluster_create(hammer2_trans_t *trans, hammer2_cluster_t *cparent,
1032                         hammer2_cluster_t **clusterp,
1033                         hammer2_key_t key, int keybits, int type, size_t bytes);
1034 void hammer2_cluster_duplicate(hammer2_trans_t *trans,
1035                         hammer2_cluster_t *cparent, hammer2_cluster_t *cluster,
1036                         hammer2_blockref_t *bref,
1037                         int snapshot, int duplicate_reason);
1038 void hammer2_cluster_delete_duplicate(hammer2_trans_t *trans,
1039                         hammer2_cluster_t *cluster, int flags);
1040 void hammer2_cluster_delete(hammer2_trans_t *trans, hammer2_cluster_t *cluster,
1041                         int flags);
1042 int hammer2_cluster_snapshot(hammer2_trans_t *trans,
1043                         hammer2_cluster_t *ocluster, hammer2_ioc_pfs_t *pfs);
1044
1045 #endif /* !_KERNEL */
1046 #endif /* !_VFS_HAMMER2_HAMMER2_H_ */