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 static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
109 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
110 enum obd_notify_event ev, void *data);
113 #define MAX_STRING_SIZE 128
114 int lov_connect_obd(struct obd_device *obd, __u32 index, int activate,
115 struct obd_connect_data *data)
117 struct lov_obd *lov = &obd->u.lov;
118 struct obd_uuid tgt_uuid;
119 struct obd_device *tgt_obd;
120 struct obd_uuid lov_osc_uuid = { "LOV_OSC_UUID" };
121 struct lustre_handle conn = {0, };
122 struct obd_import *imp;
125 cfs_proc_dir_entry_t *lov_proc_dir;
130 if (!lov->lov_tgts[index])
133 tgt_uuid = lov->lov_tgts[index]->ltd_uuid;
135 tgt_obd = class_find_client_obd(&tgt_uuid, LUSTRE_OSC_NAME,
139 CERROR("Target %s not attached\n", obd_uuid2str(&tgt_uuid));
142 if (!tgt_obd->obd_set_up) {
143 CERROR("Target %s not set up\n", obd_uuid2str(&tgt_uuid));
147 /* override the sp_me from lov */
148 tgt_obd->u.cli.cl_sp_me = lov->lov_sp_me;
150 if (data && (data->ocd_connect_flags & OBD_CONNECT_INDEX))
151 data->ocd_index = index;
154 * Divine LOV knows that OBDs under it are OSCs.
156 imp = tgt_obd->u.cli.cl_import;
159 tgt_obd->obd_no_recov = 0;
160 /* FIXME this is probably supposed to be
161 ptlrpc_set_import_active. Horrible naming. */
162 ptlrpc_activate_import(imp);
165 if (imp->imp_invalid) {
166 CERROR("not connecting OSC %s; administratively "
167 "disabled\n", obd_uuid2str(&tgt_uuid));
168 rc = obd_register_observer(tgt_obd, obd);
170 CERROR("Target %s register_observer error %d; "
171 "will not be able to reactivate\n",
172 obd_uuid2str(&tgt_uuid), rc);
177 rc = obd_connect(NULL, &conn, tgt_obd, &lov_osc_uuid, data, NULL);
179 CERROR("Target %s connect error %d\n",
180 obd_uuid2str(&tgt_uuid), rc);
183 lov->lov_tgts[index]->ltd_exp = class_conn2export(&conn);
184 if (!lov->lov_tgts[index]->ltd_exp) {
185 CERROR("Target %s: null export!\n", obd_uuid2str(&tgt_uuid));
189 rc = obd_register_observer(tgt_obd, obd);
191 CERROR("Target %s register_observer error %d\n",
192 obd_uuid2str(&tgt_uuid), rc);
193 obd_disconnect(lov->lov_tgts[index]->ltd_exp);
194 lov->lov_tgts[index]->ltd_exp = NULL;
198 lov->lov_tgts[index]->ltd_reap = 0;
200 lov->lov_tgts[index]->ltd_active = 1;
201 lov->desc.ld_active_tgt_count++;
202 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 0;
204 CDEBUG(D_CONFIG, "Connected tgt idx %d %s (%s) %sactive\n", index,
205 obd_uuid2str(&tgt_uuid), tgt_obd->obd_name, activate ? "":"in");
208 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
210 struct obd_device *osc_obd = class_conn2obd(&conn);
211 cfs_proc_dir_entry_t *osc_symlink;
212 char name[MAX_STRING_SIZE];
214 LASSERT(osc_obd != NULL);
215 LASSERT(osc_obd->obd_magic == OBD_DEVICE_MAGIC);
216 LASSERT(osc_obd->obd_type->typ_name != NULL);
217 snprintf(name, MAX_STRING_SIZE, "../../../%s/%s",
218 osc_obd->obd_type->typ_name,
220 osc_symlink = lprocfs_add_symlink(osc_obd->obd_name, lov_proc_dir,
222 if (osc_symlink == NULL) {
223 CERROR("could not register LOV target "
224 "/proc/fs/lustre/%s/%s/target_obds/%s.",
225 obd->obd_type->typ_name, obd->obd_name,
227 lprocfs_remove(&lov_proc_dir);
232 rc = qos_add_tgt(obd, index);
234 CERROR("qos_add_tgt failed %d\n", rc);
239 static int lov_connect(const struct lu_env *env,
240 struct lustre_handle *conn, struct obd_device *obd,
241 struct obd_uuid *cluuid, struct obd_connect_data *data,
244 struct lov_obd *lov = &obd->u.lov;
245 struct lov_tgt_desc *tgt;
249 CDEBUG(D_CONFIG, "connect #%d\n", lov->lov_connects);
251 rc = class_connect(conn, obd, cluuid);
255 /* Why should there ever be more than 1 connect? */
257 LASSERT(lov->lov_connects == 1);
259 memset(&lov->lov_ocd, 0, sizeof(lov->lov_ocd));
261 lov->lov_ocd = *data;
264 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
265 tgt = lov->lov_tgts[i];
266 if (!tgt || obd_uuid_empty(&tgt->ltd_uuid))
268 /* Flags will be lowest common denominator */
269 rc = lov_connect_obd(obd, i, tgt->ltd_activate, &lov->lov_ocd);
271 CERROR("%s: lov connect tgt %d failed: %d\n",
272 obd->obd_name, i, rc);
275 /* connect to administrative disabled ost */
276 if (!lov->lov_tgts[i]->ltd_exp)
279 rc = lov_notify(obd, lov->lov_tgts[i]->ltd_exp->exp_obd,
280 OBD_NOTIFY_ACTIVE, (void *)&i);
282 CERROR("%s error sending notify %d\n",
291 static int lov_disconnect_obd(struct obd_device *obd, __u32 index)
293 cfs_proc_dir_entry_t *lov_proc_dir;
294 struct lov_obd *lov = &obd->u.lov;
295 struct obd_device *osc_obd;
300 if (lov->lov_tgts[index] == NULL)
303 osc_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
304 CDEBUG(D_CONFIG, "%s: disconnecting target %s\n",
305 obd->obd_name, osc_obd->obd_name);
307 if (lov->lov_tgts[index]->ltd_active) {
308 lov->lov_tgts[index]->ltd_active = 0;
309 lov->desc.ld_active_tgt_count--;
310 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 1;
313 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
315 cfs_proc_dir_entry_t *osc_symlink;
317 osc_symlink = lprocfs_srch(lov_proc_dir, osc_obd->obd_name);
319 lprocfs_remove(&osc_symlink);
321 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing.",
322 obd->obd_type->typ_name, obd->obd_name,
328 /* Pass it on to our clients.
329 * XXX This should be an argument to disconnect,
330 * XXX not a back-door flag on the OBD. Ah well.
332 osc_obd->obd_force = obd->obd_force;
333 osc_obd->obd_fail = obd->obd_fail;
334 osc_obd->obd_no_recov = obd->obd_no_recov;
337 obd_register_observer(osc_obd, NULL);
339 rc = obd_disconnect(lov->lov_tgts[index]->ltd_exp);
341 CERROR("Target %s disconnect error %d\n",
342 lov_uuid2str(lov, index), rc);
346 qos_del_tgt(obd, index);
348 lov->lov_tgts[index]->ltd_exp = NULL;
352 static int lov_disconnect(struct obd_export *exp)
354 struct obd_device *obd = class_exp2obd(exp);
355 struct lov_obd *lov = &obd->u.lov;
362 /* Only disconnect the underlying layers on the final disconnect. */
364 if (lov->lov_connects != 0) {
365 /* why should there be more than 1 connect? */
366 CERROR("disconnect #%d\n", lov->lov_connects);
370 /* Let's hold another reference so lov_del_obd doesn't spin through
374 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
375 if (lov->lov_tgts[i] && lov->lov_tgts[i]->ltd_exp) {
376 /* Disconnection is the last we know about an obd */
377 lov_del_target(obd, i, 0, lov->lov_tgts[i]->ltd_gen);
383 rc = class_disconnect(exp); /* bz 9811 */
389 * -EINVAL : UUID can't be found in the LOV's target list
390 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
391 * -EBADF : The UUID is found, but the OBD is the wrong type (!)
392 * any >= 0 : is log target index
394 static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
397 struct lov_obd *lov = &obd->u.lov;
398 struct lov_tgt_desc *tgt;
402 CDEBUG(D_INFO, "Searching in lov %p for uuid %s (activate=%d)\n",
403 lov, uuid->uuid, activate);
406 for (index = 0; index < lov->desc.ld_tgt_count; index++) {
407 tgt = lov->lov_tgts[index];
408 if (!tgt || !tgt->ltd_exp)
411 CDEBUG(D_INFO, "lov idx %d is %s conn "LPX64"\n",
412 index, obd_uuid2str(&tgt->ltd_uuid),
413 tgt->ltd_exp->exp_handle.h_cookie);
414 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
418 if (index == lov->desc.ld_tgt_count)
419 GOTO(out, index = -EINVAL);
421 if (lov->lov_tgts[index]->ltd_active == activate) {
422 CDEBUG(D_INFO, "OSC %s already %sactive!\n", uuid->uuid,
423 activate ? "" : "in");
427 CDEBUG(D_CONFIG, "Marking OSC %s %sactive\n", obd_uuid2str(uuid),
428 activate ? "" : "in");
430 lov->lov_tgts[index]->ltd_active = activate;
433 lov->desc.ld_active_tgt_count++;
434 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 0;
436 lov->desc.ld_active_tgt_count--;
437 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 1;
439 /* remove any old qos penalty */
440 lov->lov_tgts[index]->ltd_qos.ltq_penalty = 0;
447 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
448 enum obd_notify_event ev, void *data)
453 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
454 struct obd_uuid *uuid;
458 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
459 CERROR("unexpected notification of %s %s!\n",
460 watched->obd_type->typ_name,
464 uuid = &watched->u.cli.cl_target_uuid;
466 /* Set OSC as active before notifying the observer, so the
467 * observer can use the OSC normally.
469 rc = lov_set_osc_active(obd, uuid, ev == OBD_NOTIFY_ACTIVE);
471 CERROR("%sactivation of %s failed: %d\n",
472 (ev == OBD_NOTIFY_ACTIVE) ? "" : "de",
473 obd_uuid2str(uuid), rc);
476 /* active event should be pass lov target index as data */
480 /* Pass the notification up the chain. */
482 rc = obd_notify_observer(obd, watched, ev, data);
484 /* NULL watched means all osc's in the lov (only for syncs) */
485 /* sync event should be send lov idx as data */
486 struct lov_obd *lov = &obd->u.lov;
487 struct obd_device *tgt_obd;
490 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
491 if (!lov->lov_tgts[i])
494 if ((ev == OBD_NOTIFY_SYNC) ||
495 (ev == OBD_NOTIFY_SYNC_NONBLOCK))
498 tgt_obd = class_exp2obd(lov->lov_tgts[i]->ltd_exp);
500 rc = obd_notify_observer(obd, tgt_obd, ev, data);
502 CERROR("%s: notify %s of %s failed %d\n",
504 obd->obd_observer->obd_name,
505 tgt_obd->obd_name, rc);
515 int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
516 __u32 index, int gen, int active)
518 struct lov_obd *lov = &obd->u.lov;
519 struct lov_tgt_desc *tgt;
523 CDEBUG(D_CONFIG, "uuid:%s idx:%d gen:%d active:%d\n",
524 uuidp->uuid, index, gen, active);
527 CERROR("request to add OBD %s with invalid generation: %d\n",
532 mutex_down(&lov->lov_lock);
534 if ((index < lov->lov_tgt_size) && (lov->lov_tgts[index] != NULL)) {
535 tgt = lov->lov_tgts[index];
536 CERROR("UUID %s already assigned at LOV target index %d\n",
537 obd_uuid2str(&tgt->ltd_uuid), index);
538 mutex_up(&lov->lov_lock);
542 if (index >= lov->lov_tgt_size) {
543 /* We need to reallocate the lov target array. */
544 struct lov_tgt_desc **newtgts, **old = NULL;
545 __u32 newsize, oldsize = 0;
547 newsize = max(lov->lov_tgt_size, (__u32)2);
548 while (newsize < index + 1)
549 newsize = newsize << 1;
550 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
551 if (newtgts == NULL) {
552 mutex_up(&lov->lov_lock);
556 if (lov->lov_tgt_size) {
557 memcpy(newtgts, lov->lov_tgts, sizeof(*newtgts) *
560 oldsize = lov->lov_tgt_size;
563 lov->lov_tgts = newtgts;
564 lov->lov_tgt_size = newsize;
569 OBD_FREE(old, sizeof(*old) * oldsize);
571 CDEBUG(D_CONFIG, "tgts: %p size: %d\n",
572 lov->lov_tgts, lov->lov_tgt_size);
577 mutex_up(&lov->lov_lock);
581 memset(tgt, 0, sizeof(*tgt));
582 tgt->ltd_uuid = *uuidp;
583 /* XXX - add a sanity check on the generation number. */
585 tgt->ltd_index = index;
586 tgt->ltd_activate = active;
587 lov->lov_tgts[index] = tgt;
588 if (index >= lov->desc.ld_tgt_count)
589 lov->desc.ld_tgt_count = index + 1;
591 rc = lov_ost_pool_add(&lov->lov_packed, index, lov->lov_tgt_size);
595 mutex_up(&lov->lov_lock);
597 CDEBUG(D_CONFIG, "idx=%d ltd_gen=%d ld_tgt_count=%d\n",
598 index, tgt->ltd_gen, lov->desc.ld_tgt_count);
600 if (lov->lov_connects == 0) {
601 /* lov_connect hasn't been called yet. We'll do the
602 lov_connect_obd on this target when that fn first runs,
603 because we don't know the connect flags yet. */
609 rc = lov_connect_obd(obd, index, active, &lov->lov_ocd);
613 /* connect to administrative disabled ost */
617 rc = lov_notify(obd, tgt->ltd_exp->exp_obd,
618 active ? OBD_NOTIFY_ACTIVE : OBD_NOTIFY_INACTIVE,
623 CERROR("add failed (%d), deleting %s\n", rc,
624 obd_uuid2str(&tgt->ltd_uuid));
625 lov_del_target(obd, index, 0, 0);
631 /* Schedule a target for deletion */
632 int lov_del_target(struct obd_device *obd, __u32 index,
633 struct obd_uuid *uuidp, int gen)
635 struct lov_obd *lov = &obd->u.lov;
636 int count = lov->desc.ld_tgt_count;
640 if (index >= count) {
641 CERROR("LOV target index %d >= number of LOV OBDs %d.\n",
648 if (!lov->lov_tgts[index]) {
649 CERROR("LOV target at index %d is not setup.\n", index);
650 GOTO(out, rc = -EINVAL);
653 if (uuidp && !obd_uuid_equals(uuidp, &lov->lov_tgts[index]->ltd_uuid)) {
654 CERROR("LOV target UUID %s at index %d doesn't match %s.\n",
655 lov_uuid2str(lov, index), index,
656 obd_uuid2str(uuidp));
657 GOTO(out, rc = -EINVAL);
660 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d exp: %p active: %d\n",
661 lov_uuid2str(lov, index), index,
662 lov->lov_tgts[index]->ltd_gen, lov->lov_tgts[index]->ltd_exp,
663 lov->lov_tgts[index]->ltd_active);
665 lov->lov_tgts[index]->ltd_reap = 1;
666 lov->lov_death_row++;
667 /* we really delete it from lov_putref */
674 /* We are holding lov_lock */
675 static void __lov_del_obd(struct obd_device *obd, __u32 index)
677 struct lov_obd *lov = &obd->u.lov;
678 struct obd_device *osc_obd;
679 struct lov_tgt_desc *tgt = lov->lov_tgts[index];
682 LASSERT(tgt->ltd_reap);
684 osc_obd = class_exp2obd(tgt->ltd_exp);
686 CDEBUG(D_CONFIG, "Removing tgt %s : %s\n",
687 lov_uuid2str(lov, index),
688 osc_obd ? osc_obd->obd_name : "<no obd>");
691 lov_disconnect_obd(obd, index);
693 /* XXX - right now there is a dependency on ld_tgt_count being the
694 * maximum tgt index for computing the mds_max_easize. So we can't
697 lov_ost_pool_remove(&lov->lov_packed, index);
698 lov->lov_tgts[index] = NULL;
701 /* Manual cleanup - no cleanup logs to clean up the osc's. We must
702 do it ourselves. And we can't do it from lov_cleanup,
703 because we just lost our only reference to it. */
705 class_manual_cleanup(osc_obd);
708 void lov_fix_desc_stripe_size(__u64 *val)
710 if (*val < PTLRPC_MAX_BRW_SIZE) {
711 LCONSOLE_WARN("Increasing default stripe size to min %u\n",
712 PTLRPC_MAX_BRW_SIZE);
713 *val = PTLRPC_MAX_BRW_SIZE;
714 } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) {
715 *val &= ~(LOV_MIN_STRIPE_SIZE - 1);
716 LCONSOLE_WARN("Changing default stripe size to "LPU64" (a "
718 *val, LOV_MIN_STRIPE_SIZE);
722 void lov_fix_desc_stripe_count(__u32 *val)
728 void lov_fix_desc_pattern(__u32 *val)
730 /* from lov_setstripe */
731 if ((*val != 0) && (*val != LOV_PATTERN_RAID0)) {
732 LCONSOLE_WARN("Unknown stripe pattern: %#x\n", *val);
737 void lov_fix_desc_qos_maxage(__u32 *val)
741 *val = QOS_DEFAULT_MAXAGE;
744 void lov_fix_desc(struct lov_desc *desc)
746 lov_fix_desc_stripe_size(&desc->ld_default_stripe_size);
747 lov_fix_desc_stripe_count(&desc->ld_default_stripe_count);
748 lov_fix_desc_pattern(&desc->ld_pattern);
749 lov_fix_desc_qos_maxage(&desc->ld_qos_maxage);
752 int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
754 struct lprocfs_static_vars lvars = { 0 };
755 struct lov_desc *desc;
756 struct lov_obd *lov = &obd->u.lov;
761 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
762 CERROR("LOV setup requires a descriptor\n");
766 desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
768 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
769 CERROR("descriptor size wrong: %d > %d\n",
770 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
774 if (desc->ld_magic != LOV_DESC_MAGIC) {
775 if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
776 CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n",
777 obd->obd_name, desc);
778 lustre_swab_lov_desc(desc);
780 CERROR("%s: Bad lov desc magic: %#x\n",
781 obd->obd_name, desc->ld_magic);
788 /* Because of 64-bit divide/mod operations only work with a 32-bit
789 * divisor in a 32-bit kernel, we cannot support a stripe width
790 * of 4GB or larger on 32-bit CPUs. */
791 count = desc->ld_default_stripe_count;
792 if ((count > 0 ? count : desc->ld_tgt_count) *
793 desc->ld_default_stripe_size > 0xffffffff) {
794 CERROR("LOV: stripe width "LPU64"x%u > 4294967295 bytes\n",
795 desc->ld_default_stripe_size, count);
799 desc->ld_active_tgt_count = 0;
801 lov->lov_tgt_size = 0;
803 sema_init(&lov->lov_lock, 1);
804 atomic_set(&lov->lov_refcount, 0);
805 CFS_INIT_LIST_HEAD(&lov->lov_qos.lq_oss_list);
806 init_rwsem(&lov->lov_qos.lq_rw_sem);
807 lov->lov_sp_me = LUSTRE_SP_CLI;
808 lov->lov_qos.lq_dirty = 1;
809 lov->lov_qos.lq_rr.lqr_dirty = 1;
810 lov->lov_qos.lq_reset = 1;
811 /* Default priority is toward free space balance */
812 lov->lov_qos.lq_prio_free = 232;
814 lov->lov_pools_hash_body = lustre_hash_init("POOLS", 7, 7,
815 &pool_hash_operations, 0);
816 CFS_INIT_LIST_HEAD(&lov->lov_pool_list);
817 lov->lov_pool_count = 0;
818 rc = lov_ost_pool_init(&lov->lov_packed, 0);
821 rc = lov_ost_pool_init(&lov->lov_qos.lq_rr.lqr_pool, 0);
823 lov_ost_pool_free(&lov->lov_packed);
827 lprocfs_lov_init_vars(&lvars);
828 lprocfs_obd_setup(obd, lvars.obd_vars);
833 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
834 0444, &lov_proc_target_fops, obd);
836 CWARN("Error adding the target_obd file\n");
839 lov->lov_pool_proc_entry = lprocfs_register("pools",
846 static int lov_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
852 case OBD_CLEANUP_EARLY: {
853 struct lov_obd *lov = &obd->u.lov;
855 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
856 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
858 obd_precleanup(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
863 case OBD_CLEANUP_EXPORTS:
864 rc = obd_llog_finish(obd, 0);
866 CERROR("failed to cleanup llogging subsystems\n");
872 static int lov_cleanup(struct obd_device *obd)
874 struct lov_obd *lov = &obd->u.lov;
875 struct list_head *pos, *tmp;
876 struct pool_desc *pool;
878 lprocfs_obd_cleanup(obd);
880 /* Delete hash entries and kill hash table before freeing pools
881 * and get to use after free issue. */
882 lustre_hash_exit(lov->lov_pools_hash_body);
884 list_for_each_safe(pos, tmp, &lov->lov_pool_list) {
885 pool = list_entry(pos, struct pool_desc, pool_list);
886 /* free pool structs */
887 lov_pool_del(obd, pool->pool_name);
889 lov_ost_pool_free(&(lov->lov_qos.lq_rr.lqr_pool));
890 lov_ost_pool_free(&lov->lov_packed);
894 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
895 if (!lov->lov_tgts[i])
898 /* Inactive targets may never have connected */
899 if (lov->lov_tgts[i]->ltd_active ||
900 atomic_read(&lov->lov_refcount))
901 /* We should never get here - these
902 should have been removed in the
904 CERROR("lov tgt %d not cleaned!"
905 " deathrow=%d, lovrc=%d\n",
906 i, lov->lov_death_row,
907 atomic_read(&lov->lov_refcount));
908 lov_del_target(obd, i, 0, 0);
910 OBD_FREE(lov->lov_tgts, sizeof(*lov->lov_tgts) *
912 lov->lov_tgt_size = 0;
918 int lov_process_config_base(struct obd_device *obd, struct lustre_cfg *lcfg,
919 __u32 *indexp, int *genp)
921 struct obd_uuid obd_uuid;
926 switch(cmd = lcfg->lcfg_command) {
927 case LCFG_LOV_ADD_OBD:
928 case LCFG_LOV_ADD_INA:
929 case LCFG_LOV_DEL_OBD: {
932 /* lov_modify_tgts add 0:lov_mdsA 1:ost1_UUID 2:0 3:1 */
933 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
934 GOTO(out, rc = -EINVAL);
936 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
938 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", indexp) != 1)
939 GOTO(out, rc = -EINVAL);
940 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", genp) != 1)
941 GOTO(out, rc = -EINVAL);
944 if (cmd == LCFG_LOV_ADD_OBD)
945 rc = lov_add_target(obd, &obd_uuid, index, gen, 1);
946 else if (cmd == LCFG_LOV_ADD_INA)
947 rc = lov_add_target(obd, &obd_uuid, index, gen, 0);
949 rc = lov_del_target(obd, index, &obd_uuid, gen);
953 struct lprocfs_static_vars lvars = { 0 };
954 struct lov_desc *desc = &(obd->u.lov.desc);
957 GOTO(out, rc = -EINVAL);
959 lprocfs_lov_init_vars(&lvars);
961 rc = class_process_proc_param(PARAM_LOV, lvars.obd_vars,
974 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
975 GOTO(out, rc = -EINVAL);
984 #define log2(n) ffz(~(n))
987 static int lov_clear_orphans(struct obd_export *export, struct obdo *src_oa,
988 struct lov_stripe_md **ea,
989 struct obd_trans_info *oti)
993 struct obd_uuid *ost_uuid = NULL;
997 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
998 src_oa->o_flags == OBD_FL_DELORPHAN);
1000 lov = &export->exp_obd->u.lov;
1006 if (oti->oti_ost_uuid) {
1007 ost_uuid = oti->oti_ost_uuid;
1008 CDEBUG(D_HA, "clearing orphans only for %s\n",
1012 lov_getref(export->exp_obd);
1013 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1014 struct lov_stripe_md obj_md;
1015 struct lov_stripe_md *obj_mdp = &obj_md;
1016 struct lov_tgt_desc *tgt;
1019 tgt = lov->lov_tgts[i];
1023 /* if called for a specific target, we don't
1024 care if it is not active. */
1025 if (!lov->lov_tgts[i]->ltd_active && ost_uuid == NULL) {
1026 CDEBUG(D_HA, "lov idx %d inactive\n", i);
1030 if (ost_uuid && !obd_uuid_equals(ost_uuid, &tgt->ltd_uuid))
1033 CDEBUG(D_CONFIG,"Clear orphans for %d:%s\n", i,
1034 obd_uuid2str(ost_uuid));
1036 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
1038 LASSERT(lov->lov_tgts[i]->ltd_exp);
1039 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1040 err = obd_create(lov->lov_tgts[i]->ltd_exp,
1041 tmp_oa, &obj_mdp, oti);
1043 /* This export will be disabled until it is recovered,
1044 and then orphan recovery will be completed. */
1045 CERROR("error in orphan recovery on OST idx %d/%d: "
1046 "rc = %d\n", i, lov->desc.ld_tgt_count, err);
1053 lov_putref(export->exp_obd);
1059 static int lov_recreate(struct obd_export *exp, struct obdo *src_oa,
1060 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1062 struct lov_stripe_md *obj_mdp, *lsm;
1063 struct lov_obd *lov = &exp->exp_obd->u.lov;
1068 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
1069 src_oa->o_flags & OBD_FL_RECREATE_OBJS);
1071 OBD_ALLOC(obj_mdp, sizeof(*obj_mdp));
1072 if (obj_mdp == NULL)
1075 ost_idx = src_oa->o_nlink;
1078 GOTO(out, rc = -EINVAL);
1079 if (ost_idx >= lov->desc.ld_tgt_count ||
1080 !lov->lov_tgts[ost_idx])
1081 GOTO(out, rc = -EINVAL);
1083 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1084 if (lsm->lsm_oinfo[i]->loi_ost_idx == ost_idx) {
1085 if (lsm->lsm_oinfo[i]->loi_id != src_oa->o_id)
1086 GOTO(out, rc = -EINVAL);
1090 if (i == lsm->lsm_stripe_count)
1091 GOTO(out, rc = -EINVAL);
1093 rc = obd_create(lov->lov_tgts[ost_idx]->ltd_exp, src_oa, &obj_mdp, oti);
1095 OBD_FREE(obj_mdp, sizeof(*obj_mdp));
1099 /* the LOV expects oa->o_id to be set to the LOV object id */
1100 static int lov_create(struct obd_export *exp, struct obdo *src_oa,
1101 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1103 struct lov_obd *lov;
1104 struct obd_info oinfo;
1105 struct lov_request_set *set = NULL;
1106 struct lov_request *req;
1107 struct obd_statfs osfs;
1112 LASSERT(ea != NULL);
1116 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1117 src_oa->o_flags == OBD_FL_DELORPHAN) {
1118 rc = lov_clear_orphans(exp, src_oa, ea, oti);
1122 lov = &exp->exp_obd->u.lov;
1123 if (!lov->desc.ld_active_tgt_count)
1126 lov_getref(exp->exp_obd);
1127 /* Recreate a specific object id at the given OST index */
1128 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1129 (src_oa->o_flags & OBD_FL_RECREATE_OBJS)) {
1130 rc = lov_recreate(exp, src_oa, ea, oti);
1134 maxage = cfs_time_shift_64(-lov->desc.ld_qos_maxage);
1135 obd_statfs_rqset(exp->exp_obd, &osfs, maxage, OBD_STATFS_NODELAY);
1137 rc = lov_prep_create_set(exp, &oinfo, ea, src_oa, oti, &set);
1141 list_for_each_entry(req, &set->set_list, rq_link) {
1142 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1143 rc = obd_create(lov->lov_tgts[req->rq_idx]->ltd_exp,
1144 req->rq_oi.oi_oa, &req->rq_oi.oi_md, oti);
1145 lov_update_create_set(set, req, rc);
1147 rc = lov_fini_create_set(set, ea);
1149 lov_putref(exp->exp_obd);
1153 #define ASSERT_LSM_MAGIC(lsmp) \
1155 LASSERT((lsmp) != NULL); \
1156 LASSERTF(((lsmp)->lsm_magic == LOV_MAGIC_V1 || \
1157 (lsmp)->lsm_magic == LOV_MAGIC_V3 || \
1158 (lsmp)->lsm_magic == LOV_MAGIC_JOIN), "%p->lsm_magic=%x\n", \
1159 (lsmp), (lsmp)->lsm_magic); \
1162 static int lov_destroy(struct obd_export *exp, struct obdo *oa,
1163 struct lov_stripe_md *lsm, struct obd_trans_info *oti,
1164 struct obd_export *md_exp, void *capa)
1166 struct lov_request_set *set;
1167 struct obd_info oinfo;
1168 struct lov_request *req;
1169 struct list_head *pos;
1170 struct lov_obd *lov;
1171 int rc = 0, err = 0;
1174 ASSERT_LSM_MAGIC(lsm);
1176 if (!exp || !exp->exp_obd)
1179 if (oa->o_valid & OBD_MD_FLCOOKIE) {
1181 LASSERT(oti->oti_logcookies);
1184 lov = &exp->exp_obd->u.lov;
1185 lov_getref(exp->exp_obd);
1186 rc = lov_prep_destroy_set(exp, &oinfo, oa, lsm, oti, &set);
1190 list_for_each (pos, &set->set_list) {
1191 req = list_entry(pos, struct lov_request, rq_link);
1193 if (oa->o_valid & OBD_MD_FLCOOKIE)
1194 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1196 err = obd_destroy(lov->lov_tgts[req->rq_idx]->ltd_exp,
1197 req->rq_oi.oi_oa, NULL, oti, NULL, capa);
1198 err = lov_update_common_set(set, req, err);
1200 CERROR("error: destroying objid "LPX64" subobj "
1201 LPX64" on OST idx %d: rc = %d\n",
1202 oa->o_id, req->rq_oi.oi_oa->o_id,
1210 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
1211 rc = lsm_op_find(lsm->lsm_magic)->lsm_destroy(lsm, oa, md_exp);
1213 err = lov_fini_destroy_set(set);
1215 lov_putref(exp->exp_obd);
1216 RETURN(rc ? rc : err);
1219 static int lov_getattr(struct obd_export *exp, struct obd_info *oinfo)
1221 struct lov_request_set *set;
1222 struct lov_request *req;
1223 struct list_head *pos;
1224 struct lov_obd *lov;
1225 int err = 0, rc = 0;
1229 ASSERT_LSM_MAGIC(oinfo->oi_md);
1231 if (!exp || !exp->exp_obd)
1234 lov = &exp->exp_obd->u.lov;
1236 rc = lov_prep_getattr_set(exp, oinfo, &set);
1240 list_for_each (pos, &set->set_list) {
1241 req = list_entry(pos, struct lov_request, rq_link);
1243 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1244 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1245 req->rq_oi.oi_oa->o_id, req->rq_idx);
1247 rc = obd_getattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1249 err = lov_update_common_set(set, req, rc);
1251 CERROR("error: getattr objid "LPX64" subobj "
1252 LPX64" on OST idx %d: rc = %d\n",
1253 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1259 rc = lov_fini_getattr_set(set);
1265 static int lov_getattr_interpret(struct ptlrpc_request_set *rqset,
1268 struct lov_request_set *lovset = (struct lov_request_set *)data;
1272 /* don't do attribute merge if this aysnc op failed */
1274 lovset->set_completes = 0;
1275 err = lov_fini_getattr_set(lovset);
1276 RETURN(rc ? rc : err);
1279 static int lov_getattr_async(struct obd_export *exp, struct obd_info *oinfo,
1280 struct ptlrpc_request_set *rqset)
1282 struct lov_request_set *lovset;
1283 struct lov_obd *lov;
1284 struct list_head *pos;
1285 struct lov_request *req;
1290 ASSERT_LSM_MAGIC(oinfo->oi_md);
1292 if (!exp || !exp->exp_obd)
1295 lov = &exp->exp_obd->u.lov;
1297 rc = lov_prep_getattr_set(exp, oinfo, &lovset);
1301 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1302 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1303 oinfo->oi_md->lsm_stripe_size);
1305 list_for_each (pos, &lovset->set_list) {
1306 req = list_entry(pos, struct lov_request, rq_link);
1308 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1309 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1310 req->rq_oi.oi_oa->o_id, req->rq_idx);
1311 rc = obd_getattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1312 &req->rq_oi, rqset);
1314 CERROR("error: getattr objid "LPX64" subobj "
1315 LPX64" on OST idx %d: rc = %d\n",
1316 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1322 if (!list_empty(&rqset->set_requests)) {
1324 LASSERT (rqset->set_interpret == NULL);
1325 rqset->set_interpret = lov_getattr_interpret;
1326 rqset->set_arg = (void *)lovset;
1331 lovset->set_completes = 0;
1332 err = lov_fini_getattr_set(lovset);
1333 RETURN(rc ? rc : err);
1336 static int lov_setattr(struct obd_export *exp, struct obd_info *oinfo,
1337 struct obd_trans_info *oti)
1339 struct lov_request_set *set;
1340 struct lov_obd *lov;
1341 struct list_head *pos;
1342 struct lov_request *req;
1343 int err = 0, rc = 0;
1347 ASSERT_LSM_MAGIC(oinfo->oi_md);
1349 if (!exp || !exp->exp_obd)
1352 /* for now, we only expect the following updates here */
1353 LASSERT(!(oinfo->oi_oa->o_valid & ~(OBD_MD_FLID | OBD_MD_FLTYPE |
1354 OBD_MD_FLMODE | OBD_MD_FLATIME |
1355 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1356 OBD_MD_FLFLAGS | OBD_MD_FLSIZE |
1357 OBD_MD_FLGROUP | OBD_MD_FLUID |
1358 OBD_MD_FLGID | OBD_MD_FLFID |
1360 lov = &exp->exp_obd->u.lov;
1361 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1365 list_for_each (pos, &set->set_list) {
1366 req = list_entry(pos, struct lov_request, rq_link);
1368 rc = obd_setattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1370 err = lov_update_setattr_set(set, req, rc);
1372 CERROR("error: setattr objid "LPX64" subobj "
1373 LPX64" on OST idx %d: rc = %d\n",
1374 set->set_oi->oi_oa->o_id,
1375 req->rq_oi.oi_oa->o_id, req->rq_idx, err);
1380 err = lov_fini_setattr_set(set);
1386 static int lov_setattr_interpret(struct ptlrpc_request_set *rqset,
1389 struct lov_request_set *lovset = (struct lov_request_set *)data;
1394 lovset->set_completes = 0;
1395 err = lov_fini_setattr_set(lovset);
1396 RETURN(rc ? rc : err);
1399 /* If @oti is given, the request goes from MDS and responses from OSTs are not
1400 needed. Otherwise, a client is waiting for responses. */
1401 static int lov_setattr_async(struct obd_export *exp, struct obd_info *oinfo,
1402 struct obd_trans_info *oti,
1403 struct ptlrpc_request_set *rqset)
1405 struct lov_request_set *set;
1406 struct lov_request *req;
1407 struct list_head *pos;
1408 struct lov_obd *lov;
1413 ASSERT_LSM_MAGIC(oinfo->oi_md);
1414 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE) {
1416 LASSERT(oti->oti_logcookies);
1419 if (!exp || !exp->exp_obd)
1422 lov = &exp->exp_obd->u.lov;
1423 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1427 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1428 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1429 oinfo->oi_md->lsm_stripe_size);
1431 list_for_each (pos, &set->set_list) {
1432 req = list_entry(pos, struct lov_request, rq_link);
1434 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
1435 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1437 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1438 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1439 req->rq_oi.oi_oa->o_id, req->rq_idx);
1441 rc = obd_setattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1442 &req->rq_oi, oti, rqset);
1444 CERROR("error: setattr objid "LPX64" subobj "
1445 LPX64" on OST idx %d: rc = %d\n",
1446 set->set_oi->oi_oa->o_id,
1447 req->rq_oi.oi_oa->o_id,
1453 /* If we are not waiting for responses on async requests, return. */
1454 if (rc || !rqset || list_empty(&rqset->set_requests)) {
1457 set->set_completes = 0;
1458 err = lov_fini_setattr_set(set);
1459 RETURN(rc ? rc : err);
1462 LASSERT(rqset->set_interpret == NULL);
1463 rqset->set_interpret = lov_setattr_interpret;
1464 rqset->set_arg = (void *)set;
1469 static int lov_punch_interpret(struct ptlrpc_request_set *rqset,
1472 struct lov_request_set *lovset = (struct lov_request_set *)data;
1477 lovset->set_completes = 0;
1478 err = lov_fini_punch_set(lovset);
1479 RETURN(rc ? rc : err);
1482 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
1483 * we can send this 'punch' to just the authoritative node and the nodes
1484 * that the punch will affect. */
1485 static int lov_punch(struct obd_export *exp, struct obd_info *oinfo,
1486 struct obd_trans_info *oti,
1487 struct ptlrpc_request_set *rqset)
1489 struct lov_request_set *set;
1490 struct lov_obd *lov;
1491 struct list_head *pos;
1492 struct lov_request *req;
1497 ASSERT_LSM_MAGIC(oinfo->oi_md);
1499 if (!exp || !exp->exp_obd)
1502 lov = &exp->exp_obd->u.lov;
1503 rc = lov_prep_punch_set(exp, oinfo, oti, &set);
1507 list_for_each (pos, &set->set_list) {
1508 req = list_entry(pos, struct lov_request, rq_link);
1510 rc = obd_punch(lov->lov_tgts[req->rq_idx]->ltd_exp,
1511 &req->rq_oi, NULL, rqset);
1513 CERROR("error: punch objid "LPX64" subobj "LPX64
1514 " on OST idx %d: rc = %d\n",
1515 set->set_oi->oi_oa->o_id,
1516 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1521 if (rc || list_empty(&rqset->set_requests)) {
1523 err = lov_fini_punch_set(set);
1524 RETURN(rc ? rc : err);
1527 LASSERT(rqset->set_interpret == NULL);
1528 rqset->set_interpret = lov_punch_interpret;
1529 rqset->set_arg = (void *)set;
1534 static int lov_sync(struct obd_export *exp, struct obdo *oa,
1535 struct lov_stripe_md *lsm, obd_off start, obd_off end,
1538 struct lov_request_set *set;
1539 struct obd_info oinfo;
1540 struct lov_obd *lov;
1541 struct list_head *pos;
1542 struct lov_request *req;
1543 int err = 0, rc = 0;
1546 ASSERT_LSM_MAGIC(lsm);
1551 lov = &exp->exp_obd->u.lov;
1552 rc = lov_prep_sync_set(exp, &oinfo, oa, lsm, start, end, &set);
1556 list_for_each (pos, &set->set_list) {
1557 req = list_entry(pos, struct lov_request, rq_link);
1559 rc = obd_sync(lov->lov_tgts[req->rq_idx]->ltd_exp,
1560 req->rq_oi.oi_oa, NULL,
1561 req->rq_oi.oi_policy.l_extent.start,
1562 req->rq_oi.oi_policy.l_extent.end, capa);
1563 err = lov_update_common_set(set, req, rc);
1565 CERROR("error: fsync objid "LPX64" subobj "LPX64
1566 " on OST idx %d: rc = %d\n",
1567 set->set_oi->oi_oa->o_id,
1568 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1573 err = lov_fini_sync_set(set);
1579 static int lov_brw_check(struct lov_obd *lov, struct obd_info *lov_oinfo,
1580 obd_count oa_bufs, struct brw_page *pga)
1582 struct obd_info oinfo = { { { 0 } } };
1585 oinfo.oi_oa = lov_oinfo->oi_oa;
1587 /* The caller just wants to know if there's a chance that this
1588 * I/O can succeed */
1589 for (i = 0; i < oa_bufs; i++) {
1590 int stripe = lov_stripe_number(lov_oinfo->oi_md, pga[i].off);
1591 int ost = lov_oinfo->oi_md->lsm_oinfo[stripe]->loi_ost_idx;
1594 if (!lov_stripe_intersects(lov_oinfo->oi_md, i, pga[i].off,
1595 pga[i].off + pga[i].count - 1,
1599 if (!lov->lov_tgts[ost] || !lov->lov_tgts[ost]->ltd_active) {
1600 CDEBUG(D_HA, "lov idx %d inactive\n", ost);
1604 rc = obd_brw(OBD_BRW_CHECK, lov->lov_tgts[ost]->ltd_exp, &oinfo,
1612 static int lov_brw(int cmd, struct obd_export *exp, struct obd_info *oinfo,
1613 obd_count oa_bufs, struct brw_page *pga,
1614 struct obd_trans_info *oti)
1616 struct lov_request_set *set;
1617 struct lov_request *req;
1618 struct list_head *pos;
1619 struct lov_obd *lov = &exp->exp_obd->u.lov;
1623 ASSERT_LSM_MAGIC(oinfo->oi_md);
1625 if (cmd == OBD_BRW_CHECK) {
1626 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1630 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &set);
1634 list_for_each (pos, &set->set_list) {
1635 struct obd_export *sub_exp;
1636 struct brw_page *sub_pga;
1637 req = list_entry(pos, struct lov_request, rq_link);
1639 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1640 sub_pga = set->set_pga + req->rq_pgaidx;
1641 rc = obd_brw(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1645 lov_update_common_set(set, req, rc);
1648 err = lov_fini_brw_set(set);
1654 static int lov_enqueue_interpret(struct ptlrpc_request_set *rqset,
1657 struct lov_request_set *lovset = (struct lov_request_set *)data;
1659 rc = lov_fini_enqueue_set(lovset, lovset->set_ei->ei_mode, rc, rqset);
1663 static int lov_enqueue(struct obd_export *exp, struct obd_info *oinfo,
1664 struct ldlm_enqueue_info *einfo,
1665 struct ptlrpc_request_set *rqset)
1667 ldlm_mode_t mode = einfo->ei_mode;
1668 struct lov_request_set *set;
1669 struct lov_request *req;
1670 struct list_head *pos;
1671 struct lov_obd *lov;
1676 ASSERT_LSM_MAGIC(oinfo->oi_md);
1677 LASSERT(mode == (mode & -mode));
1679 /* we should never be asked to replay a lock this way. */
1680 LASSERT((oinfo->oi_flags & LDLM_FL_REPLAY) == 0);
1682 if (!exp || !exp->exp_obd)
1685 lov = &exp->exp_obd->u.lov;
1686 rc = lov_prep_enqueue_set(exp, oinfo, einfo, &set);
1690 list_for_each (pos, &set->set_list) {
1691 req = list_entry(pos, struct lov_request, rq_link);
1693 rc = obd_enqueue(lov->lov_tgts[req->rq_idx]->ltd_exp,
1694 &req->rq_oi, einfo, rqset);
1699 if (rqset && !list_empty(&rqset->set_requests)) {
1701 LASSERT(rqset->set_interpret == NULL);
1702 rqset->set_interpret = lov_enqueue_interpret;
1703 rqset->set_arg = (void *)set;
1707 rc = lov_fini_enqueue_set(set, mode, rc, rqset);
1711 static int lov_change_cbdata(struct obd_export *exp,
1712 struct lov_stripe_md *lsm, ldlm_iterator_t it,
1715 struct lov_obd *lov;
1719 ASSERT_LSM_MAGIC(lsm);
1721 if (!exp || !exp->exp_obd)
1724 LASSERT_MDS_GROUP(lsm->lsm_object_gr);
1726 lov = &exp->exp_obd->u.lov;
1727 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1728 struct lov_stripe_md submd;
1729 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
1731 if (!lov->lov_tgts[loi->loi_ost_idx]) {
1732 CDEBUG(D_HA, "lov idx %d NULL \n", loi->loi_ost_idx);
1736 submd.lsm_object_id = loi->loi_id;
1737 submd.lsm_object_gr = lsm->lsm_object_gr;
1738 submd.lsm_stripe_count = 0;
1739 rc = obd_change_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1745 static int lov_cancel(struct obd_export *exp, struct lov_stripe_md *lsm,
1746 __u32 mode, struct lustre_handle *lockh)
1748 struct lov_request_set *set;
1749 struct obd_info oinfo;
1750 struct lov_request *req;
1751 struct list_head *pos;
1752 struct lov_obd *lov = &exp->exp_obd->u.lov;
1753 struct lustre_handle *lov_lockhp;
1754 int err = 0, rc = 0;
1757 ASSERT_LSM_MAGIC(lsm);
1759 if (!exp || !exp->exp_obd)
1762 LASSERT_MDS_GROUP(lsm->lsm_object_gr);
1764 lov = &exp->exp_obd->u.lov;
1765 rc = lov_prep_cancel_set(exp, &oinfo, lsm, mode, lockh, &set);
1769 list_for_each (pos, &set->set_list) {
1770 req = list_entry(pos, struct lov_request, rq_link);
1771 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
1773 rc = obd_cancel(lov->lov_tgts[req->rq_idx]->ltd_exp,
1774 req->rq_oi.oi_md, mode, lov_lockhp);
1775 rc = lov_update_common_set(set, req, rc);
1777 CERROR("error: cancel objid "LPX64" subobj "
1778 LPX64" on OST idx %d: rc = %d\n",
1780 req->rq_oi.oi_md->lsm_object_id,
1786 lov_fini_cancel_set(set);
1790 static int lov_cancel_unused(struct obd_export *exp,
1791 struct lov_stripe_md *lsm,
1792 int flags, void *opaque)
1794 struct lov_obd *lov;
1798 if (!exp || !exp->exp_obd)
1801 lov = &exp->exp_obd->u.lov;
1803 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1805 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
1808 err = obd_cancel_unused(lov->lov_tgts[i]->ltd_exp, NULL,
1816 ASSERT_LSM_MAGIC(lsm);
1818 LASSERT_MDS_GROUP(lsm->lsm_object_gr);
1819 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1820 struct lov_stripe_md submd;
1821 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
1824 if (!lov->lov_tgts[loi->loi_ost_idx]) {
1825 CDEBUG(D_HA, "lov idx %d NULL\n", loi->loi_ost_idx);
1829 if (!lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
1830 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1832 submd.lsm_object_id = loi->loi_id;
1833 submd.lsm_object_gr = lsm->lsm_object_gr;
1834 submd.lsm_stripe_count = 0;
1835 err = obd_cancel_unused(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1836 &submd, flags, opaque);
1837 if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1838 CERROR("error: cancel unused objid "LPX64" subobj "LPX64
1839 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
1840 loi->loi_id, loi->loi_ost_idx, err);
1848 static int lov_statfs_interpret(struct ptlrpc_request_set *rqset,
1851 struct lov_request_set *lovset = (struct lov_request_set *)data;
1856 lovset->set_completes = 0;
1858 err = lov_fini_statfs_set(lovset);
1859 RETURN(rc ? rc : err);
1862 static int lov_statfs_async(struct obd_device *obd, struct obd_info *oinfo,
1863 __u64 max_age, struct ptlrpc_request_set *rqset)
1865 struct lov_request_set *set;
1866 struct lov_request *req;
1867 struct list_head *pos;
1868 struct lov_obd *lov;
1872 LASSERT(oinfo != NULL);
1873 LASSERT(oinfo->oi_osfs != NULL);
1876 rc = lov_prep_statfs_set(obd, oinfo, &set);
1880 list_for_each (pos, &set->set_list) {
1881 struct obd_device *osc_obd;
1883 req = list_entry(pos, struct lov_request, rq_link);
1885 osc_obd = class_exp2obd(lov->lov_tgts[req->rq_idx]->ltd_exp);
1886 rc = obd_statfs_async(osc_obd, &req->rq_oi, max_age, rqset);
1891 if (rc || list_empty(&rqset->set_requests)) {
1894 set->set_completes = 0;
1895 err = lov_fini_statfs_set(set);
1896 RETURN(rc ? rc : err);
1899 LASSERT(rqset->set_interpret == NULL);
1900 rqset->set_interpret = lov_statfs_interpret;
1901 rqset->set_arg = (void *)set;
1905 static int lov_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1906 __u64 max_age, __u32 flags)
1908 struct ptlrpc_request_set *set = NULL;
1909 struct obd_info oinfo = { { { 0 } } };
1914 /* for obdclass we forbid using obd_statfs_rqset, but prefer using async
1915 * statfs requests */
1916 set = ptlrpc_prep_set();
1920 oinfo.oi_osfs = osfs;
1921 oinfo.oi_flags = flags;
1922 rc = lov_statfs_async(obd, &oinfo, max_age, set);
1924 rc = ptlrpc_set_wait(set);
1925 ptlrpc_set_destroy(set);
1930 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1931 void *karg, void *uarg)
1933 struct obd_device *obddev = class_exp2obd(exp);
1934 struct lov_obd *lov = &obddev->u.lov;
1935 int i = 0, rc = 0, count = lov->desc.ld_tgt_count;
1936 struct obd_uuid *uuidp;
1940 case IOC_OBD_STATFS: {
1941 struct obd_ioctl_data *data = karg;
1942 struct obd_device *osc_obd;
1943 struct obd_statfs stat_buf = {0};
1946 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
1947 LASSERT(data->ioc_plen1 == sizeof(struct obd_statfs));
1949 if ((index >= count))
1952 if (!lov->lov_tgts[index])
1953 /* Try again with the next index */
1955 if (!lov->lov_tgts[index]->ltd_active)
1958 osc_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
1962 /* got statfs data */
1963 rc = obd_statfs(osc_obd, &stat_buf,
1964 cfs_time_current_64() - HZ, 0);
1967 if (copy_to_user(data->ioc_pbuf1, &stat_buf, data->ioc_plen1))
1970 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(osc_obd),
1975 case OBD_IOC_LOV_GET_CONFIG: {
1976 struct obd_ioctl_data *data;
1977 struct lov_desc *desc;
1982 if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
1985 data = (struct obd_ioctl_data *)buf;
1987 if (sizeof(*desc) > data->ioc_inllen1) {
1988 obd_ioctl_freedata(buf, len);
1992 if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
1993 obd_ioctl_freedata(buf, len);
1997 if (sizeof(__u32) * count > data->ioc_inllen3) {
1998 obd_ioctl_freedata(buf, len);
2002 desc = (struct lov_desc *)data->ioc_inlbuf1;
2003 memcpy(desc, &(lov->desc), sizeof(*desc));
2005 uuidp = (struct obd_uuid *)data->ioc_inlbuf2;
2006 genp = (__u32 *)data->ioc_inlbuf3;
2007 /* the uuid will be empty for deleted OSTs */
2008 for (i = 0; i < count; i++, uuidp++, genp++) {
2009 if (!lov->lov_tgts[i])
2011 *uuidp = lov->lov_tgts[i]->ltd_uuid;
2012 *genp = lov->lov_tgts[i]->ltd_gen;
2015 if (copy_to_user((void *)uarg, buf, len))
2017 obd_ioctl_freedata(buf, len);
2020 case LL_IOC_LOV_SETSTRIPE:
2021 rc = lov_setstripe(exp, karg, uarg);
2023 case LL_IOC_LOV_GETSTRIPE:
2024 rc = lov_getstripe(exp, karg, uarg);
2026 case LL_IOC_LOV_SETEA:
2027 rc = lov_setea(exp, karg, uarg);
2029 case OBD_IOC_QUOTACTL: {
2030 struct if_quotactl *qctl = karg;
2031 struct lov_tgt_desc *tgt = NULL;
2032 struct obd_quotactl *oqctl;
2034 if (qctl->qc_valid == QC_OSTIDX) {
2035 if (qctl->qc_idx < 0 || count <= qctl->qc_idx)
2038 tgt = lov->lov_tgts[qctl->qc_idx];
2039 if (!tgt || !tgt->ltd_exp)
2041 } else if (qctl->qc_valid == QC_UUID) {
2042 for (i = 0; i < count; i++) {
2043 tgt = lov->lov_tgts[i];
2045 !obd_uuid_equals(&tgt->ltd_uuid,
2049 if (tgt->ltd_exp == NULL)
2061 LASSERT(tgt && tgt->ltd_exp);
2062 OBD_ALLOC_PTR(oqctl);
2066 QCTL_COPY(oqctl, qctl);
2067 rc = obd_quotactl(tgt->ltd_exp, oqctl);
2069 QCTL_COPY(qctl, oqctl);
2070 qctl->qc_valid = QC_OSTIDX;
2071 qctl->obd_uuid = tgt->ltd_uuid;
2073 OBD_FREE_PTR(oqctl);
2082 for (i = 0; i < count; i++) {
2085 /* OST was disconnected */
2086 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2089 err = obd_iocontrol(cmd, lov->lov_tgts[i]->ltd_exp,
2091 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
2094 if (lov->lov_tgts[i]->ltd_active) {
2095 CDEBUG(err == -ENOTTY ?
2096 D_IOCTL : D_WARNING,
2097 "iocontrol OSC %s on OST "
2098 "idx %d cmd %x: err = %d\n",
2099 lov_uuid2str(lov, i),
2116 #define FIEMAP_BUFFER_SIZE 4096
2119 * Non-zero fe_logical indicates that this is a continuation FIEMAP
2120 * call. The local end offset and the device are sent in the first
2121 * fm_extent. This function calculates the stripe number from the index.
2122 * This function returns a stripe_no on which mapping is to be restarted.
2124 * This function returns fm_end_offset which is the in-OST offset at which
2125 * mapping should be restarted. If fm_end_offset=0 is returned then caller
2126 * will re-calculate proper offset in next stripe.
2127 * Note that the first extent is passed to lov_get_info via the value field.
2129 * \param fiemap fiemap request header
2130 * \param lsm striping information for the file
2131 * \param fm_start logical start of mapping
2132 * \param fm_end logical end of mapping
2133 * \param start_stripe starting stripe will be returned in this
2135 obd_size fiemap_calc_fm_end_offset(struct ll_user_fiemap *fiemap,
2136 struct lov_stripe_md *lsm, obd_size fm_start,
2137 obd_size fm_end, int *start_stripe)
2139 obd_size local_end = fiemap->fm_extents[0].fe_logical;
2140 obd_off lun_start, lun_end;
2141 obd_size fm_end_offset;
2142 int stripe_no = -1, i;
2144 if (fiemap->fm_extent_count == 0 ||
2145 fiemap->fm_extents[0].fe_logical == 0)
2148 /* Find out stripe_no from ost_index saved in the fe_device */
2149 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2150 if (lsm->lsm_oinfo[i]->loi_ost_idx ==
2151 fiemap->fm_extents[0].fe_device) {
2157 /* If we have finished mapping on previous device, shift logical
2158 * offset to start of next device */
2159 if ((lov_stripe_intersects(lsm, stripe_no, fm_start, fm_end,
2160 &lun_start, &lun_end)) != 0 &&
2161 local_end < lun_end) {
2162 fm_end_offset = local_end;
2163 *start_stripe = stripe_no;
2165 /* This is a special value to indicate that caller should
2166 * calculate offset in next stripe. */
2168 *start_stripe = (stripe_no + 1) % lsm->lsm_stripe_count;
2171 return fm_end_offset;
2175 * We calculate on which OST the mapping will end. If the length of mapping
2176 * is greater than (stripe_size * stripe_count) then the last_stripe will
2177 * will be one just before start_stripe. Else we check if the mapping
2178 * intersects each OST and find last_stripe.
2179 * This function returns the last_stripe and also sets the stripe_count
2180 * over which the mapping is spread
2182 * \param lsm striping information for the file
2183 * \param fm_start logical start of mapping
2184 * \param fm_end logical end of mapping
2185 * \param start_stripe starting stripe of the mapping
2186 * \param stripe_count the number of stripes across which to map is returned
2188 * \retval last_stripe return the last stripe of the mapping
2190 int fiemap_calc_last_stripe(struct lov_stripe_md *lsm, obd_size fm_start,
2191 obd_size fm_end, int start_stripe,
2195 obd_off obd_start, obd_end;
2198 if (fm_end - fm_start > lsm->lsm_stripe_size * lsm->lsm_stripe_count) {
2199 last_stripe = (start_stripe < 1 ? lsm->lsm_stripe_count - 1 :
2201 *stripe_count = lsm->lsm_stripe_count;
2203 for (j = 0, i = start_stripe; j < lsm->lsm_stripe_count;
2204 i = (i + 1) % lsm->lsm_stripe_count, j++) {
2205 if ((lov_stripe_intersects(lsm, i, fm_start, fm_end,
2206 &obd_start, &obd_end)) == 0)
2210 last_stripe = (start_stripe + j - 1) %lsm->lsm_stripe_count;
2217 * Set fe_device and copy extents from local buffer into main return buffer.
2219 * \param fiemap fiemap request header
2220 * \param lcl_fm_ext array of local fiemap extents to be copied
2221 * \param ost_index OST index to be written into the fm_device field for each
2223 * \param ext_count number of extents to be copied
2224 * \param current_extent where to start copying in main extent array
2226 void fiemap_prepare_and_copy_exts(struct ll_user_fiemap *fiemap,
2227 struct ll_fiemap_extent *lcl_fm_ext,
2228 int ost_index, unsigned int ext_count,
2234 for (ext = 0; ext < ext_count; ext++) {
2235 lcl_fm_ext[ext].fe_device = ost_index;
2236 lcl_fm_ext[ext].fe_flags |= FIEMAP_EXTENT_NET;
2239 /* Copy fm_extent's from fm_local to return buffer */
2240 to = (char *)fiemap + fiemap_count_to_size(current_extent);
2241 memcpy(to, lcl_fm_ext, ext_count * sizeof(struct ll_fiemap_extent));
2245 * Break down the FIEMAP request and send appropriate calls to individual OSTs.
2246 * This also handles the restarting of FIEMAP calls in case mapping overflows
2247 * the available number of extents in single call.
2249 static int lov_fiemap(struct lov_obd *lov, __u32 keylen, void *key,
2250 __u32 *vallen, void *val, struct lov_stripe_md *lsm)
2252 struct ll_fiemap_info_key *fm_key = key;
2253 struct ll_user_fiemap *fiemap = val;
2254 struct ll_user_fiemap *fm_local = NULL;
2255 struct ll_fiemap_extent *lcl_fm_ext;
2257 unsigned int get_num_extents = 0;
2258 int ost_index = 0, actual_start_stripe, start_stripe;
2259 obd_size fm_start, fm_end, fm_length, fm_end_offset = 0;
2261 int current_extent = 0, rc = 0, i;
2262 int ost_eof = 0; /* EOF for object */
2263 int ost_done = 0; /* done with required mapping for this OST? */
2265 int cur_stripe = 0, cur_stripe_wrap = 0, stripe_count;
2266 unsigned int buffer_size = FIEMAP_BUFFER_SIZE;
2271 if (fiemap_count_to_size(fm_key->fiemap.fm_extent_count) < buffer_size)
2272 buffer_size = fiemap_count_to_size(fm_key->fiemap.fm_extent_count);
2274 OBD_ALLOC(fm_local, buffer_size);
2275 if (fm_local == NULL)
2276 GOTO(out, rc = -ENOMEM);
2277 lcl_fm_ext = &fm_local->fm_extents[0];
2279 count_local = fiemap_size_to_count(buffer_size);
2281 memcpy(fiemap, &fm_key->fiemap, sizeof(*fiemap));
2282 fm_start = fiemap->fm_start;
2283 fm_length = fiemap->fm_length;
2284 /* Calculate start stripe, last stripe and length of mapping */
2285 actual_start_stripe = start_stripe = lov_stripe_number(lsm, fm_start);
2286 fm_end = (fm_length == ~0ULL ? fm_key->oa.o_size :
2287 fm_start + fm_length - 1);
2288 /* If fm_length != ~0ULL but fm_start+fm_length-1 exceeds file size */
2289 if (fm_end > fm_key->oa.o_size)
2290 fm_end = fm_key->oa.o_size;
2292 last_stripe = fiemap_calc_last_stripe(lsm, fm_start, fm_end,
2293 actual_start_stripe, &stripe_count);
2295 fm_end_offset = fiemap_calc_fm_end_offset(fiemap, lsm, fm_start, fm_end,
2298 if (fiemap->fm_extent_count == 0) {
2299 get_num_extents = 1;
2303 /* Check each stripe */
2304 for (cur_stripe = start_stripe, i = 0; i < stripe_count;
2305 i++, cur_stripe = (cur_stripe + 1) % lsm->lsm_stripe_count) {
2306 obd_size req_fm_len; /* Stores length of required mapping */
2307 obd_size len_mapped_single_call;
2308 obd_off lun_start, lun_end, obd_object_end;
2309 unsigned int ext_count;
2311 cur_stripe_wrap = cur_stripe;
2313 /* Find out range of mapping on this stripe */
2314 if ((lov_stripe_intersects(lsm, cur_stripe, fm_start, fm_end,
2315 &lun_start, &obd_object_end)) == 0)
2318 /* If this is a continuation FIEMAP call and we are on
2319 * starting stripe then lun_start needs to be set to
2321 if (fm_end_offset != 0 && cur_stripe == start_stripe)
2322 lun_start = fm_end_offset;
2324 if (fm_length != ~0ULL) {
2325 /* Handle fm_start + fm_length overflow */
2326 if (fm_start + fm_length < fm_start)
2327 fm_length = ~0ULL - fm_start;
2328 lun_end = lov_size_to_stripe(lsm, fm_start + fm_length,
2334 if (lun_start == lun_end)
2337 req_fm_len = obd_object_end - lun_start;
2338 fm_local->fm_length = 0;
2339 len_mapped_single_call = 0;
2341 /* If the output buffer is very large and the objects have many
2342 * extents we may need to loop on a single OST repeatedly */
2346 if (get_num_extents == 0) {
2347 /* Don't get too many extents. */
2348 if (current_extent + count_local >
2349 fiemap->fm_extent_count)
2350 count_local = fiemap->fm_extent_count -
2354 lun_start += len_mapped_single_call;
2355 fm_local->fm_length = req_fm_len - len_mapped_single_call;
2356 req_fm_len = fm_local->fm_length;
2357 fm_local->fm_extent_count = count_local;
2358 fm_local->fm_mapped_extents = 0;
2359 fm_local->fm_flags = fiemap->fm_flags;
2361 fm_key->oa.o_id = lsm->lsm_oinfo[cur_stripe]->loi_id;
2362 ost_index = lsm->lsm_oinfo[cur_stripe]->loi_ost_idx;
2364 if (ost_index < 0 || ost_index >=lov->desc.ld_tgt_count)
2365 GOTO(out, rc = -EINVAL);
2367 /* If OST is inactive, return extent with UNKNOWN flag */
2368 if (lov && !lov->lov_tgts[ost_index]->ltd_active) {
2369 fm_local->fm_flags |= FIEMAP_EXTENT_LAST;
2370 fm_local->fm_mapped_extents = 1;
2372 lcl_fm_ext[0].fe_logical = lun_start;
2373 lcl_fm_ext[0].fe_length = obd_object_end -
2375 lcl_fm_ext[0].fe_flags |= FIEMAP_EXTENT_UNKNOWN;
2380 fm_local->fm_start = lun_start;
2381 fm_local->fm_flags &= ~FIEMAP_FLAG_DEVICE_ORDER;
2382 memcpy(&fm_key->fiemap, fm_local, sizeof(*fm_local));
2383 *vallen=fiemap_count_to_size(fm_local->fm_extent_count);
2384 rc = obd_get_info(lov->lov_tgts[ost_index]->ltd_exp,
2385 keylen, key, vallen, fm_local, lsm);
2390 ext_count = fm_local->fm_mapped_extents;
2391 if (ext_count == 0) {
2393 /* If last stripe has hole at the end,
2394 * then we need to return */
2395 if (cur_stripe_wrap == last_stripe) {
2396 fiemap->fm_mapped_extents = 0;
2402 /* If we just need num of extents then go to next device */
2403 if (get_num_extents) {
2404 current_extent += ext_count;
2408 len_mapped_single_call = lcl_fm_ext[ext_count-1].fe_logical -
2409 lun_start + lcl_fm_ext[ext_count - 1].fe_length;
2411 /* Have we finished mapping on this device? */
2412 if (req_fm_len <= len_mapped_single_call)
2415 /* Clear the EXTENT_LAST flag which can be present on
2417 if (lcl_fm_ext[ext_count-1].fe_flags & FIEMAP_EXTENT_LAST)
2418 lcl_fm_ext[ext_count - 1].fe_flags &=
2419 ~FIEMAP_EXTENT_LAST;
2421 curr_loc = lov_stripe_size(lsm,
2422 lcl_fm_ext[ext_count - 1].fe_logical+
2423 lcl_fm_ext[ext_count - 1].fe_length,
2425 if (curr_loc >= fm_key->oa.o_size)
2428 fiemap_prepare_and_copy_exts(fiemap, lcl_fm_ext,
2429 ost_index, ext_count,
2432 current_extent += ext_count;
2434 /* Ran out of available extents? */
2435 if (current_extent >= fiemap->fm_extent_count)
2437 } while (ost_done == 0 && ost_eof == 0);
2439 if (cur_stripe_wrap == last_stripe)
2444 /* Indicate that we are returning device offsets unless file just has
2446 if (lsm->lsm_stripe_count > 1)
2447 fiemap->fm_flags |= FIEMAP_FLAG_DEVICE_ORDER;
2449 if (get_num_extents)
2450 goto skip_last_device_calc;
2452 /* Check if we have reached the last stripe and whether mapping for that
2453 * stripe is done. */
2454 if (cur_stripe_wrap == last_stripe) {
2455 if (ost_done || ost_eof)
2456 fiemap->fm_extents[current_extent - 1].fe_flags |=
2460 skip_last_device_calc:
2461 fiemap->fm_mapped_extents = current_extent;
2464 OBD_FREE(fm_local, buffer_size);
2468 static int lov_get_info(struct obd_export *exp, __u32 keylen,
2469 void *key, __u32 *vallen, void *val,
2470 struct lov_stripe_md *lsm)
2472 struct obd_device *obddev = class_exp2obd(exp);
2473 struct lov_obd *lov = &obddev->u.lov;
2477 if (!vallen || !val)
2482 if (KEY_IS(KEY_LOCK_TO_STRIPE)) {
2485 struct ldlm_lock *lock;
2487 struct ldlm_res_id *res_id = &data->lock->l_resource->lr_name;
2488 struct lov_oinfo *loi;
2489 __u32 *stripe = val;
2491 if (*vallen < sizeof(*stripe))
2492 GOTO(out, rc = -EFAULT);
2493 *vallen = sizeof(*stripe);
2495 /* XXX This is another one of those bits that will need to
2496 * change if we ever actually support nested LOVs. It uses
2497 * the lock's export to find out which stripe it is. */
2498 /* XXX - it's assumed all the locks for deleted OSTs have
2499 * been cancelled. Also, the export for deleted OSTs will
2500 * be NULL and won't match the lock's export. */
2501 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2502 loi = lsm->lsm_oinfo[i];
2503 if (!lov->lov_tgts[loi->loi_ost_idx])
2505 if (lov->lov_tgts[loi->loi_ost_idx]->ltd_exp ==
2506 data->lock->l_conn_export &&
2507 osc_res_name_eq(loi->loi_id, loi->loi_gr, res_id)) {
2512 LDLM_ERROR(data->lock, "lock on inode without such object");
2513 dump_lsm(D_ERROR, lsm);
2514 GOTO(out, rc = -ENXIO);
2515 } else if (KEY_IS(KEY_LAST_ID)) {
2516 struct obd_id_info *info = val;
2517 __u32 size = sizeof(obd_id);
2518 struct lov_tgt_desc *tgt;
2520 LASSERT(*vallen == sizeof(struct obd_id_info));
2521 tgt = lov->lov_tgts[info->idx];
2523 if (!tgt || !tgt->ltd_active)
2524 GOTO(out, rc = -ESRCH);
2526 rc = obd_get_info(tgt->ltd_exp, keylen, key, &size, info->data, NULL);
2528 } else if (KEY_IS(KEY_LOVDESC)) {
2529 struct lov_desc *desc_ret = val;
2530 *desc_ret = lov->desc;
2533 } else if (KEY_IS(KEY_FIEMAP)) {
2534 rc = lov_fiemap(lov, keylen, key, vallen, val, lsm);
2545 static int lov_set_info_async(struct obd_export *exp, obd_count keylen,
2546 void *key, obd_count vallen, void *val,
2547 struct ptlrpc_request_set *set)
2549 struct obd_device *obddev = class_exp2obd(exp);
2550 struct lov_obd *lov = &obddev->u.lov;
2553 struct lov_tgt_desc *tgt;
2554 unsigned incr, check_uuid,
2555 do_inactive, no_set;
2556 unsigned next_id = 0, mds_con = 0;
2559 incr = check_uuid = do_inactive = no_set = 0;
2562 set = ptlrpc_prep_set();
2568 count = lov->desc.ld_tgt_count;
2570 if (KEY_IS(KEY_NEXT_ID)) {
2571 count = vallen / sizeof(struct obd_id_info);
2572 vallen = sizeof(obd_id);
2573 incr = sizeof(struct obd_id_info);
2576 } else if (KEY_IS(KEY_CHECKSUM)) {
2578 } else if (KEY_IS(KEY_UNLINKED)) {
2579 check_uuid = val ? 1 : 0;
2580 } else if (KEY_IS(KEY_EVICT_BY_NID)) {
2581 /* use defaults: do_inactive = incr = 0; */
2582 } else if (KEY_IS(KEY_MDS_CONN)) {
2586 for (i = 0; i < count; i++, val = (char *)val + incr) {
2588 tgt = lov->lov_tgts[((struct obd_id_info*)val)->idx];
2590 tgt = lov->lov_tgts[i];
2592 /* OST was disconnected */
2593 if (!tgt || !tgt->ltd_exp)
2596 /* OST is inactive and we don't want inactive OSCs */
2597 if (!tgt->ltd_active && !do_inactive)
2601 struct mds_group_info *mgi;
2603 LASSERT(vallen == sizeof(*mgi));
2604 mgi = (struct mds_group_info *)val;
2606 /* Only want a specific OSC */
2607 if (mgi->uuid && !obd_uuid_equals(mgi->uuid,
2611 err = obd_set_info_async(tgt->ltd_exp,
2612 keylen, key, sizeof(int),
2614 } else if (next_id) {
2615 err = obd_set_info_async(tgt->ltd_exp,
2616 keylen, key, vallen,
2617 ((struct obd_id_info*)val)->data, set);
2619 /* Only want a specific OSC */
2621 !obd_uuid_equals(val, &tgt->ltd_uuid))
2624 err = obd_set_info_async(tgt->ltd_exp,
2625 keylen, key, vallen, val, set);
2634 err = ptlrpc_set_wait(set);
2637 ptlrpc_set_destroy(set);
2642 static int lov_checkmd(struct obd_export *exp, struct obd_export *md_exp,
2643 struct lov_stripe_md *lsm)
2651 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
2652 rc = lsm_op_find(lsm->lsm_magic)->lsm_revalidate(lsm, md_exp->exp_obd);
2657 int lov_test_and_clear_async_rc(struct lov_stripe_md *lsm)
2662 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2663 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
2664 if (loi->loi_ar.ar_rc && !rc)
2665 rc = loi->loi_ar.ar_rc;
2666 loi->loi_ar.ar_rc = 0;
2670 EXPORT_SYMBOL(lov_test_and_clear_async_rc);
2673 static int lov_extent_calc(struct obd_export *exp, struct lov_stripe_md *lsm,
2674 int cmd, __u64 *offset)
2676 __u32 ssize = lsm->lsm_stripe_size;
2680 do_div(start, ssize);
2681 start = start * ssize;
2683 CDEBUG(D_DLMTRACE, "offset "LPU64", stripe %u, start "LPU64
2684 ", end "LPU64"\n", *offset, ssize, start,
2686 if (cmd == OBD_CALC_STRIPE_END) {
2687 *offset = start + ssize - 1;
2688 } else if (cmd == OBD_CALC_STRIPE_START) {
2697 void lov_stripe_lock(struct lov_stripe_md *md)
2699 LASSERT(md->lsm_lock_owner != cfs_curproc_pid());
2700 spin_lock(&md->lsm_lock);
2701 LASSERT(md->lsm_lock_owner == 0);
2702 md->lsm_lock_owner = cfs_curproc_pid();
2704 EXPORT_SYMBOL(lov_stripe_lock);
2706 void lov_stripe_unlock(struct lov_stripe_md *md)
2708 LASSERT(md->lsm_lock_owner == cfs_curproc_pid());
2709 md->lsm_lock_owner = 0;
2710 spin_unlock(&md->lsm_lock);
2712 EXPORT_SYMBOL(lov_stripe_unlock);
2715 struct obd_ops lov_obd_ops = {
2716 .o_owner = THIS_MODULE,
2717 .o_setup = lov_setup,
2718 .o_precleanup = lov_precleanup,
2719 .o_cleanup = lov_cleanup,
2720 //.o_process_config = lov_process_config,
2721 .o_connect = lov_connect,
2722 .o_disconnect = lov_disconnect,
2723 .o_statfs = lov_statfs,
2724 .o_statfs_async = lov_statfs_async,
2725 .o_packmd = lov_packmd,
2726 .o_unpackmd = lov_unpackmd,
2727 .o_checkmd = lov_checkmd,
2728 .o_create = lov_create,
2729 .o_destroy = lov_destroy,
2730 .o_getattr = lov_getattr,
2731 .o_getattr_async = lov_getattr_async,
2732 .o_setattr = lov_setattr,
2733 .o_setattr_async = lov_setattr_async,
2735 .o_merge_lvb = lov_merge_lvb,
2736 .o_adjust_kms = lov_adjust_kms,
2737 .o_punch = lov_punch,
2739 .o_enqueue = lov_enqueue,
2740 .o_change_cbdata = lov_change_cbdata,
2741 .o_cancel = lov_cancel,
2742 .o_cancel_unused = lov_cancel_unused,
2743 .o_iocontrol = lov_iocontrol,
2744 .o_get_info = lov_get_info,
2745 .o_set_info_async = lov_set_info_async,
2746 .o_extent_calc = lov_extent_calc,
2747 .o_llog_init = lov_llog_init,
2748 .o_llog_finish = lov_llog_finish,
2749 .o_notify = lov_notify,
2750 .o_pool_new = lov_pool_new,
2751 .o_pool_rem = lov_pool_remove,
2752 .o_pool_add = lov_pool_add,
2753 .o_pool_del = lov_pool_del,
2756 static quota_interface_t *quota_interface;
2757 extern quota_interface_t lov_quota_interface;
2759 cfs_mem_cache_t *lov_oinfo_slab;
2761 extern struct lu_kmem_descr lov_caches[];
2763 int __init lov_init(void)
2765 struct lprocfs_static_vars lvars = { 0 };
2769 /* print an address of _any_ initialized kernel symbol from this
2770 * module, to allow debugging with gdb that doesn't support data
2771 * symbols from modules.*/
2772 CDEBUG(D_CONSOLE, "Lustre LOV module (%p).\n", &lov_caches);
2774 rc = lu_kmem_init(lov_caches);
2778 lov_oinfo_slab = cfs_mem_cache_create("lov_oinfo",
2779 sizeof(struct lov_oinfo),
2780 0, SLAB_HWCACHE_ALIGN);
2781 if (lov_oinfo_slab == NULL) {
2782 lu_kmem_fini(lov_caches);
2785 lprocfs_lov_init_vars(&lvars);
2787 request_module("lquota");
2788 quota_interface = PORTAL_SYMBOL_GET(lov_quota_interface);
2789 init_obd_quota_ops(quota_interface, &lov_obd_ops);
2791 rc = class_register_type(&lov_obd_ops, NULL, lvars.module_vars,
2792 LUSTRE_LOV_NAME, &lov_device_type);
2795 if (quota_interface)
2796 PORTAL_SYMBOL_PUT(lov_quota_interface);
2797 rc2 = cfs_mem_cache_destroy(lov_oinfo_slab);
2799 lu_kmem_fini(lov_caches);
2806 static void /*__exit*/ lov_exit(void)
2810 lu_device_type_fini(&lov_device_type);
2811 lu_kmem_fini(lov_caches);
2813 if (quota_interface)
2814 PORTAL_SYMBOL_PUT(lov_quota_interface);
2816 class_unregister_type(LUSTRE_LOV_NAME);
2817 rc = cfs_mem_cache_destroy(lov_oinfo_slab);
2821 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2822 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver");
2823 MODULE_LICENSE("GPL");
2825 cfs_module(lov, LUSTRE_VERSION_STRING, lov_init, lov_exit);