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