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, 2015, 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"
46 static inline struct lov_device *lov_object_dev(struct lov_object *obj)
48 return lu2lov_dev(obj->lo_cl.co_lu.lo_dev);
55 /*****************************************************************************
61 struct lov_layout_operations {
62 int (*llo_init)(const struct lu_env *env, struct lov_device *dev,
63 struct lov_object *lov, struct lov_stripe_md *lsm,
64 const struct cl_object_conf *conf,
65 union lov_layout_state *state);
66 int (*llo_delete)(const struct lu_env *env, struct lov_object *lov,
67 union lov_layout_state *state);
68 void (*llo_fini)(const struct lu_env *env, struct lov_object *lov,
69 union lov_layout_state *state);
70 void (*llo_install)(const struct lu_env *env, struct lov_object *lov,
71 union lov_layout_state *state);
72 int (*llo_print)(const struct lu_env *env, void *cookie,
73 lu_printer_t p, const struct lu_object *o);
74 int (*llo_page_init)(const struct lu_env *env, struct cl_object *obj,
75 struct cl_page *page, pgoff_t index);
76 int (*llo_lock_init)(const struct lu_env *env,
77 struct cl_object *obj, struct cl_lock *lock,
78 const struct cl_io *io);
79 int (*llo_io_init)(const struct lu_env *env,
80 struct cl_object *obj, struct cl_io *io);
81 int (*llo_getattr)(const struct lu_env *env, struct cl_object *obj,
82 struct cl_attr *attr);
85 static int lov_layout_wait(const struct lu_env *env, struct lov_object *lov);
87 static void lov_lsm_put(struct lov_stripe_md *lsm)
93 /*****************************************************************************
95 * Lov object layout operations.
99 static void lov_install_empty(const struct lu_env *env,
100 struct lov_object *lov,
101 union lov_layout_state *state)
104 * File without objects.
108 static int lov_init_empty(const struct lu_env *env, struct lov_device *dev,
109 struct lov_object *lov, struct lov_stripe_md *lsm,
110 const struct cl_object_conf *conf,
111 union lov_layout_state *state)
116 static void lov_install_raid0(const struct lu_env *env,
117 struct lov_object *lov,
118 union lov_layout_state *state)
122 static struct cl_object *lov_sub_find(const struct lu_env *env,
123 struct cl_device *dev,
124 const struct lu_fid *fid,
125 const struct cl_object_conf *conf)
130 o = lu_object_find_at(env, cl2lu_dev(dev), fid, &conf->coc_lu);
131 LASSERT(ergo(!IS_ERR(o), o->lo_dev->ld_type == &lovsub_device_type));
135 static int lov_init_sub(const struct lu_env *env, struct lov_object *lov,
136 struct cl_object *stripe, struct lov_layout_raid0 *r0,
139 struct cl_object_header *hdr;
140 struct cl_object_header *subhdr;
141 struct cl_object_header *parent;
142 struct lov_oinfo *oinfo;
145 if (OBD_FAIL_CHECK(OBD_FAIL_LOV_INIT)) {
146 /* For sanity:test_206.
147 * Do not leave the object in cache to avoid accessing
148 * freed memory. This is because osc_object is referring to
149 * lov_oinfo of lsm_stripe_data which will be freed due to
151 cl_object_kill(env, stripe);
152 cl_object_put(env, stripe);
156 hdr = cl_object_header(lov2cl(lov));
157 subhdr = cl_object_header(stripe);
159 oinfo = lov->lo_lsm->lsm_oinfo[idx];
160 CDEBUG(D_INODE, DFID"@%p[%d] -> "DFID"@%p: ostid: "DOSTID
161 " idx: %d gen: %d\n",
162 PFID(&subhdr->coh_lu.loh_fid), subhdr, idx,
163 PFID(&hdr->coh_lu.loh_fid), hdr, POSTID(&oinfo->loi_oi),
164 oinfo->loi_ost_idx, oinfo->loi_ost_gen);
166 /* reuse ->coh_attr_guard to protect coh_parent change */
167 spin_lock(&subhdr->coh_attr_guard);
168 parent = subhdr->coh_parent;
169 if (parent == NULL) {
170 subhdr->coh_parent = hdr;
171 spin_unlock(&subhdr->coh_attr_guard);
172 subhdr->coh_nesting = hdr->coh_nesting + 1;
173 lu_object_ref_add(&stripe->co_lu, "lov-parent", lov);
174 r0->lo_sub[idx] = cl2lovsub(stripe);
175 r0->lo_sub[idx]->lso_super = lov;
176 r0->lo_sub[idx]->lso_index = idx;
179 struct lu_object *old_obj;
180 struct lov_object *old_lov;
181 unsigned int mask = D_INODE;
183 spin_unlock(&subhdr->coh_attr_guard);
184 old_obj = lu_object_locate(&parent->coh_lu, &lov_device_type);
185 LASSERT(old_obj != NULL);
186 old_lov = cl2lov(lu2cl(old_obj));
187 if (old_lov->lo_layout_invalid) {
188 /* the object's layout has already changed but isn't
190 lu_object_unhash(env, &stripe->co_lu);
197 LU_OBJECT_DEBUG(mask, env, &stripe->co_lu,
198 "stripe %d is already owned.", idx);
199 LU_OBJECT_DEBUG(mask, env, old_obj, "owned.");
200 LU_OBJECT_HEADER(mask, env, lov2lu(lov), "try to own.\n");
201 cl_object_put(env, stripe);
206 static int lov_page_slice_fixup(struct lov_object *lov,
207 struct cl_object *stripe)
209 struct cl_object_header *hdr = cl_object_header(&lov->lo_cl);
213 return hdr->coh_page_bufsize - lov->lo_cl.co_slice_off -
214 cfs_size_round(sizeof(struct lov_page));
216 cl_object_for_each(o, stripe)
217 o->co_slice_off += hdr->coh_page_bufsize;
219 return cl_object_header(stripe)->coh_page_bufsize;
222 static int lov_init_raid0(const struct lu_env *env, struct lov_device *dev,
223 struct lov_object *lov, struct lov_stripe_md *lsm,
224 const struct cl_object_conf *conf,
225 union lov_layout_state *state)
230 struct cl_object *stripe;
231 struct lov_thread_info *lti = lov_env_info(env);
232 struct cl_object_conf *subconf = <i->lti_stripe_conf;
233 struct lu_fid *ofid = <i->lti_fid;
234 struct lov_layout_raid0 *r0 = &state->raid0;
238 if (lsm->lsm_magic != LOV_MAGIC_V1 && lsm->lsm_magic != LOV_MAGIC_V3) {
239 dump_lsm(D_ERROR, lsm);
240 LASSERTF(0, "magic mismatch, expected %d/%d, actual %d.\n",
241 LOV_MAGIC_V1, LOV_MAGIC_V3, lsm->lsm_magic);
244 LASSERT(lov->lo_lsm == NULL);
245 lov->lo_lsm = lsm_addref(lsm);
246 r0->lo_nr = lsm->lsm_stripe_count;
247 LASSERT(r0->lo_nr <= lov_targets_nr(dev));
249 lov->lo_layout_invalid = true;
251 OBD_ALLOC_LARGE(r0->lo_sub, r0->lo_nr * sizeof r0->lo_sub[0]);
252 if (r0->lo_sub != NULL) {
256 subconf->coc_inode = conf->coc_inode;
257 spin_lock_init(&r0->lo_sub_lock);
259 * Create stripe cl_objects.
261 for (i = 0; i < r0->lo_nr && result == 0; ++i) {
262 struct cl_device *subdev;
263 struct lov_oinfo *oinfo = lsm->lsm_oinfo[i];
264 int ost_idx = oinfo->loi_ost_idx;
266 if (lov_oinfo_is_dummy(oinfo))
269 result = ostid_to_fid(ofid, &oinfo->loi_oi,
274 if (dev->ld_target[ost_idx] == NULL) {
275 CERROR("%s: OST %04x is not initialized\n",
276 lov2obd(dev->ld_lov)->obd_name, ost_idx);
277 GOTO(out, result = -EIO);
280 subdev = lovsub2cl_dev(dev->ld_target[ost_idx]);
281 subconf->u.coc_oinfo = oinfo;
282 LASSERTF(subdev != NULL, "not init ost %d\n", ost_idx);
283 /* In the function below, .hs_keycmp resolves to
284 * lu_obj_hop_keycmp() */
285 /* coverity[overrun-buffer-val] */
286 stripe = lov_sub_find(env, subdev, ofid, subconf);
287 if (!IS_ERR(stripe)) {
288 result = lov_init_sub(env, lov, stripe, r0, i);
289 if (result == -EAGAIN) { /* try again */
295 result = PTR_ERR(stripe);
299 int sz = lov_page_slice_fixup(lov, stripe);
300 LASSERT(ergo(psz > 0, psz == sz));
305 cl_object_header(&lov->lo_cl)->coh_page_bufsize += psz;
312 static int lov_init_released(const struct lu_env *env,
313 struct lov_device *dev, struct lov_object *lov,
314 struct lov_stripe_md *lsm,
315 const struct cl_object_conf *conf,
316 union lov_layout_state *state)
318 LASSERT(lsm != NULL);
319 LASSERT(lsm_is_released(lsm));
320 LASSERT(lov->lo_lsm == NULL);
322 lov->lo_lsm = lsm_addref(lsm);
326 static struct cl_object *lov_find_subobj(const struct lu_env *env,
327 struct lov_object *lov,
328 struct lov_stripe_md *lsm,
331 struct lov_device *dev = lu2lov_dev(lov2lu(lov)->lo_dev);
332 struct lov_oinfo *oinfo = lsm->lsm_oinfo[stripe_idx];
333 struct lov_thread_info *lti = lov_env_info(env);
334 struct lu_fid *ofid = <i->lti_fid;
335 struct cl_device *subdev;
338 struct cl_object *result;
340 if (lov->lo_type != LLT_RAID0)
341 GOTO(out, result = NULL);
343 ost_idx = oinfo->loi_ost_idx;
344 rc = ostid_to_fid(ofid, &oinfo->loi_oi, ost_idx);
346 GOTO(out, result = NULL);
348 subdev = lovsub2cl_dev(dev->ld_target[ost_idx]);
349 result = lov_sub_find(env, subdev, ofid, NULL);
352 result = ERR_PTR(-EINVAL);
356 static int lov_delete_empty(const struct lu_env *env, struct lov_object *lov,
357 union lov_layout_state *state)
359 LASSERT(lov->lo_type == LLT_EMPTY || lov->lo_type == LLT_RELEASED);
361 lov_layout_wait(env, lov);
365 static void lov_subobject_kill(const struct lu_env *env, struct lov_object *lov,
366 struct lovsub_object *los, int idx)
368 struct cl_object *sub;
369 struct lov_layout_raid0 *r0;
370 struct lu_site *site;
371 struct lu_site_bkt_data *bkt;
372 wait_queue_t *waiter;
375 LASSERT(r0->lo_sub[idx] == los);
377 sub = lovsub2cl(los);
378 site = sub->co_lu.lo_dev->ld_site;
379 bkt = lu_site_bkt_from_fid(site, &sub->co_lu.lo_header->loh_fid);
381 cl_object_kill(env, sub);
382 /* release a reference to the sub-object and ... */
383 lu_object_ref_del(&sub->co_lu, "lov-parent", lov);
384 cl_object_put(env, sub);
386 /* ... wait until it is actually destroyed---sub-object clears its
387 * ->lo_sub[] slot in lovsub_object_fini() */
388 if (r0->lo_sub[idx] == los) {
389 waiter = &lov_env_info(env)->lti_waiter;
390 init_waitqueue_entry(waiter, current);
391 add_wait_queue(&bkt->lsb_marche_funebre, waiter);
392 set_current_state(TASK_UNINTERRUPTIBLE);
394 /* this wait-queue is signaled at the end of
395 * lu_object_free(). */
396 set_current_state(TASK_UNINTERRUPTIBLE);
397 spin_lock(&r0->lo_sub_lock);
398 if (r0->lo_sub[idx] == los) {
399 spin_unlock(&r0->lo_sub_lock);
402 spin_unlock(&r0->lo_sub_lock);
403 set_current_state(TASK_RUNNING);
407 remove_wait_queue(&bkt->lsb_marche_funebre, waiter);
409 LASSERT(r0->lo_sub[idx] == NULL);
412 static int lov_delete_raid0(const struct lu_env *env, struct lov_object *lov,
413 union lov_layout_state *state)
415 struct lov_layout_raid0 *r0 = &state->raid0;
416 struct lov_stripe_md *lsm = lov->lo_lsm;
421 dump_lsm(D_INODE, lsm);
423 lov_layout_wait(env, lov);
424 if (r0->lo_sub != NULL) {
425 for (i = 0; i < r0->lo_nr; ++i) {
426 struct lovsub_object *los = r0->lo_sub[i];
429 cl_object_prune(env, &los->lso_cl);
431 * If top-level object is to be evicted from
432 * the cache, so are its sub-objects.
434 lov_subobject_kill(env, lov, los, i);
441 static void lov_fini_empty(const struct lu_env *env, struct lov_object *lov,
442 union lov_layout_state *state)
444 LASSERT(lov->lo_type == LLT_EMPTY || lov->lo_type == LLT_RELEASED);
447 static void lov_fini_raid0(const struct lu_env *env, struct lov_object *lov,
448 union lov_layout_state *state)
450 struct lov_layout_raid0 *r0 = &state->raid0;
453 if (r0->lo_sub != NULL) {
454 OBD_FREE_LARGE(r0->lo_sub, r0->lo_nr * sizeof r0->lo_sub[0]);
458 dump_lsm(D_INODE, lov->lo_lsm);
459 lov_free_memmd(&lov->lo_lsm);
464 static void lov_fini_released(const struct lu_env *env, struct lov_object *lov,
465 union lov_layout_state *state)
468 dump_lsm(D_INODE, lov->lo_lsm);
469 lov_free_memmd(&lov->lo_lsm);
473 static int lov_print_empty(const struct lu_env *env, void *cookie,
474 lu_printer_t p, const struct lu_object *o)
476 (*p)(env, cookie, "empty %d\n", lu2lov(o)->lo_layout_invalid);
480 static int lov_print_raid0(const struct lu_env *env, void *cookie,
481 lu_printer_t p, const struct lu_object *o)
483 struct lov_object *lov = lu2lov(o);
484 struct lov_layout_raid0 *r0 = lov_r0(lov);
485 struct lov_stripe_md *lsm = lov->lo_lsm;
488 (*p)(env, cookie, "stripes: %d, %s, lsm{%p 0x%08X %d %u %u}:\n",
489 r0->lo_nr, lov->lo_layout_invalid ? "invalid" : "valid", lsm,
490 lsm->lsm_magic, atomic_read(&lsm->lsm_refc),
491 lsm->lsm_stripe_count, lsm->lsm_layout_gen);
492 for (i = 0; i < r0->lo_nr; ++i) {
493 struct lu_object *sub;
495 if (r0->lo_sub[i] != NULL) {
496 sub = lovsub2lu(r0->lo_sub[i]);
497 lu_object_print(env, cookie, p, sub);
499 (*p)(env, cookie, "sub %d absent\n", i);
505 static int lov_print_released(const struct lu_env *env, void *cookie,
506 lu_printer_t p, const struct lu_object *o)
508 struct lov_object *lov = lu2lov(o);
509 struct lov_stripe_md *lsm = lov->lo_lsm;
512 "released: %s, lsm{%p 0x%08X %d %u %u}:\n",
513 lov->lo_layout_invalid ? "invalid" : "valid", lsm,
514 lsm->lsm_magic, atomic_read(&lsm->lsm_refc),
515 lsm->lsm_stripe_count, lsm->lsm_layout_gen);
520 * Implements cl_object_operations::coo_attr_get() method for an object
521 * without stripes (LLT_EMPTY layout type).
523 * The only attributes this layer is authoritative in this case is
524 * cl_attr::cat_blocks---it's 0.
526 static int lov_attr_get_empty(const struct lu_env *env, struct cl_object *obj,
527 struct cl_attr *attr)
529 attr->cat_blocks = 0;
533 static int lov_attr_get_raid0(const struct lu_env *env, struct cl_object *obj,
534 struct cl_attr *attr)
536 struct lov_object *lov = cl2lov(obj);
537 struct lov_layout_raid0 *r0 = lov_r0(lov);
538 struct cl_attr *lov_attr = &r0->lo_attr;
543 /* this is called w/o holding type guard mutex, so it must be inside
544 * an on going IO otherwise lsm may be replaced.
545 * LU-2117: it turns out there exists one exception. For mmaped files,
546 * the lock of those files may be requested in the other file's IO
547 * context, and this function is called in ccc_lock_state(), it will
548 * hit this assertion.
549 * Anyway, it's still okay to call attr_get w/o type guard as layout
550 * can't go if locks exist. */
551 /* LASSERT(atomic_read(&lsm->lsm_refc) > 1); */
553 if (!r0->lo_attr_valid) {
554 struct lov_stripe_md *lsm = lov->lo_lsm;
555 struct ost_lvb *lvb = &lov_env_info(env)->lti_lvb;
558 memset(lvb, 0, sizeof(*lvb));
559 /* XXX: timestamps can be negative by sanity:test_39m,
561 lvb->lvb_atime = LLONG_MIN;
562 lvb->lvb_ctime = LLONG_MIN;
563 lvb->lvb_mtime = LLONG_MIN;
566 * XXX that should be replaced with a loop over sub-objects,
567 * doing cl_object_attr_get() on them. But for now, let's
568 * reuse old lov code.
572 * XXX take lsm spin-lock to keep lov_merge_lvb_kms()
573 * happy. It's not needed, because new code uses
574 * ->coh_attr_guard spin-lock to protect consistency of
575 * sub-object attributes.
577 lov_stripe_lock(lsm);
578 result = lov_merge_lvb_kms(lsm, lvb, &kms);
579 lov_stripe_unlock(lsm);
581 cl_lvb2attr(lov_attr, lvb);
582 lov_attr->cat_kms = kms;
583 r0->lo_attr_valid = 1;
586 if (result == 0) { /* merge results */
587 attr->cat_blocks = lov_attr->cat_blocks;
588 attr->cat_size = lov_attr->cat_size;
589 attr->cat_kms = lov_attr->cat_kms;
590 if (attr->cat_atime < lov_attr->cat_atime)
591 attr->cat_atime = lov_attr->cat_atime;
592 if (attr->cat_ctime < lov_attr->cat_ctime)
593 attr->cat_ctime = lov_attr->cat_ctime;
594 if (attr->cat_mtime < lov_attr->cat_mtime)
595 attr->cat_mtime = lov_attr->cat_mtime;
600 const static struct lov_layout_operations lov_dispatch[] = {
602 .llo_init = lov_init_empty,
603 .llo_delete = lov_delete_empty,
604 .llo_fini = lov_fini_empty,
605 .llo_install = lov_install_empty,
606 .llo_print = lov_print_empty,
607 .llo_page_init = lov_page_init_empty,
608 .llo_lock_init = lov_lock_init_empty,
609 .llo_io_init = lov_io_init_empty,
610 .llo_getattr = lov_attr_get_empty,
613 .llo_init = lov_init_raid0,
614 .llo_delete = lov_delete_raid0,
615 .llo_fini = lov_fini_raid0,
616 .llo_install = lov_install_raid0,
617 .llo_print = lov_print_raid0,
618 .llo_page_init = lov_page_init_raid0,
619 .llo_lock_init = lov_lock_init_raid0,
620 .llo_io_init = lov_io_init_raid0,
621 .llo_getattr = lov_attr_get_raid0,
624 .llo_init = lov_init_released,
625 .llo_delete = lov_delete_empty,
626 .llo_fini = lov_fini_released,
627 .llo_install = lov_install_empty,
628 .llo_print = lov_print_released,
629 .llo_page_init = lov_page_init_empty,
630 .llo_lock_init = lov_lock_init_empty,
631 .llo_io_init = lov_io_init_released,
632 .llo_getattr = lov_attr_get_empty,
637 * Performs a double-dispatch based on the layout type of an object.
639 #define LOV_2DISPATCH_NOLOCK(obj, op, ...) \
641 struct lov_object *__obj = (obj); \
642 enum lov_layout_type __llt; \
644 __llt = __obj->lo_type; \
645 LASSERT(0 <= __llt && __llt < ARRAY_SIZE(lov_dispatch)); \
646 lov_dispatch[__llt].op(__VA_ARGS__); \
650 * Return lov_layout_type associated with a given lsm
652 static enum lov_layout_type lov_type(struct lov_stripe_md *lsm)
656 if (lsm_is_released(lsm))
661 static inline void lov_conf_freeze(struct lov_object *lov)
663 CDEBUG(D_INODE, "To take share lov(%p) owner %p/%p\n",
664 lov, lov->lo_owner, current);
665 if (lov->lo_owner != current)
666 down_read(&lov->lo_type_guard);
669 static inline void lov_conf_thaw(struct lov_object *lov)
671 CDEBUG(D_INODE, "To release share lov(%p) owner %p/%p\n",
672 lov, lov->lo_owner, current);
673 if (lov->lo_owner != current)
674 up_read(&lov->lo_type_guard);
677 #define LOV_2DISPATCH_MAYLOCK(obj, op, lock, ...) \
679 struct lov_object *__obj = (obj); \
680 int __lock = !!(lock); \
681 typeof(lov_dispatch[0].op(__VA_ARGS__)) __result; \
684 lov_conf_freeze(__obj); \
685 __result = LOV_2DISPATCH_NOLOCK(obj, op, __VA_ARGS__); \
687 lov_conf_thaw(__obj); \
692 * Performs a locked double-dispatch based on the layout type of an object.
694 #define LOV_2DISPATCH(obj, op, ...) \
695 LOV_2DISPATCH_MAYLOCK(obj, op, 1, __VA_ARGS__)
697 #define LOV_2DISPATCH_VOID(obj, op, ...) \
699 struct lov_object *__obj = (obj); \
700 enum lov_layout_type __llt; \
702 lov_conf_freeze(__obj); \
703 __llt = __obj->lo_type; \
704 LASSERT(0 <= __llt && __llt < ARRAY_SIZE(lov_dispatch)); \
705 lov_dispatch[__llt].op(__VA_ARGS__); \
706 lov_conf_thaw(__obj); \
709 static void lov_conf_lock(struct lov_object *lov)
711 LASSERT(lov->lo_owner != current);
712 down_write(&lov->lo_type_guard);
713 LASSERT(lov->lo_owner == NULL);
714 lov->lo_owner = current;
715 CDEBUG(D_INODE, "Took exclusive lov(%p) owner %p\n",
719 static void lov_conf_unlock(struct lov_object *lov)
721 CDEBUG(D_INODE, "To release exclusive lov(%p) owner %p\n",
723 lov->lo_owner = NULL;
724 up_write(&lov->lo_type_guard);
727 static int lov_layout_wait(const struct lu_env *env, struct lov_object *lov)
729 struct l_wait_info lwi = { 0 };
732 while (atomic_read(&lov->lo_active_ios) > 0) {
733 CDEBUG(D_INODE, "file:"DFID" wait for active IO, now: %d.\n",
734 PFID(lu_object_fid(lov2lu(lov))),
735 atomic_read(&lov->lo_active_ios));
737 l_wait_event(lov->lo_waitq,
738 atomic_read(&lov->lo_active_ios) == 0, &lwi);
743 static int lov_layout_change(const struct lu_env *unused,
744 struct lov_object *lov, struct lov_stripe_md *lsm,
745 const struct cl_object_conf *conf)
747 enum lov_layout_type llt = lov_type(lsm);
748 union lov_layout_state *state = &lov->u;
749 const struct lov_layout_operations *old_ops;
750 const struct lov_layout_operations *new_ops;
751 struct lov_device *lov_dev = lov_object_dev(lov);
757 LASSERT(0 <= lov->lo_type && lov->lo_type < ARRAY_SIZE(lov_dispatch));
759 env = cl_env_get(&refcheck);
761 RETURN(PTR_ERR(env));
763 LASSERT(0 <= llt && llt < ARRAY_SIZE(lov_dispatch));
765 CDEBUG(D_INODE, DFID" from %s to %s\n",
766 PFID(lu_object_fid(lov2lu(lov))),
767 llt2str(lov->lo_type), llt2str(llt));
769 old_ops = &lov_dispatch[lov->lo_type];
770 new_ops = &lov_dispatch[llt];
772 rc = cl_object_prune(env, &lov->lo_cl);
776 rc = old_ops->llo_delete(env, lov, &lov->u);
780 old_ops->llo_fini(env, lov, &lov->u);
782 LASSERT(atomic_read(&lov->lo_active_ios) == 0);
784 CDEBUG(D_INODE, DFID "Apply new layout lov %p, type %d\n",
785 PFID(lu_object_fid(lov2lu(lov))), lov, llt);
787 lov->lo_type = LLT_EMPTY;
789 /* page bufsize fixup */
790 cl_object_header(&lov->lo_cl)->coh_page_bufsize -=
791 lov_page_slice_fixup(lov, NULL);
793 rc = new_ops->llo_init(env, lov_dev, lov, lsm, conf, state);
795 struct obd_device *obd = lov2obd(lov_dev->ld_lov);
797 CERROR("%s: cannot apply new layout on "DFID" : rc = %d\n",
798 obd->obd_name, PFID(lu_object_fid(lov2lu(lov))), rc);
799 new_ops->llo_delete(env, lov, state);
800 new_ops->llo_fini(env, lov, state);
801 /* this file becomes an EMPTY file. */
805 new_ops->llo_install(env, lov, state);
809 cl_env_put(env, &refcheck);
813 /*****************************************************************************
815 * Lov object operations.
818 int lov_object_init(const struct lu_env *env, struct lu_object *obj,
819 const struct lu_object_conf *conf)
821 struct lov_object *lov = lu2lov(obj);
822 struct lov_device *dev = lov_object_dev(lov);
823 const struct cl_object_conf *cconf = lu2cl_conf(conf);
824 union lov_layout_state *set = &lov->u;
825 const struct lov_layout_operations *ops;
826 struct lov_stripe_md *lsm = NULL;
830 init_rwsem(&lov->lo_type_guard);
831 atomic_set(&lov->lo_active_ios, 0);
832 init_waitqueue_head(&lov->lo_waitq);
833 cl_object_page_init(lu2cl(obj), sizeof(struct lov_page));
835 lov->lo_type = LLT_EMPTY;
836 if (cconf->u.coc_layout.lb_buf != NULL) {
837 lsm = lov_unpackmd(dev->ld_lov,
838 cconf->u.coc_layout.lb_buf,
839 cconf->u.coc_layout.lb_len);
841 RETURN(PTR_ERR(lsm));
844 /* no locking is necessary, as object is being created */
845 lov->lo_type = lov_type(lsm);
846 ops = &lov_dispatch[lov->lo_type];
847 rc = ops->llo_init(env, dev, lov, lsm, cconf, set);
851 ops->llo_install(env, lov, set);
859 static int lov_conf_set(const struct lu_env *env, struct cl_object *obj,
860 const struct cl_object_conf *conf)
862 struct lov_stripe_md *lsm = NULL;
863 struct lov_object *lov = cl2lov(obj);
867 if (conf->coc_opc == OBJECT_CONF_SET &&
868 conf->u.coc_layout.lb_buf != NULL) {
869 lsm = lov_unpackmd(lov_object_dev(lov)->ld_lov,
870 conf->u.coc_layout.lb_buf,
871 conf->u.coc_layout.lb_len);
873 RETURN(PTR_ERR(lsm));
877 if (conf->coc_opc == OBJECT_CONF_INVALIDATE) {
878 lov->lo_layout_invalid = true;
879 GOTO(out, result = 0);
882 if (conf->coc_opc == OBJECT_CONF_WAIT) {
883 if (lov->lo_layout_invalid &&
884 atomic_read(&lov->lo_active_ios) > 0) {
885 lov_conf_unlock(lov);
886 result = lov_layout_wait(env, lov);
892 LASSERT(conf->coc_opc == OBJECT_CONF_SET);
894 if ((lsm == NULL && lov->lo_lsm == NULL) ||
895 ((lsm != NULL && lov->lo_lsm != NULL) &&
896 (lov->lo_lsm->lsm_layout_gen == lsm->lsm_layout_gen) &&
897 (lov->lo_lsm->lsm_pattern == lsm->lsm_pattern))) {
898 /* same version of layout */
899 lov->lo_layout_invalid = false;
900 GOTO(out, result = 0);
903 /* will change layout - check if there still exists active IO. */
904 if (atomic_read(&lov->lo_active_ios) > 0) {
905 lov->lo_layout_invalid = true;
906 GOTO(out, result = -EBUSY);
909 result = lov_layout_change(env, lov, lsm, conf);
910 lov->lo_layout_invalid = result != 0;
914 lov_conf_unlock(lov);
916 CDEBUG(D_INODE, DFID" lo_layout_invalid=%d\n",
917 PFID(lu_object_fid(lov2lu(lov))), lov->lo_layout_invalid);
921 static void lov_object_delete(const struct lu_env *env, struct lu_object *obj)
923 struct lov_object *lov = lu2lov(obj);
926 LOV_2DISPATCH_VOID(lov, llo_delete, env, lov, &lov->u);
930 static void lov_object_free(const struct lu_env *env, struct lu_object *obj)
932 struct lov_object *lov = lu2lov(obj);
935 LOV_2DISPATCH_VOID(lov, llo_fini, env, lov, &lov->u);
937 OBD_SLAB_FREE_PTR(lov, lov_object_kmem);
941 static int lov_object_print(const struct lu_env *env, void *cookie,
942 lu_printer_t p, const struct lu_object *o)
944 return LOV_2DISPATCH_NOLOCK(lu2lov(o), llo_print, env, cookie, p, o);
947 int lov_page_init(const struct lu_env *env, struct cl_object *obj,
948 struct cl_page *page, pgoff_t index)
950 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_page_init, env, obj, page,
955 * Implements cl_object_operations::clo_io_init() method for lov
956 * layer. Dispatches to the appropriate layout io initialization method.
958 int lov_io_init(const struct lu_env *env, struct cl_object *obj,
961 CL_IO_SLICE_CLEAN(lov_env_io(env), lis_cl);
963 CDEBUG(D_INODE, DFID "io %p type %d ignore/verify layout %d/%d\n",
964 PFID(lu_object_fid(&obj->co_lu)), io, io->ci_type,
965 io->ci_ignore_layout, io->ci_verify_layout);
967 return LOV_2DISPATCH_MAYLOCK(cl2lov(obj), llo_io_init,
968 !io->ci_ignore_layout, env, obj, io);
972 * An implementation of cl_object_operations::clo_attr_get() method for lov
973 * layer. For raid0 layout this collects and merges attributes of all
976 static int lov_attr_get(const struct lu_env *env, struct cl_object *obj,
977 struct cl_attr *attr)
979 /* do not take lock, as this function is called under a
980 * spin-lock. Layout is protected from changing by ongoing IO. */
981 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_getattr, env, obj, attr);
984 static int lov_attr_update(const struct lu_env *env, struct cl_object *obj,
985 const struct cl_attr *attr, unsigned valid)
988 * No dispatch is required here, as no layout implements this.
993 int lov_lock_init(const struct lu_env *env, struct cl_object *obj,
994 struct cl_lock *lock, const struct cl_io *io)
996 /* No need to lock because we've taken one refcount of layout. */
997 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_lock_init, env, obj, lock,
1002 * We calculate on which OST the mapping will end. If the length of mapping
1003 * is greater than (stripe_size * stripe_count) then the last_stripe will
1004 * will be one just before start_stripe. Else we check if the mapping
1005 * intersects each OST and find last_stripe.
1006 * This function returns the last_stripe and also sets the stripe_count
1007 * over which the mapping is spread
1009 * \param lsm [in] striping information for the file
1010 * \param fm_start [in] logical start of mapping
1011 * \param fm_end [in] logical end of mapping
1012 * \param start_stripe [in] starting stripe of the mapping
1013 * \param stripe_count [out] the number of stripes across which to map is
1016 * \retval last_stripe return the last stripe of the mapping
1018 static int fiemap_calc_last_stripe(struct lov_stripe_md *lsm,
1019 loff_t fm_start, loff_t fm_end,
1020 int start_stripe, int *stripe_count)
1027 if (fm_end - fm_start > lsm->lsm_stripe_size * lsm->lsm_stripe_count) {
1028 last_stripe = (start_stripe < 1 ? lsm->lsm_stripe_count - 1 :
1030 *stripe_count = lsm->lsm_stripe_count;
1032 for (j = 0, i = start_stripe; j < lsm->lsm_stripe_count;
1033 i = (i + 1) % lsm->lsm_stripe_count, j++) {
1034 if ((lov_stripe_intersects(lsm, i, fm_start, fm_end,
1035 &obd_start, &obd_end)) == 0)
1039 last_stripe = (start_stripe + j - 1) % lsm->lsm_stripe_count;
1046 * Set fe_device and copy extents from local buffer into main return buffer.
1048 * \param fiemap [out] fiemap to hold all extents
1049 * \param lcl_fm_ext [in] array of fiemap extents get from OSC layer
1050 * \param ost_index [in] OST index to be written into the fm_device
1051 * field for each extent
1052 * \param ext_count [in] number of extents to be copied
1053 * \param current_extent [in] where to start copying in the extent array
1055 static void fiemap_prepare_and_copy_exts(struct fiemap *fiemap,
1056 struct fiemap_extent *lcl_fm_ext,
1057 int ost_index, unsigned int ext_count,
1063 for (ext = 0; ext < ext_count; ext++) {
1064 lcl_fm_ext[ext].fe_device = ost_index;
1065 lcl_fm_ext[ext].fe_flags |= FIEMAP_EXTENT_NET;
1068 /* Copy fm_extent's from fm_local to return buffer */
1069 to = (char *)fiemap + fiemap_count_to_size(current_extent);
1070 memcpy(to, lcl_fm_ext, ext_count * sizeof(struct fiemap_extent));
1073 #define FIEMAP_BUFFER_SIZE 4096
1076 * Non-zero fe_logical indicates that this is a continuation FIEMAP
1077 * call. The local end offset and the device are sent in the first
1078 * fm_extent. This function calculates the stripe number from the index.
1079 * This function returns a stripe_no on which mapping is to be restarted.
1081 * This function returns fm_end_offset which is the in-OST offset at which
1082 * mapping should be restarted. If fm_end_offset=0 is returned then caller
1083 * will re-calculate proper offset in next stripe.
1084 * Note that the first extent is passed to lov_get_info via the value field.
1086 * \param fiemap [in] fiemap request header
1087 * \param lsm [in] striping information for the file
1088 * \param fm_start [in] logical start of mapping
1089 * \param fm_end [in] logical end of mapping
1090 * \param start_stripe [out] starting stripe will be returned in this
1092 static loff_t fiemap_calc_fm_end_offset(struct fiemap *fiemap,
1093 struct lov_stripe_md *lsm,
1094 loff_t fm_start, loff_t fm_end,
1097 loff_t local_end = fiemap->fm_extents[0].fe_logical;
1100 loff_t fm_end_offset;
1104 if (fiemap->fm_extent_count == 0 ||
1105 fiemap->fm_extents[0].fe_logical == 0)
1108 /* Find out stripe_no from ost_index saved in the fe_device */
1109 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1110 struct lov_oinfo *oinfo = lsm->lsm_oinfo[i];
1112 if (lov_oinfo_is_dummy(oinfo))
1115 if (oinfo->loi_ost_idx == fiemap->fm_extents[0].fe_device) {
1121 if (stripe_no == -1)
1124 /* If we have finished mapping on previous device, shift logical
1125 * offset to start of next device */
1126 if (lov_stripe_intersects(lsm, stripe_no, fm_start, fm_end,
1127 &lun_start, &lun_end) != 0 &&
1128 local_end < lun_end) {
1129 fm_end_offset = local_end;
1130 *start_stripe = stripe_no;
1132 /* This is a special value to indicate that caller should
1133 * calculate offset in next stripe. */
1135 *start_stripe = (stripe_no + 1) % lsm->lsm_stripe_count;
1138 return fm_end_offset;
1142 * Break down the FIEMAP request and send appropriate calls to individual OSTs.
1143 * This also handles the restarting of FIEMAP calls in case mapping overflows
1144 * the available number of extents in single call.
1146 * \param env [in] lustre environment
1147 * \param obj [in] file object
1148 * \param fmkey [in] fiemap request header and other info
1149 * \param fiemap [out] fiemap buffer holding retrived map extents
1150 * \param buflen [in/out] max buffer length of @fiemap, when iterate
1151 * each OST, it is used to limit max map needed
1155 static int lov_object_fiemap(const struct lu_env *env, struct cl_object *obj,
1156 struct ll_fiemap_info_key *fmkey,
1157 struct fiemap *fiemap, size_t *buflen)
1159 struct lov_stripe_md *lsm;
1160 struct cl_object *subobj = NULL;
1161 struct lov_obd *lov = lu2lov_dev(obj->co_lu.lo_dev)->ld_lov;
1162 struct fiemap *fm_local = NULL;
1163 struct fiemap_extent *lcl_fm_ext;
1167 loff_t fm_end_offset;
1171 int current_extent = 0;
1175 int cur_stripe_wrap = 0;
1177 unsigned int buffer_size = FIEMAP_BUFFER_SIZE;
1178 /* Whether have we collected enough extents */
1179 bool enough = false;
1180 /* EOF for object */
1181 bool ost_eof = false;
1182 /* done with required mapping for this OST? */
1183 bool ost_done = false;
1186 lsm = lov_lsm_addref(cl2lov(obj));
1191 * If the stripe_count > 1 and the application does not understand
1192 * DEVICE_ORDER flag, it cannot interpret the extents correctly.
1194 if (lsm->lsm_stripe_count > 1 && !(fiemap->fm_flags &
1195 FIEMAP_FLAG_DEVICE_ORDER))
1196 GOTO(out_lsm, rc = -ENOTSUPP);
1198 if (lsm_is_released(lsm)) {
1199 if (fiemap->fm_start < fmkey->lfik_oa.o_size) {
1201 * released file, return a minimal FIEMAP if
1202 * request fits in file-size.
1204 fiemap->fm_mapped_extents = 1;
1205 fiemap->fm_extents[0].fe_logical = fiemap->fm_start;
1206 if (fiemap->fm_start + fiemap->fm_length <
1207 fmkey->lfik_oa.o_size)
1208 fiemap->fm_extents[0].fe_length =
1211 fiemap->fm_extents[0].fe_length =
1212 fmkey->lfik_oa.o_size -
1214 fiemap->fm_extents[0].fe_flags |=
1215 FIEMAP_EXTENT_UNKNOWN | FIEMAP_EXTENT_LAST;
1217 GOTO(out_lsm, rc = 0);
1220 if (fiemap_count_to_size(fiemap->fm_extent_count) < buffer_size)
1221 buffer_size = fiemap_count_to_size(fiemap->fm_extent_count);
1223 OBD_ALLOC_LARGE(fm_local, buffer_size);
1224 if (fm_local == NULL)
1225 GOTO(out_lsm, rc = -ENOMEM);
1226 lcl_fm_ext = &fm_local->fm_extents[0];
1227 count_local = fiemap_size_to_count(buffer_size);
1229 fm_start = fiemap->fm_start;
1230 fm_length = fiemap->fm_length;
1231 /* Calculate start stripe, last stripe and length of mapping */
1232 start_stripe = lov_stripe_number(lsm, fm_start);
1233 fm_end = (fm_length == ~0ULL) ? fmkey->lfik_oa.o_size :
1234 fm_start + fm_length - 1;
1235 /* If fm_length != ~0ULL but fm_start_fm_length-1 exceeds file size */
1236 if (fm_end > fmkey->lfik_oa.o_size)
1237 fm_end = fmkey->lfik_oa.o_size;
1239 last_stripe = fiemap_calc_last_stripe(lsm, fm_start, fm_end,
1240 start_stripe, &stripe_count);
1241 fm_end_offset = fiemap_calc_fm_end_offset(fiemap, lsm, fm_start, fm_end,
1243 if (fm_end_offset == -EINVAL)
1244 GOTO(out_fm_local, rc = -EINVAL);
1247 * Requested extent count exceeds the fiemap buffer size, shrink our
1250 if (fiemap_count_to_size(fiemap->fm_extent_count) > *buflen)
1251 fiemap->fm_extent_count = fiemap_size_to_count(*buflen);
1252 if (fiemap->fm_extent_count == 0)
1255 /* Check each stripe */
1256 for (cur_stripe = start_stripe; stripe_count > 0;
1258 cur_stripe = (cur_stripe + 1) % lsm->lsm_stripe_count) {
1259 loff_t req_fm_len; /* Stores length of required mapping */
1260 loff_t len_mapped_single_call;
1263 loff_t obd_object_end;
1264 unsigned int ext_count;
1266 cur_stripe_wrap = cur_stripe;
1268 /* Find out range of mapping on this stripe */
1269 if ((lov_stripe_intersects(lsm, cur_stripe, fm_start, fm_end,
1270 &lun_start, &obd_object_end)) == 0)
1273 if (lov_oinfo_is_dummy(lsm->lsm_oinfo[cur_stripe]))
1274 GOTO(out_fm_local, rc = -EIO);
1276 /* If this is a continuation FIEMAP call and we are on
1277 * starting stripe then lun_start needs to be set to
1279 if (fm_end_offset != 0 && cur_stripe == start_stripe)
1280 lun_start = fm_end_offset;
1282 if (fm_length != ~0ULL) {
1283 /* Handle fm_start + fm_length overflow */
1284 if (fm_start + fm_length < fm_start)
1285 fm_length = ~0ULL - fm_start;
1286 lun_end = lov_size_to_stripe(lsm, fm_start + fm_length,
1292 if (lun_start == lun_end)
1295 req_fm_len = obd_object_end - lun_start;
1296 fm_local->fm_length = 0;
1297 len_mapped_single_call = 0;
1299 /* find lobsub object */
1300 subobj = lov_find_subobj(env, cl2lov(obj), lsm,
1303 GOTO(out_fm_local, rc = PTR_ERR(subobj));
1304 /* If the output buffer is very large and the objects have many
1305 * extents we may need to loop on a single OST repeatedly */
1309 if (fiemap->fm_extent_count > 0) {
1310 /* Don't get too many extents. */
1311 if (current_extent + count_local >
1312 fiemap->fm_extent_count)
1313 count_local = fiemap->fm_extent_count -
1317 lun_start += len_mapped_single_call;
1318 fm_local->fm_length = req_fm_len -
1319 len_mapped_single_call;
1320 req_fm_len = fm_local->fm_length;
1321 fm_local->fm_extent_count = enough ? 1 : count_local;
1322 fm_local->fm_mapped_extents = 0;
1323 fm_local->fm_flags = fiemap->fm_flags;
1325 ost_index = lsm->lsm_oinfo[cur_stripe]->loi_ost_idx;
1327 if (ost_index < 0 ||
1328 ost_index >= lov->desc.ld_tgt_count)
1329 GOTO(obj_put, rc = -EINVAL);
1330 /* If OST is inactive, return extent with UNKNOWN
1332 if (!lov->lov_tgts[ost_index]->ltd_active) {
1333 fm_local->fm_flags |= FIEMAP_EXTENT_LAST;
1334 fm_local->fm_mapped_extents = 1;
1336 lcl_fm_ext[0].fe_logical = lun_start;
1337 lcl_fm_ext[0].fe_length = obd_object_end -
1339 lcl_fm_ext[0].fe_flags |= FIEMAP_EXTENT_UNKNOWN;
1344 fm_local->fm_start = lun_start;
1345 fm_local->fm_flags &= ~FIEMAP_FLAG_DEVICE_ORDER;
1346 memcpy(&fmkey->lfik_fiemap, fm_local,
1348 *buflen = fiemap_count_to_size(
1349 fm_local->fm_extent_count);
1351 rc = cl_object_fiemap(env, subobj, fmkey, fm_local,
1356 ext_count = fm_local->fm_mapped_extents;
1357 if (ext_count == 0) {
1359 /* If last stripe has hold at the end,
1360 * we need to return */
1361 if (cur_stripe_wrap == last_stripe) {
1362 fiemap->fm_mapped_extents = 0;
1366 } else if (enough) {
1368 * We've collected enough extents and there are
1369 * more extents after it.
1374 /* If we just need num of extents, got to next device */
1375 if (fiemap->fm_extent_count == 0) {
1376 current_extent += ext_count;
1380 /* prepare to copy retrived map extents */
1381 len_mapped_single_call =
1382 lcl_fm_ext[ext_count - 1].fe_logical -
1383 lun_start + lcl_fm_ext[ext_count - 1].fe_length;
1385 /* Have we finished mapping on this device? */
1386 if (req_fm_len <= len_mapped_single_call)
1389 /* Clear the EXTENT_LAST flag which can be present on
1390 * the last extent */
1391 if (lcl_fm_ext[ext_count - 1].fe_flags &
1393 lcl_fm_ext[ext_count - 1].fe_flags &=
1394 ~FIEMAP_EXTENT_LAST;
1395 if (lov_stripe_size(lsm,
1396 lcl_fm_ext[ext_count - 1].fe_logical +
1397 lcl_fm_ext[ext_count - 1].fe_length,
1398 cur_stripe) >= fmkey->lfik_oa.o_size)
1401 fiemap_prepare_and_copy_exts(fiemap, lcl_fm_ext,
1402 ost_index, ext_count,
1404 current_extent += ext_count;
1406 /* Ran out of available extents? */
1407 if (current_extent >= fiemap->fm_extent_count)
1409 } while (!ost_done && !ost_eof);
1411 cl_object_put(env, subobj);
1414 if (cur_stripe_wrap == last_stripe)
1416 } /* for each stripe */
1418 /* Indicate that we are returning device offsets unless file just has
1420 if (lsm->lsm_stripe_count > 1)
1421 fiemap->fm_flags |= FIEMAP_FLAG_DEVICE_ORDER;
1423 if (fiemap->fm_extent_count == 0)
1424 goto skip_last_device_calc;
1426 /* Check if we have reached the last stripe and whether mapping for that
1427 * stripe is done. */
1428 if ((cur_stripe_wrap == last_stripe) && (ost_done || ost_eof))
1429 fiemap->fm_extents[current_extent - 1].fe_flags |=
1431 skip_last_device_calc:
1432 fiemap->fm_mapped_extents = current_extent;
1435 cl_object_put(env, subobj);
1437 OBD_FREE_LARGE(fm_local, buffer_size);
1445 static int lov_object_getstripe(const struct lu_env *env, struct cl_object *obj,
1446 struct lov_user_md __user *lum)
1448 struct lov_object *lov = cl2lov(obj);
1449 struct lov_stripe_md *lsm;
1453 lsm = lov_lsm_addref(lov);
1457 rc = lov_getstripe(cl2lov(obj), lsm, lum);
1462 static int lov_object_layout_get(const struct lu_env *env,
1463 struct cl_object *obj,
1464 struct cl_layout *cl)
1466 struct lov_object *lov = cl2lov(obj);
1467 struct lov_stripe_md *lsm = lov_lsm_addref(lov);
1468 struct lu_buf *buf = &cl->cl_buf;
1474 cl->cl_layout_gen = CL_LAYOUT_GEN_EMPTY;
1479 cl->cl_size = lov_mds_md_size(lsm->lsm_stripe_count, lsm->lsm_magic);
1480 cl->cl_layout_gen = lsm->lsm_layout_gen;
1482 rc = lov_lsm_pack(lsm, buf->lb_buf, buf->lb_len);
1485 RETURN(rc < 0 ? rc : 0);
1488 static loff_t lov_object_maxbytes(struct cl_object *obj)
1490 struct lov_object *lov = cl2lov(obj);
1491 struct lov_stripe_md *lsm = lov_lsm_addref(lov);
1497 maxbytes = lsm->lsm_maxbytes;
1504 static const struct cl_object_operations lov_ops = {
1505 .coo_page_init = lov_page_init,
1506 .coo_lock_init = lov_lock_init,
1507 .coo_io_init = lov_io_init,
1508 .coo_attr_get = lov_attr_get,
1509 .coo_attr_update = lov_attr_update,
1510 .coo_conf_set = lov_conf_set,
1511 .coo_getstripe = lov_object_getstripe,
1512 .coo_layout_get = lov_object_layout_get,
1513 .coo_maxbytes = lov_object_maxbytes,
1514 .coo_fiemap = lov_object_fiemap,
1517 static const struct lu_object_operations lov_lu_obj_ops = {
1518 .loo_object_init = lov_object_init,
1519 .loo_object_delete = lov_object_delete,
1520 .loo_object_release = NULL,
1521 .loo_object_free = lov_object_free,
1522 .loo_object_print = lov_object_print,
1523 .loo_object_invariant = NULL
1526 struct lu_object *lov_object_alloc(const struct lu_env *env,
1527 const struct lu_object_header *unused,
1528 struct lu_device *dev)
1530 struct lov_object *lov;
1531 struct lu_object *obj;
1534 OBD_SLAB_ALLOC_PTR_GFP(lov, lov_object_kmem, GFP_NOFS);
1537 lu_object_init(obj, NULL, dev);
1538 lov->lo_cl.co_ops = &lov_ops;
1539 lov->lo_type = -1; /* invalid, to catch uninitialized type */
1541 * object io operation vector (cl_object::co_iop) is installed
1542 * later in lov_object_init(), as different vectors are used
1543 * for object with different layouts.
1545 obj->lo_ops = &lov_lu_obj_ops;
1551 struct lov_stripe_md *lov_lsm_addref(struct lov_object *lov)
1553 struct lov_stripe_md *lsm = NULL;
1555 lov_conf_freeze(lov);
1556 if (lov->lo_lsm != NULL) {
1557 lsm = lsm_addref(lov->lo_lsm);
1558 CDEBUG(D_INODE, "lsm %p addref %d/%d by %p.\n",
1559 lsm, atomic_read(&lsm->lsm_refc),
1560 lov->lo_layout_invalid, current);
1566 int lov_read_and_clear_async_rc(struct cl_object *clob)
1568 struct lu_object *luobj;
1572 luobj = lu_object_locate(&cl_object_header(clob)->coh_lu,
1574 if (luobj != NULL) {
1575 struct lov_object *lov = lu2lov(luobj);
1577 lov_conf_freeze(lov);
1578 switch (lov->lo_type) {
1580 struct lov_stripe_md *lsm;
1584 LASSERT(lsm != NULL);
1585 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1586 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
1588 if (lov_oinfo_is_dummy(loi))
1591 if (loi->loi_ar.ar_rc && !rc)
1592 rc = loi->loi_ar.ar_rc;
1593 loi->loi_ar.ar_rc = 0;
1606 EXPORT_SYMBOL(lov_read_and_clear_async_rc);