Whamcloud - gitweb
b=17167 libcfs: ensure all libcfs exported symbols to have cfs_ prefix
[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  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/obdecho/echo.c
37  *
38  * Author: Peter Braam <braam@clusterfs.com>
39  * Author: Andreas Dilger <adilger@clusterfs.com>
40  */
41
42 #ifndef EXPORT_SYMTAB
43 # define EXPORT_SYMTAB
44 #endif
45
46 #define DEBUG_SUBSYSTEM S_ECHO
47
48 #include <obd_support.h>
49 #include <obd_class.h>
50 #include <lustre_debug.h>
51 #include <lustre_dlm.h>
52 #include <lprocfs_status.h>
53
54 #include "echo_internal.h"
55
56 #define ECHO_INIT_OBJID      0x1000000000000000ULL
57 #define ECHO_HANDLE_MAGIC    0xabcd0123fedc9876ULL
58
59 #define ECHO_PERSISTENT_PAGES (ECHO_PERSISTENT_SIZE >> CFS_PAGE_SHIFT)
60 static cfs_page_t *echo_persistent_pages[ECHO_PERSISTENT_PAGES];
61
62 enum {
63         LPROC_ECHO_READ_BYTES = 1,
64         LPROC_ECHO_WRITE_BYTES = 2,
65         LPROC_ECHO_LAST = LPROC_ECHO_WRITE_BYTES +1
66 };
67
68 static int echo_connect(const struct lu_env *env,
69                         struct obd_export **exp, struct obd_device *obd,
70                         struct obd_uuid *cluuid, struct obd_connect_data *data,
71                         void *localdata)
72 {
73         struct lustre_handle conn = { 0 };
74         int rc;
75
76         data->ocd_connect_flags &= ECHO_CONNECT_SUPPORTED;
77         rc = class_connect(&conn, obd, cluuid);
78         if (rc) {
79                 CERROR("can't connect %d\n", rc);
80                 return rc;
81         }
82         *exp = class_conn2export(&conn);
83
84         return 0;
85 }
86
87 static int echo_disconnect(struct obd_export *exp)
88 {
89         LASSERT (exp != NULL);
90
91         return server_disconnect_export(exp);
92 }
93
94 static int echo_init_export(struct obd_export *exp)
95 {
96         return ldlm_init_export(exp);
97 }
98
99 static int echo_destroy_export(struct obd_export *exp)
100 {
101         ENTRY;
102
103         target_destroy_export(exp);
104         ldlm_destroy_export(exp);
105
106         RETURN(0);
107 }
108
109  static __u64 echo_next_id(struct obd_device *obddev)
110 {
111         obd_id id;
112
113         cfs_spin_lock(&obddev->u.echo.eo_lock);
114         id = ++obddev->u.echo.eo_lastino;
115         cfs_spin_unlock(&obddev->u.echo.eo_lock);
116
117         return id;
118 }
119
120 int echo_create(struct obd_export *exp, struct obdo *oa,
121                 struct lov_stripe_md **ea, struct obd_trans_info *oti)
122 {
123         struct obd_device *obd = class_exp2obd(exp);
124
125         if (!obd) {
126                 CERROR("invalid client cookie "LPX64"\n",
127                        exp->exp_handle.h_cookie);
128                 return -EINVAL;
129         }
130
131         if (!(oa->o_mode && S_IFMT)) {
132                 CERROR("echo obd: no type!\n");
133                 return -ENOENT;
134         }
135
136         if (!(oa->o_valid & OBD_MD_FLTYPE)) {
137                 CERROR("invalid o_valid "LPX64"\n", oa->o_valid);
138                 return -EINVAL;
139         }
140
141         oa->o_id = echo_next_id(obd);
142         oa->o_valid = OBD_MD_FLID;
143
144         return 0;
145 }
146
147 int echo_destroy(struct obd_export *exp, struct obdo *oa,
148                  struct lov_stripe_md *ea, struct obd_trans_info *oti,
149                  struct obd_export *md_exp, void *capa)
150 {
151         struct obd_device *obd = class_exp2obd(exp);
152
153         ENTRY;
154         if (!obd) {
155                 CERROR("invalid client cookie "LPX64"\n",
156                        exp->exp_handle.h_cookie);
157                 RETURN(-EINVAL);
158         }
159
160         if (!(oa->o_valid & OBD_MD_FLID)) {
161                 CERROR("obdo missing FLID valid flag: "LPX64"\n", oa->o_valid);
162                 RETURN(-EINVAL);
163         }
164
165         if (oa->o_id > obd->u.echo.eo_lastino || oa->o_id < ECHO_INIT_OBJID) {
166                 CERROR("bad destroy objid: "LPX64"\n", oa->o_id);
167                 RETURN(-EINVAL);
168         }
169
170         RETURN(0);
171 }
172
173 static int echo_getattr(struct obd_export *exp, struct obd_info *oinfo)
174 {
175         struct obd_device *obd = class_exp2obd(exp);
176         obd_id id = oinfo->oi_oa->o_id;
177
178         ENTRY;
179         if (!obd) {
180                 CERROR("invalid client cookie "LPX64"\n",
181                        exp->exp_handle.h_cookie);
182                 RETURN(-EINVAL);
183         }
184
185         if (!(oinfo->oi_oa->o_valid & OBD_MD_FLID)) {
186                 CERROR("obdo missing FLID valid flag: "LPX64"\n",
187                        oinfo->oi_oa->o_valid);
188                 RETURN(-EINVAL);
189         }
190
191         obdo_cpy_md(oinfo->oi_oa, &obd->u.echo.eo_oa, oinfo->oi_oa->o_valid);
192         oinfo->oi_oa->o_id = id;
193
194         RETURN(0);
195 }
196
197 static int echo_setattr(struct obd_export *exp, struct obd_info *oinfo,
198                         struct obd_trans_info *oti)
199 {
200         struct obd_device *obd = class_exp2obd(exp);
201
202         ENTRY;
203         if (!obd) {
204                 CERROR("invalid client cookie "LPX64"\n",
205                        exp->exp_handle.h_cookie);
206                 RETURN(-EINVAL);
207         }
208
209         if (!(oinfo->oi_oa->o_valid & OBD_MD_FLID)) {
210                 CERROR("obdo missing FLID valid flag: "LPX64"\n",
211                        oinfo->oi_oa->o_valid);
212                 RETURN(-EINVAL);
213         }
214
215         memcpy(&obd->u.echo.eo_oa, oinfo->oi_oa, sizeof(*oinfo->oi_oa));
216
217         if (oinfo->oi_oa->o_id & 4) {
218                 /* Save lock to force ACKed reply */
219                 ldlm_lock_addref (&obd->u.echo.eo_nl_lock, LCK_NL);
220                 oti->oti_ack_locks[0].mode = LCK_NL;
221                 oti->oti_ack_locks[0].lock = obd->u.echo.eo_nl_lock;
222         }
223
224         RETURN(0);
225 }
226
227 static void
228 echo_page_debug_setup(cfs_page_t *page, int rw, obd_id id,
229                       __u64 offset, int len)
230 {
231         int   page_offset = offset & ~CFS_PAGE_MASK;
232         char *addr        = ((char *)cfs_kmap(page)) + page_offset;
233
234         if (len % OBD_ECHO_BLOCK_SIZE != 0)
235                 CERROR("Unexpected block size %d\n", len);
236
237         while (len > 0) {
238                 if (rw & OBD_BRW_READ)
239                         block_debug_setup(addr, OBD_ECHO_BLOCK_SIZE,
240                                           offset, id);
241                 else
242                         block_debug_setup(addr, OBD_ECHO_BLOCK_SIZE,
243                                           0xecc0ecc0ecc0ecc0ULL,
244                                           0xecc0ecc0ecc0ecc0ULL);
245
246                 addr   += OBD_ECHO_BLOCK_SIZE;
247                 offset += OBD_ECHO_BLOCK_SIZE;
248                 len    -= OBD_ECHO_BLOCK_SIZE;
249         }
250
251         cfs_kunmap(page);
252 }
253
254 static int
255 echo_page_debug_check(cfs_page_t *page, obd_id id,
256                       __u64 offset, int len)
257 {
258         int   page_offset = offset & ~CFS_PAGE_MASK;
259         char *addr        = ((char *)cfs_kmap(page)) + page_offset;
260         int   rc          = 0;
261         int   rc2;
262
263         if (len % OBD_ECHO_BLOCK_SIZE != 0)
264                 CERROR("Unexpected block size %d\n", len);
265
266         while (len > 0) {
267                 rc2 = block_debug_check("echo", addr, OBD_ECHO_BLOCK_SIZE,
268                                         offset, id);
269
270                 if (rc2 != 0 && rc == 0)
271                         rc = rc2;
272
273                 addr   += OBD_ECHO_BLOCK_SIZE;
274                 offset += OBD_ECHO_BLOCK_SIZE;
275                 len    -= OBD_ECHO_BLOCK_SIZE;
276         }
277
278         cfs_kunmap(page);
279
280         return (rc);
281 }
282
283 /* This allows us to verify that desc_private is passed unmolested */
284 #define DESC_PRIV 0x10293847
285
286 static int echo_map_nb_to_lb(struct obdo *oa, struct obd_ioobj *obj,
287                              struct niobuf_remote *nb, int *pages,
288                              struct niobuf_local *lb, int cmd, int *left)
289 {
290         int gfp_mask = (obj->ioo_id & 1) ? CFS_ALLOC_HIGHUSER : CFS_ALLOC_STD;
291         int ispersistent = obj->ioo_id == ECHO_PERSISTENT_OBJID;
292         int debug_setup = (!ispersistent &&
293                            (oa->o_valid & OBD_MD_FLFLAGS) != 0 &&
294                            (oa->o_flags & OBD_FL_DEBUG_CHECK) != 0);
295         struct niobuf_local *res = lb;
296         obd_off offset = nb->offset;
297         int len = nb->len;
298
299         while (len > 0) {
300                 int plen = CFS_PAGE_SIZE - (offset & (CFS_PAGE_SIZE-1));
301                 if (len < plen)
302                         plen = len;
303
304                 /* check for local buf overflow */
305                 if (*left == 0)
306                         return -EINVAL;
307
308                 res->offset = offset;
309                 res->len = plen;
310                 LASSERT((res->offset & ~CFS_PAGE_MASK) + res->len <= CFS_PAGE_SIZE);
311
312
313                 if (ispersistent &&
314                     (res->offset >> CFS_PAGE_SHIFT) < ECHO_PERSISTENT_PAGES) {
315                         res->page = echo_persistent_pages[res->offset >>
316                                 CFS_PAGE_SHIFT];
317                         /* Take extra ref so __free_pages() can be called OK */
318                         cfs_get_page (res->page);
319                 } else {
320                         OBD_PAGE_ALLOC(res->page, gfp_mask);
321                         if (res->page == NULL) {
322                                 CERROR("can't get page for id " LPU64"\n",
323                                        obj->ioo_id);
324                                 return -ENOMEM;
325                         }
326                 }
327
328                 CDEBUG(D_PAGE, "$$$$ get page %p @ "LPU64" for %d\n",
329                        res->page, res->offset, res->len);
330
331                 if (cmd & OBD_BRW_READ)
332                         res->rc = res->len;
333
334                 if (debug_setup)
335                         echo_page_debug_setup(res->page, cmd, obj->ioo_id,
336                                               res->offset, res->len);
337
338                 offset += plen;
339                 len -= plen;
340                 res++;
341
342                 (*left)--;
343                 (*pages)++;
344         }
345
346         return 0;
347 }
348
349 static int echo_finalize_lb(struct obdo *oa, struct obd_ioobj *obj,
350                             struct niobuf_remote *rb, int *pgs,
351                             struct niobuf_local *lb, int verify)
352 {
353         struct niobuf_local *res = lb;
354         obd_off start  = rb->offset >> CFS_PAGE_SHIFT;
355         obd_off end    = (rb->offset + rb->len + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
356         int     count  = (int)(end - start);
357         int     rc     = 0;
358         int     i;
359
360         for (i = 0; i < count; i++, (*pgs) ++, res++) {
361                 cfs_page_t *page = res->page;
362                 void       *addr;
363
364                 if (page == NULL) {
365                         CERROR("null page objid "LPU64":%p, buf %d/%d\n",
366                                obj->ioo_id, page, i, obj->ioo_bufcnt);
367                         return -EFAULT;
368                 }
369
370                 addr = cfs_kmap(page);
371
372                 CDEBUG(D_PAGE, "$$$$ use page %p, addr %p@"LPU64"\n",
373                        res->page, addr, res->offset);
374
375                 if (verify) {
376                         int vrc = echo_page_debug_check(page, obj->ioo_id,
377                                                         res->offset, res->len);
378                         /* check all the pages always */
379                         if (vrc != 0 && rc == 0)
380                                 rc = vrc;
381                 }
382
383                 cfs_kunmap(page);
384                 /* NB see comment above regarding persistent pages */
385                 OBD_PAGE_FREE(page);
386         }
387
388         return rc;
389 }
390
391 int echo_preprw(int cmd, struct obd_export *export, struct obdo *oa,
392                 int objcount, struct obd_ioobj *obj, struct niobuf_remote *nb,
393                 int *pages, struct niobuf_local *res,
394                 struct obd_trans_info *oti, struct lustre_capa *unused)
395 {
396         struct obd_device *obd;
397         int tot_bytes = 0;
398         int rc = 0;
399         int i, left;
400         ENTRY;
401
402         obd = export->exp_obd;
403         if (obd == NULL)
404                 RETURN(-EINVAL);
405
406         /* Temp fix to stop falling foul of osc_announce_cached() */
407         oa->o_valid &= ~(OBD_MD_FLBLOCKS | OBD_MD_FLGRANT);
408
409         memset(res, 0, sizeof(*res) * *pages);
410
411         CDEBUG(D_PAGE, "%s %d obdos with %d IOs\n",
412                cmd == OBD_BRW_READ ? "reading" : "writing", objcount, *pages);
413
414         if (oti)
415                 oti->oti_handle = (void *)DESC_PRIV;
416
417         left = *pages;
418         *pages = 0;
419
420         for (i = 0; i < objcount; i++, obj++) {
421                 int j;
422
423                 for (j = 0 ; j < obj->ioo_bufcnt ; j++, nb++) {
424
425                         rc = echo_map_nb_to_lb(oa, obj, nb, pages,
426                                                res + *pages, cmd, &left);
427                         if (rc)
428                                 GOTO(preprw_cleanup, rc);
429
430                         tot_bytes += nb->len;
431                 }
432         }
433
434         cfs_atomic_add(*pages, &obd->u.echo.eo_prep);
435
436         if (cmd & OBD_BRW_READ)
437                 lprocfs_counter_add(obd->obd_stats, LPROC_ECHO_READ_BYTES,
438                                     tot_bytes);
439         else
440                 lprocfs_counter_add(obd->obd_stats, LPROC_ECHO_WRITE_BYTES,
441                                     tot_bytes);
442
443         CDEBUG(D_PAGE, "%d pages allocated after prep\n",
444                cfs_atomic_read(&obd->u.echo.eo_prep));
445
446         RETURN(0);
447
448 preprw_cleanup:
449         /* It is possible that we would rather handle errors by  allow
450          * any already-set-up pages to complete, rather than tearing them
451          * all down again.  I believe that this is what the in-kernel
452          * prep/commit operations do.
453          */
454         CERROR("cleaning up %u pages (%d obdos)\n", *pages, objcount);
455         for (i = 0; i < *pages; i++) {
456                 cfs_kunmap(res[i].page);
457                 /* NB if this is a persistent page, __free_pages will just
458                  * lose the extra ref gained above */
459                 OBD_PAGE_FREE(res[i].page);
460                 res[i].page = NULL;
461                 cfs_atomic_dec(&obd->u.echo.eo_prep);
462         }
463
464         return rc;
465 }
466
467 int echo_commitrw(int cmd, struct obd_export *export, struct obdo *oa,
468                   int objcount, struct obd_ioobj *obj,
469                   struct niobuf_remote *rb, int niocount,
470                   struct niobuf_local *res, struct obd_trans_info *oti, int rc)
471 {
472         struct obd_device *obd;
473         int pgs = 0;
474         int i;
475         ENTRY;
476
477         obd = export->exp_obd;
478         if (obd == NULL)
479                 RETURN(-EINVAL);
480
481         if (rc)
482                 GOTO(commitrw_cleanup, rc);
483
484         if ((cmd & OBD_BRW_RWMASK) == OBD_BRW_READ) {
485                 CDEBUG(D_PAGE, "reading %d obdos with %d IOs\n",
486                        objcount, niocount);
487         } else {
488                 CDEBUG(D_PAGE, "writing %d obdos with %d IOs\n",
489                        objcount, niocount);
490         }
491
492         if (niocount && res == NULL) {
493                 CERROR("NULL res niobuf with niocount %d\n", niocount);
494                 RETURN(-EINVAL);
495         }
496
497         LASSERT(oti == NULL || oti->oti_handle == (void *)DESC_PRIV);
498
499         for (i = 0; i < objcount; i++, obj++) {
500                 int verify = (rc == 0 &&
501                               obj->ioo_id != ECHO_PERSISTENT_OBJID &&
502                               (oa->o_valid & OBD_MD_FLFLAGS) != 0 &&
503                               (oa->o_flags & OBD_FL_DEBUG_CHECK) != 0);
504                 int j;
505
506                 for (j = 0 ; j < obj->ioo_bufcnt ; j++, rb++) {
507                         int vrc = echo_finalize_lb(oa, obj, rb, &pgs, &res[pgs], verify);
508
509                         if (vrc == 0)
510                                 continue;
511
512                         if (vrc == -EFAULT)
513                                 GOTO(commitrw_cleanup, rc = vrc);
514
515                         if (rc == 0)
516                                 rc = vrc;
517                 }
518
519         }
520
521         cfs_atomic_sub(pgs, &obd->u.echo.eo_prep);
522
523         CDEBUG(D_PAGE, "%d pages remain after commit\n",
524                cfs_atomic_read(&obd->u.echo.eo_prep));
525         RETURN(rc);
526
527 commitrw_cleanup:
528         cfs_atomic_sub(pgs, &obd->u.echo.eo_prep);
529
530         CERROR("cleaning up %d pages (%d obdos)\n",
531                niocount - pgs - 1, objcount);
532
533         while (pgs ++ < niocount) {
534                 cfs_page_t *page = res[pgs].page;
535
536                 if (page == NULL)
537                         continue;
538
539                 /* NB see comment above regarding persistent pages */
540                 OBD_PAGE_FREE(page);
541                 cfs_atomic_dec(&obd->u.echo.eo_prep);
542         }
543         return rc;
544 }
545
546 static int echo_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
547 {
548         struct lprocfs_static_vars lvars;
549         int                        rc;
550         int                        lock_flags = 0;
551         struct ldlm_res_id         res_id = {.name = {1}};
552         char                       ns_name[48];
553         ENTRY;
554
555         cfs_spin_lock_init(&obd->u.echo.eo_lock);
556         obd->u.echo.eo_lastino = ECHO_INIT_OBJID;
557
558         sprintf(ns_name, "echotgt-%s", obd->obd_uuid.uuid);
559         obd->obd_namespace = ldlm_namespace_new(obd, ns_name,
560                                                 LDLM_NAMESPACE_SERVER,
561                                                 LDLM_NAMESPACE_MODEST);
562         if (obd->obd_namespace == NULL) {
563                 LBUG();
564                 RETURN(-ENOMEM);
565         }
566
567         rc = ldlm_cli_enqueue_local(obd->obd_namespace, &res_id, LDLM_PLAIN,
568                                     NULL, LCK_NL, &lock_flags, NULL,
569                                     ldlm_completion_ast, NULL, NULL, 0, NULL,
570                                     &obd->u.echo.eo_nl_lock);
571         LASSERT (rc == ELDLM_OK);
572
573         lprocfs_echo_init_vars(&lvars);
574         if (lprocfs_obd_setup(obd, lvars.obd_vars) == 0 &&
575             lprocfs_alloc_obd_stats(obd, LPROC_ECHO_LAST) == 0) {
576                 lprocfs_counter_init(obd->obd_stats, LPROC_ECHO_READ_BYTES,
577                                      LPROCFS_CNTR_AVGMINMAX,
578                                      "read_bytes", "bytes");
579                 lprocfs_counter_init(obd->obd_stats, LPROC_ECHO_WRITE_BYTES,
580                                      LPROCFS_CNTR_AVGMINMAX,
581                                      "write_bytes", "bytes");
582         }
583
584         ptlrpc_init_client (LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
585                             "echo_ldlm_cb_client", &obd->obd_ldlm_client);
586         RETURN(0);
587 }
588
589 static int echo_cleanup(struct obd_device *obd)
590 {
591         int leaked;
592         ENTRY;
593
594         lprocfs_obd_cleanup(obd);
595         lprocfs_free_obd_stats(obd);
596
597         ldlm_lock_decref(&obd->u.echo.eo_nl_lock, LCK_NL);
598
599         /* XXX Bug 3413; wait for a bit to ensure the BL callback has
600          * happened before calling ldlm_namespace_free() */
601         cfs_schedule_timeout_and_set_state(CFS_TASK_UNINT, cfs_time_seconds(1));
602
603         ldlm_namespace_free(obd->obd_namespace, NULL, obd->obd_force);
604         obd->obd_namespace = NULL;
605
606         leaked = cfs_atomic_read(&obd->u.echo.eo_prep);
607         if (leaked != 0)
608                 CERROR("%d prep/commitrw pages leaked\n", leaked);
609
610         RETURN(0);
611 }
612
613 static struct obd_ops echo_obd_ops = {
614         .o_owner           = THIS_MODULE,
615         .o_connect         = echo_connect,
616         .o_disconnect      = echo_disconnect,
617         .o_init_export     = echo_init_export,
618         .o_destroy_export  = echo_destroy_export,
619         .o_create          = echo_create,
620         .o_destroy         = echo_destroy,
621         .o_getattr         = echo_getattr,
622         .o_setattr         = echo_setattr,
623         .o_preprw          = echo_preprw,
624         .o_commitrw        = echo_commitrw,
625         .o_setup           = echo_setup,
626         .o_cleanup         = echo_cleanup
627 };
628
629 extern int echo_client_init(void);
630 extern void echo_client_exit(void);
631
632 static void
633 echo_persistent_pages_fini (void)
634 {
635         int     i;
636
637         for (i = 0; i < ECHO_PERSISTENT_PAGES; i++)
638                 if (echo_persistent_pages[i] != NULL) {
639                         OBD_PAGE_FREE(echo_persistent_pages[i]);
640                         echo_persistent_pages[i] = NULL;
641                 }
642 }
643
644 static int
645 echo_persistent_pages_init (void)
646 {
647         cfs_page_t *pg;
648         int          i;
649
650         for (i = 0; i < ECHO_PERSISTENT_PAGES; i++) {
651                 int gfp_mask = (i < ECHO_PERSISTENT_PAGES/2) ?
652                         CFS_ALLOC_STD : CFS_ALLOC_HIGHUSER;
653
654                 OBD_PAGE_ALLOC(pg, gfp_mask);
655                 if (pg == NULL) {
656                         echo_persistent_pages_fini ();
657                         return (-ENOMEM);
658                 }
659
660                 memset (cfs_kmap (pg), 0, CFS_PAGE_SIZE);
661                 cfs_kunmap (pg);
662
663                 echo_persistent_pages[i] = pg;
664         }
665
666         return (0);
667 }
668
669 static int __init obdecho_init(void)
670 {
671         struct lprocfs_static_vars lvars;
672         int rc;
673
674         ENTRY;
675         LCONSOLE_INFO("Echo OBD driver; http://www.lustre.org/\n");
676
677         LASSERT(CFS_PAGE_SIZE % OBD_ECHO_BLOCK_SIZE == 0);
678
679         lprocfs_echo_init_vars(&lvars);
680
681         rc = echo_persistent_pages_init ();
682         if (rc != 0)
683                 goto failed_0;
684
685         rc = class_register_type(&echo_obd_ops, NULL, lvars.module_vars,
686                                  LUSTRE_ECHO_NAME, NULL);
687         if (rc != 0)
688                 goto failed_1;
689
690         rc = echo_client_init();
691         if (rc == 0)
692                 RETURN (0);
693
694         class_unregister_type(LUSTRE_ECHO_NAME);
695  failed_1:
696         echo_persistent_pages_fini ();
697  failed_0:
698         RETURN(rc);
699 }
700
701 static void /*__exit*/ obdecho_exit(void)
702 {
703         echo_client_exit();
704         class_unregister_type(LUSTRE_ECHO_NAME);
705         echo_persistent_pages_fini ();
706 }
707
708 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
709 MODULE_DESCRIPTION("Lustre Testing Echo OBD driver");
710 MODULE_LICENSE("GPL");
711
712 cfs_module(obdecho, "1.0.0", obdecho_init, obdecho_exit);