1/* $NetBSD: ufs_wapbl.h,v 1.19 2020/04/11 17:43:54 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 85static __inline int 86ufs_wapbl_begin(struct mount *mp, const char *file, int line) 87{ 88 if (mp->mnt_wapbl) { 89 int error; 90 error = wapbl_begin(mp->mnt_wapbl, file, line); 91 if (error) 92 return error; 93 } 94 return 0; 95} 96 97static __inline void 98ufs_wapbl_end(struct mount *mp) 99{ 100 if (mp->mnt_wapbl) { 101 wapbl_end(mp->mnt_wapbl); 102 } 103} 104 105#define UFS_WAPBL_BEGIN(mp) \ 106 ufs_wapbl_begin(mp, __func__, __LINE__) 107#define UFS_WAPBL_END(mp) ufs_wapbl_end(mp) 108 109#define UFS_WAPBL_UPDATE(vp, access, modify, flags) \ 110 if ((vp)->v_mount->mnt_wapbl) { \ 111 UFS_UPDATE(vp, access, modify, flags); \ 112 } 113 114#ifdef DIAGNOSTIC 115#define UFS_WAPBL_JLOCK_ASSERT(mp) \ 116 if (mp->mnt_wapbl) wapbl_jlock_assert(mp->mnt_wapbl) 117#define UFS_WAPBL_JUNLOCK_ASSERT(mp) \ 118 if (mp->mnt_wapbl) wapbl_junlock_assert(mp->mnt_wapbl) 119#else 120#define UFS_WAPBL_JLOCK_ASSERT(mp) 121#define UFS_WAPBL_JUNLOCK_ASSERT(mp) 122#endif 123 124#define UFS_WAPBL_REGISTER_INODE(mp, ino, mode) \ 125 if (mp->mnt_wapbl) wapbl_register_inode(mp->mnt_wapbl, ino, mode) 126#define UFS_WAPBL_UNREGISTER_INODE(mp, ino, mode) \ 127 if (mp->mnt_wapbl) wapbl_unregister_inode(mp->mnt_wapbl, ino, mode) 128 129#define UFS_WAPBL_REGISTER_DEALLOCATION(mp, blk, len, cookiep) \ 130 (mp->mnt_wapbl) \ 131 ? wapbl_register_deallocation(mp->mnt_wapbl, blk, len, \ 132 false, cookiep) \ 133 : 0 134 135#define UFS_WAPBL_REGISTER_DEALLOCATION_FORCE(mp, blk, len) \ 136 ( \ 137 (mp->mnt_wapbl) \ 138 ? wapbl_register_deallocation(mp->mnt_wapbl, blk, len, \ 139 true, NULL) \ 140 : 0 \ 141 ) 142 143#define UFS_WAPBL_UNREGISTER_DEALLOCATION(mp, cookie) \ 144 if (mp->mnt_wapbl) wapbl_unregister_deallocation(mp->mnt_wapbl, cookie) 145 146#else /* ! WAPBL */ 147#define UFS_WAPBL_BEGIN(mp) (__USE(mp), 0) 148#define UFS_WAPBL_END(mp) do { } while (0) 149#define UFS_WAPBL_UPDATE(vp, access, modify, flags) do { } while (0) 150#define UFS_WAPBL_JLOCK_ASSERT(mp) 151#define UFS_WAPBL_JUNLOCK_ASSERT(mp) 152#define UFS_WAPBL_REGISTER_INODE(mp, ino, mode) do { } while (0) 153#define UFS_WAPBL_UNREGISTER_INODE(mp, ino, mode) do { } while (0) 154#define UFS_WAPBL_REGISTER_DEALLOCATION(mp, blk, len, cookiep) 0 155#define UFS_WAPBL_REGISTER_DEALLOCATION_FORCE(mp, blk, len) 0 156#define UFS_WAPBL_UNREGISTER_DEALLOCATION(mp, cookie) do { } while (0) 157#endif 158 159#endif /* !_UFS_UFS_UFS_WAPBL_H_ */ 160