1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/lov/lov_obd.c
38 * Author: Phil Schwan <phil@clusterfs.com>
39 * Author: Peter Braam <braam@clusterfs.com>
40 * Author: Mike Shaver <shaver@clusterfs.com>
41 * Author: Nathan Rutman <nathan@clusterfs.com>
45 # define EXPORT_SYMTAB
47 #define DEBUG_SUBSYSTEM S_LOV
49 #include <libcfs/libcfs.h>
51 #include <liblustre.h>
54 #include <obd_support.h>
55 #include <lustre_lib.h>
56 #include <lustre_net.h>
57 #include <lustre/lustre_idl.h>
58 #include <lustre_dlm.h>
59 #include <lustre_mds.h>
60 #include <lustre_debug.h>
61 #include <obd_class.h>
64 #include <lprocfs_status.h>
65 #include <lustre_param.h>
66 #include <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,
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) {
204 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
205 CERROR("unexpected notification of %s %s!\n",
206 watched->obd_type->typ_name,
211 /* Set OSC as active before notifying the observer, so the
212 * observer can use the OSC normally.
214 rc = lov_set_osc_active(obd, &watched->u.cli.cl_target_uuid,
215 ev == OBD_NOTIFY_ACTIVE);
217 CERROR("%sactivation of %s failed: %d\n",
218 (ev == OBD_NOTIFY_ACTIVE) ? "" : "de",
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 CERROR("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 /* Why should there ever be more than 1 connect? */
394 LASSERT(lov->lov_connects == 1);
396 memset(&lov->lov_ocd, 0, sizeof(lov->lov_ocd));
398 lov->lov_ocd = *data;
401 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
402 tgt = lov->lov_tgts[i];
403 if (!tgt || obd_uuid_empty(&tgt->ltd_uuid))
405 /* Flags will be lowest common denominator */
406 rc = lov_connect_obd(obd, i, lov->lov_tgts[i]->ltd_activate,
409 CERROR("%s: lov connect tgt %d failed: %d\n",
410 obd->obd_name, i, rc);
413 /* connect to administrative disabled ost */
414 if (!lov->lov_tgts[i]->ltd_exp)
417 rc = lov_notify(obd, lov->lov_tgts[i]->ltd_exp->exp_obd,
418 OBD_NOTIFY_CONNECT, (void *)&i);
420 CERROR("%s error sending notify %d\n",
429 static int lov_disconnect_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
431 cfs_proc_dir_entry_t *lov_proc_dir;
432 struct lov_obd *lov = &obd->u.lov;
433 struct obd_device *osc_obd = class_exp2obd(tgt->ltd_exp);
438 CDEBUG(D_CONFIG, "%s: disconnecting target %s\n",
439 obd->obd_name, osc_obd->obd_name);
441 if (tgt->ltd_active) {
443 lov->desc.ld_active_tgt_count--;
444 tgt->ltd_exp->exp_obd->obd_inactive = 1;
447 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
449 cfs_proc_dir_entry_t *osc_symlink;
451 osc_symlink = lprocfs_srch(lov_proc_dir, osc_obd->obd_name);
453 lprocfs_remove(&osc_symlink);
455 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing.",
456 obd->obd_type->typ_name, obd->obd_name,
461 if (obd->obd_force) {
462 /* Pass it on to our clients.
463 * XXX This should be an argument to disconnect,
464 * XXX not a back-door flag on the OBD. Ah well.
467 osc_obd->obd_force = 1;
470 obd_register_observer(osc_obd, NULL);
472 obd_unregister_page_removal_cb(osc_obd, lov->lov_page_removal_cb);
473 obd_unregister_lock_cancel_cb(osc_obd, lov->lov_lock_cancel_cb);
475 rc = obd_disconnect(tgt->ltd_exp);
477 CERROR("Target %s disconnect error %d\n",
478 tgt->ltd_uuid.uuid, rc);
482 qos_del_tgt(obd, tgt);
489 static int lov_del_target(struct obd_device *obd, __u32 index,
490 struct obd_uuid *uuidp, int gen);
492 static int lov_disconnect(struct obd_export *exp)
494 struct obd_device *obd = class_exp2obd(exp);
495 struct lov_obd *lov = &obd->u.lov;
502 /* Only disconnect the underlying layers on the final disconnect. */
504 if (lov->lov_connects != 0) {
505 /* why should there be more than 1 connect? */
506 CERROR("disconnect #%d\n", lov->lov_connects);
510 /* Let's hold another reference so lov_del_obd doesn't spin through
513 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
514 if (lov->lov_tgts[i] && lov->lov_tgts[i]->ltd_exp) {
515 /* Disconnection is the last we know about an obd */
516 lov_del_target(obd, i, 0, lov->lov_tgts[i]->ltd_gen);
522 rc = class_disconnect(exp); /* bz 9811 */
528 * -EINVAL : UUID can't be found in the LOV's target list
529 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
530 * -EBADF : The UUID is found, but the OBD is the wrong type (!)
531 * - any above 0 is lov index
533 static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
536 struct lov_obd *lov = &obd->u.lov;
537 struct lov_tgt_desc *tgt;
541 CDEBUG(D_INFO, "Searching in lov %p for uuid %s (activate=%d)\n",
542 lov, uuid->uuid, activate);
545 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
546 tgt = lov->lov_tgts[i];
547 if (!tgt || !tgt->ltd_exp)
550 CDEBUG(D_INFO, "lov idx %d is %s conn "LPX64"\n",
551 i, obd_uuid2str(&tgt->ltd_uuid),
552 tgt->ltd_exp->exp_handle.h_cookie);
553 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
557 if (i == lov->desc.ld_tgt_count)
558 GOTO(out, i = -EINVAL);
560 if (lov->lov_tgts[i]->ltd_active == activate) {
561 CDEBUG(D_INFO, "OSC %s already %sactive!\n", uuid->uuid,
562 activate ? "" : "in");
566 CDEBUG(D_CONFIG, "Marking OSC %s %sactive\n", obd_uuid2str(uuid),
567 activate ? "" : "in");
569 lov->lov_tgts[i]->ltd_active = activate;
572 lov->desc.ld_active_tgt_count++;
573 lov->lov_tgts[i]->ltd_exp->exp_obd->obd_inactive = 0;
575 lov->desc.ld_active_tgt_count--;
576 lov->lov_tgts[i]->ltd_exp->exp_obd->obd_inactive = 1;
578 /* remove any old qos penalty */
579 lov->lov_tgts[i]->ltd_qos.ltq_penalty = 0;
587 static int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
588 __u32 index, int gen, int active)
590 struct obd_device *tgt_obd;
591 struct lov_obd *lov = &obd->u.lov;
592 struct lov_tgt_desc *tgt;
596 CDEBUG(D_CONFIG, "uuid:%s idx:%d gen:%d active:%d\n",
597 uuidp->uuid, index, gen, active);
600 CERROR("request to add OBD %s with invalid generation: %d\n",
606 tgt_obd = class_find_client_obd(uuidp, LUSTRE_OSC_NAME,
609 CERROR("Target %s not attached\n", obd_uuid2str(uuidp));
613 mutex_down(&lov->lov_lock);
615 if ((index < lov->lov_tgt_size) && (lov->lov_tgts[index] != NULL)) {
616 tgt = lov->lov_tgts[index];
617 CERROR("UUID %s already assigned at LOV target index %d\n",
618 obd_uuid2str(&tgt->ltd_uuid), index);
619 GOTO(err_unlock, rc = -EEXIST);
622 if (index >= lov->lov_tgt_size) {
623 /* We need to reallocate the lov target array. */
624 struct lov_tgt_desc **newtgts, **old = NULL;
625 __u32 newsize, oldsize = 0;
627 newsize = max(lov->lov_tgt_size, (__u32)2);
628 while (newsize < index + 1)
629 newsize = newsize << 1;
630 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
632 GOTO(err_unlock, rc = -ENOMEM);
634 if (lov->lov_tgt_size) {
635 memcpy(newtgts, lov->lov_tgts, sizeof(*newtgts) *
638 oldsize = lov->lov_tgt_size;
641 lov->lov_tgts = newtgts;
642 lov->lov_tgt_size = newsize;
647 OBD_FREE(old, sizeof(*old) * oldsize);
649 CDEBUG(D_CONFIG, "tgts: %p size: %d\n",
650 lov->lov_tgts, lov->lov_tgt_size);
655 GOTO(err_unlock, rc = -ENOMEM);
657 rc = lov_ost_pool_add(&lov->lov_packed, index, lov->lov_tgt_size);
659 GOTO(err_free_tgt, rc = -EEXIST);
661 memset(tgt, 0, sizeof(*tgt));
662 tgt->ltd_obd = tgt_obd;
663 tgt->ltd_uuid = *uuidp;
664 /* XXX - add a sanity check on the generation number. */
666 tgt->ltd_index = index;
667 tgt->ltd_activate = active;
669 lov->lov_tgts[index] = tgt;
670 if (index >= lov->desc.ld_tgt_count)
671 lov->desc.ld_tgt_count = index + 1;
673 mutex_up(&lov->lov_lock);
675 CDEBUG(D_CONFIG, "idx=%d ltd_gen=%d ld_tgt_count=%d\n",
676 index, tgt->ltd_gen, lov->desc.ld_tgt_count);
678 rc = obd_notify(obd, tgt_obd, OBD_NOTIFY_CREATE, &index);
680 if (lov->lov_connects == 0) {
681 /* lov_connect hasn't been called yet. We'll do the
682 lov_connect_obd on this target when that fn first runs,
683 because we don't know the connect flags yet. */
689 rc = lov_connect_obd(obd, index, active, &lov->lov_ocd);
693 /* connect to administrative disabled ost */
697 rc = lov_notify(obd, tgt->ltd_exp->exp_obd,
698 active ? OBD_NOTIFY_CONNECT : OBD_NOTIFY_INACTIVE,
702 /* connect or notify failed - we can try connect later
703 * instead of complete delete target */
704 CERROR("connect or notify failed (%d) for %s\n", rc,
705 obd_uuid2str(&tgt->ltd_uuid));
713 mutex_up(&lov->lov_lock);
717 /* Schedule a target for deletion */
718 static int lov_del_target(struct obd_device *obd, __u32 index,
719 struct obd_uuid *uuidp, int gen)
721 struct lov_obd *lov = &obd->u.lov;
722 int count = lov->desc.ld_tgt_count;
726 if (index >= count) {
727 CERROR("LOV target index %d >= number of LOV OBDs %d.\n",
734 if (!lov->lov_tgts[index]) {
735 CERROR("LOV target at index %d is not setup.\n", index);
736 GOTO(out, rc = -EINVAL);
739 if (uuidp && !obd_uuid_equals(uuidp, &lov->lov_tgts[index]->ltd_uuid)) {
740 CERROR("LOV target UUID %s at index %d doesn't match %s.\n",
741 lov_uuid2str(lov, index), index,
742 obd_uuid2str(uuidp));
743 GOTO(out, rc = -EINVAL);
746 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d exp: %p active: %d\n",
747 lov_uuid2str(lov, index), index,
748 lov->lov_tgts[index]->ltd_gen, lov->lov_tgts[index]->ltd_exp,
749 lov->lov_tgts[index]->ltd_active);
751 lov->lov_tgts[index]->ltd_reap = 1;
752 lov->lov_death_row++;
753 /* we really delete it from obd_putref */
760 static void __lov_del_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
762 struct obd_device *osc_obd;
765 LASSERT(tgt->ltd_reap);
767 osc_obd = class_exp2obd(tgt->ltd_exp);
769 CDEBUG(D_CONFIG, "Removing tgt %s : %s\n",
771 osc_obd ? osc_obd->obd_name : "<no obd>");
774 lov_disconnect_obd(obd, tgt);
778 /* Manual cleanup - no cleanup logs to clean up the osc's. We must
779 do it ourselves. And we can't do it from lov_cleanup,
780 because we just lost our only reference to it. */
782 /* Use lov's force/fail flags. */
783 osc_obd->obd_force = obd->obd_force;
784 osc_obd->obd_fail = obd->obd_fail;
785 class_manual_cleanup(osc_obd);
789 void lov_fix_desc_stripe_size(__u64 *val)
791 if (*val < PTLRPC_MAX_BRW_SIZE) {
793 LCONSOLE_WARN("Increasing default stripe size from "
794 LPU64" to %u\n",*val,PTLRPC_MAX_BRW_SIZE);
795 *val = PTLRPC_MAX_BRW_SIZE;
796 } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) {
797 *val &= ~(LOV_MIN_STRIPE_SIZE - 1);
798 LCONSOLE_WARN("Changing default stripe size to "LPU64" (a "
800 *val, LOV_MIN_STRIPE_SIZE);
804 void lov_fix_desc_stripe_count(__u32 *val)
810 void lov_fix_desc_pattern(__u32 *val)
812 /* from lov_setstripe */
813 if ((*val != 0) && (*val != LOV_PATTERN_RAID0)) {
814 LCONSOLE_WARN("Unknown stripe pattern: %#x\n", *val);
819 void lov_fix_desc_qos_maxage(__u32 *val)
823 *val = QOS_DEFAULT_MAXAGE;
826 void lov_fix_desc(struct lov_desc *desc)
828 lov_fix_desc_stripe_size(&desc->ld_default_stripe_size);
829 lov_fix_desc_stripe_count(&desc->ld_default_stripe_count);
830 lov_fix_desc_pattern(&desc->ld_pattern);
831 lov_fix_desc_qos_maxage(&desc->ld_qos_maxage);
834 static int lov_setup(struct obd_device *obd, obd_count len, void *buf)
836 struct lprocfs_static_vars lvars = { 0 };
837 struct lustre_cfg *lcfg = buf;
838 struct lov_desc *desc;
839 struct lov_obd *lov = &obd->u.lov;
843 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
844 CERROR("LOV setup requires a descriptor\n");
848 desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
850 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
851 CERROR("descriptor size wrong: %d > %d\n",
852 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
856 if (desc->ld_magic != LOV_DESC_MAGIC) {
857 if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
858 CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n",
859 obd->obd_name, desc);
860 lustre_swab_lov_desc(desc);
862 CERROR("%s: Bad lov desc magic: %#x\n",
863 obd->obd_name, desc->ld_magic);
870 desc->ld_active_tgt_count = 0;
872 lov->lov_tgt_size = 0;
874 sema_init(&lov->lov_lock, 1);
875 atomic_set(&lov->lov_refcount, 0);
876 CFS_INIT_LIST_HEAD(&lov->lov_qos.lq_oss_list);
877 init_rwsem(&lov->lov_qos.lq_rw_sem);
878 lov->lov_qos.lq_dirty = 1;
879 lov->lov_qos.lq_rr.lqr_dirty = 1;
880 lov->lov_qos.lq_reset = 1;
881 /* Default priority is toward free space balance */
882 lov->lov_qos.lq_prio_free = 232;
883 /* Default threshold for rr (roughly 17%) */
884 lov->lov_qos.lq_threshold_rr = 43;
885 /* Init statfs fields */
886 OBD_ALLOC_PTR(lov->lov_qos.lq_statfs_data);
887 if (NULL == lov->lov_qos.lq_statfs_data)
889 cfs_waitq_init(&lov->lov_qos.lq_statfs_waitq);
891 lov->lov_pools_hash_body = lustre_hash_init("POOLS",
894 &pool_hash_operations, 0);
895 CFS_INIT_LIST_HEAD(&lov->lov_pool_list);
896 lov->lov_pool_count = 0;
897 rc = lov_ost_pool_init(&lov->lov_packed, 0);
900 rc = lov_ost_pool_init(&lov->lov_qos.lq_rr.lqr_pool, 0);
902 lov_ost_pool_free(&lov->lov_packed);
906 lprocfs_lov_init_vars(&lvars);
907 lprocfs_obd_setup(obd, lvars.obd_vars);
910 cfs_proc_dir_entry_t *entry;
912 entry = create_proc_entry("target_obd", 0444,
913 obd->obd_proc_entry);
915 entry->proc_fops = &lov_proc_target_fops;
920 lov->lov_pool_proc_entry = lprocfs_register("pools",
927 static int lov_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
933 case OBD_CLEANUP_EARLY: {
934 struct lov_obd *lov = &obd->u.lov;
936 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
937 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
939 obd_precleanup(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
944 case OBD_CLEANUP_EXPORTS:
946 case OBD_CLEANUP_SELF_EXP:
947 rc = obd_llog_finish(obd, 0);
949 CERROR("failed to cleanup llogging subsystems\n");
951 case OBD_CLEANUP_OBD:
957 static int lov_cleanup(struct obd_device *obd)
959 struct lov_obd *lov = &obd->u.lov;
960 struct list_head *pos, *tmp;
961 struct pool_desc *pool;
963 list_for_each_safe(pos, tmp, &lov->lov_pool_list) {
964 pool = list_entry(pos, struct pool_desc, pool_list);
965 /* free the pool structs */
966 CDEBUG(D_INFO, "delete pool %p\n", pool);
967 lov_pool_del(obd, pool->pool_name);
970 lustre_hash_exit(lov->lov_pools_hash_body);
972 lov_ost_pool_free(&(lov->lov_qos.lq_rr.lqr_pool));
973 lov_ost_pool_free(&lov->lov_packed);
978 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
979 if (lov->lov_tgts[i]) {
980 /* Inactive targets may never have connected */
981 if (lov->lov_tgts[i]->ltd_active ||
982 atomic_read(&lov->lov_refcount))
983 /* We should never get here - these
984 should have been removed in the
986 CERROR("lov tgt %d not cleaned!"
987 " deathrow=%d, lovrc=%d\n",
988 i, lov->lov_death_row,
989 atomic_read(&lov->lov_refcount));
990 lov_del_target(obd, i, 0, 0);
994 OBD_FREE(lov->lov_tgts, sizeof(*lov->lov_tgts) *
996 lov->lov_tgt_size = 0;
999 /* clear pools parent proc entry only after all pools is killed */
1000 lprocfs_obd_cleanup(obd);
1002 OBD_FREE_PTR(lov->lov_qos.lq_statfs_data);
1006 static int lov_process_config(struct obd_device *obd, obd_count len, void *buf)
1008 struct lustre_cfg *lcfg = buf;
1009 struct obd_uuid obd_uuid;
1014 switch(cmd = lcfg->lcfg_command) {
1015 case LCFG_LOV_ADD_OBD:
1016 case LCFG_LOV_ADD_INA:
1017 case LCFG_LOV_DEL_OBD: {
1020 /* lov_modify_tgts add 0:lov_mdsA 1:ost1_UUID 2:0 3:1 */
1021 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
1022 GOTO(out, rc = -EINVAL);
1024 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1026 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
1027 GOTO(out, rc = -EINVAL);
1028 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
1029 GOTO(out, rc = -EINVAL);
1030 if (cmd == LCFG_LOV_ADD_OBD)
1031 rc = lov_add_target(obd, &obd_uuid, index, gen, 1);
1032 else if (cmd == LCFG_LOV_ADD_INA)
1033 rc = lov_add_target(obd, &obd_uuid, index, gen, 0);
1035 rc = lov_del_target(obd, index, &obd_uuid, gen);
1039 struct lprocfs_static_vars lvars = { 0 };
1040 struct lov_desc *desc = &(obd->u.lov.desc);
1043 GOTO(out, rc = -EINVAL);
1045 lprocfs_lov_init_vars(&lvars);
1047 rc = class_process_proc_param(PARAM_LOV, lvars.obd_vars,
1058 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1059 GOTO(out, rc = -EINVAL);
1068 #define log2(n) ffz(~(n))
1071 static int lov_clear_orphans(struct obd_export *export, struct obdo *src_oa,
1072 struct lov_stripe_md **ea,
1073 struct obd_trans_info *oti)
1075 struct lov_obd *lov;
1076 struct obdo *tmp_oa;
1077 struct obd_uuid *ost_uuid = NULL;
1081 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
1082 src_oa->o_flags == OBD_FL_DELORPHAN);
1084 lov = &export->exp_obd->u.lov;
1090 if (oti->oti_ost_uuid) {
1091 ost_uuid = oti->oti_ost_uuid;
1092 CDEBUG(D_HA, "clearing orphans only for %s\n",
1096 obd_getref(export->exp_obd);
1097 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1098 struct lov_stripe_md obj_md;
1099 struct lov_stripe_md *obj_mdp = &obj_md;
1100 struct lov_tgt_desc *tgt;
1103 tgt = lov->lov_tgts[i];
1107 /* if called for a specific target, we don't
1108 care if it is not active. */
1109 if (!lov->lov_tgts[i]->ltd_active && ost_uuid == NULL) {
1110 CDEBUG(D_HA, "lov idx %d inactive\n", i);
1114 if (ost_uuid && !obd_uuid_equals(ost_uuid, &tgt->ltd_uuid))
1117 CDEBUG(D_CONFIG,"Clear orphans for %d:%s\n", i,
1118 obd_uuid2str(ost_uuid));
1120 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
1122 LASSERT(lov->lov_tgts[i]->ltd_exp);
1123 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1124 err = obd_create(lov->lov_tgts[i]->ltd_exp,
1125 tmp_oa, &obj_mdp, oti);
1127 /* This export will be disabled until it is recovered,
1128 and then orphan recovery will be completed. */
1129 CERROR("error in orphan recovery on OST idx %d/%d: "
1130 "rc = %d\n", i, lov->desc.ld_tgt_count, err);
1137 obd_putref(export->exp_obd);
1143 static int lov_recreate(struct obd_export *exp, struct obdo *src_oa,
1144 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1146 struct lov_stripe_md *obj_mdp, *lsm;
1147 struct lov_obd *lov = &exp->exp_obd->u.lov;
1152 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
1153 src_oa->o_flags & OBD_FL_RECREATE_OBJS);
1155 OBD_ALLOC(obj_mdp, sizeof(*obj_mdp));
1156 if (obj_mdp == NULL)
1159 ost_idx = src_oa->o_nlink;
1162 GOTO(out, rc = -EINVAL);
1163 if (ost_idx >= lov->desc.ld_tgt_count ||
1164 !lov->lov_tgts[ost_idx])
1165 GOTO(out, rc = -EINVAL);
1167 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1168 if (lsm->lsm_oinfo[i]->loi_ost_idx == ost_idx) {
1169 if (lsm->lsm_oinfo[i]->loi_id != src_oa->o_id)
1170 GOTO(out, rc = -EINVAL);
1174 if (i == lsm->lsm_stripe_count)
1175 GOTO(out, rc = -EINVAL);
1177 rc = obd_create(lov->lov_tgts[ost_idx]->ltd_exp, src_oa, &obj_mdp, oti);
1179 OBD_FREE(obj_mdp, sizeof(*obj_mdp));
1183 /* the LOV expects oa->o_id to be set to the LOV object id */
1184 static int lov_create(struct obd_export *exp, struct obdo *src_oa,
1185 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1187 struct lov_obd *lov;
1188 struct obd_info *oinfo;
1189 struct lov_request_set *set = NULL;
1190 struct lov_request *req;
1191 struct l_wait_info lwi = { 0 };
1195 LASSERT(ea != NULL);
1199 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1200 src_oa->o_flags == OBD_FL_DELORPHAN) {
1201 rc = lov_clear_orphans(exp, src_oa, ea, oti);
1205 lov = &exp->exp_obd->u.lov;
1206 if (!lov->desc.ld_active_tgt_count)
1209 OBD_ALLOC_PTR(oinfo);
1213 obd_getref(exp->exp_obd);
1214 /* Recreate a specific object id at the given OST index */
1215 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1216 (src_oa->o_flags & OBD_FL_RECREATE_OBJS)) {
1217 rc = lov_recreate(exp, src_oa, ea, oti);
1221 /* issue statfs rpcs if the osfs data is older than qos_maxage - 1s,
1222 * later in alloc_qos(), we will wait for those rpcs to complete if
1223 * the osfs age is older than 2 * qos_maxage */
1224 qos_statfs_update(exp->exp_obd,
1225 cfs_time_shift_64(-lov->desc.ld_qos_maxage +
1226 OBD_STATFS_CACHE_SECONDS),
1229 rc = lov_prep_create_set(exp, oinfo, ea, src_oa, oti, &set);
1233 list_for_each_entry(req, &set->set_list, rq_link) {
1234 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1235 rc = obd_create_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1236 &req->rq_oi, &req->rq_oi.oi_md, oti);
1239 /* osc_create have timeout equ obd_timeout/2 so waiting don't be
1240 * longer then this */
1241 l_wait_event(set->set_waitq, lov_finished_set(set), &lwi);
1243 /* we not have ptlrpc set for assign set->interpret and should
1244 * be call interpret function himself. calling from cb_create_update
1245 * not permited because lov_fini_create_set can sleep for long time,
1246 * but we must avoid sleeping in ptlrpcd interpret function. */
1247 rc = lov_fini_create_set(set, ea);
1249 obd_putref(exp->exp_obd);
1250 OBD_FREE_PTR(oinfo);
1254 #define ASSERT_LSM_MAGIC(lsmp) \
1256 LASSERT((lsmp) != NULL); \
1257 LASSERTF(((lsmp)->lsm_magic == LOV_MAGIC_V1 || \
1258 (lsmp)->lsm_magic == LOV_MAGIC_V3 || \
1259 (lsmp)->lsm_magic == LOV_MAGIC_JOIN), "%p->lsm_magic=%x\n", \
1260 (lsmp), (lsmp)->lsm_magic); \
1263 static int lov_destroy(struct obd_export *exp, struct obdo *oa,
1264 struct lov_stripe_md *lsm, struct obd_trans_info *oti,
1265 struct obd_export *md_exp)
1267 struct lov_request_set *set;
1268 struct obd_info *oinfo;
1269 struct lov_request *req;
1270 struct list_head *pos;
1271 struct lov_obd *lov;
1272 int rc = 0, err = 0;
1275 ASSERT_LSM_MAGIC(lsm);
1277 if (!exp || !exp->exp_obd)
1280 if (oa->o_valid & OBD_MD_FLCOOKIE) {
1282 LASSERT(oti->oti_logcookies);
1285 OBD_ALLOC_PTR(oinfo);
1289 lov = &exp->exp_obd->u.lov;
1290 obd_getref(exp->exp_obd);
1291 rc = lov_prep_destroy_set(exp, oinfo, oa, lsm, oti, &set);
1295 list_for_each (pos, &set->set_list) {
1296 req = list_entry(pos, struct lov_request, rq_link);
1298 if (oa->o_valid & OBD_MD_FLCOOKIE)
1299 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1301 err = obd_destroy(lov->lov_tgts[req->rq_idx]->ltd_exp,
1302 req->rq_oi.oi_oa, NULL, oti, NULL);
1303 err = lov_update_common_set(set, req, err);
1305 CERROR("error: destroying objid "LPX64" subobj "
1306 LPX64" on OST idx %d: rc = %d\n",
1307 oa->o_id, req->rq_oi.oi_oa->o_id,
1315 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
1316 rc = lsm_op_find(lsm->lsm_magic)->lsm_destroy(lsm, oa, md_exp);
1318 err = lov_fini_destroy_set(set);
1320 obd_putref(exp->exp_obd);
1321 OBD_FREE_PTR(oinfo);
1322 RETURN(rc ? rc : err);
1325 static int lov_getattr(struct obd_export *exp, struct obd_info *oinfo)
1327 struct lov_request_set *set;
1328 struct lov_request *req;
1329 struct list_head *pos;
1330 struct lov_obd *lov;
1331 int err = 0, rc = 0;
1335 ASSERT_LSM_MAGIC(oinfo->oi_md);
1337 if (!exp || !exp->exp_obd)
1340 lov = &exp->exp_obd->u.lov;
1342 rc = lov_prep_getattr_set(exp, oinfo, &set);
1346 list_for_each (pos, &set->set_list) {
1347 req = list_entry(pos, struct lov_request, rq_link);
1349 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1350 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1351 req->rq_oi.oi_oa->o_id, req->rq_idx);
1353 rc = obd_getattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1355 err = lov_update_common_set(set, req, rc);
1357 CERROR("error: getattr objid "LPX64" subobj "
1358 LPX64" on OST idx %d: rc = %d\n",
1359 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1365 rc = lov_fini_getattr_set(set);
1371 static int lov_getattr_interpret(struct ptlrpc_request_set *rqset,
1374 struct lov_request_set *lovset = (struct lov_request_set *)data;
1378 /* don't do attribute merge if this aysnc op failed */
1380 lovset->set_completes = 0;
1381 err = lov_fini_getattr_set(lovset);
1382 RETURN(rc ? rc : err);
1385 static int lov_getattr_async(struct obd_export *exp, struct obd_info *oinfo,
1386 struct ptlrpc_request_set *rqset)
1388 struct lov_request_set *lovset;
1389 struct lov_obd *lov;
1390 struct list_head *pos;
1391 struct lov_request *req;
1396 ASSERT_LSM_MAGIC(oinfo->oi_md);
1398 if (!exp || !exp->exp_obd)
1401 lov = &exp->exp_obd->u.lov;
1403 rc = lov_prep_getattr_set(exp, oinfo, &lovset);
1407 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1408 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1409 oinfo->oi_md->lsm_stripe_size);
1411 list_for_each (pos, &lovset->set_list) {
1412 req = list_entry(pos, struct lov_request, rq_link);
1414 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1415 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1416 req->rq_oi.oi_oa->o_id, req->rq_idx);
1417 rc = obd_getattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1418 &req->rq_oi, rqset);
1420 CERROR("error: getattr objid "LPX64" subobj "
1421 LPX64" on OST idx %d: rc = %d\n",
1422 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1428 if (!list_empty(&rqset->set_requests)) {
1430 LASSERT (rqset->set_interpret == NULL);
1431 rqset->set_interpret = lov_getattr_interpret;
1432 rqset->set_arg = (void *)lovset;
1437 lovset->set_completes = 0;
1438 err = lov_fini_getattr_set(lovset);
1439 RETURN(rc ? rc : err);
1442 static int lov_setattr(struct obd_export *exp, struct obd_info *oinfo,
1443 struct obd_trans_info *oti)
1445 struct lov_request_set *set;
1446 struct lov_obd *lov;
1447 struct list_head *pos;
1448 struct lov_request *req;
1449 int err = 0, rc = 0;
1453 ASSERT_LSM_MAGIC(oinfo->oi_md);
1455 if (!exp || !exp->exp_obd)
1458 /* for now, we only expect the following updates here */
1459 LASSERT(!(oinfo->oi_oa->o_valid & ~(OBD_MD_FLID | OBD_MD_FLTYPE |
1460 OBD_MD_FLMODE | OBD_MD_FLATIME |
1461 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1462 OBD_MD_FLFLAGS | OBD_MD_FLSIZE |
1463 OBD_MD_FLGROUP | OBD_MD_FLUID |
1464 OBD_MD_FLGID | OBD_MD_FLFID |
1466 lov = &exp->exp_obd->u.lov;
1467 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1471 list_for_each (pos, &set->set_list) {
1472 req = list_entry(pos, struct lov_request, rq_link);
1474 rc = obd_setattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1476 err = lov_update_setattr_set(set, req, rc);
1478 CERROR("error: setattr objid "LPX64" subobj "
1479 LPX64" on OST idx %d: rc = %d\n",
1480 set->set_oi->oi_oa->o_id,
1481 req->rq_oi.oi_oa->o_id, req->rq_idx, err);
1486 err = lov_fini_setattr_set(set);
1492 static int lov_setattr_interpret(struct ptlrpc_request_set *rqset,
1495 struct lov_request_set *lovset = (struct lov_request_set *)data;
1500 lovset->set_completes = 0;
1501 err = lov_fini_setattr_set(lovset);
1502 RETURN(rc ? rc : err);
1505 /* If @oti is given, the request goes from MDS and responses from OSTs are not
1506 needed. Otherwise, a client is waiting for responses. */
1507 static int lov_setattr_async(struct obd_export *exp, struct obd_info *oinfo,
1508 struct obd_trans_info *oti,
1509 struct ptlrpc_request_set *rqset)
1511 struct lov_request_set *set;
1512 struct lov_request *req;
1513 struct list_head *pos;
1514 struct lov_obd *lov;
1519 ASSERT_LSM_MAGIC(oinfo->oi_md);
1520 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE) {
1522 LASSERT(oti->oti_logcookies);
1525 if (!exp || !exp->exp_obd)
1528 lov = &exp->exp_obd->u.lov;
1529 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1533 CDEBUG(D_INFO, "objid "LPX64"@"LPX64": %ux%u byte stripes\n",
1534 oinfo->oi_md->lsm_object_id,
1535 oinfo->oi_md->lsm_object_gr,
1536 oinfo->oi_md->lsm_stripe_count,
1537 oinfo->oi_md->lsm_stripe_size);
1539 list_for_each (pos, &set->set_list) {
1540 req = list_entry(pos, struct lov_request, rq_link);
1542 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
1543 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1545 CDEBUG(D_INFO, "objid "LPX64"@"LPX64"[%d] has subobj "LPX64
1546 " at idx %u\n", oinfo->oi_oa->o_id, oinfo->oi_oa->o_gr,
1547 req->rq_stripe, req->rq_oi.oi_oa->o_id, req->rq_idx);
1549 rc = obd_setattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1550 &req->rq_oi, oti, rqset);
1552 CERROR("error: setattr objid "LPX64" subobj "
1553 LPX64" on OST idx %d: rc = %d\n",
1554 set->set_oi->oi_oa->o_id,
1555 req->rq_oi.oi_oa->o_id,
1561 /* If we are not waiting for responses on async requests, return. */
1562 if (rc || !rqset || list_empty(&rqset->set_requests)) {
1565 set->set_completes = 0;
1566 err = lov_fini_setattr_set(set);
1567 RETURN(rc ? rc : err);
1570 LASSERT(rqset->set_interpret == NULL);
1571 rqset->set_interpret = lov_setattr_interpret;
1572 rqset->set_arg = (void *)set;
1577 static int lov_punch_interpret(struct ptlrpc_request_set *rqset,
1580 struct lov_request_set *lovset = (struct lov_request_set *)data;
1585 lovset->set_completes = 0;
1586 err = lov_fini_punch_set(lovset);
1587 RETURN(rc ? rc : err);
1590 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
1591 * we can send this 'punch' to just the authoritative node and the nodes
1592 * that the punch will affect. */
1593 static int lov_punch(struct obd_export *exp, struct obd_info *oinfo,
1594 struct obd_trans_info *oti,
1595 struct ptlrpc_request_set *rqset)
1597 struct lov_request_set *set;
1598 struct lov_obd *lov;
1599 struct list_head *pos;
1600 struct lov_request *req;
1605 ASSERT_LSM_MAGIC(oinfo->oi_md);
1607 if (!exp || !exp->exp_obd)
1610 lov = &exp->exp_obd->u.lov;
1611 rc = lov_prep_punch_set(exp, oinfo, oti, &set);
1615 list_for_each (pos, &set->set_list) {
1616 req = list_entry(pos, struct lov_request, rq_link);
1618 rc = obd_punch(lov->lov_tgts[req->rq_idx]->ltd_exp,
1619 &req->rq_oi, NULL, rqset);
1621 CERROR("error: punch objid "LPX64" subobj "LPX64
1622 " on OST idx %d: rc = %d\n",
1623 set->set_oi->oi_oa->o_id,
1624 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1629 if (rc || list_empty(&rqset->set_requests)) {
1631 err = lov_fini_punch_set(set);
1632 RETURN(rc ? rc : err);
1635 LASSERT(rqset->set_interpret == NULL);
1636 rqset->set_interpret = lov_punch_interpret;
1637 rqset->set_arg = (void *)set;
1642 static int lov_sync_interpret(struct ptlrpc_request_set *rqset,
1645 struct lov_request_set *lovset = (struct lov_request_set *)data;
1650 lovset->set_completes = 0;
1651 err = lov_fini_sync_set(lovset);
1652 RETURN(rc ? rc : err);
1655 static int lov_sync(struct obd_export *exp, struct obd_info *oinfo,
1656 obd_off start, obd_off end,
1657 struct ptlrpc_request_set *rqset)
1659 struct lov_request_set *set = NULL;
1660 struct lov_obd *lov;
1661 struct list_head *pos;
1662 struct lov_request *req;
1666 ASSERT_LSM_MAGIC(oinfo->oi_md);
1667 LASSERT(rqset != NULL);
1672 lov = &exp->exp_obd->u.lov;
1673 rc = lov_prep_sync_set(exp, oinfo, start, end, &set);
1677 list_for_each (pos, &set->set_list) {
1678 req = list_entry(pos, struct lov_request, rq_link);
1680 rc = obd_sync(lov->lov_tgts[req->rq_idx]->ltd_exp, &req->rq_oi,
1681 req->rq_oi.oi_policy.l_extent.start,
1682 req->rq_oi.oi_policy.l_extent.end, rqset);
1684 CERROR("error: fsync objid "LPX64" subobj "LPX64
1685 " on OST idx %d: rc = %d\n",
1686 set->set_oi->oi_oa->o_id,
1687 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1692 /* If we are not waiting for responses on async requests, return. */
1693 if (rc || list_empty(&rqset->set_requests)) {
1694 int err = lov_fini_sync_set(set);
1695 RETURN(rc ? rc : err);
1698 LASSERT(rqset->set_interpret == NULL);
1699 rqset->set_interpret = lov_sync_interpret;
1700 rqset->set_arg = (void *)set;
1705 static int lov_brw_check(struct lov_obd *lov, struct obd_info *lov_oinfo,
1706 obd_count oa_bufs, struct brw_page *pga)
1708 struct obd_info oinfo = { { { 0 } } };
1711 oinfo.oi_oa = lov_oinfo->oi_oa;
1713 /* The caller just wants to know if there's a chance that this
1714 * I/O can succeed */
1715 for (i = 0; i < oa_bufs; i++) {
1716 int stripe = lov_stripe_number(lov_oinfo->oi_md, pga[i].off);
1717 int ost = lov_oinfo->oi_md->lsm_oinfo[stripe]->loi_ost_idx;
1720 if (!lov_stripe_intersects(lov_oinfo->oi_md, i, pga[i].off,
1721 pga[i].off + pga[i].count - 1,
1725 if (!lov->lov_tgts[ost] || !lov->lov_tgts[ost]->ltd_active) {
1726 CDEBUG(D_HA, "lov idx %d inactive\n", ost);
1730 rc = obd_brw(OBD_BRW_CHECK, lov->lov_tgts[ost]->ltd_exp, &oinfo,
1738 static int lov_brw(int cmd, struct obd_export *exp, struct obd_info *oinfo,
1739 obd_count oa_bufs, struct brw_page *pga,
1740 struct obd_trans_info *oti)
1742 struct lov_request_set *set;
1743 struct lov_request *req;
1744 struct list_head *pos;
1745 struct lov_obd *lov = &exp->exp_obd->u.lov;
1749 ASSERT_LSM_MAGIC(oinfo->oi_md);
1751 if (cmd == OBD_BRW_CHECK) {
1752 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1756 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &set);
1760 list_for_each (pos, &set->set_list) {
1761 struct obd_export *sub_exp;
1762 struct brw_page *sub_pga;
1763 req = list_entry(pos, struct lov_request, rq_link);
1765 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1766 sub_pga = set->set_pga + req->rq_pgaidx;
1767 rc = obd_brw(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1771 lov_update_common_set(set, req, rc);
1774 err = lov_fini_brw_set(set);
1780 static int lov_brw_interpret(struct ptlrpc_request_set *reqset, void *data,
1783 struct lov_request_set *lovset = (struct lov_request_set *)data;
1787 lovset->set_completes = 0;
1788 lov_fini_brw_set(lovset);
1790 rc = lov_fini_brw_set(lovset);
1796 static int lov_brw_async(int cmd, struct obd_export *exp,
1797 struct obd_info *oinfo, obd_count oa_bufs,
1798 struct brw_page *pga, struct obd_trans_info *oti,
1799 struct ptlrpc_request_set *set, int pshift)
1801 struct lov_request_set *lovset;
1802 struct lov_request *req;
1803 struct list_head *pos;
1804 struct lov_obd *lov = &exp->exp_obd->u.lov;
1809 ASSERT_LSM_MAGIC(oinfo->oi_md);
1811 if (cmd == OBD_BRW_CHECK) {
1812 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1816 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &lovset);
1820 list_for_each (pos, &lovset->set_list) {
1821 struct obd_export *sub_exp;
1822 struct brw_page *sub_pga;
1823 req = list_entry(pos, struct lov_request, rq_link);
1825 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1826 sub_pga = lovset->set_pga + req->rq_pgaidx;
1827 rc = obd_brw_async(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1828 sub_pga, oti, set, pshift);
1831 lov_update_common_set(lovset, req, rc);
1834 LASSERT(set->set_interpret == NULL);
1835 LASSERT(set->set_arg == NULL);
1836 rc = ptlrpc_set_add_cb(set, lov_brw_interpret, lovset);
1842 lov_fini_brw_set(lovset);
1846 static int lov_ap_make_ready(void *data, int cmd)
1848 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1850 return lap->lap_caller_ops->ap_make_ready(lap->lap_caller_data, cmd);
1853 static int lov_ap_refresh_count(void *data, int cmd)
1855 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1857 return lap->lap_caller_ops->ap_refresh_count(lap->lap_caller_data,
1861 static void lov_ap_fill_obdo(void *data, int cmd, struct obdo *oa)
1863 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1865 lap->lap_caller_ops->ap_fill_obdo(lap->lap_caller_data, cmd, oa);
1866 /* XXX woah, shouldn't we be altering more here? size? */
1867 oa->o_id = lap->lap_loi_id;
1868 oa->o_stripe_idx = lap->lap_stripe;
1871 static void lov_ap_update_obdo(void *data, int cmd, struct obdo *oa,
1874 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1876 lap->lap_caller_ops->ap_update_obdo(lap->lap_caller_data, cmd,oa,valid);
1879 static int lov_ap_completion(void *data, int cmd, struct obdo *oa, int rc)
1881 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1883 /* in a raid1 regime this would down a count of many ios
1884 * in flight, onl calling the caller_ops completion when all
1885 * the raid1 ios are complete */
1886 rc = lap->lap_caller_ops->ap_completion(lap->lap_caller_data,cmd,oa,rc);
1890 static struct obd_async_page_ops lov_async_page_ops = {
1891 .ap_make_ready = lov_ap_make_ready,
1892 .ap_refresh_count = lov_ap_refresh_count,
1893 .ap_fill_obdo = lov_ap_fill_obdo,
1894 .ap_update_obdo = lov_ap_update_obdo,
1895 .ap_completion = lov_ap_completion,
1898 int lov_prep_async_page(struct obd_export *exp, struct lov_stripe_md *lsm,
1899 struct lov_oinfo *loi, cfs_page_t *page,
1900 obd_off offset, struct obd_async_page_ops *ops,
1901 void *data, void **res, int flags,
1902 struct lustre_handle *lockh)
1904 struct lov_obd *lov = &exp->exp_obd->u.lov;
1905 struct lov_async_page *lap;
1906 struct lov_lock_handles *lov_lockh = NULL;
1912 /* Find an existing osc so we can get it's stupid sizeof(*oap).
1913 Only because of this layering limitation will a client
1914 mount with no osts fail */
1915 while (!lov->lov_tgts || !lov->lov_tgts[i] ||
1916 !lov->lov_tgts[i]->ltd_exp) {
1918 if (i >= lov->desc.ld_tgt_count)
1921 rc = size_round(sizeof(*lap)) +
1922 obd_prep_async_page(lov->lov_tgts[i]->ltd_exp, NULL,
1923 NULL, NULL, 0, NULL, NULL, NULL, 0,
1927 ASSERT_LSM_MAGIC(lsm);
1928 LASSERT(loi == NULL);
1931 lap->lap_magic = LOV_AP_MAGIC;
1932 lap->lap_caller_ops = ops;
1933 lap->lap_caller_data = data;
1935 /* for now only raid 0 which passes through */
1936 lap->lap_stripe = lov_stripe_number(lsm, offset);
1937 lov_stripe_offset(lsm, offset, lap->lap_stripe, &lap->lap_sub_offset);
1938 loi = lsm->lsm_oinfo[lap->lap_stripe];
1940 /* so the callback doesn't need the lsm */
1941 lap->lap_loi_id = loi->loi_id;
1943 lap->lap_sub_cookie = (void *)lap + size_round(sizeof(*lap));
1945 if (lockh && lustre_handle_is_used(lockh) && !(flags & OBD_FAST_LOCK)) {
1946 lov_lockh = lov_handle2llh(lockh);
1948 lockh = lov_lockh->llh_handles + lap->lap_stripe;
1952 rc = obd_prep_async_page(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1953 lsm, loi, page, lap->lap_sub_offset,
1954 &lov_async_page_ops, lap,
1955 &lap->lap_sub_cookie, flags, lockh);
1957 lov_llh_put(lov_lockh);
1960 CDEBUG(D_CACHE, "lap %p page %p cookie %p off "LPU64"\n", lap, page,
1961 lap->lap_sub_cookie, offset);
1965 static int lov_queue_async_io(struct obd_export *exp,
1966 struct lov_stripe_md *lsm,
1967 struct lov_oinfo *loi, void *cookie,
1968 int cmd, obd_off off, int count,
1969 obd_flag brw_flags, obd_flag async_flags)
1971 struct lov_obd *lov = &exp->exp_obd->u.lov;
1972 struct lov_async_page *lap;
1975 LASSERT(loi == NULL);
1977 ASSERT_LSM_MAGIC(lsm);
1979 lap = LAP_FROM_COOKIE(cookie);
1981 loi = lsm->lsm_oinfo[lap->lap_stripe];
1983 rc = obd_queue_async_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp, lsm,
1984 loi, lap->lap_sub_cookie, cmd, off, count,
1985 brw_flags, async_flags);
1989 static int lov_set_async_flags(struct obd_export *exp,
1990 struct lov_stripe_md *lsm,
1991 struct lov_oinfo *loi, void *cookie,
1992 obd_flag async_flags)
1994 struct lov_obd *lov = &exp->exp_obd->u.lov;
1995 struct lov_async_page *lap;
1998 LASSERT(loi == NULL);
2000 ASSERT_LSM_MAGIC(lsm);
2002 lap = LAP_FROM_COOKIE(cookie);
2004 loi = lsm->lsm_oinfo[lap->lap_stripe];
2006 rc = obd_set_async_flags(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2007 lsm, loi, lap->lap_sub_cookie, async_flags);
2011 static int lov_queue_group_io(struct obd_export *exp,
2012 struct lov_stripe_md *lsm,
2013 struct lov_oinfo *loi,
2014 struct obd_io_group *oig, void *cookie,
2015 int cmd, obd_off off, int count,
2016 obd_flag brw_flags, obd_flag async_flags)
2018 struct lov_obd *lov = &exp->exp_obd->u.lov;
2019 struct lov_async_page *lap;
2022 LASSERT(loi == NULL);
2024 ASSERT_LSM_MAGIC(lsm);
2026 lap = LAP_FROM_COOKIE(cookie);
2028 loi = lsm->lsm_oinfo[lap->lap_stripe];
2030 rc = obd_queue_group_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp, lsm,
2031 loi, oig, lap->lap_sub_cookie, cmd, off, count,
2032 brw_flags, async_flags);
2036 /* this isn't exactly optimal. we may have queued sync io in oscs on
2037 * all stripes, but we don't record that fact at queue time. so we
2038 * trigger sync io on all stripes. */
2039 static int lov_trigger_group_io(struct obd_export *exp,
2040 struct lov_stripe_md *lsm,
2041 struct lov_oinfo *loi,
2042 struct obd_io_group *oig)
2044 struct lov_obd *lov = &exp->exp_obd->u.lov;
2047 LASSERT(loi == NULL);
2049 ASSERT_LSM_MAGIC(lsm);
2051 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2052 loi = lsm->lsm_oinfo[i];
2053 if (!lov->lov_tgts[loi->loi_ost_idx] ||
2054 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
2055 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2059 err = obd_trigger_group_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2061 if (rc == 0 && err != 0)
2067 static int lov_teardown_async_page(struct obd_export *exp,
2068 struct lov_stripe_md *lsm,
2069 struct lov_oinfo *loi, void *cookie)
2071 struct lov_obd *lov = &exp->exp_obd->u.lov;
2072 struct lov_async_page *lap;
2075 LASSERT(loi == NULL);
2077 ASSERT_LSM_MAGIC(lsm);
2079 lap = LAP_FROM_COOKIE(cookie);
2081 loi = lsm->lsm_oinfo[lap->lap_stripe];
2083 rc = obd_teardown_async_page(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2084 lsm, loi, lap->lap_sub_cookie);
2086 CERROR("unable to teardown sub cookie %p: %d\n",
2087 lap->lap_sub_cookie, rc);
2093 static int lov_enqueue_interpret(struct ptlrpc_request_set *rqset,
2096 struct lov_request_set *lovset = (struct lov_request_set *)data;
2098 rc = lov_fini_enqueue_set(lovset, lovset->set_ei->ei_mode, rc, rqset);
2102 static int lov_enqueue(struct obd_export *exp, struct obd_info *oinfo,
2103 struct ldlm_enqueue_info *einfo,
2104 struct ptlrpc_request_set *rqset)
2106 ldlm_mode_t mode = einfo->ei_mode;
2107 struct lov_request_set *set;
2108 struct lov_request *req;
2109 struct list_head *pos;
2110 struct lov_obd *lov;
2115 ASSERT_LSM_MAGIC(oinfo->oi_md);
2116 LASSERT(mode == (mode & -mode));
2118 /* we should never be asked to replay a lock this way. */
2119 LASSERT((oinfo->oi_flags & LDLM_FL_REPLAY) == 0);
2121 if (!exp || !exp->exp_obd)
2124 lov = &exp->exp_obd->u.lov;
2125 rc = lov_prep_enqueue_set(exp, oinfo, einfo, &set);
2129 list_for_each (pos, &set->set_list) {
2130 req = list_entry(pos, struct lov_request, rq_link);
2132 rc = obd_enqueue(lov->lov_tgts[req->rq_idx]->ltd_exp,
2133 &req->rq_oi, einfo, rqset);
2138 if (rqset && !list_empty(&rqset->set_requests)) {
2140 LASSERT(rqset->set_interpret == NULL);
2141 rqset->set_interpret = lov_enqueue_interpret;
2142 rqset->set_arg = (void *)set;
2146 rc = lov_fini_enqueue_set(set, mode, rc, rqset);
2150 static int lov_match(struct obd_export *exp, struct lov_stripe_md *lsm,
2151 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
2152 int *flags, void *data, struct lustre_handle *lockh,
2155 struct lov_request_set *set;
2156 struct obd_info oinfo;
2157 struct lov_request *req;
2158 struct list_head *pos;
2159 struct lov_obd *lov;
2160 struct lustre_handle *lov_lockhp;
2161 int lov_flags, rc = 0;
2164 ASSERT_LSM_MAGIC(lsm);
2165 LASSERT((*flags & LDLM_FL_TEST_LOCK) || mode == (mode & -mode));
2167 if (!exp || !exp->exp_obd)
2170 lov = &exp->exp_obd->u.lov;
2171 rc = lov_prep_match_set(exp, &oinfo, lsm, policy, mode, lockh, &set);
2175 list_for_each (pos, &set->set_list) {
2176 ldlm_policy_data_t sub_policy;
2177 req = list_entry(pos, struct lov_request, rq_link);
2178 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
2179 LASSERT(lov_lockhp);
2182 sub_policy.l_extent = req->rq_oi.oi_policy.l_extent;
2184 rc = obd_match(lov->lov_tgts[req->rq_idx]->ltd_exp,
2185 req->rq_oi.oi_md, type, &sub_policy,
2186 mode, &lov_flags, data, lov_lockhp,
2188 rc = lov_update_match_set(set, req, rc);
2192 lov_fini_match_set(set, mode, *flags);
2196 static int lov_change_cbdata(struct obd_export *exp,
2197 struct lov_stripe_md *lsm, ldlm_iterator_t it,
2200 struct lov_obd *lov;
2201 struct lov_oinfo *loi;
2205 ASSERT_LSM_MAGIC(lsm);
2207 if (!exp || !exp->exp_obd)
2210 lov = &exp->exp_obd->u.lov;
2211 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2212 struct lov_stripe_md submd;
2214 loi = lsm->lsm_oinfo[i];
2215 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2216 CDEBUG(D_HA, "lov idx %d NULL \n", loi->loi_ost_idx);
2219 submd.lsm_object_id = loi->loi_id;
2220 submd.lsm_object_gr = loi->loi_gr;
2221 submd.lsm_stripe_count = 0;
2222 rc = obd_change_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2228 static int lov_cancel(struct obd_export *exp, struct lov_stripe_md *lsm,
2229 __u32 mode, struct lustre_handle *lockh, int flags,
2232 struct lov_request_set *set;
2233 struct obd_info oinfo;
2234 struct lov_request *req;
2235 struct list_head *pos;
2236 struct lov_obd *lov;
2237 struct lustre_handle *lov_lockhp;
2238 ldlm_mode_t this_mode;
2239 int err = 0, rc = 0;
2242 ASSERT_LSM_MAGIC(lsm);
2244 if (!exp || !exp->exp_obd)
2248 lov = &exp->exp_obd->u.lov;
2249 if (flags & OBD_FAST_LOCK) {
2250 int stripe = lov_stripe_number(lsm, end);
2251 RETURN(obd_cancel(lov->lov_tgts[lsm->lsm_oinfo[stripe]->
2252 loi_ost_idx]->ltd_exp, NULL, mode, lockh,
2256 rc = lov_prep_cancel_set(exp, &oinfo, lsm, mode, lockh, &set);
2260 list_for_each (pos, &set->set_list) {
2261 req = list_entry(pos, struct lov_request, rq_link);
2262 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
2264 /* If this lock was used for a write or truncate, the object
2265 * will have been recreated by the OST, cancel the lock
2266 * (setting LCK_GROUP incidentally causes immediate cancel). */
2267 if (OST_LVB_IS_ERR(lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_blocks) &&
2268 (mode == LCK_PW || mode == LCK_CW))
2269 this_mode = LCK_GROUP;
2273 rc = obd_cancel(lov->lov_tgts[req->rq_idx]->ltd_exp,
2274 req->rq_oi.oi_md, this_mode, lov_lockhp, flags,
2276 rc = lov_update_common_set(set, req, rc);
2278 CERROR("error: cancel objid "LPX64" subobj "
2279 LPX64" on OST idx %d: rc = %d\n",
2281 req->rq_oi.oi_md->lsm_object_id,
2287 lov_fini_cancel_set(set);
2291 static int lov_cancel_unused(struct obd_export *exp,
2292 struct lov_stripe_md *lsm, int flags, void *opaque)
2294 struct lov_obd *lov;
2295 struct lov_oinfo *loi;
2299 if (!exp || !exp->exp_obd)
2302 lov = &exp->exp_obd->u.lov;
2304 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2306 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2309 err = obd_cancel_unused(lov->lov_tgts[i]->ltd_exp, NULL,
2317 ASSERT_LSM_MAGIC(lsm);
2319 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2320 struct lov_stripe_md submd;
2323 loi = lsm->lsm_oinfo[i];
2324 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2325 CDEBUG(D_HA, "lov idx %d NULL\n", loi->loi_ost_idx);
2329 if (!lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
2330 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2332 submd.lsm_object_id = loi->loi_id;
2333 submd.lsm_stripe_count = 0;
2334 err = obd_cancel_unused(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2335 &submd, flags, opaque);
2336 if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
2337 CERROR("error: cancel unused objid "LPX64" subobj "LPX64
2338 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
2339 loi->loi_id, loi->loi_ost_idx, err);
2347 static int lov_join_lru(struct obd_export *exp,
2348 struct lov_stripe_md *lsm, int join)
2350 struct lov_obd *lov;
2351 struct lov_oinfo *loi;
2355 ASSERT_LSM_MAGIC(lsm);
2356 if (!exp || !exp->exp_obd)
2359 lov = &exp->exp_obd->u.lov;
2360 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2361 struct lov_stripe_md submd;
2364 loi = lsm->lsm_oinfo[i];
2365 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2366 CDEBUG(D_HA, "lov idx %d NULL\n", loi->loi_ost_idx);
2370 if (!lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
2371 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2373 submd.lsm_object_id = loi->loi_id;
2374 submd.lsm_stripe_count = 0;
2375 rc = obd_join_lru(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2378 CERROR("join lru failed. objid: "LPX64" subobj: "LPX64
2379 " ostidx: %d rc: %d\n", lsm->lsm_object_id,
2380 loi->loi_id, loi->loi_ost_idx, rc);
2389 int lov_statfs_interpret(struct ptlrpc_request_set *rqset, void *data, int rc)
2391 struct lov_request_set *lovset = (struct lov_request_set *)data;
2396 lovset->set_completes = 0;
2398 err = lov_fini_statfs_set(lovset);
2399 RETURN(rc ? rc : err);
2402 static int lov_statfs_async(struct obd_device *obd, struct obd_info *oinfo,
2403 __u64 max_age, struct ptlrpc_request_set *rqset)
2405 struct lov_request_set *set;
2406 struct lov_request *req;
2407 struct list_head *pos;
2408 struct lov_obd *lov;
2412 LASSERT(oinfo != NULL);
2413 LASSERT(oinfo->oi_osfs != NULL);
2416 rc = lov_prep_statfs_set(obd, oinfo, &set);
2420 list_for_each (pos, &set->set_list) {
2421 struct obd_device *osc_obd;
2423 req = list_entry(pos, struct lov_request, rq_link);
2425 osc_obd = class_exp2obd(lov->lov_tgts[req->rq_idx]->ltd_exp);
2426 rc = obd_statfs_async(osc_obd, &req->rq_oi, max_age, rqset);
2431 if (rc || list_empty(&rqset->set_requests)) {
2434 set->set_completes = 0;
2435 err = lov_fini_statfs_set(set);
2436 RETURN(rc ? rc : err);
2439 LASSERT(rqset->set_interpret == NULL);
2440 rqset->set_interpret = lov_statfs_interpret;
2441 rqset->set_arg = (void *)set;
2445 static int lov_statfs(struct obd_device *obd, struct obd_statfs *osfs,
2446 __u64 max_age, __u32 flags)
2448 struct ptlrpc_request_set *set = NULL;
2449 struct obd_info oinfo = { { { 0 } } };
2453 /* for obdclass we forbid using obd_statfs_rqset, but prefer using async
2454 * statfs requests */
2455 set = ptlrpc_prep_set();
2459 oinfo.oi_osfs = osfs;
2460 oinfo.oi_flags = flags;
2461 rc = lov_statfs_async(obd, &oinfo, max_age, set);
2463 rc = ptlrpc_set_wait(set);
2464 ptlrpc_set_destroy(set);
2469 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
2470 void *karg, void *uarg)
2472 struct obd_device *obddev = class_exp2obd(exp);
2473 struct lov_obd *lov = &obddev->u.lov;
2474 int i, rc, count = lov->desc.ld_tgt_count;
2475 struct obd_uuid *uuidp;
2479 case OBD_IOC_LOV_GET_CONFIG: {
2480 struct obd_ioctl_data *data;
2481 struct lov_desc *desc;
2486 if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
2489 data = (struct obd_ioctl_data *)buf;
2491 if (sizeof(*desc) > data->ioc_inllen1) {
2492 obd_ioctl_freedata(buf, len);
2496 if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
2497 obd_ioctl_freedata(buf, len);
2501 if (sizeof(__u32) * count > data->ioc_inllen3) {
2502 obd_ioctl_freedata(buf, len);
2506 desc = (struct lov_desc *)data->ioc_inlbuf1;
2507 memcpy(desc, &(lov->desc), sizeof(*desc));
2509 uuidp = (struct obd_uuid *)data->ioc_inlbuf2;
2510 genp = (__u32 *)data->ioc_inlbuf3;
2511 /* the uuid will be empty for deleted OSTs */
2512 for (i = 0; i < count; i++, uuidp++, genp++) {
2513 if (!lov->lov_tgts[i])
2515 *uuidp = lov->lov_tgts[i]->ltd_uuid;
2516 *genp = lov->lov_tgts[i]->ltd_gen;
2519 rc = copy_to_user((void *)uarg, buf, len);
2522 obd_ioctl_freedata(buf, len);
2525 case LL_IOC_LOV_SETSTRIPE:
2526 rc = lov_setstripe(exp, karg, uarg);
2528 case LL_IOC_LOV_GETSTRIPE:
2529 rc = lov_getstripe(exp, karg, uarg);
2531 case LL_IOC_LOV_SETEA:
2532 rc = lov_setea(exp, karg, uarg);
2541 for (i = 0; i < count; i++) {
2544 /* OST was disconnected */
2545 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2548 err = obd_iocontrol(cmd, lov->lov_tgts[i]->ltd_exp,
2550 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
2553 if (lov->lov_tgts[i]->ltd_active) {
2554 CDEBUG(err == -ENOTTY ?
2555 D_IOCTL : D_WARNING,
2556 "iocontrol OSC %s on OST "
2557 "idx %d cmd %x: err = %d\n",
2558 lov_uuid2str(lov, i),
2575 #define FIEMAP_BUFFER_SIZE 4096
2577 /* Non-zero fe_logical indicates that this is a continuation FIEMAP
2578 * call. The local end offset and the device are sent in the first
2579 * fm_extent. This function calculates the stripe number from the index.
2580 * This function returns a stripe_no on which mapping is to be restarted.
2582 * This function returns fm_end_offset which is the in-OST offset at which
2583 * mapping should be restarted. If fm_end_offset=0 is returned then caller
2584 * will re-calculate proper offset in next stripe.
2585 * Note that the first extent is passed to lov_get_info via the value field */
2586 obd_size fiemap_calc_fm_end_offset(struct ll_user_fiemap *fiemap,
2587 struct lov_stripe_md *lsm, obd_size fm_start,
2588 obd_size fm_end, int *start_stripe)
2590 obd_size local_end = fiemap->fm_extents[0].fe_logical;
2591 obd_off lun_start, lun_end;
2592 obd_size fm_end_offset;
2593 int stripe_no = -1, i;
2595 if (fiemap->fm_extent_count == 0 ||
2596 fiemap->fm_extents[0].fe_logical == 0)
2599 /* Find out stripe_no from ost_index saved in the fe_device */
2600 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2601 if (lsm->lsm_oinfo[i]->loi_ost_idx ==
2602 fiemap->fm_extents[0].fe_device) {
2608 /* If we have finished mapping on previous device, shift logical
2609 * offset to start of next device */
2610 if ((lov_stripe_intersects(lsm, stripe_no, fm_start, fm_end,
2611 &lun_start, &lun_end)) != 0 &&
2612 local_end < lun_end) {
2613 fm_end_offset = local_end;
2614 *start_stripe = stripe_no;
2616 /* This is a special value to indicate that caller should
2617 * calculate offset in next stripe. */
2619 *start_stripe = (stripe_no + 1) % lsm->lsm_stripe_count;
2622 return fm_end_offset;
2625 /* We calculate on which OST the mapping will end. If the length of mapping
2626 * is greater than (stripe_size * stripe_count) then the last_stripe will
2627 * will be one just before start_stripe. Else we check if the mapping
2628 * intersects each OST and find last_stripe.
2629 * This function returns the last_stripe and also sets the stripe_count
2630 * over which the mapping is spread */
2631 int fiemap_calc_last_stripe(struct lov_stripe_md *lsm, obd_size fm_start,
2632 obd_size fm_end, int start_stripe,
2636 obd_off obd_start, obd_end;
2639 if (fm_end - fm_start > lsm->lsm_stripe_size * lsm->lsm_stripe_count) {
2640 last_stripe = (start_stripe < 1 ? lsm->lsm_stripe_count - 1 :
2642 *stripe_count = lsm->lsm_stripe_count;
2644 for (j = 0, i = start_stripe; j < lsm->lsm_stripe_count;
2645 i = (i + 1) % lsm->lsm_stripe_count, j++) {
2646 if ((lov_stripe_intersects(lsm, i, fm_start, fm_end,
2647 &obd_start, &obd_end)) == 0)
2651 last_stripe = (start_stripe + j - 1) %lsm->lsm_stripe_count;
2657 /* Set fe_device and copy extents from local buffer into main return buffer */
2658 void fiemap_prepare_and_copy_exts(struct ll_user_fiemap *fiemap,
2659 struct ll_fiemap_extent *lcl_fm_ext,
2660 int ost_index, unsigned int ext_count,
2666 for (ext = 0; ext < ext_count; ext++) {
2667 lcl_fm_ext[ext].fe_device = ost_index;
2668 lcl_fm_ext[ext].fe_flags |= FIEMAP_EXTENT_NET;
2671 /* Copy fm_extent's from fm_local to return buffer */
2672 to = (char *)fiemap + fiemap_count_to_size(current_extent);
2673 memcpy(to, lcl_fm_ext, ext_count * sizeof(struct ll_fiemap_extent));
2676 static int lov_fiemap(struct lov_obd *lov, __u32 keylen, void *key,
2677 __u32 *vallen, void *val, struct lov_stripe_md *lsm)
2679 struct ll_fiemap_info_key *fm_key = key;
2680 struct ll_user_fiemap *fiemap = val;
2681 struct ll_user_fiemap *fm_local = NULL;
2682 struct ll_fiemap_extent *lcl_fm_ext;
2684 unsigned int get_num_extents = 0;
2685 int ost_index = 0, actual_start_stripe, start_stripe;
2686 obd_size fm_start, fm_end, fm_length, fm_end_offset = 0;
2688 int current_extent = 0, rc = 0, i;
2689 int ost_eof = 0; /* EOF for object */
2690 int ost_done = 0; /* done with required mapping for this OST? */
2692 int cur_stripe = 0, cur_stripe_wrap = 0, stripe_count;
2693 unsigned int buffer_size = FIEMAP_BUFFER_SIZE;
2698 if (fiemap_count_to_size(fm_key->fiemap.fm_extent_count) < buffer_size)
2699 buffer_size = fiemap_count_to_size(fm_key->fiemap.fm_extent_count);
2701 OBD_ALLOC(fm_local, buffer_size);
2702 if (fm_local == NULL)
2703 GOTO(out, rc = -ENOMEM);
2704 lcl_fm_ext = &fm_local->fm_extents[0];
2706 count_local = fiemap_size_to_count(buffer_size);
2708 memcpy(fiemap, &fm_key->fiemap, sizeof(*fiemap));
2709 fm_start = fiemap->fm_start;
2710 fm_length = fiemap->fm_length;
2711 /* Calculate start stripe, last stripe and length of mapping */
2712 actual_start_stripe = start_stripe = lov_stripe_number(lsm, fm_start);
2713 fm_end = (fm_length == ~0ULL ? fm_key->oa.o_size :
2714 fm_start + fm_length - 1);
2715 /* If fm_length != ~0ULL but fm_start+fm_length-1 exceeds file size */
2716 if (fm_end > fm_key->oa.o_size)
2717 fm_end = fm_key->oa.o_size;
2719 last_stripe = fiemap_calc_last_stripe(lsm, fm_start, fm_end,
2720 actual_start_stripe, &stripe_count);
2722 fm_end_offset = fiemap_calc_fm_end_offset(fiemap, lsm, fm_start, fm_end,
2725 if (fiemap->fm_extent_count == 0) {
2726 get_num_extents = 1;
2730 /* Check each stripe */
2731 for (cur_stripe = start_stripe, i = 0; i < stripe_count;
2732 i++, cur_stripe = (cur_stripe + 1) % lsm->lsm_stripe_count) {
2733 obd_size req_fm_len; /* Stores length of required mapping */
2734 obd_size len_mapped_single_call;
2735 obd_off lun_start, lun_end, obd_object_end;
2736 unsigned int ext_count;
2738 cur_stripe_wrap = cur_stripe;
2740 /* Find out range of mapping on this stripe */
2741 if ((lov_stripe_intersects(lsm, cur_stripe, fm_start, fm_end,
2742 &lun_start, &obd_object_end)) == 0)
2745 /* If this is a continuation FIEMAP call and we are on
2746 * starting stripe then lun_start needs to be set to
2748 if (fm_end_offset != 0 && cur_stripe == start_stripe)
2749 lun_start = fm_end_offset;
2751 if (fm_length != ~0ULL) {
2752 /* Handle fm_start + fm_length overflow */
2753 if (fm_start + fm_length < fm_start)
2754 fm_length = ~0ULL - fm_start;
2755 lun_end = lov_size_to_stripe(lsm, fm_start + fm_length,
2761 if (lun_start == lun_end)
2764 req_fm_len = obd_object_end - lun_start;
2765 fm_local->fm_length = 0;
2766 len_mapped_single_call = 0;
2768 /* If the output buffer is very large and the objects have many
2769 * extents we may need to loop on a single OST repeatedly */
2773 if (get_num_extents == 0) {
2774 /* Don't get too many extents. */
2775 if (current_extent + count_local >
2776 fiemap->fm_extent_count)
2777 count_local = fiemap->fm_extent_count -
2781 lun_start += len_mapped_single_call;
2782 fm_local->fm_length = req_fm_len - len_mapped_single_call;
2783 req_fm_len = fm_local->fm_length;
2784 fm_local->fm_extent_count = count_local;
2785 fm_local->fm_mapped_extents = 0;
2786 fm_local->fm_flags = fiemap->fm_flags;
2788 fm_key->oa.o_id = lsm->lsm_oinfo[cur_stripe]->loi_id;
2789 ost_index = lsm->lsm_oinfo[cur_stripe]->loi_ost_idx;
2791 if (ost_index < 0 || ost_index >=lov->desc.ld_tgt_count)
2792 GOTO(out, rc = -EINVAL);
2794 /* If OST is inactive, return extent with UNKNOWN flag */
2795 if (!lov->lov_tgts[ost_index]->ltd_active) {
2796 fm_local->fm_flags |= FIEMAP_EXTENT_LAST;
2797 fm_local->fm_mapped_extents = 1;
2799 lcl_fm_ext[0].fe_logical = lun_start;
2800 lcl_fm_ext[0].fe_length = obd_object_end -
2802 lcl_fm_ext[0].fe_flags |= FIEMAP_EXTENT_UNKNOWN;
2807 fm_local->fm_start = lun_start;
2808 fm_local->fm_flags &= ~FIEMAP_FLAG_DEVICE_ORDER;
2809 memcpy(&fm_key->fiemap, fm_local, sizeof(*fm_local));
2810 *vallen=fiemap_count_to_size(fm_local->fm_extent_count);
2811 rc = obd_get_info(lov->lov_tgts[ost_index]->ltd_exp,
2812 keylen, key, vallen, fm_local, lsm);
2817 ext_count = fm_local->fm_mapped_extents;
2818 if (ext_count == 0) {
2820 /* If last stripe has hole at the end,
2821 * then we need to return */
2822 if (cur_stripe_wrap == last_stripe) {
2823 fiemap->fm_mapped_extents = 0;
2829 /* If we just need num of extents then go to next device */
2830 if (get_num_extents) {
2831 current_extent += ext_count;
2835 len_mapped_single_call = lcl_fm_ext[ext_count-1].fe_logical -
2836 lun_start + lcl_fm_ext[ext_count - 1].fe_length;
2838 /* Have we finished mapping on this device? */
2839 if (req_fm_len <= len_mapped_single_call)
2842 /* Clear the EXTENT_LAST flag which can be present on
2844 if (lcl_fm_ext[ext_count-1].fe_flags & FIEMAP_EXTENT_LAST)
2845 lcl_fm_ext[ext_count - 1].fe_flags &=
2846 ~FIEMAP_EXTENT_LAST;
2848 curr_loc = lov_stripe_size(lsm,
2849 lcl_fm_ext[ext_count - 1].fe_logical+
2850 lcl_fm_ext[ext_count - 1].fe_length,
2852 if (curr_loc >= fm_key->oa.o_size)
2855 fiemap_prepare_and_copy_exts(fiemap, lcl_fm_ext,
2856 ost_index, ext_count,
2859 current_extent += ext_count;
2861 /* Ran out of available extents? */
2862 if (current_extent >= fiemap->fm_extent_count)
2864 } while (ost_done == 0 && ost_eof == 0);
2866 if (cur_stripe_wrap == last_stripe)
2871 /* Indicate that we are returning device offsets unless file just has
2873 if (lsm->lsm_stripe_count > 1)
2874 fiemap->fm_flags |= FIEMAP_FLAG_DEVICE_ORDER;
2876 if (get_num_extents)
2877 goto skip_last_device_calc;
2879 /* Check if we have reached the last stripe and whether mapping for that
2880 * stripe is done. */
2881 if (cur_stripe_wrap == last_stripe) {
2882 if (ost_done || ost_eof)
2883 fiemap->fm_extents[current_extent - 1].fe_flags |=
2887 skip_last_device_calc:
2888 fiemap->fm_mapped_extents = current_extent;
2891 OBD_FREE(fm_local, buffer_size);
2895 static int lov_get_info(struct obd_export *exp, __u32 keylen,
2896 void *key, __u32 *vallen, void *val,
2897 struct lov_stripe_md *lsm)
2899 struct obd_device *obddev = class_exp2obd(exp);
2900 struct lov_obd *lov = &obddev->u.lov;
2904 if (!vallen || !val)
2909 if (KEY_IS(KEY_LOCK_TO_STRIPE)) {
2912 struct ldlm_lock *lock;
2914 struct ldlm_res_id *res_id = &data->lock->l_resource->lr_name;
2915 struct lov_oinfo *loi;
2916 __u32 *stripe = val;
2918 if (*vallen < sizeof(*stripe))
2919 GOTO(out, rc = -EFAULT);
2920 *vallen = sizeof(*stripe);
2922 /* XXX This is another one of those bits that will need to
2923 * change if we ever actually support nested LOVs. It uses
2924 * the lock's export to find out which stripe it is. */
2925 /* XXX - it's assumed all the locks for deleted OSTs have
2926 * been cancelled. Also, the export for deleted OSTs will
2927 * be NULL and won't match the lock's export. */
2928 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2929 loi = lsm->lsm_oinfo[i];
2930 if (!lov->lov_tgts[loi->loi_ost_idx])
2932 if (lov->lov_tgts[loi->loi_ost_idx]->ltd_exp ==
2933 data->lock->l_conn_export &&
2934 osc_res_name_eq(loi->loi_id, loi->loi_gr, res_id)) {
2939 LDLM_ERROR(data->lock, "lock on inode without such object");
2940 dump_lsm(D_ERROR, lsm);
2941 GOTO(out, rc = -ENXIO);
2942 } else if (KEY_IS(KEY_LAST_ID)) {
2943 struct obd_id_info *info = val;
2944 __u32 size = sizeof(obd_id);
2945 struct lov_tgt_desc *tgt;
2947 LASSERT(*vallen == sizeof(struct obd_id_info));
2948 tgt = lov->lov_tgts[info->idx];
2950 if (!tgt || !tgt->ltd_active)
2951 GOTO(out, rc = -ESRCH);
2953 rc = obd_get_info(tgt->ltd_exp, keylen, key, &size, info->data, NULL);
2955 } else if (KEY_IS(KEY_LOVDESC)) {
2956 struct lov_desc *desc_ret = val;
2957 *desc_ret = lov->desc;
2960 } else if (KEY_IS(KEY_FIEMAP)) {
2961 rc = lov_fiemap(lov, keylen, key, vallen, val, lsm);
2963 } else if (KEY_IS(KEY_OFF_RPCSIZE)) {
2964 __u64 *offset = val;
2965 struct lov_tgt_desc *tgt;
2966 struct lov_oinfo *loi;
2969 LASSERT(*vallen == sizeof(__u64));
2970 stripe = lov_stripe_number(lsm, *offset);
2971 loi = lsm->lsm_oinfo[stripe];
2972 tgt = lov->lov_tgts[loi->loi_ost_idx];
2973 if (!tgt || !tgt->ltd_active)
2974 GOTO(out, rc = -ESRCH);
2975 rc = obd_get_info(tgt->ltd_exp, keylen, key, vallen, val, NULL);
2977 } else if (KEY_IS(KEY_CONNECT_FLAG)) {
2978 struct lov_tgt_desc *tgt;
2979 __u64 ost_idx = *((__u64*)val);
2981 LASSERT(*vallen == sizeof(__u64));
2982 LASSERT(ost_idx < lov->desc.ld_tgt_count);
2983 tgt = lov->lov_tgts[ost_idx];
2985 if (!tgt || !tgt->ltd_exp)
2986 GOTO(out, rc = -ESRCH);
2988 *((__u64*)val) = tgt->ltd_exp->exp_connect_flags;
2998 static int lov_set_info_async(struct obd_export *exp, obd_count keylen,
2999 void *key, obd_count vallen, void *val,
3000 struct ptlrpc_request_set *set)
3002 struct obd_device *obddev = class_exp2obd(exp);
3003 struct lov_obd *lov = &obddev->u.lov;
3005 int i, rc = 0, err, incr = 0, check_uuid = 0, do_inactive = 0;
3007 unsigned next_id = 0;
3008 struct lov_tgt_desc *tgt;
3013 set = ptlrpc_prep_set();
3019 count = lov->desc.ld_tgt_count;
3021 if (KEY_IS(KEY_NEXT_ID)) {
3022 count = vallen / sizeof(struct obd_id_info);
3023 vallen = sizeof(obd_id);
3024 incr = sizeof(struct obd_id_info);
3027 } else if (KEY_IS(KEY_CHECKSUM)) {
3029 } else if (KEY_IS(KEY_MDS_CONN)) {
3030 check_uuid = val ? 1 : 0;
3031 } else if (KEY_IS(KEY_EVICT_BY_NID)) {
3033 do_inactive = incr = 0;
3037 for (i = 0; i < count; i++, val = (char *)val + incr) {
3039 tgt = lov->lov_tgts[((struct obd_id_info*)val)->idx];
3040 data = ((struct obd_id_info*)val)->data;
3042 tgt = lov->lov_tgts[i];
3045 /* OST was disconnected */
3046 if (!tgt || !tgt->ltd_exp)
3049 /* OST is inactive and we don't want inactive OSCs */
3050 if (!tgt->ltd_active && !do_inactive)
3053 /* Only want a specific OSC */
3055 !obd_uuid_equals(val, &tgt->ltd_uuid))
3058 err = obd_set_info_async(tgt->ltd_exp,
3059 keylen, key, vallen, data, set);
3065 err = ptlrpc_set_wait(set);
3068 ptlrpc_set_destroy(set);
3073 static int lov_checkmd(struct obd_export *exp, struct obd_export *md_exp,
3074 struct lov_stripe_md *lsm)
3082 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
3083 rc = lsm_op_find(lsm->lsm_magic)->lsm_revalidate(lsm, md_exp->exp_obd);
3088 int lov_test_and_clear_async_rc(struct lov_stripe_md *lsm)
3090 struct lov_oinfo *loi;
3094 for (i = 0; i < lsm->lsm_stripe_count; i++) {
3095 loi = lsm->lsm_oinfo[i];
3096 if (loi->loi_ar.ar_rc && !rc)
3097 rc = loi->loi_ar.ar_rc;
3098 loi->loi_ar.ar_rc = 0;
3102 EXPORT_SYMBOL(lov_test_and_clear_async_rc);
3105 static int lov_extent_calc(struct obd_export *exp, struct lov_stripe_md *lsm,
3106 int cmd, __u64 *offset)
3109 __u32 ssize = lsm->lsm_stripe_size;
3111 if (cmd & OBD_CALC_STRIPE_RPC_ALIGN)
3112 ssize = ssize > PTLRPC_MAX_BRW_SIZE ?
3113 PTLRPC_MAX_BRW_SIZE : ssize;
3116 do_div(start, ssize);
3117 start = start * ssize;
3119 CDEBUG(D_DLMTRACE, "offset "LPU64", stripe %u, start "LPU64
3120 ", end "LPU64"\n", *offset, ssize, start, start + ssize - 1);
3121 if (cmd & OBD_CALC_STRIPE_END)
3122 *offset = start + ssize - 1;
3123 else if (cmd & OBD_CALC_STRIPE_START)
3132 struct lov_multi_wait {
3133 struct ldlm_lock *lock;
3139 int lov_complete_many(struct obd_export *exp, struct lov_stripe_md *lsm,
3140 struct lustre_handle *lockh)
3142 struct lov_lock_handles *lov_lockh = NULL;
3143 struct lustre_handle *lov_lockhp;
3144 struct lov_obd *lov;
3145 struct lov_oinfo *loi;
3146 struct lov_multi_wait *queues;
3150 ASSERT_LSM_MAGIC(lsm);
3152 if (!exp || !exp->exp_obd)
3155 LASSERT(lockh != NULL);
3156 if (lsm->lsm_stripe_count > 1) {
3157 lov_lockh = lov_handle2llh(lockh);
3158 if (lov_lockh == NULL) {
3159 CERROR("LOV: invalid lov lock handle %p\n", lockh);
3163 lov_lockhp = lov_lockh->llh_handles;
3168 OBD_ALLOC(queues, lsm->lsm_stripe_count * sizeof(*queues));
3170 GOTO(out, rc = -ENOMEM);
3172 lov = &exp->exp_obd->u.lov;
3173 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
3174 i++, loi++, lov_lockhp++) {
3175 struct ldlm_lock *lock;
3176 struct obd_device *obd;
3178 lock = ldlm_handle2lock(lov_lockhp);
3180 CDEBUG(D_HA, "lov idx %d subobj "LPX64" no lock?\n",
3181 loi->loi_ost_idx, loi->loi_id);
3182 queues[i].completed = 1;
3186 queues[i].lock = lock;
3187 init_waitqueue_entry(&(queues[i].wait), current);
3188 add_wait_queue(lock->l_waitq, &(queues[i].wait));
3190 obd = class_exp2obd(lock->l_conn_export);
3192 imp = obd->u.cli.cl_import;
3194 spin_lock(&imp->imp_lock);
3195 queues[i].generation = imp->imp_generation;
3196 spin_unlock(&imp->imp_lock);
3200 lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, ldlm_expired_completion_wait,
3201 interrupted_completion_wait, &lwd);
3202 rc = l_wait_event_added(check_multi_complete(queues, lsm), &lwi);
3204 for (i = 0; i < lsm->lsm_stripe_count; i++)
3205 remove_wait_queue(lock->l_waitq, &(queues[i].wait));
3207 if (rc == -EINTR || rc == -ETIMEDOUT) {
3213 if (lov_lockh != NULL)
3214 lov_llh_put(lov_lockh);
3219 void lov_stripe_lock(struct lov_stripe_md *md)
3221 LASSERT(md->lsm_lock_owner != cfs_current());
3222 spin_lock(&md->lsm_lock);
3223 LASSERT(md->lsm_lock_owner == NULL);
3224 md->lsm_lock_owner = cfs_current();
3226 EXPORT_SYMBOL(lov_stripe_lock);
3228 void lov_stripe_unlock(struct lov_stripe_md *md)
3230 LASSERT(md->lsm_lock_owner == cfs_current());
3231 md->lsm_lock_owner = NULL;
3232 spin_unlock(&md->lsm_lock);
3234 EXPORT_SYMBOL(lov_stripe_unlock);
3236 static int lov_get_lock(struct obd_export *exp, struct lov_stripe_md *lsm,
3237 void **res, int rw, obd_off start, obd_off end,
3238 struct lustre_handle *lockh, int flags)
3240 struct lov_async_page *l = *res;
3241 obd_off stripe_start, stripe_end = start;
3242 struct lov_lock_handles *lov_lockh = NULL;
3247 if (lockh && lustre_handle_is_used(lockh) &&
3248 !(flags & OBD_FAST_LOCK)) {
3249 lov_lockh = lov_handle2llh(lockh);
3250 if (lov_lockh == NULL) {
3251 CERROR("LOV: invalid lov lock handle %p\n", lockh);
3254 lockh = lov_lockh->llh_handles + l->lap_stripe;
3257 /* ensure we don't cross stripe boundaries */
3258 lov_extent_calc(exp, lsm, OBD_CALC_STRIPE_END, &stripe_end);
3259 if (stripe_end < end)
3262 /* map the region limits to the object limits */
3263 lov_stripe_offset(lsm, start, l->lap_stripe, &stripe_start);
3264 lov_stripe_offset(lsm, end, l->lap_stripe, &stripe_end);
3266 rc = obd_get_lock(exp->exp_obd->u.lov.lov_tgts[lsm->
3267 lsm_oinfo[l->lap_stripe]->loi_ost_idx]->
3268 ltd_exp, NULL, &l->lap_sub_cookie,
3269 rw, stripe_start, stripe_end, lockh, flags);
3271 if (lov_lockh != NULL)
3272 lov_llh_put(lov_lockh);
3276 struct obd_ops lov_obd_ops = {
3277 .o_owner = THIS_MODULE,
3278 .o_setup = lov_setup,
3279 .o_precleanup = lov_precleanup,
3280 .o_cleanup = lov_cleanup,
3281 .o_process_config = lov_process_config,
3282 .o_connect = lov_connect,
3283 .o_disconnect = lov_disconnect,
3284 .o_statfs = lov_statfs,
3285 .o_statfs_async = lov_statfs_async,
3286 .o_packmd = lov_packmd,
3287 .o_unpackmd = lov_unpackmd,
3288 .o_checkmd = lov_checkmd,
3289 .o_create = lov_create,
3290 .o_destroy = lov_destroy,
3291 .o_getattr = lov_getattr,
3292 .o_getattr_async = lov_getattr_async,
3293 .o_setattr = lov_setattr,
3294 .o_setattr_async = lov_setattr_async,
3296 .o_brw_async = lov_brw_async,
3297 .o_prep_async_page = lov_prep_async_page,
3298 .o_get_lock = lov_get_lock,
3299 .o_queue_async_io = lov_queue_async_io,
3300 .o_set_async_flags = lov_set_async_flags,
3301 .o_queue_group_io = lov_queue_group_io,
3302 .o_trigger_group_io = lov_trigger_group_io,
3303 .o_teardown_async_page = lov_teardown_async_page,
3304 .o_merge_lvb = lov_merge_lvb,
3305 .o_update_lvb = lov_update_lvb,
3306 .o_adjust_kms = lov_adjust_kms,
3307 .o_punch = lov_punch,
3309 .o_enqueue = lov_enqueue,
3310 .o_match = lov_match,
3311 .o_change_cbdata = lov_change_cbdata,
3312 .o_cancel = lov_cancel,
3313 .o_cancel_unused = lov_cancel_unused,
3314 .o_join_lru = lov_join_lru,
3315 .o_iocontrol = lov_iocontrol,
3316 .o_get_info = lov_get_info,
3317 .o_set_info_async = lov_set_info_async,
3318 .o_extent_calc = lov_extent_calc,
3319 .o_llog_init = lov_llog_init,
3320 .o_llog_finish = lov_llog_finish,
3321 .o_notify = lov_notify,
3322 .o_register_page_removal_cb = lov_obd_register_page_removal_cb,
3323 .o_unregister_page_removal_cb = lov_obd_unregister_page_removal_cb,
3324 .o_register_lock_cancel_cb = lov_obd_register_lock_cancel_cb,
3325 .o_unregister_lock_cancel_cb = lov_obd_unregister_lock_cancel_cb,
3326 .o_pool_new = lov_pool_new,
3327 .o_pool_rem = lov_pool_remove,
3328 .o_pool_add = lov_pool_add,
3329 .o_pool_del = lov_pool_del,
3330 .o_getref = lov_getref,
3331 .o_putref = lov_putref,
3334 static quota_interface_t *quota_interface;
3335 extern quota_interface_t lov_quota_interface;
3337 cfs_mem_cache_t *lov_oinfo_slab;
3339 int __init lov_init(void)
3341 struct lprocfs_static_vars lvars = { 0 };
3345 lov_oinfo_slab = cfs_mem_cache_create("lov_oinfo",
3346 sizeof(struct lov_oinfo),
3347 0, SLAB_HWCACHE_ALIGN);
3348 if (lov_oinfo_slab == NULL)
3350 lprocfs_lov_init_vars(&lvars);
3352 request_module("lquota");
3353 quota_interface = PORTAL_SYMBOL_GET(lov_quota_interface);
3354 init_obd_quota_ops(quota_interface, &lov_obd_ops);
3356 rc = class_register_type(&lov_obd_ops, lvars.module_vars,
3359 if (quota_interface)
3360 PORTAL_SYMBOL_PUT(lov_quota_interface);
3361 rc2 = cfs_mem_cache_destroy(lov_oinfo_slab);
3369 static void /*__exit*/ lov_exit(void)
3373 if (quota_interface)
3374 PORTAL_SYMBOL_PUT(lov_quota_interface);
3376 class_unregister_type(LUSTRE_LOV_NAME);
3377 rc = cfs_mem_cache_destroy(lov_oinfo_slab);
3381 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
3382 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver");
3383 MODULE_LICENSE("GPL");
3385 cfs_module(lov, LUSTRE_VERSION_STRING, lov_init, lov_exit);