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"
54 static int lov_stripe_offset(struct lov_stripe_md *lsm, obd_off lov_off,
55 int stripeno, obd_off *obd_off);
57 struct lov_lock_handles {
58 struct portals_handle llh_handle;
59 atomic_t llh_refcount;
61 struct lustre_handle llh_handles[0];
64 static void lov_llh_addref(void *llhp)
66 struct lov_lock_handles *llh = llhp;
68 atomic_inc(&llh->llh_refcount);
69 CDEBUG(D_INFO, "GETting llh %p : new refcount %d\n", llh,
70 atomic_read(&llh->llh_refcount));
73 static struct lov_lock_handles *lov_llh_new(struct lov_stripe_md *lsm)
75 struct lov_lock_handles *llh;
77 OBD_ALLOC(llh, sizeof *llh +
78 sizeof(*llh->llh_handles) * lsm->lsm_stripe_count);
80 CERROR("out of memory\n");
83 atomic_set(&llh->llh_refcount, 2);
84 llh->llh_stripe_count = lsm->lsm_stripe_count;
85 INIT_LIST_HEAD(&llh->llh_handle.h_link);
86 class_handle_hash(&llh->llh_handle, lov_llh_addref);
90 static struct lov_lock_handles *lov_handle2llh(struct lustre_handle *handle)
93 LASSERT(handle != NULL);
94 RETURN(class_handle2object(handle->cookie));
97 static void lov_llh_put(struct lov_lock_handles *llh)
99 CDEBUG(D_INFO, "PUTting llh %p : new refcount %d\n", llh,
100 atomic_read(&llh->llh_refcount) - 1);
101 LASSERT(atomic_read(&llh->llh_refcount) > 0 &&
102 atomic_read(&llh->llh_refcount) < 0x5a5a);
103 if (atomic_dec_and_test(&llh->llh_refcount)) {
104 LASSERT(list_empty(&llh->llh_handle.h_link));
105 OBD_FREE(llh, sizeof *llh +
106 sizeof(*llh->llh_handles) * llh->llh_stripe_count);
110 static void lov_llh_destroy(struct lov_lock_handles *llh)
112 class_handle_unhash(&llh->llh_handle);
117 #define MAX_STRING_SIZE 128
118 static int lov_connect_obd(struct obd_device *obd, struct lov_tgt_desc *tgt,
119 int activate, unsigned long connect_flags)
121 struct obd_uuid lov_osc_uuid = { "LOV_OSC_UUID" };
122 struct obd_uuid *tgt_uuid = &tgt->uuid;
125 struct proc_dir_entry *lov_proc_dir;
127 struct lov_obd *lov = &obd->u.lov;
128 struct lustre_handle conn = {0, };
129 struct obd_device *tgt_obd;
133 tgt_obd = class_find_client_obd(tgt_uuid, LUSTRE_OSC_NAME,
137 CERROR("Target %s not attached\n", tgt_uuid->uuid);
141 if (!tgt_obd->obd_set_up) {
142 CERROR("Target %s not set up\n", tgt_uuid->uuid);
147 tgt_obd->obd_no_recov = 0;
148 ptlrpc_activate_import(tgt_obd->u.cli.cl_import);
151 if (tgt_obd->u.cli.cl_import->imp_invalid) {
152 CERROR("not connecting OSC %s; administratively "
153 "disabled\n", tgt_uuid->uuid);
154 rc = obd_register_observer(tgt_obd, obd);
156 CERROR("Target %s register_observer error %d; "
157 "will not be able to reactivate\n",
163 rc = obd_connect(&conn, tgt_obd, &lov_osc_uuid, connect_flags);
165 CERROR("Target %s connect error %d\n", tgt_uuid->uuid, rc);
168 tgt->ltd_exp = class_conn2export(&conn);
170 rc = obd_register_observer(tgt_obd, obd);
172 CERROR("Target %s register_observer error %d\n",
174 obd_disconnect(tgt->ltd_exp, 0);
180 lov->desc.ld_active_tgt_count++;
183 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
185 struct obd_device *osc_obd = class_conn2obd(&conn);
186 struct proc_dir_entry *osc_symlink;
187 char name[MAX_STRING_SIZE + 1];
189 LASSERT(osc_obd != NULL);
190 LASSERT(osc_obd->obd_type != NULL);
191 LASSERT(osc_obd->obd_type->typ_name != NULL);
192 name[MAX_STRING_SIZE] = '\0';
193 snprintf(name, MAX_STRING_SIZE, "../../../%s/%s",
194 osc_obd->obd_type->typ_name,
196 osc_symlink = proc_symlink(osc_obd->obd_name, lov_proc_dir,
198 if (osc_symlink == NULL) {
199 CERROR("could not register LOV target "
200 "/proc/fs/lustre/%s/%s/target_obds/%s\n",
201 obd->obd_type->typ_name, obd->obd_name,
203 lprocfs_remove(lov_proc_dir);
212 static int lov_connect(struct lustre_handle *conn, struct obd_device *obd,
213 struct obd_uuid *cluuid, unsigned long connect_flags)
216 struct proc_dir_entry *lov_proc_dir;
218 struct lov_obd *lov = &obd->u.lov;
219 struct lov_tgt_desc *tgt;
220 struct obd_export *exp;
224 rc = class_connect(conn, obd, cluuid);
228 exp = class_conn2export(conn);
230 /* We don't want to actually do the underlying connections more than
231 * once, so keep track. */
233 if (lov->refcount > 1) {
234 class_export_put(exp);
239 lov_proc_dir = lprocfs_register("target_obds", obd->obd_proc_entry,
241 if (IS_ERR(lov_proc_dir)) {
242 CERROR("could not register /proc/fs/lustre/%s/%s/target_obds.",
243 obd->obd_type->typ_name, obd->obd_name);
248 /* connect_flags is the MDS number, save for use in lov_add_obd */
249 lov->lov_connect_flags = connect_flags;
250 for (i = 0, tgt = lov->tgts; i < lov->desc.ld_tgt_count; i++, tgt++) {
251 if (obd_uuid_empty(&tgt->uuid))
253 rc = lov_connect_obd(obd, tgt, 0, connect_flags);
258 class_export_put(exp);
264 lprocfs_remove(lov_proc_dir);
268 struct obd_uuid uuid;
270 --lov->desc.ld_active_tgt_count;
272 /* save for CERROR below; (we know it's terminated) */
274 rc2 = obd_disconnect(tgt->ltd_exp, 0);
276 CERROR("error: LOV target %s disconnect on OST idx %d: "
277 "rc = %d\n", uuid.uuid, i, rc2);
279 class_disconnect(exp, 0);
283 static int lov_disconnect_obd(struct obd_device *obd, struct lov_tgt_desc *tgt,
287 struct proc_dir_entry *lov_proc_dir;
289 struct obd_device *osc_obd = class_exp2obd(tgt->ltd_exp);
290 struct lov_obd *lov = &obd->u.lov;
295 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
297 struct proc_dir_entry *osc_symlink;
299 osc_symlink = lprocfs_srch(lov_proc_dir, osc_obd->obd_name);
301 lprocfs_remove(osc_symlink);
303 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing\n",
304 obd->obd_type->typ_name, obd->obd_name,
310 if (obd->obd_no_recov) {
311 /* Pass it on to our clients.
312 * XXX This should be an argument to disconnect,
313 * XXX not a back-door flag on the OBD. Ah well.
316 osc_obd->obd_no_recov = 1;
319 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
320 rc = obd_disconnect(tgt->ltd_exp, flags);
323 CERROR("Target %s disconnect error %d\n",
331 lov->desc.ld_active_tgt_count--;
338 static int lov_disconnect(struct obd_export *exp, int flags)
340 struct obd_device *obd = class_exp2obd(exp);
342 struct proc_dir_entry *lov_proc_dir;
344 struct lov_obd *lov = &obd->u.lov;
345 struct lov_tgt_desc *tgt;
352 /* Only disconnect the underlying layers on the final disconnect. */
354 if (lov->refcount != 0)
357 for (i = 0, tgt = lov->tgts; i < lov->desc.ld_tgt_count; i++, tgt++) {
359 lov_disconnect_obd(obd, tgt, flags);
363 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
365 lprocfs_remove(lov_proc_dir);
367 CERROR("/proc/fs/lustre/%s/%s/target_obds missing.",
368 obd->obd_type->typ_name, obd->obd_name);
373 rc = class_disconnect(exp, 0);
379 * -EINVAL : UUID can't be found in the LOV's target list
380 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
381 * -EBADF : The UUID is found, but the OBD is the wrong type (!)
383 static int lov_set_osc_active(struct lov_obd *lov, struct obd_uuid *uuid,
386 struct lov_tgt_desc *tgt;
390 CDEBUG(D_INFO, "Searching in lov %p for uuid %s (activate=%d)\n",
391 lov, uuid->uuid, activate);
393 spin_lock(&lov->lov_lock);
394 for (i = 0, tgt = lov->tgts; i < lov->desc.ld_tgt_count; i++, tgt++) {
395 CDEBUG(D_INFO, "lov idx %d is %s conn "LPX64"\n",
396 i, tgt->uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
397 if (strncmp(uuid->uuid, tgt->uuid.uuid, sizeof uuid->uuid) == 0)
401 if (i == lov->desc.ld_tgt_count)
402 GOTO(out, rc = -EINVAL);
405 if (tgt->active == activate) {
406 CDEBUG(D_INFO, "OSC %s already %sactive!\n", uuid->uuid,
407 activate ? "" : "in");
411 CDEBUG(D_INFO, "Marking OSC %s %sactive\n", uuid->uuid,
412 activate ? "" : "in");
414 tgt->active = activate;
416 lov->desc.ld_active_tgt_count++;
418 lov->desc.ld_active_tgt_count--;
422 spin_unlock(&lov->lov_lock);
426 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
427 int active, void *data)
430 struct obd_uuid *uuid;
433 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
434 CERROR("unexpected notification of %s %s!\n",
435 watched->obd_type->typ_name,
439 uuid = &watched->u.cli.cl_import->imp_target_uuid;
441 /* Set OSC as active before notifying the observer, so the
442 * observer can use the OSC normally.
444 rc = lov_set_osc_active(&obd->u.lov, uuid, active);
446 CERROR("%sactivation of %s failed: %d\n",
447 active ? "" : "de", uuid->uuid, rc);
451 if (obd->obd_observer)
452 /* Pass the notification up the chain. */
453 rc = obd_notify(obd->obd_observer, watched, active, data);
458 int lov_attach(struct obd_device *dev, obd_count len, void *data)
460 struct lprocfs_static_vars lvars;
463 lprocfs_init_vars(lov, &lvars);
464 rc = lprocfs_obd_attach(dev, lvars.obd_vars);
467 struct proc_dir_entry *entry;
469 entry = create_proc_entry("target_obd_status", 0444,
470 dev->obd_proc_entry);
474 entry->proc_fops = &lov_proc_target_fops;
482 int lov_detach(struct obd_device *dev)
484 return lprocfs_obd_detach(dev);
487 static int lov_setup(struct obd_device *obd, obd_count len, void *buf)
489 struct lustre_cfg *lcfg = buf;
490 struct lov_desc *desc;
491 struct lov_obd *lov = &obd->u.lov;
495 if (lcfg->lcfg_inllen1 < 1) {
496 CERROR("LOV setup requires a descriptor\n");
500 desc = (struct lov_desc *)lcfg->lcfg_inlbuf1;
501 if (sizeof(*desc) > lcfg->lcfg_inllen1) {
502 CERROR("descriptor size wrong: %d > %d\n",
503 (int)sizeof(*desc), lcfg->lcfg_inllen1);
507 /* Because of 64-bit divide/mod operations only work with a 32-bit
508 * divisor in a 32-bit kernel, we cannot support a stripe width
509 * of 4GB or larger on 32-bit CPUs.
512 count = desc->ld_default_stripe_count;
513 if (count && (count * desc->ld_default_stripe_size) > ~0UL) {
514 CERROR("LOV: stripe width "LPU64"x%u > %lu on 32-bit system\n",
515 desc->ld_default_stripe_size, count, ~0UL);
518 if (desc->ld_tgt_count > 0) {
519 lov->bufsize= sizeof(struct lov_tgt_desc) * desc->ld_tgt_count;
521 lov->bufsize = sizeof(struct lov_tgt_desc) * LOV_MAX_TGT_COUNT;
523 OBD_ALLOC(lov->tgts, lov->bufsize);
524 if (lov->tgts == NULL) {
526 CERROR("couldn't allocate %d bytes for target table.\n",
531 desc->ld_tgt_count = 0;
532 desc->ld_active_tgt_count = 0;
534 spin_lock_init(&lov->lov_lock);
535 sema_init(&lov->lov_llog_sem, 1);
540 static int lov_cleanup(struct obd_device *obd, int flags)
542 struct lov_obd *lov = &obd->u.lov;
544 OBD_FREE(lov->tgts, lov->bufsize);
549 lov_add_obd(struct obd_device *obd, struct obd_uuid *uuidp, int index, int gen)
551 struct lov_obd *lov = &obd->u.lov;
552 struct lov_tgt_desc *tgt;
556 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d\n",
557 uuidp->uuid, index, gen);
559 if ((index < 0) || (index >= LOV_MAX_TGT_COUNT)) {
560 CERROR("request to add OBD %s at invalid index: %d\n",
566 CERROR("request to add OBD %s with invalid generation: %d\n",
571 tgt = lov->tgts + index;
572 if (!obd_uuid_empty(&tgt->uuid)) {
573 CERROR("OBD already assigned at LOV target index %d\n",
579 /* XXX - add a sanity check on the generation number. */
582 if (index >= lov->desc.ld_tgt_count)
583 lov->desc.ld_tgt_count = index + 1;
585 CDEBUG(D_CONFIG, "idx: %d ltd_gen: %d ld_tgt_count: %d\n",
586 index, tgt->ltd_gen, lov->desc.ld_tgt_count);
588 if (lov->refcount == 0)
592 struct obd_device *osc_obd;
594 osc_obd = class_exp2obd(tgt->ltd_exp);
596 osc_obd->obd_no_recov = 0;
599 rc = lov_connect_obd(obd, tgt, 1, lov->lov_connect_flags);
603 if (obd->obd_observer) {
604 /* tell the mds_lov about the new target */
605 rc = obd_notify(obd->obd_observer, tgt->ltd_exp->exp_obd, 1,
611 if (rc && tgt->ltd_exp != NULL)
612 lov_disconnect_obd(obd, tgt, 0);
617 lov_del_obd(struct obd_device *obd, struct obd_uuid *uuidp, int index, int gen)
619 struct lov_obd *lov = &obd->u.lov;
620 struct lov_tgt_desc *tgt;
621 int count = lov->desc.ld_tgt_count;
625 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d\n",
626 uuidp->uuid, index, gen);
628 if (index >= count) {
629 CERROR("LOV target index %d >= number of LOV OBDs %d.\n",
634 tgt = lov->tgts + index;
636 if (obd_uuid_empty(&tgt->uuid)) {
637 CERROR("LOV target at index %d is not setup.\n", index);
641 if (strncmp(uuidp->uuid, tgt->uuid.uuid, sizeof uuidp->uuid) != 0) {
642 CERROR("LOV target UUID %s at index %d doesn't match %s.\n",
643 tgt->uuid.uuid, index, uuidp->uuid);
648 struct obd_device *osc_obd;
650 osc_obd = class_exp2obd(tgt->ltd_exp);
652 osc_obd->obd_no_recov = 1;
653 rc = obd_llog_finish(osc_obd, &osc_obd->obd_llogs, 1);
655 CERROR("osc_llog_finish error: %d\n", rc);
657 lov_disconnect_obd(obd, tgt, 0);
660 /* XXX - right now there is a dependency on ld_tgt_count being the
661 * maximum tgt index for computing the mds_max_easize. So we can't
664 /* lt_gen = 0 will mean it will not match the gen of any valid loi */
665 memset(tgt, 0, sizeof(*tgt));
667 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d exp: %p active: %d\n",
668 tgt->uuid.uuid, index, tgt->ltd_gen, tgt->ltd_exp, tgt->active);
673 static int lov_process_config(struct obd_device *obd, obd_count len, void *buf)
675 struct lustre_cfg *lcfg = buf;
676 struct obd_uuid obd_uuid;
683 switch(cmd = lcfg->lcfg_command) {
684 case LCFG_LOV_ADD_OBD:
685 case LCFG_LOV_DEL_OBD: {
686 if (lcfg->lcfg_inllen1 > sizeof(obd_uuid.uuid))
687 GOTO(out, rc = -EINVAL);
689 obd_str2uuid(&obd_uuid, lcfg->lcfg_inlbuf1);
691 if (sscanf(lcfg->lcfg_inlbuf2, "%d", &index) != 1)
692 GOTO(out, rc = -EINVAL);
693 if (sscanf(lcfg->lcfg_inlbuf3, "%d", &gen) != 1)
694 GOTO(out, rc = -EINVAL);
695 if (cmd == LCFG_LOV_ADD_OBD)
696 rc = lov_add_obd(obd, &obd_uuid, index, gen);
698 rc = lov_del_obd(obd, &obd_uuid, index, gen);
702 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
703 GOTO(out, rc = -EINVAL);
711 /* compute object size given "stripeno" and the ost size */
712 static obd_size lov_stripe_size(struct lov_stripe_md *lsm, obd_size ost_size,
715 unsigned long ssize = lsm->lsm_stripe_size;
716 unsigned long swidth = ssize * lsm->lsm_stripe_count;
717 unsigned long stripe_size;
723 /* do_div(a, b) returns a % b, and a = a / b */
724 stripe_size = do_div(ost_size, ssize);
726 lov_size = ost_size * swidth + stripeno * ssize + stripe_size;
728 lov_size = (ost_size - 1) * swidth + (stripeno + 1) * ssize;
733 static void lov_merge_attrs(struct obdo *tgt, struct obdo *src, obd_flag valid,
734 struct lov_stripe_md *lsm, int stripeno, int *set)
736 valid &= src->o_valid;
739 if (valid & OBD_MD_FLSIZE) {
740 /* this handles sparse files properly */
743 lov_size = lov_stripe_size(lsm, src->o_size, stripeno);
744 if (lov_size > tgt->o_size)
745 tgt->o_size = lov_size;
747 if (valid & OBD_MD_FLBLOCKS)
748 tgt->o_blocks += src->o_blocks;
749 if (valid & OBD_MD_FLBLKSZ)
750 tgt->o_blksize += src->o_blksize;
751 if (valid & OBD_MD_FLCTIME && tgt->o_ctime < src->o_ctime)
752 tgt->o_ctime = src->o_ctime;
753 if (valid & OBD_MD_FLMTIME && tgt->o_mtime < src->o_mtime)
754 tgt->o_mtime = src->o_mtime;
756 memcpy(tgt, src, sizeof(*tgt));
757 tgt->o_id = lsm->lsm_object_id;
758 if (valid & OBD_MD_FLSIZE)
759 tgt->o_size = lov_stripe_size(lsm,src->o_size,stripeno);
765 #define log2(n) ffz(~(n))
768 static int lov_clear_orphans(struct obd_export *export, struct obdo *src_oa,
769 struct lov_stripe_md **ea,
770 struct obd_trans_info *oti)
774 struct obd_uuid *ost_uuid = NULL;
778 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
779 src_oa->o_flags == OBD_FL_DELORPHAN);
781 lov = &export->exp_obd->u.lov;
783 tmp_oa = obdo_alloc();
787 if (src_oa->o_valid & OBD_MD_FLINLINE) {
788 ost_uuid = (struct obd_uuid *)src_oa->o_inline;
789 CDEBUG(D_HA, "clearing orphans only for %s\n",
793 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
794 struct lov_stripe_md obj_md;
795 struct lov_stripe_md *obj_mdp = &obj_md;
798 /* if called for a specific target, we don't
799 care if it is not active. */
800 if (lov->tgts[i].active == 0 && ost_uuid == NULL) {
801 CDEBUG(D_HA, "lov idx %d inactive\n", i);
805 if (ost_uuid && !obd_uuid_equals(ost_uuid, &lov->tgts[i].uuid))
808 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
810 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
811 err = obd_create(lov->tgts[i].ltd_exp, tmp_oa, &obj_mdp, oti);
813 /* This export will be disabled until it is recovered,
814 and then orphan recovery will be completed. */
815 CERROR("error in orphan recovery on OST idx %d/%d: "
816 "rc = %d\n", i, lov->desc.ld_tgt_count, err);
825 #define LOV_CREATE_RESEED_INTERVAL 1000
827 /* the LOV expects oa->o_id to be set to the LOV object id */
828 static int lov_create(struct obd_export *exp, struct obdo *src_oa,
829 struct lov_stripe_md **ea, struct obd_trans_info *oti)
831 static int ost_start_idx, ost_start_count;
833 struct lov_stripe_md *lsm;
834 struct lov_oinfo *loi = NULL;
835 struct obdo *tmp_oa, *ret_oa;
836 struct llog_cookie *cookies = NULL;
837 unsigned ost_count, ost_idx;
838 int set = 0, obj_alloc = 0, cookie_sent = 0, rc = 0, i;
843 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
844 src_oa->o_flags == OBD_FL_DELORPHAN) {
845 rc = lov_clear_orphans(exp, src_oa, ea, oti);
852 lov = &exp->exp_obd->u.lov;
854 if (!lov->desc.ld_active_tgt_count)
857 /* Recreate a specific object id at the given OST index */
858 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
859 (src_oa->o_flags & OBD_FL_RECREATE_OBJS)) {
860 struct lov_stripe_md obj_md;
861 struct lov_stripe_md *obj_mdp = &obj_md;
863 ost_idx = src_oa->o_nlink;
867 if (ost_idx >= lov->desc.ld_tgt_count)
869 for (i = 0; i < lsm->lsm_stripe_count; i++) {
870 if (lsm->lsm_oinfo[i].loi_ost_idx == ost_idx) {
871 if (lsm->lsm_oinfo[i].loi_id != src_oa->o_id ||
872 lsm->lsm_oinfo[i].loi_gr != src_oa->o_gr) {
878 if (i == lsm->lsm_stripe_count)
881 rc = obd_create(lov->tgts[ost_idx].ltd_exp, src_oa,
886 ret_oa = obdo_alloc();
890 tmp_oa = obdo_alloc();
892 GOTO(out_oa, rc = -ENOMEM);
897 ost_count = lov_get_stripecnt(lov, 0);
899 /* If the MDS file was truncated up to some size, stripe over
900 * enough OSTs to allow the file to be created at that size. */
901 if (src_oa->o_valid & OBD_MD_FLSIZE) {
902 stripes=((src_oa->o_size+LUSTRE_STRIPE_MAXBYTES)>>12)-1;
903 do_div(stripes, (__u32)(LUSTRE_STRIPE_MAXBYTES >> 12));
905 if (stripes > lov->desc.ld_active_tgt_count)
907 if (stripes < ost_count)
913 rc = lov_alloc_memmd(&lsm, stripes, lov->desc.ld_pattern ?
914 lov->desc.ld_pattern : LOV_PATTERN_RAID0);
921 ost_count = lov->desc.ld_tgt_count;
923 LASSERT(src_oa->o_gr > 0);
924 LASSERT(src_oa->o_valid & OBD_MD_FLID);
925 lsm->lsm_object_id = src_oa->o_id;
926 lsm->lsm_object_gr = src_oa->o_gr;
927 if (!lsm->lsm_stripe_size)
928 lsm->lsm_stripe_size = lov->desc.ld_default_stripe_size;
929 if (!lsm->lsm_pattern) {
930 lsm->lsm_pattern = lov->desc.ld_pattern ?
931 lov->desc.ld_pattern : LOV_PATTERN_RAID0;
934 if (*ea == NULL || lsm->lsm_oinfo[0].loi_ost_idx >= ost_count) {
935 if (--ost_start_count <= 0) {
936 ost_start_idx = ll_insecure_random_int();
937 ost_start_count = LOV_CREATE_RESEED_INTERVAL;
938 } else if (lsm->lsm_stripe_count >=
939 lov->desc.ld_active_tgt_count) {
940 /* If we allocate from all of the stripes, make the
941 * next file start on the next OST. */
944 ost_idx = ost_start_idx % ost_count;
946 ost_idx = lsm->lsm_oinfo[0].loi_ost_idx;
949 CDEBUG(D_INODE, "allocating %d subobjs for objid "LPX64" at idx %d\n",
950 lsm->lsm_stripe_count, lsm->lsm_object_id, ost_idx);
952 /* XXX LOV STACKING: need to figure out how many real OSCs */
953 if (oti && (src_oa->o_valid & OBD_MD_FLCOOKIE)) {
954 oti_alloc_cookies(oti, lsm->lsm_stripe_count);
955 if (!oti->oti_logcookies)
956 GOTO(out_cleanup, rc = -ENOMEM);
957 cookies = oti->oti_logcookies;
960 loi = lsm->lsm_oinfo;
961 for (i = 0; i < ost_count; i++, ost_idx = (ost_idx + 1) % ost_count) {
962 struct lov_stripe_md obj_md;
963 struct lov_stripe_md *obj_mdp = &obj_md;
967 if (lov->tgts[ost_idx].active == 0) {
968 if (!obd_uuid_empty(&lov->tgts[ost_idx].uuid))
969 CDEBUG(D_HA, "lov idx %d inactive\n", ost_idx);
973 /* create data objects with "parent" OA */
974 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
976 /* XXX When we start creating objects on demand, we need to
977 * make sure that we always create the object on the
978 * stripe which holds the existing file size.
980 if (src_oa->o_valid & OBD_MD_FLSIZE) {
981 if (lov_stripe_offset(lsm, src_oa->o_size, i,
982 &tmp_oa->o_size) < 0 &&
986 CDEBUG(D_INODE, "stripe %d has size "LPU64"/"LPU64"\n",
987 i, tmp_oa->o_size, src_oa->o_size);
991 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
992 err = obd_create(lov->tgts[ost_idx].ltd_exp, tmp_oa, &obj_mdp,
995 if (lov->tgts[ost_idx].active) {
996 CERROR("error creating objid "LPX64" sub-object"
997 " on OST idx %d/%d: rc = %d\n",
998 src_oa->o_id, ost_idx,
999 lsm->lsm_stripe_count, err);
1001 CERROR("obd_create returned invalid "
1011 oti->oti_objid[ost_idx] = tmp_oa->o_id;
1012 loi->loi_id = tmp_oa->o_id;
1013 loi->loi_gr = tmp_oa->o_gr;
1014 loi->loi_ost_idx = ost_idx;
1015 loi->loi_ost_gen = lov->tgts[ost_idx].ltd_gen;
1016 CDEBUG(D_INODE, "objid "LPX64" has subobj "LPX64" at "
1017 "idx %d gen %d\n", lsm->lsm_object_id, loi->loi_id,
1018 ost_idx, loi->loi_ost_gen);
1020 lov_merge_attrs(ret_oa, tmp_oa, tmp_oa->o_valid, lsm,
1025 ++oti->oti_logcookies;
1026 if (tmp_oa->o_valid & OBD_MD_FLCOOKIE)
1031 /* If we have allocated enough objects, we are OK */
1032 if (obj_alloc == lsm->lsm_stripe_count)
1033 GOTO(out_done, rc = 0);
1036 if (obj_alloc == 0) {
1039 GOTO(out_cleanup, rc);
1042 /* If we were passed specific striping params, then a failure to
1043 * meet those requirements is an error, since we can't reallocate
1044 * that memory (it might be part of a larger array or something).
1046 * We can only get here if lsm_stripe_count was originally > 1.
1049 CERROR("can't lstripe objid "LPX64": have %u want %u, rc %d\n",
1050 lsm->lsm_object_id, obj_alloc, lsm->lsm_stripe_count,rc);
1053 GOTO(out_cleanup, rc);
1055 struct lov_stripe_md *lsm_new;
1056 /* XXX LOV STACKING call into osc for sizes */
1057 unsigned oldsize, newsize;
1059 if (oti && cookies && cookie_sent) {
1060 oldsize = lsm->lsm_stripe_count * sizeof(*cookies);
1061 newsize = obj_alloc * sizeof(*cookies);
1063 oti_alloc_cookies(oti, obj_alloc);
1064 if (oti->oti_logcookies) {
1065 memcpy(oti->oti_logcookies, cookies, newsize);
1066 OBD_FREE(cookies, oldsize);
1067 cookies = oti->oti_logcookies;
1069 CWARN("'leaking' %d bytes\n", oldsize-newsize);
1073 CWARN("using fewer stripes for object "LPX64": old %u new %u\n",
1074 lsm->lsm_object_id, lsm->lsm_stripe_count, obj_alloc);
1075 oldsize = lov_stripe_md_size(lsm->lsm_stripe_count);
1076 newsize = lov_stripe_md_size(obj_alloc);
1077 OBD_ALLOC(lsm_new, newsize);
1078 if (lsm_new != NULL) {
1079 memcpy(lsm_new, lsm, newsize);
1080 lsm_new->lsm_stripe_count = obj_alloc;
1081 OBD_FREE(lsm, oldsize);
1084 CWARN("'leaking' %d bytes\n", oldsize - newsize);
1091 if (src_oa->o_valid & OBD_MD_FLSIZE &&
1092 ret_oa->o_size != src_oa->o_size) {
1093 CERROR("original size "LPU64" isn't new object size "LPU64"\n",
1094 src_oa->o_size, ret_oa->o_size);
1097 ret_oa->o_id = src_oa->o_id;
1098 ret_oa->o_gr = src_oa->o_gr;
1099 ret_oa->o_valid |= OBD_MD_FLGROUP;
1100 memcpy(src_oa, ret_oa, sizeof(*src_oa));
1106 if (oti && cookies) {
1107 oti->oti_logcookies = cookies;
1109 oti_free_cookies(oti);
1110 src_oa->o_valid &= ~OBD_MD_FLCOOKIE;
1112 src_oa->o_valid |= OBD_MD_FLCOOKIE;
1118 while (obj_alloc-- > 0) {
1119 struct obd_export *sub_exp;
1123 sub_exp = lov->tgts[loi->loi_ost_idx].ltd_exp;
1124 /* destroy already created objects here */
1125 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
1126 tmp_oa->o_id = loi->loi_id;
1128 err = obd_destroy(sub_exp, tmp_oa, NULL, oti);
1130 CERROR("Failed to uncreate objid "LPX64" subobj "LPX64
1131 " on OST idx %d: rc = %d\n", src_oa->o_id,
1132 loi->loi_id, loi->loi_ost_idx, err);
1135 obd_free_memmd(exp, &lsm);
1139 static int lov_revalidate_policy(struct lov_obd *lov, struct lov_stripe_md *lsm)
1141 static int next_idx = 0;
1142 struct lov_tgt_desc *tgt;
1145 /* XXX - we should do something clever and take lsm
1146 * into account but just do round robin for now. */
1148 /* last_idx must always be less that count because
1149 * ld_tgt_count currently cannot shrink. */
1150 count = lov->desc.ld_tgt_count;
1152 for (i = next_idx, tgt = lov->tgts + i; i < count; i++, tgt++) {
1154 next_idx = (i + 1) % count;
1159 for (i = 0, tgt = lov->tgts; i < next_idx; i++, tgt++) {
1161 next_idx = (i + 1) % count;
1169 #define lsm_bad_magic(LSMP) \
1171 struct lov_stripe_md *_lsm__ = (LSMP); \
1174 CERROR("LOV requires striping ea\n"); \
1176 } else if (_lsm__->lsm_magic != LOV_MAGIC) { \
1177 CERROR("LOV striping magic bad %#x != %#x\n", \
1178 _lsm__->lsm_magic, LOV_MAGIC); \
1184 static int lov_destroy(struct obd_export *exp, struct obdo *oa,
1185 struct lov_stripe_md *lsm, struct obd_trans_info *oti)
1188 struct lov_obd *lov;
1189 struct lov_oinfo *loi;
1193 if (lsm_bad_magic(lsm))
1196 if (!exp || !exp->exp_obd)
1199 lov = &exp->exp_obd->u.lov;
1200 loi = lsm->lsm_oinfo;
1201 for (i = 0; i < lsm->lsm_stripe_count; i++, loi++) {
1204 if (lov->tgts[loi->loi_ost_idx].active == 0) {
1205 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1206 /* Orphan clean up will (someday) fix this up. */
1207 if (oti != NULL && oa->o_valid & OBD_MD_FLCOOKIE)
1208 oti->oti_logcookies++;
1212 memcpy(&tmp, oa, sizeof(tmp));
1213 tmp.o_id = loi->loi_id;
1214 err = obd_destroy(lov->tgts[loi->loi_ost_idx].ltd_exp, &tmp,
1216 if (err && lov->tgts[loi->loi_ost_idx].active) {
1217 CDEBUG(D_INODE, "error: destroying objid "LPX64" subobj "
1218 LPX64" on OST idx %d: rc = %d\n",
1219 oa->o_id, loi->loi_id, loi->loi_ost_idx, err);
1227 static int lov_getattr(struct obd_export *exp, struct obdo *oa,
1228 struct lov_stripe_md *lsm)
1231 struct lov_obd *lov;
1232 struct lov_oinfo *loi;
1233 int i, rc = 0, set = 0;
1236 if (lsm_bad_magic(lsm))
1239 if (!exp || !exp->exp_obd)
1242 lov = &exp->exp_obd->u.lov;
1244 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1245 lsm->lsm_object_id, lsm->lsm_stripe_count, lsm->lsm_stripe_size);
1246 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
1249 if (lov->tgts[loi->loi_ost_idx].active == 0) {
1250 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1254 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1255 "%u\n", oa->o_id, i, loi->loi_id, loi->loi_ost_idx);
1256 /* create data objects with "parent" OA */
1257 memcpy(&tmp, oa, sizeof(tmp));
1258 tmp.o_id = loi->loi_id;
1260 err = obd_getattr(lov->tgts[loi->loi_ost_idx].ltd_exp, &tmp,
1263 if (lov->tgts[loi->loi_ost_idx].active) {
1264 CERROR("error: getattr objid "LPX64" subobj "
1265 LPX64" on OST idx %d: rc = %d\n",
1266 oa->o_id, loi->loi_id, loi->loi_ost_idx,
1271 lov_merge_attrs(oa, &tmp, tmp.o_valid, lsm, i, &set);
1279 static int lov_getattr_interpret(struct ptlrpc_request_set *rqset, void *data,
1282 struct lov_getattr_async_args *aa = data;
1283 struct lov_stripe_md *lsm = aa->aa_lsm;
1284 struct obdo *oa = aa->aa_oa;
1285 struct obdo *obdos = aa->aa_obdos;
1286 struct lov_oinfo *loi;
1292 /* NB all stripe requests succeeded to get here */
1294 loi = lsm->lsm_oinfo;
1295 for (i = 0; i < lsm->lsm_stripe_count; i++, loi++) {
1296 if (obdos[i].o_valid == 0) /* inactive stripe */
1299 lov_merge_attrs(oa, &obdos[i], obdos[i].o_valid, lsm,
1304 CERROR ("No stripes had valid attrs\n");
1309 OBD_FREE (obdos, lsm->lsm_stripe_count * sizeof (*obdos));
1313 static int lov_getattr_async(struct obd_export *exp, struct obdo *oa,
1314 struct lov_stripe_md *lsm,
1315 struct ptlrpc_request_set *rqset)
1318 struct lov_obd *lov;
1319 struct lov_oinfo *loi;
1320 struct lov_getattr_async_args *aa;
1321 int i, rc = 0, set = 0;
1324 if (lsm_bad_magic(lsm))
1327 if (!exp || !exp->exp_obd)
1330 lov = &exp->exp_obd->u.lov;
1332 OBD_ALLOC (obdos, lsm->lsm_stripe_count * sizeof (*obdos));
1336 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1337 lsm->lsm_object_id, lsm->lsm_stripe_count, lsm->lsm_stripe_size);
1338 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
1341 if (lov->tgts[loi->loi_ost_idx].active == 0) {
1342 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1343 /* leaves obdos[i].obd_valid unset */
1347 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at "
1348 "idx %u gen %d\n", oa->o_id, i, loi->loi_id,
1349 loi->loi_ost_idx, loi->loi_ost_gen);
1351 /* create data objects with "parent" OA */
1352 memcpy(&obdos[i], oa, sizeof(obdos[i]));
1353 obdos[i].o_id = loi->loi_id;
1355 err = obd_getattr_async(lov->tgts[loi->loi_ost_idx].ltd_exp,
1356 &obdos[i], NULL, rqset);
1358 CERROR("error: getattr objid "LPX64" subobj "
1359 LPX64" on OST idx %d: rc = %d\n",
1360 oa->o_id, loi->loi_id, loi->loi_ost_idx,
1362 GOTO(out_obdos, rc = err);
1367 GOTO (out_obdos, rc = -EIO);
1369 LASSERT (rqset->set_interpret == NULL);
1370 rqset->set_interpret = lov_getattr_interpret;
1371 LASSERT (sizeof (rqset->set_args) >= sizeof (*aa));
1372 aa = (struct lov_getattr_async_args *)&rqset->set_args;
1375 aa->aa_obdos = obdos;
1380 OBD_FREE (obdos, lsm->lsm_stripe_count * sizeof (*obdos));
1386 static int lov_setattr(struct obd_export *exp, struct obdo *src_oa,
1387 struct lov_stripe_md *lsm, struct obd_trans_info *oti)
1389 struct obdo *tmp_oa, *ret_oa;
1390 struct lov_obd *lov;
1391 struct lov_oinfo *loi;
1392 int rc = 0, i, set = 0;
1395 if (lsm_bad_magic(lsm))
1398 if (!exp || !exp->exp_obd)
1401 /* for now, we only expect time updates here */
1402 LASSERT(!(src_oa->o_valid & ~(OBD_MD_FLID|OBD_MD_FLTYPE | OBD_MD_FLMODE|
1403 OBD_MD_FLATIME | OBD_MD_FLMTIME |
1404 OBD_MD_FLCTIME | OBD_MD_FLFLAGS |
1405 OBD_MD_FLSIZE | OBD_MD_FLGROUP)));
1407 LASSERT(!(src_oa->o_valid & OBD_MD_FLGROUP) || src_oa->o_gr > 0);
1409 ret_oa = obdo_alloc();
1413 tmp_oa = obdo_alloc();
1415 GOTO(out_oa, rc = -ENOMEM);
1417 lov = &exp->exp_obd->u.lov;
1418 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
1421 if (lov->tgts[loi->loi_ost_idx].active == 0) {
1422 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1426 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
1427 tmp_oa->o_id = loi->loi_id;
1428 LASSERT(!(tmp_oa->o_valid & OBD_MD_FLGROUP) || tmp_oa->o_gr>0);
1430 if (src_oa->o_valid & OBD_MD_FLSIZE) {
1431 if (lov_stripe_offset(lsm, src_oa->o_size, i,
1432 &tmp_oa->o_size) < 0 &&
1436 CDEBUG(D_INODE, "stripe %d has size "LPU64"/"LPU64"\n",
1437 i, tmp_oa->o_size, src_oa->o_size);
1440 err = obd_setattr(lov->tgts[loi->loi_ost_idx].ltd_exp, tmp_oa,
1443 if (lov->tgts[loi->loi_ost_idx].active) {
1444 CERROR("error: setattr objid "LPX64" subobj "
1445 LPX64" on OST idx %d: rc = %d\n",
1446 src_oa->o_id, loi->loi_id,
1447 loi->loi_ost_idx, err);
1453 lov_merge_attrs(ret_oa, tmp_oa, tmp_oa->o_valid, lsm, i, &set);
1458 ret_oa->o_id = src_oa->o_id;
1459 memcpy(src_oa, ret_oa, sizeof(*src_oa));
1468 /* we have an offset in file backed by an lov and want to find out where
1469 * that offset lands in our given stripe of the file. for the easy
1470 * case where the offset is within the stripe, we just have to scale the
1471 * offset down to make it relative to the stripe instead of the lov.
1473 * the harder case is what to do when the offset doesn't intersect the
1474 * stripe. callers will want start offsets clamped ahead to the start
1475 * of the nearest stripe in the file. end offsets similarly clamped to the
1476 * nearest ending byte of a stripe in the file:
1478 * all this function does is move offsets to the nearest region of the
1479 * stripe, and it does its work "mod" the full length of all the stripes.
1480 * consider a file with 3 stripes:
1483 * ---------------------------------------------------------------------
1484 * | 0 | 1 | 2 | 0 | 1 | 2 |
1485 * ---------------------------------------------------------------------
1487 * to find stripe 1's offsets for S and E, it divides by the full stripe
1488 * width and does its math in the context of a single set of stripes:
1491 * -----------------------------------
1493 * -----------------------------------
1495 * it'll notice that E is outside stripe 1 and clamp it to the end of the
1496 * stripe, then multiply it back out by lov_off to give the real offsets in
1500 * ---------------------------------------------------------------------
1501 * | 1 | 1 | 1 | 1 | 1 | 1 |
1502 * ---------------------------------------------------------------------
1504 * it would have done similarly and pulled S forward to the start of a 1
1505 * stripe if, say, S had landed in a 0 stripe.
1507 * this rounding isn't always correct. consider an E lov offset that lands
1508 * on a 0 stripe, the "mod stripe width" math will pull it forward to the
1509 * start of a 1 stripe, when in fact it wanted to be rounded back to the end
1510 * of a previous 1 stripe. this logic is handled by callers and this is why:
1512 * this function returns < 0 when the offset was "before" the stripe and
1513 * was moved forward to the start of the stripe in question; 0 when it
1514 * falls in the stripe and no shifting was done; > 0 when the offset
1515 * was outside the stripe and was pulled back to its final byte. */
1516 static int lov_stripe_offset(struct lov_stripe_md *lsm, obd_off lov_off,
1517 int stripeno, obd_off *obd_off)
1519 unsigned long ssize = lsm->lsm_stripe_size;
1520 unsigned long swidth = ssize * lsm->lsm_stripe_count;
1521 unsigned long stripe_off, this_stripe;
1524 if (lov_off == OBD_OBJECT_EOF) {
1525 *obd_off = OBD_OBJECT_EOF;
1529 /* do_div(a, b) returns a % b, and a = a / b */
1530 stripe_off = do_div(lov_off, swidth);
1532 this_stripe = stripeno * ssize;
1533 if (stripe_off < this_stripe) {
1537 stripe_off -= this_stripe;
1539 if (stripe_off >= ssize) {
1545 *obd_off = lov_off * ssize + stripe_off;
1549 /* Given a whole-file size and a stripe number, give the file size which
1550 * corresponds to the individual object of that stripe.
1552 * This behaves basically in the same was as lov_stripe_offset, except that
1553 * file sizes falling before the beginning of a stripe are clamped to the end
1554 * of the previous stripe, not the beginning of the next:
1557 * ---------------------------------------------------------------------
1558 * | 0 | 1 | 2 | 0 | 1 | 2 |
1559 * ---------------------------------------------------------------------
1561 * if clamped to stripe 2 becomes:
1564 * ---------------------------------------------------------------------
1565 * | 0 | 1 | 2 | 0 | 1 | 2 |
1566 * ---------------------------------------------------------------------
1568 static obd_off lov_size_to_stripe(struct lov_stripe_md *lsm, obd_off file_size,
1571 unsigned long ssize = lsm->lsm_stripe_size;
1572 unsigned long swidth = ssize * lsm->lsm_stripe_count;
1573 unsigned long stripe_off, this_stripe;
1575 if (file_size == OBD_OBJECT_EOF)
1576 return OBD_OBJECT_EOF;
1578 /* do_div(a, b) returns a % b, and a = a / b */
1579 stripe_off = do_div(file_size, swidth);
1581 this_stripe = stripeno * ssize;
1582 if (stripe_off < this_stripe) {
1583 /* Move to end of previous stripe, or zero */
1584 if (file_size > 0) {
1591 stripe_off -= this_stripe;
1593 if (stripe_off >= ssize) {
1594 /* Clamp to end of this stripe */
1599 return (file_size * ssize + stripe_off);
1602 /* given an extent in an lov and a stripe, calculate the extent of the stripe
1603 * that is contained within the lov extent. this returns true if the given
1604 * stripe does intersect with the lov extent. */
1605 static int lov_stripe_intersects(struct lov_stripe_md *lsm, int stripeno,
1606 obd_off start, obd_off end,
1607 obd_off *obd_start, obd_off *obd_end)
1609 int start_side = 0, end_side = 0;
1611 switch (lsm->lsm_pattern) {
1612 case LOV_PATTERN_RAID0:
1613 start_side = lov_stripe_offset(lsm, start, stripeno, obd_start);
1614 end_side = lov_stripe_offset(lsm, end, stripeno, obd_end);
1616 case LOV_PATTERN_CMOBD:
1619 start_side = end_side = 0;
1625 CDEBUG(D_INODE, "["LPU64"->"LPU64"] -> [(%d) "LPU64"->"LPU64" (%d)]\n",
1626 start, end, start_side, *obd_start, *obd_end, end_side);
1628 /* this stripe doesn't intersect the file extent when neither
1629 * start or the end intersected the stripe and obd_start and
1630 * obd_end got rounded up to the save value. */
1631 if (start_side != 0 && end_side != 0 && *obd_start == *obd_end)
1634 /* as mentioned in the lov_stripe_offset commentary, end
1635 * might have been shifted in the wrong direction. This
1636 * happens when an end offset is before the stripe when viewed
1637 * through the "mod stripe size" math. we detect it being shifted
1638 * in the wrong direction and touch it up.
1639 * interestingly, this can't underflow since end must be > start
1640 * if we passed through the previous check.
1641 * (should we assert for that somewhere?) */
1648 /* compute which stripe number "lov_off" will be written into */
1649 static int lov_stripe_number(struct lov_stripe_md *lsm, obd_off lov_off)
1651 unsigned long ssize = lsm->lsm_stripe_size;
1652 unsigned long swidth = ssize * lsm->lsm_stripe_count;
1653 unsigned long stripe_off;
1655 if (lsm->lsm_pattern == LOV_PATTERN_CMOBD)
1658 stripe_off = do_div(lov_off, swidth);
1660 return stripe_off / ssize;
1663 static int lov_revalidate_md(struct obd_export *exp, struct obdo *src_oa,
1664 struct lov_stripe_md *ea,
1665 struct obd_trans_info *oti)
1667 struct obd_export *osc_exp;
1668 struct lov_obd *lov = &exp->exp_obd->u.lov;
1669 struct lov_stripe_md *lsm = ea;
1670 struct lov_stripe_md obj_md;
1671 struct lov_stripe_md *obj_mdp = &obj_md;
1672 struct lov_oinfo *loi;
1673 struct obdo *tmp_oa;
1674 int ost_idx, updates = 0, i;
1677 tmp_oa = obdo_alloc();
1681 loi = lsm->lsm_oinfo;
1682 for (i = 0; i < lsm->lsm_stripe_count; i++, loi++) {
1684 if (!obd_uuid_empty(&lov->tgts[loi->loi_ost_idx].uuid))
1687 ost_idx = lov_revalidate_policy(lov, lsm);
1689 /* FIXME: punt for now. */
1690 CERROR("lov_revalidate_policy failed; no active "
1695 /* create a new object */
1696 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
1697 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1698 osc_exp = lov->tgts[ost_idx].ltd_exp;
1699 rc = obd_create(osc_exp, tmp_oa, &obj_mdp, oti);
1701 CERROR("error creating new subobj at idx %d; "
1702 "rc = %d\n", ost_idx, rc);
1706 oti->oti_objid[ost_idx] = tmp_oa->o_id;
1707 loi->loi_id = tmp_oa->o_id;
1708 loi->loi_ost_idx = ost_idx;
1709 loi->loi_ost_gen = lov->tgts[ost_idx].ltd_gen;
1710 CDEBUG(D_INODE, "replacing objid "LPX64" subobj "LPX64
1711 " with idx %d gen %d.\n", lsm->lsm_object_id,
1712 loi->loi_id, ost_idx, loi->loi_ost_gen);
1716 /* If we got an error revalidating an entry there's no need to
1717 * cleanup up objects we allocated here because the bad entry
1718 * still points to a deleted OST. */
1724 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
1725 * we can send this 'punch' to just the authoritative node and the nodes
1726 * that the punch will affect. */
1727 static int lov_punch(struct obd_export *exp, struct obdo *oa,
1728 struct lov_stripe_md *lsm,
1729 obd_off start, obd_off end, struct obd_trans_info *oti)
1732 struct lov_obd *lov;
1733 struct lov_oinfo *loi;
1737 if (lsm_bad_magic(lsm))
1740 if (!exp || !exp->exp_obd)
1743 lov = &exp->exp_obd->u.lov;
1744 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
1745 obd_off starti, endi;
1748 if (lov->tgts[loi->loi_ost_idx].active == 0) {
1749 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1753 if (!lov_stripe_intersects(lsm, i, start, end, &starti, &endi))
1756 /* create data objects with "parent" OA */
1757 memcpy(&tmp, oa, sizeof(tmp));
1758 tmp.o_id = loi->loi_id;
1760 err = obd_punch(lov->tgts[loi->loi_ost_idx].ltd_exp, &tmp, NULL,
1761 starti, endi, NULL);
1763 if (lov->tgts[loi->loi_ost_idx].active) {
1764 CERROR("error: punch objid "LPX64" subobj "LPX64
1765 " on OST idx %d: rc = %d\n", oa->o_id,
1766 loi->loi_id, loi->loi_ost_idx, err);
1771 loi->loi_kms = loi->loi_rss = starti;
1777 static int lov_sync(struct obd_export *exp, struct obdo *oa,
1778 struct lov_stripe_md *lsm, obd_off start, obd_off end)
1781 struct lov_obd *lov;
1782 struct lov_oinfo *loi;
1786 if (lsm_bad_magic(lsm))
1796 lov = &exp->exp_obd->u.lov;
1797 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
1798 obd_off starti, endi;
1801 if (lov->tgts[loi->loi_ost_idx].active == 0) {
1802 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1806 if (!lov_stripe_intersects(lsm, i, start, end, &starti, &endi))
1809 memcpy(tmp, oa, sizeof(*tmp));
1810 tmp->o_id = loi->loi_id;
1812 err = obd_sync(lov->tgts[loi->loi_ost_idx].ltd_exp, tmp, NULL,
1815 if (lov->tgts[loi->loi_ost_idx].active) {
1816 CERROR("error: fsync objid "LPX64" subobj "LPX64
1817 " on OST idx %d: rc = %d\n", oa->o_id,
1818 loi->loi_id, loi->loi_ost_idx, err);
1829 static int lov_brw_check(struct lov_obd *lov, struct obdo *oa,
1830 struct lov_stripe_md *lsm,
1831 obd_count oa_bufs, struct brw_page *pga)
1836 /* The caller just wants to know if there's a chance that this
1837 * I/O can succeed */
1838 for (i = 0; i < oa_bufs; i++) {
1839 int stripe = lov_stripe_number(lsm, pga[i].disk_offset);
1840 int ost = lsm->lsm_oinfo[stripe].loi_ost_idx;
1843 if (!lov_stripe_intersects(lsm, i, pga[i].disk_offset,
1844 pga[i].disk_offset + pga[i].count,
1848 if (lov->tgts[ost].active == 0) {
1849 CDEBUG(D_HA, "lov idx %d inactive\n", ost);
1852 rc = obd_brw(OBD_BRW_CHECK, lov->tgts[ost].ltd_exp, oa,
1853 NULL, 1, &pga[i], NULL);
1860 static int lov_brw(int cmd, struct obd_export *exp, struct obdo *src_oa,
1861 struct lov_stripe_md *lsm, obd_count oa_bufs,
1862 struct brw_page *pga, struct obd_trans_info *oti)
1868 struct lov_stripe_md lsm;
1870 } *stripeinfo, *si, *si_last;
1871 struct obdo *ret_oa = NULL, *tmp_oa = NULL;
1872 struct lov_obd *lov;
1873 struct brw_page *ioarr;
1874 struct lov_oinfo *loi;
1875 int rc = 0, i, *where, stripe_count = lsm->lsm_stripe_count, set = 0;
1878 if (lsm_bad_magic(lsm))
1881 lov = &exp->exp_obd->u.lov;
1883 if (cmd == OBD_BRW_CHECK) {
1884 rc = lov_brw_check(lov, src_oa, lsm, oa_bufs, pga);
1888 OBD_ALLOC(stripeinfo, stripe_count * sizeof(*stripeinfo));
1892 OBD_ALLOC(where, sizeof(*where) * oa_bufs);
1894 GOTO(out_sinfo, rc = -ENOMEM);
1896 OBD_ALLOC(ioarr, sizeof(*ioarr) * oa_bufs);
1898 GOTO(out_where, rc = -ENOMEM);
1901 ret_oa = obdo_alloc();
1903 GOTO(out_ioarr, rc = -ENOMEM);
1905 tmp_oa = obdo_alloc();
1907 GOTO(out_oa, rc = -ENOMEM);
1910 for (i = 0; i < oa_bufs; i++) {
1911 where[i] = lov_stripe_number(lsm, pga[i].disk_offset);
1912 stripeinfo[where[i]].bufct++;
1915 for (i = 0, loi = lsm->lsm_oinfo, si_last = si = stripeinfo;
1916 i < stripe_count; i++, loi++, si_last = si, si++) {
1918 si->index = si_last->index + si_last->bufct;
1919 si->lsm.lsm_object_id = loi->loi_id;
1920 si->lsm.lsm_object_gr = lsm->lsm_object_gr;
1921 si->ost_idx = loi->loi_ost_idx;
1924 for (i = 0; i < oa_bufs; i++) {
1925 int which = where[i];
1928 shift = stripeinfo[which].index + stripeinfo[which].subcount;
1929 LASSERT(shift < oa_bufs);
1930 ioarr[shift] = pga[i];
1931 lov_stripe_offset(lsm, pga[i].disk_offset, which,
1932 &ioarr[shift].disk_offset);
1933 stripeinfo[which].subcount++;
1936 for (i = 0, si = stripeinfo; i < stripe_count; i++, si++) {
1937 int shift = si->index;
1939 if (lov->tgts[si->ost_idx].active == 0) {
1940 CDEBUG(D_HA, "lov idx %d inactive\n", si->ost_idx);
1941 GOTO(out_oa, rc = -EIO);
1945 LASSERT(shift < oa_bufs);
1947 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
1949 tmp_oa->o_id = si->lsm.lsm_object_id;
1950 rc = obd_brw(cmd, lov->tgts[si->ost_idx].ltd_exp,
1951 tmp_oa, &si->lsm, si->bufct,
1952 &ioarr[shift], oti);
1956 lov_merge_attrs(ret_oa, tmp_oa, tmp_oa->o_valid, lsm,
1961 ret_oa->o_id = src_oa->o_id;
1962 memcpy(src_oa, ret_oa, sizeof(*src_oa));
1971 OBD_FREE(ioarr, sizeof(*ioarr) * oa_bufs);
1973 OBD_FREE(where, sizeof(*where) * oa_bufs);
1975 OBD_FREE(stripeinfo, stripe_count * sizeof(*stripeinfo));
1979 static int lov_brw_interpret(struct ptlrpc_request_set *reqset, void *data,
1982 struct lov_brw_async_args *aa = data;
1983 struct lov_stripe_md *lsm = aa->aa_lsm;
1984 obd_count oa_bufs = aa->aa_oa_bufs;
1985 struct obdo *oa = aa->aa_oa;
1986 struct obdo *obdos = aa->aa_obdos;
1987 struct brw_page *ioarr = aa->aa_ioarr;
1988 struct lov_oinfo *loi;
1993 /* NB all stripe requests succeeded to get here */
1995 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
1997 if (obdos[i].o_valid == 0) /* inactive stripe */
2000 lov_merge_attrs(oa, &obdos[i], obdos[i].o_valid, lsm,
2005 CERROR("No stripes had valid attrs\n");
2009 oa->o_id = lsm->lsm_object_id;
2011 OBD_FREE(obdos, lsm->lsm_stripe_count * sizeof(*obdos));
2012 OBD_FREE(ioarr, sizeof(*ioarr) * oa_bufs);
2016 static int lov_brw_async(int cmd, struct obd_export *exp, struct obdo *oa,
2017 struct lov_stripe_md *lsm, obd_count oa_bufs,
2018 struct brw_page *pga, struct ptlrpc_request_set *set,
2019 struct obd_trans_info *oti)
2025 struct lov_stripe_md lsm;
2027 } *stripeinfo, *si, *si_last;
2028 struct lov_obd *lov;
2029 struct brw_page *ioarr;
2030 struct obdo *obdos = NULL;
2031 struct lov_oinfo *loi;
2032 struct lov_brw_async_args *aa;
2033 int rc = 0, i, *where, stripe_count = lsm->lsm_stripe_count;
2036 if (lsm_bad_magic(lsm))
2039 lov = &exp->exp_obd->u.lov;
2041 if (cmd == OBD_BRW_CHECK) {
2042 rc = lov_brw_check(lov, oa, lsm, oa_bufs, pga);
2046 OBD_ALLOC(stripeinfo, stripe_count * sizeof(*stripeinfo));
2050 OBD_ALLOC(where, sizeof(*where) * oa_bufs);
2052 GOTO(out_sinfo, rc = -ENOMEM);
2055 OBD_ALLOC(obdos, sizeof(*obdos) * stripe_count);
2057 GOTO(out_where, rc = -ENOMEM);
2060 OBD_ALLOC(ioarr, sizeof(*ioarr) * oa_bufs);
2062 GOTO(out_obdos, rc = -ENOMEM);
2064 for (i = 0; i < oa_bufs; i++) {
2065 where[i] = lov_stripe_number(lsm, pga[i].disk_offset);
2066 stripeinfo[where[i]].bufct++;
2069 for (i = 0, loi = lsm->lsm_oinfo, si_last = si = stripeinfo;
2070 i < stripe_count; i++, loi++, si_last = si, si++) {
2072 si->index = si_last->index + si_last->bufct;
2073 si->lsm.lsm_object_id = loi->loi_id;
2074 si->ost_idx = loi->loi_ost_idx;
2077 memcpy(&obdos[i], oa, sizeof(*obdos));
2078 obdos[i].o_id = si->lsm.lsm_object_id;
2082 for (i = 0; i < oa_bufs; i++) {
2083 int which = where[i];
2086 shift = stripeinfo[which].index + stripeinfo[which].subcount;
2087 LASSERT(shift < oa_bufs);
2088 ioarr[shift] = pga[i];
2089 lov_stripe_offset(lsm, pga[i].disk_offset, which,
2090 &ioarr[shift].disk_offset);
2091 stripeinfo[which].subcount++;
2094 for (i = 0, si = stripeinfo; i < stripe_count; i++, si++) {
2095 int shift = si->index;
2100 if (lov->tgts[si->ost_idx].active == 0) {
2101 CDEBUG(D_HA, "lov idx %d inactive\n", si->ost_idx);
2102 GOTO(out_ioarr, rc = -EIO);
2105 LASSERT(shift < oa_bufs);
2107 rc = obd_brw_async(cmd, lov->tgts[si->ost_idx].ltd_exp,
2108 &obdos[i], &si->lsm, si->bufct,
2109 &ioarr[shift], set, oti);
2111 GOTO(out_ioarr, rc);
2114 LASSERT(set->set_interpret == NULL);
2115 set->set_interpret = (set_interpreter_func)lov_brw_interpret;
2116 LASSERT(sizeof(set->set_args) >= sizeof(struct lov_brw_async_args));
2117 aa = (struct lov_brw_async_args *)&set->set_args;
2119 aa->aa_obdos = obdos;
2121 aa->aa_ioarr = ioarr;
2122 aa->aa_oa_bufs = oa_bufs;
2124 /* Don't free ioarr or obdos - that's done in lov_brw_interpret */
2125 GOTO(out_where, rc);
2128 OBD_FREE(ioarr, sizeof(*ioarr) * oa_bufs);
2130 OBD_FREE(obdos, stripe_count * sizeof(*obdos));
2132 OBD_FREE(where, sizeof(*where) * oa_bufs);
2134 OBD_FREE(stripeinfo, stripe_count * sizeof(*stripeinfo));
2138 struct lov_async_page *lap_from_cookie(void *cookie)
2140 struct lov_async_page *lap = cookie;
2141 if (lap->lap_magic != LAP_MAGIC)
2142 return ERR_PTR(-EINVAL);
2146 static int lov_ap_make_ready(void *data, int cmd)
2148 struct lov_async_page *lap = lap_from_cookie(data);
2149 /* XXX should these assert? */
2153 return lap->lap_caller_ops->ap_make_ready(lap->lap_caller_data, cmd);
2155 static int lov_ap_refresh_count(void *data, int cmd)
2157 struct lov_async_page *lap = lap_from_cookie(data);
2161 return lap->lap_caller_ops->ap_refresh_count(lap->lap_caller_data,
2164 static void lov_ap_fill_obdo(void *data, int cmd, struct obdo *oa)
2166 struct lov_async_page *lap = lap_from_cookie(data);
2167 /* XXX should these assert? */
2171 lap->lap_caller_ops->ap_fill_obdo(lap->lap_caller_data, cmd, oa);
2172 /* XXX woah, shouldn't we be altering more here? size? */
2173 oa->o_id = lap->lap_loi_id;
2176 static void lov_ap_completion(void *data, int cmd, struct obdo *oa, int rc)
2178 struct lov_async_page *lap = lap_from_cookie(data);
2182 /* in a raid1 regime this would down a count of many ios
2183 * in flight, onl calling the caller_ops completion when all
2184 * the raid1 ios are complete */
2185 lap->lap_caller_ops->ap_completion(lap->lap_caller_data, cmd, oa, rc);
2188 static struct obd_async_page_ops lov_async_page_ops = {
2189 .ap_make_ready = lov_ap_make_ready,
2190 .ap_refresh_count = lov_ap_refresh_count,
2191 .ap_fill_obdo = lov_ap_fill_obdo,
2192 .ap_completion = lov_ap_completion,
2195 static int lov_prep_async_page(struct obd_export *exp,
2196 struct lov_stripe_md *lsm,
2197 struct lov_oinfo *loi, struct page *page,
2198 obd_off offset, struct obd_async_page_ops *ops,
2199 void *data, void **res)
2201 struct lov_obd *lov = &exp->exp_obd->u.lov;
2202 struct lov_async_page *lap;
2206 if (lsm_bad_magic(lsm))
2208 LASSERT(loi == NULL);
2210 stripe = lov_stripe_number(lsm, offset);
2211 loi = &lsm->lsm_oinfo[stripe];
2213 if (obd_uuid_empty(&lov->tgts[loi->loi_ost_idx].uuid))
2215 if (lov->tgts[loi->loi_ost_idx].active == 0)
2217 if (lov->tgts[loi->loi_ost_idx].ltd_exp == NULL) {
2218 CERROR("ltd_exp == NULL, but OST idx %d doesn't appear to be "
2219 "deleted or inactive.\n", loi->loi_ost_idx);
2223 OBD_ALLOC(lap, sizeof(*lap));
2227 lap->lap_magic = LAP_MAGIC;
2228 lap->lap_caller_ops = ops;
2229 lap->lap_caller_data = data;
2231 /* FIXME handle multiple oscs after landing b_raid1 */
2232 lap->lap_stripe = stripe;
2233 switch (lsm->lsm_pattern) {
2234 case LOV_PATTERN_RAID0:
2235 lov_stripe_offset(lsm, offset, lap->lap_stripe,
2236 &lap->lap_sub_offset);
2238 case LOV_PATTERN_CMOBD:
2239 lap->lap_sub_offset = offset;
2245 /* so the callback doesn't need the lsm */
2246 lap->lap_loi_id = loi->loi_id;
2248 rc = obd_prep_async_page(lov->tgts[loi->loi_ost_idx].ltd_exp,
2249 lsm, loi, page, lap->lap_sub_offset,
2250 &lov_async_page_ops, lap,
2251 &lap->lap_sub_cookie);
2253 OBD_FREE(lap, sizeof(*lap));
2256 CDEBUG(D_CACHE, "lap %p page %p cookie %p off "LPU64"\n", lap, page,
2257 lap->lap_sub_cookie, offset);
2262 static int lov_queue_async_io(struct obd_export *exp,
2263 struct lov_stripe_md *lsm,
2264 struct lov_oinfo *loi, void *cookie,
2265 int cmd, obd_off off, int count,
2266 obd_flag brw_flags, obd_flag async_flags)
2268 struct lov_obd *lov = &exp->exp_obd->u.lov;
2269 struct lov_async_page *lap;
2272 LASSERT(loi == NULL);
2274 if (lsm_bad_magic(lsm))
2277 lap = lap_from_cookie(cookie);
2279 RETURN(PTR_ERR(lap));
2281 loi = &lsm->lsm_oinfo[lap->lap_stripe];
2283 rc = obd_queue_async_io(lov->tgts[loi->loi_ost_idx].ltd_exp, lsm,
2284 loi, lap->lap_sub_cookie, cmd, off, count,
2285 brw_flags, async_flags);
2289 static int lov_set_async_flags(struct obd_export *exp,
2290 struct lov_stripe_md *lsm,
2291 struct lov_oinfo *loi, void *cookie,
2292 obd_flag async_flags)
2294 struct lov_obd *lov = &exp->exp_obd->u.lov;
2295 struct lov_async_page *lap;
2298 LASSERT(loi == NULL);
2300 if (lsm_bad_magic(lsm))
2303 lap = lap_from_cookie(cookie);
2305 RETURN(PTR_ERR(lap));
2307 loi = &lsm->lsm_oinfo[lap->lap_stripe];
2309 rc = obd_set_async_flags(lov->tgts[loi->loi_ost_idx].ltd_exp,
2310 lsm, loi, lap->lap_sub_cookie, async_flags);
2314 static int lov_queue_group_io(struct obd_export *exp,
2315 struct lov_stripe_md *lsm,
2316 struct lov_oinfo *loi,
2317 struct obd_io_group *oig, void *cookie,
2318 int cmd, obd_off off, int count,
2319 obd_flag brw_flags, obd_flag async_flags)
2321 struct lov_obd *lov = &exp->exp_obd->u.lov;
2322 struct lov_async_page *lap;
2325 LASSERT(loi == NULL);
2327 if (lsm_bad_magic(lsm))
2330 lap = lap_from_cookie(cookie);
2332 RETURN(PTR_ERR(lap));
2334 loi = &lsm->lsm_oinfo[lap->lap_stripe];
2336 rc = obd_queue_group_io(lov->tgts[loi->loi_ost_idx].ltd_exp, lsm, loi,
2337 oig, lap->lap_sub_cookie, cmd, off, count,
2338 brw_flags, async_flags);
2342 /* this isn't exactly optimal. we may have queued sync io in oscs on
2343 * all stripes, but we don't record that fact at queue time. so we
2344 * trigger sync io on all stripes. */
2345 static int lov_trigger_group_io(struct obd_export *exp,
2346 struct lov_stripe_md *lsm,
2347 struct lov_oinfo *loi,
2348 struct obd_io_group *oig)
2350 struct lov_obd *lov = &exp->exp_obd->u.lov;
2353 LASSERT(loi == NULL);
2355 if (lsm_bad_magic(lsm))
2358 loi = lsm->lsm_oinfo;
2359 for (i = 0; i < lsm->lsm_stripe_count; i++, loi++) {
2360 if (lov->tgts[loi->loi_ost_idx].active == 0) {
2361 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2365 err = obd_trigger_group_io(lov->tgts[loi->loi_ost_idx].ltd_exp,
2367 if (rc == 0 && err != 0)
2373 static int lov_teardown_async_page(struct obd_export *exp,
2374 struct lov_stripe_md *lsm,
2375 struct lov_oinfo *loi, void *cookie)
2377 struct lov_obd *lov = &exp->exp_obd->u.lov;
2378 struct lov_async_page *lap;
2381 LASSERT(loi == NULL);
2383 if (lsm_bad_magic(lsm))
2386 lap = lap_from_cookie(cookie);
2388 RETURN(PTR_ERR(lap));
2390 loi = &lsm->lsm_oinfo[lap->lap_stripe];
2392 rc = obd_teardown_async_page(lov->tgts[loi->loi_ost_idx].ltd_exp,
2393 lsm, loi, lap->lap_sub_cookie);
2395 CERROR("unable to teardown sub cookie %p: %d\n",
2396 lap->lap_sub_cookie, rc);
2399 OBD_FREE(lap, sizeof(*lap));
2403 static int lov_enqueue(struct obd_export *exp, struct lov_stripe_md *lsm,
2404 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
2405 int *flags, void *bl_cb, void *cp_cb, void *gl_cb,
2406 void *data,__u32 lvb_len, void *lvb_swabber,
2407 struct lustre_handle *lockh)
2409 struct lov_lock_handles *lov_lockh = NULL;
2410 struct lustre_handle *lov_lockhp;
2411 struct lov_obd *lov;
2412 struct lov_oinfo *loi;
2413 char submd_buf[sizeof(struct lov_stripe_md) + sizeof(struct lov_oinfo)];
2414 struct lov_stripe_md *submd = (void *)submd_buf;
2416 int i, save_flags = *flags;
2419 if (lsm_bad_magic(lsm))
2422 /* we should never be asked to replay a lock this way. */
2423 LASSERT((*flags & LDLM_FL_REPLAY) == 0);
2425 if (!exp || !exp->exp_obd)
2428 if (lsm->lsm_stripe_count > 1) {
2429 lov_lockh = lov_llh_new(lsm);
2430 if (lov_lockh == NULL)
2433 lockh->cookie = lov_lockh->llh_handle.h_cookie;
2434 lov_lockhp = lov_lockh->llh_handles;
2439 lov = &exp->exp_obd->u.lov;
2440 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
2441 i++, loi++, lov_lockhp++) {
2442 ldlm_policy_data_t sub_ext;
2445 if (!lov_stripe_intersects(lsm, i, policy->l_extent.start,
2446 policy->l_extent.end, &start,
2450 sub_ext.l_extent.start = start;
2451 sub_ext.l_extent.end = end;
2452 sub_ext.l_extent.gid = policy->l_extent.gid;
2454 if (lov->tgts[loi->loi_ost_idx].active == 0) {
2455 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2459 /* XXX LOV STACKING: submd should be from the subobj */
2460 submd->lsm_object_id = loi->loi_id;
2461 submd->lsm_object_gr = lsm->lsm_object_gr;
2462 submd->lsm_stripe_count = 0;
2463 submd->lsm_oinfo->loi_kms_valid = loi->loi_kms_valid;
2464 submd->lsm_oinfo->loi_rss = loi->loi_rss;
2465 submd->lsm_oinfo->loi_kms = loi->loi_kms;
2466 submd->lsm_oinfo->loi_blocks = loi->loi_blocks;
2467 loi->loi_mtime = submd->lsm_oinfo->loi_mtime;
2468 /* XXX submd is not fully initialized here */
2469 *flags = save_flags;
2470 rc = obd_enqueue(lov->tgts[loi->loi_ost_idx].ltd_exp, submd,
2471 type, &sub_ext, mode, flags, bl_cb, cp_cb,
2472 gl_cb, data, lvb_len, lvb_swabber, lov_lockhp);
2474 /* XXX FIXME: This unpleasantness doesn't belong here at *all*.
2475 * It belongs in the OSC, except that the OSC doesn't have
2476 * access to the real LOI -- it gets a copy, that we created
2477 * above, and that copy can be arbitrarily out of date.
2479 * The LOV API is due for a serious rewriting anyways, and this
2480 * can be addressed then. */
2481 if (rc == ELDLM_OK) {
2482 struct ldlm_lock *lock = ldlm_handle2lock(lov_lockhp);
2483 __u64 tmp = submd->lsm_oinfo->loi_rss;
2485 LASSERT(lock != NULL);
2487 loi->loi_blocks = submd->lsm_oinfo->loi_blocks;
2488 /* Extend KMS up to the end of this lock and no further
2489 * A lock on [x,y] means a KMS of up to y + 1 bytes! */
2490 if (tmp > lock->l_policy_data.l_extent.end)
2491 tmp = lock->l_policy_data.l_extent.end + 1;
2492 if (tmp >= loi->loi_kms) {
2493 CDEBUG(D_INODE, "lock acquired, setting rss="
2494 LPU64", kms="LPU64"\n", loi->loi_rss,
2497 loi->loi_kms_valid = 1;
2499 CDEBUG(D_INODE, "lock acquired, setting rss="
2500 LPU64"; leaving kms="LPU64", end="LPU64
2501 "\n", loi->loi_rss, loi->loi_kms,
2502 lock->l_policy_data.l_extent.end);
2504 ldlm_lock_allow_match(lock);
2505 LDLM_LOCK_PUT(lock);
2506 } else if (rc == ELDLM_LOCK_ABORTED &&
2507 save_flags & LDLM_FL_HAS_INTENT) {
2508 memset(lov_lockhp, 0, sizeof(*lov_lockhp));
2509 loi->loi_rss = submd->lsm_oinfo->loi_rss;
2510 loi->loi_blocks = submd->lsm_oinfo->loi_blocks;
2511 CDEBUG(D_INODE, "glimpsed, setting rss="LPU64"; leaving"
2512 " kms="LPU64"\n", loi->loi_rss, loi->loi_kms);
2514 memset(lov_lockhp, 0, sizeof(*lov_lockhp));
2515 if (lov->tgts[loi->loi_ost_idx].active) {
2516 CERROR("error: enqueue objid "LPX64" subobj "
2517 LPX64" on OST idx %d: rc = %d\n",
2518 lsm->lsm_object_id, loi->loi_id,
2519 loi->loi_ost_idx, rc);
2520 GOTO(out_locks, rc);
2524 if (lsm->lsm_stripe_count > 1)
2525 lov_llh_put(lov_lockh);
2529 while (loi--, lov_lockhp--, i-- > 0) {
2530 struct lov_stripe_md submd;
2533 if (lov_lockhp->cookie == 0)
2536 /* XXX LOV STACKING: submd should be from the subobj */
2537 submd.lsm_object_id = loi->loi_id;
2538 submd.lsm_object_gr = lsm->lsm_object_gr;
2539 submd.lsm_stripe_count = 0;
2540 err = obd_cancel(lov->tgts[loi->loi_ost_idx].ltd_exp, &submd,
2542 if (err && lov->tgts[loi->loi_ost_idx].active) {
2543 CERROR("error: cancelling objid "LPX64" on OST "
2544 "idx %d after enqueue error: rc = %d\n",
2545 loi->loi_id, loi->loi_ost_idx, err);
2549 if (lsm->lsm_stripe_count > 1) {
2550 lov_llh_destroy(lov_lockh);
2551 lov_llh_put(lov_lockh);
2556 static int lov_match(struct obd_export *exp, struct lov_stripe_md *lsm,
2557 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
2558 int *flags, void *data, struct lustre_handle *lockh)
2560 struct lov_lock_handles *lov_lockh = NULL;
2561 struct lustre_handle *lov_lockhp;
2562 struct lov_obd *lov;
2563 struct lov_oinfo *loi;
2564 struct lov_stripe_md submd;
2565 ldlm_error_t rc = 0;
2569 if (lsm_bad_magic(lsm))
2572 if (!exp || !exp->exp_obd)
2575 if (lsm->lsm_stripe_count > 1) {
2576 lov_lockh = lov_llh_new(lsm);
2577 if (lov_lockh == NULL)
2580 lockh->cookie = lov_lockh->llh_handle.h_cookie;
2581 lov_lockhp = lov_lockh->llh_handles;
2586 lov = &exp->exp_obd->u.lov;
2587 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
2588 i++, loi++, lov_lockhp++) {
2589 ldlm_policy_data_t sub_ext;
2593 if (!lov_stripe_intersects(lsm, i, policy->l_extent.start,
2594 policy->l_extent.end, &start, &end))
2597 sub_ext.l_extent.start = start;
2598 sub_ext.l_extent.end = end;
2600 if (obd_uuid_empty(&lov->tgts[loi->loi_ost_idx].uuid)) {
2601 CDEBUG(D_HA, "lov idx %d deleted\n", loi->loi_ost_idx);
2604 if (lov->tgts[loi->loi_ost_idx].active == 0) {
2605 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2610 /* XXX LOV STACKING: submd should be from the subobj */
2611 submd.lsm_object_id = loi->loi_id;
2612 submd.lsm_object_gr = lsm->lsm_object_gr;
2613 submd.lsm_stripe_count = 0;
2615 /* XXX submd is not fully initialized here */
2616 rc = obd_match(lov->tgts[loi->loi_ost_idx].ltd_exp, &submd,
2617 type, &sub_ext, mode, &lov_flags, data,
2623 if (lsm->lsm_stripe_count > 1) {
2624 if (*flags & LDLM_FL_TEST_LOCK)
2625 lov_llh_destroy(lov_lockh);
2626 lov_llh_put(lov_lockh);
2631 while (loi--, lov_lockhp--, i-- > 0) {
2632 struct lov_stripe_md submd;
2635 if (lov_lockhp->cookie == 0)
2638 /* XXX LOV STACKING: submd should be from the subobj */
2639 submd.lsm_object_id = loi->loi_id;
2640 submd.lsm_object_gr = lsm->lsm_object_gr;
2641 submd.lsm_stripe_count = 0;
2642 err = obd_cancel(lov->tgts[loi->loi_ost_idx].ltd_exp, &submd,
2644 if (err && lov->tgts[loi->loi_ost_idx].active) {
2645 CERROR("error: cancelling objid "LPX64" on OST "
2646 "idx %d after match failure: rc = %d\n",
2647 loi->loi_id, loi->loi_ost_idx, err);
2651 if (lsm->lsm_stripe_count > 1) {
2652 lov_llh_destroy(lov_lockh);
2653 lov_llh_put(lov_lockh);
2658 static int lov_change_cbdata(struct obd_export *exp,
2659 struct lov_stripe_md *lsm, ldlm_iterator_t it,
2662 struct lov_obd *lov;
2663 struct lov_oinfo *loi;
2667 if (lsm_bad_magic(lsm))
2670 if (!exp || !exp->exp_obd)
2673 LASSERT(lsm->lsm_object_gr > 0);
2675 lov = &exp->exp_obd->u.lov;
2676 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
2677 struct lov_stripe_md submd;
2678 if (lov->tgts[loi->loi_ost_idx].active == 0) {
2679 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2683 submd.lsm_object_id = loi->loi_id;
2684 submd.lsm_object_gr = lsm->lsm_object_gr;
2685 submd.lsm_stripe_count = 0;
2686 rc = obd_change_cbdata(lov->tgts[loi->loi_ost_idx].ltd_exp,
2692 static int lov_cancel(struct obd_export *exp, struct lov_stripe_md *lsm,
2693 __u32 mode, struct lustre_handle *lockh)
2695 struct lov_lock_handles *lov_lockh = NULL;
2696 struct lustre_handle *lov_lockhp;
2697 struct lov_obd *lov;
2698 struct lov_oinfo *loi;
2702 if (lsm_bad_magic(lsm))
2705 if (!exp || !exp->exp_obd)
2708 LASSERT(lsm->lsm_object_gr > 0);
2711 if (lsm->lsm_stripe_count > 1) {
2712 lov_lockh = lov_handle2llh(lockh);
2714 CERROR("LOV: invalid lov lock handle %p\n", lockh);
2718 lov_lockhp = lov_lockh->llh_handles;
2723 lov = &exp->exp_obd->u.lov;
2724 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
2725 i++, loi++, lov_lockhp++) {
2726 struct lov_stripe_md submd;
2729 if (lov_lockhp->cookie == 0) {
2730 CDEBUG(D_HA, "lov idx %d subobj "LPX64" no lock?\n",
2731 loi->loi_ost_idx, loi->loi_id);
2735 /* XXX LOV STACKING: submd should be from the subobj */
2736 submd.lsm_object_id = loi->loi_id;
2737 submd.lsm_object_gr = lsm->lsm_object_gr;
2738 submd.lsm_stripe_count = 0;
2739 err = obd_cancel(lov->tgts[loi->loi_ost_idx].ltd_exp, &submd,
2742 if (lov->tgts[loi->loi_ost_idx].active) {
2743 CERROR("error: cancel objid "LPX64" subobj "
2744 LPX64" on OST idx %d: rc = %d\n",
2746 loi->loi_id, loi->loi_ost_idx, err);
2753 if (lsm->lsm_stripe_count > 1)
2754 lov_llh_destroy(lov_lockh);
2755 if (lov_lockh != NULL)
2756 lov_llh_put(lov_lockh);
2760 static int lov_cancel_unused(struct obd_export *exp,
2761 struct lov_stripe_md *lsm, int flags, void *opaque)
2763 struct lov_obd *lov;
2764 struct lov_oinfo *loi;
2768 lov = &exp->exp_obd->u.lov;
2770 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2771 int err = obd_cancel_unused(lov->tgts[i].ltd_exp, NULL,
2779 if (lsm_bad_magic(lsm))
2782 if (!exp || !exp->exp_obd)
2785 LASSERT(lsm->lsm_object_gr > 0);
2787 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
2788 struct lov_stripe_md submd;
2791 if (lov->tgts[loi->loi_ost_idx].active == 0)
2792 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2794 submd.lsm_object_id = loi->loi_id;
2795 submd.lsm_object_gr = lsm->lsm_object_gr;
2796 submd.lsm_stripe_count = 0;
2797 err = obd_cancel_unused(lov->tgts[loi->loi_ost_idx].ltd_exp,
2798 &submd, flags, opaque);
2799 if (err && lov->tgts[loi->loi_ost_idx].active) {
2800 CERROR("error: cancel unused objid "LPX64" subobj "LPX64
2801 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
2802 loi->loi_id, loi->loi_ost_idx, err);
2810 #define LOV_U64_MAX ((__u64)~0ULL)
2811 #define LOV_SUM_MAX(tot, add) \
2813 if ((tot) + (add) < (tot)) \
2814 (tot) = LOV_U64_MAX; \
2819 static int lov_statfs(struct obd_device *obd, struct obd_statfs *osfs,
2820 unsigned long max_age)
2822 struct lov_obd *lov = &obd->u.lov;
2823 struct obd_statfs lov_sfs;
2830 /* We only get block data from the OBD */
2831 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2833 if (!lov->tgts[i].active) {
2834 CDEBUG(D_HA, "lov idx %d inactive\n", i);
2838 err = obd_statfs(class_exp2obd(lov->tgts[i].ltd_exp), &lov_sfs,
2841 if (lov->tgts[i].active && !rc)
2847 memcpy(osfs, &lov_sfs, sizeof(lov_sfs));
2850 osfs->os_bfree += lov_sfs.os_bfree;
2851 osfs->os_bavail += lov_sfs.os_bavail;
2852 osfs->os_blocks += lov_sfs.os_blocks;
2853 /* XXX not sure about this one - depends on policy.
2854 * - could be minimum if we always stripe on all OBDs
2855 * (but that would be wrong for any other policy,
2856 * if one of the OBDs has no more objects left)
2857 * - could be sum if we stripe whole objects
2858 * - could be average, just to give a nice number
2860 * To give a "reasonable" (if not wholly accurate)
2861 * number, we divide the total number of free objects
2862 * by expected stripe count (watch out for overflow).
2864 LOV_SUM_MAX(osfs->os_files, lov_sfs.os_files);
2865 LOV_SUM_MAX(osfs->os_ffree, lov_sfs.os_ffree);
2870 __u32 expected_stripes = lov->desc.ld_default_stripe_count ?
2871 lov->desc.ld_default_stripe_count :
2872 lov->desc.ld_active_tgt_count;
2874 if (osfs->os_files != LOV_U64_MAX)
2875 do_div(osfs->os_files, expected_stripes);
2876 if (osfs->os_ffree != LOV_U64_MAX)
2877 do_div(osfs->os_ffree, expected_stripes);
2884 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
2885 void *karg, void *uarg)
2887 struct obd_device *obddev = class_exp2obd(exp);
2888 struct lov_obd *lov = &obddev->u.lov;
2889 int i, rc, count = lov->desc.ld_tgt_count;
2890 struct obd_uuid *uuidp;
2894 case OBD_IOC_LOV_GET_CONFIG: {
2895 struct obd_ioctl_data *data = karg;
2896 struct lov_tgt_desc *tgtdesc;
2897 struct lov_desc *desc;
2903 if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
2906 data = (struct obd_ioctl_data *)buf;
2908 if (sizeof(*desc) > data->ioc_inllen1) {
2909 obd_ioctl_freedata(buf, len);
2913 if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
2914 obd_ioctl_freedata(buf, len);
2918 if (sizeof(__u32) * count > data->ioc_inllen3) {
2919 obd_ioctl_freedata(buf, len);
2923 desc = (struct lov_desc *)data->ioc_inlbuf1;
2924 memcpy(desc, &(lov->desc), sizeof(*desc));
2926 uuidp = (struct obd_uuid *)data->ioc_inlbuf2;
2927 genp = (__u32 *)data->ioc_inlbuf3;
2928 tgtdesc = lov->tgts;
2929 /* the uuid will be empty for deleted OSTs */
2930 for (i = 0; i < count; i++, uuidp++, genp++, tgtdesc++) {
2931 obd_str2uuid(uuidp, tgtdesc->uuid.uuid);
2932 *genp = tgtdesc->ltd_gen;
2935 rc = copy_to_user((void *)uarg, buf, len);
2938 obd_ioctl_freedata(buf, len);
2941 case LL_IOC_LOV_SETSTRIPE:
2942 rc = lov_setstripe(exp, karg, uarg);
2944 case LL_IOC_LOV_GETSTRIPE:
2945 rc = lov_getstripe(exp, karg, uarg);
2947 case LL_IOC_LOV_SETEA:
2948 rc = lov_setea(exp, karg, uarg);
2955 for (i = 0; i < count; i++) {
2958 /* OST was deleted */
2959 if (obd_uuid_empty(&lov->tgts[i].uuid))
2962 err = obd_iocontrol(cmd, lov->tgts[i].ltd_exp,
2965 if (lov->tgts[i].active) {
2966 CERROR("error: iocontrol OSC %s on OST"
2967 "idx %d: cmd %x err = %d\n",
2968 lov->tgts[i].uuid.uuid, i,
2984 static int lov_get_info(struct obd_export *exp, __u32 keylen,
2985 void *key, __u32 *vallen, void *val)
2987 struct obd_device *obddev = class_exp2obd(exp);
2988 struct lov_obd *lov = &obddev->u.lov;
2992 if (!vallen || !val)
2995 if (keylen > strlen("lock_to_stripe") &&
2996 strcmp(key, "lock_to_stripe") == 0) {
2999 struct ldlm_lock *lock;
3000 struct lov_stripe_md *lsm;
3002 struct lov_oinfo *loi;
3003 struct ldlm_res_id *res_id = &data->lock->l_resource->lr_name;
3004 __u32 *stripe = val;
3006 if (*vallen < sizeof(*stripe))
3008 *vallen = sizeof(*stripe);
3010 /* XXX This is another one of those bits that will need to
3011 * change if we ever actually support nested LOVs. It uses
3012 * the lock's export to find out which stripe it is. */
3013 /* XXX - it's assumed all the locks for deleted OSTs have
3014 * been cancelled. Also, the export for deleted OSTs will
3015 * be NULL and won't match the lock's export. */
3016 for (i = 0, loi = data->lsm->lsm_oinfo;
3017 i < data->lsm->lsm_stripe_count;
3019 if (lov->tgts[loi->loi_ost_idx].ltd_exp ==
3020 data->lock->l_conn_export &&
3021 loi->loi_id == res_id->name[0] &&
3022 loi->loi_gr == res_id->name[2]) {
3027 LDLM_ERROR(data->lock, "lock on inode without such object\n");
3028 dump_lsm(D_ERROR, data->lsm);
3030 } else if (keylen >= strlen("size_to_stripe") &&
3031 strcmp(key, "size_to_stripe") == 0) {
3035 struct lov_stripe_md *lsm;
3038 if (*vallen < sizeof(*data))
3041 data->size = lov_size_to_stripe(data->lsm, data->size,
3042 data->stripe_number);
3044 } else if (keylen >= strlen("last_id") && strcmp(key, "last_id") == 0) {
3046 int rc, size = sizeof(obd_id);
3047 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
3048 if (!lov->tgts[i].active)
3050 rc = obd_get_info(lov->tgts[i].ltd_exp, keylen, key,
3056 } else if (keylen >= strlen("lovdesc") && strcmp(key, "lovdesc") == 0) {
3057 struct lov_desc *desc_ret = val;
3058 *desc_ret = lov->desc;
3066 static int lov_set_info(struct obd_export *exp, obd_count keylen,
3067 void *key, obd_count vallen, void *val)
3069 struct obd_device *obddev = class_exp2obd(exp);
3070 struct lov_obd *lov = &obddev->u.lov;
3074 #define KEY_IS(str) \
3075 (keylen == strlen(str) && memcmp(key, str, keylen) == 0)
3077 if (KEY_IS("next_id")) {
3078 if (vallen != lov->desc.ld_tgt_count)
3080 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
3083 /* OST was deleted */
3084 if (obd_uuid_empty(&lov->tgts[i].uuid))
3087 /* initialize all OSCs, even inactive ones */
3089 er = obd_set_info(lov->tgts[i].ltd_exp, keylen, key,
3090 sizeof(obd_id), ((obd_id*)val) + i);
3096 if (KEY_IS("growth_count")) {
3097 if (vallen != sizeof(int))
3099 } else if (KEY_IS("mds_conn")) {
3100 if (vallen != sizeof(__u32))
3102 } else if (KEY_IS("unlinked") || KEY_IS("unrecovery")) {
3109 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
3112 /* OST was deleted */
3113 if (obd_uuid_empty(&lov->tgts[i].uuid))
3116 if (!val && !lov->tgts[i].active)
3119 er = obd_set_info(lov->tgts[i].ltd_exp, keylen, key, vallen,
3129 /* Merge rss if @kms_only == 0
3131 * Even when merging RSS, we will take the KMS value if it's larger.
3132 * This prevents getattr from stomping on dirty cached pages which
3133 * extend the file size. */
3134 __u64 lov_merge_size(struct lov_stripe_md *lsm, int kms_only)
3136 struct lov_oinfo *loi;
3140 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
3142 obd_size lov_size, tmpsize;
3144 tmpsize = loi->loi_kms;
3145 if (kms_only == 0 && loi->loi_rss > tmpsize)
3146 tmpsize = loi->loi_rss;
3148 lov_size = lov_stripe_size(lsm, tmpsize, i);
3149 if (lov_size > size)
3155 EXPORT_SYMBOL(lov_merge_size);
3158 __u64 lov_merge_blocks(struct lov_stripe_md *lsm)
3160 struct lov_oinfo *loi;
3164 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
3166 blocks += loi->loi_blocks;
3170 EXPORT_SYMBOL(lov_merge_blocks);
3172 __u64 lov_merge_mtime(struct lov_stripe_md *lsm, __u64 current_time)
3174 struct lov_oinfo *loi;
3177 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
3179 if (loi->loi_mtime > current_time)
3180 current_time = loi->loi_mtime;
3182 return current_time;
3184 EXPORT_SYMBOL(lov_merge_mtime);
3187 struct lov_multi_wait {
3188 struct ldlm_lock *lock;
3194 int lov_complete_many(struct obd_export *exp, struct lov_stripe_md *lsm,
3195 struct lustre_handle *lockh)
3197 struct lov_lock_handles *lov_lockh = NULL;
3198 struct lustre_handle *lov_lockhp;
3199 struct lov_obd *lov;
3200 struct lov_oinfo *loi;
3201 struct lov_multi_wait *queues;
3205 if (lsm_bad_magic(lsm))
3208 if (!exp || !exp->exp_obd)
3211 LASSERT(lockh != NULL);
3212 if (lsm->lsm_stripe_count > 1) {
3213 lov_lockh = lov_handle2llh(lockh);
3214 if (lov_lockh == NULL) {
3215 CERROR("LOV: invalid lov lock handle %p\n", lockh);
3219 lov_lockhp = lov_lockh->llh_handles;
3224 OBD_ALLOC(queues, lsm->lsm_stripe_count * sizeof(*queues));
3226 GOTO(out, rc = -ENOMEM);
3228 lov = &exp->exp_obd->u.lov;
3229 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
3230 i++, loi++, lov_lockhp++) {
3231 struct ldlm_lock *lock;
3232 struct obd_device *obd;
3233 unsigned long irqflags;
3235 lock = ldlm_handle2lock(lov_lockhp);
3237 CDEBUG(D_HA, "lov idx %d subobj "LPX64" no lock?\n",
3238 loi->loi_ost_idx, loi->loi_id);
3239 queues[i].completed = 1;
3243 queues[i].lock = lock;
3244 init_waitqueue_entry(&(queues[i].wait), current);
3245 add_wait_queue(lock->l_waitq, &(queues[i].wait));
3247 obd = class_exp2obd(lock->l_conn_export);
3249 imp = obd->u.cli.cl_import;
3251 spin_lock_irqsave(&imp->imp_lock, irqflags);
3252 queues[i].generation = imp->imp_generation;
3253 spin_unlock_irqrestore(&imp->imp_lock, irqflags);
3257 lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, ldlm_expired_completion_wait,
3258 interrupted_completion_wait, &lwd);
3259 rc = l_wait_event_added(check_multi_complete(queues, lsm), &lwi);
3261 for (i = 0; i < lsm->lsm_stripe_count; i++)
3262 remove_wait_queue(lock->l_waitq, &(queues[i].wait));
3264 if (rc == -EINTR || rc == -ETIMEDOUT) {
3270 if (lov_lockh != NULL)
3271 lov_llh_put(lov_lockh);
3276 void lov_increase_kms(struct obd_export *exp, struct lov_stripe_md *lsm,
3279 struct lov_oinfo *loi;
3285 stripe = lov_stripe_number(lsm, size - 1);
3286 kms = lov_size_to_stripe(lsm, size, stripe);
3287 loi = &(lsm->lsm_oinfo[stripe]);
3289 CDEBUG(D_INODE, "stripe %d KMS %sincreasing "LPU64"->"LPU64"\n",
3290 stripe, kms > loi->loi_kms ? "" : "not ", loi->loi_kms, kms);
3291 if (kms > loi->loi_kms)
3295 EXPORT_SYMBOL(lov_increase_kms);
3297 struct obd_ops lov_obd_ops = {
3298 .o_owner = THIS_MODULE,
3299 .o_attach = lov_attach,
3300 .o_detach = lov_detach,
3301 .o_setup = lov_setup,
3302 .o_cleanup = lov_cleanup,
3303 .o_process_config = lov_process_config,
3304 .o_connect = lov_connect,
3305 .o_disconnect = lov_disconnect,
3306 .o_statfs = lov_statfs,
3307 .o_packmd = lov_packmd,
3308 .o_unpackmd = lov_unpackmd,
3309 .o_revalidate_md = lov_revalidate_md,
3310 .o_create = lov_create,
3311 .o_destroy = lov_destroy,
3312 .o_getattr = lov_getattr,
3313 .o_getattr_async = lov_getattr_async,
3314 .o_setattr = lov_setattr,
3316 .o_brw_async = lov_brw_async,
3317 .o_prep_async_page = lov_prep_async_page,
3318 .o_queue_async_io = lov_queue_async_io,
3319 .o_set_async_flags = lov_set_async_flags,
3320 .o_queue_group_io = lov_queue_group_io,
3321 .o_trigger_group_io = lov_trigger_group_io,
3322 .o_teardown_async_page = lov_teardown_async_page,
3323 .o_punch = lov_punch,
3325 .o_enqueue = lov_enqueue,
3326 .o_match = lov_match,
3327 .o_change_cbdata = lov_change_cbdata,
3328 .o_cancel = lov_cancel,
3329 .o_cancel_unused = lov_cancel_unused,
3330 .o_iocontrol = lov_iocontrol,
3331 .o_get_info = lov_get_info,
3332 .o_set_info = lov_set_info,
3333 .o_llog_init = lov_llog_init,
3334 .o_llog_finish = lov_llog_finish,
3335 .o_notify = lov_notify,
3338 int __init lov_init(void)
3340 struct lprocfs_static_vars lvars;
3344 lprocfs_init_vars(lov, &lvars);
3345 rc = class_register_type(&lov_obd_ops, NULL, lvars.module_vars,
3346 OBD_LOV_DEVICENAME);
3351 static void /*__exit*/ lov_exit(void)
3353 class_unregister_type(OBD_LOV_DEVICENAME);
3356 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
3357 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver");
3358 MODULE_LICENSE("GPL");
3360 module_init(lov_init);
3361 module_exit(lov_exit);