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.
26 * Copyright (c) 2012, Intel Corporation.
29 * lustre/lod/lod_lov.c
31 * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
35 # define EXPORT_SYMTAB
37 #define DEBUG_SUBSYSTEM S_MDS
39 #include <obd_class.h>
42 #include "lod_internal.h"
45 * Keep a refcount of lod->lod_osts usage to prevent racing with
46 * addition/deletion. Any function that expects lov_tgts to remain stationary
49 * \param lod - is the lod device from which we want to grab a reference
51 void lod_getref(struct lod_device *lod)
53 down_read(&lod->lod_rw_sem);
54 mutex_lock(&lod->lod_mutex);
56 mutex_unlock(&lod->lod_mutex);
60 * Companion of lod_getref() to release a reference on the lod table.
61 * If this is the last reference and the ost entry was scheduled for deletion,
62 * the descriptor is removed from the array.
64 * \param lod - is the lod device from which we release a reference
66 void lod_putref(struct lod_device *lod)
68 mutex_lock(&lod->lod_mutex);
70 if (lod->lod_refcount == 0 && lod->lod_death_row) {
71 struct lod_ost_desc *ost_desc, *tmp;
75 CDEBUG(D_CONFIG, "destroying %d lod desc\n",
78 cfs_foreach_bit(lod->lod_ost_bitmap, idx) {
79 ost_desc = OST_TGT(lod, idx);
82 if (!ost_desc->ltd_reap)
85 cfs_list_add(&ost_desc->ltd_kill, &kill);
87 lod_ost_pool_remove(&lod->lod_pool_info, idx);
88 OST_TGT(lod, idx) = NULL;
90 cfs_bitmap_clear(lod->lod_ost_bitmap, idx);
91 if (ost_desc->ltd_active)
92 lod->lod_desc.ld_active_tgt_count--;
95 mutex_unlock(&lod->lod_mutex);
96 up_read(&lod->lod_rw_sem);
98 cfs_list_for_each_entry_safe(ost_desc, tmp, &kill, ltd_kill) {
100 cfs_list_del(&ost_desc->ltd_kill);
101 /* remove from QoS structures */
102 rc = qos_del_tgt(lod, ost_desc);
104 CERROR("%s: qos_del_tgt(%s) failed: rc = %d\n",
105 lod2obd(lod)->obd_name,
106 obd_uuid2str(&ost_desc->ltd_uuid), rc);
107 rc = obd_disconnect(ost_desc->ltd_exp);
109 CERROR("%s: failed to disconnect %s: rc = %d\n",
110 lod2obd(lod)->obd_name,
111 obd_uuid2str(&ost_desc->ltd_uuid), rc);
112 OBD_FREE_PTR(ost_desc);
115 mutex_unlock(&lod->lod_mutex);
116 up_read(&lod->lod_rw_sem);
120 static int lod_bitmap_resize(struct lod_device *lod, __u32 newsize)
122 cfs_bitmap_t *new_bitmap, *old_bitmap = NULL;
126 /* grab write reference on the lod. Relocating the array requires
127 * exclusive access */
128 down_write(&lod->lod_rw_sem);
130 if (newsize <= lod->lod_osts_size)
131 /* someone else has already resize the array */
134 /* allocate new bitmap */
135 new_bitmap = CFS_ALLOCATE_BITMAP(newsize);
137 GOTO(out, rc = -ENOMEM);
139 if (lod->lod_osts_size > 0) {
140 /* the bitmap already exists, we need
141 * to copy data from old one */
142 cfs_bitmap_copy(new_bitmap, lod->lod_ost_bitmap);
143 old_bitmap = lod->lod_ost_bitmap;
146 lod->lod_osts_size = newsize;
147 lod->lod_ost_bitmap = new_bitmap;
150 CFS_FREE_BITMAP(old_bitmap);
152 CDEBUG(D_CONFIG, "ost size: %d\n", lod->lod_osts_size);
156 up_write(&lod->lod_rw_sem);
161 * Connect LOD to a new OSP and add it to the device table.
163 * \param env - is the environment passed by the caller
164 * \param lod - is the LOD device to be connected to the new OSP
165 * \param osp - is the name of OSP device name about to be added
166 * \param index - is the OSP index
167 * \param gen - is the generation number
169 int lod_add_device(const struct lu_env *env, struct lod_device *lod,
170 char *osp, unsigned index, unsigned gen, int active)
172 struct obd_connect_data *data = NULL;
173 struct obd_export *exp = NULL;
174 struct obd_device *obd;
175 struct lu_device *ldev;
178 struct lod_ost_desc *ost_desc;
179 struct obd_uuid obd_uuid;
183 CDEBUG(D_CONFIG, "osp:%s idx:%d gen:%d\n", osp, index, gen);
186 CERROR("request to add OBD %s with invalid generation: %d\n",
191 obd_str2uuid(&obd_uuid, osp);
193 obd = class_find_client_obd(&obd_uuid, LUSTRE_OSP_NAME,
194 &lod->lod_dt_dev.dd_lu_dev.ld_obd->obd_uuid);
196 CERROR("can't find %s device\n", osp);
204 data->ocd_connect_flags = OBD_CONNECT_INDEX | OBD_CONNECT_VERSION;
205 data->ocd_version = LUSTRE_VERSION_CODE;
206 data->ocd_index = index;
208 rc = obd_connect(env, &exp, obd, &obd->obd_uuid, data, NULL);
211 CERROR("%s: cannot connect to next dev %s (%d)\n",
212 obd->obd_name, osp, rc);
216 LASSERT(obd->obd_lu_dev);
217 LASSERT(obd->obd_lu_dev->ld_site = lod->lod_dt_dev.dd_lu_dev.ld_site);
219 ldev = obd->obd_lu_dev;
222 /* Allocate ost descriptor and fill it */
223 OBD_ALLOC_PTR(ost_desc);
225 GOTO(out_conn, rc = -ENOMEM);
227 ost_desc->ltd_ost = d;
228 ost_desc->ltd_exp = exp;
229 ost_desc->ltd_uuid = obd->u.cli.cl_target_uuid;
230 ost_desc->ltd_gen = gen;
231 ost_desc->ltd_index = index;
232 ost_desc->ltd_active = active;
235 if (index >= lod->lod_osts_size) {
236 /* we have to increase the size of the lod_osts array */
239 newsize = max(lod->lod_osts_size, (__u32)2);
240 while (newsize < index + 1)
241 newsize = newsize << 1;
243 /* lod_bitmap_resize() needs lod_rw_sem
244 * which we hold with th reference */
247 rc = lod_bitmap_resize(lod, newsize);
254 mutex_lock(&lod->lod_mutex);
255 if (cfs_bitmap_check(lod->lod_ost_bitmap, index)) {
256 CERROR("%s: device %d is registered already\n", obd->obd_name,
258 GOTO(out_mutex, rc = -EEXIST);
261 if (lod->lod_ost_idx[index / OST_PTRS_PER_BLOCK] == NULL) {
262 OBD_ALLOC_PTR(lod->lod_ost_idx[index / OST_PTRS_PER_BLOCK]);
263 if (lod->lod_ost_idx[index / OST_PTRS_PER_BLOCK] == NULL) {
264 CERROR("can't allocate index to add %s\n",
266 GOTO(out_mutex, rc = -ENOMEM);
270 rc = lod_ost_pool_add(&lod->lod_pool_info, index, lod->lod_osts_size);
272 CERROR("%s: can't set up pool, failed with %d\n",
277 rc = qos_add_tgt(lod, ost_desc);
279 CERROR("%s: qos_add_tgt(%s) failed: rc = %d\n", obd->obd_name,
280 obd_uuid2str(&ost_desc->ltd_uuid), rc);
284 /* The new OST is now a full citizen */
285 if (index >= lod->lod_desc.ld_tgt_count)
286 lod->lod_desc.ld_tgt_count = index + 1;
288 lod->lod_desc.ld_active_tgt_count++;
289 OST_TGT(lod, index) = ost_desc;
290 cfs_bitmap_set(lod->lod_ost_bitmap, index);
292 mutex_unlock(&lod->lod_mutex);
295 if (lod->lod_recovery_completed)
296 ldev->ld_ops->ldo_recovery_complete(env, ldev);
301 lod_ost_pool_remove(&lod->lod_pool_info, index);
303 mutex_unlock(&lod->lod_mutex);
306 OBD_FREE_PTR(ost_desc);
314 * helper function to schedule OST removal from the device table
316 static void __lod_del_device(struct lod_device *lod, unsigned idx)
318 LASSERT(OST_TGT(lod,idx));
319 if (OST_TGT(lod,idx)->ltd_reap == 0) {
320 OST_TGT(lod,idx)->ltd_reap = 1;
321 lod->lod_death_row++;
326 * Add support for administratively disabled OST (through the MGS).
327 * Schedule a target for deletion. Disconnection and real removal from the
328 * table takes place in lod_putref() once the last table user release its
331 * \param env - is the environment passed by the caller
332 * \param lod - is the lod device currently connected to the OSP about to be
334 * \param osp - is the name of OSP device about to be removed
335 * \param idx - is the OSP index
336 * \param gen - is the generation number, not used currently
338 int lod_del_device(const struct lu_env *env, struct lod_device *lod,
339 char *osp, unsigned idx, unsigned gen)
341 struct obd_device *obd;
343 struct obd_uuid uuid;
346 CDEBUG(D_CONFIG, "osp:%s idx:%d gen:%d\n", osp, idx, gen);
348 obd = class_name2obd(osp);
350 CERROR("can't find %s device\n", osp);
355 CERROR("%s: request to remove OBD %s with invalid generation %d"
356 "\n", obd->obd_name, osp, gen);
360 obd_str2uuid(&uuid, osp);
363 mutex_lock(&lod->lod_mutex);
364 /* check that the index is allocated in the bitmap */
365 if (!cfs_bitmap_check(lod->lod_ost_bitmap, idx) || !OST_TGT(lod,idx)) {
366 CERROR("%s: device %d is not set up\n", obd->obd_name, idx);
367 GOTO(out, rc = -EINVAL);
370 /* check that the UUID matches */
371 if (!obd_uuid_equals(&uuid, &OST_TGT(lod,idx)->ltd_uuid)) {
372 CERROR("%s: LOD target UUID %s at index %d does not match %s\n",
373 obd->obd_name, obd_uuid2str(&OST_TGT(lod,idx)->ltd_uuid),
375 GOTO(out, rc = -EINVAL);
378 __lod_del_device(lod, idx);
381 mutex_unlock(&lod->lod_mutex);
386 int lod_ea_store_resize(struct lod_thread_info *info, int size)
388 int round = size_roundup_power2(size);
390 LASSERT(round <= lov_mds_md_size(LOV_MAX_STRIPE_COUNT, LOV_MAGIC_V3));
391 if (info->lti_ea_store) {
392 LASSERT(info->lti_ea_store_size);
393 LASSERT(info->lti_ea_store_size < round);
394 CDEBUG(D_INFO, "EA store size %d is not enough, need %d\n",
395 info->lti_ea_store_size, round);
396 OBD_FREE_LARGE(info->lti_ea_store, info->lti_ea_store_size);
397 info->lti_ea_store = NULL;
398 info->lti_ea_store_size = 0;
401 OBD_ALLOC_LARGE(info->lti_ea_store, round);
402 if (info->lti_ea_store == NULL)
404 info->lti_ea_store_size = round;
409 * generate and write LOV EA for given striped object
411 int lod_generate_and_set_lovea(const struct lu_env *env,
412 struct lod_object *lo, struct thandle *th)
414 struct lod_thread_info *info = lod_env_info(env);
415 struct dt_object *next = dt_object_child(&lo->ldo_obj);
416 const struct lu_fid *fid = lu_object_fid(&lo->ldo_obj.do_lu);
417 struct lov_mds_md_v1 *lmm;
418 struct lov_ost_data_v1 *objs;
424 LASSERT(lo->ldo_stripenr > 0);
426 magic = lo->ldo_pool ? LOV_MAGIC_V3 : LOV_MAGIC_V1;
427 lmm_size = lov_mds_md_size(lo->ldo_stripenr, magic);
428 if (info->lti_ea_store_size < lmm_size) {
429 rc = lod_ea_store_resize(info, lmm_size);
434 lmm = info->lti_ea_store;
436 lmm->lmm_magic = cpu_to_le32(magic);
437 lmm->lmm_pattern = cpu_to_le32(LOV_PATTERN_RAID0);
438 lmm->lmm_object_id = cpu_to_le64(fid_ver_oid(fid));
439 lmm->lmm_object_seq = cpu_to_le64(fid_seq(fid));
440 lmm->lmm_stripe_size = cpu_to_le32(lo->ldo_stripe_size);
441 lmm->lmm_stripe_count = cpu_to_le16(lo->ldo_stripenr);
442 lmm->lmm_layout_gen = 0;
443 if (magic == LOV_MAGIC_V1) {
444 objs = &lmm->lmm_objects[0];
446 struct lov_mds_md_v3 *v3 = (struct lov_mds_md_v3 *) lmm;
447 strncpy(v3->lmm_pool_name, lo->ldo_pool, LOV_MAXPOOLNAME);
448 objs = &v3->lmm_objects[0];
451 for (i = 0; i < lo->ldo_stripenr; i++) {
452 const struct lu_fid *fid;
454 LASSERT(lo->ldo_stripe[i]);
455 fid = lu_object_fid(&lo->ldo_stripe[i]->do_lu);
457 rc = fid_ostid_pack(fid, &info->lti_ostid);
459 LASSERT(info->lti_ostid.oi_seq == FID_SEQ_OST_MDT0);
461 objs[i].l_object_id = cpu_to_le64(info->lti_ostid.oi_id);
462 objs[i].l_object_seq = cpu_to_le64(info->lti_ostid.oi_seq);
463 objs[i].l_ost_gen = cpu_to_le32(0);
464 objs[i].l_ost_idx = cpu_to_le32(fid_idif_ost_idx(fid));
467 info->lti_buf.lb_buf = lmm;
468 info->lti_buf.lb_len = lmm_size;
469 rc = dt_xattr_set(env, next, &info->lti_buf, XATTR_NAME_LOV, 0,
475 int lod_get_lov_ea(const struct lu_env *env, struct lod_object *lo)
477 struct lod_thread_info *info = lod_env_info(env);
478 struct dt_object *next = dt_object_child(&lo->ldo_obj);
484 if (unlikely(info->lti_ea_store_size == 0)) {
485 /* just to enter in allocation block below */
489 info->lti_buf.lb_buf = info->lti_ea_store;
490 info->lti_buf.lb_len = info->lti_ea_store_size;
491 rc = dt_xattr_get(env, next, &info->lti_buf, XATTR_NAME_LOV,
494 /* if object is not striped or inaccessible */
499 /* EA doesn't fit, reallocate new buffer */
500 rc = dt_xattr_get(env, next, &LU_BUF_NULL, XATTR_NAME_LOV,
508 rc = lod_ea_store_resize(info, rc);
517 int lod_store_def_striping(const struct lu_env *env, struct dt_object *dt,
520 struct lod_thread_info *info = lod_env_info(env);
521 struct lod_object *lo = lod_dt_obj(dt);
522 struct dt_object *next = dt_object_child(dt);
523 struct lov_user_md_v3 *v3;
527 LASSERT(S_ISDIR(dt->do_lu.lo_header->loh_attr));
530 * store striping defaults into new directory
531 * used to implement defaults inheritance
534 /* probably nothing to inherite */
535 if (lo->ldo_striping_cached == 0)
538 if (LOVEA_DELETE_VALUES(lo->ldo_def_stripe_size, lo->ldo_def_stripenr,
539 lo->ldo_def_stripe_offset))
542 /* XXX: use thread info */
547 v3->lmm_magic = cpu_to_le32(LOV_MAGIC_V3);
548 v3->lmm_pattern = cpu_to_le32(LOV_PATTERN_RAID0);
549 v3->lmm_object_id = 0;
550 v3->lmm_object_seq = 0;
551 v3->lmm_stripe_size = cpu_to_le32(lo->ldo_def_stripe_size);
552 v3->lmm_stripe_count = cpu_to_le16(lo->ldo_def_stripenr);
553 v3->lmm_stripe_offset = cpu_to_le16(lo->ldo_def_stripe_offset);
555 strncpy(v3->lmm_pool_name, lo->ldo_pool, LOV_MAXPOOLNAME);
557 info->lti_buf.lb_buf = v3;
558 info->lti_buf.lb_len = sizeof(*v3);
559 rc = dt_xattr_set(env, next, &info->lti_buf, XATTR_NAME_LOV, 0, th,
568 * allocate array of objects pointers, find/create objects
569 * stripenr and other fields should be initialized by this moment
571 int lod_initialize_objects(const struct lu_env *env, struct lod_object *lo,
572 struct lov_ost_data_v1 *objs)
574 struct lod_thread_info *info = lod_env_info(env);
575 struct lod_device *md = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
576 struct lu_object *o, *n;
577 struct lu_device *nd;
582 LASSERT(lo->ldo_stripe == NULL);
583 LASSERT(lo->ldo_stripenr > 0);
584 LASSERT(lo->ldo_stripe_size > 0);
586 i = sizeof(struct dt_object *) * lo->ldo_stripenr;
587 OBD_ALLOC(lo->ldo_stripe, i);
588 if (lo->ldo_stripe == NULL)
589 GOTO(out, rc = -ENOMEM);
590 lo->ldo_stripes_allocated = lo->ldo_stripenr;
592 for (i = 0; i < lo->ldo_stripenr; i++) {
594 info->lti_ostid.oi_id = le64_to_cpu(objs[i].l_object_id);
595 /* XXX: support for DNE? */
596 info->lti_ostid.oi_seq = le64_to_cpu(objs[i].l_object_seq);
597 idx = le64_to_cpu(objs[i].l_ost_idx);
598 fid_ostid_unpack(&info->lti_fid, &info->lti_ostid, idx);
601 * XXX: assertion is left for testing, to make
602 * sure we never process requests till configuration
603 * is completed. to be changed to -EINVAL
607 LASSERT(cfs_bitmap_check(md->lod_ost_bitmap, idx));
608 LASSERT(OST_TGT(md,idx));
609 LASSERTF(OST_TGT(md,idx)->ltd_ost, "idx %d\n", idx);
610 nd = &OST_TGT(md,idx)->ltd_ost->dd_lu_dev;
613 o = lu_object_find_at(env, nd, &info->lti_fid, NULL);
615 GOTO(out, rc = PTR_ERR(o));
617 n = lu_object_locate(o->lo_header, nd->ld_type);
620 lo->ldo_stripe[i] = container_of(n, struct dt_object, do_lu);
628 * Parse striping information stored in lti_ea_store
630 int lod_parse_striping(const struct lu_env *env, struct lod_object *lo,
631 const struct lu_buf *buf)
633 struct lov_mds_md_v1 *lmm;
634 struct lov_ost_data_v1 *objs;
640 LASSERT(buf->lb_buf);
641 LASSERT(buf->lb_len);
643 lmm = (struct lov_mds_md_v1 *) buf->lb_buf;
644 magic = le32_to_cpu(lmm->lmm_magic);
646 if (magic != LOV_MAGIC_V1 && magic != LOV_MAGIC_V3)
647 GOTO(out, rc = -EINVAL);
648 if (le32_to_cpu(lmm->lmm_pattern) != LOV_PATTERN_RAID0)
649 GOTO(out, rc = -EINVAL);
651 lo->ldo_stripe_size = le32_to_cpu(lmm->lmm_stripe_size);
652 lo->ldo_stripenr = le16_to_cpu(lmm->lmm_stripe_count);
653 lo->ldo_layout_gen = le16_to_cpu(lmm->lmm_layout_gen);
655 LASSERT(buf->lb_len >= lov_mds_md_size(lo->ldo_stripenr, magic));
657 if (magic == LOV_MAGIC_V3) {
658 struct lov_mds_md_v3 *v3 = (struct lov_mds_md_v3 *) lmm;
659 objs = &v3->lmm_objects[0];
660 lod_object_set_pool(lo, v3->lmm_pool_name);
662 objs = &lmm->lmm_objects[0];
665 rc = lod_initialize_objects(env, lo, objs);
672 * Load and parse striping information, create in-core representation for the
675 int lod_load_striping(const struct lu_env *env, struct lod_object *lo)
677 struct lod_thread_info *info = lod_env_info(env);
678 struct dt_object *next = dt_object_child(&lo->ldo_obj);
683 * currently this code is supposed to be called from declaration
684 * phase only, thus the object is not expected to be locked by caller
686 dt_write_lock(env, next, 0);
687 /* already initialized? */
688 if (lo->ldo_stripe) {
691 for (i = 0; i < lo->ldo_stripenr; i++)
692 LASSERTF(lo->ldo_stripe[i], "stripe %d is NULL\n", i);
696 if (!dt_object_exists(next))
699 /* only regular files can be striped */
700 if (!(lu_object_attr(lod2lu_obj(lo)) & S_IFREG))
703 LASSERT(lo->ldo_stripenr == 0);
705 rc = lod_get_lov_ea(env, lo);
710 * there is LOV EA (striping information) in this object
711 * let's parse it and create in-core objects for the stripes
713 info->lti_buf.lb_buf = info->lti_ea_store;
714 info->lti_buf.lb_len = info->lti_ea_store_size;
715 rc = lod_parse_striping(env, lo, &info->lti_buf);
717 dt_write_unlock(env, next);
721 int lod_verify_striping(struct lod_device *d, const struct lu_buf *buf,
724 struct lov_user_md_v1 *lum;
725 struct lov_user_md_v3 *v3 = NULL;
726 struct pool_desc *pool = NULL;
732 if (lum->lmm_magic != LOV_USER_MAGIC_V1 &&
733 lum->lmm_magic != LOV_USER_MAGIC_V3 &&
734 lum->lmm_magic != LOV_MAGIC_V1_DEF &&
735 lum->lmm_magic != LOV_MAGIC_V3_DEF) {
736 CDEBUG(D_IOCTL, "bad userland LOV MAGIC: %#x\n",
741 if ((specific && lum->lmm_pattern != LOV_PATTERN_RAID0) ||
742 (specific == 0 && lum->lmm_pattern != 0)) {
743 CDEBUG(D_IOCTL, "bad userland stripe pattern: %#x\n",
748 /* 64kB is the largest common page size we see (ia64), and matches the
750 if (lum->lmm_stripe_size & (LOV_MIN_STRIPE_SIZE - 1)) {
751 CDEBUG(D_IOCTL, "stripe size %u not multiple of %u, fixing\n",
752 lum->lmm_stripe_size, LOV_MIN_STRIPE_SIZE);
756 /* an offset of -1 is treated as a "special" valid offset */
757 if (lum->lmm_stripe_offset != (typeof(lum->lmm_stripe_offset))(-1)) {
758 /* if offset is not within valid range [0, osts_size) */
759 if (lum->lmm_stripe_offset >= d->lod_osts_size) {
760 CDEBUG(D_IOCTL, "stripe offset %u >= bitmap size %u\n",
761 lum->lmm_stripe_offset, d->lod_osts_size);
765 /* if lmm_stripe_offset is *not* in bitmap */
766 if (!cfs_bitmap_check(d->lod_ost_bitmap,
767 lum->lmm_stripe_offset)) {
768 CDEBUG(D_IOCTL, "stripe offset %u not in bitmap\n",
769 lum->lmm_stripe_offset);
774 if (lum->lmm_magic == LOV_USER_MAGIC_V3)
778 pool = lod_find_pool(d, v3->lmm_pool_name);
781 __u16 offs = v3->lmm_stripe_offset;
783 if (offs != (typeof(v3->lmm_stripe_offset))(-1)) {
784 rc = lod_check_index_in_pool(offs, pool);
786 lod_pool_putref(pool);
791 if (specific && lum->lmm_stripe_count > pool_tgt_count(pool)) {
793 "stripe count %u > # OSTs %u in the pool\n",
794 lum->lmm_stripe_count, pool_tgt_count(pool));
795 lod_pool_putref(pool);
799 lod_pool_putref(pool);
805 void lod_fix_desc_stripe_size(__u64 *val)
807 if (*val < PTLRPC_MAX_BRW_SIZE) {
808 LCONSOLE_WARN("Increasing default stripe size to min %u\n",
809 PTLRPC_MAX_BRW_SIZE);
810 *val = PTLRPC_MAX_BRW_SIZE;
811 } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) {
812 *val &= ~(LOV_MIN_STRIPE_SIZE - 1);
813 LCONSOLE_WARN("Changing default stripe size to "LPU64" (a "
815 *val, LOV_MIN_STRIPE_SIZE);
819 void lod_fix_desc_stripe_count(__u32 *val)
825 void lod_fix_desc_pattern(__u32 *val)
827 /* from lov_setstripe */
828 if ((*val != 0) && (*val != LOV_PATTERN_RAID0)) {
829 LCONSOLE_WARN("Unknown stripe pattern: %#x\n", *val);
834 void lod_fix_desc_qos_maxage(__u32 *val)
838 *val = QOS_DEFAULT_MAXAGE;
841 void lod_fix_desc(struct lov_desc *desc)
843 lod_fix_desc_stripe_size(&desc->ld_default_stripe_size);
844 lod_fix_desc_stripe_count(&desc->ld_default_stripe_count);
845 lod_fix_desc_pattern(&desc->ld_pattern);
846 lod_fix_desc_qos_maxage(&desc->ld_qos_maxage);
849 int lod_pools_init(struct lod_device *lod, struct lustre_cfg *lcfg)
851 struct obd_device *obd;
852 struct lov_desc *desc;
856 obd = class_name2obd(lustre_cfg_string(lcfg, 0));
857 LASSERT(obd != NULL);
858 obd->obd_lu_dev = &lod->lod_dt_dev.dd_lu_dev;
860 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
861 CERROR("LOD setup requires a descriptor\n");
865 desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
867 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
868 CERROR("descriptor size wrong: %d > %d\n",
869 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
873 if (desc->ld_magic != LOV_DESC_MAGIC) {
874 if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
875 CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n",
876 obd->obd_name, desc);
877 lustre_swab_lov_desc(desc);
879 CERROR("%s: Bad lov desc magic: %#x\n",
880 obd->obd_name, desc->ld_magic);
887 desc->ld_active_tgt_count = 0;
888 lod->lod_desc = *desc;
890 lod->lod_sp_me = LUSTRE_SP_CLI;
892 /* Set up allocation policy (QoS and RR) */
893 CFS_INIT_LIST_HEAD(&lod->lod_qos.lq_oss_list);
894 init_rwsem(&lod->lod_qos.lq_rw_sem);
895 lod->lod_qos.lq_dirty = 1;
896 lod->lod_qos.lq_rr.lqr_dirty = 1;
897 lod->lod_qos.lq_reset = 1;
898 /* Default priority is toward free space balance */
899 lod->lod_qos.lq_prio_free = 232;
900 /* Default threshold for rr (roughly 17%) */
901 lod->lod_qos.lq_threshold_rr = 43;
902 /* Init statfs fields */
903 OBD_ALLOC_PTR(lod->lod_qos.lq_statfs_data);
904 if (NULL == lod->lod_qos.lq_statfs_data)
906 cfs_waitq_init(&lod->lod_qos.lq_statfs_waitq);
908 /* Set up OST pool environment */
909 lod->lod_pools_hash_body = cfs_hash_create("POOLS", HASH_POOLS_CUR_BITS,
911 HASH_POOLS_BKT_BITS, 0,
914 &pool_hash_operations,
916 if (!lod->lod_pools_hash_body)
917 GOTO(out_statfs, rc = -ENOMEM);
918 CFS_INIT_LIST_HEAD(&lod->lod_pool_list);
919 lod->lod_pool_count = 0;
920 rc = lod_ost_pool_init(&lod->lod_pool_info, 0);
923 rc = lod_ost_pool_init(&lod->lod_qos.lq_rr.lqr_pool, 0);
925 GOTO(out_pool_info, rc);
927 /* the OST array and bitmap are allocated/grown dynamically as OSTs are
928 * added to the LOD, see lod_add_device() */
929 lod->lod_ost_bitmap = NULL;
930 lod->lod_osts_size = 0;
933 lod->lod_death_row = 0;
934 lod->lod_refcount = 0;
939 lod_ost_pool_free(&lod->lod_pool_info);
941 cfs_hash_putref(lod->lod_pools_hash_body);
943 OBD_FREE_PTR(lod->lod_qos.lq_statfs_data);
947 int lod_pools_fini(struct lod_device *lod)
949 struct obd_device *obd = lod2obd(lod);
950 cfs_list_t *pos, *tmp;
951 struct pool_desc *pool;
954 cfs_list_for_each_safe(pos, tmp, &lod->lod_pool_list) {
955 pool = cfs_list_entry(pos, struct pool_desc, pool_list);
956 /* free pool structs */
957 CDEBUG(D_INFO, "delete pool %p\n", pool);
958 lod_pool_del(obd, pool->pool_name);
961 if (lod->lod_osts_size > 0) {
964 mutex_lock(&lod->lod_mutex);
965 cfs_foreach_bit(lod->lod_ost_bitmap, idx)
966 __lod_del_device(lod, idx);
967 mutex_unlock(&lod->lod_mutex);
969 CFS_FREE_BITMAP(lod->lod_ost_bitmap);
970 for (idx = 0; idx < OST_PTRS; idx++) {
971 if (lod->lod_ost_idx[idx])
972 OBD_FREE_PTR(lod->lod_ost_idx[idx]);
974 lod->lod_osts_size = 0;
977 cfs_hash_putref(lod->lod_pools_hash_body);
978 lod_ost_pool_free(&(lod->lod_qos.lq_rr.lqr_pool));
979 lod_ost_pool_free(&lod->lod_pool_info);
980 OBD_FREE_PTR(lod->lod_qos.lq_statfs_data);