1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002-2006 Cluster File Systems, Inc.
5 * Author: Phil Schwan <phil@clusterfs.com>
6 * Peter Braam <braam@clusterfs.com>
7 * Mike Shaver <shaver@clusterfs.com>
8 * Nathan Rutman <nathan@clusterfs.com>
10 * This file is part of the Lustre file system, http://www.lustre.org
11 * Lustre is a trademark of Cluster File Systems, Inc.
13 * You may have signed or agreed to another license before downloading
14 * this software. If so, you are bound by the terms and conditions
15 * of that agreement, and the following does not apply to you. See the
16 * LICENSE file included with this distribution for more information.
18 * If you did not agree to a different license, then this copy of Lustre
19 * is open source software; you can redistribute it and/or modify it
20 * under the terms of version 2 of the GNU General Public License as
21 * published by the Free Software Foundation.
23 * In either case, Lustre is distributed in the hope that it will be
24 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
25 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * license text for more details.
30 # define EXPORT_SYMTAB
32 #define DEBUG_SUBSYSTEM S_LOV
34 #include <libcfs/libcfs.h>
36 #include <liblustre.h>
39 #include <obd_support.h>
40 #include <lustre_lib.h>
41 #include <lustre_net.h>
42 #include <lustre/lustre_idl.h>
43 #include <lustre_dlm.h>
44 #include <lustre_mds.h>
45 #include <lustre_debug.h>
46 #include <obd_class.h>
49 #include <lprocfs_status.h>
50 #include <lustre_param.h>
51 #include <lustre_cache.h>
53 #include "lov_internal.h"
56 /* Keep a refcount of lov->tgt usage to prevent racing with addition/deletion.
57 Any function that expects lov_tgts to remain stationary must take a ref. */
58 void lov_getref(struct obd_device *obd)
60 struct lov_obd *lov = &obd->u.lov;
62 /* nobody gets through here until lov_putref is done */
63 mutex_down(&lov->lov_lock);
64 atomic_inc(&lov->lov_refcount);
65 mutex_up(&lov->lov_lock);
69 static void __lov_del_obd(struct obd_device *obd, __u32 index);
71 void lov_putref(struct obd_device *obd)
73 struct lov_obd *lov = &obd->u.lov;
74 mutex_down(&lov->lov_lock);
75 /* ok to dec to 0 more than once -- ltd_exp's will be null */
76 if (atomic_dec_and_test(&lov->lov_refcount) && lov->lov_death_row) {
78 CDEBUG(D_CONFIG, "destroying %d lov targets\n",
80 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
81 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_reap)
83 /* Disconnect and delete from list */
84 __lov_del_obd(obd, i);
88 mutex_up(&lov->lov_lock);
91 static int lov_register_page_removal_cb(struct obd_export *exp,
92 obd_page_removal_cb_t func,
93 obd_pin_extent_cb pin_cb)
95 struct lov_obd *lov = &exp->exp_obd->u.lov;
98 if (lov->lov_page_removal_cb && lov->lov_page_removal_cb != func)
101 if (lov->lov_page_pin_cb && lov->lov_page_pin_cb != pin_cb)
104 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
105 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
107 rc |= obd_register_page_removal_cb(lov->lov_tgts[i]->ltd_exp,
111 lov->lov_page_removal_cb = func;
112 lov->lov_page_pin_cb = pin_cb;
117 static int lov_unregister_page_removal_cb(struct obd_export *exp,
118 obd_page_removal_cb_t func)
120 struct lov_obd *lov = &exp->exp_obd->u.lov;
123 if (lov->lov_page_removal_cb && lov->lov_page_removal_cb != func)
126 lov->lov_page_removal_cb = NULL;
127 lov->lov_page_pin_cb = NULL;
129 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
130 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
132 rc |= obd_unregister_page_removal_cb(lov->lov_tgts[i]->ltd_exp,
139 static int lov_register_lock_cancel_cb(struct obd_export *exp,
140 obd_lock_cancel_cb func)
142 struct lov_obd *lov = &exp->exp_obd->u.lov;
145 if (lov->lov_lock_cancel_cb && lov->lov_lock_cancel_cb != func)
148 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
149 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
151 rc |= obd_register_lock_cancel_cb(lov->lov_tgts[i]->ltd_exp,
155 lov->lov_lock_cancel_cb = func;
160 static int lov_unregister_lock_cancel_cb(struct obd_export *exp,
161 obd_lock_cancel_cb func)
163 struct lov_obd *lov = &exp->exp_obd->u.lov;
166 if (lov->lov_lock_cancel_cb && lov->lov_lock_cancel_cb != func)
169 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
170 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
172 rc |= obd_unregister_lock_cancel_cb(lov->lov_tgts[i]->ltd_exp,
175 lov->lov_lock_cancel_cb = NULL;
179 #define MAX_STRING_SIZE 128
180 static int lov_connect_obd(struct obd_device *obd, __u32 index, int activate,
181 struct obd_connect_data *data)
183 struct lov_obd *lov = &obd->u.lov;
184 struct obd_uuid tgt_uuid;
185 struct obd_device *tgt_obd;
186 struct obd_uuid lov_osc_uuid = { "LOV_OSC_UUID" };
187 struct lustre_handle conn = {0, };
188 struct obd_import *imp;
191 cfs_proc_dir_entry_t *lov_proc_dir;
196 if (!lov->lov_tgts[index])
199 tgt_uuid = lov->lov_tgts[index]->ltd_uuid;
201 tgt_obd = class_find_client_obd(&tgt_uuid, LUSTRE_OSC_NAME,
205 CERROR("Target %s not attached\n", obd_uuid2str(&tgt_uuid));
208 if (!tgt_obd->obd_set_up) {
209 CERROR("Target %s not set up\n", obd_uuid2str(&tgt_uuid));
213 if (data && (data->ocd_connect_flags & OBD_CONNECT_INDEX))
214 data->ocd_index = index;
217 * Divine LOV knows that OBDs under it are OSCs.
219 imp = tgt_obd->u.cli.cl_import;
222 tgt_obd->obd_no_recov = 0;
223 /* FIXME this is probably supposed to be
224 ptlrpc_set_import_active. Horrible naming. */
225 ptlrpc_activate_import(imp);
228 if (imp->imp_invalid) {
229 CERROR("not connecting OSC %s; administratively "
230 "disabled\n", obd_uuid2str(&tgt_uuid));
231 rc = obd_register_observer(tgt_obd, obd);
233 CERROR("Target %s register_observer error %d; "
234 "will not be able to reactivate\n",
235 obd_uuid2str(&tgt_uuid), rc);
240 rc = obd_connect(NULL, &conn, tgt_obd, &lov_osc_uuid, data, NULL);
242 CERROR("Target %s connect error %d\n",
243 obd_uuid2str(&tgt_uuid), rc);
246 lov->lov_tgts[index]->ltd_exp = class_conn2export(&conn);
247 if (!lov->lov_tgts[index]->ltd_exp) {
248 CERROR("Target %s: null export!\n", obd_uuid2str(&tgt_uuid));
252 rc = obd_register_page_removal_cb(lov->lov_tgts[index]->ltd_exp,
253 lov->lov_page_removal_cb,
254 lov->lov_page_pin_cb);
256 obd_disconnect(lov->lov_tgts[index]->ltd_exp);
257 lov->lov_tgts[index]->ltd_exp = NULL;
261 rc = obd_register_lock_cancel_cb(lov->lov_tgts[index]->ltd_exp,
262 lov->lov_lock_cancel_cb);
264 obd_unregister_page_removal_cb(lov->lov_tgts[index]->ltd_exp,
265 lov->lov_page_removal_cb);
266 obd_disconnect(lov->lov_tgts[index]->ltd_exp);
267 lov->lov_tgts[index]->ltd_exp = NULL;
271 rc = obd_register_observer(tgt_obd, obd);
273 CERROR("Target %s register_observer error %d\n",
274 obd_uuid2str(&tgt_uuid), rc);
275 obd_unregister_lock_cancel_cb(lov->lov_tgts[index]->ltd_exp,
276 lov->lov_lock_cancel_cb);
277 obd_unregister_page_removal_cb(lov->lov_tgts[index]->ltd_exp,
278 lov->lov_page_removal_cb);
279 obd_disconnect(lov->lov_tgts[index]->ltd_exp);
280 lov->lov_tgts[index]->ltd_exp = NULL;
284 lov->lov_tgts[index]->ltd_reap = 0;
286 lov->lov_tgts[index]->ltd_active = 1;
287 lov->desc.ld_active_tgt_count++;
288 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 0;
290 CDEBUG(D_CONFIG, "Connected tgt idx %d %s (%s) %sactive\n", index,
291 obd_uuid2str(&tgt_uuid), tgt_obd->obd_name, activate ? "":"in");
294 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
296 struct obd_device *osc_obd = class_conn2obd(&conn);
297 cfs_proc_dir_entry_t *osc_symlink;
298 char name[MAX_STRING_SIZE];
300 LASSERT(osc_obd != NULL);
301 LASSERT(osc_obd->obd_magic == OBD_DEVICE_MAGIC);
302 LASSERT(osc_obd->obd_type->typ_name != NULL);
303 snprintf(name, MAX_STRING_SIZE, "../../../%s/%s",
304 osc_obd->obd_type->typ_name,
306 osc_symlink = lprocfs_add_symlink(osc_obd->obd_name, lov_proc_dir,
308 if (osc_symlink == NULL) {
309 CERROR("could not register LOV target "
310 "/proc/fs/lustre/%s/%s/target_obds/%s.",
311 obd->obd_type->typ_name, obd->obd_name,
313 lprocfs_remove(&lov_proc_dir);
318 rc = qos_add_tgt(obd, index);
320 CERROR("qos_add_tgt failed %d\n", rc);
325 static int lov_connect(const struct lu_env *env,
326 struct lustre_handle *conn, struct obd_device *obd,
327 struct obd_uuid *cluuid, struct obd_connect_data *data,
330 struct lov_obd *lov = &obd->u.lov;
331 struct lov_tgt_desc *tgt;
335 CDEBUG(D_CONFIG, "connect #%d\n", lov->lov_connects);
337 rc = class_connect(conn, obd, cluuid);
341 /* Why should there ever be more than 1 connect? */
343 LASSERT(lov->lov_connects == 1);
345 memset(&lov->lov_ocd, 0, sizeof(lov->lov_ocd));
347 lov->lov_ocd = *data;
350 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
351 tgt = lov->lov_tgts[i];
352 if (!tgt || obd_uuid_empty(&tgt->ltd_uuid))
354 /* Flags will be lowest common denominator */
355 rc = lov_connect_obd(obd, i, tgt->ltd_activate, &lov->lov_ocd);
357 CERROR("%s: lov connect tgt %d failed: %d\n",
358 obd->obd_name, i, rc);
367 static int lov_disconnect_obd(struct obd_device *obd, __u32 index)
369 cfs_proc_dir_entry_t *lov_proc_dir;
370 struct lov_obd *lov = &obd->u.lov;
371 struct obd_device *osc_obd;
376 if (lov->lov_tgts[index] == NULL)
379 osc_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
380 CDEBUG(D_CONFIG, "%s: disconnecting target %s\n",
381 obd->obd_name, osc_obd->obd_name);
383 obd_unregister_lock_cancel_cb(lov->lov_tgts[index]->ltd_exp,
384 lov->lov_lock_cancel_cb);
385 obd_unregister_page_removal_cb(lov->lov_tgts[index]->ltd_exp,
386 lov->lov_page_removal_cb);
388 if (lov->lov_tgts[index]->ltd_active) {
389 lov->lov_tgts[index]->ltd_active = 0;
390 lov->desc.ld_active_tgt_count--;
391 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 1;
394 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
396 cfs_proc_dir_entry_t *osc_symlink;
398 osc_symlink = lprocfs_srch(lov_proc_dir, osc_obd->obd_name);
400 lprocfs_remove(&osc_symlink);
402 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing.",
403 obd->obd_type->typ_name, obd->obd_name,
409 /* Pass it on to our clients.
410 * XXX This should be an argument to disconnect,
411 * XXX not a back-door flag on the OBD. Ah well.
413 osc_obd->obd_force = obd->obd_force;
414 osc_obd->obd_fail = obd->obd_fail;
415 osc_obd->obd_no_recov = obd->obd_no_recov;
418 obd_register_observer(osc_obd, NULL);
420 rc = obd_disconnect(lov->lov_tgts[index]->ltd_exp);
422 CERROR("Target %s disconnect error %d\n",
423 lov_uuid2str(lov, index), rc);
427 qos_del_tgt(obd, index);
429 lov->lov_tgts[index]->ltd_exp = NULL;
433 static int lov_del_target(struct obd_device *obd, __u32 index,
434 struct obd_uuid *uuidp, int gen);
436 static int lov_disconnect(struct obd_export *exp)
438 struct obd_device *obd = class_exp2obd(exp);
439 struct lov_obd *lov = &obd->u.lov;
446 /* Only disconnect the underlying layers on the final disconnect. */
448 if (lov->lov_connects != 0) {
449 /* why should there be more than 1 connect? */
450 CERROR("disconnect #%d\n", lov->lov_connects);
454 /* Let's hold another reference so lov_del_obd doesn't spin through
457 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
458 if (lov->lov_tgts[i] && lov->lov_tgts[i]->ltd_exp) {
459 /* Disconnection is the last we know about an obd */
460 lov_del_target(obd, i, 0, lov->lov_tgts[i]->ltd_gen);
466 rc = class_disconnect(exp); /* bz 9811 */
472 * -EINVAL : UUID can't be found in the LOV's target list
473 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
474 * -EBADF : The UUID is found, but the OBD is the wrong type (!)
476 static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
479 struct lov_obd *lov = &obd->u.lov;
480 struct lov_tgt_desc *tgt;
484 CDEBUG(D_INFO, "Searching in lov %p for uuid %s (activate=%d)\n",
485 lov, uuid->uuid, activate);
488 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
489 tgt = lov->lov_tgts[i];
490 if (!tgt || !tgt->ltd_exp)
493 CDEBUG(D_INFO, "lov idx %d is %s conn "LPX64"\n",
494 i, obd_uuid2str(&tgt->ltd_uuid),
495 tgt->ltd_exp->exp_handle.h_cookie);
496 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
500 if (i == lov->desc.ld_tgt_count)
501 GOTO(out, rc = -EINVAL);
503 if (lov->lov_tgts[i]->ltd_active == activate) {
504 CDEBUG(D_INFO, "OSC %s already %sactive!\n", uuid->uuid,
505 activate ? "" : "in");
509 CDEBUG(D_CONFIG, "Marking OSC %s %sactive\n", obd_uuid2str(uuid),
510 activate ? "" : "in");
512 lov->lov_tgts[i]->ltd_active = activate;
515 lov->desc.ld_active_tgt_count++;
516 lov->lov_tgts[i]->ltd_exp->exp_obd->obd_inactive = 0;
518 lov->desc.ld_active_tgt_count--;
519 lov->lov_tgts[i]->ltd_exp->exp_obd->obd_inactive = 1;
521 /* remove any old qos penalty */
522 lov->lov_tgts[i]->ltd_qos.ltq_penalty = 0;
529 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
530 enum obd_notify_event ev, void *data)
535 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
536 struct obd_uuid *uuid;
540 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
541 CERROR("unexpected notification of %s %s!\n",
542 watched->obd_type->typ_name,
546 uuid = &watched->u.cli.cl_target_uuid;
548 /* Set OSC as active before notifying the observer, so the
549 * observer can use the OSC normally.
551 rc = lov_set_osc_active(obd, uuid, ev == OBD_NOTIFY_ACTIVE);
553 CERROR("%sactivation of %s failed: %d\n",
554 (ev == OBD_NOTIFY_ACTIVE) ? "" : "de",
555 obd_uuid2str(uuid), rc);
560 /* Pass the notification up the chain. */
562 rc = obd_notify_observer(obd, watched, ev, data);
564 /* NULL watched means all osc's in the lov (only for syncs) */
565 struct lov_obd *lov = &obd->u.lov;
566 struct obd_device *tgt_obd;
569 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
570 if (!lov->lov_tgts[i])
572 tgt_obd = class_exp2obd(lov->lov_tgts[i]->ltd_exp);
573 rc = obd_notify_observer(obd, tgt_obd, ev, data);
575 CERROR("%s: notify %s of %s failed %d\n",
577 obd->obd_observer->obd_name,
578 tgt_obd->obd_name, rc);
588 static int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
589 __u32 index, int gen, int active)
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",
605 mutex_down(&lov->lov_lock);
607 if ((index < lov->lov_tgt_size) && (lov->lov_tgts[index] != NULL)) {
608 tgt = lov->lov_tgts[index];
609 CERROR("UUID %s already assigned at LOV target index %d\n",
610 obd_uuid2str(&tgt->ltd_uuid), index);
611 mutex_up(&lov->lov_lock);
615 if (index >= lov->lov_tgt_size) {
616 /* We need to reallocate the lov target array. */
617 struct lov_tgt_desc **newtgts, **old = NULL;
618 __u32 newsize, oldsize = 0;
620 newsize = max(lov->lov_tgt_size, (__u32)2);
621 while (newsize < index + 1)
622 newsize = newsize << 1;
623 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
624 if (newtgts == NULL) {
625 mutex_up(&lov->lov_lock);
629 if (lov->lov_tgt_size) {
630 memcpy(newtgts, lov->lov_tgts, sizeof(*newtgts) *
633 oldsize = lov->lov_tgt_size;
636 lov->lov_tgts = newtgts;
637 lov->lov_tgt_size = newsize;
642 OBD_FREE(old, sizeof(*old) * oldsize);
644 CDEBUG(D_CONFIG, "tgts: %p size: %d\n",
645 lov->lov_tgts, lov->lov_tgt_size);
651 mutex_up(&lov->lov_lock);
655 memset(tgt, 0, sizeof(*tgt));
656 tgt->ltd_uuid = *uuidp;
657 /* XXX - add a sanity check on the generation number. */
659 tgt->ltd_index = index;
660 tgt->ltd_activate = active;
661 lov->lov_tgts[index] = tgt;
662 if (index >= lov->desc.ld_tgt_count)
663 lov->desc.ld_tgt_count = index + 1;
664 mutex_up(&lov->lov_lock);
666 CDEBUG(D_CONFIG, "idx=%d ltd_gen=%d ld_tgt_count=%d\n",
667 index, tgt->ltd_gen, lov->desc.ld_tgt_count);
669 if (lov->lov_connects == 0) {
670 /* lov_connect hasn't been called yet. We'll do the
671 lov_connect_obd on this target when that fn first runs,
672 because we don't know the connect flags yet. */
678 rc = lov_connect_obd(obd, index, active, &lov->lov_ocd);
682 rc = lov_notify(obd, tgt->ltd_exp->exp_obd,
683 active ? OBD_NOTIFY_ACTIVE : OBD_NOTIFY_INACTIVE,
688 CERROR("add failed (%d), deleting %s\n", rc,
689 obd_uuid2str(&tgt->ltd_uuid));
690 lov_del_target(obd, index, 0, 0);
696 /* Schedule a target for deletion */
697 static int lov_del_target(struct obd_device *obd, __u32 index,
698 struct obd_uuid *uuidp, int gen)
700 struct lov_obd *lov = &obd->u.lov;
701 int count = lov->desc.ld_tgt_count;
705 if (index >= count) {
706 CERROR("LOV target index %d >= number of LOV OBDs %d.\n",
713 if (!lov->lov_tgts[index]) {
714 CERROR("LOV target at index %d is not setup.\n", index);
715 GOTO(out, rc = -EINVAL);
718 if (uuidp && !obd_uuid_equals(uuidp, &lov->lov_tgts[index]->ltd_uuid)) {
719 CERROR("LOV target UUID %s at index %d doesn't match %s.\n",
720 lov_uuid2str(lov, index), index,
721 obd_uuid2str(uuidp));
722 GOTO(out, rc = -EINVAL);
725 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d exp: %p active: %d\n",
726 lov_uuid2str(lov, index), index,
727 lov->lov_tgts[index]->ltd_gen, lov->lov_tgts[index]->ltd_exp,
728 lov->lov_tgts[index]->ltd_active);
730 lov->lov_tgts[index]->ltd_reap = 1;
731 lov->lov_death_row++;
732 /* we really delete it from lov_putref */
739 /* We are holding lov_lock */
740 static void __lov_del_obd(struct obd_device *obd, __u32 index)
742 struct lov_obd *lov = &obd->u.lov;
743 struct obd_device *osc_obd;
744 struct lov_tgt_desc *tgt = lov->lov_tgts[index];
747 LASSERT(tgt->ltd_reap);
749 osc_obd = class_exp2obd(tgt->ltd_exp);
751 CDEBUG(D_CONFIG, "Removing tgt %s : %s\n",
752 lov_uuid2str(lov, index),
753 osc_obd ? osc_obd->obd_name : "<no obd>");
756 lov_disconnect_obd(obd, index);
758 /* XXX - right now there is a dependency on ld_tgt_count being the
759 * maximum tgt index for computing the mds_max_easize. So we can't
762 lov->lov_tgts[index] = NULL;
765 /* Manual cleanup - no cleanup logs to clean up the osc's. We must
766 do it ourselves. And we can't do it from lov_cleanup,
767 because we just lost our only reference to it. */
769 class_manual_cleanup(osc_obd);
772 void lov_fix_desc_stripe_size(__u64 *val)
774 if (*val < PTLRPC_MAX_BRW_SIZE) {
775 LCONSOLE_WARN("Increasing default stripe size to min %u\n",
776 PTLRPC_MAX_BRW_SIZE);
777 *val = PTLRPC_MAX_BRW_SIZE;
778 } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) {
779 *val &= ~(LOV_MIN_STRIPE_SIZE - 1);
780 LCONSOLE_WARN("Changing default stripe size to "LPU64" (a "
782 *val, LOV_MIN_STRIPE_SIZE);
786 void lov_fix_desc_stripe_count(__u32 *val)
792 void lov_fix_desc_pattern(__u32 *val)
794 /* from lov_setstripe */
795 if ((*val != 0) && (*val != LOV_PATTERN_RAID0)) {
796 LCONSOLE_WARN("Unknown stripe pattern: %#x\n", *val);
801 void lov_fix_desc_qos_maxage(__u32 *val)
805 *val = QOS_DEFAULT_MAXAGE;
808 void lov_fix_desc(struct lov_desc *desc)
810 lov_fix_desc_stripe_size(&desc->ld_default_stripe_size);
811 lov_fix_desc_stripe_count(&desc->ld_default_stripe_count);
812 lov_fix_desc_pattern(&desc->ld_pattern);
813 lov_fix_desc_qos_maxage(&desc->ld_qos_maxage);
816 static int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
818 struct lprocfs_static_vars lvars = { 0 };
819 struct lov_desc *desc;
820 struct lov_obd *lov = &obd->u.lov;
824 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
825 CERROR("LOV setup requires a descriptor\n");
829 desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
831 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
832 CERROR("descriptor size wrong: %d > %d\n",
833 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
837 if (desc->ld_magic != LOV_DESC_MAGIC) {
838 if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
839 CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n",
840 obd->obd_name, desc);
841 lustre_swab_lov_desc(desc);
843 CERROR("%s: Bad lov desc magic: %#x\n",
844 obd->obd_name, desc->ld_magic);
851 /* Because of 64-bit divide/mod operations only work with a 32-bit
852 * divisor in a 32-bit kernel, we cannot support a stripe width
853 * of 4GB or larger on 32-bit CPUs. */
854 count = desc->ld_default_stripe_count;
855 if ((count > 0 ? count : desc->ld_tgt_count) *
856 desc->ld_default_stripe_size > 0xffffffff) {
857 CERROR("LOV: stripe width "LPU64"x%u > 4294967295 bytes\n",
858 desc->ld_default_stripe_size, count);
862 desc->ld_active_tgt_count = 0;
864 lov->lov_tgt_size = 0;
865 sema_init(&lov->lov_lock, 1);
866 atomic_set(&lov->lov_refcount, 0);
867 CFS_INIT_LIST_HEAD(&lov->lov_qos.lq_oss_list);
868 init_rwsem(&lov->lov_qos.lq_rw_sem);
869 lov->lov_qos.lq_dirty = 1;
870 lov->lov_qos.lq_dirty_rr = 1;
871 lov->lov_qos.lq_reset = 1;
872 /* Default priority is toward free space balance */
873 lov->lov_qos.lq_prio_free = 232;
875 lprocfs_lov_init_vars(&lvars);
876 lprocfs_obd_setup(obd, lvars.obd_vars);
881 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
882 0444, &lov_proc_target_fops, obd);
884 CWARN("Error adding the target_obd file\n");
891 static int lov_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
897 case OBD_CLEANUP_EARLY: {
898 struct lov_obd *lov = &obd->u.lov;
900 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
901 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
903 obd_precleanup(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
908 case OBD_CLEANUP_EXPORTS:
910 case OBD_CLEANUP_SELF_EXP:
911 rc = obd_llog_finish(obd, 0);
913 CERROR("failed to cleanup llogging subsystems\n");
915 case OBD_CLEANUP_OBD:
921 static int lov_cleanup(struct obd_device *obd)
923 struct lov_obd *lov = &obd->u.lov;
925 lprocfs_obd_cleanup(obd);
928 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
929 if (!lov->lov_tgts[i])
932 /* Inactive targets may never have connected */
933 if (lov->lov_tgts[i]->ltd_active ||
934 atomic_read(&lov->lov_refcount))
935 /* We should never get here - these
936 should have been removed in the
938 CERROR("lov tgt %d not cleaned!"
939 " deathrow=%d, lovrc=%d\n",
940 i, lov->lov_death_row,
941 atomic_read(&lov->lov_refcount));
942 lov_del_target(obd, i, 0, 0);
944 OBD_FREE(lov->lov_tgts, sizeof(*lov->lov_tgts) *
946 lov->lov_tgt_size = 0;
949 if (lov->lov_qos.lq_rr_size)
950 OBD_FREE(lov->lov_qos.lq_rr_array, lov->lov_qos.lq_rr_size);
955 static int lov_process_config(struct obd_device *obd, obd_count len, void *buf)
957 struct lustre_cfg *lcfg = buf;
958 struct obd_uuid obd_uuid;
963 switch(cmd = lcfg->lcfg_command) {
964 case LCFG_LOV_ADD_OBD:
965 case LCFG_LOV_ADD_INA:
966 case LCFG_LOV_DEL_OBD: {
969 /* lov_modify_tgts add 0:lov_mdsA 1:ost1_UUID 2:0 3:1 */
970 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
971 GOTO(out, rc = -EINVAL);
973 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
975 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
976 GOTO(out, rc = -EINVAL);
977 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
978 GOTO(out, rc = -EINVAL);
979 if (cmd == LCFG_LOV_ADD_OBD)
980 rc = lov_add_target(obd, &obd_uuid, index, gen, 1);
981 else if (cmd == LCFG_LOV_ADD_INA)
982 rc = lov_add_target(obd, &obd_uuid, index, gen, 0);
984 rc = lov_del_target(obd, index, &obd_uuid, gen);
988 struct lprocfs_static_vars lvars = { 0 };
989 struct lov_desc *desc = &(obd->u.lov.desc);
992 GOTO(out, rc = -EINVAL);
994 lprocfs_lov_init_vars(&lvars);
996 rc = class_process_proc_param(PARAM_LOV, lvars.obd_vars,
1001 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1002 GOTO(out, rc = -EINVAL);
1011 #define log2(n) ffz(~(n))
1014 static int lov_clear_orphans(struct obd_export *export, struct obdo *src_oa,
1015 struct lov_stripe_md **ea,
1016 struct obd_trans_info *oti)
1018 struct lov_obd *lov;
1019 struct obdo *tmp_oa;
1020 struct obd_uuid *ost_uuid = NULL;
1024 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
1025 src_oa->o_flags == OBD_FL_DELORPHAN);
1027 lov = &export->exp_obd->u.lov;
1033 if (src_oa->o_valid & OBD_MD_FLINLINE) {
1034 ost_uuid = (struct obd_uuid *)src_oa->o_inline;
1035 CDEBUG(D_HA, "clearing orphans only for %s\n",
1039 lov_getref(export->exp_obd);
1040 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1041 struct lov_stripe_md obj_md;
1042 struct lov_stripe_md *obj_mdp = &obj_md;
1043 struct lov_tgt_desc *tgt;
1046 tgt = lov->lov_tgts[i];
1050 /* if called for a specific target, we don't
1051 care if it is not active. */
1052 if (!lov->lov_tgts[i]->ltd_active && ost_uuid == NULL) {
1053 CDEBUG(D_HA, "lov idx %d inactive\n", i);
1057 if (ost_uuid && !obd_uuid_equals(ost_uuid, &tgt->ltd_uuid))
1060 CDEBUG(D_CONFIG,"Clear orphans for %d:%s\n", i,
1061 obd_uuid2str(ost_uuid));
1063 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
1065 LASSERT(lov->lov_tgts[i]->ltd_exp);
1066 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1067 err = obd_create(lov->lov_tgts[i]->ltd_exp,
1068 tmp_oa, &obj_mdp, oti);
1070 /* This export will be disabled until it is recovered,
1071 and then orphan recovery will be completed. */
1072 CERROR("error in orphan recovery on OST idx %d/%d: "
1073 "rc = %d\n", i, lov->desc.ld_tgt_count, err);
1078 lov_putref(export->exp_obd);
1084 static int lov_recreate(struct obd_export *exp, struct obdo *src_oa,
1085 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1087 struct lov_stripe_md *obj_mdp, *lsm;
1088 struct lov_obd *lov = &exp->exp_obd->u.lov;
1093 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
1094 src_oa->o_flags & OBD_FL_RECREATE_OBJS);
1096 OBD_ALLOC(obj_mdp, sizeof(*obj_mdp));
1097 if (obj_mdp == NULL)
1100 ost_idx = src_oa->o_nlink;
1103 GOTO(out, rc = -EINVAL);
1104 if (ost_idx >= lov->desc.ld_tgt_count ||
1105 !lov->lov_tgts[ost_idx])
1106 GOTO(out, rc = -EINVAL);
1108 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1109 if (lsm->lsm_oinfo[i]->loi_ost_idx == ost_idx) {
1110 if (lsm->lsm_oinfo[i]->loi_id != src_oa->o_id)
1111 GOTO(out, rc = -EINVAL);
1115 if (i == lsm->lsm_stripe_count)
1116 GOTO(out, rc = -EINVAL);
1118 rc = obd_create(lov->lov_tgts[ost_idx]->ltd_exp, src_oa, &obj_mdp, oti);
1120 OBD_FREE(obj_mdp, sizeof(*obj_mdp));
1124 /* the LOV expects oa->o_id to be set to the LOV object id */
1125 static int lov_create(struct obd_export *exp, struct obdo *src_oa,
1126 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1128 struct lov_obd *lov;
1129 struct obd_info oinfo;
1130 struct lov_request_set *set = NULL;
1131 struct lov_request *req;
1132 struct obd_statfs osfs;
1137 LASSERT(ea != NULL);
1141 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1142 src_oa->o_flags == OBD_FL_DELORPHAN) {
1143 rc = lov_clear_orphans(exp, src_oa, ea, oti);
1147 lov = &exp->exp_obd->u.lov;
1148 if (!lov->desc.ld_active_tgt_count)
1151 /* Recreate a specific object id at the given OST index */
1152 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1153 (src_oa->o_flags & OBD_FL_RECREATE_OBJS)) {
1154 rc = lov_recreate(exp, src_oa, ea, oti);
1158 maxage = cfs_time_shift_64(-lov->desc.ld_qos_maxage);
1159 obd_statfs_rqset(exp->exp_obd, &osfs, maxage, OBD_STATFS_NODELAY);
1161 rc = lov_prep_create_set(exp, &oinfo, ea, src_oa, oti, &set);
1165 list_for_each_entry(req, &set->set_list, rq_link) {
1166 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1167 rc = obd_create(lov->lov_tgts[req->rq_idx]->ltd_exp,
1168 req->rq_oi.oi_oa, &req->rq_oi.oi_md, oti);
1169 lov_update_create_set(set, req, rc);
1171 rc = lov_fini_create_set(set, ea);
1175 #define ASSERT_LSM_MAGIC(lsmp) \
1177 LASSERT((lsmp) != NULL); \
1178 LASSERTF(((lsmp)->lsm_magic == LOV_MAGIC || \
1179 (lsmp)->lsm_magic == LOV_MAGIC_JOIN), "%p->lsm_magic=%x\n", \
1180 (lsmp), (lsmp)->lsm_magic); \
1183 static int lov_destroy(struct obd_export *exp, struct obdo *oa,
1184 struct lov_stripe_md *lsm, struct obd_trans_info *oti,
1185 struct obd_export *md_exp)
1187 struct lov_request_set *set;
1188 struct obd_info oinfo;
1189 struct lov_request *req;
1190 struct list_head *pos;
1191 struct lov_obd *lov;
1195 ASSERT_LSM_MAGIC(lsm);
1197 if (!exp || !exp->exp_obd)
1200 if (oa->o_valid & OBD_MD_FLCOOKIE) {
1202 LASSERT(oti->oti_logcookies);
1205 lov = &exp->exp_obd->u.lov;
1206 rc = lov_prep_destroy_set(exp, &oinfo, oa, lsm, oti, &set);
1210 list_for_each (pos, &set->set_list) {
1212 req = list_entry(pos, struct lov_request, rq_link);
1214 if (oa->o_valid & OBD_MD_FLCOOKIE)
1215 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1217 err = obd_destroy(lov->lov_tgts[req->rq_idx]->ltd_exp,
1218 req->rq_oi.oi_oa, NULL, oti, NULL);
1219 err = lov_update_common_set(set, req, err);
1221 CERROR("error: destroying objid "LPX64" subobj "
1222 LPX64" on OST idx %d: rc = %d\n",
1223 oa->o_id, req->rq_oi.oi_oa->o_id,
1231 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
1232 rc = lsm_op_find(lsm->lsm_magic)->lsm_destroy(lsm, oa, md_exp);
1234 err = lov_fini_destroy_set(set);
1235 RETURN(rc ? rc : err);
1238 static int lov_getattr(struct obd_export *exp, struct obd_info *oinfo)
1240 struct lov_request_set *set;
1241 struct lov_request *req;
1242 struct list_head *pos;
1243 struct lov_obd *lov;
1244 int err = 0, rc = 0;
1248 ASSERT_LSM_MAGIC(oinfo->oi_md);
1250 if (!exp || !exp->exp_obd)
1253 lov = &exp->exp_obd->u.lov;
1255 rc = lov_prep_getattr_set(exp, oinfo, &set);
1259 list_for_each (pos, &set->set_list) {
1260 req = list_entry(pos, struct lov_request, rq_link);
1262 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1263 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1264 req->rq_oi.oi_oa->o_id, req->rq_idx);
1266 rc = obd_getattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1268 err = lov_update_common_set(set, req, rc);
1270 CERROR("error: getattr objid "LPX64" subobj "
1271 LPX64" on OST idx %d: rc = %d\n",
1272 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1278 rc = lov_fini_getattr_set(set);
1284 static int lov_getattr_interpret(struct ptlrpc_request_set *rqset,
1287 struct lov_request_set *lovset = (struct lov_request_set *)data;
1291 /* don't do attribute merge if this aysnc op failed */
1293 lovset->set_completes = 0;
1294 err = lov_fini_getattr_set(lovset);
1295 RETURN(rc ? rc : err);
1298 static int lov_getattr_async(struct obd_export *exp, struct obd_info *oinfo,
1299 struct ptlrpc_request_set *rqset)
1301 struct lov_request_set *lovset;
1302 struct lov_obd *lov;
1303 struct list_head *pos;
1304 struct lov_request *req;
1309 ASSERT_LSM_MAGIC(oinfo->oi_md);
1311 if (!exp || !exp->exp_obd)
1314 lov = &exp->exp_obd->u.lov;
1316 rc = lov_prep_getattr_set(exp, oinfo, &lovset);
1320 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1321 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1322 oinfo->oi_md->lsm_stripe_size);
1324 list_for_each (pos, &lovset->set_list) {
1325 req = list_entry(pos, struct lov_request, rq_link);
1327 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1328 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1329 req->rq_oi.oi_oa->o_id, req->rq_idx);
1330 rc = obd_getattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1331 &req->rq_oi, rqset);
1333 CERROR("error: getattr objid "LPX64" subobj "
1334 LPX64" on OST idx %d: rc = %d\n",
1335 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1341 if (!list_empty(&rqset->set_requests)) {
1343 LASSERT (rqset->set_interpret == NULL);
1344 rqset->set_interpret = lov_getattr_interpret;
1345 rqset->set_arg = (void *)lovset;
1350 lovset->set_completes = 0;
1351 err = lov_fini_getattr_set(lovset);
1352 RETURN(rc ? rc : err);
1355 static int lov_setattr(struct obd_export *exp, struct obd_info *oinfo,
1356 struct obd_trans_info *oti)
1358 struct lov_request_set *set;
1359 struct lov_obd *lov;
1360 struct list_head *pos;
1361 struct lov_request *req;
1362 int err = 0, rc = 0;
1366 ASSERT_LSM_MAGIC(oinfo->oi_md);
1368 if (!exp || !exp->exp_obd)
1371 /* for now, we only expect the following updates here */
1372 LASSERT(!(oinfo->oi_oa->o_valid & ~(OBD_MD_FLID | OBD_MD_FLTYPE |
1373 OBD_MD_FLMODE | OBD_MD_FLATIME |
1374 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1375 OBD_MD_FLFLAGS | OBD_MD_FLSIZE |
1376 OBD_MD_FLGROUP | OBD_MD_FLUID |
1377 OBD_MD_FLGID | OBD_MD_FLINLINE |
1378 OBD_MD_FLFID | OBD_MD_FLGENER)));
1379 lov = &exp->exp_obd->u.lov;
1380 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1384 list_for_each (pos, &set->set_list) {
1385 req = list_entry(pos, struct lov_request, rq_link);
1387 rc = obd_setattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1389 err = lov_update_setattr_set(set, req, rc);
1391 CERROR("error: setattr objid "LPX64" subobj "
1392 LPX64" on OST idx %d: rc = %d\n",
1393 set->set_oi->oi_oa->o_id,
1394 req->rq_oi.oi_oa->o_id, req->rq_idx, err);
1399 err = lov_fini_setattr_set(set);
1405 static int lov_setattr_interpret(struct ptlrpc_request_set *rqset,
1408 struct lov_request_set *lovset = (struct lov_request_set *)data;
1413 lovset->set_completes = 0;
1414 err = lov_fini_setattr_set(lovset);
1415 RETURN(rc ? rc : err);
1418 /* If @oti is given, the request goes from MDS and responses from OSTs are not
1419 needed. Otherwise, a client is waiting for responses. */
1420 static int lov_setattr_async(struct obd_export *exp, struct obd_info *oinfo,
1421 struct obd_trans_info *oti,
1422 struct ptlrpc_request_set *rqset)
1424 struct lov_request_set *set;
1425 struct lov_request *req;
1426 struct list_head *pos;
1427 struct lov_obd *lov;
1432 ASSERT_LSM_MAGIC(oinfo->oi_md);
1433 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE) {
1435 LASSERT(oti->oti_logcookies);
1438 if (!exp || !exp->exp_obd)
1441 lov = &exp->exp_obd->u.lov;
1442 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1446 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1447 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1448 oinfo->oi_md->lsm_stripe_size);
1450 list_for_each (pos, &set->set_list) {
1451 req = list_entry(pos, struct lov_request, rq_link);
1453 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
1454 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1456 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1457 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1458 req->rq_oi.oi_oa->o_id, req->rq_idx);
1460 rc = obd_setattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1461 &req->rq_oi, oti, rqset);
1463 CERROR("error: setattr objid "LPX64" subobj "
1464 LPX64" on OST idx %d: rc = %d\n",
1465 set->set_oi->oi_oa->o_id,
1466 req->rq_oi.oi_oa->o_id,
1472 /* If we are not waiting for responses on async requests, return. */
1473 if (rc || !rqset || list_empty(&rqset->set_requests)) {
1476 set->set_completes = 0;
1477 err = lov_fini_setattr_set(set);
1478 RETURN(rc ? rc : err);
1481 LASSERT(rqset->set_interpret == NULL);
1482 rqset->set_interpret = lov_setattr_interpret;
1483 rqset->set_arg = (void *)set;
1488 static int lov_punch_interpret(struct ptlrpc_request_set *rqset,
1491 struct lov_request_set *lovset = (struct lov_request_set *)data;
1496 lovset->set_completes = 0;
1497 err = lov_fini_punch_set(lovset);
1498 RETURN(rc ? rc : err);
1501 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
1502 * we can send this 'punch' to just the authoritative node and the nodes
1503 * that the punch will affect. */
1504 static int lov_punch(struct obd_export *exp, struct obd_info *oinfo,
1505 struct obd_trans_info *oti,
1506 struct ptlrpc_request_set *rqset)
1508 struct lov_request_set *set;
1509 struct lov_obd *lov;
1510 struct list_head *pos;
1511 struct lov_request *req;
1516 ASSERT_LSM_MAGIC(oinfo->oi_md);
1518 if (!exp || !exp->exp_obd)
1521 lov = &exp->exp_obd->u.lov;
1522 rc = lov_prep_punch_set(exp, oinfo, oti, &set);
1526 list_for_each (pos, &set->set_list) {
1527 req = list_entry(pos, struct lov_request, rq_link);
1529 rc = obd_punch(lov->lov_tgts[req->rq_idx]->ltd_exp,
1530 &req->rq_oi, NULL, rqset);
1532 CERROR("error: punch objid "LPX64" subobj "LPX64
1533 " on OST idx %d: rc = %d\n",
1534 set->set_oi->oi_oa->o_id,
1535 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1540 if (rc || list_empty(&rqset->set_requests)) {
1542 err = lov_fini_punch_set(set);
1543 RETURN(rc ? rc : err);
1546 LASSERT(rqset->set_interpret == NULL);
1547 rqset->set_interpret = lov_punch_interpret;
1548 rqset->set_arg = (void *)set;
1553 static int lov_sync(struct obd_export *exp, struct obdo *oa,
1554 struct lov_stripe_md *lsm, obd_off start, obd_off end,
1557 struct lov_request_set *set;
1558 struct obd_info oinfo;
1559 struct lov_obd *lov;
1560 struct list_head *pos;
1561 struct lov_request *req;
1562 int err = 0, rc = 0;
1565 ASSERT_LSM_MAGIC(lsm);
1570 lov = &exp->exp_obd->u.lov;
1571 rc = lov_prep_sync_set(exp, &oinfo, oa, lsm, start, end, &set);
1575 list_for_each (pos, &set->set_list) {
1576 req = list_entry(pos, struct lov_request, rq_link);
1578 rc = obd_sync(lov->lov_tgts[req->rq_idx]->ltd_exp,
1579 req->rq_oi.oi_oa, NULL,
1580 req->rq_oi.oi_policy.l_extent.start,
1581 req->rq_oi.oi_policy.l_extent.end, capa);
1582 err = lov_update_common_set(set, req, rc);
1584 CERROR("error: fsync objid "LPX64" subobj "LPX64
1585 " on OST idx %d: rc = %d\n",
1586 set->set_oi->oi_oa->o_id,
1587 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1592 err = lov_fini_sync_set(set);
1598 static int lov_brw_check(struct lov_obd *lov, struct obd_info *lov_oinfo,
1599 obd_count oa_bufs, struct brw_page *pga)
1601 struct obd_info oinfo = { { { 0 } } };
1604 oinfo.oi_oa = lov_oinfo->oi_oa;
1606 /* The caller just wants to know if there's a chance that this
1607 * I/O can succeed */
1608 for (i = 0; i < oa_bufs; i++) {
1609 int stripe = lov_stripe_number(lov_oinfo->oi_md, pga[i].off);
1610 int ost = lov_oinfo->oi_md->lsm_oinfo[stripe]->loi_ost_idx;
1613 if (!lov_stripe_intersects(lov_oinfo->oi_md, i, pga[i].off,
1614 pga[i].off + pga[i].count,
1618 if (!lov->lov_tgts[ost] || !lov->lov_tgts[ost]->ltd_active) {
1619 CDEBUG(D_HA, "lov idx %d inactive\n", ost);
1623 rc = obd_brw(OBD_BRW_CHECK, lov->lov_tgts[ost]->ltd_exp, &oinfo,
1631 static int lov_brw(int cmd, struct obd_export *exp, struct obd_info *oinfo,
1632 obd_count oa_bufs, struct brw_page *pga,
1633 struct obd_trans_info *oti)
1635 struct lov_request_set *set;
1636 struct lov_request *req;
1637 struct list_head *pos;
1638 struct lov_obd *lov = &exp->exp_obd->u.lov;
1642 ASSERT_LSM_MAGIC(oinfo->oi_md);
1644 if (cmd == OBD_BRW_CHECK) {
1645 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1649 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &set);
1653 list_for_each (pos, &set->set_list) {
1654 struct obd_export *sub_exp;
1655 struct brw_page *sub_pga;
1656 req = list_entry(pos, struct lov_request, rq_link);
1658 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1659 sub_pga = set->set_pga + req->rq_pgaidx;
1660 rc = obd_brw(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1664 lov_update_common_set(set, req, rc);
1667 err = lov_fini_brw_set(set);
1673 static int lov_brw_interpret(struct ptlrpc_request_set *reqset, void *data,
1676 struct lov_request_set *lovset = (struct lov_request_set *)data;
1680 lovset->set_completes = 0;
1681 lov_fini_brw_set(lovset);
1683 rc = lov_fini_brw_set(lovset);
1689 static int lov_brw_async(int cmd, struct obd_export *exp,
1690 struct obd_info *oinfo, obd_count oa_bufs,
1691 struct brw_page *pga, struct obd_trans_info *oti,
1692 struct ptlrpc_request_set *set)
1694 struct lov_request_set *lovset;
1695 struct lov_request *req;
1696 struct list_head *pos;
1697 struct lov_obd *lov = &exp->exp_obd->u.lov;
1702 ASSERT_LSM_MAGIC(oinfo->oi_md);
1704 if (cmd == OBD_BRW_CHECK) {
1705 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1709 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &lovset);
1713 list_for_each (pos, &lovset->set_list) {
1714 struct obd_export *sub_exp;
1715 struct brw_page *sub_pga;
1716 req = list_entry(pos, struct lov_request, rq_link);
1718 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1719 sub_pga = lovset->set_pga + req->rq_pgaidx;
1720 rc = obd_brw_async(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1724 lov_update_common_set(lovset, req, rc);
1727 LASSERT(set->set_interpret == NULL);
1728 LASSERT(set->set_arg == NULL);
1729 rc = ptlrpc_set_add_cb(set, lov_brw_interpret, lovset);
1735 lov_fini_brw_set(lovset);
1739 static int lov_ap_make_ready(void *data, int cmd)
1741 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1743 return lap->lap_caller_ops->ap_make_ready(lap->lap_caller_data, cmd);
1746 static int lov_ap_refresh_count(void *data, int cmd)
1748 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1750 return lap->lap_caller_ops->ap_refresh_count(lap->lap_caller_data,
1754 static void lov_ap_fill_obdo(void *data, int cmd, struct obdo *oa)
1756 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1758 lap->lap_caller_ops->ap_fill_obdo(lap->lap_caller_data, cmd, oa);
1759 /* XXX woah, shouldn't we be altering more here? size? */
1760 oa->o_id = lap->lap_loi_id;
1761 oa->o_gr = lap->lap_loi_gr;
1762 oa->o_valid |= OBD_MD_FLGROUP;
1763 oa->o_stripe_idx = lap->lap_stripe;
1766 static void lov_ap_update_obdo(void *data, int cmd, struct obdo *oa,
1769 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1771 lap->lap_caller_ops->ap_update_obdo(lap->lap_caller_data, cmd,oa,valid);
1774 static int lov_ap_completion(void *data, int cmd, struct obdo *oa, int rc)
1776 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1778 /* in a raid1 regime this would down a count of many ios
1779 * in flight, onl calling the caller_ops completion when all
1780 * the raid1 ios are complete */
1781 rc = lap->lap_caller_ops->ap_completion(lap->lap_caller_data,cmd,oa,rc);
1785 static struct obd_capa *lov_ap_lookup_capa(void *data, int cmd)
1787 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1788 return lap->lap_caller_ops->ap_lookup_capa(lap->lap_caller_data, cmd);
1791 static struct obd_async_page_ops lov_async_page_ops = {
1792 .ap_make_ready = lov_ap_make_ready,
1793 .ap_refresh_count = lov_ap_refresh_count,
1794 .ap_fill_obdo = lov_ap_fill_obdo,
1795 .ap_update_obdo = lov_ap_update_obdo,
1796 .ap_completion = lov_ap_completion,
1797 .ap_lookup_capa = lov_ap_lookup_capa,
1800 int lov_prep_async_page(struct obd_export *exp, struct lov_stripe_md *lsm,
1801 struct lov_oinfo *loi, cfs_page_t *page,
1802 obd_off offset, struct obd_async_page_ops *ops,
1803 void *data, void **res, int nocache,
1804 struct lustre_handle *lockh)
1806 struct lov_obd *lov = &exp->exp_obd->u.lov;
1807 struct lov_async_page *lap;
1808 struct lov_lock_handles *lov_lockh = NULL;
1814 /* Find an existing osc so we can get it's stupid sizeof(*oap).
1815 Only because of this layering limitation will a client
1816 mount with no osts fail */
1817 while (!lov->lov_tgts || !lov->lov_tgts[i] ||
1818 !lov->lov_tgts[i]->ltd_exp) {
1820 if (i >= lov->desc.ld_tgt_count)
1823 rc = size_round(sizeof(*lap)) +
1824 obd_prep_async_page(lov->lov_tgts[i]->ltd_exp, NULL,
1825 NULL, NULL, 0, NULL, NULL, NULL, 0,
1829 ASSERT_LSM_MAGIC(lsm);
1830 LASSERT(loi == NULL);
1833 lap->lap_magic = LOV_AP_MAGIC;
1834 lap->lap_caller_ops = ops;
1835 lap->lap_caller_data = data;
1837 /* for now only raid 0 which passes through */
1838 lap->lap_stripe = lov_stripe_number(lsm, offset);
1839 lov_stripe_offset(lsm, offset, lap->lap_stripe, &lap->lap_sub_offset);
1840 loi = lsm->lsm_oinfo[lap->lap_stripe];
1842 /* so the callback doesn't need the lsm */
1843 lap->lap_loi_id = loi->loi_id;
1844 lap->lap_loi_gr = lsm->lsm_object_gr;
1845 LASSERT(lsm->lsm_object_gr > 0);
1847 lap->lap_sub_cookie = (void *)lap + size_round(sizeof(*lap));
1850 lov_lockh = lov_handle2llh(lockh);
1852 lockh = lov_lockh->llh_handles + lap->lap_stripe;
1856 rc = obd_prep_async_page(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1857 lsm, loi, page, lap->lap_sub_offset,
1858 &lov_async_page_ops, lap,
1859 &lap->lap_sub_cookie, nocache, lockh);
1861 lov_llh_put(lov_lockh);
1864 CDEBUG(D_CACHE, "lap %p page %p cookie %p off "LPU64"\n", lap, page,
1865 lap->lap_sub_cookie, offset);
1869 static int lov_queue_async_io(struct obd_export *exp,
1870 struct lov_stripe_md *lsm,
1871 struct lov_oinfo *loi, void *cookie,
1872 int cmd, obd_off off, int count,
1873 obd_flag brw_flags, obd_flag async_flags)
1875 struct lov_obd *lov = &exp->exp_obd->u.lov;
1876 struct lov_async_page *lap;
1879 LASSERT(loi == NULL);
1881 ASSERT_LSM_MAGIC(lsm);
1883 lap = LAP_FROM_COOKIE(cookie);
1885 loi = lsm->lsm_oinfo[lap->lap_stripe];
1887 rc = obd_queue_async_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp, lsm,
1888 loi, lap->lap_sub_cookie, cmd, off, count,
1889 brw_flags, async_flags);
1893 static int lov_set_async_flags(struct obd_export *exp,
1894 struct lov_stripe_md *lsm,
1895 struct lov_oinfo *loi, void *cookie,
1896 obd_flag async_flags)
1898 struct lov_obd *lov = &exp->exp_obd->u.lov;
1899 struct lov_async_page *lap;
1902 LASSERT(loi == NULL);
1904 ASSERT_LSM_MAGIC(lsm);
1906 lap = LAP_FROM_COOKIE(cookie);
1908 loi = lsm->lsm_oinfo[lap->lap_stripe];
1910 rc = obd_set_async_flags(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1911 lsm, loi, lap->lap_sub_cookie, async_flags);
1915 static int lov_queue_group_io(struct obd_export *exp,
1916 struct lov_stripe_md *lsm,
1917 struct lov_oinfo *loi,
1918 struct obd_io_group *oig, void *cookie,
1919 int cmd, obd_off off, int count,
1920 obd_flag brw_flags, obd_flag async_flags)
1922 struct lov_obd *lov = &exp->exp_obd->u.lov;
1923 struct lov_async_page *lap;
1926 LASSERT(loi == NULL);
1928 ASSERT_LSM_MAGIC(lsm);
1930 lap = LAP_FROM_COOKIE(cookie);
1932 loi = lsm->lsm_oinfo[lap->lap_stripe];
1934 rc = obd_queue_group_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp, lsm,
1935 loi, oig, lap->lap_sub_cookie, cmd, off, count,
1936 brw_flags, async_flags);
1940 /* this isn't exactly optimal. we may have queued sync io in oscs on
1941 * all stripes, but we don't record that fact at queue time. so we
1942 * trigger sync io on all stripes. */
1943 static int lov_trigger_group_io(struct obd_export *exp,
1944 struct lov_stripe_md *lsm,
1945 struct lov_oinfo *loi,
1946 struct obd_io_group *oig)
1948 struct lov_obd *lov = &exp->exp_obd->u.lov;
1951 LASSERT(loi == NULL);
1953 ASSERT_LSM_MAGIC(lsm);
1955 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1956 loi = lsm->lsm_oinfo[i];
1957 if (!lov->lov_tgts[loi->loi_ost_idx] ||
1958 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1959 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1963 err = obd_trigger_group_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1965 if (rc == 0 && err != 0)
1971 static int lov_teardown_async_page(struct obd_export *exp,
1972 struct lov_stripe_md *lsm,
1973 struct lov_oinfo *loi, void *cookie)
1975 struct lov_obd *lov = &exp->exp_obd->u.lov;
1976 struct lov_async_page *lap;
1979 LASSERT(loi == NULL);
1981 ASSERT_LSM_MAGIC(lsm);
1983 lap = LAP_FROM_COOKIE(cookie);
1985 loi = lsm->lsm_oinfo[lap->lap_stripe];
1987 rc = obd_teardown_async_page(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1988 lsm, loi, lap->lap_sub_cookie);
1990 CERROR("unable to teardown sub cookie %p: %d\n",
1991 lap->lap_sub_cookie, rc);
1997 static int lov_enqueue_interpret(struct ptlrpc_request_set *rqset,
2000 struct lov_request_set *lovset = (struct lov_request_set *)data;
2002 rc = lov_fini_enqueue_set(lovset, lovset->set_ei->ei_mode, rc, rqset);
2006 static int lov_enqueue(struct obd_export *exp, struct obd_info *oinfo,
2007 struct ldlm_enqueue_info *einfo,
2008 struct ptlrpc_request_set *rqset)
2010 ldlm_mode_t mode = einfo->ei_mode;
2011 struct lov_request_set *set;
2012 struct lov_request *req;
2013 struct list_head *pos;
2014 struct lov_obd *lov;
2019 ASSERT_LSM_MAGIC(oinfo->oi_md);
2020 LASSERT(mode == (mode & -mode));
2022 /* we should never be asked to replay a lock this way. */
2023 LASSERT((oinfo->oi_flags & LDLM_FL_REPLAY) == 0);
2025 if (!exp || !exp->exp_obd)
2028 lov = &exp->exp_obd->u.lov;
2029 rc = lov_prep_enqueue_set(exp, oinfo, einfo, &set);
2033 list_for_each (pos, &set->set_list) {
2034 req = list_entry(pos, struct lov_request, rq_link);
2036 rc = obd_enqueue(lov->lov_tgts[req->rq_idx]->ltd_exp,
2037 &req->rq_oi, einfo, rqset);
2042 if (rqset && !list_empty(&rqset->set_requests)) {
2044 LASSERT(rqset->set_interpret == NULL);
2045 rqset->set_interpret = lov_enqueue_interpret;
2046 rqset->set_arg = (void *)set;
2050 rc = lov_fini_enqueue_set(set, mode, rc, rqset);
2054 static int lov_match(struct obd_export *exp, struct lov_stripe_md *lsm,
2055 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
2056 int *flags, void *data, struct lustre_handle *lockh)
2058 struct lov_request_set *set;
2059 struct obd_info oinfo;
2060 struct lov_request *req;
2061 struct list_head *pos;
2062 struct lov_obd *lov = &exp->exp_obd->u.lov;
2063 struct lustre_handle *lov_lockhp;
2064 int lov_flags, rc = 0;
2067 ASSERT_LSM_MAGIC(lsm);
2068 LASSERT((*flags & LDLM_FL_TEST_LOCK) || mode == (mode & -mode));
2070 if (!exp || !exp->exp_obd)
2073 lov = &exp->exp_obd->u.lov;
2074 rc = lov_prep_match_set(exp, &oinfo, lsm, policy, mode, lockh, &set);
2078 list_for_each (pos, &set->set_list) {
2079 ldlm_policy_data_t sub_policy;
2080 req = list_entry(pos, struct lov_request, rq_link);
2081 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
2082 LASSERT(lov_lockhp);
2085 sub_policy.l_extent = req->rq_oi.oi_policy.l_extent;
2087 rc = obd_match(lov->lov_tgts[req->rq_idx]->ltd_exp,
2088 req->rq_oi.oi_md, type, &sub_policy,
2089 mode, &lov_flags, data, lov_lockhp);
2090 rc = lov_update_match_set(set, req, rc);
2094 lov_fini_match_set(set, mode, *flags);
2098 static int lov_change_cbdata(struct obd_export *exp,
2099 struct lov_stripe_md *lsm, ldlm_iterator_t it,
2102 struct lov_obd *lov;
2106 ASSERT_LSM_MAGIC(lsm);
2108 if (!exp || !exp->exp_obd)
2111 LASSERT(lsm->lsm_object_gr > 0);
2113 lov = &exp->exp_obd->u.lov;
2114 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2115 struct lov_stripe_md submd;
2116 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
2118 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2119 CDEBUG(D_HA, "lov idx %d NULL \n", loi->loi_ost_idx);
2123 submd.lsm_object_id = loi->loi_id;
2124 submd.lsm_object_gr = lsm->lsm_object_gr;
2125 submd.lsm_stripe_count = 0;
2126 rc = obd_change_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2132 static int lov_cancel(struct obd_export *exp, struct lov_stripe_md *lsm,
2133 __u32 mode, struct lustre_handle *lockh)
2135 struct lov_request_set *set;
2136 struct obd_info oinfo;
2137 struct lov_request *req;
2138 struct list_head *pos;
2139 struct lov_obd *lov = &exp->exp_obd->u.lov;
2140 struct lustre_handle *lov_lockhp;
2141 int err = 0, rc = 0;
2144 ASSERT_LSM_MAGIC(lsm);
2146 if (!exp || !exp->exp_obd)
2149 LASSERT(lsm->lsm_object_gr > 0);
2151 lov = &exp->exp_obd->u.lov;
2152 rc = lov_prep_cancel_set(exp, &oinfo, lsm, mode, lockh, &set);
2156 list_for_each (pos, &set->set_list) {
2157 req = list_entry(pos, struct lov_request, rq_link);
2158 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
2160 rc = obd_cancel(lov->lov_tgts[req->rq_idx]->ltd_exp,
2161 req->rq_oi.oi_md, mode, lov_lockhp);
2162 rc = lov_update_common_set(set, req, rc);
2164 CERROR("error: cancel objid "LPX64" subobj "
2165 LPX64" on OST idx %d: rc = %d\n",
2167 req->rq_oi.oi_md->lsm_object_id,
2173 lov_fini_cancel_set(set);
2177 static int lov_cancel_unused(struct obd_export *exp,
2178 struct lov_stripe_md *lsm,
2179 int flags, void *opaque)
2181 struct lov_obd *lov;
2185 if (!exp || !exp->exp_obd)
2188 lov = &exp->exp_obd->u.lov;
2190 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2192 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2195 err = obd_cancel_unused(lov->lov_tgts[i]->ltd_exp, NULL,
2203 ASSERT_LSM_MAGIC(lsm);
2205 LASSERT(lsm->lsm_object_gr > 0);
2206 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2207 struct lov_stripe_md submd;
2208 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
2211 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2212 CDEBUG(D_HA, "lov idx %d NULL\n", loi->loi_ost_idx);
2216 if (!lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
2217 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2219 submd.lsm_object_id = loi->loi_id;
2220 submd.lsm_object_gr = lsm->lsm_object_gr;
2221 submd.lsm_stripe_count = 0;
2222 err = obd_cancel_unused(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2223 &submd, flags, opaque);
2224 if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
2225 CERROR("error: cancel unused objid "LPX64" subobj "LPX64
2226 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
2227 loi->loi_id, loi->loi_ost_idx, err);
2235 static int lov_join_lru(struct obd_export *exp,
2236 struct lov_stripe_md *lsm, int join)
2238 struct lov_obd *lov;
2242 ASSERT_LSM_MAGIC(lsm);
2243 if (!exp || !exp->exp_obd)
2246 lov = &exp->exp_obd->u.lov;
2247 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2248 struct lov_stripe_md submd;
2249 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
2252 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2253 CDEBUG(D_HA, "lov idx %d NULL\n", loi->loi_ost_idx);
2257 if (!lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
2258 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2260 submd.lsm_object_id = loi->loi_id;
2261 submd.lsm_object_gr = lsm->lsm_object_gr;
2262 submd.lsm_stripe_count = 0;
2263 rc = obd_join_lru(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2266 CERROR("join lru failed. objid: "LPX64" subobj: "LPX64
2267 " ostidx: %d rc: %d\n", lsm->lsm_object_id,
2268 loi->loi_id, loi->loi_ost_idx, rc);
2277 static int lov_statfs_interpret(struct ptlrpc_request_set *rqset,
2280 struct lov_request_set *lovset = (struct lov_request_set *)data;
2285 lovset->set_completes = 0;
2287 err = lov_fini_statfs_set(lovset);
2288 RETURN(rc ? rc : err);
2291 static int lov_statfs_async(struct obd_device *obd, struct obd_info *oinfo,
2292 __u64 max_age, struct ptlrpc_request_set *rqset)
2294 struct lov_request_set *set;
2295 struct lov_request *req;
2296 struct list_head *pos;
2297 struct lov_obd *lov;
2301 LASSERT(oinfo != NULL);
2302 LASSERT(oinfo->oi_osfs != NULL);
2305 rc = lov_prep_statfs_set(obd, oinfo, &set);
2309 list_for_each (pos, &set->set_list) {
2310 struct obd_device *osc_obd;
2312 req = list_entry(pos, struct lov_request, rq_link);
2314 osc_obd = class_exp2obd(lov->lov_tgts[req->rq_idx]->ltd_exp);
2315 rc = obd_statfs_async(osc_obd, &req->rq_oi, max_age, rqset);
2320 if (rc || list_empty(&rqset->set_requests)) {
2323 set->set_completes = 0;
2324 err = lov_fini_statfs_set(set);
2325 RETURN(rc ? rc : err);
2328 LASSERT(rqset->set_interpret == NULL);
2329 rqset->set_interpret = lov_statfs_interpret;
2330 rqset->set_arg = (void *)set;
2334 static int lov_statfs(struct obd_device *obd, struct obd_statfs *osfs,
2335 __u64 max_age, __u32 flags)
2337 struct ptlrpc_request_set *set = NULL;
2338 struct obd_info oinfo = { { { 0 } } };
2343 /* for obdclass we forbid using obd_statfs_rqset, but prefer using async
2344 * statfs requests */
2345 set = ptlrpc_prep_set();
2349 oinfo.oi_osfs = osfs;
2350 oinfo.oi_flags = flags;
2351 rc = lov_statfs_async(obd, &oinfo, max_age, set);
2353 rc = ptlrpc_set_wait(set);
2354 ptlrpc_set_destroy(set);
2359 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
2360 void *karg, void *uarg)
2362 struct obd_device *obddev = class_exp2obd(exp);
2363 struct lov_obd *lov = &obddev->u.lov;
2364 int i, rc, count = lov->desc.ld_tgt_count;
2365 struct obd_uuid *uuidp;
2369 case IOC_OBD_STATFS: {
2370 struct obd_ioctl_data *data = karg;
2371 struct obd_device *osc_obd;
2372 struct obd_statfs stat_buf = {0};
2375 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
2376 LASSERT(data->ioc_plen1 == sizeof(struct obd_statfs));
2378 if ((index >= count))
2381 if (!lov->lov_tgts[index])
2382 /* Try again with the next index */
2384 if (!lov->lov_tgts[index]->ltd_active)
2387 osc_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
2391 /* got statfs data */
2392 rc = obd_statfs(osc_obd, &stat_buf,
2393 cfs_time_current_64() - HZ, 0);
2396 if (copy_to_user(data->ioc_pbuf1, &stat_buf, data->ioc_plen1))
2399 rc = copy_to_user(data->ioc_pbuf2, obd2cli_tgt(osc_obd),
2403 case OBD_IOC_LOV_GET_CONFIG: {
2404 struct obd_ioctl_data *data;
2405 struct lov_desc *desc;
2410 if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
2413 data = (struct obd_ioctl_data *)buf;
2415 if (sizeof(*desc) > data->ioc_inllen1) {
2416 obd_ioctl_freedata(buf, len);
2420 if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
2421 obd_ioctl_freedata(buf, len);
2425 if (sizeof(__u32) * count > data->ioc_inllen3) {
2426 obd_ioctl_freedata(buf, len);
2430 desc = (struct lov_desc *)data->ioc_inlbuf1;
2431 memcpy(desc, &(lov->desc), sizeof(*desc));
2433 uuidp = (struct obd_uuid *)data->ioc_inlbuf2;
2434 genp = (__u32 *)data->ioc_inlbuf3;
2435 /* the uuid will be empty for deleted OSTs */
2436 for (i = 0; i < count; i++, uuidp++, genp++) {
2437 if (!lov->lov_tgts[i])
2439 *uuidp = lov->lov_tgts[i]->ltd_uuid;
2440 *genp = lov->lov_tgts[i]->ltd_gen;
2443 rc = copy_to_user((void *)uarg, buf, len);
2446 obd_ioctl_freedata(buf, len);
2449 case LL_IOC_LOV_SETSTRIPE:
2450 rc = lov_setstripe(exp, karg, uarg);
2452 case LL_IOC_LOV_GETSTRIPE:
2453 rc = lov_getstripe(exp, karg, uarg);
2455 case LL_IOC_LOV_SETEA:
2456 rc = lov_setea(exp, karg, uarg);
2465 for (i = 0; i < count; i++) {
2468 /* OST was disconnected */
2469 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2472 err = obd_iocontrol(cmd, lov->lov_tgts[i]->ltd_exp,
2474 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
2477 if (lov->lov_tgts[i]->ltd_active) {
2478 CDEBUG(err == -ENOTTY ?
2479 D_IOCTL : D_WARNING,
2480 "iocontrol OSC %s on OST "
2481 "idx %d cmd %x: err = %d\n",
2482 lov_uuid2str(lov, i),
2499 static int lov_get_info(struct obd_export *exp, __u32 keylen,
2500 void *key, __u32 *vallen, void *val)
2502 struct obd_device *obddev = class_exp2obd(exp);
2503 struct lov_obd *lov = &obddev->u.lov;
2507 if (!vallen || !val)
2512 if (KEY_IS(KEY_LOCK_TO_STRIPE)) {
2515 struct ldlm_lock *lock;
2516 struct lov_stripe_md *lsm;
2518 struct ldlm_res_id *res_id = &data->lock->l_resource->lr_name;
2519 struct lov_oinfo *loi;
2520 __u32 *stripe = val;
2522 if (*vallen < sizeof(*stripe))
2523 GOTO(out, rc = -EFAULT);
2524 *vallen = sizeof(*stripe);
2526 /* XXX This is another one of those bits that will need to
2527 * change if we ever actually support nested LOVs. It uses
2528 * the lock's export to find out which stripe it is. */
2529 /* XXX - it's assumed all the locks for deleted OSTs have
2530 * been cancelled. Also, the export for deleted OSTs will
2531 * be NULL and won't match the lock's export. */
2532 for (i = 0; i < data->lsm->lsm_stripe_count; i++) {
2533 loi = data->lsm->lsm_oinfo[i];
2534 if (!lov->lov_tgts[loi->loi_ost_idx])
2536 if (lov->lov_tgts[loi->loi_ost_idx]->ltd_exp ==
2537 data->lock->l_conn_export &&
2538 loi->loi_id == res_id->name[0] &&
2539 loi->loi_gr == res_id->name[2]) {
2544 LDLM_ERROR(data->lock, "lock on inode without such object");
2545 dump_lsm(D_ERROR, data->lsm);
2546 GOTO(out, rc = -ENXIO);
2547 } else if (KEY_IS(KEY_LAST_ID)) {
2548 struct obd_id_info *info = val;
2549 __u32 size = sizeof(obd_id);
2550 struct lov_tgt_desc *tgt;
2552 LASSERT(*vallen == sizeof(struct obd_id_info));
2553 tgt = lov->lov_tgts[info->idx];
2555 if (!tgt || !tgt->ltd_active)
2556 GOTO(out, rc = -ESRCH);
2558 rc = obd_get_info(tgt->ltd_exp, keylen, key, &size, info->data);
2560 } else if (KEY_IS(KEY_LOVDESC)) {
2561 struct lov_desc *desc_ret = val;
2562 *desc_ret = lov->desc;
2565 } else if (KEY_IS(KEY_LOV_IDX)) {
2566 struct lov_tgt_desc *tgt;
2568 for(i = 0; i < lov->desc.ld_tgt_count; i++) {
2569 tgt = lov->lov_tgts[i];
2570 if (tgt && obd_uuid_equals(val, &tgt->ltd_uuid))
2581 static int lov_set_info_async(struct obd_export *exp, obd_count keylen,
2582 void *key, obd_count vallen, void *val,
2583 struct ptlrpc_request_set *set)
2585 struct obd_device *obddev = class_exp2obd(exp);
2586 struct lov_obd *lov = &obddev->u.lov;
2589 struct lov_tgt_desc *tgt;
2590 unsigned incr, check_uuid,
2591 do_inactive, no_set;
2592 unsigned next_id = 0, mds_con = 0;
2595 incr = check_uuid = do_inactive = no_set = 0;
2598 set = ptlrpc_prep_set();
2604 count = lov->desc.ld_tgt_count;
2606 if (KEY_IS(KEY_NEXT_ID)) {
2607 count = vallen / sizeof(struct obd_id_info);
2608 vallen = sizeof(obd_id);
2609 incr = sizeof(struct obd_id_info);
2612 } else if (KEY_IS("checksum")) {
2614 } else if (KEY_IS("unlinked")) {
2615 check_uuid = val ? 1 : 0;
2616 } else if (KEY_IS("evict_by_nid")) {
2617 /* use defaults: do_inactive = incr = 0; */
2618 } else if (KEY_IS(KEY_MDS_CONN)) {
2622 for (i = 0; i < count; i++, val = (char *)val + incr) {
2624 tgt = lov->lov_tgts[((struct obd_id_info*)val)->idx];
2626 tgt = lov->lov_tgts[i];
2628 /* OST was disconnected */
2629 if (!tgt || !tgt->ltd_exp)
2632 /* OST is inactive and we don't want inactive OSCs */
2633 if (!tgt->ltd_active && !do_inactive)
2637 struct mds_group_info *mgi;
2639 LASSERT(vallen == sizeof(*mgi));
2640 mgi = (struct mds_group_info *)val;
2642 /* Only want a specific OSC */
2643 if (mgi->uuid && !obd_uuid_equals(mgi->uuid,
2647 err = obd_set_info_async(tgt->ltd_exp,
2648 keylen, key, sizeof(int),
2650 } else if (next_id) {
2651 err = obd_set_info_async(tgt->ltd_exp,
2652 keylen, key, vallen,
2653 ((struct obd_id_info*)val)->data, set);
2655 /* Only want a specific OSC */
2657 !obd_uuid_equals(val, &tgt->ltd_uuid))
2660 err = obd_set_info_async(tgt->ltd_exp,
2661 keylen, key, vallen, val, set);
2670 err = ptlrpc_set_wait(set);
2673 ptlrpc_set_destroy(set);
2678 static int lov_checkmd(struct obd_export *exp, struct obd_export *md_exp,
2679 struct lov_stripe_md *lsm)
2687 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
2688 rc = lsm_op_find(lsm->lsm_magic)->lsm_revalidate(lsm, md_exp->exp_obd);
2693 int lov_test_and_clear_async_rc(struct lov_stripe_md *lsm)
2698 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2699 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
2700 if (loi->loi_ar.ar_rc && !rc)
2701 rc = loi->loi_ar.ar_rc;
2702 loi->loi_ar.ar_rc = 0;
2706 EXPORT_SYMBOL(lov_test_and_clear_async_rc);
2709 static int lov_extent_calc(struct obd_export *exp, struct lov_stripe_md *lsm,
2710 int cmd, __u64 *offset)
2712 __u32 ssize = lsm->lsm_stripe_size;
2716 do_div(start, ssize);
2717 start = start * ssize;
2719 CDEBUG(D_DLMTRACE, "offset "LPU64", stripe %u, start "LPU64
2720 ", end "LPU64"\n", *offset, ssize, start,
2722 if (cmd == OBD_CALC_STRIPE_END) {
2723 *offset = start + ssize - 1;
2724 } else if (cmd == OBD_CALC_STRIPE_START) {
2735 struct lov_multi_wait {
2736 struct ldlm_lock *lock;
2742 int lov_complete_many(struct obd_export *exp, struct lov_stripe_md *lsm,
2743 struct lustre_handle *lockh)
2745 struct lov_lock_handles *lov_lockh = NULL;
2746 struct lustre_handle *lov_lockhp;
2747 struct lov_obd *lov;
2748 struct lov_oinfo *loi;
2749 struct lov_multi_wait *queues;
2753 ASSERT_LSM_MAGIC(lsm);
2755 if (!exp || !exp->exp_obd)
2758 LASSERT(lockh != NULL);
2759 if (lsm->lsm_stripe_count > 1) {
2760 lov_lockh = lov_handle2llh(lockh);
2761 if (lov_lockh == NULL) {
2762 CERROR("LOV: invalid lov lock handle %p\n", lockh);
2766 lov_lockhp = lov_lockh->llh_handles;
2771 OBD_ALLOC(queues, lsm->lsm_stripe_count * sizeof(*queues));
2773 GOTO(out, rc = -ENOMEM);
2775 lov = &exp->exp_obd->u.lov;
2776 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
2777 i++, loi++, lov_lockhp++) {
2778 struct ldlm_lock *lock;
2779 struct obd_device *obd;
2781 lock = ldlm_handle2lock(lov_lockhp);
2783 CDEBUG(D_HA, "lov idx %d subobj "LPX64" no lock?\n",
2784 loi->loi_ost_idx, loi->loi_id);
2785 queues[i].completed = 1;
2789 queues[i].lock = lock;
2790 init_waitqueue_entry(&(queues[i].wait), current);
2791 add_wait_queue(lock->l_waitq, &(queues[i].wait));
2793 obd = class_exp2obd(lock->l_conn_export);
2795 imp = obd->u.cli.cl_import;
2797 spin_lock(&imp->imp_lock);
2798 queues[i].generation = imp->imp_generation;
2799 spin_unlock(&imp->imp_lock);
2803 lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, ldlm_expired_completion_wait,
2804 interrupted_completion_wait, &lwd);
2805 rc = l_wait_event_added(check_multi_complete(queues, lsm), &lwi);
2807 for (i = 0; i < lsm->lsm_stripe_count; i++)
2808 remove_wait_queue(lock->l_waitq, &(queues[i].wait));
2810 if (rc == -EINTR || rc == -ETIMEDOUT) {
2816 if (lov_lockh != NULL)
2817 lov_llh_put(lov_lockh);
2822 void lov_stripe_lock(struct lov_stripe_md *md)
2824 LASSERT(md->lsm_lock_owner != cfs_curproc_pid());
2825 spin_lock(&md->lsm_lock);
2826 LASSERT(md->lsm_lock_owner == 0);
2827 md->lsm_lock_owner = cfs_curproc_pid();
2829 EXPORT_SYMBOL(lov_stripe_lock);
2831 void lov_stripe_unlock(struct lov_stripe_md *md)
2833 LASSERT(md->lsm_lock_owner == cfs_curproc_pid());
2834 md->lsm_lock_owner = 0;
2835 spin_unlock(&md->lsm_lock);
2837 EXPORT_SYMBOL(lov_stripe_unlock);
2839 struct obd_ops lov_obd_ops = {
2840 .o_owner = THIS_MODULE,
2841 .o_setup = lov_setup,
2842 .o_precleanup = lov_precleanup,
2843 .o_cleanup = lov_cleanup,
2844 .o_process_config = lov_process_config,
2845 .o_connect = lov_connect,
2846 .o_disconnect = lov_disconnect,
2847 .o_statfs = lov_statfs,
2848 .o_statfs_async = lov_statfs_async,
2849 .o_packmd = lov_packmd,
2850 .o_unpackmd = lov_unpackmd,
2851 .o_checkmd = lov_checkmd,
2852 .o_create = lov_create,
2853 .o_destroy = lov_destroy,
2854 .o_getattr = lov_getattr,
2855 .o_getattr_async = lov_getattr_async,
2856 .o_setattr = lov_setattr,
2857 .o_setattr_async = lov_setattr_async,
2859 .o_brw_async = lov_brw_async,
2860 .o_prep_async_page = lov_prep_async_page,
2861 .o_queue_async_io = lov_queue_async_io,
2862 .o_set_async_flags = lov_set_async_flags,
2863 .o_queue_group_io = lov_queue_group_io,
2864 .o_trigger_group_io = lov_trigger_group_io,
2865 .o_teardown_async_page = lov_teardown_async_page,
2866 .o_merge_lvb = lov_merge_lvb,
2867 .o_adjust_kms = lov_adjust_kms,
2868 .o_punch = lov_punch,
2870 .o_enqueue = lov_enqueue,
2871 .o_match = lov_match,
2872 .o_change_cbdata = lov_change_cbdata,
2873 .o_cancel = lov_cancel,
2874 .o_cancel_unused = lov_cancel_unused,
2875 .o_join_lru = lov_join_lru,
2876 .o_iocontrol = lov_iocontrol,
2877 .o_get_info = lov_get_info,
2878 .o_set_info_async = lov_set_info_async,
2879 .o_extent_calc = lov_extent_calc,
2880 .o_llog_init = lov_llog_init,
2881 .o_llog_finish = lov_llog_finish,
2882 .o_notify = lov_notify,
2883 .o_register_page_removal_cb = lov_register_page_removal_cb,
2884 .o_unregister_page_removal_cb = lov_unregister_page_removal_cb,
2885 .o_register_lock_cancel_cb = lov_register_lock_cancel_cb,
2886 .o_unregister_lock_cancel_cb = lov_unregister_lock_cancel_cb,
2889 static quota_interface_t *quota_interface;
2890 extern quota_interface_t lov_quota_interface;
2892 cfs_mem_cache_t *lov_oinfo_slab;
2894 int __init lov_init(void)
2896 struct lprocfs_static_vars lvars = { 0 };
2900 lov_oinfo_slab = cfs_mem_cache_create("lov_oinfo",
2901 sizeof(struct lov_oinfo),
2902 0, SLAB_HWCACHE_ALIGN);
2903 if (lov_oinfo_slab == NULL)
2905 lprocfs_lov_init_vars(&lvars);
2907 request_module("lquota");
2908 quota_interface = PORTAL_SYMBOL_GET(lov_quota_interface);
2909 init_obd_quota_ops(quota_interface, &lov_obd_ops);
2911 rc = class_register_type(&lov_obd_ops, NULL, lvars.module_vars,
2912 LUSTRE_LOV_NAME, NULL);
2914 if (quota_interface)
2915 PORTAL_SYMBOL_PUT(lov_quota_interface);
2916 rc2 = cfs_mem_cache_destroy(lov_oinfo_slab);
2924 static void /*__exit*/ lov_exit(void)
2928 if (quota_interface)
2929 PORTAL_SYMBOL_PUT(lov_quota_interface);
2931 class_unregister_type(LUSTRE_LOV_NAME);
2932 rc = cfs_mem_cache_destroy(lov_oinfo_slab);
2936 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2937 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver");
2938 MODULE_LICENSE("GPL");
2940 cfs_module(lov, LUSTRE_VERSION_STRING, lov_init, lov_exit);