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));
121 if (data && (data->ocd_connect_flags & OBD_CONNECT_INDEX))
122 data->ocd_index = index;
125 * Divine LOV knows that OBDs under it are OSCs.
127 imp = tgt_obd->u.cli.cl_import;
130 tgt_obd->obd_no_recov = 0;
131 /* FIXME this is probably supposed to be
132 ptlrpc_set_import_active. Horrible naming. */
133 ptlrpc_activate_import(imp);
136 if (imp->imp_invalid) {
137 CERROR("not connecting OSC %s; administratively "
138 "disabled\n", obd_uuid2str(&tgt_uuid));
139 rc = obd_register_observer(tgt_obd, obd);
141 CERROR("Target %s register_observer error %d; "
142 "will not be able to reactivate\n",
143 obd_uuid2str(&tgt_uuid), rc);
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);
202 rc = qos_add_tgt(obd, index);
204 CERROR("qos_add_tgt failed %d\n", rc);
209 static int lov_connect(const struct lu_env *env,
210 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, tgt->ltd_activate, &lov->lov_ocd);
240 CERROR("%s: lov connect tgt %d failed: %d\n",
241 obd->obd_name, i, rc);
250 static int lov_disconnect_obd(struct obd_device *obd, __u32 index)
252 cfs_proc_dir_entry_t *lov_proc_dir;
253 struct lov_obd *lov = &obd->u.lov;
254 struct obd_device *osc_obd =
255 class_exp2obd(lov->lov_tgts[index]->ltd_exp);
259 CDEBUG(D_CONFIG, "%s: disconnecting target %s\n",
260 obd->obd_name, osc_obd->obd_name);
262 if (lov->lov_tgts[index]->ltd_active) {
263 lov->lov_tgts[index]->ltd_active = 0;
264 lov->desc.ld_active_tgt_count--;
267 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
269 cfs_proc_dir_entry_t *osc_symlink;
271 osc_symlink = lprocfs_srch(lov_proc_dir, osc_obd->obd_name);
273 lprocfs_remove(&osc_symlink);
275 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing.",
276 obd->obd_type->typ_name, obd->obd_name,
282 /* Pass it on to our clients.
283 * XXX This should be an argument to disconnect,
284 * XXX not a back-door flag on the OBD. Ah well.
286 osc_obd->obd_force = obd->obd_force;
287 osc_obd->obd_fail = obd->obd_fail;
288 osc_obd->obd_no_recov = obd->obd_no_recov;
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 class_manual_cleanup(osc_obd);
641 void lov_fix_desc(struct lov_desc *desc)
643 if (desc->ld_default_stripe_size < PTLRPC_MAX_BRW_SIZE) {
644 LCONSOLE_WARN("Increasing default stripe size to min %u\n",
645 PTLRPC_MAX_BRW_SIZE);
646 desc->ld_default_stripe_size = PTLRPC_MAX_BRW_SIZE;
647 } else if (desc->ld_default_stripe_size & (LOV_MIN_STRIPE_SIZE - 1)) {
648 desc->ld_default_stripe_size &= ~(LOV_MIN_STRIPE_SIZE - 1);
649 LCONSOLE_WARN("Changing default stripe size to "LPU64" (a "
651 desc->ld_default_stripe_size,LOV_MIN_STRIPE_SIZE);
654 if (desc->ld_default_stripe_count == 0)
655 desc->ld_default_stripe_count = 1;
657 /* from lov_setstripe */
658 if ((desc->ld_pattern != 0) &&
659 (desc->ld_pattern != LOV_PATTERN_RAID0)) {
660 LCONSOLE_WARN("Unknown stripe pattern: %#x\n",desc->ld_pattern);
661 desc->ld_pattern = 0;
664 if (desc->ld_qos_maxage == 0)
665 desc->ld_qos_maxage = QOS_DEFAULT_MAXAGE;
668 static int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
670 struct lprocfs_static_vars lvars;
671 struct lov_desc *desc;
672 struct lov_obd *lov = &obd->u.lov;
676 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
677 CERROR("LOV setup requires a descriptor\n");
681 desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
683 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
684 CERROR("descriptor size wrong: %d > %d\n",
685 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
689 if (desc->ld_magic != LOV_DESC_MAGIC) {
690 if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
691 CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n",
692 obd->obd_name, desc);
693 lustre_swab_lov_desc(desc);
695 CERROR("%s: Bad lov desc magic: %#x\n",
696 obd->obd_name, desc->ld_magic);
703 /* Because of 64-bit divide/mod operations only work with a 32-bit
704 * divisor in a 32-bit kernel, we cannot support a stripe width
705 * of 4GB or larger on 32-bit CPUs. */
706 count = desc->ld_default_stripe_count;
707 if ((count > 0 ? count : desc->ld_tgt_count) *
708 desc->ld_default_stripe_size > 0xffffffff) {
709 CERROR("LOV: stripe width "LPU64"x%u > 4294967295 bytes\n",
710 desc->ld_default_stripe_size, count);
714 desc->ld_active_tgt_count = 0;
716 lov->lov_tgt_size = 0;
717 sema_init(&lov->lov_lock, 1);
718 atomic_set(&lov->lov_refcount, 0);
719 INIT_LIST_HEAD(&lov->lov_qos.lq_oss_list);
720 init_rwsem(&lov->lov_qos.lq_rw_sem);
721 lov->lov_qos.lq_dirty = 1;
722 lov->lov_qos.lq_dirty_rr = 1;
723 lov->lov_qos.lq_reset = 1;
724 /* Default priority is toward free space balance */
725 lov->lov_qos.lq_prio_free = 232;
727 lprocfs_init_vars(lov, &lvars);
728 lprocfs_obd_setup(obd, lvars.obd_vars);
731 cfs_proc_dir_entry_t *entry;
733 entry = create_proc_entry("target_obd", 0444,
734 obd->obd_proc_entry);
736 entry->proc_fops = &lov_proc_target_fops;
745 static int lov_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
751 case OBD_CLEANUP_EARLY: {
752 struct lov_obd *lov = &obd->u.lov;
754 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
755 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
757 obd_precleanup(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
762 case OBD_CLEANUP_EXPORTS:
764 case OBD_CLEANUP_SELF_EXP:
765 rc = obd_llog_finish(obd, 0);
767 CERROR("failed to cleanup llogging subsystems\n");
769 case OBD_CLEANUP_OBD:
775 static int lov_cleanup(struct obd_device *obd)
777 struct lov_obd *lov = &obd->u.lov;
779 lprocfs_obd_cleanup(obd);
782 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
783 if (lov->lov_tgts[i]) {
784 /* Inactive targets may never have connected */
785 if (lov->lov_tgts[i]->ltd_active ||
786 atomic_read(&lov->lov_refcount))
787 /* We should never get here - these
788 should have been removed in the
790 CERROR("lov tgt %d not cleaned!"
791 " deathrow=%d, lovrc=%d\n",
792 i, lov->lov_death_row,
793 atomic_read(&lov->lov_refcount));
794 lov_del_target(obd, i, 0, 0);
797 OBD_FREE(lov->lov_tgts, sizeof(*lov->lov_tgts) *
799 lov->lov_tgt_size = 0;
802 if (lov->lov_qos.lq_rr_size)
803 OBD_FREE(lov->lov_qos.lq_rr_array, lov->lov_qos.lq_rr_size);
808 static int lov_process_config(struct obd_device *obd, obd_count len, void *buf)
810 struct lustre_cfg *lcfg = buf;
811 struct obd_uuid obd_uuid;
816 switch(cmd = lcfg->lcfg_command) {
817 case LCFG_LOV_ADD_OBD:
818 case LCFG_LOV_ADD_INA:
819 case LCFG_LOV_DEL_OBD: {
822 /* lov_modify_tgts add 0:lov_mdsA 1:ost1_UUID 2:0 3:1 */
823 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
824 GOTO(out, rc = -EINVAL);
826 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
828 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
829 GOTO(out, rc = -EINVAL);
830 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
831 GOTO(out, rc = -EINVAL);
832 if (cmd == LCFG_LOV_ADD_OBD)
833 rc = lov_add_target(obd, &obd_uuid, index, gen, 1);
834 else if (cmd == LCFG_LOV_ADD_INA)
835 rc = lov_add_target(obd, &obd_uuid, index, gen, 0);
837 rc = lov_del_target(obd, index, &obd_uuid, gen);
841 struct lprocfs_static_vars lvars;
842 struct lov_desc *desc = &(obd->u.lov.desc);
845 GOTO(out, rc = -EINVAL);
847 lprocfs_init_vars(lov, &lvars);
849 rc = class_process_proc_param(PARAM_LOV, lvars.obd_vars,
854 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
855 GOTO(out, rc = -EINVAL);
864 #define log2(n) ffz(~(n))
867 static int lov_clear_orphans(struct obd_export *export, struct obdo *src_oa,
868 struct lov_stripe_md **ea,
869 struct obd_trans_info *oti)
873 struct obd_uuid *ost_uuid = NULL;
877 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
878 src_oa->o_flags == OBD_FL_DELORPHAN);
880 lov = &export->exp_obd->u.lov;
886 if (src_oa->o_valid & OBD_MD_FLINLINE) {
887 ost_uuid = (struct obd_uuid *)src_oa->o_inline;
888 CDEBUG(D_HA, "clearing orphans only for %s\n",
892 lov_getref(export->exp_obd);
893 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
894 struct lov_stripe_md obj_md;
895 struct lov_stripe_md *obj_mdp = &obj_md;
896 struct lov_tgt_desc *tgt;
899 tgt = lov->lov_tgts[i];
903 /* if called for a specific target, we don't
904 care if it is not active. */
905 if (!lov->lov_tgts[i]->ltd_active && ost_uuid == NULL) {
906 CDEBUG(D_HA, "lov idx %d inactive\n", i);
910 if (ost_uuid && !obd_uuid_equals(ost_uuid, &tgt->ltd_uuid))
913 CDEBUG(D_CONFIG,"Clear orphans for %d:%s\n", i,
914 obd_uuid2str(ost_uuid));
916 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
918 LASSERT(lov->lov_tgts[i]->ltd_exp);
919 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
920 err = obd_create(lov->lov_tgts[i]->ltd_exp,
921 tmp_oa, &obj_mdp, oti);
923 /* This export will be disabled until it is recovered,
924 and then orphan recovery will be completed. */
925 CERROR("error in orphan recovery on OST idx %d/%d: "
926 "rc = %d\n", i, lov->desc.ld_tgt_count, err);
931 lov_putref(export->exp_obd);
937 static int lov_recreate(struct obd_export *exp, struct obdo *src_oa,
938 struct lov_stripe_md **ea, struct obd_trans_info *oti)
940 struct lov_stripe_md *obj_mdp, *lsm;
941 struct lov_obd *lov = &exp->exp_obd->u.lov;
946 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
947 src_oa->o_flags & OBD_FL_RECREATE_OBJS);
949 OBD_ALLOC(obj_mdp, sizeof(*obj_mdp));
953 ost_idx = src_oa->o_nlink;
956 GOTO(out, rc = -EINVAL);
957 if (ost_idx >= lov->desc.ld_tgt_count ||
958 !lov->lov_tgts[ost_idx])
959 GOTO(out, rc = -EINVAL);
961 for (i = 0; i < lsm->lsm_stripe_count; i++) {
962 if (lsm->lsm_oinfo[i]->loi_ost_idx == ost_idx) {
963 if (lsm->lsm_oinfo[i]->loi_id != src_oa->o_id)
964 GOTO(out, rc = -EINVAL);
968 if (i == lsm->lsm_stripe_count)
969 GOTO(out, rc = -EINVAL);
971 rc = obd_create(lov->lov_tgts[ost_idx]->ltd_exp, src_oa, &obj_mdp, oti);
973 OBD_FREE(obj_mdp, sizeof(*obj_mdp));
977 /* the LOV expects oa->o_id to be set to the LOV object id */
978 static int lov_create(struct obd_export *exp, struct obdo *src_oa,
979 struct lov_stripe_md **ea, struct obd_trans_info *oti)
982 struct obd_info oinfo;
983 struct lov_request_set *set = NULL;
984 struct lov_request *req;
985 struct obd_statfs osfs;
994 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
995 src_oa->o_flags == OBD_FL_DELORPHAN) {
996 rc = lov_clear_orphans(exp, src_oa, ea, oti);
1000 lov = &exp->exp_obd->u.lov;
1001 if (!lov->desc.ld_active_tgt_count)
1004 /* Recreate a specific object id at the given OST index */
1005 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1006 (src_oa->o_flags & OBD_FL_RECREATE_OBJS)) {
1007 rc = lov_recreate(exp, src_oa, ea, oti);
1011 maxage = cfs_time_shift_64(-lov->desc.ld_qos_maxage);
1012 obd_statfs_rqset(exp->exp_obd, &osfs, maxage);
1014 rc = lov_prep_create_set(exp, &oinfo, ea, src_oa, oti, &set);
1018 list_for_each_entry(req, &set->set_list, rq_link) {
1019 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1020 rc = obd_create(lov->lov_tgts[req->rq_idx]->ltd_exp,
1021 req->rq_oi.oi_oa, &req->rq_oi.oi_md, oti);
1022 lov_update_create_set(set, req, rc);
1024 rc = lov_fini_create_set(set, ea);
1028 #define ASSERT_LSM_MAGIC(lsmp) \
1030 LASSERT((lsmp) != NULL); \
1031 LASSERTF(((lsmp)->lsm_magic == LOV_MAGIC || \
1032 (lsmp)->lsm_magic == LOV_MAGIC_JOIN), "%p->lsm_magic=%x\n", \
1033 (lsmp), (lsmp)->lsm_magic); \
1036 static int lov_destroy(struct obd_export *exp, struct obdo *oa,
1037 struct lov_stripe_md *lsm, struct obd_trans_info *oti,
1038 struct obd_export *md_exp)
1040 struct lov_request_set *set;
1041 struct obd_info oinfo;
1042 struct lov_request *req;
1043 struct list_head *pos;
1044 struct lov_obd *lov;
1048 ASSERT_LSM_MAGIC(lsm);
1050 if (!exp || !exp->exp_obd)
1053 if (oa->o_valid & OBD_MD_FLCOOKIE) {
1055 LASSERT(oti->oti_logcookies);
1058 lov = &exp->exp_obd->u.lov;
1059 rc = lov_prep_destroy_set(exp, &oinfo, oa, lsm, oti, &set);
1063 list_for_each (pos, &set->set_list) {
1065 req = list_entry(pos, struct lov_request, rq_link);
1067 if (oa->o_valid & OBD_MD_FLCOOKIE)
1068 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1070 err = obd_destroy(lov->lov_tgts[req->rq_idx]->ltd_exp,
1071 req->rq_oi.oi_oa, NULL, oti, NULL);
1072 err = lov_update_common_set(set, req, err);
1074 CERROR("error: destroying objid "LPX64" subobj "
1075 LPX64" on OST idx %d: rc = %d\n",
1076 oa->o_id, req->rq_oi.oi_oa->o_id,
1084 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
1085 rc = lsm_op_find(lsm->lsm_magic)->lsm_destroy(lsm, oa, md_exp);
1087 err = lov_fini_destroy_set(set);
1088 RETURN(rc ? rc : err);
1091 static int lov_getattr(struct obd_export *exp, struct obd_info *oinfo)
1093 struct lov_request_set *set;
1094 struct lov_request *req;
1095 struct list_head *pos;
1096 struct lov_obd *lov;
1097 int err = 0, rc = 0;
1101 ASSERT_LSM_MAGIC(oinfo->oi_md);
1103 if (!exp || !exp->exp_obd)
1106 lov = &exp->exp_obd->u.lov;
1108 rc = lov_prep_getattr_set(exp, oinfo, &set);
1112 list_for_each (pos, &set->set_list) {
1113 req = list_entry(pos, struct lov_request, rq_link);
1115 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1116 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1117 req->rq_oi.oi_oa->o_id, req->rq_idx);
1119 rc = obd_getattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1121 err = lov_update_common_set(set, req, rc);
1123 CERROR("error: getattr objid "LPX64" subobj "
1124 LPX64" on OST idx %d: rc = %d\n",
1125 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1131 rc = lov_fini_getattr_set(set);
1137 static int lov_getattr_interpret(struct ptlrpc_request_set *rqset,
1140 struct lov_request_set *lovset = (struct lov_request_set *)data;
1144 /* don't do attribute merge if this aysnc op failed */
1146 lovset->set_completes = 0;
1147 err = lov_fini_getattr_set(lovset);
1148 RETURN(rc ? rc : err);
1151 static int lov_getattr_async(struct obd_export *exp, struct obd_info *oinfo,
1152 struct ptlrpc_request_set *rqset)
1154 struct lov_request_set *lovset;
1155 struct lov_obd *lov;
1156 struct list_head *pos;
1157 struct lov_request *req;
1162 ASSERT_LSM_MAGIC(oinfo->oi_md);
1164 if (!exp || !exp->exp_obd)
1167 lov = &exp->exp_obd->u.lov;
1169 rc = lov_prep_getattr_set(exp, oinfo, &lovset);
1173 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1174 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1175 oinfo->oi_md->lsm_stripe_size);
1177 list_for_each (pos, &lovset->set_list) {
1178 req = list_entry(pos, struct lov_request, rq_link);
1180 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1181 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1182 req->rq_oi.oi_oa->o_id, req->rq_idx);
1183 rc = obd_getattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1184 &req->rq_oi, rqset);
1186 CERROR("error: getattr objid "LPX64" subobj "
1187 LPX64" on OST idx %d: rc = %d\n",
1188 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1194 if (!list_empty(&rqset->set_requests)) {
1196 LASSERT (rqset->set_interpret == NULL);
1197 rqset->set_interpret = lov_getattr_interpret;
1198 rqset->set_arg = (void *)lovset;
1203 lovset->set_completes = 0;
1204 err = lov_fini_getattr_set(lovset);
1205 RETURN(rc ? rc : err);
1208 static int lov_setattr(struct obd_export *exp, struct obd_info *oinfo,
1209 struct obd_trans_info *oti)
1211 struct lov_request_set *set;
1212 struct lov_obd *lov;
1213 struct list_head *pos;
1214 struct lov_request *req;
1215 int err = 0, rc = 0;
1219 ASSERT_LSM_MAGIC(oinfo->oi_md);
1221 if (!exp || !exp->exp_obd)
1224 /* for now, we only expect the following updates here */
1225 LASSERT(!(oinfo->oi_oa->o_valid & ~(OBD_MD_FLID | OBD_MD_FLTYPE |
1226 OBD_MD_FLMODE | OBD_MD_FLATIME |
1227 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1228 OBD_MD_FLFLAGS | OBD_MD_FLSIZE |
1229 OBD_MD_FLGROUP | OBD_MD_FLUID |
1230 OBD_MD_FLGID | OBD_MD_FLINLINE |
1231 OBD_MD_FLFID | OBD_MD_FLGENER)));
1232 lov = &exp->exp_obd->u.lov;
1233 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1237 list_for_each (pos, &set->set_list) {
1238 req = list_entry(pos, struct lov_request, rq_link);
1240 rc = obd_setattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1242 err = lov_update_setattr_set(set, req, rc);
1244 CERROR("error: setattr objid "LPX64" subobj "
1245 LPX64" on OST idx %d: rc = %d\n",
1246 set->set_oi->oi_oa->o_id,
1247 req->rq_oi.oi_oa->o_id, req->rq_idx, err);
1252 err = lov_fini_setattr_set(set);
1258 static int lov_setattr_interpret(struct ptlrpc_request_set *rqset,
1261 struct lov_request_set *lovset = (struct lov_request_set *)data;
1266 lovset->set_completes = 0;
1267 err = lov_fini_setattr_set(lovset);
1268 RETURN(rc ? rc : err);
1271 /* If @oti is given, the request goes from MDS and responses from OSTs are not
1272 needed. Otherwise, a client is waiting for responses. */
1273 static int lov_setattr_async(struct obd_export *exp, struct obd_info *oinfo,
1274 struct obd_trans_info *oti,
1275 struct ptlrpc_request_set *rqset)
1277 struct lov_request_set *set;
1278 struct lov_request *req;
1279 struct list_head *pos;
1280 struct lov_obd *lov;
1285 ASSERT_LSM_MAGIC(oinfo->oi_md);
1286 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE) {
1288 LASSERT(oti->oti_logcookies);
1291 if (!exp || !exp->exp_obd)
1294 lov = &exp->exp_obd->u.lov;
1295 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1299 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1300 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1301 oinfo->oi_md->lsm_stripe_size);
1303 list_for_each (pos, &set->set_list) {
1304 req = list_entry(pos, struct lov_request, rq_link);
1306 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
1307 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1309 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1310 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1311 req->rq_oi.oi_oa->o_id, req->rq_idx);
1313 rc = obd_setattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1314 &req->rq_oi, oti, rqset);
1316 CERROR("error: setattr objid "LPX64" subobj "
1317 LPX64" on OST idx %d: rc = %d\n",
1318 set->set_oi->oi_oa->o_id,
1319 req->rq_oi.oi_oa->o_id,
1325 /* If we are not waiting for responses on async requests, return. */
1326 if (rc || !rqset || list_empty(&rqset->set_requests)) {
1329 set->set_completes = 0;
1330 err = lov_fini_setattr_set(set);
1331 RETURN(rc ? rc : err);
1334 LASSERT(rqset->set_interpret == NULL);
1335 rqset->set_interpret = lov_setattr_interpret;
1336 rqset->set_arg = (void *)set;
1341 static int lov_punch_interpret(struct ptlrpc_request_set *rqset,
1344 struct lov_request_set *lovset = (struct lov_request_set *)data;
1349 lovset->set_completes = 0;
1350 err = lov_fini_punch_set(lovset);
1351 RETURN(rc ? rc : err);
1354 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
1355 * we can send this 'punch' to just the authoritative node and the nodes
1356 * that the punch will affect. */
1357 static int lov_punch(struct obd_export *exp, struct obd_info *oinfo,
1358 struct obd_trans_info *oti,
1359 struct ptlrpc_request_set *rqset)
1361 struct lov_request_set *set;
1362 struct lov_obd *lov;
1363 struct list_head *pos;
1364 struct lov_request *req;
1369 ASSERT_LSM_MAGIC(oinfo->oi_md);
1371 if (!exp || !exp->exp_obd)
1374 lov = &exp->exp_obd->u.lov;
1375 rc = lov_prep_punch_set(exp, oinfo, oti, &set);
1379 list_for_each (pos, &set->set_list) {
1380 req = list_entry(pos, struct lov_request, rq_link);
1382 rc = obd_punch(lov->lov_tgts[req->rq_idx]->ltd_exp,
1383 &req->rq_oi, NULL, rqset);
1385 CERROR("error: punch objid "LPX64" subobj "LPX64
1386 " on OST idx %d: rc = %d\n",
1387 set->set_oi->oi_oa->o_id,
1388 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1393 if (rc || list_empty(&rqset->set_requests)) {
1395 err = lov_fini_punch_set(set);
1396 RETURN(rc ? rc : err);
1399 LASSERT(rqset->set_interpret == NULL);
1400 rqset->set_interpret = lov_punch_interpret;
1401 rqset->set_arg = (void *)set;
1406 static int lov_sync(struct obd_export *exp, struct obdo *oa,
1407 struct lov_stripe_md *lsm, obd_off start, obd_off end,
1410 struct lov_request_set *set;
1411 struct obd_info oinfo;
1412 struct lov_obd *lov;
1413 struct list_head *pos;
1414 struct lov_request *req;
1415 int err = 0, rc = 0;
1418 ASSERT_LSM_MAGIC(lsm);
1423 lov = &exp->exp_obd->u.lov;
1424 rc = lov_prep_sync_set(exp, &oinfo, oa, lsm, start, end, &set);
1428 list_for_each (pos, &set->set_list) {
1429 req = list_entry(pos, struct lov_request, rq_link);
1431 rc = obd_sync(lov->lov_tgts[req->rq_idx]->ltd_exp,
1432 req->rq_oi.oi_oa, NULL,
1433 req->rq_oi.oi_policy.l_extent.start,
1434 req->rq_oi.oi_policy.l_extent.end, capa);
1435 err = lov_update_common_set(set, req, rc);
1437 CERROR("error: fsync objid "LPX64" subobj "LPX64
1438 " on OST idx %d: rc = %d\n",
1439 set->set_oi->oi_oa->o_id,
1440 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1445 err = lov_fini_sync_set(set);
1451 static int lov_brw_check(struct lov_obd *lov, struct obd_info *lov_oinfo,
1452 obd_count oa_bufs, struct brw_page *pga)
1454 struct obd_info oinfo = { { { 0 } } };
1457 oinfo.oi_oa = lov_oinfo->oi_oa;
1459 /* The caller just wants to know if there's a chance that this
1460 * I/O can succeed */
1461 for (i = 0; i < oa_bufs; i++) {
1462 int stripe = lov_stripe_number(lov_oinfo->oi_md, pga[i].off);
1463 int ost = lov_oinfo->oi_md->lsm_oinfo[stripe]->loi_ost_idx;
1466 if (!lov_stripe_intersects(lov_oinfo->oi_md, i, pga[i].off,
1467 pga[i].off + pga[i].count,
1471 if (!lov->lov_tgts[ost] || !lov->lov_tgts[ost]->ltd_active) {
1472 CDEBUG(D_HA, "lov idx %d inactive\n", ost);
1476 rc = obd_brw(OBD_BRW_CHECK, lov->lov_tgts[ost]->ltd_exp, &oinfo,
1484 static int lov_brw(int cmd, struct obd_export *exp, struct obd_info *oinfo,
1485 obd_count oa_bufs, struct brw_page *pga,
1486 struct obd_trans_info *oti)
1488 struct lov_request_set *set;
1489 struct lov_request *req;
1490 struct list_head *pos;
1491 struct lov_obd *lov = &exp->exp_obd->u.lov;
1495 ASSERT_LSM_MAGIC(oinfo->oi_md);
1497 if (cmd == OBD_BRW_CHECK) {
1498 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1502 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &set);
1506 list_for_each (pos, &set->set_list) {
1507 struct obd_export *sub_exp;
1508 struct brw_page *sub_pga;
1509 req = list_entry(pos, struct lov_request, rq_link);
1511 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1512 sub_pga = set->set_pga + req->rq_pgaidx;
1513 rc = obd_brw(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1517 lov_update_common_set(set, req, rc);
1520 err = lov_fini_brw_set(set);
1526 static int lov_brw_interpret(struct ptlrpc_request_set *reqset, void *data,
1529 struct lov_request_set *lovset = (struct lov_request_set *)data;
1533 lovset->set_completes = 0;
1534 lov_fini_brw_set(lovset);
1536 rc = lov_fini_brw_set(lovset);
1542 static int lov_brw_async(int cmd, struct obd_export *exp,
1543 struct obd_info *oinfo, obd_count oa_bufs,
1544 struct brw_page *pga, struct obd_trans_info *oti,
1545 struct ptlrpc_request_set *set)
1547 struct lov_request_set *lovset;
1548 struct lov_request *req;
1549 struct list_head *pos;
1550 struct lov_obd *lov = &exp->exp_obd->u.lov;
1555 ASSERT_LSM_MAGIC(oinfo->oi_md);
1557 if (cmd == OBD_BRW_CHECK) {
1558 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1562 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &lovset);
1566 list_for_each (pos, &lovset->set_list) {
1567 struct obd_export *sub_exp;
1568 struct brw_page *sub_pga;
1569 req = list_entry(pos, struct lov_request, rq_link);
1571 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1572 sub_pga = lovset->set_pga + req->rq_pgaidx;
1573 rc = obd_brw_async(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1577 lov_update_common_set(lovset, req, rc);
1580 LASSERT(set->set_interpret == NULL);
1581 set->set_interpret = (set_interpreter_func)lov_brw_interpret;
1582 set->set_arg = (void *)lovset;
1586 lov_fini_brw_set(lovset);
1590 static int lov_ap_make_ready(void *data, int cmd)
1592 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1594 return lap->lap_caller_ops->ap_make_ready(lap->lap_caller_data, cmd);
1597 static int lov_ap_refresh_count(void *data, int cmd)
1599 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1601 return lap->lap_caller_ops->ap_refresh_count(lap->lap_caller_data,
1605 static void lov_ap_fill_obdo(void *data, int cmd, struct obdo *oa)
1607 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1609 lap->lap_caller_ops->ap_fill_obdo(lap->lap_caller_data, cmd, oa);
1610 /* XXX woah, shouldn't we be altering more here? size? */
1611 oa->o_id = lap->lap_loi_id;
1612 oa->o_gr = lap->lap_loi_gr;
1613 oa->o_valid |= OBD_MD_FLGROUP;
1614 oa->o_stripe_idx = lap->lap_stripe;
1617 static void lov_ap_update_obdo(void *data, int cmd, struct obdo *oa,
1620 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1622 lap->lap_caller_ops->ap_update_obdo(lap->lap_caller_data, cmd,oa,valid);
1625 static int lov_ap_completion(void *data, int cmd, struct obdo *oa, int rc)
1627 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1629 /* in a raid1 regime this would down a count of many ios
1630 * in flight, onl calling the caller_ops completion when all
1631 * the raid1 ios are complete */
1632 rc = lap->lap_caller_ops->ap_completion(lap->lap_caller_data,cmd,oa,rc);
1636 static struct obd_capa *lov_ap_lookup_capa(void *data, int cmd)
1638 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1639 return lap->lap_caller_ops->ap_lookup_capa(lap->lap_caller_data, cmd);
1642 static struct obd_async_page_ops lov_async_page_ops = {
1643 .ap_make_ready = lov_ap_make_ready,
1644 .ap_refresh_count = lov_ap_refresh_count,
1645 .ap_fill_obdo = lov_ap_fill_obdo,
1646 .ap_update_obdo = lov_ap_update_obdo,
1647 .ap_completion = lov_ap_completion,
1648 .ap_lookup_capa = lov_ap_lookup_capa,
1651 int lov_prep_async_page(struct obd_export *exp, struct lov_stripe_md *lsm,
1652 struct lov_oinfo *loi, cfs_page_t *page,
1653 obd_off offset, struct obd_async_page_ops *ops,
1654 void *data, void **res)
1656 struct lov_obd *lov = &exp->exp_obd->u.lov;
1657 struct lov_async_page *lap;
1663 /* Find an existing osc so we can get it's stupid sizeof(*oap).
1664 Only because of this layering limitation will a client
1665 mount with no osts fail */
1666 while (!lov->lov_tgts || !lov->lov_tgts[i] ||
1667 !lov->lov_tgts[i]->ltd_exp) {
1669 if (i >= lov->desc.ld_tgt_count)
1672 rc = size_round(sizeof(*lap)) +
1673 obd_prep_async_page(lov->lov_tgts[i]->ltd_exp, NULL,
1674 NULL, NULL, 0, NULL, NULL, NULL);
1677 ASSERT_LSM_MAGIC(lsm);
1678 LASSERT(loi == NULL);
1681 lap->lap_magic = LOV_AP_MAGIC;
1682 lap->lap_caller_ops = ops;
1683 lap->lap_caller_data = data;
1685 /* for now only raid 0 which passes through */
1686 lap->lap_stripe = lov_stripe_number(lsm, offset);
1687 lov_stripe_offset(lsm, offset, lap->lap_stripe, &lap->lap_sub_offset);
1688 loi = lsm->lsm_oinfo[lap->lap_stripe];
1690 /* so the callback doesn't need the lsm */
1691 lap->lap_loi_id = loi->loi_id;
1692 lap->lap_loi_gr = lsm->lsm_object_gr;
1693 LASSERT(lsm->lsm_object_gr > 0);
1695 lap->lap_sub_cookie = (void *)lap + size_round(sizeof(*lap));
1697 rc = obd_prep_async_page(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1698 lsm, loi, page, lap->lap_sub_offset,
1699 &lov_async_page_ops, lap,
1700 &lap->lap_sub_cookie);
1703 CDEBUG(D_CACHE, "lap %p page %p cookie %p off "LPU64"\n", lap, page,
1704 lap->lap_sub_cookie, offset);
1708 static int lov_queue_async_io(struct obd_export *exp,
1709 struct lov_stripe_md *lsm,
1710 struct lov_oinfo *loi, void *cookie,
1711 int cmd, obd_off off, int count,
1712 obd_flag brw_flags, obd_flag async_flags)
1714 struct lov_obd *lov = &exp->exp_obd->u.lov;
1715 struct lov_async_page *lap;
1718 LASSERT(loi == NULL);
1720 ASSERT_LSM_MAGIC(lsm);
1722 lap = LAP_FROM_COOKIE(cookie);
1724 loi = lsm->lsm_oinfo[lap->lap_stripe];
1726 rc = obd_queue_async_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp, lsm,
1727 loi, lap->lap_sub_cookie, cmd, off, count,
1728 brw_flags, async_flags);
1732 static int lov_set_async_flags(struct obd_export *exp,
1733 struct lov_stripe_md *lsm,
1734 struct lov_oinfo *loi, void *cookie,
1735 obd_flag async_flags)
1737 struct lov_obd *lov = &exp->exp_obd->u.lov;
1738 struct lov_async_page *lap;
1741 LASSERT(loi == NULL);
1743 ASSERT_LSM_MAGIC(lsm);
1745 lap = LAP_FROM_COOKIE(cookie);
1747 loi = lsm->lsm_oinfo[lap->lap_stripe];
1749 rc = obd_set_async_flags(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1750 lsm, loi, lap->lap_sub_cookie, async_flags);
1754 static int lov_queue_group_io(struct obd_export *exp,
1755 struct lov_stripe_md *lsm,
1756 struct lov_oinfo *loi,
1757 struct obd_io_group *oig, void *cookie,
1758 int cmd, obd_off off, int count,
1759 obd_flag brw_flags, obd_flag async_flags)
1761 struct lov_obd *lov = &exp->exp_obd->u.lov;
1762 struct lov_async_page *lap;
1765 LASSERT(loi == NULL);
1767 ASSERT_LSM_MAGIC(lsm);
1769 lap = LAP_FROM_COOKIE(cookie);
1771 loi = lsm->lsm_oinfo[lap->lap_stripe];
1773 rc = obd_queue_group_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp, lsm,
1774 loi, oig, lap->lap_sub_cookie, cmd, off, count,
1775 brw_flags, async_flags);
1779 /* this isn't exactly optimal. we may have queued sync io in oscs on
1780 * all stripes, but we don't record that fact at queue time. so we
1781 * trigger sync io on all stripes. */
1782 static int lov_trigger_group_io(struct obd_export *exp,
1783 struct lov_stripe_md *lsm,
1784 struct lov_oinfo *loi,
1785 struct obd_io_group *oig)
1787 struct lov_obd *lov = &exp->exp_obd->u.lov;
1790 LASSERT(loi == NULL);
1792 ASSERT_LSM_MAGIC(lsm);
1794 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1795 loi = lsm->lsm_oinfo[i];
1796 if (!lov->lov_tgts[loi->loi_ost_idx] ||
1797 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1798 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1802 err = obd_trigger_group_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1804 if (rc == 0 && err != 0)
1810 static int lov_teardown_async_page(struct obd_export *exp,
1811 struct lov_stripe_md *lsm,
1812 struct lov_oinfo *loi, void *cookie)
1814 struct lov_obd *lov = &exp->exp_obd->u.lov;
1815 struct lov_async_page *lap;
1818 LASSERT(loi == NULL);
1820 ASSERT_LSM_MAGIC(lsm);
1822 lap = LAP_FROM_COOKIE(cookie);
1824 loi = lsm->lsm_oinfo[lap->lap_stripe];
1826 rc = obd_teardown_async_page(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1827 lsm, loi, lap->lap_sub_cookie);
1829 CERROR("unable to teardown sub cookie %p: %d\n",
1830 lap->lap_sub_cookie, rc);
1836 static int lov_enqueue_interpret(struct ptlrpc_request_set *rqset,
1839 struct lov_request_set *lovset = (struct lov_request_set *)data;
1841 rc = lov_fini_enqueue_set(lovset, lovset->set_ei->ei_mode, rc, rqset);
1845 static int lov_enqueue(struct obd_export *exp, struct obd_info *oinfo,
1846 struct ldlm_enqueue_info *einfo,
1847 struct ptlrpc_request_set *rqset)
1849 ldlm_mode_t mode = einfo->ei_mode;
1850 struct lov_request_set *set;
1851 struct lov_request *req;
1852 struct list_head *pos;
1853 struct lov_obd *lov;
1858 ASSERT_LSM_MAGIC(oinfo->oi_md);
1859 LASSERT(mode == (mode & -mode));
1861 /* we should never be asked to replay a lock this way. */
1862 LASSERT((oinfo->oi_flags & LDLM_FL_REPLAY) == 0);
1864 if (!exp || !exp->exp_obd)
1867 lov = &exp->exp_obd->u.lov;
1868 rc = lov_prep_enqueue_set(exp, oinfo, einfo, &set);
1872 list_for_each (pos, &set->set_list) {
1873 req = list_entry(pos, struct lov_request, rq_link);
1875 rc = obd_enqueue(lov->lov_tgts[req->rq_idx]->ltd_exp,
1876 &req->rq_oi, einfo, rqset);
1881 if (rqset && !list_empty(&rqset->set_requests)) {
1883 LASSERT(rqset->set_interpret == NULL);
1884 rqset->set_interpret = lov_enqueue_interpret;
1885 rqset->set_arg = (void *)set;
1889 rc = lov_fini_enqueue_set(set, mode, rc, rqset);
1893 static int lov_match(struct obd_export *exp, struct lov_stripe_md *lsm,
1894 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1895 int *flags, void *data, struct lustre_handle *lockh)
1897 struct lov_request_set *set;
1898 struct obd_info oinfo;
1899 struct lov_request *req;
1900 struct list_head *pos;
1901 struct lov_obd *lov = &exp->exp_obd->u.lov;
1902 struct lustre_handle *lov_lockhp;
1903 int lov_flags, rc = 0;
1906 ASSERT_LSM_MAGIC(lsm);
1907 LASSERT((*flags & LDLM_FL_TEST_LOCK) || mode == (mode & -mode));
1909 if (!exp || !exp->exp_obd)
1912 lov = &exp->exp_obd->u.lov;
1913 rc = lov_prep_match_set(exp, &oinfo, lsm, policy, mode, lockh, &set);
1917 list_for_each (pos, &set->set_list) {
1918 ldlm_policy_data_t sub_policy;
1919 req = list_entry(pos, struct lov_request, rq_link);
1920 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
1921 LASSERT(lov_lockhp);
1924 sub_policy.l_extent = req->rq_oi.oi_policy.l_extent;
1926 rc = obd_match(lov->lov_tgts[req->rq_idx]->ltd_exp,
1927 req->rq_oi.oi_md, type, &sub_policy,
1928 mode, &lov_flags, data, lov_lockhp);
1929 rc = lov_update_match_set(set, req, rc);
1933 lov_fini_match_set(set, mode, *flags);
1937 static int lov_change_cbdata(struct obd_export *exp,
1938 struct lov_stripe_md *lsm, ldlm_iterator_t it,
1941 struct lov_obd *lov;
1945 ASSERT_LSM_MAGIC(lsm);
1947 if (!exp || !exp->exp_obd)
1950 LASSERT(lsm->lsm_object_gr > 0);
1952 lov = &exp->exp_obd->u.lov;
1953 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1954 struct lov_stripe_md submd;
1955 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
1957 if (!lov->lov_tgts[loi->loi_ost_idx]) {
1958 CDEBUG(D_HA, "lov idx %d NULL \n", loi->loi_ost_idx);
1962 submd.lsm_object_id = loi->loi_id;
1963 submd.lsm_object_gr = lsm->lsm_object_gr;
1964 submd.lsm_stripe_count = 0;
1965 rc = obd_change_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1971 static int lov_cancel(struct obd_export *exp, struct lov_stripe_md *lsm,
1972 __u32 mode, struct lustre_handle *lockh)
1974 struct lov_request_set *set;
1975 struct obd_info oinfo;
1976 struct lov_request *req;
1977 struct list_head *pos;
1978 struct lov_obd *lov = &exp->exp_obd->u.lov;
1979 struct lustre_handle *lov_lockhp;
1980 int err = 0, rc = 0;
1983 ASSERT_LSM_MAGIC(lsm);
1985 if (!exp || !exp->exp_obd)
1988 LASSERT(lsm->lsm_object_gr > 0);
1990 lov = &exp->exp_obd->u.lov;
1991 rc = lov_prep_cancel_set(exp, &oinfo, lsm, mode, lockh, &set);
1995 list_for_each (pos, &set->set_list) {
1996 req = list_entry(pos, struct lov_request, rq_link);
1997 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
1999 rc = obd_cancel(lov->lov_tgts[req->rq_idx]->ltd_exp,
2000 req->rq_oi.oi_md, mode, lov_lockhp);
2001 rc = lov_update_common_set(set, req, rc);
2003 CERROR("error: cancel objid "LPX64" subobj "
2004 LPX64" on OST idx %d: rc = %d\n",
2006 req->rq_oi.oi_md->lsm_object_id,
2012 lov_fini_cancel_set(set);
2016 static int lov_cancel_unused(struct obd_export *exp,
2017 struct lov_stripe_md *lsm,
2018 int flags, void *opaque)
2020 struct lov_obd *lov;
2024 if (!exp || !exp->exp_obd)
2027 lov = &exp->exp_obd->u.lov;
2029 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2031 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2034 err = obd_cancel_unused(lov->lov_tgts[i]->ltd_exp, NULL,
2042 ASSERT_LSM_MAGIC(lsm);
2044 LASSERT(lsm->lsm_object_gr > 0);
2045 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2046 struct lov_stripe_md submd;
2047 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
2050 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2051 CDEBUG(D_HA, "lov idx %d NULL\n", loi->loi_ost_idx);
2055 if (!lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
2056 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2058 submd.lsm_object_id = loi->loi_id;
2059 submd.lsm_object_gr = lsm->lsm_object_gr;
2060 submd.lsm_stripe_count = 0;
2061 err = obd_cancel_unused(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2062 &submd, flags, opaque);
2063 if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
2064 CERROR("error: cancel unused objid "LPX64" subobj "LPX64
2065 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
2066 loi->loi_id, loi->loi_ost_idx, err);
2074 static int lov_join_lru(struct obd_export *exp,
2075 struct lov_stripe_md *lsm, int join)
2077 struct lov_obd *lov;
2081 ASSERT_LSM_MAGIC(lsm);
2082 if (!exp || !exp->exp_obd)
2085 lov = &exp->exp_obd->u.lov;
2086 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2087 struct lov_stripe_md submd;
2088 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
2091 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2092 CDEBUG(D_HA, "lov idx %d NULL\n", loi->loi_ost_idx);
2096 if (!lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
2097 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2099 submd.lsm_object_id = loi->loi_id;
2100 submd.lsm_object_gr = lsm->lsm_object_gr;
2101 submd.lsm_stripe_count = 0;
2102 rc = obd_join_lru(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2105 CERROR("join lru failed. objid: "LPX64" subobj: "LPX64
2106 " ostidx: %d rc: %d\n", lsm->lsm_object_id,
2107 loi->loi_id, loi->loi_ost_idx, rc);
2116 static int lov_statfs_interpret(struct ptlrpc_request_set *rqset,
2119 struct lov_request_set *lovset = (struct lov_request_set *)data;
2124 lovset->set_completes = 0;
2126 err = lov_fini_statfs_set(lovset);
2127 RETURN(rc ? rc : err);
2130 static int lov_statfs_async(struct obd_device *obd, struct obd_info *oinfo,
2131 __u64 max_age, struct ptlrpc_request_set *rqset)
2133 struct lov_request_set *set;
2134 struct lov_request *req;
2135 struct list_head *pos;
2136 struct lov_obd *lov;
2140 LASSERT(oinfo != NULL);
2141 LASSERT(oinfo->oi_osfs != NULL);
2144 rc = lov_prep_statfs_set(obd, oinfo, &set);
2148 list_for_each (pos, &set->set_list) {
2149 struct obd_device *osc_obd;
2151 req = list_entry(pos, struct lov_request, rq_link);
2153 osc_obd = class_exp2obd(lov->lov_tgts[req->rq_idx]->ltd_exp);
2154 rc = obd_statfs_async(osc_obd, &req->rq_oi, max_age, rqset);
2159 if (rc || list_empty(&rqset->set_requests)) {
2162 set->set_completes = 0;
2163 err = lov_fini_statfs_set(set);
2164 RETURN(rc ? rc : err);
2167 LASSERT(rqset->set_interpret == NULL);
2168 rqset->set_interpret = lov_statfs_interpret;
2169 rqset->set_arg = (void *)set;
2173 static int lov_statfs(struct obd_device *obd, struct obd_statfs *osfs,
2176 struct lov_obd *lov = &obd->u.lov;
2177 struct obd_statfs lov_sfs;
2183 /* We only get block data from the OBD */
2184 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2185 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active) {
2186 CDEBUG(D_HA, "lov idx %d inactive\n", i);
2190 err = obd_statfs(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
2193 if (lov->lov_tgts[i]->ltd_active && !rc)
2197 lov_update_statfs(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
2198 osfs, &lov_sfs, set);
2202 err = lov_fini_statfs(obd, osfs, set);
2205 RETURN(rc ? rc : err);
2208 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
2209 void *karg, void *uarg)
2211 struct obd_device *obddev = class_exp2obd(exp);
2212 struct lov_obd *lov = &obddev->u.lov;
2213 int i, rc, count = lov->desc.ld_tgt_count;
2214 struct obd_uuid *uuidp;
2218 case OBD_IOC_LOV_GET_CONFIG: {
2219 struct obd_ioctl_data *data;
2220 struct lov_desc *desc;
2225 if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
2228 data = (struct obd_ioctl_data *)buf;
2230 if (sizeof(*desc) > data->ioc_inllen1) {
2231 obd_ioctl_freedata(buf, len);
2235 if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
2236 obd_ioctl_freedata(buf, len);
2240 if (sizeof(__u32) * count > data->ioc_inllen3) {
2241 obd_ioctl_freedata(buf, len);
2245 desc = (struct lov_desc *)data->ioc_inlbuf1;
2246 memcpy(desc, &(lov->desc), sizeof(*desc));
2248 uuidp = (struct obd_uuid *)data->ioc_inlbuf2;
2249 genp = (__u32 *)data->ioc_inlbuf3;
2250 /* the uuid will be empty for deleted OSTs */
2251 for (i = 0; i < count; i++, uuidp++, genp++) {
2252 if (!lov->lov_tgts[i])
2254 *uuidp = lov->lov_tgts[i]->ltd_uuid;
2255 *genp = lov->lov_tgts[i]->ltd_gen;
2258 rc = copy_to_user((void *)uarg, buf, len);
2261 obd_ioctl_freedata(buf, len);
2264 case LL_IOC_LOV_SETSTRIPE:
2265 rc = lov_setstripe(exp, karg, uarg);
2267 case LL_IOC_LOV_GETSTRIPE:
2268 rc = lov_getstripe(exp, karg, uarg);
2270 case LL_IOC_LOV_SETEA:
2271 rc = lov_setea(exp, karg, uarg);
2280 for (i = 0; i < count; i++) {
2283 /* OST was disconnected */
2284 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2287 err = obd_iocontrol(cmd, lov->lov_tgts[i]->ltd_exp,
2289 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
2292 if (lov->lov_tgts[i]->ltd_active) {
2293 CDEBUG(err == -ENOTTY ?
2294 D_IOCTL : D_WARNING,
2295 "iocontrol OSC %s on OST "
2296 "idx %d cmd %x: err = %d\n",
2297 lov_uuid2str(lov, i),
2314 static int lov_get_info(struct obd_export *exp, __u32 keylen,
2315 void *key, __u32 *vallen, void *val)
2317 struct obd_device *obddev = class_exp2obd(exp);
2318 struct lov_obd *lov = &obddev->u.lov;
2322 if (!vallen || !val)
2327 if (KEY_IS("lock_to_stripe")) {
2330 struct ldlm_lock *lock;
2331 struct lov_stripe_md *lsm;
2333 struct ldlm_res_id *res_id = &data->lock->l_resource->lr_name;
2334 struct lov_oinfo *loi;
2335 __u32 *stripe = val;
2337 if (*vallen < sizeof(*stripe))
2338 GOTO(out, rc = -EFAULT);
2339 *vallen = sizeof(*stripe);
2341 /* XXX This is another one of those bits that will need to
2342 * change if we ever actually support nested LOVs. It uses
2343 * the lock's export to find out which stripe it is. */
2344 /* XXX - it's assumed all the locks for deleted OSTs have
2345 * been cancelled. Also, the export for deleted OSTs will
2346 * be NULL and won't match the lock's export. */
2347 for (i = 0; i < data->lsm->lsm_stripe_count; i++) {
2348 loi = data->lsm->lsm_oinfo[i];
2349 if (!lov->lov_tgts[loi->loi_ost_idx])
2351 if (lov->lov_tgts[loi->loi_ost_idx]->ltd_exp ==
2352 data->lock->l_conn_export &&
2353 loi->loi_id == res_id->name[0] &&
2354 loi->loi_gr == res_id->name[2]) {
2359 LDLM_ERROR(data->lock, "lock on inode without such object");
2360 dump_lsm(D_ERROR, data->lsm);
2361 GOTO(out, rc = -ENXIO);
2362 } else if (KEY_IS("last_id")) {
2364 unsigned int size = sizeof(obd_id);
2365 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2366 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
2368 rc = obd_get_info(lov->lov_tgts[i]->ltd_exp,
2369 keylen, key, &size, ids + i);
2374 } else if (KEY_IS(KEY_LOVDESC)) {
2375 struct lov_desc *desc_ret = val;
2376 *desc_ret = lov->desc;
2387 static int lov_set_info_async(struct obd_export *exp, obd_count keylen,
2388 void *key, obd_count vallen, void *val,
2389 struct ptlrpc_request_set *set)
2391 struct obd_device *obddev = class_exp2obd(exp);
2392 struct lov_obd *lov = &obddev->u.lov;
2396 int incr = 0, check_uuid = 0, do_inactive = 0;
2400 set = ptlrpc_prep_set();
2406 count = lov->desc.ld_tgt_count;
2408 if (KEY_IS(KEY_NEXT_ID)) {
2409 /* We must use mds's idea of # osts for indexing into
2410 mds->mds_lov_objids */
2411 count = vallen / sizeof(obd_id);
2412 LASSERT(count <= lov->desc.ld_tgt_count);
2413 vallen = sizeof(obd_id);
2414 incr = sizeof(obd_id);
2416 } else if (KEY_IS("checksum")) {
2418 } else if (KEY_IS("unlinked")) {
2419 check_uuid = val ? 1 : 0;
2420 } else if (KEY_IS("evict_by_nid")) {
2421 /* use defaults: do_inactive = incr = 0; */
2424 for (i = 0; i < count; i++, val = (char *)val + incr) {
2425 /* OST was disconnected */
2426 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2429 /* OST is inactive and we don't want inactive OSCs */
2430 if (!lov->lov_tgts[i]->ltd_active && !do_inactive)
2433 if (KEY_IS(KEY_MDS_CONN)) {
2434 struct mds_group_info *mgi;
2436 LASSERT(vallen == sizeof(*mgi));
2437 mgi = (struct mds_group_info *)val;
2439 /* Only want a specific OSC */
2440 if (mgi->uuid && !obd_uuid_equals(mgi->uuid,
2441 &lov->lov_tgts[i]->ltd_uuid))
2444 err = obd_set_info_async(lov->lov_tgts[i]->ltd_exp,
2445 keylen, key, sizeof(int),
2448 /* Only want a specific OSC */
2450 !obd_uuid_equals(val, &lov->lov_tgts[i]->ltd_uuid))
2453 err = obd_set_info_async(lov->lov_tgts[i]->ltd_exp,
2454 keylen, key, vallen, val, set);
2463 err = ptlrpc_set_wait(set);
2466 ptlrpc_set_destroy(set);
2471 static int lov_checkmd(struct obd_export *exp, struct obd_export *md_exp,
2472 struct lov_stripe_md *lsm)
2480 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
2481 rc = lsm_op_find(lsm->lsm_magic)->lsm_revalidate(lsm, md_exp->exp_obd);
2486 int lov_test_and_clear_async_rc(struct lov_stripe_md *lsm)
2491 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2492 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
2493 if (loi->loi_ar.ar_rc && !rc)
2494 rc = loi->loi_ar.ar_rc;
2495 loi->loi_ar.ar_rc = 0;
2499 EXPORT_SYMBOL(lov_test_and_clear_async_rc);
2502 static int lov_extent_calc(struct obd_export *exp, struct lov_stripe_md *lsm,
2503 int cmd, __u64 *offset)
2505 __u32 ssize = lsm->lsm_stripe_size;
2509 do_div(start, ssize);
2510 start = start * ssize;
2512 CDEBUG(D_DLMTRACE, "offset "LPU64", stripe %u, start "LPU64
2513 ", end "LPU64"\n", *offset, ssize, start,
2515 if (cmd == OBD_CALC_STRIPE_END) {
2516 *offset = start + ssize - 1;
2517 } else if (cmd == OBD_CALC_STRIPE_START) {
2528 struct lov_multi_wait {
2529 struct ldlm_lock *lock;
2535 int lov_complete_many(struct obd_export *exp, struct lov_stripe_md *lsm,
2536 struct lustre_handle *lockh)
2538 struct lov_lock_handles *lov_lockh = NULL;
2539 struct lustre_handle *lov_lockhp;
2540 struct lov_obd *lov;
2541 struct lov_oinfo *loi;
2542 struct lov_multi_wait *queues;
2546 ASSERT_LSM_MAGIC(lsm);
2548 if (!exp || !exp->exp_obd)
2551 LASSERT(lockh != NULL);
2552 if (lsm->lsm_stripe_count > 1) {
2553 lov_lockh = lov_handle2llh(lockh);
2554 if (lov_lockh == NULL) {
2555 CERROR("LOV: invalid lov lock handle %p\n", lockh);
2559 lov_lockhp = lov_lockh->llh_handles;
2564 OBD_ALLOC(queues, lsm->lsm_stripe_count * sizeof(*queues));
2566 GOTO(out, rc = -ENOMEM);
2568 lov = &exp->exp_obd->u.lov;
2569 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
2570 i++, loi++, lov_lockhp++) {
2571 struct ldlm_lock *lock;
2572 struct obd_device *obd;
2574 lock = ldlm_handle2lock(lov_lockhp);
2576 CDEBUG(D_HA, "lov idx %d subobj "LPX64" no lock?\n",
2577 loi->loi_ost_idx, loi->loi_id);
2578 queues[i].completed = 1;
2582 queues[i].lock = lock;
2583 init_waitqueue_entry(&(queues[i].wait), current);
2584 add_wait_queue(lock->l_waitq, &(queues[i].wait));
2586 obd = class_exp2obd(lock->l_conn_export);
2588 imp = obd->u.cli.cl_import;
2590 spin_lock(&imp->imp_lock);
2591 queues[i].generation = imp->imp_generation;
2592 spin_unlock(&imp->imp_lock);
2596 lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, ldlm_expired_completion_wait,
2597 interrupted_completion_wait, &lwd);
2598 rc = l_wait_event_added(check_multi_complete(queues, lsm), &lwi);
2600 for (i = 0; i < lsm->lsm_stripe_count; i++)
2601 remove_wait_queue(lock->l_waitq, &(queues[i].wait));
2603 if (rc == -EINTR || rc == -ETIMEDOUT) {
2609 if (lov_lockh != NULL)
2610 lov_llh_put(lov_lockh);
2615 void lov_stripe_lock(struct lov_stripe_md *md)
2617 LASSERT(md->lsm_lock_owner != cfs_current());
2618 spin_lock(&md->lsm_lock);
2619 LASSERT(md->lsm_lock_owner == NULL);
2620 md->lsm_lock_owner = cfs_current();
2622 EXPORT_SYMBOL(lov_stripe_lock);
2624 void lov_stripe_unlock(struct lov_stripe_md *md)
2626 LASSERT(md->lsm_lock_owner == cfs_current());
2627 md->lsm_lock_owner = NULL;
2628 spin_unlock(&md->lsm_lock);
2630 EXPORT_SYMBOL(lov_stripe_unlock);
2632 struct obd_ops lov_obd_ops = {
2633 .o_owner = THIS_MODULE,
2634 .o_setup = lov_setup,
2635 .o_precleanup = lov_precleanup,
2636 .o_cleanup = lov_cleanup,
2637 .o_process_config = lov_process_config,
2638 .o_connect = lov_connect,
2639 .o_disconnect = lov_disconnect,
2640 .o_statfs = lov_statfs,
2641 .o_statfs_async = lov_statfs_async,
2642 .o_packmd = lov_packmd,
2643 .o_unpackmd = lov_unpackmd,
2644 .o_checkmd = lov_checkmd,
2645 .o_create = lov_create,
2646 .o_destroy = lov_destroy,
2647 .o_getattr = lov_getattr,
2648 .o_getattr_async = lov_getattr_async,
2649 .o_setattr = lov_setattr,
2650 .o_setattr_async = lov_setattr_async,
2652 .o_brw_async = lov_brw_async,
2653 .o_prep_async_page = lov_prep_async_page,
2654 .o_queue_async_io = lov_queue_async_io,
2655 .o_set_async_flags = lov_set_async_flags,
2656 .o_queue_group_io = lov_queue_group_io,
2657 .o_trigger_group_io = lov_trigger_group_io,
2658 .o_teardown_async_page = lov_teardown_async_page,
2659 .o_merge_lvb = lov_merge_lvb,
2660 .o_adjust_kms = lov_adjust_kms,
2661 .o_punch = lov_punch,
2663 .o_enqueue = lov_enqueue,
2664 .o_match = lov_match,
2665 .o_change_cbdata = lov_change_cbdata,
2666 .o_cancel = lov_cancel,
2667 .o_cancel_unused = lov_cancel_unused,
2668 .o_join_lru = lov_join_lru,
2669 .o_iocontrol = lov_iocontrol,
2670 .o_get_info = lov_get_info,
2671 .o_set_info_async = lov_set_info_async,
2672 .o_extent_calc = lov_extent_calc,
2673 .o_llog_init = lov_llog_init,
2674 .o_llog_finish = lov_llog_finish,
2675 .o_notify = lov_notify,
2678 static quota_interface_t *quota_interface;
2679 extern quota_interface_t lov_quota_interface;
2681 cfs_mem_cache_t *lov_oinfo_slab;
2683 int __init lov_init(void)
2685 struct lprocfs_static_vars lvars;
2689 lov_oinfo_slab = cfs_mem_cache_create("lov_oinfo",
2690 sizeof(struct lov_oinfo),
2691 0, SLAB_HWCACHE_ALIGN);
2692 if (lov_oinfo_slab == NULL)
2694 lprocfs_init_vars(lov, &lvars);
2696 request_module("lquota");
2697 quota_interface = PORTAL_SYMBOL_GET(lov_quota_interface);
2698 init_obd_quota_ops(quota_interface, &lov_obd_ops);
2700 rc = class_register_type(&lov_obd_ops, NULL, lvars.module_vars,
2701 LUSTRE_LOV_NAME, NULL);
2703 if (quota_interface)
2704 PORTAL_SYMBOL_PUT(lov_quota_interface);
2705 rc2 = cfs_mem_cache_destroy(lov_oinfo_slab);
2713 static void /*__exit*/ lov_exit(void)
2717 if (quota_interface)
2718 PORTAL_SYMBOL_PUT(lov_quota_interface);
2720 class_unregister_type(LUSTRE_LOV_NAME);
2721 rc = cfs_mem_cache_destroy(lov_oinfo_slab);
2725 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2726 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver");
2727 MODULE_LICENSE("GPL");
2729 cfs_module(lov, LUSTRE_VERSION_STRING, lov_init, lov_exit);