909654951efd91337a430b188c800646837c928e
[dragonfly.git] / sys / vfs / hammer2 / hammer2.h
1 /*
2  * Copyright (c) 2011-2013 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  * This header file contains structures used internally by the HAMMER2
38  * implementation.  See hammer2_disk.h for on-disk structures.
39  */
40
41 #ifndef _VFS_HAMMER2_HAMMER2_H_
42 #define _VFS_HAMMER2_HAMMER2_H_
43
44 #include <sys/param.h>
45 #include <sys/types.h>
46 #include <sys/kernel.h>
47 #include <sys/conf.h>
48 #include <sys/systm.h>
49 #include <sys/tree.h>
50 #include <sys/malloc.h>
51 #include <sys/mount.h>
52 #include <sys/vnode.h>
53 #include <sys/proc.h>
54 #include <sys/mountctl.h>
55 #include <sys/priv.h>
56 #include <sys/stat.h>
57 #include <sys/thread.h>
58 #include <sys/globaldata.h>
59 #include <sys/lockf.h>
60 #include <sys/buf.h>
61 #include <sys/queue.h>
62 #include <sys/limits.h>
63 #include <sys/buf2.h>
64 #include <sys/signal2.h>
65 #include <sys/dmsg.h>
66
67 #include "hammer2_disk.h"
68 #include "hammer2_mount.h"
69 #include "hammer2_ioctl.h"
70 #include "hammer2_ccms.h"
71
72 struct hammer2_chain;
73 struct hammer2_inode;
74 struct hammer2_mount;
75 struct hammer2_pfsmount;
76 struct hammer2_span;
77 struct hammer2_state;
78 struct hammer2_msg;
79
80 /*
81  * The chain structure tracks blockref recursions all the way to the root
82  * volume.  These consist of indirect blocks, inodes, and eventually the
83  * volume header itself.
84  *
85  * In situations where a duplicate is needed to represent different snapshots
86  * or flush points a new chain will be allocated but associated with the
87  * same shared chain_core.  The RBTREE is contained in the shared chain_core
88  * and entries in the RBTREE are versioned.
89  *
90  * Duplication can occur whenever a chain must be modified.  Note that
91  * a deletion is not considered a modification.
92  *
93  *      (a) General modifications at data leafs
94  *      (b) When a chain is resized
95  *      (c) When a chain's blockref array is updated
96  *      (d) When a chain is renamed
97  *      (e) When a chain is moved (when an indirect block is split)
98  *
99  * Advantages:
100  *
101  *      (1) Fully coherent snapshots can be taken without requiring
102  *          a pre-flush, resulting in extremely fast (sub-millisecond)
103  *          snapshots.
104  *
105  *      (2) Multiple synchronization points can be in-flight at the same
106  *          time, representing multiple snapshots or flushes.
107  *
108  *      (3) The algorithms needed to keep track of everything are actually
109  *          not that complex.
110  *
111  * Special Considerations:
112  *
113  *      A chain is ref-counted on a per-chain basis, but the chain's lock
114  *      is associated with the shared chain_core and is not per-chain.
115  *
116  *      Each chain is representative of a filesystem topology.  Even
117  *      though the shared chain_core's are effectively multi-homed, the
118  *      chain structure is not.
119  *
120  *      chain->parent is a stable pointer and can be iterated without locking
121  *      as long as either the chain or *any* deep child under the chain
122  *      is held.
123  */
124 RB_HEAD(hammer2_chain_tree, hammer2_chain);
125 TAILQ_HEAD(flush_deferral_list, hammer2_chain);
126
127 struct hammer2_chain_core {
128         struct ccms_cst cst;
129         struct hammer2_chain_tree rbtree;
130         struct hammer2_chain    *first_parent;
131         u_int           sharecnt;
132         u_int           flags;
133 };
134
135 typedef struct hammer2_chain_core hammer2_chain_core_t;
136
137 #define HAMMER2_CORE_INDIRECT           0x0001
138
139 struct hammer2_chain {
140         RB_ENTRY(hammer2_chain) rbnode;
141         hammer2_blockref_t      bref;
142         hammer2_chain_core_t    *core;
143         hammer2_chain_core_t    *above;
144         struct hammer2_chain    *next_parent;
145         struct hammer2_state    *state;         /* if active cache msg */
146         struct hammer2_mount    *hmp;
147
148         hammer2_tid_t   modify_tid;             /* snapshot/flush filter */
149         hammer2_tid_t   delete_tid;
150         hammer2_key_t   data_count;             /* delta's to apply */
151         hammer2_key_t   inode_count;            /* delta's to apply */
152         struct buf      *bp;                    /* physical data buffer */
153         u_int           bytes;                  /* physical data size */
154         int             index;                  /* blockref index in parent */
155         u_int           flags;
156         u_int           refs;
157         u_int           lockcnt;
158         hammer2_media_data_t *data;             /* data pointer shortcut */
159         TAILQ_ENTRY(hammer2_chain) flush_node;  /* flush deferral list */
160 };
161
162 typedef struct hammer2_chain hammer2_chain_t;
163
164 int hammer2_chain_cmp(hammer2_chain_t *chain1, hammer2_chain_t *chain2);
165 RB_PROTOTYPE(hammer2_chain_tree, hammer2_chain, rbnode, hammer2_chain_cmp);
166
167 /*
168  * Special notes on flags:
169  *
170  * INITIAL - This flag allows a chain to be created and for storage to
171  *           be allocated without having to immediately instantiate the
172  *           related buffer.  The data is assumed to be all-zeros.  It
173  *           is primarily used for indirect blocks.
174  *
175  * MOVED   - A modified chain becomes MOVED after it flushes.  A chain
176  *           can also become MOVED if it is moved within the topology
177  *           (even if not modified).
178  */
179 #define HAMMER2_CHAIN_MODIFIED          0x00000001      /* dirty chain data */
180 #define HAMMER2_CHAIN_ALLOCATED         0x00000002      /* kmalloc'd chain */
181 #define HAMMER2_CHAIN_DIRTYBP           0x00000004      /* dirty on unlock */
182 #define HAMMER2_CHAIN_SUBMODIFIED       0x00000008      /* recursive flush */
183 #define HAMMER2_CHAIN_DELETED           0x00000010      /* deleted chain */
184 #define HAMMER2_CHAIN_INITIAL           0x00000020      /* initial create */
185 #define HAMMER2_CHAIN_FLUSHED           0x00000040      /* flush on unlock */
186 #define HAMMER2_CHAIN_MOVED             0x00000080      /* bref changed */
187 #define HAMMER2_CHAIN_IOFLUSH           0x00000100      /* bawrite on put */
188 #define HAMMER2_CHAIN_DEFERRED          0x00000200      /* on a deferral list */
189 #define HAMMER2_CHAIN_DESTROYED         0x00000400      /* destroying inode */
190 #define HAMMER2_CHAIN_VOLUMESYNC        0x00000800      /* needs volume sync */
191 #define HAMMER2_CHAIN_RECYCLE           0x00001000      /* force recycle */
192 #define HAMMER2_CHAIN_MOUNTED           0x00002000      /* PFS is mounted */
193 #define HAMMER2_CHAIN_ONRBTREE          0x00004000      /* on parent RB tree */
194 #define HAMMER2_CHAIN_SNAPSHOT          0x00008000      /* snapshot special */
195 #define HAMMER2_CHAIN_EMBEDDED          0x00010000      /* embedded data */
196
197 /*
198  * Flags passed to hammer2_chain_lookup() and hammer2_chain_next()
199  *
200  * NOTE: MATCHIND allows an indirect block / freemap node to be returned
201  *       when the passed key range matches the radix.  Remember that key_end
202  *       is inclusive (e.g. {0x000,0xFFF}, not {0x000,0x1000}).
203  */
204 #define HAMMER2_LOOKUP_NOLOCK           0x00000001      /* ref only */
205 #define HAMMER2_LOOKUP_NODATA           0x00000002      /* data left NULL */
206 #define HAMMER2_LOOKUP_SHARED           0x00000100
207 #define HAMMER2_LOOKUP_MATCHIND         0x00000200
208 #define HAMMER2_LOOKUP_FREEMAP          0x00000400      /* freemap base */
209 #define HAMMER2_LOOKUP_ALWAYS           0x00000800      /* resolve data */
210
211 /*
212  * Flags passed to hammer2_chain_modify() and hammer2_chain_resize()
213  *
214  * NOTE: OPTDATA allows us to avoid instantiating buffers for INDIRECT
215  *       blocks in the INITIAL-create state.
216  */
217 #define HAMMER2_MODIFY_OPTDATA          0x00000002      /* data can be NULL */
218 #define HAMMER2_MODIFY_NO_MODIFY_TID    0x00000004
219 #define HAMMER2_MODIFY_ASSERTNOCOPY     0x00000008
220 #define HAMMER2_MODIFY_NOREALLOC        0x00000010
221
222 /*
223  * Flags passed to hammer2_chain_lock()
224  */
225 #define HAMMER2_RESOLVE_NEVER           1
226 #define HAMMER2_RESOLVE_MAYBE           2
227 #define HAMMER2_RESOLVE_ALWAYS          3
228 #define HAMMER2_RESOLVE_MASK            0x0F
229
230 #define HAMMER2_RESOLVE_SHARED          0x10    /* request shared lock */
231 #define HAMMER2_RESOLVE_NOREF           0x20    /* already ref'd on lock */
232
233 /*
234  * Flags passed to hammer2_chain_delete()
235  */
236 #define HAMMER2_DELETE_WILLDUP          0x0001  /* no blk free, will be dup */
237
238 /*
239  * Flags passed to hammer2_chain_delete_duplicate()
240  */
241 #define HAMMER2_DELDUP_RECORE           0x0001
242
243 /*
244  * Cluster different types of storage together for allocations
245  */
246 #define HAMMER2_FREECACHE_INODE         0
247 #define HAMMER2_FREECACHE_INDIR         1
248 #define HAMMER2_FREECACHE_DATA          2
249 #define HAMMER2_FREECACHE_UNUSED3       3
250 #define HAMMER2_FREECACHE_TYPES         4
251
252 /*
253  * hammer2_freemap_alloc() block preference
254  */
255 #define HAMMER2_OFF_NOPREF              ((hammer2_off_t)-1)
256
257 /*
258  * BMAP read-ahead maximum parameters
259  */
260 #define HAMMER2_BMAP_COUNT              16      /* max bmap read-ahead */
261 #define HAMMER2_BMAP_BYTES              (HAMMER2_PBUFSIZE * HAMMER2_BMAP_COUNT)
262
263 /*
264  * Misc
265  */
266 #define HAMMER2_FLUSH_DEPTH_LIMIT       40      /* stack recursion limit */
267
268 /*
269  * HAMMER2 IN-MEMORY CACHE OF MEDIA STRUCTURES
270  *
271  * There is an in-memory representation of all on-media data structure.
272  *
273  * When accessed read-only the data will be mapped to the related buffer
274  * cache buffer.
275  *
276  * When accessed read-write (marked modified) a kmalloc()'d copy of the
277  * is created which can then be modified.  The copy is destroyed when a
278  * filesystem block is allocated to replace it.
279  *
280  * Active inodes (those with vnodes attached) will maintain the kmalloc()'d
281  * copy for both the read-only and the read-write case.  The combination of
282  * (bp) and (data) determines whether (data) was allocated or not.
283  *
284  * The in-memory representation may remain cached (for example in order to
285  * placemark clustering locks) even after the related data has been
286  * detached.
287  */
288
289 RB_HEAD(hammer2_inode_tree, hammer2_inode);
290
291 /*
292  * A hammer2 inode.
293  *
294  * NOTE: The inode's attribute CST which is also used to lock the inode
295  *       is embedded in the chain (chain.cst) and aliased w/ attr_cst.
296  */
297 struct hammer2_inode {
298         RB_ENTRY(hammer2_inode) rbnode;         /* inumber lookup (HL) */
299         ccms_cst_t              topo_cst;       /* directory topology cst */
300         struct hammer2_pfsmount *pmp;           /* PFS mount */
301         struct hammer2_inode    *pip;           /* parent inode */
302         struct vnode            *vp;
303         hammer2_chain_t         *chain;         /* NOTE: rehomed on rename */
304         struct lockf            advlock;
305         hammer2_tid_t           inum;
306         u_int                   flags;
307         u_int                   refs;           /* +vpref, +flushref */
308 };
309
310 typedef struct hammer2_inode hammer2_inode_t;
311
312 #define HAMMER2_INODE_MODIFIED          0x0001
313 #define HAMMER2_INODE_SROOT             0x0002  /* kmalloc special case */
314 #define HAMMER2_INODE_RENAME_INPROG     0x0004
315 #define HAMMER2_INODE_ONRBTREE          0x0008
316
317 int hammer2_inode_cmp(hammer2_inode_t *ip1, hammer2_inode_t *ip2);
318 RB_PROTOTYPE2(hammer2_inode_tree, hammer2_inode, rbnode, hammer2_inode_cmp,
319                 hammer2_tid_t);
320
321 /*
322  * A hammer2 transaction and flush sequencing structure.
323  *
324  * This global structure is tied into hammer2_mount and is used
325  * to sequence modifying operations and flushes.
326  *
327  * (a) Any modifying operations with sync_tid >= flush_tid will stall until
328  *     all modifying operating with sync_tid < flush_tid complete.
329  *
330  *     The flush related to flush_tid stalls until all modifying operations
331  *     with sync_tid < flush_tid complete.
332  *
333  * (b) Once unstalled, modifying operations with sync_tid > flush_tid are
334  *     allowed to run.  All modifications cause modify/duplicate operations
335  *     to occur on the related chains.  Note that most INDIRECT blocks will
336  *     be unaffected because the modifications just overload the RBTREE
337  *     structurally instead of actually modifying the indirect blocks.
338  *
339  * (c) The actual flush unstalls and RUNS CONCURRENTLY with (b), but only
340  *     utilizes the chain structures with sync_tid <= flush_tid.  The
341  *     flush will modify related indirect blocks and inodes in-place
342  *     (rather than duplicate) since the adjustments are compatible with
343  *     (b)'s RBTREE overloading
344  *
345  *     SPECIAL NOTE:  Inode modifications have to also propagate along any
346  *                    modify/duplicate chains.  File writes detect the flush
347  *                    and force out the conflicting buffer cache buffer(s)
348  *                    before reusing them.
349  *
350  * (d) Snapshots can be made instantly but must be flushed and disconnected
351  *     from their duplicative source before they can be mounted.  This is
352  *     because while H2's on-media structure supports forks, its in-memory
353  *     structure only supports very simple forking for background flushing
354  *     purposes.
355  *
356  * TODO: Flush merging.  When fsync() is called on multiple discrete files
357  *       concurrently there is no reason to stall the second fsync.
358  *       The final flush that reaches to root can cover both fsync()s.
359  *
360  *     The chains typically terminate as they fly onto the disk.  The flush
361  *     ultimately reaches the volume header.
362  */
363 struct hammer2_trans {
364         TAILQ_ENTRY(hammer2_trans) entry;
365         struct hammer2_pfsmount *pmp;
366         hammer2_tid_t           sync_tid;
367         thread_t                td;             /* pointer */
368         int                     flags;
369         int                     blocked;
370         uint8_t                 inodes_created;
371         uint8_t                 dummy[7];
372 };
373
374 typedef struct hammer2_trans hammer2_trans_t;
375
376 #define HAMMER2_TRANS_ISFLUSH           0x0001
377 #define HAMMER2_TRANS_RESTRICTED        0x0002  /* snapshot flush restrict */
378
379 #define HAMMER2_FREEMAP_HEUR_NRADIX     4       /* pwr 2 PBUFRADIX-MINIORADIX */
380 #define HAMMER2_FREEMAP_HEUR_TYPES      8
381 #define HAMMER2_FREEMAP_HEUR            (HAMMER2_FREEMAP_HEUR_NRADIX * \
382                                          HAMMER2_FREEMAP_HEUR_TYPES)
383
384 /*
385  * Global (per device) mount structure for device (aka vp->v_mount->hmp)
386  */
387 TAILQ_HEAD(hammer2_trans_queue, hammer2_trans);
388
389 struct hammer2_mount {
390         struct vnode    *devvp;         /* device vnode */
391         int             ronly;          /* read-only mount */
392         int             pmp_count;      /* PFS mounts backed by us */
393         TAILQ_ENTRY(hammer2_mount) mntentry; /* hammer2_mntlist */
394
395         struct malloc_type *mchain;
396         int             nipstacks;
397         int             maxipstacks;
398         hammer2_chain_t vchain;         /* anchor chain */
399         hammer2_chain_t fchain;         /* freemap chain special */
400         hammer2_chain_t *schain;        /* super-root */
401         hammer2_inode_t *sroot;         /* super-root inode */
402         struct lock     alloclk;        /* lockmgr lock */
403         struct lock     voldatalk;      /* lockmgr lock */
404         struct hammer2_trans_queue transq; /* all in-progress transactions */
405         hammer2_trans_t *curflush;      /* current flush in progress */
406         hammer2_tid_t   topo_flush_tid; /* currently synchronizing flush pt */
407         hammer2_tid_t   free_flush_tid; /* currently synchronizing flush pt */
408         hammer2_off_t   heur_freemap[HAMMER2_FREEMAP_HEUR];
409         int             flushcnt;       /* #of flush trans on the list */
410
411         int             volhdrno;       /* last volhdrno written */
412         hammer2_volume_data_t voldata;
413         hammer2_volume_data_t volsync;  /* synchronized voldata */
414 };
415
416 typedef struct hammer2_mount hammer2_mount_t;
417
418 /*
419  * HAMMER2 cluster - a device/root associated with a PFS.
420  *
421  * A PFS may have several hammer2_cluster's associated with it.
422  */
423 struct hammer2_cluster {
424         struct hammer2_mount    *hmp;           /* device global mount */
425         hammer2_chain_t         *rchain;        /* PFS root chain */
426 };
427
428 typedef struct hammer2_cluster hammer2_cluster_t;
429
430 /*
431  * HAMMER2 PFS mount point structure (aka vp->v_mount->mnt_data).
432  *
433  * This structure represents a cluster mount and not necessarily a
434  * PFS under a specific device mount (HMP).  The distinction is important
435  * because the elements backing a cluster mount can change on the fly.
436  */
437 struct hammer2_pfsmount {
438         struct mount            *mp;            /* kernel mount */
439         hammer2_cluster_t       *mount_cluster;
440         hammer2_cluster_t       *cluster;
441         hammer2_inode_t         *iroot;         /* PFS root inode */
442         hammer2_off_t           inode_count;    /* copy of inode_count */
443         ccms_domain_t           ccms_dom;
444         struct netexport        export;         /* nfs export */
445         int                     ronly;          /* read-only mount */
446         struct malloc_type      *minode;
447         struct malloc_type      *mmsg;
448         kdmsg_iocom_t           iocom;
449         struct spinlock         inum_spin;      /* inumber lookup */
450         struct hammer2_inode_tree inum_tree;
451 };
452
453 typedef struct hammer2_pfsmount hammer2_pfsmount_t;
454
455 struct hammer2_cbinfo {
456         hammer2_chain_t *chain;
457         void (*func)(hammer2_chain_t *, struct buf *, char *, void *);
458         void *arg;
459         size_t boff;
460 };
461
462 typedef struct hammer2_cbinfo hammer2_cbinfo_t;
463
464 #if defined(_KERNEL)
465
466 MALLOC_DECLARE(M_HAMMER2);
467
468 #define VTOI(vp)        ((hammer2_inode_t *)(vp)->v_data)
469 #define ITOV(ip)        ((ip)->vp)
470
471 /*
472  * Currently locked chains retain the locked buffer cache buffer for
473  * indirect blocks, and indirect blocks can be one of two sizes.  The
474  * device buffer has to match the case to avoid deadlocking recursive
475  * chains that might otherwise try to access different offsets within
476  * the same device buffer.
477  */
478 static __inline
479 int
480 hammer2_devblkradix(int radix)
481 {
482 #if 1
483         if (radix <= HAMMER2_LBUFRADIX) {
484                 return (HAMMER2_LBUFRADIX);
485         } else {
486                 return (HAMMER2_PBUFRADIX);
487         }
488 #else
489         return (HAMMER2_PBUFRADIX);
490 #endif
491 }
492
493 static __inline
494 size_t
495 hammer2_devblksize(size_t bytes)
496 {
497 #if 1
498         if (bytes <= HAMMER2_LBUFSIZE) {
499                 return(HAMMER2_LBUFSIZE);
500         } else {
501                 KKASSERT(bytes <= HAMMER2_PBUFSIZE &&
502                          (bytes ^ (bytes - 1)) == ((bytes << 1) - 1));
503                 return (HAMMER2_PBUFSIZE);
504         }
505 #else
506         KKASSERT(bytes <= HAMMER2_PBUFSIZE &&
507                  (bytes ^ (bytes - 1)) == ((bytes << 1) - 1));
508         return(HAMMER2_PBUFSIZE);
509 #endif
510 }
511
512
513 static __inline
514 hammer2_pfsmount_t *
515 MPTOPMP(struct mount *mp)
516 {
517         return ((hammer2_pfsmount_t *)mp->mnt_data);
518 }
519
520 static __inline
521 hammer2_mount_t *
522 MPTOHMP(struct mount *mp)
523 {
524         return (((hammer2_pfsmount_t *)mp->mnt_data)->cluster->hmp);
525 }
526
527 static __inline
528 int
529 hammer2_chain_refactor_test(hammer2_chain_t *chain, int traverse_hlink)
530 {
531         if ((chain->flags & HAMMER2_CHAIN_DELETED) &&
532             chain->next_parent &&
533             (chain->next_parent->flags & HAMMER2_CHAIN_SNAPSHOT) == 0) {
534                 return (1);
535         }
536         if (traverse_hlink &&
537             chain->bref.type == HAMMER2_BREF_TYPE_INODE &&
538             chain->data->ipdata.type == HAMMER2_OBJTYPE_HARDLINK &&
539             chain->next_parent &&
540             (chain->next_parent->flags & HAMMER2_CHAIN_SNAPSHOT) == 0) {
541                 return(1);
542         }
543
544         return (0);
545 }
546
547 extern struct vop_ops hammer2_vnode_vops;
548 extern struct vop_ops hammer2_spec_vops;
549 extern struct vop_ops hammer2_fifo_vops;
550
551 extern int hammer2_debug;
552 extern int hammer2_cluster_enable;
553 extern int hammer2_hardlink_enable;
554 extern long hammer2_iod_file_read;
555 extern long hammer2_iod_meta_read;
556 extern long hammer2_iod_indr_read;
557 extern long hammer2_iod_fmap_read;
558 extern long hammer2_iod_volu_read;
559 extern long hammer2_iod_file_write;
560 extern long hammer2_iod_meta_write;
561 extern long hammer2_iod_indr_write;
562 extern long hammer2_iod_fmap_write;
563 extern long hammer2_iod_volu_write;
564 extern long hammer2_ioa_file_read;
565 extern long hammer2_ioa_meta_read;
566 extern long hammer2_ioa_indr_read;
567 extern long hammer2_ioa_fmap_read;
568 extern long hammer2_ioa_volu_read;
569 extern long hammer2_ioa_file_write;
570 extern long hammer2_ioa_meta_write;
571 extern long hammer2_ioa_indr_write;
572 extern long hammer2_ioa_fmap_write;
573 extern long hammer2_ioa_volu_write;
574
575 /*
576  * hammer2_subr.c
577  */
578 #define hammer2_icrc32(buf, size)       iscsi_crc32((buf), (size))
579 #define hammer2_icrc32c(buf, size, crc) iscsi_crc32_ext((buf), (size), (crc))
580
581 hammer2_chain_t *hammer2_inode_lock_ex(hammer2_inode_t *ip);
582 hammer2_chain_t *hammer2_inode_lock_sh(hammer2_inode_t *ip);
583 void hammer2_inode_unlock_ex(hammer2_inode_t *ip, hammer2_chain_t *chain);
584 void hammer2_inode_unlock_sh(hammer2_inode_t *ip, hammer2_chain_t *chain);
585 void hammer2_voldata_lock(hammer2_mount_t *hmp);
586 void hammer2_voldata_unlock(hammer2_mount_t *hmp, int modify);
587 ccms_state_t hammer2_inode_lock_temp_release(hammer2_inode_t *ip);
588 void hammer2_inode_lock_temp_restore(hammer2_inode_t *ip, ccms_state_t ostate);
589 ccms_state_t hammer2_inode_lock_upgrade(hammer2_inode_t *ip);
590 void hammer2_inode_lock_downgrade(hammer2_inode_t *ip, ccms_state_t ostate);
591
592 void hammer2_mount_exlock(hammer2_mount_t *hmp);
593 void hammer2_mount_shlock(hammer2_mount_t *hmp);
594 void hammer2_mount_unlock(hammer2_mount_t *hmp);
595
596 int hammer2_get_dtype(hammer2_chain_t *chain);
597 int hammer2_get_vtype(hammer2_chain_t *chain);
598 u_int8_t hammer2_get_obj_type(enum vtype vtype);
599 void hammer2_time_to_timespec(u_int64_t xtime, struct timespec *ts);
600 u_int64_t hammer2_timespec_to_time(struct timespec *ts);
601 u_int32_t hammer2_to_unix_xid(uuid_t *uuid);
602 void hammer2_guid_to_uuid(uuid_t *uuid, u_int32_t guid);
603
604 hammer2_key_t hammer2_dirhash(const unsigned char *name, size_t len);
605 int hammer2_getradix(size_t bytes);
606
607 int hammer2_calc_logical(hammer2_inode_t *ip, hammer2_off_t uoff,
608                          hammer2_key_t *lbasep, hammer2_key_t *leofp);
609 void hammer2_update_time(uint64_t *timep);
610
611 /*
612  * hammer2_inode.c
613  */
614 struct vnode *hammer2_igetv(hammer2_inode_t *ip, int *errorp);
615
616 void hammer2_inode_lock_nlinks(hammer2_inode_t *ip);
617 void hammer2_inode_unlock_nlinks(hammer2_inode_t *ip);
618 hammer2_inode_t *hammer2_inode_lookup(hammer2_pfsmount_t *pmp,
619                         hammer2_tid_t inum);
620 hammer2_inode_t *hammer2_inode_get(hammer2_pfsmount_t *pmp,
621                         hammer2_inode_t *dip, hammer2_chain_t *chain);
622 void hammer2_inode_free(hammer2_inode_t *ip);
623 void hammer2_inode_ref(hammer2_inode_t *ip);
624 void hammer2_inode_drop(hammer2_inode_t *ip);
625 void hammer2_inode_repoint(hammer2_inode_t *ip, hammer2_inode_t *pip,
626                         hammer2_chain_t *chain);
627
628 hammer2_inode_t *hammer2_inode_create(hammer2_trans_t *trans,
629                         hammer2_inode_t *dip,
630                         struct vattr *vap, struct ucred *cred,
631                         const uint8_t *name, size_t name_len,
632                         hammer2_chain_t **chainp, int *errorp);
633 int hammer2_inode_connect(hammer2_trans_t *trans, int hlink,
634                         hammer2_inode_t *dip, hammer2_chain_t **chainp,
635                         const uint8_t *name, size_t name_len);
636 hammer2_inode_t *hammer2_inode_common_parent(hammer2_inode_t *fdip,
637                         hammer2_inode_t *tdip);
638
639 int hammer2_unlink_file(hammer2_trans_t *trans, hammer2_inode_t *dip,
640                         const uint8_t *name, size_t name_len, int isdir,
641                         int *hlinkp);
642 int hammer2_hardlink_consolidate(hammer2_trans_t *trans, hammer2_inode_t *ip,
643                         hammer2_chain_t **chainp,
644                         hammer2_inode_t *tdip, int linkcnt);
645 int hammer2_hardlink_deconsolidate(hammer2_trans_t *trans, hammer2_inode_t *dip,
646                         hammer2_chain_t **chainp, hammer2_chain_t **ochainp);
647 int hammer2_hardlink_find(hammer2_inode_t *dip,
648                         hammer2_chain_t **chainp, hammer2_chain_t **ochainp);
649
650 /*
651  * hammer2_chain.c
652  */
653 void hammer2_modify_volume(hammer2_mount_t *hmp);
654 hammer2_chain_t *hammer2_chain_alloc(hammer2_mount_t *hmp,
655                                 hammer2_trans_t *trans,
656                                 hammer2_blockref_t *bref);
657 void hammer2_chain_core_alloc(hammer2_chain_t *chain,
658                                 hammer2_chain_core_t *core);
659 void hammer2_chain_ref(hammer2_chain_t *chain);
660 void hammer2_chain_drop(hammer2_chain_t *chain);
661 int hammer2_chain_lock(hammer2_chain_t *chain, int how);
662 void hammer2_chain_load_async(hammer2_chain_t *chain,
663                                 void (*func)(hammer2_chain_t *, struct buf *,
664                                              char *, void *),
665                                 void *arg);
666 void hammer2_chain_moved(hammer2_chain_t *chain);
667 void hammer2_chain_modify(hammer2_trans_t *trans,
668                                 hammer2_chain_t **chainp, int flags);
669 hammer2_inode_data_t *hammer2_chain_modify_ip(hammer2_trans_t *trans,
670                                 hammer2_inode_t *ip, hammer2_chain_t **chainp,
671                                 int flags);
672 void hammer2_chain_resize(hammer2_trans_t *trans, hammer2_inode_t *ip,
673                                 struct buf *bp,
674                                 hammer2_chain_t *parent,
675                                 hammer2_chain_t **chainp,
676                                 int nradix, int flags);
677 void hammer2_chain_unlock(hammer2_chain_t *chain);
678 void hammer2_chain_wait(hammer2_chain_t *chain);
679 hammer2_chain_t *hammer2_chain_find(hammer2_chain_t *parent, int index);
680 hammer2_chain_t *hammer2_chain_get(hammer2_chain_t *parent, int index,
681                                 int flags);
682 hammer2_chain_t *hammer2_chain_lookup_init(hammer2_chain_t *parent, int flags);
683 void hammer2_chain_lookup_done(hammer2_chain_t *parent);
684 hammer2_chain_t *hammer2_chain_lookup(hammer2_chain_t **parentp,
685                                 hammer2_key_t key_beg, hammer2_key_t key_end,
686                                 int flags);
687 hammer2_chain_t *hammer2_chain_next(hammer2_chain_t **parentp,
688                                 hammer2_chain_t *chain,
689                                 hammer2_key_t key_beg, hammer2_key_t key_end,
690                                 int flags);
691 int hammer2_chain_iterate(hammer2_chain_t *parent,
692                           int (*callback)(hammer2_chain_t *parent,
693                                           hammer2_chain_t **chainp,
694                                           void *arg),
695                           void *arg, int flags);
696
697 int hammer2_chain_create(hammer2_trans_t *trans,
698                                 hammer2_chain_t **parentp,
699                                 hammer2_chain_t **chainp,
700                                 hammer2_key_t key, int keybits,
701                                 int type, size_t bytes);
702 void hammer2_chain_duplicate(hammer2_trans_t *trans, hammer2_chain_t *parent,
703                                 int i,
704                                 hammer2_chain_t **chainp,
705                                 hammer2_blockref_t *bref);
706 int hammer2_chain_snapshot(hammer2_trans_t *trans, hammer2_inode_t *ip,
707                                 hammer2_ioc_pfs_t *pfs);
708 void hammer2_chain_delete(hammer2_trans_t *trans, hammer2_chain_t *chain,
709                                 int flags);
710 void hammer2_chain_delete_duplicate(hammer2_trans_t *trans,
711                                 hammer2_chain_t **chainp, int flags);
712 void hammer2_chain_flush(hammer2_trans_t *trans, hammer2_chain_t *chain);
713 void hammer2_chain_commit(hammer2_trans_t *trans, hammer2_chain_t *chain);
714 void hammer2_chain_setsubmod(hammer2_trans_t *trans, hammer2_chain_t *chain);
715
716 /*
717  * hammer2_trans.c
718  */
719 void hammer2_trans_init(hammer2_trans_t *trans,
720                         hammer2_pfsmount_t *pmp, int flags);
721 void hammer2_trans_done(hammer2_trans_t *trans);
722
723 /*
724  * hammer2_ioctl.c
725  */
726 int hammer2_ioctl(hammer2_inode_t *ip, u_long com, void *data,
727                                 int fflag, struct ucred *cred);
728
729 /*
730  * hammer2_msgops.c
731  */
732 int hammer2_msg_dbg_rcvmsg(kdmsg_msg_t *msg);
733 int hammer2_msg_adhoc_input(kdmsg_msg_t *msg);
734
735 /*
736  * hammer2_vfsops.c
737  */
738 void hammer2_clusterctl_wakeup(kdmsg_iocom_t *iocom);
739 void hammer2_volconf_update(hammer2_pfsmount_t *pmp, int index);
740 void hammer2_cluster_reconnect(hammer2_pfsmount_t *pmp, struct file *fp);
741 void hammer2_dump_chain(hammer2_chain_t *chain, int tab, int *countp);
742
743 /*
744  * hammer2_freemap.c
745  */
746 int hammer2_freemap_alloc(hammer2_trans_t *trans, hammer2_mount_t *hmp,
747                                 hammer2_blockref_t *bref, size_t bytes);
748 void hammer2_freemap_free(hammer2_trans_t *trans, hammer2_mount_t *hmp,
749                                 hammer2_blockref_t *bref, int how);
750
751
752 #endif /* !_KERNEL */
753 #endif /* !_VFS_HAMMER2_HAMMER2_H_ */