1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * linux/fs/ext2_obd/ext2_obd.c
6 * Copyright (C) 2001 Cluster File Systems, Inc.
8 * This code is issued under the GNU General Public License.
9 * See the file COPYING in this distribution
11 * by Peter Braam <braam@clusterfs.com>
14 static char rcsid[] __attribute ((unused)) = "$Id: echo.c,v 1.26 2002/08/22 13:34:20 eeb Exp $";
15 #define OBDECHO_VERSION "$Revision: 1.26 $"
19 #include <linux/version.h>
20 #include <linux/module.h>
22 #include <linux/stat.h>
23 #include <linux/locks.h>
24 #include <linux/ext2_fs.h>
25 #include <linux/quotaops.h>
26 #include <linux/proc_fs.h>
27 #include <linux/init.h>
28 #include <asm/unistd.h>
30 #define DEBUG_SUBSYSTEM S_ECHO
32 #include <linux/obd_support.h>
33 #include <linux/obd_class.h>
34 #include <linux/obd_echo.h>
35 #include <linux/lustre_debug.h>
36 #include <linux/lustre_dlm.h>
38 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
39 static struct obdo OA;
41 static long echo_pages = 0;
43 static atomic_t echo_page_rws;
44 static atomic_t echo_getattrs;
46 #define ECHO_PROC_STAT "sys/obdecho"
49 echo_proc_read (char *page, char **start, off_t off, int count, int *eof, void *data)
52 int attrs = atomic_read (&echo_getattrs);
53 int pages = atomic_read (&echo_page_rws);
59 len = sprintf (page, "%d %d\n", pages, attrs);
66 echo_proc_write (struct file *file, const char *ubuffer, unsigned long count, void *data)
68 /* Ignore what we've been asked to write, and just zero the stats counters */
69 atomic_set (&echo_page_rws, 0);
70 atomic_set (&echo_getattrs, 0);
78 struct proc_dir_entry *entry;
80 entry = create_proc_entry(ECHO_PROC_STAT, S_IFREG|S_IRUGO|S_IWUSR,NULL);
83 CERROR("couldn't create proc entry %s\n", ECHO_PROC_STAT);
88 entry->read_proc = echo_proc_read;
89 entry->write_proc = echo_proc_write;
92 void echo_proc_fini(void)
94 remove_proc_entry(ECHO_PROC_STAT, 0);
97 static int echo_connect(struct lustre_handle *conn, struct obd_device *obd,
103 rc = class_connect(conn, obd, NULL);
111 static int echo_disconnect(struct lustre_handle *conn)
115 rc = class_disconnect(conn);
122 static int echo_getattr(struct lustre_handle *conn, struct obdo *oa,
123 struct lov_stripe_md *md)
125 memcpy(oa, &OA, sizeof(*oa));
128 atomic_inc (&echo_getattrs);
133 #define DESC_PRIV 0x10293847
135 int echo_preprw(int cmd, struct lustre_handle *conn, int objcount,
136 struct obd_ioobj *obj, int niocount, struct niobuf_remote *nb,
137 struct niobuf_local *res, void **desc_private)
139 struct niobuf_local *r = res;
145 memset(res, 0, sizeof(*res) * niocount);
147 CDEBUG(D_PAGE, "%s %d obdos with %d IOs\n",
148 cmd == OBD_BRW_READ ? "reading" : "writing", objcount, niocount);
150 *desc_private = (void *)DESC_PRIV;
152 for (i = 0; i < objcount; i++, obj++) {
153 int highmem = (obj->ioo_id & 1) != 0;
154 int verify = obj->ioo_id != 0;
157 for (j = 0 ; j < obj->ioo_bufcnt ; j++, nb++, r++) {
158 r->page = alloc_pages(highmem ? GFP_HIGHUSER : GFP_KERNEL, 0);
160 CERROR("can't get page %d/%d for id "LPU64"\n",
161 j, obj->ioo_bufcnt, obj->ioo_id);
162 GOTO(preprw_cleanup, rc = -ENOMEM);
166 r->offset = nb->offset;
167 r->addr = kmap(r->page);
170 CDEBUG(D_PAGE, "$$$$ get page %p, addr %p@"LPU64"\n",
171 r->page, r->addr, r->offset);
173 if (verify && (cmd & OBD_BRW_READ) != 0)
174 page_debug_setup(r->addr, r->len, r->offset,
178 CDEBUG(D_PAGE, "%ld pages allocated after prep\n", echo_pages);
183 /* It is possible that we would rather handle errors by allow
184 * any already-set-up pages to complete, rather than tearing them
185 * all down again. I believe that this is what the in-kernel
186 * prep/commit operations do.
188 CERROR("cleaning up %ld pages (%d obdos)\n", (long)(r - res), objcount);
191 __free_pages(r->page, 0);
194 memset(res, 0, sizeof(*res) * niocount);
199 int echo_commitrw(int cmd, struct lustre_handle *conn, int objcount,
200 struct obd_ioobj *obj, int niocount, struct niobuf_local *res,
203 struct niobuf_local *r = res;
208 CDEBUG(D_PAGE, "%s %d obdos with %d IOs\n",
209 cmd == OBD_BRW_READ ? "reading" : "writing", objcount, niocount);
211 if (niocount && !r) {
212 CERROR("NULL res niobuf with niocount %d\n", niocount);
216 LASSERT(desc_private == (void *)DESC_PRIV);
218 for (i = 0; i < objcount; i++, obj++) {
219 int verify = obj->ioo_id != 0;
222 for (j = 0 ; j < obj->ioo_bufcnt ; j++, r++) {
223 struct page *page = r->page;
226 if (!page || !(addr = page_address(page)) ||
227 !kern_addr_valid(addr)) {
229 CERROR("bad page "LPU64":%p, buf %d/%d\n",
230 obj->ioo_id, page, j, obj->ioo_bufcnt);
231 GOTO(commitrw_cleanup, rc = -EFAULT);
234 atomic_inc (&echo_page_rws);
236 CDEBUG(D_PAGE, "$$$$ use page %p, addr %p@"LPU64"\n",
237 r->page, addr, r->offset);
239 if (verify && (cmd & OBD_BRW_WRITE))
240 page_debug_check("echo", addr, r->len,
241 r->offset, obj->ioo_id);
244 __free_pages(page, 0);
248 CDEBUG(D_PAGE, "%ld pages remain after commit\n", echo_pages);
252 CERROR("cleaning up %ld pages (%d obdos)\n",
253 niocount - (long)(r - res) - 1, objcount);
254 while (++r < res + niocount) {
255 struct page *page = r->page;
258 __free_pages(page, 0);
264 static int echo_setup(struct obd_device *obddev, obd_count len, void *buf)
268 obddev->obd_namespace =
269 ldlm_namespace_new("echo-tgt", LDLM_NAMESPACE_SERVER);
270 if (obddev->obd_namespace == NULL) {
278 static int echo_cleanup(struct obd_device *obddev)
282 ldlm_namespace_free(obddev->obd_namespace);
287 struct obd_ops echo_obd_ops = {
288 o_connect: echo_connect,
289 o_disconnect: echo_disconnect,
290 o_getattr: echo_getattr,
291 o_preprw: echo_preprw,
292 o_commitrw: echo_commitrw,
294 o_cleanup: echo_cleanup
297 static int __init obdecho_init(void)
299 printk(KERN_INFO "Echo OBD driver " OBDECHO_VERSION " info@clusterfs.com\n");
303 return class_register_type(&echo_obd_ops, OBD_ECHO_DEVICENAME);
306 static void __exit obdecho_exit(void)
310 CERROR("%ld prep/commitrw pages leaked\n", echo_pages);
311 class_unregister_type(OBD_ECHO_DEVICENAME);
314 MODULE_AUTHOR("Cluster Filesystems Inc. <info@clusterfs.com>");
315 MODULE_DESCRIPTION("Lustre Testing Echo OBD driver " OBDECHO_VERSION);
316 MODULE_LICENSE("GPL");
318 module_init(obdecho_init);
319 module_exit(obdecho_exit);