]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/coda/coda_fbsd.c
This commit was generated by cvs2svn to compensate for changes in r41220,
[FreeBSD/FreeBSD.git] / sys / coda / coda_fbsd.c
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/coda_fbsd.cr,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
30  *  $Id: coda_fbsd.c,v 1.8 1998/11/03 08:55:05 peter Exp $
31  * 
32  */
33
34 #ifdef  VFS_LKM
35 #define NVCODA 4
36 #else
37 #include "vcoda.h"
38 #include "opt_devfs.h"
39 #endif
40
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
44 #include <sys/proc.h>
45 #include <sys/malloc.h>
46 #include <sys/fcntl.h>
47 #include <sys/ucred.h>
48 #include <sys/vnode.h>
49 #include <sys/conf.h>
50
51 #include <vm/vm.h>
52 #include <vm/vnode_pager.h>
53
54 #include <coda/coda.h>
55 #include <coda/cnode.h>
56 #include <coda/coda_vnops.h>
57 #include <coda/coda_psdev.h>
58
59 #ifdef DEVFS
60 #include <sys/devfsext.h>
61
62 static  void    *cfs_devfs_token[NVCODA];
63 static  void    *coda_devfs_token[NVCODA];
64 #endif
65
66 /* 
67    From: "Jordan K. Hubbard" <jkh@time.cdrom.com>
68    Subject: Re: New 3.0 SNAPshot CDROM about ready for production.. 
69    To: "Robert.V.Baron" <rvb@GLUCK.CODA.CS.CMU.EDU>
70    Date: Fri, 20 Feb 1998 15:57:01 -0800
71
72    > Also I need a character device major number. (and might want to reserve
73    > a block of 10 syscalls.)
74
75    Just one char device number?  No block devices?  Very well, cdev 93 is yours!
76 */
77
78 #define VC_DEV_NO      93
79
80 static struct cdevsw codadevsw =
81
82   vc_nb_open,      vc_nb_close,    vc_nb_read,        vc_nb_write,      /*93*/
83   vc_nb_ioctl,     nostop,         nullreset,         nodevtotty,
84   vc_nb_poll,      nommap,         NULL,              "Coda", NULL, -1 
85 };
86
87 int     vcdebug = 1;
88 #define VCDEBUG if (vcdebug) printf
89
90 #if !defined(VFS_LKM) || defined(VFS_KLD)
91
92 static int
93 codadev_modevent(module_t mod, int type, void *data)
94 {
95         dev_t dev;
96 #ifdef DEVFS
97         int i;
98 #endif
99         static struct cdevsw *oldcdevsw;
100
101         switch (type) {
102         case MOD_LOAD:
103                 dev = makedev(VC_DEV_NO, 0);
104                 cdevsw_add(&dev,&codadevsw, &oldcdevsw);
105 #ifdef DEVFS
106                 /* tmp */
107 #undef  NVCODA
108 #define NVCODA 1
109                 for (i = 0; i < NVCODA; i++) {
110                         cfs_devfs_token[i] =
111                                 devfs_add_devswf(&codadevsw, i,
112                                         DV_CHR, UID_ROOT, GID_WHEEL, 0666,
113                                         "cfs%d", i);
114                         coda_devfs_token[i] =
115                                 devfs_add_devswf(&codadevsw, i,
116                                         DV_CHR, UID_ROOT, GID_WHEEL, 0666,
117                                         "coda%d", i);
118                 }
119 #endif
120                 break;
121         case MOD_UNLOAD:
122 #ifdef DEVFS
123                 for (i = 0; i < NVCODA; i++) {
124                         devfs_remove_dev(cfs_devfs_token[i]);
125                         devfs_remove_dev(coda_devfs_token[i]);
126                 }
127 #endif
128                 cdevsw_add(&dev, oldcdevsw, NULL);
129                 break;
130         default:
131                 break;
132         }
133         return 0;
134 }
135 static moduledata_t codadev_mod = {
136         "codadev",
137         codadev_modevent,
138         NULL
139 };
140 DECLARE_MODULE(codadev, codadev_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE+VC_DEV_NO);
141
142 #endif
143
144 int
145 coda_fbsd_getpages(v)
146         void *v;
147 {
148     struct vop_getpages_args *ap = v;
149     int ret = 0;
150
151 #if     1
152         /* ??? a_offset */
153         ret = vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
154                 ap->a_reqpage);
155         return ret;
156 #else
157   {
158     struct vnode *vp = ap->a_vp;
159     struct cnode *cp = VTOC(vp);
160     struct vnode *cfvp = cp->c_ovp;
161     int opened_internally = 0;
162     struct ucred *cred = (struct ucred *) 0;
163     struct proc *p = curproc;
164     int error = 0;
165         
166     if (IS_CTL_VP(vp)) {
167         return(EINVAL);
168     }
169
170     /* Redirect the request to UFS. */
171
172     if (cfvp == NULL) {
173         opened_internally = 1;
174
175         error = VOP_OPEN(vp, FREAD,  cred, p);
176 printf("coda_getp: Internally Opening %p\n", vp);
177
178         if (error) {
179             printf("coda_getpage: VOP_OPEN on container failed %d\n", error);
180                 return (error);
181         }
182         if (vp->v_type == VREG) {
183             error = vfs_object_create(vp, p, cred, 1);
184             if (error != 0) {
185                 printf("coda_getpage: vfs_object_create() returns %d\n", error);
186                 vput(vp);
187                 return(error);
188             }
189         }
190
191         cfvp = cp->c_ovp;
192     } else {
193 printf("coda_getp: has container %p\n", cfvp);
194     }
195
196 printf("coda_fbsd_getpages: using container ");
197 /*
198     error = vnode_pager_generic_getpages(cfvp, ap->a_m, ap->a_count,
199         ap->a_reqpage);
200 */
201     error = VOP_GETPAGES(cfvp, ap->a_m, ap->a_count,
202         ap->a_reqpage, ap->a_offset);
203 printf("error = %d\n", error);
204
205     /* Do an internal close if necessary. */
206     if (opened_internally) {
207         (void)VOP_CLOSE(vp, FREAD, cred, p);
208     }
209
210     return(error);
211   }
212 #endif
213 }
214
215 int
216 coda_fbsd_putpages(v)
217         void *v;
218 {
219         struct vop_putpages_args *ap = v;
220
221         /*??? a_offset */
222         return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
223                 ap->a_sync, ap->a_rtvals);
224 }
225
226 #if defined(VFS_LKM) && !defined(VFS_KLD)
227
228 #include <sys/mount.h>
229 #include <sys/lkm.h>
230
231 void vcattach __P((void));
232 static dev_t codadev;
233
234 void
235 vcattach(void)
236 {
237   if (0 == (codadev = makedev(VC_DEV_NO, 0)))
238     VCDEBUG("makedev returned null\n");
239   else 
240     VCDEBUG("makedev OK.\n");
241     
242   cdevsw_add(&codadev, &codadevsw, NULL);
243   VCDEBUG("coda: codadevsw entry installed at %d.\n", major(codadev));
244 }
245
246 extern struct vfsops coda_vfsops;
247
248 static struct vfsconf _fs_vfsconf = { &coda_vfsops, "coda", -1, 0, 0 };
249
250 extern struct linker_set coda_modvnops ;
251
252 static struct lkm_vfs coda_mod_vfs  = {
253         LM_VFS, LKM_VERSION, "coda", 0, &coda_modvnops, &_fs_vfsconf };
254
255 static struct lkm_dev coda_mod_dev = {
256         LM_DEV, LKM_VERSION, "codadev", VC_DEV_NO, LM_DT_CHAR, (void *) &codadevsw};
257
258 int coda_mod(struct lkm_table *, int, int);
259 int
260 coda_mod(struct lkm_table *lkmtp, int cmd, int ver)
261 {
262         int error = 0;
263
264         if (ver != LKM_VERSION)
265                 return EINVAL;
266
267         switch (cmd) {
268         case LKM_E_LOAD:
269                 lkmtp->private.lkm_any = (struct lkm_any *) &coda_mod_dev;
270                 error = lkmdispatch(lkmtp, cmd);
271                 if (error)
272                         break;
273                 lkmtp->private.lkm_any = (struct lkm_any *) &coda_mod_vfs ;
274                 error = lkmdispatch(lkmtp, cmd);
275                 break;
276         case LKM_E_UNLOAD:
277                 lkmtp->private.lkm_any = (struct lkm_any *) &coda_mod_vfs ;
278                 error = lkmdispatch(lkmtp, cmd);
279                 if (error)
280                         break;
281                 lkmtp->private.lkm_any = (struct lkm_any *) &coda_mod_dev;
282                 error = lkmdispatch(lkmtp, cmd);
283                 break;
284         case LKM_E_STAT:
285                 error = lkmdispatch(lkmtp, cmd);
286                 break;
287         }
288         return error;
289 }
290 #endif