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