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,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License version 2 for more details. A copy is
14 * included in the COPYING file that accompanied this code.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved
24 * Use is subject to license terms.
27 * lustre/lod/lod_lov.c
29 * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
33 # define EXPORT_SYMTAB
35 #define DEBUG_SUBSYSTEM S_MDS
37 #include <obd_class.h>
40 #include "lod_internal.h"
43 * Keep a refcount of lod->lod_osts usage to prevent racing with
44 * addition/deletion. Any function that expects lov_tgts to remain stationary
47 * \param lod - is the lod device from which we want to grab a reference
49 void lod_getref(struct lod_device *lod)
51 down_read(&lod->lod_rw_sem);
52 mutex_lock(&lod->lod_mutex);
54 mutex_unlock(&lod->lod_mutex);
58 * Companion of lod_getref() to release a reference on the lod table.
59 * If this is the last reference and the ost entry was scheduled for deletion,
60 * the descriptor is removed from the array.
62 * \param lod - is the lod device from which we release a reference
64 void lod_putref(struct lod_device *lod)
66 mutex_lock(&lod->lod_mutex);
68 if (lod->lod_refcount == 0 && lod->lod_death_row) {
69 struct lod_ost_desc *ost_desc, *tmp;
73 CDEBUG(D_CONFIG, "destroying %d lod desc\n",
76 cfs_foreach_bit(lod->lod_ost_bitmap, idx) {
77 ost_desc = OST_TGT(lod, idx);
80 if (!ost_desc->ltd_reap)
83 cfs_list_add(&ost_desc->ltd_kill, &kill);
85 lod_ost_pool_remove(&lod->lod_pool_info, idx);
86 OST_TGT(lod, idx) = NULL;
88 cfs_bitmap_clear(lod->lod_ost_bitmap, idx);
89 if (ost_desc->ltd_active)
90 lod->lod_desc.ld_active_tgt_count--;
93 mutex_unlock(&lod->lod_mutex);
94 up_read(&lod->lod_rw_sem);
96 cfs_list_for_each_entry_safe(ost_desc, tmp, &kill, ltd_kill) {
98 cfs_list_del(&ost_desc->ltd_kill);
99 /* remove from QoS structures */
100 rc = qos_del_tgt(lod, ost_desc);
102 CERROR("%s: qos_del_tgt(%s) failed: rc = %d\n",
103 lod2obd(lod)->obd_name,
104 obd_uuid2str(&ost_desc->ltd_uuid), rc);
105 rc = obd_disconnect(ost_desc->ltd_exp);
107 CERROR("%s: failed to disconnect %s: rc = %d\n",
108 lod2obd(lod)->obd_name,
109 obd_uuid2str(&ost_desc->ltd_uuid), rc);
110 OBD_FREE_PTR(ost_desc);
113 mutex_unlock(&lod->lod_mutex);
114 up_read(&lod->lod_rw_sem);
118 static int lod_bitmap_resize(struct lod_device *lod, __u32 newsize)
120 cfs_bitmap_t *new_bitmap, *old_bitmap = NULL;
124 /* grab write reference on the lod. Relocating the array requires
125 * exclusive access */
126 down_write(&lod->lod_rw_sem);
128 if (newsize <= lod->lod_osts_size)
129 /* someone else has already resize the array */
132 /* allocate new bitmap */
133 new_bitmap = CFS_ALLOCATE_BITMAP(newsize);
135 GOTO(out, rc = -ENOMEM);
137 if (lod->lod_osts_size > 0) {
138 /* the bitmap already exists, we need
139 * to copy data from old one */
140 cfs_bitmap_copy(new_bitmap, lod->lod_ost_bitmap);
141 old_bitmap = lod->lod_ost_bitmap;
144 lod->lod_osts_size = newsize;
145 lod->lod_ost_bitmap = new_bitmap;
148 CFS_FREE_BITMAP(old_bitmap);
150 CDEBUG(D_CONFIG, "ost size: %d\n", lod->lod_osts_size);
154 up_write(&lod->lod_rw_sem);
159 * Connect LOD to a new OSP and add it to the device table.
161 * \param env - is the environment passed by the caller
162 * \param lod - is the LOD device to be connected to the new OSP
163 * \param osp - is the name of OSP device name about to be added
164 * \param index - is the OSP index
165 * \param gen - is the generation number
167 int lod_add_device(const struct lu_env *env, struct lod_device *lod,
168 char *osp, unsigned index, unsigned gen, int active)
170 struct obd_connect_data *data = NULL;
171 struct obd_export *exp = NULL;
172 struct obd_device *obd;
173 struct lu_device *ldev;
176 struct lod_ost_desc *ost_desc;
177 struct obd_uuid obd_uuid;
181 CDEBUG(D_CONFIG, "osp:%s idx:%d gen:%d\n", osp, index, gen);
184 CERROR("request to add OBD %s with invalid generation: %d\n",
189 obd_str2uuid(&obd_uuid, osp);
191 obd = class_find_client_obd(&obd_uuid, LUSTRE_OSP_NAME,
192 &lod->lod_dt_dev.dd_lu_dev.ld_obd->obd_uuid);
194 CERROR("can't find %s device\n", osp);
202 data->ocd_connect_flags = OBD_CONNECT_INDEX | OBD_CONNECT_VERSION;
203 data->ocd_version = LUSTRE_VERSION_CODE;
204 data->ocd_index = index;
206 rc = obd_connect(env, &exp, obd, &obd->obd_uuid, data, NULL);
209 CERROR("%s: cannot connect to next dev %s (%d)\n",
210 obd->obd_name, osp, rc);
214 LASSERT(obd->obd_lu_dev);
215 LASSERT(obd->obd_lu_dev->ld_site = lod->lod_dt_dev.dd_lu_dev.ld_site);
217 ldev = obd->obd_lu_dev;
220 /* Allocate ost descriptor and fill it */
221 OBD_ALLOC_PTR(ost_desc);
223 GOTO(out_conn, rc = -ENOMEM);
225 ost_desc->ltd_ost = d;
226 ost_desc->ltd_exp = exp;
227 ost_desc->ltd_uuid = obd->u.cli.cl_target_uuid;
228 ost_desc->ltd_gen = gen;
229 ost_desc->ltd_index = index;
230 ost_desc->ltd_active = active;
233 if (index >= lod->lod_osts_size) {
234 /* we have to increase the size of the lod_osts array */
237 newsize = max(lod->lod_osts_size, (__u32)2);
238 while (newsize < index + 1)
239 newsize = newsize << 1;
241 /* lod_bitmap_resize() needs lod_rw_sem
242 * which we hold with th reference */
245 rc = lod_bitmap_resize(lod, newsize);
252 mutex_lock(&lod->lod_mutex);
253 if (cfs_bitmap_check(lod->lod_ost_bitmap, index)) {
254 CERROR("%s: device %d is registered already\n", obd->obd_name,
256 GOTO(out_mutex, rc = -EEXIST);
259 if (lod->lod_ost_idx[index / OST_PTRS_PER_BLOCK] == NULL) {
260 OBD_ALLOC_PTR(lod->lod_ost_idx[index / OST_PTRS_PER_BLOCK]);
261 if (lod->lod_ost_idx[index / OST_PTRS_PER_BLOCK] == NULL) {
262 CERROR("can't allocate index to add %s\n",
264 GOTO(out_mutex, rc = -ENOMEM);
268 rc = lod_ost_pool_add(&lod->lod_pool_info, index, lod->lod_osts_size);
270 CERROR("%s: can't set up pool, failed with %d\n",
275 rc = qos_add_tgt(lod, ost_desc);
277 CERROR("%s: qos_add_tgt(%s) failed: rc = %d\n", obd->obd_name,
278 obd_uuid2str(&ost_desc->ltd_uuid), rc);
282 /* The new OST is now a full citizen */
283 if (index >= lod->lod_desc.ld_tgt_count)
284 lod->lod_desc.ld_tgt_count = index + 1;
286 lod->lod_desc.ld_active_tgt_count++;
287 OST_TGT(lod, index) = ost_desc;
288 cfs_bitmap_set(lod->lod_ost_bitmap, index);
290 mutex_unlock(&lod->lod_mutex);
293 if (lod->lod_recovery_completed)
294 ldev->ld_ops->ldo_recovery_complete(env, ldev);
299 lod_ost_pool_remove(&lod->lod_pool_info, index);
301 mutex_unlock(&lod->lod_mutex);
304 OBD_FREE_PTR(ost_desc);
312 * helper function to schedule OST removal from the device table
314 static void __lod_del_device(struct lod_device *lod, unsigned idx)
316 LASSERT(OST_TGT(lod,idx));
317 if (OST_TGT(lod,idx)->ltd_reap == 0) {
318 OST_TGT(lod,idx)->ltd_reap = 1;
319 lod->lod_death_row++;
324 * Add support for administratively disabled OST (through the MGS).
325 * Schedule a target for deletion. Disconnection and real removal from the
326 * table takes place in lod_putref() once the last table user release its
329 * \param env - is the environment passed by the caller
330 * \param lod - is the lod device currently connected to the OSP about to be
332 * \param osp - is the name of OSP device about to be removed
333 * \param idx - is the OSP index
334 * \param gen - is the generation number, not used currently
336 int lod_del_device(const struct lu_env *env, struct lod_device *lod,
337 char *osp, unsigned idx, unsigned gen)
339 struct obd_device *obd;
341 struct obd_uuid uuid;
344 CDEBUG(D_CONFIG, "osp:%s idx:%d gen:%d\n", osp, idx, gen);
346 obd = class_name2obd(osp);
348 CERROR("can't find %s device\n", osp);
353 CERROR("%s: request to remove OBD %s with invalid generation %d"
354 "\n", obd->obd_name, osp, gen);
358 obd_str2uuid(&uuid, osp);
361 mutex_lock(&lod->lod_mutex);
362 /* check that the index is allocated in the bitmap */
363 if (!cfs_bitmap_check(lod->lod_ost_bitmap, idx) || !OST_TGT(lod,idx)) {
364 CERROR("%s: device %d is not set up\n", obd->obd_name, idx);
365 GOTO(out, rc = -EINVAL);
368 /* check that the UUID matches */
369 if (!obd_uuid_equals(&uuid, &OST_TGT(lod,idx)->ltd_uuid)) {
370 CERROR("%s: LOD target UUID %s at index %d does not match %s\n",
371 obd->obd_name, obd_uuid2str(&OST_TGT(lod,idx)->ltd_uuid),
373 GOTO(out, rc = -EINVAL);
376 __lod_del_device(lod, idx);
379 mutex_unlock(&lod->lod_mutex);
384 int lod_ea_store_resize(struct lod_thread_info *info, int size)
386 int round = size_roundup_power2(size);
388 LASSERT(round <= lov_mds_md_size(LOV_MAX_STRIPE_COUNT, LOV_MAGIC_V3));
389 if (info->lti_ea_store) {
390 LASSERT(info->lti_ea_store_size);
391 LASSERT(info->lti_ea_store_size < round);
392 CDEBUG(D_INFO, "EA store size %d is not enough, need %d\n",
393 info->lti_ea_store_size, round);
394 OBD_FREE_LARGE(info->lti_ea_store, info->lti_ea_store_size);
395 info->lti_ea_store = NULL;
396 info->lti_ea_store_size = 0;
399 OBD_ALLOC_LARGE(info->lti_ea_store, round);
400 if (info->lti_ea_store == NULL)
402 info->lti_ea_store_size = round;
407 * generate and write LOV EA for given striped object
409 int lod_generate_and_set_lovea(const struct lu_env *env,
410 struct lod_object *lo, struct thandle *th)
412 struct lod_thread_info *info = lod_env_info(env);
413 struct dt_object *next = dt_object_child(&lo->ldo_obj);
414 const struct lu_fid *fid = lu_object_fid(&lo->ldo_obj.do_lu);
415 struct lov_mds_md_v1 *lmm;
416 struct lov_ost_data_v1 *objs;
422 LASSERT(lo->ldo_stripenr > 0);
424 magic = lo->ldo_pool ? LOV_MAGIC_V3 : LOV_MAGIC_V1;
425 lmm_size = lov_mds_md_size(lo->ldo_stripenr, magic);
426 if (info->lti_ea_store_size < lmm_size) {
427 rc = lod_ea_store_resize(info, lmm_size);
432 lmm = info->lti_ea_store;
434 lmm->lmm_magic = cpu_to_le32(magic);
435 lmm->lmm_pattern = cpu_to_le32(LOV_PATTERN_RAID0);
436 lmm->lmm_object_id = cpu_to_le64(fid_ver_oid(fid));
437 lmm->lmm_object_seq = cpu_to_le64(fid_seq(fid));
438 lmm->lmm_stripe_size = cpu_to_le32(lo->ldo_stripe_size);
439 lmm->lmm_stripe_count = cpu_to_le16(lo->ldo_stripenr);
440 lmm->lmm_layout_gen = 0;
441 if (magic == LOV_MAGIC_V1) {
442 objs = &lmm->lmm_objects[0];
444 struct lov_mds_md_v3 *v3 = (struct lov_mds_md_v3 *) lmm;
445 strncpy(v3->lmm_pool_name, lo->ldo_pool, LOV_MAXPOOLNAME);
446 objs = &v3->lmm_objects[0];
449 for (i = 0; i < lo->ldo_stripenr; i++) {
450 const struct lu_fid *fid;
452 LASSERT(lo->ldo_stripe[i]);
453 fid = lu_object_fid(&lo->ldo_stripe[i]->do_lu);
455 rc = fid_ostid_pack(fid, &info->lti_ostid);
457 LASSERT(info->lti_ostid.oi_seq == FID_SEQ_OST_MDT0);
459 objs[i].l_object_id = cpu_to_le64(info->lti_ostid.oi_id);
460 objs[i].l_object_seq = cpu_to_le64(info->lti_ostid.oi_seq);
461 objs[i].l_ost_gen = cpu_to_le32(0);
462 objs[i].l_ost_idx = cpu_to_le32(fid_idif_ost_idx(fid));
465 info->lti_buf.lb_buf = lmm;
466 info->lti_buf.lb_len = lmm_size;
467 rc = dt_xattr_set(env, next, &info->lti_buf, XATTR_NAME_LOV, 0,
473 int lod_get_lov_ea(const struct lu_env *env, struct lod_object *lo)
475 struct lod_thread_info *info = lod_env_info(env);
476 struct dt_object *next = dt_object_child(&lo->ldo_obj);
482 if (unlikely(info->lti_ea_store_size == 0)) {
483 /* just to enter in allocation block below */
487 info->lti_buf.lb_buf = info->lti_ea_store;
488 info->lti_buf.lb_len = info->lti_ea_store_size;
489 rc = dt_xattr_get(env, next, &info->lti_buf, XATTR_NAME_LOV,
492 /* if object is not striped or inaccessible */
497 /* EA doesn't fit, reallocate new buffer */
498 rc = dt_xattr_get(env, next, &LU_BUF_NULL, XATTR_NAME_LOV,
506 rc = lod_ea_store_resize(info, rc);
515 int lod_store_def_striping(const struct lu_env *env, struct dt_object *dt,
518 struct lod_thread_info *info = lod_env_info(env);
519 struct lod_object *lo = lod_dt_obj(dt);
520 struct dt_object *next = dt_object_child(dt);
521 struct lov_user_md_v3 *v3;
525 LASSERT(S_ISDIR(dt->do_lu.lo_header->loh_attr));
528 * store striping defaults into new directory
529 * used to implement defaults inheritance
532 /* probably nothing to inherite */
533 if (lo->ldo_striping_cached == 0)
536 if (LOVEA_DELETE_VALUES(lo->ldo_def_stripe_size, lo->ldo_def_stripenr,
537 lo->ldo_def_stripe_offset))
540 /* XXX: use thread info */
545 v3->lmm_magic = cpu_to_le32(LOV_MAGIC_V3);
546 v3->lmm_pattern = cpu_to_le32(LOV_PATTERN_RAID0);
547 v3->lmm_object_id = 0;
548 v3->lmm_object_seq = 0;
549 v3->lmm_stripe_size = cpu_to_le32(lo->ldo_def_stripe_size);
550 v3->lmm_stripe_count = cpu_to_le16(lo->ldo_def_stripenr);
551 v3->lmm_stripe_offset = cpu_to_le16(lo->ldo_def_stripe_offset);
553 strncpy(v3->lmm_pool_name, lo->ldo_pool, LOV_MAXPOOLNAME);
555 info->lti_buf.lb_buf = v3;
556 info->lti_buf.lb_len = sizeof(*v3);
557 rc = dt_xattr_set(env, next, &info->lti_buf, XATTR_NAME_LOV, 0, th,
566 * allocate array of objects pointers, find/create objects
567 * stripenr and other fields should be initialized by this moment
569 int lod_initialize_objects(const struct lu_env *env, struct lod_object *lo,
570 struct lov_ost_data_v1 *objs)
572 struct lod_thread_info *info = lod_env_info(env);
573 struct lod_device *md = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
574 struct lu_object *o, *n;
575 struct lu_device *nd;
580 LASSERT(lo->ldo_stripe == NULL);
581 LASSERT(lo->ldo_stripenr > 0);
582 LASSERT(lo->ldo_stripe_size > 0);
584 i = sizeof(struct dt_object *) * lo->ldo_stripenr;
585 OBD_ALLOC(lo->ldo_stripe, i);
586 if (lo->ldo_stripe == NULL)
587 GOTO(out, rc = -ENOMEM);
588 lo->ldo_stripes_allocated = lo->ldo_stripenr;
590 for (i = 0; i < lo->ldo_stripenr; i++) {
592 info->lti_ostid.oi_id = le64_to_cpu(objs[i].l_object_id);
593 /* XXX: support for DNE? */
594 info->lti_ostid.oi_seq = le64_to_cpu(objs[i].l_object_seq);
595 idx = le64_to_cpu(objs[i].l_ost_idx);
596 fid_ostid_unpack(&info->lti_fid, &info->lti_ostid, idx);
599 * XXX: assertion is left for testing, to make
600 * sure we never process requests till configuration
601 * is completed. to be changed to -EINVAL
605 LASSERT(cfs_bitmap_check(md->lod_ost_bitmap, idx));
606 LASSERT(OST_TGT(md,idx));
607 LASSERTF(OST_TGT(md,idx)->ltd_ost, "idx %d\n", idx);
608 nd = &OST_TGT(md,idx)->ltd_ost->dd_lu_dev;
611 o = lu_object_find_at(env, nd, &info->lti_fid, NULL);
613 GOTO(out, rc = PTR_ERR(o));
615 n = lu_object_locate(o->lo_header, nd->ld_type);
618 lo->ldo_stripe[i] = container_of(n, struct dt_object, do_lu);
626 * Parse striping information stored in lti_ea_store
628 int lod_parse_striping(const struct lu_env *env, struct lod_object *lo,
629 const struct lu_buf *buf)
631 struct lov_mds_md_v1 *lmm;
632 struct lov_ost_data_v1 *objs;
638 LASSERT(buf->lb_buf);
639 LASSERT(buf->lb_len);
641 lmm = (struct lov_mds_md_v1 *) buf->lb_buf;
642 magic = le32_to_cpu(lmm->lmm_magic);
644 if (magic != LOV_MAGIC_V1 && magic != LOV_MAGIC_V3)
645 GOTO(out, rc = -EINVAL);
646 if (le32_to_cpu(lmm->lmm_pattern) != LOV_PATTERN_RAID0)
647 GOTO(out, rc = -EINVAL);
649 lo->ldo_stripe_size = le32_to_cpu(lmm->lmm_stripe_size);
650 lo->ldo_stripenr = le16_to_cpu(lmm->lmm_stripe_count);
651 lo->ldo_layout_gen = le16_to_cpu(lmm->lmm_layout_gen);
653 LASSERT(buf->lb_len >= lov_mds_md_size(lo->ldo_stripenr, magic));
655 if (magic == LOV_MAGIC_V3) {
656 struct lov_mds_md_v3 *v3 = (struct lov_mds_md_v3 *) lmm;
657 objs = &v3->lmm_objects[0];
658 lod_object_set_pool(lo, v3->lmm_pool_name);
660 objs = &lmm->lmm_objects[0];
663 rc = lod_initialize_objects(env, lo, objs);
670 * Load and parse striping information, create in-core representation for the
673 int lod_load_striping(const struct lu_env *env, struct lod_object *lo)
675 struct lod_thread_info *info = lod_env_info(env);
676 struct dt_object *next = dt_object_child(&lo->ldo_obj);
681 * currently this code is supposed to be called from declaration
682 * phase only, thus the object is not expected to be locked by caller
684 dt_write_lock(env, next, 0);
685 /* already initialized? */
686 if (lo->ldo_stripe) {
689 for (i = 0; i < lo->ldo_stripenr; i++)
690 LASSERTF(lo->ldo_stripe[i], "stripe %d is NULL\n", i);
694 if (!dt_object_exists(next))
697 /* only regular files can be striped */
698 if (!(lu_object_attr(lod2lu_obj(lo)) & S_IFREG))
701 LASSERT(lo->ldo_stripenr == 0);
703 rc = lod_get_lov_ea(env, lo);
708 * there is LOV EA (striping information) in this object
709 * let's parse it and create in-core objects for the stripes
711 info->lti_buf.lb_buf = info->lti_ea_store;
712 info->lti_buf.lb_len = info->lti_ea_store_size;
713 rc = lod_parse_striping(env, lo, &info->lti_buf);
715 dt_write_unlock(env, next);
719 int lod_verify_striping(struct lod_device *d, const struct lu_buf *buf,
722 struct lov_user_md_v1 *lum;
723 struct lov_user_md_v3 *v3 = NULL;
724 struct pool_desc *pool = NULL;
730 if (lum->lmm_magic != LOV_USER_MAGIC_V1 &&
731 lum->lmm_magic != LOV_USER_MAGIC_V3 &&
732 lum->lmm_magic != LOV_MAGIC_V1_DEF &&
733 lum->lmm_magic != LOV_MAGIC_V3_DEF) {
734 CDEBUG(D_IOCTL, "bad userland LOV MAGIC: %#x\n",
739 if ((specific && lum->lmm_pattern != LOV_PATTERN_RAID0) ||
740 (specific == 0 && lum->lmm_pattern != 0)) {
741 CDEBUG(D_IOCTL, "bad userland stripe pattern: %#x\n",
746 /* 64kB is the largest common page size we see (ia64), and matches the
748 if (lum->lmm_stripe_size & (LOV_MIN_STRIPE_SIZE - 1)) {
749 CDEBUG(D_IOCTL, "stripe size %u not multiple of %u, fixing\n",
750 lum->lmm_stripe_size, LOV_MIN_STRIPE_SIZE);
754 /* an offset of -1 is treated as a "special" valid offset */
755 if (lum->lmm_stripe_offset != (typeof(lum->lmm_stripe_offset))(-1)) {
756 /* if offset is not within valid range [0, osts_size) */
757 if (lum->lmm_stripe_offset >= d->lod_osts_size) {
758 CDEBUG(D_IOCTL, "stripe offset %u >= bitmap size %u\n",
759 lum->lmm_stripe_offset, d->lod_osts_size);
763 /* if lmm_stripe_offset is *not* in bitmap */
764 if (!cfs_bitmap_check(d->lod_ost_bitmap,
765 lum->lmm_stripe_offset)) {
766 CDEBUG(D_IOCTL, "stripe offset %u not in bitmap\n",
767 lum->lmm_stripe_offset);
772 if (lum->lmm_magic == LOV_USER_MAGIC_V3)
776 pool = lod_find_pool(d, v3->lmm_pool_name);
779 __u16 offs = v3->lmm_stripe_offset;
781 if (offs != (typeof(v3->lmm_stripe_offset))(-1)) {
782 rc = lod_check_index_in_pool(offs, pool);
784 lod_pool_putref(pool);
789 if (specific && lum->lmm_stripe_count > pool_tgt_count(pool)) {
791 "stripe count %u > # OSTs %u in the pool\n",
792 lum->lmm_stripe_count, pool_tgt_count(pool));
793 lod_pool_putref(pool);
797 lod_pool_putref(pool);
803 void lod_fix_desc_stripe_size(__u64 *val)
805 if (*val < PTLRPC_MAX_BRW_SIZE) {
806 LCONSOLE_WARN("Increasing default stripe size to min %u\n",
807 PTLRPC_MAX_BRW_SIZE);
808 *val = PTLRPC_MAX_BRW_SIZE;
809 } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) {
810 *val &= ~(LOV_MIN_STRIPE_SIZE - 1);
811 LCONSOLE_WARN("Changing default stripe size to "LPU64" (a "
813 *val, LOV_MIN_STRIPE_SIZE);
817 void lod_fix_desc_stripe_count(__u32 *val)
823 void lod_fix_desc_pattern(__u32 *val)
825 /* from lov_setstripe */
826 if ((*val != 0) && (*val != LOV_PATTERN_RAID0)) {
827 LCONSOLE_WARN("Unknown stripe pattern: %#x\n", *val);
832 void lod_fix_desc_qos_maxage(__u32 *val)
836 *val = QOS_DEFAULT_MAXAGE;
839 void lod_fix_desc(struct lov_desc *desc)
841 lod_fix_desc_stripe_size(&desc->ld_default_stripe_size);
842 lod_fix_desc_stripe_count(&desc->ld_default_stripe_count);
843 lod_fix_desc_pattern(&desc->ld_pattern);
844 lod_fix_desc_qos_maxage(&desc->ld_qos_maxage);
847 int lod_pools_init(struct lod_device *lod, struct lustre_cfg *lcfg)
849 struct lprocfs_static_vars lvars = { 0 };
850 struct obd_device *obd;
851 struct lov_desc *desc;
855 obd = class_name2obd(lustre_cfg_string(lcfg, 0));
856 LASSERT(obd != NULL);
857 obd->obd_lu_dev = &lod->lod_dt_dev.dd_lu_dev;
859 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
860 CERROR("LOD setup requires a descriptor\n");
864 desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
866 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
867 CERROR("descriptor size wrong: %d > %d\n",
868 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
872 if (desc->ld_magic != LOV_DESC_MAGIC) {
873 if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
874 CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n",
875 obd->obd_name, desc);
876 lustre_swab_lov_desc(desc);
878 CERROR("%s: Bad lov desc magic: %#x\n",
879 obd->obd_name, desc->ld_magic);
886 desc->ld_active_tgt_count = 0;
887 lod->lod_desc = *desc;
889 lod->lod_sp_me = LUSTRE_SP_CLI;
891 /* Set up allocation policy (QoS and RR) */
892 CFS_INIT_LIST_HEAD(&lod->lod_qos.lq_oss_list);
893 init_rwsem(&lod->lod_qos.lq_rw_sem);
894 lod->lod_qos.lq_dirty = 1;
895 lod->lod_qos.lq_rr.lqr_dirty = 1;
896 lod->lod_qos.lq_reset = 1;
897 /* Default priority is toward free space balance */
898 lod->lod_qos.lq_prio_free = 232;
899 /* Default threshold for rr (roughly 17%) */
900 lod->lod_qos.lq_threshold_rr = 43;
901 /* Init statfs fields */
902 OBD_ALLOC_PTR(lod->lod_qos.lq_statfs_data);
903 if (NULL == lod->lod_qos.lq_statfs_data)
905 cfs_waitq_init(&lod->lod_qos.lq_statfs_waitq);
907 /* Set up OST pool environment */
908 lod->lod_pools_hash_body = cfs_hash_create("POOLS", HASH_POOLS_CUR_BITS,
910 HASH_POOLS_BKT_BITS, 0,
913 &pool_hash_operations,
915 if (!lod->lod_pools_hash_body)
916 GOTO(out_statfs, rc = -ENOMEM);
917 CFS_INIT_LIST_HEAD(&lod->lod_pool_list);
918 lod->lod_pool_count = 0;
919 rc = lod_ost_pool_init(&lod->lod_pool_info, 0);
922 rc = lod_ost_pool_init(&lod->lod_qos.lq_rr.lqr_pool, 0);
924 GOTO(out_pool_info, rc);
926 /* the OST array and bitmap are allocated/grown dynamically as OSTs are
927 * added to the LOD, see lod_add_device() */
928 lod->lod_ost_bitmap = NULL;
929 lod->lod_osts_size = 0;
932 lod->lod_death_row = 0;
933 lod->lod_refcount = 0;
935 lprocfs_lod_init_vars(&lvars);
936 lprocfs_obd_setup(obd, lvars.obd_vars);
939 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
940 0444, &lod_proc_target_fops, obd);
942 CWARN("%s: Error adding the target_obd file %d\n",
946 lod->lod_pool_proc_entry = lprocfs_register("pools",
949 if (IS_ERR(lod->lod_pool_proc_entry)) {
950 int ret = PTR_ERR(lod->lod_pool_proc_entry);
951 lod->lod_pool_proc_entry = NULL;
952 CWARN("%s: Failed to create pool proc file %d\n",
954 rc = lod_pools_fini(lod);
962 lprocfs_obd_cleanup(obd);
963 lod_ost_pool_free(&lod->lod_qos.lq_rr.lqr_pool);
965 lod_ost_pool_free(&lod->lod_pool_info);
967 cfs_hash_putref(lod->lod_pools_hash_body);
969 OBD_FREE_PTR(lod->lod_qos.lq_statfs_data);
973 int lod_pools_fini(struct lod_device *lod)
975 struct obd_device *obd = lod2obd(lod);
976 cfs_list_t *pos, *tmp;
977 struct pool_desc *pool;
980 cfs_list_for_each_safe(pos, tmp, &lod->lod_pool_list) {
981 pool = cfs_list_entry(pos, struct pool_desc, pool_list);
982 /* free pool structs */
983 CDEBUG(D_INFO, "delete pool %p\n", pool);
984 lod_pool_del(obd, pool->pool_name);
987 if (lod->lod_osts_size > 0) {
990 mutex_lock(&lod->lod_mutex);
991 cfs_foreach_bit(lod->lod_ost_bitmap, idx)
992 __lod_del_device(lod, idx);
993 mutex_unlock(&lod->lod_mutex);
995 CFS_FREE_BITMAP(lod->lod_ost_bitmap);
996 for (idx = 0; idx < OST_PTRS; idx++) {
997 if (lod->lod_ost_idx[idx])
998 OBD_FREE_PTR(lod->lod_ost_idx[idx]);
1000 lod->lod_osts_size = 0;
1003 cfs_hash_putref(lod->lod_pools_hash_body);
1004 lod_ost_pool_free(&(lod->lod_qos.lq_rr.lqr_pool));
1005 lod_ost_pool_free(&lod->lod_pool_info);
1007 /* clear pools parent proc entry only after all pools are killed */
1008 if (lod->lod_pool_proc_entry) {
1009 lprocfs_remove(&lod->lod_pool_proc_entry);
1010 lod->lod_pool_proc_entry = NULL;
1013 lprocfs_obd_cleanup(obd);
1015 OBD_FREE_PTR(lod->lod_qos.lq_statfs_data);