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>
16 #include <linux/version.h>
17 #include <linux/module.h>
19 #include <linux/stat.h>
20 #include <linux/locks.h>
21 #include <linux/ext2_fs.h>
22 #include <linux/quotaops.h>
23 #include <asm/unistd.h>
25 #define DEBUG_SUBSYSTEM S_ECHO
27 #include <linux/obd_support.h>
28 #include <linux/obd_class.h>
29 #include <linux/obd_echo.h>
31 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
32 static struct obdo OA;
34 static long echo_pages = 0;
36 static int echo_getattr(struct obd_conn *conn, struct obdo *oa)
38 memcpy(oa, &OA, sizeof(*oa));
44 int echo_preprw(int cmd, struct obd_conn *conn, int objcount,
45 struct obd_ioobj *obj, int niocount, struct niobuf *nb,
52 memset(res, 0, sizeof(*res) * niocount);
54 CDEBUG(D_CACHE, "%s %d obdos with %d IOs\n",
55 cmd == OBD_BRW_READ ? "reading" : "writing", objcount, niocount);
57 for (i = 0; i < objcount; i++, obj++) {
60 for (j = 0 ; j < obj->ioo_bufcnt ; j++, nb++, res++) {
61 unsigned long address;
63 address = get_zeroed_page(GFP_KERNEL);
65 /* FIXME: cleanup old pages on error */
72 if (cmd == OBD_BRW_READ) {
73 __u64 *data = address;
75 data[0] = obj->ioo_id;
83 res->offset = nb->offset;
84 res->page = virt_to_page(address);
93 int echo_commitrw(int cmd, struct obd_conn *conn, int objcount,
94 struct obd_ioobj *obj, int niocount, struct niobuf *res)
100 CDEBUG(D_CACHE, "%s %d obdos with %d IOs\n",
101 cmd == OBD_BRW_READ ? "reading" : "writing", objcount, niocount);
103 for (i = 0; i < objcount; i++, obj++) {
106 for (j = 0 ; j < obj->ioo_bufcnt ; j++, res++) {
110 /* FIXME: cleanup remaining pages */
111 CERROR("NULL buf, obj %Ld (%d), buf %d/%d\n",
112 obj->ioo_id, i, j, obj->ioo_bufcnt);
117 if (!addr || !kern_addr_valid(addr)) {
118 /* FIXME: cleanup remaining pages */
119 CERROR("bad addr %lx, id %Ld (%d), buf %d/%d\n",
120 addr, obj->ioo_id, i, j,obj->ioo_bufcnt);
128 CDEBUG(D_MALLOC, "%ld pages remain after commit\n", echo_pages);
132 struct obd_ops echo_obd_ops = {
133 o_connect: gen_connect,
134 o_disconnect: gen_disconnect,
135 o_getattr: echo_getattr,
136 o_preprw: echo_preprw,
137 o_commitrw: echo_commitrw,
141 static int __init obdecho_init(void)
143 printk(KERN_INFO "Echo OBD driver v0.001, braam@clusterfs.com\n");
145 return obd_register_type(&echo_obd_ops, OBD_ECHO_DEVICENAME);
148 static void __exit obdecho_exit(void)
150 CERROR("%ld prep/commitrw pages leaked\n", echo_pages);
151 obd_unregister_type(OBD_ECHO_DEVICENAME);
154 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
155 MODULE_DESCRIPTION("Lustre Testing Echo OBD driver v1.0");
156 MODULE_LICENSE("GPL");
158 module_init(obdecho_init);
159 module_exit(obdecho_exit);