Whamcloud - gitweb
d75b53be125758f833f6f76ad959bf91af63bd49
[fs/lustre-release.git] / lustre / lov / lov_object.c
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  * Implementation of cl_object for LOV layer.
37  *
38  *   Author: Nikita Danilov <nikita.danilov@sun.com>
39  */
40
41 #define DEBUG_SUBSYSTEM S_LOV
42
43 #include "lov_cl_internal.h"
44
45 /** \addtogroup lov
46  *  @{
47  */
48
49 /*****************************************************************************
50  *
51  * Layout operations.
52  *
53  */
54
55 struct lov_layout_operations {
56         int (*llo_init)(const struct lu_env *env, struct lov_device *dev,
57                         struct lov_object *lov,
58                         const struct cl_object_conf *conf,
59                         union lov_layout_state *state);
60         void (*llo_delete)(const struct lu_env *env, struct lov_object *lov,
61                            union lov_layout_state *state);
62         void (*llo_fini)(const struct lu_env *env, struct lov_object *lov,
63                          union lov_layout_state *state);
64         void (*llo_install)(const struct lu_env *env, struct lov_object *lov,
65                             union lov_layout_state *state);
66         int  (*llo_print)(const struct lu_env *env, void *cookie,
67                           lu_printer_t p, const struct lu_object *o);
68         struct cl_page *(*llo_page_init)(const struct lu_env *env,
69                                          struct cl_object *obj,
70                                          struct cl_page *page,
71                                          cfs_page_t *vmpage);
72         int  (*llo_lock_init)(const struct lu_env *env,
73                               struct cl_object *obj, struct cl_lock *lock,
74                               const struct cl_io *io);
75         int  (*llo_io_init)(const struct lu_env *env,
76                             struct cl_object *obj, struct cl_io *io);
77         int  (*llo_getattr)(const struct lu_env *env, struct cl_object *obj,
78                             struct cl_attr *attr);
79 };
80
81 /*****************************************************************************
82  *
83  * Lov object layout operations.
84  *
85  */
86
87 static void lov_install_empty(const struct lu_env *env,
88                               struct lov_object *lov,
89                               union  lov_layout_state *state)
90 {
91         /*
92          * File without objects.
93          */
94 }
95
96 static int lov_init_empty(const struct lu_env *env,
97                           struct lov_device *dev, struct lov_object *lov,
98                           const struct cl_object_conf *conf,
99                           union  lov_layout_state *state)
100 {
101         return 0;
102 }
103
104 static void lov_install_raid0(const struct lu_env *env,
105                               struct lov_object *lov,
106                               union  lov_layout_state *state)
107 {
108         lov->u = *state;
109 }
110
111 static struct cl_object *lov_sub_find(const struct lu_env *env,
112                                       struct cl_device *dev,
113                                       const struct lu_fid *fid,
114                                       const struct cl_object_conf *conf)
115 {
116         struct lu_object *o;
117
118         ENTRY;
119         o = lu_object_find_at(env, cl2lu_dev(dev), fid, &conf->coc_lu);
120         LASSERT(ergo(!IS_ERR(o), o->lo_dev->ld_type == &lovsub_device_type));
121         RETURN(lu2cl(o));
122 }
123
124 static int lov_init_sub(const struct lu_env *env, struct lov_object *lov,
125                         struct cl_object *stripe,
126                         struct lov_layout_raid0 *r0, int idx)
127 {
128         struct cl_object_header *hdr;
129         struct cl_object_header *subhdr;
130         struct cl_object_header *parent;
131         struct lov_oinfo        *oinfo;
132         int result;
133
134         hdr    = cl_object_header(lov2cl(lov));
135         subhdr = cl_object_header(stripe);
136         parent = subhdr->coh_parent;
137
138         oinfo = r0->lo_lsm->lsm_oinfo[idx];
139         CDEBUG(D_INODE, DFID"@%p[%d] -> "DFID"@%p: id: "LPU64" seq: "LPU64
140                " idx: %d gen: %d\n",
141                PFID(&subhdr->coh_lu.loh_fid), subhdr, idx,
142                PFID(&hdr->coh_lu.loh_fid), hdr,
143                oinfo->loi_id, oinfo->loi_seq,
144                oinfo->loi_ost_idx, oinfo->loi_ost_gen);
145
146         if (parent == NULL) {
147                 subhdr->coh_parent = hdr;
148                 subhdr->coh_nesting = hdr->coh_nesting + 1;
149                 lu_object_ref_add(&stripe->co_lu, "lov-parent", lov);
150                 r0->lo_sub[idx] = cl2lovsub(stripe);
151                 r0->lo_sub[idx]->lso_super = lov;
152                 r0->lo_sub[idx]->lso_index = idx;
153                 result = 0;
154         } else {
155                 CERROR("Stripe is already owned by other file (%i).\n", idx);
156                 LU_OBJECT_DEBUG(D_ERROR, env, &stripe->co_lu, "\n");
157                 LU_OBJECT_DEBUG(D_ERROR, env, lu_object_top(&parent->coh_lu),
158                                 "old\n");
159                 LU_OBJECT_HEADER(D_ERROR, env, lov2lu(lov), "new\n");
160                 cl_object_put(env, stripe);
161                 result = -EIO;
162         }
163         return result;
164 }
165
166 static int lov_init_raid0(const struct lu_env *env,
167                           struct lov_device *dev, struct lov_object *lov,
168                           const struct cl_object_conf *conf,
169                           union  lov_layout_state *state)
170 {
171         int result;
172         int i;
173
174         struct cl_object        *stripe;
175         struct lov_thread_info  *lti     = lov_env_info(env);
176         struct cl_object_conf   *subconf = &lti->lti_stripe_conf;
177         struct lov_stripe_md    *lsm     = conf->u.coc_md->lsm;
178         struct lu_fid           *ofid    = &lti->lti_fid;
179         struct lov_layout_raid0 *r0      = &state->raid0;
180
181         ENTRY;
182         r0->lo_nr  = conf->u.coc_md->lsm->lsm_stripe_count;
183         r0->lo_lsm = conf->u.coc_md->lsm;
184         LASSERT(r0->lo_nr <= lov_targets_nr(dev));
185
186         OBD_ALLOC(r0->lo_sub, r0->lo_nr * sizeof r0->lo_sub[0]);
187         if (r0->lo_sub != NULL) {
188                 result = 0;
189                 subconf->coc_inode = conf->coc_inode;
190                 cfs_spin_lock_init(&r0->lo_sub_lock);
191                 /*
192                  * Create stripe cl_objects.
193                  */
194                 for (i = 0; i < r0->lo_nr && result == 0; ++i) {
195                         struct cl_device *subdev;
196                         struct lov_oinfo *oinfo = lsm->lsm_oinfo[i];
197                         int ost_idx = oinfo->loi_ost_idx;
198
199                         fid_ostid_unpack(ofid, &oinfo->loi_oi,
200                                          oinfo->loi_ost_idx);
201                         subdev = lovsub2cl_dev(dev->ld_target[ost_idx]);
202                         subconf->u.coc_oinfo = oinfo;
203                         LASSERTF(subdev != NULL, "not init ost %d\n", ost_idx);
204                         stripe = lov_sub_find(env, subdev, ofid, subconf);
205                         if (!IS_ERR(stripe))
206                                 result = lov_init_sub(env, lov, stripe, r0, i);
207                         else
208                                 result = PTR_ERR(stripe);
209                 }
210         } else
211                 result = -ENOMEM;
212         RETURN(result);
213 }
214
215 static void lov_delete_empty(const struct lu_env *env, struct lov_object *lov,
216                              union lov_layout_state *state)
217 {
218         LASSERT(lov->lo_type == LLT_EMPTY);
219 }
220
221 static void lov_subobject_kill(const struct lu_env *env, struct lov_object *lov,
222                                struct lovsub_object *los, int idx)
223 {
224         struct cl_object        *sub;
225         struct lov_layout_raid0 *r0;
226         struct lu_site          *site;
227         cfs_waitlink_t          *waiter;
228
229         r0  = &lov->u.raid0;
230         LASSERT(r0->lo_sub[idx] == los);
231
232         sub  = lovsub2cl(los);
233         site = sub->co_lu.lo_dev->ld_site;
234
235         cl_object_kill(env, sub);
236         /* release a reference to the sub-object and ... */
237         lu_object_ref_del(&sub->co_lu, "lov-parent", lov);
238         cl_object_put(env, sub);
239
240         /* ... wait until it is actually destroyed---sub-object clears its
241          * ->lo_sub[] slot in lovsub_object_fini() */
242         if (r0->lo_sub[idx] == los) {
243                 waiter = &lov_env_info(env)->lti_waiter;
244                 cfs_waitlink_init(waiter);
245                 cfs_waitq_add(&site->ls_marche_funebre, waiter);
246                 cfs_set_current_state(CFS_TASK_UNINT);
247                 while (1) {
248                         /* this wait-queue is signaled at the end of
249                          * lu_object_free(). */
250                         cfs_set_current_state(CFS_TASK_UNINT);
251                         cfs_spin_lock(&r0->lo_sub_lock);
252                         if (r0->lo_sub[idx] == los) {
253                                 cfs_spin_unlock(&r0->lo_sub_lock);
254                                 cfs_waitq_wait(waiter, CFS_TASK_UNINT);
255                         } else {
256                                 cfs_spin_unlock(&r0->lo_sub_lock);
257                                 cfs_set_current_state(CFS_TASK_RUNNING);
258                                 break;
259                         }
260                 }
261                 cfs_waitq_del(&site->ls_marche_funebre, waiter);
262         }
263         LASSERT(r0->lo_sub[idx] == NULL);
264 }
265
266 static void lov_delete_raid0(const struct lu_env *env, struct lov_object *lov,
267                              union lov_layout_state *state)
268 {
269         struct lov_layout_raid0 *r0 = &state->raid0;
270         int                      i;
271
272         ENTRY;
273         if (r0->lo_sub != NULL) {
274                 for (i = 0; i < r0->lo_nr; ++i) {
275                         struct lovsub_object *los = r0->lo_sub[i];
276
277                         if (los != NULL)
278                                 /*
279                                  * If top-level object is to be evicted from
280                                  * the cache, so are its sub-objects.
281                                  */
282                                 lov_subobject_kill(env, lov, los, i);
283                 }
284         }
285         EXIT;
286 }
287
288 static void lov_fini_empty(const struct lu_env *env, struct lov_object *lov,
289                            union lov_layout_state *state)
290 {
291         LASSERT(lov->lo_type == LLT_EMPTY);
292 }
293
294 static void lov_fini_raid0(const struct lu_env *env, struct lov_object *lov,
295                            union lov_layout_state *state)
296 {
297         struct lov_layout_raid0 *r0 = &state->raid0;
298
299         ENTRY;
300         if (r0->lo_sub != NULL) {
301                 OBD_FREE(r0->lo_sub, r0->lo_nr * sizeof r0->lo_sub[0]);
302                 r0->lo_sub = NULL;
303         }
304         EXIT;
305 }
306
307 static int lov_print_empty(const struct lu_env *env, void *cookie,
308                            lu_printer_t p, const struct lu_object *o)
309 {
310         (*p)(env, cookie, "empty\n");
311         return 0;
312 }
313
314 static int lov_print_raid0(const struct lu_env *env, void *cookie,
315                            lu_printer_t p, const struct lu_object *o)
316 {
317         struct lov_object       *lov = lu2lov(o);
318         struct lov_layout_raid0 *r0  = lov_r0(lov);
319         int i;
320
321         (*p)(env, cookie, "stripes: %d:\n", r0->lo_nr);
322         for (i = 0; i < r0->lo_nr; ++i) {
323                 struct lu_object *sub;
324
325                 if (r0->lo_sub[i] != NULL) {
326                         sub = lovsub2lu(r0->lo_sub[i]);
327                         lu_object_print(env, cookie, p, sub);
328                 } else
329                         (*p)(env, cookie, "sub %d absent\n", i);
330         }
331         return 0;
332 }
333
334 /**
335  * Implements cl_object_operations::coo_attr_get() method for an object
336  * without stripes (LLT_EMPTY layout type).
337  *
338  * The only attributes this layer is authoritative in this case is
339  * cl_attr::cat_blocks---it's 0.
340  */
341 static int lov_attr_get_empty(const struct lu_env *env, struct cl_object *obj,
342                               struct cl_attr *attr)
343 {
344         attr->cat_blocks = 0;
345         return 0;
346 }
347
348 static int lov_attr_get_raid0(const struct lu_env *env, struct cl_object *obj,
349                               struct cl_attr *attr)
350 {
351         struct lov_object       *lov = cl2lov(obj);
352         struct lov_layout_raid0 *r0 = lov_r0(lov);
353         struct lov_stripe_md    *lsm = lov->u.raid0.lo_lsm;
354         struct ost_lvb          *lvb = &lov_env_info(env)->lti_lvb;
355         __u64                    kms;
356         int                      result = 0;
357
358         ENTRY;
359         if (!r0->lo_attr_valid) {
360                 /*
361                  * Fill LVB with attributes already initialized by the upper
362                  * layer.
363                  */
364                 cl_attr2lvb(lvb, attr);
365                 kms = attr->cat_kms;
366
367                 /*
368                  * XXX that should be replaced with a loop over sub-objects,
369                  * doing cl_object_attr_get() on them. But for now, let's
370                  * reuse old lov code.
371                  */
372
373                 /*
374                  * XXX take lsm spin-lock to keep lov_merge_lvb_kms()
375                  * happy. It's not needed, because new code uses
376                  * ->coh_attr_guard spin-lock to protect consistency of
377                  * sub-object attributes.
378                  */
379                 lov_stripe_lock(lsm);
380                 result = lov_merge_lvb_kms(lsm, lvb, &kms);
381                 lov_stripe_unlock(lsm);
382                 if (result == 0) {
383                         cl_lvb2attr(attr, lvb);
384                         attr->cat_kms = kms;
385                         r0->lo_attr_valid = 1;
386                         r0->lo_attr = *attr;
387                 }
388         } else
389                 *attr = r0->lo_attr;
390         RETURN(result);
391 }
392
393 const static struct lov_layout_operations lov_dispatch[] = {
394         [LLT_EMPTY] = {
395                 .llo_init      = lov_init_empty,
396                 .llo_delete    = lov_delete_empty,
397                 .llo_fini      = lov_fini_empty,
398                 .llo_install   = lov_install_empty,
399                 .llo_print     = lov_print_empty,
400                 .llo_page_init = lov_page_init_empty,
401                 .llo_lock_init = NULL,
402                 .llo_io_init   = lov_io_init_empty,
403                 .llo_getattr   = lov_attr_get_empty
404         },
405         [LLT_RAID0] = {
406                 .llo_init      = lov_init_raid0,
407                 .llo_delete    = lov_delete_raid0,
408                 .llo_fini      = lov_fini_raid0,
409                 .llo_install   = lov_install_raid0,
410                 .llo_print     = lov_print_raid0,
411                 .llo_page_init = lov_page_init_raid0,
412                 .llo_lock_init = lov_lock_init_raid0,
413                 .llo_io_init   = lov_io_init_raid0,
414                 .llo_getattr   = lov_attr_get_raid0
415         }
416 };
417
418
419 /**
420  * Performs a double-dispatch based on the layout type of an object.
421  */
422 #define LOV_2DISPATCH_NOLOCK(obj, op, ...)                              \
423 ({                                                                      \
424         struct lov_object                      *__obj = (obj);          \
425         enum lov_layout_type                    __llt;                  \
426                                                                         \
427         __llt = __obj->lo_type;                                         \
428         LASSERT(0 <= __llt && __llt < ARRAY_SIZE(lov_dispatch));        \
429         lov_dispatch[__llt].op(__VA_ARGS__);                            \
430 })
431
432 #define LOV_2DISPATCH_MAYLOCK(obj, op, lock, ...)                       \
433 ({                                                                      \
434         struct lov_object                      *__obj = (obj);          \
435         int                                     __lock = !!(lock);      \
436         typeof(lov_dispatch[0].op(__VA_ARGS__)) __result;               \
437                                                                         \
438         __lock &= __obj->lo_owner != cfs_current();                     \
439         if (__lock)                                                     \
440                 cfs_down_read(&__obj->lo_type_guard);                   \
441         __result = LOV_2DISPATCH_NOLOCK(obj, op, __VA_ARGS__);          \
442         if (__lock)                                                     \
443                 cfs_up_read(&__obj->lo_type_guard);                     \
444         __result;                                                       \
445 })
446
447 /**
448  * Performs a locked double-dispatch based on the layout type of an object.
449  */
450 #define LOV_2DISPATCH(obj, op, ...)                     \
451         LOV_2DISPATCH_MAYLOCK(obj, op, 1, __VA_ARGS__)
452
453 #define LOV_2DISPATCH_VOID(obj, op, ...)                                \
454 do {                                                                    \
455         struct lov_object                      *__obj = (obj);          \
456         enum lov_layout_type                    __llt;                  \
457                                                                         \
458         if (__obj->lo_owner != cfs_current())                           \
459                 cfs_down_read(&__obj->lo_type_guard);                   \
460         __llt = __obj->lo_type;                                         \
461         LASSERT(0 <= __llt && __llt < ARRAY_SIZE(lov_dispatch));        \
462         lov_dispatch[__llt].op(__VA_ARGS__);                            \
463         if (__obj->lo_owner != cfs_current())                           \
464                 cfs_up_read(&__obj->lo_type_guard);                     \
465 } while (0)
466
467 static int lov_layout_change(const struct lu_env *env,
468                              struct lov_object *obj, enum lov_layout_type llt,
469                              const struct cl_object_conf *conf)
470 {
471         int result;
472         union lov_layout_state       *state = &lov_env_info(env)->lti_state;
473         const struct lov_layout_operations *old_ops;
474         const struct lov_layout_operations *new_ops;
475
476         LASSERT(0 <= obj->lo_type && obj->lo_type < ARRAY_SIZE(lov_dispatch));
477         LASSERT(0 <= llt && llt < ARRAY_SIZE(lov_dispatch));
478         ENTRY;
479
480         old_ops = &lov_dispatch[obj->lo_type];
481         new_ops = &lov_dispatch[llt];
482
483         result = new_ops->llo_init(env, lu2lov_dev(obj->lo_cl.co_lu.lo_dev),
484                                    obj, conf, state);
485         if (result == 0) {
486                 struct cl_object_header *hdr = cl_object_header(&obj->lo_cl);
487                 void                    *cookie;
488                 struct lu_env           *nested;
489                 int                      refcheck;
490
491                 cookie = cl_env_reenter();
492                 nested = cl_env_get(&refcheck);
493                 if (!IS_ERR(nested))
494                         cl_object_prune(nested, &obj->lo_cl);
495                 else
496                         result = PTR_ERR(nested);
497                 cl_env_put(nested, &refcheck);
498                 cl_env_reexit(cookie);
499
500                 old_ops->llo_fini(env, obj, &obj->u);
501                 LASSERT(cfs_list_empty(&hdr->coh_locks));
502                 LASSERT(hdr->coh_tree.rnode == NULL);
503                 LASSERT(hdr->coh_pages == 0);
504
505                 new_ops->llo_install(env, obj, state);
506                 obj->lo_type = llt;
507         } else
508                 new_ops->llo_fini(env, obj, state);
509         RETURN(result);
510 }
511
512 /*****************************************************************************
513  *
514  * Lov object operations.
515  *
516  */
517
518 int lov_object_init(const struct lu_env *env, struct lu_object *obj,
519                     const struct lu_object_conf *conf)
520 {
521         struct lov_device            *dev   = lu2lov_dev(obj->lo_dev);
522         struct lov_object            *lov   = lu2lov(obj);
523         const struct cl_object_conf  *cconf = lu2cl_conf(conf);
524         union  lov_layout_state      *set   = &lov_env_info(env)->lti_state;
525         const struct lov_layout_operations *ops;
526         int result;
527
528         ENTRY;
529         cfs_init_rwsem(&lov->lo_type_guard);
530
531         /* no locking is necessary, as object is being created */
532         lov->lo_type = cconf->u.coc_md->lsm != NULL ? LLT_RAID0 : LLT_EMPTY;
533         ops = &lov_dispatch[lov->lo_type];
534         result = ops->llo_init(env, dev, lov, cconf, set);
535         if (result == 0)
536                 ops->llo_install(env, lov, set);
537         else
538                 ops->llo_fini(env, lov, set);
539         RETURN(result);
540 }
541
542 static int lov_conf_set(const struct lu_env *env, struct cl_object *obj,
543                         const struct cl_object_conf *conf)
544 {
545         struct lov_object *lov = cl2lov(obj);
546         int result;
547
548         ENTRY;
549         /*
550          * Currently only LLT_EMPTY -> LLT_RAID0 transition is supported.
551          */
552         LASSERT(lov->lo_owner != cfs_current());
553         cfs_down_write(&lov->lo_type_guard);
554         LASSERT(lov->lo_owner == NULL);
555         lov->lo_owner = cfs_current();
556         if (lov->lo_type == LLT_EMPTY && conf->u.coc_md->lsm != NULL)
557                 result = lov_layout_change(env, lov, LLT_RAID0, conf);
558         else
559                 result = -EOPNOTSUPP;
560         lov->lo_owner = NULL;
561         cfs_up_write(&lov->lo_type_guard);
562         RETURN(result);
563 }
564
565 static void lov_object_delete(const struct lu_env *env, struct lu_object *obj)
566 {
567         struct lov_object *lov = lu2lov(obj);
568
569         ENTRY;
570         LOV_2DISPATCH_VOID(lov, llo_delete, env, lov, &lov->u);
571         EXIT;
572 }
573
574 static void lov_object_free(const struct lu_env *env, struct lu_object *obj)
575 {
576         struct lov_object *lov = lu2lov(obj);
577
578         ENTRY;
579         LOV_2DISPATCH_VOID(lov, llo_fini, env, lov, &lov->u);
580         lu_object_fini(obj);
581         OBD_SLAB_FREE_PTR(lov, lov_object_kmem);
582         EXIT;
583 }
584
585 static int lov_object_print(const struct lu_env *env, void *cookie,
586                             lu_printer_t p, const struct lu_object *o)
587 {
588         return LOV_2DISPATCH(lu2lov(o), llo_print, env, cookie, p, o);
589 }
590
591 struct cl_page *lov_page_init(const struct lu_env *env, struct cl_object *obj,
592                               struct cl_page *page, cfs_page_t *vmpage)
593 {
594         return LOV_2DISPATCH(cl2lov(obj),
595                              llo_page_init, env, obj, page, vmpage);
596 }
597
598 /**
599  * Implements cl_object_operations::clo_io_init() method for lov
600  * layer. Dispatches to the appropriate layout io initialization method.
601  */
602 int lov_io_init(const struct lu_env *env, struct cl_object *obj,
603                 struct cl_io *io)
604 {
605         CL_IO_SLICE_CLEAN(lov_env_io(env), lis_cl);
606         /*
607          * Do not take lock in case of CIT_MISC io, because
608          *
609          *     - if this is an io for a glimpse, then we don't care;
610          *
611          *     - if this not a glimpse (writepage or lock cancellation), then
612          *       layout change cannot happen because a page or a lock
613          *       already exist; and
614          *
615          *     - lock ordering (lock mutex nests within layout rw-semaphore)
616          *       is obeyed in case of lock cancellation.
617          */
618         return LOV_2DISPATCH_MAYLOCK(cl2lov(obj), llo_io_init,
619                                      io->ci_type != CIT_MISC, env, obj, io);
620 }
621
622 /**
623  * An implementation of cl_object_operations::clo_attr_get() method for lov
624  * layer. For raid0 layout this collects and merges attributes of all
625  * sub-objects.
626  */
627 static int lov_attr_get(const struct lu_env *env, struct cl_object *obj,
628                         struct cl_attr *attr)
629 {
630         /* do not take lock, as this function is called under a
631          * spin-lock. Layout is protected from changing by ongoing IO. */
632         return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_getattr, env, obj, attr);
633 }
634
635 static int lov_attr_set(const struct lu_env *env, struct cl_object *obj,
636                         const struct cl_attr *attr, unsigned valid)
637 {
638         /*
639          * No dispatch is required here, as no layout implements this.
640          */
641         return 0;
642 }
643
644 int lov_lock_init(const struct lu_env *env, struct cl_object *obj,
645                   struct cl_lock *lock, const struct cl_io *io)
646 {
647         return LOV_2DISPATCH(cl2lov(obj), llo_lock_init, env, obj, lock, io);
648 }
649
650 static const struct cl_object_operations lov_ops = {
651         .coo_page_init = lov_page_init,
652         .coo_lock_init = lov_lock_init,
653         .coo_io_init   = lov_io_init,
654         .coo_attr_get  = lov_attr_get,
655         .coo_attr_set  = lov_attr_set,
656         .coo_conf_set  = lov_conf_set
657 };
658
659 static const struct lu_object_operations lov_lu_obj_ops = {
660         .loo_object_init      = lov_object_init,
661         .loo_object_delete    = lov_object_delete,
662         .loo_object_release   = NULL,
663         .loo_object_free      = lov_object_free,
664         .loo_object_print     = lov_object_print,
665         .loo_object_invariant = NULL
666 };
667
668 struct lu_object *lov_object_alloc(const struct lu_env *env,
669                                    const struct lu_object_header *unused,
670                                    struct lu_device *dev)
671 {
672         struct lov_object *lov;
673         struct lu_object  *obj;
674
675         ENTRY;
676         OBD_SLAB_ALLOC_PTR_GFP(lov, lov_object_kmem, CFS_ALLOC_IO);
677         if (lov != NULL) {
678                 obj = lov2lu(lov);
679                 lu_object_init(obj, NULL, dev);
680                 lov->lo_cl.co_ops = &lov_ops;
681                 lov->lo_type = -1; /* invalid, to catch uninitialized type */
682                 /*
683                  * object io operation vector (cl_object::co_iop) is installed
684                  * later in lov_object_init(), as different vectors are used
685                  * for object with different layouts.
686                  */
687                 obj->lo_ops = &lov_lu_obj_ops;
688         } else
689                 obj = NULL;
690         RETURN(obj);
691 }
692
693 /** @} lov */