X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Flod%2Flod_qos.c;h=fa5903eb7fa18ccd3648186104144fedd64e55ee;hb=b384ea39e593cda1ac4d6fb8b955d0c7d1a1f67b;hp=6d32975f0f8b5be0163ed7caf319aa2ee5c75fae;hpb=e284bfbe78d008ebfaae14878893bc7200338f83;p=fs%2Flustre-release.git diff --git a/lustre/lod/lod_qos.c b/lustre/lod/lod_qos.c index 6d32975..fa5903e 100644 --- a/lustre/lod/lod_qos.c +++ b/lustre/lod/lod_qos.c @@ -65,17 +65,17 @@ static inline int lod_statfs_check(struct lu_tgt_descs *ltd, { struct obd_statfs *sfs = &tgt->ltd_statfs; - if (((sfs->os_state & OS_STATE_ENOSPC) || - (!ltd->ltd_is_mdt && sfs->os_state & OS_STATE_ENOINO && + if (((sfs->os_state & OS_STATFS_ENOSPC) || + (!ltd->ltd_is_mdt && sfs->os_state & OS_STATFS_ENOINO && sfs->os_fprecreated == 0))) return -ENOSPC; /* If the OST is readonly then we can't allocate objects there */ - if (sfs->os_state & OS_STATE_READONLY) + if (sfs->os_state & OS_STATFS_READONLY) return -EROFS; /* object precreation is skipped on the OST with max_create_count=0 */ - if (!ltd->ltd_is_mdt && sfs->os_state & OS_STATE_NOPRECREATE) + if (!ltd->ltd_is_mdt && sfs->os_state & OS_STATFS_NOPRECREATE) return -ENOBUFS; return 0; @@ -100,8 +100,9 @@ static inline int lod_statfs_check(struct lu_tgt_descs *ltd, */ static int lod_statfs_and_check(const struct lu_env *env, struct lod_device *d, struct lu_tgt_descs *ltd, - struct lu_tgt_desc *tgt) + struct lu_tgt_desc *tgt, __u64 reserve) { + struct obd_statfs_info info = { 0 }; struct lov_desc *desc = <d->ltd_lov_desc; int rc; ENTRY; @@ -109,7 +110,8 @@ static int lod_statfs_and_check(const struct lu_env *env, struct lod_device *d, LASSERT(d); LASSERT(tgt); - rc = dt_statfs(env, tgt->ltd_tgt, &tgt->ltd_statfs); + info.os_enable_pre = 1; + rc = dt_statfs_info(env, tgt->ltd_tgt, &tgt->ltd_statfs, &info); if (rc && rc != -ENOTCONN) CERROR("%s: statfs: rc = %d\n", lod2obd(d)->obd_name, rc); @@ -119,6 +121,11 @@ static int lod_statfs_and_check(const struct lu_env *env, struct lod_device *d, return rc; } + if (reserve && + (reserve + (info.os_reserved_mb_low << 20) > + tgt->ltd_statfs.os_bavail * tgt->ltd_statfs.os_bsize)) + return -ENOSPC; + /* check whether device has changed state (active, inactive) */ if (rc != 0 && tgt->ltd_active) { /* turned inactive? */ @@ -130,8 +137,8 @@ static int lod_statfs_and_check(const struct lu_env *env, struct lod_device *d, LASSERT(desc->ld_active_tgt_count > 0); desc->ld_active_tgt_count--; - ltd->ltd_qos.lq_dirty = 1; - ltd->ltd_qos.lq_rr.lqr_dirty = 1; + set_bit(LQ_DIRTY, <d->ltd_qos.lq_flags); + set_bit(LQ_DIRTY, <d->ltd_qos.lq_rr.lqr_flags); CDEBUG(D_CONFIG, "%s: turns inactive\n", tgt->ltd_exp->exp_obd->obd_name); } @@ -146,8 +153,8 @@ static int lod_statfs_and_check(const struct lu_env *env, struct lod_device *d, tgt->ltd_active = 1; tgt->ltd_connecting = 0; desc->ld_active_tgt_count++; - ltd->ltd_qos.lq_dirty = 1; - ltd->ltd_qos.lq_rr.lqr_dirty = 1; + set_bit(LQ_DIRTY, <d->ltd_qos.lq_flags); + set_bit(LQ_DIRTY, <d->ltd_qos.lq_rr.lqr_flags); CDEBUG(D_CONFIG, "%s: turns active\n", tgt->ltd_exp->exp_obd->obd_name); } @@ -211,12 +218,12 @@ void lod_qos_statfs_update(const struct lu_env *env, struct lod_device *lod, ltd_foreach_tgt(ltd, tgt) { avail = tgt->ltd_statfs.os_bavail; - if (lod_statfs_and_check(env, lod, ltd, tgt)) + if (lod_statfs_and_check(env, lod, ltd, tgt, 0)) continue; if (tgt->ltd_statfs.os_bavail != avail) /* recalculate weigths */ - ltd->ltd_qos.lq_dirty = 1; + set_bit(LQ_DIRTY, <d->ltd_qos.lq_flags); } obd->obd_osfs_age = ktime_get_seconds(); @@ -255,7 +262,7 @@ static int lod_qos_calc_rr(struct lod_device *lod, struct lu_tgt_descs *ltd, int rc; ENTRY; - if (!lqr->lqr_dirty) { + if (!test_bit(LQ_DIRTY, &lqr->lqr_flags)) { LASSERT(lqr->lqr_pool.op_size); RETURN(0); } @@ -267,7 +274,7 @@ static int lod_qos_calc_rr(struct lod_device *lod, struct lu_tgt_descs *ltd, * Check again. While we were sleeping on @lq_rw_sem something could * change. */ - if (!lqr->lqr_dirty) { + if (!test_bit(LQ_DIRTY, &lqr->lqr_flags)) { LASSERT(lqr->lqr_pool.op_size); up_write(<d->ltd_qos.lq_rw_sem); RETURN(0); @@ -280,7 +287,7 @@ static int lod_qos_calc_rr(struct lod_device *lod, struct lu_tgt_descs *ltd, deleting from the pool. The lq_rw_sem insures that nobody else is reading. */ lqr->lqr_pool.op_count = real_count; - rc = lod_tgt_pool_extend(&lqr->lqr_pool, real_count); + rc = tgt_pool_extend(&lqr->lqr_pool, real_count); if (rc) { up_write(<d->ltd_qos.lq_rw_sem); RETURN(rc); @@ -296,8 +303,8 @@ static int lod_qos_calc_rr(struct lod_device *lod, struct lu_tgt_descs *ltd, for (i = 0; i < lqr->lqr_pool.op_count; i++) { int next; - if (!cfs_bitmap_check(ltd->ltd_tgt_bitmap, - src_pool->op_array[i])) + if (!test_bit(src_pool->op_array[i], + ltd->ltd_tgt_bitmap)) continue; tgt = LTD_TGT(ltd, src_pool->op_array[i]); @@ -316,7 +323,7 @@ static int lod_qos_calc_rr(struct lod_device *lod, struct lu_tgt_descs *ltd, } } - lqr->lqr_dirty = 0; + clear_bit(LQ_DIRTY, &lqr->lqr_flags); up_write(<d->ltd_qos.lq_rw_sem); if (placed != real_count) { @@ -328,7 +335,7 @@ static int lod_qos_calc_rr(struct lod_device *lod, struct lu_tgt_descs *ltd, LCONSOLE(D_WARNING, "rr #%d tgt idx=%d\n", i, lqr->lqr_pool.op_array[i]); } - lqr->lqr_dirty = 1; + set_bit(LQ_DIRTY, &lqr->lqr_flags); RETURN(-EAGAIN); } @@ -363,8 +370,10 @@ static int lod_qos_calc_rr(struct lod_device *lod, struct lu_tgt_descs *ltd, static struct dt_object *lod_qos_declare_object_on(const struct lu_env *env, struct lod_device *d, __u32 ost_idx, + bool can_block, struct thandle *th) { + struct dt_allocation_hint *ah = &lod_env_info(env)->lti_ah; struct lod_tgt_desc *ost; struct lu_object *o, *n; struct lu_device *nd; @@ -387,7 +396,7 @@ static struct dt_object *lod_qos_declare_object_on(const struct lu_env *env, */ o = lu_object_anon(env, nd, NULL); if (IS_ERR(o)) - GOTO(out, dt = ERR_PTR(PTR_ERR(o))); + GOTO(out, dt = ERR_CAST(o)); n = lu_object_locate(o->lo_header, nd->ld_type); if (unlikely(n == NULL)) { @@ -398,7 +407,8 @@ static struct dt_object *lod_qos_declare_object_on(const struct lu_env *env, dt = container_of(n, struct dt_object, do_lu); - rc = lod_sub_declare_create(env, dt, NULL, NULL, NULL, th); + ah->dah_can_block = can_block; + rc = lod_sub_declare_create(env, dt, NULL, ah, NULL, th); if (rc < 0) { CDEBUG(D_OTHER, "can't declare creation on #%u: %d\n", ost_idx, rc); @@ -572,7 +582,7 @@ static inline bool lod_should_avoid_ost(struct lod_object *lo, bool used = false; int i; - if (!cfs_bitmap_check(lod->lod_ost_bitmap, index)) { + if (!test_bit(index, lod->lod_ost_bitmap)) { QOS_DEBUG("OST%d: been used in conflicting mirror component\n", index); return true; @@ -600,7 +610,7 @@ static inline bool lod_should_avoid_ost(struct lod_object *lo, return false; /* if the OSS has been used, check whether the OST has been used */ - if (!cfs_bitmap_check(lag->lag_ost_avoid_bitmap, index)) + if (!test_bit(index, lag->lag_ost_avoid_bitmap)) used = false; else QOS_DEBUG("OST%d: been used in conflicting mirror component\n", @@ -615,7 +625,8 @@ static int lod_check_and_reserve_ost(const struct lu_env *env, struct dt_object **stripe, __u32 *ost_indices, struct thandle *th, - bool *overstriped) + bool *overstriped, + __u64 reserve) { struct lod_device *lod = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev); struct lod_avoid_guide *lag = &lod_env_info(env)->lti_avoid; @@ -626,7 +637,7 @@ static int lod_check_and_reserve_ost(const struct lu_env *env, ENTRY; - rc = lod_statfs_and_check(env, lod, &lod->lod_ost_descs, ost); + rc = lod_statfs_and_check(env, lod, &lod->lod_ost_descs, ost, reserve); if (rc) RETURN(rc); @@ -642,7 +653,7 @@ static int lod_check_and_reserve_ost(const struct lu_env *env, /* * try to use another OSP if this one is degraded */ - if (ost->ltd_statfs.os_state & OS_STATE_DEGRADED && speed < 2) { + if (ost->ltd_statfs.os_state & OS_STATFS_DEGRADED && speed < 2) { QOS_DEBUG("#%d: degraded\n", ost_idx); RETURN(rc); } @@ -675,7 +686,7 @@ static int lod_check_and_reserve_ost(const struct lu_env *env, RETURN(rc); } - o = lod_qos_declare_object_on(env, lod, ost_idx, th); + o = lod_qos_declare_object_on(env, lod, ost_idx, true, th); if (IS_ERR(o)) { CDEBUG(D_OTHER, "can't declare new object on #%u: %d\n", ost_idx, (int) PTR_ERR(o)); @@ -725,7 +736,8 @@ static int lod_check_and_reserve_ost(const struct lu_env *env, */ static int lod_ost_alloc_rr(const struct lu_env *env, struct lod_object *lo, struct dt_object **stripe, __u32 *ost_indices, - int flags, struct thandle *th, int comp_idx) + int flags, struct thandle *th, int comp_idx, + __u64 reserve) { struct lod_layout_component *lod_comp; struct lod_device *m = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev); @@ -808,7 +820,7 @@ repeat_find: stripe_idx, array_idx, ost_idx); if ((ost_idx == LOV_QOS_EMPTY) || - !cfs_bitmap_check(m->lod_ost_bitmap, ost_idx)) + !test_bit(ost_idx, m->lod_ost_bitmap)) continue; /* Fail Check before osc_precreate() is called @@ -819,7 +831,8 @@ repeat_find: spin_unlock(&lqr->lqr_alloc); rc = lod_check_and_reserve_ost(env, lo, lod_comp, ost_idx, speed, &stripe_idx, stripe, - ost_indices, th, &overstriped); + ost_indices, th, &overstriped, + reserve); spin_lock(&lqr->lqr_alloc); if (rc != 0 && OST_TGT(m, ost_idx)->ltd_connecting) @@ -890,7 +903,7 @@ lod_qos_mdt_in_use_init(const struct lu_env *env, for (j = 0; j < pool->op_count; j++) { mdt_idx = pool->op_array[j]; - if (!cfs_bitmap_check(ltd->ltd_tgt_bitmap, mdt_idx)) + if (!test_bit(mdt_idx, ltd->ltd_tgt_bitmap)) continue; mdt = LTD_TGT(ltd, mdt_idx); @@ -993,7 +1006,7 @@ repeat_find: stripe_idx, pool_idx, mdt_idx); if (mdt_idx == LOV_QOS_EMPTY || - !cfs_bitmap_check(ltd->ltd_tgt_bitmap, mdt_idx)) + !test_bit(mdt_idx, ltd->ltd_tgt_bitmap)) continue; /* do not put >1 objects on one MDT */ @@ -1008,14 +1021,14 @@ repeat_find: } /* try to use another OSP if this one is degraded */ - if (mdt->ltd_statfs.os_state & OS_STATE_DEGRADED && + if (mdt->ltd_statfs.os_state & OS_STATFS_DEGRADED && !use_degraded) { QOS_DEBUG("#%d: degraded\n", mdt_idx); continue; } spin_unlock(&lqr->lqr_alloc); - rc = obd_fid_alloc(env, mdt->ltd_exp, &fid, NULL); + rc = dt_fid_alloc(env, mdt->ltd_tgt, &fid, NULL, NULL); if (rc < 0) { QOS_DEBUG("#%d: alloc FID failed: %dl\n", mdt_idx, rc); spin_lock(&lqr->lqr_alloc); @@ -1089,7 +1102,7 @@ repeat_find: */ static int lod_alloc_ost_list(const struct lu_env *env, struct lod_object *lo, struct dt_object **stripe, __u32 *ost_indices, - struct thandle *th, int comp_idx) + struct thandle *th, int comp_idx, __u64 reserve) { struct lod_layout_component *lod_comp; struct lod_device *m = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev); @@ -1132,7 +1145,7 @@ static int lod_alloc_ost_list(const struct lu_env *env, struct lod_object *lo, i++, array_idx = (array_idx + 1) % lod_comp->llc_stripe_count) { __u32 ost_idx = lod_comp->llc_ostlist.op_array[array_idx]; - if (!cfs_bitmap_check(m->lod_ost_bitmap, ost_idx)) { + if (!test_bit(ost_idx, m->lod_ost_bitmap)) { rc = -ENODEV; break; } @@ -1147,11 +1160,12 @@ static int lod_alloc_ost_list(const struct lu_env *env, struct lod_object *lo, } rc = lod_statfs_and_check(env, m, &m->lod_ost_descs, - LTD_TGT(&m->lod_ost_descs, ost_idx)); + LTD_TGT(&m->lod_ost_descs, ost_idx), + reserve); if (rc < 0) /* this OSP doesn't feel well */ break; - o = lod_qos_declare_object_on(env, m, ost_idx, th); + o = lod_qos_declare_object_on(env, m, ost_idx, true, th); if (IS_ERR(o)) { rc = PTR_ERR(o); CDEBUG(D_OTHER, @@ -1201,7 +1215,8 @@ static int lod_alloc_ost_list(const struct lu_env *env, struct lod_object *lo, static int lod_ost_alloc_specific(const struct lu_env *env, struct lod_object *lo, struct dt_object **stripe, __u32 *ost_indices, - int flags, struct thandle *th, int comp_idx) + int flags, struct thandle *th, int comp_idx, + __u64 reserve) { struct lod_layout_component *lod_comp; struct lod_device *m = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev); @@ -1260,7 +1275,7 @@ repeat_find: i++, array_idx = (array_idx + 1) % ost_count) { ost_idx = osts->op_array[array_idx]; - if (!cfs_bitmap_check(m->lod_ost_bitmap, ost_idx)) + if (!test_bit(ost_idx, m->lod_ost_bitmap)) continue; /* Fail Check before osc_precreate() is called @@ -1294,7 +1309,8 @@ repeat_find: * start OST, then it can be skipped, otherwise skip it only * if it is inactive/recovering/out-of-space." */ - rc = lod_statfs_and_check(env, m, &m->lod_ost_descs, tgt); + rc = lod_statfs_and_check(env, m, &m->lod_ost_descs, + tgt, reserve); if (rc) { /* this OSP doesn't feel well */ continue; @@ -1308,7 +1324,7 @@ repeat_find: if (i && !tgt->ltd_statfs.os_fprecreated && !speed) continue; - o = lod_qos_declare_object_on(env, m, ost_idx, th); + o = lod_qos_declare_object_on(env, m, ost_idx, true, th); if (IS_ERR(o)) { CDEBUG(D_OTHER, "can't declare new object on #%u: %d\n", ost_idx, (int) PTR_ERR(o)); @@ -1395,7 +1411,8 @@ out: */ static int lod_ost_alloc_qos(const struct lu_env *env, struct lod_object *lo, struct dt_object **stripe, __u32 *ost_indices, - int flags, struct thandle *th, int comp_idx) + int flags, struct thandle *th, int comp_idx, + __u64 reserve) { struct lod_layout_component *lod_comp; struct lod_device *lod = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev); @@ -1409,6 +1426,7 @@ static int lod_ost_alloc_qos(const struct lu_env *env, struct lod_object *lo, __u32 nfound, good_osts, stripe_count, stripe_count_min; bool overstriped = false; int stripes_per_ost = 1; + bool slow = false; int rc = 0; ENTRY; @@ -1458,19 +1476,20 @@ static int lod_ost_alloc_qos(const struct lu_env *env, struct lod_object *lo, good_osts = 0; /* Find all the OSTs that are valid stripe candidates */ for (i = 0; i < osts->op_count; i++) { - if (!cfs_bitmap_check(lod->lod_ost_bitmap, osts->op_array[i])) + if (!test_bit(osts->op_array[i], lod->lod_ost_bitmap)) continue; ost = OST_TGT(lod, osts->op_array[i]); ost->ltd_qos.ltq_usable = 0; - rc = lod_statfs_and_check(env, lod, &lod->lod_ost_descs, ost); + rc = lod_statfs_and_check(env, lod, &lod->lod_ost_descs, + ost, reserve); if (rc) { /* this OSP doesn't feel well */ continue; } - if (ost->ltd_statfs.os_state & OS_STATE_DEGRADED) + if (ost->ltd_statfs.os_state & OS_STATFS_DEGRADED) continue; /* Fail Check before osc_precreate() is called @@ -1513,6 +1532,7 @@ static int lod_ost_alloc_qos(const struct lu_env *env, struct lod_object *lo, */ for (i = 0; i < osts->op_count; i++) { __u32 idx = osts->op_array[i]; + struct lod_tgt_desc *ost = OST_TGT(lod, idx); if (lod_should_avoid_ost(lo, lag, idx)) continue; @@ -1548,7 +1568,7 @@ static int lod_ost_alloc_qos(const struct lu_env *env, struct lod_object *lo, continue; } - o = lod_qos_declare_object_on(env, lod, idx, th); + o = lod_qos_declare_object_on(env, lod, idx, slow, th); if (IS_ERR(o)) { QOS_DEBUG("can't declare object on #%u: %d\n", idx, (int) PTR_ERR(o)); @@ -1565,6 +1585,13 @@ static int lod_ost_alloc_qos(const struct lu_env *env, struct lod_object *lo, break; } + if (rc && !slow && nfound < stripe_count) { + /* couldn't allocate using precreated objects + * so try to wait for new precreations */ + slow = true; + rc = 0; + } + if (rc) { /* no OST found on this iteration, give up */ break; @@ -1588,9 +1615,8 @@ static int lod_ost_alloc_qos(const struct lu_env *env, struct lod_object *lo, } /* makes sense to rebalance next time */ - lod->lod_ost_descs.ltd_qos.lq_dirty = 1; - lod->lod_ost_descs.ltd_qos.lq_same_space = 0; - + set_bit(LQ_DIRTY, &lod->lod_ost_descs.ltd_qos.lq_flags); + clear_bit(LQ_SAME_SPACE, &lod->lod_ost_descs.ltd_qos.lq_flags); rc = -EAGAIN; } @@ -1702,7 +1728,7 @@ int lod_mdt_alloc_qos(const struct lu_env *env, struct lod_object *lo, good_mdts = 0; /* Find all the MDTs that are valid stripe candidates */ for (i = 0; i < pool->op_count; i++) { - if (!cfs_bitmap_check(ltd->ltd_tgt_bitmap, pool->op_array[i])) + if (!test_bit(pool->op_array[i], ltd->ltd_tgt_bitmap)) continue; mdt = LTD_TGT(ltd, pool->op_array[i]); @@ -1712,7 +1738,7 @@ int lod_mdt_alloc_qos(const struct lu_env *env, struct lod_object *lo, if (rc) continue; - if (mdt->ltd_statfs.os_state & OS_STATE_DEGRADED) + if (mdt->ltd_statfs.os_state & OS_STATFS_DEGRADED) continue; mdt->ltd_qos.ltq_usable = 1; @@ -1762,7 +1788,7 @@ int lod_mdt_alloc_qos(const struct lu_env *env, struct lod_object *lo, if (lod_qos_is_tgt_used(env, mdt_idx, stripe_idx)) continue; - rc2 = obd_fid_alloc(env, mdt->ltd_exp, &fid, NULL); + rc2 = dt_fid_alloc(env, mdt->ltd_tgt, &fid, NULL, NULL); if (rc2 < 0) { QOS_DEBUG("can't alloc FID on #%u: %d\n", mdt_idx, rc2); @@ -1809,8 +1835,8 @@ int lod_mdt_alloc_qos(const struct lu_env *env, struct lod_object *lo, } /* makes sense to rebalance next time */ - ltd->ltd_qos.lq_dirty = 1; - ltd->ltd_qos.lq_same_space = 0; + set_bit(LQ_DIRTY, <d->ltd_qos.lq_flags); + clear_bit(LQ_SAME_SPACE, <d->ltd_qos.lq_flags); rc = -EAGAIN; } else { @@ -1836,19 +1862,20 @@ unlock: * * \param[in] lod LOD device * \param[in] lo The lod_object + * \param[in] comp_idx The component id, which the amount of stripes is + calculated for * \param[in] stripe_count count the caller would like to use * * \retval the maximum usable stripe count */ __u16 lod_get_stripe_count(struct lod_device *lod, struct lod_object *lo, - __u16 stripe_count, bool overstriping) + int comp_idx, __u16 stripe_count, bool overstriping) { __u32 max_stripes = LOV_MAX_STRIPE_COUNT_OLD; /* max stripe count is based on OSD ea size */ unsigned int easize = lod->lod_osd_max_easize; int i; - if (!stripe_count) stripe_count = lod->lod_ost_descs.ltd_lov_desc.ld_default_stripe_count; @@ -1872,9 +1899,17 @@ __u16 lod_get_stripe_count(struct lod_device *lod, struct lod_object *lo, lo->ldo_comp_cnt; for (i = 0; i < lo->ldo_comp_cnt; i++) { + unsigned int stripes; + + if (i == comp_idx) + continue; + lod_comp = &lo->ldo_comp_entries[i]; - comp_sz = lov_mds_md_size(lod_comp->llc_stripe_count, - LOV_MAGIC_V3); + /* Extension comp is never inited - 0 stripes on disk */ + stripes = lod_comp->llc_flags & LCME_FL_EXTENSION ? 0 : + lod_comp->llc_stripe_count; + + comp_sz = lov_mds_md_size(stripes, LOV_MAGIC_V3); total_comp_sz += comp_sz; if (lod_comp->llc_flags & LCME_FL_INIT) init_comp_sz += comp_sz; @@ -2102,7 +2137,7 @@ int lod_qos_parse_config(const struct lu_env *env, struct lod_object *lo, else lod_free_comp_entries(lo); - rc = lod_verify_striping(d, lo, buf, false); + rc = lod_verify_striping(env, d, lo, buf, false); if (rc) RETURN(-EINVAL); @@ -2207,9 +2242,13 @@ int lod_qos_parse_config(const struct lu_env *env, struct lod_object *lo, } pool_name = NULL; + if (def_pool[0] != '\0') + pool_name = def_pool; + if (v1->lmm_magic == LOV_USER_MAGIC_V3 || v1->lmm_magic == LOV_USER_MAGIC_SPECIFIC) { v3 = (struct lov_user_md_v3 *)v1; + if (v3->lmm_pool_name[0] != '\0') pool_name = v3->lmm_pool_name; @@ -2217,12 +2256,11 @@ int lod_qos_parse_config(const struct lu_env *env, struct lod_object *lo, rc = lod_comp_copy_ost_lists(lod_comp, v3); if (rc) GOTO(free_comp, rc); + + pool_name = NULL; } } - if (pool_name == NULL && def_pool[0] != '\0') - pool_name = def_pool; - if (v1->lmm_pattern == 0) v1->lmm_pattern = LOV_PATTERN_RAID0; if (lov_pattern(v1->lmm_pattern) != LOV_PATTERN_RAID0 && @@ -2297,7 +2335,7 @@ int lod_prepare_avoidance(const struct lu_env *env, struct lod_object *lo) { struct lod_device *lod = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev); struct lod_avoid_guide *lag = &lod_env_info(env)->lti_avoid; - struct cfs_bitmap *bitmap = NULL; + unsigned long *bitmap = NULL; __u32 *new_oss = NULL; lag->lag_ost_avail = lod->lod_ost_count; @@ -2306,24 +2344,24 @@ int lod_prepare_avoidance(const struct lu_env *env, struct lod_object *lo) lag->lag_oaa_count = 0; if (lag->lag_oss_avoid_array && lag->lag_oaa_size < lod->lod_ost_count) { - OBD_FREE(lag->lag_oss_avoid_array, - sizeof(__u32) * lag->lag_oaa_size); + OBD_FREE_PTR_ARRAY(lag->lag_oss_avoid_array, lag->lag_oaa_size); lag->lag_oss_avoid_array = NULL; lag->lag_oaa_size = 0; } /* init OST avoid guide bitmap */ if (lag->lag_ost_avoid_bitmap) { - if (lod->lod_ost_count <= lag->lag_ost_avoid_bitmap->size) { - CFS_RESET_BITMAP(lag->lag_ost_avoid_bitmap); + if (lod->lod_ost_count <= lag->lag_ost_avoid_size) { + bitmap_zero(lag->lag_ost_avoid_bitmap, + lag->lag_ost_avoid_size); } else { - CFS_FREE_BITMAP(lag->lag_ost_avoid_bitmap); + bitmap_free(lag->lag_ost_avoid_bitmap); lag->lag_ost_avoid_bitmap = NULL; } } if (!lag->lag_ost_avoid_bitmap) { - bitmap = CFS_ALLOCATE_BITMAP(lod->lod_ost_count); + bitmap = bitmap_zalloc(lod->lod_ost_count, GFP_KERNEL); if (!bitmap) return -ENOMEM; } @@ -2335,9 +2373,9 @@ int lod_prepare_avoidance(const struct lu_env *env, struct lod_object *lo) * using OST count to allocate the array to store the OSS * id. */ - OBD_ALLOC(new_oss, sizeof(*new_oss) * lod->lod_ost_count); + OBD_ALLOC_PTR_ARRAY(new_oss, lod->lod_ost_count); if (!new_oss) { - CFS_FREE_BITMAP(bitmap); + bitmap_free(bitmap); return -ENOMEM; } } @@ -2346,8 +2384,10 @@ int lod_prepare_avoidance(const struct lu_env *env, struct lod_object *lo) lag->lag_oss_avoid_array = new_oss; lag->lag_oaa_size = lod->lod_ost_count; } - if (bitmap) + if (bitmap) { lag->lag_ost_avoid_bitmap = bitmap; + lag->lag_ost_avoid_size = lod->lod_ost_count; + } return 0; } @@ -2361,7 +2401,7 @@ void lod_collect_avoidance(struct lod_object *lo, struct lod_avoid_guide *lag, { struct lod_device *lod = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev); struct lod_layout_component *lod_comp = &lo->ldo_comp_entries[comp_idx]; - struct cfs_bitmap *bitmap = lag->lag_ost_avoid_bitmap; + unsigned long *bitmap = lag->lag_ost_avoid_bitmap; int i, j; /* iterate mirrors */ @@ -2408,12 +2448,12 @@ void lod_collect_avoidance(struct lod_object *lo, struct lod_avoid_guide *lag, ost = OST_TGT(lod, comp->llc_ost_indices[j]); lsq = ost->ltd_qos.ltq_svr; - if (cfs_bitmap_check(bitmap, ost->ltd_index)) + if (test_bit(ost->ltd_index, bitmap)) continue; QOS_DEBUG("OST%d used in conflicting mirror " "component\n", ost->ltd_index); - cfs_bitmap_set(bitmap, ost->ltd_index); + set_bit(ost->ltd_index, bitmap); lag->lag_ost_avail--; for (k = 0; k < lag->lag_oaa_count; k++) { @@ -2451,7 +2491,7 @@ void lod_collect_avoidance(struct lod_object *lo, struct lod_avoid_guide *lag, */ int lod_qos_prep_create(const struct lu_env *env, struct lod_object *lo, struct lu_attr *attr, struct thandle *th, - int comp_idx) + int comp_idx, __u64 reserve) { struct lod_layout_component *lod_comp; struct lod_device *d = lu2lod_dev(lod2lu_obj(lo)->lo_dev); @@ -2486,7 +2526,7 @@ int lod_qos_prep_create(const struct lu_env *env, struct lod_object *lo, * could be changed if some OSTs are [de]activated manually. */ lod_qos_statfs_update(env, d, &d->lod_ost_descs); - stripe_len = lod_get_stripe_count(d, lo, + stripe_len = lod_get_stripe_count(d, lo, comp_idx, lod_comp->llc_stripe_count, lod_comp->llc_pattern & LOV_PATTERN_OVERSTRIPING); @@ -2494,13 +2534,14 @@ int lod_qos_prep_create(const struct lu_env *env, struct lod_object *lo, if (stripe_len == 0) GOTO(out, rc = -ERANGE); lod_comp->llc_stripe_count = stripe_len; - OBD_ALLOC(stripe, sizeof(stripe[0]) * stripe_len); + OBD_ALLOC_PTR_ARRAY(stripe, stripe_len); if (stripe == NULL) GOTO(out, rc = -ENOMEM); - OBD_ALLOC(ost_indices, sizeof(*ost_indices) * stripe_len); + OBD_ALLOC_PTR_ARRAY(ost_indices, stripe_len); if (!ost_indices) GOTO(out, rc = -ENOMEM); +repeat: lod_getref(&d->lod_ost_descs); /* XXX: support for non-0 files w/o objects */ CDEBUG(D_OTHER, "tgt_count %d stripe_count %d\n", @@ -2509,7 +2550,7 @@ int lod_qos_prep_create(const struct lu_env *env, struct lod_object *lo, if (lod_comp->llc_ostlist.op_array && lod_comp->llc_ostlist.op_count) { rc = lod_alloc_ost_list(env, lo, stripe, ost_indices, - th, comp_idx); + th, comp_idx, reserve); } else if (lod_comp->llc_stripe_offset == LOV_OFFSET_DEFAULT) { /** * collect OSTs and OSSs used in other mirrors whose @@ -2524,15 +2565,15 @@ int lod_qos_prep_create(const struct lu_env *env, struct lod_object *lo, lod_collect_avoidance(lo, lag, comp_idx); rc = lod_ost_alloc_qos(env, lo, stripe, ost_indices, - flag, th, comp_idx); + flag, th, comp_idx, reserve); if (rc == -EAGAIN) rc = lod_ost_alloc_rr(env, lo, stripe, ost_indices, flag, th, - comp_idx); + comp_idx, reserve); } else { rc = lod_ost_alloc_specific(env, lo, stripe, ost_indices, flag, th, - comp_idx); + comp_idx, reserve); } put_ldts: lod_putref(d, &d->lod_ost_descs); @@ -2540,6 +2581,15 @@ put_ldts: for (i = 0; i < stripe_len; i++) if (stripe[i] != NULL) dt_object_put(env, stripe[i]); + + /* In case there is no space on any OST, let's ignore + * the @reserve space to avoid an error at the init + * time, probably the actual IO will be less than the + * given @reserve space (aka extension_size). */ + if (reserve) { + reserve = 0; + goto repeat; + } lod_comp->llc_stripe_count = 0; } else { lod_comp->llc_stripe = stripe; @@ -2576,10 +2626,9 @@ put_ldts: out: if (rc < 0) { if (stripe) - OBD_FREE(stripe, sizeof(stripe[0]) * stripe_len); + OBD_FREE_PTR_ARRAY(stripe, stripe_len); if (ost_indices) - OBD_FREE(ost_indices, - sizeof(*ost_indices) * stripe_len); + OBD_FREE_PTR_ARRAY(ost_indices, stripe_len); } RETURN(rc); } @@ -2631,7 +2680,7 @@ int lod_prepare_create(const struct lu_env *env, struct lod_object *lo, extent = &lod_comp->llc_extent; QOS_DEBUG("comp[%d] %lld "DEXT"\n", i, size, PEXT(extent)); if (!lo->ldo_is_composite || size >= extent->e_start) { - rc = lod_qos_prep_create(env, lo, attr, th, i); + rc = lod_qos_prep_create(env, lo, attr, th, i, 0); if (rc) break; }