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));
116 if (!tgt_obd->obd_set_up) {
117 CERROR("Target %s not set up\n", obd_uuid2str(&tgt_uuid));
122 tgt_obd->obd_no_recov = 0;
123 /* FIXME this is probably supposed to be
124 ptlrpc_set_import_active. Horrible naming. */
125 ptlrpc_activate_import(tgt_obd->u.cli.cl_import);
129 * Divine LOV knows that OBDs under it are OSCs.
131 imp = tgt_obd->u.cli.cl_import;
133 if (imp->imp_invalid) {
134 CERROR("not connecting OSC %s; administratively "
135 "disabled\n", obd_uuid2str(&tgt_uuid));
136 rc = obd_register_observer(tgt_obd, obd);
138 CERROR("Target %s register_observer error %d; "
139 "will not be able to reactivate\n",
140 obd_uuid2str(&tgt_uuid), rc);
145 if (data && (data->ocd_connect_flags & OBD_CONNECT_INDEX))
146 data->ocd_index = index;
148 rc = obd_connect(NULL, &conn, tgt_obd, &lov_osc_uuid, data);
150 CERROR("Target %s connect error %d\n",
151 obd_uuid2str(&tgt_uuid), rc);
154 lov->lov_tgts[index]->ltd_exp = class_conn2export(&conn);
155 if (!lov->lov_tgts[index]->ltd_exp) {
156 CERROR("Target %s: null export!\n", obd_uuid2str(&tgt_uuid));
160 rc = obd_register_observer(tgt_obd, obd);
162 CERROR("Target %s register_observer error %d\n",
163 obd_uuid2str(&tgt_uuid), rc);
164 obd_disconnect(lov->lov_tgts[index]->ltd_exp);
165 lov->lov_tgts[index]->ltd_exp = NULL;
169 lov->lov_tgts[index]->ltd_reap = 0;
171 lov->lov_tgts[index]->ltd_active = 1;
172 lov->desc.ld_active_tgt_count++;
174 CDEBUG(D_CONFIG, "Connected tgt idx %d %s (%s) %sactive\n", index,
175 obd_uuid2str(&tgt_uuid), tgt_obd->obd_name, activate ? "":"in");
178 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
180 struct obd_device *osc_obd = class_conn2obd(&conn);
181 cfs_proc_dir_entry_t *osc_symlink;
182 char name[MAX_STRING_SIZE];
184 LASSERT(osc_obd != NULL);
185 LASSERT(osc_obd->obd_magic == OBD_DEVICE_MAGIC);
186 LASSERT(osc_obd->obd_type->typ_name != NULL);
187 snprintf(name, MAX_STRING_SIZE, "../../../%s/%s",
188 osc_obd->obd_type->typ_name,
190 osc_symlink = proc_symlink(osc_obd->obd_name, lov_proc_dir,
192 if (osc_symlink == NULL) {
193 CERROR("could not register LOV target "
194 "/proc/fs/lustre/%s/%s/target_obds/%s.",
195 obd->obd_type->typ_name, obd->obd_name,
197 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(const struct lu_env *env,
211 struct lustre_handle *conn, struct obd_device *obd,
212 struct obd_uuid *cluuid, struct obd_connect_data *data)
214 struct lov_obd *lov = &obd->u.lov;
215 struct lov_tgt_desc *tgt;
219 CDEBUG(D_CONFIG, "connect #%d\n", lov->lov_connects);
221 rc = class_connect(conn, obd, cluuid);
225 /* Why should there ever be more than 1 connect? */
227 LASSERT(lov->lov_connects == 1);
229 memset(&lov->lov_ocd, 0, sizeof(lov->lov_ocd));
231 lov->lov_ocd = *data;
234 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
235 tgt = lov->lov_tgts[i];
236 if (!tgt || obd_uuid_empty(&tgt->ltd_uuid))
238 /* Flags will be lowest common denominator */
239 rc = lov_connect_obd(obd, i, tgt->ltd_activate, &lov->lov_ocd);
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, struct lustre_cfg *lcfg)
674 struct lprocfs_static_vars lvars;
675 struct lov_desc *desc;
676 struct lov_obd *lov = &obd->u.lov;
680 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
681 CERROR("LOV setup requires a descriptor\n");
685 desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
687 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
688 CERROR("descriptor size wrong: %d > %d\n",
689 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
693 if (desc->ld_magic != LOV_DESC_MAGIC) {
694 if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
695 CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n",
696 obd->obd_name, desc);
697 lustre_swab_lov_desc(desc);
699 CERROR("%s: Bad lov desc magic: %#x\n",
700 obd->obd_name, desc->ld_magic);
707 /* Because of 64-bit divide/mod operations only work with a 32-bit
708 * divisor in a 32-bit kernel, we cannot support a stripe width
709 * of 4GB or larger on 32-bit CPUs. */
710 count = desc->ld_default_stripe_count;
711 if ((count > 0 ? count : desc->ld_tgt_count) *
712 desc->ld_default_stripe_size > 0xffffffff) {
713 CERROR("LOV: stripe width "LPU64"x%u > 4294967295 bytes\n",
714 desc->ld_default_stripe_size, count);
718 desc->ld_active_tgt_count = 0;
720 lov->lov_tgt_size = 0;
721 sema_init(&lov->lov_lock, 1);
722 atomic_set(&lov->lov_refcount, 0);
723 INIT_LIST_HEAD(&lov->lov_qos.lq_oss_list);
724 init_rwsem(&lov->lov_qos.lq_rw_sem);
725 lov->lov_qos.lq_dirty = 1;
726 lov->lov_qos.lq_dirty_rr = 1;
727 lov->lov_qos.lq_reset = 1;
729 lprocfs_init_vars(lov, &lvars);
730 lprocfs_obd_setup(obd, lvars.obd_vars);
733 cfs_proc_dir_entry_t *entry;
735 entry = create_proc_entry("target_obd", 0444,
736 obd->obd_proc_entry);
738 entry->proc_fops = &lov_proc_target_fops;
747 static int lov_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
753 case OBD_CLEANUP_EARLY: {
754 struct lov_obd *lov = &obd->u.lov;
756 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
757 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
759 obd_precleanup(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
764 case OBD_CLEANUP_EXPORTS:
766 case OBD_CLEANUP_SELF_EXP:
767 rc = obd_llog_finish(obd, 0);
769 CERROR("failed to cleanup llogging subsystems\n");
771 case OBD_CLEANUP_OBD:
777 static int lov_cleanup(struct obd_device *obd)
779 struct lov_obd *lov = &obd->u.lov;
781 lprocfs_obd_cleanup(obd);
784 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
785 /* We should never get here - these should have
786 been removed in the disconnect. */
787 if (lov->lov_tgts[i]) {
788 CERROR("lov tgt %d not cleaned!"
789 " deathrow=%d, lovrc=%d\n",
790 i, lov->lov_death_row,
791 atomic_read(&lov->lov_refcount));
792 lov_del_target(obd, i, 0, 0);
795 OBD_FREE(lov->lov_tgts, sizeof(*lov->lov_tgts) *
797 lov->lov_tgt_size = 0;
800 if (lov->lov_qos.lq_rr_size)
801 OBD_FREE(lov->lov_qos.lq_rr_array, lov->lov_qos.lq_rr_size);
806 static int lov_process_config(struct obd_device *obd, obd_count len, void *buf)
808 struct lustre_cfg *lcfg = buf;
809 struct obd_uuid obd_uuid;
814 switch(cmd = lcfg->lcfg_command) {
815 case LCFG_LOV_ADD_OBD:
816 case LCFG_LOV_ADD_INA:
817 case LCFG_LOV_DEL_OBD: {
820 /* lov_modify_tgts add 0:lov_mdsA 1:ost1_UUID 2:0 3:1 */
821 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
822 GOTO(out, rc = -EINVAL);
824 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
826 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
827 GOTO(out, rc = -EINVAL);
828 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
829 GOTO(out, rc = -EINVAL);
830 if (cmd == LCFG_LOV_ADD_OBD)
831 rc = lov_add_target(obd, &obd_uuid, index, gen, 1);
832 else if (cmd == LCFG_LOV_ADD_INA)
833 rc = lov_add_target(obd, &obd_uuid, index, gen, 0);
835 rc = lov_del_target(obd, index, &obd_uuid, gen);
839 struct lprocfs_static_vars lvars;
840 struct lov_desc *desc = &(obd->u.lov.desc);
843 GOTO(out, rc = -EINVAL);
845 lprocfs_init_vars(lov, &lvars);
847 rc = class_process_proc_param(PARAM_LOV, lvars.obd_vars,
852 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
853 GOTO(out, rc = -EINVAL);
862 #define log2(n) ffz(~(n))
865 static int lov_clear_orphans(struct obd_export *export, struct obdo *src_oa,
866 struct lov_stripe_md **ea,
867 struct obd_trans_info *oti)
871 struct obd_uuid *ost_uuid = NULL;
875 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
876 src_oa->o_flags == OBD_FL_DELORPHAN);
878 lov = &export->exp_obd->u.lov;
880 tmp_oa = obdo_alloc();
884 if (src_oa->o_valid & OBD_MD_FLINLINE) {
885 ost_uuid = (struct obd_uuid *)src_oa->o_inline;
886 CDEBUG(D_HA, "clearing orphans only for %s\n",
890 lov_getref(export->exp_obd);
891 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
892 struct lov_stripe_md obj_md;
893 struct lov_stripe_md *obj_mdp = &obj_md;
894 struct lov_tgt_desc *tgt;
897 tgt = lov->lov_tgts[i];
901 /* if called for a specific target, we don't
902 care if it is not active. */
903 if (!lov->lov_tgts[i]->ltd_active == 0 && ost_uuid == NULL) {
904 CDEBUG(D_HA, "lov idx %d inactive\n", i);
908 if (ost_uuid && !obd_uuid_equals(ost_uuid, &tgt->ltd_uuid))
911 CDEBUG(D_CONFIG,"Clear orphans for %d:%s\n", i,
912 obd_uuid2str(ost_uuid));
914 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
916 LASSERT(lov->lov_tgts[i]->ltd_exp);
917 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
918 err = obd_create(lov->lov_tgts[i]->ltd_exp,
919 tmp_oa, &obj_mdp, oti);
921 /* This export will be disabled until it is recovered,
922 and then orphan recovery will be completed. */
923 CERROR("error in orphan recovery on OST idx %d/%d: "
924 "rc = %d\n", i, lov->desc.ld_tgt_count, err);
929 lov_putref(export->exp_obd);
935 static int lov_recreate(struct obd_export *exp, struct obdo *src_oa,
936 struct lov_stripe_md **ea, struct obd_trans_info *oti)
938 struct lov_stripe_md *obj_mdp, *lsm;
939 struct lov_obd *lov = &exp->exp_obd->u.lov;
944 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
945 src_oa->o_flags & OBD_FL_RECREATE_OBJS);
947 OBD_ALLOC(obj_mdp, sizeof(*obj_mdp));
951 ost_idx = src_oa->o_nlink;
954 GOTO(out, rc = -EINVAL);
955 if (ost_idx >= lov->desc.ld_tgt_count ||
956 !lov->lov_tgts[ost_idx])
957 GOTO(out, rc = -EINVAL);
959 for (i = 0; i < lsm->lsm_stripe_count; i++) {
960 if (lsm->lsm_oinfo[i].loi_ost_idx == ost_idx) {
961 if (lsm->lsm_oinfo[i].loi_id != src_oa->o_id)
962 GOTO(out, rc = -EINVAL);
966 if (i == lsm->lsm_stripe_count)
967 GOTO(out, rc = -EINVAL);
969 rc = obd_create(lov->lov_tgts[ost_idx]->ltd_exp, src_oa, &obj_mdp, oti);
971 OBD_FREE(obj_mdp, sizeof(*obj_mdp));
975 /* the LOV expects oa->o_id to be set to the LOV object id */
976 static int lov_create(struct obd_export *exp, struct obdo *src_oa,
977 struct lov_stripe_md **ea, struct obd_trans_info *oti)
980 struct obd_info oinfo;
981 struct lov_request_set *set = NULL;
982 struct lov_request *req;
983 struct obd_statfs osfs;
992 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
993 src_oa->o_flags == OBD_FL_DELORPHAN) {
994 rc = lov_clear_orphans(exp, src_oa, ea, oti);
998 lov = &exp->exp_obd->u.lov;
999 if (!lov->desc.ld_active_tgt_count)
1002 /* Recreate a specific object id at the given OST index */
1003 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1004 (src_oa->o_flags & OBD_FL_RECREATE_OBJS)) {
1005 rc = lov_recreate(exp, src_oa, ea, oti);
1009 maxage = cfs_time_shift_64(-lov->desc.ld_qos_maxage);
1010 obd_statfs_rqset(exp->exp_obd, &osfs, maxage);
1012 rc = lov_prep_create_set(exp, &oinfo, ea, src_oa, oti, &set);
1016 list_for_each_entry(req, &set->set_list, rq_link) {
1017 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1018 rc = obd_create(lov->lov_tgts[req->rq_idx]->ltd_exp,
1019 req->rq_oi.oi_oa, &req->rq_oi.oi_md, oti);
1020 lov_update_create_set(set, req, rc);
1022 rc = lov_fini_create_set(set, ea);
1026 #define ASSERT_LSM_MAGIC(lsmp) \
1028 LASSERT((lsmp) != NULL); \
1029 LASSERTF(((lsmp)->lsm_magic == LOV_MAGIC || \
1030 (lsmp)->lsm_magic == LOV_MAGIC_JOIN), "%p->lsm_magic=%x\n", \
1031 (lsmp), (lsmp)->lsm_magic); \
1034 static int lov_destroy(struct obd_export *exp, struct obdo *oa,
1035 struct lov_stripe_md *lsm, struct obd_trans_info *oti,
1036 struct obd_export *md_exp)
1038 struct lov_request_set *set;
1039 struct obd_info oinfo;
1040 struct lov_request *req;
1041 struct list_head *pos;
1042 struct lov_obd *lov;
1046 ASSERT_LSM_MAGIC(lsm);
1048 if (!exp || !exp->exp_obd)
1051 if (oa->o_valid & OBD_MD_FLCOOKIE) {
1053 LASSERT(oti->oti_logcookies);
1056 lov = &exp->exp_obd->u.lov;
1057 rc = lov_prep_destroy_set(exp, &oinfo, oa, lsm, oti, &set);
1061 list_for_each (pos, &set->set_list) {
1063 req = list_entry(pos, struct lov_request, rq_link);
1065 if (oa->o_valid & OBD_MD_FLCOOKIE)
1066 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1068 err = obd_destroy(lov->lov_tgts[req->rq_idx]->ltd_exp,
1069 req->rq_oi.oi_oa, NULL, oti, NULL);
1070 err = lov_update_common_set(set, req, err);
1072 CERROR("error: destroying objid "LPX64" subobj "
1073 LPX64" on OST idx %d: rc = %d\n",
1074 oa->o_id, req->rq_oi.oi_oa->o_id,
1082 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
1083 rc = lsm_op_find(lsm->lsm_magic)->lsm_destroy(lsm, oa, md_exp);
1085 err = lov_fini_destroy_set(set);
1086 RETURN(rc ? rc : err);
1089 static int lov_getattr(struct obd_export *exp, struct obd_info *oinfo)
1091 struct lov_request_set *set;
1092 struct lov_request *req;
1093 struct list_head *pos;
1094 struct lov_obd *lov;
1095 int err = 0, rc = 0;
1099 ASSERT_LSM_MAGIC(oinfo->oi_md);
1101 if (!exp || !exp->exp_obd)
1104 lov = &exp->exp_obd->u.lov;
1106 rc = lov_prep_getattr_set(exp, oinfo, &set);
1110 list_for_each (pos, &set->set_list) {
1111 req = list_entry(pos, struct lov_request, rq_link);
1113 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1114 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1115 req->rq_oi.oi_oa->o_id, req->rq_idx);
1117 rc = obd_getattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1119 err = lov_update_common_set(set, req, rc);
1121 CERROR("error: getattr objid "LPX64" subobj "
1122 LPX64" on OST idx %d: rc = %d\n",
1123 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1129 rc = lov_fini_getattr_set(set);
1135 static int lov_getattr_interpret(struct ptlrpc_request_set *rqset,
1138 struct lov_request_set *lovset = (struct lov_request_set *)data;
1142 /* don't do attribute merge if this aysnc op failed */
1144 lovset->set_completes = 0;
1145 err = lov_fini_getattr_set(lovset);
1146 RETURN(rc ? rc : err);
1149 static int lov_getattr_async(struct obd_export *exp, struct obd_info *oinfo,
1150 struct ptlrpc_request_set *rqset)
1152 struct lov_request_set *lovset;
1153 struct lov_obd *lov;
1154 struct list_head *pos;
1155 struct lov_request *req;
1160 ASSERT_LSM_MAGIC(oinfo->oi_md);
1162 if (!exp || !exp->exp_obd)
1165 lov = &exp->exp_obd->u.lov;
1167 rc = lov_prep_getattr_set(exp, oinfo, &lovset);
1171 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1172 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1173 oinfo->oi_md->lsm_stripe_size);
1175 list_for_each (pos, &lovset->set_list) {
1176 req = list_entry(pos, struct lov_request, rq_link);
1178 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1179 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1180 req->rq_oi.oi_oa->o_id, req->rq_idx);
1181 rc = obd_getattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1182 &req->rq_oi, rqset);
1184 CERROR("error: getattr objid "LPX64" subobj "
1185 LPX64" on OST idx %d: rc = %d\n",
1186 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1192 if (!list_empty(&rqset->set_requests)) {
1194 LASSERT (rqset->set_interpret == NULL);
1195 rqset->set_interpret = lov_getattr_interpret;
1196 rqset->set_arg = (void *)lovset;
1201 lovset->set_completes = 0;
1202 err = lov_fini_getattr_set(lovset);
1203 RETURN(rc ? rc : err);
1206 static int lov_setattr(struct obd_export *exp, struct obd_info *oinfo,
1207 struct obd_trans_info *oti)
1209 struct lov_request_set *set;
1210 struct lov_obd *lov;
1211 struct list_head *pos;
1212 struct lov_request *req;
1213 int err = 0, rc = 0;
1217 ASSERT_LSM_MAGIC(oinfo->oi_md);
1219 if (!exp || !exp->exp_obd)
1222 /* for now, we only expect the following updates here */
1223 LASSERT(!(oinfo->oi_oa->o_valid & ~(OBD_MD_FLID | OBD_MD_FLTYPE |
1224 OBD_MD_FLMODE | OBD_MD_FLATIME |
1225 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1226 OBD_MD_FLFLAGS | OBD_MD_FLSIZE |
1227 OBD_MD_FLGROUP | OBD_MD_FLUID |
1228 OBD_MD_FLGID | OBD_MD_FLINLINE |
1229 OBD_MD_FLFID | OBD_MD_FLGENER)));
1230 lov = &exp->exp_obd->u.lov;
1231 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1235 list_for_each (pos, &set->set_list) {
1236 req = list_entry(pos, struct lov_request, rq_link);
1238 rc = obd_setattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1240 err = lov_update_setattr_set(set, req, rc);
1242 CERROR("error: setattr objid "LPX64" subobj "
1243 LPX64" on OST idx %d: rc = %d\n",
1244 set->set_oi->oi_oa->o_id,
1245 req->rq_oi.oi_oa->o_id, req->rq_idx, err);
1250 err = lov_fini_setattr_set(set);
1256 static int lov_setattr_interpret(struct ptlrpc_request_set *rqset,
1259 struct lov_request_set *lovset = (struct lov_request_set *)data;
1264 lovset->set_completes = 0;
1265 err = lov_fini_setattr_set(lovset);
1266 RETURN(rc ? rc : err);
1269 /* If @oti is given, the request goes from MDS and responses from OSTs are not
1270 needed. Otherwise, a client is waiting for responses. */
1271 static int lov_setattr_async(struct obd_export *exp, struct obd_info *oinfo,
1272 struct obd_trans_info *oti,
1273 struct ptlrpc_request_set *rqset)
1275 struct lov_request_set *set;
1276 struct lov_request *req;
1277 struct list_head *pos;
1278 struct lov_obd *lov;
1283 ASSERT_LSM_MAGIC(oinfo->oi_md);
1284 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE) {
1286 LASSERT(oti->oti_logcookies);
1289 if (!exp || !exp->exp_obd)
1292 lov = &exp->exp_obd->u.lov;
1293 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1297 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1298 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1299 oinfo->oi_md->lsm_stripe_size);
1301 list_for_each (pos, &set->set_list) {
1302 req = list_entry(pos, struct lov_request, rq_link);
1304 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
1305 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1307 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1308 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1309 req->rq_oi.oi_oa->o_id, req->rq_idx);
1311 rc = obd_setattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1312 &req->rq_oi, oti, rqset);
1314 CERROR("error: setattr objid "LPX64" subobj "
1315 LPX64" on OST idx %d: rc = %d\n",
1316 set->set_oi->oi_oa->o_id,
1317 req->rq_oi.oi_oa->o_id,
1323 /* If we are not waiting for responses on async requests, return. */
1324 if (rc || !rqset || list_empty(&rqset->set_requests)) {
1327 set->set_completes = 0;
1328 err = lov_fini_setattr_set(set);
1329 RETURN(rc ? rc : err);
1332 LASSERT(rqset->set_interpret == NULL);
1333 rqset->set_interpret = lov_setattr_interpret;
1334 rqset->set_arg = (void *)set;
1339 static int lov_punch_interpret(struct ptlrpc_request_set *rqset,
1342 struct lov_request_set *lovset = (struct lov_request_set *)data;
1347 lovset->set_completes = 0;
1348 err = lov_fini_punch_set(lovset);
1349 RETURN(rc ? rc : err);
1352 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
1353 * we can send this 'punch' to just the authoritative node and the nodes
1354 * that the punch will affect. */
1355 static int lov_punch(struct obd_export *exp, struct obd_info *oinfo,
1356 struct obd_trans_info *oti,
1357 struct ptlrpc_request_set *rqset)
1359 struct lov_request_set *set;
1360 struct lov_obd *lov;
1361 struct list_head *pos;
1362 struct lov_request *req;
1367 ASSERT_LSM_MAGIC(oinfo->oi_md);
1369 if (!exp || !exp->exp_obd)
1372 lov = &exp->exp_obd->u.lov;
1373 rc = lov_prep_punch_set(exp, oinfo, oti, &set);
1377 list_for_each (pos, &set->set_list) {
1378 req = list_entry(pos, struct lov_request, rq_link);
1380 rc = obd_punch(lov->lov_tgts[req->rq_idx]->ltd_exp,
1381 &req->rq_oi, NULL, rqset);
1383 CERROR("error: punch objid "LPX64" subobj "LPX64
1384 " on OST idx %d: rc = %d\n",
1385 set->set_oi->oi_oa->o_id,
1386 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1391 if (rc || list_empty(&rqset->set_requests)) {
1393 err = lov_fini_punch_set(set);
1394 RETURN(rc ? rc : err);
1397 LASSERT(rqset->set_interpret == NULL);
1398 rqset->set_interpret = lov_punch_interpret;
1399 rqset->set_arg = (void *)set;
1404 static int lov_sync(struct obd_export *exp, struct obdo *oa,
1405 struct lov_stripe_md *lsm, obd_off start, obd_off end,
1408 struct lov_request_set *set;
1409 struct obd_info oinfo;
1410 struct lov_obd *lov;
1411 struct list_head *pos;
1412 struct lov_request *req;
1413 int err = 0, rc = 0;
1416 ASSERT_LSM_MAGIC(lsm);
1421 lov = &exp->exp_obd->u.lov;
1422 rc = lov_prep_sync_set(exp, &oinfo, oa, lsm, start, end, &set);
1426 list_for_each (pos, &set->set_list) {
1427 req = list_entry(pos, struct lov_request, rq_link);
1429 rc = obd_sync(lov->lov_tgts[req->rq_idx]->ltd_exp,
1430 req->rq_oi.oi_oa, NULL,
1431 req->rq_oi.oi_policy.l_extent.start,
1432 req->rq_oi.oi_policy.l_extent.end, capa);
1433 err = lov_update_common_set(set, req, rc);
1435 CERROR("error: fsync objid "LPX64" subobj "LPX64
1436 " on OST idx %d: rc = %d\n",
1437 set->set_oi->oi_oa->o_id,
1438 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1443 err = lov_fini_sync_set(set);
1449 static int lov_brw_check(struct lov_obd *lov, struct obd_info *lov_oinfo,
1450 obd_count oa_bufs, struct brw_page *pga)
1452 struct obd_info oinfo = { { { 0 } } };
1455 oinfo.oi_oa = lov_oinfo->oi_oa;
1457 /* The caller just wants to know if there's a chance that this
1458 * I/O can succeed */
1459 for (i = 0; i < oa_bufs; i++) {
1460 int stripe = lov_stripe_number(lov_oinfo->oi_md, pga[i].off);
1461 int ost = lov_oinfo->oi_md->lsm_oinfo[stripe].loi_ost_idx;
1464 if (!lov_stripe_intersects(lov_oinfo->oi_md, i, pga[i].off,
1465 pga[i].off + pga[i].count,
1469 if (!lov->lov_tgts[ost] || !lov->lov_tgts[ost]->ltd_active) {
1470 CDEBUG(D_HA, "lov idx %d inactive\n", ost);
1474 rc = obd_brw(OBD_BRW_CHECK, lov->lov_tgts[ost]->ltd_exp, &oinfo,
1482 static int lov_brw(int cmd, struct obd_export *exp, struct obd_info *oinfo,
1483 obd_count oa_bufs, struct brw_page *pga,
1484 struct obd_trans_info *oti)
1486 struct lov_request_set *set;
1487 struct lov_request *req;
1488 struct list_head *pos;
1489 struct lov_obd *lov = &exp->exp_obd->u.lov;
1493 ASSERT_LSM_MAGIC(oinfo->oi_md);
1495 if (cmd == OBD_BRW_CHECK) {
1496 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1500 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &set);
1504 list_for_each (pos, &set->set_list) {
1505 struct obd_export *sub_exp;
1506 struct brw_page *sub_pga;
1507 req = list_entry(pos, struct lov_request, rq_link);
1509 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1510 sub_pga = set->set_pga + req->rq_pgaidx;
1511 rc = obd_brw(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1515 lov_update_common_set(set, req, rc);
1518 err = lov_fini_brw_set(set);
1524 static int lov_brw_interpret(struct ptlrpc_request_set *reqset, void *data,
1527 struct lov_request_set *lovset = (struct lov_request_set *)data;
1531 lovset->set_completes = 0;
1532 lov_fini_brw_set(lovset);
1534 rc = lov_fini_brw_set(lovset);
1540 static int lov_brw_async(int cmd, struct obd_export *exp,
1541 struct obd_info *oinfo, obd_count oa_bufs,
1542 struct brw_page *pga, struct obd_trans_info *oti,
1543 struct ptlrpc_request_set *set)
1545 struct lov_request_set *lovset;
1546 struct lov_request *req;
1547 struct list_head *pos;
1548 struct lov_obd *lov = &exp->exp_obd->u.lov;
1553 ASSERT_LSM_MAGIC(oinfo->oi_md);
1555 if (cmd == OBD_BRW_CHECK) {
1556 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1560 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &lovset);
1564 list_for_each (pos, &lovset->set_list) {
1565 struct obd_export *sub_exp;
1566 struct brw_page *sub_pga;
1567 req = list_entry(pos, struct lov_request, rq_link);
1569 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1570 sub_pga = lovset->set_pga + req->rq_pgaidx;
1571 rc = obd_brw_async(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1575 lov_update_common_set(lovset, req, rc);
1578 LASSERT(set->set_interpret == NULL);
1579 set->set_interpret = (set_interpreter_func)lov_brw_interpret;
1580 set->set_arg = (void *)lovset;
1584 lov_fini_brw_set(lovset);
1588 static int lov_ap_make_ready(void *data, int cmd)
1590 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1592 return lap->lap_caller_ops->ap_make_ready(lap->lap_caller_data, cmd);
1595 static int lov_ap_refresh_count(void *data, int cmd)
1597 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1599 return lap->lap_caller_ops->ap_refresh_count(lap->lap_caller_data,
1603 static void lov_ap_fill_obdo(void *data, int cmd, struct obdo *oa)
1605 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1607 lap->lap_caller_ops->ap_fill_obdo(lap->lap_caller_data, cmd, oa);
1608 /* XXX woah, shouldn't we be altering more here? size? */
1609 oa->o_id = lap->lap_loi_id;
1610 oa->o_gr = lap->lap_loi_gr;
1611 oa->o_valid |= OBD_MD_FLGROUP;
1612 oa->o_stripe_idx = lap->lap_stripe;
1615 static void lov_ap_update_obdo(void *data, int cmd, struct obdo *oa,
1618 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1620 lap->lap_caller_ops->ap_update_obdo(lap->lap_caller_data, cmd,oa,valid);
1623 static int lov_ap_completion(void *data, int cmd, struct obdo *oa, int rc)
1625 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1627 /* in a raid1 regime this would down a count of many ios
1628 * in flight, onl calling the caller_ops completion when all
1629 * the raid1 ios are complete */
1630 rc = lap->lap_caller_ops->ap_completion(lap->lap_caller_data,cmd,oa,rc);
1634 static struct obd_capa *lov_ap_lookup_capa(void *data, int cmd)
1636 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1638 return lap->lap_caller_ops->ap_lookup_capa(lap->lap_caller_data, cmd);
1641 static struct obd_async_page_ops lov_async_page_ops = {
1642 .ap_make_ready = lov_ap_make_ready,
1643 .ap_refresh_count = lov_ap_refresh_count,
1644 .ap_fill_obdo = lov_ap_fill_obdo,
1645 .ap_update_obdo = lov_ap_update_obdo,
1646 .ap_completion = lov_ap_completion,
1647 .ap_lookup_capa = lov_ap_lookup_capa,
1650 int lov_prep_async_page(struct obd_export *exp, struct lov_stripe_md *lsm,
1651 struct lov_oinfo *loi, cfs_page_t *page,
1652 obd_off offset, struct obd_async_page_ops *ops,
1653 void *data, void **res)
1655 struct lov_obd *lov = &exp->exp_obd->u.lov;
1656 struct lov_async_page *lap;
1662 /* Find an existing osc so we can get it's stupid sizeof(*oap).
1663 Only because of this layering limitation will a client
1664 mount with no osts fail */
1665 while (!lov->lov_tgts || !lov->lov_tgts[i] ||
1666 !lov->lov_tgts[i]->ltd_exp) {
1668 if (i >= lov->desc.ld_tgt_count)
1671 rc = size_round(sizeof(*lap)) +
1672 obd_prep_async_page(lov->lov_tgts[i]->ltd_exp, NULL,
1673 NULL, NULL, 0, NULL, NULL, NULL);
1676 ASSERT_LSM_MAGIC(lsm);
1677 LASSERT(loi == NULL);
1680 lap->lap_magic = LOV_AP_MAGIC;
1681 lap->lap_caller_ops = ops;
1682 lap->lap_caller_data = data;
1684 /* for now only raid 0 which passes through */
1685 lap->lap_stripe = lov_stripe_number(lsm, offset);
1686 lov_stripe_offset(lsm, offset, lap->lap_stripe, &lap->lap_sub_offset);
1687 loi = &lsm->lsm_oinfo[lap->lap_stripe];
1689 /* so the callback doesn't need the lsm */
1690 lap->lap_loi_id = loi->loi_id;
1691 lap->lap_loi_gr = lsm->lsm_object_gr;
1692 LASSERT(lsm->lsm_object_gr > 0);
1694 lap->lap_sub_cookie = (void *)lap + size_round(sizeof(*lap));
1696 rc = obd_prep_async_page(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1697 lsm, loi, page, lap->lap_sub_offset,
1698 &lov_async_page_ops, lap,
1699 &lap->lap_sub_cookie);
1702 CDEBUG(D_CACHE, "lap %p page %p cookie %p off "LPU64"\n", lap, page,
1703 lap->lap_sub_cookie, offset);
1707 static int lov_queue_async_io(struct obd_export *exp,
1708 struct lov_stripe_md *lsm,
1709 struct lov_oinfo *loi, void *cookie,
1710 int cmd, obd_off off, int count,
1711 obd_flag brw_flags, obd_flag async_flags)
1713 struct lov_obd *lov = &exp->exp_obd->u.lov;
1714 struct lov_async_page *lap;
1717 LASSERT(loi == NULL);
1719 ASSERT_LSM_MAGIC(lsm);
1721 lap = LAP_FROM_COOKIE(cookie);
1723 loi = &lsm->lsm_oinfo[lap->lap_stripe];
1725 rc = obd_queue_async_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp, lsm,
1726 loi, lap->lap_sub_cookie, cmd, off, count,
1727 brw_flags, async_flags);
1731 static int lov_set_async_flags(struct obd_export *exp,
1732 struct lov_stripe_md *lsm,
1733 struct lov_oinfo *loi, void *cookie,
1734 obd_flag async_flags)
1736 struct lov_obd *lov = &exp->exp_obd->u.lov;
1737 struct lov_async_page *lap;
1740 LASSERT(loi == NULL);
1742 ASSERT_LSM_MAGIC(lsm);
1744 lap = LAP_FROM_COOKIE(cookie);
1746 loi = &lsm->lsm_oinfo[lap->lap_stripe];
1748 rc = obd_set_async_flags(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1749 lsm, loi, lap->lap_sub_cookie, async_flags);
1753 static int lov_queue_group_io(struct obd_export *exp,
1754 struct lov_stripe_md *lsm,
1755 struct lov_oinfo *loi,
1756 struct obd_io_group *oig, void *cookie,
1757 int cmd, obd_off off, int count,
1758 obd_flag brw_flags, obd_flag async_flags)
1760 struct lov_obd *lov = &exp->exp_obd->u.lov;
1761 struct lov_async_page *lap;
1764 LASSERT(loi == NULL);
1766 ASSERT_LSM_MAGIC(lsm);
1768 lap = LAP_FROM_COOKIE(cookie);
1770 loi = &lsm->lsm_oinfo[lap->lap_stripe];
1772 rc = obd_queue_group_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp, lsm,
1773 loi, oig, lap->lap_sub_cookie, cmd, off, count,
1774 brw_flags, async_flags);
1778 /* this isn't exactly optimal. we may have queued sync io in oscs on
1779 * all stripes, but we don't record that fact at queue time. so we
1780 * trigger sync io on all stripes. */
1781 static int lov_trigger_group_io(struct obd_export *exp,
1782 struct lov_stripe_md *lsm,
1783 struct lov_oinfo *loi,
1784 struct obd_io_group *oig)
1786 struct lov_obd *lov = &exp->exp_obd->u.lov;
1789 LASSERT(loi == NULL);
1791 ASSERT_LSM_MAGIC(lsm);
1793 loi = lsm->lsm_oinfo;
1794 for (i = 0; i < lsm->lsm_stripe_count; i++, loi++) {
1795 if (!lov->lov_tgts[loi->loi_ost_idx] ||
1796 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1797 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1801 err = obd_trigger_group_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1803 if (rc == 0 && err != 0)
1809 static int lov_teardown_async_page(struct obd_export *exp,
1810 struct lov_stripe_md *lsm,
1811 struct lov_oinfo *loi, void *cookie)
1813 struct lov_obd *lov = &exp->exp_obd->u.lov;
1814 struct lov_async_page *lap;
1817 LASSERT(loi == NULL);
1819 ASSERT_LSM_MAGIC(lsm);
1821 lap = LAP_FROM_COOKIE(cookie);
1823 loi = &lsm->lsm_oinfo[lap->lap_stripe];
1825 rc = obd_teardown_async_page(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1826 lsm, loi, lap->lap_sub_cookie);
1828 CERROR("unable to teardown sub cookie %p: %d\n",
1829 lap->lap_sub_cookie, rc);
1835 static int lov_enqueue_interpret(struct ptlrpc_request_set *rqset,
1838 struct lov_request_set *lovset = (struct lov_request_set *)data;
1840 rc = lov_fini_enqueue_set(lovset, lovset->set_ei->ei_mode, rc);
1844 static int lov_enqueue(struct obd_export *exp, struct obd_info *oinfo,
1845 struct obd_enqueue_info *einfo)
1847 struct lov_request_set *set;
1848 struct lov_request *req;
1849 struct list_head *pos;
1850 struct lov_obd *lov;
1855 ASSERT_LSM_MAGIC(oinfo->oi_md);
1857 /* we should never be asked to replay a lock this way. */
1858 LASSERT((einfo->ei_flags & LDLM_FL_REPLAY) == 0);
1860 if (!exp || !exp->exp_obd)
1863 lov = &exp->exp_obd->u.lov;
1864 rc = lov_prep_enqueue_set(exp, oinfo, einfo, &set);
1868 list_for_each (pos, &set->set_list) {
1869 req = list_entry(pos, struct lov_request, rq_link);
1871 rc = obd_enqueue(lov->lov_tgts[req->rq_idx]->ltd_exp,
1872 &req->rq_oi, einfo);
1877 if (einfo->ei_rqset && !list_empty(&einfo->ei_rqset->set_requests)) {
1879 LASSERT(einfo->ei_rqset->set_interpret == NULL);
1880 einfo->ei_rqset->set_interpret = lov_enqueue_interpret;
1881 einfo->ei_rqset->set_arg = (void *)set;
1885 rc = lov_fini_enqueue_set(set, einfo->ei_mode, rc);
1889 static int lov_match(struct obd_export *exp, struct lov_stripe_md *lsm,
1890 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1891 int *flags, void *data, struct lustre_handle *lockh)
1893 struct lov_request_set *set;
1894 struct obd_info oinfo;
1895 struct lov_request *req;
1896 struct list_head *pos;
1897 struct lov_obd *lov = &exp->exp_obd->u.lov;
1898 struct lustre_handle *lov_lockhp;
1899 int lov_flags, rc = 0;
1902 ASSERT_LSM_MAGIC(lsm);
1904 if (!exp || !exp->exp_obd)
1907 lov = &exp->exp_obd->u.lov;
1908 rc = lov_prep_match_set(exp, &oinfo, lsm, policy, mode, lockh, &set);
1912 list_for_each (pos, &set->set_list) {
1913 ldlm_policy_data_t sub_policy;
1914 req = list_entry(pos, struct lov_request, rq_link);
1915 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
1916 LASSERT(lov_lockhp);
1919 sub_policy.l_extent = req->rq_oi.oi_policy.l_extent;
1921 rc = obd_match(lov->lov_tgts[req->rq_idx]->ltd_exp,
1922 req->rq_oi.oi_md, type, &sub_policy,
1923 mode, &lov_flags, data, lov_lockhp);
1924 rc = lov_update_match_set(set, req, rc);
1928 lov_fini_match_set(set, mode, *flags);
1932 static int lov_change_cbdata(struct obd_export *exp,
1933 struct lov_stripe_md *lsm, ldlm_iterator_t it,
1936 struct lov_obd *lov;
1937 struct lov_oinfo *loi;
1941 ASSERT_LSM_MAGIC(lsm);
1943 if (!exp || !exp->exp_obd)
1946 LASSERT(lsm->lsm_object_gr > 0);
1948 lov = &exp->exp_obd->u.lov;
1949 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
1950 struct lov_stripe_md submd;
1952 submd.lsm_object_id = loi->loi_id;
1953 submd.lsm_object_gr = lsm->lsm_object_gr;
1954 submd.lsm_stripe_count = 0;
1955 rc = obd_change_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1961 static int lov_cancel(struct obd_export *exp, struct lov_stripe_md *lsm,
1962 __u32 mode, struct lustre_handle *lockh)
1964 struct lov_request_set *set;
1965 struct obd_info oinfo;
1966 struct lov_request *req;
1967 struct list_head *pos;
1968 struct lov_obd *lov = &exp->exp_obd->u.lov;
1969 struct lustre_handle *lov_lockhp;
1970 int err = 0, rc = 0;
1973 ASSERT_LSM_MAGIC(lsm);
1975 if (!exp || !exp->exp_obd)
1978 LASSERT(lsm->lsm_object_gr > 0);
1980 lov = &exp->exp_obd->u.lov;
1981 rc = lov_prep_cancel_set(exp, &oinfo, lsm, mode, lockh, &set);
1985 list_for_each (pos, &set->set_list) {
1986 req = list_entry(pos, struct lov_request, rq_link);
1987 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
1989 rc = obd_cancel(lov->lov_tgts[req->rq_idx]->ltd_exp,
1990 req->rq_oi.oi_md, mode, lov_lockhp);
1991 rc = lov_update_common_set(set, req, rc);
1993 CERROR("error: cancel objid "LPX64" subobj "
1994 LPX64" on OST idx %d: rc = %d\n",
1996 req->rq_oi.oi_md->lsm_object_id,
2002 lov_fini_cancel_set(set);
2006 static int lov_cancel_unused(struct obd_export *exp,
2007 struct lov_stripe_md *lsm,
2008 int flags, void *opaque)
2010 struct lov_oinfo *loi;
2011 struct lov_obd *lov;
2015 if (!exp || !exp->exp_obd)
2018 lov = &exp->exp_obd->u.lov;
2020 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2022 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2025 err = obd_cancel_unused(lov->lov_tgts[i]->ltd_exp, NULL,
2033 ASSERT_LSM_MAGIC(lsm);
2035 LASSERT(lsm->lsm_object_gr > 0);
2036 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
2037 struct lov_stripe_md submd;
2040 if (!lov->lov_tgts[loi->loi_ost_idx] ||
2041 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
2042 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2044 submd.lsm_object_id = loi->loi_id;
2045 submd.lsm_object_gr = lsm->lsm_object_gr;
2046 submd.lsm_stripe_count = 0;
2047 err = obd_cancel_unused(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2048 &submd, flags, opaque);
2049 if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
2050 CERROR("error: cancel unused objid "LPX64" subobj "LPX64
2051 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
2052 loi->loi_id, loi->loi_ost_idx, err);
2060 static int lov_join_lru(struct obd_export *exp,
2061 struct lov_stripe_md *lsm, int join)
2063 struct lov_obd *lov;
2064 struct lov_oinfo *loi;
2068 ASSERT_LSM_MAGIC(lsm);
2069 if (!exp || !exp->exp_obd)
2072 lov = &exp->exp_obd->u.lov;
2073 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
2074 struct lov_stripe_md submd;
2077 if (!lov->lov_tgts[loi->loi_ost_idx] ||
2078 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
2079 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2081 submd.lsm_object_id = loi->loi_id;
2082 submd.lsm_object_gr = lsm->lsm_object_gr;
2083 submd.lsm_stripe_count = 0;
2084 rc = obd_join_lru(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2087 CERROR("join lru failed. objid: "LPX64" subobj: "LPX64
2088 " ostidx: %d rc: %d\n", lsm->lsm_object_id,
2089 loi->loi_id, loi->loi_ost_idx, rc);
2098 static int lov_statfs_interpret(struct ptlrpc_request_set *rqset,
2101 struct lov_request_set *lovset = (struct lov_request_set *)data;
2106 lovset->set_completes = 0;
2108 err = lov_fini_statfs_set(lovset);
2109 RETURN(rc ? rc : err);
2112 static int lov_statfs_async(struct obd_device *obd, struct obd_info *oinfo,
2113 __u64 max_age, struct ptlrpc_request_set *rqset)
2115 struct lov_request_set *set;
2116 struct lov_request *req;
2117 struct list_head *pos;
2118 struct lov_obd *lov;
2121 LASSERT(oinfo != NULL);
2122 LASSERT(oinfo->oi_osfs != NULL);
2125 rc = lov_prep_statfs_set(obd, oinfo, &set);
2129 list_for_each (pos, &set->set_list) {
2130 struct obd_device *osc_obd;
2132 req = list_entry(pos, struct lov_request, rq_link);
2134 osc_obd = class_exp2obd(lov->lov_tgts[req->rq_idx]->ltd_exp);
2135 rc = obd_statfs_async(osc_obd, &req->rq_oi, max_age, rqset);
2140 if (rc || list_empty(&rqset->set_requests)) {
2143 set->set_completes = 0;
2144 err = lov_fini_statfs_set(set);
2145 RETURN(rc ? rc : err);
2148 LASSERT(rqset->set_interpret == NULL);
2149 rqset->set_interpret = lov_statfs_interpret;
2150 rqset->set_arg = (void *)set;
2154 static int lov_statfs(struct obd_device *obd, struct obd_statfs *osfs,
2157 struct lov_obd *lov = &obd->u.lov;
2158 struct obd_statfs lov_sfs;
2164 /* We only get block data from the OBD */
2165 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2166 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active) {
2167 CDEBUG(D_HA, "lov idx %d inactive\n", i);
2171 err = obd_statfs(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
2174 if (lov->lov_tgts[i]->ltd_active && !rc)
2178 qos_update(lov, i, &lov_sfs);
2180 lov_update_statfs(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
2181 osfs, &lov_sfs, set);
2185 err = lov_fini_statfs(obd, osfs, set);
2186 RETURN(rc ? rc : err);
2189 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
2190 void *karg, void *uarg)
2192 struct obd_device *obddev = class_exp2obd(exp);
2193 struct lov_obd *lov = &obddev->u.lov;
2194 int i, rc, count = lov->desc.ld_tgt_count;
2195 struct obd_uuid *uuidp;
2199 case OBD_IOC_LOV_GET_CONFIG: {
2200 struct obd_ioctl_data *data;
2201 struct lov_desc *desc;
2206 if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
2209 data = (struct obd_ioctl_data *)buf;
2211 if (sizeof(*desc) > data->ioc_inllen1) {
2212 obd_ioctl_freedata(buf, len);
2216 if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
2217 obd_ioctl_freedata(buf, len);
2221 if (sizeof(__u32) * count > data->ioc_inllen3) {
2222 obd_ioctl_freedata(buf, len);
2226 desc = (struct lov_desc *)data->ioc_inlbuf1;
2227 memcpy(desc, &(lov->desc), sizeof(*desc));
2229 uuidp = (struct obd_uuid *)data->ioc_inlbuf2;
2230 genp = (__u32 *)data->ioc_inlbuf3;
2231 /* the uuid will be empty for deleted OSTs */
2232 for (i = 0; i < count; i++, uuidp++, genp++) {
2233 if (!lov->lov_tgts[i])
2235 *uuidp = lov->lov_tgts[i]->ltd_uuid;
2236 *genp = lov->lov_tgts[i]->ltd_gen;
2239 rc = copy_to_user((void *)uarg, buf, len);
2242 obd_ioctl_freedata(buf, len);
2245 case LL_IOC_LOV_SETSTRIPE:
2246 rc = lov_setstripe(exp, karg, uarg);
2248 case LL_IOC_LOV_GETSTRIPE:
2249 rc = lov_getstripe(exp, karg, uarg);
2251 case LL_IOC_LOV_SETEA:
2252 rc = lov_setea(exp, karg, uarg);
2261 for (i = 0; i < count; i++) {
2264 /* OST was disconnected */
2265 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2268 err = obd_iocontrol(cmd, lov->lov_tgts[i]->ltd_exp,
2270 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
2273 if (lov->lov_tgts[i]->ltd_active) {
2275 "iocontrol OSC %s on OST "
2276 "idx %d cmd %x: err = %d\n",
2277 lov_uuid2str(lov, i),
2294 static int lov_get_info(struct obd_export *exp, __u32 keylen,
2295 void *key, __u32 *vallen, void *val)
2297 struct obd_device *obddev = class_exp2obd(exp);
2298 struct lov_obd *lov = &obddev->u.lov;
2302 if (!vallen || !val)
2307 if (keylen > strlen("lock_to_stripe") &&
2308 strcmp(key, "lock_to_stripe") == 0) {
2311 struct ldlm_lock *lock;
2312 struct lov_stripe_md *lsm;
2314 struct ldlm_res_id *res_id = &data->lock->l_resource->lr_name;
2315 struct lov_oinfo *loi;
2316 __u32 *stripe = val;
2318 if (*vallen < sizeof(*stripe))
2319 GOTO(out, rc = -EFAULT);
2320 *vallen = sizeof(*stripe);
2322 /* XXX This is another one of those bits that will need to
2323 * change if we ever actually support nested LOVs. It uses
2324 * the lock's export to find out which stripe it is. */
2325 /* XXX - it's assumed all the locks for deleted OSTs have
2326 * been cancelled. Also, the export for deleted OSTs will
2327 * be NULL and won't match the lock's export. */
2328 for (i = 0, loi = data->lsm->lsm_oinfo;
2329 i < data->lsm->lsm_stripe_count;
2331 if (!lov->lov_tgts[loi->loi_ost_idx])
2333 if (lov->lov_tgts[loi->loi_ost_idx]->ltd_exp ==
2334 data->lock->l_conn_export &&
2335 loi->loi_id == res_id->name[0] &&
2336 loi->loi_gr == res_id->name[2]) {
2341 LDLM_ERROR(data->lock, "lock on inode without such object");
2342 dump_lsm(D_ERROR, data->lsm);
2343 GOTO(out, rc = -ENXIO);
2344 } else if (keylen >= strlen("last_id") && strcmp(key, "last_id") == 0) {
2346 int size = sizeof(obd_id);
2347 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2348 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
2350 rc = obd_get_info(lov->lov_tgts[i]->ltd_exp,
2351 keylen, key, &size, &(ids[i]));
2356 } else if (keylen >= strlen(KEY_LOVDESC) &&
2357 strcmp(key, KEY_LOVDESC) == 0) {
2358 struct lov_desc *desc_ret = val;
2359 *desc_ret = lov->desc;
2370 static int lov_set_info_async(struct obd_export *exp, obd_count keylen,
2371 void *key, obd_count vallen, void *val,
2372 struct ptlrpc_request_set *set)
2374 struct obd_device *obddev = class_exp2obd(exp);
2375 struct lov_obd *lov = &obddev->u.lov;
2381 set = ptlrpc_prep_set();
2386 if (KEY_IS(KEY_NEXT_ID)) {
2387 if (vallen > lov->desc.ld_tgt_count)
2389 vallen = sizeof(obd_id);
2394 if (KEY_IS(KEY_NEXT_ID) || KEY_IS("checksum")) {
2395 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2396 /* OST was disconnected */
2397 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2400 /* hit all OSCs, even inactive ones */
2401 err = obd_set_info_async(lov->lov_tgts[i]->ltd_exp,
2402 keylen, key, vallen,
2403 ((obd_id*)val) + i, set);
2410 if (KEY_IS("evict_by_nid") || KEY_IS(KEY_CAPA_KEY)) {
2411 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2412 /* OST was disconnected or is inactive */
2413 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
2416 err = obd_set_info_async(lov->lov_tgts[i]->ltd_exp,
2417 keylen, key, vallen, val, set);
2423 if (KEY_IS(KEY_MDS_CONN)) {
2424 struct mds_group_info mgi;
2426 LASSERT(vallen == sizeof(mgi));
2427 mgi = (*(struct mds_group_info *)val);
2429 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2430 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2433 if (mgi.uuid && !obd_uuid_equals(mgi.uuid,
2434 &lov->lov_tgts[i]->ltd_uuid))
2436 if (!val && !lov->lov_tgts[i]->ltd_active)
2439 err = obd_set_info_async(lov->lov_tgts[i]->ltd_exp,
2440 keylen, key, sizeof(int),
2448 if (KEY_IS("unlinked")) {
2449 if (vallen != 0 && KEY_IS("unlinked"))
2450 GOTO(out, rc = -EINVAL);
2451 } else if (KEY_IS(KEY_FLUSH_CTX)) {
2454 GOTO(out, rc = -EINVAL);
2457 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2458 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2461 if (val && !obd_uuid_equals(val, &lov->lov_tgts[i]->ltd_uuid))
2464 if (!val && !lov->lov_tgts[i]->ltd_active)
2467 err = obd_set_info_async(lov->lov_tgts[i]->ltd_exp,
2468 keylen, key, vallen, val, set);
2475 err = ptlrpc_set_wait(set);
2478 ptlrpc_set_destroy(set);
2483 static int lov_checkmd(struct obd_export *exp, struct obd_export *md_exp,
2484 struct lov_stripe_md *lsm)
2492 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
2493 rc = lsm_op_find(lsm->lsm_magic)->lsm_revalidate(lsm, md_exp->exp_obd);
2498 int lov_test_and_clear_async_rc(struct lov_stripe_md *lsm)
2500 struct lov_oinfo *loi;
2504 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
2506 if (loi->loi_ar.ar_rc && !rc)
2507 rc = loi->loi_ar.ar_rc;
2508 loi->loi_ar.ar_rc = 0;
2512 EXPORT_SYMBOL(lov_test_and_clear_async_rc);
2515 static int lov_extent_calc(struct obd_export *exp, struct lov_stripe_md *lsm,
2516 int cmd, obd_off *offset)
2518 unsigned long ssize = lsm->lsm_stripe_size;
2522 do_div(start, ssize);
2523 start = start * ssize;
2525 CDEBUG(D_DLMTRACE, "offset %Lu, stripe %lu, start %Lu, end %Lu\n",
2526 *offset, ssize, start, start + ssize - 1);
2527 if (cmd == OBD_CALC_STRIPE_END) {
2528 *offset = start + ssize - 1;
2529 } else if (cmd == OBD_CALC_STRIPE_START) {
2540 struct lov_multi_wait {
2541 struct ldlm_lock *lock;
2547 int lov_complete_many(struct obd_export *exp, struct lov_stripe_md *lsm,
2548 struct lustre_handle *lockh)
2550 struct lov_lock_handles *lov_lockh = NULL;
2551 struct lustre_handle *lov_lockhp;
2552 struct lov_obd *lov;
2553 struct lov_oinfo *loi;
2554 struct lov_multi_wait *queues;
2558 ASSERT_LSM_MAGIC(lsm);
2560 if (!exp || !exp->exp_obd)
2563 LASSERT(lockh != NULL);
2564 if (lsm->lsm_stripe_count > 1) {
2565 lov_lockh = lov_handle2llh(lockh);
2566 if (lov_lockh == NULL) {
2567 CERROR("LOV: invalid lov lock handle %p\n", lockh);
2571 lov_lockhp = lov_lockh->llh_handles;
2576 OBD_ALLOC(queues, lsm->lsm_stripe_count * sizeof(*queues));
2578 GOTO(out, rc = -ENOMEM);
2580 lov = &exp->exp_obd->u.lov;
2581 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
2582 i++, loi++, lov_lockhp++) {
2583 struct ldlm_lock *lock;
2584 struct obd_device *obd;
2586 lock = ldlm_handle2lock(lov_lockhp);
2588 CDEBUG(D_HA, "lov idx %d subobj "LPX64" no lock?\n",
2589 loi->loi_ost_idx, loi->loi_id);
2590 queues[i].completed = 1;
2594 queues[i].lock = lock;
2595 init_waitqueue_entry(&(queues[i].wait), current);
2596 add_wait_queue(lock->l_waitq, &(queues[i].wait));
2598 obd = class_exp2obd(lock->l_conn_export);
2600 imp = obd->u.cli.cl_import;
2602 spin_lock(&imp->imp_lock);
2603 queues[i].generation = imp->imp_generation;
2604 spin_unlock(&imp->imp_lock);
2608 lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, ldlm_expired_completion_wait,
2609 interrupted_completion_wait, &lwd);
2610 rc = l_wait_event_added(check_multi_complete(queues, lsm), &lwi);
2612 for (i = 0; i < lsm->lsm_stripe_count; i++)
2613 remove_wait_queue(lock->l_waitq, &(queues[i].wait));
2615 if (rc == -EINTR || rc == -ETIMEDOUT) {
2621 if (lov_lockh != NULL)
2622 lov_llh_put(lov_lockh);
2627 void lov_stripe_lock(struct lov_stripe_md *md)
2629 LASSERT(md->lsm_lock_owner != cfs_current());
2630 spin_lock(&md->lsm_lock);
2631 LASSERT(md->lsm_lock_owner == NULL);
2632 md->lsm_lock_owner = cfs_current();
2634 EXPORT_SYMBOL(lov_stripe_lock);
2636 void lov_stripe_unlock(struct lov_stripe_md *md)
2638 LASSERT(md->lsm_lock_owner == cfs_current());
2639 md->lsm_lock_owner = NULL;
2640 spin_unlock(&md->lsm_lock);
2642 EXPORT_SYMBOL(lov_stripe_unlock);
2644 struct obd_ops lov_obd_ops = {
2645 .o_owner = THIS_MODULE,
2646 .o_setup = lov_setup,
2647 .o_precleanup = lov_precleanup,
2648 .o_cleanup = lov_cleanup,
2649 .o_process_config = lov_process_config,
2650 .o_connect = lov_connect,
2651 .o_disconnect = lov_disconnect,
2652 .o_statfs = lov_statfs,
2653 .o_statfs_async = lov_statfs_async,
2654 .o_packmd = lov_packmd,
2655 .o_unpackmd = lov_unpackmd,
2656 .o_checkmd = lov_checkmd,
2657 .o_create = lov_create,
2658 .o_destroy = lov_destroy,
2659 .o_getattr = lov_getattr,
2660 .o_getattr_async = lov_getattr_async,
2661 .o_setattr = lov_setattr,
2662 .o_setattr_async = lov_setattr_async,
2664 .o_brw_async = lov_brw_async,
2665 .o_prep_async_page = lov_prep_async_page,
2666 .o_queue_async_io = lov_queue_async_io,
2667 .o_set_async_flags = lov_set_async_flags,
2668 .o_queue_group_io = lov_queue_group_io,
2669 .o_trigger_group_io = lov_trigger_group_io,
2670 .o_teardown_async_page = lov_teardown_async_page,
2671 .o_merge_lvb = lov_merge_lvb,
2672 .o_adjust_kms = lov_adjust_kms,
2673 .o_punch = lov_punch,
2675 .o_enqueue = lov_enqueue,
2676 .o_match = lov_match,
2677 .o_change_cbdata = lov_change_cbdata,
2678 .o_cancel = lov_cancel,
2679 .o_cancel_unused = lov_cancel_unused,
2680 .o_join_lru = lov_join_lru,
2681 .o_iocontrol = lov_iocontrol,
2682 .o_get_info = lov_get_info,
2683 .o_set_info_async = lov_set_info_async,
2684 .o_extent_calc = lov_extent_calc,
2685 .o_llog_init = lov_llog_init,
2686 .o_llog_finish = lov_llog_finish,
2687 .o_notify = lov_notify,
2690 static quota_interface_t *quota_interface;
2691 extern quota_interface_t lov_quota_interface;
2693 int __init lov_init(void)
2695 struct lprocfs_static_vars lvars;
2699 lprocfs_init_vars(lov, &lvars);
2701 request_module("lquota");
2702 quota_interface = PORTAL_SYMBOL_GET(lov_quota_interface);
2703 init_obd_quota_ops(quota_interface, &lov_obd_ops);
2705 rc = class_register_type(&lov_obd_ops, NULL, lvars.module_vars,
2706 LUSTRE_LOV_NAME, NULL);
2707 if (rc && quota_interface)
2708 PORTAL_SYMBOL_PUT(lov_quota_interface);
2714 static void /*__exit*/ lov_exit(void)
2716 if (quota_interface)
2717 PORTAL_SYMBOL_PUT(lov_quota_interface);
2719 class_unregister_type(LUSTRE_LOV_NAME);
2722 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2723 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver");
2724 MODULE_LICENSE("GPL");
2726 cfs_module(lov, LUSTRE_VERSION_STRING, lov_init, lov_exit);