From 40af153a20c6c362d44b2f0f9931bf11b4250e6b Mon Sep 17 00:00:00 2001 From: yury Date: Thu, 4 May 2006 10:46:22 +0000 Subject: [PATCH] - LMV only implements plecement policy and MDC allocates fids --- lustre/include/linux/obd.h | 7 +++---- lustre/include/linux/obd_class.h | 4 +++- lustre/ldlm/ldlm_lib.c | 18 ++++++++++++++++++ lustre/lmv/lmv_obd.c | 35 ++++++----------------------------- lustre/mdc/mdc_request.c | 24 ++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 34 deletions(-) diff --git a/lustre/include/linux/obd.h b/lustre/include/linux/obd.h index e9dc04e..73ac0e4 100644 --- a/lustre/include/linux/obd.h +++ b/lustre/include/linux/obd.h @@ -369,6 +369,9 @@ struct client_obd { /* used by quotacheck */ int cl_qchk_stat; /* quotacheck stat of the peer */ + + struct lu_fid cl_fid; + spinlock_t cl_fids_lock; }; #define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid) @@ -503,10 +506,6 @@ struct lmv_obd { struct obd_connect_data *datas; int datas_size; - struct lu_fid *fids; - int fids_size; - spinlock_t fids_lock; - struct obd_connect_data conn_data; }; diff --git a/lustre/include/linux/obd_class.h b/lustre/include/linux/obd_class.h index d614f50..f9e311a 100644 --- a/lustre/include/linux/obd_class.h +++ b/lustre/include/linux/obd_class.h @@ -701,7 +701,9 @@ static inline int obd_fid_alloc(struct obd_export *exp, int rc; ENTRY; - EXP_CHECK_DT_OP(exp, fid_alloc); + if (OBP(exp->exp_obd, fid_alloc) == NULL) + RETURN(-ENOTSUPP); + OBD_COUNTER_INCREMENT(exp->exp_obd, fid_alloc); rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, hint); diff --git a/lustre/ldlm/ldlm_lib.c b/lustre/ldlm/ldlm_lib.c index 6057380..babf5f6 100644 --- a/lustre/ldlm/ldlm_lib.c +++ b/lustre/ldlm/ldlm_lib.c @@ -256,6 +256,10 @@ int client_obd_setup(struct obd_device *obddev, struct lustre_cfg* lcfg) spin_lock_init(&cli->cl_loi_list_lock); cli->cl_r_in_flight = 0; cli->cl_w_in_flight = 0; + + memset(&cli->cl_fid, 0, sizeof(struct lu_fid)); + spin_lock_init(&cli->cl_fids_lock); + spin_lock_init(&cli->cl_read_rpc_hist.oh_lock); spin_lock_init(&cli->cl_write_rpc_hist.oh_lock); spin_lock_init(&cli->cl_read_page_hist.oh_lock); @@ -375,6 +379,9 @@ int client_connect_import(struct lustre_handle *dlm_handle, imp->imp_connect_flags_orig = data->ocd_connect_flags; } + /* zero out sequence to check it later for validness */ + ocd->ocd_seq = 0; + rc = ptlrpc_connect_import(imp, NULL); if (rc != 0) { LASSERT (imp->imp_state == LUSTRE_IMP_DISCON); @@ -389,6 +396,17 @@ int client_connect_import(struct lustre_handle *dlm_handle, } ptlrpc_pinger_add_import(imp); + + /* XXX: in principle we initialize start cl_fid by seq from MDS and + * start oid. But as connect is asynchronous, we should make sure that + * by this time server answered already with correct data (wait for + * connect finish). */ + LASSERTF(ocd->ocd_seq != 0, "Asynchronous connect was not in " + "time to return correct sequnece\n"); + + cli->cl_fid.f_seq = ocd->ocd_seq; + cli->cl_fid.f_oid = LUSTRE_FID_INIT_OID; + EXIT; if (rc) { diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index 2066f8e..54bd8be 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -364,10 +364,6 @@ int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt) /* copy connect data, it may be used later */ lmv->datas[tgt->idx] = *mdc_data; - /* setup start fid for this target */ - lmv->fids[tgt->idx].f_seq = mdc_data->ocd_seq; - lmv->fids[tgt->idx].f_oid = LUSTRE_FID_INIT_OID; - md_init_ea_size(tgt->ltd_exp, lmv->max_easize, lmv->max_def_easize, lmv->max_cookiesize); @@ -675,31 +671,20 @@ static int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid, { struct obd_device *obd = class_exp2obd(exp); struct lmv_obd *lmv = &obd->u.lmv; - struct lu_fid *tgt_fid; - int rc = 0, i; + int rc = 0, mds; ENTRY; LASSERT(fid != NULL); LASSERT(hint != NULL); - i = lmv_plcament_policy(obd, hint); - if (i < 0 || i >= lmv->desc.ld_tgt_count) { + mds = lmv_plcament_policy(obd, hint); + if (mds < 0 || mds >= lmv->desc.ld_tgt_count) { CERROR("can't get target for allocating fid\n"); RETURN(-EINVAL); } - - tgt_fid = &lmv->fids[i]; - - spin_lock(&lmv->fids_lock); - if (fid_oid(tgt_fid) < LUSTRE_FID_SEQ_WIDTH) { - tgt_fid->f_oid += 1; - *fid = *tgt_fid; - } else { - CERROR("sequence is exhausted. Switching to " - "new one is not yet implemented\n"); - rc = -ERANGE; - } - spin_unlock(&lmv->fids_lock); + + /* asking underlaying tgt later to allocate new fid */ + rc = obd_fid_alloc(lmv->tgts[mds].ltd_exp, fid, hint); RETURN(rc); } @@ -750,12 +735,6 @@ static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg) if (lmv->datas == NULL) GOTO(out_free_tgts, rc = -ENOMEM); - lmv->fids_size = LMV_MAX_TGT_COUNT * sizeof(struct lu_fid); - - OBD_ALLOC(lmv->fids, lmv->fids_size); - if (lmv->fids == NULL) - GOTO(out_free_datas, rc = -ENOMEM); - obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid); lmv->desc.ld_tgt_count = 0; lmv->desc.ld_active_tgt_count = 0; @@ -763,7 +742,6 @@ static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg) lmv->max_def_easize = 0; lmv->max_easize = 0; - spin_lock_init(&lmv->fids_lock); spin_lock_init(&lmv->lmv_lock); sema_init(&lmv->init_sem, 1); @@ -807,7 +785,6 @@ static int lmv_cleanup(struct obd_device *obd) lprocfs_obd_cleanup(obd); lmv_mgr_cleanup(obd); - OBD_FREE(lmv->fids, lmv->fids_size); OBD_FREE(lmv->datas, lmv->datas_size); OBD_FREE(lmv->tgts, lmv->tgts_size); diff --git a/lustre/mdc/mdc_request.c b/lustre/mdc/mdc_request.c index 712268b..5c22c2a 100644 --- a/lustre/mdc/mdc_request.c +++ b/lustre/mdc/mdc_request.c @@ -1075,6 +1075,29 @@ static int mdc_import_event(struct obd_device *obd, struct obd_import *imp, RETURN(rc); } +static int mdc_fid_alloc(struct obd_export *exp, struct lu_fid *fid, + struct placement_hint *hint) +{ + struct client_obd *cli = &exp->exp_obd->u.cli; + int rc = 0; + ENTRY; + + LASSERT(fid != NULL); + LASSERT(hint != NULL); + + spin_lock(&cli->cl_fids_lock); + if (fid_oid(&cli->cl_fid) < LUSTRE_FID_SEQ_WIDTH) { + cli->cl_fid.f_oid += 1; + *fid = cli->cl_fid; + } else { + CERROR("sequence is exhausted. Switching to " + "new one is not yet implemented\n"); + rc = -ERANGE; + } + spin_unlock(&cli->cl_fids_lock); + RETURN(rc); +} + static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg) { struct client_obd *cli = &obd->u.cli; @@ -1223,6 +1246,7 @@ struct obd_ops mdc_obd_ops = { .o_statfs = mdc_statfs, .o_pin = mdc_pin, .o_unpin = mdc_unpin, + .o_fid_alloc = mdc_fid_alloc, .o_import_event = mdc_import_event, .o_llog_init = mdc_llog_init, .o_llog_finish = mdc_llog_finish, -- 1.8.3.1