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.20 2002/08/07 21:46:32 shaver Exp $";
15 #define OBDECHO_VERSION "$Revision: 1.20 $"
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,
101 rc = class_connect(conn, obd, NULL);
109 static int echo_disconnect(struct lustre_handle *conn)
113 rc = class_disconnect(conn);
120 static int echo_getattr(struct lustre_handle *conn, struct obdo *oa,
121 struct lov_stripe_md *md)
123 memcpy(oa, &OA, sizeof(*oa));
126 atomic_inc (&echo_getattrs);
131 int echo_preprw(int cmd, struct lustre_handle *conn, int objcount,
132 struct obd_ioobj *obj, int niocount, struct niobuf_remote *nb,
133 struct niobuf_local *res, void **desc_private)
135 struct niobuf_local *r = res;
141 memset(res, 0, sizeof(*res) * niocount);
143 CDEBUG(D_PAGE, "%s %d obdos with %d IOs\n",
144 cmd == OBD_BRW_READ ? "reading" : "writing", objcount, niocount);
146 for (i = 0; i < objcount; i++, obj++) {
149 for (j = 0 ; j < obj->ioo_bufcnt ; j++, nb++, r++) {
150 unsigned long address;
152 address = get_zeroed_page(GFP_KERNEL);
154 CERROR("can't get new page %d/%d for id %Ld\n",
156 (unsigned long long)obj->ioo_id);
157 GOTO(preprw_cleanup, rc = -ENOMEM);
161 r->offset = nb->offset;
162 r->page = virt_to_page(address);
163 r->addr = kmap(r->page);
167 CDEBUG(D_PAGE, "%ld pages allocated after prep\n", echo_pages);
172 /* It is possible that we would rather handle errors by allow
173 * any already-set-up pages to complete, rather than tearing them
174 * all down again. I believe that this is what the in-kernel
175 * prep/commit operations do.
177 CERROR("cleaning up %ld pages (%d obdos)\n", (long)(r - res), objcount);
180 __free_pages(r->page, 0);
183 memset(res, 0, sizeof(*res) * niocount);
188 int echo_commitrw(int cmd, struct lustre_handle *conn, int objcount,
189 struct obd_ioobj *obj, int niocount, struct niobuf_local *res,
192 struct niobuf_local *r = res;
197 CDEBUG(D_PAGE, "%s %d obdos with %d IOs\n",
198 cmd == OBD_BRW_READ ? "reading" : "writing", objcount, niocount);
200 if (niocount && !r) {
201 CERROR("NULL res niobuf with niocount %d\n", niocount);
205 for (i = 0; i < objcount; i++, obj++) {
208 for (j = 0 ; j < obj->ioo_bufcnt ; j++, r++) {
209 struct page *page = r->page;
213 !(addr = (unsigned long)page_address(page)) ||
214 !kern_addr_valid(addr)) {
216 CERROR("bad page %p, id %Ld (%d), buf %d/%d\n",
217 page, (unsigned long long)obj->ioo_id, i,
219 GOTO(commitrw_cleanup, rc = -EFAULT);
222 atomic_inc (&echo_page_rws);
225 __free_pages(page, 0);
229 CDEBUG(D_PAGE, "%ld pages remain after commit\n", echo_pages);
233 CERROR("cleaning up %ld pages (%d obdos)\n",
234 niocount - (long)(r - res) - 1, objcount);
235 while (++r < res + niocount) {
236 struct page *page = r->page;
239 __free_pages(page, 0);
245 struct obd_ops echo_obd_ops = {
246 o_connect: echo_connect,
247 o_disconnect: echo_disconnect,
248 o_getattr: echo_getattr,
249 o_preprw: echo_preprw,
250 o_commitrw: echo_commitrw,
253 static int __init obdecho_init(void)
255 printk(KERN_INFO "Echo OBD driver " OBDECHO_VERSION " info@clusterfs.com\n");
259 return class_register_type(&echo_obd_ops, OBD_ECHO_DEVICENAME);
262 static void __exit obdecho_exit(void)
266 CERROR("%ld prep/commitrw pages leaked\n", echo_pages);
267 class_unregister_type(OBD_ECHO_DEVICENAME);
270 MODULE_AUTHOR("Cluster Filesystems Inc. <info@clusterfs.com>");
271 MODULE_DESCRIPTION("Lustre Testing Echo OBD driver " OBDECHO_VERSION);
272 MODULE_LICENSE("GPL");
274 module_init(obdecho_init);
275 module_exit(obdecho_exit);