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, 2016, 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 <lustre/lustre_idl.h>
45 #include <cl_object.h>
46 #include <lustre_dlm.h>
47 #include <lustre_fid.h>
48 #include <lustre_ioctl.h>
49 #include <lustre_lib.h>
50 #include <lustre_mds.h>
51 #include <lustre_net.h>
52 #include <lustre_param.h>
53 #include <lustre_swab.h>
54 #include <lprocfs_status.h>
55 #include <obd_class.h>
56 #include <obd_support.h>
58 #include "lov_internal.h"
60 /* Keep a refcount of lov->tgt usage to prevent racing with addition/deletion.
61 Any function that expects lov_tgts to remain stationary must take a ref. */
62 static void lov_getref(struct obd_device *obd)
64 struct lov_obd *lov = &obd->u.lov;
66 /* nobody gets through here until lov_putref is done */
67 mutex_lock(&lov->lov_lock);
68 atomic_inc(&lov->lov_refcount);
69 mutex_unlock(&lov->lov_lock);
73 static void __lov_del_obd(struct obd_device *obd, struct lov_tgt_desc *tgt);
75 static void lov_putref(struct obd_device *obd)
77 struct lov_obd *lov = &obd->u.lov;
79 mutex_lock(&lov->lov_lock);
80 /* ok to dec to 0 more than once -- ltd_exp's will be null */
81 if (atomic_dec_and_test(&lov->lov_refcount) && lov->lov_death_row) {
82 struct list_head kill = LIST_HEAD_INIT(kill);
83 struct lov_tgt_desc *tgt, *n;
86 CDEBUG(D_CONFIG, "destroying %d lov targets\n",
88 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
89 tgt = lov->lov_tgts[i];
91 if (!tgt || !tgt->ltd_reap)
93 list_add(&tgt->ltd_kill, &kill);
94 /* XXX - right now there is a dependency on ld_tgt_count
95 * being the maximum tgt index for computing the
96 * mds_max_easize. So we can't shrink it. */
97 lov_ost_pool_remove(&lov->lov_packed, i);
98 lov->lov_tgts[i] = NULL;
101 mutex_unlock(&lov->lov_lock);
103 list_for_each_entry_safe(tgt, n, &kill, ltd_kill) {
104 list_del(&tgt->ltd_kill);
106 __lov_del_obd(obd, tgt);
109 mutex_unlock(&lov->lov_lock);
113 static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
114 enum obd_notify_event ev);
115 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
116 enum obd_notify_event ev, void *data);
118 int lov_connect_obd(struct obd_device *obd, __u32 index, int activate,
119 struct obd_connect_data *data)
121 struct lov_obd *lov = &obd->u.lov;
122 struct obd_uuid *tgt_uuid;
123 struct obd_device *tgt_obd;
124 static struct obd_uuid lov_osc_uuid = { "LOV_OSC_UUID" };
125 struct obd_import *imp;
129 if (lov->lov_tgts[index] == NULL)
132 tgt_uuid = &lov->lov_tgts[index]->ltd_uuid;
133 tgt_obd = lov->lov_tgts[index]->ltd_obd;
135 if (!tgt_obd->obd_set_up) {
136 CERROR("Target %s not set up\n", obd_uuid2str(tgt_uuid));
140 /* override the sp_me from lov */
141 tgt_obd->u.cli.cl_sp_me = lov->lov_sp_me;
143 if (data && (data->ocd_connect_flags & OBD_CONNECT_INDEX))
144 data->ocd_index = index;
147 * Divine LOV knows that OBDs under it are OSCs.
149 imp = tgt_obd->u.cli.cl_import;
152 tgt_obd->obd_no_recov = 0;
153 /* FIXME this is probably supposed to be
154 ptlrpc_set_import_active. Horrible naming. */
155 ptlrpc_activate_import(imp);
158 rc = obd_register_observer(tgt_obd, obd);
160 CERROR("Target %s register_observer error %d\n",
161 obd_uuid2str(tgt_uuid), rc);
166 if (imp->imp_invalid) {
167 CDEBUG(D_CONFIG, "not connecting OSC %s; administratively "
168 "disabled\n", obd_uuid2str(tgt_uuid));
172 rc = obd_connect(NULL, &lov->lov_tgts[index]->ltd_exp, tgt_obd,
173 &lov_osc_uuid, data, NULL);
174 if (rc || !lov->lov_tgts[index]->ltd_exp) {
175 CERROR("Target %s connect error %d\n",
176 obd_uuid2str(tgt_uuid), rc);
180 lov->lov_tgts[index]->ltd_reap = 0;
182 CDEBUG(D_CONFIG, "Connected tgt idx %d %s (%s) %sactive\n", index,
183 obd_uuid2str(tgt_uuid), tgt_obd->obd_name, activate ? "":"in");
185 if (lov->targets_proc_entry != NULL) {
186 struct proc_dir_entry *osc_symlink;
187 struct obd_device *osc_obd;
189 osc_obd = lov->lov_tgts[index]->ltd_exp->exp_obd;
191 LASSERT(osc_obd != NULL);
192 LASSERT(osc_obd->obd_magic == OBD_DEVICE_MAGIC);
193 LASSERT(osc_obd->obd_type->typ_name != NULL);
195 osc_symlink = lprocfs_add_symlink(osc_obd->obd_name,
196 lov->targets_proc_entry,
198 osc_obd->obd_type->typ_name,
200 if (osc_symlink == NULL) {
201 CERROR("cannot register LOV target "
202 "/proc/fs/lustre/%s/%s/target_obds/%s\n",
203 obd->obd_type->typ_name, obd->obd_name,
210 static int lov_connect(const struct lu_env *env,
211 struct obd_export **exp, struct obd_device *obd,
212 struct obd_uuid *cluuid, struct obd_connect_data *data,
215 struct lov_obd *lov = &obd->u.lov;
216 struct lov_tgt_desc *tgt;
217 struct lustre_handle conn;
221 CDEBUG(D_CONFIG, "connect #%d\n", lov->lov_connects);
223 rc = class_connect(&conn, obd, cluuid);
227 *exp = class_conn2export(&conn);
229 /* Why should there ever be more than 1 connect? */
231 LASSERT(lov->lov_connects == 1);
233 memset(&lov->lov_ocd, 0, sizeof(lov->lov_ocd));
235 lov->lov_ocd = *data;
237 lov->targets_proc_entry = lprocfs_register("target_obds",
240 if (IS_ERR(lov->targets_proc_entry)) {
241 CERROR("%s: cannot register "
242 "/proc/fs/lustre/%s/%s/target_obds\n",
243 obd->obd_name, obd->obd_type->typ_name, obd->obd_name);
244 lov->targets_proc_entry = NULL;
248 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
249 tgt = lov->lov_tgts[i];
250 if (!tgt || obd_uuid_empty(&tgt->ltd_uuid))
252 /* Flags will be lowest common denominator */
253 rc = lov_connect_obd(obd, i, tgt->ltd_activate, &lov->lov_ocd);
255 CERROR("%s: lov connect tgt %d failed: %d\n",
256 obd->obd_name, i, rc);
259 /* connect to administrative disabled ost */
260 if (!lov->lov_tgts[i]->ltd_exp)
263 rc = lov_notify(obd, lov->lov_tgts[i]->ltd_exp->exp_obd,
264 OBD_NOTIFY_CONNECT, (void *)&i);
266 CERROR("%s error sending notify %d\n",
275 static int lov_disconnect_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
277 struct lov_obd *lov = &obd->u.lov;
278 struct obd_device *osc_obd;
282 osc_obd = class_exp2obd(tgt->ltd_exp);
283 CDEBUG(D_CONFIG, "%s: disconnecting target %s\n",
284 obd->obd_name, osc_obd->obd_name);
286 if (tgt->ltd_active) {
288 lov->desc.ld_active_tgt_count--;
289 tgt->ltd_exp->exp_obd->obd_inactive = 1;
293 /* Pass it on to our clients.
294 * XXX This should be an argument to disconnect,
295 * XXX not a back-door flag on the OBD. Ah well.
297 osc_obd->obd_force = obd->obd_force;
298 osc_obd->obd_fail = obd->obd_fail;
299 osc_obd->obd_no_recov = obd->obd_no_recov;
301 if (lov->targets_proc_entry != NULL)
302 lprocfs_remove_proc_entry(osc_obd->obd_name,
303 lov->targets_proc_entry);
306 obd_register_observer(osc_obd, NULL);
308 rc = obd_disconnect(tgt->ltd_exp);
310 CERROR("Target %s disconnect error %d\n",
311 tgt->ltd_uuid.uuid, rc);
319 static int lov_disconnect(struct obd_export *exp)
321 struct obd_device *obd = class_exp2obd(exp);
322 struct lov_obd *lov = &obd->u.lov;
329 /* Only disconnect the underlying layers on the final disconnect. */
331 if (lov->lov_connects != 0) {
332 /* why should there be more than 1 connect? */
333 CERROR("disconnect #%d\n", lov->lov_connects);
337 /* Let's hold another reference so lov_del_obd doesn't spin through
341 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
342 if (lov->lov_tgts[i] && lov->lov_tgts[i]->ltd_exp) {
343 /* Disconnection is the last we know about an obd */
344 lov_del_target(obd, i, NULL, lov->lov_tgts[i]->ltd_gen);
349 if (lov->targets_proc_entry != NULL)
350 lprocfs_remove(&lov->targets_proc_entry);
353 rc = class_disconnect(exp); /* bz 9811 */
359 * -EINVAL : UUID can't be found in the LOV's target list
360 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
361 * -EBADF : The UUID is found, but the OBD is the wrong type (!)
362 * any >= 0 : is log target index
364 static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
365 enum obd_notify_event ev)
367 struct lov_obd *lov = &obd->u.lov;
368 struct lov_tgt_desc *tgt;
369 int index, activate, active;
372 CDEBUG(D_INFO, "Searching in lov %p for uuid %s event(%d)\n",
373 lov, uuid->uuid, ev);
376 for (index = 0; index < lov->desc.ld_tgt_count; index++) {
377 tgt = lov->lov_tgts[index];
381 * LU-642, initially inactive OSC could miss the obd_connect,
382 * we make up for it here.
384 if (ev == OBD_NOTIFY_ACTIVATE && tgt->ltd_exp == NULL &&
385 obd_uuid_equals(uuid, &tgt->ltd_uuid)) {
386 struct obd_uuid lov_osc_uuid = {"LOV_OSC_UUID"};
388 obd_connect(NULL, &tgt->ltd_exp, tgt->ltd_obd,
389 &lov_osc_uuid, &lov->lov_ocd, NULL);
394 CDEBUG(D_INFO, "lov idx %d is %s conn %#llx\n",
395 index, obd_uuid2str(&tgt->ltd_uuid),
396 tgt->ltd_exp->exp_handle.h_cookie);
397 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
401 if (index == lov->desc.ld_tgt_count)
402 GOTO(out, index = -EINVAL);
404 if (ev == OBD_NOTIFY_DEACTIVATE || ev == OBD_NOTIFY_ACTIVATE) {
405 activate = (ev == OBD_NOTIFY_ACTIVATE) ? 1 : 0;
407 if (lov->lov_tgts[index]->ltd_activate == activate) {
408 CDEBUG(D_INFO, "OSC %s already %sactivate!\n",
409 uuid->uuid, activate ? "" : "de");
411 lov->lov_tgts[index]->ltd_activate = activate;
412 CDEBUG(D_CONFIG, "%sactivate OSC %s\n",
413 activate ? "" : "de", obd_uuid2str(uuid));
416 } else if (ev == OBD_NOTIFY_INACTIVE || ev == OBD_NOTIFY_ACTIVE) {
417 active = (ev == OBD_NOTIFY_ACTIVE) ? 1 : 0;
419 if (lov->lov_tgts[index]->ltd_active == active) {
420 CDEBUG(D_INFO, "OSC %s already %sactive!\n",
421 uuid->uuid, active ? "" : "in");
424 CDEBUG(D_CONFIG, "Marking OSC %s %sactive\n",
425 obd_uuid2str(uuid), active ? "" : "in");
428 lov->lov_tgts[index]->ltd_active = active;
430 lov->desc.ld_active_tgt_count++;
431 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 0;
433 lov->desc.ld_active_tgt_count--;
434 lov->lov_tgts[index]->ltd_exp->exp_obd->obd_inactive = 1;
437 CERROR("%s: unknown event %d for uuid %s\n", obd->obd_name,
446 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
447 enum obd_notify_event ev, void *data)
450 struct lov_obd *lov = &obd->u.lov;
453 down_read(&lov->lov_notify_lock);
454 if (!lov->lov_connects)
455 GOTO(out_notify_lock, rc = 0);
457 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE ||
458 ev == OBD_NOTIFY_ACTIVATE || ev == OBD_NOTIFY_DEACTIVATE) {
459 struct obd_uuid *uuid;
463 if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
464 CERROR("unexpected notification of %s %s\n",
465 watched->obd_type->typ_name, watched->obd_name);
466 GOTO(out_notify_lock, rc = -EINVAL);
469 uuid = &watched->u.cli.cl_target_uuid;
471 /* Set OSC as active before notifying the observer, so the
472 * observer can use the OSC normally.
474 rc = lov_set_osc_active(obd, uuid, ev);
476 CERROR("%s: event %d failed: rc = %d\n", obd->obd_name,
478 GOTO(out_notify_lock, rc);
481 /* active event should be pass lov target index as data */
485 /* Pass the notification up the chain. */
486 rc = obd_notify_observer(obd, watched, ev, data);
489 up_read(&lov->lov_notify_lock);
494 static int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
495 __u32 index, int gen, int active)
497 struct lov_obd *lov = &obd->u.lov;
498 struct lov_tgt_desc *tgt;
499 struct obd_device *tgt_obd;
503 CDEBUG(D_CONFIG, "uuid:%s idx:%d gen:%d active:%d\n",
504 uuidp->uuid, index, gen, active);
507 CERROR("request to add OBD %s with invalid generation: %d\n",
512 tgt_obd = class_find_client_obd(uuidp, LUSTRE_OSC_NAME,
517 mutex_lock(&lov->lov_lock);
519 if ((index < lov->lov_tgt_size) && (lov->lov_tgts[index] != NULL)) {
520 tgt = lov->lov_tgts[index];
521 CERROR("UUID %s already assigned at LOV target index %d\n",
522 obd_uuid2str(&tgt->ltd_uuid), index);
523 mutex_unlock(&lov->lov_lock);
527 if (index >= lov->lov_tgt_size) {
528 /* We need to reallocate the lov target array. */
529 struct lov_tgt_desc **newtgts, **old = NULL;
530 __u32 newsize, oldsize = 0;
532 newsize = max(lov->lov_tgt_size, (__u32)2);
533 while (newsize < index + 1)
534 newsize = newsize << 1;
535 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
536 if (newtgts == NULL) {
537 mutex_unlock(&lov->lov_lock);
541 if (lov->lov_tgt_size) {
542 memcpy(newtgts, lov->lov_tgts, sizeof(*newtgts) *
545 oldsize = lov->lov_tgt_size;
548 lov->lov_tgts = newtgts;
549 lov->lov_tgt_size = newsize;
552 OBD_FREE(old, sizeof(*old) * oldsize);
554 CDEBUG(D_CONFIG, "tgts: %p size: %d\n",
555 lov->lov_tgts, lov->lov_tgt_size);
560 mutex_unlock(&lov->lov_lock);
564 rc = lov_ost_pool_add(&lov->lov_packed, index, lov->lov_tgt_size);
566 mutex_unlock(&lov->lov_lock);
571 tgt->ltd_uuid = *uuidp;
572 tgt->ltd_obd = tgt_obd;
573 /* XXX - add a sanity check on the generation number. */
575 tgt->ltd_index = index;
576 tgt->ltd_activate = active;
577 lov->lov_tgts[index] = tgt;
578 if (index >= lov->desc.ld_tgt_count)
579 lov->desc.ld_tgt_count = index + 1;
581 mutex_unlock(&lov->lov_lock);
583 CDEBUG(D_CONFIG, "idx=%d ltd_gen=%d ld_tgt_count=%d\n",
584 index, tgt->ltd_gen, lov->desc.ld_tgt_count);
586 if (lov->lov_connects == 0) {
587 /* lov_connect hasn't been called yet. We'll do the
588 lov_connect_obd on this target when that fn first runs,
589 because we don't know the connect flags yet. */
595 rc = lov_connect_obd(obd, index, active, &lov->lov_ocd);
599 /* connect to administrative disabled ost */
603 if (lov->lov_cache != NULL) {
604 rc = obd_set_info_async(NULL, tgt->ltd_exp,
605 sizeof(KEY_CACHE_SET), KEY_CACHE_SET,
606 sizeof(struct cl_client_cache), lov->lov_cache,
612 rc = lov_notify(obd, tgt->ltd_exp->exp_obd,
613 active ? OBD_NOTIFY_CONNECT : OBD_NOTIFY_INACTIVE,
618 CERROR("add failed (%d), deleting %s\n", rc,
619 obd_uuid2str(&tgt->ltd_uuid));
620 lov_del_target(obd, index, NULL, 0);
626 /* Schedule a target for deletion */
627 int lov_del_target(struct obd_device *obd, __u32 index,
628 struct obd_uuid *uuidp, int gen)
630 struct lov_obd *lov = &obd->u.lov;
631 int count = lov->desc.ld_tgt_count;
635 if (index >= count) {
636 CERROR("LOV target index %d >= number of LOV OBDs %d.\n",
641 /* to make sure there's no ongoing lov_notify() now */
642 down_write(&lov->lov_notify_lock);
645 if (!lov->lov_tgts[index]) {
646 CERROR("LOV target at index %d is not setup.\n", index);
647 GOTO(out, rc = -EINVAL);
650 if (uuidp && !obd_uuid_equals(uuidp, &lov->lov_tgts[index]->ltd_uuid)) {
651 CERROR("LOV target UUID %s at index %d doesn't match %s.\n",
652 lov_uuid2str(lov, index), index,
653 obd_uuid2str(uuidp));
654 GOTO(out, rc = -EINVAL);
657 CDEBUG(D_CONFIG, "uuid: %s idx: %d gen: %d exp: %p active: %d\n",
658 lov_uuid2str(lov, index), index,
659 lov->lov_tgts[index]->ltd_gen, lov->lov_tgts[index]->ltd_exp,
660 lov->lov_tgts[index]->ltd_active);
662 lov->lov_tgts[index]->ltd_reap = 1;
663 lov->lov_death_row++;
664 /* we really delete it from obd_putref */
667 up_write(&lov->lov_notify_lock);
672 static void __lov_del_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
674 struct obd_device *osc_obd;
677 LASSERT(tgt->ltd_reap);
679 osc_obd = class_exp2obd(tgt->ltd_exp);
681 CDEBUG(D_CONFIG, "Removing tgt %s : %s\n",
683 osc_obd ? osc_obd->obd_name : "<no obd>");
686 lov_disconnect_obd(obd, tgt);
690 /* Manual cleanup - no cleanup logs to clean up the osc's. We must
691 do it ourselves. And we can't do it from lov_cleanup,
692 because we just lost our only reference to it. */
694 class_manual_cleanup(osc_obd);
697 void lov_fix_desc_stripe_size(__u64 *val)
699 if (*val < LOV_MIN_STRIPE_SIZE) {
701 LCONSOLE_INFO("Increasing default stripe size to "
703 LOV_DESC_STRIPE_SIZE_DEFAULT);
704 *val = LOV_DESC_STRIPE_SIZE_DEFAULT;
705 } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) {
706 *val &= ~(LOV_MIN_STRIPE_SIZE - 1);
707 LCONSOLE_WARN("Changing default stripe size to %llu (a "
709 *val, LOV_MIN_STRIPE_SIZE);
713 void lov_fix_desc_stripe_count(__u32 *val)
719 void lov_fix_desc_pattern(__u32 *val)
721 /* from lov_setstripe */
722 if ((*val != 0) && (*val != LOV_PATTERN_RAID0)) {
723 LCONSOLE_WARN("Unknown stripe pattern: %#x\n", *val);
728 void lov_fix_desc_qos_maxage(__u32 *val)
731 *val = LOV_DESC_QOS_MAXAGE_DEFAULT;
734 void lov_fix_desc(struct lov_desc *desc)
736 lov_fix_desc_stripe_size(&desc->ld_default_stripe_size);
737 lov_fix_desc_stripe_count(&desc->ld_default_stripe_count);
738 lov_fix_desc_pattern(&desc->ld_pattern);
739 lov_fix_desc_qos_maxage(&desc->ld_qos_maxage);
742 int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
744 struct lov_desc *desc;
745 struct lov_obd *lov = &obd->u.lov;
746 #ifdef CONFIG_PROC_FS
747 struct obd_type *type;
752 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
753 CERROR("LOV setup requires a descriptor\n");
757 desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
759 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
760 CERROR("descriptor size wrong: %d > %d\n",
761 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
765 if (desc->ld_magic != LOV_DESC_MAGIC) {
766 if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
767 CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n",
768 obd->obd_name, desc);
769 lustre_swab_lov_desc(desc);
771 CERROR("%s: Bad lov desc magic: %#x\n",
772 obd->obd_name, desc->ld_magic);
779 desc->ld_active_tgt_count = 0;
781 lov->lov_tgt_size = 0;
783 mutex_init(&lov->lov_lock);
784 atomic_set(&lov->lov_refcount, 0);
785 lov->lov_sp_me = LUSTRE_SP_CLI;
787 init_rwsem(&lov->lov_notify_lock);
789 lov->lov_pools_hash_body = cfs_hash_create("POOLS", HASH_POOLS_CUR_BITS,
791 HASH_POOLS_BKT_BITS, 0,
794 &pool_hash_operations,
796 INIT_LIST_HEAD(&lov->lov_pool_list);
797 lov->lov_pool_count = 0;
798 rc = lov_ost_pool_init(&lov->lov_packed, 0);
802 #ifdef CONFIG_PROC_FS
803 obd->obd_vars = lprocfs_lov_obd_vars;
804 /* If this is true then both client (lov) and server
805 * (lod) are on the same node. The lod layer if loaded
806 * first will register the lov proc directory. In that
807 * case obd->obd_type->typ_procroot will be not set.
808 * Instead we use type->typ_procsym as the parent. */
809 type = class_search_type(LUSTRE_LOD_NAME);
810 if (type != NULL && type->typ_procsym != NULL) {
811 obd->obd_proc_entry = lprocfs_register(obd->obd_name,
814 if (IS_ERR(obd->obd_proc_entry)) {
815 rc = PTR_ERR(obd->obd_proc_entry);
816 CERROR("error %d setting up lprocfs for %s\n", rc,
818 obd->obd_proc_entry = NULL;
821 rc = lprocfs_obd_setup(obd);
825 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
826 0444, &lov_proc_target_fops, obd);
828 CWARN("Error adding the target_obd file\n");
830 lov->lov_pool_proc_entry = lprocfs_register("pools",
833 if (IS_ERR(lov->lov_pool_proc_entry)) {
834 rc = PTR_ERR(lov->lov_pool_proc_entry);
835 CERROR("error %d setting up lprocfs for pools\n", rc);
836 lov->lov_pool_proc_entry = NULL;
846 static int lov_cleanup(struct obd_device *obd)
848 struct lov_obd *lov = &obd->u.lov;
849 struct list_head *pos, *tmp;
850 struct pool_desc *pool;
853 list_for_each_safe(pos, tmp, &lov->lov_pool_list) {
854 pool = list_entry(pos, struct pool_desc, pool_list);
855 /* free pool structs */
856 CDEBUG(D_INFO, "delete pool %p\n", pool);
857 /* In the function below, .hs_keycmp resolves to
858 * pool_hashkey_keycmp() */
859 /* coverity[overrun-buffer-val] */
860 lov_pool_del(obd, pool->pool_name);
862 cfs_hash_putref(lov->lov_pools_hash_body);
863 lov_ost_pool_free(&lov->lov_packed);
865 lprocfs_obd_cleanup(obd);
869 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
870 if (!lov->lov_tgts[i])
873 /* Inactive targets may never have connected */
874 if (lov->lov_tgts[i]->ltd_active ||
875 atomic_read(&lov->lov_refcount))
876 /* We should never get here - these
877 * should have been removed in the
879 CERROR("%s: lov tgt %d not cleaned! "
880 "deathrow=%d, lovrc=%d\n",
881 obd->obd_name, i, lov->lov_death_row,
882 atomic_read(&lov->lov_refcount));
883 lov_del_target(obd, i, NULL, 0);
886 OBD_FREE(lov->lov_tgts, sizeof(*lov->lov_tgts) *
888 lov->lov_tgt_size = 0;
891 if (lov->lov_cache != NULL) {
892 cl_cache_decref(lov->lov_cache);
893 lov->lov_cache = NULL;
899 int lov_process_config_base(struct obd_device *obd, struct lustre_cfg *lcfg,
900 __u32 *indexp, int *genp)
902 struct obd_uuid obd_uuid;
907 switch(cmd = lcfg->lcfg_command) {
908 case LCFG_LOV_ADD_OBD:
909 case LCFG_LOV_ADD_INA:
910 case LCFG_LOV_DEL_OBD: {
913 /* lov_modify_tgts add 0:lov_mdsA 1:ost1_UUID 2:0 3:1 */
914 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
915 GOTO(out, rc = -EINVAL);
917 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
919 if (sscanf(lustre_cfg_buf(lcfg, 2), "%u", indexp) != 1)
920 GOTO(out, rc = -EINVAL);
921 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", genp) != 1)
922 GOTO(out, rc = -EINVAL);
925 if (cmd == LCFG_LOV_ADD_OBD)
926 rc = lov_add_target(obd, &obd_uuid, index, gen, 1);
927 else if (cmd == LCFG_LOV_ADD_INA)
928 rc = lov_add_target(obd, &obd_uuid, index, gen, 0);
930 rc = lov_del_target(obd, index, &obd_uuid, gen);
934 struct lov_desc *desc = &(obd->u.lov.desc);
937 GOTO(out, rc = -EINVAL);
939 rc = class_process_proc_param(PARAM_LOV, obd->obd_vars,
952 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
953 GOTO(out, rc = -EINVAL);
962 lov_statfs_interpret(struct ptlrpc_request_set *rqset, void *data, int rc)
964 struct lov_request_set *lovset = (struct lov_request_set *)data;
969 atomic_set(&lovset->set_completes, 0);
971 err = lov_fini_statfs_set(lovset);
972 RETURN(rc ? rc : err);
975 static int lov_statfs_async(struct obd_export *exp, struct obd_info *oinfo,
976 __u64 max_age, struct ptlrpc_request_set *rqset)
978 struct obd_device *obd = class_exp2obd(exp);
979 struct lov_request_set *set;
980 struct lov_request *req;
981 struct list_head *pos;
986 LASSERT(oinfo != NULL);
987 LASSERT(oinfo->oi_osfs != NULL);
990 rc = lov_prep_statfs_set(obd, oinfo, &set);
994 list_for_each(pos, &set->set_list) {
995 req = list_entry(pos, struct lov_request, rq_link);
996 rc = obd_statfs_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
997 &req->rq_oi, max_age, rqset);
1002 if (rc || list_empty(&rqset->set_requests)) {
1005 atomic_set(&set->set_completes, 0);
1006 err = lov_fini_statfs_set(set);
1007 RETURN(rc ? rc : err);
1010 LASSERT(rqset->set_interpret == NULL);
1011 rqset->set_interpret = lov_statfs_interpret;
1012 rqset->set_arg = (void *)set;
1016 static int lov_statfs(const struct lu_env *env, struct obd_export *exp,
1017 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1019 struct ptlrpc_request_set *set = NULL;
1020 struct obd_info oinfo = {
1028 /* for obdclass we forbid using obd_statfs_rqset, but prefer using async
1029 * statfs requests */
1030 set = ptlrpc_prep_set();
1034 rc = lov_statfs_async(exp, &oinfo, max_age, set);
1036 rc = ptlrpc_set_wait(set);
1038 ptlrpc_set_destroy(set);
1043 static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1044 void *karg, void __user *uarg)
1046 struct obd_device *obddev = class_exp2obd(exp);
1047 struct lov_obd *lov = &obddev->u.lov;
1048 int i = 0, rc = 0, count = lov->desc.ld_tgt_count;
1049 struct obd_uuid *uuidp;
1053 case IOC_OBD_STATFS: {
1054 struct obd_ioctl_data *data = karg;
1055 struct obd_device *osc_obd;
1056 struct obd_statfs stat_buf = {0};
1060 memcpy(&index, data->ioc_inlbuf2, sizeof(index));
1061 if ((index >= count))
1064 if (!lov->lov_tgts[index])
1065 /* Try again with the next index */
1067 if (!lov->lov_tgts[index]->ltd_active)
1070 osc_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
1075 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(osc_obd),
1076 min_t(unsigned long, data->ioc_plen2,
1077 sizeof(struct obd_uuid))))
1080 memcpy(&flags, data->ioc_inlbuf1, sizeof(flags));
1081 flags = flags & LL_STATFS_NODELAY ? OBD_STATFS_NODELAY : 0;
1083 /* got statfs data */
1084 rc = obd_statfs(NULL, lov->lov_tgts[index]->ltd_exp, &stat_buf,
1085 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1089 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
1090 min_t(unsigned long, data->ioc_plen1,
1091 sizeof(struct obd_statfs))))
1095 case OBD_IOC_LOV_GET_CONFIG: {
1096 struct obd_ioctl_data *data;
1097 struct lov_desc *desc;
1102 if (obd_ioctl_getdata(&buf, &len, uarg))
1105 data = (struct obd_ioctl_data *)buf;
1107 if (sizeof(*desc) > data->ioc_inllen1) {
1108 obd_ioctl_freedata(buf, len);
1112 if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
1113 obd_ioctl_freedata(buf, len);
1117 if (sizeof(__u32) * count > data->ioc_inllen3) {
1118 obd_ioctl_freedata(buf, len);
1122 desc = (struct lov_desc *)data->ioc_inlbuf1;
1123 memcpy(desc, &(lov->desc), sizeof(*desc));
1125 uuidp = (struct obd_uuid *)data->ioc_inlbuf2;
1126 genp = (__u32 *)data->ioc_inlbuf3;
1127 /* the uuid will be empty for deleted OSTs */
1128 for (i = 0; i < count; i++, uuidp++, genp++) {
1129 if (!lov->lov_tgts[i])
1131 *uuidp = lov->lov_tgts[i]->ltd_uuid;
1132 *genp = lov->lov_tgts[i]->ltd_gen;
1135 if (copy_to_user(uarg, buf, len))
1137 obd_ioctl_freedata(buf, len);
1140 case OBD_IOC_QUOTACTL: {
1141 struct if_quotactl *qctl = karg;
1142 struct lov_tgt_desc *tgt = NULL;
1143 struct obd_quotactl *oqctl;
1145 if (qctl->qc_valid == QC_OSTIDX) {
1146 if (count <= qctl->qc_idx)
1149 tgt = lov->lov_tgts[qctl->qc_idx];
1150 if (!tgt || !tgt->ltd_exp)
1152 } else if (qctl->qc_valid == QC_UUID) {
1153 for (i = 0; i < count; i++) {
1154 tgt = lov->lov_tgts[i];
1156 !obd_uuid_equals(&tgt->ltd_uuid,
1160 if (tgt->ltd_exp == NULL)
1172 LASSERT(tgt && tgt->ltd_exp);
1173 OBD_ALLOC_PTR(oqctl);
1177 QCTL_COPY(oqctl, qctl);
1178 rc = obd_quotactl(tgt->ltd_exp, oqctl);
1180 QCTL_COPY(qctl, oqctl);
1181 qctl->qc_valid = QC_OSTIDX;
1182 qctl->obd_uuid = tgt->ltd_uuid;
1184 OBD_FREE_PTR(oqctl);
1193 for (i = 0; i < count; i++) {
1195 struct obd_device *osc_obd;
1197 /* OST was disconnected */
1198 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_exp)
1201 /* ll_umount_begin() sets force flag but for lov, not
1202 * osc. Let's pass it through */
1203 osc_obd = class_exp2obd(lov->lov_tgts[i]->ltd_exp);
1204 osc_obd->obd_force = obddev->obd_force;
1205 err = obd_iocontrol(cmd, lov->lov_tgts[i]->ltd_exp,
1208 if (lov->lov_tgts[i]->ltd_active) {
1209 CDEBUG(err == -ENOTTY ?
1210 D_IOCTL : D_WARNING,
1211 "iocontrol OSC %s on OST "
1212 "idx %d cmd %x: err = %d\n",
1213 lov_uuid2str(lov, i),
1230 static int lov_get_info(const struct lu_env *env, struct obd_export *exp,
1231 __u32 keylen, void *key, __u32 *vallen, void *val)
1233 struct obd_device *obddev = class_exp2obd(exp);
1234 struct lov_obd *lov = &obddev->u.lov;
1235 struct lov_desc *ld = &lov->desc;
1239 if (vallen == NULL || val == NULL)
1244 if (KEY_IS(KEY_MAX_EASIZE)) {
1245 u32 max_stripe_count = min_t(u32, ld->ld_active_tgt_count,
1246 LOV_MAX_STRIPE_COUNT);
1248 *((u32 *)val) = lov_mds_md_size(max_stripe_count, LOV_MAGIC_V3);
1249 } else if (KEY_IS(KEY_DEFAULT_EASIZE)) {
1250 u32 def_stripe_count = min_t(u32, ld->ld_default_stripe_count,
1251 LOV_MAX_STRIPE_COUNT);
1253 *((u32 *)val) = lov_mds_md_size(def_stripe_count, LOV_MAGIC_V3);
1254 } else if (KEY_IS(KEY_TGT_COUNT)) {
1255 *((int *)val) = lov->desc.ld_tgt_count;
1265 static int lov_set_info_async(const struct lu_env *env, struct obd_export *exp,
1266 __u32 keylen, void *key,
1267 __u32 vallen, void *val,
1268 struct ptlrpc_request_set *set)
1270 struct obd_device *obddev = class_exp2obd(exp);
1271 struct lov_obd *lov = &obddev->u.lov;
1272 struct lov_tgt_desc *tgt;
1273 int do_inactive = 0;
1283 set = ptlrpc_prep_set();
1289 count = lov->desc.ld_tgt_count;
1291 if (KEY_IS(KEY_CHECKSUM)) {
1293 } else if (KEY_IS(KEY_CACHE_SET)) {
1294 LASSERT(lov->lov_cache == NULL);
1295 lov->lov_cache = val;
1297 cl_cache_incref(lov->lov_cache);
1300 for (i = 0; i < count; i++) {
1301 tgt = lov->lov_tgts[i];
1303 /* OST was disconnected */
1304 if (!tgt || !tgt->ltd_exp)
1307 /* OST is inactive and we don't want inactive OSCs */
1308 if (!tgt->ltd_active && !do_inactive)
1311 err = obd_set_info_async(env, tgt->ltd_exp, keylen, key,
1319 err = ptlrpc_set_wait(set);
1322 ptlrpc_set_destroy(set);
1327 void lov_stripe_lock(struct lov_stripe_md *md)
1328 __acquires(&md->lsm_lock)
1330 LASSERT(md->lsm_lock_owner != current_pid());
1331 spin_lock(&md->lsm_lock);
1332 LASSERT(md->lsm_lock_owner == 0);
1333 md->lsm_lock_owner = current_pid();
1336 void lov_stripe_unlock(struct lov_stripe_md *md)
1337 __releases(&md->lsm_lock)
1339 LASSERT(md->lsm_lock_owner == current_pid());
1340 md->lsm_lock_owner = 0;
1341 spin_unlock(&md->lsm_lock);
1344 static int lov_quotactl(struct obd_device *obd, struct obd_export *exp,
1345 struct obd_quotactl *oqctl)
1347 struct lov_obd *lov = &obd->u.lov;
1348 struct lov_tgt_desc *tgt;
1350 __u64 bhardlimit = 0;
1354 if (oqctl->qc_cmd != Q_GETOQUOTA &&
1355 oqctl->qc_cmd != LUSTRE_Q_SETQUOTA) {
1356 CERROR("%s: bad quota opc %x for lov obd\n",
1357 obd->obd_name, oqctl->qc_cmd);
1363 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1366 tgt = lov->lov_tgts[i];
1371 if (!tgt->ltd_active || tgt->ltd_reap) {
1372 if (oqctl->qc_cmd == Q_GETOQUOTA &&
1373 lov->lov_tgts[i]->ltd_activate) {
1375 CERROR("ost %d is inactive\n", i);
1377 CDEBUG(D_HA, "ost %d is inactive\n", i);
1382 err = obd_quotactl(tgt->ltd_exp, oqctl);
1384 if (tgt->ltd_active && !rc)
1389 if (oqctl->qc_cmd == Q_GETOQUOTA) {
1390 curspace += oqctl->qc_dqblk.dqb_curspace;
1391 bhardlimit += oqctl->qc_dqblk.dqb_bhardlimit;
1396 if (oqctl->qc_cmd == Q_GETOQUOTA) {
1397 oqctl->qc_dqblk.dqb_curspace = curspace;
1398 oqctl->qc_dqblk.dqb_bhardlimit = bhardlimit;
1403 static struct obd_ops lov_obd_ops = {
1404 .o_owner = THIS_MODULE,
1405 .o_setup = lov_setup,
1406 .o_cleanup = lov_cleanup,
1407 .o_connect = lov_connect,
1408 .o_disconnect = lov_disconnect,
1409 .o_statfs = lov_statfs,
1410 .o_statfs_async = lov_statfs_async,
1411 .o_iocontrol = lov_iocontrol,
1412 .o_get_info = lov_get_info,
1413 .o_set_info_async = lov_set_info_async,
1414 .o_notify = lov_notify,
1415 .o_pool_new = lov_pool_new,
1416 .o_pool_rem = lov_pool_remove,
1417 .o_pool_add = lov_pool_add,
1418 .o_pool_del = lov_pool_del,
1419 .o_getref = lov_getref,
1420 .o_putref = lov_putref,
1421 .o_quotactl = lov_quotactl,
1424 struct kmem_cache *lov_oinfo_slab;
1426 static int __init lov_init(void)
1428 bool enable_proc = true;
1429 struct obd_type *type;
1433 /* print an address of _any_ initialized kernel symbol from this
1434 * module, to allow debugging with gdb that doesn't support data
1435 * symbols from modules.*/
1436 CDEBUG(D_INFO, "Lustre LOV module (%p).\n", &lov_caches);
1438 rc = lu_kmem_init(lov_caches);
1442 lov_oinfo_slab = kmem_cache_create("lov_oinfo",
1443 sizeof(struct lov_oinfo), 0,
1444 SLAB_HWCACHE_ALIGN, NULL);
1445 if (lov_oinfo_slab == NULL) {
1446 lu_kmem_fini(lov_caches);
1450 type = class_search_type(LUSTRE_LOD_NAME);
1451 if (type != NULL && type->typ_procsym != NULL)
1452 enable_proc = false;
1454 rc = class_register_type(&lov_obd_ops, NULL, enable_proc, NULL,
1455 LUSTRE_LOV_NAME, &lov_device_type);
1458 kmem_cache_destroy(lov_oinfo_slab);
1459 lu_kmem_fini(lov_caches);
1465 static void __exit lov_exit(void)
1467 class_unregister_type(LUSTRE_LOV_NAME);
1468 kmem_cache_destroy(lov_oinfo_slab);
1469 lu_kmem_fini(lov_caches);
1472 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
1473 MODULE_DESCRIPTION("Lustre Logical Object Volume");
1474 MODULE_VERSION(LUSTRE_VERSION_STRING);
1475 MODULE_LICENSE("GPL");
1477 module_init(lov_init);
1478 module_exit(lov_exit);