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.4/sys/coda/coda_fbsd.c 141016 2005-01-30 01:00:13Z imp $");
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/module.h>
44 #include <sys/ucred.h>
45 #include <sys/vnode.h>
46
47 #include <vm/vm.h>
48 #include <vm/vnode_pager.h>
49
50 #include <coda/coda.h>
51 #include <coda/cnode.h>
52 #include <coda/coda_vnops.h>
53 #include <coda/coda_psdev.h>
54
55 /*
56 From: "Jordan K. Hubbard" <jkh@time.cdrom.com>
57 Subject: Re: New 3.0 SNAPshot CDROM about ready for production..
58 To: "Robert.V.Baron" <rvb@GLUCK.CODA.CS.CMU.EDU>
59 Date: Fri, 20 Feb 1998 15:57:01 -0800
60
61 > Also I need a character device major number. (and might want to reserve
62 > a block of 10 syscalls.)
63
64 Just one char device number? No block devices? Very well, cdev 93 is yours!
65 */
66
67 #define VC_DEV_NO 93
68
69 static struct cdevsw codadevsw = {
70 .d_version = D_VERSION,
71 .d_flags = D_NEEDGIANT,
72 .d_open = vc_nb_open,
73 .d_close = vc_nb_close,
74 .d_read = vc_nb_read,
75 .d_write = vc_nb_write,
76 .d_ioctl = vc_nb_ioctl,
77 .d_poll = vc_nb_poll,
78 .d_name = "Coda",
79 .d_maj = VC_DEV_NO,
80 };
81
82 int vcdebug = 1;
83 #define VCDEBUG if (vcdebug) printf
84
85 static int
86 codadev_modevent(module_t mod, int type, void *data)
87 {
88
89 switch (type) {
90 case MOD_LOAD:
91 break;
92 case MOD_UNLOAD:
93 return (EBUSY);
94 default:
95 return (EOPNOTSUPP);
96 }
97 return 0;
98 }
99 static moduledata_t codadev_mod = {
100 "codadev",
101 codadev_modevent,
102 NULL
103 };
104 DECLARE_MODULE(codadev, codadev_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE+VC_DEV_NO);
105
106 int
107 coda_fbsd_getpages(v)
108 void *v;
109 {
110 struct vop_getpages_args *ap = v;
111
112 #if 1
113 return vop_stdgetpages(ap);
114 #else
115 {
116 struct vnode *vp = ap->a_vp;
117 struct cnode *cp = VTOC(vp);
118 struct vnode *cfvp = cp->c_ovp;
119 int opened_internally = 0;
120 struct ucred *cred = (struct ucred *) 0;
121 struct proc *p = curproc;
122 int error = 0;
123
124 if (IS_CTL_VP(vp)) {
125 return(EINVAL);
126 }
127
128 /* Redirect the request to UFS. */
129
130 if (cfvp == NULL) {
131 opened_internally = 1;
132
133 error = VOP_OPEN(vp, FREAD, cred, p, -1);
134 printf("coda_getp: Internally Opening %p\n", vp);
135
136 if (error) {
137 printf("coda_getpage: VOP_OPEN on container failed %d\n", error);
138 return (error);
139 }
140 if (vp->v_type == VREG) {
141 error = vfs_object_create(vp, p, cred);
142 if (error != 0) {
143 printf("coda_getpage: vfs_object_create() returns %d\n", error);
144 vput(vp);
145 return(error);
146 }
147 }
148
149 cfvp = cp->c_ovp;
150 } else {
151 printf("coda_getp: has container %p\n", cfvp);
152 }
153
154 printf("coda_fbsd_getpages: using container ");
155 /*
156 error = vnode_pager_generic_getpages(cfvp, ap->a_m, ap->a_count,
157 ap->a_reqpage);
158 */
159 error = VOP_GETPAGES(cfvp, ap->a_m, ap->a_count,
160 ap->a_reqpage, ap->a_offset);
161 printf("error = %d\n", error);
162
163 /* Do an internal close if necessary. */
164 if (opened_internally) {
165 (void)VOP_CLOSE(vp, FREAD, cred, p);
166 }
167
168 return(error);
169 }
170 #endif
171 }
172
173
174 /* for DEVFS, using bpf & tun drivers as examples*/
175 static void coda_fbsd_drvinit(void *unused);
176 static void coda_fbsd_drvuninit(void *unused);
177 static void coda_fbsd_clone(void *arg, char *name, int namelen, struct cdev **dev);
178
179 static eventhandler_tag clonetag;
180
181 static void coda_fbsd_clone(arg, name, namelen, dev)
182 void *arg;
183 char *name;
184 int namelen;
185 struct cdev **dev;
186 {
187 int u;
188
189 if (*dev != NULL)
190 return;
191 if (dev_stdclone(name,NULL,"cfs",&u) != 1)
192 return;
193
194 *dev = make_dev(&codadevsw,unit2minor(u),UID_ROOT,GID_WHEEL,0600,"cfs%d",u);
195 coda_mnttbl[unit2minor(u)].dev = *dev;
196
197 }
198
199 static void coda_fbsd_drvinit(unused)
200 void *unused;
201 {
202 int i;
203
204 clonetag = EVENTHANDLER_REGISTER(dev_clone,coda_fbsd_clone,0,1000);
205 for(i=0;i<NVCODA;i++)
206 coda_mnttbl[i].dev = NULL;
207 }
208
209 static void coda_fbsd_drvuninit(unused)
210 void *unused;
211 {
212 int i;
213
214 EVENTHANDLER_DEREGISTER(dev_clone,clonetag);
215 for(i=0;i<NVCODA;i++)
216 if(coda_mnttbl[i].dev)
217 destroy_dev(coda_mnttbl[i].dev);
218 }
219
220 SYSINIT(coda_fbsd_dev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+VC_DEV_NO,coda_fbsd_drvinit,NULL);
221
222 SYSUNINIT(coda_fbsd_dev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+VC_DEV_NO,coda_fbsd_drvuninit,NULL);
Cache object: 5747838968bea330acbc5ebe1faaf6ca
|