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;
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_uuid = lov->lov_tgts[index]->ltd_uuid;
110 tgt_obd = class_find_client_obd(&tgt_uuid, LUSTRE_OSC_NAME,
114 CERROR("Target %s not attached\n", obd_uuid2str(&tgt_uuid));
118 if (!tgt_obd->obd_set_up) {
119 CERROR("Target %s not set up\n", obd_uuid2str(&tgt_uuid));
123 if (data && (data->ocd_connect_flags & OBD_CONNECT_INDEX))
124 data->ocd_index = index;
127 * Divine LOV knows that OBDs under it are OSCs.
129 imp = tgt_obd->u.cli.cl_import;
132 tgt_obd->obd_no_recov = 0;
133 /* FIXME this is probably supposed to be
134 ptlrpc_set_import_active. Horrible naming. */
135 ptlrpc_activate_import(imp);
138 if (imp->imp_invalid) {
139 CERROR("not connecting OSC %s; administratively "
140 "disabled\n", obd_uuid2str(&tgt_uuid));
141 rc = obd_register_observer(tgt_obd, obd);
143 CERROR("Target %s register_observer error %d; "
144 "will not be able to reactivate\n",
145 obd_uuid2str(&tgt_uuid), rc);
150 rc = obd_connect(&conn, tgt_obd, &lov_osc_uuid, data);
152 CERROR("Target %s connect error %d\n",
153 obd_uuid2str(&tgt_uuid), rc);
156 lov->lov_tgts[index]->ltd_exp = class_conn2export(&conn);
157 if (!lov->lov_tgts[index]->ltd_exp) {
158 CERROR("Target %s: null export!\n", obd_uuid2str(&tgt_uuid));
162 rc = obd_register_observer(tgt_obd, obd);
164 CERROR("Target %s register_observer error %d\n",
165 obd_uuid2str(&tgt_uuid), rc);
166 obd_disconnect(lov->lov_tgts[index]->ltd_exp);
167 lov->lov_tgts[index]->ltd_exp = NULL;
171 lov->lov_tgts[index]->ltd_reap = 0;
173 lov->lov_tgts[index]->ltd_active = 1;
174 lov->desc.ld_active_tgt_count++;
176 CDEBUG(D_CONFIG, "Connected tgt idx %d %s (%s) %sactive\n", index,
177 obd_uuid2str(&tgt_uuid), tgt_obd->obd_name, activate ? "":"in");
180 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
182 struct obd_device *osc_obd = class_conn2obd(&conn);
183 cfs_proc_dir_entry_t *osc_symlink;
184 char name[MAX_STRING_SIZE];
186 LASSERT(osc_obd != NULL);
187 LASSERT(osc_obd->obd_magic == OBD_DEVICE_MAGIC);
188 LASSERT(osc_obd->obd_type->typ_name != NULL);
189 snprintf(name, MAX_STRING_SIZE, "../../../%s/%s",
190 osc_obd->obd_type->typ_name,
192 osc_symlink = proc_symlink(osc_obd->obd_name, lov_proc_dir,
194 if (osc_symlink == NULL) {
195 CERROR("could not register LOV target "
196 "/proc/fs/lustre/%s/%s/target_obds/%s.",
197 obd->obd_type->typ_name, obd->obd_name,
199 lprocfs_remove(&lov_proc_dir);
204 rc = qos_add_tgt(obd, index);
206 CERROR("qos_add_tgt failed %d\n", rc);
211 static int lov_connect(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, lov->lov_tgts[i]->ltd_activate,
242 CERROR("%s: lov connect tgt %d failed: %d\n",
243 obd->obd_name, i, rc);
252 static int lov_disconnect_obd(struct obd_device *obd, __u32 index)
254 cfs_proc_dir_entry_t *lov_proc_dir;
255 struct lov_obd *lov = &obd->u.lov;
256 struct obd_device *osc_obd =
257 class_exp2obd(lov->lov_tgts[index]->ltd_exp);
261 CDEBUG(D_CONFIG, "%s: disconnecting target %s\n",
262 obd->obd_name, osc_obd->obd_name);
264 if (lov->lov_tgts[index]->ltd_active) {
265 lov->lov_tgts[index]->ltd_active = 0;
266 lov->desc.ld_active_tgt_count--;
269 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
271 cfs_proc_dir_entry_t *osc_symlink;
273 osc_symlink = lprocfs_srch(lov_proc_dir, osc_obd->obd_name);
275 lprocfs_remove(&osc_symlink);
277 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing.",
278 obd->obd_type->typ_name, obd->obd_name,
283 if (obd->obd_no_recov) {
284 /* Pass it on to our clients.
285 * XXX This should be an argument to disconnect,
286 * XXX not a back-door flag on the OBD. Ah well.
289 osc_obd->obd_no_recov = 1;
292 obd_register_observer(osc_obd, NULL);
294 rc = obd_disconnect(lov->lov_tgts[index]->ltd_exp);
296 CERROR("Target %s disconnect error %d\n",
297 lov_uuid2str(lov, index), rc);
301 qos_del_tgt(obd, index);
303 lov->lov_tgts[index]->ltd_exp = NULL;
307 static int lov_del_target(struct obd_device *obd, __u32 index,
308 struct obd_uuid *uuidp, int gen);
310 static int lov_disconnect(struct obd_export *exp)
312 struct obd_device *obd = class_exp2obd(exp);
313 struct lov_obd *lov = &obd->u.lov;
320 /* Only disconnect the underlying layers on the final disconnect. */
322 if (lov->lov_connects != 0) {
323 /* why should there be more than 1 connect? */
324 CERROR("disconnect #%d\n", lov->lov_connects);
328 /* Let's hold another reference so lov_del_obd doesn't spin through
331 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
332 if (lov->lov_tgts[i] && lov->lov_tgts[i]->ltd_exp) {
333 /* Disconnection is the last we know about an obd */
334 lov_del_target(obd, i, 0, lov->lov_tgts[i]->ltd_gen);
340 rc = class_disconnect(exp); /* bz 9811 */
346 * -EINVAL : UUID can't be found in the LOV's target list
347 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
348 * -EBADF : The UUID is found, but the OBD is the wrong type (!)
350 static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
353 struct lov_obd *lov = &obd->u.lov;
354 struct lov_tgt_desc *tgt;
358 CDEBUG(D_INFO, "Searching in lov %p for uuid %s (activate=%d)\n",
359 lov, uuid->uuid, activate);
362 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
363 tgt = lov->lov_tgts[i];
364 if (!tgt || !tgt->ltd_exp)
367 CDEBUG(D_INFO, "lov idx %d is %s conn "LPX64"\n",
368 i, obd_uuid2str(&tgt->ltd_uuid),
369 tgt->ltd_exp->exp_handle.h_cookie);
370 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
374 if (i == lov->desc.ld_tgt_count)
375 GOTO(out, rc = -EINVAL);
377 if (lov->lov_tgts[i]->ltd_active == activate) {
378 CDEBUG(D_INFO, "OSC %s already %sactive!\n", uuid->uuid,
379 activate ? "" : "in");
383 CDEBUG(D_CONFIG, "Marking OSC %s %sactive\n", obd_uuid2str(uuid),
384 activate ? "" : "in");
386 lov->lov_tgts[i]->ltd_active = activate;
388 lov->desc.ld_active_tgt_count++;
390 lov->desc.ld_active_tgt_count--;
391 /* remove any old qos penalty */
392 lov->lov_tgts[i]->ltd_qos.ltq_penalty = 0;
399 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
400 enum obd_notify_event ev, void *data)
405 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
406 struct obd_uuid *uuid;
410 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
411 CERROR("unexpected notification of %s %s!\n",
412 watched->obd_type->typ_name,
416 uuid = &watched->u.cli.cl_target_uuid;
418 /* Set OSC as active before notifying the observer, so the
419 * observer can use the OSC normally.
421 rc = lov_set_osc_active(obd, uuid, ev == OBD_NOTIFY_ACTIVE);
423 CERROR("%sactivation of %s failed: %d\n",
424 (ev == OBD_NOTIFY_ACTIVE) ? "" : "de",
425 obd_uuid2str(uuid), rc);
430 /* Pass the notification up the chain. */
432 rc = obd_notify_observer(obd, watched, ev, data);
434 /* NULL watched means all osc's in the lov (only for syncs) */
435 struct lov_obd *lov = &obd->u.lov;
436 struct obd_device *tgt_obd;
439 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
440 if (!lov->lov_tgts[i])
442 tgt_obd = class_exp2obd(lov->lov_tgts[i]->ltd_exp);
443 rc = obd_notify_observer(obd, tgt_obd, ev, data);
445 CERROR("%s: notify %s of %s failed %d\n",
447 obd->obd_observer->obd_name,
448 tgt_obd->obd_name, rc);
458 static int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
459 __u32 index, int gen, int active)
461 struct lov_obd *lov = &obd->u.lov;
462 struct lov_tgt_desc *tgt;
466 CDEBUG(D_CONFIG, "uuid:%s idx:%d gen:%d active:%d\n",
467 uuidp->uuid, index, gen, active);
470 CERROR("request to add OBD %s with invalid generation: %d\n",
475 mutex_down(&lov->lov_lock);
477 if ((index < lov->lov_tgt_size) && (lov->lov_tgts[index] != NULL)) {
478 tgt = lov->lov_tgts[index];
479 CERROR("UUID %s already assigned at LOV target index %d\n",
480 obd_uuid2str(&tgt->ltd_uuid), index);
481 mutex_up(&lov->lov_lock);
485 if (index >= lov->lov_tgt_size) {
486 /* We need to reallocate the lov target array. */
487 struct lov_tgt_desc **newtgts, **old = NULL;
488 __u32 newsize, oldsize = 0;
490 newsize = max(lov->lov_tgt_size, (__u32)2);
491 while (newsize < index + 1)
492 newsize = newsize << 1;
493 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
494 if (newtgts == NULL) {
495 mutex_up(&lov->lov_lock);
499 if (lov->lov_tgt_size) {
500 memcpy(newtgts, lov->lov_tgts, sizeof(*newtgts) *
503 oldsize = lov->lov_tgt_size;
506 lov->lov_tgts = newtgts;
507 lov->lov_tgt_size = newsize;
512 OBD_FREE(old, sizeof(*old) * oldsize);
514 CDEBUG(D_CONFIG, "tgts: %p size: %d\n",
515 lov->lov_tgts, lov->lov_tgt_size);
521 mutex_up(&lov->lov_lock);
525 memset(tgt, 0, sizeof(*tgt));
526 tgt->ltd_uuid = *uuidp;
527 /* XXX - add a sanity check on the generation number. */
529 tgt->ltd_index = index;
530 tgt->ltd_activate = active;
531 lov->lov_tgts[index] = tgt;
532 if (index >= lov->desc.ld_tgt_count)
533 lov->desc.ld_tgt_count = index + 1;
534 mutex_up(&lov->lov_lock);
536 CDEBUG(D_CONFIG, "idx=%d ltd_gen=%d ld_tgt_count=%d\n",
537 index, tgt->ltd_gen, lov->desc.ld_tgt_count);
539 if (lov->lov_connects == 0) {
540 /* lov_connect hasn't been called yet. We'll do the
541 lov_connect_obd on this target when that fn first runs,
542 because we don't know the connect flags yet. */
548 rc = lov_connect_obd(obd, index, active, &lov->lov_ocd);
552 rc = lov_notify(obd, tgt->ltd_exp->exp_obd,
553 active ? OBD_NOTIFY_ACTIVE : OBD_NOTIFY_INACTIVE,
558 CERROR("add failed (%d), deleting %s\n", rc,
559 obd_uuid2str(&tgt->ltd_uuid));
560 lov_del_target(obd, index, 0, 0);
566 /* Schedule a target for deletion */
567 static int lov_del_target(struct obd_device *obd, __u32 index,
568 struct obd_uuid *uuidp, int gen)
570 struct lov_obd *lov = &obd->u.lov;
571 int count = lov->desc.ld_tgt_count;
575 if (index >= count) {
576 CERROR("LOV target index %d >= number of LOV OBDs %d.\n",
583 if (!lov->lov_tgts[index]) {
584 CERROR("LOV target at index %d is not setup.\n", index);
585 GOTO(out, rc = -EINVAL);
588 if (uuidp && !obd_uuid_equals(uuidp, &lov->lov_tgts[index]->ltd_uuid)) {
589 CERROR("LOV target UUID %s at index %d doesn't match %s.\n",
590 lov_uuid2str(lov, index), index,
591 obd_uuid2str(uuidp));
592 GOTO(out, rc = -EINVAL);
595 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d exp: %p active: %d\n",
596 lov_uuid2str(lov, index), index,
597 lov->lov_tgts[index]->ltd_gen, lov->lov_tgts[index]->ltd_exp,
598 lov->lov_tgts[index]->ltd_active);
600 lov->lov_tgts[index]->ltd_reap = 1;
601 lov->lov_death_row++;
602 /* we really delete it from lov_putref */
609 /* We are holding lov_lock */
610 static void __lov_del_obd(struct obd_device *obd, __u32 index)
612 struct lov_obd *lov = &obd->u.lov;
613 struct obd_device *osc_obd;
614 struct lov_tgt_desc *tgt = lov->lov_tgts[index];
617 LASSERT(tgt->ltd_reap);
619 osc_obd = class_exp2obd(tgt->ltd_exp);
621 CDEBUG(D_CONFIG, "Removing tgt %s : %s\n",
622 lov_uuid2str(lov, index),
623 osc_obd ? osc_obd->obd_name : "<no obd>");
626 lov_disconnect_obd(obd, index);
628 /* XXX - right now there is a dependency on ld_tgt_count being the
629 * maximum tgt index for computing the mds_max_easize. So we can't
632 lov->lov_tgts[index] = NULL;
635 /* Manual cleanup - no cleanup logs to clean up the osc's. We must
636 do it ourselves. And we can't do it from lov_cleanup,
637 because we just lost our only reference to it. */
639 /* Use lov's force/fail flags. */
640 osc_obd->obd_force = obd->obd_force;
641 osc_obd->obd_fail = obd->obd_fail;
642 class_manual_cleanup(osc_obd);
646 void lov_fix_desc(struct lov_desc *desc)
648 if (desc->ld_default_stripe_size < PTLRPC_MAX_BRW_SIZE) {
649 LCONSOLE_WARN("Increasing default stripe size to min %u\n",
650 PTLRPC_MAX_BRW_SIZE);
651 desc->ld_default_stripe_size = PTLRPC_MAX_BRW_SIZE;
652 } else if (desc->ld_default_stripe_size & (LOV_MIN_STRIPE_SIZE - 1)) {
653 desc->ld_default_stripe_size &= ~(LOV_MIN_STRIPE_SIZE - 1);
654 LCONSOLE_WARN("Changing default stripe size to "LPU64" (a "
656 desc->ld_default_stripe_size,LOV_MIN_STRIPE_SIZE);
659 if (desc->ld_default_stripe_count == 0)
660 desc->ld_default_stripe_count = 1;
662 /* from lov_setstripe */
663 if ((desc->ld_pattern != 0) &&
664 (desc->ld_pattern != LOV_PATTERN_RAID0)) {
665 LCONSOLE_WARN("Unknown stripe pattern: %#x\n",desc->ld_pattern);
666 desc->ld_pattern = 0;
669 if (desc->ld_qos_maxage == 0)
670 desc->ld_qos_maxage = QOS_DEFAULT_MAXAGE;
673 static int lov_setup(struct obd_device *obd, obd_count len, void *buf)
675 struct lprocfs_static_vars lvars;
676 struct lustre_cfg *lcfg = buf;
677 struct lov_desc *desc;
678 struct lov_obd *lov = &obd->u.lov;
682 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
683 CERROR("LOV setup requires a descriptor\n");
687 desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
689 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
690 CERROR("descriptor size wrong: %d > %d\n",
691 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
695 if (desc->ld_magic != LOV_DESC_MAGIC) {
696 if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
697 CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n",
698 obd->obd_name, desc);
699 lustre_swab_lov_desc(desc);
701 CERROR("%s: Bad lov desc magic: %#x\n",
702 obd->obd_name, desc->ld_magic);
709 /* Because of 64-bit divide/mod operations only work with a 32-bit
710 * divisor in a 32-bit kernel, we cannot support a stripe width
711 * of 4GB or larger on 32-bit CPUs. */
712 count = desc->ld_default_stripe_count;
713 if ((count > 0 ? count : desc->ld_tgt_count) *
714 desc->ld_default_stripe_size > 0xffffffff) {
715 CERROR("LOV: stripe width "LPU64"x%u > 4294967295 bytes\n",
716 desc->ld_default_stripe_size, count);
720 desc->ld_active_tgt_count = 0;
722 lov->lov_tgt_size = 0;
723 sema_init(&lov->lov_lock, 1);
724 atomic_set(&lov->lov_refcount, 0);
725 INIT_LIST_HEAD(&lov->lov_qos.lq_oss_list);
726 init_rwsem(&lov->lov_qos.lq_rw_sem);
727 lov->lov_qos.lq_dirty = 1;
728 lov->lov_qos.lq_dirty_rr = 1;
729 lov->lov_qos.lq_reset = 1;
730 /* Default priority is toward free space balance */
731 lov->lov_qos.lq_prio_free = 232;
733 lprocfs_init_vars(lov, &lvars);
734 lprocfs_obd_setup(obd, lvars.obd_vars);
737 cfs_proc_dir_entry_t *entry;
739 entry = create_proc_entry("target_obd", 0444,
740 obd->obd_proc_entry);
742 entry->proc_fops = &lov_proc_target_fops;
751 static int lov_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
757 case OBD_CLEANUP_EARLY: {
758 struct lov_obd *lov = &obd->u.lov;
760 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
761 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
763 obd_precleanup(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
768 case OBD_CLEANUP_EXPORTS:
770 case OBD_CLEANUP_SELF_EXP:
771 rc = obd_llog_finish(obd, 0);
773 CERROR("failed to cleanup llogging subsystems\n");
775 case OBD_CLEANUP_OBD:
781 static int lov_cleanup(struct obd_device *obd)
783 struct lov_obd *lov = &obd->u.lov;
785 lprocfs_obd_cleanup(obd);
788 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
789 if (lov->lov_tgts[i]) {
790 /* Inactive targets may never have connected */
791 if (lov->lov_tgts[i]->ltd_active ||
792 atomic_read(&lov->lov_refcount))
793 /* We should never get here - these
794 should have been removed in the
796 CERROR("lov tgt %d not cleaned!"
797 " deathrow=%d, lovrc=%d\n",
798 i, lov->lov_death_row,
799 atomic_read(&lov->lov_refcount));
800 lov_del_target(obd, i, 0, 0);
803 OBD_FREE(lov->lov_tgts, sizeof(*lov->lov_tgts) *
805 lov->lov_tgt_size = 0;
808 if (lov->lov_qos.lq_rr_size)
809 OBD_FREE(lov->lov_qos.lq_rr_array, lov->lov_qos.lq_rr_size);
814 static int lov_process_config(struct obd_device *obd, obd_count len, void *buf)
816 struct lustre_cfg *lcfg = buf;
817 struct obd_uuid obd_uuid;
822 switch(cmd = lcfg->lcfg_command) {
823 case LCFG_LOV_ADD_OBD:
824 case LCFG_LOV_ADD_INA:
825 case LCFG_LOV_DEL_OBD: {
828 /* lov_modify_tgts add 0:lov_mdsA 1:ost1_UUID 2:0 3:1 */
829 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
830 GOTO(out, rc = -EINVAL);
832 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
834 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
835 GOTO(out, rc = -EINVAL);
836 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
837 GOTO(out, rc = -EINVAL);
838 if (cmd == LCFG_LOV_ADD_OBD)
839 rc = lov_add_target(obd, &obd_uuid, index, gen, 1);
840 else if (cmd == LCFG_LOV_ADD_INA)
841 rc = lov_add_target(obd, &obd_uuid, index, gen, 0);
843 rc = lov_del_target(obd, index, &obd_uuid, gen);
847 struct lprocfs_static_vars lvars;
848 struct lov_desc *desc = &(obd->u.lov.desc);
851 GOTO(out, rc = -EINVAL);
853 lprocfs_init_vars(lov, &lvars);
855 rc = class_process_proc_param(PARAM_LOV, lvars.obd_vars,
860 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
861 GOTO(out, rc = -EINVAL);
870 #define log2(n) ffz(~(n))
873 static int lov_clear_orphans(struct obd_export *export, struct obdo *src_oa,
874 struct lov_stripe_md **ea,
875 struct obd_trans_info *oti)
879 struct obd_uuid *ost_uuid = NULL;
883 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
884 src_oa->o_flags == OBD_FL_DELORPHAN);
886 lov = &export->exp_obd->u.lov;
892 if (src_oa->o_valid & OBD_MD_FLINLINE) {
893 ost_uuid = (struct obd_uuid *)src_oa->o_inline;
894 CDEBUG(D_HA, "clearing orphans only for %s\n",
898 lov_getref(export->exp_obd);
899 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
900 struct lov_stripe_md obj_md;
901 struct lov_stripe_md *obj_mdp = &obj_md;
902 struct lov_tgt_desc *tgt;
905 tgt = lov->lov_tgts[i];
909 /* if called for a specific target, we don't
910 care if it is not active. */
911 if (!lov->lov_tgts[i]->ltd_active && ost_uuid == NULL) {
912 CDEBUG(D_HA, "lov idx %d inactive\n", i);
916 if (ost_uuid && !obd_uuid_equals(ost_uuid, &tgt->ltd_uuid))
919 CDEBUG(D_CONFIG,"Clear orphans for %d:%s\n", i,
920 obd_uuid2str(ost_uuid));
922 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
924 LASSERT(lov->lov_tgts[i]->ltd_exp);
925 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
926 err = obd_create(lov->lov_tgts[i]->ltd_exp,
927 tmp_oa, &obj_mdp, oti);
929 /* This export will be disabled until it is recovered,
930 and then orphan recovery will be completed. */
931 CERROR("error in orphan recovery on OST idx %d/%d: "
932 "rc = %d\n", i, lov->desc.ld_tgt_count, err);
937 lov_putref(export->exp_obd);
943 static int lov_recreate(struct obd_export *exp, struct obdo *src_oa,
944 struct lov_stripe_md **ea, struct obd_trans_info *oti)
946 struct lov_stripe_md *obj_mdp, *lsm;
947 struct lov_obd *lov = &exp->exp_obd->u.lov;
952 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
953 src_oa->o_flags & OBD_FL_RECREATE_OBJS);
955 OBD_ALLOC(obj_mdp, sizeof(*obj_mdp));
959 ost_idx = src_oa->o_nlink;
962 GOTO(out, rc = -EINVAL);
963 if (ost_idx >= lov->desc.ld_tgt_count ||
964 !lov->lov_tgts[ost_idx])
965 GOTO(out, rc = -EINVAL);
967 for (i = 0; i < lsm->lsm_stripe_count; i++) {
968 if (lsm->lsm_oinfo[i]->loi_ost_idx == ost_idx) {
969 if (lsm->lsm_oinfo[i]->loi_id != src_oa->o_id)
970 GOTO(out, rc = -EINVAL);
974 if (i == lsm->lsm_stripe_count)
975 GOTO(out, rc = -EINVAL);
977 rc = obd_create(lov->lov_tgts[ost_idx]->ltd_exp, src_oa, &obj_mdp, oti);
979 OBD_FREE(obj_mdp, sizeof(*obj_mdp));
983 /* the LOV expects oa->o_id to be set to the LOV object id */
984 static int lov_create(struct obd_export *exp, struct obdo *src_oa,
985 struct lov_stripe_md **ea, struct obd_trans_info *oti)
988 struct obd_info oinfo;
989 struct lov_request_set *set = NULL;
990 struct lov_request *req;
991 struct obd_statfs osfs;
1000 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1001 src_oa->o_flags == OBD_FL_DELORPHAN) {
1002 rc = lov_clear_orphans(exp, src_oa, ea, oti);
1006 lov = &exp->exp_obd->u.lov;
1007 if (!lov->desc.ld_active_tgt_count)
1010 /* Recreate a specific object id at the given OST index */
1011 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1012 (src_oa->o_flags & OBD_FL_RECREATE_OBJS)) {
1013 rc = lov_recreate(exp, src_oa, ea, oti);
1017 maxage = cfs_time_shift_64(-lov->desc.ld_qos_maxage);
1018 obd_statfs_rqset(exp->exp_obd, &osfs, maxage);
1020 rc = lov_prep_create_set(exp, &oinfo, ea, src_oa, oti, &set);
1024 list_for_each_entry(req, &set->set_list, rq_link) {
1025 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1026 rc = obd_create(lov->lov_tgts[req->rq_idx]->ltd_exp,
1027 req->rq_oi.oi_oa, &req->rq_oi.oi_md, oti);
1028 lov_update_create_set(set, req, rc);
1030 rc = lov_fini_create_set(set, ea);
1034 #define ASSERT_LSM_MAGIC(lsmp) \
1036 LASSERT((lsmp) != NULL); \
1037 LASSERTF(((lsmp)->lsm_magic == LOV_MAGIC || \
1038 (lsmp)->lsm_magic == LOV_MAGIC_JOIN), "%p->lsm_magic=%x\n", \
1039 (lsmp), (lsmp)->lsm_magic); \
1042 static int lov_destroy(struct obd_export *exp, struct obdo *oa,
1043 struct lov_stripe_md *lsm, struct obd_trans_info *oti,
1044 struct obd_export *md_exp)
1046 struct lov_request_set *set;
1047 struct obd_info oinfo;
1048 struct lov_request *req;
1049 struct list_head *pos;
1050 struct lov_obd *lov;
1054 ASSERT_LSM_MAGIC(lsm);
1056 if (!exp || !exp->exp_obd)
1059 if (oa->o_valid & OBD_MD_FLCOOKIE) {
1061 LASSERT(oti->oti_logcookies);
1064 lov = &exp->exp_obd->u.lov;
1065 rc = lov_prep_destroy_set(exp, &oinfo, oa, lsm, oti, &set);
1069 list_for_each (pos, &set->set_list) {
1071 req = list_entry(pos, struct lov_request, rq_link);
1073 if (oa->o_valid & OBD_MD_FLCOOKIE)
1074 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1076 err = obd_destroy(lov->lov_tgts[req->rq_idx]->ltd_exp,
1077 req->rq_oi.oi_oa, NULL, oti, NULL);
1078 err = lov_update_common_set(set, req, err);
1080 CERROR("error: destroying objid "LPX64" subobj "
1081 LPX64" on OST idx %d: rc = %d\n",
1082 oa->o_id, req->rq_oi.oi_oa->o_id,
1090 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
1091 rc = lsm_op_find(lsm->lsm_magic)->lsm_destroy(lsm, oa, md_exp);
1093 err = lov_fini_destroy_set(set);
1094 RETURN(rc ? rc : err);
1097 static int lov_getattr(struct obd_export *exp, struct obd_info *oinfo)
1099 struct lov_request_set *set;
1100 struct lov_request *req;
1101 struct list_head *pos;
1102 struct lov_obd *lov;
1103 int err = 0, rc = 0;
1107 ASSERT_LSM_MAGIC(oinfo->oi_md);
1109 if (!exp || !exp->exp_obd)
1112 lov = &exp->exp_obd->u.lov;
1114 rc = lov_prep_getattr_set(exp, oinfo, &set);
1118 list_for_each (pos, &set->set_list) {
1119 req = list_entry(pos, struct lov_request, rq_link);
1121 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1122 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1123 req->rq_oi.oi_oa->o_id, req->rq_idx);
1125 rc = obd_getattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1127 err = lov_update_common_set(set, req, rc);
1129 CERROR("error: getattr objid "LPX64" subobj "
1130 LPX64" on OST idx %d: rc = %d\n",
1131 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1137 rc = lov_fini_getattr_set(set);
1143 static int lov_getattr_interpret(struct ptlrpc_request_set *rqset,
1146 struct lov_request_set *lovset = (struct lov_request_set *)data;
1150 /* don't do attribute merge if this aysnc op failed */
1152 lovset->set_completes = 0;
1153 err = lov_fini_getattr_set(lovset);
1154 RETURN(rc ? rc : err);
1157 static int lov_getattr_async(struct obd_export *exp, struct obd_info *oinfo,
1158 struct ptlrpc_request_set *rqset)
1160 struct lov_request_set *lovset;
1161 struct lov_obd *lov;
1162 struct list_head *pos;
1163 struct lov_request *req;
1168 ASSERT_LSM_MAGIC(oinfo->oi_md);
1170 if (!exp || !exp->exp_obd)
1173 lov = &exp->exp_obd->u.lov;
1175 rc = lov_prep_getattr_set(exp, oinfo, &lovset);
1179 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1180 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1181 oinfo->oi_md->lsm_stripe_size);
1183 list_for_each (pos, &lovset->set_list) {
1184 req = list_entry(pos, struct lov_request, rq_link);
1186 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1187 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1188 req->rq_oi.oi_oa->o_id, req->rq_idx);
1189 rc = obd_getattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1190 &req->rq_oi, rqset);
1192 CERROR("error: getattr objid "LPX64" subobj "
1193 LPX64" on OST idx %d: rc = %d\n",
1194 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1200 if (!list_empty(&rqset->set_requests)) {
1202 LASSERT (rqset->set_interpret == NULL);
1203 rqset->set_interpret = lov_getattr_interpret;
1204 rqset->set_arg = (void *)lovset;
1209 lovset->set_completes = 0;
1210 err = lov_fini_getattr_set(lovset);
1211 RETURN(rc ? rc : err);
1214 static int lov_setattr(struct obd_export *exp, struct obd_info *oinfo,
1215 struct obd_trans_info *oti)
1217 struct lov_request_set *set;
1218 struct lov_obd *lov;
1219 struct list_head *pos;
1220 struct lov_request *req;
1221 int err = 0, rc = 0;
1225 ASSERT_LSM_MAGIC(oinfo->oi_md);
1227 if (!exp || !exp->exp_obd)
1230 /* for now, we only expect the following updates here */
1231 LASSERT(!(oinfo->oi_oa->o_valid & ~(OBD_MD_FLID | OBD_MD_FLTYPE |
1232 OBD_MD_FLMODE | OBD_MD_FLATIME |
1233 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1234 OBD_MD_FLFLAGS | OBD_MD_FLSIZE |
1235 OBD_MD_FLGROUP | OBD_MD_FLUID |
1236 OBD_MD_FLGID | OBD_MD_FLINLINE |
1237 OBD_MD_FLFID | OBD_MD_FLGENER)));
1238 lov = &exp->exp_obd->u.lov;
1239 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1243 list_for_each (pos, &set->set_list) {
1244 req = list_entry(pos, struct lov_request, rq_link);
1246 rc = obd_setattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1248 err = lov_update_setattr_set(set, req, rc);
1250 CERROR("error: setattr objid "LPX64" subobj "
1251 LPX64" on OST idx %d: rc = %d\n",
1252 set->set_oi->oi_oa->o_id,
1253 req->rq_oi.oi_oa->o_id, req->rq_idx, err);
1258 err = lov_fini_setattr_set(set);
1264 static int lov_setattr_interpret(struct ptlrpc_request_set *rqset,
1267 struct lov_request_set *lovset = (struct lov_request_set *)data;
1272 lovset->set_completes = 0;
1273 err = lov_fini_setattr_set(lovset);
1274 RETURN(rc ? rc : err);
1277 /* If @oti is given, the request goes from MDS and responses from OSTs are not
1278 needed. Otherwise, a client is waiting for responses. */
1279 static int lov_setattr_async(struct obd_export *exp, struct obd_info *oinfo,
1280 struct obd_trans_info *oti,
1281 struct ptlrpc_request_set *rqset)
1283 struct lov_request_set *set;
1284 struct lov_request *req;
1285 struct list_head *pos;
1286 struct lov_obd *lov;
1291 ASSERT_LSM_MAGIC(oinfo->oi_md);
1292 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE) {
1294 LASSERT(oti->oti_logcookies);
1297 if (!exp || !exp->exp_obd)
1300 lov = &exp->exp_obd->u.lov;
1301 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1305 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1306 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1307 oinfo->oi_md->lsm_stripe_size);
1309 list_for_each (pos, &set->set_list) {
1310 req = list_entry(pos, struct lov_request, rq_link);
1312 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
1313 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1315 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1316 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1317 req->rq_oi.oi_oa->o_id, req->rq_idx);
1319 rc = obd_setattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1320 &req->rq_oi, oti, rqset);
1322 CERROR("error: setattr objid "LPX64" subobj "
1323 LPX64" on OST idx %d: rc = %d\n",
1324 set->set_oi->oi_oa->o_id,
1325 req->rq_oi.oi_oa->o_id,
1331 /* If we are not waiting for responses on async requests, return. */
1332 if (rc || !rqset || list_empty(&rqset->set_requests)) {
1335 set->set_completes = 0;
1336 err = lov_fini_setattr_set(set);
1337 RETURN(rc ? rc : err);
1340 LASSERT(rqset->set_interpret == NULL);
1341 rqset->set_interpret = lov_setattr_interpret;
1342 rqset->set_arg = (void *)set;
1347 static int lov_punch_interpret(struct ptlrpc_request_set *rqset,
1350 struct lov_request_set *lovset = (struct lov_request_set *)data;
1355 lovset->set_completes = 0;
1356 err = lov_fini_punch_set(lovset);
1357 RETURN(rc ? rc : err);
1360 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
1361 * we can send this 'punch' to just the authoritative node and the nodes
1362 * that the punch will affect. */
1363 static int lov_punch(struct obd_export *exp, struct obd_info *oinfo,
1364 struct obd_trans_info *oti,
1365 struct ptlrpc_request_set *rqset)
1367 struct lov_request_set *set;
1368 struct lov_obd *lov;
1369 struct list_head *pos;
1370 struct lov_request *req;
1375 ASSERT_LSM_MAGIC(oinfo->oi_md);
1377 if (!exp || !exp->exp_obd)
1380 lov = &exp->exp_obd->u.lov;
1381 rc = lov_prep_punch_set(exp, oinfo, oti, &set);
1385 list_for_each (pos, &set->set_list) {
1386 req = list_entry(pos, struct lov_request, rq_link);
1388 rc = obd_punch(lov->lov_tgts[req->rq_idx]->ltd_exp,
1389 &req->rq_oi, NULL, rqset);
1391 CERROR("error: punch objid "LPX64" subobj "LPX64
1392 " on OST idx %d: rc = %d\n",
1393 set->set_oi->oi_oa->o_id,
1394 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1399 if (rc || list_empty(&rqset->set_requests)) {
1401 err = lov_fini_punch_set(set);
1402 RETURN(rc ? rc : err);
1405 LASSERT(rqset->set_interpret == NULL);
1406 rqset->set_interpret = lov_punch_interpret;
1407 rqset->set_arg = (void *)set;
1412 static int lov_sync(struct obd_export *exp, struct obdo *oa,
1413 struct lov_stripe_md *lsm, obd_off start, obd_off end)
1415 struct lov_request_set *set;
1416 struct obd_info oinfo;
1417 struct lov_obd *lov;
1418 struct list_head *pos;
1419 struct lov_request *req;
1420 int err = 0, rc = 0;
1423 ASSERT_LSM_MAGIC(lsm);
1428 lov = &exp->exp_obd->u.lov;
1429 rc = lov_prep_sync_set(exp, &oinfo, oa, lsm, start, end, &set);
1433 list_for_each (pos, &set->set_list) {
1434 req = list_entry(pos, struct lov_request, rq_link);
1436 rc = obd_sync(lov->lov_tgts[req->rq_idx]->ltd_exp,
1437 req->rq_oi.oi_oa, NULL,
1438 req->rq_oi.oi_policy.l_extent.start,
1439 req->rq_oi.oi_policy.l_extent.end);
1440 err = lov_update_common_set(set, req, rc);
1442 CERROR("error: fsync objid "LPX64" subobj "LPX64
1443 " on OST idx %d: rc = %d\n",
1444 set->set_oi->oi_oa->o_id,
1445 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1450 err = lov_fini_sync_set(set);
1456 static int lov_brw_check(struct lov_obd *lov, struct obd_info *lov_oinfo,
1457 obd_count oa_bufs, struct brw_page *pga)
1459 struct obd_info oinfo = { { { 0 } } };
1462 oinfo.oi_oa = lov_oinfo->oi_oa;
1464 /* The caller just wants to know if there's a chance that this
1465 * I/O can succeed */
1466 for (i = 0; i < oa_bufs; i++) {
1467 int stripe = lov_stripe_number(lov_oinfo->oi_md, pga[i].off);
1468 int ost = lov_oinfo->oi_md->lsm_oinfo[stripe]->loi_ost_idx;
1471 if (!lov_stripe_intersects(lov_oinfo->oi_md, i, pga[i].off,
1472 pga[i].off + pga[i].count,
1476 if (!lov->lov_tgts[ost] || !lov->lov_tgts[ost]->ltd_active) {
1477 CDEBUG(D_HA, "lov idx %d inactive\n", ost);
1481 rc = obd_brw(OBD_BRW_CHECK, lov->lov_tgts[ost]->ltd_exp, &oinfo,
1489 static int lov_brw(int cmd, struct obd_export *exp, struct obd_info *oinfo,
1490 obd_count oa_bufs, struct brw_page *pga,
1491 struct obd_trans_info *oti)
1493 struct lov_request_set *set;
1494 struct lov_request *req;
1495 struct list_head *pos;
1496 struct lov_obd *lov = &exp->exp_obd->u.lov;
1500 ASSERT_LSM_MAGIC(oinfo->oi_md);
1502 if (cmd == OBD_BRW_CHECK) {
1503 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1507 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &set);
1511 list_for_each (pos, &set->set_list) {
1512 struct obd_export *sub_exp;
1513 struct brw_page *sub_pga;
1514 req = list_entry(pos, struct lov_request, rq_link);
1516 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1517 sub_pga = set->set_pga + req->rq_pgaidx;
1518 rc = obd_brw(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1522 lov_update_common_set(set, req, rc);
1525 err = lov_fini_brw_set(set);
1531 static int lov_brw_interpret(struct ptlrpc_request_set *reqset, void *data,
1534 struct lov_request_set *lovset = (struct lov_request_set *)data;
1538 lovset->set_completes = 0;
1539 lov_fini_brw_set(lovset);
1541 rc = lov_fini_brw_set(lovset);
1547 static int lov_brw_async(int cmd, struct obd_export *exp,
1548 struct obd_info *oinfo, obd_count oa_bufs,
1549 struct brw_page *pga, struct obd_trans_info *oti,
1550 struct ptlrpc_request_set *set)
1552 struct lov_request_set *lovset;
1553 struct lov_request *req;
1554 struct list_head *pos;
1555 struct lov_obd *lov = &exp->exp_obd->u.lov;
1560 ASSERT_LSM_MAGIC(oinfo->oi_md);
1562 if (cmd == OBD_BRW_CHECK) {
1563 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1567 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &lovset);
1571 list_for_each (pos, &lovset->set_list) {
1572 struct obd_export *sub_exp;
1573 struct brw_page *sub_pga;
1574 req = list_entry(pos, struct lov_request, rq_link);
1576 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1577 sub_pga = lovset->set_pga + req->rq_pgaidx;
1578 rc = obd_brw_async(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1582 lov_update_common_set(lovset, req, rc);
1585 LASSERT(set->set_interpret == NULL);
1586 LASSERT(set->set_arg == NULL);
1587 rc = ptlrpc_set_add_cb(set, lov_brw_interpret, lovset);
1593 lov_fini_brw_set(lovset);
1597 static int lov_ap_make_ready(void *data, int cmd)
1599 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1601 return lap->lap_caller_ops->ap_make_ready(lap->lap_caller_data, cmd);
1604 static int lov_ap_refresh_count(void *data, int cmd)
1606 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1608 return lap->lap_caller_ops->ap_refresh_count(lap->lap_caller_data,
1612 static void lov_ap_fill_obdo(void *data, int cmd, struct obdo *oa)
1614 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1616 lap->lap_caller_ops->ap_fill_obdo(lap->lap_caller_data, cmd, oa);
1617 /* XXX woah, shouldn't we be altering more here? size? */
1618 oa->o_id = lap->lap_loi_id;
1619 oa->o_stripe_idx = lap->lap_stripe;
1622 static void lov_ap_update_obdo(void *data, int cmd, struct obdo *oa,
1625 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1627 lap->lap_caller_ops->ap_update_obdo(lap->lap_caller_data, cmd,oa,valid);
1630 static int lov_ap_completion(void *data, int cmd, struct obdo *oa, int rc)
1632 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1634 /* in a raid1 regime this would down a count of many ios
1635 * in flight, onl calling the caller_ops completion when all
1636 * the raid1 ios are complete */
1637 rc = lap->lap_caller_ops->ap_completion(lap->lap_caller_data,cmd,oa,rc);
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,
1649 int lov_prep_async_page(struct obd_export *exp, struct lov_stripe_md *lsm,
1650 struct lov_oinfo *loi, cfs_page_t *page,
1651 obd_off offset, struct obd_async_page_ops *ops,
1652 void *data, void **res)
1654 struct lov_obd *lov = &exp->exp_obd->u.lov;
1655 struct lov_async_page *lap;
1661 /* Find an existing osc so we can get it's stupid sizeof(*oap).
1662 Only because of this layering limitation will a client
1663 mount with no osts fail */
1664 while (!lov->lov_tgts || !lov->lov_tgts[i] ||
1665 !lov->lov_tgts[i]->ltd_exp) {
1667 if (i >= lov->desc.ld_tgt_count)
1670 rc = size_round(sizeof(*lap)) +
1671 obd_prep_async_page(lov->lov_tgts[i]->ltd_exp, NULL,
1672 NULL, NULL, 0, NULL, NULL, NULL);
1675 ASSERT_LSM_MAGIC(lsm);
1676 LASSERT(loi == NULL);
1679 lap->lap_magic = LOV_AP_MAGIC;
1680 lap->lap_caller_ops = ops;
1681 lap->lap_caller_data = data;
1683 /* for now only raid 0 which passes through */
1684 lap->lap_stripe = lov_stripe_number(lsm, offset);
1685 lov_stripe_offset(lsm, offset, lap->lap_stripe, &lap->lap_sub_offset);
1686 loi = lsm->lsm_oinfo[lap->lap_stripe];
1688 /* so the callback doesn't need the lsm */
1689 lap->lap_loi_id = loi->loi_id;
1691 lap->lap_sub_cookie = (void *)lap + size_round(sizeof(*lap));
1693 rc = obd_prep_async_page(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1694 lsm, loi, page, lap->lap_sub_offset,
1695 &lov_async_page_ops, lap,
1696 &lap->lap_sub_cookie);
1699 CDEBUG(D_CACHE, "lap %p page %p cookie %p off "LPU64"\n", lap, page,
1700 lap->lap_sub_cookie, offset);
1704 static int lov_queue_async_io(struct obd_export *exp,
1705 struct lov_stripe_md *lsm,
1706 struct lov_oinfo *loi, void *cookie,
1707 int cmd, obd_off off, int count,
1708 obd_flag brw_flags, obd_flag async_flags)
1710 struct lov_obd *lov = &exp->exp_obd->u.lov;
1711 struct lov_async_page *lap;
1714 LASSERT(loi == NULL);
1716 ASSERT_LSM_MAGIC(lsm);
1718 lap = LAP_FROM_COOKIE(cookie);
1720 loi = lsm->lsm_oinfo[lap->lap_stripe];
1722 rc = obd_queue_async_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp, lsm,
1723 loi, lap->lap_sub_cookie, cmd, off, count,
1724 brw_flags, async_flags);
1728 static int lov_set_async_flags(struct obd_export *exp,
1729 struct lov_stripe_md *lsm,
1730 struct lov_oinfo *loi, void *cookie,
1731 obd_flag async_flags)
1733 struct lov_obd *lov = &exp->exp_obd->u.lov;
1734 struct lov_async_page *lap;
1737 LASSERT(loi == NULL);
1739 ASSERT_LSM_MAGIC(lsm);
1741 lap = LAP_FROM_COOKIE(cookie);
1743 loi = lsm->lsm_oinfo[lap->lap_stripe];
1745 rc = obd_set_async_flags(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1746 lsm, loi, lap->lap_sub_cookie, async_flags);
1750 static int lov_queue_group_io(struct obd_export *exp,
1751 struct lov_stripe_md *lsm,
1752 struct lov_oinfo *loi,
1753 struct obd_io_group *oig, void *cookie,
1754 int cmd, obd_off off, int count,
1755 obd_flag brw_flags, obd_flag async_flags)
1757 struct lov_obd *lov = &exp->exp_obd->u.lov;
1758 struct lov_async_page *lap;
1761 LASSERT(loi == NULL);
1763 ASSERT_LSM_MAGIC(lsm);
1765 lap = LAP_FROM_COOKIE(cookie);
1767 loi = lsm->lsm_oinfo[lap->lap_stripe];
1769 rc = obd_queue_group_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp, lsm,
1770 loi, oig, lap->lap_sub_cookie, cmd, off, count,
1771 brw_flags, async_flags);
1775 /* this isn't exactly optimal. we may have queued sync io in oscs on
1776 * all stripes, but we don't record that fact at queue time. so we
1777 * trigger sync io on all stripes. */
1778 static int lov_trigger_group_io(struct obd_export *exp,
1779 struct lov_stripe_md *lsm,
1780 struct lov_oinfo *loi,
1781 struct obd_io_group *oig)
1783 struct lov_obd *lov = &exp->exp_obd->u.lov;
1786 LASSERT(loi == NULL);
1788 ASSERT_LSM_MAGIC(lsm);
1790 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1791 loi = lsm->lsm_oinfo[i];
1792 if (!lov->lov_tgts[loi->loi_ost_idx] ||
1793 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1794 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1798 err = obd_trigger_group_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1800 if (rc == 0 && err != 0)
1806 static int lov_teardown_async_page(struct obd_export *exp,
1807 struct lov_stripe_md *lsm,
1808 struct lov_oinfo *loi, void *cookie)
1810 struct lov_obd *lov = &exp->exp_obd->u.lov;
1811 struct lov_async_page *lap;
1814 LASSERT(loi == NULL);
1816 ASSERT_LSM_MAGIC(lsm);
1818 lap = LAP_FROM_COOKIE(cookie);
1820 loi = lsm->lsm_oinfo[lap->lap_stripe];
1822 rc = obd_teardown_async_page(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1823 lsm, loi, lap->lap_sub_cookie);
1825 CERROR("unable to teardown sub cookie %p: %d\n",
1826 lap->lap_sub_cookie, rc);
1832 static int lov_enqueue_interpret(struct ptlrpc_request_set *rqset,
1835 struct lov_request_set *lovset = (struct lov_request_set *)data;
1837 rc = lov_fini_enqueue_set(lovset, lovset->set_ei->ei_mode, rc, rqset);
1841 static int lov_enqueue(struct obd_export *exp, struct obd_info *oinfo,
1842 struct ldlm_enqueue_info *einfo,
1843 struct ptlrpc_request_set *rqset)
1845 struct lov_request_set *set;
1846 struct lov_request *req;
1847 struct list_head *pos;
1848 struct lov_obd *lov;
1853 ASSERT_LSM_MAGIC(oinfo->oi_md);
1855 /* we should never be asked to replay a lock this way. */
1856 LASSERT((oinfo->oi_flags & LDLM_FL_REPLAY) == 0);
1858 if (!exp || !exp->exp_obd)
1861 lov = &exp->exp_obd->u.lov;
1862 rc = lov_prep_enqueue_set(exp, oinfo, einfo, &set);
1866 list_for_each (pos, &set->set_list) {
1867 req = list_entry(pos, struct lov_request, rq_link);
1869 rc = obd_enqueue(lov->lov_tgts[req->rq_idx]->ltd_exp,
1870 &req->rq_oi, einfo, rqset);
1875 if (rqset && !list_empty(&rqset->set_requests)) {
1877 LASSERT(rqset->set_interpret == NULL);
1878 rqset->set_interpret = lov_enqueue_interpret;
1879 rqset->set_arg = (void *)set;
1883 rc = lov_fini_enqueue_set(set, einfo->ei_mode, rc, rqset);
1887 static int lov_match(struct obd_export *exp, struct lov_stripe_md *lsm,
1888 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1889 int *flags, void *data, struct lustre_handle *lockh)
1891 struct lov_request_set *set;
1892 struct obd_info oinfo;
1893 struct lov_request *req;
1894 struct list_head *pos;
1895 struct lov_obd *lov = &exp->exp_obd->u.lov;
1896 struct lustre_handle *lov_lockhp;
1897 int lov_flags, rc = 0;
1900 ASSERT_LSM_MAGIC(lsm);
1902 if (!exp || !exp->exp_obd)
1905 lov = &exp->exp_obd->u.lov;
1906 rc = lov_prep_match_set(exp, &oinfo, lsm, policy, mode, lockh, &set);
1910 list_for_each (pos, &set->set_list) {
1911 ldlm_policy_data_t sub_policy;
1912 req = list_entry(pos, struct lov_request, rq_link);
1913 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
1914 LASSERT(lov_lockhp);
1917 sub_policy.l_extent = req->rq_oi.oi_policy.l_extent;
1919 rc = obd_match(lov->lov_tgts[req->rq_idx]->ltd_exp,
1920 req->rq_oi.oi_md, type, &sub_policy,
1921 mode, &lov_flags, data, lov_lockhp);
1922 rc = lov_update_match_set(set, req, rc);
1926 lov_fini_match_set(set, mode, *flags);
1930 static int lov_change_cbdata(struct obd_export *exp,
1931 struct lov_stripe_md *lsm, ldlm_iterator_t it,
1934 struct lov_obd *lov;
1935 struct lov_oinfo *loi;
1939 ASSERT_LSM_MAGIC(lsm);
1941 if (!exp || !exp->exp_obd)
1944 lov = &exp->exp_obd->u.lov;
1945 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1946 struct lov_stripe_md submd;
1948 loi = lsm->lsm_oinfo[i];
1949 if (!lov->lov_tgts[loi->loi_ost_idx]) {
1950 CDEBUG(D_HA, "lov idx %d NULL \n", loi->loi_ost_idx);
1953 submd.lsm_object_id = loi->loi_id;
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 ldlm_mode_t this_mode;
1971 int err = 0, rc = 0;
1974 ASSERT_LSM_MAGIC(lsm);
1976 if (!exp || !exp->exp_obd)
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 /* If this lock was used for a write or truncate, the object
1990 * will have been recreated by the OST, cancel the lock
1991 * (setting LCK_GROUP incidentally causes immediate cancel). */
1992 if (OST_LVB_IS_ERR(lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_blocks) &&
1993 (mode == LCK_PW || mode == LCK_CW))
1994 this_mode = LCK_GROUP;
1998 rc = obd_cancel(lov->lov_tgts[req->rq_idx]->ltd_exp,
1999 req->rq_oi.oi_md, this_mode, lov_lockhp);
2000 rc = lov_update_common_set(set, req, rc);
2002 CERROR("error: cancel objid "LPX64" subobj "
2003 LPX64" on OST idx %d: rc = %d\n",
2005 req->rq_oi.oi_md->lsm_object_id,
2011 lov_fini_cancel_set(set);
2015 static int lov_cancel_unused(struct obd_export *exp,
2016 struct lov_stripe_md *lsm, int flags, void *opaque)
2018 struct lov_obd *lov;
2019 struct lov_oinfo *loi;
2023 if (!exp || !exp->exp_obd)
2026 lov = &exp->exp_obd->u.lov;
2028 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2030 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2033 err = obd_cancel_unused(lov->lov_tgts[i]->ltd_exp, NULL,
2041 ASSERT_LSM_MAGIC(lsm);
2043 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2044 struct lov_stripe_md submd;
2047 loi = lsm->lsm_oinfo[i];
2048 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2049 CDEBUG(D_HA, "lov idx %d NULL\n", loi->loi_ost_idx);
2053 if (!lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
2054 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2056 submd.lsm_object_id = loi->loi_id;
2057 submd.lsm_stripe_count = 0;
2058 err = obd_cancel_unused(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2059 &submd, flags, opaque);
2060 if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
2061 CERROR("error: cancel unused objid "LPX64" subobj "LPX64
2062 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
2063 loi->loi_id, loi->loi_ost_idx, err);
2071 static int lov_join_lru(struct obd_export *exp,
2072 struct lov_stripe_md *lsm, int join)
2074 struct lov_obd *lov;
2075 struct lov_oinfo *loi;
2079 ASSERT_LSM_MAGIC(lsm);
2080 if (!exp || !exp->exp_obd)
2083 lov = &exp->exp_obd->u.lov;
2084 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2085 struct lov_stripe_md submd;
2088 loi = lsm->lsm_oinfo[i];
2089 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2090 CDEBUG(D_HA, "lov idx %d NULL\n", loi->loi_ost_idx);
2094 if (!lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
2095 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2097 submd.lsm_object_id = loi->loi_id;
2098 submd.lsm_stripe_count = 0;
2099 rc = obd_join_lru(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2102 CERROR("join lru failed. objid: "LPX64" subobj: "LPX64
2103 " ostidx: %d rc: %d\n", lsm->lsm_object_id,
2104 loi->loi_id, loi->loi_ost_idx, rc);
2113 static int lov_statfs_interpret(struct ptlrpc_request_set *rqset,
2116 struct lov_request_set *lovset = (struct lov_request_set *)data;
2121 lovset->set_completes = 0;
2123 err = lov_fini_statfs_set(lovset);
2124 RETURN(rc ? rc : err);
2127 static int lov_statfs_async(struct obd_device *obd, struct obd_info *oinfo,
2128 __u64 max_age, struct ptlrpc_request_set *rqset)
2130 struct lov_request_set *set;
2131 struct lov_request *req;
2132 struct list_head *pos;
2133 struct lov_obd *lov;
2137 LASSERT(oinfo != NULL);
2138 LASSERT(oinfo->oi_osfs != NULL);
2141 rc = lov_prep_statfs_set(obd, oinfo, &set);
2145 list_for_each (pos, &set->set_list) {
2146 struct obd_device *osc_obd;
2148 req = list_entry(pos, struct lov_request, rq_link);
2150 osc_obd = class_exp2obd(lov->lov_tgts[req->rq_idx]->ltd_exp);
2151 rc = obd_statfs_async(osc_obd, &req->rq_oi, max_age, rqset);
2156 if (rc || list_empty(&rqset->set_requests)) {
2159 set->set_completes = 0;
2160 err = lov_fini_statfs_set(set);
2161 RETURN(rc ? rc : err);
2164 LASSERT(rqset->set_interpret == NULL);
2165 rqset->set_interpret = lov_statfs_interpret;
2166 rqset->set_arg = (void *)set;
2170 static int lov_statfs(struct obd_device *obd, struct obd_statfs *osfs,
2173 struct lov_obd *lov = &obd->u.lov;
2174 struct obd_statfs lov_sfs;
2180 /* We only get block data from the OBD */
2181 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2182 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active) {
2183 CDEBUG(D_HA, "lov idx %d inactive\n", i);
2187 err = obd_statfs(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
2190 if (lov->lov_tgts[i]->ltd_active && !rc)
2194 lov_update_statfs(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
2195 osfs, &lov_sfs, set);
2199 err = lov_fini_statfs(obd, osfs, set);
2202 RETURN(rc ? rc : err);
2205 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
2206 void *karg, void *uarg)
2208 struct obd_device *obddev = class_exp2obd(exp);
2209 struct lov_obd *lov = &obddev->u.lov;
2210 int i, rc, count = lov->desc.ld_tgt_count;
2211 struct obd_uuid *uuidp;
2215 case OBD_IOC_LOV_GET_CONFIG: {
2216 struct obd_ioctl_data *data;
2217 struct lov_desc *desc;
2222 if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
2225 data = (struct obd_ioctl_data *)buf;
2227 if (sizeof(*desc) > data->ioc_inllen1) {
2228 obd_ioctl_freedata(buf, len);
2232 if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
2233 obd_ioctl_freedata(buf, len);
2237 if (sizeof(__u32) * count > data->ioc_inllen3) {
2238 obd_ioctl_freedata(buf, len);
2242 desc = (struct lov_desc *)data->ioc_inlbuf1;
2243 memcpy(desc, &(lov->desc), sizeof(*desc));
2245 uuidp = (struct obd_uuid *)data->ioc_inlbuf2;
2246 genp = (__u32 *)data->ioc_inlbuf3;
2247 /* the uuid will be empty for deleted OSTs */
2248 for (i = 0; i < count; i++, uuidp++, genp++) {
2249 if (!lov->lov_tgts[i])
2251 *uuidp = lov->lov_tgts[i]->ltd_uuid;
2252 *genp = lov->lov_tgts[i]->ltd_gen;
2255 rc = copy_to_user((void *)uarg, buf, len);
2258 obd_ioctl_freedata(buf, len);
2261 case LL_IOC_LOV_SETSTRIPE:
2262 rc = lov_setstripe(exp, karg, uarg);
2264 case LL_IOC_LOV_GETSTRIPE:
2265 rc = lov_getstripe(exp, karg, uarg);
2267 case LL_IOC_LOV_SETEA:
2268 rc = lov_setea(exp, karg, uarg);
2277 for (i = 0; i < count; i++) {
2280 /* OST was disconnected */
2281 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2284 err = obd_iocontrol(cmd, lov->lov_tgts[i]->ltd_exp,
2286 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
2289 if (lov->lov_tgts[i]->ltd_active) {
2290 CDEBUG(err == -ENOTTY ?
2291 D_IOCTL : D_WARNING,
2292 "iocontrol OSC %s on OST "
2293 "idx %d cmd %x: err = %d\n",
2294 lov_uuid2str(lov, i),
2311 static int lov_get_info(struct obd_export *exp, __u32 keylen,
2312 void *key, __u32 *vallen, void *val)
2314 struct obd_device *obddev = class_exp2obd(exp);
2315 struct lov_obd *lov = &obddev->u.lov;
2319 if (!vallen || !val)
2324 if (KEY_IS("lock_to_stripe")) {
2327 struct ldlm_lock *lock;
2328 struct lov_stripe_md *lsm;
2330 struct ldlm_res_id *res_id = &data->lock->l_resource->lr_name;
2331 struct lov_oinfo *loi;
2332 __u32 *stripe = val;
2334 if (*vallen < sizeof(*stripe))
2335 GOTO(out, rc = -EFAULT);
2336 *vallen = sizeof(*stripe);
2338 /* XXX This is another one of those bits that will need to
2339 * change if we ever actually support nested LOVs. It uses
2340 * the lock's export to find out which stripe it is. */
2341 /* XXX - it's assumed all the locks for deleted OSTs have
2342 * been cancelled. Also, the export for deleted OSTs will
2343 * be NULL and won't match the lock's export. */
2344 for (i = 0; i < data->lsm->lsm_stripe_count; i++) {
2345 loi = data->lsm->lsm_oinfo[i];
2346 if (!lov->lov_tgts[loi->loi_ost_idx])
2348 if (lov->lov_tgts[loi->loi_ost_idx]->ltd_exp ==
2349 data->lock->l_conn_export &&
2350 loi->loi_id == res_id->name[0] &&
2351 loi->loi_gr == res_id->name[1]) {
2356 LDLM_ERROR(data->lock, "lock on inode without such object");
2357 dump_lsm(D_ERROR, data->lsm);
2358 GOTO(out, rc = -ENXIO);
2359 } else if (KEY_IS("last_id")) {
2361 int size = sizeof(obd_id);
2362 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2363 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
2365 rc = obd_get_info(lov->lov_tgts[i]->ltd_exp,
2366 keylen, key, &size, ids + i);
2371 } else if (KEY_IS(KEY_LOVDESC)) {
2372 struct lov_desc *desc_ret = val;
2373 *desc_ret = lov->desc;
2384 static int lov_set_info_async(struct obd_export *exp, obd_count keylen,
2385 void *key, obd_count vallen, void *val,
2386 struct ptlrpc_request_set *set)
2388 struct obd_device *obddev = class_exp2obd(exp);
2389 struct lov_obd *lov = &obddev->u.lov;
2391 int i, rc = 0, err, incr = 0, check_uuid = 0, do_inactive = 0;
2396 set = ptlrpc_prep_set();
2402 count = lov->desc.ld_tgt_count;
2404 if (KEY_IS(KEY_NEXT_ID)) {
2405 /* We must use mds's idea of # osts for indexing into
2406 mds->mds_lov_objids */
2407 count = vallen / sizeof(obd_id);
2408 LASSERT(count <= lov->desc.ld_tgt_count);
2409 vallen = sizeof(obd_id);
2410 incr = sizeof(obd_id);
2412 } else if (KEY_IS("checksum")) {
2414 } else if (KEY_IS(KEY_MDS_CONN) || KEY_IS("unlinked")) {
2415 check_uuid = val ? 1 : 0;
2416 } else if (KEY_IS("evict_by_nid")) {
2418 do_inactive = incr = 0;
2422 for (i = 0; i < count; i++, val = (char *)val + incr) {
2423 /* OST was disconnected */
2424 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2427 /* OST is inactive and we don't want inactive OSCs */
2428 if (!lov->lov_tgts[i]->ltd_active && !do_inactive)
2431 /* Only want a specific OSC */
2433 !obd_uuid_equals(val, &lov->lov_tgts[i]->ltd_uuid))
2436 err = obd_set_info_async(lov->lov_tgts[i]->ltd_exp,
2437 keylen, key, vallen, val, set);
2443 err = ptlrpc_set_wait(set);
2446 ptlrpc_set_destroy(set);
2451 static int lov_checkmd(struct obd_export *exp, struct obd_export *md_exp,
2452 struct lov_stripe_md *lsm)
2460 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
2461 rc = lsm_op_find(lsm->lsm_magic)->lsm_revalidate(lsm, md_exp->exp_obd);
2466 int lov_test_and_clear_async_rc(struct lov_stripe_md *lsm)
2468 struct lov_oinfo *loi;
2472 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2473 loi = lsm->lsm_oinfo[i];
2474 if (loi->loi_ar.ar_rc && !rc)
2475 rc = loi->loi_ar.ar_rc;
2476 loi->loi_ar.ar_rc = 0;
2480 EXPORT_SYMBOL(lov_test_and_clear_async_rc);
2483 static int lov_extent_calc(struct obd_export *exp, struct lov_stripe_md *lsm,
2484 int cmd, __u64 *offset)
2487 __u32 ssize = lsm->lsm_stripe_size;
2490 do_div(start, ssize);
2491 start = start * ssize;
2493 CDEBUG(D_DLMTRACE, "offset "LPU64", stripe %u, start "LPU64
2494 ", end "LPU64"\n", *offset, ssize, start, start + ssize - 1);
2495 if (cmd == OBD_CALC_STRIPE_END) {
2496 *offset = start + ssize - 1;
2497 } else if (cmd == OBD_CALC_STRIPE_START) {
2507 struct lov_multi_wait {
2508 struct ldlm_lock *lock;
2514 int lov_complete_many(struct obd_export *exp, struct lov_stripe_md *lsm,
2515 struct lustre_handle *lockh)
2517 struct lov_lock_handles *lov_lockh = NULL;
2518 struct lustre_handle *lov_lockhp;
2519 struct lov_obd *lov;
2520 struct lov_oinfo *loi;
2521 struct lov_multi_wait *queues;
2525 ASSERT_LSM_MAGIC(lsm);
2527 if (!exp || !exp->exp_obd)
2530 LASSERT(lockh != NULL);
2531 if (lsm->lsm_stripe_count > 1) {
2532 lov_lockh = lov_handle2llh(lockh);
2533 if (lov_lockh == NULL) {
2534 CERROR("LOV: invalid lov lock handle %p\n", lockh);
2538 lov_lockhp = lov_lockh->llh_handles;
2543 OBD_ALLOC(queues, lsm->lsm_stripe_count * sizeof(*queues));
2545 GOTO(out, rc = -ENOMEM);
2547 lov = &exp->exp_obd->u.lov;
2548 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
2549 i++, loi++, lov_lockhp++) {
2550 struct ldlm_lock *lock;
2551 struct obd_device *obd;
2553 lock = ldlm_handle2lock(lov_lockhp);
2555 CDEBUG(D_HA, "lov idx %d subobj "LPX64" no lock?\n",
2556 loi->loi_ost_idx, loi->loi_id);
2557 queues[i].completed = 1;
2561 queues[i].lock = lock;
2562 init_waitqueue_entry(&(queues[i].wait), current);
2563 add_wait_queue(lock->l_waitq, &(queues[i].wait));
2565 obd = class_exp2obd(lock->l_conn_export);
2567 imp = obd->u.cli.cl_import;
2569 spin_lock(&imp->imp_lock);
2570 queues[i].generation = imp->imp_generation;
2571 spin_unlock(&imp->imp_lock);
2575 lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, ldlm_expired_completion_wait,
2576 interrupted_completion_wait, &lwd);
2577 rc = l_wait_event_added(check_multi_complete(queues, lsm), &lwi);
2579 for (i = 0; i < lsm->lsm_stripe_count; i++)
2580 remove_wait_queue(lock->l_waitq, &(queues[i].wait));
2582 if (rc == -EINTR || rc == -ETIMEDOUT) {
2588 if (lov_lockh != NULL)
2589 lov_llh_put(lov_lockh);
2594 void lov_stripe_lock(struct lov_stripe_md *md)
2596 LASSERT(md->lsm_lock_owner != cfs_current());
2597 spin_lock(&md->lsm_lock);
2598 LASSERT(md->lsm_lock_owner == NULL);
2599 md->lsm_lock_owner = cfs_current();
2601 EXPORT_SYMBOL(lov_stripe_lock);
2603 void lov_stripe_unlock(struct lov_stripe_md *md)
2605 LASSERT(md->lsm_lock_owner == cfs_current());
2606 md->lsm_lock_owner = NULL;
2607 spin_unlock(&md->lsm_lock);
2609 EXPORT_SYMBOL(lov_stripe_unlock);
2611 struct obd_ops lov_obd_ops = {
2612 .o_owner = THIS_MODULE,
2613 .o_setup = lov_setup,
2614 .o_precleanup = lov_precleanup,
2615 .o_cleanup = lov_cleanup,
2616 .o_process_config = lov_process_config,
2617 .o_connect = lov_connect,
2618 .o_disconnect = lov_disconnect,
2619 .o_statfs = lov_statfs,
2620 .o_statfs_async = lov_statfs_async,
2621 .o_packmd = lov_packmd,
2622 .o_unpackmd = lov_unpackmd,
2623 .o_checkmd = lov_checkmd,
2624 .o_create = lov_create,
2625 .o_destroy = lov_destroy,
2626 .o_getattr = lov_getattr,
2627 .o_getattr_async = lov_getattr_async,
2628 .o_setattr = lov_setattr,
2629 .o_setattr_async = lov_setattr_async,
2631 .o_brw_async = lov_brw_async,
2632 .o_prep_async_page = lov_prep_async_page,
2633 .o_queue_async_io = lov_queue_async_io,
2634 .o_set_async_flags = lov_set_async_flags,
2635 .o_queue_group_io = lov_queue_group_io,
2636 .o_trigger_group_io = lov_trigger_group_io,
2637 .o_teardown_async_page = lov_teardown_async_page,
2638 .o_merge_lvb = lov_merge_lvb,
2639 .o_adjust_kms = lov_adjust_kms,
2640 .o_punch = lov_punch,
2642 .o_enqueue = lov_enqueue,
2643 .o_match = lov_match,
2644 .o_change_cbdata = lov_change_cbdata,
2645 .o_cancel = lov_cancel,
2646 .o_cancel_unused = lov_cancel_unused,
2647 .o_join_lru = lov_join_lru,
2648 .o_iocontrol = lov_iocontrol,
2649 .o_get_info = lov_get_info,
2650 .o_set_info_async = lov_set_info_async,
2651 .o_extent_calc = lov_extent_calc,
2652 .o_llog_init = lov_llog_init,
2653 .o_llog_finish = lov_llog_finish,
2654 .o_notify = lov_notify,
2657 static quota_interface_t *quota_interface;
2658 extern quota_interface_t lov_quota_interface;
2660 cfs_mem_cache_t *lov_oinfo_slab;
2662 int __init lov_init(void)
2664 struct lprocfs_static_vars lvars;
2668 lov_oinfo_slab = cfs_mem_cache_create("lov_oinfo",
2669 sizeof(struct lov_oinfo),
2670 0, SLAB_HWCACHE_ALIGN);
2671 if (lov_oinfo_slab == NULL)
2673 lprocfs_init_vars(lov, &lvars);
2675 request_module("lquota");
2676 quota_interface = PORTAL_SYMBOL_GET(lov_quota_interface);
2677 init_obd_quota_ops(quota_interface, &lov_obd_ops);
2679 rc = class_register_type(&lov_obd_ops, lvars.module_vars,
2682 if (quota_interface)
2683 PORTAL_SYMBOL_PUT(lov_quota_interface);
2684 rc2 = cfs_mem_cache_destroy(lov_oinfo_slab);
2692 static void /*__exit*/ lov_exit(void)
2696 if (quota_interface)
2697 PORTAL_SYMBOL_PUT(lov_quota_interface);
2699 class_unregister_type(LUSTRE_LOV_NAME);
2700 rc = cfs_mem_cache_destroy(lov_oinfo_slab);
2704 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2705 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver");
2706 MODULE_LICENSE("GPL");
2708 cfs_module(lov, LUSTRE_VERSION_STRING, lov_init, lov_exit);