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