1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002-2006 Cluster File Systems, Inc.
5 * Author: Phil Schwan <phil@clusterfs.com>
6 * Peter Braam <braam@clusterfs.com>
7 * Mike Shaver <shaver@clusterfs.com>
8 * Nathan Rutman <nathan@clusterfs.com>
10 * This file is part of the Lustre file system, http://www.lustre.org
11 * Lustre is a trademark of Cluster File Systems, Inc.
13 * You may have signed or agreed to another license before downloading
14 * this software. If so, you are bound by the terms and conditions
15 * of that agreement, and the following does not apply to you. See the
16 * LICENSE file included with this distribution for more information.
18 * If you did not agree to a different license, then this copy of Lustre
19 * is open source software; you can redistribute it and/or modify it
20 * under the terms of version 2 of the GNU General Public License as
21 * published by the Free Software Foundation.
23 * In either case, Lustre is distributed in the hope that it will be
24 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
25 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * license text for more details.
30 # define EXPORT_SYMTAB
32 #define DEBUG_SUBSYSTEM S_LOV
34 #include <libcfs/libcfs.h>
36 #include <liblustre.h>
39 #include <obd_support.h>
40 #include <lustre_lib.h>
41 #include <lustre_net.h>
42 #include <lustre/lustre_idl.h>
43 #include <lustre_dlm.h>
44 #include <lustre_mds.h>
45 #include <lustre_debug.h>
46 #include <obd_class.h>
49 #include <lprocfs_status.h>
50 #include <lustre_param.h>
52 #include "lov_internal.h"
55 /* Keep a refcount of lov->tgt usage to prevent racing with addition/deletion.
56 Any function that expects lov_tgts to remain stationary must take a ref. */
57 void lov_getref(struct obd_device *obd)
59 struct lov_obd *lov = &obd->u.lov;
61 /* nobody gets through here until lov_putref is done */
62 mutex_down(&lov->lov_lock);
63 atomic_inc(&lov->lov_refcount);
64 mutex_up(&lov->lov_lock);
68 static void __lov_del_obd(struct obd_device *obd, __u32 index);
70 void lov_putref(struct obd_device *obd)
72 struct lov_obd *lov = &obd->u.lov;
73 mutex_down(&lov->lov_lock);
74 /* ok to dec to 0 more than once -- ltd_exp's will be null */
75 if (atomic_dec_and_test(&lov->lov_refcount) && lov->lov_death_row) {
77 CDEBUG(D_CONFIG, "destroying %d lov targets\n",
79 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
80 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_reap)
82 /* Disconnect and delete from list */
83 __lov_del_obd(obd, i);
87 mutex_up(&lov->lov_lock);
90 #define MAX_STRING_SIZE 128
91 static int lov_connect_obd(struct obd_device *obd, __u32 index, int activate,
92 struct obd_connect_data *data)
94 struct lov_obd *lov = &obd->u.lov;
95 struct obd_uuid tgt_uuid = lov->lov_tgts[index]->ltd_uuid;
96 struct obd_device *tgt_obd;
97 struct obd_uuid lov_osc_uuid = { "LOV_OSC_UUID" };
98 struct lustre_handle conn = {0, };
99 struct obd_import *imp;
101 cfs_proc_dir_entry_t *lov_proc_dir;
106 if (!lov->lov_tgts[index])
109 tgt_obd = class_find_client_obd(&tgt_uuid, LUSTRE_OSC_NAME,
113 CERROR("Target %s not attached\n", obd_uuid2str(&tgt_uuid));
117 if (!tgt_obd->obd_set_up) {
118 CERROR("Target %s not set up\n", obd_uuid2str(&tgt_uuid));
122 if (data && (data->ocd_connect_flags & OBD_CONNECT_INDEX))
123 data->ocd_index = index;
126 * Divine LOV knows that OBDs under it are OSCs.
128 imp = tgt_obd->u.cli.cl_import;
131 tgt_obd->obd_no_recov = 0;
132 /* FIXME this is probably supposed to be
133 ptlrpc_set_import_active. Horrible naming. */
134 ptlrpc_activate_import(imp);
137 if (imp->imp_invalid) {
138 CERROR("not connecting OSC %s; administratively "
139 "disabled\n", obd_uuid2str(&tgt_uuid));
140 rc = obd_register_observer(tgt_obd, obd);
142 CERROR("Target %s register_observer error %d; "
143 "will not be able to reactivate\n",
144 obd_uuid2str(&tgt_uuid), rc);
149 rc = obd_connect(&conn, tgt_obd, &lov_osc_uuid, data);
151 CERROR("Target %s connect error %d\n",
152 obd_uuid2str(&tgt_uuid), rc);
155 lov->lov_tgts[index]->ltd_exp = class_conn2export(&conn);
156 if (!lov->lov_tgts[index]->ltd_exp) {
157 CERROR("Target %s: null export!\n", obd_uuid2str(&tgt_uuid));
161 rc = obd_register_observer(tgt_obd, obd);
163 CERROR("Target %s register_observer error %d\n",
164 obd_uuid2str(&tgt_uuid), rc);
165 obd_disconnect(lov->lov_tgts[index]->ltd_exp);
166 lov->lov_tgts[index]->ltd_exp = NULL;
170 lov->lov_tgts[index]->ltd_reap = 0;
172 lov->lov_tgts[index]->ltd_active = 1;
173 lov->desc.ld_active_tgt_count++;
175 CDEBUG(D_CONFIG, "Connected tgt idx %d %s (%s) %sactive\n", index,
176 obd_uuid2str(&tgt_uuid), tgt_obd->obd_name, activate ? "":"in");
179 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
181 struct obd_device *osc_obd = class_conn2obd(&conn);
182 cfs_proc_dir_entry_t *osc_symlink;
183 char name[MAX_STRING_SIZE];
185 LASSERT(osc_obd != NULL);
186 LASSERT(osc_obd->obd_magic == OBD_DEVICE_MAGIC);
187 LASSERT(osc_obd->obd_type->typ_name != NULL);
188 snprintf(name, MAX_STRING_SIZE, "../../../%s/%s",
189 osc_obd->obd_type->typ_name,
191 osc_symlink = proc_symlink(osc_obd->obd_name, lov_proc_dir,
193 if (osc_symlink == NULL) {
194 CERROR("could not register LOV target "
195 "/proc/fs/lustre/%s/%s/target_obds/%s.",
196 obd->obd_type->typ_name, obd->obd_name,
198 lprocfs_remove(&lov_proc_dir);
203 rc = qos_add_tgt(obd, index);
205 CERROR("qos_add_tgt failed %d\n", rc);
210 static int lov_connect(struct lustre_handle *conn, struct obd_device *obd,
211 struct obd_uuid *cluuid, struct obd_connect_data *data)
213 struct lov_obd *lov = &obd->u.lov;
214 struct lov_tgt_desc *tgt;
218 CDEBUG(D_CONFIG, "connect #%d\n", lov->lov_connects);
220 rc = class_connect(conn, obd, cluuid);
224 /* Why should there ever be more than 1 connect? */
226 LASSERT(lov->lov_connects == 1);
228 memset(&lov->lov_ocd, 0, sizeof(lov->lov_ocd));
230 lov->lov_ocd = *data;
233 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
234 tgt = lov->lov_tgts[i];
235 if (!tgt || obd_uuid_empty(&tgt->ltd_uuid))
237 /* Flags will be lowest common denominator */
238 rc = lov_connect_obd(obd, i, lov->lov_tgts[i]->ltd_activate,
241 CERROR("%s: lov connect tgt %d failed: %d\n",
242 obd->obd_name, i, rc);
251 static int lov_disconnect_obd(struct obd_device *obd, __u32 index)
253 cfs_proc_dir_entry_t *lov_proc_dir;
254 struct lov_obd *lov = &obd->u.lov;
255 struct obd_device *osc_obd =
256 class_exp2obd(lov->lov_tgts[index]->ltd_exp);
260 CDEBUG(D_CONFIG, "%s: disconnecting target %s\n",
261 obd->obd_name, osc_obd->obd_name);
263 if (lov->lov_tgts[index]->ltd_active) {
264 lov->lov_tgts[index]->ltd_active = 0;
265 lov->desc.ld_active_tgt_count--;
268 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
270 cfs_proc_dir_entry_t *osc_symlink;
272 osc_symlink = lprocfs_srch(lov_proc_dir, osc_obd->obd_name);
274 lprocfs_remove(&osc_symlink);
276 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing.",
277 obd->obd_type->typ_name, obd->obd_name,
282 if (obd->obd_no_recov) {
283 /* Pass it on to our clients.
284 * XXX This should be an argument to disconnect,
285 * XXX not a back-door flag on the OBD. Ah well.
288 osc_obd->obd_no_recov = 1;
291 obd_register_observer(osc_obd, NULL);
293 rc = obd_disconnect(lov->lov_tgts[index]->ltd_exp);
295 CERROR("Target %s disconnect error %d\n",
296 lov_uuid2str(lov, index), rc);
300 qos_del_tgt(obd, index);
302 lov->lov_tgts[index]->ltd_exp = NULL;
306 static int lov_del_target(struct obd_device *obd, __u32 index,
307 struct obd_uuid *uuidp, int gen);
309 static int lov_disconnect(struct obd_export *exp)
311 struct obd_device *obd = class_exp2obd(exp);
312 struct lov_obd *lov = &obd->u.lov;
319 /* Only disconnect the underlying layers on the final disconnect. */
321 if (lov->lov_connects != 0) {
322 /* why should there be more than 1 connect? */
323 CERROR("disconnect #%d\n", lov->lov_connects);
327 /* Let's hold another reference so lov_del_obd doesn't spin through
330 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
331 if (lov->lov_tgts[i] && lov->lov_tgts[i]->ltd_exp) {
332 /* Disconnection is the last we know about an obd */
333 lov_del_target(obd, i, 0, lov->lov_tgts[i]->ltd_gen);
339 rc = class_disconnect(exp); /* bz 9811 */
345 * -EINVAL : UUID can't be found in the LOV's target list
346 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
347 * -EBADF : The UUID is found, but the OBD is the wrong type (!)
349 static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
352 struct lov_obd *lov = &obd->u.lov;
353 struct lov_tgt_desc *tgt;
357 CDEBUG(D_INFO, "Searching in lov %p for uuid %s (activate=%d)\n",
358 lov, uuid->uuid, activate);
361 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
362 tgt = lov->lov_tgts[i];
363 if (!tgt || !tgt->ltd_exp)
366 CDEBUG(D_INFO, "lov idx %d is %s conn "LPX64"\n",
367 i, obd_uuid2str(&tgt->ltd_uuid),
368 tgt->ltd_exp->exp_handle.h_cookie);
369 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
373 if (i == lov->desc.ld_tgt_count)
374 GOTO(out, rc = -EINVAL);
376 if (lov->lov_tgts[i]->ltd_active == activate) {
377 CDEBUG(D_INFO, "OSC %s already %sactive!\n", uuid->uuid,
378 activate ? "" : "in");
382 CDEBUG(D_CONFIG, "Marking OSC %s %sactive\n", obd_uuid2str(uuid),
383 activate ? "" : "in");
385 lov->lov_tgts[i]->ltd_active = activate;
387 lov->desc.ld_active_tgt_count++;
389 lov->desc.ld_active_tgt_count--;
390 /* remove any old qos penalty */
391 lov->lov_tgts[i]->ltd_qos.ltq_penalty = 0;
398 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
399 enum obd_notify_event ev, void *data)
404 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
405 struct obd_uuid *uuid;
409 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
410 CERROR("unexpected notification of %s %s!\n",
411 watched->obd_type->typ_name,
415 uuid = &watched->u.cli.cl_target_uuid;
417 /* Set OSC as active before notifying the observer, so the
418 * observer can use the OSC normally.
420 rc = lov_set_osc_active(obd, uuid, ev == OBD_NOTIFY_ACTIVE);
422 CERROR("%sactivation of %s failed: %d\n",
423 (ev == OBD_NOTIFY_ACTIVE) ? "" : "de",
424 obd_uuid2str(uuid), rc);
429 /* Pass the notification up the chain. */
431 rc = obd_notify_observer(obd, watched, ev, data);
433 /* NULL watched means all osc's in the lov (only for syncs) */
434 struct lov_obd *lov = &obd->u.lov;
435 struct obd_device *tgt_obd;
438 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
439 if (!lov->lov_tgts[i])
441 tgt_obd = class_exp2obd(lov->lov_tgts[i]->ltd_exp);
442 rc = obd_notify_observer(obd, tgt_obd, ev, data);
444 CERROR("%s: notify %s of %s failed %d\n",
446 obd->obd_observer->obd_name,
447 tgt_obd->obd_name, rc);
457 static int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
458 __u32 index, int gen, int active)
460 struct lov_obd *lov = &obd->u.lov;
461 struct lov_tgt_desc *tgt;
465 CDEBUG(D_CONFIG, "uuid:%s idx:%d gen:%d active:%d\n",
466 uuidp->uuid, index, gen, active);
469 CERROR("request to add OBD %s with invalid generation: %d\n",
474 mutex_down(&lov->lov_lock);
476 if ((index < lov->lov_tgt_size) && (lov->lov_tgts[index] != NULL)) {
477 tgt = lov->lov_tgts[index];
478 CERROR("UUID %s already assigned at LOV target index %d\n",
479 obd_uuid2str(&tgt->ltd_uuid), index);
480 mutex_up(&lov->lov_lock);
484 if (index >= lov->lov_tgt_size) {
485 /* We need to reallocate the lov target array. */
486 struct lov_tgt_desc **newtgts, **old = NULL;
487 __u32 newsize, oldsize = 0;
489 newsize = max(lov->lov_tgt_size, (__u32)2);
490 while (newsize < index + 1)
491 newsize = newsize << 1;
492 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
493 if (newtgts == NULL) {
494 mutex_up(&lov->lov_lock);
498 if (lov->lov_tgt_size) {
499 memcpy(newtgts, lov->lov_tgts, sizeof(*newtgts) *
502 oldsize = lov->lov_tgt_size;
505 lov->lov_tgts = newtgts;
506 lov->lov_tgt_size = newsize;
511 OBD_FREE(old, sizeof(*old) * oldsize);
513 CDEBUG(D_CONFIG, "tgts: %p size: %d\n",
514 lov->lov_tgts, lov->lov_tgt_size);
520 mutex_up(&lov->lov_lock);
524 memset(tgt, 0, sizeof(*tgt));
525 tgt->ltd_uuid = *uuidp;
526 /* XXX - add a sanity check on the generation number. */
528 tgt->ltd_index = index;
529 tgt->ltd_activate = active;
530 lov->lov_tgts[index] = tgt;
531 if (index >= lov->desc.ld_tgt_count)
532 lov->desc.ld_tgt_count = index + 1;
533 mutex_up(&lov->lov_lock);
535 CDEBUG(D_CONFIG, "idx=%d ltd_gen=%d ld_tgt_count=%d\n",
536 index, tgt->ltd_gen, lov->desc.ld_tgt_count);
538 if (lov->lov_connects == 0) {
539 /* lov_connect hasn't been called yet. We'll do the
540 lov_connect_obd on this target when that fn first runs,
541 because we don't know the connect flags yet. */
547 rc = lov_connect_obd(obd, index, active, &lov->lov_ocd);
551 rc = lov_notify(obd, tgt->ltd_exp->exp_obd,
552 active ? OBD_NOTIFY_ACTIVE : OBD_NOTIFY_INACTIVE,
557 CERROR("add failed (%d), deleting %s\n", rc,
558 obd_uuid2str(&tgt->ltd_uuid));
559 lov_del_target(obd, index, 0, 0);
565 /* Schedule a target for deletion */
566 static int lov_del_target(struct obd_device *obd, __u32 index,
567 struct obd_uuid *uuidp, int gen)
569 struct lov_obd *lov = &obd->u.lov;
570 int count = lov->desc.ld_tgt_count;
574 if (index >= count) {
575 CERROR("LOV target index %d >= number of LOV OBDs %d.\n",
582 if (!lov->lov_tgts[index]) {
583 CERROR("LOV target at index %d is not setup.\n", index);
584 GOTO(out, rc = -EINVAL);
587 if (uuidp && !obd_uuid_equals(uuidp, &lov->lov_tgts[index]->ltd_uuid)) {
588 CERROR("LOV target UUID %s at index %d doesn't match %s.\n",
589 lov_uuid2str(lov, index), index,
590 obd_uuid2str(uuidp));
591 GOTO(out, rc = -EINVAL);
594 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d exp: %p active: %d\n",
595 lov_uuid2str(lov, index), index,
596 lov->lov_tgts[index]->ltd_gen, lov->lov_tgts[index]->ltd_exp,
597 lov->lov_tgts[index]->ltd_active);
599 lov->lov_tgts[index]->ltd_reap = 1;
600 lov->lov_death_row++;
601 /* we really delete it from lov_putref */
608 /* We are holding lov_lock */
609 static void __lov_del_obd(struct obd_device *obd, __u32 index)
611 struct lov_obd *lov = &obd->u.lov;
612 struct obd_device *osc_obd;
613 struct lov_tgt_desc *tgt = lov->lov_tgts[index];
616 LASSERT(tgt->ltd_reap);
618 osc_obd = class_exp2obd(tgt->ltd_exp);
620 CDEBUG(D_CONFIG, "Removing tgt %s : %s\n",
621 lov_uuid2str(lov, index),
622 osc_obd ? osc_obd->obd_name : "<no obd>");
625 lov_disconnect_obd(obd, index);
627 /* XXX - right now there is a dependency on ld_tgt_count being the
628 * maximum tgt index for computing the mds_max_easize. So we can't
631 lov->lov_tgts[index] = NULL;
634 /* Manual cleanup - no cleanup logs to clean up the osc's. We must
635 do it ourselves. And we can't do it from lov_cleanup,
636 because we just lost our only reference to it. */
638 /* Use lov's force/fail flags. */
639 osc_obd->obd_force = obd->obd_force;
640 osc_obd->obd_fail = obd->obd_fail;
641 class_manual_cleanup(osc_obd);
645 void lov_fix_desc(struct lov_desc *desc)
647 if (desc->ld_default_stripe_size < PTLRPC_MAX_BRW_SIZE) {
648 LCONSOLE_WARN("Increasing default stripe size to min %u\n",
649 PTLRPC_MAX_BRW_SIZE);
650 desc->ld_default_stripe_size = PTLRPC_MAX_BRW_SIZE;
651 } else if (desc->ld_default_stripe_size & (LOV_MIN_STRIPE_SIZE - 1)) {
652 desc->ld_default_stripe_size &= ~(LOV_MIN_STRIPE_SIZE - 1);
653 LCONSOLE_WARN("Changing default stripe size to "LPU64" (a "
655 desc->ld_default_stripe_size,LOV_MIN_STRIPE_SIZE);
658 if (desc->ld_default_stripe_count == 0)
659 desc->ld_default_stripe_count = 1;
661 /* from lov_setstripe */
662 if ((desc->ld_pattern != 0) &&
663 (desc->ld_pattern != LOV_PATTERN_RAID0)) {
664 LCONSOLE_WARN("Unknown stripe pattern: %#x\n",desc->ld_pattern);
665 desc->ld_pattern = 0;
668 if (desc->ld_qos_maxage == 0)
669 desc->ld_qos_maxage = QOS_DEFAULT_MAXAGE;
672 static int lov_setup(struct obd_device *obd, obd_count len, void *buf)
674 struct lprocfs_static_vars lvars;
675 struct lustre_cfg *lcfg = buf;
676 struct lov_desc *desc;
677 struct lov_obd *lov = &obd->u.lov;
681 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
682 CERROR("LOV setup requires a descriptor\n");
686 desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
688 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
689 CERROR("descriptor size wrong: %d > %d\n",
690 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
694 if (desc->ld_magic != LOV_DESC_MAGIC) {
695 if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
696 CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n",
697 obd->obd_name, desc);
698 lustre_swab_lov_desc(desc);
700 CERROR("%s: Bad lov desc magic: %#x\n",
701 obd->obd_name, desc->ld_magic);
708 /* Because of 64-bit divide/mod operations only work with a 32-bit
709 * divisor in a 32-bit kernel, we cannot support a stripe width
710 * of 4GB or larger on 32-bit CPUs. */
711 count = desc->ld_default_stripe_count;
712 if ((count > 0 ? count : desc->ld_tgt_count) *
713 desc->ld_default_stripe_size > 0xffffffff) {
714 CERROR("LOV: stripe width "LPU64"x%u > 4294967295 bytes\n",
715 desc->ld_default_stripe_size, count);
719 desc->ld_active_tgt_count = 0;
721 lov->lov_tgt_size = 0;
722 sema_init(&lov->lov_lock, 1);
723 atomic_set(&lov->lov_refcount, 0);
724 INIT_LIST_HEAD(&lov->lov_qos.lq_oss_list);
725 init_rwsem(&lov->lov_qos.lq_rw_sem);
726 lov->lov_qos.lq_dirty = 1;
727 lov->lov_qos.lq_dirty_rr = 1;
728 lov->lov_qos.lq_reset = 1;
729 /* Default priority is toward free space balance */
730 lov->lov_qos.lq_prio_free = 232;
732 lprocfs_init_vars(lov, &lvars);
733 lprocfs_obd_setup(obd, lvars.obd_vars);
736 cfs_proc_dir_entry_t *entry;
738 entry = create_proc_entry("target_obd", 0444,
739 obd->obd_proc_entry);
741 entry->proc_fops = &lov_proc_target_fops;
750 static int lov_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
756 case OBD_CLEANUP_EARLY: {
757 struct lov_obd *lov = &obd->u.lov;
759 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
760 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
762 obd_precleanup(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
767 case OBD_CLEANUP_EXPORTS:
769 case OBD_CLEANUP_SELF_EXP:
770 rc = obd_llog_finish(obd, 0);
772 CERROR("failed to cleanup llogging subsystems\n");
774 case OBD_CLEANUP_OBD:
780 static int lov_cleanup(struct obd_device *obd)
782 struct lov_obd *lov = &obd->u.lov;
784 lprocfs_obd_cleanup(obd);
787 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
788 if (lov->lov_tgts[i]) {
789 /* Inactive targets may never have connected */
790 if (lov->lov_tgts[i]->ltd_active ||
791 atomic_read(&lov->lov_refcount))
792 /* We should never get here - these
793 should have been removed in the
795 CERROR("lov tgt %d not cleaned!"
796 " deathrow=%d, lovrc=%d\n",
797 i, lov->lov_death_row,
798 atomic_read(&lov->lov_refcount));
799 lov_del_target(obd, i, 0, 0);
802 OBD_FREE(lov->lov_tgts, sizeof(*lov->lov_tgts) *
804 lov->lov_tgt_size = 0;
807 if (lov->lov_qos.lq_rr_size)
808 OBD_FREE(lov->lov_qos.lq_rr_array, lov->lov_qos.lq_rr_size);
813 static int lov_process_config(struct obd_device *obd, obd_count len, void *buf)
815 struct lustre_cfg *lcfg = buf;
816 struct obd_uuid obd_uuid;
821 switch(cmd = lcfg->lcfg_command) {
822 case LCFG_LOV_ADD_OBD:
823 case LCFG_LOV_ADD_INA:
824 case LCFG_LOV_DEL_OBD: {
827 /* lov_modify_tgts add 0:lov_mdsA 1:ost1_UUID 2:0 3:1 */
828 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
829 GOTO(out, rc = -EINVAL);
831 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
833 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
834 GOTO(out, rc = -EINVAL);
835 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
836 GOTO(out, rc = -EINVAL);
837 if (cmd == LCFG_LOV_ADD_OBD)
838 rc = lov_add_target(obd, &obd_uuid, index, gen, 1);
839 else if (cmd == LCFG_LOV_ADD_INA)
840 rc = lov_add_target(obd, &obd_uuid, index, gen, 0);
842 rc = lov_del_target(obd, index, &obd_uuid, gen);
846 struct lprocfs_static_vars lvars;
847 struct lov_desc *desc = &(obd->u.lov.desc);
850 GOTO(out, rc = -EINVAL);
852 lprocfs_init_vars(lov, &lvars);
854 rc = class_process_proc_param(PARAM_LOV, lvars.obd_vars,
859 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
860 GOTO(out, rc = -EINVAL);
869 #define log2(n) ffz(~(n))
872 static int lov_clear_orphans(struct obd_export *export, struct obdo *src_oa,
873 struct lov_stripe_md **ea,
874 struct obd_trans_info *oti)
878 struct obd_uuid *ost_uuid = NULL;
882 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
883 src_oa->o_flags == OBD_FL_DELORPHAN);
885 lov = &export->exp_obd->u.lov;
887 tmp_oa = obdo_alloc();
891 if (src_oa->o_valid & OBD_MD_FLINLINE) {
892 ost_uuid = (struct obd_uuid *)src_oa->o_inline;
893 CDEBUG(D_HA, "clearing orphans only for %s\n",
897 lov_getref(export->exp_obd);
898 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
899 struct lov_stripe_md obj_md;
900 struct lov_stripe_md *obj_mdp = &obj_md;
901 struct lov_tgt_desc *tgt;
904 tgt = lov->lov_tgts[i];
908 /* if called for a specific target, we don't
909 care if it is not active. */
910 if (!lov->lov_tgts[i]->ltd_active == 0 && ost_uuid == NULL) {
911 CDEBUG(D_HA, "lov idx %d inactive\n", i);
915 if (ost_uuid && !obd_uuid_equals(ost_uuid, &tgt->ltd_uuid))
918 CDEBUG(D_CONFIG,"Clear orphans for %d:%s\n", i,
919 obd_uuid2str(ost_uuid));
921 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
923 LASSERT(lov->lov_tgts[i]->ltd_exp);
924 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
925 err = obd_create(lov->lov_tgts[i]->ltd_exp,
926 tmp_oa, &obj_mdp, oti);
928 /* This export will be disabled until it is recovered,
929 and then orphan recovery will be completed. */
930 CERROR("error in orphan recovery on OST idx %d/%d: "
931 "rc = %d\n", i, lov->desc.ld_tgt_count, err);
936 lov_putref(export->exp_obd);
942 static int lov_recreate(struct obd_export *exp, struct obdo *src_oa,
943 struct lov_stripe_md **ea, struct obd_trans_info *oti)
945 struct lov_stripe_md *obj_mdp, *lsm;
946 struct lov_obd *lov = &exp->exp_obd->u.lov;
951 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
952 src_oa->o_flags & OBD_FL_RECREATE_OBJS);
954 OBD_ALLOC(obj_mdp, sizeof(*obj_mdp));
958 ost_idx = src_oa->o_nlink;
961 GOTO(out, rc = -EINVAL);
962 if (ost_idx >= lov->desc.ld_tgt_count ||
963 !lov->lov_tgts[ost_idx])
964 GOTO(out, rc = -EINVAL);
966 for (i = 0; i < lsm->lsm_stripe_count; i++) {
967 if (lsm->lsm_oinfo[i]->loi_ost_idx == ost_idx) {
968 if (lsm->lsm_oinfo[i]->loi_id != src_oa->o_id)
969 GOTO(out, rc = -EINVAL);
973 if (i == lsm->lsm_stripe_count)
974 GOTO(out, rc = -EINVAL);
976 rc = obd_create(lov->lov_tgts[ost_idx]->ltd_exp, src_oa, &obj_mdp, oti);
978 OBD_FREE(obj_mdp, sizeof(*obj_mdp));
982 /* the LOV expects oa->o_id to be set to the LOV object id */
983 static int lov_create(struct obd_export *exp, struct obdo *src_oa,
984 struct lov_stripe_md **ea, struct obd_trans_info *oti)
987 struct obd_info oinfo;
988 struct lov_request_set *set = NULL;
989 struct lov_request *req;
990 struct obd_statfs osfs;
999 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1000 src_oa->o_flags == OBD_FL_DELORPHAN) {
1001 rc = lov_clear_orphans(exp, src_oa, ea, oti);
1005 lov = &exp->exp_obd->u.lov;
1006 if (!lov->desc.ld_active_tgt_count)
1009 /* Recreate a specific object id at the given OST index */
1010 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1011 (src_oa->o_flags & OBD_FL_RECREATE_OBJS)) {
1012 rc = lov_recreate(exp, src_oa, ea, oti);
1016 maxage = cfs_time_shift_64(-lov->desc.ld_qos_maxage);
1017 obd_statfs_rqset(exp->exp_obd, &osfs, maxage);
1019 rc = lov_prep_create_set(exp, &oinfo, ea, src_oa, oti, &set);
1023 list_for_each_entry(req, &set->set_list, rq_link) {
1024 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1025 rc = obd_create(lov->lov_tgts[req->rq_idx]->ltd_exp,
1026 req->rq_oi.oi_oa, &req->rq_oi.oi_md, oti);
1027 lov_update_create_set(set, req, rc);
1029 rc = lov_fini_create_set(set, ea);
1033 #define ASSERT_LSM_MAGIC(lsmp) \
1035 LASSERT((lsmp) != NULL); \
1036 LASSERTF(((lsmp)->lsm_magic == LOV_MAGIC || \
1037 (lsmp)->lsm_magic == LOV_MAGIC_JOIN), "%p->lsm_magic=%x\n", \
1038 (lsmp), (lsmp)->lsm_magic); \
1041 static int lov_destroy(struct obd_export *exp, struct obdo *oa,
1042 struct lov_stripe_md *lsm, struct obd_trans_info *oti,
1043 struct obd_export *md_exp)
1045 struct lov_request_set *set;
1046 struct obd_info oinfo;
1047 struct lov_request *req;
1048 struct list_head *pos;
1049 struct lov_obd *lov;
1053 ASSERT_LSM_MAGIC(lsm);
1055 if (!exp || !exp->exp_obd)
1058 if (oa->o_valid & OBD_MD_FLCOOKIE) {
1060 LASSERT(oti->oti_logcookies);
1063 lov = &exp->exp_obd->u.lov;
1064 rc = lov_prep_destroy_set(exp, &oinfo, oa, lsm, oti, &set);
1068 list_for_each (pos, &set->set_list) {
1070 req = list_entry(pos, struct lov_request, rq_link);
1072 if (oa->o_valid & OBD_MD_FLCOOKIE)
1073 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1075 err = obd_destroy(lov->lov_tgts[req->rq_idx]->ltd_exp,
1076 req->rq_oi.oi_oa, NULL, oti, NULL);
1077 err = lov_update_common_set(set, req, err);
1079 CERROR("error: destroying objid "LPX64" subobj "
1080 LPX64" on OST idx %d: rc = %d\n",
1081 oa->o_id, req->rq_oi.oi_oa->o_id,
1089 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
1090 rc = lsm_op_find(lsm->lsm_magic)->lsm_destroy(lsm, oa, md_exp);
1092 err = lov_fini_destroy_set(set);
1093 RETURN(rc ? rc : err);
1096 static int lov_getattr(struct obd_export *exp, struct obd_info *oinfo)
1098 struct lov_request_set *set;
1099 struct lov_request *req;
1100 struct list_head *pos;
1101 struct lov_obd *lov;
1102 int err = 0, rc = 0;
1106 ASSERT_LSM_MAGIC(oinfo->oi_md);
1108 if (!exp || !exp->exp_obd)
1111 lov = &exp->exp_obd->u.lov;
1113 rc = lov_prep_getattr_set(exp, oinfo, &set);
1117 list_for_each (pos, &set->set_list) {
1118 req = list_entry(pos, struct lov_request, rq_link);
1120 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1121 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1122 req->rq_oi.oi_oa->o_id, req->rq_idx);
1124 rc = obd_getattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1126 err = lov_update_common_set(set, req, rc);
1128 CERROR("error: getattr objid "LPX64" subobj "
1129 LPX64" on OST idx %d: rc = %d\n",
1130 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1136 rc = lov_fini_getattr_set(set);
1142 static int lov_getattr_interpret(struct ptlrpc_request_set *rqset,
1145 struct lov_request_set *lovset = (struct lov_request_set *)data;
1149 /* don't do attribute merge if this aysnc op failed */
1151 lovset->set_completes = 0;
1152 err = lov_fini_getattr_set(lovset);
1153 RETURN(rc ? rc : err);
1156 static int lov_getattr_async(struct obd_export *exp, struct obd_info *oinfo,
1157 struct ptlrpc_request_set *rqset)
1159 struct lov_request_set *lovset;
1160 struct lov_obd *lov;
1161 struct list_head *pos;
1162 struct lov_request *req;
1167 ASSERT_LSM_MAGIC(oinfo->oi_md);
1169 if (!exp || !exp->exp_obd)
1172 lov = &exp->exp_obd->u.lov;
1174 rc = lov_prep_getattr_set(exp, oinfo, &lovset);
1178 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1179 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1180 oinfo->oi_md->lsm_stripe_size);
1182 list_for_each (pos, &lovset->set_list) {
1183 req = list_entry(pos, struct lov_request, rq_link);
1185 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1186 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1187 req->rq_oi.oi_oa->o_id, req->rq_idx);
1188 rc = obd_getattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1189 &req->rq_oi, rqset);
1191 CERROR("error: getattr objid "LPX64" subobj "
1192 LPX64" on OST idx %d: rc = %d\n",
1193 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1199 if (!list_empty(&rqset->set_requests)) {
1201 LASSERT (rqset->set_interpret == NULL);
1202 rqset->set_interpret = lov_getattr_interpret;
1203 rqset->set_arg = (void *)lovset;
1208 lovset->set_completes = 0;
1209 err = lov_fini_getattr_set(lovset);
1210 RETURN(rc ? rc : err);
1213 static int lov_setattr(struct obd_export *exp, struct obd_info *oinfo,
1214 struct obd_trans_info *oti)
1216 struct lov_request_set *set;
1217 struct lov_obd *lov;
1218 struct list_head *pos;
1219 struct lov_request *req;
1220 int err = 0, rc = 0;
1224 ASSERT_LSM_MAGIC(oinfo->oi_md);
1226 if (!exp || !exp->exp_obd)
1229 /* for now, we only expect the following updates here */
1230 LASSERT(!(oinfo->oi_oa->o_valid & ~(OBD_MD_FLID | OBD_MD_FLTYPE |
1231 OBD_MD_FLMODE | OBD_MD_FLATIME |
1232 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1233 OBD_MD_FLFLAGS | OBD_MD_FLSIZE |
1234 OBD_MD_FLGROUP | OBD_MD_FLUID |
1235 OBD_MD_FLGID | OBD_MD_FLINLINE |
1236 OBD_MD_FLFID | OBD_MD_FLGENER)));
1237 lov = &exp->exp_obd->u.lov;
1238 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1242 list_for_each (pos, &set->set_list) {
1243 req = list_entry(pos, struct lov_request, rq_link);
1245 rc = obd_setattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1247 err = lov_update_setattr_set(set, req, rc);
1249 CERROR("error: setattr objid "LPX64" subobj "
1250 LPX64" on OST idx %d: rc = %d\n",
1251 set->set_oi->oi_oa->o_id,
1252 req->rq_oi.oi_oa->o_id, req->rq_idx, err);
1257 err = lov_fini_setattr_set(set);
1263 static int lov_setattr_interpret(struct ptlrpc_request_set *rqset,
1266 struct lov_request_set *lovset = (struct lov_request_set *)data;
1271 lovset->set_completes = 0;
1272 err = lov_fini_setattr_set(lovset);
1273 RETURN(rc ? rc : err);
1276 /* If @oti is given, the request goes from MDS and responses from OSTs are not
1277 needed. Otherwise, a client is waiting for responses. */
1278 static int lov_setattr_async(struct obd_export *exp, struct obd_info *oinfo,
1279 struct obd_trans_info *oti,
1280 struct ptlrpc_request_set *rqset)
1282 struct lov_request_set *set;
1283 struct lov_request *req;
1284 struct list_head *pos;
1285 struct lov_obd *lov;
1290 ASSERT_LSM_MAGIC(oinfo->oi_md);
1291 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE) {
1293 LASSERT(oti->oti_logcookies);
1296 if (!exp || !exp->exp_obd)
1299 lov = &exp->exp_obd->u.lov;
1300 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1304 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1305 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1306 oinfo->oi_md->lsm_stripe_size);
1308 list_for_each (pos, &set->set_list) {
1309 req = list_entry(pos, struct lov_request, rq_link);
1311 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
1312 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1314 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1315 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1316 req->rq_oi.oi_oa->o_id, req->rq_idx);
1318 rc = obd_setattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1319 &req->rq_oi, oti, rqset);
1321 CERROR("error: setattr objid "LPX64" subobj "
1322 LPX64" on OST idx %d: rc = %d\n",
1323 set->set_oi->oi_oa->o_id,
1324 req->rq_oi.oi_oa->o_id,
1330 /* If we are not waiting for responses on async requests, return. */
1331 if (rc || !rqset || list_empty(&rqset->set_requests)) {
1334 set->set_completes = 0;
1335 err = lov_fini_setattr_set(set);
1336 RETURN(rc ? rc : err);
1339 LASSERT(rqset->set_interpret == NULL);
1340 rqset->set_interpret = lov_setattr_interpret;
1341 rqset->set_arg = (void *)set;
1346 static int lov_punch_interpret(struct ptlrpc_request_set *rqset,
1349 struct lov_request_set *lovset = (struct lov_request_set *)data;
1354 lovset->set_completes = 0;
1355 err = lov_fini_punch_set(lovset);
1356 RETURN(rc ? rc : err);
1359 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
1360 * we can send this 'punch' to just the authoritative node and the nodes
1361 * that the punch will affect. */
1362 static int lov_punch(struct obd_export *exp, struct obd_info *oinfo,
1363 struct obd_trans_info *oti,
1364 struct ptlrpc_request_set *rqset)
1366 struct lov_request_set *set;
1367 struct lov_obd *lov;
1368 struct list_head *pos;
1369 struct lov_request *req;
1374 ASSERT_LSM_MAGIC(oinfo->oi_md);
1376 if (!exp || !exp->exp_obd)
1379 lov = &exp->exp_obd->u.lov;
1380 rc = lov_prep_punch_set(exp, oinfo, oti, &set);
1384 list_for_each (pos, &set->set_list) {
1385 req = list_entry(pos, struct lov_request, rq_link);
1387 rc = obd_punch(lov->lov_tgts[req->rq_idx]->ltd_exp,
1388 &req->rq_oi, NULL, rqset);
1390 CERROR("error: punch objid "LPX64" subobj "LPX64
1391 " on OST idx %d: rc = %d\n",
1392 set->set_oi->oi_oa->o_id,
1393 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1398 if (rc || list_empty(&rqset->set_requests)) {
1400 err = lov_fini_punch_set(set);
1401 RETURN(rc ? rc : err);
1404 LASSERT(rqset->set_interpret == NULL);
1405 rqset->set_interpret = lov_punch_interpret;
1406 rqset->set_arg = (void *)set;
1411 static int lov_sync(struct obd_export *exp, struct obdo *oa,
1412 struct lov_stripe_md *lsm, obd_off start, obd_off end)
1414 struct lov_request_set *set;
1415 struct obd_info oinfo;
1416 struct lov_obd *lov;
1417 struct list_head *pos;
1418 struct lov_request *req;
1419 int err = 0, rc = 0;
1422 ASSERT_LSM_MAGIC(lsm);
1427 lov = &exp->exp_obd->u.lov;
1428 rc = lov_prep_sync_set(exp, &oinfo, oa, lsm, start, end, &set);
1432 list_for_each (pos, &set->set_list) {
1433 req = list_entry(pos, struct lov_request, rq_link);
1435 rc = obd_sync(lov->lov_tgts[req->rq_idx]->ltd_exp,
1436 req->rq_oi.oi_oa, NULL,
1437 req->rq_oi.oi_policy.l_extent.start,
1438 req->rq_oi.oi_policy.l_extent.end);
1439 err = lov_update_common_set(set, req, rc);
1441 CERROR("error: fsync objid "LPX64" subobj "LPX64
1442 " on OST idx %d: rc = %d\n",
1443 set->set_oi->oi_oa->o_id,
1444 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1449 err = lov_fini_sync_set(set);
1455 static int lov_brw_check(struct lov_obd *lov, struct obd_info *lov_oinfo,
1456 obd_count oa_bufs, struct brw_page *pga)
1458 struct obd_info oinfo = { { { 0 } } };
1461 oinfo.oi_oa = lov_oinfo->oi_oa;
1463 /* The caller just wants to know if there's a chance that this
1464 * I/O can succeed */
1465 for (i = 0; i < oa_bufs; i++) {
1466 int stripe = lov_stripe_number(lov_oinfo->oi_md, pga[i].off);
1467 int ost = lov_oinfo->oi_md->lsm_oinfo[stripe]->loi_ost_idx;
1470 if (!lov_stripe_intersects(lov_oinfo->oi_md, i, pga[i].off,
1471 pga[i].off + pga[i].count,
1475 if (!lov->lov_tgts[ost] || !lov->lov_tgts[ost]->ltd_active) {
1476 CDEBUG(D_HA, "lov idx %d inactive\n", ost);
1480 rc = obd_brw(OBD_BRW_CHECK, lov->lov_tgts[ost]->ltd_exp, &oinfo,
1488 static int lov_brw(int cmd, struct obd_export *exp, struct obd_info *oinfo,
1489 obd_count oa_bufs, struct brw_page *pga,
1490 struct obd_trans_info *oti)
1492 struct lov_request_set *set;
1493 struct lov_request *req;
1494 struct list_head *pos;
1495 struct lov_obd *lov = &exp->exp_obd->u.lov;
1499 ASSERT_LSM_MAGIC(oinfo->oi_md);
1501 if (cmd == OBD_BRW_CHECK) {
1502 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1506 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &set);
1510 list_for_each (pos, &set->set_list) {
1511 struct obd_export *sub_exp;
1512 struct brw_page *sub_pga;
1513 req = list_entry(pos, struct lov_request, rq_link);
1515 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1516 sub_pga = set->set_pga + req->rq_pgaidx;
1517 rc = obd_brw(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1521 lov_update_common_set(set, req, rc);
1524 err = lov_fini_brw_set(set);
1530 static int lov_brw_interpret(struct ptlrpc_request_set *reqset, void *data,
1533 struct lov_request_set *lovset = (struct lov_request_set *)data;
1537 lovset->set_completes = 0;
1538 lov_fini_brw_set(lovset);
1540 rc = lov_fini_brw_set(lovset);
1546 static int lov_brw_async(int cmd, struct obd_export *exp,
1547 struct obd_info *oinfo, obd_count oa_bufs,
1548 struct brw_page *pga, struct obd_trans_info *oti,
1549 struct ptlrpc_request_set *set)
1551 struct lov_request_set *lovset;
1552 struct lov_request *req;
1553 struct list_head *pos;
1554 struct lov_obd *lov = &exp->exp_obd->u.lov;
1559 ASSERT_LSM_MAGIC(oinfo->oi_md);
1561 if (cmd == OBD_BRW_CHECK) {
1562 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1566 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &lovset);
1570 list_for_each (pos, &lovset->set_list) {
1571 struct obd_export *sub_exp;
1572 struct brw_page *sub_pga;
1573 req = list_entry(pos, struct lov_request, rq_link);
1575 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1576 sub_pga = lovset->set_pga + req->rq_pgaidx;
1577 rc = obd_brw_async(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1581 lov_update_common_set(lovset, req, rc);
1584 LASSERT(set->set_interpret == NULL);
1585 set->set_interpret = (set_interpreter_func)lov_brw_interpret;
1586 set->set_arg = (void *)lovset;
1590 lov_fini_brw_set(lovset);
1594 static int lov_ap_make_ready(void *data, int cmd)
1596 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1598 return lap->lap_caller_ops->ap_make_ready(lap->lap_caller_data, cmd);
1601 static int lov_ap_refresh_count(void *data, int cmd)
1603 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1605 return lap->lap_caller_ops->ap_refresh_count(lap->lap_caller_data,
1609 static void lov_ap_fill_obdo(void *data, int cmd, struct obdo *oa)
1611 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1613 lap->lap_caller_ops->ap_fill_obdo(lap->lap_caller_data, cmd, oa);
1614 /* XXX woah, shouldn't we be altering more here? size? */
1615 oa->o_id = lap->lap_loi_id;
1616 oa->o_stripe_idx = lap->lap_stripe;
1619 static void lov_ap_update_obdo(void *data, int cmd, struct obdo *oa,
1622 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1624 lap->lap_caller_ops->ap_update_obdo(lap->lap_caller_data, cmd,oa,valid);
1627 static int lov_ap_completion(void *data, int cmd, struct obdo *oa, int rc)
1629 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1631 /* in a raid1 regime this would down a count of many ios
1632 * in flight, onl calling the caller_ops completion when all
1633 * the raid1 ios are complete */
1634 rc = lap->lap_caller_ops->ap_completion(lap->lap_caller_data,cmd,oa,rc);
1638 static struct obd_async_page_ops lov_async_page_ops = {
1639 .ap_make_ready = lov_ap_make_ready,
1640 .ap_refresh_count = lov_ap_refresh_count,
1641 .ap_fill_obdo = lov_ap_fill_obdo,
1642 .ap_update_obdo = lov_ap_update_obdo,
1643 .ap_completion = lov_ap_completion,
1646 int lov_prep_async_page(struct obd_export *exp, struct lov_stripe_md *lsm,
1647 struct lov_oinfo *loi, cfs_page_t *page,
1648 obd_off offset, struct obd_async_page_ops *ops,
1649 void *data, void **res)
1651 struct lov_obd *lov = &exp->exp_obd->u.lov;
1652 struct lov_async_page *lap;
1658 /* Find an existing osc so we can get it's stupid sizeof(*oap).
1659 Only because of this layering limitation will a client
1660 mount with no osts fail */
1661 while (!lov->lov_tgts || !lov->lov_tgts[i] ||
1662 !lov->lov_tgts[i]->ltd_exp) {
1664 if (i >= lov->desc.ld_tgt_count)
1667 rc = size_round(sizeof(*lap)) +
1668 obd_prep_async_page(lov->lov_tgts[i]->ltd_exp, NULL,
1669 NULL, NULL, 0, NULL, NULL, NULL);
1672 ASSERT_LSM_MAGIC(lsm);
1673 LASSERT(loi == NULL);
1676 lap->lap_magic = LOV_AP_MAGIC;
1677 lap->lap_caller_ops = ops;
1678 lap->lap_caller_data = data;
1680 /* for now only raid 0 which passes through */
1681 lap->lap_stripe = lov_stripe_number(lsm, offset);
1682 lov_stripe_offset(lsm, offset, lap->lap_stripe, &lap->lap_sub_offset);
1683 loi = lsm->lsm_oinfo[lap->lap_stripe];
1685 /* so the callback doesn't need the lsm */
1686 lap->lap_loi_id = loi->loi_id;
1688 lap->lap_sub_cookie = (void *)lap + size_round(sizeof(*lap));
1690 rc = obd_prep_async_page(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1691 lsm, loi, page, lap->lap_sub_offset,
1692 &lov_async_page_ops, lap,
1693 &lap->lap_sub_cookie);
1696 CDEBUG(D_CACHE, "lap %p page %p cookie %p off "LPU64"\n", lap, page,
1697 lap->lap_sub_cookie, offset);
1701 static int lov_queue_async_io(struct obd_export *exp,
1702 struct lov_stripe_md *lsm,
1703 struct lov_oinfo *loi, void *cookie,
1704 int cmd, obd_off off, int count,
1705 obd_flag brw_flags, obd_flag async_flags)
1707 struct lov_obd *lov = &exp->exp_obd->u.lov;
1708 struct lov_async_page *lap;
1711 LASSERT(loi == NULL);
1713 ASSERT_LSM_MAGIC(lsm);
1715 lap = LAP_FROM_COOKIE(cookie);
1717 loi = lsm->lsm_oinfo[lap->lap_stripe];
1719 rc = obd_queue_async_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp, lsm,
1720 loi, lap->lap_sub_cookie, cmd, off, count,
1721 brw_flags, async_flags);
1725 static int lov_set_async_flags(struct obd_export *exp,
1726 struct lov_stripe_md *lsm,
1727 struct lov_oinfo *loi, void *cookie,
1728 obd_flag async_flags)
1730 struct lov_obd *lov = &exp->exp_obd->u.lov;
1731 struct lov_async_page *lap;
1734 LASSERT(loi == NULL);
1736 ASSERT_LSM_MAGIC(lsm);
1738 lap = LAP_FROM_COOKIE(cookie);
1740 loi = lsm->lsm_oinfo[lap->lap_stripe];
1742 rc = obd_set_async_flags(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1743 lsm, loi, lap->lap_sub_cookie, async_flags);
1747 static int lov_queue_group_io(struct obd_export *exp,
1748 struct lov_stripe_md *lsm,
1749 struct lov_oinfo *loi,
1750 struct obd_io_group *oig, void *cookie,
1751 int cmd, obd_off off, int count,
1752 obd_flag brw_flags, obd_flag async_flags)
1754 struct lov_obd *lov = &exp->exp_obd->u.lov;
1755 struct lov_async_page *lap;
1758 LASSERT(loi == NULL);
1760 ASSERT_LSM_MAGIC(lsm);
1762 lap = LAP_FROM_COOKIE(cookie);
1764 loi = lsm->lsm_oinfo[lap->lap_stripe];
1766 rc = obd_queue_group_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp, lsm,
1767 loi, oig, lap->lap_sub_cookie, cmd, off, count,
1768 brw_flags, async_flags);
1772 /* this isn't exactly optimal. we may have queued sync io in oscs on
1773 * all stripes, but we don't record that fact at queue time. so we
1774 * trigger sync io on all stripes. */
1775 static int lov_trigger_group_io(struct obd_export *exp,
1776 struct lov_stripe_md *lsm,
1777 struct lov_oinfo *loi,
1778 struct obd_io_group *oig)
1780 struct lov_obd *lov = &exp->exp_obd->u.lov;
1783 LASSERT(loi == NULL);
1785 ASSERT_LSM_MAGIC(lsm);
1787 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1788 loi = lsm->lsm_oinfo[i];
1789 if (!lov->lov_tgts[loi->loi_ost_idx] ||
1790 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1791 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1795 err = obd_trigger_group_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1797 if (rc == 0 && err != 0)
1803 static int lov_teardown_async_page(struct obd_export *exp,
1804 struct lov_stripe_md *lsm,
1805 struct lov_oinfo *loi, void *cookie)
1807 struct lov_obd *lov = &exp->exp_obd->u.lov;
1808 struct lov_async_page *lap;
1811 LASSERT(loi == NULL);
1813 ASSERT_LSM_MAGIC(lsm);
1815 lap = LAP_FROM_COOKIE(cookie);
1817 loi = lsm->lsm_oinfo[lap->lap_stripe];
1819 rc = obd_teardown_async_page(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1820 lsm, loi, lap->lap_sub_cookie);
1822 CERROR("unable to teardown sub cookie %p: %d\n",
1823 lap->lap_sub_cookie, rc);
1829 static int lov_enqueue_interpret(struct ptlrpc_request_set *rqset,
1832 struct lov_request_set *lovset = (struct lov_request_set *)data;
1834 rc = lov_fini_enqueue_set(lovset, lovset->set_ei->ei_mode, rc);
1838 static int lov_enqueue(struct obd_export *exp, struct obd_info *oinfo,
1839 struct obd_enqueue_info *einfo)
1841 struct lov_request_set *set;
1842 struct lov_request *req;
1843 struct list_head *pos;
1844 struct lov_obd *lov;
1849 ASSERT_LSM_MAGIC(oinfo->oi_md);
1851 /* we should never be asked to replay a lock this way. */
1852 LASSERT((einfo->ei_flags & LDLM_FL_REPLAY) == 0);
1854 if (!exp || !exp->exp_obd)
1857 lov = &exp->exp_obd->u.lov;
1858 rc = lov_prep_enqueue_set(exp, oinfo, einfo, &set);
1862 list_for_each (pos, &set->set_list) {
1863 req = list_entry(pos, struct lov_request, rq_link);
1865 rc = obd_enqueue(lov->lov_tgts[req->rq_idx]->ltd_exp,
1866 &req->rq_oi, einfo);
1871 if (einfo->ei_rqset && !list_empty(&einfo->ei_rqset->set_requests)) {
1873 LASSERT(einfo->ei_rqset->set_interpret == NULL);
1874 einfo->ei_rqset->set_interpret = lov_enqueue_interpret;
1875 einfo->ei_rqset->set_arg = (void *)set;
1879 rc = lov_fini_enqueue_set(set, einfo->ei_mode, rc);
1883 static int lov_match(struct obd_export *exp, struct lov_stripe_md *lsm,
1884 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1885 int *flags, void *data, struct lustre_handle *lockh)
1887 struct lov_request_set *set;
1888 struct obd_info oinfo;
1889 struct lov_request *req;
1890 struct list_head *pos;
1891 struct lov_obd *lov = &exp->exp_obd->u.lov;
1892 struct lustre_handle *lov_lockhp;
1893 int lov_flags, rc = 0;
1896 ASSERT_LSM_MAGIC(lsm);
1898 if (!exp || !exp->exp_obd)
1901 lov = &exp->exp_obd->u.lov;
1902 rc = lov_prep_match_set(exp, &oinfo, lsm, policy, mode, lockh, &set);
1906 list_for_each (pos, &set->set_list) {
1907 ldlm_policy_data_t sub_policy;
1908 req = list_entry(pos, struct lov_request, rq_link);
1909 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
1910 LASSERT(lov_lockhp);
1913 sub_policy.l_extent = req->rq_oi.oi_policy.l_extent;
1915 rc = obd_match(lov->lov_tgts[req->rq_idx]->ltd_exp,
1916 req->rq_oi.oi_md, type, &sub_policy,
1917 mode, &lov_flags, data, lov_lockhp);
1918 rc = lov_update_match_set(set, req, rc);
1922 lov_fini_match_set(set, mode, *flags);
1926 static int lov_change_cbdata(struct obd_export *exp,
1927 struct lov_stripe_md *lsm, ldlm_iterator_t it,
1930 struct lov_obd *lov;
1931 struct lov_oinfo *loi;
1935 ASSERT_LSM_MAGIC(lsm);
1937 if (!exp || !exp->exp_obd)
1940 lov = &exp->exp_obd->u.lov;
1941 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1942 struct lov_stripe_md submd;
1944 loi = lsm->lsm_oinfo[i];
1945 submd.lsm_object_id = loi->loi_id;
1946 submd.lsm_stripe_count = 0;
1947 rc = obd_change_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1953 static int lov_cancel(struct obd_export *exp, struct lov_stripe_md *lsm,
1954 __u32 mode, struct lustre_handle *lockh)
1956 struct lov_request_set *set;
1957 struct obd_info oinfo;
1958 struct lov_request *req;
1959 struct list_head *pos;
1960 struct lov_obd *lov = &exp->exp_obd->u.lov;
1961 struct lustre_handle *lov_lockhp;
1962 int err = 0, rc = 0;
1965 ASSERT_LSM_MAGIC(lsm);
1967 if (!exp || !exp->exp_obd)
1971 lov = &exp->exp_obd->u.lov;
1972 rc = lov_prep_cancel_set(exp, &oinfo, lsm, mode, lockh, &set);
1976 list_for_each (pos, &set->set_list) {
1977 req = list_entry(pos, struct lov_request, rq_link);
1978 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
1980 rc = obd_cancel(lov->lov_tgts[req->rq_idx]->ltd_exp,
1981 req->rq_oi.oi_md, mode, lov_lockhp);
1982 rc = lov_update_common_set(set, req, rc);
1984 CERROR("error: cancel objid "LPX64" subobj "
1985 LPX64" on OST idx %d: rc = %d\n",
1987 req->rq_oi.oi_md->lsm_object_id,
1993 lov_fini_cancel_set(set);
1997 static int lov_cancel_unused(struct obd_export *exp,
1998 struct lov_stripe_md *lsm, int flags, void *opaque)
2000 struct lov_obd *lov;
2001 struct lov_oinfo *loi;
2005 if (!exp || !exp->exp_obd)
2008 lov = &exp->exp_obd->u.lov;
2010 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2012 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2015 err = obd_cancel_unused(lov->lov_tgts[i]->ltd_exp, NULL,
2023 ASSERT_LSM_MAGIC(lsm);
2025 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2026 struct lov_stripe_md submd;
2029 loi = lsm->lsm_oinfo[i];
2030 if (!lov->lov_tgts[loi->loi_ost_idx] ||
2031 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
2032 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2034 submd.lsm_object_id = loi->loi_id;
2035 submd.lsm_stripe_count = 0;
2036 err = obd_cancel_unused(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2037 &submd, flags, opaque);
2038 if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
2039 CERROR("error: cancel unused objid "LPX64" subobj "LPX64
2040 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
2041 loi->loi_id, loi->loi_ost_idx, err);
2049 static int lov_join_lru(struct obd_export *exp,
2050 struct lov_stripe_md *lsm, int join)
2052 struct lov_obd *lov;
2053 struct lov_oinfo *loi;
2057 ASSERT_LSM_MAGIC(lsm);
2058 if (!exp || !exp->exp_obd)
2061 lov = &exp->exp_obd->u.lov;
2062 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2063 struct lov_stripe_md submd;
2066 loi = lsm->lsm_oinfo[i];
2067 if (!lov->lov_tgts[loi->loi_ost_idx] ||
2068 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
2069 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2071 submd.lsm_object_id = loi->loi_id;
2072 submd.lsm_stripe_count = 0;
2073 rc = obd_join_lru(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2076 CERROR("join lru failed. objid: "LPX64" subobj: "LPX64
2077 " ostidx: %d rc: %d\n", lsm->lsm_object_id,
2078 loi->loi_id, loi->loi_ost_idx, rc);
2087 static int lov_statfs_interpret(struct ptlrpc_request_set *rqset,
2090 struct lov_request_set *lovset = (struct lov_request_set *)data;
2095 lovset->set_completes = 0;
2097 err = lov_fini_statfs_set(lovset);
2098 RETURN(rc ? rc : err);
2101 static int lov_statfs_async(struct obd_device *obd, struct obd_info *oinfo,
2102 __u64 max_age, struct ptlrpc_request_set *rqset)
2104 struct lov_request_set *set;
2105 struct lov_request *req;
2106 struct list_head *pos;
2107 struct lov_obd *lov;
2111 LASSERT(oinfo != NULL);
2112 LASSERT(oinfo->oi_osfs != NULL);
2115 rc = lov_prep_statfs_set(obd, oinfo, &set);
2119 list_for_each (pos, &set->set_list) {
2120 struct obd_device *osc_obd;
2122 req = list_entry(pos, struct lov_request, rq_link);
2124 osc_obd = class_exp2obd(lov->lov_tgts[req->rq_idx]->ltd_exp);
2125 rc = obd_statfs_async(osc_obd, &req->rq_oi, max_age, rqset);
2130 if (rc || list_empty(&rqset->set_requests)) {
2133 set->set_completes = 0;
2134 err = lov_fini_statfs_set(set);
2135 RETURN(rc ? rc : err);
2138 LASSERT(rqset->set_interpret == NULL);
2139 rqset->set_interpret = lov_statfs_interpret;
2140 rqset->set_arg = (void *)set;
2144 static int lov_statfs(struct obd_device *obd, struct obd_statfs *osfs,
2147 struct lov_obd *lov = &obd->u.lov;
2148 struct obd_statfs lov_sfs;
2154 /* We only get block data from the OBD */
2155 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2156 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active) {
2157 CDEBUG(D_HA, "lov idx %d inactive\n", i);
2161 err = obd_statfs(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
2164 if (lov->lov_tgts[i]->ltd_active && !rc)
2168 lov_update_statfs(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
2169 osfs, &lov_sfs, set);
2173 err = lov_fini_statfs(obd, osfs, set);
2176 RETURN(rc ? rc : err);
2179 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
2180 void *karg, void *uarg)
2182 struct obd_device *obddev = class_exp2obd(exp);
2183 struct lov_obd *lov = &obddev->u.lov;
2184 int i, rc, count = lov->desc.ld_tgt_count;
2185 struct obd_uuid *uuidp;
2189 case OBD_IOC_LOV_GET_CONFIG: {
2190 struct obd_ioctl_data *data;
2191 struct lov_desc *desc;
2196 if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
2199 data = (struct obd_ioctl_data *)buf;
2201 if (sizeof(*desc) > data->ioc_inllen1) {
2202 obd_ioctl_freedata(buf, len);
2206 if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
2207 obd_ioctl_freedata(buf, len);
2211 if (sizeof(__u32) * count > data->ioc_inllen3) {
2212 obd_ioctl_freedata(buf, len);
2216 desc = (struct lov_desc *)data->ioc_inlbuf1;
2217 memcpy(desc, &(lov->desc), sizeof(*desc));
2219 uuidp = (struct obd_uuid *)data->ioc_inlbuf2;
2220 genp = (__u32 *)data->ioc_inlbuf3;
2221 /* the uuid will be empty for deleted OSTs */
2222 for (i = 0; i < count; i++, uuidp++, genp++) {
2223 if (!lov->lov_tgts[i])
2225 *uuidp = lov->lov_tgts[i]->ltd_uuid;
2226 *genp = lov->lov_tgts[i]->ltd_gen;
2229 rc = copy_to_user((void *)uarg, buf, len);
2232 obd_ioctl_freedata(buf, len);
2235 case LL_IOC_LOV_SETSTRIPE:
2236 rc = lov_setstripe(exp, karg, uarg);
2238 case LL_IOC_LOV_GETSTRIPE:
2239 rc = lov_getstripe(exp, karg, uarg);
2241 case LL_IOC_LOV_SETEA:
2242 rc = lov_setea(exp, karg, uarg);
2251 for (i = 0; i < count; i++) {
2254 /* OST was disconnected */
2255 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2258 err = obd_iocontrol(cmd, lov->lov_tgts[i]->ltd_exp,
2260 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
2263 if (lov->lov_tgts[i]->ltd_active) {
2264 CDEBUG(err == -ENOTTY ?
2265 D_IOCTL : D_WARNING,
2266 "iocontrol OSC %s on OST "
2267 "idx %d cmd %x: err = %d\n",
2268 lov_uuid2str(lov, i),
2285 static int lov_get_info(struct obd_export *exp, __u32 keylen,
2286 void *key, __u32 *vallen, void *val)
2288 struct obd_device *obddev = class_exp2obd(exp);
2289 struct lov_obd *lov = &obddev->u.lov;
2293 if (!vallen || !val)
2298 if (KEY_IS("lock_to_stripe")) {
2301 struct ldlm_lock *lock;
2302 struct lov_stripe_md *lsm;
2304 struct ldlm_res_id *res_id = &data->lock->l_resource->lr_name;
2305 struct lov_oinfo *loi;
2306 __u32 *stripe = val;
2308 if (*vallen < sizeof(*stripe))
2309 GOTO(out, rc = -EFAULT);
2310 *vallen = sizeof(*stripe);
2312 /* XXX This is another one of those bits that will need to
2313 * change if we ever actually support nested LOVs. It uses
2314 * the lock's export to find out which stripe it is. */
2315 /* XXX - it's assumed all the locks for deleted OSTs have
2316 * been cancelled. Also, the export for deleted OSTs will
2317 * be NULL and won't match the lock's export. */
2318 for (i = 0; i < data->lsm->lsm_stripe_count; i++) {
2319 loi = data->lsm->lsm_oinfo[i];
2320 if (!lov->lov_tgts[loi->loi_ost_idx])
2322 if (lov->lov_tgts[loi->loi_ost_idx]->ltd_exp ==
2323 data->lock->l_conn_export &&
2324 loi->loi_id == res_id->name[0] &&
2325 loi->loi_gr == res_id->name[1]) {
2330 LDLM_ERROR(data->lock, "lock on inode without such object");
2331 dump_lsm(D_ERROR, data->lsm);
2332 GOTO(out, rc = -ENXIO);
2333 } else if (KEY_IS("last_id")) {
2335 int size = sizeof(obd_id);
2336 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2337 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
2339 rc = obd_get_info(lov->lov_tgts[i]->ltd_exp,
2340 keylen, key, &size, ids + i);
2345 } else if (KEY_IS(KEY_LOVDESC)) {
2346 struct lov_desc *desc_ret = val;
2347 *desc_ret = lov->desc;
2358 static int lov_set_info_async(struct obd_export *exp, obd_count keylen,
2359 void *key, obd_count vallen, void *val,
2360 struct ptlrpc_request_set *set)
2362 struct obd_device *obddev = class_exp2obd(exp);
2363 struct lov_obd *lov = &obddev->u.lov;
2364 int i, rc = 0, err, incr = 0, check_uuid = 0, do_inactive = 0;
2369 set = ptlrpc_prep_set();
2374 if (KEY_IS(KEY_NEXT_ID)) {
2375 if (vallen != lov->desc.ld_tgt_count * sizeof(obd_id))
2377 vallen = sizeof(obd_id);
2378 incr = sizeof(obd_id);
2380 } else if (KEY_IS("checksum")) {
2382 } else if (KEY_IS("mds_conn") || KEY_IS("unlinked")) {
2383 check_uuid = val ? 1 : 0;
2384 } else if (KEY_IS("evict_by_nid")) {
2386 do_inactive = incr = 0;
2392 for (i = 0; i < lov->desc.ld_tgt_count; i++, val = (char *)val + incr) {
2393 /* OST was disconnected */
2394 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2397 /* OST is inactive and we don't want inactive OSCs */
2398 if (!lov->lov_tgts[i]->ltd_active && !do_inactive)
2401 /* Only want a specific OSC */
2403 !obd_uuid_equals(val, &lov->lov_tgts[i]->ltd_uuid))
2406 err = obd_set_info_async(lov->lov_tgts[i]->ltd_exp,
2407 keylen, key, vallen, val, set);
2413 err = ptlrpc_set_wait(set);
2416 ptlrpc_set_destroy(set);
2421 static int lov_checkmd(struct obd_export *exp, struct obd_export *md_exp,
2422 struct lov_stripe_md *lsm)
2430 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
2431 rc = lsm_op_find(lsm->lsm_magic)->lsm_revalidate(lsm, md_exp->exp_obd);
2436 int lov_test_and_clear_async_rc(struct lov_stripe_md *lsm)
2438 struct lov_oinfo *loi;
2442 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2443 loi = lsm->lsm_oinfo[i];
2444 if (loi->loi_ar.ar_rc && !rc)
2445 rc = loi->loi_ar.ar_rc;
2446 loi->loi_ar.ar_rc = 0;
2450 EXPORT_SYMBOL(lov_test_and_clear_async_rc);
2453 static int lov_extent_calc(struct obd_export *exp, struct lov_stripe_md *lsm,
2454 int cmd, __u64 *offset)
2457 __u32 ssize = lsm->lsm_stripe_size;
2460 do_div(start, ssize);
2461 start = start * ssize;
2463 CDEBUG(D_DLMTRACE, "offset "LPU64", stripe %u, start "LPU64
2464 ", end "LPU64"\n", *offset, ssize, start, start + ssize - 1);
2465 if (cmd == OBD_CALC_STRIPE_END) {
2466 *offset = start + ssize - 1;
2467 } else if (cmd == OBD_CALC_STRIPE_START) {
2478 struct lov_multi_wait {
2479 struct ldlm_lock *lock;
2485 int lov_complete_many(struct obd_export *exp, struct lov_stripe_md *lsm,
2486 struct lustre_handle *lockh)
2488 struct lov_lock_handles *lov_lockh = NULL;
2489 struct lustre_handle *lov_lockhp;
2490 struct lov_obd *lov;
2491 struct lov_oinfo *loi;
2492 struct lov_multi_wait *queues;
2496 ASSERT_LSM_MAGIC(lsm);
2498 if (!exp || !exp->exp_obd)
2501 LASSERT(lockh != NULL);
2502 if (lsm->lsm_stripe_count > 1) {
2503 lov_lockh = lov_handle2llh(lockh);
2504 if (lov_lockh == NULL) {
2505 CERROR("LOV: invalid lov lock handle %p\n", lockh);
2509 lov_lockhp = lov_lockh->llh_handles;
2514 OBD_ALLOC(queues, lsm->lsm_stripe_count * sizeof(*queues));
2516 GOTO(out, rc = -ENOMEM);
2518 lov = &exp->exp_obd->u.lov;
2519 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
2520 i++, loi++, lov_lockhp++) {
2521 struct ldlm_lock *lock;
2522 struct obd_device *obd;
2524 lock = ldlm_handle2lock(lov_lockhp);
2526 CDEBUG(D_HA, "lov idx %d subobj "LPX64" no lock?\n",
2527 loi->loi_ost_idx, loi->loi_id);
2528 queues[i].completed = 1;
2532 queues[i].lock = lock;
2533 init_waitqueue_entry(&(queues[i].wait), current);
2534 add_wait_queue(lock->l_waitq, &(queues[i].wait));
2536 obd = class_exp2obd(lock->l_conn_export);
2538 imp = obd->u.cli.cl_import;
2540 spin_lock(&imp->imp_lock);
2541 queues[i].generation = imp->imp_generation;
2542 spin_unlock(&imp->imp_lock);
2546 lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, ldlm_expired_completion_wait,
2547 interrupted_completion_wait, &lwd);
2548 rc = l_wait_event_added(check_multi_complete(queues, lsm), &lwi);
2550 for (i = 0; i < lsm->lsm_stripe_count; i++)
2551 remove_wait_queue(lock->l_waitq, &(queues[i].wait));
2553 if (rc == -EINTR || rc == -ETIMEDOUT) {
2559 if (lov_lockh != NULL)
2560 lov_llh_put(lov_lockh);
2565 void lov_stripe_lock(struct lov_stripe_md *md)
2567 LASSERT(md->lsm_lock_owner != cfs_current());
2568 spin_lock(&md->lsm_lock);
2569 LASSERT(md->lsm_lock_owner == NULL);
2570 md->lsm_lock_owner = cfs_current();
2572 EXPORT_SYMBOL(lov_stripe_lock);
2574 void lov_stripe_unlock(struct lov_stripe_md *md)
2576 LASSERT(md->lsm_lock_owner == cfs_current());
2577 md->lsm_lock_owner = NULL;
2578 spin_unlock(&md->lsm_lock);
2580 EXPORT_SYMBOL(lov_stripe_unlock);
2582 struct obd_ops lov_obd_ops = {
2583 .o_owner = THIS_MODULE,
2584 .o_setup = lov_setup,
2585 .o_precleanup = lov_precleanup,
2586 .o_cleanup = lov_cleanup,
2587 .o_process_config = lov_process_config,
2588 .o_connect = lov_connect,
2589 .o_disconnect = lov_disconnect,
2590 .o_statfs = lov_statfs,
2591 .o_statfs_async = lov_statfs_async,
2592 .o_packmd = lov_packmd,
2593 .o_unpackmd = lov_unpackmd,
2594 .o_checkmd = lov_checkmd,
2595 .o_create = lov_create,
2596 .o_destroy = lov_destroy,
2597 .o_getattr = lov_getattr,
2598 .o_getattr_async = lov_getattr_async,
2599 .o_setattr = lov_setattr,
2600 .o_setattr_async = lov_setattr_async,
2602 .o_brw_async = lov_brw_async,
2603 .o_prep_async_page = lov_prep_async_page,
2604 .o_queue_async_io = lov_queue_async_io,
2605 .o_set_async_flags = lov_set_async_flags,
2606 .o_queue_group_io = lov_queue_group_io,
2607 .o_trigger_group_io = lov_trigger_group_io,
2608 .o_teardown_async_page = lov_teardown_async_page,
2609 .o_merge_lvb = lov_merge_lvb,
2610 .o_adjust_kms = lov_adjust_kms,
2611 .o_punch = lov_punch,
2613 .o_enqueue = lov_enqueue,
2614 .o_match = lov_match,
2615 .o_change_cbdata = lov_change_cbdata,
2616 .o_cancel = lov_cancel,
2617 .o_cancel_unused = lov_cancel_unused,
2618 .o_join_lru = lov_join_lru,
2619 .o_iocontrol = lov_iocontrol,
2620 .o_get_info = lov_get_info,
2621 .o_set_info_async = lov_set_info_async,
2622 .o_extent_calc = lov_extent_calc,
2623 .o_llog_init = lov_llog_init,
2624 .o_llog_finish = lov_llog_finish,
2625 .o_notify = lov_notify,
2628 static quota_interface_t *quota_interface;
2629 extern quota_interface_t lov_quota_interface;
2631 cfs_mem_cache_t *lov_oinfo_slab;
2633 int __init lov_init(void)
2635 struct lprocfs_static_vars lvars;
2639 lov_oinfo_slab = cfs_mem_cache_create("lov_oinfo",
2640 sizeof(struct lov_oinfo), 0, 0);
2641 if (lov_oinfo_slab == NULL)
2643 lprocfs_init_vars(lov, &lvars);
2645 request_module("lquota");
2646 quota_interface = PORTAL_SYMBOL_GET(lov_quota_interface);
2647 init_obd_quota_ops(quota_interface, &lov_obd_ops);
2649 rc = class_register_type(&lov_obd_ops, lvars.module_vars,
2652 if (quota_interface)
2653 PORTAL_SYMBOL_PUT(lov_quota_interface);
2654 rc2 = cfs_mem_cache_destroy(lov_oinfo_slab);
2662 static void /*__exit*/ lov_exit(void)
2666 if (quota_interface)
2667 PORTAL_SYMBOL_PUT(lov_quota_interface);
2669 class_unregister_type(LUSTRE_LOV_NAME);
2670 rc = cfs_mem_cache_destroy(lov_oinfo_slab);
2674 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2675 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver");
2676 MODULE_LICENSE("GPL");
2678 cfs_module(lov, LUSTRE_VERSION_STRING, lov_init, lov_exit);