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 int echo_connect (struct obd_conn *conn)
41 rc = gen_connect(conn);
49 int echo_disconnect(struct obd_conn *conn)
53 rc = gen_disconnect(conn);
60 static int echo_getattr(struct obd_conn *conn, struct obdo *oa)
62 memcpy(oa, &OA, sizeof(*oa));
68 int echo_preprw(int cmd, struct obd_conn *conn, int objcount,
69 struct obd_ioobj *obj, int niocount, struct niobuf *nb,
72 struct niobuf *r = res;
78 memset(res, 0, sizeof(*res) * niocount);
80 CDEBUG(D_PAGE, "%s %d obdos with %d IOs\n",
81 cmd == OBD_BRW_READ ? "reading" : "writing", objcount, niocount);
83 for (i = 0; i < objcount; i++, obj++) {
86 for (j = 0 ; j < obj->ioo_bufcnt ; j++, nb++, r++) {
87 unsigned long address;
89 address = get_zeroed_page(GFP_KERNEL);
91 CERROR("can't get new page %d/%d for id %Ld\n",
92 j, obj->ioo_bufcnt, obj->ioo_id);
100 if (cmd == OBD_BRW_READ) {
101 __u64 *data = address;
103 data[0] = obj->ioo_id;
105 data[2] = nb->offset;
111 r->offset = nb->offset;
112 r->page = virt_to_page(address);
117 CDEBUG(D_PAGE, "%ld pages allocated after prep\n", echo_pages);
123 /* It is possible that we would rather handle errors by allow
124 * any already-set-up pages to complete, rather than tearing them
125 * all down again. I believe that this is what the in-kernel
126 * prep/commit operations do.
128 CERROR("cleaning up %d pages (%d obdos)\n", r - res, objcount);
130 unsigned long addr = r->addr;
135 memset(res, 0, sizeof(*res) * niocount);
140 int echo_commitrw(int cmd, struct obd_conn *conn, int objcount,
141 struct obd_ioobj *obj, int niocount, struct niobuf *res)
143 struct niobuf *r = res;
149 CDEBUG(D_PAGE, "%s %d obdos with %d IOs\n",
150 cmd == OBD_BRW_READ ? "reading" : "writing", objcount, niocount);
152 if (niocount && !r) {
153 CERROR("NULL res niobuf with niocount %d\n", niocount);
158 for (i = 0; i < objcount; i++, obj++) {
161 for (j = 0 ; j < obj->ioo_bufcnt ; j++, r++) {
162 struct page *page = r->page;
163 unsigned long addr = (unsigned long)page_address(page);
165 if (!addr || !kern_addr_valid(addr)) {
166 CERROR("bad page %p, id %Ld (%d), buf %d/%d\n",
167 page, obj->ioo_id, i, j,obj->ioo_bufcnt);
170 goto commitrw_cleanup;
177 CDEBUG(D_PAGE, "%ld pages remain after commit\n", echo_pages);
182 CERROR("cleaning up %d pages (%d obdos)\n", niocount - (r - res) - 1,
184 while (++r < res + niocount) {
185 struct page *page = r->page;
186 unsigned long addr = (unsigned long)page_address(page);
194 struct obd_ops echo_obd_ops = {
195 o_connect: echo_connect,
196 o_disconnect: echo_disconnect,
197 o_getattr: echo_getattr,
198 o_preprw: echo_preprw,
199 o_commitrw: echo_commitrw,
203 static int __init obdecho_init(void)
205 printk(KERN_INFO "Echo OBD driver v0.001, braam@clusterfs.com\n");
207 return obd_register_type(&echo_obd_ops, OBD_ECHO_DEVICENAME);
210 static void __exit obdecho_exit(void)
212 CERROR("%ld prep/commitrw pages leaked\n", echo_pages);
213 obd_unregister_type(OBD_ECHO_DEVICENAME);
216 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
217 MODULE_DESCRIPTION("Lustre Testing Echo OBD driver v1.0");
218 MODULE_LICENSE("GPL");
220 module_init(obdecho_init);
221 module_exit(obdecho_exit);