Whamcloud - gitweb
LU-19098 hsm: don't print progname twice with lhsmtool
[fs/lustre-release.git] / lustre / lov / lov_cl_internal.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2
3 /*
4  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
5  * Use is subject to license terms.
6  *
7  * Copyright (c) 2012, 2017, Intel Corporation.
8  */
9
10 /*
11  * This file is part of Lustre, http://www.lustre.org/
12  *
13  * Internal interfaces of LOV layer.
14  *
15  * Author: Nikita Danilov <nikita.danilov@sun.com>
16  * Author: Jinshan Xiong <jinshan.xiong@intel.com>
17  */
18
19 #ifndef LOV_CL_INTERNAL_H
20 #define LOV_CL_INTERNAL_H
21
22 #include <libcfs/libcfs.h>
23 #include <obd.h>
24 #include <cl_object.h>
25 #include "lov_internal.h"
26
27 /* \defgroup lov lov
28  * Logical object volume layer. This layer implements data striping (raid0).
29  *
30  * At the lov layer top-entity (object, lock, io) is connected to one or
31  * more sub-entities: top-object, representing a file is connected to a set of
32  * sub-objects, each representing a stripe, file-level top-lock is connected
33  * to a set of per-stripe sub-locks, and a top-level IO is connected to a set of
34  * (potentially concurrent) sub-IO's.
35  *
36  * Sub-object and sub-io have well-defined top-object and top-io
37  * respectively, while a single sub-lock can be part of multiple top-locks.
38  *
39  * Reference counting models are different for different types of entities:
40  *
41  *     - top-object keeps a reference to its sub-objects, and destroys them
42  *       when it is destroyed.
43  *
44  *     - IO's are not reference counted.
45  *
46  * To implement a connection between top and sub entities, lov layer is split
47  * into two pieces: lov ("upper half"), and lovsub ("bottom half"), both
48  * implementing full set of cl-interfaces. For example, top-object has vvp and
49  * lov layers, and it's sub-object has lovsub and osc layers. lovsub layer is
50  * used to track child-parent relationship.
51  *
52  * @{
53  */
54
55 struct lovsub_device;
56 struct lovsub_object;
57
58 enum lov_device_flags {
59         LOV_DEV_INITIALIZED = BIT(0),
60 };
61
62 /*
63  * Upper half.
64  */
65
66 /* Data-on-MDT array item in lov_device::ld_md_tgts[] */
67 struct lovdom_device {
68         struct cl_device        *ldm_mdc;
69         int                      ldm_idx;
70 };
71
72 struct lov_device {
73         /*
74          * XXX Locking of lov-private data is missing.
75          */
76         struct cl_device          ld_cl;
77         struct lov_obd           *ld_lov;
78         /* size of lov_device::ld_target[] array */
79         __u32                     ld_target_nr;
80         struct lovsub_device    **ld_target;
81         __u32                     ld_flags;
82
83         /* Data-on-MDT devices */
84         __u32                     ld_md_tgts_nr;
85         struct lovdom_device     *ld_md_tgts;
86         struct obd_device        *ld_lmv;
87         /* LU site for subdevices */
88         struct lu_site            ld_site;
89 };
90
91 /*
92  * Layout type.
93  */
94 enum lov_layout_type {
95         LLT_EMPTY,      /* empty file without body (mknod + truncate) */
96         LLT_RELEASED,   /* file with no objects (data in HSM) */
97         LLT_COMP,       /* support composite layout */
98         LLT_FOREIGN,    /* foreign layout */
99         LLT_NR
100 };
101
102 static inline char *llt2str(enum lov_layout_type llt)
103 {
104         switch (llt) {
105         case LLT_EMPTY:
106                 return "EMPTY";
107         case LLT_RELEASED:
108                 return "RELEASED";
109         case LLT_COMP:
110                 return "COMPOSITE";
111         case LLT_FOREIGN:
112                 return "FOREIGN";
113         case LLT_NR:
114                 LBUG();
115         }
116         LBUG();
117         return "";
118 }
119
120 /*
121  * Return lov_layout_entry_type associated with a given composite layout
122  * entry.
123  */
124 static inline __u32 lov_entry_type(struct lov_stripe_md_entry *lsme)
125 {
126         if ((lov_pattern(lsme->lsme_pattern) & LOV_PATTERN_RAID0) ||
127             (lov_pattern(lsme->lsme_pattern) & LOV_PATTERN_MDT) ||
128             (lov_pattern(lsme->lsme_pattern) == LOV_PATTERN_FOREIGN))
129                 return lov_pattern(lsme->lsme_pattern &
130                            ~(LOV_PATTERN_OVERSTRIPING | LOV_PATTERN_COMPRESS));
131         return 0;
132 }
133
134 struct lov_layout_entry;
135 struct lov_object;
136 struct lov_lock_sub;
137
138 struct lov_comp_layout_entry_ops {
139         int (*lco_init)(const struct lu_env *env, struct lov_device *dev,
140                         struct lov_object *lov, unsigned int index,
141                         const struct cl_object_conf *conf,
142                         struct lov_layout_entry *lle);
143         void (*lco_fini)(const struct lu_env *env,
144                          struct lov_layout_entry *lle);
145         int  (*lco_getattr)(const struct lu_env *env, struct lov_object *obj,
146                             unsigned int index, struct lov_layout_entry *lle,
147                             struct cl_attr **attr);
148 };
149
150 struct lov_layout_raid0 {
151         unsigned int lo_nr;
152         /*
153          * When this is true, lov_object::lo_attr contains
154          * valid up to date attributes for a top-level
155          * object. This field is reset to 0 when attributes of
156          * any sub-object change.
157          */
158         bool                   lo_attr_valid;
159         /*
160          * Array of sub-objects. Allocated when top-object is
161          * created (lov_init_raid0()).
162          *
163          * Top-object is a strict master of its sub-objects:
164          * it is created before them, and outlives its
165          * children (this later is necessary so that basic
166          * functions like cl_object_top() always
167          * work). Top-object keeps a reference on every
168          * sub-object.
169          *
170          * When top-object is destroyed (lov_delete_raid0())
171          * it releases its reference to a sub-object and waits
172          * until the latter is finally destroyed.
173          */
174         struct lovsub_object **lo_sub;
175         /*
176          * protect lo_sub
177          */
178         spinlock_t              lo_sub_lock;
179         /*
180          * Cached object attribute, built from sub-object
181          * attributes.
182          */
183         struct cl_attr         lo_attr;
184 };
185
186 struct lov_layout_dom {
187         /* keep this always at first place so DOM layout entry
188          * can be addressed also as RAID0 after initialization.
189          */
190         struct lov_layout_raid0 lo_dom_r0;
191         struct lovsub_object *lo_dom;
192         struct lov_oinfo *lo_loi;
193         unsigned short lo_mdt_idx;
194 };
195
196 struct lov_layout_entry {
197         __u32                           lle_type;
198         unsigned int                    lle_valid:1;
199         unsigned int                    lle_preference;
200         struct lu_extent                *lle_extent;
201         struct lov_stripe_md_entry      *lle_lsme;
202         struct lov_comp_layout_entry_ops *lle_comp_ops;
203         union {
204                 struct lov_layout_raid0 lle_raid0;
205                 struct lov_layout_dom   lle_dom;
206         };
207 };
208
209 struct lov_mirror_entry {
210         unsigned short  lre_mirror_id;
211         unsigned short  lre_stale:1,    /* set if any components is stale */
212                         /* set if one of components in this mirror is valid */
213                         lre_valid:1,
214                         lre_foreign:1;  /* set if it is a foreign component */
215         int             lre_preference; /* overall preference of this mirror */
216
217         unsigned short  lre_start;      /* idx(lo_entries) start idx (mirror) */
218         unsigned short  lre_end;        /* end index of this mirror */
219 };
220
221 enum lov_object_flags {
222         /* Layout is invalid, set when layout lock is lost */
223         LO_LAYOUT_INVALID       = 0x1,
224         LO_NEED_INODE_LOCK      = 0x2,
225 };
226
227 /*
228  * lov-specific file state.
229  *
230  * lov object has particular layout type, determining how top-object is built
231  * on top of sub-objects. Layout type can change dynamically. When this
232  * happens, lov_object::lo_type_guard semaphore is taken in exclusive mode,
233  * all state pertaining to the old layout type is destroyed, and new state is
234  * constructed. All object methods take said semaphore in the shared mode,
235  * providing serialization against transition between layout types.
236  *
237  * To avoid multiple `if' or `switch' statements, selecting behavior for the
238  * current layout type, object methods perform double-dispatch, invoking
239  * function corresponding to the current layout type.
240  */
241 struct lov_object {
242         struct cl_object        lo_cl;
243         /*
244          * Serializes object operations with transitions between layout types.
245          *
246          * This semaphore is taken in shared mode by all object methods, and
247          * is taken in exclusive mode when object type is changed.
248          *
249          * \see lov_object::lo_type
250          */
251         struct rw_semaphore     lo_type_guard;
252         /*
253          * Type of an object. Protected by lov_object::lo_type_guard.
254          */
255         enum lov_layout_type    lo_type;
256         /*
257          * Object flags.
258          */
259         unsigned long           lo_obj_flags;
260         /*
261          * How many IOs are on going on this object. Layout can be changed
262          * only if there is no active IO.
263          */
264         atomic_t               lo_active_ios;
265         /*
266          * Waitq - wait for no one else is using lo_lsm
267          */
268         wait_queue_head_t       lo_waitq;
269         /*
270          * Layout metadata. NULL if empty layout.
271          */
272         struct lov_stripe_md  *lo_lsm;
273
274         union lov_layout_state {
275                 struct lov_layout_state_empty {
276                 } empty;
277                 struct lov_layout_state_released {
278                 } released;
279                 struct lov_layout_composite {
280                         /* flags of lov_comp_md_v1::lcm_flags. Mainly used
281                          * by FLR.
282                          */
283                         uint32_t        lo_flags;
284                         /* For FLR: index of preferred mirror to read.
285                          * Preferred mirror is initialized by the preferred
286                          * bit of lsme. It can be changed when the preferred
287                          * is inaccessible.
288                          */
289                         int             lo_preferred_mirror;
290                         /* For FLR: Number of (valid) mirrors. */
291                         unsigned int lo_mirror_count;
292                         struct lov_mirror_entry *lo_mirrors;
293                         /* Current entry count of lo_entries, include
294                          * invalid entries.
295                          */
296                         unsigned int    lo_entry_count;
297                         struct lov_layout_entry *lo_entries;
298                 } composite;
299         } u;
300         /* Thread that acquired lov_object::lo_type_guard in exclusive mode. */
301         struct task_struct            *lo_owner;
302 };
303
304 static inline const struct lu_fid *lov_object_fid(const struct lov_object *lov)
305 {
306         return lu_object_fid(&lov->lo_cl.co_lu);
307 }
308
309 static inline struct lov_stripe_md_entry *lov_lse(struct lov_object *lov, int i)
310 {
311         LASSERT(lov->lo_lsm != NULL);
312         LASSERT(i < lov->lo_lsm->lsm_entry_count);
313
314         return lov->lo_lsm->lsm_entries[i];
315 }
316
317 static inline unsigned int lov_flr_state(const struct lov_object *lov)
318 {
319         if (lov->lo_type != LLT_COMP)
320                 return LCM_FL_NONE;
321
322         return lov->u.composite.lo_flags & LCM_FL_FLR_MASK;
323 }
324
325 static inline bool lov_is_flr(const struct lov_object *lov)
326 {
327         return lov_flr_state(lov) != LCM_FL_NONE;
328 }
329
330 static inline struct lov_layout_entry *lov_entry(struct lov_object *lov, int i)
331 {
332         LASSERT(lov->lo_type == LLT_COMP);
333         LASSERTF(i < lov->u.composite.lo_entry_count,
334                  DFID" entry %d, entry_count %d\n",
335                  PFID(lov_object_fid(lov)),
336                  i, lov->u.composite.lo_entry_count);
337
338         return &lov->u.composite.lo_entries[i];
339 }
340
341 static inline struct lov_layout_raid0 *lov_r0(struct lov_object *lov, int i)
342 {
343         return &lov_entry(lov, i)->lle_raid0;
344 }
345
346 #define lov_for_layout_entry(lov, entry, start, end)                    \
347         if (lov->u.composite.lo_entries &&                              \
348             lov->u.composite.lo_entry_count > 0)                        \
349                 for (entry = lov_entry(lov, start);                     \
350                      entry <= lov_entry(lov, end); entry++)
351
352 #define lov_foreach_layout_entry(lov, entry)                            \
353         lov_for_layout_entry(lov, entry, 0,                             \
354                              (lov)->u.composite.lo_entry_count - 1)
355
356 #define lov_foreach_mirror_layout_entry(lov, entry, lre)                \
357         lov_for_layout_entry(lov, entry, (lre)->lre_start, (lre)->lre_end)
358
359 static inline struct lov_mirror_entry *
360 lov_mirror_entry(struct lov_object *lov, int i)
361 {
362         LASSERTF(i < lov->u.composite.lo_mirror_count,
363                  DFID" entry %d, mirror_count %d\n",
364                  PFID(lov_object_fid(lov)),
365                  i, lov->u.composite.lo_mirror_count);
366
367         return &lov->u.composite.lo_mirrors[i];
368 }
369
370 #define lov_foreach_mirror_entry(lov, lre)                              \
371         for (lre = lov_mirror_entry(lov, 0);                            \
372              lre <= lov_mirror_entry(lov,                               \
373                                 lov->u.composite.lo_mirror_count - 1);  \
374              lre++)
375
376 static inline unsigned
377 lov_layout_entry_index(struct lov_object *lov, struct lov_layout_entry *entry)
378 {
379         struct lov_layout_entry *first = &lov->u.composite.lo_entries[0];
380         unsigned int index = (unsigned int)(entry - first);
381
382         LASSERT(entry >= first);
383         LASSERT(index < lov->u.composite.lo_entry_count);
384
385         return index;
386 }
387
388 /* State lov_lock keeps for each sub-lock. */
389 struct lov_lock_sub {
390         /* sub-lock itself */
391         struct cl_lock          sub_lock;
392         /* Set if the sublock has ever been enqueued, meaning it may
393          * hold resources of underlying layers
394          */
395         unsigned int            sub_is_enqueued:1,
396                                 sub_initialized:1;
397         int                     sub_index;
398 };
399
400 /* lov-specific lock state. */
401 struct lov_lock {
402         struct cl_lock_slice    lls_cl;
403         /* Number of sub-locks in this lock */
404         int                     lls_nr;
405         /* sublock array */
406         struct lov_lock_sub     lls_sub[];
407 };
408
409 /* Bottom half. */
410 struct lovsub_device {
411         struct cl_device   acid_cl;
412         struct cl_device  *acid_next;
413 };
414
415 struct lovsub_object {
416         struct cl_object_header lso_header;
417         struct cl_object        lso_cl;
418         struct lov_object      *lso_super;
419         int                     lso_index;
420 };
421
422 /* Describe the environment settings for sublocks. */
423 struct lov_sublock_env {
424         const struct lu_env *lse_env;
425         struct cl_io        *lse_io;
426 };
427
428 struct lov_thread_info {
429         struct cl_object_conf   lti_stripe_conf;
430         struct lu_fid           lti_fid;
431         struct ost_lvb          lti_lvb;
432         struct cl_2queue        lti_cl2q;
433         struct cl_page_list     lti_plist;
434 };
435
436 /* State that lov_io maintains for every sub-io. */
437 struct lov_io_sub {
438         /* Linkage into a list (hanging off lov_io::lis_subios) */
439         struct list_head        sub_list;
440         /* Linkage into a list (hanging off lov_io::lis_active) of all
441          * sub-io's active for the current IO iteration.
442          */
443         struct list_head        sub_linkage;
444         unsigned int            sub_subio_index;
445         /* sub-io for a stripe. Ideally sub-io's can be stopped and resumed
446          * independently, with lov acting as a scheduler to maximize overall
447          * throughput.
448          */
449         struct cl_io            sub_io;
450         /* environment, in which sub-io executes. */
451         struct lu_env           *sub_env;
452         /* environment's refcheck. (cl_env_get()) */
453         __u16                   sub_refcheck;
454 };
455
456 /* IO state private for LOV. */
457 #define LIS_CACHE_ENTRY_NONE    -ENOENT
458 struct lov_io {
459         /* super-class */
460         struct cl_io_slice lis_cl;
461
462         /* FLR: index to lo_mirrors. Valid only if lov_is_flr() returns true.
463          *
464          * The mirror index of this io. Preserved over cl_io_init()
465          * if io->ci_ndelay_tried is greater than zero.
466          */
467         int                     lis_mirror_index;
468         /* FLR: the layout gen when lis_mirror_index was cached. The
469          * mirror index makes sense only when the layout gen doesn't
470          * change.
471          */
472         int                     lis_mirror_layout_gen;
473
474         /* fields below this will be initialized in lov_io_init(). */
475         unsigned int lis_preserved;
476
477         /* Pointer to obj slice. Duplicate of lov_io::lis_cl::cis_object. */
478         struct lov_object *lis_object;
479         /*
480          * Original end-of-io position for this IO, set by the upper layer as
481          * cl_io::u::ci_rw::pos + cl_io::u::ci_rw::count. lov remembers this,
482          * changes pos and count to fit IO into a single stripe and uses saved
483          * value to determine when IO iterations have to stop.
484          *
485          * This is used only for CIT_READ and CIT_WRITE io's.
486          */
487         loff_t             lis_io_endpos;
488
489         /* Record stripe index before the truncate size, used for setting OST
490          * obj size for truncate. LU-14128. lis_trunc_stripe_index[i] refers to
491          * lov_object.u.composite.lo_entries[i].
492          */
493         int *lis_trunc_stripe_index;
494
495         /* starting position within a file, for the current io loop iteration
496          * (stripe), used by ci_io_loop().
497          */
498         loff_t                  lis_pos;
499         /* end position with in a file, for the current stripe io. This is
500          * exclusive (i.e., next offset after last byte affected by io).
501          */
502         loff_t                  lis_endpos;
503         int                     lis_nr_subios;
504
505         /* the index of ls_single_subio in ls_subios array */
506         int                     lis_single_subio_index;
507         struct lov_io_sub       lis_single_subio;
508
509         /* List of active sub-io's. Active sub-io's are under the range
510          * of [lis_pos, lis_endpos).
511          */
512         struct list_head        lis_active;
513         /* All sub-io's created in this lov_io. */
514         struct list_head        lis_subios;
515         /* Cached results from stripe & offset calculations for page init */
516         int                     lis_cached_entry;
517         int                     lis_cached_stripe;
518         loff_t                  lis_cached_off;
519         loff_t                  lis_cached_suboff;
520         struct lov_io_sub       *lis_cached_sub;
521 };
522
523 struct lov_session {
524         struct lov_io          ls_io;
525         struct lov_sublock_env ls_subenv;
526 };
527
528 extern struct lu_device_type lov_device_type;
529 extern struct lu_device_type lovsub_device_type;
530
531 extern struct lu_context_key lov_key;
532 extern struct lu_context_key lov_session_key;
533
534 extern struct kmem_cache *lov_lock_kmem;
535 extern struct kmem_cache *lov_object_kmem;
536 extern struct kmem_cache *lov_thread_kmem;
537 extern struct kmem_cache *lov_session_kmem;
538
539 extern struct kmem_cache *lovsub_object_kmem;
540
541 int   lov_lock_init_composite(const struct lu_env *env, struct cl_object *obj,
542                            struct cl_lock *lock, const struct cl_io *io);
543 int   lov_lock_init_empty(const struct lu_env *env, struct cl_object *obj,
544                            struct cl_lock *lock, const struct cl_io *io);
545 int   lov_io_init_composite(const struct lu_env *env, struct cl_object *obj,
546                            struct cl_io *io);
547 int   lov_io_init_empty(const struct lu_env *env, struct cl_object *obj,
548                            struct cl_io *io);
549 int   lov_io_init_released(const struct lu_env *env, struct cl_object *obj,
550                            struct cl_io *io);
551
552 struct lov_io_sub *lov_sub_get(const struct lu_env *env, struct lov_io *lio,
553                                int stripe);
554
555 enum {
556         CP_LOV_INDEX_EMPTY = -1U,
557 };
558
559 static inline bool lov_pages_is_empty(struct cl_dio_pages *cdp)
560 {
561         return cdp->cdp_lov_index == CP_LOV_INDEX_EMPTY;
562 }
563
564 static inline bool lov_page_is_empty(const struct cl_page *cp)
565 {
566         return cp->cp_lov_index == CP_LOV_INDEX_EMPTY;
567 }
568
569
570 int lov_dio_pages_init_empty(const struct lu_env *env, struct cl_object *obj,
571                              struct cl_dio_pages *cdp, pgoff_t index);
572 int lov_dio_pages_init_composite(const struct lu_env *env,
573                                  struct cl_object *obj,
574                                  struct cl_dio_pages *cdp, pgoff_t index);
575 int lov_dio_pages_init_foreign(const struct lu_env *env, struct cl_object *obj,
576                                struct cl_dio_pages *cdp, pgoff_t index);
577 int   lov_page_init_empty(const struct lu_env *env, struct cl_object *obj,
578                            struct cl_page *page, pgoff_t index);
579 int   lov_page_init_composite(const struct lu_env *env, struct cl_object *obj,
580                            struct cl_page *page, pgoff_t index);
581 int   lov_page_init_foreign(const struct lu_env *env, struct cl_object *obj,
582                              struct cl_page *page, pgoff_t index);
583 struct lu_object *lov_object_alloc(const struct lu_env *env,
584                                       const struct lu_object_header *hdr,
585                                       struct lu_device *dev);
586
587 struct lu_object *lovsub_object_alloc(const struct lu_env *env,
588                                       const struct lu_object_header *hdr,
589                                       struct lu_device *dev);
590
591 int lov_io_layout_at(struct lov_io *lio, __u64 offset);
592 bool lov_io_layout_at_confirm(struct lov_io *lio, int entry, __u64 offset);
593
594 static inline struct lu_extent *lov_io_extent(struct lov_io *io, int i)
595 {
596         return &lov_lse(io->lis_object, i)->lsme_extent;
597 }
598
599 /* For layout entries within @ext. */
600 #define lov_foreach_io_layout(ind, lio, ext)                            \
601         for (ind = lov_io_layout_at(lio, (ext)->e_start);               \
602              ind >= 0 &&                                                \
603              lu_extent_is_overlapped(lov_io_extent(lio, ind), ext);     \
604              ind = lov_io_layout_at(lio, lov_io_extent(lio, ind)->e_end))
605
606 /*
607  * Type conversions.
608  *
609  * Accessors.
610  */
611 static inline struct lov_session *lov_env_session(const struct lu_env *env)
612 {
613         struct lov_session *ses;
614
615         ses = lu_context_key_get(env->le_ses, &lov_session_key);
616         LASSERT(ses != NULL);
617         return ses;
618 }
619
620 static inline struct lov_io *lov_env_io(const struct lu_env *env)
621 {
622         return &lov_env_session(env)->ls_io;
623 }
624
625 static inline int lov_is_object(const struct lu_object *obj)
626 {
627         return obj->lo_dev->ld_type == &lov_device_type;
628 }
629
630 static inline int lovsub_is_object(const struct lu_object *obj)
631 {
632         return obj->lo_dev->ld_type == &lovsub_device_type;
633 }
634
635 static inline struct lu_device *lov2lu_dev(struct lov_device *lov)
636 {
637         return &lov->ld_cl.cd_lu_dev;
638 }
639
640 static inline struct lov_device *lu2lov_dev(const struct lu_device *d)
641 {
642         LINVRNT(d->ld_type == &lov_device_type);
643         return container_of(d, struct lov_device, ld_cl.cd_lu_dev);
644 }
645
646 static inline struct cl_device *lovsub2cl_dev(struct lovsub_device *lovsub)
647 {
648         return &lovsub->acid_cl;
649 }
650
651 static inline struct lu_device *lovsub2lu_dev(struct lovsub_device *lovsub)
652 {
653         return &lovsub2cl_dev(lovsub)->cd_lu_dev;
654 }
655
656 static inline struct lovsub_device *lu2lovsub_dev(const struct lu_device *d)
657 {
658         LINVRNT(d->ld_type == &lovsub_device_type);
659         return container_of(d, struct lovsub_device, acid_cl.cd_lu_dev);
660 }
661
662 static inline struct lovsub_device *cl2lovsub_dev(const struct cl_device *d)
663 {
664         LINVRNT(d->cd_lu_dev.ld_type == &lovsub_device_type);
665         return container_of(d, struct lovsub_device, acid_cl);
666 }
667
668 static inline struct lu_object *lov2lu(struct lov_object *lov)
669 {
670         return &lov->lo_cl.co_lu;
671 }
672
673 static inline struct cl_object *lov2cl(struct lov_object *lov)
674 {
675         return &lov->lo_cl;
676 }
677
678 static inline struct lov_object *lu2lov(const struct lu_object *obj)
679 {
680         LINVRNT(lov_is_object(obj));
681         return container_of(obj, struct lov_object, lo_cl.co_lu);
682 }
683
684 static inline struct lov_object *cl2lov(const struct cl_object *obj)
685 {
686         LINVRNT(lov_is_object(&obj->co_lu));
687         return container_of(obj, struct lov_object, lo_cl);
688 }
689
690 static inline struct lu_object *lovsub2lu(struct lovsub_object *los)
691 {
692         return &los->lso_cl.co_lu;
693 }
694
695 static inline struct cl_object *lovsub2cl(struct lovsub_object *los)
696 {
697         return &los->lso_cl;
698 }
699
700 static inline struct lovsub_object *cl2lovsub(const struct cl_object *obj)
701 {
702         LINVRNT(lovsub_is_object(&obj->co_lu));
703         return container_of(obj, struct lovsub_object, lso_cl);
704 }
705
706 static inline struct lovsub_object *lu2lovsub(const struct lu_object *obj)
707 {
708         LINVRNT(lovsub_is_object(obj));
709         return container_of(obj, struct lovsub_object, lso_cl.co_lu);
710 }
711
712 static inline struct lov_lock *cl2lov_lock(const struct cl_lock_slice *slice)
713 {
714         LINVRNT(lov_is_object(&slice->cls_obj->co_lu));
715         return container_of(slice, struct lov_lock, lls_cl);
716 }
717
718 static inline struct lov_io *cl2lov_io(const struct lu_env *env,
719                                 const struct cl_io_slice *ios)
720 {
721         struct lov_io *lio;
722
723         lio = container_of(ios, struct lov_io, lis_cl);
724         LASSERT(lio == lov_env_io(env));
725         return lio;
726 }
727
728 static inline struct lov_thread_info *lov_env_info(const struct lu_env *env)
729 {
730         struct lov_thread_info *info;
731
732         info = lu_context_key_get(&env->le_ctx, &lov_key);
733         LASSERT(info != NULL);
734         return info;
735 }
736
737 /* lov_pack.c */
738 int lov_getstripe(const struct lu_env *env, struct lov_object *obj,
739                   struct lov_stripe_md *lsm, struct lov_user_md __user *lump,
740                   size_t size);
741
742 #endif