4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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.
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
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2012, Intel, Inc.
29 * lustre/lod/lod_object.c
31 * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
35 # define EXPORT_SYMTAB
37 #define DEBUG_SUBSYSTEM S_MDS
40 #include <obd_class.h>
41 #include <lustre_ver.h>
42 #include <obd_support.h>
43 #include <lprocfs_status.h>
45 #include <lustre_fid.h>
46 #include <lustre_param.h>
47 #include <lustre_fid.h>
50 #include "lod_internal.h"
52 extern cfs_mem_cache_t *lod_object_kmem;
53 static const struct dt_body_operations lod_body_lnk_ops;
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)
59 struct dt_object *next = dt_object_child(dt);
60 return next->do_index_ops->dio_lookup(env, next, rec, key, capa);
63 static int lod_declare_index_insert(const struct lu_env *env,
65 const struct dt_rec *rec,
66 const struct dt_key *key,
67 struct thandle *handle)
69 return dt_declare_insert(env, dt_object_child(dt), rec, key, handle);
72 static int lod_index_insert(const struct lu_env *env,
74 const struct dt_rec *rec,
75 const struct dt_key *key,
77 struct lustre_capa *capa,
80 return dt_insert(env, dt_object_child(dt), rec, key, th, capa, ign);
83 static int lod_declare_index_delete(const struct lu_env *env,
85 const struct dt_key *key,
88 return dt_declare_delete(env, dt_object_child(dt), key, th);
91 static int lod_index_delete(const struct lu_env *env,
93 const struct dt_key *key,
95 struct lustre_capa *capa)
97 return dt_delete(env, dt_object_child(dt), key, th, capa);
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)
104 struct dt_object *next = dt_object_child(dt);
106 return next->do_index_ops->dio_it.init(env, next, attr, capa);
109 static struct dt_index_operations lod_index_ops = {
110 .dio_lookup = lod_index_lookup,
111 .dio_declare_insert = lod_declare_index_insert,
112 .dio_insert = lod_index_insert,
113 .dio_declare_delete = lod_declare_index_delete,
114 .dio_delete = lod_index_delete,
120 static void lod_object_read_lock(const struct lu_env *env,
121 struct dt_object *dt, unsigned role)
123 dt_read_lock(env, dt_object_child(dt), role);
126 static void lod_object_write_lock(const struct lu_env *env,
127 struct dt_object *dt, unsigned role)
129 dt_write_lock(env, dt_object_child(dt), role);
132 static void lod_object_read_unlock(const struct lu_env *env,
133 struct dt_object *dt)
135 dt_read_unlock(env, dt_object_child(dt));
138 static void lod_object_write_unlock(const struct lu_env *env,
139 struct dt_object *dt)
141 dt_write_unlock(env, dt_object_child(dt));
144 static int lod_object_write_locked(const struct lu_env *env,
145 struct dt_object *dt)
147 return dt_write_locked(env, dt_object_child(dt));
150 static int lod_attr_get(const struct lu_env *env,
151 struct dt_object *dt,
152 struct lu_attr *attr,
153 struct lustre_capa *capa)
155 return dt_attr_get(env, dt_object_child(dt), attr, capa);
158 static int lod_declare_attr_set(const struct lu_env *env,
159 struct dt_object *dt,
160 const struct lu_attr *attr,
161 struct thandle *handle)
163 struct dt_object *next = dt_object_child(dt);
164 struct lod_object *lo = lod_dt_obj(dt);
169 * declare setattr on the local object
171 rc = dt_declare_attr_set(env, next, attr, handle);
176 * load striping information, notice we don't do this when object
177 * is being initialized as we don't need this information till
178 * few specific cases like destroy, chown
180 rc = lod_load_striping(env, lo);
185 * if object is striped declare changes on the stripes
187 LASSERT(lo->ldo_stripe || lo->ldo_stripenr == 0);
188 for (i = 0; i < lo->ldo_stripenr; i++) {
189 LASSERT(lo->ldo_stripe[i]);
190 rc = dt_declare_attr_set(env, lo->ldo_stripe[i], attr, handle);
192 CERROR("failed declaration: %d\n", rc);
200 static int lod_attr_set(const struct lu_env *env,
201 struct dt_object *dt,
202 const struct lu_attr *attr,
203 struct thandle *handle,
204 struct lustre_capa *capa)
206 struct dt_object *next = dt_object_child(dt);
207 struct lod_object *lo = lod_dt_obj(dt);
212 * apply changes to the local object
214 rc = dt_attr_set(env, next, attr, handle, capa);
219 * if object is striped, apply changes to all the stripes
221 LASSERT(lo->ldo_stripe || lo->ldo_stripenr == 0);
222 for (i = 0; i < lo->ldo_stripenr; i++) {
223 LASSERT(lo->ldo_stripe[i]);
224 rc = dt_attr_set(env, lo->ldo_stripe[i], attr, handle, capa);
226 CERROR("failed declaration: %d\n", rc);
234 static int lod_xattr_get(const struct lu_env *env, struct dt_object *dt,
235 struct lu_buf *buf, const char *name,
236 struct lustre_capa *capa)
238 struct lod_thread_info *info = lod_env_info(env);
239 struct lod_device *dev = lu2lod_dev(dt->do_lu.lo_dev);
243 rc = dt_xattr_get(env, dt_object_child(dt), buf, name, capa);
244 if (rc != -ENODATA || !S_ISDIR(dt->do_lu.lo_header->loh_attr & S_IFMT))
248 * lod returns default striping on the real root of the device
249 * this is like the root stores default striping for the whole
250 * filesystem. historically we've been using a different approach
251 * and store it in the config.
253 dt_root_get(env, dev->lod_child, &info->lti_fid);
254 is_root = lu_fid_eq(&info->lti_fid, lu_object_fid(&dt->do_lu));
256 if (is_root && strcmp(XATTR_NAME_LOV, name) == 0) {
257 struct lov_user_md *lum = buf->lb_buf;
258 struct lov_desc *desc = &dev->lod_desc;
260 if (buf->lb_buf == NULL) {
261 rc = sizeof(struct lov_user_md_v1);
262 } else if (buf->lb_len >= sizeof(struct lov_user_md_v1)) {
263 lum->lmm_magic = LOV_USER_MAGIC_V1;
264 lum->lmm_object_seq = FID_SEQ_LOV_DEFAULT;
265 lum->lmm_pattern = desc->ld_pattern;
266 lum->lmm_stripe_size = desc->ld_default_stripe_size;
267 lum->lmm_stripe_count = desc->ld_default_stripe_count;
268 lum->lmm_stripe_offset = desc->ld_default_stripe_offset;
269 rc = sizeof(struct lov_user_md_v1);
279 * LOV xattr is a storage for striping, and LOD owns this xattr.
280 * but LOD allows others to control striping to some extent
282 * - to set new defined striping
283 * - to set new semi-defined striping
284 * - number of stripes is defined
285 * - number of stripes + osts are defined
288 static int lod_declare_xattr_set(const struct lu_env *env,
289 struct dt_object *dt,
290 const struct lu_buf *buf,
291 const char *name, int fl,
294 struct dt_object *next = dt_object_child(dt);
298 rc = dt_declare_xattr_set(env, next, buf, name, fl, th);
303 static int lod_xattr_set_lov_on_dir(const struct lu_env *env,
304 struct dt_object *dt,
305 const struct lu_buf *buf,
306 const char *name, int fl,
308 struct lustre_capa *capa)
310 struct lod_device *d = lu2lod_dev(dt->do_lu.lo_dev);
311 struct dt_object *next = dt_object_child(dt);
312 struct lod_object *l = lod_dt_obj(dt);
313 struct lov_user_md_v1 *lum;
314 struct lov_user_md_v3 *v3 = NULL;
318 LASSERT(l->ldo_stripe == NULL);
319 l->ldo_striping_cached = 0;
320 l->ldo_def_striping_set = 0;
321 lod_object_set_pool(l, NULL);
322 l->ldo_def_stripe_size = 0;
323 l->ldo_def_stripenr = 0;
326 LASSERT(buf->lb_buf);
329 rc = lod_verify_striping(d, buf, 0);
333 if (lum->lmm_magic == LOV_USER_MAGIC_V3)
336 /* if { size, offset, count } = { 0, -1, 0 } and no pool
337 * (i.e. all default values specified) then delete default
338 * striping from dir. */
340 "set default striping: sz %u # %u offset %d %s %s\n",
341 (unsigned)lum->lmm_stripe_size,
342 (unsigned)lum->lmm_stripe_count,
343 (int)lum->lmm_stripe_offset,
344 v3 ? "from" : "", v3 ? v3->lmm_pool_name : "");
346 if (LOVEA_DELETE_VALUES((lum->lmm_stripe_size),
347 (lum->lmm_stripe_count),
348 (lum->lmm_stripe_offset)) &&
349 lum->lmm_magic == LOV_USER_MAGIC_V1) {
350 rc = dt_xattr_del(env, next, name, th, capa);
354 rc = dt_xattr_set(env, next, buf, name, fl, th, capa);
360 static int lod_xattr_set(const struct lu_env *env,
361 struct dt_object *dt, const struct lu_buf *buf,
362 const char *name, int fl, struct thandle *th,
363 struct lustre_capa *capa)
365 struct dt_object *next = dt_object_child(dt);
370 attr = dt->do_lu.lo_header->loh_attr & S_IFMT;
372 if (strncmp(name, XATTR_NAME_LOV, strlen(XATTR_NAME_LOV)) == 0)
373 rc = lod_xattr_set_lov_on_dir(env, dt, buf, name,
376 rc = dt_xattr_set(env, next, buf, name, fl, th, capa);
380 * behave transparantly for all other EAs
382 rc = dt_xattr_set(env, next, buf, name, fl, th, capa);
388 static int lod_declare_xattr_del(const struct lu_env *env,
389 struct dt_object *dt, const char *name,
392 return dt_declare_xattr_del(env, dt_object_child(dt), name, th);
395 static int lod_xattr_del(const struct lu_env *env, struct dt_object *dt,
396 const char *name, struct thandle *th,
397 struct lustre_capa *capa)
399 return dt_xattr_del(env, dt_object_child(dt), name, th, capa);
402 static int lod_xattr_list(const struct lu_env *env,
403 struct dt_object *dt, struct lu_buf *buf,
404 struct lustre_capa *capa)
406 return dt_xattr_list(env, dt_object_child(dt), buf, capa);
409 int lod_object_set_pool(struct lod_object *o, char *pool)
414 len = strlen(o->ldo_pool);
415 OBD_FREE(o->ldo_pool, len + 1);
420 OBD_ALLOC(o->ldo_pool, len + 1);
421 if (o->ldo_pool == NULL)
423 strcpy(o->ldo_pool, pool);
428 static inline int lod_object_will_be_striped(int is_reg, const struct lu_fid *fid)
430 return (is_reg && fid_seq(fid) != FID_SEQ_LOCAL_FILE);
433 static int lod_cache_parent_striping(const struct lu_env *env,
434 struct lod_object *lp)
436 struct lov_user_md_v1 *v1 = NULL;
437 struct lov_user_md_v3 *v3 = NULL;
441 /* dt_ah_init() is called from MDD without parent being write locked
443 dt_write_lock(env, dt_object_child(&lp->ldo_obj), 0);
444 if (lp->ldo_striping_cached)
445 GOTO(unlock, rc = 0);
447 rc = lod_get_lov_ea(env, lp);
451 if (rc < sizeof(struct lov_user_md)) {
452 /* don't lookup for non-existing or invalid striping */
453 lp->ldo_def_striping_set = 0;
454 lp->ldo_striping_cached = 1;
455 lp->ldo_def_stripe_size = 0;
456 lp->ldo_def_stripenr = 0;
457 lp->ldo_def_stripe_offset = (typeof(v1->lmm_stripe_offset))(-1);
458 GOTO(unlock, rc = 0);
461 v1 = (struct lov_user_md_v1 *)lod_env_info(env)->lti_ea_store;
462 if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V1))
463 lustre_swab_lov_user_md_v1(v1);
464 else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V3))
465 lustre_swab_lov_user_md_v3(v3);
467 if (v1->lmm_magic != LOV_MAGIC_V3 && v1->lmm_magic != LOV_MAGIC_V1)
468 GOTO(unlock, rc = 0);
470 if (v1->lmm_pattern != LOV_PATTERN_RAID0 && v1->lmm_pattern != 0)
471 GOTO(unlock, rc = 0);
473 lp->ldo_def_stripenr = v1->lmm_stripe_count;
474 lp->ldo_def_stripe_size = v1->lmm_stripe_size;
475 lp->ldo_def_stripe_offset = v1->lmm_stripe_offset;
476 lp->ldo_striping_cached = 1;
477 lp->ldo_def_striping_set = 1;
479 if (v1->lmm_magic == LOV_USER_MAGIC_V3) {
480 /* XXX: sanity check here */
481 v3 = (struct lov_user_md_v3 *) v1;
482 if (v3->lmm_pool_name[0])
483 lod_object_set_pool(lp, v3->lmm_pool_name);
486 CDEBUG(D_OTHER, "def. striping: # %d, sz %d, off %d %s%s on "DFID"\n",
487 lp->ldo_def_stripenr, lp->ldo_def_stripe_size,
488 lp->ldo_def_stripe_offset, v3 ? "from " : "",
489 v3 ? lp->ldo_pool : "", PFID(lu_object_fid(&lp->ldo_obj.do_lu)));
493 dt_write_unlock(env, dt_object_child(&lp->ldo_obj));
498 * used to transfer default striping data to the object being created
500 static void lod_ah_init(const struct lu_env *env,
501 struct dt_allocation_hint *ah,
502 struct dt_object *parent,
503 struct dt_object *child,
504 cfs_umode_t child_mode)
506 struct lod_device *d = lu2lod_dev(child->do_lu.lo_dev);
507 struct dt_object *nextp = NULL;
508 struct dt_object *nextc;
509 struct lod_object *lp = NULL;
510 struct lod_object *lc;
511 struct lov_desc *desc;
516 if (likely(parent)) {
517 nextp = dt_object_child(parent);
518 lp = lod_dt_obj(parent);
521 nextc = dt_object_child(child);
522 lc = lod_dt_obj(child);
524 LASSERT(lc->ldo_stripenr == 0);
525 LASSERT(lc->ldo_stripe == NULL);
528 * local object may want some hints
529 * in case of late striping creation, ->ah_init()
530 * can be called with local object existing
532 if (!dt_object_exists(nextc))
533 nextc->do_ops->do_ah_init(env, ah, nextp, nextc, child_mode);
535 if (S_ISDIR(child_mode)) {
536 if (lp->ldo_striping_cached == 0) {
537 /* we haven't tried to get default striping for
538 * the directory yet, let's cache it in the object */
539 lod_cache_parent_striping(env, lp);
541 /* transfer defaults to new directory */
542 if (lp->ldo_striping_cached) {
544 lod_object_set_pool(lc, lp->ldo_pool);
545 lc->ldo_def_stripenr = lp->ldo_def_stripenr;
546 lc->ldo_def_stripe_size = lp->ldo_def_stripe_size;
547 lc->ldo_def_stripe_offset = lp->ldo_def_stripe_offset;
548 lc->ldo_striping_cached = 1;
549 lc->ldo_def_striping_set = 1;
550 CDEBUG(D_OTHER, "inherite striping defaults\n");
556 * if object is going to be striped over OSTs, transfer default
557 * striping information to the child, so that we can use it
558 * during declaration and creation
560 if (!lod_object_will_be_striped(S_ISREG(child_mode),
561 lu_object_fid(&child->do_lu)))
565 * try from the parent
567 if (likely(parent)) {
568 if (lp->ldo_striping_cached == 0) {
569 /* we haven't tried to get default striping for
570 * the directory yet, let's cache it in the object */
571 lod_cache_parent_striping(env, lp);
574 lc->ldo_def_stripe_offset = (__u16) -1;
576 if (lp->ldo_def_striping_set) {
578 lod_object_set_pool(lc, lp->ldo_pool);
579 lc->ldo_stripenr = lp->ldo_def_stripenr;
580 lc->ldo_stripe_size = lp->ldo_def_stripe_size;
581 lc->ldo_def_stripe_offset = lp->ldo_def_stripe_offset;
582 CDEBUG(D_OTHER, "striping from parent: #%d, sz %d %s\n",
583 lc->ldo_stripenr, lc->ldo_stripe_size,
584 lp->ldo_pool ? lp->ldo_pool : "");
589 * if the parent doesn't provide with specific pattern, grab fs-wide one
592 if (lc->ldo_stripenr == 0)
593 lc->ldo_stripenr = desc->ld_default_stripe_count;
594 if (lc->ldo_stripe_size == 0)
595 lc->ldo_stripe_size = desc->ld_default_stripe_size;
596 CDEBUG(D_OTHER, "final striping: # %d stripes, sz %d from %s\n",
597 lc->ldo_stripenr, lc->ldo_stripe_size,
598 lc->ldo_pool ? lc->ldo_pool : "");
603 static int lod_declare_object_create(const struct lu_env *env,
604 struct dt_object *dt,
605 struct lu_attr *attr,
606 struct dt_allocation_hint *hint,
607 struct dt_object_format *dof,
610 struct dt_object *next = dt_object_child(dt);
611 struct lod_object *lo = lod_dt_obj(dt);
618 LASSERT(!dt_object_exists(next));
621 * first of all, we declare creation of local object
623 rc = dt_declare_create(env, next, attr, hint, dof, th);
627 if (dof->dof_type == DFT_SYM)
628 dt->do_body_ops = &lod_body_lnk_ops;
630 if (dof->dof_type == DFT_DIR && lo->ldo_striping_cached) {
631 struct lod_thread_info *info = lod_env_info(env);
633 info->lti_buf.lb_buf = NULL;
634 info->lti_buf.lb_len = sizeof(struct lov_user_md_v3);
635 /* to transfer default striping from the parent */
636 rc = dt_declare_xattr_set(env, next, &info->lti_buf,
637 XATTR_NAME_LOV, 0, th);
644 static int lod_object_create(const struct lu_env *env, struct dt_object *dt,
645 struct lu_attr *attr,
646 struct dt_allocation_hint *hint,
647 struct dt_object_format *dof, struct thandle *th)
649 struct dt_object *next = dt_object_child(dt);
653 /* create local object */
654 rc = dt_create(env, next, attr, hint, dof, th);
657 if (S_ISDIR(dt->do_lu.lo_header->loh_attr))
658 rc = lod_store_def_striping(env, dt, th);
664 static int lod_declare_object_destroy(const struct lu_env *env,
665 struct dt_object *dt,
668 struct dt_object *next = dt_object_child(dt);
669 struct lod_object *lo = lod_dt_obj(dt);
674 * we declare destroy for the local object
676 rc = dt_declare_destroy(env, next, th);
681 * load striping information, notice we don't do this when object
682 * is being initialized as we don't need this information till
683 * few specific cases like destroy, chown
685 rc = lod_load_striping(env, lo);
689 /* declare destroy for all underlying objects */
690 for (i = 0; i < lo->ldo_stripenr; i++) {
691 LASSERT(lo->ldo_stripe[i]);
692 rc = dt_declare_destroy(env, lo->ldo_stripe[i], th);
701 static int lod_object_destroy(const struct lu_env *env,
702 struct dt_object *dt, struct thandle *th)
704 struct dt_object *next = dt_object_child(dt);
705 struct lod_object *lo = lod_dt_obj(dt);
709 /* destroy local object */
710 rc = dt_destroy(env, next, th);
714 /* destroy all underlying objects */
715 for (i = 0; i < lo->ldo_stripenr; i++) {
716 LASSERT(lo->ldo_stripe[i]);
717 rc = dt_destroy(env, lo->ldo_stripe[i], th);
725 static int lod_index_try(const struct lu_env *env, struct dt_object *dt,
726 const struct dt_index_features *feat)
728 struct dt_object *next = dt_object_child(dt);
732 LASSERT(next->do_ops);
733 LASSERT(next->do_ops->do_index_try);
735 rc = next->do_ops->do_index_try(env, next, feat);
736 if (next->do_index_ops && dt->do_index_ops == NULL) {
737 dt->do_index_ops = &lod_index_ops;
738 /* XXX: iterators don't accept device, so bypass LOD */
739 /* will be fixed with DNE */
740 if (lod_index_ops.dio_it.fini == NULL) {
741 lod_index_ops.dio_it = next->do_index_ops->dio_it;
742 lod_index_ops.dio_it.init = lod_it_init;
749 static int lod_declare_ref_add(const struct lu_env *env,
750 struct dt_object *dt, struct thandle *th)
752 return dt_declare_ref_add(env, dt_object_child(dt), th);
755 static int lod_ref_add(const struct lu_env *env,
756 struct dt_object *dt, struct thandle *th)
758 return dt_ref_add(env, dt_object_child(dt), th);
761 static int lod_declare_ref_del(const struct lu_env *env,
762 struct dt_object *dt, struct thandle *th)
764 return dt_declare_ref_del(env, dt_object_child(dt), th);
767 static int lod_ref_del(const struct lu_env *env,
768 struct dt_object *dt, struct thandle *th)
770 return dt_ref_del(env, dt_object_child(dt), th);
773 static struct obd_capa *lod_capa_get(const struct lu_env *env,
774 struct dt_object *dt,
775 struct lustre_capa *old, __u64 opc)
777 return dt_capa_get(env, dt_object_child(dt), old, opc);
780 static int lod_object_sync(const struct lu_env *env, struct dt_object *dt)
782 return dt_object_sync(env, dt_object_child(dt));
785 struct dt_object_operations lod_obj_ops = {
786 .do_read_lock = lod_object_read_lock,
787 .do_write_lock = lod_object_write_lock,
788 .do_read_unlock = lod_object_read_unlock,
789 .do_write_unlock = lod_object_write_unlock,
790 .do_write_locked = lod_object_write_locked,
791 .do_attr_get = lod_attr_get,
792 .do_declare_attr_set = lod_declare_attr_set,
793 .do_attr_set = lod_attr_set,
794 .do_xattr_get = lod_xattr_get,
795 .do_declare_xattr_set = lod_declare_xattr_set,
796 .do_xattr_set = lod_xattr_set,
797 .do_declare_xattr_del = lod_declare_xattr_del,
798 .do_xattr_del = lod_xattr_del,
799 .do_xattr_list = lod_xattr_list,
800 .do_ah_init = lod_ah_init,
801 .do_declare_create = lod_declare_object_create,
802 .do_create = lod_object_create,
803 .do_declare_destroy = lod_declare_object_destroy,
804 .do_destroy = lod_object_destroy,
805 .do_index_try = lod_index_try,
806 .do_declare_ref_add = lod_declare_ref_add,
807 .do_ref_add = lod_ref_add,
808 .do_declare_ref_del = lod_declare_ref_del,
809 .do_ref_del = lod_ref_del,
810 .do_capa_get = lod_capa_get,
811 .do_object_sync = lod_object_sync,
814 static ssize_t lod_read(const struct lu_env *env, struct dt_object *dt,
815 struct lu_buf *buf, loff_t *pos,
816 struct lustre_capa *capa)
818 struct dt_object *next = dt_object_child(dt);
819 return next->do_body_ops->dbo_read(env, next, buf, pos, capa);
822 static ssize_t lod_declare_write(const struct lu_env *env,
823 struct dt_object *dt,
824 const loff_t size, loff_t pos,
827 return dt_declare_record_write(env, dt_object_child(dt),
831 static ssize_t lod_write(const struct lu_env *env, struct dt_object *dt,
832 const struct lu_buf *buf, loff_t *pos,
833 struct thandle *th, struct lustre_capa *capa, int iq)
835 struct dt_object *next = dt_object_child(dt);
837 return next->do_body_ops->dbo_write(env, next, buf, pos, th, capa, iq);
840 static const struct dt_body_operations lod_body_lnk_ops = {
841 .dbo_read = lod_read,
842 .dbo_declare_write = lod_declare_write,
843 .dbo_write = lod_write
846 static int lod_object_init(const struct lu_env *env, struct lu_object *o,
847 const struct lu_object_conf *conf)
849 struct lod_device *d = lu2lod_dev(o->lo_dev);
850 struct lu_object *below;
851 struct lu_device *under;
855 * create local object
857 under = &d->lod_child->dd_lu_dev;
858 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
862 lu_object_add(o, below);
867 void lod_object_free_striping(const struct lu_env *env, struct lod_object *lo)
871 if (lo->ldo_stripe) {
872 LASSERT(lo->ldo_stripes_allocated > 0);
874 for (i = 0; i < lo->ldo_stripenr; i++) {
875 if (lo->ldo_stripe[i])
876 lu_object_put(env, &lo->ldo_stripe[i]->do_lu);
879 i = sizeof(struct dt_object *) * lo->ldo_stripes_allocated;
880 OBD_FREE(lo->ldo_stripe, i);
881 lo->ldo_stripe = NULL;
882 lo->ldo_stripes_allocated = 0;
884 lo->ldo_stripenr = 0;
888 * ->start is called once all slices are initialized, including header's
889 * cache for mode (object type). using the type we can initialize ops
891 static int lod_object_start(const struct lu_env *env, struct lu_object *o)
893 if (S_ISLNK(o->lo_header->loh_attr & S_IFMT))
894 lu2lod_obj(o)->ldo_obj.do_body_ops = &lod_body_lnk_ops;
898 static void lod_object_free(const struct lu_env *env, struct lu_object *o)
900 struct lod_object *mo = lu2lod_obj(o);
903 * release all underlying object pinned
906 lod_object_free_striping(env, mo);
908 lod_object_set_pool(mo, NULL);
911 OBD_SLAB_FREE_PTR(mo, lod_object_kmem);
914 static void lod_object_release(const struct lu_env *env, struct lu_object *o)
916 /* XXX: shouldn't we release everything here in case if object
917 * creation failed before? */
920 static int lod_object_print(const struct lu_env *env, void *cookie,
921 lu_printer_t p, const struct lu_object *l)
923 struct lod_object *o = lu2lod_obj((struct lu_object *) l);
925 return (*p)(env, cookie, LUSTRE_LOD_NAME"-object@%p", o);
928 struct lu_object_operations lod_lu_obj_ops = {
929 .loo_object_init = lod_object_init,
930 .loo_object_start = lod_object_start,
931 .loo_object_free = lod_object_free,
932 .loo_object_release = lod_object_release,
933 .loo_object_print = lod_object_print,