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