Deleted Added
full compact
coda_fbsd.c (43311) coda_fbsd.c (47625)
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 $
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.12 1999/01/27 20:09:17 dillon Exp $
30 * $Id: coda_fbsd.c,v 1.13 1999/01/28 00:57:46 dillon Exp $
31 *
32 */
33
34#include "vcoda.h"
35#include "opt_devfs.h"
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/kernel.h>
40#include <sys/proc.h>
41#include <sys/malloc.h>
42#include <sys/fcntl.h>
43#include <sys/ucred.h>
44#include <sys/vnode.h>
45#include <sys/conf.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#ifdef DEVFS
56#include <sys/devfsext.h>
57
58static void *cfs_devfs_token[NVCODA];
59static void *coda_devfs_token[NVCODA];
60#endif
61
62/*
63 From: "Jordan K. Hubbard" <jkh@time.cdrom.com>
64 Subject: Re: New 3.0 SNAPshot CDROM about ready for production..
65 To: "Robert.V.Baron" <rvb@GLUCK.CODA.CS.CMU.EDU>
66 Date: Fri, 20 Feb 1998 15:57:01 -0800
67
68 > Also I need a character device major number. (and might want to reserve
69 > a block of 10 syscalls.)
70
71 Just one char device number? No block devices? Very well, cdev 93 is yours!
72*/
73
74#define VC_DEV_NO 93
75
31 *
32 */
33
34#include "vcoda.h"
35#include "opt_devfs.h"
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/kernel.h>
40#include <sys/proc.h>
41#include <sys/malloc.h>
42#include <sys/fcntl.h>
43#include <sys/ucred.h>
44#include <sys/vnode.h>
45#include <sys/conf.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#ifdef DEVFS
56#include <sys/devfsext.h>
57
58static void *cfs_devfs_token[NVCODA];
59static void *coda_devfs_token[NVCODA];
60#endif
61
62/*
63 From: "Jordan K. Hubbard" <jkh@time.cdrom.com>
64 Subject: Re: New 3.0 SNAPshot CDROM about ready for production..
65 To: "Robert.V.Baron" <rvb@GLUCK.CODA.CS.CMU.EDU>
66 Date: Fri, 20 Feb 1998 15:57:01 -0800
67
68 > Also I need a character device major number. (and might want to reserve
69 > a block of 10 syscalls.)
70
71 Just one char device number? No block devices? Very well, cdev 93 is yours!
72*/
73
74#define VC_DEV_NO 93
75
76static struct cdevsw codadevsw =
77{
78 vc_nb_open, vc_nb_close, vc_nb_read, vc_nb_write, /*93*/
79 vc_nb_ioctl, nostop, nullreset, nodevtotty,
80 vc_nb_poll, nommap, NULL, "Coda", NULL, -1
76static struct cdevsw codadevsw = {
77 /* open */ vc_nb_open,
78 /* close */ vc_nb_close,
79 /* read */ vc_nb_read,
80 /* write */ vc_nb_write,
81 /* ioctl */ vc_nb_ioctl,
82 /* stop */ nostop,
83 /* reset */ noreset,
84 /* devtotty */ nodevtotty,
85 /* poll */ vc_nb_poll,
86 /* mmap */ nommap,
87 /* strategy */ nostrategy,
88 /* name */ "Coda",
89 /* parms */ noparms,
90 /* maj */ VC_DEV_NO,
91 /* dump */ nodump,
92 /* psize */ nopsize,
93 /* flags */ 0,
94 /* maxio */ 0,
95 /* bmaj */ -1
81};
82
83int vcdebug = 1;
84#define VCDEBUG if (vcdebug) printf
85
86static int
87codadev_modevent(module_t mod, int type, void *data)
88{
89 dev_t dev;
90#ifdef DEVFS
91 int i;
92#endif
93 static struct cdevsw *oldcdevsw;
94
95 switch (type) {
96 case MOD_LOAD:
97 dev = makedev(VC_DEV_NO, 0);
98 cdevsw_add(&dev,&codadevsw, &oldcdevsw);
99#ifdef DEVFS
100 /* tmp */
101#undef NVCODA
102#define NVCODA 1
103 for (i = 0; i < NVCODA; i++) {
104 cfs_devfs_token[i] =
105 devfs_add_devswf(&codadevsw, i,
106 DV_CHR, UID_ROOT, GID_WHEEL, 0666,
107 "cfs%d", i);
108 coda_devfs_token[i] =
109 devfs_add_devswf(&codadevsw, i,
110 DV_CHR, UID_ROOT, GID_WHEEL, 0666,
111 "coda%d", i);
112 }
113#endif
114 break;
115 case MOD_UNLOAD:
116#ifdef DEVFS
117 for (i = 0; i < NVCODA; i++) {
118 devfs_remove_dev(cfs_devfs_token[i]);
119 devfs_remove_dev(coda_devfs_token[i]);
120 }
121#endif
122 cdevsw_add(&dev, oldcdevsw, NULL);
123 break;
124 default:
125 break;
126 }
127 return 0;
128}
129static moduledata_t codadev_mod = {
130 "codadev",
131 codadev_modevent,
132 NULL
133};
134DECLARE_MODULE(codadev, codadev_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE+VC_DEV_NO);
135
136int
137coda_fbsd_getpages(v)
138 void *v;
139{
140 struct vop_getpages_args *ap = v;
141 int ret = 0;
142
143#if 1
144 /* ??? a_offset */
145 ret = vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
146 ap->a_reqpage);
147 return ret;
148#else
149 {
150 struct vnode *vp = ap->a_vp;
151 struct cnode *cp = VTOC(vp);
152 struct vnode *cfvp = cp->c_ovp;
153 int opened_internally = 0;
154 struct ucred *cred = (struct ucred *) 0;
155 struct proc *p = curproc;
156 int error = 0;
157
158 if (IS_CTL_VP(vp)) {
159 return(EINVAL);
160 }
161
162 /* Redirect the request to UFS. */
163
164 if (cfvp == NULL) {
165 opened_internally = 1;
166
167 error = VOP_OPEN(vp, FREAD, cred, p);
168printf("coda_getp: Internally Opening %p\n", vp);
169
170 if (error) {
171 printf("coda_getpage: VOP_OPEN on container failed %d\n", error);
172 return (error);
173 }
174 if (vp->v_type == VREG) {
175 error = vfs_object_create(vp, p, cred);
176 if (error != 0) {
177 printf("coda_getpage: vfs_object_create() returns %d\n", error);
178 vput(vp);
179 return(error);
180 }
181 }
182
183 cfvp = cp->c_ovp;
184 } else {
185printf("coda_getp: has container %p\n", cfvp);
186 }
187
188printf("coda_fbsd_getpages: using container ");
189/*
190 error = vnode_pager_generic_getpages(cfvp, ap->a_m, ap->a_count,
191 ap->a_reqpage);
192*/
193 error = VOP_GETPAGES(cfvp, ap->a_m, ap->a_count,
194 ap->a_reqpage, ap->a_offset);
195printf("error = %d\n", error);
196
197 /* Do an internal close if necessary. */
198 if (opened_internally) {
199 (void)VOP_CLOSE(vp, FREAD, cred, p);
200 }
201
202 return(error);
203 }
204#endif
205}
206
207int
208coda_fbsd_putpages(v)
209 void *v;
210{
211 struct vop_putpages_args *ap = v;
212
213 /*??? a_offset */
214 return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
215 ap->a_sync, ap->a_rtvals);
216}
96};
97
98int vcdebug = 1;
99#define VCDEBUG if (vcdebug) printf
100
101static int
102codadev_modevent(module_t mod, int type, void *data)
103{
104 dev_t dev;
105#ifdef DEVFS
106 int i;
107#endif
108 static struct cdevsw *oldcdevsw;
109
110 switch (type) {
111 case MOD_LOAD:
112 dev = makedev(VC_DEV_NO, 0);
113 cdevsw_add(&dev,&codadevsw, &oldcdevsw);
114#ifdef DEVFS
115 /* tmp */
116#undef NVCODA
117#define NVCODA 1
118 for (i = 0; i < NVCODA; i++) {
119 cfs_devfs_token[i] =
120 devfs_add_devswf(&codadevsw, i,
121 DV_CHR, UID_ROOT, GID_WHEEL, 0666,
122 "cfs%d", i);
123 coda_devfs_token[i] =
124 devfs_add_devswf(&codadevsw, i,
125 DV_CHR, UID_ROOT, GID_WHEEL, 0666,
126 "coda%d", i);
127 }
128#endif
129 break;
130 case MOD_UNLOAD:
131#ifdef DEVFS
132 for (i = 0; i < NVCODA; i++) {
133 devfs_remove_dev(cfs_devfs_token[i]);
134 devfs_remove_dev(coda_devfs_token[i]);
135 }
136#endif
137 cdevsw_add(&dev, oldcdevsw, NULL);
138 break;
139 default:
140 break;
141 }
142 return 0;
143}
144static moduledata_t codadev_mod = {
145 "codadev",
146 codadev_modevent,
147 NULL
148};
149DECLARE_MODULE(codadev, codadev_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE+VC_DEV_NO);
150
151int
152coda_fbsd_getpages(v)
153 void *v;
154{
155 struct vop_getpages_args *ap = v;
156 int ret = 0;
157
158#if 1
159 /* ??? a_offset */
160 ret = vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
161 ap->a_reqpage);
162 return ret;
163#else
164 {
165 struct vnode *vp = ap->a_vp;
166 struct cnode *cp = VTOC(vp);
167 struct vnode *cfvp = cp->c_ovp;
168 int opened_internally = 0;
169 struct ucred *cred = (struct ucred *) 0;
170 struct proc *p = curproc;
171 int error = 0;
172
173 if (IS_CTL_VP(vp)) {
174 return(EINVAL);
175 }
176
177 /* Redirect the request to UFS. */
178
179 if (cfvp == NULL) {
180 opened_internally = 1;
181
182 error = VOP_OPEN(vp, FREAD, cred, p);
183printf("coda_getp: Internally Opening %p\n", vp);
184
185 if (error) {
186 printf("coda_getpage: VOP_OPEN on container failed %d\n", error);
187 return (error);
188 }
189 if (vp->v_type == VREG) {
190 error = vfs_object_create(vp, p, cred);
191 if (error != 0) {
192 printf("coda_getpage: vfs_object_create() returns %d\n", error);
193 vput(vp);
194 return(error);
195 }
196 }
197
198 cfvp = cp->c_ovp;
199 } else {
200printf("coda_getp: has container %p\n", cfvp);
201 }
202
203printf("coda_fbsd_getpages: using container ");
204/*
205 error = vnode_pager_generic_getpages(cfvp, ap->a_m, ap->a_count,
206 ap->a_reqpage);
207*/
208 error = VOP_GETPAGES(cfvp, ap->a_m, ap->a_count,
209 ap->a_reqpage, ap->a_offset);
210printf("error = %d\n", error);
211
212 /* Do an internal close if necessary. */
213 if (opened_internally) {
214 (void)VOP_CLOSE(vp, FREAD, cred, p);
215 }
216
217 return(error);
218 }
219#endif
220}
221
222int
223coda_fbsd_putpages(v)
224 void *v;
225{
226 struct vop_putpages_args *ap = v;
227
228 /*??? a_offset */
229 return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
230 ap->a_sync, ap->a_rtvals);
231}