]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/coda/coda_fbsd.c
Put "stray" printouts under DIAGNOSTIC. Make everything build
[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.4 1998/09/13 13:57:59 rvb Exp $
31  * 
32  */
33
34 #ifdef  ACTUALLY_LKM_NOT_KERNEL
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    *devfs_token[NVCODA];
63 #endif
64
65 /* 
66    From: "Jordan K. Hubbard" <jkh@time.cdrom.com>
67    Subject: Re: New 3.0 SNAPshot CDROM about ready for production.. 
68    To: "Robert.V.Baron" <rvb@GLUCK.CODA.CS.CMU.EDU>
69    Date: Fri, 20 Feb 1998 15:57:01 -0800
70
71    > Also I need a character device major number. (and might want to reserve
72    > a block of 10 syscalls.)
73
74    Just one char device number?  No block devices?  Very well, cdev 93 is yours!
75 */
76
77 #define VC_DEV_NO      93
78
79 static struct cdevsw codadevsw =
80
81   vc_nb_open,      vc_nb_close,    vc_nb_read,        vc_nb_write,      /*93*/
82   vc_nb_ioctl,     nostop,         nullreset,         nodevtotty,
83   vc_nb_poll,      nommap,         NULL,              "Coda", NULL, -1 
84 };
85
86 void vcattach __P((void));
87 static dev_t codadev;
88
89 int     vcdebug = 1;
90 #define VCDEBUG if (vcdebug) printf
91
92 void
93 vcattach(void)
94 {
95   /*
96    * In case we are an LKM, set up device switch.
97    */
98   if (0 == (codadev = makedev(VC_DEV_NO, 0)))
99     VCDEBUG("makedev returned null\n");
100   else 
101     VCDEBUG("makedev OK.\n");
102     
103   cdevsw_add(&codadev, &codadevsw, NULL);
104   VCDEBUG("coda: codadevsw entry installed at %d.\n", major(codadev));
105 }
106
107 static vc_devsw_installed = 0;
108 static void     vc_drvinit __P((void *unused));
109
110 static void
111 vc_drvinit(void *unused)
112 {
113         dev_t dev;
114 #ifdef DEVFS
115         int i;
116 #endif
117
118         if( ! vc_devsw_installed ) {
119                 dev = makedev(VC_DEV_NO, 0);
120                 cdevsw_add(&dev,&codadevsw, NULL);
121                 vc_devsw_installed = 1;
122         }
123 #ifdef DEVFS
124         for (i = 0; i < NVCODA; i++) {
125                 devfs_token[i] =
126                         devfs_add_devswf(&codadevsw, i
127                                 DV_CHR, 0, 0, 0666,
128                                 "cfs%d", i);
129                 devfs_token[i] =
130                         devfs_add_devswf(&codadevsw, i
131                                 DV_CHR, 0, 0, 0666,
132                                 "coda%d", i);
133         }
134 #endif
135
136 }
137
138 int
139 coda_fbsd_getpages(v)
140         void *v;
141 {
142     struct vop_getpages_args *ap = v;
143     struct vnode *vp = ap->a_vp;
144     struct cnode *cp = VTOC(vp);
145     int ret = 0;
146
147 #if     1
148         /*??? a_offset */
149         ret = vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
150                 ap->a_reqpage);
151         return ret;
152 #else
153   {
154     struct vnode *vp = ap->a_vp;
155     struct cnode *cp = VTOC(vp);
156     struct vnode *cfvp = cp->c_ovp;
157     int opened_internally = 0;
158     struct ucred *cred = (struct ucred *) 0;
159     struct proc *p = curproc;
160     int error = 0;
161         
162     if (IS_CTL_VP(vp)) {
163         return(EINVAL);
164     }
165
166     /* Redirect the request to UFS. */
167
168     if (cfvp == NULL) {
169         opened_internally = 1;
170
171         error = VOP_OPEN(vp, FREAD,  cred, p);
172 printf("coda_getp: Internally Opening %p\n", vp);
173
174         if (error) {
175             printf("coda_getpage: VOP_OPEN on container failed %d\n", error);
176                 return (error);
177         }
178         if (vp->v_type == VREG) {
179             error = vfs_object_create(vp, p, cred, 1);
180             if (error != 0) {
181                 printf("coda_getpage: vfs_object_create() returns %d\n", error);
182                 vput(vp);
183                 return(error);
184             }
185         }
186
187         cfvp = cp->c_ovp;
188     } else {
189 printf("coda_getp: has container %p\n", cfvp);
190     }
191
192 printf("coda_fbsd_getpages: using container ");
193 /*
194     error = vnode_pager_generic_getpages(cfvp, ap->a_m, ap->a_count,
195         ap->a_reqpage);
196 */
197     error = VOP_GETPAGES(cfvp, ap->a_m, ap->a_count,
198         ap->a_reqpage, ap->a_offset);
199 printf("error = %d\n", error);
200
201     /* Do an internal close if necessary. */
202     if (opened_internally) {
203         (void)VOP_CLOSE(vp, FREAD, cred, p);
204     }
205
206     return(error);
207   }
208 #endif
209 }
210
211 int
212 coda_fbsd_putpages(v)
213         void *v;
214 {
215         struct vop_putpages_args *ap = v;
216
217         /*??? a_offset */
218         return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
219                 ap->a_sync, ap->a_rtvals);
220 }
221
222
223 SYSINIT(codadev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+VC_DEV_NO,vc_drvinit,NULL)
224
225 #ifdef  ACTUALLY_LKM_NOT_KERNEL
226
227 #include <sys/mount.h>
228 #include <sys/lkm.h>
229
230 extern struct vfsops coda_vfsops;
231
232 static struct vfsconf _fs_vfsconf = { &coda_vfsops, "coda", -1, 0, 0 };
233
234 extern struct linker_set coda_modvnops ;
235
236 static struct lkm_vfs coda_mod_vfs  = {
237         LM_VFS, LKM_VERSION, "coda", 0, &coda_modvnops, &_fs_vfsconf };
238
239 static struct lkm_dev coda_mod_dev = {
240         LM_DEV, LKM_VERSION, "codadev", VC_DEV_NO, LM_DT_CHAR, (void *) &codadevsw};
241
242 int coda_mod(struct lkm_table *, int, int);
243 int
244 coda_mod(struct lkm_table *lkmtp, int cmd, int ver)
245 {
246         int error = 0;
247
248         if (ver != LKM_VERSION)
249                 return EINVAL;
250
251         switch (cmd) {
252         case LKM_E_LOAD:
253                 lkmtp->private.lkm_any = (struct lkm_any *) &coda_mod_dev;
254                 error = lkmdispatch(lkmtp, cmd);
255                 if (error)
256                         break;
257                 lkmtp->private.lkm_any = (struct lkm_any *) &coda_mod_vfs ;
258                 error = lkmdispatch(lkmtp, cmd);
259                 break;
260         case LKM_E_UNLOAD:
261                 lkmtp->private.lkm_any = (struct lkm_any *) &coda_mod_vfs ;
262                 error = lkmdispatch(lkmtp, cmd);
263                 if (error)
264                         break;
265                 lkmtp->private.lkm_any = (struct lkm_any *) &coda_mod_dev;
266                 error = lkmdispatch(lkmtp, cmd);
267                 break;
268         case LKM_E_STAT:
269                 error = lkmdispatch(lkmtp, cmd);
270                 break;
271         }
272         return error;
273 }
274 #endif