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, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/lod/lod_qos.c
33 * Implementation of different allocation algorithm used
34 * to distribute objects and data among OSTs.
37 #define DEBUG_SUBSYSTEM S_LOV
39 #include <asm/div64.h>
40 #include <linux/random.h>
42 #include <libcfs/libcfs.h>
43 #include <uapi/linux/lustre/lustre_idl.h>
44 #include <lustre_swab.h>
45 #include <obd_class.h>
47 #include "lod_internal.h"
49 /* check whether a target is available for new object allocation */
50 static inline int lod_statfs_check(struct lu_tgt_descs *ltd,
51 struct lu_tgt_desc *tgt)
53 struct obd_statfs *sfs = &tgt->ltd_statfs;
55 if (sfs->os_state & OS_STATFS_ENOSPC ||
56 (sfs->os_state & OS_STATFS_ENOINO &&
57 /* OST allocation allowed while precreated objects available */
58 (ltd->ltd_is_mdt || sfs->os_fprecreated == 0)))
61 /* If the OST is readonly then we can't allocate objects there */
62 if (sfs->os_state & OS_STATFS_READONLY)
65 /* object creation is skipped on the OST with max_create_count=0 */
66 if (!ltd->ltd_is_mdt && sfs->os_state & OS_STATFS_NOCREATE)
73 * Check whether the target is available for new objects.
75 * Request statfs data from the given target and verify it's active and not
76 * read-only. If so, then it can be used to place new objects. This
77 * function also maintains the number of active/inactive targets and sets
78 * dirty flags if those numbers change so others can run re-balance procedures.
79 * No external locking is required.
81 * \param[in] env execution environment for this thread
82 * \param[in] d LOD device
83 * \param[in] ltd target table
84 * \param[in] tgt target
86 * \retval 0 if the target is good
87 * \retval negative negated errno on error
89 static int lod_statfs_and_check(const struct lu_env *env, struct lod_device *d,
90 struct lu_tgt_descs *ltd,
91 struct lu_tgt_desc *tgt, __u64 reserve)
93 struct obd_statfs_info info = { 0 };
94 struct lov_desc *desc = <d->ltd_lov_desc;
101 info.os_enable_pre = 1;
102 rc = dt_statfs_info(env, tgt->ltd_tgt, &tgt->ltd_statfs, &info);
103 if (rc && rc != -ENOTCONN)
104 CERROR("%s: statfs error: rc = %d\n", lod2obd(d)->obd_name, rc);
107 rc = lod_statfs_check(ltd, tgt);
109 /* reserving space shouldn't be enough to mark an OST inactive */
111 (reserve + (info.os_reserved_mb_low << 20) >
112 tgt->ltd_statfs.os_bavail * tgt->ltd_statfs.os_bsize))
115 /* check whether device has changed state (active, inactive) */
116 if (rc && tgt->ltd_active) {
117 /* turned inactive? */
118 spin_lock(&d->lod_lock);
119 if (tgt->ltd_active) {
124 LASSERT(desc->ld_active_tgt_count > 0);
125 desc->ld_active_tgt_count--;
126 set_bit(LQ_DIRTY, <d->ltd_qos.lq_flags);
127 CDEBUG(D_CONFIG, "%s: turns inactive\n",
128 tgt->ltd_exp->exp_obd->obd_name);
130 spin_unlock(&d->lod_lock);
131 } else if (rc == 0 && !tgt->ltd_active) {
133 spin_lock(&d->lod_lock);
134 if (!tgt->ltd_active) {
135 LASSERTF(desc->ld_active_tgt_count < desc->ld_tgt_count,
136 "active tgt count %d, tgt nr %d\n",
137 desc->ld_active_tgt_count, desc->ld_tgt_count);
140 desc->ld_active_tgt_count++;
141 set_bit(LQ_DIRTY, <d->ltd_qos.lq_flags);
142 CDEBUG(D_CONFIG, "%s: turns active\n",
143 tgt->ltd_exp->exp_obd->obd_name);
145 spin_unlock(&d->lod_lock);
147 if (rc == -ENOTCONN) {
148 /* In case that the ENOTCONN for inactive OST state is
149 * mistreated as MDT disconnection state by the client,
150 * this error should be changed to someone else.
159 * Maintain per-target statfs data.
161 * The function refreshes statfs data for all the targets every N seconds.
162 * The actual N is controlled via procfs and set to LOV_DESC_QOS_MAXAGE_DEFAULT
165 * \param[in] env execution environment for this thread
166 * \param[in] lod LOD device
167 * \param[in] ltd tgt table
169 void lod_qos_statfs_update(const struct lu_env *env, struct lod_device *lod,
170 struct lu_tgt_descs *ltd)
172 struct obd_device *obd = lod2obd(lod);
173 struct lu_tgt_desc *tgt;
178 max_age = ktime_get_seconds() - 2 * ltd->ltd_lov_desc.ld_qos_maxage;
180 if (obd->obd_osfs_age > max_age)
181 /* statfs data are quite recent, don't need to refresh it */
184 if (test_and_set_bit(LQ_SF_PROGRESS, <d->ltd_qos.lq_flags))
187 if (obd->obd_osfs_age > max_age) {
188 /* statfs data are quite recent, don't need to refresh it */
189 clear_bit(LQ_SF_PROGRESS, <d->ltd_qos.lq_flags);
193 ltd_foreach_tgt(ltd, tgt) {
194 avail = tgt->ltd_statfs.os_bavail;
195 if (lod_statfs_and_check(env, lod, ltd, tgt, 0))
198 if (tgt->ltd_statfs.os_bavail != avail)
199 /* recalculate weigths */
200 set_bit(LQ_DIRTY, <d->ltd_qos.lq_flags);
202 lod_putref(lod, ltd);
203 obd->obd_osfs_age = ktime_get_seconds();
205 clear_bit(LQ_SF_PROGRESS, <d->ltd_qos.lq_flags);
209 #define LOV_QOS_EMPTY ((__u32)-1)
212 * Calculate optimal round-robin order with regard to OSSes.
214 * Place all the OSTs from pool \a src_pool in a special array to be used for
215 * round-robin (RR) stripe allocation. The placement algorithm interleaves
216 * OSTs from the different OSSs so that RR allocation can balance OSSs evenly.
217 * Resorts the targets when the number of active targets changes (because of
218 * a new target or activation/deactivation).
220 * \param[in] lod LOD device
221 * \param[in] ltd tgt table
222 * \param[in] src_pool tgt pool
223 * \param[in] lqr round-robin list
225 * \retval 0 on success
226 * \retval -ENOMEM fails to allocate the array
228 static int lod_qos_calc_rr(struct lod_device *lod, struct lu_tgt_descs *ltd,
229 const struct lu_tgt_pool *src_pool,
230 struct lu_qos_rr *lqr)
232 struct lu_svr_qos *svr;
233 struct lu_tgt_desc *tgt;
234 unsigned placed, real_count;
239 if (!test_bit(LQ_DIRTY, &lqr->lqr_flags)) {
240 LASSERT(lqr->lqr_pool.op_size);
244 /* Do actual allocation. */
245 down_write(<d->ltd_qos.lq_rw_sem);
248 * Check again. While we were sleeping on @lq_rw_sem something could
251 if (!test_bit(LQ_DIRTY, &lqr->lqr_flags)) {
252 LASSERT(lqr->lqr_pool.op_size);
253 up_write(<d->ltd_qos.lq_rw_sem);
257 real_count = src_pool->op_count;
259 /* Zero the pool array */
260 /* alloc_rr is holding a read lock on the pool, so nobody is adding/
261 deleting from the pool. The lq_rw_sem insures that nobody else
263 lqr->lqr_pool.op_count = real_count;
264 rc = lu_tgt_pool_extend(&lqr->lqr_pool, real_count);
266 up_write(<d->ltd_qos.lq_rw_sem);
269 for (i = 0; i < lqr->lqr_pool.op_count; i++)
270 lqr->lqr_pool.op_array[i] = LOV_QOS_EMPTY;
272 /* Place all the tgts from 1 svr at the same time. */
274 list_for_each_entry(svr, <d->ltd_qos.lq_svr_list, lsq_svr_list) {
277 for (i = 0; i < lqr->lqr_pool.op_count; i++) {
280 if (!test_bit(src_pool->op_array[i],
281 ltd->ltd_tgt_bitmap))
284 tgt = LTD_TGT(ltd, src_pool->op_array[i]);
285 LASSERT(tgt && tgt->ltd_tgt);
286 if (tgt->ltd_qos.ltq_svr != svr)
289 /* Evenly space these tgts across arrayspace */
290 next = j * lqr->lqr_pool.op_count / svr->lsq_tgt_count;
291 while (lqr->lqr_pool.op_array[next] != LOV_QOS_EMPTY)
292 next = (next + 1) % lqr->lqr_pool.op_count;
294 lqr->lqr_pool.op_array[next] = src_pool->op_array[i];
300 clear_bit(LQ_DIRTY, &lqr->lqr_flags);
301 up_write(<d->ltd_qos.lq_rw_sem);
303 if (placed != real_count) {
304 /* This should never happen */
305 LCONSOLE_ERROR_MSG(0x14e, "Failed to place all tgts in the "
306 "round-robin list (%d of %d).\n",
308 for (i = 0; i < lqr->lqr_pool.op_count; i++) {
309 LCONSOLE(D_WARNING, "rr #%d tgt idx=%d\n", i,
310 lqr->lqr_pool.op_array[i]);
312 set_bit(LQ_DIRTY, &lqr->lqr_flags);
320 * Instantiate and declare creation of a new object.
322 * The function instantiates LU representation for a new object on the
323 * specified device. Also it declares an intention to create that
324 * object on the storage target.
326 * Note lu_object_anon() is used which is a trick with regard to LU/OSD
327 * infrastructure - in the existing precreation framework we can't assign FID
328 * at this moment, we do this later once a transaction is started. So the
329 * special method instantiates FID-less object in the cache and later it
330 * will get a FID and proper placement in LU cache.
332 * \param[in] env execution environment for this thread
333 * \param[in] d LOD device
334 * \param[in] ost_idx OST target index where the object is being created
335 * \param[in] th transaction handle
337 * \retval object ptr on success, ERR_PTR() otherwise
339 static struct dt_object *lod_qos_declare_object_on(const struct lu_env *env,
340 struct lod_device *d,
345 struct dt_allocation_hint *ah = &lod_env_info(env)->lti_ah;
346 struct lod_tgt_desc *ost;
347 struct lu_object *o, *n;
348 struct lu_device *nd;
349 struct dt_object *dt;
354 LASSERT(ost_idx < d->lod_ost_descs.ltd_tgts_size);
355 ost = OST_TGT(d,ost_idx);
357 LASSERT(ost->ltd_tgt);
359 nd = &ost->ltd_tgt->dd_lu_dev;
362 * allocate anonymous object with zero fid, real fid
363 * will be assigned by OSP within transaction
364 * XXX: to be fixed with fully-functional OST fids
366 o = lu_object_anon(env, nd, NULL);
368 GOTO(out, dt = ERR_CAST(o));
370 n = lu_object_locate(o->lo_header, nd->ld_type);
371 if (unlikely(n == NULL)) {
372 CERROR("can't find slice\n");
373 lu_object_put(env, o);
374 GOTO(out, dt = ERR_PTR(-EINVAL));
377 dt = container_of(n, struct dt_object, do_lu);
379 ah->dah_can_block = can_block;
380 rc = lod_sub_declare_create(env, dt, NULL, ah, NULL, th);
382 CDEBUG(D_OTHER, "can't declare creation on #%u: %d\n",
384 lu_object_put(env, o);
393 * Calculate a minimum acceptable stripe count.
395 * Return an acceptable stripe count depending on flag LOD_USES_DEFAULT_STRIPE:
396 * all stripes or 3/4 of stripes. The code is written this way to avoid
397 * returning 0 for stripe_count < 4, like "stripe_count * 3 / 4" would do.
399 * \param[in] stripe_count number of stripes requested
400 * \param[in] flags 0 or LOD_USES_DEFAULT_STRIPE
402 * \retval acceptable stripecount
404 static int lod_stripe_count_min(__u32 stripe_count, enum lod_uses_hint flags)
406 return (flags & LOD_USES_DEFAULT_STRIPE ?
407 stripe_count - (stripe_count / 4) : stripe_count);
410 #define LOV_CREATE_RESEED_MULT 30
411 #define LOV_CREATE_RESEED_MIN 2000
414 * Initialize temporary tgt-in-use array.
416 * Allocate or extend the array used to mark targets already assigned to a new
417 * striping so they are not used more than once.
419 * \param[in] env execution environment for this thread
420 * \param[in] stripes number of items needed in the array
422 * \retval 0 on success
423 * \retval -ENOMEM on error
425 static inline int lod_qos_tgt_in_use_clear(const struct lu_env *env,
428 struct lod_thread_info *info = lod_env_info(env);
430 if (info->lti_ea_store_size < sizeof(int) * stripes)
431 lod_ea_store_resize(info, stripes * sizeof(int));
432 if (info->lti_ea_store_size < sizeof(int) * stripes) {
433 CERROR("can't allocate memory for tgt-in-use array\n");
436 memset(info->lti_ea_store, -1, sizeof(int) * stripes);
441 * Remember a target in the array of used targets.
443 * Mark the given target as used for a new striping being created. The status
444 * of an tgt in a striping can be checked with lod_qos_is_tgt_used().
446 * \param[in] env execution environment for this thread
447 * \param[in] idx index in the array
448 * \param[in] tgt_idx target index to mark as used
450 static inline void lod_qos_tgt_in_use(const struct lu_env *env,
451 int idx, int tgt_idx)
453 struct lod_thread_info *info = lod_env_info(env);
454 int *tgts = info->lti_ea_store;
456 LASSERT(info->lti_ea_store_size >= idx * sizeof(int));
461 * Check is tgt used in a striping.
463 * Checks whether tgt with the given index is marked as used in the temporary
464 * array (see lod_qos_tgt_in_use()).
466 * \param[in] env execution environment for this thread
467 * \param[in] tgt_idx target index to check
468 * \param[in] stripes the number of items used in the array already
473 static int lod_qos_is_tgt_used(const struct lu_env *env, int tgt_idx,
476 struct lod_thread_info *info = lod_env_info(env);
477 int *tgts = info->lti_ea_store;
480 for (j = 0; j < stripes; j++) {
481 if (tgts[j] == tgt_idx)
488 lod_obj_is_ost_use_skip_cb(const struct lu_env *env, struct lod_object *lo,
489 int comp_idx, struct lod_obj_stripe_cb_data *data)
491 struct lod_layout_component *comp = &lo->ldo_comp_entries[comp_idx];
493 return comp->llc_ost_indices == NULL;
497 lod_obj_is_ost_use_cb(const struct lu_env *env, struct lod_object *lo,
498 int comp_idx, struct lod_obj_stripe_cb_data *data)
500 struct lod_layout_component *comp = &lo->ldo_comp_entries[comp_idx];
503 for (i = 0; i < comp->llc_stripe_count; i++) {
504 if (comp->llc_ost_indices[i] == data->locd_ost_index) {
505 data->locd_ost_index = -1;
514 * Check is OST used in a composite layout
516 * \param[in] lo lod object
517 * \param[in] ost OST target index to check
519 * \retval false not used
522 static inline bool lod_comp_is_ost_used(const struct lu_env *env,
523 struct lod_object *lo, int ost)
525 struct lod_obj_stripe_cb_data data = { { 0 } };
527 data.locd_ost_index = ost;
528 data.locd_comp_skip_cb = lod_obj_is_ost_use_skip_cb;
529 data.locd_comp_cb = lod_obj_is_ost_use_cb;
531 (void)lod_obj_for_each_stripe(env, lo, NULL, &data);
533 return data.locd_ost_index == -1;
536 static inline void lod_avoid_update(struct lod_object *lo,
537 struct lod_avoid_guide *lag)
542 lag->lag_ost_avail--;
545 static inline bool lod_should_avoid_ost(struct lod_object *lo,
546 struct lod_avoid_guide *lag,
549 struct lod_device *lod = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
550 struct lod_tgt_desc *ost = OST_TGT(lod, index);
551 struct lu_svr_qos *lsq = ost->ltd_qos.ltq_svr;
555 if (!test_bit(index, lod->lod_ost_bitmap)) {
556 CDEBUG(D_OTHER, "OST%d: been used in conflicting mirror component\n",
562 * we've tried our best, all available OSTs have been used in
563 * overlapped components in the other mirror
565 if (lag->lag_ost_avail == 0)
569 for (i = 0; i < lag->lag_oaa_count; i++) {
570 if (lag->lag_oss_avoid_array[i] == lsq->lsq_id) {
576 * if the OSS which OST[index] resides has not been used, we'd like to
582 /* if the OSS has been used, check whether the OST has been used */
583 if (!test_bit(index, lag->lag_ost_avoid_bitmap))
586 CDEBUG(D_OTHER, "OST%d: been used in conflicting mirror component\n",
591 static int lod_check_and_reserve_ost(const struct lu_env *env,
592 struct lod_object *lo,
593 struct lod_layout_component *lod_comp,
594 __u32 ost_idx, __u32 speed, __u32 *s_idx,
595 struct dt_object **stripe,
601 struct lod_device *lod = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
602 struct lod_avoid_guide *lag = &lod_env_info(env)->lti_avoid;
603 struct lu_tgt_desc *ost = OST_TGT(lod, ost_idx);
605 __u32 stripe_idx = *s_idx;
610 rc = lod_statfs_and_check(env, lod, &lod->lod_ost_descs, ost, reserve);
615 * We expect number of precreated objects in f_ffree at
616 * the first iteration, skip OSPs with no objects ready
618 if (ost->ltd_statfs.os_fprecreated == 0 && speed == 0) {
619 CDEBUG(D_OTHER, "#%d: precreation is empty\n", ost_idx);
624 * try to use another OSP if this one is degraded
626 if (ost->ltd_statfs.os_state & OS_STATFS_DEGRADED && speed < 2) {
627 CDEBUG(D_OTHER, "#%d: degraded\n", ost_idx);
632 * try not allocate on OST which has been used by other
635 if (speed == 0 && lod_comp_is_ost_used(env, lo, ost_idx)) {
636 CDEBUG(D_OTHER, "iter %d: OST%d used by other component\n",
642 * try not allocate OSTs used by conflicting component of other mirrors
643 * for the first and second time.
645 if (speed < 2 && lod_should_avoid_ost(lo, lag, ost_idx)) {
646 CDEBUG(D_OTHER, "iter %d: OST%d used by conflicting mirror component\n",
651 /* do not put >1 objects on a single OST, except for overstriping */
652 if (lod_qos_is_tgt_used(env, ost_idx, stripe_idx)) {
653 if (lod_comp->llc_pattern & LOV_PATTERN_OVERSTRIPING)
659 o = lod_qos_declare_object_on(env, lod, ost_idx, (speed > 1), th);
661 CDEBUG(D_OTHER, "can't declare new object on #%u: %d\n",
662 ost_idx, (int) PTR_ERR(o));
668 * We've successfully declared (reserved) an object
670 lod_avoid_update(lo, lag);
671 lod_qos_tgt_in_use(env, stripe_idx, ost_idx);
672 stripe[stripe_idx] = o;
673 ost_indices[stripe_idx] = ost_idx;
674 CFS_FAIL_TIMEOUT(OBD_FAIL_MDS_LOV_CREATE_RACE, 2);
682 * Allocate a striping using round-robin algorithm.
684 * Allocates a new striping using round-robin algorithm. The function refreshes
685 * all the internal structures (statfs cache, array of available OSTs sorted
686 * with regard to OSS, etc). The number of stripes required is taken from the
687 * object (must be prepared by the caller), but can change if the flag
688 * LOD_USES_DEFAULT_STRIPE is supplied. The caller should ensure nobody else
689 * is trying to create a striping on the object in parallel. All the internal
690 * structures (like pools, etc) are protected and no additional locking is
691 * required. The function succeeds even if a single stripe is allocated. To save
692 * time we give priority to targets which already have objects precreated.
693 * Full OSTs are skipped (see lod_qos_dev_is_full() for the details).
695 * \param[in] env execution environment for this thread
696 * \param[in] lo LOD object
697 * \param[out] stripe striping created
698 * \param[out] ost_indices ost indices of striping created
699 * \param[in] flags allocation flags (0 or LOD_USES_DEFAULT_STRIPE)
700 * \param[in] th transaction handle
701 * \param[in] comp_idx index of ldo_comp_entries
703 * \retval 0 on success
704 * \retval -ENOSPC if not enough OSTs are found
705 * \retval negative negated errno for other failures
707 static int lod_ost_alloc_rr(const struct lu_env *env, struct lod_object *lo,
708 struct dt_object **stripe, __u32 *ost_indices,
709 enum lod_uses_hint flags, struct thandle *th,
710 int comp_idx, __u64 reserve)
712 struct lod_layout_component *lod_comp;
713 struct lod_device *m = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
714 struct lod_pool_desc *pool = NULL;
715 struct lu_tgt_pool *osts;
716 struct lu_qos_rr *lqr;
717 unsigned int i, array_idx;
718 __u32 stripe_idx = 0;
719 __u32 stripe_count, stripe_count_min, ost_idx;
720 int rc, speed = 0, ost_connecting = 0;
721 int idx, stripes_per_ost = 1;
722 bool overstriped = false;
725 LASSERT(lo->ldo_comp_cnt > comp_idx && lo->ldo_comp_entries != NULL);
726 lod_comp = &lo->ldo_comp_entries[comp_idx];
727 stripe_count = lod_comp->llc_stripe_count;
728 stripe_count_min = lod_stripe_count_min(stripe_count, flags);
730 if (lod_comp->llc_pool != NULL)
731 pool = lod_find_pool(m, lod_comp->llc_pool);
734 down_read(&pool_tgt_rw_sem(pool));
735 osts = &(pool->pool_obds);
736 lqr = &(pool->pool_rr);
738 osts = &m->lod_ost_descs.ltd_tgt_pool;
739 lqr = &(m->lod_ost_descs.ltd_qos.lq_rr);
742 rc = lod_qos_calc_rr(m, &m->lod_ost_descs, osts, lqr);
746 rc = lod_qos_tgt_in_use_clear(env, stripe_count);
750 down_read(&m->lod_ost_descs.ltd_qos.lq_rw_sem);
751 spin_lock(&lqr->lqr_alloc);
752 if (--lqr->lqr_start_count <= 0) {
753 atomic_set(&lqr->lqr_start_idx,
754 get_random_u32_below(osts->op_count));
755 lqr->lqr_start_count =
756 (LOV_CREATE_RESEED_MIN / max(osts->op_count, 1U) +
757 LOV_CREATE_RESEED_MULT) * max(osts->op_count, 1U);
758 } else if (atomic_read(&lqr->lqr_start_idx) >= osts->op_count) {
759 /* If we have allocated from all of the tgts, slowly
760 * precess the next start OST if the tgt/stripe count
761 * difference isn't already doing this for us.
763 atomic_sub(osts->op_count, &lqr->lqr_start_idx);
764 if (stripe_count > 1 && (osts->op_count % stripe_count) != 1)
765 ++lqr->lqr_offset_idx;
767 spin_unlock(&lqr->lqr_alloc);
768 if (lod_comp->llc_pattern & LOV_PATTERN_OVERSTRIPING)
770 (lod_comp->llc_stripe_count - 1) / osts->op_count + 1;
773 CDEBUG(D_OTHER, "pool '%s' want %d start_idx %d start_count %d offset %d active %d count %d\n",
774 lod_comp->llc_pool ? lod_comp->llc_pool : "",
775 stripe_count, atomic_read(&lqr->lqr_start_idx),
776 lqr->lqr_start_count, lqr->lqr_offset_idx, osts->op_count,
779 for (i = 0, idx = 0; i < osts->op_count * stripes_per_ost &&
780 stripe_idx < stripe_count; i++) {
781 if (likely(speed < 2) || i == 0) {
782 idx = atomic_inc_return(&lqr->lqr_start_idx) +
786 * For last speed, use OSTs one by one
790 array_idx = idx % osts->op_count;
791 ost_idx = lqr->lqr_pool.op_array[array_idx];
793 CDEBUG(D_OTHER, "#%d strt %d act %d strp %d ary %d idx %d\n",
794 i, idx, /* XXX: active*/ 0,
795 stripe_idx, array_idx, ost_idx);
797 if ((ost_idx == LOV_QOS_EMPTY) ||
798 !test_bit(ost_idx, m->lod_ost_bitmap))
801 /* Fail Check before osc_precreate() is called
802 so we can only 'fail' single OSC. */
803 if (CFS_FAIL_CHECK(OBD_FAIL_MDS_OSC_PRECREATE) && ost_idx == 0)
806 if (CFS_FAIL_PRECHECK(OBD_FAIL_MDS_LOD_CREATE_PAUSE)) {
807 clear_bit(LQ_SAME_SPACE,
808 &m->lod_ost_descs.ltd_qos.lq_flags);
809 CFS_FAIL_TIMEOUT(OBD_FAIL_MDS_LOD_CREATE_PAUSE,
812 rc = lod_check_and_reserve_ost(env, lo, lod_comp, ost_idx,
813 speed, &stripe_idx, stripe,
814 ost_indices, th, &overstriped,
817 if (rc != 0 && OST_TGT(m, ost_idx)->ltd_discon)
820 if ((speed < 2) && (stripe_idx < stripe_count_min)) {
821 /* Try again, allowing slower OSCs */
827 up_read(&m->lod_ost_descs.ltd_qos.lq_rw_sem);
829 /* If there are enough OSTs, a component with overstriping requested
830 * will not actually end up overstriped. The comp should reflect this.
833 lod_comp->llc_pattern &= ~LOV_PATTERN_OVERSTRIPING;
836 lod_comp->llc_stripe_count = stripe_idx;
837 /* at least one stripe is allocated */
840 /* nobody provided us with a single object */
849 up_read(&pool_tgt_rw_sem(pool));
850 /* put back ref got by lod_find_pool() */
851 lod_pool_putref(pool);
858 lod_qos_mdt_in_use_init(const struct lu_env *env,
859 const struct lu_tgt_descs *ltd,
860 u32 stripe_idx, u32 stripe_count,
861 const struct lu_tgt_pool *pool,
862 struct dt_object **stripes)
865 struct lu_tgt_desc *mdt;
869 rc = lod_qos_tgt_in_use_clear(env, stripe_count);
873 /* if stripe_idx > 1, we are splitting directory, mark existing stripes
874 * in_use. Because for either split or creation, stripe 0 is local,
875 * don't mark it in use.
877 for (i = 1; i < stripe_idx; i++) {
879 for (j = 0; j < pool->op_count; j++) {
880 mdt_idx = pool->op_array[j];
882 if (!test_bit(mdt_idx, ltd->ltd_tgt_bitmap))
885 mdt = LTD_TGT(ltd, mdt_idx);
886 if (&mdt->ltd_tgt->dd_lu_dev ==
887 stripes[i]->do_lu.lo_dev)
888 lod_qos_tgt_in_use(env, i, mdt_idx);
896 * Allocate a striping using round-robin algorithm.
898 * Allocates a new striping using round-robin algorithm. The function refreshes
899 * all the internal structures (statfs cache, array of available remote MDTs
900 * sorted with regard to MDS, etc). The number of stripes required is taken from
901 * the object (must be prepared by the caller). The caller should ensure nobody
902 * else is trying to create a striping on the object in parallel. All the
903 * internal structures (like pools, etc) are protected and no additional locking
904 * is required. The function succeeds even if a single stripe is allocated.
906 * \param[in] env execution environment for this thread
907 * \param[in] lo LOD object
908 * \param[out] stripes striping created
910 * \retval positive stripe objects allocated, including the first stripe
912 * \retval -ENOSPC if not enough MDTs are found
913 * \retval negative negated errno for other failures
915 int lod_mdt_alloc_rr(const struct lu_env *env, struct lod_object *lo,
916 struct dt_object **stripes, u32 stripe_idx,
919 struct lod_device *lod = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
920 struct lu_tgt_descs *ltd = &lod->lod_mdt_descs;
921 struct lu_tgt_pool *pool;
922 struct lu_qos_rr *lqr;
923 struct lu_object_conf conf = { .loc_flags = LOC_F_NEW };
924 struct lu_fid fid = { 0 };
925 struct dt_object *dto;
926 unsigned int pool_idx;
928 u32 saved_idx = stripe_idx;
929 int stripes_per_mdt = 1;
931 bool use_degraded = false;
932 bool overstriped = false;
933 int tgt_connecting = 0;
938 pool = <d->ltd_tgt_pool;
939 lqr = <d->ltd_qos.lq_rr;
940 rc = lod_qos_calc_rr(lod, ltd, pool, lqr);
944 overstriped = lo->ldo_dir_hash_type & LMV_HASH_FLAG_OVERSTRIPED;
946 if (stripe_count > lod->lod_remote_mdt_count + 1 && !overstriped)
949 if (lo->ldo_dir_hash_type & LMV_HASH_FLAG_OVERSTRIPED)
950 stripes_per_mdt = stripe_count / (pool->op_count + 1);
952 rc = lod_qos_mdt_in_use_init(env, ltd, stripe_idx, stripe_count, pool,
957 down_read(<d->ltd_qos.lq_rw_sem);
958 spin_lock(&lqr->lqr_alloc);
959 if (--lqr->lqr_start_count <= 0) {
960 atomic_set(&lqr->lqr_start_idx,
961 get_random_u32_below(pool->op_count));
962 lqr->lqr_start_count =
963 (LOV_CREATE_RESEED_MIN / max(pool->op_count, 1U) +
964 LOV_CREATE_RESEED_MULT) * max(pool->op_count, 1U);
965 } else if (atomic_read(&lqr->lqr_start_idx) >= pool->op_count) {
966 /* If we have allocated from all of the tgts, slowly
967 * precess the next start if the tgt/stripe count isn't
968 * already doing this for us.
970 atomic_sub(pool->op_count, &lqr->lqr_start_idx);
971 if (stripe_count - 1 > 1 &&
972 (pool->op_count % (stripe_count - 1)) != 1)
973 ++lqr->lqr_offset_idx;
975 spin_unlock(&lqr->lqr_alloc);
979 "want=%d start_idx=%d start_count=%d offset=%d active=%d count=%d\n",
980 stripe_count - 1, atomic_read(&lqr->lqr_start_idx),
981 lqr->lqr_start_count, lqr->lqr_offset_idx,
982 /* if we're overstriped, the local MDT is available and is
983 * included in the count
985 pool->op_count + overstriped,
986 lqr->lqr_pool.op_count + overstriped);
988 for (i = 0; i < (pool->op_count + overstriped) * stripes_per_mdt &&
989 stripe_idx < stripe_count; i++) {
990 struct lu_tgt_desc *mdt = NULL;
991 struct dt_device *mdt_tgt;
992 bool local_alloc = false;
995 idx = atomic_inc_return(&lqr->lqr_start_idx);
996 pool_idx = (idx + lqr->lqr_offset_idx) %
997 (pool->op_count + overstriped);
998 /* in the overstriped case, we must be able to allocate a stripe
999 * to the local MDT, ie, the one doing the allocation
1001 if (pool_idx == pool->op_count) {
1002 LASSERT(overstriped);
1003 /* because there is already a stripe on the local MDT,
1004 * do not allocate from the local MDT until we've
1005 * allocated at least as many stripes as we have MDTs
1007 if (stripe_idx < (pool->op_count + 1)) {
1009 "Skipping local alloc, not enough stripes yet\n");
1012 CDEBUG(D_OTHER, "Attempting to allocate locally\n");
1014 mdt_tgt = lod->lod_child;
1015 rc = lodname2mdt_index(lod2obd(lod)->obd_name,
1017 /* this parsing can't fail here because we're working
1018 * with a known-good MDT
1022 mdt_idx = lqr->lqr_pool.op_array[pool_idx];
1023 mdt = LTD_TGT(ltd, mdt_idx);
1024 mdt_tgt = mdt->ltd_tgt;
1027 CDEBUG(D_OTHER, "#%d strt %d act %d strp %d ary %d idx %d\n",
1028 i, idx, /* XXX: active*/ 0,
1029 stripe_idx, pool_idx, mdt_idx);
1031 if (!local_alloc && (mdt_idx == LOV_QOS_EMPTY ||
1032 !test_bit(mdt_idx, ltd->ltd_tgt_bitmap))) {
1033 CDEBUG(D_OTHER, "mdt_idx not found %d\n", mdt_idx);
1037 /* do not put >1 objects on one MDT, except for overstriping */
1039 if (lo->ldo_dir_hash_type & LMV_HASH_FLAG_OVERSTRIPED) {
1040 CDEBUG(D_OTHER, "overstriped\n");
1041 } else if (lod_qos_is_tgt_used(env, mdt_idx,
1043 CDEBUG(D_OTHER, "#%d: already used\n", mdt_idx);
1048 /* we know the local MDT is usable */
1050 if (mdt->ltd_discon) {
1052 CDEBUG(D_OTHER, "#%d: unusable\n", mdt_idx);
1055 if (lod_statfs_check(ltd, mdt))
1057 if (mdt->ltd_statfs.os_state & OS_STATFS_NOCREATE)
1061 /* try to use another OSP if this one is degraded */
1062 if (!local_alloc && !use_degraded &&
1063 mdt->ltd_statfs.os_state & OS_STATFS_DEGRADED) {
1064 CDEBUG(D_OTHER, "#%d: degraded\n", mdt_idx);
1068 rc = dt_fid_alloc(env, mdt_tgt, &fid, NULL, NULL);
1070 CDEBUG(D_OTHER, "#%d: alloc FID failed: %dl\n", mdt_idx, rc);
1074 dto = dt_locate_at(env, mdt_tgt, &fid,
1075 lo->ldo_obj.do_lu.lo_dev->ld_site->ls_top_dev,
1079 CDEBUG(D_OTHER, "can't alloc stripe on #%u: %d\n",
1080 mdt_idx, (int) PTR_ERR(dto));
1082 if (!local_alloc && mdt->ltd_discon)
1087 lod_qos_tgt_in_use(env, stripe_idx, mdt_idx);
1088 stripes[stripe_idx++] = dto;
1091 if (!use_degraded && stripe_idx < stripe_count) {
1092 /* Try again, allowing slower MDTs */
1093 use_degraded = true;
1098 up_read(<d->ltd_qos.lq_rw_sem);
1100 if (stripe_idx > saved_idx) {
1101 /* If there are enough MDTs, we will not actually do
1102 * overstriping, and the hash flags should reflect this.
1105 lo->ldo_dir_hash_type &= ~LMV_HASH_FLAG_OVERSTRIPED;
1106 /* at least one stripe is allocated */
1110 /* nobody provided us with a single object */
1112 RETURN(-EINPROGRESS);
1118 * Allocate a specific striping layout on a user defined set of OSTs.
1120 * Allocates new striping using the OST index range provided by the data from
1121 * the lmm_obejcts contained in the lov_user_md passed to this method. Full
1122 * OSTs are not considered. The exact order of OSTs requested by the user
1123 * is respected as much as possible depending on OST status. The number of
1124 * stripes needed and stripe offset are taken from the object. If that number
1125 * can not be met, then the function returns a failure and then it's the
1126 * caller's responsibility to release the stripes allocated. All the internal
1127 * structures are protected, but no concurrent allocation is allowed on the
1130 * \param[in] env execution environment for this thread
1131 * \param[in] lo LOD object
1132 * \param[out] stripe striping created
1133 * \param[out] ost_indices ost indices of striping created
1134 * \param[in] th transaction handle
1135 * \param[in] comp_idx index of ldo_comp_entries
1137 * \retval 0 on success
1138 * \retval -ENODEV OST index does not exist on file system
1139 * \retval -EINVAL requested OST index is invalid
1140 * \retval negative negated errno on error
1142 static int lod_alloc_ost_list(const struct lu_env *env, struct lod_object *lo,
1143 struct dt_object **stripe, __u32 *ost_indices,
1144 struct thandle *th, int comp_idx, __u64 reserve)
1146 struct lod_layout_component *lod_comp;
1147 struct lod_device *m = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
1148 struct dt_object *o;
1149 unsigned int array_idx = 0;
1150 int stripe_count = 0;
1155 /* for specific OSTs layout */
1156 LASSERT(lo->ldo_comp_cnt > comp_idx && lo->ldo_comp_entries != NULL);
1157 lod_comp = &lo->ldo_comp_entries[comp_idx];
1158 LASSERT(lod_comp->llc_ostlist.op_array);
1159 LASSERT(lod_comp->llc_ostlist.op_count);
1161 rc = lod_qos_tgt_in_use_clear(env, lod_comp->llc_stripe_count);
1165 if (lod_comp->llc_stripe_offset == LOV_OFFSET_DEFAULT)
1166 lod_comp->llc_stripe_offset =
1167 lod_comp->llc_ostlist.op_array[0];
1169 for (i = 0; i < lod_comp->llc_stripe_count; i++) {
1170 if (lod_comp->llc_ostlist.op_array[i] ==
1171 lod_comp->llc_stripe_offset) {
1176 if (i == lod_comp->llc_stripe_count) {
1178 "%s: start index %d not in the specified list of OSTs\n",
1179 lod2obd(m)->obd_name, lod_comp->llc_stripe_offset);
1183 for (i = 0; i < lod_comp->llc_stripe_count;
1184 i++, array_idx = (array_idx + 1) % lod_comp->llc_stripe_count) {
1185 __u32 ost_idx = lod_comp->llc_ostlist.op_array[array_idx];
1187 if (!test_bit(ost_idx, m->lod_ost_bitmap)) {
1192 /* do not put >1 objects on a single OST, except for
1195 if (lod_qos_is_tgt_used(env, ost_idx, stripe_count) &&
1196 !(lod_comp->llc_pattern & LOV_PATTERN_OVERSTRIPING)) {
1201 rc = lod_statfs_and_check(env, m, &m->lod_ost_descs,
1202 LTD_TGT(&m->lod_ost_descs, ost_idx),
1204 if (rc < 0) /* this OSP doesn't feel well */
1207 o = lod_qos_declare_object_on(env, m, ost_idx, true, th);
1211 "%s: can't declare new object on #%u: %d\n",
1212 lod2obd(m)->obd_name, ost_idx, rc);
1217 * We've successfully declared (reserved) an object
1219 lod_qos_tgt_in_use(env, stripe_count, ost_idx);
1220 stripe[stripe_count] = o;
1221 ost_indices[stripe_count] = ost_idx;
1229 * Allocate a striping on a predefined set of OSTs.
1231 * Allocates new layout starting from OST index in lo->ldo_stripe_offset.
1232 * Full OSTs are not considered. The exact order of OSTs is not important and
1233 * varies depending on OST status. The allocation procedure prefers the targets
1234 * with precreated objects ready. The number of stripes needed and stripe
1235 * offset are taken from the object. If that number cannot be met, then the
1236 * function returns an error and then it's the caller's responsibility to
1237 * release the stripes allocated. All the internal structures are protected,
1238 * but no concurrent allocation is allowed on the same objects.
1240 * \param[in] env execution environment for this thread
1241 * \param[in] lo LOD object
1242 * \param[out] stripe striping created
1243 * \param[out] ost_indices ost indices of striping created
1244 * \param[in] flags not used
1245 * \param[in] th transaction handle
1246 * \param[in] comp_idx index of ldo_comp_entries
1248 * \retval 0 on success
1249 * \retval -ENOSPC if no OST objects are available at all
1250 * \retval -EFBIG if not enough OST objects are found
1251 * \retval -EINVAL requested offset is invalid
1252 * \retval negative errno on failure
1254 static int lod_ost_alloc_specific(const struct lu_env *env,
1255 struct lod_object *lo,
1256 struct dt_object **stripe, __u32 *ost_indices,
1257 enum lod_uses_hint flags, struct thandle *th,
1258 int comp_idx, __u64 reserve)
1260 struct lod_layout_component *lod_comp;
1261 struct lod_device *m = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
1262 struct dt_object *o;
1263 struct lu_tgt_desc *tgt;
1265 unsigned int i, array_idx, ost_count;
1266 int rc, stripe_num = 0;
1268 struct lod_pool_desc *pool = NULL;
1269 struct lu_tgt_pool *osts;
1270 int stripes_per_ost = 1;
1271 bool overstriped = false;
1274 LASSERT(lo->ldo_comp_cnt > comp_idx && lo->ldo_comp_entries != NULL);
1275 lod_comp = &lo->ldo_comp_entries[comp_idx];
1277 rc = lod_qos_tgt_in_use_clear(env, lod_comp->llc_stripe_count);
1281 if (lod_comp->llc_pool != NULL)
1282 pool = lod_find_pool(m, lod_comp->llc_pool);
1285 down_read(&pool_tgt_rw_sem(pool));
1286 osts = &(pool->pool_obds);
1288 osts = &m->lod_ost_descs.ltd_tgt_pool;
1291 ost_count = osts->op_count;
1294 /* search loi_ost_idx in ost array */
1296 for (i = 0; i < ost_count; i++) {
1297 if (osts->op_array[i] == lod_comp->llc_stripe_offset) {
1302 if (i == ost_count) {
1303 CERROR("Start index %d not found in pool '%s'\n",
1304 lod_comp->llc_stripe_offset,
1305 lod_comp->llc_pool ? lod_comp->llc_pool : "");
1306 GOTO(out, rc = -EINVAL);
1309 if (lod_comp->llc_pattern & LOV_PATTERN_OVERSTRIPING)
1311 (lod_comp->llc_stripe_count - 1)/ost_count + 1;
1313 /* user specifies bigger stripe count than available ost count */
1314 if (lod_comp->llc_stripe_count > ost_count * stripes_per_ost)
1315 lod_comp->llc_stripe_count = ost_count * stripes_per_ost;
1317 for (i = 0; i < ost_count * stripes_per_ost;
1318 i++, array_idx = (array_idx + 1) % ost_count) {
1319 ost_idx = osts->op_array[array_idx];
1321 if (!test_bit(ost_idx, m->lod_ost_bitmap))
1324 /* Fail Check before osc_precreate() is called
1325 so we can only 'fail' single OSC. */
1326 if (CFS_FAIL_CHECK(OBD_FAIL_MDS_OSC_PRECREATE) && ost_idx == 0)
1330 * do not put >1 objects on a single OST, except for
1331 * overstriping, where it is intended
1333 if (lod_qos_is_tgt_used(env, ost_idx, stripe_num)) {
1334 if (lod_comp->llc_pattern & LOV_PATTERN_OVERSTRIPING)
1341 * try not allocate on the OST used by other component
1343 if (speed == 0 && i != 0 &&
1344 lod_comp_is_ost_used(env, lo, ost_idx))
1347 tgt = LTD_TGT(&m->lod_ost_descs, ost_idx);
1349 /* Drop slow OSCs if we can, but not for requested start idx.
1351 * This means "if OSC is slow and it is not the requested
1352 * start OST, then it can be skipped, otherwise skip it only
1353 * if it is inactive/recovering/out-of-space." */
1355 rc = lod_statfs_and_check(env, m, &m->lod_ost_descs,
1358 /* this OSP doesn't feel well */
1363 * We expect number of precreated objects at the first
1364 * iteration. Skip OSPs with no objects ready. Don't apply
1365 * this logic to OST specified with stripe_offset.
1367 if (i && !tgt->ltd_statfs.os_fprecreated && !speed)
1370 o = lod_qos_declare_object_on(env, m, ost_idx, true, th);
1372 CDEBUG(D_OTHER, "can't declare new object on #%u: %d\n",
1373 ost_idx, (int) PTR_ERR(o));
1378 * We've successfully declared (reserved) an object
1380 lod_qos_tgt_in_use(env, stripe_num, ost_idx);
1381 stripe[stripe_num] = o;
1382 ost_indices[stripe_num] = ost_idx;
1385 /* We have enough stripes */
1386 if (stripe_num == lod_comp->llc_stripe_count)
1390 /* Try again, allowing slower OSCs */
1395 /* If we were passed specific striping params, then a failure to
1396 * meet those requirements is an error, since we can't reallocate
1397 * that memory (it might be part of a larger array or something).
1399 CERROR("can't lstripe objid "DFID": have %d want %u\n",
1400 PFID(lu_object_fid(lod2lu_obj(lo))), stripe_num,
1401 lod_comp->llc_stripe_count);
1402 rc = stripe_num == 0 ? -ENOSPC : -EFBIG;
1404 /* If there are enough OSTs, a component with overstriping requessted
1405 * will not actually end up overstriped. The comp should reflect this.
1407 if (rc == 0 && !overstriped)
1408 lod_comp->llc_pattern &= ~LOV_PATTERN_OVERSTRIPING;
1412 up_read(&pool_tgt_rw_sem(pool));
1413 /* put back ref got by lod_find_pool() */
1414 lod_pool_putref(pool);
1420 #ifdef HAVE_DOWN_WRITE_KILLABLE
1421 struct semaphore_timer {
1422 struct timer_list timer;
1423 struct task_struct *task;
1426 static void process_semaphore_timer(struct timer_list *t)
1428 struct semaphore_timer *timeout = cfs_from_timer(timeout, t, timer);
1430 send_sig(SIGKILL, timeout->task, 1);
1435 * Calculate penalties per-ost in a pool
1437 * The algorithm is similar to ltd_qos_penalties_calc(), but much simpler,
1438 * just considering the space of each OST in this pool.
1440 * \param[in] lod lod_device
1441 * \param[in] pool pool_desc
1443 * \retval 0 on success
1444 * \retval -EAGAIN the number of OSTs isn't enough or all tgt spaces are
1447 static int lod_pool_qos_penalties_calc(struct lod_device *lod,
1448 struct lod_pool_desc *pool)
1450 struct lu_tgt_descs *ltd = &lod->lod_ost_descs;
1451 struct lu_qos *qos = <d->ltd_qos;
1452 struct lov_desc *desc = <d->ltd_lov_desc;
1453 struct lu_tgt_pool *osts = &pool->pool_obds;
1454 struct lod_tgt_desc *ost;
1455 __u64 ba_max, ba_min, ba;
1463 now = ktime_get_real_seconds();
1465 if (pool->pool_same_space && now < pool->pool_same_space_expire)
1468 num_active = osts->op_count - 1;
1470 GOTO(out, rc = -EAGAIN);
1472 prio_wide = 256 - qos->lq_prio_free;
1474 ba_min = (__u64)(-1);
1477 /* Calculate penalty per OST */
1478 for (i = 0; i < osts->op_count; i++) {
1479 if (!test_bit(osts->op_array[i], lod->lod_ost_bitmap))
1482 ost = OST_TGT(lod, osts->op_array[i]);
1483 if (!ost->ltd_active)
1486 ba = tgt_statfs_bavail(ost) >> 8;
1490 ba_min = min(ba, ba_min);
1491 ba_max = max(ba, ba_max);
1492 ost->ltd_qos.ltq_svr->lsq_bavail += ba;
1495 * per-ost penalty is
1496 * prio * bavail / (num_tgt - 1) / prio_max / 2
1498 ost->ltd_qos.ltq_penalty_per_obj = prio_wide * ba >> 9;
1499 do_div(ost->ltd_qos.ltq_penalty_per_obj, num_active);
1501 age = (now - ost->ltd_qos.ltq_used) >> 3;
1502 if (age > 32 * desc->ld_qos_maxage)
1503 ost->ltd_qos.ltq_penalty = 0;
1504 else if (age > desc->ld_qos_maxage)
1505 /* Decay ost penalty. */
1506 ost->ltd_qos.ltq_penalty >>= age / desc->ld_qos_maxage;
1510 * If each ost has almost same free space, do rr allocation for better
1511 * creation performance
1513 if ((ba_max * (256 - qos->lq_threshold_rr)) >> 8 < ba_min) {
1514 pool->pool_same_space = true;
1515 pool->pool_same_space_expire = now + desc->ld_qos_maxage;
1517 pool->pool_same_space = false;
1522 if (!rc && pool->pool_same_space)
1529 * Allocate a striping using an algorithm with weights.
1531 * The function allocates OST objects to create a striping. The algorithm
1532 * used is based on weights (currently only using the free space), and it's
1533 * trying to ensure the space is used evenly by OSTs and OSSs. The striping
1534 * configuration (# of stripes, offset, pool) is taken from the object and
1535 * is prepared by the caller.
1537 * If LOD_USES_DEFAULT_STRIPE is not passed and prepared configuration can't
1538 * be met due to too few OSTs, then allocation fails. If the flag is passed
1539 * fewer than 3/4 of the requested number of stripes can be allocated, then
1542 * No concurrent allocation is allowed on the object and this must be ensured
1543 * by the caller. All the internal structures are protected by the function.
1545 * The algorithm has two steps: find available OSTs and calculate their
1546 * weights, then select the OSTs with their weights used as the probability.
1547 * An OST with a higher weight is proportionately more likely to be selected
1548 * than one with a lower weight.
1550 * \param[in] env execution environment for this thread
1551 * \param[in] lo LOD object
1552 * \param[out] stripe striping created
1553 * \param[out] ost_indices ost indices of striping created
1554 * \param[in] flags 0 or LOD_USES_DEFAULT_STRIPE
1555 * \param[in] th transaction handle
1556 * \param[in] comp_idx index of ldo_comp_entries
1558 * \retval 0 on success
1559 * \retval -EAGAIN not enough OSTs are found for specified stripe count
1560 * \retval -EINVAL requested OST index is invalid
1561 * \retval negative errno on failure
1563 static int lod_ost_alloc_qos(const struct lu_env *env, struct lod_object *lo,
1564 struct dt_object **stripe, __u32 *ost_indices,
1565 enum lod_uses_hint flags, struct thandle *th,
1566 int comp_idx, __u64 reserve)
1568 struct lod_layout_component *lod_comp;
1569 struct lod_device *lod = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
1570 struct lod_avoid_guide *lag = &lod_env_info(env)->lti_avoid;
1571 struct lod_tgt_desc *ost;
1572 struct dt_object *o;
1573 __u64 total_weight = 0;
1574 struct lod_pool_desc *pool = NULL;
1575 struct lu_tgt_pool *osts;
1577 __u32 nfound, good_osts, stripe_count, stripe_count_min;
1578 bool overstriped = false;
1579 int stripes_per_ost = 1;
1584 /* Totally skip qos part when qos_threshold_rr=100% */
1585 if (lod->lod_ost_descs.ltd_qos.lq_threshold_rr == QOS_THRESHOLD_MAX)
1588 LASSERT(lo->ldo_comp_cnt > comp_idx && lo->ldo_comp_entries != NULL);
1589 lod_comp = &lo->ldo_comp_entries[comp_idx];
1590 stripe_count = lod_comp->llc_stripe_count;
1591 stripe_count_min = lod_stripe_count_min(stripe_count, flags);
1592 if (stripe_count_min < 1)
1595 if (lod_comp->llc_pool != NULL)
1596 pool = lod_find_pool(lod, lod_comp->llc_pool);
1599 down_read(&pool_tgt_rw_sem(pool));
1600 osts = &(pool->pool_obds);
1602 osts = &lod->lod_ost_descs.ltd_tgt_pool;
1605 /* Detect -EAGAIN early, before expensive lock is taken. */
1606 if (!ltd_qos_is_usable(&lod->lod_ost_descs))
1607 GOTO(out_nolock, rc = -EAGAIN);
1609 if (lod_comp->llc_pattern & LOV_PATTERN_OVERSTRIPING)
1611 (lod_comp->llc_stripe_count - 1)/osts->op_count + 1;
1613 #ifdef HAVE_DOWN_WRITE_KILLABLE
1614 if (!down_write_trylock(&lod->lod_ost_descs.ltd_qos.lq_rw_sem)) {
1615 struct semaphore_timer timer;
1617 kernel_sigaction(SIGKILL, SIG_DFL);
1618 timer.task = current;
1619 cfs_timer_setup(&timer.timer, process_semaphore_timer, 0, 0);
1620 mod_timer(&timer.timer, jiffies + cfs_time_seconds(2));
1621 /* Do actual allocation, use write lock here. */
1622 rc = down_write_killable(&lod->lod_ost_descs.ltd_qos.lq_rw_sem);
1624 timer_delete_sync(&timer.timer);
1625 kernel_sigaction(SIGKILL, SIG_IGN);
1627 flush_signals(current);
1628 CDEBUG(D_OTHER, "%s: wakeup semaphore on timeout rc = %d\n",
1629 lod2obd(lod)->obd_name, rc);
1630 GOTO(out_nolock, rc = -EAGAIN);
1634 /* Do actual allocation, use write lock here. */
1635 down_write(&lod->lod_ost_descs.ltd_qos.lq_rw_sem);
1638 * Check again, while we were sleeping on @lq_rw_sem things could
1641 if (!ltd_qos_is_usable(&lod->lod_ost_descs))
1642 GOTO(out, rc = -EAGAIN);
1645 rc = lod_pool_qos_penalties_calc(lod, pool);
1647 rc = ltd_qos_penalties_calc(&lod->lod_ost_descs);
1651 rc = lod_qos_tgt_in_use_clear(env, lod_comp->llc_stripe_count);
1656 /* Find all the OSTs that are valid stripe candidates */
1657 for (i = 0; i < osts->op_count; i++) {
1658 if (!test_bit(osts->op_array[i], lod->lod_ost_bitmap))
1661 ost = OST_TGT(lod, osts->op_array[i]);
1662 ost->ltd_qos.ltq_usable = 0;
1664 rc = lod_statfs_and_check(env, lod, &lod->lod_ost_descs,
1667 /* this OSP doesn't feel well */
1671 if (ost->ltd_statfs.os_state & OS_STATFS_DEGRADED)
1674 /* Fail Check before osc_precreate() is called
1675 * so we can only 'fail' single OSC.
1677 if (CFS_FAIL_CHECK(OBD_FAIL_MDS_OSC_PRECREATE) &&
1678 osts->op_array[i] == 0)
1681 ost->ltd_qos.ltq_usable = 1;
1682 lu_tgt_qos_weight_calc(ost, false);
1683 total_weight += ost->ltd_qos.ltq_weight;
1688 CDEBUG(D_OTHER, "found %d good osts\n", good_osts);
1690 if (good_osts < stripe_count_min)
1691 GOTO(out, rc = -EAGAIN);
1693 /* If we do not have enough OSTs for the requested stripe count, do not
1694 * put more stripes per OST than requested.
1696 if (stripe_count / stripes_per_ost > good_osts)
1697 stripe_count = good_osts * stripes_per_ost;
1699 /* Find enough OSTs with weighted random allocation. */
1701 while (nfound < stripe_count) {
1702 u64 rand, cur_weight;
1707 rand = lu_prandom_u64_max(total_weight);
1709 /* On average, this will hit larger-weighted OSTs more often.
1710 * 0-weight OSTs will always get used last (only when rand=0)
1712 for (i = 0; i < osts->op_count; i++) {
1713 __u32 idx = osts->op_array[i];
1714 struct lod_tgt_desc *ost;
1716 if (lod_should_avoid_ost(lo, lag, idx))
1719 ost = OST_TGT(lod, idx);
1721 if (!ost->ltd_qos.ltq_usable)
1724 cur_weight += ost->ltd_qos.ltq_weight;
1725 CDEBUG(D_OTHER, "stripe_count=%d nfound=%d cur_weight=%llu rand=%llu total_weight=%llu\n",
1726 stripe_count, nfound, cur_weight, rand,
1729 if (cur_weight < rand)
1732 CDEBUG(D_OTHER, "stripe=%d to idx=%d\n", nfound, idx);
1734 * In case of QOS it makes sense to check components
1735 * only for FLR and if current component doesn't support
1738 if (lo->ldo_mirror_count > 1 &&
1739 !(lod_comp->llc_pattern & LOV_PATTERN_OVERSTRIPING)
1740 && lod_comp_is_ost_used(env, lo, idx))
1743 if (lod_qos_is_tgt_used(env, idx, nfound)) {
1744 if (lod_comp->llc_pattern &
1745 LOV_PATTERN_OVERSTRIPING)
1751 o = lod_qos_declare_object_on(env, lod, idx, slow, th);
1753 CDEBUG(D_OTHER, "can't declare object on #%u: %d\n",
1754 idx, (int) PTR_ERR(o));
1758 lod_avoid_update(lo, lag);
1759 lod_qos_tgt_in_use(env, nfound, idx);
1761 ost_indices[nfound] = idx;
1762 ltd_qos_update(&lod->lod_ost_descs, ost, &total_weight);
1768 if (rc && !slow && nfound < stripe_count) {
1769 /* couldn't allocate using precreated objects
1770 * so try to wait for new precreations */
1776 /* no OST found on this iteration, give up */
1781 if (unlikely(nfound < stripe_count_min)) {
1783 * when the decision to use weighted algorithm was made
1784 * we had enough appropriate OSPs, but this state can
1785 * change anytime (no space on OST, broken connection, etc)
1786 * so it's possible OSP won't be able to provide us with
1787 * an object due to just changed state
1789 CDEBUG(D_OTHER, "%s: wanted %d objects, found only %d\n",
1790 lod2obd(lod)->obd_name, stripe_count, nfound);
1791 for (i = 0; i < nfound; i++) {
1792 LASSERT(stripe[i] != NULL);
1793 dt_object_put(env, stripe[i]);
1797 /* makes sense to rebalance next time */
1798 set_bit(LQ_DIRTY, &lod->lod_ost_descs.ltd_qos.lq_flags);
1799 clear_bit(LQ_SAME_SPACE, &lod->lod_ost_descs.ltd_qos.lq_flags);
1801 } else if (nfound < lod_comp->llc_stripe_count) {
1802 lod_comp->llc_stripe_count = nfound;
1805 /* If there are enough OSTs, a component with overstriping requessted
1806 * will not actually end up overstriped. The comp should reflect this.
1808 if (rc == 0 && !overstriped)
1809 lod_comp->llc_pattern &= ~LOV_PATTERN_OVERSTRIPING;
1812 up_write(&lod->lod_ost_descs.ltd_qos.lq_rw_sem);
1816 up_read(&pool_tgt_rw_sem(pool));
1817 /* put back ref got by lod_find_pool() */
1818 lod_pool_putref(pool);
1825 * Allocate a striping using an algorithm with weights.
1827 * The function allocates remote MDT objects to create a striping, the first
1828 * object was already allocated on current MDT to ensure master object and
1829 * the first object are on the same MDT. The algorithm used is based on weights
1830 * (both free space and inodes), and it's trying to ensure the space/inodes are
1831 * used evenly by MDTs and MDSs. The striping configuration (# of stripes,
1832 * offset, pool) is taken from the object and is prepared by the caller.
1834 * If prepared configuration can't be met due to too few MDTs, then allocation
1837 * No concurrent allocation is allowed on the object and this must be ensured
1838 * by the caller. All the internal structures are protected by the function.
1840 * The algorithm has two steps: find available MDTs and calculate their
1841 * weights, then select the MDTs with their weights used as the probability.
1842 * An MDT with a higher weight is proportionately more likely to be selected
1843 * than one with a lower weight.
1845 * \param[in] env execution environment for this thread
1846 * \param[in] lo LOD object
1847 * \param[in] stripe_idx starting stripe index to allocate, if it's not
1848 * 0, we are restriping directory
1849 * \param[in] stripe_count total stripe count
1850 * \param[out] stripes striping created
1852 * \retval positive stripes allocated, and it should be equal to
1853 * lo->ldo_dir_stripe_count
1854 * \retval -EAGAIN not enough tgts are found for specified stripe count
1855 * \retval -EINVAL requested MDT index is invalid
1856 * \retval negative errno on failure
1858 int lod_mdt_alloc_qos(const struct lu_env *env, struct lod_object *lo,
1859 struct dt_object **stripes, u32 stripe_idx,
1862 struct lod_device *lod = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
1863 struct lu_tgt_descs *ltd = &lod->lod_mdt_descs;
1864 struct lu_object_conf conf = { .loc_flags = LOC_F_NEW };
1865 struct lu_fid fid = { 0 };
1866 const struct lu_tgt_pool *pool;
1867 struct lu_tgt_desc *mdt;
1868 struct dt_object *dto;
1869 u64 total_weight = 0;
1870 u32 saved_idx = stripe_idx;
1872 unsigned int good_mdts;
1878 /* Totally skip qos part when qos_threshold_rr=100% */
1879 if (ltd->ltd_qos.lq_threshold_rr == QOS_THRESHOLD_MAX)
1882 LASSERT(stripe_idx <= stripe_count);
1883 if (stripe_idx == stripe_count)
1884 RETURN(stripe_count);
1886 /* we do not use qos for overstriping, since it will always use all the
1887 * MDTs. So we check if it's truly needed, falling back to rr if it is,
1888 * and otherwise we remove the flag and continue
1890 if (lo->ldo_dir_hash_type & LMV_HASH_FLAG_OVERSTRIPED) {
1891 if (stripe_count > lod->lod_remote_mdt_count + 1)
1893 lo->ldo_dir_hash_type &= ~LMV_HASH_FLAG_OVERSTRIPED;
1896 /* use MDT pool in @ltd, once MDT pool is supported in the future, it
1897 * can be passed in as argument like OST object allocation.
1899 pool = <d->ltd_tgt_pool;
1901 /* Detect -EAGAIN early, before expensive lock is taken. */
1902 if (!ltd_qos_is_usable(ltd))
1905 rc = lod_qos_mdt_in_use_init(env, ltd, stripe_idx, stripe_count, pool,
1910 /* Do actual allocation, use write lock here. */
1911 down_write(<d->ltd_qos.lq_rw_sem);
1914 * Check again, while we were sleeping on @lq_rw_sem things could
1917 if (!ltd_qos_is_usable(ltd))
1918 GOTO(unlock, rc = -EAGAIN);
1920 rc = ltd_qos_penalties_calc(ltd);
1925 /* Find all the MDTs that are valid stripe candidates */
1926 for (i = 0; i < pool->op_count; i++) {
1927 if (!test_bit(pool->op_array[i], ltd->ltd_tgt_bitmap))
1930 mdt = LTD_TGT(ltd, pool->op_array[i]);
1931 mdt->ltd_qos.ltq_usable = 0;
1933 if (mdt->ltd_discon || lod_statfs_check(ltd, mdt))
1936 if (mdt->ltd_statfs.os_state &
1937 (OS_STATFS_DEGRADED | OS_STATFS_NOCREATE))
1940 mdt->ltd_qos.ltq_usable = 1;
1941 lu_tgt_qos_weight_calc(mdt, true);
1942 total_weight += mdt->ltd_qos.ltq_weight;
1947 CDEBUG(D_OTHER, "found %d good MDTs\n", good_mdts);
1949 if (good_mdts < stripe_count - stripe_idx)
1950 GOTO(unlock, rc = -EAGAIN);
1952 /* Find enough MDTs with weighted random allocation. */
1953 while (stripe_idx < stripe_count) {
1954 u64 rand, cur_weight;
1959 rand = lu_prandom_u64_max(total_weight);
1961 /* On average, this will hit larger-weighted MDTs more often.
1962 * 0-weight MDT will always get used last (only when rand=0) */
1963 for (i = 0; i < pool->op_count; i++) {
1966 mdt_idx = pool->op_array[i];
1967 mdt = LTD_TGT(ltd, mdt_idx);
1969 if (!mdt->ltd_qos.ltq_usable)
1972 cur_weight += mdt->ltd_qos.ltq_weight;
1974 CDEBUG(D_OTHER, "stripe_count=%d stripe_index=%d cur_weight=%llu rand=%llu total_weight=%llu\n",
1975 stripe_count, stripe_idx, cur_weight, rand,
1978 if (cur_weight < rand)
1981 CDEBUG(D_OTHER, "stripe=%d to idx=%d\n",
1982 stripe_idx, mdt_idx);
1984 if (lod_qos_is_tgt_used(env, mdt_idx, stripe_idx))
1987 rc2 = dt_fid_alloc(env, mdt->ltd_tgt, &fid, NULL, NULL);
1989 CDEBUG(D_OTHER, "can't alloc FID on #%u: %d\n",
1994 conf.loc_flags = LOC_F_NEW;
1995 dto = dt_locate_at(env, mdt->ltd_tgt, &fid,
1996 lo->ldo_obj.do_lu.lo_dev->ld_site->ls_top_dev,
1999 CDEBUG(D_OTHER, "can't alloc stripe on #%u: %d\n",
2000 mdt_idx, (int) PTR_ERR(dto));
2004 lod_qos_tgt_in_use(env, stripe_idx, mdt_idx);
2005 stripes[stripe_idx] = dto;
2006 ltd_qos_update(ltd, mdt, &total_weight);
2012 /* no MDT found on this iteration, give up */
2017 if (unlikely(stripe_idx != stripe_count)) {
2019 * when the decision to use weighted algorithm was made
2020 * we had enough appropriate OSPs, but this state can
2021 * change anytime (no space on MDT, broken connection, etc)
2022 * so it's possible OSP won't be able to provide us with
2023 * an object due to just changed state
2025 CDEBUG(D_OTHER, "%s: wanted %d objects, found only %d\n",
2026 lod2obd(lod)->obd_name, stripe_count, stripe_idx);
2027 for (i = saved_idx; i < stripe_idx; i++) {
2028 LASSERT(stripes[i] != NULL);
2029 dt_object_put(env, stripes[i]);
2033 /* makes sense to rebalance next time */
2034 set_bit(LQ_DIRTY, <d->ltd_qos.lq_flags);
2035 clear_bit(LQ_SAME_SPACE, <d->ltd_qos.lq_flags);
2043 up_write(<d->ltd_qos.lq_rw_sem);
2049 * Check stripe count the caller can use.
2051 * For new layouts (no initialized components), check the total size of the
2052 * layout against the maximum EA size from the backing file system. This
2053 * stops us from creating a layout which will be too large once initialized.
2055 * For existing layouts (with initialized components):
2056 * Find the maximal possible stripe count not greater than \a stripe_count.
2057 * If the provided stripe count is 0, then the filesystem's default is used.
2059 * \param[in] lod LOD device
2060 * \param[in] lo The lod_object
2061 * \param[in] comp_idx The component id, which the amount of stripes is
2063 * \param[in] stripe_count count the caller would like to use
2065 * \retval the maximum usable stripe count
2067 __u16 lod_get_stripe_count_plain(struct lod_device *lod, struct lod_object *lo,
2068 __u16 stripe_count, bool overstriping,
2069 enum lod_uses_hint *flags)
2071 struct lov_desc *lov_desc = &lod->lod_ost_descs.ltd_lov_desc;
2073 /* Overstriping allows more stripes than targets */
2074 if (stripe_count > lov_desc->ld_active_tgt_count) {
2076 if (stripe_count >= LOV_ALL_STRIPES_MIN &&
2077 stripe_count <= LOV_ALL_STRIPES_MAX) {
2079 ((stripe_count - LOV_ALL_STRIPES_MIN) + 1) *
2080 lov_desc->ld_active_tgt_count;
2083 *flags |= LOD_USES_DEFAULT_STRIPE;
2084 if ((stripe_count >= LOV_ALL_STRIPES_MIN &&
2085 stripe_count <= LOV_ALL_STRIPES_MAX) &&
2086 lod->lod_max_stripecount)
2087 stripe_count = lod->lod_max_stripecount;
2089 stripe_count = lov_desc->ld_active_tgt_count;
2094 stripe_count = lov_desc->ld_default_stripe_count;
2096 if (overstriping && stripe_count > LOV_MAX_STRIPE_COUNT)
2097 stripe_count = LOV_MAX_STRIPE_COUNT;
2099 return stripe_count;
2102 __u16 lod_get_stripe_count(struct lod_device *lod, struct lod_object *lo,
2103 int comp_idx, __u16 stripe_count, bool overstriping,
2104 enum lod_uses_hint *flags)
2106 __u32 max_stripes = LOV_MAX_STRIPE_COUNT_OLD;
2107 /* max stripe count is based on OSD ea size */
2108 unsigned int easize = lod->lod_osd_max_easize;
2113 stripe_count = lod_get_stripe_count_plain(lod, lo, stripe_count,
2114 overstriping, flags);
2116 if (lo->ldo_is_composite) {
2117 struct lod_layout_component *lod_comp;
2118 unsigned int header_sz = sizeof(struct lov_comp_md_v1);
2119 unsigned int init_comp_sz = 0;
2120 unsigned int total_comp_sz = 0;
2121 unsigned int comp_sz;
2123 header_sz += sizeof(struct lov_comp_md_entry_v1) *
2126 for (i = 0; i < lo->ldo_comp_cnt; i++) {
2127 unsigned int stripes;
2132 lod_comp = &lo->ldo_comp_entries[i];
2133 /* Extension comp is never inited - 0 stripes on disk */
2134 stripes = lod_comp->llc_flags & LCME_FL_EXTENSION ? 0 :
2135 lod_comp->llc_stripe_count;
2137 comp_sz = lov_mds_md_size(stripes, LOV_MAGIC_V3);
2138 total_comp_sz += comp_sz;
2139 if (lod_comp->llc_flags & LCME_FL_INIT)
2140 init_comp_sz += comp_sz;
2143 if (init_comp_sz > 0)
2144 total_comp_sz = init_comp_sz;
2146 header_sz += total_comp_sz;
2148 if (easize > header_sz)
2149 easize -= header_sz;
2154 max_stripes = lov_mds_md_max_stripe_count(easize, LOV_MAGIC_V3);
2155 max_stripes = (max_stripes == 0) ? 0 : max_stripes - 1;
2157 stripe_count = min_t(__u16, stripe_count, max_stripes);
2158 RETURN(stripe_count);
2162 * Create in-core respresentation for a fully-defined striping
2164 * When the caller passes a fully-defined striping (i.e. everything including
2165 * OST object FIDs are defined), then we still need to instantiate LU-cache
2166 * with the objects representing the stripes defined. This function completes
2169 * \param[in] env execution environment for this thread
2170 * \param[in] mo LOD object
2171 * \param[in] buf buffer containing the striping
2173 * \retval 0 on success
2174 * \retval negative negated errno on error
2176 int lod_use_defined_striping(const struct lu_env *env,
2177 struct lod_object *mo,
2178 const struct lu_buf *buf)
2180 struct lod_layout_component *lod_comp;
2181 struct lov_mds_md_v1 *v1 = buf->lb_buf;
2182 struct lov_mds_md_v3 *v3 = buf->lb_buf;
2183 struct lov_comp_md_v1 *comp_v1 = NULL;
2184 struct lov_ost_data_v1 *objs;
2191 mutex_lock(&mo->ldo_layout_mutex);
2192 lod_striping_free_nolock(env, mo);
2194 magic = le32_to_cpu(v1->lmm_magic) & ~LOV_MAGIC_DEFINED;
2196 if (magic != LOV_MAGIC_V1 && magic != LOV_MAGIC_V3 &&
2197 magic != LOV_MAGIC_COMP_V1 && magic != LOV_MAGIC_FOREIGN)
2198 GOTO(unlock, rc = -EINVAL);
2200 if (magic == LOV_MAGIC_COMP_V1) {
2201 comp_v1 = buf->lb_buf;
2202 comp_cnt = le16_to_cpu(comp_v1->lcm_entry_count);
2204 GOTO(unlock, rc = -EINVAL);
2205 mirror_cnt = le16_to_cpu(comp_v1->lcm_mirror_count) + 1;
2206 mo->ldo_flr_state = le16_to_cpu(comp_v1->lcm_flags) &
2208 mo->ldo_is_composite = 1;
2209 } else if (magic == LOV_MAGIC_FOREIGN) {
2210 struct lov_foreign_md *foreign;
2213 if (buf->lb_len < offsetof(typeof(*foreign), lfm_value)) {
2215 "buf len %zu < min lov_foreign_md size (%zu)\n",
2217 offsetof(typeof(*foreign), lfm_value));
2218 GOTO(out, rc = -EINVAL);
2220 foreign = (struct lov_foreign_md *)buf->lb_buf;
2221 length = lov_foreign_size_le(foreign);
2222 if (buf->lb_len < length) {
2224 "buf len %zu < this lov_foreign_md size (%zu)\n",
2225 buf->lb_len, length);
2226 GOTO(out, rc = -EINVAL);
2229 /* just cache foreign LOV EA raw */
2230 rc = lod_alloc_foreign_lov(mo, length);
2233 memcpy(mo->ldo_foreign_lov, buf->lb_buf, length);
2236 mo->ldo_is_composite = 0;
2240 mo->ldo_layout_gen = le16_to_cpu(v1->lmm_layout_gen);
2242 rc = lod_alloc_comp_entries(mo, mirror_cnt, comp_cnt);
2246 for (i = 0; i < comp_cnt; i++) {
2247 struct lu_extent *ext;
2251 lod_comp = &mo->ldo_comp_entries[i];
2253 if (mo->ldo_is_composite) {
2254 offs = le32_to_cpu(comp_v1->lcm_entries[i].lcme_offset);
2255 v1 = (struct lov_mds_md_v1 *)((char *)comp_v1 + offs);
2256 v3 = (struct lov_mds_md_v3 *)v1;
2257 magic = le32_to_cpu(v1->lmm_magic);
2259 ext = &comp_v1->lcm_entries[i].lcme_extent;
2260 lod_comp->llc_extent.e_start =
2261 le64_to_cpu(ext->e_start);
2262 lod_comp->llc_extent.e_end = le64_to_cpu(ext->e_end);
2263 lod_comp->llc_flags =
2264 le32_to_cpu(comp_v1->lcm_entries[i].lcme_flags);
2265 if (lod_comp->llc_flags & LCME_FL_NOSYNC)
2266 lod_comp->llc_timestamp = le64_to_cpu(
2267 comp_v1->lcm_entries[i].lcme_timestamp);
2269 le32_to_cpu(comp_v1->lcm_entries[i].lcme_id);
2270 if (lod_comp->llc_id == LCME_ID_INVAL)
2271 GOTO(out, rc = -EINVAL);
2273 lod_comp->llc_magic = magic;
2274 if (magic == LOV_MAGIC_FOREIGN) {
2275 rc = lod_init_comp_foreign(lod_comp, v1);
2281 lod_comp->llc_magic = magic;
2285 if (magic == LOV_MAGIC_V1) {
2286 objs = &v1->lmm_objects[0];
2287 } else if (magic == LOV_MAGIC_V3) {
2288 objs = &v3->lmm_objects[0];
2289 if (v3->lmm_pool_name[0] != '\0')
2290 pool_name = v3->lmm_pool_name;
2292 CDEBUG(D_LAYOUT, "Invalid magic %x\n", magic);
2293 GOTO(out, rc = -EINVAL);
2296 lod_comp->llc_pattern = le32_to_cpu(v1->lmm_pattern);
2297 lod_comp->llc_stripe_size = le32_to_cpu(v1->lmm_stripe_size);
2298 lod_comp->llc_stripe_count = le16_to_cpu(v1->lmm_stripe_count);
2300 * limit stripe count so that it's less than/equal to
2301 * extent_size / stripe_size.
2303 * Note: extension size reused llc_stripe_size field and
2304 * uninstantiated component could be defined with
2305 * extent_start == extent_end as extension component will
2308 if (mo->ldo_is_composite &&
2309 !(lod_comp->llc_flags & LCME_FL_EXTENSION) &&
2310 (lod_comp_inited(lod_comp) ||
2311 lod_comp->llc_extent.e_start <
2312 lod_comp->llc_extent.e_end) &&
2313 !(lod_comp->llc_stripe_count >= LOV_ALL_STRIPES_MIN &&
2314 lod_comp->llc_stripe_count <= LOV_ALL_STRIPES_MAX) &&
2315 lod_comp->llc_extent.e_end != OBD_OBJECT_EOF &&
2316 (__u64)lod_comp->llc_stripe_count *
2317 lod_comp->llc_stripe_size >
2318 (lod_comp->llc_extent.e_end - lod_comp->llc_extent.e_start))
2319 lod_comp->llc_stripe_count =
2320 DIV_ROUND_UP(lod_comp->llc_extent.e_end -
2321 lod_comp->llc_extent.e_start,
2322 lod_comp->llc_stripe_size);
2323 lod_comp->llc_layout_gen = le16_to_cpu(v1->lmm_layout_gen);
2325 * The stripe_offset of an uninit-ed component is stored in
2326 * the lmm_layout_gen
2328 if (mo->ldo_is_composite && !lod_comp_inited(lod_comp))
2329 lod_comp->llc_stripe_offset = lod_comp->llc_layout_gen;
2330 lod_obj_set_pool(mo, i, pool_name);
2332 if ((!mo->ldo_is_composite || lod_comp_inited(lod_comp)) &&
2333 !(lod_comp->llc_pattern & LOV_PATTERN_F_RELEASED) &&
2334 !(lod_comp->llc_pattern & LOV_PATTERN_MDT)) {
2335 rc = lod_initialize_objects(env, mo, objs, i);
2341 rc = lod_fill_mirrors(mo);
2345 lod_striping_free_nolock(env, mo);
2347 mutex_unlock(&mo->ldo_layout_mutex);
2352 void lod_qos_set_pool(struct lod_object *lo, int pos, const char *pool_name)
2354 struct lod_device *d = lu2lod_dev(lod2lu_obj(lo)->lo_dev);
2355 struct lod_layout_component *lod_comp;
2356 struct lod_pool_desc *pool = NULL;
2360 /* In the function below, .hs_keycmp resolves to
2361 * pool_hashkey_keycmp() */
2363 pool = lod_find_pool(d, pool_name);
2366 lod_obj_set_pool(lo, pos, pool_name);
2370 lod_comp = &lo->ldo_comp_entries[pos];
2371 if (lod_comp->llc_stripe_offset != LOV_OFFSET_DEFAULT) {
2372 if (lod_comp->llc_ostlist.op_count) {
2373 for (j = 0; j < lod_comp->llc_ostlist.op_count; j++) {
2374 idx = lod_comp->llc_ostlist.op_array[j];
2375 rc = lod_check_index_in_pool(idx, pool);
2380 idx = lod_comp->llc_stripe_offset;
2381 rc = lod_check_index_in_pool(idx, pool);
2385 CDEBUG(D_LAYOUT, "%s: index %u is not in the pool %s, "
2386 "dropping the pool\n", lod2obd(d)->obd_name,
2393 lod_comp->llc_stripe_count > pool_tgt_count(pool) &&
2394 !(lod_comp->llc_pattern & LOV_PATTERN_OVERSTRIPING))
2395 lod_comp->llc_stripe_count = pool_tgt_count(pool);
2397 lod_pool_putref(pool);
2398 lod_obj_set_pool(lo, pos, pool_name);
2402 * Parse suggested striping configuration.
2404 * The caller gets a suggested striping configuration from a number of sources
2405 * including per-directory default and applications. Then it needs to verify
2406 * the suggested striping is valid, apply missing bits and store the resulting
2407 * configuration in the object to be used by the allocator later. Must not be
2408 * called concurrently against the same object. It's OK to provide a
2409 * fully-defined striping.
2411 * \param[in] env execution environment for this thread
2412 * \param[in] lo LOD object
2413 * \param[in] buf buffer containing the striping
2415 * \retval 0 on success
2416 * \retval negative negated errno on error
2418 int lod_qos_parse_config(const struct lu_env *env, struct lod_object *lo,
2419 const struct lu_buf *buf)
2421 struct lod_layout_component *lod_comp;
2422 struct lod_device *d = lu2lod_dev(lod2lu_obj(lo)->lo_dev);
2423 struct lov_desc *desc = &d->lod_ost_descs.ltd_lov_desc;
2424 struct lov_user_md_v1 *v1 = NULL;
2425 struct lov_user_md_v3 *v3 = NULL;
2426 struct lov_comp_md_v1 *comp_v1 = NULL;
2427 struct lov_foreign_md *lfm = NULL;
2428 char def_pool[LOV_MAXPOOLNAME + 1];
2435 if (buf == NULL || buf->lb_buf == NULL || buf->lb_len == 0)
2438 memset(def_pool, 0, sizeof(def_pool));
2439 if (lo->ldo_comp_entries != NULL)
2440 lod_layout_get_pool(lo->ldo_comp_entries, lo->ldo_comp_cnt,
2441 def_pool, sizeof(def_pool));
2443 /* free default striping info */
2444 if (lo->ldo_is_foreign)
2445 lod_free_foreign_lov(lo);
2447 lod_free_comp_entries(lo);
2449 rc = lod_verify_striping(env, d, lo, buf, false);
2455 comp_v1 = buf->lb_buf;
2456 /* {lmm,lfm}_magic position/length work for all LOV formats */
2457 magic = v1->lmm_magic;
2459 if (unlikely(le32_to_cpu(magic) & LOV_MAGIC_DEFINED)) {
2460 /* try to use as fully defined striping */
2461 rc = lod_use_defined_striping(env, lo, buf);
2466 case __swab32(LOV_USER_MAGIC_V1):
2467 lustre_swab_lov_user_md_v1(v1);
2468 magic = v1->lmm_magic;
2470 case LOV_USER_MAGIC_V1:
2472 case __swab32(LOV_USER_MAGIC_V3):
2473 lustre_swab_lov_user_md_v3(v3);
2474 magic = v3->lmm_magic;
2476 case LOV_USER_MAGIC_V3:
2478 case __swab32(LOV_USER_MAGIC_SPECIFIC):
2479 lustre_swab_lov_user_md_v3(v3);
2480 lustre_swab_lov_user_md_objects(v3->lmm_objects,
2481 v3->lmm_stripe_count);
2482 magic = v3->lmm_magic;
2484 case LOV_USER_MAGIC_SPECIFIC:
2486 case __swab32(LOV_USER_MAGIC_COMP_V1):
2487 lustre_swab_lov_comp_md_v1(comp_v1);
2488 magic = comp_v1->lcm_magic;
2490 case LOV_USER_MAGIC_COMP_V1:
2492 case __swab32(LOV_USER_MAGIC_FOREIGN):
2494 __swab32s(&lfm->lfm_magic);
2495 __swab32s(&lfm->lfm_length);
2496 __swab32s(&lfm->lfm_type);
2497 __swab32s(&lfm->lfm_flags);
2498 magic = lfm->lfm_magic;
2500 case LOV_USER_MAGIC_FOREIGN:
2503 rc = lod_alloc_foreign_lov(lo, lov_foreign_size(lfm));
2506 memcpy(lo->ldo_foreign_lov, buf->lb_buf,
2507 lov_foreign_size(lfm));
2510 CERROR("%s: unrecognized magic %X\n",
2511 lod2obd(d)->obd_name, magic);
2515 lustre_print_user_md(D_OTHER, v1, "parse config");
2517 if (magic == LOV_USER_MAGIC_COMP_V1) {
2518 comp_cnt = comp_v1->lcm_entry_count;
2521 mirror_cnt = comp_v1->lcm_mirror_count + 1;
2523 lo->ldo_flr_state = LCM_FL_RDONLY;
2524 lo->ldo_is_composite = 1;
2528 lo->ldo_is_composite = 0;
2531 rc = lod_alloc_comp_entries(lo, mirror_cnt, comp_cnt);
2535 LASSERT(lo->ldo_comp_entries);
2537 for (i = 0; i < comp_cnt; i++) {
2538 struct lu_extent *ext;
2541 lod_comp = &lo->ldo_comp_entries[i];
2543 if (lo->ldo_is_composite) {
2544 v1 = (struct lov_user_md *)((char *)comp_v1 +
2545 comp_v1->lcm_entries[i].lcme_offset);
2546 ext = &comp_v1->lcm_entries[i].lcme_extent;
2547 lod_comp->llc_extent = *ext;
2548 lod_comp->llc_flags =
2549 comp_v1->lcm_entries[i].lcme_flags &
2554 if (def_pool[0] != '\0')
2555 pool_name = def_pool;
2557 if (v1->lmm_magic == LOV_USER_MAGIC_V3 ||
2558 v1->lmm_magic == LOV_USER_MAGIC_SPECIFIC) {
2559 v3 = (struct lov_user_md_v3 *)v1;
2561 if (lov_pool_is_ignored(v3->lmm_pool_name))
2563 else if (v3->lmm_pool_name[0] != '\0' &&
2564 !lov_pool_is_inherited(v3->lmm_pool_name))
2565 pool_name = v3->lmm_pool_name;
2567 if (v3->lmm_magic == LOV_USER_MAGIC_SPECIFIC) {
2568 rc = lod_comp_copy_ost_lists(lod_comp, v3);
2570 GOTO(free_comp, rc);
2574 if (v1->lmm_pattern == 0)
2575 v1->lmm_pattern = LOV_PATTERN_RAID0;
2576 if (!lov_pattern_supported(lov_pattern(v1->lmm_pattern))) {
2577 CDEBUG(D_LAYOUT, "%s: invalid pattern: %x\n",
2578 lod2obd(d)->obd_name, v1->lmm_pattern);
2579 GOTO(free_comp, rc = -EINVAL);
2582 lod_comp->llc_pattern = v1->lmm_pattern;
2583 lod_comp->llc_stripe_size = v1->lmm_stripe_size;
2584 lod_adjust_stripe_size(lod_comp, desc->ld_default_stripe_size);
2586 lod_comp->llc_stripe_count = desc->ld_default_stripe_count;
2587 if (v1->lmm_stripe_count ||
2588 (lov_pattern(v1->lmm_pattern) & LOV_PATTERN_MDT))
2589 lod_comp->llc_stripe_count = v1->lmm_stripe_count;
2591 if ((lov_pattern(lod_comp->llc_pattern) & LOV_PATTERN_MDT) &&
2592 lod_comp->llc_stripe_count != 0) {
2593 CDEBUG(D_LAYOUT, "%s: invalid stripe count: %u\n",
2594 lod2obd(d)->obd_name,
2595 lod_comp->llc_stripe_count);
2596 GOTO(free_comp, rc = -EINVAL);
2599 * limit stripe count so that it's less than/equal to
2600 * extent_size / stripe_size.
2602 * Note: extension size reused llc_stripe_size field and
2603 * uninstantiated component could be defined with
2604 * extent_start == extent_end as extension component will
2607 if (lo->ldo_is_composite &&
2608 !(lod_comp->llc_flags & LCME_FL_EXTENSION) &&
2609 !(lod_comp->llc_stripe_count >= LOV_ALL_STRIPES_MIN &&
2610 lod_comp->llc_stripe_count <= LOV_ALL_STRIPES_MAX) &&
2611 (lod_comp_inited(lod_comp) ||
2612 lod_comp->llc_extent.e_start <
2613 lod_comp->llc_extent.e_end) &&
2614 lod_comp->llc_extent.e_end != OBD_OBJECT_EOF &&
2615 lod_comp->llc_stripe_count * lod_comp->llc_stripe_size >
2616 (lod_comp->llc_extent.e_end - lod_comp->llc_extent.e_start))
2617 lod_comp->llc_stripe_count =
2618 DIV_ROUND_UP(lod_comp->llc_extent.e_end -
2619 lod_comp->llc_extent.e_start,
2620 lod_comp->llc_stripe_size);
2622 lod_comp->llc_stripe_offset = v1->lmm_stripe_offset;
2623 lod_qos_set_pool(lo, i, pool_name);
2629 lod_free_comp_entries(lo);
2634 * prepare enough OST avoidance bitmap space
2636 static int lod_prepare_avoidance(const struct lu_env *env,
2637 struct lod_object *lo)
2639 struct lod_device *lod = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
2640 struct lod_avoid_guide *lag = &lod_env_info(env)->lti_avoid;
2641 unsigned long *bitmap = NULL;
2642 __u32 *new_oss = NULL;
2644 lag->lag_ost_avail = lod->lod_ost_count;
2646 /* reset OSS avoid guide array */
2647 lag->lag_oaa_count = 0;
2648 if (lag->lag_oss_avoid_array &&
2649 lag->lag_oaa_size < lod->lod_ost_count) {
2650 OBD_FREE_PTR_ARRAY(lag->lag_oss_avoid_array, lag->lag_oaa_size);
2651 lag->lag_oss_avoid_array = NULL;
2652 lag->lag_oaa_size = 0;
2655 /* init OST avoid guide bitmap */
2656 if (lag->lag_ost_avoid_bitmap) {
2657 if (lod->lod_ost_count <= lag->lag_ost_avoid_size) {
2658 bitmap_zero(lag->lag_ost_avoid_bitmap,
2659 lag->lag_ost_avoid_size);
2661 bitmap_free(lag->lag_ost_avoid_bitmap);
2662 lag->lag_ost_avoid_bitmap = NULL;
2666 if (!lag->lag_ost_avoid_bitmap) {
2667 bitmap = bitmap_zalloc(lod->lod_ost_count, GFP_KERNEL);
2672 if (!lag->lag_oss_avoid_array) {
2674 * usually there are multiple OSTs in one OSS, but we don't
2675 * know the exact OSS number, so we choose a safe option,
2676 * using OST count to allocate the array to store the OSS
2679 OBD_ALLOC_PTR_ARRAY(new_oss, lod->lod_ost_count);
2681 bitmap_free(bitmap);
2687 lag->lag_oss_avoid_array = new_oss;
2688 lag->lag_oaa_size = lod->lod_ost_count;
2691 lag->lag_ost_avoid_bitmap = bitmap;
2692 lag->lag_ost_avoid_size = lod->lod_ost_count;
2699 * Collect information of used OSTs and OSSs in the overlapped components
2702 static void lod_collect_avoidance(struct lod_object *lo,
2703 struct lod_avoid_guide *lag,
2706 struct lod_device *lod = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
2707 struct lod_layout_component *lod_comp = &lo->ldo_comp_entries[comp_idx];
2708 unsigned long *bitmap = lag->lag_ost_avoid_bitmap;
2711 /* iterate components */
2712 for (i = 0; i < lo->ldo_comp_cnt; i++) {
2713 struct lod_layout_component *comp;
2716 * skip mirror containing component[comp_idx], we only
2717 * collect OSTs info of conflicting component in other mirrors,
2718 * so that during read, if OSTs of a mirror's component are
2719 * not available, we still have other mirror with different
2720 * OSTs to read the data.
2722 comp = &lo->ldo_comp_entries[i];
2723 if (comp->llc_id != LCME_ID_INVAL &&
2724 mirror_id_of(comp->llc_id) ==
2725 mirror_id_of(lod_comp->llc_id))
2729 * skip non-overlapped or un-instantiated components,
2730 * NOTE: don't use lod_comp_inited(comp) to judge
2731 * whether @comp has been inited, since during
2732 * declare phase, comp->llc_stripe has been allocated
2733 * while it's init flag not been set until the exec
2736 if (!lu_extent_is_overlapped(&comp->llc_extent,
2737 &lod_comp->llc_extent) ||
2742 * collect used OSTs index and OSS info from a
2745 for (j = 0; j < comp->llc_stripe_count; j++) {
2746 struct lod_tgt_desc *ost;
2747 struct lu_svr_qos *lsq;
2750 ost = OST_TGT(lod, comp->llc_ost_indices[j]);
2751 lsq = ost->ltd_qos.ltq_svr;
2753 if (test_bit(ost->ltd_index, bitmap))
2756 CDEBUG(D_OTHER, "OST%d used in conflicting mirror component\n", ost->ltd_index);
2757 set_bit(ost->ltd_index, bitmap);
2758 lag->lag_ost_avail--;
2760 for (k = 0; k < lag->lag_oaa_count; k++) {
2761 if (lag->lag_oss_avoid_array[k] ==
2765 if (k == lag->lag_oaa_count) {
2766 lag->lag_oss_avoid_array[k] =
2768 lag->lag_oaa_count++;
2775 * Create a striping for an obejct.
2777 * The function creates a new striping for the object. The function tries QoS
2778 * algorithm first unless free space is distributed evenly among OSTs, but
2779 * by default RR algorithm is preferred due to internal concurrency (QoS is
2780 * serialized). The caller must ensure no concurrent calls to the function
2781 * are made against the same object.
2783 * \param[in] env execution environment for this thread
2784 * \param[in] lo LOD object
2785 * \param[in] attr attributes OST objects will be declared with
2786 * \param[in] th transaction handle
2787 * \param[in] comp_idx index of ldo_comp_entries
2789 * \retval 0 on success
2790 * \retval negative negated errno on error
2792 int lod_qos_prep_create(const struct lu_env *env, struct lod_object *lo,
2793 struct lu_attr *attr, struct thandle *th,
2794 int comp_idx, __u64 reserve)
2796 struct lod_layout_component *lod_comp;
2797 struct lod_device *d = lu2lod_dev(lod2lu_obj(lo)->lo_dev);
2798 struct lod_avoid_guide *lag = &lod_env_info(env)->lti_avoid;
2799 struct dt_object **stripe = NULL;
2800 __u32 *ost_indices = NULL;
2801 enum lod_uses_hint flags = LOD_USES_ASSIGNED_STRIPE;
2807 LASSERT(lo->ldo_comp_cnt > comp_idx && lo->ldo_comp_entries != NULL);
2808 lod_comp = &lo->ldo_comp_entries[comp_idx];
2809 LASSERT(!(lod_comp->llc_flags & LCME_FL_EXTENSION));
2811 /* A foreign/HSM component is being created */
2812 if (lod_comp->llc_magic == LOV_MAGIC_FOREIGN)
2815 /* A released component is being created */
2816 if (lod_comp->llc_pattern & LOV_PATTERN_F_RELEASED)
2819 /* A Data-on-MDT component is being created */
2820 if (lov_pattern(lod_comp->llc_pattern) & LOV_PATTERN_MDT)
2823 if (lod_comp->llc_pool)
2824 lod_check_and_spill_pool(env, d, &lod_comp->llc_pool);
2826 if (likely(lod_comp->llc_stripe == NULL)) {
2828 * no striping has been created so far
2830 LASSERT(lod_comp->llc_stripe_count);
2832 * statfs and check OST targets now, since ld_active_tgt_count
2833 * could be changed if some OSTs are [de]activated manually.
2835 lod_qos_statfs_update(env, d, &d->lod_ost_descs);
2836 stripe_len = lod_get_stripe_count(d, lo, comp_idx,
2837 lod_comp->llc_stripe_count,
2838 lod_comp->llc_pattern &
2839 LOV_PATTERN_OVERSTRIPING,
2842 if (stripe_len == 0)
2843 GOTO(out, rc = -ERANGE);
2844 lod_comp->llc_stripe_count = stripe_len;
2845 OBD_ALLOC_PTR_ARRAY(stripe, stripe_len);
2847 GOTO(out, rc = -ENOMEM);
2848 OBD_ALLOC_PTR_ARRAY(ost_indices, stripe_len);
2850 GOTO(out, rc = -ENOMEM);
2853 lod_getref(&d->lod_ost_descs);
2854 /* XXX: support for non-0 files w/o objects */
2855 CDEBUG(D_OTHER, "tgt_count %d stripe_count %d\n",
2856 d->lod_ost_count, stripe_len);
2858 if (lod_comp->llc_ostlist.op_array &&
2859 lod_comp->llc_ostlist.op_count) {
2860 rc = lod_alloc_ost_list(env, lo, stripe, ost_indices,
2861 th, comp_idx, reserve);
2862 } else if (lod_comp->llc_stripe_offset == LOV_OFFSET_DEFAULT) {
2864 * collect OSTs and OSSs used in other mirrors whose
2865 * components cross the ldo_comp_entries[comp_idx]
2867 rc = lod_prepare_avoidance(env, lo);
2871 CDEBUG(D_OTHER, "collecting conflict osts for comp[%d]\n",
2873 lod_collect_avoidance(lo, lag, comp_idx);
2875 rc = lod_ost_alloc_qos(env, lo, stripe, ost_indices,
2876 flags, th, comp_idx, reserve);
2878 rc = lod_ost_alloc_rr(env, lo, stripe,
2879 ost_indices, flags, th,
2882 rc = lod_ost_alloc_specific(env, lo, stripe,
2883 ost_indices, flags, th,
2887 lod_putref(d, &d->lod_ost_descs);
2889 for (i = 0; i < stripe_len; i++)
2890 if (stripe[i] != NULL)
2891 dt_object_put(env, stripe[i]);
2893 /* In case there is no space on any OST, let's ignore
2894 * the @reserve space to avoid an error at the init
2895 * time, probably the actual IO will be less than the
2896 * given @reserve space (aka extension_size). */
2901 lod_comp->llc_stripe_count = 0;
2903 lod_comp->llc_layout_gen = 0;
2904 lod_comp->llc_stripe = stripe;
2905 lod_comp->llc_ost_indices = ost_indices;
2906 lod_comp->llc_stripes_allocated = stripe_len;
2910 * lod_qos_parse_config() found supplied buf as a predefined
2911 * striping (not a hint), so it allocated all the object
2912 * now we need to create them
2914 for (i = 0; i < lod_comp->llc_stripe_count; i++) {
2915 struct dt_object *o;
2917 o = lod_comp->llc_stripe[i];
2920 rc = lod_sub_declare_create(env, o, attr, NULL,
2923 CERROR("can't declare create: %d\n", rc);
2928 * Clear LCME_FL_INIT for the component so that
2929 * lod_striping_create() can create the striping objects
2932 lod_comp_unset_init(lod_comp);
2938 OBD_FREE_PTR_ARRAY(stripe, stripe_len);
2940 OBD_FREE_PTR_ARRAY(ost_indices, stripe_len);
2945 int lod_prepare_create(const struct lu_env *env, struct lod_object *lo,
2946 struct lu_attr *attr, const struct lu_buf *buf,
2950 struct lod_device *d = lu2lod_dev(lod2lu_obj(lo)->lo_dev);
2958 /* no OST available */
2959 /* XXX: should we be waiting a bit to prevent failures during
2960 * cluster initialization? */
2961 if (!d->lod_ost_count)
2965 * by this time, the object's ldo_stripe_count and ldo_stripe_size
2966 * contain default value for striping: taken from the parent
2967 * or from filesystem defaults
2969 * in case the caller is passing lovea with new striping config,
2970 * we may need to parse lovea and apply new configuration
2972 rc = lod_qos_parse_config(env, lo, buf);
2976 if (attr->la_valid & LA_SIZE)
2977 size = attr->la_size;
2980 * prepare OST object creation for the component covering file's
2981 * size, the 1st component (including plain layout file) is always
2984 for (i = 0; i < lo->ldo_comp_cnt; i++) {
2985 struct lod_layout_component *lod_comp;
2986 struct lu_extent *extent;
2988 lod_comp = &lo->ldo_comp_entries[i];
2989 extent = &lod_comp->llc_extent;
2990 CDEBUG(D_OTHER, "comp[%d] %lld "DEXT"\n", i, size, PEXT(extent));
2991 if (!lo->ldo_is_composite || size >= extent->e_start) {
2992 rc = lod_qos_prep_create(env, lo, attr, th, i, 0);