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, 2012, 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, struct page *vmpage);
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
139 cl_object_kill(env, stripe);
140 cl_object_put(env, stripe);
144 hdr = cl_object_header(lov2cl(lov));
145 subhdr = cl_object_header(stripe);
147 oinfo = lov->lo_lsm->lsm_oinfo[idx];
148 CDEBUG(D_INODE, DFID"@%p[%d] -> "DFID"@%p: ostid: "DOSTID
149 " idx: %d gen: %d\n",
150 PFID(&subhdr->coh_lu.loh_fid), subhdr, idx,
151 PFID(&hdr->coh_lu.loh_fid), hdr, POSTID(&oinfo->loi_oi),
152 oinfo->loi_ost_idx, oinfo->loi_ost_gen);
154 /* reuse ->coh_attr_guard to protect coh_parent change */
155 spin_lock(&subhdr->coh_attr_guard);
156 parent = subhdr->coh_parent;
157 if (parent == NULL) {
158 subhdr->coh_parent = hdr;
159 spin_unlock(&subhdr->coh_attr_guard);
160 subhdr->coh_nesting = hdr->coh_nesting + 1;
161 lu_object_ref_add(&stripe->co_lu, "lov-parent", lov);
162 r0->lo_sub[idx] = cl2lovsub(stripe);
163 r0->lo_sub[idx]->lso_super = lov;
164 r0->lo_sub[idx]->lso_index = idx;
167 struct lu_object *old_obj;
168 struct lov_object *old_lov;
169 unsigned int mask = D_INODE;
171 spin_unlock(&subhdr->coh_attr_guard);
172 old_obj = lu_object_locate(&parent->coh_lu, &lov_device_type);
173 LASSERT(old_obj != NULL);
174 old_lov = cl2lov(lu2cl(old_obj));
175 if (old_lov->lo_layout_invalid) {
176 /* the object's layout has already changed but isn't
178 lu_object_unhash(env, &stripe->co_lu);
185 LU_OBJECT_DEBUG(mask, env, &stripe->co_lu,
186 "stripe %d is already owned.\n", idx);
187 LU_OBJECT_DEBUG(mask, env, old_obj, "owned.\n");
188 LU_OBJECT_HEADER(mask, env, lov2lu(lov), "try to own.\n");
189 cl_object_put(env, stripe);
194 static int lov_init_raid0(const struct lu_env *env,
195 struct lov_device *dev, struct lov_object *lov,
196 const struct cl_object_conf *conf,
197 union lov_layout_state *state)
202 struct cl_object *stripe;
203 struct lov_thread_info *lti = lov_env_info(env);
204 struct cl_object_conf *subconf = <i->lti_stripe_conf;
205 struct lov_stripe_md *lsm = conf->u.coc_md->lsm;
206 struct lu_fid *ofid = <i->lti_fid;
207 struct lov_layout_raid0 *r0 = &state->raid0;
209 if (lsm->lsm_magic != LOV_MAGIC_V1 && lsm->lsm_magic != LOV_MAGIC_V3) {
210 dump_lsm(D_ERROR, lsm);
211 LASSERTF(0, "magic mismatch, expected %d/%d, actual %d.\n",
212 LOV_MAGIC_V1, LOV_MAGIC_V3, lsm->lsm_magic);
215 LASSERT(lov->lo_lsm == NULL);
216 lov->lo_lsm = lsm_addref(lsm);
217 r0->lo_nr = lsm->lsm_stripe_count;
218 LASSERT(r0->lo_nr <= lov_targets_nr(dev));
220 OBD_ALLOC_LARGE(r0->lo_sub, r0->lo_nr * sizeof(r0->lo_sub[0]));
221 if (r0->lo_sub != NULL) {
223 subconf->coc_inode = conf->coc_inode;
224 spin_lock_init(&r0->lo_sub_lock);
226 * Create stripe cl_objects.
228 for (i = 0; i < r0->lo_nr && result == 0; ++i) {
229 struct cl_device *subdev;
230 struct lov_oinfo *oinfo = lsm->lsm_oinfo[i];
231 int ost_idx = oinfo->loi_ost_idx;
233 if (lov_oinfo_is_dummy(oinfo))
236 result = ostid_to_fid(ofid, &oinfo->loi_oi,
241 subdev = lovsub2cl_dev(dev->ld_target[ost_idx]);
242 subconf->u.coc_oinfo = oinfo;
243 LASSERTF(subdev != NULL, "not init ost %d\n", ost_idx);
244 /* In the function below, .hs_keycmp resolves to
245 * lu_obj_hop_keycmp() */
246 /* coverity[overrun-buffer-val] */
247 stripe = lov_sub_find(env, subdev, ofid, subconf);
248 if (!IS_ERR(stripe)) {
249 result = lov_init_sub(env, lov, stripe, r0, i);
250 if (result == -EAGAIN) { /* try again */
255 result = PTR_ERR(stripe);
264 static int lov_init_released(const struct lu_env *env,
265 struct lov_device *dev, struct lov_object *lov,
266 const struct cl_object_conf *conf,
267 union lov_layout_state *state)
269 struct lov_stripe_md *lsm = conf->u.coc_md->lsm;
271 LASSERT(lsm != NULL);
272 LASSERT(lsm_is_released(lsm));
273 LASSERT(lov->lo_lsm == NULL);
275 lov->lo_lsm = lsm_addref(lsm);
279 static int lov_delete_empty(const struct lu_env *env, struct lov_object *lov,
280 union lov_layout_state *state)
282 LASSERT(lov->lo_type == LLT_EMPTY || lov->lo_type == LLT_RELEASED);
284 lov_layout_wait(env, lov);
286 cl_object_prune(env, &lov->lo_cl);
290 static void lov_subobject_kill(const struct lu_env *env, struct lov_object *lov,
291 struct lovsub_object *los, int idx)
293 struct cl_object *sub;
294 struct lov_layout_raid0 *r0;
295 struct lu_site *site;
296 struct lu_site_bkt_data *bkt;
297 wait_queue_t *waiter;
300 LASSERT(r0->lo_sub[idx] == los);
302 sub = lovsub2cl(los);
303 site = sub->co_lu.lo_dev->ld_site;
304 bkt = lu_site_bkt_from_fid(site, &sub->co_lu.lo_header->loh_fid);
306 cl_object_kill(env, sub);
307 /* release a reference to the sub-object and ... */
308 lu_object_ref_del(&sub->co_lu, "lov-parent", lov);
309 cl_object_put(env, sub);
311 /* ... wait until it is actually destroyed---sub-object clears its
312 * ->lo_sub[] slot in lovsub_object_fini() */
313 if (r0->lo_sub[idx] == los) {
314 waiter = &lov_env_info(env)->lti_waiter;
315 init_waitqueue_entry(waiter, current);
316 add_wait_queue(&bkt->lsb_marche_funebre, waiter);
317 set_current_state(TASK_UNINTERRUPTIBLE);
319 /* this wait-queue is signaled at the end of
320 * lu_object_free(). */
321 set_current_state(TASK_UNINTERRUPTIBLE);
322 spin_lock(&r0->lo_sub_lock);
323 if (r0->lo_sub[idx] == los) {
324 spin_unlock(&r0->lo_sub_lock);
327 spin_unlock(&r0->lo_sub_lock);
328 set_current_state(TASK_RUNNING);
332 remove_wait_queue(&bkt->lsb_marche_funebre, waiter);
334 LASSERT(r0->lo_sub[idx] == NULL);
337 static int lov_delete_raid0(const struct lu_env *env, struct lov_object *lov,
338 union lov_layout_state *state)
340 struct lov_layout_raid0 *r0 = &state->raid0;
341 struct lov_stripe_md *lsm = lov->lo_lsm;
344 dump_lsm(D_INODE, lsm);
346 lov_layout_wait(env, lov);
347 if (r0->lo_sub != NULL) {
348 for (i = 0; i < r0->lo_nr; ++i) {
349 struct lovsub_object *los = r0->lo_sub[i];
352 cl_locks_prune(env, &los->lso_cl, 1);
354 * If top-level object is to be evicted from
355 * the cache, so are its sub-objects.
357 lov_subobject_kill(env, lov, los, i);
361 cl_object_prune(env, &lov->lo_cl);
365 static void lov_fini_empty(const struct lu_env *env, struct lov_object *lov,
366 union lov_layout_state *state)
368 LASSERT(lov->lo_type == LLT_EMPTY || lov->lo_type == LLT_RELEASED);
371 static void lov_fini_raid0(const struct lu_env *env, struct lov_object *lov,
372 union lov_layout_state *state)
374 struct lov_layout_raid0 *r0 = &state->raid0;
376 if (r0->lo_sub != NULL) {
377 OBD_FREE_LARGE(r0->lo_sub, r0->lo_nr * sizeof(r0->lo_sub[0]));
381 dump_lsm(D_INODE, lov->lo_lsm);
382 lov_free_memmd(&lov->lo_lsm);
385 static void lov_fini_released(const struct lu_env *env, struct lov_object *lov,
386 union lov_layout_state *state)
388 dump_lsm(D_INODE, lov->lo_lsm);
389 lov_free_memmd(&lov->lo_lsm);
392 static int lov_print_empty(const struct lu_env *env, void *cookie,
393 lu_printer_t p, const struct lu_object *o)
395 (*p)(env, cookie, "empty %d\n", lu2lov(o)->lo_layout_invalid);
399 static int lov_print_raid0(const struct lu_env *env, void *cookie,
400 lu_printer_t p, const struct lu_object *o)
402 struct lov_object *lov = lu2lov(o);
403 struct lov_layout_raid0 *r0 = lov_r0(lov);
404 struct lov_stripe_md *lsm = lov->lo_lsm;
407 (*p)(env, cookie, "stripes: %d, %s, lsm{%p 0x%08X %d %u %u}:\n",
408 r0->lo_nr, lov->lo_layout_invalid ? "invalid" : "valid", lsm,
409 lsm->lsm_magic, atomic_read(&lsm->lsm_refc),
410 lsm->lsm_stripe_count, lsm->lsm_layout_gen);
411 for (i = 0; i < r0->lo_nr; ++i) {
412 struct lu_object *sub;
414 if (r0->lo_sub[i] != NULL) {
415 sub = lovsub2lu(r0->lo_sub[i]);
416 lu_object_print(env, cookie, p, sub);
418 (*p)(env, cookie, "sub %d absent\n", i);
424 static int lov_print_released(const struct lu_env *env, void *cookie,
425 lu_printer_t p, const struct lu_object *o)
427 struct lov_object *lov = lu2lov(o);
428 struct lov_stripe_md *lsm = lov->lo_lsm;
431 "released: %s, lsm{%p 0x%08X %d %u %u}:\n",
432 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);
439 * Implements cl_object_operations::coo_attr_get() method for an object
440 * without stripes (LLT_EMPTY layout type).
442 * The only attributes this layer is authoritative in this case is
443 * cl_attr::cat_blocks---it's 0.
445 static int lov_attr_get_empty(const struct lu_env *env, struct cl_object *obj,
446 struct cl_attr *attr)
448 attr->cat_blocks = 0;
452 static int lov_attr_get_raid0(const struct lu_env *env, struct cl_object *obj,
453 struct cl_attr *attr)
455 struct lov_object *lov = cl2lov(obj);
456 struct lov_layout_raid0 *r0 = lov_r0(lov);
457 struct cl_attr *lov_attr = &r0->lo_attr;
460 /* this is called w/o holding type guard mutex, so it must be inside
461 * an on going IO otherwise lsm may be replaced.
462 * LU-2117: it turns out there exists one exception. For mmaped files,
463 * the lock of those files may be requested in the other file's IO
464 * context, and this function is called in ccc_lock_state(), it will
465 * hit this assertion.
466 * Anyway, it's still okay to call attr_get w/o type guard as layout
467 * can't go if locks exist. */
468 /* LASSERT(atomic_read(&lsm->lsm_refc) > 1); */
470 if (!r0->lo_attr_valid) {
471 struct lov_stripe_md *lsm = lov->lo_lsm;
472 struct ost_lvb *lvb = &lov_env_info(env)->lti_lvb;
475 memset(lvb, 0, sizeof(*lvb));
476 /* XXX: timestamps can be negative by sanity:test_39m,
478 lvb->lvb_atime = LLONG_MIN;
479 lvb->lvb_ctime = LLONG_MIN;
480 lvb->lvb_mtime = LLONG_MIN;
483 * XXX that should be replaced with a loop over sub-objects,
484 * doing cl_object_attr_get() on them. But for now, let's
485 * reuse old lov code.
489 * XXX take lsm spin-lock to keep lov_merge_lvb_kms()
490 * happy. It's not needed, because new code uses
491 * ->coh_attr_guard spin-lock to protect consistency of
492 * sub-object attributes.
494 lov_stripe_lock(lsm);
495 result = lov_merge_lvb_kms(lsm, lvb, &kms);
496 lov_stripe_unlock(lsm);
498 cl_lvb2attr(lov_attr, lvb);
499 lov_attr->cat_kms = kms;
500 r0->lo_attr_valid = 1;
503 if (result == 0) { /* merge results */
504 attr->cat_blocks = lov_attr->cat_blocks;
505 attr->cat_size = lov_attr->cat_size;
506 attr->cat_kms = lov_attr->cat_kms;
507 if (attr->cat_atime < lov_attr->cat_atime)
508 attr->cat_atime = lov_attr->cat_atime;
509 if (attr->cat_ctime < lov_attr->cat_ctime)
510 attr->cat_ctime = lov_attr->cat_ctime;
511 if (attr->cat_mtime < lov_attr->cat_mtime)
512 attr->cat_mtime = lov_attr->cat_mtime;
517 static const struct lov_layout_operations lov_dispatch[] = {
519 .llo_init = lov_init_empty,
520 .llo_delete = lov_delete_empty,
521 .llo_fini = lov_fini_empty,
522 .llo_install = lov_install_empty,
523 .llo_print = lov_print_empty,
524 .llo_page_init = lov_page_init_empty,
525 .llo_lock_init = lov_lock_init_empty,
526 .llo_io_init = lov_io_init_empty,
527 .llo_getattr = lov_attr_get_empty
530 .llo_init = lov_init_raid0,
531 .llo_delete = lov_delete_raid0,
532 .llo_fini = lov_fini_raid0,
533 .llo_install = lov_install_raid0,
534 .llo_print = lov_print_raid0,
535 .llo_page_init = lov_page_init_raid0,
536 .llo_lock_init = lov_lock_init_raid0,
537 .llo_io_init = lov_io_init_raid0,
538 .llo_getattr = lov_attr_get_raid0
541 .llo_init = lov_init_released,
542 .llo_delete = lov_delete_empty,
543 .llo_fini = lov_fini_released,
544 .llo_install = lov_install_empty,
545 .llo_print = lov_print_released,
546 .llo_page_init = lov_page_init_empty,
547 .llo_lock_init = lov_lock_init_empty,
548 .llo_io_init = lov_io_init_released,
549 .llo_getattr = lov_attr_get_empty
554 * Performs a double-dispatch based on the layout type of an object.
556 #define LOV_2DISPATCH_NOLOCK(obj, op, ...) \
558 struct lov_object *__obj = (obj); \
559 enum lov_layout_type __llt; \
561 __llt = __obj->lo_type; \
562 LASSERT(0 <= __llt && __llt < ARRAY_SIZE(lov_dispatch)); \
563 lov_dispatch[__llt].op(__VA_ARGS__); \
567 * Return lov_layout_type associated with a given lsm
569 static enum lov_layout_type lov_type(struct lov_stripe_md *lsm)
573 if (lsm_is_released(lsm))
578 static inline void lov_conf_freeze(struct lov_object *lov)
580 if (lov->lo_owner != current)
581 down_read(&lov->lo_type_guard);
584 static inline void lov_conf_thaw(struct lov_object *lov)
586 if (lov->lo_owner != current)
587 up_read(&lov->lo_type_guard);
590 #define LOV_2DISPATCH_MAYLOCK(obj, op, lock, ...) \
592 struct lov_object *__obj = (obj); \
593 int __lock = !!(lock); \
594 typeof(lov_dispatch[0].op(__VA_ARGS__)) __result; \
597 lov_conf_freeze(__obj); \
598 __result = LOV_2DISPATCH_NOLOCK(obj, op, __VA_ARGS__); \
600 lov_conf_thaw(__obj); \
605 * Performs a locked double-dispatch based on the layout type of an object.
607 #define LOV_2DISPATCH(obj, op, ...) \
608 LOV_2DISPATCH_MAYLOCK(obj, op, 1, __VA_ARGS__)
610 #define LOV_2DISPATCH_VOID(obj, op, ...) \
612 struct lov_object *__obj = (obj); \
613 enum lov_layout_type __llt; \
615 lov_conf_freeze(__obj); \
616 __llt = __obj->lo_type; \
617 LASSERT(0 <= __llt && __llt < ARRAY_SIZE(lov_dispatch)); \
618 lov_dispatch[__llt].op(__VA_ARGS__); \
619 lov_conf_thaw(__obj); \
622 static void lov_conf_lock(struct lov_object *lov)
624 LASSERT(lov->lo_owner != current);
625 down_write(&lov->lo_type_guard);
626 LASSERT(lov->lo_owner == NULL);
627 lov->lo_owner = current;
630 static void lov_conf_unlock(struct lov_object *lov)
632 lov->lo_owner = NULL;
633 up_write(&lov->lo_type_guard);
636 static int lov_layout_wait(const struct lu_env *env, struct lov_object *lov)
638 struct l_wait_info lwi = { 0 };
640 while (atomic_read(&lov->lo_active_ios) > 0) {
641 CDEBUG(D_INODE, "file:"DFID" wait for active IO, now: %d.\n",
642 PFID(lu_object_fid(lov2lu(lov))),
643 atomic_read(&lov->lo_active_ios));
645 l_wait_event(lov->lo_waitq,
646 atomic_read(&lov->lo_active_ios) == 0, &lwi);
651 static int lov_layout_change(const struct lu_env *unused,
652 struct lov_object *lov,
653 const struct cl_object_conf *conf)
656 enum lov_layout_type llt = LLT_EMPTY;
657 union lov_layout_state *state = &lov->u;
658 const struct lov_layout_operations *old_ops;
659 const struct lov_layout_operations *new_ops;
661 struct cl_object_header *hdr = cl_object_header(&lov->lo_cl);
666 LASSERT(0 <= lov->lo_type && lov->lo_type < ARRAY_SIZE(lov_dispatch));
668 if (conf->u.coc_md != NULL)
669 llt = lov_type(conf->u.coc_md->lsm);
670 LASSERT(0 <= llt && llt < ARRAY_SIZE(lov_dispatch));
672 cookie = cl_env_reenter();
673 env = cl_env_get(&refcheck);
675 cl_env_reexit(cookie);
679 CDEBUG(D_INODE, DFID" from %s to %s\n",
680 PFID(lu_object_fid(lov2lu(lov))),
681 llt2str(lov->lo_type), llt2str(llt));
683 old_ops = &lov_dispatch[lov->lo_type];
684 new_ops = &lov_dispatch[llt];
686 result = old_ops->llo_delete(env, lov, &lov->u);
688 old_ops->llo_fini(env, lov, &lov->u);
690 LASSERT(atomic_read(&lov->lo_active_ios) == 0);
691 LASSERT(hdr->coh_tree.rnode == NULL);
692 LASSERT(hdr->coh_pages == 0);
694 lov->lo_type = LLT_EMPTY;
695 result = new_ops->llo_init(env,
696 lu2lov_dev(lov->lo_cl.co_lu.lo_dev),
699 new_ops->llo_install(env, lov, state);
702 new_ops->llo_delete(env, lov, state);
703 new_ops->llo_fini(env, lov, state);
704 /* this file becomes an EMPTY file. */
708 cl_env_put(env, &refcheck);
709 cl_env_reexit(cookie);
713 /*****************************************************************************
715 * Lov object operations.
718 int lov_object_init(const struct lu_env *env, struct lu_object *obj,
719 const struct lu_object_conf *conf)
721 struct lov_device *dev = lu2lov_dev(obj->lo_dev);
722 struct lov_object *lov = lu2lov(obj);
723 const struct cl_object_conf *cconf = lu2cl_conf(conf);
724 union lov_layout_state *set = &lov->u;
725 const struct lov_layout_operations *ops;
728 init_rwsem(&lov->lo_type_guard);
729 atomic_set(&lov->lo_active_ios, 0);
730 init_waitqueue_head(&lov->lo_waitq);
732 cl_object_page_init(lu2cl(obj), sizeof(struct lov_page));
734 /* no locking is necessary, as object is being created */
735 lov->lo_type = lov_type(cconf->u.coc_md->lsm);
736 ops = &lov_dispatch[lov->lo_type];
737 result = ops->llo_init(env, dev, lov, cconf, set);
739 ops->llo_install(env, lov, set);
743 static int lov_conf_set(const struct lu_env *env, struct cl_object *obj,
744 const struct cl_object_conf *conf)
746 struct lov_stripe_md *lsm = NULL;
747 struct lov_object *lov = cl2lov(obj);
751 if (conf->coc_opc == OBJECT_CONF_INVALIDATE) {
752 lov->lo_layout_invalid = true;
757 if (conf->coc_opc == OBJECT_CONF_WAIT) {
758 if (lov->lo_layout_invalid &&
759 atomic_read(&lov->lo_active_ios) > 0) {
760 lov_conf_unlock(lov);
761 result = lov_layout_wait(env, lov);
767 LASSERT(conf->coc_opc == OBJECT_CONF_SET);
769 if (conf->u.coc_md != NULL)
770 lsm = conf->u.coc_md->lsm;
771 if ((lsm == NULL && lov->lo_lsm == NULL) ||
772 ((lsm != NULL && lov->lo_lsm != NULL) &&
773 (lov->lo_lsm->lsm_layout_gen == lsm->lsm_layout_gen) &&
774 (lov->lo_lsm->lsm_pattern == lsm->lsm_pattern))) {
775 /* same version of layout */
776 lov->lo_layout_invalid = false;
781 /* will change layout - check if there still exists active IO. */
782 if (atomic_read(&lov->lo_active_ios) > 0) {
783 lov->lo_layout_invalid = true;
788 lov->lo_layout_invalid = lov_layout_change(env, lov, conf);
791 lov_conf_unlock(lov);
792 CDEBUG(D_INODE, DFID" lo_layout_invalid=%d\n",
793 PFID(lu_object_fid(lov2lu(lov))), lov->lo_layout_invalid);
797 static void lov_object_delete(const struct lu_env *env, struct lu_object *obj)
799 struct lov_object *lov = lu2lov(obj);
801 LOV_2DISPATCH_VOID(lov, llo_delete, env, lov, &lov->u);
804 static void lov_object_free(const struct lu_env *env, struct lu_object *obj)
806 struct lov_object *lov = lu2lov(obj);
808 LOV_2DISPATCH_VOID(lov, llo_fini, env, lov, &lov->u);
810 OBD_SLAB_FREE_PTR(lov, lov_object_kmem);
813 static int lov_object_print(const struct lu_env *env, void *cookie,
814 lu_printer_t p, const struct lu_object *o)
816 return LOV_2DISPATCH_NOLOCK(lu2lov(o), llo_print, env, cookie, p, o);
819 int lov_page_init(const struct lu_env *env, struct cl_object *obj,
820 struct cl_page *page, struct page *vmpage)
822 return LOV_2DISPATCH_NOLOCK(cl2lov(obj),
823 llo_page_init, env, obj, page, vmpage);
827 * Implements cl_object_operations::clo_io_init() method for lov
828 * layer. Dispatches to the appropriate layout io initialization method.
830 int lov_io_init(const struct lu_env *env, struct cl_object *obj,
833 CL_IO_SLICE_CLEAN(lov_env_io(env), lis_cl);
834 return LOV_2DISPATCH_MAYLOCK(cl2lov(obj), llo_io_init,
835 !io->ci_ignore_layout, env, obj, io);
839 * An implementation of cl_object_operations::clo_attr_get() method for lov
840 * layer. For raid0 layout this collects and merges attributes of all
843 static int lov_attr_get(const struct lu_env *env, struct cl_object *obj,
844 struct cl_attr *attr)
846 /* do not take lock, as this function is called under a
847 * spin-lock. Layout is protected from changing by ongoing IO. */
848 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_getattr, env, obj, attr);
851 static int lov_attr_set(const struct lu_env *env, struct cl_object *obj,
852 const struct cl_attr *attr, unsigned valid)
855 * No dispatch is required here, as no layout implements this.
860 int lov_lock_init(const struct lu_env *env, struct cl_object *obj,
861 struct cl_lock *lock, const struct cl_io *io)
863 /* No need to lock because we've taken one refcount of layout. */
864 return LOV_2DISPATCH_NOLOCK(cl2lov(obj), llo_lock_init, env, obj, lock,
868 static const struct cl_object_operations lov_ops = {
869 .coo_page_init = lov_page_init,
870 .coo_lock_init = lov_lock_init,
871 .coo_io_init = lov_io_init,
872 .coo_attr_get = lov_attr_get,
873 .coo_attr_set = lov_attr_set,
874 .coo_conf_set = lov_conf_set
877 static const struct lu_object_operations lov_lu_obj_ops = {
878 .loo_object_init = lov_object_init,
879 .loo_object_delete = lov_object_delete,
880 .loo_object_release = NULL,
881 .loo_object_free = lov_object_free,
882 .loo_object_print = lov_object_print,
883 .loo_object_invariant = NULL
886 struct lu_object *lov_object_alloc(const struct lu_env *env,
887 const struct lu_object_header *unused,
888 struct lu_device *dev)
890 struct lov_object *lov;
891 struct lu_object *obj;
893 OBD_SLAB_ALLOC_PTR_GFP(lov, lov_object_kmem, GFP_NOFS);
896 lu_object_init(obj, NULL, dev);
897 lov->lo_cl.co_ops = &lov_ops;
898 lov->lo_type = -1; /* invalid, to catch uninitialized type */
900 * object io operation vector (cl_object::co_iop) is installed
901 * later in lov_object_init(), as different vectors are used
902 * for object with different layouts.
904 obj->lo_ops = &lov_lu_obj_ops;
910 struct lov_stripe_md *lov_lsm_addref(struct lov_object *lov)
912 struct lov_stripe_md *lsm = NULL;
914 lov_conf_freeze(lov);
915 if (lov->lo_lsm != NULL) {
916 lsm = lsm_addref(lov->lo_lsm);
917 CDEBUG(D_INODE, "lsm %p addref %d/%d by %p.\n",
918 lsm, atomic_read(&lsm->lsm_refc),
919 lov->lo_layout_invalid, current);
925 void lov_lsm_decref(struct lov_object *lov, struct lov_stripe_md *lsm)
930 CDEBUG(D_INODE, "lsm %p decref %d by %p.\n",
931 lsm, atomic_read(&lsm->lsm_refc), current);
933 lov_free_memmd(&lsm);
936 struct lov_stripe_md *lov_lsm_get(struct cl_object *clobj)
938 struct lu_object *luobj;
939 struct lov_stripe_md *lsm = NULL;
944 luobj = lu_object_locate(&cl_object_header(clobj)->coh_lu,
947 lsm = lov_lsm_addref(lu2lov(luobj));
950 EXPORT_SYMBOL(lov_lsm_get);
952 void lov_lsm_put(struct cl_object *unused, struct lov_stripe_md *lsm)
955 lov_free_memmd(&lsm);
957 EXPORT_SYMBOL(lov_lsm_put);
959 int lov_read_and_clear_async_rc(struct cl_object *clob)
961 struct lu_object *luobj;
964 luobj = lu_object_locate(&cl_object_header(clob)->coh_lu,
967 struct lov_object *lov = lu2lov(luobj);
969 lov_conf_freeze(lov);
970 switch (lov->lo_type) {
972 struct lov_stripe_md *lsm;
976 LASSERT(lsm != NULL);
977 for (i = 0; i < lsm->lsm_stripe_count; i++) {
978 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
980 if (lov_oinfo_is_dummy(loi))
983 if (loi->loi_ar.ar_rc && !rc)
984 rc = loi->loi_ar.ar_rc;
985 loi->loi_ar.ar_rc = 0;
998 EXPORT_SYMBOL(lov_read_and_clear_async_rc);