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