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