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, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2014, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * Implementation of cl_object for LOV layer.
38 * Author: Nikita Danilov <nikita.danilov@sun.com>
39 * Author: Jinshan Xiong <jinshan.xiong@whamcloud.com>
42 #define DEBUG_SUBSYSTEM S_LOV
44 #include "lov_cl_internal.h"
50 /*****************************************************************************
56 struct lov_layout_operations {
57 int (*llo_init)(const struct lu_env *env, struct lov_device *dev,
58 struct lov_object *lov,
59 const struct cl_object_conf *conf,
60 union lov_layout_state *state);
61 int (*llo_delete)(const struct lu_env *env, struct lov_object *lov,
62 union lov_layout_state *state);
63 void (*llo_fini)(const struct lu_env *env, struct lov_object *lov,
64 union lov_layout_state *state);
65 void (*llo_install)(const struct lu_env *env, struct lov_object *lov,
66 union lov_layout_state *state);
67 int (*llo_print)(const struct lu_env *env, void *cookie,
68 lu_printer_t p, const struct lu_object *o);
69 int (*llo_page_init)(const struct lu_env *env, struct cl_object *obj,
70 struct cl_page *page, pgoff_t index);
71 int (*llo_lock_init)(const struct lu_env *env,
72 struct cl_object *obj, struct cl_lock *lock,
73 const struct cl_io *io);
74 int (*llo_io_init)(const struct lu_env *env,
75 struct cl_object *obj, struct cl_io *io);
76 int (*llo_getattr)(const struct lu_env *env, struct cl_object *obj,
77 struct cl_attr *attr);
78 int (*llo_find_cbdata)(const struct lu_env *env, struct cl_object *obj,
79 ldlm_iterator_t iter, void *data);
82 static int lov_layout_wait(const struct lu_env *env, struct lov_object *lov);
84 struct lov_stripe_md *lov_lsm_get(struct cl_object *clobj)
86 struct lu_object *luobj;
87 struct lov_stripe_md *lsm = NULL;
92 luobj = lu_object_locate(&cl_object_header(clobj)->coh_lu,
95 lsm = lov_lsm_addref(lu2lov(luobj));
98 EXPORT_SYMBOL(lov_lsm_get);
100 void lov_lsm_put(struct cl_object *unused, struct lov_stripe_md *lsm)
103 lov_free_memmd(&lsm);
105 EXPORT_SYMBOL(lov_lsm_put);
107 /*****************************************************************************
109 * Lov object layout operations.
113 static void lov_install_empty(const struct lu_env *env,
114 struct lov_object *lov,
115 union lov_layout_state *state)
118 * File without objects.
122 static int lov_init_empty(const struct lu_env *env,
123 struct lov_device *dev, struct lov_object *lov,
124 const struct cl_object_conf *conf,
125 union lov_layout_state *state)
130 static void lov_install_raid0(const struct lu_env *env,
131 struct lov_object *lov,
132 union lov_layout_state *state)
136 static struct cl_object *lov_sub_find(const struct lu_env *env,
137 struct cl_device *dev,
138 const struct lu_fid *fid,
139 const struct cl_object_conf *conf)
144 o = lu_object_find_at(env, cl2lu_dev(dev), fid, &conf->coc_lu);
145 LASSERT(ergo(!IS_ERR(o), o->lo_dev->ld_type == &lovsub_device_type));
149 static int lov_init_sub(const struct lu_env *env, struct lov_object *lov,
150 struct cl_object *stripe, struct lov_layout_raid0 *r0,
153 struct cl_object_header *hdr;
154 struct cl_object_header *subhdr;
155 struct cl_object_header *parent;
156 struct lov_oinfo *oinfo;
159 if (OBD_FAIL_CHECK(OBD_FAIL_LOV_INIT)) {
160 /* For sanity:test_206.
161 * Do not leave the object in cache to avoid accessing
162 * freed memory. This is because osc_object is referring to
163 * lov_oinfo of lsm_stripe_data which will be freed due to
165 cl_object_kill(env, stripe);
166 cl_object_put(env, stripe);
170 hdr = cl_object_header(lov2cl(lov));
171 subhdr = cl_object_header(stripe);
173 oinfo = lov->lo_lsm->lsm_oinfo[idx];
174 CDEBUG(D_INODE, DFID"@%p[%d] -> "DFID"@%p: ostid: "DOSTID
175 " idx: %d gen: %d\n",
176 PFID(&subhdr->coh_lu.loh_fid), subhdr, idx,
177 PFID(&hdr->coh_lu.loh_fid), hdr, POSTID(&oinfo->loi_oi),
178 oinfo->loi_ost_idx, oinfo->loi_ost_gen);
180 /* reuse ->coh_attr_guard to protect coh_parent change */
181 spin_lock(&subhdr->coh_attr_guard);
182 parent = subhdr->coh_parent;
183 if (parent == NULL) {
184 subhdr->coh_parent = hdr;
185 spin_unlock(&subhdr->coh_attr_guard);
186 subhdr->coh_nesting = hdr->coh_nesting + 1;
187 lu_object_ref_add(&stripe->co_lu, "lov-parent", lov);
188 r0->lo_sub[idx] = cl2lovsub(stripe);
189 r0->lo_sub[idx]->lso_super = lov;
190 r0->lo_sub[idx]->lso_index = idx;
193 struct lu_object *old_obj;
194 struct lov_object *old_lov;
195 unsigned int mask = D_INODE;
197 spin_unlock(&subhdr->coh_attr_guard);
198 old_obj = lu_object_locate(&parent->coh_lu, &lov_device_type);
199 LASSERT(old_obj != NULL);
200 old_lov = cl2lov(lu2cl(old_obj));
201 if (old_lov->lo_layout_invalid) {
202 /* the object's layout has already changed but isn't
204 lu_object_unhash(env, &stripe->co_lu);
211 LU_OBJECT_DEBUG(mask, env, &stripe->co_lu,
212 "stripe %d is already owned.\n", idx);
213 LU_OBJECT_DEBUG(mask, env, old_obj, "owned.\n");
214 LU_OBJECT_HEADER(mask, env, lov2lu(lov), "try to own.\n");
215 cl_object_put(env, stripe);
220 static int lov_page_slice_fixup(struct lov_object *lov,
221 struct cl_object *stripe)
223 struct cl_object_header *hdr = cl_object_header(&lov->lo_cl);
227 return hdr->coh_page_bufsize - lov->lo_cl.co_slice_off -
228 cfs_size_round(sizeof(struct lov_page));
230 cl_object_for_each(o, stripe)
231 o->co_slice_off += hdr->coh_page_bufsize;
233 return cl_object_header(stripe)->coh_page_bufsize;
236 static int lov_init_raid0(const struct lu_env *env,
237 struct lov_device *dev, struct lov_object *lov,
238 const struct cl_object_conf *conf,
239 union lov_layout_state *state)
244 struct cl_object *stripe;
245 struct lov_thread_info *lti = lov_env_info(env);
246 struct cl_object_conf *subconf = <i->lti_stripe_conf;
247 struct lov_stripe_md *lsm = conf->u.coc_md->lsm;
248 struct lu_fid *ofid = <i->lti_fid;
249 struct lov_layout_raid0 *r0 = &state->raid0;
253 if (lsm->lsm_magic != LOV_MAGIC_V1 && lsm->lsm_magic != LOV_MAGIC_V3) {
254 dump_lsm(D_ERROR, lsm);
255 LASSERTF(0, "magic mismatch, expected %d/%d, actual %d.\n",
256 LOV_MAGIC_V1, LOV_MAGIC_V3, lsm->lsm_magic);
259 LASSERT(lov->lo_lsm == NULL);
260 lov->lo_lsm = lsm_addref(lsm);
261 r0->lo_nr = lsm->lsm_stripe_count;
262 LASSERT(r0->lo_nr <= lov_targets_nr(dev));
264 lov->lo_layout_invalid = true;
266 OBD_ALLOC_LARGE(r0->lo_sub, r0->lo_nr * sizeof r0->lo_sub[0]);
267 if (r0->lo_sub != NULL) {
271 subconf->coc_inode = conf->coc_inode;
272 spin_lock_init(&r0->lo_sub_lock);
274 * Create stripe cl_objects.
276 for (i = 0; i < r0->lo_nr && result == 0; ++i) {
277 struct cl_device *subdev;
278 struct lov_oinfo *oinfo = lsm->lsm_oinfo[i];
279 int ost_idx = oinfo->loi_ost_idx;
281 if (lov_oinfo_is_dummy(oinfo))
284 result = ostid_to_fid(ofid, &oinfo->loi_oi,
289 subdev = lovsub2cl_dev(dev->ld_target[ost_idx]);
290 subconf->u.coc_oinfo = oinfo;
291 LASSERTF(subdev != NULL, "not init ost %d\n", ost_idx);
292 /* In the function below, .hs_keycmp resolves to
293 * lu_obj_hop_keycmp() */
294 /* coverity[overrun-buffer-val] */
295 stripe = lov_sub_find(env, subdev, ofid, subconf);
296 if (!IS_ERR(stripe)) {
297 result = lov_init_sub(env, lov, stripe, r0, i);
298 if (result == -EAGAIN) { /* try again */
304 result = PTR_ERR(stripe);
308 int sz = lov_page_slice_fixup(lov, stripe);
309 LASSERT(ergo(psz > 0, psz == sz));
314 cl_object_header(&lov->lo_cl)->coh_page_bufsize += psz;
321 static int lov_init_released(const struct lu_env *env,
322 struct lov_device *dev, struct lov_object *lov,
323 const struct cl_object_conf *conf,
324 union lov_layout_state *state)
326 struct lov_stripe_md *lsm = conf->u.coc_md->lsm;
328 LASSERT(lsm != NULL);
329 LASSERT(lsm_is_released(lsm));
330 LASSERT(lov->lo_lsm == NULL);
332 lov->lo_lsm = lsm_addref(lsm);
336 static struct cl_object *lov_find_subobj(const struct lu_env *env,
337 struct lov_object *lov,
338 struct lov_stripe_md *lsm,
341 struct lov_device *dev = lu2lov_dev(lov2lu(lov)->lo_dev);
342 struct lov_oinfo *oinfo = lsm->lsm_oinfo[stripe_idx];
343 struct lov_thread_info *lti = lov_env_info(env);
344 struct lu_fid *ofid = <i->lti_fid;
345 struct cl_device *subdev;
348 struct cl_object *result;
350 if (lov->lo_type != LLT_RAID0)
351 GOTO(out, result = NULL);
353 ost_idx = oinfo->loi_ost_idx;
354 rc = ostid_to_fid(ofid, &oinfo->loi_oi, ost_idx);
356 GOTO(out, result = NULL);
358 subdev = lovsub2cl_dev(dev->ld_target[ost_idx]);
359 result = lov_sub_find(env, subdev, ofid, NULL);
362 result = ERR_PTR(-EINVAL);
366 static int lov_delete_empty(const struct lu_env *env, struct lov_object *lov,
367 union lov_layout_state *state)
369 LASSERT(lov->lo_type == LLT_EMPTY || lov->lo_type == LLT_RELEASED);
371 lov_layout_wait(env, lov);
375 static void lov_subobject_kill(const struct lu_env *env, struct lov_object *lov,
376 struct lovsub_object *los, int idx)
378 struct cl_object *sub;
379 struct lov_layout_raid0 *r0;
380 struct lu_site *site;
381 struct lu_site_bkt_data *bkt;
382 wait_queue_t *waiter;
385 LASSERT(r0->lo_sub[idx] == los);
387 sub = lovsub2cl(los);
388 site = sub->co_lu.lo_dev->ld_site;
389 bkt = lu_site_bkt_from_fid(site, &sub->co_lu.lo_header->loh_fid);
391 cl_object_kill(env, sub);
392 /* release a reference to the sub-object and ... */
393 lu_object_ref_del(&sub->co_lu, "lov-parent", lov);
394 cl_object_put(env, sub);
396 /* ... wait until it is actually destroyed---sub-object clears its
397 * ->lo_sub[] slot in lovsub_object_fini() */
398 if (r0->lo_sub[idx] == los) {
399 waiter = &lov_env_info(env)->lti_waiter;
400 init_waitqueue_entry_current(waiter);
401 add_wait_queue(&bkt->lsb_marche_funebre, waiter);
402 set_current_state(TASK_UNINTERRUPTIBLE);
404 /* this wait-queue is signaled at the end of
405 * lu_object_free(). */
406 set_current_state(TASK_UNINTERRUPTIBLE);
407 spin_lock(&r0->lo_sub_lock);
408 if (r0->lo_sub[idx] == los) {
409 spin_unlock(&r0->lo_sub_lock);
410 waitq_wait(waiter, TASK_UNINTERRUPTIBLE);
412 spin_unlock(&r0->lo_sub_lock);
413 set_current_state(TASK_RUNNING);
417 remove_wait_queue(&bkt->lsb_marche_funebre, waiter);
419 LASSERT(r0->lo_sub[idx] == NULL);
422 static int lov_delete_raid0(const struct lu_env *env, struct lov_object *lov,
423 union lov_layout_state *state)
425 struct lov_layout_raid0 *r0 = &state->raid0;
426 struct lov_stripe_md *lsm = lov->lo_lsm;
431 dump_lsm(D_INODE, lsm);
433 lov_layout_wait(env, lov);
434 if (r0->lo_sub != NULL) {
435 for (i = 0; i < r0->lo_nr; ++i) {
436 struct lovsub_object *los = r0->lo_sub[i];
439 cl_object_prune(env, &los->lso_cl);
441 * If top-level object is to be evicted from
442 * the cache, so are its sub-objects.
444 lov_subobject_kill(env, lov, los, i);
451 static void lov_fini_empty(const struct lu_env *env, struct lov_object *lov,
452 union lov_layout_state *state)
454 LASSERT(lov->lo_type == LLT_EMPTY || lov->lo_type == LLT_RELEASED);
457 static void lov_fini_raid0(const struct lu_env *env, struct lov_object *lov,
458 union lov_layout_state *state)
460 struct lov_layout_raid0 *r0 = &state->raid0;
463 if (r0->lo_sub != NULL) {
464 OBD_FREE_LARGE(r0->lo_sub, r0->lo_nr * sizeof r0->lo_sub[0]);
468 dump_lsm(D_INODE, lov->lo_lsm);
469 lov_free_memmd(&lov->lo_lsm);
474 static void lov_fini_released(const struct lu_env *env, struct lov_object *lov,
475 union lov_layout_state *state)
478 dump_lsm(D_INODE, lov->lo_lsm);
479 lov_free_memmd(&lov->lo_lsm);
483 static int lov_print_empty(const struct lu_env *env, void *cookie,
484 lu_printer_t p, const struct lu_object *o)
486 (*p)(env, cookie, "empty %d\n", lu2lov(o)->lo_layout_invalid);
490 static int lov_print_raid0(const struct lu_env *env, void *cookie,
491 lu_printer_t p, const struct lu_object *o)
493 struct lov_object *lov = lu2lov(o);
494 struct lov_layout_raid0 *r0 = lov_r0(lov);
495 struct lov_stripe_md *lsm = lov->lo_lsm;
498 (*p)(env, cookie, "stripes: %d, %s, lsm{%p 0x%08X %d %u %u}:\n",
499 r0->lo_nr, lov->lo_layout_invalid ? "invalid" : "valid", lsm,
500 lsm->lsm_magic, atomic_read(&lsm->lsm_refc),
501 lsm->lsm_stripe_count, lsm->lsm_layout_gen);
502 for (i = 0; i < r0->lo_nr; ++i) {
503 struct lu_object *sub;
505 if (r0->lo_sub[i] != NULL) {
506 sub = lovsub2lu(r0->lo_sub[i]);
507 lu_object_print(env, cookie, p, sub);
509 (*p)(env, cookie, "sub %d absent\n", i);
515 static int lov_print_released(const struct lu_env *env, void *cookie,
516 lu_printer_t p, const struct lu_object *o)
518 struct lov_object *lov = lu2lov(o);
519 struct lov_stripe_md *lsm = lov->lo_lsm;
522 "released: %s, lsm{%p 0x%08X %d %u %u}:\n",
523 lov->lo_layout_invalid ? "invalid" : "valid", lsm,
524 lsm->lsm_magic, atomic_read(&lsm->lsm_refc),
525 lsm->lsm_stripe_count, lsm->lsm_layout_gen);
530 * Implements cl_object_operations::coo_attr_get() method for an object
531 * without stripes (LLT_EMPTY layout type).
533 * The only attributes this layer is authoritative in this case is
534 * cl_attr::cat_blocks---it's 0.
536 static int lov_attr_get_empty(const struct lu_env *env, struct cl_object *obj,
537 struct cl_attr *attr)
539 attr->cat_blocks = 0;
543 static int lov_attr_get_raid0(const struct lu_env *env, struct cl_object *obj,
544 struct cl_attr *attr)
546 struct lov_object *lov = cl2lov(obj);
547 struct lov_layout_raid0 *r0 = lov_r0(lov);
548 struct cl_attr *lov_attr = &r0->lo_attr;
553 /* this is called w/o holding type guard mutex, so it must be inside
554 * an on going IO otherwise lsm may be replaced.
555 * LU-2117: it turns out there exists one exception. For mmaped files,
556 * the lock of those files may be requested in the other file's IO
557 * context, and this function is called in ccc_lock_state(), it will
558 * hit this assertion.
559 * Anyway, it's still okay to call attr_get w/o type guard as layout
560 * can't go if locks exist. */
561 /* LASSERT(atomic_read(&lsm->lsm_refc) > 1); */
563 if (!r0->lo_attr_valid) {
564 struct lov_stripe_md *lsm = lov->lo_lsm;
565 struct ost_lvb *lvb = &lov_env_info(env)->lti_lvb;
568 memset(lvb, 0, sizeof(*lvb));
569 /* XXX: timestamps can be negative by sanity:test_39m,
571 lvb->lvb_atime = LLONG_MIN;
572 lvb->lvb_ctime = LLONG_MIN;
573 lvb->lvb_mtime = LLONG_MIN;
576 * XXX that should be replaced with a loop over sub-objects,
577 * doing cl_object_attr_get() on them. But for now, let's
578 * reuse old lov code.
582 * XXX take lsm spin-lock to keep lov_merge_lvb_kms()
583 * happy. It's not needed, because new code uses
584 * ->coh_attr_guard spin-lock to protect consistency of
585 * sub-object attributes.
587 lov_stripe_lock(lsm);
588 result = lov_merge_lvb_kms(lsm, lvb, &kms);
589 lov_stripe_unlock(lsm);
591 cl_lvb2attr(lov_attr, lvb);
592 lov_attr->cat_kms = kms;
593 r0->lo_attr_valid = 1;
596 if (result == 0) { /* merge results */
597 attr->cat_blocks = lov_attr->cat_blocks;
598 attr->cat_size = lov_attr->cat_size;
599 attr->cat_kms = lov_attr->cat_kms;
600 if (attr->cat_atime < lov_attr->cat_atime)
601 attr->cat_atime = lov_attr->cat_atime;
602 if (attr->cat_ctime < lov_attr->cat_ctime)
603 attr->cat_ctime = lov_attr->cat_ctime;
604 if (attr->cat_mtime < lov_attr->cat_mtime)
605 attr->cat_mtime = lov_attr->cat_mtime;
610 static int lov_find_cbdata_empty(const struct lu_env *env,
611 struct cl_object *obj, ldlm_iterator_t iter,
617 static int lov_find_cbdata_raid0(const struct lu_env *env,
618 struct cl_object *obj, ldlm_iterator_t iter,
621 struct lov_object *lov = cl2lov(obj);
622 struct lov_layout_raid0 *r0 = lov_r0(lov);
623 struct cl_object *subobj;
627 for (i = 0; i < r0->lo_nr; ++i) {
628 if (r0->lo_sub[i] == NULL)
631 subobj = lovsub2cl(r0->lo_sub[i]);
633 rc = cl_object_find_cbdata(env, subobj, iter, data);
641 const static struct lov_layout_operations lov_dispatch[] = {
643 .llo_init = lov_init_empty,
644 .llo_delete = lov_delete_empty,
645 .llo_fini = lov_fini_empty,
646 .llo_install = lov_install_empty,
647 .llo_print = lov_print_empty,
648 .llo_page_init = lov_page_init_empty,
649 .llo_lock_init = lov_lock_init_empty,
650 .llo_io_init = lov_io_init_empty,
651 .llo_getattr = lov_attr_get_empty,
652 .llo_find_cbdata = lov_find_cbdata_empty
655 .llo_init = lov_init_raid0,
656 .llo_delete = lov_delete_raid0,
657 .llo_fini = lov_fini_raid0,
658 .llo_install = lov_install_raid0,
659 .llo_print = lov_print_raid0,
660 .llo_page_init = lov_page_init_raid0,
661 .llo_lock_init = lov_lock_init_raid0,
662 .llo_io_init = lov_io_init_raid0,
663 .llo_getattr = lov_attr_get_raid0,
664 .llo_find_cbdata = lov_find_cbdata_raid0
667 .llo_init = lov_init_released,
668 .llo_delete = lov_delete_empty,
669 .llo_fini = lov_fini_released,
670 .llo_install = lov_install_empty,
671 .llo_print = lov_print_released,
672 .llo_page_init = lov_page_init_empty,
673 .llo_lock_init = lov_lock_init_empty,
674 .llo_io_init = lov_io_init_released,
675 .llo_getattr = lov_attr_get_empty,
676 .llo_find_cbdata = lov_find_cbdata_empty
681 * Performs a double-dispatch based on the layout type of an object.
683 #define LOV_2DISPATCH_NOLOCK(obj, op, ...) \
685 struct lov_object *__obj = (obj); \
686 enum lov_layout_type __llt; \
688 __llt = __obj->lo_type; \
689 LASSERT(0 <= __llt && __llt < ARRAY_SIZE(lov_dispatch)); \
690 lov_dispatch[__llt].op(__VA_ARGS__); \
694 * Return lov_layout_type associated with a given lsm
696 static enum lov_layout_type lov_type(struct lov_stripe_md *lsm)
700 if (lsm_is_released(lsm))
705 static inline void lov_conf_freeze(struct lov_object *lov)
707 if (lov->lo_owner != current)
708 down_read(&lov->lo_type_guard);
711 static inline void lov_conf_thaw(struct lov_object *lov)
713 if (lov->lo_owner != current)
714 up_read(&lov->lo_type_guard);
717 #define LOV_2DISPATCH_MAYLOCK(obj, op, lock, ...) \
719 struct lov_object *__obj = (obj); \
720 int __lock = !!(lock); \
721 typeof(lov_dispatch[0].op(__VA_ARGS__)) __result; \
724 lov_conf_freeze(__obj); \
725 __result = LOV_2DISPATCH_NOLOCK(obj, op, __VA_ARGS__); \
727 lov_conf_thaw(__obj); \
732 * Performs a locked double-dispatch based on the layout type of an object.
734 #define LOV_2DISPATCH(obj, op, ...) \
735 LOV_2DISPATCH_MAYLOCK(obj, op, 1, __VA_ARGS__)
737 #define LOV_2DISPATCH_VOID(obj, op, ...) \
739 struct lov_object *__obj = (obj); \
740 enum lov_layout_type __llt; \
742 lov_conf_freeze(__obj); \
743 __llt = __obj->lo_type; \
744 LASSERT(0 <= __llt && __llt < ARRAY_SIZE(lov_dispatch)); \
745 lov_dispatch[__llt].op(__VA_ARGS__); \
746 lov_conf_thaw(__obj); \
749 static void lov_conf_lock(struct lov_object *lov)
751 LASSERT(lov->lo_owner != current);
752 down_write(&lov->lo_type_guard);
753 LASSERT(lov->lo_owner == NULL);
754 lov->lo_owner = current;
757 static void lov_conf_unlock(struct lov_object *lov)
759 lov->lo_owner = NULL;
760 up_write(&lov->lo_type_guard);
763 static int lov_layout_wait(const struct lu_env *env, struct lov_object *lov)
765 struct l_wait_info lwi = { 0 };
768 while (atomic_read(&lov->lo_active_ios) > 0) {
769 CDEBUG(D_INODE, "file:"DFID" wait for active IO, now: %d.\n",
770 PFID(lu_object_fid(lov2lu(lov))),
771 atomic_read(&lov->lo_active_ios));
773 l_wait_event(lov->lo_waitq,
774 atomic_read(&lov->lo_active_ios) == 0, &lwi);
779 static int lov_layout_change(const struct lu_env *unused,
780 struct lov_object *lov,
781 const struct cl_object_conf *conf)
784 enum lov_layout_type llt = LLT_EMPTY;
785 union lov_layout_state *state = &lov->u;
786 const struct lov_layout_operations *old_ops;
787 const struct lov_layout_operations *new_ops;
794 LASSERT(0 <= lov->lo_type && lov->lo_type < ARRAY_SIZE(lov_dispatch));
796 if (conf->u.coc_md != NULL)
797 llt = lov_type(conf->u.coc_md->lsm);
798 LASSERT(0 <= llt && llt < ARRAY_SIZE(lov_dispatch));
800 cookie = cl_env_reenter();
801 env = cl_env_get(&refcheck);
803 cl_env_reexit(cookie);
804 RETURN(PTR_ERR(env));
807 CDEBUG(D_INODE, DFID" from %s to %s\n",
808 PFID(lu_object_fid(lov2lu(lov))),
809 llt2str(lov->lo_type), llt2str(llt));
811 old_ops = &lov_dispatch[lov->lo_type];
812 new_ops = &lov_dispatch[llt];
814 result = cl_object_prune(env, &lov->lo_cl);
818 result = old_ops->llo_delete(env, lov, &lov->u);
820 old_ops->llo_fini(env, lov, &lov->u);
822 LASSERT(atomic_read(&lov->lo_active_ios) == 0);
824 lov->lo_type = LLT_EMPTY;
825 /* page bufsize fixup */
826 cl_object_header(&lov->lo_cl)->coh_page_bufsize -=
827 lov_page_slice_fixup(lov, NULL);
829 result = new_ops->llo_init(env,
830 lu2lov_dev(lov->lo_cl.co_lu.lo_dev),
833 new_ops->llo_install(env, lov, state);
836 new_ops->llo_delete(env, lov, state);
837 new_ops->llo_fini(env, lov, state);
838 /* this file becomes an EMPTY file. */
843 cl_env_put(env, &refcheck);
844 cl_env_reexit(cookie);
848 /*****************************************************************************
850 * Lov object operations.
853 int lov_object_init(const struct lu_env *env, struct lu_object *obj,
854 const struct lu_object_conf *conf)
856 struct lov_device *dev = lu2lov_dev(obj->lo_dev);
857 struct lov_object *lov = lu2lov(obj);
858 const struct cl_object_conf *cconf = lu2cl_conf(conf);
859 union lov_layout_state *set = &lov->u;
860 const struct lov_layout_operations *ops;
864 init_rwsem(&lov->lo_type_guard);
865 atomic_set(&lov->lo_active_ios, 0);
866 init_waitqueue_head(&lov->lo_waitq);
868 cl_object_page_init(lu2cl(obj), sizeof(struct lov_page));
870 /* no locking is necessary, as object is being created */
871 lov->lo_type = lov_type(cconf->u.coc_md->lsm);
872 ops = &lov_dispatch[lov->lo_type];
873 result = ops->llo_init(env, dev, lov, cconf, set);
875 ops->llo_install(env, lov, set);
879 static int lov_conf_set(const struct lu_env *env, struct cl_object *obj,
880 const struct cl_object_conf *conf)
882 struct lov_stripe_md *lsm = NULL;
883 struct lov_object *lov = cl2lov(obj);
888 if (conf->coc_opc == OBJECT_CONF_INVALIDATE) {
889 lov->lo_layout_invalid = true;
890 GOTO(out, result = 0);
893 if (conf->coc_opc == OBJECT_CONF_WAIT) {
894 if (lov->lo_layout_invalid &&
895 atomic_read(&lov->lo_active_ios) > 0) {
896 lov_conf_unlock(lov);
897 result = lov_layout_wait(env, lov);
903 LASSERT(conf->coc_opc == OBJECT_CONF_SET);
905 if (conf->u.coc_md != NULL)
906 lsm = conf->u.coc_md->lsm;
907 if ((lsm == NULL && lov->lo_lsm == NULL) ||
908 ((lsm != NULL && lov->lo_lsm != NULL) &&
909 (lov->lo_lsm->lsm_layout_gen == lsm->lsm_layout_gen) &&
910 (lov->lo_lsm->lsm_pattern == lsm->lsm_pattern))) {
911 /* same version of layout */
912 lov->lo_layout_invalid = false;
913 GOTO(out, result = 0);
916 /* will change layout - check if there still exists active IO. */
917 if (atomic_read(&lov->lo_active_ios) > 0) {
918 lov->lo_layout_invalid = true;
919 GOTO(out, result = -EBUSY);
922 result = lov_layout_change(env, lov, conf);
923 lov->lo_layout_invalid = result != 0;
927 lov_conf_unlock(lov);
928 CDEBUG(D_INODE, DFID" lo_layout_invalid=%d\n",
929 PFID(lu_object_fid(lov2lu(lov))), lov->lo_layout_invalid);
933 static void lov_object_delete(const struct lu_env *env, struct lu_object *obj)
935 struct lov_object *lov = lu2lov(obj);
938 LOV_2DISPATCH_VOID(lov, llo_delete, env, lov, &lov->u);
942 static void lov_object_free(const struct lu_env *env, struct lu_object *obj)
944 struct lov_object *lov = lu2lov(obj);
947 LOV_2DISPATCH_VOID(lov, llo_fini, env, lov, &lov->u);
949 OBD_SLAB_FREE_PTR(lov, lov_object_kmem);
953 static int lov_object_print(const struct lu_env *env, void *cookie,
954 lu_printer_t p, const struct lu_object *o)
956 return LOV_2DISPATCH_NOLOCK(lu2lov(o), llo_print, env, cookie, p, o);
959 int lov_page_init(const struct lu_env *env, struct cl_object *obj,
960 struct cl_page *page, pgoff_t index)
962 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_page_init, env, obj, page,
967 * Implements cl_object_operations::clo_io_init() method for lov
968 * layer. Dispatches to the appropriate layout io initialization method.
970 int lov_io_init(const struct lu_env *env, struct cl_object *obj,
973 CL_IO_SLICE_CLEAN(lov_env_io(env), lis_cl);
974 return LOV_2DISPATCH_MAYLOCK(cl2lov(obj), llo_io_init,
975 !io->ci_ignore_layout, env, obj, io);
979 * An implementation of cl_object_operations::clo_attr_get() method for lov
980 * layer. For raid0 layout this collects and merges attributes of all
983 static int lov_attr_get(const struct lu_env *env, struct cl_object *obj,
984 struct cl_attr *attr)
986 /* do not take lock, as this function is called under a
987 * spin-lock. Layout is protected from changing by ongoing IO. */
988 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_getattr, env, obj, attr);
991 static int lov_attr_update(const struct lu_env *env, struct cl_object *obj,
992 const struct cl_attr *attr, unsigned valid)
995 * No dispatch is required here, as no layout implements this.
1000 int lov_lock_init(const struct lu_env *env, struct cl_object *obj,
1001 struct cl_lock *lock, const struct cl_io *io)
1003 /* No need to lock because we've taken one refcount of layout. */
1004 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_lock_init, env, obj, lock,
1009 * We calculate on which OST the mapping will end. If the length of mapping
1010 * is greater than (stripe_size * stripe_count) then the last_stripe will
1011 * will be one just before start_stripe. Else we check if the mapping
1012 * intersects each OST and find last_stripe.
1013 * This function returns the last_stripe and also sets the stripe_count
1014 * over which the mapping is spread
1016 * \param lsm [in] striping information for the file
1017 * \param fm_start [in] logical start of mapping
1018 * \param fm_end [in] logical end of mapping
1019 * \param start_stripe [in] starting stripe of the mapping
1020 * \param stripe_count [out] the number of stripes across which to map is
1023 * \retval last_stripe return the last stripe of the mapping
1025 static int fiemap_calc_last_stripe(struct lov_stripe_md *lsm,
1026 loff_t fm_start, loff_t fm_end,
1027 int start_stripe, int *stripe_count)
1034 if (fm_end - fm_start > lsm->lsm_stripe_size * lsm->lsm_stripe_count) {
1035 last_stripe = (start_stripe < 1 ? lsm->lsm_stripe_count - 1 :
1037 *stripe_count = lsm->lsm_stripe_count;
1039 for (j = 0, i = start_stripe; j < lsm->lsm_stripe_count;
1040 i = (i + 1) % lsm->lsm_stripe_count, j++) {
1041 if ((lov_stripe_intersects(lsm, i, fm_start, fm_end,
1042 &obd_start, &obd_end)) == 0)
1046 last_stripe = (start_stripe + j - 1) % lsm->lsm_stripe_count;
1053 * Set fe_device and copy extents from local buffer into main return buffer.
1055 * \param fiemap [out] fiemap to hold all extents
1056 * \param lcl_fm_ext [in] array of fiemap extents get from OSC layer
1057 * \param ost_index [in] OST index to be written into the fm_device
1058 * field for each extent
1059 * \param ext_count [in] number of extents to be copied
1060 * \param current_extent [in] where to start copying in the extent array
1062 static void fiemap_prepare_and_copy_exts(struct fiemap *fiemap,
1063 struct ll_fiemap_extent *lcl_fm_ext,
1064 int ost_index, unsigned int ext_count,
1070 for (ext = 0; ext < ext_count; ext++) {
1071 lcl_fm_ext[ext].fe_device = ost_index;
1072 lcl_fm_ext[ext].fe_flags |= FIEMAP_EXTENT_NET;
1075 /* Copy fm_extent's from fm_local to return buffer */
1076 to = (char *)fiemap + fiemap_count_to_size(current_extent);
1077 memcpy(to, lcl_fm_ext, ext_count * sizeof(struct ll_fiemap_extent));
1080 #define FIEMAP_BUFFER_SIZE 4096
1083 * Non-zero fe_logical indicates that this is a continuation FIEMAP
1084 * call. The local end offset and the device are sent in the first
1085 * fm_extent. This function calculates the stripe number from the index.
1086 * This function returns a stripe_no on which mapping is to be restarted.
1088 * This function returns fm_end_offset which is the in-OST offset at which
1089 * mapping should be restarted. If fm_end_offset=0 is returned then caller
1090 * will re-calculate proper offset in next stripe.
1091 * Note that the first extent is passed to lov_get_info via the value field.
1093 * \param fiemap [in] fiemap request header
1094 * \param lsm [in] striping information for the file
1095 * \param fm_start [in] logical start of mapping
1096 * \param fm_end [in] logical end of mapping
1097 * \param start_stripe [out] starting stripe will be returned in this
1099 static loff_t fiemap_calc_fm_end_offset(struct fiemap *fiemap,
1100 struct lov_stripe_md *lsm,
1101 loff_t fm_start, loff_t fm_end,
1104 loff_t local_end = fiemap->fm_extents[0].fe_logical;
1107 loff_t fm_end_offset;
1111 if (fiemap->fm_extent_count == 0 ||
1112 fiemap->fm_extents[0].fe_logical == 0)
1115 /* Find out stripe_no from ost_index saved in the fe_device */
1116 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1117 struct lov_oinfo *oinfo = lsm->lsm_oinfo[i];
1119 if (lov_oinfo_is_dummy(oinfo))
1122 if (oinfo->loi_ost_idx == fiemap->fm_extents[0].fe_device) {
1128 if (stripe_no == -1)
1131 /* If we have finished mapping on previous device, shift logical
1132 * offset to start of next device */
1133 if (lov_stripe_intersects(lsm, stripe_no, fm_start, fm_end,
1134 &lun_start, &lun_end) != 0 &&
1135 local_end < lun_end) {
1136 fm_end_offset = local_end;
1137 *start_stripe = stripe_no;
1139 /* This is a special value to indicate that caller should
1140 * calculate offset in next stripe. */
1142 *start_stripe = (stripe_no + 1) % lsm->lsm_stripe_count;
1145 return fm_end_offset;
1149 * Break down the FIEMAP request and send appropriate calls to individual OSTs.
1150 * This also handles the restarting of FIEMAP calls in case mapping overflows
1151 * the available number of extents in single call.
1153 * \param env [in] lustre environment
1154 * \param obj [in] file object
1155 * \param fmkey [in] fiemap request header and other info
1156 * \param fiemap [out] fiemap buffer holding retrived map extents
1157 * \param buflen [in/out] max buffer length of @fiemap, when iterate
1158 * each OST, it is used to limit max map needed
1162 static int lov_object_fiemap(const struct lu_env *env, struct cl_object *obj,
1163 struct ll_fiemap_info_key *fmkey,
1164 struct fiemap *fiemap, size_t *buflen)
1166 struct lov_stripe_md *lsm;
1167 struct cl_object *subobj = NULL;
1168 struct lov_obd *lov = lu2lov_dev(obj->co_lu.lo_dev)->ld_lov;
1169 struct fiemap *fm_local = NULL;
1170 struct ll_fiemap_extent *lcl_fm_ext;
1174 loff_t fm_end_offset;
1178 int current_extent = 0;
1182 int cur_stripe_wrap = 0;
1184 unsigned int buffer_size = FIEMAP_BUFFER_SIZE;
1185 /* Whether have we collected enough extents */
1186 bool enough = false;
1187 /* EOF for object */
1188 bool ost_eof = false;
1189 /* done with required mapping for this OST? */
1190 bool ost_done = false;
1193 lsm = lov_lsm_addref(cl2lov(obj));
1198 * If the stripe_count > 1 and the application does not understand
1199 * DEVICE_ORDER flag, it cannot interpret the extents correctly.
1201 if (lsm->lsm_stripe_count > 1 && !(fiemap->fm_flags &
1202 FIEMAP_FLAG_DEVICE_ORDER))
1203 GOTO(out, rc = -ENOTSUPP);
1205 if (lsm_is_released(lsm)) {
1206 if (fiemap->fm_start < fmkey->oa.o_size) {
1208 * released file, return a minimal FIEMAP if
1209 * request fits in file-size.
1211 fiemap->fm_mapped_extents = 1;
1212 fiemap->fm_extents[0].fe_logical = fiemap->fm_start;
1213 if (fiemap->fm_start + fiemap->fm_length <
1215 fiemap->fm_extents[0].fe_length =
1218 fiemap->fm_extents[0].fe_length =
1219 fmkey->oa.o_size - fiemap->fm_start;
1220 fiemap->fm_extents[0].fe_flags |=
1221 FIEMAP_EXTENT_UNKNOWN | FIEMAP_EXTENT_LAST;
1226 if (fiemap_count_to_size(fiemap->fm_extent_count) < buffer_size)
1227 buffer_size = fiemap_count_to_size(fiemap->fm_extent_count);
1229 OBD_ALLOC_LARGE(fm_local, buffer_size);
1230 if (fm_local == NULL)
1231 GOTO(out, rc = -ENOMEM);
1232 lcl_fm_ext = &fm_local->fm_extents[0];
1233 count_local = fiemap_size_to_count(buffer_size);
1235 fm_start = fiemap->fm_start;
1236 fm_length = fiemap->fm_length;
1237 /* Calculate start stripe, last stripe and length of mapping */
1238 start_stripe = lov_stripe_number(lsm, fm_start);
1239 fm_end = (fm_length == ~0ULL) ? fmkey->oa.o_size :
1240 fm_start + fm_length - 1;
1241 /* If fm_length != ~0ULL but fm_start_fm_length-1 exceeds file size */
1242 if (fm_end > fmkey->oa.o_size)
1243 fm_end = fmkey->oa.o_size;
1245 last_stripe = fiemap_calc_last_stripe(lsm, fm_start, fm_end,
1246 start_stripe, &stripe_count);
1247 fm_end_offset = fiemap_calc_fm_end_offset(fiemap, lsm, fm_start, fm_end,
1249 if (fm_end_offset == -EINVAL)
1250 GOTO(out, rc = -EINVAL);
1253 * Requested extent count exceeds the fiemap buffer size, shrink our
1256 if (fiemap_count_to_size(fiemap->fm_extent_count) > *buflen)
1257 fiemap->fm_extent_count = fiemap_size_to_count(*buflen);
1258 if (fiemap->fm_extent_count == 0)
1261 /* Check each stripe */
1262 for (cur_stripe = start_stripe; stripe_count > 0;
1264 cur_stripe = (cur_stripe + 1) % lsm->lsm_stripe_count) {
1265 loff_t req_fm_len; /* Stores length of required mapping */
1266 loff_t len_mapped_single_call;
1269 loff_t obd_object_end;
1270 unsigned int ext_count;
1272 cur_stripe_wrap = cur_stripe;
1274 /* Find out range of mapping on this stripe */
1275 if ((lov_stripe_intersects(lsm, cur_stripe, fm_start, fm_end,
1276 &lun_start, &obd_object_end)) == 0)
1279 if (lov_oinfo_is_dummy(lsm->lsm_oinfo[cur_stripe]))
1280 GOTO(out, rc = -EIO);
1282 /* If this is a continuation FIEMAP call and we are on
1283 * starting stripe then lun_start needs to be set to
1285 if (fm_end_offset != 0 && cur_stripe == start_stripe)
1286 lun_start = fm_end_offset;
1288 if (fm_length != ~0ULL) {
1289 /* Handle fm_start + fm_length overflow */
1290 if (fm_start + fm_length < fm_start)
1291 fm_length = ~0ULL - fm_start;
1292 lun_end = lov_size_to_stripe(lsm, fm_start + fm_length,
1298 if (lun_start == lun_end)
1301 req_fm_len = obd_object_end - lun_start;
1302 fm_local->fm_length = 0;
1303 len_mapped_single_call = 0;
1305 /* find lobsub object */
1306 subobj = lov_find_subobj(env, cl2lov(obj), lsm,
1309 GOTO(out, rc = PTR_ERR(subobj));
1310 /* If the output buffer is very large and the objects have many
1311 * extents we may need to loop on a single OST repeatedly */
1315 if (fiemap->fm_extent_count > 0) {
1316 /* Don't get too many extents. */
1317 if (current_extent + count_local >
1318 fiemap->fm_extent_count)
1319 count_local = fiemap->fm_extent_count -
1323 lun_start += len_mapped_single_call;
1324 fm_local->fm_length = req_fm_len -
1325 len_mapped_single_call;
1326 req_fm_len = fm_local->fm_length;
1327 fm_local->fm_extent_count = enough ? 1 : count_local;
1328 fm_local->fm_mapped_extents = 0;
1329 fm_local->fm_flags = fiemap->fm_flags;
1331 ost_index = lsm->lsm_oinfo[cur_stripe]->loi_ost_idx;
1333 if (ost_index < 0 ||
1334 ost_index >= lov->desc.ld_tgt_count)
1335 GOTO(obj_put, rc = -EINVAL);
1336 /* If OST is inactive, return extent with UNKNOWN
1338 if (!lov->lov_tgts[ost_index]->ltd_active) {
1339 fm_local->fm_flags |= FIEMAP_EXTENT_LAST;
1340 fm_local->fm_mapped_extents = 1;
1342 lcl_fm_ext[0].fe_logical = lun_start;
1343 lcl_fm_ext[0].fe_length = obd_object_end -
1345 lcl_fm_ext[0].fe_flags |= FIEMAP_EXTENT_UNKNOWN;
1350 fm_local->fm_start = lun_start;
1351 fm_local->fm_flags &= ~FIEMAP_FLAG_DEVICE_ORDER;
1352 memcpy(&fmkey->fiemap, fm_local, sizeof(*fm_local));
1353 *buflen = fiemap_count_to_size(
1354 fm_local->fm_extent_count);
1356 rc = cl_object_fiemap(env, subobj, fmkey, fm_local,
1361 ext_count = fm_local->fm_mapped_extents;
1362 if (ext_count == 0) {
1364 /* If last stripe has hold at the end,
1365 * we need to return */
1366 if (cur_stripe_wrap == last_stripe) {
1367 fiemap->fm_mapped_extents = 0;
1371 } else if (enough) {
1373 * We've collected enough extents and there are
1374 * more extents after it.
1379 /* If we just need num of extents, got to next device */
1380 if (fiemap->fm_extent_count == 0) {
1381 current_extent += ext_count;
1385 /* prepare to copy retrived map extents */
1386 len_mapped_single_call =
1387 lcl_fm_ext[ext_count - 1].fe_logical -
1388 lun_start + lcl_fm_ext[ext_count - 1].fe_length;
1390 /* Have we finished mapping on this device? */
1391 if (req_fm_len <= len_mapped_single_call)
1394 /* Clear the EXTENT_LAST flag which can be present on
1395 * the last extent */
1396 if (lcl_fm_ext[ext_count - 1].fe_flags &
1398 lcl_fm_ext[ext_count - 1].fe_flags &=
1399 ~FIEMAP_EXTENT_LAST;
1400 if (lov_stripe_size(lsm,
1401 lcl_fm_ext[ext_count - 1].fe_logical +
1402 lcl_fm_ext[ext_count - 1].fe_length,
1403 cur_stripe) >= fmkey->oa.o_size)
1406 fiemap_prepare_and_copy_exts(fiemap, lcl_fm_ext,
1407 ost_index, ext_count,
1409 current_extent += ext_count;
1411 /* Ran out of available extents? */
1412 if (current_extent >= fiemap->fm_extent_count)
1414 } while (!ost_done && !ost_eof);
1416 cl_object_put(env, subobj);
1419 if (cur_stripe_wrap == last_stripe)
1421 } /* for each stripe */
1423 /* Indicate that we are returning device offsets unless file just has
1425 if (lsm->lsm_stripe_count > 1)
1426 fiemap->fm_flags |= FIEMAP_FLAG_DEVICE_ORDER;
1428 if (fiemap->fm_extent_count == 0)
1429 goto skip_last_device_calc;
1431 /* Check if we have reached the last stripe and whether mapping for that
1432 * stripe is done. */
1433 if ((cur_stripe_wrap == last_stripe) && (ost_done || ost_eof))
1434 fiemap->fm_extents[current_extent - 1].fe_flags |=
1436 skip_last_device_calc:
1437 fiemap->fm_mapped_extents = current_extent;
1440 cl_object_put(env, subobj);
1442 if (fm_local != NULL)
1443 OBD_FREE_LARGE(fm_local, buffer_size);
1444 lov_lsm_put(obj, lsm);
1448 static int lov_object_getstripe(const struct lu_env *env, struct cl_object *obj,
1449 struct lov_user_md __user *lum)
1451 struct lov_object *lov = cl2lov(obj);
1452 struct lov_stripe_md *lsm;
1456 lsm = lov_lsm_addref(lov);
1460 rc = lov_getstripe(cl2lov(obj), lsm, lum);
1461 lov_lsm_put(obj, lsm);
1465 static int lov_object_find_cbdata(const struct lu_env *env,
1466 struct cl_object *obj, ldlm_iterator_t iter,
1472 /* call cl_object_find_cbdata for sub obj */
1473 rc = LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_find_cbdata,
1474 env, obj, iter, data);
1478 static const struct cl_object_operations lov_ops = {
1479 .coo_page_init = lov_page_init,
1480 .coo_lock_init = lov_lock_init,
1481 .coo_io_init = lov_io_init,
1482 .coo_attr_get = lov_attr_get,
1483 .coo_attr_update = lov_attr_update,
1484 .coo_conf_set = lov_conf_set,
1485 .coo_getstripe = lov_object_getstripe,
1486 .coo_find_cbdata = lov_object_find_cbdata,
1487 .coo_fiemap = lov_object_fiemap,
1490 static const struct lu_object_operations lov_lu_obj_ops = {
1491 .loo_object_init = lov_object_init,
1492 .loo_object_delete = lov_object_delete,
1493 .loo_object_release = NULL,
1494 .loo_object_free = lov_object_free,
1495 .loo_object_print = lov_object_print,
1496 .loo_object_invariant = NULL
1499 struct lu_object *lov_object_alloc(const struct lu_env *env,
1500 const struct lu_object_header *unused,
1501 struct lu_device *dev)
1503 struct lov_object *lov;
1504 struct lu_object *obj;
1507 OBD_SLAB_ALLOC_PTR_GFP(lov, lov_object_kmem, GFP_NOFS);
1510 lu_object_init(obj, NULL, dev);
1511 lov->lo_cl.co_ops = &lov_ops;
1512 lov->lo_type = -1; /* invalid, to catch uninitialized type */
1514 * object io operation vector (cl_object::co_iop) is installed
1515 * later in lov_object_init(), as different vectors are used
1516 * for object with different layouts.
1518 obj->lo_ops = &lov_lu_obj_ops;
1524 struct lov_stripe_md *lov_lsm_addref(struct lov_object *lov)
1526 struct lov_stripe_md *lsm = NULL;
1528 lov_conf_freeze(lov);
1529 if (lov->lo_lsm != NULL) {
1530 lsm = lsm_addref(lov->lo_lsm);
1531 CDEBUG(D_INODE, "lsm %p addref %d/%d by %p.\n",
1532 lsm, atomic_read(&lsm->lsm_refc),
1533 lov->lo_layout_invalid, current);
1539 int lov_read_and_clear_async_rc(struct cl_object *clob)
1541 struct lu_object *luobj;
1545 luobj = lu_object_locate(&cl_object_header(clob)->coh_lu,
1547 if (luobj != NULL) {
1548 struct lov_object *lov = lu2lov(luobj);
1550 lov_conf_freeze(lov);
1551 switch (lov->lo_type) {
1553 struct lov_stripe_md *lsm;
1557 LASSERT(lsm != NULL);
1558 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1559 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
1561 if (lov_oinfo_is_dummy(loi))
1564 if (loi->loi_ar.ar_rc && !rc)
1565 rc = loi->loi_ar.ar_rc;
1566 loi->loi_ar.ar_rc = 0;
1579 EXPORT_SYMBOL(lov_read_and_clear_async_rc);