xref: /minix/sys/ufs/ufs/ufs_wapbl.h (revision 84d9c625)
1 /*	$NetBSD: ufs_wapbl.h,v 1.8 2013/11/10 18:28:08 christos Exp $	*/
2 
3 /*-
4  * Copyright (c) 2003,2006,2008 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Wasabi Systems, Inc.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 
33 #ifndef _UFS_UFS_UFS_WAPBL_H_
34 #define	_UFS_UFS_UFS_WAPBL_H_
35 
36 #if defined(_KERNEL_OPT)
37 #include "opt_wapbl.h"
38 #endif
39 
40 /*
41  * Information for the journal location stored in the superblock.
42  * We store the journal version, some flags, the journal location
43  * type, and some location specific "locators" that identify where
44  * the log itself is located.
45  */
46 
47 /* fs->fs_journal_version */
48 #define	UFS_WAPBL_VERSION			1
49 
50 /* fs->fs_journal_location */
51 #define	UFS_WAPBL_JOURNALLOC_NONE		0
52 
53 #define	UFS_WAPBL_JOURNALLOC_END_PARTITION	1
54 #define	 UFS_WAPBL_EPART_ADDR			  0 /* locator slots */
55 #define	 UFS_WAPBL_EPART_COUNT			  1
56 #define	 UFS_WAPBL_EPART_BLKSZ			  2
57 #define	 UFS_WAPBL_EPART_UNUSED			  3
58 
59 #define	UFS_WAPBL_JOURNALLOC_IN_FILESYSTEM	2
60 #define	 UFS_WAPBL_INFS_ADDR			  0 /* locator slots */
61 #define	 UFS_WAPBL_INFS_COUNT			  1
62 #define	 UFS_WAPBL_INFS_BLKSZ			  2
63 #define	 UFS_WAPBL_INFS_INO			  3
64 
65 /* fs->fs_journal_flags */
66 #define	UFS_WAPBL_FLAGS_CREATE_LOG		0x1
67 #define	UFS_WAPBL_FLAGS_CLEAR_LOG		0x2
68 
69 
70 /*
71  * The journal size is limited to between 1MB and 64MB.
72  * The default journal size is the filesystem size divided by
73  * the scale factor - this is 1M of journal per 1GB of filesystem
74  * space.
75  *
76  * XXX: Is 64MB too limiting?  If user explicitly asks for more, allow it?
77  */
78 #define	UFS_WAPBL_JOURNAL_SCALE			1024
79 #define	UFS_WAPBL_MIN_JOURNAL_SIZE		(1024 * 1024)
80 #define	UFS_WAPBL_MAX_JOURNAL_SIZE		(64 * 1024 * 1024)
81 
82 
83 #if defined(WAPBL)
84 
85 #if defined(WAPBL_DEBUG)
86 #define	WAPBL_DEBUG_INODES
87 #endif
88 
89 #ifdef WAPBL_DEBUG_INODES
90 #error Undefine WAPBL_DEBUG_INODES or update the code.  Have a nice day.
91 #endif
92 
93 #ifdef WAPBL_DEBUG_INODES
94 void	ufs_wapbl_verify_inodes(struct mount *, const char *);
95 #endif
96 
97 static __inline int
ufs_wapbl_begin2(struct mount * mp,struct vnode * vp1,struct vnode * vp2,const char * file,int line)98 ufs_wapbl_begin2(struct mount *mp, struct vnode *vp1, struct vnode *vp2,
99 		 const char *file, int line)
100 {
101 	if (mp->mnt_wapbl) {
102 		int error;
103 
104 		if (vp1)
105 			vref(vp1);
106 		if (vp2)
107 			vref(vp2);
108 		error = wapbl_begin(mp->mnt_wapbl, file, line);
109 		if (error)
110 			return error;
111 #ifdef WAPBL_DEBUG_INODES
112 		if (mp->mnt_wapbl->wl_lock.lk_exclusivecount == 1)
113 			ufs_wapbl_verify_inodes(mp, "wapbl_begin");
114 #endif
115 	}
116 	return 0;
117 }
118 
119 static __inline void
ufs_wapbl_end2(struct mount * mp,struct vnode * vp1,struct vnode * vp2)120 ufs_wapbl_end2(struct mount *mp, struct vnode *vp1, struct vnode *vp2)
121 {
122 	if (mp->mnt_wapbl) {
123 #ifdef WAPBL_DEBUG_INODES
124 		if (mp->mnt_wapbl->wl_lock.lk_exclusivecount == 1)
125 			ufs_wapbl_verify_inodes(mp, "wapbl_end");
126 #endif
127 		wapbl_end(mp->mnt_wapbl);
128 		if (vp2)
129 			vrele(vp2);
130 		if (vp1)
131 			vrele(vp1);
132 	}
133 }
134 
135 #define	UFS_WAPBL_BEGIN(mp)						\
136 	ufs_wapbl_begin2(mp, NULL, NULL, __FUNCTION__, __LINE__)
137 #define	UFS_WAPBL_BEGIN1(mp, v1)					\
138 	ufs_wapbl_begin2(mp, v1, NULL, __FUNCTION__, __LINE__)
139 #define	UFS_WAPBL_END(mp)	ufs_wapbl_end2(mp, NULL, NULL)
140 #define	UFS_WAPBL_END1(mp, v1)	ufs_wapbl_end2(mp, v1, NULL)
141 
142 #define	UFS_WAPBL_UPDATE(vp, access, modify, flags)			\
143 	if ((vp)->v_mount->mnt_wapbl) {					\
144 		UFS_UPDATE(vp, access, modify, flags);			\
145 	}
146 
147 #ifdef UFS_WAPBL_DEBUG_JLOCK
148 #define	UFS_WAPBL_JLOCK_ASSERT(mp)					\
149 	if (mp->mnt_wapbl) wapbl_jlock_assert(mp->mnt_wapbl)
150 #define	UFS_WAPBL_JUNLOCK_ASSERT(mp)					\
151 	if (mp->mnt_wapbl) wapbl_junlock_assert(mp->mnt_wapbl)
152 #else
153 #define	UFS_WAPBL_JLOCK_ASSERT(mp)
154 #define	UFS_WAPBL_JUNLOCK_ASSERT(mp)
155 #endif
156 
157 #define	UFS_WAPBL_REGISTER_INODE(mp, ino, mode)				\
158 	if (mp->mnt_wapbl) wapbl_register_inode(mp->mnt_wapbl, ino, mode)
159 #define	UFS_WAPBL_UNREGISTER_INODE(mp, ino, mode)			\
160 	if (mp->mnt_wapbl) wapbl_unregister_inode(mp->mnt_wapbl, ino, mode)
161 
162 #define	UFS_WAPBL_REGISTER_DEALLOCATION(mp, blk, len)			\
163 	if (mp->mnt_wapbl) wapbl_register_deallocation(mp->mnt_wapbl, blk, len)
164 
165 #else /* ! WAPBL */
166 #define	UFS_WAPBL_BEGIN(mp) (__USE(mp), 0)
167 #define	UFS_WAPBL_BEGIN1(mp, v1) 0
168 #define	UFS_WAPBL_END(mp)	do { } while (0)
169 #define	UFS_WAPBL_END1(mp, v1)
170 #define	UFS_WAPBL_UPDATE(vp, access, modify, flags)	do { } while (0)
171 #define	UFS_WAPBL_JLOCK_ASSERT(mp)
172 #define	UFS_WAPBL_JUNLOCK_ASSERT(mp)
173 #define	UFS_WAPBL_REGISTER_INODE(mp, ino, mode)		do { } while (0)
174 #define	UFS_WAPBL_UNREGISTER_INODE(mp, ino, mode)	do { } while (0)
175 #define	UFS_WAPBL_REGISTER_DEALLOCATION(mp, blk, len)
176 #endif
177 
178 #endif /* !_UFS_UFS_UFS_WAPBL_H_ */
179