Whamcloud - gitweb
LU-3057 llite: swap layout fixes - hang at sanity 56x and 56w
[fs/lustre-release.git] / lustre / lod / lod_object.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License version 2 for more details.  A copy is
14  * included in the COPYING file that accompanied this code.
15
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright  2009 Sun Microsystems, Inc. All rights reserved
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, Intel Corporation.
27  */
28 /*
29  * lustre/lod/lod_object.c
30  *
31  * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
32  */
33
34 #ifndef EXPORT_SYMTAB
35 # define EXPORT_SYMTAB
36 #endif
37 #define DEBUG_SUBSYSTEM S_MDS
38
39 #include <obd.h>
40 #include <obd_class.h>
41 #include <lustre_ver.h>
42 #include <obd_support.h>
43 #include <lprocfs_status.h>
44
45 #include <lustre_fid.h>
46 #include <lustre_param.h>
47 #include <lustre_fid.h>
48 #include <obd_lov.h>
49
50 #include "lod_internal.h"
51
52 extern cfs_mem_cache_t *lod_object_kmem;
53 static const struct dt_body_operations lod_body_lnk_ops;
54
55 static int lod_index_lookup(const struct lu_env *env, struct dt_object *dt,
56                             struct dt_rec *rec, const struct dt_key *key,
57                             struct lustre_capa *capa)
58 {
59         struct dt_object *next = dt_object_child(dt);
60         return next->do_index_ops->dio_lookup(env, next, rec, key, capa);
61 }
62
63 static int lod_declare_index_insert(const struct lu_env *env,
64                                     struct dt_object *dt,
65                                     const struct dt_rec *rec,
66                                     const struct dt_key *key,
67                                     struct thandle *handle)
68 {
69         return dt_declare_insert(env, dt_object_child(dt), rec, key, handle);
70 }
71
72 static int lod_index_insert(const struct lu_env *env,
73                             struct dt_object *dt,
74                             const struct dt_rec *rec,
75                             const struct dt_key *key,
76                             struct thandle *th,
77                             struct lustre_capa *capa,
78                             int ign)
79 {
80         return dt_insert(env, dt_object_child(dt), rec, key, th, capa, ign);
81 }
82
83 static int lod_declare_index_delete(const struct lu_env *env,
84                                     struct dt_object *dt,
85                                     const struct dt_key *key,
86                                     struct thandle *th)
87 {
88         return dt_declare_delete(env, dt_object_child(dt), key, th);
89 }
90
91 static int lod_index_delete(const struct lu_env *env,
92                             struct dt_object *dt,
93                             const struct dt_key *key,
94                             struct thandle *th,
95                             struct lustre_capa *capa)
96 {
97         return dt_delete(env, dt_object_child(dt), key, th, capa);
98 }
99
100 static struct dt_it *lod_it_init(const struct lu_env *env,
101                                  struct dt_object *dt, __u32 attr,
102                                  struct lustre_capa *capa)
103 {
104         struct dt_object        *next = dt_object_child(dt);
105         struct lod_it           *it = &lod_env_info(env)->lti_it;
106         struct dt_it            *it_next;
107
108
109         it_next = next->do_index_ops->dio_it.init(env, next, attr, capa);
110         if (IS_ERR(it_next))
111                 return it_next;
112
113         /* currently we do not use more than one iterator per thread
114          * so we store it in thread info. if at some point we need
115          * more active iterators in a single thread, we can allocate
116          * additional ones */
117         LASSERT(it->lit_obj == NULL);
118
119         it->lit_it = it_next;
120         it->lit_obj = next;
121
122         return (struct dt_it *)it;
123 }
124
125 #define LOD_CHECK_IT(env, it)                                   \
126 {                                                               \
127         LASSERT((it)->lit_obj != NULL);                         \
128         LASSERT((it)->lit_it != NULL);                          \
129 } while(0)
130
131 void lod_it_fini(const struct lu_env *env, struct dt_it *di)
132 {
133         struct lod_it *it = (struct lod_it *)di;
134
135         LOD_CHECK_IT(env, it);
136         it->lit_obj->do_index_ops->dio_it.fini(env, it->lit_it);
137
138         /* the iterator not in use any more */
139         it->lit_obj = NULL;
140         it->lit_it = NULL;
141 }
142
143 int lod_it_get(const struct lu_env *env, struct dt_it *di,
144                const struct dt_key *key)
145 {
146         const struct lod_it *it = (const struct lod_it *)di;
147
148         LOD_CHECK_IT(env, it);
149         return it->lit_obj->do_index_ops->dio_it.get(env, it->lit_it, key);
150 }
151
152 void lod_it_put(const struct lu_env *env, struct dt_it *di)
153 {
154         struct lod_it *it = (struct lod_it *)di;
155
156         LOD_CHECK_IT(env, it);
157         return it->lit_obj->do_index_ops->dio_it.put(env, it->lit_it);
158 }
159
160 int lod_it_next(const struct lu_env *env, struct dt_it *di)
161 {
162         struct lod_it *it = (struct lod_it *)di;
163
164         LOD_CHECK_IT(env, it);
165         return it->lit_obj->do_index_ops->dio_it.next(env, it->lit_it);
166 }
167
168 struct dt_key *lod_it_key(const struct lu_env *env, const struct dt_it *di)
169 {
170         const struct lod_it *it = (const struct lod_it *)di;
171
172         LOD_CHECK_IT(env, it);
173         return it->lit_obj->do_index_ops->dio_it.key(env, it->lit_it);
174 }
175
176 int lod_it_key_size(const struct lu_env *env, const struct dt_it *di)
177 {
178         struct lod_it *it = (struct lod_it *)di;
179
180         LOD_CHECK_IT(env, it);
181         return it->lit_obj->do_index_ops->dio_it.key_size(env, it->lit_it);
182 }
183
184 int lod_it_rec(const struct lu_env *env, const struct dt_it *di,
185                struct dt_rec *rec, __u32 attr)
186 {
187         const struct lod_it *it = (const struct lod_it *)di;
188
189         LOD_CHECK_IT(env, it);
190         return it->lit_obj->do_index_ops->dio_it.rec(env, it->lit_it, rec, attr);
191 }
192
193 __u64 lod_it_store(const struct lu_env *env, const struct dt_it *di)
194 {
195         const struct lod_it *it = (const struct lod_it *)di;
196
197         LOD_CHECK_IT(env, it);
198         return it->lit_obj->do_index_ops->dio_it.store(env, it->lit_it);
199 }
200
201 int lod_it_load(const struct lu_env *env, const struct dt_it *di, __u64 hash)
202 {
203         const struct lod_it *it = (const struct lod_it *)di;
204
205         LOD_CHECK_IT(env, it);
206         return it->lit_obj->do_index_ops->dio_it.load(env, it->lit_it, hash);
207 }
208
209 int lod_it_key_rec(const struct lu_env *env, const struct dt_it *di,
210                    void* key_rec)
211 {
212         const struct lod_it *it = (const struct lod_it *)di;
213
214         LOD_CHECK_IT(env, it);
215         return it->lit_obj->do_index_ops->dio_it.key_rec(env, it->lit_it, key_rec);
216 }
217
218 static struct dt_index_operations lod_index_ops = {
219         .dio_lookup             = lod_index_lookup,
220         .dio_declare_insert     = lod_declare_index_insert,
221         .dio_insert             = lod_index_insert,
222         .dio_declare_delete     = lod_declare_index_delete,
223         .dio_delete             = lod_index_delete,
224         .dio_it = {
225                 .init           = lod_it_init,
226                 .fini           = lod_it_fini,
227                 .get            = lod_it_get,
228                 .put            = lod_it_put,
229                 .next           = lod_it_next,
230                 .key            = lod_it_key,
231                 .key_size       = lod_it_key_size,
232                 .rec            = lod_it_rec,
233                 .store          = lod_it_store,
234                 .load           = lod_it_load,
235                 .key_rec        = lod_it_key_rec,
236         }
237 };
238
239 static void lod_object_read_lock(const struct lu_env *env,
240                                  struct dt_object *dt, unsigned role)
241 {
242         dt_read_lock(env, dt_object_child(dt), role);
243 }
244
245 static void lod_object_write_lock(const struct lu_env *env,
246                                   struct dt_object *dt, unsigned role)
247 {
248         dt_write_lock(env, dt_object_child(dt), role);
249 }
250
251 static void lod_object_read_unlock(const struct lu_env *env,
252                                    struct dt_object *dt)
253 {
254         dt_read_unlock(env, dt_object_child(dt));
255 }
256
257 static void lod_object_write_unlock(const struct lu_env *env,
258                                     struct dt_object *dt)
259 {
260         dt_write_unlock(env, dt_object_child(dt));
261 }
262
263 static int lod_object_write_locked(const struct lu_env *env,
264                                    struct dt_object *dt)
265 {
266         return dt_write_locked(env, dt_object_child(dt));
267 }
268
269 static int lod_attr_get(const struct lu_env *env,
270                         struct dt_object *dt,
271                         struct lu_attr *attr,
272                         struct lustre_capa *capa)
273 {
274         return dt_attr_get(env, dt_object_child(dt), attr, capa);
275 }
276
277 static int lod_declare_attr_set(const struct lu_env *env,
278                                 struct dt_object *dt,
279                                 const struct lu_attr *attr,
280                                 struct thandle *handle)
281 {
282         struct dt_object  *next = dt_object_child(dt);
283         struct lod_object *lo = lod_dt_obj(dt);
284         int                rc, i;
285         ENTRY;
286
287         /*
288          * declare setattr on the local object
289          */
290         rc = dt_declare_attr_set(env, next, attr, handle);
291         if (rc)
292                 RETURN(rc);
293
294         /*
295          * load striping information, notice we don't do this when object
296          * is being initialized as we don't need this information till
297          * few specific cases like destroy, chown
298          */
299         rc = lod_load_striping(env, lo);
300         if (rc)
301                 RETURN(rc);
302
303         /*
304          * if object is striped declare changes on the stripes
305          */
306         LASSERT(lo->ldo_stripe || lo->ldo_stripenr == 0);
307         for (i = 0; i < lo->ldo_stripenr; i++) {
308                 LASSERT(lo->ldo_stripe[i]);
309                 rc = dt_declare_attr_set(env, lo->ldo_stripe[i], attr, handle);
310                 if (rc) {
311                         CERROR("failed declaration: %d\n", rc);
312                         break;
313                 }
314         }
315
316         RETURN(rc);
317 }
318
319 static int lod_attr_set(const struct lu_env *env,
320                         struct dt_object *dt,
321                         const struct lu_attr *attr,
322                         struct thandle *handle,
323                         struct lustre_capa *capa)
324 {
325         struct dt_object  *next = dt_object_child(dt);
326         struct lod_object *lo = lod_dt_obj(dt);
327         int                rc, i;
328         ENTRY;
329
330         /*
331          * apply changes to the local object
332          */
333         rc = dt_attr_set(env, next, attr, handle, capa);
334         if (rc)
335                 RETURN(rc);
336
337         /*
338          * if object is striped, apply changes to all the stripes
339          */
340         LASSERT(lo->ldo_stripe || lo->ldo_stripenr == 0);
341         for (i = 0; i < lo->ldo_stripenr; i++) {
342                 LASSERT(lo->ldo_stripe[i]);
343                 rc = dt_attr_set(env, lo->ldo_stripe[i], attr, handle, capa);
344                 if (rc) {
345                         CERROR("failed declaration: %d\n", rc);
346                         break;
347                 }
348         }
349
350         RETURN(rc);
351 }
352
353 static int lod_xattr_get(const struct lu_env *env, struct dt_object *dt,
354                          struct lu_buf *buf, const char *name,
355                          struct lustre_capa *capa)
356 {
357         struct lod_thread_info  *info = lod_env_info(env);
358         struct lod_device       *dev = lu2lod_dev(dt->do_lu.lo_dev);
359         int                      rc, is_root;
360         ENTRY;
361
362         rc = dt_xattr_get(env, dt_object_child(dt), buf, name, capa);
363         if (rc != -ENODATA || !S_ISDIR(dt->do_lu.lo_header->loh_attr & S_IFMT))
364                 RETURN(rc);
365
366         /*
367          * lod returns default striping on the real root of the device
368          * this is like the root stores default striping for the whole
369          * filesystem. historically we've been using a different approach
370          * and store it in the config.
371          */
372         dt_root_get(env, dev->lod_child, &info->lti_fid);
373         is_root = lu_fid_eq(&info->lti_fid, lu_object_fid(&dt->do_lu));
374
375         if (is_root && strcmp(XATTR_NAME_LOV, name) == 0) {
376                 struct lov_user_md *lum = buf->lb_buf;
377                 struct lov_desc    *desc = &dev->lod_desc;
378
379                 if (buf->lb_buf == NULL) {
380                         rc = sizeof(struct lov_user_md_v1);
381                 } else if (buf->lb_len >= sizeof(struct lov_user_md_v1)) {
382                         lum->lmm_magic = LOV_USER_MAGIC_V1;
383                         lum->lmm_oi.oi_seq = FID_SEQ_LOV_DEFAULT;
384                         lum->lmm_pattern = desc->ld_pattern;
385                         lum->lmm_stripe_size = desc->ld_default_stripe_size;
386                         lum->lmm_stripe_count = desc->ld_default_stripe_count;
387                         lum->lmm_stripe_offset = desc->ld_default_stripe_offset;
388                         rc = sizeof(struct lov_user_md_v1);
389                 } else {
390                         rc = -ERANGE;
391                 }
392         }
393
394         RETURN(rc);
395 }
396
397 /*
398  * LOV xattr is a storage for striping, and LOD owns this xattr.
399  * but LOD allows others to control striping to some extent
400  * - to reset strping
401  * - to set new defined striping
402  * - to set new semi-defined striping
403  *   - number of stripes is defined
404  *   - number of stripes + osts are defined
405  *   - ??
406  */
407 static int lod_declare_xattr_set(const struct lu_env *env,
408                                  struct dt_object *dt,
409                                  const struct lu_buf *buf,
410                                  const char *name, int fl,
411                                  struct thandle *th)
412 {
413         struct dt_object *next = dt_object_child(dt);
414         struct lu_attr   *attr = &lod_env_info(env)->lti_attr;
415         __u32             mode;
416         int               rc;
417         ENTRY;
418
419         /*
420          * allow to declare predefined striping on a new (!mode) object
421          * which is supposed to be replay of regular file creation
422          * (when LOV setting is declared)
423          * LU_XATTR_REPLACE is set to indicate a layout swap
424          */
425         mode = dt->do_lu.lo_header->loh_attr & S_IFMT;
426         if ((S_ISREG(mode) || !mode) && !strcmp(name, XATTR_NAME_LOV) &&
427              !(fl & LU_XATTR_REPLACE)) {
428                 /*
429                  * this is a request to manipulate object's striping
430                  */
431                 if (dt_object_exists(dt)) {
432                         rc = dt_attr_get(env, next, attr, BYPASS_CAPA);
433                         if (rc)
434                                 RETURN(rc);
435                 } else {
436                         memset(attr, 0, sizeof(*attr));
437                         attr->la_valid = LA_TYPE | LA_MODE;
438                         attr->la_mode = S_IFREG;
439                 }
440                 rc = lod_declare_striped_object(env, dt, attr, buf, th);
441                 if (rc)
442                         RETURN(rc);
443         }
444
445         rc = dt_declare_xattr_set(env, next, buf, name, fl, th);
446
447         RETURN(rc);
448 }
449
450 static int lod_xattr_set_lov_on_dir(const struct lu_env *env,
451                                     struct dt_object *dt,
452                                     const struct lu_buf *buf,
453                                     const char *name, int fl,
454                                     struct thandle *th,
455                                     struct lustre_capa *capa)
456 {
457         struct lod_device       *d = lu2lod_dev(dt->do_lu.lo_dev);
458         struct dt_object        *next = dt_object_child(dt);
459         struct lod_object       *l = lod_dt_obj(dt);
460         struct lov_user_md_v1   *lum;
461         struct lov_user_md_v3   *v3 = NULL;
462         int                      rc;
463         ENTRY;
464
465         LASSERT(l->ldo_stripe == NULL);
466         l->ldo_striping_cached = 0;
467         l->ldo_def_striping_set = 0;
468         lod_object_set_pool(l, NULL);
469         l->ldo_def_stripe_size = 0;
470         l->ldo_def_stripenr = 0;
471
472         LASSERT(buf);
473         LASSERT(buf->lb_buf);
474         lum = buf->lb_buf;
475
476         rc = lod_verify_striping(d, buf, 0);
477         if (rc)
478                 RETURN(rc);
479
480         if (lum->lmm_magic == LOV_USER_MAGIC_V3)
481                 v3 = buf->lb_buf;
482
483         /* if { size, offset, count } = { 0, -1, 0 } and no pool
484          * (i.e. all default values specified) then delete default
485          * striping from dir. */
486         CDEBUG(D_OTHER,
487                 "set default striping: sz %u # %u offset %d %s %s\n",
488                 (unsigned)lum->lmm_stripe_size,
489                 (unsigned)lum->lmm_stripe_count,
490                 (int)lum->lmm_stripe_offset,
491                 v3 ? "from" : "", v3 ? v3->lmm_pool_name : "");
492
493         if (LOVEA_DELETE_VALUES((lum->lmm_stripe_size),
494                                 (lum->lmm_stripe_count),
495                                 (lum->lmm_stripe_offset)) &&
496                         lum->lmm_magic == LOV_USER_MAGIC_V1) {
497                 rc = dt_xattr_del(env, next, name, th, capa);
498                 if (rc == -ENODATA)
499                         rc = 0;
500         } else {
501                 rc = dt_xattr_set(env, next, buf, name, fl, th, capa);
502         }
503
504         RETURN(rc);
505 }
506
507 static int lod_xattr_set(const struct lu_env *env,
508                          struct dt_object *dt, const struct lu_buf *buf,
509                          const char *name, int fl, struct thandle *th,
510                          struct lustre_capa *capa)
511 {
512         struct dt_object        *next = dt_object_child(dt);
513         __u32                    attr;
514         int                      rc;
515         ENTRY;
516
517         attr = dt->do_lu.lo_header->loh_attr & S_IFMT;
518         if (S_ISDIR(attr)) {
519                 if (strncmp(name, XATTR_NAME_LOV, strlen(XATTR_NAME_LOV)) == 0)
520                         rc = lod_xattr_set_lov_on_dir(env, dt, buf, name,
521                                                       fl, th, capa);
522                 else
523                         rc = dt_xattr_set(env, next, buf, name, fl, th, capa);
524
525         } else if (S_ISREG(attr) && !strcmp(name, XATTR_NAME_LOV)) {
526                 /* in case of lov EA swap, just set it
527                  * if not, it is a replay so check striping match what we
528                  * already have during req replay, declare_xattr_set()
529                  * defines striping, then create() does the work
530                 */
531                 if (fl & LU_XATTR_REPLACE) {
532                         /* free stripes, then update disk */
533                         lod_object_free_striping(env, lod_dt_obj(dt));
534                         rc = dt_xattr_set(env, next, buf, name, fl, th, capa);
535                 } else {
536                         rc = lod_striping_create(env, dt, NULL, NULL, th);
537                 }
538                 RETURN(rc);
539         } else {
540                 /*
541                  * behave transparantly for all other EAs
542                  */
543                 rc = dt_xattr_set(env, next, buf, name, fl, th, capa);
544         }
545
546         RETURN(rc);
547 }
548
549 static int lod_declare_xattr_del(const struct lu_env *env,
550                                  struct dt_object *dt, const char *name,
551                                  struct thandle *th)
552 {
553         return dt_declare_xattr_del(env, dt_object_child(dt), name, th);
554 }
555
556 static int lod_xattr_del(const struct lu_env *env, struct dt_object *dt,
557                          const char *name, struct thandle *th,
558                          struct lustre_capa *capa)
559 {
560         return dt_xattr_del(env, dt_object_child(dt), name, th, capa);
561 }
562
563 static int lod_xattr_list(const struct lu_env *env,
564                           struct dt_object *dt, struct lu_buf *buf,
565                           struct lustre_capa *capa)
566 {
567         return dt_xattr_list(env, dt_object_child(dt), buf, capa);
568 }
569
570 int lod_object_set_pool(struct lod_object *o, char *pool)
571 {
572         int len;
573
574         if (o->ldo_pool) {
575                 len = strlen(o->ldo_pool);
576                 OBD_FREE(o->ldo_pool, len + 1);
577                 o->ldo_pool = NULL;
578         }
579         if (pool) {
580                 len = strlen(pool);
581                 OBD_ALLOC(o->ldo_pool, len + 1);
582                 if (o->ldo_pool == NULL)
583                         return -ENOMEM;
584                 strcpy(o->ldo_pool, pool);
585         }
586         return 0;
587 }
588
589 static inline int lod_object_will_be_striped(int is_reg, const struct lu_fid *fid)
590 {
591         return (is_reg && fid_seq(fid) != FID_SEQ_LOCAL_FILE);
592 }
593
594 static int lod_cache_parent_striping(const struct lu_env *env,
595                                      struct lod_object *lp)
596 {
597         struct lov_user_md_v1   *v1 = NULL;
598         struct lov_user_md_v3   *v3 = NULL;
599         int                      rc;
600         ENTRY;
601
602         /* dt_ah_init() is called from MDD without parent being write locked
603          * lock it here */
604         dt_write_lock(env, dt_object_child(&lp->ldo_obj), 0);
605         if (lp->ldo_striping_cached)
606                 GOTO(unlock, rc = 0);
607
608         rc = lod_get_lov_ea(env, lp);
609         if (rc < 0)
610                 GOTO(unlock, rc);
611
612         if (rc < sizeof(struct lov_user_md)) {
613                 /* don't lookup for non-existing or invalid striping */
614                 lp->ldo_def_striping_set = 0;
615                 lp->ldo_striping_cached = 1;
616                 lp->ldo_def_stripe_size = 0;
617                 lp->ldo_def_stripenr = 0;
618                 lp->ldo_def_stripe_offset = (typeof(v1->lmm_stripe_offset))(-1);
619                 GOTO(unlock, rc = 0);
620         }
621
622         v1 = (struct lov_user_md_v1 *)lod_env_info(env)->lti_ea_store;
623         if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V1))
624                 lustre_swab_lov_user_md_v1(v1);
625         else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V3))
626                 lustre_swab_lov_user_md_v3(v3);
627
628         if (v1->lmm_magic != LOV_MAGIC_V3 && v1->lmm_magic != LOV_MAGIC_V1)
629                 GOTO(unlock, rc = 0);
630
631         if (v1->lmm_pattern != LOV_PATTERN_RAID0 && v1->lmm_pattern != 0)
632                 GOTO(unlock, rc = 0);
633
634         lp->ldo_def_stripenr = v1->lmm_stripe_count;
635         lp->ldo_def_stripe_size = v1->lmm_stripe_size;
636         lp->ldo_def_stripe_offset = v1->lmm_stripe_offset;
637         lp->ldo_striping_cached = 1;
638         lp->ldo_def_striping_set = 1;
639
640         if (v1->lmm_magic == LOV_USER_MAGIC_V3) {
641                 /* XXX: sanity check here */
642                 v3 = (struct lov_user_md_v3 *) v1;
643                 if (v3->lmm_pool_name[0])
644                         lod_object_set_pool(lp, v3->lmm_pool_name);
645         }
646
647         CDEBUG(D_OTHER, "def. striping: # %d, sz %d, off %d %s%s on "DFID"\n",
648                lp->ldo_def_stripenr, lp->ldo_def_stripe_size,
649                lp->ldo_def_stripe_offset, v3 ? "from " : "",
650                v3 ? lp->ldo_pool : "", PFID(lu_object_fid(&lp->ldo_obj.do_lu)));
651
652         EXIT;
653 unlock:
654         dt_write_unlock(env, dt_object_child(&lp->ldo_obj));
655         return rc;
656 }
657
658 /**
659  * used to transfer default striping data to the object being created
660  */
661 static void lod_ah_init(const struct lu_env *env,
662                         struct dt_allocation_hint *ah,
663                         struct dt_object *parent,
664                         struct dt_object *child,
665                         cfs_umode_t child_mode)
666 {
667         struct lod_device *d = lu2lod_dev(child->do_lu.lo_dev);
668         struct dt_object  *nextp = NULL;
669         struct dt_object  *nextc;
670         struct lod_object *lp = NULL;
671         struct lod_object *lc;
672         struct lov_desc   *desc;
673         ENTRY;
674
675         LASSERT(child);
676
677         if (likely(parent)) {
678                 nextp = dt_object_child(parent);
679                 lp = lod_dt_obj(parent);
680         }
681
682         nextc = dt_object_child(child);
683         lc = lod_dt_obj(child);
684
685         LASSERT(lc->ldo_stripenr == 0);
686         LASSERT(lc->ldo_stripe == NULL);
687
688         /*
689          * local object may want some hints
690          * in case of late striping creation, ->ah_init()
691          * can be called with local object existing
692          */
693         if (!dt_object_exists(nextc) || dt_object_remote(nextc))
694                 nextc->do_ops->do_ah_init(env, ah, nextp, nextc, child_mode);
695
696         if (S_ISDIR(child_mode)) {
697                 if (lp->ldo_striping_cached == 0) {
698                         /* we haven't tried to get default striping for
699                          * the directory yet, let's cache it in the object */
700                         lod_cache_parent_striping(env, lp);
701                 }
702                 /* transfer defaults to new directory */
703                 if (lp->ldo_striping_cached) {
704                         if (lp->ldo_pool)
705                                 lod_object_set_pool(lc, lp->ldo_pool);
706                         lc->ldo_def_stripenr = lp->ldo_def_stripenr;
707                         lc->ldo_def_stripe_size = lp->ldo_def_stripe_size;
708                         lc->ldo_def_stripe_offset = lp->ldo_def_stripe_offset;
709                         lc->ldo_striping_cached = 1;
710                         lc->ldo_def_striping_set = 1;
711                         CDEBUG(D_OTHER, "inherite EA sz:%d off:%d nr:%d\n",
712                                (int)lc->ldo_def_stripenr,
713                                (int)lc->ldo_def_stripe_size,
714                                (int)lc->ldo_def_stripe_offset);
715                 }
716                 return;
717         }
718
719         /*
720          * if object is going to be striped over OSTs, transfer default
721          * striping information to the child, so that we can use it
722          * during declaration and creation
723          */
724         if (!lod_object_will_be_striped(S_ISREG(child_mode),
725                                         lu_object_fid(&child->do_lu)))
726                 return;
727
728         /*
729          * try from the parent
730          */
731         if (likely(parent)) {
732                 if (lp->ldo_striping_cached == 0) {
733                         /* we haven't tried to get default striping for
734                          * the directory yet, let's cache it in the object */
735                         lod_cache_parent_striping(env, lp);
736                 }
737
738                 lc->ldo_def_stripe_offset = (__u16) -1;
739
740                 if (lp->ldo_def_striping_set) {
741                         if (lp->ldo_pool)
742                                 lod_object_set_pool(lc, lp->ldo_pool);
743                         lc->ldo_stripenr = lp->ldo_def_stripenr;
744                         lc->ldo_stripe_size = lp->ldo_def_stripe_size;
745                         lc->ldo_def_stripe_offset = lp->ldo_def_stripe_offset;
746                         CDEBUG(D_OTHER, "striping from parent: #%d, sz %d %s\n",
747                                lc->ldo_stripenr, lc->ldo_stripe_size,
748                                lp->ldo_pool ? lp->ldo_pool : "");
749                 }
750         }
751
752         /*
753          * if the parent doesn't provide with specific pattern, grab fs-wide one
754          */
755         desc = &d->lod_desc;
756         if (lc->ldo_stripenr == 0)
757                 lc->ldo_stripenr = desc->ld_default_stripe_count;
758         if (lc->ldo_stripe_size == 0)
759                 lc->ldo_stripe_size = desc->ld_default_stripe_size;
760         CDEBUG(D_OTHER, "final striping: # %d stripes, sz %d from %s\n",
761                lc->ldo_stripenr, lc->ldo_stripe_size,
762                lc->ldo_pool ? lc->ldo_pool : "");
763
764         EXIT;
765 }
766
767 #define ll_do_div64(aaa,bbb)    do_div((aaa), (bbb))
768 /*
769  * this function handles a special case when truncate was done
770  * on a stripeless object and now striping is being created
771  * we can't lose that size, so we have to propagate it to newly
772  * created object
773  */
774 static int lod_declare_init_size(const struct lu_env *env,
775                                  struct dt_object *dt, struct thandle *th)
776 {
777         struct dt_object   *next = dt_object_child(dt);
778         struct lod_object  *lo = lod_dt_obj(dt);
779         struct lu_attr     *attr = &lod_env_info(env)->lti_attr;
780         uint64_t            size, offs;
781         int                 rc, stripe;
782         ENTRY;
783
784         /* XXX: we support the simplest (RAID0) striping so far */
785         LASSERT(lo->ldo_stripe || lo->ldo_stripenr == 0);
786         LASSERT(lo->ldo_stripe_size > 0);
787
788         rc = dt_attr_get(env, next, attr, BYPASS_CAPA);
789         LASSERT(attr->la_valid & LA_SIZE);
790         if (rc)
791                 RETURN(rc);
792
793         size = attr->la_size;
794         if (size == 0)
795                 RETURN(0);
796
797         /* ll_do_div64(a, b) returns a % b, and a = a / b */
798         ll_do_div64(size, (__u64) lo->ldo_stripe_size);
799         stripe = ll_do_div64(size, (__u64) lo->ldo_stripenr);
800
801         size = size * lo->ldo_stripe_size;
802         offs = attr->la_size;
803         size += ll_do_div64(offs, lo->ldo_stripe_size);
804
805         attr->la_valid = LA_SIZE;
806         attr->la_size = size;
807
808         rc = dt_declare_attr_set(env, lo->ldo_stripe[stripe], attr, th);
809
810         RETURN(rc);
811 }
812
813
814 /**
815  * Create declaration of striped object
816  */
817 int lod_declare_striped_object(const struct lu_env *env, struct dt_object *dt,
818                                struct lu_attr *attr,
819                                const struct lu_buf *lovea, struct thandle *th)
820 {
821         struct lod_thread_info  *info = lod_env_info(env);
822         struct dt_object        *next = dt_object_child(dt);
823         struct lod_object       *lo = lod_dt_obj(dt);
824         int                      rc;
825         ENTRY;
826
827         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_ALLOC_OBDO)) {
828                 /* failed to create striping, let's reset
829                  * config so that others don't get confused */
830                 lod_object_free_striping(env, lo);
831                 GOTO(out, rc = -ENOMEM);
832         }
833
834         /* choose OST and generate appropriate objects */
835         rc = lod_qos_prep_create(env, lo, attr, lovea, th);
836         if (rc) {
837                 /* failed to create striping, let's reset
838                  * config so that others don't get confused */
839                 lod_object_free_striping(env, lo);
840                 GOTO(out, rc);
841         }
842
843         /*
844          * declare storage for striping data
845          */
846         info->lti_buf.lb_len = lov_mds_md_size(lo->ldo_stripenr,
847                                 lo->ldo_pool ?  LOV_MAGIC_V3 : LOV_MAGIC_V1);
848         rc = dt_declare_xattr_set(env, next, &info->lti_buf, XATTR_NAME_LOV,
849                                   0, th);
850         if (rc)
851                 GOTO(out, rc);
852
853         /*
854          * if striping is created with local object's size > 0,
855          * we have to propagate this size to specific object
856          * the case is possible only when local object was created previously
857          */
858         if (dt_object_exists(next))
859                 rc = lod_declare_init_size(env, dt, th);
860
861 out:
862         RETURN(rc);
863 }
864
865 static int lod_declare_object_create(const struct lu_env *env,
866                                      struct dt_object *dt,
867                                      struct lu_attr *attr,
868                                      struct dt_allocation_hint *hint,
869                                      struct dt_object_format *dof,
870                                      struct thandle *th)
871 {
872         struct dt_object   *next = dt_object_child(dt);
873         struct lod_object  *lo = lod_dt_obj(dt);
874         int                 rc;
875         ENTRY;
876
877         LASSERT(dof);
878         LASSERT(attr);
879         LASSERT(th);
880
881         /*
882          * first of all, we declare creation of local object
883          */
884         rc = dt_declare_create(env, next, attr, hint, dof, th);
885         if (rc)
886                 GOTO(out, rc);
887
888         if (dof->dof_type == DFT_SYM)
889                 dt->do_body_ops = &lod_body_lnk_ops;
890
891         /*
892          * it's lod_ah_init() who has decided the object will striped
893          */
894         if (dof->dof_type == DFT_REGULAR) {
895                 /* callers don't want stripes */
896                 /* XXX: all tricky interactions with ->ah_make_hint() decided
897                  * to use striping, then ->declare_create() behaving differently
898                  * should be cleaned */
899                 if (dof->u.dof_reg.striped == 0)
900                         lo->ldo_stripenr = 0;
901                 if (lo->ldo_stripenr > 0)
902                         rc = lod_declare_striped_object(env, dt, attr,
903                                                         NULL, th);
904         } else if (dof->dof_type == DFT_DIR && lo->ldo_striping_cached) {
905                 struct lod_thread_info *info = lod_env_info(env);
906
907                 struct lov_user_md_v3 *v3;
908
909                 if (LOVEA_DELETE_VALUES(lo->ldo_def_stripe_size,
910                                         lo->ldo_def_stripenr,
911                                         lo->ldo_def_stripe_offset))
912                         RETURN(0);
913
914                 OBD_ALLOC_PTR(v3);
915                 if (v3 == NULL)
916                         RETURN(-ENOMEM);
917
918                 v3->lmm_magic = cpu_to_le32(LOV_MAGIC_V3);
919                 v3->lmm_pattern = cpu_to_le32(LOV_PATTERN_RAID0);
920                 fid_ostid_pack(lu_object_fid(&dt->do_lu), &v3->lmm_oi);
921                 ostid_cpu_to_le(&v3->lmm_oi, &v3->lmm_oi);
922                 v3->lmm_stripe_size = cpu_to_le32(lo->ldo_def_stripe_size);
923                 v3->lmm_stripe_count = cpu_to_le32(lo->ldo_def_stripenr);
924                 v3->lmm_stripe_offset = cpu_to_le16(lo->ldo_def_stripe_offset);
925                 if (lo->ldo_pool)
926                         strncpy(v3->lmm_pool_name, lo->ldo_pool,
927                                 LOV_MAXPOOLNAME);
928
929                 info->lti_buf.lb_buf = v3;
930                 info->lti_buf.lb_len = sizeof(*v3);
931
932                 /* to transfer default striping from the parent */
933                 rc = dt_declare_xattr_set(env, next, &info->lti_buf,
934                                           XATTR_NAME_LOV, 0, th);
935                 OBD_FREE_PTR(v3);
936         }
937
938 out:
939         RETURN(rc);
940 }
941
942 int lod_striping_create(const struct lu_env *env, struct dt_object *dt,
943                         struct lu_attr *attr, struct dt_object_format *dof,
944                         struct thandle *th)
945 {
946         struct lod_object *lo = lod_dt_obj(dt);
947         int                rc = 0, i;
948         ENTRY;
949
950         LASSERT(lo->ldo_stripe);
951         LASSERT(lo->ldo_stripenr > 0);
952         LASSERT(lo->ldo_striping_cached == 0);
953
954         /* create all underlying objects */
955         for (i = 0; i < lo->ldo_stripenr; i++) {
956                 LASSERT(lo->ldo_stripe[i]);
957                 rc = dt_create(env, lo->ldo_stripe[i], attr, NULL, dof, th);
958
959                 if (rc)
960                         break;
961         }
962         if (rc == 0)
963                 rc = lod_generate_and_set_lovea(env, lo, th);
964
965         RETURN(rc);
966 }
967
968 static int lod_object_create(const struct lu_env *env, struct dt_object *dt,
969                              struct lu_attr *attr,
970                              struct dt_allocation_hint *hint,
971                              struct dt_object_format *dof, struct thandle *th)
972 {
973         struct dt_object   *next = dt_object_child(dt);
974         struct lod_object  *lo = lod_dt_obj(dt);
975         int                 rc;
976         ENTRY;
977
978         /* create local object */
979         rc = dt_create(env, next, attr, hint, dof, th);
980
981         if (rc == 0) {
982                 if (S_ISDIR(dt->do_lu.lo_header->loh_attr))
983                         rc = lod_store_def_striping(env, dt, th);
984                 else if (lo->ldo_stripe)
985                         rc = lod_striping_create(env, dt, attr, dof, th);
986         }
987
988         RETURN(rc);
989 }
990
991 static int lod_declare_object_destroy(const struct lu_env *env,
992                                       struct dt_object *dt,
993                                       struct thandle *th)
994 {
995         struct dt_object   *next = dt_object_child(dt);
996         struct lod_object  *lo = lod_dt_obj(dt);
997         int                 rc, i;
998         ENTRY;
999
1000         /*
1001          * we declare destroy for the local object
1002          */
1003         rc = dt_declare_destroy(env, next, th);
1004         if (rc)
1005                 RETURN(rc);
1006
1007         /*
1008          * load striping information, notice we don't do this when object
1009          * is being initialized as we don't need this information till
1010          * few specific cases like destroy, chown
1011          */
1012         rc = lod_load_striping(env, lo);
1013         if (rc)
1014                 RETURN(rc);
1015
1016         /* declare destroy for all underlying objects */
1017         for (i = 0; i < lo->ldo_stripenr; i++) {
1018                 LASSERT(lo->ldo_stripe[i]);
1019                 rc = dt_declare_destroy(env, lo->ldo_stripe[i], th);
1020
1021                 if (rc)
1022                         break;
1023         }
1024
1025         RETURN(rc);
1026 }
1027
1028 static int lod_object_destroy(const struct lu_env *env,
1029                 struct dt_object *dt, struct thandle *th)
1030 {
1031         struct dt_object  *next = dt_object_child(dt);
1032         struct lod_object *lo = lod_dt_obj(dt);
1033         int                rc, i;
1034         ENTRY;
1035
1036         /* destroy local object */
1037         rc = dt_destroy(env, next, th);
1038         if (rc)
1039                 RETURN(rc);
1040
1041         /* destroy all underlying objects */
1042         for (i = 0; i < lo->ldo_stripenr; i++) {
1043                 LASSERT(lo->ldo_stripe[i]);
1044                 rc = dt_destroy(env, lo->ldo_stripe[i], th);
1045                 if (rc)
1046                         break;
1047         }
1048
1049         RETURN(rc);
1050 }
1051
1052 static int lod_index_try(const struct lu_env *env, struct dt_object *dt,
1053                          const struct dt_index_features *feat)
1054 {
1055         struct dt_object *next = dt_object_child(dt);
1056         int               rc;
1057         ENTRY;
1058
1059         LASSERT(next->do_ops);
1060         LASSERT(next->do_ops->do_index_try);
1061
1062         rc = next->do_ops->do_index_try(env, next, feat);
1063         if (next->do_index_ops && dt->do_index_ops == NULL)
1064                 dt->do_index_ops = &lod_index_ops;
1065
1066         RETURN(rc);
1067 }
1068
1069 static int lod_declare_ref_add(const struct lu_env *env,
1070                                struct dt_object *dt, struct thandle *th)
1071 {
1072         return dt_declare_ref_add(env, dt_object_child(dt), th);
1073 }
1074
1075 static int lod_ref_add(const struct lu_env *env,
1076                        struct dt_object *dt, struct thandle *th)
1077 {
1078         return dt_ref_add(env, dt_object_child(dt), th);
1079 }
1080
1081 static int lod_declare_ref_del(const struct lu_env *env,
1082                                struct dt_object *dt, struct thandle *th)
1083 {
1084         return dt_declare_ref_del(env, dt_object_child(dt), th);
1085 }
1086
1087 static int lod_ref_del(const struct lu_env *env,
1088                        struct dt_object *dt, struct thandle *th)
1089 {
1090         return dt_ref_del(env, dt_object_child(dt), th);
1091 }
1092
1093 static struct obd_capa *lod_capa_get(const struct lu_env *env,
1094                                      struct dt_object *dt,
1095                                      struct lustre_capa *old, __u64 opc)
1096 {
1097         return dt_capa_get(env, dt_object_child(dt), old, opc);
1098 }
1099
1100 static int lod_object_sync(const struct lu_env *env, struct dt_object *dt)
1101 {
1102         return dt_object_sync(env, dt_object_child(dt));
1103 }
1104
1105 struct dt_object_operations lod_obj_ops = {
1106         .do_read_lock           = lod_object_read_lock,
1107         .do_write_lock          = lod_object_write_lock,
1108         .do_read_unlock         = lod_object_read_unlock,
1109         .do_write_unlock        = lod_object_write_unlock,
1110         .do_write_locked        = lod_object_write_locked,
1111         .do_attr_get            = lod_attr_get,
1112         .do_declare_attr_set    = lod_declare_attr_set,
1113         .do_attr_set            = lod_attr_set,
1114         .do_xattr_get           = lod_xattr_get,
1115         .do_declare_xattr_set   = lod_declare_xattr_set,
1116         .do_xattr_set           = lod_xattr_set,
1117         .do_declare_xattr_del   = lod_declare_xattr_del,
1118         .do_xattr_del           = lod_xattr_del,
1119         .do_xattr_list          = lod_xattr_list,
1120         .do_ah_init             = lod_ah_init,
1121         .do_declare_create      = lod_declare_object_create,
1122         .do_create              = lod_object_create,
1123         .do_declare_destroy     = lod_declare_object_destroy,
1124         .do_destroy             = lod_object_destroy,
1125         .do_index_try           = lod_index_try,
1126         .do_declare_ref_add     = lod_declare_ref_add,
1127         .do_ref_add             = lod_ref_add,
1128         .do_declare_ref_del     = lod_declare_ref_del,
1129         .do_ref_del             = lod_ref_del,
1130         .do_capa_get            = lod_capa_get,
1131         .do_object_sync         = lod_object_sync,
1132 };
1133
1134 static int lod_object_lock(const struct lu_env *env,
1135                            struct dt_object *dt, struct lustre_handle *lh,
1136                            struct ldlm_enqueue_info *einfo,
1137                            void *policy)
1138 {
1139         struct dt_object   *next = dt_object_child(dt);
1140         int              rc;
1141         ENTRY;
1142
1143         /*
1144          * declare setattr on the local object
1145          */
1146         rc = dt_object_lock(env, next, lh, einfo, policy);
1147
1148         RETURN(rc);
1149 }
1150
1151 struct dt_lock_operations lod_lock_ops = {
1152         .do_object_lock       = lod_object_lock,
1153 };
1154 static ssize_t lod_read(const struct lu_env *env, struct dt_object *dt,
1155                         struct lu_buf *buf, loff_t *pos,
1156                         struct lustre_capa *capa)
1157 {
1158         struct dt_object *next = dt_object_child(dt);
1159         return next->do_body_ops->dbo_read(env, next, buf, pos, capa);
1160 }
1161
1162 static ssize_t lod_declare_write(const struct lu_env *env,
1163                                  struct dt_object *dt,
1164                                  const loff_t size, loff_t pos,
1165                                  struct thandle *th)
1166 {
1167         return dt_declare_record_write(env, dt_object_child(dt),
1168                                        size, pos, th);
1169 }
1170
1171 static ssize_t lod_write(const struct lu_env *env, struct dt_object *dt,
1172                          const struct lu_buf *buf, loff_t *pos,
1173                          struct thandle *th, struct lustre_capa *capa, int iq)
1174 {
1175         struct dt_object *next = dt_object_child(dt);
1176         LASSERT(next);
1177         return next->do_body_ops->dbo_write(env, next, buf, pos, th, capa, iq);
1178 }
1179
1180 static const struct dt_body_operations lod_body_lnk_ops = {
1181         .dbo_read               = lod_read,
1182         .dbo_declare_write      = lod_declare_write,
1183         .dbo_write              = lod_write
1184 };
1185
1186 static int lod_object_init(const struct lu_env *env, struct lu_object *o,
1187                            const struct lu_object_conf *conf)
1188 {
1189         struct lod_device *d = lu2lod_dev(o->lo_dev);
1190         struct lu_object  *below;
1191         struct lu_device  *under;
1192         ENTRY;
1193
1194         /*
1195          * create local object
1196          */
1197         under = &d->lod_child->dd_lu_dev;
1198         below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
1199         if (below == NULL)
1200                 RETURN(-ENOMEM);
1201
1202         lu_object_add(o, below);
1203
1204         RETURN(0);
1205 }
1206
1207 void lod_object_free_striping(const struct lu_env *env, struct lod_object *lo)
1208 {
1209         int i;
1210
1211         if (lo->ldo_stripe) {
1212                 LASSERT(lo->ldo_stripes_allocated > 0);
1213
1214                 for (i = 0; i < lo->ldo_stripenr; i++) {
1215                         if (lo->ldo_stripe[i])
1216                                 lu_object_put(env, &lo->ldo_stripe[i]->do_lu);
1217                 }
1218
1219                 i = sizeof(struct dt_object *) * lo->ldo_stripes_allocated;
1220                 OBD_FREE(lo->ldo_stripe, i);
1221                 lo->ldo_stripe = NULL;
1222                 lo->ldo_stripes_allocated = 0;
1223         }
1224         lo->ldo_stripenr = 0;
1225 }
1226
1227 /*
1228  * ->start is called once all slices are initialized, including header's
1229  * cache for mode (object type). using the type we can initialize ops
1230  */
1231 static int lod_object_start(const struct lu_env *env, struct lu_object *o)
1232 {
1233         if (S_ISLNK(o->lo_header->loh_attr & S_IFMT))
1234                 lu2lod_obj(o)->ldo_obj.do_body_ops = &lod_body_lnk_ops;
1235         return 0;
1236 }
1237
1238 static void lod_object_free(const struct lu_env *env, struct lu_object *o)
1239 {
1240         struct lod_object *mo = lu2lod_obj(o);
1241
1242         /*
1243          * release all underlying object pinned
1244          */
1245
1246         lod_object_free_striping(env, mo);
1247
1248         lod_object_set_pool(mo, NULL);
1249
1250         lu_object_fini(o);
1251         OBD_SLAB_FREE_PTR(mo, lod_object_kmem);
1252 }
1253
1254 static void lod_object_release(const struct lu_env *env, struct lu_object *o)
1255 {
1256         /* XXX: shouldn't we release everything here in case if object
1257          * creation failed before? */
1258 }
1259
1260 static int lod_object_print(const struct lu_env *env, void *cookie,
1261                             lu_printer_t p, const struct lu_object *l)
1262 {
1263         struct lod_object *o = lu2lod_obj((struct lu_object *) l);
1264
1265         return (*p)(env, cookie, LUSTRE_LOD_NAME"-object@%p", o);
1266 }
1267
1268 struct lu_object_operations lod_lu_obj_ops = {
1269         .loo_object_init        = lod_object_init,
1270         .loo_object_start       = lod_object_start,
1271         .loo_object_free        = lod_object_free,
1272         .loo_object_release     = lod_object_release,
1273         .loo_object_print       = lod_object_print,
1274 };
1275
1276 /**
1277  * Init remote lod object
1278  */
1279 static int lod_robject_init(const struct lu_env *env, struct lu_object *lo,
1280                             const struct lu_object_conf *conf)
1281 {
1282         struct lod_device *lod = lu2lod_dev(lo->lo_dev);
1283         struct lod_tgt_descs *ltd = &lod->lod_mdt_descs;
1284         struct lu_device  *c_dev = NULL;
1285         struct lu_object  *c_obj;
1286         int i;
1287         ENTRY;
1288
1289         lod_getref(ltd);
1290         if (ltd->ltd_tgts_size > 0) {
1291                 cfs_foreach_bit(ltd->ltd_tgt_bitmap, i) {
1292                         struct lod_tgt_desc *tgt;
1293                         tgt = LTD_TGT(ltd, i);
1294                         LASSERT(tgt && tgt->ltd_tgt);
1295                         if (tgt->ltd_index ==
1296                             lu2lod_obj(lo)->ldo_mds_num) {
1297                                 c_dev = &(tgt->ltd_tgt->dd_lu_dev);
1298                                 break;
1299                         }
1300                 }
1301         }
1302         lod_putref(lod, ltd);
1303
1304         if (unlikely(c_dev == NULL))
1305                 RETURN(-ENOENT);
1306
1307         c_obj = c_dev->ld_ops->ldo_object_alloc(env, lo->lo_header, c_dev);
1308         if (unlikely(c_obj == NULL))
1309                 RETURN(-ENOMEM);
1310
1311         lu_object_add(lo, c_obj);
1312
1313         RETURN(0);
1314 }
1315
1316 struct lu_object_operations lod_lu_robj_ops = {
1317         .loo_object_init      = lod_robject_init,
1318         .loo_object_start     = lod_object_start,
1319         .loo_object_free      = lod_object_free,
1320         .loo_object_release   = lod_object_release,
1321         .loo_object_print     = lod_object_print,
1322 };