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"
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);
80 static int lov_layout_wait(const struct lu_env *env, struct lov_object *lov);
82 /*****************************************************************************
84 * Lov object layout operations.
88 static void lov_install_empty(const struct lu_env *env,
89 struct lov_object *lov,
90 union lov_layout_state *state)
93 * File without objects.
97 static int lov_init_empty(const struct lu_env *env,
98 struct lov_device *dev, struct lov_object *lov,
99 const struct cl_object_conf *conf,
100 union lov_layout_state *state)
105 static void lov_install_raid0(const struct lu_env *env,
106 struct lov_object *lov,
107 union lov_layout_state *state)
111 static struct cl_object *lov_sub_find(const struct lu_env *env,
112 struct cl_device *dev,
113 const struct lu_fid *fid,
114 const struct cl_object_conf *conf)
118 o = lu_object_find_at(env, cl2lu_dev(dev), fid, &conf->coc_lu);
119 LASSERT(ergo(!IS_ERR(o), o->lo_dev->ld_type == &lovsub_device_type));
123 static int lov_init_sub(const struct lu_env *env, struct lov_object *lov,
124 struct cl_object *stripe, struct lov_layout_raid0 *r0,
127 struct cl_object_header *hdr;
128 struct cl_object_header *subhdr;
129 struct cl_object_header *parent;
130 struct lov_oinfo *oinfo;
133 if (OBD_FAIL_CHECK(OBD_FAIL_LOV_INIT)) {
134 /* For sanity:test_206.
135 * Do not leave the object in cache to avoid accessing
136 * freed memory. This is because osc_object is referring to
137 * lov_oinfo of lsm_stripe_data which will be freed due to
140 cl_object_kill(env, stripe);
141 cl_object_put(env, stripe);
145 hdr = cl_object_header(lov2cl(lov));
146 subhdr = cl_object_header(stripe);
148 oinfo = lov->lo_lsm->lsm_oinfo[idx];
149 CDEBUG(D_INODE, DFID"@%p[%d] -> "DFID"@%p: ostid: "DOSTID
150 " idx: %d gen: %d\n",
151 PFID(&subhdr->coh_lu.loh_fid), subhdr, idx,
152 PFID(&hdr->coh_lu.loh_fid), hdr, POSTID(&oinfo->loi_oi),
153 oinfo->loi_ost_idx, oinfo->loi_ost_gen);
155 /* reuse ->coh_attr_guard to protect coh_parent change */
156 spin_lock(&subhdr->coh_attr_guard);
157 parent = subhdr->coh_parent;
159 subhdr->coh_parent = hdr;
160 spin_unlock(&subhdr->coh_attr_guard);
161 subhdr->coh_nesting = hdr->coh_nesting + 1;
162 lu_object_ref_add(&stripe->co_lu, "lov-parent", lov);
163 r0->lo_sub[idx] = cl2lovsub(stripe);
164 r0->lo_sub[idx]->lso_super = lov;
165 r0->lo_sub[idx]->lso_index = idx;
168 struct lu_object *old_obj;
169 struct lov_object *old_lov;
170 unsigned int mask = D_INODE;
172 spin_unlock(&subhdr->coh_attr_guard);
173 old_obj = lu_object_locate(&parent->coh_lu, &lov_device_type);
175 old_lov = cl2lov(lu2cl(old_obj));
176 if (old_lov->lo_layout_invalid) {
177 /* the object's layout has already changed but isn't
180 lu_object_unhash(env, &stripe->co_lu);
187 LU_OBJECT_DEBUG(mask, env, &stripe->co_lu,
188 "stripe %d is already owned.\n", idx);
189 LU_OBJECT_DEBUG(mask, env, old_obj, "owned.\n");
190 LU_OBJECT_HEADER(mask, env, lov2lu(lov), "try to own.\n");
191 cl_object_put(env, stripe);
196 static int lov_page_slice_fixup(struct lov_object *lov,
197 struct cl_object *stripe)
199 struct cl_object_header *hdr = cl_object_header(&lov->lo_cl);
202 cl_object_for_each(o, stripe)
203 o->co_slice_off += hdr->coh_page_bufsize;
205 return cl_object_header(stripe)->coh_page_bufsize;
208 static int lov_init_raid0(const struct lu_env *env,
209 struct lov_device *dev, struct lov_object *lov,
210 const struct cl_object_conf *conf,
211 union lov_layout_state *state)
216 struct cl_object *stripe;
217 struct lov_thread_info *lti = lov_env_info(env);
218 struct cl_object_conf *subconf = <i->lti_stripe_conf;
219 struct lov_stripe_md *lsm = conf->u.coc_md->lsm;
220 struct lu_fid *ofid = <i->lti_fid;
221 struct lov_layout_raid0 *r0 = &state->raid0;
223 if (lsm->lsm_magic != LOV_MAGIC_V1 && lsm->lsm_magic != LOV_MAGIC_V3) {
224 dump_lsm(D_ERROR, lsm);
225 LASSERTF(0, "magic mismatch, expected %d/%d, actual %d.\n",
226 LOV_MAGIC_V1, LOV_MAGIC_V3, lsm->lsm_magic);
229 LASSERT(!lov->lo_lsm);
230 lov->lo_lsm = lsm_addref(lsm);
231 r0->lo_nr = lsm->lsm_stripe_count;
232 LASSERT(r0->lo_nr <= lov_targets_nr(dev));
234 r0->lo_sub = libcfs_kvzalloc(r0->lo_nr * sizeof(r0->lo_sub[0]),
240 subconf->coc_inode = conf->coc_inode;
241 spin_lock_init(&r0->lo_sub_lock);
243 * Create stripe cl_objects.
245 for (i = 0; i < r0->lo_nr && result == 0; ++i) {
246 struct cl_device *subdev;
247 struct lov_oinfo *oinfo = lsm->lsm_oinfo[i];
248 int ost_idx = oinfo->loi_ost_idx;
250 if (lov_oinfo_is_dummy(oinfo))
253 result = ostid_to_fid(ofid, &oinfo->loi_oi,
258 subdev = lovsub2cl_dev(dev->ld_target[ost_idx]);
259 subconf->u.coc_oinfo = oinfo;
260 LASSERTF(subdev, "not init ost %d\n", ost_idx);
261 /* In the function below, .hs_keycmp resolves to
262 * lu_obj_hop_keycmp()
264 /* coverity[overrun-buffer-val] */
265 stripe = lov_sub_find(env, subdev, ofid, subconf);
266 if (!IS_ERR(stripe)) {
267 result = lov_init_sub(env, lov, stripe, r0, i);
268 if (result == -EAGAIN) { /* try again */
274 result = PTR_ERR(stripe);
278 int sz = lov_page_slice_fixup(lov, stripe);
280 LASSERT(ergo(psz > 0, psz == sz));
285 cl_object_header(&lov->lo_cl)->coh_page_bufsize += psz;
293 static int lov_init_released(const struct lu_env *env,
294 struct lov_device *dev, struct lov_object *lov,
295 const struct cl_object_conf *conf,
296 union lov_layout_state *state)
298 struct lov_stripe_md *lsm = conf->u.coc_md->lsm;
301 LASSERT(lsm_is_released(lsm));
302 LASSERT(!lov->lo_lsm);
304 lov->lo_lsm = lsm_addref(lsm);
308 static int lov_delete_empty(const struct lu_env *env, struct lov_object *lov,
309 union lov_layout_state *state)
311 LASSERT(lov->lo_type == LLT_EMPTY || lov->lo_type == LLT_RELEASED);
313 lov_layout_wait(env, lov);
317 static void lov_subobject_kill(const struct lu_env *env, struct lov_object *lov,
318 struct lovsub_object *los, int idx)
320 struct cl_object *sub;
321 struct lov_layout_raid0 *r0;
322 struct lu_site *site;
323 struct lu_site_bkt_data *bkt;
324 wait_queue_t *waiter;
327 LASSERT(r0->lo_sub[idx] == los);
329 sub = lovsub2cl(los);
330 site = sub->co_lu.lo_dev->ld_site;
331 bkt = lu_site_bkt_from_fid(site, &sub->co_lu.lo_header->loh_fid);
333 cl_object_kill(env, sub);
334 /* release a reference to the sub-object and ... */
335 lu_object_ref_del(&sub->co_lu, "lov-parent", lov);
336 cl_object_put(env, sub);
338 /* ... wait until it is actually destroyed---sub-object clears its
339 * ->lo_sub[] slot in lovsub_object_fini()
341 if (r0->lo_sub[idx] == los) {
342 waiter = &lov_env_info(env)->lti_waiter;
343 init_waitqueue_entry(waiter, current);
344 add_wait_queue(&bkt->lsb_marche_funebre, waiter);
345 set_current_state(TASK_UNINTERRUPTIBLE);
347 /* this wait-queue is signaled at the end of
350 set_current_state(TASK_UNINTERRUPTIBLE);
351 spin_lock(&r0->lo_sub_lock);
352 if (r0->lo_sub[idx] == los) {
353 spin_unlock(&r0->lo_sub_lock);
356 spin_unlock(&r0->lo_sub_lock);
357 set_current_state(TASK_RUNNING);
361 remove_wait_queue(&bkt->lsb_marche_funebre, waiter);
363 LASSERT(!r0->lo_sub[idx]);
366 static int lov_delete_raid0(const struct lu_env *env, struct lov_object *lov,
367 union lov_layout_state *state)
369 struct lov_layout_raid0 *r0 = &state->raid0;
370 struct lov_stripe_md *lsm = lov->lo_lsm;
373 dump_lsm(D_INODE, lsm);
375 lov_layout_wait(env, lov);
377 for (i = 0; i < r0->lo_nr; ++i) {
378 struct lovsub_object *los = r0->lo_sub[i];
381 cl_object_prune(env, &los->lso_cl);
383 * If top-level object is to be evicted from
384 * the cache, so are its sub-objects.
386 lov_subobject_kill(env, lov, los, i);
393 static void lov_fini_empty(const struct lu_env *env, struct lov_object *lov,
394 union lov_layout_state *state)
396 LASSERT(lov->lo_type == LLT_EMPTY || lov->lo_type == LLT_RELEASED);
399 static void lov_fini_raid0(const struct lu_env *env, struct lov_object *lov,
400 union lov_layout_state *state)
402 struct lov_layout_raid0 *r0 = &state->raid0;
409 dump_lsm(D_INODE, lov->lo_lsm);
410 lov_free_memmd(&lov->lo_lsm);
413 static void lov_fini_released(const struct lu_env *env, struct lov_object *lov,
414 union lov_layout_state *state)
416 dump_lsm(D_INODE, lov->lo_lsm);
417 lov_free_memmd(&lov->lo_lsm);
420 static int lov_print_empty(const struct lu_env *env, void *cookie,
421 lu_printer_t p, const struct lu_object *o)
423 (*p)(env, cookie, "empty %d\n", lu2lov(o)->lo_layout_invalid);
427 static int lov_print_raid0(const struct lu_env *env, void *cookie,
428 lu_printer_t p, const struct lu_object *o)
430 struct lov_object *lov = lu2lov(o);
431 struct lov_layout_raid0 *r0 = lov_r0(lov);
432 struct lov_stripe_md *lsm = lov->lo_lsm;
435 (*p)(env, cookie, "stripes: %d, %s, lsm{%p 0x%08X %d %u %u}:\n",
436 r0->lo_nr, lov->lo_layout_invalid ? "invalid" : "valid", lsm,
437 lsm->lsm_magic, atomic_read(&lsm->lsm_refc),
438 lsm->lsm_stripe_count, lsm->lsm_layout_gen);
439 for (i = 0; i < r0->lo_nr; ++i) {
440 struct lu_object *sub;
443 sub = lovsub2lu(r0->lo_sub[i]);
444 lu_object_print(env, cookie, p, sub);
446 (*p)(env, cookie, "sub %d absent\n", i);
452 static int lov_print_released(const struct lu_env *env, void *cookie,
453 lu_printer_t p, const struct lu_object *o)
455 struct lov_object *lov = lu2lov(o);
456 struct lov_stripe_md *lsm = lov->lo_lsm;
459 "released: %s, lsm{%p 0x%08X %d %u %u}:\n",
460 lov->lo_layout_invalid ? "invalid" : "valid", lsm,
461 lsm->lsm_magic, atomic_read(&lsm->lsm_refc),
462 lsm->lsm_stripe_count, lsm->lsm_layout_gen);
467 * Implements cl_object_operations::coo_attr_get() method for an object
468 * without stripes (LLT_EMPTY layout type).
470 * The only attributes this layer is authoritative in this case is
471 * cl_attr::cat_blocks---it's 0.
473 static int lov_attr_get_empty(const struct lu_env *env, struct cl_object *obj,
474 struct cl_attr *attr)
476 attr->cat_blocks = 0;
480 static int lov_attr_get_raid0(const struct lu_env *env, struct cl_object *obj,
481 struct cl_attr *attr)
483 struct lov_object *lov = cl2lov(obj);
484 struct lov_layout_raid0 *r0 = lov_r0(lov);
485 struct cl_attr *lov_attr = &r0->lo_attr;
488 /* this is called w/o holding type guard mutex, so it must be inside
489 * an on going IO otherwise lsm may be replaced.
490 * LU-2117: it turns out there exists one exception. For mmaped files,
491 * the lock of those files may be requested in the other file's IO
492 * context, and this function is called in ccc_lock_state(), it will
493 * hit this assertion.
494 * Anyway, it's still okay to call attr_get w/o type guard as layout
495 * can't go if locks exist.
497 /* LASSERT(atomic_read(&lsm->lsm_refc) > 1); */
499 if (!r0->lo_attr_valid) {
500 struct lov_stripe_md *lsm = lov->lo_lsm;
501 struct ost_lvb *lvb = &lov_env_info(env)->lti_lvb;
504 memset(lvb, 0, sizeof(*lvb));
505 /* XXX: timestamps can be negative by sanity:test_39m,
508 lvb->lvb_atime = LLONG_MIN;
509 lvb->lvb_ctime = LLONG_MIN;
510 lvb->lvb_mtime = LLONG_MIN;
513 * XXX that should be replaced with a loop over sub-objects,
514 * doing cl_object_attr_get() on them. But for now, let's
515 * reuse old lov code.
519 * XXX take lsm spin-lock to keep lov_merge_lvb_kms()
520 * happy. It's not needed, because new code uses
521 * ->coh_attr_guard spin-lock to protect consistency of
522 * sub-object attributes.
524 lov_stripe_lock(lsm);
525 result = lov_merge_lvb_kms(lsm, lvb, &kms);
526 lov_stripe_unlock(lsm);
528 cl_lvb2attr(lov_attr, lvb);
529 lov_attr->cat_kms = kms;
530 r0->lo_attr_valid = 1;
533 if (result == 0) { /* merge results */
534 attr->cat_blocks = lov_attr->cat_blocks;
535 attr->cat_size = lov_attr->cat_size;
536 attr->cat_kms = lov_attr->cat_kms;
537 if (attr->cat_atime < lov_attr->cat_atime)
538 attr->cat_atime = lov_attr->cat_atime;
539 if (attr->cat_ctime < lov_attr->cat_ctime)
540 attr->cat_ctime = lov_attr->cat_ctime;
541 if (attr->cat_mtime < lov_attr->cat_mtime)
542 attr->cat_mtime = lov_attr->cat_mtime;
547 static const struct lov_layout_operations lov_dispatch[] = {
549 .llo_init = lov_init_empty,
550 .llo_delete = lov_delete_empty,
551 .llo_fini = lov_fini_empty,
552 .llo_install = lov_install_empty,
553 .llo_print = lov_print_empty,
554 .llo_page_init = lov_page_init_empty,
555 .llo_lock_init = lov_lock_init_empty,
556 .llo_io_init = lov_io_init_empty,
557 .llo_getattr = lov_attr_get_empty
560 .llo_init = lov_init_raid0,
561 .llo_delete = lov_delete_raid0,
562 .llo_fini = lov_fini_raid0,
563 .llo_install = lov_install_raid0,
564 .llo_print = lov_print_raid0,
565 .llo_page_init = lov_page_init_raid0,
566 .llo_lock_init = lov_lock_init_raid0,
567 .llo_io_init = lov_io_init_raid0,
568 .llo_getattr = lov_attr_get_raid0
571 .llo_init = lov_init_released,
572 .llo_delete = lov_delete_empty,
573 .llo_fini = lov_fini_released,
574 .llo_install = lov_install_empty,
575 .llo_print = lov_print_released,
576 .llo_page_init = lov_page_init_empty,
577 .llo_lock_init = lov_lock_init_empty,
578 .llo_io_init = lov_io_init_released,
579 .llo_getattr = lov_attr_get_empty
584 * Performs a double-dispatch based on the layout type of an object.
586 #define LOV_2DISPATCH_NOLOCK(obj, op, ...) \
588 struct lov_object *__obj = (obj); \
589 enum lov_layout_type __llt; \
591 __llt = __obj->lo_type; \
592 LASSERT(0 <= __llt && __llt < ARRAY_SIZE(lov_dispatch)); \
593 lov_dispatch[__llt].op(__VA_ARGS__); \
597 * Return lov_layout_type associated with a given lsm
599 static enum lov_layout_type lov_type(struct lov_stripe_md *lsm)
603 if (lsm_is_released(lsm))
608 static inline void lov_conf_freeze(struct lov_object *lov)
610 if (lov->lo_owner != current)
611 down_read(&lov->lo_type_guard);
614 static inline void lov_conf_thaw(struct lov_object *lov)
616 if (lov->lo_owner != current)
617 up_read(&lov->lo_type_guard);
620 #define LOV_2DISPATCH_MAYLOCK(obj, op, lock, ...) \
622 struct lov_object *__obj = (obj); \
623 int __lock = !!(lock); \
624 typeof(lov_dispatch[0].op(__VA_ARGS__)) __result; \
627 lov_conf_freeze(__obj); \
628 __result = LOV_2DISPATCH_NOLOCK(obj, op, __VA_ARGS__); \
630 lov_conf_thaw(__obj); \
635 * Performs a locked double-dispatch based on the layout type of an object.
637 #define LOV_2DISPATCH(obj, op, ...) \
638 LOV_2DISPATCH_MAYLOCK(obj, op, 1, __VA_ARGS__)
640 #define LOV_2DISPATCH_VOID(obj, op, ...) \
642 struct lov_object *__obj = (obj); \
643 enum lov_layout_type __llt; \
645 lov_conf_freeze(__obj); \
646 __llt = __obj->lo_type; \
647 LASSERT(0 <= __llt && __llt < ARRAY_SIZE(lov_dispatch)); \
648 lov_dispatch[__llt].op(__VA_ARGS__); \
649 lov_conf_thaw(__obj); \
652 static void lov_conf_lock(struct lov_object *lov)
654 LASSERT(lov->lo_owner != current);
655 down_write(&lov->lo_type_guard);
656 LASSERT(!lov->lo_owner);
657 lov->lo_owner = current;
660 static void lov_conf_unlock(struct lov_object *lov)
662 lov->lo_owner = NULL;
663 up_write(&lov->lo_type_guard);
666 static int lov_layout_wait(const struct lu_env *env, struct lov_object *lov)
668 struct l_wait_info lwi = { 0 };
670 while (atomic_read(&lov->lo_active_ios) > 0) {
671 CDEBUG(D_INODE, "file:" DFID " wait for active IO, now: %d.\n",
672 PFID(lu_object_fid(lov2lu(lov))),
673 atomic_read(&lov->lo_active_ios));
675 l_wait_event(lov->lo_waitq,
676 atomic_read(&lov->lo_active_ios) == 0, &lwi);
681 static int lov_layout_change(const struct lu_env *unused,
682 struct lov_object *lov,
683 const struct cl_object_conf *conf)
686 enum lov_layout_type llt = LLT_EMPTY;
687 union lov_layout_state *state = &lov->u;
688 const struct lov_layout_operations *old_ops;
689 const struct lov_layout_operations *new_ops;
695 LASSERT(0 <= lov->lo_type && lov->lo_type < ARRAY_SIZE(lov_dispatch));
698 llt = lov_type(conf->u.coc_md->lsm);
699 LASSERT(0 <= llt && llt < ARRAY_SIZE(lov_dispatch));
701 cookie = cl_env_reenter();
702 env = cl_env_get(&refcheck);
704 cl_env_reexit(cookie);
708 CDEBUG(D_INODE, DFID" from %s to %s\n",
709 PFID(lu_object_fid(lov2lu(lov))),
710 llt2str(lov->lo_type), llt2str(llt));
712 old_ops = &lov_dispatch[lov->lo_type];
713 new_ops = &lov_dispatch[llt];
715 result = cl_object_prune(env, &lov->lo_cl);
719 result = old_ops->llo_delete(env, lov, &lov->u);
721 old_ops->llo_fini(env, lov, &lov->u);
723 LASSERT(atomic_read(&lov->lo_active_ios) == 0);
725 lov->lo_type = LLT_EMPTY;
726 result = new_ops->llo_init(env,
727 lu2lov_dev(lov->lo_cl.co_lu.lo_dev),
730 new_ops->llo_install(env, lov, state);
733 new_ops->llo_delete(env, lov, state);
734 new_ops->llo_fini(env, lov, state);
735 /* this file becomes an EMPTY file. */
740 cl_env_put(env, &refcheck);
741 cl_env_reexit(cookie);
745 /*****************************************************************************
747 * Lov object operations.
750 int lov_object_init(const struct lu_env *env, struct lu_object *obj,
751 const struct lu_object_conf *conf)
753 struct lov_device *dev = lu2lov_dev(obj->lo_dev);
754 struct lov_object *lov = lu2lov(obj);
755 const struct cl_object_conf *cconf = lu2cl_conf(conf);
756 union lov_layout_state *set = &lov->u;
757 const struct lov_layout_operations *ops;
760 init_rwsem(&lov->lo_type_guard);
761 atomic_set(&lov->lo_active_ios, 0);
762 init_waitqueue_head(&lov->lo_waitq);
764 cl_object_page_init(lu2cl(obj), sizeof(struct lov_page));
766 /* no locking is necessary, as object is being created */
767 lov->lo_type = lov_type(cconf->u.coc_md->lsm);
768 ops = &lov_dispatch[lov->lo_type];
769 result = ops->llo_init(env, dev, lov, cconf, set);
771 ops->llo_install(env, lov, set);
775 static int lov_conf_set(const struct lu_env *env, struct cl_object *obj,
776 const struct cl_object_conf *conf)
778 struct lov_stripe_md *lsm = NULL;
779 struct lov_object *lov = cl2lov(obj);
783 if (conf->coc_opc == OBJECT_CONF_INVALIDATE) {
784 lov->lo_layout_invalid = true;
789 if (conf->coc_opc == OBJECT_CONF_WAIT) {
790 if (lov->lo_layout_invalid &&
791 atomic_read(&lov->lo_active_ios) > 0) {
792 lov_conf_unlock(lov);
793 result = lov_layout_wait(env, lov);
799 LASSERT(conf->coc_opc == OBJECT_CONF_SET);
802 lsm = conf->u.coc_md->lsm;
803 if ((!lsm && !lov->lo_lsm) ||
804 ((lsm && lov->lo_lsm) &&
805 (lov->lo_lsm->lsm_layout_gen == lsm->lsm_layout_gen) &&
806 (lov->lo_lsm->lsm_pattern == lsm->lsm_pattern))) {
807 /* same version of layout */
808 lov->lo_layout_invalid = false;
813 /* will change layout - check if there still exists active IO. */
814 if (atomic_read(&lov->lo_active_ios) > 0) {
815 lov->lo_layout_invalid = true;
820 result = lov_layout_change(env, lov, conf);
821 lov->lo_layout_invalid = result != 0;
824 lov_conf_unlock(lov);
825 CDEBUG(D_INODE, DFID" lo_layout_invalid=%d\n",
826 PFID(lu_object_fid(lov2lu(lov))), lov->lo_layout_invalid);
830 static void lov_object_delete(const struct lu_env *env, struct lu_object *obj)
832 struct lov_object *lov = lu2lov(obj);
834 LOV_2DISPATCH_VOID(lov, llo_delete, env, lov, &lov->u);
837 static void lov_object_free(const struct lu_env *env, struct lu_object *obj)
839 struct lov_object *lov = lu2lov(obj);
841 LOV_2DISPATCH_VOID(lov, llo_fini, env, lov, &lov->u);
843 kmem_cache_free(lov_object_kmem, lov);
846 static int lov_object_print(const struct lu_env *env, void *cookie,
847 lu_printer_t p, const struct lu_object *o)
849 return LOV_2DISPATCH_NOLOCK(lu2lov(o), llo_print, env, cookie, p, o);
852 int lov_page_init(const struct lu_env *env, struct cl_object *obj,
853 struct cl_page *page, pgoff_t index)
855 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_page_init, env, obj, page,
860 * Implements cl_object_operations::clo_io_init() method for lov
861 * layer. Dispatches to the appropriate layout io initialization method.
863 int lov_io_init(const struct lu_env *env, struct cl_object *obj,
866 CL_IO_SLICE_CLEAN(lov_env_io(env), lis_cl);
867 return LOV_2DISPATCH_MAYLOCK(cl2lov(obj), llo_io_init,
868 !io->ci_ignore_layout, env, obj, io);
872 * An implementation of cl_object_operations::clo_attr_get() method for lov
873 * layer. For raid0 layout this collects and merges attributes of all
876 static int lov_attr_get(const struct lu_env *env, struct cl_object *obj,
877 struct cl_attr *attr)
879 /* do not take lock, as this function is called under a
880 * spin-lock. Layout is protected from changing by ongoing IO.
882 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_getattr, env, obj, attr);
885 static int lov_attr_set(const struct lu_env *env, struct cl_object *obj,
886 const struct cl_attr *attr, unsigned valid)
889 * No dispatch is required here, as no layout implements this.
894 int lov_lock_init(const struct lu_env *env, struct cl_object *obj,
895 struct cl_lock *lock, const struct cl_io *io)
897 /* No need to lock because we've taken one refcount of layout. */
898 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_lock_init, env, obj, lock,
902 static const struct cl_object_operations lov_ops = {
903 .coo_page_init = lov_page_init,
904 .coo_lock_init = lov_lock_init,
905 .coo_io_init = lov_io_init,
906 .coo_attr_get = lov_attr_get,
907 .coo_attr_set = lov_attr_set,
908 .coo_conf_set = lov_conf_set
911 static const struct lu_object_operations lov_lu_obj_ops = {
912 .loo_object_init = lov_object_init,
913 .loo_object_delete = lov_object_delete,
914 .loo_object_release = NULL,
915 .loo_object_free = lov_object_free,
916 .loo_object_print = lov_object_print,
917 .loo_object_invariant = NULL
920 struct lu_object *lov_object_alloc(const struct lu_env *env,
921 const struct lu_object_header *unused,
922 struct lu_device *dev)
924 struct lov_object *lov;
925 struct lu_object *obj;
927 lov = kmem_cache_zalloc(lov_object_kmem, GFP_NOFS);
930 lu_object_init(obj, NULL, dev);
931 lov->lo_cl.co_ops = &lov_ops;
932 lov->lo_type = -1; /* invalid, to catch uninitialized type */
934 * object io operation vector (cl_object::co_iop) is installed
935 * later in lov_object_init(), as different vectors are used
936 * for object with different layouts.
938 obj->lo_ops = &lov_lu_obj_ops;
945 static struct lov_stripe_md *lov_lsm_addref(struct lov_object *lov)
947 struct lov_stripe_md *lsm = NULL;
949 lov_conf_freeze(lov);
951 lsm = lsm_addref(lov->lo_lsm);
952 CDEBUG(D_INODE, "lsm %p addref %d/%d by %p.\n",
953 lsm, atomic_read(&lsm->lsm_refc),
954 lov->lo_layout_invalid, current);
960 struct lov_stripe_md *lov_lsm_get(struct cl_object *clobj)
962 struct lu_object *luobj;
963 struct lov_stripe_md *lsm = NULL;
968 luobj = lu_object_locate(&cl_object_header(clobj)->coh_lu,
971 lsm = lov_lsm_addref(lu2lov(luobj));
974 EXPORT_SYMBOL(lov_lsm_get);
976 void lov_lsm_put(struct cl_object *unused, struct lov_stripe_md *lsm)
979 lov_free_memmd(&lsm);
981 EXPORT_SYMBOL(lov_lsm_put);
983 int lov_read_and_clear_async_rc(struct cl_object *clob)
985 struct lu_object *luobj;
988 luobj = lu_object_locate(&cl_object_header(clob)->coh_lu,
991 struct lov_object *lov = lu2lov(luobj);
993 lov_conf_freeze(lov);
994 switch (lov->lo_type) {
996 struct lov_stripe_md *lsm;
1000 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1001 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
1003 if (lov_oinfo_is_dummy(loi))
1006 if (loi->loi_ar.ar_rc && !rc)
1007 rc = loi->loi_ar.ar_rc;
1008 loi->loi_ar.ar_rc = 0;
1021 EXPORT_SYMBOL(lov_read_and_clear_async_rc);