| 1 | /* $NetBSD: ulfs_inode.h,v 1.22 2016/06/21 06:14:40 dholland Exp $ */ |
| 2 | /* from NetBSD: inode.h,v 1.72 2016/06/03 15:36:03 christos Exp */ |
| 3 | |
| 4 | /* |
| 5 | * Copyright (c) 1982, 1989, 1993 |
| 6 | * The Regents of the University of California. All rights reserved. |
| 7 | * (c) UNIX System Laboratories, Inc. |
| 8 | * All or some portions of this file are derived from material licensed |
| 9 | * to the University of California by American Telephone and Telegraph |
| 10 | * Co. or Unix System Laboratories, Inc. and are reproduced herein with |
| 11 | * the permission of UNIX System Laboratories, Inc. |
| 12 | * |
| 13 | * Redistribution and use in source and binary forms, with or without |
| 14 | * modification, are permitted provided that the following conditions |
| 15 | * are met: |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its contributors |
| 22 | * may be used to endorse or promote products derived from this software |
| 23 | * without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 35 | * SUCH DAMAGE. |
| 36 | * |
| 37 | * @(#)inode.h 8.9 (Berkeley) 5/14/95 |
| 38 | */ |
| 39 | |
| 40 | #ifndef _UFS_LFS_ULFS_INODE_H_ |
| 41 | #define _UFS_LFS_ULFS_INODE_H_ |
| 42 | |
| 43 | #include <sys/vnode.h> |
| 44 | #include <ufs/lfs/lfs_inode.h> |
| 45 | #include <ufs/lfs/ulfs_dinode.h> |
| 46 | #include <ufs/lfs/ulfs_quotacommon.h> |
| 47 | |
| 48 | /* |
| 49 | * These macros are used to bracket ULFS directory ops, so that we can |
| 50 | * identify all the pages touched during directory ops which need to |
| 51 | * be ordered and flushed atomically, so that they may be recovered. |
| 52 | * |
| 53 | * Because we have to mark nodes VU_DIROP in order to prevent |
| 54 | * the cache from reclaiming them while a dirop is in progress, we must |
| 55 | * also manage the number of nodes so marked (otherwise we can run out). |
| 56 | * We do this by setting lfs_dirvcount to the number of marked vnodes; it |
| 57 | * is decremented during segment write, when VU_DIROP is taken off. |
| 58 | */ |
| 59 | #define MARK_VNODE(vp) lfs_mark_vnode(vp) |
| 60 | #define UNMARK_VNODE(vp) lfs_unmark_vnode(vp) |
| 61 | int lfs_set_dirop(struct vnode *, struct vnode *); |
| 62 | void lfs_unset_dirop(struct lfs *, struct vnode *, const char *); |
| 63 | |
| 64 | /* Misc. definitions */ |
| 65 | #define BW_CLEAN 1 /* Flag for lfs_bwrite_ext() */ |
| 66 | #define PG_DELWRI PG_PAGER1 /* Local def for delayed pageout */ |
| 67 | |
| 68 | /* Resource limits */ |
| 69 | #define LFS_MAX_RESOURCE(x, u) (((x) >> 2) - 10 * (u)) |
| 70 | #define LFS_WAIT_RESOURCE(x, u) (((x) >> 1) - ((x) >> 3) - 10 * (u)) |
| 71 | #define LFS_INVERSE_MAX_RESOURCE(x, u) (((x) + 10 * (u)) << 2) |
| 72 | #define LFS_MAX_BUFS LFS_MAX_RESOURCE(nbuf, 1) |
| 73 | #define LFS_WAIT_BUFS LFS_WAIT_RESOURCE(nbuf, 1) |
| 74 | #define LFS_INVERSE_MAX_BUFS(n) LFS_INVERSE_MAX_RESOURCE(n, 1) |
| 75 | #define LFS_MAX_BYTES LFS_MAX_RESOURCE(bufmem_lowater, PAGE_SIZE) |
| 76 | #define LFS_INVERSE_MAX_BYTES(n) LFS_INVERSE_MAX_RESOURCE(n, PAGE_SIZE) |
| 77 | #define LFS_WAIT_BYTES LFS_WAIT_RESOURCE(bufmem_lowater, PAGE_SIZE) |
| 78 | #define LFS_MAX_DIROP ((desiredvnodes >> 2) + (desiredvnodes >> 3)) |
| 79 | #define SIZEOF_DIROP(fs) (2 * (lfs_sb_getbsize(fs) + DINOSIZE(fs))) |
| 80 | #define LFS_MAX_FSDIROP(fs) \ |
| 81 | (lfs_sb_getnclean(fs) <= lfs_sb_getresvseg(fs) ? 0 : \ |
| 82 | ((lfs_sb_getnclean(fs) - lfs_sb_getresvseg(fs)) * lfs_sb_getssize(fs)) / \ |
| 83 | (2 * SIZEOF_DIROP(fs))) |
| 84 | #define LFS_MAX_PAGES lfs_max_pages() |
| 85 | #define LFS_WAIT_PAGES lfs_wait_pages() |
| 86 | #define LFS_BUFWAIT 2 /* How long to wait if over *_WAIT_* */ |
| 87 | |
| 88 | #ifdef _KERNEL |
| 89 | extern u_long bufmem_lowater, bufmem_hiwater; /* XXX */ |
| 90 | |
| 91 | int lfs_wait_pages(void); |
| 92 | int lfs_max_pages(void); |
| 93 | #endif /* _KERNEL */ |
| 94 | |
| 95 | /* How starved can we be before we start holding back page writes */ |
| 96 | #define LFS_STARVED_FOR_SEGS(fs) (lfs_sb_getnclean(fs) < lfs_sb_getresvseg(fs)) |
| 97 | |
| 98 | /* |
| 99 | * Reserved blocks for lfs_malloc |
| 100 | */ |
| 101 | |
| 102 | /* Structure to keep reserved blocks */ |
| 103 | typedef struct lfs_res_blk { |
| 104 | void *p; |
| 105 | LIST_ENTRY(lfs_res_blk) res; |
| 106 | int size; |
| 107 | char inuse; |
| 108 | } res_t; |
| 109 | |
| 110 | /* Types for lfs_newbuf and lfs_malloc */ |
| 111 | #define LFS_NB_UNKNOWN -1 |
| 112 | #define LFS_NB_SUMMARY 0 |
| 113 | #define LFS_NB_SBLOCK 1 |
| 114 | #define LFS_NB_IBLOCK 2 |
| 115 | #define LFS_NB_CLUSTER 3 |
| 116 | #define LFS_NB_CLEAN 4 |
| 117 | #define LFS_NB_BLKIOV 5 |
| 118 | #define LFS_NB_COUNT 6 /* always last */ |
| 119 | |
| 120 | /* Number of reserved memory blocks of each type */ |
| 121 | #define LFS_N_SUMMARIES 2 |
| 122 | #define LFS_N_SBLOCKS 1 /* Always 1, to throttle superblock writes */ |
| 123 | #define LFS_N_IBLOCKS 16 /* In theory ssize/bsize; in practice around 2 */ |
| 124 | #define LFS_N_CLUSTERS 16 /* In theory ssize/MAXPHYS */ |
| 125 | #define LFS_N_CLEAN 0 |
| 126 | #define LFS_N_BLKIOV 1 |
| 127 | |
| 128 | /* Total count of "large" (non-pool) types */ |
| 129 | #define LFS_N_TOTAL (LFS_N_SUMMARIES + LFS_N_SBLOCKS + LFS_N_IBLOCKS + \ |
| 130 | LFS_N_CLUSTERS + LFS_N_CLEAN + LFS_N_BLKIOV) |
| 131 | |
| 132 | /* Counts for pool types */ |
| 133 | #define LFS_N_CL LFS_N_CLUSTERS |
| 134 | #define LFS_N_BPP 2 |
| 135 | #define LFS_N_SEG 2 |
| 136 | |
| 137 | /* |
| 138 | * "struct buf" associated definitions |
| 139 | */ |
| 140 | |
| 141 | /* Determine if a buffer belongs to the ifile */ |
| 142 | #define IS_IFILE(bp) (VTOI(bp->b_vp)->i_number == LFS_IFILE_INUM) |
| 143 | |
| 144 | #ifdef _KERNEL |
| 145 | /* This overlays the fid structure (see fstypes.h). */ |
| 146 | struct ulfs_ufid { |
| 147 | uint16_t ufid_len; /* Length of structure. */ |
| 148 | uint16_t ufid_pad; /* Force 32-bit alignment. */ |
| 149 | uint32_t ufid_ino; /* File number (ino). XXX should be 64 */ |
| 150 | int32_t ufid_gen; /* Generation number. */ |
| 151 | }; |
| 152 | /* Filehandle structure for exported LFSes */ |
| 153 | struct lfid { |
| 154 | struct ulfs_ufid lfid_ufid; |
| 155 | #define lfid_len lfid_ufid.ufid_len |
| 156 | #define lfid_ino lfid_ufid.ufid_ino |
| 157 | #define lfid_gen lfid_ufid.ufid_gen |
| 158 | uint32_t lfid_ident; |
| 159 | }; |
| 160 | #endif /* _KERNEL */ |
| 161 | |
| 162 | /* Address calculations for metadata located in the inode */ |
| 163 | #define S_INDIR(fs) -ULFS_NDADDR |
| 164 | #define D_INDIR(fs) (S_INDIR(fs) - LFS_NINDIR(fs) - 1) |
| 165 | #define T_INDIR(fs) (D_INDIR(fs) - LFS_NINDIR(fs) * LFS_NINDIR(fs) - 1) |
| 166 | |
| 167 | /* |
| 168 | * "struct vnode" associated definitions |
| 169 | */ |
| 170 | |
| 171 | /* Heuristic emptiness measure */ |
| 172 | #define VPISEMPTY(vp) (LIST_EMPTY(&(vp)->v_dirtyblkhd) && \ |
| 173 | !(vp->v_type == VREG && (vp)->v_iflag & VI_ONWORKLST) &&\ |
| 174 | VTOI(vp)->i_lfs_nbtree == 0) |
| 175 | |
| 176 | #define WRITEINPROG(vp) ((vp)->v_numoutput > 0 || \ |
| 177 | (!LIST_EMPTY(&(vp)->v_dirtyblkhd) && \ |
| 178 | !(VTOI(vp)->i_flag & (IN_MODIFIED | IN_ACCESSED | IN_CLEANING)))) |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | #if defined(_KERNEL) |
| 185 | |
| 186 | /* |
| 187 | * The DIP macro is used to access fields in the dinode that are |
| 188 | * not cached in the inode itself. |
| 189 | */ |
| 190 | #define DIP(ip, field) \ |
| 191 | (((ip)->i_ump->um_fstype == ULFS1) ? \ |
| 192 | (ip)->i_din->u_32.di_##field : (ip)->i_din->u_64.di_##field) |
| 193 | |
| 194 | #define DIP_ASSIGN(ip, field, value) \ |
| 195 | do { \ |
| 196 | if ((ip)->i_ump->um_fstype == ULFS1) \ |
| 197 | (ip)->i_din->u_32.di_##field = (value); \ |
| 198 | else \ |
| 199 | (ip)->i_din->u_64.di_##field = (value); \ |
| 200 | } while(0) |
| 201 | |
| 202 | #define DIP_ADD(ip, field, value) \ |
| 203 | do { \ |
| 204 | if ((ip)->i_ump->um_fstype == ULFS1) \ |
| 205 | (ip)->i_din->u_32.di_##field += (value); \ |
| 206 | else \ |
| 207 | (ip)->i_din->u_64.di_##field += (value); \ |
| 208 | } while(0) |
| 209 | |
| 210 | /* XXX rework this better */ |
| 211 | #define SHORTLINK(ip) \ |
| 212 | (((ip)->i_ump->um_fstype == ULFS1) ? \ |
| 213 | (void *)(ip)->i_din->u_32.di_db : (void *)(ip)->i_din->u_64.di_db) |
| 214 | |
| 215 | |
| 216 | /* |
| 217 | * Structure used to pass around logical block paths generated by |
| 218 | * ulfs_getlbns and used by truncate and bmap code. |
| 219 | */ |
| 220 | struct indir { |
| 221 | daddr_t in_lbn; /* Logical block number. */ |
| 222 | int in_off; /* Offset in buffer. */ |
| 223 | int in_exists; /* Flag if the block exists. */ |
| 224 | }; |
| 225 | |
| 226 | /* Convert between inode pointers and vnode pointers. */ |
| 227 | #define VTOI(vp) ((struct inode *)(vp)->v_data) |
| 228 | #define ITOV(ip) ((ip)->i_vnode) |
| 229 | |
| 230 | #endif /* _KERNEL */ |
| 231 | |
| 232 | #endif /* !_UFS_LFS_ULFS_INODE_H_ */ |
| 233 | |