X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Flmv%2Flmv_obd.c;h=659d3dec07a126de23803c6da5b2ba11d3feb768;hp=e7e67b8805f9c4b80e3c3c8ca4e0a5e5326e8e93;hb=8d161d44214f907a9f2d9cf5a79cd2c83de995c3;hpb=38fa948b83523004576a9c19cf38258bca67ad50;ds=sidebyside diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index e7e67b8..659d3de 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -60,6 +60,7 @@ #include #include #include +#include #include "lmv_internal.h" /* This hash is only for testing purpose */ @@ -89,39 +90,35 @@ lmv_hash_fnv1a(unsigned int count, const char *name, int namelen) return hash; } -int lmv_name_to_stripe_index(enum lmv_hash_type hashtype, - unsigned int max_mdt_index, +int lmv_name_to_stripe_index(__u32 lmv_hash_type, unsigned int stripe_count, const char *name, int namelen) { int idx; + __u32 hash_type = lmv_hash_type & LMV_HASH_TYPE_MASK; LASSERT(namelen > 0); - if (max_mdt_index <= 1) + if (stripe_count <= 1) return 0; - switch (hashtype) { + /* for migrating object, always start from 0 stripe */ + if (lmv_hash_type & LMV_HASH_FLAG_MIGRATION) + return 0; + + switch (hash_type) { case LMV_HASH_TYPE_ALL_CHARS: - idx = lmv_hash_all_chars(max_mdt_index, name, namelen); + idx = lmv_hash_all_chars(stripe_count, name, namelen); break; case LMV_HASH_TYPE_FNV_1A_64: - idx = lmv_hash_fnv1a(max_mdt_index, name, namelen); + idx = lmv_hash_fnv1a(stripe_count, name, namelen); break; - /* LMV_HASH_TYPE_MIGRATION means the file is being migrated, - * and the file should be accessed by client, except for - * lookup(see lmv_intent_lookup), return -EACCES here */ - case LMV_HASH_TYPE_MIGRATION: - CERROR("%.*s is being migrated: rc = %d\n", namelen, - name, -EACCES); - return -EACCES; default: - CERROR("Unknown hash type 0x%x\n", hashtype); + CERROR("Unknown hash type 0x%x\n", hash_type); return -EINVAL; } CDEBUG(D_INFO, "name %.*s hash_type %d idx %d\n", namelen, name, - hashtype, idx); + hash_type, idx); - LASSERT(idx < max_mdt_index); return idx; } @@ -301,14 +298,14 @@ static int lmv_connect(const struct lu_env *env, if (data) lmv->conn_data = *data; - if (obd->obd_type->typ_procsym == NULL) { - obd->obd_type->typ_procsym = lprocfs_seq_register("target_obds", - obd->obd_proc_entry, - NULL, NULL); - if (IS_ERR(obd->obd_type->typ_procsym)) { + if (lmv->targets_proc_entry == NULL) { + lmv->targets_proc_entry = lprocfs_seq_register("target_obds", + obd->obd_proc_entry, + NULL, NULL); + if (IS_ERR(lmv->targets_proc_entry)) { CERROR("could not register /proc/fs/lustre/%s/%s/target_obds.", obd->obd_type->typ_name, obd->obd_name); - obd->obd_type->typ_procsym = NULL; + lmv->targets_proc_entry = NULL; } } @@ -321,9 +318,9 @@ static int lmv_connect(const struct lu_env *env, if (data != NULL && (data->ocd_connect_flags & OBD_CONNECT_REAL)) rc = lmv_check_connect(obd); - if (rc && obd->obd_type->typ_procsym != NULL) - lprocfs_remove(&obd->obd_type->typ_procsym); - RETURN(rc); + if (rc && lmv->targets_proc_entry != NULL) + lprocfs_remove(&lmv->targets_proc_entry); + RETURN(rc); } static void lmv_set_timeouts(struct obd_device *obd) @@ -482,13 +479,13 @@ int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt) mdc_obd->obd_name, mdc_obd->obd_uuid.uuid, atomic_read(&obd->obd_refcount)); - if (obd->obd_type->typ_procsym != NULL) { + if (lmv->targets_proc_entry != NULL) { struct proc_dir_entry *mdc_symlink; LASSERT(mdc_obd->obd_type != NULL); LASSERT(mdc_obd->obd_type->typ_name != NULL); mdc_symlink = lprocfs_add_symlink(mdc_obd->obd_name, - obd->obd_type->typ_procsym, + lmv->targets_proc_entry, "../../../%s/%s", mdc_obd->obd_type->typ_name, mdc_obd->obd_name); @@ -497,7 +494,6 @@ int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt) "/proc/fs/lustre/%s/%s/target_obds/%s.", obd->obd_type->typ_name, obd->obd_name, mdc_obd->obd_name); - lprocfs_remove(&obd->obd_type->typ_procsym); } } RETURN(0); @@ -703,9 +699,9 @@ static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt) mdc_obd->obd_no_recov = obd->obd_no_recov; } - if (obd->obd_type->typ_procsym != NULL) + if (lmv->targets_proc_entry != NULL) lprocfs_remove_proc_entry(mdc_obd->obd_name, - obd->obd_type->typ_procsym); + lmv->targets_proc_entry); rc = obd_fid_fini(tgt->ltd_exp->exp_obd); if (rc) @@ -754,8 +750,8 @@ static int lmv_disconnect(struct obd_export *exp) lmv_disconnect_mdc(obd, lmv->tgts[i]); } - if (obd->obd_type->typ_procsym != NULL) - lprocfs_remove(&obd->obd_type->typ_procsym); + if (lmv->targets_proc_entry != NULL) + lprocfs_remove(&lmv->targets_proc_entry); else CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n", obd->obd_type->typ_name, obd->obd_name); @@ -1370,14 +1366,14 @@ int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid, if (tgt->ltd_active == 0 || tgt->ltd_exp == NULL) GOTO(out, rc = -ENODEV); - /* - * Asking underlaying tgt layer to allocate new fid. - */ - rc = obd_fid_alloc(tgt->ltd_exp, fid, NULL); - if (rc > 0) { - LASSERT(fid_is_sane(fid)); - rc = 0; - } + /* + * Asking underlying tgt layer to allocate new fid. + */ + rc = obd_fid_alloc(NULL, tgt->ltd_exp, fid, NULL); + if (rc > 0) { + LASSERT(fid_is_sane(fid)); + rc = 0; + } EXIT; out: @@ -1385,8 +1381,8 @@ out: return rc; } -int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid, - struct md_op_data *op_data) +int lmv_fid_alloc(const struct lu_env *env, struct obd_export *exp, + struct lu_fid *fid, struct md_op_data *op_data) { struct obd_device *obd = class_exp2obd(exp); struct lmv_obd *lmv = &obd->u.lmv; @@ -1787,9 +1783,7 @@ struct lmv_tgt_desc struct lmv_stripe_md *lsm = op_data->op_mea1; struct lmv_tgt_desc *tgt; - if (lsm == NULL || lsm->lsm_md_stripe_count <= 1 || - op_data->op_namelen == 0 || - lsm->lsm_md_magic == LMV_MAGIC_MIGRATE) { + if (lsm == NULL || op_data->op_namelen == 0) { tgt = lmv_find_target(lmv, fid); if (IS_ERR(tgt)) return tgt; @@ -1829,7 +1823,7 @@ int lmv_create(struct obd_export *exp, struct md_op_data *op_data, op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1), op_data->op_mds); - rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data); + rc = lmv_fid_alloc(NULL, exp, &op_data->op_fid2, op_data); if (rc) RETURN(rc); @@ -1878,69 +1872,10 @@ static int lmv_done_writing(struct obd_export *exp, } static int -lmv_enqueue_remote(struct obd_export *exp, struct ldlm_enqueue_info *einfo, - struct lookup_intent *it, struct md_op_data *op_data, - struct lustre_handle *lockh, void *lmm, int lmmsize, - __u64 extra_lock_flags) -{ - struct ptlrpc_request *req = it->d.lustre.it_data; - struct obd_device *obd = exp->exp_obd; - struct lmv_obd *lmv = &obd->u.lmv; - struct lustre_handle plock; - struct lmv_tgt_desc *tgt; - struct md_op_data *rdata; - struct lu_fid fid1; - struct mdt_body *body; - int rc = 0; - int pmode; - ENTRY; - - body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY); - LASSERT(body != NULL); - - if (!(body->valid & OBD_MD_MDS)) - RETURN(0); - - CDEBUG(D_INODE, "REMOTE_ENQUEUE '%s' on "DFID" -> "DFID"\n", - LL_IT2STR(it), PFID(&op_data->op_fid1), PFID(&body->fid1)); - - /* - * We got LOOKUP lock, but we really need attrs. - */ - pmode = it->d.lustre.it_lock_mode; - LASSERT(pmode != 0); - memcpy(&plock, lockh, sizeof(plock)); - it->d.lustre.it_lock_mode = 0; - it->d.lustre.it_data = NULL; - fid1 = body->fid1; - - ptlrpc_req_finished(req); - - tgt = lmv_find_target(lmv, &fid1); - if (IS_ERR(tgt)) - GOTO(out, rc = PTR_ERR(tgt)); - - OBD_ALLOC_PTR(rdata); - if (rdata == NULL) - GOTO(out, rc = -ENOMEM); - - rdata->op_fid1 = fid1; - rdata->op_bias = MDS_CROSS_REF; - - rc = md_enqueue(tgt->ltd_exp, einfo, it, rdata, lockh, - lmm, lmmsize, NULL, extra_lock_flags); - OBD_FREE_PTR(rdata); - EXIT; -out: - ldlm_lock_decref(&plock, pmode); - return rc; -} - -static int lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo, - struct lookup_intent *it, struct md_op_data *op_data, - struct lustre_handle *lockh, void *lmm, int lmmsize, - struct ptlrpc_request **req, __u64 extra_lock_flags) + const union ldlm_policy_data *policy, + struct lookup_intent *it, struct md_op_data *op_data, + struct lustre_handle *lockh, __u64 extra_lock_flags) { struct obd_device *obd = exp->exp_obd; struct lmv_obd *lmv = &obd->u.lmv; @@ -1962,13 +1897,9 @@ lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo, CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID" -> mds #%d\n", LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx); - rc = md_enqueue(tgt->ltd_exp, einfo, it, op_data, lockh, - lmm, lmmsize, req, extra_lock_flags); + rc = md_enqueue(tgt->ltd_exp, einfo, policy, it, op_data, lockh, + extra_lock_flags); - if (rc == 0 && it && it->it_op == IT_OPEN) { - rc = lmv_enqueue_remote(exp, einfo, it, op_data, lockh, - lmm, lmmsize, extra_lock_flags); - } RETURN(rc); } @@ -2154,7 +2085,7 @@ static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data, if (op_data->op_cli_flags & CLI_MIGRATE) { LASSERTF(fid_is_sane(&op_data->op_fid3), "invalid FID "DFID"\n", PFID(&op_data->op_fid3)); - rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data); + rc = lmv_fid_alloc(NULL, exp, &op_data->op_fid2, op_data); if (rc) RETURN(rc); src_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid3); @@ -2510,8 +2441,7 @@ retry: RETURN(PTR_ERR(tgt)); /* For striped dir, we need to locate the parent as well */ - if (op_data->op_mea1 != NULL && - op_data->op_mea1->lsm_md_stripe_count > 1) { + if (op_data->op_mea1 != NULL) { struct lmv_tgt_desc *tmp; LASSERT(op_data->op_name != NULL && @@ -2830,9 +2760,13 @@ static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm, lsm->lsm_md_master_mdt_index = le32_to_cpu(lmm1->lmv_master_mdt_index); lsm->lsm_md_hash_type = le32_to_cpu(lmm1->lmv_hash_type); lsm->lsm_md_layout_version = le32_to_cpu(lmm1->lmv_layout_version); + fid_le_to_cpu(&lsm->lsm_md_master_fid, &lmm1->lmv_master_fid); cplen = strlcpy(lsm->lsm_md_pool_name, lmm1->lmv_pool_name, sizeof(lsm->lsm_md_pool_name)); + if (!fid_is_sane(&lsm->lsm_md_master_fid)) + RETURN(-EPROTO); + if (cplen >= sizeof(lsm->lsm_md_pool_name)) RETURN(-E2BIG); @@ -2872,8 +2806,12 @@ int lmv_unpack_md(struct obd_export *exp, struct lmv_stripe_md **lsmp, if (lsm != NULL && lmm == NULL) { #ifdef __KERNEL__ int i; - for (i = 1; i < lsm->lsm_md_stripe_count; i++) { - if (lsm->lsm_md_oinfo[i].lmo_root != NULL) + for (i = 0; i < lsm->lsm_md_stripe_count; i++) { + /* For migrating inode, the master stripe and master + * object will be the same, so do not need iput, see + * ll_update_lsm_md */ + if (!(lsm->lsm_md_hash_type & LMV_HASH_FLAG_MIGRATION && + i == 0) && lsm->lsm_md_oinfo[i].lmo_root != NULL) iput(lsm->lsm_md_oinfo[i].lmo_root); } #endif @@ -2896,7 +2834,6 @@ int lmv_unpack_md(struct obd_export *exp, struct lmv_stripe_md **lsmp, /* Unpack memmd */ if (le32_to_cpu(lmm->lmv_magic) != LMV_MAGIC_V1 && - le32_to_cpu(lmm->lmv_magic) != LMV_MAGIC_MIGRATE && le32_to_cpu(lmm->lmv_magic) != LMV_USER_MAGIC) { CERROR("%s: invalid lmv magic %x: rc = %d\n", exp->exp_obd->obd_name, le32_to_cpu(lmm->lmv_magic), @@ -2904,8 +2841,7 @@ int lmv_unpack_md(struct obd_export *exp, struct lmv_stripe_md **lsmp, RETURN(-EIO); } - if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_V1 || - le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_MIGRATE) + if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_V1) lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm)); else /** @@ -2925,7 +2861,6 @@ int lmv_unpack_md(struct obd_export *exp, struct lmv_stripe_md **lsmp, switch (le32_to_cpu(lmm->lmv_magic)) { case LMV_MAGIC_V1: - case LMV_MAGIC_MIGRATE: rc = lmv_unpack_md_v1(exp, lsm, &lmm->lmv_md_v1); break; default: @@ -3298,9 +3233,6 @@ int lmv_quotacheck(struct obd_device *unused, struct obd_export *exp, int lmv_update_lsm_md(struct obd_export *exp, struct lmv_stripe_md *lsm, struct mdt_body *body, ldlm_blocking_callback cb_blocking) { - if (lsm->lsm_md_stripe_count <= 1) - return 0; - return lmv_revalidate_slaves(exp, body, lsm, cb_blocking, 0); }