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