4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/lov/lov_obd.c
34 * Author: Phil Schwan <phil@clusterfs.com>
35 * Author: Peter Braam <braam@clusterfs.com>
36 * Author: Mike Shaver <shaver@clusterfs.com>
37 * Author: Nathan Rutman <nathan@clusterfs.com>
40 #define DEBUG_SUBSYSTEM S_LOV
41 #include <libcfs/libcfs.h>
43 #include <cl_object.h>
44 #include <lustre_dlm.h>
45 #include <lustre_fid.h>
46 #include <uapi/linux/lustre/lustre_ioctl.h>
47 #include <lustre_lib.h>
48 #include <lustre_mds.h>
49 #include <lustre_net.h>
50 #include <uapi/linux/lustre/lustre_param.h>
51 #include <lustre_swab.h>
52 #include <lprocfs_status.h>
53 #include <obd_class.h>
54 #include <obd_support.h>
56 #include "lov_internal.h"
58 /* Keep a refcount of lov->tgt usage to prevent racing with addition/deletion.
59 Any function that expects lov_tgts to remain stationary must take a ref. */
60 void lov_tgts_getref(struct obd_device *obd)
62 struct lov_obd *lov = &obd->u.lov;
64 /* nobody gets through here until lov_putref is done */
65 mutex_lock(&lov->lov_lock);
66 atomic_inc(&lov->lov_refcount);
67 mutex_unlock(&lov->lov_lock);
70 static void __lov_del_obd(struct obd_device *obd, struct lov_tgt_desc *tgt);
72 void lov_tgts_putref(struct obd_device *obd)
74 struct lov_obd *lov = &obd->u.lov;
76 mutex_lock(&lov->lov_lock);
77 /* ok to dec to 0 more than once -- ltd_exp's will be null */
78 if (atomic_dec_and_test(&lov->lov_refcount) && lov->lov_death_row) {
80 struct lov_tgt_desc *tgt, *n;
83 CDEBUG(D_CONFIG, "destroying %d lov targets\n",
85 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
86 tgt = lov->lov_tgts[i];
88 if (!tgt || !tgt->ltd_reap)
90 list_add(&tgt->ltd_kill, &kill);
91 /* XXX - right now there is a dependency on ld_tgt_count
92 * being the maximum tgt index for computing the
93 * mds_max_easize. So we can't shrink it. */
94 lov_ost_pool_remove(&lov->lov_packed, i);
95 lov->lov_tgts[i] = NULL;
98 mutex_unlock(&lov->lov_lock);
100 list_for_each_entry_safe(tgt, n, &kill, ltd_kill) {
101 list_del(&tgt->ltd_kill);
103 __lov_del_obd(obd, tgt);
106 mutex_unlock(&lov->lov_lock);
110 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
111 enum obd_notify_event ev);
113 int lov_connect_osc(struct obd_device *obd, u32 index, int activate,
114 struct obd_connect_data *data)
116 struct lov_obd *lov = &obd->u.lov;
117 struct obd_uuid *tgt_uuid;
118 struct obd_device *tgt_obd;
119 static struct obd_uuid lov_osc_uuid = { "LOV_OSC_UUID" };
120 struct obd_import *imp;
124 if (lov->lov_tgts[index] == NULL)
127 tgt_uuid = &lov->lov_tgts[index]->ltd_uuid;
128 tgt_obd = lov->lov_tgts[index]->ltd_obd;
130 if (!tgt_obd->obd_set_up) {
131 CERROR("Target %s not set up\n", obd_uuid2str(tgt_uuid));
135 /* override the sp_me from lov */
136 tgt_obd->u.cli.cl_sp_me = lov->lov_sp_me;
138 if (data && (data->ocd_connect_flags & OBD_CONNECT_INDEX))
139 data->ocd_index = index;
142 * Divine LOV knows that OBDs under it are OSCs.
144 imp = tgt_obd->u.cli.cl_import;
147 tgt_obd->obd_no_recov = 0;
148 /* FIXME this is probably supposed to be
149 ptlrpc_set_import_active. Horrible naming. */
150 ptlrpc_activate_import(imp, false);
153 rc = obd_register_observer(tgt_obd, obd);
155 CERROR("Target %s register_observer error %d\n",
156 obd_uuid2str(tgt_uuid), rc);
160 if (imp->imp_invalid) {
161 CDEBUG(D_CONFIG, "%s: not connecting - administratively disabled\n",
162 obd_uuid2str(tgt_uuid));
166 rc = obd_connect(NULL, &lov->lov_tgts[index]->ltd_exp, tgt_obd,
167 &lov_osc_uuid, data, lov->lov_cache);
168 if (rc || !lov->lov_tgts[index]->ltd_exp) {
169 CERROR("Target %s connect error %d\n",
170 obd_uuid2str(tgt_uuid), rc);
174 lov->lov_tgts[index]->ltd_reap = 0;
176 CDEBUG(D_CONFIG, "Connected tgt idx %d %s (%s) %sactive\n", index,
177 obd_uuid2str(tgt_uuid), tgt_obd->obd_name, activate ? "":"in");
179 if (lov->lov_tgts_kobj) {
180 /* Even if we failed, that's ok */
181 rc = sysfs_create_link(lov->lov_tgts_kobj,
182 &tgt_obd->obd_kset.kobj,
185 CERROR("%s: can't register LOV target /sys/fs/lustre/%s/%s/target_obds/%s : rc = %d\n",
186 obd->obd_name, obd->obd_type->typ_name,
188 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_name,
195 static int lov_connect(const struct lu_env *env,
196 struct obd_export **exp, struct obd_device *obd,
197 struct obd_uuid *cluuid, struct obd_connect_data *data,
200 struct lov_obd *lov = &obd->u.lov;
201 struct lov_tgt_desc *tgt;
202 struct lustre_handle conn;
206 CDEBUG(D_CONFIG, "connect #%d\n", lov->lov_connects);
208 rc = class_connect(&conn, obd, cluuid);
212 *exp = class_conn2export(&conn);
214 /* Why should there ever be more than 1 connect? */
216 LASSERT(lov->lov_connects == 1);
218 memset(&lov->lov_ocd, 0, sizeof(lov->lov_ocd));
220 lov->lov_ocd = *data;
222 lov_tgts_getref(obd);
225 lov->lov_cache = localdata;
226 cl_cache_incref(lov->lov_cache);
229 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
230 tgt = lov->lov_tgts[i];
231 if (!tgt || obd_uuid_empty(&tgt->ltd_uuid))
233 /* Flags will be lowest common denominator */
234 rc = lov_connect_osc(obd, i, tgt->ltd_activate, &lov->lov_ocd);
236 CERROR("%s: lov connect tgt %d failed: %d\n",
237 obd->obd_name, i, rc);
240 /* connect to administrative disabled ost */
241 if (!lov->lov_tgts[i]->ltd_exp)
244 rc = lov_notify(obd, lov->lov_tgts[i]->ltd_exp->exp_obd,
247 CERROR("%s error sending notify %d\n",
252 lov_tgts_putref(obd);
257 static int lov_disconnect_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
259 struct lov_obd *lov = &obd->u.lov;
260 struct obd_device *osc_obd;
264 osc_obd = class_exp2obd(tgt->ltd_exp);
265 CDEBUG(D_CONFIG, "%s: disconnecting target %s\n", obd->obd_name,
266 osc_obd ? osc_obd->obd_name : "<no obd>");
268 if (tgt->ltd_active) {
270 lov->desc.ld_active_tgt_count--;
271 tgt->ltd_exp->exp_obd->obd_inactive = 1;
275 if (lov->lov_tgts_kobj)
276 sysfs_remove_link(lov->lov_tgts_kobj,
279 /* Pass it on to our clients.
280 * XXX This should be an argument to disconnect,
281 * XXX not a back-door flag on the OBD. Ah well.
283 osc_obd->obd_force = obd->obd_force;
284 osc_obd->obd_fail = obd->obd_fail;
285 osc_obd->obd_no_recov = obd->obd_no_recov;
287 if (lov->targets_proc_entry != NULL)
288 lprocfs_remove_proc_entry(osc_obd->obd_name,
289 lov->targets_proc_entry);
292 obd_register_observer(osc_obd, NULL);
294 rc = obd_disconnect(tgt->ltd_exp);
296 CERROR("Target %s disconnect error %d\n",
297 tgt->ltd_uuid.uuid, rc);
305 static int lov_disconnect(struct obd_export *exp)
307 struct obd_device *obd = class_exp2obd(exp);
308 struct lov_obd *lov = &obd->u.lov;
316 /* Only disconnect the underlying layers on the final disconnect. */
318 if (lov->lov_connects != 0) {
319 /* why should there be more than 1 connect? */
320 CWARN("%s: unexpected disconnect #%d\n",
321 obd->obd_name, lov->lov_connects);
325 /* hold another ref so lov_del_obd() doesn't spin in putref each time */
326 lov_tgts_getref(obd);
328 for (index = 0; index < lov->desc.ld_tgt_count; index++) {
329 if (lov->lov_tgts[index] && lov->lov_tgts[index]->ltd_exp) {
330 /* Disconnection is the last we know about an OBD */
331 lov_del_target(obd, index, NULL,
332 lov->lov_tgts[index]->ltd_gen);
335 lov_tgts_putref(obd);
338 rc = class_disconnect(exp); /* bz 9811 */
344 * -EINVAL : UUID can't be found in the LOV's target list
345 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
346 * -EBADF : The UUID is found, but the OBD is the wrong type (!)
347 * any >= 0 : is log target index
349 static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
350 enum obd_notify_event ev)
352 struct lov_obd *lov = &obd->u.lov;
353 struct lov_tgt_desc *tgt;
355 bool activate, active;
358 CDEBUG(D_INFO, "Searching in lov %p for uuid %s event(%d)\n",
359 lov, uuid->uuid, ev);
361 lov_tgts_getref(obd);
362 for (index = 0; index < lov->desc.ld_tgt_count; index++) {
363 tgt = lov->lov_tgts[index];
364 if (tgt && obd_uuid_equals(uuid, &tgt->ltd_uuid))
368 if (index == lov->desc.ld_tgt_count)
369 GOTO(out, index = -EINVAL);
371 if (ev == OBD_NOTIFY_DEACTIVATE || ev == OBD_NOTIFY_ACTIVATE) {
372 activate = (ev == OBD_NOTIFY_ACTIVATE);
375 * LU-642, initially inactive OSC could miss the obd_connect,
376 * we make up for it here.
378 if (activate && !tgt->ltd_exp) {
380 struct obd_uuid lov_osc_uuid = {"LOV_OSC_UUID"};
382 rc = obd_connect(NULL, &tgt->ltd_exp, tgt->ltd_obd,
383 &lov_osc_uuid, &lov->lov_ocd,
385 if (rc || !tgt->ltd_exp)
386 GOTO(out, index = rc);
389 if (lov->lov_tgts[index]->ltd_activate == activate) {
390 CDEBUG(D_INFO, "OSC %s already %sactivate!\n",
391 uuid->uuid, activate ? "" : "de");
393 lov->lov_tgts[index]->ltd_activate = activate;
394 CDEBUG(D_CONFIG, "%sactivate OSC %s\n",
395 activate ? "" : "de", obd_uuid2str(uuid));
397 } else if (ev == OBD_NOTIFY_INACTIVE || ev == OBD_NOTIFY_ACTIVE) {
398 active = (ev == OBD_NOTIFY_ACTIVE);
400 if (lov->lov_tgts[index]->ltd_active == active) {
401 CDEBUG(D_INFO, "OSC %s already %sactive!\n",
402 uuid->uuid, active ? "" : "in");
405 CDEBUG(D_CONFIG, "Marking OSC %s %sactive\n",
406 obd_uuid2str(uuid), active ? "" : "in");
408 lov->lov_tgts[index]->ltd_active = active;
410 lov->desc.ld_active_tgt_count++;
411 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 0;
413 lov->desc.ld_active_tgt_count--;
414 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 1;
417 CERROR("%s: unknown event %d for uuid %s\n", obd->obd_name,
422 CDEBUG(D_INFO, "%s: lov idx %d conn %llx\n", obd_uuid2str(uuid),
423 index, tgt->ltd_exp->exp_handle.h_cookie);
426 lov_tgts_putref(obd);
430 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
431 enum obd_notify_event ev)
434 struct lov_obd *lov = &obd->u.lov;
437 down_read(&lov->lov_notify_lock);
438 if (!lov->lov_connects)
439 GOTO(out_notify_lock, rc = 0);
441 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE ||
442 ev == OBD_NOTIFY_ACTIVATE || ev == OBD_NOTIFY_DEACTIVATE) {
443 struct obd_uuid *uuid;
447 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
448 CERROR("unexpected notification of %s %s\n",
449 watched->obd_type->typ_name, watched->obd_name);
450 GOTO(out_notify_lock, rc = -EINVAL);
453 uuid = &watched->u.cli.cl_target_uuid;
455 /* Set OSC as active before notifying the observer, so the
456 * observer can use the OSC normally.
458 rc = lov_set_osc_active(obd, uuid, ev);
460 CERROR("%s: event %d failed: rc = %d\n", obd->obd_name,
462 GOTO(out_notify_lock, rc);
466 /* Pass the notification up the chain. */
467 rc = obd_notify_observer(obd, watched, ev);
470 up_read(&lov->lov_notify_lock);
475 static int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
476 u32 index, int gen, int active)
478 struct lov_obd *lov = &obd->u.lov;
479 struct lov_tgt_desc *tgt;
480 struct obd_device *tgt_obd;
484 CDEBUG(D_CONFIG, "uuid:%s idx:%u gen:%d active:%d\n",
485 uuidp->uuid, index, gen, active);
488 CERROR("%s: request to add '%s' with invalid generation: %d\n",
489 obd->obd_name, uuidp->uuid, gen);
493 tgt_obd = class_find_client_obd(uuidp, LUSTRE_OSC_NAME, &obd->obd_uuid);
497 mutex_lock(&lov->lov_lock);
499 if ((index < lov->lov_tgt_size) && (lov->lov_tgts[index] != NULL)) {
500 tgt = lov->lov_tgts[index];
502 CERROR("%s: UUID %s already assigned at index %d: rc = %d\n",
503 obd->obd_name, obd_uuid2str(&tgt->ltd_uuid), index, rc);
504 mutex_unlock(&lov->lov_lock);
508 if (index >= lov->lov_tgt_size) {
509 /* We need to reallocate the lov target array. */
510 struct lov_tgt_desc **newtgts, **old = NULL;
511 __u32 newsize, oldsize = 0;
513 newsize = max(lov->lov_tgt_size, 2U);
514 while (newsize < index + 1)
515 newsize = newsize << 1;
516 OBD_ALLOC_PTR_ARRAY(newtgts, newsize);
517 if (newtgts == NULL) {
518 mutex_unlock(&lov->lov_lock);
522 if (lov->lov_tgt_size) {
523 memcpy(newtgts, lov->lov_tgts, sizeof(*newtgts) *
526 oldsize = lov->lov_tgt_size;
529 lov->lov_tgts = newtgts;
530 lov->lov_tgt_size = newsize;
533 OBD_FREE_PTR_ARRAY(old, oldsize);
535 CDEBUG(D_CONFIG, "tgts: %p size: %d\n",
536 lov->lov_tgts, lov->lov_tgt_size);
541 mutex_unlock(&lov->lov_lock);
545 rc = lov_ost_pool_add(&lov->lov_packed, index, lov->lov_tgt_size);
547 mutex_unlock(&lov->lov_lock);
552 tgt->ltd_uuid = *uuidp;
553 tgt->ltd_obd = tgt_obd;
554 /* XXX - add a sanity check on the generation number. */
556 tgt->ltd_index = index;
557 tgt->ltd_activate = active;
558 lov->lov_tgts[index] = tgt;
559 if (index >= lov->desc.ld_tgt_count)
560 lov->desc.ld_tgt_count = index + 1;
562 mutex_unlock(&lov->lov_lock);
564 CDEBUG(D_CONFIG, "idx=%d ltd_gen=%d ld_tgt_count=%d\n",
565 index, tgt->ltd_gen, lov->desc.ld_tgt_count);
567 if (lov->lov_connects == 0) {
568 /* lov_connect hasn't been called yet. We'll do the
569 lov_connect_osc on this target when that fn first runs,
570 because we don't know the connect flags yet. */
574 lov_tgts_getref(obd);
576 rc = lov_connect_osc(obd, index, active, &lov->lov_ocd);
580 /* connect to administrative disabled ost */
584 rc = lov_notify(obd, tgt->ltd_exp->exp_obd,
585 active ? OBD_NOTIFY_CONNECT : OBD_NOTIFY_INACTIVE);
589 CERROR("%s: add failed, deleting %s: rc = %d\n",
590 obd->obd_name, obd_uuid2str(&tgt->ltd_uuid), rc);
591 lov_del_target(obd, index, NULL, 0);
593 lov_tgts_putref(obd);
597 /* Schedule a target for deletion */
598 int lov_del_target(struct obd_device *obd, u32 index,
599 struct obd_uuid *uuidp, int gen)
601 struct lov_obd *lov = &obd->u.lov;
602 int count = lov->desc.ld_tgt_count;
606 if (index >= count) {
607 CERROR("LOV target index %d >= number of LOV OBDs %d.\n",
612 /* to make sure there's no ongoing lov_notify() now */
613 down_write(&lov->lov_notify_lock);
614 lov_tgts_getref(obd);
616 if (!lov->lov_tgts[index]) {
617 CERROR("LOV target at index %d is not setup.\n", index);
618 GOTO(out, rc = -EINVAL);
621 if (uuidp && !obd_uuid_equals(uuidp, &lov->lov_tgts[index]->ltd_uuid)) {
622 CERROR("LOV target UUID %s at index %d doesn't match %s.\n",
623 lov_uuid2str(lov, index), index,
624 obd_uuid2str(uuidp));
625 GOTO(out, rc = -EINVAL);
628 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d exp: %p active: %d\n",
629 lov_uuid2str(lov, index), index,
630 lov->lov_tgts[index]->ltd_gen, lov->lov_tgts[index]->ltd_exp,
631 lov->lov_tgts[index]->ltd_active);
633 lov->lov_tgts[index]->ltd_reap = 1;
634 lov->lov_death_row++;
635 /* we really delete it from lov_tgts_putref() */
637 lov_tgts_putref(obd);
638 up_write(&lov->lov_notify_lock);
643 static void __lov_del_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
645 struct obd_device *osc_obd;
648 LASSERT(tgt->ltd_reap);
650 osc_obd = class_exp2obd(tgt->ltd_exp);
652 CDEBUG(D_CONFIG, "Removing tgt %s : %s\n",
654 osc_obd ? osc_obd->obd_name : "<no obd>");
657 lov_disconnect_obd(obd, tgt);
661 /* Manual cleanup - no cleanup logs to clean up the osc's. We must
662 do it ourselves. And we can't do it from lov_cleanup,
663 because we just lost our only reference to it. */
665 class_manual_cleanup(osc_obd);
668 void lov_fix_desc_stripe_size(__u64 *val)
670 if (*val < LOV_MIN_STRIPE_SIZE) {
672 LCONSOLE_INFO("Increasing default stripe size to "
674 LOV_DESC_STRIPE_SIZE_DEFAULT);
675 *val = LOV_DESC_STRIPE_SIZE_DEFAULT;
676 } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) {
677 *val &= ~(LOV_MIN_STRIPE_SIZE - 1);
678 LCONSOLE_WARN("Changing default stripe size to %llu (a "
680 *val, LOV_MIN_STRIPE_SIZE);
684 void lov_fix_desc_stripe_count(__u32 *val)
690 void lov_fix_desc_pattern(__u32 *val)
692 /* from lov_setstripe */
693 if ((*val != 0) && !lov_pattern_supported_normal_comp(*val)) {
694 LCONSOLE_WARN("lov: Unknown stripe pattern: %#x\n", *val);
699 void lov_fix_desc_qos_maxage(__u32 *val)
702 *val = LOV_DESC_QOS_MAXAGE_DEFAULT;
705 void lov_fix_desc(struct lov_desc *desc)
707 lov_fix_desc_stripe_size(&desc->ld_default_stripe_size);
708 lov_fix_desc_stripe_count(&desc->ld_default_stripe_count);
709 lov_fix_desc_pattern(&desc->ld_pattern);
710 lov_fix_desc_qos_maxage(&desc->ld_qos_maxage);
713 int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
715 struct lov_desc *desc;
716 struct lov_obd *lov = &obd->u.lov;
720 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
721 CERROR("LOV setup requires a descriptor\n");
725 desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
727 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
728 CERROR("descriptor size wrong: %d > %d\n",
729 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
733 if (desc->ld_magic != LOV_DESC_MAGIC) {
734 if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
735 CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n",
736 obd->obd_name, desc);
737 lustre_swab_lov_desc(desc);
739 CERROR("%s: Bad lov desc magic: %#x\n",
740 obd->obd_name, desc->ld_magic);
747 desc->ld_active_tgt_count = 0;
749 lov->lov_tgt_size = 0;
751 mutex_init(&lov->lov_lock);
752 atomic_set(&lov->lov_refcount, 0);
753 lov->lov_sp_me = LUSTRE_SP_CLI;
755 init_rwsem(&lov->lov_notify_lock);
757 INIT_LIST_HEAD(&lov->lov_pool_list);
758 lov->lov_pool_count = 0;
759 rc = lov_pool_hash_init(&lov->lov_pools_hash_body);
763 rc = lov_ost_pool_init(&lov->lov_packed, 0);
767 rc = lov_tunables_init(obd);
771 lov->lov_tgts_kobj = kobject_create_and_add("target_obds",
772 &obd->obd_kset.kobj);
778 static int lov_cleanup(struct obd_device *obd)
780 struct lov_obd *lov = &obd->u.lov;
781 struct list_head *pos, *tmp;
782 struct pool_desc *pool;
785 if (lov->lov_tgts_kobj) {
786 kobject_put(lov->lov_tgts_kobj);
787 lov->lov_tgts_kobj = NULL;
790 list_for_each_safe(pos, tmp, &lov->lov_pool_list) {
791 pool = list_entry(pos, struct pool_desc, pool_list);
792 /* free pool structs */
793 CDEBUG(D_INFO, "delete pool %p\n", pool);
794 /* In the function below, .hs_keycmp resolves to
795 * pool_hashkey_keycmp() */
796 /* coverity[overrun-buffer-val] */
797 lov_pool_del(obd, pool->pool_name);
799 lov_pool_hash_destroy(&lov->lov_pools_hash_body);
800 lov_ost_pool_free(&lov->lov_packed);
802 lprocfs_obd_cleanup(obd);
805 lov_tgts_getref(obd);
806 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
807 if (!lov->lov_tgts[i])
810 /* Inactive targets may never have connected */
811 if (lov->lov_tgts[i]->ltd_active)
812 /* We should never get here - these
813 * should have been removed in the
815 CERROR("%s: lov tgt %d not cleaned! "
816 "deathrow=%d, lovrc=%d\n",
817 obd->obd_name, i, lov->lov_death_row,
818 atomic_read(&lov->lov_refcount));
819 lov_del_target(obd, i, NULL, 0);
821 lov_tgts_putref(obd);
822 OBD_FREE_PTR_ARRAY(lov->lov_tgts, lov->lov_tgt_size);
823 lov->lov_tgt_size = 0;
826 if (lov->lov_cache != NULL) {
827 cl_cache_decref(lov->lov_cache);
828 lov->lov_cache = NULL;
834 int lov_process_config_base(struct obd_device *obd, struct lustre_cfg *lcfg,
835 u32 *indexp, int *genp)
837 struct obd_uuid obd_uuid;
842 switch (cmd = lcfg->lcfg_command) {
846 case LCFG_LOV_ADD_OBD:
847 case LCFG_LOV_ADD_INA:
848 case LCFG_LOV_DEL_OBD: {
852 /* lov_modify_tgts add 0:lov_mdsA 1:ost1_UUID 2:0 3:1 */
853 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
854 GOTO(out, rc = -EINVAL);
856 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
858 rc = kstrtou32(lustre_cfg_buf(lcfg, 2), 10, indexp);
861 rc = kstrtoint(lustre_cfg_buf(lcfg, 3), 10, genp);
866 if (cmd == LCFG_LOV_ADD_OBD)
867 rc = lov_add_target(obd, &obd_uuid, index, gen, 1);
868 else if (cmd == LCFG_LOV_ADD_INA)
869 rc = lov_add_target(obd, &obd_uuid, index, gen, 0);
871 rc = lov_del_target(obd, index, &obd_uuid, gen);
876 struct lov_desc *desc = &(obd->u.lov.desc);
880 GOTO(out, rc = -EINVAL);
882 count = class_modify_config(lcfg, PARAM_LOV,
883 &obd->obd_kset.kobj);
884 GOTO(out, rc = count < 0 ? count : 0);
893 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
894 GOTO(out, rc = -EINVAL);
902 static int lov_statfs(const struct lu_env *env, struct obd_export *exp,
903 struct obd_statfs *osfs, time64_t max_age, __u32 flags)
905 struct obd_device *obd = class_exp2obd(exp);
906 struct lov_obd *lov = &obd->u.lov;
907 struct obd_info oinfo = {
911 struct ptlrpc_request_set *rqset;
912 struct lov_request_set *set = NULL;
913 struct lov_request *req;
919 rqset = ptlrpc_prep_set();
923 rc = lov_prep_statfs_set(obd, &oinfo, &set);
927 list_for_each_entry(req, &set->set_list, rq_link) {
928 rc = obd_statfs_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
929 &req->rq_oi, max_age, rqset);
934 rc = ptlrpc_set_wait(env, rqset);
938 atomic_set(&set->set_completes, 0);
940 rc2 = lov_fini_statfs_set(set);
945 ptlrpc_set_destroy(rqset);
950 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
951 void *karg, void __user *uarg)
953 struct obd_device *obd = class_exp2obd(exp);
954 struct lov_obd *lov = &obd->u.lov;
955 int i = 0, rc = 0, count = lov->desc.ld_tgt_count;
956 struct obd_uuid *uuidp;
960 case IOC_OBD_STATFS: {
961 struct obd_ioctl_data *data = karg;
962 struct obd_device *osc_obd;
963 struct obd_statfs stat_buf = {0};
964 struct obd_import *imp;
968 memcpy(&index, data->ioc_inlbuf2, sizeof(index));
972 if (!lov->lov_tgts[index])
973 /* Try again with the next index */
976 osc_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
980 imp = osc_obd->u.cli.cl_import;
981 if (!lov->lov_tgts[index]->ltd_active &&
982 imp->imp_state != LUSTRE_IMP_IDLE)
986 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(osc_obd),
987 min_t(unsigned long, data->ioc_plen2,
988 sizeof(struct obd_uuid))))
991 memcpy(&flags, data->ioc_inlbuf1, sizeof(flags));
992 flags = flags & LL_STATFS_NODELAY ? OBD_STATFS_NODELAY : 0;
994 /* got statfs data */
995 rc = obd_statfs(NULL, lov->lov_tgts[index]->ltd_exp, &stat_buf,
996 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
1000 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
1001 min_t(unsigned long, data->ioc_plen1,
1002 sizeof(struct obd_statfs))))
1006 case OBD_IOC_LOV_GET_CONFIG: {
1007 struct obd_ioctl_data *data = NULL;
1008 struct lov_desc *desc;
1012 if (obd_ioctl_getdata(&data, &len, uarg))
1015 if (sizeof(*desc) > data->ioc_inllen1) {
1016 OBD_FREE_LARGE(data, len);
1020 if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
1021 OBD_FREE_LARGE(data, len);
1025 if (sizeof(__u32) * count > data->ioc_inllen3) {
1026 OBD_FREE_LARGE(data, len);
1030 desc = (struct lov_desc *)data->ioc_inlbuf1;
1031 memcpy(desc, &lov->desc, sizeof(*desc));
1033 uuidp = (struct obd_uuid *)data->ioc_inlbuf2;
1034 genp = (__u32 *)data->ioc_inlbuf3;
1035 /* the uuid will be empty for deleted OSTs */
1036 for (i = 0; i < count; i++, uuidp++, genp++) {
1037 if (!lov->lov_tgts[i])
1039 *uuidp = lov->lov_tgts[i]->ltd_uuid;
1040 *genp = lov->lov_tgts[i]->ltd_gen;
1043 if (copy_to_user(uarg, data, len))
1045 OBD_FREE_LARGE(data, len);
1048 case OBD_IOC_QUOTACTL: {
1049 struct if_quotactl *qctl = karg;
1050 struct lov_tgt_desc *tgt = NULL;
1051 struct obd_quotactl *oqctl;
1053 if (qctl->qc_valid == QC_OSTIDX) {
1054 if (count <= qctl->qc_idx)
1057 tgt = lov->lov_tgts[qctl->qc_idx];
1058 if (!tgt || !tgt->ltd_exp)
1060 } else if (qctl->qc_valid == QC_UUID) {
1061 for (i = 0; i < count; i++) {
1062 tgt = lov->lov_tgts[i];
1064 !obd_uuid_equals(&tgt->ltd_uuid,
1068 if (tgt->ltd_exp == NULL)
1080 LASSERT(tgt && tgt->ltd_exp);
1081 OBD_ALLOC_PTR(oqctl);
1085 QCTL_COPY(oqctl, qctl);
1086 rc = obd_quotactl(tgt->ltd_exp, oqctl);
1088 QCTL_COPY(qctl, oqctl);
1089 qctl->qc_valid = QC_OSTIDX;
1090 qctl->obd_uuid = tgt->ltd_uuid;
1092 OBD_FREE_PTR(oqctl);
1101 for (i = 0; i < count; i++) {
1103 struct obd_device *osc_obd;
1105 /* OST was disconnected */
1106 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
1109 /* ll_umount_begin() sets force on lov, pass to osc */
1110 osc_obd = class_exp2obd(lov->lov_tgts[i]->ltd_exp);
1112 osc_obd->obd_force = obd->obd_force;
1113 err = obd_iocontrol(cmd, lov->lov_tgts[i]->ltd_exp,
1116 if (lov->lov_tgts[i]->ltd_active) {
1117 CDEBUG(err == -ENOTTY ?
1118 D_IOCTL : D_WARNING,
1119 "iocontrol OSC %s on OST idx %d cmd %x: err = %d\n",
1120 lov_uuid2str(lov, i),
1137 static int lov_get_info(const struct lu_env *env, struct obd_export *exp,
1138 __u32 keylen, void *key, __u32 *vallen, void *val)
1140 struct obd_device *obd = class_exp2obd(exp);
1141 struct lov_obd *lov = &obd->u.lov;
1142 struct lov_desc *ld = &lov->desc;
1146 if (vallen == NULL || val == NULL)
1149 lov_tgts_getref(obd);
1151 if (KEY_IS(KEY_MAX_EASIZE)) {
1152 *((u32 *)val) = exp->exp_connect_data.ocd_max_easize;
1153 } else if (KEY_IS(KEY_DEFAULT_EASIZE)) {
1154 u32 def_stripe_count = min_t(u32, ld->ld_default_stripe_count,
1155 LOV_MAX_STRIPE_COUNT);
1157 *((u32 *)val) = lov_mds_md_size(def_stripe_count, LOV_MAGIC_V3);
1158 } else if (KEY_IS(KEY_TGT_COUNT)) {
1159 *((int *)val) = lov->desc.ld_tgt_count;
1164 lov_tgts_putref(obd);
1169 static int lov_set_info_async(const struct lu_env *env, struct obd_export *exp,
1170 __u32 keylen, void *key,
1171 __u32 vallen, void *val,
1172 struct ptlrpc_request_set *set)
1174 struct obd_device *obd = class_exp2obd(exp);
1175 struct lov_obd *lov = &obd->u.lov;
1176 struct lov_tgt_desc *tgt;
1177 bool do_inactive = false, no_set = false;
1186 set = ptlrpc_prep_set();
1191 lov_tgts_getref(obd);
1193 if (KEY_IS(KEY_CHECKSUM))
1196 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1197 tgt = lov->lov_tgts[i];
1199 /* OST was disconnected */
1200 if (tgt == NULL || tgt->ltd_exp == NULL)
1203 /* OST is inactive and we don't want inactive OSCs */
1204 if (!tgt->ltd_active && !do_inactive)
1207 err = obd_set_info_async(env, tgt->ltd_exp, keylen, key,
1214 /* cycle through MDC target for Data-on-MDT */
1215 for (i = 0; i < LOV_MDC_TGT_MAX; i++) {
1216 struct obd_device *mdc;
1218 mdc = lov->lov_mdc_tgts[i].lmtd_mdc;
1222 err = obd_set_info_async(env, mdc->obd_self_export,
1223 keylen, key, vallen, val, set);
1228 lov_tgts_putref(obd);
1230 err = ptlrpc_set_wait(env, set);
1233 ptlrpc_set_destroy(set);
1238 void lov_stripe_lock(struct lov_stripe_md *md)
1239 __acquires(&md->lsm_lock)
1241 LASSERT(md->lsm_lock_owner != current->pid);
1242 spin_lock(&md->lsm_lock);
1243 LASSERT(md->lsm_lock_owner == 0);
1244 md->lsm_lock_owner = current->pid;
1247 void lov_stripe_unlock(struct lov_stripe_md *md)
1248 __releases(&md->lsm_lock)
1250 LASSERT(md->lsm_lock_owner == current->pid);
1251 md->lsm_lock_owner = 0;
1252 spin_unlock(&md->lsm_lock);
1255 static int lov_quotactl(struct obd_device *obd, struct obd_export *exp,
1256 struct obd_quotactl *oqctl)
1258 struct lov_obd *lov = &obd->u.lov;
1259 struct lov_tgt_desc *tgt;
1260 struct pool_desc *pool = NULL;
1262 __u64 bhardlimit = 0;
1266 if (oqctl->qc_cmd != Q_GETOQUOTA &&
1267 oqctl->qc_cmd != LUSTRE_Q_SETQUOTA &&
1268 oqctl->qc_cmd != LUSTRE_Q_GETQUOTAPOOL) {
1270 CERROR("%s: bad quota opc %x for lov obd: rc = %d\n",
1271 obd->obd_name, oqctl->qc_cmd, rc);
1275 if (oqctl->qc_cmd == LUSTRE_Q_GETQUOTAPOOL) {
1276 pool = lov_pool_find(obd, oqctl->qc_poolname);
1279 /* Set Q_GETOQUOTA back as targets report it's own
1280 * usage and doesn't care about pools */
1281 oqctl->qc_cmd = Q_GETOQUOTA;
1285 lov_tgts_getref(obd);
1286 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1289 tgt = lov->lov_tgts[i];
1295 tgt_check_index(tgt->ltd_index, &pool->pool_obds))
1298 if (!tgt->ltd_active || tgt->ltd_reap) {
1299 if (oqctl->qc_cmd == Q_GETOQUOTA &&
1300 lov->lov_tgts[i]->ltd_activate) {
1302 CERROR("%s: ost %d is inactive: rc = %d\n",
1303 obd->obd_name, i, rc);
1305 CDEBUG(D_HA, "ost %d is inactive\n", i);
1310 err = obd_quotactl(tgt->ltd_exp, oqctl);
1312 if (tgt->ltd_active && !rc)
1317 if (oqctl->qc_cmd == Q_GETOQUOTA) {
1318 curspace += oqctl->qc_dqblk.dqb_curspace;
1319 bhardlimit += oqctl->qc_dqblk.dqb_bhardlimit;
1322 lov_tgts_putref(obd);
1324 lov_pool_putref(pool);
1326 if (oqctl->qc_cmd == Q_GETOQUOTA) {
1327 oqctl->qc_dqblk.dqb_curspace = curspace;
1328 oqctl->qc_dqblk.dqb_bhardlimit = bhardlimit;
1333 static const struct obd_ops lov_obd_ops = {
1334 .o_owner = THIS_MODULE,
1335 .o_setup = lov_setup,
1336 .o_cleanup = lov_cleanup,
1337 .o_connect = lov_connect,
1338 .o_disconnect = lov_disconnect,
1339 .o_statfs = lov_statfs,
1340 .o_iocontrol = lov_iocontrol,
1341 .o_get_info = lov_get_info,
1342 .o_set_info_async = lov_set_info_async,
1343 .o_notify = lov_notify,
1344 .o_pool_new = lov_pool_new,
1345 .o_pool_rem = lov_pool_remove,
1346 .o_pool_add = lov_pool_add,
1347 .o_pool_del = lov_pool_del,
1348 .o_quotactl = lov_quotactl,
1351 struct kmem_cache *lov_oinfo_slab;
1353 static int __init lov_init(void)
1358 /* print an address of _any_ initialized kernel symbol from this
1359 * module, to allow debugging with gdb that doesn't support data
1360 * symbols from modules.*/
1361 CDEBUG(D_INFO, "Lustre LOV module (%p).\n", &lov_caches);
1363 rc = lu_kmem_init(lov_caches);
1367 lov_oinfo_slab = kmem_cache_create("lov_oinfo",
1368 sizeof(struct lov_oinfo), 0,
1369 SLAB_HWCACHE_ALIGN, NULL);
1370 if (lov_oinfo_slab == NULL) {
1371 lu_kmem_fini(lov_caches);
1375 rc = class_register_type(&lov_obd_ops, NULL, true, NULL,
1376 LUSTRE_LOV_NAME, &lov_device_type);
1378 kmem_cache_destroy(lov_oinfo_slab);
1379 lu_kmem_fini(lov_caches);
1385 static void __exit lov_exit(void)
1387 class_unregister_type(LUSTRE_LOV_NAME);
1388 kmem_cache_destroy(lov_oinfo_slab);
1389 lu_kmem_fini(lov_caches);
1392 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
1393 MODULE_DESCRIPTION("Lustre Logical Object Volume");
1394 MODULE_VERSION(LUSTRE_VERSION_STRING);
1395 MODULE_LICENSE("GPL");
1397 module_init(lov_init);
1398 module_exit(lov_exit);