Whamcloud - gitweb
b=22980 improve obdfilter-survey performance on multi-core system
[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 (c) 2008, 2010, Oracle and/or its affiliates. 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 (%d).\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_LARGE(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         struct lu_site_bkt_data *bkt;
228         cfs_waitlink_t          *waiter;
229
230         r0  = &lov->u.raid0;
231         LASSERT(r0->lo_sub[idx] == los);
232
233         sub  = lovsub2cl(los);
234         site = sub->co_lu.lo_dev->ld_site;
235         bkt  = lu_site_bkt_from_fid(site, &sub->co_lu.lo_header->loh_fid);
236
237         cl_object_kill(env, sub);
238         /* release a reference to the sub-object and ... */
239         lu_object_ref_del(&sub->co_lu, "lov-parent", lov);
240         cl_object_put(env, sub);
241
242         /* ... wait until it is actually destroyed---sub-object clears its
243          * ->lo_sub[] slot in lovsub_object_fini() */
244         if (r0->lo_sub[idx] == los) {
245                 waiter = &lov_env_info(env)->lti_waiter;
246                 cfs_waitlink_init(waiter);
247                 cfs_waitq_add(&bkt->lsb_marche_funebre, waiter);
248                 cfs_set_current_state(CFS_TASK_UNINT);
249                 while (1) {
250                         /* this wait-queue is signaled at the end of
251                          * lu_object_free(). */
252                         cfs_set_current_state(CFS_TASK_UNINT);
253                         cfs_spin_lock(&r0->lo_sub_lock);
254                         if (r0->lo_sub[idx] == los) {
255                                 cfs_spin_unlock(&r0->lo_sub_lock);
256                                 cfs_waitq_wait(waiter, CFS_TASK_UNINT);
257                         } else {
258                                 cfs_spin_unlock(&r0->lo_sub_lock);
259                                 cfs_set_current_state(CFS_TASK_RUNNING);
260                                 break;
261                         }
262                 }
263                 cfs_waitq_del(&bkt->lsb_marche_funebre, waiter);
264         }
265         LASSERT(r0->lo_sub[idx] == NULL);
266 }
267
268 static void lov_delete_raid0(const struct lu_env *env, struct lov_object *lov,
269                              union lov_layout_state *state)
270 {
271         struct lov_layout_raid0 *r0 = &state->raid0;
272         int                      i;
273
274         ENTRY;
275         if (r0->lo_sub != NULL) {
276                 for (i = 0; i < r0->lo_nr; ++i) {
277                         struct lovsub_object *los = r0->lo_sub[i];
278
279                         if (los != NULL)
280                                 /*
281                                  * If top-level object is to be evicted from
282                                  * the cache, so are its sub-objects.
283                                  */
284                                 lov_subobject_kill(env, lov, los, i);
285                 }
286         }
287         EXIT;
288 }
289
290 static void lov_fini_empty(const struct lu_env *env, struct lov_object *lov,
291                            union lov_layout_state *state)
292 {
293         LASSERT(lov->lo_type == LLT_EMPTY);
294 }
295
296 static void lov_fini_raid0(const struct lu_env *env, struct lov_object *lov,
297                            union lov_layout_state *state)
298 {
299         struct lov_layout_raid0 *r0 = &state->raid0;
300
301         ENTRY;
302         if (r0->lo_sub != NULL) {
303                 OBD_FREE_LARGE(r0->lo_sub, r0->lo_nr * sizeof r0->lo_sub[0]);
304                 r0->lo_sub = NULL;
305         }
306         EXIT;
307 }
308
309 static int lov_print_empty(const struct lu_env *env, void *cookie,
310                            lu_printer_t p, const struct lu_object *o)
311 {
312         (*p)(env, cookie, "empty\n");
313         return 0;
314 }
315
316 static int lov_print_raid0(const struct lu_env *env, void *cookie,
317                            lu_printer_t p, const struct lu_object *o)
318 {
319         struct lov_object       *lov = lu2lov(o);
320         struct lov_layout_raid0 *r0  = lov_r0(lov);
321         int i;
322
323         (*p)(env, cookie, "stripes: %d:\n", r0->lo_nr);
324         for (i = 0; i < r0->lo_nr; ++i) {
325                 struct lu_object *sub;
326
327                 if (r0->lo_sub[i] != NULL) {
328                         sub = lovsub2lu(r0->lo_sub[i]);
329                         lu_object_print(env, cookie, p, sub);
330                 } else
331                         (*p)(env, cookie, "sub %d absent\n", i);
332         }
333         return 0;
334 }
335
336 /**
337  * Implements cl_object_operations::coo_attr_get() method for an object
338  * without stripes (LLT_EMPTY layout type).
339  *
340  * The only attributes this layer is authoritative in this case is
341  * cl_attr::cat_blocks---it's 0.
342  */
343 static int lov_attr_get_empty(const struct lu_env *env, struct cl_object *obj,
344                               struct cl_attr *attr)
345 {
346         attr->cat_blocks = 0;
347         return 0;
348 }
349
350 static int lov_attr_get_raid0(const struct lu_env *env, struct cl_object *obj,
351                               struct cl_attr *attr)
352 {
353         struct lov_object       *lov = cl2lov(obj);
354         struct lov_layout_raid0 *r0 = lov_r0(lov);
355         struct lov_stripe_md    *lsm = lov->u.raid0.lo_lsm;
356         struct ost_lvb          *lvb = &lov_env_info(env)->lti_lvb;
357         __u64                    kms;
358         int                      result = 0;
359
360         ENTRY;
361         if (!r0->lo_attr_valid) {
362                 /*
363                  * Fill LVB with attributes already initialized by the upper
364                  * layer.
365                  */
366                 cl_attr2lvb(lvb, attr);
367                 kms = attr->cat_kms;
368
369                 /*
370                  * XXX that should be replaced with a loop over sub-objects,
371                  * doing cl_object_attr_get() on them. But for now, let's
372                  * reuse old lov code.
373                  */
374
375                 /*
376                  * XXX take lsm spin-lock to keep lov_merge_lvb_kms()
377                  * happy. It's not needed, because new code uses
378                  * ->coh_attr_guard spin-lock to protect consistency of
379                  * sub-object attributes.
380                  */
381                 lov_stripe_lock(lsm);
382                 result = lov_merge_lvb_kms(lsm, lvb, &kms);
383                 lov_stripe_unlock(lsm);
384                 if (result == 0) {
385                         cl_lvb2attr(attr, lvb);
386                         attr->cat_kms = kms;
387                         r0->lo_attr_valid = 1;
388                         r0->lo_attr = *attr;
389                 }
390         } else
391                 *attr = r0->lo_attr;
392         RETURN(result);
393 }
394
395 const static struct lov_layout_operations lov_dispatch[] = {
396         [LLT_EMPTY] = {
397                 .llo_init      = lov_init_empty,
398                 .llo_delete    = lov_delete_empty,
399                 .llo_fini      = lov_fini_empty,
400                 .llo_install   = lov_install_empty,
401                 .llo_print     = lov_print_empty,
402                 .llo_page_init = lov_page_init_empty,
403                 .llo_lock_init = NULL,
404                 .llo_io_init   = lov_io_init_empty,
405                 .llo_getattr   = lov_attr_get_empty
406         },
407         [LLT_RAID0] = {
408                 .llo_init      = lov_init_raid0,
409                 .llo_delete    = lov_delete_raid0,
410                 .llo_fini      = lov_fini_raid0,
411                 .llo_install   = lov_install_raid0,
412                 .llo_print     = lov_print_raid0,
413                 .llo_page_init = lov_page_init_raid0,
414                 .llo_lock_init = lov_lock_init_raid0,
415                 .llo_io_init   = lov_io_init_raid0,
416                 .llo_getattr   = lov_attr_get_raid0
417         }
418 };
419
420
421 /**
422  * Performs a double-dispatch based on the layout type of an object.
423  */
424 #define LOV_2DISPATCH_NOLOCK(obj, op, ...)                              \
425 ({                                                                      \
426         struct lov_object                      *__obj = (obj);          \
427         enum lov_layout_type                    __llt;                  \
428                                                                         \
429         __llt = __obj->lo_type;                                         \
430         LASSERT(0 <= __llt && __llt < ARRAY_SIZE(lov_dispatch));        \
431         lov_dispatch[__llt].op(__VA_ARGS__);                            \
432 })
433
434 #define LOV_2DISPATCH_MAYLOCK(obj, op, lock, ...)                       \
435 ({                                                                      \
436         struct lov_object                      *__obj = (obj);          \
437         int                                     __lock = !!(lock);      \
438         typeof(lov_dispatch[0].op(__VA_ARGS__)) __result;               \
439                                                                         \
440         __lock &= __obj->lo_owner != cfs_current();                     \
441         if (__lock)                                                     \
442                 cfs_down_read(&__obj->lo_type_guard);                   \
443         __result = LOV_2DISPATCH_NOLOCK(obj, op, __VA_ARGS__);          \
444         if (__lock)                                                     \
445                 cfs_up_read(&__obj->lo_type_guard);                     \
446         __result;                                                       \
447 })
448
449 /**
450  * Performs a locked double-dispatch based on the layout type of an object.
451  */
452 #define LOV_2DISPATCH(obj, op, ...)                     \
453         LOV_2DISPATCH_MAYLOCK(obj, op, 1, __VA_ARGS__)
454
455 #define LOV_2DISPATCH_VOID(obj, op, ...)                                \
456 do {                                                                    \
457         struct lov_object                      *__obj = (obj);          \
458         enum lov_layout_type                    __llt;                  \
459                                                                         \
460         if (__obj->lo_owner != cfs_current())                           \
461                 cfs_down_read(&__obj->lo_type_guard);                   \
462         __llt = __obj->lo_type;                                         \
463         LASSERT(0 <= __llt && __llt < ARRAY_SIZE(lov_dispatch));        \
464         lov_dispatch[__llt].op(__VA_ARGS__);                            \
465         if (__obj->lo_owner != cfs_current())                           \
466                 cfs_up_read(&__obj->lo_type_guard);                     \
467 } while (0)
468
469 static int lov_layout_change(const struct lu_env *env,
470                              struct lov_object *obj, enum lov_layout_type llt,
471                              const struct cl_object_conf *conf)
472 {
473         int result;
474         union lov_layout_state       *state = &lov_env_info(env)->lti_state;
475         const struct lov_layout_operations *old_ops;
476         const struct lov_layout_operations *new_ops;
477
478         LASSERT(0 <= obj->lo_type && obj->lo_type < ARRAY_SIZE(lov_dispatch));
479         LASSERT(0 <= llt && llt < ARRAY_SIZE(lov_dispatch));
480         ENTRY;
481
482         old_ops = &lov_dispatch[obj->lo_type];
483         new_ops = &lov_dispatch[llt];
484
485         result = new_ops->llo_init(env, lu2lov_dev(obj->lo_cl.co_lu.lo_dev),
486                                    obj, conf, state);
487         if (result == 0) {
488                 struct cl_object_header *hdr = cl_object_header(&obj->lo_cl);
489                 void                    *cookie;
490                 struct lu_env           *nested;
491                 int                      refcheck;
492
493                 cookie = cl_env_reenter();
494                 nested = cl_env_get(&refcheck);
495                 if (!IS_ERR(nested))
496                         cl_object_prune(nested, &obj->lo_cl);
497                 else
498                         result = PTR_ERR(nested);
499                 cl_env_put(nested, &refcheck);
500                 cl_env_reexit(cookie);
501
502                 old_ops->llo_fini(env, obj, &obj->u);
503                 LASSERT(cfs_list_empty(&hdr->coh_locks));
504                 LASSERT(hdr->coh_tree.rnode == NULL);
505                 LASSERT(hdr->coh_pages == 0);
506
507                 new_ops->llo_install(env, obj, state);
508                 obj->lo_type = llt;
509         } else
510                 new_ops->llo_fini(env, obj, state);
511         RETURN(result);
512 }
513
514 /*****************************************************************************
515  *
516  * Lov object operations.
517  *
518  */
519
520 int lov_object_init(const struct lu_env *env, struct lu_object *obj,
521                     const struct lu_object_conf *conf)
522 {
523         struct lov_device            *dev   = lu2lov_dev(obj->lo_dev);
524         struct lov_object            *lov   = lu2lov(obj);
525         const struct cl_object_conf  *cconf = lu2cl_conf(conf);
526         union  lov_layout_state      *set   = &lov_env_info(env)->lti_state;
527         const struct lov_layout_operations *ops;
528         int result;
529
530         ENTRY;
531         cfs_init_rwsem(&lov->lo_type_guard);
532
533         /* no locking is necessary, as object is being created */
534         lov->lo_type = cconf->u.coc_md->lsm != NULL ? LLT_RAID0 : LLT_EMPTY;
535         ops = &lov_dispatch[lov->lo_type];
536         result = ops->llo_init(env, dev, lov, cconf, set);
537         if (result == 0)
538                 ops->llo_install(env, lov, set);
539         else
540                 ops->llo_fini(env, lov, set);
541         RETURN(result);
542 }
543
544 static int lov_conf_set(const struct lu_env *env, struct cl_object *obj,
545                         const struct cl_object_conf *conf)
546 {
547         struct lov_object *lov = cl2lov(obj);
548         int result;
549
550         ENTRY;
551         /*
552          * Currently only LLT_EMPTY -> LLT_RAID0 transition is supported.
553          */
554         LASSERT(lov->lo_owner != cfs_current());
555         cfs_down_write(&lov->lo_type_guard);
556         LASSERT(lov->lo_owner == NULL);
557         lov->lo_owner = cfs_current();
558         if (lov->lo_type == LLT_EMPTY && conf->u.coc_md->lsm != NULL)
559                 result = lov_layout_change(env, lov, LLT_RAID0, conf);
560         else
561                 result = -EOPNOTSUPP;
562         lov->lo_owner = NULL;
563         cfs_up_write(&lov->lo_type_guard);
564         RETURN(result);
565 }
566
567 static void lov_object_delete(const struct lu_env *env, struct lu_object *obj)
568 {
569         struct lov_object *lov = lu2lov(obj);
570
571         ENTRY;
572         LOV_2DISPATCH_VOID(lov, llo_delete, env, lov, &lov->u);
573         EXIT;
574 }
575
576 static void lov_object_free(const struct lu_env *env, struct lu_object *obj)
577 {
578         struct lov_object *lov = lu2lov(obj);
579
580         ENTRY;
581         LOV_2DISPATCH_VOID(lov, llo_fini, env, lov, &lov->u);
582         lu_object_fini(obj);
583         OBD_SLAB_FREE_PTR(lov, lov_object_kmem);
584         EXIT;
585 }
586
587 static int lov_object_print(const struct lu_env *env, void *cookie,
588                             lu_printer_t p, const struct lu_object *o)
589 {
590         return LOV_2DISPATCH(lu2lov(o), llo_print, env, cookie, p, o);
591 }
592
593 struct cl_page *lov_page_init(const struct lu_env *env, struct cl_object *obj,
594                               struct cl_page *page, cfs_page_t *vmpage)
595 {
596         return LOV_2DISPATCH(cl2lov(obj),
597                              llo_page_init, env, obj, page, vmpage);
598 }
599
600 /**
601  * Implements cl_object_operations::clo_io_init() method for lov
602  * layer. Dispatches to the appropriate layout io initialization method.
603  */
604 int lov_io_init(const struct lu_env *env, struct cl_object *obj,
605                 struct cl_io *io)
606 {
607         CL_IO_SLICE_CLEAN(lov_env_io(env), lis_cl);
608         /*
609          * Do not take lock in case of CIT_MISC io, because
610          *
611          *     - if this is an io for a glimpse, then we don't care;
612          *
613          *     - if this not a glimpse (writepage or lock cancellation), then
614          *       layout change cannot happen because a page or a lock
615          *       already exist; and
616          *
617          *     - lock ordering (lock mutex nests within layout rw-semaphore)
618          *       is obeyed in case of lock cancellation.
619          */
620         return LOV_2DISPATCH_MAYLOCK(cl2lov(obj), llo_io_init,
621                                      io->ci_type != CIT_MISC, env, obj, io);
622 }
623
624 /**
625  * An implementation of cl_object_operations::clo_attr_get() method for lov
626  * layer. For raid0 layout this collects and merges attributes of all
627  * sub-objects.
628  */
629 static int lov_attr_get(const struct lu_env *env, struct cl_object *obj,
630                         struct cl_attr *attr)
631 {
632         /* do not take lock, as this function is called under a
633          * spin-lock. Layout is protected from changing by ongoing IO. */
634         return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_getattr, env, obj, attr);
635 }
636
637 static int lov_attr_set(const struct lu_env *env, struct cl_object *obj,
638                         const struct cl_attr *attr, unsigned valid)
639 {
640         /*
641          * No dispatch is required here, as no layout implements this.
642          */
643         return 0;
644 }
645
646 int lov_lock_init(const struct lu_env *env, struct cl_object *obj,
647                   struct cl_lock *lock, const struct cl_io *io)
648 {
649         return LOV_2DISPATCH(cl2lov(obj), llo_lock_init, env, obj, lock, io);
650 }
651
652 static const struct cl_object_operations lov_ops = {
653         .coo_page_init = lov_page_init,
654         .coo_lock_init = lov_lock_init,
655         .coo_io_init   = lov_io_init,
656         .coo_attr_get  = lov_attr_get,
657         .coo_attr_set  = lov_attr_set,
658         .coo_conf_set  = lov_conf_set
659 };
660
661 static const struct lu_object_operations lov_lu_obj_ops = {
662         .loo_object_init      = lov_object_init,
663         .loo_object_delete    = lov_object_delete,
664         .loo_object_release   = NULL,
665         .loo_object_free      = lov_object_free,
666         .loo_object_print     = lov_object_print,
667         .loo_object_invariant = NULL
668 };
669
670 struct lu_object *lov_object_alloc(const struct lu_env *env,
671                                    const struct lu_object_header *unused,
672                                    struct lu_device *dev)
673 {
674         struct lov_object *lov;
675         struct lu_object  *obj;
676
677         ENTRY;
678         OBD_SLAB_ALLOC_PTR_GFP(lov, lov_object_kmem, CFS_ALLOC_IO);
679         if (lov != NULL) {
680                 obj = lov2lu(lov);
681                 lu_object_init(obj, NULL, dev);
682                 lov->lo_cl.co_ops = &lov_ops;
683                 lov->lo_type = -1; /* invalid, to catch uninitialized type */
684                 /*
685                  * object io operation vector (cl_object::co_iop) is installed
686                  * later in lov_object_init(), as different vectors are used
687                  * for object with different layouts.
688                  */
689                 obj->lo_ops = &lov_lu_obj_ops;
690         } else
691                 obj = NULL;
692         RETURN(obj);
693 }
694
695 /** @} lov */