1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002-2004 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/lustre_debug.h>
48 #include <linux/obd_class.h>
49 #include <linux/obd_lov.h>
50 #include <linux/obd_ost.h>
51 #include <linux/lprocfs_status.h>
53 #include "lov_internal.h"
56 #define MAX_STRING_SIZE 128
57 static int lov_connect_obd(struct obd_device *obd, struct lov_tgt_desc *tgt,
58 int activate, struct obd_connect_data *data)
60 struct lov_obd *lov = &obd->u.lov;
61 struct obd_uuid *tgt_uuid = &tgt->uuid;
62 struct obd_device *tgt_obd;
63 struct obd_uuid lov_osc_uuid = { "LOV_OSC_UUID" };
64 struct lustre_handle conn = {0, };
65 struct proc_dir_entry *lov_proc_dir;
69 tgt_obd = class_find_client_obd(tgt_uuid, LUSTRE_OSC_NAME,
73 CERROR("Target %s not attached\n", tgt_uuid->uuid);
77 if (!tgt_obd->obd_set_up) {
78 CERROR("Target %s not set up\n", tgt_uuid->uuid);
83 tgt_obd->obd_no_recov = 0;
84 ptlrpc_activate_import(tgt_obd->u.cli.cl_import);
87 if (tgt_obd->u.cli.cl_import->imp_invalid) {
88 CERROR("not connecting OSC %s; administratively "
89 "disabled\n", tgt_uuid->uuid);
90 rc = obd_register_observer(tgt_obd, obd);
92 CERROR("Target %s register_observer error %d; "
93 "will not be able to reactivate\n",
99 rc = obd_connect(&conn, tgt_obd, &lov_osc_uuid, data);
101 CERROR("Target %s connect error %d\n", tgt_uuid->uuid, rc);
104 tgt->ltd_exp = class_conn2export(&conn);
106 rc = obd_register_observer(tgt_obd, obd);
108 CERROR("Target %s register_observer error %d\n",
110 obd_disconnect(tgt->ltd_exp);
116 lov->desc.ld_active_tgt_count++;
118 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
120 struct obd_device *osc_obd = class_conn2obd(&conn);
121 struct proc_dir_entry *osc_symlink;
122 char name[MAX_STRING_SIZE];
124 LASSERT(osc_obd != NULL);
125 LASSERT(osc_obd->obd_type != NULL);
126 LASSERT(osc_obd->obd_type->typ_name != NULL);
127 snprintf(name, MAX_STRING_SIZE, "../../../%s/%s",
128 osc_obd->obd_type->typ_name,
130 osc_symlink = proc_symlink(osc_obd->obd_name, lov_proc_dir,
132 if (osc_symlink == NULL) {
133 CERROR("could not register LOV target "
134 "/proc/fs/lustre/%s/%s/target_obds/%s.",
135 obd->obd_type->typ_name, obd->obd_name,
137 lprocfs_remove(lov_proc_dir);
145 static int lov_connect(struct lustre_handle *conn, struct obd_device *obd,
146 struct obd_uuid *cluuid, struct obd_connect_data *data)
148 struct lov_obd *lov = &obd->u.lov;
149 struct lov_tgt_desc *tgt;
150 struct obd_export *exp;
154 rc = class_connect(conn, obd, cluuid);
158 exp = class_conn2export(conn);
160 /* We don't want to actually do the underlying connections more than
161 * once, so keep track. */
163 if (lov->refcount > 1) {
164 class_export_put(exp);
168 for (i = 0, tgt = lov->tgts; i < lov->desc.ld_tgt_count; i++, tgt++) {
169 if (obd_uuid_empty(&tgt->uuid))
171 rc = lov_connect_obd(obd, tgt, 0, data);
176 class_export_put(exp);
181 struct obd_uuid uuid;
183 --lov->desc.ld_active_tgt_count;
185 /* save for CERROR below; (we know it's terminated) */
187 rc2 = obd_disconnect(tgt->ltd_exp);
189 CERROR("error: LOV target %s disconnect on OST idx %d: "
190 "rc = %d\n", uuid.uuid, i, rc2);
192 class_disconnect(exp);
196 static int lov_disconnect_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
198 struct proc_dir_entry *lov_proc_dir;
199 struct obd_device *osc_obd = class_exp2obd(tgt->ltd_exp);
200 struct lov_obd *lov = &obd->u.lov;
204 CDEBUG(D_CONFIG, "Disconnecting lov target %s\n", obd->obd_uuid.uuid);
206 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
208 struct proc_dir_entry *osc_symlink;
210 osc_symlink = lprocfs_srch(lov_proc_dir, osc_obd->obd_name);
212 lprocfs_remove(osc_symlink);
214 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing.",
215 obd->obd_type->typ_name, obd->obd_name,
220 if (obd->obd_no_recov) {
221 /* Pass it on to our clients.
222 * XXX This should be an argument to disconnect,
223 * XXX not a back-door flag on the OBD. Ah well.
226 osc_obd->obd_no_recov = 1;
229 obd_register_observer(osc_obd, NULL);
231 rc = obd_disconnect(tgt->ltd_exp);
234 CERROR("Target %s disconnect error %d\n",
242 lov->desc.ld_active_tgt_count--;
249 static int lov_disconnect(struct obd_export *exp)
251 struct obd_device *obd = class_exp2obd(exp);
252 struct lov_obd *lov = &obd->u.lov;
253 struct lov_tgt_desc *tgt;
257 rc = class_disconnect(exp);
262 /* Only disconnect the underlying layers on the final disconnect. */
264 if (lov->refcount != 0)
267 for (i = 0, tgt = lov->tgts; i < lov->desc.ld_tgt_count; i++, tgt++) {
269 lov_disconnect_obd(obd, tgt);
277 * -EINVAL : UUID can't be found in the LOV's target list
278 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
279 * -EBADF : The UUID is found, but the OBD is the wrong type (!)
281 static int lov_set_osc_active(struct lov_obd *lov, struct obd_uuid *uuid,
284 struct lov_tgt_desc *tgt;
288 CDEBUG(D_INFO, "Searching in lov %p for uuid %s (activate=%d)\n",
289 lov, uuid->uuid, activate);
291 spin_lock(&lov->lov_lock);
292 for (i = 0, tgt = lov->tgts; i < lov->desc.ld_tgt_count; i++, tgt++) {
293 if (tgt->ltd_exp == NULL)
296 CDEBUG(D_INFO, "lov idx %d is %s conn "LPX64"\n",
297 i, tgt->uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
298 if (strncmp(uuid->uuid, tgt->uuid.uuid, sizeof uuid->uuid) == 0)
302 if (i == lov->desc.ld_tgt_count)
303 GOTO(out, rc = -EINVAL);
305 if (tgt->active == activate) {
306 CDEBUG(D_INFO, "OSC %s already %sactive!\n", uuid->uuid,
307 activate ? "" : "in");
311 CDEBUG(D_INFO, "Marking OSC %s %sactive\n", uuid->uuid,
312 activate ? "" : "in");
314 tgt->active = activate;
316 lov->desc.ld_active_tgt_count++;
318 lov->desc.ld_active_tgt_count--;
322 spin_unlock(&lov->lov_lock);
326 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
330 struct obd_uuid *uuid;
332 if (strcmp(watched->obd_type->typ_name, "osc")) {
333 CERROR("unexpected notification of %s %s!\n",
334 watched->obd_type->typ_name,
338 uuid = &watched->u.cli.cl_import->imp_target_uuid;
340 /* Set OSC as active before notifying the observer, so the
341 * observer can use the OSC normally.
343 rc = lov_set_osc_active(&obd->u.lov, uuid, active);
345 CERROR("%sactivation of %s failed: %d\n",
346 active ? "" : "de", uuid->uuid, rc);
350 if (obd->obd_observer)
351 /* Pass the notification up the chain. */
352 rc = obd_notify(obd->obd_observer, watched, active);
358 lov_add_obd(struct obd_device *obd, struct obd_uuid *uuidp, int index, int gen)
360 struct lov_obd *lov = &obd->u.lov;
361 struct lov_tgt_desc *tgt;
362 struct obd_export *exp_observer;
369 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d\n",
370 uuidp->uuid, index, gen);
373 CERROR("request to add OBD %s at invalid index: %d\n",
379 CERROR("request to add OBD %s with invalid generation: %d\n",
384 bufsize = sizeof(struct lov_tgt_desc) * (index + 1);
385 if (bufsize > lov->bufsize) {
386 OBD_ALLOC(tgt, bufsize);
388 CERROR("couldn't allocate %d bytes for new table.\n",
393 memset(tgt, 0, bufsize);
395 memcpy(tgt, lov->tgts, lov->bufsize);
396 OBD_FREE(lov->tgts, lov->bufsize);
400 lov->bufsize = bufsize;
401 CDEBUG(D_CONFIG, "tgts: %p bufsize: %d\n",
402 lov->tgts, lov->bufsize);
405 tgt = &lov->tgts[index];
406 if (!obd_uuid_empty(&tgt->uuid)) {
407 CERROR("OBD already assigned at LOV target index %d\n",
413 /* XXX - add a sanity check on the generation number. */
416 old_count = lov->desc.ld_tgt_count;
417 if (index >= lov->desc.ld_tgt_count)
418 lov->desc.ld_tgt_count = index + 1;
420 CDEBUG(D_CONFIG, "idx=%d ltd_gen=%d ld_tgt_count=%d\n",
421 index, tgt->ltd_gen, lov->desc.ld_tgt_count);
423 if (lov->refcount == 0)
424 /* lov_connect hasn't been called yet. So we'll do the
425 lov_connect_obd on this obd when that fn first runs. */
429 struct obd_device *osc_obd;
431 osc_obd = class_exp2obd(tgt->ltd_exp);
433 osc_obd->obd_no_recov = 0;
436 /* NULL may need to change when we use flags for osc's */
437 rc = lov_connect_obd(obd, tgt, 1, NULL);
438 if (rc || !obd->obd_observer)
441 /* tell the mds_lov about the new target */
442 obd_llog_finish(obd->obd_observer, old_count);
443 llog_cat_initialize(obd->obd_observer, lov->desc.ld_tgt_count);
446 rc = obd_get_info(tgt->ltd_exp, strlen("last_id"), "last_id", &size,
451 exp_observer = obd->obd_observer->obd_self_export;
452 rc = obd_set_info(exp_observer, strlen("next_id"),"next_id", 2, params);
456 rc = lov_notify(obd, tgt->ltd_exp->exp_obd, 1);
459 if (rc && tgt->ltd_exp != NULL)
460 lov_disconnect_obd(obd, tgt);
465 lov_del_obd(struct obd_device *obd, struct obd_uuid *uuidp, int index, int gen)
467 struct lov_obd *lov = &obd->u.lov;
468 struct lov_tgt_desc *tgt;
469 int count = lov->desc.ld_tgt_count;
473 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d\n",
474 uuidp->uuid, index, gen);
476 if (index >= count) {
477 CERROR("LOV target index %d >= number of LOV OBDs %d.\n",
482 tgt = &lov->tgts[index];
484 if (obd_uuid_empty(&tgt->uuid)) {
485 CERROR("LOV target at index %d is not setup.\n", index);
489 if (strncmp(uuidp->uuid, tgt->uuid.uuid, sizeof uuidp->uuid) != 0) {
490 CERROR("LOV target UUID %s at index %d doesn't match %s.\n",
491 tgt->uuid.uuid, index, uuidp->uuid);
496 lov_disconnect_obd(obd, tgt);
498 /* XXX - right now there is a dependency on ld_tgt_count being the
499 * maximum tgt index for computing the mds_max_easize. So we can't
502 /* lt_gen = 0 will mean it will not match the gen of any valid loi */
503 memset(tgt, 0, sizeof(*tgt));
505 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d exp: %p active: %d\n",
506 tgt->uuid.uuid, index, tgt->ltd_gen, tgt->ltd_exp, tgt->active);
511 static int lov_setup(struct obd_device *obd, obd_count len, void *buf)
513 struct lprocfs_static_vars lvars;
514 struct lustre_cfg *lcfg = buf;
515 struct lov_desc *desc;
516 struct lov_obd *lov = &obd->u.lov;
520 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
521 CERROR("LOV setup requires a descriptor\n");
525 desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
527 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
528 CERROR("descriptor size wrong: %d > %d\n",
529 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
533 if (desc->ld_magic != LOV_DESC_MAGIC) {
534 if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
535 CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n",
536 obd->obd_name, desc);
537 lustre_swab_lov_desc(desc);
539 CERROR("%s: Bad lov desc magic: %#x\n",
540 obd->obd_name, desc->ld_magic);
545 if (desc->ld_default_stripe_size < PTLRPC_MAX_BRW_SIZE) {
546 CWARN("Increasing default_stripe_size "LPU64" to %u\n",
547 desc->ld_default_stripe_size, PTLRPC_MAX_BRW_SIZE);
548 CWARN("Please update config and run --write-conf on MDS\n");
550 desc->ld_default_stripe_size = PTLRPC_MAX_BRW_SIZE;
551 } else if (desc->ld_default_stripe_size & (LOV_MIN_STRIPE_SIZE - 1)) {
552 CWARN("default_stripe_size "LPU64" isn't a multiple of %u\n",
553 desc->ld_default_stripe_size, LOV_MIN_STRIPE_SIZE);
554 CWARN("Please update config and run --write-conf on MDS\n");
556 desc->ld_default_stripe_size &= ~(LOV_MIN_STRIPE_SIZE - 1);
559 /* Because of 64-bit divide/mod operations only work with a 32-bit
560 * divisor in a 32-bit kernel, we cannot support a stripe width
561 * of 4GB or larger on 32-bit CPUs. */
562 count = desc->ld_default_stripe_count;
563 if ((count ? count : desc->ld_tgt_count) *
564 desc->ld_default_stripe_size > ~0UL) {
565 CERROR("LOV: stripe width "LPU64"x%u > %lu on 32-bit system\n",
566 desc->ld_default_stripe_size, count, ~0UL);
570 /* Allocate space for target list */
571 if (desc->ld_tgt_count)
572 count = desc->ld_tgt_count;
573 lov->bufsize = sizeof(struct lov_tgt_desc) * count;
574 OBD_ALLOC(lov->tgts, lov->bufsize);
575 if (lov->tgts == NULL) {
576 CERROR("Out of memory\n");
579 memset(lov->tgts, 0, lov->bufsize);
581 desc->ld_active_tgt_count = 0;
583 spin_lock_init(&lov->lov_lock);
585 lprocfs_init_vars(lov, &lvars);
586 lprocfs_obd_setup(obd, lvars.obd_vars);
589 struct proc_dir_entry *entry;
591 entry = create_proc_entry("target_obd", 0444,
592 obd->obd_proc_entry);
594 entry->proc_fops = &lov_proc_target_fops;
603 static int lov_precleanup(struct obd_device *obd, int stage)
611 rc = obd_llog_finish(obd, 0);
613 CERROR("failed to cleanup llogging subsystems\n");
618 static int lov_cleanup(struct obd_device *obd)
620 struct lov_obd *lov = &obd->u.lov;
622 lprocfs_obd_cleanup(obd);
625 struct lov_tgt_desc *tgt;
626 for (i = 0, tgt = lov->tgts;
627 i < lov->desc.ld_tgt_count; i++, tgt++) {
628 if (!obd_uuid_empty(&tgt->uuid))
629 lov_del_obd(obd, &tgt->uuid, i, 0);
631 OBD_FREE(lov->tgts, lov->bufsize);
636 static int lov_process_config(struct obd_device *obd, obd_count len, void *buf)
638 struct lustre_cfg *lcfg = buf;
639 struct obd_uuid obd_uuid;
646 switch(cmd = lcfg->lcfg_command) {
647 case LCFG_LOV_ADD_OBD:
648 case LCFG_LOV_DEL_OBD: {
649 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
650 GOTO(out, rc = -EINVAL);
652 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
654 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
655 GOTO(out, rc = -EINVAL);
656 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
657 GOTO(out, rc = -EINVAL);
658 if (cmd == LCFG_LOV_ADD_OBD)
659 rc = lov_add_obd(obd, &obd_uuid, index, gen);
661 rc = lov_del_obd(obd, &obd_uuid, index, gen);
665 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
666 GOTO(out, rc = -EINVAL);
675 #define log2(n) ffz(~(n))
678 static int lov_clear_orphans(struct obd_export *export, struct obdo *src_oa,
679 struct lov_stripe_md **ea,
680 struct obd_trans_info *oti)
684 struct obd_uuid *ost_uuid = NULL;
688 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
689 src_oa->o_flags == OBD_FL_DELORPHAN);
691 lov = &export->exp_obd->u.lov;
693 tmp_oa = obdo_alloc();
697 if (src_oa->o_valid & OBD_MD_FLINLINE) {
698 ost_uuid = (struct obd_uuid *)src_oa->o_inline;
699 CDEBUG(D_HA, "clearing orphans only for %s\n",
703 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
704 struct lov_stripe_md obj_md;
705 struct lov_stripe_md *obj_mdp = &obj_md;
708 /* if called for a specific target, we don't
709 care if it is not active. */
710 if (lov->tgts[i].active == 0 && ost_uuid == NULL) {
711 CDEBUG(D_HA, "lov idx %d inactive\n", i);
715 if (ost_uuid && !obd_uuid_equals(ost_uuid, &lov->tgts[i].uuid))
718 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
720 LASSERT(lov->tgts[i].ltd_exp);
721 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
722 err = obd_create(lov->tgts[i].ltd_exp, tmp_oa, &obj_mdp, oti);
724 /* This export will be disabled until it is recovered,
725 and then orphan recovery will be completed. */
726 CERROR("error in orphan recovery on OST idx %d/%d: "
727 "rc = %d\n", i, lov->desc.ld_tgt_count, err);
736 static int lov_recreate(struct obd_export *exp, struct obdo *src_oa,
737 struct lov_stripe_md **ea, struct obd_trans_info *oti)
739 struct lov_stripe_md *obj_mdp, *lsm;
740 struct lov_obd *lov = &exp->exp_obd->u.lov;
745 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
746 src_oa->o_flags & OBD_FL_RECREATE_OBJS);
748 OBD_ALLOC(obj_mdp, sizeof(*obj_mdp));
752 ost_idx = src_oa->o_nlink;
755 GOTO(out, rc = -EINVAL);
756 if (ost_idx >= lov->desc.ld_tgt_count)
757 GOTO(out, rc = -EINVAL);
759 for (i = 0; i < lsm->lsm_stripe_count; i++) {
760 if (lsm->lsm_oinfo[i].loi_ost_idx == ost_idx) {
761 if (lsm->lsm_oinfo[i].loi_id != src_oa->o_id)
762 GOTO(out, rc = -EINVAL);
766 if (i == lsm->lsm_stripe_count)
767 GOTO(out, rc = -EINVAL);
769 rc = obd_create(lov->tgts[ost_idx].ltd_exp, src_oa, &obj_mdp, oti);
771 OBD_FREE(obj_mdp, sizeof(*obj_mdp));
775 /* the LOV expects oa->o_id to be set to the LOV object id */
776 static int lov_create(struct obd_export *exp, struct obdo *src_oa,
777 struct lov_stripe_md **ea, struct obd_trans_info *oti)
780 struct lov_request_set *set = NULL;
781 struct list_head *pos;
789 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
790 src_oa->o_flags == OBD_FL_DELORPHAN) {
791 rc = lov_clear_orphans(exp, src_oa, ea, oti);
795 lov = &exp->exp_obd->u.lov;
796 if (!lov->desc.ld_active_tgt_count)
799 /* Recreate a specific object id at the given OST index */
800 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
801 (src_oa->o_flags & OBD_FL_RECREATE_OBJS)) {
802 rc = lov_recreate(exp, src_oa, ea, oti);
806 rc = lov_prep_create_set(exp, ea, src_oa, oti, &set);
810 list_for_each (pos, &set->set_list) {
811 struct lov_request *req =
812 list_entry(pos, struct lov_request, rq_link);
814 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
815 rc = obd_create(lov->tgts[req->rq_idx].ltd_exp,
816 req->rq_oa, &req->rq_md, oti);
817 lov_update_create_set(set, req, rc);
819 rc = lov_fini_create_set(set, ea);
823 #define ASSERT_LSM_MAGIC(lsmp) \
825 LASSERT((lsmp) != NULL); \
826 LASSERTF((lsmp)->lsm_magic == LOV_MAGIC, "%p->lsm_magic=%x\n", \
827 (lsmp), (lsmp)->lsm_magic); \
830 static int lov_destroy(struct obd_export *exp, struct obdo *oa,
831 struct lov_stripe_md *lsm, struct obd_trans_info *oti)
833 struct lov_request_set *set;
834 struct lov_request *req;
835 struct list_head *pos;
840 ASSERT_LSM_MAGIC(lsm);
842 if (!exp || !exp->exp_obd)
845 lov = &exp->exp_obd->u.lov;
846 rc = lov_prep_destroy_set(exp, oa, lsm, oti, &set);
850 list_for_each (pos, &set->set_list) {
852 req = list_entry(pos, struct lov_request, rq_link);
854 /* XXX update the cookie position */
855 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
856 rc = obd_destroy(lov->tgts[req->rq_idx].ltd_exp, req->rq_oa,
858 err = lov_update_common_set(set, req, rc);
860 CERROR("error: destroying objid "LPX64" subobj "
861 LPX64" on OST idx %d: rc = %d\n",
862 set->set_oa->o_id, req->rq_oa->o_id,
868 lov_fini_destroy_set(set);
872 static int lov_getattr(struct obd_export *exp, struct obdo *oa,
873 struct lov_stripe_md *lsm)
875 struct lov_request_set *set;
876 struct lov_request *req;
877 struct list_head *pos;
882 ASSERT_LSM_MAGIC(lsm);
884 if (!exp || !exp->exp_obd)
887 lov = &exp->exp_obd->u.lov;
889 rc = lov_prep_getattr_set(exp, oa, lsm, &set);
893 list_for_each (pos, &set->set_list) {
894 req = list_entry(pos, struct lov_request, rq_link);
896 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
897 "%u\n", oa->o_id, req->rq_stripe, req->rq_oa->o_id,
900 rc = obd_getattr(lov->tgts[req->rq_idx].ltd_exp,
902 err = lov_update_common_set(set, req, rc);
904 CERROR("error: getattr objid "LPX64" subobj "
905 LPX64" on OST idx %d: rc = %d\n",
906 set->set_oa->o_id, req->rq_oa->o_id,
912 rc = lov_fini_getattr_set(set);
918 static int lov_getattr_interpret(struct ptlrpc_request_set *rqset, void *data,
921 struct lov_request_set *lovset = (struct lov_request_set *)data;
924 /* don't do attribute merge if this aysnc op failed */
926 lovset->set_completes = 0;
927 lov_fini_getattr_set(lovset);
929 rc = lov_fini_getattr_set(lovset);
934 static int lov_getattr_async(struct obd_export *exp, struct obdo *oa,
935 struct lov_stripe_md *lsm,
936 struct ptlrpc_request_set *rqset)
938 struct lov_request_set *lovset;
940 struct list_head *pos;
941 struct lov_request *req;
945 ASSERT_LSM_MAGIC(lsm);
947 if (!exp || !exp->exp_obd)
950 lov = &exp->exp_obd->u.lov;
952 rc = lov_prep_getattr_set(exp, oa, lsm, &lovset);
956 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
957 lsm->lsm_object_id, lsm->lsm_stripe_count, lsm->lsm_stripe_size);
959 list_for_each (pos, &lovset->set_list) {
960 req = list_entry(pos, struct lov_request, rq_link);
962 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
963 "%u\n", oa->o_id, req->rq_stripe, req->rq_oa->o_id,
965 rc = obd_getattr_async(lov->tgts[req->rq_idx].ltd_exp,
966 req->rq_oa, NULL, rqset);
968 CERROR("error: getattr objid "LPX64" subobj "
969 LPX64" on OST idx %d: rc = %d\n",
970 lovset->set_oa->o_id, req->rq_oa->o_id,
974 lov_update_common_set(lovset, req, rc);
978 LASSERT (rqset->set_interpret == NULL);
979 rqset->set_interpret = lov_getattr_interpret;
980 rqset->set_arg = (void *)lovset;
984 lov_fini_getattr_set(lovset);
988 static int lov_setattr(struct obd_export *exp, struct obdo *src_oa,
989 struct lov_stripe_md *lsm, struct obd_trans_info *oti)
991 struct lov_request_set *set;
993 struct list_head *pos;
994 struct lov_request *req;
998 ASSERT_LSM_MAGIC(lsm);
1000 if (!exp || !exp->exp_obd)
1003 /* for now, we only expect time updates here */
1004 LASSERT(!(src_oa->o_valid & ~(OBD_MD_FLID|OBD_MD_FLTYPE | OBD_MD_FLMODE|
1005 OBD_MD_FLATIME | OBD_MD_FLMTIME |
1006 OBD_MD_FLCTIME | OBD_MD_FLFLAGS |
1008 lov = &exp->exp_obd->u.lov;
1009 rc = lov_prep_setattr_set(exp, src_oa, lsm, NULL, &set);
1013 list_for_each (pos, &set->set_list) {
1014 req = list_entry(pos, struct lov_request, rq_link);
1016 rc = obd_setattr(lov->tgts[req->rq_idx].ltd_exp, req->rq_oa,
1018 err = lov_update_setattr_set(set, req, rc);
1020 CERROR("error: setattr objid "LPX64" subobj "
1021 LPX64" on OST idx %d: rc = %d\n",
1022 set->set_oa->o_id, req->rq_oa->o_id,
1028 err = lov_fini_setattr_set(set);
1034 static int lov_setattr_async(struct obd_export *exp, struct obdo *src_oa,
1035 struct lov_stripe_md *lsm, struct obd_trans_info *oti)
1037 struct lov_obd *lov;
1038 struct lov_oinfo *loi = NULL;
1040 obd_id objid = src_oa->o_id;
1044 ASSERT_LSM_MAGIC(lsm);
1046 if (src_oa->o_valid & OBD_MD_FLCOOKIE)
1047 LASSERT(oti->oti_logcookies);
1049 if (!exp || !exp->exp_obd)
1052 /* support OBD_MD_FLUID, OBD_MD_FLGID and OBD_MD_FLCOOKIE now */
1053 LASSERT(!(src_oa->o_valid & ~(OBD_MD_FLID | OBD_MD_FLUID |
1054 OBD_MD_FLGID| OBD_MD_FLCOOKIE)));
1055 lov = &exp->exp_obd->u.lov;
1057 loi = lsm->lsm_oinfo;
1058 for (i = 0; i < lsm->lsm_stripe_count; i++, loi++) {
1059 if (lov->tgts[loi->loi_ost_idx].active == 0) {
1060 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1064 src_oa->o_id = loi->loi_id;
1065 /* do chown/chgrp on OST asynchronously */
1066 err = obd_setattr_async(lov->tgts[loi->loi_ost_idx].ltd_exp,
1069 CERROR("error: setattr objid "LPX64" subobj "
1070 LPX64" on OST idx %d: rc = %d\n",
1071 objid, src_oa->o_id, i, err);
1076 if (src_oa->o_valid & OBD_MD_FLCOOKIE)
1077 oti->oti_logcookies++;
1083 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
1084 * we can send this 'punch' to just the authoritative node and the nodes
1085 * that the punch will affect. */
1086 static int lov_punch(struct obd_export *exp, struct obdo *oa,
1087 struct lov_stripe_md *lsm,
1088 obd_off start, obd_off end, struct obd_trans_info *oti)
1090 struct lov_request_set *set;
1091 struct lov_obd *lov;
1092 struct list_head *pos;
1093 struct lov_request *req;
1094 int err = 0, rc = 0;
1097 ASSERT_LSM_MAGIC(lsm);
1099 if (!exp || !exp->exp_obd)
1102 lov = &exp->exp_obd->u.lov;
1103 rc = lov_prep_punch_set(exp, oa, lsm, start, end, oti, &set);
1107 list_for_each (pos, &set->set_list) {
1108 req = list_entry(pos, struct lov_request, rq_link);
1110 rc = obd_punch(lov->tgts[req->rq_idx].ltd_exp, req->rq_oa,
1111 NULL, req->rq_extent.start,
1112 req->rq_extent.end, NULL);
1113 err = lov_update_punch_set(set, req, rc);
1115 CERROR("error: punch objid "LPX64" subobj "LPX64
1116 " on OST idx %d: rc = %d\n", set->set_oa->o_id,
1117 req->rq_oa->o_id, req->rq_idx, rc);
1122 err = lov_fini_punch_set(set);
1128 static int lov_sync(struct obd_export *exp, struct obdo *oa,
1129 struct lov_stripe_md *lsm, obd_off start, obd_off end)
1131 struct lov_request_set *set;
1132 struct lov_obd *lov;
1133 struct list_head *pos;
1134 struct lov_request *req;
1135 int err = 0, rc = 0;
1138 ASSERT_LSM_MAGIC(lsm);
1143 lov = &exp->exp_obd->u.lov;
1144 rc = lov_prep_sync_set(exp, oa, lsm, start, end, &set);
1148 list_for_each (pos, &set->set_list) {
1149 req = list_entry(pos, struct lov_request, rq_link);
1151 rc = obd_sync(lov->tgts[req->rq_idx].ltd_exp, req->rq_oa,
1152 NULL, req->rq_extent.start, req->rq_extent.end);
1153 err = lov_update_common_set(set, req, rc);
1155 CERROR("error: fsync objid "LPX64" subobj "LPX64
1156 " on OST idx %d: rc = %d\n", set->set_oa->o_id,
1157 req->rq_oa->o_id, req->rq_idx, rc);
1162 err = lov_fini_sync_set(set);
1168 static int lov_brw_check(struct lov_obd *lov, struct obdo *oa,
1169 struct lov_stripe_md *lsm,
1170 obd_count oa_bufs, struct brw_page *pga)
1174 /* The caller just wants to know if there's a chance that this
1175 * I/O can succeed */
1176 for (i = 0; i < oa_bufs; i++) {
1177 int stripe = lov_stripe_number(lsm, pga[i].off);
1178 int ost = lsm->lsm_oinfo[stripe].loi_ost_idx;
1181 if (!lov_stripe_intersects(lsm, i, pga[i].off,
1182 pga[i].off + pga[i].count,
1186 if (lov->tgts[ost].active == 0) {
1187 CDEBUG(D_HA, "lov idx %d inactive\n", ost);
1190 rc = obd_brw(OBD_BRW_CHECK, lov->tgts[ost].ltd_exp, oa,
1191 NULL, 1, &pga[i], NULL);
1198 static int lov_brw(int cmd, struct obd_export *exp, struct obdo *src_oa,
1199 struct lov_stripe_md *lsm, obd_count oa_bufs,
1200 struct brw_page *pga, struct obd_trans_info *oti)
1202 struct lov_request_set *set;
1203 struct lov_request *req;
1204 struct list_head *pos;
1205 struct lov_obd *lov = &exp->exp_obd->u.lov;
1209 ASSERT_LSM_MAGIC(lsm);
1211 if (cmd == OBD_BRW_CHECK) {
1212 rc = lov_brw_check(lov, src_oa, lsm, oa_bufs, pga);
1216 rc = lov_prep_brw_set(exp, src_oa, lsm, oa_bufs, pga, oti, &set);
1220 list_for_each (pos, &set->set_list) {
1221 struct obd_export *sub_exp;
1222 struct brw_page *sub_pga;
1223 req = list_entry(pos, struct lov_request, rq_link);
1225 sub_exp = lov->tgts[req->rq_idx].ltd_exp;
1226 sub_pga = set->set_pga + req->rq_pgaidx;
1227 rc = obd_brw(cmd, sub_exp, req->rq_oa, req->rq_md,
1228 req->rq_oabufs, sub_pga, oti);
1231 lov_update_common_set(set, req, rc);
1234 err = lov_fini_brw_set(set);
1240 static int lov_brw_interpret(struct ptlrpc_request_set *reqset, void *data,
1243 struct lov_request_set *lovset = (struct lov_request_set *)data;
1247 lovset->set_completes = 0;
1248 lov_fini_brw_set(lovset);
1250 rc = lov_fini_brw_set(lovset);
1256 static int lov_brw_async(int cmd, struct obd_export *exp, struct obdo *oa,
1257 struct lov_stripe_md *lsm, obd_count oa_bufs,
1258 struct brw_page *pga, struct ptlrpc_request_set *set,
1259 struct obd_trans_info *oti)
1261 struct lov_request_set *lovset;
1262 struct lov_request *req;
1263 struct list_head *pos;
1264 struct lov_obd *lov = &exp->exp_obd->u.lov;
1268 ASSERT_LSM_MAGIC(lsm);
1270 if (cmd == OBD_BRW_CHECK) {
1271 rc = lov_brw_check(lov, oa, lsm, oa_bufs, pga);
1275 rc = lov_prep_brw_set(exp, oa, lsm, oa_bufs, pga, oti, &lovset);
1279 list_for_each (pos, &lovset->set_list) {
1280 struct obd_export *sub_exp;
1281 struct brw_page *sub_pga;
1282 req = list_entry(pos, struct lov_request, rq_link);
1284 sub_exp = lov->tgts[req->rq_idx].ltd_exp;
1285 sub_pga = lovset->set_pga + req->rq_pgaidx;
1286 rc = obd_brw_async(cmd, sub_exp, req->rq_oa, req->rq_md,
1287 req->rq_oabufs, sub_pga, set, oti);
1290 lov_update_common_set(lovset, req, rc);
1293 LASSERT(set->set_interpret == NULL);
1294 set->set_interpret = (set_interpreter_func)lov_brw_interpret;
1295 set->set_arg = (void *)lovset;
1299 lov_fini_brw_set(lovset);
1303 static int lov_ap_make_ready(void *data, int cmd)
1305 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1307 return lap->lap_caller_ops->ap_make_ready(lap->lap_caller_data, cmd);
1309 static int lov_ap_refresh_count(void *data, int cmd)
1311 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1313 return lap->lap_caller_ops->ap_refresh_count(lap->lap_caller_data,
1316 static void lov_ap_fill_obdo(void *data, int cmd, struct obdo *oa)
1318 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1320 lap->lap_caller_ops->ap_fill_obdo(lap->lap_caller_data, cmd, oa);
1321 /* XXX woah, shouldn't we be altering more here? size? */
1322 oa->o_id = lap->lap_loi_id;
1325 static void lov_ap_completion(void *data, int cmd, struct obdo *oa, int rc)
1327 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1329 /* in a raid1 regime this would down a count of many ios
1330 * in flight, onl calling the caller_ops completion when all
1331 * the raid1 ios are complete */
1332 lap->lap_caller_ops->ap_completion(lap->lap_caller_data, cmd, oa, rc);
1335 static void lov_ap_get_ucred(void *data, struct obd_ucred *ouc)
1337 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1339 lap->lap_caller_ops->ap_get_ucred(lap->lap_caller_data, ouc);
1342 static struct obd_async_page_ops lov_async_page_ops = {
1343 .ap_make_ready = lov_ap_make_ready,
1344 .ap_refresh_count = lov_ap_refresh_count,
1345 .ap_fill_obdo = lov_ap_fill_obdo,
1346 .ap_completion = lov_ap_completion,
1347 .ap_get_ucred = lov_ap_get_ucred,
1350 int lov_prep_async_page(struct obd_export *exp, struct lov_stripe_md *lsm,
1351 struct lov_oinfo *loi, struct page *page,
1352 obd_off offset, struct obd_async_page_ops *ops,
1353 void *data, void **res)
1355 struct lov_obd *lov = &exp->exp_obd->u.lov;
1356 struct lov_async_page *lap;
1361 return size_round(sizeof(*lap)) +
1362 obd_prep_async_page(lov->tgts[0].ltd_exp, NULL, NULL,
1363 NULL, 0, NULL, NULL, NULL);
1365 ASSERT_LSM_MAGIC(lsm);
1366 LASSERT(loi == NULL);
1369 lap->lap_magic = LAP_MAGIC;
1370 lap->lap_caller_ops = ops;
1371 lap->lap_caller_data = data;
1373 /* for now only raid 0 which passes through */
1374 lap->lap_stripe = lov_stripe_number(lsm, offset);
1375 lov_stripe_offset(lsm, offset, lap->lap_stripe, &lap->lap_sub_offset);
1376 loi = &lsm->lsm_oinfo[lap->lap_stripe];
1378 /* so the callback doesn't need the lsm */
1379 lap->lap_loi_id = loi->loi_id;
1381 lap->lap_sub_cookie = (void *)lap + size_round(sizeof(*lap));
1383 rc = obd_prep_async_page(lov->tgts[loi->loi_ost_idx].ltd_exp,
1384 lsm, loi, page, lap->lap_sub_offset,
1385 &lov_async_page_ops, lap,
1386 &lap->lap_sub_cookie);
1389 CDEBUG(D_CACHE, "lap %p page %p cookie %p off "LPU64"\n", lap, page,
1390 lap->lap_sub_cookie, offset);
1394 static int lov_queue_async_io(struct obd_export *exp,
1395 struct lov_stripe_md *lsm,
1396 struct lov_oinfo *loi, void *cookie,
1397 int cmd, obd_off off, int count,
1398 obd_flag brw_flags, obd_flag async_flags)
1400 struct lov_obd *lov = &exp->exp_obd->u.lov;
1401 struct lov_async_page *lap;
1404 LASSERT(loi == NULL);
1406 ASSERT_LSM_MAGIC(lsm);
1408 lap = LAP_FROM_COOKIE(cookie);
1410 loi = &lsm->lsm_oinfo[lap->lap_stripe];
1412 rc = obd_queue_async_io(lov->tgts[loi->loi_ost_idx].ltd_exp, lsm,
1413 loi, lap->lap_sub_cookie, cmd, off, count,
1414 brw_flags, async_flags);
1418 static int lov_set_async_flags(struct obd_export *exp,
1419 struct lov_stripe_md *lsm,
1420 struct lov_oinfo *loi, void *cookie,
1421 obd_flag async_flags)
1423 struct lov_obd *lov = &exp->exp_obd->u.lov;
1424 struct lov_async_page *lap;
1427 LASSERT(loi == NULL);
1429 ASSERT_LSM_MAGIC(lsm);
1431 lap = LAP_FROM_COOKIE(cookie);
1433 loi = &lsm->lsm_oinfo[lap->lap_stripe];
1435 rc = obd_set_async_flags(lov->tgts[loi->loi_ost_idx].ltd_exp,
1436 lsm, loi, lap->lap_sub_cookie, async_flags);
1440 static int lov_queue_group_io(struct obd_export *exp,
1441 struct lov_stripe_md *lsm,
1442 struct lov_oinfo *loi,
1443 struct obd_io_group *oig, void *cookie,
1444 int cmd, obd_off off, int count,
1445 obd_flag brw_flags, obd_flag async_flags)
1447 struct lov_obd *lov = &exp->exp_obd->u.lov;
1448 struct lov_async_page *lap;
1451 LASSERT(loi == NULL);
1453 ASSERT_LSM_MAGIC(lsm);
1455 lap = LAP_FROM_COOKIE(cookie);
1457 loi = &lsm->lsm_oinfo[lap->lap_stripe];
1459 rc = obd_queue_group_io(lov->tgts[loi->loi_ost_idx].ltd_exp, lsm, loi,
1460 oig, lap->lap_sub_cookie, cmd, off, count,
1461 brw_flags, async_flags);
1465 /* this isn't exactly optimal. we may have queued sync io in oscs on
1466 * all stripes, but we don't record that fact at queue time. so we
1467 * trigger sync io on all stripes. */
1468 static int lov_trigger_group_io(struct obd_export *exp,
1469 struct lov_stripe_md *lsm,
1470 struct lov_oinfo *loi,
1471 struct obd_io_group *oig)
1473 struct lov_obd *lov = &exp->exp_obd->u.lov;
1476 LASSERT(loi == NULL);
1478 ASSERT_LSM_MAGIC(lsm);
1480 loi = lsm->lsm_oinfo;
1481 for (i = 0; i < lsm->lsm_stripe_count; i++, loi++) {
1482 if (lov->tgts[loi->loi_ost_idx].active == 0) {
1483 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1487 err = obd_trigger_group_io(lov->tgts[loi->loi_ost_idx].ltd_exp,
1489 if (rc == 0 && err != 0)
1495 static int lov_teardown_async_page(struct obd_export *exp,
1496 struct lov_stripe_md *lsm,
1497 struct lov_oinfo *loi, void *cookie)
1499 struct lov_obd *lov = &exp->exp_obd->u.lov;
1500 struct lov_async_page *lap;
1503 LASSERT(loi == NULL);
1505 ASSERT_LSM_MAGIC(lsm);
1507 lap = LAP_FROM_COOKIE(cookie);
1509 loi = &lsm->lsm_oinfo[lap->lap_stripe];
1511 rc = obd_teardown_async_page(lov->tgts[loi->loi_ost_idx].ltd_exp,
1512 lsm, loi, lap->lap_sub_cookie);
1514 CERROR("unable to teardown sub cookie %p: %d\n",
1515 lap->lap_sub_cookie, rc);
1521 static int lov_enqueue(struct obd_export *exp, struct lov_stripe_md *lsm,
1522 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1523 int *flags, void *bl_cb, void *cp_cb, void *gl_cb,
1524 void *data,__u32 lvb_len, void *lvb_swabber,
1525 struct lustre_handle *lockh)
1527 struct lov_request_set *set;
1528 struct lov_request *req;
1529 struct list_head *pos;
1530 struct lustre_handle *lov_lockhp;
1531 struct lov_obd *lov;
1533 int save_flags = *flags;
1536 ASSERT_LSM_MAGIC(lsm);
1538 /* we should never be asked to replay a lock this way. */
1539 LASSERT((*flags & LDLM_FL_REPLAY) == 0);
1541 if (!exp || !exp->exp_obd)
1544 lov = &exp->exp_obd->u.lov;
1545 rc = lov_prep_enqueue_set(exp, lsm, policy, mode, lockh, &set);
1549 list_for_each (pos, &set->set_list) {
1550 ldlm_policy_data_t sub_policy;
1551 req = list_entry(pos, struct lov_request, rq_link);
1552 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
1553 LASSERT(lov_lockhp);
1555 *flags = save_flags;
1556 sub_policy.l_extent.start = req->rq_extent.start;
1557 sub_policy.l_extent.end = req->rq_extent.end;
1559 rc = obd_enqueue(lov->tgts[req->rq_idx].ltd_exp, req->rq_md,
1560 type, &sub_policy, mode, flags, bl_cb,
1561 cp_cb, gl_cb, data, lvb_len, lvb_swabber,
1563 rc = lov_update_enqueue_set(set, req, rc, save_flags);
1568 lov_fini_enqueue_set(set, mode);
1572 static int lov_match(struct obd_export *exp, struct lov_stripe_md *lsm,
1573 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1574 int *flags, void *data, struct lustre_handle *lockh)
1576 struct lov_request_set *set;
1577 struct lov_request *req;
1578 struct list_head *pos;
1579 struct lov_obd *lov = &exp->exp_obd->u.lov;
1580 struct lustre_handle *lov_lockhp;
1581 int lov_flags, rc = 0;
1584 ASSERT_LSM_MAGIC(lsm);
1586 if (!exp || !exp->exp_obd)
1589 lov = &exp->exp_obd->u.lov;
1590 rc = lov_prep_match_set(exp, lsm, policy, mode, lockh, &set);
1594 list_for_each (pos, &set->set_list) {
1595 ldlm_policy_data_t sub_policy;
1596 req = list_entry(pos, struct lov_request, rq_link);
1597 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
1598 LASSERT(lov_lockhp);
1600 sub_policy.l_extent.start = req->rq_extent.start;
1601 sub_policy.l_extent.end = req->rq_extent.end;
1604 rc = obd_match(lov->tgts[req->rq_idx].ltd_exp, req->rq_md,
1605 type, &sub_policy, mode, &lov_flags, data,
1607 rc = lov_update_match_set(set, req, rc);
1611 lov_fini_match_set(set, mode, *flags);
1615 static int lov_change_cbdata(struct obd_export *exp,
1616 struct lov_stripe_md *lsm, ldlm_iterator_t it,
1619 struct lov_obd *lov;
1620 struct lov_oinfo *loi;
1624 ASSERT_LSM_MAGIC(lsm);
1626 if (!exp || !exp->exp_obd)
1629 lov = &exp->exp_obd->u.lov;
1630 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
1631 struct lov_stripe_md submd;
1632 if (lov->tgts[loi->loi_ost_idx].active == 0) {
1633 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1637 submd.lsm_object_id = loi->loi_id;
1638 submd.lsm_stripe_count = 0;
1639 rc = obd_change_cbdata(lov->tgts[loi->loi_ost_idx].ltd_exp,
1645 static int lov_cancel(struct obd_export *exp, struct lov_stripe_md *lsm,
1646 __u32 mode, struct lustre_handle *lockh)
1648 struct lov_request_set *set;
1649 struct lov_request *req;
1650 struct list_head *pos;
1651 struct lov_obd *lov = &exp->exp_obd->u.lov;
1652 struct lustre_handle *lov_lockhp;
1653 int err = 0, rc = 0;
1656 ASSERT_LSM_MAGIC(lsm);
1658 if (!exp || !exp->exp_obd)
1662 lov = &exp->exp_obd->u.lov;
1663 rc = lov_prep_cancel_set(exp, lsm, mode, lockh, &set);
1667 list_for_each (pos, &set->set_list) {
1668 req = list_entry(pos, struct lov_request, rq_link);
1669 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
1671 rc = obd_cancel(lov->tgts[req->rq_idx].ltd_exp, req->rq_md,
1673 rc = lov_update_common_set(set, req, rc);
1675 CERROR("error: cancel objid "LPX64" subobj "
1676 LPX64" on OST idx %d: rc = %d\n",
1678 req->rq_md->lsm_object_id, req->rq_idx, rc);
1683 lov_fini_cancel_set(set);
1687 static int lov_cancel_unused(struct obd_export *exp,
1688 struct lov_stripe_md *lsm, int flags, void *opaque)
1690 struct lov_obd *lov;
1691 struct lov_oinfo *loi;
1695 lov = &exp->exp_obd->u.lov;
1697 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1699 if (!lov->tgts[i].ltd_exp)
1702 err = obd_cancel_unused(lov->tgts[i].ltd_exp, NULL,
1710 ASSERT_LSM_MAGIC(lsm);
1712 if (!exp || !exp->exp_obd)
1715 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
1716 struct lov_stripe_md submd;
1719 if (lov->tgts[loi->loi_ost_idx].active == 0)
1720 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1722 submd.lsm_object_id = loi->loi_id;
1723 submd.lsm_stripe_count = 0;
1724 err = obd_cancel_unused(lov->tgts[loi->loi_ost_idx].ltd_exp,
1725 &submd, flags, opaque);
1726 if (err && lov->tgts[loi->loi_ost_idx].active) {
1727 CERROR("error: cancel unused objid "LPX64" subobj "LPX64
1728 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
1729 loi->loi_id, loi->loi_ost_idx, err);
1737 static int lov_join_lru(struct obd_export *exp,
1738 struct lov_stripe_md *lsm, int join)
1740 struct lov_obd *lov;
1741 struct lov_oinfo *loi;
1745 ASSERT_LSM_MAGIC(lsm);
1746 if (!exp || !exp->exp_obd)
1749 lov = &exp->exp_obd->u.lov;
1750 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
1751 struct lov_stripe_md submd;
1754 if (lov->tgts[loi->loi_ost_idx].active == 0)
1755 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1757 submd.lsm_object_id = loi->loi_id;
1758 submd.lsm_stripe_count = 0;
1759 rc = obd_join_lru(lov->tgts[loi->loi_ost_idx].ltd_exp,
1762 CERROR("join lru failed. objid: "LPX64" subobj: "LPX64
1763 " ostidx: %d rc: %d\n", lsm->lsm_object_id,
1764 loi->loi_id, loi->loi_ost_idx, rc);
1773 #define LOV_U64_MAX ((__u64)~0ULL)
1774 #define LOV_SUM_MAX(tot, add) \
1776 if ((tot) + (add) < (tot)) \
1777 (tot) = LOV_U64_MAX; \
1782 static int lov_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1783 unsigned long max_age)
1785 struct lov_obd *lov = &obd->u.lov;
1786 struct obd_statfs lov_sfs;
1793 /* We only get block data from the OBD */
1794 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1796 if (!lov->tgts[i].active) {
1797 CDEBUG(D_HA, "lov idx %d inactive\n", i);
1801 err = obd_statfs(class_exp2obd(lov->tgts[i].ltd_exp), &lov_sfs,
1804 if (lov->tgts[i].active && !rc)
1810 memcpy(osfs, &lov_sfs, sizeof(lov_sfs));
1813 osfs->os_bfree += lov_sfs.os_bfree;
1814 osfs->os_bavail += lov_sfs.os_bavail;
1815 osfs->os_blocks += lov_sfs.os_blocks;
1816 /* XXX not sure about this one - depends on policy.
1817 * - could be minimum if we always stripe on all OBDs
1818 * (but that would be wrong for any other policy,
1819 * if one of the OBDs has no more objects left)
1820 * - could be sum if we stripe whole objects
1821 * - could be average, just to give a nice number
1823 * To give a "reasonable" (if not wholly accurate)
1824 * number, we divide the total number of free objects
1825 * by expected stripe count (watch out for overflow).
1827 LOV_SUM_MAX(osfs->os_files, lov_sfs.os_files);
1828 LOV_SUM_MAX(osfs->os_ffree, lov_sfs.os_ffree);
1833 __u32 expected_stripes = lov->desc.ld_default_stripe_count ?
1834 lov->desc.ld_default_stripe_count :
1835 lov->desc.ld_active_tgt_count;
1837 if (osfs->os_files != LOV_U64_MAX)
1838 do_div(osfs->os_files, expected_stripes);
1839 if (osfs->os_ffree != LOV_U64_MAX)
1840 do_div(osfs->os_ffree, expected_stripes);
1847 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1848 void *karg, void *uarg)
1850 struct obd_device *obddev = class_exp2obd(exp);
1851 struct lov_obd *lov = &obddev->u.lov;
1852 int i, rc, count = lov->desc.ld_tgt_count;
1853 struct obd_uuid *uuidp;
1857 case OBD_IOC_LOV_GET_CONFIG: {
1858 struct obd_ioctl_data *data = karg;
1859 struct lov_tgt_desc *tgtdesc;
1860 struct lov_desc *desc;
1866 if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
1869 data = (struct obd_ioctl_data *)buf;
1871 if (sizeof(*desc) > data->ioc_inllen1) {
1872 obd_ioctl_freedata(buf, len);
1876 if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
1877 obd_ioctl_freedata(buf, len);
1881 if (sizeof(__u32) * count > data->ioc_inllen3) {
1882 obd_ioctl_freedata(buf, len);
1886 desc = (struct lov_desc *)data->ioc_inlbuf1;
1887 memcpy(desc, &(lov->desc), sizeof(*desc));
1889 uuidp = (struct obd_uuid *)data->ioc_inlbuf2;
1890 genp = (__u32 *)data->ioc_inlbuf3;
1891 tgtdesc = lov->tgts;
1892 /* the uuid will be empty for deleted OSTs */
1893 for (i = 0; i < count; i++, uuidp++, genp++, tgtdesc++) {
1894 obd_str2uuid(uuidp, tgtdesc->uuid.uuid);
1895 *genp = tgtdesc->ltd_gen;
1898 rc = copy_to_user((void *)uarg, buf, len);
1901 obd_ioctl_freedata(buf, len);
1904 case LL_IOC_LOV_SETSTRIPE:
1905 rc = lov_setstripe(exp, karg, uarg);
1907 case LL_IOC_LOV_GETSTRIPE:
1908 rc = lov_getstripe(exp, karg, uarg);
1910 case LL_IOC_LOV_SETEA:
1911 rc = lov_setea(exp, karg, uarg);
1918 for (i = 0; i < count; i++) {
1921 /* OST was disconnected */
1922 if (!lov->tgts[i].ltd_exp)
1925 err = obd_iocontrol(cmd, lov->tgts[i].ltd_exp,
1928 if (lov->tgts[i].active) {
1929 CERROR("error: iocontrol OSC %s on OST "
1930 "idx %d cmd %x: err = %d\n",
1931 lov->tgts[i].uuid.uuid, i,
1947 static int lov_get_info(struct obd_export *exp, __u32 keylen,
1948 void *key, __u32 *vallen, void *val)
1950 struct obd_device *obddev = class_exp2obd(exp);
1951 struct lov_obd *lov = &obddev->u.lov;
1955 if (!vallen || !val)
1958 if (keylen > strlen("lock_to_stripe") &&
1959 strcmp(key, "lock_to_stripe") == 0) {
1962 struct ldlm_lock *lock;
1963 struct lov_stripe_md *lsm;
1965 struct lov_oinfo *loi;
1966 __u32 *stripe = val;
1968 if (*vallen < sizeof(*stripe))
1970 *vallen = sizeof(*stripe);
1972 /* XXX This is another one of those bits that will need to
1973 * change if we ever actually support nested LOVs. It uses
1974 * the lock's export to find out which stripe it is. */
1975 /* XXX - it's assumed all the locks for deleted OSTs have
1976 * been cancelled. Also, the export for deleted OSTs will
1977 * be NULL and won't match the lock's export. */
1978 for (i = 0, loi = data->lsm->lsm_oinfo;
1979 i < data->lsm->lsm_stripe_count;
1981 if (lov->tgts[loi->loi_ost_idx].ltd_exp ==
1982 data->lock->l_conn_export) {
1987 LDLM_ERROR(data->lock, "lock on inode without such object\n");
1988 dump_lsm(D_ERROR, data->lsm);
1990 } else if (keylen >= strlen("size_to_stripe") &&
1991 strcmp(key, "size_to_stripe") == 0) {
1995 struct lov_stripe_md *lsm;
1998 if (*vallen < sizeof(*data))
2001 data->size = lov_size_to_stripe(data->lsm, data->size,
2002 data->stripe_number);
2004 } else if (keylen >= strlen("last_id") && strcmp(key, "last_id") == 0) {
2006 int rc, size = sizeof(obd_id);
2007 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2008 if (!lov->tgts[i].active)
2010 rc = obd_get_info(lov->tgts[i].ltd_exp,
2011 keylen, key, &size, &(ids[i]));
2016 } else if (keylen >= strlen("lovdesc") && strcmp(key, "lovdesc") == 0) {
2017 struct lov_desc *desc_ret = val;
2018 *desc_ret = lov->desc;
2026 static int lov_set_info(struct obd_export *exp, obd_count keylen,
2027 void *key, obd_count vallen, void *val)
2029 struct obd_device *obddev = class_exp2obd(exp);
2030 struct lov_obd *lov = &obddev->u.lov;
2034 #define KEY_IS(str) \
2035 (keylen == strlen(str) && memcmp(key, str, keylen) == 0)
2037 if (KEY_IS("next_id")) {
2038 if (vallen != lov->desc.ld_tgt_count)
2040 vallen = sizeof(obd_id);
2043 if (KEY_IS("next_id") || KEY_IS("checksum")) {
2044 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2045 /* OST was disconnected */
2046 if (!lov->tgts[i].ltd_exp)
2049 /* hit all OSCs, even inactive ones */
2050 err = obd_set_info(lov->tgts[i].ltd_exp, keylen, key,
2051 vallen, ((obd_id*)val) + i);
2058 if (KEY_IS("mds_conn") || KEY_IS("unlinked")) {
2065 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2066 if (val && !obd_uuid_equals(val, &lov->tgts[i].uuid))
2069 /* OST was disconnected */
2070 if (!lov->tgts[i].ltd_exp)
2073 if (!val && !lov->tgts[i].active)
2076 err = obd_set_info(lov->tgts[i].ltd_exp,
2077 keylen, key, vallen, val);
2085 int lov_test_and_clear_async_rc(struct lov_stripe_md *lsm)
2087 struct lov_oinfo *loi;
2091 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
2093 if (loi->loi_ar.ar_rc && !rc)
2094 rc = loi->loi_ar.ar_rc;
2095 loi->loi_ar.ar_rc = 0;
2099 EXPORT_SYMBOL(lov_test_and_clear_async_rc);
2102 struct lov_multi_wait {
2103 struct ldlm_lock *lock;
2109 int lov_complete_many(struct obd_export *exp, struct lov_stripe_md *lsm,
2110 struct lustre_handle *lockh)
2112 struct lov_lock_handles *lov_lockh = NULL;
2113 struct lustre_handle *lov_lockhp;
2114 struct lov_obd *lov;
2115 struct lov_oinfo *loi;
2116 struct lov_multi_wait *queues;
2120 ASSERT_LSM_MAGIC(lsm);
2122 if (!exp || !exp->exp_obd)
2125 LASSERT(lockh != NULL);
2126 if (lsm->lsm_stripe_count > 1) {
2127 lov_lockh = lov_handle2llh(lockh);
2128 if (lov_lockh == NULL) {
2129 CERROR("LOV: invalid lov lock handle %p\n", lockh);
2133 lov_lockhp = lov_lockh->llh_handles;
2138 OBD_ALLOC(queues, lsm->lsm_stripe_count * sizeof(*queues));
2140 GOTO(out, rc = -ENOMEM);
2142 lov = &exp->exp_obd->u.lov;
2143 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
2144 i++, loi++, lov_lockhp++) {
2145 struct ldlm_lock *lock;
2146 struct obd_device *obd;
2147 unsigned long irqflags;
2149 lock = ldlm_handle2lock(lov_lockhp);
2151 CDEBUG(D_HA, "lov idx %d subobj "LPX64" no lock?\n",
2152 loi->loi_ost_idx, loi->loi_id);
2153 queues[i].completed = 1;
2157 queues[i].lock = lock;
2158 init_waitqueue_entry(&(queues[i].wait), current);
2159 add_wait_queue(lock->l_waitq, &(queues[i].wait));
2161 obd = class_exp2obd(lock->l_conn_export);
2163 imp = obd->u.cli.cl_import;
2165 spin_lock_irqsave(&imp->imp_lock, irqflags);
2166 queues[i].generation = imp->imp_generation;
2167 spin_unlock_irqrestore(&imp->imp_lock, irqflags);
2171 lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, ldlm_expired_completion_wait,
2172 interrupted_completion_wait, &lwd);
2173 rc = l_wait_event_added(check_multi_complete(queues, lsm), &lwi);
2175 for (i = 0; i < lsm->lsm_stripe_count; i++)
2176 remove_wait_queue(lock->l_waitq, &(queues[i].wait));
2178 if (rc == -EINTR || rc == -ETIMEDOUT) {
2184 if (lov_lockh != NULL)
2185 lov_llh_put(lov_lockh);
2190 static int lov_quotacheck(struct obd_export *exp, struct obd_quotactl *oqctl)
2192 struct obd_device *obd = class_exp2obd(exp);
2193 struct lov_obd *lov = &obd->u.lov;
2197 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2200 if (!lov->tgts[i].active) {
2201 CDEBUG(D_HA, "lov idx %d inactive\n", i);
2205 err = obd_quotacheck(lov->tgts[i].ltd_exp, oqctl);
2207 if (lov->tgts[i].active && !rc)
2216 static int lov_quotactl(struct obd_export *exp, struct obd_quotactl *oqctl)
2218 struct obd_device *obd = class_exp2obd(exp);
2219 struct lov_obd *lov = &obd->u.lov;
2220 __u64 curspace = oqctl->qc_dqblk.dqb_curspace;
2224 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2227 if (!lov->tgts[i].active) {
2228 CDEBUG(D_HA, "lov idx %d inactive\n", i);
2232 err = obd_quotactl(lov->tgts[i].ltd_exp, oqctl);
2234 if (lov->tgts[i].active && !rc)
2239 if (oqctl->qc_cmd == Q_GETQUOTA)
2240 curspace += oqctl->qc_dqblk.dqb_curspace;
2243 if (oqctl->qc_cmd == Q_GETQUOTA)
2244 oqctl->qc_dqblk.dqb_curspace = curspace;
2248 struct obd_ops lov_obd_ops = {
2249 .o_owner = THIS_MODULE,
2250 .o_setup = lov_setup,
2251 .o_precleanup = lov_precleanup,
2252 .o_cleanup = lov_cleanup,
2253 .o_process_config = lov_process_config,
2254 .o_connect = lov_connect,
2255 .o_disconnect = lov_disconnect,
2256 .o_statfs = lov_statfs,
2257 .o_packmd = lov_packmd,
2258 .o_unpackmd = lov_unpackmd,
2259 .o_create = lov_create,
2260 .o_destroy = lov_destroy,
2261 .o_getattr = lov_getattr,
2262 .o_getattr_async = lov_getattr_async,
2263 .o_setattr = lov_setattr,
2264 .o_setattr_async = lov_setattr_async,
2266 .o_brw_async = lov_brw_async,
2267 .o_prep_async_page = lov_prep_async_page,
2268 .o_queue_async_io = lov_queue_async_io,
2269 .o_set_async_flags = lov_set_async_flags,
2270 .o_queue_group_io = lov_queue_group_io,
2271 .o_trigger_group_io = lov_trigger_group_io,
2272 .o_teardown_async_page = lov_teardown_async_page,
2273 .o_adjust_kms = lov_adjust_kms,
2274 .o_punch = lov_punch,
2276 .o_enqueue = lov_enqueue,
2277 .o_match = lov_match,
2278 .o_change_cbdata = lov_change_cbdata,
2279 .o_cancel = lov_cancel,
2280 .o_cancel_unused = lov_cancel_unused,
2281 .o_join_lru = lov_join_lru,
2282 .o_iocontrol = lov_iocontrol,
2283 .o_get_info = lov_get_info,
2284 .o_set_info = lov_set_info,
2285 .o_llog_init = lov_llog_init,
2286 .o_llog_finish = lov_llog_finish,
2287 .o_notify = lov_notify,
2288 .o_quotacheck = lov_quotacheck,
2289 .o_quotactl = lov_quotactl,
2292 int __init lov_init(void)
2294 struct lprocfs_static_vars lvars;
2298 lprocfs_init_vars(lov, &lvars);
2299 rc = class_register_type(&lov_obd_ops, lvars.module_vars,
2300 OBD_LOV_DEVICENAME);
2305 static void /*__exit*/ lov_exit(void)
2307 class_unregister_type(OBD_LOV_DEVICENAME);
2310 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2311 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver");
2312 MODULE_LICENSE("GPL");
2314 module_init(lov_init);
2315 module_exit(lov_exit);