Whamcloud - gitweb
LU-5418 echo: replace lov_stripe_md with lov_oinfo
[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, 2013, 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         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 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 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 (ostid_id(&oa->o_oi) > obd->u.echo.eo_lastino ||
166             ostid_id(&oa->o_oi) < ECHO_INIT_OID) {
167                 CERROR("bad destroy objid: "DOSTID"\n", POSTID(&oa->o_oi));
168                 RETURN(-EINVAL);
169         }
170
171         RETURN(0);
172 }
173
174 static int echo_getattr(const struct lu_env *env, struct obd_export *exp,
175                         struct obd_info *oinfo)
176 {
177         struct obd_device *obd = class_exp2obd(exp);
178         obd_id id = ostid_id(&oinfo->oi_oa->o_oi);
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         ostid_set_seq_echo(&oinfo->oi_oa->o_oi);
195         ostid_set_id(&oinfo->oi_oa->o_oi, id);
196
197         RETURN(0);
198 }
199
200 static int echo_setattr(const struct lu_env *env, struct obd_export *exp,
201                         struct obd_info *oinfo, struct obd_trans_info *oti)
202 {
203         struct obd_device *obd = class_exp2obd(exp);
204
205         ENTRY;
206         if (!obd) {
207                 CERROR("invalid client cookie "LPX64"\n",
208                        exp->exp_handle.h_cookie);
209                 RETURN(-EINVAL);
210         }
211
212         if (!(oinfo->oi_oa->o_valid & OBD_MD_FLID)) {
213                 CERROR("obdo missing FLID valid flag: "LPX64"\n",
214                        oinfo->oi_oa->o_valid);
215                 RETURN(-EINVAL);
216         }
217
218         memcpy(&obd->u.echo.eo_oa, oinfo->oi_oa, sizeof(*oinfo->oi_oa));
219
220         if (ostid_id(&oinfo->oi_oa->o_oi) & 4) {
221                 /* Save lock to force ACKed reply */
222                 ldlm_lock_addref (&obd->u.echo.eo_nl_lock, LCK_NL);
223                 oti->oti_ack_locks[0].mode = LCK_NL;
224                 oti->oti_ack_locks[0].lock = obd->u.echo.eo_nl_lock;
225         }
226
227         RETURN(0);
228 }
229
230 static void
231 echo_page_debug_setup(struct page *page, int rw, obd_id id,
232                       __u64 offset, int len)
233 {
234         int   page_offset = offset & ~CFS_PAGE_MASK;
235         char *addr        = ((char *)kmap(page)) + page_offset;
236
237         if (len % OBD_ECHO_BLOCK_SIZE != 0)
238                 CERROR("Unexpected block size %d\n", len);
239
240         while (len > 0) {
241                 if (rw & OBD_BRW_READ)
242                         block_debug_setup(addr, OBD_ECHO_BLOCK_SIZE,
243                                           offset, id);
244                 else
245                         block_debug_setup(addr, OBD_ECHO_BLOCK_SIZE,
246                                           0xecc0ecc0ecc0ecc0ULL,
247                                           0xecc0ecc0ecc0ecc0ULL);
248
249                 addr   += OBD_ECHO_BLOCK_SIZE;
250                 offset += OBD_ECHO_BLOCK_SIZE;
251                 len    -= OBD_ECHO_BLOCK_SIZE;
252         }
253
254         kunmap(page);
255 }
256
257 static int
258 echo_page_debug_check(struct page *page, obd_id id,
259                       __u64 offset, int len)
260 {
261         int   page_offset = offset & ~CFS_PAGE_MASK;
262         char *addr        = ((char *)kmap(page)) + page_offset;
263         int   rc          = 0;
264         int   rc2;
265
266         if (len % OBD_ECHO_BLOCK_SIZE != 0)
267                 CERROR("Unexpected block size %d\n", len);
268
269         while (len > 0) {
270                 rc2 = block_debug_check("echo", addr, OBD_ECHO_BLOCK_SIZE,
271                                         offset, id);
272
273                 if (rc2 != 0 && rc == 0)
274                         rc = rc2;
275
276                 addr   += OBD_ECHO_BLOCK_SIZE;
277                 offset += OBD_ECHO_BLOCK_SIZE;
278                 len    -= OBD_ECHO_BLOCK_SIZE;
279         }
280
281         kunmap(page);
282
283         return rc;
284 }
285
286 /* This allows us to verify that desc_private is passed unmolested */
287 #define DESC_PRIV 0x10293847
288
289 static int echo_map_nb_to_lb(struct obdo *oa, struct obd_ioobj *obj,
290                              struct niobuf_remote *nb, int *pages,
291                              struct niobuf_local *lb, int cmd, int *left)
292 {
293         gfp_t gfp_mask = (ostid_id(&obj->ioo_oid) & 1) ?
294                         GFP_HIGHUSER : GFP_IOFS;
295         int ispersistent = ostid_id(&obj->ioo_oid) == ECHO_PERSISTENT_OBJID;
296         int debug_setup = (!ispersistent &&
297                            (oa->o_valid & OBD_MD_FLFLAGS) != 0 &&
298                            (oa->o_flags & OBD_FL_DEBUG_CHECK) != 0);
299         struct niobuf_local *res = lb;
300         obd_off offset = nb->rnb_offset;
301         int len = nb->rnb_len;
302
303         while (len > 0) {
304                 int plen = PAGE_CACHE_SIZE - (offset & (PAGE_CACHE_SIZE-1));
305                 if (len < plen)
306                         plen = len;
307
308                 /* check for local buf overflow */
309                 if (*left == 0)
310                         return -EINVAL;
311
312                 res->lnb_file_offset = offset;
313                 res->lnb_len = plen;
314                 LASSERT((res->lnb_file_offset & ~CFS_PAGE_MASK) +
315                         res->lnb_len <= PAGE_CACHE_SIZE);
316
317                 if (ispersistent &&
318                     ((res->lnb_file_offset >> PAGE_CACHE_SHIFT) <
319                       ECHO_PERSISTENT_PAGES)) {
320                         res->lnb_page =
321                                 echo_persistent_pages[res->lnb_file_offset >>
322                                                       PAGE_CACHE_SHIFT];
323                         /* Take extra ref so __free_pages() can be called OK */
324                         get_page(res->lnb_page);
325                 } else {
326                         OBD_PAGE_ALLOC(res->lnb_page, gfp_mask);
327                         if (res->lnb_page == NULL) {
328                                 CERROR("can't get page for id " DOSTID"\n",
329                                        POSTID(&obj->ioo_oid));
330                                 return -ENOMEM;
331                         }
332                 }
333
334                 CDEBUG(D_PAGE, "$$$$ get page %p @ "LPU64" for %d\n",
335                        res->lnb_page, res->lnb_file_offset, res->lnb_len);
336
337                 if (cmd & OBD_BRW_READ)
338                         res->lnb_rc = res->lnb_len;
339
340                 if (debug_setup)
341                         echo_page_debug_setup(res->lnb_page, cmd,
342                                               ostid_id(&obj->ioo_oid),
343                                               res->lnb_file_offset,
344                                               res->lnb_len);
345
346                 offset += plen;
347                 len -= plen;
348                 res++;
349
350                 (*left)--;
351                 (*pages)++;
352         }
353
354         return 0;
355 }
356
357 static int echo_finalize_lb(struct obdo *oa, struct obd_ioobj *obj,
358                             struct niobuf_remote *rb, int *pgs,
359                             struct niobuf_local *lb, int verify)
360 {
361         struct niobuf_local *res = lb;
362         obd_off start  = rb->rnb_offset >> PAGE_CACHE_SHIFT;
363         obd_off end    = (rb->rnb_offset + rb->rnb_len + PAGE_CACHE_SIZE - 1) >>
364                          PAGE_CACHE_SHIFT;
365         int     count  = (int)(end - start);
366         int     rc     = 0;
367         int     i;
368
369         for (i = 0; i < count; i++, (*pgs) ++, res++) {
370                 struct page *page = res->lnb_page;
371                 void       *addr;
372
373                 if (page == NULL) {
374                         CERROR("null page objid "LPU64":%p, buf %d/%d\n",
375                                ostid_id(&obj->ioo_oid), page, i,
376                                obj->ioo_bufcnt);
377                         return -EFAULT;
378                 }
379
380                 addr = kmap(page);
381
382                 CDEBUG(D_PAGE, "$$$$ use page %p, addr %p@"LPU64"\n",
383                        res->lnb_page, addr, res->lnb_file_offset);
384
385                 if (verify) {
386                         int vrc = echo_page_debug_check(page,
387                                                         ostid_id(&obj->ioo_oid),
388                                                         res->lnb_file_offset,
389                                                         res->lnb_len);
390                         /* check all the pages always */
391                         if (vrc != 0 && rc == 0)
392                                 rc = vrc;
393                 }
394
395                 kunmap(page);
396                 /* NB see comment above regarding persistent pages */
397                 OBD_PAGE_FREE(page);
398         }
399
400         return rc;
401 }
402
403 static int echo_preprw(const struct lu_env *env, int cmd,
404                        struct obd_export *export, struct obdo *oa,
405                        int objcount, struct obd_ioobj *obj,
406                        struct niobuf_remote *nb, int *pages,
407                        struct niobuf_local *res, struct obd_trans_info *oti,
408                        struct lustre_capa *unused)
409 {
410         struct obd_device *obd;
411         int tot_bytes = 0;
412         int rc = 0;
413         int i, left;
414         ENTRY;
415
416         obd = export->exp_obd;
417         if (obd == NULL)
418                 RETURN(-EINVAL);
419
420         /* Temp fix to stop falling foul of osc_announce_cached() */
421         oa->o_valid &= ~(OBD_MD_FLBLOCKS | OBD_MD_FLGRANT);
422
423         memset(res, 0, sizeof(*res) * *pages);
424
425         CDEBUG(D_PAGE, "%s %d obdos with %d IOs\n",
426                cmd == OBD_BRW_READ ? "reading" : "writing", objcount, *pages);
427
428         if (oti)
429                 oti->oti_handle = (void *)DESC_PRIV;
430
431         left = *pages;
432         *pages = 0;
433
434         for (i = 0; i < objcount; i++, obj++) {
435                 int j;
436
437                 for (j = 0 ; j < obj->ioo_bufcnt ; j++, nb++) {
438
439                         rc = echo_map_nb_to_lb(oa, obj, nb, pages,
440                                                res + *pages, cmd, &left);
441                         if (rc)
442                                 GOTO(preprw_cleanup, rc);
443
444                         tot_bytes += nb->rnb_len;
445                 }
446         }
447
448         atomic_add(*pages, &obd->u.echo.eo_prep);
449
450         if (cmd & OBD_BRW_READ)
451                 lprocfs_counter_add(obd->obd_stats, LPROC_ECHO_READ_BYTES,
452                                     tot_bytes);
453         else
454                 lprocfs_counter_add(obd->obd_stats, LPROC_ECHO_WRITE_BYTES,
455                                     tot_bytes);
456
457         CDEBUG(D_PAGE, "%d pages allocated after prep\n",
458                atomic_read(&obd->u.echo.eo_prep));
459
460         RETURN(0);
461
462 preprw_cleanup:
463         /* It is possible that we would rather handle errors by  allow
464          * any already-set-up pages to complete, rather than tearing them
465          * all down again.  I believe that this is what the in-kernel
466          * prep/commit operations do.
467          */
468         CERROR("cleaning up %u pages (%d obdos)\n", *pages, objcount);
469         for (i = 0; i < *pages; i++) {
470                 kunmap(res[i].lnb_page);
471                 /* NB if this is a persistent page, __free_pages will just
472                  * lose the extra ref gained above */
473                 OBD_PAGE_FREE(res[i].lnb_page);
474                 res[i].lnb_page = NULL;
475                 atomic_dec(&obd->u.echo.eo_prep);
476         }
477
478         return rc;
479 }
480
481 static int echo_commitrw(const struct lu_env *env, int cmd,
482                          struct obd_export *export, struct obdo *oa,
483                          int objcount, struct obd_ioobj *obj,
484                          struct niobuf_remote *rb, int niocount,
485                          struct niobuf_local *res, struct obd_trans_info *oti,
486                          int rc)
487 {
488         struct obd_device *obd;
489         int pgs = 0;
490         int i;
491         ENTRY;
492
493         obd = export->exp_obd;
494         if (obd == NULL)
495                 RETURN(-EINVAL);
496
497         if (rc)
498                 GOTO(commitrw_cleanup, rc);
499
500         if ((cmd & OBD_BRW_RWMASK) == OBD_BRW_READ) {
501                 CDEBUG(D_PAGE, "reading %d obdos with %d IOs\n",
502                        objcount, niocount);
503         } else {
504                 CDEBUG(D_PAGE, "writing %d obdos with %d IOs\n",
505                        objcount, niocount);
506         }
507
508         if (niocount && res == NULL) {
509                 CERROR("NULL res niobuf with niocount %d\n", niocount);
510                 RETURN(-EINVAL);
511         }
512
513         LASSERT(oti == NULL || oti->oti_handle == (void *)DESC_PRIV);
514
515         for (i = 0; i < objcount; i++, obj++) {
516                 int verify = (rc == 0 &&
517                              ostid_id(&obj->ioo_oid) != ECHO_PERSISTENT_OBJID &&
518                               (oa->o_valid & OBD_MD_FLFLAGS) != 0 &&
519                               (oa->o_flags & OBD_FL_DEBUG_CHECK) != 0);
520                 int j;
521
522                 for (j = 0 ; j < obj->ioo_bufcnt ; j++, rb++) {
523                         int vrc = echo_finalize_lb(oa, obj, rb, &pgs, &res[pgs],
524                                                    verify);
525                         if (vrc == 0)
526                                 continue;
527
528                         if (vrc == -EFAULT)
529                                 GOTO(commitrw_cleanup, rc = vrc);
530
531                         if (rc == 0)
532                                 rc = vrc;
533                 }
534
535         }
536
537         atomic_sub(pgs, &obd->u.echo.eo_prep);
538
539         CDEBUG(D_PAGE, "%d pages remain after commit\n",
540                atomic_read(&obd->u.echo.eo_prep));
541         RETURN(rc);
542
543 commitrw_cleanup:
544         atomic_sub(pgs, &obd->u.echo.eo_prep);
545
546         CERROR("cleaning up %d pages (%d obdos)\n",
547                niocount - pgs - 1, objcount);
548
549         while (pgs < niocount) {
550                 struct page *page = res[pgs++].lnb_page;
551
552                 if (page == NULL)
553                         continue;
554
555                 /* NB see comment above regarding persistent pages */
556                 OBD_PAGE_FREE(page);
557                 atomic_dec(&obd->u.echo.eo_prep);
558         }
559         return rc;
560 }
561
562 LPROC_SEQ_FOPS_RO_TYPE(echo, uuid);
563 static struct lprocfs_seq_vars lprocfs_echo_obd_vars[] = {
564         { .name =       "uuid",
565           .fops =       &echo_uuid_fops         },
566         { 0 }
567 };
568
569 static int echo_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
570 {
571         int                     rc;
572         __u64                   lock_flags = 0;
573         struct ldlm_res_id      res_id = {.name = {1}};
574         char                    ns_name[48];
575         ENTRY;
576
577         obd->u.echo.eo_obt.obt_magic = OBT_MAGIC;
578         spin_lock_init(&obd->u.echo.eo_lock);
579         obd->u.echo.eo_lastino = ECHO_INIT_OID;
580
581         sprintf(ns_name, "echotgt-%s", obd->obd_uuid.uuid);
582         obd->obd_namespace = ldlm_namespace_new(obd, ns_name,
583                                                 LDLM_NAMESPACE_SERVER,
584                                                 LDLM_NAMESPACE_MODEST,
585                                                 LDLM_NS_TYPE_OST);
586         if (obd->obd_namespace == NULL) {
587                 LBUG();
588                 RETURN(-ENOMEM);
589         }
590
591         rc = ldlm_cli_enqueue_local(obd->obd_namespace, &res_id, LDLM_PLAIN,
592                                     NULL, LCK_NL, &lock_flags, NULL,
593                                     ldlm_completion_ast, NULL, NULL, 0,
594                                     LVB_T_NONE, NULL, &obd->u.echo.eo_nl_lock);
595         LASSERT (rc == ELDLM_OK);
596
597         obd->obd_vars = lprocfs_echo_obd_vars;
598         if (lprocfs_obd_setup(obd) == 0 &&
599             lprocfs_alloc_obd_stats(obd, LPROC_ECHO_LAST) == 0) {
600                 lprocfs_counter_init(obd->obd_stats, LPROC_ECHO_READ_BYTES,
601                                      LPROCFS_CNTR_AVGMINMAX,
602                                      "read_bytes", "bytes");
603                 lprocfs_counter_init(obd->obd_stats, LPROC_ECHO_WRITE_BYTES,
604                                      LPROCFS_CNTR_AVGMINMAX,
605                                      "write_bytes", "bytes");
606         }
607
608         ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
609                            "echo_ldlm_cb_client", &obd->obd_ldlm_client);
610         RETURN(0);
611 }
612
613 static int echo_cleanup(struct obd_device *obd)
614 {
615         int leaked;
616         ENTRY;
617
618         lprocfs_obd_cleanup(obd);
619         lprocfs_free_obd_stats(obd);
620
621         ldlm_lock_decref(&obd->u.echo.eo_nl_lock, LCK_NL);
622
623         /* XXX Bug 3413; wait for a bit to ensure the BL callback has
624          * happened before calling ldlm_namespace_free() */
625         schedule_timeout_and_set_state(TASK_UNINTERRUPTIBLE, cfs_time_seconds(1));
626
627         ldlm_namespace_free(obd->obd_namespace, NULL, obd->obd_force);
628         obd->obd_namespace = NULL;
629
630         leaked = atomic_read(&obd->u.echo.eo_prep);
631         if (leaked != 0)
632                 CERROR("%d prep/commitrw pages leaked\n", leaked);
633
634         RETURN(0);
635 }
636
637 struct obd_ops echo_obd_ops = {
638         .o_owner           = THIS_MODULE,
639         .o_connect         = echo_connect,
640         .o_disconnect      = echo_disconnect,
641         .o_init_export     = echo_init_export,
642         .o_destroy_export  = echo_destroy_export,
643         .o_create          = echo_create,
644         .o_destroy         = echo_destroy,
645         .o_getattr         = echo_getattr,
646         .o_setattr         = echo_setattr,
647         .o_preprw          = echo_preprw,
648         .o_commitrw        = echo_commitrw,
649         .o_setup           = echo_setup,
650         .o_cleanup         = echo_cleanup
651 };
652
653 void echo_persistent_pages_fini(void)
654 {
655         int     i;
656
657         for (i = 0; i < ECHO_PERSISTENT_PAGES; i++)
658                 if (echo_persistent_pages[i] != NULL) {
659                         OBD_PAGE_FREE(echo_persistent_pages[i]);
660                         echo_persistent_pages[i] = NULL;
661                 }
662 }
663
664 int echo_persistent_pages_init(void)
665 {
666         struct page *pg;
667         int          i;
668
669         for (i = 0; i < ECHO_PERSISTENT_PAGES; i++) {
670                 gfp_t gfp_mask = (i < ECHO_PERSISTENT_PAGES/2) ?
671                         GFP_IOFS : GFP_HIGHUSER;
672
673                 OBD_PAGE_ALLOC(pg, gfp_mask);
674                 if (pg == NULL) {
675                         echo_persistent_pages_fini();
676                         return -ENOMEM;
677                 }
678
679                 memset (kmap (pg), 0, PAGE_CACHE_SIZE);
680                 kunmap (pg);
681
682                 echo_persistent_pages[i] = pg;
683         }
684
685         return 0;
686 }