1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * Copyright (c) 2011 Whamcloud, Inc.
36 * This file is part of Lustre, http://www.lustre.org/
37 * Lustre is a trademark of Sun Microsystems, Inc.
39 * lustre/lov/lov_obd.c
41 * Author: Phil Schwan <phil@clusterfs.com>
42 * Author: Peter Braam <braam@clusterfs.com>
43 * Author: Mike Shaver <shaver@clusterfs.com>
44 * Author: Nathan Rutman <nathan@clusterfs.com>
48 # define EXPORT_SYMTAB
50 #define DEBUG_SUBSYSTEM S_LOV
52 #include <libcfs/libcfs.h>
54 #include <liblustre.h>
57 #include <obd_support.h>
58 #include <lustre_lib.h>
59 #include <lustre_net.h>
60 #include <lustre/lustre_idl.h>
61 #include <lustre_dlm.h>
62 #include <lustre_mds.h>
63 #include <lustre_debug.h>
64 #include <obd_class.h>
67 #include <lprocfs_status.h>
68 #include <lustre_param.h>
69 #include <cl_object.h>
70 #include <lustre/ll_fiemap.h>
72 #include "lov_internal.h"
74 /* Keep a refcount of lov->tgt usage to prevent racing with addition/deletion.
75 Any function that expects lov_tgts to remain stationary must take a ref. */
76 static void lov_getref(struct obd_device *obd)
78 struct lov_obd *lov = &obd->u.lov;
80 /* nobody gets through here until lov_putref is done */
81 cfs_mutex_down(&lov->lov_lock);
82 cfs_atomic_inc(&lov->lov_refcount);
83 cfs_mutex_up(&lov->lov_lock);
87 static void __lov_del_obd(struct obd_device *obd, struct lov_tgt_desc *tgt);
89 static void lov_putref(struct obd_device *obd)
91 struct lov_obd *lov = &obd->u.lov;
93 cfs_mutex_down(&lov->lov_lock);
94 /* ok to dec to 0 more than once -- ltd_exp's will be null */
95 if (cfs_atomic_dec_and_test(&lov->lov_refcount) && lov->lov_death_row) {
98 struct lov_tgt_desc *tgt, *n;
99 CDEBUG(D_CONFIG, "destroying %d lov targets\n",
101 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
102 tgt = lov->lov_tgts[i];
104 if (!tgt || !tgt->ltd_reap)
106 cfs_list_add(&tgt->ltd_kill, &kill);
107 /* XXX - right now there is a dependency on ld_tgt_count
108 * being the maximum tgt index for computing the
109 * mds_max_easize. So we can't shrink it. */
110 lov_ost_pool_remove(&lov->lov_packed, i);
111 lov->lov_tgts[i] = NULL;
112 lov->lov_death_row--;
114 cfs_mutex_up(&lov->lov_lock);
116 cfs_list_for_each_entry_safe(tgt, n, &kill, ltd_kill) {
117 cfs_list_del(&tgt->ltd_kill);
119 __lov_del_obd(obd, tgt);
122 cfs_mutex_up(&lov->lov_lock);
126 static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
127 enum obd_notify_event ev);
128 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
129 enum obd_notify_event ev, void *data);
132 #define MAX_STRING_SIZE 128
133 int lov_connect_obd(struct obd_device *obd, __u32 index, int activate,
134 struct obd_connect_data *data)
136 struct lov_obd *lov = &obd->u.lov;
137 struct obd_uuid *tgt_uuid;
138 struct obd_device *tgt_obd;
139 static struct obd_uuid lov_osc_uuid = { "LOV_OSC_UUID" };
140 struct obd_import *imp;
142 cfs_proc_dir_entry_t *lov_proc_dir;
147 if (!lov->lov_tgts[index])
150 tgt_uuid = &lov->lov_tgts[index]->ltd_uuid;
151 tgt_obd = lov->lov_tgts[index]->ltd_obd;
153 if (!tgt_obd->obd_set_up) {
154 CERROR("Target %s not set up\n", obd_uuid2str(tgt_uuid));
158 /* override the sp_me from lov */
159 tgt_obd->u.cli.cl_sp_me = lov->lov_sp_me;
161 if (data && (data->ocd_connect_flags & OBD_CONNECT_INDEX))
162 data->ocd_index = index;
165 * Divine LOV knows that OBDs under it are OSCs.
167 imp = tgt_obd->u.cli.cl_import;
170 tgt_obd->obd_no_recov = 0;
171 /* FIXME this is probably supposed to be
172 ptlrpc_set_import_active. Horrible naming. */
173 ptlrpc_activate_import(imp);
176 rc = obd_register_observer(tgt_obd, obd);
178 CERROR("Target %s register_observer error %d\n",
179 obd_uuid2str(tgt_uuid), rc);
184 if (imp->imp_invalid) {
185 CDEBUG(D_CONFIG, "not connecting OSC %s; administratively "
186 "disabled\n", obd_uuid2str(tgt_uuid));
190 rc = obd_connect(NULL, &lov->lov_tgts[index]->ltd_exp, tgt_obd,
191 &lov_osc_uuid, data, NULL);
192 if (rc || !lov->lov_tgts[index]->ltd_exp) {
193 CERROR("Target %s connect error %d\n",
194 obd_uuid2str(tgt_uuid), rc);
198 lov->lov_tgts[index]->ltd_reap = 0;
200 CDEBUG(D_CONFIG, "Connected tgt idx %d %s (%s) %sactive\n", index,
201 obd_uuid2str(tgt_uuid), tgt_obd->obd_name, activate ? "":"in");
204 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
206 struct obd_device *osc_obd = lov->lov_tgts[index]->ltd_exp->exp_obd;
207 cfs_proc_dir_entry_t *osc_symlink;
209 LASSERT(osc_obd != NULL);
210 LASSERT(osc_obd->obd_magic == OBD_DEVICE_MAGIC);
211 LASSERT(osc_obd->obd_type->typ_name != NULL);
213 osc_symlink = lprocfs_add_symlink(osc_obd->obd_name,
216 osc_obd->obd_type->typ_name,
218 if (osc_symlink == NULL) {
219 CERROR("could not register LOV target "
220 "/proc/fs/lustre/%s/%s/target_obds/%s.",
221 obd->obd_type->typ_name, obd->obd_name,
223 lprocfs_remove(&lov_proc_dir);
228 rc = qos_add_tgt(obd, index);
230 CERROR("qos_add_tgt failed %d\n", rc);
235 static int lov_connect(const struct lu_env *env,
236 struct obd_export **exp, struct obd_device *obd,
237 struct obd_uuid *cluuid, struct obd_connect_data *data,
240 struct lov_obd *lov = &obd->u.lov;
241 struct lov_tgt_desc *tgt;
242 struct lustre_handle conn;
246 CDEBUG(D_CONFIG, "connect #%d\n", lov->lov_connects);
248 rc = class_connect(&conn, obd, cluuid);
252 *exp = class_conn2export(&conn);
254 /* Why should there ever be more than 1 connect? */
256 LASSERT(lov->lov_connects == 1);
258 memset(&lov->lov_ocd, 0, sizeof(lov->lov_ocd));
260 lov->lov_ocd = *data;
263 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
264 tgt = lov->lov_tgts[i];
265 if (!tgt || obd_uuid_empty(&tgt->ltd_uuid))
267 /* Flags will be lowest common denominator */
268 rc = lov_connect_obd(obd, i, tgt->ltd_activate, &lov->lov_ocd);
270 CERROR("%s: lov connect tgt %d failed: %d\n",
271 obd->obd_name, i, rc);
274 /* connect to administrative disabled ost */
275 if (!lov->lov_tgts[i]->ltd_exp)
278 rc = lov_notify(obd, lov->lov_tgts[i]->ltd_exp->exp_obd,
279 OBD_NOTIFY_CONNECT, (void *)&i);
281 CERROR("%s error sending notify %d\n",
290 static int lov_disconnect_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
292 cfs_proc_dir_entry_t *lov_proc_dir;
293 struct lov_obd *lov = &obd->u.lov;
294 struct obd_device *osc_obd;
298 osc_obd = class_exp2obd(tgt->ltd_exp);
299 CDEBUG(D_CONFIG, "%s: disconnecting target %s\n",
300 obd->obd_name, osc_obd->obd_name);
302 if (tgt->ltd_active) {
304 lov->desc.ld_active_tgt_count--;
305 tgt->ltd_exp->exp_obd->obd_inactive = 1;
308 lov_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
310 cfs_proc_dir_entry_t *osc_symlink;
312 osc_symlink = lprocfs_srch(lov_proc_dir, osc_obd->obd_name);
314 lprocfs_remove(&osc_symlink);
316 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing.",
317 obd->obd_type->typ_name, obd->obd_name,
323 /* Pass it on to our clients.
324 * XXX This should be an argument to disconnect,
325 * XXX not a back-door flag on the OBD. Ah well.
327 osc_obd->obd_force = obd->obd_force;
328 osc_obd->obd_fail = obd->obd_fail;
329 osc_obd->obd_no_recov = obd->obd_no_recov;
332 obd_register_observer(osc_obd, NULL);
334 rc = obd_disconnect(tgt->ltd_exp);
336 CERROR("Target %s disconnect error %d\n",
337 tgt->ltd_uuid.uuid, rc);
341 qos_del_tgt(obd, tgt);
347 static int lov_disconnect(struct obd_export *exp)
349 struct obd_device *obd = class_exp2obd(exp);
350 struct lov_obd *lov = &obd->u.lov;
357 /* Only disconnect the underlying layers on the final disconnect. */
359 if (lov->lov_connects != 0) {
360 /* why should there be more than 1 connect? */
361 CERROR("disconnect #%d\n", lov->lov_connects);
365 /* Let's hold another reference so lov_del_obd doesn't spin through
369 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
370 if (lov->lov_tgts[i] && lov->lov_tgts[i]->ltd_exp) {
371 /* Disconnection is the last we know about an obd */
372 lov_del_target(obd, i, 0, lov->lov_tgts[i]->ltd_gen);
378 rc = class_disconnect(exp); /* bz 9811 */
384 * -EINVAL : UUID can't be found in the LOV's target list
385 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
386 * -EBADF : The UUID is found, but the OBD is the wrong type (!)
387 * any >= 0 : is log target index
389 static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
390 enum obd_notify_event ev)
392 struct lov_obd *lov = &obd->u.lov;
393 struct lov_tgt_desc *tgt;
394 int index, activate, active;
397 CDEBUG(D_INFO, "Searching in lov %p for uuid %s event(%d)\n",
398 lov, uuid->uuid, ev);
401 for (index = 0; index < lov->desc.ld_tgt_count; index++) {
402 tgt = lov->lov_tgts[index];
403 if (!tgt || !tgt->ltd_exp)
406 CDEBUG(D_INFO, "lov idx %d is %s conn "LPX64"\n",
407 index, obd_uuid2str(&tgt->ltd_uuid),
408 tgt->ltd_exp->exp_handle.h_cookie);
409 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
413 if (index == lov->desc.ld_tgt_count)
414 GOTO(out, index = -EINVAL);
416 if (ev == OBD_NOTIFY_DEACTIVATE || ev == OBD_NOTIFY_ACTIVATE) {
417 activate = (ev == OBD_NOTIFY_ACTIVATE) ? 1 : 0;
419 if (lov->lov_tgts[index]->ltd_activate == activate) {
420 CDEBUG(D_INFO, "OSC %s already %sactivate!\n",
421 uuid->uuid, activate ? "" : "de");
423 lov->lov_tgts[index]->ltd_activate = activate;
424 CDEBUG(D_CONFIG, "%sactivate OSC %s\n",
425 activate ? "" : "de", obd_uuid2str(uuid));
428 } else if (ev == OBD_NOTIFY_INACTIVE || ev == OBD_NOTIFY_ACTIVE) {
429 active = (ev == OBD_NOTIFY_ACTIVE) ? 1 : 0;
431 if (lov->lov_tgts[index]->ltd_active == active) {
432 CDEBUG(D_INFO, "OSC %s already %sactive!\n",
433 uuid->uuid, active ? "" : "in");
436 CDEBUG(D_CONFIG, "Marking OSC %s %sactive\n",
437 obd_uuid2str(uuid), active ? "" : "in");
440 lov->lov_tgts[index]->ltd_active = active;
442 lov->desc.ld_active_tgt_count++;
443 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 0;
445 lov->desc.ld_active_tgt_count--;
446 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 1;
448 /* remove any old qos penalty */
449 lov->lov_tgts[index]->ltd_qos.ltq_penalty = 0;
451 CERROR("Unknown event(%d) for uuid %s", ev, uuid->uuid);
459 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
460 enum obd_notify_event ev, void *data)
465 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE ||
466 ev == OBD_NOTIFY_ACTIVATE || ev == OBD_NOTIFY_DEACTIVATE) {
467 struct obd_uuid *uuid;
471 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
472 CERROR("unexpected notification of %s %s!\n",
473 watched->obd_type->typ_name,
477 uuid = &watched->u.cli.cl_target_uuid;
479 /* Set OSC as active before notifying the observer, so the
480 * observer can use the OSC normally.
482 rc = lov_set_osc_active(obd, uuid, ev);
484 CERROR("event(%d) of %s failed: %d\n", ev,
485 obd_uuid2str(uuid), rc);
488 /* active event should be pass lov target index as data */
492 /* Pass the notification up the chain. */
494 rc = obd_notify_observer(obd, watched, ev, data);
496 /* NULL watched means all osc's in the lov (only for syncs) */
497 /* sync event should be send lov idx as data */
498 struct lov_obd *lov = &obd->u.lov;
502 is_sync = (ev == OBD_NOTIFY_SYNC) ||
503 (ev == OBD_NOTIFY_SYNC_NONBLOCK);
506 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
507 if (!lov->lov_tgts[i])
510 /* don't send sync event if target not
511 * connected/activated */
512 if (is_sync && !lov->lov_tgts[i]->ltd_active)
515 rc = obd_notify_observer(obd, lov->lov_tgts[i]->ltd_obd,
518 CERROR("%s: notify %s of %s failed %d\n",
520 obd->obd_observer->obd_name,
521 lov->lov_tgts[i]->ltd_obd->obd_name,
531 static int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
532 __u32 index, int gen, int active)
534 struct lov_obd *lov = &obd->u.lov;
535 struct lov_tgt_desc *tgt;
536 struct obd_device *tgt_obd;
540 CDEBUG(D_CONFIG, "uuid:%s idx:%d gen:%d active:%d\n",
541 uuidp->uuid, index, gen, active);
544 CERROR("request to add OBD %s with invalid generation: %d\n",
549 tgt_obd = class_find_client_obd(uuidp, LUSTRE_OSC_NAME,
554 cfs_mutex_down(&lov->lov_lock);
556 if ((index < lov->lov_tgt_size) && (lov->lov_tgts[index] != NULL)) {
557 tgt = lov->lov_tgts[index];
558 CERROR("UUID %s already assigned at LOV target index %d\n",
559 obd_uuid2str(&tgt->ltd_uuid), index);
560 cfs_mutex_up(&lov->lov_lock);
564 if (index >= lov->lov_tgt_size) {
565 /* We need to reallocate the lov target array. */
566 struct lov_tgt_desc **newtgts, **old = NULL;
567 __u32 newsize, oldsize = 0;
569 newsize = max(lov->lov_tgt_size, (__u32)2);
570 while (newsize < index + 1)
571 newsize = newsize << 1;
572 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
573 if (newtgts == NULL) {
574 cfs_mutex_up(&lov->lov_lock);
578 if (lov->lov_tgt_size) {
579 memcpy(newtgts, lov->lov_tgts, sizeof(*newtgts) *
582 oldsize = lov->lov_tgt_size;
585 lov->lov_tgts = newtgts;
586 lov->lov_tgt_size = newsize;
591 OBD_FREE(old, sizeof(*old) * oldsize);
593 CDEBUG(D_CONFIG, "tgts: %p size: %d\n",
594 lov->lov_tgts, lov->lov_tgt_size);
599 cfs_mutex_up(&lov->lov_lock);
603 rc = lov_ost_pool_add(&lov->lov_packed, index, lov->lov_tgt_size);
605 cfs_mutex_up(&lov->lov_lock);
610 tgt->ltd_uuid = *uuidp;
611 tgt->ltd_obd = tgt_obd;
612 /* XXX - add a sanity check on the generation number. */
614 tgt->ltd_index = index;
615 tgt->ltd_activate = active;
616 lov->lov_tgts[index] = tgt;
617 if (index >= lov->desc.ld_tgt_count)
618 lov->desc.ld_tgt_count = index + 1;
620 cfs_mutex_up(&lov->lov_lock);
622 CDEBUG(D_CONFIG, "idx=%d ltd_gen=%d ld_tgt_count=%d\n",
623 index, tgt->ltd_gen, lov->desc.ld_tgt_count);
625 rc = obd_notify(obd, tgt_obd, OBD_NOTIFY_CREATE, &index);
627 if (lov->lov_connects == 0) {
628 /* lov_connect hasn't been called yet. We'll do the
629 lov_connect_obd on this target when that fn first runs,
630 because we don't know the connect flags yet. */
636 rc = lov_connect_obd(obd, index, active, &lov->lov_ocd);
640 /* connect to administrative disabled ost */
644 rc = lov_notify(obd, tgt->ltd_exp->exp_obd,
645 active ? OBD_NOTIFY_CONNECT : OBD_NOTIFY_INACTIVE,
650 CERROR("add failed (%d), deleting %s\n", rc,
651 obd_uuid2str(&tgt->ltd_uuid));
652 lov_del_target(obd, index, 0, 0);
658 /* Schedule a target for deletion */
659 int lov_del_target(struct obd_device *obd, __u32 index,
660 struct obd_uuid *uuidp, int gen)
662 struct lov_obd *lov = &obd->u.lov;
663 int count = lov->desc.ld_tgt_count;
667 if (index >= count) {
668 CERROR("LOV target index %d >= number of LOV OBDs %d.\n",
675 if (!lov->lov_tgts[index]) {
676 CERROR("LOV target at index %d is not setup.\n", index);
677 GOTO(out, rc = -EINVAL);
680 if (uuidp && !obd_uuid_equals(uuidp, &lov->lov_tgts[index]->ltd_uuid)) {
681 CERROR("LOV target UUID %s at index %d doesn't match %s.\n",
682 lov_uuid2str(lov, index), index,
683 obd_uuid2str(uuidp));
684 GOTO(out, rc = -EINVAL);
687 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d exp: %p active: %d\n",
688 lov_uuid2str(lov, index), index,
689 lov->lov_tgts[index]->ltd_gen, lov->lov_tgts[index]->ltd_exp,
690 lov->lov_tgts[index]->ltd_active);
692 lov->lov_tgts[index]->ltd_reap = 1;
693 lov->lov_death_row++;
694 /* we really delete it from obd_putref */
701 static void __lov_del_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
703 struct obd_device *osc_obd;
706 LASSERT(tgt->ltd_reap);
708 osc_obd = class_exp2obd(tgt->ltd_exp);
710 CDEBUG(D_CONFIG, "Removing tgt %s : %s\n",
712 osc_obd ? osc_obd->obd_name : "<no obd>");
715 lov_disconnect_obd(obd, tgt);
719 /* Manual cleanup - no cleanup logs to clean up the osc's. We must
720 do it ourselves. And we can't do it from lov_cleanup,
721 because we just lost our only reference to it. */
723 class_manual_cleanup(osc_obd);
726 void lov_fix_desc_stripe_size(__u64 *val)
728 if (*val < PTLRPC_MAX_BRW_SIZE) {
729 LCONSOLE_WARN("Increasing default stripe size to min %u\n",
730 PTLRPC_MAX_BRW_SIZE);
731 *val = PTLRPC_MAX_BRW_SIZE;
732 } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) {
733 *val &= ~(LOV_MIN_STRIPE_SIZE - 1);
734 LCONSOLE_WARN("Changing default stripe size to "LPU64" (a "
736 *val, LOV_MIN_STRIPE_SIZE);
740 void lov_fix_desc_stripe_count(__u32 *val)
746 void lov_fix_desc_pattern(__u32 *val)
748 /* from lov_setstripe */
749 if ((*val != 0) && (*val != LOV_PATTERN_RAID0)) {
750 LCONSOLE_WARN("Unknown stripe pattern: %#x\n", *val);
755 void lov_fix_desc_qos_maxage(__u32 *val)
759 *val = QOS_DEFAULT_MAXAGE;
762 void lov_fix_desc(struct lov_desc *desc)
764 lov_fix_desc_stripe_size(&desc->ld_default_stripe_size);
765 lov_fix_desc_stripe_count(&desc->ld_default_stripe_count);
766 lov_fix_desc_pattern(&desc->ld_pattern);
767 lov_fix_desc_qos_maxage(&desc->ld_qos_maxage);
770 int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
772 struct lprocfs_static_vars lvars = { 0 };
773 struct lov_desc *desc;
774 struct lov_obd *lov = &obd->u.lov;
778 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
779 CERROR("LOV setup requires a descriptor\n");
783 desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
785 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
786 CERROR("descriptor size wrong: %d > %d\n",
787 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
791 if (desc->ld_magic != LOV_DESC_MAGIC) {
792 if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
793 CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n",
794 obd->obd_name, desc);
795 lustre_swab_lov_desc(desc);
797 CERROR("%s: Bad lov desc magic: %#x\n",
798 obd->obd_name, desc->ld_magic);
805 desc->ld_active_tgt_count = 0;
807 lov->lov_tgt_size = 0;
809 cfs_sema_init(&lov->lov_lock, 1);
810 cfs_atomic_set(&lov->lov_refcount, 0);
811 CFS_INIT_LIST_HEAD(&lov->lov_qos.lq_oss_list);
812 cfs_init_rwsem(&lov->lov_qos.lq_rw_sem);
813 lov->lov_sp_me = LUSTRE_SP_CLI;
814 lov->lov_qos.lq_dirty = 1;
815 lov->lov_qos.lq_rr.lqr_dirty = 1;
816 lov->lov_qos.lq_reset = 1;
817 /* Default priority is toward free space balance */
818 lov->lov_qos.lq_prio_free = 232;
819 /* Default threshold for rr (roughly 17%) */
820 lov->lov_qos.lq_threshold_rr = 43;
821 /* Init statfs fields */
822 OBD_ALLOC_PTR(lov->lov_qos.lq_statfs_data);
823 if (NULL == lov->lov_qos.lq_statfs_data)
825 cfs_waitq_init(&lov->lov_qos.lq_statfs_waitq);
827 lov->lov_pools_hash_body = cfs_hash_create("POOLS", HASH_POOLS_CUR_BITS,
829 HASH_POOLS_BKT_BITS, 0,
832 &pool_hash_operations,
834 CFS_INIT_LIST_HEAD(&lov->lov_pool_list);
835 lov->lov_pool_count = 0;
836 rc = lov_ost_pool_init(&lov->lov_packed, 0);
838 GOTO(out_free_statfs, rc);
839 rc = lov_ost_pool_init(&lov->lov_qos.lq_rr.lqr_pool, 0);
841 GOTO(out_free_lov_packed, rc);
843 lprocfs_lov_init_vars(&lvars);
844 lprocfs_obd_setup(obd, lvars.obd_vars);
849 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
850 0444, &lov_proc_target_fops, obd);
852 CWARN("Error adding the target_obd file\n");
855 lov->lov_pool_proc_entry = lprocfs_register("pools",
862 lov_ost_pool_free(&lov->lov_packed);
864 OBD_FREE_PTR(lov->lov_qos.lq_statfs_data);
868 static int lov_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
871 struct lov_obd *lov = &obd->u.lov;
876 case OBD_CLEANUP_EARLY: {
878 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
879 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
881 obd_precleanup(class_exp2obd(lov->lov_tgts[i]->ltd_exp),
886 case OBD_CLEANUP_EXPORTS:
887 lprocfs_obd_cleanup(obd);
888 rc = obd_llog_finish(obd, 0);
890 CERROR("failed to cleanup llogging subsystems\n");
896 static int lov_cleanup(struct obd_device *obd)
898 struct lov_obd *lov = &obd->u.lov;
899 cfs_list_t *pos, *tmp;
900 struct pool_desc *pool;
903 cfs_list_for_each_safe(pos, tmp, &lov->lov_pool_list) {
904 pool = cfs_list_entry(pos, struct pool_desc, pool_list);
905 /* free pool structs */
906 CDEBUG(D_INFO, "delete pool %p\n", pool);
907 lov_pool_del(obd, pool->pool_name);
909 cfs_hash_putref(lov->lov_pools_hash_body);
910 lov_ost_pool_free(&(lov->lov_qos.lq_rr.lqr_pool));
911 lov_ost_pool_free(&lov->lov_packed);
916 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
917 if (!lov->lov_tgts[i])
920 /* Inactive targets may never have connected */
921 if (lov->lov_tgts[i]->ltd_active ||
922 cfs_atomic_read(&lov->lov_refcount))
923 /* We should never get here - these
924 should have been removed in the
926 CERROR("lov tgt %d not cleaned!"
927 " deathrow=%d, lovrc=%d\n",
928 i, lov->lov_death_row,
929 cfs_atomic_read(&lov->lov_refcount));
930 lov_del_target(obd, i, 0, 0);
933 OBD_FREE(lov->lov_tgts, sizeof(*lov->lov_tgts) *
935 lov->lov_tgt_size = 0;
937 OBD_FREE_PTR(lov->lov_qos.lq_statfs_data);
941 int lov_process_config_base(struct obd_device *obd, struct lustre_cfg *lcfg,
942 __u32 *indexp, int *genp)
944 struct obd_uuid obd_uuid;
949 switch(cmd = lcfg->lcfg_command) {
950 case LCFG_LOV_ADD_OBD:
951 case LCFG_LOV_ADD_INA:
952 case LCFG_LOV_DEL_OBD: {
955 /* lov_modify_tgts add 0:lov_mdsA 1:ost1_UUID 2:0 3:1 */
956 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
957 GOTO(out, rc = -EINVAL);
959 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
961 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", indexp) != 1)
962 GOTO(out, rc = -EINVAL);
963 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", genp) != 1)
964 GOTO(out, rc = -EINVAL);
967 if (cmd == LCFG_LOV_ADD_OBD)
968 rc = lov_add_target(obd, &obd_uuid, index, gen, 1);
969 else if (cmd == LCFG_LOV_ADD_INA)
970 rc = lov_add_target(obd, &obd_uuid, index, gen, 0);
972 rc = lov_del_target(obd, index, &obd_uuid, gen);
976 struct lprocfs_static_vars lvars = { 0 };
977 struct lov_desc *desc = &(obd->u.lov.desc);
980 GOTO(out, rc = -EINVAL);
982 lprocfs_lov_init_vars(&lvars);
984 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) cfs_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 (oti->oti_ost_uuid) {
1030 ost_uuid = oti->oti_ost_uuid;
1031 CDEBUG(D_HA, "clearing orphans only for %s\n",
1035 obd_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);
1076 obd_putref(export->exp_obd);
1082 static int lov_recreate(struct obd_export *exp, struct obdo *src_oa,
1083 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1085 struct lov_stripe_md *obj_mdp, *lsm;
1086 struct lov_obd *lov = &exp->exp_obd->u.lov;
1091 LASSERT(src_oa->o_valid & OBD_MD_FLFLAGS &&
1092 src_oa->o_flags & OBD_FL_RECREATE_OBJS);
1094 OBD_ALLOC(obj_mdp, sizeof(*obj_mdp));
1095 if (obj_mdp == NULL)
1098 ost_idx = src_oa->o_nlink;
1101 GOTO(out, rc = -EINVAL);
1102 if (ost_idx >= lov->desc.ld_tgt_count ||
1103 !lov->lov_tgts[ost_idx])
1104 GOTO(out, rc = -EINVAL);
1106 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1107 if (lsm->lsm_oinfo[i]->loi_ost_idx == ost_idx) {
1108 if (lsm->lsm_oinfo[i]->loi_id != src_oa->o_id)
1109 GOTO(out, rc = -EINVAL);
1113 if (i == lsm->lsm_stripe_count)
1114 GOTO(out, rc = -EINVAL);
1116 rc = obd_create(lov->lov_tgts[ost_idx]->ltd_exp, src_oa, &obj_mdp, oti);
1118 OBD_FREE(obj_mdp, sizeof(*obj_mdp));
1122 /* the LOV expects oa->o_id to be set to the LOV object id */
1123 static int lov_create(struct obd_export *exp, struct obdo *src_oa,
1124 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1126 struct lov_obd *lov;
1127 struct obd_info oinfo;
1128 struct lov_request_set *set = NULL;
1129 struct lov_request *req;
1130 struct l_wait_info lwi = { 0 };
1134 LASSERT(ea != NULL);
1138 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1139 src_oa->o_flags == OBD_FL_DELORPHAN) {
1140 rc = lov_clear_orphans(exp, src_oa, ea, oti);
1144 lov = &exp->exp_obd->u.lov;
1145 if (!lov->desc.ld_active_tgt_count)
1148 obd_getref(exp->exp_obd);
1149 /* Recreate a specific object id at the given OST index */
1150 if ((src_oa->o_valid & OBD_MD_FLFLAGS) &&
1151 (src_oa->o_flags & OBD_FL_RECREATE_OBJS)) {
1152 rc = lov_recreate(exp, src_oa, ea, oti);
1156 /* issue statfs rpcs if the osfs data is older than qos_maxage - 1s,
1157 * later in alloc_qos(), we will wait for those rpcs to complete if
1158 * the osfs age is older than 2 * qos_maxage */
1159 qos_statfs_update(exp->exp_obd,
1160 cfs_time_shift_64(-lov->desc.ld_qos_maxage +
1161 OBD_STATFS_CACHE_SECONDS),
1164 rc = lov_prep_create_set(exp, &oinfo, ea, src_oa, oti, &set);
1168 cfs_list_for_each_entry(req, &set->set_list, rq_link) {
1169 /* XXX: LOV STACKING: use real "obj_mdp" sub-data */
1170 rc = obd_create_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1171 &req->rq_oi, &req->rq_oi.oi_md, oti);
1174 /* osc_create have timeout equ obd_timeout/2 so waiting don't be
1175 * longer then this */
1176 l_wait_event(set->set_waitq, lov_finished_set(set), &lwi);
1178 /* we not have ptlrpc set for assign set->interpret and should
1179 * be call interpret function himself. calling from cb_create_update
1180 * not permited because lov_fini_create_set can sleep for long time,
1181 * but we must avoid sleeping in ptlrpcd interpret function. */
1182 rc = lov_fini_create_set(set, ea);
1184 obd_putref(exp->exp_obd);
1188 #define ASSERT_LSM_MAGIC(lsmp) \
1190 LASSERT((lsmp) != NULL); \
1191 LASSERTF(((lsmp)->lsm_magic == LOV_MAGIC_V1 || \
1192 (lsmp)->lsm_magic == LOV_MAGIC_V3), \
1193 "%p->lsm_magic=%x\n", (lsmp), (lsmp)->lsm_magic); \
1196 static int lov_destroy(struct obd_export *exp, struct obdo *oa,
1197 struct lov_stripe_md *lsm, struct obd_trans_info *oti,
1198 struct obd_export *md_exp, void *capa)
1200 struct lov_request_set *set;
1201 struct obd_info oinfo;
1202 struct lov_request *req;
1204 struct lov_obd *lov;
1205 int rc = 0, err = 0;
1208 ASSERT_LSM_MAGIC(lsm);
1210 if (!exp || !exp->exp_obd)
1213 if (oa->o_valid & OBD_MD_FLCOOKIE) {
1215 LASSERT(oti->oti_logcookies);
1218 lov = &exp->exp_obd->u.lov;
1219 obd_getref(exp->exp_obd);
1220 rc = lov_prep_destroy_set(exp, &oinfo, oa, lsm, oti, &set);
1224 cfs_list_for_each (pos, &set->set_list) {
1225 req = cfs_list_entry(pos, struct lov_request, rq_link);
1227 if (oa->o_valid & OBD_MD_FLCOOKIE)
1228 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1230 err = obd_destroy(lov->lov_tgts[req->rq_idx]->ltd_exp,
1231 req->rq_oi.oi_oa, NULL, oti, NULL, capa);
1232 err = lov_update_common_set(set, req, err);
1234 CERROR("error: destroying objid "LPX64" subobj "
1235 LPX64" on OST idx %d: rc = %d\n",
1236 oa->o_id, req->rq_oi.oi_oa->o_id,
1244 LASSERT(lsm_op_find(lsm->lsm_magic) != NULL);
1245 rc = lsm_op_find(lsm->lsm_magic)->lsm_destroy(lsm, oa, md_exp);
1247 err = lov_fini_destroy_set(set);
1249 obd_putref(exp->exp_obd);
1250 RETURN(rc ? rc : err);
1253 static int lov_getattr(struct obd_export *exp, struct obd_info *oinfo)
1255 struct lov_request_set *set;
1256 struct lov_request *req;
1258 struct lov_obd *lov;
1259 int err = 0, rc = 0;
1263 ASSERT_LSM_MAGIC(oinfo->oi_md);
1265 if (!exp || !exp->exp_obd)
1268 lov = &exp->exp_obd->u.lov;
1270 rc = lov_prep_getattr_set(exp, oinfo, &set);
1274 cfs_list_for_each (pos, &set->set_list) {
1275 req = cfs_list_entry(pos, struct lov_request, rq_link);
1277 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1278 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1279 req->rq_oi.oi_oa->o_id, req->rq_idx);
1281 rc = obd_getattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1283 err = lov_update_common_set(set, req, rc);
1285 CERROR("error: getattr objid "LPX64" subobj "
1286 LPX64" on OST idx %d: rc = %d\n",
1287 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1293 rc = lov_fini_getattr_set(set);
1299 static int lov_getattr_interpret(struct ptlrpc_request_set *rqset,
1302 struct lov_request_set *lovset = (struct lov_request_set *)data;
1306 /* don't do attribute merge if this aysnc op failed */
1308 cfs_atomic_set(&lovset->set_completes, 0);
1309 err = lov_fini_getattr_set(lovset);
1310 RETURN(rc ? rc : err);
1313 static int lov_getattr_async(struct obd_export *exp, struct obd_info *oinfo,
1314 struct ptlrpc_request_set *rqset)
1316 struct lov_request_set *lovset;
1317 struct lov_obd *lov;
1319 struct lov_request *req;
1324 ASSERT_LSM_MAGIC(oinfo->oi_md);
1326 if (!exp || !exp->exp_obd)
1329 lov = &exp->exp_obd->u.lov;
1331 rc = lov_prep_getattr_set(exp, oinfo, &lovset);
1335 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1336 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1337 oinfo->oi_md->lsm_stripe_size);
1339 cfs_list_for_each (pos, &lovset->set_list) {
1340 req = cfs_list_entry(pos, struct lov_request, rq_link);
1342 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1343 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1344 req->rq_oi.oi_oa->o_id, req->rq_idx);
1345 rc = obd_getattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1346 &req->rq_oi, rqset);
1348 CERROR("error: getattr objid "LPX64" subobj "
1349 LPX64" on OST idx %d: rc = %d\n",
1350 oinfo->oi_oa->o_id, req->rq_oi.oi_oa->o_id,
1356 if (!cfs_list_empty(&rqset->set_requests)) {
1358 LASSERT (rqset->set_interpret == NULL);
1359 rqset->set_interpret = lov_getattr_interpret;
1360 rqset->set_arg = (void *)lovset;
1365 cfs_atomic_set(&lovset->set_completes, 0);
1366 err = lov_fini_getattr_set(lovset);
1367 RETURN(rc ? rc : err);
1370 static int lov_setattr(struct obd_export *exp, struct obd_info *oinfo,
1371 struct obd_trans_info *oti)
1373 struct lov_request_set *set;
1374 struct lov_obd *lov;
1376 struct lov_request *req;
1377 int err = 0, rc = 0;
1381 ASSERT_LSM_MAGIC(oinfo->oi_md);
1383 if (!exp || !exp->exp_obd)
1386 /* for now, we only expect the following updates here */
1387 LASSERT(!(oinfo->oi_oa->o_valid & ~(OBD_MD_FLID | OBD_MD_FLTYPE |
1388 OBD_MD_FLMODE | OBD_MD_FLATIME |
1389 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1390 OBD_MD_FLFLAGS | OBD_MD_FLSIZE |
1391 OBD_MD_FLGROUP | OBD_MD_FLUID |
1392 OBD_MD_FLGID | OBD_MD_FLFID |
1394 lov = &exp->exp_obd->u.lov;
1395 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1399 cfs_list_for_each (pos, &set->set_list) {
1400 req = cfs_list_entry(pos, struct lov_request, rq_link);
1402 rc = obd_setattr(lov->lov_tgts[req->rq_idx]->ltd_exp,
1404 err = lov_update_setattr_set(set, req, rc);
1406 CERROR("error: setattr objid "LPX64" subobj "
1407 LPX64" on OST idx %d: rc = %d\n",
1408 set->set_oi->oi_oa->o_id,
1409 req->rq_oi.oi_oa->o_id, req->rq_idx, err);
1414 err = lov_fini_setattr_set(set);
1420 static int lov_setattr_interpret(struct ptlrpc_request_set *rqset,
1423 struct lov_request_set *lovset = (struct lov_request_set *)data;
1428 cfs_atomic_set(&lovset->set_completes, 0);
1429 err = lov_fini_setattr_set(lovset);
1430 RETURN(rc ? rc : err);
1433 /* If @oti is given, the request goes from MDS and responses from OSTs are not
1434 needed. Otherwise, a client is waiting for responses. */
1435 static int lov_setattr_async(struct obd_export *exp, struct obd_info *oinfo,
1436 struct obd_trans_info *oti,
1437 struct ptlrpc_request_set *rqset)
1439 struct lov_request_set *set;
1440 struct lov_request *req;
1442 struct lov_obd *lov;
1447 ASSERT_LSM_MAGIC(oinfo->oi_md);
1448 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE) {
1450 LASSERT(oti->oti_logcookies);
1453 if (!exp || !exp->exp_obd)
1456 lov = &exp->exp_obd->u.lov;
1457 rc = lov_prep_setattr_set(exp, oinfo, oti, &set);
1461 CDEBUG(D_INFO, "objid "LPX64": %ux%u byte stripes\n",
1462 oinfo->oi_md->lsm_object_id, oinfo->oi_md->lsm_stripe_count,
1463 oinfo->oi_md->lsm_stripe_size);
1465 cfs_list_for_each (pos, &set->set_list) {
1466 req = cfs_list_entry(pos, struct lov_request, rq_link);
1468 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
1469 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1471 CDEBUG(D_INFO, "objid "LPX64"[%d] has subobj "LPX64" at idx "
1472 "%u\n", oinfo->oi_oa->o_id, req->rq_stripe,
1473 req->rq_oi.oi_oa->o_id, req->rq_idx);
1475 rc = obd_setattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1476 &req->rq_oi, oti, rqset);
1478 CERROR("error: setattr objid "LPX64" subobj "
1479 LPX64" on OST idx %d: rc = %d\n",
1480 set->set_oi->oi_oa->o_id,
1481 req->rq_oi.oi_oa->o_id,
1487 /* If we are not waiting for responses on async requests, return. */
1488 if (rc || !rqset || cfs_list_empty(&rqset->set_requests)) {
1491 cfs_atomic_set(&set->set_completes, 0);
1492 err = lov_fini_setattr_set(set);
1493 RETURN(rc ? rc : err);
1496 LASSERT(rqset->set_interpret == NULL);
1497 rqset->set_interpret = lov_setattr_interpret;
1498 rqset->set_arg = (void *)set;
1503 static int lov_punch_interpret(struct ptlrpc_request_set *rqset,
1506 struct lov_request_set *lovset = (struct lov_request_set *)data;
1511 cfs_atomic_set(&lovset->set_completes, 0);
1512 err = lov_fini_punch_set(lovset);
1513 RETURN(rc ? rc : err);
1516 /* FIXME: maybe we'll just make one node the authoritative attribute node, then
1517 * we can send this 'punch' to just the authoritative node and the nodes
1518 * that the punch will affect. */
1519 static int lov_punch(struct obd_export *exp, struct obd_info *oinfo,
1520 struct obd_trans_info *oti,
1521 struct ptlrpc_request_set *rqset)
1523 struct lov_request_set *set;
1524 struct lov_obd *lov;
1526 struct lov_request *req;
1531 ASSERT_LSM_MAGIC(oinfo->oi_md);
1533 if (!exp || !exp->exp_obd)
1536 lov = &exp->exp_obd->u.lov;
1537 rc = lov_prep_punch_set(exp, oinfo, oti, &set);
1541 cfs_list_for_each (pos, &set->set_list) {
1542 req = cfs_list_entry(pos, struct lov_request, rq_link);
1544 rc = obd_punch(lov->lov_tgts[req->rq_idx]->ltd_exp,
1545 &req->rq_oi, NULL, rqset);
1547 CERROR("error: punch objid "LPX64" subobj "LPX64
1548 " on OST idx %d: rc = %d\n",
1549 set->set_oi->oi_oa->o_id,
1550 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1555 if (rc || cfs_list_empty(&rqset->set_requests)) {
1557 err = lov_fini_punch_set(set);
1558 RETURN(rc ? rc : err);
1561 LASSERT(rqset->set_interpret == NULL);
1562 rqset->set_interpret = lov_punch_interpret;
1563 rqset->set_arg = (void *)set;
1568 static int lov_sync_interpret(struct ptlrpc_request_set *rqset,
1571 struct lov_request_set *lovset = data;
1576 cfs_atomic_set(&lovset->set_completes, 0);
1577 err = lov_fini_sync_set(lovset);
1581 static int lov_sync(struct obd_export *exp, struct obd_info *oinfo,
1582 obd_off start, obd_off end,
1583 struct ptlrpc_request_set *rqset)
1585 struct lov_request_set *set = NULL;
1586 struct lov_obd *lov;
1588 struct lov_request *req;
1592 ASSERT_LSM_MAGIC(oinfo->oi_md);
1593 LASSERT(rqset != NULL);
1598 lov = &exp->exp_obd->u.lov;
1599 rc = lov_prep_sync_set(exp, oinfo, start, end, &set);
1603 CDEBUG(D_INFO, "fsync objid "LPX64" ["LPX64", "LPX64"]\n",
1604 set->set_oi->oi_oa->o_id, start, end);
1606 cfs_list_for_each (pos, &set->set_list) {
1607 req = cfs_list_entry(pos, struct lov_request, rq_link);
1609 rc = obd_sync(lov->lov_tgts[req->rq_idx]->ltd_exp, &req->rq_oi,
1610 req->rq_oi.oi_policy.l_extent.start,
1611 req->rq_oi.oi_policy.l_extent.end, rqset);
1613 CERROR("error: fsync objid "LPX64" subobj "LPX64
1614 " on OST idx %d: rc = %d\n",
1615 set->set_oi->oi_oa->o_id,
1616 req->rq_oi.oi_oa->o_id, req->rq_idx, rc);
1621 /* If we are not waiting for responses on async requests, return. */
1622 if (rc || cfs_list_empty(&rqset->set_requests)) {
1623 int err = lov_fini_sync_set(set);
1628 LASSERT(rqset->set_interpret == NULL);
1629 rqset->set_interpret = lov_sync_interpret;
1630 rqset->set_arg = (void *)set;
1635 static int lov_brw_check(struct lov_obd *lov, struct obd_info *lov_oinfo,
1636 obd_count oa_bufs, struct brw_page *pga)
1638 struct obd_info oinfo = { { { 0 } } };
1641 oinfo.oi_oa = lov_oinfo->oi_oa;
1643 /* The caller just wants to know if there's a chance that this
1644 * I/O can succeed */
1645 for (i = 0; i < oa_bufs; i++) {
1646 int stripe = lov_stripe_number(lov_oinfo->oi_md, pga[i].off);
1647 int ost = lov_oinfo->oi_md->lsm_oinfo[stripe]->loi_ost_idx;
1650 if (!lov_stripe_intersects(lov_oinfo->oi_md, i, pga[i].off,
1651 pga[i].off + pga[i].count - 1,
1655 if (!lov->lov_tgts[ost] || !lov->lov_tgts[ost]->ltd_active) {
1656 CDEBUG(D_HA, "lov idx %d inactive\n", ost);
1660 rc = obd_brw(OBD_BRW_CHECK, lov->lov_tgts[ost]->ltd_exp, &oinfo,
1668 static int lov_brw(int cmd, struct obd_export *exp, struct obd_info *oinfo,
1669 obd_count oa_bufs, struct brw_page *pga,
1670 struct obd_trans_info *oti)
1672 struct lov_request_set *set;
1673 struct lov_request *req;
1675 struct lov_obd *lov = &exp->exp_obd->u.lov;
1679 ASSERT_LSM_MAGIC(oinfo->oi_md);
1681 if (cmd == OBD_BRW_CHECK) {
1682 rc = lov_brw_check(lov, oinfo, oa_bufs, pga);
1686 rc = lov_prep_brw_set(exp, oinfo, oa_bufs, pga, oti, &set);
1690 cfs_list_for_each (pos, &set->set_list) {
1691 struct obd_export *sub_exp;
1692 struct brw_page *sub_pga;
1693 req = cfs_list_entry(pos, struct lov_request, rq_link);
1695 sub_exp = lov->lov_tgts[req->rq_idx]->ltd_exp;
1696 sub_pga = set->set_pga + req->rq_pgaidx;
1697 rc = obd_brw(cmd, sub_exp, &req->rq_oi, req->rq_oabufs,
1701 lov_update_common_set(set, req, rc);
1704 err = lov_fini_brw_set(set);
1710 static int lov_enqueue_interpret(struct ptlrpc_request_set *rqset,
1713 struct lov_request_set *lovset = (struct lov_request_set *)data;
1715 rc = lov_fini_enqueue_set(lovset, lovset->set_ei->ei_mode, rc, rqset);
1719 static int lov_enqueue(struct obd_export *exp, struct obd_info *oinfo,
1720 struct ldlm_enqueue_info *einfo,
1721 struct ptlrpc_request_set *rqset)
1723 ldlm_mode_t mode = einfo->ei_mode;
1724 struct lov_request_set *set;
1725 struct lov_request *req;
1727 struct lov_obd *lov;
1732 ASSERT_LSM_MAGIC(oinfo->oi_md);
1733 LASSERT(mode == (mode & -mode));
1735 /* we should never be asked to replay a lock this way. */
1736 LASSERT((oinfo->oi_flags & LDLM_FL_REPLAY) == 0);
1738 if (!exp || !exp->exp_obd)
1741 lov = &exp->exp_obd->u.lov;
1742 rc = lov_prep_enqueue_set(exp, oinfo, einfo, &set);
1746 cfs_list_for_each (pos, &set->set_list) {
1747 req = cfs_list_entry(pos, struct lov_request, rq_link);
1749 rc = obd_enqueue(lov->lov_tgts[req->rq_idx]->ltd_exp,
1750 &req->rq_oi, einfo, rqset);
1755 if (rqset && !cfs_list_empty(&rqset->set_requests)) {
1757 LASSERT(rqset->set_interpret == NULL);
1758 rqset->set_interpret = lov_enqueue_interpret;
1759 rqset->set_arg = (void *)set;
1763 rc = lov_fini_enqueue_set(set, mode, rc, rqset);
1767 static int lov_change_cbdata(struct obd_export *exp,
1768 struct lov_stripe_md *lsm, ldlm_iterator_t it,
1771 struct lov_obd *lov;
1775 ASSERT_LSM_MAGIC(lsm);
1777 if (!exp || !exp->exp_obd)
1780 lov = &exp->exp_obd->u.lov;
1781 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1782 struct lov_stripe_md submd;
1783 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
1785 if (!lov->lov_tgts[loi->loi_ost_idx]) {
1786 CDEBUG(D_HA, "lov idx %d NULL \n", loi->loi_ost_idx);
1790 LASSERT_SEQ_IS_MDT(loi->loi_seq);
1791 submd.lsm_object_id = loi->loi_id;
1792 submd.lsm_object_seq = loi->loi_seq;
1793 submd.lsm_stripe_count = 0;
1794 rc = obd_change_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1800 /* find any ldlm lock of the inode in lov
1804 static int lov_find_cbdata(struct obd_export *exp,
1805 struct lov_stripe_md *lsm, ldlm_iterator_t it,
1808 struct lov_obd *lov;
1812 ASSERT_LSM_MAGIC(lsm);
1814 if (!exp || !exp->exp_obd)
1817 lov = &exp->exp_obd->u.lov;
1818 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1819 struct lov_stripe_md submd;
1820 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
1822 if (!lov->lov_tgts[loi->loi_ost_idx]) {
1823 CDEBUG(D_HA, "lov idx %d NULL \n", loi->loi_ost_idx);
1827 LASSERT_SEQ_IS_MDT(loi->loi_seq);
1828 submd.lsm_object_id = loi->loi_id;
1829 submd.lsm_object_seq = loi->loi_seq;
1830 submd.lsm_stripe_count = 0;
1831 rc = obd_find_cbdata(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1839 static int lov_cancel(struct obd_export *exp, struct lov_stripe_md *lsm,
1840 __u32 mode, struct lustre_handle *lockh)
1842 struct lov_request_set *set;
1843 struct obd_info oinfo;
1844 struct lov_request *req;
1846 struct lov_obd *lov;
1847 struct lustre_handle *lov_lockhp;
1848 int err = 0, rc = 0;
1851 ASSERT_LSM_MAGIC(lsm);
1853 if (!exp || !exp->exp_obd)
1856 LASSERT_SEQ_IS_MDT(lsm->lsm_object_seq);
1858 lov = &exp->exp_obd->u.lov;
1859 rc = lov_prep_cancel_set(exp, &oinfo, lsm, mode, lockh, &set);
1863 cfs_list_for_each (pos, &set->set_list) {
1864 req = cfs_list_entry(pos, struct lov_request, rq_link);
1865 lov_lockhp = set->set_lockh->llh_handles + req->rq_stripe;
1867 rc = obd_cancel(lov->lov_tgts[req->rq_idx]->ltd_exp,
1868 req->rq_oi.oi_md, mode, lov_lockhp);
1869 rc = lov_update_common_set(set, req, rc);
1871 CERROR("error: cancel objid "LPX64" subobj "
1872 LPX64" on OST idx %d: rc = %d\n",
1874 req->rq_oi.oi_md->lsm_object_id,
1880 lov_fini_cancel_set(set);
1884 static int lov_cancel_unused(struct obd_export *exp,
1885 struct lov_stripe_md *lsm,
1886 ldlm_cancel_flags_t flags, void *opaque)
1888 struct lov_obd *lov;
1892 if (!exp || !exp->exp_obd)
1895 lov = &exp->exp_obd->u.lov;
1897 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1899 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
1902 err = obd_cancel_unused(lov->lov_tgts[i]->ltd_exp, NULL,
1910 ASSERT_LSM_MAGIC(lsm);
1912 LASSERT_SEQ_IS_MDT(lsm->lsm_object_seq);
1913 for (i = 0; i < lsm->lsm_stripe_count; i++) {
1914 struct lov_stripe_md submd;
1915 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
1918 if (!lov->lov_tgts[loi->loi_ost_idx]) {
1919 CDEBUG(D_HA, "lov idx %d NULL\n", loi->loi_ost_idx);
1923 if (!lov->lov_tgts[loi->loi_ost_idx]->ltd_active)
1924 CDEBUG(D_HA, "lov idx %d inactive\n", loi->loi_ost_idx);
1926 submd.lsm_object_id = loi->loi_id;
1927 submd.lsm_object_seq = loi->loi_seq;
1928 submd.lsm_stripe_count = 0;
1929 err = obd_cancel_unused(lov->lov_tgts[loi->loi_ost_idx]->ltd_exp,
1930 &submd, flags, opaque);
1931 if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
1932 CERROR("error: cancel unused objid "LPX64" subobj "LPX64
1933 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
1934 loi->loi_id, loi->loi_ost_idx, err);
1942 int lov_statfs_interpret(struct ptlrpc_request_set *rqset, void *data, int rc)
1944 struct lov_request_set *lovset = (struct lov_request_set *)data;
1949 cfs_atomic_set(&lovset->set_completes, 0);
1951 err = lov_fini_statfs_set(lovset);
1952 RETURN(rc ? rc : err);
1955 static int lov_statfs_async(struct obd_device *obd, struct obd_info *oinfo,
1956 __u64 max_age, struct ptlrpc_request_set *rqset)
1958 struct lov_request_set *set;
1959 struct lov_request *req;
1961 struct lov_obd *lov;
1965 LASSERT(oinfo != NULL);
1966 LASSERT(oinfo->oi_osfs != NULL);
1969 rc = lov_prep_statfs_set(obd, oinfo, &set);
1973 cfs_list_for_each (pos, &set->set_list) {
1974 struct obd_device *osc_obd;
1976 req = cfs_list_entry(pos, struct lov_request, rq_link);
1978 osc_obd = class_exp2obd(lov->lov_tgts[req->rq_idx]->ltd_exp);
1979 rc = obd_statfs_async(osc_obd, &req->rq_oi, max_age, rqset);
1984 if (rc || cfs_list_empty(&rqset->set_requests)) {
1987 cfs_atomic_set(&set->set_completes, 0);
1988 err = lov_fini_statfs_set(set);
1989 RETURN(rc ? rc : err);
1992 LASSERT(rqset->set_interpret == NULL);
1993 rqset->set_interpret = lov_statfs_interpret;
1994 rqset->set_arg = (void *)set;
1998 static int lov_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1999 __u64 max_age, __u32 flags)
2001 struct ptlrpc_request_set *set = NULL;
2002 struct obd_info oinfo = { { { 0 } } };
2007 /* for obdclass we forbid using obd_statfs_rqset, but prefer using async
2008 * statfs requests */
2009 set = ptlrpc_prep_set();
2013 oinfo.oi_osfs = osfs;
2014 oinfo.oi_flags = flags;
2015 rc = lov_statfs_async(obd, &oinfo, max_age, set);
2017 rc = ptlrpc_set_wait(set);
2018 ptlrpc_set_destroy(set);
2023 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
2024 void *karg, void *uarg)
2026 struct obd_device *obddev = class_exp2obd(exp);
2027 struct lov_obd *lov = &obddev->u.lov;
2028 int i = 0, rc = 0, count = lov->desc.ld_tgt_count;
2029 struct obd_uuid *uuidp;
2033 case IOC_OBD_STATFS: {
2034 struct obd_ioctl_data *data = karg;
2035 struct obd_device *osc_obd;
2036 struct obd_statfs stat_buf = {0};
2039 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
2040 if ((index >= count))
2043 if (!lov->lov_tgts[index])
2044 /* Try again with the next index */
2046 if (!lov->lov_tgts[index]->ltd_active)
2049 osc_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
2054 if (cfs_copy_to_user(data->ioc_pbuf2, obd2cli_tgt(osc_obd),
2055 min((int) data->ioc_plen2,
2056 (int) sizeof(struct obd_uuid))))
2059 /* got statfs data */
2060 rc = obd_statfs(osc_obd, &stat_buf,
2061 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
2065 if (cfs_copy_to_user(data->ioc_pbuf1, &stat_buf,
2066 min((int) data->ioc_plen1,
2067 (int) sizeof(stat_buf))))
2071 case OBD_IOC_LOV_GET_CONFIG: {
2072 struct obd_ioctl_data *data;
2073 struct lov_desc *desc;
2078 if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
2081 data = (struct obd_ioctl_data *)buf;
2083 if (sizeof(*desc) > data->ioc_inllen1) {
2084 obd_ioctl_freedata(buf, len);
2088 if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
2089 obd_ioctl_freedata(buf, len);
2093 if (sizeof(__u32) * count > data->ioc_inllen3) {
2094 obd_ioctl_freedata(buf, len);
2098 desc = (struct lov_desc *)data->ioc_inlbuf1;
2099 memcpy(desc, &(lov->desc), sizeof(*desc));
2101 uuidp = (struct obd_uuid *)data->ioc_inlbuf2;
2102 genp = (__u32 *)data->ioc_inlbuf3;
2103 /* the uuid will be empty for deleted OSTs */
2104 for (i = 0; i < count; i++, uuidp++, genp++) {
2105 if (!lov->lov_tgts[i])
2107 *uuidp = lov->lov_tgts[i]->ltd_uuid;
2108 *genp = lov->lov_tgts[i]->ltd_gen;
2111 if (cfs_copy_to_user((void *)uarg, buf, len))
2113 obd_ioctl_freedata(buf, len);
2116 case LL_IOC_LOV_SETSTRIPE:
2117 rc = lov_setstripe(exp, len, karg, uarg);
2119 case LL_IOC_LOV_GETSTRIPE:
2120 rc = lov_getstripe(exp, karg, uarg);
2122 case LL_IOC_LOV_SETEA:
2123 rc = lov_setea(exp, karg, uarg);
2125 case OBD_IOC_QUOTACTL: {
2126 struct if_quotactl *qctl = karg;
2127 struct lov_tgt_desc *tgt = NULL;
2128 struct obd_quotactl *oqctl;
2130 if (qctl->qc_valid == QC_OSTIDX) {
2131 if (qctl->qc_idx < 0 || count <= qctl->qc_idx)
2134 tgt = lov->lov_tgts[qctl->qc_idx];
2135 if (!tgt || !tgt->ltd_exp)
2137 } else if (qctl->qc_valid == QC_UUID) {
2138 for (i = 0; i < count; i++) {
2139 tgt = lov->lov_tgts[i];
2141 !obd_uuid_equals(&tgt->ltd_uuid,
2145 if (tgt->ltd_exp == NULL)
2157 LASSERT(tgt && tgt->ltd_exp);
2158 OBD_ALLOC_PTR(oqctl);
2162 QCTL_COPY(oqctl, qctl);
2163 rc = obd_quotactl(tgt->ltd_exp, oqctl);
2165 QCTL_COPY(qctl, oqctl);
2166 qctl->qc_valid = QC_OSTIDX;
2167 qctl->obd_uuid = tgt->ltd_uuid;
2169 OBD_FREE_PTR(oqctl);
2178 for (i = 0; i < count; i++) {
2180 struct obd_device *osc_obd;
2182 /* OST was disconnected */
2183 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
2186 /* ll_umount_begin() sets force flag but for lov, not
2187 * osc. Let's pass it through */
2188 osc_obd = class_exp2obd(lov->lov_tgts[i]->ltd_exp);
2189 osc_obd->obd_force = obddev->obd_force;
2190 err = obd_iocontrol(cmd, lov->lov_tgts[i]->ltd_exp,
2192 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
2195 if (lov->lov_tgts[i]->ltd_active) {
2196 CDEBUG(err == -ENOTTY ?
2197 D_IOCTL : D_WARNING,
2198 "iocontrol OSC %s on OST "
2199 "idx %d cmd %x: err = %d\n",
2200 lov_uuid2str(lov, i),
2217 #define FIEMAP_BUFFER_SIZE 4096
2220 * Non-zero fe_logical indicates that this is a continuation FIEMAP
2221 * call. The local end offset and the device are sent in the first
2222 * fm_extent. This function calculates the stripe number from the index.
2223 * This function returns a stripe_no on which mapping is to be restarted.
2225 * This function returns fm_end_offset which is the in-OST offset at which
2226 * mapping should be restarted. If fm_end_offset=0 is returned then caller
2227 * will re-calculate proper offset in next stripe.
2228 * Note that the first extent is passed to lov_get_info via the value field.
2230 * \param fiemap fiemap request header
2231 * \param lsm striping information for the file
2232 * \param fm_start logical start of mapping
2233 * \param fm_end logical end of mapping
2234 * \param start_stripe starting stripe will be returned in this
2236 obd_size fiemap_calc_fm_end_offset(struct ll_user_fiemap *fiemap,
2237 struct lov_stripe_md *lsm, obd_size fm_start,
2238 obd_size fm_end, int *start_stripe)
2240 obd_size local_end = fiemap->fm_extents[0].fe_logical;
2241 obd_off lun_start, lun_end;
2242 obd_size fm_end_offset;
2243 int stripe_no = -1, i;
2245 if (fiemap->fm_extent_count == 0 ||
2246 fiemap->fm_extents[0].fe_logical == 0)
2249 /* Find out stripe_no from ost_index saved in the fe_device */
2250 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2251 if (lsm->lsm_oinfo[i]->loi_ost_idx ==
2252 fiemap->fm_extents[0].fe_device) {
2258 /* If we have finished mapping on previous device, shift logical
2259 * offset to start of next device */
2260 if ((lov_stripe_intersects(lsm, stripe_no, fm_start, fm_end,
2261 &lun_start, &lun_end)) != 0 &&
2262 local_end < lun_end) {
2263 fm_end_offset = local_end;
2264 *start_stripe = stripe_no;
2266 /* This is a special value to indicate that caller should
2267 * calculate offset in next stripe. */
2269 *start_stripe = (stripe_no + 1) % lsm->lsm_stripe_count;
2272 return fm_end_offset;
2276 * We calculate on which OST the mapping will end. If the length of mapping
2277 * is greater than (stripe_size * stripe_count) then the last_stripe will
2278 * will be one just before start_stripe. Else we check if the mapping
2279 * intersects each OST and find last_stripe.
2280 * This function returns the last_stripe and also sets the stripe_count
2281 * over which the mapping is spread
2283 * \param lsm striping information for the file
2284 * \param fm_start logical start of mapping
2285 * \param fm_end logical end of mapping
2286 * \param start_stripe starting stripe of the mapping
2287 * \param stripe_count the number of stripes across which to map is returned
2289 * \retval last_stripe return the last stripe of the mapping
2291 int fiemap_calc_last_stripe(struct lov_stripe_md *lsm, obd_size fm_start,
2292 obd_size fm_end, int start_stripe,
2296 obd_off obd_start, obd_end;
2299 if (fm_end - fm_start > lsm->lsm_stripe_size * lsm->lsm_stripe_count) {
2300 last_stripe = (start_stripe < 1 ? lsm->lsm_stripe_count - 1 :
2302 *stripe_count = lsm->lsm_stripe_count;
2304 for (j = 0, i = start_stripe; j < lsm->lsm_stripe_count;
2305 i = (i + 1) % lsm->lsm_stripe_count, j++) {
2306 if ((lov_stripe_intersects(lsm, i, fm_start, fm_end,
2307 &obd_start, &obd_end)) == 0)
2311 last_stripe = (start_stripe + j - 1) %lsm->lsm_stripe_count;
2318 * Set fe_device and copy extents from local buffer into main return buffer.
2320 * \param fiemap fiemap request header
2321 * \param lcl_fm_ext array of local fiemap extents to be copied
2322 * \param ost_index OST index to be written into the fm_device field for each
2324 * \param ext_count number of extents to be copied
2325 * \param current_extent where to start copying in main extent array
2327 void fiemap_prepare_and_copy_exts(struct ll_user_fiemap *fiemap,
2328 struct ll_fiemap_extent *lcl_fm_ext,
2329 int ost_index, unsigned int ext_count,
2335 for (ext = 0; ext < ext_count; ext++) {
2336 lcl_fm_ext[ext].fe_device = ost_index;
2337 lcl_fm_ext[ext].fe_flags |= FIEMAP_EXTENT_NET;
2340 /* Copy fm_extent's from fm_local to return buffer */
2341 to = (char *)fiemap + fiemap_count_to_size(current_extent);
2342 memcpy(to, lcl_fm_ext, ext_count * sizeof(struct ll_fiemap_extent));
2346 * Break down the FIEMAP request and send appropriate calls to individual OSTs.
2347 * This also handles the restarting of FIEMAP calls in case mapping overflows
2348 * the available number of extents in single call.
2350 static int lov_fiemap(struct lov_obd *lov, __u32 keylen, void *key,
2351 __u32 *vallen, void *val, struct lov_stripe_md *lsm)
2353 struct ll_fiemap_info_key *fm_key = key;
2354 struct ll_user_fiemap *fiemap = val;
2355 struct ll_user_fiemap *fm_local = NULL;
2356 struct ll_fiemap_extent *lcl_fm_ext;
2358 unsigned int get_num_extents = 0;
2359 int ost_index = 0, actual_start_stripe, start_stripe;
2360 obd_size fm_start, fm_end, fm_length, fm_end_offset = 0;
2362 int current_extent = 0, rc = 0, i;
2363 int ost_eof = 0; /* EOF for object */
2364 int ost_done = 0; /* done with required mapping for this OST? */
2366 int cur_stripe = 0, cur_stripe_wrap = 0, stripe_count;
2367 unsigned int buffer_size = FIEMAP_BUFFER_SIZE;
2372 if (fiemap_count_to_size(fm_key->fiemap.fm_extent_count) < buffer_size)
2373 buffer_size = fiemap_count_to_size(fm_key->fiemap.fm_extent_count);
2375 OBD_ALLOC_LARGE(fm_local, buffer_size);
2376 if (fm_local == NULL)
2377 GOTO(out, rc = -ENOMEM);
2378 lcl_fm_ext = &fm_local->fm_extents[0];
2380 count_local = fiemap_size_to_count(buffer_size);
2382 memcpy(fiemap, &fm_key->fiemap, sizeof(*fiemap));
2383 fm_start = fiemap->fm_start;
2384 fm_length = fiemap->fm_length;
2385 /* Calculate start stripe, last stripe and length of mapping */
2386 actual_start_stripe = start_stripe = lov_stripe_number(lsm, fm_start);
2387 fm_end = (fm_length == ~0ULL ? fm_key->oa.o_size :
2388 fm_start + fm_length - 1);
2389 /* If fm_length != ~0ULL but fm_start+fm_length-1 exceeds file size */
2390 if (fm_end > fm_key->oa.o_size)
2391 fm_end = fm_key->oa.o_size;
2393 last_stripe = fiemap_calc_last_stripe(lsm, fm_start, fm_end,
2394 actual_start_stripe, &stripe_count);
2396 fm_end_offset = fiemap_calc_fm_end_offset(fiemap, lsm, fm_start, fm_end,
2399 if (fiemap->fm_extent_count == 0) {
2400 get_num_extents = 1;
2404 /* Check each stripe */
2405 for (cur_stripe = start_stripe, i = 0; i < stripe_count;
2406 i++, cur_stripe = (cur_stripe + 1) % lsm->lsm_stripe_count) {
2407 obd_size req_fm_len; /* Stores length of required mapping */
2408 obd_size len_mapped_single_call;
2409 obd_off lun_start, lun_end, obd_object_end;
2410 unsigned int ext_count;
2412 cur_stripe_wrap = cur_stripe;
2414 /* Find out range of mapping on this stripe */
2415 if ((lov_stripe_intersects(lsm, cur_stripe, fm_start, fm_end,
2416 &lun_start, &obd_object_end)) == 0)
2419 /* If this is a continuation FIEMAP call and we are on
2420 * starting stripe then lun_start needs to be set to
2422 if (fm_end_offset != 0 && cur_stripe == start_stripe)
2423 lun_start = fm_end_offset;
2425 if (fm_length != ~0ULL) {
2426 /* Handle fm_start + fm_length overflow */
2427 if (fm_start + fm_length < fm_start)
2428 fm_length = ~0ULL - fm_start;
2429 lun_end = lov_size_to_stripe(lsm, fm_start + fm_length,
2435 if (lun_start == lun_end)
2438 req_fm_len = obd_object_end - lun_start;
2439 fm_local->fm_length = 0;
2440 len_mapped_single_call = 0;
2442 /* If the output buffer is very large and the objects have many
2443 * extents we may need to loop on a single OST repeatedly */
2447 if (get_num_extents == 0) {
2448 /* Don't get too many extents. */
2449 if (current_extent + count_local >
2450 fiemap->fm_extent_count)
2451 count_local = fiemap->fm_extent_count -
2455 lun_start += len_mapped_single_call;
2456 fm_local->fm_length = req_fm_len - len_mapped_single_call;
2457 req_fm_len = fm_local->fm_length;
2458 fm_local->fm_extent_count = count_local;
2459 fm_local->fm_mapped_extents = 0;
2460 fm_local->fm_flags = fiemap->fm_flags;
2462 fm_key->oa.o_id = lsm->lsm_oinfo[cur_stripe]->loi_id;
2463 fm_key->oa.o_seq = lsm->lsm_oinfo[cur_stripe]->loi_seq;
2464 ost_index = lsm->lsm_oinfo[cur_stripe]->loi_ost_idx;
2466 if (ost_index < 0 || ost_index >=lov->desc.ld_tgt_count)
2467 GOTO(out, rc = -EINVAL);
2469 /* If OST is inactive, return extent with UNKNOWN flag */
2470 if (!lov->lov_tgts[ost_index]->ltd_active) {
2471 fm_local->fm_flags |= FIEMAP_EXTENT_LAST;
2472 fm_local->fm_mapped_extents = 1;
2474 lcl_fm_ext[0].fe_logical = lun_start;
2475 lcl_fm_ext[0].fe_length = obd_object_end -
2477 lcl_fm_ext[0].fe_flags |= FIEMAP_EXTENT_UNKNOWN;
2482 fm_local->fm_start = lun_start;
2483 fm_local->fm_flags &= ~FIEMAP_FLAG_DEVICE_ORDER;
2484 memcpy(&fm_key->fiemap, fm_local, sizeof(*fm_local));
2485 *vallen=fiemap_count_to_size(fm_local->fm_extent_count);
2486 rc = obd_get_info(lov->lov_tgts[ost_index]->ltd_exp,
2487 keylen, key, vallen, fm_local, lsm);
2492 ext_count = fm_local->fm_mapped_extents;
2493 if (ext_count == 0) {
2495 /* If last stripe has hole at the end,
2496 * then we need to return */
2497 if (cur_stripe_wrap == last_stripe) {
2498 fiemap->fm_mapped_extents = 0;
2504 /* If we just need num of extents then go to next device */
2505 if (get_num_extents) {
2506 current_extent += ext_count;
2510 len_mapped_single_call = lcl_fm_ext[ext_count-1].fe_logical -
2511 lun_start + lcl_fm_ext[ext_count - 1].fe_length;
2513 /* Have we finished mapping on this device? */
2514 if (req_fm_len <= len_mapped_single_call)
2517 /* Clear the EXTENT_LAST flag which can be present on
2519 if (lcl_fm_ext[ext_count-1].fe_flags & FIEMAP_EXTENT_LAST)
2520 lcl_fm_ext[ext_count - 1].fe_flags &=
2521 ~FIEMAP_EXTENT_LAST;
2523 curr_loc = lov_stripe_size(lsm,
2524 lcl_fm_ext[ext_count - 1].fe_logical+
2525 lcl_fm_ext[ext_count - 1].fe_length,
2527 if (curr_loc >= fm_key->oa.o_size)
2530 fiemap_prepare_and_copy_exts(fiemap, lcl_fm_ext,
2531 ost_index, ext_count,
2534 current_extent += ext_count;
2536 /* Ran out of available extents? */
2537 if (current_extent >= fiemap->fm_extent_count)
2539 } while (ost_done == 0 && ost_eof == 0);
2541 if (cur_stripe_wrap == last_stripe)
2546 /* Indicate that we are returning device offsets unless file just has
2548 if (lsm->lsm_stripe_count > 1)
2549 fiemap->fm_flags |= FIEMAP_FLAG_DEVICE_ORDER;
2551 if (get_num_extents)
2552 goto skip_last_device_calc;
2554 /* Check if we have reached the last stripe and whether mapping for that
2555 * stripe is done. */
2556 if (cur_stripe_wrap == last_stripe) {
2557 if (ost_done || ost_eof)
2558 fiemap->fm_extents[current_extent - 1].fe_flags |=
2562 skip_last_device_calc:
2563 fiemap->fm_mapped_extents = current_extent;
2566 OBD_FREE_LARGE(fm_local, buffer_size);
2570 static int lov_get_info(struct obd_export *exp, __u32 keylen,
2571 void *key, __u32 *vallen, void *val,
2572 struct lov_stripe_md *lsm)
2574 struct obd_device *obddev = class_exp2obd(exp);
2575 struct lov_obd *lov = &obddev->u.lov;
2579 if (!vallen || !val)
2584 if (KEY_IS(KEY_LOCK_TO_STRIPE)) {
2587 struct ldlm_lock *lock;
2589 struct ldlm_res_id *res_id = &data->lock->l_resource->lr_name;
2590 struct lov_oinfo *loi;
2591 __u32 *stripe = val;
2593 if (*vallen < sizeof(*stripe))
2594 GOTO(out, rc = -EFAULT);
2595 *vallen = sizeof(*stripe);
2597 /* XXX This is another one of those bits that will need to
2598 * change if we ever actually support nested LOVs. It uses
2599 * the lock's export to find out which stripe it is. */
2600 /* XXX - it's assumed all the locks for deleted OSTs have
2601 * been cancelled. Also, the export for deleted OSTs will
2602 * be NULL and won't match the lock's export. */
2603 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2604 loi = lsm->lsm_oinfo[i];
2605 if (!lov->lov_tgts[loi->loi_ost_idx])
2607 if (lov->lov_tgts[loi->loi_ost_idx]->ltd_exp ==
2608 data->lock->l_conn_export &&
2609 osc_res_name_eq(loi->loi_id, loi->loi_seq, res_id)) {
2614 LDLM_ERROR(data->lock, "lock on inode without such object");
2615 dump_lsm(D_ERROR, lsm);
2616 GOTO(out, rc = -ENXIO);
2617 } else if (KEY_IS(KEY_LAST_ID)) {
2618 struct obd_id_info *info = val;
2619 __u32 size = sizeof(obd_id);
2620 struct lov_tgt_desc *tgt;
2622 LASSERT(*vallen == sizeof(struct obd_id_info));
2623 tgt = lov->lov_tgts[info->idx];
2625 if (!tgt || !tgt->ltd_active)
2626 GOTO(out, rc = -ESRCH);
2628 rc = obd_get_info(tgt->ltd_exp, keylen, key, &size, info->data, NULL);
2630 } else if (KEY_IS(KEY_LOVDESC)) {
2631 struct lov_desc *desc_ret = val;
2632 *desc_ret = lov->desc;
2635 } else if (KEY_IS(KEY_FIEMAP)) {
2636 rc = lov_fiemap(lov, keylen, key, vallen, val, lsm);
2638 } else if (KEY_IS(KEY_CONNECT_FLAG)) {
2639 struct lov_tgt_desc *tgt;
2640 __u64 ost_idx = *((__u64*)val);
2642 LASSERT(*vallen == sizeof(__u64));
2643 LASSERT(ost_idx < lov->desc.ld_tgt_count);
2644 tgt = lov->lov_tgts[ost_idx];
2646 if (!tgt || !tgt->ltd_exp)
2647 GOTO(out, rc = -ESRCH);
2649 *((__u64*)val) = tgt->ltd_exp->exp_connect_flags;
2651 } else if (KEY_IS(KEY_TGT_COUNT)) {
2652 *((int *)val) = lov->desc.ld_tgt_count;
2663 static int lov_set_info_async(struct obd_export *exp, obd_count keylen,
2664 void *key, obd_count vallen, void *val,
2665 struct ptlrpc_request_set *set)
2667 struct obd_device *obddev = class_exp2obd(exp);
2668 struct lov_obd *lov = &obddev->u.lov;
2671 struct lov_tgt_desc *tgt;
2672 unsigned incr, check_uuid,
2673 do_inactive, no_set;
2674 unsigned next_id = 0, mds_con = 0, capa = 0;
2677 incr = check_uuid = do_inactive = no_set = 0;
2680 set = ptlrpc_prep_set();
2686 count = lov->desc.ld_tgt_count;
2688 if (KEY_IS(KEY_NEXT_ID)) {
2689 count = vallen / sizeof(struct obd_id_info);
2690 vallen = sizeof(obd_id);
2691 incr = sizeof(struct obd_id_info);
2694 } else if (KEY_IS(KEY_CHECKSUM)) {
2696 } else if (KEY_IS(KEY_EVICT_BY_NID)) {
2697 /* use defaults: do_inactive = incr = 0; */
2698 } else if (KEY_IS(KEY_MDS_CONN)) {
2700 } else if (KEY_IS(KEY_CAPA_KEY)) {
2704 for (i = 0; i < count; i++, val = (char *)val + incr) {
2706 tgt = lov->lov_tgts[((struct obd_id_info*)val)->idx];
2708 tgt = lov->lov_tgts[i];
2710 /* OST was disconnected */
2711 if (!tgt || !tgt->ltd_exp)
2714 /* OST is inactive and we don't want inactive OSCs */
2715 if (!tgt->ltd_active && !do_inactive)
2719 struct mds_group_info *mgi;
2721 LASSERT(vallen == sizeof(*mgi));
2722 mgi = (struct mds_group_info *)val;
2724 /* Only want a specific OSC */
2725 if (mgi->uuid && !obd_uuid_equals(mgi->uuid,
2729 err = obd_set_info_async(tgt->ltd_exp,
2730 keylen, key, sizeof(int),
2732 } else if (next_id) {
2733 err = obd_set_info_async(tgt->ltd_exp,
2734 keylen, key, vallen,
2735 ((struct obd_id_info*)val)->data, set);
2737 struct mds_capa_info *info = (struct mds_capa_info*)val;
2739 LASSERT(vallen == sizeof(*info));
2741 /* Only want a specific OSC */
2743 !obd_uuid_equals(info->uuid, &tgt->ltd_uuid))
2746 err = obd_set_info_async(tgt->ltd_exp, keylen, key,
2747 sizeof(*info->capa),
2750 /* Only want a specific OSC */
2752 !obd_uuid_equals(val, &tgt->ltd_uuid))
2755 err = obd_set_info_async(tgt->ltd_exp,
2756 keylen, key, vallen, val, set);
2765 err = ptlrpc_set_wait(set);
2768 ptlrpc_set_destroy(set);
2773 int lov_test_and_clear_async_rc(struct lov_stripe_md *lsm)
2778 for (i = 0; i < lsm->lsm_stripe_count; i++) {
2779 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
2780 if (loi->loi_ar.ar_rc && !rc)
2781 rc = loi->loi_ar.ar_rc;
2782 loi->loi_ar.ar_rc = 0;
2786 EXPORT_SYMBOL(lov_test_and_clear_async_rc);
2789 static int lov_extent_calc(struct obd_export *exp, struct lov_stripe_md *lsm,
2790 int cmd, __u64 *offset)
2792 __u32 ssize = lsm->lsm_stripe_size;
2796 do_div(start, ssize);
2797 start = start * ssize;
2799 CDEBUG(D_DLMTRACE, "offset "LPU64", stripe %u, start "LPU64
2800 ", end "LPU64"\n", *offset, ssize, start,
2802 if (cmd == OBD_CALC_STRIPE_END) {
2803 *offset = start + ssize - 1;
2804 } else if (cmd == OBD_CALC_STRIPE_START) {
2813 void lov_stripe_lock(struct lov_stripe_md *md)
2815 LASSERT(md->lsm_lock_owner != cfs_curproc_pid());
2816 cfs_spin_lock(&md->lsm_lock);
2817 LASSERT(md->lsm_lock_owner == 0);
2818 md->lsm_lock_owner = cfs_curproc_pid();
2820 EXPORT_SYMBOL(lov_stripe_lock);
2822 void lov_stripe_unlock(struct lov_stripe_md *md)
2824 LASSERT(md->lsm_lock_owner == cfs_curproc_pid());
2825 md->lsm_lock_owner = 0;
2826 cfs_spin_unlock(&md->lsm_lock);
2828 EXPORT_SYMBOL(lov_stripe_unlock);
2830 static int lov_quotactl(struct obd_device *obd, struct obd_export *exp,
2831 struct obd_quotactl *oqctl)
2833 struct lov_obd *lov = &obd->u.lov;
2834 struct lov_tgt_desc *tgt;
2836 __u64 bhardlimit = 0;
2840 if (oqctl->qc_cmd != LUSTRE_Q_QUOTAON &&
2841 oqctl->qc_cmd != LUSTRE_Q_QUOTAOFF &&
2842 oqctl->qc_cmd != Q_GETOQUOTA &&
2843 oqctl->qc_cmd != Q_INITQUOTA &&
2844 oqctl->qc_cmd != LUSTRE_Q_SETQUOTA &&
2845 oqctl->qc_cmd != Q_FINVALIDATE) {
2846 CERROR("bad quota opc %x for lov obd", oqctl->qc_cmd);
2852 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2855 tgt = lov->lov_tgts[i];
2860 if (!tgt->ltd_active || tgt->ltd_reap) {
2861 if (oqctl->qc_cmd == Q_GETOQUOTA &&
2862 lov->lov_tgts[i]->ltd_activate) {
2864 CERROR("ost %d is inactive\n", i);
2866 CDEBUG(D_HA, "ost %d is inactive\n", i);
2871 err = obd_quotactl(tgt->ltd_exp, oqctl);
2873 if (tgt->ltd_active && !rc)
2878 if (oqctl->qc_cmd == Q_GETOQUOTA) {
2879 curspace += oqctl->qc_dqblk.dqb_curspace;
2880 bhardlimit += oqctl->qc_dqblk.dqb_bhardlimit;
2885 if (oqctl->qc_cmd == Q_GETOQUOTA) {
2886 oqctl->qc_dqblk.dqb_curspace = curspace;
2887 oqctl->qc_dqblk.dqb_bhardlimit = bhardlimit;
2892 static int lov_quotacheck(struct obd_device *obd, struct obd_export *exp,
2893 struct obd_quotactl *oqctl)
2895 struct lov_obd *lov = &obd->u.lov;
2901 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2902 if (!lov->lov_tgts[i])
2905 /* Skip quota check on the administratively disabled OSTs. */
2906 if (!lov->lov_tgts[i]->ltd_activate) {
2907 CWARN("lov idx %d was administratively disabled, "
2908 "skip quotacheck on it.\n", i);
2912 if (!lov->lov_tgts[i]->ltd_active) {
2913 CERROR("lov idx %d inactive\n", i);
2919 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2922 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_activate)
2925 err = obd_quotacheck(lov->lov_tgts[i]->ltd_exp, oqctl);
2936 int lov_quota_adjust_qunit(struct obd_export *exp,
2937 struct quota_adjust_qunit *oqaq,
2938 struct lustre_quota_ctxt *qctxt,
2939 struct ptlrpc_request_set *rqset)
2941 struct obd_device *obd = class_exp2obd(exp);
2942 struct lov_obd *lov = &obd->u.lov;
2944 unsigned no_set = 0;
2947 if (!QAQ_IS_ADJBLK(oqaq)) {
2948 CERROR("bad qaq_flags %x for lov obd.\n", oqaq->qaq_flags);
2952 if (rqset == NULL) {
2953 rqset = ptlrpc_prep_set();
2960 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
2962 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active) {
2963 CDEBUG(D_HA, "ost %d is inactive\n", i);
2967 err = obd_quota_adjust_qunit(lov->lov_tgts[i]->ltd_exp, oqaq,
2970 if (lov->lov_tgts[i]->ltd_active && !rc)
2976 err = ptlrpc_set_wait(rqset);
2980 /* Destroy the set if none was provided by the caller */
2982 ptlrpc_set_destroy(rqset);
2988 struct obd_ops lov_obd_ops = {
2989 .o_owner = THIS_MODULE,
2990 .o_setup = lov_setup,
2991 .o_precleanup = lov_precleanup,
2992 .o_cleanup = lov_cleanup,
2993 //.o_process_config = lov_process_config,
2994 .o_connect = lov_connect,
2995 .o_disconnect = lov_disconnect,
2996 .o_statfs = lov_statfs,
2997 .o_statfs_async = lov_statfs_async,
2998 .o_packmd = lov_packmd,
2999 .o_unpackmd = lov_unpackmd,
3000 .o_create = lov_create,
3001 .o_destroy = lov_destroy,
3002 .o_getattr = lov_getattr,
3003 .o_getattr_async = lov_getattr_async,
3004 .o_setattr = lov_setattr,
3005 .o_setattr_async = lov_setattr_async,
3007 .o_merge_lvb = lov_merge_lvb,
3008 .o_adjust_kms = lov_adjust_kms,
3009 .o_punch = lov_punch,
3011 .o_enqueue = lov_enqueue,
3012 .o_change_cbdata = lov_change_cbdata,
3013 .o_find_cbdata = lov_find_cbdata,
3014 .o_cancel = lov_cancel,
3015 .o_cancel_unused = lov_cancel_unused,
3016 .o_iocontrol = lov_iocontrol,
3017 .o_get_info = lov_get_info,
3018 .o_set_info_async = lov_set_info_async,
3019 .o_extent_calc = lov_extent_calc,
3020 .o_llog_init = lov_llog_init,
3021 .o_llog_finish = lov_llog_finish,
3022 .o_notify = lov_notify,
3023 .o_pool_new = lov_pool_new,
3024 .o_pool_rem = lov_pool_remove,
3025 .o_pool_add = lov_pool_add,
3026 .o_pool_del = lov_pool_del,
3027 .o_getref = lov_getref,
3028 .o_putref = lov_putref,
3029 .o_quotactl = lov_quotactl,
3030 .o_quotacheck = lov_quotacheck,
3031 .o_quota_adjust_qunit = lov_quota_adjust_qunit,
3034 static quota_interface_t *quota_interface;
3035 extern quota_interface_t lov_quota_interface;
3037 cfs_mem_cache_t *lov_oinfo_slab;
3039 extern struct lu_kmem_descr lov_caches[];
3041 int __init lov_init(void)
3043 struct lprocfs_static_vars lvars = { 0 };
3047 /* print an address of _any_ initialized kernel symbol from this
3048 * module, to allow debugging with gdb that doesn't support data
3049 * symbols from modules.*/
3050 CDEBUG(D_CONSOLE, "Lustre LOV module (%p).\n", &lov_caches);
3052 rc = lu_kmem_init(lov_caches);
3056 lov_oinfo_slab = cfs_mem_cache_create("lov_oinfo",
3057 sizeof(struct lov_oinfo),
3058 0, CFS_SLAB_HWCACHE_ALIGN);
3059 if (lov_oinfo_slab == NULL) {
3060 lu_kmem_fini(lov_caches);
3063 lprocfs_lov_init_vars(&lvars);
3065 cfs_request_module("lquota");
3066 quota_interface = PORTAL_SYMBOL_GET(lov_quota_interface);
3067 init_obd_quota_ops(quota_interface, &lov_obd_ops);
3069 rc = class_register_type(&lov_obd_ops, NULL, lvars.module_vars,
3070 LUSTRE_LOV_NAME, &lov_device_type);
3073 if (quota_interface)
3074 PORTAL_SYMBOL_PUT(lov_quota_interface);
3075 rc2 = cfs_mem_cache_destroy(lov_oinfo_slab);
3077 lu_kmem_fini(lov_caches);
3084 static void /*__exit*/ lov_exit(void)
3088 lu_device_type_fini(&lov_device_type);
3089 lu_kmem_fini(lov_caches);
3091 if (quota_interface)
3092 PORTAL_SYMBOL_PUT(lov_quota_interface);
3094 class_unregister_type(LUSTRE_LOV_NAME);
3095 rc = cfs_mem_cache_destroy(lov_oinfo_slab);
3099 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
3100 MODULE_DESCRIPTION("Lustre Logical Object Volume OBD driver");
3101 MODULE_LICENSE("GPL");
3103 cfs_module(lov, LUSTRE_VERSION_STRING, lov_init, lov_exit);