1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/lov/lov_obd.c
38 * Author: Phil Schwan <phil@clusterfs.com>
39 * Author: Peter Braam <braam@clusterfs.com>
40 * Author: Mike Shaver <shaver@clusterfs.com>
41 * Author: Nathan Rutman <nathan@clusterfs.com>
45 # define EXPORT_SYMTAB
47 #define DEBUG_SUBSYSTEM S_LOV
49 #include <libcfs/libcfs.h>
51 #include <liblustre.h>
54 #include <obd_support.h>
55 #include <lustre_lib.h>
56 #include <lustre_net.h>
57 #include <lustre/lustre_idl.h>
58 #include <lustre_dlm.h>
59 #include <lustre_mds.h>
60 #include <lustre_debug.h>
61 #include <obd_class.h>
64 #include <lprocfs_status.h>
65 #include <lustre_param.h>
66 #include <cl_object.h>
67 #include <lustre/ll_fiemap.h>
69 #include "lov_internal.h"
72 /* Keep a refcount of lov->tgt usage to prevent racing with addition/deletion.
73 Any function that expects lov_tgts to remain stationary must take a ref. */
74 void lov_getref(struct obd_device *obd)
76 struct lov_obd *lov = &obd->u.lov;
78 /* nobody gets through here until lov_putref is done */
79 mutex_down(&lov->lov_lock);
80 atomic_inc(&lov->lov_refcount);
81 mutex_up(&lov->lov_lock);
85 static void __lov_del_obd(struct obd_device *obd, __u32 index);
87 void lov_putref(struct obd_device *obd)
89 struct lov_obd *lov = &obd->u.lov;
90 mutex_down(&lov->lov_lock);
91 /* ok to dec to 0 more than once -- ltd_exp's will be null */
92 if (atomic_dec_and_test(&lov->lov_refcount) && lov->lov_death_row) {
94 CDEBUG(D_CONFIG, "destroying %d lov targets\n",
96 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
97 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_reap)
99 /* Disconnect and delete from list */
100 __lov_del_obd(obd, i);
101 lov->lov_death_row--;
104 mutex_up(&lov->lov_lock);
107 #define MAX_STRING_SIZE 128
108 int lov_connect_obd(struct obd_device *obd, __u32 index, int activate,
109 struct obd_connect_data *data)
111 struct lov_obd *lov = &obd->u.lov;
112 struct obd_uuid tgt_uuid;
113 struct obd_device *tgt_obd;
114 struct obd_uuid lov_osc_uuid = { "LOV_OSC_UUID" };
115 struct lustre_handle conn = {0, };
116 struct obd_import *imp;
119 cfs_proc_dir_entry_t *lov_proc_dir;
124 if (!lov->lov_tgts[index])
127 tgt_uuid = lov->lov_tgts[index]->ltd_uuid;
129 tgt_obd = class_find_client_obd(&tgt_uuid, LUSTRE_OSC_NAME,
133 CERROR("Target %s not attached\n", obd_uuid2str(&tgt_uuid));
136 if (!tgt_obd->obd_set_up) {
137 CERROR("Target %s not set up\n", obd_uuid2str(&tgt_uuid));
141 if (data && (data->ocd_connect_flags & OBD_CONNECT_INDEX))
142 data->ocd_index = index;
145 * Divine LOV knows that OBDs under it are OSCs.
147 imp = tgt_obd->u.cli.cl_import;
150 tgt_obd->obd_no_recov = 0;
151 /* FIXME this is probably supposed to be
152 ptlrpc_set_import_active. Horrible naming. */
153 ptlrpc_activate_import(imp);
156 if (imp->imp_invalid) {
157 CERROR("not connecting OSC %s; administratively "
158 "disabled\n", obd_uuid2str(&tgt_uuid));
159 rc = obd_register_observer(tgt_obd, obd);
161 CERROR("Target %s register_observer error %d; "
162 "will not be able to reactivate\n",
163 obd_uuid2str(&tgt_uuid), rc);
168 rc = obd_connect(NULL, &conn, tgt_obd, &lov_osc_uuid, data, NULL);
170 CERROR("Target %s connect error %d\n",
171 obd_uuid2str(&tgt_uuid), rc);
174 lov->lov_tgts[index]->ltd_exp = class_conn2export(&conn);
175 if (!lov->lov_tgts[index]->ltd_exp) {
176 CERROR("Target %s: null export!\n", obd_uuid2str(&tgt_uuid));
180 rc = obd_register_observer(tgt_obd, obd);
182 CERROR("Target %s register_observer error %d\n",
183 obd_uuid2str(&tgt_uuid), rc);
184 obd_disconnect(lov->lov_tgts[index]->ltd_exp);
185 lov->lov_tgts[index]->ltd_exp = NULL;
189 lov->lov_tgts[index]->ltd_reap = 0;
191 lov->lov_tgts[index]->ltd_active = 1;
192 lov->desc.ld_active_tgt_count++;
193 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 0;
195 CDEBUG(D_CONFIG, "Connected tgt idx %d %s (%s) %sactive\n", index,
196 obd_uuid2str(&tgt_uuid), tgt_obd->obd_name, activate ? "":"in");
199 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
201 struct obd_device *osc_obd = class_conn2obd(&conn);
202 cfs_proc_dir_entry_t *osc_symlink;
203 char name[MAX_STRING_SIZE];
205 LASSERT(osc_obd != NULL);
206 LASSERT(osc_obd->obd_magic == OBD_DEVICE_MAGIC);
207 LASSERT(osc_obd->obd_type->typ_name != NULL);
208 snprintf(name, MAX_STRING_SIZE, "../../../%s/%s",
209 osc_obd->obd_type->typ_name,
211 osc_symlink = lprocfs_add_symlink(osc_obd->obd_name, lov_proc_dir,
213 if (osc_symlink == NULL) {
214 CERROR("could not register LOV target "
215 "/proc/fs/lustre/%s/%s/target_obds/%s.",
216 obd->obd_type->typ_name, obd->obd_name,
218 lprocfs_remove(&lov_proc_dir);
223 rc = qos_add_tgt(obd, index);
225 CERROR("qos_add_tgt failed %d\n", rc);
230 static int lov_connect(const struct lu_env *env,
231 struct lustre_handle *conn, struct obd_device *obd,
232 struct obd_uuid *cluuid, struct obd_connect_data *data,
235 struct lov_obd *lov = &obd->u.lov;
236 struct lov_tgt_desc *tgt;
240 CDEBUG(D_CONFIG, "connect #%d\n", lov->lov_connects);
242 rc = class_connect(conn, obd, cluuid);
246 /* Why should there ever be more than 1 connect? */
248 LASSERT(lov->lov_connects == 1);
250 memset(&lov->lov_ocd, 0, sizeof(lov->lov_ocd));
252 lov->lov_ocd = *data;
255 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
256 tgt = lov->lov_tgts[i];
257 if (!tgt || obd_uuid_empty(&tgt->ltd_uuid))
259 /* Flags will be lowest common denominator */
260 rc = lov_connect_obd(obd, i, tgt->ltd_activate, &lov->lov_ocd);
262 CERROR("%s: lov connect tgt %d failed: %d\n",
263 obd->obd_name, i, rc);
272 static int lov_disconnect_obd(struct obd_device *obd, __u32 index)
274 cfs_proc_dir_entry_t *lov_proc_dir;
275 struct lov_obd *lov = &obd->u.lov;
276 struct obd_device *osc_obd;
281 if (lov->lov_tgts[index] == NULL)
284 osc_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
285 CDEBUG(D_CONFIG, "%s: disconnecting target %s\n",
286 obd->obd_name, osc_obd->obd_name);
288 if (lov->lov_tgts[index]->ltd_active) {
289 lov->lov_tgts[index]->ltd_active = 0;
290 lov->desc.ld_active_tgt_count--;
291 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 1;
294 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
296 cfs_proc_dir_entry_t *osc_symlink;
298 osc_symlink = lprocfs_srch(lov_proc_dir, osc_obd->obd_name);
300 lprocfs_remove(&osc_symlink);
302 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing.",
303 obd->obd_type->typ_name, obd->obd_name,
309 /* Pass it on to our clients.
310 * XXX This should be an argument to disconnect,
311 * XXX not a back-door flag on the OBD. Ah well.
313 osc_obd->obd_force = obd->obd_force;
314 osc_obd->obd_fail = obd->obd_fail;
315 osc_obd->obd_no_recov = obd->obd_no_recov;
318 obd_register_observer(osc_obd, NULL);
320 rc = obd_disconnect(lov->lov_tgts[index]->ltd_exp);
322 CERROR("Target %s disconnect error %d\n",
323 lov_uuid2str(lov, index), rc);
327 qos_del_tgt(obd, index);
329 lov->lov_tgts[index]->ltd_exp = NULL;
333 static int lov_disconnect(struct obd_export *exp)
335 struct obd_device *obd = class_exp2obd(exp);
336 struct lov_obd *lov = &obd->u.lov;
343 /* Only disconnect the underlying layers on the final disconnect. */
345 if (lov->lov_connects != 0) {
346 /* why should there be more than 1 connect? */
347 CERROR("disconnect #%d\n", lov->lov_connects);
351 /* Let's hold another reference so lov_del_obd doesn't spin through
355 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
356 if (lov->lov_tgts[i] && lov->lov_tgts[i]->ltd_exp) {
357 /* Disconnection is the last we know about an obd */
358 lov_del_target(obd, i, 0, lov->lov_tgts[i]->ltd_gen);
364 rc = class_disconnect(exp); /* bz 9811 */
370 * -EINVAL : UUID can't be found in the LOV's target list
371 * - any other is lov index
373 static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
376 struct lov_obd *lov = &obd->u.lov;
377 struct lov_tgt_desc *tgt;
381 CDEBUG(D_INFO, "Searching in lov %p for uuid %s (activate=%d)\n",
382 lov, uuid->uuid, activate);
385 for (index = 0; index < lov->desc.ld_tgt_count; index++) {
386 tgt = lov->lov_tgts[index];
387 if (!tgt || !tgt->ltd_exp)
390 CDEBUG(D_INFO, "lov idx %d is %s conn "LPX64"\n",
391 index, obd_uuid2str(&tgt->ltd_uuid),
392 tgt->ltd_exp->exp_handle.h_cookie);
393 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
397 if (index == lov->desc.ld_tgt_count)
398 GOTO(out, index = -EINVAL);
400 if (lov->lov_tgts[index]->ltd_active == activate) {
401 CDEBUG(D_INFO, "OSC %s already %sactive!\n", uuid->uuid,
402 activate ? "" : "in");
406 CDEBUG(D_CONFIG, "Marking OSC %s %sactive\n", obd_uuid2str(uuid),
407 activate ? "" : "in");
409 lov->lov_tgts[index]->ltd_active = activate;
412 lov->desc.ld_active_tgt_count++;
413 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 0;
415 lov->desc.ld_active_tgt_count--;
416 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 1;
418 /* remove any old qos penalty */
419 lov->lov_tgts[index]->ltd_qos.ltq_penalty = 0;
426 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
427 enum obd_notify_event ev, void *data)
432 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
433 struct obd_uuid *uuid;
437 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
438 CERROR("unexpected notification of %s %s!\n",
439 watched->obd_type->typ_name,
443 uuid = &watched->u.cli.cl_target_uuid;
445 /* Set OSC as active before notifying the observer, so the
446 * observer can use the OSC normally.
448 rc = lov_set_osc_active(obd, uuid, ev == OBD_NOTIFY_ACTIVE);
450 CERROR("%sactivation of %s failed: %d\n",
451 (ev == OBD_NOTIFY_ACTIVE) ? "" : "de",
452 obd_uuid2str(uuid), rc);
458 /* Pass the notification up the chain. */
460 rc = obd_notify_observer(obd, watched, ev, data);
462 /* NULL watched means all osc's in the lov (only for syncs) */
463 /* sync event should be send lov idx as data */
464 struct lov_obd *lov = &obd->u.lov;
465 struct obd_device *tgt_obd;
468 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
469 if (!lov->lov_tgts[i])
472 if ((ev == OBD_NOTIFY_SYNC) ||
473 (ev == OBD_NOTIFY_SYNC_NONBLOCK))
476 tgt_obd = class_exp2obd(lov->lov_tgts[i]->ltd_exp);
477 rc = obd_notify_observer(obd, tgt_obd, ev, data);
479 CERROR("%s: notify %s of %s failed %d\n",
481 obd->obd_observer->obd_name,
482 tgt_obd->obd_name, rc);
492 int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
493 __u32 index, int gen, int active)
495 struct lov_obd *lov = &obd->u.lov;
496 struct lov_tgt_desc *tgt;
500 CDEBUG(D_CONFIG, "uuid:%s idx:%d gen:%d active:%d\n",
501 uuidp->uuid, index, gen, active);
504 CERROR("request to add OBD %s with invalid generation: %d\n",
509 mutex_down(&lov->lov_lock);
511 if ((index < lov->lov_tgt_size) && (lov->lov_tgts[index] != NULL)) {
512 tgt = lov->lov_tgts[index];
513 CERROR("UUID %s already assigned at LOV target index %d\n",
514 obd_uuid2str(&tgt->ltd_uuid), index);
515 mutex_up(&lov->lov_lock);
519 if (index >= lov->lov_tgt_size) {
520 /* We need to reallocate the lov target array. */
521 struct lov_tgt_desc **newtgts, **old = NULL;
522 __u32 newsize, oldsize = 0;
524 newsize = max(lov->lov_tgt_size, (__u32)2);
525 while (newsize < index + 1)
526 newsize = newsize << 1;
527 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
528 if (newtgts == NULL) {
529 mutex_up(&lov->lov_lock);
533 if (lov->lov_tgt_size) {
534 memcpy(newtgts, lov->lov_tgts, sizeof(*newtgts) *
537 oldsize = lov->lov_tgt_size;
540 lov->lov_tgts = newtgts;
541 lov->lov_tgt_size = newsize;
546 OBD_FREE(old, sizeof(*old) * oldsize);
548 CDEBUG(D_CONFIG, "tgts: %p size: %d\n",
549 lov->lov_tgts, lov->lov_tgt_size);
554 mutex_up(&lov->lov_lock);
558 memset(tgt, 0, sizeof(*tgt));
559 tgt->ltd_uuid = *uuidp;
560 /* XXX - add a sanity check on the generation number. */
562 tgt->ltd_index = index;
563 tgt->ltd_activate = active;
564 lov->lov_tgts[index] = tgt;
565 if (index >= lov->desc.ld_tgt_count)
566 lov->desc.ld_tgt_count = index + 1;
568 rc = lov_ost_pool_add(&lov->lov_packed, index, lov->lov_tgt_size);
572 mutex_up(&lov->lov_lock);
574 CDEBUG(D_CONFIG, "idx=%d ltd_gen=%d ld_tgt_count=%d\n",
575 index, tgt->ltd_gen, lov->desc.ld_tgt_count);
577 if (lov->lov_connects == 0) {
578 /* lov_connect hasn't been called yet. We'll do the
579 lov_connect_obd on this target when that fn first runs,
580 because we don't know the connect flags yet. */
586 rc = lov_connect_obd(obd, index, active, &lov->lov_ocd);
590 rc = lov_notify(obd, tgt->ltd_exp->exp_obd,
591 active ? OBD_NOTIFY_ACTIVE : OBD_NOTIFY_INACTIVE,
596 CERROR("add failed (%d), deleting %s\n", rc,
597 obd_uuid2str(&tgt->ltd_uuid));
598 lov_del_target(obd, index, 0, 0);
604 /* Schedule a target for deletion */
605 int lov_del_target(struct obd_device *obd, __u32 index,
606 struct obd_uuid *uuidp, int gen)
608 struct lov_obd *lov = &obd->u.lov;
609 int count = lov->desc.ld_tgt_count;
613 if (index >= count) {
614 CERROR("LOV target index %d >= number of LOV OBDs %d.\n",
621 if (!lov->lov_tgts[index]) {
622 CERROR("LOV target at index %d is not setup.\n", index);
623 GOTO(out, rc = -EINVAL);
626 if (uuidp && !obd_uuid_equals(uuidp, &lov->lov_tgts[index]->ltd_uuid)) {
627 CERROR("LOV target UUID %s at index %d doesn't match %s.\n",
628 lov_uuid2str(lov, index), index,
629 obd_uuid2str(uuidp));
630 GOTO(out, rc = -EINVAL);
633 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d exp: %p active: %d\n",
634 lov_uuid2str(lov, index), index,
635 lov->lov_tgts[index]->ltd_gen, lov->lov_tgts[index]->ltd_exp,
636 lov->lov_tgts[index]->ltd_active);
638 lov->lov_tgts[index]->ltd_reap = 1;
639 lov->lov_death_row++;
640 /* we really delete it from lov_putref */
647 /* We are holding lov_lock */
648 static void __lov_del_obd(struct obd_device *obd, __u32 index)
650 struct lov_obd *lov = &obd->u.lov;
651 struct obd_device *osc_obd;
652 struct lov_tgt_desc *tgt = lov->lov_tgts[index];
655 LASSERT(tgt->ltd_reap);
657 osc_obd = class_exp2obd(tgt->ltd_exp);
659 CDEBUG(D_CONFIG, "Removing tgt %s : %s\n",
660 lov_uuid2str(lov, index),
661 osc_obd ? osc_obd->obd_name : "<no obd>");
664 lov_disconnect_obd(obd, index);
666 /* XXX - right now there is a dependency on ld_tgt_count being the
667 * maximum tgt index for computing the mds_max_easize. So we can't
670 lov_ost_pool_remove(&lov->lov_packed, index);
671 lov->lov_tgts[index] = NULL;
674 /* Manual cleanup - no cleanup logs to clean up the osc's. We must
675 do it ourselves. And we can't do it from lov_cleanup,
676 because we just lost our only reference to it. */
678 class_manual_cleanup(osc_obd);
681 void lov_fix_desc_stripe_size(__u64 *val)
683 if (*val < PTLRPC_MAX_BRW_SIZE) {
684 LCONSOLE_WARN("Increasing default stripe size to min %u\n",
685 PTLRPC_MAX_BRW_SIZE);
686 *val = PTLRPC_MAX_BRW_SIZE;
687 } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) {
688 *val &= ~(LOV_MIN_STRIPE_SIZE - 1);
689 LCONSOLE_WARN("Changing default stripe size to "LPU64" (a "
691 *val, LOV_MIN_STRIPE_SIZE);
695 void lov_fix_desc_stripe_count(__u32 *val)
701 void lov_fix_desc_pattern(__u32 *val)
703 /* from lov_setstripe */
704 if ((*val != 0) && (*val != LOV_PATTERN_RAID0)) {
705 LCONSOLE_WARN("Unknown stripe pattern: %#x\n", *val);
710 void lov_fix_desc_qos_maxage(__u32 *val)
714 *val = QOS_DEFAULT_MAXAGE;
717 void lov_fix_desc(struct lov_desc *desc)
719 lov_fix_desc_stripe_size(&desc->ld_default_stripe_size);
720 lov_fix_desc_stripe_count(&desc->ld_default_stripe_count);
721 lov_fix_desc_pattern(&desc->ld_pattern);
722 lov_fix_desc_qos_maxage(&desc->ld_qos_maxage);
725 int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
727 struct lprocfs_static_vars lvars = { 0 };
728 struct lov_desc *desc;
729 struct lov_obd *lov = &obd->u.lov;
734 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
735 CERROR("LOV setup requires a descriptor\n");
739 desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
741 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
742 CERROR("descriptor size wrong: %d > %d\n",
743 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
747 if (desc->ld_magic != LOV_DESC_MAGIC) {
748 if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
749 CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n",
750 obd->obd_name, desc);
751 lustre_swab_lov_desc(desc);
753 CERROR("%s: Bad lov desc magic: %#x\n",
754 obd->obd_name, desc->ld_magic);
761 /* Because of 64-bit divide/mod operations only work with a 32-bit
762 * divisor in a 32-bit kernel, we cannot support a stripe width
763 * of 4GB or larger on 32-bit CPUs. */
764 count = desc->ld_default_stripe_count;
765 if ((count > 0 ? count : desc->ld_tgt_count) *
766 desc->ld_default_stripe_size > 0xffffffff) {
767 CERROR("LOV: stripe width "LPU64"x%u > 4294967295 bytes\n",
768 desc->ld_default_stripe_size, count);
772 desc->ld_active_tgt_count = 0;
774 lov->lov_tgt_size = 0;
776 sema_init(&lov->lov_lock, 1);
777 atomic_set(&lov->lov_refcount, 0);
778 CFS_INIT_LIST_HEAD(&lov->lov_qos.lq_oss_list);
779 init_rwsem(&lov->lov_qos.lq_rw_sem);
780 lov->lov_qos.lq_dirty = 1;
781 lov->lov_qos.lq_rr.lqr_dirty = 1;
782 lov->lov_qos.lq_reset = 1;
783 /* Default priority is toward free space balance */
784 lov->lov_qos.lq_prio_free = 232;
786 lov->lov_pools_hash_body = lustre_hash_init("POOLS", 7, 7,
787 &pool_hash_operations, 0);
788 CFS_INIT_LIST_HEAD(&lov->lov_pool_list);
789 lov->lov_pool_count = 0;
790 rc = lov_ost_pool_init(&lov->lov_packed, 0);
793 rc = lov_ost_pool_init(&lov->lov_qos.lq_rr.lqr_pool, 0);
795 lov_ost_pool_free(&lov->lov_packed);
799 lprocfs_lov_init_vars(&lvars);
800 lprocfs_obd_setup(obd, lvars.obd_vars);
805 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
806 0444, &lov_proc_target_fops, obd);
808 CWARN("Error adding the target_obd file\n");
811 lov->lov_pool_proc_entry = lprocfs_register("pools",
818 static int lov_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
824 case OBD_CLEANUP_EARLY: {
825 struct lov_obd *lov = &obd->u.lov;
827 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
828 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
830 obd_precleanup(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
835 case OBD_CLEANUP_EXPORTS:
836 rc = obd_llog_finish(obd, 0);
838 CERROR("failed to cleanup llogging subsystems\n");
844 static int lov_cleanup(struct obd_device *obd)
846 struct lov_obd *lov = &obd->u.lov;
847 struct list_head *pos, *tmp;
848 struct pool_desc *pool;
850 lprocfs_obd_cleanup(obd);
852 list_for_each_safe(pos, tmp, &lov->lov_pool_list) {
853 pool = list_entry(pos, struct pool_desc, pool_list);
854 list_del(&pool->pool_list);
855 lov_ost_pool_free(&(pool->pool_rr.lqr_pool));
856 lov_ost_pool_free(&(pool->pool_obds));
859 lov_ost_pool_free(&(lov->lov_qos.lq_rr.lqr_pool));
860 lov_ost_pool_free(&lov->lov_packed);
861 lustre_hash_exit(lov->lov_pools_hash_body);
865 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
866 if (!lov->lov_tgts[i])
869 /* Inactive targets may never have connected */
870 if (lov->lov_tgts[i]->ltd_active ||
871 atomic_read(&lov->lov_refcount))
872 /* We should never get here - these
873 should have been removed in the
875 CERROR("lov tgt %d not cleaned!"
876 " deathrow=%d, lovrc=%d\n",
877 i, lov->lov_death_row,
878 atomic_read(&lov->lov_refcount));
879 lov_del_target(obd, i, 0, 0);
881 OBD_FREE(lov->lov_tgts, sizeof(*lov->lov_tgts) *
883 lov->lov_tgt_size = 0;
889 int lov_process_config_base(struct obd_device *obd, struct lustre_cfg *lcfg,
890 __u32 *indexp, int *genp)
892 struct obd_uuid obd_uuid;
897 switch(cmd = lcfg->lcfg_command) {
898 case LCFG_LOV_ADD_OBD:
899 case LCFG_LOV_ADD_INA:
900 case LCFG_LOV_DEL_OBD: {
903 /* lov_modify_tgts add 0:lov_mdsA 1:ost1_UUID 2:0 3:1 */
904 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
905 GOTO(out, rc = -EINVAL);
907 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
909 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", indexp) != 1)
910 GOTO(out, rc = -EINVAL);
911 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", genp) != 1)
912 GOTO(out, rc = -EINVAL);
915 if (cmd == LCFG_LOV_ADD_OBD)
916 rc = lov_add_target(obd, &obd_uuid, index, gen, 1);
917 else if (cmd == LCFG_LOV_ADD_INA)
918 rc = lov_add_target(obd, &obd_uuid, index, gen, 0);
920 rc = lov_del_target(obd, index, &obd_uuid, gen);
924 struct lprocfs_static_vars lvars = { 0 };
925 struct lov_desc *desc = &(obd->u.lov.desc);
928 GOTO(out, rc = -EINVAL);
930 lprocfs_lov_init_vars(&lvars);
932 rc = class_process_proc_param(PARAM_LOV, lvars.obd_vars,
945 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
946 GOTO(out, rc = -EINVAL);
955 #define log2(n) ffz(~(n))
958 static int lov_clear_orphans(struct obd_export *export, struct obdo *src_oa,
959 struct lov_stripe_md **ea,
960 struct obd_trans_info *oti)
964 struct obd_uuid *ost_uuid = NULL;
968 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
969 src_oa->o_flags == OBD_FL_DELORPHAN);
971 lov = &export->exp_obd->u.lov;
977 if (oti->oti_ost_uuid) {
978 ost_uuid = oti->oti_ost_uuid;
979 CDEBUG(D_HA, "clearing orphans only for %s\n",
983 lov_getref(export->exp_obd);
984 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
985 struct lov_stripe_md obj_md;
986 struct lov_stripe_md *obj_mdp = &obj_md;
987 struct lov_tgt_desc *tgt;
990 tgt = lov->lov_tgts[i];
994 /* if called for a specific target, we don't
995 care if it is not active. */
996 if (!lov->lov_tgts[i]->ltd_active && ost_uuid == NULL) {
997 CDEBUG(D_HA, "lov idx %d inactive\n", i);
1001 if (ost_uuid && !obd_uuid_equals(ost_uuid, &tgt->ltd_uuid))
1004 CDEBUG(D_CONFIG,"Clear orphans for %d:%s\n", i,
1005 obd_uuid2str(ost_uuid));
1007 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
1009 LASSERT(lov->lov_tgts[i]->ltd_exp);
1010 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1011 err = obd_create(lov->lov_tgts[i]->ltd_exp,
1012 tmp_oa, &obj_mdp, oti);
1014 /* This export will be disabled until it is recovered,
1015 and then orphan recovery will be completed. */
1016 CERROR("error in orphan recovery on OST idx %d/%d: "
1017 "rc = %d\n", i, lov->desc.ld_tgt_count, err);
1024 lov_putref(export->exp_obd);
1030 static int lov_recreate(struct obd_export *exp, struct obdo *src_oa,
1031 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1033 struct lov_stripe_md *obj_mdp, *lsm;
1034 struct lov_obd *lov = &exp->exp_obd->u.lov;
1039 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
1040 src_oa->o_flags & OBD_FL_RECREATE_OBJS);
1042 OBD_ALLOC(obj_mdp, sizeof(*obj_mdp));
1043 if (obj_mdp == NULL)
1046 ost_idx = src_oa->o_nlink;
1049 GOTO(out, rc = -EINVAL);
1050 if (ost_idx >= lov->desc.ld_tgt_count ||
1051 !lov->lov_tgts[ost_idx])
1052 GOTO(out, rc = -EINVAL);
1054 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1055 if (lsm->lsm_oinfo[i]->loi_ost_idx == ost_idx) {
1056 if (lsm->lsm_oinfo[i]->loi_id != src_oa->o_id)
1057 GOTO(out, rc = -EINVAL);
1061 if (i == lsm->lsm_stripe_count)
1062 GOTO(out, rc = -EINVAL);
1064 rc = obd_create(lov->lov_tgts[ost_idx]->ltd_exp, src_oa, &obj_mdp, oti);
1066 OBD_FREE(obj_mdp, sizeof(*obj_mdp));
1070 /* the LOV expects oa->o_id to be set to the LOV object id */
1071 static int lov_create(struct obd_export *exp, struct obdo *src_oa,
1072 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1074 struct lov_obd *lov;
1075 struct obd_info oinfo;
1076 struct lov_request_set *set = NULL;
1077 struct lov_request *req;
1078 struct obd_statfs osfs;
1083 LASSERT(ea != NULL);
1087 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1088 src_oa->o_flags == OBD_FL_DELORPHAN) {
1089 rc = lov_clear_orphans(exp, src_oa, ea, oti);
1093 lov = &exp->exp_obd->u.lov;
1094 if (!lov->desc.ld_active_tgt_count)
1097 lov_getref(exp->exp_obd);
1098 /* Recreate a specific object id at the given OST index */
1099 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1100 (src_oa->o_flags & OBD_FL_RECREATE_OBJS)) {
1101 rc = lov_recreate(exp, src_oa, ea, oti);
1105 maxage = cfs_time_shift_64(-lov->desc.ld_qos_maxage);
1106 obd_statfs_rqset(exp->exp_obd, &osfs, maxage, OBD_STATFS_NODELAY);
1108 rc = lov_prep_create_set(exp, &oinfo, ea, src_oa, oti, &set);
1112 list_for_each_entry(req, &set->set_list, rq_link) {
1113 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1114 rc = obd_create(lov->lov_tgts[req->rq_idx]->ltd_exp,
1115 req->rq_oi.oi_oa, &req->rq_oi.oi_md, oti);
1116 lov_update_create_set(set, req, rc);
1118 rc = lov_fini_create_set(set, ea);
1120 lov_putref(exp->exp_obd);
1124 #define ASSERT_LSM_MAGIC(lsmp) \
1126 LASSERT((lsmp) != NULL); \
1127 LASSERTF(((lsmp)->lsm_magic == LOV_MAGIC_V1 || \
1128 (lsmp)->lsm_magic == LOV_MAGIC_V3 || \
1129 (lsmp)->lsm_magic == LOV_MAGIC_JOIN), "%p->lsm_magic=%x\n", \
1130 (lsmp), (lsmp)->lsm_magic); \
1133 static int lov_destroy(struct obd_export *exp, struct obdo *oa,
1134 struct lov_stripe_md *lsm, struct obd_trans_info *oti,
1135 struct obd_export *md_exp, void *capa)
1137 struct lov_request_set *set;
1138 struct obd_info oinfo;
1139 struct lov_request *req;
1140 struct list_head *pos;
1141 struct lov_obd *lov;
1142 int rc = 0, err = 0;
1145 ASSERT_LSM_MAGIC(lsm);
1147 if (!exp || !exp->exp_obd)
1150 if (oa->o_valid & OBD_MD_FLCOOKIE) {
1152 LASSERT(oti->oti_logcookies);
1155 lov = &exp->exp_obd->u.lov;
1156 lov_getref(exp->exp_obd);
1157 rc = lov_prep_destroy_set(exp, &oinfo, oa, lsm, oti, &set);
1161 list_for_each (pos, &set->set_list) {
1162 req = list_entry(pos, struct lov_request, rq_link);
1164 if (oa->o_valid & OBD_MD_FLCOOKIE)
1165 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1167 err = obd_destroy(lov->lov_tgts[req->rq_idx]->ltd_exp,
1168 req->rq_oi.oi_oa, NULL, oti, NULL, capa);
1169 err = lov_update_common_set(set, req, err);
1171 CERROR("error: destroying objid "LPX64" subobj "
1172 LPX64" on OST idx %d: rc = %d\n",
1173 oa->o_id, req->rq_oi.oi_oa->o_id,
1181 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
1182 rc = lsm_op_find(lsm->lsm_magic)->lsm_destroy(lsm, oa, md_exp);
1184 err = lov_fini_destroy_set(set);
1186 lov_putref(exp->exp_obd);
1187 RETURN(rc ? rc : err);
1190 static int lov_getattr(struct obd_export *exp, struct obd_info *oinfo)
1192 struct lov_request_set *set;
1193 struct lov_request *req;
1194 struct list_head *pos;
1195 struct lov_obd *lov;
1196 int err = 0, rc = 0;
1200 ASSERT_LSM_MAGIC(oinfo->oi_md);
1202 if (!exp || !exp->exp_obd)
1205 lov = &exp->exp_obd->u.lov;
1207 rc = lov_prep_getattr_set(exp, oinfo, &set);
1211 list_for_each (pos, &set->set_list) {
1212 req = list_entry(pos, struct lov_request, rq_link);
1214 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1215 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1216 req->rq_oi.oi_oa->o_id, req->rq_idx);
1218 rc = obd_getattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1220 err = lov_update_common_set(set, req, rc);
1222 CERROR("error: getattr objid "LPX64" subobj "
1223 LPX64" on OST idx %d: rc = %d\n",
1224 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1230 rc = lov_fini_getattr_set(set);
1236 static int lov_getattr_interpret(struct ptlrpc_request_set *rqset,
1239 struct lov_request_set *lovset = (struct lov_request_set *)data;
1243 /* don't do attribute merge if this aysnc op failed */
1245 lovset->set_completes = 0;
1246 err = lov_fini_getattr_set(lovset);
1247 RETURN(rc ? rc : err);
1250 static int lov_getattr_async(struct obd_export *exp, struct obd_info *oinfo,
1251 struct ptlrpc_request_set *rqset)
1253 struct lov_request_set *lovset;
1254 struct lov_obd *lov;
1255 struct list_head *pos;
1256 struct lov_request *req;
1261 ASSERT_LSM_MAGIC(oinfo->oi_md);
1263 if (!exp || !exp->exp_obd)
1266 lov = &exp->exp_obd->u.lov;
1268 rc = lov_prep_getattr_set(exp, oinfo, &lovset);
1272 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1273 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1274 oinfo->oi_md->lsm_stripe_size);
1276 list_for_each (pos, &lovset->set_list) {
1277 req = list_entry(pos, struct lov_request, rq_link);
1279 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1280 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1281 req->rq_oi.oi_oa->o_id, req->rq_idx);
1282 rc = obd_getattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1283 &req->rq_oi, rqset);
1285 CERROR("error: getattr objid "LPX64" subobj "
1286 LPX64" on OST idx %d: rc = %d\n",
1287 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1293 if (!list_empty(&rqset->set_requests)) {
1295 LASSERT (rqset->set_interpret == NULL);
1296 rqset->set_interpret = lov_getattr_interpret;
1297 rqset->set_arg = (void *)lovset;
1302 lovset->set_completes = 0;
1303 err = lov_fini_getattr_set(lovset);
1304 RETURN(rc ? rc : err);
1307 static int lov_setattr(struct obd_export *exp, struct obd_info *oinfo,
1308 struct obd_trans_info *oti)
1310 struct lov_request_set *set;
1311 struct lov_obd *lov;
1312 struct list_head *pos;
1313 struct lov_request *req;
1314 int err = 0, rc = 0;
1318 ASSERT_LSM_MAGIC(oinfo->oi_md);
1320 if (!exp || !exp->exp_obd)
1323 /* for now, we only expect the following updates here */
1324 LASSERT(!(oinfo->oi_oa->o_valid & ~(OBD_MD_FLID | OBD_MD_FLTYPE |
1325 OBD_MD_FLMODE | OBD_MD_FLATIME |
1326 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1327 OBD_MD_FLFLAGS | OBD_MD_FLSIZE |
1328 OBD_MD_FLGROUP | OBD_MD_FLUID |
1329 OBD_MD_FLGID | OBD_MD_FLFID |
1331 lov = &exp->exp_obd->u.lov;
1332 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1336 list_for_each (pos, &set->set_list) {
1337 req = list_entry(pos, struct lov_request, rq_link);
1339 rc = obd_setattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1341 err = lov_update_setattr_set(set, req, rc);
1343 CERROR("error: setattr objid "LPX64" subobj "
1344 LPX64" on OST idx %d: rc = %d\n",
1345 set->set_oi->oi_oa->o_id,
1346 req->rq_oi.oi_oa->o_id, req->rq_idx, err);
1351 err = lov_fini_setattr_set(set);
1357 static int lov_setattr_interpret(struct ptlrpc_request_set *rqset,
1360 struct lov_request_set *lovset = (struct lov_request_set *)data;
1365 lovset->set_completes = 0;
1366 err = lov_fini_setattr_set(lovset);
1367 RETURN(rc ? rc : err);
1370 /* If @oti is given, the request goes from MDS and responses from OSTs are not
1371 needed. Otherwise, a client is waiting for responses. */
1372 static int lov_setattr_async(struct obd_export *exp, struct obd_info *oinfo,
1373 struct obd_trans_info *oti,
1374 struct ptlrpc_request_set *rqset)
1376 struct lov_request_set *set;
1377 struct lov_request *req;
1378 struct list_head *pos;
1379 struct lov_obd *lov;
1384 ASSERT_LSM_MAGIC(oinfo->oi_md);
1385 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE) {
1387 LASSERT(oti->oti_logcookies);
1390 if (!exp || !exp->exp_obd)
1393 lov = &exp->exp_obd->u.lov;
1394 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1398 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1399 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1400 oinfo->oi_md->lsm_stripe_size);
1402 list_for_each (pos, &set->set_list) {
1403 req = list_entry(pos, struct lov_request, rq_link);
1405 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
1406 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1408 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1409 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1410 req->rq_oi.oi_oa->o_id, req->rq_idx);
1412 rc = obd_setattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1413 &req->rq_oi, oti, rqset);
1415 CERROR("error: setattr objid "LPX64" subobj "
1416 LPX64" on OST idx %d: rc = %d\n",
1417 set->set_oi->oi_oa->o_id,
1418 req->rq_oi.oi_oa->o_id,
1424 /* If we are not waiting for responses on async requests, return. */
1425 if (rc || !rqset || list_empty(&rqset->set_requests)) {
1428 set->set_completes = 0;
1429 err = lov_fini_setattr_set(set);
1430 RETURN(rc ? rc : err);
1433 LASSERT(rqset->set_interpret == NULL);
1434 rqset->set_interpret = lov_setattr_interpret;
1435 rqset->set_arg = (void *)set;
1440 static int lov_punch_interpret(struct ptlrpc_request_set *rqset,
1443 struct lov_request_set *lovset = (struct lov_request_set *)data;
1448 lovset->set_completes = 0;
1449 err = lov_fini_punch_set(lovset);
1450 RETURN(rc ? rc : err);
1453 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
1454 * we can send this 'punch' to just the authoritative node and the nodes
1455 * that the punch will affect. */
1456 static int lov_punch(struct obd_export *exp, struct obd_info *oinfo,
1457 struct obd_trans_info *oti,
1458 struct ptlrpc_request_set *rqset)
1460 struct lov_request_set *set;
1461 struct lov_obd *lov;
1462 struct list_head *pos;
1463 struct lov_request *req;
1468 ASSERT_LSM_MAGIC(oinfo->oi_md);
1470 if (!exp || !exp->exp_obd)
1473 lov = &exp->exp_obd->u.lov;
1474 rc = lov_prep_punch_set(exp, oinfo, oti, &set);
1478 list_for_each (pos, &set->set_list) {
1479 req = list_entry(pos, struct lov_request, rq_link);
1481 rc = obd_punch(lov->lov_tgts[req->rq_idx]->ltd_exp,
1482 &req->rq_oi, NULL, rqset);
1484 CERROR("error: punch objid "LPX64" subobj "LPX64
1485 " on OST idx %d: rc = %d\n",
1486 set->set_oi->oi_oa->o_id,
1487 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1492 if (rc || list_empty(&rqset->set_requests)) {
1494 err = lov_fini_punch_set(set);
1495 RETURN(rc ? rc : err);
1498 LASSERT(rqset->set_interpret == NULL);
1499 rqset->set_interpret = lov_punch_interpret;
1500 rqset->set_arg = (void *)set;
1505 static int lov_sync(struct obd_export *exp, struct obdo *oa,
1506 struct lov_stripe_md *lsm, obd_off start, obd_off end,
1509 struct lov_request_set *set;
1510 struct obd_info oinfo;
1511 struct lov_obd *lov;
1512 struct list_head *pos;
1513 struct lov_request *req;
1514 int err = 0, rc = 0;
1517 ASSERT_LSM_MAGIC(lsm);
1522 lov = &exp->exp_obd->u.lov;
1523 rc = lov_prep_sync_set(exp, &oinfo, oa, lsm, start, end, &set);
1527 list_for_each (pos, &set->set_list) {
1528 req = list_entry(pos, struct lov_request, rq_link);
1530 rc = obd_sync(lov->lov_tgts[req->rq_idx]->ltd_exp,
1531 req->rq_oi.oi_oa, NULL,
1532 req->rq_oi.oi_policy.l_extent.start,
1533 req->rq_oi.oi_policy.l_extent.end, capa);
1534 err = lov_update_common_set(set, req, rc);
1536 CERROR("error: fsync objid "LPX64" subobj "LPX64
1537 " on OST idx %d: rc = %d\n",
1538 set->set_oi->oi_oa->o_id,
1539 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1544 err = lov_fini_sync_set(set);
1550 static int lov_brw_check(struct lov_obd *lov, struct obd_info *lov_oinfo,
1551 obd_count oa_bufs, struct brw_page *pga)
1553 struct obd_info oinfo = { { { 0 } } };
1556 oinfo.oi_oa = lov_oinfo->oi_oa;
1558 /* The caller just wants to know if there's a chance that this
1559 * I/O can succeed */
1560 for (i = 0; i < oa_bufs; i++) {
1561 int stripe = lov_stripe_number(lov_oinfo->oi_md, pga[i].off);
1562 int ost = lov_oinfo->oi_md->lsm_oinfo[stripe]->loi_ost_idx;
1565 if (!lov_stripe_intersects(lov_oinfo->oi_md, i, pga[i].off,
1566 pga[i].off + pga[i].count - 1,
1570 if (!lov->lov_tgts[ost] || !lov->lov_tgts[ost]->ltd_active) {
1571 CDEBUG(D_HA, "lov idx %d inactive\n", ost);
1575 rc = obd_brw(OBD_BRW_CHECK, lov->lov_tgts[ost]->ltd_exp, &oinfo,
1583 static int lov_brw(int cmd, struct obd_export *exp, struct obd_info *oinfo,
1584 obd_count oa_bufs, struct brw_page *pga,
1585 struct obd_trans_info *oti)
1587 struct lov_request_set *set;
1588 struct lov_request *req;
1589 struct list_head *pos;
1590 struct lov_obd *lov = &exp->exp_obd->u.lov;
1594 ASSERT_LSM_MAGIC(oinfo->oi_md);
1596 if (cmd == OBD_BRW_CHECK) {
1597 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1601 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &set);
1605 list_for_each (pos, &set->set_list) {
1606 struct obd_export *sub_exp;
1607 struct brw_page *sub_pga;
1608 req = list_entry(pos, struct lov_request, rq_link);
1610 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1611 sub_pga = set->set_pga + req->rq_pgaidx;
1612 rc = obd_brw(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1616 lov_update_common_set(set, req, rc);
1619 err = lov_fini_brw_set(set);
1625 static int lov_enqueue_interpret(struct ptlrpc_request_set *rqset,
1628 struct lov_request_set *lovset = (struct lov_request_set *)data;
1630 rc = lov_fini_enqueue_set(lovset, lovset->set_ei->ei_mode, rc, rqset);
1634 static int lov_enqueue(struct obd_export *exp, struct obd_info *oinfo,
1635 struct ldlm_enqueue_info *einfo,
1636 struct ptlrpc_request_set *rqset)
1638 ldlm_mode_t mode = einfo->ei_mode;
1639 struct lov_request_set *set;
1640 struct lov_request *req;
1641 struct list_head *pos;
1642 struct lov_obd *lov;
1647 ASSERT_LSM_MAGIC(oinfo->oi_md);
1648 LASSERT(mode == (mode & -mode));
1650 /* we should never be asked to replay a lock this way. */
1651 LASSERT((oinfo->oi_flags & LDLM_FL_REPLAY) == 0);
1653 if (!exp || !exp->exp_obd)
1656 lov = &exp->exp_obd->u.lov;
1657 rc = lov_prep_enqueue_set(exp, oinfo, einfo, &set);
1661 list_for_each (pos, &set->set_list) {
1662 req = list_entry(pos, struct lov_request, rq_link);
1664 rc = obd_enqueue(lov->lov_tgts[req->rq_idx]->ltd_exp,
1665 &req->rq_oi, einfo, rqset);
1670 if (rqset && !list_empty(&rqset->set_requests)) {
1672 LASSERT(rqset->set_interpret == NULL);
1673 rqset->set_interpret = lov_enqueue_interpret;
1674 rqset->set_arg = (void *)set;
1678 rc = lov_fini_enqueue_set(set, mode, rc, rqset);
1682 static int lov_change_cbdata(struct obd_export *exp,
1683 struct lov_stripe_md *lsm, ldlm_iterator_t it,
1686 struct lov_obd *lov;
1690 ASSERT_LSM_MAGIC(lsm);
1692 if (!exp || !exp->exp_obd)
1695 LASSERT(lsm->lsm_object_gr > 0);
1697 lov = &exp->exp_obd->u.lov;
1698 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1699 struct lov_stripe_md submd;
1700 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
1702 if (!lov->lov_tgts[loi->loi_ost_idx]) {
1703 CDEBUG(D_HA, "lov idx %d NULL \n", loi->loi_ost_idx);
1707 submd.lsm_object_id = loi->loi_id;
1708 submd.lsm_object_gr = lsm->lsm_object_gr;
1709 submd.lsm_stripe_count = 0;
1710 rc = obd_change_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1716 static int lov_cancel(struct obd_export *exp, struct lov_stripe_md *lsm,
1717 __u32 mode, struct lustre_handle *lockh)
1719 struct lov_request_set *set;
1720 struct obd_info oinfo;
1721 struct lov_request *req;
1722 struct list_head *pos;
1723 struct lov_obd *lov = &exp->exp_obd->u.lov;
1724 struct lustre_handle *lov_lockhp;
1725 int err = 0, rc = 0;
1728 ASSERT_LSM_MAGIC(lsm);
1730 if (!exp || !exp->exp_obd)
1733 LASSERT(lsm->lsm_object_gr > 0);
1735 lov = &exp->exp_obd->u.lov;
1736 rc = lov_prep_cancel_set(exp, &oinfo, lsm, mode, lockh, &set);
1740 list_for_each (pos, &set->set_list) {
1741 req = list_entry(pos, struct lov_request, rq_link);
1742 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
1744 rc = obd_cancel(lov->lov_tgts[req->rq_idx]->ltd_exp,
1745 req->rq_oi.oi_md, mode, lov_lockhp);
1746 rc = lov_update_common_set(set, req, rc);
1748 CERROR("error: cancel objid "LPX64" subobj "
1749 LPX64" on OST idx %d: rc = %d\n",
1751 req->rq_oi.oi_md->lsm_object_id,
1757 lov_fini_cancel_set(set);
1761 static int lov_cancel_unused(struct obd_export *exp,
1762 struct lov_stripe_md *lsm,
1763 int flags, void *opaque)
1765 struct lov_obd *lov;
1769 if (!exp || !exp->exp_obd)
1772 lov = &exp->exp_obd->u.lov;
1774 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1776 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
1779 err = obd_cancel_unused(lov->lov_tgts[i]->ltd_exp, NULL,
1787 ASSERT_LSM_MAGIC(lsm);
1789 LASSERT(lsm->lsm_object_gr > 0);
1790 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1791 struct lov_stripe_md submd;
1792 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
1795 if (!lov->lov_tgts[loi->loi_ost_idx]) {
1796 CDEBUG(D_HA, "lov idx %d NULL\n", loi->loi_ost_idx);
1800 if (!lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
1801 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1803 submd.lsm_object_id = loi->loi_id;
1804 submd.lsm_object_gr = lsm->lsm_object_gr;
1805 submd.lsm_stripe_count = 0;
1806 err = obd_cancel_unused(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1807 &submd, flags, opaque);
1808 if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1809 CERROR("error: cancel unused objid "LPX64" subobj "LPX64
1810 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
1811 loi->loi_id, loi->loi_ost_idx, err);
1819 static int lov_statfs_interpret(struct ptlrpc_request_set *rqset,
1822 struct lov_request_set *lovset = (struct lov_request_set *)data;
1827 lovset->set_completes = 0;
1829 err = lov_fini_statfs_set(lovset);
1830 RETURN(rc ? rc : err);
1833 static int lov_statfs_async(struct obd_device *obd, struct obd_info *oinfo,
1834 __u64 max_age, struct ptlrpc_request_set *rqset)
1836 struct lov_request_set *set;
1837 struct lov_request *req;
1838 struct list_head *pos;
1839 struct lov_obd *lov;
1843 LASSERT(oinfo != NULL);
1844 LASSERT(oinfo->oi_osfs != NULL);
1847 rc = lov_prep_statfs_set(obd, oinfo, &set);
1851 list_for_each (pos, &set->set_list) {
1852 struct obd_device *osc_obd;
1854 req = list_entry(pos, struct lov_request, rq_link);
1856 osc_obd = class_exp2obd(lov->lov_tgts[req->rq_idx]->ltd_exp);
1857 rc = obd_statfs_async(osc_obd, &req->rq_oi, max_age, rqset);
1862 if (rc || list_empty(&rqset->set_requests)) {
1865 set->set_completes = 0;
1866 err = lov_fini_statfs_set(set);
1867 RETURN(rc ? rc : err);
1870 LASSERT(rqset->set_interpret == NULL);
1871 rqset->set_interpret = lov_statfs_interpret;
1872 rqset->set_arg = (void *)set;
1876 static int lov_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1877 __u64 max_age, __u32 flags)
1879 struct ptlrpc_request_set *set = NULL;
1880 struct obd_info oinfo = { { { 0 } } };
1885 /* for obdclass we forbid using obd_statfs_rqset, but prefer using async
1886 * statfs requests */
1887 set = ptlrpc_prep_set();
1891 oinfo.oi_osfs = osfs;
1892 oinfo.oi_flags = flags;
1893 rc = lov_statfs_async(obd, &oinfo, max_age, set);
1895 rc = ptlrpc_set_wait(set);
1896 ptlrpc_set_destroy(set);
1901 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1902 void *karg, void *uarg)
1904 struct obd_device *obddev = class_exp2obd(exp);
1905 struct lov_obd *lov = &obddev->u.lov;
1906 int i = 0, rc = 0, count = lov->desc.ld_tgt_count;
1907 struct obd_uuid *uuidp;
1911 case IOC_OBD_STATFS: {
1912 struct obd_ioctl_data *data = karg;
1913 struct obd_device *osc_obd;
1914 struct obd_statfs stat_buf = {0};
1917 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
1918 LASSERT(data->ioc_plen1 == sizeof(struct obd_statfs));
1920 if ((index >= count))
1923 if (!lov->lov_tgts[index])
1924 /* Try again with the next index */
1926 if (!lov->lov_tgts[index]->ltd_active)
1929 osc_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
1933 /* got statfs data */
1934 rc = obd_statfs(osc_obd, &stat_buf,
1935 cfs_time_current_64() - HZ, 0);
1938 if (copy_to_user(data->ioc_pbuf1, &stat_buf, data->ioc_plen1))
1941 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(osc_obd),
1946 case OBD_IOC_LOV_GET_CONFIG: {
1947 struct obd_ioctl_data *data;
1948 struct lov_desc *desc;
1953 if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
1956 data = (struct obd_ioctl_data *)buf;
1958 if (sizeof(*desc) > data->ioc_inllen1) {
1959 obd_ioctl_freedata(buf, len);
1963 if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
1964 obd_ioctl_freedata(buf, len);
1968 if (sizeof(__u32) * count > data->ioc_inllen3) {
1969 obd_ioctl_freedata(buf, len);
1973 desc = (struct lov_desc *)data->ioc_inlbuf1;
1974 memcpy(desc, &(lov->desc), sizeof(*desc));
1976 uuidp = (struct obd_uuid *)data->ioc_inlbuf2;
1977 genp = (__u32 *)data->ioc_inlbuf3;
1978 /* the uuid will be empty for deleted OSTs */
1979 for (i = 0; i < count; i++, uuidp++, genp++) {
1980 if (!lov->lov_tgts[i])
1982 *uuidp = lov->lov_tgts[i]->ltd_uuid;
1983 *genp = lov->lov_tgts[i]->ltd_gen;
1986 if (copy_to_user((void *)uarg, buf, len))
1988 obd_ioctl_freedata(buf, len);
1991 case LL_IOC_LOV_SETSTRIPE:
1992 rc = lov_setstripe(exp, karg, uarg);
1994 case LL_IOC_LOV_GETSTRIPE:
1995 rc = lov_getstripe(exp, karg, uarg);
1997 case LL_IOC_LOV_SETEA:
1998 rc = lov_setea(exp, karg, uarg);
2000 case OBD_IOC_QUOTACTL: {
2001 struct if_quotactl *qctl = karg;
2002 struct lov_tgt_desc *tgt = NULL;
2003 struct obd_quotactl *oqctl;
2005 if (qctl->qc_valid == QC_OSTIDX) {
2006 if (qctl->qc_idx < 0 || count <= qctl->qc_idx)
2009 tgt = lov->lov_tgts[qctl->qc_idx];
2010 if (!tgt || !tgt->ltd_exp)
2012 } else if (qctl->qc_valid == QC_UUID) {
2013 for (i = 0; i < count; i++) {
2014 tgt = lov->lov_tgts[i];
2016 !obd_uuid_equals(&tgt->ltd_uuid,
2020 if (tgt->ltd_exp == NULL)
2032 LASSERT(tgt && tgt->ltd_exp);
2033 OBD_ALLOC_PTR(oqctl);
2037 QCTL_COPY(oqctl, qctl);
2038 rc = obd_quotactl(tgt->ltd_exp, oqctl);
2040 QCTL_COPY(qctl, oqctl);
2041 qctl->qc_valid = QC_OSTIDX;
2042 qctl->obd_uuid = tgt->ltd_uuid;
2044 OBD_FREE_PTR(oqctl);
2053 for (i = 0; i < count; i++) {
2056 /* OST was disconnected */
2057 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2060 err = obd_iocontrol(cmd, lov->lov_tgts[i]->ltd_exp,
2062 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
2065 if (lov->lov_tgts[i]->ltd_active) {
2066 CDEBUG(err == -ENOTTY ?
2067 D_IOCTL : D_WARNING,
2068 "iocontrol OSC %s on OST "
2069 "idx %d cmd %x: err = %d\n",
2070 lov_uuid2str(lov, i),
2087 #define FIEMAP_BUFFER_SIZE 4096
2090 * Non-zero fe_logical indicates that this is a continuation FIEMAP
2091 * call. The local end offset and the device are sent in the first
2092 * fm_extent. This function calculates the stripe number from the index.
2093 * This function returns a stripe_no on which mapping is to be restarted.
2095 * This function returns fm_end_offset which is the in-OST offset at which
2096 * mapping should be restarted. If fm_end_offset=0 is returned then caller
2097 * will re-calculate proper offset in next stripe.
2098 * Note that the first extent is passed to lov_get_info via the value field.
2100 * \param fiemap fiemap request header
2101 * \param lsm striping information for the file
2102 * \param fm_start logical start of mapping
2103 * \param fm_end logical end of mapping
2104 * \param start_stripe starting stripe will be returned in this
2106 obd_size fiemap_calc_fm_end_offset(struct ll_user_fiemap *fiemap,
2107 struct lov_stripe_md *lsm, obd_size fm_start,
2108 obd_size fm_end, int *start_stripe)
2110 obd_size local_end = fiemap->fm_extents[0].fe_logical;
2111 obd_off lun_start, lun_end;
2112 obd_size fm_end_offset;
2113 int stripe_no = -1, i;
2115 if (fiemap->fm_extent_count == 0 ||
2116 fiemap->fm_extents[0].fe_logical == 0)
2119 /* Find out stripe_no from ost_index saved in the fe_device */
2120 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2121 if (lsm->lsm_oinfo[i]->loi_ost_idx ==
2122 fiemap->fm_extents[0].fe_device) {
2128 /* If we have finished mapping on previous device, shift logical
2129 * offset to start of next device */
2130 if ((lov_stripe_intersects(lsm, stripe_no, fm_start, fm_end,
2131 &lun_start, &lun_end)) != 0 &&
2132 local_end < lun_end) {
2133 fm_end_offset = local_end;
2134 *start_stripe = stripe_no;
2136 /* This is a special value to indicate that caller should
2137 * calculate offset in next stripe. */
2139 *start_stripe = (stripe_no + 1) % lsm->lsm_stripe_count;
2142 return fm_end_offset;
2146 * We calculate on which OST the mapping will end. If the length of mapping
2147 * is greater than (stripe_size * stripe_count) then the last_stripe will
2148 * will be one just before start_stripe. Else we check if the mapping
2149 * intersects each OST and find last_stripe.
2150 * This function returns the last_stripe and also sets the stripe_count
2151 * over which the mapping is spread
2153 * \param lsm striping information for the file
2154 * \param fm_start logical start of mapping
2155 * \param fm_end logical end of mapping
2156 * \param start_stripe starting stripe of the mapping
2157 * \param stripe_count the number of stripes across which to map is returned
2159 * \retval last_stripe return the last stripe of the mapping
2161 int fiemap_calc_last_stripe(struct lov_stripe_md *lsm, obd_size fm_start,
2162 obd_size fm_end, int start_stripe,
2166 obd_off obd_start, obd_end;
2169 if (fm_end - fm_start > lsm->lsm_stripe_size * lsm->lsm_stripe_count) {
2170 last_stripe = (start_stripe < 1 ? lsm->lsm_stripe_count - 1 :
2172 *stripe_count = lsm->lsm_stripe_count;
2174 for (j = 0, i = start_stripe; j < lsm->lsm_stripe_count;
2175 i = (i + 1) % lsm->lsm_stripe_count, j++) {
2176 if ((lov_stripe_intersects(lsm, i, fm_start, fm_end,
2177 &obd_start, &obd_end)) == 0)
2181 last_stripe = (start_stripe + j - 1) %lsm->lsm_stripe_count;
2188 * Set fe_device and copy extents from local buffer into main return buffer.
2190 * \param fiemap fiemap request header
2191 * \param lcl_fm_ext array of local fiemap extents to be copied
2192 * \param ost_index OST index to be written into the fm_device field for each
2194 * \param ext_count number of extents to be copied
2195 * \param current_extent where to start copying in main extent array
2197 void fiemap_prepare_and_copy_exts(struct ll_user_fiemap *fiemap,
2198 struct ll_fiemap_extent *lcl_fm_ext,
2199 int ost_index, unsigned int ext_count,
2205 for (ext = 0; ext < ext_count; ext++) {
2206 lcl_fm_ext[ext].fe_device = ost_index;
2207 lcl_fm_ext[ext].fe_flags |= FIEMAP_EXTENT_NET;
2210 /* Copy fm_extent's from fm_local to return buffer */
2211 to = (char *)fiemap + fiemap_count_to_size(current_extent);
2212 memcpy(to, lcl_fm_ext, ext_count * sizeof(struct ll_fiemap_extent));
2216 * Break down the FIEMAP request and send appropriate calls to individual OSTs.
2217 * This also handles the restarting of FIEMAP calls in case mapping overflows
2218 * the available number of extents in single call.
2220 static int lov_fiemap(struct lov_obd *lov, __u32 keylen, void *key,
2221 __u32 *vallen, void *val, struct lov_stripe_md *lsm)
2223 struct ll_fiemap_info_key *fm_key = key;
2224 struct ll_user_fiemap *fiemap = val;
2225 struct ll_user_fiemap *fm_local = NULL;
2226 struct ll_fiemap_extent *lcl_fm_ext;
2228 unsigned int get_num_extents = 0;
2229 int ost_index = 0, actual_start_stripe, start_stripe;
2230 obd_size fm_start, fm_end, fm_length, fm_end_offset = 0;
2232 int current_extent = 0, rc = 0, i;
2233 int ost_eof = 0; /* EOF for object */
2234 int ost_done = 0; /* done with required mapping for this OST? */
2236 int cur_stripe = 0, cur_stripe_wrap = 0, stripe_count;
2237 unsigned int buffer_size = FIEMAP_BUFFER_SIZE;
2242 if (fiemap_count_to_size(fm_key->fiemap.fm_extent_count) < buffer_size)
2243 buffer_size = fiemap_count_to_size(fm_key->fiemap.fm_extent_count);
2245 OBD_ALLOC(fm_local, buffer_size);
2246 if (fm_local == NULL)
2247 GOTO(out, rc = -ENOMEM);
2248 lcl_fm_ext = &fm_local->fm_extents[0];
2250 count_local = fiemap_size_to_count(buffer_size);
2252 memcpy(fiemap, &fm_key->fiemap, sizeof(*fiemap));
2253 fm_start = fiemap->fm_start;
2254 fm_length = fiemap->fm_length;
2255 /* Calculate start stripe, last stripe and length of mapping */
2256 actual_start_stripe = start_stripe = lov_stripe_number(lsm, fm_start);
2257 fm_end = (fm_length == ~0ULL ? fm_key->oa.o_size :
2258 fm_start + fm_length - 1);
2259 /* If fm_length != ~0ULL but fm_start+fm_length-1 exceeds file size */
2260 if (fm_end > fm_key->oa.o_size)
2261 fm_end = fm_key->oa.o_size;
2263 last_stripe = fiemap_calc_last_stripe(lsm, fm_start, fm_end,
2264 actual_start_stripe, &stripe_count);
2266 fm_end_offset = fiemap_calc_fm_end_offset(fiemap, lsm, fm_start, fm_end,
2269 if (fiemap->fm_extent_count == 0) {
2270 get_num_extents = 1;
2274 /* Check each stripe */
2275 for (cur_stripe = start_stripe, i = 0; i < stripe_count;
2276 i++, cur_stripe = (cur_stripe + 1) % lsm->lsm_stripe_count) {
2277 obd_size req_fm_len; /* Stores length of required mapping */
2278 obd_size len_mapped_single_call;
2279 obd_off lun_start, lun_end, obd_object_end;
2280 unsigned int ext_count;
2282 cur_stripe_wrap = cur_stripe;
2284 /* Find out range of mapping on this stripe */
2285 if ((lov_stripe_intersects(lsm, cur_stripe, fm_start, fm_end,
2286 &lun_start, &obd_object_end)) == 0)
2289 /* If this is a continuation FIEMAP call and we are on
2290 * starting stripe then lun_start needs to be set to
2292 if (fm_end_offset != 0 && cur_stripe == start_stripe)
2293 lun_start = fm_end_offset;
2295 if (fm_length != ~0ULL) {
2296 /* Handle fm_start + fm_length overflow */
2297 if (fm_start + fm_length < fm_start)
2298 fm_length = ~0ULL - fm_start;
2299 lun_end = lov_size_to_stripe(lsm, fm_start + fm_length,
2305 if (lun_start == lun_end)
2308 req_fm_len = obd_object_end - lun_start;
2309 fm_local->fm_length = 0;
2310 len_mapped_single_call = 0;
2312 /* If the output buffer is very large and the objects have many
2313 * extents we may need to loop on a single OST repeatedly */
2317 if (get_num_extents == 0) {
2318 /* Don't get too many extents. */
2319 if (current_extent + count_local >
2320 fiemap->fm_extent_count)
2321 count_local = fiemap->fm_extent_count -
2325 lun_start += len_mapped_single_call;
2326 fm_local->fm_length = req_fm_len - len_mapped_single_call;
2327 req_fm_len = fm_local->fm_length;
2328 fm_local->fm_extent_count = count_local;
2329 fm_local->fm_mapped_extents = 0;
2330 fm_local->fm_flags = fiemap->fm_flags;
2332 fm_key->oa.o_id = lsm->lsm_oinfo[cur_stripe]->loi_id;
2333 ost_index = lsm->lsm_oinfo[cur_stripe]->loi_ost_idx;
2335 if (ost_index < 0 || ost_index >=lov->desc.ld_tgt_count)
2336 GOTO(out, rc = -EINVAL);
2338 /* If OST is inactive, return extent with UNKNOWN flag */
2339 if (lov && !lov->lov_tgts[ost_index]->ltd_active) {
2340 fm_local->fm_flags |= FIEMAP_EXTENT_LAST;
2341 fm_local->fm_mapped_extents = 1;
2343 lcl_fm_ext[0].fe_logical = lun_start;
2344 lcl_fm_ext[0].fe_length = obd_object_end -
2346 lcl_fm_ext[0].fe_flags |= FIEMAP_EXTENT_UNKNOWN;
2351 fm_local->fm_start = lun_start;
2352 fm_local->fm_flags &= ~FIEMAP_FLAG_DEVICE_ORDER;
2353 memcpy(&fm_key->fiemap, fm_local, sizeof(*fm_local));
2354 *vallen=fiemap_count_to_size(fm_local->fm_extent_count);
2355 rc = obd_get_info(lov->lov_tgts[ost_index]->ltd_exp,
2356 keylen, key, vallen, fm_local, lsm);
2361 ext_count = fm_local->fm_mapped_extents;
2362 if (ext_count == 0) {
2364 /* If last stripe has hole at the end,
2365 * then we need to return */
2366 if (cur_stripe_wrap == last_stripe) {
2367 fiemap->fm_mapped_extents = 0;
2373 /* If we just need num of extents then go to next device */
2374 if (get_num_extents) {
2375 current_extent += ext_count;
2379 len_mapped_single_call = lcl_fm_ext[ext_count-1].fe_logical -
2380 lun_start + lcl_fm_ext[ext_count - 1].fe_length;
2382 /* Have we finished mapping on this device? */
2383 if (req_fm_len <= len_mapped_single_call)
2386 /* Clear the EXTENT_LAST flag which can be present on
2388 if (lcl_fm_ext[ext_count-1].fe_flags & FIEMAP_EXTENT_LAST)
2389 lcl_fm_ext[ext_count - 1].fe_flags &=
2390 ~FIEMAP_EXTENT_LAST;
2392 curr_loc = lov_stripe_size(lsm,
2393 lcl_fm_ext[ext_count - 1].fe_logical+
2394 lcl_fm_ext[ext_count - 1].fe_length,
2396 if (curr_loc >= fm_key->oa.o_size)
2399 fiemap_prepare_and_copy_exts(fiemap, lcl_fm_ext,
2400 ost_index, ext_count,
2403 current_extent += ext_count;
2405 /* Ran out of available extents? */
2406 if (current_extent >= fiemap->fm_extent_count)
2408 } while (ost_done == 0 && ost_eof == 0);
2410 if (cur_stripe_wrap == last_stripe)
2415 /* Indicate that we are returning device offsets unless file just has
2417 if (lsm->lsm_stripe_count > 1)
2418 fiemap->fm_flags |= FIEMAP_FLAG_DEVICE_ORDER;
2420 if (get_num_extents)
2421 goto skip_last_device_calc;
2423 /* Check if we have reached the last stripe and whether mapping for that
2424 * stripe is done. */
2425 if (cur_stripe_wrap == last_stripe) {
2426 if (ost_done || ost_eof)
2427 fiemap->fm_extents[current_extent - 1].fe_flags |=
2431 skip_last_device_calc:
2432 fiemap->fm_mapped_extents = current_extent;
2435 OBD_FREE(fm_local, buffer_size);
2439 static int lov_get_info(struct obd_export *exp, __u32 keylen,
2440 void *key, __u32 *vallen, void *val,
2441 struct lov_stripe_md *lsm)
2443 struct obd_device *obddev = class_exp2obd(exp);
2444 struct lov_obd *lov = &obddev->u.lov;
2448 if (!vallen || !val)
2453 if (KEY_IS(KEY_LOCK_TO_STRIPE)) {
2456 struct ldlm_lock *lock;
2458 struct ldlm_res_id *res_id = &data->lock->l_resource->lr_name;
2459 struct lov_oinfo *loi;
2460 __u32 *stripe = val;
2462 if (*vallen < sizeof(*stripe))
2463 GOTO(out, rc = -EFAULT);
2464 *vallen = sizeof(*stripe);
2466 /* XXX This is another one of those bits that will need to
2467 * change if we ever actually support nested LOVs. It uses
2468 * the lock's export to find out which stripe it is. */
2469 /* XXX - it's assumed all the locks for deleted OSTs have
2470 * been cancelled. Also, the export for deleted OSTs will
2471 * be NULL and won't match the lock's export. */
2472 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2473 loi = lsm->lsm_oinfo[i];
2474 if (!lov->lov_tgts[loi->loi_ost_idx])
2476 if (lov->lov_tgts[loi->loi_ost_idx]->ltd_exp ==
2477 data->lock->l_conn_export &&
2478 osc_res_name_eq(loi->loi_id, loi->loi_gr, res_id)) {
2483 LDLM_ERROR(data->lock, "lock on inode without such object");
2484 dump_lsm(D_ERROR, lsm);
2485 GOTO(out, rc = -ENXIO);
2486 } else if (KEY_IS(KEY_LAST_ID)) {
2487 struct obd_id_info *info = val;
2488 __u32 size = sizeof(obd_id);
2489 struct lov_tgt_desc *tgt;
2491 LASSERT(*vallen == sizeof(struct obd_id_info));
2492 tgt = lov->lov_tgts[info->idx];
2494 if (!tgt || !tgt->ltd_active)
2495 GOTO(out, rc = -ESRCH);
2497 rc = obd_get_info(tgt->ltd_exp, keylen, key, &size, info->data, NULL);
2499 } else if (KEY_IS(KEY_LOVDESC)) {
2500 struct lov_desc *desc_ret = val;
2501 *desc_ret = lov->desc;
2504 } else if (KEY_IS(KEY_FIEMAP)) {
2505 rc = lov_fiemap(lov, keylen, key, vallen, val, lsm);
2516 static int lov_set_info_async(struct obd_export *exp, obd_count keylen,
2517 void *key, obd_count vallen, void *val,
2518 struct ptlrpc_request_set *set)
2520 struct obd_device *obddev = class_exp2obd(exp);
2521 struct lov_obd *lov = &obddev->u.lov;
2524 struct lov_tgt_desc *tgt;
2525 unsigned incr, check_uuid,
2526 do_inactive, no_set;
2527 unsigned next_id = 0, mds_con = 0;
2530 incr = check_uuid = do_inactive = no_set = 0;
2533 set = ptlrpc_prep_set();
2539 count = lov->desc.ld_tgt_count;
2541 if (KEY_IS(KEY_NEXT_ID)) {
2542 count = vallen / sizeof(struct obd_id_info);
2543 vallen = sizeof(obd_id);
2544 incr = sizeof(struct obd_id_info);
2547 } else if (KEY_IS(KEY_CHECKSUM)) {
2549 } else if (KEY_IS(KEY_UNLINKED)) {
2550 check_uuid = val ? 1 : 0;
2551 } else if (KEY_IS(KEY_EVICT_BY_NID)) {
2552 /* use defaults: do_inactive = incr = 0; */
2553 } else if (KEY_IS(KEY_MDS_CONN)) {
2557 for (i = 0; i < count; i++, val = (char *)val + incr) {
2559 tgt = lov->lov_tgts[((struct obd_id_info*)val)->idx];
2561 tgt = lov->lov_tgts[i];
2563 /* OST was disconnected */
2564 if (!tgt || !tgt->ltd_exp)
2567 /* OST is inactive and we don't want inactive OSCs */
2568 if (!tgt->ltd_active && !do_inactive)
2572 struct mds_group_info *mgi;
2574 LASSERT(vallen == sizeof(*mgi));
2575 mgi = (struct mds_group_info *)val;
2577 /* Only want a specific OSC */
2578 if (mgi->uuid && !obd_uuid_equals(mgi->uuid,
2582 err = obd_set_info_async(tgt->ltd_exp,
2583 keylen, key, sizeof(int),
2585 } else if (next_id) {
2586 err = obd_set_info_async(tgt->ltd_exp,
2587 keylen, key, vallen,
2588 ((struct obd_id_info*)val)->data, set);
2590 /* Only want a specific OSC */
2592 !obd_uuid_equals(val, &tgt->ltd_uuid))
2595 err = obd_set_info_async(tgt->ltd_exp,
2596 keylen, key, vallen, val, set);
2605 err = ptlrpc_set_wait(set);
2608 ptlrpc_set_destroy(set);
2613 static int lov_checkmd(struct obd_export *exp, struct obd_export *md_exp,
2614 struct lov_stripe_md *lsm)
2622 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
2623 rc = lsm_op_find(lsm->lsm_magic)->lsm_revalidate(lsm, md_exp->exp_obd);
2628 int lov_test_and_clear_async_rc(struct lov_stripe_md *lsm)
2633 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2634 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
2635 if (loi->loi_ar.ar_rc && !rc)
2636 rc = loi->loi_ar.ar_rc;
2637 loi->loi_ar.ar_rc = 0;
2641 EXPORT_SYMBOL(lov_test_and_clear_async_rc);
2644 static int lov_extent_calc(struct obd_export *exp, struct lov_stripe_md *lsm,
2645 int cmd, __u64 *offset)
2647 __u32 ssize = lsm->lsm_stripe_size;
2651 do_div(start, ssize);
2652 start = start * ssize;
2654 CDEBUG(D_DLMTRACE, "offset "LPU64", stripe %u, start "LPU64
2655 ", end "LPU64"\n", *offset, ssize, start,
2657 if (cmd == OBD_CALC_STRIPE_END) {
2658 *offset = start + ssize - 1;
2659 } else if (cmd == OBD_CALC_STRIPE_START) {
2670 struct lov_multi_wait {
2671 struct ldlm_lock *lock;
2677 int lov_complete_many(struct obd_export *exp, struct lov_stripe_md *lsm,
2678 struct lustre_handle *lockh)
2680 struct lov_lock_handles *lov_lockh = NULL;
2681 struct lustre_handle *lov_lockhp;
2682 struct lov_obd *lov;
2683 struct lov_oinfo *loi;
2684 struct lov_multi_wait *queues;
2688 ASSERT_LSM_MAGIC(lsm);
2690 if (!exp || !exp->exp_obd)
2693 LASSERT(lockh != NULL);
2694 if (lsm->lsm_stripe_count > 1) {
2695 lov_lockh = lov_handle2llh(lockh);
2696 if (lov_lockh == NULL) {
2697 CERROR("LOV: invalid lov lock handle %p\n", lockh);
2701 lov_lockhp = lov_lockh->llh_handles;
2706 OBD_ALLOC(queues, lsm->lsm_stripe_count * sizeof(*queues));
2708 GOTO(out, rc = -ENOMEM);
2710 lov = &exp->exp_obd->u.lov;
2711 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
2712 i++, loi++, lov_lockhp++) {
2713 struct ldlm_lock *lock;
2714 struct obd_device *obd;
2716 lock = ldlm_handle2lock_long(lov_lockhp, 0);
2718 CDEBUG(D_HA, "lov idx %d subobj "LPX64" no lock?\n",
2719 loi->loi_ost_idx, loi->loi_id);
2720 queues[i].completed = 1;
2724 queues[i].lock = lock;
2725 init_waitqueue_entry(&(queues[i].wait), current);
2726 add_wait_queue(lock->l_waitq, &(queues[i].wait));
2728 obd = class_exp2obd(lock->l_conn_export);
2730 imp = obd->u.cli.cl_import;
2732 spin_lock(&imp->imp_lock);
2733 queues[i].generation = imp->imp_generation;
2734 spin_unlock(&imp->imp_lock);
2738 lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, ldlm_expired_completion_wait,
2739 interrupted_completion_wait, &lwd);
2740 rc = l_wait_event_added(check_multi_complete(queues, lsm), &lwi);
2742 for (i = 0; i < lsm->lsm_stripe_count; i++)
2743 remove_wait_queue(lock->l_waitq, &(queues[i].wait));
2745 if (rc == -EINTR || rc == -ETIMEDOUT) {
2751 if (lov_lockh != NULL)
2752 lov_llh_put(lov_lockh);
2757 void lov_stripe_lock(struct lov_stripe_md *md)
2759 LASSERT(md->lsm_lock_owner != cfs_curproc_pid());
2760 spin_lock(&md->lsm_lock);
2761 LASSERT(md->lsm_lock_owner == 0);
2762 md->lsm_lock_owner = cfs_curproc_pid();
2764 EXPORT_SYMBOL(lov_stripe_lock);
2766 void lov_stripe_unlock(struct lov_stripe_md *md)
2768 LASSERT(md->lsm_lock_owner == cfs_curproc_pid());
2769 md->lsm_lock_owner = 0;
2770 spin_unlock(&md->lsm_lock);
2772 EXPORT_SYMBOL(lov_stripe_unlock);
2775 struct obd_ops lov_obd_ops = {
2776 .o_owner = THIS_MODULE,
2777 .o_setup = lov_setup,
2778 .o_precleanup = lov_precleanup,
2779 .o_cleanup = lov_cleanup,
2780 //.o_process_config = lov_process_config,
2781 .o_connect = lov_connect,
2782 .o_disconnect = lov_disconnect,
2783 .o_statfs = lov_statfs,
2784 .o_statfs_async = lov_statfs_async,
2785 .o_packmd = lov_packmd,
2786 .o_unpackmd = lov_unpackmd,
2787 .o_checkmd = lov_checkmd,
2788 .o_create = lov_create,
2789 .o_destroy = lov_destroy,
2790 .o_getattr = lov_getattr,
2791 .o_getattr_async = lov_getattr_async,
2792 .o_setattr = lov_setattr,
2793 .o_setattr_async = lov_setattr_async,
2795 .o_merge_lvb = lov_merge_lvb,
2796 .o_adjust_kms = lov_adjust_kms,
2797 .o_punch = lov_punch,
2799 .o_enqueue = lov_enqueue,
2800 .o_change_cbdata = lov_change_cbdata,
2801 .o_cancel = lov_cancel,
2802 .o_cancel_unused = lov_cancel_unused,
2803 .o_iocontrol = lov_iocontrol,
2804 .o_get_info = lov_get_info,
2805 .o_set_info_async = lov_set_info_async,
2806 .o_extent_calc = lov_extent_calc,
2807 .o_llog_init = lov_llog_init,
2808 .o_llog_finish = lov_llog_finish,
2809 .o_notify = lov_notify,
2810 .o_pool_new = lov_pool_new,
2811 .o_pool_rem = lov_pool_remove,
2812 .o_pool_add = lov_pool_add,
2813 .o_pool_del = lov_pool_del,
2816 static quota_interface_t *quota_interface;
2817 extern quota_interface_t lov_quota_interface;
2819 cfs_mem_cache_t *lov_oinfo_slab;
2821 extern struct lu_kmem_descr lov_caches[];
2823 int __init lov_init(void)
2825 struct lprocfs_static_vars lvars = { 0 };
2829 /* print an address of _any_ initialized kernel symbol from this
2830 * module, to allow debugging with gdb that doesn't support data
2831 * symbols from modules.*/
2832 CDEBUG(D_CONSOLE, "Lustre LOV module (%p).\n", &lov_caches);
2834 rc = lu_kmem_init(lov_caches);
2838 lov_oinfo_slab = cfs_mem_cache_create("lov_oinfo",
2839 sizeof(struct lov_oinfo),
2840 0, SLAB_HWCACHE_ALIGN);
2841 if (lov_oinfo_slab == NULL) {
2842 lu_kmem_fini(lov_caches);
2845 lprocfs_lov_init_vars(&lvars);
2847 request_module("lquota");
2848 quota_interface = PORTAL_SYMBOL_GET(lov_quota_interface);
2849 init_obd_quota_ops(quota_interface, &lov_obd_ops);
2851 rc = class_register_type(&lov_obd_ops, NULL, lvars.module_vars,
2852 LUSTRE_LOV_NAME, &lov_device_type);
2855 if (quota_interface)
2856 PORTAL_SYMBOL_PUT(lov_quota_interface);
2857 rc2 = cfs_mem_cache_destroy(lov_oinfo_slab);
2859 lu_kmem_fini(lov_caches);
2866 static void /*__exit*/ lov_exit(void)
2870 lu_device_type_fini(&lov_device_type);
2871 lu_kmem_fini(lov_caches);
2873 if (quota_interface)
2874 PORTAL_SYMBOL_PUT(lov_quota_interface);
2876 class_unregister_type(LUSTRE_LOV_NAME);
2877 rc = cfs_mem_cache_destroy(lov_oinfo_slab);
2881 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2882 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver");
2883 MODULE_LICENSE("GPL");
2885 cfs_module(lov, LUSTRE_VERSION_STRING, lov_init, lov_exit);