4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2013, Intel Corporation.
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>
44 #define DEBUG_SUBSYSTEM S_LOV
46 #include <libcfs/libcfs.h>
48 #include <liblustre.h>
51 #include <obd_support.h>
52 #include <lustre_lib.h>
53 #include <lustre_net.h>
54 #include <lustre/lustre_idl.h>
55 #include <lustre_dlm.h>
56 #include <lustre_mds.h>
57 #include <lustre_debug.h>
58 #include <obd_class.h>
61 #include <lprocfs_status.h>
62 #include <lustre_param.h>
63 #include <cl_object.h>
65 #include <lustre/ll_fiemap.h>
66 #include <lustre_fid.h>
68 #include "lov_internal.h"
70 /* Keep a refcount of lov->tgt usage to prevent racing with addition/deletion.
71 Any function that expects lov_tgts to remain stationary must take a ref. */
72 static void lov_getref(struct obd_device *obd)
74 struct lov_obd *lov = &obd->u.lov;
76 /* nobody gets through here until lov_putref is done */
77 mutex_lock(&lov->lov_lock);
78 cfs_atomic_inc(&lov->lov_refcount);
79 mutex_unlock(&lov->lov_lock);
83 static void __lov_del_obd(struct obd_device *obd, struct lov_tgt_desc *tgt);
85 static void lov_putref(struct obd_device *obd)
87 struct lov_obd *lov = &obd->u.lov;
89 mutex_lock(&lov->lov_lock);
90 /* ok to dec to 0 more than once -- ltd_exp's will be null */
91 if (cfs_atomic_dec_and_test(&lov->lov_refcount) && lov->lov_death_row) {
94 struct lov_tgt_desc *tgt, *n;
95 CDEBUG(D_CONFIG, "destroying %d lov targets\n",
97 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
98 tgt = lov->lov_tgts[i];
100 if (!tgt || !tgt->ltd_reap)
102 cfs_list_add(&tgt->ltd_kill, &kill);
103 /* XXX - right now there is a dependency on ld_tgt_count
104 * being the maximum tgt index for computing the
105 * mds_max_easize. So we can't shrink it. */
106 lov_ost_pool_remove(&lov->lov_packed, i);
107 lov->lov_tgts[i] = NULL;
108 lov->lov_death_row--;
110 mutex_unlock(&lov->lov_lock);
112 cfs_list_for_each_entry_safe(tgt, n, &kill, ltd_kill) {
113 cfs_list_del(&tgt->ltd_kill);
115 __lov_del_obd(obd, tgt);
118 mutex_unlock(&lov->lov_lock);
122 static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
123 enum obd_notify_event ev);
124 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
125 enum obd_notify_event ev, void *data);
128 #define MAX_STRING_SIZE 128
129 int lov_connect_obd(struct obd_device *obd, __u32 index, int activate,
130 struct obd_connect_data *data)
132 struct lov_obd *lov = &obd->u.lov;
133 struct obd_uuid *tgt_uuid;
134 struct obd_device *tgt_obd;
135 static struct obd_uuid lov_osc_uuid = { "LOV_OSC_UUID" };
136 struct obd_import *imp;
138 struct proc_dir_entry *lov_proc_dir;
143 if (!lov->lov_tgts[index])
146 tgt_uuid = &lov->lov_tgts[index]->ltd_uuid;
147 tgt_obd = lov->lov_tgts[index]->ltd_obd;
149 if (!tgt_obd->obd_set_up) {
150 CERROR("Target %s not set up\n", obd_uuid2str(tgt_uuid));
154 /* override the sp_me from lov */
155 tgt_obd->u.cli.cl_sp_me = lov->lov_sp_me;
157 if (data && (data->ocd_connect_flags & OBD_CONNECT_INDEX))
158 data->ocd_index = index;
161 * Divine LOV knows that OBDs under it are OSCs.
163 imp = tgt_obd->u.cli.cl_import;
166 tgt_obd->obd_no_recov = 0;
167 /* FIXME this is probably supposed to be
168 ptlrpc_set_import_active. Horrible naming. */
169 ptlrpc_activate_import(imp);
172 rc = obd_register_observer(tgt_obd, obd);
174 CERROR("Target %s register_observer error %d\n",
175 obd_uuid2str(tgt_uuid), rc);
180 if (imp->imp_invalid) {
181 CDEBUG(D_CONFIG, "not connecting OSC %s; administratively "
182 "disabled\n", obd_uuid2str(tgt_uuid));
186 rc = obd_connect(NULL, &lov->lov_tgts[index]->ltd_exp, tgt_obd,
187 &lov_osc_uuid, data, NULL);
188 if (rc || !lov->lov_tgts[index]->ltd_exp) {
189 CERROR("Target %s connect error %d\n",
190 obd_uuid2str(tgt_uuid), rc);
194 lov->lov_tgts[index]->ltd_reap = 0;
196 CDEBUG(D_CONFIG, "Connected tgt idx %d %s (%s) %sactive\n", index,
197 obd_uuid2str(tgt_uuid), tgt_obd->obd_name, activate ? "":"in");
200 lov_proc_dir = obd->obd_proc_private;
202 struct obd_device *osc_obd = lov->lov_tgts[index]->ltd_exp->exp_obd;
203 struct proc_dir_entry *osc_symlink;
205 LASSERT(osc_obd != NULL);
206 LASSERT(osc_obd->obd_magic == OBD_DEVICE_MAGIC);
207 LASSERT(osc_obd->obd_type->typ_name != NULL);
209 osc_symlink = lprocfs_add_symlink(osc_obd->obd_name,
212 osc_obd->obd_type->typ_name,
214 if (osc_symlink == NULL) {
215 CERROR("could not register LOV target "
216 "/proc/fs/lustre/%s/%s/target_obds/%s.",
217 obd->obd_type->typ_name, obd->obd_name,
219 lprocfs_remove(&lov_proc_dir);
220 obd->obd_proc_private = NULL;
228 static int lov_connect(const struct lu_env *env,
229 struct obd_export **exp, struct obd_device *obd,
230 struct obd_uuid *cluuid, struct obd_connect_data *data,
233 struct lov_obd *lov = &obd->u.lov;
234 struct lov_tgt_desc *tgt;
235 struct lustre_handle conn;
239 CDEBUG(D_CONFIG, "connect #%d\n", lov->lov_connects);
241 rc = class_connect(&conn, obd, cluuid);
245 *exp = class_conn2export(&conn);
247 /* Why should there ever be more than 1 connect? */
249 LASSERT(lov->lov_connects == 1);
251 memset(&lov->lov_ocd, 0, sizeof(lov->lov_ocd));
253 lov->lov_ocd = *data;
256 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
257 tgt = lov->lov_tgts[i];
258 if (!tgt || obd_uuid_empty(&tgt->ltd_uuid))
260 /* Flags will be lowest common denominator */
261 rc = lov_connect_obd(obd, i, tgt->ltd_activate, &lov->lov_ocd);
263 CERROR("%s: lov connect tgt %d failed: %d\n",
264 obd->obd_name, i, rc);
267 /* connect to administrative disabled ost */
268 if (!lov->lov_tgts[i]->ltd_exp)
271 rc = lov_notify(obd, lov->lov_tgts[i]->ltd_exp->exp_obd,
272 OBD_NOTIFY_CONNECT, (void *)&i);
274 CERROR("%s error sending notify %d\n",
283 static int lov_disconnect_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
285 struct proc_dir_entry *lov_proc_dir;
286 struct lov_obd *lov = &obd->u.lov;
287 struct obd_device *osc_obd;
291 osc_obd = class_exp2obd(tgt->ltd_exp);
292 CDEBUG(D_CONFIG, "%s: disconnecting target %s\n",
293 obd->obd_name, osc_obd->obd_name);
295 if (tgt->ltd_active) {
297 lov->desc.ld_active_tgt_count--;
298 tgt->ltd_exp->exp_obd->obd_inactive = 1;
301 lov_proc_dir = obd->obd_proc_private;
303 lprocfs_remove_proc_entry(osc_obd->obd_name, lov_proc_dir);
306 /* Pass it on to our clients.
307 * XXX This should be an argument to disconnect,
308 * XXX not a back-door flag on the OBD. Ah well.
310 osc_obd->obd_force = obd->obd_force;
311 osc_obd->obd_fail = obd->obd_fail;
312 osc_obd->obd_no_recov = obd->obd_no_recov;
315 obd_register_observer(osc_obd, NULL);
317 rc = obd_disconnect(tgt->ltd_exp);
319 CERROR("Target %s disconnect error %d\n",
320 tgt->ltd_uuid.uuid, rc);
328 static int lov_disconnect(struct obd_export *exp)
330 struct obd_device *obd = class_exp2obd(exp);
331 struct lov_obd *lov = &obd->u.lov;
338 /* Only disconnect the underlying layers on the final disconnect. */
340 if (lov->lov_connects != 0) {
341 /* why should there be more than 1 connect? */
342 CERROR("disconnect #%d\n", lov->lov_connects);
346 /* Let's hold another reference so lov_del_obd doesn't spin through
350 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
351 if (lov->lov_tgts[i] && lov->lov_tgts[i]->ltd_exp) {
352 /* Disconnection is the last we know about an obd */
353 lov_del_target(obd, i, 0, lov->lov_tgts[i]->ltd_gen);
359 rc = class_disconnect(exp); /* bz 9811 */
365 * -EINVAL : UUID can't be found in the LOV's target list
366 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
367 * -EBADF : The UUID is found, but the OBD is the wrong type (!)
368 * any >= 0 : is log target index
370 static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
371 enum obd_notify_event ev)
373 struct lov_obd *lov = &obd->u.lov;
374 struct lov_tgt_desc *tgt;
375 int index, activate, active;
378 CDEBUG(D_INFO, "Searching in lov %p for uuid %s event(%d)\n",
379 lov, uuid->uuid, ev);
382 for (index = 0; index < lov->desc.ld_tgt_count; index++) {
383 tgt = lov->lov_tgts[index];
387 * LU-642, initially inactive OSC could miss the obd_connect,
388 * we make up for it here.
390 if (ev == OBD_NOTIFY_ACTIVATE && tgt->ltd_exp == NULL &&
391 obd_uuid_equals(uuid, &tgt->ltd_uuid)) {
392 struct obd_uuid lov_osc_uuid = {"LOV_OSC_UUID"};
394 obd_connect(NULL, &tgt->ltd_exp, tgt->ltd_obd,
395 &lov_osc_uuid, &lov->lov_ocd, NULL);
400 CDEBUG(D_INFO, "lov idx %d is %s conn "LPX64"\n",
401 index, obd_uuid2str(&tgt->ltd_uuid),
402 tgt->ltd_exp->exp_handle.h_cookie);
403 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
407 if (index == lov->desc.ld_tgt_count)
408 GOTO(out, index = -EINVAL);
410 if (ev == OBD_NOTIFY_DEACTIVATE || ev == OBD_NOTIFY_ACTIVATE) {
411 activate = (ev == OBD_NOTIFY_ACTIVATE) ? 1 : 0;
413 if (lov->lov_tgts[index]->ltd_activate == activate) {
414 CDEBUG(D_INFO, "OSC %s already %sactivate!\n",
415 uuid->uuid, activate ? "" : "de");
417 lov->lov_tgts[index]->ltd_activate = activate;
418 CDEBUG(D_CONFIG, "%sactivate OSC %s\n",
419 activate ? "" : "de", obd_uuid2str(uuid));
422 } else if (ev == OBD_NOTIFY_INACTIVE || ev == OBD_NOTIFY_ACTIVE) {
423 active = (ev == OBD_NOTIFY_ACTIVE) ? 1 : 0;
425 if (lov->lov_tgts[index]->ltd_active == active) {
426 CDEBUG(D_INFO, "OSC %s already %sactive!\n",
427 uuid->uuid, active ? "" : "in");
430 CDEBUG(D_CONFIG, "Marking OSC %s %sactive\n",
431 obd_uuid2str(uuid), active ? "" : "in");
434 lov->lov_tgts[index]->ltd_active = active;
436 lov->desc.ld_active_tgt_count++;
437 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 0;
439 lov->desc.ld_active_tgt_count--;
440 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 1;
443 CERROR("Unknown event(%d) for uuid %s", ev, uuid->uuid);
451 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
452 enum obd_notify_event ev, void *data)
455 struct lov_obd *lov = &obd->u.lov;
458 down_read(&lov->lov_notify_lock);
459 if (!lov->lov_connects) {
460 up_read(&lov->lov_notify_lock);
464 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE ||
465 ev == OBD_NOTIFY_ACTIVATE || ev == OBD_NOTIFY_DEACTIVATE) {
466 struct obd_uuid *uuid;
470 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
471 up_read(&lov->lov_notify_lock);
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);
484 up_read(&lov->lov_notify_lock);
485 CERROR("event(%d) of %s failed: %d\n", ev,
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;
503 is_sync = (ev == OBD_NOTIFY_SYNC) ||
504 (ev == OBD_NOTIFY_SYNC_NONBLOCK);
507 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
508 if (!lov->lov_tgts[i])
511 /* don't send sync event if target not
512 * connected/activated */
513 if (is_sync && !lov->lov_tgts[i]->ltd_active)
516 rc = obd_notify_observer(obd, lov->lov_tgts[i]->ltd_obd,
519 CERROR("%s: notify %s of %s failed %d\n",
521 obd->obd_observer->obd_name,
522 lov->lov_tgts[i]->ltd_obd->obd_name,
529 up_read(&lov->lov_notify_lock);
533 static int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
534 __u32 index, int gen, int active)
536 struct lov_obd *lov = &obd->u.lov;
537 struct lov_tgt_desc *tgt;
538 struct obd_device *tgt_obd;
542 CDEBUG(D_CONFIG, "uuid:%s idx:%d gen:%d active:%d\n",
543 uuidp->uuid, index, gen, active);
546 CERROR("request to add OBD %s with invalid generation: %d\n",
551 tgt_obd = class_find_client_obd(uuidp, LUSTRE_OSC_NAME,
556 mutex_lock(&lov->lov_lock);
558 if ((index < lov->lov_tgt_size) && (lov->lov_tgts[index] != NULL)) {
559 tgt = lov->lov_tgts[index];
560 CERROR("UUID %s already assigned at LOV target index %d\n",
561 obd_uuid2str(&tgt->ltd_uuid), index);
562 mutex_unlock(&lov->lov_lock);
566 if (index >= lov->lov_tgt_size) {
567 /* We need to reallocate the lov target array. */
568 struct lov_tgt_desc **newtgts, **old = NULL;
569 __u32 newsize, oldsize = 0;
571 newsize = max(lov->lov_tgt_size, (__u32)2);
572 while (newsize < index + 1)
573 newsize = newsize << 1;
574 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
575 if (newtgts == NULL) {
576 mutex_unlock(&lov->lov_lock);
580 if (lov->lov_tgt_size) {
581 memcpy(newtgts, lov->lov_tgts, sizeof(*newtgts) *
584 oldsize = lov->lov_tgt_size;
587 lov->lov_tgts = newtgts;
588 lov->lov_tgt_size = newsize;
591 OBD_FREE(old, sizeof(*old) * oldsize);
593 CDEBUG(D_CONFIG, "tgts: %p size: %d\n",
594 lov->lov_tgts, lov->lov_tgt_size);
599 mutex_unlock(&lov->lov_lock);
603 rc = lov_ost_pool_add(&lov->lov_packed, index, lov->lov_tgt_size);
605 mutex_unlock(&lov->lov_lock);
610 tgt->ltd_uuid = *uuidp;
611 tgt->ltd_obd = tgt_obd;
612 /* XXX - add a sanity check on the generation number. */
614 tgt->ltd_index = index;
615 tgt->ltd_activate = active;
616 lov->lov_tgts[index] = tgt;
617 if (index >= lov->desc.ld_tgt_count)
618 lov->desc.ld_tgt_count = index + 1;
620 mutex_unlock(&lov->lov_lock);
622 CDEBUG(D_CONFIG, "idx=%d ltd_gen=%d ld_tgt_count=%d\n",
623 index, tgt->ltd_gen, lov->desc.ld_tgt_count);
625 rc = obd_notify(obd, tgt_obd, OBD_NOTIFY_CREATE, &index);
627 if (lov->lov_connects == 0) {
628 /* lov_connect hasn't been called yet. We'll do the
629 lov_connect_obd on this target when that fn first runs,
630 because we don't know the connect flags yet. */
636 rc = lov_connect_obd(obd, index, active, &lov->lov_ocd);
640 /* connect to administrative disabled ost */
644 if (lov->lov_cache != NULL) {
645 rc = obd_set_info_async(NULL, tgt->ltd_exp,
646 sizeof(KEY_CACHE_SET), KEY_CACHE_SET,
647 sizeof(struct cl_client_cache), lov->lov_cache,
653 rc = lov_notify(obd, tgt->ltd_exp->exp_obd,
654 active ? OBD_NOTIFY_CONNECT : OBD_NOTIFY_INACTIVE,
659 CERROR("add failed (%d), deleting %s\n", rc,
660 obd_uuid2str(&tgt->ltd_uuid));
661 lov_del_target(obd, index, 0, 0);
667 /* Schedule a target for deletion */
668 int lov_del_target(struct obd_device *obd, __u32 index,
669 struct obd_uuid *uuidp, int gen)
671 struct lov_obd *lov = &obd->u.lov;
672 int count = lov->desc.ld_tgt_count;
676 if (index >= count) {
677 CERROR("LOV target index %d >= number of LOV OBDs %d.\n",
682 /* to make sure there's no ongoing lov_notify() now */
683 down_write(&lov->lov_notify_lock);
686 if (!lov->lov_tgts[index]) {
687 CERROR("LOV target at index %d is not setup.\n", index);
688 GOTO(out, rc = -EINVAL);
691 if (uuidp && !obd_uuid_equals(uuidp, &lov->lov_tgts[index]->ltd_uuid)) {
692 CERROR("LOV target UUID %s at index %d doesn't match %s.\n",
693 lov_uuid2str(lov, index), index,
694 obd_uuid2str(uuidp));
695 GOTO(out, rc = -EINVAL);
698 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d exp: %p active: %d\n",
699 lov_uuid2str(lov, index), index,
700 lov->lov_tgts[index]->ltd_gen, lov->lov_tgts[index]->ltd_exp,
701 lov->lov_tgts[index]->ltd_active);
703 lov->lov_tgts[index]->ltd_reap = 1;
704 lov->lov_death_row++;
705 /* we really delete it from obd_putref */
708 up_write(&lov->lov_notify_lock);
713 static void __lov_del_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
715 struct obd_device *osc_obd;
718 LASSERT(tgt->ltd_reap);
720 osc_obd = class_exp2obd(tgt->ltd_exp);
722 CDEBUG(D_CONFIG, "Removing tgt %s : %s\n",
724 osc_obd ? osc_obd->obd_name : "<no obd>");
727 lov_disconnect_obd(obd, tgt);
731 /* Manual cleanup - no cleanup logs to clean up the osc's. We must
732 do it ourselves. And we can't do it from lov_cleanup,
733 because we just lost our only reference to it. */
735 class_manual_cleanup(osc_obd);
738 void lov_fix_desc_stripe_size(__u64 *val)
740 if (*val < LOV_MIN_STRIPE_SIZE) {
742 LCONSOLE_INFO("Increasing default stripe size to "
744 LOV_DEFAULT_STRIPE_SIZE);
745 *val = LOV_DEFAULT_STRIPE_SIZE;
746 } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) {
747 *val &= ~(LOV_MIN_STRIPE_SIZE - 1);
748 LCONSOLE_WARN("Changing default stripe size to "LPU64" (a "
750 *val, LOV_MIN_STRIPE_SIZE);
754 void lov_fix_desc_stripe_count(__u32 *val)
760 void lov_fix_desc_pattern(__u32 *val)
762 /* from lov_setstripe */
763 if ((*val != 0) && (*val != LOV_PATTERN_RAID0)) {
764 LCONSOLE_WARN("Unknown stripe pattern: %#x\n", *val);
769 void lov_fix_desc_qos_maxage(__u32 *val)
773 *val = QOS_DEFAULT_MAXAGE;
776 void lov_fix_desc(struct lov_desc *desc)
778 lov_fix_desc_stripe_size(&desc->ld_default_stripe_size);
779 lov_fix_desc_stripe_count(&desc->ld_default_stripe_count);
780 lov_fix_desc_pattern(&desc->ld_pattern);
781 lov_fix_desc_qos_maxage(&desc->ld_qos_maxage);
784 int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
786 struct lov_desc *desc;
787 struct lov_obd *lov = &obd->u.lov;
791 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
792 CERROR("LOV setup requires a descriptor\n");
796 desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
798 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
799 CERROR("descriptor size wrong: %d > %d\n",
800 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
804 if (desc->ld_magic != LOV_DESC_MAGIC) {
805 if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
806 CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n",
807 obd->obd_name, desc);
808 lustre_swab_lov_desc(desc);
810 CERROR("%s: Bad lov desc magic: %#x\n",
811 obd->obd_name, desc->ld_magic);
818 desc->ld_active_tgt_count = 0;
820 lov->lov_tgt_size = 0;
822 mutex_init(&lov->lov_lock);
823 cfs_atomic_set(&lov->lov_refcount, 0);
824 lov->lov_sp_me = LUSTRE_SP_CLI;
826 init_rwsem(&lov->lov_notify_lock);
828 lov->lov_pools_hash_body = cfs_hash_create("POOLS", HASH_POOLS_CUR_BITS,
830 HASH_POOLS_BKT_BITS, 0,
833 &pool_hash_operations,
835 CFS_INIT_LIST_HEAD(&lov->lov_pool_list);
836 lov->lov_pool_count = 0;
837 rc = lov_ost_pool_init(&lov->lov_packed, 0);
842 obd->obd_vars = lprocfs_lov_obd_vars;
843 lprocfs_seq_obd_setup(obd);
844 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd", 0444,
845 &lov_proc_target_fops, obd);
847 CWARN("Error adding the target_obd file\n");
849 lov->lov_pool_proc_entry = lprocfs_seq_register("pools",
859 static int lov_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
862 struct lov_obd *lov = &obd->u.lov;
867 case OBD_CLEANUP_EARLY: {
869 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
870 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
872 obd_precleanup(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
884 static int lov_cleanup(struct obd_device *obd)
886 struct lov_obd *lov = &obd->u.lov;
887 cfs_list_t *pos, *tmp;
888 struct pool_desc *pool;
891 cfs_list_for_each_safe(pos, tmp, &lov->lov_pool_list) {
892 pool = cfs_list_entry(pos, struct pool_desc, pool_list);
893 /* free pool structs */
894 CDEBUG(D_INFO, "delete pool %p\n", pool);
895 /* In the function below, .hs_keycmp resolves to
896 * pool_hashkey_keycmp() */
897 /* coverity[overrun-buffer-val] */
898 lov_pool_del(obd, pool->pool_name);
900 cfs_hash_putref(lov->lov_pools_hash_body);
901 lov_ost_pool_free(&lov->lov_packed);
903 lprocfs_obd_cleanup(obd);
907 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
908 if (!lov->lov_tgts[i])
911 /* Inactive targets may never have connected */
912 if (lov->lov_tgts[i]->ltd_active ||
913 cfs_atomic_read(&lov->lov_refcount))
914 /* We should never get here - these
915 should have been removed in the
917 CERROR("lov tgt %d not cleaned!"
918 " deathrow=%d, lovrc=%d\n",
919 i, lov->lov_death_row,
920 cfs_atomic_read(&lov->lov_refcount));
921 lov_del_target(obd, i, 0, 0);
924 OBD_FREE(lov->lov_tgts, sizeof(*lov->lov_tgts) *
926 lov->lov_tgt_size = 0;
931 int lov_process_config_base(struct obd_device *obd, struct lustre_cfg *lcfg,
932 __u32 *indexp, int *genp)
934 struct obd_uuid obd_uuid;
939 switch(cmd = lcfg->lcfg_command) {
940 case LCFG_LOV_ADD_OBD:
941 case LCFG_LOV_ADD_INA:
942 case LCFG_LOV_DEL_OBD: {
945 /* lov_modify_tgts add 0:lov_mdsA 1:ost1_UUID 2:0 3:1 */
946 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
947 GOTO(out, rc = -EINVAL);
949 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
951 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", indexp) != 1)
952 GOTO(out, rc = -EINVAL);
953 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", genp) != 1)
954 GOTO(out, rc = -EINVAL);
957 if (cmd == LCFG_LOV_ADD_OBD)
958 rc = lov_add_target(obd, &obd_uuid, index, gen, 1);
959 else if (cmd == LCFG_LOV_ADD_INA)
960 rc = lov_add_target(obd, &obd_uuid, index, gen, 0);
962 rc = lov_del_target(obd, index, &obd_uuid, gen);
966 struct lov_desc *desc = &(obd->u.lov.desc);
969 GOTO(out, rc = -EINVAL);
971 rc = class_process_proc_seq_param(PARAM_LOV, obd->obd_vars,
984 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
985 GOTO(out, rc = -EINVAL);
993 static int lov_recreate(struct obd_export *exp, struct obdo *src_oa,
994 struct lov_stripe_md **ea, struct obd_trans_info *oti)
996 struct lov_stripe_md *obj_mdp, *lsm;
997 struct lov_obd *lov = &exp->exp_obd->u.lov;
1002 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
1003 src_oa->o_flags & OBD_FL_RECREATE_OBJS);
1005 OBD_ALLOC(obj_mdp, sizeof(*obj_mdp));
1006 if (obj_mdp == NULL)
1009 ost_idx = src_oa->o_nlink;
1012 GOTO(out, rc = -EINVAL);
1013 if (ost_idx >= lov->desc.ld_tgt_count ||
1014 !lov->lov_tgts[ost_idx])
1015 GOTO(out, rc = -EINVAL);
1017 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1018 if (lsm->lsm_oinfo[i]->loi_ost_idx == ost_idx) {
1019 if (ostid_id(&lsm->lsm_oinfo[i]->loi_oi) !=
1020 ostid_id(&src_oa->o_oi))
1021 GOTO(out, rc = -EINVAL);
1025 if (i == lsm->lsm_stripe_count)
1026 GOTO(out, rc = -EINVAL);
1028 rc = obd_create(NULL, lov->lov_tgts[ost_idx]->ltd_exp,
1029 src_oa, &obj_mdp, oti);
1031 OBD_FREE(obj_mdp, sizeof(*obj_mdp));
1035 /* the LOV expects oa->o_id to be set to the LOV object id */
1036 static int lov_create(const struct lu_env *env, struct obd_export *exp,
1037 struct obdo *src_oa, struct lov_stripe_md **ea,
1038 struct obd_trans_info *oti)
1040 struct lov_obd *lov;
1044 LASSERT(ea != NULL);
1048 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1049 src_oa->o_flags == OBD_FL_DELORPHAN) {
1050 /* should be used with LOV anymore */
1054 lov = &exp->exp_obd->u.lov;
1055 if (!lov->desc.ld_active_tgt_count)
1058 obd_getref(exp->exp_obd);
1059 /* Recreate a specific object id at the given OST index */
1060 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1061 (src_oa->o_flags & OBD_FL_RECREATE_OBJS)) {
1062 rc = lov_recreate(exp, src_oa, ea, oti);
1065 obd_putref(exp->exp_obd);
1069 #define ASSERT_LSM_MAGIC(lsmp) \
1071 LASSERT((lsmp) != NULL); \
1072 LASSERTF(((lsmp)->lsm_magic == LOV_MAGIC_V1 || \
1073 (lsmp)->lsm_magic == LOV_MAGIC_V3), \
1074 "%p->lsm_magic=%x\n", (lsmp), (lsmp)->lsm_magic); \
1077 static int lov_destroy(const struct lu_env *env, struct obd_export *exp,
1078 struct obdo *oa, struct lov_stripe_md *lsm,
1079 struct obd_trans_info *oti, struct obd_export *md_exp,
1082 struct lov_request_set *set;
1083 struct obd_info oinfo;
1084 struct lov_request *req;
1086 struct lov_obd *lov;
1087 int rc = 0, err = 0;
1090 ASSERT_LSM_MAGIC(lsm);
1092 if (!exp || !exp->exp_obd)
1095 if (oa->o_valid & OBD_MD_FLCOOKIE) {
1097 LASSERT(oti->oti_logcookies);
1100 lov = &exp->exp_obd->u.lov;
1101 obd_getref(exp->exp_obd);
1102 rc = lov_prep_destroy_set(exp, &oinfo, oa, lsm, oti, &set);
1106 cfs_list_for_each (pos, &set->set_list) {
1107 req = cfs_list_entry(pos, struct lov_request, rq_link);
1109 if (oa->o_valid & OBD_MD_FLCOOKIE)
1110 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1112 err = obd_destroy(env, lov->lov_tgts[req->rq_idx]->ltd_exp,
1113 req->rq_oi.oi_oa, NULL, oti, NULL, capa);
1114 err = lov_update_common_set(set, req, err);
1116 CERROR("%s: destroying objid "DOSTID" subobj "
1117 DOSTID" on OST idx %d: rc = %d\n",
1118 exp->exp_obd->obd_name, POSTID(&oa->o_oi),
1119 POSTID(&req->rq_oi.oi_oa->o_oi),
1127 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
1128 rc = lsm_op_find(lsm->lsm_magic)->lsm_destroy(lsm, oa, md_exp);
1130 err = lov_fini_destroy_set(set);
1132 obd_putref(exp->exp_obd);
1133 RETURN(rc ? rc : err);
1136 static int lov_getattr(const struct lu_env *env, struct obd_export *exp,
1137 struct obd_info *oinfo)
1139 struct lov_request_set *set;
1140 struct lov_request *req;
1142 struct lov_obd *lov;
1143 int err = 0, rc = 0;
1147 ASSERT_LSM_MAGIC(oinfo->oi_md);
1149 if (!exp || !exp->exp_obd)
1152 lov = &exp->exp_obd->u.lov;
1154 rc = lov_prep_getattr_set(exp, oinfo, &set);
1158 cfs_list_for_each (pos, &set->set_list) {
1159 req = cfs_list_entry(pos, struct lov_request, rq_link);
1161 CDEBUG(D_INFO, "objid "DOSTID"[%d] has subobj "DOSTID" at idx"
1162 " %u\n", POSTID(&oinfo->oi_oa->o_oi), req->rq_stripe,
1163 POSTID(&req->rq_oi.oi_oa->o_oi), req->rq_idx);
1165 rc = obd_getattr(env, lov->lov_tgts[req->rq_idx]->ltd_exp,
1167 err = lov_update_common_set(set, req, rc);
1169 CERROR("%s: getattr objid "DOSTID" subobj "
1170 DOSTID" on OST idx %d: rc = %d\n",
1171 exp->exp_obd->obd_name,
1172 POSTID(&oinfo->oi_oa->o_oi),
1173 POSTID(&req->rq_oi.oi_oa->o_oi),
1179 rc = lov_fini_getattr_set(set);
1185 static int lov_getattr_interpret(struct ptlrpc_request_set *rqset,
1188 struct lov_request_set *lovset = (struct lov_request_set *)data;
1192 /* don't do attribute merge if this aysnc op failed */
1194 cfs_atomic_set(&lovset->set_completes, 0);
1195 err = lov_fini_getattr_set(lovset);
1196 RETURN(rc ? rc : err);
1199 static int lov_getattr_async(struct obd_export *exp, struct obd_info *oinfo,
1200 struct ptlrpc_request_set *rqset)
1202 struct lov_request_set *lovset;
1203 struct lov_obd *lov;
1205 struct lov_request *req;
1210 ASSERT_LSM_MAGIC(oinfo->oi_md);
1212 if (!exp || !exp->exp_obd)
1215 lov = &exp->exp_obd->u.lov;
1217 rc = lov_prep_getattr_set(exp, oinfo, &lovset);
1221 CDEBUG(D_INFO, "objid "DOSTID": %ux%u byte stripes\n",
1222 POSTID(&oinfo->oi_md->lsm_oi), oinfo->oi_md->lsm_stripe_count,
1223 oinfo->oi_md->lsm_stripe_size);
1225 cfs_list_for_each(pos, &lovset->set_list) {
1226 req = cfs_list_entry(pos, struct lov_request, rq_link);
1228 CDEBUG(D_INFO, "objid "DOSTID"[%d] has subobj "DOSTID" at idx"
1229 "%u\n", POSTID(&oinfo->oi_oa->o_oi), req->rq_stripe,
1230 POSTID(&req->rq_oi.oi_oa->o_oi), req->rq_idx);
1231 rc = obd_getattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1232 &req->rq_oi, rqset);
1234 CERROR("%s: getattr objid "DOSTID" subobj"
1235 DOSTID" on OST idx %d: rc = %d\n",
1236 exp->exp_obd->obd_name,
1237 POSTID(&oinfo->oi_oa->o_oi),
1238 POSTID(&req->rq_oi.oi_oa->o_oi),
1244 if (!cfs_list_empty(&rqset->set_requests)) {
1246 LASSERT (rqset->set_interpret == NULL);
1247 rqset->set_interpret = lov_getattr_interpret;
1248 rqset->set_arg = (void *)lovset;
1253 cfs_atomic_set(&lovset->set_completes, 0);
1254 err = lov_fini_getattr_set(lovset);
1255 RETURN(rc ? rc : err);
1258 static int lov_setattr(const struct lu_env *env, struct obd_export *exp,
1259 struct obd_info *oinfo, struct obd_trans_info *oti)
1261 struct lov_request_set *set;
1262 struct lov_obd *lov;
1264 struct lov_request *req;
1265 int err = 0, rc = 0;
1269 ASSERT_LSM_MAGIC(oinfo->oi_md);
1271 if (!exp || !exp->exp_obd)
1274 /* for now, we only expect the following updates here */
1275 LASSERT(!(oinfo->oi_oa->o_valid & ~(OBD_MD_FLID | OBD_MD_FLTYPE |
1276 OBD_MD_FLMODE | OBD_MD_FLATIME |
1277 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1278 OBD_MD_FLFLAGS | OBD_MD_FLSIZE |
1279 OBD_MD_FLGROUP | OBD_MD_FLUID |
1280 OBD_MD_FLGID | OBD_MD_FLFID |
1282 lov = &exp->exp_obd->u.lov;
1283 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1287 cfs_list_for_each (pos, &set->set_list) {
1288 req = cfs_list_entry(pos, struct lov_request, rq_link);
1290 rc = obd_setattr(env, lov->lov_tgts[req->rq_idx]->ltd_exp,
1292 err = lov_update_setattr_set(set, req, rc);
1294 CERROR("%s: setattr objid "DOSTID" subobj "
1295 DOSTID" on OST idx %d: rc = %d\n",
1296 exp->exp_obd->obd_name,
1297 POSTID(&set->set_oi->oi_oa->o_oi),
1298 POSTID(&req->rq_oi.oi_oa->o_oi), req->rq_idx,
1304 err = lov_fini_setattr_set(set);
1310 static int lov_setattr_interpret(struct ptlrpc_request_set *rqset,
1313 struct lov_request_set *lovset = (struct lov_request_set *)data;
1318 cfs_atomic_set(&lovset->set_completes, 0);
1319 err = lov_fini_setattr_set(lovset);
1320 RETURN(rc ? rc : err);
1323 /* If @oti is given, the request goes from MDS and responses from OSTs are not
1324 needed. Otherwise, a client is waiting for responses. */
1325 static int lov_setattr_async(struct obd_export *exp, struct obd_info *oinfo,
1326 struct obd_trans_info *oti,
1327 struct ptlrpc_request_set *rqset)
1329 struct lov_request_set *set;
1330 struct lov_request *req;
1332 struct lov_obd *lov;
1337 ASSERT_LSM_MAGIC(oinfo->oi_md);
1338 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE) {
1340 LASSERT(oti->oti_logcookies);
1343 if (!exp || !exp->exp_obd)
1346 lov = &exp->exp_obd->u.lov;
1347 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1351 CDEBUG(D_INFO, "objid "DOSTID": %ux%u byte stripes\n",
1352 POSTID(&oinfo->oi_md->lsm_oi),
1353 oinfo->oi_md->lsm_stripe_count,
1354 oinfo->oi_md->lsm_stripe_size);
1356 cfs_list_for_each(pos, &set->set_list) {
1357 req = cfs_list_entry(pos, struct lov_request, rq_link);
1359 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
1360 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1362 CDEBUG(D_INFO, "objid "DOSTID"[%d] has subobj "DOSTID" at idx"
1363 "%u\n", POSTID(&oinfo->oi_oa->o_oi), req->rq_stripe,
1364 POSTID(&req->rq_oi.oi_oa->o_oi), req->rq_idx);
1366 rc = obd_setattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1367 &req->rq_oi, oti, rqset);
1369 CERROR("error: setattr objid "DOSTID" subobj"
1370 DOSTID" on OST idx %d: rc = %d\n",
1371 POSTID(&set->set_oi->oi_oa->o_oi),
1372 POSTID(&req->rq_oi.oi_oa->o_oi),
1378 /* If we are not waiting for responses on async requests, return. */
1379 if (rc || !rqset || cfs_list_empty(&rqset->set_requests)) {
1382 cfs_atomic_set(&set->set_completes, 0);
1383 err = lov_fini_setattr_set(set);
1384 RETURN(rc ? rc : err);
1387 LASSERT(rqset->set_interpret == NULL);
1388 rqset->set_interpret = lov_setattr_interpret;
1389 rqset->set_arg = (void *)set;
1394 static int lov_punch_interpret(struct ptlrpc_request_set *rqset,
1397 struct lov_request_set *lovset = (struct lov_request_set *)data;
1402 cfs_atomic_set(&lovset->set_completes, 0);
1403 err = lov_fini_punch_set(lovset);
1404 RETURN(rc ? rc : err);
1407 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
1408 * we can send this 'punch' to just the authoritative node and the nodes
1409 * that the punch will affect. */
1410 static int lov_punch(const struct lu_env *env, struct obd_export *exp,
1411 struct obd_info *oinfo, struct obd_trans_info *oti,
1412 struct ptlrpc_request_set *rqset)
1414 struct lov_request_set *set;
1415 struct lov_obd *lov;
1417 struct lov_request *req;
1422 ASSERT_LSM_MAGIC(oinfo->oi_md);
1424 if (!exp || !exp->exp_obd)
1427 lov = &exp->exp_obd->u.lov;
1428 rc = lov_prep_punch_set(exp, oinfo, oti, &set);
1432 cfs_list_for_each (pos, &set->set_list) {
1433 req = cfs_list_entry(pos, struct lov_request, rq_link);
1435 rc = obd_punch(env, lov->lov_tgts[req->rq_idx]->ltd_exp,
1436 &req->rq_oi, NULL, rqset);
1438 CERROR("%s: punch objid "DOSTID" subobj "DOSTID
1439 " on OST idx %d: rc = %d\n",
1440 exp->exp_obd->obd_name,
1441 POSTID(&set->set_oi->oi_oa->o_oi),
1442 POSTID(&req->rq_oi.oi_oa->o_oi), req->rq_idx, rc);
1447 if (rc || cfs_list_empty(&rqset->set_requests)) {
1449 err = lov_fini_punch_set(set);
1450 RETURN(rc ? rc : err);
1453 LASSERT(rqset->set_interpret == NULL);
1454 rqset->set_interpret = lov_punch_interpret;
1455 rqset->set_arg = (void *)set;
1460 static int lov_sync_interpret(struct ptlrpc_request_set *rqset,
1463 struct lov_request_set *lovset = data;
1468 cfs_atomic_set(&lovset->set_completes, 0);
1469 err = lov_fini_sync_set(lovset);
1473 static int lov_sync(const struct lu_env *env, struct obd_export *exp,
1474 struct obd_info *oinfo, obd_off start, obd_off end,
1475 struct ptlrpc_request_set *rqset)
1477 struct lov_request_set *set = NULL;
1478 struct lov_obd *lov;
1480 struct lov_request *req;
1484 ASSERT_LSM_MAGIC(oinfo->oi_md);
1485 LASSERT(rqset != NULL);
1490 lov = &exp->exp_obd->u.lov;
1491 rc = lov_prep_sync_set(exp, oinfo, start, end, &set);
1495 CDEBUG(D_INFO, "fsync objid "DOSTID" ["LPX64", "LPX64"]\n",
1496 POSTID(&set->set_oi->oi_oa->o_oi), start, end);
1498 cfs_list_for_each (pos, &set->set_list) {
1499 req = cfs_list_entry(pos, struct lov_request, rq_link);
1501 rc = obd_sync(env, lov->lov_tgts[req->rq_idx]->ltd_exp,
1502 &req->rq_oi, req->rq_oi.oi_policy.l_extent.start,
1503 req->rq_oi.oi_policy.l_extent.end, rqset);
1505 CERROR("%s: fsync objid "DOSTID" subobj "DOSTID
1506 " on OST idx %d: rc = %d\n",
1507 exp->exp_obd->obd_name,
1508 POSTID(&set->set_oi->oi_oa->o_oi),
1509 POSTID(&req->rq_oi.oi_oa->o_oi), req->rq_idx,
1515 /* If we are not waiting for responses on async requests, return. */
1516 if (rc || cfs_list_empty(&rqset->set_requests)) {
1517 int err = lov_fini_sync_set(set);
1522 LASSERT(rqset->set_interpret == NULL);
1523 rqset->set_interpret = lov_sync_interpret;
1524 rqset->set_arg = (void *)set;
1529 static int lov_brw_check(struct lov_obd *lov, struct obd_info *lov_oinfo,
1530 obd_count oa_bufs, struct brw_page *pga)
1532 struct obd_info oinfo = { { { 0 } } };
1535 oinfo.oi_oa = lov_oinfo->oi_oa;
1537 /* The caller just wants to know if there's a chance that this
1538 * I/O can succeed */
1539 for (i = 0; i < oa_bufs; i++) {
1540 int stripe = lov_stripe_number(lov_oinfo->oi_md, pga[i].off);
1541 int ost = lov_oinfo->oi_md->lsm_oinfo[stripe]->loi_ost_idx;
1544 if (!lov_stripe_intersects(lov_oinfo->oi_md, i, pga[i].off,
1545 pga[i].off + pga[i].count - 1,
1549 if (!lov->lov_tgts[ost] || !lov->lov_tgts[ost]->ltd_active) {
1550 CDEBUG(D_HA, "lov idx %d inactive\n", ost);
1554 rc = obd_brw(OBD_BRW_CHECK, lov->lov_tgts[ost]->ltd_exp, &oinfo,
1562 static int lov_brw(int cmd, struct obd_export *exp, struct obd_info *oinfo,
1563 obd_count oa_bufs, struct brw_page *pga,
1564 struct obd_trans_info *oti)
1566 struct lov_request_set *set;
1567 struct lov_request *req;
1569 struct lov_obd *lov = &exp->exp_obd->u.lov;
1573 ASSERT_LSM_MAGIC(oinfo->oi_md);
1575 if (cmd == OBD_BRW_CHECK) {
1576 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1580 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &set);
1584 cfs_list_for_each (pos, &set->set_list) {
1585 struct obd_export *sub_exp;
1586 struct brw_page *sub_pga;
1587 req = cfs_list_entry(pos, struct lov_request, rq_link);
1589 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1590 sub_pga = set->set_pga + req->rq_pgaidx;
1591 rc = obd_brw(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1595 lov_update_common_set(set, req, rc);
1598 err = lov_fini_brw_set(set);
1604 static int lov_enqueue_interpret(struct ptlrpc_request_set *rqset,
1607 struct lov_request_set *lovset = (struct lov_request_set *)data;
1609 rc = lov_fini_enqueue_set(lovset, lovset->set_ei->ei_mode, rc, rqset);
1613 static int lov_enqueue(struct obd_export *exp, struct obd_info *oinfo,
1614 struct ldlm_enqueue_info *einfo,
1615 struct ptlrpc_request_set *rqset)
1617 ldlm_mode_t mode = einfo->ei_mode;
1618 struct lov_request_set *set;
1619 struct lov_request *req;
1621 struct lov_obd *lov;
1626 ASSERT_LSM_MAGIC(oinfo->oi_md);
1627 LASSERT(mode == (mode & -mode));
1629 /* we should never be asked to replay a lock this way. */
1630 LASSERT((oinfo->oi_flags & LDLM_FL_REPLAY) == 0);
1632 if (!exp || !exp->exp_obd)
1635 lov = &exp->exp_obd->u.lov;
1636 rc = lov_prep_enqueue_set(exp, oinfo, einfo, &set);
1640 cfs_list_for_each (pos, &set->set_list) {
1641 req = cfs_list_entry(pos, struct lov_request, rq_link);
1643 rc = obd_enqueue(lov->lov_tgts[req->rq_idx]->ltd_exp,
1644 &req->rq_oi, einfo, rqset);
1649 if (rqset && !cfs_list_empty(&rqset->set_requests)) {
1651 LASSERT(rqset->set_interpret == NULL);
1652 rqset->set_interpret = lov_enqueue_interpret;
1653 rqset->set_arg = (void *)set;
1657 rc = lov_fini_enqueue_set(set, mode, rc, rqset);
1661 static int lov_change_cbdata(struct obd_export *exp,
1662 struct lov_stripe_md *lsm, ldlm_iterator_t it,
1665 struct lov_obd *lov;
1669 ASSERT_LSM_MAGIC(lsm);
1671 if (!exp || !exp->exp_obd)
1674 lov = &exp->exp_obd->u.lov;
1675 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1676 struct lov_stripe_md submd;
1677 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
1679 if (!lov->lov_tgts[loi->loi_ost_idx]) {
1680 CDEBUG(D_HA, "lov idx %d NULL \n", loi->loi_ost_idx);
1684 submd.lsm_oi = loi->loi_oi;
1685 submd.lsm_stripe_count = 0;
1686 rc = obd_change_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1692 /* find any ldlm lock of the inode in lov
1696 static int lov_find_cbdata(struct obd_export *exp,
1697 struct lov_stripe_md *lsm, ldlm_iterator_t it,
1700 struct lov_obd *lov;
1704 ASSERT_LSM_MAGIC(lsm);
1706 if (!exp || !exp->exp_obd)
1709 lov = &exp->exp_obd->u.lov;
1710 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1711 struct lov_stripe_md submd;
1712 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
1714 if (!lov->lov_tgts[loi->loi_ost_idx]) {
1715 CDEBUG(D_HA, "lov idx %d NULL \n", loi->loi_ost_idx);
1718 submd.lsm_oi = loi->loi_oi;
1719 submd.lsm_stripe_count = 0;
1720 rc = obd_find_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1728 static int lov_cancel(struct obd_export *exp, struct lov_stripe_md *lsm,
1729 __u32 mode, struct lustre_handle *lockh)
1731 struct lov_request_set *set;
1732 struct obd_info oinfo;
1733 struct lov_request *req;
1735 struct lov_obd *lov;
1736 struct lustre_handle *lov_lockhp;
1737 int err = 0, rc = 0;
1740 ASSERT_LSM_MAGIC(lsm);
1742 if (!exp || !exp->exp_obd)
1746 lov = &exp->exp_obd->u.lov;
1747 rc = lov_prep_cancel_set(exp, &oinfo, lsm, mode, lockh, &set);
1751 cfs_list_for_each(pos, &set->set_list) {
1752 req = cfs_list_entry(pos, struct lov_request, rq_link);
1753 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
1755 rc = obd_cancel(lov->lov_tgts[req->rq_idx]->ltd_exp,
1756 req->rq_oi.oi_md, mode, lov_lockhp);
1757 rc = lov_update_common_set(set, req, rc);
1759 CERROR("%s: cancel objid "DOSTID" subobj "
1760 DOSTID" on OST idx %d: rc = %d\n",
1761 exp->exp_obd->obd_name, POSTID(&lsm->lsm_oi),
1762 POSTID(&req->rq_oi.oi_md->lsm_oi),
1768 lov_fini_cancel_set(set);
1772 static int lov_cancel_unused(struct obd_export *exp,
1773 struct lov_stripe_md *lsm,
1774 ldlm_cancel_flags_t flags, void *opaque)
1776 struct lov_obd *lov;
1780 if (!exp || !exp->exp_obd)
1783 lov = &exp->exp_obd->u.lov;
1785 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1787 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
1790 err = obd_cancel_unused(lov->lov_tgts[i]->ltd_exp, NULL,
1798 ASSERT_LSM_MAGIC(lsm);
1800 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1801 struct lov_stripe_md submd;
1802 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
1803 int idx = loi->loi_ost_idx;
1806 if (!lov->lov_tgts[idx]) {
1807 CDEBUG(D_HA, "lov idx %d NULL\n", idx);
1811 if (!lov->lov_tgts[idx]->ltd_active)
1812 CDEBUG(D_HA, "lov idx %d inactive\n", idx);
1814 submd.lsm_oi = loi->loi_oi;
1815 submd.lsm_stripe_count = 0;
1816 err = obd_cancel_unused(lov->lov_tgts[idx]->ltd_exp,
1817 &submd, flags, opaque);
1818 if (err && lov->lov_tgts[idx]->ltd_active) {
1819 CERROR("%s: cancel unused objid "DOSTID
1820 " subobj "DOSTID" on OST idx %d: rc = %d\n",
1821 exp->exp_obd->obd_name, POSTID(&lsm->lsm_oi),
1822 POSTID(&loi->loi_oi), idx, err);
1830 int lov_statfs_interpret(struct ptlrpc_request_set *rqset, void *data, int rc)
1832 struct lov_request_set *lovset = (struct lov_request_set *)data;
1837 cfs_atomic_set(&lovset->set_completes, 0);
1839 err = lov_fini_statfs_set(lovset);
1840 RETURN(rc ? rc : err);
1843 static int lov_statfs_async(struct obd_export *exp, struct obd_info *oinfo,
1844 __u64 max_age, struct ptlrpc_request_set *rqset)
1846 struct obd_device *obd = class_exp2obd(exp);
1847 struct lov_request_set *set;
1848 struct lov_request *req;
1850 struct lov_obd *lov;
1854 LASSERT(oinfo != NULL);
1855 LASSERT(oinfo->oi_osfs != NULL);
1858 rc = lov_prep_statfs_set(obd, oinfo, &set);
1862 cfs_list_for_each (pos, &set->set_list) {
1863 req = cfs_list_entry(pos, struct lov_request, rq_link);
1864 rc = obd_statfs_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1865 &req->rq_oi, max_age, rqset);
1870 if (rc || cfs_list_empty(&rqset->set_requests)) {
1873 cfs_atomic_set(&set->set_completes, 0);
1874 err = lov_fini_statfs_set(set);
1875 RETURN(rc ? rc : err);
1878 LASSERT(rqset->set_interpret == NULL);
1879 rqset->set_interpret = lov_statfs_interpret;
1880 rqset->set_arg = (void *)set;
1884 static int lov_statfs(const struct lu_env *env, struct obd_export *exp,
1885 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1887 struct ptlrpc_request_set *set = NULL;
1888 struct obd_info oinfo = { { { 0 } } };
1893 /* for obdclass we forbid using obd_statfs_rqset, but prefer using async
1894 * statfs requests */
1895 set = ptlrpc_prep_set();
1899 oinfo.oi_osfs = osfs;
1900 oinfo.oi_flags = flags;
1901 rc = lov_statfs_async(exp, &oinfo, max_age, set);
1903 rc = ptlrpc_set_wait(set);
1904 ptlrpc_set_destroy(set);
1909 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1910 void *karg, void *uarg)
1912 struct obd_device *obddev = class_exp2obd(exp);
1913 struct lov_obd *lov = &obddev->u.lov;
1914 int i = 0, rc = 0, count = lov->desc.ld_tgt_count;
1915 struct obd_uuid *uuidp;
1919 case IOC_OBD_STATFS: {
1920 struct obd_ioctl_data *data = karg;
1921 struct obd_device *osc_obd;
1922 struct obd_statfs stat_buf = {0};
1926 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
1927 if ((index >= count))
1930 if (!lov->lov_tgts[index])
1931 /* Try again with the next index */
1933 if (!lov->lov_tgts[index]->ltd_active)
1936 osc_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
1941 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(osc_obd),
1942 min((int)data->ioc_plen2,
1943 (int)sizeof(struct obd_uuid))))
1946 flags = uarg ? *(__u32*)uarg : 0;
1947 /* got statfs data */
1948 rc = obd_statfs(NULL, lov->lov_tgts[index]->ltd_exp, &stat_buf,
1949 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1953 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
1954 min((int) data->ioc_plen1,
1955 (int) sizeof(stat_buf))))
1959 case OBD_IOC_LOV_GET_CONFIG: {
1960 struct obd_ioctl_data *data;
1961 struct lov_desc *desc;
1966 if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
1969 data = (struct obd_ioctl_data *)buf;
1971 if (sizeof(*desc) > data->ioc_inllen1) {
1972 obd_ioctl_freedata(buf, len);
1976 if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
1977 obd_ioctl_freedata(buf, len);
1981 if (sizeof(__u32) * count > data->ioc_inllen3) {
1982 obd_ioctl_freedata(buf, len);
1986 desc = (struct lov_desc *)data->ioc_inlbuf1;
1987 memcpy(desc, &(lov->desc), sizeof(*desc));
1989 uuidp = (struct obd_uuid *)data->ioc_inlbuf2;
1990 genp = (__u32 *)data->ioc_inlbuf3;
1991 /* the uuid will be empty for deleted OSTs */
1992 for (i = 0; i < count; i++, uuidp++, genp++) {
1993 if (!lov->lov_tgts[i])
1995 *uuidp = lov->lov_tgts[i]->ltd_uuid;
1996 *genp = lov->lov_tgts[i]->ltd_gen;
1999 if (copy_to_user((void *)uarg, buf, len))
2001 obd_ioctl_freedata(buf, len);
2004 case LL_IOC_LOV_SETSTRIPE:
2005 rc = lov_setstripe(exp, len, karg, uarg);
2007 case LL_IOC_LOV_GETSTRIPE:
2008 rc = lov_getstripe(exp, karg, uarg);
2010 case LL_IOC_LOV_SETEA:
2011 rc = lov_setea(exp, karg, uarg);
2013 case OBD_IOC_QUOTACTL: {
2014 struct if_quotactl *qctl = karg;
2015 struct lov_tgt_desc *tgt = NULL;
2016 struct obd_quotactl *oqctl;
2018 if (qctl->qc_valid == QC_OSTIDX) {
2019 if (count <= qctl->qc_idx)
2022 tgt = lov->lov_tgts[qctl->qc_idx];
2023 if (!tgt || !tgt->ltd_exp)
2025 } else if (qctl->qc_valid == QC_UUID) {
2026 for (i = 0; i < count; i++) {
2027 tgt = lov->lov_tgts[i];
2029 !obd_uuid_equals(&tgt->ltd_uuid,
2033 if (tgt->ltd_exp == NULL)
2045 LASSERT(tgt && tgt->ltd_exp);
2046 OBD_ALLOC_PTR(oqctl);
2050 QCTL_COPY(oqctl, qctl);
2051 rc = obd_quotactl(tgt->ltd_exp, oqctl);
2053 QCTL_COPY(qctl, oqctl);
2054 qctl->qc_valid = QC_OSTIDX;
2055 qctl->obd_uuid = tgt->ltd_uuid;
2057 OBD_FREE_PTR(oqctl);
2066 for (i = 0; i < count; i++) {
2068 struct obd_device *osc_obd;
2070 /* OST was disconnected */
2071 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2074 /* ll_umount_begin() sets force flag but for lov, not
2075 * osc. Let's pass it through */
2076 osc_obd = class_exp2obd(lov->lov_tgts[i]->ltd_exp);
2077 osc_obd->obd_force = obddev->obd_force;
2078 err = obd_iocontrol(cmd, lov->lov_tgts[i]->ltd_exp,
2080 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
2083 if (lov->lov_tgts[i]->ltd_active) {
2084 CDEBUG(err == -ENOTTY ?
2085 D_IOCTL : D_WARNING,
2086 "iocontrol OSC %s on OST "
2087 "idx %d cmd %x: err = %d\n",
2088 lov_uuid2str(lov, i),
2105 #define FIEMAP_BUFFER_SIZE 4096
2108 * Non-zero fe_logical indicates that this is a continuation FIEMAP
2109 * call. The local end offset and the device are sent in the first
2110 * fm_extent. This function calculates the stripe number from the index.
2111 * This function returns a stripe_no on which mapping is to be restarted.
2113 * This function returns fm_end_offset which is the in-OST offset at which
2114 * mapping should be restarted. If fm_end_offset=0 is returned then caller
2115 * will re-calculate proper offset in next stripe.
2116 * Note that the first extent is passed to lov_get_info via the value field.
2118 * \param fiemap fiemap request header
2119 * \param lsm striping information for the file
2120 * \param fm_start logical start of mapping
2121 * \param fm_end logical end of mapping
2122 * \param start_stripe starting stripe will be returned in this
2124 obd_size fiemap_calc_fm_end_offset(struct ll_user_fiemap *fiemap,
2125 struct lov_stripe_md *lsm, obd_size fm_start,
2126 obd_size fm_end, int *start_stripe)
2128 obd_size local_end = fiemap->fm_extents[0].fe_logical;
2129 obd_off lun_start, lun_end;
2130 obd_size fm_end_offset;
2131 int stripe_no = -1, i;
2133 if (fiemap->fm_extent_count == 0 ||
2134 fiemap->fm_extents[0].fe_logical == 0)
2137 /* Find out stripe_no from ost_index saved in the fe_device */
2138 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2139 if (lsm->lsm_oinfo[i]->loi_ost_idx ==
2140 fiemap->fm_extents[0].fe_device) {
2145 if (stripe_no == -1)
2148 /* If we have finished mapping on previous device, shift logical
2149 * offset to start of next device */
2150 if ((lov_stripe_intersects(lsm, stripe_no, fm_start, fm_end,
2151 &lun_start, &lun_end)) != 0 &&
2152 local_end < lun_end) {
2153 fm_end_offset = local_end;
2154 *start_stripe = stripe_no;
2156 /* This is a special value to indicate that caller should
2157 * calculate offset in next stripe. */
2159 *start_stripe = (stripe_no + 1) % lsm->lsm_stripe_count;
2162 return fm_end_offset;
2166 * We calculate on which OST the mapping will end. If the length of mapping
2167 * is greater than (stripe_size * stripe_count) then the last_stripe will
2168 * will be one just before start_stripe. Else we check if the mapping
2169 * intersects each OST and find last_stripe.
2170 * This function returns the last_stripe and also sets the stripe_count
2171 * over which the mapping is spread
2173 * \param lsm striping information for the file
2174 * \param fm_start logical start of mapping
2175 * \param fm_end logical end of mapping
2176 * \param start_stripe starting stripe of the mapping
2177 * \param stripe_count the number of stripes across which to map is returned
2179 * \retval last_stripe return the last stripe of the mapping
2181 int fiemap_calc_last_stripe(struct lov_stripe_md *lsm, obd_size fm_start,
2182 obd_size fm_end, int start_stripe,
2186 obd_off obd_start, obd_end;
2189 if (fm_end - fm_start > lsm->lsm_stripe_size * lsm->lsm_stripe_count) {
2190 last_stripe = (start_stripe < 1 ? lsm->lsm_stripe_count - 1 :
2192 *stripe_count = lsm->lsm_stripe_count;
2194 for (j = 0, i = start_stripe; j < lsm->lsm_stripe_count;
2195 i = (i + 1) % lsm->lsm_stripe_count, j++) {
2196 if ((lov_stripe_intersects(lsm, i, fm_start, fm_end,
2197 &obd_start, &obd_end)) == 0)
2201 last_stripe = (start_stripe + j - 1) %lsm->lsm_stripe_count;
2208 * Set fe_device and copy extents from local buffer into main return buffer.
2210 * \param fiemap fiemap request header
2211 * \param lcl_fm_ext array of local fiemap extents to be copied
2212 * \param ost_index OST index to be written into the fm_device field for each
2214 * \param ext_count number of extents to be copied
2215 * \param current_extent where to start copying in main extent array
2217 void fiemap_prepare_and_copy_exts(struct ll_user_fiemap *fiemap,
2218 struct ll_fiemap_extent *lcl_fm_ext,
2219 int ost_index, unsigned int ext_count,
2225 for (ext = 0; ext < ext_count; ext++) {
2226 lcl_fm_ext[ext].fe_device = ost_index;
2227 lcl_fm_ext[ext].fe_flags |= FIEMAP_EXTENT_NET;
2230 /* Copy fm_extent's from fm_local to return buffer */
2231 to = (char *)fiemap + fiemap_count_to_size(current_extent);
2232 memcpy(to, lcl_fm_ext, ext_count * sizeof(struct ll_fiemap_extent));
2236 * Break down the FIEMAP request and send appropriate calls to individual OSTs.
2237 * This also handles the restarting of FIEMAP calls in case mapping overflows
2238 * the available number of extents in single call.
2240 static int lov_fiemap(struct lov_obd *lov, __u32 keylen, void *key,
2241 __u32 *vallen, void *val, struct lov_stripe_md *lsm)
2243 struct ll_fiemap_info_key *fm_key = key;
2244 struct ll_user_fiemap *fiemap = val;
2245 struct ll_user_fiemap *fm_local = NULL;
2246 struct ll_fiemap_extent *lcl_fm_ext;
2248 unsigned int get_num_extents = 0;
2249 int ost_index = 0, actual_start_stripe, start_stripe;
2250 obd_size fm_start, fm_end, fm_length, fm_end_offset;
2252 int current_extent = 0, rc = 0, i;
2253 int ost_eof = 0; /* EOF for object */
2254 int ost_done = 0; /* done with required mapping for this OST? */
2256 int cur_stripe = 0, cur_stripe_wrap = 0, stripe_count;
2257 unsigned int buffer_size = FIEMAP_BUFFER_SIZE;
2259 if (!lsm_has_objects(lsm)) {
2260 if (lsm && lsm_is_released(lsm) && (fm_key->fiemap.fm_start <
2261 fm_key->oa.o_size)) {
2262 /* released file, return a minimal FIEMAP if
2263 * request fits in file-size.
2265 fiemap->fm_mapped_extents = 1;
2266 fiemap->fm_extents[0].fe_logical =
2267 fm_key->fiemap.fm_start;
2268 if (fm_key->fiemap.fm_start + fm_key->fiemap.fm_length <
2270 fiemap->fm_extents[0].fe_length =
2271 fm_key->fiemap.fm_length;
2273 fiemap->fm_extents[0].fe_length =
2275 fm_key->fiemap.fm_start;
2276 fiemap->fm_extents[0].fe_flags |=
2277 (FIEMAP_EXTENT_UNKNOWN |
2278 FIEMAP_EXTENT_LAST);
2283 if (fiemap_count_to_size(fm_key->fiemap.fm_extent_count) < buffer_size)
2284 buffer_size = fiemap_count_to_size(fm_key->fiemap.fm_extent_count);
2286 OBD_ALLOC_LARGE(fm_local, buffer_size);
2287 if (fm_local == NULL)
2288 GOTO(out, rc = -ENOMEM);
2289 lcl_fm_ext = &fm_local->fm_extents[0];
2291 count_local = fiemap_size_to_count(buffer_size);
2293 memcpy(fiemap, &fm_key->fiemap, sizeof(*fiemap));
2294 fm_start = fiemap->fm_start;
2295 fm_length = fiemap->fm_length;
2296 /* Calculate start stripe, last stripe and length of mapping */
2297 actual_start_stripe = start_stripe = lov_stripe_number(lsm, fm_start);
2298 fm_end = (fm_length == ~0ULL ? fm_key->oa.o_size :
2299 fm_start + fm_length - 1);
2300 /* If fm_length != ~0ULL but fm_start+fm_length-1 exceeds file size */
2301 if (fm_end > fm_key->oa.o_size)
2302 fm_end = fm_key->oa.o_size;
2304 last_stripe = fiemap_calc_last_stripe(lsm, fm_start, fm_end,
2305 actual_start_stripe, &stripe_count);
2307 fm_end_offset = fiemap_calc_fm_end_offset(fiemap, lsm, fm_start,
2308 fm_end, &start_stripe);
2309 if (fm_end_offset == -EINVAL)
2310 GOTO(out, rc = -EINVAL);
2312 if (fiemap->fm_extent_count == 0) {
2313 get_num_extents = 1;
2317 /* Check each stripe */
2318 for (cur_stripe = start_stripe, i = 0; i < stripe_count;
2319 i++, cur_stripe = (cur_stripe + 1) % lsm->lsm_stripe_count) {
2320 obd_size req_fm_len; /* Stores length of required mapping */
2321 obd_size len_mapped_single_call;
2322 obd_off lun_start, lun_end, obd_object_end;
2323 unsigned int ext_count;
2325 cur_stripe_wrap = cur_stripe;
2327 /* Find out range of mapping on this stripe */
2328 if ((lov_stripe_intersects(lsm, cur_stripe, fm_start, fm_end,
2329 &lun_start, &obd_object_end)) == 0)
2332 /* If this is a continuation FIEMAP call and we are on
2333 * starting stripe then lun_start needs to be set to
2335 if (fm_end_offset != 0 && cur_stripe == start_stripe)
2336 lun_start = fm_end_offset;
2338 if (fm_length != ~0ULL) {
2339 /* Handle fm_start + fm_length overflow */
2340 if (fm_start + fm_length < fm_start)
2341 fm_length = ~0ULL - fm_start;
2342 lun_end = lov_size_to_stripe(lsm, fm_start + fm_length,
2348 if (lun_start == lun_end)
2351 req_fm_len = obd_object_end - lun_start;
2352 fm_local->fm_length = 0;
2353 len_mapped_single_call = 0;
2355 /* If the output buffer is very large and the objects have many
2356 * extents we may need to loop on a single OST repeatedly */
2360 if (get_num_extents == 0) {
2361 /* Don't get too many extents. */
2362 if (current_extent + count_local >
2363 fiemap->fm_extent_count)
2364 count_local = fiemap->fm_extent_count -
2368 lun_start += len_mapped_single_call;
2369 fm_local->fm_length = req_fm_len - len_mapped_single_call;
2370 req_fm_len = fm_local->fm_length;
2371 fm_local->fm_extent_count = count_local;
2372 fm_local->fm_mapped_extents = 0;
2373 fm_local->fm_flags = fiemap->fm_flags;
2375 fm_key->oa.o_oi = lsm->lsm_oinfo[cur_stripe]->loi_oi;
2376 ost_index = lsm->lsm_oinfo[cur_stripe]->loi_ost_idx;
2378 if (ost_index < 0 || ost_index >=lov->desc.ld_tgt_count)
2379 GOTO(out, rc = -EINVAL);
2381 /* If OST is inactive, return extent with UNKNOWN flag */
2382 if (!lov->lov_tgts[ost_index]->ltd_active) {
2383 fm_local->fm_flags |= FIEMAP_EXTENT_LAST;
2384 fm_local->fm_mapped_extents = 1;
2386 lcl_fm_ext[0].fe_logical = lun_start;
2387 lcl_fm_ext[0].fe_length = obd_object_end -
2389 lcl_fm_ext[0].fe_flags |= FIEMAP_EXTENT_UNKNOWN;
2394 fm_local->fm_start = lun_start;
2395 fm_local->fm_flags &= ~FIEMAP_FLAG_DEVICE_ORDER;
2396 memcpy(&fm_key->fiemap, fm_local, sizeof(*fm_local));
2397 *vallen=fiemap_count_to_size(fm_local->fm_extent_count);
2398 rc = obd_get_info(NULL,
2399 lov->lov_tgts[ost_index]->ltd_exp,
2400 keylen, key, vallen, fm_local, lsm);
2405 ext_count = fm_local->fm_mapped_extents;
2406 if (ext_count == 0) {
2408 /* If last stripe has hole at the end,
2409 * then we need to return */
2410 if (cur_stripe_wrap == last_stripe) {
2411 fiemap->fm_mapped_extents = 0;
2417 /* If we just need num of extents then go to next device */
2418 if (get_num_extents) {
2419 current_extent += ext_count;
2423 len_mapped_single_call = lcl_fm_ext[ext_count-1].fe_logical -
2424 lun_start + lcl_fm_ext[ext_count - 1].fe_length;
2426 /* Have we finished mapping on this device? */
2427 if (req_fm_len <= len_mapped_single_call)
2430 /* Clear the EXTENT_LAST flag which can be present on
2432 if (lcl_fm_ext[ext_count-1].fe_flags & FIEMAP_EXTENT_LAST)
2433 lcl_fm_ext[ext_count - 1].fe_flags &=
2434 ~FIEMAP_EXTENT_LAST;
2436 curr_loc = lov_stripe_size(lsm,
2437 lcl_fm_ext[ext_count - 1].fe_logical+
2438 lcl_fm_ext[ext_count - 1].fe_length,
2440 if (curr_loc >= fm_key->oa.o_size)
2443 fiemap_prepare_and_copy_exts(fiemap, lcl_fm_ext,
2444 ost_index, ext_count,
2447 current_extent += ext_count;
2449 /* Ran out of available extents? */
2450 if (current_extent >= fiemap->fm_extent_count)
2452 } while (ost_done == 0 && ost_eof == 0);
2454 if (cur_stripe_wrap == last_stripe)
2459 /* Indicate that we are returning device offsets unless file just has
2461 if (lsm->lsm_stripe_count > 1)
2462 fiemap->fm_flags |= FIEMAP_FLAG_DEVICE_ORDER;
2464 if (get_num_extents)
2465 goto skip_last_device_calc;
2467 /* Check if we have reached the last stripe and whether mapping for that
2468 * stripe is done. */
2469 if (cur_stripe_wrap == last_stripe) {
2470 if (ost_done || ost_eof)
2471 fiemap->fm_extents[current_extent - 1].fe_flags |=
2475 skip_last_device_calc:
2476 fiemap->fm_mapped_extents = current_extent;
2480 OBD_FREE_LARGE(fm_local, buffer_size);
2484 static int lov_get_info(const struct lu_env *env, struct obd_export *exp,
2485 __u32 keylen, void *key, __u32 *vallen, void *val,
2486 struct lov_stripe_md *lsm)
2488 struct obd_device *obddev = class_exp2obd(exp);
2489 struct lov_obd *lov = &obddev->u.lov;
2493 if (!vallen || !val)
2498 if (KEY_IS(KEY_LOCK_TO_STRIPE)) {
2501 struct ldlm_lock *lock;
2503 struct ldlm_res_id *res_id = &data->lock->l_resource->lr_name;
2504 struct lov_oinfo *loi;
2505 __u32 *stripe = val;
2507 if (*vallen < sizeof(*stripe))
2508 GOTO(out, rc = -EFAULT);
2509 *vallen = sizeof(*stripe);
2511 /* XXX This is another one of those bits that will need to
2512 * change if we ever actually support nested LOVs. It uses
2513 * the lock's export to find out which stripe it is. */
2514 /* XXX - it's assumed all the locks for deleted OSTs have
2515 * been cancelled. Also, the export for deleted OSTs will
2516 * be NULL and won't match the lock's export. */
2517 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2518 loi = lsm->lsm_oinfo[i];
2519 if (!lov->lov_tgts[loi->loi_ost_idx])
2521 if (lov->lov_tgts[loi->loi_ost_idx]->ltd_exp ==
2522 data->lock->l_conn_export &&
2523 ostid_res_name_eq(&loi->loi_oi, res_id)) {
2528 LDLM_ERROR(data->lock, "lock on inode without such object");
2529 dump_lsm(D_ERROR, lsm);
2530 GOTO(out, rc = -ENXIO);
2531 } else if (KEY_IS(KEY_LAST_ID)) {
2532 struct obd_id_info *info = val;
2533 __u32 size = sizeof(obd_id);
2534 struct lov_tgt_desc *tgt;
2536 LASSERT(*vallen == sizeof(struct obd_id_info));
2537 tgt = lov->lov_tgts[info->idx];
2539 if (!tgt || !tgt->ltd_active)
2540 GOTO(out, rc = -ESRCH);
2542 rc = obd_get_info(env, tgt->ltd_exp, keylen, key,
2543 &size, info->data, NULL);
2545 } else if (KEY_IS(KEY_LOVDESC)) {
2546 struct lov_desc *desc_ret = val;
2547 *desc_ret = lov->desc;
2550 } else if (KEY_IS(KEY_FIEMAP)) {
2551 rc = lov_fiemap(lov, keylen, key, vallen, val, lsm);
2553 } else if (KEY_IS(KEY_CONNECT_FLAG)) {
2554 struct lov_tgt_desc *tgt;
2555 __u64 ost_idx = *((__u64*)val);
2557 LASSERT(*vallen == sizeof(__u64));
2558 LASSERT(ost_idx < lov->desc.ld_tgt_count);
2559 tgt = lov->lov_tgts[ost_idx];
2561 if (!tgt || !tgt->ltd_exp)
2562 GOTO(out, rc = -ESRCH);
2564 *((__u64 *)val) = exp_connect_flags(tgt->ltd_exp);
2566 } else if (KEY_IS(KEY_TGT_COUNT)) {
2567 *((int *)val) = lov->desc.ld_tgt_count;
2578 static int lov_set_info_async(const struct lu_env *env, struct obd_export *exp,
2579 obd_count keylen, void *key, obd_count vallen,
2580 void *val, struct ptlrpc_request_set *set)
2582 struct obd_device *obddev = class_exp2obd(exp);
2583 struct lov_obd *lov = &obddev->u.lov;
2586 struct lov_tgt_desc *tgt;
2587 unsigned incr, check_uuid,
2588 do_inactive, no_set;
2589 unsigned next_id = 0, mds_con = 0, capa = 0;
2592 incr = check_uuid = do_inactive = no_set = 0;
2595 set = ptlrpc_prep_set();
2601 count = lov->desc.ld_tgt_count;
2603 if (KEY_IS(KEY_NEXT_ID)) {
2604 count = vallen / sizeof(struct obd_id_info);
2605 vallen = sizeof(obd_id);
2606 incr = sizeof(struct obd_id_info);
2609 } else if (KEY_IS(KEY_CHECKSUM)) {
2611 } else if (KEY_IS(KEY_EVICT_BY_NID)) {
2612 /* use defaults: do_inactive = incr = 0; */
2613 } else if (KEY_IS(KEY_MDS_CONN)) {
2615 } else if (KEY_IS(KEY_CAPA_KEY)) {
2617 } else if (KEY_IS(KEY_CACHE_SET)) {
2618 LASSERT(lov->lov_cache == NULL);
2619 lov->lov_cache = val;
2623 for (i = 0; i < count; i++, val = (char *)val + incr) {
2625 tgt = lov->lov_tgts[((struct obd_id_info*)val)->idx];
2627 tgt = lov->lov_tgts[i];
2629 /* OST was disconnected */
2630 if (!tgt || !tgt->ltd_exp)
2633 /* OST is inactive and we don't want inactive OSCs */
2634 if (!tgt->ltd_active && !do_inactive)
2638 struct mds_group_info *mgi;
2640 LASSERT(vallen == sizeof(*mgi));
2641 mgi = (struct mds_group_info *)val;
2643 /* Only want a specific OSC */
2644 if (mgi->uuid && !obd_uuid_equals(mgi->uuid,
2648 err = obd_set_info_async(env, tgt->ltd_exp,
2649 keylen, key, sizeof(int),
2651 } else if (next_id) {
2652 err = obd_set_info_async(env, tgt->ltd_exp,
2653 keylen, key, vallen,
2654 ((struct obd_id_info*)val)->data, set);
2656 struct mds_capa_info *info = (struct mds_capa_info*)val;
2658 LASSERT(vallen == sizeof(*info));
2660 /* Only want a specific OSC */
2662 !obd_uuid_equals(info->uuid, &tgt->ltd_uuid))
2665 err = obd_set_info_async(env, tgt->ltd_exp, keylen,
2666 key, sizeof(*info->capa),
2669 /* Only want a specific OSC */
2671 !obd_uuid_equals(val, &tgt->ltd_uuid))
2674 err = obd_set_info_async(env, tgt->ltd_exp,
2675 keylen, key, vallen, val, set);
2684 err = ptlrpc_set_wait(set);
2687 ptlrpc_set_destroy(set);
2692 static int lov_extent_calc(struct obd_export *exp, struct lov_stripe_md *lsm,
2693 int cmd, __u64 *offset)
2695 __u32 ssize = lsm->lsm_stripe_size;
2699 lov_do_div64(start, ssize);
2700 start = start * ssize;
2702 CDEBUG(D_DLMTRACE, "offset "LPU64", stripe %u, start "LPU64
2703 ", end "LPU64"\n", *offset, ssize, start,
2705 if (cmd == OBD_CALC_STRIPE_END) {
2706 *offset = start + ssize - 1;
2707 } else if (cmd == OBD_CALC_STRIPE_START) {
2716 void lov_stripe_lock(struct lov_stripe_md *md)
2718 LASSERT(md->lsm_lock_owner != current_pid());
2719 spin_lock(&md->lsm_lock);
2720 LASSERT(md->lsm_lock_owner == 0);
2721 md->lsm_lock_owner = current_pid();
2723 EXPORT_SYMBOL(lov_stripe_lock);
2725 void lov_stripe_unlock(struct lov_stripe_md *md)
2727 LASSERT(md->lsm_lock_owner == current_pid());
2728 md->lsm_lock_owner = 0;
2729 spin_unlock(&md->lsm_lock);
2731 EXPORT_SYMBOL(lov_stripe_unlock);
2733 static int lov_quotactl(struct obd_device *obd, struct obd_export *exp,
2734 struct obd_quotactl *oqctl)
2736 struct lov_obd *lov = &obd->u.lov;
2737 struct lov_tgt_desc *tgt;
2739 __u64 bhardlimit = 0;
2743 if (oqctl->qc_cmd != LUSTRE_Q_QUOTAON &&
2744 oqctl->qc_cmd != LUSTRE_Q_QUOTAOFF &&
2745 oqctl->qc_cmd != Q_GETOQUOTA &&
2746 oqctl->qc_cmd != Q_INITQUOTA &&
2747 oqctl->qc_cmd != LUSTRE_Q_SETQUOTA &&
2748 oqctl->qc_cmd != Q_FINVALIDATE) {
2749 CERROR("bad quota opc %x for lov obd", oqctl->qc_cmd);
2755 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2758 tgt = lov->lov_tgts[i];
2763 if (!tgt->ltd_active || tgt->ltd_reap) {
2764 if (oqctl->qc_cmd == Q_GETOQUOTA &&
2765 lov->lov_tgts[i]->ltd_activate) {
2767 CERROR("ost %d is inactive\n", i);
2769 CDEBUG(D_HA, "ost %d is inactive\n", i);
2774 err = obd_quotactl(tgt->ltd_exp, oqctl);
2776 if (tgt->ltd_active && !rc)
2781 if (oqctl->qc_cmd == Q_GETOQUOTA) {
2782 curspace += oqctl->qc_dqblk.dqb_curspace;
2783 bhardlimit += oqctl->qc_dqblk.dqb_bhardlimit;
2788 if (oqctl->qc_cmd == Q_GETOQUOTA) {
2789 oqctl->qc_dqblk.dqb_curspace = curspace;
2790 oqctl->qc_dqblk.dqb_bhardlimit = bhardlimit;
2795 static int lov_quotacheck(struct obd_device *obd, struct obd_export *exp,
2796 struct obd_quotactl *oqctl)
2798 struct lov_obd *lov = &obd->u.lov;
2804 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2805 if (!lov->lov_tgts[i])
2808 /* Skip quota check on the administratively disabled OSTs. */
2809 if (!lov->lov_tgts[i]->ltd_activate) {
2810 CWARN("lov idx %d was administratively disabled, "
2811 "skip quotacheck on it.\n", i);
2815 if (!lov->lov_tgts[i]->ltd_active) {
2816 CERROR("lov idx %d inactive\n", i);
2822 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2825 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_activate)
2828 err = obd_quotacheck(lov->lov_tgts[i]->ltd_exp, oqctl);
2839 struct obd_ops lov_obd_ops = {
2840 .o_owner = THIS_MODULE,
2841 .o_setup = lov_setup,
2842 .o_precleanup = lov_precleanup,
2843 .o_cleanup = lov_cleanup,
2844 //.o_process_config = lov_process_config,
2845 .o_connect = lov_connect,
2846 .o_disconnect = lov_disconnect,
2847 .o_statfs = lov_statfs,
2848 .o_statfs_async = lov_statfs_async,
2849 .o_packmd = lov_packmd,
2850 .o_unpackmd = lov_unpackmd,
2851 .o_create = lov_create,
2852 .o_destroy = lov_destroy,
2853 .o_getattr = lov_getattr,
2854 .o_getattr_async = lov_getattr_async,
2855 .o_setattr = lov_setattr,
2856 .o_setattr_async = lov_setattr_async,
2858 .o_merge_lvb = lov_merge_lvb,
2859 .o_adjust_kms = lov_adjust_kms,
2860 .o_punch = lov_punch,
2862 .o_enqueue = lov_enqueue,
2863 .o_change_cbdata = lov_change_cbdata,
2864 .o_find_cbdata = lov_find_cbdata,
2865 .o_cancel = lov_cancel,
2866 .o_cancel_unused = lov_cancel_unused,
2867 .o_iocontrol = lov_iocontrol,
2868 .o_get_info = lov_get_info,
2869 .o_set_info_async = lov_set_info_async,
2870 .o_extent_calc = lov_extent_calc,
2871 .o_notify = lov_notify,
2872 .o_pool_new = lov_pool_new,
2873 .o_pool_rem = lov_pool_remove,
2874 .o_pool_add = lov_pool_add,
2875 .o_pool_del = lov_pool_del,
2876 .o_getref = lov_getref,
2877 .o_putref = lov_putref,
2878 .o_quotactl = lov_quotactl,
2879 .o_quotacheck = lov_quotacheck,
2882 struct kmem_cache *lov_oinfo_slab;
2884 extern struct lu_kmem_descr lov_caches[];
2886 int __init lov_init(void)
2891 /* print an address of _any_ initialized kernel symbol from this
2892 * module, to allow debugging with gdb that doesn't support data
2893 * symbols from modules.*/
2894 CDEBUG(D_INFO, "Lustre LOV module (%p).\n", &lov_caches);
2896 rc = lu_kmem_init(lov_caches);
2900 lov_oinfo_slab = kmem_cache_create("lov_oinfo",
2901 sizeof(struct lov_oinfo), 0,
2902 SLAB_HWCACHE_ALIGN, NULL);
2903 if (lov_oinfo_slab == NULL) {
2904 lu_kmem_fini(lov_caches);
2908 rc = class_register_type(&lov_obd_ops, NULL, NULL,
2909 #ifndef HAVE_ONLY_PROCFS_SEQ
2912 LUSTRE_LOV_NAME, &lov_device_type);
2915 kmem_cache_destroy(lov_oinfo_slab);
2916 lu_kmem_fini(lov_caches);
2923 static void /*__exit*/ lov_exit(void)
2925 class_unregister_type(LUSTRE_LOV_NAME);
2926 kmem_cache_destroy(lov_oinfo_slab);
2927 lu_kmem_fini(lov_caches);
2930 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2931 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver");
2932 MODULE_LICENSE("GPL");
2934 cfs_module(lov, LUSTRE_VERSION_STRING, lov_init, lov_exit);