1/* 2 * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved. 3 * 4 * This program is free software; you can redistribute it and/or modify it 5 * under the terms of version 2 of the GNU General Public License as 6 * published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it would be useful, but 9 * WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 * 12 * Further, this software is distributed without any warranty that it is 13 * free of the rightful claim of any third person regarding infringement 14 * or the like. Any license provided herein, whether implied or 15 * otherwise, applies only to this software file. Patent licenses, if 16 * any, provided herein do not apply to combinations of this program with 17 * other software, or any other product whatsoever. 18 * 19 * You should have received a copy of the GNU General Public License along 20 * with this program; if not, write the Free Software Foundation, Inc., 59 21 * Temple Place - Suite 330, Boston MA 02111-1307, USA. 22 * 23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, 24 * Mountain View, CA 94043, or: 25 * 26 * http://www.sgi.com 27 * 28 * For further information regarding this notice, see: 29 * 30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ 31 */ 32 33#include "xfs.h" 34#include "xfs_types.h" 35#include "xfs_bit.h" 36#include "xfs_inum.h" 37#include "xfs_log.h" 38#include "xfs_trans.h" 39#include "xfs_trans_priv.h" 40#include "xfs_sb.h" 41#include "xfs_ag.h" 42#include "xfs_dir.h" 43#include "xfs_dir2.h" 44#include "xfs_dmapi.h" 45#include "xfs_mount.h" 46#include "xfs_alloc_btree.h" 47#include "xfs_bmap_btree.h" 48#include "xfs_ialloc_btree.h" 49#include "xfs_btree.h" 50#include "xfs_imap.h" 51#include "xfs_alloc.h" 52#include "xfs_attr_sf.h" 53#include "xfs_dir_sf.h" 54#include "xfs_dir2_sf.h" 55#include "xfs_dinode.h" 56#include "xfs_ialloc.h" 57#include "xfs_inode.h" 58#include "xfs_inode_item.h" 59 60void 61vn_init(void) 62{ 63} 64 65void 66vn_iowait( 67 struct xfs_vnode *vp) 68{ 69 printf("vn_iowait doing nothing on FreeBSD?\n"); 70} 71 72struct xfs_vnode * 73vn_initialize( 74 xfs_vnode_t *vp) 75{ 76 XFS_STATS_INC(vn_active); 77 XFS_STATS_INC(vn_alloc); 78 79 /* Initialize the first behavior and the behavior chain head. */ 80 vn_bhv_head_init(VN_BHV_HEAD(vp), "vnode"); 81 82#ifdef CONFIG_XFS_VNODE_TRACING 83 vp->v_trace = ktrace_alloc(VNODE_TRACE_SIZE, KM_SLEEP); 84#endif /* CONFIG_XFS_VNODE_TRACING */ 85 86 vn_trace_exit(vp, "vn_initialize", (inst_t *)__return_address); 87 return vp; 88} 89 90/* 91 * Get a reference on a vnode. Need to drop vnode reference 92 * to accomodate for vhold by VMAP regardless of whether or 93 * not we were able to successfully grab the vnode. 94 */ 95xfs_vnode_t * 96vn_get( 97 struct xfs_vnode *xfs_vp, 98 vmap_t *vmap) 99{ 100 struct vnode *vp; 101 int error; 102 103 XFS_STATS_INC(vn_get); 104 105 vp = vmap->v_vp; 106 107 error = vget(vp, LK_EXCLUSIVE, curthread); 108 vdrop(vp); 109 if (error) 110 return (NULL); 111 112 /* 113 * Drop the vnode returned by vget here. 114 * VOP_RECLAIM(9) should block on internal XFS locks so that 115 * the reclaiming scheme still remains consistent even if the 116 * vp is not locked. 117 */ 118 VOP_UNLOCK(vp, 0); 119 if (vp->v_data != xfs_vp) { 120 vput(vp); 121 return (NULL); 122 } 123 124 vn_trace_exit(vp, "vn_get", (inst_t *)__return_address); 125 return xfs_vp; 126} 127 128/* 129 * purge a vnode from the cache 130 * At this point the vnode is guaranteed to have no references (vn_count == 0) 131 * The caller has to make sure that there are no ways someone could 132 * get a handle (via vn_get) on the vnode (usually done via a mount/vfs lock). 133 */ 134void 135vn_purge(struct xfs_vnode *xfs_vp) 136{ 137 struct vnode *vp; 138 139 vn_trace_entry(vp, "vn_purge", (inst_t *)__return_address); 140 141 vp = xfs_vp->v_vnode; 142 143 vn_lock(vp, LK_EXCLUSIVE); 144 if (vp->v_holdcnt == 0) 145 vhold(vp); 146 vgone(vp); 147 VOP_UNLOCK(vp, 0); 148} 149 150void xfs_ichgtime( 151 xfs_inode_t *ip, 152 int flags) 153{ 154 timespec_t tv; 155 156 vfs_timestamp(&tv); 157 if (flags & XFS_ICHGTIME_MOD) { 158 ip->i_d.di_mtime.t_sec = (__int32_t)tv.tv_sec; 159 ip->i_d.di_mtime.t_nsec = (__int32_t)tv.tv_nsec; 160 } 161 if (flags & XFS_ICHGTIME_ACC) { 162 ip->i_d.di_atime.t_sec = (__int32_t)tv.tv_sec; 163 ip->i_d.di_atime.t_nsec = (__int32_t)tv.tv_nsec; 164 } 165 if (flags & XFS_ICHGTIME_CHG) { 166 ip->i_d.di_ctime.t_sec = (__int32_t)tv.tv_sec; 167 ip->i_d.di_ctime.t_nsec = (__int32_t)tv.tv_nsec; 168 } 169 170//printf ("xfs_ichgtime NI\n"); 171 172} 173 174 175/* 176 * Bring the atime in the XFS inode uptodate. 177 * Used before logging the inode to disk or when the Linux inode goes away. 178 */ 179 180/* 181 * It's unclear if we need this since this is for syncing the linux inode's atime 182 * to the xfs inode's atime. 183 * Since FreeBSD doesn't have atime in the vnode is there anything to really 184 * sync over? 185 * For now just make this a update atime call 186 */ 187 188void 189xfs_synchronize_atime( 190 xfs_inode_t *ip) 191{ 192#if 0 193 xfs_vnode_t *vp; 194#endif 195 196 timespec_t tv; 197 198/* vfs_timestamp looks at the system time accuracy variable */ 199 vfs_timestamp(&tv); 200#if 0 201 printf("xfs_synchronize_atime old (%d,%d) new (%d,%ld)\n", 202 ip->i_d.di_atime.t_sec, 203 ip->i_d.di_atime.t_nsec, 204 tv.tv_sec, 205 tv.tv_nsec); 206#endif 207 208 ip->i_d.di_atime.t_sec = (__int32_t)tv.tv_sec; 209 ip->i_d.di_atime.t_nsec = (__int32_t)tv.tv_nsec; 210} 211 212#ifdef RMC 213/* 214 * Extracting atime values in various formats 215 */ 216void vn_atime_to_bstime(struct xfs_vnode *vp, xfs_bstime_t *bs_atime) 217{ 218 bs_atime->tv_sec = vp->v_inode.i_atime.tv_sec; 219 bs_atime->tv_nsec = vp->v_inode.i_atime.tv_nsec; 220 printf("vn_atime_to_bstime NI\n"); 221} 222#endif 223 224 225#ifdef CONFIG_XFS_VNODE_TRACING 226 227#define KTRACE_ENTER(vp, vk, s, line, ra) \ 228 ktrace_enter( (vp)->v_trace, \ 229/* 0 */ (void *)(__psint_t)(vk), \ 230/* 1 */ (void *)(s), \ 231/* 2 */ (void *)(__psint_t) line, \ 232/* 3 */ (void *)(vn_count(vp)), \ 233/* 4 */ (void *)(ra), \ 234/* 5 */ (void *)(__psunsigned_t)(vp)->v_flag, \ 235/* 6 */ (void *)(__psint_t)smp_processor_id(), \ 236/* 7 */ (void *)(__psint_t)(current->pid), \ 237/* 8 */ (void *)__return_address, \ 238/* 9 */ 0, 0, 0, 0, 0, 0, 0) 239 240/* 241 * Vnode tracing code. 242 */ 243void 244vn_trace_entry(xfs_vnode_t *vp, char *func, inst_t *ra) 245{ 246 KTRACE_ENTER(vp, VNODE_KTRACE_ENTRY, func, 0, ra); 247} 248 249void 250vn_trace_exit(xfs_vnode_t *vp, char *func, inst_t *ra) 251{ 252 KTRACE_ENTER(vp, VNODE_KTRACE_EXIT, func, 0, ra); 253} 254 255void 256vn_trace_hold(xfs_vnode_t *vp, char *file, int line, inst_t *ra) 257{ 258 KTRACE_ENTER(vp, VNODE_KTRACE_HOLD, file, line, ra); 259} 260 261void 262vn_trace_ref(xfs_vnode_t *vp, char *file, int line, inst_t *ra) 263{ 264 KTRACE_ENTER(vp, VNODE_KTRACE_REF, file, line, ra); 265} 266 267void 268vn_trace_rele(xfs_vnode_t *vp, char *file, int line, inst_t *ra) 269{ 270 KTRACE_ENTER(vp, VNODE_KTRACE_RELE, file, line, ra); 271} 272#endif /* CONFIG_XFS_VNODE_TRACING */ 273