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,
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 /* 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,
539 struct lov_obd *lov = &obd->u.lov;
540 struct lov_tgt_desc *tgt;
544 CDEBUG(D_INFO, "Searching in lov %p for uuid %s (activate=%d)\n",
545 lov, uuid->uuid, activate);
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 (lov->lov_tgts[i]->ltd_active == activate) {
564 CDEBUG(D_INFO, "OSC %s already %sactive!\n", uuid->uuid,
565 activate ? "" : "in");
569 CDEBUG(D_CONFIG, "Marking OSC %s %sactive\n", obd_uuid2str(uuid),
570 activate ? "" : "in");
572 lov->lov_tgts[i]->ltd_active = activate;
575 lov->desc.ld_active_tgt_count++;
576 lov->lov_tgts[i]->ltd_exp->exp_obd->obd_inactive = 0;
578 lov->desc.ld_active_tgt_count--;
579 lov->lov_tgts[i]->ltd_exp->exp_obd->obd_inactive = 1;
581 /* remove any old qos penalty */
582 lov->lov_tgts[i]->ltd_qos.ltq_penalty = 0;
590 static int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
591 __u32 index, int gen, int active)
593 struct obd_device *tgt_obd;
594 struct lov_obd *lov = &obd->u.lov;
595 struct lov_tgt_desc *tgt;
599 CDEBUG(D_CONFIG, "uuid:%s idx:%d gen:%d active:%d\n",
600 uuidp->uuid, index, gen, active);
603 CERROR("request to add OBD %s with invalid generation: %d\n",
609 tgt_obd = class_find_client_obd(uuidp, LUSTRE_OSC_NAME,
612 CERROR("Target %s not attached\n", obd_uuid2str(uuidp));
616 mutex_down(&lov->lov_lock);
618 if ((index < lov->lov_tgt_size) && (lov->lov_tgts[index] != NULL)) {
619 tgt = lov->lov_tgts[index];
620 CERROR("UUID %s already assigned at LOV target index %d\n",
621 obd_uuid2str(&tgt->ltd_uuid), index);
622 GOTO(err_unlock, rc = -EEXIST);
625 if (index >= lov->lov_tgt_size) {
626 /* We need to reallocate the lov target array. */
627 struct lov_tgt_desc **newtgts, **old = NULL;
628 __u32 newsize, oldsize = 0;
630 newsize = max(lov->lov_tgt_size, (__u32)2);
631 while (newsize < index + 1)
632 newsize = newsize << 1;
633 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
635 GOTO(err_unlock, rc = -ENOMEM);
637 if (lov->lov_tgt_size) {
638 memcpy(newtgts, lov->lov_tgts, sizeof(*newtgts) *
641 oldsize = lov->lov_tgt_size;
644 lov->lov_tgts = newtgts;
645 lov->lov_tgt_size = newsize;
650 OBD_FREE(old, sizeof(*old) * oldsize);
652 CDEBUG(D_CONFIG, "tgts: %p size: %d\n",
653 lov->lov_tgts, lov->lov_tgt_size);
658 GOTO(err_unlock, rc = -ENOMEM);
660 rc = lov_ost_pool_add(&lov->lov_packed, index, lov->lov_tgt_size);
662 GOTO(err_free_tgt, rc = -EEXIST);
664 memset(tgt, 0, sizeof(*tgt));
665 tgt->ltd_obd = tgt_obd;
666 tgt->ltd_uuid = *uuidp;
667 /* XXX - add a sanity check on the generation number. */
669 tgt->ltd_index = index;
670 tgt->ltd_activate = active;
672 lov->lov_tgts[index] = tgt;
673 if (index >= lov->desc.ld_tgt_count)
674 lov->desc.ld_tgt_count = index + 1;
676 mutex_up(&lov->lov_lock);
678 CDEBUG(D_CONFIG, "idx=%d ltd_gen=%d ld_tgt_count=%d\n",
679 index, tgt->ltd_gen, lov->desc.ld_tgt_count);
681 if (lov->lov_connects == 0) {
682 /* lov_connect hasn't been called yet. We'll do the
683 lov_connect_obd on this target when that fn first runs,
684 because we don't know the connect flags yet. */
688 rc = obd_notify(obd, tgt_obd, OBD_NOTIFY_CREATE, &index);
692 rc = lov_connect_obd(obd, index, active, &lov->lov_ocd);
696 /* connect to administrative disabled ost */
700 rc = lov_notify(obd, tgt->ltd_exp->exp_obd,
701 active ? OBD_NOTIFY_CONNECT : OBD_NOTIFY_INACTIVE,
705 /* connect or notify failed - we can try connect later
706 * instead of complete delete target */
707 CERROR("connect or notify failed (%d) for %s\n", rc,
708 obd_uuid2str(&tgt->ltd_uuid));
716 mutex_up(&lov->lov_lock);
720 /* Schedule a target for deletion */
721 static int lov_del_target(struct obd_device *obd, __u32 index,
722 struct obd_uuid *uuidp, int gen)
724 struct lov_obd *lov = &obd->u.lov;
725 int count = lov->desc.ld_tgt_count;
729 if (index >= count) {
730 CERROR("LOV target index %d >= number of LOV OBDs %d.\n",
737 if (!lov->lov_tgts[index]) {
738 CERROR("LOV target at index %d is not setup.\n", index);
739 GOTO(out, rc = -EINVAL);
742 if (uuidp && !obd_uuid_equals(uuidp, &lov->lov_tgts[index]->ltd_uuid)) {
743 CERROR("LOV target UUID %s at index %d doesn't match %s.\n",
744 lov_uuid2str(lov, index), index,
745 obd_uuid2str(uuidp));
746 GOTO(out, rc = -EINVAL);
749 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d exp: %p active: %d\n",
750 lov_uuid2str(lov, index), index,
751 lov->lov_tgts[index]->ltd_gen, lov->lov_tgts[index]->ltd_exp,
752 lov->lov_tgts[index]->ltd_active);
754 lov->lov_tgts[index]->ltd_reap = 1;
755 lov->lov_death_row++;
756 /* we really delete it from obd_putref */
763 static void __lov_del_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
765 struct obd_device *osc_obd;
768 LASSERT(tgt->ltd_reap);
770 osc_obd = class_exp2obd(tgt->ltd_exp);
772 CDEBUG(D_CONFIG, "Removing tgt %s : %s\n",
774 osc_obd ? osc_obd->obd_name : "<no obd>");
777 lov_disconnect_obd(obd, tgt);
781 /* Manual cleanup - no cleanup logs to clean up the osc's. We must
782 do it ourselves. And we can't do it from lov_cleanup,
783 because we just lost our only reference to it. */
785 /* Use lov's force/fail flags. */
786 osc_obd->obd_force = obd->obd_force;
787 osc_obd->obd_fail = obd->obd_fail;
788 class_manual_cleanup(osc_obd);
792 void lov_fix_desc_stripe_size(__u64 *val)
794 if (*val < PTLRPC_MAX_BRW_SIZE) {
796 LCONSOLE_WARN("Increasing default stripe size from "
797 LPU64" to %u\n",*val,PTLRPC_MAX_BRW_SIZE);
798 *val = PTLRPC_MAX_BRW_SIZE;
799 } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) {
800 *val &= ~(LOV_MIN_STRIPE_SIZE - 1);
801 LCONSOLE_WARN("Changing default stripe size to "LPU64" (a "
803 *val, LOV_MIN_STRIPE_SIZE);
807 void lov_fix_desc_stripe_count(__u32 *val)
813 void lov_fix_desc_pattern(__u32 *val)
815 /* from lov_setstripe */
816 if ((*val != 0) && (*val != LOV_PATTERN_RAID0)) {
817 LCONSOLE_WARN("Unknown stripe pattern: %#x\n", *val);
822 void lov_fix_desc_qos_maxage(__u32 *val)
826 *val = QOS_DEFAULT_MAXAGE;
829 void lov_fix_desc(struct lov_desc *desc)
831 lov_fix_desc_stripe_size(&desc->ld_default_stripe_size);
832 lov_fix_desc_stripe_count(&desc->ld_default_stripe_count);
833 lov_fix_desc_pattern(&desc->ld_pattern);
834 lov_fix_desc_qos_maxage(&desc->ld_qos_maxage);
837 static int lov_setup(struct obd_device *obd, obd_count len, void *buf)
839 struct lprocfs_static_vars lvars = { 0 };
840 struct lustre_cfg *lcfg = buf;
841 struct lov_desc *desc;
842 struct lov_obd *lov = &obd->u.lov;
846 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
847 CERROR("LOV setup requires a descriptor\n");
851 desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
853 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
854 CERROR("descriptor size wrong: %d > %d\n",
855 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
859 if (desc->ld_magic != LOV_DESC_MAGIC) {
860 if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
861 CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n",
862 obd->obd_name, desc);
863 lustre_swab_lov_desc(desc);
865 CERROR("%s: Bad lov desc magic: %#x\n",
866 obd->obd_name, desc->ld_magic);
873 desc->ld_active_tgt_count = 0;
875 lov->lov_tgt_size = 0;
877 sema_init(&lov->lov_lock, 1);
878 atomic_set(&lov->lov_refcount, 0);
879 CFS_INIT_LIST_HEAD(&lov->lov_qos.lq_oss_list);
880 init_rwsem(&lov->lov_qos.lq_rw_sem);
881 lov->lov_qos.lq_dirty = 1;
882 lov->lov_qos.lq_rr.lqr_dirty = 1;
883 lov->lov_qos.lq_reset = 1;
884 /* Default priority is toward free space balance */
885 lov->lov_qos.lq_prio_free = 232;
886 /* Default threshold for rr (roughly 17%) */
887 lov->lov_qos.lq_threshold_rr = 43;
888 /* Init statfs fields */
889 OBD_ALLOC_PTR(lov->lov_qos.lq_statfs_data);
890 if (NULL == lov->lov_qos.lq_statfs_data)
892 cfs_waitq_init(&lov->lov_qos.lq_statfs_waitq);
894 lov->lov_pools_hash_body = lustre_hash_init("POOLS",
897 &pool_hash_operations,
899 CFS_INIT_LIST_HEAD(&lov->lov_pool_list);
900 lov->lov_pool_count = 0;
901 rc = lov_ost_pool_init(&lov->lov_packed, 0);
904 rc = lov_ost_pool_init(&lov->lov_qos.lq_rr.lqr_pool, 0);
906 lov_ost_pool_free(&lov->lov_packed);
910 lprocfs_lov_init_vars(&lvars);
911 lprocfs_obd_setup(obd, lvars.obd_vars);
914 cfs_proc_dir_entry_t *entry;
916 entry = create_proc_entry("target_obd", 0444,
917 obd->obd_proc_entry);
919 entry->proc_fops = &lov_proc_target_fops;
924 lov->lov_pool_proc_entry = lprocfs_register("pools",
931 static int lov_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
937 case OBD_CLEANUP_EARLY: {
938 struct lov_obd *lov = &obd->u.lov;
940 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
941 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
943 obd_precleanup(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
948 case OBD_CLEANUP_EXPORTS:
950 case OBD_CLEANUP_SELF_EXP:
951 rc = obd_llog_finish(obd, 0);
953 CERROR("failed to cleanup llogging subsystems\n");
955 case OBD_CLEANUP_OBD:
961 static int lov_cleanup(struct obd_device *obd)
963 struct lov_obd *lov = &obd->u.lov;
964 struct list_head *pos, *tmp;
965 struct pool_desc *pool;
967 list_for_each_safe(pos, tmp, &lov->lov_pool_list) {
968 pool = list_entry(pos, struct pool_desc, pool_list);
969 /* free the pool structs */
970 CDEBUG(D_INFO, "delete pool %p\n", pool);
971 lov_pool_del(obd, pool->pool_name);
974 lustre_hash_exit(lov->lov_pools_hash_body);
976 lov_ost_pool_free(&(lov->lov_qos.lq_rr.lqr_pool));
977 lov_ost_pool_free(&lov->lov_packed);
982 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
983 if (lov->lov_tgts[i]) {
984 /* Inactive targets may never have connected */
985 if (lov->lov_tgts[i]->ltd_active ||
986 atomic_read(&lov->lov_refcount))
987 /* We should never get here - these
988 should have been removed in the
990 CERROR("lov tgt %d not cleaned!"
991 " deathrow=%d, lovrc=%d\n",
992 i, lov->lov_death_row,
993 atomic_read(&lov->lov_refcount));
994 lov_del_target(obd, i, 0, 0);
998 OBD_FREE(lov->lov_tgts, sizeof(*lov->lov_tgts) *
1000 lov->lov_tgt_size = 0;
1003 /* clear pools parent proc entry only after all pools is killed */
1004 lprocfs_obd_cleanup(obd);
1006 OBD_FREE_PTR(lov->lov_qos.lq_statfs_data);
1010 static int lov_process_config(struct obd_device *obd, obd_count len, void *buf)
1012 struct lustre_cfg *lcfg = buf;
1013 struct obd_uuid obd_uuid;
1018 switch(cmd = lcfg->lcfg_command) {
1019 case LCFG_LOV_ADD_OBD:
1020 case LCFG_LOV_ADD_INA:
1021 case LCFG_LOV_DEL_OBD: {
1024 /* lov_modify_tgts add 0:lov_mdsA 1:ost1_UUID 2:0 3:1 */
1025 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
1026 GOTO(out, rc = -EINVAL);
1028 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1030 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
1031 GOTO(out, rc = -EINVAL);
1032 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
1033 GOTO(out, rc = -EINVAL);
1034 if (cmd == LCFG_LOV_ADD_OBD)
1035 rc = lov_add_target(obd, &obd_uuid, index, gen, 1);
1036 else if (cmd == LCFG_LOV_ADD_INA)
1037 rc = lov_add_target(obd, &obd_uuid, index, gen, 0);
1039 rc = lov_del_target(obd, index, &obd_uuid, gen);
1043 struct lprocfs_static_vars lvars = { 0 };
1044 struct lov_desc *desc = &(obd->u.lov.desc);
1047 GOTO(out, rc = -EINVAL);
1049 lprocfs_lov_init_vars(&lvars);
1051 rc = class_process_proc_param(PARAM_LOV, lvars.obd_vars,
1062 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1063 GOTO(out, rc = -EINVAL);
1072 #define log2(n) ffz(~(n))
1075 static int lov_clear_orphans(struct obd_export *export, struct obdo *src_oa,
1076 struct lov_stripe_md **ea,
1077 struct obd_trans_info *oti)
1079 struct lov_obd *lov;
1080 struct obdo *tmp_oa;
1081 struct obd_uuid *ost_uuid = NULL;
1085 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
1086 src_oa->o_flags == OBD_FL_DELORPHAN);
1088 lov = &export->exp_obd->u.lov;
1094 if (oti->oti_ost_uuid) {
1095 ost_uuid = oti->oti_ost_uuid;
1096 CDEBUG(D_HA, "clearing orphans only for %s\n",
1100 obd_getref(export->exp_obd);
1101 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1102 struct lov_stripe_md obj_md;
1103 struct lov_stripe_md *obj_mdp = &obj_md;
1104 struct lov_tgt_desc *tgt;
1107 tgt = lov->lov_tgts[i];
1111 /* if called for a specific target, we don't
1112 care if it is not active. */
1113 if (!lov->lov_tgts[i]->ltd_active && ost_uuid == NULL) {
1114 CDEBUG(D_HA, "lov idx %d inactive\n", i);
1118 if (ost_uuid && !obd_uuid_equals(ost_uuid, &tgt->ltd_uuid))
1121 CDEBUG(D_CONFIG,"Clear orphans for %d:%s\n", i,
1122 obd_uuid2str(ost_uuid));
1124 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
1126 LASSERT(lov->lov_tgts[i]->ltd_exp);
1127 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1128 err = obd_create(lov->lov_tgts[i]->ltd_exp,
1129 tmp_oa, &obj_mdp, oti);
1131 /* This export will be disabled until it is recovered,
1132 and then orphan recovery will be completed. */
1133 CERROR("error in orphan recovery on OST idx %d/%d: "
1134 "rc = %d\n", i, lov->desc.ld_tgt_count, err);
1141 obd_putref(export->exp_obd);
1147 static int lov_recreate(struct obd_export *exp, struct obdo *src_oa,
1148 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1150 struct lov_stripe_md *obj_mdp, *lsm;
1151 struct lov_obd *lov = &exp->exp_obd->u.lov;
1156 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
1157 src_oa->o_flags & OBD_FL_RECREATE_OBJS);
1159 OBD_ALLOC(obj_mdp, sizeof(*obj_mdp));
1160 if (obj_mdp == NULL)
1163 ost_idx = src_oa->o_nlink;
1166 GOTO(out, rc = -EINVAL);
1167 if (ost_idx >= lov->desc.ld_tgt_count ||
1168 !lov->lov_tgts[ost_idx])
1169 GOTO(out, rc = -EINVAL);
1171 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1172 if (lsm->lsm_oinfo[i]->loi_ost_idx == ost_idx) {
1173 if (lsm->lsm_oinfo[i]->loi_id != src_oa->o_id)
1174 GOTO(out, rc = -EINVAL);
1178 if (i == lsm->lsm_stripe_count)
1179 GOTO(out, rc = -EINVAL);
1181 rc = obd_create(lov->lov_tgts[ost_idx]->ltd_exp, src_oa, &obj_mdp, oti);
1183 OBD_FREE(obj_mdp, sizeof(*obj_mdp));
1187 /* the LOV expects oa->o_id to be set to the LOV object id */
1188 static int lov_create(struct obd_export *exp, struct obdo *src_oa,
1189 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1191 struct lov_obd *lov;
1192 struct obd_info *oinfo;
1193 struct lov_request_set *set = NULL;
1194 struct lov_request *req;
1195 struct l_wait_info lwi = { 0 };
1199 LASSERT(ea != NULL);
1203 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1204 src_oa->o_flags == OBD_FL_DELORPHAN) {
1205 rc = lov_clear_orphans(exp, src_oa, ea, oti);
1209 lov = &exp->exp_obd->u.lov;
1210 if (!lov->desc.ld_active_tgt_count)
1213 OBD_ALLOC_PTR(oinfo);
1217 obd_getref(exp->exp_obd);
1218 /* Recreate a specific object id at the given OST index */
1219 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1220 (src_oa->o_flags & OBD_FL_RECREATE_OBJS)) {
1221 rc = lov_recreate(exp, src_oa, ea, oti);
1225 /* issue statfs rpcs if the osfs data is older than qos_maxage - 1s,
1226 * later in alloc_qos(), we will wait for those rpcs to complete if
1227 * the osfs age is older than 2 * qos_maxage */
1228 qos_statfs_update(exp->exp_obd,
1229 cfs_time_shift_64(-lov->desc.ld_qos_maxage +
1230 OBD_STATFS_CACHE_SECONDS),
1233 rc = lov_prep_create_set(exp, oinfo, ea, src_oa, oti, &set);
1237 list_for_each_entry(req, &set->set_list, rq_link) {
1238 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1239 rc = obd_create_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1240 &req->rq_oi, &req->rq_oi.oi_md, oti);
1243 /* osc_create have timeout equ obd_timeout/2 so waiting don't be
1244 * longer then this */
1245 l_wait_event(set->set_waitq, lov_finished_set(set), &lwi);
1247 /* we not have ptlrpc set for assign set->interpret and should
1248 * be call interpret function himself. calling from cb_create_update
1249 * not permited because lov_fini_create_set can sleep for long time,
1250 * but we must avoid sleeping in ptlrpcd interpret function. */
1251 rc = lov_fini_create_set(set, ea);
1253 obd_putref(exp->exp_obd);
1254 OBD_FREE_PTR(oinfo);
1258 #define ASSERT_LSM_MAGIC(lsmp) \
1260 LASSERT((lsmp) != NULL); \
1261 LASSERTF(((lsmp)->lsm_magic == LOV_MAGIC_V1 || \
1262 (lsmp)->lsm_magic == LOV_MAGIC_V3 || \
1263 (lsmp)->lsm_magic == LOV_MAGIC_JOIN), "%p->lsm_magic=%x\n", \
1264 (lsmp), (lsmp)->lsm_magic); \
1267 static int lov_destroy(struct obd_export *exp, struct obdo *oa,
1268 struct lov_stripe_md *lsm, struct obd_trans_info *oti,
1269 struct obd_export *md_exp)
1271 struct lov_request_set *set;
1272 struct obd_info *oinfo;
1273 struct lov_request *req;
1274 struct list_head *pos;
1275 struct lov_obd *lov;
1276 int rc = 0, err = 0;
1279 ASSERT_LSM_MAGIC(lsm);
1281 if (!exp || !exp->exp_obd)
1284 if (oa->o_valid & OBD_MD_FLCOOKIE) {
1286 LASSERT(oti->oti_logcookies);
1289 OBD_ALLOC_PTR(oinfo);
1293 lov = &exp->exp_obd->u.lov;
1294 obd_getref(exp->exp_obd);
1295 rc = lov_prep_destroy_set(exp, oinfo, oa, lsm, oti, &set);
1299 list_for_each (pos, &set->set_list) {
1300 req = list_entry(pos, struct lov_request, rq_link);
1302 if (oa->o_valid & OBD_MD_FLCOOKIE)
1303 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1305 err = obd_destroy(lov->lov_tgts[req->rq_idx]->ltd_exp,
1306 req->rq_oi.oi_oa, NULL, oti, NULL);
1307 err = lov_update_common_set(set, req, err);
1309 CERROR("error: destroying objid "LPX64" subobj "
1310 LPX64" on OST idx %d: rc = %d\n",
1311 oa->o_id, req->rq_oi.oi_oa->o_id,
1319 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
1320 rc = lsm_op_find(lsm->lsm_magic)->lsm_destroy(lsm, oa, md_exp);
1322 err = lov_fini_destroy_set(set);
1324 obd_putref(exp->exp_obd);
1325 OBD_FREE_PTR(oinfo);
1326 RETURN(rc ? rc : err);
1329 static int lov_getattr(struct obd_export *exp, struct obd_info *oinfo)
1331 struct lov_request_set *set;
1332 struct lov_request *req;
1333 struct list_head *pos;
1334 struct lov_obd *lov;
1335 int err = 0, rc = 0;
1339 ASSERT_LSM_MAGIC(oinfo->oi_md);
1341 if (!exp || !exp->exp_obd)
1344 lov = &exp->exp_obd->u.lov;
1346 rc = lov_prep_getattr_set(exp, oinfo, &set);
1350 list_for_each (pos, &set->set_list) {
1351 req = list_entry(pos, struct lov_request, rq_link);
1353 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1354 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1355 req->rq_oi.oi_oa->o_id, req->rq_idx);
1357 rc = obd_getattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1359 err = lov_update_common_set(set, req, rc);
1361 CERROR("error: getattr objid "LPX64" subobj "
1362 LPX64" on OST idx %d: rc = %d\n",
1363 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1369 rc = lov_fini_getattr_set(set);
1375 static int lov_getattr_interpret(struct ptlrpc_request_set *rqset,
1378 struct lov_request_set *lovset = (struct lov_request_set *)data;
1382 /* don't do attribute merge if this aysnc op failed */
1384 lovset->set_completes = 0;
1385 err = lov_fini_getattr_set(lovset);
1386 RETURN(rc ? rc : err);
1389 static int lov_getattr_async(struct obd_export *exp, struct obd_info *oinfo,
1390 struct ptlrpc_request_set *rqset)
1392 struct lov_request_set *lovset;
1393 struct lov_obd *lov;
1394 struct list_head *pos;
1395 struct lov_request *req;
1400 ASSERT_LSM_MAGIC(oinfo->oi_md);
1402 if (!exp || !exp->exp_obd)
1405 lov = &exp->exp_obd->u.lov;
1407 rc = lov_prep_getattr_set(exp, oinfo, &lovset);
1411 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1412 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1413 oinfo->oi_md->lsm_stripe_size);
1415 list_for_each (pos, &lovset->set_list) {
1416 req = list_entry(pos, struct lov_request, rq_link);
1418 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1419 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1420 req->rq_oi.oi_oa->o_id, req->rq_idx);
1421 rc = obd_getattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1422 &req->rq_oi, rqset);
1424 CERROR("error: getattr objid "LPX64" subobj "
1425 LPX64" on OST idx %d: rc = %d\n",
1426 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1432 if (!list_empty(&rqset->set_requests)) {
1434 LASSERT (rqset->set_interpret == NULL);
1435 rqset->set_interpret = lov_getattr_interpret;
1436 rqset->set_arg = (void *)lovset;
1441 lovset->set_completes = 0;
1442 err = lov_fini_getattr_set(lovset);
1443 RETURN(rc ? rc : err);
1446 static int lov_setattr(struct obd_export *exp, struct obd_info *oinfo,
1447 struct obd_trans_info *oti)
1449 struct lov_request_set *set;
1450 struct lov_obd *lov;
1451 struct list_head *pos;
1452 struct lov_request *req;
1453 int err = 0, rc = 0;
1457 ASSERT_LSM_MAGIC(oinfo->oi_md);
1459 if (!exp || !exp->exp_obd)
1462 /* for now, we only expect the following updates here */
1463 LASSERT(!(oinfo->oi_oa->o_valid & ~(OBD_MD_FLID | OBD_MD_FLTYPE |
1464 OBD_MD_FLMODE | OBD_MD_FLATIME |
1465 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1466 OBD_MD_FLFLAGS | OBD_MD_FLSIZE |
1467 OBD_MD_FLGROUP | OBD_MD_FLUID |
1468 OBD_MD_FLGID | OBD_MD_FLFID |
1470 lov = &exp->exp_obd->u.lov;
1471 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1475 list_for_each (pos, &set->set_list) {
1476 req = list_entry(pos, struct lov_request, rq_link);
1478 rc = obd_setattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1480 err = lov_update_setattr_set(set, req, rc);
1482 CERROR("error: setattr objid "LPX64" subobj "
1483 LPX64" on OST idx %d: rc = %d\n",
1484 set->set_oi->oi_oa->o_id,
1485 req->rq_oi.oi_oa->o_id, req->rq_idx, err);
1490 err = lov_fini_setattr_set(set);
1496 static int lov_setattr_interpret(struct ptlrpc_request_set *rqset,
1499 struct lov_request_set *lovset = (struct lov_request_set *)data;
1504 lovset->set_completes = 0;
1505 err = lov_fini_setattr_set(lovset);
1506 RETURN(rc ? rc : err);
1509 /* If @oti is given, the request goes from MDS and responses from OSTs are not
1510 needed. Otherwise, a client is waiting for responses. */
1511 static int lov_setattr_async(struct obd_export *exp, struct obd_info *oinfo,
1512 struct obd_trans_info *oti,
1513 struct ptlrpc_request_set *rqset)
1515 struct lov_request_set *set;
1516 struct lov_request *req;
1517 struct list_head *pos;
1518 struct lov_obd *lov;
1523 ASSERT_LSM_MAGIC(oinfo->oi_md);
1524 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE) {
1526 LASSERT(oti->oti_logcookies);
1529 if (!exp || !exp->exp_obd)
1532 lov = &exp->exp_obd->u.lov;
1533 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1537 CDEBUG(D_INFO, "objid "LPX64"@"LPX64": %ux%u byte stripes\n",
1538 oinfo->oi_md->lsm_object_id,
1539 oinfo->oi_md->lsm_object_gr,
1540 oinfo->oi_md->lsm_stripe_count,
1541 oinfo->oi_md->lsm_stripe_size);
1543 list_for_each (pos, &set->set_list) {
1544 req = list_entry(pos, struct lov_request, rq_link);
1546 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
1547 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1549 CDEBUG(D_INFO, "objid "LPX64"@"LPX64"[%d] has subobj "LPX64
1550 " at idx %u\n", oinfo->oi_oa->o_id, oinfo->oi_oa->o_gr,
1551 req->rq_stripe, req->rq_oi.oi_oa->o_id, req->rq_idx);
1553 rc = obd_setattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1554 &req->rq_oi, oti, rqset);
1556 CERROR("error: setattr objid "LPX64" subobj "
1557 LPX64" on OST idx %d: rc = %d\n",
1558 set->set_oi->oi_oa->o_id,
1559 req->rq_oi.oi_oa->o_id,
1565 /* If we are not waiting for responses on async requests, return. */
1566 if (rc || !rqset || list_empty(&rqset->set_requests)) {
1569 set->set_completes = 0;
1570 err = lov_fini_setattr_set(set);
1571 RETURN(rc ? rc : err);
1574 LASSERT(rqset->set_interpret == NULL);
1575 rqset->set_interpret = lov_setattr_interpret;
1576 rqset->set_arg = (void *)set;
1581 static int lov_punch_interpret(struct ptlrpc_request_set *rqset,
1584 struct lov_request_set *lovset = (struct lov_request_set *)data;
1589 lovset->set_completes = 0;
1590 err = lov_fini_punch_set(lovset);
1591 RETURN(rc ? rc : err);
1594 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
1595 * we can send this 'punch' to just the authoritative node and the nodes
1596 * that the punch will affect. */
1597 static int lov_punch(struct obd_export *exp, struct obd_info *oinfo,
1598 struct obd_trans_info *oti,
1599 struct ptlrpc_request_set *rqset)
1601 struct lov_request_set *set;
1602 struct lov_obd *lov;
1603 struct list_head *pos;
1604 struct lov_request *req;
1609 ASSERT_LSM_MAGIC(oinfo->oi_md);
1611 if (!exp || !exp->exp_obd)
1614 lov = &exp->exp_obd->u.lov;
1615 rc = lov_prep_punch_set(exp, oinfo, oti, &set);
1619 list_for_each (pos, &set->set_list) {
1620 req = list_entry(pos, struct lov_request, rq_link);
1622 rc = obd_punch(lov->lov_tgts[req->rq_idx]->ltd_exp,
1623 &req->rq_oi, NULL, rqset);
1625 CERROR("error: punch objid "LPX64" subobj "LPX64
1626 " on OST idx %d: rc = %d\n",
1627 set->set_oi->oi_oa->o_id,
1628 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1633 if (rc || list_empty(&rqset->set_requests)) {
1635 err = lov_fini_punch_set(set);
1636 RETURN(rc ? rc : err);
1639 LASSERT(rqset->set_interpret == NULL);
1640 rqset->set_interpret = lov_punch_interpret;
1641 rqset->set_arg = (void *)set;
1646 static int lov_sync_interpret(struct ptlrpc_request_set *rqset,
1649 struct lov_request_set *lovset = (struct lov_request_set *)data;
1654 lovset->set_completes = 0;
1655 err = lov_fini_sync_set(lovset);
1656 RETURN(rc ? rc : err);
1659 static int lov_sync(struct obd_export *exp, struct obd_info *oinfo,
1660 obd_off start, obd_off end,
1661 struct ptlrpc_request_set *rqset)
1663 struct lov_request_set *set = NULL;
1664 struct lov_obd *lov;
1665 struct list_head *pos;
1666 struct lov_request *req;
1670 ASSERT_LSM_MAGIC(oinfo->oi_md);
1671 LASSERT(rqset != NULL);
1676 lov = &exp->exp_obd->u.lov;
1677 rc = lov_prep_sync_set(exp, oinfo, start, end, &set);
1681 list_for_each (pos, &set->set_list) {
1682 req = list_entry(pos, struct lov_request, rq_link);
1684 rc = obd_sync(lov->lov_tgts[req->rq_idx]->ltd_exp, &req->rq_oi,
1685 req->rq_oi.oi_policy.l_extent.start,
1686 req->rq_oi.oi_policy.l_extent.end, rqset);
1688 CERROR("error: fsync objid "LPX64" subobj "LPX64
1689 " on OST idx %d: rc = %d\n",
1690 set->set_oi->oi_oa->o_id,
1691 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1696 /* If we are not waiting for responses on async requests, return. */
1697 if (rc || list_empty(&rqset->set_requests)) {
1698 int err = lov_fini_sync_set(set);
1699 RETURN(rc ? rc : err);
1702 LASSERT(rqset->set_interpret == NULL);
1703 rqset->set_interpret = lov_sync_interpret;
1704 rqset->set_arg = (void *)set;
1709 static int lov_brw_check(struct lov_obd *lov, struct obd_info *lov_oinfo,
1710 obd_count oa_bufs, struct brw_page *pga)
1712 struct obd_info oinfo = { { { 0 } } };
1715 oinfo.oi_oa = lov_oinfo->oi_oa;
1717 /* The caller just wants to know if there's a chance that this
1718 * I/O can succeed */
1719 for (i = 0; i < oa_bufs; i++) {
1720 int stripe = lov_stripe_number(lov_oinfo->oi_md, pga[i].off);
1721 int ost = lov_oinfo->oi_md->lsm_oinfo[stripe]->loi_ost_idx;
1724 if (!lov_stripe_intersects(lov_oinfo->oi_md, i, pga[i].off,
1725 pga[i].off + pga[i].count - 1,
1729 if (!lov->lov_tgts[ost] || !lov->lov_tgts[ost]->ltd_active) {
1730 CDEBUG(D_HA, "lov idx %d inactive\n", ost);
1734 rc = obd_brw(OBD_BRW_CHECK, lov->lov_tgts[ost]->ltd_exp, &oinfo,
1742 static int lov_brw(int cmd, struct obd_export *exp, struct obd_info *oinfo,
1743 obd_count oa_bufs, struct brw_page *pga,
1744 struct obd_trans_info *oti)
1746 struct lov_request_set *set;
1747 struct lov_request *req;
1748 struct list_head *pos;
1749 struct lov_obd *lov = &exp->exp_obd->u.lov;
1753 ASSERT_LSM_MAGIC(oinfo->oi_md);
1755 if (cmd == OBD_BRW_CHECK) {
1756 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1760 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &set);
1764 list_for_each (pos, &set->set_list) {
1765 struct obd_export *sub_exp;
1766 struct brw_page *sub_pga;
1767 req = list_entry(pos, struct lov_request, rq_link);
1769 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1770 sub_pga = set->set_pga + req->rq_pgaidx;
1771 rc = obd_brw(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1775 lov_update_common_set(set, req, rc);
1778 err = lov_fini_brw_set(set);
1784 static int lov_brw_interpret(struct ptlrpc_request_set *reqset, void *data,
1787 struct lov_request_set *lovset = (struct lov_request_set *)data;
1791 lovset->set_completes = 0;
1792 lov_fini_brw_set(lovset);
1794 rc = lov_fini_brw_set(lovset);
1800 static int lov_brw_async(int cmd, struct obd_export *exp,
1801 struct obd_info *oinfo, obd_count oa_bufs,
1802 struct brw_page *pga, struct obd_trans_info *oti,
1803 struct ptlrpc_request_set *set, int pshift)
1805 struct lov_request_set *lovset;
1806 struct lov_request *req;
1807 struct list_head *pos;
1808 struct lov_obd *lov = &exp->exp_obd->u.lov;
1813 ASSERT_LSM_MAGIC(oinfo->oi_md);
1815 if (cmd == OBD_BRW_CHECK) {
1816 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1820 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &lovset);
1824 list_for_each (pos, &lovset->set_list) {
1825 struct obd_export *sub_exp;
1826 struct brw_page *sub_pga;
1827 req = list_entry(pos, struct lov_request, rq_link);
1829 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1830 sub_pga = lovset->set_pga + req->rq_pgaidx;
1831 rc = obd_brw_async(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1832 sub_pga, oti, set, pshift);
1835 lov_update_common_set(lovset, req, rc);
1838 LASSERT(set->set_interpret == NULL);
1839 LASSERT(set->set_arg == NULL);
1840 rc = ptlrpc_set_add_cb(set, lov_brw_interpret, lovset);
1846 lov_fini_brw_set(lovset);
1850 static int lov_ap_make_ready(void *data, int cmd)
1852 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1854 return lap->lap_caller_ops->ap_make_ready(lap->lap_caller_data, cmd);
1857 static int lov_ap_refresh_count(void *data, int cmd)
1859 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1861 return lap->lap_caller_ops->ap_refresh_count(lap->lap_caller_data,
1865 static void lov_ap_fill_obdo(void *data, int cmd, struct obdo *oa)
1867 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1869 lap->lap_caller_ops->ap_fill_obdo(lap->lap_caller_data, cmd, oa);
1870 /* XXX woah, shouldn't we be altering more here? size? */
1871 oa->o_id = lap->lap_loi_id;
1872 oa->o_gr = lap->lap_loi_gr;
1873 oa->o_stripe_idx = lap->lap_stripe;
1876 static void lov_ap_update_obdo(void *data, int cmd, struct obdo *oa,
1879 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1881 lap->lap_caller_ops->ap_update_obdo(lap->lap_caller_data, cmd,oa,valid);
1884 static int lov_ap_completion(void *data, int cmd, struct obdo *oa, int rc)
1886 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1888 /* in a raid1 regime this would down a count of many ios
1889 * in flight, onl calling the caller_ops completion when all
1890 * the raid1 ios are complete */
1891 rc = lap->lap_caller_ops->ap_completion(lap->lap_caller_data,cmd,oa,rc);
1895 static struct obd_async_page_ops lov_async_page_ops = {
1896 .ap_make_ready = lov_ap_make_ready,
1897 .ap_refresh_count = lov_ap_refresh_count,
1898 .ap_fill_obdo = lov_ap_fill_obdo,
1899 .ap_update_obdo = lov_ap_update_obdo,
1900 .ap_completion = lov_ap_completion,
1903 int lov_prep_async_page(struct obd_export *exp, struct lov_stripe_md *lsm,
1904 struct lov_oinfo *loi, cfs_page_t *page,
1905 obd_off offset, struct obd_async_page_ops *ops,
1906 void *data, void **res, int flags,
1907 struct lustre_handle *lockh)
1909 struct lov_obd *lov = &exp->exp_obd->u.lov;
1910 struct lov_async_page *lap;
1911 struct lov_lock_handles *lov_lockh = NULL;
1917 /* Find an existing osc so we can get it's stupid sizeof(*oap).
1918 Only because of this layering limitation will a client
1919 mount with no osts fail */
1920 while (!lov->lov_tgts || !lov->lov_tgts[i] ||
1921 !lov->lov_tgts[i]->ltd_exp) {
1923 if (i >= lov->desc.ld_tgt_count)
1926 rc = size_round(sizeof(*lap)) +
1927 obd_prep_async_page(lov->lov_tgts[i]->ltd_exp, NULL,
1928 NULL, NULL, 0, NULL, NULL, NULL, 0,
1932 ASSERT_LSM_MAGIC(lsm);
1933 LASSERT(loi == NULL);
1936 lap->lap_magic = LOV_AP_MAGIC;
1937 lap->lap_caller_ops = ops;
1938 lap->lap_caller_data = data;
1940 /* for now only raid 0 which passes through */
1941 lap->lap_stripe = lov_stripe_number(lsm, offset);
1942 lov_stripe_offset(lsm, offset, lap->lap_stripe, &lap->lap_sub_offset);
1943 loi = lsm->lsm_oinfo[lap->lap_stripe];
1945 /* so the callback doesn't need the lsm */
1946 lap->lap_loi_id = loi->loi_id;
1947 lap->lap_loi_gr = loi->loi_gr;
1949 lap->lap_sub_cookie = (void *)lap + size_round(sizeof(*lap));
1951 if (lockh && lustre_handle_is_used(lockh) && !(flags & OBD_FAST_LOCK)) {
1952 lov_lockh = lov_handle2llh(lockh);
1954 lockh = lov_lockh->llh_handles + lap->lap_stripe;
1958 rc = obd_prep_async_page(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1959 lsm, loi, page, lap->lap_sub_offset,
1960 &lov_async_page_ops, lap,
1961 &lap->lap_sub_cookie, flags, lockh);
1963 lov_llh_put(lov_lockh);
1966 CDEBUG(D_CACHE, "lap %p page %p cookie %p off "LPU64"\n", lap, page,
1967 lap->lap_sub_cookie, offset);
1971 static int lov_queue_async_io(struct obd_export *exp,
1972 struct lov_stripe_md *lsm,
1973 struct lov_oinfo *loi, void *cookie,
1974 int cmd, obd_off off, int count,
1975 obd_flag brw_flags, obd_flag async_flags)
1977 struct lov_obd *lov = &exp->exp_obd->u.lov;
1978 struct lov_async_page *lap;
1981 LASSERT(loi == NULL);
1983 ASSERT_LSM_MAGIC(lsm);
1985 lap = LAP_FROM_COOKIE(cookie);
1987 loi = lsm->lsm_oinfo[lap->lap_stripe];
1989 rc = obd_queue_async_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp, lsm,
1990 loi, lap->lap_sub_cookie, cmd, off, count,
1991 brw_flags, async_flags);
1995 static int lov_set_async_flags(struct obd_export *exp,
1996 struct lov_stripe_md *lsm,
1997 struct lov_oinfo *loi, void *cookie,
1998 obd_flag async_flags)
2000 struct lov_obd *lov = &exp->exp_obd->u.lov;
2001 struct lov_async_page *lap;
2004 LASSERT(loi == NULL);
2006 ASSERT_LSM_MAGIC(lsm);
2008 lap = LAP_FROM_COOKIE(cookie);
2010 loi = lsm->lsm_oinfo[lap->lap_stripe];
2012 rc = obd_set_async_flags(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2013 lsm, loi, lap->lap_sub_cookie, async_flags);
2017 static int lov_queue_group_io(struct obd_export *exp,
2018 struct lov_stripe_md *lsm,
2019 struct lov_oinfo *loi,
2020 struct obd_io_group *oig, void *cookie,
2021 int cmd, obd_off off, int count,
2022 obd_flag brw_flags, obd_flag async_flags)
2024 struct lov_obd *lov = &exp->exp_obd->u.lov;
2025 struct lov_async_page *lap;
2028 LASSERT(loi == NULL);
2030 ASSERT_LSM_MAGIC(lsm);
2032 lap = LAP_FROM_COOKIE(cookie);
2034 loi = lsm->lsm_oinfo[lap->lap_stripe];
2036 rc = obd_queue_group_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp, lsm,
2037 loi, oig, lap->lap_sub_cookie, cmd, off, count,
2038 brw_flags, async_flags);
2042 /* this isn't exactly optimal. we may have queued sync io in oscs on
2043 * all stripes, but we don't record that fact at queue time. so we
2044 * trigger sync io on all stripes. */
2045 static int lov_trigger_group_io(struct obd_export *exp,
2046 struct lov_stripe_md *lsm,
2047 struct lov_oinfo *loi,
2048 struct obd_io_group *oig)
2050 struct lov_obd *lov = &exp->exp_obd->u.lov;
2053 LASSERT(loi == NULL);
2055 ASSERT_LSM_MAGIC(lsm);
2057 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2058 loi = lsm->lsm_oinfo[i];
2059 if (!lov->lov_tgts[loi->loi_ost_idx] ||
2060 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
2061 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2065 err = obd_trigger_group_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2067 if (rc == 0 && err != 0)
2073 static int lov_teardown_async_page(struct obd_export *exp,
2074 struct lov_stripe_md *lsm,
2075 struct lov_oinfo *loi, void *cookie)
2077 struct lov_obd *lov = &exp->exp_obd->u.lov;
2078 struct lov_async_page *lap;
2081 LASSERT(loi == NULL);
2083 ASSERT_LSM_MAGIC(lsm);
2085 lap = LAP_FROM_COOKIE(cookie);
2087 loi = lsm->lsm_oinfo[lap->lap_stripe];
2089 rc = obd_teardown_async_page(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2090 lsm, loi, lap->lap_sub_cookie);
2092 CERROR("unable to teardown sub cookie %p: %d\n",
2093 lap->lap_sub_cookie, rc);
2099 static int lov_enqueue_interpret(struct ptlrpc_request_set *rqset,
2102 struct lov_request_set *lovset = (struct lov_request_set *)data;
2104 rc = lov_fini_enqueue_set(lovset, lovset->set_ei->ei_mode, rc, rqset);
2108 static int lov_enqueue(struct obd_export *exp, struct obd_info *oinfo,
2109 struct ldlm_enqueue_info *einfo,
2110 struct ptlrpc_request_set *rqset)
2112 ldlm_mode_t mode = einfo->ei_mode;
2113 struct lov_request_set *set;
2114 struct lov_request *req;
2115 struct list_head *pos;
2116 struct lov_obd *lov;
2121 ASSERT_LSM_MAGIC(oinfo->oi_md);
2122 LASSERT(mode == (mode & -mode));
2124 /* we should never be asked to replay a lock this way. */
2125 LASSERT((oinfo->oi_flags & LDLM_FL_REPLAY) == 0);
2127 if (!exp || !exp->exp_obd)
2130 lov = &exp->exp_obd->u.lov;
2131 rc = lov_prep_enqueue_set(exp, oinfo, einfo, &set);
2135 list_for_each (pos, &set->set_list) {
2136 req = list_entry(pos, struct lov_request, rq_link);
2138 rc = obd_enqueue(lov->lov_tgts[req->rq_idx]->ltd_exp,
2139 &req->rq_oi, einfo, rqset);
2144 if (rqset && !list_empty(&rqset->set_requests)) {
2146 LASSERT(rqset->set_interpret == NULL);
2147 rqset->set_interpret = lov_enqueue_interpret;
2148 rqset->set_arg = (void *)set;
2152 rc = lov_fini_enqueue_set(set, mode, rc, rqset);
2156 static int lov_match(struct obd_export *exp, struct lov_stripe_md *lsm,
2157 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
2158 int *flags, void *data, struct lustre_handle *lockh,
2161 struct lov_request_set *set;
2162 struct obd_info oinfo;
2163 struct lov_request *req;
2164 struct list_head *pos;
2165 struct lov_obd *lov;
2166 struct lustre_handle *lov_lockhp;
2167 int lov_flags, rc = 0;
2170 ASSERT_LSM_MAGIC(lsm);
2171 LASSERT((*flags & LDLM_FL_TEST_LOCK) || mode == (mode & -mode));
2173 if (!exp || !exp->exp_obd)
2176 lov = &exp->exp_obd->u.lov;
2177 rc = lov_prep_match_set(exp, &oinfo, lsm, policy, mode, lockh, &set);
2181 list_for_each (pos, &set->set_list) {
2182 ldlm_policy_data_t sub_policy;
2183 req = list_entry(pos, struct lov_request, rq_link);
2184 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
2185 LASSERT(lov_lockhp);
2188 sub_policy.l_extent = req->rq_oi.oi_policy.l_extent;
2190 rc = obd_match(lov->lov_tgts[req->rq_idx]->ltd_exp,
2191 req->rq_oi.oi_md, type, &sub_policy,
2192 mode, &lov_flags, data, lov_lockhp,
2194 rc = lov_update_match_set(set, req, rc);
2198 lov_fini_match_set(set, mode, *flags);
2202 static int lov_change_cbdata(struct obd_export *exp,
2203 struct lov_stripe_md *lsm, ldlm_iterator_t it,
2206 struct lov_obd *lov;
2207 struct lov_oinfo *loi;
2211 ASSERT_LSM_MAGIC(lsm);
2213 if (!exp || !exp->exp_obd)
2216 lov = &exp->exp_obd->u.lov;
2217 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2218 struct lov_stripe_md submd;
2220 loi = lsm->lsm_oinfo[i];
2221 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2222 CDEBUG(D_HA, "lov idx %d NULL \n", loi->loi_ost_idx);
2225 submd.lsm_object_id = loi->loi_id;
2226 submd.lsm_object_gr = loi->loi_gr;
2227 submd.lsm_stripe_count = 0;
2228 rc = obd_change_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2234 /* find any ldlm lock of the inode in lov
2238 static int lov_find_cbdata(struct obd_export *exp,
2239 struct lov_stripe_md *lsm, ldlm_iterator_t it,
2242 struct lov_obd *lov;
2243 struct lov_oinfo *loi;
2247 ASSERT_LSM_MAGIC(lsm);
2249 if (!exp || !exp->exp_obd)
2252 lov = &exp->exp_obd->u.lov;
2253 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2254 struct lov_stripe_md submd;
2256 loi = lsm->lsm_oinfo[i];
2257 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2258 CDEBUG(D_HA, "lov idx %d NULL \n", loi->loi_ost_idx);
2261 submd.lsm_object_id = loi->loi_id;
2262 submd.lsm_object_gr = loi->loi_gr;
2263 submd.lsm_stripe_count = 0;
2264 rc = obd_find_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2273 static int lov_cancel(struct obd_export *exp, struct lov_stripe_md *lsm,
2274 __u32 mode, struct lustre_handle *lockh, int flags,
2277 struct lov_request_set *set;
2278 struct obd_info oinfo;
2279 struct lov_request *req;
2280 struct list_head *pos;
2281 struct lov_obd *lov;
2282 struct lustre_handle *lov_lockhp;
2283 ldlm_mode_t this_mode;
2284 int err = 0, rc = 0;
2287 ASSERT_LSM_MAGIC(lsm);
2289 if (!exp || !exp->exp_obd)
2293 lov = &exp->exp_obd->u.lov;
2294 if (flags & OBD_FAST_LOCK) {
2295 int stripe = lov_stripe_number(lsm, end);
2296 RETURN(obd_cancel(lov->lov_tgts[lsm->lsm_oinfo[stripe]->
2297 loi_ost_idx]->ltd_exp, NULL, mode, lockh,
2301 rc = lov_prep_cancel_set(exp, &oinfo, lsm, mode, lockh, &set);
2305 list_for_each (pos, &set->set_list) {
2306 req = list_entry(pos, struct lov_request, rq_link);
2307 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
2309 /* If this lock was used for a write or truncate, the object
2310 * will have been recreated by the OST, cancel the lock
2311 * (setting LCK_GROUP incidentally causes immediate cancel). */
2312 if (OST_LVB_IS_ERR(lsm->lsm_oinfo[req->rq_stripe]->loi_lvb.lvb_blocks) &&
2313 (mode == LCK_PW || mode == LCK_CW))
2314 this_mode = LCK_GROUP;
2318 rc = obd_cancel(lov->lov_tgts[req->rq_idx]->ltd_exp,
2319 req->rq_oi.oi_md, this_mode, lov_lockhp, flags,
2321 rc = lov_update_common_set(set, req, rc);
2323 CERROR("error: cancel objid "LPX64" subobj "
2324 LPX64" on OST idx %d: rc = %d\n",
2326 req->rq_oi.oi_md->lsm_object_id,
2332 lov_fini_cancel_set(set);
2336 static int lov_cancel_unused(struct obd_export *exp,
2337 struct lov_stripe_md *lsm, int flags, void *opaque)
2339 struct lov_obd *lov;
2340 struct lov_oinfo *loi;
2344 if (!exp || !exp->exp_obd)
2347 lov = &exp->exp_obd->u.lov;
2349 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2351 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2354 err = obd_cancel_unused(lov->lov_tgts[i]->ltd_exp, NULL,
2362 ASSERT_LSM_MAGIC(lsm);
2364 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2365 struct lov_stripe_md submd;
2368 loi = lsm->lsm_oinfo[i];
2369 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2370 CDEBUG(D_HA, "lov idx %d NULL\n", loi->loi_ost_idx);
2374 if (!lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
2375 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2377 submd.lsm_object_id = loi->loi_id;
2378 submd.lsm_stripe_count = 0;
2379 err = obd_cancel_unused(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2380 &submd, flags, opaque);
2381 if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
2382 CERROR("error: cancel unused objid "LPX64" subobj "LPX64
2383 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
2384 loi->loi_id, loi->loi_ost_idx, err);
2392 static int lov_join_lru(struct obd_export *exp,
2393 struct lov_stripe_md *lsm, int join)
2395 struct lov_obd *lov;
2396 struct lov_oinfo *loi;
2400 ASSERT_LSM_MAGIC(lsm);
2401 if (!exp || !exp->exp_obd)
2404 lov = &exp->exp_obd->u.lov;
2405 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2406 struct lov_stripe_md submd;
2409 loi = lsm->lsm_oinfo[i];
2410 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2411 CDEBUG(D_HA, "lov idx %d NULL\n", loi->loi_ost_idx);
2415 if (!lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
2416 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2418 submd.lsm_object_id = loi->loi_id;
2419 submd.lsm_stripe_count = 0;
2420 rc = obd_join_lru(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2423 CERROR("join lru failed. objid: "LPX64" subobj: "LPX64
2424 " ostidx: %d rc: %d\n", lsm->lsm_object_id,
2425 loi->loi_id, loi->loi_ost_idx, rc);
2434 int lov_statfs_interpret(struct ptlrpc_request_set *rqset, void *data, int rc)
2436 struct lov_request_set *lovset = (struct lov_request_set *)data;
2441 lovset->set_completes = 0;
2443 err = lov_fini_statfs_set(lovset);
2444 RETURN(rc ? rc : err);
2447 static int lov_statfs_async(struct obd_device *obd, struct obd_info *oinfo,
2448 __u64 max_age, struct ptlrpc_request_set *rqset)
2450 struct lov_request_set *set;
2451 struct lov_request *req;
2452 struct list_head *pos;
2453 struct lov_obd *lov;
2457 LASSERT(oinfo != NULL);
2458 LASSERT(oinfo->oi_osfs != NULL);
2461 rc = lov_prep_statfs_set(obd, oinfo, &set);
2465 list_for_each (pos, &set->set_list) {
2466 struct obd_device *osc_obd;
2468 req = list_entry(pos, struct lov_request, rq_link);
2470 osc_obd = class_exp2obd(lov->lov_tgts[req->rq_idx]->ltd_exp);
2471 rc = obd_statfs_async(osc_obd, &req->rq_oi, max_age, rqset);
2476 if (rc || list_empty(&rqset->set_requests)) {
2479 set->set_completes = 0;
2480 err = lov_fini_statfs_set(set);
2481 RETURN(rc ? rc : err);
2484 LASSERT(rqset->set_interpret == NULL);
2485 rqset->set_interpret = lov_statfs_interpret;
2486 rqset->set_arg = (void *)set;
2490 static int lov_statfs(struct obd_device *obd, struct obd_statfs *osfs,
2491 __u64 max_age, __u32 flags)
2493 struct ptlrpc_request_set *set = NULL;
2494 struct obd_info oinfo = { { { 0 } } };
2498 /* for obdclass we forbid using obd_statfs_rqset, but prefer using async
2499 * statfs requests */
2500 set = ptlrpc_prep_set();
2504 oinfo.oi_osfs = osfs;
2505 oinfo.oi_flags = flags;
2506 rc = lov_statfs_async(obd, &oinfo, max_age, set);
2508 rc = ptlrpc_set_wait(set);
2509 ptlrpc_set_destroy(set);
2514 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
2515 void *karg, void *uarg)
2517 struct obd_device *obddev = class_exp2obd(exp);
2518 struct lov_obd *lov = &obddev->u.lov;
2519 int i, rc, count = lov->desc.ld_tgt_count;
2520 struct obd_uuid *uuidp;
2524 case OBD_IOC_LOV_GET_CONFIG: {
2525 struct obd_ioctl_data *data;
2526 struct lov_desc *desc;
2531 if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
2534 data = (struct obd_ioctl_data *)buf;
2536 if (sizeof(*desc) > data->ioc_inllen1) {
2537 obd_ioctl_freedata(buf, len);
2541 if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
2542 obd_ioctl_freedata(buf, len);
2546 if (sizeof(__u32) * count > data->ioc_inllen3) {
2547 obd_ioctl_freedata(buf, len);
2551 desc = (struct lov_desc *)data->ioc_inlbuf1;
2552 memcpy(desc, &(lov->desc), sizeof(*desc));
2554 uuidp = (struct obd_uuid *)data->ioc_inlbuf2;
2555 genp = (__u32 *)data->ioc_inlbuf3;
2556 /* the uuid will be empty for deleted OSTs */
2557 for (i = 0; i < count; i++, uuidp++, genp++) {
2558 if (!lov->lov_tgts[i])
2560 *uuidp = lov->lov_tgts[i]->ltd_uuid;
2561 *genp = lov->lov_tgts[i]->ltd_gen;
2564 rc = copy_to_user((void *)uarg, buf, len);
2567 obd_ioctl_freedata(buf, len);
2570 case LL_IOC_LOV_SETSTRIPE:
2571 rc = lov_setstripe(exp, karg, uarg);
2573 case LL_IOC_LOV_GETSTRIPE:
2574 rc = lov_getstripe(exp, karg, uarg);
2576 case LL_IOC_LOV_SETEA:
2577 rc = lov_setea(exp, karg, uarg);
2586 for (i = 0; i < count; i++) {
2589 /* OST was disconnected */
2590 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2593 err = obd_iocontrol(cmd, lov->lov_tgts[i]->ltd_exp,
2595 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
2598 if (lov->lov_tgts[i]->ltd_active) {
2599 CDEBUG(err == -ENOTTY ?
2600 D_IOCTL : D_WARNING,
2601 "iocontrol OSC %s on OST "
2602 "idx %d cmd %x: err = %d\n",
2603 lov_uuid2str(lov, i),
2620 #define FIEMAP_BUFFER_SIZE 4096
2622 /* Non-zero fe_logical indicates that this is a continuation FIEMAP
2623 * call. The local end offset and the device are sent in the first
2624 * fm_extent. This function calculates the stripe number from the index.
2625 * This function returns a stripe_no on which mapping is to be restarted.
2627 * This function returns fm_end_offset which is the in-OST offset at which
2628 * mapping should be restarted. If fm_end_offset=0 is returned then caller
2629 * will re-calculate proper offset in next stripe.
2630 * Note that the first extent is passed to lov_get_info via the value field */
2631 obd_size fiemap_calc_fm_end_offset(struct ll_user_fiemap *fiemap,
2632 struct lov_stripe_md *lsm, obd_size fm_start,
2633 obd_size fm_end, int *start_stripe)
2635 obd_size local_end = fiemap->fm_extents[0].fe_logical;
2636 obd_off lun_start, lun_end;
2637 obd_size fm_end_offset;
2638 int stripe_no = -1, i;
2640 if (fiemap->fm_extent_count == 0 ||
2641 fiemap->fm_extents[0].fe_logical == 0)
2644 /* Find out stripe_no from ost_index saved in the fe_device */
2645 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2646 if (lsm->lsm_oinfo[i]->loi_ost_idx ==
2647 fiemap->fm_extents[0].fe_device) {
2653 /* If we have finished mapping on previous device, shift logical
2654 * offset to start of next device */
2655 if ((lov_stripe_intersects(lsm, stripe_no, fm_start, fm_end,
2656 &lun_start, &lun_end)) != 0 &&
2657 local_end < lun_end) {
2658 fm_end_offset = local_end;
2659 *start_stripe = stripe_no;
2661 /* This is a special value to indicate that caller should
2662 * calculate offset in next stripe. */
2664 *start_stripe = (stripe_no + 1) % lsm->lsm_stripe_count;
2667 return fm_end_offset;
2670 /* We calculate on which OST the mapping will end. If the length of mapping
2671 * is greater than (stripe_size * stripe_count) then the last_stripe will
2672 * will be one just before start_stripe. Else we check if the mapping
2673 * intersects each OST and find last_stripe.
2674 * This function returns the last_stripe and also sets the stripe_count
2675 * over which the mapping is spread */
2676 int fiemap_calc_last_stripe(struct lov_stripe_md *lsm, obd_size fm_start,
2677 obd_size fm_end, int start_stripe,
2681 obd_off obd_start, obd_end;
2684 if (fm_end - fm_start > lsm->lsm_stripe_size * lsm->lsm_stripe_count) {
2685 last_stripe = (start_stripe < 1 ? lsm->lsm_stripe_count - 1 :
2687 *stripe_count = lsm->lsm_stripe_count;
2689 for (j = 0, i = start_stripe; j < lsm->lsm_stripe_count;
2690 i = (i + 1) % lsm->lsm_stripe_count, j++) {
2691 if ((lov_stripe_intersects(lsm, i, fm_start, fm_end,
2692 &obd_start, &obd_end)) == 0)
2696 last_stripe = (start_stripe + j - 1) %lsm->lsm_stripe_count;
2702 /* Set fe_device and copy extents from local buffer into main return buffer */
2703 void fiemap_prepare_and_copy_exts(struct ll_user_fiemap *fiemap,
2704 struct ll_fiemap_extent *lcl_fm_ext,
2705 int ost_index, unsigned int ext_count,
2711 for (ext = 0; ext < ext_count; ext++) {
2712 lcl_fm_ext[ext].fe_device = ost_index;
2713 lcl_fm_ext[ext].fe_flags |= FIEMAP_EXTENT_NET;
2716 /* Copy fm_extent's from fm_local to return buffer */
2717 to = (char *)fiemap + fiemap_count_to_size(current_extent);
2718 memcpy(to, lcl_fm_ext, ext_count * sizeof(struct ll_fiemap_extent));
2721 static int lov_fiemap(struct lov_obd *lov, __u32 keylen, void *key,
2722 __u32 *vallen, void *val, struct lov_stripe_md *lsm)
2724 struct ll_fiemap_info_key *fm_key = key;
2725 struct ll_user_fiemap *fiemap = val;
2726 struct ll_user_fiemap *fm_local = NULL;
2727 struct ll_fiemap_extent *lcl_fm_ext;
2729 unsigned int get_num_extents = 0;
2730 int ost_index = 0, actual_start_stripe, start_stripe;
2731 obd_size fm_start, fm_end, fm_length, fm_end_offset = 0;
2733 int current_extent = 0, rc = 0, i;
2734 int ost_eof = 0; /* EOF for object */
2735 int ost_done = 0; /* done with required mapping for this OST? */
2737 int cur_stripe = 0, cur_stripe_wrap = 0, stripe_count;
2738 unsigned int buffer_size = FIEMAP_BUFFER_SIZE;
2743 if (fiemap_count_to_size(fm_key->fiemap.fm_extent_count) < buffer_size)
2744 buffer_size = fiemap_count_to_size(fm_key->fiemap.fm_extent_count);
2746 OBD_ALLOC(fm_local, buffer_size);
2747 if (fm_local == NULL)
2748 GOTO(out, rc = -ENOMEM);
2749 lcl_fm_ext = &fm_local->fm_extents[0];
2751 count_local = fiemap_size_to_count(buffer_size);
2753 memcpy(fiemap, &fm_key->fiemap, sizeof(*fiemap));
2754 fm_start = fiemap->fm_start;
2755 fm_length = fiemap->fm_length;
2756 /* Calculate start stripe, last stripe and length of mapping */
2757 actual_start_stripe = start_stripe = lov_stripe_number(lsm, fm_start);
2758 fm_end = (fm_length == ~0ULL ? fm_key->oa.o_size :
2759 fm_start + fm_length - 1);
2760 /* If fm_length != ~0ULL but fm_start+fm_length-1 exceeds file size */
2761 if (fm_end > fm_key->oa.o_size)
2762 fm_end = fm_key->oa.o_size;
2764 last_stripe = fiemap_calc_last_stripe(lsm, fm_start, fm_end,
2765 actual_start_stripe, &stripe_count);
2767 fm_end_offset = fiemap_calc_fm_end_offset(fiemap, lsm, fm_start, fm_end,
2770 if (fiemap->fm_extent_count == 0) {
2771 get_num_extents = 1;
2775 /* Check each stripe */
2776 for (cur_stripe = start_stripe, i = 0; i < stripe_count;
2777 i++, cur_stripe = (cur_stripe + 1) % lsm->lsm_stripe_count) {
2778 obd_size req_fm_len; /* Stores length of required mapping */
2779 obd_size len_mapped_single_call;
2780 obd_off lun_start, lun_end, obd_object_end;
2781 unsigned int ext_count;
2783 cur_stripe_wrap = cur_stripe;
2785 /* Find out range of mapping on this stripe */
2786 if ((lov_stripe_intersects(lsm, cur_stripe, fm_start, fm_end,
2787 &lun_start, &obd_object_end)) == 0)
2790 /* If this is a continuation FIEMAP call and we are on
2791 * starting stripe then lun_start needs to be set to
2793 if (fm_end_offset != 0 && cur_stripe == start_stripe)
2794 lun_start = fm_end_offset;
2796 if (fm_length != ~0ULL) {
2797 /* Handle fm_start + fm_length overflow */
2798 if (fm_start + fm_length < fm_start)
2799 fm_length = ~0ULL - fm_start;
2800 lun_end = lov_size_to_stripe(lsm, fm_start + fm_length,
2806 if (lun_start == lun_end)
2809 req_fm_len = obd_object_end - lun_start;
2810 fm_local->fm_length = 0;
2811 len_mapped_single_call = 0;
2813 /* If the output buffer is very large and the objects have many
2814 * extents we may need to loop on a single OST repeatedly */
2818 if (get_num_extents == 0) {
2819 /* Don't get too many extents. */
2820 if (current_extent + count_local >
2821 fiemap->fm_extent_count)
2822 count_local = fiemap->fm_extent_count -
2826 lun_start += len_mapped_single_call;
2827 fm_local->fm_length = req_fm_len - len_mapped_single_call;
2828 req_fm_len = fm_local->fm_length;
2829 fm_local->fm_extent_count = count_local;
2830 fm_local->fm_mapped_extents = 0;
2831 fm_local->fm_flags = fiemap->fm_flags;
2833 fm_key->oa.o_id = lsm->lsm_oinfo[cur_stripe]->loi_id;
2834 fm_key->oa.o_gr = lsm->lsm_oinfo[cur_stripe]->loi_gr;
2835 ost_index = lsm->lsm_oinfo[cur_stripe]->loi_ost_idx;
2837 if (ost_index < 0 || ost_index >=lov->desc.ld_tgt_count)
2838 GOTO(out, rc = -EINVAL);
2840 /* If OST is inactive, return extent with UNKNOWN flag */
2841 if (!lov->lov_tgts[ost_index]->ltd_active) {
2842 fm_local->fm_flags |= FIEMAP_EXTENT_LAST;
2843 fm_local->fm_mapped_extents = 1;
2845 lcl_fm_ext[0].fe_logical = lun_start;
2846 lcl_fm_ext[0].fe_length = obd_object_end -
2848 lcl_fm_ext[0].fe_flags |= FIEMAP_EXTENT_UNKNOWN;
2853 fm_local->fm_start = lun_start;
2854 fm_local->fm_flags &= ~FIEMAP_FLAG_DEVICE_ORDER;
2855 memcpy(&fm_key->fiemap, fm_local, sizeof(*fm_local));
2856 *vallen=fiemap_count_to_size(fm_local->fm_extent_count);
2857 rc = obd_get_info(lov->lov_tgts[ost_index]->ltd_exp,
2858 keylen, key, vallen, fm_local, lsm);
2863 ext_count = fm_local->fm_mapped_extents;
2864 if (ext_count == 0) {
2866 /* If last stripe has hole at the end,
2867 * then we need to return */
2868 if (cur_stripe_wrap == last_stripe) {
2869 fiemap->fm_mapped_extents = 0;
2875 /* If we just need num of extents then go to next device */
2876 if (get_num_extents) {
2877 current_extent += ext_count;
2881 len_mapped_single_call = lcl_fm_ext[ext_count-1].fe_logical -
2882 lun_start + lcl_fm_ext[ext_count - 1].fe_length;
2884 /* Have we finished mapping on this device? */
2885 if (req_fm_len <= len_mapped_single_call)
2888 /* Clear the EXTENT_LAST flag which can be present on
2890 if (lcl_fm_ext[ext_count-1].fe_flags & FIEMAP_EXTENT_LAST)
2891 lcl_fm_ext[ext_count - 1].fe_flags &=
2892 ~FIEMAP_EXTENT_LAST;
2894 curr_loc = lov_stripe_size(lsm,
2895 lcl_fm_ext[ext_count - 1].fe_logical+
2896 lcl_fm_ext[ext_count - 1].fe_length,
2898 if (curr_loc >= fm_key->oa.o_size)
2901 fiemap_prepare_and_copy_exts(fiemap, lcl_fm_ext,
2902 ost_index, ext_count,
2905 current_extent += ext_count;
2907 /* Ran out of available extents? */
2908 if (current_extent >= fiemap->fm_extent_count)
2910 } while (ost_done == 0 && ost_eof == 0);
2912 if (cur_stripe_wrap == last_stripe)
2917 /* Indicate that we are returning device offsets unless file just has
2919 if (lsm->lsm_stripe_count > 1)
2920 fiemap->fm_flags |= FIEMAP_FLAG_DEVICE_ORDER;
2922 if (get_num_extents)
2923 goto skip_last_device_calc;
2925 /* Check if we have reached the last stripe and whether mapping for that
2926 * stripe is done. */
2927 if (cur_stripe_wrap == last_stripe) {
2928 if (ost_done || ost_eof)
2929 fiemap->fm_extents[current_extent - 1].fe_flags |=
2933 skip_last_device_calc:
2934 fiemap->fm_mapped_extents = current_extent;
2937 OBD_FREE(fm_local, buffer_size);
2941 static int lov_get_info(struct obd_export *exp, __u32 keylen,
2942 void *key, __u32 *vallen, void *val,
2943 struct lov_stripe_md *lsm)
2945 struct obd_device *obddev = class_exp2obd(exp);
2946 struct lov_obd *lov = &obddev->u.lov;
2950 if (!vallen || !val)
2955 if (KEY_IS(KEY_LOCK_TO_STRIPE)) {
2958 struct ldlm_lock *lock;
2960 struct ldlm_res_id *res_id = &data->lock->l_resource->lr_name;
2961 struct lov_oinfo *loi;
2962 __u32 *stripe = val;
2964 if (*vallen < sizeof(*stripe))
2965 GOTO(out, rc = -EFAULT);
2966 *vallen = sizeof(*stripe);
2968 /* XXX This is another one of those bits that will need to
2969 * change if we ever actually support nested LOVs. It uses
2970 * the lock's export to find out which stripe it is. */
2971 /* XXX - it's assumed all the locks for deleted OSTs have
2972 * been cancelled. Also, the export for deleted OSTs will
2973 * be NULL and won't match the lock's export. */
2974 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2975 loi = lsm->lsm_oinfo[i];
2976 if (!lov->lov_tgts[loi->loi_ost_idx])
2978 if (lov->lov_tgts[loi->loi_ost_idx]->ltd_exp ==
2979 data->lock->l_conn_export &&
2980 osc_res_name_eq(loi->loi_id, loi->loi_gr, res_id)) {
2985 LDLM_ERROR(data->lock, "lock on inode without such object");
2986 dump_lsm(D_ERROR, lsm);
2987 GOTO(out, rc = -ENXIO);
2988 } else if (KEY_IS(KEY_LAST_ID)) {
2989 struct obd_id_info *info = val;
2990 __u32 size = sizeof(obd_id);
2991 struct lov_tgt_desc *tgt;
2993 LASSERT(*vallen == sizeof(struct obd_id_info));
2994 tgt = lov->lov_tgts[info->idx];
2996 if (!tgt || !tgt->ltd_active)
2997 GOTO(out, rc = -ESRCH);
2999 rc = obd_get_info(tgt->ltd_exp, keylen, key, &size, info->data, NULL);
3001 } else if (KEY_IS(KEY_LOVDESC)) {
3002 struct lov_desc *desc_ret = val;
3003 *desc_ret = lov->desc;
3006 } else if (KEY_IS(KEY_FIEMAP)) {
3007 rc = lov_fiemap(lov, keylen, key, vallen, val, lsm);
3009 } else if (KEY_IS(KEY_OFF_RPCSIZE)) {
3010 __u64 *offset = val;
3011 struct lov_tgt_desc *tgt;
3012 struct lov_oinfo *loi;
3015 LASSERT(*vallen == sizeof(__u64));
3016 stripe = lov_stripe_number(lsm, *offset);
3017 loi = lsm->lsm_oinfo[stripe];
3018 tgt = lov->lov_tgts[loi->loi_ost_idx];
3019 if (!tgt || !tgt->ltd_active)
3020 GOTO(out, rc = -ESRCH);
3021 rc = obd_get_info(tgt->ltd_exp, keylen, key, vallen, val, NULL);
3023 } else if (KEY_IS(KEY_CONNECT_FLAG)) {
3024 struct lov_tgt_desc *tgt;
3025 __u64 ost_idx = *((__u64*)val);
3027 LASSERT(*vallen == sizeof(__u64));
3028 LASSERT(ost_idx < lov->desc.ld_tgt_count);
3029 tgt = lov->lov_tgts[ost_idx];
3031 if (!tgt || !tgt->ltd_exp)
3032 GOTO(out, rc = -ESRCH);
3034 *((__u64*)val) = tgt->ltd_exp->exp_connect_flags;
3044 static int lov_set_info_async(struct obd_export *exp, obd_count keylen,
3045 void *key, obd_count vallen, void *val,
3046 struct ptlrpc_request_set *set)
3048 struct obd_device *obddev = class_exp2obd(exp);
3049 struct lov_obd *lov = &obddev->u.lov;
3051 int i, rc = 0, err, incr = 0, check_uuid = 0, do_inactive = 0;
3053 unsigned next_id = 0;
3054 struct lov_tgt_desc *tgt;
3059 set = ptlrpc_prep_set();
3065 count = lov->desc.ld_tgt_count;
3067 if (KEY_IS(KEY_NEXT_ID)) {
3068 count = vallen / sizeof(struct obd_id_info);
3069 vallen = sizeof(obd_id);
3070 incr = sizeof(struct obd_id_info);
3073 } else if (KEY_IS(KEY_CHECKSUM)) {
3075 } else if (KEY_IS(KEY_MDS_CONN)) {
3076 check_uuid = val ? 1 : 0;
3077 } else if (KEY_IS(KEY_EVICT_BY_NID)) {
3079 do_inactive = incr = 0;
3083 for (i = 0; i < count; i++, val = (char *)val + incr) {
3085 tgt = lov->lov_tgts[((struct obd_id_info*)val)->idx];
3086 data = ((struct obd_id_info*)val)->data;
3088 tgt = lov->lov_tgts[i];
3091 /* OST was disconnected */
3092 if (!tgt || !tgt->ltd_exp)
3095 /* OST is inactive and we don't want inactive OSCs */
3096 if (!tgt->ltd_active && !do_inactive)
3099 /* Only want a specific OSC */
3101 !obd_uuid_equals(val, &tgt->ltd_uuid))
3104 err = obd_set_info_async(tgt->ltd_exp,
3105 keylen, key, vallen, data, set);
3111 err = ptlrpc_set_wait(set);
3114 ptlrpc_set_destroy(set);
3119 static int lov_checkmd(struct obd_export *exp, struct obd_export *md_exp,
3120 struct lov_stripe_md *lsm)
3128 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
3129 rc = lsm_op_find(lsm->lsm_magic)->lsm_revalidate(lsm, md_exp->exp_obd);
3134 int lov_test_and_clear_async_rc(struct lov_stripe_md *lsm)
3136 struct lov_oinfo *loi;
3140 for (i = 0; i < lsm->lsm_stripe_count; i++) {
3141 loi = lsm->lsm_oinfo[i];
3142 if (loi->loi_ar.ar_rc && !rc)
3143 rc = loi->loi_ar.ar_rc;
3144 loi->loi_ar.ar_rc = 0;
3148 EXPORT_SYMBOL(lov_test_and_clear_async_rc);
3151 static int lov_extent_calc(struct obd_export *exp, struct lov_stripe_md *lsm,
3152 int cmd, __u64 *offset)
3155 __u32 ssize = lsm->lsm_stripe_size;
3157 if (cmd & OBD_CALC_STRIPE_RPC_ALIGN)
3158 ssize = ssize > PTLRPC_MAX_BRW_SIZE ?
3159 PTLRPC_MAX_BRW_SIZE : ssize;
3162 do_div(start, ssize);
3163 start = start * ssize;
3165 CDEBUG(D_DLMTRACE, "offset "LPU64", stripe %u, start "LPU64
3166 ", end "LPU64"\n", *offset, ssize, start, start + ssize - 1);
3167 if (cmd & OBD_CALC_STRIPE_END)
3168 *offset = start + ssize - 1;
3169 else if (cmd & OBD_CALC_STRIPE_START)
3178 struct lov_multi_wait {
3179 struct ldlm_lock *lock;
3185 int lov_complete_many(struct obd_export *exp, struct lov_stripe_md *lsm,
3186 struct lustre_handle *lockh)
3188 struct lov_lock_handles *lov_lockh = NULL;
3189 struct lustre_handle *lov_lockhp;
3190 struct lov_obd *lov;
3191 struct lov_oinfo *loi;
3192 struct lov_multi_wait *queues;
3196 ASSERT_LSM_MAGIC(lsm);
3198 if (!exp || !exp->exp_obd)
3201 LASSERT(lockh != NULL);
3202 if (lsm->lsm_stripe_count > 1) {
3203 lov_lockh = lov_handle2llh(lockh);
3204 if (lov_lockh == NULL) {
3205 CERROR("LOV: invalid lov lock handle %p\n", lockh);
3209 lov_lockhp = lov_lockh->llh_handles;
3214 OBD_ALLOC(queues, lsm->lsm_stripe_count * sizeof(*queues));
3216 GOTO(out, rc = -ENOMEM);
3218 lov = &exp->exp_obd->u.lov;
3219 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
3220 i++, loi++, lov_lockhp++) {
3221 struct ldlm_lock *lock;
3222 struct obd_device *obd;
3224 lock = ldlm_handle2lock(lov_lockhp);
3226 CDEBUG(D_HA, "lov idx %d subobj "LPX64" no lock?\n",
3227 loi->loi_ost_idx, loi->loi_id);
3228 queues[i].completed = 1;
3232 queues[i].lock = lock;
3233 init_waitqueue_entry(&(queues[i].wait), current);
3234 add_wait_queue(lock->l_waitq, &(queues[i].wait));
3236 obd = class_exp2obd(lock->l_conn_export);
3238 imp = obd->u.cli.cl_import;
3240 spin_lock(&imp->imp_lock);
3241 queues[i].generation = imp->imp_generation;
3242 spin_unlock(&imp->imp_lock);
3246 lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, ldlm_expired_completion_wait,
3247 interrupted_completion_wait, &lwd);
3248 rc = l_wait_event_added(check_multi_complete(queues, lsm), &lwi);
3250 for (i = 0; i < lsm->lsm_stripe_count; i++)
3251 remove_wait_queue(lock->l_waitq, &(queues[i].wait));
3253 if (rc == -EINTR || rc == -ETIMEDOUT) {
3259 if (lov_lockh != NULL)
3260 lov_llh_put(lov_lockh);
3265 void lov_stripe_lock(struct lov_stripe_md *md)
3267 LASSERT(md->lsm_lock_owner != cfs_current());
3268 spin_lock(&md->lsm_lock);
3269 LASSERT(md->lsm_lock_owner == NULL);
3270 md->lsm_lock_owner = cfs_current();
3272 EXPORT_SYMBOL(lov_stripe_lock);
3274 void lov_stripe_unlock(struct lov_stripe_md *md)
3276 LASSERT(md->lsm_lock_owner == cfs_current());
3277 md->lsm_lock_owner = NULL;
3278 spin_unlock(&md->lsm_lock);
3280 EXPORT_SYMBOL(lov_stripe_unlock);
3282 static int lov_get_lock(struct obd_export *exp, struct lov_stripe_md *lsm,
3283 void **res, int rw, obd_off start, obd_off end,
3284 struct lustre_handle *lockh, int flags)
3286 struct lov_async_page *l = *res;
3287 obd_off stripe_start, stripe_end = start;
3288 struct lov_lock_handles *lov_lockh = NULL;
3293 if (lockh && lustre_handle_is_used(lockh) &&
3294 !(flags & OBD_FAST_LOCK)) {
3295 lov_lockh = lov_handle2llh(lockh);
3296 if (lov_lockh == NULL) {
3297 CERROR("LOV: invalid lov lock handle %p\n", lockh);
3300 lockh = lov_lockh->llh_handles + l->lap_stripe;
3303 /* ensure we don't cross stripe boundaries */
3304 lov_extent_calc(exp, lsm, OBD_CALC_STRIPE_END, &stripe_end);
3305 if (stripe_end < end)
3308 /* map the region limits to the object limits */
3309 lov_stripe_offset(lsm, start, l->lap_stripe, &stripe_start);
3310 lov_stripe_offset(lsm, end, l->lap_stripe, &stripe_end);
3312 rc = obd_get_lock(exp->exp_obd->u.lov.lov_tgts[lsm->
3313 lsm_oinfo[l->lap_stripe]->loi_ost_idx]->
3314 ltd_exp, NULL, &l->lap_sub_cookie,
3315 rw, stripe_start, stripe_end, lockh, flags);
3317 if (lov_lockh != NULL)
3318 lov_llh_put(lov_lockh);
3322 struct obd_ops lov_obd_ops = {
3323 .o_owner = THIS_MODULE,
3324 .o_setup = lov_setup,
3325 .o_precleanup = lov_precleanup,
3326 .o_cleanup = lov_cleanup,
3327 .o_process_config = lov_process_config,
3328 .o_connect = lov_connect,
3329 .o_disconnect = lov_disconnect,
3330 .o_statfs = lov_statfs,
3331 .o_statfs_async = lov_statfs_async,
3332 .o_packmd = lov_packmd,
3333 .o_unpackmd = lov_unpackmd,
3334 .o_checkmd = lov_checkmd,
3335 .o_create = lov_create,
3336 .o_destroy = lov_destroy,
3337 .o_getattr = lov_getattr,
3338 .o_getattr_async = lov_getattr_async,
3339 .o_setattr = lov_setattr,
3340 .o_setattr_async = lov_setattr_async,
3342 .o_brw_async = lov_brw_async,
3343 .o_prep_async_page = lov_prep_async_page,
3344 .o_get_lock = lov_get_lock,
3345 .o_queue_async_io = lov_queue_async_io,
3346 .o_set_async_flags = lov_set_async_flags,
3347 .o_queue_group_io = lov_queue_group_io,
3348 .o_trigger_group_io = lov_trigger_group_io,
3349 .o_teardown_async_page = lov_teardown_async_page,
3350 .o_merge_lvb = lov_merge_lvb,
3351 .o_update_lvb = lov_update_lvb,
3352 .o_adjust_kms = lov_adjust_kms,
3353 .o_punch = lov_punch,
3355 .o_enqueue = lov_enqueue,
3356 .o_match = lov_match,
3357 .o_change_cbdata = lov_change_cbdata,
3358 .o_find_cbdata = lov_find_cbdata,
3359 .o_cancel = lov_cancel,
3360 .o_cancel_unused = lov_cancel_unused,
3361 .o_join_lru = lov_join_lru,
3362 .o_iocontrol = lov_iocontrol,
3363 .o_get_info = lov_get_info,
3364 .o_set_info_async = lov_set_info_async,
3365 .o_extent_calc = lov_extent_calc,
3366 .o_llog_init = lov_llog_init,
3367 .o_llog_finish = lov_llog_finish,
3368 .o_notify = lov_notify,
3369 .o_register_page_removal_cb = lov_obd_register_page_removal_cb,
3370 .o_unregister_page_removal_cb = lov_obd_unregister_page_removal_cb,
3371 .o_register_lock_cancel_cb = lov_obd_register_lock_cancel_cb,
3372 .o_unregister_lock_cancel_cb = lov_obd_unregister_lock_cancel_cb,
3373 .o_pool_new = lov_pool_new,
3374 .o_pool_rem = lov_pool_remove,
3375 .o_pool_add = lov_pool_add,
3376 .o_pool_del = lov_pool_del,
3377 .o_getref = lov_getref,
3378 .o_putref = lov_putref,
3381 static quota_interface_t *quota_interface;
3382 extern quota_interface_t lov_quota_interface;
3384 cfs_mem_cache_t *lov_oinfo_slab;
3386 int __init lov_init(void)
3388 struct lprocfs_static_vars lvars = { 0 };
3392 lov_oinfo_slab = cfs_mem_cache_create("lov_oinfo",
3393 sizeof(struct lov_oinfo),
3394 0, SLAB_HWCACHE_ALIGN);
3395 if (lov_oinfo_slab == NULL)
3397 lprocfs_lov_init_vars(&lvars);
3399 request_module("lquota");
3400 quota_interface = PORTAL_SYMBOL_GET(lov_quota_interface);
3401 init_obd_quota_ops(quota_interface, &lov_obd_ops);
3403 rc = class_register_type(&lov_obd_ops, lvars.module_vars,
3406 if (quota_interface)
3407 PORTAL_SYMBOL_PUT(lov_quota_interface);
3408 rc2 = cfs_mem_cache_destroy(lov_oinfo_slab);
3416 static void /*__exit*/ lov_exit(void)
3420 if (quota_interface)
3421 PORTAL_SYMBOL_PUT(lov_quota_interface);
3423 class_unregister_type(LUSTRE_LOV_NAME);
3424 rc = cfs_mem_cache_destroy(lov_oinfo_slab);
3428 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
3429 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver");
3430 MODULE_LICENSE("GPL");
3432 cfs_module(lov, LUSTRE_VERSION_STRING, lov_init, lov_exit);