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, struct lov_tgt_desc *tgt);
87 void lov_putref(struct obd_device *obd)
89 struct lov_obd *lov = &obd->u.lov;
91 mutex_down(&lov->lov_lock);
92 /* ok to dec to 0 more than once -- ltd_exp's will be null */
93 if (atomic_dec_and_test(&lov->lov_refcount) && lov->lov_death_row) {
96 struct lov_tgt_desc *tgt, *n;
97 CDEBUG(D_CONFIG, "destroying %d lov targets\n",
99 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
100 tgt = lov->lov_tgts[i];
102 if (!tgt || !tgt->ltd_reap)
104 list_add(&tgt->ltd_kill, &kill);
105 /* XXX - right now there is a dependency on ld_tgt_count
106 * being the maximum tgt index for computing the
107 * mds_max_easize. So we can't shrink it. */
108 lov_ost_pool_remove(&lov->lov_packed, i);
109 lov->lov_tgts[i] = NULL;
110 lov->lov_death_row--;
112 mutex_up(&lov->lov_lock);
114 list_for_each_entry_safe(tgt, n, &kill, ltd_kill) {
115 list_del(&tgt->ltd_kill);
117 __lov_del_obd(obd, tgt);
120 mutex_up(&lov->lov_lock);
124 static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
126 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
127 enum obd_notify_event ev, void *data);
130 #define MAX_STRING_SIZE 128
131 int lov_connect_obd(struct obd_device *obd, __u32 index, int activate,
132 struct obd_connect_data *data)
134 struct lov_obd *lov = &obd->u.lov;
135 struct obd_uuid tgt_uuid;
136 struct obd_device *tgt_obd;
137 struct obd_uuid lov_osc_uuid = { "LOV_OSC_UUID" };
138 struct lustre_handle conn = {0, };
139 struct obd_import *imp;
142 cfs_proc_dir_entry_t *lov_proc_dir;
147 if (!lov->lov_tgts[index])
150 tgt_uuid = lov->lov_tgts[index]->ltd_uuid;
152 tgt_obd = class_find_client_obd(&tgt_uuid, LUSTRE_OSC_NAME,
156 CERROR("Target %s not attached\n", obd_uuid2str(&tgt_uuid));
159 if (!tgt_obd->obd_set_up) {
160 CERROR("Target %s not set up\n", obd_uuid2str(&tgt_uuid));
164 /* override the sp_me from lov */
165 tgt_obd->u.cli.cl_sp_me = lov->lov_sp_me;
167 if (data && (data->ocd_connect_flags & OBD_CONNECT_INDEX))
168 data->ocd_index = index;
171 * Divine LOV knows that OBDs under it are OSCs.
173 imp = tgt_obd->u.cli.cl_import;
176 tgt_obd->obd_no_recov = 0;
177 /* FIXME this is probably supposed to be
178 ptlrpc_set_import_active. Horrible naming. */
179 ptlrpc_activate_import(imp);
182 if (imp->imp_invalid) {
183 CERROR("not connecting OSC %s; administratively "
184 "disabled\n", obd_uuid2str(&tgt_uuid));
185 rc = obd_register_observer(tgt_obd, obd);
187 CERROR("Target %s register_observer error %d; "
188 "will not be able to reactivate\n",
189 obd_uuid2str(&tgt_uuid), rc);
194 rc = obd_connect(NULL, &conn, tgt_obd, &lov_osc_uuid, data, NULL);
196 CERROR("Target %s connect error %d\n",
197 obd_uuid2str(&tgt_uuid), rc);
200 lov->lov_tgts[index]->ltd_exp = class_conn2export(&conn);
201 if (!lov->lov_tgts[index]->ltd_exp) {
202 CERROR("Target %s: null export!\n", obd_uuid2str(&tgt_uuid));
206 rc = obd_register_observer(tgt_obd, obd);
208 CERROR("Target %s register_observer error %d\n",
209 obd_uuid2str(&tgt_uuid), rc);
210 obd_disconnect(lov->lov_tgts[index]->ltd_exp);
211 lov->lov_tgts[index]->ltd_exp = NULL;
215 lov->lov_tgts[index]->ltd_reap = 0;
217 lov->lov_tgts[index]->ltd_active = 1;
218 lov->desc.ld_active_tgt_count++;
219 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 0;
221 CDEBUG(D_CONFIG, "Connected tgt idx %d %s (%s) %sactive\n", index,
222 obd_uuid2str(&tgt_uuid), tgt_obd->obd_name, activate ? "":"in");
225 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
227 struct obd_device *osc_obd = class_conn2obd(&conn);
228 cfs_proc_dir_entry_t *osc_symlink;
229 char name[MAX_STRING_SIZE];
231 LASSERT(osc_obd != NULL);
232 LASSERT(osc_obd->obd_magic == OBD_DEVICE_MAGIC);
233 LASSERT(osc_obd->obd_type->typ_name != NULL);
234 snprintf(name, MAX_STRING_SIZE, "../../../%s/%s",
235 osc_obd->obd_type->typ_name,
237 osc_symlink = lprocfs_add_symlink(osc_obd->obd_name, lov_proc_dir,
239 if (osc_symlink == NULL) {
240 CERROR("could not register LOV target "
241 "/proc/fs/lustre/%s/%s/target_obds/%s.",
242 obd->obd_type->typ_name, obd->obd_name,
244 lprocfs_remove(&lov_proc_dir);
249 rc = qos_add_tgt(obd, index);
251 CERROR("qos_add_tgt failed %d\n", rc);
256 static int lov_connect(const struct lu_env *env,
257 struct lustre_handle *conn, struct obd_device *obd,
258 struct obd_uuid *cluuid, struct obd_connect_data *data,
261 struct lov_obd *lov = &obd->u.lov;
262 struct lov_tgt_desc *tgt;
266 CDEBUG(D_CONFIG, "connect #%d\n", lov->lov_connects);
268 rc = class_connect(conn, obd, cluuid);
272 /* Why should there ever be more than 1 connect? */
274 LASSERT(lov->lov_connects == 1);
276 memset(&lov->lov_ocd, 0, sizeof(lov->lov_ocd));
278 lov->lov_ocd = *data;
281 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
282 tgt = lov->lov_tgts[i];
283 if (!tgt || obd_uuid_empty(&tgt->ltd_uuid))
285 /* Flags will be lowest common denominator */
286 rc = lov_connect_obd(obd, i, tgt->ltd_activate, &lov->lov_ocd);
288 CERROR("%s: lov connect tgt %d failed: %d\n",
289 obd->obd_name, i, rc);
292 /* connect to administrative disabled ost */
293 if (!lov->lov_tgts[i]->ltd_exp)
296 rc = lov_notify(obd, lov->lov_tgts[i]->ltd_exp->exp_obd,
297 OBD_NOTIFY_ACTIVE, (void *)&i);
299 CERROR("%s error sending notify %d\n",
308 static int lov_disconnect_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
310 cfs_proc_dir_entry_t *lov_proc_dir;
311 struct lov_obd *lov = &obd->u.lov;
312 struct obd_device *osc_obd;
316 osc_obd = class_exp2obd(tgt->ltd_exp);
317 CDEBUG(D_CONFIG, "%s: disconnecting target %s\n",
318 obd->obd_name, osc_obd->obd_name);
320 if (tgt->ltd_active) {
322 lov->desc.ld_active_tgt_count--;
323 tgt->ltd_exp->exp_obd->obd_inactive = 1;
326 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
328 cfs_proc_dir_entry_t *osc_symlink;
330 osc_symlink = lprocfs_srch(lov_proc_dir, osc_obd->obd_name);
332 lprocfs_remove(&osc_symlink);
334 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing.",
335 obd->obd_type->typ_name, obd->obd_name,
341 /* Pass it on to our clients.
342 * XXX This should be an argument to disconnect,
343 * XXX not a back-door flag on the OBD. Ah well.
345 osc_obd->obd_force = obd->obd_force;
346 osc_obd->obd_fail = obd->obd_fail;
347 osc_obd->obd_no_recov = obd->obd_no_recov;
350 obd_register_observer(osc_obd, NULL);
352 rc = obd_disconnect(tgt->ltd_exp);
354 CERROR("Target %s disconnect error %d\n",
355 tgt->ltd_uuid.uuid, rc);
359 qos_del_tgt(obd, tgt);
365 static int lov_disconnect(struct obd_export *exp)
367 struct obd_device *obd = class_exp2obd(exp);
368 struct lov_obd *lov = &obd->u.lov;
375 /* Only disconnect the underlying layers on the final disconnect. */
377 if (lov->lov_connects != 0) {
378 /* why should there be more than 1 connect? */
379 CERROR("disconnect #%d\n", lov->lov_connects);
383 /* Let's hold another reference so lov_del_obd doesn't spin through
387 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
388 if (lov->lov_tgts[i] && lov->lov_tgts[i]->ltd_exp) {
389 /* Disconnection is the last we know about an obd */
390 lov_del_target(obd, i, 0, lov->lov_tgts[i]->ltd_gen);
396 rc = class_disconnect(exp); /* bz 9811 */
402 * -EINVAL : UUID can't be found in the LOV's target list
403 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
404 * -EBADF : The UUID is found, but the OBD is the wrong type (!)
405 * any >= 0 : is log target index
407 static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
410 struct lov_obd *lov = &obd->u.lov;
411 struct lov_tgt_desc *tgt;
415 CDEBUG(D_INFO, "Searching in lov %p for uuid %s (activate=%d)\n",
416 lov, uuid->uuid, activate);
419 for (index = 0; index < lov->desc.ld_tgt_count; index++) {
420 tgt = lov->lov_tgts[index];
421 if (!tgt || !tgt->ltd_exp)
424 CDEBUG(D_INFO, "lov idx %d is %s conn "LPX64"\n",
425 index, obd_uuid2str(&tgt->ltd_uuid),
426 tgt->ltd_exp->exp_handle.h_cookie);
427 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
431 if (index == lov->desc.ld_tgt_count)
432 GOTO(out, index = -EINVAL);
434 if (lov->lov_tgts[index]->ltd_active == activate) {
435 CDEBUG(D_INFO, "OSC %s already %sactive!\n", uuid->uuid,
436 activate ? "" : "in");
440 CDEBUG(D_CONFIG, "Marking OSC %s %sactive\n", obd_uuid2str(uuid),
441 activate ? "" : "in");
443 lov->lov_tgts[index]->ltd_active = activate;
446 lov->desc.ld_active_tgt_count++;
447 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 0;
449 lov->desc.ld_active_tgt_count--;
450 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 1;
452 /* remove any old qos penalty */
453 lov->lov_tgts[index]->ltd_qos.ltq_penalty = 0;
460 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
461 enum obd_notify_event ev, void *data)
466 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
467 struct obd_uuid *uuid;
471 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
472 CERROR("unexpected notification of %s %s!\n",
473 watched->obd_type->typ_name,
477 uuid = &watched->u.cli.cl_target_uuid;
479 /* Set OSC as active before notifying the observer, so the
480 * observer can use the OSC normally.
482 rc = lov_set_osc_active(obd, uuid, ev == OBD_NOTIFY_ACTIVE);
484 CERROR("%sactivation of %s failed: %d\n",
485 (ev == OBD_NOTIFY_ACTIVE) ? "" : "de",
486 obd_uuid2str(uuid), rc);
489 /* active event should be pass lov target index as data */
493 /* Pass the notification up the chain. */
495 rc = obd_notify_observer(obd, watched, ev, data);
497 /* NULL watched means all osc's in the lov (only for syncs) */
498 /* sync event should be send lov idx as data */
499 struct lov_obd *lov = &obd->u.lov;
500 struct obd_device *tgt_obd;
503 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
504 if (!lov->lov_tgts[i])
507 if ((ev == OBD_NOTIFY_SYNC) ||
508 (ev == OBD_NOTIFY_SYNC_NONBLOCK))
511 tgt_obd = class_exp2obd(lov->lov_tgts[i]->ltd_exp);
513 rc = obd_notify_observer(obd, tgt_obd, ev, data);
515 CERROR("%s: notify %s of %s failed %d\n",
517 obd->obd_observer->obd_name,
518 tgt_obd->obd_name, rc);
528 int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
529 __u32 index, int gen, int active)
531 struct lov_obd *lov = &obd->u.lov;
532 struct lov_tgt_desc *tgt;
536 CDEBUG(D_CONFIG, "uuid:%s idx:%d gen:%d active:%d\n",
537 uuidp->uuid, index, gen, active);
540 CERROR("request to add OBD %s with invalid generation: %d\n",
545 mutex_down(&lov->lov_lock);
547 if ((index < lov->lov_tgt_size) && (lov->lov_tgts[index] != NULL)) {
548 tgt = lov->lov_tgts[index];
549 CERROR("UUID %s already assigned at LOV target index %d\n",
550 obd_uuid2str(&tgt->ltd_uuid), index);
551 mutex_up(&lov->lov_lock);
555 if (index >= lov->lov_tgt_size) {
556 /* We need to reallocate the lov target array. */
557 struct lov_tgt_desc **newtgts, **old = NULL;
558 __u32 newsize, oldsize = 0;
560 newsize = max(lov->lov_tgt_size, (__u32)2);
561 while (newsize < index + 1)
562 newsize = newsize << 1;
563 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
564 if (newtgts == NULL) {
565 mutex_up(&lov->lov_lock);
569 if (lov->lov_tgt_size) {
570 memcpy(newtgts, lov->lov_tgts, sizeof(*newtgts) *
573 oldsize = lov->lov_tgt_size;
576 lov->lov_tgts = newtgts;
577 lov->lov_tgt_size = newsize;
582 OBD_FREE(old, sizeof(*old) * oldsize);
584 CDEBUG(D_CONFIG, "tgts: %p size: %d\n",
585 lov->lov_tgts, lov->lov_tgt_size);
590 mutex_up(&lov->lov_lock);
594 memset(tgt, 0, sizeof(*tgt));
595 tgt->ltd_uuid = *uuidp;
596 /* XXX - add a sanity check on the generation number. */
598 tgt->ltd_index = index;
599 tgt->ltd_activate = active;
600 lov->lov_tgts[index] = tgt;
601 if (index >= lov->desc.ld_tgt_count)
602 lov->desc.ld_tgt_count = index + 1;
604 rc = lov_ost_pool_add(&lov->lov_packed, index, lov->lov_tgt_size);
608 mutex_up(&lov->lov_lock);
610 CDEBUG(D_CONFIG, "idx=%d ltd_gen=%d ld_tgt_count=%d\n",
611 index, tgt->ltd_gen, lov->desc.ld_tgt_count);
613 if (lov->lov_connects == 0) {
614 /* lov_connect hasn't been called yet. We'll do the
615 lov_connect_obd on this target when that fn first runs,
616 because we don't know the connect flags yet. */
622 rc = lov_connect_obd(obd, index, active, &lov->lov_ocd);
626 /* connect to administrative disabled ost */
630 rc = lov_notify(obd, tgt->ltd_exp->exp_obd,
631 active ? OBD_NOTIFY_ACTIVE : OBD_NOTIFY_INACTIVE,
636 CERROR("add failed (%d), deleting %s\n", rc,
637 obd_uuid2str(&tgt->ltd_uuid));
638 lov_del_target(obd, index, 0, 0);
644 /* Schedule a target for deletion */
645 int lov_del_target(struct obd_device *obd, __u32 index,
646 struct obd_uuid *uuidp, int gen)
648 struct lov_obd *lov = &obd->u.lov;
649 int count = lov->desc.ld_tgt_count;
653 if (index >= count) {
654 CERROR("LOV target index %d >= number of LOV OBDs %d.\n",
661 if (!lov->lov_tgts[index]) {
662 CERROR("LOV target at index %d is not setup.\n", index);
663 GOTO(out, rc = -EINVAL);
666 if (uuidp && !obd_uuid_equals(uuidp, &lov->lov_tgts[index]->ltd_uuid)) {
667 CERROR("LOV target UUID %s at index %d doesn't match %s.\n",
668 lov_uuid2str(lov, index), index,
669 obd_uuid2str(uuidp));
670 GOTO(out, rc = -EINVAL);
673 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d exp: %p active: %d\n",
674 lov_uuid2str(lov, index), index,
675 lov->lov_tgts[index]->ltd_gen, lov->lov_tgts[index]->ltd_exp,
676 lov->lov_tgts[index]->ltd_active);
678 lov->lov_tgts[index]->ltd_reap = 1;
679 lov->lov_death_row++;
680 /* we really delete it from lov_putref */
687 static void __lov_del_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
689 struct obd_device *osc_obd;
692 LASSERT(tgt->ltd_reap);
694 osc_obd = class_exp2obd(tgt->ltd_exp);
696 CDEBUG(D_CONFIG, "Removing tgt %s : %s\n",
698 osc_obd ? osc_obd->obd_name : "<no obd>");
701 lov_disconnect_obd(obd, tgt);
705 /* Manual cleanup - no cleanup logs to clean up the osc's. We must
706 do it ourselves. And we can't do it from lov_cleanup,
707 because we just lost our only reference to it. */
709 class_manual_cleanup(osc_obd);
712 void lov_fix_desc_stripe_size(__u64 *val)
714 if (*val < PTLRPC_MAX_BRW_SIZE) {
715 LCONSOLE_WARN("Increasing default stripe size to min %u\n",
716 PTLRPC_MAX_BRW_SIZE);
717 *val = PTLRPC_MAX_BRW_SIZE;
718 } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) {
719 *val &= ~(LOV_MIN_STRIPE_SIZE - 1);
720 LCONSOLE_WARN("Changing default stripe size to "LPU64" (a "
722 *val, LOV_MIN_STRIPE_SIZE);
726 void lov_fix_desc_stripe_count(__u32 *val)
732 void lov_fix_desc_pattern(__u32 *val)
734 /* from lov_setstripe */
735 if ((*val != 0) && (*val != LOV_PATTERN_RAID0)) {
736 LCONSOLE_WARN("Unknown stripe pattern: %#x\n", *val);
741 void lov_fix_desc_qos_maxage(__u32 *val)
745 *val = QOS_DEFAULT_MAXAGE;
748 void lov_fix_desc(struct lov_desc *desc)
750 lov_fix_desc_stripe_size(&desc->ld_default_stripe_size);
751 lov_fix_desc_stripe_count(&desc->ld_default_stripe_count);
752 lov_fix_desc_pattern(&desc->ld_pattern);
753 lov_fix_desc_qos_maxage(&desc->ld_qos_maxage);
756 int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
758 struct lprocfs_static_vars lvars = { 0 };
759 struct lov_desc *desc;
760 struct lov_obd *lov = &obd->u.lov;
765 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
766 CERROR("LOV setup requires a descriptor\n");
770 desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
772 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
773 CERROR("descriptor size wrong: %d > %d\n",
774 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
778 if (desc->ld_magic != LOV_DESC_MAGIC) {
779 if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
780 CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n",
781 obd->obd_name, desc);
782 lustre_swab_lov_desc(desc);
784 CERROR("%s: Bad lov desc magic: %#x\n",
785 obd->obd_name, desc->ld_magic);
792 /* Because of 64-bit divide/mod operations only work with a 32-bit
793 * divisor in a 32-bit kernel, we cannot support a stripe width
794 * of 4GB or larger on 32-bit CPUs. */
795 count = desc->ld_default_stripe_count;
796 if ((count > 0 ? count : desc->ld_tgt_count) *
797 desc->ld_default_stripe_size > 0xffffffff) {
798 CERROR("LOV: stripe width "LPU64"x%u > 4294967295 bytes\n",
799 desc->ld_default_stripe_size, count);
803 desc->ld_active_tgt_count = 0;
805 lov->lov_tgt_size = 0;
807 sema_init(&lov->lov_lock, 1);
808 atomic_set(&lov->lov_refcount, 0);
809 CFS_INIT_LIST_HEAD(&lov->lov_qos.lq_oss_list);
810 init_rwsem(&lov->lov_qos.lq_rw_sem);
811 lov->lov_sp_me = LUSTRE_SP_CLI;
812 lov->lov_qos.lq_dirty = 1;
813 lov->lov_qos.lq_rr.lqr_dirty = 1;
814 lov->lov_qos.lq_reset = 1;
815 /* Default priority is toward free space balance */
816 lov->lov_qos.lq_prio_free = 232;
818 lov->lov_pools_hash_body = lustre_hash_init("POOLS", 7, 7,
819 &pool_hash_operations, 0);
820 CFS_INIT_LIST_HEAD(&lov->lov_pool_list);
821 lov->lov_pool_count = 0;
822 rc = lov_ost_pool_init(&lov->lov_packed, 0);
825 rc = lov_ost_pool_init(&lov->lov_qos.lq_rr.lqr_pool, 0);
827 lov_ost_pool_free(&lov->lov_packed);
831 lprocfs_lov_init_vars(&lvars);
832 lprocfs_obd_setup(obd, lvars.obd_vars);
837 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
838 0444, &lov_proc_target_fops, obd);
840 CWARN("Error adding the target_obd file\n");
843 lov->lov_pool_proc_entry = lprocfs_register("pools",
850 static int lov_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
856 case OBD_CLEANUP_EARLY: {
857 struct lov_obd *lov = &obd->u.lov;
859 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
860 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
862 obd_precleanup(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
867 case OBD_CLEANUP_EXPORTS:
868 rc = obd_llog_finish(obd, 0);
870 CERROR("failed to cleanup llogging subsystems\n");
876 static int lov_cleanup(struct obd_device *obd)
878 struct lov_obd *lov = &obd->u.lov;
879 struct list_head *pos, *tmp;
880 struct pool_desc *pool;
882 lprocfs_obd_cleanup(obd);
884 /* Delete hash entries and kill hash table before freeing pools
885 * and get to use after free issue. */
886 lustre_hash_exit(lov->lov_pools_hash_body);
888 list_for_each_safe(pos, tmp, &lov->lov_pool_list) {
889 pool = list_entry(pos, struct pool_desc, pool_list);
890 /* free pool structs */
891 lov_pool_del(obd, pool->pool_name);
893 lov_ost_pool_free(&(lov->lov_qos.lq_rr.lqr_pool));
894 lov_ost_pool_free(&lov->lov_packed);
898 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
899 if (!lov->lov_tgts[i])
902 /* Inactive targets may never have connected */
903 if (lov->lov_tgts[i]->ltd_active ||
904 atomic_read(&lov->lov_refcount))
905 /* We should never get here - these
906 should have been removed in the
908 CERROR("lov tgt %d not cleaned!"
909 " deathrow=%d, lovrc=%d\n",
910 i, lov->lov_death_row,
911 atomic_read(&lov->lov_refcount));
912 lov_del_target(obd, i, 0, 0);
914 OBD_FREE(lov->lov_tgts, sizeof(*lov->lov_tgts) *
916 lov->lov_tgt_size = 0;
922 int lov_process_config_base(struct obd_device *obd, struct lustre_cfg *lcfg,
923 __u32 *indexp, int *genp)
925 struct obd_uuid obd_uuid;
930 switch(cmd = lcfg->lcfg_command) {
931 case LCFG_LOV_ADD_OBD:
932 case LCFG_LOV_ADD_INA:
933 case LCFG_LOV_DEL_OBD: {
936 /* lov_modify_tgts add 0:lov_mdsA 1:ost1_UUID 2:0 3:1 */
937 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
938 GOTO(out, rc = -EINVAL);
940 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
942 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", indexp) != 1)
943 GOTO(out, rc = -EINVAL);
944 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", genp) != 1)
945 GOTO(out, rc = -EINVAL);
948 if (cmd == LCFG_LOV_ADD_OBD)
949 rc = lov_add_target(obd, &obd_uuid, index, gen, 1);
950 else if (cmd == LCFG_LOV_ADD_INA)
951 rc = lov_add_target(obd, &obd_uuid, index, gen, 0);
953 rc = lov_del_target(obd, index, &obd_uuid, gen);
957 struct lprocfs_static_vars lvars = { 0 };
958 struct lov_desc *desc = &(obd->u.lov.desc);
961 GOTO(out, rc = -EINVAL);
963 lprocfs_lov_init_vars(&lvars);
965 rc = class_process_proc_param(PARAM_LOV, lvars.obd_vars,
978 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
979 GOTO(out, rc = -EINVAL);
988 #define log2(n) ffz(~(n))
991 static int lov_clear_orphans(struct obd_export *export, struct obdo *src_oa,
992 struct lov_stripe_md **ea,
993 struct obd_trans_info *oti)
997 struct obd_uuid *ost_uuid = NULL;
1001 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
1002 src_oa->o_flags == OBD_FL_DELORPHAN);
1004 lov = &export->exp_obd->u.lov;
1010 if (oti->oti_ost_uuid) {
1011 ost_uuid = oti->oti_ost_uuid;
1012 CDEBUG(D_HA, "clearing orphans only for %s\n",
1016 lov_getref(export->exp_obd);
1017 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1018 struct lov_stripe_md obj_md;
1019 struct lov_stripe_md *obj_mdp = &obj_md;
1020 struct lov_tgt_desc *tgt;
1023 tgt = lov->lov_tgts[i];
1027 /* if called for a specific target, we don't
1028 care if it is not active. */
1029 if (!lov->lov_tgts[i]->ltd_active && ost_uuid == NULL) {
1030 CDEBUG(D_HA, "lov idx %d inactive\n", i);
1034 if (ost_uuid && !obd_uuid_equals(ost_uuid, &tgt->ltd_uuid))
1037 CDEBUG(D_CONFIG,"Clear orphans for %d:%s\n", i,
1038 obd_uuid2str(ost_uuid));
1040 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
1042 LASSERT(lov->lov_tgts[i]->ltd_exp);
1043 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1044 err = obd_create(lov->lov_tgts[i]->ltd_exp,
1045 tmp_oa, &obj_mdp, oti);
1047 /* This export will be disabled until it is recovered,
1048 and then orphan recovery will be completed. */
1049 CERROR("error in orphan recovery on OST idx %d/%d: "
1050 "rc = %d\n", i, lov->desc.ld_tgt_count, err);
1057 lov_putref(export->exp_obd);
1063 static int lov_recreate(struct obd_export *exp, struct obdo *src_oa,
1064 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1066 struct lov_stripe_md *obj_mdp, *lsm;
1067 struct lov_obd *lov = &exp->exp_obd->u.lov;
1072 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
1073 src_oa->o_flags & OBD_FL_RECREATE_OBJS);
1075 OBD_ALLOC(obj_mdp, sizeof(*obj_mdp));
1076 if (obj_mdp == NULL)
1079 ost_idx = src_oa->o_nlink;
1082 GOTO(out, rc = -EINVAL);
1083 if (ost_idx >= lov->desc.ld_tgt_count ||
1084 !lov->lov_tgts[ost_idx])
1085 GOTO(out, rc = -EINVAL);
1087 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1088 if (lsm->lsm_oinfo[i]->loi_ost_idx == ost_idx) {
1089 if (lsm->lsm_oinfo[i]->loi_id != src_oa->o_id)
1090 GOTO(out, rc = -EINVAL);
1094 if (i == lsm->lsm_stripe_count)
1095 GOTO(out, rc = -EINVAL);
1097 rc = obd_create(lov->lov_tgts[ost_idx]->ltd_exp, src_oa, &obj_mdp, oti);
1099 OBD_FREE(obj_mdp, sizeof(*obj_mdp));
1103 /* the LOV expects oa->o_id to be set to the LOV object id */
1104 static int lov_create(struct obd_export *exp, struct obdo *src_oa,
1105 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1107 struct lov_obd *lov;
1108 struct obd_info oinfo;
1109 struct lov_request_set *set = NULL;
1110 struct lov_request *req;
1111 struct obd_statfs osfs;
1116 LASSERT(ea != NULL);
1120 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1121 src_oa->o_flags == OBD_FL_DELORPHAN) {
1122 rc = lov_clear_orphans(exp, src_oa, ea, oti);
1126 lov = &exp->exp_obd->u.lov;
1127 if (!lov->desc.ld_active_tgt_count)
1130 lov_getref(exp->exp_obd);
1131 /* Recreate a specific object id at the given OST index */
1132 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1133 (src_oa->o_flags & OBD_FL_RECREATE_OBJS)) {
1134 rc = lov_recreate(exp, src_oa, ea, oti);
1138 maxage = cfs_time_shift_64(-lov->desc.ld_qos_maxage);
1139 obd_statfs_rqset(exp->exp_obd, &osfs, maxage, OBD_STATFS_NODELAY);
1141 rc = lov_prep_create_set(exp, &oinfo, ea, src_oa, oti, &set);
1145 list_for_each_entry(req, &set->set_list, rq_link) {
1146 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1147 rc = obd_create(lov->lov_tgts[req->rq_idx]->ltd_exp,
1148 req->rq_oi.oi_oa, &req->rq_oi.oi_md, oti);
1149 lov_update_create_set(set, req, rc);
1151 rc = lov_fini_create_set(set, ea);
1153 lov_putref(exp->exp_obd);
1157 #define ASSERT_LSM_MAGIC(lsmp) \
1159 LASSERT((lsmp) != NULL); \
1160 LASSERTF(((lsmp)->lsm_magic == LOV_MAGIC_V1 || \
1161 (lsmp)->lsm_magic == LOV_MAGIC_V3 || \
1162 (lsmp)->lsm_magic == LOV_MAGIC_JOIN), "%p->lsm_magic=%x\n", \
1163 (lsmp), (lsmp)->lsm_magic); \
1166 static int lov_destroy(struct obd_export *exp, struct obdo *oa,
1167 struct lov_stripe_md *lsm, struct obd_trans_info *oti,
1168 struct obd_export *md_exp, void *capa)
1170 struct lov_request_set *set;
1171 struct obd_info oinfo;
1172 struct lov_request *req;
1173 struct list_head *pos;
1174 struct lov_obd *lov;
1175 int rc = 0, err = 0;
1178 ASSERT_LSM_MAGIC(lsm);
1180 if (!exp || !exp->exp_obd)
1183 if (oa->o_valid & OBD_MD_FLCOOKIE) {
1185 LASSERT(oti->oti_logcookies);
1188 lov = &exp->exp_obd->u.lov;
1189 lov_getref(exp->exp_obd);
1190 rc = lov_prep_destroy_set(exp, &oinfo, oa, lsm, oti, &set);
1194 list_for_each (pos, &set->set_list) {
1195 req = list_entry(pos, struct lov_request, rq_link);
1197 if (oa->o_valid & OBD_MD_FLCOOKIE)
1198 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1200 err = obd_destroy(lov->lov_tgts[req->rq_idx]->ltd_exp,
1201 req->rq_oi.oi_oa, NULL, oti, NULL, capa);
1202 err = lov_update_common_set(set, req, err);
1204 CERROR("error: destroying objid "LPX64" subobj "
1205 LPX64" on OST idx %d: rc = %d\n",
1206 oa->o_id, req->rq_oi.oi_oa->o_id,
1214 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
1215 rc = lsm_op_find(lsm->lsm_magic)->lsm_destroy(lsm, oa, md_exp);
1217 err = lov_fini_destroy_set(set);
1219 lov_putref(exp->exp_obd);
1220 RETURN(rc ? rc : err);
1223 static int lov_getattr(struct obd_export *exp, struct obd_info *oinfo)
1225 struct lov_request_set *set;
1226 struct lov_request *req;
1227 struct list_head *pos;
1228 struct lov_obd *lov;
1229 int err = 0, rc = 0;
1233 ASSERT_LSM_MAGIC(oinfo->oi_md);
1235 if (!exp || !exp->exp_obd)
1238 lov = &exp->exp_obd->u.lov;
1240 rc = lov_prep_getattr_set(exp, oinfo, &set);
1244 list_for_each (pos, &set->set_list) {
1245 req = list_entry(pos, struct lov_request, rq_link);
1247 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1248 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1249 req->rq_oi.oi_oa->o_id, req->rq_idx);
1251 rc = obd_getattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1253 err = lov_update_common_set(set, req, rc);
1255 CERROR("error: getattr objid "LPX64" subobj "
1256 LPX64" on OST idx %d: rc = %d\n",
1257 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1263 rc = lov_fini_getattr_set(set);
1269 static int lov_getattr_interpret(struct ptlrpc_request_set *rqset,
1272 struct lov_request_set *lovset = (struct lov_request_set *)data;
1276 /* don't do attribute merge if this aysnc op failed */
1278 lovset->set_completes = 0;
1279 err = lov_fini_getattr_set(lovset);
1280 RETURN(rc ? rc : err);
1283 static int lov_getattr_async(struct obd_export *exp, struct obd_info *oinfo,
1284 struct ptlrpc_request_set *rqset)
1286 struct lov_request_set *lovset;
1287 struct lov_obd *lov;
1288 struct list_head *pos;
1289 struct lov_request *req;
1294 ASSERT_LSM_MAGIC(oinfo->oi_md);
1296 if (!exp || !exp->exp_obd)
1299 lov = &exp->exp_obd->u.lov;
1301 rc = lov_prep_getattr_set(exp, oinfo, &lovset);
1305 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1306 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1307 oinfo->oi_md->lsm_stripe_size);
1309 list_for_each (pos, &lovset->set_list) {
1310 req = list_entry(pos, struct lov_request, rq_link);
1312 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1313 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1314 req->rq_oi.oi_oa->o_id, req->rq_idx);
1315 rc = obd_getattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1316 &req->rq_oi, rqset);
1318 CERROR("error: getattr objid "LPX64" subobj "
1319 LPX64" on OST idx %d: rc = %d\n",
1320 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1326 if (!list_empty(&rqset->set_requests)) {
1328 LASSERT (rqset->set_interpret == NULL);
1329 rqset->set_interpret = lov_getattr_interpret;
1330 rqset->set_arg = (void *)lovset;
1335 lovset->set_completes = 0;
1336 err = lov_fini_getattr_set(lovset);
1337 RETURN(rc ? rc : err);
1340 static int lov_setattr(struct obd_export *exp, struct obd_info *oinfo,
1341 struct obd_trans_info *oti)
1343 struct lov_request_set *set;
1344 struct lov_obd *lov;
1345 struct list_head *pos;
1346 struct lov_request *req;
1347 int err = 0, rc = 0;
1351 ASSERT_LSM_MAGIC(oinfo->oi_md);
1353 if (!exp || !exp->exp_obd)
1356 /* for now, we only expect the following updates here */
1357 LASSERT(!(oinfo->oi_oa->o_valid & ~(OBD_MD_FLID | OBD_MD_FLTYPE |
1358 OBD_MD_FLMODE | OBD_MD_FLATIME |
1359 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1360 OBD_MD_FLFLAGS | OBD_MD_FLSIZE |
1361 OBD_MD_FLGROUP | OBD_MD_FLUID |
1362 OBD_MD_FLGID | OBD_MD_FLFID |
1364 lov = &exp->exp_obd->u.lov;
1365 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1369 list_for_each (pos, &set->set_list) {
1370 req = list_entry(pos, struct lov_request, rq_link);
1372 rc = obd_setattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1374 err = lov_update_setattr_set(set, req, rc);
1376 CERROR("error: setattr objid "LPX64" subobj "
1377 LPX64" on OST idx %d: rc = %d\n",
1378 set->set_oi->oi_oa->o_id,
1379 req->rq_oi.oi_oa->o_id, req->rq_idx, err);
1384 err = lov_fini_setattr_set(set);
1390 static int lov_setattr_interpret(struct ptlrpc_request_set *rqset,
1393 struct lov_request_set *lovset = (struct lov_request_set *)data;
1398 lovset->set_completes = 0;
1399 err = lov_fini_setattr_set(lovset);
1400 RETURN(rc ? rc : err);
1403 /* If @oti is given, the request goes from MDS and responses from OSTs are not
1404 needed. Otherwise, a client is waiting for responses. */
1405 static int lov_setattr_async(struct obd_export *exp, struct obd_info *oinfo,
1406 struct obd_trans_info *oti,
1407 struct ptlrpc_request_set *rqset)
1409 struct lov_request_set *set;
1410 struct lov_request *req;
1411 struct list_head *pos;
1412 struct lov_obd *lov;
1417 ASSERT_LSM_MAGIC(oinfo->oi_md);
1418 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE) {
1420 LASSERT(oti->oti_logcookies);
1423 if (!exp || !exp->exp_obd)
1426 lov = &exp->exp_obd->u.lov;
1427 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1431 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1432 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1433 oinfo->oi_md->lsm_stripe_size);
1435 list_for_each (pos, &set->set_list) {
1436 req = list_entry(pos, struct lov_request, rq_link);
1438 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
1439 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1441 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1442 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1443 req->rq_oi.oi_oa->o_id, req->rq_idx);
1445 rc = obd_setattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1446 &req->rq_oi, oti, rqset);
1448 CERROR("error: setattr objid "LPX64" subobj "
1449 LPX64" on OST idx %d: rc = %d\n",
1450 set->set_oi->oi_oa->o_id,
1451 req->rq_oi.oi_oa->o_id,
1457 /* If we are not waiting for responses on async requests, return. */
1458 if (rc || !rqset || list_empty(&rqset->set_requests)) {
1461 set->set_completes = 0;
1462 err = lov_fini_setattr_set(set);
1463 RETURN(rc ? rc : err);
1466 LASSERT(rqset->set_interpret == NULL);
1467 rqset->set_interpret = lov_setattr_interpret;
1468 rqset->set_arg = (void *)set;
1473 static int lov_punch_interpret(struct ptlrpc_request_set *rqset,
1476 struct lov_request_set *lovset = (struct lov_request_set *)data;
1481 lovset->set_completes = 0;
1482 err = lov_fini_punch_set(lovset);
1483 RETURN(rc ? rc : err);
1486 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
1487 * we can send this 'punch' to just the authoritative node and the nodes
1488 * that the punch will affect. */
1489 static int lov_punch(struct obd_export *exp, struct obd_info *oinfo,
1490 struct obd_trans_info *oti,
1491 struct ptlrpc_request_set *rqset)
1493 struct lov_request_set *set;
1494 struct lov_obd *lov;
1495 struct list_head *pos;
1496 struct lov_request *req;
1501 ASSERT_LSM_MAGIC(oinfo->oi_md);
1503 if (!exp || !exp->exp_obd)
1506 lov = &exp->exp_obd->u.lov;
1507 rc = lov_prep_punch_set(exp, oinfo, oti, &set);
1511 list_for_each (pos, &set->set_list) {
1512 req = list_entry(pos, struct lov_request, rq_link);
1514 rc = obd_punch(lov->lov_tgts[req->rq_idx]->ltd_exp,
1515 &req->rq_oi, NULL, rqset);
1517 CERROR("error: punch objid "LPX64" subobj "LPX64
1518 " on OST idx %d: rc = %d\n",
1519 set->set_oi->oi_oa->o_id,
1520 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1525 if (rc || list_empty(&rqset->set_requests)) {
1527 err = lov_fini_punch_set(set);
1528 RETURN(rc ? rc : err);
1531 LASSERT(rqset->set_interpret == NULL);
1532 rqset->set_interpret = lov_punch_interpret;
1533 rqset->set_arg = (void *)set;
1538 static int lov_sync(struct obd_export *exp, struct obdo *oa,
1539 struct lov_stripe_md *lsm, obd_off start, obd_off end,
1542 struct lov_request_set *set;
1543 struct obd_info oinfo;
1544 struct lov_obd *lov;
1545 struct list_head *pos;
1546 struct lov_request *req;
1547 int err = 0, rc = 0;
1550 ASSERT_LSM_MAGIC(lsm);
1555 lov = &exp->exp_obd->u.lov;
1556 rc = lov_prep_sync_set(exp, &oinfo, oa, lsm, start, end, &set);
1560 list_for_each (pos, &set->set_list) {
1561 req = list_entry(pos, struct lov_request, rq_link);
1563 rc = obd_sync(lov->lov_tgts[req->rq_idx]->ltd_exp,
1564 req->rq_oi.oi_oa, NULL,
1565 req->rq_oi.oi_policy.l_extent.start,
1566 req->rq_oi.oi_policy.l_extent.end, capa);
1567 err = lov_update_common_set(set, req, rc);
1569 CERROR("error: fsync objid "LPX64" subobj "LPX64
1570 " on OST idx %d: rc = %d\n",
1571 set->set_oi->oi_oa->o_id,
1572 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1577 err = lov_fini_sync_set(set);
1583 static int lov_brw_check(struct lov_obd *lov, struct obd_info *lov_oinfo,
1584 obd_count oa_bufs, struct brw_page *pga)
1586 struct obd_info oinfo = { { { 0 } } };
1589 oinfo.oi_oa = lov_oinfo->oi_oa;
1591 /* The caller just wants to know if there's a chance that this
1592 * I/O can succeed */
1593 for (i = 0; i < oa_bufs; i++) {
1594 int stripe = lov_stripe_number(lov_oinfo->oi_md, pga[i].off);
1595 int ost = lov_oinfo->oi_md->lsm_oinfo[stripe]->loi_ost_idx;
1598 if (!lov_stripe_intersects(lov_oinfo->oi_md, i, pga[i].off,
1599 pga[i].off + pga[i].count - 1,
1603 if (!lov->lov_tgts[ost] || !lov->lov_tgts[ost]->ltd_active) {
1604 CDEBUG(D_HA, "lov idx %d inactive\n", ost);
1608 rc = obd_brw(OBD_BRW_CHECK, lov->lov_tgts[ost]->ltd_exp, &oinfo,
1616 static int lov_brw(int cmd, struct obd_export *exp, struct obd_info *oinfo,
1617 obd_count oa_bufs, struct brw_page *pga,
1618 struct obd_trans_info *oti)
1620 struct lov_request_set *set;
1621 struct lov_request *req;
1622 struct list_head *pos;
1623 struct lov_obd *lov = &exp->exp_obd->u.lov;
1627 ASSERT_LSM_MAGIC(oinfo->oi_md);
1629 if (cmd == OBD_BRW_CHECK) {
1630 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1634 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &set);
1638 list_for_each (pos, &set->set_list) {
1639 struct obd_export *sub_exp;
1640 struct brw_page *sub_pga;
1641 req = list_entry(pos, struct lov_request, rq_link);
1643 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1644 sub_pga = set->set_pga + req->rq_pgaidx;
1645 rc = obd_brw(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1649 lov_update_common_set(set, req, rc);
1652 err = lov_fini_brw_set(set);
1658 static int lov_enqueue_interpret(struct ptlrpc_request_set *rqset,
1661 struct lov_request_set *lovset = (struct lov_request_set *)data;
1663 rc = lov_fini_enqueue_set(lovset, lovset->set_ei->ei_mode, rc, rqset);
1667 static int lov_enqueue(struct obd_export *exp, struct obd_info *oinfo,
1668 struct ldlm_enqueue_info *einfo,
1669 struct ptlrpc_request_set *rqset)
1671 ldlm_mode_t mode = einfo->ei_mode;
1672 struct lov_request_set *set;
1673 struct lov_request *req;
1674 struct list_head *pos;
1675 struct lov_obd *lov;
1680 ASSERT_LSM_MAGIC(oinfo->oi_md);
1681 LASSERT(mode == (mode & -mode));
1683 /* we should never be asked to replay a lock this way. */
1684 LASSERT((oinfo->oi_flags & LDLM_FL_REPLAY) == 0);
1686 if (!exp || !exp->exp_obd)
1689 lov = &exp->exp_obd->u.lov;
1690 rc = lov_prep_enqueue_set(exp, oinfo, einfo, &set);
1694 list_for_each (pos, &set->set_list) {
1695 req = list_entry(pos, struct lov_request, rq_link);
1697 rc = obd_enqueue(lov->lov_tgts[req->rq_idx]->ltd_exp,
1698 &req->rq_oi, einfo, rqset);
1703 if (rqset && !list_empty(&rqset->set_requests)) {
1705 LASSERT(rqset->set_interpret == NULL);
1706 rqset->set_interpret = lov_enqueue_interpret;
1707 rqset->set_arg = (void *)set;
1711 rc = lov_fini_enqueue_set(set, mode, rc, rqset);
1715 static int lov_change_cbdata(struct obd_export *exp,
1716 struct lov_stripe_md *lsm, ldlm_iterator_t it,
1719 struct lov_obd *lov;
1723 ASSERT_LSM_MAGIC(lsm);
1725 if (!exp || !exp->exp_obd)
1728 LASSERT_MDS_GROUP(lsm->lsm_object_gr);
1730 lov = &exp->exp_obd->u.lov;
1731 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1732 struct lov_stripe_md submd;
1733 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
1735 if (!lov->lov_tgts[loi->loi_ost_idx]) {
1736 CDEBUG(D_HA, "lov idx %d NULL \n", loi->loi_ost_idx);
1740 submd.lsm_object_id = loi->loi_id;
1741 submd.lsm_object_gr = lsm->lsm_object_gr;
1742 submd.lsm_stripe_count = 0;
1743 rc = obd_change_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1749 static int lov_cancel(struct obd_export *exp, struct lov_stripe_md *lsm,
1750 __u32 mode, struct lustre_handle *lockh)
1752 struct lov_request_set *set;
1753 struct obd_info oinfo;
1754 struct lov_request *req;
1755 struct list_head *pos;
1756 struct lov_obd *lov = &exp->exp_obd->u.lov;
1757 struct lustre_handle *lov_lockhp;
1758 int err = 0, rc = 0;
1761 ASSERT_LSM_MAGIC(lsm);
1763 if (!exp || !exp->exp_obd)
1766 LASSERT_MDS_GROUP(lsm->lsm_object_gr);
1768 lov = &exp->exp_obd->u.lov;
1769 rc = lov_prep_cancel_set(exp, &oinfo, lsm, mode, lockh, &set);
1773 list_for_each (pos, &set->set_list) {
1774 req = list_entry(pos, struct lov_request, rq_link);
1775 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
1777 rc = obd_cancel(lov->lov_tgts[req->rq_idx]->ltd_exp,
1778 req->rq_oi.oi_md, mode, lov_lockhp);
1779 rc = lov_update_common_set(set, req, rc);
1781 CERROR("error: cancel objid "LPX64" subobj "
1782 LPX64" on OST idx %d: rc = %d\n",
1784 req->rq_oi.oi_md->lsm_object_id,
1790 lov_fini_cancel_set(set);
1794 static int lov_cancel_unused(struct obd_export *exp,
1795 struct lov_stripe_md *lsm,
1796 int flags, void *opaque)
1798 struct lov_obd *lov;
1802 if (!exp || !exp->exp_obd)
1805 lov = &exp->exp_obd->u.lov;
1807 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1809 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
1812 err = obd_cancel_unused(lov->lov_tgts[i]->ltd_exp, NULL,
1820 ASSERT_LSM_MAGIC(lsm);
1822 LASSERT_MDS_GROUP(lsm->lsm_object_gr);
1823 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1824 struct lov_stripe_md submd;
1825 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
1828 if (!lov->lov_tgts[loi->loi_ost_idx]) {
1829 CDEBUG(D_HA, "lov idx %d NULL\n", loi->loi_ost_idx);
1833 if (!lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
1834 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1836 submd.lsm_object_id = loi->loi_id;
1837 submd.lsm_object_gr = lsm->lsm_object_gr;
1838 submd.lsm_stripe_count = 0;
1839 err = obd_cancel_unused(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1840 &submd, flags, opaque);
1841 if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1842 CERROR("error: cancel unused objid "LPX64" subobj "LPX64
1843 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
1844 loi->loi_id, loi->loi_ost_idx, err);
1852 static int lov_statfs_interpret(struct ptlrpc_request_set *rqset,
1855 struct lov_request_set *lovset = (struct lov_request_set *)data;
1860 lovset->set_completes = 0;
1862 err = lov_fini_statfs_set(lovset);
1863 RETURN(rc ? rc : err);
1866 static int lov_statfs_async(struct obd_device *obd, struct obd_info *oinfo,
1867 __u64 max_age, struct ptlrpc_request_set *rqset)
1869 struct lov_request_set *set;
1870 struct lov_request *req;
1871 struct list_head *pos;
1872 struct lov_obd *lov;
1876 LASSERT(oinfo != NULL);
1877 LASSERT(oinfo->oi_osfs != NULL);
1880 rc = lov_prep_statfs_set(obd, oinfo, &set);
1884 list_for_each (pos, &set->set_list) {
1885 struct obd_device *osc_obd;
1887 req = list_entry(pos, struct lov_request, rq_link);
1889 osc_obd = class_exp2obd(lov->lov_tgts[req->rq_idx]->ltd_exp);
1890 rc = obd_statfs_async(osc_obd, &req->rq_oi, max_age, rqset);
1895 if (rc || list_empty(&rqset->set_requests)) {
1898 set->set_completes = 0;
1899 err = lov_fini_statfs_set(set);
1900 RETURN(rc ? rc : err);
1903 LASSERT(rqset->set_interpret == NULL);
1904 rqset->set_interpret = lov_statfs_interpret;
1905 rqset->set_arg = (void *)set;
1909 static int lov_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1910 __u64 max_age, __u32 flags)
1912 struct ptlrpc_request_set *set = NULL;
1913 struct obd_info oinfo = { { { 0 } } };
1918 /* for obdclass we forbid using obd_statfs_rqset, but prefer using async
1919 * statfs requests */
1920 set = ptlrpc_prep_set();
1924 oinfo.oi_osfs = osfs;
1925 oinfo.oi_flags = flags;
1926 rc = lov_statfs_async(obd, &oinfo, max_age, set);
1928 rc = ptlrpc_set_wait(set);
1929 ptlrpc_set_destroy(set);
1934 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1935 void *karg, void *uarg)
1937 struct obd_device *obddev = class_exp2obd(exp);
1938 struct lov_obd *lov = &obddev->u.lov;
1939 int i = 0, rc = 0, count = lov->desc.ld_tgt_count;
1940 struct obd_uuid *uuidp;
1944 case IOC_OBD_STATFS: {
1945 struct obd_ioctl_data *data = karg;
1946 struct obd_device *osc_obd;
1947 struct obd_statfs stat_buf = {0};
1950 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
1951 LASSERT(data->ioc_plen1 == sizeof(struct obd_statfs));
1953 if ((index >= count))
1956 if (!lov->lov_tgts[index])
1957 /* Try again with the next index */
1959 if (!lov->lov_tgts[index]->ltd_active)
1962 osc_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
1966 /* got statfs data */
1967 rc = obd_statfs(osc_obd, &stat_buf,
1968 cfs_time_current_64() - HZ, 0);
1971 if (copy_to_user(data->ioc_pbuf1, &stat_buf, data->ioc_plen1))
1974 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(osc_obd),
1979 case OBD_IOC_LOV_GET_CONFIG: {
1980 struct obd_ioctl_data *data;
1981 struct lov_desc *desc;
1986 if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
1989 data = (struct obd_ioctl_data *)buf;
1991 if (sizeof(*desc) > data->ioc_inllen1) {
1992 obd_ioctl_freedata(buf, len);
1996 if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
1997 obd_ioctl_freedata(buf, len);
2001 if (sizeof(__u32) * count > data->ioc_inllen3) {
2002 obd_ioctl_freedata(buf, len);
2006 desc = (struct lov_desc *)data->ioc_inlbuf1;
2007 memcpy(desc, &(lov->desc), sizeof(*desc));
2009 uuidp = (struct obd_uuid *)data->ioc_inlbuf2;
2010 genp = (__u32 *)data->ioc_inlbuf3;
2011 /* the uuid will be empty for deleted OSTs */
2012 for (i = 0; i < count; i++, uuidp++, genp++) {
2013 if (!lov->lov_tgts[i])
2015 *uuidp = lov->lov_tgts[i]->ltd_uuid;
2016 *genp = lov->lov_tgts[i]->ltd_gen;
2019 if (copy_to_user((void *)uarg, buf, len))
2021 obd_ioctl_freedata(buf, len);
2024 case LL_IOC_LOV_SETSTRIPE:
2025 rc = lov_setstripe(exp, karg, uarg);
2027 case LL_IOC_LOV_GETSTRIPE:
2028 rc = lov_getstripe(exp, karg, uarg);
2030 case LL_IOC_LOV_SETEA:
2031 rc = lov_setea(exp, karg, uarg);
2033 case OBD_IOC_QUOTACTL: {
2034 struct if_quotactl *qctl = karg;
2035 struct lov_tgt_desc *tgt = NULL;
2036 struct obd_quotactl *oqctl;
2038 if (qctl->qc_valid == QC_OSTIDX) {
2039 if (qctl->qc_idx < 0 || count <= qctl->qc_idx)
2042 tgt = lov->lov_tgts[qctl->qc_idx];
2043 if (!tgt || !tgt->ltd_exp)
2045 } else if (qctl->qc_valid == QC_UUID) {
2046 for (i = 0; i < count; i++) {
2047 tgt = lov->lov_tgts[i];
2049 !obd_uuid_equals(&tgt->ltd_uuid,
2053 if (tgt->ltd_exp == NULL)
2065 LASSERT(tgt && tgt->ltd_exp);
2066 OBD_ALLOC_PTR(oqctl);
2070 QCTL_COPY(oqctl, qctl);
2071 rc = obd_quotactl(tgt->ltd_exp, oqctl);
2073 QCTL_COPY(qctl, oqctl);
2074 qctl->qc_valid = QC_OSTIDX;
2075 qctl->obd_uuid = tgt->ltd_uuid;
2077 OBD_FREE_PTR(oqctl);
2086 for (i = 0; i < count; i++) {
2089 /* OST was disconnected */
2090 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2093 err = obd_iocontrol(cmd, lov->lov_tgts[i]->ltd_exp,
2095 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
2098 if (lov->lov_tgts[i]->ltd_active) {
2099 CDEBUG(err == -ENOTTY ?
2100 D_IOCTL : D_WARNING,
2101 "iocontrol OSC %s on OST "
2102 "idx %d cmd %x: err = %d\n",
2103 lov_uuid2str(lov, i),
2120 #define FIEMAP_BUFFER_SIZE 4096
2123 * Non-zero fe_logical indicates that this is a continuation FIEMAP
2124 * call. The local end offset and the device are sent in the first
2125 * fm_extent. This function calculates the stripe number from the index.
2126 * This function returns a stripe_no on which mapping is to be restarted.
2128 * This function returns fm_end_offset which is the in-OST offset at which
2129 * mapping should be restarted. If fm_end_offset=0 is returned then caller
2130 * will re-calculate proper offset in next stripe.
2131 * Note that the first extent is passed to lov_get_info via the value field.
2133 * \param fiemap fiemap request header
2134 * \param lsm striping information for the file
2135 * \param fm_start logical start of mapping
2136 * \param fm_end logical end of mapping
2137 * \param start_stripe starting stripe will be returned in this
2139 obd_size fiemap_calc_fm_end_offset(struct ll_user_fiemap *fiemap,
2140 struct lov_stripe_md *lsm, obd_size fm_start,
2141 obd_size fm_end, int *start_stripe)
2143 obd_size local_end = fiemap->fm_extents[0].fe_logical;
2144 obd_off lun_start, lun_end;
2145 obd_size fm_end_offset;
2146 int stripe_no = -1, i;
2148 if (fiemap->fm_extent_count == 0 ||
2149 fiemap->fm_extents[0].fe_logical == 0)
2152 /* Find out stripe_no from ost_index saved in the fe_device */
2153 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2154 if (lsm->lsm_oinfo[i]->loi_ost_idx ==
2155 fiemap->fm_extents[0].fe_device) {
2161 /* If we have finished mapping on previous device, shift logical
2162 * offset to start of next device */
2163 if ((lov_stripe_intersects(lsm, stripe_no, fm_start, fm_end,
2164 &lun_start, &lun_end)) != 0 &&
2165 local_end < lun_end) {
2166 fm_end_offset = local_end;
2167 *start_stripe = stripe_no;
2169 /* This is a special value to indicate that caller should
2170 * calculate offset in next stripe. */
2172 *start_stripe = (stripe_no + 1) % lsm->lsm_stripe_count;
2175 return fm_end_offset;
2179 * We calculate on which OST the mapping will end. If the length of mapping
2180 * is greater than (stripe_size * stripe_count) then the last_stripe will
2181 * will be one just before start_stripe. Else we check if the mapping
2182 * intersects each OST and find last_stripe.
2183 * This function returns the last_stripe and also sets the stripe_count
2184 * over which the mapping is spread
2186 * \param lsm striping information for the file
2187 * \param fm_start logical start of mapping
2188 * \param fm_end logical end of mapping
2189 * \param start_stripe starting stripe of the mapping
2190 * \param stripe_count the number of stripes across which to map is returned
2192 * \retval last_stripe return the last stripe of the mapping
2194 int fiemap_calc_last_stripe(struct lov_stripe_md *lsm, obd_size fm_start,
2195 obd_size fm_end, int start_stripe,
2199 obd_off obd_start, obd_end;
2202 if (fm_end - fm_start > lsm->lsm_stripe_size * lsm->lsm_stripe_count) {
2203 last_stripe = (start_stripe < 1 ? lsm->lsm_stripe_count - 1 :
2205 *stripe_count = lsm->lsm_stripe_count;
2207 for (j = 0, i = start_stripe; j < lsm->lsm_stripe_count;
2208 i = (i + 1) % lsm->lsm_stripe_count, j++) {
2209 if ((lov_stripe_intersects(lsm, i, fm_start, fm_end,
2210 &obd_start, &obd_end)) == 0)
2214 last_stripe = (start_stripe + j - 1) %lsm->lsm_stripe_count;
2221 * Set fe_device and copy extents from local buffer into main return buffer.
2223 * \param fiemap fiemap request header
2224 * \param lcl_fm_ext array of local fiemap extents to be copied
2225 * \param ost_index OST index to be written into the fm_device field for each
2227 * \param ext_count number of extents to be copied
2228 * \param current_extent where to start copying in main extent array
2230 void fiemap_prepare_and_copy_exts(struct ll_user_fiemap *fiemap,
2231 struct ll_fiemap_extent *lcl_fm_ext,
2232 int ost_index, unsigned int ext_count,
2238 for (ext = 0; ext < ext_count; ext++) {
2239 lcl_fm_ext[ext].fe_device = ost_index;
2240 lcl_fm_ext[ext].fe_flags |= FIEMAP_EXTENT_NET;
2243 /* Copy fm_extent's from fm_local to return buffer */
2244 to = (char *)fiemap + fiemap_count_to_size(current_extent);
2245 memcpy(to, lcl_fm_ext, ext_count * sizeof(struct ll_fiemap_extent));
2249 * Break down the FIEMAP request and send appropriate calls to individual OSTs.
2250 * This also handles the restarting of FIEMAP calls in case mapping overflows
2251 * the available number of extents in single call.
2253 static int lov_fiemap(struct lov_obd *lov, __u32 keylen, void *key,
2254 __u32 *vallen, void *val, struct lov_stripe_md *lsm)
2256 struct ll_fiemap_info_key *fm_key = key;
2257 struct ll_user_fiemap *fiemap = val;
2258 struct ll_user_fiemap *fm_local = NULL;
2259 struct ll_fiemap_extent *lcl_fm_ext;
2261 unsigned int get_num_extents = 0;
2262 int ost_index = 0, actual_start_stripe, start_stripe;
2263 obd_size fm_start, fm_end, fm_length, fm_end_offset = 0;
2265 int current_extent = 0, rc = 0, i;
2266 int ost_eof = 0; /* EOF for object */
2267 int ost_done = 0; /* done with required mapping for this OST? */
2269 int cur_stripe = 0, cur_stripe_wrap = 0, stripe_count;
2270 unsigned int buffer_size = FIEMAP_BUFFER_SIZE;
2275 if (fiemap_count_to_size(fm_key->fiemap.fm_extent_count) < buffer_size)
2276 buffer_size = fiemap_count_to_size(fm_key->fiemap.fm_extent_count);
2278 OBD_ALLOC(fm_local, buffer_size);
2279 if (fm_local == NULL)
2280 GOTO(out, rc = -ENOMEM);
2281 lcl_fm_ext = &fm_local->fm_extents[0];
2283 count_local = fiemap_size_to_count(buffer_size);
2285 memcpy(fiemap, &fm_key->fiemap, sizeof(*fiemap));
2286 fm_start = fiemap->fm_start;
2287 fm_length = fiemap->fm_length;
2288 /* Calculate start stripe, last stripe and length of mapping */
2289 actual_start_stripe = start_stripe = lov_stripe_number(lsm, fm_start);
2290 fm_end = (fm_length == ~0ULL ? fm_key->oa.o_size :
2291 fm_start + fm_length - 1);
2292 /* If fm_length != ~0ULL but fm_start+fm_length-1 exceeds file size */
2293 if (fm_end > fm_key->oa.o_size)
2294 fm_end = fm_key->oa.o_size;
2296 last_stripe = fiemap_calc_last_stripe(lsm, fm_start, fm_end,
2297 actual_start_stripe, &stripe_count);
2299 fm_end_offset = fiemap_calc_fm_end_offset(fiemap, lsm, fm_start, fm_end,
2302 if (fiemap->fm_extent_count == 0) {
2303 get_num_extents = 1;
2307 /* Check each stripe */
2308 for (cur_stripe = start_stripe, i = 0; i < stripe_count;
2309 i++, cur_stripe = (cur_stripe + 1) % lsm->lsm_stripe_count) {
2310 obd_size req_fm_len; /* Stores length of required mapping */
2311 obd_size len_mapped_single_call;
2312 obd_off lun_start, lun_end, obd_object_end;
2313 unsigned int ext_count;
2315 cur_stripe_wrap = cur_stripe;
2317 /* Find out range of mapping on this stripe */
2318 if ((lov_stripe_intersects(lsm, cur_stripe, fm_start, fm_end,
2319 &lun_start, &obd_object_end)) == 0)
2322 /* If this is a continuation FIEMAP call and we are on
2323 * starting stripe then lun_start needs to be set to
2325 if (fm_end_offset != 0 && cur_stripe == start_stripe)
2326 lun_start = fm_end_offset;
2328 if (fm_length != ~0ULL) {
2329 /* Handle fm_start + fm_length overflow */
2330 if (fm_start + fm_length < fm_start)
2331 fm_length = ~0ULL - fm_start;
2332 lun_end = lov_size_to_stripe(lsm, fm_start + fm_length,
2338 if (lun_start == lun_end)
2341 req_fm_len = obd_object_end - lun_start;
2342 fm_local->fm_length = 0;
2343 len_mapped_single_call = 0;
2345 /* If the output buffer is very large and the objects have many
2346 * extents we may need to loop on a single OST repeatedly */
2350 if (get_num_extents == 0) {
2351 /* Don't get too many extents. */
2352 if (current_extent + count_local >
2353 fiemap->fm_extent_count)
2354 count_local = fiemap->fm_extent_count -
2358 lun_start += len_mapped_single_call;
2359 fm_local->fm_length = req_fm_len - len_mapped_single_call;
2360 req_fm_len = fm_local->fm_length;
2361 fm_local->fm_extent_count = count_local;
2362 fm_local->fm_mapped_extents = 0;
2363 fm_local->fm_flags = fiemap->fm_flags;
2365 fm_key->oa.o_id = lsm->lsm_oinfo[cur_stripe]->loi_id;
2366 ost_index = lsm->lsm_oinfo[cur_stripe]->loi_ost_idx;
2368 if (ost_index < 0 || ost_index >=lov->desc.ld_tgt_count)
2369 GOTO(out, rc = -EINVAL);
2371 /* If OST is inactive, return extent with UNKNOWN flag */
2372 if (lov && !lov->lov_tgts[ost_index]->ltd_active) {
2373 fm_local->fm_flags |= FIEMAP_EXTENT_LAST;
2374 fm_local->fm_mapped_extents = 1;
2376 lcl_fm_ext[0].fe_logical = lun_start;
2377 lcl_fm_ext[0].fe_length = obd_object_end -
2379 lcl_fm_ext[0].fe_flags |= FIEMAP_EXTENT_UNKNOWN;
2384 fm_local->fm_start = lun_start;
2385 fm_local->fm_flags &= ~FIEMAP_FLAG_DEVICE_ORDER;
2386 memcpy(&fm_key->fiemap, fm_local, sizeof(*fm_local));
2387 *vallen=fiemap_count_to_size(fm_local->fm_extent_count);
2388 rc = obd_get_info(lov->lov_tgts[ost_index]->ltd_exp,
2389 keylen, key, vallen, fm_local, lsm);
2394 ext_count = fm_local->fm_mapped_extents;
2395 if (ext_count == 0) {
2397 /* If last stripe has hole at the end,
2398 * then we need to return */
2399 if (cur_stripe_wrap == last_stripe) {
2400 fiemap->fm_mapped_extents = 0;
2406 /* If we just need num of extents then go to next device */
2407 if (get_num_extents) {
2408 current_extent += ext_count;
2412 len_mapped_single_call = lcl_fm_ext[ext_count-1].fe_logical -
2413 lun_start + lcl_fm_ext[ext_count - 1].fe_length;
2415 /* Have we finished mapping on this device? */
2416 if (req_fm_len <= len_mapped_single_call)
2419 /* Clear the EXTENT_LAST flag which can be present on
2421 if (lcl_fm_ext[ext_count-1].fe_flags & FIEMAP_EXTENT_LAST)
2422 lcl_fm_ext[ext_count - 1].fe_flags &=
2423 ~FIEMAP_EXTENT_LAST;
2425 curr_loc = lov_stripe_size(lsm,
2426 lcl_fm_ext[ext_count - 1].fe_logical+
2427 lcl_fm_ext[ext_count - 1].fe_length,
2429 if (curr_loc >= fm_key->oa.o_size)
2432 fiemap_prepare_and_copy_exts(fiemap, lcl_fm_ext,
2433 ost_index, ext_count,
2436 current_extent += ext_count;
2438 /* Ran out of available extents? */
2439 if (current_extent >= fiemap->fm_extent_count)
2441 } while (ost_done == 0 && ost_eof == 0);
2443 if (cur_stripe_wrap == last_stripe)
2448 /* Indicate that we are returning device offsets unless file just has
2450 if (lsm->lsm_stripe_count > 1)
2451 fiemap->fm_flags |= FIEMAP_FLAG_DEVICE_ORDER;
2453 if (get_num_extents)
2454 goto skip_last_device_calc;
2456 /* Check if we have reached the last stripe and whether mapping for that
2457 * stripe is done. */
2458 if (cur_stripe_wrap == last_stripe) {
2459 if (ost_done || ost_eof)
2460 fiemap->fm_extents[current_extent - 1].fe_flags |=
2464 skip_last_device_calc:
2465 fiemap->fm_mapped_extents = current_extent;
2468 OBD_FREE(fm_local, buffer_size);
2472 static int lov_get_info(struct obd_export *exp, __u32 keylen,
2473 void *key, __u32 *vallen, void *val,
2474 struct lov_stripe_md *lsm)
2476 struct obd_device *obddev = class_exp2obd(exp);
2477 struct lov_obd *lov = &obddev->u.lov;
2481 if (!vallen || !val)
2486 if (KEY_IS(KEY_LOCK_TO_STRIPE)) {
2489 struct ldlm_lock *lock;
2491 struct ldlm_res_id *res_id = &data->lock->l_resource->lr_name;
2492 struct lov_oinfo *loi;
2493 __u32 *stripe = val;
2495 if (*vallen < sizeof(*stripe))
2496 GOTO(out, rc = -EFAULT);
2497 *vallen = sizeof(*stripe);
2499 /* XXX This is another one of those bits that will need to
2500 * change if we ever actually support nested LOVs. It uses
2501 * the lock's export to find out which stripe it is. */
2502 /* XXX - it's assumed all the locks for deleted OSTs have
2503 * been cancelled. Also, the export for deleted OSTs will
2504 * be NULL and won't match the lock's export. */
2505 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2506 loi = lsm->lsm_oinfo[i];
2507 if (!lov->lov_tgts[loi->loi_ost_idx])
2509 if (lov->lov_tgts[loi->loi_ost_idx]->ltd_exp ==
2510 data->lock->l_conn_export &&
2511 osc_res_name_eq(loi->loi_id, loi->loi_gr, res_id)) {
2516 LDLM_ERROR(data->lock, "lock on inode without such object");
2517 dump_lsm(D_ERROR, lsm);
2518 GOTO(out, rc = -ENXIO);
2519 } else if (KEY_IS(KEY_LAST_ID)) {
2520 struct obd_id_info *info = val;
2521 __u32 size = sizeof(obd_id);
2522 struct lov_tgt_desc *tgt;
2524 LASSERT(*vallen == sizeof(struct obd_id_info));
2525 tgt = lov->lov_tgts[info->idx];
2527 if (!tgt || !tgt->ltd_active)
2528 GOTO(out, rc = -ESRCH);
2530 rc = obd_get_info(tgt->ltd_exp, keylen, key, &size, info->data, NULL);
2532 } else if (KEY_IS(KEY_LOVDESC)) {
2533 struct lov_desc *desc_ret = val;
2534 *desc_ret = lov->desc;
2537 } else if (KEY_IS(KEY_FIEMAP)) {
2538 rc = lov_fiemap(lov, keylen, key, vallen, val, lsm);
2549 static int lov_set_info_async(struct obd_export *exp, obd_count keylen,
2550 void *key, obd_count vallen, void *val,
2551 struct ptlrpc_request_set *set)
2553 struct obd_device *obddev = class_exp2obd(exp);
2554 struct lov_obd *lov = &obddev->u.lov;
2557 struct lov_tgt_desc *tgt;
2558 unsigned incr, check_uuid,
2559 do_inactive, no_set;
2560 unsigned next_id = 0, mds_con = 0;
2563 incr = check_uuid = do_inactive = no_set = 0;
2566 set = ptlrpc_prep_set();
2572 count = lov->desc.ld_tgt_count;
2574 if (KEY_IS(KEY_NEXT_ID)) {
2575 count = vallen / sizeof(struct obd_id_info);
2576 vallen = sizeof(obd_id);
2577 incr = sizeof(struct obd_id_info);
2580 } else if (KEY_IS(KEY_CHECKSUM)) {
2582 } else if (KEY_IS(KEY_UNLINKED)) {
2583 check_uuid = val ? 1 : 0;
2584 } else if (KEY_IS(KEY_EVICT_BY_NID)) {
2585 /* use defaults: do_inactive = incr = 0; */
2586 } else if (KEY_IS(KEY_MDS_CONN)) {
2590 for (i = 0; i < count; i++, val = (char *)val + incr) {
2592 tgt = lov->lov_tgts[((struct obd_id_info*)val)->idx];
2594 tgt = lov->lov_tgts[i];
2596 /* OST was disconnected */
2597 if (!tgt || !tgt->ltd_exp)
2600 /* OST is inactive and we don't want inactive OSCs */
2601 if (!tgt->ltd_active && !do_inactive)
2605 struct mds_group_info *mgi;
2607 LASSERT(vallen == sizeof(*mgi));
2608 mgi = (struct mds_group_info *)val;
2610 /* Only want a specific OSC */
2611 if (mgi->uuid && !obd_uuid_equals(mgi->uuid,
2615 err = obd_set_info_async(tgt->ltd_exp,
2616 keylen, key, sizeof(int),
2618 } else if (next_id) {
2619 err = obd_set_info_async(tgt->ltd_exp,
2620 keylen, key, vallen,
2621 ((struct obd_id_info*)val)->data, set);
2623 /* Only want a specific OSC */
2625 !obd_uuid_equals(val, &tgt->ltd_uuid))
2628 err = obd_set_info_async(tgt->ltd_exp,
2629 keylen, key, vallen, val, set);
2638 err = ptlrpc_set_wait(set);
2641 ptlrpc_set_destroy(set);
2646 static int lov_checkmd(struct obd_export *exp, struct obd_export *md_exp,
2647 struct lov_stripe_md *lsm)
2655 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
2656 rc = lsm_op_find(lsm->lsm_magic)->lsm_revalidate(lsm, md_exp->exp_obd);
2661 int lov_test_and_clear_async_rc(struct lov_stripe_md *lsm)
2666 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2667 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
2668 if (loi->loi_ar.ar_rc && !rc)
2669 rc = loi->loi_ar.ar_rc;
2670 loi->loi_ar.ar_rc = 0;
2674 EXPORT_SYMBOL(lov_test_and_clear_async_rc);
2677 static int lov_extent_calc(struct obd_export *exp, struct lov_stripe_md *lsm,
2678 int cmd, __u64 *offset)
2680 __u32 ssize = lsm->lsm_stripe_size;
2684 do_div(start, ssize);
2685 start = start * ssize;
2687 CDEBUG(D_DLMTRACE, "offset "LPU64", stripe %u, start "LPU64
2688 ", end "LPU64"\n", *offset, ssize, start,
2690 if (cmd == OBD_CALC_STRIPE_END) {
2691 *offset = start + ssize - 1;
2692 } else if (cmd == OBD_CALC_STRIPE_START) {
2701 void lov_stripe_lock(struct lov_stripe_md *md)
2703 LASSERT(md->lsm_lock_owner != cfs_curproc_pid());
2704 spin_lock(&md->lsm_lock);
2705 LASSERT(md->lsm_lock_owner == 0);
2706 md->lsm_lock_owner = cfs_curproc_pid();
2708 EXPORT_SYMBOL(lov_stripe_lock);
2710 void lov_stripe_unlock(struct lov_stripe_md *md)
2712 LASSERT(md->lsm_lock_owner == cfs_curproc_pid());
2713 md->lsm_lock_owner = 0;
2714 spin_unlock(&md->lsm_lock);
2716 EXPORT_SYMBOL(lov_stripe_unlock);
2719 struct obd_ops lov_obd_ops = {
2720 .o_owner = THIS_MODULE,
2721 .o_setup = lov_setup,
2722 .o_precleanup = lov_precleanup,
2723 .o_cleanup = lov_cleanup,
2724 //.o_process_config = lov_process_config,
2725 .o_connect = lov_connect,
2726 .o_disconnect = lov_disconnect,
2727 .o_statfs = lov_statfs,
2728 .o_statfs_async = lov_statfs_async,
2729 .o_packmd = lov_packmd,
2730 .o_unpackmd = lov_unpackmd,
2731 .o_checkmd = lov_checkmd,
2732 .o_create = lov_create,
2733 .o_destroy = lov_destroy,
2734 .o_getattr = lov_getattr,
2735 .o_getattr_async = lov_getattr_async,
2736 .o_setattr = lov_setattr,
2737 .o_setattr_async = lov_setattr_async,
2739 .o_merge_lvb = lov_merge_lvb,
2740 .o_adjust_kms = lov_adjust_kms,
2741 .o_punch = lov_punch,
2743 .o_enqueue = lov_enqueue,
2744 .o_change_cbdata = lov_change_cbdata,
2745 .o_cancel = lov_cancel,
2746 .o_cancel_unused = lov_cancel_unused,
2747 .o_iocontrol = lov_iocontrol,
2748 .o_get_info = lov_get_info,
2749 .o_set_info_async = lov_set_info_async,
2750 .o_extent_calc = lov_extent_calc,
2751 .o_llog_init = lov_llog_init,
2752 .o_llog_finish = lov_llog_finish,
2753 .o_notify = lov_notify,
2754 .o_pool_new = lov_pool_new,
2755 .o_pool_rem = lov_pool_remove,
2756 .o_pool_add = lov_pool_add,
2757 .o_pool_del = lov_pool_del,
2760 static quota_interface_t *quota_interface;
2761 extern quota_interface_t lov_quota_interface;
2763 cfs_mem_cache_t *lov_oinfo_slab;
2765 extern struct lu_kmem_descr lov_caches[];
2767 int __init lov_init(void)
2769 struct lprocfs_static_vars lvars = { 0 };
2773 /* print an address of _any_ initialized kernel symbol from this
2774 * module, to allow debugging with gdb that doesn't support data
2775 * symbols from modules.*/
2776 CDEBUG(D_CONSOLE, "Lustre LOV module (%p).\n", &lov_caches);
2778 rc = lu_kmem_init(lov_caches);
2782 lov_oinfo_slab = cfs_mem_cache_create("lov_oinfo",
2783 sizeof(struct lov_oinfo),
2784 0, SLAB_HWCACHE_ALIGN);
2785 if (lov_oinfo_slab == NULL) {
2786 lu_kmem_fini(lov_caches);
2789 lprocfs_lov_init_vars(&lvars);
2791 request_module("lquota");
2792 quota_interface = PORTAL_SYMBOL_GET(lov_quota_interface);
2793 init_obd_quota_ops(quota_interface, &lov_obd_ops);
2795 rc = class_register_type(&lov_obd_ops, NULL, lvars.module_vars,
2796 LUSTRE_LOV_NAME, &lov_device_type);
2799 if (quota_interface)
2800 PORTAL_SYMBOL_PUT(lov_quota_interface);
2801 rc2 = cfs_mem_cache_destroy(lov_oinfo_slab);
2803 lu_kmem_fini(lov_caches);
2810 static void /*__exit*/ lov_exit(void)
2814 lu_device_type_fini(&lov_device_type);
2815 lu_kmem_fini(lov_caches);
2817 if (quota_interface)
2818 PORTAL_SYMBOL_PUT(lov_quota_interface);
2820 class_unregister_type(LUSTRE_LOV_NAME);
2821 rc = cfs_mem_cache_destroy(lov_oinfo_slab);
2825 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2826 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver");
2827 MODULE_LICENSE("GPL");
2829 cfs_module(lov, LUSTRE_VERSION_STRING, lov_init, lov_exit);