Whamcloud - gitweb
Add closing quote so that obdecho compiles.
[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_connect(struct lustre_handle *conn, struct obd_device *obd)
37 {
38         int rc;
39
40         MOD_INC_USE_COUNT;
41         rc = class_connect(conn, obd);
42
43         if (rc)
44                 MOD_DEC_USE_COUNT;
45
46         return rc;
47 }
48
49 static int echo_disconnect(struct lustre_handle *conn)
50 {
51         int rc;
52
53         rc = class_disconnect(conn);
54         if (!rc)
55                 MOD_DEC_USE_COUNT;
56
57         return rc;
58 }
59
60 static int echo_getattr(struct lustre_handle *conn, struct obdo *oa)
61 {
62         memcpy(oa, &OA, sizeof(*oa));
63         oa->o_mode = ++GEN;
64
65         return 0;
66 }
67
68 int echo_preprw(int cmd, struct lustre_handle *conn, int objcount,
69                 struct obd_ioobj *obj, int niocount, struct niobuf_remote *nb,
70                 struct niobuf_local *res, void **desc_private)
71 {
72         struct niobuf_local *r = res;
73         int rc = 0;
74         int i;
75
76         ENTRY;
77
78         memset(res, 0, sizeof(*res) * niocount);
79
80         CDEBUG(D_PAGE, "%s %d obdos with %d IOs\n",
81                cmd == OBD_BRW_READ ? "reading" : "writing", objcount, niocount);
82
83         for (i = 0; i < objcount; i++, obj++) {
84                 int j;
85
86                 for (j = 0 ; j < obj->ioo_bufcnt ; j++, nb++, r++) {
87                         unsigned long address;
88
89                         address = get_zeroed_page(GFP_KERNEL);
90                         if (!address) {
91                                 CERROR("can't get new page %d/%d for id %Ld\n",
92                                        j, obj->ioo_bufcnt,
93                                        (unsigned long long)obj->ioo_id);
94                                 GOTO(preprw_cleanup, rc = -ENOMEM);
95                         }
96                         echo_pages++;
97
98                         r->offset = nb->offset;
99                         r->page = virt_to_page(address);
100                         r->addr = kmap(r->page);
101                         r->len = nb->len;
102                 }
103         }
104         CDEBUG(D_PAGE, "%ld pages allocated after prep\n", echo_pages);
105
106         RETURN(0);
107
108 preprw_cleanup:
109         /* It is possible that we would rather handle errors by  allow
110          * any already-set-up pages to complete, rather than tearing them
111          * all down again.  I believe that this is what the in-kernel
112          * prep/commit operations do.
113          */
114         CERROR("cleaning up %ld pages (%d obdos)\n", (long)(r - res), objcount);
115         while (r-- > res) {
116                 kunmap(r->page);
117                 __free_pages(r->page, 0);
118                 echo_pages--;
119         }
120         memset(res, 0, sizeof(*res) * niocount);
121
122         return rc;
123 }
124
125 int echo_commitrw(int cmd, struct lustre_handle *conn, int objcount,
126                   struct obd_ioobj *obj, int niocount, struct niobuf_local *res,
127                   void *desc_private)
128 {
129         struct niobuf_local *r = res;
130         int rc = 0;
131         int i;
132         ENTRY;
133
134         CDEBUG(D_PAGE, "%s %d obdos with %d IOs\n",
135                cmd == OBD_BRW_READ ? "reading" : "writing", objcount, niocount);
136
137         if (niocount && !r) {
138                 CERROR("NULL res niobuf with niocount %d\n", niocount);
139                 RETURN(-EINVAL);
140         }
141
142         for (i = 0; i < objcount; i++, obj++) {
143                 int j;
144
145                 for (j = 0 ; j < obj->ioo_bufcnt ; j++, r++) {
146                         struct page *page = r->page;
147                         unsigned long addr;
148
149                         if (!page ||
150                             !(addr = (unsigned long)page_address(page)) ||
151                             !kern_addr_valid(addr)) {
152
153                                 CERROR("bad page %p, id %Ld (%d), buf %d/%d\n",
154                                        page, (unsigned long long)obj->ioo_id, i,
155                                        j, obj->ioo_bufcnt);
156                                 GOTO(commitrw_cleanup, rc = -EFAULT);
157                         }
158
159                         kunmap(page);
160                         __free_pages(page, 0);
161                         echo_pages--;
162                 }
163         }
164         CDEBUG(D_PAGE, "%ld pages remain after commit\n", echo_pages);
165         RETURN(0);
166
167 commitrw_cleanup:
168         CERROR("cleaning up %ld pages (%d obdos)\n",
169                niocount - (long)(r - res) - 1, objcount);
170         while (++r < res + niocount) {
171                 struct page *page = r->page;
172
173                 kunmap(page);
174                 __free_pages(page, 0);
175                 echo_pages--;
176         }
177         return rc;
178 }
179
180 struct obd_ops echo_obd_ops = {
181         o_connect:     echo_connect,
182         o_disconnect:  echo_disconnect,
183         o_getattr:     echo_getattr,
184         o_preprw:      echo_preprw,
185         o_commitrw:    echo_commitrw,
186 };
187
188 #define OBDECHO_VERSION "$Revision: 1.16 $"
189
190 static int __init obdecho_init(void)
191 {
192         printk(KERN_INFO "Echo OBD driver " OBDECHO_VERSION " info@clusterfs.com\n");
193
194         return class_register_type(&echo_obd_ops, OBD_ECHO_DEVICENAME);
195 }
196
197 static void __exit obdecho_exit(void)
198 {
199         CERROR("%ld prep/commitrw pages leaked\n", echo_pages);
200         class_unregister_type(OBD_ECHO_DEVICENAME);
201 }
202
203 MODULE_AUTHOR("Cluster Filesystems Inc. <info@clusterfs.com>");
204 MODULE_DESCRIPTION("Lustre Testing Echo OBD driver " OBDECHO_VERSION);
205 MODULE_LICENSE("GPL"); 
206
207 module_init(obdecho_init);
208 module_exit(obdecho_exit);