Home | History | Annotate | Line # | Download | only in coda
cnode.h revision 1.1
      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 
     30 /* $Header: /tank/opengrok/rsync2/NetBSD/src/sys/coda/cnode.h,v 1.1 1998/08/29 21:26:46 rvb Exp $ */
     31 
     32 /*
     33  * Mach Operating System
     34  * Copyright (c) 1990 Carnegie-Mellon University
     35  * Copyright (c) 1989 Carnegie-Mellon University
     36  * All rights reserved.  The CMU software License Agreement specifies
     37  * the terms and conditions for use and redistribution.
     38  */
     39 
     40 /*
     41  * This code was written for the Coda file system at Carnegie Mellon University.
     42  * Contributers include David Steere, James Kistler, and M. Satyanarayanan.
     43  */
     44 
     45 /*
     46  * HISTORY
     47  * $Log: cnode.h,v $
     48  * Revision 1.1  1998/08/29 21:26:46  rvb
     49  * Initial revision
     50  *
     51  * Revision 1.10  1998/08/28 18:12:25  rvb
     52  * Now it also works on FreeBSD -current.  This code will be
     53  * committed to the FreeBSD -current and NetBSD -current
     54  * trees.  It will then be tailored to the particular platform
     55  * by flushing conditional code.
     56  *
     57  * Revision 1.9  1998/08/18 17:05:24  rvb
     58  * Don't use __RCSID now
     59  *
     60  * Revision 1.8  1998/08/18 16:31:49  rvb
     61  * Sync the code for NetBSD -current; test on 1.3 later
     62  *
     63  * Revision 1.7  98/02/24  22:22:53  rvb
     64  * Fixes up mainly to flush iopen and friends
     65  *
     66  * Revision 1.6  98/01/31  20:53:19  rvb
     67  * First version that works on FreeBSD 2.2.5
     68  *
     69  * Revision 1.5  98/01/23  11:53:51  rvb
     70  * Bring RVB_CFS1_1 to HEAD
     71  *
     72  * Revision 1.4.2.5  98/01/23  11:21:14  rvb
     73  * Sync with 2.2.5
     74  *
     75  * Revision 1.4.2.4  98/01/22  13:03:38  rvb
     76  * Had Breaken ls .
     77  *
     78  * Revision 1.4.2.3  97/12/19  14:26:09  rvb
     79  * session id
     80  *
     81  * Revision 1.4.2.2  97/12/16  12:40:24  rvb
     82  * Sync with 1.3
     83  *
     84  * Revision 1.4.2.1  97/12/06  17:41:28  rvb
     85  * Sync with peters coda.h
     86  *
     87  * Revision 1.4  97/12/05  10:39:30  rvb
     88  * Read CHANGES
     89  *
     90  * Revision 1.3.18.2  97/11/12  12:09:45  rvb
     91  * reorg pass1
     92  *
     93  * Revision 1.3.18.1  97/10/29  16:06:31  rvb
     94  * Kill DYING
     95  *
     96  * Revision 1.3  1996/12/12 22:11:03  bnoble
     97  * Fixed the "downcall invokes venus operation" deadlock in all known cases.
     98  *  There may be more.
     99  *
    100  * Revision 1.2  1996/01/02 16:57:26  bnoble
    101  * Added support for Coda MiniCache and raw inode calls (final commit)
    102  *
    103  * Revision 1.1.2.1  1995/12/20 01:57:53  bnoble
    104  * Added CFS-specific files
    105  *
    106  * Revision 3.1.1.1  1995/03/04  19:08:23  bnoble
    107  * Branch for NetBSD port revisions
    108  *
    109  * Revision 3.1  1995/03/04  19:08:23  bnoble
    110  * Bump to major revision 3 to prepare for NetBSD port
    111  *
    112  * Revision 2.2  1994/12/06  13:39:18  dcs
    113  * Add a flag value to indicate a cnode was orphaned, e.g. the venus
    114  * that created it has exited. This will allow one to restart venus
    115  * even though some process may be cd'd into /coda.
    116  *
    117  * Revision 2.1  94/07/21  16:25:33  satya
    118  * Conversion to C++ 3.0; start of Coda Release 2.0
    119  *
    120  * Revision 1.2.7.1  94/06/16  11:26:02  raiff
    121  * Branch for release beta-16Jun1994_39118
    122  *
    123  * Revision 1.2  92/10/27  17:58:41  lily
    124  * merge kernel/latest and alpha/src/cfs
    125  *
    126  * Revision 2.3  92/09/30  14:16:53  mja
    127  * 	Picked up fixed #ifdef _KERNEL. Also...
    128  *
    129  * 	Substituted rvb's history blurb so that we agree with Mach 2.5 sources.
    130  * 	[91/02/09            jjk]
    131  *
    132  * 	Added contributors blurb.
    133  * 	[90/12/13            jjk]
    134  *
    135  * Revision 2.2  90/07/05  11:27:24  mrt
    136  * 	Created for the Coda File System.
    137  * 	[90/05/23            dcs]
    138  *
    139  * Revision 1.4  90/05/31  17:02:16  dcs
    140  * Prepare for merge with facilities kernel.
    141  *
    142  *
    143  *
    144  */
    145 
    146 #ifndef	_CNODE_H_
    147 #define	_CNODE_H_
    148 
    149 #include <sys/vnode.h>
    150 
    151 #ifdef	__FreeBSD__
    152 
    153 /* for the prototype of DELAY() */
    154 #include <machine/clock.h>
    155 
    156 #ifdef	__FreeBSD_version
    157 /* You would think that <sys/param.h> or something would include this */
    158 #include <sys/lock.h>
    159 
    160 MALLOC_DECLARE(M_CFS);
    161 
    162 #else
    163 
    164 /* yuck yuck yuck */
    165 #define vref(x) cvref(x)
    166 extern void cvref(struct vnode *vp);
    167 /* yuck yuck yuck */
    168 
    169 #endif
    170 #endif
    171 
    172 #if	defined(__NetBSD__) && defined(NetBSD1_3) && (NetBSD1_3 >= 7)
    173 #define	NEW_LOCKMGR(l, f, i) lockmgr(l, f, i)
    174 #define	VOP_X_LOCK(vn, fl) vn_lock(vn, fl)
    175 #define	VOP_X_UNLOCK(vn, fl) VOP_UNLOCK(vn, fl)
    176 
    177 #elif defined(__FreeBSD_version)
    178 #define	NEW_LOCKMGR(l, f, i) lockmgr(l, f, i, curproc)
    179 #define	VOP_X_LOCK(vn, fl) vn_lock(vn, fl, curproc)
    180 #define	VOP_X_UNLOCK(vn, fl) VOP_UNLOCK(vn, fl, curproc)
    181 
    182 /* NetBSD 1.3 & FreeBSD 2.2.x */
    183 #else
    184 #undef	NEW_LOCKMGR
    185 #define	VOP_X_LOCK(vn, fl) VOP_LOCK(vn)
    186 #define	VOP_X_UNLOCK(vn, fl) VOP_UNLOCK(vn)
    187 #endif
    188 
    189 /*
    190  * tmp below since we need struct queue
    191  */
    192 #include <cfs/cfsk.h>
    193 
    194 /*
    195  * Cnode lookup stuff.
    196  * NOTE: CFS_CACHESIZE must be a power of 2 for cfshash to work!
    197  */
    198 #define CFS_CACHESIZE 512
    199 
    200 #define CFS_ALLOC(ptr, cast, size)                                        \
    201 do {                                                                      \
    202     ptr = (cast)malloc((unsigned long) size, M_CFS, M_WAITOK);            \
    203     if (ptr == 0) {                                                       \
    204 	panic("kernel malloc returns 0 at %s:%d\n", __FILE__, __LINE__);  \
    205     }                                                                     \
    206 } while (0)
    207 
    208 #define CFS_FREE(ptr, size)  free((ptr), M_CFS)
    209 
    210 /*
    211  * global cache state control
    212  */
    213 extern int cfsnc_use;
    214 
    215 /*
    216  * Used to select debugging statements throughout the cfs code.
    217  */
    218 extern int cfsdebug;
    219 extern int cfsnc_debug;
    220 extern int cfs_printf_delay;
    221 extern int cfs_vnop_print_entry;
    222 extern int cfs_psdev_print_entry;
    223 extern int cfs_vfsop_print_entry;
    224 
    225 #define CFSDBGMSK(N)            (1 << N)
    226 #define CFSDEBUG(N, STMT)       { if (cfsdebug & CFSDBGMSK(N)) { STMT } }
    227 #define myprintf(args)          \
    228 do {                            \
    229     if (cfs_printf_delay)       \
    230 	DELAY(cfs_printf_delay);\
    231     printf args ;               \
    232 } while (0)
    233 
    234 struct cnode {
    235     struct vnode	*c_vnode;
    236     u_short		 c_flags;	/* flags (see below) */
    237     ViceFid		 c_fid;		/* file handle */
    238 #ifdef	NEW_LOCKMGR
    239     struct lock		 c_lock;	/* new lock protocol */
    240 #endif
    241     struct vnode	*c_ovp;		/* open vnode pointer */
    242     u_short		 c_ocount;	/* count of openers */
    243     u_short		 c_owrite;	/* count of open for write */
    244     struct vattr	 c_vattr; 	/* attributes */
    245     char		*c_symlink;	/* pointer to symbolic link */
    246     u_short		 c_symlen;	/* length of symbolic link */
    247     dev_t		 c_device;	/* associated vnode device */
    248     ino_t		 c_inode;	/* associated vnode inode */
    249     struct cnode	*c_next;	/* links if on NetBSD machine */
    250 };
    251 #define	VTOC(vp)	((struct cnode *)(vp)->v_data)
    252 #define	CTOV(cp)	((struct vnode *)((cp)->c_vnode))
    253 
    254 /* flags */
    255 #define C_VATTR		0x01	/* Validity of vattr in the cnode */
    256 #define C_SYMLINK	0x02	/* Validity of symlink pointer in the Code */
    257 #define C_WANTED	0x08	/* Set if lock wanted */
    258 #define C_LOCKED	0x10	/* Set if lock held */
    259 #define C_UNMOUNTING	0X20	/* Set if unmounting */
    260 #define C_PURGING	0x40	/* Set if purging a fid */
    261 
    262 #define VALID_VATTR(cp)		((cp->c_flags) & C_VATTR)
    263 #define VALID_SYMLINK(cp)	((cp->c_flags) & C_SYMLINK)
    264 #define IS_UNMOUNTING(cp)	((cp)->c_flags & C_UNMOUNTING)
    265 
    266 struct vcomm {
    267 	u_long		vc_seq;
    268 	struct selinfo	vc_selproc;
    269 	struct queue	vc_requests;
    270 	struct queue	vc_replys;
    271 };
    272 
    273 #define	VC_OPEN(vcp)	    ((vcp)->vc_requests.forw != NULL)
    274 #define MARK_VC_CLOSED(vcp) (vcp)->vc_requests.forw = NULL;
    275 #define MARK_VC_OPEN(vcp)    /* MT */
    276 
    277 struct cfs_clstat {
    278 	int	ncalls;			/* client requests */
    279 	int	nbadcalls;		/* upcall failures */
    280 	int	reqs[CFS_NCALLS];	/* count of each request */
    281 };
    282 extern struct cfs_clstat cfs_clstat;
    283 
    284 /*
    285  * CFS structure to hold mount/file system information
    286  */
    287 struct cfs_mntinfo {
    288     struct vnode	*mi_rootvp;
    289     struct mount	*mi_vfsp;
    290     struct vcomm	 mi_vcomm;
    291 };
    292 extern struct cfs_mntinfo cfs_mnttbl[]; /* indexed by minor device number */
    293 
    294 /*
    295  * vfs pointer to mount info
    296  */
    297 #define vftomi(vfsp)    ((struct cfs_mntinfo *)(vfsp->mnt_data))
    298 #define	CFS_MOUNTED(vfsp)   (vftomi((vfsp)) != (struct cfs_mntinfo *)0)
    299 
    300 /*
    301  * vnode pointer to mount info
    302  */
    303 #define vtomi(vp)       ((struct cfs_mntinfo *)(vp->v_mount->mnt_data))
    304 
    305 /*
    306  * Used for identifying usage of "Control" object
    307  */
    308 extern struct vnode *cfs_ctlvp;
    309 #define	IS_CTL_VP(vp)		((vp) == cfs_ctlvp)
    310 #define	IS_CTL_NAME(vp, name, l)((l == CFS_CONTROLLEN) \
    311  				 && ((vp) == vtomi((vp))->mi_rootvp)    \
    312 				 && strncmp(name, CFS_CONTROL, l) == 0)
    313 
    314 /*
    315  * An enum to tell us whether something that will remove a reference
    316  * to a cnode was a downcall or not
    317  */
    318 enum dc_status {
    319     IS_DOWNCALL = 6,
    320     NOT_DOWNCALL = 7
    321 };
    322 
    323 /* cfs_psdev.h */
    324 int cfscall(struct cfs_mntinfo *mntinfo, int inSize, int *outSize, caddr_t buffer);
    325 
    326 /* cfs_subr.h */
    327 int  handleDownCall(int opcode, union outputArgs *out);
    328 void cfs_unmounting(struct mount *whoIam);
    329 int  cfs_vmflush(struct cnode *cp);
    330 
    331 /* cfs_vnodeops.h */
    332 struct cnode *makecfsnode(ViceFid *fid, struct mount *vfsp, short type);
    333 int cfs_vnodeopstats_init(void);
    334 
    335 /* cfs_vfsops.h */
    336 struct mount *devtomp(dev_t dev);
    337 
    338 #if	!(defined NetBSD1_3) && !defined(__FreeBSD_version)
    339 #define __RCSID(x) static char *rcsid = x
    340 #endif
    341 
    342 /* sigh */
    343 #define CFS_RDWR ((u_long) 31)
    344 
    345 #endif	/* _CNODE_H_ */
    346 
    347