hammer2 - code cleanup, fix kldload issue
[dragonfly.git] / sys / vfs / hammer2 / hammer2.h
1 /*
2  * Copyright (c) 2011-2012 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/globaldata.h>
58 #include <sys/lockf.h>
59 #include <sys/buf.h>
60 #include <sys/queue.h>
61 #include <sys/limits.h>
62 #include <sys/buf2.h>
63 #include <sys/signal2.h>
64 #include <sys/tree.h>
65
66 #include "hammer2_disk.h"
67 #include "hammer2_mount.h"
68
69 struct hammer2_inode;
70 struct hammer2_mount;
71
72 /*
73  * A hammer2 inode.
74  */
75 struct hammer2_inode {
76         struct hammer2_mount    *mp;
77         struct lock             lk;
78         struct vnode            *vp;
79         hammer2_tid_t           inum;
80         unsigned char           type;
81         int                     busy;
82 };
83
84 #define HAMMER2_INODE_TYPE_DIR  0x01
85 #define HAMMER2_INODE_TYPE_FILE 0x02
86 #define HAMMER2_INODE_TYPE_ROOT 0x10
87 #define HAMMER2_INODE_TYPE_MASK 0x07
88
89 /*
90  * Governing mount structure for filesystem (aka vp->v_mount)
91  */
92 struct hammer2_mount {
93         struct mount    *hm_mp;
94         int             hm_ronly;       /* block device mounted read-only */
95         struct vnode    *hm_devvp;      /* device vnode */
96         struct lock     hm_lk;
97
98         /* Root inode */
99         struct hammer2_inode    *hm_iroot;
100
101         /* Per-mount inode zone */
102         struct malloc_type *hm_inodes;
103         int             hm_ninodes;
104         int             hm_maxinodes;
105
106         struct malloc_type *hm_ipstacks;
107         int             hm_nipstacks;
108         int             hm_maxipstacks;
109
110         struct hammer2_volume_data hm_sb;
111
112         struct netexport        hm_export;
113 };
114
115 #if defined(_KERNEL)
116
117 MALLOC_DECLARE(M_HAMMER2);
118
119 static __inline
120 struct mount *
121 H2TOMP(struct hammer2_mount *hmp)
122 {
123         return (struct mount *) hmp->hm_mp;
124 }
125
126 #define VTOI(vp)        ((struct hammer2_inode *) (vp)->v_data)
127 #define ITOV(ip)        ((ip)->vp)
128
129 static __inline
130 struct hammer2_mount *
131 MPTOH2(struct mount *mp)
132 {
133         return (struct hammer2_mount *) mp->mnt_data;
134 }
135
136 extern struct vop_ops hammer2_vnode_vops;
137 extern struct vop_ops hammer2_spec_vops;
138 extern struct vop_ops hammer2_fifo_vops;
139
140 /* hammer2_subr.c */
141
142 void hammer2_inode_lock_sh(struct hammer2_inode *ip);
143 void hammer2_inode_lock_up(struct hammer2_inode *ip);
144 void hammer2_inode_lock_ex(struct hammer2_inode *ip);
145 void hammer2_inode_unlock_ex(struct hammer2_inode *ip);
146 void hammer2_inode_unlock_up(struct hammer2_inode *ip);
147 void hammer2_inode_unlock_sh(struct hammer2_inode *ip);
148
149 struct vnode *igetv(struct hammer2_inode *, int *);
150
151 void hammer2_mount_exlock(struct hammer2_mount *);
152 void hammer2_mount_shlock(struct hammer2_mount *);
153 void hammer2_mount_unlock(struct hammer2_mount *);
154 struct hammer2_inode *alloci(struct hammer2_mount *hmp);
155
156 #endif /* !_KERNEL */
157 #endif /* !_VFS_HAMMER2_HAMMER2_H_ */