Whamcloud - gitweb
0f02723d0006c1a1df8172e1af496110a8d66e1a
[fs/lustre-release.git] / lustre / obdclass / cl_page.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) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 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  * Client Lustre Page.
37  *
38  *   Author: Nikita Danilov <nikita.danilov@sun.com>
39  *   Author: Jinshan Xiong <jinshan.xiong@intel.com>
40  */
41
42 #define DEBUG_SUBSYSTEM S_CLASS
43
44 #include <libcfs/libcfs.h>
45 #include <obd_class.h>
46 #include <obd_support.h>
47 #include <libcfs/list.h>
48
49 #include <cl_object.h>
50 #include "cl_internal.h"
51
52 static void cl_page_delete0(const struct lu_env *env, struct cl_page *pg);
53
54 #ifdef LIBCFS_DEBUG
55 # define PASSERT(env, page, expr)                                       \
56   do {                                                                    \
57           if (unlikely(!(expr))) {                                      \
58                   CL_PAGE_DEBUG(D_ERROR, (env), (page), #expr "\n");    \
59                   LASSERT(0);                                           \
60           }                                                             \
61   } while (0)
62 #else /* !LIBCFS_DEBUG */
63 # define PASSERT(env, page, exp) \
64         ((void)sizeof(env), (void)sizeof(page), (void)sizeof !!(exp))
65 #endif /* !LIBCFS_DEBUG */
66
67 #ifdef CONFIG_LUSTRE_DEBUG_EXPENSIVE_CHECK
68 # define PINVRNT(env, page, expr)                                       \
69   do {                                                                    \
70           if (unlikely(!(expr))) {                                      \
71                   CL_PAGE_DEBUG(D_ERROR, (env), (page), #expr "\n");    \
72                   LINVRNT(0);                                           \
73           }                                                             \
74   } while (0)
75 #else /* !CONFIG_LUSTRE_DEBUG_EXPENSIVE_CHECK */
76 # define PINVRNT(env, page, exp) \
77          ((void)sizeof(env), (void)sizeof(page), (void)sizeof !!(exp))
78 #endif /* !CONFIG_LUSTRE_DEBUG_EXPENSIVE_CHECK */
79
80 /* Disable page statistic by default due to huge performance penalty. */
81 #ifdef CONFIG_DEBUG_PAGESTATE_TRACKING
82 #define CS_PAGE_INC(o, item) \
83         cfs_atomic_inc(&cl_object_site(o)->cs_pages.cs_stats[CS_##item])
84 #define CS_PAGE_DEC(o, item) \
85         cfs_atomic_dec(&cl_object_site(o)->cs_pages.cs_stats[CS_##item])
86 #define CS_PAGESTATE_INC(o, state) \
87         cfs_atomic_inc(&cl_object_site(o)->cs_pages_state[state])
88 #define CS_PAGESTATE_DEC(o, state) \
89         cfs_atomic_dec(&cl_object_site(o)->cs_pages_state[state])
90 #else
91 #define CS_PAGE_INC(o, item)
92 #define CS_PAGE_DEC(o, item)
93 #define CS_PAGESTATE_INC(o, state)
94 #define CS_PAGESTATE_DEC(o, state)
95 #endif
96
97 /**
98  * Internal version of cl_page_top, it should be called if the page is
99  * known to be not freed, says with page referenced, or radix tree lock held,
100  * or page owned.
101  */
102 static struct cl_page *cl_page_top_trusted(struct cl_page *page)
103 {
104         while (page->cp_parent != NULL)
105                 page = page->cp_parent;
106         return page;
107 }
108
109 /**
110  * Internal version of cl_page_get().
111  *
112  * This function can be used to obtain initial reference to previously
113  * unreferenced cached object. It can be called only if concurrent page
114  * reclamation is somehow prevented, e.g., by keeping a lock on a VM page,
115  * associated with \a page.
116  *
117  * Use with care! Not exported.
118  */
119 static void cl_page_get_trust(struct cl_page *page)
120 {
121         LASSERT(cfs_atomic_read(&page->cp_ref) > 0);
122         cfs_atomic_inc(&page->cp_ref);
123 }
124
125 /**
126  * Returns a slice within a page, corresponding to the given layer in the
127  * device stack.
128  *
129  * \see cl_lock_at()
130  */
131 static const struct cl_page_slice *
132 cl_page_at_trusted(const struct cl_page *page,
133                    const struct lu_device_type *dtype)
134 {
135         const struct cl_page_slice *slice;
136         ENTRY;
137
138         page = cl_page_top_trusted((struct cl_page *)page);
139         do {
140                 cfs_list_for_each_entry(slice, &page->cp_layers, cpl_linkage) {
141                         if (slice->cpl_obj->co_lu.lo_dev->ld_type == dtype)
142                                 RETURN(slice);
143                 }
144                 page = page->cp_child;
145         } while (page != NULL);
146         RETURN(NULL);
147 }
148
149 static void cl_page_free(const struct lu_env *env, struct cl_page *page)
150 {
151         struct cl_object *obj  = page->cp_obj;
152         int pagesize = cl_object_header(obj)->coh_page_bufsize;
153
154         PASSERT(env, page, cfs_list_empty(&page->cp_batch));
155         PASSERT(env, page, page->cp_owner == NULL);
156         PASSERT(env, page, page->cp_req == NULL);
157         PASSERT(env, page, page->cp_parent == NULL);
158         PASSERT(env, page, page->cp_state == CPS_FREEING);
159
160         ENTRY;
161         while (!cfs_list_empty(&page->cp_layers)) {
162                 struct cl_page_slice *slice;
163
164                 slice = cfs_list_entry(page->cp_layers.next,
165                                        struct cl_page_slice, cpl_linkage);
166                 cfs_list_del_init(page->cp_layers.next);
167                 slice->cpl_ops->cpo_fini(env, slice);
168         }
169         CS_PAGE_DEC(obj, total);
170         CS_PAGESTATE_DEC(obj, page->cp_state);
171         lu_object_ref_del_at(&obj->co_lu, &page->cp_obj_ref, "cl_page", page);
172         cl_object_put(env, obj);
173         lu_ref_fini(&page->cp_reference);
174         OBD_FREE(page, pagesize);
175         EXIT;
176 }
177
178 /**
179  * Helper function updating page state. This is the only place in the code
180  * where cl_page::cp_state field is mutated.
181  */
182 static inline void cl_page_state_set_trust(struct cl_page *page,
183                                            enum cl_page_state state)
184 {
185         /* bypass const. */
186         *(enum cl_page_state *)&page->cp_state = state;
187 }
188
189 struct cl_page *cl_page_alloc(const struct lu_env *env,
190                 struct cl_object *o, pgoff_t ind, struct page *vmpage,
191                 enum cl_page_type type)
192 {
193         struct cl_page          *page;
194         struct lu_object_header *head;
195
196         ENTRY;
197         OBD_ALLOC_GFP(page, cl_object_header(o)->coh_page_bufsize,
198                         __GFP_IO);
199         if (page != NULL) {
200                 int result = 0;
201                 cfs_atomic_set(&page->cp_ref, 1);
202                 page->cp_obj = o;
203                 cl_object_get(o);
204                 lu_object_ref_add_at(&o->co_lu, &page->cp_obj_ref, "cl_page",
205                                      page);
206                 page->cp_index = ind;
207                 cl_page_state_set_trust(page, CPS_CACHED);
208                 page->cp_type = type;
209                 CFS_INIT_LIST_HEAD(&page->cp_layers);
210                 CFS_INIT_LIST_HEAD(&page->cp_batch);
211                 CFS_INIT_LIST_HEAD(&page->cp_flight);
212                 mutex_init(&page->cp_mutex);
213                 lu_ref_init(&page->cp_reference);
214                 head = o->co_lu.lo_header;
215                 cfs_list_for_each_entry(o, &head->loh_layers,
216                                         co_lu.lo_linkage) {
217                         if (o->co_ops->coo_page_init != NULL) {
218                                 result = o->co_ops->coo_page_init(env, o,
219                                                                   page, vmpage);
220                                 if (result != 0) {
221                                         cl_page_delete0(env, page);
222                                         cl_page_free(env, page);
223                                         page = ERR_PTR(result);
224                                         break;
225                                 }
226                         }
227                 }
228                 if (result == 0) {
229                         CS_PAGE_INC(o, total);
230                         CS_PAGE_INC(o, create);
231                         CS_PAGESTATE_DEC(o, CPS_CACHED);
232                 }
233         } else {
234                 page = ERR_PTR(-ENOMEM);
235         }
236         RETURN(page);
237 }
238 EXPORT_SYMBOL(cl_page_alloc);
239
240 /**
241  * Returns a cl_page with index \a idx at the object \a o, and associated with
242  * the VM page \a vmpage.
243  *
244  * This is the main entry point into the cl_page caching interface. First, a
245  * cache (implemented as a per-object radix tree) is consulted. If page is
246  * found there, it is returned immediately. Otherwise new page is allocated
247  * and returned. In any case, additional reference to page is acquired.
248  *
249  * \see cl_object_find(), cl_lock_find()
250  */
251 struct cl_page *cl_page_find(const struct lu_env *env,
252                              struct cl_object *o,
253                              pgoff_t idx, struct page *vmpage,
254                              enum cl_page_type type)
255 {
256         struct cl_page          *page = NULL;
257         struct cl_object_header *hdr;
258
259         LASSERT(type == CPT_CACHEABLE || type == CPT_TRANSIENT);
260         might_sleep();
261
262         ENTRY;
263
264         hdr = cl_object_header(o);
265         CS_PAGE_INC(o, lookup);
266
267         CDEBUG(D_PAGE, "%lu@"DFID" %p %lx %d\n",
268                idx, PFID(&hdr->coh_lu.loh_fid), vmpage, vmpage->private, type);
269         /* fast path. */
270         if (type == CPT_CACHEABLE) {
271                 /* vmpage lock is used to protect the child/parent
272                  * relationship */
273                 KLASSERT(PageLocked(vmpage));
274                 /*
275                  * cl_vmpage_page() can be called here without any locks as
276                  *
277                  *     - "vmpage" is locked (which prevents ->private from
278                  *       concurrent updates), and
279                  *
280                  *     - "o" cannot be destroyed while current thread holds a
281                  *       reference on it.
282                  */
283                 page = cl_vmpage_page(vmpage, o);
284                 if (page != NULL) {
285                         CS_PAGE_INC(o, hit);
286                         RETURN(page);
287                 }
288         }
289
290         /* allocate and initialize cl_page */
291         page = cl_page_alloc(env, o, idx, vmpage, type);
292         RETURN(page);
293 }
294 EXPORT_SYMBOL(cl_page_find);
295
296 static inline int cl_page_invariant(const struct cl_page *pg)
297 {
298         struct cl_page          *parent;
299         struct cl_page          *child;
300         struct cl_io            *owner;
301
302         /*
303          * Page invariant is protected by a VM lock.
304          */
305         LINVRNT(cl_page_is_vmlocked(NULL, pg));
306
307         parent = pg->cp_parent;
308         child  = pg->cp_child;
309         owner  = pg->cp_owner;
310
311         return cl_page_in_use_noref(pg) &&
312                 ergo(parent != NULL, parent->cp_child == pg) &&
313                 ergo(child != NULL, child->cp_parent == pg) &&
314                 ergo(child != NULL, pg->cp_obj != child->cp_obj) &&
315                 ergo(parent != NULL, pg->cp_obj != parent->cp_obj) &&
316                 ergo(owner != NULL && parent != NULL,
317                      parent->cp_owner == pg->cp_owner->ci_parent) &&
318                 ergo(owner != NULL && child != NULL,
319                      child->cp_owner->ci_parent == owner);
320 }
321
322 static void cl_page_state_set0(const struct lu_env *env,
323                                struct cl_page *page, enum cl_page_state state)
324 {
325         enum cl_page_state old;
326
327         /*
328          * Matrix of allowed state transitions [old][new], for sanity
329          * checking.
330          */
331         static const int allowed_transitions[CPS_NR][CPS_NR] = {
332                 [CPS_CACHED] = {
333                         [CPS_CACHED]  = 0,
334                         [CPS_OWNED]   = 1, /* io finds existing cached page */
335                         [CPS_PAGEIN]  = 0,
336                         [CPS_PAGEOUT] = 1, /* write-out from the cache */
337                         [CPS_FREEING] = 1, /* eviction on the memory pressure */
338                 },
339                 [CPS_OWNED] = {
340                         [CPS_CACHED]  = 1, /* release to the cache */
341                         [CPS_OWNED]   = 0,
342                         [CPS_PAGEIN]  = 1, /* start read immediately */
343                         [CPS_PAGEOUT] = 1, /* start write immediately */
344                         [CPS_FREEING] = 1, /* lock invalidation or truncate */
345                 },
346                 [CPS_PAGEIN] = {
347                         [CPS_CACHED]  = 1, /* io completion */
348                         [CPS_OWNED]   = 0,
349                         [CPS_PAGEIN]  = 0,
350                         [CPS_PAGEOUT] = 0,
351                         [CPS_FREEING] = 0,
352                 },
353                 [CPS_PAGEOUT] = {
354                         [CPS_CACHED]  = 1, /* io completion */
355                         [CPS_OWNED]   = 0,
356                         [CPS_PAGEIN]  = 0,
357                         [CPS_PAGEOUT] = 0,
358                         [CPS_FREEING] = 0,
359                 },
360                 [CPS_FREEING] = {
361                         [CPS_CACHED]  = 0,
362                         [CPS_OWNED]   = 0,
363                         [CPS_PAGEIN]  = 0,
364                         [CPS_PAGEOUT] = 0,
365                         [CPS_FREEING] = 0,
366                 }
367         };
368
369         ENTRY;
370         old = page->cp_state;
371         PASSERT(env, page, allowed_transitions[old][state]);
372         CL_PAGE_HEADER(D_TRACE, env, page, "%d -> %d\n", old, state);
373         for (; page != NULL; page = page->cp_child) {
374                 PASSERT(env, page, page->cp_state == old);
375                 PASSERT(env, page,
376                         equi(state == CPS_OWNED, page->cp_owner != NULL));
377
378                 CS_PAGESTATE_DEC(page->cp_obj, page->cp_state);
379                 CS_PAGESTATE_INC(page->cp_obj, state);
380                 cl_page_state_set_trust(page, state);
381         }
382         EXIT;
383 }
384
385 static void cl_page_state_set(const struct lu_env *env,
386                               struct cl_page *page, enum cl_page_state state)
387 {
388         cl_page_state_set0(env, page, state);
389 }
390
391 /**
392  * Acquires an additional reference to a page.
393  *
394  * This can be called only by caller already possessing a reference to \a
395  * page.
396  *
397  * \see cl_object_get(), cl_lock_get().
398  */
399 void cl_page_get(struct cl_page *page)
400 {
401         ENTRY;
402         cl_page_get_trust(page);
403         EXIT;
404 }
405 EXPORT_SYMBOL(cl_page_get);
406
407 /**
408  * Releases a reference to a page.
409  *
410  * When last reference is released, page is returned to the cache, unless it
411  * is in cl_page_state::CPS_FREEING state, in which case it is immediately
412  * destroyed.
413  *
414  * \see cl_object_put(), cl_lock_put().
415  */
416 void cl_page_put(const struct lu_env *env, struct cl_page *page)
417 {
418         PASSERT(env, page, cfs_atomic_read(&page->cp_ref) > !!page->cp_parent);
419
420         ENTRY;
421         CL_PAGE_HEADER(D_TRACE, env, page, "%d\n",
422                        cfs_atomic_read(&page->cp_ref));
423
424         if (cfs_atomic_dec_and_test(&page->cp_ref)) {
425                 LASSERT(page->cp_state == CPS_FREEING);
426
427                 LASSERT(cfs_atomic_read(&page->cp_ref) == 0);
428                 PASSERT(env, page, page->cp_owner == NULL);
429                 PASSERT(env, page, cfs_list_empty(&page->cp_batch));
430                 /*
431                  * Page is no longer reachable by other threads. Tear
432                  * it down.
433                  */
434                 cl_page_free(env, page);
435         }
436
437         EXIT;
438 }
439 EXPORT_SYMBOL(cl_page_put);
440
441 /**
442  * Returns a VM page associated with a given cl_page.
443  */
444 struct page *cl_page_vmpage(const struct lu_env *env, struct cl_page *page)
445 {
446         const struct cl_page_slice *slice;
447
448         /*
449          * Find uppermost layer with ->cpo_vmpage() method, and return its
450          * result.
451          */
452         page = cl_page_top(page);
453         do {
454                 cfs_list_for_each_entry(slice, &page->cp_layers, cpl_linkage) {
455                         if (slice->cpl_ops->cpo_vmpage != NULL)
456                                 RETURN(slice->cpl_ops->cpo_vmpage(env, slice));
457                 }
458                 page = page->cp_child;
459         } while (page != NULL);
460         LBUG(); /* ->cpo_vmpage() has to be defined somewhere in the stack */
461 }
462 EXPORT_SYMBOL(cl_page_vmpage);
463
464 /**
465  * Returns a cl_page associated with a VM page, and given cl_object.
466  */
467 struct cl_page *cl_vmpage_page(struct page *vmpage, struct cl_object *obj)
468 {
469         struct cl_page *top;
470         struct cl_page *page;
471
472         ENTRY;
473         KLASSERT(PageLocked(vmpage));
474
475         /*
476          * NOTE: absence of races and liveness of data are guaranteed by page
477          *       lock on a "vmpage". That works because object destruction has
478          *       bottom-to-top pass.
479          */
480
481         /*
482          * This loop assumes that ->private points to the top-most page. This
483          * can be rectified easily.
484          */
485         top = (struct cl_page *)vmpage->private;
486         if (top == NULL)
487                 RETURN(NULL);
488
489         for (page = top; page != NULL; page = page->cp_child) {
490                 if (cl_object_same(page->cp_obj, obj)) {
491                         cl_page_get_trust(page);
492                         break;
493                 }
494         }
495         LASSERT(ergo(page, page->cp_type == CPT_CACHEABLE));
496         RETURN(page);
497 }
498 EXPORT_SYMBOL(cl_vmpage_page);
499
500 /**
501  * Returns the top-page for a given page.
502  *
503  * \see cl_object_top(), cl_io_top()
504  */
505 struct cl_page *cl_page_top(struct cl_page *page)
506 {
507         return cl_page_top_trusted(page);
508 }
509 EXPORT_SYMBOL(cl_page_top);
510
511 const struct cl_page_slice *cl_page_at(const struct cl_page *page,
512                                        const struct lu_device_type *dtype)
513 {
514         return cl_page_at_trusted(page, dtype);
515 }
516 EXPORT_SYMBOL(cl_page_at);
517
518 #define CL_PAGE_OP(opname) offsetof(struct cl_page_operations, opname)
519
520 #define CL_PAGE_INVOKE(_env, _page, _op, _proto, ...)                   \
521 ({                                                                      \
522         const struct lu_env        *__env  = (_env);                    \
523         struct cl_page             *__page = (_page);                   \
524         const struct cl_page_slice *__scan;                             \
525         int                         __result;                           \
526         ptrdiff_t                   __op   = (_op);                     \
527         int                       (*__method)_proto;                    \
528                                                                         \
529         __result = 0;                                                   \
530         __page = cl_page_top(__page);                                   \
531         do {                                                            \
532                 cfs_list_for_each_entry(__scan, &__page->cp_layers,     \
533                                         cpl_linkage) {                  \
534                         __method = *(void **)((char *)__scan->cpl_ops + \
535                                               __op);                    \
536                         if (__method != NULL) {                         \
537                                 __result = (*__method)(__env, __scan,   \
538                                                        ## __VA_ARGS__); \
539                                 if (__result != 0)                      \
540                                         break;                          \
541                         }                                               \
542                 }                                                       \
543                 __page = __page->cp_child;                              \
544         } while (__page != NULL && __result == 0);                      \
545         if (__result > 0)                                               \
546                 __result = 0;                                           \
547         __result;                                                       \
548 })
549
550 #define CL_PAGE_INVOID(_env, _page, _op, _proto, ...)                   \
551 do {                                                                    \
552         const struct lu_env        *__env  = (_env);                    \
553         struct cl_page             *__page = (_page);                   \
554         const struct cl_page_slice *__scan;                             \
555         ptrdiff_t                   __op   = (_op);                     \
556         void                      (*__method)_proto;                    \
557                                                                         \
558         __page = cl_page_top(__page);                                   \
559         do {                                                            \
560                 cfs_list_for_each_entry(__scan, &__page->cp_layers,     \
561                                         cpl_linkage) {                  \
562                         __method = *(void **)((char *)__scan->cpl_ops + \
563                                               __op);                    \
564                         if (__method != NULL)                           \
565                                 (*__method)(__env, __scan,              \
566                                             ## __VA_ARGS__);            \
567                 }                                                       \
568                 __page = __page->cp_child;                              \
569         } while (__page != NULL);                                       \
570 } while (0)
571
572 #define CL_PAGE_INVOID_REVERSE(_env, _page, _op, _proto, ...)               \
573 do {                                                                        \
574         const struct lu_env        *__env  = (_env);                        \
575         struct cl_page             *__page = (_page);                       \
576         const struct cl_page_slice *__scan;                                 \
577         ptrdiff_t                   __op   = (_op);                         \
578         void                      (*__method)_proto;                        \
579                                                                             \
580         /* get to the bottom page. */                                       \
581         while (__page->cp_child != NULL)                                    \
582                 __page = __page->cp_child;                                  \
583         do {                                                                \
584                 cfs_list_for_each_entry_reverse(__scan, &__page->cp_layers, \
585                                                 cpl_linkage) {              \
586                         __method = *(void **)((char *)__scan->cpl_ops +     \
587                                               __op);                        \
588                         if (__method != NULL)                               \
589                                 (*__method)(__env, __scan,                  \
590                                             ## __VA_ARGS__);                \
591                 }                                                           \
592                 __page = __page->cp_parent;                                 \
593         } while (__page != NULL);                                           \
594 } while (0)
595
596 static int cl_page_invoke(const struct lu_env *env,
597                           struct cl_io *io, struct cl_page *page, ptrdiff_t op)
598
599 {
600         PINVRNT(env, page, cl_object_same(page->cp_obj, io->ci_obj));
601         ENTRY;
602         RETURN(CL_PAGE_INVOKE(env, page, op,
603                               (const struct lu_env *,
604                                const struct cl_page_slice *, struct cl_io *),
605                               io));
606 }
607
608 static void cl_page_invoid(const struct lu_env *env,
609                            struct cl_io *io, struct cl_page *page, ptrdiff_t op)
610
611 {
612         PINVRNT(env, page, cl_object_same(page->cp_obj, io->ci_obj));
613         ENTRY;
614         CL_PAGE_INVOID(env, page, op,
615                        (const struct lu_env *,
616                         const struct cl_page_slice *, struct cl_io *), io);
617         EXIT;
618 }
619
620 static void cl_page_owner_clear(struct cl_page *page)
621 {
622         ENTRY;
623         for (page = cl_page_top(page); page != NULL; page = page->cp_child) {
624                 if (page->cp_owner != NULL) {
625                         LASSERT(page->cp_owner->ci_owned_nr > 0);
626                         page->cp_owner->ci_owned_nr--;
627                         page->cp_owner = NULL;
628                         page->cp_task = NULL;
629                 }
630         }
631         EXIT;
632 }
633
634 static void cl_page_owner_set(struct cl_page *page)
635 {
636         ENTRY;
637         for (page = cl_page_top(page); page != NULL; page = page->cp_child) {
638                 LASSERT(page->cp_owner != NULL);
639                 page->cp_owner->ci_owned_nr++;
640         }
641         EXIT;
642 }
643
644 void cl_page_disown0(const struct lu_env *env,
645                      struct cl_io *io, struct cl_page *pg)
646 {
647         enum cl_page_state state;
648
649         ENTRY;
650         state = pg->cp_state;
651         PINVRNT(env, pg, state == CPS_OWNED || state == CPS_FREEING);
652         PINVRNT(env, pg, cl_page_invariant(pg) || state == CPS_FREEING);
653         cl_page_owner_clear(pg);
654
655         if (state == CPS_OWNED)
656                 cl_page_state_set(env, pg, CPS_CACHED);
657         /*
658          * Completion call-backs are executed in the bottom-up order, so that
659          * uppermost layer (llite), responsible for VFS/VM interaction runs
660          * last and can release locks safely.
661          */
662         CL_PAGE_INVOID_REVERSE(env, pg, CL_PAGE_OP(cpo_disown),
663                                (const struct lu_env *,
664                                 const struct cl_page_slice *, struct cl_io *),
665                                io);
666         EXIT;
667 }
668
669 /**
670  * returns true, iff page is owned by the given io.
671  */
672 int cl_page_is_owned(const struct cl_page *pg, const struct cl_io *io)
673 {
674         LINVRNT(cl_object_same(pg->cp_obj, io->ci_obj));
675         ENTRY;
676         RETURN(pg->cp_state == CPS_OWNED && pg->cp_owner == io);
677 }
678 EXPORT_SYMBOL(cl_page_is_owned);
679
680 /**
681  * Try to own a page by IO.
682  *
683  * Waits until page is in cl_page_state::CPS_CACHED state, and then switch it
684  * into cl_page_state::CPS_OWNED state.
685  *
686  * \pre  !cl_page_is_owned(pg, io)
687  * \post result == 0 iff cl_page_is_owned(pg, io)
688  *
689  * \retval 0   success
690  *
691  * \retval -ve failure, e.g., page was destroyed (and landed in
692  *             cl_page_state::CPS_FREEING instead of cl_page_state::CPS_CACHED).
693  *             or, page was owned by another thread, or in IO.
694  *
695  * \see cl_page_disown()
696  * \see cl_page_operations::cpo_own()
697  * \see cl_page_own_try()
698  * \see cl_page_own
699  */
700 static int cl_page_own0(const struct lu_env *env, struct cl_io *io,
701                         struct cl_page *pg, int nonblock)
702 {
703         int result;
704
705         PINVRNT(env, pg, !cl_page_is_owned(pg, io));
706
707         ENTRY;
708         pg = cl_page_top(pg);
709         io = cl_io_top(io);
710
711         if (pg->cp_state == CPS_FREEING) {
712                 result = -ENOENT;
713         } else {
714                 result = CL_PAGE_INVOKE(env, pg, CL_PAGE_OP(cpo_own),
715                                         (const struct lu_env *,
716                                          const struct cl_page_slice *,
717                                          struct cl_io *, int),
718                                         io, nonblock);
719                 if (result == 0) {
720                         PASSERT(env, pg, pg->cp_owner == NULL);
721                         PASSERT(env, pg, pg->cp_req == NULL);
722                         pg->cp_owner = io;
723                         pg->cp_task  = current;
724                         cl_page_owner_set(pg);
725                         if (pg->cp_state != CPS_FREEING) {
726                                 cl_page_state_set(env, pg, CPS_OWNED);
727                         } else {
728                                 cl_page_disown0(env, io, pg);
729                                 result = -ENOENT;
730                         }
731                 }
732         }
733         PINVRNT(env, pg, ergo(result == 0, cl_page_invariant(pg)));
734         RETURN(result);
735 }
736
737 /**
738  * Own a page, might be blocked.
739  *
740  * \see cl_page_own0()
741  */
742 int cl_page_own(const struct lu_env *env, struct cl_io *io, struct cl_page *pg)
743 {
744         return cl_page_own0(env, io, pg, 0);
745 }
746 EXPORT_SYMBOL(cl_page_own);
747
748 /**
749  * Nonblock version of cl_page_own().
750  *
751  * \see cl_page_own0()
752  */
753 int cl_page_own_try(const struct lu_env *env, struct cl_io *io,
754                     struct cl_page *pg)
755 {
756         return cl_page_own0(env, io, pg, 1);
757 }
758 EXPORT_SYMBOL(cl_page_own_try);
759
760
761 /**
762  * Assume page ownership.
763  *
764  * Called when page is already locked by the hosting VM.
765  *
766  * \pre !cl_page_is_owned(pg, io)
767  * \post cl_page_is_owned(pg, io)
768  *
769  * \see cl_page_operations::cpo_assume()
770  */
771 void cl_page_assume(const struct lu_env *env,
772                     struct cl_io *io, struct cl_page *pg)
773 {
774         PINVRNT(env, pg, cl_object_same(pg->cp_obj, io->ci_obj));
775
776         ENTRY;
777         pg = cl_page_top(pg);
778         io = cl_io_top(io);
779
780         cl_page_invoid(env, io, pg, CL_PAGE_OP(cpo_assume));
781         PASSERT(env, pg, pg->cp_owner == NULL);
782         pg->cp_owner = io;
783         pg->cp_task = current;
784         cl_page_owner_set(pg);
785         cl_page_state_set(env, pg, CPS_OWNED);
786         EXIT;
787 }
788 EXPORT_SYMBOL(cl_page_assume);
789
790 /**
791  * Releases page ownership without unlocking the page.
792  *
793  * Moves page into cl_page_state::CPS_CACHED without releasing a lock on the
794  * underlying VM page (as VM is supposed to do this itself).
795  *
796  * \pre   cl_page_is_owned(pg, io)
797  * \post !cl_page_is_owned(pg, io)
798  *
799  * \see cl_page_assume()
800  */
801 void cl_page_unassume(const struct lu_env *env,
802                       struct cl_io *io, struct cl_page *pg)
803 {
804         PINVRNT(env, pg, cl_page_is_owned(pg, io));
805         PINVRNT(env, pg, cl_page_invariant(pg));
806
807         ENTRY;
808         pg = cl_page_top(pg);
809         io = cl_io_top(io);
810         cl_page_owner_clear(pg);
811         cl_page_state_set(env, pg, CPS_CACHED);
812         CL_PAGE_INVOID_REVERSE(env, pg, CL_PAGE_OP(cpo_unassume),
813                                (const struct lu_env *,
814                                 const struct cl_page_slice *, struct cl_io *),
815                                io);
816         EXIT;
817 }
818 EXPORT_SYMBOL(cl_page_unassume);
819
820 /**
821  * Releases page ownership.
822  *
823  * Moves page into cl_page_state::CPS_CACHED.
824  *
825  * \pre   cl_page_is_owned(pg, io)
826  * \post !cl_page_is_owned(pg, io)
827  *
828  * \see cl_page_own()
829  * \see cl_page_operations::cpo_disown()
830  */
831 void cl_page_disown(const struct lu_env *env,
832                     struct cl_io *io, struct cl_page *pg)
833 {
834         PINVRNT(env, pg, cl_page_is_owned(pg, io) ||
835                          pg->cp_state == CPS_FREEING);
836
837         ENTRY;
838         pg = cl_page_top(pg);
839         io = cl_io_top(io);
840         cl_page_disown0(env, io, pg);
841         EXIT;
842 }
843 EXPORT_SYMBOL(cl_page_disown);
844
845 /**
846  * Called when page is to be removed from the object, e.g., as a result of
847  * truncate.
848  *
849  * Calls cl_page_operations::cpo_discard() top-to-bottom.
850  *
851  * \pre cl_page_is_owned(pg, io)
852  *
853  * \see cl_page_operations::cpo_discard()
854  */
855 void cl_page_discard(const struct lu_env *env,
856                      struct cl_io *io, struct cl_page *pg)
857 {
858         PINVRNT(env, pg, cl_page_is_owned(pg, io));
859         PINVRNT(env, pg, cl_page_invariant(pg));
860
861         cl_page_invoid(env, io, pg, CL_PAGE_OP(cpo_discard));
862 }
863 EXPORT_SYMBOL(cl_page_discard);
864
865 /**
866  * Version of cl_page_delete() that can be called for not fully constructed
867  * pages, e.g,. in a error handling cl_page_find()->cl_page_delete0()
868  * path. Doesn't check page invariant.
869  */
870 static void cl_page_delete0(const struct lu_env *env, struct cl_page *pg)
871 {
872         ENTRY;
873
874         PASSERT(env, pg, pg == cl_page_top(pg));
875         PASSERT(env, pg, pg->cp_state != CPS_FREEING);
876
877         /*
878          * Severe all ways to obtain new pointers to @pg.
879          */
880         cl_page_owner_clear(pg);
881
882         cl_page_state_set0(env, pg, CPS_FREEING);
883
884         CL_PAGE_INVOID_REVERSE(env, pg, CL_PAGE_OP(cpo_delete),
885                        (const struct lu_env *, const struct cl_page_slice *));
886
887         EXIT;
888 }
889
890 /**
891  * Called when a decision is made to throw page out of memory.
892  *
893  * Notifies all layers about page destruction by calling
894  * cl_page_operations::cpo_delete() method top-to-bottom.
895  *
896  * Moves page into cl_page_state::CPS_FREEING state (this is the only place
897  * where transition to this state happens).
898  *
899  * Eliminates all venues through which new references to the page can be
900  * obtained:
901  *
902  *     - removes page from the radix trees,
903  *
904  *     - breaks linkage from VM page to cl_page.
905  *
906  * Once page reaches cl_page_state::CPS_FREEING, all remaining references will
907  * drain after some time, at which point page will be recycled.
908  *
909  * \pre  pg == cl_page_top(pg)
910  * \pre  VM page is locked
911  * \post pg->cp_state == CPS_FREEING
912  *
913  * \see cl_page_operations::cpo_delete()
914  */
915 void cl_page_delete(const struct lu_env *env, struct cl_page *pg)
916 {
917         PINVRNT(env, pg, cl_page_invariant(pg));
918         ENTRY;
919         cl_page_delete0(env, pg);
920         EXIT;
921 }
922 EXPORT_SYMBOL(cl_page_delete);
923
924 /**
925  * Marks page up-to-date.
926  *
927  * Call cl_page_operations::cpo_export() through all layers top-to-bottom. The
928  * layer responsible for VM interaction has to mark/clear page as up-to-date
929  * by the \a uptodate argument.
930  *
931  * \see cl_page_operations::cpo_export()
932  */
933 void cl_page_export(const struct lu_env *env, struct cl_page *pg, int uptodate)
934 {
935         PINVRNT(env, pg, cl_page_invariant(pg));
936         CL_PAGE_INVOID(env, pg, CL_PAGE_OP(cpo_export),
937                        (const struct lu_env *,
938                         const struct cl_page_slice *, int), uptodate);
939 }
940 EXPORT_SYMBOL(cl_page_export);
941
942 /**
943  * Returns true, iff \a pg is VM locked in a suitable sense by the calling
944  * thread.
945  */
946 int cl_page_is_vmlocked(const struct lu_env *env, const struct cl_page *pg)
947 {
948         int result;
949         const struct cl_page_slice *slice;
950
951         ENTRY;
952         pg = cl_page_top_trusted((struct cl_page *)pg);
953         slice = container_of(pg->cp_layers.next,
954                              const struct cl_page_slice, cpl_linkage);
955         PASSERT(env, pg, slice->cpl_ops->cpo_is_vmlocked != NULL);
956         /*
957          * Call ->cpo_is_vmlocked() directly instead of going through
958          * CL_PAGE_INVOKE(), because cl_page_is_vmlocked() is used by
959          * cl_page_invariant().
960          */
961         result = slice->cpl_ops->cpo_is_vmlocked(env, slice);
962         PASSERT(env, pg, result == -EBUSY || result == -ENODATA);
963         RETURN(result == -EBUSY);
964 }
965 EXPORT_SYMBOL(cl_page_is_vmlocked);
966
967 static enum cl_page_state cl_req_type_state(enum cl_req_type crt)
968 {
969         ENTRY;
970         RETURN(crt == CRT_WRITE ? CPS_PAGEOUT : CPS_PAGEIN);
971 }
972
973 static void cl_page_io_start(const struct lu_env *env,
974                              struct cl_page *pg, enum cl_req_type crt)
975 {
976         /*
977          * Page is queued for IO, change its state.
978          */
979         ENTRY;
980         cl_page_owner_clear(pg);
981         cl_page_state_set(env, pg, cl_req_type_state(crt));
982         EXIT;
983 }
984
985 /**
986  * Prepares page for immediate transfer. cl_page_operations::cpo_prep() is
987  * called top-to-bottom. Every layer either agrees to submit this page (by
988  * returning 0), or requests to omit this page (by returning -EALREADY). Layer
989  * handling interactions with the VM also has to inform VM that page is under
990  * transfer now.
991  */
992 int cl_page_prep(const struct lu_env *env, struct cl_io *io,
993                  struct cl_page *pg, enum cl_req_type crt)
994 {
995         int result;
996
997         PINVRNT(env, pg, cl_page_is_owned(pg, io));
998         PINVRNT(env, pg, cl_page_invariant(pg));
999         PINVRNT(env, pg, crt < CRT_NR);
1000
1001         /*
1002          * XXX this has to be called bottom-to-top, so that llite can set up
1003          * PG_writeback without risking other layers deciding to skip this
1004          * page.
1005          */
1006         if (crt >= CRT_NR)
1007                 return -EINVAL;
1008         result = cl_page_invoke(env, io, pg, CL_PAGE_OP(io[crt].cpo_prep));
1009         if (result == 0)
1010                 cl_page_io_start(env, pg, crt);
1011
1012         KLASSERT(ergo(crt == CRT_WRITE && pg->cp_type == CPT_CACHEABLE,
1013                       equi(result == 0,
1014                            PageWriteback(cl_page_vmpage(env, pg)))));
1015         CL_PAGE_HEADER(D_TRACE, env, pg, "%d %d\n", crt, result);
1016         return result;
1017 }
1018 EXPORT_SYMBOL(cl_page_prep);
1019
1020 /**
1021  * Notify layers about transfer completion.
1022  *
1023  * Invoked by transfer sub-system (which is a part of osc) to notify layers
1024  * that a transfer, of which this page is a part of has completed.
1025  *
1026  * Completion call-backs are executed in the bottom-up order, so that
1027  * uppermost layer (llite), responsible for the VFS/VM interaction runs last
1028  * and can release locks safely.
1029  *
1030  * \pre  pg->cp_state == CPS_PAGEIN || pg->cp_state == CPS_PAGEOUT
1031  * \post pg->cp_state == CPS_CACHED
1032  *
1033  * \see cl_page_operations::cpo_completion()
1034  */
1035 void cl_page_completion(const struct lu_env *env,
1036                         struct cl_page *pg, enum cl_req_type crt, int ioret)
1037 {
1038         struct cl_sync_io *anchor = pg->cp_sync_io;
1039
1040         PASSERT(env, pg, crt < CRT_NR);
1041         /* cl_page::cp_req already cleared by the caller (osc_completion()) */
1042         PASSERT(env, pg, pg->cp_req == NULL);
1043         PASSERT(env, pg, pg->cp_state == cl_req_type_state(crt));
1044
1045         ENTRY;
1046         CL_PAGE_HEADER(D_TRACE, env, pg, "%d %d\n", crt, ioret);
1047         if (crt == CRT_READ && ioret == 0) {
1048                 PASSERT(env, pg, !(pg->cp_flags & CPF_READ_COMPLETED));
1049                 pg->cp_flags |= CPF_READ_COMPLETED;
1050         }
1051
1052         cl_page_state_set(env, pg, CPS_CACHED);
1053         if (crt >= CRT_NR)
1054                 return;
1055         CL_PAGE_INVOID_REVERSE(env, pg, CL_PAGE_OP(io[crt].cpo_completion),
1056                                (const struct lu_env *,
1057                                 const struct cl_page_slice *, int), ioret);
1058         if (anchor) {
1059                 LASSERT(cl_page_is_vmlocked(env, pg));
1060                 LASSERT(pg->cp_sync_io == anchor);
1061                 pg->cp_sync_io = NULL;
1062         }
1063         /*
1064          * As page->cp_obj is pinned by a reference from page->cp_req, it is
1065          * safe to call cl_page_put() without risking object destruction in a
1066          * non-blocking context.
1067          */
1068         cl_page_put(env, pg);
1069
1070         if (anchor)
1071                 cl_sync_io_note(anchor, ioret);
1072
1073         EXIT;
1074 }
1075 EXPORT_SYMBOL(cl_page_completion);
1076
1077 /**
1078  * Notify layers that transfer formation engine decided to yank this page from
1079  * the cache and to make it a part of a transfer.
1080  *
1081  * \pre  pg->cp_state == CPS_CACHED
1082  * \post pg->cp_state == CPS_PAGEIN || pg->cp_state == CPS_PAGEOUT
1083  *
1084  * \see cl_page_operations::cpo_make_ready()
1085  */
1086 int cl_page_make_ready(const struct lu_env *env, struct cl_page *pg,
1087                        enum cl_req_type crt)
1088 {
1089         int result;
1090
1091         PINVRNT(env, pg, crt < CRT_NR);
1092
1093         ENTRY;
1094         if (crt >= CRT_NR)
1095                 RETURN(-EINVAL);
1096         result = CL_PAGE_INVOKE(env, pg, CL_PAGE_OP(io[crt].cpo_make_ready),
1097                                 (const struct lu_env *,
1098                                  const struct cl_page_slice *));
1099         if (result == 0) {
1100                 PASSERT(env, pg, pg->cp_state == CPS_CACHED);
1101                 cl_page_io_start(env, pg, crt);
1102         }
1103         CL_PAGE_HEADER(D_TRACE, env, pg, "%d %d\n", crt, result);
1104         RETURN(result);
1105 }
1106 EXPORT_SYMBOL(cl_page_make_ready);
1107
1108 /**
1109  * Notify layers that high level io decided to place this page into a cache
1110  * for future transfer.
1111  *
1112  * The layer implementing transfer engine (osc) has to register this page in
1113  * its queues.
1114  *
1115  * \pre  cl_page_is_owned(pg, io)
1116  * \post cl_page_is_owned(pg, io)
1117  *
1118  * \see cl_page_operations::cpo_cache_add()
1119  */
1120 int cl_page_cache_add(const struct lu_env *env, struct cl_io *io,
1121                       struct cl_page *pg, enum cl_req_type crt)
1122 {
1123         const struct cl_page_slice *scan;
1124         int result = 0;
1125
1126         PINVRNT(env, pg, crt < CRT_NR);
1127         PINVRNT(env, pg, cl_page_is_owned(pg, io));
1128         PINVRNT(env, pg, cl_page_invariant(pg));
1129
1130         ENTRY;
1131
1132         if (crt >= CRT_NR)
1133                 RETURN(-EINVAL);
1134
1135         cfs_list_for_each_entry(scan, &pg->cp_layers, cpl_linkage) {
1136                 if (scan->cpl_ops->io[crt].cpo_cache_add == NULL)
1137                         continue;
1138
1139                 result = scan->cpl_ops->io[crt].cpo_cache_add(env, scan, io);
1140                 if (result != 0)
1141                         break;
1142         }
1143         CL_PAGE_HEADER(D_TRACE, env, pg, "%d %d\n", crt, result);
1144         RETURN(result);
1145 }
1146 EXPORT_SYMBOL(cl_page_cache_add);
1147
1148 /**
1149  * Called if a pge is being written back by kernel's intention.
1150  *
1151  * \pre  cl_page_is_owned(pg, io)
1152  * \post ergo(result == 0, pg->cp_state == CPS_PAGEOUT)
1153  *
1154  * \see cl_page_operations::cpo_flush()
1155  */
1156 int cl_page_flush(const struct lu_env *env, struct cl_io *io,
1157                   struct cl_page *pg)
1158 {
1159         int result;
1160
1161         PINVRNT(env, pg, cl_page_is_owned(pg, io));
1162         PINVRNT(env, pg, cl_page_invariant(pg));
1163
1164         ENTRY;
1165
1166         result = cl_page_invoke(env, io, pg, CL_PAGE_OP(cpo_flush));
1167
1168         CL_PAGE_HEADER(D_TRACE, env, pg, "%d\n", result);
1169         RETURN(result);
1170 }
1171 EXPORT_SYMBOL(cl_page_flush);
1172
1173 /**
1174  * Checks whether page is protected by any extent lock is at least required
1175  * mode.
1176  *
1177  * \return the same as in cl_page_operations::cpo_is_under_lock() method.
1178  * \see cl_page_operations::cpo_is_under_lock()
1179  */
1180 int cl_page_is_under_lock(const struct lu_env *env, struct cl_io *io,
1181                           struct cl_page *page)
1182 {
1183         int rc;
1184
1185         PINVRNT(env, page, cl_page_invariant(page));
1186
1187         ENTRY;
1188         rc = CL_PAGE_INVOKE(env, page, CL_PAGE_OP(cpo_is_under_lock),
1189                             (const struct lu_env *,
1190                              const struct cl_page_slice *, struct cl_io *),
1191                             io);
1192         PASSERT(env, page, rc != 0);
1193         RETURN(rc);
1194 }
1195 EXPORT_SYMBOL(cl_page_is_under_lock);
1196
1197 /**
1198  * Tells transfer engine that only part of a page is to be transmitted.
1199  *
1200  * \see cl_page_operations::cpo_clip()
1201  */
1202 void cl_page_clip(const struct lu_env *env, struct cl_page *pg,
1203                   int from, int to)
1204 {
1205         PINVRNT(env, pg, cl_page_invariant(pg));
1206
1207         CL_PAGE_HEADER(D_TRACE, env, pg, "%d %d\n", from, to);
1208         CL_PAGE_INVOID(env, pg, CL_PAGE_OP(cpo_clip),
1209                        (const struct lu_env *,
1210                         const struct cl_page_slice *,int, int),
1211                        from, to);
1212 }
1213 EXPORT_SYMBOL(cl_page_clip);
1214
1215 /**
1216  * Prints human readable representation of \a pg to the \a f.
1217  */
1218 void cl_page_header_print(const struct lu_env *env, void *cookie,
1219                           lu_printer_t printer, const struct cl_page *pg)
1220 {
1221         (*printer)(env, cookie,
1222                    "page@%p[%d %p:%lu ^%p_%p %d %d %d %p %p %#x]\n",
1223                    pg, cfs_atomic_read(&pg->cp_ref), pg->cp_obj,
1224                    pg->cp_index, pg->cp_parent, pg->cp_child,
1225                    pg->cp_state, pg->cp_error, pg->cp_type,
1226                    pg->cp_owner, pg->cp_req, pg->cp_flags);
1227 }
1228 EXPORT_SYMBOL(cl_page_header_print);
1229
1230 /**
1231  * Prints human readable representation of \a pg to the \a f.
1232  */
1233 void cl_page_print(const struct lu_env *env, void *cookie,
1234                    lu_printer_t printer, const struct cl_page *pg)
1235 {
1236         struct cl_page *scan;
1237
1238         for (scan = cl_page_top((struct cl_page *)pg);
1239              scan != NULL; scan = scan->cp_child)
1240                 cl_page_header_print(env, cookie, printer, scan);
1241         CL_PAGE_INVOKE(env, (struct cl_page *)pg, CL_PAGE_OP(cpo_print),
1242                        (const struct lu_env *env,
1243                         const struct cl_page_slice *slice,
1244                         void *cookie, lu_printer_t p), cookie, printer);
1245         (*printer)(env, cookie, "end page@%p\n", pg);
1246 }
1247 EXPORT_SYMBOL(cl_page_print);
1248
1249 /**
1250  * Cancel a page which is still in a transfer.
1251  */
1252 int cl_page_cancel(const struct lu_env *env, struct cl_page *page)
1253 {
1254         return CL_PAGE_INVOKE(env, page, CL_PAGE_OP(cpo_cancel),
1255                               (const struct lu_env *,
1256                                const struct cl_page_slice *));
1257 }
1258 EXPORT_SYMBOL(cl_page_cancel);
1259
1260 /**
1261  * Converts a byte offset within object \a obj into a page index.
1262  */
1263 loff_t cl_offset(const struct cl_object *obj, pgoff_t idx)
1264 {
1265         return (loff_t)idx << PAGE_CACHE_SHIFT;
1266 }
1267 EXPORT_SYMBOL(cl_offset);
1268
1269 /**
1270  * Converts a page index into a byte offset within object \a obj.
1271  */
1272 pgoff_t cl_index(const struct cl_object *obj, loff_t offset)
1273 {
1274         return offset >> PAGE_CACHE_SHIFT;
1275 }
1276 EXPORT_SYMBOL(cl_index);
1277
1278 int cl_page_size(const struct cl_object *obj)
1279 {
1280         return 1 << PAGE_CACHE_SHIFT;
1281 }
1282 EXPORT_SYMBOL(cl_page_size);
1283
1284 /**
1285  * Adds page slice to the compound page.
1286  *
1287  * This is called by cl_object_operations::coo_page_init() methods to add a
1288  * per-layer state to the page. New state is added at the end of
1289  * cl_page::cp_layers list, that is, it is at the bottom of the stack.
1290  *
1291  * \see cl_lock_slice_add(), cl_req_slice_add(), cl_io_slice_add()
1292  */
1293 void cl_page_slice_add(struct cl_page *page, struct cl_page_slice *slice,
1294                        struct cl_object *obj,
1295                        const struct cl_page_operations *ops)
1296 {
1297         ENTRY;
1298         cfs_list_add_tail(&slice->cpl_linkage, &page->cp_layers);
1299         slice->cpl_obj  = obj;
1300         slice->cpl_ops  = ops;
1301         slice->cpl_page = page;
1302         EXIT;
1303 }
1304 EXPORT_SYMBOL(cl_page_slice_add);
1305
1306 int  cl_page_init(void)
1307 {
1308         return 0;
1309 }
1310
1311 void cl_page_fini(void)
1312 {
1313 }