1/* $NetBSD: ufs_wapbl.h,v 1.14 2016/11/11 22:59:26 jdolecek 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
94void ufs_wapbl_verify_inodes(struct mount *, const char *);
95#endif
96
97static __inline int
98ufs_wapbl_begin(struct mount *mp, const char *file, int line)
99{
100 if (mp->mnt_wapbl) {
101 int error;
102 error = wapbl_begin(mp->mnt_wapbl, file, line);
103 if (error)
104 return error;
105#ifdef WAPBL_DEBUG_INODES
106 if (mp->mnt_wapbl->wl_lock.lk_exclusivecount == 1)
107 ufs_wapbl_verify_inodes(mp, "wapbl_begin");
108#endif
109 }
110 return 0;
111}
112
113static __inline void
114ufs_wapbl_end(struct mount *mp)
115{
116 if (mp->mnt_wapbl) {
117#ifdef WAPBL_DEBUG_INODES
118 if (mp->mnt_wapbl->wl_lock.lk_exclusivecount == 1)
119 ufs_wapbl_verify_inodes(mp, "wapbl_end");
120#endif
121 wapbl_end(mp->mnt_wapbl);
122 }
123}
124
125#define UFS_WAPBL_BEGIN(mp) \
126 ufs_wapbl_begin(mp, __func__, __LINE__)
127#define UFS_WAPBL_END(mp) ufs_wapbl_end(mp)
128
129#define UFS_WAPBL_UPDATE(vp, access, modify, flags) \
130 if ((vp)->v_mount->mnt_wapbl) { \
131 UFS_UPDATE(vp, access, modify, flags); \
132 }
133
134#ifdef UFS_WAPBL_DEBUG_JLOCK
135#define UFS_WAPBL_JLOCK_ASSERT(mp) \
136 if (mp->mnt_wapbl) wapbl_jlock_assert(mp->mnt_wapbl)
137#define UFS_WAPBL_JUNLOCK_ASSERT(mp) \
138 if (mp->mnt_wapbl) wapbl_junlock_assert(mp->mnt_wapbl)
139#else
140#define UFS_WAPBL_JLOCK_ASSERT(mp)
141#define UFS_WAPBL_JUNLOCK_ASSERT(mp)
142#endif
143
144#define UFS_WAPBL_REGISTER_INODE(mp, ino, mode) \
145 if (mp->mnt_wapbl) wapbl_register_inode(mp->mnt_wapbl, ino, mode)
146#define UFS_WAPBL_UNREGISTER_INODE(mp, ino, mode) \
147 if (mp->mnt_wapbl) wapbl_unregister_inode(mp->mnt_wapbl, ino, mode)
148
149#define UFS_WAPBL_REGISTER_DEALLOCATION(mp, blk, len, cookiep) \
150 (mp->mnt_wapbl) \
151 ? wapbl_register_deallocation(mp->mnt_wapbl, blk, len, \
152 false, cookiep) \
153 : 0
154
155#define UFS_WAPBL_REGISTER_DEALLOCATION_FORCE(mp, blk, len) \
156 ( \
157 (mp->mnt_wapbl) \
158 ? wapbl_register_deallocation(mp->mnt_wapbl, blk, len, \
159 true, NULL) \
160 : 0 \
161 )
162
163#define UFS_WAPBL_UNREGISTER_DEALLOCATION(mp, cookie) \
164 if (mp->mnt_wapbl) wapbl_unregister_deallocation(mp->mnt_wapbl, cookie)
165
166#else /* ! WAPBL */
167#define UFS_WAPBL_BEGIN(mp) (__USE(mp), 0)
168#define UFS_WAPBL_END(mp) do { } while (0)
169#define UFS_WAPBL_UPDATE(vp, access, modify, flags) do { } while (0)
170#define UFS_WAPBL_JLOCK_ASSERT(mp)
171#define UFS_WAPBL_JUNLOCK_ASSERT(mp)
172#define UFS_WAPBL_REGISTER_INODE(mp, ino, mode) do { } while (0)
173#define UFS_WAPBL_UNREGISTER_INODE(mp, ino, mode) do { } while (0)
174#define UFS_WAPBL_REGISTER_DEALLOCATION(mp, blk, len, cookiep) 0
175#define UFS_WAPBL_REGISTER_DEALLOCATION_FORCE(mp, blk, len) 0
176#define UFS_WAPBL_UNREGISTER_DEALLOCATION(mp, cookie) do { } while (0)
177#endif
178
179#endif /* !_UFS_UFS_UFS_WAPBL_H_ */
180