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