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.18 2002/07/26 16:54:55 rread Exp $";
15 #define OBDECHO_VERSION "$Revision: 1.18 $"
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/init.h>
27 #include <asm/unistd.h>
29 #define DEBUG_SUBSYSTEM S_ECHO
31 #include <linux/obd_support.h>
32 #include <linux/obd_class.h>
33 #include <linux/obd_echo.h>
35 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
36 static struct obdo OA;
38 static long echo_pages = 0;
40 static int echo_connect(struct lustre_handle *conn, struct obd_device *obd)
45 rc = class_connect(conn, obd);
53 static int echo_disconnect(struct lustre_handle *conn)
57 rc = class_disconnect(conn);
64 static int echo_getattr(struct lustre_handle *conn, struct obdo *oa)
66 memcpy(oa, &OA, sizeof(*oa));
72 int echo_preprw(int cmd, struct lustre_handle *conn, int objcount,
73 struct obd_ioobj *obj, int niocount, struct niobuf_remote *nb,
74 struct niobuf_local *res, void **desc_private)
76 struct niobuf_local *r = res;
82 memset(res, 0, sizeof(*res) * niocount);
84 CDEBUG(D_PAGE, "%s %d obdos with %d IOs\n",
85 cmd == OBD_BRW_READ ? "reading" : "writing", objcount, niocount);
87 for (i = 0; i < objcount; i++, obj++) {
90 for (j = 0 ; j < obj->ioo_bufcnt ; j++, nb++, r++) {
91 unsigned long address;
93 address = get_zeroed_page(GFP_KERNEL);
95 CERROR("can't get new page %d/%d for id %Ld\n",
97 (unsigned long long)obj->ioo_id);
98 GOTO(preprw_cleanup, rc = -ENOMEM);
102 r->offset = nb->offset;
103 r->page = virt_to_page(address);
104 r->addr = kmap(r->page);
108 CDEBUG(D_PAGE, "%ld pages allocated after prep\n", echo_pages);
113 /* It is possible that we would rather handle errors by allow
114 * any already-set-up pages to complete, rather than tearing them
115 * all down again. I believe that this is what the in-kernel
116 * prep/commit operations do.
118 CERROR("cleaning up %ld pages (%d obdos)\n", (long)(r - res), objcount);
121 __free_pages(r->page, 0);
124 memset(res, 0, sizeof(*res) * niocount);
129 int echo_commitrw(int cmd, struct lustre_handle *conn, int objcount,
130 struct obd_ioobj *obj, int niocount, struct niobuf_local *res,
133 struct niobuf_local *r = res;
138 CDEBUG(D_PAGE, "%s %d obdos with %d IOs\n",
139 cmd == OBD_BRW_READ ? "reading" : "writing", objcount, niocount);
141 if (niocount && !r) {
142 CERROR("NULL res niobuf with niocount %d\n", niocount);
146 for (i = 0; i < objcount; i++, obj++) {
149 for (j = 0 ; j < obj->ioo_bufcnt ; j++, r++) {
150 struct page *page = r->page;
154 !(addr = (unsigned long)page_address(page)) ||
155 !kern_addr_valid(addr)) {
157 CERROR("bad page %p, id %Ld (%d), buf %d/%d\n",
158 page, (unsigned long long)obj->ioo_id, i,
160 GOTO(commitrw_cleanup, rc = -EFAULT);
164 __free_pages(page, 0);
168 CDEBUG(D_PAGE, "%ld pages remain after commit\n", echo_pages);
172 CERROR("cleaning up %ld pages (%d obdos)\n",
173 niocount - (long)(r - res) - 1, objcount);
174 while (++r < res + niocount) {
175 struct page *page = r->page;
178 __free_pages(page, 0);
184 struct obd_ops echo_obd_ops = {
185 o_connect: echo_connect,
186 o_disconnect: echo_disconnect,
187 o_getattr: echo_getattr,
188 o_preprw: echo_preprw,
189 o_commitrw: echo_commitrw,
192 static int __init obdecho_init(void)
194 printk(KERN_INFO "Echo OBD driver " OBDECHO_VERSION " info@clusterfs.com\n");
196 return class_register_type(&echo_obd_ops, OBD_ECHO_DEVICENAME);
199 static void __exit obdecho_exit(void)
201 CERROR("%ld prep/commitrw pages leaked\n", echo_pages);
202 class_unregister_type(OBD_ECHO_DEVICENAME);
205 MODULE_AUTHOR("Cluster Filesystems Inc. <info@clusterfs.com>");
206 MODULE_DESCRIPTION("Lustre Testing Echo OBD driver " OBDECHO_VERSION);
207 MODULE_LICENSE("GPL");
209 module_init(obdecho_init);
210 module_exit(obdecho_exit);