Home | History | Annotate | Line # | Download | only in coda
      1  1.21   thorpej /*	$NetBSD: cnode.h,v 1.21 2024/05/17 23:56:24 thorpej Exp $	*/
      2   1.2       rvb 
      3   1.1       rvb /*
      4  1.14     perry  *
      5   1.2       rvb  *             Coda: an Experimental Distributed File System
      6   1.2       rvb  *                              Release 3.1
      7  1.14     perry  *
      8   1.2       rvb  *           Copyright (c) 1987-1998 Carnegie Mellon University
      9   1.2       rvb  *                          All Rights Reserved
     10  1.14     perry  *
     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.14     perry  *
     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.14     perry  *
     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.14     perry  *
     31  1.14     perry  * 	@(#) 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.14     perry /*
     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.11  christos #ifdef _KERNEL
     52  1.21   thorpej #include <sys/malloc.h>
     53  1.10   thorpej 
     54  1.10   thorpej MALLOC_DECLARE(M_CODA);
     55  1.11  christos #endif
     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.9     perry } while (/*CONSTCOND*/ 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.9     perry } while (/*CONSTCOND*/ 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.13  drochner     CodaFid		 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.20   hannken     kmutex_t		 c_lock;
    110   1.1       rvb };
    111   1.1       rvb #define	VTOC(vp)	((struct cnode *)(vp)->v_data)
    112   1.8     perry #define	SET_VTOC(vp)	((vp)->v_data)
    113   1.1       rvb #define	CTOV(cp)	((struct vnode *)((cp)->c_vnode))
    114   1.1       rvb 
    115   1.1       rvb /* flags */
    116   1.1       rvb #define C_VATTR		0x01	/* Validity of vattr in the cnode */
    117   1.1       rvb #define C_SYMLINK	0x02	/* Validity of symlink pointer in the Code */
    118   1.1       rvb #define C_UNMOUNTING	0X20	/* Set if unmounting */
    119   1.1       rvb #define C_PURGING	0x40	/* Set if purging a fid */
    120   1.1       rvb 
    121   1.1       rvb #define VALID_VATTR(cp)		((cp->c_flags) & C_VATTR)
    122   1.1       rvb #define VALID_SYMLINK(cp)	((cp->c_flags) & C_SYMLINK)
    123   1.1       rvb #define IS_UNMOUNTING(cp)	((cp)->c_flags & C_UNMOUNTING)
    124   1.1       rvb 
    125  1.17    plunky struct vmsg;
    126  1.17    plunky 
    127   1.1       rvb struct vcomm {
    128  1.17    plunky 	u_long			vc_seq;
    129  1.17    plunky 	int			vc_open;
    130  1.17    plunky 	struct selinfo		vc_selproc;
    131  1.17    plunky 	TAILQ_HEAD(,vmsg)	vc_requests;
    132  1.17    plunky 	TAILQ_HEAD(,vmsg)	vc_replies;
    133   1.1       rvb };
    134   1.1       rvb 
    135  1.17    plunky #define VC_OPEN(vcp)		((vcp)->vc_open == 1)
    136  1.17    plunky #define MARK_VC_CLOSED(vcp)	((vcp)->vc_open = 0)
    137  1.17    plunky #define MARK_VC_OPEN(vcp)	((vcp)->vc_open = 1)
    138   1.1       rvb 
    139   1.3       rvb struct coda_clstat {
    140   1.1       rvb 	int	ncalls;			/* client requests */
    141   1.1       rvb 	int	nbadcalls;		/* upcall failures */
    142   1.3       rvb 	int	reqs[CODA_NCALLS];	/* count of each request */
    143   1.1       rvb };
    144   1.3       rvb extern struct coda_clstat coda_clstat;
    145   1.1       rvb 
    146   1.1       rvb /*
    147   1.3       rvb  * CODA structure to hold mount/file system information
    148   1.1       rvb  */
    149   1.3       rvb struct coda_mntinfo {
    150   1.1       rvb     struct vnode	*mi_rootvp;
    151   1.1       rvb     struct mount	*mi_vfsp;
    152   1.1       rvb     struct vcomm	 mi_vcomm;
    153  1.14     perry     int			 mi_started;
    154   1.1       rvb };
    155   1.3       rvb extern struct coda_mntinfo coda_mnttbl[]; /* indexed by minor device number */
    156   1.1       rvb 
    157   1.1       rvb /*
    158   1.1       rvb  * vfs pointer to mount info
    159   1.1       rvb  */
    160   1.3       rvb #define vftomi(vfsp)    ((struct coda_mntinfo *)(vfsp->mnt_data))
    161  1.12  drochner #define	CODA_MOUNTED(vfsp)   ((vftomi(vfsp) != (struct coda_mntinfo *)0) \
    162  1.12  drochner 	&& (vftomi(vfsp)->mi_started))
    163   1.1       rvb 
    164   1.1       rvb /*
    165   1.1       rvb  * vnode pointer to mount info
    166   1.1       rvb  */
    167   1.3       rvb #define vtomi(vp)       ((struct coda_mntinfo *)(vp->v_mount->mnt_data))
    168   1.1       rvb 
    169   1.1       rvb /*
    170   1.1       rvb  * Used for identifying usage of "Control" object
    171   1.1       rvb  */
    172   1.3       rvb extern struct vnode *coda_ctlvp;
    173   1.3       rvb #define	IS_CTL_VP(vp)		((vp) == coda_ctlvp)
    174   1.3       rvb #define	IS_CTL_NAME(vp, name, l)((l == CODA_CONTROLLEN) \
    175   1.1       rvb  				 && ((vp) == vtomi((vp))->mi_rootvp)    \
    176   1.3       rvb 				 && strncmp(name, CODA_CONTROL, l) == 0)
    177   1.1       rvb 
    178  1.14     perry /*
    179   1.1       rvb  * An enum to tell us whether something that will remove a reference
    180   1.1       rvb  * to a cnode was a downcall or not
    181   1.1       rvb  */
    182   1.1       rvb enum dc_status {
    183   1.1       rvb     IS_DOWNCALL = 6,
    184   1.1       rvb     NOT_DOWNCALL = 7
    185   1.1       rvb };
    186   1.1       rvb 
    187   1.1       rvb /* cfs_psdev.h */
    188  1.18  christos extern int coda_call(struct coda_mntinfo *, int, int *, void *);
    189   1.5       rvb extern int coda_kernel_version;
    190   1.1       rvb 
    191   1.1       rvb /* cfs_subr.h */
    192  1.18  christos extern int  handleDownCall(int, union outputArgs *);
    193  1.18  christos extern void coda_unmounting(struct mount *);
    194  1.18  christos extern int  coda_vmflush(struct cnode *);
    195   1.1       rvb 
    196   1.1       rvb /* cfs_vnodeops.h */
    197  1.18  christos extern struct cnode *make_coda_node(CodaFid *, struct mount *, short);
    198   1.5       rvb extern int coda_vnodeopstats_init(void);
    199   1.1       rvb 
    200   1.3       rvb /* coda_vfsops.h */
    201  1.18  christos extern struct mount *devtomp(dev_t);
    202   1.1       rvb 
    203   1.1       rvb /* sigh */
    204   1.3       rvb #define CODA_RDWR ((u_long) 31)
    205   1.1       rvb 
    206   1.1       rvb #endif	/* _CNODE_H_ */
    207   1.1       rvb 
    208