1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/lov/lov_obd.c
38 * Author: Phil Schwan <phil@clusterfs.com>
39 * Author: Peter Braam <braam@clusterfs.com>
40 * Author: Mike Shaver <shaver@clusterfs.com>
41 * Author: Nathan Rutman <nathan@clusterfs.com>
45 # define EXPORT_SYMTAB
47 #define DEBUG_SUBSYSTEM S_LOV
49 #include <libcfs/libcfs.h>
51 #include <liblustre.h>
54 #include <obd_support.h>
55 #include <lustre_lib.h>
56 #include <lustre_net.h>
57 #include <lustre/lustre_idl.h>
58 #include <lustre_dlm.h>
59 #include <lustre_mds.h>
60 #include <lustre_debug.h>
61 #include <obd_class.h>
64 #include <lprocfs_status.h>
65 #include <lustre_param.h>
66 #include <lustre_cache.h>
67 #include <lustre/ll_fiemap.h>
69 #include "lov_internal.h"
72 /* Keep a refcount of lov->tgt usage to prevent racing with addition/deletion.
73 Any function that expects lov_tgts to remain stationary must take a ref. */
74 void lov_getref(struct obd_device *obd)
76 struct lov_obd *lov = &obd->u.lov;
78 /* nobody gets through here until lov_putref is done */
79 mutex_down(&lov->lov_lock);
80 atomic_inc(&lov->lov_refcount);
81 mutex_up(&lov->lov_lock);
85 static void __lov_del_obd(struct obd_device *obd, __u32 index);
87 void lov_putref(struct obd_device *obd)
89 struct lov_obd *lov = &obd->u.lov;
90 mutex_down(&lov->lov_lock);
91 /* ok to dec to 0 more than once -- ltd_exp's will be null */
92 if (atomic_dec_and_test(&lov->lov_refcount) && lov->lov_death_row) {
94 CDEBUG(D_CONFIG, "destroying %d lov targets\n",
96 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
97 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_reap)
99 /* Disconnect and delete from list */
100 __lov_del_obd(obd, i);
101 lov->lov_death_row--;
104 mutex_up(&lov->lov_lock);
107 static int lov_register_page_removal_cb(struct obd_export *exp,
108 obd_page_removal_cb_t func,
109 obd_pin_extent_cb pin_cb)
111 struct lov_obd *lov = &exp->exp_obd->u.lov;
114 if (lov->lov_page_removal_cb && lov->lov_page_removal_cb != func)
117 if (lov->lov_page_pin_cb && lov->lov_page_pin_cb != pin_cb)
120 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
121 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
123 rc |= obd_register_page_removal_cb(lov->lov_tgts[i]->ltd_exp,
127 lov->lov_page_removal_cb = func;
128 lov->lov_page_pin_cb = pin_cb;
133 static int lov_unregister_page_removal_cb(struct obd_export *exp,
134 obd_page_removal_cb_t func)
136 struct lov_obd *lov = &exp->exp_obd->u.lov;
139 if (lov->lov_page_removal_cb && lov->lov_page_removal_cb != func)
142 lov->lov_page_removal_cb = NULL;
143 lov->lov_page_pin_cb = NULL;
145 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
146 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
148 rc |= obd_unregister_page_removal_cb(lov->lov_tgts[i]->ltd_exp,
155 static int lov_register_lock_cancel_cb(struct obd_export *exp,
156 obd_lock_cancel_cb func)
158 struct lov_obd *lov = &exp->exp_obd->u.lov;
161 if (lov->lov_lock_cancel_cb && lov->lov_lock_cancel_cb != func)
164 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
165 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
167 rc |= obd_register_lock_cancel_cb(lov->lov_tgts[i]->ltd_exp,
171 lov->lov_lock_cancel_cb = func;
176 static int lov_unregister_lock_cancel_cb(struct obd_export *exp,
177 obd_lock_cancel_cb func)
179 struct lov_obd *lov = &exp->exp_obd->u.lov;
182 if (lov->lov_lock_cancel_cb && lov->lov_lock_cancel_cb != func)
185 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
186 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
188 rc |= obd_unregister_lock_cancel_cb(lov->lov_tgts[i]->ltd_exp,
191 lov->lov_lock_cancel_cb = NULL;
195 #define MAX_STRING_SIZE 128
196 static int lov_connect_obd(struct obd_device *obd, __u32 index, int activate,
197 struct obd_connect_data *data)
199 struct lov_obd *lov = &obd->u.lov;
200 struct obd_uuid tgt_uuid;
201 struct obd_device *tgt_obd;
202 struct obd_uuid lov_osc_uuid = { "LOV_OSC_UUID" };
203 struct lustre_handle conn = {0, };
204 struct obd_import *imp;
207 cfs_proc_dir_entry_t *lov_proc_dir;
212 if (!lov->lov_tgts[index])
215 tgt_uuid = lov->lov_tgts[index]->ltd_uuid;
217 tgt_obd = class_find_client_obd(&tgt_uuid, LUSTRE_OSC_NAME,
221 CERROR("Target %s not attached\n", obd_uuid2str(&tgt_uuid));
224 if (!tgt_obd->obd_set_up) {
225 CERROR("Target %s not set up\n", obd_uuid2str(&tgt_uuid));
229 if (data && (data->ocd_connect_flags & OBD_CONNECT_INDEX))
230 data->ocd_index = index;
233 * Divine LOV knows that OBDs under it are OSCs.
235 imp = tgt_obd->u.cli.cl_import;
238 tgt_obd->obd_no_recov = 0;
239 /* FIXME this is probably supposed to be
240 ptlrpc_set_import_active. Horrible naming. */
241 ptlrpc_activate_import(imp);
244 if (imp->imp_invalid) {
245 CERROR("not connecting OSC %s; administratively "
246 "disabled\n", obd_uuid2str(&tgt_uuid));
247 rc = obd_register_observer(tgt_obd, obd);
249 CERROR("Target %s register_observer error %d; "
250 "will not be able to reactivate\n",
251 obd_uuid2str(&tgt_uuid), rc);
256 rc = obd_connect(NULL, &conn, tgt_obd, &lov_osc_uuid, data, NULL);
258 CERROR("Target %s connect error %d\n",
259 obd_uuid2str(&tgt_uuid), rc);
262 lov->lov_tgts[index]->ltd_exp = class_conn2export(&conn);
263 if (!lov->lov_tgts[index]->ltd_exp) {
264 CERROR("Target %s: null export!\n", obd_uuid2str(&tgt_uuid));
268 rc = obd_register_page_removal_cb(lov->lov_tgts[index]->ltd_exp,
269 lov->lov_page_removal_cb,
270 lov->lov_page_pin_cb);
272 obd_disconnect(lov->lov_tgts[index]->ltd_exp);
273 lov->lov_tgts[index]->ltd_exp = NULL;
277 rc = obd_register_lock_cancel_cb(lov->lov_tgts[index]->ltd_exp,
278 lov->lov_lock_cancel_cb);
280 obd_unregister_page_removal_cb(lov->lov_tgts[index]->ltd_exp,
281 lov->lov_page_removal_cb);
282 obd_disconnect(lov->lov_tgts[index]->ltd_exp);
283 lov->lov_tgts[index]->ltd_exp = NULL;
287 rc = obd_register_observer(tgt_obd, obd);
289 CERROR("Target %s register_observer error %d\n",
290 obd_uuid2str(&tgt_uuid), rc);
291 obd_unregister_lock_cancel_cb(lov->lov_tgts[index]->ltd_exp,
292 lov->lov_lock_cancel_cb);
293 obd_unregister_page_removal_cb(lov->lov_tgts[index]->ltd_exp,
294 lov->lov_page_removal_cb);
295 obd_disconnect(lov->lov_tgts[index]->ltd_exp);
296 lov->lov_tgts[index]->ltd_exp = NULL;
300 lov->lov_tgts[index]->ltd_reap = 0;
302 lov->lov_tgts[index]->ltd_active = 1;
303 lov->desc.ld_active_tgt_count++;
304 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 0;
306 CDEBUG(D_CONFIG, "Connected tgt idx %d %s (%s) %sactive\n", index,
307 obd_uuid2str(&tgt_uuid), tgt_obd->obd_name, activate ? "":"in");
310 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
312 struct obd_device *osc_obd = class_conn2obd(&conn);
313 cfs_proc_dir_entry_t *osc_symlink;
314 char name[MAX_STRING_SIZE];
316 LASSERT(osc_obd != NULL);
317 LASSERT(osc_obd->obd_magic == OBD_DEVICE_MAGIC);
318 LASSERT(osc_obd->obd_type->typ_name != NULL);
319 snprintf(name, MAX_STRING_SIZE, "../../../%s/%s",
320 osc_obd->obd_type->typ_name,
322 osc_symlink = lprocfs_add_symlink(osc_obd->obd_name, lov_proc_dir,
324 if (osc_symlink == NULL) {
325 CERROR("could not register LOV target "
326 "/proc/fs/lustre/%s/%s/target_obds/%s.",
327 obd->obd_type->typ_name, obd->obd_name,
329 lprocfs_remove(&lov_proc_dir);
334 rc = qos_add_tgt(obd, index);
336 CERROR("qos_add_tgt failed %d\n", rc);
341 static int lov_connect(const struct lu_env *env,
342 struct lustre_handle *conn, struct obd_device *obd,
343 struct obd_uuid *cluuid, struct obd_connect_data *data,
346 struct lov_obd *lov = &obd->u.lov;
347 struct lov_tgt_desc *tgt;
351 CDEBUG(D_CONFIG, "connect #%d\n", lov->lov_connects);
353 rc = class_connect(conn, obd, cluuid);
357 /* Why should there ever be more than 1 connect? */
359 LASSERT(lov->lov_connects == 1);
361 memset(&lov->lov_ocd, 0, sizeof(lov->lov_ocd));
363 lov->lov_ocd = *data;
366 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
367 tgt = lov->lov_tgts[i];
368 if (!tgt || obd_uuid_empty(&tgt->ltd_uuid))
370 /* Flags will be lowest common denominator */
371 rc = lov_connect_obd(obd, i, tgt->ltd_activate, &lov->lov_ocd);
373 CERROR("%s: lov connect tgt %d failed: %d\n",
374 obd->obd_name, i, rc);
383 static int lov_disconnect_obd(struct obd_device *obd, __u32 index)
385 cfs_proc_dir_entry_t *lov_proc_dir;
386 struct lov_obd *lov = &obd->u.lov;
387 struct obd_device *osc_obd;
392 if (lov->lov_tgts[index] == NULL)
395 osc_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
396 CDEBUG(D_CONFIG, "%s: disconnecting target %s\n",
397 obd->obd_name, osc_obd->obd_name);
399 obd_unregister_lock_cancel_cb(lov->lov_tgts[index]->ltd_exp,
400 lov->lov_lock_cancel_cb);
401 obd_unregister_page_removal_cb(lov->lov_tgts[index]->ltd_exp,
402 lov->lov_page_removal_cb);
404 if (lov->lov_tgts[index]->ltd_active) {
405 lov->lov_tgts[index]->ltd_active = 0;
406 lov->desc.ld_active_tgt_count--;
407 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 1;
410 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
412 cfs_proc_dir_entry_t *osc_symlink;
414 osc_symlink = lprocfs_srch(lov_proc_dir, osc_obd->obd_name);
416 lprocfs_remove(&osc_symlink);
418 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing.",
419 obd->obd_type->typ_name, obd->obd_name,
425 /* Pass it on to our clients.
426 * XXX This should be an argument to disconnect,
427 * XXX not a back-door flag on the OBD. Ah well.
429 osc_obd->obd_force = obd->obd_force;
430 osc_obd->obd_fail = obd->obd_fail;
431 osc_obd->obd_no_recov = obd->obd_no_recov;
434 obd_register_observer(osc_obd, NULL);
436 rc = obd_disconnect(lov->lov_tgts[index]->ltd_exp);
438 CERROR("Target %s disconnect error %d\n",
439 lov_uuid2str(lov, index), rc);
443 qos_del_tgt(obd, index);
445 lov->lov_tgts[index]->ltd_exp = NULL;
449 static int lov_del_target(struct obd_device *obd, __u32 index,
450 struct obd_uuid *uuidp, int gen);
452 static int lov_disconnect(struct obd_export *exp)
454 struct obd_device *obd = class_exp2obd(exp);
455 struct lov_obd *lov = &obd->u.lov;
462 /* Only disconnect the underlying layers on the final disconnect. */
464 if (lov->lov_connects != 0) {
465 /* why should there be more than 1 connect? */
466 CERROR("disconnect #%d\n", lov->lov_connects);
470 /* Let's hold another reference so lov_del_obd doesn't spin through
473 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
474 if (lov->lov_tgts[i] && lov->lov_tgts[i]->ltd_exp) {
475 /* Disconnection is the last we know about an obd */
476 lov_del_target(obd, i, 0, lov->lov_tgts[i]->ltd_gen);
482 rc = class_disconnect(exp); /* bz 9811 */
488 * -EINVAL : UUID can't be found in the LOV's target list
489 * - any other is lov index
491 static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
494 struct lov_obd *lov = &obd->u.lov;
495 struct lov_tgt_desc *tgt;
499 CDEBUG(D_INFO, "Searching in lov %p for uuid %s (activate=%d)\n",
500 lov, uuid->uuid, activate);
503 for (index = 0; index < lov->desc.ld_tgt_count; index++) {
504 tgt = lov->lov_tgts[index];
505 if (!tgt || !tgt->ltd_exp)
508 CDEBUG(D_INFO, "lov idx %d is %s conn "LPX64"\n",
509 index, obd_uuid2str(&tgt->ltd_uuid),
510 tgt->ltd_exp->exp_handle.h_cookie);
511 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
515 if (index == lov->desc.ld_tgt_count)
516 GOTO(out, index = -EINVAL);
518 if (lov->lov_tgts[index]->ltd_active == activate) {
519 CDEBUG(D_INFO, "OSC %s already %sactive!\n", uuid->uuid,
520 activate ? "" : "in");
524 CDEBUG(D_CONFIG, "Marking OSC %s %sactive\n", obd_uuid2str(uuid),
525 activate ? "" : "in");
527 lov->lov_tgts[index]->ltd_active = activate;
530 lov->desc.ld_active_tgt_count++;
531 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 0;
533 lov->desc.ld_active_tgt_count--;
534 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 1;
536 /* remove any old qos penalty */
537 lov->lov_tgts[index]->ltd_qos.ltq_penalty = 0;
544 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
545 enum obd_notify_event ev, void *data)
550 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
551 struct obd_uuid *uuid;
555 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
556 CERROR("unexpected notification of %s %s!\n",
557 watched->obd_type->typ_name,
561 uuid = &watched->u.cli.cl_target_uuid;
563 /* Set OSC as active before notifying the observer, so the
564 * observer can use the OSC normally.
566 rc = lov_set_osc_active(obd, uuid, ev == OBD_NOTIFY_ACTIVE);
568 CERROR("%sactivation of %s failed: %d\n",
569 (ev == OBD_NOTIFY_ACTIVE) ? "" : "de",
570 obd_uuid2str(uuid), rc);
576 /* Pass the notification up the chain. */
578 rc = obd_notify_observer(obd, watched, ev, data);
580 /* NULL watched means all osc's in the lov (only for syncs) */
581 /* sync event should be send lov idx as data */
582 struct lov_obd *lov = &obd->u.lov;
583 struct obd_device *tgt_obd;
586 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
587 if (!lov->lov_tgts[i])
590 if ((ev == OBD_NOTIFY_SYNC) ||
591 (ev == OBD_NOTIFY_SYNC_NONBLOCK))
594 tgt_obd = class_exp2obd(lov->lov_tgts[i]->ltd_exp);
595 rc = obd_notify_observer(obd, tgt_obd, ev, data);
597 CERROR("%s: notify %s of %s failed %d\n",
599 obd->obd_observer->obd_name,
600 tgt_obd->obd_name, rc);
610 static int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
611 __u32 index, int gen, int active)
613 struct lov_obd *lov = &obd->u.lov;
614 struct lov_tgt_desc *tgt;
618 CDEBUG(D_CONFIG, "uuid:%s idx:%d gen:%d active:%d\n",
619 uuidp->uuid, index, gen, active);
622 CERROR("request to add OBD %s with invalid generation: %d\n",
627 mutex_down(&lov->lov_lock);
629 if ((index < lov->lov_tgt_size) && (lov->lov_tgts[index] != NULL)) {
630 tgt = lov->lov_tgts[index];
631 CERROR("UUID %s already assigned at LOV target index %d\n",
632 obd_uuid2str(&tgt->ltd_uuid), index);
633 mutex_up(&lov->lov_lock);
637 if (index >= lov->lov_tgt_size) {
638 /* We need to reallocate the lov target array. */
639 struct lov_tgt_desc **newtgts, **old = NULL;
640 __u32 newsize, oldsize = 0;
642 newsize = max(lov->lov_tgt_size, (__u32)2);
643 while (newsize < index + 1)
644 newsize = newsize << 1;
645 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
646 if (newtgts == NULL) {
647 mutex_up(&lov->lov_lock);
651 if (lov->lov_tgt_size) {
652 memcpy(newtgts, lov->lov_tgts, sizeof(*newtgts) *
655 oldsize = lov->lov_tgt_size;
658 lov->lov_tgts = newtgts;
659 lov->lov_tgt_size = newsize;
664 OBD_FREE(old, sizeof(*old) * oldsize);
666 CDEBUG(D_CONFIG, "tgts: %p size: %d\n",
667 lov->lov_tgts, lov->lov_tgt_size);
672 mutex_up(&lov->lov_lock);
676 memset(tgt, 0, sizeof(*tgt));
677 tgt->ltd_uuid = *uuidp;
678 /* XXX - add a sanity check on the generation number. */
680 tgt->ltd_index = index;
681 tgt->ltd_activate = active;
682 lov->lov_tgts[index] = tgt;
683 if (index >= lov->desc.ld_tgt_count)
684 lov->desc.ld_tgt_count = index + 1;
686 rc = lov_ost_pool_add(&lov->lov_packed, index, lov->lov_tgt_size);
690 mutex_up(&lov->lov_lock);
692 CDEBUG(D_CONFIG, "idx=%d ltd_gen=%d ld_tgt_count=%d\n",
693 index, tgt->ltd_gen, lov->desc.ld_tgt_count);
695 if (lov->lov_connects == 0) {
696 /* lov_connect hasn't been called yet. We'll do the
697 lov_connect_obd on this target when that fn first runs,
698 because we don't know the connect flags yet. */
704 rc = lov_connect_obd(obd, index, active, &lov->lov_ocd);
708 rc = lov_notify(obd, tgt->ltd_exp->exp_obd,
709 active ? OBD_NOTIFY_ACTIVE : OBD_NOTIFY_INACTIVE,
714 CERROR("add failed (%d), deleting %s\n", rc,
715 obd_uuid2str(&tgt->ltd_uuid));
716 lov_del_target(obd, index, 0, 0);
722 /* Schedule a target for deletion */
723 static int lov_del_target(struct obd_device *obd, __u32 index,
724 struct obd_uuid *uuidp, int gen)
726 struct lov_obd *lov = &obd->u.lov;
727 int count = lov->desc.ld_tgt_count;
731 if (index >= count) {
732 CERROR("LOV target index %d >= number of LOV OBDs %d.\n",
739 if (!lov->lov_tgts[index]) {
740 CERROR("LOV target at index %d is not setup.\n", index);
741 GOTO(out, rc = -EINVAL);
744 if (uuidp && !obd_uuid_equals(uuidp, &lov->lov_tgts[index]->ltd_uuid)) {
745 CERROR("LOV target UUID %s at index %d doesn't match %s.\n",
746 lov_uuid2str(lov, index), index,
747 obd_uuid2str(uuidp));
748 GOTO(out, rc = -EINVAL);
751 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d exp: %p active: %d\n",
752 lov_uuid2str(lov, index), index,
753 lov->lov_tgts[index]->ltd_gen, lov->lov_tgts[index]->ltd_exp,
754 lov->lov_tgts[index]->ltd_active);
756 lov->lov_tgts[index]->ltd_reap = 1;
757 lov->lov_death_row++;
758 /* we really delete it from lov_putref */
765 /* We are holding lov_lock */
766 static void __lov_del_obd(struct obd_device *obd, __u32 index)
768 struct lov_obd *lov = &obd->u.lov;
769 struct obd_device *osc_obd;
770 struct lov_tgt_desc *tgt = lov->lov_tgts[index];
773 LASSERT(tgt->ltd_reap);
775 osc_obd = class_exp2obd(tgt->ltd_exp);
777 CDEBUG(D_CONFIG, "Removing tgt %s : %s\n",
778 lov_uuid2str(lov, index),
779 osc_obd ? osc_obd->obd_name : "<no obd>");
782 lov_disconnect_obd(obd, index);
784 /* XXX - right now there is a dependency on ld_tgt_count being the
785 * maximum tgt index for computing the mds_max_easize. So we can't
788 lov_ost_pool_remove(&lov->lov_packed, index);
789 lov->lov_tgts[index] = NULL;
792 /* Manual cleanup - no cleanup logs to clean up the osc's. We must
793 do it ourselves. And we can't do it from lov_cleanup,
794 because we just lost our only reference to it. */
796 class_manual_cleanup(osc_obd);
799 void lov_fix_desc_stripe_size(__u64 *val)
801 if (*val < PTLRPC_MAX_BRW_SIZE) {
802 LCONSOLE_WARN("Increasing default stripe size to min %u\n",
803 PTLRPC_MAX_BRW_SIZE);
804 *val = PTLRPC_MAX_BRW_SIZE;
805 } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) {
806 *val &= ~(LOV_MIN_STRIPE_SIZE - 1);
807 LCONSOLE_WARN("Changing default stripe size to "LPU64" (a "
809 *val, LOV_MIN_STRIPE_SIZE);
813 void lov_fix_desc_stripe_count(__u32 *val)
819 void lov_fix_desc_pattern(__u32 *val)
821 /* from lov_setstripe */
822 if ((*val != 0) && (*val != LOV_PATTERN_RAID0)) {
823 LCONSOLE_WARN("Unknown stripe pattern: %#x\n", *val);
828 void lov_fix_desc_qos_maxage(__u32 *val)
832 *val = QOS_DEFAULT_MAXAGE;
835 void lov_fix_desc(struct lov_desc *desc)
837 lov_fix_desc_stripe_size(&desc->ld_default_stripe_size);
838 lov_fix_desc_stripe_count(&desc->ld_default_stripe_count);
839 lov_fix_desc_pattern(&desc->ld_pattern);
840 lov_fix_desc_qos_maxage(&desc->ld_qos_maxage);
843 static int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
845 struct lprocfs_static_vars lvars = { 0 };
846 struct lov_desc *desc;
847 struct lov_obd *lov = &obd->u.lov;
852 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
853 CERROR("LOV setup requires a descriptor\n");
857 desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
859 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
860 CERROR("descriptor size wrong: %d > %d\n",
861 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
865 if (desc->ld_magic != LOV_DESC_MAGIC) {
866 if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
867 CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n",
868 obd->obd_name, desc);
869 lustre_swab_lov_desc(desc);
871 CERROR("%s: Bad lov desc magic: %#x\n",
872 obd->obd_name, desc->ld_magic);
879 /* Because of 64-bit divide/mod operations only work with a 32-bit
880 * divisor in a 32-bit kernel, we cannot support a stripe width
881 * of 4GB or larger on 32-bit CPUs. */
882 count = desc->ld_default_stripe_count;
883 if ((count > 0 ? count : desc->ld_tgt_count) *
884 desc->ld_default_stripe_size > 0xffffffff) {
885 CERROR("LOV: stripe width "LPU64"x%u > 4294967295 bytes\n",
886 desc->ld_default_stripe_size, count);
890 desc->ld_active_tgt_count = 0;
892 lov->lov_tgt_size = 0;
894 sema_init(&lov->lov_lock, 1);
895 atomic_set(&lov->lov_refcount, 0);
896 CFS_INIT_LIST_HEAD(&lov->lov_qos.lq_oss_list);
897 init_rwsem(&lov->lov_qos.lq_rw_sem);
898 lov->lov_qos.lq_dirty = 1;
899 lov->lov_qos.lq_rr.lqr_dirty = 1;
900 lov->lov_qos.lq_reset = 1;
901 /* Default priority is toward free space balance */
902 lov->lov_qos.lq_prio_free = 232;
904 lov->lov_pools_hash_body = lustre_hash_init("POOLS", 128, 128,
905 &pool_hash_operations, 0);
906 CFS_INIT_LIST_HEAD(&lov->lov_pool_list);
907 lov->lov_pool_count = 0;
908 rc = lov_ost_pool_init(&lov->lov_packed, 0);
911 rc = lov_ost_pool_init(&lov->lov_qos.lq_rr.lqr_pool, 0);
913 lov_ost_pool_free(&lov->lov_packed);
917 lprocfs_lov_init_vars(&lvars);
918 lprocfs_obd_setup(obd, lvars.obd_vars);
923 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
924 0444, &lov_proc_target_fops, obd);
926 CWARN("Error adding the target_obd file\n");
929 lov->lov_pool_proc_entry = lprocfs_register("pools",
936 static int lov_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
942 case OBD_CLEANUP_EARLY: {
943 struct lov_obd *lov = &obd->u.lov;
945 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
946 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
948 obd_precleanup(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
953 case OBD_CLEANUP_EXPORTS:
954 rc = obd_llog_finish(obd, 0);
956 CERROR("failed to cleanup llogging subsystems\n");
962 static int lov_cleanup(struct obd_device *obd)
964 struct lov_obd *lov = &obd->u.lov;
965 struct list_head *pos, *tmp;
966 struct pool_desc *pool;
968 lprocfs_obd_cleanup(obd);
970 list_for_each_safe(pos, tmp, &lov->lov_pool_list) {
971 pool = list_entry(pos, struct pool_desc, pool_list);
972 list_del(&pool->pool_list);
973 lov_ost_pool_free(&(pool->pool_rr.lqr_pool));
974 lov_ost_pool_free(&(pool->pool_obds));
977 lov_ost_pool_free(&(lov->lov_qos.lq_rr.lqr_pool));
978 lov_ost_pool_free(&lov->lov_packed);
979 lustre_hash_exit(lov->lov_pools_hash_body);
983 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
984 if (!lov->lov_tgts[i])
987 /* Inactive targets may never have connected */
988 if (lov->lov_tgts[i]->ltd_active ||
989 atomic_read(&lov->lov_refcount))
990 /* We should never get here - these
991 should have been removed in the
993 CERROR("lov tgt %d not cleaned!"
994 " deathrow=%d, lovrc=%d\n",
995 i, lov->lov_death_row,
996 atomic_read(&lov->lov_refcount));
997 lov_del_target(obd, i, 0, 0);
999 OBD_FREE(lov->lov_tgts, sizeof(*lov->lov_tgts) *
1001 lov->lov_tgt_size = 0;
1007 static int lov_process_config(struct obd_device *obd, obd_count len, void *buf)
1009 struct lustre_cfg *lcfg = buf;
1010 struct obd_uuid obd_uuid;
1015 switch(cmd = lcfg->lcfg_command) {
1016 case LCFG_LOV_ADD_OBD:
1017 case LCFG_LOV_ADD_INA:
1018 case LCFG_LOV_DEL_OBD: {
1021 /* lov_modify_tgts add 0:lov_mdsA 1:ost1_UUID 2:0 3:1 */
1022 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
1023 GOTO(out, rc = -EINVAL);
1025 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1027 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
1028 GOTO(out, rc = -EINVAL);
1029 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
1030 GOTO(out, rc = -EINVAL);
1031 if (cmd == LCFG_LOV_ADD_OBD)
1032 rc = lov_add_target(obd, &obd_uuid, index, gen, 1);
1033 else if (cmd == LCFG_LOV_ADD_INA)
1034 rc = lov_add_target(obd, &obd_uuid, index, gen, 0);
1036 rc = lov_del_target(obd, index, &obd_uuid, gen);
1040 struct lprocfs_static_vars lvars = { 0 };
1041 struct lov_desc *desc = &(obd->u.lov.desc);
1044 GOTO(out, rc = -EINVAL);
1046 lprocfs_lov_init_vars(&lvars);
1048 rc = class_process_proc_param(PARAM_LOV, lvars.obd_vars,
1059 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1060 GOTO(out, rc = -EINVAL);
1069 #define log2(n) ffz(~(n))
1072 static int lov_clear_orphans(struct obd_export *export, struct obdo *src_oa,
1073 struct lov_stripe_md **ea,
1074 struct obd_trans_info *oti)
1076 struct lov_obd *lov;
1077 struct obdo *tmp_oa;
1078 struct obd_uuid *ost_uuid = NULL;
1082 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
1083 src_oa->o_flags == OBD_FL_DELORPHAN);
1085 lov = &export->exp_obd->u.lov;
1091 if (oti->oti_ost_uuid) {
1092 ost_uuid = oti->oti_ost_uuid;
1093 CDEBUG(D_HA, "clearing orphans only for %s\n",
1097 lov_getref(export->exp_obd);
1098 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1099 struct lov_stripe_md obj_md;
1100 struct lov_stripe_md *obj_mdp = &obj_md;
1101 struct lov_tgt_desc *tgt;
1104 tgt = lov->lov_tgts[i];
1108 /* if called for a specific target, we don't
1109 care if it is not active. */
1110 if (!lov->lov_tgts[i]->ltd_active && ost_uuid == NULL) {
1111 CDEBUG(D_HA, "lov idx %d inactive\n", i);
1115 if (ost_uuid && !obd_uuid_equals(ost_uuid, &tgt->ltd_uuid))
1118 CDEBUG(D_CONFIG,"Clear orphans for %d:%s\n", i,
1119 obd_uuid2str(ost_uuid));
1121 memcpy(tmp_oa, src_oa, sizeof(*tmp_oa));
1123 LASSERT(lov->lov_tgts[i]->ltd_exp);
1124 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1125 err = obd_create(lov->lov_tgts[i]->ltd_exp,
1126 tmp_oa, &obj_mdp, oti);
1128 /* This export will be disabled until it is recovered,
1129 and then orphan recovery will be completed. */
1130 CERROR("error in orphan recovery on OST idx %d/%d: "
1131 "rc = %d\n", i, lov->desc.ld_tgt_count, err);
1138 lov_putref(export->exp_obd);
1144 static int lov_recreate(struct obd_export *exp, struct obdo *src_oa,
1145 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1147 struct lov_stripe_md *obj_mdp, *lsm;
1148 struct lov_obd *lov = &exp->exp_obd->u.lov;
1153 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
1154 src_oa->o_flags & OBD_FL_RECREATE_OBJS);
1156 OBD_ALLOC(obj_mdp, sizeof(*obj_mdp));
1157 if (obj_mdp == NULL)
1160 ost_idx = src_oa->o_nlink;
1163 GOTO(out, rc = -EINVAL);
1164 if (ost_idx >= lov->desc.ld_tgt_count ||
1165 !lov->lov_tgts[ost_idx])
1166 GOTO(out, rc = -EINVAL);
1168 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1169 if (lsm->lsm_oinfo[i]->loi_ost_idx == ost_idx) {
1170 if (lsm->lsm_oinfo[i]->loi_id != src_oa->o_id)
1171 GOTO(out, rc = -EINVAL);
1175 if (i == lsm->lsm_stripe_count)
1176 GOTO(out, rc = -EINVAL);
1178 rc = obd_create(lov->lov_tgts[ost_idx]->ltd_exp, src_oa, &obj_mdp, oti);
1180 OBD_FREE(obj_mdp, sizeof(*obj_mdp));
1184 /* the LOV expects oa->o_id to be set to the LOV object id */
1185 static int lov_create(struct obd_export *exp, struct obdo *src_oa,
1186 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1188 struct lov_obd *lov;
1189 struct obd_info oinfo;
1190 struct lov_request_set *set = NULL;
1191 struct lov_request *req;
1192 struct obd_statfs osfs;
1197 LASSERT(ea != NULL);
1201 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1202 src_oa->o_flags == OBD_FL_DELORPHAN) {
1203 rc = lov_clear_orphans(exp, src_oa, ea, oti);
1207 lov = &exp->exp_obd->u.lov;
1208 if (!lov->desc.ld_active_tgt_count)
1211 /* Recreate a specific object id at the given OST index */
1212 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1213 (src_oa->o_flags & OBD_FL_RECREATE_OBJS)) {
1214 rc = lov_recreate(exp, src_oa, ea, oti);
1218 maxage = cfs_time_shift_64(-lov->desc.ld_qos_maxage);
1219 obd_statfs_rqset(exp->exp_obd, &osfs, maxage, OBD_STATFS_NODELAY);
1221 rc = lov_prep_create_set(exp, &oinfo, ea, src_oa, oti, &set);
1225 list_for_each_entry(req, &set->set_list, rq_link) {
1226 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1227 rc = obd_create(lov->lov_tgts[req->rq_idx]->ltd_exp,
1228 req->rq_oi.oi_oa, &req->rq_oi.oi_md, oti);
1229 lov_update_create_set(set, req, rc);
1231 rc = lov_fini_create_set(set, ea);
1235 #define ASSERT_LSM_MAGIC(lsmp) \
1237 LASSERT((lsmp) != NULL); \
1238 LASSERTF(((lsmp)->lsm_magic == LOV_MAGIC_V1 || \
1239 (lsmp)->lsm_magic == LOV_MAGIC_V3 || \
1240 (lsmp)->lsm_magic == LOV_MAGIC_JOIN), "%p->lsm_magic=%x\n", \
1241 (lsmp), (lsmp)->lsm_magic); \
1244 static int lov_destroy(struct obd_export *exp, struct obdo *oa,
1245 struct lov_stripe_md *lsm, struct obd_trans_info *oti,
1246 struct obd_export *md_exp)
1248 struct lov_request_set *set;
1249 struct obd_info oinfo;
1250 struct lov_request *req;
1251 struct list_head *pos;
1252 struct lov_obd *lov;
1256 ASSERT_LSM_MAGIC(lsm);
1258 if (!exp || !exp->exp_obd)
1261 if (oa->o_valid & OBD_MD_FLCOOKIE) {
1263 LASSERT(oti->oti_logcookies);
1266 lov = &exp->exp_obd->u.lov;
1267 rc = lov_prep_destroy_set(exp, &oinfo, oa, lsm, oti, &set);
1271 list_for_each (pos, &set->set_list) {
1273 req = list_entry(pos, struct lov_request, rq_link);
1275 if (oa->o_valid & OBD_MD_FLCOOKIE)
1276 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1278 err = obd_destroy(lov->lov_tgts[req->rq_idx]->ltd_exp,
1279 req->rq_oi.oi_oa, NULL, oti, NULL);
1280 err = lov_update_common_set(set, req, err);
1282 CERROR("error: destroying objid "LPX64" subobj "
1283 LPX64" on OST idx %d: rc = %d\n",
1284 oa->o_id, req->rq_oi.oi_oa->o_id,
1292 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
1293 rc = lsm_op_find(lsm->lsm_magic)->lsm_destroy(lsm, oa, md_exp);
1295 err = lov_fini_destroy_set(set);
1296 RETURN(rc ? rc : err);
1299 static int lov_getattr(struct obd_export *exp, struct obd_info *oinfo)
1301 struct lov_request_set *set;
1302 struct lov_request *req;
1303 struct list_head *pos;
1304 struct lov_obd *lov;
1305 int err = 0, rc = 0;
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, &set);
1320 list_for_each (pos, &set->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);
1327 rc = obd_getattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1329 err = lov_update_common_set(set, req, rc);
1331 CERROR("error: getattr objid "LPX64" subobj "
1332 LPX64" on OST idx %d: rc = %d\n",
1333 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1339 rc = lov_fini_getattr_set(set);
1345 static int lov_getattr_interpret(struct ptlrpc_request_set *rqset,
1348 struct lov_request_set *lovset = (struct lov_request_set *)data;
1352 /* don't do attribute merge if this aysnc op failed */
1354 lovset->set_completes = 0;
1355 err = lov_fini_getattr_set(lovset);
1356 RETURN(rc ? rc : err);
1359 static int lov_getattr_async(struct obd_export *exp, struct obd_info *oinfo,
1360 struct ptlrpc_request_set *rqset)
1362 struct lov_request_set *lovset;
1363 struct lov_obd *lov;
1364 struct list_head *pos;
1365 struct lov_request *req;
1370 ASSERT_LSM_MAGIC(oinfo->oi_md);
1372 if (!exp || !exp->exp_obd)
1375 lov = &exp->exp_obd->u.lov;
1377 rc = lov_prep_getattr_set(exp, oinfo, &lovset);
1381 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1382 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1383 oinfo->oi_md->lsm_stripe_size);
1385 list_for_each (pos, &lovset->set_list) {
1386 req = list_entry(pos, struct lov_request, rq_link);
1388 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1389 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1390 req->rq_oi.oi_oa->o_id, req->rq_idx);
1391 rc = obd_getattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1392 &req->rq_oi, rqset);
1394 CERROR("error: getattr objid "LPX64" subobj "
1395 LPX64" on OST idx %d: rc = %d\n",
1396 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1402 if (!list_empty(&rqset->set_requests)) {
1404 LASSERT (rqset->set_interpret == NULL);
1405 rqset->set_interpret = lov_getattr_interpret;
1406 rqset->set_arg = (void *)lovset;
1411 lovset->set_completes = 0;
1412 err = lov_fini_getattr_set(lovset);
1413 RETURN(rc ? rc : err);
1416 static int lov_setattr(struct obd_export *exp, struct obd_info *oinfo,
1417 struct obd_trans_info *oti)
1419 struct lov_request_set *set;
1420 struct lov_obd *lov;
1421 struct list_head *pos;
1422 struct lov_request *req;
1423 int err = 0, rc = 0;
1427 ASSERT_LSM_MAGIC(oinfo->oi_md);
1429 if (!exp || !exp->exp_obd)
1432 /* for now, we only expect the following updates here */
1433 LASSERT(!(oinfo->oi_oa->o_valid & ~(OBD_MD_FLID | OBD_MD_FLTYPE |
1434 OBD_MD_FLMODE | OBD_MD_FLATIME |
1435 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1436 OBD_MD_FLFLAGS | OBD_MD_FLSIZE |
1437 OBD_MD_FLGROUP | OBD_MD_FLUID |
1438 OBD_MD_FLGID | OBD_MD_FLFID |
1440 lov = &exp->exp_obd->u.lov;
1441 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1445 list_for_each (pos, &set->set_list) {
1446 req = list_entry(pos, struct lov_request, rq_link);
1448 rc = obd_setattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1450 err = lov_update_setattr_set(set, req, rc);
1452 CERROR("error: setattr objid "LPX64" subobj "
1453 LPX64" on OST idx %d: rc = %d\n",
1454 set->set_oi->oi_oa->o_id,
1455 req->rq_oi.oi_oa->o_id, req->rq_idx, err);
1460 err = lov_fini_setattr_set(set);
1466 static int lov_setattr_interpret(struct ptlrpc_request_set *rqset,
1469 struct lov_request_set *lovset = (struct lov_request_set *)data;
1474 lovset->set_completes = 0;
1475 err = lov_fini_setattr_set(lovset);
1476 RETURN(rc ? rc : err);
1479 /* If @oti is given, the request goes from MDS and responses from OSTs are not
1480 needed. Otherwise, a client is waiting for responses. */
1481 static int lov_setattr_async(struct obd_export *exp, struct obd_info *oinfo,
1482 struct obd_trans_info *oti,
1483 struct ptlrpc_request_set *rqset)
1485 struct lov_request_set *set;
1486 struct lov_request *req;
1487 struct list_head *pos;
1488 struct lov_obd *lov;
1493 ASSERT_LSM_MAGIC(oinfo->oi_md);
1494 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE) {
1496 LASSERT(oti->oti_logcookies);
1499 if (!exp || !exp->exp_obd)
1502 lov = &exp->exp_obd->u.lov;
1503 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1507 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1508 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1509 oinfo->oi_md->lsm_stripe_size);
1511 list_for_each (pos, &set->set_list) {
1512 req = list_entry(pos, struct lov_request, rq_link);
1514 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
1515 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1517 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1518 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1519 req->rq_oi.oi_oa->o_id, req->rq_idx);
1521 rc = obd_setattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1522 &req->rq_oi, oti, rqset);
1524 CERROR("error: setattr objid "LPX64" subobj "
1525 LPX64" on OST idx %d: rc = %d\n",
1526 set->set_oi->oi_oa->o_id,
1527 req->rq_oi.oi_oa->o_id,
1533 /* If we are not waiting for responses on async requests, return. */
1534 if (rc || !rqset || list_empty(&rqset->set_requests)) {
1537 set->set_completes = 0;
1538 err = lov_fini_setattr_set(set);
1539 RETURN(rc ? rc : err);
1542 LASSERT(rqset->set_interpret == NULL);
1543 rqset->set_interpret = lov_setattr_interpret;
1544 rqset->set_arg = (void *)set;
1549 static int lov_punch_interpret(struct ptlrpc_request_set *rqset,
1552 struct lov_request_set *lovset = (struct lov_request_set *)data;
1557 lovset->set_completes = 0;
1558 err = lov_fini_punch_set(lovset);
1559 RETURN(rc ? rc : err);
1562 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
1563 * we can send this 'punch' to just the authoritative node and the nodes
1564 * that the punch will affect. */
1565 static int lov_punch(struct obd_export *exp, struct obd_info *oinfo,
1566 struct obd_trans_info *oti,
1567 struct ptlrpc_request_set *rqset)
1569 struct lov_request_set *set;
1570 struct lov_obd *lov;
1571 struct list_head *pos;
1572 struct lov_request *req;
1577 ASSERT_LSM_MAGIC(oinfo->oi_md);
1579 if (!exp || !exp->exp_obd)
1582 lov = &exp->exp_obd->u.lov;
1583 rc = lov_prep_punch_set(exp, oinfo, oti, &set);
1587 list_for_each (pos, &set->set_list) {
1588 req = list_entry(pos, struct lov_request, rq_link);
1590 rc = obd_punch(lov->lov_tgts[req->rq_idx]->ltd_exp,
1591 &req->rq_oi, NULL, rqset);
1593 CERROR("error: punch objid "LPX64" subobj "LPX64
1594 " on OST idx %d: rc = %d\n",
1595 set->set_oi->oi_oa->o_id,
1596 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1601 if (rc || list_empty(&rqset->set_requests)) {
1603 err = lov_fini_punch_set(set);
1604 RETURN(rc ? rc : err);
1607 LASSERT(rqset->set_interpret == NULL);
1608 rqset->set_interpret = lov_punch_interpret;
1609 rqset->set_arg = (void *)set;
1614 static int lov_sync(struct obd_export *exp, struct obdo *oa,
1615 struct lov_stripe_md *lsm, obd_off start, obd_off end,
1618 struct lov_request_set *set;
1619 struct obd_info oinfo;
1620 struct lov_obd *lov;
1621 struct list_head *pos;
1622 struct lov_request *req;
1623 int err = 0, rc = 0;
1626 ASSERT_LSM_MAGIC(lsm);
1631 lov = &exp->exp_obd->u.lov;
1632 rc = lov_prep_sync_set(exp, &oinfo, oa, lsm, start, end, &set);
1636 list_for_each (pos, &set->set_list) {
1637 req = list_entry(pos, struct lov_request, rq_link);
1639 rc = obd_sync(lov->lov_tgts[req->rq_idx]->ltd_exp,
1640 req->rq_oi.oi_oa, NULL,
1641 req->rq_oi.oi_policy.l_extent.start,
1642 req->rq_oi.oi_policy.l_extent.end, capa);
1643 err = lov_update_common_set(set, req, rc);
1645 CERROR("error: fsync objid "LPX64" subobj "LPX64
1646 " on OST idx %d: rc = %d\n",
1647 set->set_oi->oi_oa->o_id,
1648 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1653 err = lov_fini_sync_set(set);
1659 static int lov_brw_check(struct lov_obd *lov, struct obd_info *lov_oinfo,
1660 obd_count oa_bufs, struct brw_page *pga)
1662 struct obd_info oinfo = { { { 0 } } };
1665 oinfo.oi_oa = lov_oinfo->oi_oa;
1667 /* The caller just wants to know if there's a chance that this
1668 * I/O can succeed */
1669 for (i = 0; i < oa_bufs; i++) {
1670 int stripe = lov_stripe_number(lov_oinfo->oi_md, pga[i].off);
1671 int ost = lov_oinfo->oi_md->lsm_oinfo[stripe]->loi_ost_idx;
1674 if (!lov_stripe_intersects(lov_oinfo->oi_md, i, pga[i].off,
1675 pga[i].off + pga[i].count,
1679 if (!lov->lov_tgts[ost] || !lov->lov_tgts[ost]->ltd_active) {
1680 CDEBUG(D_HA, "lov idx %d inactive\n", ost);
1684 rc = obd_brw(OBD_BRW_CHECK, lov->lov_tgts[ost]->ltd_exp, &oinfo,
1692 static int lov_brw(int cmd, struct obd_export *exp, struct obd_info *oinfo,
1693 obd_count oa_bufs, struct brw_page *pga,
1694 struct obd_trans_info *oti)
1696 struct lov_request_set *set;
1697 struct lov_request *req;
1698 struct list_head *pos;
1699 struct lov_obd *lov = &exp->exp_obd->u.lov;
1703 ASSERT_LSM_MAGIC(oinfo->oi_md);
1705 if (cmd == OBD_BRW_CHECK) {
1706 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1710 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &set);
1714 list_for_each (pos, &set->set_list) {
1715 struct obd_export *sub_exp;
1716 struct brw_page *sub_pga;
1717 req = list_entry(pos, struct lov_request, rq_link);
1719 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1720 sub_pga = set->set_pga + req->rq_pgaidx;
1721 rc = obd_brw(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1725 lov_update_common_set(set, req, rc);
1728 err = lov_fini_brw_set(set);
1734 static int lov_brw_interpret(struct ptlrpc_request_set *reqset, void *data,
1737 struct lov_request_set *lovset = (struct lov_request_set *)data;
1741 lovset->set_completes = 0;
1742 lov_fini_brw_set(lovset);
1744 rc = lov_fini_brw_set(lovset);
1750 static int lov_brw_async(int cmd, struct obd_export *exp,
1751 struct obd_info *oinfo, obd_count oa_bufs,
1752 struct brw_page *pga, struct obd_trans_info *oti,
1753 struct ptlrpc_request_set *set)
1755 struct lov_request_set *lovset;
1756 struct lov_request *req;
1757 struct list_head *pos;
1758 struct lov_obd *lov = &exp->exp_obd->u.lov;
1763 ASSERT_LSM_MAGIC(oinfo->oi_md);
1765 if (cmd == OBD_BRW_CHECK) {
1766 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1770 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &lovset);
1774 list_for_each (pos, &lovset->set_list) {
1775 struct obd_export *sub_exp;
1776 struct brw_page *sub_pga;
1777 req = list_entry(pos, struct lov_request, rq_link);
1779 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1780 sub_pga = lovset->set_pga + req->rq_pgaidx;
1781 rc = obd_brw_async(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1785 lov_update_common_set(lovset, req, rc);
1788 LASSERT(set->set_interpret == NULL);
1789 LASSERT(set->set_arg == NULL);
1790 rc = ptlrpc_set_add_cb(set, lov_brw_interpret, lovset);
1796 lov_fini_brw_set(lovset);
1800 static int lov_ap_make_ready(void *data, int cmd)
1802 struct lov_async_page *lap = lap_from_cookie(data);
1804 return lap->lap_caller_ops->ap_make_ready(lap->lap_caller_data, cmd);
1807 static int lov_ap_refresh_count(void *data, int cmd)
1809 struct lov_async_page *lap = lap_from_cookie(data);
1811 return lap->lap_caller_ops->ap_refresh_count(lap->lap_caller_data,
1815 static void lov_ap_fill_obdo(void *data, int cmd, struct obdo *oa)
1817 struct lov_async_page *lap = lap_from_cookie(data);
1819 lap->lap_caller_ops->ap_fill_obdo(lap->lap_caller_data, cmd, oa);
1820 /* XXX woah, shouldn't we be altering more here? size? */
1821 oa->o_id = lap->lap_loi_id;
1822 oa->o_gr = lap->lap_loi_gr;
1823 oa->o_valid |= OBD_MD_FLGROUP;
1824 oa->o_stripe_idx = lap->lap_stripe;
1827 static void lov_ap_update_obdo(void *data, int cmd, struct obdo *oa,
1830 struct lov_async_page *lap = lap_from_cookie(data);
1832 lap->lap_caller_ops->ap_update_obdo(lap->lap_caller_data, cmd,oa,valid);
1835 static int lov_ap_completion(void *data, int cmd, struct obdo *oa, int rc)
1837 struct lov_async_page *lap = lap_from_cookie(data);
1839 /* in a raid1 regime this would down a count of many ios
1840 * in flight, onl calling the caller_ops completion when all
1841 * the raid1 ios are complete */
1842 rc = lap->lap_caller_ops->ap_completion(lap->lap_caller_data,cmd,oa,rc);
1846 static struct obd_capa *lov_ap_lookup_capa(void *data, int cmd)
1848 struct lov_async_page *lap = lap_from_cookie(data);
1849 return lap->lap_caller_ops->ap_lookup_capa(lap->lap_caller_data, cmd);
1852 static struct obd_async_page_ops lov_async_page_ops = {
1853 .ap_make_ready = lov_ap_make_ready,
1854 .ap_refresh_count = lov_ap_refresh_count,
1855 .ap_fill_obdo = lov_ap_fill_obdo,
1856 .ap_update_obdo = lov_ap_update_obdo,
1857 .ap_completion = lov_ap_completion,
1858 .ap_lookup_capa = lov_ap_lookup_capa,
1861 int lov_prep_async_page(struct obd_export *exp, struct lov_stripe_md *lsm,
1862 struct lov_oinfo *loi, cfs_page_t *page,
1863 obd_off offset, struct obd_async_page_ops *ops,
1864 void *data, void **res, int nocache,
1865 struct lustre_handle *lockh)
1867 struct lov_obd *lov = &exp->exp_obd->u.lov;
1868 struct lov_async_page *lap;
1869 struct lov_lock_handles *lov_lockh = NULL;
1875 /* Find an existing osc so we can get it's stupid sizeof(*oap).
1876 Only because of this layering limitation will a client
1877 mount with no osts fail */
1878 while (!lov->lov_tgts || !lov->lov_tgts[i] ||
1879 !lov->lov_tgts[i]->ltd_exp) {
1881 if (i >= lov->desc.ld_tgt_count)
1884 rc = size_round(sizeof(*lap)) +
1885 obd_prep_async_page(lov->lov_tgts[i]->ltd_exp, NULL,
1886 NULL, NULL, 0, NULL, NULL, NULL, 0,
1890 ASSERT_LSM_MAGIC(lsm);
1891 LASSERT(loi == NULL);
1894 lap->lap_magic = LOV_AP_MAGIC;
1895 lap->lap_caller_ops = ops;
1896 lap->lap_caller_data = data;
1898 /* for now only raid 0 which passes through */
1899 lap->lap_stripe = lov_stripe_number(lsm, offset);
1900 lov_stripe_offset(lsm, offset, lap->lap_stripe, &lap->lap_sub_offset);
1901 loi = lsm->lsm_oinfo[lap->lap_stripe];
1903 /* so the callback doesn't need the lsm */
1904 lap->lap_loi_id = loi->loi_id;
1905 lap->lap_loi_gr = lsm->lsm_object_gr;
1906 LASSERT(lsm->lsm_object_gr > 0);
1908 lap->lap_sub_cookie = (void *)lap + size_round(sizeof(*lap));
1911 lov_lockh = lov_handle2llh(lockh);
1913 lockh = lov_lockh->llh_handles + lap->lap_stripe;
1917 rc = obd_prep_async_page(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1918 lsm, loi, page, lap->lap_sub_offset,
1919 &lov_async_page_ops, lap,
1920 &lap->lap_sub_cookie, nocache, lockh);
1922 lov_llh_put(lov_lockh);
1925 CDEBUG(D_CACHE, "lap %p page %p cookie %p off "LPU64"\n", lap, page,
1926 lap->lap_sub_cookie, offset);
1930 static int lov_queue_async_io(struct obd_export *exp,
1931 struct lov_stripe_md *lsm,
1932 struct lov_oinfo *loi, void *cookie,
1933 int cmd, obd_off off, int count,
1934 obd_flag brw_flags, obd_flag async_flags)
1936 struct lov_obd *lov = &exp->exp_obd->u.lov;
1937 struct lov_async_page *lap;
1940 LASSERT(loi == NULL);
1942 ASSERT_LSM_MAGIC(lsm);
1944 lap = lap_from_cookie(cookie);
1946 loi = lsm->lsm_oinfo[lap->lap_stripe];
1948 rc = obd_queue_async_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp, lsm,
1949 loi, lap->lap_sub_cookie, cmd, off, count,
1950 brw_flags, async_flags);
1954 static int lov_set_async_flags(struct obd_export *exp,
1955 struct lov_stripe_md *lsm,
1956 struct lov_oinfo *loi, void *cookie,
1957 obd_flag async_flags)
1959 struct lov_obd *lov = &exp->exp_obd->u.lov;
1960 struct lov_async_page *lap;
1963 LASSERT(loi == NULL);
1965 ASSERT_LSM_MAGIC(lsm);
1967 lap = lap_from_cookie(cookie);
1969 loi = lsm->lsm_oinfo[lap->lap_stripe];
1971 rc = obd_set_async_flags(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1972 lsm, loi, lap->lap_sub_cookie, async_flags);
1976 static int lov_queue_group_io(struct obd_export *exp,
1977 struct lov_stripe_md *lsm,
1978 struct lov_oinfo *loi,
1979 struct obd_io_group *oig, void *cookie,
1980 int cmd, obd_off off, int count,
1981 obd_flag brw_flags, obd_flag async_flags)
1983 struct lov_obd *lov = &exp->exp_obd->u.lov;
1984 struct lov_async_page *lap;
1987 LASSERT(loi == NULL);
1989 ASSERT_LSM_MAGIC(lsm);
1991 lap = lap_from_cookie(cookie);
1993 loi = lsm->lsm_oinfo[lap->lap_stripe];
1995 rc = obd_queue_group_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp, lsm,
1996 loi, oig, lap->lap_sub_cookie, cmd, off, count,
1997 brw_flags, async_flags);
2001 /* this isn't exactly optimal. we may have queued sync io in oscs on
2002 * all stripes, but we don't record that fact at queue time. so we
2003 * trigger sync io on all stripes. */
2004 static int lov_trigger_group_io(struct obd_export *exp,
2005 struct lov_stripe_md *lsm,
2006 struct lov_oinfo *loi,
2007 struct obd_io_group *oig)
2009 struct lov_obd *lov = &exp->exp_obd->u.lov;
2012 LASSERT(loi == NULL);
2014 ASSERT_LSM_MAGIC(lsm);
2016 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2017 loi = lsm->lsm_oinfo[i];
2018 if (!lov->lov_tgts[loi->loi_ost_idx] ||
2019 !lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
2020 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2024 err = obd_trigger_group_io(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2026 if (rc == 0 && err != 0)
2032 static int lov_teardown_async_page(struct obd_export *exp,
2033 struct lov_stripe_md *lsm,
2034 struct lov_oinfo *loi, void *cookie)
2036 struct lov_obd *lov = &exp->exp_obd->u.lov;
2037 struct lov_async_page *lap;
2040 LASSERT(loi == NULL);
2042 ASSERT_LSM_MAGIC(lsm);
2044 lap = lap_from_cookie(cookie);
2046 loi = lsm->lsm_oinfo[lap->lap_stripe];
2048 rc = obd_teardown_async_page(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2049 lsm, loi, lap->lap_sub_cookie);
2051 CERROR("unable to teardown sub cookie %p: %d\n",
2052 lap->lap_sub_cookie, rc);
2058 static int lov_enqueue_interpret(struct ptlrpc_request_set *rqset,
2061 struct lov_request_set *lovset = (struct lov_request_set *)data;
2063 rc = lov_fini_enqueue_set(lovset, lovset->set_ei->ei_mode, rc, rqset);
2067 static int lov_enqueue(struct obd_export *exp, struct obd_info *oinfo,
2068 struct ldlm_enqueue_info *einfo,
2069 struct ptlrpc_request_set *rqset)
2071 ldlm_mode_t mode = einfo->ei_mode;
2072 struct lov_request_set *set;
2073 struct lov_request *req;
2074 struct list_head *pos;
2075 struct lov_obd *lov;
2080 ASSERT_LSM_MAGIC(oinfo->oi_md);
2081 LASSERT(mode == (mode & -mode));
2083 /* we should never be asked to replay a lock this way. */
2084 LASSERT((oinfo->oi_flags & LDLM_FL_REPLAY) == 0);
2086 if (!exp || !exp->exp_obd)
2089 lov = &exp->exp_obd->u.lov;
2090 rc = lov_prep_enqueue_set(exp, oinfo, einfo, &set);
2094 list_for_each (pos, &set->set_list) {
2095 req = list_entry(pos, struct lov_request, rq_link);
2097 rc = obd_enqueue(lov->lov_tgts[req->rq_idx]->ltd_exp,
2098 &req->rq_oi, einfo, rqset);
2103 if (rqset && !list_empty(&rqset->set_requests)) {
2105 LASSERT(rqset->set_interpret == NULL);
2106 rqset->set_interpret = lov_enqueue_interpret;
2107 rqset->set_arg = (void *)set;
2111 rc = lov_fini_enqueue_set(set, mode, rc, rqset);
2115 static int lov_match(struct obd_export *exp, struct lov_stripe_md *lsm,
2116 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
2117 int *flags, void *data, struct lustre_handle *lockh)
2119 struct lov_request_set *set;
2120 struct obd_info oinfo;
2121 struct lov_request *req;
2122 struct list_head *pos;
2123 struct lov_obd *lov = &exp->exp_obd->u.lov;
2124 struct lustre_handle *lov_lockhp;
2125 int lov_flags, rc = 0;
2128 ASSERT_LSM_MAGIC(lsm);
2129 LASSERT((*flags & LDLM_FL_TEST_LOCK) || mode == (mode & -mode));
2131 if (!exp || !exp->exp_obd)
2134 lov = &exp->exp_obd->u.lov;
2135 rc = lov_prep_match_set(exp, &oinfo, lsm, policy, mode, lockh, &set);
2139 list_for_each (pos, &set->set_list) {
2140 ldlm_policy_data_t sub_policy;
2141 req = list_entry(pos, struct lov_request, rq_link);
2142 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
2143 LASSERT(lov_lockhp);
2146 sub_policy.l_extent = req->rq_oi.oi_policy.l_extent;
2148 rc = obd_match(lov->lov_tgts[req->rq_idx]->ltd_exp,
2149 req->rq_oi.oi_md, type, &sub_policy,
2150 mode, &lov_flags, data, lov_lockhp);
2151 rc = lov_update_match_set(set, req, rc);
2155 lov_fini_match_set(set, mode, *flags);
2159 static int lov_change_cbdata(struct obd_export *exp,
2160 struct lov_stripe_md *lsm, ldlm_iterator_t it,
2163 struct lov_obd *lov;
2167 ASSERT_LSM_MAGIC(lsm);
2169 if (!exp || !exp->exp_obd)
2172 LASSERT(lsm->lsm_object_gr > 0);
2174 lov = &exp->exp_obd->u.lov;
2175 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2176 struct lov_stripe_md submd;
2177 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
2179 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2180 CDEBUG(D_HA, "lov idx %d NULL \n", loi->loi_ost_idx);
2184 submd.lsm_object_id = loi->loi_id;
2185 submd.lsm_object_gr = lsm->lsm_object_gr;
2186 submd.lsm_stripe_count = 0;
2187 rc = obd_change_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2193 static int lov_cancel(struct obd_export *exp, struct lov_stripe_md *lsm,
2194 __u32 mode, struct lustre_handle *lockh)
2196 struct lov_request_set *set;
2197 struct obd_info oinfo;
2198 struct lov_request *req;
2199 struct list_head *pos;
2200 struct lov_obd *lov = &exp->exp_obd->u.lov;
2201 struct lustre_handle *lov_lockhp;
2202 int err = 0, rc = 0;
2205 ASSERT_LSM_MAGIC(lsm);
2207 if (!exp || !exp->exp_obd)
2210 LASSERT(lsm->lsm_object_gr > 0);
2212 lov = &exp->exp_obd->u.lov;
2213 rc = lov_prep_cancel_set(exp, &oinfo, lsm, mode, lockh, &set);
2217 list_for_each (pos, &set->set_list) {
2218 req = list_entry(pos, struct lov_request, rq_link);
2219 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
2221 rc = obd_cancel(lov->lov_tgts[req->rq_idx]->ltd_exp,
2222 req->rq_oi.oi_md, mode, lov_lockhp);
2223 rc = lov_update_common_set(set, req, rc);
2225 CERROR("error: cancel objid "LPX64" subobj "
2226 LPX64" on OST idx %d: rc = %d\n",
2228 req->rq_oi.oi_md->lsm_object_id,
2234 lov_fini_cancel_set(set);
2238 static int lov_cancel_unused(struct obd_export *exp,
2239 struct lov_stripe_md *lsm,
2240 int flags, void *opaque)
2242 struct lov_obd *lov;
2246 if (!exp || !exp->exp_obd)
2249 lov = &exp->exp_obd->u.lov;
2251 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2253 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2256 err = obd_cancel_unused(lov->lov_tgts[i]->ltd_exp, NULL,
2264 ASSERT_LSM_MAGIC(lsm);
2266 LASSERT(lsm->lsm_object_gr > 0);
2267 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2268 struct lov_stripe_md submd;
2269 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
2272 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2273 CDEBUG(D_HA, "lov idx %d NULL\n", loi->loi_ost_idx);
2277 if (!lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
2278 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2280 submd.lsm_object_id = loi->loi_id;
2281 submd.lsm_object_gr = lsm->lsm_object_gr;
2282 submd.lsm_stripe_count = 0;
2283 err = obd_cancel_unused(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2284 &submd, flags, opaque);
2285 if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
2286 CERROR("error: cancel unused objid "LPX64" subobj "LPX64
2287 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
2288 loi->loi_id, loi->loi_ost_idx, err);
2296 static int lov_join_lru(struct obd_export *exp,
2297 struct lov_stripe_md *lsm, int join)
2299 struct lov_obd *lov;
2303 ASSERT_LSM_MAGIC(lsm);
2304 if (!exp || !exp->exp_obd)
2307 lov = &exp->exp_obd->u.lov;
2308 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2309 struct lov_stripe_md submd;
2310 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
2313 if (!lov->lov_tgts[loi->loi_ost_idx]) {
2314 CDEBUG(D_HA, "lov idx %d NULL\n", loi->loi_ost_idx);
2318 if (!lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
2319 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
2321 submd.lsm_object_id = loi->loi_id;
2322 submd.lsm_object_gr = lsm->lsm_object_gr;
2323 submd.lsm_stripe_count = 0;
2324 rc = obd_join_lru(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
2327 CERROR("join lru failed. objid: "LPX64" subobj: "LPX64
2328 " ostidx: %d rc: %d\n", lsm->lsm_object_id,
2329 loi->loi_id, loi->loi_ost_idx, rc);
2338 static int lov_statfs_interpret(struct ptlrpc_request_set *rqset,
2341 struct lov_request_set *lovset = (struct lov_request_set *)data;
2346 lovset->set_completes = 0;
2348 err = lov_fini_statfs_set(lovset);
2349 RETURN(rc ? rc : err);
2352 static int lov_statfs_async(struct obd_device *obd, struct obd_info *oinfo,
2353 __u64 max_age, struct ptlrpc_request_set *rqset)
2355 struct lov_request_set *set;
2356 struct lov_request *req;
2357 struct list_head *pos;
2358 struct lov_obd *lov;
2362 LASSERT(oinfo != NULL);
2363 LASSERT(oinfo->oi_osfs != NULL);
2366 rc = lov_prep_statfs_set(obd, oinfo, &set);
2370 list_for_each (pos, &set->set_list) {
2371 struct obd_device *osc_obd;
2373 req = list_entry(pos, struct lov_request, rq_link);
2375 osc_obd = class_exp2obd(lov->lov_tgts[req->rq_idx]->ltd_exp);
2376 rc = obd_statfs_async(osc_obd, &req->rq_oi, max_age, rqset);
2381 if (rc || list_empty(&rqset->set_requests)) {
2384 set->set_completes = 0;
2385 err = lov_fini_statfs_set(set);
2386 RETURN(rc ? rc : err);
2389 LASSERT(rqset->set_interpret == NULL);
2390 rqset->set_interpret = lov_statfs_interpret;
2391 rqset->set_arg = (void *)set;
2395 static int lov_statfs(struct obd_device *obd, struct obd_statfs *osfs,
2396 __u64 max_age, __u32 flags)
2398 struct ptlrpc_request_set *set = NULL;
2399 struct obd_info oinfo = { { { 0 } } };
2404 /* for obdclass we forbid using obd_statfs_rqset, but prefer using async
2405 * statfs requests */
2406 set = ptlrpc_prep_set();
2410 oinfo.oi_osfs = osfs;
2411 oinfo.oi_flags = flags;
2412 rc = lov_statfs_async(obd, &oinfo, max_age, set);
2414 rc = ptlrpc_set_wait(set);
2415 ptlrpc_set_destroy(set);
2420 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
2421 void *karg, void *uarg)
2423 struct obd_device *obddev = class_exp2obd(exp);
2424 struct lov_obd *lov = &obddev->u.lov;
2425 int i, rc, count = lov->desc.ld_tgt_count;
2426 struct obd_uuid *uuidp;
2430 case IOC_OBD_STATFS: {
2431 struct obd_ioctl_data *data = karg;
2432 struct obd_device *osc_obd;
2433 struct obd_statfs stat_buf = {0};
2436 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
2437 LASSERT(data->ioc_plen1 == sizeof(struct obd_statfs));
2439 if ((index >= count))
2442 if (!lov->lov_tgts[index])
2443 /* Try again with the next index */
2445 if (!lov->lov_tgts[index]->ltd_active)
2448 osc_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
2452 /* got statfs data */
2453 rc = obd_statfs(osc_obd, &stat_buf,
2454 cfs_time_current_64() - HZ, 0);
2457 if (copy_to_user(data->ioc_pbuf1, &stat_buf, data->ioc_plen1))
2460 rc = copy_to_user(data->ioc_pbuf2, obd2cli_tgt(osc_obd),
2464 case OBD_IOC_LOV_GET_CONFIG: {
2465 struct obd_ioctl_data *data;
2466 struct lov_desc *desc;
2471 if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
2474 data = (struct obd_ioctl_data *)buf;
2476 if (sizeof(*desc) > data->ioc_inllen1) {
2477 obd_ioctl_freedata(buf, len);
2481 if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
2482 obd_ioctl_freedata(buf, len);
2486 if (sizeof(__u32) * count > data->ioc_inllen3) {
2487 obd_ioctl_freedata(buf, len);
2491 desc = (struct lov_desc *)data->ioc_inlbuf1;
2492 memcpy(desc, &(lov->desc), sizeof(*desc));
2494 uuidp = (struct obd_uuid *)data->ioc_inlbuf2;
2495 genp = (__u32 *)data->ioc_inlbuf3;
2496 /* the uuid will be empty for deleted OSTs */
2497 for (i = 0; i < count; i++, uuidp++, genp++) {
2498 if (!lov->lov_tgts[i])
2500 *uuidp = lov->lov_tgts[i]->ltd_uuid;
2501 *genp = lov->lov_tgts[i]->ltd_gen;
2504 rc = copy_to_user((void *)uarg, buf, len);
2507 obd_ioctl_freedata(buf, len);
2510 case LL_IOC_LOV_SETSTRIPE:
2511 rc = lov_setstripe(exp, karg, uarg);
2513 case LL_IOC_LOV_GETSTRIPE:
2514 rc = lov_getstripe(exp, karg, uarg);
2516 case LL_IOC_LOV_SETEA:
2517 rc = lov_setea(exp, karg, uarg);
2526 for (i = 0; i < count; i++) {
2529 /* OST was disconnected */
2530 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2533 err = obd_iocontrol(cmd, lov->lov_tgts[i]->ltd_exp,
2535 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
2538 if (lov->lov_tgts[i]->ltd_active) {
2539 CDEBUG(err == -ENOTTY ?
2540 D_IOCTL : D_WARNING,
2541 "iocontrol OSC %s on OST "
2542 "idx %d cmd %x: err = %d\n",
2543 lov_uuid2str(lov, i),
2560 #define FIEMAP_BUFFER_SIZE 4096
2563 * Non-zero fe_logical indicates that this is a continuation FIEMAP
2564 * call. The local end offset and the device are sent in the first
2565 * fm_extent. This function calculates the stripe number from the index.
2566 * This function returns a stripe_no on which mapping is to be restarted.
2568 * This function returns fm_end_offset which is the in-OST offset at which
2569 * mapping should be restarted. If fm_end_offset=0 is returned then caller
2570 * will re-calculate proper offset in next stripe.
2571 * Note that the first extent is passed to lov_get_info via the value field.
2573 * \param fiemap fiemap request header
2574 * \param lsm striping information for the file
2575 * \param fm_start logical start of mapping
2576 * \param fm_end logical end of mapping
2577 * \param start_stripe starting stripe will be returned in this
2579 obd_size fiemap_calc_fm_end_offset(struct ll_user_fiemap *fiemap,
2580 struct lov_stripe_md *lsm, obd_size fm_start,
2581 obd_size fm_end, int *start_stripe)
2583 obd_size local_end = fiemap->fm_extents[0].fe_logical;
2584 obd_off lun_start, lun_end;
2585 obd_size fm_end_offset;
2586 int stripe_no = -1, i;
2588 if (fiemap->fm_extent_count == 0 ||
2589 fiemap->fm_extents[0].fe_logical == 0)
2592 /* Find out stripe_no from ost_index saved in the fe_device */
2593 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2594 if (lsm->lsm_oinfo[i]->loi_ost_idx ==
2595 fiemap->fm_extents[0].fe_device) {
2601 /* If we have finished mapping on previous device, shift logical
2602 * offset to start of next device */
2603 if ((lov_stripe_intersects(lsm, stripe_no, fm_start, fm_end,
2604 &lun_start, &lun_end)) != 0 &&
2605 local_end < lun_end) {
2606 fm_end_offset = local_end;
2607 *start_stripe = stripe_no;
2609 /* This is a special value to indicate that caller should
2610 * calculate offset in next stripe. */
2612 *start_stripe = (stripe_no + 1) % lsm->lsm_stripe_count;
2615 return fm_end_offset;
2619 * We calculate on which OST the mapping will end. If the length of mapping
2620 * is greater than (stripe_size * stripe_count) then the last_stripe will
2621 * will be one just before start_stripe. Else we check if the mapping
2622 * intersects each OST and find last_stripe.
2623 * This function returns the last_stripe and also sets the stripe_count
2624 * over which the mapping is spread
2626 * \param lsm striping information for the file
2627 * \param fm_start logical start of mapping
2628 * \param fm_end logical end of mapping
2629 * \param start_stripe starting stripe of the mapping
2630 * \param stripe_count the number of stripes across which to map is returned
2632 * \retval last_stripe return the last stripe of the mapping
2634 int fiemap_calc_last_stripe(struct lov_stripe_md *lsm, obd_size fm_start,
2635 obd_size fm_end, int start_stripe,
2639 obd_off obd_start, obd_end;
2642 if (fm_end - fm_start > lsm->lsm_stripe_size * lsm->lsm_stripe_count) {
2643 last_stripe = (start_stripe < 1 ? lsm->lsm_stripe_count - 1 :
2645 *stripe_count = lsm->lsm_stripe_count;
2647 for (j = 0, i = start_stripe; j < lsm->lsm_stripe_count;
2648 i = (i + 1) % lsm->lsm_stripe_count, j++) {
2649 if ((lov_stripe_intersects(lsm, i, fm_start, fm_end,
2650 &obd_start, &obd_end)) == 0)
2654 last_stripe = (start_stripe + j - 1) %lsm->lsm_stripe_count;
2661 * Set fe_device and copy extents from local buffer into main return buffer.
2663 * \param fiemap fiemap request header
2664 * \param lcl_fm_ext array of local fiemap extents to be copied
2665 * \param ost_index OST index to be written into the fm_device field for each
2667 * \param ext_count number of extents to be copied
2668 * \param current_extent where to start copying in main extent array
2670 void fiemap_prepare_and_copy_exts(struct ll_user_fiemap *fiemap,
2671 struct ll_fiemap_extent *lcl_fm_ext,
2672 int ost_index, unsigned int ext_count,
2678 for (ext = 0; ext < ext_count; ext++) {
2679 lcl_fm_ext[ext].fe_device = ost_index;
2680 lcl_fm_ext[ext].fe_flags |= FIEMAP_EXTENT_NET;
2683 /* Copy fm_extent's from fm_local to return buffer */
2684 to = (char *)fiemap + fiemap_count_to_size(current_extent);
2685 memcpy(to, lcl_fm_ext, ext_count * sizeof(struct ll_fiemap_extent));
2689 * Break down the FIEMAP request and send appropriate calls to individual OSTs.
2690 * This also handles the restarting of FIEMAP calls in case mapping overflows
2691 * the available number of extents in single call.
2693 static int lov_fiemap(struct lov_obd *lov, __u32 keylen, void *key,
2694 __u32 *vallen, void *val, struct lov_stripe_md *lsm)
2696 struct ll_fiemap_info_key *fm_key = key;
2697 struct ll_user_fiemap *fiemap = val;
2698 struct ll_user_fiemap *fm_local = NULL;
2699 struct ll_fiemap_extent *lcl_fm_ext;
2701 unsigned int get_num_extents = 0;
2702 int ost_index = 0, actual_start_stripe, start_stripe;
2703 obd_size fm_start, fm_end, fm_length, fm_end_offset = 0;
2705 int current_extent = 0, rc = 0, i;
2706 int ost_eof = 0; /* EOF for object */
2707 int ost_done = 0; /* done with required mapping for this OST? */
2709 int cur_stripe = 0, cur_stripe_wrap = 0, stripe_count;
2710 unsigned int buffer_size = FIEMAP_BUFFER_SIZE;
2715 if (fiemap_count_to_size(fm_key->fiemap.fm_extent_count) < buffer_size)
2716 buffer_size = fiemap_count_to_size(fm_key->fiemap.fm_extent_count);
2718 OBD_ALLOC(fm_local, buffer_size);
2719 if (fm_local == NULL)
2720 GOTO(out, rc = -ENOMEM);
2721 lcl_fm_ext = &fm_local->fm_extents[0];
2723 count_local = fiemap_size_to_count(buffer_size);
2725 memcpy(fiemap, &fm_key->fiemap, sizeof(*fiemap));
2726 fm_start = fiemap->fm_start;
2727 fm_length = fiemap->fm_length;
2728 /* Calculate start stripe, last stripe and length of mapping */
2729 actual_start_stripe = start_stripe = lov_stripe_number(lsm, fm_start);
2730 fm_end = (fm_length == ~0ULL ? fm_key->oa.o_size :
2731 fm_start + fm_length - 1);
2732 /* If fm_length != ~0ULL but fm_start+fm_length-1 exceeds file size */
2733 if (fm_end > fm_key->oa.o_size)
2734 fm_end = fm_key->oa.o_size;
2736 last_stripe = fiemap_calc_last_stripe(lsm, fm_start, fm_end,
2737 actual_start_stripe, &stripe_count);
2739 fm_end_offset = fiemap_calc_fm_end_offset(fiemap, lsm, fm_start, fm_end,
2742 if (fiemap->fm_extent_count == 0) {
2743 get_num_extents = 1;
2747 /* Check each stripe */
2748 for (cur_stripe = start_stripe, i = 0; i < stripe_count;
2749 i++, cur_stripe = (cur_stripe + 1) % lsm->lsm_stripe_count) {
2750 obd_size req_fm_len; /* Stores length of required mapping */
2751 obd_size len_mapped_single_call;
2752 obd_off lun_start, lun_end, obd_object_end;
2753 unsigned int ext_count;
2755 cur_stripe_wrap = cur_stripe;
2757 /* Find out range of mapping on this stripe */
2758 if ((lov_stripe_intersects(lsm, cur_stripe, fm_start, fm_end,
2759 &lun_start, &obd_object_end)) == 0)
2762 /* If this is a continuation FIEMAP call and we are on
2763 * starting stripe then lun_start needs to be set to
2765 if (fm_end_offset != 0 && cur_stripe == start_stripe)
2766 lun_start = fm_end_offset;
2768 if (fm_length != ~0ULL) {
2769 /* Handle fm_start + fm_length overflow */
2770 if (fm_start + fm_length < fm_start)
2771 fm_length = ~0ULL - fm_start;
2772 lun_end = lov_size_to_stripe(lsm, fm_start + fm_length,
2778 if (lun_start == lun_end)
2781 req_fm_len = obd_object_end - lun_start;
2782 fm_local->fm_length = 0;
2783 len_mapped_single_call = 0;
2785 /* If the output buffer is very large and the objects have many
2786 * extents we may need to loop on a single OST repeatedly */
2790 if (get_num_extents == 0) {
2791 /* Don't get too many extents. */
2792 if (current_extent + count_local >
2793 fiemap->fm_extent_count)
2794 count_local = fiemap->fm_extent_count -
2798 lun_start += len_mapped_single_call;
2799 fm_local->fm_length = req_fm_len - len_mapped_single_call;
2800 req_fm_len = fm_local->fm_length;
2801 fm_local->fm_extent_count = count_local;
2802 fm_local->fm_mapped_extents = 0;
2803 fm_local->fm_flags = fiemap->fm_flags;
2805 fm_key->oa.o_id = lsm->lsm_oinfo[cur_stripe]->loi_id;
2806 ost_index = lsm->lsm_oinfo[cur_stripe]->loi_ost_idx;
2808 if (ost_index < 0 || ost_index >=lov->desc.ld_tgt_count)
2809 GOTO(out, rc = -EINVAL);
2811 /* If OST is inactive, return extent with UNKNOWN flag */
2812 if (lov && !lov->lov_tgts[ost_index]->ltd_active) {
2813 fm_local->fm_flags |= FIEMAP_EXTENT_LAST;
2814 fm_local->fm_mapped_extents = 1;
2816 lcl_fm_ext[0].fe_logical = lun_start;
2817 lcl_fm_ext[0].fe_length = obd_object_end -
2819 lcl_fm_ext[0].fe_flags |= FIEMAP_EXTENT_UNKNOWN;
2824 fm_local->fm_start = lun_start;
2825 fm_local->fm_flags &= ~FIEMAP_FLAG_DEVICE_ORDER;
2826 memcpy(&fm_key->fiemap, fm_local, sizeof(*fm_local));
2827 *vallen=fiemap_count_to_size(fm_local->fm_extent_count);
2828 rc = obd_get_info(lov->lov_tgts[ost_index]->ltd_exp,
2829 keylen, key, vallen, fm_local, lsm);
2834 ext_count = fm_local->fm_mapped_extents;
2835 if (ext_count == 0) {
2837 /* If last stripe has hole at the end,
2838 * then we need to return */
2839 if (cur_stripe_wrap == last_stripe) {
2840 fiemap->fm_mapped_extents = 0;
2846 /* If we just need num of extents then go to next device */
2847 if (get_num_extents) {
2848 current_extent += ext_count;
2852 len_mapped_single_call = lcl_fm_ext[ext_count-1].fe_logical -
2853 lun_start + lcl_fm_ext[ext_count - 1].fe_length;
2855 /* Have we finished mapping on this device? */
2856 if (req_fm_len <= len_mapped_single_call)
2859 /* Clear the EXTENT_LAST flag which can be present on
2861 if (lcl_fm_ext[ext_count-1].fe_flags & FIEMAP_EXTENT_LAST)
2862 lcl_fm_ext[ext_count - 1].fe_flags &=
2863 ~FIEMAP_EXTENT_LAST;
2865 curr_loc = lov_stripe_size(lsm,
2866 lcl_fm_ext[ext_count - 1].fe_logical+
2867 lcl_fm_ext[ext_count - 1].fe_length,
2869 if (curr_loc >= fm_key->oa.o_size)
2872 fiemap_prepare_and_copy_exts(fiemap, lcl_fm_ext,
2873 ost_index, ext_count,
2876 current_extent += ext_count;
2878 /* Ran out of available extents? */
2879 if (current_extent >= fiemap->fm_extent_count)
2881 } while (ost_done == 0 && ost_eof == 0);
2883 if (cur_stripe_wrap == last_stripe)
2888 /* Indicate that we are returning device offsets unless file just has
2890 if (lsm->lsm_stripe_count > 1)
2891 fiemap->fm_flags |= FIEMAP_FLAG_DEVICE_ORDER;
2893 if (get_num_extents)
2894 goto skip_last_device_calc;
2896 /* Check if we have reached the last stripe and whether mapping for that
2897 * stripe is done. */
2898 if (cur_stripe_wrap == last_stripe) {
2899 if (ost_done || ost_eof)
2900 fiemap->fm_extents[current_extent - 1].fe_flags |=
2904 skip_last_device_calc:
2905 fiemap->fm_mapped_extents = current_extent;
2908 OBD_FREE(fm_local, buffer_size);
2912 static int lov_get_info(struct obd_export *exp, __u32 keylen,
2913 void *key, __u32 *vallen, void *val,
2914 struct lov_stripe_md *lsm)
2916 struct obd_device *obddev = class_exp2obd(exp);
2917 struct lov_obd *lov = &obddev->u.lov;
2921 if (!vallen || !val)
2926 if (KEY_IS(KEY_LOCK_TO_STRIPE)) {
2929 struct ldlm_lock *lock;
2931 struct ldlm_res_id *res_id = &data->lock->l_resource->lr_name;
2932 struct lov_oinfo *loi;
2933 __u32 *stripe = val;
2935 if (*vallen < sizeof(*stripe))
2936 GOTO(out, rc = -EFAULT);
2937 *vallen = sizeof(*stripe);
2939 /* XXX This is another one of those bits that will need to
2940 * change if we ever actually support nested LOVs. It uses
2941 * the lock's export to find out which stripe it is. */
2942 /* XXX - it's assumed all the locks for deleted OSTs have
2943 * been cancelled. Also, the export for deleted OSTs will
2944 * be NULL and won't match the lock's export. */
2945 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2946 loi = lsm->lsm_oinfo[i];
2947 if (!lov->lov_tgts[loi->loi_ost_idx])
2949 if (lov->lov_tgts[loi->loi_ost_idx]->ltd_exp ==
2950 data->lock->l_conn_export &&
2951 osc_res_name_eq(loi->loi_id, loi->loi_gr, res_id)) {
2956 LDLM_ERROR(data->lock, "lock on inode without such object");
2957 dump_lsm(D_ERROR, lsm);
2958 GOTO(out, rc = -ENXIO);
2959 } else if (KEY_IS(KEY_LAST_ID)) {
2960 struct obd_id_info *info = val;
2961 __u32 size = sizeof(obd_id);
2962 struct lov_tgt_desc *tgt;
2964 LASSERT(*vallen == sizeof(struct obd_id_info));
2965 tgt = lov->lov_tgts[info->idx];
2967 if (!tgt || !tgt->ltd_active)
2968 GOTO(out, rc = -ESRCH);
2970 rc = obd_get_info(tgt->ltd_exp, keylen, key, &size, info->data, NULL);
2972 } else if (KEY_IS(KEY_LOVDESC)) {
2973 struct lov_desc *desc_ret = val;
2974 *desc_ret = lov->desc;
2977 } else if (KEY_IS(KEY_FIEMAP)) {
2978 rc = lov_fiemap(lov, keylen, key, vallen, val, lsm);
2989 static int lov_set_info_async(struct obd_export *exp, obd_count keylen,
2990 void *key, obd_count vallen, void *val,
2991 struct ptlrpc_request_set *set)
2993 struct obd_device *obddev = class_exp2obd(exp);
2994 struct lov_obd *lov = &obddev->u.lov;
2997 struct lov_tgt_desc *tgt;
2998 unsigned incr, check_uuid,
2999 do_inactive, no_set;
3000 unsigned next_id = 0, mds_con = 0;
3003 incr = check_uuid = do_inactive = no_set = 0;
3006 set = ptlrpc_prep_set();
3012 count = lov->desc.ld_tgt_count;
3014 if (KEY_IS(KEY_NEXT_ID)) {
3015 count = vallen / sizeof(struct obd_id_info);
3016 vallen = sizeof(obd_id);
3017 incr = sizeof(struct obd_id_info);
3020 } else if (KEY_IS(KEY_CHECKSUM)) {
3022 } else if (KEY_IS(KEY_UNLINKED)) {
3023 check_uuid = val ? 1 : 0;
3024 } else if (KEY_IS(KEY_EVICT_BY_NID)) {
3025 /* use defaults: do_inactive = incr = 0; */
3026 } else if (KEY_IS(KEY_MDS_CONN)) {
3030 for (i = 0; i < count; i++, val = (char *)val + incr) {
3032 tgt = lov->lov_tgts[((struct obd_id_info*)val)->idx];
3034 tgt = lov->lov_tgts[i];
3036 /* OST was disconnected */
3037 if (!tgt || !tgt->ltd_exp)
3040 /* OST is inactive and we don't want inactive OSCs */
3041 if (!tgt->ltd_active && !do_inactive)
3045 struct mds_group_info *mgi;
3047 LASSERT(vallen == sizeof(*mgi));
3048 mgi = (struct mds_group_info *)val;
3050 /* Only want a specific OSC */
3051 if (mgi->uuid && !obd_uuid_equals(mgi->uuid,
3055 err = obd_set_info_async(tgt->ltd_exp,
3056 keylen, key, sizeof(int),
3058 } else if (next_id) {
3059 err = obd_set_info_async(tgt->ltd_exp,
3060 keylen, key, vallen,
3061 ((struct obd_id_info*)val)->data, set);
3063 /* Only want a specific OSC */
3065 !obd_uuid_equals(val, &tgt->ltd_uuid))
3068 err = obd_set_info_async(tgt->ltd_exp,
3069 keylen, key, vallen, val, set);
3078 err = ptlrpc_set_wait(set);
3081 ptlrpc_set_destroy(set);
3086 static int lov_checkmd(struct obd_export *exp, struct obd_export *md_exp,
3087 struct lov_stripe_md *lsm)
3095 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
3096 rc = lsm_op_find(lsm->lsm_magic)->lsm_revalidate(lsm, md_exp->exp_obd);
3101 int lov_test_and_clear_async_rc(struct lov_stripe_md *lsm)
3106 for (i = 0; i < lsm->lsm_stripe_count; i++) {
3107 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
3108 if (loi->loi_ar.ar_rc && !rc)
3109 rc = loi->loi_ar.ar_rc;
3110 loi->loi_ar.ar_rc = 0;
3114 EXPORT_SYMBOL(lov_test_and_clear_async_rc);
3117 static int lov_extent_calc(struct obd_export *exp, struct lov_stripe_md *lsm,
3118 int cmd, __u64 *offset)
3120 __u32 ssize = lsm->lsm_stripe_size;
3124 do_div(start, ssize);
3125 start = start * ssize;
3127 CDEBUG(D_DLMTRACE, "offset "LPU64", stripe %u, start "LPU64
3128 ", end "LPU64"\n", *offset, ssize, start,
3130 if (cmd == OBD_CALC_STRIPE_END) {
3131 *offset = start + ssize - 1;
3132 } else if (cmd == OBD_CALC_STRIPE_START) {
3143 struct lov_multi_wait {
3144 struct ldlm_lock *lock;
3150 int lov_complete_many(struct obd_export *exp, struct lov_stripe_md *lsm,
3151 struct lustre_handle *lockh)
3153 struct lov_lock_handles *lov_lockh = NULL;
3154 struct lustre_handle *lov_lockhp;
3155 struct lov_obd *lov;
3156 struct lov_oinfo *loi;
3157 struct lov_multi_wait *queues;
3161 ASSERT_LSM_MAGIC(lsm);
3163 if (!exp || !exp->exp_obd)
3166 LASSERT(lockh != NULL);
3167 if (lsm->lsm_stripe_count > 1) {
3168 lov_lockh = lov_handle2llh(lockh);
3169 if (lov_lockh == NULL) {
3170 CERROR("LOV: invalid lov lock handle %p\n", lockh);
3174 lov_lockhp = lov_lockh->llh_handles;
3179 OBD_ALLOC(queues, lsm->lsm_stripe_count * sizeof(*queues));
3181 GOTO(out, rc = -ENOMEM);
3183 lov = &exp->exp_obd->u.lov;
3184 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
3185 i++, loi++, lov_lockhp++) {
3186 struct ldlm_lock *lock;
3187 struct obd_device *obd;
3189 lock = ldlm_handle2lock(lov_lockhp);
3191 CDEBUG(D_HA, "lov idx %d subobj "LPX64" no lock?\n",
3192 loi->loi_ost_idx, loi->loi_id);
3193 queues[i].completed = 1;
3197 queues[i].lock = lock;
3198 init_waitqueue_entry(&(queues[i].wait), current);
3199 add_wait_queue(lock->l_waitq, &(queues[i].wait));
3201 obd = class_exp2obd(lock->l_conn_export);
3203 imp = obd->u.cli.cl_import;
3205 spin_lock(&imp->imp_lock);
3206 queues[i].generation = imp->imp_generation;
3207 spin_unlock(&imp->imp_lock);
3211 lwi = LWI_TIMEOUT_INTR(obd_timeout * HZ, ldlm_expired_completion_wait,
3212 interrupted_completion_wait, &lwd);
3213 rc = l_wait_event_added(check_multi_complete(queues, lsm), &lwi);
3215 for (i = 0; i < lsm->lsm_stripe_count; i++)
3216 remove_wait_queue(lock->l_waitq, &(queues[i].wait));
3218 if (rc == -EINTR || rc == -ETIMEDOUT) {
3224 if (lov_lockh != NULL)
3225 lov_llh_put(lov_lockh);
3230 void lov_stripe_lock(struct lov_stripe_md *md)
3232 LASSERT(md->lsm_lock_owner != cfs_curproc_pid());
3233 spin_lock(&md->lsm_lock);
3234 LASSERT(md->lsm_lock_owner == 0);
3235 md->lsm_lock_owner = cfs_curproc_pid();
3237 EXPORT_SYMBOL(lov_stripe_lock);
3239 void lov_stripe_unlock(struct lov_stripe_md *md)
3241 LASSERT(md->lsm_lock_owner == cfs_curproc_pid());
3242 md->lsm_lock_owner = 0;
3243 spin_unlock(&md->lsm_lock);
3245 EXPORT_SYMBOL(lov_stripe_unlock);
3248 * Checks if requested extent lock is compatible with a lock under the page.
3250 * Checks if the lock under \a page is compatible with a read or write lock
3251 * (specified by \a rw) for an extent [\a start , \a end].
3253 * \param exp lov export
3254 * \param lsm striping information for the file
3255 * \param res lov_async_page placeholder
3256 * \param rw OBD_BRW_READ if requested for reading,
3257 * OBD_BRW_WRITE if requested for writing
3258 * \param start start of the requested extent
3259 * \param end end of the requested extent
3260 * \param cookie transparent parameter for passing locking context
3262 * \post result == 1, *cookie == context, appropriate lock is referenced or
3265 * \retval 1 owned lock is reused for the request
3266 * \retval 0 no lock reused for the request
3268 * \see lov_release_short_lock
3270 static int lov_reget_short_lock(struct obd_export *exp,
3271 struct lov_stripe_md *lsm,
3273 obd_off start, obd_off end,
3276 struct lov_async_page *l = *res;
3277 obd_off stripe_start, stripe_end = start;
3281 /* ensure we don't cross stripe boundaries */
3282 lov_extent_calc(exp, lsm, OBD_CALC_STRIPE_END, &stripe_end);
3283 if (stripe_end <= end)
3286 /* map the region limits to the object limits */
3287 lov_stripe_offset(lsm, start, l->lap_stripe, &stripe_start);
3288 lov_stripe_offset(lsm, end, l->lap_stripe, &stripe_end);
3290 RETURN(obd_reget_short_lock(exp->exp_obd->u.lov.lov_tgts[lsm->
3291 lsm_oinfo[l->lap_stripe]->loi_ost_idx]->
3292 ltd_exp, NULL, &l->lap_sub_cookie,
3293 rw, stripe_start, stripe_end, cookie));
3297 * Releases a reference to a lock taken in a "fast" way.
3299 * Releases a read or a write (specified by \a rw) lock
3300 * referenced by \a cookie.
3302 * \param exp lov export
3303 * \param lsm striping information for the file
3304 * \param end end of the locked extent
3305 * \param rw OBD_BRW_READ if requested for reading,
3306 * OBD_BRW_WRITE if requested for writing
3307 * \param cookie transparent parameter for passing locking context
3309 * \post appropriate lock is dereferenced
3311 * \see lov_reget_short_lock
3313 static int lov_release_short_lock(struct obd_export *exp,
3314 struct lov_stripe_md *lsm, obd_off end,
3315 void *cookie, int rw)
3321 stripe = lov_stripe_number(lsm, end);
3323 RETURN(obd_release_short_lock(exp->exp_obd->u.lov.lov_tgts[lsm->
3324 lsm_oinfo[stripe]->loi_ost_idx]->
3325 ltd_exp, NULL, end, cookie, rw));
3328 struct obd_ops lov_obd_ops = {
3329 .o_owner = THIS_MODULE,
3330 .o_setup = lov_setup,
3331 .o_precleanup = lov_precleanup,
3332 .o_cleanup = lov_cleanup,
3333 .o_process_config = lov_process_config,
3334 .o_connect = lov_connect,
3335 .o_disconnect = lov_disconnect,
3336 .o_statfs = lov_statfs,
3337 .o_statfs_async = lov_statfs_async,
3338 .o_packmd = lov_packmd,
3339 .o_unpackmd = lov_unpackmd,
3340 .o_checkmd = lov_checkmd,
3341 .o_create = lov_create,
3342 .o_destroy = lov_destroy,
3343 .o_getattr = lov_getattr,
3344 .o_getattr_async = lov_getattr_async,
3345 .o_setattr = lov_setattr,
3346 .o_setattr_async = lov_setattr_async,
3348 .o_brw_async = lov_brw_async,
3349 .o_prep_async_page = lov_prep_async_page,
3350 .o_reget_short_lock = lov_reget_short_lock,
3351 .o_release_short_lock = lov_release_short_lock,
3352 .o_queue_async_io = lov_queue_async_io,
3353 .o_set_async_flags = lov_set_async_flags,
3354 .o_queue_group_io = lov_queue_group_io,
3355 .o_trigger_group_io = lov_trigger_group_io,
3356 .o_teardown_async_page = lov_teardown_async_page,
3357 .o_merge_lvb = lov_merge_lvb,
3358 .o_adjust_kms = lov_adjust_kms,
3359 .o_punch = lov_punch,
3361 .o_enqueue = lov_enqueue,
3362 .o_match = lov_match,
3363 .o_change_cbdata = lov_change_cbdata,
3364 .o_cancel = lov_cancel,
3365 .o_cancel_unused = lov_cancel_unused,
3366 .o_join_lru = lov_join_lru,
3367 .o_iocontrol = lov_iocontrol,
3368 .o_get_info = lov_get_info,
3369 .o_set_info_async = lov_set_info_async,
3370 .o_extent_calc = lov_extent_calc,
3371 .o_llog_init = lov_llog_init,
3372 .o_llog_finish = lov_llog_finish,
3373 .o_notify = lov_notify,
3374 .o_register_page_removal_cb = lov_register_page_removal_cb,
3375 .o_unregister_page_removal_cb = lov_unregister_page_removal_cb,
3376 .o_register_lock_cancel_cb = lov_register_lock_cancel_cb,
3377 .o_unregister_lock_cancel_cb = lov_unregister_lock_cancel_cb,
3378 .o_pool_new = lov_pool_new,
3379 .o_pool_rem = lov_pool_remove,
3380 .o_pool_add = lov_pool_add,
3381 .o_pool_del = lov_pool_del,
3384 static quota_interface_t *quota_interface;
3385 extern quota_interface_t lov_quota_interface;
3387 cfs_mem_cache_t *lov_oinfo_slab;
3389 int __init lov_init(void)
3391 struct lprocfs_static_vars lvars = { 0 };
3395 lov_oinfo_slab = cfs_mem_cache_create("lov_oinfo",
3396 sizeof(struct lov_oinfo),
3397 0, SLAB_HWCACHE_ALIGN);
3398 if (lov_oinfo_slab == NULL)
3400 lprocfs_lov_init_vars(&lvars);
3402 request_module("lquota");
3403 quota_interface = PORTAL_SYMBOL_GET(lov_quota_interface);
3404 init_obd_quota_ops(quota_interface, &lov_obd_ops);
3406 rc = class_register_type(&lov_obd_ops, NULL, lvars.module_vars,
3407 LUSTRE_LOV_NAME, NULL);
3409 if (quota_interface)
3410 PORTAL_SYMBOL_PUT(lov_quota_interface);
3411 rc2 = cfs_mem_cache_destroy(lov_oinfo_slab);
3419 static void /*__exit*/ lov_exit(void)
3423 if (quota_interface)
3424 PORTAL_SYMBOL_PUT(lov_quota_interface);
3426 class_unregister_type(LUSTRE_LOV_NAME);
3427 rc = cfs_mem_cache_destroy(lov_oinfo_slab);
3431 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
3432 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver");
3433 MODULE_LICENSE("GPL");
3435 cfs_module(lov, LUSTRE_VERSION_STRING, lov_init, lov_exit);