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"
46 /*****************************************************************************
52 struct lov_layout_operations {
53 int (*llo_init)(const struct lu_env *env, struct lov_device *dev,
54 struct lov_object *lov,
55 const struct cl_object_conf *conf,
56 union lov_layout_state *state);
57 int (*llo_delete)(const struct lu_env *env, struct lov_object *lov,
58 union lov_layout_state *state);
59 void (*llo_fini)(const struct lu_env *env, struct lov_object *lov,
60 union lov_layout_state *state);
61 void (*llo_install)(const struct lu_env *env, struct lov_object *lov,
62 union lov_layout_state *state);
63 int (*llo_print)(const struct lu_env *env, void *cookie,
64 lu_printer_t p, const struct lu_object *o);
65 int (*llo_page_init)(const struct lu_env *env, struct cl_object *obj,
66 struct cl_page *page, pgoff_t index);
67 int (*llo_lock_init)(const struct lu_env *env,
68 struct cl_object *obj, struct cl_lock *lock,
69 const struct cl_io *io);
70 int (*llo_io_init)(const struct lu_env *env,
71 struct cl_object *obj, struct cl_io *io);
72 int (*llo_getattr)(const struct lu_env *env, struct cl_object *obj,
73 struct cl_attr *attr);
76 static int lov_layout_wait(const struct lu_env *env, struct lov_object *lov);
78 /*****************************************************************************
80 * Lov object layout operations.
84 static void lov_install_empty(const struct lu_env *env,
85 struct lov_object *lov,
86 union lov_layout_state *state)
89 * File without objects.
93 static int lov_init_empty(const struct lu_env *env,
94 struct lov_device *dev, struct lov_object *lov,
95 const struct cl_object_conf *conf,
96 union lov_layout_state *state)
101 static void lov_install_raid0(const struct lu_env *env,
102 struct lov_object *lov,
103 union lov_layout_state *state)
107 static struct cl_object *lov_sub_find(const struct lu_env *env,
108 struct cl_device *dev,
109 const struct lu_fid *fid,
110 const struct cl_object_conf *conf)
114 o = lu_object_find_at(env, cl2lu_dev(dev), fid, &conf->coc_lu);
115 LASSERT(ergo(!IS_ERR(o), o->lo_dev->ld_type == &lovsub_device_type));
119 static int lov_init_sub(const struct lu_env *env, struct lov_object *lov,
120 struct cl_object *stripe, struct lov_layout_raid0 *r0,
123 struct cl_object_header *hdr;
124 struct cl_object_header *subhdr;
125 struct cl_object_header *parent;
126 struct lov_oinfo *oinfo;
129 if (OBD_FAIL_CHECK(OBD_FAIL_LOV_INIT)) {
130 /* For sanity:test_206.
131 * Do not leave the object in cache to avoid accessing
132 * freed memory. This is because osc_object is referring to
133 * lov_oinfo of lsm_stripe_data which will be freed due to
136 cl_object_kill(env, stripe);
137 cl_object_put(env, stripe);
141 hdr = cl_object_header(lov2cl(lov));
142 subhdr = cl_object_header(stripe);
144 oinfo = lov->lo_lsm->lsm_oinfo[idx];
145 CDEBUG(D_INODE, DFID"@%p[%d] -> "DFID"@%p: ostid: "DOSTID
146 " idx: %d gen: %d\n",
147 PFID(&subhdr->coh_lu.loh_fid), subhdr, idx,
148 PFID(&hdr->coh_lu.loh_fid), hdr, POSTID(&oinfo->loi_oi),
149 oinfo->loi_ost_idx, oinfo->loi_ost_gen);
151 /* reuse ->coh_attr_guard to protect coh_parent change */
152 spin_lock(&subhdr->coh_attr_guard);
153 parent = subhdr->coh_parent;
155 subhdr->coh_parent = hdr;
156 spin_unlock(&subhdr->coh_attr_guard);
157 subhdr->coh_nesting = hdr->coh_nesting + 1;
158 lu_object_ref_add(&stripe->co_lu, "lov-parent", lov);
159 r0->lo_sub[idx] = cl2lovsub(stripe);
160 r0->lo_sub[idx]->lso_super = lov;
161 r0->lo_sub[idx]->lso_index = idx;
164 struct lu_object *old_obj;
165 struct lov_object *old_lov;
166 unsigned int mask = D_INODE;
168 spin_unlock(&subhdr->coh_attr_guard);
169 old_obj = lu_object_locate(&parent->coh_lu, &lov_device_type);
171 old_lov = cl2lov(lu2cl(old_obj));
172 if (old_lov->lo_layout_invalid) {
173 /* the object's layout has already changed but isn't
176 lu_object_unhash(env, &stripe->co_lu);
183 LU_OBJECT_DEBUG(mask, env, &stripe->co_lu,
184 "stripe %d is already owned.", idx);
185 LU_OBJECT_DEBUG(mask, env, old_obj, "owned.");
186 LU_OBJECT_HEADER(mask, env, lov2lu(lov), "try to own.\n");
187 cl_object_put(env, stripe);
192 static int lov_page_slice_fixup(struct lov_object *lov,
193 struct cl_object *stripe)
195 struct cl_object_header *hdr = cl_object_header(&lov->lo_cl);
198 cl_object_for_each(o, stripe)
199 o->co_slice_off += hdr->coh_page_bufsize;
201 return cl_object_header(stripe)->coh_page_bufsize;
204 static int lov_init_raid0(const struct lu_env *env,
205 struct lov_device *dev, struct lov_object *lov,
206 const struct cl_object_conf *conf,
207 union lov_layout_state *state)
212 struct cl_object *stripe;
213 struct lov_thread_info *lti = lov_env_info(env);
214 struct cl_object_conf *subconf = <i->lti_stripe_conf;
215 struct lov_stripe_md *lsm = conf->u.coc_md->lsm;
216 struct lu_fid *ofid = <i->lti_fid;
217 struct lov_layout_raid0 *r0 = &state->raid0;
219 if (lsm->lsm_magic != LOV_MAGIC_V1 && lsm->lsm_magic != LOV_MAGIC_V3) {
220 dump_lsm(D_ERROR, lsm);
221 LASSERTF(0, "magic mismatch, expected %d/%d, actual %d.\n",
222 LOV_MAGIC_V1, LOV_MAGIC_V3, lsm->lsm_magic);
225 LASSERT(!lov->lo_lsm);
226 lov->lo_lsm = lsm_addref(lsm);
227 r0->lo_nr = lsm->lsm_stripe_count;
228 LASSERT(r0->lo_nr <= lov_targets_nr(dev));
230 r0->lo_sub = libcfs_kvzalloc(r0->lo_nr * sizeof(r0->lo_sub[0]),
236 subconf->coc_inode = conf->coc_inode;
237 spin_lock_init(&r0->lo_sub_lock);
239 * Create stripe cl_objects.
241 for (i = 0; i < r0->lo_nr && result == 0; ++i) {
242 struct cl_device *subdev;
243 struct lov_oinfo *oinfo = lsm->lsm_oinfo[i];
244 int ost_idx = oinfo->loi_ost_idx;
246 if (lov_oinfo_is_dummy(oinfo))
249 result = ostid_to_fid(ofid, &oinfo->loi_oi,
254 subdev = lovsub2cl_dev(dev->ld_target[ost_idx]);
255 subconf->u.coc_oinfo = oinfo;
256 LASSERTF(subdev, "not init ost %d\n", ost_idx);
257 /* In the function below, .hs_keycmp resolves to
258 * lu_obj_hop_keycmp()
260 /* coverity[overrun-buffer-val] */
261 stripe = lov_sub_find(env, subdev, ofid, subconf);
262 if (!IS_ERR(stripe)) {
263 result = lov_init_sub(env, lov, stripe, r0, i);
264 if (result == -EAGAIN) { /* try again */
270 result = PTR_ERR(stripe);
274 int sz = lov_page_slice_fixup(lov, stripe);
276 LASSERT(ergo(psz > 0, psz == sz));
281 cl_object_header(&lov->lo_cl)->coh_page_bufsize += psz;
289 static int lov_init_released(const struct lu_env *env,
290 struct lov_device *dev, struct lov_object *lov,
291 const struct cl_object_conf *conf,
292 union lov_layout_state *state)
294 struct lov_stripe_md *lsm = conf->u.coc_md->lsm;
297 LASSERT(lsm_is_released(lsm));
298 LASSERT(!lov->lo_lsm);
300 lov->lo_lsm = lsm_addref(lsm);
304 static int lov_delete_empty(const struct lu_env *env, struct lov_object *lov,
305 union lov_layout_state *state)
307 LASSERT(lov->lo_type == LLT_EMPTY || lov->lo_type == LLT_RELEASED);
309 lov_layout_wait(env, lov);
313 static void lov_subobject_kill(const struct lu_env *env, struct lov_object *lov,
314 struct lovsub_object *los, int idx)
316 struct cl_object *sub;
317 struct lov_layout_raid0 *r0;
318 struct lu_site *site;
319 struct lu_site_bkt_data *bkt;
320 wait_queue_t *waiter;
323 LASSERT(r0->lo_sub[idx] == los);
325 sub = lovsub2cl(los);
326 site = sub->co_lu.lo_dev->ld_site;
327 bkt = lu_site_bkt_from_fid(site, &sub->co_lu.lo_header->loh_fid);
329 cl_object_kill(env, sub);
330 /* release a reference to the sub-object and ... */
331 lu_object_ref_del(&sub->co_lu, "lov-parent", lov);
332 cl_object_put(env, sub);
334 /* ... wait until it is actually destroyed---sub-object clears its
335 * ->lo_sub[] slot in lovsub_object_fini()
337 if (r0->lo_sub[idx] == los) {
338 waiter = &lov_env_info(env)->lti_waiter;
339 init_waitqueue_entry(waiter, current);
340 add_wait_queue(&bkt->lsb_marche_funebre, waiter);
341 set_current_state(TASK_UNINTERRUPTIBLE);
343 /* this wait-queue is signaled at the end of
346 set_current_state(TASK_UNINTERRUPTIBLE);
347 spin_lock(&r0->lo_sub_lock);
348 if (r0->lo_sub[idx] == los) {
349 spin_unlock(&r0->lo_sub_lock);
352 spin_unlock(&r0->lo_sub_lock);
353 set_current_state(TASK_RUNNING);
357 remove_wait_queue(&bkt->lsb_marche_funebre, waiter);
359 LASSERT(!r0->lo_sub[idx]);
362 static int lov_delete_raid0(const struct lu_env *env, struct lov_object *lov,
363 union lov_layout_state *state)
365 struct lov_layout_raid0 *r0 = &state->raid0;
366 struct lov_stripe_md *lsm = lov->lo_lsm;
369 dump_lsm(D_INODE, lsm);
371 lov_layout_wait(env, lov);
373 for (i = 0; i < r0->lo_nr; ++i) {
374 struct lovsub_object *los = r0->lo_sub[i];
377 cl_object_prune(env, &los->lso_cl);
379 * If top-level object is to be evicted from
380 * the cache, so are its sub-objects.
382 lov_subobject_kill(env, lov, los, i);
389 static void lov_fini_empty(const struct lu_env *env, struct lov_object *lov,
390 union lov_layout_state *state)
392 LASSERT(lov->lo_type == LLT_EMPTY || lov->lo_type == LLT_RELEASED);
395 static void lov_fini_raid0(const struct lu_env *env, struct lov_object *lov,
396 union lov_layout_state *state)
398 struct lov_layout_raid0 *r0 = &state->raid0;
405 dump_lsm(D_INODE, lov->lo_lsm);
406 lov_free_memmd(&lov->lo_lsm);
409 static void lov_fini_released(const struct lu_env *env, struct lov_object *lov,
410 union lov_layout_state *state)
412 dump_lsm(D_INODE, lov->lo_lsm);
413 lov_free_memmd(&lov->lo_lsm);
416 static int lov_print_empty(const struct lu_env *env, void *cookie,
417 lu_printer_t p, const struct lu_object *o)
419 (*p)(env, cookie, "empty %d\n", lu2lov(o)->lo_layout_invalid);
423 static int lov_print_raid0(const struct lu_env *env, void *cookie,
424 lu_printer_t p, const struct lu_object *o)
426 struct lov_object *lov = lu2lov(o);
427 struct lov_layout_raid0 *r0 = lov_r0(lov);
428 struct lov_stripe_md *lsm = lov->lo_lsm;
431 (*p)(env, cookie, "stripes: %d, %s, lsm{%p 0x%08X %d %u %u}:\n",
432 r0->lo_nr, lov->lo_layout_invalid ? "invalid" : "valid", lsm,
433 lsm->lsm_magic, atomic_read(&lsm->lsm_refc),
434 lsm->lsm_stripe_count, lsm->lsm_layout_gen);
435 for (i = 0; i < r0->lo_nr; ++i) {
436 struct lu_object *sub;
439 sub = lovsub2lu(r0->lo_sub[i]);
440 lu_object_print(env, cookie, p, sub);
442 (*p)(env, cookie, "sub %d absent\n", i);
448 static int lov_print_released(const struct lu_env *env, void *cookie,
449 lu_printer_t p, const struct lu_object *o)
451 struct lov_object *lov = lu2lov(o);
452 struct lov_stripe_md *lsm = lov->lo_lsm;
455 "released: %s, lsm{%p 0x%08X %d %u %u}:\n",
456 lov->lo_layout_invalid ? "invalid" : "valid", lsm,
457 lsm->lsm_magic, atomic_read(&lsm->lsm_refc),
458 lsm->lsm_stripe_count, lsm->lsm_layout_gen);
463 * Implements cl_object_operations::coo_attr_get() method for an object
464 * without stripes (LLT_EMPTY layout type).
466 * The only attributes this layer is authoritative in this case is
467 * cl_attr::cat_blocks---it's 0.
469 static int lov_attr_get_empty(const struct lu_env *env, struct cl_object *obj,
470 struct cl_attr *attr)
472 attr->cat_blocks = 0;
476 static int lov_attr_get_raid0(const struct lu_env *env, struct cl_object *obj,
477 struct cl_attr *attr)
479 struct lov_object *lov = cl2lov(obj);
480 struct lov_layout_raid0 *r0 = lov_r0(lov);
481 struct cl_attr *lov_attr = &r0->lo_attr;
484 /* this is called w/o holding type guard mutex, so it must be inside
485 * an on going IO otherwise lsm may be replaced.
486 * LU-2117: it turns out there exists one exception. For mmaped files,
487 * the lock of those files may be requested in the other file's IO
488 * context, and this function is called in ccc_lock_state(), it will
489 * hit this assertion.
490 * Anyway, it's still okay to call attr_get w/o type guard as layout
491 * can't go if locks exist.
493 /* LASSERT(atomic_read(&lsm->lsm_refc) > 1); */
495 if (!r0->lo_attr_valid) {
496 struct lov_stripe_md *lsm = lov->lo_lsm;
497 struct ost_lvb *lvb = &lov_env_info(env)->lti_lvb;
500 memset(lvb, 0, sizeof(*lvb));
501 /* XXX: timestamps can be negative by sanity:test_39m,
504 lvb->lvb_atime = LLONG_MIN;
505 lvb->lvb_ctime = LLONG_MIN;
506 lvb->lvb_mtime = LLONG_MIN;
509 * XXX that should be replaced with a loop over sub-objects,
510 * doing cl_object_attr_get() on them. But for now, let's
511 * reuse old lov code.
515 * XXX take lsm spin-lock to keep lov_merge_lvb_kms()
516 * happy. It's not needed, because new code uses
517 * ->coh_attr_guard spin-lock to protect consistency of
518 * sub-object attributes.
520 lov_stripe_lock(lsm);
521 result = lov_merge_lvb_kms(lsm, lvb, &kms);
522 lov_stripe_unlock(lsm);
524 cl_lvb2attr(lov_attr, lvb);
525 lov_attr->cat_kms = kms;
526 r0->lo_attr_valid = 1;
529 if (result == 0) { /* merge results */
530 attr->cat_blocks = lov_attr->cat_blocks;
531 attr->cat_size = lov_attr->cat_size;
532 attr->cat_kms = lov_attr->cat_kms;
533 if (attr->cat_atime < lov_attr->cat_atime)
534 attr->cat_atime = lov_attr->cat_atime;
535 if (attr->cat_ctime < lov_attr->cat_ctime)
536 attr->cat_ctime = lov_attr->cat_ctime;
537 if (attr->cat_mtime < lov_attr->cat_mtime)
538 attr->cat_mtime = lov_attr->cat_mtime;
543 static const struct lov_layout_operations lov_dispatch[] = {
545 .llo_init = lov_init_empty,
546 .llo_delete = lov_delete_empty,
547 .llo_fini = lov_fini_empty,
548 .llo_install = lov_install_empty,
549 .llo_print = lov_print_empty,
550 .llo_page_init = lov_page_init_empty,
551 .llo_lock_init = lov_lock_init_empty,
552 .llo_io_init = lov_io_init_empty,
553 .llo_getattr = lov_attr_get_empty
556 .llo_init = lov_init_raid0,
557 .llo_delete = lov_delete_raid0,
558 .llo_fini = lov_fini_raid0,
559 .llo_install = lov_install_raid0,
560 .llo_print = lov_print_raid0,
561 .llo_page_init = lov_page_init_raid0,
562 .llo_lock_init = lov_lock_init_raid0,
563 .llo_io_init = lov_io_init_raid0,
564 .llo_getattr = lov_attr_get_raid0
567 .llo_init = lov_init_released,
568 .llo_delete = lov_delete_empty,
569 .llo_fini = lov_fini_released,
570 .llo_install = lov_install_empty,
571 .llo_print = lov_print_released,
572 .llo_page_init = lov_page_init_empty,
573 .llo_lock_init = lov_lock_init_empty,
574 .llo_io_init = lov_io_init_released,
575 .llo_getattr = lov_attr_get_empty
580 * Performs a double-dispatch based on the layout type of an object.
582 #define LOV_2DISPATCH_NOLOCK(obj, op, ...) \
584 struct lov_object *__obj = (obj); \
585 enum lov_layout_type __llt; \
587 __llt = __obj->lo_type; \
588 LASSERT(0 <= __llt && __llt < ARRAY_SIZE(lov_dispatch)); \
589 lov_dispatch[__llt].op(__VA_ARGS__); \
593 * Return lov_layout_type associated with a given lsm
595 static enum lov_layout_type lov_type(struct lov_stripe_md *lsm)
599 if (lsm_is_released(lsm))
604 static inline void lov_conf_freeze(struct lov_object *lov)
606 if (lov->lo_owner != current)
607 down_read(&lov->lo_type_guard);
610 static inline void lov_conf_thaw(struct lov_object *lov)
612 if (lov->lo_owner != current)
613 up_read(&lov->lo_type_guard);
616 #define LOV_2DISPATCH_MAYLOCK(obj, op, lock, ...) \
618 struct lov_object *__obj = (obj); \
619 int __lock = !!(lock); \
620 typeof(lov_dispatch[0].op(__VA_ARGS__)) __result; \
623 lov_conf_freeze(__obj); \
624 __result = LOV_2DISPATCH_NOLOCK(obj, op, __VA_ARGS__); \
626 lov_conf_thaw(__obj); \
631 * Performs a locked double-dispatch based on the layout type of an object.
633 #define LOV_2DISPATCH(obj, op, ...) \
634 LOV_2DISPATCH_MAYLOCK(obj, op, 1, __VA_ARGS__)
636 #define LOV_2DISPATCH_VOID(obj, op, ...) \
638 struct lov_object *__obj = (obj); \
639 enum lov_layout_type __llt; \
641 lov_conf_freeze(__obj); \
642 __llt = __obj->lo_type; \
643 LASSERT(0 <= __llt && __llt < ARRAY_SIZE(lov_dispatch)); \
644 lov_dispatch[__llt].op(__VA_ARGS__); \
645 lov_conf_thaw(__obj); \
648 static void lov_conf_lock(struct lov_object *lov)
650 LASSERT(lov->lo_owner != current);
651 down_write(&lov->lo_type_guard);
652 LASSERT(!lov->lo_owner);
653 lov->lo_owner = current;
656 static void lov_conf_unlock(struct lov_object *lov)
658 lov->lo_owner = NULL;
659 up_write(&lov->lo_type_guard);
662 static int lov_layout_wait(const struct lu_env *env, struct lov_object *lov)
664 struct l_wait_info lwi = { 0 };
666 while (atomic_read(&lov->lo_active_ios) > 0) {
667 CDEBUG(D_INODE, "file:" DFID " wait for active IO, now: %d.\n",
668 PFID(lu_object_fid(lov2lu(lov))),
669 atomic_read(&lov->lo_active_ios));
671 l_wait_event(lov->lo_waitq,
672 atomic_read(&lov->lo_active_ios) == 0, &lwi);
677 static int lov_layout_change(const struct lu_env *unused,
678 struct lov_object *lov,
679 const struct cl_object_conf *conf)
682 enum lov_layout_type llt = LLT_EMPTY;
683 union lov_layout_state *state = &lov->u;
684 const struct lov_layout_operations *old_ops;
685 const struct lov_layout_operations *new_ops;
691 LASSERT(0 <= lov->lo_type && lov->lo_type < ARRAY_SIZE(lov_dispatch));
694 llt = lov_type(conf->u.coc_md->lsm);
695 LASSERT(0 <= llt && llt < ARRAY_SIZE(lov_dispatch));
697 cookie = cl_env_reenter();
698 env = cl_env_get(&refcheck);
700 cl_env_reexit(cookie);
704 CDEBUG(D_INODE, DFID" from %s to %s\n",
705 PFID(lu_object_fid(lov2lu(lov))),
706 llt2str(lov->lo_type), llt2str(llt));
708 old_ops = &lov_dispatch[lov->lo_type];
709 new_ops = &lov_dispatch[llt];
711 result = cl_object_prune(env, &lov->lo_cl);
715 result = old_ops->llo_delete(env, lov, &lov->u);
717 old_ops->llo_fini(env, lov, &lov->u);
719 LASSERT(atomic_read(&lov->lo_active_ios) == 0);
721 lov->lo_type = LLT_EMPTY;
722 result = new_ops->llo_init(env,
723 lu2lov_dev(lov->lo_cl.co_lu.lo_dev),
726 new_ops->llo_install(env, lov, state);
729 new_ops->llo_delete(env, lov, state);
730 new_ops->llo_fini(env, lov, state);
731 /* this file becomes an EMPTY file. */
736 cl_env_put(env, &refcheck);
737 cl_env_reexit(cookie);
741 /*****************************************************************************
743 * Lov object operations.
746 int lov_object_init(const struct lu_env *env, struct lu_object *obj,
747 const struct lu_object_conf *conf)
749 struct lov_device *dev = lu2lov_dev(obj->lo_dev);
750 struct lov_object *lov = lu2lov(obj);
751 const struct cl_object_conf *cconf = lu2cl_conf(conf);
752 union lov_layout_state *set = &lov->u;
753 const struct lov_layout_operations *ops;
756 init_rwsem(&lov->lo_type_guard);
757 atomic_set(&lov->lo_active_ios, 0);
758 init_waitqueue_head(&lov->lo_waitq);
760 cl_object_page_init(lu2cl(obj), sizeof(struct lov_page));
762 /* no locking is necessary, as object is being created */
763 lov->lo_type = lov_type(cconf->u.coc_md->lsm);
764 ops = &lov_dispatch[lov->lo_type];
765 result = ops->llo_init(env, dev, lov, cconf, set);
767 ops->llo_install(env, lov, set);
771 static int lov_conf_set(const struct lu_env *env, struct cl_object *obj,
772 const struct cl_object_conf *conf)
774 struct lov_stripe_md *lsm = NULL;
775 struct lov_object *lov = cl2lov(obj);
779 if (conf->coc_opc == OBJECT_CONF_INVALIDATE) {
780 lov->lo_layout_invalid = true;
785 if (conf->coc_opc == OBJECT_CONF_WAIT) {
786 if (lov->lo_layout_invalid &&
787 atomic_read(&lov->lo_active_ios) > 0) {
788 lov_conf_unlock(lov);
789 result = lov_layout_wait(env, lov);
795 LASSERT(conf->coc_opc == OBJECT_CONF_SET);
798 lsm = conf->u.coc_md->lsm;
799 if ((!lsm && !lov->lo_lsm) ||
800 ((lsm && lov->lo_lsm) &&
801 (lov->lo_lsm->lsm_layout_gen == lsm->lsm_layout_gen) &&
802 (lov->lo_lsm->lsm_pattern == lsm->lsm_pattern))) {
803 /* same version of layout */
804 lov->lo_layout_invalid = false;
809 /* will change layout - check if there still exists active IO. */
810 if (atomic_read(&lov->lo_active_ios) > 0) {
811 lov->lo_layout_invalid = true;
816 result = lov_layout_change(env, lov, conf);
817 lov->lo_layout_invalid = result != 0;
820 lov_conf_unlock(lov);
821 CDEBUG(D_INODE, DFID" lo_layout_invalid=%d\n",
822 PFID(lu_object_fid(lov2lu(lov))), lov->lo_layout_invalid);
826 static void lov_object_delete(const struct lu_env *env, struct lu_object *obj)
828 struct lov_object *lov = lu2lov(obj);
830 LOV_2DISPATCH_VOID(lov, llo_delete, env, lov, &lov->u);
833 static void lov_object_free(const struct lu_env *env, struct lu_object *obj)
835 struct lov_object *lov = lu2lov(obj);
837 LOV_2DISPATCH_VOID(lov, llo_fini, env, lov, &lov->u);
839 kmem_cache_free(lov_object_kmem, lov);
842 static int lov_object_print(const struct lu_env *env, void *cookie,
843 lu_printer_t p, const struct lu_object *o)
845 return LOV_2DISPATCH_NOLOCK(lu2lov(o), llo_print, env, cookie, p, o);
848 int lov_page_init(const struct lu_env *env, struct cl_object *obj,
849 struct cl_page *page, pgoff_t index)
851 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_page_init, env, obj, page,
856 * Implements cl_object_operations::clo_io_init() method for lov
857 * layer. Dispatches to the appropriate layout io initialization method.
859 int lov_io_init(const struct lu_env *env, struct cl_object *obj,
862 CL_IO_SLICE_CLEAN(lov_env_io(env), lis_cl);
863 return LOV_2DISPATCH_MAYLOCK(cl2lov(obj), llo_io_init,
864 !io->ci_ignore_layout, env, obj, io);
868 * An implementation of cl_object_operations::clo_attr_get() method for lov
869 * layer. For raid0 layout this collects and merges attributes of all
872 static int lov_attr_get(const struct lu_env *env, struct cl_object *obj,
873 struct cl_attr *attr)
875 /* do not take lock, as this function is called under a
876 * spin-lock. Layout is protected from changing by ongoing IO.
878 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_getattr, env, obj, attr);
881 static int lov_attr_set(const struct lu_env *env, struct cl_object *obj,
882 const struct cl_attr *attr, unsigned valid)
885 * No dispatch is required here, as no layout implements this.
890 int lov_lock_init(const struct lu_env *env, struct cl_object *obj,
891 struct cl_lock *lock, const struct cl_io *io)
893 /* No need to lock because we've taken one refcount of layout. */
894 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_lock_init, env, obj, lock,
898 static const struct cl_object_operations lov_ops = {
899 .coo_page_init = lov_page_init,
900 .coo_lock_init = lov_lock_init,
901 .coo_io_init = lov_io_init,
902 .coo_attr_get = lov_attr_get,
903 .coo_attr_set = lov_attr_set,
904 .coo_conf_set = lov_conf_set
907 static const struct lu_object_operations lov_lu_obj_ops = {
908 .loo_object_init = lov_object_init,
909 .loo_object_delete = lov_object_delete,
910 .loo_object_release = NULL,
911 .loo_object_free = lov_object_free,
912 .loo_object_print = lov_object_print,
913 .loo_object_invariant = NULL
916 struct lu_object *lov_object_alloc(const struct lu_env *env,
917 const struct lu_object_header *unused,
918 struct lu_device *dev)
920 struct lov_object *lov;
921 struct lu_object *obj;
923 lov = kmem_cache_zalloc(lov_object_kmem, GFP_NOFS);
926 lu_object_init(obj, NULL, dev);
927 lov->lo_cl.co_ops = &lov_ops;
928 lov->lo_type = -1; /* invalid, to catch uninitialized type */
930 * object io operation vector (cl_object::co_iop) is installed
931 * later in lov_object_init(), as different vectors are used
932 * for object with different layouts.
934 obj->lo_ops = &lov_lu_obj_ops;
941 static struct lov_stripe_md *lov_lsm_addref(struct lov_object *lov)
943 struct lov_stripe_md *lsm = NULL;
945 lov_conf_freeze(lov);
947 lsm = lsm_addref(lov->lo_lsm);
948 CDEBUG(D_INODE, "lsm %p addref %d/%d by %p.\n",
949 lsm, atomic_read(&lsm->lsm_refc),
950 lov->lo_layout_invalid, current);
956 struct lov_stripe_md *lov_lsm_get(struct cl_object *clobj)
958 struct lu_object *luobj;
959 struct lov_stripe_md *lsm = NULL;
964 luobj = lu_object_locate(&cl_object_header(clobj)->coh_lu,
967 lsm = lov_lsm_addref(lu2lov(luobj));
970 EXPORT_SYMBOL(lov_lsm_get);
972 void lov_lsm_put(struct cl_object *unused, struct lov_stripe_md *lsm)
975 lov_free_memmd(&lsm);
977 EXPORT_SYMBOL(lov_lsm_put);
979 int lov_read_and_clear_async_rc(struct cl_object *clob)
981 struct lu_object *luobj;
984 luobj = lu_object_locate(&cl_object_header(clob)->coh_lu,
987 struct lov_object *lov = lu2lov(luobj);
989 lov_conf_freeze(lov);
990 switch (lov->lo_type) {
992 struct lov_stripe_md *lsm;
996 for (i = 0; i < lsm->lsm_stripe_count; i++) {
997 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
999 if (lov_oinfo_is_dummy(loi))
1002 if (loi->loi_ar.ar_rc && !rc)
1003 rc = loi->loi_ar.ar_rc;
1004 loi->loi_ar.ar_rc = 0;
1017 EXPORT_SYMBOL(lov_read_and_clear_async_rc);