Home | History | Annotate | Line # | Download | only in coda
cnode.h revision 1.7
      1  1.7  cgd /*	$NetBSD: cnode.h,v 1.7 1999/10/17 23:39:15 cgd Exp $	*/
      2  1.2  rvb 
      3  1.1  rvb /*
      4  1.2  rvb  *
      5  1.2  rvb  *             Coda: an Experimental Distributed File System
      6  1.2  rvb  *                              Release 3.1
      7  1.2  rvb  *
      8  1.2  rvb  *           Copyright (c) 1987-1998 Carnegie Mellon University
      9  1.2  rvb  *                          All Rights Reserved
     10  1.2  rvb  *
     11  1.2  rvb  * Permission  to  use, copy, modify and distribute this software and its
     12  1.2  rvb  * documentation is hereby granted,  provided  that  both  the  copyright
     13  1.2  rvb  * notice  and  this  permission  notice  appear  in  all  copies  of the
     14  1.2  rvb  * software, derivative works or  modified  versions,  and  any  portions
     15  1.2  rvb  * thereof, and that both notices appear in supporting documentation, and
     16  1.2  rvb  * that credit is given to Carnegie Mellon University  in  all  documents
     17  1.2  rvb  * and publicity pertaining to direct or indirect use of this code or its
     18  1.2  rvb  * derivatives.
     19  1.2  rvb  *
     20  1.2  rvb  * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS  KNOWN  TO  HAVE  BUGS,
     21  1.2  rvb  * SOME  OF  WHICH MAY HAVE SERIOUS CONSEQUENCES.  CARNEGIE MELLON ALLOWS
     22  1.2  rvb  * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.   CARNEGIE  MELLON
     23  1.2  rvb  * DISCLAIMS  ANY  LIABILITY  OF  ANY  KIND  FOR  ANY  DAMAGES WHATSOEVER
     24  1.2  rvb  * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE  OR  OF
     25  1.2  rvb  * ANY DERIVATIVE WORK.
     26  1.2  rvb  *
     27  1.2  rvb  * Carnegie  Mellon  encourages  users  of  this  software  to return any
     28  1.2  rvb  * improvements or extensions that  they  make,  and  to  grant  Carnegie
     29  1.2  rvb  * Mellon the rights to redistribute these changes without encumbrance.
     30  1.2  rvb  *
     31  1.4  rvb  * 	@(#) coda/cnode.h,v 1.1.1.1 1998/08/29 21:26:46 rvb Exp $
     32  1.2  rvb  */
     33  1.1  rvb 
     34  1.1  rvb /*
     35  1.1  rvb  * Mach Operating System
     36  1.1  rvb  * Copyright (c) 1990 Carnegie-Mellon University
     37  1.1  rvb  * Copyright (c) 1989 Carnegie-Mellon University
     38  1.1  rvb  * All rights reserved.  The CMU software License Agreement specifies
     39  1.1  rvb  * the terms and conditions for use and redistribution.
     40  1.1  rvb  */
     41  1.1  rvb 
     42  1.1  rvb /*
     43  1.1  rvb  * This code was written for the Coda file system at Carnegie Mellon University.
     44  1.1  rvb  * Contributers include David Steere, James Kistler, and M. Satyanarayanan.
     45  1.1  rvb  */
     46  1.1  rvb 
     47  1.1  rvb #ifndef	_CNODE_H_
     48  1.1  rvb #define	_CNODE_H_
     49  1.1  rvb 
     50  1.1  rvb #include <sys/vnode.h>
     51  1.1  rvb 
     52  1.1  rvb /*
     53  1.1  rvb  * tmp below since we need struct queue
     54  1.1  rvb  */
     55  1.4  rvb #include <coda/coda_kernel.h>
     56  1.1  rvb 
     57  1.1  rvb /*
     58  1.1  rvb  * Cnode lookup stuff.
     59  1.3  rvb  * NOTE: CODA_CACHESIZE must be a power of 2 for cfshash to work!
     60  1.1  rvb  */
     61  1.3  rvb #define CODA_CACHESIZE 512
     62  1.1  rvb 
     63  1.3  rvb #define CODA_ALLOC(ptr, cast, size)                                        \
     64  1.1  rvb do {                                                                      \
     65  1.3  rvb     ptr = (cast)malloc((unsigned long) size, M_CODA, M_WAITOK);            \
     66  1.1  rvb     if (ptr == 0) {                                                       \
     67  1.1  rvb 	panic("kernel malloc returns 0 at %s:%d\n", __FILE__, __LINE__);  \
     68  1.1  rvb     }                                                                     \
     69  1.1  rvb } while (0)
     70  1.1  rvb 
     71  1.3  rvb #define CODA_FREE(ptr, size)  free((ptr), M_CODA)
     72  1.1  rvb 
     73  1.1  rvb /*
     74  1.1  rvb  * global cache state control
     75  1.1  rvb  */
     76  1.3  rvb extern int coda_nc_use;
     77  1.1  rvb 
     78  1.1  rvb /*
     79  1.1  rvb  * Used to select debugging statements throughout the cfs code.
     80  1.1  rvb  */
     81  1.3  rvb extern int codadebug;
     82  1.3  rvb extern int coda_nc_debug;
     83  1.3  rvb extern int coda_printf_delay;
     84  1.3  rvb extern int coda_vnop_print_entry;
     85  1.3  rvb extern int coda_psdev_print_entry;
     86  1.3  rvb extern int coda_vfsop_print_entry;
     87  1.1  rvb 
     88  1.3  rvb #define CODADBGMSK(N)            (1 << N)
     89  1.3  rvb #define CODADEBUG(N, STMT)       { if (codadebug & CODADBGMSK(N)) { STMT } }
     90  1.1  rvb #define myprintf(args)          \
     91  1.1  rvb do {                            \
     92  1.3  rvb     if (coda_printf_delay)       \
     93  1.3  rvb 	DELAY(coda_printf_delay);\
     94  1.1  rvb     printf args ;               \
     95  1.1  rvb } while (0)
     96  1.1  rvb 
     97  1.1  rvb struct cnode {
     98  1.1  rvb     struct vnode	*c_vnode;
     99  1.1  rvb     u_short		 c_flags;	/* flags (see below) */
    100  1.1  rvb     ViceFid		 c_fid;		/* file handle */
    101  1.1  rvb     struct vnode	*c_ovp;		/* open vnode pointer */
    102  1.1  rvb     u_short		 c_ocount;	/* count of openers */
    103  1.1  rvb     u_short		 c_owrite;	/* count of open for write */
    104  1.1  rvb     struct vattr	 c_vattr; 	/* attributes */
    105  1.1  rvb     char		*c_symlink;	/* pointer to symbolic link */
    106  1.1  rvb     u_short		 c_symlen;	/* length of symbolic link */
    107  1.1  rvb     dev_t		 c_device;	/* associated vnode device */
    108  1.1  rvb     ino_t		 c_inode;	/* associated vnode inode */
    109  1.1  rvb     struct cnode	*c_next;	/* links if on NetBSD machine */
    110  1.1  rvb };
    111  1.1  rvb #define	VTOC(vp)	((struct cnode *)(vp)->v_data)
    112  1.1  rvb #define	CTOV(cp)	((struct vnode *)((cp)->c_vnode))
    113  1.1  rvb 
    114  1.1  rvb /* flags */
    115  1.1  rvb #define C_VATTR		0x01	/* Validity of vattr in the cnode */
    116  1.1  rvb #define C_SYMLINK	0x02	/* Validity of symlink pointer in the Code */
    117  1.1  rvb #define C_WANTED	0x08	/* Set if lock wanted */
    118  1.1  rvb #define C_LOCKED	0x10	/* Set if lock held */
    119  1.1  rvb #define C_UNMOUNTING	0X20	/* Set if unmounting */
    120  1.1  rvb #define C_PURGING	0x40	/* Set if purging a fid */
    121  1.1  rvb 
    122  1.1  rvb #define VALID_VATTR(cp)		((cp->c_flags) & C_VATTR)
    123  1.1  rvb #define VALID_SYMLINK(cp)	((cp->c_flags) & C_SYMLINK)
    124  1.1  rvb #define IS_UNMOUNTING(cp)	((cp)->c_flags & C_UNMOUNTING)
    125  1.1  rvb 
    126  1.1  rvb struct vcomm {
    127  1.1  rvb 	u_long		vc_seq;
    128  1.1  rvb 	struct selinfo	vc_selproc;
    129  1.1  rvb 	struct queue	vc_requests;
    130  1.1  rvb 	struct queue	vc_replys;
    131  1.1  rvb };
    132  1.1  rvb 
    133  1.1  rvb #define	VC_OPEN(vcp)	    ((vcp)->vc_requests.forw != NULL)
    134  1.1  rvb #define MARK_VC_CLOSED(vcp) (vcp)->vc_requests.forw = NULL;
    135  1.1  rvb #define MARK_VC_OPEN(vcp)    /* MT */
    136  1.1  rvb 
    137  1.3  rvb struct coda_clstat {
    138  1.1  rvb 	int	ncalls;			/* client requests */
    139  1.1  rvb 	int	nbadcalls;		/* upcall failures */
    140  1.3  rvb 	int	reqs[CODA_NCALLS];	/* count of each request */
    141  1.1  rvb };
    142  1.3  rvb extern struct coda_clstat coda_clstat;
    143  1.1  rvb 
    144  1.1  rvb /*
    145  1.3  rvb  * CODA structure to hold mount/file system information
    146  1.1  rvb  */
    147  1.3  rvb struct coda_mntinfo {
    148  1.1  rvb     struct vnode	*mi_rootvp;
    149  1.1  rvb     struct mount	*mi_vfsp;
    150  1.1  rvb     struct vcomm	 mi_vcomm;
    151  1.1  rvb };
    152  1.3  rvb extern struct coda_mntinfo coda_mnttbl[]; /* indexed by minor device number */
    153  1.1  rvb 
    154  1.1  rvb /*
    155  1.1  rvb  * vfs pointer to mount info
    156  1.1  rvb  */
    157  1.3  rvb #define vftomi(vfsp)    ((struct coda_mntinfo *)(vfsp->mnt_data))
    158  1.3  rvb #define	CODA_MOUNTED(vfsp)   (vftomi((vfsp)) != (struct coda_mntinfo *)0)
    159  1.1  rvb 
    160  1.1  rvb /*
    161  1.1  rvb  * vnode pointer to mount info
    162  1.1  rvb  */
    163  1.3  rvb #define vtomi(vp)       ((struct coda_mntinfo *)(vp->v_mount->mnt_data))
    164  1.1  rvb 
    165  1.1  rvb /*
    166  1.1  rvb  * Used for identifying usage of "Control" object
    167  1.1  rvb  */
    168  1.3  rvb extern struct vnode *coda_ctlvp;
    169  1.3  rvb #define	IS_CTL_VP(vp)		((vp) == coda_ctlvp)
    170  1.3  rvb #define	IS_CTL_NAME(vp, name, l)((l == CODA_CONTROLLEN) \
    171  1.1  rvb  				 && ((vp) == vtomi((vp))->mi_rootvp)    \
    172  1.3  rvb 				 && strncmp(name, CODA_CONTROL, l) == 0)
    173  1.1  rvb 
    174  1.1  rvb /*
    175  1.1  rvb  * An enum to tell us whether something that will remove a reference
    176  1.1  rvb  * to a cnode was a downcall or not
    177  1.1  rvb  */
    178  1.1  rvb enum dc_status {
    179  1.1  rvb     IS_DOWNCALL = 6,
    180  1.1  rvb     NOT_DOWNCALL = 7
    181  1.1  rvb };
    182  1.1  rvb 
    183  1.1  rvb /* cfs_psdev.h */
    184  1.5  rvb extern int coda_call(struct coda_mntinfo *mntinfo, int inSize, int *outSize, caddr_t buffer);
    185  1.5  rvb extern int coda_kernel_version;
    186  1.1  rvb 
    187  1.1  rvb /* cfs_subr.h */
    188  1.5  rvb extern int  handleDownCall(int opcode, union outputArgs *out);
    189  1.5  rvb extern void coda_unmounting(struct mount *whoIam);
    190  1.5  rvb extern int  coda_vmflush(struct cnode *cp);
    191  1.1  rvb 
    192  1.1  rvb /* cfs_vnodeops.h */
    193  1.5  rvb extern struct cnode *make_coda_node(ViceFid *fid, struct mount *vfsp, short type);
    194  1.5  rvb extern int coda_vnodeopstats_init(void);
    195  1.1  rvb 
    196  1.3  rvb /* coda_vfsops.h */
    197  1.5  rvb extern struct mount *devtomp(dev_t dev);
    198  1.1  rvb 
    199  1.1  rvb /* sigh */
    200  1.3  rvb #define CODA_RDWR ((u_long) 31)
    201  1.1  rvb 
    202  1.1  rvb #endif	/* _CNODE_H_ */
    203  1.1  rvb 
    204