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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * Implementation of cl_object for LOV layer.
34 * Author: Nikita Danilov <nikita.danilov@sun.com>
35 * Author: Jinshan Xiong <jinshan.xiong@whamcloud.com>
38 #define DEBUG_SUBSYSTEM S_LOV
40 #include "lov_cl_internal.h"
42 static inline struct lov_device *lov_object_dev(struct lov_object *obj)
44 return lu2lov_dev(obj->lo_cl.co_lu.lo_dev);
51 /*****************************************************************************
57 struct lov_layout_operations {
58 int (*llo_init)(const struct lu_env *env, struct lov_device *dev,
59 struct lov_object *lov, struct lov_stripe_md *lsm,
60 const struct cl_object_conf *conf,
61 union lov_layout_state *state);
62 int (*llo_delete)(const struct lu_env *env, struct lov_object *lov,
63 union lov_layout_state *state);
64 void (*llo_fini)(const struct lu_env *env, struct lov_object *lov,
65 union lov_layout_state *state);
66 void (*llo_install)(const struct lu_env *env, struct lov_object *lov,
67 union lov_layout_state *state);
68 int (*llo_print)(const struct lu_env *env, void *cookie,
69 lu_printer_t p, const struct lu_object *o);
70 int (*llo_page_init)(const struct lu_env *env, struct cl_object *obj,
71 struct cl_page *page, pgoff_t index);
72 int (*llo_lock_init)(const struct lu_env *env,
73 struct cl_object *obj, struct cl_lock *lock,
74 const struct cl_io *io);
75 int (*llo_io_init)(const struct lu_env *env,
76 struct cl_object *obj, struct cl_io *io);
77 int (*llo_getattr)(const struct lu_env *env, struct cl_object *obj,
78 struct cl_attr *attr);
81 static int lov_layout_wait(const struct lu_env *env, struct lov_object *lov);
83 static void lov_lsm_put(struct lov_stripe_md *lsm)
89 /*****************************************************************************
91 * Lov object layout operations.
95 static void lov_install_empty(const struct lu_env *env,
96 struct lov_object *lov,
97 union lov_layout_state *state)
100 * File without objects.
104 static int lov_init_empty(const struct lu_env *env, struct lov_device *dev,
105 struct lov_object *lov, struct lov_stripe_md *lsm,
106 const struct cl_object_conf *conf,
107 union lov_layout_state *state)
112 static void lov_install_raid0(const struct lu_env *env,
113 struct lov_object *lov,
114 union lov_layout_state *state)
118 static struct cl_object *lov_sub_find(const struct lu_env *env,
119 struct cl_device *dev,
120 const struct lu_fid *fid,
121 const struct cl_object_conf *conf)
125 o = lu_object_find_at(env, cl2lu_dev(dev), fid, &conf->coc_lu);
126 LASSERT(ergo(!IS_ERR(o), o->lo_dev->ld_type == &lovsub_device_type));
130 static int lov_init_sub(const struct lu_env *env, struct lov_object *lov,
131 struct cl_object *stripe, struct lov_layout_raid0 *r0,
134 struct cl_object_header *hdr;
135 struct cl_object_header *subhdr;
136 struct cl_object_header *parent;
137 struct lov_oinfo *oinfo;
140 if (OBD_FAIL_CHECK(OBD_FAIL_LOV_INIT)) {
141 /* For sanity:test_206.
142 * Do not leave the object in cache to avoid accessing
143 * freed memory. This is because osc_object is referring to
144 * lov_oinfo of lsm_stripe_data which will be freed due to
147 cl_object_kill(env, stripe);
148 cl_object_put(env, stripe);
152 hdr = cl_object_header(lov2cl(lov));
153 subhdr = cl_object_header(stripe);
155 oinfo = lov->lo_lsm->lsm_oinfo[idx];
156 CDEBUG(D_INODE, DFID "@%p[%d] -> " DFID "@%p: ostid: " DOSTID " idx: %d gen: %d\n",
157 PFID(&subhdr->coh_lu.loh_fid), subhdr, idx,
158 PFID(&hdr->coh_lu.loh_fid), hdr, POSTID(&oinfo->loi_oi),
159 oinfo->loi_ost_idx, oinfo->loi_ost_gen);
161 /* reuse ->coh_attr_guard to protect coh_parent change */
162 spin_lock(&subhdr->coh_attr_guard);
163 parent = subhdr->coh_parent;
165 subhdr->coh_parent = hdr;
166 spin_unlock(&subhdr->coh_attr_guard);
167 subhdr->coh_nesting = hdr->coh_nesting + 1;
168 lu_object_ref_add(&stripe->co_lu, "lov-parent", lov);
169 r0->lo_sub[idx] = cl2lovsub(stripe);
170 r0->lo_sub[idx]->lso_super = lov;
171 r0->lo_sub[idx]->lso_index = idx;
174 struct lu_object *old_obj;
175 struct lov_object *old_lov;
176 unsigned int mask = D_INODE;
178 spin_unlock(&subhdr->coh_attr_guard);
179 old_obj = lu_object_locate(&parent->coh_lu, &lov_device_type);
181 old_lov = cl2lov(lu2cl(old_obj));
182 if (old_lov->lo_layout_invalid) {
183 /* the object's layout has already changed but isn't
186 lu_object_unhash(env, &stripe->co_lu);
193 LU_OBJECT_DEBUG(mask, env, &stripe->co_lu,
194 "stripe %d is already owned.", idx);
195 LU_OBJECT_DEBUG(mask, env, old_obj, "owned.");
196 LU_OBJECT_HEADER(mask, env, lov2lu(lov), "try to own.\n");
197 cl_object_put(env, stripe);
202 static int lov_page_slice_fixup(struct lov_object *lov,
203 struct cl_object *stripe)
205 struct cl_object_header *hdr = cl_object_header(&lov->lo_cl);
209 return hdr->coh_page_bufsize - lov->lo_cl.co_slice_off -
210 cfs_size_round(sizeof(struct lov_page));
212 cl_object_for_each(o, stripe)
213 o->co_slice_off += hdr->coh_page_bufsize;
215 return cl_object_header(stripe)->coh_page_bufsize;
218 static int lov_init_raid0(const struct lu_env *env, struct lov_device *dev,
219 struct lov_object *lov, struct lov_stripe_md *lsm,
220 const struct cl_object_conf *conf,
221 union lov_layout_state *state)
226 struct cl_object *stripe;
227 struct lov_thread_info *lti = lov_env_info(env);
228 struct cl_object_conf *subconf = <i->lti_stripe_conf;
229 struct lu_fid *ofid = <i->lti_fid;
230 struct lov_layout_raid0 *r0 = &state->raid0;
232 if (lsm->lsm_magic != LOV_MAGIC_V1 && lsm->lsm_magic != LOV_MAGIC_V3) {
233 dump_lsm(D_ERROR, lsm);
234 LASSERTF(0, "magic mismatch, expected %d/%d, actual %d.\n",
235 LOV_MAGIC_V1, LOV_MAGIC_V3, lsm->lsm_magic);
238 LASSERT(!lov->lo_lsm);
239 lov->lo_lsm = lsm_addref(lsm);
240 lov->lo_layout_invalid = true;
241 r0->lo_nr = lsm->lsm_stripe_count;
242 LASSERT(r0->lo_nr <= lov_targets_nr(dev));
244 r0->lo_sub = libcfs_kvzalloc(r0->lo_nr * sizeof(r0->lo_sub[0]),
250 subconf->coc_inode = conf->coc_inode;
251 spin_lock_init(&r0->lo_sub_lock);
253 * Create stripe cl_objects.
255 for (i = 0; i < r0->lo_nr && result == 0; ++i) {
256 struct cl_device *subdev;
257 struct lov_oinfo *oinfo = lsm->lsm_oinfo[i];
258 int ost_idx = oinfo->loi_ost_idx;
260 if (lov_oinfo_is_dummy(oinfo))
263 result = ostid_to_fid(ofid, &oinfo->loi_oi,
268 if (!dev->ld_target[ost_idx]) {
269 CERROR("%s: OST %04x is not initialized\n",
270 lov2obd(dev->ld_lov)->obd_name, ost_idx);
275 subdev = lovsub2cl_dev(dev->ld_target[ost_idx]);
276 subconf->u.coc_oinfo = oinfo;
277 LASSERTF(subdev, "not init ost %d\n", ost_idx);
278 /* In the function below, .hs_keycmp resolves to
279 * lu_obj_hop_keycmp()
281 /* coverity[overrun-buffer-val] */
282 stripe = lov_sub_find(env, subdev, ofid, subconf);
283 if (!IS_ERR(stripe)) {
284 result = lov_init_sub(env, lov, stripe, r0, i);
285 if (result == -EAGAIN) { /* try again */
291 result = PTR_ERR(stripe);
295 int sz = lov_page_slice_fixup(lov, stripe);
297 LASSERT(ergo(psz > 0, psz == sz));
302 cl_object_header(&lov->lo_cl)->coh_page_bufsize += psz;
310 static int lov_init_released(const struct lu_env *env, struct lov_device *dev,
311 struct lov_object *lov, struct lov_stripe_md *lsm,
312 const struct cl_object_conf *conf,
313 union lov_layout_state *state)
316 LASSERT(lsm_is_released(lsm));
317 LASSERT(!lov->lo_lsm);
319 lov->lo_lsm = lsm_addref(lsm);
323 static struct cl_object *lov_find_subobj(const struct lu_env *env,
324 struct lov_object *lov,
325 struct lov_stripe_md *lsm,
328 struct lov_device *dev = lu2lov_dev(lov2lu(lov)->lo_dev);
329 struct lov_oinfo *oinfo = lsm->lsm_oinfo[stripe_idx];
330 struct lov_thread_info *lti = lov_env_info(env);
331 struct lu_fid *ofid = <i->lti_fid;
332 struct cl_device *subdev;
333 struct cl_object *result;
337 if (lov->lo_type != LLT_RAID0) {
342 ost_idx = oinfo->loi_ost_idx;
343 rc = ostid_to_fid(ofid, &oinfo->loi_oi, ost_idx);
349 subdev = lovsub2cl_dev(dev->ld_target[ost_idx]);
350 result = lov_sub_find(env, subdev, ofid, NULL);
353 result = ERR_PTR(-EINVAL);
357 static int lov_delete_empty(const struct lu_env *env, struct lov_object *lov,
358 union lov_layout_state *state)
360 LASSERT(lov->lo_type == LLT_EMPTY || lov->lo_type == LLT_RELEASED);
362 lov_layout_wait(env, lov);
366 static void lov_subobject_kill(const struct lu_env *env, struct lov_object *lov,
367 struct lovsub_object *los, int idx)
369 struct cl_object *sub;
370 struct lov_layout_raid0 *r0;
371 struct lu_site *site;
372 struct lu_site_bkt_data *bkt;
373 wait_queue_entry_t *waiter;
376 LASSERT(r0->lo_sub[idx] == los);
378 sub = lovsub2cl(los);
379 site = sub->co_lu.lo_dev->ld_site;
380 bkt = lu_site_bkt_from_fid(site, &sub->co_lu.lo_header->loh_fid);
382 cl_object_kill(env, sub);
383 /* release a reference to the sub-object and ... */
384 lu_object_ref_del(&sub->co_lu, "lov-parent", lov);
385 cl_object_put(env, sub);
387 /* ... wait until it is actually destroyed---sub-object clears its
388 * ->lo_sub[] slot in lovsub_object_fini()
390 if (r0->lo_sub[idx] == los) {
391 waiter = &lov_env_info(env)->lti_waiter;
392 init_waitqueue_entry(waiter, current);
393 add_wait_queue(&bkt->lsb_marche_funebre, waiter);
394 set_current_state(TASK_UNINTERRUPTIBLE);
396 /* this wait-queue is signaled at the end of
399 set_current_state(TASK_UNINTERRUPTIBLE);
400 spin_lock(&r0->lo_sub_lock);
401 if (r0->lo_sub[idx] == los) {
402 spin_unlock(&r0->lo_sub_lock);
405 spin_unlock(&r0->lo_sub_lock);
406 set_current_state(TASK_RUNNING);
410 remove_wait_queue(&bkt->lsb_marche_funebre, waiter);
412 LASSERT(!r0->lo_sub[idx]);
415 static int lov_delete_raid0(const struct lu_env *env, struct lov_object *lov,
416 union lov_layout_state *state)
418 struct lov_layout_raid0 *r0 = &state->raid0;
419 struct lov_stripe_md *lsm = lov->lo_lsm;
422 dump_lsm(D_INODE, lsm);
424 lov_layout_wait(env, lov);
426 for (i = 0; i < r0->lo_nr; ++i) {
427 struct lovsub_object *los = r0->lo_sub[i];
430 cl_object_prune(env, &los->lso_cl);
432 * If top-level object is to be evicted from
433 * the cache, so are its sub-objects.
435 lov_subobject_kill(env, lov, los, i);
442 static void lov_fini_empty(const struct lu_env *env, struct lov_object *lov,
443 union lov_layout_state *state)
445 LASSERT(lov->lo_type == LLT_EMPTY || lov->lo_type == LLT_RELEASED);
448 static void lov_fini_raid0(const struct lu_env *env, struct lov_object *lov,
449 union lov_layout_state *state)
451 struct lov_layout_raid0 *r0 = &state->raid0;
458 dump_lsm(D_INODE, lov->lo_lsm);
459 lov_free_memmd(&lov->lo_lsm);
462 static void lov_fini_released(const struct lu_env *env, struct lov_object *lov,
463 union lov_layout_state *state)
465 dump_lsm(D_INODE, lov->lo_lsm);
466 lov_free_memmd(&lov->lo_lsm);
469 static int lov_print_empty(const struct lu_env *env, void *cookie,
470 lu_printer_t p, const struct lu_object *o)
472 (*p)(env, cookie, "empty %d\n", lu2lov(o)->lo_layout_invalid);
476 static int lov_print_raid0(const struct lu_env *env, void *cookie,
477 lu_printer_t p, const struct lu_object *o)
479 struct lov_object *lov = lu2lov(o);
480 struct lov_layout_raid0 *r0 = lov_r0(lov);
481 struct lov_stripe_md *lsm = lov->lo_lsm;
484 (*p)(env, cookie, "stripes: %d, %s, lsm{%p 0x%08X %d %u %u}:\n",
485 r0->lo_nr, lov->lo_layout_invalid ? "invalid" : "valid", lsm,
486 lsm->lsm_magic, atomic_read(&lsm->lsm_refc),
487 lsm->lsm_stripe_count, lsm->lsm_layout_gen);
488 for (i = 0; i < r0->lo_nr; ++i) {
489 struct lu_object *sub;
492 sub = lovsub2lu(r0->lo_sub[i]);
493 lu_object_print(env, cookie, p, sub);
495 (*p)(env, cookie, "sub %d absent\n", i);
501 static int lov_print_released(const struct lu_env *env, void *cookie,
502 lu_printer_t p, const struct lu_object *o)
504 struct lov_object *lov = lu2lov(o);
505 struct lov_stripe_md *lsm = lov->lo_lsm;
508 "released: %s, lsm{%p 0x%08X %d %u %u}:\n",
509 lov->lo_layout_invalid ? "invalid" : "valid", lsm,
510 lsm->lsm_magic, atomic_read(&lsm->lsm_refc),
511 lsm->lsm_stripe_count, lsm->lsm_layout_gen);
516 * Implements cl_object_operations::coo_attr_get() method for an object
517 * without stripes (LLT_EMPTY layout type).
519 * The only attributes this layer is authoritative in this case is
520 * cl_attr::cat_blocks---it's 0.
522 static int lov_attr_get_empty(const struct lu_env *env, struct cl_object *obj,
523 struct cl_attr *attr)
525 attr->cat_blocks = 0;
529 static int lov_attr_get_raid0(const struct lu_env *env, struct cl_object *obj,
530 struct cl_attr *attr)
532 struct lov_object *lov = cl2lov(obj);
533 struct lov_layout_raid0 *r0 = lov_r0(lov);
534 struct cl_attr *lov_attr = &r0->lo_attr;
537 /* this is called w/o holding type guard mutex, so it must be inside
538 * an on going IO otherwise lsm may be replaced.
539 * LU-2117: it turns out there exists one exception. For mmaped files,
540 * the lock of those files may be requested in the other file's IO
541 * context, and this function is called in ccc_lock_state(), it will
542 * hit this assertion.
543 * Anyway, it's still okay to call attr_get w/o type guard as layout
544 * can't go if locks exist.
546 /* LASSERT(atomic_read(&lsm->lsm_refc) > 1); */
548 if (!r0->lo_attr_valid) {
549 struct lov_stripe_md *lsm = lov->lo_lsm;
550 struct ost_lvb *lvb = &lov_env_info(env)->lti_lvb;
553 memset(lvb, 0, sizeof(*lvb));
554 /* XXX: timestamps can be negative by sanity:test_39m,
557 lvb->lvb_atime = LLONG_MIN;
558 lvb->lvb_ctime = LLONG_MIN;
559 lvb->lvb_mtime = LLONG_MIN;
562 * XXX that should be replaced with a loop over sub-objects,
563 * doing cl_object_attr_get() on them. But for now, let's
564 * reuse old lov code.
568 * XXX take lsm spin-lock to keep lov_merge_lvb_kms()
569 * happy. It's not needed, because new code uses
570 * ->coh_attr_guard spin-lock to protect consistency of
571 * sub-object attributes.
573 lov_stripe_lock(lsm);
574 result = lov_merge_lvb_kms(lsm, lvb, &kms);
575 lov_stripe_unlock(lsm);
577 cl_lvb2attr(lov_attr, lvb);
578 lov_attr->cat_kms = kms;
579 r0->lo_attr_valid = 1;
582 if (result == 0) { /* merge results */
583 attr->cat_blocks = lov_attr->cat_blocks;
584 attr->cat_size = lov_attr->cat_size;
585 attr->cat_kms = lov_attr->cat_kms;
586 if (attr->cat_atime < lov_attr->cat_atime)
587 attr->cat_atime = lov_attr->cat_atime;
588 if (attr->cat_ctime < lov_attr->cat_ctime)
589 attr->cat_ctime = lov_attr->cat_ctime;
590 if (attr->cat_mtime < lov_attr->cat_mtime)
591 attr->cat_mtime = lov_attr->cat_mtime;
596 static const struct lov_layout_operations lov_dispatch[] = {
598 .llo_init = lov_init_empty,
599 .llo_delete = lov_delete_empty,
600 .llo_fini = lov_fini_empty,
601 .llo_install = lov_install_empty,
602 .llo_print = lov_print_empty,
603 .llo_page_init = lov_page_init_empty,
604 .llo_lock_init = lov_lock_init_empty,
605 .llo_io_init = lov_io_init_empty,
606 .llo_getattr = lov_attr_get_empty
609 .llo_init = lov_init_raid0,
610 .llo_delete = lov_delete_raid0,
611 .llo_fini = lov_fini_raid0,
612 .llo_install = lov_install_raid0,
613 .llo_print = lov_print_raid0,
614 .llo_page_init = lov_page_init_raid0,
615 .llo_lock_init = lov_lock_init_raid0,
616 .llo_io_init = lov_io_init_raid0,
617 .llo_getattr = lov_attr_get_raid0
620 .llo_init = lov_init_released,
621 .llo_delete = lov_delete_empty,
622 .llo_fini = lov_fini_released,
623 .llo_install = lov_install_empty,
624 .llo_print = lov_print_released,
625 .llo_page_init = lov_page_init_empty,
626 .llo_lock_init = lov_lock_init_empty,
627 .llo_io_init = lov_io_init_released,
628 .llo_getattr = lov_attr_get_empty
633 * Performs a double-dispatch based on the layout type of an object.
635 #define LOV_2DISPATCH_NOLOCK(obj, op, ...) \
637 struct lov_object *__obj = (obj); \
638 enum lov_layout_type __llt; \
640 __llt = __obj->lo_type; \
641 LASSERT(__llt < ARRAY_SIZE(lov_dispatch)); \
642 lov_dispatch[__llt].op(__VA_ARGS__); \
646 * Return lov_layout_type associated with a given lsm
648 static enum lov_layout_type lov_type(struct lov_stripe_md *lsm)
652 if (lsm_is_released(lsm))
657 static inline void lov_conf_freeze(struct lov_object *lov)
659 CDEBUG(D_INODE, "To take share lov(%p) owner %p/%p\n",
660 lov, lov->lo_owner, current);
661 if (lov->lo_owner != current)
662 down_read(&lov->lo_type_guard);
665 static inline void lov_conf_thaw(struct lov_object *lov)
667 CDEBUG(D_INODE, "To release share lov(%p) owner %p/%p\n",
668 lov, lov->lo_owner, current);
669 if (lov->lo_owner != current)
670 up_read(&lov->lo_type_guard);
673 #define LOV_2DISPATCH_MAYLOCK(obj, op, lock, ...) \
675 struct lov_object *__obj = (obj); \
676 int __lock = !!(lock); \
677 typeof(lov_dispatch[0].op(__VA_ARGS__)) __result; \
680 lov_conf_freeze(__obj); \
681 __result = LOV_2DISPATCH_NOLOCK(obj, op, __VA_ARGS__); \
683 lov_conf_thaw(__obj); \
688 * Performs a locked double-dispatch based on the layout type of an object.
690 #define LOV_2DISPATCH(obj, op, ...) \
691 LOV_2DISPATCH_MAYLOCK(obj, op, 1, __VA_ARGS__)
693 #define LOV_2DISPATCH_VOID(obj, op, ...) \
695 struct lov_object *__obj = (obj); \
696 enum lov_layout_type __llt; \
698 lov_conf_freeze(__obj); \
699 __llt = __obj->lo_type; \
700 LASSERT(__llt < ARRAY_SIZE(lov_dispatch)); \
701 lov_dispatch[__llt].op(__VA_ARGS__); \
702 lov_conf_thaw(__obj); \
705 static void lov_conf_lock(struct lov_object *lov)
707 LASSERT(lov->lo_owner != current);
708 down_write(&lov->lo_type_guard);
709 LASSERT(!lov->lo_owner);
710 lov->lo_owner = current;
711 CDEBUG(D_INODE, "Took exclusive lov(%p) owner %p\n",
715 static void lov_conf_unlock(struct lov_object *lov)
717 CDEBUG(D_INODE, "To release exclusive lov(%p) owner %p\n",
719 lov->lo_owner = NULL;
720 up_write(&lov->lo_type_guard);
723 static int lov_layout_wait(const struct lu_env *env, struct lov_object *lov)
725 struct l_wait_info lwi = { 0 };
727 while (atomic_read(&lov->lo_active_ios) > 0) {
728 CDEBUG(D_INODE, "file:" DFID " wait for active IO, now: %d.\n",
729 PFID(lu_object_fid(lov2lu(lov))),
730 atomic_read(&lov->lo_active_ios));
732 l_wait_event(lov->lo_waitq,
733 atomic_read(&lov->lo_active_ios) == 0, &lwi);
738 static int lov_layout_change(const struct lu_env *unused,
739 struct lov_object *lov, struct lov_stripe_md *lsm,
740 const struct cl_object_conf *conf)
742 struct lov_device *lov_dev = lov_object_dev(lov);
743 enum lov_layout_type llt = lov_type(lsm);
744 union lov_layout_state *state = &lov->u;
745 const struct lov_layout_operations *old_ops;
746 const struct lov_layout_operations *new_ops;
751 LASSERT(lov->lo_type < ARRAY_SIZE(lov_dispatch));
753 env = cl_env_get(&refcheck);
757 LASSERT(llt < ARRAY_SIZE(lov_dispatch));
759 CDEBUG(D_INODE, DFID " from %s to %s\n",
760 PFID(lu_object_fid(lov2lu(lov))),
761 llt2str(lov->lo_type), llt2str(llt));
763 old_ops = &lov_dispatch[lov->lo_type];
764 new_ops = &lov_dispatch[llt];
766 rc = cl_object_prune(env, &lov->lo_cl);
770 rc = old_ops->llo_delete(env, lov, &lov->u);
774 old_ops->llo_fini(env, lov, &lov->u);
776 LASSERT(!atomic_read(&lov->lo_active_ios));
778 CDEBUG(D_INODE, DFID "Apply new layout lov %p, type %d\n",
779 PFID(lu_object_fid(lov2lu(lov))), lov, llt);
781 lov->lo_type = LLT_EMPTY;
783 /* page bufsize fixup */
784 cl_object_header(&lov->lo_cl)->coh_page_bufsize -=
785 lov_page_slice_fixup(lov, NULL);
787 rc = new_ops->llo_init(env, lov_dev, lov, lsm, conf, state);
789 struct obd_device *obd = lov2obd(lov_dev->ld_lov);
791 CERROR("%s: cannot apply new layout on " DFID " : rc = %d\n",
792 obd->obd_name, PFID(lu_object_fid(lov2lu(lov))), rc);
793 new_ops->llo_delete(env, lov, state);
794 new_ops->llo_fini(env, lov, state);
795 /* this file becomes an EMPTY file. */
799 new_ops->llo_install(env, lov, state);
802 cl_env_put(env, &refcheck);
806 /*****************************************************************************
808 * Lov object operations.
811 int lov_object_init(const struct lu_env *env, struct lu_object *obj,
812 const struct lu_object_conf *conf)
814 struct lov_object *lov = lu2lov(obj);
815 struct lov_device *dev = lov_object_dev(lov);
816 const struct cl_object_conf *cconf = lu2cl_conf(conf);
817 union lov_layout_state *set = &lov->u;
818 const struct lov_layout_operations *ops;
819 struct lov_stripe_md *lsm = NULL;
822 init_rwsem(&lov->lo_type_guard);
823 atomic_set(&lov->lo_active_ios, 0);
824 init_waitqueue_head(&lov->lo_waitq);
825 cl_object_page_init(lu2cl(obj), sizeof(struct lov_page));
827 lov->lo_type = LLT_EMPTY;
828 if (cconf->u.coc_layout.lb_buf) {
829 lsm = lov_unpackmd(dev->ld_lov,
830 cconf->u.coc_layout.lb_buf,
831 cconf->u.coc_layout.lb_len);
836 /* no locking is necessary, as object is being created */
837 lov->lo_type = lov_type(lsm);
838 ops = &lov_dispatch[lov->lo_type];
839 rc = ops->llo_init(env, dev, lov, lsm, cconf, set);
841 ops->llo_install(env, lov, set);
848 static int lov_conf_set(const struct lu_env *env, struct cl_object *obj,
849 const struct cl_object_conf *conf)
851 struct lov_stripe_md *lsm = NULL;
852 struct lov_object *lov = cl2lov(obj);
855 if (conf->coc_opc == OBJECT_CONF_SET &&
856 conf->u.coc_layout.lb_buf) {
857 lsm = lov_unpackmd(lov_object_dev(lov)->ld_lov,
858 conf->u.coc_layout.lb_buf,
859 conf->u.coc_layout.lb_len);
865 if (conf->coc_opc == OBJECT_CONF_INVALIDATE) {
866 lov->lo_layout_invalid = true;
871 if (conf->coc_opc == OBJECT_CONF_WAIT) {
872 if (lov->lo_layout_invalid &&
873 atomic_read(&lov->lo_active_ios) > 0) {
874 lov_conf_unlock(lov);
875 result = lov_layout_wait(env, lov);
881 LASSERT(conf->coc_opc == OBJECT_CONF_SET);
883 if ((!lsm && !lov->lo_lsm) ||
884 ((lsm && lov->lo_lsm) &&
885 (lov->lo_lsm->lsm_layout_gen == lsm->lsm_layout_gen) &&
886 (lov->lo_lsm->lsm_pattern == lsm->lsm_pattern))) {
887 /* same version of layout */
888 lov->lo_layout_invalid = false;
893 /* will change layout - check if there still exists active IO. */
894 if (atomic_read(&lov->lo_active_ios) > 0) {
895 lov->lo_layout_invalid = true;
900 result = lov_layout_change(env, lov, lsm, conf);
901 lov->lo_layout_invalid = result != 0;
904 lov_conf_unlock(lov);
906 CDEBUG(D_INODE, DFID " lo_layout_invalid=%d\n",
907 PFID(lu_object_fid(lov2lu(lov))), lov->lo_layout_invalid);
911 static void lov_object_delete(const struct lu_env *env, struct lu_object *obj)
913 struct lov_object *lov = lu2lov(obj);
915 LOV_2DISPATCH_VOID(lov, llo_delete, env, lov, &lov->u);
918 static void lov_object_free(const struct lu_env *env, struct lu_object *obj)
920 struct lov_object *lov = lu2lov(obj);
922 LOV_2DISPATCH_VOID(lov, llo_fini, env, lov, &lov->u);
924 kmem_cache_free(lov_object_kmem, lov);
927 static int lov_object_print(const struct lu_env *env, void *cookie,
928 lu_printer_t p, const struct lu_object *o)
930 return LOV_2DISPATCH_NOLOCK(lu2lov(o), llo_print, env, cookie, p, o);
933 int lov_page_init(const struct lu_env *env, struct cl_object *obj,
934 struct cl_page *page, pgoff_t index)
936 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_page_init, env, obj, page,
941 * Implements cl_object_operations::clo_io_init() method for lov
942 * layer. Dispatches to the appropriate layout io initialization method.
944 int lov_io_init(const struct lu_env *env, struct cl_object *obj,
947 CL_IO_SLICE_CLEAN(lov_env_io(env), lis_cl);
949 CDEBUG(D_INODE, DFID "io %p type %d ignore/verify layout %d/%d\n",
950 PFID(lu_object_fid(&obj->co_lu)), io, io->ci_type,
951 io->ci_ignore_layout, io->ci_verify_layout);
953 return LOV_2DISPATCH_MAYLOCK(cl2lov(obj), llo_io_init,
954 !io->ci_ignore_layout, env, obj, io);
958 * An implementation of cl_object_operations::clo_attr_get() method for lov
959 * layer. For raid0 layout this collects and merges attributes of all
962 static int lov_attr_get(const struct lu_env *env, struct cl_object *obj,
963 struct cl_attr *attr)
965 /* do not take lock, as this function is called under a
966 * spin-lock. Layout is protected from changing by ongoing IO.
968 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_getattr, env, obj, attr);
971 static int lov_attr_update(const struct lu_env *env, struct cl_object *obj,
972 const struct cl_attr *attr, unsigned int valid)
975 * No dispatch is required here, as no layout implements this.
980 int lov_lock_init(const struct lu_env *env, struct cl_object *obj,
981 struct cl_lock *lock, const struct cl_io *io)
983 /* No need to lock because we've taken one refcount of layout. */
984 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_lock_init, env, obj, lock,
989 * We calculate on which OST the mapping will end. If the length of mapping
990 * is greater than (stripe_size * stripe_count) then the last_stripe will
991 * will be one just before start_stripe. Else we check if the mapping
992 * intersects each OST and find last_stripe.
993 * This function returns the last_stripe and also sets the stripe_count
994 * over which the mapping is spread
996 * \param lsm [in] striping information for the file
997 * \param fm_start [in] logical start of mapping
998 * \param fm_end [in] logical end of mapping
999 * \param start_stripe [in] starting stripe of the mapping
1000 * \param stripe_count [out] the number of stripes across which to map is
1003 * \retval last_stripe return the last stripe of the mapping
1005 static int fiemap_calc_last_stripe(struct lov_stripe_md *lsm,
1006 u64 fm_start, u64 fm_end,
1007 int start_stripe, int *stripe_count)
1014 if (fm_end - fm_start > lsm->lsm_stripe_size * lsm->lsm_stripe_count) {
1015 last_stripe = (start_stripe < 1 ? lsm->lsm_stripe_count - 1 :
1017 *stripe_count = lsm->lsm_stripe_count;
1019 for (j = 0, i = start_stripe; j < lsm->lsm_stripe_count;
1020 i = (i + 1) % lsm->lsm_stripe_count, j++) {
1021 if (!(lov_stripe_intersects(lsm, i, fm_start, fm_end,
1022 &obd_start, &obd_end)))
1026 last_stripe = (start_stripe + j - 1) % lsm->lsm_stripe_count;
1033 * Set fe_device and copy extents from local buffer into main return buffer.
1035 * \param fiemap [out] fiemap to hold all extents
1036 * \param lcl_fm_ext [in] array of fiemap extents get from OSC layer
1037 * \param ost_index [in] OST index to be written into the fm_device
1038 * field for each extent
1039 * \param ext_count [in] number of extents to be copied
1040 * \param current_extent [in] where to start copying in the extent array
1042 static void fiemap_prepare_and_copy_exts(struct fiemap *fiemap,
1043 struct fiemap_extent *lcl_fm_ext,
1044 int ost_index, unsigned int ext_count,
1050 for (ext = 0; ext < ext_count; ext++) {
1051 lcl_fm_ext[ext].fe_device = ost_index;
1052 lcl_fm_ext[ext].fe_flags |= FIEMAP_EXTENT_NET;
1055 /* Copy fm_extent's from fm_local to return buffer */
1056 to = (char *)fiemap + fiemap_count_to_size(current_extent);
1057 memcpy(to, lcl_fm_ext, ext_count * sizeof(struct fiemap_extent));
1060 #define FIEMAP_BUFFER_SIZE 4096
1063 * Non-zero fe_logical indicates that this is a continuation FIEMAP
1064 * call. The local end offset and the device are sent in the first
1065 * fm_extent. This function calculates the stripe number from the index.
1066 * This function returns a stripe_no on which mapping is to be restarted.
1068 * This function returns fm_end_offset which is the in-OST offset at which
1069 * mapping should be restarted. If fm_end_offset=0 is returned then caller
1070 * will re-calculate proper offset in next stripe.
1071 * Note that the first extent is passed to lov_get_info via the value field.
1073 * \param fiemap [in] fiemap request header
1074 * \param lsm [in] striping information for the file
1075 * \param fm_start [in] logical start of mapping
1076 * \param fm_end [in] logical end of mapping
1077 * \param start_stripe [out] starting stripe will be returned in this
1079 static u64 fiemap_calc_fm_end_offset(struct fiemap *fiemap,
1080 struct lov_stripe_md *lsm,
1081 u64 fm_start, u64 fm_end,
1084 u64 local_end = fiemap->fm_extents[0].fe_logical;
1085 u64 lun_start, lun_end;
1090 if (!fiemap->fm_extent_count || !fiemap->fm_extents[0].fe_logical)
1093 /* Find out stripe_no from ost_index saved in the fe_device */
1094 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1095 struct lov_oinfo *oinfo = lsm->lsm_oinfo[i];
1097 if (lov_oinfo_is_dummy(oinfo))
1100 if (oinfo->loi_ost_idx == fiemap->fm_extents[0].fe_device) {
1106 if (stripe_no == -1)
1110 * If we have finished mapping on previous device, shift logical
1111 * offset to start of next device
1113 if (lov_stripe_intersects(lsm, stripe_no, fm_start, fm_end,
1114 &lun_start, &lun_end) &&
1115 local_end < lun_end) {
1116 fm_end_offset = local_end;
1117 *start_stripe = stripe_no;
1119 /* This is a special value to indicate that caller should
1120 * calculate offset in next stripe.
1123 *start_stripe = (stripe_no + 1) % lsm->lsm_stripe_count;
1126 return fm_end_offset;
1129 struct fiemap_state {
1130 struct fiemap *fs_fm;
1137 int fs_start_stripe;
1139 bool fs_device_done;
1144 static int fiemap_for_stripe(const struct lu_env *env, struct cl_object *obj,
1145 struct lov_stripe_md *lsm,
1146 struct fiemap *fiemap, size_t *buflen,
1147 struct ll_fiemap_info_key *fmkey, int stripeno,
1148 struct fiemap_state *fs)
1150 struct cl_object *subobj;
1151 struct lov_obd *lov = lu2lov_dev(obj->co_lu.lo_dev)->ld_lov;
1152 struct fiemap_extent *fm_ext = &fs->fs_fm->fm_extents[0];
1153 u64 req_fm_len; /* Stores length of required mapping */
1154 u64 len_mapped_single_call;
1158 unsigned int ext_count;
1159 /* EOF for object */
1160 bool ost_eof = false;
1161 /* done with required mapping for this OST? */
1162 bool ost_done = false;
1166 fs->fs_device_done = false;
1167 /* Find out range of mapping on this stripe */
1168 if ((lov_stripe_intersects(lsm, stripeno, fs->fs_start, fs->fs_end,
1169 &lun_start, &obd_object_end)) == 0)
1172 if (lov_oinfo_is_dummy(lsm->lsm_oinfo[stripeno]))
1175 /* If this is a continuation FIEMAP call and we are on
1176 * starting stripe then lun_start needs to be set to
1178 if (fs->fs_end_offset != 0 && stripeno == fs->fs_start_stripe)
1179 lun_start = fs->fs_end_offset;
1181 lun_end = fs->fs_length;
1182 if (lun_end != ~0ULL) {
1183 /* Handle fs->fs_start + fs->fs_length overflow */
1184 if (fs->fs_start + fs->fs_length < fs->fs_start)
1185 fs->fs_length = ~0ULL - fs->fs_start;
1186 lun_end = lov_size_to_stripe(lsm, fs->fs_start + fs->fs_length,
1190 if (lun_start == lun_end)
1193 req_fm_len = obd_object_end - lun_start;
1194 fs->fs_fm->fm_length = 0;
1195 len_mapped_single_call = 0;
1197 /* find lobsub object */
1198 subobj = lov_find_subobj(env, cl2lov(obj), lsm, stripeno);
1200 return PTR_ERR(subobj);
1201 /* If the output buffer is very large and the objects have many
1202 * extents we may need to loop on a single OST repeatedly */
1204 if (fiemap->fm_extent_count > 0) {
1205 /* Don't get too many extents. */
1206 if (fs->fs_cur_extent + fs->fs_cnt_need >
1207 fiemap->fm_extent_count)
1208 fs->fs_cnt_need = fiemap->fm_extent_count -
1212 lun_start += len_mapped_single_call;
1213 fs->fs_fm->fm_length = req_fm_len - len_mapped_single_call;
1214 req_fm_len = fs->fs_fm->fm_length;
1215 fs->fs_fm->fm_extent_count = fs->fs_enough ?
1216 1 : fs->fs_cnt_need;
1217 fs->fs_fm->fm_mapped_extents = 0;
1218 fs->fs_fm->fm_flags = fiemap->fm_flags;
1220 ost_index = lsm->lsm_oinfo[stripeno]->loi_ost_idx;
1222 if (ost_index < 0 || ost_index >= lov->desc.ld_tgt_count) {
1226 /* If OST is inactive, return extent with UNKNOWN flag. */
1227 if (!lov->lov_tgts[ost_index]->ltd_active) {
1228 fs->fs_fm->fm_flags |= FIEMAP_EXTENT_LAST;
1229 fs->fs_fm->fm_mapped_extents = 1;
1231 fm_ext[0].fe_logical = lun_start;
1232 fm_ext[0].fe_length = obd_object_end - lun_start;
1233 fm_ext[0].fe_flags |= FIEMAP_EXTENT_UNKNOWN;
1238 fs->fs_fm->fm_start = lun_start;
1239 fs->fs_fm->fm_flags &= ~FIEMAP_FLAG_DEVICE_ORDER;
1240 memcpy(&fmkey->lfik_fiemap, fs->fs_fm, sizeof(*fs->fs_fm));
1241 *buflen = fiemap_count_to_size(fs->fs_fm->fm_extent_count);
1243 rc = cl_object_fiemap(env, subobj, fmkey, fs->fs_fm, buflen);
1247 ext_count = fs->fs_fm->fm_mapped_extents;
1248 if (ext_count == 0) {
1250 fs->fs_device_done = true;
1251 /* If last stripe has hold at the end,
1252 * we need to return */
1253 if (stripeno == fs->fs_last_stripe) {
1254 fiemap->fm_mapped_extents = 0;
1255 fs->fs_finish = true;
1259 } else if (fs->fs_enough) {
1261 * We've collected enough extents and there are
1262 * more extents after it.
1264 fs->fs_finish = true;
1268 /* If we just need num of extents, got to next device */
1269 if (fiemap->fm_extent_count == 0) {
1270 fs->fs_cur_extent += ext_count;
1274 /* prepare to copy retrived map extents */
1275 len_mapped_single_call = fm_ext[ext_count - 1].fe_logical +
1276 fm_ext[ext_count - 1].fe_length -
1279 /* Have we finished mapping on this device? */
1280 if (req_fm_len <= len_mapped_single_call) {
1282 fs->fs_device_done = true;
1285 /* Clear the EXTENT_LAST flag which can be present on
1286 * the last extent */
1287 if (fm_ext[ext_count - 1].fe_flags & FIEMAP_EXTENT_LAST)
1288 fm_ext[ext_count - 1].fe_flags &= ~FIEMAP_EXTENT_LAST;
1289 if (lov_stripe_size(lsm, fm_ext[ext_count - 1].fe_logical +
1290 fm_ext[ext_count - 1].fe_length,
1291 stripeno) >= fmkey->lfik_oa.o_size) {
1293 fs->fs_device_done = true;
1296 fiemap_prepare_and_copy_exts(fiemap, fm_ext, ost_index,
1297 ext_count, fs->fs_cur_extent);
1298 fs->fs_cur_extent += ext_count;
1300 /* Ran out of available extents? */
1301 if (fs->fs_cur_extent >= fiemap->fm_extent_count)
1302 fs->fs_enough = true;
1303 } while (!ost_done && !ost_eof);
1305 if (stripeno == fs->fs_last_stripe)
1306 fs->fs_finish = true;
1308 cl_object_put(env, subobj);
1314 * Break down the FIEMAP request and send appropriate calls to individual OSTs.
1315 * This also handles the restarting of FIEMAP calls in case mapping overflows
1316 * the available number of extents in single call.
1318 * \param env [in] lustre environment
1319 * \param obj [in] file object
1320 * \param fmkey [in] fiemap request header and other info
1321 * \param fiemap [out] fiemap buffer holding retrived map extents
1322 * \param buflen [in/out] max buffer length of @fiemap, when iterate
1323 * each OST, it is used to limit max map needed
1327 static int lov_object_fiemap(const struct lu_env *env, struct cl_object *obj,
1328 struct ll_fiemap_info_key *fmkey,
1329 struct fiemap *fiemap, size_t *buflen)
1331 unsigned int buffer_size = FIEMAP_BUFFER_SIZE;
1332 struct fiemap *fm_local = NULL;
1333 struct lov_stripe_md *lsm;
1337 struct fiemap_state fs = { 0 };
1339 lsm = lov_lsm_addref(cl2lov(obj));
1344 * If the stripe_count > 1 and the application does not understand
1345 * DEVICE_ORDER flag, it cannot interpret the extents correctly.
1347 if (lsm->lsm_stripe_count > 1 &&
1348 !(fiemap->fm_flags & FIEMAP_FLAG_DEVICE_ORDER)) {
1353 if (lsm_is_released(lsm)) {
1354 if (fiemap->fm_start < fmkey->lfik_oa.o_size) {
1356 * released file, return a minimal FIEMAP if
1357 * request fits in file-size.
1359 fiemap->fm_mapped_extents = 1;
1360 fiemap->fm_extents[0].fe_logical = fiemap->fm_start;
1361 if (fiemap->fm_start + fiemap->fm_length <
1362 fmkey->lfik_oa.o_size)
1363 fiemap->fm_extents[0].fe_length =
1366 fiemap->fm_extents[0].fe_length =
1367 fmkey->lfik_oa.o_size -
1369 fiemap->fm_extents[0].fe_flags |=
1370 FIEMAP_EXTENT_UNKNOWN | FIEMAP_EXTENT_LAST;
1376 if (fiemap_count_to_size(fiemap->fm_extent_count) < buffer_size)
1377 buffer_size = fiemap_count_to_size(fiemap->fm_extent_count);
1379 fm_local = libcfs_kvzalloc(buffer_size, GFP_NOFS);
1384 fs.fs_fm = fm_local;
1385 fs.fs_cnt_need = fiemap_size_to_count(buffer_size);
1387 fs.fs_start = fiemap->fm_start;
1388 /* fs_start is beyond the end of the file */
1389 if (fs.fs_start > fmkey->lfik_oa.o_size) {
1393 /* Calculate start stripe, last stripe and length of mapping */
1394 fs.fs_start_stripe = lov_stripe_number(lsm, fs.fs_start);
1395 fs.fs_end = (fs.fs_length == ~0ULL) ? fmkey->lfik_oa.o_size :
1396 fs.fs_start + fs.fs_length - 1;
1397 /* If fs_length != ~0ULL but fs_start+fs_length-1 exceeds file size */
1398 if (fs.fs_end > fmkey->lfik_oa.o_size) {
1399 fs.fs_end = fmkey->lfik_oa.o_size;
1400 fs.fs_length = fs.fs_end - fs.fs_start;
1403 fs.fs_last_stripe = fiemap_calc_last_stripe(lsm, fs.fs_start, fs.fs_end,
1406 fs.fs_end_offset = fiemap_calc_fm_end_offset(fiemap, lsm, fs.fs_start,
1408 &fs.fs_start_stripe);
1409 if (fs.fs_end_offset == -EINVAL) {
1416 * Requested extent count exceeds the fiemap buffer size, shrink our
1419 if (fiemap_count_to_size(fiemap->fm_extent_count) > *buflen)
1420 fiemap->fm_extent_count = fiemap_size_to_count(*buflen);
1421 if (!fiemap->fm_extent_count)
1424 fs.fs_finish = false;
1425 fs.fs_enough = false;
1426 fs.fs_cur_extent = 0;
1428 /* Check each stripe */
1429 for (cur_stripe = fs.fs_start_stripe; stripe_count > 0;
1431 cur_stripe = (cur_stripe + 1) % lsm->lsm_stripe_count) {
1432 rc = fiemap_for_stripe(env, obj, lsm, fiemap, buflen, fmkey,
1438 } /* for each stripe */
1440 * Indicate that we are returning device offsets unless file just has
1443 if (lsm->lsm_stripe_count > 1)
1444 fiemap->fm_flags |= FIEMAP_FLAG_DEVICE_ORDER;
1446 if (!fiemap->fm_extent_count)
1447 goto skip_last_device_calc;
1450 * Check if we have reached the last stripe and whether mapping for that
1453 if ((cur_stripe == fs.fs_last_stripe) && fs.fs_device_done)
1454 fiemap->fm_extents[fs.fs_cur_extent - 1].fe_flags |=
1456 skip_last_device_calc:
1457 fiemap->fm_mapped_extents = fs.fs_cur_extent;
1464 static int lov_object_getstripe(const struct lu_env *env, struct cl_object *obj,
1465 struct lov_user_md __user *lum)
1467 struct lov_object *lov = cl2lov(obj);
1468 struct lov_stripe_md *lsm;
1471 lsm = lov_lsm_addref(lov);
1475 rc = lov_getstripe(cl2lov(obj), lsm, lum);
1480 static int lov_object_layout_get(const struct lu_env *env,
1481 struct cl_object *obj,
1482 struct cl_layout *cl)
1484 struct lov_object *lov = cl2lov(obj);
1485 struct lov_stripe_md *lsm = lov_lsm_addref(lov);
1486 struct lu_buf *buf = &cl->cl_buf;
1491 cl->cl_layout_gen = CL_LAYOUT_GEN_EMPTY;
1495 cl->cl_size = lov_mds_md_size(lsm->lsm_stripe_count, lsm->lsm_magic);
1496 cl->cl_layout_gen = lsm->lsm_layout_gen;
1498 rc = lov_lsm_pack(lsm, buf->lb_buf, buf->lb_len);
1501 return rc < 0 ? rc : 0;
1504 static loff_t lov_object_maxbytes(struct cl_object *obj)
1506 struct lov_object *lov = cl2lov(obj);
1507 struct lov_stripe_md *lsm = lov_lsm_addref(lov);
1513 maxbytes = lsm->lsm_maxbytes;
1520 static const struct cl_object_operations lov_ops = {
1521 .coo_page_init = lov_page_init,
1522 .coo_lock_init = lov_lock_init,
1523 .coo_io_init = lov_io_init,
1524 .coo_attr_get = lov_attr_get,
1525 .coo_attr_update = lov_attr_update,
1526 .coo_conf_set = lov_conf_set,
1527 .coo_getstripe = lov_object_getstripe,
1528 .coo_layout_get = lov_object_layout_get,
1529 .coo_maxbytes = lov_object_maxbytes,
1530 .coo_fiemap = lov_object_fiemap,
1533 static const struct lu_object_operations lov_lu_obj_ops = {
1534 .loo_object_init = lov_object_init,
1535 .loo_object_delete = lov_object_delete,
1536 .loo_object_release = NULL,
1537 .loo_object_free = lov_object_free,
1538 .loo_object_print = lov_object_print,
1539 .loo_object_invariant = NULL
1542 struct lu_object *lov_object_alloc(const struct lu_env *env,
1543 const struct lu_object_header *unused,
1544 struct lu_device *dev)
1546 struct lov_object *lov;
1547 struct lu_object *obj;
1549 lov = kmem_cache_zalloc(lov_object_kmem, GFP_NOFS);
1552 lu_object_init(obj, NULL, dev);
1553 lov->lo_cl.co_ops = &lov_ops;
1554 lov->lo_type = -1; /* invalid, to catch uninitialized type */
1556 * object io operation vector (cl_object::co_iop) is installed
1557 * later in lov_object_init(), as different vectors are used
1558 * for object with different layouts.
1560 obj->lo_ops = &lov_lu_obj_ops;
1567 struct lov_stripe_md *lov_lsm_addref(struct lov_object *lov)
1569 struct lov_stripe_md *lsm = NULL;
1571 lov_conf_freeze(lov);
1573 lsm = lsm_addref(lov->lo_lsm);
1574 CDEBUG(D_INODE, "lsm %p addref %d/%d by %p.\n",
1575 lsm, atomic_read(&lsm->lsm_refc),
1576 lov->lo_layout_invalid, current);
1582 int lov_read_and_clear_async_rc(struct cl_object *clob)
1584 struct lu_object *luobj;
1587 luobj = lu_object_locate(&cl_object_header(clob)->coh_lu,
1590 struct lov_object *lov = lu2lov(luobj);
1592 lov_conf_freeze(lov);
1593 switch (lov->lo_type) {
1595 struct lov_stripe_md *lsm;
1599 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1600 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
1602 if (lov_oinfo_is_dummy(loi))
1605 if (loi->loi_ar.ar_rc && !rc)
1606 rc = loi->loi_ar.ar_rc;
1607 loi->loi_ar.ar_rc = 0;
1620 EXPORT_SYMBOL(lov_read_and_clear_async_rc);