b7202b12e870e9a94c0147f593f11d3db9271fa8
[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/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_pfsmount *pmp;           /* PFS mount */
299         struct hammer2_inode    *pip;           /* parent inode */
300         struct vnode            *vp;
301         hammer2_chain_t         *chain;         /* NOTE: rehomed on rename */
302         struct lockf            advlock;
303         hammer2_tid_t           inum;
304         u_int                   flags;
305         u_int                   refs;           /* +vpref, +flushref */
306 };
307
308 typedef struct hammer2_inode hammer2_inode_t;
309
310 #define HAMMER2_INODE_MODIFIED          0x0001
311 #define HAMMER2_INODE_SROOT             0x0002  /* kmalloc special case */
312 #define HAMMER2_INODE_RENAME_INPROG     0x0004
313 #define HAMMER2_INODE_ONRBTREE          0x0008
314
315 int hammer2_inode_cmp(hammer2_inode_t *ip1, hammer2_inode_t *ip2);
316 RB_PROTOTYPE2(hammer2_inode_tree, hammer2_inode, rbnode, hammer2_inode_cmp,
317                 hammer2_tid_t);
318
319 /*
320  * A hammer2 transaction and flush sequencing structure.
321  *
322  * This global structure is tied into hammer2_mount and is used
323  * to sequence modifying operations and flushes.
324  *
325  * (a) Any modifying operations with sync_tid >= flush_tid will stall until
326  *     all modifying operating with sync_tid < flush_tid complete.
327  *
328  *     The flush related to flush_tid stalls until all modifying operations
329  *     with sync_tid < flush_tid complete.
330  *
331  * (b) Once unstalled, modifying operations with sync_tid > flush_tid are
332  *     allowed to run.  All modifications cause modify/duplicate operations
333  *     to occur on the related chains.  Note that most INDIRECT blocks will
334  *     be unaffected because the modifications just overload the RBTREE
335  *     structurally instead of actually modifying the indirect blocks.
336  *
337  * (c) The actual flush unstalls and RUNS CONCURRENTLY with (b), but only
338  *     utilizes the chain structures with sync_tid <= flush_tid.  The
339  *     flush will modify related indirect blocks and inodes in-place
340  *     (rather than duplicate) since the adjustments are compatible with
341  *     (b)'s RBTREE overloading
342  *
343  *     SPECIAL NOTE:  Inode modifications have to also propagate along any
344  *                    modify/duplicate chains.  File writes detect the flush
345  *                    and force out the conflicting buffer cache buffer(s)
346  *                    before reusing them.
347  *
348  * (d) Snapshots can be made instantly but must be flushed and disconnected
349  *     from their duplicative source before they can be mounted.  This is
350  *     because while H2's on-media structure supports forks, its in-memory
351  *     structure only supports very simple forking for background flushing
352  *     purposes.
353  *
354  * TODO: Flush merging.  When fsync() is called on multiple discrete files
355  *       concurrently there is no reason to stall the second fsync.
356  *       The final flush that reaches to root can cover both fsync()s.
357  *
358  *     The chains typically terminate as they fly onto the disk.  The flush
359  *     ultimately reaches the volume header.
360  */
361 struct hammer2_trans {
362         TAILQ_ENTRY(hammer2_trans) entry;
363         struct hammer2_pfsmount *pmp;
364         hammer2_tid_t           sync_tid;
365         thread_t                td;             /* pointer */
366         int                     flags;
367         int                     blocked;
368         uint8_t                 inodes_created;
369         uint8_t                 dummy[7];
370 };
371
372 typedef struct hammer2_trans hammer2_trans_t;
373
374 #define HAMMER2_TRANS_ISFLUSH           0x0001
375 #define HAMMER2_TRANS_RESTRICTED        0x0002  /* snapshot flush restrict */
376
377 /*
378  * XXX
379  */
380 struct hammer2_freecache {
381         hammer2_off_t   bulk;
382         hammer2_off_t   single;
383 };
384
385 typedef struct hammer2_freecache hammer2_freecache_t;
386
387 /*
388  * Global (per device) mount structure for device (aka vp->v_mount->hmp)
389  */
390 TAILQ_HEAD(hammer2_trans_queue, hammer2_trans);
391
392 struct hammer2_mount {
393         struct vnode    *devvp;         /* device vnode */
394         int             ronly;          /* read-only mount */
395         int             pmp_count;      /* PFS mounts backed by us */
396         TAILQ_ENTRY(hammer2_mount) mntentry; /* hammer2_mntlist */
397
398         struct malloc_type *mchain;
399         int             nipstacks;
400         int             maxipstacks;
401         hammer2_chain_t vchain;         /* anchor chain */
402         hammer2_chain_t fchain;         /* freemap chain special */
403         hammer2_chain_t *schain;        /* super-root */
404         hammer2_inode_t *sroot;         /* super-root inode */
405         struct lock     alloclk;        /* lockmgr lock */
406         struct lock     voldatalk;      /* lockmgr lock */
407         struct hammer2_trans_queue transq; /* all in-progress transactions */
408         hammer2_trans_t *curflush;      /* current flush in progress */
409         hammer2_tid_t   topo_flush_tid; /* currently synchronizing flush pt */
410         hammer2_tid_t   free_flush_tid; /* currently synchronizing flush pt */
411         hammer2_off_t   heur_freemap[HAMMER2_MAX_RADIX+1];
412         int             flushcnt;       /* #of flush trans on the list */
413
414         int             volhdrno;       /* last volhdrno written */
415         hammer2_volume_data_t voldata;
416         hammer2_volume_data_t volsync;  /* synchronized voldata */
417         hammer2_freecache_t freecache[HAMMER2_FREECACHE_TYPES]
418                                      [HAMMER2_MAX_RADIX+1];
419 };
420
421 typedef struct hammer2_mount hammer2_mount_t;
422
423 /*
424  * HAMMER2 cluster - a device/root associated with a PFS.
425  *
426  * A PFS may have several hammer2_cluster's associated with it.
427  */
428 struct hammer2_cluster {
429         struct hammer2_mount    *hmp;           /* device global mount */
430         hammer2_chain_t         *rchain;        /* PFS root chain */
431 };
432
433 typedef struct hammer2_cluster hammer2_cluster_t;
434
435 /*
436  * HAMMER2 PFS mount point structure (aka vp->v_mount->mnt_data).
437  *
438  * This structure represents a cluster mount and not necessarily a
439  * PFS under a specific device mount (HMP).  The distinction is important
440  * because the elements backing a cluster mount can change on the fly.
441  */
442 struct hammer2_pfsmount {
443         struct mount            *mp;            /* kernel mount */
444         hammer2_cluster_t       *mount_cluster;
445         hammer2_cluster_t       *cluster;
446         hammer2_inode_t         *iroot;         /* PFS root inode */
447         hammer2_off_t           inode_count;    /* copy of inode_count */
448         ccms_domain_t           ccms_dom;
449         struct netexport        export;         /* nfs export */
450         int                     ronly;          /* read-only mount */
451         struct malloc_type      *minode;
452         struct malloc_type      *mmsg;
453         kdmsg_iocom_t           iocom;
454         struct spinlock         inum_spin;      /* inumber lookup */
455         struct hammer2_inode_tree inum_tree;
456 };
457
458 typedef struct hammer2_pfsmount hammer2_pfsmount_t;
459
460 struct hammer2_cbinfo {
461         hammer2_chain_t *chain;
462         void (*func)(hammer2_chain_t *, struct buf *, char *, void *);
463         void *arg;
464         size_t boff;
465 };
466
467 typedef struct hammer2_cbinfo hammer2_cbinfo_t;
468
469 #if defined(_KERNEL)
470
471 MALLOC_DECLARE(M_HAMMER2);
472
473 #define VTOI(vp)        ((hammer2_inode_t *)(vp)->v_data)
474 #define ITOV(ip)        ((ip)->vp)
475
476 static __inline
477 int
478 hammer2_devblkradix(int radix)
479 {
480         int cluster_radix;
481
482         if (radix <= HAMMER2_LBUFRADIX)
483                 cluster_radix = HAMMER2_LBUFRADIX;
484         else
485                 cluster_radix = HAMMER2_PBUFRADIX;
486         return(cluster_radix);
487 }
488
489 static __inline
490 size_t
491 hammer2_devblksize(size_t bytes)
492 {
493         if (bytes <= HAMMER2_LBUFSIZE) {
494                 return(HAMMER2_LBUFSIZE);
495         } else {
496                 KKASSERT(bytes <= HAMMER2_PBUFSIZE &&
497                          (bytes ^ (bytes - 1)) == ((bytes << 1) - 1));
498                 return(bytes);
499         }
500 }
501
502
503 static __inline
504 hammer2_pfsmount_t *
505 MPTOPMP(struct mount *mp)
506 {
507         return ((hammer2_pfsmount_t *)mp->mnt_data);
508 }
509
510 static __inline
511 hammer2_mount_t *
512 MPTOHMP(struct mount *mp)
513 {
514         return (((hammer2_pfsmount_t *)mp->mnt_data)->cluster->hmp);
515 }
516
517 static __inline
518 int
519 hammer2_chain_refactor_test(hammer2_chain_t *chain, int traverse_hlink)
520 {
521         if ((chain->flags & HAMMER2_CHAIN_DELETED) &&
522             chain->next_parent &&
523             (chain->next_parent->flags & HAMMER2_CHAIN_SNAPSHOT) == 0) {
524                 return (1);
525         }
526         if (traverse_hlink &&
527             chain->bref.type == HAMMER2_BREF_TYPE_INODE &&
528             chain->data->ipdata.type == HAMMER2_OBJTYPE_HARDLINK &&
529             chain->next_parent &&
530             (chain->next_parent->flags & HAMMER2_CHAIN_SNAPSHOT) == 0) {
531                 return(1);
532         }
533
534         return (0);
535 }
536
537 extern struct vop_ops hammer2_vnode_vops;
538 extern struct vop_ops hammer2_spec_vops;
539 extern struct vop_ops hammer2_fifo_vops;
540
541 extern int hammer2_debug;
542 extern int hammer2_cluster_enable;
543 extern int hammer2_hardlink_enable;
544 extern long hammer2_iod_file_read;
545 extern long hammer2_iod_meta_read;
546 extern long hammer2_iod_indr_read;
547 extern long hammer2_iod_fmap_read;
548 extern long hammer2_iod_volu_read;
549 extern long hammer2_iod_file_write;
550 extern long hammer2_iod_meta_write;
551 extern long hammer2_iod_indr_write;
552 extern long hammer2_iod_fmap_write;
553 extern long hammer2_iod_volu_write;
554 extern long hammer2_ioa_file_read;
555 extern long hammer2_ioa_meta_read;
556 extern long hammer2_ioa_indr_read;
557 extern long hammer2_ioa_fmap_read;
558 extern long hammer2_ioa_volu_read;
559 extern long hammer2_ioa_file_write;
560 extern long hammer2_ioa_meta_write;
561 extern long hammer2_ioa_indr_write;
562 extern long hammer2_ioa_fmap_write;
563 extern long hammer2_ioa_volu_write;
564
565 /*
566  * hammer2_subr.c
567  */
568 #define hammer2_icrc32(buf, size)       iscsi_crc32((buf), (size))
569 #define hammer2_icrc32c(buf, size, crc) iscsi_crc32_ext((buf), (size), (crc))
570
571 hammer2_chain_t *hammer2_inode_lock_ex(hammer2_inode_t *ip);
572 hammer2_chain_t *hammer2_inode_lock_sh(hammer2_inode_t *ip);
573 void hammer2_inode_unlock_ex(hammer2_inode_t *ip, hammer2_chain_t *chain);
574 void hammer2_inode_unlock_sh(hammer2_inode_t *ip, hammer2_chain_t *chain);
575 void hammer2_voldata_lock(hammer2_mount_t *hmp);
576 void hammer2_voldata_unlock(hammer2_mount_t *hmp, int modify);
577 ccms_state_t hammer2_inode_lock_temp_release(hammer2_inode_t *ip);
578 void hammer2_inode_lock_temp_restore(hammer2_inode_t *ip, ccms_state_t ostate);
579 ccms_state_t hammer2_inode_lock_upgrade(hammer2_inode_t *ip);
580 void hammer2_inode_lock_downgrade(hammer2_inode_t *ip, ccms_state_t ostate);
581
582 void hammer2_mount_exlock(hammer2_mount_t *hmp);
583 void hammer2_mount_shlock(hammer2_mount_t *hmp);
584 void hammer2_mount_unlock(hammer2_mount_t *hmp);
585
586 int hammer2_get_dtype(hammer2_chain_t *chain);
587 int hammer2_get_vtype(hammer2_chain_t *chain);
588 u_int8_t hammer2_get_obj_type(enum vtype vtype);
589 void hammer2_time_to_timespec(u_int64_t xtime, struct timespec *ts);
590 u_int64_t hammer2_timespec_to_time(struct timespec *ts);
591 u_int32_t hammer2_to_unix_xid(uuid_t *uuid);
592 void hammer2_guid_to_uuid(uuid_t *uuid, u_int32_t guid);
593
594 hammer2_key_t hammer2_dirhash(const unsigned char *name, size_t len);
595 int hammer2_getradix(size_t bytes);
596
597 int hammer2_calc_logical(hammer2_inode_t *ip, hammer2_off_t uoff,
598                          hammer2_key_t *lbasep, hammer2_key_t *leofp);
599 void hammer2_update_time(uint64_t *timep);
600
601 /*
602  * hammer2_inode.c
603  */
604 struct vnode *hammer2_igetv(hammer2_inode_t *ip, int *errorp);
605
606 void hammer2_inode_lock_nlinks(hammer2_inode_t *ip);
607 void hammer2_inode_unlock_nlinks(hammer2_inode_t *ip);
608 hammer2_inode_t *hammer2_inode_lookup(hammer2_pfsmount_t *pmp,
609                         hammer2_tid_t inum);
610 hammer2_inode_t *hammer2_inode_get(hammer2_pfsmount_t *pmp,
611                         hammer2_inode_t *dip, hammer2_chain_t *chain);
612 void hammer2_inode_free(hammer2_inode_t *ip);
613 void hammer2_inode_ref(hammer2_inode_t *ip);
614 void hammer2_inode_drop(hammer2_inode_t *ip);
615 void hammer2_inode_repoint(hammer2_inode_t *ip, hammer2_inode_t *pip,
616                         hammer2_chain_t *chain);
617
618 hammer2_inode_t *hammer2_inode_create(hammer2_trans_t *trans,
619                         hammer2_inode_t *dip,
620                         struct vattr *vap, struct ucred *cred,
621                         const uint8_t *name, size_t name_len,
622                         hammer2_chain_t **chainp, int *errorp);
623 int hammer2_inode_connect(hammer2_trans_t *trans, int hlink,
624                         hammer2_inode_t *dip, hammer2_chain_t **chainp,
625                         const uint8_t *name, size_t name_len);
626 hammer2_inode_t *hammer2_inode_common_parent(hammer2_inode_t *fdip,
627                         hammer2_inode_t *tdip);
628
629 int hammer2_unlink_file(hammer2_trans_t *trans, hammer2_inode_t *dip,
630                         const uint8_t *name, size_t name_len, int isdir,
631                         int *hlinkp);
632 int hammer2_hardlink_consolidate(hammer2_trans_t *trans, hammer2_inode_t *ip,
633                         hammer2_chain_t **chainp,
634                         hammer2_inode_t *tdip, int linkcnt);
635 int hammer2_hardlink_deconsolidate(hammer2_trans_t *trans, hammer2_inode_t *dip,
636                         hammer2_chain_t **chainp, hammer2_chain_t **ochainp);
637 int hammer2_hardlink_find(hammer2_inode_t *dip,
638                         hammer2_chain_t **chainp, hammer2_chain_t **ochainp);
639
640 /*
641  * hammer2_chain.c
642  */
643 void hammer2_modify_volume(hammer2_mount_t *hmp);
644 hammer2_chain_t *hammer2_chain_alloc(hammer2_mount_t *hmp,
645                                 hammer2_trans_t *trans,
646                                 hammer2_blockref_t *bref);
647 void hammer2_chain_core_alloc(hammer2_chain_t *chain,
648                                 hammer2_chain_core_t *core);
649 void hammer2_chain_ref(hammer2_chain_t *chain);
650 void hammer2_chain_drop(hammer2_chain_t *chain);
651 int hammer2_chain_lock(hammer2_chain_t *chain, int how);
652 void hammer2_chain_load_async(hammer2_chain_t *chain,
653                                 void (*func)(hammer2_chain_t *, struct buf *,
654                                              char *, void *),
655                                 void *arg);
656 void hammer2_chain_moved(hammer2_chain_t *chain);
657 void hammer2_chain_modify(hammer2_trans_t *trans,
658                                 hammer2_chain_t **chainp, int flags);
659 hammer2_inode_data_t *hammer2_chain_modify_ip(hammer2_trans_t *trans,
660                                 hammer2_inode_t *ip, hammer2_chain_t **chainp,
661                                 int flags);
662 void hammer2_chain_resize(hammer2_trans_t *trans, hammer2_inode_t *ip,
663                                 struct buf *bp,
664                                 hammer2_chain_t *parent,
665                                 hammer2_chain_t **chainp,
666                                 int nradix, int flags);
667 void hammer2_chain_unlock(hammer2_chain_t *chain);
668 void hammer2_chain_wait(hammer2_chain_t *chain);
669 hammer2_chain_t *hammer2_chain_find(hammer2_chain_t *parent, int index);
670 hammer2_chain_t *hammer2_chain_get(hammer2_chain_t *parent, int index,
671                                 int flags);
672 hammer2_chain_t *hammer2_chain_lookup_init(hammer2_chain_t *parent, int flags);
673 void hammer2_chain_lookup_done(hammer2_chain_t *parent);
674 hammer2_chain_t *hammer2_chain_lookup(hammer2_chain_t **parentp,
675                                 hammer2_key_t key_beg, hammer2_key_t key_end,
676                                 int flags);
677 hammer2_chain_t *hammer2_chain_next(hammer2_chain_t **parentp,
678                                 hammer2_chain_t *chain,
679                                 hammer2_key_t key_beg, hammer2_key_t key_end,
680                                 int flags);
681 int hammer2_chain_create(hammer2_trans_t *trans,
682                                 hammer2_chain_t **parentp,
683                                 hammer2_chain_t **chainp,
684                                 hammer2_key_t key, int keybits,
685                                 int type, size_t bytes);
686 void hammer2_chain_duplicate(hammer2_trans_t *trans, hammer2_chain_t *parent,
687                                 int i,
688                                 hammer2_chain_t **chainp,
689                                 hammer2_blockref_t *bref);
690 int hammer2_chain_snapshot(hammer2_trans_t *trans, hammer2_inode_t *ip,
691                                 hammer2_ioc_pfs_t *pfs);
692 void hammer2_chain_delete(hammer2_trans_t *trans, hammer2_chain_t *chain);
693 void hammer2_chain_delete_duplicate(hammer2_trans_t *trans,
694                                 hammer2_chain_t **chainp, int flags);
695 void hammer2_chain_flush(hammer2_trans_t *trans, hammer2_chain_t *chain);
696 void hammer2_chain_commit(hammer2_trans_t *trans, hammer2_chain_t *chain);
697 void hammer2_chain_setsubmod(hammer2_trans_t *trans, hammer2_chain_t *chain);
698
699 /*
700  * hammer2_trans.c
701  */
702 void hammer2_trans_init(hammer2_trans_t *trans,
703                         hammer2_pfsmount_t *pmp, int flags);
704 void hammer2_trans_done(hammer2_trans_t *trans);
705
706 /*
707  * hammer2_ioctl.c
708  */
709 int hammer2_ioctl(hammer2_inode_t *ip, u_long com, void *data,
710                                 int fflag, struct ucred *cred);
711
712 /*
713  * hammer2_msgops.c
714  */
715 int hammer2_msg_dbg_rcvmsg(kdmsg_msg_t *msg);
716 int hammer2_msg_adhoc_input(kdmsg_msg_t *msg);
717
718 /*
719  * hammer2_vfsops.c
720  */
721 void hammer2_clusterctl_wakeup(kdmsg_iocom_t *iocom);
722 void hammer2_volconf_update(hammer2_pfsmount_t *pmp, int index);
723 void hammer2_cluster_reconnect(hammer2_pfsmount_t *pmp, struct file *fp);
724 void hammer2_dump_chain(hammer2_chain_t *chain, int tab, int *countp);
725
726 /*
727  * hammer2_freemap.c
728  */
729 int hammer2_freemap_alloc(hammer2_trans_t *trans, hammer2_mount_t *hmp,
730                                 hammer2_blockref_t *bref, size_t bytes);
731 void hammer2_freemap_free(hammer2_mount_t *hmp, hammer2_off_t data_off,
732                                 int type);
733
734 #endif /* !_KERNEL */
735 #endif /* !_VFS_HAMMER2_HAMMER2_H_ */