cnode.h revision 39085
1/* 2 * 3 * Coda: an Experimental Distributed File System 4 * Release 3.1 5 * 6 * Copyright (c) 1987-1998 Carnegie Mellon University 7 * All Rights Reserved 8 * 9 * Permission to use, copy, modify and distribute this software and its 10 * documentation is hereby granted, provided that both the copyright 11 * notice and this permission notice appear in all copies of the 12 * software, derivative works or modified versions, and any portions 13 * thereof, and that both notices appear in supporting documentation, and 14 * that credit is given to Carnegie Mellon University in all documents 15 * and publicity pertaining to direct or indirect use of this code or its 16 * derivatives. 17 * 18 * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS, 19 * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS 20 * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON 21 * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER 22 * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF 23 * ANY DERIVATIVE WORK. 24 * 25 * Carnegie Mellon encourages users of this software to return any 26 * improvements or extensions that they make, and to grant Carnegie 27 * Mellon the rights to redistribute these changes without encumbrance. 28 * 29 * @(#) src/sys/cfs/cnode.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $ 30 * $Id: cnode.h,v 1.2 1998/09/02 19:09:53 rvb Exp $ 31 * 32 */ 33 34/* 35 * Mach Operating System 36 * Copyright (c) 1990 Carnegie-Mellon University 37 * Copyright (c) 1989 Carnegie-Mellon University 38 * All rights reserved. The CMU software License Agreement specifies 39 * the terms and conditions for use and redistribution. 40 */ 41 42/* 43 * This code was written for the Coda file system at Carnegie Mellon University. 44 * Contributers include David Steere, James Kistler, and M. Satyanarayanan. 45 */ 46 47/* 48 * HISTORY 49 * $Log: cnode.h,v $ 50 * Revision 1.2 1998/09/02 19:09:53 rvb 51 * Pass2 complete 52 * 53 * Revision 1.1.1.1 1998/08/29 21:14:52 rvb 54 * Very Preliminary Coda 55 * 56 * Revision 1.10 1998/08/28 18:12:25 rvb 57 * Now it also works on FreeBSD -current. This code will be 58 * committed to the FreeBSD -current and NetBSD -current 59 * trees. It will then be tailored to the particular platform 60 * by flushing conditional code. 61 * 62 * Revision 1.9 1998/08/18 17:05:24 rvb 63 * Don't use __RCSID now 64 * 65 * Revision 1.8 1998/08/18 16:31:49 rvb 66 * Sync the code for NetBSD -current; test on 1.3 later 67 * 68 * Revision 1.7 98/02/24 22:22:53 rvb 69 * Fixes up mainly to flush iopen and friends 70 * 71 * Revision 1.6 98/01/31 20:53:19 rvb 72 * First version that works on FreeBSD 2.2.5 73 * 74 * Revision 1.5 98/01/23 11:53:51 rvb 75 * Bring RVB_CODA1_1 to HEAD 76 * 77 * Revision 1.4.2.5 98/01/23 11:21:14 rvb 78 * Sync with 2.2.5 79 * 80 * Revision 1.4.2.4 98/01/22 13:03:38 rvb 81 * Had Breaken ls . 82 * 83 * Revision 1.4.2.3 97/12/19 14:26:09 rvb 84 * session id 85 * 86 * Revision 1.4.2.2 97/12/16 12:40:24 rvb 87 * Sync with 1.3 88 * 89 * Revision 1.4.2.1 97/12/06 17:41:28 rvb 90 * Sync with peters coda.h 91 * 92 * Revision 1.4 97/12/05 10:39:30 rvb 93 * Read CHANGES 94 * 95 * Revision 1.3.18.2 97/11/12 12:09:45 rvb 96 * reorg pass1 97 * 98 * Revision 1.3.18.1 97/10/29 16:06:31 rvb 99 * Kill DYING 100 * 101 * Revision 1.3 1996/12/12 22:11:03 bnoble 102 * Fixed the "downcall invokes venus operation" deadlock in all known cases. 103 * There may be more. 104 * 105 * Revision 1.2 1996/01/02 16:57:26 bnoble 106 * Added support for Coda MiniCache and raw inode calls (final commit) 107 * 108 * Revision 1.1.2.1 1995/12/20 01:57:53 bnoble 109 * Added CODA-specific files 110 * 111 * Revision 3.1.1.1 1995/03/04 19:08:23 bnoble 112 * Branch for NetBSD port revisions 113 * 114 * Revision 3.1 1995/03/04 19:08:23 bnoble 115 * Bump to major revision 3 to prepare for NetBSD port 116 * 117 * Revision 2.2 1994/12/06 13:39:18 dcs 118 * Add a flag value to indicate a cnode was orphaned, e.g. the venus 119 * that created it has exited. This will allow one to restart venus 120 * even though some process may be cd'd into /coda. 121 * 122 * Revision 2.1 94/07/21 16:25:33 satya 123 * Conversion to C++ 3.0; start of Coda Release 2.0 124 * 125 * Revision 1.2.7.1 94/06/16 11:26:02 raiff 126 * Branch for release beta-16Jun1994_39118 127 * 128 * Revision 1.2 92/10/27 17:58:41 lily 129 * merge kernel/latest and alpha/src/cfs 130 * 131 * Revision 2.3 92/09/30 14:16:53 mja 132 * Picked up fixed #ifdef _KERNEL. Also... 133 * 134 * Substituted rvb's history blurb so that we agree with Mach 2.5 sources. 135 * [91/02/09 jjk] 136 * 137 * Added contributors blurb. 138 * [90/12/13 jjk] 139 * 140 * Revision 2.2 90/07/05 11:27:24 mrt 141 * Created for the Coda File System. 142 * [90/05/23 dcs] 143 * 144 * Revision 1.4 90/05/31 17:02:16 dcs 145 * Prepare for merge with facilities kernel. 146 * 147 * 148 * 149 */ 150 151#ifndef _CNODE_H_ 152#define _CNODE_H_ 153 154#include <sys/vnode.h> 155#include <sys/lock.h> 156#include <machine/clock.h> 157 158MALLOC_DECLARE(M_CODA); 159 160/* 161 * tmp below since we need struct queue 162 */ 163#include <cfs/cfsk.h> 164 165/* 166 * Cnode lookup stuff. 167 * NOTE: CODA_CACHESIZE must be a power of 2 for cfshash to work! 168 */ 169#define CODA_CACHESIZE 512 170 171#define CODA_ALLOC(ptr, cast, size) \ 172do { \ 173 ptr = (cast)malloc((unsigned long) size, M_CODA, M_WAITOK); \ 174 if (ptr == 0) { \ 175 panic("kernel malloc returns 0 at %s:%d\n", __FILE__, __LINE__); \ 176 } \ 177} while (0) 178 179#define CODA_FREE(ptr, size) free((ptr), M_CODA) 180 181/* 182 * global cache state control 183 */ 184extern int coda_nc_use; 185 186/* 187 * Used to select debugging statements throughout the cfs code. 188 */ 189extern int codadebug; 190extern int coda_nc_debug; 191extern int coda_printf_delay; 192extern int coda_vnop_print_entry; 193extern int coda_psdev_print_entry; 194extern int coda_vfsop_print_entry; 195 196#define CODADBGMSK(N) (1 << N) 197#define CODADEBUG(N, STMT) { if (codadebug & CODADBGMSK(N)) { STMT } } 198#define myprintf(args) \ 199do { \ 200 if (coda_printf_delay) \ 201 DELAY(coda_printf_delay);\ 202 printf args ; \ 203} while (0) 204 205struct cnode { 206 struct vnode *c_vnode; 207 u_short c_flags; /* flags (see below) */ 208 ViceFid c_fid; /* file handle */ 209 struct lock c_lock; /* new lock protocol */ 210 struct vnode *c_ovp; /* open vnode pointer */ 211 u_short c_ocount; /* count of openers */ 212 u_short c_owrite; /* count of open for write */ 213 struct vattr c_vattr; /* attributes */ 214 char *c_symlink; /* pointer to symbolic link */ 215 u_short c_symlen; /* length of symbolic link */ 216 dev_t c_device; /* associated vnode device */ 217 ino_t c_inode; /* associated vnode inode */ 218 struct cnode *c_next; /* links if on NetBSD machine */ 219}; 220#define VTOC(vp) ((struct cnode *)(vp)->v_data) 221#define CTOV(cp) ((struct vnode *)((cp)->c_vnode)) 222 223/* flags */ 224#define C_VATTR 0x01 /* Validity of vattr in the cnode */ 225#define C_SYMLINK 0x02 /* Validity of symlink pointer in the Code */ 226#define C_WANTED 0x08 /* Set if lock wanted */ 227#define C_LOCKED 0x10 /* Set if lock held */ 228#define C_UNMOUNTING 0X20 /* Set if unmounting */ 229#define C_PURGING 0x40 /* Set if purging a fid */ 230 231#define VALID_VATTR(cp) ((cp->c_flags) & C_VATTR) 232#define VALID_SYMLINK(cp) ((cp->c_flags) & C_SYMLINK) 233#define IS_UNMOUNTING(cp) ((cp)->c_flags & C_UNMOUNTING) 234 235struct vcomm { 236 u_long vc_seq; 237 struct selinfo vc_selproc; 238 struct queue vc_requests; 239 struct queue vc_replys; 240}; 241 242#define VC_OPEN(vcp) ((vcp)->vc_requests.forw != NULL) 243#define MARK_VC_CLOSED(vcp) (vcp)->vc_requests.forw = NULL; 244#define MARK_VC_OPEN(vcp) /* MT */ 245 246struct coda_clstat { 247 int ncalls; /* client requests */ 248 int nbadcalls; /* upcall failures */ 249 int reqs[CODA_NCALLS]; /* count of each request */ 250}; 251extern struct coda_clstat coda_clstat; 252 253/* 254 * CODA structure to hold mount/file system information 255 */ 256struct coda_mntinfo { 257 struct vnode *mi_rootvp; 258 struct mount *mi_vfsp; 259 struct vcomm mi_vcomm; 260}; 261extern struct coda_mntinfo coda_mnttbl[]; /* indexed by minor device number */ 262 263/* 264 * vfs pointer to mount info 265 */ 266#define vftomi(vfsp) ((struct coda_mntinfo *)(vfsp->mnt_data)) 267#define CODA_MOUNTED(vfsp) (vftomi((vfsp)) != (struct coda_mntinfo *)0) 268 269/* 270 * vnode pointer to mount info 271 */ 272#define vtomi(vp) ((struct coda_mntinfo *)(vp->v_mount->mnt_data)) 273 274/* 275 * Used for identifying usage of "Control" object 276 */ 277extern struct vnode *coda_ctlvp; 278#define IS_CTL_VP(vp) ((vp) == coda_ctlvp) 279#define IS_CTL_NAME(vp, name, l)((l == CODA_CONTROLLEN) \ 280 && ((vp) == vtomi((vp))->mi_rootvp) \ 281 && strncmp(name, CODA_CONTROL, l) == 0) 282 283/* 284 * An enum to tell us whether something that will remove a reference 285 * to a cnode was a downcall or not 286 */ 287enum dc_status { 288 IS_DOWNCALL = 6, 289 NOT_DOWNCALL = 7 290}; 291 292/* cfs_psdev.h */ 293int coda_call(struct coda_mntinfo *mntinfo, int inSize, int *outSize, caddr_t buffer); 294 295/* cfs_subr.h */ 296int handleDownCall(int opcode, union outputArgs *out); 297void coda_unmounting(struct mount *whoIam); 298int coda_vmflush(struct cnode *cp); 299 300/* cfs_vnodeops.h */ 301struct cnode *make_coda_node(ViceFid *fid, struct mount *vfsp, short type); 302int coda_vnodeopstats_init(void); 303 304/* coda_vfsops.h */ 305struct mount *devtomp(dev_t dev); 306 307/* sigh */ 308#define CODA_RDWR ((u_long) 31) 309 310#endif /* _CNODE_H_ */ 311 312