Whamcloud - gitweb
LU-6068 misc: update Intel copyright messages 2014
[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, 2014, Intel Corporation.
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 >> PAGE_CACHE_SHIFT)
58 static struct page *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         u64 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 obd_trans_info *oti)
120 {
121         struct obd_device *obd = class_exp2obd(exp);
122
123         if (!obd) {
124                 CERROR("invalid client cookie "LPX64"\n",
125                        exp->exp_handle.h_cookie);
126                 return -EINVAL;
127         }
128
129         if (!(oa->o_mode & S_IFMT)) {
130                 CERROR("echo obd: no type!\n");
131                 return -ENOENT;
132         }
133
134         if (!(oa->o_valid & OBD_MD_FLTYPE)) {
135                 CERROR("invalid o_valid "LPX64"\n", oa->o_valid);
136                 return -EINVAL;
137         }
138
139         ostid_set_seq_echo(&oa->o_oi);
140         ostid_set_id(&oa->o_oi, 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 obd_trans_info *oti)
148 {
149         struct obd_device *obd = class_exp2obd(exp);
150
151         ENTRY;
152         if (!obd) {
153                 CERROR("invalid client cookie "LPX64"\n",
154                        exp->exp_handle.h_cookie);
155                 RETURN(-EINVAL);
156         }
157
158         if (!(oa->o_valid & OBD_MD_FLID)) {
159                 CERROR("obdo missing FLID valid flag: "LPX64"\n", oa->o_valid);
160                 RETURN(-EINVAL);
161         }
162
163         if (ostid_id(&oa->o_oi) > obd->u.echo.eo_lastino ||
164             ostid_id(&oa->o_oi) < ECHO_INIT_OID) {
165                 CERROR("bad destroy objid: "DOSTID"\n", POSTID(&oa->o_oi));
166                 RETURN(-EINVAL);
167         }
168
169         RETURN(0);
170 }
171
172 static int echo_getattr(const struct lu_env *env, struct obd_export *exp,
173                         struct obd_info *oinfo)
174 {
175         struct obd_device *obd = class_exp2obd(exp);
176         u64 id = ostid_id(&oinfo->oi_oa->o_oi);
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         ostid_set_seq_echo(&oinfo->oi_oa->o_oi);
193         ostid_set_id(&oinfo->oi_oa->o_oi, 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 (ostid_id(&oinfo->oi_oa->o_oi) & 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(struct page *page, int rw, u64 id,
230                       __u64 offset, int len)
231 {
232         int   page_offset = offset & ~CFS_PAGE_MASK;
233         char *addr        = ((char *)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         kunmap(page);
253 }
254
255 static int
256 echo_page_debug_check(struct page *page, u64 id,
257                       __u64 offset, int len)
258 {
259         int   page_offset = offset & ~CFS_PAGE_MASK;
260         char *addr        = ((char *)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         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         gfp_t gfp_mask = (ostid_id(&obj->ioo_oid) & 1) ?
292                         GFP_HIGHUSER : GFP_IOFS;
293         int ispersistent = ostid_id(&obj->ioo_oid) == 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         u64 offset = nb->rnb_offset;
299         int len = nb->rnb_len;
300
301         while (len > 0) {
302                 int plen = PAGE_CACHE_SIZE - (offset & (PAGE_CACHE_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->lnb_file_offset = offset;
311                 res->lnb_len = plen;
312                 LASSERT((res->lnb_file_offset & ~CFS_PAGE_MASK) +
313                         res->lnb_len <= PAGE_CACHE_SIZE);
314
315                 if (ispersistent &&
316                     ((res->lnb_file_offset >> PAGE_CACHE_SHIFT) <
317                       ECHO_PERSISTENT_PAGES)) {
318                         res->lnb_page =
319                                 echo_persistent_pages[res->lnb_file_offset >>
320                                                       PAGE_CACHE_SHIFT];
321                         /* Take extra ref so __free_pages() can be called OK */
322                         get_page(res->lnb_page);
323                 } else {
324                         OBD_PAGE_ALLOC(res->lnb_page, gfp_mask);
325                         if (res->lnb_page == NULL) {
326                                 CERROR("can't get page for id " DOSTID"\n",
327                                        POSTID(&obj->ioo_oid));
328                                 return -ENOMEM;
329                         }
330                 }
331
332                 CDEBUG(D_PAGE, "$$$$ get page %p @ "LPU64" for %d\n",
333                        res->lnb_page, res->lnb_file_offset, res->lnb_len);
334
335                 if (cmd & OBD_BRW_READ)
336                         res->lnb_rc = res->lnb_len;
337
338                 if (debug_setup)
339                         echo_page_debug_setup(res->lnb_page, cmd,
340                                               ostid_id(&obj->ioo_oid),
341                                               res->lnb_file_offset,
342                                               res->lnb_len);
343
344                 offset += plen;
345                 len -= plen;
346                 res++;
347
348                 (*left)--;
349                 (*pages)++;
350         }
351
352         return 0;
353 }
354
355 static int echo_finalize_lb(struct obdo *oa, struct obd_ioobj *obj,
356                             struct niobuf_remote *rb, int *pgs,
357                             struct niobuf_local *lb, int verify)
358 {
359         struct niobuf_local *res = lb;
360         u64 start = rb->rnb_offset >> PAGE_CACHE_SHIFT;
361         u64 end   = (rb->rnb_offset + rb->rnb_len + PAGE_CACHE_SIZE - 1) >>
362                     PAGE_CACHE_SHIFT;
363         int     count  = (int)(end - start);
364         int     rc     = 0;
365         int     i;
366
367         for (i = 0; i < count; i++, (*pgs) ++, res++) {
368                 struct page *page = res->lnb_page;
369                 void       *addr;
370
371                 if (page == NULL) {
372                         CERROR("null page objid "LPU64":%p, buf %d/%d\n",
373                                ostid_id(&obj->ioo_oid), page, i,
374                                obj->ioo_bufcnt);
375                         return -EFAULT;
376                 }
377
378                 addr = kmap(page);
379
380                 CDEBUG(D_PAGE, "$$$$ use page %p, addr %p@"LPU64"\n",
381                        res->lnb_page, addr, res->lnb_file_offset);
382
383                 if (verify) {
384                         int vrc = echo_page_debug_check(page,
385                                                         ostid_id(&obj->ioo_oid),
386                                                         res->lnb_file_offset,
387                                                         res->lnb_len);
388                         /* check all the pages always */
389                         if (vrc != 0 && rc == 0)
390                                 rc = vrc;
391                 }
392
393                 kunmap(page);
394                 /* NB see comment above regarding persistent pages */
395                 OBD_PAGE_FREE(page);
396         }
397
398         return rc;
399 }
400
401 static int echo_preprw(const struct lu_env *env, int cmd,
402                        struct obd_export *export, struct obdo *oa,
403                        int objcount, struct obd_ioobj *obj,
404                        struct niobuf_remote *nb, int *pages,
405                        struct niobuf_local *res, struct obd_trans_info *oti,
406                        struct lustre_capa *unused)
407 {
408         struct obd_device *obd;
409         int tot_bytes = 0;
410         int rc = 0;
411         int i, left;
412         ENTRY;
413
414         obd = export->exp_obd;
415         if (obd == NULL)
416                 RETURN(-EINVAL);
417
418         /* Temp fix to stop falling foul of osc_announce_cached() */
419         oa->o_valid &= ~(OBD_MD_FLBLOCKS | OBD_MD_FLGRANT);
420
421         memset(res, 0, sizeof(*res) * *pages);
422
423         CDEBUG(D_PAGE, "%s %d obdos with %d IOs\n",
424                cmd == OBD_BRW_READ ? "reading" : "writing", objcount, *pages);
425
426         if (oti)
427                 oti->oti_handle = (void *)DESC_PRIV;
428
429         left = *pages;
430         *pages = 0;
431
432         for (i = 0; i < objcount; i++, obj++) {
433                 int j;
434
435                 for (j = 0 ; j < obj->ioo_bufcnt ; j++, nb++) {
436
437                         rc = echo_map_nb_to_lb(oa, obj, nb, pages,
438                                                res + *pages, cmd, &left);
439                         if (rc)
440                                 GOTO(preprw_cleanup, rc);
441
442                         tot_bytes += nb->rnb_len;
443                 }
444         }
445
446         atomic_add(*pages, &obd->u.echo.eo_prep);
447
448         if (cmd & OBD_BRW_READ)
449                 lprocfs_counter_add(obd->obd_stats, LPROC_ECHO_READ_BYTES,
450                                     tot_bytes);
451         else
452                 lprocfs_counter_add(obd->obd_stats, LPROC_ECHO_WRITE_BYTES,
453                                     tot_bytes);
454
455         CDEBUG(D_PAGE, "%d pages allocated after prep\n",
456                atomic_read(&obd->u.echo.eo_prep));
457
458         RETURN(0);
459
460 preprw_cleanup:
461         /* It is possible that we would rather handle errors by  allow
462          * any already-set-up pages to complete, rather than tearing them
463          * all down again.  I believe that this is what the in-kernel
464          * prep/commit operations do.
465          */
466         CERROR("cleaning up %u pages (%d obdos)\n", *pages, objcount);
467         for (i = 0; i < *pages; i++) {
468                 kunmap(res[i].lnb_page);
469                 /* NB if this is a persistent page, __free_pages will just
470                  * lose the extra ref gained above */
471                 OBD_PAGE_FREE(res[i].lnb_page);
472                 res[i].lnb_page = NULL;
473                 atomic_dec(&obd->u.echo.eo_prep);
474         }
475
476         return rc;
477 }
478
479 static int echo_commitrw(const struct lu_env *env, int cmd,
480                          struct obd_export *export, struct obdo *oa,
481                          int objcount, struct obd_ioobj *obj,
482                          struct niobuf_remote *rb, int niocount,
483                          struct niobuf_local *res, struct obd_trans_info *oti,
484                          int rc)
485 {
486         struct obd_device *obd;
487         int pgs = 0;
488         int i;
489         ENTRY;
490
491         obd = export->exp_obd;
492         if (obd == NULL)
493                 RETURN(-EINVAL);
494
495         if (rc)
496                 GOTO(commitrw_cleanup, rc);
497
498         if ((cmd & OBD_BRW_RWMASK) == OBD_BRW_READ) {
499                 CDEBUG(D_PAGE, "reading %d obdos with %d IOs\n",
500                        objcount, niocount);
501         } else {
502                 CDEBUG(D_PAGE, "writing %d obdos with %d IOs\n",
503                        objcount, niocount);
504         }
505
506         if (niocount && res == NULL) {
507                 CERROR("NULL res niobuf with niocount %d\n", niocount);
508                 RETURN(-EINVAL);
509         }
510
511         LASSERT(oti == NULL || oti->oti_handle == (void *)DESC_PRIV);
512
513         for (i = 0; i < objcount; i++, obj++) {
514                 int verify = (rc == 0 &&
515                              ostid_id(&obj->ioo_oid) != ECHO_PERSISTENT_OBJID &&
516                               (oa->o_valid & OBD_MD_FLFLAGS) != 0 &&
517                               (oa->o_flags & OBD_FL_DEBUG_CHECK) != 0);
518                 int j;
519
520                 for (j = 0 ; j < obj->ioo_bufcnt ; j++, rb++) {
521                         int vrc = echo_finalize_lb(oa, obj, rb, &pgs, &res[pgs],
522                                                    verify);
523                         if (vrc == 0)
524                                 continue;
525
526                         if (vrc == -EFAULT)
527                                 GOTO(commitrw_cleanup, rc = vrc);
528
529                         if (rc == 0)
530                                 rc = vrc;
531                 }
532
533         }
534
535         atomic_sub(pgs, &obd->u.echo.eo_prep);
536
537         CDEBUG(D_PAGE, "%d pages remain after commit\n",
538                atomic_read(&obd->u.echo.eo_prep));
539         RETURN(rc);
540
541 commitrw_cleanup:
542         atomic_sub(pgs, &obd->u.echo.eo_prep);
543
544         CERROR("cleaning up %d pages (%d obdos)\n",
545                niocount - pgs - 1, objcount);
546
547         while (pgs < niocount) {
548                 struct page *page = res[pgs++].lnb_page;
549
550                 if (page == NULL)
551                         continue;
552
553                 /* NB see comment above regarding persistent pages */
554                 OBD_PAGE_FREE(page);
555                 atomic_dec(&obd->u.echo.eo_prep);
556         }
557         return rc;
558 }
559
560 LPROC_SEQ_FOPS_RO_TYPE(echo, uuid);
561 static struct lprocfs_seq_vars lprocfs_echo_obd_vars[] = {
562         { .name =       "uuid",
563           .fops =       &echo_uuid_fops         },
564         { 0 }
565 };
566
567 static int echo_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
568 {
569         int                     rc;
570         __u64                   lock_flags = 0;
571         struct ldlm_res_id      res_id = {.name = {1}};
572         char                    ns_name[48];
573         ENTRY;
574
575         obd->u.echo.eo_obt.obt_magic = OBT_MAGIC;
576         spin_lock_init(&obd->u.echo.eo_lock);
577         obd->u.echo.eo_lastino = ECHO_INIT_OID;
578
579         sprintf(ns_name, "echotgt-%s", obd->obd_uuid.uuid);
580         obd->obd_namespace = ldlm_namespace_new(obd, ns_name,
581                                                 LDLM_NAMESPACE_SERVER,
582                                                 LDLM_NAMESPACE_MODEST,
583                                                 LDLM_NS_TYPE_OST);
584         if (obd->obd_namespace == NULL) {
585                 LBUG();
586                 RETURN(-ENOMEM);
587         }
588
589         rc = ldlm_cli_enqueue_local(obd->obd_namespace, &res_id, LDLM_PLAIN,
590                                     NULL, LCK_NL, &lock_flags, NULL,
591                                     ldlm_completion_ast, NULL, NULL, 0,
592                                     LVB_T_NONE, NULL, &obd->u.echo.eo_nl_lock);
593         LASSERT (rc == ELDLM_OK);
594
595         obd->obd_vars = lprocfs_echo_obd_vars;
596         if (lprocfs_obd_setup(obd) == 0 &&
597             lprocfs_alloc_obd_stats(obd, LPROC_ECHO_LAST) == 0) {
598                 lprocfs_counter_init(obd->obd_stats, LPROC_ECHO_READ_BYTES,
599                                      LPROCFS_CNTR_AVGMINMAX,
600                                      "read_bytes", "bytes");
601                 lprocfs_counter_init(obd->obd_stats, LPROC_ECHO_WRITE_BYTES,
602                                      LPROCFS_CNTR_AVGMINMAX,
603                                      "write_bytes", "bytes");
604         }
605
606         ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
607                            "echo_ldlm_cb_client", &obd->obd_ldlm_client);
608         RETURN(0);
609 }
610
611 static int echo_cleanup(struct obd_device *obd)
612 {
613         int leaked;
614         ENTRY;
615
616         lprocfs_obd_cleanup(obd);
617         lprocfs_free_obd_stats(obd);
618
619         ldlm_lock_decref(&obd->u.echo.eo_nl_lock, LCK_NL);
620
621         /* XXX Bug 3413; wait for a bit to ensure the BL callback has
622          * happened before calling ldlm_namespace_free() */
623         schedule_timeout_and_set_state(TASK_UNINTERRUPTIBLE, cfs_time_seconds(1));
624
625         ldlm_namespace_free(obd->obd_namespace, NULL, obd->obd_force);
626         obd->obd_namespace = NULL;
627
628         leaked = atomic_read(&obd->u.echo.eo_prep);
629         if (leaked != 0)
630                 CERROR("%d prep/commitrw pages leaked\n", leaked);
631
632         RETURN(0);
633 }
634
635 struct obd_ops echo_obd_ops = {
636         .o_owner           = THIS_MODULE,
637         .o_connect         = echo_connect,
638         .o_disconnect      = echo_disconnect,
639         .o_init_export     = echo_init_export,
640         .o_destroy_export  = echo_destroy_export,
641         .o_create          = echo_create,
642         .o_destroy         = echo_destroy,
643         .o_getattr         = echo_getattr,
644         .o_setattr         = echo_setattr,
645         .o_preprw          = echo_preprw,
646         .o_commitrw        = echo_commitrw,
647         .o_setup           = echo_setup,
648         .o_cleanup         = echo_cleanup
649 };
650
651 void echo_persistent_pages_fini(void)
652 {
653         int     i;
654
655         for (i = 0; i < ECHO_PERSISTENT_PAGES; i++)
656                 if (echo_persistent_pages[i] != NULL) {
657                         OBD_PAGE_FREE(echo_persistent_pages[i]);
658                         echo_persistent_pages[i] = NULL;
659                 }
660 }
661
662 int echo_persistent_pages_init(void)
663 {
664         struct page *pg;
665         int          i;
666
667         for (i = 0; i < ECHO_PERSISTENT_PAGES; i++) {
668                 gfp_t gfp_mask = (i < ECHO_PERSISTENT_PAGES/2) ?
669                         GFP_IOFS : GFP_HIGHUSER;
670
671                 OBD_PAGE_ALLOC(pg, gfp_mask);
672                 if (pg == NULL) {
673                         echo_persistent_pages_fini();
674                         return -ENOMEM;
675                 }
676
677                 memset (kmap (pg), 0, PAGE_CACHE_SIZE);
678                 kunmap (pg);
679
680                 echo_persistent_pages[i] = pg;
681         }
682
683         return 0;
684 }