Whamcloud - gitweb
Update preprw and commitrw methods on echo OST.
[fs/lustre-release.git] / lustre / obdecho / echo.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  linux/fs/ext2_obd/ext2_obd.c
5  *
6  * Copyright (C) 2001  Cluster File Systems, Inc.
7  *
8  * This code is issued under the GNU General Public License.
9  * See the file COPYING in this distribution
10  *
11  * by Peter Braam <braam@clusterfs.com>
12  */
13
14 #define EXPORT_SYMTAB
15
16 #include <linux/version.h>
17 #include <linux/module.h>
18 #include <linux/fs.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>
24
25 #define DEBUG_SUBSYSTEM S_ECHO
26
27 #include <linux/obd_support.h>
28 #include <linux/obd_class.h>
29 #include <linux/obd_echo.h>
30
31 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
32 static struct obdo OA;
33 static obd_count GEN;
34 static long echo_pages = 0;
35
36 static int echo_getattr(struct obd_conn *conn, struct obdo *oa)
37 {
38         memcpy(oa, &OA, sizeof(*oa));
39         oa->o_mode = ++GEN;
40
41         return 0;
42 }
43
44 int echo_preprw(int cmd, struct obd_conn *conn, int objcount,
45                 struct obd_ioobj *obj, int niocount, struct niobuf *nb,
46                 struct niobuf *res)
47 {
48         int rc = 0;
49         int i;
50
51         ENTRY;
52         memset(res, 0, sizeof(*res) * niocount);
53
54         CDEBUG(D_CACHE, "%s %d obdos with %d IOs\n",
55                cmd == OBD_BRW_READ ? "reading" : "writing", objcount, niocount);
56
57         for (i = 0; i < objcount; i++, obj++) {
58                 int j;
59
60                 for (j = 0 ; j < obj->ioo_bufcnt ; j++, nb++, res++) {
61                         unsigned long address;
62
63                         address = get_zeroed_page(GFP_KERNEL);
64                         if (!address) {
65                                 /* FIXME: cleanup old pages on error */
66                                 EXIT;
67                                 rc = -ENOMEM;
68                         }
69                         echo_pages++;
70
71                         /*
72                         if (cmd == OBD_BRW_READ) {
73                                 __u64 *data = address;
74
75                                 data[0] = obj->ioo_id;
76                                 data[1] = j;
77                                 data[2] = nb->offset;
78                                 data[3] = nb->len;
79                         }
80                         */
81
82                         res->addr = address;
83                         res->offset = nb->offset;
84                         res->page = virt_to_page(address);
85                         res->len = PAGE_SIZE;
86                         // r->flags
87                 }
88         }
89
90         return rc;
91 }
92
93 int echo_commitrw(int cmd, struct obd_conn *conn, int objcount,
94                   struct obd_ioobj *obj, int niocount, struct niobuf *res)
95 {
96         int i;
97         int rc = 0;
98         ENTRY;
99
100         CDEBUG(D_CACHE, "%s %d obdos with %d IOs\n",
101                cmd == OBD_BRW_READ ? "reading" : "writing", objcount, niocount);
102
103         for (i = 0; i < objcount; i++, obj++) {
104                 int j;
105
106                 for (j = 0 ; j < obj->ioo_bufcnt ; j++, res++) {
107                         unsigned long addr;
108
109                         if (!res) {
110                                 /* FIXME: cleanup remaining pages */
111                                 CERROR("NULL buf, obj %Ld (%d), buf %d/%d\n",
112                                         obj->ioo_id, i, j, obj->ioo_bufcnt);
113                                 rc = -EINVAL;
114                         }
115
116                         addr = res->addr;
117                         if (!addr || !kern_addr_valid(addr)) {
118                                 /* FIXME: cleanup remaining pages */
119                                 CERROR("bad addr %lx, id %Ld (%d), buf %d/%d\n",
120                                        addr, obj->ioo_id, i, j,obj->ioo_bufcnt);
121                                 rc = -EINVAL;
122                         }
123
124                         free_pages(addr, 0);
125                         echo_pages--;
126                 }
127         }
128         CDEBUG(D_MALLOC, "%ld pages remain after commit\n", echo_pages);
129         return rc;
130 }
131
132 struct obd_ops echo_obd_ops = {
133         o_connect:     gen_connect,
134         o_disconnect:  gen_disconnect,
135         o_getattr:     echo_getattr,
136         o_preprw:      echo_preprw,
137         o_commitrw:    echo_commitrw,
138 };
139
140
141 static int __init obdecho_init(void)
142 {
143         printk(KERN_INFO "Echo OBD driver  v0.001, braam@clusterfs.com\n");
144
145         return obd_register_type(&echo_obd_ops, OBD_ECHO_DEVICENAME);
146 }
147
148 static void __exit obdecho_exit(void)
149 {
150         CERROR("%ld prep/commitrw pages leaked\n", echo_pages);
151         obd_unregister_type(OBD_ECHO_DEVICENAME);
152 }
153
154 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
155 MODULE_DESCRIPTION("Lustre Testing Echo OBD driver v1.0");
156 MODULE_LICENSE("GPL"); 
157
158 module_init(obdecho_init);
159 module_exit(obdecho_exit);