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, struct obd_connect_data *conn_data,
58 unsigned long connect_flags)
60 struct obd_uuid lov_osc_uuid = { "LOV_OSC_UUID" };
61 struct obd_uuid *tgt_uuid = &tgt->uuid;
64 struct proc_dir_entry *lov_proc_dir;
66 struct lov_obd *lov = &obd->u.lov;
67 struct lustre_handle conn = {0, };
68 struct obd_device *tgt_obd;
72 tgt_obd = class_find_client_obd(tgt_uuid, LUSTRE_OSC_NAME,
76 CERROR("Target %s not attached\n", tgt_uuid->uuid);
80 if (!tgt_obd->obd_set_up) {
81 CERROR("Target %s not set up\n", tgt_uuid->uuid);
86 tgt_obd->obd_no_recov = 0;
87 ptlrpc_activate_import(tgt_obd->u.cli.cl_import);
90 if (tgt_obd->u.cli.cl_import->imp_invalid) {
91 CERROR("not connecting OSC %s; administratively "
92 "disabled\n", tgt_uuid->uuid);
93 rc = obd_register_observer(tgt_obd, obd);
95 CERROR("Target %s register_observer error %d; "
96 "will not be able to reactivate\n",
102 rc = obd_connect(&conn, tgt_obd, &lov_osc_uuid, conn_data,
105 CERROR("Target %s connect error %d\n", tgt_uuid->uuid, rc);
108 tgt->ltd_exp = class_conn2export(&conn);
110 rc = obd_register_observer(tgt_obd, obd);
112 CERROR("Target %s register_observer error %d\n",
114 obd_disconnect(tgt->ltd_exp, 0);
120 lov->desc.ld_active_tgt_count++;
123 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
125 struct obd_device *osc_obd = class_conn2obd(&conn);
126 struct proc_dir_entry *osc_symlink;
127 char name[MAX_STRING_SIZE + 1];
129 LASSERT(osc_obd != NULL);
130 LASSERT(osc_obd->obd_type != NULL);
131 LASSERT(osc_obd->obd_type->typ_name != NULL);
132 name[MAX_STRING_SIZE] = '\0';
133 snprintf(name, MAX_STRING_SIZE, "../../../%s/%s",
134 osc_obd->obd_type->typ_name,
136 osc_symlink = proc_symlink(osc_obd->obd_name, lov_proc_dir,
138 if (osc_symlink == NULL) {
139 CERROR("could not register LOV target "
140 "/proc/fs/lustre/%s/%s/target_obds/%s\n",
141 obd->obd_type->typ_name, obd->obd_name,
143 lprocfs_remove(lov_proc_dir);
152 static int lov_connect(struct lustre_handle *conn, struct obd_device *obd,
153 struct obd_uuid *cluuid, struct obd_connect_data *data,
157 struct proc_dir_entry *lov_proc_dir;
159 struct lov_obd *lov = &obd->u.lov;
160 struct lov_tgt_desc *tgt;
161 struct obd_export *exp;
165 rc = class_connect(conn, obd, cluuid);
169 exp = class_conn2export(conn);
171 /* We don't want to actually do the underlying connections more than
172 * once, so keep track. */
174 if (lov->refcount > 1) {
175 class_export_put(exp);
180 lov_proc_dir = lprocfs_register("target_obds", obd->obd_proc_entry,
182 if (IS_ERR(lov_proc_dir)) {
183 CERROR("could not register /proc/fs/lustre/%s/%s/target_obds.",
184 obd->obd_type->typ_name, obd->obd_name);
189 /* connect_flags is the MDS number, save for use in lov_add_obd */
190 lov->lov_connect_flags = flags;
191 for (i = 0, tgt = lov->tgts; i < lov->desc.ld_tgt_count; i++, tgt++) {
192 if (obd_uuid_empty(&tgt->uuid))
194 rc = lov_connect_obd(obd, tgt, 0, data, flags);
199 class_export_put(exp);
205 lprocfs_remove(lov_proc_dir);
209 struct obd_uuid uuid;
211 --lov->desc.ld_active_tgt_count;
213 /* save for CERROR below; (we know it's terminated) */
215 rc2 = obd_disconnect(tgt->ltd_exp, 0);
217 CERROR("error: LOV target %s disconnect on OST idx %d: "
218 "rc = %d\n", uuid.uuid, i, rc2);
220 class_disconnect(exp, 0);
224 static int lov_disconnect_obd(struct obd_device *obd,
225 struct lov_tgt_desc *tgt,
229 struct proc_dir_entry *lov_proc_dir;
231 struct obd_device *osc_obd = class_exp2obd(tgt->ltd_exp);
232 struct lov_obd *lov = &obd->u.lov;
237 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
239 struct proc_dir_entry *osc_symlink;
241 osc_symlink = lprocfs_srch(lov_proc_dir, osc_obd->obd_name);
243 lprocfs_remove(osc_symlink);
245 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing\n",
246 obd->obd_type->typ_name, obd->obd_name,
251 if (obd->obd_no_recov) {
252 /* Pass it on to our clients.
253 * XXX This should be an argument to disconnect,
254 * XXX not a back-door flag on the OBD. Ah well.
257 osc_obd->obd_no_recov = 1;
260 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
261 rc = obd_disconnect(tgt->ltd_exp, flags);
264 CERROR("Target %s disconnect error %d\n",
272 lov->desc.ld_active_tgt_count--;
278 static int lov_disconnect(struct obd_export *exp, unsigned long flags)
280 struct obd_device *obd = class_exp2obd(exp);
282 struct proc_dir_entry *lov_proc_dir;
284 struct lov_obd *lov = &obd->u.lov;
285 struct lov_tgt_desc *tgt;
292 /* Only disconnect the underlying layers on the final disconnect. */
294 if (lov->refcount != 0)
297 for (i = 0, tgt = lov->tgts; i < lov->desc.ld_tgt_count; i++, tgt++) {
299 lov_disconnect_obd(obd, tgt, flags);
303 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
305 lprocfs_remove(lov_proc_dir);
307 CERROR("/proc/fs/lustre/%s/%s/target_obds missing.",
308 obd->obd_type->typ_name, obd->obd_name);
313 rc = class_disconnect(exp, 0);
319 * -EINVAL : UUID can't be found in the LOV's target list
320 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
321 * -EBADF : The UUID is found, but the OBD is the wrong type (!)
323 static int lov_set_osc_active(struct lov_obd *lov, struct obd_uuid *uuid,
326 struct lov_tgt_desc *tgt;
330 CDEBUG(D_INFO, "Searching in lov %p for uuid %s (activate=%d)\n",
331 lov, uuid->uuid, activate);
333 spin_lock(&lov->lov_lock);
334 for (i = 0, tgt = lov->tgts; i < lov->desc.ld_tgt_count; i++, tgt++) {
335 if (tgt->ltd_exp == NULL)
338 CDEBUG(D_INFO, "lov idx %d is %s conn "LPX64"\n",
339 i, tgt->uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
341 if (obd_uuid_equals(uuid, &tgt->uuid))
345 if (i == lov->desc.ld_tgt_count)
346 GOTO(out, rc = -EINVAL);
349 if (tgt->active == activate) {
350 CDEBUG(D_INFO, "OSC %s already %sactive!\n", uuid->uuid,
351 activate ? "" : "in");
355 CDEBUG(D_INFO, "Marking OSC %s %sactive\n", uuid->uuid,
356 activate ? "" : "in");
358 tgt->active = activate;
360 lov->desc.ld_active_tgt_count++;
362 lov->desc.ld_active_tgt_count--;
366 spin_unlock(&lov->lov_lock);
370 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
371 int active, void *data)
373 struct obd_uuid *uuid;
377 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
378 CERROR("unexpected notification of %s %s!\n",
379 watched->obd_type->typ_name,
383 uuid = &watched->u.cli.cl_import->imp_target_uuid;
385 /* Set OSC as active before notifying the observer, so the
386 * observer can use the OSC normally.
388 rc = lov_set_osc_active(&obd->u.lov, uuid, active);
390 CERROR("%sactivation of %s failed: %d\n",
391 active ? "" : "de", uuid->uuid, rc);
395 if (obd->obd_observer)
396 /* Pass the notification up the chain. */
397 rc = obd_notify(obd->obd_observer, watched, active, data);
402 int lov_attach(struct obd_device *dev, obd_count len, void *data)
404 struct lprocfs_static_vars lvars;
407 lprocfs_init_vars(lov, &lvars);
408 rc = lprocfs_obd_attach(dev, lvars.obd_vars);
411 struct proc_dir_entry *entry;
413 entry = create_proc_entry("target_obd_status", 0444,
414 dev->obd_proc_entry);
418 entry->proc_fops = &lov_proc_target_fops;
426 int lov_detach(struct obd_device *dev)
428 return lprocfs_obd_detach(dev);
431 static int lov_setup(struct obd_device *obd, obd_count len, void *buf)
433 struct lov_obd *lov = &obd->u.lov;
434 struct lustre_cfg *lcfg = buf;
435 struct lov_desc *desc;
439 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
440 CERROR("LOV setup requires a descriptor\n");
444 desc = (struct lov_desc *)lustre_cfg_string(lcfg, 1);
445 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
446 CERROR("descriptor size wrong: %d > %d\n",
447 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
451 /* Because of 64-bit divide/mod operations only work with a 32-bit
452 * divisor in a 32-bit kernel, we cannot support a stripe width
453 * of 4GB or larger on 32-bit CPUs.
456 count = desc->ld_default_stripe_count;
457 if (count && (count * desc->ld_default_stripe_size) > ~0UL) {
458 CERROR("LOV: stripe width "LPU64"x%u > %lu on 32-bit system\n",
459 desc->ld_default_stripe_size, count, ~0UL);
462 if (desc->ld_tgt_count > 0) {
463 lov->bufsize= sizeof(struct lov_tgt_desc) * desc->ld_tgt_count;
465 lov->bufsize = sizeof(struct lov_tgt_desc) * LOV_MAX_TGT_COUNT;
467 OBD_ALLOC(lov->tgts, lov->bufsize);
468 if (lov->tgts == NULL) {
470 CERROR("couldn't allocate %d bytes for target table.\n",
475 desc->ld_tgt_count = 0;
476 desc->ld_active_tgt_count = 0;
478 spin_lock_init(&lov->lov_lock);
479 sema_init(&lov->lov_llog_sem, 1);
484 static int lov_cleanup(struct obd_device *obd, int flags)
486 struct lov_obd *lov = &obd->u.lov;
488 OBD_FREE(lov->tgts, lov->bufsize);
493 lov_add_obd(struct obd_device *obd, struct obd_uuid *uuidp, int index, int gen)
495 struct lov_obd *lov = &obd->u.lov;
496 struct lov_tgt_desc *tgt;
500 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d\n",
501 uuidp->uuid, index, gen);
503 if ((index < 0) || (index >= LOV_MAX_TGT_COUNT)) {
504 CERROR("request to add OBD %s at invalid index: %d\n",
510 CERROR("request to add OBD %s with invalid generation: %d\n",
515 tgt = lov->tgts + index;
516 if (!obd_uuid_empty(&tgt->uuid)) {
517 CERROR("OBD already assigned at LOV target index %d\n",
523 /* XXX - add a sanity check on the generation number. */
526 if (index >= lov->desc.ld_tgt_count)
527 lov->desc.ld_tgt_count = index + 1;
529 CDEBUG(D_CONFIG, "idx: %d ltd_gen: %d ld_tgt_count: %d\n",
530 index, tgt->ltd_gen, lov->desc.ld_tgt_count);
532 if (lov->refcount == 0)
536 struct obd_device *osc_obd;
538 osc_obd = class_exp2obd(tgt->ltd_exp);
540 osc_obd->obd_no_recov = 0;
543 rc = lov_connect_obd(obd, tgt, 1, NULL, lov->lov_connect_flags);
547 if (obd->obd_observer) {
548 /* tell the mds_lov about the new target */
549 rc = obd_notify(obd->obd_observer, tgt->ltd_exp->exp_obd, 1,
555 if (rc && tgt->ltd_exp != NULL)
556 lov_disconnect_obd(obd, tgt, 0);
561 lov_del_obd(struct obd_device *obd, struct obd_uuid *uuidp, int index, int gen)
563 struct lov_obd *lov = &obd->u.lov;
564 struct lov_tgt_desc *tgt;
565 int count = lov->desc.ld_tgt_count;
569 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d\n",
570 uuidp->uuid, index, gen);
572 if (index >= count) {
573 CERROR("LOV target index %d >= number of LOV OBDs %d.\n",
578 tgt = lov->tgts + index;
580 if (obd_uuid_empty(&tgt->uuid)) {
581 CERROR("LOV target at index %d is not setup.\n", index);
585 if (!obd_uuid_equals(uuidp, &tgt->uuid)) {
586 CERROR("LOV target UUID %s at index %d doesn't match %s.\n",
587 tgt->uuid.uuid, index, uuidp->uuid);
592 struct obd_device *osc_obd;
594 osc_obd = class_exp2obd(tgt->ltd_exp);
596 osc_obd->obd_no_recov = 1;
597 rc = obd_llog_finish(osc_obd, &osc_obd->obd_llogs, 1);
599 CERROR("osc_llog_finish error: %d\n", rc);
601 lov_disconnect_obd(obd, tgt, 0);
604 /* XXX - right now there is a dependency on ld_tgt_count being the
605 * maximum tgt index for computing the mds_max_easize. So we can't
608 /* lt_gen = 0 will mean it will not match the gen of any valid loi */
609 memset(tgt, 0, sizeof(*tgt));
611 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d exp: %p active: %d\n",
612 tgt->uuid.uuid, index, tgt->ltd_gen, tgt->ltd_exp, tgt->active);
617 static int lov_process_config(struct obd_device *obd, obd_count len, void *buf)
619 struct lustre_cfg *lcfg = buf;
620 struct obd_uuid obd_uuid;
627 switch(cmd = lcfg->lcfg_command) {
628 case LCFG_LOV_ADD_OBD:
629 case LCFG_LOV_DEL_OBD: {
630 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
631 GOTO(out, rc = -EINVAL);
633 obd_str2uuid(&obd_uuid, lustre_cfg_string(lcfg, 1));
635 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
636 GOTO(out, rc = -EINVAL);
637 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
638 GOTO(out, rc = -EINVAL);
639 if (cmd == LCFG_LOV_ADD_OBD)
640 rc = lov_add_obd(obd, &obd_uuid, index, gen);
642 rc = lov_del_obd(obd, &obd_uuid, index, gen);
646 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
647 GOTO(out, rc = -EINVAL);
656 #define log2(n) ffz(~(n))
659 static int lov_clear_orphans(struct obd_export *export,
661 struct lov_stripe_md **ea,
662 struct obd_trans_info *oti)
666 struct obd_uuid *ost_uuid = NULL;
670 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
671 src_oa->o_flags == OBD_FL_DELORPHAN);
673 lov = &export->exp_obd->u.lov;
675 tmp_oa = obdo_alloc();
679 if (src_oa->o_valid & OBD_MD_FLINLINE) {
680 ost_uuid = (struct obd_uuid *)src_oa->o_inline;
681 CDEBUG(D_HA, "clearing orphans only for %s\n",
685 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
687 struct lov_stripe_md obj_md;
688 struct lov_stripe_md *obj_mdp = &obj_md;
691 * if called for a specific target, we don't care if it is not
694 if (lov->tgts[i].active == 0 && ost_uuid == NULL) {
695 CDEBUG(D_HA, "lov idx %d inactive\n", i);
699 if (ost_uuid && !obd_uuid_equals(ost_uuid, &lov->tgts[i].uuid))
703 * setting up objid OSS objects should be destroyed starting
706 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
707 tmp_oa->o_valid |= OBD_MD_FLID;
708 tmp_oa->o_id = oti->oti_objid[i];
710 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
711 err = obd_create(lov->tgts[i].ltd_exp, tmp_oa, NULL, 0,
715 * this export will be disabled until it is recovered,
716 * and then orphan recovery will be completed.
718 CERROR("error in orphan recovery on OST idx %d/%d: "
719 "rc = %d\n", i, lov->desc.ld_tgt_count, err);
729 /* the LOV expects oa->o_id to be set to the LOV object id */
731 lov_create(struct obd_export *exp, struct obdo *src_oa,
732 void *acl, int acl_size, struct lov_stripe_md **ea,
733 struct obd_trans_info *oti)
735 struct lov_request_set *set = NULL;
736 struct list_head *pos;
745 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
746 src_oa->o_flags == OBD_FL_DELORPHAN) {
747 rc = lov_clear_orphans(exp, src_oa, ea, oti);
751 lov = &exp->exp_obd->u.lov;
752 if (!lov->desc.ld_active_tgt_count)
755 LASSERT(oti->oti_flags & OBD_MODE_CROW);
757 /* main creation loop */
758 rc = lov_prep_create_set(exp, ea, src_oa, oti, &set);
762 list_for_each (pos, &set->set_list) {
763 struct lov_request *req =
764 list_entry(pos, struct lov_request, rq_link);
766 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
767 rc = obd_create(lov->tgts[req->rq_idx].ltd_exp,
768 req->rq_oa, NULL, 0, &req->rq_md, oti);
769 lov_update_create_set(set, req, rc);
771 rc = lov_fini_create_set(set, ea);
775 #define lsm_bad_magic(LSMP) \
777 struct lov_stripe_md *_lsm__ = (LSMP); \
780 CERROR("LOV requires striping ea\n"); \
782 } else if (_lsm__->lsm_magic != LOV_MAGIC) { \
783 CERROR("LOV striping magic bad %#x != %#x\n", \
784 _lsm__->lsm_magic, LOV_MAGIC); \
790 static int lov_destroy(struct obd_export *exp, struct obdo *oa,
791 struct lov_stripe_md *lsm, struct obd_trans_info *oti)
793 struct lov_request_set *set;
794 struct lov_request *req;
795 struct list_head *pos;
800 if (lsm_bad_magic(lsm))
803 if (!exp || !exp->exp_obd)
806 lov = &exp->exp_obd->u.lov;
807 rc = lov_prep_destroy_set(exp, oa, lsm, oti, &set);
811 list_for_each (pos, &set->set_list) {
813 req = list_entry(pos, struct lov_request, rq_link);
815 /* XXX update the cookie position */
816 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
817 rc = obd_destroy(lov->tgts[req->rq_idx].ltd_exp, req->rq_oa,
819 err = lov_update_common_set(set, req, rc);
821 CERROR("error: destroying objid "LPX64" subobj "
822 LPX64" on OST idx %d: rc = %d\n",
823 set->set_oa->o_id, req->rq_oa->o_id,
829 lov_fini_destroy_set(set);
833 static int lov_getattr(struct obd_export *exp, struct obdo *oa,
834 struct lov_stripe_md *lsm)
836 struct lov_request_set *set;
837 struct lov_request *req;
838 struct list_head *pos;
843 if (lsm_bad_magic(lsm))
846 if (!exp || !exp->exp_obd)
849 lov = &exp->exp_obd->u.lov;
851 rc = lov_prep_getattr_set(exp, oa, lsm, &set);
855 list_for_each (pos, &set->set_list) {
856 req = list_entry(pos, struct lov_request, rq_link);
858 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
859 "%u\n", oa->o_id, req->rq_stripe, req->rq_oa->o_id,
862 rc = obd_getattr(lov->tgts[req->rq_idx].ltd_exp,
864 err = lov_update_common_set(set, req, rc);
866 CERROR("error: getattr objid "LPX64" subobj "
867 LPX64" on OST idx %d: rc = %d\n",
868 set->set_oa->o_id, req->rq_oa->o_id,
874 rc = lov_fini_getattr_set(set);
880 static int lov_getattr_interpret(struct ptlrpc_request_set *rqset, void *data,
883 struct lov_request_set *lovset = (struct lov_request_set *)data;
886 /* don't do attribute merge if this aysnc op failed */
888 lovset->set_completes = 0;
889 lov_fini_getattr_set(lovset);
891 rc = lov_fini_getattr_set(lovset);
896 static int lov_getattr_async(struct obd_export *exp, struct obdo *oa,
897 struct lov_stripe_md *lsm,
898 struct ptlrpc_request_set *rqset)
900 struct lov_request_set *lovset;
902 struct list_head *pos;
903 struct lov_request *req;
907 if (lsm_bad_magic(lsm))
910 if (!exp || !exp->exp_obd)
913 lov = &exp->exp_obd->u.lov;
915 rc = lov_prep_getattr_set(exp, oa, lsm, &lovset);
919 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
920 lsm->lsm_object_id, lsm->lsm_stripe_count, lsm->lsm_stripe_size);
922 list_for_each (pos, &lovset->set_list) {
923 req = list_entry(pos, struct lov_request, rq_link);
925 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
926 "%u\n", oa->o_id, req->rq_stripe, req->rq_oa->o_id,
928 rc = obd_getattr_async(lov->tgts[req->rq_idx].ltd_exp,
929 req->rq_oa, NULL, rqset);
931 CERROR("error: getattr objid "LPX64" subobj "
932 LPX64" on OST idx %d: rc = %d\n",
933 lovset->set_oa->o_id, req->rq_oa->o_id,
937 lov_update_common_set(lovset, req, rc);
941 LASSERT (rqset->set_interpret == NULL);
942 rqset->set_interpret = lov_getattr_interpret;
943 rqset->set_arg = (void *)lovset;
947 lov_fini_getattr_set(lovset);
951 static int lov_setattr(struct obd_export *exp, struct obdo *src_oa,
952 struct lov_stripe_md *lsm, struct obd_trans_info *oti)
954 struct lov_request_set *set;
956 struct list_head *pos;
957 struct lov_request *req;
961 if (lsm_bad_magic(lsm))
964 if (!exp || !exp->exp_obd)
967 LASSERT(!(src_oa->o_valid & ~(OBD_MD_FLID|OBD_MD_FLTYPE | OBD_MD_FLMODE|
968 OBD_MD_FLATIME | OBD_MD_FLMTIME |
969 OBD_MD_FLCTIME | OBD_MD_FLFLAGS |
970 OBD_MD_FLSIZE | OBD_MD_FLGROUP |
971 OBD_MD_FLUID | OBD_MD_FLGID |
974 LASSERT(!(src_oa->o_valid & OBD_MD_FLGROUP) || src_oa->o_gr > 0);
976 lov = &exp->exp_obd->u.lov;
977 rc = lov_prep_setattr_set(exp, src_oa, lsm, NULL, &set);
981 list_for_each (pos, &set->set_list) {
982 req = list_entry(pos, struct lov_request, rq_link);
984 rc = obd_setattr(lov->tgts[req->rq_idx].ltd_exp, req->rq_oa,
986 err = lov_update_common_set(set, req, rc);
988 CERROR("error: setattr objid "LPX64" subobj "
989 LPX64" on OST idx %d: rc = %d\n",
990 set->set_oa->o_id, req->rq_oa->o_id,
996 err = lov_fini_setattr_set(set);
1002 static int lov_revalidate_policy(struct lov_obd *lov, struct lov_stripe_md *lsm)
1004 static int next_idx = 0;
1005 struct lov_tgt_desc *tgt;
1008 /* XXX - we should do something clever and take lsm
1009 * into account but just do round robin for now. */
1011 /* last_idx must always be less that count because
1012 * ld_tgt_count currently cannot shrink. */
1013 count = lov->desc.ld_tgt_count;
1015 for (i = next_idx, tgt = lov->tgts + i; i < count; i++, tgt++) {
1017 next_idx = (i + 1) % count;
1022 for (i = 0, tgt = lov->tgts; i < next_idx; i++, tgt++) {
1024 next_idx = (i + 1) % count;
1032 static int lov_revalidate_md(struct obd_export *exp, struct obdo *src_oa,
1033 struct lov_stripe_md *ea,
1034 struct obd_trans_info *oti)
1036 struct obd_export *osc_exp;
1037 struct lov_obd *lov = &exp->exp_obd->u.lov;
1038 struct lov_stripe_md *lsm = ea;
1039 struct lov_stripe_md obj_md;
1040 struct lov_stripe_md *obj_mdp = &obj_md;
1041 struct lov_oinfo *loi;
1042 struct obdo *tmp_oa;
1043 int ost_idx, updates = 0, i;
1046 tmp_oa = obdo_alloc();
1050 loi = lsm->lsm_oinfo;
1051 for (i = 0; i < lsm->lsm_stripe_count; i++, loi++) {
1053 if (!obd_uuid_empty(&lov->tgts[loi->loi_ost_idx].uuid))
1056 ost_idx = lov_revalidate_policy(lov, lsm);
1058 /* FIXME: punt for now. */
1059 CERROR("lov_revalidate_policy failed; no active "
1064 /* create a new object */
1065 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
1066 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1067 osc_exp = lov->tgts[ost_idx].ltd_exp;
1068 rc = obd_create(osc_exp, tmp_oa, NULL, 0, &obj_mdp, oti);
1070 CERROR("error creating new subobj at idx %d; "
1071 "rc = %d\n", ost_idx, rc);
1075 oti->oti_objid[ost_idx] = tmp_oa->o_id;
1076 loi->loi_id = tmp_oa->o_id;
1077 loi->loi_gr = tmp_oa->o_gr;
1078 loi->loi_ost_idx = ost_idx;
1079 loi->loi_ost_gen = lov->tgts[ost_idx].ltd_gen;
1080 CDEBUG(D_INODE, "replacing objid "LPX64" subobj "LPX64
1081 " with idx %d gen %d.\n", lsm->lsm_object_id,
1082 loi->loi_id, ost_idx, loi->loi_ost_gen);
1086 /* If we got an error revalidating an entry there's no need to
1087 * cleanup up objects we allocated here because the bad entry
1088 * still points to a deleted OST. */
1094 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
1095 * we can send this 'punch' to just the authoritative node and the nodes
1096 * that the punch will affect. */
1097 static int lov_punch(struct obd_export *exp, struct obdo *oa,
1098 struct lov_stripe_md *lsm,
1099 obd_off start, obd_off end, struct obd_trans_info *oti)
1101 struct lov_request_set *set;
1102 struct lov_obd *lov;
1103 struct list_head *pos;
1104 struct lov_request *req;
1105 int err = 0, rc = 0;
1108 if (lsm_bad_magic(lsm))
1111 if (!exp || !exp->exp_obd)
1114 lov = &exp->exp_obd->u.lov;
1115 rc = lov_prep_punch_set(exp, oa, lsm, start, end, oti, &set);
1119 list_for_each (pos, &set->set_list) {
1120 req = list_entry(pos, struct lov_request, rq_link);
1122 rc = obd_punch(lov->tgts[req->rq_idx].ltd_exp, req->rq_oa,
1123 NULL, req->rq_extent.start,
1124 req->rq_extent.end, NULL);
1125 err = lov_update_punch_set(set, req, rc);
1127 CERROR("error: punch objid "LPX64" subobj "LPX64
1128 " on OST idx %d: rc = %d\n", set->set_oa->o_id,
1129 req->rq_oa->o_id, req->rq_idx, rc);
1134 err = lov_fini_punch_set(set);
1140 static int lov_sync(struct obd_export *exp, struct obdo *oa,
1141 struct lov_stripe_md *lsm, obd_off start, obd_off end)
1143 struct lov_request_set *set;
1144 struct lov_obd *lov;
1145 struct list_head *pos;
1146 struct lov_request *req;
1147 int err = 0, rc = 0;
1150 if (lsm_bad_magic(lsm))
1156 lov = &exp->exp_obd->u.lov;
1157 rc = lov_prep_sync_set(exp, oa, lsm, start, end, &set);
1161 list_for_each (pos, &set->set_list) {
1162 req = list_entry(pos, struct lov_request, rq_link);
1164 rc = obd_sync(lov->tgts[req->rq_idx].ltd_exp, req->rq_oa,
1165 NULL, req->rq_extent.start, req->rq_extent.end);
1166 err = lov_update_common_set(set, req, rc);
1168 CERROR("error: fsync objid "LPX64" subobj "LPX64
1169 " on OST idx %d: rc = %d\n", set->set_oa->o_id,
1170 req->rq_oa->o_id, req->rq_idx, rc);
1175 err = lov_fini_sync_set(set);
1181 static int lov_brw_check(struct lov_obd *lov, struct obdo *oa,
1182 struct lov_stripe_md *lsm,
1183 obd_count oa_bufs, struct brw_page *pga)
1188 /* The caller just wants to know if there's a chance that this
1189 * I/O can succeed */
1190 for (i = 0; i < oa_bufs; i++) {
1191 int stripe = lov_stripe_number(lsm, pga[i].disk_offset);
1192 int ost = lsm->lsm_oinfo[stripe].loi_ost_idx;
1195 if (!lov_stripe_intersects(lsm, i, pga[i].disk_offset,
1196 pga[i].disk_offset + pga[i].count,
1200 if (lov->tgts[ost].active == 0) {
1201 CDEBUG(D_HA, "lov idx %d inactive\n", ost);
1204 rc = obd_brw(OBD_BRW_CHECK, lov->tgts[ost].ltd_exp, oa,
1205 NULL, 1, &pga[i], NULL);
1212 static int lov_brw(int cmd, struct obd_export *exp, struct obdo *src_oa,
1213 struct lov_stripe_md *lsm, obd_count oa_bufs,
1214 struct brw_page *pga, struct obd_trans_info *oti)
1216 struct lov_request_set *set;
1217 struct lov_request *req;
1218 struct list_head *pos;
1219 struct lov_obd *lov = &exp->exp_obd->u.lov;
1223 if (lsm_bad_magic(lsm))
1226 if (cmd == OBD_BRW_CHECK) {
1227 rc = lov_brw_check(lov, src_oa, lsm, oa_bufs, pga);
1231 rc = lov_prep_brw_set(exp, src_oa, lsm, oa_bufs, pga, oti, &set);
1235 list_for_each (pos, &set->set_list) {
1236 struct obd_export *sub_exp;
1237 struct brw_page *sub_pga;
1238 req = list_entry(pos, struct lov_request, rq_link);
1240 sub_exp = lov->tgts[req->rq_idx].ltd_exp;
1241 sub_pga = set->set_pga + req->rq_pgaidx;
1242 rc = obd_brw(cmd, sub_exp, req->rq_oa, req->rq_md,
1243 req->rq_oabufs, sub_pga, oti);
1246 lov_update_common_set(set, req, rc);
1249 err = lov_fini_brw_set(set);
1255 static int lov_brw_interpret(struct ptlrpc_request_set *reqset, void *data,
1258 struct lov_request_set *lovset = (struct lov_request_set *)data;
1262 lovset->set_completes = 0;
1263 lov_fini_brw_set(lovset);
1265 rc = lov_fini_brw_set(lovset);
1271 static int lov_brw_async(int cmd, struct obd_export *exp, struct obdo *oa,
1272 struct lov_stripe_md *lsm, obd_count oa_bufs,
1273 struct brw_page *pga, struct ptlrpc_request_set *set,
1274 struct obd_trans_info *oti)
1276 struct lov_request_set *lovset;
1277 struct lov_request *req;
1278 struct list_head *pos;
1279 struct lov_obd *lov = &exp->exp_obd->u.lov;
1283 if (lsm_bad_magic(lsm))
1286 if (cmd == OBD_BRW_CHECK) {
1287 rc = lov_brw_check(lov, oa, lsm, oa_bufs, pga);
1291 rc = lov_prep_brw_set(exp, oa, lsm, oa_bufs, pga, oti, &lovset);
1295 list_for_each (pos, &lovset->set_list) {
1296 struct obd_export *sub_exp;
1297 struct brw_page *sub_pga;
1298 req = list_entry(pos, struct lov_request, rq_link);
1300 sub_exp = lov->tgts[req->rq_idx].ltd_exp;
1301 sub_pga = lovset->set_pga + req->rq_pgaidx;
1302 rc = obd_brw_async(cmd, sub_exp, req->rq_oa, req->rq_md,
1303 req->rq_oabufs, sub_pga, set, oti);
1306 lov_update_common_set(lovset, req, rc);
1309 LASSERT(set->set_interpret == NULL);
1310 set->set_interpret = (set_interpreter_func)lov_brw_interpret;
1311 set->set_arg = (void *)lovset;
1315 lov_fini_brw_set(lovset);
1319 static int lov_ap_make_ready(void *data, int cmd)
1321 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1323 return lap->lap_caller_ops->ap_make_ready(lap->lap_caller_data, cmd);
1325 static int lov_ap_refresh_count(void *data, int cmd)
1327 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1329 return lap->lap_caller_ops->ap_refresh_count(lap->lap_caller_data,
1332 static void lov_ap_fill_obdo(void *data, int cmd, struct obdo *oa)
1334 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1336 lap->lap_caller_ops->ap_fill_obdo(lap->lap_caller_data, cmd, oa);
1337 /* XXX woah, shouldn't we be altering more here? size? */
1338 oa->o_id = lap->lap_loi_id;
1341 static void lov_ap_completion(void *data, int cmd, struct obdo *oa, int rc)
1343 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1345 /* in a raid1 regime this would down a count of many ios
1346 * in flight, onl calling the caller_ops completion when all
1347 * the raid1 ios are complete */
1348 lap->lap_caller_ops->ap_completion(lap->lap_caller_data, cmd, oa, rc);
1351 static struct obd_async_page_ops lov_async_page_ops = {
1352 .ap_make_ready = lov_ap_make_ready,
1353 .ap_refresh_count = lov_ap_refresh_count,
1354 .ap_fill_obdo = lov_ap_fill_obdo,
1355 .ap_completion = lov_ap_completion,
1358 static int lov_prep_async_page(struct obd_export *exp,
1359 struct lov_stripe_md *lsm,
1360 struct lov_oinfo *loi, struct page *page,
1361 obd_off offset, struct obd_async_page_ops *ops,
1362 void *data, void **res)
1364 struct lov_obd *lov = &exp->exp_obd->u.lov;
1365 struct lov_async_page *lap;
1369 if (lsm_bad_magic(lsm))
1371 LASSERT(loi == NULL);
1373 stripe = lov_stripe_number(lsm, offset);
1374 loi = &lsm->lsm_oinfo[stripe];
1376 if (obd_uuid_empty(&lov->tgts[loi->loi_ost_idx].uuid))
1378 if (lov->tgts[loi->loi_ost_idx].active == 0)
1380 if (lov->tgts[loi->loi_ost_idx].ltd_exp == NULL) {
1381 CERROR("ltd_exp == NULL, but OST idx %d doesn't appear to be "
1382 "deleted or inactive.\n", loi->loi_ost_idx);
1386 OBD_ALLOC(lap, sizeof(*lap));
1390 lap->lap_magic = LAP_MAGIC;
1391 lap->lap_caller_ops = ops;
1392 lap->lap_caller_data = data;
1394 /* FIXME handle multiple oscs after landing b_raid1 */
1395 lap->lap_stripe = stripe;
1396 switch (lsm->lsm_pattern) {
1397 case LOV_PATTERN_RAID0:
1398 lov_stripe_offset(lsm, offset, lap->lap_stripe,
1399 &lap->lap_sub_offset);
1401 case LOV_PATTERN_CMOBD:
1402 lap->lap_sub_offset = offset;
1408 /* so the callback doesn't need the lsm */
1409 lap->lap_loi_id = loi->loi_id;
1411 rc = obd_prep_async_page(lov->tgts[loi->loi_ost_idx].ltd_exp,
1412 lsm, loi, page, lap->lap_sub_offset,
1413 &lov_async_page_ops, lap,
1414 &lap->lap_sub_cookie);
1416 OBD_FREE(lap, sizeof(*lap));
1419 CDEBUG(D_CACHE, "lap %p page %p cookie %p off "LPU64"\n", lap, page,
1420 lap->lap_sub_cookie, offset);
1425 static int lov_queue_async_io(struct obd_export *exp,
1426 struct lov_stripe_md *lsm,
1427 struct lov_oinfo *loi, void *cookie,
1428 int cmd, obd_off off, int count,
1429 obd_flags brw_flags, obd_flags async_flags)
1431 struct lov_obd *lov = &exp->exp_obd->u.lov;
1432 struct lov_async_page *lap;
1435 LASSERT(loi == NULL);
1437 if (lsm_bad_magic(lsm))
1440 lap = LAP_FROM_COOKIE(cookie);
1442 loi = &lsm->lsm_oinfo[lap->lap_stripe];
1444 rc = obd_queue_async_io(lov->tgts[loi->loi_ost_idx].ltd_exp, lsm,
1445 loi, lap->lap_sub_cookie, cmd, off, count,
1446 brw_flags, async_flags);
1450 static int lov_set_async_flags(struct obd_export *exp,
1451 struct lov_stripe_md *lsm,
1452 struct lov_oinfo *loi, void *cookie,
1453 obd_flags async_flags)
1455 struct lov_obd *lov = &exp->exp_obd->u.lov;
1456 struct lov_async_page *lap;
1459 LASSERT(loi == NULL);
1461 if (lsm_bad_magic(lsm))
1464 lap = LAP_FROM_COOKIE(cookie);
1466 loi = &lsm->lsm_oinfo[lap->lap_stripe];
1468 rc = obd_set_async_flags(lov->tgts[loi->loi_ost_idx].ltd_exp,
1469 lsm, loi, lap->lap_sub_cookie, async_flags);
1473 static int lov_queue_group_io(struct obd_export *exp,
1474 struct lov_stripe_md *lsm,
1475 struct lov_oinfo *loi,
1476 struct obd_io_group *oig, void *cookie,
1477 int cmd, obd_off off, int count,
1478 obd_flags brw_flags, obd_flags async_flags)
1480 struct lov_obd *lov = &exp->exp_obd->u.lov;
1481 struct lov_async_page *lap;
1484 LASSERT(loi == NULL);
1486 if (lsm_bad_magic(lsm))
1489 lap = LAP_FROM_COOKIE(cookie);
1491 loi = &lsm->lsm_oinfo[lap->lap_stripe];
1493 rc = obd_queue_group_io(lov->tgts[loi->loi_ost_idx].ltd_exp, lsm, loi,
1494 oig, lap->lap_sub_cookie, cmd, off, count,
1495 brw_flags, async_flags);
1499 /* this isn't exactly optimal. we may have queued sync io in oscs on
1500 * all stripes, but we don't record that fact at queue time. so we
1501 * trigger sync io on all stripes. */
1502 static int lov_trigger_group_io(struct obd_export *exp,
1503 struct lov_stripe_md *lsm,
1504 struct lov_oinfo *loi,
1505 struct obd_io_group *oig)
1507 struct lov_obd *lov = &exp->exp_obd->u.lov;
1510 LASSERT(loi == NULL);
1512 if (lsm_bad_magic(lsm))
1515 loi = lsm->lsm_oinfo;
1516 for (i = 0; i < lsm->lsm_stripe_count; i++, loi++) {
1517 if (lov->tgts[loi->loi_ost_idx].active == 0) {
1518 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1522 err = obd_trigger_group_io(lov->tgts[loi->loi_ost_idx].ltd_exp,
1524 if (rc == 0 && err != 0)
1530 static int lov_teardown_async_page(struct obd_export *exp,
1531 struct lov_stripe_md *lsm,
1532 struct lov_oinfo *loi, void *cookie)
1534 struct lov_obd *lov = &exp->exp_obd->u.lov;
1535 struct lov_async_page *lap;
1538 LASSERT(loi == NULL);
1540 if (lsm_bad_magic(lsm))
1543 lap = LAP_FROM_COOKIE(cookie);
1545 loi = &lsm->lsm_oinfo[lap->lap_stripe];
1547 rc = obd_teardown_async_page(lov->tgts[loi->loi_ost_idx].ltd_exp,
1548 lsm, loi, lap->lap_sub_cookie);
1550 CERROR("unable to teardown sub cookie %p: %d\n",
1551 lap->lap_sub_cookie, rc);
1554 OBD_FREE(lap, sizeof(*lap));
1558 static int lov_enqueue(struct obd_export *exp, struct lov_stripe_md *lsm,
1559 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1560 int *flags, void *bl_cb, void *cp_cb, void *gl_cb,
1561 void *data,__u32 lvb_len, void *lvb_swabber,
1562 struct lustre_handle *lockh)
1564 struct lov_request_set *set;
1565 struct lov_request *req;
1566 struct list_head *pos;
1567 struct lustre_handle *lov_lockhp;
1568 struct lov_obd *lov;
1570 int save_flags = *flags;
1573 if (lsm_bad_magic(lsm))
1576 /* we should never be asked to replay a lock this way. */
1577 LASSERT((*flags & LDLM_FL_REPLAY) == 0);
1579 if (!exp || !exp->exp_obd)
1582 lov = &exp->exp_obd->u.lov;
1583 rc = lov_prep_enqueue_set(exp, lsm, policy, mode, lockh, &set);
1587 list_for_each (pos, &set->set_list) {
1588 ldlm_policy_data_t sub_policy;
1589 req = list_entry(pos, struct lov_request, rq_link);
1590 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
1591 LASSERT(lov_lockhp);
1593 *flags = save_flags;
1594 sub_policy.l_extent.start = req->rq_extent.start;
1595 sub_policy.l_extent.end = req->rq_extent.end;
1597 rc = obd_enqueue(lov->tgts[req->rq_idx].ltd_exp, req->rq_md,
1598 type, &sub_policy, mode, flags, bl_cb,
1599 cp_cb, gl_cb, data, lvb_len, lvb_swabber,
1601 rc = lov_update_enqueue_set(set, req, rc, save_flags);
1606 lov_fini_enqueue_set(set, mode);
1610 static int lov_match(struct obd_export *exp, struct lov_stripe_md *lsm,
1611 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1612 int *flags, void *data, struct lustre_handle *lockh)
1614 struct lov_request_set *set;
1615 struct lov_request *req;
1616 struct list_head *pos;
1617 struct lov_obd *lov = &exp->exp_obd->u.lov;
1618 struct lustre_handle *lov_lockhp;
1619 int lov_flags, rc = 0;
1622 if (lsm_bad_magic(lsm))
1625 if (!exp || !exp->exp_obd)
1628 lov = &exp->exp_obd->u.lov;
1629 rc = lov_prep_match_set(exp, lsm, policy, mode, lockh, &set);
1633 list_for_each (pos, &set->set_list) {
1634 ldlm_policy_data_t sub_policy;
1635 req = list_entry(pos, struct lov_request, rq_link);
1636 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
1637 LASSERT(lov_lockhp);
1639 sub_policy.l_extent.start = req->rq_extent.start;
1640 sub_policy.l_extent.end = req->rq_extent.end;
1643 rc = obd_match(lov->tgts[req->rq_idx].ltd_exp, req->rq_md,
1644 type, &sub_policy, mode, &lov_flags, data,
1646 rc = lov_update_match_set(set, req, rc);
1650 lov_fini_match_set(set, mode, *flags);
1654 static int lov_change_cbdata(struct obd_export *exp,
1655 struct lov_stripe_md *lsm, ldlm_iterator_t it,
1658 struct lov_obd *lov;
1659 struct lov_oinfo *loi;
1663 if (lsm_bad_magic(lsm))
1666 if (!exp || !exp->exp_obd)
1669 LASSERT(lsm->lsm_object_gr > 0);
1671 lov = &exp->exp_obd->u.lov;
1672 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
1673 struct lov_stripe_md submd;
1674 if (lov->tgts[loi->loi_ost_idx].active == 0) {
1675 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1679 submd.lsm_object_id = loi->loi_id;
1680 submd.lsm_object_gr = lsm->lsm_object_gr;
1681 submd.lsm_stripe_count = 0;
1682 rc = obd_change_cbdata(lov->tgts[loi->loi_ost_idx].ltd_exp,
1688 static int lov_cancel(struct obd_export *exp, struct lov_stripe_md *lsm,
1689 __u32 mode, struct lustre_handle *lockh)
1691 struct lov_request_set *set;
1692 struct lov_request *req;
1693 struct list_head *pos;
1694 struct lov_obd *lov = &exp->exp_obd->u.lov;
1695 struct lustre_handle *lov_lockhp;
1696 int err = 0, rc = 0;
1699 if (lsm_bad_magic(lsm))
1702 if (!exp || !exp->exp_obd)
1705 LASSERT(lsm->lsm_object_gr > 0);
1708 lov = &exp->exp_obd->u.lov;
1709 rc = lov_prep_cancel_set(exp, lsm, mode, lockh, &set);
1713 list_for_each (pos, &set->set_list) {
1714 req = list_entry(pos, struct lov_request, rq_link);
1715 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
1717 rc = obd_cancel(lov->tgts[req->rq_idx].ltd_exp, req->rq_md,
1719 rc = lov_update_common_set(set, req, rc);
1721 CERROR("error: cancel objid "LPX64" subobj "
1722 LPX64" on OST idx %d: rc = %d\n",
1724 req->rq_md->lsm_object_id, req->rq_idx, rc);
1729 lov_fini_cancel_set(set);
1733 static int lov_cancel_unused(struct obd_export *exp,
1734 struct lov_stripe_md *lsm,
1735 int flags, void *opaque)
1737 struct lov_obd *lov;
1738 struct lov_oinfo *loi;
1742 lov = &exp->exp_obd->u.lov;
1744 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1745 int err = obd_cancel_unused(lov->tgts[i].ltd_exp,
1746 NULL, flags, opaque);
1753 if (lsm_bad_magic(lsm))
1756 if (!exp || !exp->exp_obd)
1759 LASSERT(lsm->lsm_object_gr > 0);
1761 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
1762 struct lov_stripe_md submd;
1765 if (lov->tgts[loi->loi_ost_idx].active == 0)
1766 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1768 submd.lsm_object_id = loi->loi_id;
1769 submd.lsm_object_gr = lsm->lsm_object_gr;
1770 submd.lsm_stripe_count = 0;
1771 err = obd_cancel_unused(lov->tgts[loi->loi_ost_idx].ltd_exp,
1772 &submd, flags, opaque);
1773 if (err && lov->tgts[loi->loi_ost_idx].active) {
1774 CERROR("error: cancel unused objid "LPX64" subobj "LPX64
1775 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
1776 loi->loi_id, loi->loi_ost_idx, err);
1784 #define LOV_U64_MAX ((__u64)~0ULL)
1785 #define LOV_SUM_MAX(tot, add) \
1787 if ((tot) + (add) < (tot)) \
1788 (tot) = LOV_U64_MAX; \
1793 static int lov_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1794 unsigned long max_age)
1796 struct lov_obd *lov = &obd->u.lov;
1797 struct obd_statfs lov_sfs;
1804 /* We only get block data from the OBD */
1805 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1807 if (!lov->tgts[i].active) {
1808 CDEBUG(D_HA, "lov idx %d inactive\n", i);
1812 err = obd_statfs(class_exp2obd(lov->tgts[i].ltd_exp), &lov_sfs,
1815 if (lov->tgts[i].active && !rc)
1821 memcpy(osfs, &lov_sfs, sizeof(lov_sfs));
1824 osfs->os_bfree += lov_sfs.os_bfree;
1825 osfs->os_bavail += lov_sfs.os_bavail;
1826 osfs->os_blocks += lov_sfs.os_blocks;
1827 /* XXX not sure about this one - depends on policy.
1828 * - could be minimum if we always stripe on all OBDs
1829 * (but that would be wrong for any other policy,
1830 * if one of the OBDs has no more objects left)
1831 * - could be sum if we stripe whole objects
1832 * - could be average, just to give a nice number
1834 * To give a "reasonable" (if not wholly accurate)
1835 * number, we divide the total number of free objects
1836 * by expected stripe count (watch out for overflow).
1838 LOV_SUM_MAX(osfs->os_files, lov_sfs.os_files);
1839 LOV_SUM_MAX(osfs->os_ffree, lov_sfs.os_ffree);
1844 __u32 expected_stripes = lov->desc.ld_default_stripe_count ?
1845 lov->desc.ld_default_stripe_count :
1846 lov->desc.ld_active_tgt_count;
1848 if (osfs->os_files != LOV_U64_MAX)
1849 do_div(osfs->os_files, expected_stripes);
1850 if (osfs->os_ffree != LOV_U64_MAX)
1851 do_div(osfs->os_ffree, expected_stripes);
1858 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1859 void *karg, void *uarg)
1861 struct obd_device *obddev = class_exp2obd(exp);
1862 struct lov_obd *lov = &obddev->u.lov;
1863 int i, rc, count = lov->desc.ld_tgt_count;
1864 struct obd_uuid *uuidp;
1868 case OBD_IOC_LOV_GET_CONFIG: {
1869 struct obd_ioctl_data *data = karg;
1870 struct lov_tgt_desc *tgtdesc;
1871 struct lov_desc *desc;
1877 if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
1880 data = (struct obd_ioctl_data *)buf;
1882 if (sizeof(*desc) > data->ioc_inllen1) {
1883 obd_ioctl_freedata(buf, len);
1887 if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
1888 obd_ioctl_freedata(buf, len);
1892 if (sizeof(__u32) * count > data->ioc_inllen3) {
1893 obd_ioctl_freedata(buf, len);
1897 desc = (struct lov_desc *)data->ioc_inlbuf1;
1898 memcpy(desc, &(lov->desc), sizeof(*desc));
1900 uuidp = (struct obd_uuid *)data->ioc_inlbuf2;
1901 genp = (__u32 *)data->ioc_inlbuf3;
1902 tgtdesc = lov->tgts;
1903 /* the uuid will be empty for deleted OSTs */
1904 for (i = 0; i < count; i++, uuidp++, genp++, tgtdesc++) {
1905 obd_str2uuid(uuidp, (char *)tgtdesc->uuid.uuid);
1906 *genp = tgtdesc->ltd_gen;
1909 rc = copy_to_user((void *)uarg, buf, len);
1912 obd_ioctl_freedata(buf, len);
1915 case LL_IOC_LOV_SETSTRIPE:
1916 rc = lov_setstripe(exp, karg, uarg);
1918 case LL_IOC_LOV_GETSTRIPE:
1919 rc = lov_getstripe(exp, karg, uarg);
1921 case LL_IOC_LOV_SETEA:
1922 rc = lov_setea(exp, karg, uarg);
1929 for (i = 0; i < count; i++) {
1932 /* OST was deleted */
1933 if (obd_uuid_empty(&lov->tgts[i].uuid))
1936 err = obd_iocontrol(cmd, lov->tgts[i].ltd_exp,
1939 if (lov->tgts[i].active) {
1940 CERROR("error: iocontrol OSC %s on OST "
1941 "idx %d cmd %x: err = %d\n",
1942 lov->tgts[i].uuid.uuid, i,
1958 static int lov_get_info(struct obd_export *exp, __u32 keylen,
1959 void *key, __u32 *vallen, void *val)
1961 struct obd_device *obddev = class_exp2obd(exp);
1962 struct lov_obd *lov = &obddev->u.lov;
1966 if (!vallen || !val)
1969 if (keylen > strlen("lock_to_stripe") &&
1970 strcmp(key, "lock_to_stripe") == 0) {
1973 struct ldlm_lock *lock;
1974 struct lov_stripe_md *lsm;
1976 struct lov_oinfo *loi;
1977 struct ldlm_res_id *res_id = &data->lock->l_resource->lr_name;
1978 __u32 *stripe = val;
1980 if (*vallen < sizeof(*stripe))
1982 *vallen = sizeof(*stripe);
1984 /* XXX This is another one of those bits that will need to
1985 * change if we ever actually support nested LOVs. It uses
1986 * the lock's export to find out which stripe it is. */
1987 /* XXX - it's assumed all the locks for deleted OSTs have
1988 * been cancelled. Also, the export for deleted OSTs will
1989 * be NULL and won't match the lock's export. */
1990 for (i = 0, loi = data->lsm->lsm_oinfo;
1991 i < data->lsm->lsm_stripe_count;
1993 if (lov->tgts[loi->loi_ost_idx].ltd_exp ==
1994 data->lock->l_conn_export &&
1995 loi->loi_id == res_id->name[0] &&
1996 loi->loi_gr == res_id->name[2]) {
2001 LDLM_ERROR(data->lock, "lock on inode without such object\n");
2002 dump_lsm(D_ERROR, data->lsm);
2003 portals_debug_dumpstack(NULL);
2005 } else if (keylen >= strlen("size_to_stripe") &&
2006 strcmp(key, "size_to_stripe") == 0) {
2010 struct lov_stripe_md *lsm;
2013 if (*vallen < sizeof(*data))
2016 data->size = lov_size_to_stripe(data->lsm, data->size,
2017 data->stripe_number);
2019 } else if (keylen >= strlen("last_id") && strcmp(key, "last_id") == 0) {
2020 __u32 size = sizeof(obd_id);
2024 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2025 if (!lov->tgts[i].active)
2027 rc = obd_get_info(lov->tgts[i].ltd_exp,
2028 keylen, key, &size, &(ids[i]));
2033 } else if (keylen >= strlen("lovdesc") && strcmp(key, "lovdesc") == 0) {
2034 struct lov_desc *desc_ret = val;
2035 *desc_ret = lov->desc;
2043 static int lov_set_info(struct obd_export *exp, obd_count keylen,
2044 void *key, obd_count vallen, void *val)
2046 struct obd_device *obddev = class_exp2obd(exp);
2047 struct lov_obd *lov = &obddev->u.lov;
2051 #define KEY_IS(str) \
2052 (keylen == strlen(str) && memcmp(key, str, keylen) == 0)
2054 if (KEY_IS("async")) {
2055 struct lov_desc *desc = &lov->desc;
2056 struct lov_tgt_desc *tgts = lov->tgts;
2058 if (vallen != sizeof(int))
2060 lov->async = *((int*) val);
2062 for (i = 0; i < desc->ld_tgt_count; i++, tgts++) {
2063 struct obd_uuid *tgt_uuid = &tgts->uuid;
2064 struct obd_device *tgt_obd;
2066 tgt_obd = class_find_client_obd(tgt_uuid,
2070 CERROR("Target %s not attached\n",
2077 err = obd_set_info(tgt_obd->obd_self_export,
2078 keylen, key, vallen, val);
2080 CERROR("Failed to set async on target %s\n",
2089 if (KEY_IS("mds_conn")) {
2090 if (vallen != sizeof(__u32))
2092 } else if (KEY_IS("unlinked") || KEY_IS("unrecovery")) {
2095 } else if (KEY_IS("sec") || KEY_IS("sec_flags")) {
2096 struct lov_tgt_desc *tgt;
2097 struct obd_export *exp;
2100 spin_lock(&lov->lov_lock);
2101 for (i = 0, tgt = lov->tgts; i < lov->desc.ld_tgt_count;
2104 /* during setup time the connections to osc might
2105 * haven't been established.
2108 struct obd_device *tgt_obd;
2110 tgt_obd = class_find_client_obd(&tgt->uuid,
2114 CERROR("can't set security flavor, "
2115 "device %s not attached?\n",
2120 exp = tgt_obd->obd_self_export;
2123 err = obd_set_info(exp, keylen, key, vallen, val);
2127 spin_unlock(&lov->lov_lock);
2130 } else if (KEY_IS("flush_cred")) {
2131 struct lov_tgt_desc *tgt;
2134 for (i = 0, tgt = lov->tgts; i < lov->desc.ld_tgt_count;
2138 rc = obd_set_info(tgt->ltd_exp,
2139 keylen, key, vallen, val);
2149 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2150 if (val && !obd_uuid_equals(val, &lov->tgts[i].uuid))
2153 if (!val && !lov->tgts[i].active)
2156 err = obd_set_info(lov->tgts[i].ltd_exp,
2157 keylen, key, vallen, val);
2166 struct lov_multi_wait {
2167 struct ldlm_lock *lock;
2173 int lov_complete_many(struct obd_export *exp, struct lov_stripe_md *lsm,
2174 struct lustre_handle *lockh)
2176 struct lov_lock_handles *lov_lockh = NULL;
2177 struct lustre_handle *lov_lockhp;
2178 struct lov_obd *lov;
2179 struct lov_oinfo *loi;
2180 struct lov_multi_wait *queues;
2184 if (lsm_bad_magic(lsm))
2187 if (!exp || !exp->exp_obd)
2190 LASSERT(lockh != NULL);
2191 if (lsm->lsm_stripe_count > 1) {
2192 lov_lockh = lov_handle2llh(lockh);
2193 if (lov_lockh == NULL) {
2194 CERROR("LOV: invalid lov lock handle %p\n", lockh);
2198 lov_lockhp = lov_lockh->llh_handles;
2203 OBD_ALLOC(queues, lsm->lsm_stripe_count * sizeof(*queues));
2205 GOTO(out, rc = -ENOMEM);
2207 lov = &exp->exp_obd->u.lov;
2208 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
2209 i++, loi++, lov_lockhp++) {
2210 struct ldlm_lock *lock;
2211 struct obd_device *obd;
2212 unsigned long irqflags;
2214 lock = ldlm_handle2lock(lov_lockhp);
2216 CDEBUG(D_HA, "lov idx %d subobj "LPX64" no lock?\n",
2217 loi->loi_ost_idx, loi->loi_id);
2218 queues[i].completed = 1;
2222 queues[i].lock = lock;
2223 init_waitqueue_entry(&(queues[i].wait), current);
2224 add_wait_queue(lock->l_waitq, &(queues[i].wait));
2226 obd = class_exp2obd(lock->l_conn_export);
2228 imp = obd->u.cli.cl_import;
2230 spin_lock_irqsave(&imp->imp_lock, irqflags);
2231 queues[i].generation = imp->imp_generation;
2232 spin_unlock_irqrestore(&imp->imp_lock, irqflags);
2236 lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, ldlm_expired_completion_wait,
2237 interrupted_completion_wait, &lwd);
2238 rc = l_wait_event_added(check_multi_complete(queues, lsm), &lwi);
2240 for (i = 0; i < lsm->lsm_stripe_count; i++)
2241 remove_wait_queue(lock->l_waitq, &(queues[i].wait));
2243 if (rc == -EINTR || rc == -ETIMEDOUT) {
2249 if (lov_lockh != NULL)
2250 lov_llh_put(lov_lockh);
2255 struct obd_ops lov_obd_ops = {
2256 .o_owner = THIS_MODULE,
2257 .o_attach = lov_attach,
2258 .o_detach = lov_detach,
2259 .o_setup = lov_setup,
2260 .o_cleanup = lov_cleanup,
2261 .o_process_config = lov_process_config,
2262 .o_connect = lov_connect,
2263 .o_disconnect = lov_disconnect,
2264 .o_statfs = lov_statfs,
2265 .o_packmd = lov_packmd,
2266 .o_unpackmd = lov_unpackmd,
2267 .o_revalidate_md = lov_revalidate_md,
2268 .o_create = lov_create,
2269 .o_destroy = lov_destroy,
2270 .o_getattr = lov_getattr,
2271 .o_getattr_async = lov_getattr_async,
2272 .o_setattr = lov_setattr,
2274 .o_brw_async = lov_brw_async,
2275 .o_prep_async_page = lov_prep_async_page,
2276 .o_queue_async_io = lov_queue_async_io,
2277 .o_set_async_flags = lov_set_async_flags,
2278 .o_queue_group_io = lov_queue_group_io,
2279 .o_trigger_group_io = lov_trigger_group_io,
2280 .o_teardown_async_page = lov_teardown_async_page,
2281 .o_adjust_kms = lov_adjust_kms,
2282 .o_punch = lov_punch,
2284 .o_enqueue = lov_enqueue,
2285 .o_match = lov_match,
2286 .o_change_cbdata = lov_change_cbdata,
2287 .o_cancel = lov_cancel,
2288 .o_cancel_unused = lov_cancel_unused,
2289 .o_iocontrol = lov_iocontrol,
2290 .o_get_info = lov_get_info,
2291 .o_set_info = lov_set_info,
2292 .o_llog_init = lov_llog_init,
2293 .o_llog_finish = lov_llog_finish,
2294 .o_notify = lov_notify,
2297 int __init lov_init(void)
2299 struct lprocfs_static_vars lvars;
2303 lprocfs_init_vars(lov, &lvars);
2304 rc = class_register_type(&lov_obd_ops, NULL, lvars.module_vars,
2305 OBD_LOV_DEVICENAME);
2310 static void /*__exit*/ lov_exit(void)
2312 class_unregister_type(OBD_LOV_DEVICENAME);
2315 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2316 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver");
2317 MODULE_LICENSE("GPL");
2319 module_init(lov_init);
2320 module_exit(lov_exit);