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.17 2002/07/05 20:05:27 rread Exp $";
15 #define OBDECHO_VERSION "$Revision: 1.17 $"
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 <asm/unistd.h>
28 #define DEBUG_SUBSYSTEM S_ECHO
30 #include <linux/obd_support.h>
31 #include <linux/obd_class.h>
32 #include <linux/obd_echo.h>
34 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
35 static struct obdo OA;
37 static long echo_pages = 0;
39 static int echo_connect(struct lustre_handle *conn, struct obd_device *obd)
44 rc = class_connect(conn, obd);
52 static int echo_disconnect(struct lustre_handle *conn)
56 rc = class_disconnect(conn);
63 static int echo_getattr(struct lustre_handle *conn, struct obdo *oa)
65 memcpy(oa, &OA, sizeof(*oa));
71 int echo_preprw(int cmd, struct lustre_handle *conn, int objcount,
72 struct obd_ioobj *obj, int niocount, struct niobuf_remote *nb,
73 struct niobuf_local *res, void **desc_private)
75 struct niobuf_local *r = res;
81 memset(res, 0, sizeof(*res) * niocount);
83 CDEBUG(D_PAGE, "%s %d obdos with %d IOs\n",
84 cmd == OBD_BRW_READ ? "reading" : "writing", objcount, niocount);
86 for (i = 0; i < objcount; i++, obj++) {
89 for (j = 0 ; j < obj->ioo_bufcnt ; j++, nb++, r++) {
90 unsigned long address;
92 address = get_zeroed_page(GFP_KERNEL);
94 CERROR("can't get new page %d/%d for id %Ld\n",
96 (unsigned long long)obj->ioo_id);
97 GOTO(preprw_cleanup, rc = -ENOMEM);
101 r->offset = nb->offset;
102 r->page = virt_to_page(address);
103 r->addr = kmap(r->page);
107 CDEBUG(D_PAGE, "%ld pages allocated after prep\n", echo_pages);
112 /* It is possible that we would rather handle errors by allow
113 * any already-set-up pages to complete, rather than tearing them
114 * all down again. I believe that this is what the in-kernel
115 * prep/commit operations do.
117 CERROR("cleaning up %ld pages (%d obdos)\n", (long)(r - res), objcount);
120 __free_pages(r->page, 0);
123 memset(res, 0, sizeof(*res) * niocount);
128 int echo_commitrw(int cmd, struct lustre_handle *conn, int objcount,
129 struct obd_ioobj *obj, int niocount, struct niobuf_local *res,
132 struct niobuf_local *r = res;
137 CDEBUG(D_PAGE, "%s %d obdos with %d IOs\n",
138 cmd == OBD_BRW_READ ? "reading" : "writing", objcount, niocount);
140 if (niocount && !r) {
141 CERROR("NULL res niobuf with niocount %d\n", niocount);
145 for (i = 0; i < objcount; i++, obj++) {
148 for (j = 0 ; j < obj->ioo_bufcnt ; j++, r++) {
149 struct page *page = r->page;
153 !(addr = (unsigned long)page_address(page)) ||
154 !kern_addr_valid(addr)) {
156 CERROR("bad page %p, id %Ld (%d), buf %d/%d\n",
157 page, (unsigned long long)obj->ioo_id, i,
159 GOTO(commitrw_cleanup, rc = -EFAULT);
163 __free_pages(page, 0);
167 CDEBUG(D_PAGE, "%ld pages remain after commit\n", echo_pages);
171 CERROR("cleaning up %ld pages (%d obdos)\n",
172 niocount - (long)(r - res) - 1, objcount);
173 while (++r < res + niocount) {
174 struct page *page = r->page;
177 __free_pages(page, 0);
183 struct obd_ops echo_obd_ops = {
184 o_connect: echo_connect,
185 o_disconnect: echo_disconnect,
186 o_getattr: echo_getattr,
187 o_preprw: echo_preprw,
188 o_commitrw: echo_commitrw,
191 static int __init obdecho_init(void)
193 printk(KERN_INFO "Echo OBD driver " OBDECHO_VERSION " info@clusterfs.com\n");
195 return class_register_type(&echo_obd_ops, OBD_ECHO_DEVICENAME);
198 static void __exit obdecho_exit(void)
200 CERROR("%ld prep/commitrw pages leaked\n", echo_pages);
201 class_unregister_type(OBD_ECHO_DEVICENAME);
204 MODULE_AUTHOR("Cluster Filesystems Inc. <info@clusterfs.com>");
205 MODULE_DESCRIPTION("Lustre Testing Echo OBD driver " OBDECHO_VERSION);
206 MODULE_LICENSE("GPL");
208 module_init(obdecho_init);
209 module_exit(obdecho_exit);