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 (c) 2002, 2010, Oracle and/or its affiliates. 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 <lustre_cache.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 static 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 static void lov_putref(struct obd_device *obd)
89 struct lov_obd *lov = &obd->u.lov;
91 struct lov_tgt_desc *tgt;
93 mutex_down(&lov->lov_lock);
94 /* ok to dec to 0 more than once -- ltd_exp's will be null */
95 if (atomic_dec_and_test(&lov->lov_refcount) && lov->lov_death_row) {
97 struct lov_tgt_desc *n;
98 CDEBUG(D_CONFIG, "destroying %d lov targets\n",
100 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
101 tgt = lov->lov_tgts[i];
103 if (!tgt || !tgt->ltd_reap)
105 list_add(&tgt->ltd_kill, &kill);
106 /* XXX - right now there is a dependency on ld_tgt_count
107 * being the maximum tgt index for computing the
108 * mds_max_easize. So we can't shrink it. */
109 lov_ost_pool_remove(&lov->lov_packed, i);
110 lov->lov_tgts[i] = NULL;
111 lov->lov_death_row--;
113 mutex_up(&lov->lov_lock);
115 list_for_each_entry_safe(tgt, n, &kill, ltd_kill) {
116 list_del(&tgt->ltd_kill);
118 __lov_del_obd(obd, tgt);
121 mutex_up(&lov->lov_lock);
125 static int lov_obd_register_page_removal_cb(struct obd_device *obd,
126 obd_page_removal_cb_t func,
127 obd_pin_extent_cb pin_cb)
129 struct lov_obd *lov = &obd->u.lov;
131 if (lov->lov_page_removal_cb && lov->lov_page_removal_cb != func)
134 if (lov->lov_page_pin_cb && lov->lov_page_pin_cb != pin_cb)
137 lov->lov_page_removal_cb = func;
138 lov->lov_page_pin_cb = pin_cb;
142 static int lov_obd_unregister_page_removal_cb(struct obd_device *obd,
143 obd_page_removal_cb_t func)
145 struct lov_obd *lov = &obd->u.lov;
148 if (lov->lov_page_removal_cb && lov->lov_page_removal_cb != func)
151 lov->lov_page_removal_cb = NULL;
152 lov->lov_page_pin_cb = NULL;
155 for (i = 0; i < lov->desc.ld_tgt_count; ++i) {
156 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
158 rc |= obd_unregister_page_removal_cb(
159 lov->lov_tgts[i]->ltd_exp->exp_obd, func);
166 static int lov_obd_register_lock_cancel_cb(struct obd_device *obd,
167 obd_lock_cancel_cb func)
169 struct lov_obd *lov = &obd->u.lov;
171 if (lov->lov_lock_cancel_cb && lov->lov_lock_cancel_cb != func)
174 lov->lov_lock_cancel_cb = func;
179 static int lov_obd_unregister_lock_cancel_cb(struct obd_device *obd,
180 obd_lock_cancel_cb func)
182 struct lov_obd *lov = &obd->u.lov;
184 if (lov->lov_lock_cancel_cb && lov->lov_lock_cancel_cb != func)
187 lov->lov_lock_cancel_cb = NULL;
192 static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
193 enum obd_notify_event ev);
195 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
196 enum obd_notify_event ev, void *data)
201 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE ||
202 ev == OBD_NOTIFY_ACTIVATE || ev == OBD_NOTIFY_DEACTIVATE) {
205 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
206 CERROR("unexpected notification of %s %s!\n",
207 watched->obd_type->typ_name,
212 /* Set OSC as active before notifying the observer, so the
213 * observer can use the OSC normally.
215 rc = lov_set_osc_active(obd, &watched->u.cli.cl_target_uuid,
218 CERROR("event(%d) of %s failed: %d\n", ev,
219 obd_uuid2str(&watched->u.cli.cl_target_uuid),
223 /* active event should be pass lov target index as data */
227 /* Pass the notification up the chain. */
229 rc = obd_notify_observer(obd, watched, ev, data);
231 /* NULL watched means all osc's in the lov (only for syncs) */
232 /* sync event should be send lov idx as data */
233 struct lov_obd *lov = &obd->u.lov;
237 is_sync = (ev == OBD_NOTIFY_SYNC) ||
238 (ev == OBD_NOTIFY_SYNC_NONBLOCK);
241 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
243 if (!lov->lov_tgts[i])
245 /* don't send sync event if target not
246 * connected/activated */
247 if (is_sync && !lov->lov_tgts[i]->ltd_active)
250 rc = obd_notify_observer(obd, lov->lov_tgts[i]->ltd_obd,
253 CERROR("%s: notify %s of %s failed %d\n",
255 obd->obd_observer->obd_name,
256 lov->lov_tgts[i]->ltd_obd->obd_name, rc);
265 #define MAX_STRING_SIZE 128
266 static int lov_connect_obd(struct obd_device *obd, __u32 index, int activate,
267 struct obd_connect_data *data)
269 struct lov_obd *lov = &obd->u.lov;
270 struct obd_uuid tgt_uuid;
271 struct obd_device *tgt_obd;
272 struct obd_uuid lov_osc_uuid = { "LOV_OSC_UUID" };
273 struct lustre_handle conn = {0, };
274 struct obd_import *imp;
276 cfs_proc_dir_entry_t *lov_proc_dir;
281 if (!lov->lov_tgts[index])
284 tgt_obd = lov->lov_tgts[index]->ltd_obd;
285 if (!tgt_obd->obd_set_up) {
286 CERROR("Target %s not set up\n", obd_uuid2str(&tgt_uuid));
290 if (data && (data->ocd_connect_flags & OBD_CONNECT_INDEX))
291 data->ocd_index = index;
294 * Divine LOV knows that OBDs under it are OSCs.
296 imp = tgt_obd->u.cli.cl_import;
299 tgt_obd->obd_no_recov = 0;
300 /* FIXME this is probably supposed to be
301 ptlrpc_set_import_active. Horrible naming. */
302 ptlrpc_activate_import(imp);
305 rc = obd_register_observer(tgt_obd, obd);
307 CERROR("Target %s register_observer error %d; "
308 "will not be able to reactivate\n",
309 obd_uuid2str(&tgt_uuid), rc);
313 if (imp->imp_invalid) {
314 CDEBUG(D_CONFIG, "not connecting OSC %s; administratively "
315 "disabled\n", obd_uuid2str(&tgt_uuid));
318 if (lov->lov_lock_cancel_cb)
319 rc = obd_register_lock_cancel_cb(tgt_obd, lov->lov_lock_cancel_cb);
323 if (lov->lov_page_removal_cb)
324 rc = obd_register_page_removal_cb(tgt_obd, lov->lov_page_removal_cb,
325 lov->lov_page_pin_cb);
327 GOTO(out_lock_cb, rc);
329 rc = obd_connect(&conn, tgt_obd, &lov_osc_uuid, data, &lov->lov_tgts[index]->ltd_exp);
330 if (rc || !lov->lov_tgts[index]->ltd_exp) {
331 CERROR("Target %s connect error %d\n",
332 obd_uuid2str(&tgt_uuid), rc);
333 GOTO(out_page_cb, rc);
337 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
339 struct obd_device *osc_obd = class_conn2obd(&conn);
340 cfs_proc_dir_entry_t *osc_symlink;
341 char name[MAX_STRING_SIZE];
343 LASSERT(osc_obd != NULL);
344 LASSERT(osc_obd->obd_magic == OBD_DEVICE_MAGIC);
345 LASSERT(osc_obd->obd_type->typ_name != NULL);
346 snprintf(name, MAX_STRING_SIZE, "../../../%s/%s",
347 osc_obd->obd_type->typ_name,
349 osc_symlink = proc_symlink(osc_obd->obd_name, lov_proc_dir,
351 if (osc_symlink == NULL) {
352 CERROR("could not register LOV target "
353 "/proc/fs/lustre/%s/%s/target_obds/%s.",
354 obd->obd_type->typ_name, obd->obd_name,
356 lprocfs_remove(&lov_proc_dir);
360 rc = qos_add_tgt(obd, index);
362 CERROR("qos_add_tgt failed %d\n", rc);
367 obd_unregister_page_removal_cb(obd, lov->lov_page_removal_cb);
369 obd_unregister_lock_cancel_cb(obd, lov->lov_lock_cancel_cb);
374 static int lov_connect(struct lustre_handle *conn, struct obd_device *obd,
375 struct obd_uuid *cluuid, struct obd_connect_data *data,
378 struct lov_obd *lov = &obd->u.lov;
379 struct lov_tgt_desc *tgt;
380 struct obd_export **exp = localdata;
384 CDEBUG(D_CONFIG, "connect #%d\n", lov->lov_connects);
386 rc = class_connect(conn, obd, cluuid);
390 *exp = class_conn2export(conn);
392 /* generate OBD_NOTIFY_CREATE events for already registered targets */
393 obd_notify(obd, NULL, OBD_NOTIFY_CREATE, NULL);
395 /* Why should there ever be more than 1 connect? */
397 LASSERT(lov->lov_connects == 1);
399 memset(&lov->lov_ocd, 0, sizeof(lov->lov_ocd));
401 lov->lov_ocd = *data;
404 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
405 tgt = lov->lov_tgts[i];
406 if (!tgt || obd_uuid_empty(&tgt->ltd_uuid))
408 /* Flags will be lowest common denominator */
409 rc = lov_connect_obd(obd, i, lov->lov_tgts[i]->ltd_activate,
412 CERROR("%s: lov connect tgt %d failed: %d\n",
413 obd->obd_name, i, rc);
416 /* connect to administrative disabled ost */
417 if (!lov->lov_tgts[i]->ltd_exp)
420 rc = lov_notify(obd, lov->lov_tgts[i]->ltd_exp->exp_obd,
421 OBD_NOTIFY_CONNECT, (void *)&i);
423 CERROR("%s error sending notify %d\n",
432 static int lov_disconnect_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
434 cfs_proc_dir_entry_t *lov_proc_dir;
435 struct lov_obd *lov = &obd->u.lov;
436 struct obd_device *osc_obd = class_exp2obd(tgt->ltd_exp);
441 CDEBUG(D_CONFIG, "%s: disconnecting target %s\n",
442 obd->obd_name, osc_obd->obd_name);
444 if (tgt->ltd_active) {
446 lov->desc.ld_active_tgt_count--;
447 tgt->ltd_exp->exp_obd->obd_inactive = 1;
450 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
452 cfs_proc_dir_entry_t *osc_symlink;
454 osc_symlink = lprocfs_srch(lov_proc_dir, osc_obd->obd_name);
456 lprocfs_remove(&osc_symlink);
458 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing.",
459 obd->obd_type->typ_name, obd->obd_name,
464 if (obd->obd_force) {
465 /* Pass it on to our clients.
466 * XXX This should be an argument to disconnect,
467 * XXX not a back-door flag on the OBD. Ah well.
470 osc_obd->obd_force = 1;
473 obd_register_observer(osc_obd, NULL);
475 obd_unregister_page_removal_cb(osc_obd, lov->lov_page_removal_cb);
476 obd_unregister_lock_cancel_cb(osc_obd, lov->lov_lock_cancel_cb);
478 rc = obd_disconnect(tgt->ltd_exp);
480 CERROR("Target %s disconnect error %d\n",
481 tgt->ltd_uuid.uuid, rc);
485 qos_del_tgt(obd, tgt);
492 static int lov_del_target(struct obd_device *obd, __u32 index,
493 struct obd_uuid *uuidp, int gen);
495 static int lov_disconnect(struct obd_export *exp)
497 struct obd_device *obd = class_exp2obd(exp);
498 struct lov_obd *lov = &obd->u.lov;
505 /* Only disconnect the underlying layers on the final disconnect. */
507 if (lov->lov_connects != 0) {
508 /* why should there be more than 1 connect? */
509 CERROR("disconnect #%d\n", lov->lov_connects);
513 /* Let's hold another reference so lov_del_obd doesn't spin through
516 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
517 if (lov->lov_tgts[i] && lov->lov_tgts[i]->ltd_exp) {
518 /* Disconnection is the last we know about an obd */
519 lov_del_target(obd, i, 0, lov->lov_tgts[i]->ltd_gen);
525 rc = class_disconnect(exp); /* bz 9811 */
531 * -EINVAL : UUID can't be found in the LOV's target list
532 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
533 * -EBADF : The UUID is found, but the OBD is the wrong type (!)
534 * - any above 0 is lov index
536 static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
537 enum obd_notify_event ev)
539 struct lov_obd *lov = &obd->u.lov;
540 struct lov_tgt_desc *tgt;
541 int i = 0, activate, active;
544 CDEBUG(D_INFO, "Searching in lov %p for uuid %s event(%d)\n",
545 lov, uuid->uuid, ev);
548 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
549 tgt = lov->lov_tgts[i];
550 if (!tgt || !tgt->ltd_exp)
553 CDEBUG(D_INFO, "lov idx %d is %s conn "LPX64"\n",
554 i, obd_uuid2str(&tgt->ltd_uuid),
555 tgt->ltd_exp->exp_handle.h_cookie);
556 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
560 if (i == lov->desc.ld_tgt_count)
561 GOTO(out, i = -EINVAL);
563 if (ev == OBD_NOTIFY_DEACTIVATE || ev == OBD_NOTIFY_ACTIVATE) {
564 activate = (ev == OBD_NOTIFY_ACTIVATE) ? 1 : 0;
566 if (lov->lov_tgts[i]->ltd_activate == activate) {
567 CDEBUG(D_INFO, "OSC %s already %sactivate!\n",
568 uuid->uuid, activate ? "" : "de");
570 lov->lov_tgts[i]->ltd_activate = activate;
571 CDEBUG(D_CONFIG, "%sactivate OSC %s\n",
572 activate ? "" : "de", obd_uuid2str(uuid));
577 active = (ev == OBD_NOTIFY_ACTIVE) ? 1 : 0;
579 if (lov->lov_tgts[i]->ltd_active == active) {
580 CDEBUG(D_INFO, "OSC %s already %sactive!\n", uuid->uuid,
585 CDEBUG(D_CONFIG, "Marking OSC %s %sactive\n", obd_uuid2str(uuid),
588 lov->lov_tgts[i]->ltd_active = active;
591 lov->desc.ld_active_tgt_count++;
592 lov->lov_tgts[i]->ltd_exp->exp_obd->obd_inactive = 0;
594 lov->desc.ld_active_tgt_count--;
595 lov->lov_tgts[i]->ltd_exp->exp_obd->obd_inactive = 1;
597 /* remove any old qos penalty */
598 lov->lov_tgts[i]->ltd_qos.ltq_penalty = 0;
606 static int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
607 __u32 index, int gen, int active)
609 struct obd_device *tgt_obd;
610 struct lov_obd *lov = &obd->u.lov;
611 struct lov_tgt_desc *tgt;
615 CDEBUG(D_CONFIG, "uuid:%s idx:%d gen:%d active:%d\n",
616 uuidp->uuid, index, gen, active);
619 CERROR("request to add OBD %s with invalid generation: %d\n",
625 tgt_obd = class_find_client_obd(uuidp, LUSTRE_OSC_NAME,
628 CERROR("Target %s not attached\n", obd_uuid2str(uuidp));
632 mutex_down(&lov->lov_lock);
634 if ((index < lov->lov_tgt_size) && (lov->lov_tgts[index] != NULL)) {
635 tgt = lov->lov_tgts[index];
636 CERROR("UUID %s already assigned at LOV target index %d\n",
637 obd_uuid2str(&tgt->ltd_uuid), index);
638 GOTO(err_unlock, rc = -EEXIST);
641 if (index >= lov->lov_tgt_size) {
642 /* We need to reallocate the lov target array. */
643 struct lov_tgt_desc **newtgts, **old = NULL;
644 __u32 newsize, oldsize = 0;
646 newsize = max(lov->lov_tgt_size, (__u32)2);
647 while (newsize < index + 1)
648 newsize = newsize << 1;
649 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
651 GOTO(err_unlock, rc = -ENOMEM);
653 if (lov->lov_tgt_size) {
654 memcpy(newtgts, lov->lov_tgts, sizeof(*newtgts) *
657 oldsize = lov->lov_tgt_size;
660 lov->lov_tgts = newtgts;
661 lov->lov_tgt_size = newsize;
666 OBD_FREE(old, sizeof(*old) * oldsize);
668 CDEBUG(D_CONFIG, "tgts: %p size: %d\n",
669 lov->lov_tgts, lov->lov_tgt_size);
674 GOTO(err_unlock, rc = -ENOMEM);
676 rc = lov_ost_pool_add(&lov->lov_packed, index, lov->lov_tgt_size);
678 GOTO(err_free_tgt, rc = -EEXIST);
680 memset(tgt, 0, sizeof(*tgt));
681 tgt->ltd_obd = tgt_obd;
682 tgt->ltd_uuid = *uuidp;
683 /* XXX - add a sanity check on the generation number. */
685 tgt->ltd_index = index;
686 tgt->ltd_activate = active;
688 lov->lov_tgts[index] = tgt;
689 if (index >= lov->desc.ld_tgt_count)
690 lov->desc.ld_tgt_count = index + 1;
692 mutex_up(&lov->lov_lock);
694 CDEBUG(D_CONFIG, "idx=%d ltd_gen=%d ld_tgt_count=%d\n",
695 index, tgt->ltd_gen, lov->desc.ld_tgt_count);
697 if (lov->lov_connects == 0) {
698 /* lov_connect hasn't been called yet. We'll do the
699 lov_connect_obd on this target when that fn first runs,
700 because we don't know the connect flags yet. */
704 rc = obd_notify(obd, tgt_obd, OBD_NOTIFY_CREATE, &index);
708 rc = lov_connect_obd(obd, index, active, &lov->lov_ocd);
712 /* connect to administrative disabled ost */
716 rc = lov_notify(obd, tgt->ltd_exp->exp_obd,
717 active ? OBD_NOTIFY_CONNECT : OBD_NOTIFY_INACTIVE,
721 /* connect or notify failed - we can try connect later
722 * instead of complete delete target */
723 CERROR("connect or notify failed (%d) for %s\n", rc,
724 obd_uuid2str(&tgt->ltd_uuid));
732 mutex_up(&lov->lov_lock);
736 /* Schedule a target for deletion */
737 static int lov_del_target(struct obd_device *obd, __u32 index,
738 struct obd_uuid *uuidp, int gen)
740 struct lov_obd *lov = &obd->u.lov;
741 int count = lov->desc.ld_tgt_count;
745 if (index >= count) {
746 CERROR("LOV target index %d >= number of LOV OBDs %d.\n",
753 if (!lov->lov_tgts[index]) {
754 CERROR("LOV target at index %d is not setup.\n", index);
755 GOTO(out, rc = -EINVAL);
758 if (uuidp && !obd_uuid_equals(uuidp, &lov->lov_tgts[index]->ltd_uuid)) {
759 CERROR("LOV target UUID %s at index %d doesn't match %s.\n",
760 lov_uuid2str(lov, index), index,
761 obd_uuid2str(uuidp));
762 GOTO(out, rc = -EINVAL);
765 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d exp: %p active: %d\n",
766 lov_uuid2str(lov, index), index,
767 lov->lov_tgts[index]->ltd_gen, lov->lov_tgts[index]->ltd_exp,
768 lov->lov_tgts[index]->ltd_active);
770 lov->lov_tgts[index]->ltd_reap = 1;
771 lov->lov_death_row++;
772 /* we really delete it from obd_putref */
779 static void __lov_del_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
781 struct obd_device *osc_obd;
784 LASSERT(tgt->ltd_reap);
786 osc_obd = class_exp2obd(tgt->ltd_exp);
788 CDEBUG(D_CONFIG, "Removing tgt %s : %s\n",
790 osc_obd ? osc_obd->obd_name : "<no obd>");
793 lov_disconnect_obd(obd, tgt);
797 /* Manual cleanup - no cleanup logs to clean up the osc's. We must
798 do it ourselves. And we can't do it from lov_cleanup,
799 because we just lost our only reference to it. */
801 /* Use lov's force/fail flags. */
802 osc_obd->obd_force = obd->obd_force;
803 osc_obd->obd_fail = obd->obd_fail;
804 class_manual_cleanup(osc_obd);
808 void lov_fix_desc_stripe_size(__u64 *val)
810 if (*val < PTLRPC_MAX_BRW_SIZE) {
812 LCONSOLE_WARN("Increasing default stripe size from "
813 LPU64" to %u\n",*val,PTLRPC_MAX_BRW_SIZE);
814 *val = PTLRPC_MAX_BRW_SIZE;
815 } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) {
816 *val &= ~(LOV_MIN_STRIPE_SIZE - 1);
817 LCONSOLE_WARN("Changing default stripe size to "LPU64" (a "
819 *val, LOV_MIN_STRIPE_SIZE);
823 void lov_fix_desc_stripe_count(__u32 *val)
829 void lov_fix_desc_pattern(__u32 *val)
831 /* from lov_setstripe */
832 if ((*val != 0) && (*val != LOV_PATTERN_RAID0)) {
833 LCONSOLE_WARN("Unknown stripe pattern: %#x\n", *val);
838 void lov_fix_desc_qos_maxage(__u32 *val)
842 *val = QOS_DEFAULT_MAXAGE;
845 void lov_fix_desc(struct lov_desc *desc)
847 lov_fix_desc_stripe_size(&desc->ld_default_stripe_size);
848 lov_fix_desc_stripe_count(&desc->ld_default_stripe_count);
849 lov_fix_desc_pattern(&desc->ld_pattern);
850 lov_fix_desc_qos_maxage(&desc->ld_qos_maxage);
853 static int lov_setup(struct obd_device *obd, obd_count len, void *buf)
855 struct lprocfs_static_vars lvars = { 0 };
856 struct lustre_cfg *lcfg = buf;
857 struct lov_desc *desc;
858 struct lov_obd *lov = &obd->u.lov;
862 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
863 CERROR("LOV setup requires a descriptor\n");
867 desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
869 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
870 CERROR("descriptor size wrong: %d > %d\n",
871 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
875 if (desc->ld_magic != LOV_DESC_MAGIC) {
876 if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
877 CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n",
878 obd->obd_name, desc);
879 lustre_swab_lov_desc(desc);
881 CERROR("%s: Bad lov desc magic: %#x\n",
882 obd->obd_name, desc->ld_magic);
889 desc->ld_active_tgt_count = 0;
891 lov->lov_tgt_size = 0;
893 sema_init(&lov->lov_lock, 1);
894 atomic_set(&lov->lov_refcount, 0);
895 CFS_INIT_LIST_HEAD(&lov->lov_qos.lq_oss_list);
896 init_rwsem(&lov->lov_qos.lq_rw_sem);
897 lov->lov_qos.lq_dirty = 1;
898 lov->lov_qos.lq_rr.lqr_dirty = 1;
899 lov->lov_qos.lq_reset = 1;
900 /* Default priority is toward free space balance */
901 lov->lov_qos.lq_prio_free = 232;
902 /* Default threshold for rr (roughly 17%) */
903 lov->lov_qos.lq_threshold_rr = 43;
904 /* Init statfs fields */
905 OBD_ALLOC_PTR(lov->lov_qos.lq_statfs_data);
906 if (NULL == lov->lov_qos.lq_statfs_data)
908 cfs_waitq_init(&lov->lov_qos.lq_statfs_waitq);
910 lov->lov_pools_hash_body = lustre_hash_init("POOLS",
913 &pool_hash_operations,
915 CFS_INIT_LIST_HEAD(&lov->lov_pool_list);
916 lov->lov_pool_count = 0;
917 rc = lov_ost_pool_init(&lov->lov_packed, 0);
920 rc = lov_ost_pool_init(&lov->lov_qos.lq_rr.lqr_pool, 0);
922 lov_ost_pool_free(&lov->lov_packed);
926 lprocfs_lov_init_vars(&lvars);
927 lprocfs_obd_setup(obd, lvars.obd_vars);
930 cfs_proc_dir_entry_t *entry;
932 entry = create_proc_entry("target_obd", 0444,
933 obd->obd_proc_entry);
935 entry->proc_fops = &lov_proc_target_fops;
940 lov->lov_pool_proc_entry = lprocfs_register("pools",
947 static int lov_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
953 case OBD_CLEANUP_EARLY: {
954 struct lov_obd *lov = &obd->u.lov;
956 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
957 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
959 obd_precleanup(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
964 case OBD_CLEANUP_EXPORTS:
966 case OBD_CLEANUP_SELF_EXP:
967 rc = obd_llog_finish(obd, 0);
969 CERROR("failed to cleanup llogging subsystems\n");
971 case OBD_CLEANUP_OBD:
977 static int lov_cleanup(struct obd_device *obd)
979 struct lov_obd *lov = &obd->u.lov;
980 struct list_head *pos, *tmp;
981 struct pool_desc *pool;
983 list_for_each_safe(pos, tmp, &lov->lov_pool_list) {
984 pool = list_entry(pos, struct pool_desc, pool_list);
985 /* free the pool structs */
986 CDEBUG(D_INFO, "delete pool %p\n", pool);
987 lov_pool_del(obd, pool->pool_name);
990 lustre_hash_exit(lov->lov_pools_hash_body);
992 lov_ost_pool_free(&(lov->lov_qos.lq_rr.lqr_pool));
993 lov_ost_pool_free(&lov->lov_packed);
998 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
999 if (lov->lov_tgts[i]) {
1000 /* Inactive targets may never have connected */
1001 if (lov->lov_tgts[i]->ltd_active ||
1002 atomic_read(&lov->lov_refcount))
1003 /* We should never get here - these
1004 should have been removed in the
1006 CERROR("lov tgt %d not cleaned!"
1007 " deathrow=%d, lovrc=%d\n",
1008 i, lov->lov_death_row,
1009 atomic_read(&lov->lov_refcount));
1010 lov_del_target(obd, i, 0, 0);
1014 OBD_FREE(lov->lov_tgts, sizeof(*lov->lov_tgts) *
1016 lov->lov_tgt_size = 0;
1019 /* clear pools parent proc entry only after all pools is killed */
1020 lprocfs_obd_cleanup(obd);
1022 OBD_FREE_PTR(lov->lov_qos.lq_statfs_data);
1026 static int lov_process_config(struct obd_device *obd, obd_count len, void *buf)
1028 struct lustre_cfg *lcfg = buf;
1029 struct obd_uuid obd_uuid;
1034 switch(cmd = lcfg->lcfg_command) {
1035 case LCFG_LOV_ADD_OBD:
1036 case LCFG_LOV_ADD_INA:
1037 case LCFG_LOV_DEL_OBD: {
1040 /* lov_modify_tgts add 0:lov_mdsA 1:ost1_UUID 2:0 3:1 */
1041 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
1042 GOTO(out, rc = -EINVAL);
1044 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1046 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
1047 GOTO(out, rc = -EINVAL);
1048 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
1049 GOTO(out, rc = -EINVAL);
1050 if (cmd == LCFG_LOV_ADD_OBD)
1051 rc = lov_add_target(obd, &obd_uuid, index, gen, 1);
1052 else if (cmd == LCFG_LOV_ADD_INA)
1053 rc = lov_add_target(obd, &obd_uuid, index, gen, 0);
1055 rc = lov_del_target(obd, index, &obd_uuid, gen);
1059 struct lprocfs_static_vars lvars = { 0 };
1060 struct lov_desc *desc = &(obd->u.lov.desc);
1063 GOTO(out, rc = -EINVAL);
1065 lprocfs_lov_init_vars(&lvars);
1067 rc = class_process_proc_param(PARAM_LOV, lvars.obd_vars,
1078 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1079 GOTO(out, rc = -EINVAL);
1088 #define log2(n) ffz(~(n))
1091 static int lov_clear_orphans(struct obd_export *export, struct obdo *src_oa,
1092 struct lov_stripe_md **ea,
1093 struct obd_trans_info *oti)
1095 struct lov_obd *lov;
1096 struct obdo *tmp_oa;
1097 struct obd_uuid *ost_uuid = NULL;
1101 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
1102 src_oa->o_flags == OBD_FL_DELORPHAN);
1104 lov = &export->exp_obd->u.lov;
1110 if (oti->oti_ost_uuid) {
1111 ost_uuid = oti->oti_ost_uuid;
1112 CDEBUG(D_HA, "clearing orphans only for %s\n",
1116 obd_getref(export->exp_obd);
1117 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1118 struct lov_stripe_md obj_md;
1119 struct lov_stripe_md *obj_mdp = &obj_md;
1120 struct lov_tgt_desc *tgt;
1123 tgt = lov->lov_tgts[i];
1127 /* if called for a specific target, we don't
1128 care if it is not active. */
1129 if (!lov->lov_tgts[i]->ltd_active && ost_uuid == NULL) {
1130 CDEBUG(D_HA, "lov idx %d inactive\n", i);
1134 if (ost_uuid && !obd_uuid_equals(ost_uuid, &tgt->ltd_uuid))
1137 CDEBUG(D_CONFIG,"Clear orphans for %d:%s\n", i,
1138 obd_uuid2str(ost_uuid));
1140 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
1142 LASSERT(lov->lov_tgts[i]->ltd_exp);
1143 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1144 err = obd_create(lov->lov_tgts[i]->ltd_exp,
1145 tmp_oa, &obj_mdp, oti);
1147 /* This export will be disabled until it is recovered,
1148 and then orphan recovery will be completed. */
1149 CERROR("error in orphan recovery on OST idx %d/%d: "
1150 "rc = %d\n", i, lov->desc.ld_tgt_count, err);
1157 obd_putref(export->exp_obd);
1163 static int lov_recreate(struct obd_export *exp, struct obdo *src_oa,
1164 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1166 struct lov_stripe_md *obj_mdp, *lsm;
1167 struct lov_obd *lov = &exp->exp_obd->u.lov;
1172 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
1173 src_oa->o_flags & OBD_FL_RECREATE_OBJS);
1175 OBD_ALLOC(obj_mdp, sizeof(*obj_mdp));
1176 if (obj_mdp == NULL)
1179 ost_idx = src_oa->o_nlink;
1182 GOTO(out, rc = -EINVAL);
1183 if (ost_idx >= lov->desc.ld_tgt_count ||
1184 !lov->lov_tgts[ost_idx])
1185 GOTO(out, rc = -EINVAL);
1187 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1188 if (lsm->lsm_oinfo[i]->loi_ost_idx == ost_idx) {
1189 if (lsm->lsm_oinfo[i]->loi_id != src_oa->o_id)
1190 GOTO(out, rc = -EINVAL);
1194 if (i == lsm->lsm_stripe_count)
1195 GOTO(out, rc = -EINVAL);
1197 rc = obd_create(lov->lov_tgts[ost_idx]->ltd_exp, src_oa, &obj_mdp, oti);
1199 OBD_FREE(obj_mdp, sizeof(*obj_mdp));
1203 /* the LOV expects oa->o_id to be set to the LOV object id */
1204 static int lov_create(struct obd_export *exp, struct obdo *src_oa,
1205 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1207 struct lov_obd *lov;
1208 struct obd_info *oinfo;
1209 struct lov_request_set *set = NULL;
1210 struct lov_request *req;
1211 struct l_wait_info lwi = { 0 };
1215 LASSERT(ea != NULL);
1219 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1220 src_oa->o_flags == OBD_FL_DELORPHAN) {
1221 rc = lov_clear_orphans(exp, src_oa, ea, oti);
1225 lov = &exp->exp_obd->u.lov;
1226 if (!lov->desc.ld_active_tgt_count)
1229 OBD_ALLOC_PTR(oinfo);
1233 obd_getref(exp->exp_obd);
1234 /* Recreate a specific object id at the given OST index */
1235 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1236 (src_oa->o_flags & OBD_FL_RECREATE_OBJS)) {
1237 rc = lov_recreate(exp, src_oa, ea, oti);
1241 /* issue statfs rpcs if the osfs data is older than qos_maxage - 1s,
1242 * later in alloc_qos(), we will wait for those rpcs to complete if
1243 * the osfs age is older than 2 * qos_maxage */
1244 qos_statfs_update(exp->exp_obd,
1245 cfs_time_shift_64(-lov->desc.ld_qos_maxage +
1246 OBD_STATFS_CACHE_SECONDS),
1249 rc = lov_prep_create_set(exp, oinfo, ea, src_oa, oti, &set);
1253 list_for_each_entry(req, &set->set_list, rq_link) {
1254 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1255 rc = obd_create_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1256 &req->rq_oi, &req->rq_oi.oi_md, oti);
1259 /* osc_create have timeout equ obd_timeout/2 so waiting don't be
1260 * longer then this */
1261 l_wait_event(set->set_waitq, lov_finished_set(set), &lwi);
1263 /* we not have ptlrpc set for assign set->interpret and should
1264 * be call interpret function himself. calling from cb_create_update
1265 * not permited because lov_fini_create_set can sleep for long time,
1266 * but we must avoid sleeping in ptlrpcd interpret function. */
1267 rc = lov_fini_create_set(set, ea);
1269 obd_putref(exp->exp_obd);
1270 OBD_FREE_PTR(oinfo);
1274 #define ASSERT_LSM_MAGIC(lsmp) \
1276 LASSERT((lsmp) != NULL); \
1277 LASSERTF(((lsmp)->lsm_magic == LOV_MAGIC_V1 || \
1278 (lsmp)->lsm_magic == LOV_MAGIC_V3 || \
1279 (lsmp)->lsm_magic == LOV_MAGIC_JOIN), "%p->lsm_magic=%x\n", \
1280 (lsmp), (lsmp)->lsm_magic); \
1283 static int lov_destroy(struct obd_export *exp, struct obdo *oa,
1284 struct lov_stripe_md *lsm, struct obd_trans_info *oti,
1285 struct obd_export *md_exp)
1287 struct lov_request_set *set;
1288 struct obd_info *oinfo;
1289 struct lov_request *req;
1290 struct list_head *pos;
1291 struct lov_obd *lov;
1292 int rc = 0, err = 0;
1295 ASSERT_LSM_MAGIC(lsm);
1297 if (!exp || !exp->exp_obd)
1300 if (oa->o_valid & OBD_MD_FLCOOKIE) {
1302 LASSERT(oti->oti_logcookies);
1305 OBD_ALLOC_PTR(oinfo);
1309 lov = &exp->exp_obd->u.lov;
1310 obd_getref(exp->exp_obd);
1311 rc = lov_prep_destroy_set(exp, oinfo, oa, lsm, oti, &set);
1315 list_for_each (pos, &set->set_list) {
1316 req = list_entry(pos, struct lov_request, rq_link);
1318 if (oa->o_valid & OBD_MD_FLCOOKIE)
1319 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1321 err = obd_destroy(lov->lov_tgts[req->rq_idx]->ltd_exp,
1322 req->rq_oi.oi_oa, NULL, oti, NULL);
1323 err = lov_update_common_set(set, req, err);
1325 CERROR("error: destroying objid "LPX64" subobj "
1326 LPX64" on OST idx %d: rc = %d\n",
1327 oa->o_id, req->rq_oi.oi_oa->o_id,
1335 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
1336 rc = lsm_op_find(lsm->lsm_magic)->lsm_destroy(lsm, oa, md_exp);
1338 err = lov_fini_destroy_set(set);
1340 obd_putref(exp->exp_obd);
1341 OBD_FREE_PTR(oinfo);
1342 RETURN(rc ? rc : err);
1345 static int lov_getattr(struct obd_export *exp, struct obd_info *oinfo)
1347 struct lov_request_set *set;
1348 struct lov_request *req;
1349 struct list_head *pos;
1350 struct lov_obd *lov;
1351 int err = 0, rc = 0;
1355 ASSERT_LSM_MAGIC(oinfo->oi_md);
1357 if (!exp || !exp->exp_obd)
1360 lov = &exp->exp_obd->u.lov;
1362 rc = lov_prep_getattr_set(exp, oinfo, &set);
1366 list_for_each (pos, &set->set_list) {
1367 req = list_entry(pos, struct lov_request, rq_link);
1369 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1370 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1371 req->rq_oi.oi_oa->o_id, req->rq_idx);
1373 rc = obd_getattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1375 err = lov_update_common_set(set, req, rc);
1377 CERROR("error: getattr objid "LPX64" subobj "
1378 LPX64" on OST idx %d: rc = %d\n",
1379 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1385 rc = lov_fini_getattr_set(set);
1391 static int lov_getattr_interpret(struct ptlrpc_request_set *rqset,
1394 struct lov_request_set *lovset = (struct lov_request_set *)data;
1398 /* don't do attribute merge if this aysnc op failed */
1400 lovset->set_completes = 0;
1401 err = lov_fini_getattr_set(lovset);
1402 RETURN(rc ? rc : err);
1405 static int lov_getattr_async(struct obd_export *exp, struct obd_info *oinfo,
1406 struct ptlrpc_request_set *rqset)
1408 struct lov_request_set *lovset;
1409 struct lov_obd *lov;
1410 struct list_head *pos;
1411 struct lov_request *req;
1416 ASSERT_LSM_MAGIC(oinfo->oi_md);
1418 if (!exp || !exp->exp_obd)
1421 lov = &exp->exp_obd->u.lov;
1423 rc = lov_prep_getattr_set(exp, oinfo, &lovset);
1427 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1428 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1429 oinfo->oi_md->lsm_stripe_size);
1431 list_for_each (pos, &lovset->set_list) {
1432 req = list_entry(pos, struct lov_request, rq_link);
1434 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1435 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1436 req->rq_oi.oi_oa->o_id, req->rq_idx);
1437 rc = obd_getattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1438 &req->rq_oi, rqset);
1440 CERROR("error: getattr objid "LPX64" subobj "
1441 LPX64" on OST idx %d: rc = %d\n",
1442 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1448 if (!list_empty(&rqset->set_requests)) {
1450 LASSERT (rqset->set_interpret == NULL);
1451 rqset->set_interpret = lov_getattr_interpret;
1452 rqset->set_arg = (void *)lovset;
1457 lovset->set_completes = 0;
1458 err = lov_fini_getattr_set(lovset);
1459 RETURN(rc ? rc : err);
1462 static int lov_setattr(struct obd_export *exp, struct obd_info *oinfo,
1463 struct obd_trans_info *oti)
1465 struct lov_request_set *set;
1466 struct lov_obd *lov;
1467 struct list_head *pos;
1468 struct lov_request *req;
1469 int err = 0, rc = 0;
1473 ASSERT_LSM_MAGIC(oinfo->oi_md);
1475 if (!exp || !exp->exp_obd)
1478 /* for now, we only expect the following updates here */
1479 LASSERT(!(oinfo->oi_oa->o_valid & ~(OBD_MD_FLID | OBD_MD_FLTYPE |
1480 OBD_MD_FLMODE | OBD_MD_FLATIME |
1481 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1482 OBD_MD_FLFLAGS | OBD_MD_FLSIZE |
1483 OBD_MD_FLGROUP | OBD_MD_FLUID |
1484 OBD_MD_FLGID | OBD_MD_FLFID |
1486 lov = &exp->exp_obd->u.lov;
1487 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1491 list_for_each (pos, &set->set_list) {
1492 req = list_entry(pos, struct lov_request, rq_link);
1494 rc = obd_setattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1496 err = lov_update_setattr_set(set, req, rc);
1498 CERROR("error: setattr objid "LPX64" subobj "
1499 LPX64" on OST idx %d: rc = %d\n",
1500 set->set_oi->oi_oa->o_id,
1501 req->rq_oi.oi_oa->o_id, req->rq_idx, err);
1506 err = lov_fini_setattr_set(set);
1512 static int lov_setattr_interpret(struct ptlrpc_request_set *rqset,
1515 struct lov_request_set *lovset = (struct lov_request_set *)data;
1520 lovset->set_completes = 0;
1521 err = lov_fini_setattr_set(lovset);
1522 RETURN(rc ? rc : err);
1525 /* If @oti is given, the request goes from MDS and responses from OSTs are not
1526 needed. Otherwise, a client is waiting for responses. */
1527 static int lov_setattr_async(struct obd_export *exp, struct obd_info *oinfo,
1528 struct obd_trans_info *oti,
1529 struct ptlrpc_request_set *rqset)
1531 struct lov_request_set *set;
1532 struct lov_request *req;
1533 struct list_head *pos;
1534 struct lov_obd *lov;
1539 ASSERT_LSM_MAGIC(oinfo->oi_md);
1540 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE) {
1542 LASSERT(oti->oti_logcookies);
1545 if (!exp || !exp->exp_obd)
1548 lov = &exp->exp_obd->u.lov;
1549 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1553 CDEBUG(D_INFO, "objid "LPX64"@"LPX64": %ux%u byte stripes\n",
1554 oinfo->oi_md->lsm_object_id,
1555 oinfo->oi_md->lsm_object_gr,
1556 oinfo->oi_md->lsm_stripe_count,
1557 oinfo->oi_md->lsm_stripe_size);
1559 list_for_each (pos, &set->set_list) {
1560 req = list_entry(pos, struct lov_request, rq_link);
1562 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
1563 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1565 CDEBUG(D_INFO, "objid "LPX64"@"LPX64"[%d] has subobj "LPX64
1566 " at idx %u\n", oinfo->oi_oa->o_id, oinfo->oi_oa->o_gr,
1567 req->rq_stripe, req->rq_oi.oi_oa->o_id, req->rq_idx);
1569 rc = obd_setattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1570 &req->rq_oi, oti, rqset);
1572 CERROR("error: setattr objid "LPX64" subobj "
1573 LPX64" on OST idx %d: rc = %d\n",
1574 set->set_oi->oi_oa->o_id,
1575 req->rq_oi.oi_oa->o_id,
1581 /* If we are not waiting for responses on async requests, return. */
1582 if (rc || !rqset || list_empty(&rqset->set_requests)) {
1585 set->set_completes = 0;
1586 err = lov_fini_setattr_set(set);
1587 RETURN(rc ? rc : err);
1590 LASSERT(rqset->set_interpret == NULL);
1591 rqset->set_interpret = lov_setattr_interpret;
1592 rqset->set_arg = (void *)set;
1597 static int lov_punch_interpret(struct ptlrpc_request_set *rqset,
1600 struct lov_request_set *lovset = (struct lov_request_set *)data;
1605 lovset->set_completes = 0;
1606 err = lov_fini_punch_set(lovset);
1607 RETURN(rc ? rc : err);
1610 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
1611 * we can send this 'punch' to just the authoritative node and the nodes
1612 * that the punch will affect. */
1613 static int lov_punch(struct obd_export *exp, struct obd_info *oinfo,
1614 struct obd_trans_info *oti,
1615 struct ptlrpc_request_set *rqset)
1617 struct lov_request_set *set;
1618 struct lov_obd *lov;
1619 struct list_head *pos;
1620 struct lov_request *req;
1625 ASSERT_LSM_MAGIC(oinfo->oi_md);
1627 if (!exp || !exp->exp_obd)
1630 lov = &exp->exp_obd->u.lov;
1631 rc = lov_prep_punch_set(exp, oinfo, oti, &set);
1635 list_for_each (pos, &set->set_list) {
1636 req = list_entry(pos, struct lov_request, rq_link);
1638 rc = obd_punch(lov->lov_tgts[req->rq_idx]->ltd_exp,
1639 &req->rq_oi, NULL, rqset);
1641 CERROR("error: punch objid "LPX64" subobj "LPX64
1642 " on OST idx %d: rc = %d\n",
1643 set->set_oi->oi_oa->o_id,
1644 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1649 if (rc || list_empty(&rqset->set_requests)) {
1651 err = lov_fini_punch_set(set);
1652 RETURN(rc ? rc : err);
1655 LASSERT(rqset->set_interpret == NULL);
1656 rqset->set_interpret = lov_punch_interpret;
1657 rqset->set_arg = (void *)set;
1662 static int lov_sync_interpret(struct ptlrpc_request_set *rqset,
1665 struct lov_request_set *lovset = (struct lov_request_set *)data;
1670 lovset->set_completes = 0;
1671 err = lov_fini_sync_set(lovset);
1672 RETURN(rc ? rc : err);
1675 static int lov_sync(struct obd_export *exp, struct obd_info *oinfo,
1676 obd_off start, obd_off end,
1677 struct ptlrpc_request_set *rqset)
1679 struct lov_request_set *set = NULL;
1680 struct lov_obd *lov;
1681 struct list_head *pos;
1682 struct lov_request *req;
1686 ASSERT_LSM_MAGIC(oinfo->oi_md);
1687 LASSERT(rqset != NULL);
1692 lov = &exp->exp_obd->u.lov;
1693 rc = lov_prep_sync_set(exp, oinfo, start, end, &set);
1697 list_for_each (pos, &set->set_list) {
1698 req = list_entry(pos, struct lov_request, rq_link);
1700 rc = obd_sync(lov->lov_tgts[req->rq_idx]->ltd_exp, &req->rq_oi,
1701 req->rq_oi.oi_policy.l_extent.start,
1702 req->rq_oi.oi_policy.l_extent.end, rqset);
1704 CERROR("error: fsync objid "LPX64" subobj "LPX64
1705 " on OST idx %d: rc = %d\n",
1706 set->set_oi->oi_oa->o_id,
1707 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1712 /* If we are not waiting for responses on async requests, return. */
1713 if (rc || list_empty(&rqset->set_requests)) {
1714 int err = lov_fini_sync_set(set);
1715 RETURN(rc ? rc : err);
1718 LASSERT(rqset->set_interpret == NULL);
1719 rqset->set_interpret = lov_sync_interpret;
1720 rqset->set_arg = (void *)set;
1725 static int lov_brw_check(struct lov_obd *lov, struct obd_info *lov_oinfo,
1726 obd_count oa_bufs, struct brw_page *pga)
1728 struct obd_info oinfo = { { { 0 } } };
1731 oinfo.oi_oa = lov_oinfo->oi_oa;
1733 /* The caller just wants to know if there's a chance that this
1734 * I/O can succeed */
1735 for (i = 0; i < oa_bufs; i++) {
1736 int stripe = lov_stripe_number(lov_oinfo->oi_md, pga[i].off);
1737 int ost = lov_oinfo->oi_md->lsm_oinfo[stripe]->loi_ost_idx;
1740 if (!lov_stripe_intersects(lov_oinfo->oi_md, i, pga[i].off,
1741 pga[i].off + pga[i].count - 1,
1745 if (!lov->lov_tgts[ost] || !lov->lov_tgts[ost]->ltd_active) {
1746 CDEBUG(D_HA, "lov idx %d inactive\n", ost);
1750 rc = obd_brw(OBD_BRW_CHECK, lov->lov_tgts[ost]->ltd_exp, &oinfo,
1758 static int lov_brw(int cmd, struct obd_export *exp, struct obd_info *oinfo,
1759 obd_count oa_bufs, struct brw_page *pga,
1760 struct obd_trans_info *oti)
1762 struct lov_request_set *set;
1763 struct lov_request *req;
1764 struct list_head *pos;
1765 struct lov_obd *lov = &exp->exp_obd->u.lov;
1769 ASSERT_LSM_MAGIC(oinfo->oi_md);
1771 if (cmd == OBD_BRW_CHECK) {
1772 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1776 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &set);
1780 list_for_each (pos, &set->set_list) {
1781 struct obd_export *sub_exp;
1782 struct brw_page *sub_pga;
1783 req = list_entry(pos, struct lov_request, rq_link);
1785 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1786 sub_pga = set->set_pga + req->rq_pgaidx;
1787 rc = obd_brw(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1791 lov_update_common_set(set, req, rc);
1794 err = lov_fini_brw_set(set);
1800 static int lov_brw_interpret(struct ptlrpc_request_set *reqset, void *data,
1803 struct lov_request_set *lovset = (struct lov_request_set *)data;
1807 lovset->set_completes = 0;
1808 lov_fini_brw_set(lovset);
1810 rc = lov_fini_brw_set(lovset);
1816 static int lov_brw_async(int cmd, struct obd_export *exp,
1817 struct obd_info *oinfo, obd_count oa_bufs,
1818 struct brw_page *pga, struct obd_trans_info *oti,
1819 struct ptlrpc_request_set *set, int pshift)
1821 struct lov_request_set *lovset;
1822 struct lov_request *req;
1823 struct list_head *pos;
1824 struct lov_obd *lov = &exp->exp_obd->u.lov;
1829 ASSERT_LSM_MAGIC(oinfo->oi_md);
1831 if (cmd == OBD_BRW_CHECK) {
1832 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1836 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &lovset);
1840 list_for_each (pos, &lovset->set_list) {
1841 struct obd_export *sub_exp;
1842 struct brw_page *sub_pga;
1843 req = list_entry(pos, struct lov_request, rq_link);
1845 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1846 sub_pga = lovset->set_pga + req->rq_pgaidx;
1847 rc = obd_brw_async(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1848 sub_pga, oti, set, pshift);
1851 lov_update_common_set(lovset, req, rc);
1854 LASSERT(set->set_interpret == NULL);
1855 LASSERT(set->set_arg == NULL);
1856 rc = ptlrpc_set_add_cb(set, lov_brw_interpret, lovset);
1862 lov_fini_brw_set(lovset);
1866 static int lov_ap_make_ready(void *data, int cmd)
1868 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1870 return lap->lap_caller_ops->ap_make_ready(lap->lap_caller_data, cmd);
1873 static int lov_ap_refresh_count(void *data, int cmd)
1875 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1877 return lap->lap_caller_ops->ap_refresh_count(lap->lap_caller_data,
1881 static void lov_ap_fill_obdo(void *data, int cmd, struct obdo *oa)
1883 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1885 lap->lap_caller_ops->ap_fill_obdo(lap->lap_caller_data, cmd, oa);
1886 /* XXX woah, shouldn't we be altering more here? size? */
1887 oa->o_id = lap->lap_loi_id;
1888 oa->o_gr = lap->lap_loi_gr;
1889 oa->o_stripe_idx = lap->lap_stripe;
1892 static void lov_ap_update_obdo(void *data, int cmd, struct obdo *oa,
1895 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1897 lap->lap_caller_ops->ap_update_obdo(lap->lap_caller_data, cmd,oa,valid);
1900 static int lov_ap_completion(void *data, int cmd, struct obdo *oa, int rc)
1902 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1904 /* in a raid1 regime this would down a count of many ios
1905 * in flight, onl calling the caller_ops completion when all
1906 * the raid1 ios are complete */
1907 rc = lap->lap_caller_ops->ap_completion(lap->lap_caller_data,cmd,oa,rc);
1911 static struct obd_async_page_ops lov_async_page_ops = {
1912 .ap_make_ready = lov_ap_make_ready,
1913 .ap_refresh_count = lov_ap_refresh_count,
1914 .ap_fill_obdo = lov_ap_fill_obdo,
1915 .ap_update_obdo = lov_ap_update_obdo,
1916 .ap_completion = lov_ap_completion,
1919 int lov_prep_async_page(struct obd_export *exp, struct lov_stripe_md *lsm,
1920 struct lov_oinfo *loi, cfs_page_t *page,
1921 obd_off offset, struct obd_async_page_ops *ops,
1922 void *data, void **res, int flags,
1923 struct lustre_handle *lockh)
1925 struct lov_obd *lov = &exp->exp_obd->u.lov;
1926 struct lov_async_page *lap;
1927 struct lov_lock_handles *lov_lockh = NULL;
1933 /* Find an existing osc so we can get it's stupid sizeof(*oap).
1934 Only because of this layering limitation will a client
1935 mount with no osts fail */
1936 while (!lov->lov_tgts || !lov->lov_tgts[i] ||
1937 !lov->lov_tgts[i]->ltd_exp) {
1939 if (i >= lov->desc.ld_tgt_count)
1942 rc = size_round(sizeof(*lap)) +
1943 obd_prep_async_page(lov->lov_tgts[i]->ltd_exp, NULL,
1944 NULL, NULL, 0, NULL, NULL, NULL, 0,
1948 ASSERT_LSM_MAGIC(lsm);
1949 LASSERT(loi == NULL);
1952 lap->lap_magic = LOV_AP_MAGIC;
1953 lap->lap_caller_ops = ops;
1954 lap->lap_caller_data = data;
1956 /* for now only raid 0 which passes through */
1957 lap->lap_stripe = lov_stripe_number(lsm, offset);
1958 lov_stripe_offset(lsm, offset, lap->lap_stripe, &lap->lap_sub_offset);
1959 loi = lsm->lsm_oinfo[lap->lap_stripe];
1961 /* so the callback doesn't need the lsm */
1962 lap->lap_loi_id = loi->loi_id;
1963 lap->lap_loi_gr = loi->loi_gr;
1965 lap->lap_sub_cookie = (void *)lap + size_round(sizeof(*lap));
1967 if (lockh && lustre_handle_is_used(lockh) && !(flags & OBD_FAST_LOCK)) {
1968 lov_lockh = lov_handle2llh(lockh);
1970 lockh = lov_lockh->llh_handles + lap->lap_stripe;
1974 rc = obd_prep_async_page(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1975 lsm, loi, page, lap->lap_sub_offset,
1976 &lov_async_page_ops, lap,
1977 &lap->lap_sub_cookie, flags, lockh);
1979 lov_llh_put(lov_lockh);
1982 CDEBUG(D_CACHE, "lap %p page %p cookie %p off "LPU64"\n", lap, page,
1983 lap->lap_sub_cookie, offset);
1987 static int lov_queue_async_io(struct obd_export *exp,
1988 struct lov_stripe_md *lsm,
1989 struct lov_oinfo *loi, void *cookie,
1990 int cmd, obd_off off, int count,
1991 obd_flag brw_flags, obd_flag async_flags)
1993 struct lov_obd *lov = &exp->exp_obd->u.lov;
1994 struct lov_async_page *lap;
1997 LASSERT(loi == NULL);
1999 ASSERT_LSM_MAGIC(lsm);
2001 lap = LAP_FROM_COOKIE(cookie);
2003 loi = lsm->lsm_oinfo[lap->lap_stripe];
2005 rc = obd_queue_async_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp, lsm,
2006 loi, lap->lap_sub_cookie, cmd, off, count,
2007 brw_flags, async_flags);
2011 static int lov_set_async_flags(struct obd_export *exp,
2012 struct lov_stripe_md *lsm,
2013 struct lov_oinfo *loi, void *cookie,
2014 obd_flag async_flags)
2016 struct lov_obd *lov = &exp->exp_obd->u.lov;
2017 struct lov_async_page *lap;
2020 LASSERT(loi == NULL);
2022 ASSERT_LSM_MAGIC(lsm);
2024 lap = LAP_FROM_COOKIE(cookie);
2026 loi = lsm->lsm_oinfo[lap->lap_stripe];
2028 rc = obd_set_async_flags(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2029 lsm, loi, lap->lap_sub_cookie, async_flags);
2033 static int lov_queue_group_io(struct obd_export *exp,
2034 struct lov_stripe_md *lsm,
2035 struct lov_oinfo *loi,
2036 struct obd_io_group *oig, void *cookie,
2037 int cmd, obd_off off, int count,
2038 obd_flag brw_flags, obd_flag async_flags)
2040 struct lov_obd *lov = &exp->exp_obd->u.lov;
2041 struct lov_async_page *lap;
2044 LASSERT(loi == NULL);
2046 ASSERT_LSM_MAGIC(lsm);
2048 lap = LAP_FROM_COOKIE(cookie);
2050 loi = lsm->lsm_oinfo[lap->lap_stripe];
2052 rc = obd_queue_group_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp, lsm,
2053 loi, oig, lap->lap_sub_cookie, cmd, off, count,
2054 brw_flags, async_flags);
2058 /* this isn't exactly optimal. we may have queued sync io in oscs on
2059 * all stripes, but we don't record that fact at queue time. so we
2060 * trigger sync io on all stripes. */
2061 static int lov_trigger_group_io(struct obd_export *exp,
2062 struct lov_stripe_md *lsm,
2063 struct lov_oinfo *loi,
2064 struct obd_io_group *oig)
2066 struct lov_obd *lov = &exp->exp_obd->u.lov;
2069 LASSERT(loi == NULL);
2071 ASSERT_LSM_MAGIC(lsm);
2073 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2074 loi = lsm->lsm_oinfo[i];
2075 if (!lov->lov_tgts[loi->loi_ost_idx] ||
2076 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
2077 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2081 err = obd_trigger_group_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2083 if (rc == 0 && err != 0)
2089 static int lov_teardown_async_page(struct obd_export *exp,
2090 struct lov_stripe_md *lsm,
2091 struct lov_oinfo *loi, void *cookie)
2093 struct lov_obd *lov = &exp->exp_obd->u.lov;
2094 struct lov_async_page *lap;
2097 LASSERT(loi == NULL);
2099 ASSERT_LSM_MAGIC(lsm);
2101 lap = LAP_FROM_COOKIE(cookie);
2103 loi = lsm->lsm_oinfo[lap->lap_stripe];
2105 rc = obd_teardown_async_page(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2106 lsm, loi, lap->lap_sub_cookie);
2108 CERROR("unable to teardown sub cookie %p: %d\n",
2109 lap->lap_sub_cookie, rc);
2115 static int lov_enqueue_interpret(struct ptlrpc_request_set *rqset,
2118 struct lov_request_set *lovset = (struct lov_request_set *)data;
2120 rc = lov_fini_enqueue_set(lovset, lovset->set_ei->ei_mode, rc, rqset);
2124 static int lov_enqueue(struct obd_export *exp, struct obd_info *oinfo,
2125 struct ldlm_enqueue_info *einfo,
2126 struct ptlrpc_request_set *rqset)
2128 ldlm_mode_t mode = einfo->ei_mode;
2129 struct lov_request_set *set;
2130 struct lov_request *req;
2131 struct list_head *pos;
2132 struct lov_obd *lov;
2137 ASSERT_LSM_MAGIC(oinfo->oi_md);
2138 LASSERT(mode == (mode & -mode));
2140 /* we should never be asked to replay a lock this way. */
2141 LASSERT((oinfo->oi_flags & LDLM_FL_REPLAY) == 0);
2143 if (!exp || !exp->exp_obd)
2146 lov = &exp->exp_obd->u.lov;
2147 rc = lov_prep_enqueue_set(exp, oinfo, einfo, &set);
2151 list_for_each (pos, &set->set_list) {
2152 req = list_entry(pos, struct lov_request, rq_link);
2154 rc = obd_enqueue(lov->lov_tgts[req->rq_idx]->ltd_exp,
2155 &req->rq_oi, einfo, rqset);
2160 if (rqset && !list_empty(&rqset->set_requests)) {
2162 LASSERT(rqset->set_interpret == NULL);
2163 rqset->set_interpret = lov_enqueue_interpret;
2164 rqset->set_arg = (void *)set;
2168 rc = lov_fini_enqueue_set(set, mode, rc, rqset);
2172 static int lov_match(struct obd_export *exp, struct lov_stripe_md *lsm,
2173 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
2174 int *flags, void *data, struct lustre_handle *lockh,
2177 struct lov_request_set *set;
2178 struct obd_info oinfo;
2179 struct lov_request *req;
2180 struct list_head *pos;
2181 struct lov_obd *lov;
2182 struct lustre_handle *lov_lockhp;
2183 int lov_flags, rc = 0;
2186 ASSERT_LSM_MAGIC(lsm);
2187 LASSERT((*flags & LDLM_FL_TEST_LOCK) || mode == (mode & -mode));
2189 if (!exp || !exp->exp_obd)
2192 lov = &exp->exp_obd->u.lov;
2193 rc = lov_prep_match_set(exp, &oinfo, lsm, policy, mode, lockh, &set);
2197 list_for_each (pos, &set->set_list) {
2198 ldlm_policy_data_t sub_policy;
2199 req = list_entry(pos, struct lov_request, rq_link);
2200 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
2201 LASSERT(lov_lockhp);
2204 sub_policy.l_extent = req->rq_oi.oi_policy.l_extent;
2206 rc = obd_match(lov->lov_tgts[req->rq_idx]->ltd_exp,
2207 req->rq_oi.oi_md, type, &sub_policy,
2208 mode, &lov_flags, data, lov_lockhp,
2210 rc = lov_update_match_set(set, req, rc);
2214 lov_fini_match_set(set, mode, *flags);
2218 static int lov_change_cbdata(struct obd_export *exp,
2219 struct lov_stripe_md *lsm, ldlm_iterator_t it,
2222 struct lov_obd *lov;
2223 struct lov_oinfo *loi;
2227 ASSERT_LSM_MAGIC(lsm);
2229 if (!exp || !exp->exp_obd)
2232 lov = &exp->exp_obd->u.lov;
2233 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2234 struct lov_stripe_md submd;
2236 loi = lsm->lsm_oinfo[i];
2237 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2238 CDEBUG(D_HA, "lov idx %d NULL \n", loi->loi_ost_idx);
2241 submd.lsm_object_id = loi->loi_id;
2242 submd.lsm_object_gr = loi->loi_gr;
2243 submd.lsm_stripe_count = 0;
2244 rc = obd_change_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2250 /* find any ldlm lock of the inode in lov
2254 static int lov_find_cbdata(struct obd_export *exp,
2255 struct lov_stripe_md *lsm, ldlm_iterator_t it,
2258 struct lov_obd *lov;
2259 struct lov_oinfo *loi;
2263 ASSERT_LSM_MAGIC(lsm);
2265 if (!exp || !exp->exp_obd)
2268 lov = &exp->exp_obd->u.lov;
2269 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2270 struct lov_stripe_md submd;
2272 loi = lsm->lsm_oinfo[i];
2273 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2274 CDEBUG(D_HA, "lov idx %d NULL \n", loi->loi_ost_idx);
2277 submd.lsm_object_id = loi->loi_id;
2278 submd.lsm_object_gr = loi->loi_gr;
2279 submd.lsm_stripe_count = 0;
2280 rc = obd_find_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2289 static int lov_cancel(struct obd_export *exp, struct lov_stripe_md *lsm,
2290 __u32 mode, struct lustre_handle *lockh, int flags,
2293 struct lov_request_set *set;
2294 struct obd_info oinfo;
2295 struct lov_request *req;
2296 struct list_head *pos;
2297 struct lov_obd *lov;
2298 struct lustre_handle *lov_lockhp;
2299 ldlm_mode_t this_mode;
2300 int err = 0, rc = 0;
2303 ASSERT_LSM_MAGIC(lsm);
2305 if (!exp || !exp->exp_obd)
2309 lov = &exp->exp_obd->u.lov;
2310 if (flags & OBD_FAST_LOCK) {
2311 int stripe = lov_stripe_number(lsm, end);
2312 RETURN(obd_cancel(lov->lov_tgts[lsm->lsm_oinfo[stripe]->
2313 loi_ost_idx]->ltd_exp, NULL, mode, lockh,
2317 rc = lov_prep_cancel_set(exp, &oinfo, lsm, mode, lockh, &set);
2321 list_for_each (pos, &set->set_list) {
2322 req = list_entry(pos, struct lov_request, rq_link);
2323 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
2325 /* If this lock was used for a write or truncate, the object
2326 * will have been recreated by the OST, cancel the lock
2327 * (setting LCK_GROUP incidentally causes immediate cancel). */
2328 if (OST_LVB_IS_ERR(lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_blocks) &&
2329 (mode == LCK_PW || mode == LCK_CW))
2330 this_mode = LCK_GROUP;
2334 rc = obd_cancel(lov->lov_tgts[req->rq_idx]->ltd_exp,
2335 req->rq_oi.oi_md, this_mode, lov_lockhp, flags,
2337 rc = lov_update_common_set(set, req, rc);
2339 CERROR("error: cancel objid "LPX64" subobj "
2340 LPX64" on OST idx %d: rc = %d\n",
2342 req->rq_oi.oi_md->lsm_object_id,
2348 lov_fini_cancel_set(set);
2352 static int lov_cancel_unused(struct obd_export *exp,
2353 struct lov_stripe_md *lsm, int flags, void *opaque)
2355 struct lov_obd *lov;
2356 struct lov_oinfo *loi;
2360 if (!exp || !exp->exp_obd)
2363 lov = &exp->exp_obd->u.lov;
2365 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2367 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2370 err = obd_cancel_unused(lov->lov_tgts[i]->ltd_exp, NULL,
2378 ASSERT_LSM_MAGIC(lsm);
2380 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2381 struct lov_stripe_md submd;
2384 loi = lsm->lsm_oinfo[i];
2385 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2386 CDEBUG(D_HA, "lov idx %d NULL\n", loi->loi_ost_idx);
2390 if (!lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
2391 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2393 submd.lsm_object_id = loi->loi_id;
2394 submd.lsm_stripe_count = 0;
2395 err = obd_cancel_unused(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2396 &submd, flags, opaque);
2397 if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
2398 CERROR("error: cancel unused objid "LPX64" subobj "LPX64
2399 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
2400 loi->loi_id, loi->loi_ost_idx, err);
2408 static int lov_join_lru(struct obd_export *exp,
2409 struct lov_stripe_md *lsm, int join)
2411 struct lov_obd *lov;
2412 struct lov_oinfo *loi;
2416 ASSERT_LSM_MAGIC(lsm);
2417 if (!exp || !exp->exp_obd)
2420 lov = &exp->exp_obd->u.lov;
2421 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2422 struct lov_stripe_md submd;
2425 loi = lsm->lsm_oinfo[i];
2426 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2427 CDEBUG(D_HA, "lov idx %d NULL\n", loi->loi_ost_idx);
2431 if (!lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
2432 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2434 submd.lsm_object_id = loi->loi_id;
2435 submd.lsm_stripe_count = 0;
2436 rc = obd_join_lru(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2439 CERROR("join lru failed. objid: "LPX64" subobj: "LPX64
2440 " ostidx: %d rc: %d\n", lsm->lsm_object_id,
2441 loi->loi_id, loi->loi_ost_idx, rc);
2450 int lov_statfs_interpret(struct ptlrpc_request_set *rqset, void *data, int rc)
2452 struct lov_request_set *lovset = (struct lov_request_set *)data;
2457 lovset->set_completes = 0;
2459 err = lov_fini_statfs_set(lovset);
2460 RETURN(rc ? rc : err);
2463 static int lov_statfs_async(struct obd_device *obd, struct obd_info *oinfo,
2464 __u64 max_age, struct ptlrpc_request_set *rqset)
2466 struct lov_request_set *set;
2467 struct lov_request *req;
2468 struct list_head *pos;
2469 struct lov_obd *lov;
2473 LASSERT(oinfo != NULL);
2474 LASSERT(oinfo->oi_osfs != NULL);
2477 rc = lov_prep_statfs_set(obd, oinfo, &set);
2481 list_for_each (pos, &set->set_list) {
2482 struct obd_device *osc_obd;
2484 req = list_entry(pos, struct lov_request, rq_link);
2486 osc_obd = class_exp2obd(lov->lov_tgts[req->rq_idx]->ltd_exp);
2487 rc = obd_statfs_async(osc_obd, &req->rq_oi, max_age, rqset);
2492 if (rc || list_empty(&rqset->set_requests)) {
2495 set->set_completes = 0;
2496 err = lov_fini_statfs_set(set);
2497 RETURN(rc ? rc : err);
2500 LASSERT(rqset->set_interpret == NULL);
2501 rqset->set_interpret = lov_statfs_interpret;
2502 rqset->set_arg = (void *)set;
2506 static int lov_statfs(struct obd_device *obd, struct obd_statfs *osfs,
2507 __u64 max_age, __u32 flags)
2509 struct ptlrpc_request_set *set = NULL;
2510 struct obd_info oinfo = { { { 0 } } };
2514 /* for obdclass we forbid using obd_statfs_rqset, but prefer using async
2515 * statfs requests */
2516 set = ptlrpc_prep_set();
2520 oinfo.oi_osfs = osfs;
2521 oinfo.oi_flags = flags;
2522 rc = lov_statfs_async(obd, &oinfo, max_age, set);
2524 rc = ptlrpc_set_wait(set);
2525 ptlrpc_set_destroy(set);
2530 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
2531 void *karg, void *uarg)
2533 struct obd_device *obddev = class_exp2obd(exp);
2534 struct lov_obd *lov = &obddev->u.lov;
2535 int i, rc, count = lov->desc.ld_tgt_count;
2536 struct obd_uuid *uuidp;
2540 case OBD_IOC_LOV_GET_CONFIG: {
2541 struct obd_ioctl_data *data;
2542 struct lov_desc *desc;
2547 if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
2550 data = (struct obd_ioctl_data *)buf;
2552 if (sizeof(*desc) > data->ioc_inllen1) {
2553 obd_ioctl_freedata(buf, len);
2557 if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
2558 obd_ioctl_freedata(buf, len);
2562 if (sizeof(__u32) * count > data->ioc_inllen3) {
2563 obd_ioctl_freedata(buf, len);
2567 desc = (struct lov_desc *)data->ioc_inlbuf1;
2568 memcpy(desc, &(lov->desc), sizeof(*desc));
2570 uuidp = (struct obd_uuid *)data->ioc_inlbuf2;
2571 genp = (__u32 *)data->ioc_inlbuf3;
2572 /* the uuid will be empty for deleted OSTs */
2573 for (i = 0; i < count; i++, uuidp++, genp++) {
2574 if (!lov->lov_tgts[i])
2576 *uuidp = lov->lov_tgts[i]->ltd_uuid;
2577 *genp = lov->lov_tgts[i]->ltd_gen;
2580 rc = copy_to_user((void *)uarg, buf, len);
2583 obd_ioctl_freedata(buf, len);
2586 case LL_IOC_LOV_SETSTRIPE:
2587 rc = lov_setstripe(exp, karg, uarg);
2589 case LL_IOC_LOV_GETSTRIPE:
2590 rc = lov_getstripe(exp, karg, uarg);
2592 case LL_IOC_LOV_SETEA:
2593 rc = lov_setea(exp, karg, uarg);
2602 for (i = 0; i < count; i++) {
2605 /* OST was disconnected */
2606 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2609 err = obd_iocontrol(cmd, lov->lov_tgts[i]->ltd_exp,
2611 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
2614 if (lov->lov_tgts[i]->ltd_active) {
2615 CDEBUG(err == -ENOTTY ?
2616 D_IOCTL : D_WARNING,
2617 "iocontrol OSC %s on OST "
2618 "idx %d cmd %x: err = %d\n",
2619 lov_uuid2str(lov, i),
2636 #define FIEMAP_BUFFER_SIZE 4096
2638 /* Non-zero fe_logical indicates that this is a continuation FIEMAP
2639 * call. The local end offset and the device are sent in the first
2640 * fm_extent. This function calculates the stripe number from the index.
2641 * This function returns a stripe_no on which mapping is to be restarted.
2643 * This function returns fm_end_offset which is the in-OST offset at which
2644 * mapping should be restarted. If fm_end_offset=0 is returned then caller
2645 * will re-calculate proper offset in next stripe.
2646 * Note that the first extent is passed to lov_get_info via the value field */
2647 obd_size fiemap_calc_fm_end_offset(struct ll_user_fiemap *fiemap,
2648 struct lov_stripe_md *lsm, obd_size fm_start,
2649 obd_size fm_end, int *start_stripe)
2651 obd_size local_end = fiemap->fm_extents[0].fe_logical;
2652 obd_off lun_start, lun_end;
2653 obd_size fm_end_offset;
2654 int stripe_no = -1, i;
2656 if (fiemap->fm_extent_count == 0 ||
2657 fiemap->fm_extents[0].fe_logical == 0)
2660 /* Find out stripe_no from ost_index saved in the fe_device */
2661 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2662 if (lsm->lsm_oinfo[i]->loi_ost_idx ==
2663 fiemap->fm_extents[0].fe_device) {
2669 /* If we have finished mapping on previous device, shift logical
2670 * offset to start of next device */
2671 if ((lov_stripe_intersects(lsm, stripe_no, fm_start, fm_end,
2672 &lun_start, &lun_end)) != 0 &&
2673 local_end < lun_end) {
2674 fm_end_offset = local_end;
2675 *start_stripe = stripe_no;
2677 /* This is a special value to indicate that caller should
2678 * calculate offset in next stripe. */
2680 *start_stripe = (stripe_no + 1) % lsm->lsm_stripe_count;
2683 return fm_end_offset;
2686 /* We calculate on which OST the mapping will end. If the length of mapping
2687 * is greater than (stripe_size * stripe_count) then the last_stripe will
2688 * will be one just before start_stripe. Else we check if the mapping
2689 * intersects each OST and find last_stripe.
2690 * This function returns the last_stripe and also sets the stripe_count
2691 * over which the mapping is spread */
2692 int fiemap_calc_last_stripe(struct lov_stripe_md *lsm, obd_size fm_start,
2693 obd_size fm_end, int start_stripe,
2697 obd_off obd_start, obd_end;
2700 if (fm_end - fm_start > lsm->lsm_stripe_size * lsm->lsm_stripe_count) {
2701 last_stripe = (start_stripe < 1 ? lsm->lsm_stripe_count - 1 :
2703 *stripe_count = lsm->lsm_stripe_count;
2705 for (j = 0, i = start_stripe; j < lsm->lsm_stripe_count;
2706 i = (i + 1) % lsm->lsm_stripe_count, j++) {
2707 if ((lov_stripe_intersects(lsm, i, fm_start, fm_end,
2708 &obd_start, &obd_end)) == 0)
2712 last_stripe = (start_stripe + j - 1) %lsm->lsm_stripe_count;
2718 /* Set fe_device and copy extents from local buffer into main return buffer */
2719 void fiemap_prepare_and_copy_exts(struct ll_user_fiemap *fiemap,
2720 struct ll_fiemap_extent *lcl_fm_ext,
2721 int ost_index, unsigned int ext_count,
2727 for (ext = 0; ext < ext_count; ext++) {
2728 lcl_fm_ext[ext].fe_device = ost_index;
2729 lcl_fm_ext[ext].fe_flags |= FIEMAP_EXTENT_NET;
2732 /* Copy fm_extent's from fm_local to return buffer */
2733 to = (char *)fiemap + fiemap_count_to_size(current_extent);
2734 memcpy(to, lcl_fm_ext, ext_count * sizeof(struct ll_fiemap_extent));
2737 static int lov_fiemap(struct lov_obd *lov, __u32 keylen, void *key,
2738 __u32 *vallen, void *val, struct lov_stripe_md *lsm)
2740 struct ll_fiemap_info_key *fm_key = key;
2741 struct ll_user_fiemap *fiemap = val;
2742 struct ll_user_fiemap *fm_local = NULL;
2743 struct ll_fiemap_extent *lcl_fm_ext;
2745 unsigned int get_num_extents = 0;
2746 int ost_index = 0, actual_start_stripe, start_stripe;
2747 obd_size fm_start, fm_end, fm_length, fm_end_offset = 0;
2749 int current_extent = 0, rc = 0, i;
2750 int ost_eof = 0; /* EOF for object */
2751 int ost_done = 0; /* done with required mapping for this OST? */
2753 int cur_stripe = 0, cur_stripe_wrap = 0, stripe_count;
2754 unsigned int buffer_size = FIEMAP_BUFFER_SIZE;
2759 if (fiemap_count_to_size(fm_key->fiemap.fm_extent_count) < buffer_size)
2760 buffer_size = fiemap_count_to_size(fm_key->fiemap.fm_extent_count);
2762 OBD_ALLOC(fm_local, buffer_size);
2763 if (fm_local == NULL)
2764 GOTO(out, rc = -ENOMEM);
2765 lcl_fm_ext = &fm_local->fm_extents[0];
2767 count_local = fiemap_size_to_count(buffer_size);
2769 memcpy(fiemap, &fm_key->fiemap, sizeof(*fiemap));
2770 fm_start = fiemap->fm_start;
2771 fm_length = fiemap->fm_length;
2772 /* Calculate start stripe, last stripe and length of mapping */
2773 actual_start_stripe = start_stripe = lov_stripe_number(lsm, fm_start);
2774 fm_end = (fm_length == ~0ULL ? fm_key->oa.o_size :
2775 fm_start + fm_length - 1);
2776 /* If fm_length != ~0ULL but fm_start+fm_length-1 exceeds file size */
2777 if (fm_end > fm_key->oa.o_size)
2778 fm_end = fm_key->oa.o_size;
2780 last_stripe = fiemap_calc_last_stripe(lsm, fm_start, fm_end,
2781 actual_start_stripe, &stripe_count);
2783 fm_end_offset = fiemap_calc_fm_end_offset(fiemap, lsm, fm_start, fm_end,
2786 if (fiemap->fm_extent_count == 0) {
2787 get_num_extents = 1;
2791 /* Check each stripe */
2792 for (cur_stripe = start_stripe, i = 0; i < stripe_count;
2793 i++, cur_stripe = (cur_stripe + 1) % lsm->lsm_stripe_count) {
2794 obd_size req_fm_len; /* Stores length of required mapping */
2795 obd_size len_mapped_single_call;
2796 obd_off lun_start, lun_end, obd_object_end;
2797 unsigned int ext_count;
2799 cur_stripe_wrap = cur_stripe;
2801 /* Find out range of mapping on this stripe */
2802 if ((lov_stripe_intersects(lsm, cur_stripe, fm_start, fm_end,
2803 &lun_start, &obd_object_end)) == 0)
2806 /* If this is a continuation FIEMAP call and we are on
2807 * starting stripe then lun_start needs to be set to
2809 if (fm_end_offset != 0 && cur_stripe == start_stripe)
2810 lun_start = fm_end_offset;
2812 if (fm_length != ~0ULL) {
2813 /* Handle fm_start + fm_length overflow */
2814 if (fm_start + fm_length < fm_start)
2815 fm_length = ~0ULL - fm_start;
2816 lun_end = lov_size_to_stripe(lsm, fm_start + fm_length,
2822 if (lun_start == lun_end)
2825 req_fm_len = obd_object_end - lun_start;
2826 fm_local->fm_length = 0;
2827 len_mapped_single_call = 0;
2829 /* If the output buffer is very large and the objects have many
2830 * extents we may need to loop on a single OST repeatedly */
2834 if (get_num_extents == 0) {
2835 /* Don't get too many extents. */
2836 if (current_extent + count_local >
2837 fiemap->fm_extent_count)
2838 count_local = fiemap->fm_extent_count -
2842 lun_start += len_mapped_single_call;
2843 fm_local->fm_length = req_fm_len - len_mapped_single_call;
2844 req_fm_len = fm_local->fm_length;
2845 fm_local->fm_extent_count = count_local;
2846 fm_local->fm_mapped_extents = 0;
2847 fm_local->fm_flags = fiemap->fm_flags;
2849 fm_key->oa.o_id = lsm->lsm_oinfo[cur_stripe]->loi_id;
2850 fm_key->oa.o_gr = lsm->lsm_oinfo[cur_stripe]->loi_gr;
2851 ost_index = lsm->lsm_oinfo[cur_stripe]->loi_ost_idx;
2853 if (ost_index < 0 || ost_index >=lov->desc.ld_tgt_count)
2854 GOTO(out, rc = -EINVAL);
2856 /* If OST is inactive, return extent with UNKNOWN flag */
2857 if (!lov->lov_tgts[ost_index]->ltd_active) {
2858 fm_local->fm_flags |= FIEMAP_EXTENT_LAST;
2859 fm_local->fm_mapped_extents = 1;
2861 lcl_fm_ext[0].fe_logical = lun_start;
2862 lcl_fm_ext[0].fe_length = obd_object_end -
2864 lcl_fm_ext[0].fe_flags |= FIEMAP_EXTENT_UNKNOWN;
2869 fm_local->fm_start = lun_start;
2870 fm_local->fm_flags &= ~FIEMAP_FLAG_DEVICE_ORDER;
2871 memcpy(&fm_key->fiemap, fm_local, sizeof(*fm_local));
2872 *vallen=fiemap_count_to_size(fm_local->fm_extent_count);
2873 rc = obd_get_info(lov->lov_tgts[ost_index]->ltd_exp,
2874 keylen, key, vallen, fm_local, lsm);
2879 ext_count = fm_local->fm_mapped_extents;
2880 if (ext_count == 0) {
2882 /* If last stripe has hole at the end,
2883 * then we need to return */
2884 if (cur_stripe_wrap == last_stripe) {
2885 fiemap->fm_mapped_extents = 0;
2891 /* If we just need num of extents then go to next device */
2892 if (get_num_extents) {
2893 current_extent += ext_count;
2897 len_mapped_single_call = lcl_fm_ext[ext_count-1].fe_logical -
2898 lun_start + lcl_fm_ext[ext_count - 1].fe_length;
2900 /* Have we finished mapping on this device? */
2901 if (req_fm_len <= len_mapped_single_call)
2904 /* Clear the EXTENT_LAST flag which can be present on
2906 if (lcl_fm_ext[ext_count-1].fe_flags & FIEMAP_EXTENT_LAST)
2907 lcl_fm_ext[ext_count - 1].fe_flags &=
2908 ~FIEMAP_EXTENT_LAST;
2910 curr_loc = lov_stripe_size(lsm,
2911 lcl_fm_ext[ext_count - 1].fe_logical+
2912 lcl_fm_ext[ext_count - 1].fe_length,
2914 if (curr_loc >= fm_key->oa.o_size)
2917 fiemap_prepare_and_copy_exts(fiemap, lcl_fm_ext,
2918 ost_index, ext_count,
2921 current_extent += ext_count;
2923 /* Ran out of available extents? */
2924 if (current_extent >= fiemap->fm_extent_count)
2926 } while (ost_done == 0 && ost_eof == 0);
2928 if (cur_stripe_wrap == last_stripe)
2933 /* Indicate that we are returning device offsets unless file just has
2935 if (lsm->lsm_stripe_count > 1)
2936 fiemap->fm_flags |= FIEMAP_FLAG_DEVICE_ORDER;
2938 if (get_num_extents)
2939 goto skip_last_device_calc;
2941 /* Check if we have reached the last stripe and whether mapping for that
2942 * stripe is done. */
2943 if (cur_stripe_wrap == last_stripe) {
2944 if (ost_done || ost_eof)
2945 fiemap->fm_extents[current_extent - 1].fe_flags |=
2949 skip_last_device_calc:
2950 fiemap->fm_mapped_extents = current_extent;
2953 OBD_FREE(fm_local, buffer_size);
2957 static int lov_get_info(struct obd_export *exp, __u32 keylen,
2958 void *key, __u32 *vallen, void *val,
2959 struct lov_stripe_md *lsm)
2961 struct obd_device *obddev = class_exp2obd(exp);
2962 struct lov_obd *lov = &obddev->u.lov;
2966 if (!vallen || !val)
2971 if (KEY_IS(KEY_LOCK_TO_STRIPE)) {
2974 struct ldlm_lock *lock;
2976 struct ldlm_res_id *res_id = &data->lock->l_resource->lr_name;
2977 struct lov_oinfo *loi;
2978 __u32 *stripe = val;
2980 if (*vallen < sizeof(*stripe))
2981 GOTO(out, rc = -EFAULT);
2982 *vallen = sizeof(*stripe);
2984 /* XXX This is another one of those bits that will need to
2985 * change if we ever actually support nested LOVs. It uses
2986 * the lock's export to find out which stripe it is. */
2987 /* XXX - it's assumed all the locks for deleted OSTs have
2988 * been cancelled. Also, the export for deleted OSTs will
2989 * be NULL and won't match the lock's export. */
2990 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2991 loi = lsm->lsm_oinfo[i];
2992 if (!lov->lov_tgts[loi->loi_ost_idx])
2994 if (lov->lov_tgts[loi->loi_ost_idx]->ltd_exp ==
2995 data->lock->l_conn_export &&
2996 osc_res_name_eq(loi->loi_id, loi->loi_gr, res_id)) {
3001 LDLM_ERROR(data->lock, "lock on inode without such object");
3002 dump_lsm(D_ERROR, lsm);
3003 GOTO(out, rc = -ENXIO);
3004 } else if (KEY_IS(KEY_LAST_ID)) {
3005 struct obd_id_info *info = val;
3006 __u32 size = sizeof(obd_id);
3007 struct lov_tgt_desc *tgt;
3009 LASSERT(*vallen == sizeof(struct obd_id_info));
3010 tgt = lov->lov_tgts[info->idx];
3012 if (!tgt || !tgt->ltd_active)
3013 GOTO(out, rc = -ESRCH);
3015 rc = obd_get_info(tgt->ltd_exp, keylen, key, &size, info->data, NULL);
3017 } else if (KEY_IS(KEY_LOVDESC)) {
3018 struct lov_desc *desc_ret = val;
3019 *desc_ret = lov->desc;
3022 } else if (KEY_IS(KEY_FIEMAP)) {
3023 rc = lov_fiemap(lov, keylen, key, vallen, val, lsm);
3025 } else if (KEY_IS(KEY_OFF_RPCSIZE)) {
3026 __u64 *offset = val;
3027 struct lov_tgt_desc *tgt;
3028 struct lov_oinfo *loi;
3031 LASSERT(*vallen == sizeof(__u64));
3032 stripe = lov_stripe_number(lsm, *offset);
3033 loi = lsm->lsm_oinfo[stripe];
3034 tgt = lov->lov_tgts[loi->loi_ost_idx];
3035 if (!tgt || !tgt->ltd_active)
3036 GOTO(out, rc = -ESRCH);
3037 rc = obd_get_info(tgt->ltd_exp, keylen, key, vallen, val, NULL);
3039 } else if (KEY_IS(KEY_CONNECT_FLAG)) {
3040 struct lov_tgt_desc *tgt;
3041 __u64 ost_idx = *((__u64*)val);
3043 LASSERT(*vallen == sizeof(__u64));
3044 LASSERT(ost_idx < lov->desc.ld_tgt_count);
3045 tgt = lov->lov_tgts[ost_idx];
3047 if (!tgt || !tgt->ltd_exp)
3048 GOTO(out, rc = -ESRCH);
3050 *((__u64*)val) = tgt->ltd_exp->exp_connect_flags;
3060 static int lov_set_info_async(struct obd_export *exp, obd_count keylen,
3061 void *key, obd_count vallen, void *val,
3062 struct ptlrpc_request_set *set)
3064 struct obd_device *obddev = class_exp2obd(exp);
3065 struct lov_obd *lov = &obddev->u.lov;
3067 int i, rc = 0, err, incr = 0, check_uuid = 0, do_inactive = 0;
3069 unsigned next_id = 0;
3070 struct lov_tgt_desc *tgt;
3075 set = ptlrpc_prep_set();
3081 count = lov->desc.ld_tgt_count;
3083 if (KEY_IS(KEY_NEXT_ID)) {
3084 count = vallen / sizeof(struct obd_id_info);
3085 vallen = sizeof(obd_id);
3086 incr = sizeof(struct obd_id_info);
3089 } else if (KEY_IS(KEY_CHECKSUM)) {
3091 } else if (KEY_IS(KEY_MDS_CONN)) {
3092 check_uuid = val ? 1 : 0;
3093 } else if (KEY_IS(KEY_EVICT_BY_NID)) {
3095 do_inactive = incr = 0;
3099 for (i = 0; i < count; i++, val = (char *)val + incr) {
3101 tgt = lov->lov_tgts[((struct obd_id_info*)val)->idx];
3102 data = ((struct obd_id_info*)val)->data;
3104 tgt = lov->lov_tgts[i];
3107 /* OST was disconnected */
3108 if (!tgt || !tgt->ltd_exp)
3111 /* OST is inactive and we don't want inactive OSCs */
3112 if (!tgt->ltd_active && !do_inactive)
3115 /* Only want a specific OSC */
3117 !obd_uuid_equals(val, &tgt->ltd_uuid))
3120 err = obd_set_info_async(tgt->ltd_exp,
3121 keylen, key, vallen, data, set);
3127 err = ptlrpc_set_wait(set);
3130 ptlrpc_set_destroy(set);
3135 static int lov_checkmd(struct obd_export *exp, struct obd_export *md_exp,
3136 struct lov_stripe_md *lsm)
3144 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
3145 rc = lsm_op_find(lsm->lsm_magic)->lsm_revalidate(lsm, md_exp->exp_obd);
3150 int lov_test_and_clear_async_rc(struct lov_stripe_md *lsm)
3152 struct lov_oinfo *loi;
3156 for (i = 0; i < lsm->lsm_stripe_count; i++) {
3157 loi = lsm->lsm_oinfo[i];
3158 if (loi->loi_ar.ar_rc && !rc)
3159 rc = loi->loi_ar.ar_rc;
3160 loi->loi_ar.ar_rc = 0;
3164 EXPORT_SYMBOL(lov_test_and_clear_async_rc);
3167 static int lov_extent_calc(struct obd_export *exp, struct lov_stripe_md *lsm,
3168 int cmd, __u64 *offset)
3171 __u32 ssize = lsm->lsm_stripe_size;
3173 if (cmd & OBD_CALC_STRIPE_RPC_ALIGN)
3174 ssize = ssize > PTLRPC_MAX_BRW_SIZE ?
3175 PTLRPC_MAX_BRW_SIZE : ssize;
3178 do_div(start, ssize);
3179 start = start * ssize;
3181 CDEBUG(D_DLMTRACE, "offset "LPU64", stripe %u, start "LPU64
3182 ", end "LPU64"\n", *offset, ssize, start, start + ssize - 1);
3183 if (cmd & OBD_CALC_STRIPE_END)
3184 *offset = start + ssize - 1;
3185 else if (cmd & OBD_CALC_STRIPE_START)
3194 struct lov_multi_wait {
3195 struct ldlm_lock *lock;
3201 int lov_complete_many(struct obd_export *exp, struct lov_stripe_md *lsm,
3202 struct lustre_handle *lockh)
3204 struct lov_lock_handles *lov_lockh = NULL;
3205 struct lustre_handle *lov_lockhp;
3206 struct lov_obd *lov;
3207 struct lov_oinfo *loi;
3208 struct lov_multi_wait *queues;
3212 ASSERT_LSM_MAGIC(lsm);
3214 if (!exp || !exp->exp_obd)
3217 LASSERT(lockh != NULL);
3218 if (lsm->lsm_stripe_count > 1) {
3219 lov_lockh = lov_handle2llh(lockh);
3220 if (lov_lockh == NULL) {
3221 CERROR("LOV: invalid lov lock handle %p\n", lockh);
3225 lov_lockhp = lov_lockh->llh_handles;
3230 OBD_ALLOC(queues, lsm->lsm_stripe_count * sizeof(*queues));
3232 GOTO(out, rc = -ENOMEM);
3234 lov = &exp->exp_obd->u.lov;
3235 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
3236 i++, loi++, lov_lockhp++) {
3237 struct ldlm_lock *lock;
3238 struct obd_device *obd;
3240 lock = ldlm_handle2lock(lov_lockhp);
3242 CDEBUG(D_HA, "lov idx %d subobj "LPX64" no lock?\n",
3243 loi->loi_ost_idx, loi->loi_id);
3244 queues[i].completed = 1;
3248 queues[i].lock = lock;
3249 init_waitqueue_entry(&(queues[i].wait), current);
3250 add_wait_queue(lock->l_waitq, &(queues[i].wait));
3252 obd = class_exp2obd(lock->l_conn_export);
3254 imp = obd->u.cli.cl_import;
3256 spin_lock(&imp->imp_lock);
3257 queues[i].generation = imp->imp_generation;
3258 spin_unlock(&imp->imp_lock);
3262 lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, ldlm_expired_completion_wait,
3263 interrupted_completion_wait, &lwd);
3264 rc = l_wait_event_added(check_multi_complete(queues, lsm), &lwi);
3266 for (i = 0; i < lsm->lsm_stripe_count; i++)
3267 remove_wait_queue(lock->l_waitq, &(queues[i].wait));
3269 if (rc == -EINTR || rc == -ETIMEDOUT) {
3275 if (lov_lockh != NULL)
3276 lov_llh_put(lov_lockh);
3281 void lov_stripe_lock(struct lov_stripe_md *md)
3283 LASSERT(md->lsm_lock_owner != cfs_current());
3284 spin_lock(&md->lsm_lock);
3285 LASSERT(md->lsm_lock_owner == NULL);
3286 md->lsm_lock_owner = cfs_current();
3288 EXPORT_SYMBOL(lov_stripe_lock);
3290 void lov_stripe_unlock(struct lov_stripe_md *md)
3292 LASSERT(md->lsm_lock_owner == cfs_current());
3293 md->lsm_lock_owner = NULL;
3294 spin_unlock(&md->lsm_lock);
3296 EXPORT_SYMBOL(lov_stripe_unlock);
3298 static int lov_get_lock(struct obd_export *exp, struct lov_stripe_md *lsm,
3299 void **res, int rw, obd_off start, obd_off end,
3300 struct lustre_handle *lockh, int flags)
3302 struct lov_async_page *l = *res;
3303 obd_off stripe_start, stripe_end = start;
3304 struct lov_lock_handles *lov_lockh = NULL;
3309 if (lockh && lustre_handle_is_used(lockh) &&
3310 !(flags & OBD_FAST_LOCK)) {
3311 lov_lockh = lov_handle2llh(lockh);
3312 if (lov_lockh == NULL) {
3313 CERROR("LOV: invalid lov lock handle %p\n", lockh);
3316 lockh = lov_lockh->llh_handles + l->lap_stripe;
3319 /* ensure we don't cross stripe boundaries */
3320 lov_extent_calc(exp, lsm, OBD_CALC_STRIPE_END, &stripe_end);
3321 if (stripe_end < end)
3324 /* map the region limits to the object limits */
3325 lov_stripe_offset(lsm, start, l->lap_stripe, &stripe_start);
3326 lov_stripe_offset(lsm, end, l->lap_stripe, &stripe_end);
3328 rc = obd_get_lock(exp->exp_obd->u.lov.lov_tgts[lsm->
3329 lsm_oinfo[l->lap_stripe]->loi_ost_idx]->
3330 ltd_exp, NULL, &l->lap_sub_cookie,
3331 rw, stripe_start, stripe_end, lockh, flags);
3333 if (lov_lockh != NULL)
3334 lov_llh_put(lov_lockh);
3338 struct obd_ops lov_obd_ops = {
3339 .o_owner = THIS_MODULE,
3340 .o_setup = lov_setup,
3341 .o_precleanup = lov_precleanup,
3342 .o_cleanup = lov_cleanup,
3343 .o_process_config = lov_process_config,
3344 .o_connect = lov_connect,
3345 .o_disconnect = lov_disconnect,
3346 .o_statfs = lov_statfs,
3347 .o_statfs_async = lov_statfs_async,
3348 .o_packmd = lov_packmd,
3349 .o_unpackmd = lov_unpackmd,
3350 .o_checkmd = lov_checkmd,
3351 .o_create = lov_create,
3352 .o_destroy = lov_destroy,
3353 .o_getattr = lov_getattr,
3354 .o_getattr_async = lov_getattr_async,
3355 .o_setattr = lov_setattr,
3356 .o_setattr_async = lov_setattr_async,
3358 .o_brw_async = lov_brw_async,
3359 .o_prep_async_page = lov_prep_async_page,
3360 .o_get_lock = lov_get_lock,
3361 .o_queue_async_io = lov_queue_async_io,
3362 .o_set_async_flags = lov_set_async_flags,
3363 .o_queue_group_io = lov_queue_group_io,
3364 .o_trigger_group_io = lov_trigger_group_io,
3365 .o_teardown_async_page = lov_teardown_async_page,
3366 .o_merge_lvb = lov_merge_lvb,
3367 .o_update_lvb = lov_update_lvb,
3368 .o_adjust_kms = lov_adjust_kms,
3369 .o_punch = lov_punch,
3371 .o_enqueue = lov_enqueue,
3372 .o_match = lov_match,
3373 .o_change_cbdata = lov_change_cbdata,
3374 .o_find_cbdata = lov_find_cbdata,
3375 .o_cancel = lov_cancel,
3376 .o_cancel_unused = lov_cancel_unused,
3377 .o_join_lru = lov_join_lru,
3378 .o_iocontrol = lov_iocontrol,
3379 .o_get_info = lov_get_info,
3380 .o_set_info_async = lov_set_info_async,
3381 .o_extent_calc = lov_extent_calc,
3382 .o_llog_init = lov_llog_init,
3383 .o_llog_finish = lov_llog_finish,
3384 .o_notify = lov_notify,
3385 .o_register_page_removal_cb = lov_obd_register_page_removal_cb,
3386 .o_unregister_page_removal_cb = lov_obd_unregister_page_removal_cb,
3387 .o_register_lock_cancel_cb = lov_obd_register_lock_cancel_cb,
3388 .o_unregister_lock_cancel_cb = lov_obd_unregister_lock_cancel_cb,
3389 .o_pool_new = lov_pool_new,
3390 .o_pool_rem = lov_pool_remove,
3391 .o_pool_add = lov_pool_add,
3392 .o_pool_del = lov_pool_del,
3393 .o_getref = lov_getref,
3394 .o_putref = lov_putref,
3397 static quota_interface_t *quota_interface;
3398 extern quota_interface_t lov_quota_interface;
3400 cfs_mem_cache_t *lov_oinfo_slab;
3402 int __init lov_init(void)
3404 struct lprocfs_static_vars lvars = { 0 };
3408 lov_oinfo_slab = cfs_mem_cache_create("lov_oinfo",
3409 sizeof(struct lov_oinfo),
3410 0, SLAB_HWCACHE_ALIGN);
3411 if (lov_oinfo_slab == NULL)
3413 lprocfs_lov_init_vars(&lvars);
3415 request_module("lquota");
3416 quota_interface = PORTAL_SYMBOL_GET(lov_quota_interface);
3417 init_obd_quota_ops(quota_interface, &lov_obd_ops);
3419 rc = class_register_type(&lov_obd_ops, lvars.module_vars,
3422 if (quota_interface)
3423 PORTAL_SYMBOL_PUT(lov_quota_interface);
3424 rc2 = cfs_mem_cache_destroy(lov_oinfo_slab);
3432 static void /*__exit*/ lov_exit(void)
3436 if (quota_interface)
3437 PORTAL_SYMBOL_PUT(lov_quota_interface);
3439 class_unregister_type(LUSTRE_LOV_NAME);
3440 rc = cfs_mem_cache_destroy(lov_oinfo_slab);
3444 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
3445 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver");
3446 MODULE_LICENSE("GPL");
3448 cfs_module(lov, LUSTRE_VERSION_STRING, lov_init, lov_exit);