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_connect(struct obd_conn *conn)
41 rc = gen_connect(conn);
49 static 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_remote *nb,
70 struct niobuf_local *res, void **desc_private)
72 struct niobuf_local *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",
93 (unsigned long long)obj->ioo_id);
94 GOTO(preprw_cleanup, rc = -ENOMEM);
98 r->offset = nb->offset;
99 r->page = virt_to_page(address);
100 r->addr = kmap(r->page);
104 CDEBUG(D_PAGE, "%ld pages allocated after prep\n", echo_pages);
109 /* It is possible that we would rather handle errors by allow
110 * any already-set-up pages to complete, rather than tearing them
111 * all down again. I believe that this is what the in-kernel
112 * prep/commit operations do.
114 CERROR("cleaning up %ld pages (%d obdos)\n", (long)(r - res), objcount);
117 __free_pages(r->page, 0);
120 memset(res, 0, sizeof(*res) * niocount);
125 int echo_commitrw(int cmd, struct obd_conn *conn, int objcount,
126 struct obd_ioobj *obj, int niocount, struct niobuf_local *res,
129 struct niobuf_local *r = res;
134 CDEBUG(D_PAGE, "%s %d obdos with %d IOs\n",
135 cmd == OBD_BRW_READ ? "reading" : "writing", objcount, niocount);
137 if (niocount && !r) {
138 CERROR("NULL res niobuf with niocount %d\n", niocount);
142 for (i = 0; i < objcount; i++, obj++) {
145 for (j = 0 ; j < obj->ioo_bufcnt ; j++, r++) {
146 struct page *page = r->page;
150 !(addr = (unsigned long)page_address(page)) ||
151 !kern_addr_valid(addr)) {
153 CERROR("bad page %p, id %Ld (%d), buf %d/%d\n",
154 page, (unsigned long long)obj->ioo_id, i,
156 GOTO(commitrw_cleanup, rc = -EFAULT);
160 __free_pages(page, 0);
164 CDEBUG(D_PAGE, "%ld pages remain after commit\n", echo_pages);
168 CERROR("cleaning up %ld pages (%d obdos)\n",
169 niocount - (long)(r - res) - 1, objcount);
170 while (++r < res + niocount) {
171 struct page *page = r->page;
174 __free_pages(page, 0);
180 struct obd_ops echo_obd_ops = {
181 o_connect: echo_connect,
182 o_disconnect: echo_disconnect,
183 o_getattr: echo_getattr,
184 o_preprw: echo_preprw,
185 o_commitrw: echo_commitrw,
189 static int __init obdecho_init(void)
191 printk(KERN_INFO "Echo OBD driver v0.001, braam@clusterfs.com\n");
193 return obd_register_type(&echo_obd_ops, OBD_ECHO_DEVICENAME);
196 static void __exit obdecho_exit(void)
198 CERROR("%ld prep/commitrw pages leaked\n", echo_pages);
199 obd_unregister_type(OBD_ECHO_DEVICENAME);
202 MODULE_AUTHOR("Cluster Filesystems Inc. <info@clusterfs.com>");
203 MODULE_DESCRIPTION("Lustre Testing Echo OBD driver v1.0");
204 MODULE_LICENSE("GPL");
206 module_init(obdecho_init);
207 module_exit(obdecho_exit);