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 static void lov_lsm_put(struct lov_stripe_md *lsm)
90 /*****************************************************************************
92 * Lov object layout operations.
96 static void lov_install_empty(const struct lu_env *env,
97 struct lov_object *lov,
98 union lov_layout_state *state)
101 * File without objects.
105 static int lov_init_empty(const struct lu_env *env,
106 struct lov_device *dev, struct lov_object *lov,
107 const struct cl_object_conf *conf,
108 union lov_layout_state *state)
113 static void lov_install_raid0(const struct lu_env *env,
114 struct lov_object *lov,
115 union lov_layout_state *state)
119 static struct cl_object *lov_sub_find(const struct lu_env *env,
120 struct cl_device *dev,
121 const struct lu_fid *fid,
122 const struct cl_object_conf *conf)
127 o = lu_object_find_at(env, cl2lu_dev(dev), fid, &conf->coc_lu);
128 LASSERT(ergo(!IS_ERR(o), o->lo_dev->ld_type == &lovsub_device_type));
132 static int lov_init_sub(const struct lu_env *env, struct lov_object *lov,
133 struct cl_object *stripe, struct lov_layout_raid0 *r0,
136 struct cl_object_header *hdr;
137 struct cl_object_header *subhdr;
138 struct cl_object_header *parent;
139 struct lov_oinfo *oinfo;
142 if (OBD_FAIL_CHECK(OBD_FAIL_LOV_INIT)) {
143 /* For sanity:test_206.
144 * Do not leave the object in cache to avoid accessing
145 * freed memory. This is because osc_object is referring to
146 * lov_oinfo of lsm_stripe_data which will be freed due to
148 cl_object_kill(env, stripe);
149 cl_object_put(env, stripe);
153 hdr = cl_object_header(lov2cl(lov));
154 subhdr = cl_object_header(stripe);
156 oinfo = lov->lo_lsm->lsm_oinfo[idx];
157 CDEBUG(D_INODE, DFID"@%p[%d] -> "DFID"@%p: ostid: "DOSTID
158 " idx: %d gen: %d\n",
159 PFID(&subhdr->coh_lu.loh_fid), subhdr, idx,
160 PFID(&hdr->coh_lu.loh_fid), hdr, POSTID(&oinfo->loi_oi),
161 oinfo->loi_ost_idx, oinfo->loi_ost_gen);
163 /* reuse ->coh_attr_guard to protect coh_parent change */
164 spin_lock(&subhdr->coh_attr_guard);
165 parent = subhdr->coh_parent;
166 if (parent == NULL) {
167 subhdr->coh_parent = hdr;
168 spin_unlock(&subhdr->coh_attr_guard);
169 subhdr->coh_nesting = hdr->coh_nesting + 1;
170 lu_object_ref_add(&stripe->co_lu, "lov-parent", lov);
171 r0->lo_sub[idx] = cl2lovsub(stripe);
172 r0->lo_sub[idx]->lso_super = lov;
173 r0->lo_sub[idx]->lso_index = idx;
176 struct lu_object *old_obj;
177 struct lov_object *old_lov;
178 unsigned int mask = D_INODE;
180 spin_unlock(&subhdr->coh_attr_guard);
181 old_obj = lu_object_locate(&parent->coh_lu, &lov_device_type);
182 LASSERT(old_obj != NULL);
183 old_lov = cl2lov(lu2cl(old_obj));
184 if (old_lov->lo_layout_invalid) {
185 /* the object's layout has already changed but isn't
187 lu_object_unhash(env, &stripe->co_lu);
194 LU_OBJECT_DEBUG(mask, env, &stripe->co_lu,
195 "stripe %d is already owned.\n", idx);
196 LU_OBJECT_DEBUG(mask, env, old_obj, "owned.\n");
197 LU_OBJECT_HEADER(mask, env, lov2lu(lov), "try to own.\n");
198 cl_object_put(env, stripe);
203 static int lov_page_slice_fixup(struct lov_object *lov,
204 struct cl_object *stripe)
206 struct cl_object_header *hdr = cl_object_header(&lov->lo_cl);
210 return hdr->coh_page_bufsize - lov->lo_cl.co_slice_off -
211 cfs_size_round(sizeof(struct lov_page));
213 cl_object_for_each(o, stripe)
214 o->co_slice_off += hdr->coh_page_bufsize;
216 return cl_object_header(stripe)->coh_page_bufsize;
219 static int lov_init_raid0(const struct lu_env *env,
220 struct lov_device *dev, struct lov_object *lov,
221 const struct cl_object_conf *conf,
222 union lov_layout_state *state)
227 struct cl_object *stripe;
228 struct lov_thread_info *lti = lov_env_info(env);
229 struct cl_object_conf *subconf = <i->lti_stripe_conf;
230 struct lov_stripe_md *lsm = conf->u.coc_md->lsm;
231 struct lu_fid *ofid = <i->lti_fid;
232 struct lov_layout_raid0 *r0 = &state->raid0;
236 if (lsm->lsm_magic != LOV_MAGIC_V1 && lsm->lsm_magic != LOV_MAGIC_V3) {
237 dump_lsm(D_ERROR, lsm);
238 LASSERTF(0, "magic mismatch, expected %d/%d, actual %d.\n",
239 LOV_MAGIC_V1, LOV_MAGIC_V3, lsm->lsm_magic);
242 LASSERT(lov->lo_lsm == NULL);
243 lov->lo_lsm = lsm_addref(lsm);
244 r0->lo_nr = lsm->lsm_stripe_count;
245 LASSERT(r0->lo_nr <= lov_targets_nr(dev));
247 lov->lo_layout_invalid = true;
249 OBD_ALLOC_LARGE(r0->lo_sub, r0->lo_nr * sizeof r0->lo_sub[0]);
250 if (r0->lo_sub != NULL) {
254 subconf->coc_inode = conf->coc_inode;
255 spin_lock_init(&r0->lo_sub_lock);
257 * Create stripe cl_objects.
259 for (i = 0; i < r0->lo_nr && result == 0; ++i) {
260 struct cl_device *subdev;
261 struct lov_oinfo *oinfo = lsm->lsm_oinfo[i];
262 int ost_idx = oinfo->loi_ost_idx;
264 if (lov_oinfo_is_dummy(oinfo))
267 result = ostid_to_fid(ofid, &oinfo->loi_oi,
272 subdev = lovsub2cl_dev(dev->ld_target[ost_idx]);
273 subconf->u.coc_oinfo = oinfo;
274 LASSERTF(subdev != NULL, "not init ost %d\n", ost_idx);
275 /* In the function below, .hs_keycmp resolves to
276 * lu_obj_hop_keycmp() */
277 /* coverity[overrun-buffer-val] */
278 stripe = lov_sub_find(env, subdev, ofid, subconf);
279 if (!IS_ERR(stripe)) {
280 result = lov_init_sub(env, lov, stripe, r0, i);
281 if (result == -EAGAIN) { /* try again */
287 result = PTR_ERR(stripe);
291 int sz = lov_page_slice_fixup(lov, stripe);
292 LASSERT(ergo(psz > 0, psz == sz));
297 cl_object_header(&lov->lo_cl)->coh_page_bufsize += psz;
304 static int lov_init_released(const struct lu_env *env,
305 struct lov_device *dev, struct lov_object *lov,
306 const struct cl_object_conf *conf,
307 union lov_layout_state *state)
309 struct lov_stripe_md *lsm = conf->u.coc_md->lsm;
311 LASSERT(lsm != NULL);
312 LASSERT(lsm_is_released(lsm));
313 LASSERT(lov->lo_lsm == NULL);
315 lov->lo_lsm = lsm_addref(lsm);
319 static struct cl_object *lov_find_subobj(const struct lu_env *env,
320 struct lov_object *lov,
321 struct lov_stripe_md *lsm,
324 struct lov_device *dev = lu2lov_dev(lov2lu(lov)->lo_dev);
325 struct lov_oinfo *oinfo = lsm->lsm_oinfo[stripe_idx];
326 struct lov_thread_info *lti = lov_env_info(env);
327 struct lu_fid *ofid = <i->lti_fid;
328 struct cl_device *subdev;
331 struct cl_object *result;
333 if (lov->lo_type != LLT_RAID0)
334 GOTO(out, result = NULL);
336 ost_idx = oinfo->loi_ost_idx;
337 rc = ostid_to_fid(ofid, &oinfo->loi_oi, ost_idx);
339 GOTO(out, result = NULL);
341 subdev = lovsub2cl_dev(dev->ld_target[ost_idx]);
342 result = lov_sub_find(env, subdev, ofid, NULL);
345 result = ERR_PTR(-EINVAL);
349 static int lov_delete_empty(const struct lu_env *env, struct lov_object *lov,
350 union lov_layout_state *state)
352 LASSERT(lov->lo_type == LLT_EMPTY || lov->lo_type == LLT_RELEASED);
354 lov_layout_wait(env, lov);
358 static void lov_subobject_kill(const struct lu_env *env, struct lov_object *lov,
359 struct lovsub_object *los, int idx)
361 struct cl_object *sub;
362 struct lov_layout_raid0 *r0;
363 struct lu_site *site;
364 struct lu_site_bkt_data *bkt;
365 wait_queue_t *waiter;
368 LASSERT(r0->lo_sub[idx] == los);
370 sub = lovsub2cl(los);
371 site = sub->co_lu.lo_dev->ld_site;
372 bkt = lu_site_bkt_from_fid(site, &sub->co_lu.lo_header->loh_fid);
374 cl_object_kill(env, sub);
375 /* release a reference to the sub-object and ... */
376 lu_object_ref_del(&sub->co_lu, "lov-parent", lov);
377 cl_object_put(env, sub);
379 /* ... wait until it is actually destroyed---sub-object clears its
380 * ->lo_sub[] slot in lovsub_object_fini() */
381 if (r0->lo_sub[idx] == los) {
382 waiter = &lov_env_info(env)->lti_waiter;
383 init_waitqueue_entry_current(waiter);
384 add_wait_queue(&bkt->lsb_marche_funebre, waiter);
385 set_current_state(TASK_UNINTERRUPTIBLE);
387 /* this wait-queue is signaled at the end of
388 * lu_object_free(). */
389 set_current_state(TASK_UNINTERRUPTIBLE);
390 spin_lock(&r0->lo_sub_lock);
391 if (r0->lo_sub[idx] == los) {
392 spin_unlock(&r0->lo_sub_lock);
393 waitq_wait(waiter, TASK_UNINTERRUPTIBLE);
395 spin_unlock(&r0->lo_sub_lock);
396 set_current_state(TASK_RUNNING);
400 remove_wait_queue(&bkt->lsb_marche_funebre, waiter);
402 LASSERT(r0->lo_sub[idx] == NULL);
405 static int lov_delete_raid0(const struct lu_env *env, struct lov_object *lov,
406 union lov_layout_state *state)
408 struct lov_layout_raid0 *r0 = &state->raid0;
409 struct lov_stripe_md *lsm = lov->lo_lsm;
414 dump_lsm(D_INODE, lsm);
416 lov_layout_wait(env, lov);
417 if (r0->lo_sub != NULL) {
418 for (i = 0; i < r0->lo_nr; ++i) {
419 struct lovsub_object *los = r0->lo_sub[i];
422 cl_object_prune(env, &los->lso_cl);
424 * If top-level object is to be evicted from
425 * the cache, so are its sub-objects.
427 lov_subobject_kill(env, lov, los, i);
434 static void lov_fini_empty(const struct lu_env *env, struct lov_object *lov,
435 union lov_layout_state *state)
437 LASSERT(lov->lo_type == LLT_EMPTY || lov->lo_type == LLT_RELEASED);
440 static void lov_fini_raid0(const struct lu_env *env, struct lov_object *lov,
441 union lov_layout_state *state)
443 struct lov_layout_raid0 *r0 = &state->raid0;
446 if (r0->lo_sub != NULL) {
447 OBD_FREE_LARGE(r0->lo_sub, r0->lo_nr * sizeof r0->lo_sub[0]);
451 dump_lsm(D_INODE, lov->lo_lsm);
452 lov_free_memmd(&lov->lo_lsm);
457 static void lov_fini_released(const struct lu_env *env, struct lov_object *lov,
458 union lov_layout_state *state)
461 dump_lsm(D_INODE, lov->lo_lsm);
462 lov_free_memmd(&lov->lo_lsm);
466 static int lov_print_empty(const struct lu_env *env, void *cookie,
467 lu_printer_t p, const struct lu_object *o)
469 (*p)(env, cookie, "empty %d\n", lu2lov(o)->lo_layout_invalid);
473 static int lov_print_raid0(const struct lu_env *env, void *cookie,
474 lu_printer_t p, const struct lu_object *o)
476 struct lov_object *lov = lu2lov(o);
477 struct lov_layout_raid0 *r0 = lov_r0(lov);
478 struct lov_stripe_md *lsm = lov->lo_lsm;
481 (*p)(env, cookie, "stripes: %d, %s, lsm{%p 0x%08X %d %u %u}:\n",
482 r0->lo_nr, lov->lo_layout_invalid ? "invalid" : "valid", lsm,
483 lsm->lsm_magic, atomic_read(&lsm->lsm_refc),
484 lsm->lsm_stripe_count, lsm->lsm_layout_gen);
485 for (i = 0; i < r0->lo_nr; ++i) {
486 struct lu_object *sub;
488 if (r0->lo_sub[i] != NULL) {
489 sub = lovsub2lu(r0->lo_sub[i]);
490 lu_object_print(env, cookie, p, sub);
492 (*p)(env, cookie, "sub %d absent\n", i);
498 static int lov_print_released(const struct lu_env *env, void *cookie,
499 lu_printer_t p, const struct lu_object *o)
501 struct lov_object *lov = lu2lov(o);
502 struct lov_stripe_md *lsm = lov->lo_lsm;
505 "released: %s, lsm{%p 0x%08X %d %u %u}:\n",
506 lov->lo_layout_invalid ? "invalid" : "valid", lsm,
507 lsm->lsm_magic, atomic_read(&lsm->lsm_refc),
508 lsm->lsm_stripe_count, lsm->lsm_layout_gen);
513 * Implements cl_object_operations::coo_attr_get() method for an object
514 * without stripes (LLT_EMPTY layout type).
516 * The only attributes this layer is authoritative in this case is
517 * cl_attr::cat_blocks---it's 0.
519 static int lov_attr_get_empty(const struct lu_env *env, struct cl_object *obj,
520 struct cl_attr *attr)
522 attr->cat_blocks = 0;
526 static int lov_attr_get_raid0(const struct lu_env *env, struct cl_object *obj,
527 struct cl_attr *attr)
529 struct lov_object *lov = cl2lov(obj);
530 struct lov_layout_raid0 *r0 = lov_r0(lov);
531 struct cl_attr *lov_attr = &r0->lo_attr;
536 /* this is called w/o holding type guard mutex, so it must be inside
537 * an on going IO otherwise lsm may be replaced.
538 * LU-2117: it turns out there exists one exception. For mmaped files,
539 * the lock of those files may be requested in the other file's IO
540 * context, and this function is called in ccc_lock_state(), it will
541 * hit this assertion.
542 * Anyway, it's still okay to call attr_get w/o type guard as layout
543 * can't go if locks exist. */
544 /* LASSERT(atomic_read(&lsm->lsm_refc) > 1); */
546 if (!r0->lo_attr_valid) {
547 struct lov_stripe_md *lsm = lov->lo_lsm;
548 struct ost_lvb *lvb = &lov_env_info(env)->lti_lvb;
551 memset(lvb, 0, sizeof(*lvb));
552 /* XXX: timestamps can be negative by sanity:test_39m,
554 lvb->lvb_atime = LLONG_MIN;
555 lvb->lvb_ctime = LLONG_MIN;
556 lvb->lvb_mtime = LLONG_MIN;
559 * XXX that should be replaced with a loop over sub-objects,
560 * doing cl_object_attr_get() on them. But for now, let's
561 * reuse old lov code.
565 * XXX take lsm spin-lock to keep lov_merge_lvb_kms()
566 * happy. It's not needed, because new code uses
567 * ->coh_attr_guard spin-lock to protect consistency of
568 * sub-object attributes.
570 lov_stripe_lock(lsm);
571 result = lov_merge_lvb_kms(lsm, lvb, &kms);
572 lov_stripe_unlock(lsm);
574 cl_lvb2attr(lov_attr, lvb);
575 lov_attr->cat_kms = kms;
576 r0->lo_attr_valid = 1;
579 if (result == 0) { /* merge results */
580 attr->cat_blocks = lov_attr->cat_blocks;
581 attr->cat_size = lov_attr->cat_size;
582 attr->cat_kms = lov_attr->cat_kms;
583 if (attr->cat_atime < lov_attr->cat_atime)
584 attr->cat_atime = lov_attr->cat_atime;
585 if (attr->cat_ctime < lov_attr->cat_ctime)
586 attr->cat_ctime = lov_attr->cat_ctime;
587 if (attr->cat_mtime < lov_attr->cat_mtime)
588 attr->cat_mtime = lov_attr->cat_mtime;
593 static int lov_find_cbdata_empty(const struct lu_env *env,
594 struct cl_object *obj, ldlm_iterator_t iter,
600 static int lov_find_cbdata_raid0(const struct lu_env *env,
601 struct cl_object *obj, ldlm_iterator_t iter,
604 struct lov_object *lov = cl2lov(obj);
605 struct lov_layout_raid0 *r0 = lov_r0(lov);
606 struct cl_object *subobj;
610 for (i = 0; i < r0->lo_nr; ++i) {
611 if (r0->lo_sub[i] == NULL)
614 subobj = lovsub2cl(r0->lo_sub[i]);
616 rc = cl_object_find_cbdata(env, subobj, iter, data);
624 const static struct lov_layout_operations lov_dispatch[] = {
626 .llo_init = lov_init_empty,
627 .llo_delete = lov_delete_empty,
628 .llo_fini = lov_fini_empty,
629 .llo_install = lov_install_empty,
630 .llo_print = lov_print_empty,
631 .llo_page_init = lov_page_init_empty,
632 .llo_lock_init = lov_lock_init_empty,
633 .llo_io_init = lov_io_init_empty,
634 .llo_getattr = lov_attr_get_empty,
635 .llo_find_cbdata = lov_find_cbdata_empty
638 .llo_init = lov_init_raid0,
639 .llo_delete = lov_delete_raid0,
640 .llo_fini = lov_fini_raid0,
641 .llo_install = lov_install_raid0,
642 .llo_print = lov_print_raid0,
643 .llo_page_init = lov_page_init_raid0,
644 .llo_lock_init = lov_lock_init_raid0,
645 .llo_io_init = lov_io_init_raid0,
646 .llo_getattr = lov_attr_get_raid0,
647 .llo_find_cbdata = lov_find_cbdata_raid0
650 .llo_init = lov_init_released,
651 .llo_delete = lov_delete_empty,
652 .llo_fini = lov_fini_released,
653 .llo_install = lov_install_empty,
654 .llo_print = lov_print_released,
655 .llo_page_init = lov_page_init_empty,
656 .llo_lock_init = lov_lock_init_empty,
657 .llo_io_init = lov_io_init_released,
658 .llo_getattr = lov_attr_get_empty,
659 .llo_find_cbdata = lov_find_cbdata_empty
664 * Performs a double-dispatch based on the layout type of an object.
666 #define LOV_2DISPATCH_NOLOCK(obj, op, ...) \
668 struct lov_object *__obj = (obj); \
669 enum lov_layout_type __llt; \
671 __llt = __obj->lo_type; \
672 LASSERT(0 <= __llt && __llt < ARRAY_SIZE(lov_dispatch)); \
673 lov_dispatch[__llt].op(__VA_ARGS__); \
677 * Return lov_layout_type associated with a given lsm
679 static enum lov_layout_type lov_type(struct lov_stripe_md *lsm)
683 if (lsm_is_released(lsm))
688 static inline void lov_conf_freeze(struct lov_object *lov)
690 if (lov->lo_owner != current)
691 down_read(&lov->lo_type_guard);
694 static inline void lov_conf_thaw(struct lov_object *lov)
696 if (lov->lo_owner != current)
697 up_read(&lov->lo_type_guard);
700 #define LOV_2DISPATCH_MAYLOCK(obj, op, lock, ...) \
702 struct lov_object *__obj = (obj); \
703 int __lock = !!(lock); \
704 typeof(lov_dispatch[0].op(__VA_ARGS__)) __result; \
707 lov_conf_freeze(__obj); \
708 __result = LOV_2DISPATCH_NOLOCK(obj, op, __VA_ARGS__); \
710 lov_conf_thaw(__obj); \
715 * Performs a locked double-dispatch based on the layout type of an object.
717 #define LOV_2DISPATCH(obj, op, ...) \
718 LOV_2DISPATCH_MAYLOCK(obj, op, 1, __VA_ARGS__)
720 #define LOV_2DISPATCH_VOID(obj, op, ...) \
722 struct lov_object *__obj = (obj); \
723 enum lov_layout_type __llt; \
725 lov_conf_freeze(__obj); \
726 __llt = __obj->lo_type; \
727 LASSERT(0 <= __llt && __llt < ARRAY_SIZE(lov_dispatch)); \
728 lov_dispatch[__llt].op(__VA_ARGS__); \
729 lov_conf_thaw(__obj); \
732 static void lov_conf_lock(struct lov_object *lov)
734 LASSERT(lov->lo_owner != current);
735 down_write(&lov->lo_type_guard);
736 LASSERT(lov->lo_owner == NULL);
737 lov->lo_owner = current;
740 static void lov_conf_unlock(struct lov_object *lov)
742 lov->lo_owner = NULL;
743 up_write(&lov->lo_type_guard);
746 static int lov_layout_wait(const struct lu_env *env, struct lov_object *lov)
748 struct l_wait_info lwi = { 0 };
751 while (atomic_read(&lov->lo_active_ios) > 0) {
752 CDEBUG(D_INODE, "file:"DFID" wait for active IO, now: %d.\n",
753 PFID(lu_object_fid(lov2lu(lov))),
754 atomic_read(&lov->lo_active_ios));
756 l_wait_event(lov->lo_waitq,
757 atomic_read(&lov->lo_active_ios) == 0, &lwi);
762 static int lov_layout_change(const struct lu_env *unused,
763 struct lov_object *lov,
764 const struct cl_object_conf *conf)
767 enum lov_layout_type llt = LLT_EMPTY;
768 union lov_layout_state *state = &lov->u;
769 const struct lov_layout_operations *old_ops;
770 const struct lov_layout_operations *new_ops;
777 LASSERT(0 <= lov->lo_type && lov->lo_type < ARRAY_SIZE(lov_dispatch));
779 if (conf->u.coc_md != NULL)
780 llt = lov_type(conf->u.coc_md->lsm);
781 LASSERT(0 <= llt && llt < ARRAY_SIZE(lov_dispatch));
783 cookie = cl_env_reenter();
784 env = cl_env_get(&refcheck);
786 cl_env_reexit(cookie);
787 RETURN(PTR_ERR(env));
790 CDEBUG(D_INODE, DFID" from %s to %s\n",
791 PFID(lu_object_fid(lov2lu(lov))),
792 llt2str(lov->lo_type), llt2str(llt));
794 old_ops = &lov_dispatch[lov->lo_type];
795 new_ops = &lov_dispatch[llt];
797 result = cl_object_prune(env, &lov->lo_cl);
801 result = old_ops->llo_delete(env, lov, &lov->u);
803 old_ops->llo_fini(env, lov, &lov->u);
805 LASSERT(atomic_read(&lov->lo_active_ios) == 0);
807 lov->lo_type = LLT_EMPTY;
808 /* page bufsize fixup */
809 cl_object_header(&lov->lo_cl)->coh_page_bufsize -=
810 lov_page_slice_fixup(lov, NULL);
812 result = new_ops->llo_init(env,
813 lu2lov_dev(lov->lo_cl.co_lu.lo_dev),
816 new_ops->llo_install(env, lov, state);
819 new_ops->llo_delete(env, lov, state);
820 new_ops->llo_fini(env, lov, state);
821 /* this file becomes an EMPTY file. */
826 cl_env_put(env, &refcheck);
827 cl_env_reexit(cookie);
831 /*****************************************************************************
833 * Lov object operations.
836 int lov_object_init(const struct lu_env *env, struct lu_object *obj,
837 const struct lu_object_conf *conf)
839 struct lov_device *dev = lu2lov_dev(obj->lo_dev);
840 struct lov_object *lov = lu2lov(obj);
841 const struct cl_object_conf *cconf = lu2cl_conf(conf);
842 union lov_layout_state *set = &lov->u;
843 const struct lov_layout_operations *ops;
847 init_rwsem(&lov->lo_type_guard);
848 atomic_set(&lov->lo_active_ios, 0);
849 init_waitqueue_head(&lov->lo_waitq);
851 cl_object_page_init(lu2cl(obj), sizeof(struct lov_page));
853 /* no locking is necessary, as object is being created */
854 lov->lo_type = lov_type(cconf->u.coc_md->lsm);
855 ops = &lov_dispatch[lov->lo_type];
856 result = ops->llo_init(env, dev, lov, cconf, set);
858 ops->llo_install(env, lov, set);
862 static int lov_conf_set(const struct lu_env *env, struct cl_object *obj,
863 const struct cl_object_conf *conf)
865 struct lov_stripe_md *lsm = NULL;
866 struct lov_object *lov = cl2lov(obj);
871 if (conf->coc_opc == OBJECT_CONF_INVALIDATE) {
872 lov->lo_layout_invalid = true;
873 GOTO(out, result = 0);
876 if (conf->coc_opc == OBJECT_CONF_WAIT) {
877 if (lov->lo_layout_invalid &&
878 atomic_read(&lov->lo_active_ios) > 0) {
879 lov_conf_unlock(lov);
880 result = lov_layout_wait(env, lov);
886 LASSERT(conf->coc_opc == OBJECT_CONF_SET);
888 if (conf->u.coc_md != NULL)
889 lsm = conf->u.coc_md->lsm;
890 if ((lsm == NULL && lov->lo_lsm == NULL) ||
891 ((lsm != NULL && lov->lo_lsm != NULL) &&
892 (lov->lo_lsm->lsm_layout_gen == lsm->lsm_layout_gen) &&
893 (lov->lo_lsm->lsm_pattern == lsm->lsm_pattern))) {
894 /* same version of layout */
895 lov->lo_layout_invalid = false;
896 GOTO(out, result = 0);
899 /* will change layout - check if there still exists active IO. */
900 if (atomic_read(&lov->lo_active_ios) > 0) {
901 lov->lo_layout_invalid = true;
902 GOTO(out, result = -EBUSY);
905 result = lov_layout_change(env, lov, conf);
906 lov->lo_layout_invalid = result != 0;
910 lov_conf_unlock(lov);
911 CDEBUG(D_INODE, DFID" lo_layout_invalid=%d\n",
912 PFID(lu_object_fid(lov2lu(lov))), lov->lo_layout_invalid);
916 static void lov_object_delete(const struct lu_env *env, struct lu_object *obj)
918 struct lov_object *lov = lu2lov(obj);
921 LOV_2DISPATCH_VOID(lov, llo_delete, env, lov, &lov->u);
925 static void lov_object_free(const struct lu_env *env, struct lu_object *obj)
927 struct lov_object *lov = lu2lov(obj);
930 LOV_2DISPATCH_VOID(lov, llo_fini, env, lov, &lov->u);
932 OBD_SLAB_FREE_PTR(lov, lov_object_kmem);
936 static int lov_object_print(const struct lu_env *env, void *cookie,
937 lu_printer_t p, const struct lu_object *o)
939 return LOV_2DISPATCH_NOLOCK(lu2lov(o), llo_print, env, cookie, p, o);
942 int lov_page_init(const struct lu_env *env, struct cl_object *obj,
943 struct cl_page *page, pgoff_t index)
945 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_page_init, env, obj, page,
950 * Implements cl_object_operations::clo_io_init() method for lov
951 * layer. Dispatches to the appropriate layout io initialization method.
953 int lov_io_init(const struct lu_env *env, struct cl_object *obj,
956 CL_IO_SLICE_CLEAN(lov_env_io(env), lis_cl);
957 return LOV_2DISPATCH_MAYLOCK(cl2lov(obj), llo_io_init,
958 !io->ci_ignore_layout, env, obj, io);
962 * An implementation of cl_object_operations::clo_attr_get() method for lov
963 * layer. For raid0 layout this collects and merges attributes of all
966 static int lov_attr_get(const struct lu_env *env, struct cl_object *obj,
967 struct cl_attr *attr)
969 /* do not take lock, as this function is called under a
970 * spin-lock. Layout is protected from changing by ongoing IO. */
971 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_getattr, env, obj, attr);
974 static int lov_attr_update(const struct lu_env *env, struct cl_object *obj,
975 const struct cl_attr *attr, unsigned valid)
978 * No dispatch is required here, as no layout implements this.
983 int lov_lock_init(const struct lu_env *env, struct cl_object *obj,
984 struct cl_lock *lock, const struct cl_io *io)
986 /* No need to lock because we've taken one refcount of layout. */
987 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_lock_init, env, obj, lock,
992 * We calculate on which OST the mapping will end. If the length of mapping
993 * is greater than (stripe_size * stripe_count) then the last_stripe will
994 * will be one just before start_stripe. Else we check if the mapping
995 * intersects each OST and find last_stripe.
996 * This function returns the last_stripe and also sets the stripe_count
997 * over which the mapping is spread
999 * \param lsm [in] striping information for the file
1000 * \param fm_start [in] logical start of mapping
1001 * \param fm_end [in] logical end of mapping
1002 * \param start_stripe [in] starting stripe of the mapping
1003 * \param stripe_count [out] the number of stripes across which to map is
1006 * \retval last_stripe return the last stripe of the mapping
1008 static int fiemap_calc_last_stripe(struct lov_stripe_md *lsm,
1009 loff_t fm_start, loff_t fm_end,
1010 int start_stripe, int *stripe_count)
1017 if (fm_end - fm_start > lsm->lsm_stripe_size * lsm->lsm_stripe_count) {
1018 last_stripe = (start_stripe < 1 ? lsm->lsm_stripe_count - 1 :
1020 *stripe_count = lsm->lsm_stripe_count;
1022 for (j = 0, i = start_stripe; j < lsm->lsm_stripe_count;
1023 i = (i + 1) % lsm->lsm_stripe_count, j++) {
1024 if ((lov_stripe_intersects(lsm, i, fm_start, fm_end,
1025 &obd_start, &obd_end)) == 0)
1029 last_stripe = (start_stripe + j - 1) % lsm->lsm_stripe_count;
1036 * Set fe_device and copy extents from local buffer into main return buffer.
1038 * \param fiemap [out] fiemap to hold all extents
1039 * \param lcl_fm_ext [in] array of fiemap extents get from OSC layer
1040 * \param ost_index [in] OST index to be written into the fm_device
1041 * field for each extent
1042 * \param ext_count [in] number of extents to be copied
1043 * \param current_extent [in] where to start copying in the extent array
1045 static void fiemap_prepare_and_copy_exts(struct fiemap *fiemap,
1046 struct ll_fiemap_extent *lcl_fm_ext,
1047 int ost_index, unsigned int ext_count,
1053 for (ext = 0; ext < ext_count; ext++) {
1054 lcl_fm_ext[ext].fe_device = ost_index;
1055 lcl_fm_ext[ext].fe_flags |= FIEMAP_EXTENT_NET;
1058 /* Copy fm_extent's from fm_local to return buffer */
1059 to = (char *)fiemap + fiemap_count_to_size(current_extent);
1060 memcpy(to, lcl_fm_ext, ext_count * sizeof(struct ll_fiemap_extent));
1063 #define FIEMAP_BUFFER_SIZE 4096
1066 * Non-zero fe_logical indicates that this is a continuation FIEMAP
1067 * call. The local end offset and the device are sent in the first
1068 * fm_extent. This function calculates the stripe number from the index.
1069 * This function returns a stripe_no on which mapping is to be restarted.
1071 * This function returns fm_end_offset which is the in-OST offset at which
1072 * mapping should be restarted. If fm_end_offset=0 is returned then caller
1073 * will re-calculate proper offset in next stripe.
1074 * Note that the first extent is passed to lov_get_info via the value field.
1076 * \param fiemap [in] fiemap request header
1077 * \param lsm [in] striping information for the file
1078 * \param fm_start [in] logical start of mapping
1079 * \param fm_end [in] logical end of mapping
1080 * \param start_stripe [out] starting stripe will be returned in this
1082 static loff_t fiemap_calc_fm_end_offset(struct fiemap *fiemap,
1083 struct lov_stripe_md *lsm,
1084 loff_t fm_start, loff_t fm_end,
1087 loff_t local_end = fiemap->fm_extents[0].fe_logical;
1090 loff_t fm_end_offset;
1094 if (fiemap->fm_extent_count == 0 ||
1095 fiemap->fm_extents[0].fe_logical == 0)
1098 /* Find out stripe_no from ost_index saved in the fe_device */
1099 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1100 struct lov_oinfo *oinfo = lsm->lsm_oinfo[i];
1102 if (lov_oinfo_is_dummy(oinfo))
1105 if (oinfo->loi_ost_idx == fiemap->fm_extents[0].fe_device) {
1111 if (stripe_no == -1)
1114 /* If we have finished mapping on previous device, shift logical
1115 * offset to start of next device */
1116 if (lov_stripe_intersects(lsm, stripe_no, fm_start, fm_end,
1117 &lun_start, &lun_end) != 0 &&
1118 local_end < lun_end) {
1119 fm_end_offset = local_end;
1120 *start_stripe = stripe_no;
1122 /* This is a special value to indicate that caller should
1123 * calculate offset in next stripe. */
1125 *start_stripe = (stripe_no + 1) % lsm->lsm_stripe_count;
1128 return fm_end_offset;
1132 * Break down the FIEMAP request and send appropriate calls to individual OSTs.
1133 * This also handles the restarting of FIEMAP calls in case mapping overflows
1134 * the available number of extents in single call.
1136 * \param env [in] lustre environment
1137 * \param obj [in] file object
1138 * \param fmkey [in] fiemap request header and other info
1139 * \param fiemap [out] fiemap buffer holding retrived map extents
1140 * \param buflen [in/out] max buffer length of @fiemap, when iterate
1141 * each OST, it is used to limit max map needed
1145 static int lov_object_fiemap(const struct lu_env *env, struct cl_object *obj,
1146 struct ll_fiemap_info_key *fmkey,
1147 struct fiemap *fiemap, size_t *buflen)
1149 struct lov_stripe_md *lsm;
1150 struct cl_object *subobj = NULL;
1151 struct lov_obd *lov = lu2lov_dev(obj->co_lu.lo_dev)->ld_lov;
1152 struct fiemap *fm_local = NULL;
1153 struct ll_fiemap_extent *lcl_fm_ext;
1157 loff_t fm_end_offset;
1161 int current_extent = 0;
1165 int cur_stripe_wrap = 0;
1167 unsigned int buffer_size = FIEMAP_BUFFER_SIZE;
1168 /* Whether have we collected enough extents */
1169 bool enough = false;
1170 /* EOF for object */
1171 bool ost_eof = false;
1172 /* done with required mapping for this OST? */
1173 bool ost_done = false;
1176 lsm = lov_lsm_addref(cl2lov(obj));
1181 * If the stripe_count > 1 and the application does not understand
1182 * DEVICE_ORDER flag, it cannot interpret the extents correctly.
1184 if (lsm->lsm_stripe_count > 1 && !(fiemap->fm_flags &
1185 FIEMAP_FLAG_DEVICE_ORDER))
1186 GOTO(out, rc = -ENOTSUPP);
1188 if (lsm_is_released(lsm)) {
1189 if (fiemap->fm_start < fmkey->oa.o_size) {
1191 * released file, return a minimal FIEMAP if
1192 * request fits in file-size.
1194 fiemap->fm_mapped_extents = 1;
1195 fiemap->fm_extents[0].fe_logical = fiemap->fm_start;
1196 if (fiemap->fm_start + fiemap->fm_length <
1198 fiemap->fm_extents[0].fe_length =
1201 fiemap->fm_extents[0].fe_length =
1202 fmkey->oa.o_size - fiemap->fm_start;
1203 fiemap->fm_extents[0].fe_flags |=
1204 FIEMAP_EXTENT_UNKNOWN | FIEMAP_EXTENT_LAST;
1209 if (fiemap_count_to_size(fiemap->fm_extent_count) < buffer_size)
1210 buffer_size = fiemap_count_to_size(fiemap->fm_extent_count);
1212 OBD_ALLOC_LARGE(fm_local, buffer_size);
1213 if (fm_local == NULL)
1214 GOTO(out, rc = -ENOMEM);
1215 lcl_fm_ext = &fm_local->fm_extents[0];
1216 count_local = fiemap_size_to_count(buffer_size);
1218 fm_start = fiemap->fm_start;
1219 fm_length = fiemap->fm_length;
1220 /* Calculate start stripe, last stripe and length of mapping */
1221 start_stripe = lov_stripe_number(lsm, fm_start);
1222 fm_end = (fm_length == ~0ULL) ? fmkey->oa.o_size :
1223 fm_start + fm_length - 1;
1224 /* If fm_length != ~0ULL but fm_start_fm_length-1 exceeds file size */
1225 if (fm_end > fmkey->oa.o_size)
1226 fm_end = fmkey->oa.o_size;
1228 last_stripe = fiemap_calc_last_stripe(lsm, fm_start, fm_end,
1229 start_stripe, &stripe_count);
1230 fm_end_offset = fiemap_calc_fm_end_offset(fiemap, lsm, fm_start, fm_end,
1232 if (fm_end_offset == -EINVAL)
1233 GOTO(out, rc = -EINVAL);
1236 * Requested extent count exceeds the fiemap buffer size, shrink our
1239 if (fiemap_count_to_size(fiemap->fm_extent_count) > *buflen)
1240 fiemap->fm_extent_count = fiemap_size_to_count(*buflen);
1241 if (fiemap->fm_extent_count == 0)
1244 /* Check each stripe */
1245 for (cur_stripe = start_stripe; stripe_count > 0;
1247 cur_stripe = (cur_stripe + 1) % lsm->lsm_stripe_count) {
1248 loff_t req_fm_len; /* Stores length of required mapping */
1249 loff_t len_mapped_single_call;
1252 loff_t obd_object_end;
1253 unsigned int ext_count;
1255 cur_stripe_wrap = cur_stripe;
1257 /* Find out range of mapping on this stripe */
1258 if ((lov_stripe_intersects(lsm, cur_stripe, fm_start, fm_end,
1259 &lun_start, &obd_object_end)) == 0)
1262 if (lov_oinfo_is_dummy(lsm->lsm_oinfo[cur_stripe]))
1263 GOTO(out, rc = -EIO);
1265 /* If this is a continuation FIEMAP call and we are on
1266 * starting stripe then lun_start needs to be set to
1268 if (fm_end_offset != 0 && cur_stripe == start_stripe)
1269 lun_start = fm_end_offset;
1271 if (fm_length != ~0ULL) {
1272 /* Handle fm_start + fm_length overflow */
1273 if (fm_start + fm_length < fm_start)
1274 fm_length = ~0ULL - fm_start;
1275 lun_end = lov_size_to_stripe(lsm, fm_start + fm_length,
1281 if (lun_start == lun_end)
1284 req_fm_len = obd_object_end - lun_start;
1285 fm_local->fm_length = 0;
1286 len_mapped_single_call = 0;
1288 /* find lobsub object */
1289 subobj = lov_find_subobj(env, cl2lov(obj), lsm,
1292 GOTO(out, rc = PTR_ERR(subobj));
1293 /* If the output buffer is very large and the objects have many
1294 * extents we may need to loop on a single OST repeatedly */
1298 if (fiemap->fm_extent_count > 0) {
1299 /* Don't get too many extents. */
1300 if (current_extent + count_local >
1301 fiemap->fm_extent_count)
1302 count_local = fiemap->fm_extent_count -
1306 lun_start += len_mapped_single_call;
1307 fm_local->fm_length = req_fm_len -
1308 len_mapped_single_call;
1309 req_fm_len = fm_local->fm_length;
1310 fm_local->fm_extent_count = enough ? 1 : count_local;
1311 fm_local->fm_mapped_extents = 0;
1312 fm_local->fm_flags = fiemap->fm_flags;
1314 ost_index = lsm->lsm_oinfo[cur_stripe]->loi_ost_idx;
1316 if (ost_index < 0 ||
1317 ost_index >= lov->desc.ld_tgt_count)
1318 GOTO(obj_put, rc = -EINVAL);
1319 /* If OST is inactive, return extent with UNKNOWN
1321 if (!lov->lov_tgts[ost_index]->ltd_active) {
1322 fm_local->fm_flags |= FIEMAP_EXTENT_LAST;
1323 fm_local->fm_mapped_extents = 1;
1325 lcl_fm_ext[0].fe_logical = lun_start;
1326 lcl_fm_ext[0].fe_length = obd_object_end -
1328 lcl_fm_ext[0].fe_flags |= FIEMAP_EXTENT_UNKNOWN;
1333 fm_local->fm_start = lun_start;
1334 fm_local->fm_flags &= ~FIEMAP_FLAG_DEVICE_ORDER;
1335 memcpy(&fmkey->fiemap, fm_local, sizeof(*fm_local));
1336 *buflen = fiemap_count_to_size(
1337 fm_local->fm_extent_count);
1339 rc = cl_object_fiemap(env, subobj, fmkey, fm_local,
1344 ext_count = fm_local->fm_mapped_extents;
1345 if (ext_count == 0) {
1347 /* If last stripe has hold at the end,
1348 * we need to return */
1349 if (cur_stripe_wrap == last_stripe) {
1350 fiemap->fm_mapped_extents = 0;
1354 } else if (enough) {
1356 * We've collected enough extents and there are
1357 * more extents after it.
1362 /* If we just need num of extents, got to next device */
1363 if (fiemap->fm_extent_count == 0) {
1364 current_extent += ext_count;
1368 /* prepare to copy retrived map extents */
1369 len_mapped_single_call =
1370 lcl_fm_ext[ext_count - 1].fe_logical -
1371 lun_start + lcl_fm_ext[ext_count - 1].fe_length;
1373 /* Have we finished mapping on this device? */
1374 if (req_fm_len <= len_mapped_single_call)
1377 /* Clear the EXTENT_LAST flag which can be present on
1378 * the last extent */
1379 if (lcl_fm_ext[ext_count - 1].fe_flags &
1381 lcl_fm_ext[ext_count - 1].fe_flags &=
1382 ~FIEMAP_EXTENT_LAST;
1383 if (lov_stripe_size(lsm,
1384 lcl_fm_ext[ext_count - 1].fe_logical +
1385 lcl_fm_ext[ext_count - 1].fe_length,
1386 cur_stripe) >= fmkey->oa.o_size)
1389 fiemap_prepare_and_copy_exts(fiemap, lcl_fm_ext,
1390 ost_index, ext_count,
1392 current_extent += ext_count;
1394 /* Ran out of available extents? */
1395 if (current_extent >= fiemap->fm_extent_count)
1397 } while (!ost_done && !ost_eof);
1399 cl_object_put(env, subobj);
1402 if (cur_stripe_wrap == last_stripe)
1404 } /* for each stripe */
1406 /* Indicate that we are returning device offsets unless file just has
1408 if (lsm->lsm_stripe_count > 1)
1409 fiemap->fm_flags |= FIEMAP_FLAG_DEVICE_ORDER;
1411 if (fiemap->fm_extent_count == 0)
1412 goto skip_last_device_calc;
1414 /* Check if we have reached the last stripe and whether mapping for that
1415 * stripe is done. */
1416 if ((cur_stripe_wrap == last_stripe) && (ost_done || ost_eof))
1417 fiemap->fm_extents[current_extent - 1].fe_flags |=
1419 skip_last_device_calc:
1420 fiemap->fm_mapped_extents = current_extent;
1423 cl_object_put(env, subobj);
1425 if (fm_local != NULL)
1426 OBD_FREE_LARGE(fm_local, buffer_size);
1433 static int lov_dispatch_obd_info_get(const struct lu_env *env,
1434 struct cl_object *obj,
1435 struct obd_info *oinfo,
1436 struct ptlrpc_request_set *set)
1438 struct cl_object *subobj = NULL;
1439 struct lov_obd *lov = lu2lov_dev(obj->co_lu.lo_dev)->ld_lov;
1440 struct lov_request_set *lovset;
1441 struct list_head *pos;
1442 struct lov_request *req;
1447 rc = lov_prep_getattr_set(lov2obd(lov)->obd_self_export, oinfo,
1452 CDEBUG(D_INFO, "objid "DOSTID": %ux%u byte stripes.\n",
1453 POSTID(&oinfo->oi_md->lsm_oi),
1454 oinfo->oi_md->lsm_stripe_count,
1455 oinfo->oi_md->lsm_stripe_size);
1457 list_for_each(pos, &lovset->set_list) {
1458 req = list_entry(pos, struct lov_request, rq_link);
1460 CDEBUG(D_INFO, "objid "DOSTID"[%d] has subobj "DOSTID" at idx"
1461 "%u\n", POSTID(&oinfo->oi_oa->o_oi), req->rq_stripe,
1462 POSTID(&req->rq_oi.oi_oa->o_oi), req->rq_idx);
1463 subobj = lov_find_subobj(env, cl2lov(obj), oinfo->oi_md,
1466 GOTO(errout, rc = PTR_ERR(subobj));
1468 rc = cl_object_obd_info_get(env, subobj, &req->rq_oi, set);
1469 cl_object_put(env, subobj);
1471 CERROR("%s: getattr objid "DOSTID" subobj"
1472 DOSTID" on OST idx %d: rc = %d\n",
1473 lov2obd(lov)->obd_name,
1474 POSTID(&oinfo->oi_oa->o_oi),
1475 POSTID(&req->rq_oi.oi_oa->o_oi),
1481 if (!list_empty(&set->set_requests)) {
1483 LASSERT(set->set_interpret == NULL);
1484 set->set_interpret = lov_getattr_interpret;
1485 set->set_arg = lovset;
1490 atomic_set(&lovset->set_completes, 0);
1491 rc2 = lov_fini_getattr_set(lovset);
1492 rc = rc != 0 ? rc : rc2;
1497 static int lov_object_data_version(const struct lu_env *env,
1498 struct cl_object *obj, __u64 *data_version,
1501 struct ptlrpc_request_set *set;
1502 struct obd_info oinfo = { { { 0 } } };
1503 struct obdo *obdo = NULL;
1504 struct lov_stripe_md *lsm;
1508 lsm = lov_lsm_addref(cl2lov(obj));
1509 if (!lsm_has_objects(lsm)) {
1510 /* If no stripe, we consider version is 0. */
1515 OBD_ALLOC_PTR(obdo);
1517 GOTO(out, rc = -ENOMEM);
1521 obdo->o_oi = lsm->lsm_oi;
1522 obdo->o_mode = S_IFREG;
1523 obdo->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP | OBD_MD_FLTYPE;
1524 if (flags & (LL_DV_RD_FLUSH | LL_DV_WR_FLUSH)) {
1525 obdo->o_valid |= OBD_MD_FLFLAGS;
1526 obdo->o_flags |= OBD_FL_SRVLOCK;
1527 if (flags & LL_DV_WR_FLUSH)
1528 obdo->o_flags |= OBD_FL_FLUSH;
1531 set = ptlrpc_prep_set();
1533 GOTO(out_obdo, rc = -ENOMEM);
1535 rc = lov_dispatch_obd_info_get(env, obj, &oinfo, set);
1537 rc = ptlrpc_set_wait(set);
1538 ptlrpc_set_destroy(set);
1540 oinfo.oi_oa->o_valid &= OBD_MD_FLDATAVERSION | OBD_MD_FLFLAGS;
1541 if (flags & LL_DV_WR_FLUSH &&
1542 !(oinfo.oi_oa->o_valid & OBD_MD_FLFLAGS &&
1543 oinfo.oi_oa->o_flags & OBD_FL_FLUSH))
1545 else if (!(obdo->o_valid & OBD_MD_FLDATAVERSION))
1548 *data_version = obdo->o_data_version;
1557 static int lov_object_getstripe(const struct lu_env *env, struct cl_object *obj,
1558 struct lov_user_md __user *lum)
1560 struct lov_object *lov = cl2lov(obj);
1561 struct lov_stripe_md *lsm;
1565 lsm = lov_lsm_addref(lov);
1569 rc = lov_getstripe(cl2lov(obj), lsm, lum);
1574 static int lov_object_layout_get(const struct lu_env *env,
1575 struct cl_object *obj,
1576 struct cl_layout *cl)
1578 struct lov_object *lov = cl2lov(obj);
1579 struct lov_stripe_md *lsm = lov_lsm_addref(lov);
1580 struct lu_buf *buf = &cl->cl_buf;
1586 cl->cl_layout_gen = CL_LAYOUT_GEN_EMPTY;
1587 cl->cl_is_released = false;
1592 cl->cl_size = lov_mds_md_size(lsm->lsm_stripe_count, lsm->lsm_magic);
1593 cl->cl_layout_gen = lsm->lsm_layout_gen;
1594 cl->cl_is_released = lsm_is_released(lsm);
1596 rc = lov_lsm_pack(lsm, buf->lb_buf, buf->lb_len);
1599 RETURN(rc < 0 ? rc : 0);
1602 static int lov_object_find_cbdata(const struct lu_env *env,
1603 struct cl_object *obj, ldlm_iterator_t iter,
1609 /* call cl_object_find_cbdata for sub obj */
1610 rc = LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_find_cbdata,
1611 env, obj, iter, data);
1615 static const struct cl_object_operations lov_ops = {
1616 .coo_page_init = lov_page_init,
1617 .coo_lock_init = lov_lock_init,
1618 .coo_io_init = lov_io_init,
1619 .coo_attr_get = lov_attr_get,
1620 .coo_attr_update = lov_attr_update,
1621 .coo_conf_set = lov_conf_set,
1622 .coo_getstripe = lov_object_getstripe,
1623 .coo_layout_get = lov_object_layout_get,
1624 .coo_find_cbdata = lov_object_find_cbdata,
1625 .coo_fiemap = lov_object_fiemap,
1626 .coo_data_version = lov_object_data_version,
1629 static const struct lu_object_operations lov_lu_obj_ops = {
1630 .loo_object_init = lov_object_init,
1631 .loo_object_delete = lov_object_delete,
1632 .loo_object_release = NULL,
1633 .loo_object_free = lov_object_free,
1634 .loo_object_print = lov_object_print,
1635 .loo_object_invariant = NULL
1638 struct lu_object *lov_object_alloc(const struct lu_env *env,
1639 const struct lu_object_header *unused,
1640 struct lu_device *dev)
1642 struct lov_object *lov;
1643 struct lu_object *obj;
1646 OBD_SLAB_ALLOC_PTR_GFP(lov, lov_object_kmem, GFP_NOFS);
1649 lu_object_init(obj, NULL, dev);
1650 lov->lo_cl.co_ops = &lov_ops;
1651 lov->lo_type = -1; /* invalid, to catch uninitialized type */
1653 * object io operation vector (cl_object::co_iop) is installed
1654 * later in lov_object_init(), as different vectors are used
1655 * for object with different layouts.
1657 obj->lo_ops = &lov_lu_obj_ops;
1663 struct lov_stripe_md *lov_lsm_addref(struct lov_object *lov)
1665 struct lov_stripe_md *lsm = NULL;
1667 lov_conf_freeze(lov);
1668 if (lov->lo_lsm != NULL) {
1669 lsm = lsm_addref(lov->lo_lsm);
1670 CDEBUG(D_INODE, "lsm %p addref %d/%d by %p.\n",
1671 lsm, atomic_read(&lsm->lsm_refc),
1672 lov->lo_layout_invalid, current);
1678 int lov_read_and_clear_async_rc(struct cl_object *clob)
1680 struct lu_object *luobj;
1684 luobj = lu_object_locate(&cl_object_header(clob)->coh_lu,
1686 if (luobj != NULL) {
1687 struct lov_object *lov = lu2lov(luobj);
1689 lov_conf_freeze(lov);
1690 switch (lov->lo_type) {
1692 struct lov_stripe_md *lsm;
1696 LASSERT(lsm != NULL);
1697 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1698 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
1700 if (lov_oinfo_is_dummy(loi))
1703 if (loi->loi_ar.ar_rc && !rc)
1704 rc = loi->loi_ar.ar_rc;
1705 loi->loi_ar.ar_rc = 0;
1718 EXPORT_SYMBOL(lov_read_and_clear_async_rc);