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.19 2002/07/31 20:49:37 braam Exp $";
15 #define OBDECHO_VERSION "$Revision: 1.19 $"
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/proc_fs.h>
27 #include <linux/init.h>
28 #include <asm/unistd.h>
30 #define DEBUG_SUBSYSTEM S_ECHO
32 #include <linux/obd_support.h>
33 #include <linux/obd_class.h>
34 #include <linux/obd_echo.h>
36 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
37 static struct obdo OA;
39 static long echo_pages = 0;
41 static atomic_t echo_page_rws;
42 static atomic_t echo_getattrs;
44 #define ECHO_PROC_STAT "sys/obdecho"
47 echo_proc_read (char *page, char **start, off_t off, int count, int *eof, void *data)
50 int attrs = atomic_read (&echo_getattrs);
51 int pages = atomic_read (&echo_page_rws);
57 len = sprintf (page, "%d %d\n", pages, attrs);
64 echo_proc_write (struct file *file, const char *ubuffer, unsigned long count, void *data)
66 /* Ignore what we've been asked to write, and just zero the stats counters */
67 atomic_set (&echo_page_rws, 0);
68 atomic_set (&echo_getattrs, 0);
76 struct proc_dir_entry *entry = create_proc_entry (ECHO_PROC_STAT, S_IFREG | S_IRUGO | S_IWUSR, NULL);
80 CERROR("couldn't create proc entry %s\n", ECHO_PROC_STAT);
85 entry->read_proc = echo_proc_read;
86 entry->write_proc = echo_proc_write;
92 remove_proc_entry(ECHO_PROC_STAT, 0);
95 static int echo_connect(struct lustre_handle *conn, struct obd_device *obd)
100 rc = class_connect(conn, obd);
108 static int echo_disconnect(struct lustre_handle *conn)
112 rc = class_disconnect(conn);
119 static int echo_getattr(struct lustre_handle *conn, struct obdo *oa,
120 struct lov_stripe_md *md)
122 memcpy(oa, &OA, sizeof(*oa));
125 atomic_inc (&echo_getattrs);
130 int echo_preprw(int cmd, struct lustre_handle *conn, int objcount,
131 struct obd_ioobj *obj, int niocount, struct niobuf_remote *nb,
132 struct niobuf_local *res, void **desc_private)
134 struct niobuf_local *r = res;
140 memset(res, 0, sizeof(*res) * niocount);
142 CDEBUG(D_PAGE, "%s %d obdos with %d IOs\n",
143 cmd == OBD_BRW_READ ? "reading" : "writing", objcount, niocount);
145 for (i = 0; i < objcount; i++, obj++) {
148 for (j = 0 ; j < obj->ioo_bufcnt ; j++, nb++, r++) {
149 unsigned long address;
151 address = get_zeroed_page(GFP_KERNEL);
153 CERROR("can't get new page %d/%d for id %Ld\n",
155 (unsigned long long)obj->ioo_id);
156 GOTO(preprw_cleanup, rc = -ENOMEM);
160 r->offset = nb->offset;
161 r->page = virt_to_page(address);
162 r->addr = kmap(r->page);
166 CDEBUG(D_PAGE, "%ld pages allocated after prep\n", echo_pages);
171 /* It is possible that we would rather handle errors by allow
172 * any already-set-up pages to complete, rather than tearing them
173 * all down again. I believe that this is what the in-kernel
174 * prep/commit operations do.
176 CERROR("cleaning up %ld pages (%d obdos)\n", (long)(r - res), objcount);
179 __free_pages(r->page, 0);
182 memset(res, 0, sizeof(*res) * niocount);
187 int echo_commitrw(int cmd, struct lustre_handle *conn, int objcount,
188 struct obd_ioobj *obj, int niocount, struct niobuf_local *res,
191 struct niobuf_local *r = res;
196 CDEBUG(D_PAGE, "%s %d obdos with %d IOs\n",
197 cmd == OBD_BRW_READ ? "reading" : "writing", objcount, niocount);
199 if (niocount && !r) {
200 CERROR("NULL res niobuf with niocount %d\n", niocount);
204 for (i = 0; i < objcount; i++, obj++) {
207 for (j = 0 ; j < obj->ioo_bufcnt ; j++, r++) {
208 struct page *page = r->page;
212 !(addr = (unsigned long)page_address(page)) ||
213 !kern_addr_valid(addr)) {
215 CERROR("bad page %p, id %Ld (%d), buf %d/%d\n",
216 page, (unsigned long long)obj->ioo_id, i,
218 GOTO(commitrw_cleanup, rc = -EFAULT);
221 atomic_inc (&echo_page_rws);
224 __free_pages(page, 0);
228 CDEBUG(D_PAGE, "%ld pages remain after commit\n", echo_pages);
232 CERROR("cleaning up %ld pages (%d obdos)\n",
233 niocount - (long)(r - res) - 1, objcount);
234 while (++r < res + niocount) {
235 struct page *page = r->page;
238 __free_pages(page, 0);
244 struct obd_ops echo_obd_ops = {
245 o_connect: echo_connect,
246 o_disconnect: echo_disconnect,
247 o_getattr: echo_getattr,
248 o_preprw: echo_preprw,
249 o_commitrw: echo_commitrw,
252 static int __init obdecho_init(void)
254 printk(KERN_INFO "Echo OBD driver " OBDECHO_VERSION " info@clusterfs.com\n");
258 return class_register_type(&echo_obd_ops, OBD_ECHO_DEVICENAME);
261 static void __exit obdecho_exit(void)
265 CERROR("%ld prep/commitrw pages leaked\n", echo_pages);
266 class_unregister_type(OBD_ECHO_DEVICENAME);
269 MODULE_AUTHOR("Cluster Filesystems Inc. <info@clusterfs.com>");
270 MODULE_DESCRIPTION("Lustre Testing Echo OBD driver " OBDECHO_VERSION);
271 MODULE_LICENSE("GPL");
273 module_init(obdecho_init);
274 module_exit(obdecho_exit);