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:
909 rc = obd_llog_finish(obd, 0);
911 CERROR("failed to cleanup llogging subsystems\n");
917 static int lov_cleanup(struct obd_device *obd)
919 struct lov_obd *lov = &obd->u.lov;
921 lprocfs_obd_cleanup(obd);
924 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
925 if (!lov->lov_tgts[i])
928 /* Inactive targets may never have connected */
929 if (lov->lov_tgts[i]->ltd_active ||
930 atomic_read(&lov->lov_refcount))
931 /* We should never get here - these
932 should have been removed in the
934 CERROR("lov tgt %d not cleaned!"
935 " deathrow=%d, lovrc=%d\n",
936 i, lov->lov_death_row,
937 atomic_read(&lov->lov_refcount));
938 lov_del_target(obd, i, 0, 0);
940 OBD_FREE(lov->lov_tgts, sizeof(*lov->lov_tgts) *
942 lov->lov_tgt_size = 0;
945 if (lov->lov_qos.lq_rr_size)
946 OBD_FREE(lov->lov_qos.lq_rr_array, lov->lov_qos.lq_rr_size);
951 static int lov_process_config(struct obd_device *obd, obd_count len, void *buf)
953 struct lustre_cfg *lcfg = buf;
954 struct obd_uuid obd_uuid;
959 switch(cmd = lcfg->lcfg_command) {
960 case LCFG_LOV_ADD_OBD:
961 case LCFG_LOV_ADD_INA:
962 case LCFG_LOV_DEL_OBD: {
965 /* lov_modify_tgts add 0:lov_mdsA 1:ost1_UUID 2:0 3:1 */
966 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
967 GOTO(out, rc = -EINVAL);
969 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
971 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
972 GOTO(out, rc = -EINVAL);
973 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
974 GOTO(out, rc = -EINVAL);
975 if (cmd == LCFG_LOV_ADD_OBD)
976 rc = lov_add_target(obd, &obd_uuid, index, gen, 1);
977 else if (cmd == LCFG_LOV_ADD_INA)
978 rc = lov_add_target(obd, &obd_uuid, index, gen, 0);
980 rc = lov_del_target(obd, index, &obd_uuid, gen);
984 struct lprocfs_static_vars lvars = { 0 };
985 struct lov_desc *desc = &(obd->u.lov.desc);
988 GOTO(out, rc = -EINVAL);
990 lprocfs_lov_init_vars(&lvars);
992 rc = class_process_proc_param(PARAM_LOV, lvars.obd_vars,
997 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
998 GOTO(out, rc = -EINVAL);
1007 #define log2(n) ffz(~(n))
1010 static int lov_clear_orphans(struct obd_export *export, struct obdo *src_oa,
1011 struct lov_stripe_md **ea,
1012 struct obd_trans_info *oti)
1014 struct lov_obd *lov;
1015 struct obdo *tmp_oa;
1016 struct obd_uuid *ost_uuid = NULL;
1020 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
1021 src_oa->o_flags == OBD_FL_DELORPHAN);
1023 lov = &export->exp_obd->u.lov;
1029 if (src_oa->o_valid & OBD_MD_FLINLINE) {
1030 ost_uuid = (struct obd_uuid *)src_oa->o_inline;
1031 CDEBUG(D_HA, "clearing orphans only for %s\n",
1035 lov_getref(export->exp_obd);
1036 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1037 struct lov_stripe_md obj_md;
1038 struct lov_stripe_md *obj_mdp = &obj_md;
1039 struct lov_tgt_desc *tgt;
1042 tgt = lov->lov_tgts[i];
1046 /* if called for a specific target, we don't
1047 care if it is not active. */
1048 if (!lov->lov_tgts[i]->ltd_active && ost_uuid == NULL) {
1049 CDEBUG(D_HA, "lov idx %d inactive\n", i);
1053 if (ost_uuid && !obd_uuid_equals(ost_uuid, &tgt->ltd_uuid))
1056 CDEBUG(D_CONFIG,"Clear orphans for %d:%s\n", i,
1057 obd_uuid2str(ost_uuid));
1059 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
1061 LASSERT(lov->lov_tgts[i]->ltd_exp);
1062 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1063 err = obd_create(lov->lov_tgts[i]->ltd_exp,
1064 tmp_oa, &obj_mdp, oti);
1066 /* This export will be disabled until it is recovered,
1067 and then orphan recovery will be completed. */
1068 CERROR("error in orphan recovery on OST idx %d/%d: "
1069 "rc = %d\n", i, lov->desc.ld_tgt_count, err);
1074 lov_putref(export->exp_obd);
1080 static int lov_recreate(struct obd_export *exp, struct obdo *src_oa,
1081 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1083 struct lov_stripe_md *obj_mdp, *lsm;
1084 struct lov_obd *lov = &exp->exp_obd->u.lov;
1089 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
1090 src_oa->o_flags & OBD_FL_RECREATE_OBJS);
1092 OBD_ALLOC(obj_mdp, sizeof(*obj_mdp));
1093 if (obj_mdp == NULL)
1096 ost_idx = src_oa->o_nlink;
1099 GOTO(out, rc = -EINVAL);
1100 if (ost_idx >= lov->desc.ld_tgt_count ||
1101 !lov->lov_tgts[ost_idx])
1102 GOTO(out, rc = -EINVAL);
1104 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1105 if (lsm->lsm_oinfo[i]->loi_ost_idx == ost_idx) {
1106 if (lsm->lsm_oinfo[i]->loi_id != src_oa->o_id)
1107 GOTO(out, rc = -EINVAL);
1111 if (i == lsm->lsm_stripe_count)
1112 GOTO(out, rc = -EINVAL);
1114 rc = obd_create(lov->lov_tgts[ost_idx]->ltd_exp, src_oa, &obj_mdp, oti);
1116 OBD_FREE(obj_mdp, sizeof(*obj_mdp));
1120 /* the LOV expects oa->o_id to be set to the LOV object id */
1121 static int lov_create(struct obd_export *exp, struct obdo *src_oa,
1122 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1124 struct lov_obd *lov;
1125 struct obd_info oinfo;
1126 struct lov_request_set *set = NULL;
1127 struct lov_request *req;
1128 struct obd_statfs osfs;
1133 LASSERT(ea != NULL);
1137 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1138 src_oa->o_flags == OBD_FL_DELORPHAN) {
1139 rc = lov_clear_orphans(exp, src_oa, ea, oti);
1143 lov = &exp->exp_obd->u.lov;
1144 if (!lov->desc.ld_active_tgt_count)
1147 /* Recreate a specific object id at the given OST index */
1148 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1149 (src_oa->o_flags & OBD_FL_RECREATE_OBJS)) {
1150 rc = lov_recreate(exp, src_oa, ea, oti);
1154 maxage = cfs_time_shift_64(-lov->desc.ld_qos_maxage);
1155 obd_statfs_rqset(exp->exp_obd, &osfs, maxage, OBD_STATFS_NODELAY);
1157 rc = lov_prep_create_set(exp, &oinfo, ea, src_oa, oti, &set);
1161 list_for_each_entry(req, &set->set_list, rq_link) {
1162 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1163 rc = obd_create(lov->lov_tgts[req->rq_idx]->ltd_exp,
1164 req->rq_oi.oi_oa, &req->rq_oi.oi_md, oti);
1165 lov_update_create_set(set, req, rc);
1167 rc = lov_fini_create_set(set, ea);
1171 #define ASSERT_LSM_MAGIC(lsmp) \
1173 LASSERT((lsmp) != NULL); \
1174 LASSERTF(((lsmp)->lsm_magic == LOV_MAGIC || \
1175 (lsmp)->lsm_magic == LOV_MAGIC_JOIN), "%p->lsm_magic=%x\n", \
1176 (lsmp), (lsmp)->lsm_magic); \
1179 static int lov_destroy(struct obd_export *exp, struct obdo *oa,
1180 struct lov_stripe_md *lsm, struct obd_trans_info *oti,
1181 struct obd_export *md_exp)
1183 struct lov_request_set *set;
1184 struct obd_info oinfo;
1185 struct lov_request *req;
1186 struct list_head *pos;
1187 struct lov_obd *lov;
1191 ASSERT_LSM_MAGIC(lsm);
1193 if (!exp || !exp->exp_obd)
1196 if (oa->o_valid & OBD_MD_FLCOOKIE) {
1198 LASSERT(oti->oti_logcookies);
1201 lov = &exp->exp_obd->u.lov;
1202 rc = lov_prep_destroy_set(exp, &oinfo, oa, lsm, oti, &set);
1206 list_for_each (pos, &set->set_list) {
1208 req = list_entry(pos, struct lov_request, rq_link);
1210 if (oa->o_valid & OBD_MD_FLCOOKIE)
1211 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1213 err = obd_destroy(lov->lov_tgts[req->rq_idx]->ltd_exp,
1214 req->rq_oi.oi_oa, NULL, oti, NULL);
1215 err = lov_update_common_set(set, req, err);
1217 CERROR("error: destroying objid "LPX64" subobj "
1218 LPX64" on OST idx %d: rc = %d\n",
1219 oa->o_id, req->rq_oi.oi_oa->o_id,
1227 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
1228 rc = lsm_op_find(lsm->lsm_magic)->lsm_destroy(lsm, oa, md_exp);
1230 err = lov_fini_destroy_set(set);
1231 RETURN(rc ? rc : err);
1234 static int lov_getattr(struct obd_export *exp, struct obd_info *oinfo)
1236 struct lov_request_set *set;
1237 struct lov_request *req;
1238 struct list_head *pos;
1239 struct lov_obd *lov;
1240 int err = 0, rc = 0;
1244 ASSERT_LSM_MAGIC(oinfo->oi_md);
1246 if (!exp || !exp->exp_obd)
1249 lov = &exp->exp_obd->u.lov;
1251 rc = lov_prep_getattr_set(exp, oinfo, &set);
1255 list_for_each (pos, &set->set_list) {
1256 req = list_entry(pos, struct lov_request, rq_link);
1258 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1259 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1260 req->rq_oi.oi_oa->o_id, req->rq_idx);
1262 rc = obd_getattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1264 err = lov_update_common_set(set, req, rc);
1266 CERROR("error: getattr objid "LPX64" subobj "
1267 LPX64" on OST idx %d: rc = %d\n",
1268 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1274 rc = lov_fini_getattr_set(set);
1280 static int lov_getattr_interpret(struct ptlrpc_request_set *rqset,
1283 struct lov_request_set *lovset = (struct lov_request_set *)data;
1287 /* don't do attribute merge if this aysnc op failed */
1289 lovset->set_completes = 0;
1290 err = lov_fini_getattr_set(lovset);
1291 RETURN(rc ? rc : err);
1294 static int lov_getattr_async(struct obd_export *exp, struct obd_info *oinfo,
1295 struct ptlrpc_request_set *rqset)
1297 struct lov_request_set *lovset;
1298 struct lov_obd *lov;
1299 struct list_head *pos;
1300 struct lov_request *req;
1305 ASSERT_LSM_MAGIC(oinfo->oi_md);
1307 if (!exp || !exp->exp_obd)
1310 lov = &exp->exp_obd->u.lov;
1312 rc = lov_prep_getattr_set(exp, oinfo, &lovset);
1316 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1317 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1318 oinfo->oi_md->lsm_stripe_size);
1320 list_for_each (pos, &lovset->set_list) {
1321 req = list_entry(pos, struct lov_request, rq_link);
1323 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1324 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1325 req->rq_oi.oi_oa->o_id, req->rq_idx);
1326 rc = obd_getattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1327 &req->rq_oi, rqset);
1329 CERROR("error: getattr objid "LPX64" subobj "
1330 LPX64" on OST idx %d: rc = %d\n",
1331 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1337 if (!list_empty(&rqset->set_requests)) {
1339 LASSERT (rqset->set_interpret == NULL);
1340 rqset->set_interpret = lov_getattr_interpret;
1341 rqset->set_arg = (void *)lovset;
1346 lovset->set_completes = 0;
1347 err = lov_fini_getattr_set(lovset);
1348 RETURN(rc ? rc : err);
1351 static int lov_setattr(struct obd_export *exp, struct obd_info *oinfo,
1352 struct obd_trans_info *oti)
1354 struct lov_request_set *set;
1355 struct lov_obd *lov;
1356 struct list_head *pos;
1357 struct lov_request *req;
1358 int err = 0, rc = 0;
1362 ASSERT_LSM_MAGIC(oinfo->oi_md);
1364 if (!exp || !exp->exp_obd)
1367 /* for now, we only expect the following updates here */
1368 LASSERT(!(oinfo->oi_oa->o_valid & ~(OBD_MD_FLID | OBD_MD_FLTYPE |
1369 OBD_MD_FLMODE | OBD_MD_FLATIME |
1370 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1371 OBD_MD_FLFLAGS | OBD_MD_FLSIZE |
1372 OBD_MD_FLGROUP | OBD_MD_FLUID |
1373 OBD_MD_FLGID | OBD_MD_FLINLINE |
1374 OBD_MD_FLFID | OBD_MD_FLGENER)));
1375 lov = &exp->exp_obd->u.lov;
1376 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1380 list_for_each (pos, &set->set_list) {
1381 req = list_entry(pos, struct lov_request, rq_link);
1383 rc = obd_setattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1385 err = lov_update_setattr_set(set, req, rc);
1387 CERROR("error: setattr objid "LPX64" subobj "
1388 LPX64" on OST idx %d: rc = %d\n",
1389 set->set_oi->oi_oa->o_id,
1390 req->rq_oi.oi_oa->o_id, req->rq_idx, err);
1395 err = lov_fini_setattr_set(set);
1401 static int lov_setattr_interpret(struct ptlrpc_request_set *rqset,
1404 struct lov_request_set *lovset = (struct lov_request_set *)data;
1409 lovset->set_completes = 0;
1410 err = lov_fini_setattr_set(lovset);
1411 RETURN(rc ? rc : err);
1414 /* If @oti is given, the request goes from MDS and responses from OSTs are not
1415 needed. Otherwise, a client is waiting for responses. */
1416 static int lov_setattr_async(struct obd_export *exp, struct obd_info *oinfo,
1417 struct obd_trans_info *oti,
1418 struct ptlrpc_request_set *rqset)
1420 struct lov_request_set *set;
1421 struct lov_request *req;
1422 struct list_head *pos;
1423 struct lov_obd *lov;
1428 ASSERT_LSM_MAGIC(oinfo->oi_md);
1429 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE) {
1431 LASSERT(oti->oti_logcookies);
1434 if (!exp || !exp->exp_obd)
1437 lov = &exp->exp_obd->u.lov;
1438 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1442 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1443 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1444 oinfo->oi_md->lsm_stripe_size);
1446 list_for_each (pos, &set->set_list) {
1447 req = list_entry(pos, struct lov_request, rq_link);
1449 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
1450 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1452 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1453 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1454 req->rq_oi.oi_oa->o_id, req->rq_idx);
1456 rc = obd_setattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1457 &req->rq_oi, oti, rqset);
1459 CERROR("error: setattr objid "LPX64" subobj "
1460 LPX64" on OST idx %d: rc = %d\n",
1461 set->set_oi->oi_oa->o_id,
1462 req->rq_oi.oi_oa->o_id,
1468 /* If we are not waiting for responses on async requests, return. */
1469 if (rc || !rqset || list_empty(&rqset->set_requests)) {
1472 set->set_completes = 0;
1473 err = lov_fini_setattr_set(set);
1474 RETURN(rc ? rc : err);
1477 LASSERT(rqset->set_interpret == NULL);
1478 rqset->set_interpret = lov_setattr_interpret;
1479 rqset->set_arg = (void *)set;
1484 static int lov_punch_interpret(struct ptlrpc_request_set *rqset,
1487 struct lov_request_set *lovset = (struct lov_request_set *)data;
1492 lovset->set_completes = 0;
1493 err = lov_fini_punch_set(lovset);
1494 RETURN(rc ? rc : err);
1497 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
1498 * we can send this 'punch' to just the authoritative node and the nodes
1499 * that the punch will affect. */
1500 static int lov_punch(struct obd_export *exp, struct obd_info *oinfo,
1501 struct obd_trans_info *oti,
1502 struct ptlrpc_request_set *rqset)
1504 struct lov_request_set *set;
1505 struct lov_obd *lov;
1506 struct list_head *pos;
1507 struct lov_request *req;
1512 ASSERT_LSM_MAGIC(oinfo->oi_md);
1514 if (!exp || !exp->exp_obd)
1517 lov = &exp->exp_obd->u.lov;
1518 rc = lov_prep_punch_set(exp, oinfo, oti, &set);
1522 list_for_each (pos, &set->set_list) {
1523 req = list_entry(pos, struct lov_request, rq_link);
1525 rc = obd_punch(lov->lov_tgts[req->rq_idx]->ltd_exp,
1526 &req->rq_oi, NULL, rqset);
1528 CERROR("error: punch objid "LPX64" subobj "LPX64
1529 " on OST idx %d: rc = %d\n",
1530 set->set_oi->oi_oa->o_id,
1531 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1536 if (rc || list_empty(&rqset->set_requests)) {
1538 err = lov_fini_punch_set(set);
1539 RETURN(rc ? rc : err);
1542 LASSERT(rqset->set_interpret == NULL);
1543 rqset->set_interpret = lov_punch_interpret;
1544 rqset->set_arg = (void *)set;
1549 static int lov_sync(struct obd_export *exp, struct obdo *oa,
1550 struct lov_stripe_md *lsm, obd_off start, obd_off end,
1553 struct lov_request_set *set;
1554 struct obd_info oinfo;
1555 struct lov_obd *lov;
1556 struct list_head *pos;
1557 struct lov_request *req;
1558 int err = 0, rc = 0;
1561 ASSERT_LSM_MAGIC(lsm);
1566 lov = &exp->exp_obd->u.lov;
1567 rc = lov_prep_sync_set(exp, &oinfo, oa, lsm, start, end, &set);
1571 list_for_each (pos, &set->set_list) {
1572 req = list_entry(pos, struct lov_request, rq_link);
1574 rc = obd_sync(lov->lov_tgts[req->rq_idx]->ltd_exp,
1575 req->rq_oi.oi_oa, NULL,
1576 req->rq_oi.oi_policy.l_extent.start,
1577 req->rq_oi.oi_policy.l_extent.end, capa);
1578 err = lov_update_common_set(set, req, rc);
1580 CERROR("error: fsync objid "LPX64" subobj "LPX64
1581 " on OST idx %d: rc = %d\n",
1582 set->set_oi->oi_oa->o_id,
1583 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1588 err = lov_fini_sync_set(set);
1594 static int lov_brw_check(struct lov_obd *lov, struct obd_info *lov_oinfo,
1595 obd_count oa_bufs, struct brw_page *pga)
1597 struct obd_info oinfo = { { { 0 } } };
1600 oinfo.oi_oa = lov_oinfo->oi_oa;
1602 /* The caller just wants to know if there's a chance that this
1603 * I/O can succeed */
1604 for (i = 0; i < oa_bufs; i++) {
1605 int stripe = lov_stripe_number(lov_oinfo->oi_md, pga[i].off);
1606 int ost = lov_oinfo->oi_md->lsm_oinfo[stripe]->loi_ost_idx;
1609 if (!lov_stripe_intersects(lov_oinfo->oi_md, i, pga[i].off,
1610 pga[i].off + pga[i].count,
1614 if (!lov->lov_tgts[ost] || !lov->lov_tgts[ost]->ltd_active) {
1615 CDEBUG(D_HA, "lov idx %d inactive\n", ost);
1619 rc = obd_brw(OBD_BRW_CHECK, lov->lov_tgts[ost]->ltd_exp, &oinfo,
1627 static int lov_brw(int cmd, struct obd_export *exp, struct obd_info *oinfo,
1628 obd_count oa_bufs, struct brw_page *pga,
1629 struct obd_trans_info *oti)
1631 struct lov_request_set *set;
1632 struct lov_request *req;
1633 struct list_head *pos;
1634 struct lov_obd *lov = &exp->exp_obd->u.lov;
1638 ASSERT_LSM_MAGIC(oinfo->oi_md);
1640 if (cmd == OBD_BRW_CHECK) {
1641 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1645 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &set);
1649 list_for_each (pos, &set->set_list) {
1650 struct obd_export *sub_exp;
1651 struct brw_page *sub_pga;
1652 req = list_entry(pos, struct lov_request, rq_link);
1654 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1655 sub_pga = set->set_pga + req->rq_pgaidx;
1656 rc = obd_brw(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1660 lov_update_common_set(set, req, rc);
1663 err = lov_fini_brw_set(set);
1669 static int lov_brw_interpret(struct ptlrpc_request_set *reqset, void *data,
1672 struct lov_request_set *lovset = (struct lov_request_set *)data;
1676 lovset->set_completes = 0;
1677 lov_fini_brw_set(lovset);
1679 rc = lov_fini_brw_set(lovset);
1685 static int lov_brw_async(int cmd, struct obd_export *exp,
1686 struct obd_info *oinfo, obd_count oa_bufs,
1687 struct brw_page *pga, struct obd_trans_info *oti,
1688 struct ptlrpc_request_set *set)
1690 struct lov_request_set *lovset;
1691 struct lov_request *req;
1692 struct list_head *pos;
1693 struct lov_obd *lov = &exp->exp_obd->u.lov;
1698 ASSERT_LSM_MAGIC(oinfo->oi_md);
1700 if (cmd == OBD_BRW_CHECK) {
1701 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1705 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &lovset);
1709 list_for_each (pos, &lovset->set_list) {
1710 struct obd_export *sub_exp;
1711 struct brw_page *sub_pga;
1712 req = list_entry(pos, struct lov_request, rq_link);
1714 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1715 sub_pga = lovset->set_pga + req->rq_pgaidx;
1716 rc = obd_brw_async(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1720 lov_update_common_set(lovset, req, rc);
1723 LASSERT(set->set_interpret == NULL);
1724 LASSERT(set->set_arg == NULL);
1725 rc = ptlrpc_set_add_cb(set, lov_brw_interpret, lovset);
1731 lov_fini_brw_set(lovset);
1735 static int lov_ap_make_ready(void *data, int cmd)
1737 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1739 return lap->lap_caller_ops->ap_make_ready(lap->lap_caller_data, cmd);
1742 static int lov_ap_refresh_count(void *data, int cmd)
1744 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1746 return lap->lap_caller_ops->ap_refresh_count(lap->lap_caller_data,
1750 static void lov_ap_fill_obdo(void *data, int cmd, struct obdo *oa)
1752 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1754 lap->lap_caller_ops->ap_fill_obdo(lap->lap_caller_data, cmd, oa);
1755 /* XXX woah, shouldn't we be altering more here? size? */
1756 oa->o_id = lap->lap_loi_id;
1757 oa->o_gr = lap->lap_loi_gr;
1758 oa->o_valid |= OBD_MD_FLGROUP;
1759 oa->o_stripe_idx = lap->lap_stripe;
1762 static void lov_ap_update_obdo(void *data, int cmd, struct obdo *oa,
1765 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1767 lap->lap_caller_ops->ap_update_obdo(lap->lap_caller_data, cmd,oa,valid);
1770 static int lov_ap_completion(void *data, int cmd, struct obdo *oa, int rc)
1772 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1774 /* in a raid1 regime this would down a count of many ios
1775 * in flight, onl calling the caller_ops completion when all
1776 * the raid1 ios are complete */
1777 rc = lap->lap_caller_ops->ap_completion(lap->lap_caller_data,cmd,oa,rc);
1781 static struct obd_capa *lov_ap_lookup_capa(void *data, int cmd)
1783 struct lov_async_page *lap = LAP_FROM_COOKIE(data);
1784 return lap->lap_caller_ops->ap_lookup_capa(lap->lap_caller_data, cmd);
1787 static struct obd_async_page_ops lov_async_page_ops = {
1788 .ap_make_ready = lov_ap_make_ready,
1789 .ap_refresh_count = lov_ap_refresh_count,
1790 .ap_fill_obdo = lov_ap_fill_obdo,
1791 .ap_update_obdo = lov_ap_update_obdo,
1792 .ap_completion = lov_ap_completion,
1793 .ap_lookup_capa = lov_ap_lookup_capa,
1796 int lov_prep_async_page(struct obd_export *exp, struct lov_stripe_md *lsm,
1797 struct lov_oinfo *loi, cfs_page_t *page,
1798 obd_off offset, struct obd_async_page_ops *ops,
1799 void *data, void **res, int nocache,
1800 struct lustre_handle *lockh)
1802 struct lov_obd *lov = &exp->exp_obd->u.lov;
1803 struct lov_async_page *lap;
1804 struct lov_lock_handles *lov_lockh = NULL;
1810 /* Find an existing osc so we can get it's stupid sizeof(*oap).
1811 Only because of this layering limitation will a client
1812 mount with no osts fail */
1813 while (!lov->lov_tgts || !lov->lov_tgts[i] ||
1814 !lov->lov_tgts[i]->ltd_exp) {
1816 if (i >= lov->desc.ld_tgt_count)
1819 rc = size_round(sizeof(*lap)) +
1820 obd_prep_async_page(lov->lov_tgts[i]->ltd_exp, NULL,
1821 NULL, NULL, 0, NULL, NULL, NULL, 0,
1825 ASSERT_LSM_MAGIC(lsm);
1826 LASSERT(loi == NULL);
1829 lap->lap_magic = LOV_AP_MAGIC;
1830 lap->lap_caller_ops = ops;
1831 lap->lap_caller_data = data;
1833 /* for now only raid 0 which passes through */
1834 lap->lap_stripe = lov_stripe_number(lsm, offset);
1835 lov_stripe_offset(lsm, offset, lap->lap_stripe, &lap->lap_sub_offset);
1836 loi = lsm->lsm_oinfo[lap->lap_stripe];
1838 /* so the callback doesn't need the lsm */
1839 lap->lap_loi_id = loi->loi_id;
1840 lap->lap_loi_gr = lsm->lsm_object_gr;
1841 LASSERT(lsm->lsm_object_gr > 0);
1843 lap->lap_sub_cookie = (void *)lap + size_round(sizeof(*lap));
1846 lov_lockh = lov_handle2llh(lockh);
1848 lockh = lov_lockh->llh_handles + lap->lap_stripe;
1852 rc = obd_prep_async_page(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1853 lsm, loi, page, lap->lap_sub_offset,
1854 &lov_async_page_ops, lap,
1855 &lap->lap_sub_cookie, nocache, lockh);
1857 lov_llh_put(lov_lockh);
1860 CDEBUG(D_CACHE, "lap %p page %p cookie %p off "LPU64"\n", lap, page,
1861 lap->lap_sub_cookie, offset);
1865 static int lov_queue_async_io(struct obd_export *exp,
1866 struct lov_stripe_md *lsm,
1867 struct lov_oinfo *loi, void *cookie,
1868 int cmd, obd_off off, int count,
1869 obd_flag brw_flags, obd_flag async_flags)
1871 struct lov_obd *lov = &exp->exp_obd->u.lov;
1872 struct lov_async_page *lap;
1875 LASSERT(loi == NULL);
1877 ASSERT_LSM_MAGIC(lsm);
1879 lap = LAP_FROM_COOKIE(cookie);
1881 loi = lsm->lsm_oinfo[lap->lap_stripe];
1883 rc = obd_queue_async_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp, lsm,
1884 loi, lap->lap_sub_cookie, cmd, off, count,
1885 brw_flags, async_flags);
1889 static int lov_set_async_flags(struct obd_export *exp,
1890 struct lov_stripe_md *lsm,
1891 struct lov_oinfo *loi, void *cookie,
1892 obd_flag async_flags)
1894 struct lov_obd *lov = &exp->exp_obd->u.lov;
1895 struct lov_async_page *lap;
1898 LASSERT(loi == NULL);
1900 ASSERT_LSM_MAGIC(lsm);
1902 lap = LAP_FROM_COOKIE(cookie);
1904 loi = lsm->lsm_oinfo[lap->lap_stripe];
1906 rc = obd_set_async_flags(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1907 lsm, loi, lap->lap_sub_cookie, async_flags);
1911 static int lov_queue_group_io(struct obd_export *exp,
1912 struct lov_stripe_md *lsm,
1913 struct lov_oinfo *loi,
1914 struct obd_io_group *oig, void *cookie,
1915 int cmd, obd_off off, int count,
1916 obd_flag brw_flags, obd_flag async_flags)
1918 struct lov_obd *lov = &exp->exp_obd->u.lov;
1919 struct lov_async_page *lap;
1922 LASSERT(loi == NULL);
1924 ASSERT_LSM_MAGIC(lsm);
1926 lap = LAP_FROM_COOKIE(cookie);
1928 loi = lsm->lsm_oinfo[lap->lap_stripe];
1930 rc = obd_queue_group_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp, lsm,
1931 loi, oig, lap->lap_sub_cookie, cmd, off, count,
1932 brw_flags, async_flags);
1936 /* this isn't exactly optimal. we may have queued sync io in oscs on
1937 * all stripes, but we don't record that fact at queue time. so we
1938 * trigger sync io on all stripes. */
1939 static int lov_trigger_group_io(struct obd_export *exp,
1940 struct lov_stripe_md *lsm,
1941 struct lov_oinfo *loi,
1942 struct obd_io_group *oig)
1944 struct lov_obd *lov = &exp->exp_obd->u.lov;
1947 LASSERT(loi == NULL);
1949 ASSERT_LSM_MAGIC(lsm);
1951 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1952 loi = lsm->lsm_oinfo[i];
1953 if (!lov->lov_tgts[loi->loi_ost_idx] ||
1954 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1955 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1959 err = obd_trigger_group_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1961 if (rc == 0 && err != 0)
1967 static int lov_teardown_async_page(struct obd_export *exp,
1968 struct lov_stripe_md *lsm,
1969 struct lov_oinfo *loi, void *cookie)
1971 struct lov_obd *lov = &exp->exp_obd->u.lov;
1972 struct lov_async_page *lap;
1975 LASSERT(loi == NULL);
1977 ASSERT_LSM_MAGIC(lsm);
1979 lap = LAP_FROM_COOKIE(cookie);
1981 loi = lsm->lsm_oinfo[lap->lap_stripe];
1983 rc = obd_teardown_async_page(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1984 lsm, loi, lap->lap_sub_cookie);
1986 CERROR("unable to teardown sub cookie %p: %d\n",
1987 lap->lap_sub_cookie, rc);
1993 static int lov_enqueue_interpret(struct ptlrpc_request_set *rqset,
1996 struct lov_request_set *lovset = (struct lov_request_set *)data;
1998 rc = lov_fini_enqueue_set(lovset, lovset->set_ei->ei_mode, rc, rqset);
2002 static int lov_enqueue(struct obd_export *exp, struct obd_info *oinfo,
2003 struct ldlm_enqueue_info *einfo,
2004 struct ptlrpc_request_set *rqset)
2006 ldlm_mode_t mode = einfo->ei_mode;
2007 struct lov_request_set *set;
2008 struct lov_request *req;
2009 struct list_head *pos;
2010 struct lov_obd *lov;
2015 ASSERT_LSM_MAGIC(oinfo->oi_md);
2016 LASSERT(mode == (mode & -mode));
2018 /* we should never be asked to replay a lock this way. */
2019 LASSERT((oinfo->oi_flags & LDLM_FL_REPLAY) == 0);
2021 if (!exp || !exp->exp_obd)
2024 lov = &exp->exp_obd->u.lov;
2025 rc = lov_prep_enqueue_set(exp, oinfo, einfo, &set);
2029 list_for_each (pos, &set->set_list) {
2030 req = list_entry(pos, struct lov_request, rq_link);
2032 rc = obd_enqueue(lov->lov_tgts[req->rq_idx]->ltd_exp,
2033 &req->rq_oi, einfo, rqset);
2038 if (rqset && !list_empty(&rqset->set_requests)) {
2040 LASSERT(rqset->set_interpret == NULL);
2041 rqset->set_interpret = lov_enqueue_interpret;
2042 rqset->set_arg = (void *)set;
2046 rc = lov_fini_enqueue_set(set, mode, rc, rqset);
2050 static int lov_match(struct obd_export *exp, struct lov_stripe_md *lsm,
2051 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
2052 int *flags, void *data, struct lustre_handle *lockh)
2054 struct lov_request_set *set;
2055 struct obd_info oinfo;
2056 struct lov_request *req;
2057 struct list_head *pos;
2058 struct lov_obd *lov = &exp->exp_obd->u.lov;
2059 struct lustre_handle *lov_lockhp;
2060 int lov_flags, rc = 0;
2063 ASSERT_LSM_MAGIC(lsm);
2064 LASSERT((*flags & LDLM_FL_TEST_LOCK) || mode == (mode & -mode));
2066 if (!exp || !exp->exp_obd)
2069 lov = &exp->exp_obd->u.lov;
2070 rc = lov_prep_match_set(exp, &oinfo, lsm, policy, mode, lockh, &set);
2074 list_for_each (pos, &set->set_list) {
2075 ldlm_policy_data_t sub_policy;
2076 req = list_entry(pos, struct lov_request, rq_link);
2077 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
2078 LASSERT(lov_lockhp);
2081 sub_policy.l_extent = req->rq_oi.oi_policy.l_extent;
2083 rc = obd_match(lov->lov_tgts[req->rq_idx]->ltd_exp,
2084 req->rq_oi.oi_md, type, &sub_policy,
2085 mode, &lov_flags, data, lov_lockhp);
2086 rc = lov_update_match_set(set, req, rc);
2090 lov_fini_match_set(set, mode, *flags);
2094 static int lov_change_cbdata(struct obd_export *exp,
2095 struct lov_stripe_md *lsm, ldlm_iterator_t it,
2098 struct lov_obd *lov;
2102 ASSERT_LSM_MAGIC(lsm);
2104 if (!exp || !exp->exp_obd)
2107 LASSERT(lsm->lsm_object_gr > 0);
2109 lov = &exp->exp_obd->u.lov;
2110 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2111 struct lov_stripe_md submd;
2112 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
2114 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2115 CDEBUG(D_HA, "lov idx %d NULL \n", loi->loi_ost_idx);
2119 submd.lsm_object_id = loi->loi_id;
2120 submd.lsm_object_gr = lsm->lsm_object_gr;
2121 submd.lsm_stripe_count = 0;
2122 rc = obd_change_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2128 static int lov_cancel(struct obd_export *exp, struct lov_stripe_md *lsm,
2129 __u32 mode, struct lustre_handle *lockh)
2131 struct lov_request_set *set;
2132 struct obd_info oinfo;
2133 struct lov_request *req;
2134 struct list_head *pos;
2135 struct lov_obd *lov = &exp->exp_obd->u.lov;
2136 struct lustre_handle *lov_lockhp;
2137 int err = 0, rc = 0;
2140 ASSERT_LSM_MAGIC(lsm);
2142 if (!exp || !exp->exp_obd)
2145 LASSERT(lsm->lsm_object_gr > 0);
2147 lov = &exp->exp_obd->u.lov;
2148 rc = lov_prep_cancel_set(exp, &oinfo, lsm, mode, lockh, &set);
2152 list_for_each (pos, &set->set_list) {
2153 req = list_entry(pos, struct lov_request, rq_link);
2154 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
2156 rc = obd_cancel(lov->lov_tgts[req->rq_idx]->ltd_exp,
2157 req->rq_oi.oi_md, mode, lov_lockhp);
2158 rc = lov_update_common_set(set, req, rc);
2160 CERROR("error: cancel objid "LPX64" subobj "
2161 LPX64" on OST idx %d: rc = %d\n",
2163 req->rq_oi.oi_md->lsm_object_id,
2169 lov_fini_cancel_set(set);
2173 static int lov_cancel_unused(struct obd_export *exp,
2174 struct lov_stripe_md *lsm,
2175 int flags, void *opaque)
2177 struct lov_obd *lov;
2181 if (!exp || !exp->exp_obd)
2184 lov = &exp->exp_obd->u.lov;
2186 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2188 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2191 err = obd_cancel_unused(lov->lov_tgts[i]->ltd_exp, NULL,
2199 ASSERT_LSM_MAGIC(lsm);
2201 LASSERT(lsm->lsm_object_gr > 0);
2202 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2203 struct lov_stripe_md submd;
2204 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
2207 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2208 CDEBUG(D_HA, "lov idx %d NULL\n", loi->loi_ost_idx);
2212 if (!lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
2213 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2215 submd.lsm_object_id = loi->loi_id;
2216 submd.lsm_object_gr = lsm->lsm_object_gr;
2217 submd.lsm_stripe_count = 0;
2218 err = obd_cancel_unused(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2219 &submd, flags, opaque);
2220 if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
2221 CERROR("error: cancel unused objid "LPX64" subobj "LPX64
2222 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
2223 loi->loi_id, loi->loi_ost_idx, err);
2231 static int lov_join_lru(struct obd_export *exp,
2232 struct lov_stripe_md *lsm, int join)
2234 struct lov_obd *lov;
2238 ASSERT_LSM_MAGIC(lsm);
2239 if (!exp || !exp->exp_obd)
2242 lov = &exp->exp_obd->u.lov;
2243 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2244 struct lov_stripe_md submd;
2245 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
2248 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2249 CDEBUG(D_HA, "lov idx %d NULL\n", loi->loi_ost_idx);
2253 if (!lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
2254 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2256 submd.lsm_object_id = loi->loi_id;
2257 submd.lsm_object_gr = lsm->lsm_object_gr;
2258 submd.lsm_stripe_count = 0;
2259 rc = obd_join_lru(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2262 CERROR("join lru failed. objid: "LPX64" subobj: "LPX64
2263 " ostidx: %d rc: %d\n", lsm->lsm_object_id,
2264 loi->loi_id, loi->loi_ost_idx, rc);
2273 static int lov_statfs_interpret(struct ptlrpc_request_set *rqset,
2276 struct lov_request_set *lovset = (struct lov_request_set *)data;
2281 lovset->set_completes = 0;
2283 err = lov_fini_statfs_set(lovset);
2284 RETURN(rc ? rc : err);
2287 static int lov_statfs_async(struct obd_device *obd, struct obd_info *oinfo,
2288 __u64 max_age, struct ptlrpc_request_set *rqset)
2290 struct lov_request_set *set;
2291 struct lov_request *req;
2292 struct list_head *pos;
2293 struct lov_obd *lov;
2297 LASSERT(oinfo != NULL);
2298 LASSERT(oinfo->oi_osfs != NULL);
2301 rc = lov_prep_statfs_set(obd, oinfo, &set);
2305 list_for_each (pos, &set->set_list) {
2306 struct obd_device *osc_obd;
2308 req = list_entry(pos, struct lov_request, rq_link);
2310 osc_obd = class_exp2obd(lov->lov_tgts[req->rq_idx]->ltd_exp);
2311 rc = obd_statfs_async(osc_obd, &req->rq_oi, max_age, rqset);
2316 if (rc || list_empty(&rqset->set_requests)) {
2319 set->set_completes = 0;
2320 err = lov_fini_statfs_set(set);
2321 RETURN(rc ? rc : err);
2324 LASSERT(rqset->set_interpret == NULL);
2325 rqset->set_interpret = lov_statfs_interpret;
2326 rqset->set_arg = (void *)set;
2330 static int lov_statfs(struct obd_device *obd, struct obd_statfs *osfs,
2331 __u64 max_age, __u32 flags)
2333 struct ptlrpc_request_set *set = NULL;
2334 struct obd_info oinfo = { { { 0 } } };
2339 /* for obdclass we forbid using obd_statfs_rqset, but prefer using async
2340 * statfs requests */
2341 set = ptlrpc_prep_set();
2345 oinfo.oi_osfs = osfs;
2346 oinfo.oi_flags = flags;
2347 rc = lov_statfs_async(obd, &oinfo, max_age, set);
2349 rc = ptlrpc_set_wait(set);
2350 ptlrpc_set_destroy(set);
2355 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
2356 void *karg, void *uarg)
2358 struct obd_device *obddev = class_exp2obd(exp);
2359 struct lov_obd *lov = &obddev->u.lov;
2360 int i, rc, count = lov->desc.ld_tgt_count;
2361 struct obd_uuid *uuidp;
2365 case IOC_OBD_STATFS: {
2366 struct obd_ioctl_data *data = karg;
2367 struct obd_device *osc_obd;
2368 struct obd_statfs stat_buf = {0};
2371 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
2372 LASSERT(data->ioc_plen1 == sizeof(struct obd_statfs));
2374 if ((index >= count))
2377 if (!lov->lov_tgts[index])
2378 /* Try again with the next index */
2380 if (!lov->lov_tgts[index]->ltd_active)
2383 osc_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
2387 /* got statfs data */
2388 rc = obd_statfs(osc_obd, &stat_buf,
2389 cfs_time_current_64() - HZ, 0);
2392 if (copy_to_user(data->ioc_pbuf1, &stat_buf, data->ioc_plen1))
2395 rc = copy_to_user(data->ioc_pbuf2, obd2cli_tgt(osc_obd),
2399 case OBD_IOC_LOV_GET_CONFIG: {
2400 struct obd_ioctl_data *data;
2401 struct lov_desc *desc;
2406 if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
2409 data = (struct obd_ioctl_data *)buf;
2411 if (sizeof(*desc) > data->ioc_inllen1) {
2412 obd_ioctl_freedata(buf, len);
2416 if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
2417 obd_ioctl_freedata(buf, len);
2421 if (sizeof(__u32) * count > data->ioc_inllen3) {
2422 obd_ioctl_freedata(buf, len);
2426 desc = (struct lov_desc *)data->ioc_inlbuf1;
2427 memcpy(desc, &(lov->desc), sizeof(*desc));
2429 uuidp = (struct obd_uuid *)data->ioc_inlbuf2;
2430 genp = (__u32 *)data->ioc_inlbuf3;
2431 /* the uuid will be empty for deleted OSTs */
2432 for (i = 0; i < count; i++, uuidp++, genp++) {
2433 if (!lov->lov_tgts[i])
2435 *uuidp = lov->lov_tgts[i]->ltd_uuid;
2436 *genp = lov->lov_tgts[i]->ltd_gen;
2439 rc = copy_to_user((void *)uarg, buf, len);
2442 obd_ioctl_freedata(buf, len);
2445 case LL_IOC_LOV_SETSTRIPE:
2446 rc = lov_setstripe(exp, karg, uarg);
2448 case LL_IOC_LOV_GETSTRIPE:
2449 rc = lov_getstripe(exp, karg, uarg);
2451 case LL_IOC_LOV_SETEA:
2452 rc = lov_setea(exp, karg, uarg);
2461 for (i = 0; i < count; i++) {
2464 /* OST was disconnected */
2465 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2468 err = obd_iocontrol(cmd, lov->lov_tgts[i]->ltd_exp,
2470 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
2473 if (lov->lov_tgts[i]->ltd_active) {
2474 CDEBUG(err == -ENOTTY ?
2475 D_IOCTL : D_WARNING,
2476 "iocontrol OSC %s on OST "
2477 "idx %d cmd %x: err = %d\n",
2478 lov_uuid2str(lov, i),
2495 static int lov_get_info(struct obd_export *exp, __u32 keylen,
2496 void *key, __u32 *vallen, void *val)
2498 struct obd_device *obddev = class_exp2obd(exp);
2499 struct lov_obd *lov = &obddev->u.lov;
2503 if (!vallen || !val)
2508 if (KEY_IS(KEY_LOCK_TO_STRIPE)) {
2511 struct ldlm_lock *lock;
2512 struct lov_stripe_md *lsm;
2514 struct ldlm_res_id *res_id = &data->lock->l_resource->lr_name;
2515 struct lov_oinfo *loi;
2516 __u32 *stripe = val;
2518 if (*vallen < sizeof(*stripe))
2519 GOTO(out, rc = -EFAULT);
2520 *vallen = sizeof(*stripe);
2522 /* XXX This is another one of those bits that will need to
2523 * change if we ever actually support nested LOVs. It uses
2524 * the lock's export to find out which stripe it is. */
2525 /* XXX - it's assumed all the locks for deleted OSTs have
2526 * been cancelled. Also, the export for deleted OSTs will
2527 * be NULL and won't match the lock's export. */
2528 for (i = 0; i < data->lsm->lsm_stripe_count; i++) {
2529 loi = data->lsm->lsm_oinfo[i];
2530 if (!lov->lov_tgts[loi->loi_ost_idx])
2532 if (lov->lov_tgts[loi->loi_ost_idx]->ltd_exp ==
2533 data->lock->l_conn_export &&
2534 loi->loi_id == res_id->name[0] &&
2535 loi->loi_gr == res_id->name[2]) {
2540 LDLM_ERROR(data->lock, "lock on inode without such object");
2541 dump_lsm(D_ERROR, data->lsm);
2542 GOTO(out, rc = -ENXIO);
2543 } else if (KEY_IS(KEY_LAST_ID)) {
2544 struct obd_id_info *info = val;
2545 __u32 size = sizeof(obd_id);
2546 struct lov_tgt_desc *tgt;
2548 LASSERT(*vallen == sizeof(struct obd_id_info));
2549 tgt = lov->lov_tgts[info->idx];
2551 if (!tgt || !tgt->ltd_active)
2552 GOTO(out, rc = -ESRCH);
2554 rc = obd_get_info(tgt->ltd_exp, keylen, key, &size, info->data);
2556 } else if (KEY_IS(KEY_LOVDESC)) {
2557 struct lov_desc *desc_ret = val;
2558 *desc_ret = lov->desc;
2561 } else if (KEY_IS(KEY_LOV_IDX)) {
2562 struct lov_tgt_desc *tgt;
2564 for(i = 0; i < lov->desc.ld_tgt_count; i++) {
2565 tgt = lov->lov_tgts[i];
2566 if (tgt && obd_uuid_equals(val, &tgt->ltd_uuid))
2577 static int lov_set_info_async(struct obd_export *exp, obd_count keylen,
2578 void *key, obd_count vallen, void *val,
2579 struct ptlrpc_request_set *set)
2581 struct obd_device *obddev = class_exp2obd(exp);
2582 struct lov_obd *lov = &obddev->u.lov;
2585 struct lov_tgt_desc *tgt;
2586 unsigned incr, check_uuid,
2587 do_inactive, no_set;
2588 unsigned next_id = 0, mds_con = 0;
2591 incr = check_uuid = do_inactive = no_set = 0;
2594 set = ptlrpc_prep_set();
2600 count = lov->desc.ld_tgt_count;
2602 if (KEY_IS(KEY_NEXT_ID)) {
2603 count = vallen / sizeof(struct obd_id_info);
2604 vallen = sizeof(obd_id);
2605 incr = sizeof(struct obd_id_info);
2608 } else if (KEY_IS(KEY_CHECKSUM)) {
2610 } else if (KEY_IS(KEY_UNLINKED)) {
2611 check_uuid = val ? 1 : 0;
2612 } else if (KEY_IS(KEY_EVICT_BY_NID)) {
2613 /* use defaults: do_inactive = incr = 0; */
2614 } else if (KEY_IS(KEY_MDS_CONN)) {
2618 for (i = 0; i < count; i++, val = (char *)val + incr) {
2620 tgt = lov->lov_tgts[((struct obd_id_info*)val)->idx];
2622 tgt = lov->lov_tgts[i];
2624 /* OST was disconnected */
2625 if (!tgt || !tgt->ltd_exp)
2628 /* OST is inactive and we don't want inactive OSCs */
2629 if (!tgt->ltd_active && !do_inactive)
2633 struct mds_group_info *mgi;
2635 LASSERT(vallen == sizeof(*mgi));
2636 mgi = (struct mds_group_info *)val;
2638 /* Only want a specific OSC */
2639 if (mgi->uuid && !obd_uuid_equals(mgi->uuid,
2643 err = obd_set_info_async(tgt->ltd_exp,
2644 keylen, key, sizeof(int),
2646 } else if (next_id) {
2647 err = obd_set_info_async(tgt->ltd_exp,
2648 keylen, key, vallen,
2649 ((struct obd_id_info*)val)->data, set);
2651 /* Only want a specific OSC */
2653 !obd_uuid_equals(val, &tgt->ltd_uuid))
2656 err = obd_set_info_async(tgt->ltd_exp,
2657 keylen, key, vallen, val, set);
2666 err = ptlrpc_set_wait(set);
2669 ptlrpc_set_destroy(set);
2674 static int lov_checkmd(struct obd_export *exp, struct obd_export *md_exp,
2675 struct lov_stripe_md *lsm)
2683 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
2684 rc = lsm_op_find(lsm->lsm_magic)->lsm_revalidate(lsm, md_exp->exp_obd);
2689 int lov_test_and_clear_async_rc(struct lov_stripe_md *lsm)
2694 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2695 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
2696 if (loi->loi_ar.ar_rc && !rc)
2697 rc = loi->loi_ar.ar_rc;
2698 loi->loi_ar.ar_rc = 0;
2702 EXPORT_SYMBOL(lov_test_and_clear_async_rc);
2705 static int lov_extent_calc(struct obd_export *exp, struct lov_stripe_md *lsm,
2706 int cmd, __u64 *offset)
2708 __u32 ssize = lsm->lsm_stripe_size;
2712 do_div(start, ssize);
2713 start = start * ssize;
2715 CDEBUG(D_DLMTRACE, "offset "LPU64", stripe %u, start "LPU64
2716 ", end "LPU64"\n", *offset, ssize, start,
2718 if (cmd == OBD_CALC_STRIPE_END) {
2719 *offset = start + ssize - 1;
2720 } else if (cmd == OBD_CALC_STRIPE_START) {
2731 struct lov_multi_wait {
2732 struct ldlm_lock *lock;
2738 int lov_complete_many(struct obd_export *exp, struct lov_stripe_md *lsm,
2739 struct lustre_handle *lockh)
2741 struct lov_lock_handles *lov_lockh = NULL;
2742 struct lustre_handle *lov_lockhp;
2743 struct lov_obd *lov;
2744 struct lov_oinfo *loi;
2745 struct lov_multi_wait *queues;
2749 ASSERT_LSM_MAGIC(lsm);
2751 if (!exp || !exp->exp_obd)
2754 LASSERT(lockh != NULL);
2755 if (lsm->lsm_stripe_count > 1) {
2756 lov_lockh = lov_handle2llh(lockh);
2757 if (lov_lockh == NULL) {
2758 CERROR("LOV: invalid lov lock handle %p\n", lockh);
2762 lov_lockhp = lov_lockh->llh_handles;
2767 OBD_ALLOC(queues, lsm->lsm_stripe_count * sizeof(*queues));
2769 GOTO(out, rc = -ENOMEM);
2771 lov = &exp->exp_obd->u.lov;
2772 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
2773 i++, loi++, lov_lockhp++) {
2774 struct ldlm_lock *lock;
2775 struct obd_device *obd;
2777 lock = ldlm_handle2lock(lov_lockhp);
2779 CDEBUG(D_HA, "lov idx %d subobj "LPX64" no lock?\n",
2780 loi->loi_ost_idx, loi->loi_id);
2781 queues[i].completed = 1;
2785 queues[i].lock = lock;
2786 init_waitqueue_entry(&(queues[i].wait), current);
2787 add_wait_queue(lock->l_waitq, &(queues[i].wait));
2789 obd = class_exp2obd(lock->l_conn_export);
2791 imp = obd->u.cli.cl_import;
2793 spin_lock(&imp->imp_lock);
2794 queues[i].generation = imp->imp_generation;
2795 spin_unlock(&imp->imp_lock);
2799 lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, ldlm_expired_completion_wait,
2800 interrupted_completion_wait, &lwd);
2801 rc = l_wait_event_added(check_multi_complete(queues, lsm), &lwi);
2803 for (i = 0; i < lsm->lsm_stripe_count; i++)
2804 remove_wait_queue(lock->l_waitq, &(queues[i].wait));
2806 if (rc == -EINTR || rc == -ETIMEDOUT) {
2812 if (lov_lockh != NULL)
2813 lov_llh_put(lov_lockh);
2818 void lov_stripe_lock(struct lov_stripe_md *md)
2820 LASSERT(md->lsm_lock_owner != cfs_curproc_pid());
2821 spin_lock(&md->lsm_lock);
2822 LASSERT(md->lsm_lock_owner == 0);
2823 md->lsm_lock_owner = cfs_curproc_pid();
2825 EXPORT_SYMBOL(lov_stripe_lock);
2827 void lov_stripe_unlock(struct lov_stripe_md *md)
2829 LASSERT(md->lsm_lock_owner == cfs_curproc_pid());
2830 md->lsm_lock_owner = 0;
2831 spin_unlock(&md->lsm_lock);
2833 EXPORT_SYMBOL(lov_stripe_unlock);
2835 static int lov_reget_short_lock(struct obd_export *exp,
2836 struct lov_stripe_md *lsm,
2838 obd_off start, obd_off end,
2841 struct lov_async_page *l = *res;
2842 obd_off stripe_start, stripe_end = start;
2846 /* ensure we don't cross stripe boundaries */
2847 lov_extent_calc(exp, lsm, OBD_CALC_STRIPE_END, &stripe_end);
2848 if (stripe_end <= end)
2851 /* map the region limits to the object limits */
2852 lov_stripe_offset(lsm, start, l->lap_stripe, &stripe_start);
2853 lov_stripe_offset(lsm, end, l->lap_stripe, &stripe_end);
2855 RETURN(obd_reget_short_lock(exp->exp_obd->u.lov.lov_tgts[lsm->
2856 lsm_oinfo[l->lap_stripe]->loi_ost_idx]->
2857 ltd_exp, NULL, &l->lap_sub_cookie,
2858 rw, stripe_start, stripe_end, cookie));
2861 static int lov_release_short_lock(struct obd_export *exp,
2862 struct lov_stripe_md *lsm, obd_off end,
2863 void *cookie, int rw)
2869 stripe = lov_stripe_number(lsm, end);
2871 RETURN(obd_release_short_lock(exp->exp_obd->u.lov.lov_tgts[lsm->
2872 lsm_oinfo[stripe]->loi_ost_idx]->
2873 ltd_exp, NULL, end, cookie, rw));
2876 struct obd_ops lov_obd_ops = {
2877 .o_owner = THIS_MODULE,
2878 .o_setup = lov_setup,
2879 .o_precleanup = lov_precleanup,
2880 .o_cleanup = lov_cleanup,
2881 .o_process_config = lov_process_config,
2882 .o_connect = lov_connect,
2883 .o_disconnect = lov_disconnect,
2884 .o_statfs = lov_statfs,
2885 .o_statfs_async = lov_statfs_async,
2886 .o_packmd = lov_packmd,
2887 .o_unpackmd = lov_unpackmd,
2888 .o_checkmd = lov_checkmd,
2889 .o_create = lov_create,
2890 .o_destroy = lov_destroy,
2891 .o_getattr = lov_getattr,
2892 .o_getattr_async = lov_getattr_async,
2893 .o_setattr = lov_setattr,
2894 .o_setattr_async = lov_setattr_async,
2896 .o_brw_async = lov_brw_async,
2897 .o_prep_async_page = lov_prep_async_page,
2898 .o_reget_short_lock = lov_reget_short_lock,
2899 .o_release_short_lock = lov_release_short_lock,
2900 .o_queue_async_io = lov_queue_async_io,
2901 .o_set_async_flags = lov_set_async_flags,
2902 .o_queue_group_io = lov_queue_group_io,
2903 .o_trigger_group_io = lov_trigger_group_io,
2904 .o_teardown_async_page = lov_teardown_async_page,
2905 .o_merge_lvb = lov_merge_lvb,
2906 .o_adjust_kms = lov_adjust_kms,
2907 .o_punch = lov_punch,
2909 .o_enqueue = lov_enqueue,
2910 .o_match = lov_match,
2911 .o_change_cbdata = lov_change_cbdata,
2912 .o_cancel = lov_cancel,
2913 .o_cancel_unused = lov_cancel_unused,
2914 .o_join_lru = lov_join_lru,
2915 .o_iocontrol = lov_iocontrol,
2916 .o_get_info = lov_get_info,
2917 .o_set_info_async = lov_set_info_async,
2918 .o_extent_calc = lov_extent_calc,
2919 .o_llog_init = lov_llog_init,
2920 .o_llog_finish = lov_llog_finish,
2921 .o_notify = lov_notify,
2922 .o_register_page_removal_cb = lov_register_page_removal_cb,
2923 .o_unregister_page_removal_cb = lov_unregister_page_removal_cb,
2924 .o_register_lock_cancel_cb = lov_register_lock_cancel_cb,
2925 .o_unregister_lock_cancel_cb = lov_unregister_lock_cancel_cb,
2928 static quota_interface_t *quota_interface;
2929 extern quota_interface_t lov_quota_interface;
2931 cfs_mem_cache_t *lov_oinfo_slab;
2933 int __init lov_init(void)
2935 struct lprocfs_static_vars lvars = { 0 };
2939 lov_oinfo_slab = cfs_mem_cache_create("lov_oinfo",
2940 sizeof(struct lov_oinfo),
2941 0, SLAB_HWCACHE_ALIGN);
2942 if (lov_oinfo_slab == NULL)
2944 lprocfs_lov_init_vars(&lvars);
2946 request_module("lquota");
2947 quota_interface = PORTAL_SYMBOL_GET(lov_quota_interface);
2948 init_obd_quota_ops(quota_interface, &lov_obd_ops);
2950 rc = class_register_type(&lov_obd_ops, NULL, lvars.module_vars,
2951 LUSTRE_LOV_NAME, NULL);
2953 if (quota_interface)
2954 PORTAL_SYMBOL_PUT(lov_quota_interface);
2955 rc2 = cfs_mem_cache_destroy(lov_oinfo_slab);
2963 static void /*__exit*/ lov_exit(void)
2967 if (quota_interface)
2968 PORTAL_SYMBOL_PUT(lov_quota_interface);
2970 class_unregister_type(LUSTRE_LOV_NAME);
2971 rc = cfs_mem_cache_destroy(lov_oinfo_slab);
2975 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2976 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver");
2977 MODULE_LICENSE("GPL");
2979 cfs_module(lov, LUSTRE_VERSION_STRING, lov_init, lov_exit);