FreeBSD/Linux Kernel Cross Reference
sys/coda/coda_fbsd.c
1 /*
2 * Coda: an Experimental Distributed File System
3 * Release 3.1
4 *
5 * Copyright (c) 1987-1998 Carnegie Mellon University
6 * All Rights Reserved
7 *
8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation, and
13 * that credit is given to Carnegie Mellon University in all documents
14 * and publicity pertaining to direct or indirect use of this code or its
15 * derivatives.
16 *
17 * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
18 * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
19 * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
20 * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
21 * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
22 * ANY DERIVATIVE WORK.
23 *
24 * Carnegie Mellon encourages users of this software to return any
25 * improvements or extensions that they make, and to grant Carnegie
26 * Mellon the rights to redistribute these changes without encumbrance.
27 *
28 * @(#) src/sys/coda/coda_fbsd.cr,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
29 */
30
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD: releng/5.2/sys/coda/coda_fbsd.c 118047 2003-07-26 07:32:23Z phk $");
33
34 #include "vcoda.h"
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/conf.h>
39 #include <sys/fcntl.h>
40 #include <sys/kernel.h>
41 #include <sys/lock.h>
42 #include <sys/malloc.h>
43 #include <sys/ucred.h>
44 #include <sys/vnode.h>
45
46 #include <vm/vm.h>
47 #include <vm/vnode_pager.h>
48
49 #include <coda/coda.h>
50 #include <coda/cnode.h>
51 #include <coda/coda_vnops.h>
52 #include <coda/coda_psdev.h>
53
54 /*
55 From: "Jordan K. Hubbard" <jkh@time.cdrom.com>
56 Subject: Re: New 3.0 SNAPshot CDROM about ready for production..
57 To: "Robert.V.Baron" <rvb@GLUCK.CODA.CS.CMU.EDU>
58 Date: Fri, 20 Feb 1998 15:57:01 -0800
59
60 > Also I need a character device major number. (and might want to reserve
61 > a block of 10 syscalls.)
62
63 Just one char device number? No block devices? Very well, cdev 93 is yours!
64 */
65
66 #define VC_DEV_NO 93
67
68 static struct cdevsw codadevsw = {
69 .d_open = vc_nb_open,
70 .d_close = vc_nb_close,
71 .d_read = vc_nb_read,
72 .d_write = vc_nb_write,
73 .d_ioctl = vc_nb_ioctl,
74 .d_poll = vc_nb_poll,
75 .d_name = "Coda",
76 .d_maj = VC_DEV_NO,
77 };
78
79 int vcdebug = 1;
80 #define VCDEBUG if (vcdebug) printf
81
82 static int
83 codadev_modevent(module_t mod, int type, void *data)
84 {
85
86 switch (type) {
87 case MOD_LOAD:
88 break;
89 case MOD_UNLOAD:
90 break;
91 default:
92 break;
93 }
94 return 0;
95 }
96 static moduledata_t codadev_mod = {
97 "codadev",
98 codadev_modevent,
99 NULL
100 };
101 DECLARE_MODULE(codadev, codadev_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE+VC_DEV_NO);
102
103 int
104 coda_fbsd_getpages(v)
105 void *v;
106 {
107 struct vop_getpages_args *ap = v;
108
109 #if 1
110 return vop_stdgetpages(ap);
111 #else
112 {
113 struct vnode *vp = ap->a_vp;
114 struct cnode *cp = VTOC(vp);
115 struct vnode *cfvp = cp->c_ovp;
116 int opened_internally = 0;
117 struct ucred *cred = (struct ucred *) 0;
118 struct proc *p = curproc;
119 int error = 0;
120
121 if (IS_CTL_VP(vp)) {
122 return(EINVAL);
123 }
124
125 /* Redirect the request to UFS. */
126
127 if (cfvp == NULL) {
128 opened_internally = 1;
129
130 error = VOP_OPEN(vp, FREAD, cred, p, -1);
131 printf("coda_getp: Internally Opening %p\n", vp);
132
133 if (error) {
134 printf("coda_getpage: VOP_OPEN on container failed %d\n", error);
135 return (error);
136 }
137 if (vp->v_type == VREG) {
138 error = vfs_object_create(vp, p, cred);
139 if (error != 0) {
140 printf("coda_getpage: vfs_object_create() returns %d\n", error);
141 vput(vp);
142 return(error);
143 }
144 }
145
146 cfvp = cp->c_ovp;
147 } else {
148 printf("coda_getp: has container %p\n", cfvp);
149 }
150
151 printf("coda_fbsd_getpages: using container ");
152 /*
153 error = vnode_pager_generic_getpages(cfvp, ap->a_m, ap->a_count,
154 ap->a_reqpage);
155 */
156 error = VOP_GETPAGES(cfvp, ap->a_m, ap->a_count,
157 ap->a_reqpage, ap->a_offset);
158 printf("error = %d\n", error);
159
160 /* Do an internal close if necessary. */
161 if (opened_internally) {
162 (void)VOP_CLOSE(vp, FREAD, cred, p);
163 }
164
165 return(error);
166 }
167 #endif
168 }
169
170
171 /* for DEVFS, using bpf & tun drivers as examples*/
172 static void coda_fbsd_drvinit(void *unused);
173 static void coda_fbsd_drvuninit(void *unused);
174 static void coda_fbsd_clone(void *arg, char *name, int namelen, dev_t *dev);
175
176 static eventhandler_tag clonetag;
177
178 static void coda_fbsd_clone(arg, name, namelen, dev)
179 void *arg;
180 char *name;
181 int namelen;
182 dev_t *dev;
183 {
184 int u;
185
186 if (*dev != NODEV)
187 return;
188 if (dev_stdclone(name,NULL,"cfs",&u) != 1)
189 return;
190
191 *dev = make_dev(&codadevsw,unit2minor(u),UID_ROOT,GID_WHEEL,0600,"cfs%d",u);
192 coda_mnttbl[unit2minor(u)].dev = *dev;
193
194 }
195
196 static void coda_fbsd_drvinit(unused)
197 void *unused;
198 {
199 int i;
200
201 clonetag = EVENTHANDLER_REGISTER(dev_clone,coda_fbsd_clone,0,1000);
202 for(i=0;i<NVCODA;i++)
203 coda_mnttbl[i].dev = NULL;
204 }
205
206 static void coda_fbsd_drvuninit(unused)
207 void *unused;
208 {
209 int i;
210
211 EVENTHANDLER_DEREGISTER(dev_clone,clonetag);
212 for(i=0;i<NVCODA;i++)
213 if(coda_mnttbl[i].dev)
214 destroy_dev(coda_mnttbl[i].dev);
215 }
216
217 SYSINIT(coda_fbsd_dev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+VC_DEV_NO,coda_fbsd_drvinit,NULL);
218
219 SYSUNINIT(coda_fbsd_dev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+VC_DEV_NO,coda_fbsd_drvuninit,NULL);
Cache object: c81e66089b5a13d90683ce112b61ebec
|