cnode.h revision 1.17 1 1.17 plunky /* $NetBSD: cnode.h,v 1.17 2008/03/21 17:59:57 plunky 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 * 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.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.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_WANTED 0x08 /* Set if lock wanted */
119 1.1 rvb #define C_LOCKED 0x10 /* Set if lock held */
120 1.1 rvb #define C_UNMOUNTING 0X20 /* Set if unmounting */
121 1.1 rvb #define C_PURGING 0x40 /* Set if purging a fid */
122 1.1 rvb
123 1.1 rvb #define VALID_VATTR(cp) ((cp->c_flags) & C_VATTR)
124 1.1 rvb #define VALID_SYMLINK(cp) ((cp->c_flags) & C_SYMLINK)
125 1.1 rvb #define IS_UNMOUNTING(cp) ((cp)->c_flags & C_UNMOUNTING)
126 1.1 rvb
127 1.17 plunky struct vmsg;
128 1.17 plunky
129 1.1 rvb struct vcomm {
130 1.17 plunky u_long vc_seq;
131 1.17 plunky int vc_open;
132 1.17 plunky struct selinfo vc_selproc;
133 1.17 plunky TAILQ_HEAD(,vmsg) vc_requests;
134 1.17 plunky TAILQ_HEAD(,vmsg) vc_replies;
135 1.1 rvb };
136 1.1 rvb
137 1.17 plunky #define VC_OPEN(vcp) ((vcp)->vc_open == 1)
138 1.17 plunky #define MARK_VC_CLOSED(vcp) ((vcp)->vc_open = 0)
139 1.17 plunky #define MARK_VC_OPEN(vcp) ((vcp)->vc_open = 1)
140 1.1 rvb
141 1.3 rvb struct coda_clstat {
142 1.1 rvb int ncalls; /* client requests */
143 1.1 rvb int nbadcalls; /* upcall failures */
144 1.3 rvb int reqs[CODA_NCALLS]; /* count of each request */
145 1.1 rvb };
146 1.3 rvb extern struct coda_clstat coda_clstat;
147 1.1 rvb
148 1.1 rvb /*
149 1.3 rvb * CODA structure to hold mount/file system information
150 1.1 rvb */
151 1.3 rvb struct coda_mntinfo {
152 1.1 rvb struct vnode *mi_rootvp;
153 1.1 rvb struct mount *mi_vfsp;
154 1.1 rvb struct vcomm mi_vcomm;
155 1.14 perry int mi_started;
156 1.1 rvb };
157 1.3 rvb extern struct coda_mntinfo coda_mnttbl[]; /* indexed by minor device number */
158 1.1 rvb
159 1.1 rvb /*
160 1.1 rvb * vfs pointer to mount info
161 1.1 rvb */
162 1.3 rvb #define vftomi(vfsp) ((struct coda_mntinfo *)(vfsp->mnt_data))
163 1.12 drochner #define CODA_MOUNTED(vfsp) ((vftomi(vfsp) != (struct coda_mntinfo *)0) \
164 1.12 drochner && (vftomi(vfsp)->mi_started))
165 1.1 rvb
166 1.1 rvb /*
167 1.1 rvb * vnode pointer to mount info
168 1.1 rvb */
169 1.3 rvb #define vtomi(vp) ((struct coda_mntinfo *)(vp->v_mount->mnt_data))
170 1.1 rvb
171 1.1 rvb /*
172 1.1 rvb * Used for identifying usage of "Control" object
173 1.1 rvb */
174 1.3 rvb extern struct vnode *coda_ctlvp;
175 1.3 rvb #define IS_CTL_VP(vp) ((vp) == coda_ctlvp)
176 1.3 rvb #define IS_CTL_NAME(vp, name, l)((l == CODA_CONTROLLEN) \
177 1.1 rvb && ((vp) == vtomi((vp))->mi_rootvp) \
178 1.3 rvb && strncmp(name, CODA_CONTROL, l) == 0)
179 1.1 rvb
180 1.14 perry /*
181 1.1 rvb * An enum to tell us whether something that will remove a reference
182 1.1 rvb * to a cnode was a downcall or not
183 1.1 rvb */
184 1.1 rvb enum dc_status {
185 1.1 rvb IS_DOWNCALL = 6,
186 1.1 rvb NOT_DOWNCALL = 7
187 1.1 rvb };
188 1.1 rvb
189 1.1 rvb /* cfs_psdev.h */
190 1.16 christos extern int coda_call(struct coda_mntinfo *mntinfo, int inSize, int *outSize, void *buffer);
191 1.5 rvb extern int coda_kernel_version;
192 1.1 rvb
193 1.1 rvb /* cfs_subr.h */
194 1.5 rvb extern int handleDownCall(int opcode, union outputArgs *out);
195 1.5 rvb extern void coda_unmounting(struct mount *whoIam);
196 1.5 rvb extern int coda_vmflush(struct cnode *cp);
197 1.1 rvb
198 1.1 rvb /* cfs_vnodeops.h */
199 1.13 drochner extern struct cnode *make_coda_node(CodaFid *fid, struct mount *vfsp, short type);
200 1.5 rvb extern int coda_vnodeopstats_init(void);
201 1.1 rvb
202 1.3 rvb /* coda_vfsops.h */
203 1.5 rvb extern struct mount *devtomp(dev_t dev);
204 1.1 rvb
205 1.1 rvb /* sigh */
206 1.3 rvb #define CODA_RDWR ((u_long) 31)
207 1.1 rvb
208 1.1 rvb #endif /* _CNODE_H_ */
209 1.1 rvb
210