1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
5 * Author: Phil Schwan <phil@clusterfs.com>
6 * Peter Braam <braam@clusterfs.com>
7 * Mike Shaver <shaver@clusterfs.com>
9 * This file is part of Lustre, http://www.lustre.org.
11 * Lustre is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General Public
13 * License as published by the Free Software Foundation.
15 * Lustre is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Lustre; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 # define EXPORT_SYMTAB
28 #define DEBUG_SUBSYSTEM S_LOV
30 #include <linux/slab.h>
31 #include <linux/module.h>
32 #include <linux/init.h>
33 #include <linux/slab.h>
34 #include <linux/pagemap.h>
35 #include <linux/seq_file.h>
36 #include <asm/div64.h>
38 #include <liblustre.h>
41 #include <linux/obd_support.h>
42 #include <linux/lustre_lib.h>
43 #include <linux/lustre_net.h>
44 #include <linux/lustre_idl.h>
45 #include <linux/lustre_dlm.h>
46 #include <linux/lustre_mds.h>
47 #include <linux/obd_class.h>
48 #include <linux/obd_lov.h>
49 #include <linux/obd_ost.h>
50 #include <linux/lprocfs_status.h>
52 #include "lov_internal.h"
55 #define MAX_STRING_SIZE 128
56 static int lov_connect_obd(struct obd_device *obd, struct lov_tgt_desc *tgt,
57 int activate, unsigned long connect_flags)
59 struct obd_uuid lov_osc_uuid = { "LOV_OSC_UUID" };
60 struct obd_uuid *tgt_uuid = &tgt->uuid;
63 struct proc_dir_entry *lov_proc_dir;
65 struct lov_obd *lov = &obd->u.lov;
66 struct lustre_handle conn = {0, };
67 struct obd_device *tgt_obd;
71 tgt_obd = class_find_client_obd(tgt_uuid, LUSTRE_OSC_NAME,
75 CERROR("Target %s not attached\n", tgt_uuid->uuid);
79 if (!tgt_obd->obd_set_up) {
80 CERROR("Target %s not set up\n", tgt_uuid->uuid);
85 tgt_obd->obd_no_recov = 0;
86 ptlrpc_activate_import(tgt_obd->u.cli.cl_import);
89 if (tgt_obd->u.cli.cl_import->imp_invalid) {
90 CERROR("not connecting OSC %s; administratively "
91 "disabled\n", tgt_uuid->uuid);
92 rc = obd_register_observer(tgt_obd, obd);
94 CERROR("Target %s register_observer error %d; "
95 "will not be able to reactivate\n",
101 rc = obd_connect(&conn, tgt_obd, &lov_osc_uuid, connect_flags);
103 CERROR("Target %s connect error %d\n", tgt_uuid->uuid, rc);
106 tgt->ltd_exp = class_conn2export(&conn);
108 rc = obd_register_observer(tgt_obd, obd);
110 CERROR("Target %s register_observer error %d\n",
112 obd_disconnect(tgt->ltd_exp, 0);
118 lov->desc.ld_active_tgt_count++;
121 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
123 struct obd_device *osc_obd = class_conn2obd(&conn);
124 struct proc_dir_entry *osc_symlink;
125 char name[MAX_STRING_SIZE + 1];
127 LASSERT(osc_obd != NULL);
128 LASSERT(osc_obd->obd_type != NULL);
129 LASSERT(osc_obd->obd_type->typ_name != NULL);
130 name[MAX_STRING_SIZE] = '\0';
131 snprintf(name, MAX_STRING_SIZE, "../../../%s/%s",
132 osc_obd->obd_type->typ_name,
134 osc_symlink = proc_symlink(osc_obd->obd_name, lov_proc_dir,
136 if (osc_symlink == NULL) {
137 CERROR("could not register LOV target "
138 "/proc/fs/lustre/%s/%s/target_obds/%s\n",
139 obd->obd_type->typ_name, obd->obd_name,
141 lprocfs_remove(lov_proc_dir);
150 static int lov_connect(struct lustre_handle *conn, struct obd_device *obd,
151 struct obd_uuid *cluuid, unsigned long flags)
154 struct proc_dir_entry *lov_proc_dir;
156 struct lov_obd *lov = &obd->u.lov;
157 struct lov_tgt_desc *tgt;
158 struct obd_export *exp;
162 rc = class_connect(conn, obd, cluuid);
166 exp = class_conn2export(conn);
168 /* We don't want to actually do the underlying connections more than
169 * once, so keep track. */
171 if (lov->refcount > 1) {
172 class_export_put(exp);
177 lov_proc_dir = lprocfs_register("target_obds", obd->obd_proc_entry,
179 if (IS_ERR(lov_proc_dir)) {
180 CERROR("could not register /proc/fs/lustre/%s/%s/target_obds.",
181 obd->obd_type->typ_name, obd->obd_name);
186 /* connect_flags is the MDS number, save for use in lov_add_obd */
187 lov->lov_connect_flags = flags;
188 for (i = 0, tgt = lov->tgts; i < lov->desc.ld_tgt_count; i++, tgt++) {
189 if (obd_uuid_empty(&tgt->uuid))
191 rc = lov_connect_obd(obd, tgt, 0, flags);
196 class_export_put(exp);
202 lprocfs_remove(lov_proc_dir);
206 struct obd_uuid uuid;
208 --lov->desc.ld_active_tgt_count;
210 /* save for CERROR below; (we know it's terminated) */
212 rc2 = obd_disconnect(tgt->ltd_exp, 0);
214 CERROR("error: LOV target %s disconnect on OST idx %d: "
215 "rc = %d\n", uuid.uuid, i, rc2);
217 class_disconnect(exp, 0);
221 static int lov_disconnect_obd(struct obd_device *obd,
222 struct lov_tgt_desc *tgt,
226 struct proc_dir_entry *lov_proc_dir;
228 struct obd_device *osc_obd = class_exp2obd(tgt->ltd_exp);
229 struct lov_obd *lov = &obd->u.lov;
234 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
236 struct proc_dir_entry *osc_symlink;
238 osc_symlink = lprocfs_srch(lov_proc_dir, osc_obd->obd_name);
240 lprocfs_remove(osc_symlink);
242 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing\n",
243 obd->obd_type->typ_name, obd->obd_name,
248 if (obd->obd_no_recov) {
249 /* Pass it on to our clients.
250 * XXX This should be an argument to disconnect,
251 * XXX not a back-door flag on the OBD. Ah well.
254 osc_obd->obd_no_recov = 1;
257 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
258 rc = obd_disconnect(tgt->ltd_exp, flags);
261 CERROR("Target %s disconnect error %d\n",
269 lov->desc.ld_active_tgt_count--;
275 static int lov_disconnect(struct obd_export *exp, unsigned long flags)
277 struct obd_device *obd = class_exp2obd(exp);
279 struct proc_dir_entry *lov_proc_dir;
281 struct lov_obd *lov = &obd->u.lov;
282 struct lov_tgt_desc *tgt;
289 /* Only disconnect the underlying layers on the final disconnect. */
291 if (lov->refcount != 0)
294 for (i = 0, tgt = lov->tgts; i < lov->desc.ld_tgt_count; i++, tgt++) {
296 lov_disconnect_obd(obd, tgt, flags);
300 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
302 lprocfs_remove(lov_proc_dir);
304 CERROR("/proc/fs/lustre/%s/%s/target_obds missing.",
305 obd->obd_type->typ_name, obd->obd_name);
310 rc = class_disconnect(exp, 0);
316 * -EINVAL : UUID can't be found in the LOV's target list
317 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
318 * -EBADF : The UUID is found, but the OBD is the wrong type (!)
320 static int lov_set_osc_active(struct lov_obd *lov, struct obd_uuid *uuid,
323 struct lov_tgt_desc *tgt;
327 CDEBUG(D_INFO, "Searching in lov %p for uuid %s (activate=%d)\n",
328 lov, uuid->uuid, activate);
330 spin_lock(&lov->lov_lock);
331 for (i = 0, tgt = lov->tgts; i < lov->desc.ld_tgt_count; i++, tgt++) {
332 if (tgt->ltd_exp == NULL)
335 CDEBUG(D_INFO, "lov idx %d is %s conn "LPX64"\n",
336 i, tgt->uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
337 if (strncmp(uuid->uuid, tgt->uuid.uuid, sizeof uuid->uuid) == 0)
341 if (i == lov->desc.ld_tgt_count)
342 GOTO(out, rc = -EINVAL);
345 if (tgt->active == activate) {
346 CDEBUG(D_INFO, "OSC %s already %sactive!\n", uuid->uuid,
347 activate ? "" : "in");
351 CDEBUG(D_INFO, "Marking OSC %s %sactive\n", uuid->uuid,
352 activate ? "" : "in");
354 tgt->active = activate;
356 lov->desc.ld_active_tgt_count++;
358 lov->desc.ld_active_tgt_count--;
362 spin_unlock(&lov->lov_lock);
366 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
367 int active, void *data)
369 struct obd_uuid *uuid;
373 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
374 CERROR("unexpected notification of %s %s!\n",
375 watched->obd_type->typ_name,
379 uuid = &watched->u.cli.cl_import->imp_target_uuid;
381 /* Set OSC as active before notifying the observer, so the
382 * observer can use the OSC normally.
384 rc = lov_set_osc_active(&obd->u.lov, uuid, active);
386 CERROR("%sactivation of %s failed: %d\n",
387 active ? "" : "de", uuid->uuid, rc);
391 if (obd->obd_observer)
392 /* Pass the notification up the chain. */
393 rc = obd_notify(obd->obd_observer, watched, active, data);
398 int lov_attach(struct obd_device *dev, obd_count len, void *data)
400 struct lprocfs_static_vars lvars;
403 lprocfs_init_vars(lov, &lvars);
404 rc = lprocfs_obd_attach(dev, lvars.obd_vars);
407 struct proc_dir_entry *entry;
409 entry = create_proc_entry("target_obd_status", 0444,
410 dev->obd_proc_entry);
414 entry->proc_fops = &lov_proc_target_fops;
422 int lov_detach(struct obd_device *dev)
424 return lprocfs_obd_detach(dev);
427 static int lov_setup(struct obd_device *obd, obd_count len, void *buf)
429 struct lov_obd *lov = &obd->u.lov;
430 struct lustre_cfg *lcfg = buf;
431 struct lov_desc *desc;
435 if (lcfg->lcfg_inllen1 < 1) {
436 CERROR("LOV setup requires a descriptor\n");
440 desc = (struct lov_desc *)lcfg->lcfg_inlbuf1;
441 if (sizeof(*desc) > lcfg->lcfg_inllen1) {
442 CERROR("descriptor size wrong: %d > %d\n",
443 (int)sizeof(*desc), lcfg->lcfg_inllen1);
447 /* Because of 64-bit divide/mod operations only work with a 32-bit
448 * divisor in a 32-bit kernel, we cannot support a stripe width
449 * of 4GB or larger on 32-bit CPUs.
452 count = desc->ld_default_stripe_count;
453 if (count && (count * desc->ld_default_stripe_size) > ~0UL) {
454 CERROR("LOV: stripe width "LPU64"x%u > %lu on 32-bit system\n",
455 desc->ld_default_stripe_size, count, ~0UL);
458 if (desc->ld_tgt_count > 0) {
459 lov->bufsize= sizeof(struct lov_tgt_desc) * desc->ld_tgt_count;
461 lov->bufsize = sizeof(struct lov_tgt_desc) * LOV_MAX_TGT_COUNT;
463 OBD_ALLOC(lov->tgts, lov->bufsize);
464 if (lov->tgts == NULL) {
466 CERROR("couldn't allocate %d bytes for target table.\n",
471 desc->ld_tgt_count = 0;
472 desc->ld_active_tgt_count = 0;
474 spin_lock_init(&lov->lov_lock);
475 sema_init(&lov->lov_llog_sem, 1);
480 static int lov_cleanup(struct obd_device *obd, int flags)
482 struct lov_obd *lov = &obd->u.lov;
484 OBD_FREE(lov->tgts, lov->bufsize);
489 lov_add_obd(struct obd_device *obd, struct obd_uuid *uuidp, int index, int gen)
491 struct lov_obd *lov = &obd->u.lov;
492 struct lov_tgt_desc *tgt;
496 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d\n",
497 uuidp->uuid, index, gen);
499 if ((index < 0) || (index >= LOV_MAX_TGT_COUNT)) {
500 CERROR("request to add OBD %s at invalid index: %d\n",
506 CERROR("request to add OBD %s with invalid generation: %d\n",
511 tgt = lov->tgts + index;
512 if (!obd_uuid_empty(&tgt->uuid)) {
513 CERROR("OBD already assigned at LOV target index %d\n",
519 /* XXX - add a sanity check on the generation number. */
522 if (index >= lov->desc.ld_tgt_count)
523 lov->desc.ld_tgt_count = index + 1;
525 CDEBUG(D_CONFIG, "idx: %d ltd_gen: %d ld_tgt_count: %d\n",
526 index, tgt->ltd_gen, lov->desc.ld_tgt_count);
528 if (lov->refcount == 0)
532 struct obd_device *osc_obd;
534 osc_obd = class_exp2obd(tgt->ltd_exp);
536 osc_obd->obd_no_recov = 0;
539 rc = lov_connect_obd(obd, tgt, 1, lov->lov_connect_flags);
543 if (obd->obd_observer) {
544 /* tell the mds_lov about the new target */
545 rc = obd_notify(obd->obd_observer, tgt->ltd_exp->exp_obd, 1,
551 if (rc && tgt->ltd_exp != NULL)
552 lov_disconnect_obd(obd, tgt, 0);
557 lov_del_obd(struct obd_device *obd, struct obd_uuid *uuidp, int index, int gen)
559 struct lov_obd *lov = &obd->u.lov;
560 struct lov_tgt_desc *tgt;
561 int count = lov->desc.ld_tgt_count;
565 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d\n",
566 uuidp->uuid, index, gen);
568 if (index >= count) {
569 CERROR("LOV target index %d >= number of LOV OBDs %d.\n",
574 tgt = lov->tgts + index;
576 if (obd_uuid_empty(&tgt->uuid)) {
577 CERROR("LOV target at index %d is not setup.\n", index);
581 if (strncmp(uuidp->uuid, tgt->uuid.uuid, sizeof uuidp->uuid) != 0) {
582 CERROR("LOV target UUID %s at index %d doesn't match %s.\n",
583 tgt->uuid.uuid, index, uuidp->uuid);
588 struct obd_device *osc_obd;
590 osc_obd = class_exp2obd(tgt->ltd_exp);
592 osc_obd->obd_no_recov = 1;
593 rc = obd_llog_finish(osc_obd, &osc_obd->obd_llogs, 1);
595 CERROR("osc_llog_finish error: %d\n", rc);
597 lov_disconnect_obd(obd, tgt, 0);
600 /* XXX - right now there is a dependency on ld_tgt_count being the
601 * maximum tgt index for computing the mds_max_easize. So we can't
604 /* lt_gen = 0 will mean it will not match the gen of any valid loi */
605 memset(tgt, 0, sizeof(*tgt));
607 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d exp: %p active: %d\n",
608 tgt->uuid.uuid, index, tgt->ltd_gen, tgt->ltd_exp, tgt->active);
613 static int lov_process_config(struct obd_device *obd, obd_count len, void *buf)
615 struct lustre_cfg *lcfg = buf;
616 struct obd_uuid obd_uuid;
623 switch(cmd = lcfg->lcfg_command) {
624 case LCFG_LOV_ADD_OBD:
625 case LCFG_LOV_DEL_OBD: {
626 if (lcfg->lcfg_inllen1 > sizeof(obd_uuid.uuid))
627 GOTO(out, rc = -EINVAL);
629 obd_str2uuid(&obd_uuid, lcfg->lcfg_inlbuf1);
631 if (sscanf(lcfg->lcfg_inlbuf2, "%d", &index) != 1)
632 GOTO(out, rc = -EINVAL);
633 if (sscanf(lcfg->lcfg_inlbuf3, "%d", &gen) != 1)
634 GOTO(out, rc = -EINVAL);
635 if (cmd == LCFG_LOV_ADD_OBD)
636 rc = lov_add_obd(obd, &obd_uuid, index, gen);
638 rc = lov_del_obd(obd, &obd_uuid, index, gen);
642 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
643 GOTO(out, rc = -EINVAL);
652 #define log2(n) ffz(~(n))
655 static int lov_clear_orphans(struct obd_export *export, struct obdo *src_oa,
656 struct lov_stripe_md **ea,
657 struct obd_trans_info *oti)
661 struct obd_uuid *ost_uuid = NULL;
665 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
666 src_oa->o_flags == OBD_FL_DELORPHAN);
668 lov = &export->exp_obd->u.lov;
670 tmp_oa = obdo_alloc();
674 if (src_oa->o_valid & OBD_MD_FLINLINE) {
675 ost_uuid = (struct obd_uuid *)src_oa->o_inline;
676 CDEBUG(D_HA, "clearing orphans only for %s\n",
680 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
681 struct lov_stripe_md obj_md;
682 struct lov_stripe_md *obj_mdp = &obj_md;
685 /* if called for a specific target, we don't
686 care if it is not active. */
687 if (lov->tgts[i].active == 0 && ost_uuid == NULL) {
688 CDEBUG(D_HA, "lov idx %d inactive\n", i);
692 if (ost_uuid && !obd_uuid_equals(ost_uuid, &lov->tgts[i].uuid))
695 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
697 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
698 err = obd_create(lov->tgts[i].ltd_exp, tmp_oa, &obj_mdp, oti);
700 /* This export will be disabled until it is recovered,
701 and then orphan recovery will be completed. */
702 CERROR("error in orphan recovery on OST idx %d/%d: "
703 "rc = %d\n", i, lov->desc.ld_tgt_count, err);
712 static int lov_recreate(struct obd_export *exp, struct obdo *src_oa,
713 struct lov_stripe_md **ea, struct obd_trans_info *oti)
715 struct lov_stripe_md *obj_mdp, *lsm;
716 struct lov_obd *lov = &exp->exp_obd->u.lov;
721 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
722 src_oa->o_flags & OBD_FL_RECREATE_OBJS);
724 OBD_ALLOC(obj_mdp, sizeof(*obj_mdp));
728 ost_idx = src_oa->o_nlink;
731 GOTO(out, rc = -EINVAL);
732 if (ost_idx >= lov->desc.ld_tgt_count)
733 GOTO(out, rc = -EINVAL);
735 for (i = 0; i < lsm->lsm_stripe_count; i++) {
736 if (lsm->lsm_oinfo[i].loi_ost_idx == ost_idx) {
737 if (lsm->lsm_oinfo[i].loi_id != src_oa->o_id)
738 GOTO(out, rc = -EINVAL);
742 if (i == lsm->lsm_stripe_count)
743 GOTO(out, rc = -EINVAL);
745 rc = obd_create(lov->tgts[ost_idx].ltd_exp, src_oa, &obj_mdp, oti);
747 OBD_FREE(obj_mdp, sizeof(*obj_mdp));
751 /* the LOV expects oa->o_id to be set to the LOV object id */
752 static int lov_create(struct obd_export *exp, struct obdo *src_oa,
753 struct lov_stripe_md **ea, struct obd_trans_info *oti)
755 struct lov_request_set *set = NULL;
756 struct list_head *pos;
765 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
766 src_oa->o_flags == OBD_FL_DELORPHAN) {
767 rc = lov_clear_orphans(exp, src_oa, ea, oti);
771 lov = &exp->exp_obd->u.lov;
772 if (!lov->desc.ld_active_tgt_count)
775 /* Recreate a specific object id at the given OST index */
776 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
777 (src_oa->o_flags & OBD_FL_RECREATE_OBJS)) {
778 rc = lov_recreate(exp, src_oa, ea, oti);
782 rc = lov_prep_create_set(exp, ea, src_oa, oti, &set);
786 list_for_each (pos, &set->set_list) {
787 struct lov_request *req =
788 list_entry(pos, struct lov_request, rq_link);
790 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
791 rc = obd_create(lov->tgts[req->rq_idx].ltd_exp,
792 req->rq_oa, &req->rq_md, oti);
793 lov_update_create_set(set, req, rc);
795 rc = lov_fini_create_set(set, ea);
799 #define lsm_bad_magic(LSMP) \
801 struct lov_stripe_md *_lsm__ = (LSMP); \
804 CERROR("LOV requires striping ea\n"); \
806 } else if (_lsm__->lsm_magic != LOV_MAGIC) { \
807 CERROR("LOV striping magic bad %#x != %#x\n", \
808 _lsm__->lsm_magic, LOV_MAGIC); \
814 static int lov_destroy(struct obd_export *exp, struct obdo *oa,
815 struct lov_stripe_md *lsm, struct obd_trans_info *oti)
817 struct lov_request_set *set;
818 struct lov_request *req;
819 struct list_head *pos;
824 if (lsm_bad_magic(lsm))
827 if (!exp || !exp->exp_obd)
830 lov = &exp->exp_obd->u.lov;
831 rc = lov_prep_destroy_set(exp, oa, lsm, oti, &set);
835 list_for_each (pos, &set->set_list) {
837 req = list_entry(pos, struct lov_request, rq_link);
839 /* XXX update the cookie position */
840 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
841 rc = obd_destroy(lov->tgts[req->rq_idx].ltd_exp, req->rq_oa,
843 err = lov_update_common_set(set, req, rc);
845 CERROR("error: destroying objid "LPX64" subobj "
846 LPX64" on OST idx %d: rc = %d\n",
847 set->set_oa->o_id, req->rq_oa->o_id,
853 lov_fini_destroy_set(set);
857 static int lov_getattr(struct obd_export *exp, struct obdo *oa,
858 struct lov_stripe_md *lsm)
860 struct lov_request_set *set;
861 struct lov_request *req;
862 struct list_head *pos;
867 if (lsm_bad_magic(lsm))
870 if (!exp || !exp->exp_obd)
873 lov = &exp->exp_obd->u.lov;
875 rc = lov_prep_getattr_set(exp, oa, lsm, &set);
879 list_for_each (pos, &set->set_list) {
880 req = list_entry(pos, struct lov_request, rq_link);
882 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
883 "%u\n", oa->o_id, req->rq_stripe, req->rq_oa->o_id,
886 rc = obd_getattr(lov->tgts[req->rq_idx].ltd_exp,
888 err = lov_update_common_set(set, req, rc);
890 CERROR("error: getattr objid "LPX64" subobj "
891 LPX64" on OST idx %d: rc = %d\n",
892 set->set_oa->o_id, req->rq_oa->o_id,
898 rc = lov_fini_getattr_set(set);
904 static int lov_getattr_interpret(struct ptlrpc_request_set *rqset, void *data,
907 struct lov_request_set *lovset = (struct lov_request_set *)data;
910 /* don't do attribute merge if this aysnc op failed */
912 lovset->set_completes = 0;
913 lov_fini_getattr_set(lovset);
915 rc = lov_fini_getattr_set(lovset);
920 static int lov_getattr_async(struct obd_export *exp, struct obdo *oa,
921 struct lov_stripe_md *lsm,
922 struct ptlrpc_request_set *rqset)
924 struct lov_request_set *lovset;
926 struct list_head *pos;
927 struct lov_request *req;
931 if (lsm_bad_magic(lsm))
934 if (!exp || !exp->exp_obd)
937 lov = &exp->exp_obd->u.lov;
939 rc = lov_prep_getattr_set(exp, oa, lsm, &lovset);
943 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
944 lsm->lsm_object_id, lsm->lsm_stripe_count, lsm->lsm_stripe_size);
946 list_for_each (pos, &lovset->set_list) {
947 req = list_entry(pos, struct lov_request, rq_link);
949 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
950 "%u\n", oa->o_id, req->rq_stripe, req->rq_oa->o_id,
952 rc = obd_getattr_async(lov->tgts[req->rq_idx].ltd_exp,
953 req->rq_oa, NULL, rqset);
955 CERROR("error: getattr objid "LPX64" subobj "
956 LPX64" on OST idx %d: rc = %d\n",
957 lovset->set_oa->o_id, req->rq_oa->o_id,
961 lov_update_common_set(lovset, req, rc);
965 LASSERT (rqset->set_interpret == NULL);
966 rqset->set_interpret = lov_getattr_interpret;
967 rqset->set_arg = (void *)lovset;
971 lov_fini_getattr_set(lovset);
975 static int lov_setattr(struct obd_export *exp, struct obdo *src_oa,
976 struct lov_stripe_md *lsm, struct obd_trans_info *oti)
978 struct lov_request_set *set;
980 struct list_head *pos;
981 struct lov_request *req;
985 if (lsm_bad_magic(lsm))
988 if (!exp || !exp->exp_obd)
991 /* for now, we only expect time updates here */
992 LASSERT(!(src_oa->o_valid & ~(OBD_MD_FLID|OBD_MD_FLTYPE | OBD_MD_FLMODE|
993 OBD_MD_FLATIME | OBD_MD_FLMTIME |
994 OBD_MD_FLCTIME | OBD_MD_FLFLAGS |
995 OBD_MD_FLSIZE | OBD_MD_FLGROUP)));
997 LASSERT(!(src_oa->o_valid & OBD_MD_FLGROUP) || src_oa->o_gr > 0);
999 lov = &exp->exp_obd->u.lov;
1000 rc = lov_prep_setattr_set(exp, src_oa, lsm, NULL, &set);
1004 list_for_each (pos, &set->set_list) {
1005 req = list_entry(pos, struct lov_request, rq_link);
1007 rc = obd_setattr(lov->tgts[req->rq_idx].ltd_exp, req->rq_oa,
1009 err = lov_update_common_set(set, req, rc);
1011 CERROR("error: setattr objid "LPX64" subobj "
1012 LPX64" on OST idx %d: rc = %d\n",
1013 set->set_oa->o_id, req->rq_oa->o_id,
1019 err = lov_fini_setattr_set(set);
1025 static int lov_revalidate_policy(struct lov_obd *lov, struct lov_stripe_md *lsm)
1027 static int next_idx = 0;
1028 struct lov_tgt_desc *tgt;
1031 /* XXX - we should do something clever and take lsm
1032 * into account but just do round robin for now. */
1034 /* last_idx must always be less that count because
1035 * ld_tgt_count currently cannot shrink. */
1036 count = lov->desc.ld_tgt_count;
1038 for (i = next_idx, tgt = lov->tgts + i; i < count; i++, tgt++) {
1040 next_idx = (i + 1) % count;
1045 for (i = 0, tgt = lov->tgts; i < next_idx; i++, tgt++) {
1047 next_idx = (i + 1) % count;
1055 static int lov_revalidate_md(struct obd_export *exp, struct obdo *src_oa,
1056 struct lov_stripe_md *ea,
1057 struct obd_trans_info *oti)
1059 struct obd_export *osc_exp;
1060 struct lov_obd *lov = &exp->exp_obd->u.lov;
1061 struct lov_stripe_md *lsm = ea;
1062 struct lov_stripe_md obj_md;
1063 struct lov_stripe_md *obj_mdp = &obj_md;
1064 struct lov_oinfo *loi;
1065 struct obdo *tmp_oa;
1066 int ost_idx, updates = 0, i;
1069 tmp_oa = obdo_alloc();
1073 loi = lsm->lsm_oinfo;
1074 for (i = 0; i < lsm->lsm_stripe_count; i++, loi++) {
1076 if (!obd_uuid_empty(&lov->tgts[loi->loi_ost_idx].uuid))
1079 ost_idx = lov_revalidate_policy(lov, lsm);
1081 /* FIXME: punt for now. */
1082 CERROR("lov_revalidate_policy failed; no active "
1087 /* create a new object */
1088 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
1089 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1090 osc_exp = lov->tgts[ost_idx].ltd_exp;
1091 rc = obd_create(osc_exp, tmp_oa, &obj_mdp, oti);
1093 CERROR("error creating new subobj at idx %d; "
1094 "rc = %d\n", ost_idx, rc);
1098 oti->oti_objid[ost_idx] = tmp_oa->o_id;
1099 loi->loi_id = tmp_oa->o_id;
1100 loi->loi_gr = tmp_oa->o_gr;
1101 loi->loi_ost_idx = ost_idx;
1102 loi->loi_ost_gen = lov->tgts[ost_idx].ltd_gen;
1103 CDEBUG(D_INODE, "replacing objid "LPX64" subobj "LPX64
1104 " with idx %d gen %d.\n", lsm->lsm_object_id,
1105 loi->loi_id, ost_idx, loi->loi_ost_gen);
1109 /* If we got an error revalidating an entry there's no need to
1110 * cleanup up objects we allocated here because the bad entry
1111 * still points to a deleted OST. */
1117 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
1118 * we can send this 'punch' to just the authoritative node and the nodes
1119 * that the punch will affect. */
1120 static int lov_punch(struct obd_export *exp, struct obdo *oa,
1121 struct lov_stripe_md *lsm,
1122 obd_off start, obd_off end, struct obd_trans_info *oti)
1124 struct lov_request_set *set;
1125 struct lov_obd *lov;
1126 struct list_head *pos;
1127 struct lov_request *req;
1128 int err = 0, rc = 0;
1131 if (lsm_bad_magic(lsm))
1134 if (!exp || !exp->exp_obd)
1137 lov = &exp->exp_obd->u.lov;
1138 rc = lov_prep_punch_set(exp, oa, lsm, start, end, oti, &set);
1142 list_for_each (pos, &set->set_list) {
1143 req = list_entry(pos, struct lov_request, rq_link);
1145 rc = obd_punch(lov->tgts[req->rq_idx].ltd_exp, req->rq_oa,
1146 NULL, req->rq_extent.start,
1147 req->rq_extent.end, NULL);
1148 err = lov_update_punch_set(set, req, rc);
1150 CERROR("error: punch objid "LPX64" subobj "LPX64
1151 " on OST idx %d: rc = %d\n", set->set_oa->o_id,
1152 req->rq_oa->o_id, req->rq_idx, rc);
1157 err = lov_fini_punch_set(set);
1163 static int lov_sync(struct obd_export *exp, struct obdo *oa,
1164 struct lov_stripe_md *lsm, obd_off start, obd_off end)
1166 struct lov_request_set *set;
1167 struct lov_obd *lov;
1168 struct list_head *pos;
1169 struct lov_request *req;
1170 int err = 0, rc = 0;
1173 if (lsm_bad_magic(lsm))
1179 lov = &exp->exp_obd->u.lov;
1180 rc = lov_prep_sync_set(exp, oa, lsm, start, end, &set);
1184 list_for_each (pos, &set->set_list) {
1185 req = list_entry(pos, struct lov_request, rq_link);
1187 rc = obd_sync(lov->tgts[req->rq_idx].ltd_exp, req->rq_oa,
1188 NULL, req->rq_extent.start, req->rq_extent.end);
1189 err = lov_update_common_set(set, req, rc);
1191 CERROR("error: fsync objid "LPX64" subobj "LPX64
1192 " on OST idx %d: rc = %d\n", set->set_oa->o_id,
1193 req->rq_oa->o_id, req->rq_idx, rc);
1198 err = lov_fini_sync_set(set);
1204 static int lov_brw_check(struct lov_obd *lov, struct obdo *oa,
1205 struct lov_stripe_md *lsm,
1206 obd_count oa_bufs, struct brw_page *pga)
1211 /* The caller just wants to know if there's a chance that this
1212 * I/O can succeed */
1213 for (i = 0; i < oa_bufs; i++) {
1214 int stripe = lov_stripe_number(lsm, pga[i].disk_offset);
1215 int ost = lsm->lsm_oinfo[stripe].loi_ost_idx;
1218 if (!lov_stripe_intersects(lsm, i, pga[i].disk_offset,
1219 pga[i].disk_offset + pga[i].count,
1223 if (lov->tgts[ost].active == 0) {
1224 CDEBUG(D_HA, "lov idx %d inactive\n", ost);
1227 rc = obd_brw(OBD_BRW_CHECK, lov->tgts[ost].ltd_exp, oa,
1228 NULL, 1, &pga[i], NULL);
1235 static int lov_brw(int cmd, struct obd_export *exp, struct obdo *src_oa,
1236 struct lov_stripe_md *lsm, obd_count oa_bufs,
1237 struct brw_page *pga, struct obd_trans_info *oti)
1239 struct lov_request_set *set;
1240 struct lov_request *req;
1241 struct list_head *pos;
1242 struct lov_obd *lov = &exp->exp_obd->u.lov;
1246 if (lsm_bad_magic(lsm))
1249 if (cmd == OBD_BRW_CHECK) {
1250 rc = lov_brw_check(lov, src_oa, lsm, oa_bufs, pga);
1254 rc = lov_prep_brw_set(exp, src_oa, lsm, oa_bufs, pga, oti, &set);
1258 list_for_each (pos, &set->set_list) {
1259 struct obd_export *sub_exp;
1260 struct brw_page *sub_pga;
1261 req = list_entry(pos, struct lov_request, rq_link);
1263 sub_exp = lov->tgts[req->rq_idx].ltd_exp;
1264 sub_pga = set->set_pga + req->rq_pgaidx;
1265 rc = obd_brw(cmd, sub_exp, req->rq_oa, req->rq_md,
1266 req->rq_oabufs, sub_pga, oti);
1269 lov_update_common_set(set, req, rc);
1272 err = lov_fini_brw_set(set);
1278 static int lov_brw_interpret(struct ptlrpc_request_set *reqset, void *data,
1281 struct lov_request_set *lovset = (struct lov_request_set *)data;
1285 lovset->set_completes = 0;
1286 lov_fini_brw_set(lovset);
1288 rc = lov_fini_brw_set(lovset);
1294 static int lov_brw_async(int cmd, struct obd_export *exp, struct obdo *oa,
1295 struct lov_stripe_md *lsm, obd_count oa_bufs,
1296 struct brw_page *pga, struct ptlrpc_request_set *set,
1297 struct obd_trans_info *oti)
1299 struct lov_request_set *lovset;
1300 struct lov_request *req;
1301 struct list_head *pos;
1302 struct lov_obd *lov = &exp->exp_obd->u.lov;
1306 if (lsm_bad_magic(lsm))
1309 if (cmd == OBD_BRW_CHECK) {
1310 rc = lov_brw_check(lov, oa, lsm, oa_bufs, pga);
1314 rc = lov_prep_brw_set(exp, oa, lsm, oa_bufs, pga, oti, &lovset);
1318 list_for_each (pos, &lovset->set_list) {
1319 struct obd_export *sub_exp;
1320 struct brw_page *sub_pga;
1321 req = list_entry(pos, struct lov_request, rq_link);
1323 sub_exp = lov->tgts[req->rq_idx].ltd_exp;
1324 sub_pga = lovset->set_pga + req->rq_pgaidx;
1325 rc = obd_brw_async(cmd, sub_exp, req->rq_oa, req->rq_md,
1326 req->rq_oabufs, sub_pga, set, oti);
1329 lov_update_common_set(lovset, req, rc);
1332 LASSERT(set->set_interpret == NULL);
1333 set->set_interpret = (set_interpreter_func)lov_brw_interpret;
1334 set->set_arg = (void *)lovset;
1338 lov_fini_brw_set(lovset);
1342 static int lov_ap_make_ready(void *data, int cmd)
1344 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1346 return lap->lap_caller_ops->ap_make_ready(lap->lap_caller_data, cmd);
1348 static int lov_ap_refresh_count(void *data, int cmd)
1350 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1352 return lap->lap_caller_ops->ap_refresh_count(lap->lap_caller_data,
1355 static void lov_ap_fill_obdo(void *data, int cmd, struct obdo *oa)
1357 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1359 lap->lap_caller_ops->ap_fill_obdo(lap->lap_caller_data, cmd, oa);
1360 /* XXX woah, shouldn't we be altering more here? size? */
1361 oa->o_id = lap->lap_loi_id;
1364 static void lov_ap_completion(void *data, int cmd, struct obdo *oa, int rc)
1366 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1368 /* in a raid1 regime this would down a count of many ios
1369 * in flight, onl calling the caller_ops completion when all
1370 * the raid1 ios are complete */
1371 lap->lap_caller_ops->ap_completion(lap->lap_caller_data, cmd, oa, rc);
1374 static struct obd_async_page_ops lov_async_page_ops = {
1375 .ap_make_ready = lov_ap_make_ready,
1376 .ap_refresh_count = lov_ap_refresh_count,
1377 .ap_fill_obdo = lov_ap_fill_obdo,
1378 .ap_completion = lov_ap_completion,
1381 static int lov_prep_async_page(struct obd_export *exp,
1382 struct lov_stripe_md *lsm,
1383 struct lov_oinfo *loi, struct page *page,
1384 obd_off offset, struct obd_async_page_ops *ops,
1385 void *data, void **res)
1387 struct lov_obd *lov = &exp->exp_obd->u.lov;
1388 struct lov_async_page *lap;
1392 if (lsm_bad_magic(lsm))
1394 LASSERT(loi == NULL);
1396 stripe = lov_stripe_number(lsm, offset);
1397 loi = &lsm->lsm_oinfo[stripe];
1399 if (obd_uuid_empty(&lov->tgts[loi->loi_ost_idx].uuid))
1401 if (lov->tgts[loi->loi_ost_idx].active == 0)
1403 if (lov->tgts[loi->loi_ost_idx].ltd_exp == NULL) {
1404 CERROR("ltd_exp == NULL, but OST idx %d doesn't appear to be "
1405 "deleted or inactive.\n", loi->loi_ost_idx);
1409 OBD_ALLOC(lap, sizeof(*lap));
1413 lap->lap_magic = LAP_MAGIC;
1414 lap->lap_caller_ops = ops;
1415 lap->lap_caller_data = data;
1417 /* FIXME handle multiple oscs after landing b_raid1 */
1418 lap->lap_stripe = stripe;
1419 switch (lsm->lsm_pattern) {
1420 case LOV_PATTERN_RAID0:
1421 lov_stripe_offset(lsm, offset, lap->lap_stripe,
1422 &lap->lap_sub_offset);
1424 case LOV_PATTERN_CMOBD:
1425 lap->lap_sub_offset = offset;
1431 /* so the callback doesn't need the lsm */
1432 lap->lap_loi_id = loi->loi_id;
1434 rc = obd_prep_async_page(lov->tgts[loi->loi_ost_idx].ltd_exp,
1435 lsm, loi, page, lap->lap_sub_offset,
1436 &lov_async_page_ops, lap,
1437 &lap->lap_sub_cookie);
1439 OBD_FREE(lap, sizeof(*lap));
1442 CDEBUG(D_CACHE, "lap %p page %p cookie %p off "LPU64"\n", lap, page,
1443 lap->lap_sub_cookie, offset);
1448 static int lov_queue_async_io(struct obd_export *exp,
1449 struct lov_stripe_md *lsm,
1450 struct lov_oinfo *loi, void *cookie,
1451 int cmd, obd_off off, int count,
1452 obd_flags brw_flags, obd_flags async_flags)
1454 struct lov_obd *lov = &exp->exp_obd->u.lov;
1455 struct lov_async_page *lap;
1458 LASSERT(loi == NULL);
1460 if (lsm_bad_magic(lsm))
1463 lap = LAP_FROM_COOKIE(cookie);
1465 loi = &lsm->lsm_oinfo[lap->lap_stripe];
1467 rc = obd_queue_async_io(lov->tgts[loi->loi_ost_idx].ltd_exp, lsm,
1468 loi, lap->lap_sub_cookie, cmd, off, count,
1469 brw_flags, async_flags);
1473 static int lov_set_async_flags(struct obd_export *exp,
1474 struct lov_stripe_md *lsm,
1475 struct lov_oinfo *loi, void *cookie,
1476 obd_flags async_flags)
1478 struct lov_obd *lov = &exp->exp_obd->u.lov;
1479 struct lov_async_page *lap;
1482 LASSERT(loi == NULL);
1484 if (lsm_bad_magic(lsm))
1487 lap = LAP_FROM_COOKIE(cookie);
1489 loi = &lsm->lsm_oinfo[lap->lap_stripe];
1491 rc = obd_set_async_flags(lov->tgts[loi->loi_ost_idx].ltd_exp,
1492 lsm, loi, lap->lap_sub_cookie, async_flags);
1496 static int lov_queue_group_io(struct obd_export *exp,
1497 struct lov_stripe_md *lsm,
1498 struct lov_oinfo *loi,
1499 struct obd_io_group *oig, void *cookie,
1500 int cmd, obd_off off, int count,
1501 obd_flags brw_flags, obd_flags async_flags)
1503 struct lov_obd *lov = &exp->exp_obd->u.lov;
1504 struct lov_async_page *lap;
1507 LASSERT(loi == NULL);
1509 if (lsm_bad_magic(lsm))
1512 lap = LAP_FROM_COOKIE(cookie);
1514 loi = &lsm->lsm_oinfo[lap->lap_stripe];
1516 rc = obd_queue_group_io(lov->tgts[loi->loi_ost_idx].ltd_exp, lsm, loi,
1517 oig, lap->lap_sub_cookie, cmd, off, count,
1518 brw_flags, async_flags);
1522 /* this isn't exactly optimal. we may have queued sync io in oscs on
1523 * all stripes, but we don't record that fact at queue time. so we
1524 * trigger sync io on all stripes. */
1525 static int lov_trigger_group_io(struct obd_export *exp,
1526 struct lov_stripe_md *lsm,
1527 struct lov_oinfo *loi,
1528 struct obd_io_group *oig)
1530 struct lov_obd *lov = &exp->exp_obd->u.lov;
1533 LASSERT(loi == NULL);
1535 if (lsm_bad_magic(lsm))
1538 loi = lsm->lsm_oinfo;
1539 for (i = 0; i < lsm->lsm_stripe_count; i++, loi++) {
1540 if (lov->tgts[loi->loi_ost_idx].active == 0) {
1541 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1545 err = obd_trigger_group_io(lov->tgts[loi->loi_ost_idx].ltd_exp,
1547 if (rc == 0 && err != 0)
1553 static int lov_teardown_async_page(struct obd_export *exp,
1554 struct lov_stripe_md *lsm,
1555 struct lov_oinfo *loi, void *cookie)
1557 struct lov_obd *lov = &exp->exp_obd->u.lov;
1558 struct lov_async_page *lap;
1561 LASSERT(loi == NULL);
1563 if (lsm_bad_magic(lsm))
1566 lap = LAP_FROM_COOKIE(cookie);
1568 loi = &lsm->lsm_oinfo[lap->lap_stripe];
1570 rc = obd_teardown_async_page(lov->tgts[loi->loi_ost_idx].ltd_exp,
1571 lsm, loi, lap->lap_sub_cookie);
1573 CERROR("unable to teardown sub cookie %p: %d\n",
1574 lap->lap_sub_cookie, rc);
1577 OBD_FREE(lap, sizeof(*lap));
1581 static int lov_enqueue(struct obd_export *exp, struct lov_stripe_md *lsm,
1582 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1583 int *flags, void *bl_cb, void *cp_cb, void *gl_cb,
1584 void *data,__u32 lvb_len, void *lvb_swabber,
1585 struct lustre_handle *lockh)
1587 struct lov_request_set *set;
1588 struct lov_request *req;
1589 struct list_head *pos;
1590 struct lustre_handle *lov_lockhp;
1591 struct lov_obd *lov;
1593 int save_flags = *flags;
1596 if (lsm_bad_magic(lsm))
1599 /* we should never be asked to replay a lock this way. */
1600 LASSERT((*flags & LDLM_FL_REPLAY) == 0);
1602 if (!exp || !exp->exp_obd)
1605 lov = &exp->exp_obd->u.lov;
1606 rc = lov_prep_enqueue_set(exp, lsm, policy, mode, lockh, &set);
1610 list_for_each (pos, &set->set_list) {
1611 ldlm_policy_data_t sub_policy;
1612 req = list_entry(pos, struct lov_request, rq_link);
1613 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
1614 LASSERT(lov_lockhp);
1616 *flags = save_flags;
1617 sub_policy.l_extent.start = req->rq_extent.start;
1618 sub_policy.l_extent.end = req->rq_extent.end;
1620 rc = obd_enqueue(lov->tgts[req->rq_idx].ltd_exp, req->rq_md,
1621 type, &sub_policy, mode, flags, bl_cb,
1622 cp_cb, gl_cb, data, lvb_len, lvb_swabber,
1624 rc = lov_update_enqueue_set(set, req, rc, save_flags);
1629 lov_fini_enqueue_set(set, mode);
1633 static int lov_match(struct obd_export *exp, struct lov_stripe_md *lsm,
1634 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1635 int *flags, void *data, struct lustre_handle *lockh)
1637 struct lov_request_set *set;
1638 struct lov_request *req;
1639 struct list_head *pos;
1640 struct lov_obd *lov = &exp->exp_obd->u.lov;
1641 struct lustre_handle *lov_lockhp;
1642 int lov_flags, rc = 0;
1645 if (lsm_bad_magic(lsm))
1648 if (!exp || !exp->exp_obd)
1651 lov = &exp->exp_obd->u.lov;
1652 rc = lov_prep_match_set(exp, lsm, policy, mode, lockh, &set);
1656 list_for_each (pos, &set->set_list) {
1657 ldlm_policy_data_t sub_policy;
1658 req = list_entry(pos, struct lov_request, rq_link);
1659 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
1660 LASSERT(lov_lockhp);
1662 sub_policy.l_extent.start = req->rq_extent.start;
1663 sub_policy.l_extent.end = req->rq_extent.end;
1666 rc = obd_match(lov->tgts[req->rq_idx].ltd_exp, req->rq_md,
1667 type, &sub_policy, mode, &lov_flags, data,
1669 rc = lov_update_match_set(set, req, rc);
1673 lov_fini_match_set(set, mode, *flags);
1677 static int lov_change_cbdata(struct obd_export *exp,
1678 struct lov_stripe_md *lsm, ldlm_iterator_t it,
1681 struct lov_obd *lov;
1682 struct lov_oinfo *loi;
1686 if (lsm_bad_magic(lsm))
1689 if (!exp || !exp->exp_obd)
1692 LASSERT(lsm->lsm_object_gr > 0);
1694 lov = &exp->exp_obd->u.lov;
1695 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
1696 struct lov_stripe_md submd;
1697 if (lov->tgts[loi->loi_ost_idx].active == 0) {
1698 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1702 submd.lsm_object_id = loi->loi_id;
1703 submd.lsm_object_gr = lsm->lsm_object_gr;
1704 submd.lsm_stripe_count = 0;
1705 rc = obd_change_cbdata(lov->tgts[loi->loi_ost_idx].ltd_exp,
1711 static int lov_cancel(struct obd_export *exp, struct lov_stripe_md *lsm,
1712 __u32 mode, struct lustre_handle *lockh)
1714 struct lov_request_set *set;
1715 struct lov_request *req;
1716 struct list_head *pos;
1717 struct lov_obd *lov = &exp->exp_obd->u.lov;
1718 struct lustre_handle *lov_lockhp;
1719 int err = 0, rc = 0;
1722 if (lsm_bad_magic(lsm))
1725 if (!exp || !exp->exp_obd)
1728 LASSERT(lsm->lsm_object_gr > 0);
1731 lov = &exp->exp_obd->u.lov;
1732 rc = lov_prep_cancel_set(exp, lsm, mode, lockh, &set);
1736 list_for_each (pos, &set->set_list) {
1737 req = list_entry(pos, struct lov_request, rq_link);
1738 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
1740 rc = obd_cancel(lov->tgts[req->rq_idx].ltd_exp, req->rq_md,
1742 rc = lov_update_common_set(set, req, rc);
1744 CERROR("error: cancel objid "LPX64" subobj "
1745 LPX64" on OST idx %d: rc = %d\n",
1747 req->rq_md->lsm_object_id, req->rq_idx, rc);
1752 lov_fini_cancel_set(set);
1756 static int lov_cancel_unused(struct obd_export *exp,
1757 struct lov_stripe_md *lsm,
1758 int flags, void *opaque)
1760 struct lov_obd *lov;
1761 struct lov_oinfo *loi;
1765 lov = &exp->exp_obd->u.lov;
1767 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1768 int err = obd_cancel_unused(lov->tgts[i].ltd_exp, NULL,
1776 if (lsm_bad_magic(lsm))
1779 if (!exp || !exp->exp_obd)
1782 LASSERT(lsm->lsm_object_gr > 0);
1784 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
1785 struct lov_stripe_md submd;
1788 if (lov->tgts[loi->loi_ost_idx].active == 0)
1789 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1791 submd.lsm_object_id = loi->loi_id;
1792 submd.lsm_object_gr = lsm->lsm_object_gr;
1793 submd.lsm_stripe_count = 0;
1794 err = obd_cancel_unused(lov->tgts[loi->loi_ost_idx].ltd_exp,
1795 &submd, flags, opaque);
1796 if (err && lov->tgts[loi->loi_ost_idx].active) {
1797 CERROR("error: cancel unused objid "LPX64" subobj "LPX64
1798 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
1799 loi->loi_id, loi->loi_ost_idx, err);
1807 #define LOV_U64_MAX ((__u64)~0ULL)
1808 #define LOV_SUM_MAX(tot, add) \
1810 if ((tot) + (add) < (tot)) \
1811 (tot) = LOV_U64_MAX; \
1816 static int lov_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1817 unsigned long max_age)
1819 struct lov_obd *lov = &obd->u.lov;
1820 struct obd_statfs lov_sfs;
1827 /* We only get block data from the OBD */
1828 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1830 if (!lov->tgts[i].active) {
1831 CDEBUG(D_HA, "lov idx %d inactive\n", i);
1835 err = obd_statfs(class_exp2obd(lov->tgts[i].ltd_exp), &lov_sfs,
1838 if (lov->tgts[i].active && !rc)
1844 memcpy(osfs, &lov_sfs, sizeof(lov_sfs));
1847 osfs->os_bfree += lov_sfs.os_bfree;
1848 osfs->os_bavail += lov_sfs.os_bavail;
1849 osfs->os_blocks += lov_sfs.os_blocks;
1850 /* XXX not sure about this one - depends on policy.
1851 * - could be minimum if we always stripe on all OBDs
1852 * (but that would be wrong for any other policy,
1853 * if one of the OBDs has no more objects left)
1854 * - could be sum if we stripe whole objects
1855 * - could be average, just to give a nice number
1857 * To give a "reasonable" (if not wholly accurate)
1858 * number, we divide the total number of free objects
1859 * by expected stripe count (watch out for overflow).
1861 LOV_SUM_MAX(osfs->os_files, lov_sfs.os_files);
1862 LOV_SUM_MAX(osfs->os_ffree, lov_sfs.os_ffree);
1867 __u32 expected_stripes = lov->desc.ld_default_stripe_count ?
1868 lov->desc.ld_default_stripe_count :
1869 lov->desc.ld_active_tgt_count;
1871 if (osfs->os_files != LOV_U64_MAX)
1872 do_div(osfs->os_files, expected_stripes);
1873 if (osfs->os_ffree != LOV_U64_MAX)
1874 do_div(osfs->os_ffree, expected_stripes);
1881 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1882 void *karg, void *uarg)
1884 struct obd_device *obddev = class_exp2obd(exp);
1885 struct lov_obd *lov = &obddev->u.lov;
1886 int i, rc, count = lov->desc.ld_tgt_count;
1887 struct obd_uuid *uuidp;
1891 case OBD_IOC_LOV_GET_CONFIG: {
1892 struct obd_ioctl_data *data = karg;
1893 struct lov_tgt_desc *tgtdesc;
1894 struct lov_desc *desc;
1900 if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
1903 data = (struct obd_ioctl_data *)buf;
1905 if (sizeof(*desc) > data->ioc_inllen1) {
1906 obd_ioctl_freedata(buf, len);
1910 if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
1911 obd_ioctl_freedata(buf, len);
1915 if (sizeof(__u32) * count > data->ioc_inllen3) {
1916 obd_ioctl_freedata(buf, len);
1920 desc = (struct lov_desc *)data->ioc_inlbuf1;
1921 memcpy(desc, &(lov->desc), sizeof(*desc));
1923 uuidp = (struct obd_uuid *)data->ioc_inlbuf2;
1924 genp = (__u32 *)data->ioc_inlbuf3;
1925 tgtdesc = lov->tgts;
1926 /* the uuid will be empty for deleted OSTs */
1927 for (i = 0; i < count; i++, uuidp++, genp++, tgtdesc++) {
1928 obd_str2uuid(uuidp, tgtdesc->uuid.uuid);
1929 *genp = tgtdesc->ltd_gen;
1932 rc = copy_to_user((void *)uarg, buf, len);
1935 obd_ioctl_freedata(buf, len);
1938 case LL_IOC_LOV_SETSTRIPE:
1939 rc = lov_setstripe(exp, karg, uarg);
1941 case LL_IOC_LOV_GETSTRIPE:
1942 rc = lov_getstripe(exp, karg, uarg);
1944 case LL_IOC_LOV_SETEA:
1945 rc = lov_setea(exp, karg, uarg);
1952 for (i = 0; i < count; i++) {
1955 /* OST was deleted */
1956 if (obd_uuid_empty(&lov->tgts[i].uuid))
1959 err = obd_iocontrol(cmd, lov->tgts[i].ltd_exp,
1962 if (lov->tgts[i].active) {
1963 CERROR("error: iocontrol OSC %s on OST "
1964 "idx %d cmd %x: err = %d\n",
1965 lov->tgts[i].uuid.uuid, i,
1981 static int lov_get_info(struct obd_export *exp, __u32 keylen,
1982 void *key, __u32 *vallen, void *val)
1984 struct obd_device *obddev = class_exp2obd(exp);
1985 struct lov_obd *lov = &obddev->u.lov;
1989 if (!vallen || !val)
1992 if (keylen > strlen("lock_to_stripe") &&
1993 strcmp(key, "lock_to_stripe") == 0) {
1996 struct ldlm_lock *lock;
1997 struct lov_stripe_md *lsm;
1999 struct lov_oinfo *loi;
2000 struct ldlm_res_id *res_id = &data->lock->l_resource->lr_name;
2001 __u32 *stripe = val;
2003 if (*vallen < sizeof(*stripe))
2005 *vallen = sizeof(*stripe);
2007 /* XXX This is another one of those bits that will need to
2008 * change if we ever actually support nested LOVs. It uses
2009 * the lock's export to find out which stripe it is. */
2010 /* XXX - it's assumed all the locks for deleted OSTs have
2011 * been cancelled. Also, the export for deleted OSTs will
2012 * be NULL and won't match the lock's export. */
2013 for (i = 0, loi = data->lsm->lsm_oinfo;
2014 i < data->lsm->lsm_stripe_count;
2016 if (lov->tgts[loi->loi_ost_idx].ltd_exp ==
2017 data->lock->l_conn_export &&
2018 loi->loi_id == res_id->name[0] &&
2019 loi->loi_gr == res_id->name[2]) {
2024 LDLM_ERROR(data->lock, "lock on inode without such object\n");
2025 dump_lsm(D_ERROR, data->lsm);
2027 } else if (keylen >= strlen("size_to_stripe") &&
2028 strcmp(key, "size_to_stripe") == 0) {
2032 struct lov_stripe_md *lsm;
2035 if (*vallen < sizeof(*data))
2038 data->size = lov_size_to_stripe(data->lsm, data->size,
2039 data->stripe_number);
2041 } else if (keylen >= strlen("last_id") && strcmp(key, "last_id") == 0) {
2043 int rc, size = sizeof(obd_id);
2044 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2045 if (!lov->tgts[i].active)
2047 rc = obd_get_info(lov->tgts[i].ltd_exp,
2048 keylen, key, &size, &(ids[i]));
2053 } else if (keylen >= strlen("lovdesc") && strcmp(key, "lovdesc") == 0) {
2054 struct lov_desc *desc_ret = val;
2055 *desc_ret = lov->desc;
2063 static int lov_set_info(struct obd_export *exp, obd_count keylen,
2064 void *key, obd_count vallen, void *val)
2066 struct obd_device *obddev = class_exp2obd(exp);
2067 struct lov_obd *lov = &obddev->u.lov;
2071 #define KEY_IS(str) \
2072 (keylen == strlen(str) && memcmp(key, str, keylen) == 0)
2074 if (KEY_IS("next_id")) {
2075 if (vallen != lov->desc.ld_tgt_count)
2077 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2078 /* initialize all OSCs, even inactive ones */
2080 err = obd_set_info(lov->tgts[i].ltd_exp,
2081 keylen, key, sizeof(obd_id),
2082 ((obd_id*)val) + i);
2088 if (KEY_IS("async")) {
2089 struct lov_desc *desc = &lov->desc;
2090 struct lov_tgt_desc *tgts = lov->tgts;
2092 if (vallen != sizeof(int))
2094 lov->async = *((int*) val);
2096 for (i = 0; i < desc->ld_tgt_count; i++, tgts++) {
2097 struct obd_uuid *tgt_uuid = &tgts->uuid;
2098 struct obd_device *tgt_obd;
2100 tgt_obd = class_find_client_obd(tgt_uuid,
2104 CERROR("Target %s not attached\n",
2111 err = obd_set_info(tgt_obd->obd_self_export,
2112 keylen, key, vallen, val);
2114 CERROR("Failed to set async on target %s\n",
2123 if (KEY_IS("growth_count")) {
2124 if (vallen != sizeof(int))
2126 } else if (KEY_IS("mds_conn")) {
2127 if (vallen != sizeof(__u32))
2129 } else if (KEY_IS("unlinked") || KEY_IS("unrecovery")) {
2132 } else if (KEY_IS("sec")) {
2133 struct lov_tgt_desc *tgt;
2134 struct obd_export *exp;
2137 spin_lock(&lov->lov_lock);
2138 for (i = 0, tgt = lov->tgts; i < lov->desc.ld_tgt_count;
2141 /* during setup time the connections to osc might
2142 * haven't been established.
2145 struct obd_device *tgt_obd;
2147 tgt_obd = class_find_client_obd(&tgt->uuid,
2151 CERROR("can't set security flavor, "
2152 "device %s not attached?\n",
2157 exp = tgt_obd->obd_self_export;
2160 err = obd_set_info(exp, keylen, key, vallen, val);
2164 spin_unlock(&lov->lov_lock);
2171 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2172 if (val && !obd_uuid_equals(val, &lov->tgts[i].uuid))
2175 if (!val && !lov->tgts[i].active)
2178 err = obd_set_info(lov->tgts[i].ltd_exp,
2179 keylen, key, vallen, val);
2188 struct lov_multi_wait {
2189 struct ldlm_lock *lock;
2195 int lov_complete_many(struct obd_export *exp, struct lov_stripe_md *lsm,
2196 struct lustre_handle *lockh)
2198 struct lov_lock_handles *lov_lockh = NULL;
2199 struct lustre_handle *lov_lockhp;
2200 struct lov_obd *lov;
2201 struct lov_oinfo *loi;
2202 struct lov_multi_wait *queues;
2206 if (lsm_bad_magic(lsm))
2209 if (!exp || !exp->exp_obd)
2212 LASSERT(lockh != NULL);
2213 if (lsm->lsm_stripe_count > 1) {
2214 lov_lockh = lov_handle2llh(lockh);
2215 if (lov_lockh == NULL) {
2216 CERROR("LOV: invalid lov lock handle %p\n", lockh);
2220 lov_lockhp = lov_lockh->llh_handles;
2225 OBD_ALLOC(queues, lsm->lsm_stripe_count * sizeof(*queues));
2227 GOTO(out, rc = -ENOMEM);
2229 lov = &exp->exp_obd->u.lov;
2230 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
2231 i++, loi++, lov_lockhp++) {
2232 struct ldlm_lock *lock;
2233 struct obd_device *obd;
2234 unsigned long irqflags;
2236 lock = ldlm_handle2lock(lov_lockhp);
2238 CDEBUG(D_HA, "lov idx %d subobj "LPX64" no lock?\n",
2239 loi->loi_ost_idx, loi->loi_id);
2240 queues[i].completed = 1;
2244 queues[i].lock = lock;
2245 init_waitqueue_entry(&(queues[i].wait), current);
2246 add_wait_queue(lock->l_waitq, &(queues[i].wait));
2248 obd = class_exp2obd(lock->l_conn_export);
2250 imp = obd->u.cli.cl_import;
2252 spin_lock_irqsave(&imp->imp_lock, irqflags);
2253 queues[i].generation = imp->imp_generation;
2254 spin_unlock_irqrestore(&imp->imp_lock, irqflags);
2258 lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, ldlm_expired_completion_wait,
2259 interrupted_completion_wait, &lwd);
2260 rc = l_wait_event_added(check_multi_complete(queues, lsm), &lwi);
2262 for (i = 0; i < lsm->lsm_stripe_count; i++)
2263 remove_wait_queue(lock->l_waitq, &(queues[i].wait));
2265 if (rc == -EINTR || rc == -ETIMEDOUT) {
2271 if (lov_lockh != NULL)
2272 lov_llh_put(lov_lockh);
2277 struct obd_ops lov_obd_ops = {
2278 .o_owner = THIS_MODULE,
2279 .o_attach = lov_attach,
2280 .o_detach = lov_detach,
2281 .o_setup = lov_setup,
2282 .o_cleanup = lov_cleanup,
2283 .o_process_config = lov_process_config,
2284 .o_connect = lov_connect,
2285 .o_disconnect = lov_disconnect,
2286 .o_statfs = lov_statfs,
2287 .o_packmd = lov_packmd,
2288 .o_unpackmd = lov_unpackmd,
2289 .o_revalidate_md = lov_revalidate_md,
2290 .o_create = lov_create,
2291 .o_destroy = lov_destroy,
2292 .o_getattr = lov_getattr,
2293 .o_getattr_async = lov_getattr_async,
2294 .o_setattr = lov_setattr,
2296 .o_brw_async = lov_brw_async,
2297 .o_prep_async_page = lov_prep_async_page,
2298 .o_queue_async_io = lov_queue_async_io,
2299 .o_set_async_flags = lov_set_async_flags,
2300 .o_queue_group_io = lov_queue_group_io,
2301 .o_trigger_group_io = lov_trigger_group_io,
2302 .o_teardown_async_page = lov_teardown_async_page,
2303 .o_adjust_kms = lov_adjust_kms,
2304 .o_punch = lov_punch,
2306 .o_enqueue = lov_enqueue,
2307 .o_match = lov_match,
2308 .o_change_cbdata = lov_change_cbdata,
2309 .o_cancel = lov_cancel,
2310 .o_cancel_unused = lov_cancel_unused,
2311 .o_iocontrol = lov_iocontrol,
2312 .o_get_info = lov_get_info,
2313 .o_set_info = lov_set_info,
2314 .o_llog_init = lov_llog_init,
2315 .o_llog_finish = lov_llog_finish,
2316 .o_notify = lov_notify,
2319 int __init lov_init(void)
2321 struct lprocfs_static_vars lvars;
2325 lprocfs_init_vars(lov, &lvars);
2326 rc = class_register_type(&lov_obd_ops, NULL, lvars.module_vars,
2327 OBD_LOV_DEVICENAME);
2332 static void /*__exit*/ lov_exit(void)
2334 class_unregister_type(OBD_LOV_DEVICENAME);
2337 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2338 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver");
2339 MODULE_LICENSE("GPL");
2341 module_init(lov_init);
2342 module_exit(lov_exit);