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$");
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/conf.h>
37 #include <sys/fcntl.h>
38 #include <sys/kernel.h>
39 #include <sys/lock.h>
40 #include <sys/malloc.h>
41 #include <sys/module.h>
42 #include <sys/ucred.h>
43 #include <sys/vnode.h>
44
45 #include <vm/vm.h>
46 #include <vm/vnode_pager.h>
47
48 #include <fs/coda/coda.h>
49 #include <fs/coda/cnode.h>
50 #include <fs/coda/coda_vnops.h>
51 #include <fs/coda/coda_psdev.h>
52
53 static struct cdevsw codadevsw = {
54 .d_version = D_VERSION,
55 .d_flags = D_NEEDGIANT,
56 .d_open = vc_open,
57 .d_close = vc_close,
58 .d_read = vc_read,
59 .d_write = vc_write,
60 .d_ioctl = vc_ioctl,
61 .d_poll = vc_poll,
62 .d_name = "coda",
63 };
64
65 static eventhandler_tag clonetag;
66
67 static LIST_HEAD(, coda_mntinfo) coda_mnttbl;
68
69 /*
70 * For DEVFS, using bpf & tun drivers as examples.
71 *
72 * XXX: Why use a cloned interface, aren't we really just interested in
73 * having a single /dev/cfs0? It's not clear the coda module knows what to
74 * do with more than one.
75 */
76 static void coda_fbsd_clone(void *arg, struct ucred *cred, char *name,
77 int namelen, struct cdev **dev);
78
79 static int
80 codadev_modevent(module_t mod, int type, void *data)
81 {
82 struct coda_mntinfo *mnt;
83
84 switch (type) {
85 case MOD_LOAD:
86 LIST_INIT(&coda_mnttbl);
87 clonetag = EVENTHANDLER_REGISTER(dev_clone, coda_fbsd_clone,
88 0, 1000);
89 break;
90
91 case MOD_UNLOAD:
92 /*
93 * XXXRW: At the very least, a busy check should occur here
94 * to prevent untimely unload. Much more serious collection
95 * of allocated memory needs to take place; right now we leak
96 * like a sieve.
97 */
98 EVENTHANDLER_DEREGISTER(dev_clone, clonetag);
99 while ((mnt = LIST_FIRST(&coda_mnttbl)) != NULL) {
100 LIST_REMOVE(mnt, mi_list);
101 destroy_dev(mnt->dev);
102 free(mnt, M_CODA);
103 }
104 break;
105
106 default:
107 return (EOPNOTSUPP);
108 }
109 return (0);
110 }
111
112 static moduledata_t codadev_mod = {
113 "codadev",
114 codadev_modevent,
115 NULL
116 };
117 DECLARE_MODULE(codadev, codadev_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
118
119 static void
120 coda_fbsd_clone(void *arg, struct ucred *cred, char *name, int namelen,
121 struct cdev **dev)
122 {
123 struct coda_mntinfo *mnt;
124 int u;
125
126 if (*dev != NULL)
127 return;
128 if (dev_stdclone(name, NULL, "cfs", &u) != 1)
129 return;
130 *dev = make_dev(&codadevsw, unit2minor(u), UID_ROOT, GID_WHEEL, 0600,
131 "cfs%d", u);
132 dev_ref(*dev);
133 mnt = malloc(sizeof(struct coda_mntinfo), M_CODA, M_WAITOK|M_ZERO);
134 LIST_INSERT_HEAD(&coda_mnttbl, mnt, mi_list);
135 mnt->dev = *dev;
136 }
137
138 struct coda_mntinfo *
139 dev2coda_mntinfo(struct cdev *dev)
140 {
141 struct coda_mntinfo *mnt;
142
143 LIST_FOREACH(mnt, &coda_mnttbl, mi_list) {
144 if (mnt->dev == dev)
145 return (mnt);
146 }
147 return (NULL);
148 }
Cache object: cad3dce298e67697953aaeb6da86fd0c
|