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