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