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