Whamcloud - gitweb
land clio.
[fs/lustre-release.git] / lustre / lov / lov_cl_internal.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36 /*
37  * This file is part of Lustre, http://www.lustre.org/
38  * Lustre is a trademark of Sun Microsystems, Inc.
39  *
40  * Internal interfaces of LOV layer.
41  *
42  *   Author: Nikita Danilov <nikita.danilov@sun.com>
43  */
44
45 #ifndef LOV_CL_INTERNAL_H
46 #define LOV_CL_INTERNAL_H
47
48 #ifdef __KERNEL__
49 # include <libcfs/libcfs.h>
50 #else
51 # include <liblustre.h>
52 #endif
53
54 #include <obd.h>
55 #include <cl_object.h>
56 #include "lov_internal.h"
57
58 /** \addtogroup lov lov @{ */
59
60 /** \defgroup lov lov
61  * Logical object volume layer. This layer implements data striping (raid0).
62  *
63  * At the lov layer top-entity (object, page, lock, io) is connected to one or
64  * more sub-entities: top-object, representing a file is connected to a set of
65  * sub-objects, each representing a stripe, file-level top-lock is connected
66  * to a set of per-stripe sub-locks, top-page is connected to a (single)
67  * sub-page, and a top-level IO is connected to a set of (potentially
68  * concurrent) sub-IO's.
69  *
70  * Sub-object, sub-page, and sub-io have well-defined top-object and top-page
71  * respectively, while a single sub-lock can be part of multiple top-locks.
72  *
73  * Reference counting models are different for different types of entities:
74  *
75  *     - top-object keeps a reference to its sub-objects, and destroys them
76  *       when it is destroyed.
77  *
78  *     - top-page keeps a reference to its sub-page, and destroys it when it
79  *       is destroyed.
80  *
81  *     - sub-lock keep a reference to its top-locks. Top-lock keeps a
82  *       reference (and a hold, see cl_lock_hold()) on its sub-locks when it
83  *       actively using them (that is, in cl_lock_state::CLS_QUEUING,
84  *       cl_lock_state::CLS_ENQUEUED, cl_lock_state::CLS_HELD states). When
85  *       moving into cl_lock_state::CLS_CACHED state, top-lock releases a
86  *       hold. From this moment top-lock has only a 'weak' reference to its
87  *       sub-locks. This reference is protected by top-lock
88  *       cl_lock::cll_guard, and will be automatically cleared by the sub-lock
89  *       when the latter is destroyed. When a sub-lock is canceled, a
90  *       reference to it is removed from the top-lock array, and top-lock is
91  *       moved into CLS_NEW state. It is guaranteed that all sub-locks exits
92  *       while their top-lock is in CLS_HELD or CLS_CACHED states.
93  *
94  *     - IO's are not reference counted.
95  *
96  * To implement a connection between top and sub entities, lov layer is split
97  * into two pieces: lov ("upper half"), and lovsub ("bottom half"), both
98  * implementing full set of cl-interfaces. For example, top-object has clu and
99  * lov layers, and it's sub-object has lovsub and osc layers. lovsub layer is
100  * used to track child-parent relationship.
101  *
102  * @{
103  */
104
105 struct lovsub_device;
106 struct lovsub_object;
107 struct lovsub_lock;
108
109 enum lov_device_flags {
110         LOV_DEV_INITIALIZED = 1 << 0
111 };
112
113 /*
114  * Upper half.
115  */
116
117 /**
118  * Resources that are used in memory-cleaning path, and whose allocation
119  * cannot fail even when memory is tight. They are preallocated in sufficient
120  * quantities in lov_device::ld_emerg[], and access to them is serialized
121  * lov_device::ld_mutex.
122  */
123 struct lov_device_emerg {
124         /**
125          * Page list used to submit IO when memory is in pressure.
126          */
127         struct cl_page_list emrg_page_list;
128         /**
129          * sub-io's shared by all threads accessing this device when memory is
130          * too low to allocate sub-io's dynamically.
131          */
132         struct cl_io        emrg_subio;
133         /**
134          * Environments used by sub-io's in
135          * lov_device_emerg::emrg_subio.
136          */
137         struct lu_env      *emrg_env;
138         /**
139          * Refchecks for lov_device_emerg::emrg_env.
140          *
141          * \see cl_env_get()
142          */
143         int                 emrg_refcheck;
144 };
145
146 struct lov_device {
147         /*
148          * XXX Locking of lov-private data is missing.
149          */
150         struct cl_device          ld_cl;
151         struct lov_obd           *ld_lov;
152         /** size of lov_device::ld_target[] array */
153         __u32                     ld_target_nr;
154         struct lovsub_device    **ld_target;
155         __u32                     ld_flags;
156
157         /** Emergency resources used in memory-cleansing paths. */
158         struct lov_device_emerg **ld_emrg;
159         /**
160          * Serializes access to lov_device::ld_emrg in low-memory
161          * conditions.
162          */
163         struct mutex              ld_mutex;
164 };
165
166 /**
167  * Layout type.
168  */
169 enum lov_layout_type {
170         /** empty file without body */
171         LLT_EMPTY,
172         /** striped file */
173         LLT_RAID0,
174         /** join file */
175         LLT_JOIN,
176         LLT_NR
177 };
178
179 /**
180  * lov-specific file state.
181  *
182  * lov object has particular layout type, determining how top-object is built
183  * on top of sub-objects. Layout type can change dynamically. When this
184  * happens, lov_object::lo_type_guard semaphore is taken in exclusive mode,
185  * all state pertaining to the old layout type is destroyed, and new state is
186  * constructed. All object methods take said semaphore in the shared mode,
187  * providing serialization against transition between layout types.
188  *
189  * To avoid multiple `if' or `switch' statements, selecting behavior for the
190  * current layout type, object methods perform double-dispatch, invoking
191  * function corresponding to the current layout type.
192  */
193 struct lov_object {
194         struct cl_object       lo_cl;
195         /**
196          * Serializes object operations with transitions between layout types.
197          *
198          * This semaphore is taken in shared mode by all object methods, and
199          * is taken in exclusive mode when object type is changed.
200          *
201          * \see lov_object::lo_type
202          */
203         struct rw_semaphore    lo_type_guard;
204         /**
205          * Type of an object. Protected by lov_object::lo_type_guard.
206          */
207         enum lov_layout_type   lo_type;
208
209         union lov_layout_state {
210                 struct lov_layout_raid0 {
211                         unsigned               lo_nr;
212                         struct lov_stripe_md  *lo_lsm;
213                         struct lovsub_object **lo_sub;
214                         /**
215                          * When this is true, lov_object::lo_attr contains
216                          * valid up to date attributes for a top-level
217                          * object. This field is reset to 0 when attributes of
218                          * any sub-object change.
219                          */
220                         int                    lo_attr_valid;
221                         /**
222                          * Cached object attribute, built from sub-object
223                          * attributes.
224                          */
225                         struct cl_attr         lo_attr;
226                 } raid0;
227                 struct lov_layout_state_empty {
228                 } empty;
229                 struct lov_layout_state_join {
230                 } join;
231         } u;
232         /**
233          * Thread that acquired lov_object::lo_type_guard in an exclusive
234          * mode.
235          */
236         cfs_task_t            *lo_owner;
237 };
238
239 /**
240  * Flags that top-lock can set on each of its sub-locks.
241  */
242 enum lov_sub_flags {
243         /** Top-lock acquired a hold (cl_lock_hold()) on a sub-lock. */
244         LSF_HELD = 1 << 0
245 };
246
247 /**
248  * State lov_lock keeps for each sub-lock.
249  */
250 struct lov_lock_sub {
251         /** sub-lock itself */
252         struct lovsub_lock  *sub_lock;
253         /** An array of per-sub-lock flags, taken from enum lov_sub_flags */
254         unsigned             sub_flags;
255         int                  sub_stripe;
256         struct cl_lock_descr sub_descr;
257         struct cl_lock_descr sub_got;
258 };
259
260 /**
261  * lov-specific lock state.
262  */
263 struct lov_lock {
264         struct cl_lock_slice   lls_cl;
265         /** Number of sub-locks in this lock */
266         int                    lls_nr;
267         /**
268          * Number of existing sub-locks.
269          */
270         unsigned               lls_nr_filled;
271         /**
272          * Set when sub-lock was canceled, while top-lock was being
273          * unlocked.
274          */
275         int                    lls_unuse_race;
276         /**
277          * An array of sub-locks
278          *
279          * There are two issues with managing sub-locks:
280          *
281          *     - sub-locks are concurrently canceled, and
282          *
283          *     - sub-locks are shared with other top-locks.
284          *
285          * To manage cancellation, top-lock acquires a hold on a sublock
286          * (lov_sublock_adopt()) when the latter is inserted into
287          * lov_lock::lls_sub[]. This hold is released (lov_sublock_release())
288          * when top-lock is going into CLS_CACHED state or destroyed. Hold
289          * prevents sub-lock from cancellation.
290          *
291          * Sub-lock sharing means, among other things, that top-lock that is
292          * in the process of creation (i.e., not yet inserted into lock list)
293          * is already accessible to other threads once at least one of its
294          * sub-locks is created, see lov_lock_sub_init().
295          *
296          * Sub-lock can be in one of the following states:
297          *
298          *     - doesn't exist, lov_lock::lls_sub[]::sub_lock == NULL. Such
299          *       sub-lock was either never created (top-lock is in CLS_NEW
300          *       state), or it was created, then canceled, then destroyed
301          *       (lov_lock_unlink() cleared sub-lock pointer in the top-lock).
302          *
303          *     - sub-lock exists and is on
304          *       hold. (lov_lock::lls_sub[]::sub_flags & LSF_HELD). This is a
305          *       normal state of a sub-lock in CLS_HELD and CLS_CACHED states
306          *       of a top-lock.
307          *
308          *     - sub-lock exists, but is not held by the top-lock. This
309          *       happens after top-lock released a hold on sub-locks before
310          *       going into cache (lov_lock_unuse()).
311          *
312          * \todo To support wide-striping, array has to be replaced with a set
313          * of queues to avoid scanning.
314          */
315         struct lov_lock_sub   *lls_sub;
316         /**
317          * Original description with which lock was enqueued.
318          */
319         struct cl_lock_descr   lls_orig;
320 };
321
322 struct lov_page {
323         struct cl_page_slice lps_cl;
324         int                  lps_invalid;
325 };
326
327 /*
328  * Bottom half.
329  */
330
331 struct lovsub_device {
332         struct cl_device   acid_cl;
333         struct lov_device *acid_super;
334         int                acid_idx;
335         struct cl_device  *acid_next;
336 };
337
338 struct lovsub_object {
339         struct cl_object_header lso_header;
340         struct cl_object        lso_cl;
341         struct lov_object      *lso_super;
342         int                     lso_index;
343 };
344
345 /**
346  * A link between a top-lock and a sub-lock. Separate data-structure is
347  * necessary, because top-locks and sub-locks are in M:N relationship.
348  *
349  * \todo This can be optimized for a (by far) most frequent case of a single
350  * top-lock per sub-lock.
351  */
352 struct lov_lock_link {
353         struct lov_lock *lll_super;
354         /** An index within parent lock. */
355         int              lll_idx;
356         /**
357          * A linkage into per sub-lock list of all corresponding top-locks,
358          * hanging off lovsub_lock::lss_parents.
359          */
360         struct list_head lll_list;
361 };
362
363 /**
364  * Lock state at lovsub layer.
365  */
366 struct lovsub_lock {
367         struct cl_lock_slice  lss_cl;
368         /**
369          * List of top-locks that have given sub-lock as their part. Protected
370          * by cl_lock::cll_guard mutex.
371          */
372         struct list_head      lss_parents;
373         /**
374          * Top-lock that initiated current operation on this sub-lock. This is
375          * only set during top-to-bottom lock operations like enqueue, and is
376          * used to optimize state change notification. Protected by
377          * cl_lock::cll_guard mutex.
378          *
379          * \see lovsub_lock_state_one().
380          */
381         struct cl_lock       *lss_active;
382 };
383
384 struct lovsub_page {
385         struct cl_page_slice lsb_cl;
386 };
387
388
389 struct lov_thread_info {
390         struct cl_object_conf   lti_stripe_conf;
391         struct lu_fid           lti_fid;
392         struct cl_lock_descr    lti_ldescr;
393         struct ost_lvb          lti_lvb;
394         struct cl_2queue        lti_cl2q;
395         union  lov_layout_state lti_state;
396         struct cl_lock_closure  lti_closure;
397 };
398
399 /**
400  * State that lov_io maintains for every sub-io.
401  */
402 struct lov_io_sub {
403         int                  sub_stripe;
404         /**
405          * sub-io for a stripe. Ideally sub-io's can be stopped and resumed
406          * independently, with lov acting as a scheduler to maximize overall
407          * throughput.
408          */
409         struct cl_io        *sub_io;
410         /**
411          * Linkage into a list (hanging off lov_io::lis_active) of all
412          * sub-io's active for the current IO iteration.
413          */
414         struct list_head     sub_linkage;
415         /**
416          * true, iff cl_io_init() was successfully executed against
417          * lov_io_sub::sub_io.
418          */
419         int                  sub_io_initialized;
420         /**
421          * True, iff lov_io_sub::sub_io and lov_io_sub::sub_env weren't
422          * allocated, but borrowed from a per-device emergency pool.
423          */
424         int                  sub_borrowed;
425         /**
426          * environment, in which sub-io executes.
427          */
428         struct lu_env *sub_env;
429         /**
430          * environment's refcheck.
431          *
432          * \see cl_env_get()
433          */
434         int                  sub_refcheck;
435         int                  sub_refcheck2;
436         int                  sub_reenter;
437         void                *sub_cookie;
438 };
439
440 /**
441  * IO state private for LOV.
442  */
443 struct lov_io {
444         /** super-class */
445         struct cl_io_slice lis_cl;
446         /**
447          * Pointer to the object slice. This is a duplicate of
448          * lov_io::lis_cl::cis_object.
449          */
450         struct lov_object *lis_object;
451         /**
452          * Original end-of-io position for this IO, set by the upper layer as
453          * cl_io::u::ci_rw::pos + cl_io::u::ci_rw::count. lov remembers this,
454          * changes pos and count to fit IO into a single stripe and uses saved
455          * value to determine when IO iterations have to stop.
456          *
457          * This is used only for CIT_READ and CIT_WRITE io's.
458          */
459         loff_t             lis_io_endpos;
460
461         /**
462          * starting position within a file, for the current io loop iteration
463          * (stripe), used by ci_io_loop().
464          */
465         obd_off            lis_pos;
466         /**
467          * end position with in a file, for the current stripe io. This is
468          * exclusive (i.e., next offset after last byte affected by io).
469          */
470         obd_off            lis_endpos;
471
472         int                lis_mem_frozen;
473         int                lis_stripe_count;
474         int                lis_active_subios;
475
476         /**
477          * the index of ls_single_subio in ls_subios array
478          */
479         int                lis_single_subio_index;
480         struct cl_io       lis_single_subio;
481
482         /**
483          * size of ls_subios array, actually the highest stripe #
484          */
485         int                lis_nr_subios;
486         struct lov_io_sub *lis_subs;
487         /**
488          * List of active sub-io's.
489          */
490         struct list_head   lis_active;
491 };
492
493 struct lov_session {
494         struct lov_io ls_io;
495 };
496
497 /**
498  * State of transfer for lov.
499  */
500 struct lov_req {
501         struct cl_req_slice lr_cl;
502 };
503
504 /**
505  * State of transfer for lovsub.
506  */
507 struct lovsub_req {
508         struct cl_req_slice lsrq_cl;
509 };
510
511 extern struct lu_device_type lov_device_type;
512 extern struct lu_device_type lovsub_device_type;
513
514 extern struct lu_context_key lov_key;
515 extern struct lu_context_key lov_session_key;
516
517 extern cfs_mem_cache_t *lov_page_kmem;
518 extern cfs_mem_cache_t *lov_lock_kmem;
519 extern cfs_mem_cache_t *lov_object_kmem;
520 extern cfs_mem_cache_t *lov_thread_kmem;
521 extern cfs_mem_cache_t *lov_session_kmem;
522 extern cfs_mem_cache_t *lov_req_kmem;
523
524 extern cfs_mem_cache_t *lovsub_page_kmem;
525 extern cfs_mem_cache_t *lovsub_lock_kmem;
526 extern cfs_mem_cache_t *lovsub_object_kmem;
527 extern cfs_mem_cache_t *lovsub_req_kmem;
528
529 extern cfs_mem_cache_t *lov_lock_link_kmem;
530
531 int   lov_object_init     (const struct lu_env *env, struct lu_object *obj,
532                            const struct lu_object_conf *conf);
533 int   lovsub_object_init  (const struct lu_env *env, struct lu_object *obj,
534                            const struct lu_object_conf *conf);
535 int   lov_lock_init       (const struct lu_env *env, struct cl_object *obj,
536                            struct cl_lock *lock, const struct cl_io *io);
537 int   lov_io_init         (const struct lu_env *env, struct cl_object *obj,
538                            struct cl_io *io);
539 int   lovsub_lock_init    (const struct lu_env *env, struct cl_object *obj,
540                            struct cl_lock *lock, const struct cl_io *io);
541
542 int   lov_lock_init_raid0 (const struct lu_env *env, struct cl_object *obj,
543                            struct cl_lock *lock, const struct cl_io *io);
544 int   lov_io_init_raid0   (const struct lu_env *env, struct cl_object *obj,
545                            struct cl_io *io);
546 int   lov_io_init_empty   (const struct lu_env *env, struct cl_object *obj,
547                            struct cl_io *io);
548 void  lov_lock_unlink     (const struct lu_env *env, struct lov_lock_link *link,
549                            struct lovsub_lock *sub);
550
551 void  lov_sub_put         (struct lov_io_sub *sub);
552 int   lov_sublock_modify  (const struct lu_env *env, struct lov_lock *lov,
553                            struct lovsub_lock *sublock,
554                            const struct cl_lock_descr *d, int idx);
555
556
557 struct cl_page *lov_page_init   (const struct lu_env *env, struct cl_object *ob,
558                                  struct cl_page *page, cfs_page_t *vmpage);
559 struct cl_page *lovsub_page_init(const struct lu_env *env, struct cl_object *ob,
560                                  struct cl_page *page, cfs_page_t *vmpage);
561
562 struct cl_page   *lov_page_init_empty(const struct lu_env *env,
563                                       struct cl_object *obj,
564                                       struct cl_page *page, cfs_page_t *vmpage);
565 struct cl_page   *lov_page_init_raid0(const struct lu_env *env,
566                                       struct cl_object *obj,
567                                       struct cl_page *page, cfs_page_t *vmpage);
568 struct lu_object *lov_object_alloc   (const struct lu_env *env,
569                                       const struct lu_object_header *hdr,
570                                       struct lu_device *dev);
571 struct lu_object *lovsub_object_alloc(const struct lu_env *env,
572                                       const struct lu_object_header *hdr,
573                                       struct lu_device *dev);
574
575 struct lov_lock_link *lov_lock_link_find(const struct lu_env *env,
576                                          struct lov_lock *lck,
577                                          struct lovsub_lock *sub);
578 struct lov_io_sub    *lov_page_subio    (const struct lu_env *env,
579                                          struct lov_io *lio,
580                                          const struct cl_page_slice *slice);
581
582
583 #define lov_foreach_target(lov, var)                    \
584         for (var = 0; var < lov_targets_nr(lov); ++var)
585
586 /*****************************************************************************
587  *
588  * Type conversions.
589  *
590  * Accessors.
591  *
592  */
593
594 static inline struct lov_session *lov_env_session(const struct lu_env *env)
595 {
596         struct lov_session *ses;
597
598         ses = lu_context_key_get(env->le_ses, &lov_session_key);
599         LASSERT(ses != NULL);
600         return ses;
601 }
602
603 static inline struct lov_io *lov_env_io(const struct lu_env *env)
604 {
605         return &lov_env_session(env)->ls_io;
606 }
607
608 static inline int lov_is_object(const struct lu_object *obj)
609 {
610         return obj->lo_dev->ld_type == &lov_device_type;
611 }
612
613 static inline int lovsub_is_object(const struct lu_object *obj)
614 {
615         return obj->lo_dev->ld_type == &lovsub_device_type;
616 }
617
618 static inline struct lu_device *lov2lu_dev(struct lov_device *lov)
619 {
620         return &lov->ld_cl.cd_lu_dev;
621 }
622
623 static inline struct lov_device *lu2lov_dev(const struct lu_device *d)
624 {
625         LINVRNT(d->ld_type == &lov_device_type);
626         return container_of0(d, struct lov_device, ld_cl.cd_lu_dev);
627 }
628
629 static inline struct cl_device *lovsub2cl_dev(struct lovsub_device *lovsub)
630 {
631         return &lovsub->acid_cl;
632 }
633
634 static inline struct lu_device *lovsub2lu_dev(struct lovsub_device *lovsub)
635 {
636         return &lovsub2cl_dev(lovsub)->cd_lu_dev;
637 }
638
639 static inline struct lovsub_device *lu2lovsub_dev(const struct lu_device *d)
640 {
641         LINVRNT(d->ld_type == &lovsub_device_type);
642         return container_of0(d, struct lovsub_device, acid_cl.cd_lu_dev);
643 }
644
645 static inline struct lovsub_device *cl2lovsub_dev(const struct cl_device *d)
646 {
647         LINVRNT(d->cd_lu_dev.ld_type == &lovsub_device_type);
648         return container_of0(d, struct lovsub_device, acid_cl);
649 }
650
651 static inline struct lu_object *lov2lu(struct lov_object *lov)
652 {
653         return &lov->lo_cl.co_lu;
654 }
655
656 static inline struct cl_object *lov2cl(struct lov_object *lov)
657 {
658         return &lov->lo_cl;
659 }
660
661 static inline struct lov_object *lu2lov(const struct lu_object *obj)
662 {
663         LINVRNT(lov_is_object(obj));
664         return container_of0(obj, struct lov_object, lo_cl.co_lu);
665 }
666
667 static inline struct lov_object *cl2lov(const struct cl_object *obj)
668 {
669         LINVRNT(lov_is_object(&obj->co_lu));
670         return container_of0(obj, struct lov_object, lo_cl);
671 }
672
673 static inline struct lu_object *lovsub2lu(struct lovsub_object *los)
674 {
675         return &los->lso_cl.co_lu;
676 }
677
678 static inline struct cl_object *lovsub2cl(struct lovsub_object *los)
679 {
680         return &los->lso_cl;
681 }
682
683 static inline struct lovsub_object *cl2lovsub(const struct cl_object *obj)
684 {
685         LINVRNT(lovsub_is_object(&obj->co_lu));
686         return container_of0(obj, struct lovsub_object, lso_cl);
687 }
688
689 static inline struct lovsub_object *lu2lovsub(const struct lu_object *obj)
690 {
691         LINVRNT(lovsub_is_object(obj));
692         return container_of0(obj, struct lovsub_object, lso_cl.co_lu);
693 }
694
695 static inline struct lovsub_lock *
696 cl2lovsub_lock(const struct cl_lock_slice *slice)
697 {
698         LINVRNT(lovsub_is_object(&slice->cls_obj->co_lu));
699         return container_of(slice, struct lovsub_lock, lss_cl);
700 }
701
702 static inline struct lovsub_lock *cl2sub_lock(const struct cl_lock *lock)
703 {
704         const struct cl_lock_slice *slice;
705
706         slice = cl_lock_at(lock, &lovsub_device_type);
707         LASSERT(slice != NULL);
708         return cl2lovsub_lock(slice);
709 }
710
711 static inline struct lov_lock *cl2lov_lock(const struct cl_lock_slice *slice)
712 {
713         LINVRNT(lov_is_object(&slice->cls_obj->co_lu));
714         return container_of(slice, struct lov_lock, lls_cl);
715 }
716
717 static inline struct lov_page *cl2lov_page(const struct cl_page_slice *slice)
718 {
719         LINVRNT(lov_is_object(&slice->cpl_obj->co_lu));
720         return container_of0(slice, struct lov_page, lps_cl);
721 }
722
723 static inline struct lov_req *cl2lov_req(const struct cl_req_slice *slice)
724 {
725         return container_of0(slice, struct lov_req, lr_cl);
726 }
727
728 static inline struct lovsub_page *
729 cl2lovsub_page(const struct cl_page_slice *slice)
730 {
731         LINVRNT(lovsub_is_object(&slice->cpl_obj->co_lu));
732         return container_of0(slice, struct lovsub_page, lsb_cl);
733 }
734
735 static inline struct lovsub_req *cl2lovsub_req(const struct cl_req_slice *slice)
736 {
737         return container_of0(slice, struct lovsub_req, lsrq_cl);
738 }
739
740 static inline struct cl_page *lov_sub_page(const struct cl_page_slice *slice)
741 {
742         return slice->cpl_page->cp_child;
743 }
744
745 static inline struct lov_io *cl2lov_io(const struct lu_env *env,
746                                 const struct cl_io_slice *ios)
747 {
748         struct lov_io *lio;
749
750         lio = container_of(ios, struct lov_io, lis_cl);
751         LASSERT(lio == lov_env_io(env));
752         return lio;
753 }
754
755 static inline int lov_targets_nr(const struct lov_device *lov)
756 {
757         return lov->ld_lov->desc.ld_tgt_count;
758 }
759
760 static inline struct lov_thread_info *lov_env_info(const struct lu_env *env)
761 {
762         struct lov_thread_info *info;
763
764         info = lu_context_key_get(&env->le_ctx, &lov_key);
765         LASSERT(info != NULL);
766         return info;
767 }
768
769 static inline struct lov_layout_raid0 *lov_r0(struct lov_object *lov)
770 {
771         struct lov_layout_raid0 *raid0;
772
773         LASSERT(lov->lo_type == LLT_RAID0);
774         raid0 = &lov->u.raid0;
775         LASSERT(raid0->lo_lsm->lsm_wire.lw_magic == LOV_MAGIC);
776         return raid0;
777 }
778
779 /** @} lov */
780
781 #endif
782