Home | History | Annotate | Line # | Download | only in lfs
ulfs_inode.h revision 1.9
      1 /*	$NetBSD: ulfs_inode.h,v 1.9 2013/06/18 18:18:58 christos Exp $	*/
      2 /*  from NetBSD: inode.h,v 1.64 2012/11/19 00:36:21 jakllsch 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 /* Misc. definitions */
     49 #define BW_CLEAN	1		/* Flag for lfs_bwrite_ext() */
     50 #define PG_DELWRI	PG_PAGER1	/* Local def for delayed pageout */
     51 
     52 /* Resource limits */
     53 #define	LFS_MAX_RESOURCE(x, u)	(((x) >> 2) - 10 * (u))
     54 #define	LFS_WAIT_RESOURCE(x, u)	(((x) >> 1) - ((x) >> 3) - 10 * (u))
     55 #define	LFS_INVERSE_MAX_RESOURCE(x, u)	(((x) + 10 * (u)) << 2)
     56 #define LFS_MAX_BUFS	    LFS_MAX_RESOURCE(nbuf, 1)
     57 #define LFS_WAIT_BUFS	    LFS_WAIT_RESOURCE(nbuf, 1)
     58 #define LFS_INVERSE_MAX_BUFS(n)	LFS_INVERSE_MAX_RESOURCE(n, 1)
     59 #define LFS_MAX_BYTES	    LFS_MAX_RESOURCE(bufmem_lowater, PAGE_SIZE)
     60 #define LFS_INVERSE_MAX_BYTES(n) LFS_INVERSE_MAX_RESOURCE(n, PAGE_SIZE)
     61 #define LFS_WAIT_BYTES	    LFS_WAIT_RESOURCE(bufmem_lowater, PAGE_SIZE)
     62 #define LFS_MAX_DIROP	    ((desiredvnodes >> 2) + (desiredvnodes >> 3))
     63 #define SIZEOF_DIROP(fs)	(2 * ((fs)->lfs_bsize + LFS_DINODE1_SIZE))
     64 #define LFS_MAX_FSDIROP(fs)						\
     65 	((fs)->lfs_nclean <= (fs)->lfs_resvseg ? 0 :			\
     66 	 (((fs)->lfs_nclean - (fs)->lfs_resvseg) * (fs)->lfs_ssize) /	\
     67           (2 * SIZEOF_DIROP(fs)))
     68 #define LFS_MAX_PAGES	lfs_max_pages()
     69 #define LFS_WAIT_PAGES	lfs_wait_pages()
     70 #define LFS_BUFWAIT	    2	/* How long to wait if over *_WAIT_* */
     71 
     72 #ifdef _KERNEL
     73 extern u_long bufmem_lowater, bufmem_hiwater; /* XXX */
     74 
     75 int lfs_wait_pages(void);
     76 int lfs_max_pages(void);
     77 #endif /* _KERNEL */
     78 
     79 /* How starved can we be before we start holding back page writes */
     80 #define LFS_STARVED_FOR_SEGS(fs) ((fs)->lfs_nclean < (fs)->lfs_resvseg)
     81 
     82 /*
     83  * Reserved blocks for lfs_malloc
     84  */
     85 
     86 /* Structure to keep reserved blocks */
     87 typedef struct lfs_res_blk {
     88 	void *p;
     89 	LIST_ENTRY(lfs_res_blk) res;
     90 	int size;
     91 	char inuse;
     92 } res_t;
     93 
     94 /* Types for lfs_newbuf and lfs_malloc */
     95 #define LFS_NB_UNKNOWN -1
     96 #define LFS_NB_SUMMARY	0
     97 #define LFS_NB_SBLOCK	1
     98 #define LFS_NB_IBLOCK	2
     99 #define LFS_NB_CLUSTER	3
    100 #define LFS_NB_CLEAN	4
    101 #define LFS_NB_BLKIOV	5
    102 #define LFS_NB_COUNT	6 /* always last */
    103 
    104 /* Number of reserved memory blocks of each type */
    105 #define LFS_N_SUMMARIES 2
    106 #define LFS_N_SBLOCKS	1   /* Always 1, to throttle superblock writes */
    107 #define LFS_N_IBLOCKS	16  /* In theory ssize/bsize; in practice around 2 */
    108 #define LFS_N_CLUSTERS	16  /* In theory ssize/MAXPHYS */
    109 #define LFS_N_CLEAN	0
    110 #define LFS_N_BLKIOV	1
    111 
    112 /* Total count of "large" (non-pool) types */
    113 #define LFS_N_TOTAL (LFS_N_SUMMARIES + LFS_N_SBLOCKS + LFS_N_IBLOCKS +	\
    114 		     LFS_N_CLUSTERS + LFS_N_CLEAN + LFS_N_BLKIOV)
    115 
    116 /* Counts for pool types */
    117 #define LFS_N_CL	LFS_N_CLUSTERS
    118 #define LFS_N_BPP	2
    119 #define LFS_N_SEG	2
    120 
    121 /*
    122  * "struct buf" associated definitions
    123  */
    124 
    125 /* Determine if a buffer belongs to the ifile */
    126 #define IS_IFILE(bp)	(VTOI(bp->b_vp)->i_number == LFS_IFILE_INUM)
    127 
    128 #ifdef _KERNEL
    129 /* This overlays the fid structure (see fstypes.h). */
    130 struct ulfs_ufid {
    131 	u_int16_t ufid_len;	/* Length of structure. */
    132 	u_int16_t ufid_pad;	/* Force 32-bit alignment. */
    133 	u_int32_t ufid_ino;	/* File number (ino). */
    134 	int32_t	  ufid_gen;	/* Generation number. */
    135 };
    136 /* Filehandle structure for exported LFSes */
    137 struct lfid {
    138 	struct ulfs_ufid lfid_ufid;
    139 #define lfid_len lfid_ufid.ufid_len
    140 #define lfid_ino lfid_ufid.ufid_ino
    141 #define lfid_gen lfid_ufid.ufid_gen
    142 	uint32_t lfid_ident;
    143 };
    144 #endif /* _KERNEL */
    145 
    146 /* Address calculations for metadata located in the inode */
    147 #define	S_INDIR(fs)	-ULFS_NDADDR
    148 #define	D_INDIR(fs)	(S_INDIR(fs) - LFS_NINDIR(fs) - 1)
    149 #define	T_INDIR(fs)	(D_INDIR(fs) - LFS_NINDIR(fs) * LFS_NINDIR(fs) - 1)
    150 
    151 /*
    152  * "struct vnode" associated definitions
    153  */
    154 
    155 /* Heuristic emptiness measure */
    156 #define VPISEMPTY(vp)	 (LIST_EMPTY(&(vp)->v_dirtyblkhd) && 		\
    157 			  !(vp->v_type == VREG && (vp)->v_iflag & VI_ONWORKLST) &&\
    158 			  VTOI(vp)->i_lfs_nbtree == 0)
    159 
    160 #define WRITEINPROG(vp) ((vp)->v_numoutput > 0 ||			\
    161 	(!LIST_EMPTY(&(vp)->v_dirtyblkhd) &&				\
    162 	 !(VTOI(vp)->i_flag & (IN_MODIFIED | IN_ACCESSED | IN_CLEANING))))
    163 
    164 
    165 
    166 
    167 
    168 #if defined(_KERNEL)
    169 
    170 /*
    171  * The DIP macro is used to access fields in the dinode that are
    172  * not cached in the inode itself.
    173  */
    174 #define	DIP(ip, field) \
    175 	(((ip)->i_ump->um_fstype == ULFS1) ? \
    176 	(ip)->i_ffs1_##field : (ip)->i_ffs2_##field)
    177 
    178 #define	DIP_ASSIGN(ip, field, value)					\
    179 	do {								\
    180 		if ((ip)->i_ump->um_fstype == ULFS1)			\
    181 			(ip)->i_ffs1_##field = (value);			\
    182 		else							\
    183 			(ip)->i_ffs2_##field = (value);			\
    184 	} while(0)
    185 
    186 #define	DIP_ADD(ip, field, value)					\
    187 	do {								\
    188 		if ((ip)->i_ump->um_fstype == ULFS1)			\
    189 			(ip)->i_ffs1_##field += (value);		\
    190 		else							\
    191 			(ip)->i_ffs2_##field += (value);		\
    192 	} while(0)
    193 
    194 #define	 SHORTLINK(ip) \
    195 	(((ip)->i_ump->um_fstype == ULFS1) ? \
    196 	(void *)(ip)->i_ffs1_db : (void *)(ip)->i_ffs2_db)
    197 
    198 
    199 /*
    200  * Structure used to pass around logical block paths generated by
    201  * ulfs_getlbns and used by truncate and bmap code.
    202  */
    203 struct indir {
    204 	daddr_t in_lbn;		/* Logical block number. */
    205 	int	in_off;			/* Offset in buffer. */
    206 	int	in_exists;		/* Flag if the block exists. */
    207 };
    208 
    209 /* Convert between inode pointers and vnode pointers. */
    210 #define	VTOI(vp)	((struct inode *)(vp)->v_data)
    211 #define	ITOV(ip)	((ip)->i_vnode)
    212 
    213 #endif /* _KERNEL */
    214 
    215 #endif /* !_UFS_LFS_ULFS_INODE_H_ */
    216