cnode.h revision 1.15 1 1.15 christos /* $NetBSD: cnode.h,v 1.15 2005/12/11 12:19:50 christos 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.10 thorpej #include <sys/mallocvar.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 * tmp below since we need struct queue
59 1.1 rvb */
60 1.4 rvb #include <coda/coda_kernel.h>
61 1.1 rvb
62 1.1 rvb /*
63 1.1 rvb * Cnode lookup stuff.
64 1.3 rvb * NOTE: CODA_CACHESIZE must be a power of 2 for cfshash to work!
65 1.1 rvb */
66 1.3 rvb #define CODA_CACHESIZE 512
67 1.1 rvb
68 1.3 rvb #define CODA_ALLOC(ptr, cast, size) \
69 1.1 rvb do { \
70 1.3 rvb ptr = (cast)malloc((unsigned long) size, M_CODA, M_WAITOK); \
71 1.1 rvb if (ptr == 0) { \
72 1.1 rvb panic("kernel malloc returns 0 at %s:%d\n", __FILE__, __LINE__); \
73 1.1 rvb } \
74 1.9 perry } while (/*CONSTCOND*/ 0)
75 1.1 rvb
76 1.3 rvb #define CODA_FREE(ptr, size) free((ptr), M_CODA)
77 1.1 rvb
78 1.1 rvb /*
79 1.1 rvb * global cache state control
80 1.1 rvb */
81 1.3 rvb extern int coda_nc_use;
82 1.1 rvb
83 1.1 rvb /*
84 1.1 rvb * Used to select debugging statements throughout the cfs code.
85 1.1 rvb */
86 1.3 rvb extern int codadebug;
87 1.3 rvb extern int coda_nc_debug;
88 1.3 rvb extern int coda_printf_delay;
89 1.3 rvb extern int coda_vnop_print_entry;
90 1.3 rvb extern int coda_psdev_print_entry;
91 1.3 rvb extern int coda_vfsop_print_entry;
92 1.1 rvb
93 1.3 rvb #define CODADBGMSK(N) (1 << N)
94 1.3 rvb #define CODADEBUG(N, STMT) { if (codadebug & CODADBGMSK(N)) { STMT } }
95 1.1 rvb #define myprintf(args) \
96 1.1 rvb do { \
97 1.3 rvb if (coda_printf_delay) \
98 1.3 rvb DELAY(coda_printf_delay);\
99 1.1 rvb printf args ; \
100 1.9 perry } while (/*CONSTCOND*/ 0)
101 1.1 rvb
102 1.1 rvb struct cnode {
103 1.1 rvb struct vnode *c_vnode;
104 1.1 rvb u_short c_flags; /* flags (see below) */
105 1.13 drochner CodaFid c_fid; /* file handle */
106 1.1 rvb struct vnode *c_ovp; /* open vnode pointer */
107 1.1 rvb u_short c_ocount; /* count of openers */
108 1.1 rvb u_short c_owrite; /* count of open for write */
109 1.1 rvb struct vattr c_vattr; /* attributes */
110 1.1 rvb char *c_symlink; /* pointer to symbolic link */
111 1.1 rvb u_short c_symlen; /* length of symbolic link */
112 1.1 rvb dev_t c_device; /* associated vnode device */
113 1.1 rvb ino_t c_inode; /* associated vnode inode */
114 1.1 rvb struct cnode *c_next; /* links if on NetBSD machine */
115 1.1 rvb };
116 1.1 rvb #define VTOC(vp) ((struct cnode *)(vp)->v_data)
117 1.8 perry #define SET_VTOC(vp) ((vp)->v_data)
118 1.1 rvb #define CTOV(cp) ((struct vnode *)((cp)->c_vnode))
119 1.1 rvb
120 1.1 rvb /* flags */
121 1.1 rvb #define C_VATTR 0x01 /* Validity of vattr in the cnode */
122 1.1 rvb #define C_SYMLINK 0x02 /* Validity of symlink pointer in the Code */
123 1.1 rvb #define C_WANTED 0x08 /* Set if lock wanted */
124 1.1 rvb #define C_LOCKED 0x10 /* Set if lock held */
125 1.1 rvb #define C_UNMOUNTING 0X20 /* Set if unmounting */
126 1.1 rvb #define C_PURGING 0x40 /* Set if purging a fid */
127 1.1 rvb
128 1.1 rvb #define VALID_VATTR(cp) ((cp->c_flags) & C_VATTR)
129 1.1 rvb #define VALID_SYMLINK(cp) ((cp->c_flags) & C_SYMLINK)
130 1.1 rvb #define IS_UNMOUNTING(cp) ((cp)->c_flags & C_UNMOUNTING)
131 1.1 rvb
132 1.1 rvb struct vcomm {
133 1.1 rvb u_long vc_seq;
134 1.1 rvb struct selinfo vc_selproc;
135 1.1 rvb struct queue vc_requests;
136 1.1 rvb struct queue vc_replys;
137 1.1 rvb };
138 1.1 rvb
139 1.1 rvb #define VC_OPEN(vcp) ((vcp)->vc_requests.forw != NULL)
140 1.1 rvb #define MARK_VC_CLOSED(vcp) (vcp)->vc_requests.forw = NULL;
141 1.1 rvb #define MARK_VC_OPEN(vcp) /* MT */
142 1.1 rvb
143 1.3 rvb struct coda_clstat {
144 1.1 rvb int ncalls; /* client requests */
145 1.1 rvb int nbadcalls; /* upcall failures */
146 1.3 rvb int reqs[CODA_NCALLS]; /* count of each request */
147 1.1 rvb };
148 1.3 rvb extern struct coda_clstat coda_clstat;
149 1.1 rvb
150 1.1 rvb /*
151 1.3 rvb * CODA structure to hold mount/file system information
152 1.1 rvb */
153 1.3 rvb struct coda_mntinfo {
154 1.1 rvb struct vnode *mi_rootvp;
155 1.1 rvb struct mount *mi_vfsp;
156 1.1 rvb struct vcomm mi_vcomm;
157 1.14 perry int mi_started;
158 1.1 rvb };
159 1.3 rvb extern struct coda_mntinfo coda_mnttbl[]; /* indexed by minor device number */
160 1.1 rvb
161 1.1 rvb /*
162 1.1 rvb * vfs pointer to mount info
163 1.1 rvb */
164 1.3 rvb #define vftomi(vfsp) ((struct coda_mntinfo *)(vfsp->mnt_data))
165 1.12 drochner #define CODA_MOUNTED(vfsp) ((vftomi(vfsp) != (struct coda_mntinfo *)0) \
166 1.12 drochner && (vftomi(vfsp)->mi_started))
167 1.1 rvb
168 1.1 rvb /*
169 1.1 rvb * vnode pointer to mount info
170 1.1 rvb */
171 1.3 rvb #define vtomi(vp) ((struct coda_mntinfo *)(vp->v_mount->mnt_data))
172 1.1 rvb
173 1.1 rvb /*
174 1.1 rvb * Used for identifying usage of "Control" object
175 1.1 rvb */
176 1.3 rvb extern struct vnode *coda_ctlvp;
177 1.3 rvb #define IS_CTL_VP(vp) ((vp) == coda_ctlvp)
178 1.3 rvb #define IS_CTL_NAME(vp, name, l)((l == CODA_CONTROLLEN) \
179 1.1 rvb && ((vp) == vtomi((vp))->mi_rootvp) \
180 1.3 rvb && strncmp(name, CODA_CONTROL, l) == 0)
181 1.1 rvb
182 1.14 perry /*
183 1.1 rvb * An enum to tell us whether something that will remove a reference
184 1.1 rvb * to a cnode was a downcall or not
185 1.1 rvb */
186 1.1 rvb enum dc_status {
187 1.1 rvb IS_DOWNCALL = 6,
188 1.1 rvb NOT_DOWNCALL = 7
189 1.1 rvb };
190 1.1 rvb
191 1.1 rvb /* cfs_psdev.h */
192 1.5 rvb extern int coda_call(struct coda_mntinfo *mntinfo, int inSize, int *outSize, caddr_t buffer);
193 1.5 rvb extern int coda_kernel_version;
194 1.1 rvb
195 1.1 rvb /* cfs_subr.h */
196 1.5 rvb extern int handleDownCall(int opcode, union outputArgs *out);
197 1.5 rvb extern void coda_unmounting(struct mount *whoIam);
198 1.5 rvb extern int coda_vmflush(struct cnode *cp);
199 1.1 rvb
200 1.1 rvb /* cfs_vnodeops.h */
201 1.13 drochner extern struct cnode *make_coda_node(CodaFid *fid, struct mount *vfsp, short type);
202 1.5 rvb extern int coda_vnodeopstats_init(void);
203 1.1 rvb
204 1.3 rvb /* coda_vfsops.h */
205 1.5 rvb extern struct mount *devtomp(dev_t dev);
206 1.1 rvb
207 1.1 rvb /* sigh */
208 1.3 rvb #define CODA_RDWR ((u_long) 31)
209 1.1 rvb
210 1.1 rvb #endif /* _CNODE_H_ */
211 1.1 rvb
212